7#include "pipeline_box_vertex.hpp"
8#include "pipeline_image_vertex.hpp"
9#include "pipeline_SDF_vertex.hpp"
10#include "pipeline_alpha_vertex.hpp"
12#include "../geometry/axis_aligned_rectangle.hpp"
13#include "../geometry/matrix.hpp"
14#include "../geometry/corner_radii.hpp"
15#include "../geometry/identity.hpp"
16#include "../geometry/transform.hpp"
17#include "../geometry/circle.hpp"
18#include "../geometry/line_end_cap.hpp"
19#include "../text/text_cursor.hpp"
20#include "../text/text_selection.hpp"
21#include "../text/text_shaper.hpp"
22#include "../color/color.hpp"
23#include "../color/quad_color.hpp"
25#include "../vector_span.hpp"
27namespace hi::inline
v1 {
29class gfx_device_vulkan;
95 operator bool() const noexcept
111 widget_layout
const& layout,
117 hi::corner_radii
const& corner_radius = {})
const noexcept
120 hilet border_radius = border_width * 0.5f;
122 border_side == hi::border_side::inside ? box - border_radius :
123 border_side == hi::border_side::outside ? box + border_radius :
125 hilet corner_radius_ =
126 border_side == hi::border_side::inside ? corner_radius - border_radius :
127 border_side == hi::border_side::outside ? corner_radius + border_radius :
132 layout.window_clipping_rectangle(),
133 layout.to_window * box_,
136 layout.to_window * border_width,
137 layout.to_window * corner_radius_);
152 widget_layout
const& layout,
159 hi::corner_radii
const& corner_radius = {})
const noexcept
162 hilet border_radius = border_width * 0.5f;
164 border_side == hi::border_side::inside ? box - border_radius :
165 border_side == hi::border_side::outside ? box + border_radius :
167 hilet corner_radius_ =
168 border_side == hi::border_side::inside ? corner_radius - border_radius :
169 border_side == hi::border_side::outside ? corner_radius + border_radius :
174 layout.window_clipping_rectangle(clipping_rectangle),
175 layout.to_window * box_,
178 layout.to_window * border_width,
179 layout.to_window * corner_radius_);
189 widget_layout
const& layout,
192 hi::corner_radii
const& corner_radius = {})
const noexcept
195 layout.window_clipping_rectangle(),
196 layout.to_window * box,
200 layout.to_window * corner_radius);
212 widget_layout
const& layout,
216 hi::corner_radii
const& corner_radius = {})
const noexcept
219 layout.window_clipping_rectangle(clipping_rectangle),
220 layout.to_window * box,
224 layout.to_window * corner_radius);
227 [[nodiscard]]
constexpr static rectangle
228 make_rectangle(line_segment
const& line,
float width, line_end_cap c1, line_end_cap c2)
noexcept
230 auto right = line.direction();
232 hilet radius = width * 0.5f;
233 hilet n = normal(right, 0.0f);
234 hilet up = n * width;
235 hilet t = normalize(right);
237 auto origin = line.origin() - n * radius;
240 hilet radius_offset = t * radius;
241 if (c1 == line_end_cap::round) {
242 origin -= radius_offset;
243 right += radius_offset;
245 if (c2 == line_end_cap::round) {
246 right += radius_offset;
249 return rectangle{origin,
right, up};
252 [[nodiscard]]
constexpr static corner_radii make_corner_radii(
float width, line_end_cap c1, line_end_cap c2)
noexcept
254 auto r = f32x4::broadcast(width * 0.5f);
256 if (c1 == line_end_cap::flat) {
259 if (c2 == line_end_cap::flat) {
263 return corner_radii{r};
267 widget_layout
const& layout,
268 line_segment
const& line,
270 quad_color
const& fill_color,
271 line_end_cap c1 = line_end_cap::flat,
272 line_end_cap c2 = line_end_cap::flat)
const noexcept
274 hilet line_ = layout.to_window * line;
275 hilet width_ = layout.to_window * width;
277 hilet box = make_rectangle(line_, width_, c1, c2);
278 hilet corners = make_corner_radii(width_, c1, c2);
280 return _draw_box(layout.window_clipping_rectangle(), box, fill_color, fill_color, 0.0f, corners);
284 widget_layout
const& layout,
285 aarectangle
const& clipping_rectangle,
286 line_segment
const& line,
288 quad_color
const& fill_color,
289 line_end_cap c1 = line_end_cap::flat,
290 line_end_cap c2 = line_end_cap::flat)
const noexcept
292 hi_axiom(width != 0.0f);
293 hilet line_ = layout.to_window * line;
294 hilet width_ = layout.to_window * width;
296 hilet box = make_rectangle(line_, width_, c1, c2);
297 hilet corners = make_corner_radii(width_, c1, c2);
299 return _draw_box(layout.window_clipping_rectangle(clipping_rectangle), box, fill_color, fill_color, 0.0f, corners);
302 [[nodiscard]]
constexpr static rectangle make_rectangle(hi::circle
const& circle)
noexcept
305 hilet origin = point3{circle_.xyz1() - circle_.ww00()};
307 hilet up = vector3{circle_._0w00() * 2.0f};
308 return rectangle{origin,
right, up};
311 [[nodiscard]]
constexpr static corner_radii make_corner_radii(hi::circle
const& circle)
noexcept
313 return corner_radii{f32x4{
circle}.wwww()};
316 void draw_circle(widget_layout
const& layout, hi::circle
const& circle, quad_color
const& fill_color)
const noexcept
318 hilet box = layout.to_window * make_rectangle(circle);
319 hilet corners = layout.to_window * make_corner_radii(circle);
320 return _draw_box(layout.window_clipping_rectangle(), box, fill_color, fill_color, 0.0f, corners);
324 widget_layout
const& layout,
325 aarectangle
const clipping_rectangle,
326 hi::circle
const& circle,
327 quad_color
const& fill_color)
const
329 hilet box = layout.to_window * make_rectangle(circle);
330 hilet corners = layout.to_window * make_corner_radii(circle);
331 return _draw_box(layout.window_clipping_rectangle(clipping_rectangle), box, fill_color, fill_color, 0.0f, corners);
335 widget_layout
const& layout,
336 hi::circle
const& circle,
337 quad_color
const& fill_color,
338 quad_color
const& border_color,
340 hi::border_side border_side)
const noexcept
349 hilet box = layout.to_window * make_rectangle(circle_);
350 hilet corners = layout.to_window * make_corner_radii(circle_);
351 return _draw_box(layout.window_clipping_rectangle(), box, fill_color, border_color, border_width, corners);
355 widget_layout
const& layout,
356 aarectangle
const& clipping_rectangle,
357 hi::circle
const& circle,
358 quad_color
const& fill_color,
359 quad_color
const& border_color,
361 hi::border_side border_side)
const noexcept
370 hilet box = layout.to_window * make_rectangle(circle_);
371 hilet corners = layout.to_window * make_corner_radii(circle_);
373 layout.window_clipping_rectangle(clipping_rectangle), box, fill_color, border_color, border_width, corners);
386 return _draw_image(layout.window_clipping_rectangle(), layout.to_window * box, image);
402 return _draw_image(layout.window_clipping_rectangle(clipping_rectangle), layout.to_window * box, image);
414 return _draw_glyph(layout.window_clipping_rectangle(), layout.to_window * box,
color, glyph);
426 widget_layout
const& layout,
432 return _draw_glyph(layout.window_clipping_rectangle(clipping_rectangle), layout.to_window * box,
color, glyph);
445 return _draw_text(layout.window_clipping_rectangle(), layout.to_window * transform,
text,
color);
457 widget_layout
const& layout,
461 shaped_text
const&
text)
const noexcept
463 return _draw_text(layout.window_clipping_rectangle(clipping_rectangle), layout.to_window * transform,
text,
color);
474 return _draw_text(layout.window_clipping_rectangle(), layout.to_window * transform,
text);
487 return _draw_text(layout.window_clipping_rectangle(), layout.to_window * transform,
text,
color);
498 return _draw_text(layout.window_clipping_rectangle(), layout.to_window,
text,
color);
510 widget_layout
const& layout,
516 return _draw_text(layout.window_clipping_rectangle(clipping_rectangle), layout.to_window * transform,
text,
color);
527 widget_layout
const& layout,
532 return _draw_text(layout.window_clipping_rectangle(clipping_rectangle), layout.to_window,
text,
color);
543 return _draw_text(layout.window_clipping_rectangle(), layout.to_window * transform,
text);
553 return _draw_text(layout.window_clipping_rectangle(), layout.to_window,
text);
567 return _draw_text_selection(layout.window_clipping_rectangle(), layout.to_window,
text, selection,
color);
581 widget_layout
const& layout,
584 hi::color primary_color,
585 hi::color secondary_color,
587 bool dead_character_mode)
const noexcept
589 return _draw_text_cursors(
590 layout.window_clipping_rectangle(),
597 dead_character_mode);
610 return _override_alpha(layout.window_clipping_rectangle(), layout.to_window * box, 0.0f);
613 [[nodiscard]]
friend bool overlaps(
draw_context const& context, widget_layout
const& layout)
noexcept
615 return overlaps(context.scissor_rectangle, layout.window_clipping_rectangle());
619 vector_span<pipeline_box::vertex> *_box_vertices;
620 vector_span<pipeline_image::vertex> *_image_vertices;
621 vector_span<pipeline_SDF::vertex> *_sdf_vertices;
622 vector_span<pipeline_alpha::vertex> *_alpha_vertices;
624 void _override_alpha(aarectangle
const& clipping_rectangle, quad box,
float alpha)
const noexcept;
627 aarectangle
const& clipping_rectangle,
629 quad_color
const& fill_color,
630 quad_color
const& border_color,
632 hi::corner_radii corner_radius)
const noexcept;
635 aarectangle
const& clipping_rectangle,
636 matrix3
const& transform,
637 shaped_text
const& text,
638 std::optional<quad_color> color = {})
const noexcept;
641 aarectangle
const& clipping_rectangle,
642 matrix3
const& transform,
643 text_shaper
const& text,
644 std::optional<quad_color> color = {})
const noexcept;
646 void _draw_text_selection(
647 aarectangle
const& clipping_rectangle,
648 matrix3
const& transform,
649 text_shaper
const& text,
650 text_selection
const& selection,
651 hi::color)
const noexcept;
653 void _draw_text_insertion_cursor_empty(
654 aarectangle
const& clipping_rectangle,
655 matrix3
const& transform,
656 text_shaper
const& text,
657 hi::color color)
const noexcept;
659 void _draw_text_insertion_cursor(
660 aarectangle
const& clipping_rectangle,
661 matrix3
const& transform,
662 text_shaper
const& text,
665 bool show_flag)
const noexcept;
667 void _draw_text_overwrite_cursor(
668 aarectangle
const& clipping_rectangle,
669 matrix3
const& transform,
670 text_shaper::char_const_iterator it,
671 hi::color color)
const noexcept;
673 void _draw_text_cursors(
674 aarectangle
const& clipping_rectangle,
675 matrix3
const& transform,
676 text_shaper
const& text,
678 hi::color primary_color,
679 hi::color secondary_color,
681 bool dead_character_mode)
const noexcept;
683 void _draw_glyph(aarectangle
const& clipping_rectangle, quad
const& box, quad_color
const& color, glyph_ids
const& glyph)
686 [[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 utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:15
@ circle
<circle> Encircled form.
border_side
The side where the border is drawn.
Definition draw_context.hpp:36
@ inside
The border is drawn inside the edge of a quad.
@ outside
The border is drawn outside the edge of a quad.
@ on
The border is drawn on the edge of a quad.
This is a RGBA floating point color.
Definition color.hpp:39
Definition quad_color.hpp:12
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:52
std::size_t frame_buffer_index
The frame buffer index of the image we are currently rendering.
Definition draw_context.hpp:58
void draw_text(widget_layout const &layout, matrix3 const &transform, text_shaper const &text) const noexcept
Draw shaped text.
Definition draw_context.hpp:541
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:188
float saturation
The tone-mapper's saturation.
Definition draw_context.hpp:74
utc_nanoseconds display_time_point
The time when the drawing will appear on the screen.
Definition draw_context.hpp:78
aarectangle scissor_rectangle
This is the rectangle of the window that is being redrawn.
Definition draw_context.hpp:62
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:509
void draw_text(widget_layout const &layout, matrix3 const &transform, shaped_text const &text) const noexcept
Draw shaped text.
Definition draw_context.hpp:472
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:399
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:580
void draw_text(widget_layout const &layout, quad_color const &color, text_shaper const &text) const noexcept
Draw shaped text.
Definition draw_context.hpp:496
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:564
color background_color
The background color to clear the window with.
Definition draw_context.hpp:66
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:425
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:442
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:211
void make_hole(widget_layout const &layout, quad const &box) const noexcept
Make a hole in the user interface.
Definition draw_context.hpp:608
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:412
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:484
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:110
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:526
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:456
hi::subpixel_orientation subpixel_orientation
The subpixel orientation for rendering glyphs.
Definition draw_context.hpp:70
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:151
void draw_text(widget_layout const &layout, text_shaper const &text) const noexcept
Draw shaped text.
Definition draw_context.hpp:551
bool draw_image(widget_layout const &layout, quad const &box, paged_image &image) const noexcept
Draw an image.
Definition draw_context.hpp:384
Definition gfx_device_vulkan.hpp:21
This is a image that is uploaded into the texture atlas.
Definition paged_image.hpp:25
A variant of text.
Definition label.hpp:36
A set of glyph-ids of a font which composites into a single glyph.
Definition glyph_ids.hpp:135
A cursor-position in text.
Definition text_cursor.hpp:25
Definition text_selection.hpp:17
Text shaper.
Definition text_shaper.hpp:39
Definition vector_span.hpp:134