Numworks Epsilon  1.4.1
Graphing Calculator Operating System
pop_up_controller.cpp
Go to the documentation of this file.
1 #include "pop_up_controller.h"
2 #include "../i18n.h"
3 #include "../apps_container.h"
4 #include <assert.h>
5 
6 namespace HardwareTest {
7 
9  ViewController(nullptr),
10  m_contentView(this)
11 {
12 }
13 
15  return &m_contentView;
16 }
17 
19  m_contentView.setSelectedButton(0);
20 }
21 
23  if (event == Ion::Events::Left && m_contentView.selectedButton() == 1) {
24  m_contentView.setSelectedButton(0);
25  return true;
26  }
27  if (event == Ion::Events::Right && m_contentView.selectedButton() == 0) {
28  m_contentView.setSelectedButton(1);
29  return true;
30  }
31  return false;
32 }
33 
34 PopUpController::ContentView::ContentView(Responder * parentResponder) :
35  Responder(parentResponder),
36  m_cancelButton(this, I18n::Message::Cancel, Invocation([](void * context, void * sender) {
37  PopUpController::ContentView * view = (PopUpController::ContentView *)context;
38  view->app()->dismissModalViewController();
39  }, this), KDText::FontSize::Small),
40  m_okButton(this, I18n::Message::Ok, Invocation([](void * context, void * sender) {
41  PopUpController::ContentView * view = (PopUpController::ContentView *)context;
42  AppsContainer * appsContainer = (AppsContainer *)view->app()->container();
43  appsContainer->switchTo(appsContainer->hardwareTestAppSnapshot());
44  }, this), KDText::FontSize::Small),
45  m_warningTextView(KDText::FontSize::Small, I18n::Message::Warning, 0.5, 0.5, KDColorWhite, KDColorBlack),
46  m_messageTextView1(KDText::FontSize::Small, I18n::Message::HardwareTestLaunch1, 0.5, 0.5, KDColorWhite, KDColorBlack),
47  m_messageTextView2(KDText::FontSize::Small, I18n::Message::HardwareTestLaunch2, 0.5, 0.5, KDColorWhite, KDColorBlack),
48  m_messageTextView3(KDText::FontSize::Small, I18n::Message::HardwareTestLaunch3, 0.5, 0.5, KDColorWhite, KDColorBlack),
49  m_messageTextView4(KDText::FontSize::Small, I18n::Message::HardwareTestLaunch4, 0.5, 0.5, KDColorWhite, KDColorBlack)
50 {
51 }
52 
53 void PopUpController::ContentView::drawRect(KDContext * ctx, KDRect rect) const {
54  ctx->fillRect(bounds(), KDColorBlack);
55 }
56 
57 void PopUpController::ContentView::setSelectedButton(int selectedButton) {
58  m_cancelButton.setHighlighted(selectedButton == 0);
59  m_okButton.setHighlighted(selectedButton == 1);
60  if (selectedButton == 0) {
61  app()->setFirstResponder(&m_cancelButton);
62  } else {
63  app()->setFirstResponder(&m_okButton);
64  }
65 }
66 
67 int PopUpController::ContentView::selectedButton() {
68  if (m_cancelButton.isHighlighted()) {
69  return 0;
70  }
71  return 1;
72 }
73 
74 int PopUpController::ContentView::numberOfSubviews() const {
75  return 7;
76 }
77 
78 View * PopUpController::ContentView::subviewAtIndex(int index) {
79  switch (index) {
80  case 0:
81  return &m_warningTextView;
82  case 1:
83  return &m_messageTextView1;
84  case 2:
85  return &m_messageTextView2;
86  case 3:
87  return &m_messageTextView3;
88  case 4:
89  return &m_messageTextView4;
90  case 5:
91  return &m_cancelButton;
92  case 6:
93  return &m_okButton;
94  default:
95  assert(false);
96  return nullptr;
97  }
98 }
99 
100 void PopUpController::ContentView::layoutSubviews() {
101  KDCoordinate height = bounds().height();
102  KDCoordinate width = bounds().width();
104  m_warningTextView.setFrame(KDRect(0, k_topMargin, width, textHeight));
105  m_messageTextView1.setFrame(KDRect(0, k_topMargin+k_paragraphHeight+textHeight, width, textHeight));
106  m_messageTextView2.setFrame(KDRect(0, k_topMargin+k_paragraphHeight+2*textHeight, width, textHeight));
107  m_messageTextView3.setFrame(KDRect(0, k_topMargin+k_paragraphHeight+3*textHeight, width, textHeight));
108  m_messageTextView4.setFrame(KDRect(0, k_topMargin+k_paragraphHeight+4*textHeight, width, textHeight));
109  m_cancelButton.setFrame(KDRect(k_buttonMargin, height-k_buttonMargin-k_buttonHeight, (width-3*k_buttonMargin)/2, k_buttonHeight));
110  m_okButton.setFrame(KDRect(2*k_buttonMargin+(width-3*k_buttonMargin)/2, height-k_buttonMargin-k_buttonHeight, (width-3*k_buttonMargin)/2, k_buttonHeight));
111 }
112 
113 }
Definition: i18n.h:6
#define assert(e)
Definition: assert.h:9
void switchTo(App::Snapshot *snapshot) override
int16_t KDCoordinate
Definition: coordinate.h:6
bool handleEvent(Ion::Events::Event event) override
constexpr KDColor KDColorWhite
Definition: color.h:42
App::Snapshot * hardwareTestAppSnapshot()
constexpr KDColor KDColorBlack
Definition: color.h:41
constexpr Event Left
Definition: events.h:61
Definition: rect.h:26
void fillRect(KDRect rect, KDColor color)
Definition: context_rect.cpp:8
Definition: view.h:23
constexpr Event Right
Definition: events.h:64
static constexpr KDSize charSize(FontSize size=FontSize::Large)
Definition: text.h:16
constexpr KDCoordinate height() const
Definition: size.h:11