mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-18 10:59:18 -06:00
Set selection of target/browser in the Pair class instead of the module
This commit is contained in:
@@ -78,7 +78,7 @@ public:
|
||||
glm::vec2 screenSpaceDimensions();
|
||||
glm::vec2 upperRightCornerScreenSpace();
|
||||
glm::vec2 lowerLeftCornerScreenSpace();
|
||||
bool coordIsInsideCornersScreenSpace(glm::vec2 coord);
|
||||
bool intersection(glm::vec2 coord);
|
||||
void translate(glm::vec2 translation, glm::vec2 position);
|
||||
friend bool operator<(const ScreenSpaceRenderable& lhs, const ScreenSpaceRenderable& rhs);
|
||||
void setCartesianPosition(const glm::vec3& position);
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace openspace {
|
||||
|
||||
class ScreenSpaceSkyBrowser;
|
||||
class ScreenSpaceSkyTarget;
|
||||
class ScreenSpaceRenderable;
|
||||
class ImageData;
|
||||
|
||||
class Pair {
|
||||
@@ -54,6 +55,10 @@ public:
|
||||
void startAnimation(glm::dvec3 coordsEnd, float fovEnd, bool shouldLockAfter = true);
|
||||
void incrementallyAnimateToCoordinate(double deltaTime);
|
||||
void incrementallyFade(float goalState, float fadeTime, float deltaTime);
|
||||
// Mouse interaction
|
||||
bool checkMouseIntersection(glm::vec2 mousePosition);
|
||||
glm::vec2 selectedScreenSpacePosition();
|
||||
bool isSelectedBrowser();
|
||||
|
||||
// Browser
|
||||
void sendIdToBrowser();
|
||||
@@ -66,7 +71,7 @@ public:
|
||||
|
||||
// Boolean functions
|
||||
bool hasFinishedFading(float goalState) const;
|
||||
bool isCoordOnPair(glm::vec2 mousePosition) const;
|
||||
|
||||
bool isEnabled() const;
|
||||
bool isLocked() const;
|
||||
|
||||
@@ -102,7 +107,9 @@ public:
|
||||
const Pair& rhs);
|
||||
|
||||
private:
|
||||
static std::string _selected;
|
||||
ScreenSpaceRenderable* _selected;
|
||||
bool _isSelectedBrowser;
|
||||
|
||||
bool isTargetFadeFinished(float goalState) const;
|
||||
bool isBrowserFadeFinished(float goalState) const;
|
||||
|
||||
|
||||
@@ -232,22 +232,15 @@ SkyBrowserModule::SkyBrowserModule()
|
||||
if (_mouseOnPair && action == MouseAction::Press) {
|
||||
|
||||
// Get the currently selected browser
|
||||
setSelectedBrowser(_mouseOnPair->getBrowser()->identifier());
|
||||
setSelectedBrowser(_mouseOnPair->browserId());
|
||||
|
||||
if (button == MouseButton::Left) {
|
||||
_isCameraRotating = false;
|
||||
_startMousePosition = _mousePosition;
|
||||
if (_isBrowser) {
|
||||
_startDragPosition = _mouseOnPair->getBrowser()->
|
||||
screenSpacePosition();
|
||||
}
|
||||
else {
|
||||
_startDragPosition = _mouseOnPair->getTarget()->
|
||||
screenSpacePosition();
|
||||
}
|
||||
_startDragPosition = _mouseOnPair->selectedScreenSpacePosition();
|
||||
|
||||
// If current object is browser, check for resizing
|
||||
if (_isBrowser) {
|
||||
if (_mouseOnPair->isSelectedBrowser()) {
|
||||
// Resize browser if mouse is over resize button
|
||||
_resizeDirection = _mouseOnPair->getBrowser()->isOnResizeArea(
|
||||
_mousePosition
|
||||
@@ -268,7 +261,8 @@ SkyBrowserModule::SkyBrowserModule()
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (_isBrowser && button == MouseButton::Right) {
|
||||
// Fine tuning mode of target
|
||||
else if (_mouseOnPair->isSelectedBrowser() && button == MouseButton::Right) {
|
||||
// If you start dragging around on the browser, the target unlocks
|
||||
_mouseOnPair->unlock();
|
||||
// Change view (by moving target) within browser if right mouse
|
||||
@@ -309,26 +303,27 @@ SkyBrowserModule::SkyBrowserModule()
|
||||
_mousePosition = skybrowser::pixelToScreenSpace2d(pixel);
|
||||
glm::vec2 translation = _mousePosition - _startMousePosition;
|
||||
|
||||
if (_isResizing) {
|
||||
// Calculate scaling factor
|
||||
glm::vec2 mouseDragVector = (_mousePosition - _startMousePosition);
|
||||
glm::vec2 scaling = mouseDragVector * glm::vec2(_resizeDirection);
|
||||
glm::vec2 newSizeRelToOld = (_startBrowserSize + (scaling)) /
|
||||
_startBrowserSize;
|
||||
// Scale the browser
|
||||
_mouseOnPair->getBrowser()->setScale(newSizeRelToOld);
|
||||
|
||||
// For dragging functionality, translate so it looks like the
|
||||
// browser isn't moving. Make sure the browser doesn't move in
|
||||
// directions it's not supposed to
|
||||
translation = 0.5f * mouseDragVector * abs(
|
||||
glm::vec2(_resizeDirection)
|
||||
);
|
||||
|
||||
}
|
||||
if (_isDragging || _isResizing) {
|
||||
if (_isResizing) {
|
||||
// Calculate scaling factor
|
||||
glm::vec2 mouseDragVector = (_mousePosition-_startMousePosition);
|
||||
glm::vec2 scaling = mouseDragVector * glm::vec2(_resizeDirection);
|
||||
glm::vec2 newSizeRelToOld = (_startBrowserSize + (scaling)) /
|
||||
_startBrowserSize;
|
||||
// Scale the browser
|
||||
_mouseOnPair->getBrowser()->setScale(newSizeRelToOld);
|
||||
|
||||
// For dragging functionality, translate so it looks like the
|
||||
// browser isn't moving. Make sure the browser doesn't move in
|
||||
// directions it's not supposed to
|
||||
translation = 0.5f * mouseDragVector * abs(
|
||||
glm::vec2(_resizeDirection)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// Translate
|
||||
if (_isBrowser) {
|
||||
if (_mouseOnPair->isSelectedBrowser()) {
|
||||
_mouseOnPair->getBrowser()->translate(
|
||||
translation,
|
||||
_startDragPosition
|
||||
@@ -375,9 +370,8 @@ SkyBrowserModule::SkyBrowserModule()
|
||||
global::callback::preSync->emplace_back([this]() {
|
||||
|
||||
// Disable browser and targets when camera is outside of solar system
|
||||
glm::dvec3 cameraPos = global::navigationHandler->camera()->positionVec3();
|
||||
double deltaTime = global::windowDelegate->deltaTime();
|
||||
bool camWasInSolarSystem = _isCameraInSolarSystem;
|
||||
glm::dvec3 cameraPos = global::navigationHandler->camera()->positionVec3();
|
||||
_isCameraInSolarSystem = glm::length(cameraPos) < SolarSystemRadius;
|
||||
|
||||
// Fading flags
|
||||
@@ -389,7 +383,7 @@ SkyBrowserModule::SkyBrowserModule()
|
||||
_selectedBrowser = _browser3dNode->renderable()->identifier();
|
||||
}
|
||||
}
|
||||
|
||||
double deltaTime = global::windowDelegate->deltaTime();
|
||||
// Fade pairs if the camera moved in or out the solar system
|
||||
if (_isTransitioningVizMode) {
|
||||
if (_isCameraInSolarSystem) {
|
||||
@@ -441,23 +435,12 @@ void SkyBrowserModule::internalInitialize(const ghoul::Dictionary& dict) {
|
||||
void SkyBrowserModule::setSelectedObject()
|
||||
{
|
||||
// Save old selection for removing highlight
|
||||
Pair* lastObj = _mouseOnPair;
|
||||
Pair* previousPair = _mouseOnPair;
|
||||
|
||||
// Find and save what mouse is currently hovering on
|
||||
auto it = std::find_if(std::begin(_targetsBrowsers), std::end(_targetsBrowsers),
|
||||
[&] (const std::unique_ptr<Pair> &pair) {
|
||||
bool onBrowser = pair->getBrowser()->coordIsInsideCornersScreenSpace(
|
||||
_mousePosition
|
||||
);
|
||||
bool onTarget = pair->getTarget()->coordIsInsideCornersScreenSpace(
|
||||
_mousePosition
|
||||
);
|
||||
if (onBrowser) {
|
||||
_selectedBrowser = pair->getBrowser()->identifier();
|
||||
}
|
||||
_isBrowser = onBrowser;
|
||||
|
||||
return onBrowser || onTarget;
|
||||
return pair->checkMouseIntersection(_mousePosition);
|
||||
});
|
||||
|
||||
if (it == std::end(_targetsBrowsers)) {
|
||||
@@ -468,17 +451,16 @@ void SkyBrowserModule::setSelectedObject()
|
||||
}
|
||||
|
||||
// Selection has changed
|
||||
if (lastObj != _mouseOnPair) {
|
||||
if (previousPair != _mouseOnPair) {
|
||||
|
||||
// Remove highlight
|
||||
if (lastObj) {
|
||||
lastObj->removeHighlight(_highlightAddition);
|
||||
if (previousPair) {
|
||||
previousPair->removeHighlight(_highlightAddition);
|
||||
}
|
||||
// Add highlight to new selection
|
||||
if (_mouseOnPair) {
|
||||
_mouseOnPair->highlight(_highlightAddition);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -107,8 +107,6 @@ private:
|
||||
// The browsers and targets
|
||||
std::vector<std::unique_ptr<Pair>> _targetsBrowsers;
|
||||
Pair* _mouseOnPair{ nullptr };
|
||||
Pair* _selectedPair{ nullptr };
|
||||
bool _isBrowser{ false };
|
||||
ScreenSpaceImageLocal* _hoverCircle{ nullptr };
|
||||
SceneGraphNode* _browser3dNode{ nullptr };
|
||||
RenderableSkyBrowser* _browser3d{ nullptr };
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <modules/skybrowser/include/screenspaceskybrowser.h>
|
||||
#include <modules/skybrowser/include/screenspaceskytarget.h>
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
#include <modules/skybrowser/include/wwtdatahandler.h>
|
||||
#include <modules/skybrowser/include/utility.h>
|
||||
#include <ghoul/misc/assert.h>
|
||||
@@ -36,8 +37,6 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
std::string Pair::_selected = ""; // Define the static variable in the global scope
|
||||
|
||||
Pair::Pair(ScreenSpaceSkyBrowser* browser, ScreenSpaceSkyTarget* target)
|
||||
: _target(target), _browser(browser)
|
||||
{
|
||||
@@ -144,20 +143,35 @@ namespace openspace {
|
||||
return browserDiff < FadeThreshold;
|
||||
}
|
||||
|
||||
bool Pair::isCoordOnPair(glm::vec2 mousePosition) const
|
||||
bool Pair::checkMouseIntersection(glm::vec2 mousePosition)
|
||||
{
|
||||
const bool onBrowser = _browser->coordIsInsideCornersScreenSpace(mousePosition);
|
||||
const bool onTarget = _target->coordIsInsideCornersScreenSpace(mousePosition);
|
||||
bool onBrowser = _browser->intersection(mousePosition);
|
||||
bool onTarget = _target->intersection(mousePosition);
|
||||
if (onBrowser) {
|
||||
_selected = _browser->identifier();
|
||||
_selected = _browser;
|
||||
_isSelectedBrowser = true;
|
||||
}
|
||||
else if (onTarget) {
|
||||
_selected = _target->identifier();
|
||||
_selected = _target;
|
||||
_isSelectedBrowser = false;
|
||||
}
|
||||
else {
|
||||
_selected = nullptr;
|
||||
_isSelectedBrowser = false;
|
||||
}
|
||||
|
||||
return onBrowser || onTarget;
|
||||
}
|
||||
|
||||
glm::vec2 Pair::selectedScreenSpacePosition()
|
||||
{
|
||||
return _selected->screenSpacePosition();
|
||||
}
|
||||
|
||||
bool Pair::isSelectedBrowser()
|
||||
{
|
||||
return _isSelectedBrowser;
|
||||
}
|
||||
|
||||
void Pair::setEnabled(bool enable)
|
||||
{
|
||||
_browser->setEnabled(enable);
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace openspace {
|
||||
identifier = dictionary.value<std::string>(KeyIdentifier);
|
||||
}
|
||||
else {
|
||||
identifier = "ScreenSpaceSkyBrowser22";
|
||||
identifier = "ScreenSpaceSkyBrowser";
|
||||
}
|
||||
identifier = makeUniqueIdentifier(identifier);
|
||||
setIdentifier(identifier);
|
||||
@@ -245,7 +245,7 @@ namespace openspace {
|
||||
glm::ivec2 ScreenSpaceSkyBrowser::isOnResizeArea(glm::vec2 coord) {
|
||||
glm::ivec2 resizePosition = glm::ivec2{ 0 };
|
||||
// Make sure coordinate is on browser
|
||||
if (!coordIsInsideCornersScreenSpace(coord)) return resizePosition;
|
||||
if (!intersection(coord)) return resizePosition;
|
||||
|
||||
// TO DO: turn this into a vector and use prettier vector arithmetic
|
||||
float resizeAreaY = screenSpaceDimensions().y * _resizeAreaPercentage;
|
||||
|
||||
@@ -530,7 +530,7 @@ glm::vec2 ScreenSpaceRenderable::lowerLeftCornerScreenSpace() {
|
||||
return screenSpacePosition() - (screenSpaceDimensions() / 2.0f);
|
||||
}
|
||||
|
||||
bool ScreenSpaceRenderable::coordIsInsideCornersScreenSpace(glm::vec2 coord) {
|
||||
bool ScreenSpaceRenderable::intersection(glm::vec2 coord) {
|
||||
bool lessThanUpperRight = coord.x < upperRightCornerScreenSpace().x && coord.y < upperRightCornerScreenSpace().y;
|
||||
bool moreThanLowerLeft = coord.x > lowerLeftCornerScreenSpace().x && coord.y > lowerLeftCornerScreenSpace().y;
|
||||
return lessThanUpperRight && moreThanLowerLeft;
|
||||
|
||||
Reference in New Issue
Block a user