Minsky
pannableTab.h
Go to the documentation of this file.
1 /*
2  @copyright Steve Keen 2021
3  @author Russell Standish
4  @author Wynand Dednam
5  This file is part of Minsky.
6 
7  Minsky is free software: you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  Minsky is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Minsky. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef PANNABLE_TAB_H
22 #define PANNABLE_TAB_H
23 #include "classdesc_access.h"
24 #include <vector>
25 
26 namespace minsky
27 {
29  {
30  float offsx=0, offsy=0;
31  double m_zoomFactor=1;
32  };
33 
35  template <class Base>
36  class PannableTab: public Base
37  {
38  bool mousePressed=false;
39  float deltaX, deltaY;
41  public:
43  template <class A> PannableTab(A& arg): Base(arg) {}
44  void mouseDown(float x, float y) override
45  {
46  deltaX=x-Base::offsx;
47  deltaY=y-Base::offsy;
48  mousePressed=true;
49  }
50  void mouseUp(float x, float y) override
51  {
52  mouseMove(x,y);
53  mousePressed=false;
54  }
55  void mouseMove(float x, float y) override
56  {
57  if (mousePressed)
58  {
59  Base::offsx=x-deltaX;
60  Base::offsy=y-deltaY;
61  Base::requestRedraw();
62  }
63  }
64  void moveTo(float x, float y) override
65  {
66  Base::offsx=x;
67  Base::offsy=y;
68  Base::requestRedraw();
69  }
70  std::vector<float> position() const override
71  {
72  return {Base::offsx, Base::offsy};
73  }
74  void zoom(double x, double y, double z) override {
75  Base::offsx=x+(Base::offsx-x)*z;
76  Base::offsy=y+(Base::offsy-y)*z;
77  Base::m_zoomFactor*=z;
78  Base::requestRedraw();
79  }
80 
81  double zoomFactor() const override {return Base::m_zoomFactor;}
82  };
83 }
84 
85 #include "pannableTab.cd"
86 #endif
void mouseDown(float x, float y) override
Definition: pannableTab.h:44
void mouseMove(float x, float y) override
Definition: pannableTab.h:55
void moveTo(float x, float y) override
Definition: pannableTab.h:64
Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky&#39;s state cha...
Definition: constMap.h:22
void zoom(double x, double y, double z) override
Definition: pannableTab.h:74
Mixin implementing common panning functionality in tabs.
Definition: pannableTab.h:36
double zoomFactor() const override
Definition: pannableTab.h:81
CLASSDESC_ACCESS(PannableTab)
void mouseUp(float x, float y) override
Definition: pannableTab.h:50
std::vector< float > position() const override
Definition: pannableTab.h:70