Blame view

Modif/epsilon-master/escher/src/container.cpp 1.36 KB
6663b6c9   adorian   projet complet av...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
  #include <escher/container.h>
  #include <assert.h>
  
  Container::Container() :
    RunLoop(),
    m_activeApp(nullptr)
  {
  }
  
  Container::~Container() {
    if (m_activeApp) {
      delete m_activeApp;
    }
  }
  
  void Container::switchTo(App::Snapshot * snapshot) {
    if (m_activeApp && snapshot == m_activeApp->snapshot()) {
      return;
    }
    if (m_activeApp) {
      m_activeApp->willBecomeInactive();
      m_activeApp->snapshot()->pack(m_activeApp);
      m_activeApp = nullptr;
    }
    if (snapshot) {
      m_activeApp = snapshot->unpack(this);
    }
    if (m_activeApp) {
      m_activeApp->didBecomeActive(window());
      window()->redraw();
    }
  }
  
  App * Container::activeApp() {
    return m_activeApp;
  }
  
  bool Container::dispatchEvent(Ion::Events::Event event) {
    if (event == Ion::Events::TimerFire || m_activeApp->processEvent(event)) {
      window()->redraw();
      return true;
    }
    return false;
  }
  
  void Container::run() {
    window()->redraw();
    RunLoop::run();
  }
  
  int Container::numberOfTimers() {
    return m_activeApp->numberOfTimers() + numberOfContainerTimers();
  }
  
  Timer * Container::timerAtIndex(int i) {
    if (i < m_activeApp->numberOfTimers()) {
      return m_activeApp->timerAtIndex(i);
    }
    return containerTimerAtIndex(i-m_activeApp->numberOfTimers());
  }
  
  int Container::numberOfContainerTimers() {
    return 0;
  }
  
  Timer * Container::containerTimerAtIndex(int i) {
    assert(false);
    return nullptr;
  }