ESP32VGA
ESP32 VGA Controller and Graphics Library
VGACanvas.h
Go to the documentation of this file.
1 /*
2  Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com)
3  Copyright (c) 2018 Fabrizio Di Vittorio.
4  All rights reserved.
5 
6  This file is part of ESP32VGA Library.
7 
8  ESP32VGA is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  ESP32VGA is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with ESP32VGA. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 
23 #ifndef _VGACANVAS_H_INCLUDED
24 #define _VGACANVAS_H_INCLUDED
25 
26 
34 #include <stdint.h>
35 #include <stddef.h>
36 
37 #include "VGAController.h"
38 
39 
40 namespace ESP32VGA {
41 
42 
43 #ifndef FONTINFO
44 #define FONTINFO
45 
46 #define FONTINFOFLAGS_ITALIC 1
47 #define FONTINFOFLAGS_UNDERLINE 2
48 #define FONTINFODLAFS_STRIKEOUT 4
49 
50 struct FontInfo {
51  uint8_t pointSize;
52  uint8_t width;
53  uint8_t height;
54  uint8_t ascent;
55  uint8_t inleading;
56  uint8_t exleading;
57  uint8_t flags;
58  uint16_t weight;
59  uint16_t charset;
60  uint8_t const * data;
61 };
62 
63 #endif
64 
65 
66 
67 
90 
91 public:
92 
94 
98  uint16_t getWidth();
99 
103  uint16_t getHeight();
104 
108  void clear();
109 
120  void setScrollingRegion(int16_t X1, int16_t Y1, int16_t X2, int16_t Y2);
121 
132  void scroll(int16_t offsetX, int16_t offsetY);
133 
149  void moveTo(int16_t X, int16_t Y);
150 
166  void setPenColor(uint8_t red, uint8_t green, uint8_t blue);
167 
178  void setPenColor(Color color);
179 
195  void setBrushColor(uint8_t red, uint8_t green, uint8_t blue);
196 
207  void setBrushColor(Color color);
208 
215  void setPixel(int16_t X, int16_t Y);
216 
235  void lineTo(int16_t X, int16_t Y);
236 
254  void drawLine(int16_t X1, int16_t Y1, int16_t X2, int16_t Y2);
255 
270  void drawRectangle(int16_t X1, int16_t Y1, int16_t X2, int16_t Y2);
271 
292  void fillRectangle(int16_t X1, int16_t Y1, int16_t X2, int16_t Y2);
293 
294 #if VGAHAS_INVERTRECT
295 
306  void invertRectangle(int16_t X1, int16_t Y1, int16_t X2, int16_t Y2);
307 
308 #endif
309 
318  void swapRectangle(int16_t X1, int16_t Y1, int16_t X2, int16_t Y2);
319 
334  void drawEllipse(int16_t X, int16_t Y, uint16_t width, uint16_t height);
335 
356  void fillEllipse(int16_t X, int16_t Y, uint16_t width, uint16_t height);
357 
363  void waitCompletion(bool waitVSync = true);
364 
395  void drawGlyph(int16_t X, int16_t Y, uint16_t width, uint16_t height, uint8_t const * data, uint16_t index = 0);
396 
397  void setGlyphOptions(GlyphOptions_t options);
398 
399  void renderGlyphsBuffer(int16_t itemX, int16_t itemY, GlyphsBuffer_t const * glyphsBuffer);
400 
401  void setPaintOptions(PaintOptions_t options);
402 
412  static FontInfo const * getPresetFontInfo(uint8_t columns);
413 
414  void selectFont(FontInfo const& fontInfo);
415 
416  void drawText(int16_t X, int16_t Y, char const * text, bool wrap = false);
417 
418  void drawText(FontInfo const& fontInfo, int16_t X, int16_t Y, char const * text, bool wrap = false);
419 
420  void drawTextFmt(int16_t X, int16_t Y, const char *format, ...);
421 
422  void copyRect(int16_t sourceX, int16_t sourceY, int16_t destX, int16_t destY, uint16_t width, uint16_t height);
423 
424 #if VGAHAS_READWRITERAWDATA
425 
426  void readRawData(int16_t sourceX, int16_t sourceY, uint16_t width, uint16_t height, uint8_t * dest);
427 
428  void writeRawData(uint8_t * source, int16_t destX, int16_t destY, uint16_t width, uint16_t height);
429 
430 #endif
431 
432 private:
433 
434  FontInfo const * m_fontInfo;
435  uint8_t m_textHorizRate; // specify character size: 1 = m_fontInfo.width, 2 = m_fontInfo.width * 2, etc...
436 };
437 
438 
439 } // end of namespace
440 
441 
442 
443 extern ESP32VGA::VGACanvasClass VGACanvas;
444 
445 
446 
447 #endif
void scroll(int16_t offsetX, int16_t offsetY)
Scrolls pixels horizontally and/or vertically.
Definition: VGACanvas.cpp:76
Color
This enum defines named colors.
Definition: VGAController.h:184
uint16_t getWidth()
Returns the canvas width in pixels. This is equivalent to VGA Controller viewport width...
Definition: VGACanvas.cpp:46
void drawEllipse(int16_t X, int16_t Y, uint16_t width, uint16_t height)
Draws an ellipse specifying center and size, using current pen color.
Definition: VGACanvas.cpp:220
void drawLine(int16_t X1, int16_t Y1, int16_t X2, int16_t Y2)
Draws a line specifying initial and ending coordinates.
Definition: VGACanvas.cpp:164
void waitCompletion(bool waitVSync=true)
Waits for drawing queue to become empty.
Definition: VGACanvas.cpp:58
void setPixel(int16_t X, int16_t Y)
Fills a single pixel with the pen color.
Definition: VGACanvas.cpp:101
void fillRectangle(int16_t X1, int16_t Y1, int16_t X2, int16_t Y2)
Fills a rectangle using the current brush color.
Definition: VGACanvas.cpp:181
void clear()
Fills the entire canvas with the brush color.
Definition: VGACanvas.cpp:67
void moveTo(int16_t X, int16_t Y)
Moves current pen position to the spcified coordinates.
Definition: VGACanvas.cpp:110
Definition: VGACanvas.cpp:29
static FontInfo const * getPresetFontInfo(uint8_t columns)
Gets the font info that best fits the specified number of columns.
Definition: VGACanvas.cpp:338
Specifies general paint options.
Definition: VGAController.h:329
A class with a set of drawing methods.
Definition: VGACanvas.h:89
void swapRectangle(int16_t X1, int16_t Y1, int16_t X2, int16_t Y2)
Swaps pen and brush colors of the specified rectangle.
Definition: VGACanvas.cpp:201
uint16_t getHeight()
Returns the canvas height in pixels. This is equivalent to VGA Controller viewport height...
Definition: VGACanvas.cpp:52
void drawGlyph(int16_t X, int16_t Y, uint16_t width, uint16_t height, uint8_t const *data, uint16_t index=0)
Draws a glyph at specified position.
Definition: VGACanvas.cpp:230
void fillEllipse(int16_t X, int16_t Y, uint16_t width, uint16_t height)
Fills an ellipse specifying center and size, using current brush color.
Definition: VGACanvas.cpp:210
Specifies various glyph painting options.
Definition: VGAController.h:301
void setPenColor(uint8_t red, uint8_t green, uint8_t blue)
Sets pen (foreground) color specifying color components.
Definition: VGACanvas.cpp:128
This file contains VGAControllerClass definition and the VGAController instance.
void setScrollingRegion(int16_t X1, int16_t Y1, int16_t X2, int16_t Y2)
Defines the scrolling region.
Definition: VGACanvas.cpp:92
void setBrushColor(uint8_t red, uint8_t green, uint8_t blue)
Sets brush (background) color specifying color components.
Definition: VGACanvas.cpp:146
void lineTo(int16_t X, int16_t Y)
Draws a line starting from current pen position.
Definition: VGACanvas.cpp:155
void drawRectangle(int16_t X1, int16_t Y1, int16_t X2, int16_t Y2)
Draws a rectangle using the current pen color.
Definition: VGACanvas.cpp:171