FabGL
ESP32 VGA Controller and Graphics Library
canvas.h
Go to the documentation of this file.
1 /*
2  Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - <http://www.fabgl.com>
3  Copyright (c) 2019 Fabrizio Di Vittorio.
4  All rights reserved.
5 
6  This file is part of FabGL Library.
7 
8  FabGL 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  FabGL 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 FabGL. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 
23 #ifndef _CANVAS_H_INCLUDED
24 #define _CANVAS_H_INCLUDED
25 
26 
34 #include <stdint.h>
35 #include <stddef.h>
36 
37 #include "vgacontroller.h"
38 
39 
40 namespace fabgl {
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 
88 class CanvasClass {
89 
90 public:
91 
92  CanvasClass();
93 
101  int getWidth() { return VGAController.getViewPortWidth(); }
102 
110  int getHeight() { return VGAController.getViewPortHeight(); }
111 
115  void clear();
116 
127  void setScrollingRegion(int X1, int Y1, int X2, int Y2);
128 
139  void scroll(int offsetX, int offsetY);
140 
156  void moveTo(int X, int Y);
157 
173  void setPenColor(uint8_t red, uint8_t green, uint8_t blue);
174 
185  void setPenColor(Color color);
186 
202  void setBrushColor(uint8_t red, uint8_t green, uint8_t blue);
203 
214  void setBrushColor(Color color);
215 
222  void setPixel(int X, int Y);
223 
242  void lineTo(int X, int Y);
243 
261  void drawLine(int X1, int Y1, int X2, int Y2);
262 
277  void drawRectangle(int X1, int Y1, int X2, int Y2);
278 
299  void fillRectangle(int X1, int Y1, int X2, int Y2);
300 
301 #if FABGLIB_HAS_INVERTRECT
302 
313  void invertRectangle(int X1, int Y1, int X2, int Y2);
314 
315 #endif
316 
325  void swapRectangle(int X1, int Y1, int X2, int Y2);
326 
341  void drawEllipse(int X, int Y, int width, int height);
342 
363  void fillEllipse(int X, int Y, int width, int height);
364 
370  void waitCompletion(bool waitVSync = true);
371 
402  void drawGlyph(int X, int Y, int width, int height, uint8_t const * data, int index = 0);
403 
420  void setGlyphOptions(GlyphOptions options);
421 
422  void renderGlyphsBuffer(int itemX, int itemY, GlyphsBuffer const * glyphsBuffer);
423 
427  void setPaintOptions(PaintOptions options);
428 
437  static FontInfo const * getPresetFontInfo(int columns, int rows);
438 
444  FontInfo const * getFontInfo() { return m_fontInfo; }
445 
459  void selectFont(FontInfo const * fontInfo);
460 
475  void drawChar(int X, int Y, char c);
476 
492  void drawText(int X, int Y, char const * text, bool wrap = false);
493 
510  void drawText(FontInfo const * fontInfo, int X, int Y, char const * text, bool wrap = false);
511 
525  void drawTextFmt(int X, int Y, const char *format, ...);
526 
539  void copyRect(int sourceX, int sourceY, int destX, int destY, int width, int height);
540 
541 #if FABGLIB_HAS_READWRITE_RAW_DATA
542 
543  void readRawData(int sourceX, int sourceY, int width, int height, uint8_t * dest);
544 
545  void writeRawData(uint8_t * source, int destX, int destY, int width, int height);
546 
547 #endif
548 
560  void drawBitmap(int X, int Y, Bitmap const * bitmap);
561 
568  void swapBuffers();
569 
587  void drawPath(Point const * points, int pointsCount);
588 
606  void fillPath(Point const * points, int pointsCount);
607 
608 private:
609 
610  FontInfo const * m_fontInfo;
611  uint8_t m_textHorizRate; // specify character size: 1 = m_fontInfo.width, 2 = m_fontInfo.width * 2, etc...
612 };
613 
614 
615 } // end of namespace
616 
617 
618 
619 extern fabgl::CanvasClass Canvas;
620 
621 
622 
623 #endif
A class with a set of drawing methods.
Definition: canvas.h:88
FontInfo const * getFontInfo()
Get info about currently selected font.
Definition: canvas.h:444
int getViewPortWidth()
Return horizontal size of the viewport.
Definition: vgacontroller.h:669
int getViewPortHeight()
Return vertical size of the viewport.
Definition: vgacontroller.h:676
void fillRectangle(int X1, int Y1, int X2, int Y2)
Fill a rectangle using the current brush color.
Definition: canvas.cpp:169
void setGlyphOptions(GlyphOptions options)
Set drawing options for the next glyphs.
Definition: canvas.cpp:236
void drawTextFmt(int X, int Y, const char *format,...)
Draw formatted text at specified position.
Definition: canvas.cpp:285
This file contains fabgl::VGAControllerClass definition and the VGAController instance.
void swapBuffers()
Swap screen buffer when double buffering is enabled.
Definition: canvas.cpp:360
int getWidth()
Return the canvas width in pixels.
Definition: canvas.h:101
void moveTo(int X, int Y)
Move current pen position to the spcified coordinates.
Definition: canvas.cpp:98
void drawLine(int X1, int Y1, int X2, int Y2)
Draw a line specifying initial and ending coordinates.
Definition: canvas.cpp:152
void setPenColor(uint8_t red, uint8_t green, uint8_t blue)
Set pen (foreground) color specifying color components.
Definition: canvas.cpp:116
void drawPath(Point const *points, int pointsCount)
Draw a sequence of lines.
Definition: canvas.cpp:370
void fillPath(Point const *points, int pointsCount)
Fill the polygon enclosed in a sequence of lines.
Definition: canvas.cpp:380
void copyRect(int sourceX, int sourceY, int destX, int destY, int width, int height)
Copy a screen rectangle to the specified position.
Definition: canvas.cpp:299
void setPixel(int X, int Y)
Fill a single pixel with the pen color.
Definition: canvas.cpp:89
void setScrollingRegion(int X1, int Y1, int X2, int Y2)
Define the scrolling region.
Definition: canvas.cpp:80
void waitCompletion(bool waitVSync=true)
Wait for drawing queue to become empty.
Definition: canvas.cpp:46
Represents the coordinate of a point.
Definition: fabutils.h:40
Represents an image with 64 colors image and transparency.
Definition: vgacontroller.h:385
void drawBitmap(int X, int Y, Bitmap const *bitmap)
Draw a bitmap at specified position.
Definition: canvas.cpp:351
Definition: canvas.cpp:37
Color
This enum defines named colors.
Definition: vgacontroller.h:206
Specifies various glyph painting options.
Definition: vgacontroller.h:293
void drawGlyph(int X, int Y, int width, int height, uint8_t const *data, int index=0)
Draw a glyph at specified position.
Definition: canvas.cpp:218
void lineTo(int X, int Y)
Draw a line starting from current pen position.
Definition: canvas.cpp:143
void swapRectangle(int X1, int Y1, int X2, int Y2)
Swap pen and brush colors of the specified rectangle.
Definition: canvas.cpp:189
int getHeight()
Return the canvas height in pixels.
Definition: canvas.h:110
void drawRectangle(int X1, int Y1, int X2, int Y2)
Draw a rectangle using the current pen color.
Definition: canvas.cpp:159
void selectFont(FontInfo const *fontInfo)
Select a font to use for the next text drawings.
Definition: canvas.cpp:255
void setBrushColor(uint8_t red, uint8_t green, uint8_t blue)
Set brush (background) color specifying color components.
Definition: canvas.cpp:134
void drawEllipse(int X, int Y, int width, int height)
Draw an ellipse specifying center and size, using current pen color.
Definition: canvas.cpp:208
void fillEllipse(int X, int Y, int width, int height)
Fill an ellipse specifying center and size, using current brush color.
Definition: canvas.cpp:198
void drawText(int X, int Y, char const *text, bool wrap=false)
Draw a string at specified position.
Definition: canvas.cpp:267
void scroll(int offsetX, int offsetY)
Scroll pixels horizontally and/or vertically.
Definition: canvas.cpp:64
Specifies general paint options.
Definition: vgacontroller.h:332
void setPaintOptions(PaintOptions options)
Set paint options.
Definition: canvas.cpp:246
void drawChar(int X, int Y, char c)
Draw a character at specified position.
Definition: canvas.cpp:261
void clear()
Fill the entire canvas with the brush color.
Definition: canvas.cpp:55
static FontInfo const * getPresetFontInfo(int columns, int rows)
Get the font info that best fits the specified number of columns and rows.
Definition: canvas.cpp:331