diff --git a/include/constants.h b/include/constants.h index 798b537..826ecc6 100644 --- a/include/constants.h +++ b/include/constants.h @@ -36,30 +36,31 @@ const int YEND = 950; // application constants -const uint16_t LOGO_X = 80; -const uint16_t LOGO_Y = 4; -const uint16_t LOGO_C = WHITE; +constexpr unsigned CANVAS_X = 4; +constexpr unsigned CANVAS_Y = 30; +constexpr unsigned CANVAS_W = 312; +constexpr unsigned CANVAS_H = 312; -const uint16_t CANVAS_W = 312; -const uint16_t CANVAS_H = 312; +constexpr unsigned CANVAS_BUFFER_W = 32; +constexpr unsigned CANVAS_BUFFER_H = 32; -const uint16_t CANVAS_X = 4; -const uint16_t CANVAS_Y = 30; +constexpr unsigned CANVAS_BUFFER_MAX_SEGMENTS = 18; +constexpr unsigned CLIENT_BUFFER_MAX_SEGMENTS = 105; -const uint16_t COLOR_SELECTOR_X = 40; -const uint16_t COLOR_SELECTOR_Y = CANVAS_Y + CANVAS_H + 30; +constexpr unsigned COLOR_SELECTOR_X = 40; +constexpr unsigned COLOR_SELECTOR_Y = CANVAS_Y + CANVAS_H + 30; -const uint16_t COLOR_SELECTOR_HPAD = 35; -const uint16_t COLOR_SELECTOR_VPAD = 35; +// const uint16_t COLOR_SELECTOR_HPAD = 35; +// const uint16_t COLOR_SELECTOR_VPAD = 35; -const uint16_t PAINT_RADIUS = 12; +// const uint16_t PAINT_RADIUS = 12; +constexpr unsigned THICKNESS_SELECTOR_X = 160; +constexpr unsigned THICKNESS_SELECTOR_Y = COLOR_SELECTOR_Y; -const uint16_t THICKNESS_SELECTOR_X = 160; -const uint16_t THICKNESS_SELECTOR_Y = COLOR_SELECTOR_Y; -const uint16_t THICKNESS_SELECTOR_PAD = 35; +// const uint16_t THICKNESS_SELECTOR_PAD = 35; const uint16_t SAVE_X = 144; @@ -106,10 +107,5 @@ const uint16_t SLOT_MENU_Y = COLOR_SELECTOR_Y - 8; const uint16_t SLOT_MENU_W = SAVE_W * 3; const uint16_t SLOT_MENU_H = SAVE_H * 4; -constexpr unsigned CANVAS_BUFFER_W = 32; -constexpr unsigned CANVAS_BUFFER_H = 32; - -constexpr unsigned CANVAS_BUFFER_MAX_SEGMENTS = 18; -constexpr unsigned CLIENT_BUFFER_MAX_SEGMENTS = 105; #endif \ No newline at end of file diff --git a/include/widgets/button.h b/include/widgets/button.h index 1e35b22..650f2d3 100644 --- a/include/widgets/button.h +++ b/include/widgets/button.h @@ -1,19 +1,17 @@ #ifndef __WIDGETS_BUTTON_H__ #define __WIDGETS_BUTTON_H__ -#include "Arduino.h" -#include "Adafruit_GFX.h" -#include "MCUFRIEND_kbv.h" +#include "widget.h" -class Button { +class Button : Widget { MCUFRIEND_kbv *tft; - uint16_t x; - uint16_t y; + unsigned x; + unsigned y; - uint16_t w; - uint16_t h; + unsigned w; + unsigned h; uint16_t color; @@ -21,10 +19,15 @@ class Button { public: - Button(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color, char *msg, MCUFRIEND_kbv *tft); + Button(unsigned x, unsigned y, unsigned w, unsigned h, uint16_t color, char *msg, MCUFRIEND_kbv *tft); - void draw() const; - bool update(uint16_t touchX, uint16_t touchY); + void draw() const override; + void clear() const override; + + bool update(unsigned touchX, unsigned touchY) override; + + unsigned height() const override; + unsigned width() const override; private: diff --git a/include/widgets/buttonGrid.h b/include/widgets/buttonGrid.h index 361f42d..4974014 100644 --- a/include/widgets/buttonGrid.h +++ b/include/widgets/buttonGrid.h @@ -1,52 +1,51 @@ #ifndef __WIDGETS_BUTTON_GRID_H__ #define __WIDGETS_BUTTON_GRID_H__ -#include "Arduino.h" -#include "Adafruit_GFX.h" -#include "MCUFRIEND_kbv.h" - #include "constants.h" +#include "widget.h" -class ButtonGrid { - - const char *msg = "SLOT"" "; +class ButtonGrid : Widget { - const uint16_t SLOT_CLOSE_X = 2; - const uint16_t SLOT_CLOSE_Y = 2; - const uint16_t SLOT_CLOSE_W = 13; + static constexpr char *msg = "SLOT"" "; - const uint16_t SLOT_MENU_C = GRAY; + static constexpr unsigned CLOSE_X = 2; + static constexpr unsigned CLOSE_Y = 2; + static constexpr unsigned CLOSE_W = 13; - const uint16_t SLOT_OPTION_X = 23; - const uint16_t SLOT_OPTION_Y = 8; + static constexpr unsigned HPAD = 23; + static constexpr unsigned VPAD = 8; - const uint16_t SLOT_OPTION_W = SAVE_W; - const uint16_t SLOT_OPTION_H = SAVE_H; - const uint16_t SLOT_OPTION_C = WHITE; + static constexpr uint16_t BUTTON_C = WHITE; MCUFRIEND_kbv *tft; - uint16_t x; - uint16_t y; + unsigned x; + unsigned y; - uint16_t w; - uint16_t h; + unsigned w; + unsigned h; - uint16_t cc; - uint16_t rc; + unsigned cc; + unsigned rc; - uint16_t slot; + unsigned button_w; + unsigned button_h; + + unsigned slot; public: - ButtonGrid(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t c, uint16_t r, MCUFRIEND_kbv *tft); + ButtonGrid(unsigned x, unsigned y, unsigned w, unsigned h, unsigned cc, unsigned rc, unsigned button_w, unsigned button_h, MCUFRIEND_kbv *tft); + + void draw() const override; + void clear() const override; - void draw() const; - bool update(uint16_t touchX, uint16_t touchY); + bool update(unsigned touch_x, unsigned touch_y) override; - void clear(); + unsigned height() const override; + unsigned width() const override; - uint16_t getSlot() const; + unsigned getSlot() const; private: diff --git a/include/widgets/canvas.h b/include/widgets/canvas.h index 4318fef..698da42 100644 --- a/include/widgets/canvas.h +++ b/include/widgets/canvas.h @@ -1,34 +1,44 @@ #ifndef __WIDGETS_CANVAS_H__ #define __WIDGETS_CANVAS_H__ -#include "Arduino.h" -#include "Adafruit_GFX.h" -#include "MCUFRIEND_kbv.h" +#include "widget.h" -class Canvas { +class Canvas : Widget { MCUFRIEND_kbv *tft; - uint16_t x; - uint16_t y; + unsigned x; + unsigned y; - uint16_t w; - uint16_t h; + unsigned w; + unsigned h; + + unsigned thickness; + uint16_t color; public: - Canvas(uint16_t x, uint16_t y, uint16_t w, uint16_t h, MCUFRIEND_kbv *tft); + Canvas(unsigned x, unsigned y, unsigned w, unsigned h, MCUFRIEND_kbv *tft); + + void draw() const override; + void clear() const override; + + bool update(unsigned touch_x, unsigned touch_y) override; + + unsigned height() const override; + unsigned width() const override; + + unsigned heightInternal() const; + unsigned widthInternal() const; - void draw() const; - bool update(uint16_t touchX, uint16_t touchY, uint16_t curThickness, uint16_t curColor); + void setThickness(unsigned curThickness); + void setColor(uint16_t curColor); - void clear(); + void clearDrawing(); - uint16_t readPixel(uint16_t r, uint16_t c) const; - void writePixel(uint16_t r, uint16_t c, uint16_t color); + uint16_t readPixel(unsigned r, unsigned c) const; + void writePixel(unsigned r, unsigned c, uint16_t color); - uint16_t height() const; - uint16_t width() const; private: diff --git a/include/widgets/colorSelector.h b/include/widgets/colorSelector.h index 9c685cb..956a23b 100644 --- a/include/widgets/colorSelector.h +++ b/include/widgets/colorSelector.h @@ -1,38 +1,43 @@ #ifndef __WIDGETS_COLOR_SELECTOR_H__ #define __WIDGETS_COLOR_SELECTOR_H__ -#include "Arduino.h" -#include "Adafruit_GFX.h" -#include "MCUFRIEND_kbv.h" +#include "widget.h" #include "constants.h" -class ColorSelector { +class ColorSelector : Widget { - constexpr static uint16_t colors[3][3] { + constexpr static uint16_t COLORS[3][3] { {RED, GREEN, BLUE}, {CYAN, MAGENTA, YELLOW}, {WHITE, GRAY, BLACK} }; - MCUFRIEND_kbv *tft; + constexpr static unsigned HPAD = 35; + constexpr static unsigned VPAD = 35; + constexpr static unsigned PAINT_RADIUS = 12; - uint16_t x; - uint16_t y; + constexpr static unsigned HEIGHT = (PAINT_RADIUS/2) + (3*HPAD); + constexpr static unsigned WIDTH = (PAINT_RADIUS/2) + (3*VPAD); - uint16_t hpad; - uint16_t vpad; + MCUFRIEND_kbv *tft; - uint16_t paintRadius; + unsigned x; + unsigned y; - uint16_t curColor = WHITE; + uint16_t curColor; public: - ColorSelector(uint16_t x, uint16_t y, uint16_t hpad, uint16_t vpad, uint16_t paintRadius, MCUFRIEND_kbv *tft); + ColorSelector(unsigned x, unsigned y, MCUFRIEND_kbv *tft); + + void draw() const override; + void clear() const override; + + bool update(unsigned touch_x, unsigned touch_y) override; - void draw() const; - bool update(uint16_t touchX, uint16_t touchY); + unsigned height() const; + unsigned width() const; uint16_t getColor() const; diff --git a/include/widgets/thicknessSelector.h b/include/widgets/thicknessSelector.h index 795b098..de966a9 100644 --- a/include/widgets/thicknessSelector.h +++ b/include/widgets/thicknessSelector.h @@ -1,32 +1,38 @@ #ifndef __WIDGETS_THICKNESS_SELECTOR_H__ #define __WIDGETS_THICKNESS_SELECTOR_H__ -#include "Arduino.h" -#include "Adafruit_GFX.h" -#include "MCUFRIEND_kbv.h" +#include "widget.h" -class ThicknessSelector { +class ThicknessSelector : Widget { - const uint16_t radii[4] = {3, 5, 7, 9}; + static constexpr unsigned RADII[4] = {3, 5, 7, 9}; + static constexpr unsigned PAD = 35; - MCUFRIEND_kbv *tft; + static constexpr unsigned HEIGHT = 0; + static constexpr unsigned WIDTH = 0; - uint16_t x; - uint16_t y; + MCUFRIEND_kbv *tft; - uint16_t pad; + unsigned x; + unsigned y; uint16_t color; - uint16_t curSelected; + unsigned curSelected; public: - ThicknessSelector(uint16_t x, uint16_t y, uint16_t pad, MCUFRIEND_kbv *tft); + ThicknessSelector(unsigned x, unsigned y, MCUFRIEND_kbv *tft); void setColor(uint16_t clr); - void draw() const; - bool update(uint16_t touchX, uint16_t touchY); + void draw() const override; + void clear() const override; + + bool update(unsigned touch_x, unsigned touch_y) override; + + unsigned height() const override; + unsigned width() const override; + uint16_t getThickness() const; private: diff --git a/src/canvasClient.cpp b/src/canvasClient.cpp index 57bb41d..957d696 100644 --- a/src/canvasClient.cpp +++ b/src/canvasClient.cpp @@ -59,8 +59,8 @@ void CanvasClient::loadCanvas(uint8_t id, Compressor return; } - uint16_t imageHeight = canvas->height() - 2; - uint16_t imageWidth = canvas->width() - 2; + uint16_t imageHeight = canvas->heightInternal(); + uint16_t imageWidth = canvas->widthInternal(); client.write("\x02", 1); client.write(&id, 1); @@ -86,7 +86,7 @@ void CanvasClient::loadCanvas(uint8_t id, Compressor } for (uint16_t j = 0; j < imageWidth; ++j) { - canvas->writePixel(row + 1, j + 1, rowbuf.color[j]); + canvas->writePixel(row, j, rowbuf.color[j]); } for (uint16_t j = 0; j < imageWidth; ++j) { @@ -125,7 +125,7 @@ void CanvasClient::saveCanvas(uint8_t id, Compressor } else { for (unsigned j = compressed[i].uncompress(rowbuf.code); j < imageWidth; ++j) { - rowbuf.code[j] = color2code(canvas->readPixel(i + 1, j + 1)); + rowbuf.code[j] = color2code(canvas->readPixel(i, j)); } compressable = compressor.compress(rowbuf.code, imageWidth); } diff --git a/src/main.cpp b/src/main.cpp index 46fa706..3b2f818 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,9 +23,9 @@ MCUFRIEND_kbv tft; Canvas canvas(CANVAS_X, CANVAS_Y, CANVAS_W, CANVAS_H, &tft); -ColorSelector colorSelector(COLOR_SELECTOR_X, COLOR_SELECTOR_Y, COLOR_SELECTOR_HPAD, COLOR_SELECTOR_VPAD, PAINT_RADIUS, &tft); -ThicknessSelector thicknessSelector(THICKNESS_SELECTOR_X, THICKNESS_SELECTOR_Y, THICKNESS_SELECTOR_PAD, &tft); -ButtonGrid slotSelector(SLOT_MENU_X, SLOT_MENU_Y, SLOT_MENU_W, SLOT_MENU_H, 2, 3, &tft); +ColorSelector colorSelector(COLOR_SELECTOR_X, COLOR_SELECTOR_Y, &tft); +ThicknessSelector thicknessSelector(THICKNESS_SELECTOR_X, THICKNESS_SELECTOR_Y, &tft); +ButtonGrid slotSelector(SLOT_MENU_X, SLOT_MENU_Y, SLOT_MENU_W, SLOT_MENU_H, 2, 3, 72, 28, &tft); Button loadButton(LOAD_X, LOAD_Y, LOAD_W, LOAD_H, LOAD_C, "LOAD", &tft); Button saveButton(SAVE_X, SAVE_Y, SAVE_W, SAVE_H, SAVE_C, "SAVE", &tft); @@ -36,7 +36,6 @@ CanvasClient client(&canvas); GFXcanvas1 canvasBuffer(CANVAS_BUFFER_W, CANVAS_BUFFER_H); -// CompressedRow compressed[CANVAS_H - 2]; Compressor compressed[CANVAS_H - 2]; uint8_t rawCode[CANVAS_W - 2] {}; @@ -78,7 +77,10 @@ void loop(void) { const uint16_t color = colorSelector.getColor(); const uint8_t code = color2code(color); - if (canvas.update(x, y, thickness, color)) { + canvas.setThickness(thickness); + canvas.setColor(color); + + if (canvas.update(x, y)) { const uint16_t canvasX = x - CANVAS_X - 1; const uint16_t canvasY = y - CANVAS_Y - 1; @@ -163,7 +165,7 @@ void loop(void) { } if (clearButton.update(x, y)) { - canvas.clear(); + canvas.clearDrawing(); clearCompressedCanvas(); } diff --git a/src/widgets/button.cpp b/src/widgets/button.cpp index a17e009..0962f81 100644 --- a/src/widgets/button.cpp +++ b/src/widgets/button.cpp @@ -2,7 +2,7 @@ #include "constants.h" #include "helper.h" -Button::Button(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color, char *msg, MCUFRIEND_kbv *tft) +Button::Button(unsigned x, unsigned y, unsigned w, unsigned h, uint16_t color, char *msg, MCUFRIEND_kbv *tft) : x {x} , y {y} , w {w} @@ -23,7 +23,12 @@ void Button::draw() const { tft->print(msg); } -bool Button::update(uint16_t touchX, uint16_t touchY) { +void Button::clear() const { + + tft->fillRect(x, y, w, h, BLACK); +} + +bool Button::update(unsigned touchX, unsigned touchY) { if (!inRange(touchX, x, x + w) || !inRange(touchY, y, y + h)) { return false; @@ -31,3 +36,11 @@ bool Button::update(uint16_t touchX, uint16_t touchY) { return true; } + +unsigned Button::height() const { + return h; +} + +unsigned Button::width() const { + return w; +} diff --git a/src/widgets/buttonGrid.cpp b/src/widgets/buttonGrid.cpp index 364069b..b021dfa 100644 --- a/src/widgets/buttonGrid.cpp +++ b/src/widgets/buttonGrid.cpp @@ -2,84 +2,93 @@ #include "constants.h" #include "helper.h" -ButtonGrid::ButtonGrid(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t c, uint16_t r, MCUFRIEND_kbv *tft) +ButtonGrid::ButtonGrid(unsigned x, unsigned y, unsigned w, unsigned h, unsigned cc, unsigned rc, unsigned button_w, unsigned button_h, MCUFRIEND_kbv *tft) : x {x} , y {y} , w {w} , h {h} - , cc {c} - , rc {r} + , cc {cc} + , rc {rc} + , button_w {button_w} + , button_h {button_h} , tft {tft} + , slot {} {} void ButtonGrid::draw() const { + unsigned i, j; + tft->fillRect(x, y, w, h, BLACK); tft->drawRect(x, y, w, h, GRAY); - tft->fillRoundRect(x + SLOT_CLOSE_X, y + SLOT_CLOSE_Y, SLOT_CLOSE_W, SLOT_CLOSE_W, SLOT_CLOSE_W / 2, RED); + tft->fillRoundRect(x + CLOSE_X, y + CLOSE_Y, CLOSE_W, CLOSE_W, CLOSE_W / 2, RED); tft->setTextColor(WHITE, BLACK); tft->setTextSize(2); - for (uint16_t r = 0; r < rc; ++r) { - for (uint16_t c = 0; c < cc; ++c) { + for (unsigned r = 0; r < rc; ++r) { + + for (unsigned c = 0; c < cc; ++c) { - uint16_t i = x + SLOT_OPTION_X*(c + 1) + SLOT_OPTION_W*(c); - uint16_t j = y + SLOT_OPTION_Y*(r + 1) + SLOT_OPTION_H*(r); + j = y + VPAD + (button_h + VPAD)*r; + i = x + HPAD + (button_w + HPAD)*c; - tft->drawRect( - i, - j, - SLOT_OPTION_W, - SLOT_OPTION_H, - WHITE - ); + tft->drawRect(i, j, button_w, button_h, WHITE); tft->setCursor(i, j); tft->print(msg); tft->print(1 + r + (c * rc)); + + // delay(2000); } } } -bool ButtonGrid::update(uint16_t touchX, uint16_t touchY) { +bool ButtonGrid::update(unsigned touch_x, unsigned touch_y) { - // close button pressed - if (inRange(touchX, x + SLOT_CLOSE_X, x + SLOT_CLOSE_X + SLOT_CLOSE_W) && inRange(touchY, y + SLOT_CLOSE_Y, y + SLOT_CLOSE_Y + SLOT_CLOSE_W)) { // close this menu + if (inRange(touch_x, x + CLOSE_X, x + CLOSE_X + CLOSE_W) + && inRange(touch_y, y + CLOSE_Y, y + CLOSE_Y + CLOSE_W)) { // close this menu slot = 0; return true; } - for (uint16_t r = 0; r < rc; ++r) { - for (uint16_t c = 0; c < cc; ++c) { - - if (!inRange( - touchX, - x + SLOT_OPTION_X*(c + 1) + SLOT_OPTION_W*(c), - x + SLOT_OPTION_X*(c + 1) + SLOT_OPTION_W*(c + 1)) || - !inRange( - touchY, - y + SLOT_OPTION_Y*(r + 1) + SLOT_OPTION_H*(r), - y + SLOT_OPTION_Y*(r + 1) + SLOT_OPTION_H*(r + 1))) { - continue; - } + for (unsigned r = 0; r < rc; ++r) { + for (unsigned c = 0; c < cc; ++c) { + + if (inRange( + touch_x, + x + HPAD + (button_w + HPAD)*c, + x + (button_w + HPAD)*(c + 1)) && + inRange( + touch_y, + y + VPAD + (button_h + VPAD)*r, + y + (button_h + VPAD)*(r + 1))) { - slot = 1 + r + (c * rc); - return true; + slot = 1 + r + (c * rc); + return true; + } } } return false; } -void ButtonGrid::clear() { +void ButtonGrid::clear() const { tft->fillRect(x, y, w, h, BLACK); } -uint16_t ButtonGrid::getSlot() const { +unsigned ButtonGrid::height() const { + return h; +} + +unsigned ButtonGrid::width() const { + return w; +} + +unsigned ButtonGrid::getSlot() const { return slot; } diff --git a/src/widgets/canvas.cpp b/src/widgets/canvas.cpp index 0cee463..0027a51 100644 --- a/src/widgets/canvas.cpp +++ b/src/widgets/canvas.cpp @@ -2,48 +2,70 @@ #include "constants.h" #include "helper.h" -Canvas::Canvas(uint16_t x, uint16_t y, uint16_t w, uint16_t h, MCUFRIEND_kbv *tft) +Canvas::Canvas(unsigned x, unsigned y, unsigned w, unsigned h, MCUFRIEND_kbv *tft) : x {x} , y {y} , w {w} , h {h} , tft {tft} + , thickness {} + , color {} {} void Canvas::draw() const { tft->drawRect(x, y, w, h, WHITE); } -bool Canvas::update(uint16_t touchX, uint16_t touchY, uint16_t curThickness, uint16_t curColor) { +void Canvas::clear() const { + tft->fillRect(x, y, w, h, BLACK); +} + +bool Canvas::update(unsigned touch_x, unsigned touch_y) { - if (inRange(touchX, x + curThickness + 2, x + w - curThickness - 2) - && inRange(touchY, y + curThickness + 2, y + h - curThickness - 2)) { + if (inRange(touch_x, x + thickness + 2, x + w - thickness - 2) + && inRange(touch_y, y + thickness + 2, y + h - thickness - 2)) { - tft->fillCircle(touchX, touchY, curThickness, curColor); + tft->fillCircle(touch_x, touch_y, thickness, color); return true; } return false; } -void Canvas::clear() { - tft->fillRect(x + 1, y + 1, w - 2, h - 2, BLACK); +unsigned Canvas::height() const { + return h; } +unsigned Canvas::width() const { + return w; +} + +unsigned Canvas::heightInternal() const { + return h - 2; +} -uint16_t Canvas::readPixel(uint16_t r, uint16_t c) const { +unsigned Canvas::widthInternal() const { + return w - 2; +} - return tft->readPixel(x + c, y + r); +void Canvas::setThickness(unsigned curThickness) { + thickness = curThickness; } -void Canvas::writePixel(uint16_t r, uint16_t c, uint16_t color) { +void Canvas::setColor(uint16_t curColor) { + color = curColor; +} - tft->writePixel(x + c, y + r, color); +void Canvas::clearDrawing() { + tft->fillRect(x + 1, y + 1, w - 2, h - 2, BLACK); } -uint16_t Canvas::height() const { - return h; + +uint16_t Canvas::readPixel(unsigned r, unsigned c) const { + + return tft->readPixel(x + c + 1, y + r + 1); } -uint16_t Canvas::width() const { - return w; +void Canvas::writePixel(unsigned r, unsigned c, uint16_t color) { + + tft->writePixel(x + c + 1, y + r + 1, color); } diff --git a/src/widgets/colorSelector.cpp b/src/widgets/colorSelector.cpp index 2578a21..619ada8 100644 --- a/src/widgets/colorSelector.cpp +++ b/src/widgets/colorSelector.cpp @@ -2,48 +2,53 @@ #include "constants.h" #include "helper.h" -ColorSelector::ColorSelector(uint16_t x, uint16_t y, uint16_t hpad, uint16_t vpad, uint16_t paintRadius, MCUFRIEND_kbv *tft) +ColorSelector::ColorSelector(unsigned x, unsigned y, MCUFRIEND_kbv *tft) : x {x} , y {y} - , hpad {hpad} - , vpad {vpad} - , paintRadius {paintRadius} , tft {tft} + , curColor {WHITE} {} void ColorSelector::draw() const { - for (uint16_t r = 0; r < 3; ++r) { + unsigned i, j; + uint16_t color; - for (uint16_t c = 0; c < 3; ++c) { + for (unsigned r = 0; r < 3; ++r) { - uint16_t i = x + (c * hpad); - uint16_t j = y + (r * vpad); - uint16_t color = colors[r][c]; + for (unsigned c = 0; c < 3; ++c) { - tft->fillCircle(i, j, paintRadius, color); - tft->drawCircle(i, j, paintRadius + 2, WHITE); + i = x + (c * HPAD); + j = y + (r * VPAD); + color = COLORS[r][c]; + + tft->fillCircle(i, j, PAINT_RADIUS, color); + tft->drawCircle(i, j, PAINT_RADIUS + 2, WHITE); } } } -bool ColorSelector::update(uint16_t touchX, uint16_t touchY) { +void ColorSelector::clear() const { + tft->fillRect(x, y, WIDTH, HEIGHT, BLACK); +} + +bool ColorSelector::update(unsigned touch_x, unsigned touch_y) { uint32_t i, j, d; - for (uint16_t r = 0; r < 3; ++r) { + for (unsigned r = 0; r < 3; ++r) { - for (uint16_t c = 0; c < 3; ++c) { + for (unsigned c = 0; c < 3; ++c) { - i = x + (c * hpad); - j = y + (r * vpad); + i = x + (c * HPAD); + j = y + (r * VPAD); - d = distance(i, j, touchX, touchY); + d = distance(i, j, touch_x, touch_y); if (d <= PAINT_RADIUS) { - curColor = colors[r][c]; + curColor = COLORS[r][c]; return true; } } @@ -52,6 +57,14 @@ bool ColorSelector::update(uint16_t touchX, uint16_t touchY) { return false; } +unsigned ColorSelector::height() const { //todo + return HEIGHT; +} + +unsigned ColorSelector::width() const { //todo + return WIDTH; +} + uint16_t ColorSelector::getColor() const { return curColor; } diff --git a/src/widgets/thicknessSelector.cpp b/src/widgets/thicknessSelector.cpp index eda029a..c6aeb84 100644 --- a/src/widgets/thicknessSelector.cpp +++ b/src/widgets/thicknessSelector.cpp @@ -2,11 +2,10 @@ #include "constants.h" #include "helper.h" -ThicknessSelector::ThicknessSelector(uint16_t x, uint16_t y, uint16_t pad, MCUFRIEND_kbv *tft) +ThicknessSelector::ThicknessSelector(unsigned x, unsigned y, MCUFRIEND_kbv *tft) : x {x} , y {y} - , pad {pad} - , curSelected {radii[0]} + , curSelected {RADII[0]} , tft {tft} {} @@ -16,13 +15,13 @@ void ThicknessSelector::setColor(uint16_t clr) { void ThicknessSelector::draw() const { - uint16_t i, j, t; + unsigned i, j, t; - for (uint16_t c = 0; c < 4; ++c) { + for (unsigned c = 0; c < 4; ++c) { - i = x + (pad * c); + i = x + (PAD * c); j = y; - t = radii[c]; + t = RADII[c]; (color == BLACK) ? tft->fillCircle(i, j, t, TFT_DARKGREY) @@ -34,17 +33,21 @@ void ThicknessSelector::draw() const { } } -bool ThicknessSelector::update(uint16_t touchX, uint16_t touchY) { +void ThicknessSelector::clear() const { //todo - uint32_t i, j, t, d; +} + +bool ThicknessSelector::update(unsigned touch_x, unsigned touch_y) { - for (uint16_t c = 0; c < 4; ++c) { + unsigned i, j, t, d; - i = x + (pad * c); + for (unsigned c = 0; c < 4; ++c) { + + i = x + (PAD * c); j = y; - t = radii[c]; + t = RADII[c]; - d = distance(i, j, touchX, touchY); + d = distance(i, j, touch_x, touch_y); // the pen is in this color if the distance between its centre // and the pen is less than the radius of the paint @@ -59,6 +62,14 @@ bool ThicknessSelector::update(uint16_t touchX, uint16_t touchY) { return false; } +unsigned ThicknessSelector::height() const { + return HEIGHT; +} + +unsigned ThicknessSelector::width() const { + return WIDTH; +} + uint16_t ThicknessSelector::getThickness() const { return curSelected; }