Deluge Firmware 1.3.0
Build date: 2025.07.11
Loading...
Searching...
No Matches
canvas.h
1/*
2 * Copyright © 2024 Synthstrom Audible Limited
3 *
4 * This file is part of The Synthstrom Audible Deluge Firmware.
5 *
6 * The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software Foundation,
8 * either version 3 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along with this program.
15 * If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include "RZA1/cpu_specific.h"
21#include "definitions.h"
22#include "deluge/util/d_string.h"
23#include <cstdint>
24#include <cstring>
25#include <string_view>
26
27namespace deluge::hid::display {
28class OLED;
29
30namespace oled_canvas {
31
32class Canvas {
33public:
34 Canvas() = default;
35 ~Canvas() = default;
36
37 Canvas(Canvas const& other) = delete;
38 Canvas(Canvas&& other) = delete;
39
40 Canvas& operator=(Canvas const& other) = delete;
41 Canvas& operator=(Canvas&& other) = delete;
42
45
47 void clear() {
48 // Takes about 1 fast-timer tick (whereas entire rendering takes around 8 to 15).
49 // So, not worth trying to use DMA here or anything.
50 memset(image_, 0, sizeof(image_));
51 };
52
59 void clearAreaExact(int32_t minX, int32_t minY, int32_t maxX, int32_t maxY);
60
62 void drawPixel(int32_t x, int32_t y);
63
65 void clearPixel(int32_t x, int32_t y);
66
72 void drawHorizontalLine(int32_t pixelY, int32_t startX, int32_t endX);
73
79 void drawVerticalLine(int32_t pixelX, int32_t startY, int32_t endY);
80
87 void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, bool thick = false);
88
95 void drawRectangle(int32_t minX, int32_t minY, int32_t maxX, int32_t maxY);
96
103 void drawRectangleRounded(int32_t minX, int32_t minY, int32_t maxX, int32_t maxY);
104
115 void drawString(std::string_view str, int32_t pixelX, int32_t pixelY, int32_t textWidth, int32_t textHeight,
116 int32_t scrollPos = 0, int32_t endX = OLED_MAIN_WIDTH_PIXELS, bool useTextWidth = false);
117
127 void drawStringCentred(char const* string, int32_t pixelY, int32_t textWidth, int32_t textHeight,
128 int32_t centrePos = OLED_MAIN_WIDTH_PIXELS / 2);
129
138 void drawStringCentered(char const* string, int32_t startX, int32_t startY, int32_t textSpacingX,
139 int32_t textSpacingY, int32_t totalWidth);
140
149 void drawStringCentered(StringBuf& stringBuf, int32_t startX, int32_t startY, int32_t textSpacingX,
150 int32_t textSpacingY, int32_t totalWidth);
151
158 void drawStringCentredShrinkIfNecessary(char const* string, int32_t pixelY, int32_t textWidth, int32_t textHeight);
159
167 void drawStringAlignRight(char const* string, int32_t pixelY, int32_t textWidth, int32_t textHeight,
168 int32_t rightPos = OLED_MAIN_WIDTH_PIXELS);
169
171 void drawChar(uint8_t theChar, int32_t pixelX, int32_t pixelY, int32_t textWidth, int32_t textHeight,
172 int32_t scrollPos = 0, int32_t endX = OLED_MAIN_WIDTH_PIXELS);
173
177 int32_t getCharIndex(uint8_t theChar);
178
183 int32_t getCharWidthInPixels(uint8_t theChar, int32_t textHeight);
184
190 int32_t getCharSpacingInPixels(uint8_t theChar, int32_t textHeight, bool isLastChar);
191
196 int32_t getStringWidthInPixels(char const* string, int32_t textHeight);
197
208 void drawGraphicMultiLine(uint8_t const* graphic, int32_t startX, int32_t startY, int32_t width, int32_t height = 8,
209 int32_t numBytesTall = 1, bool reversed = false);
210
214 void drawScreenTitle(std::string_view text, bool drawSeparator = true);
215
222 void invertArea(int32_t xMin, int32_t width, int32_t startY, int32_t endY);
223
230 void invertAreaRounded(int32_t xMin, int32_t width, int32_t startY, int32_t endY);
231
238 void invertLeftEdgeForMenuHighlighting(int32_t xMin, int32_t width, int32_t startY, int32_t endY);
239
241
243 static constexpr uint32_t kImageHeight = OLED_MAIN_HEIGHT_PIXELS >> 3;
245 static constexpr uint32_t kImageWidth = OLED_MAIN_WIDTH_PIXELS;
246
247 using ImageStore = uint8_t[kImageHeight][kImageWidth];
248
250 ImageStore& hackGetImageStore() { return image_; }
251
252private:
253 [[gnu::aligned(CACHE_LINE_SIZE)]] uint8_t image_[kImageHeight][kImageWidth];
254};
255} // namespace oled_canvas
256} // namespace deluge::hid::display
Definition d_stringbuf.h:16
void drawString(std::string_view str, int32_t pixelX, int32_t pixelY, int32_t textWidth, int32_t textHeight, int32_t scrollPos=0, int32_t endX=OLED_MAIN_WIDTH_PIXELS, bool useTextWidth=false)
Definition canvas.cpp:180
void clearPixel(int32_t x, int32_t y)
Clear a single pixel.
Definition canvas.cpp:75
void drawScreenTitle(std::string_view text, bool drawSeparator=true)
Definition canvas.cpp:591
int32_t getStringWidthInPixels(char const *string, int32_t textHeight)
Definition canvas.cpp:497
void drawChar(uint8_t theChar, int32_t pixelX, int32_t pixelY, int32_t textWidth, int32_t textHeight, int32_t scrollPos=0, int32_t endX=OLED_MAIN_WIDTH_PIXELS)
Draw a single character.
Definition canvas.cpp:332
void drawRectangleRounded(int32_t minX, int32_t minY, int32_t maxX, int32_t maxY)
Definition canvas.cpp:172
static constexpr uint32_t kImageHeight
Height of the image in bytes.
Definition canvas.h:243
static constexpr uint32_t kImageWidth
Width of the image in pixels.
Definition canvas.h:245
void drawStringCentered(char const *string, int32_t startX, int32_t startY, int32_t textSpacingX, int32_t textSpacingY, int32_t totalWidth)
Definition canvas.cpp:254
void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, bool thick=false)
Definition canvas.cpp:124
void drawPixel(int32_t x, int32_t y)
Set a single pixel.
Definition canvas.cpp:70
void clear()
Clear the entire image.
Definition canvas.h:47
void drawHorizontalLine(int32_t pixelY, int32_t startX, int32_t endX)
Definition canvas.cpp:80
void drawStringAlignRight(char const *string, int32_t pixelY, int32_t textWidth, int32_t textHeight, int32_t rightPos=OLED_MAIN_WIDTH_PIXELS)
Definition canvas.cpp:322
int32_t getCharSpacingInPixels(uint8_t theChar, int32_t textHeight, bool isLastChar)
Definition canvas.cpp:459
int32_t getCharWidthInPixels(uint8_t theChar, int32_t textHeight)
Definition canvas.cpp:427
void drawStringCentred(char const *string, int32_t pixelY, int32_t textWidth, int32_t textHeight, int32_t centrePos=OLED_MAIN_WIDTH_PIXELS/2)
Definition canvas.cpp:246
void clearAreaExact(int32_t minX, int32_t minY, int32_t maxX, int32_t maxY)
Definition canvas.cpp:29
void invertArea(int32_t xMin, int32_t width, int32_t startY, int32_t endY)
Definition canvas.cpp:601
void drawGraphicMultiLine(uint8_t const *graphic, int32_t startX, int32_t startY, int32_t width, int32_t height=8, int32_t numBytesTall=1, bool reversed=false)
Definition canvas.cpp:511
void invertLeftEdgeForMenuHighlighting(int32_t xMin, int32_t width, int32_t startY, int32_t endY)
inverts just the left edge
Definition canvas.cpp:639
void drawStringCentredShrinkIfNecessary(char const *string, int32_t pixelY, int32_t textWidth, int32_t textHeight)
Definition canvas.cpp:287
int32_t getCharIndex(uint8_t theChar)
Definition canvas.cpp:405
void drawVerticalLine(int32_t pixelX, int32_t startY, int32_t endY)
Definition canvas.cpp:91
void invertAreaRounded(int32_t xMin, int32_t width, int32_t startY, int32_t endY)
Definition canvas.cpp:627
void drawRectangle(int32_t minX, int32_t minY, int32_t maxX, int32_t maxY)
Definition canvas.cpp:164
ImageStore & hackGetImageStore()
XXX: DO NOT USE THIS OUTSIDE OF THE CORE OLED CODE.
Definition canvas.h:250