Deluge Firmware 1.3.0
Build date: 2025.06.24
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 {
31class Canvas {
32public:
33 Canvas() = default;
34 ~Canvas() = default;
35
36 Canvas(Canvas const& other) = delete;
37 Canvas(Canvas&& other) = delete;
38
39 Canvas& operator=(Canvas const& other) = delete;
40 Canvas& operator=(Canvas&& other) = delete;
41
44
46 void clear() {
47 // Takes about 1 fast-timer tick (whereas entire rendering takes around 8 to 15).
48 // So, not worth trying to use DMA here or anything.
49 memset(image_, 0, sizeof(image_));
50 };
51
58 void clearAreaExact(int32_t minX, int32_t minY, int32_t maxX, int32_t maxY);
59
61 void drawPixel(int32_t x, int32_t y);
62
64 void clearPixel(int32_t x, int32_t y);
65
71 void drawHorizontalLine(int32_t pixelY, int32_t startX, int32_t endX);
72
78 void drawVerticalLine(int32_t pixelX, int32_t startY, int32_t endY);
79
86 void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, bool thick = false);
87
94 void drawRectangle(int32_t minX, int32_t minY, int32_t maxX, int32_t maxY);
95
102 void drawRectangleRounded(int32_t minX, int32_t minY, int32_t maxX, int32_t maxY);
103
114 void drawString(std::string_view str, int32_t pixelX, int32_t pixelY, int32_t textWidth, int32_t textHeight,
115 int32_t scrollPos = 0, int32_t endX = OLED_MAIN_WIDTH_PIXELS, bool useTextWidth = false);
116
126 void drawStringCentred(char const* string, int32_t pixelY, int32_t textWidth, int32_t textHeight,
127 int32_t centrePos = OLED_MAIN_WIDTH_PIXELS / 2);
128
137 void drawStringCentered(char const* string, int32_t startX, int32_t startY, int32_t textSpacingX,
138 int32_t textSpacingY, int32_t totalWidth);
139
148 void drawStringCentered(StringBuf& stringBuf, int32_t startX, int32_t startY, int32_t textSpacingX,
149 int32_t textSpacingY, int32_t totalWidth);
150
157 void drawStringCentredShrinkIfNecessary(char const* string, int32_t pixelY, int32_t textWidth, int32_t textHeight);
158
166 void drawStringAlignRight(char const* string, int32_t pixelY, int32_t textWidth, int32_t textHeight,
167 int32_t rightPos = OLED_MAIN_WIDTH_PIXELS);
168
170 void drawChar(uint8_t theChar, int32_t pixelX, int32_t pixelY, int32_t textWidth, int32_t textHeight,
171 int32_t scrollPos = 0, int32_t endX = OLED_MAIN_WIDTH_PIXELS);
172
176 int32_t getCharIndex(uint8_t theChar);
177
182 int32_t getCharWidthInPixels(uint8_t theChar, int32_t textHeight);
183
189 int32_t getCharSpacingInPixels(uint8_t theChar, int32_t textHeight, bool isLastChar);
190
195 int32_t getStringWidthInPixels(char const* string, int32_t textHeight);
196
207 void drawGraphicMultiLine(uint8_t const* graphic, int32_t startX, int32_t startY, int32_t width, int32_t height = 8,
208 int32_t numBytesTall = 1);
209
213 void drawScreenTitle(std::string_view text, bool drawSeparator = true);
214
221 void invertArea(int32_t xMin, int32_t width, int32_t startY, int32_t endY);
222
229 void invertAreaRounded(int32_t xMin, int32_t width, int32_t startY, int32_t endY);
230
237 void invertLeftEdgeForMenuHighlighting(int32_t xMin, int32_t width, int32_t startY, int32_t endY);
238
240
242 static constexpr uint32_t kImageHeight = OLED_MAIN_HEIGHT_PIXELS >> 3;
244 static constexpr uint32_t kImageWidth = OLED_MAIN_WIDTH_PIXELS;
245
246 using ImageStore = uint8_t[kImageHeight][kImageWidth];
247
249 ImageStore& hackGetImageStore() { return image_; }
250
251private:
252 [[gnu::aligned(CACHE_LINE_SIZE)]] uint8_t image_[kImageHeight][kImageWidth];
253};
254} // namespace oled_canvas
255} // 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:179
void clearPixel(int32_t x, int32_t y)
Clear a single pixel.
Definition canvas.cpp:74
void drawScreenTitle(std::string_view text, bool drawSeparator=true)
Definition canvas.cpp:570
int32_t getStringWidthInPixels(char const *string, int32_t textHeight)
Definition canvas.cpp:490
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:325
void drawRectangleRounded(int32_t minX, int32_t minY, int32_t maxX, int32_t maxY)
Definition canvas.cpp:171
static constexpr uint32_t kImageHeight
Height of the image in bytes.
Definition canvas.h:242
static constexpr uint32_t kImageWidth
Width of the image in pixels.
Definition canvas.h:244
void drawStringCentered(char const *string, int32_t startX, int32_t startY, int32_t textSpacingX, int32_t textSpacingY, int32_t totalWidth)
Definition canvas.cpp:253
void drawGraphicMultiLine(uint8_t const *graphic, int32_t startX, int32_t startY, int32_t width, int32_t height=8, int32_t numBytesTall=1)
Definition canvas.cpp:504
void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, bool thick=false)
Definition canvas.cpp:123
void drawPixel(int32_t x, int32_t y)
Set a single pixel.
Definition canvas.cpp:69
void clear()
Clear the entire image.
Definition canvas.h:46
void drawHorizontalLine(int32_t pixelY, int32_t startX, int32_t endX)
Definition canvas.cpp:79
void drawStringAlignRight(char const *string, int32_t pixelY, int32_t textWidth, int32_t textHeight, int32_t rightPos=OLED_MAIN_WIDTH_PIXELS)
Definition canvas.cpp:315
int32_t getCharSpacingInPixels(uint8_t theChar, int32_t textHeight, bool isLastChar)
Definition canvas.cpp:452
int32_t getCharWidthInPixels(uint8_t theChar, int32_t textHeight)
Definition canvas.cpp:420
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:245
void clearAreaExact(int32_t minX, int32_t minY, int32_t maxX, int32_t maxY)
Definition canvas.cpp:28
void invertArea(int32_t xMin, int32_t width, int32_t startY, int32_t endY)
Definition canvas.cpp:580
void invertLeftEdgeForMenuHighlighting(int32_t xMin, int32_t width, int32_t startY, int32_t endY)
inverts just the left edge
Definition canvas.cpp:618
void drawStringCentredShrinkIfNecessary(char const *string, int32_t pixelY, int32_t textWidth, int32_t textHeight)
Definition canvas.cpp:280
int32_t getCharIndex(uint8_t theChar)
Definition canvas.cpp:398
void drawVerticalLine(int32_t pixelX, int32_t startY, int32_t endY)
Definition canvas.cpp:90
void invertAreaRounded(int32_t xMin, int32_t width, int32_t startY, int32_t endY)
Definition canvas.cpp:606
void drawRectangle(int32_t minX, int32_t minY, int32_t maxX, int32_t maxY)
Definition canvas.cpp:163
ImageStore & hackGetImageStore()
XXX: DO NOT USE THIS OUTSIDE OF THE CORE OLED CODE.
Definition canvas.h:249