mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[apps/hardware_test] Create an arrow view
Change-Id: I0054820a3c6d21638dd358f88299765d0ebf5b18
This commit is contained in:
@@ -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\
|
||||
|
||||
55
apps/hardware_test/arrow_view.cpp
Normal file
55
apps/hardware_test/arrow_view.cpp
Normal file
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
23
apps/hardware_test/arrow_view.h
Normal file
23
apps/hardware_test/arrow_view.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef HARDWARE_TEST_ARROW_VIEW_H
|
||||
#define HARDWARE_TEST_ARROW_VIEW_H
|
||||
|
||||
#include <escher.h>
|
||||
|
||||
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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <escher.h>
|
||||
#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);
|
||||
|
||||
Reference in New Issue
Block a user