PatchworkOS
Loading...
Searching...
No Matches
Drawable

Drawable. More...

Data Structures

struct  drawable_t
 Drawable structure. More...
 

Enumerations

enum  align_t {
  ALIGN_CENTER = 0 ,
  ALIGN_MAX = 1 ,
  ALIGN_MIN = 2
}
 Alignment type. More...
 
enum  direction_t {
  DIRECTION_VERTICAL ,
  DIRECTION_HORIZONTAL ,
  DIRECTION_DIAGONAL
}
 Direction type. More...
 

Functions

void draw_rect (drawable_t *draw, const rect_t *rect, pixel_t pixel)
 Draw a filled rectangle.
 
void draw_polygon (drawable_t *draw, const point_t *points, uint64_t pointCount, pixel_t pixel)
 Draw a filled polygon.
 
void draw_line (drawable_t *draw, const point_t *start, const point_t *end, pixel_t pixel, uint32_t thickness)
 Draw a line between two points.
 
void draw_frame (drawable_t *draw, const rect_t *rect, uint64_t width, pixel_t foreground, pixel_t background)
 Draw a skeuomorphic frame.
 
void draw_dashed_outline (drawable_t *draw, const rect_t *rect, pixel_t pixel, uint32_t length, int32_t width)
 Draw a dashed outline just inside the given rectangle.
 
void draw_bezel (drawable_t *draw, const rect_t *rect, uint64_t width, pixel_t pixel)
 Draw a filled border bezel just inside the given rectangle.
 
void draw_gradient (drawable_t *draw, const rect_t *rect, pixel_t start, pixel_t end, direction_t direction, bool shouldAddNoise)
 Draw a gradient filled rectangle.
 
void draw_transfer (drawable_t *dest, drawable_t *src, const rect_t *destRect, const point_t *srcPoint)
 Transfer pixels from one drawable to another.
 
void draw_transfer_blend (drawable_t *dest, drawable_t *src, const rect_t *destRect, const point_t *srcPoint)
 Transfer pixels from one drawable to another with alpha blending.
 
void draw_image (drawable_t *draw, image_t *image, const rect_t *destRect, const point_t *srcPoint)
 Draw an image,.
 
void draw_image_blend (drawable_t *draw, image_t *image, const rect_t *destRect, const point_t *srcPoint)
 Draw an image with alpha blending.
 
void draw_string (drawable_t *draw, const font_t *font, const point_t *point, pixel_t pixel, const char *string, uint64_t length)
 Draw a string.
 
void draw_text (drawable_t *draw, const rect_t *rect, const font_t *font, align_t xAlign, align_t yAlign, pixel_t pixel, const char *text)
 Draw text to a drawable.
 
void draw_text_multiline (drawable_t *draw, const rect_t *rect, const font_t *font, align_t xAlign, align_t yAlign, pixel_t pixel, const char *text)
 Draw multiline text to a drawable.
 
void draw_ridge (drawable_t *draw, const rect_t *rect, uint64_t width, pixel_t foreground, pixel_t background)
 Draw a ridge effect.
 
void draw_separator (drawable_t *draw, const rect_t *rect, pixel_t highlight, pixel_t shadow, direction_t direction)
 Draw a separator line.
 
void draw_invalidate (drawable_t *draw, const rect_t *rect)
 Invalidate a rectangle in the drawable.
 

Detailed Description

Drawable.

A drawable implements a generic system for drawing operations to a pixel buffer.

Enumeration Type Documentation

◆ align_t

enum align_t

Alignment type.

Enumerator
ALIGN_CENTER 
ALIGN_MAX 
ALIGN_MIN 

Definition at line 47 of file drawable.h.

◆ direction_t

Direction type.

Enumerator
DIRECTION_VERTICAL 
DIRECTION_HORIZONTAL 
DIRECTION_DIAGONAL 

Definition at line 58 of file drawable.h.

Function Documentation

◆ draw_bezel()

void draw_bezel ( drawable_t draw,
const rect_t rect,
uint64_t  width,
pixel_t  pixel 
)

Draw a filled border bezel just inside the given rectangle.

Will fit the rectangle to the drawable's content rectangle.

Parameters
drawThe drawable to draw to.
rectThe rectangle to draw the bezel around.
widthThe width of the bezel.
pixelThe pixel color to draw with.

Definition at line 339 of file drawable.c.

References rect_t::bottom, drawable_t::contentRect, draw_rect(), rect_t::left, NULL, RECT_FIT, rect_t::right, and rect_t::top.

Referenced by button_draw(), and field_edge_draw().

◆ draw_dashed_outline()

void draw_dashed_outline ( drawable_t draw,
const rect_t rect,
pixel_t  pixel,
uint32_t  length,
int32_t  width 
)

Draw a dashed outline just inside the given rectangle.

Will fit the rectangle to the drawable's content rectangle.

Parameters
drawThe drawable to draw to.
rectThe rectangle to draw the outline inside.
pixelThe pixel color to draw with.
lengthThe length of the dashes.
widthThe width of the outline.

Definition at line 259 of file drawable.c.

References rect_t::bottom, drawable_t::buffer, drawable_t::contentRect, draw_invalidate(), rect_t::left, NULL, RECT_FIT, RECT_HEIGHT, RECT_WIDTH, rect_t::right, drawable_t::stride, rect_t::top, x, and y.

Referenced by button_draw().

◆ draw_frame()

void draw_frame ( drawable_t draw,
const rect_t rect,
uint64_t  width,
pixel_t  foreground,
pixel_t  background 
)

Draw a skeuomorphic frame.

Will draw a frame with the given width, using the foreground color for the top and left sides, and the background color for the bottom and right sides.

Will fit the rectangle to the drawable's content rectangle.

Parameters
drawThe drawable to draw to.
rectThe rectangle to draw the frame around.
widthThe width of the frame.
foregroundThe pixel color for the top and left sides.
backgroundThe pixel color for the bottom and right sides.

Definition at line 204 of file drawable.c.

References rect_t::bottom, drawable_t::buffer, drawable_t::contentRect, draw_invalidate(), draw_rect(), rect_t::left, NULL, RECT_FIT, rect_t::right, drawable_t::stride, rect_t::top, x, and y.

Referenced by block_draw(), button_draw(), draw_ridge(), field_edge_draw(), label_procedure(), startmenu_procedure(), window_deco_draw_titlebar(), and window_deco_redraw().

◆ draw_gradient()

void draw_gradient ( drawable_t draw,
const rect_t rect,
pixel_t  start,
pixel_t  end,
direction_t  direction,
bool  shouldAddNoise 
)

Draw a gradient filled rectangle.

Will fit the rectangle to the drawable's content rectangle.

Parameters
drawThe drawable to draw to.
rectThe rectangle to draw.
startThe starting pixel color.
endThe ending pixel color.
directionThe direction of the gradient.
shouldAddNoiseWhether to add noise to the gradient to reduce banding.

Definition at line 382 of file drawable.c.

References rect_t::bottom, drawable_t::buffer, CLAMP, drawable_t::contentRect, DIRECTION_DIAGONAL, DIRECTION_HORIZONTAL, DIRECTION_VERTICAL, draw_invalidate(), rect_t::left, NULL, PIXEL_ARGB, PIXEL_BLUE, PIXEL_GREEN, PIXEL_RED, rand(), RECT_FIT, RECT_HEIGHT, RECT_WIDTH, rect_t::right, start(), drawable_t::stride, rect_t::top, x, and y.

Referenced by startmenu_procedure(), and window_deco_draw_titlebar().

◆ draw_image()

void draw_image ( drawable_t draw,
image_t image,
const rect_t destRect,
const point_t srcPoint 
)

Draw an image,.

Parameters
drawThe drawable to draw to.
imageThe image to draw.
destRectThe rectangle that will be filled in the drawable.
srcPointThe top-left point in the image to copy from.

Definition at line 545 of file drawable.c.

References draw_transfer(), image, and image_draw().

Referenced by procedure().

◆ draw_image_blend()

void draw_image_blend ( drawable_t draw,
image_t image,
const rect_t destRect,
const point_t srcPoint 
)

Draw an image with alpha blending.

Parameters
drawThe drawable to draw to.
imageThe image to draw.
destRectThe rectangle that will be filled in the drawable.
srcPointThe top-left point in the image to copy from.

Definition at line 550 of file drawable.c.

References draw_transfer_blend(), image, and image_draw().

Referenced by button_draw().

◆ draw_invalidate()

void draw_invalidate ( drawable_t draw,
const rect_t rect 
)

Invalidate a rectangle in the drawable.

Marks the given rectangle as invalid, so that it will be updated on the next flush.

Flushing is handled by each element or other system using the drawable, not the drawable itself.

Parameters
drawThe drawable.
rectThe rectangle to invalidate, or NULL to invalidate the entire content rectangle.

Definition at line 1062 of file drawable.c.

References drawable_t::contentRect, drawable_t::invalidRect, NULL, RECT_AREA, and RECT_EXPAND_TO_CONTAIN.

Referenced by draw_dashed_outline(), draw_frame(), draw_gradient(), draw_rect(), draw_separator(), draw_string(), draw_text_multiline(), draw_transfer(), and draw_transfer_blend().

◆ draw_line()

void draw_line ( drawable_t draw,
const point_t start,
const point_t end,
pixel_t  pixel,
uint32_t  thickness 
)

Draw a line between two points.

Will clip the line to fit within the drawable's content rectangle.

Parameters
drawThe drawable to draw to.
startThe starting point of the line, inclusive.
endThe ending point of the line, inclusive.
pixelThe pixel color to draw with.
thicknessThe thickness of the line, must be at least 1.

Definition at line 179 of file drawable.c.

References atan2(), rect_t::bottom, CLAMP, drawable_t::contentRect, cos(), draw_polygon(), rect_t::left, M_PI_2, NULL, rect_t::right, sin(), start(), rect_t::top, point_t::x, and point_t::y.

◆ draw_polygon()

void draw_polygon ( drawable_t draw,
const point_t points,
uint64_t  pointCount,
pixel_t  pixel 
)

Draw a filled polygon.

Will clip the polygon to fit within the drawable's content rectangle.

Parameters
drawThe drawable to draw to.
pointsThe points of the polygon.
pointCountThe number of points in the polygon, must be at least 3.
pixelThe pixel color to fill with.

Definition at line 48 of file drawable.c.

References rect_t::bottom, drawable_t::buffer, drawable_t::contentRect, edge_compare(), INT64_MAX, INT64_MIN, edge_t::invSlope, rect_t::left, MAX, MIN, NULL, PIXEL_ALPHA, PIXEL_ARGB, PIXEL_BLEND, PIXEL_BLUE, PIXEL_GREEN, PIXEL_RED, polygon_contains(), qsort(), rect_t::right, drawable_t::stride, point_t::x, edge_t::x, x, point_t::y, y, edge_t::yMax, and edge_t::yMin.

Referenced by draw_hand(), draw_line(), and draw_marker().

◆ draw_rect()

void draw_rect ( drawable_t draw,
const rect_t rect,
pixel_t  pixel 
)

Draw a filled rectangle.

Will fit the rectangle to the drawable's content rectangle.

Parameters
drawThe drawable to draw to.
rectThe rectangle to draw.
pixelThe pixel color to fill with.

Definition at line 7 of file drawable.c.

References rect_t::bottom, drawable_t::buffer, drawable_t::contentRect, draw_invalidate(), rect_t::left, memset32(), NULL, RECT_FIT, RECT_WIDTH, drawable_t::stride, rect_t::top, and y.

Referenced by block_draw(), button_draw(), draw_bezel(), draw_frame(), draw_separator(), label_procedure(), popup_procedure(), procedure(), start_press_space_draw(), startmenu_procedure(), taskbar_procedure(), terminal_char_draw(), terminal_clear(), terminal_scroll(), and window_deco_redraw().

◆ draw_ridge()

void draw_ridge ( drawable_t draw,
const rect_t rect,
uint64_t  width,
pixel_t  foreground,
pixel_t  background 
)

Draw a ridge effect.

Will draw a inverted frame inside another frame inside the given rectangle, creating a ridge effect.

Parameters
drawThe drawable to draw to.
rectThe rectangle to draw the ridge effect within.
widthThe total width of the ridge effect.
foregroundThe pixel color for the top and left sides of the outer frame and the bottom and right sides of the inner frame.
backgroundThe pixel color for the bottom and right sides of the outer frame and the top and left sides of the inner frame.

Definition at line 994 of file drawable.c.

References draw_frame(), NULL, and RECT_SHRINK.

Referenced by side_panel_draw().

◆ draw_separator()

void draw_separator ( drawable_t draw,
const rect_t rect,
pixel_t  highlight,
pixel_t  shadow,
direction_t  direction 
)

Draw a separator line.

Will draw a separator line within the given rectangle, either horizontally or vertically.

Parameters
drawThe drawable to draw to.
rectThe rectangle to draw the separator within.
highlightThe pixel color for the highlight side of the separator (top or left).
shadowThe pixel color for the shadow side of the separator (bottom or right).
directionThe direction of the separator line.

Definition at line 1008 of file drawable.c.

References rect_t::bottom, drawable_t::contentRect, DIRECTION_HORIZONTAL, DIRECTION_VERTICAL, draw_invalidate(), draw_rect(), rect_t::left, NULL, RECT_FIT, RECT_HEIGHT, RECT_WIDTH, rect_t::right, and rect_t::top.

Referenced by taskbar_procedure().

◆ draw_string()

void draw_string ( drawable_t draw,
const font_t font,
const point_t point,
pixel_t  pixel,
const char *  string,
uint64_t  length 
)

Draw a string.

Will not draw a background, only the glyphs of the string.

Parameters
drawThe drawable to draw to.
fontThe font to use. If NULL, the default font for the display will be used.
pointThe top-left point to start drawing the string at.
pixelThe pixel color to draw with.
stringThe string to draw, null-termination is ignored.
lengthThe length of the string to draw.

Definition at line 591 of file drawable.c.

References grf_glyph_t::advanceX, grf_t::ascender, grf_t::buffer, grf_t::descender, drawable_t::disp, draw_grf_char(), draw_invalidate(), font_default(), font_kerning_offset(), font_width(), grf_t::glyphOffsets, font_t::grf, GRF_NONE, NULL, RECT_INIT_DIM, point_t::x, and point_t::y.

Referenced by draw_text(), draw_text_multiline(), and terminal_char_draw().

◆ draw_text()

void draw_text ( drawable_t draw,
const rect_t rect,
const font_t font,
align_t  xAlign,
align_t  yAlign,
pixel_t  pixel,
const char *  text 
)

Draw text to a drawable.

Will clip the text to fit within the rectangle, adding an ellipsis (...) if the text is too long.

Parameters
drawThe drawable to draw to.
rectThe rectangle to draw the text within.
fontThe font to use. If NULL, the default font for the display will be used.
xAlignThe horizontal alignment of the text within the rectangle.
yAlignThe vertical alignment of the text within the rectangle.
pixelThe pixel color to draw with.
textThe text to draw, null-terminated.

Definition at line 669 of file drawable.c.

References ALIGN_CENTER, ALIGN_MAX, ALIGN_MIN, grf_t::ascender, grf_t::descender, drawable_t::disp, draw_calculate_aligned_text_pos(), draw_string(), font_default(), font_kerning_offset(), font_width(), font_t::grf, rect_t::left, MAX, NULL, RECT_HEIGHT, RECT_WIDTH, strlen(), rect_t::top, point_t::x, and point_t::y.

Referenced by button_draw(), label_procedure(), side_panel_draw(), start_press_space_draw(), start_tetris_draw(), and window_deco_draw_titlebar().

◆ draw_text_multiline()

void draw_text_multiline ( drawable_t draw,
const rect_t rect,
const font_t font,
align_t  xAlign,
align_t  yAlign,
pixel_t  pixel,
const char *  text 
)

Draw multiline text to a drawable.

Will wrap lines to fit within the rectangle. Newlines (\n) are also supported.

Parameters
drawThe drawable to draw to.
rectThe rectangle to draw the text within.
fontThe font to use. If NULL, the default font for the display will be used.
xAlignThe horizontal alignment of the text within the rectangle.
yAlignThe vertical alignment of the text within the rectangle.
pixelThe pixel color to draw with.
textThe text to draw, null-terminated.

Definition at line 814 of file drawable.c.

References grf_glyph_t::advanceX, ALIGN_CENTER, ALIGN_MAX, ALIGN_MIN, grf_t::ascender, rect_t::bottom, grf_t::buffer, drawable_t::contentRect, grf_t::descender, drawable_t::disp, draw_invalidate(), draw_string(), font_default(), font_kerning_offset(), font_width(), grf_t::glyphOffsets, font_t::grf, GRF_NONE, rect_t::left, MAX, NULL, RECT_FIT, RECT_HEIGHT, RECT_WIDTH, rect_t::top, and point_t::x.

Referenced by popup_procedure().

◆ draw_transfer()

void draw_transfer ( drawable_t dest,
drawable_t src,
const rect_t destRect,
const point_t srcPoint 
)

Transfer pixels from one drawable to another.

Parameters
destThe destination drawable.
srcThe source drawable.
destRectThe rectangle that will be filled in the destination.
srcPointThe top-left point in the source drawable to copy from.

Definition at line 462 of file drawable.c.

References drawable_t::buffer, drawable_t::contentRect, draw_invalidate(), rect_t::left, memcpy(), memmove(), NULL, RECT_HEIGHT, RECT_WIDTH, drawable_t::stride, rect_t::top, point_t::x, point_t::y, and y.

Referenced by draw_image(), and terminal_scroll().

◆ draw_transfer_blend()

void draw_transfer_blend ( drawable_t dest,
drawable_t src,
const rect_t destRect,
const point_t srcPoint 
)

Transfer pixels from one drawable to another with alpha blending.

Parameters
destThe destination drawable.
srcThe source drawable.
destRectThe rectangle that will be filled in the destination.
srcPointThe top-left point in the source drawable to copy from.

Definition at line 507 of file drawable.c.

References drawable_t::buffer, drawable_t::contentRect, draw_invalidate(), rect_t::left, NULL, PIXEL_BLEND, RECT_HEIGHT, RECT_WIDTH, drawable_t::stride, rect_t::top, point_t::x, x, point_t::y, and y.

Referenced by draw_image_blend().