Iridescence 1.00
Embedded Graphic Framework
Loading...
Searching...
No Matches
ds_renderer.h
1/* Copyright (C) 2017 - 2024, Thornwave Labs Inc - All Rights Reserved.
2 * Unauthorized copying of this file, via any medium is strictly prohibited.
3 * Proprietary and confidential.
4 * Written by Razvan Turiac <razvan.turiac@thornwave.com>
5*/
6
7#ifndef _DS_RENDERER_H
8#define _DS_RENDERER_H
9
10
11#include <ds_types.h>
12#include <ds_font.h>
13
14#include <ds_string.h>
15#include <ds_surface.h>
16
17
18
28DsSize DsTextSize(const ds_bitmap_font_t* font, float row_spacing, const char* text, size_t length = -1);
29
30
31
42{
43public:
48 void setSurface(DsSurface &surface);
49
55
56
62 void pushClipRegion(DsRegion &region);
63
64
68 void popClipRegion(void);
69
70
75 void unrollClipRegions(uint8_t level);
76
77
81 void clearClipRegions(void);
82
83
84
93
94
100 void setSupersampling(int32_t ss);
101
102
109 void drawLine(DsPoint p0, DsPoint p1, DsColor color);
110
111
121 void drawRectangle(DsRect rect, uint16_t thickness, DsColor color);
122
123
131 inline void drawRoundedRectangle(DsRect rect, DsColor color, uint16_t corner_radius)
132 {
133 drawRoundedRectangle(rect, color, corner_radius, corner_radius, corner_radius, corner_radius);
134 }
135
146 void drawRoundedRectangle(DsRect rect, DsColor color, uint16_t corner_radius_tl, uint16_t corner_radius_tr, uint16_t corner_radius_br, uint16_t corner_radius_bl);
147
148
155 void fillRectangle(DsRect rect, DsColor color);
156
157
165 inline void fillRoundedRectangle(DsRect rect, DsColor color, uint16_t corner_radius)
166 {
167 fillRoundedRectangle(rect, color, corner_radius, corner_radius, corner_radius, corner_radius);
168 }
169
180 void fillRoundedRectangle(DsRect rect, DsColor color, uint16_t corner_radius_tl, uint16_t corner_radius_tr, uint16_t corner_radius_br, uint16_t corner_radius_bl);
181
182
189 void drawPoly(const DsPoint* points, uint32_t np, DsColor color);
190
191
198 void fillPoly(const DsPoint* points, uint32_t np, DsColor color);
199
200
208 inline void drawCircle(DsFPoint center, float radius, float thickness, DsColor color)
209 {
210 drawEllipse(DsEllipse(center, radius), thickness, color);
211 }
212
219 inline void fillCircle(DsFPoint center, float radius, DsColor color)
220 {
221 fillEllipse(DsEllipse(center, radius), color);
222 }
223
233 void drawEllipse(DsEllipse ellipse, float thickness, DsColor color);
234
235
244 void fillEllipse(DsEllipse ellipse, DsColor color);
245
246
258 void drawEllipseArc(DsEllipse ellipse, float thickness, float start_angle, float end_angle, DsColor color);
259
260
271 void fillEllipseArc(DsEllipse ellipse, float start_angle, float end_angle, DsColor color);
272
273
284 inline void drawCircleArc(DsFPoint center, float radius, float thickness, float start_angle, float end_angle, DsColor color)
285 {
286 drawEllipseArc(DsEllipse(center, radius), thickness, start_angle, end_angle, color);
287 }
288
289
299 inline void fillCircleArc(DsFPoint center, float radius, float start_angle, float end_angle, DsColor color)
300 {
301 fillEllipseArc(DsEllipse(center, radius), start_angle, end_angle, color);
302 }
303
304
312 void drawLineAA(const DsFPoint &p0, const DsFPoint &p1, float thickness, DsColor color);
313
314
322 void drawPolyAA(const DsFPoint* points, uint32_t np, float thickness, DsColor color);
323
324
331 void fillPolyAA(const DsFPoint* points, uint32_t np, DsColor color);
332
333
340 inline void fillRectangleAA(DsFRect rect, DsColor color)
341 {
342 fillRoundedRectangleAA(rect, color, 0, 0, 0, 0);
343 }
344
345
354 inline void drawRoundedRectangleAA(DsFRect rect, DsColor color, float thickness, float corner_radius)
355 {
356 drawRoundedRectangleAA(rect, color, thickness, corner_radius, corner_radius, corner_radius, corner_radius);
357 }
358
370 void drawRoundedRectangleAA(DsFRect rect, DsColor color, float thickness, float corner_radius_tl, float corner_radius_tr, float corner_radius_br, float corner_radius_bl);
371
372
380 inline void fillRoundedRectangleAA(DsFRect rect, DsColor color, float corner_radius)
381 {
382 if (corner_radius > 0)
383 fillRoundedRectangleAA(rect, color, corner_radius, corner_radius, corner_radius, corner_radius);
384 else
385 fillRectangle(rect, color);
386 }
387
398 void fillRoundedRectangleAA(DsFRect rect, DsColor color, float corner_radius_tl, float corner_radius_tr, float corner_radius_br, float corner_radius_bl);
399
400
410 void drawEllipseAA(DsEllipse ellipse, float thickness, DsColor color);
411
412
421 void fillEllipseAA(DsEllipse ellipse, DsColor color);
422
423
431 inline void drawCircleAA(DsFPoint center, float radius, float thickness, DsColor color)
432 {
433 drawEllipseAA(DsEllipse(center, radius), thickness, color);
434 }
435
442 inline void fillCircleAA(DsFPoint center, float radius, DsColor color)
443 {
444 fillEllipseAA(DsEllipse(center, radius), color);
445 }
446
447
459 void drawEllipseArcAA(DsEllipse ellipse, float thickness, float start, float end, DsColor color);
460
461
472 void fillEllipseArcAA(DsEllipse ellipse, float start, float end, DsColor color);
473
474
485 inline void drawCircleArcAA(DsFPoint center, float radius, float thickness, float start, float end, DsColor color)
486 {
487 drawEllipseArcAA(DsEllipse(center, radius), thickness, start, end, color);
488 }
489
490
500 inline void fillCircleArcAA(DsFPoint center, float radius, float start, float end, DsColor color)
501 {
502 fillEllipseArcAA(DsEllipse(center, radius), start, end, color);
503 }
504
505
506
517 DsRect renderText(DsPoint pos, const ds_bitmap_font_t* font, DsColor color, const char* text, size_t length = DsString::npos);
518
531 DsRect renderMultilineText(DsPoint pos, const ds_bitmap_font_t* font, DsColor color, const DsAlignment &line_alignment, float row_spacing, const char* text, size_t length = DsString::npos);
532
533
546 DsRect renderTextAligned(const DsRect &boundary, const DsAlignment &alignment, const DsPoint &offset, const ds_bitmap_font_t* font, DsColor color, const char* text, size_t length = DsString::npos);
547
548
563 DsRect renderMultilineTextAligned(const DsRect &boundary, const DsAlignment &text_alignment, const DsPoint &offset, const ds_bitmap_font_t* font, DsColor color, const DsAlignment &line_alignment, float row_spacing, const char* text, size_t length = DsString::npos);
564
565
576 DsRect renderTextCentered(DsPoint pos, const ds_bitmap_font_t* font, DsColor color, const char* text, size_t length = DsString::npos);
577
578
591 DsRect renderMultilineTextCentered(DsPoint pos, const ds_bitmap_font_t* font, DsColor color, const DsAlignment &line_alignment, float row_spacing, const char* text, size_t length = DsString::npos);
592
593
594 void moveClipRegions(const DsFPoint &offset);
595 static bool clipLine(const DsRect &bounds, int32_t &x0, int32_t &y0, int32_t &x1, int32_t &y1);
596
597private:
598 friend class DsScreen;
599
600 typedef struct
601 {
602 uint8_t* pixels;
603 uint32_t width;
604 int32_t min;
605 int32_t max;
606 }ds_scanline_t;
607
608 uint32_t mSsCoeffLog2;
609 uint32_t mSsCoeff;
610 uint32_t mSsInc8;
611 uint32_t mSsInc32;
612 float mSsYInc;
613 ds_scanline_t mScanlineBuffers[2];
614
615 DsSurface* mSurface;
616 uint8_t* mScanlineAlpha;
617
618 DsRegion* mClipRegions[8];
619 uint8_t mClipRegionCount;
620
621 DsRenderer(const void* memory, const void* memory_aa, uint32_t width, uint32_t height);
622
623 void scanline_blend(int32_t y, int32_t xl, int32_t xr);
624 void render_line_h(int32_t y, int32_t x0, int32_t x1, DsColor color);
625 void render_line_v(int32_t x, int32_t y0, int32_t y1, DsColor color);
626
627 void scanline_clear_aa(ds_scanline_t* line);
628 void scanline_blend_init_aa(DsColor color);
629 void scanline_blend_aa(ds_scanline_t* line, int32_t y, int32_t xoff);
630 void scanline_draw_aa(float y, float xl, float xr, ds_scanline_t* line, int32_t xoff);
631};
632
633
634#endif
DsAlignment is a class representing both horizontal and vertical alignment type.
Definition ds_types.h:130
DsColor is a class that represents a 4 channel color (Alpha, Red, Green, Blue).
Definition ds_color.h:53
DsEllipse is a class that represents a 2D ellipse (Xc, Yc, Rx, Ry)
Definition ds_geometry.h:2636
DsFPoint is a class that represents the X and Y 2D coordinates of a point as floating point numbers.
Definition ds_geometry.h:397
DsFRect is a class that represents a 2D rectangle (X, Y, W, H) using floating point coordiantes and s...
Definition ds_geometry.h:2059
DsPoint is a class that represents the X and Y 2D coordinates of a point as integer numbers.
Definition ds_geometry.h:24
DsRect is a class that represents a 2D rectangle (X, Y, W, H)
Definition ds_geometry.h:1507
Definition ds_geometry.h:1492
DsRenderer is a class that implements all the drawing operations.
Definition ds_renderer.h:42
void unrollClipRegions(uint8_t level)
Unrolls the clipping region stack back to a specific number of clip regions.
void drawEllipse(DsEllipse ellipse, float thickness, DsColor color)
Draws a non-antialiased ellipse of specified thickness.
void drawRoundedRectangle(DsRect rect, DsColor color, uint16_t corner_radius_tl, uint16_t corner_radius_tr, uint16_t corner_radius_br, uint16_t corner_radius_bl)
Draws a non-antialiased rectangle with rounded corners using lines of thickness 1.
void drawEllipseArc(DsEllipse ellipse, float thickness, float start_angle, float end_angle, DsColor color)
Draws a non-antialiased ellipse arc of specified thickness.
void clearClipRegions(void)
Clears all the clipping regions.
void drawEllipseArcAA(DsEllipse ellipse, float thickness, float start, float end, DsColor color)
Draws an antialiased ellipse arc of specified thickness.
void fillRoundedRectangle(DsRect rect, DsColor color, uint16_t corner_radius)
Fills a rectangle with rounded corners using the specified color.
Definition ds_renderer.h:165
void drawCircle(DsFPoint center, float radius, float thickness, DsColor color)
Draws a non-antialiased circle of specified thickness.
Definition ds_renderer.h:208
void fillEllipseArcAA(DsEllipse ellipse, float start, float end, DsColor color)
Fills an antialiased ellipse arc.
void fillRoundedRectangle(DsRect rect, DsColor color, uint16_t corner_radius_tl, uint16_t corner_radius_tr, uint16_t corner_radius_br, uint16_t corner_radius_bl)
Fills a rectangle with rounded corners using the specified color.
void drawRoundedRectangleAA(DsFRect rect, DsColor color, float thickness, float corner_radius_tl, float corner_radius_tr, float corner_radius_br, float corner_radius_bl)
Draws an antialiased rectangle with rounded corners and lines of specified thickness.
void fillCircle(DsFPoint center, float radius, DsColor color)
Fills a non-antialiased circle.
Definition ds_renderer.h:219
void drawRoundedRectangleAA(DsFRect rect, DsColor color, float thickness, float corner_radius)
Draws an antialiased rectangle with rounded corners and lines of specified thickness.
Definition ds_renderer.h:354
DsSurface & getSurface(void)
Gets the underlying surface used for drawing.
void drawRoundedRectangle(DsRect rect, DsColor color, uint16_t corner_radius)
Draws a non-antialiased rectangle with rounded corners using lines of thickness 1.
Definition ds_renderer.h:131
void drawEllipseAA(DsEllipse ellipse, float thickness, DsColor color)
Draws an antialiased ellipse of specified thickness.
void drawPolyAA(const DsFPoint *points, uint32_t np, float thickness, DsColor color)
Draws an antialiased closed polygon using lines of specified thickness.
void popClipRegion(void)
Pops a clipping region from the clipping region stack.
DsRect renderTextAligned(const DsRect &boundary, const DsAlignment &alignment, const DsPoint &offset, const ds_bitmap_font_t *font, DsColor color, const char *text, size_t length=DsString::npos)
Renders text in aligned mode.
void fillEllipse(DsEllipse ellipse, DsColor color)
Fills a non-antialiased ellipse.
void drawCircleArc(DsFPoint center, float radius, float thickness, float start_angle, float end_angle, DsColor color)
Draws a non-antialiased circle arc of specified thickness.
Definition ds_renderer.h:284
void drawCircleArcAA(DsFPoint center, float radius, float thickness, float start, float end, DsColor color)
Draws an antialiased circle arc of specified thickness.
Definition ds_renderer.h:485
void fillCircleArc(DsFPoint center, float radius, float start_angle, float end_angle, DsColor color)
Fills a non-antialiased circle arc.
Definition ds_renderer.h:299
void drawRectangle(DsRect rect, uint16_t thickness, DsColor color)
Draws a rectangle with lines of specified thickness.
void drawLine(DsPoint p0, DsPoint p1, DsColor color)
Draws a non-antialiased line of thickness 1 in between two points.
void fillEllipseAA(DsEllipse ellipse, DsColor color)
Fills an antialiased ellipse.
DsRect renderTextCentered(DsPoint pos, const ds_bitmap_font_t *font, DsColor color, const char *text, size_t length=DsString::npos)
Renders text centered on a point.
void fillRoundedRectangleAA(DsFRect rect, DsColor color, float corner_radius)
Fills an antialiased rectangle with rounded corners using the specified color.
Definition ds_renderer.h:380
void fillEllipseArc(DsEllipse ellipse, float start_angle, float end_angle, DsColor color)
Fills a non-antialiased ellipse arc.
void drawLineAA(const DsFPoint &p0, const DsFPoint &p1, float thickness, DsColor color)
Draws an antialiased line of specified thickness between two points.
DsRect renderMultilineTextAligned(const DsRect &boundary, const DsAlignment &text_alignment, const DsPoint &offset, const ds_bitmap_font_t *font, DsColor color, const DsAlignment &line_alignment, float row_spacing, const char *text, size_t length=DsString::npos)
Renders multiline text in aligned mode. It does this by interpreting the CR and LF characters.
void fillPoly(const DsPoint *points, uint32_t np, DsColor color)
Fills a non-antialiased closed polygon.
DsRenderer newRenderer(DsSurface &surface)
Creates a new child renderer for the specified surface.
void setSupersampling(int32_t ss)
Sets the supersampling factor.
void drawCircleAA(DsFPoint center, float radius, float thickness, DsColor color)
Draws an antialiased circle of specified thickness.
Definition ds_renderer.h:431
void fillCircleAA(DsFPoint center, float radius, DsColor color)
Fills an antialiased circle.
Definition ds_renderer.h:442
DsRect renderMultilineTextCentered(DsPoint pos, const ds_bitmap_font_t *font, DsColor color, const DsAlignment &line_alignment, float row_spacing, const char *text, size_t length=DsString::npos)
Renders multiline text centered on a point. It does this by interpreting the CR and LF characters.
void fillRectangle(DsRect rect, DsColor color)
Fills a rectangle using the specified color.
void fillPolyAA(const DsFPoint *points, uint32_t np, DsColor color)
Fills an antialiased closed polygon.
void fillRoundedRectangleAA(DsFRect rect, DsColor color, float corner_radius_tl, float corner_radius_tr, float corner_radius_br, float corner_radius_bl)
Fills an antialiased rectangle with rounded corners using the specified color.
void setSurface(DsSurface &surface)
Sets the underlying surface used for drawing.
void drawPoly(const DsPoint *points, uint32_t np, DsColor color)
Draws a non-antialiased closed polygon using lines of thickness 1.
DsRect renderText(DsPoint pos, const ds_bitmap_font_t *font, DsColor color, const char *text, size_t length=DsString::npos)
Renders text.
void fillRectangleAA(DsFRect rect, DsColor color)
Fills an antialiased rectangle using the specified color.
Definition ds_renderer.h:340
DsRect renderMultilineText(DsPoint pos, const ds_bitmap_font_t *font, DsColor color, const DsAlignment &line_alignment, float row_spacing, const char *text, size_t length=DsString::npos)
Renders multiline text. It does this by interpreting the CR and LF characters.
void pushClipRegion(DsRegion &region)
Pushes a clipping region to the clipping region stack.
void fillCircleArcAA(DsFPoint center, float radius, float start, float end, DsColor color)
Fills an antialiased circle arc.
Definition ds_renderer.h:500
DsScreen is class of type DsView (inherits from DsView) that implements a physical screen.
Definition ds_screen.h:29
DsSize is class that represents the 2D size of a graphic object (width, height) as integer values.
Definition ds_geometry.h:780
static const size_t npos
Constant representing an invalid position/size value.
Definition ds_string.h:28
DsSurface is a class that represents a drawing surface.
Definition ds_surface.h:30
Definition ds_font.h:45