7#include "gfx_pipeline_box_vulkan_intf.hpp"
8#include "gfx_pipeline_image_vulkan_intf.hpp"
9#include "gfx_pipeline_SDF_vulkan_intf.hpp"
10#include "gfx_pipeline_override_vulkan_intf.hpp"
11#include "../settings/settings.hpp"
12#include "../geometry/geometry.hpp"
13#include "../unicode/unicode.hpp"
14#include "../text/text.hpp"
16#include "../container/container.hpp"
17#include "../utility/utility.hpp"
18#include "../macros.hpp"
20hi_export_module(hikogui.GFX : draw_context_intf);
22hi_export
namespace hi {
inline namespace v1 {
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) {
136 hi_axiom(num_colors <= 2);
138 }
else if constexpr (std::is_same_v<T, color>) {
139 if (num_colors++ == 0) {
144 hi_axiom(num_colors <= 2);
146 }
else if constexpr (std::is_same_v<T, line_end_cap>) {
147 if (num_line_caps++ == 0) {
153 hi_axiom(num_line_caps <= 2);
155 }
else if constexpr (std::is_same_v<T, hi::border_side>) {
158 hi_assert(not _has_border_side);
159 _has_border_side =
true;
162 }
else if constexpr (std::is_same_v<T, corner_radii>) {
165 hi_assert(not _has_corner_radii);
166 _has_corner_radii =
true;
169 }
else if constexpr (std::is_same_v<T, aarectangle>) {
172 hi_assert(not _has_clipping_rectangle);
173 _has_clipping_rectangle =
true;
176 }
else if constexpr (std::is_same_v<T, float> or std::is_same_v<T, int>) {
179 hi_assert(not _has_line_width);
180 _has_line_width =
true;
183 hi_static_no_default();
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>;
241 vector_span<gfx_pipeline_box::vertex>& box_vertices,
242 vector_span<gfx_pipeline_image::vertex>& image_vertices,
243 vector_span<gfx_pipeline_SDF::vertex>& sdf_vertices,
244 vector_span<gfx_pipeline_override::vertex>& override_vertices)
noexcept;
248 operator bool() const noexcept
259 template<std::same_as<w
idget_layout> W
idgetLayout>
263 layout.clipping_rectangle_on_window(attributes.clipping_rectangle), layout.to_window3() * box, attributes);
272 template<std::same_as<w
idget_layout> W
idgetLayout, draw_quad_shape Shape, draw_attribute... Attributes>
273 void draw_box(WidgetLayout
const& layout, Shape
const& shape, Attributes
const&...attributes)
const noexcept
284 template<std::same_as<w
idget_layout> W
idgetLayout>
287 auto const box = make_rectangle(line, attributes.line_width, attributes.begin_line_cap, attributes.end_line_cap);
289 auto box_attributes = attributes;
290 box_attributes.line_width = 0.0f;
291 box_attributes.corner_radius =
292 make_corner_radii(attributes.line_width, attributes.begin_line_cap, attributes.end_line_cap);
293 return draw_box(layout, box, box_attributes);
302 template<std::same_as<w
idget_layout> W
idgetLayout, draw_attribute... Attributes>
314 template<std::same_as<w
idget_layout> W
idgetLayout>
317 auto box_attributes = attributes;
318 box_attributes.corner_radius = make_corner_radii(
circle);
328 template<std::same_as<w
idget_layout> W
idgetLayout, draw_attribute... Attributes>
343 template<std::same_as<w
idget_layout> W
idgetLayout>
347 return _draw_image(layout.clipping_rectangle_on_window(attributes.clipping_rectangle), layout.to_window3() * box, image);
359 template<std::same_as<w
idget_layout> W
idgetLayout, draw_attribute... Attributes>
374 template<std::same_as<w
idget_layout> W
idgetLayout>
376 WidgetLayout
const& layout,
378 hi::font
const& font,
383 layout.clipping_rectangle_on_window(attributes.clipping_rectangle), layout.to_window3() * box, font, glyph, attributes);
393 template<std::same_as<w
idget_layout> W
idgetLayout, draw_quad_shape Shape, draw_attribute... Attributes>
395 WidgetLayout
const& layout,
397 hi::font
const& font,
398 hi::glyph_id glyph_id,
399 Attributes
const&...attributes)
const noexcept
411 template<std::same_as<w
idget_layout> W
idgetLayout>
413 WidgetLayout
const& layout,
415 font_book::font_glyph_type
const& glyph,
419 layout.clipping_rectangle_on_window(attributes.clipping_rectangle), layout.to_window3() * box, *glyph.font, glyph.id, attributes);
429 template<std::same_as<w
idget_layout> W
idgetLayout, draw_quad_shape Shape, draw_attribute... Attributes>
431 WidgetLayout
const& layout,
433 font_book::font_glyph_type
const& glyph,
434 Attributes
const&...attributes)
const noexcept
446 template<std::same_as<w
idget_layout> W
idgetLayout>
452 layout.clipping_rectangle_on_window(attributes.clipping_rectangle),
453 layout.to_window3() * transform,
465 template<std::same_as<w
idget_layout> W
idgetLayout, draw_attribute... Attributes>
466 void draw_text(WidgetLayout
const& layout,
matrix3 const& transform, text_shaper
const& text, Attributes
const&...attributes)
478 template<std::same_as<w
idget_layout> W
idgetLayout, draw_attribute... Attributes>
479 void draw_text(WidgetLayout
const& layout, text_shaper
const& text, Attributes
const&...attributes)
const noexcept
491 template<std::same_as<w
idget_layout> W
idgetLayout>
493 WidgetLayout
const& layout,
494 text_shaper
const& text,
495 text_selection
const& selection,
498 return _draw_text_selection(
499 layout.clipping_rectangle_on_window(attributes.clipping_rectangle), layout.to_window3(), text, selection, attributes);
509 template<std::same_as<w
idget_layout> W
idgetLayout, draw_attribute... Attributes>
511 WidgetLayout
const& layout,
512 text_shaper
const& text,
513 text_selection
const& selection,
514 Attributes
const&...attributes)
const noexcept
528 template<std::same_as<w
idget_layout> W
idgetLayout>
530 WidgetLayout
const& layout,
531 text_shaper
const& text,
534 bool dead_character_mode,
537 return _draw_text_cursors(
538 layout.clipping_rectangle_on_window(attributes.clipping_rectangle),
556 template<std::same_as<w
idget_layout> W
idgetLayout, draw_attribute... Attributes>
558 WidgetLayout
const& layout,
559 text_shaper
const& text,
562 bool dead_character_mode,
563 Attributes
const&...attributes)
const noexcept
577 template<std::same_as<w
idget_layout> W
idgetLayout>
581 attributes.fill_color =
color{0.0f, 0.0f, 0.0f, 0.0f};
582 attributes.line_color =
color{0.0f, 0.0f, 0.0f, 1.0f};
583 return _draw_override(
584 layout.clipping_rectangle_on_window(attributes.clipping_rectangle), layout.to_window3() * box, attributes);
596 template<std::same_as<w
idget_layout> W
idgetLayout, draw_quad_shape Shape, draw_attribute... Attributes>
597 void draw_hole(WidgetLayout
const& layout, Shape
const& box, Attributes
const&...attributes)
const noexcept
609 template<std::same_as<w
idget_layout> W
idgetLayout>
612 return overlaps(context.scissor_rectangle, layout.clipping_rectangle_on_window());
616 vector_span<gfx_pipeline_box::vertex> *_box_vertices;
617 vector_span<gfx_pipeline_image::vertex> *_image_vertices;
618 vector_span<gfx_pipeline_SDF::vertex> *_sdf_vertices;
619 vector_span<gfx_pipeline_override::vertex> *_override_vertices;
621 template<draw_quad_shape Shape>
622 [[nodiscard]]
constexpr static quad make_quad(Shape
const& shape)
noexcept
624 if constexpr (std::is_same_v<Shape, quad>) {
634 auto right = line.direction();
636 auto const radius = width * 0.5f;
637 auto const n = normal(
right, 0.0f);
638 auto const up = n * width;
639 auto const t = normalize(
right);
641 auto origin = line.origin() - n * radius;
644 auto const radius_offset = t * radius;
646 origin -= radius_offset;
647 right += radius_offset;
650 right += radius_offset;
658 auto const circle_ = f32x4{circle};
659 auto const origin = point3{circle_.xyz1() - circle_.ww00()};
660 auto const right = vector3{circle_.w000() * f32x4::broadcast(2.0f)};
661 auto const up = vector3{circle_._0w00() * f32x4::broadcast(2.0f)};
665 [[nodiscard]]
constexpr static corner_radii make_corner_radii(
float width,
line_end_cap c1,
line_end_cap c2)
noexcept
667 auto r = f32x4::broadcast(width * 0.5f);
670 r = blend<0b0101>(r, f32x4{});
673 r = blend<0b1010>(r, f32x4{});
676 return corner_radii{r};
679 [[nodiscard]]
constexpr static corner_radii make_corner_radii(
hi::circle const& circle)
noexcept
681 return corner_radii{f32x4{circle}.wwww()};
684 void _draw_override(aarectangle
const& clipping_rectangle, quad box, draw_attributes
const& attributes)
const noexcept;
686 void _draw_box(aarectangle
const& clipping_rectangle, quad box, draw_attributes
const& attributes)
const noexcept;
689 aarectangle
const& clipping_rectangle,
690 matrix3
const& transform,
691 text_shaper
const& text,
692 draw_attributes
const& attributes)
const noexcept;
694 void _draw_text_selection(
695 aarectangle
const& clipping_rectangle,
696 matrix3
const& transform,
697 text_shaper
const& text,
698 text_selection
const& selection,
699 draw_attributes
const& attributes)
const noexcept;
701 void _draw_text_insertion_cursor_empty(
702 aarectangle
const& clipping_rectangle,
703 matrix3
const& transform,
704 text_shaper
const& text,
705 draw_attributes
const& attributes)
const noexcept;
707 void _draw_text_insertion_cursor(
708 aarectangle
const& clipping_rectangle,
709 matrix3
const& transform,
710 text_shaper
const& text,
713 draw_attributes
const& attributes)
const noexcept;
715 void _draw_text_overwrite_cursor(
716 aarectangle
const& clipping_rectangle,
717 matrix3
const& transform,
718 text_shaper::char_const_iterator it,
719 draw_attributes
const& attributes)
const noexcept;
721 void _draw_text_cursors(
722 aarectangle
const& clipping_rectangle,
723 matrix3
const& transform,
724 text_shaper
const& text,
727 bool dead_character_mode,
728 draw_attributes
const& attributes)
const noexcept;
731 aarectangle
const& clipping_rectangle,
733 hi::font
const& font,
735 draw_attributes
const& attributes)
const noexcept;
738 _draw_image(aarectangle
const& clipping_rectangle, quad
const& box, gfx_pipeline_image::paged_image
const& image)
const noexcept;
line_end_cap
The way two lines should be joined.
Definition line_end_cap.hpp:21
@ 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.
The HikoGUI namespace.
Definition array_generic.hpp:20
border_side
The side where the border is drawn.
Definition draw_context_intf.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.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
This is a RGBA floating point color.
Definition color_intf.hpp:49
A color for each corner of a quad.
Definition quad_color.hpp:22
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:33
static constexpr aarectangle large() noexcept
Create a large axis aligned rectangle.
Definition aarectangle.hpp:46
A type defining a 2D circle.
Definition circle.hpp:23
The 4 radii of the corners of a quad or rectangle.
Definition corner_radii.hpp:26
Line segment.
Definition line_segment.hpp:26
A 2D or 3D homogenius matrix for transforming homogenious vectors and points.
Definition matrix3.hpp:36
The draw attributes used to draw shaped into the draw context.
Definition draw_context_intf.hpp:49
aarectangle clipping_rectangle
The rectangle used the clip the shape when drawing.
Definition draw_context_intf.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_intf.hpp:72
float line_width
The width of a line, or the width of a border.
Definition draw_context_intf.hpp:68
line_end_cap end_line_cap
The shape of the beginning of a line.
Definition draw_context_intf.hpp:91
quad_color fill_color
The fill color used for the color of a box inside the border.
Definition draw_context_intf.hpp:58
quad_color line_color
The line color used for the color of the border of the box.
Definition draw_context_intf.hpp:64
line_end_cap begin_line_cap
The shape of the beginning of a line.
Definition draw_context_intf.hpp:87
hi::corner_radii corner_radius
The radii of each corner of a quad.
Definition draw_context_intf.hpp:76
Draw context for drawing using the HikoGUI shaders.
Definition draw_context_intf.hpp:209
void draw_glyph(WidgetLayout const &layout, quad const &box, font_book::font_glyph_type const &glyph, draw_attributes const &attributes) const noexcept
Draw a glyph.
Definition draw_context_intf.hpp:412
void draw_text(WidgetLayout const &layout, text_shaper const &text, Attributes const &...attributes) const noexcept
Draw shaped text.
Definition draw_context_intf.hpp:479
void draw_circle(WidgetLayout const &layout, hi::circle const &circle, Attributes const &...attributes) const noexcept
Draw a circle.
Definition draw_context_intf.hpp:329
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_intf.hpp:557
hi::subpixel_orientation subpixel_orientation
The subpixel orientation for rendering glyphs.
Definition draw_context_intf.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_intf.hpp:610
void draw_box(WidgetLayout const &layout, Shape const &shape, Attributes const &...attributes) const noexcept
Draw a box.
Definition draw_context_intf.hpp:273
bool draw_image(WidgetLayout const &layout, draw_quad_shape auto const &box, gfx_pipeline_image::paged_image &image, Attributes const &...attributes) const noexcept
Draw an image.
Definition draw_context_intf.hpp:361
void draw_hole(WidgetLayout const &layout, quad const &box, draw_attributes attributes) const noexcept
Make a hole in the user interface.
Definition draw_context_intf.hpp:578
void draw_circle(WidgetLayout const &layout, hi::circle const &circle, draw_attributes const &attributes) const noexcept
Draw a circle.
Definition draw_context_intf.hpp:315
float saturation
The tone-mapper's saturation.
Definition draw_context_intf.hpp:227
void draw_text(WidgetLayout const &layout, matrix3 const &transform, text_shaper const &text, Attributes const &...attributes) const noexcept
Draw shaped text.
Definition draw_context_intf.hpp:466
void draw_glyph(WidgetLayout const &layout, Shape const &box, hi::font const &font, hi::glyph_id glyph_id, Attributes const &...attributes) const noexcept
Draw a glyph.
Definition draw_context_intf.hpp:394
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_intf.hpp:492
aarectangle scissor_rectangle
This is the rectangle of the window that is being redrawn.
Definition draw_context_intf.hpp:219
void draw_line(WidgetLayout const &layout, line_segment const &line, Attributes const &...attributes) const noexcept
Draw a line.
Definition draw_context_intf.hpp:303
void draw_glyph(WidgetLayout const &layout, Shape const &box, font_book::font_glyph_type const &glyph, Attributes const &...attributes) const noexcept
Draw a glyph.
Definition draw_context_intf.hpp:430
std::size_t frame_buffer_index
The frame buffer index of the image we are currently rendering.
Definition draw_context_intf.hpp:215
void draw_hole(WidgetLayout const &layout, Shape const &box, Attributes const &...attributes) const noexcept
Make a hole in the user interface.
Definition draw_context_intf.hpp:597
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_intf.hpp:529
void draw_line(WidgetLayout const &layout, line_segment const &line, draw_attributes const &attributes) const noexcept
Draw a line.
Definition draw_context_intf.hpp:285
bool draw_image(WidgetLayout const &layout, quad const &box, gfx_pipeline_image::paged_image &image, draw_attributes const &attributes) const noexcept
Draw an image.
Definition draw_context_intf.hpp:345
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_intf.hpp:510
void draw_glyph(WidgetLayout const &layout, quad const &box, hi::font const &font, glyph_id glyph, draw_attributes const &attributes) const noexcept
Draw a glyph.
Definition draw_context_intf.hpp:375
void draw_box(WidgetLayout const &layout, quad const &box, draw_attributes const &attributes) const noexcept
Draw a box.
Definition draw_context_intf.hpp:260
utc_nanoseconds display_time_point
The time when the drawing will appear on the screen.
Definition draw_context_intf.hpp:231
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_intf.hpp:448
This is a image that is uploaded into the texture atlas.
Definition gfx_pipeline_image_vulkan_intf.hpp:83
Definition draw_context_intf.hpp:43
Definition draw_context_intf.hpp:204