7#include "pipeline_box_vertex.hpp"
8#include "pipeline_image_vertex.hpp"
9#include "pipeline_SDF_vertex.hpp"
11#include "../geometry/axis_aligned_rectangle.hpp"
12#include "../geometry/matrix.hpp"
13#include "../geometry/corner_radii.hpp"
14#include "../geometry/identity.hpp"
15#include "../geometry/transform.hpp"
16#include "../geometry/circle.hpp"
17#include "../geometry/line_end_cap.hpp"
18#include "../text/text_cursor.hpp"
19#include "../text/text_selection.hpp"
20#include "../text/text_shaper.hpp"
21#include "../color/color.hpp"
22#include "../color/quad_color.hpp"
23#include "../widgets/widget_layout.hpp"
24#include "../vspan.hpp"
26namespace hi::inline v1 {
28class gfx_device_vulkan;
35enum class border_side {
93 operator bool() const noexcept
114 hi::border_side border_side,
115 hi::corner_radii
const &corner_radius = {})
const noexcept
118 hilet border_radius = border_width * 0.5f;
120 border_side == hi::border_side::inside ? box - border_radius :
121 border_side == hi::border_side::outside ? box + border_radius :
123 hilet corner_radius_ =
124 border_side == hi::border_side::inside ? corner_radius - border_radius :
125 border_side == hi::border_side::outside ? corner_radius + border_radius :
155 hi::border_side border_side,
156 hi::corner_radii
const &corner_radius = {})
const noexcept
159 hilet border_radius = border_width * 0.5f;
161 border_side == hi::border_side::inside ? box - border_radius :
162 border_side == hi::border_side::outside ? box + border_radius :
164 hilet corner_radius_ =
165 border_side == hi::border_side::inside ? corner_radius - border_radius :
166 border_side == hi::border_side::outside ? corner_radius + border_radius :
189 hi::corner_radii
const &corner_radius = {})
const noexcept
213 hi::corner_radii
const &corner_radius = {})
const noexcept
224 [[nodiscard]]
constexpr static rectangle
225 make_rectangle(line_segment
const &line,
float width, line_end_cap c1, line_end_cap c2)
noexcept
227 auto right = line.direction();
229 hilet radius = width * 0.5f;
230 hilet n = normal(right, 0.0f);
231 hilet up = n * width;
232 hilet t = normalize(right);
234 auto origin = line.origin() - n * radius;
237 hilet radius_offset = t * radius;
238 if (c1 == line_end_cap::round) {
239 origin -= radius_offset;
240 right += radius_offset;
242 if (c2 == line_end_cap::round) {
243 right += radius_offset;
246 return rectangle{origin,
right, up};
249 [[nodiscard]]
constexpr static corner_radii make_corner_radii(
float width, line_end_cap c1, line_end_cap c2)
noexcept
251 auto r = f32x4::broadcast(width * 0.5f);
253 if (c1 == line_end_cap::flat) {
256 if (c2 == line_end_cap::flat) {
260 return corner_radii{r};
264 widget_layout
const &layout,
265 line_segment
const &line,
267 quad_color
const &fill_color,
268 line_end_cap c1 = line_end_cap::flat,
269 line_end_cap c2 = line_end_cap::flat)
const noexcept
274 hilet box = make_rectangle(line_, width_, c1, c2);
275 hilet corners = make_corner_radii(width_, c1, c2);
281 widget_layout
const &layout,
282 aarectangle
const &clipping_rectangle,
283 line_segment
const &line,
285 quad_color
const &fill_color,
286 line_end_cap c1 = line_end_cap::flat,
287 line_end_cap c2 = line_end_cap::flat)
const noexcept
289 hi_axiom(width != 0.0f);
293 hilet box = make_rectangle(line_, width_, c1, c2);
294 hilet corners = make_corner_radii(width_, c1, c2);
299 [[nodiscard]]
constexpr static rectangle make_rectangle(hi::circle
const &circle)
noexcept
301 hilet circle_ = f32x4{circle};
302 hilet origin = point3{circle_.xyz1() - circle_.ww00()};
304 hilet up = vector3{circle_._0w00() * 2.0f};
305 return rectangle{origin,
right, up};
308 [[nodiscard]]
constexpr static corner_radii make_corner_radii(hi::circle
const &circle)
noexcept
310 return corner_radii{f32x4{circle}.wwww()};
313 void draw_circle(widget_layout
const &layout, hi::circle
const &circle, quad_color
const &fill_color)
const noexcept
321 widget_layout
const &layout,
322 aarectangle
const clipping_rectangle,
323 hi::circle
const &circle,
324 quad_color
const &fill_color)
const
326 hilet box = layout.to_window * make_rectangle(circle);
327 hilet corners = layout.to_window * make_corner_radii(circle);
328 return _draw_box(layout.window_clipping_rectangle(clipping_rectangle), box, fill_color, fill_color, 0.0f, corners);
332 widget_layout
const &layout,
333 hi::circle
const &circle,
334 quad_color
const &fill_color,
335 quad_color
const &border_color,
337 hi::border_side border_side)
const noexcept
341 border_side == hi::border_side::inside ? circle - border_width * 0.5f :
342 border_side == hi::border_side::outside ? circle + border_width * 0.5f :
352 widget_layout
const &layout,
353 aarectangle
const &clipping_rectangle,
354 hi::circle
const &circle,
355 quad_color
const &fill_color,
356 quad_color
const &border_color,
358 hi::border_side border_side)
const noexcept
362 border_side == hi::border_side::inside ? circle - border_width * 0.5f :
363 border_side == hi::border_side::outside ? circle + border_width * 0.5f :
458 shaped_text
const &text)
const noexcept
581 hi::color primary_color,
582 hi::color secondary_color,
584 bool dead_character_mode)
const noexcept
586 return _draw_text_cursors(
594 dead_character_mode);
603 vspan<pipeline_box::vertex> *_box_vertices;
604 vspan<pipeline_image::vertex> *_image_vertices;
605 vspan<pipeline_SDF::vertex> *_sdf_vertices;
608 aarectangle
const &clipping_rectangle,
610 quad_color
const &fill_color,
611 quad_color
const &border_color,
613 hi::corner_radii corner_radius)
const noexcept;
616 aarectangle
const &clipping_rectangle,
617 matrix3
const &transform,
618 shaped_text
const &text,
619 std::optional<quad_color> color = {})
const noexcept;
622 aarectangle
const &clipping_rectangle,
623 matrix3
const &transform,
624 text_shaper
const &text,
625 std::optional<quad_color> color = {})
const noexcept;
627 void _draw_text_selection(
628 aarectangle
const &clipping_rectangle,
629 matrix3
const &transform,
630 text_shaper
const &text,
631 text_selection
const &selection,
632 hi::color)
const noexcept;
634 void _draw_text_insertion_cursor_empty(
635 aarectangle
const &clipping_rectangle,
636 matrix3
const &transform,
637 text_shaper
const &text,
638 hi::color color)
const noexcept;
640 void _draw_text_insertion_cursor(
641 aarectangle
const &clipping_rectangle,
642 matrix3
const &transform,
643 text_shaper
const &text,
646 bool show_flag)
const noexcept;
648 void _draw_text_overwrite_cursor(
649 aarectangle
const &clipping_rectangle,
650 matrix3
const &transform,
651 text_shaper::char_const_iterator it,
652 hi::color color)
const noexcept;
654 void _draw_text_cursors(
655 aarectangle
const &clipping_rectangle,
656 matrix3
const &transform,
657 text_shaper
const &text,
659 hi::color primary_color,
660 hi::color secondary_color,
662 bool dead_character_mode)
const noexcept;
664 void _draw_glyph(aarectangle
const &clipping_rectangle, quad
const &box, quad_color
const &color, glyph_ids
const &glyph)
667 [[nodiscard]]
bool _draw_image(aarectangle
const &clipping_rectangle, quad
const &box, paged_image &image)
const noexcept;
#define hilet
Invariant should be the default for variables.
Definition required.hpp:23
This is a RGBA floating point color.
Definition color.hpp:37
Definition quad_color.hpp:9
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:20
Draw context for drawing using the HikoGUI shaders.
Definition draw_context.hpp:51
std::size_t frame_buffer_index
The frame buffer index of the image we are currently rendering.
Definition draw_context.hpp:57
void draw_text(widget_layout const &layout, matrix3 const &transform, text_shaper const &text) const noexcept
Draw shaped text.
Definition draw_context.hpp:538
void draw_box(widget_layout const &layout, quad const &box, quad_color const &fill_color, hi::corner_radii const &corner_radius={}) const noexcept
Draw a box with rounded corners without a border.
Definition draw_context.hpp:185
float saturation
The tone-mapper's saturation.
Definition draw_context.hpp:73
utc_nanoseconds display_time_point
The time when the drawing will appear on the screen.
Definition draw_context.hpp:77
aarectangle scissor_rectangle
This is the rectangle of the window that is being redrawn.
Definition draw_context.hpp:61
void draw_text(widget_layout const &layout, aarectangle const &clipping_rectangle, matrix3 const &transform, quad_color const &color, text_shaper const &text) const noexcept
Draw shaped text.
Definition draw_context.hpp:506
void draw_text(widget_layout const &layout, matrix3 const &transform, shaped_text const &text) const noexcept
Draw shaped text.
Definition draw_context.hpp:469
bool draw_image(widget_layout const &layout, aarectangle const &clipping_rectangle, quad const &box, paged_image &image) const noexcept
Draw an image.
Definition draw_context.hpp:396
void draw_text_cursors(widget_layout const &layout, text_shaper const &text, text_cursor cursor, hi::color primary_color, hi::color secondary_color, bool overwrite_mode, bool dead_character_mode) const noexcept
Draw text cursors of shaped text.
Definition draw_context.hpp:577
void draw_text(widget_layout const &layout, quad_color const &color, text_shaper const &text) const noexcept
Draw shaped text.
Definition draw_context.hpp:493
void draw_text_selection(widget_layout const &layout, text_shaper const &text, text_selection const &selection, hi::color color) const noexcept
Draw text-selection of shaped text.
Definition draw_context.hpp:561
color background_color
The background color to clear the window with.
Definition draw_context.hpp:65
void draw_glyph(widget_layout const &layout, aarectangle clipping_rectangle, quad const &box, quad_color const &color, glyph_ids const &glyph) const noexcept
Draw a glyph.
Definition draw_context.hpp:422
void draw_text(widget_layout const &layout, matrix3 const &transform, quad_color const &color, shaped_text const &text) const noexcept
Draw shaped text.
Definition draw_context.hpp:439
void draw_box(widget_layout const &layout, aarectangle const &clipping_rectangle, quad const &box, quad_color const &fill_color, hi::corner_radii const &corner_radius={}) const noexcept
Draw a box with rounded corners without a border.
Definition draw_context.hpp:208
void draw_glyph(widget_layout const &layout, quad const &box, quad_color const &color, glyph_ids const &glyph) const noexcept
Draw a glyph.
Definition draw_context.hpp:409
void draw_text(widget_layout const &layout, matrix3 const &transform, quad_color const &color, text_shaper const &text) const noexcept
Draw shaped text.
Definition draw_context.hpp:481
void draw_box(widget_layout const &layout, quad const &box, quad_color const &fill_color, quad_color const &border_color, float border_width, hi::border_side border_side, hi::corner_radii const &corner_radius={}) const noexcept
Draw a box with rounded corners.
Definition draw_context.hpp:108
void draw_text(widget_layout const &layout, aarectangle const &clipping_rectangle, quad_color const &color, text_shaper const &text) const noexcept
Draw shaped text.
Definition draw_context.hpp:523
void draw_text(widget_layout const &layout, aarectangle const &clipping_rectangle, matrix3 const &transform, quad_color const &color, shaped_text const &text) const noexcept
Draw shaped text.
Definition draw_context.hpp:453
hi::subpixel_orientation subpixel_orientation
The subpixel orientation for rendering glyphs.
Definition draw_context.hpp:69
void draw_box(widget_layout const &layout, aarectangle const &clipping_rectangle, quad const &box, quad_color const &fill_color, quad_color const &border_color, float border_width, hi::border_side border_side, hi::corner_radii const &corner_radius={}) const noexcept
Draw a box with rounded corners.
Definition draw_context.hpp:148
void draw_text(widget_layout const &layout, text_shaper const &text) const noexcept
Draw shaped text.
Definition draw_context.hpp:548
bool draw_image(widget_layout const &layout, quad const &box, paged_image &image) const noexcept
Draw an image.
Definition draw_context.hpp:381
Definition gfx_device_vulkan.hpp:20
This is a image that is uploaded into the texture atlas.
Definition paged_image.hpp:25
A set of glyph-ids of a font which composites into a single glyph.
Definition glyph_ids.hpp:127
Definition text_cursor.hpp:18
Definition text_selection.hpp:17
Text shaper.
Definition text_shaper.hpp:39
Definition widget_layout.hpp:17
constexpr aarectangle window_clipping_rectangle() const noexcept
Get the clipping rectangle in window coordinate system.
Definition widget_layout.hpp:112
matrix3 to_window
This matrix transforms local coordinates to window coordinates.
Definition widget_layout.hpp:35