Minsky
variablePane.h
Go to the documentation of this file.
1 /*
2  @copyright Steve Keen 2022
3  @author Russell Standish
4  This file is part of Minsky.
5 
6  Minsky is free software: you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Minsky is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Minsky. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef VARIABLEPANE_H
21 #define VARIABLEPANE_H
22 #include "cairo.h"
23 #include "classdesc_access.h"
24 #include "grid.h"
25 #include "pannableTab.h"
26 #include "variable.h"
27 #include "renderNativeWindow.h"
28 #include <vector>
29 
30 namespace minsky
31 {
33  {
35  double m_width=0, m_height=0;
36  cairo_t* cachedCairo=nullptr;
38  public:
41  void reset(cairo_t* cairo) {cachedCairo=cairo;}
42  void show();
43  double width() const {return m_width+2;}
44  double height() const {return m_height+4;}
45  void emplace() const;
46  const VariableBase& variable() const;
47  };
48 
50 
51  class VariablePane: public Grid<VariablePaneCell>, public PannableTab<VariablePaneBase>, public VariableType
52  {
53  unsigned m_numRows=0, m_numCols=0;
54  classdesc::Exclude<std::vector<VariablePaneCell>> vars;
56  bool redraw(int, int, int width, int height) override;
57  public:
58  bool shift=false;
59  std::set<Type> selection;
61  void select(VariableType::Type x) {selection.insert(x);}
63  VariablePaneCell& cell(unsigned row, unsigned col) override;
65  void updateWithHeight(unsigned height);
67  void update();
68  unsigned numRows() const override {return m_numRows;}
69  unsigned numCols() const override {return m_numCols;}
70  bool evenHeight() const override {return false;}
71  void moveCursorTo(double,double) override;
72  void mouseDown(float x,float y) override {
74  cell(rowY(y-offsy),colX(x-offsx)).emplace();
75  }
76  };
77 }
78 #include "variablePane.cd"
79 #endif
bool evenHeight() const override
whether cells all have the same height or not
Definition: variablePane.h:70
bool shift
true if shift pressed
Definition: variablePane.h:58
void mouseDown(float x, float y) override
Definition: pannableTab.h:44
void update()
update variables from model, using previous height value
Definition: variablePane.cc:89
void deselect(VariableType::Type x)
Definition: variablePane.h:62
void reset(cairo_t *cairo)
Definition: variablePane.h:41
std::set< Type > selection
Definition: variablePane.h:59
unsigned numRows() const override
Definition: variablePane.h:68
CLASSDESC_ACCESS(VariablePaneCell)
double height() const
Definition: variablePane.h:44
const VariableBase & variable() const
Definition: variablePane.cc:63
void select(VariableType::Type x)
Definition: variablePane.h:61
int colX(double x) const
column at x in unzoomed coordinates
Definition: grid.cc:103
Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky&#39;s state cha...
Definition: constMap.h:22
bool redraw(int, int, int width, int height) override
Mixin implementing common panning functionality in tabs.
Definition: pannableTab.h:36
double width() const
Definition: variablePane.h:43
int rowY(double y) const
row at y in unzoomed coordinates
Definition: grid.cc:112
void moveCursorTo(double, double) override
move current cursor to x,y
void mouseDown(float x, float y) override
Definition: variablePane.h:72
unsigned numCols() const override
Definition: variablePane.h:69
VariablePaneCell & cell(unsigned row, unsigned col) override
return reference to cell row, col. Reference is valid until next call to cell()
Definition: variablePane.cc:70
classdesc::Exclude< std::vector< VariablePaneCell > > vars
Definition: variablePane.h:54
void updateWithHeight(unsigned height)
update variables from model, given a window of height pixels
Definition: variablePane.cc:81
CLASSDESC_ACCESS(VariablePane)