CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
ColorPickerView.h
Go to the documentation of this file.
1#pragma once
2
3#include "cdc_ui/IView.h"
4#include <cstdint>
5
6class Gdey029T94;
7
8namespace cdc::ui {
9
24class ColorPickerView : public ViewBase {
25public:
27 using SaveCallback = void(*)(uint8_t r, uint8_t g, uint8_t b);
28
30 using CancelCallback = void(*)();
31
38 void init(uint8_t r, uint8_t g, uint8_t b);
39
41 void setOnSave(SaveCallback cb) { onSave_ = cb; }
42
44 void setOnCancel(CancelCallback cb) { onCancel_ = cb; }
45
47 void currentColor(uint8_t& r, uint8_t& g, uint8_t& b) const;
48
49 // IView
50 void render(bool partial) override;
51 InputResult onKey(char key) override;
52 void onTick(uint32_t nowMs) override;
53 const char* getName() const override { return "ColorPickerView"; }
54 const char* getFooterHint() const override;
55
56private:
57 SaveCallback onSave_ = nullptr;
58 CancelCallback onCancel_ = nullptr;
59
60 int16_t cursorX_ = 0;
61 int16_t cursorY_ = 0;
62 uint8_t value_ = 255;
63
64 uint32_t repeatStartMs_ = 0;
65 uint32_t lastRepeatMs_ = 0;
66
67 void barycentric(int16_t px, int16_t py,
68 int32_t& aR, int32_t& aG, int32_t& aB) const;
69 void clampInsideTriangle();
70 void setFromRGB(uint8_t r, uint8_t g, uint8_t b);
71 void moveCursor(int16_t dx, int16_t dy);
72 void adjustValue(int8_t delta);
73 void rawColor(uint8_t& r, uint8_t& g, uint8_t& b) const;
74 void drawDitheredBox(Gdey029T94* gfx, int16_t x, int16_t y, int16_t w, int16_t h,
75 uint8_t luminance) const;
76 void drawTriangle(Gdey029T94* gfx, int16_t ox, int16_t oy) const;
77};
78
79} // namespace cdc::ui
Monochrome RGB color picker.
void onTick(uint32_t nowMs) override
void(*)() CancelCallback
Cancel callback. The view pops itself before this fires.
const char * getName() const override
void(*)(uint8_t r, uint8_t g, uint8_t b) SaveCallback
Save callback. Values are pre-multiplied with brightness.
void currentColor(uint8_t &r, uint8_t &g, uint8_t &b) const
Read the currently chosen color (post brightness scaling).
void init(uint8_t r, uint8_t g, uint8_t b)
Initialize the picker with a starting color.
void setOnSave(SaveCallback cb)
Register a save callback (fired on Y).
const char * getFooterHint() const override
void setOnCancel(CancelCallback cb)
Register a cancel callback (fired when dismissed with N).
InputResult onKey(char key) override
Centralized key-code constants for cdc_views.
Definition IModule.h:8
InputResult
Definition IView.h:10