33#pragma GCC optimize ("O2")
39#define INVALIDRECT Rect(-32768, -32768, -32768, -32768)
42Canvas::Canvas(BitmappedDisplayController * displayController)
43 : m_displayController(displayController),
46 m_origin(Point(0, 0)),
47 m_clippingRect(INVALIDRECT)
52void Canvas::setOrigin(
int X,
int Y)
58void Canvas::setOrigin(
Point const & origin)
61 p.cmd = PrimitiveCmd::SetOrigin;
62 p.position = m_origin = origin;
63 m_displayController->addPrimitive(p);
67void Canvas::setClippingRect(
Rect const & rect)
70 p.cmd = PrimitiveCmd::SetClippingRect;
71 p.rect = m_clippingRect = rect;
72 m_displayController->addPrimitive(p);
76Rect Canvas::getClippingRect()
78 if (m_clippingRect == INVALIDRECT)
79 m_clippingRect =
Rect(0, 0, getWidth() - 1, getHeight() - 1);
80 return m_clippingRect;
84void Canvas::waitCompletion(
bool waitVSync)
87 m_displayController->primitivesExecutionWait();
89 m_displayController->processPrimitives();
97void Canvas::beginUpdate()
99 m_displayController->suspendBackgroundPrimitiveExecution();
103void Canvas::endUpdate()
105 m_displayController->resumeBackgroundPrimitiveExecution();
112 p.cmd = PrimitiveCmd::Clear;
114 m_displayController->addPrimitive(p);
121 p.cmd = PrimitiveCmd::Reset;
122 m_displayController->addPrimitive(p);
123 m_origin =
Point(0, 0);
124 m_clippingRect = INVALIDRECT;
129void Canvas::scroll(
int offsetX,
int offsetY)
133 p.cmd = PrimitiveCmd::VScroll;
135 m_displayController->addPrimitive(p);
138 p.cmd = PrimitiveCmd::HScroll;
140 m_displayController->addPrimitive(p);
145void Canvas::setScrollingRegion(
int X1,
int Y1,
int X2,
int Y2)
148 p.cmd = PrimitiveCmd::SetScrollingRegion;
150 m_displayController->addPrimitive(p);
154void Canvas::setPixel(
int X,
int Y)
157 p.cmd = PrimitiveCmd::SetPixel;
159 m_displayController->addPrimitive(p);
163void Canvas::setPixel(
int X,
int Y,
RGB888 const & color)
172 p.cmd = PrimitiveCmd::SetPixelAt;
173 p.pixelDesc = { pos, color };
174 m_displayController->addPrimitive(p);
178void Canvas::moveTo(
int X,
int Y)
181 p.cmd = PrimitiveCmd::MoveTo;
183 m_displayController->addPrimitive(p);
187void Canvas::setPenColor(
Color color)
189 setPenColor(
RGB888(color));
193void Canvas::setPenColor(uint8_t red, uint8_t green, uint8_t blue)
195 setPenColor(
RGB888(red, green, blue));
199void Canvas::setPenColor(
RGB888 const & color)
202 p.cmd = PrimitiveCmd::SetPenColor;
204 m_displayController->addPrimitive(p);
208void Canvas::setBrushColor(
Color color)
210 setBrushColor(
RGB888(color));
214void Canvas::setBrushColor(uint8_t red, uint8_t green, uint8_t blue)
216 setBrushColor(
RGB888(red, green, blue));
220void Canvas::setPenWidth(
int value)
223 p.cmd = PrimitiveCmd::SetPenWidth;
225 m_displayController->addPrimitive(p);
232 p.cmd = PrimitiveCmd::SetLineEnds;
234 m_displayController->addPrimitive(p);
238void Canvas::setBrushColor(
RGB888 const & color)
241 p.cmd = PrimitiveCmd::SetBrushColor;
243 m_displayController->addPrimitive(p);
247void Canvas::lineTo(
int X,
int Y)
250 p.cmd = PrimitiveCmd::LineTo;
252 m_displayController->addPrimitive(p);
256void Canvas::drawLine(
int X1,
int Y1,
int X2,
int Y2)
263void Canvas::drawRectangle(
int X1,
int Y1,
int X2,
int Y2)
266 p.cmd = PrimitiveCmd::DrawRect;
268 m_displayController->addPrimitive(p);
272void Canvas::drawRectangle(
Rect const & rect)
274 drawRectangle(rect.X1, rect.Y1, rect.X2, rect.Y2);
278void Canvas::fillRectangle(
int X1,
int Y1,
int X2,
int Y2)
281 p.cmd = PrimitiveCmd::FillRect;
283 m_displayController->addPrimitive(p);
287void Canvas::fillRectangle(
Rect const & rect)
290 p.cmd = PrimitiveCmd::FillRect;
292 m_displayController->addPrimitive(p);
296void Canvas::invertRectangle(
int X1,
int Y1,
int X2,
int Y2)
302void Canvas::invertRectangle(
Rect const & rect)
305 p.cmd = PrimitiveCmd::InvertRect;
307 m_displayController->addPrimitive(p);
311void Canvas::swapRectangle(
int X1,
int Y1,
int X2,
int Y2)
314 p.cmd = PrimitiveCmd::SwapFGBG;
316 m_displayController->addPrimitive(p);
324 p.cmd = PrimitiveCmd::FillEllipse;
326 m_displayController->addPrimitive(p);
334 p.cmd = PrimitiveCmd::DrawEllipse;
336 m_displayController->addPrimitive(p);
343 p.cmd = PrimitiveCmd::DrawGlyph;
345 m_displayController->addPrimitive(p);
349void Canvas::renderGlyphsBuffer(
int itemX,
int itemY, GlyphsBuffer
const * glyphsBuffer)
352 p.cmd = PrimitiveCmd::RenderGlyphsBuffer;
353 p.glyphsBufferRenderInfo = GlyphsBufferRenderInfo(itemX, itemY, glyphsBuffer);
354 m_displayController->addPrimitive(p);
361 p.cmd = PrimitiveCmd::SetGlyphOptions;
362 p.glyphOptions = options;
363 m_displayController->addPrimitive(p);
368void Canvas::resetGlyphOptions()
377 p.cmd = PrimitiveCmd::SetPaintOptions;
378 p.paintOptions = options;
379 m_displayController->addPrimitive(p);
383void Canvas::resetPaintOptions()
389void Canvas::selectFont(FontInfo
const * fontInfo)
391 m_fontInfo = fontInfo;
395void Canvas::drawChar(
int X,
int Y,
char c)
397 drawGlyph(
X,
Y, m_fontInfo->width, m_fontInfo->height, m_fontInfo->data, c);
401void Canvas::drawText(
int X,
int Y,
char const * text,
bool wrap)
403 if (m_fontInfo ==
nullptr)
404 selectFont(&FONT_8x8);
405 drawText(m_fontInfo,
X,
Y, text, wrap);
409void Canvas::drawText(FontInfo
const * fontInfo,
int X,
int Y,
char const * text,
bool wrap)
411 int fontWidth = fontInfo->width;
412 for (; *text; ++text,
X += fontWidth * m_textHorizRate) {
413 if (wrap &&
X >= getWidth()) {
415 Y += fontInfo->height;
417 if (fontInfo->chptr) {
419 uint8_t
const * chptr = fontInfo->data + fontInfo->chptr[(int)(*text)];
420 fontWidth = *chptr++;
421 drawGlyph(
X,
Y, fontWidth, fontInfo->height, chptr, 0);
424 drawGlyph(
X,
Y, fontInfo->width, fontInfo->height, fontInfo->data, *text);
430void Canvas::drawTextWithEllipsis(FontInfo
const * fontInfo,
int X,
int Y,
char const * text,
int maxX)
432 int fontWidth = fontInfo->width;
433 int fontHeight = fontInfo->height;
434 for (; *text; ++text,
X += fontWidth) {
435 if (
X >= maxX - fontHeight) {
437 drawText(fontInfo,
X,
Y,
"...");
440 if (fontInfo->chptr) {
442 uint8_t
const * chptr = fontInfo->data + fontInfo->chptr[(int)(*text)];
443 fontWidth = *chptr++;
444 drawGlyph(
X,
Y, fontWidth, fontInfo->height, chptr, 0);
447 drawGlyph(
X,
Y, fontInfo->width, fontInfo->height, fontInfo->data, *text);
453int Canvas::textExtent(FontInfo
const * fontInfo,
char const * text)
455 int fontWidth = fontInfo->width;
457 for (; *text; ++text, extent += fontWidth) {
458 if (fontInfo->chptr) {
460 uint8_t
const * chptr = fontInfo->data + fontInfo->chptr[(int)(*text)];
468int Canvas::textExtent(
char const * text)
470 return textExtent(m_fontInfo, text);
474void Canvas::drawTextFmt(
int X,
int Y,
const char *format, ...)
477 va_start(ap, format);
478 int size = vsnprintf(
nullptr, 0, format, ap) + 1;
481 va_start(ap, format);
483 vsnprintf(buf, size, format, ap);
484 drawText(
X,
Y, buf,
false);
490void Canvas::copyRect(
int sourceX,
int sourceY,
int destX,
int destY,
int width,
int height)
492 moveTo(destX, destY);
493 int sourceX2 = sourceX +
width - 1;
494 int sourceY2 = sourceY +
height - 1;
496 p.cmd = PrimitiveCmd::CopyRect;
497 p.rect =
Rect(sourceX, sourceY, sourceX2, sourceY2);
498 m_displayController->addPrimitive(p);
502void Canvas::drawBitmap(
int X,
int Y,
Bitmap const * bitmap)
505 p.cmd = PrimitiveCmd::DrawBitmap;
506 p.bitmapDrawingInfo = BitmapDrawingInfo(
X,
Y, bitmap);
507 m_displayController->addPrimitive(p);
511void Canvas::swapBuffers()
514 p.cmd = PrimitiveCmd::SwapBuffers;
515 p.notifyTask = xTaskGetCurrentTaskHandle();
516 m_displayController->addPrimitive(p);
517 m_displayController->primitivesExecutionWait();
521void Canvas::drawPath(
Point const * points,
int pointsCount)
524 p.cmd = PrimitiveCmd::DrawPath;
525 p.path.points = points;
526 p.path.pointsCount = pointsCount;
527 p.path.freePoints =
false;
528 m_displayController->addPrimitive(p);
532void Canvas::fillPath(
Point const * points,
int pointsCount)
535 p.cmd = PrimitiveCmd::FillPath;
536 p.path.points = points;
537 p.path.pointsCount = pointsCount;
538 p.path.freePoints =
false;
539 m_displayController->addPrimitive(p);
546 m_displayController->readScreen(
Rect(
X,
Y,
X,
Y), &rgb);
This file contains fabgl::Canvas definition.
LineEnds
This enum defines line ends when pen width is greater than 1.
Color
This enum defines named colors.
Represents a glyph position, size and binary data.
Specifies general paint options.
Represents the coordinate of a point.
Represents a 24 bit RGB color.
Represents a bidimensional size.
Specifies various glyph painting options.