TinyGPU
Loading...
Searching...
No Matches
ISurface.h
Go to the documentation of this file.
1#pragma once
2
3#include <stddef.h>
4#include <stdint.h>
5
6
7#include "RGB565.h"
8
9namespace tinygpu {
10
11
12// Forward declaration of IFont to avoid circular dependency.
13template <typename RGB_T> class IFont;
14
15/**
16 * @brief Abstract framebuffer and drawing interface for TinyGPU surfaces.
17 *
18 * Implementations expose pixel access, primitive drawing, sprite operations,
19 * and text rendering through a common API.
20 *
21 * @note The coordinate x=0 and y=0 corresponds to the top-left corner of the
22 * surface. The x coordinate increases to the right and the y coordinate
23 * increases downwards.
24 */
25template <typename RGB_T = RGB565>
26class ISurface {
27 public:
28 /// Destroys the framebuffer interface.
29 virtual ~ISurface() = default;
30
31 /// Initializes the framebuffer surface.
32 virtual bool begin() = 0;
33 /// Closes the framebuffer and releases resources.
34 virtual void end() = 0;
35
36 /// Resizes the framebuffer surface.
37 virtual bool resize(size_t newWidth, size_t newHeight) = 0;
38 /// Sets a pixel at the given position.
39 virtual void setPixel(size_t x, size_t y, RGB_T color) = 0;
40 /// Returns the pixel at the given position.
41 virtual RGB_T getPixel(size_t x, size_t y) const = 0;
42 /// Scrolls the framebuffer content by the specified offsets.
43 virtual void scroll(int dx, int dy) = 0;
44 /// Clears the framebuffer with a single color.
45 virtual void clear(RGB_T color = RGB_T(0)) = 0;
46 /// Draws a line between two points.
47 virtual void drawLine(size_t x0, size_t y0, size_t x1, size_t y1,
48 RGB_T color) = 0;
49 /// Draws a rectangle outline.
50 virtual void drawRect(size_t x, size_t y, size_t w, size_t h,
51 RGB_T color) = 0;
52 /// Fills a rectangle.
53 virtual void fillRect(size_t x, size_t y, size_t w, size_t h,
54 RGB_T color) = 0;
55 /// Draws a circle outline.
56 virtual void drawCircle(size_t x, size_t y, size_t r, RGB_T color) = 0;
57 /// Fills a circle.
58 virtual void fillCircle(size_t x, size_t y, size_t r, RGB_T color) = 0;
59 /// Draws a sprite using an optional transparent color.
60 virtual void drawSprite(size_t x, size_t y, const ISurface<RGB_T>& sprite,
61 RGB_T invisibleColor = RGB_T(0)) = 0;
62 /// Clears the area covered by a sprite.
63 virtual void clearSprite(size_t x, size_t y, ISurface<RGB_T>& sprite,
64 RGB_T clearColor = RGB_T(0)) = 0;
65 /// Copies pixels from the framebuffer into a sprite.
66 virtual void copySprite(size_t x, size_t y, const ISurface<RGB_T>& sprite) = 0;
67 /// Returns the framebuffer width in pixels.
68 virtual size_t width() const = 0;
69 /// Returns the framebuffer height in pixels.
70 virtual size_t height() const = 0;
71 /// Draws UTF-8 text using the configured font.
72 virtual void drawText(int16_t x, int16_t y, const char* text,
73 RGB_T foreground, RGB_T background = RGB_T(0),
74 bool opaque = false, uint8_t scale = 1,
75 uint8_t spacing = 1, uint8_t lineSpacing = 1) = 0;
76
77 /// Returns the currently set font for text rendering.
78 virtual IFont<RGB_T>& font() = 0;
79 /// Provides access to the framebuffer as a byte buffer.
80 virtual const uint8_t* data() const = 0;
81 /// Provides the total data size in bytes.
82 virtual size_t size() const = 0;
83};
84
85
86} // namespace tinygpu
Font rendering interface for TinyGPU-compatible framebuffers.
Definition: IFont.h:19
virtual ~ISurface()=default
Destroys the framebuffer interface.
virtual void fillRect(size_t x, size_t y, size_t w, size_t h, RGB_T color)=0
Fills a rectangle.
virtual size_t height() const =0
Returns the framebuffer height in pixels.
virtual void drawLine(size_t x0, size_t y0, size_t x1, size_t y1, RGB_T color)=0
Draws a line between two points.
virtual void copySprite(size_t x, size_t y, const ISurface< RGB_T > &sprite)=0
Copies pixels from the framebuffer into a sprite.
virtual void drawRect(size_t x, size_t y, size_t w, size_t h, RGB_T color)=0
Draws a rectangle outline.
virtual void fillCircle(size_t x, size_t y, size_t r, RGB_T color)=0
Fills a circle.
virtual bool resize(size_t newWidth, size_t newHeight)=0
Resizes the framebuffer surface.
virtual void clearSprite(size_t x, size_t y, ISurface< RGB_T > &sprite, RGB_T clearColor=RGB_T(0))=0
Clears the area covered by a sprite.
virtual void setPixel(size_t x, size_t y, RGB_T color)=0
Sets a pixel at the given position.
virtual void scroll(int dx, int dy)=0
Scrolls the framebuffer content by the specified offsets.
virtual void end()=0
Closes the framebuffer and releases resources.
virtual size_t size() const =0
Provides the total data size in bytes.
virtual void drawText(int16_t x, int16_t y, const char *text, RGB_T foreground, RGB_T background=RGB_T(0), bool opaque=false, uint8_t scale=1, uint8_t spacing=1, uint8_t lineSpacing=1)=0
Draws UTF-8 text using the configured font.
virtual void clear(RGB_T color=RGB_T(0))=0
Clears the framebuffer with a single color.
virtual size_t width() const =0
Returns the framebuffer width in pixels.
virtual RGB_T getPixel(size_t x, size_t y) const =0
Returns the pixel at the given position.
virtual IFont< RGB_T > & font()=0
Returns the currently set font for text rendering.
virtual bool begin()=0
Initializes the framebuffer surface.
virtual void drawCircle(size_t x, size_t y, size_t r, RGB_T color)=0
Draws a circle outline.
virtual void drawSprite(size_t x, size_t y, const ISurface< RGB_T > &sprite, RGB_T invisibleColor=RGB_T(0))=0
Draws a sprite using an optional transparent color.
virtual const uint8_t * data() const =0
Provides access to the framebuffer as a byte buffer.
RGB color stored in 16-bit RGB565 format.
Definition: RGB565.h:13
Definition: AVIWriter.h:9