7#include "pipeline_box_vertex.hpp"
8#include "pipeline_image_vertex.hpp"
9#include "pipeline_SDF_vertex.hpp"
10#include "pipeline_alpha_vertex.hpp"
11#include "../settings/module.hpp"
12#include "../geometry/module.hpp"
13#include "../unicode/module.hpp"
14#include "../text/module.hpp"
15#include "../color/module.hpp"
16#include "../container/module.hpp"
17#include "../utility/module.hpp"
19namespace hi {
inline namespace v1 {
21class gfx_device_vulkan;
42template<
typename Context>
43concept draw_attribute = std::same_as<Context, quad_color> or std::same_as<Context, color> or
44 std::same_as<Context, border_side> or std::same_as<Context, line_end_cap> or std::same_as<Context, corner_radii> or
45 std::same_as<Context, aarectangle> or std::same_as<Context, float> or std::same_as<Context, int>;
50 unsigned char num_colors = 0;
51 unsigned char num_line_caps = 0;
125 constexpr void add() noexcept {}
127 template<draw_attribute T>
128 constexpr void add(T
const& attribute)
noexcept
130 if constexpr (std::is_same_v<T, quad_color>) {
131 if (num_colors++ == 0) {
138 }
else if constexpr (std::is_same_v<T, color>) {
139 if (num_colors++ == 0) {
146 }
else if constexpr (std::is_same_v<T, line_end_cap>) {
147 if (num_line_caps++ == 0) {
155 }
else if constexpr (std::is_same_v<T, hi::border_side>) {
159 _has_border_side =
true;
162 }
else if constexpr (std::is_same_v<T, corner_radii>) {
166 _has_corner_radii =
true;
169 }
else if constexpr (std::is_same_v<T, aarectangle>) {
173 _has_clipping_rectangle =
true;
176 }
else if constexpr (std::is_same_v<T, float> or std::is_same_v<T, int>) {
180 _has_line_width =
true;
187 template<draw_attribute First, draw_attribute Second, draw_attribute... Rest>
188 constexpr void add(First
const& first, Second
const& second, Rest
const&...rest)
noexcept
191 add(second, rest...);
196 bool _has_border_side =
false;
197 bool _has_corner_radii =
false;
198 bool _has_clipping_rectangle =
false;
199 bool _has_line_width =
false;
203template<
typename Context>
204concept draw_quad_shape = std::same_as<Context, quad> or std::same_as<Context, rectangle> or std::same_as<Context, aarectangle> or
205 std::same_as<Context, aarectangle>;
211 gfx_device_vulkan& device;
244 gfx_device_vulkan& device,
245 vector_span<pipeline_box::vertex>& box_vertices,
246 vector_span<pipeline_image::vertex>& image_vertices,
247 vector_span<pipeline_SDF::vertex>& sdf_vertices,
248 vector_span<pipeline_alpha::vertex>& alpha_vertices)
noexcept;
252 operator bool() const noexcept
263 template<std::same_as<w
idget_layout> W
idgetLayout>
267 layout.clipping_rectangle_on_window(attributes.clipping_rectangle), layout.to_window3() * box, attributes);
276 template<std::same_as<w
idget_layout> W
idgetLayout, draw_quad_shape Shape, draw_attribute... Attributes>
277 void draw_box(WidgetLayout
const& layout, Shape
const& shape, Attributes
const&...attributes)
const noexcept
288 template<std::same_as<w
idget_layout> W
idgetLayout>
291 hilet box = make_rectangle(line, attributes.line_width, attributes.begin_line_cap, attributes.end_line_cap);
293 auto box_attributes = attributes;
294 box_attributes.line_width = 0.0f;
295 box_attributes.corner_radius =
296 make_corner_radii(attributes.line_width, attributes.begin_line_cap, attributes.end_line_cap);
297 return draw_box(layout, box, box_attributes);
306 template<std::same_as<w
idget_layout> W
idgetLayout, draw_attribute... Attributes>
318 template<std::same_as<w
idget_layout> W
idgetLayout>
321 auto box_attributes = attributes;
322 box_attributes.corner_radius = make_corner_radii(
circle);
332 template<std::same_as<w
idget_layout> W
idgetLayout, draw_attribute... Attributes>
347 template<std::same_as<w
idget_layout> W
idgetLayout>
351 return _draw_image(layout.clipping_rectangle_on_window(attributes.clipping_rectangle), layout.to_window3() * box, image);
363 template<std::same_as<w
idget_layout> W
idgetLayout, draw_attribute... Attributes>
378 template<std::same_as<w
idget_layout> W
idgetLayout>
383 layout.clipping_rectangle_on_window(attributes.clipping_rectangle), layout.to_window3() * box, glyph, attributes);
393 template<std::same_as<w
idget_layout> W
idgetLayout, draw_quad_shape Shape, draw_attribute... Attributes>
394 void draw_glyph(WidgetLayout
const& layout, Shape
const& box, glyph_ids
const& glyph, Attributes
const&...attributes)
407 template<std::same_as<w
idget_layout> W
idgetLayout>
413 layout.clipping_rectangle_on_window(attributes.clipping_rectangle),
414 layout.to_window3() * transform,
426 template<std::same_as<w
idget_layout> W
idgetLayout, draw_attribute... Attributes>
427 void draw_text(WidgetLayout
const& layout,
matrix3 const& transform, text_shaper
const& text, Attributes
const&...attributes)
439 template<std::same_as<w
idget_layout> W
idgetLayout, draw_attribute... Attributes>
440 void draw_text(WidgetLayout
const& layout, text_shaper
const& text, Attributes
const&...attributes)
const noexcept
452 template<std::same_as<w
idget_layout> W
idgetLayout>
454 WidgetLayout
const& layout,
455 text_shaper
const& text,
456 text_selection
const& selection,
459 return _draw_text_selection(
460 layout.clipping_rectangle_on_window(attributes.clipping_rectangle), layout.to_window3(), text, selection, attributes);
470 template<std::same_as<w
idget_layout> W
idgetLayout, draw_attribute... Attributes>
472 WidgetLayout
const& layout,
473 text_shaper
const& text,
474 text_selection
const& selection,
475 Attributes
const&...attributes)
const noexcept
489 template<std::same_as<w
idget_layout> W
idgetLayout>
491 WidgetLayout
const& layout,
492 text_shaper
const& text,
495 bool dead_character_mode,
498 return _draw_text_cursors(
499 layout.clipping_rectangle_on_window(attributes.clipping_rectangle),
517 template<std::same_as<w
idget_layout> W
idgetLayout, draw_attribute... Attributes>
519 WidgetLayout
const& layout,
520 text_shaper
const& text,
523 bool dead_character_mode,
524 Attributes
const&...attributes)
const noexcept
538 template<std::same_as<w
idget_layout> W
idgetLayout>
541 return _override_alpha(
542 layout.clipping_rectangle_on_window(attributes.clipping_rectangle), layout.to_window3() * box, attributes);
554 template<std::same_as<w
idget_layout> W
idgetLayout, draw_quad_shape Shape, draw_attribute... Attributes>
555 void draw_hole(WidgetLayout
const& layout, Shape
const& box, Attributes
const&...attributes)
const noexcept
567 template<std::same_as<w
idget_layout> W
idgetLayout>
570 return overlaps(context.scissor_rectangle, layout.clipping_rectangle_on_window());
574 vector_span<pipeline_box::vertex> *_box_vertices;
575 vector_span<pipeline_image::vertex> *_image_vertices;
576 vector_span<pipeline_SDF::vertex> *_sdf_vertices;
577 vector_span<pipeline_alpha::vertex> *_alpha_vertices;
579 template<draw_quad_shape Shape>
580 [[nodiscard]]
constexpr static quad make_quad(Shape
const& shape)
noexcept
582 if constexpr (std::is_same_v<Shape, quad>) {
592 auto right = line.direction();
594 hilet radius = width * 0.5f;
596 hilet up = n * width;
599 auto origin = line.origin() - n * radius;
602 hilet radius_offset = t * radius;
604 origin -= radius_offset;
605 right += radius_offset;
608 right += radius_offset;
616 hilet circle_ = f32x4{circle};
617 hilet origin = point3{circle_.xyz1() - circle_.ww00()};
619 hilet up = vector3{circle_._0w00() * 2.0f};
623 [[nodiscard]]
constexpr static corner_radii make_corner_radii(
float width,
line_end_cap c1,
line_end_cap c2)
noexcept
625 auto r = f32x4::broadcast(width * 0.5f);
628 r = set_zero<0b0101>(r);
631 r = set_zero<0b1010>(r);
634 return corner_radii{r};
637 [[nodiscard]]
constexpr static corner_radii make_corner_radii(
hi::circle const& circle)
noexcept
639 return corner_radii{f32x4{circle}.wwww()};
642 void _override_alpha(aarectangle
const& clipping_rectangle, quad box, draw_attributes
const& attributes)
const noexcept;
644 void _draw_box(aarectangle
const& clipping_rectangle, quad box, draw_attributes
const& attributes)
const noexcept;
647 aarectangle
const& clipping_rectangle,
648 matrix3
const& transform,
649 text_shaper
const& text,
650 draw_attributes
const& attributes)
const noexcept;
652 void _draw_text_selection(
653 aarectangle
const& clipping_rectangle,
654 matrix3
const& transform,
655 text_shaper
const& text,
656 text_selection
const& selection,
657 draw_attributes
const& attributes)
const noexcept;
659 void _draw_text_insertion_cursor_empty(
660 aarectangle
const& clipping_rectangle,
661 matrix3
const& transform,
662 text_shaper
const& text,
663 draw_attributes
const& attributes)
const noexcept;
665 void _draw_text_insertion_cursor(
666 aarectangle
const& clipping_rectangle,
667 matrix3
const& transform,
668 text_shaper
const& text,
671 draw_attributes
const& attributes)
const noexcept;
673 void _draw_text_overwrite_cursor(
674 aarectangle
const& clipping_rectangle,
675 matrix3
const& transform,
676 text_shaper::char_const_iterator it,
677 draw_attributes
const& attributes)
const noexcept;
679 void _draw_text_cursors(
680 aarectangle
const& clipping_rectangle,
681 matrix3
const& transform,
682 text_shaper
const& text,
685 bool dead_character_mode,
686 draw_attributes
const& attributes)
const noexcept;
689 _draw_glyph(aarectangle
const& clipping_rectangle, quad
const& box, glyph_ids
const& glyph, draw_attributes
const& attributes)
693 _draw_image(aarectangle
const& clipping_rectangle, quad
const& box, paged_image
const& image)
const noexcept;
#define hi_static_no_default(...)
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:323
#define hi_assert(expression,...)
Assert if expression is true.
Definition assert.hpp:199
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
line_end_cap
The way two lines should be joined.
Definition line_end_cap.hpp:17
@ right
Align the text to the right side.
@ flat
The end cap of the line is flat.
@ round
The end cap of the line is round.
@ rectangle
The gui_event has rectangle data.
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
border_side
The side where the border is drawn.
Definition draw_context.hpp:28
@ 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.
A color for each corner of a quad.
Definition quad_color.hpp:19
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:26
static constexpr aarectangle large() noexcept
Create a large axis aligned rectangle.
Definition aarectangle.hpp:39
A type defining a 2D circle.
Definition circle.hpp:18
The 4 radii of the corners of a quad or rectangle.
Definition corner_radii.hpp:18
Line segment.
Definition line_segment.hpp:20
A 2D or 3D homogenius matrix for transforming homogenious vectors and points.
Definition matrix3.hpp:29
The draw attributes used to draw shaped into the draw context.
Definition draw_context.hpp:49
aarectangle clipping_rectangle
The rectangle used the clip the shape when drawing.
Definition draw_context.hpp:83
hi::border_side border_side
The side on which side of the edge of a shape the border should be drawn.
Definition draw_context.hpp:72
float line_width
The width of a line, or the width of a border.
Definition draw_context.hpp:68
line_end_cap end_line_cap
The shape of the beginning of a line.
Definition draw_context.hpp:91
quad_color fill_color
The fill color used for the color of a box inside the border.
Definition draw_context.hpp:58
quad_color line_color
The line color used for the color of the border of the box.
Definition draw_context.hpp:64
line_end_cap begin_line_cap
The shape of the beginning of a line.
Definition draw_context.hpp:87
hi::corner_radii corner_radius
The radii of each corner of a quad.
Definition draw_context.hpp:76
Draw context for drawing using the HikoGUI shaders.
Definition draw_context.hpp:209
bool draw_image(WidgetLayout const &layout, draw_quad_shape auto const &box, paged_image &image, Attributes const &...attributes) const noexcept
Draw an image.
Definition draw_context.hpp:365
void draw_text(WidgetLayout const &layout, text_shaper const &text, Attributes const &...attributes) const noexcept
Draw shaped text.
Definition draw_context.hpp:440
void draw_circle(WidgetLayout const &layout, hi::circle const &circle, Attributes const &...attributes) const noexcept
Draw a circle.
Definition draw_context.hpp:333
void draw_text_cursors(WidgetLayout 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:518
hi::subpixel_orientation subpixel_orientation
The subpixel orientation for rendering glyphs.
Definition draw_context.hpp:223
friend bool overlaps(draw_context const &context, WidgetLayout const &layout) noexcept
Checks if a widget's layout overlaps with the part of the window that is being drawn.
Definition draw_context.hpp:568
void draw_box(WidgetLayout const &layout, Shape const &shape, Attributes const &...attributes) const noexcept
Draw a box.
Definition draw_context.hpp:277
void draw_circle(WidgetLayout const &layout, hi::circle const &circle, draw_attributes const &attributes) const noexcept
Draw a circle.
Definition draw_context.hpp:319
float saturation
The tone-mapper's saturation.
Definition draw_context.hpp:231
void draw_text(WidgetLayout const &layout, matrix3 const &transform, text_shaper const &text, Attributes const &...attributes) const noexcept
Draw shaped text.
Definition draw_context.hpp:427
bool active
Window is active.
Definition draw_context.hpp:227
bool draw_image(WidgetLayout const &layout, quad const &box, paged_image &image, draw_attributes const &attributes) const noexcept
Draw an image.
Definition draw_context.hpp:349
void draw_text_selection(WidgetLayout 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:453
aarectangle scissor_rectangle
This is the rectangle of the window that is being redrawn.
Definition draw_context.hpp:219
void draw_glyph(WidgetLayout const &layout, quad const &box, glyph_ids const &glyph, draw_attributes const &attributes) const noexcept
Draw a glyph.
Definition draw_context.hpp:379
void draw_line(WidgetLayout const &layout, line_segment const &line, Attributes const &...attributes) const noexcept
Draw a line.
Definition draw_context.hpp:307
void draw_glyph(WidgetLayout const &layout, Shape const &box, glyph_ids const &glyph, Attributes const &...attributes) const noexcept
Draw a glyph.
Definition draw_context.hpp:394
std::size_t frame_buffer_index
The frame buffer index of the image we are currently rendering.
Definition draw_context.hpp:215
void draw_hole(WidgetLayout const &layout, quad const &box, draw_attributes const &attributes) const noexcept
Make a hole in the user interface.
Definition draw_context.hpp:539
void draw_hole(WidgetLayout const &layout, Shape const &box, Attributes const &...attributes) const noexcept
Make a hole in the user interface.
Definition draw_context.hpp:555
void draw_text_cursors(WidgetLayout 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:490
void draw_line(WidgetLayout const &layout, line_segment const &line, draw_attributes const &attributes) const noexcept
Draw a line.
Definition draw_context.hpp:289
void draw_text_selection(WidgetLayout 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:471
void draw_box(WidgetLayout const &layout, quad const &box, draw_attributes const &attributes) const noexcept
Draw a box.
Definition draw_context.hpp:264
utc_nanoseconds display_time_point
The time when the drawing will appear on the screen.
Definition draw_context.hpp:235
void draw_text(WidgetLayout const &layout, matrix3 const &transform, text_shaper const &text, draw_attributes const &attributes) const noexcept
Draw shaped text.
Definition draw_context.hpp:409
Definition draw_context.hpp:43
Definition draw_context.hpp:204