diff --git a/apps/hardware_test/Makefile b/apps/hardware_test/Makefile index b790d87e3..447f25a4d 100644 --- a/apps/hardware_test/Makefile +++ b/apps/hardware_test/Makefile @@ -1,5 +1,6 @@ app_objs += $(addprefix apps/hardware_test/,\ app.o\ + arrow_view.o\ battery_test_controller.o\ keyboard_test_controller.o\ keyboard_view.o\ diff --git a/apps/hardware_test/arrow_view.cpp b/apps/hardware_test/arrow_view.cpp new file mode 100644 index 000000000..9adc7fbb4 --- /dev/null +++ b/apps/hardware_test/arrow_view.cpp @@ -0,0 +1,55 @@ +#include "arrow_view.h" + +namespace HardwareTest { + +const uint8_t arrowUpMask[10][9] = { + {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF}, + {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF}, + {0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF}, + {0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF}, + {0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF}, + {0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF}, + {0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}, + {0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, +}; + +const uint8_t arrowDownMask[10][9] = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}, + {0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}, + {0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF}, + {0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF}, + {0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF}, + {0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF}, + {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF}, + {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF}, +}; + +ArrowView::ArrowView() : + m_directionIsUp(true) +{ +} + +void ArrowView::setDirection(bool isUp) { + if (m_directionIsUp!= isUp) { + m_directionIsUp = isUp; + markRectAsDirty(bounds()); + } +} +KDColor s_arrowWorkingBuffer[10*9]; + +void ArrowView::drawRect(KDContext * ctx, KDRect rect) const { + ctx->fillRect(bounds(), KDColorWhite); + KDCoordinate startLine = m_directionIsUp ? k_arrowHeight : 0; + KDCoordinate startArrow = m_directionIsUp ? 0 : bounds().height()-k_arrowHeight; + ctx->fillRect(KDRect((Ion::Display::Width-k_arrowThickness)/2, startLine, k_arrowThickness, bounds().height()-k_arrowHeight), KDColorBlack); + KDRect frame((Ion::Display::Width-k_arrowWidth)/2, startArrow, k_arrowWidth, k_arrowHeight); + const uint8_t * mask = m_directionIsUp ? (const uint8_t *)arrowUpMask : (const uint8_t *)arrowDownMask; + ctx->blendRectWithMask(frame, KDColorBlack, mask, s_arrowWorkingBuffer); +} + +} + diff --git a/apps/hardware_test/arrow_view.h b/apps/hardware_test/arrow_view.h new file mode 100644 index 000000000..d823912c7 --- /dev/null +++ b/apps/hardware_test/arrow_view.h @@ -0,0 +1,23 @@ +#ifndef HARDWARE_TEST_ARROW_VIEW_H +#define HARDWARE_TEST_ARROW_VIEW_H + +#include + +namespace HardwareTest { + +class ArrowView : public View { +public: + ArrowView(); + void drawRect(KDContext * ctx, KDRect rect) const override; + void setDirection(bool up); +private: + constexpr static KDCoordinate k_arrowHeight = 10; + constexpr static KDCoordinate k_arrowWidth = 9; + constexpr static KDCoordinate k_arrowThickness = 3; + bool m_directionIsUp; +}; + +} + +#endif + diff --git a/apps/hardware_test/led_test_controller.cpp b/apps/hardware_test/led_test_controller.cpp index eae2a3b10..2afd10b87 100644 --- a/apps/hardware_test/led_test_controller.cpp +++ b/apps/hardware_test/led_test_controller.cpp @@ -43,23 +43,12 @@ KDColor LEDTestController::LEDColorAtIndex(int i) { return k_LEDColors[i]; } -const uint8_t arrowMask[10][9] = { - {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF}, - {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF}, - {0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF}, - {0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF}, - {0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF}, - {0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF}, - {0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}, - {0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, -}; - LEDTestController::ContentView::ContentView() : + SolidColorView(KDColorWhite), m_ledColorIndicatorView(KDColorBlack), m_ledColorOutlineView(KDColorBlack), - m_ledView(KDText::FontSize::Large) + m_ledView(KDText::FontSize::Large), + m_arrowView() { m_ledView.setText("LED"); } @@ -68,24 +57,16 @@ SolidColorView * LEDTestController::ContentView::LEDColorIndicatorView() { return &m_ledColorIndicatorView; } -KDColor s_arrowWorkingBuffer[10*9]; - -void LEDTestController::ContentView::drawRect(KDContext * ctx, KDRect rect) const { - ctx->fillRect(bounds(), KDColorWhite); - ctx->fillRect(KDRect((Ion::Display::Width-k_arrowThickness)/2, k_arrowMargin+k_arrowHeight, k_arrowThickness, k_arrowLength), KDColorBlack); - KDRect frame((Ion::Display::Width-k_arrowWidth)/2, k_arrowMargin, k_arrowWidth, k_arrowHeight); - ctx->blendRectWithMask(frame, KDColorBlack, (const uint8_t *)arrowMask, s_arrowWorkingBuffer); -} - void LEDTestController::ContentView::layoutSubviews() { KDSize ledSize = m_ledView.minimalSizeForOptimalDisplay(); - m_ledView.setFrame(KDRect((Ion::Display::Width-ledSize.width()-k_indicatorSize-k_indicatorMargin)/2, k_arrowHeight+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_arrowHeight+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_arrowHeight+k_arrowLength+2*k_arrowMargin-1, k_indicatorSize+2, k_indicatorSize+2)); + 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 3; + return 4; } View * LEDTestController::ContentView::subviewAtIndex(int index) { @@ -95,7 +76,10 @@ View * LEDTestController::ContentView::subviewAtIndex(int index) { if (index == 1) { return &m_ledColorOutlineView; } - return &m_ledColorIndicatorView; + if (index == 2) { + return &m_ledColorIndicatorView; + } + return &m_arrowView; } } diff --git a/apps/hardware_test/led_test_controller.h b/apps/hardware_test/led_test_controller.h index 724e8e745..dbe686fe1 100644 --- a/apps/hardware_test/led_test_controller.h +++ b/apps/hardware_test/led_test_controller.h @@ -3,6 +3,7 @@ #include #include "battery_test_controller.h" +#include "arrow_view.h" namespace HardwareTest { @@ -13,11 +14,10 @@ public: bool handleEvent(Ion::Events::Event event) override; void viewWillAppear() override; private: - class ContentView : public View { + class ContentView : public SolidColorView { public: ContentView(); SolidColorView * LEDColorIndicatorView(); - void drawRect(KDContext * ctx, KDRect rect) const override; private: void layoutSubviews() override; int numberOfSubviews() const override; @@ -25,15 +25,13 @@ private: SolidColorView m_ledColorIndicatorView; SolidColorView m_ledColorOutlineView; BufferTextView m_ledView; + ArrowView m_arrowView; }; void setLEDColor(KDColor color); - constexpr static KDCoordinate k_arrowThickness = 3; constexpr static KDCoordinate k_arrowLength = 100; constexpr static KDCoordinate k_arrowMargin = 20; constexpr static KDCoordinate k_indicatorSize = 20; constexpr static KDCoordinate k_indicatorMargin = 8; - constexpr static KDCoordinate k_arrowHeight = 10; - constexpr static KDCoordinate k_arrowWidth = 9; constexpr static int k_numberOfColors = 5; constexpr static KDColor k_LEDColors[k_numberOfColors] = {KDColorWhite, KDColorRed, KDColorBlue, KDColorGreen, KDColorBlack}; static KDColor LEDColorAtIndex(int i);