Euphoria
canvaslogic.cc
Go to the documentation of this file.
1 #include "core/canvaslogic.h"
2 #include "base/numeric.h"
3 
4 namespace eu::core
5 {
6  void
8  {
9  scroll += p;
10  }
11 
12  void
13  CanvasLogic::zoom(const vec2f& mouse, float zoom)
14  {
15  // todo(Gustav): change to use screen_to_world
16  const auto focus = (mouse - scroll) / scale;
17 
18  const float scale_factor = 1 + 0.01f * abs(zoom);
19 
20  if(zoom < 0.0f)
21  {
22  scale /= scale_factor;
23  }
24 
25  if(zoom > 0.0f)
26  {
27  scale *= scale_factor;
28  }
29 
31 
32  // todo(Gustav): change to use world_to_screen
33  const auto new_focus = scroll + focus * scale;
34  scroll = scroll + vec2f::from_to(new_focus, mouse);
35  }
36 
37  vec2f
39  {
40  return scroll + p * scale;
41  }
42 
43  vec2f
45  {
46  return (p - scroll) / scale;
47  }
48 }
T keep_within(const Range< T > &range, T value)
Definition: range.h:115
constexpr float abs(float r)
Definition: numeric.h:8
void pan(const vec2f &p)
Definition: canvaslogic.cc:7
vec2f from_world_to_screen(const vec2f &p) const
Definition: canvaslogic.cc:38
void zoom(const vec2f &mouse, float zoom)
Definition: canvaslogic.cc:13
Range< float > scale_range
Definition: canvaslogic.h:15
vec2f from_screen_to_world(const vec2f &p) const
Definition: canvaslogic.cc:44
Definition: vec2.h:33
static vec2f from_to(const vec2f &from, const vec2f &to)
Definition: vec2.cc:83