Numworks Epsilon  1.4.1
Graphing Calculator Operating System
container.cpp
Go to the documentation of this file.
1 #include <escher/container.h>
2 #include <assert.h>
3 
5  RunLoop(),
6  m_activeApp(nullptr)
7 {
8 }
9 
11  if (m_activeApp) {
12  delete m_activeApp;
13  }
14 }
15 
17  if (m_activeApp && snapshot == m_activeApp->snapshot()) {
18  return;
19  }
20  if (m_activeApp) {
21  m_activeApp->willBecomeInactive();
22  m_activeApp->snapshot()->pack(m_activeApp);
23  m_activeApp = nullptr;
24  }
25  if (snapshot) {
26  m_activeApp = snapshot->unpack(this);
27  }
28  if (m_activeApp) {
29  m_activeApp->didBecomeActive(window());
30  window()->redraw();
31  }
32 }
33 
35  return m_activeApp;
36 }
37 
39  if (event == Ion::Events::TimerFire || m_activeApp->processEvent(event)) {
40  window()->redraw();
41  return true;
42  }
43  return false;
44 }
45 
47  window()->redraw();
48  RunLoop::run();
49 }
50 
51 int Container::numberOfTimers() {
52  return m_activeApp->numberOfTimers() + numberOfContainerTimers();
53 }
54 
55 Timer * Container::timerAtIndex(int i) {
56  if (i < m_activeApp->numberOfTimers()) {
57  return m_activeApp->timerAtIndex(i);
58  }
59  return containerTimerAtIndex(i-m_activeApp->numberOfTimers());
60 }
61 
62 int Container::numberOfContainerTimers() {
63  return 0;
64 }
65 
66 Timer * Container::containerTimerAtIndex(int i) {
67  assert(false);
68  return nullptr;
69 }
virtual void didBecomeActive(Window *window)
Definition: app.cpp:106
virtual void switchTo(App::Snapshot *snapshot)
Definition: container.cpp:16
Definition: timer.h:15
#define assert(e)
Definition: assert.h:9
virtual void willBecomeInactive()
Definition: app.cpp:114
void run()
Definition: run_loop.cpp:20
Snapshot * snapshot()
Definition: app.cpp:41
virtual bool processEvent(Ion::Events::Event event)
Definition: app.cpp:45
virtual int numberOfTimers()
Definition: app.cpp:126
virtual void run()
Definition: container.cpp:46
virtual Window * window()=0
void redraw(bool force=false)
Definition: window.cpp:12
virtual App * unpack(Container *container)=0
virtual ~Container()
Definition: container.cpp:10
virtual Timer * timerAtIndex(int i)
Definition: app.cpp:130
Definition: app.h:23
constexpr Event TimerFire
Definition: events.h:217
virtual bool dispatchEvent(Ion::Events::Event event) override
Definition: container.cpp:38
void pack(App *app)
Definition: app.cpp:19
App * activeApp()
Definition: container.cpp:34