Mouse Wheel zoom. Zoom is scaled to be relative to current zoom level.
This commit is contained in:
@@ -118,6 +118,10 @@ public:
|
||||
/// Passes the current window size to subordinate objects, such as the JUI scene.
|
||||
void PropagateWindowSize();
|
||||
|
||||
void ZoomIn(float rate);
|
||||
|
||||
void ZoomOut(float rate);
|
||||
|
||||
/// Performs a logic update.
|
||||
void Update(float elapsed);
|
||||
|
||||
@@ -144,6 +148,15 @@ public:
|
||||
/// Called by the ReWindow base when the user presses a key.
|
||||
void OnKeyUp(const ReWindow::KeyUpEvent &e) override;
|
||||
|
||||
void OnMouseWheel(const ReWindow::MouseWheelEvent &e) override {
|
||||
if (e.WheelMovement > 0) {
|
||||
ZoomOut(0.1);
|
||||
}
|
||||
if (e.WheelMovement < 0) {
|
||||
ZoomIn(0.1);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
@@ -68,6 +68,7 @@ float iterate_mandelbrot(vec2 p) {
|
||||
void main() {
|
||||
vec2 R = u_resolution.xy;
|
||||
|
||||
|
||||
// Unused as of yet, see TODOs for what and why.
|
||||
float scale = (3.0 - u_scale);
|
||||
|
||||
|
@@ -404,6 +404,25 @@ void FractalInspectorApp::PropagateWindowSize() {
|
||||
//canvas->Resize(vSize);
|
||||
}
|
||||
|
||||
|
||||
void FractalInspectorApp::ZoomIn(float rate) {
|
||||
|
||||
rate = rate * u_scale;
|
||||
|
||||
u_scale -= rate;
|
||||
// Stupid hack to make zoom originate at the center of the screen.
|
||||
u_translation -= Vector2(0.5f, 0.5f)*rate;
|
||||
}
|
||||
|
||||
void FractalInspectorApp::ZoomOut(float rate) {
|
||||
|
||||
rate = rate * u_scale;
|
||||
|
||||
u_scale += rate;
|
||||
// Stupid hack to make zoom originate at the center of the screen.
|
||||
u_translation += Vector2(0.5f, 0.5f)*rate;
|
||||
}
|
||||
|
||||
void FractalInspectorApp::Update(float elapsed) {
|
||||
scene->Update(elapsed);
|
||||
|
||||
@@ -413,7 +432,7 @@ void FractalInspectorApp::Update(float elapsed) {
|
||||
}
|
||||
|
||||
// TODO: Vary the rate appropriately.
|
||||
float rate = elapsed * 0.25f;
|
||||
float rate = elapsed * 0.5f;
|
||||
|
||||
if (IsKeyDown(Keys::LeftShift))
|
||||
rate *= 0.125f;
|
||||
@@ -421,17 +440,12 @@ void FractalInspectorApp::Update(float elapsed) {
|
||||
if (IsKeyDown(Keys::LeftControl))
|
||||
rate *= 0.125f;
|
||||
|
||||
if (IsKeyDown(Keys::Minus)) {
|
||||
u_scale += rate;
|
||||
// Stupid hack to make zoom originate at the center of the screen.
|
||||
u_translation += Vector2(0.5f, 0.5f)*rate;
|
||||
}
|
||||
if (IsKeyDown(Keys::Minus))
|
||||
ZoomOut(rate);
|
||||
|
||||
if (IsKeyDown(Keys::Equals))
|
||||
ZoomIn(rate);
|
||||
|
||||
if (IsKeyDown(Keys::Equals)) {
|
||||
u_scale -= rate;
|
||||
// Stupid hack to make zoom originate at the center of the screen.
|
||||
u_translation -= Vector2(0.5f, 0.5f)*rate;
|
||||
}
|
||||
|
||||
|
||||
if (IsKeyDown(Keys::DownArrow))
|
||||
|
Reference in New Issue
Block a user