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;
99 operator bool() const noexcept
115 widget_layout
const& layout,
121 hi::corner_radii
const& corner_radius = {})
const noexcept
124 hilet border_radius = border_width * 0.5f;
126 border_side == hi::border_side::inside ? box - border_radius :
127 border_side == hi::border_side::outside ? box + border_radius :
129 hilet corner_radius_ =
130 border_side == hi::border_side::inside ? corner_radius - border_radius :
131 border_side == hi::border_side::outside ? corner_radius + border_radius :
136 layout.clipping_rectangle_on_window(),
137 layout.to_window * box_,
140 layout.to_window * border_width,
141 layout.to_window * corner_radius_);
156 widget_layout
const& layout,
163 hi::corner_radii
const& corner_radius = {})
const noexcept
166 hilet border_radius = border_width * 0.5f;
168 border_side == hi::border_side::inside ? box - border_radius :
169 border_side == hi::border_side::outside ? box + border_radius :
171 hilet corner_radius_ =
172 border_side == hi::border_side::inside ? corner_radius - border_radius :
173 border_side == hi::border_side::outside ? corner_radius + border_radius :
178 layout.clipping_rectangle_on_window(clipping_rectangle),
179 layout.to_window * box_,
182 layout.to_window * border_width,
183 layout.to_window * corner_radius_);
193 widget_layout
const& layout,
196 hi::corner_radii
const& corner_radius = {})
const noexcept
199 layout.clipping_rectangle_on_window(),
200 layout.to_window * box,
204 layout.to_window * corner_radius);
216 widget_layout
const& layout,
220 hi::corner_radii
const& corner_radius = {})
const noexcept
223 layout.clipping_rectangle_on_window(clipping_rectangle),
224 layout.to_window * box,
228 layout.to_window * corner_radius);
231 [[nodiscard]]
constexpr static rectangle
232 make_rectangle(line_segment
const& line,
float width, line_end_cap c1, line_end_cap c2)
noexcept
234 auto right = line.direction();
236 hilet radius = width * 0.5f;
237 hilet n = normal(right, 0.0f);
238 hilet up = n * width;
239 hilet t = normalize(right);
241 auto origin = line.origin() - n * radius;
244 hilet radius_offset = t * radius;
245 if (c1 == line_end_cap::round) {
246 origin -= radius_offset;
247 right += radius_offset;
249 if (c2 == line_end_cap::round) {
250 right += radius_offset;
256 [[nodiscard]]
constexpr static corner_radii make_corner_radii(
float width, line_end_cap c1, line_end_cap c2)
noexcept
258 auto r = f32x4::broadcast(width * 0.5f);
260 if (c1 == line_end_cap::flat) {
263 if (c2 == line_end_cap::flat) {
267 return corner_radii{r};
271 widget_layout
const& layout,
272 line_segment
const& line,
274 quad_color
const& fill_color,
275 line_end_cap c1 = line_end_cap::flat,
276 line_end_cap c2 = line_end_cap::flat)
const noexcept
278 hilet line_ = layout.to_window * line;
279 hilet width_ = layout.to_window * width;
281 hilet box = make_rectangle(line_, width_, c1, c2);
282 hilet corners = make_corner_radii(width_, c1, c2);
284 return _draw_box(layout.clipping_rectangle_on_window(), box, fill_color, fill_color, 0.0f, corners);
288 widget_layout
const& layout,
289 aarectangle
const& clipping_rectangle,
290 line_segment
const& line,
292 quad_color
const& fill_color,
293 line_end_cap c1 = line_end_cap::flat,
294 line_end_cap c2 = line_end_cap::flat)
const noexcept
297 hilet line_ = layout.to_window * line;
298 hilet width_ = layout.to_window * width;
300 hilet box = make_rectangle(line_, width_, c1, c2);
301 hilet corners = make_corner_radii(width_, c1, c2);
303 return _draw_box(layout.clipping_rectangle_on_window(clipping_rectangle), box, fill_color, fill_color, 0.0f, corners);
306 [[nodiscard]]
constexpr static rectangle make_rectangle(hi::circle
const& circle)
noexcept
309 hilet origin = point3{circle_.xyz1() - circle_.ww00()};
311 hilet up = vector3{circle_._0w00() * 2.0f};
315 [[nodiscard]]
constexpr static corner_radii make_corner_radii(hi::circle
const& circle)
noexcept
317 return corner_radii{f32x4{
circle}.wwww()};
320 void draw_circle(widget_layout
const& layout, hi::circle
const& circle, quad_color
const& fill_color)
const noexcept
322 hilet box = layout.to_window * make_rectangle(circle);
323 hilet corners = layout.to_window * make_corner_radii(circle);
324 return _draw_box(layout.clipping_rectangle_on_window(), box, fill_color, fill_color, 0.0f, corners);
328 widget_layout
const& layout,
329 aarectangle
const clipping_rectangle,
330 hi::circle
const& circle,
331 quad_color
const& fill_color)
const
333 hilet box = layout.to_window * make_rectangle(circle);
334 hilet corners = layout.to_window * make_corner_radii(circle);
335 return _draw_box(layout.clipping_rectangle_on_window(clipping_rectangle), box, fill_color, fill_color, 0.0f, corners);
339 widget_layout
const& layout,
340 hi::circle
const& circle,
341 quad_color
const& fill_color,
342 quad_color
const& border_color,
344 hi::border_side border_side)
const noexcept
353 hilet box = layout.to_window * make_rectangle(circle_);
354 hilet corners = layout.to_window * make_corner_radii(circle_);
355 return _draw_box(layout.clipping_rectangle_on_window(), box, fill_color, border_color, border_width, corners);
359 widget_layout
const& layout,
360 aarectangle
const& clipping_rectangle,
361 hi::circle
const& circle,
362 quad_color
const& fill_color,
363 quad_color
const& border_color,
365 hi::border_side border_side)
const noexcept
374 hilet box = layout.to_window * make_rectangle(circle_);
375 hilet corners = layout.to_window * make_corner_radii(circle_);
377 layout.clipping_rectangle_on_window(clipping_rectangle), box, fill_color, border_color, border_width, corners);
390 return _draw_image(layout.clipping_rectangle_on_window(), layout.to_window * box, image);
406 return _draw_image(layout.clipping_rectangle_on_window(clipping_rectangle), layout.to_window * box, image);
418 return _draw_glyph(layout.clipping_rectangle_on_window(), layout.to_window * box,
color, glyph);
430 widget_layout
const& layout,
436 return _draw_glyph(layout.clipping_rectangle_on_window(clipping_rectangle), layout.to_window * box,
color, glyph);
449 return _draw_text(layout.clipping_rectangle_on_window(), layout.to_window * transform,
text,
color);
461 widget_layout
const& layout,
465 shaped_text
const&
text)
const noexcept
467 return _draw_text(layout.clipping_rectangle_on_window(clipping_rectangle), layout.to_window * transform,
text,
color);
478 return _draw_text(layout.clipping_rectangle_on_window(), layout.to_window * transform,
text);
491 return _draw_text(layout.clipping_rectangle_on_window(), layout.to_window * transform,
text,
color);
502 return _draw_text(layout.clipping_rectangle_on_window(), layout.to_window,
text,
color);
514 widget_layout
const& layout,
520 return _draw_text(layout.clipping_rectangle_on_window(clipping_rectangle), layout.to_window * transform,
text,
color);
531 widget_layout
const& layout,
536 return _draw_text(layout.clipping_rectangle_on_window(clipping_rectangle), layout.to_window,
text,
color);
547 return _draw_text(layout.clipping_rectangle_on_window(), layout.to_window * transform,
text);
557 return _draw_text(layout.clipping_rectangle_on_window(), layout.to_window,
text);
571 return _draw_text_selection(layout.clipping_rectangle_on_window(), layout.to_window,
text, selection,
color);
585 widget_layout
const& layout,
588 hi::color primary_color,
589 hi::color secondary_color,
591 bool dead_character_mode)
const noexcept
593 return _draw_text_cursors(
594 layout.clipping_rectangle_on_window(),
601 dead_character_mode);
614 return _override_alpha(layout.clipping_rectangle_on_window(), layout.to_window * box, 0.0f);
617 [[nodiscard]]
friend bool overlaps(
draw_context const& context, widget_layout
const& layout)
noexcept
619 return overlaps(context.scissor_rectangle, layout.clipping_rectangle_on_window());
623 vector_span<pipeline_box::vertex> *_box_vertices;
624 vector_span<pipeline_image::vertex> *_image_vertices;
625 vector_span<pipeline_SDF::vertex> *_sdf_vertices;
626 vector_span<pipeline_alpha::vertex> *_alpha_vertices;
628 void _override_alpha(aarectangle
const& clipping_rectangle, quad box,
float alpha)
const noexcept;
631 aarectangle
const& clipping_rectangle,
633 quad_color
const& fill_color,
634 quad_color
const& border_color,
636 hi::corner_radii corner_radius)
const noexcept;
639 aarectangle
const& clipping_rectangle,
640 matrix3
const& transform,
641 shaped_text
const& text,
642 std::optional<quad_color> color = {})
const noexcept;
645 aarectangle
const& clipping_rectangle,
646 matrix3
const& transform,
647 text_shaper
const& text,
648 std::optional<quad_color> color = {})
const noexcept;
650 void _draw_text_selection(
651 aarectangle
const& clipping_rectangle,
652 matrix3
const& transform,
653 text_shaper
const& text,
654 text_selection
const& selection,
655 hi::color)
const noexcept;
657 void _draw_text_insertion_cursor_empty(
658 aarectangle
const& clipping_rectangle,
659 matrix3
const& transform,
660 text_shaper
const& text,
661 hi::color color)
const noexcept;
663 void _draw_text_insertion_cursor(
664 aarectangle
const& clipping_rectangle,
665 matrix3
const& transform,
666 text_shaper
const& text,
669 bool show_flag)
const noexcept;
671 void _draw_text_overwrite_cursor(
672 aarectangle
const& clipping_rectangle,
673 matrix3
const& transform,
674 text_shaper::char_const_iterator it,
675 hi::color color)
const noexcept;
677 void _draw_text_cursors(
678 aarectangle
const& clipping_rectangle,
679 matrix3
const& transform,
680 text_shaper
const& text,
682 hi::color primary_color,
683 hi::color secondary_color,
685 bool dead_character_mode)
const noexcept;
687 void _draw_glyph(aarectangle
const& clipping_rectangle, quad
const& box, quad_color
const& color, glyph_ids
const& glyph)
690 [[nodiscard]]
bool _draw_image(aarectangle
const& clipping_rectangle, quad
const& box, paged_image& image)
const noexcept;
#define hi_assert(expression)
Assert if expression is true.
Definition assert.hpp:86
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
@ rectangle
The gui_event has rectangle data.
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:545
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:192
float saturation
The tone-mapper's saturation.
Definition draw_context.hpp:78
utc_nanoseconds display_time_point
The time when the drawing will appear on the screen.
Definition draw_context.hpp:82
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:513
void draw_text(widget_layout const &layout, matrix3 const &transform, shaped_text const &text) const noexcept
Draw shaped text.
Definition draw_context.hpp:476
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:403
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:584
void draw_text(widget_layout const &layout, quad_color const &color, text_shaper const &text) const noexcept
Draw shaped text.
Definition draw_context.hpp:500
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:568
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:429
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:446
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:215
void make_hole(widget_layout const &layout, quad const &box) const noexcept
Make a hole in the user interface.
Definition draw_context.hpp:612
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:416
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:488
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:114
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:530
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:460
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:155
bool active
Window is active.
Definition draw_context.hpp:74
void draw_text(widget_layout const &layout, text_shaper const &text) const noexcept
Draw shaped text.
Definition draw_context.hpp:555
bool draw_image(widget_layout const &layout, quad const &box, paged_image &image) const noexcept
Draw an image.
Definition draw_context.hpp:388
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