Deluge Firmware 1.3.0
Build date: 2025.06.05
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
68 void drawHorizontalLine(int32_t pixelY, int32_t startX, int32_t endX);
69
75 void drawVerticalLine(int32_t pixelX, int32_t startY, int32_t endY);
76
83 void drawRectangle(int32_t minX, int32_t minY, int32_t maxX, int32_t maxY);
84
95 void drawString(std::string_view str, int32_t pixelX, int32_t pixelY, int32_t textWidth, int32_t textHeight,
96 int32_t scrollPos = 0, int32_t endX = OLED_MAIN_WIDTH_PIXELS, bool useTextWidth = false);
97
107 void drawStringCentred(char const* string, int32_t pixelY, int32_t textWidth, int32_t textHeight,
108 int32_t centrePos = OLED_MAIN_WIDTH_PIXELS / 2);
109
118 void drawStringCentered(char const* string, int32_t startX, int32_t startY, int32_t textSpacingX,
119 int32_t textSpacingY, int32_t totalWidth);
120
129 void drawStringCentered(StringBuf& stringBuf, int32_t startX, int32_t startY, int32_t textSpacingX,
130 int32_t textSpacingY, int32_t totalWidth);
131
138 void drawStringCentredShrinkIfNecessary(char const* string, int32_t pixelY, int32_t textWidth, int32_t textHeight);
139
147 void drawStringAlignRight(char const* string, int32_t pixelY, int32_t textWidth, int32_t textHeight,
148 int32_t rightPos = OLED_MAIN_WIDTH_PIXELS);
149
151 void drawChar(uint8_t theChar, int32_t pixelX, int32_t pixelY, int32_t textWidth, int32_t textHeight,
152 int32_t scrollPos = 0, int32_t endX = OLED_MAIN_WIDTH_PIXELS);
153
157 int32_t getCharIndex(uint8_t theChar);
158
163 int32_t getCharWidthInPixels(uint8_t theChar, int32_t textHeight);
164
170 int32_t getCharSpacingInPixels(uint8_t theChar, int32_t textHeight, bool isLastChar);
171
176 int32_t getStringWidthInPixels(char const* string, int32_t textHeight);
177
188 void drawGraphicMultiLine(uint8_t const* graphic, int32_t startX, int32_t startY, int32_t width, int32_t height = 8,
189 int32_t numBytesTall = 1);
190
194 void drawScreenTitle(std::string_view text);
195
202 void invertArea(int32_t xMin, int32_t width, int32_t startY, int32_t endY);
203
210 void invertLeftEdgeForMenuHighlighting(int32_t xMin, int32_t width, int32_t startY, int32_t endY);
211
213
215 static constexpr uint32_t kImageHeight = OLED_MAIN_HEIGHT_PIXELS >> 3;
217 static constexpr uint32_t kImageWidth = OLED_MAIN_WIDTH_PIXELS;
218
219 using ImageStore = uint8_t[kImageHeight][kImageWidth];
220
222 ImageStore& hackGetImageStore() { return image_; }
223
224private:
225 [[gnu::aligned(CACHE_LINE_SIZE)]] uint8_t image_[kImageHeight][kImageWidth];
226};
227} // namespace oled_canvas
228} // 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:124
int32_t getStringWidthInPixels(char const *string, int32_t textHeight)
Definition canvas.cpp:431
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:270
static constexpr uint32_t kImageHeight
Height of the image in bytes.
Definition canvas.h:215
static constexpr uint32_t kImageWidth
Width of the image in pixels.
Definition canvas.h:217
void drawStringCentered(char const *string, int32_t startX, int32_t startY, int32_t textSpacingX, int32_t textSpacingY, int32_t totalWidth)
Definition canvas.cpp:198
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:445
void drawPixel(int32_t x, int32_t y)
Set a single pixel.
Definition canvas.cpp:67
void clear()
Clear the entire image.
Definition canvas.h:46
void drawHorizontalLine(int32_t pixelY, int32_t startX, int32_t endX)
Definition canvas.cpp:72
void drawStringAlignRight(char const *string, int32_t pixelY, int32_t textWidth, int32_t textHeight, int32_t rightPos=OLED_MAIN_WIDTH_PIXELS)
Definition canvas.cpp:260
int32_t getCharSpacingInPixels(uint8_t theChar, int32_t textHeight, bool isLastChar)
Definition canvas.cpp:393
int32_t getCharWidthInPixels(uint8_t theChar, int32_t textHeight)
Definition canvas.cpp:361
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:190
void clearAreaExact(int32_t minX, int32_t minY, int32_t maxX, int32_t maxY)
Definition canvas.cpp:26
void invertArea(int32_t xMin, int32_t width, int32_t startY, int32_t endY)
Definition canvas.cpp:520
void drawScreenTitle(std::string_view text)
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:547
void drawStringCentredShrinkIfNecessary(char const *string, int32_t pixelY, int32_t textWidth, int32_t textHeight)
Definition canvas.cpp:225
int32_t getCharIndex(uint8_t theChar)
Definition canvas.cpp:343
void drawVerticalLine(int32_t pixelX, int32_t startY, int32_t endY)
Definition canvas.cpp:83
void drawRectangle(int32_t minX, int32_t minY, int32_t maxX, int32_t maxY)
Definition canvas.cpp:116
ImageStore & hackGetImageStore()
XXX: DO NOT USE THIS OUTSIDE OF THE CORE OLED CODE.
Definition canvas.h:222