Implemented View feature to center view on a source. Using it when

inserting new source in MixingView.
This commit is contained in:
brunoherbelin
2020-06-07 16:37:42 +02:00
parent d0c31f0331
commit 32ba013bb1
6 changed files with 68 additions and 36 deletions

View File

@@ -298,7 +298,8 @@ void Mixer::insertSource(Source *s, bool makecurrent)
// switch to Mixing view to show source created
setCurrentView(View::MIXING);
current_view_->update(0);
current_view_->restoreSettings();
// current_view_->restoreSettings();
current_view_->centerSource(s);
}
}

View File

@@ -287,6 +287,27 @@ void UserInterface::handleKeyboard()
}
void setMouseCursor(View::Cursor c = View::Cursor())
{
ImGui::SetMouseCursor(c.type);
if ( !c.info.empty()) {
ImGuiIO& io = ImGui::GetIO();
float d = 0.5f * ImGui::GetFrameHeight() ;
ImVec2 window_pos = ImVec2( io.MousePos.x - d, io.MousePos.y - d );
ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always);
ImGui::SetNextWindowBgAlpha(0.45f); // Transparent background
if (ImGui::Begin("MouseInfoContext", NULL, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav))
{
ImGuiToolkit::PushFont(ImGuiToolkit::FONT_MONO);
ImGui::Text(" %s", c.info.c_str());
ImGui::PopFont();
ImGui::End();
}
}
}
void UserInterface::handleMouse()
{
@@ -331,20 +352,19 @@ void UserInterface::handleMouse()
{
// right mouse drag => drag current view
View::Cursor c = Mixer::manager().currentView()->drag( mouseclic[ImGuiMouseButton_Right], mousepos);
ImGui::SetMouseCursor(c.type);
setMouseCursor(c);
}
else {
ImGui::SetMouseCursor(ImGuiMouseCursor_Arrow);
else if ( ImGui::IsMouseDown(ImGuiMouseButton_Right)) {
if ( ImGui::IsMouseDown(ImGuiMouseButton_Right)) {
// TODO CONTEXT MENU
Mixer::manager().unsetCurrentSource();
navigator.hidePannel();
// glm::vec3 point = Rendering::manager().unProject(mousepos, Mixer::manager().currentView()->scene.root()->transform_ );
}
}
if ( ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Right) )
{
Mixer::manager().currentView()->restoreSettings();
}
//
@@ -357,19 +377,7 @@ void UserInterface::handleMouse()
// grab current source
View::Cursor c = Mixer::manager().currentView()->grab( mouseclic[ImGuiMouseButton_Left], mousepos, current, picked);
ImGui::SetMouseCursor(c.type);
float d = 0.5f * ImGui::GetFrameHeight() ;
ImVec2 window_pos = ImVec2( mousepos.x - d, mousepos.y - d );
ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always);
ImGui::SetNextWindowBgAlpha(0.45f); // Transparent background
if (ImGui::Begin("MouseInfoContext", NULL, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav))
{
ImGuiToolkit::PushFont(ImGuiToolkit::FONT_MONO);
ImGui::Text(" %s", c.info.c_str());
ImGui::PopFont();
ImGui::End();
}
setMouseCursor(c);
}
else {
// Log::Info("Mouse drag (%.1f,%.1f)(%.1f,%.1f)", io.MouseClickedPos[0].x, io.MouseClickedPos[0].y, io.MousePos.x, io.MousePos.y);

View File

@@ -144,7 +144,6 @@ protected:
void handleKeyboard();
void handleMouse();
void handleScreenshot();
};
#endif /* #define __UI_MANAGER_H_ */

View File

@@ -107,7 +107,7 @@ MixingView::MixingView() : View(MIXING)
if ( Settings::application.views[mode_].name.empty() ) {
// no settings found: store application default
Settings::application.views[mode_].name = "Mixing";
scene.root()->scale_ = glm::vec3(2.4f, 2.4f, 1.0f);
scene.root()->scale_ = glm::vec3(MIXING_DEFAULT_SCALE, MIXING_DEFAULT_SCALE, 1.0f);
scene.root()->translation_ = glm::vec3(1.0f, 0.0f, 0.0f);
saveSettings();
}
@@ -117,9 +117,8 @@ MixingView::MixingView() : View(MIXING)
disk->setTexture(textureMixingQuadratic());
scene.bg()->attach(disk);
glm::vec4 pink( 0.8f, 0.f, 0.8f, 1.f );
Mesh *circle = new Mesh("mesh/circle.ply");
circle->shader()->color = pink;
circle->shader()->color = glm::vec4( COLOR_FRAME, 1.f );
scene.bg()->attach(circle);
}
@@ -127,11 +126,22 @@ MixingView::MixingView() : View(MIXING)
void MixingView::zoom( float factor )
{
float z = scene.root()->scale_.x;
z = CLAMP( z + 0.1f * factor, 0.2f, 10.f);
z = CLAMP( z + 0.1f * factor, MIXING_MIN_SCALE, MIXING_MAX_SCALE);
scene.root()->scale_.x = z;
scene.root()->scale_.y = z;
}
void MixingView::centerSource(Source *s)
{
// setup view so that the center of the source ends at screen coordinates (650, 150)
// -> this is just next to the navigation pannel
glm::vec3 pos_to = Rendering::manager().unProject( glm::vec2(650.f, 150.f) , scene.root()->transform_);
glm::vec4 pos_delta = glm::vec4(pos_to.x, pos_to.y, 0.f, 0.f) - glm::vec4(s->group(View::MIXING)->translation_, 0.f);
pos_delta = scene.root()->transform_ * pos_delta;
scene.root()->translation_ += glm::vec3(pos_delta);
}
View::Cursor MixingView::grab (glm::vec2 from, glm::vec2 to, Source *s, std::pair<Node *, glm::vec2>)
{
if (!s)
@@ -251,7 +261,7 @@ GeometryView::GeometryView() : View(GEOMETRY)
if ( Settings::application.views[mode_].name.empty() ) {
// no settings found: store application default
Settings::application.views[mode_].name = "Geometry";
scene.root()->scale_ = glm::vec3(1.2f, 1.2f, 1.0f);
scene.root()->scale_ = glm::vec3(GEOMETRY_DEFAULT_SCALE, GEOMETRY_DEFAULT_SCALE, 1.0f);
saveSettings();
}
@@ -260,7 +270,7 @@ GeometryView::GeometryView() : View(GEOMETRY)
scene.bg()->attach(rect);
Frame *border = new Frame(Frame::SHARP_THIN);
border->color = glm::vec4( 0.8f, 0.f, 0.8f, 1.f );
border->color = glm::vec4( COLOR_FRAME, 1.f );
scene.fg()->attach(border);
}
@@ -288,7 +298,7 @@ void GeometryView::update(float dt)
void GeometryView::zoom( float factor )
{
float z = scene.root()->scale_.x;
z = CLAMP( z + 0.1f * factor, 0.2f, 10.f);
z = CLAMP( z + 0.1f * factor, GEOMETRY_MIN_SCALE, GEOMETRY_MAX_SCALE);
scene.root()->scale_.x = z;
scene.root()->scale_.y = z;
}
@@ -482,8 +492,8 @@ LayerView::LayerView() : View(LAYER), aspect_ratio(1.f)
if ( Settings::application.views[mode_].name.empty() ) {
// no settings found: store application default
Settings::application.views[mode_].name = "Layer";
scene.root()->scale_ = glm::vec3(0.8f, 0.8f, 1.0f);
scene.root()->translation_ = glm::vec3(1.3f, 0.5f, 0.0f);
scene.root()->scale_ = glm::vec3(LAYER_DEFAULT_SCALE, LAYER_DEFAULT_SCALE, 1.0f);
scene.root()->translation_ = glm::vec3(1.3f, 1.f, 0.0f);
saveSettings();
}
@@ -497,7 +507,7 @@ LayerView::LayerView() : View(LAYER), aspect_ratio(1.f)
scene.bg()->attach(persp);
Frame *border = new Frame(Frame::ROUND_SHADOW);
border->color = glm::vec4( 0.8f, 0.f, 0.8f, 0.7f );
border->color = glm::vec4( COLOR_FRAME, 0.7f );
scene.bg()->attach(border);
}
@@ -525,7 +535,7 @@ void LayerView::update(float dt)
void LayerView::zoom (float factor)
{
float z = scene.root()->scale_.x;
z = CLAMP( z + 0.1f * factor, 0.2f, 10.f);
z = CLAMP( z + 0.1f * factor, LAYER_MIN_SCALE, LAYER_MAX_SCALE);
scene.root()->scale_.x = z;
scene.root()->scale_.y = z;
}

5
View.h
View File

@@ -20,7 +20,9 @@ public:
virtual void update (float dt);
virtual void draw ();
virtual void zoom (float) {}
virtual void centerSource(Source *) {}
typedef enum {
Cursor_Arrow = 0,
@@ -50,6 +52,7 @@ public:
return Cursor();
}
virtual void restoreSettings();
virtual void saveSettings();
@@ -69,6 +72,8 @@ public:
MixingView();
void zoom (float factor) override;
void centerSource(Source *) override;
Cursor grab (glm::vec2 from, glm::vec2 to, Source *s, std::pair<Node *, glm::vec2>) override;
private:

View File

@@ -28,6 +28,15 @@
#define MIN_SCALE 0.01f
#define MAX_SCALE 10.f
#define CLAMP_SCALE(x) SIGN(x) * CLAMP( ABS(x), MIN_SCALE, MAX_SCALE)
#define MIXING_DEFAULT_SCALE 2.4f
#define MIXING_MIN_SCALE 0.8f
#define MIXING_MAX_SCALE 7.0f
#define GEOMETRY_DEFAULT_SCALE 1.2f
#define GEOMETRY_MIN_SCALE 0.2f
#define GEOMETRY_MAX_SCALE 10.0f
#define LAYER_DEFAULT_SCALE 0.8f
#define LAYER_MIN_SCALE 0.4f
#define LAYER_MAX_SCALE 1.7f
#define IMGUI_TITLE_MAINWINDOW ICON_FA_CIRCLE_NOTCH " vimix"
#define IMGUI_TITLE_MEDIAPLAYER ICON_FA_FILM " Media Player"
@@ -47,6 +56,7 @@
#define COLOR_NAVIGATOR 0.1f, 0.1f, 0.1f
#define COLOR_DEFAULT_SOURCE 0.8f, 0.8f, 0.8f
#define COLOR_HIGHLIGHT_SOURCE 1.f, 1.f, 1.f
#define COLOR_FRAME 0.8f, 0.f, 0.8f
// from glmixer
#define TEXTURE_REQUIRED_MAXIMUM 2048
@@ -77,7 +87,6 @@
#define COLOR_LIMBO_CIRCLE 210, 160, 210
#define COLOR_FADING 25, 25, 25
#define COLOR_FLASHING 250, 250, 250
#define COLOR_FRAME 210, 30, 210
#define COLOR_FRAME_MOVE 230, 30, 230
#define COLOR_CURSOR 10, 100, 255