Milo  0.1
Milo:EquationManipulationProgram
panel.h
Go to the documentation of this file.
1 #ifndef __PANEL_H
2 #define __PANEL_H
3 
4 /* Copyright (C) 2018 - James Terman
5  *
6  * milo is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * milo 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 GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
26 #include <iostream>
27 #include <unordered_map>
28 #include <string>
29 #include <memory>
30 #include "ui.h"
31 
36 namespace UI {
37 
41  class EqnPanel : public MiloPanel
42  {
43  public:
50  using key_handler = bool (*)(EqnPanel&, const KeyEvent&);
51 
56  using mouse_handler = bool (*)(EqnPanel&, const MouseEvent&);
57 
62  using menu_handler = bool (*)(EqnPanel&);
64 
69  EqnPanel() : MiloPanel(), m_eqn(new Equation("#")) {}
70 
73  EqnPanel(std::istream& is) : MiloPanel(), m_eqn(new Equation(is)) {}
74 
77  EqnPanel(const std::string& eq) : MiloPanel(), m_eqn(new Equation(eq)) {}
78 
79  ~EqnPanel() {}
80 
81 
88  void doKey(const KeyEvent& key);
89 
93  void doMouse(const MouseEvent& mouse);
94 
100  bool doMenu(const std::string& menuFunctionName);
101 
104  void doDraw();
105 
109  void pushUndo();
110 
114  void popUndo();
115 
120  void saveState(std::ostream& fs);
121 
126  void loadState(std::istream& is);
127 
132  bool blink();
133 
139  void getCursorOrig(int& x, int& y);
141 
148  Equation& getEqn() { return *m_eqn; }
149 
155  Equation& newEqn(std::string eq) {
156  m_eqn.reset(new Equation(eq));
157  return *m_eqn;
158  }
159 
165  Equation& newEqn(std::istream& is) {
166  m_eqn.reset(new Equation(is));
167  return *m_eqn;
168  }
169 
174  void set_refresh(bool refresh) { m_fRefresh = refresh; }
176 
177  static const std::string name;
178  private:
181  bool m_fRefresh = true;
182  Node* m_start_select = nullptr;
183  int m_start_mouse_x = -1;
184  int m_start_mouse_y = -1;
185  static bool init;
186 
192  static bool do_init();
193 
200  static bool emit_key(EqnPanel& panel, const KeyEvent& key);
202 
208  static const std::unordered_map<MouseEvent, mouse_handler> mouse_event_map;
209 
213  static const std::unordered_map<KeyEvent, key_handler> key_event_map;
214 
218  static const std::unordered_map<std::string, menu_handler> menu_map;
220 
229  bool do_alphaNumber(const KeyEvent& event);
230 
237  bool do_backspace(const KeyEvent& event);
238 
245  bool do_left(const KeyEvent& event);
246 
253  bool do_right(const KeyEvent& event);
254 
262  bool do_shift_left(const KeyEvent& event);
263 
271  bool do_shift_right(const KeyEvent& event);
272 
281  bool do_up(const KeyEvent& event);
282 
291  bool do_down(const KeyEvent& event);
292 
300  bool do_shift_up(const KeyEvent& event);
301 
309  bool do_shift_down(const KeyEvent& event);
310 
318  bool do_enter(const KeyEvent& event);
319 
326  bool do_tab(const KeyEvent& event);
327 
335  bool do_plus_minus(const KeyEvent& event);
336 
342  bool do_divide(const KeyEvent& event);
343 
349  bool do_power(const KeyEvent& event);
350 
358  bool do_left_parenthesis(const KeyEvent& event);
359 
366  bool do_space(const KeyEvent& event);
367 
374  bool do_mouse_pressed(const MouseEvent& mouse);
375 
383  bool do_mouse_released(const MouseEvent& mouse);
384 
391  bool do_mouse_clicked(const MouseEvent& mouse);
392 
400  bool do_mouse_double(const MouseEvent& mouse);
401 
408  bool do_mouse_position(const MouseEvent& mouse);
410  };
411 
412 }
413 
414 #endif // __PANEL_H
void getCursorOrig(int &x, int &y)
Definition: eqn.cpp:689
Definition: ui.h:569
EqnPanel(const std::string &eq)
Definition: panel.h:77
void set_refresh(bool refresh)
Definition: panel.h:174
Definition: milo.h:45
Definition: milo.h:72
std::shared_ptr< Equation > EqnPtr
Shared pointer for equation.
Definition: milo.h:65
bool(*)(EqnPanel &, const MouseEvent &) mouse_handler
Definition: panel.h:56
void doKey(const KeyEvent &key)
Definition: eqn.cpp:609
Node * m_start_select
If not null, node is selected.
Definition: panel.h:182
bool do_shift_up(const KeyEvent &event)
Definition: eqn.cpp:246
bool do_up(const KeyEvent &event)
Definition: eqn.cpp:197
static const std::unordered_map< MouseEvent, mouse_handler > mouse_event_map
Definition: panel.h:208
Definition: milo.h:1798
int m_start_mouse_x
Horiz coord of start of mouse drag.
Definition: panel.h:183
void doMouse(const MouseEvent &mouse)
Definition: eqn.cpp:622
bool do_power(const KeyEvent &event)
Definition: eqn.cpp:345
static bool init
Should be true after static initilization.
Definition: panel.h:185
Definition: ui.h:104
bool do_mouse_released(const MouseEvent &mouse)
Definition: eqn.cpp:427
bool do_shift_left(const KeyEvent &event)
Definition: eqn.cpp:149
bool do_plus_minus(const KeyEvent &event)
Definition: eqn.cpp:319
EqnPanel panel
Asciigraphics class objects.
Definition: milo_test.cpp:265
static bool emit_key(EqnPanel &panel, const KeyEvent &key)
Definition: eqn.cpp:519
bool do_tab(const KeyEvent &event)
Definition: eqn.cpp:312
EqnPtr m_eqn
Shared pointer to current equation.
Definition: panel.h:179
bool do_mouse_double(const MouseEvent &mouse)
Definition: eqn.cpp:454
void loadState(std::istream &is)
Definition: eqn.cpp:678
static const std::string name
Name of this panel.
Definition: panel.h:177
bool doMenu(const std::string &menuFunctionName)
Definition: eqn.cpp:640
bool do_shift_down(const KeyEvent &event)
Definition: eqn.cpp:269
bool do_left(const KeyEvent &event)
Definition: eqn.cpp:84
EqnUndoList m_eqns
Equation undo stack.
Definition: panel.h:180
bool m_fRefresh
Refresh on very draw by default.
Definition: panel.h:181
Definition: ui.h:235
EqnPanel()
Definition: panel.h:69
bool do_mouse_position(const MouseEvent &mouse)
Definition: eqn.cpp:473
bool do_left_parenthesis(const KeyEvent &event)
Definition: eqn.cpp:354
bool do_mouse_pressed(const MouseEvent &mouse)
Definition: eqn.cpp:411
void popUndo()
Definition: eqn.cpp:661
Definition: milo.h:1326
static const std::unordered_map< std::string, menu_handler > menu_map
Definition: panel.h:218
bool do_backspace(const KeyEvent &event)
Definition: eqn.cpp:53
bool do_right(const KeyEvent &event)
Definition: eqn.cpp:115
bool blink()
Definition: eqn.cpp:684
~EqnPanel()
Virtual desctructor.
Definition: panel.h:79
bool do_space(const KeyEvent &event)
Definition: eqn.cpp:365
bool do_alphaNumber(const KeyEvent &event)
Definition: eqn.cpp:39
bool do_mouse_clicked(const MouseEvent &mouse)
Definition: eqn.cpp:439
Equation & newEqn(std::istream &is)
Definition: panel.h:165
void saveState(std::ostream &fs)
Definition: eqn.cpp:671
bool do_down(const KeyEvent &event)
Definition: eqn.cpp:221
Equation & newEqn(std::string eq)
Definition: panel.h:155
bool(*)(EqnPanel &, const KeyEvent &) key_handler
Definition: panel.h:50
bool do_divide(const KeyEvent &event)
Definition: eqn.cpp:336
Equation & getEqn()
Definition: panel.h:148
bool(*)(EqnPanel &) menu_handler
Definition: panel.h:62
void doDraw()
Definition: eqn.cpp:694
static const std::unordered_map< KeyEvent, key_handler > key_event_map
Definition: panel.h:213
bool do_shift_right(const KeyEvent &event)
Definition: eqn.cpp:173
void pushUndo()
Definition: eqn.cpp:655
int m_start_mouse_y
Vertical coord of start of mouse drag.
Definition: panel.h:184
static bool do_init()
Definition: eqn.cpp:33
Definition: panel.h:41
EqnPanel(std::istream &is)
Definition: panel.h:73
bool do_enter(const KeyEvent &event)
Definition: eqn.cpp:292