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"
24#include "../widgets/widget_layout.hpp"
25#include "../vector_span.hpp"
27namespace hi::inline v1 {
29class gfx_device_vulkan;
36enum class border_side {
95 operator bool() const noexcept
116 hi::border_side border_side,
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 :
157 hi::border_side border_side,
158 hi::corner_radii
const& corner_radius = {})
const noexcept
161 hilet border_radius = border_width * 0.5f;
163 border_side == hi::border_side::inside ? box - border_radius :
164 border_side == hi::border_side::outside ? box + border_radius :
166 hilet corner_radius_ =
167 border_side == hi::border_side::inside ? corner_radius - border_radius :
168 border_side == hi::border_side::outside ? corner_radius + border_radius :
191 hi::corner_radii
const& corner_radius = {})
const noexcept
215 hi::corner_radii
const& corner_radius = {})
const noexcept
226 [[nodiscard]]
constexpr static rectangle
227 make_rectangle(line_segment
const& line,
float width, line_end_cap c1, line_end_cap c2)
noexcept
229 auto right = line.direction();
231 hilet radius = width * 0.5f;
232 hilet n = normal(right, 0.0f);
233 hilet up = n * width;
234 hilet t = normalize(right);
236 auto origin = line.origin() - n * radius;
239 hilet radius_offset = t * radius;
240 if (c1 == line_end_cap::round) {
241 origin -= radius_offset;
242 right += radius_offset;
244 if (c2 == line_end_cap::round) {
245 right += radius_offset;
248 return rectangle{origin,
right, up};
251 [[nodiscard]]
constexpr static corner_radii make_corner_radii(
float width, line_end_cap c1, line_end_cap c2)
noexcept
253 auto r = f32x4::broadcast(width * 0.5f);
255 if (c1 == line_end_cap::flat) {
258 if (c2 == line_end_cap::flat) {
262 return corner_radii{r};
266 widget_layout
const& layout,
267 line_segment
const& line,
269 quad_color
const& fill_color,
270 line_end_cap c1 = line_end_cap::flat,
271 line_end_cap c2 = line_end_cap::flat)
const noexcept
276 hilet box = make_rectangle(line_, width_, c1, c2);
277 hilet corners = make_corner_radii(width_, c1, c2);
283 widget_layout
const& layout,
284 aarectangle
const& clipping_rectangle,
285 line_segment
const& line,
287 quad_color
const& fill_color,
288 line_end_cap c1 = line_end_cap::flat,
289 line_end_cap c2 = line_end_cap::flat)
const noexcept
291 hi_axiom(width != 0.0f);
295 hilet box = make_rectangle(line_, width_, c1, c2);
296 hilet corners = make_corner_radii(width_, c1, c2);
301 [[nodiscard]]
constexpr static rectangle make_rectangle(hi::circle
const& circle)
noexcept
303 hilet circle_ = f32x4{circle};
304 hilet origin = point3{circle_.xyz1() - circle_.ww00()};
306 hilet up = vector3{circle_._0w00() * 2.0f};
307 return rectangle{origin,
right, up};
310 [[nodiscard]]
constexpr static corner_radii make_corner_radii(hi::circle
const& circle)
noexcept
312 return corner_radii{f32x4{circle}.wwww()};
315 void draw_circle(widget_layout
const& layout, hi::circle
const& circle, quad_color
const& fill_color)
const noexcept
323 widget_layout
const& layout,
324 aarectangle
const clipping_rectangle,
325 hi::circle
const& circle,
326 quad_color
const& fill_color)
const
328 hilet box = layout.to_window * make_rectangle(circle);
329 hilet corners = layout.to_window * make_corner_radii(circle);
330 return _draw_box(layout.window_clipping_rectangle(clipping_rectangle), box, fill_color, fill_color, 0.0f, corners);
334 widget_layout
const& layout,
335 hi::circle
const& circle,
336 quad_color
const& fill_color,
337 quad_color
const& border_color,
339 hi::border_side border_side)
const noexcept
343 border_side == hi::border_side::inside ? circle - border_width * 0.5f :
344 border_side == hi::border_side::outside ? circle + border_width * 0.5f :
354 widget_layout
const& layout,
355 aarectangle
const& clipping_rectangle,
356 hi::circle
const& circle,
357 quad_color
const& fill_color,
358 quad_color
const& border_color,
360 hi::border_side border_side)
const noexcept
364 border_side == hi::border_side::inside ? circle - border_width * 0.5f :
365 border_side == hi::border_side::outside ? circle + border_width * 0.5f :
429 glyph_ids
const& glyph)
const noexcept
460 shaped_text
const& text)
const noexcept
583 hi::color primary_color,
584 hi::color secondary_color,
586 bool dead_character_mode)
const noexcept
588 return _draw_text_cursors(
596 dead_character_mode);
618 vector_span<pipeline_box::vertex> *_box_vertices;
619 vector_span<pipeline_image::vertex> *_image_vertices;
620 vector_span<pipeline_SDF::vertex> *_sdf_vertices;
621 vector_span<pipeline_alpha::vertex> *_alpha_vertices;
623 void _override_alpha(aarectangle
const& clipping_rectangle, quad box,
float alpha)
const noexcept;
626 aarectangle
const& clipping_rectangle,
628 quad_color
const& fill_color,
629 quad_color
const& border_color,
631 hi::corner_radii corner_radius)
const noexcept;
634 aarectangle
const& clipping_rectangle,
635 matrix3
const& transform,
636 shaped_text
const& text,
637 std::optional<quad_color> color = {})
const noexcept;
640 aarectangle
const& clipping_rectangle,
641 matrix3
const& transform,
642 text_shaper
const& text,
643 std::optional<quad_color> color = {})
const noexcept;
645 void _draw_text_selection(
646 aarectangle
const& clipping_rectangle,
647 matrix3
const& transform,
648 text_shaper
const& text,
649 text_selection
const& selection,
650 hi::color)
const noexcept;
652 void _draw_text_insertion_cursor_empty(
653 aarectangle
const& clipping_rectangle,
654 matrix3
const& transform,
655 text_shaper
const& text,
656 hi::color color)
const noexcept;
658 void _draw_text_insertion_cursor(
659 aarectangle
const& clipping_rectangle,
660 matrix3
const& transform,
661 text_shaper
const& text,
664 bool show_flag)
const noexcept;
666 void _draw_text_overwrite_cursor(
667 aarectangle
const& clipping_rectangle,
668 matrix3
const& transform,
669 text_shaper::char_const_iterator it,
670 hi::color color)
const noexcept;
672 void _draw_text_cursors(
673 aarectangle
const& clipping_rectangle,
674 matrix3
const& transform,
675 text_shaper
const& text,
677 hi::color primary_color,
678 hi::color secondary_color,
680 bool dead_character_mode)
const noexcept;
682 void _draw_glyph(aarectangle
const& clipping_rectangle, quad
const& box, quad_color
const& color, glyph_ids
const& glyph)
685 [[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:39
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: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:540
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:187
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:508
void draw_text(widget_layout const &layout, matrix3 const &transform, shaped_text const &text) const noexcept
Draw shaped text.
Definition draw_context.hpp:471
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:398
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:579
void draw_text(widget_layout const &layout, quad_color const &color, text_shaper const &text) const noexcept
Draw shaped text.
Definition draw_context.hpp:495
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:563
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:424
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:441
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:210
void make_hole(widget_layout const &layout, quad const &box) const noexcept
Make a hole in the user interface.
Definition draw_context.hpp:607
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:411
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:483
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:525
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:455
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:150
void draw_text(widget_layout const &layout, text_shaper const &text) const noexcept
Draw shaped text.
Definition draw_context.hpp:550
bool draw_image(widget_layout const &layout, quad const &box, paged_image &image) const noexcept
Draw an image.
Definition draw_context.hpp:383
Definition gfx_device_vulkan.hpp:21
This is a image that is uploaded into the texture atlas.
Definition paged_image.hpp:25
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
Definition widget_layout.hpp:18
constexpr aarectangle window_clipping_rectangle() const noexcept
Get the clipping rectangle in window coordinate system.
Definition widget_layout.hpp:113
matrix3 to_window
This matrix transforms local coordinates to window coordinates.
Definition widget_layout.hpp:36