Make browser and target highlight when the mouse is hovering on them

This commit is contained in:
Ylva Selling
2021-03-23 15:01:40 +01:00
parent 6ff0e6475a
commit 74609230b6
6 changed files with 63 additions and 11 deletions
@@ -44,6 +44,8 @@ namespace openspace {
// Resizing
void saveResizeStartSize();
void updateBrowserSize();
void setBorderColor(glm::ivec3 addColor);
glm::ivec3 getColor();
// Flag for dimensions
bool _browserDimIsDirty;
properties::FloatProperty _fieldOfView;
@@ -55,6 +57,7 @@ namespace openspace {
bool _camIsSyncedWWT;
ScreenSpaceSkyTarget* _skyTarget;
std::thread _threadWWTMessages;
glm::ivec3 _borderColor;
};
}
@@ -41,6 +41,8 @@ namespace openspace {
glm::vec2 getAnglePosition();
void setScale(float scale);
void setConnectedBrowser();
void setBorderColor(glm::ivec3 color);
glm::ivec3 getColor();
void translate(glm::vec2 translation, glm::vec2 position);
@@ -57,11 +59,12 @@ namespace openspace {
properties::Vec2Property _targetDimensions;
std::unique_ptr<ghoul::opengl::Texture> _texture;
UniformCache(modelTransform, viewProj, texture, fieldOfView, borderWidth, targetRatio) _uniformCache;
UniformCache(modelTransform, viewProj, texture, fieldOfView, borderWidth, targetRatio, borderColor) _uniformCache;
GLuint _vertexArray = 0;
GLuint _vertexBuffer = 0;
float _fieldOfView = 100.f;
ScreenSpaceSkyBrowser* _skyBrowser;
glm::vec3 _borderColor;
};
}
+6 -7
View File
@@ -2,6 +2,7 @@ uniform sampler2D texture1;
uniform float borderWidth;
uniform vec2 targetRatio;
uniform float fieldOfView;
uniform vec3 borderColor;
in vec2 vs_st;
in vec4 vs_position;
@@ -28,11 +29,12 @@ Fragment getFragment() {
vec3 crosshair = vec3(cross(vs_st, 0.1));
// draw square border
vec2 bl = step(vec2(borderWidth),(1.0-vs_st)*targetRatio); // bottom-left line
vec2 tr = step(vec2(borderWidth),vs_st*targetRatio); // top-right line
vec2 bl = step(vec2(borderWidth),(1.0-vs_st)*targetRatio); // bottom-left line
vec2 tr = step(vec2(borderWidth),vs_st*targetRatio); // top-right line
vec3 border = vec3(tr.x * tr.y * bl.x * bl.y);
frag.color = vec4(1,1,1,1);
frag.color.rgb = vec3(borderColor / 255);
if(fieldOfView < 10.f) {
frag.color = vec4(1,1,1,1);
@@ -60,8 +62,8 @@ Fragment getFragment() {
/*
// draw square border
vec2 bl = step(vec2(borderWidth),(1.0-vs_st)*targetRatio); // bottom-left line
vec2 tr = step(vec2(borderWidth),vs_st*targetRatio); // top-right line
vec2 bl = step(vec2(borderWidth),(1.0-vs_st)*targetRatio); // bottom-left line
vec2 tr = step(vec2(borderWidth),vs_st*targetRatio); // top-right line
vec3 border = vec3(tr.x * tr.y * bl.x * bl.y);
frag.color = vec4(1,1,1,1);
@@ -71,6 +73,3 @@ Fragment getFragment() {
}
*/
+25
View File
@@ -143,10 +143,35 @@ SkyBrowserModule::SkyBrowserModule()
}
// If there is no dragging or resizing, look for new objects
else {
// Save old selection for removing highlight
ScreenSpaceRenderable* lastObj = _mouseOnObject;
// Find and save what mouse is currently hovering on
auto currentlyOnObject = std::find_if(renderables.begin(), renderables.end(), [&](ScreenSpaceRenderable* obj) {
return obj->coordIsInsideCornersScreenSpace(_mousePosition);
});
_mouseOnObject = currentlyOnObject != renderables.end() ? *currentlyOnObject : nullptr;
// Selection has changed
if (lastObj != _mouseOnObject) {
glm::ivec3 highlightAddition{ 35, 35, 35 };
// Remove highlight
if (to_browser(lastObj)) {
to_browser(lastObj)->setBorderColor(to_browser(lastObj)->getColor() - highlightAddition);
}
else if (to_target(lastObj)) {
to_target(lastObj)->setBorderColor(to_target(lastObj)->getColor() - highlightAddition);
}
// Add highlight
if (to_browser(_mouseOnObject)) {
to_browser(_mouseOnObject)->setBorderColor(to_browser(_mouseOnObject)->getColor() + highlightAddition);
}
else if (to_target(_mouseOnObject)) {
to_target(_mouseOnObject)->setBorderColor(to_target(_mouseOnObject)->getColor() + highlightAddition);
}
}
}
}
);
@@ -69,6 +69,7 @@ namespace openspace {
, _skyTargetID(TargetIDInfo)
, _camIsSyncedWWT(true)
, _skyTarget(nullptr)
, _borderColor(220, 220, 220)
{
// Handle target dimension property
const Parameters p = codegen::bake<Parameters>(dictionary);
@@ -119,7 +120,7 @@ namespace openspace {
if (_skyTarget) {
_skyTarget->property("Enabled")->set(_enabled.value());
}
});
});
}
bool ScreenSpaceSkyBrowser::initializeGL() {
@@ -165,6 +166,17 @@ namespace openspace {
frame->ExecuteJavaScript(script, frame->GetURL(), 0);
}
}
glm::ivec3 ScreenSpaceSkyBrowser::getColor() {
return _borderColor;
}
void ScreenSpaceSkyBrowser::setBorderColor(glm::ivec3 col) {
std::string stringColor = std::to_string(col.x) + "," + std::to_string(col.y) + "," + std::to_string(col.z);
std::string script = "document.body.style.backgroundColor = 'rgb(" + stringColor + ")';";
executeJavascript(script);
}
bool ScreenSpaceSkyBrowser::sendMessageToWWT(const ghoul::Dictionary& msg) {
std::string script = "sendMessageToWWT(" + ghoul::formatJson(msg) + ");";
executeJavascript(script);
@@ -39,8 +39,8 @@ namespace {
"Set the dimensions of the SkyTarget according to the SkyBrowser ratio "
};
constexpr const std::array<const char*, 6> UniformNames = {
"ModelTransform", "ViewProjectionMatrix", "texture1", "fieldOfView", "borderWidth", "targetRatio"
constexpr const std::array<const char*, 7> UniformNames = {
"ModelTransform", "ViewProjectionMatrix", "texture1", "fieldOfView", "borderWidth", "targetRatio", "borderColor"
};
constexpr const openspace::properties::Property::PropertyInfo BrowserIDInfo =
@@ -68,6 +68,7 @@ namespace openspace {
: ScreenSpaceRenderable(dictionary)
, _targetDimensions(TargetDimensionInfo, glm::ivec2(1000.f), glm::ivec2(0.f), glm::ivec2(6000.f))
, _skyBrowserID(BrowserIDInfo)
, _borderColor(220.f, 220.f, 220.f)
{
// Handle target dimension property
const Parameters p = codegen::bake<Parameters>(dictionary);
@@ -179,6 +180,14 @@ namespace openspace {
}
void ScreenSpaceSkyTarget::setBorderColor(glm::ivec3 color) {
_borderColor = color;
}
glm::ivec3 ScreenSpaceSkyTarget::getColor() {
return _borderColor;
}
void ScreenSpaceSkyTarget::setBrowser(ScreenSpaceSkyBrowser* browser) {
_skyBrowser = browser;
}
@@ -202,6 +211,7 @@ namespace openspace {
_shader->setUniform(_uniformCache.borderWidth, borderWidth);
_shader->setUniform(_uniformCache.targetRatio, targetRatio);
_shader->setUniform(_uniformCache.modelTransform, modelTransform);
_shader->setUniform(_uniformCache.borderColor, _borderColor);
_shader->setUniform(
_uniformCache.viewProj,