HikoGUI
A low latency retained GUI
|
Drawing is done through the hi::draw_context
object that is passed to hi::widget::draw()
when drawing a frame. The hi::draw_context
has several draw_*()
member functions that allow you to draw shapes, glyphs, text and images.
The first argument to those draw_*()
functions is a reference to the widget's hi::widget_layout
object. This object was stored by the hi::widget::set_layout()
function and contains the to-window transformation matrix and clipping rectangle used when drawing.
The second optional argument is an axis-aligned clipping rectangle which will be intersected with the layout's clipping rectangle. This can be used to specifically clip the shape, glyph or image being drawn.
The coordinate system for drawing is relative to the widget, including the elevation where the rectangle is drawn on the z-buffer. The origin of the coordinate system is in the left-bottom corner of the pixel in the left-bottom corner of the widget. The axes extend to the right, up and toward the user.
The coordinates, widths and radii are in virtual pixels. On high resolution displays there will be an integer scaling factor to map the virtual pixels onto physical pixels. In this library when you read "pixel" without an explicit qualifier, it is meant to be "virtual pixels".
The order of the corners in the hi::quad
, hi::quad_color
and hi::corner_radii
are always:
The order of in the hi::margins
are always:
In the example below we draw a rectangle with a border and rounded corners:
To get the rectangle to align to edges of pixels, you want to specify the quad as integer coordinates; and for the border side to specify either inside
or outside
, this will yield sharp borders.
The actual polygon send to the GPU is extended to include the part of the border that falls outside the polygon and an extra physical pixel for anti-aliasing.
In the example below we draw a circle with a border:
hi::draw_context::draw_circle()
is a convenience-function for hi::draw_context::draw_box()
A circle is a square with rounded corners with the corner diameter set to the height/width of the square.
When drawing circles among rectangular objects, it is recommended to draw the circle at a 1-3% larger radius, so that the shape seems to be the same size and aligned to the flat edges of the rectangles.
In the example below we draw a line with rounded end points:
hi::draw_context::draw_line()
is a convenience-function for hi::draw_context::draw_box()
A line is a thin rectangle with rounded corners with the corner diameter set to the width of the line.
When drawing horizontal or vertical lines, you may want to position the line so that it goes through the center of the pixels to get a sharp line. The origin of the coordinate system is in the left-bottom corner of the most left bottom pixel of a widget.
There are three steps for drawing an image:
Here we load the mars3.png
file from a resource directory from the constructor:
During set_constraints()
we try to construct a hi::gfx_pipeline_image::paged_image
. In the set_constraints()
function this may fail when the window is still being created; therefor, we keep reconstraining until it succeeds.
This version of the hi::gfx_pipeline_image::paged_image{}
constructor also directly uploads the image to the GPU. It is also possible to make a hi::gfx_pipeline_image::paged_image
with just a width and a height and then upload the image at a later time.