7#include "pipeline_box_vertex.hpp"
8#include "pipeline_image_vertex.hpp"
9#include "pipeline_SDF_vertex.hpp"
10#include "pipeline_alpha_vertex.hpp"
16#include "../geometry/transform.hpp"
19#include "../unicode/unicode_bidi_class.hpp"
20#include "../text/text_cursor.hpp"
21#include "../text/text_selection.hpp"
22#include "../text/text_shaper.hpp"
23#include "../color/color.hpp"
24#include "../color/quad_color.hpp"
26#include "../vector_span.hpp"
27#include "../concepts.hpp"
29namespace hi::inline
v1 {
31class gfx_device_vulkan;
51template<
typename Context>
52concept draw_attribute = std::same_as<Context, quad_color> or std::same_as<Context, color> or
53 std::same_as<Context, border_side> or std::same_as<Context, line_end_cap> or std::same_as<Context, corner_radii> or
54 std::same_as<Context, aarectanglei> or std::same_as<Context, float> or std::same_as<Context, int>;
57 unsigned char num_colors = 0;
58 unsigned char num_line_caps = 0;
62 float line_width = 0.0f;
65 aarectanglei clipping_rectangle = aarectanglei::large();
66 line_end_cap begin_line_cap = line_end_cap::flat;
67 line_end_cap end_line_cap = line_end_cap::flat;
81 constexpr void add()
noexcept {}
83 template<draw_attribute T>
84 constexpr void add(T
const& attribute)
noexcept
86 if constexpr (std::is_same_v<T, quad_color>) {
87 if (num_colors++ == 0) {
88 fill_color = attribute;
90 line_color = attribute;
94 }
else if constexpr (std::is_same_v<T, color>) {
95 if (num_colors++ == 0) {
102 }
else if constexpr (std::is_same_v<T, line_end_cap>) {
103 if (num_line_caps++ == 0) {
104 begin_line_cap = attribute;
105 end_line_cap = attribute;
107 end_line_cap = attribute;
111 }
else if constexpr (std::is_same_v<T, hi::border_side>) {
115 _has_border_side =
true;
118 }
else if constexpr (std::is_same_v<T, corner_radii>) {
119 corner_radius = attribute;
122 _has_corner_radii =
true;
125 }
else if constexpr (std::is_same_v<T, aarectanglei>) {
126 clipping_rectangle = attribute;
129 _has_clipping_rectangle =
true;
132 }
else if constexpr (std::is_same_v<T, float> or std::is_same_v<T, int>) {
133 line_width = narrow_cast<float>(attribute);
136 _has_line_width =
true;
144 constexpr void add(First
const& first, Second
const& second, Rest
const&...rest)
noexcept
147 add(second, rest...);
152 bool _has_border_side =
false;
153 bool _has_corner_radii =
false;
154 bool _has_clipping_rectangle =
false;
155 bool _has_line_width =
false;
159template<
typename Context>
160concept draw_quad_shape = std::same_as<Context, quad> or std::same_as<Context, rectangle> or std::same_as<Context, aarectangle> or
161 std::same_as<Context, aarectanglei>;
212 operator bool() const noexcept
230 layout.clipping_rectangle_on_window(attributes.clipping_rectangle), layout.to_window3() * box, attributes);
234 void draw_box(widget_layout
const& layout, Shape
const& shape, Attributes
const&...attributes)
const noexcept
236 return draw_box(layout, make_quad(shape),
draw_attributes{attributes...});
239 void draw_line(widget_layout
const& layout, line_segment
const& line, draw_attributes
const& attributes)
const noexcept
242 make_rectangle(line, attributes.line_width, attributes.begin_line_cap, attributes.end_line_cap);
244 auto box_attributes = attributes;
245 box_attributes.line_width = 0.0f;
246 box_attributes.fill_color = attributes.line_color;
247 box_attributes.corner_radius =
248 make_corner_radii(attributes.line_width, attributes.begin_line_cap, attributes.end_line_cap);
249 return draw_box(layout, box, box_attributes);
252 template<draw_attribute... Attributes>
253 void draw_line(widget_layout
const& layout, line_segment
const& line, Attributes
const&...attributes)
const noexcept
255 return draw_line(layout, line, draw_attributes{attributes...});
258 void draw_circle(widget_layout
const& layout,
hi::circle const& circle, draw_attributes
const& attributes)
const noexcept
260 auto box_attributes = attributes;
261 box_attributes.corner_radius = make_corner_radii(circle);
262 return draw_box(layout, make_rectangle(circle), box_attributes);
265 template<draw_attribute... Attributes>
266 void draw_circle(widget_layout
const& layout,
hi::circle const& circle, Attributes
const&...attributes)
const noexcept
268 return draw_circle(layout, circle, draw_attributes{attributes...});
282 return _draw_image(layout.clipping_rectangle_on_window(attributes.clipping_rectangle), layout.to_window3() * box, image);
298 return draw_image(layout, make_quad(box), image,
draw_attributes{attributes...});
313 layout.clipping_rectangle_on_window(attributes.clipping_rectangle), layout.to_window3() * box, glyph, attributes);
325 void draw_glyph(widget_layout
const& layout, Shape
const& box,
glyph_ids const& glyph, Attributes
const&...attributes)
328 return draw_glyph(layout, make_quad(box), glyph,
draw_attributes{attributes...});
343 layout.clipping_rectangle_on_window(attributes.clipping_rectangle),
344 layout.to_window3() * transform,
384 widget_layout
const& layout,
389 return _draw_text_selection(
390 layout.clipping_rectangle_on_window(attributes.clipping_rectangle), layout.to_window3(),
text, selection, attributes);
402 widget_layout
const& layout,
405 Attributes
const&...attributes)
const noexcept
421 widget_layout
const& layout,
425 bool dead_character_mode,
428 return _draw_text_cursors(
429 layout.clipping_rectangle_on_window(attributes.clipping_rectangle),
450 widget_layout
const& layout,
454 bool dead_character_mode,
455 Attributes
const&...attributes)
const noexcept
457 return draw_text_cursors(layout,
text, cursor, overwrite_mode, dead_character_mode,
draw_attributes{attributes...});
470 return _override_alpha(
471 layout.clipping_rectangle_on_window(attributes.clipping_rectangle), layout.to_window3() * box, attributes);
483 void draw_hole(widget_layout
const& layout, Shape
const& box, Attributes
const&...attributes)
const noexcept
485 return draw_hole(layout, make_quad(box),
draw_attributes{attributes...});
488 [[nodiscard]]
friend bool overlaps(
draw_context const& context, widget_layout
const& layout)
noexcept
490 return overlaps(context.scissor_rectangle, layout.clipping_rectangle_on_window());
494 vector_span<pipeline_box::vertex> *_box_vertices;
495 vector_span<pipeline_image::vertex> *_image_vertices;
496 vector_span<pipeline_SDF::vertex> *_sdf_vertices;
497 vector_span<pipeline_alpha::vertex> *_alpha_vertices;
499 template<draw_quad_shape Shape>
500 [[nodiscard]]
constexpr static quad make_quad(Shape
const& shape)
noexcept
502 if constexpr (std::is_same_v<Shape, aarectanglei>) {
503 return narrow_cast<aarectangle>(shape);
510 make_rectangle(line_segment
const& line,
float width, line_end_cap c1, line_end_cap c2)
noexcept
512 auto right = line.direction();
514 hilet radius = width * 0.5f;
515 hilet n = normal(right, 0.0f);
517 hilet t = normalize(right);
519 auto origin = line.origin() -
n * radius;
522 hilet radius_offset = t * radius;
523 if (c1 == line_end_cap::round) {
524 origin -= radius_offset;
525 right += radius_offset;
527 if (c2 == line_end_cap::round) {
528 right += radius_offset;
537 hilet origin = point3{circle_.xyz1() - circle_.ww00()};
539 hilet up = vector3{circle_._0w00() * 2.0f};
543 [[nodiscard]]
constexpr static corner_radii make_corner_radii(
float width, line_end_cap c1, line_end_cap c2)
noexcept
545 auto r = f32x4::broadcast(width * 0.5f);
547 if (c1 == line_end_cap::flat) {
550 if (c2 == line_end_cap::flat) {
554 return corner_radii{r};
557 [[nodiscard]]
constexpr static corner_radii make_corner_radii(
hi::circle const& circle)
noexcept
559 return corner_radii{f32x4{
circle}.wwww()};
562 void _override_alpha(aarectanglei
const& clipping_rectangle, quad box, draw_attributes
const& attributes)
const noexcept;
564 void _draw_box(aarectanglei
const& clipping_rectangle, quad box, draw_attributes
const& attributes)
const noexcept;
567 aarectanglei
const& clipping_rectangle,
568 matrix3
const& transform,
569 text_shaper
const& text,
570 draw_attributes
const& attributes)
const noexcept;
572 void _draw_text_selection(
573 aarectanglei
const& clipping_rectangle,
574 matrix3
const& transform,
575 text_shaper
const& text,
576 text_selection
const& selection,
577 draw_attributes
const& attributes)
const noexcept;
579 void _draw_text_insertion_cursor_empty(
580 aarectanglei
const& clipping_rectangle,
581 matrix3
const& transform,
582 text_shaper
const& text,
583 draw_attributes
const& attributes)
const noexcept;
585 void _draw_text_insertion_cursor(
586 aarectanglei
const& clipping_rectangle,
587 matrix3
const& transform,
588 text_shaper
const& text,
591 draw_attributes
const& attributes)
const noexcept;
593 void _draw_text_overwrite_cursor(
594 aarectanglei
const& clipping_rectangle,
595 matrix3
const& transform,
596 text_shaper::char_const_iterator it,
597 draw_attributes
const& attributes)
const noexcept;
599 void _draw_text_cursors(
600 aarectanglei
const& clipping_rectangle,
601 matrix3
const& transform,
602 text_shaper
const& text,
605 bool dead_character_mode,
606 draw_attributes
const& attributes)
const noexcept;
609 aarectanglei
const& clipping_rectangle,
611 glyph_ids
const& glyph,
612 draw_attributes
const& attributes)
const noexcept;
614 [[nodiscard]]
bool _draw_image(aarectanglei
const& clipping_rectangle, quad
const& box, paged_image& image)
const noexcept;
#define hi_static_no_default(...)
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:181
#define hi_assert(expression,...)
Assert if expression is true.
Definition assert.hpp:87
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:133
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
Defined the corner_radii type.
Defines geo::matrix, matrix2 and matrix3.
@ 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:37
@ 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
A type defining a 2D circle.
Definition circle.hpp:19
The 4 radiuses of the corners of a quad or rectangle.
Definition corner_radii.hpp:17
Definition draw_context.hpp:56
Draw context for drawing using the HikoGUI shaders.
Definition draw_context.hpp:165
void draw_text_cursors(widget_layout const &layout, text_shaper const &text, text_cursor cursor, bool overwrite_mode, bool dead_character_mode, Attributes const &...attributes) const noexcept
Draw text cursors of shaped text.
Definition draw_context.hpp:449
std::size_t frame_buffer_index
The frame buffer index of the image we are currently rendering.
Definition draw_context.hpp:171
bool draw_image(widget_layout const &layout, quad const &box, paged_image &image, draw_attributes const &attributes) const noexcept
Draw an image.
Definition draw_context.hpp:280
void draw_box(widget_layout const &layout, quad const &box, draw_attributes const &attributes) const noexcept
Draw a box with rounded corners.
Definition draw_context.hpp:227
float saturation
The tone-mapper's saturation.
Definition draw_context.hpp:191
utc_nanoseconds display_time_point
The time when the drawing will appear on the screen.
Definition draw_context.hpp:195
void draw_text(widget_layout const &layout, matrix3 const &transform, text_shaper const &text, Attributes const &...attributes) const noexcept
Draw shaped text.
Definition draw_context.hpp:357
void draw_glyph(widget_layout const &layout, Shape const &box, glyph_ids const &glyph, Attributes const &...attributes) const noexcept
Draw a glyph.
Definition draw_context.hpp:325
void draw_text_selection(widget_layout const &layout, text_shaper const &text, text_selection const &selection, Attributes const &...attributes) const noexcept
Draw text-selection of shaped text.
Definition draw_context.hpp:401
void draw_glyph(widget_layout const &layout, quad const &box, glyph_ids const &glyph, draw_attributes const &attributes) const noexcept
Draw a glyph.
Definition draw_context.hpp:309
color background_color
The background color to clear the window with.
Definition draw_context.hpp:179
aarectanglei scissor_rectangle
This is the rectangle of the window that is being redrawn.
Definition draw_context.hpp:175
void draw_hole(widget_layout const &layout, Shape const &box, Attributes const &...attributes) const noexcept
Make a hole in the user interface.
Definition draw_context.hpp:483
void draw_text_cursors(widget_layout const &layout, text_shaper const &text, text_cursor cursor, bool overwrite_mode, bool dead_character_mode, draw_attributes const &attributes) const noexcept
Draw text cursors of shaped text.
Definition draw_context.hpp:420
bool draw_image(widget_layout const &layout, draw_quad_shape auto const &box, paged_image &image, Attributes const &...attributes) const noexcept
Draw an image.
Definition draw_context.hpp:295
void draw_text(widget_layout const &layout, matrix3 const &transform, text_shaper const &text, draw_attributes const &attributes) const noexcept
Draw shaped text.
Definition draw_context.hpp:339
void draw_text_selection(widget_layout const &layout, text_shaper const &text, text_selection const &selection, draw_attributes const &attributes) const noexcept
Draw text-selection of shaped text.
Definition draw_context.hpp:383
hi::subpixel_orientation subpixel_orientation
The subpixel orientation for rendering glyphs.
Definition draw_context.hpp:183
void draw_text(widget_layout const &layout, text_shaper const &text, Attributes const &...attributes) const noexcept
Draw shaped text.
Definition draw_context.hpp:371
bool active
Window is active.
Definition draw_context.hpp:187
void draw_hole(widget_layout const &layout, quad const &box, draw_attributes const &attributes) const noexcept
Make a hole in the user interface.
Definition draw_context.hpp:468
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:41
Definition vector_span.hpp:134
Definition draw_context.hpp:52
Definition draw_context.hpp:160