Deluge Firmware 1.3.0
Build date: 2025.04.16
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 <cstdint>
23#include <cstring>
24#include <string_view>
25
26namespace deluge::hid::display {
27class OLED;
28
29namespace oled_canvas {
30class Canvas {
31public:
32 Canvas() = default;
33 ~Canvas() = default;
34
35 Canvas(Canvas const& other) = delete;
36 Canvas(Canvas&& other) = delete;
37
38 Canvas& operator=(Canvas const& other) = delete;
39 Canvas& operator=(Canvas&& other) = delete;
40
43
45 void clear() {
46 // Takes about 1 fast-timer tick (whereas entire rendering takes around 8 to 15).
47 // So, not worth trying to use DMA here or anything.
48 memset(image_, 0, sizeof(image_));
49 };
50
57 void clearAreaExact(int32_t minX, int32_t minY, int32_t maxX, int32_t maxY);
58
60 void drawPixel(int32_t x, int32_t y);
61
67 void drawHorizontalLine(int32_t pixelY, int32_t startX, int32_t endX);
68
74 void drawVerticalLine(int32_t pixelX, int32_t startY, int32_t endY);
75
82 void drawRectangle(int32_t minX, int32_t minY, int32_t maxX, int32_t maxY);
83
94 void drawString(std::string_view str, int32_t pixelX, int32_t pixelY, int32_t textWidth, int32_t textHeight,
95 int32_t scrollPos = 0, int32_t endX = OLED_MAIN_WIDTH_PIXELS, bool useTextWidth = false);
96
106 void drawStringCentred(char const* string, int32_t pixelY, int32_t textWidth, int32_t textHeight,
107 int32_t centrePos = OLED_MAIN_WIDTH_PIXELS / 2);
108
115 void drawStringCentredShrinkIfNecessary(char const* string, int32_t pixelY, int32_t textWidth, int32_t textHeight);
116
124 void drawStringAlignRight(char const* string, int32_t pixelY, int32_t textWidth, int32_t textHeight,
125 int32_t rightPos = OLED_MAIN_WIDTH_PIXELS);
126
128 void drawChar(uint8_t theChar, int32_t pixelX, int32_t pixelY, int32_t textWidth, int32_t textHeight,
129 int32_t scrollPos = 0, int32_t endX = OLED_MAIN_WIDTH_PIXELS);
130
134 int32_t getCharIndex(uint8_t theChar);
135
140 int32_t getCharWidthInPixels(uint8_t theChar, int32_t textHeight);
141
147 int32_t getCharSpacingInPixels(uint8_t theChar, int32_t textHeight, bool isLastChar);
148
153 int32_t getStringWidthInPixels(char const* string, int32_t textHeight);
154
165 void drawGraphicMultiLine(uint8_t const* graphic, int32_t startX, int32_t startY, int32_t width, int32_t height = 8,
166 int32_t numBytesTall = 1);
167
171 void drawScreenTitle(std::string_view text);
172
179 void invertArea(int32_t xMin, int32_t width, int32_t startY, int32_t endY);
180
187 void invertLeftEdgeForMenuHighlighting(int32_t xMin, int32_t width, int32_t startY, int32_t endY);
188
190
192 static constexpr uint32_t kImageHeight = OLED_MAIN_HEIGHT_PIXELS >> 3;
194 static constexpr uint32_t kImageWidth = OLED_MAIN_WIDTH_PIXELS;
195
196 using ImageStore = uint8_t[kImageHeight][kImageWidth];
197
199 ImageStore& hackGetImageStore() { return image_; }
200
201private:
202 [[gnu::aligned(CACHE_LINE_SIZE)]] uint8_t image_[kImageHeight][kImageWidth];
203};
204} // namespace oled_canvas
205} // namespace deluge::hid::display
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:123
int32_t getStringWidthInPixels(char const *string, int32_t textHeight)
Definition canvas.cpp:387
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:245
static constexpr uint32_t kImageHeight
Height of the image in bytes.
Definition canvas.h:192
static constexpr uint32_t kImageWidth
Width of the image in pixels.
Definition canvas.h:194
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:401
void drawPixel(int32_t x, int32_t y)
Set a single pixel.
Definition canvas.cpp:66
void clear()
Clear the entire image.
Definition canvas.h:45
void drawHorizontalLine(int32_t pixelY, int32_t startX, int32_t endX)
Definition canvas.cpp:71
void drawStringAlignRight(char const *string, int32_t pixelY, int32_t textWidth, int32_t textHeight, int32_t rightPos=OLED_MAIN_WIDTH_PIXELS)
Definition canvas.cpp:235
int32_t getCharSpacingInPixels(uint8_t theChar, int32_t textHeight, bool isLastChar)
Definition canvas.cpp:357
int32_t getCharWidthInPixels(uint8_t theChar, int32_t textHeight)
Definition canvas.cpp:328
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:189
void clearAreaExact(int32_t minX, int32_t minY, int32_t maxX, int32_t maxY)
Definition canvas.cpp:25
void invertArea(int32_t xMin, int32_t width, int32_t startY, int32_t endY)
Definition canvas.cpp:476
void drawScreenTitle(std::string_view text)
Definition canvas.cpp:467
void invertLeftEdgeForMenuHighlighting(int32_t xMin, int32_t width, int32_t startY, int32_t endY)
inverts just the left edge
Definition canvas.cpp:503
void drawStringCentredShrinkIfNecessary(char const *string, int32_t pixelY, int32_t textWidth, int32_t textHeight)
Definition canvas.cpp:203
int32_t getCharIndex(uint8_t theChar)
Definition canvas.cpp:310
void drawVerticalLine(int32_t pixelX, int32_t startY, int32_t endY)
Definition canvas.cpp:82
void drawRectangle(int32_t minX, int32_t minY, int32_t maxX, int32_t maxY)
Definition canvas.cpp:115
ImageStore & hackGetImageStore()
XXX: DO NOT USE THIS OUTSIDE OF THE CORE OLED CODE.
Definition canvas.h:199