Snoke
application.cpp
Go to the documentation of this file.
1 #include "application.h"
2 
7 {
10 }
11 
16 {
17  bool esc = false;
18 
19  while (!esc)
20  {
21  int command = getch();
22  Widget* previous = currentWidget;
23 
24  if (command != ERR)
25  {
26  switch(command)
27  {
28  case (KEY_UP):
29 
31  previous->dispatch(EVENT_UNFOCUS);
33  break;
34 
35  case (KEY_DOWN):
36 
38  previous->dispatch(EVENT_UNFOCUS);
40  break;
41 
42  case (27):
43 
44  esc = true;
45  break;
46  }
47  }
48  }
49 }
50 
55 void Application::load(char* name)
56 {
57  history.push_back(currentScreen);
58  currentScreen = screens[name];
60  focusFirst();
61 }
62 
68 {
69  history.pop_back();
70  currentScreen = *(std::prev(history.end(), 1));
72  focusFirst();
73 }
74 
80 void Application::add(char* name, Screen* screen)
81 {
82  screens.insert(std::pair<char*, Screen*>(name, screen));
83 }
84 
91 {
92  static Application app;
93  return app;
94 }
95 
101 {}
102 
Widget * previous(Widget *current)
Definition: screen.cpp:79
Widget * currentWidget
Definition: application.h:26
static Application & instance()
Definition: application.cpp:90
virtual void draw()
Definition: screen.cpp:7
Definition: screen.h:10
std::list< Screen * > history
Definition: application.h:24
#define EVENT_FOCUS
Definition: widget.h:14
void load(char *name)
Definition: application.cpp:55
void add(char *name, Screen *screen)
Definition: application.cpp:80
#define EVENT_UNFOCUS
Definition: widget.h:15
void dispatch(unsigned char name)
Definition: widget.cpp:161
Screen * currentScreen
Definition: application.h:25
std::map< char *, Screen * > screens
Definition: application.h:23
Definition: widget.h:36
Widget * first()
Definition: screen.cpp:14
Application & app
void execute()
Definition: application.cpp:15
Widget * next(Widget *current)
Definition: screen.cpp:24
void focusFirst()
Definition: application.cpp:6