29 #include <unordered_map> 68 NONE, CTRL_A, CTRL_B, CTRL_C, CTRL_D, CTRL_E, CTRL_F, CTRL_G, CTRL_H,
69 TAB, ENTER, CTRL_K, CTRL_L, CTRL_M, CTRL_N, CTRL_O, CTRL_P, CTRL_Q,
70 CTRL_R, CTRL_S, CTRL_T, CTRL_U, CTRL_V, CTRL_W, CTRL_X, CTRL_Y, CTRL_Z, ESC,
71 SPACE = 32, BANG, DBL_QUOTE, HASH, DOLLAR, PERCENT, AMP, QUOTE, L_PAR, R_PAR,
72 STAR, PLUS, COMMA, MINUS, DOT, DIVIDE, K0, K1, K2, K3, K4, K5, K6, K7, K8, K9,
73 COLON, SEMI, LESS, EQUAL, GREATER, QUESTION, AT, A, B, C, D, E, F, G, H, I, J, K,
74 L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, L_BRACKET, B_SLASH, R_BRACKET,
75 POWER, U_SCORE, ACCENT, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r,
76 s, t, u, v, w, x, y, z, L_BRACE, PIPE, R_BRACE, TILDE,
77 F1 = 0x80, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12,
78 INS, DEL, HOME, END, PAGE_UP, PAGE_DOWN, UP, DOWN, LEFT, RIGHT, BSPACE
88 NO_MOUSE, POSITION, PRESSED, RELEASED, CLICKED, DOUBLE
95 NO_MOD, ALT, SHIFT, ALT_SHIFT, CTRL, CRL_ALT, CTRL_SHIFT, CTRL_ALT_SHIFT
118 m_type{t}, m_button{b}, m_mod{md}, m_x{mouse_x}, m_y{mouse_y} {}
126 void setCoords(
int mouse_x,
int mouse_y) { m_x = mouse_x; m_y = mouse_y; }
130 enum Mouse getMouse()
const {
return m_type; }
139 void getCoords(
int& mouse_x,
int& mouse_y)
const { mouse_x = m_x; mouse_y = m_y; }
145 bool noMod()
const {
return (m_mod == 0) ?
true :
false; }
151 bool shiftMod()
const {
return (m_mod && Modifiers::SHIFT != 0) ?
true :
false; }
157 bool altMod()
const {
return (m_mod && Modifiers::ALT != 0) ?
true :
false; }
162 operator bool()
const {
return m_type !=NO_MOUSE; }
173 return hash_calculate<int>({(int) m_type, m_button, (
int) m_mod});
183 return e.
m_type == m_type &&
207 std::string toString()
const;
275 bool noMod()
const {
return (m_mod == 0) ?
true :
false; }
281 bool shiftMod()
const {
return (m_mod && Modifiers::SHIFT != 0) ?
true :
false; }
287 bool altMod()
const {
return (m_mod && Modifiers::ALT != 0) ?
true :
false; }
292 operator bool()
const {
return m_key != Keys::NONE; }
303 return hash_calculate<int>({(int) m_key, (
int) m_mod});
313 return e.
m_key == m_key &&
333 std::string toString()
const;
375 enum Color { BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE };
390 virtual void differential(
int x0,
int y0,
char variable)=0;
399 virtual void parenthesis(
int x_size,
int y_size,
int x0,
int y0)=0;
407 virtual void horiz_line(
int x_size,
int x0,
int y0)=0;
417 virtual void at(
int x0,
int y0,
int c,
Attributes chrAttr,
Color color = BLACK)=0;
427 virtual void at(
int x0,
int y0,
const std::string& s,
Attributes chrAttr,
Color color = BLACK)=0;
432 virtual void clear_screen()=0;
437 virtual void out()=0;
443 virtual int getTextHeight()=0;
449 virtual int getTextLength(
const std::string& s)=0;
455 virtual int getCharLength(
char c)=0;
461 virtual int getParenthesisWidth(
int height = 1)=0;
467 virtual int getDivideLineHeight()=0;
474 virtual int getDifferentialHeight(
char c)=0;
481 virtual int getDifferentialWidth(
char c)=0;
488 virtual int getDifferentialBase(
char c)=0;
497 virtual void set(
int x,
int y,
int x0 = 0,
int y0 = 0) {
498 m_xSize = x; m_ySize = y; m_xOrig = x0, m_yOrig = y0;
508 virtual void setSelect(
int x,
int y,
int x0,
int y0) { m_select.set(x, y, x0, y0); }
517 void set(
const Box& box) {
518 set(box.width(), box.height(), box.x0(), box.y0());
564 using panel_factory =
MiloPanelPtr (*)(
const std::string&);
602 virtual bool doMenu(
const std::string& menuFunctionName) = 0;
606 virtual void doDraw() = 0;
611 virtual void pushUndo()=0;
616 virtual void popUndo()=0;
622 virtual void saveState(std::ostream& fs) = 0;
628 virtual void loadState(std::istream& is) = 0;
635 std::fstream out(filename, std::fstream::out | std::fstream::trunc);
644 std::ifstream ifs(filename);
652 virtual bool blink() = 0;
659 virtual void getCursorOrig(
int& x,
int& y) = 0;
668 static MiloPanelPtr makePanel(
const std::string& name,
const std::string& init);
671 static std::unordered_map<std::string, panel_factory>
panel_map;
687 m_panels({panel}), m_current_panel(m_panels.begin()) {}
710 m_current_panel =
AddAfter(m_panels, m_current_panel, panel);
718 m_current_panel = m_panels.erase(it);
725 m_current_panel = m_panels.erase(m_current_panel);
734 virtual void makeTopWindow()=0;
753 virtual void redraw_screen()=0;
767 void doMenu(
const std::string& menuFunctionName);
773 static bool isRunning();
786 m_current_window =
AddAfter(m_windows, m_current_window, win);
793 m_current_window = m_windows.erase(m_current_window);
801 m_current_window = m_windows.erase(it);
825 m_windows({win}), m_current_window(m_windows.begin()) {}
843 static std::unordered_map<std::string, menu_handler>
menu_map;
858 virtual void define_menu(
const StringMap& attributes)=0;
864 virtual void define_menu_end(
const std::string& name)=0;
870 virtual void define_menu_item(
const StringMap& attributes)=0;
875 virtual void define_menu_line()=0;
895 template<>
struct hash<
UI::KeyEvent>
906 template<>
struct hash<
UI::MouseEvent>
bool equals(const KeyEvent e) const
Definition: ui.h:311
bool shiftMod() const
Definition: ui.h:281
static MiloApp & getGlobal()
Definition: ui.h:809
void closeWindow()
Definition: ui.h:792
static std::unordered_map< std::string, menu_handler > menu_map
Definition: ui.h:843
void saveState(const std::string &filename)
Definition: ui.h:634
int m_ySize
Vertical size of graphic window.
Definition: ui.h:547
int & x0()
Definition: util.h:237
int m_xSize
Horizontal size of graphic window.
Definition: ui.h:546
static std::unordered_map< std::string, panel_factory > panel_map
Map of name to panel create functions.
Definition: ui.h:671
virtual void setSelect(int x, int y, int x0, int y0)
Definition: ui.h:508
void setSelect(const Box &box)
Definition: ui.h:525
MiloWindowIter m_current_window
Current active window.
Definition: ui.h:834
void addPanel(MiloPanelPtr panel)
Definition: ui.h:709
MiloWindow & getWindow()
Definition: ui.h:779
MiloWindow(MiloPanelPtr panel)
Definition: ui.h:686
bool equals(const MouseEvent &e) const
Definition: ui.h:181
int & y0()
Definition: util.h:243
KeyEvent & operator=(const KeyEvent &e)
Definition: ui.h:322
typename std::vector< SmartPtr< MiloWindow > >::iterator iterator
Definition: smart.h:88
MouseEvent & operator=(const MouseEvent &e)
Definition: ui.h:193
enum Modifiers m_mod
Modifiers state.
Definition: ui.h:213
int getButton() const
Definition: ui.h:131
void setCoords(int mouse_x, int mouse_y)
Definition: ui.h:126
MiloWindowVector::iterator MiloWindowIter
Iterator of MiloWindow pointers vector.
Definition: ui.h:50
MiloPanelIter m_current_panel
Current active panel.
Definition: ui.h:739
int m_button
Number of button pressed.
Definition: ui.h:212
KeyEvent(Keyboard key, enum Modifiers md=NO_MOD)
Definition: ui.h:245
bool noMod() const
Definition: ui.h:275
Modifiers
Definition: ui.h:94
Graphics()
Definition: ui.h:364
int m_y
mouse y-coordinate.
Definition: ui.h:215
EqnPanel panel
Asciigraphics class objects.
Definition: milo_test.cpp:265
std::size_t hash() const
Definition: ui.h:301
std::size_t hash() const
Definition: ui.h:171
void deletePanel(MiloPanelIter it)
Definition: ui.h:717
bool noMod() const
Definition: ui.h:145
void(*)(void) menu_handler
Definition: ui.h:59
MiloPanelVector::iterator MiloPanelIter
Iterator of MiloPanel pointers vector.
Definition: ui.h:53
Keyboard getKey() const
Definition: ui.h:268
void getCoords(int &mouse_x, int &mouse_y) const
Definition: ui.h:139
std::unordered_map< std::string, std::string > StringMap
hash map for string => string
Definition: util.h:363
int & height()
Definition: util.h:255
Keyboard m_key
Key code.
Definition: ui.h:337
void closeWindow(MiloWindowIter it)
Definition: ui.h:800
enum Modifiers m_mod
Modifiers state.
Definition: ui.h:338
KeyEvent(char key, enum Modifiers md=NO_MOD)
Definition: ui.h:252
enum Mouse m_type
Mouse click type.
Definition: ui.h:211
void addWindow(MiloWindowPtr win)
Definition: ui.h:785
Attributes
Definition: ui.h:380
bool altMod() const
Definition: ui.h:287
MiloApp(MiloWindowPtr win)
Definition: ui.h:824
MiloPanelVector m_panels
List of panels for this window.
Definition: ui.h:738
static MiloApp & m_current
Reference to current application singleton.
Definition: ui.h:836
Box m_select
Currently selected area.
Definition: ui.h:550
SmartPtr< MiloPanel > MiloPanelPtr
Smart pointer for MiloPanel.
Definition: ui.h:51
MiloPanel & getPanel()
Definition: ui.h:703
int m_xOrig
Horizontal origin of graphic window.
Definition: ui.h:548
int m_x
mouse x-coordinate.
Definition: ui.h:214
void relativeOrig(int &x, int &y)
Definition: ui.h:542
int m_yOrig
Vertical origin of graphic window.
Definition: ui.h:549
~MiloPanel()
Definition: ui.h:580
void deletePanel()
Definition: ui.h:724
virtual ~MiloWindow()
Definition: ui.h:694
MiloPanel()
Definition: ui.h:576
MouseEvent(enum Mouse t, int b, enum Modifiers md=NO_MOD, int mouse_x=-1, int mouse_y=-1)
Definition: ui.h:117
int & width()
Definition: util.h:249
MiloPanelPtr createPanel(const std::string &init)
Definition: ui.h:559
MiloWindowVector m_windows
List of windows for this application.
Definition: ui.h:833
bool operator==(const MouseEvent &m1, const MouseEvent &m2)
Definition: ui.h:224
void loadState(const std::string &filename)
Definition: ui.h:643
~MiloApp()
Definition: ui.h:830
auto AddAfter(std::vector< T > &v, decltype(v.begin()) it, const T &elem) -> decltype(v.begin())
Definition: util.h:147
void parenthesis(const Box &box)
Definition: ui.h:533
constexpr KeyEvent(const KeyEvent &e)
Definition: ui.h:263
bool altMod() const
Definition: ui.h:157
Key_Values
Definition: ui.h:67
Color
Definition: ui.h:375
bool shiftMod() const
Definition: ui.h:151
MiloApp()
Definition: ui.h:818
virtual ~Graphics()
Definition: ui.h:369