Blame view

Modif/epsilon-master/apps/hardware_test/led_test_controller.cpp 2.43 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  #include "led_test_controller.h"
  extern "C" {
  #include <assert.h>
  }
  
  namespace HardwareTest {
  
  constexpr KDColor LEDTestController::k_LEDColors[k_numberOfColors];
  
  LEDTestController::LEDTestController(Responder * parentResponder) :
    ViewController(parentResponder),
    m_view(),
    m_LEDColorIndex(0)
  {
  }
  
  View * LEDTestController::view() {
    return &m_view;
  }
  
  bool LEDTestController::handleEvent(Ion::Events::Event event) {
    if (event == Ion::Events::OK) {
      setLEDColor(LEDColorAtIndex(m_LEDColorIndex++));
      if (m_LEDColorIndex == k_numberOfColors) {
        // Next step, see WizardViewController
        return false;
      }
    }
    return true;
  }
  
  void LEDTestController::viewWillAppear() {
    m_LEDColorIndex = 0;
    setLEDColor(LEDColorAtIndex(m_LEDColorIndex++));
  }
  
  void LEDTestController::setLEDColor(KDColor color) {
    Ion::LED::setColor(color);
    m_view.LEDColorIndicatorView()->setColor(color);
  }
  
  KDColor LEDTestController::LEDColorAtIndex(int i) {
    assert(i >= 0 && i < k_numberOfColors);
    return k_LEDColors[i];
  }
  
  LEDTestController::ContentView::ContentView() :
    SolidColorView(KDColorWhite),
    m_ledColorIndicatorView(KDColorBlack),
    m_ledColorOutlineView(KDColorBlack),
    m_ledView(KDText::FontSize::Large),
    m_arrowView()
  {
    m_ledView.setText("LED");
  }
  
  SolidColorView * LEDTestController::ContentView::LEDColorIndicatorView() {
    return &m_ledColorIndicatorView;
  }
  
  void LEDTestController::ContentView::layoutSubviews() {
    KDSize ledSize = m_ledView.minimalSizeForOptimalDisplay();
    m_ledView.setFrame(KDRect((Ion::Display::Width-ledSize.width()-k_indicatorSize-k_indicatorMargin)/2, k_arrowLength+2*k_arrowMargin, ledSize.width(), ledSize.height()));
    m_ledColorIndicatorView.setFrame(KDRect((Ion::Display::Width-k_indicatorSize)/2+k_indicatorMargin/2+ledSize.width()/2, k_arrowLength+2*k_arrowMargin, k_indicatorSize, k_indicatorSize));
    m_ledColorOutlineView.setFrame(KDRect((Ion::Display::Width-k_indicatorSize)/2+k_indicatorMargin/2+ledSize.width()/2-1, k_arrowLength+2*k_arrowMargin-1, k_indicatorSize+2, k_indicatorSize+2));
    m_arrowView.setFrame(KDRect(0, k_arrowMargin, bounds().width(), k_arrowLength));
  }
  
  int LEDTestController::ContentView::numberOfSubviews() const {
    return 4;
  }
  
  View * LEDTestController::ContentView::subviewAtIndex(int index) {
    if (index == 0) {
      return &m_ledView;
    }
    if (index == 1) {
      return &m_ledColorOutlineView;
    }
    if (index == 2) {
      return &m_ledColorIndicatorView;
    }
    return &m_arrowView;
  }
  
  }