7#include "widget_layout.hpp"
8#include "../GFX/module.hpp"
9#include "../geometry/module.hpp"
10#include "../unicode/module.hpp"
11#include "../text/module.hpp"
12#include "../font/module.hpp"
13#include "../color/module.hpp"
14#include "../utility/module.hpp"
15#include "../vector_span.hpp"
17namespace hi {
inline namespace v1 {
36template<
typename Context>
38 std::same_as<Context, quad_color> or std::same_as<Context, color> or std::same_as<Context, border_side> or
39 std::same_as<Context, line_end_cap> or std::same_as<Context, corner_radii> or
40 std::same_as<Context, aarectangle> or std::same_as<Context, float>;
45 unsigned char num_colors = 0;
46 unsigned char num_line_caps = 0;
120 constexpr void add() noexcept {}
122 template<draw_attribute T>
123 constexpr void add(T
const& attribute)
noexcept
125 if constexpr (std::is_same_v<T, quad_color>) {
126 if (num_colors++ == 0) {
133 }
else if constexpr (std::is_same_v<T, color>) {
134 if (num_colors++ == 0) {
142 }
else if constexpr (std::is_same_v<T, line_end_cap>) {
143 if (num_line_caps++ == 0) {
151 }
else if constexpr (std::is_same_v<T, hi::border_side>) {
155 _has_border_side =
true;
158 }
else if constexpr (std::is_same_v<T, corner_radii>) {
162 _has_corner_radii =
true;
165 }
else if constexpr (std::is_same_v<T, aarectangle>) {
169 _has_clipping_rectangle =
true;
172 }
else if constexpr (std::is_same_v<T, float>) {
176 _has_line_width =
true;
183 template<draw_attribute First, draw_attribute Second, draw_attribute... Rest>
184 constexpr void add(First
const& first, Second
const& second, Rest
const&...rest)
noexcept
187 add(second, rest...);
192 bool _has_border_side =
false;
193 bool _has_corner_radii =
false;
194 bool _has_clipping_rectangle =
false;
195 bool _has_line_width =
false;
199template<
typename Context>
200concept draw_quad_shape = std::same_as<Context, quad> or std::same_as<Context, rectangle> or std::same_as<Context, aarectangle>;
229 layout.clipping_rectangle_on_window(attributes.clipping_rectangle), layout.to_window3() * box, attributes);
252 hilet box = make_rectangle(line, attributes.line_width, attributes.begin_line_cap, attributes.end_line_cap);
254 auto box_attributes = attributes;
255 box_attributes.line_width = 0.0f;
256 box_attributes.border_radius =
257 make_corner_radii(attributes.line_width, attributes.begin_line_cap, attributes.end_line_cap);
258 return draw_box(layout, box, box_attributes);
281 auto box_attributes = attributes;
282 box_attributes.border_radius = make_corner_radii(
circle);
310 return _draw_image(layout.clipping_rectangle_on_window(attributes.clipping_rectangle), layout.to_window3() * box, image);
340 hi::font
const& font,
345 layout.clipping_rectangle_on_window(attributes.clipping_rectangle),
346 layout.to_window3() * box,
363 hi::font
const& font,
365 Attributes
const&...attributes)
noexcept
380 font_book::font_glyph_type font_glyph,
384 layout.clipping_rectangle_on_window(attributes.clipping_rectangle),
385 layout.to_window3() * box,
402 font_book::font_glyph_type font_glyph,
403 Attributes
const&...attributes)
noexcept
420 layout.clipping_rectangle_on_window(attributes.clipping_rectangle),
421 layout.to_window3() * transform,
461 text_shaper
const&
text,
462 text_selection
const& selection,
465 return _draw_text_selection(
466 layout.clipping_rectangle_on_window(attributes.clipping_rectangle), layout.to_window3(),
text, selection, attributes);
479 text_shaper
const&
text,
480 text_selection
const& selection,
481 Attributes
const&...attributes)
noexcept
497 text_shaper
const&
text,
500 bool dead_character_mode,
503 return _draw_text_cursors(
504 layout.clipping_rectangle_on_window(attributes.clipping_rectangle),
525 text_shaper
const&
text,
528 bool dead_character_mode,
529 Attributes
const&...attributes)
noexcept
545 return _override_alpha(
546 layout.clipping_rectangle_on_window(attributes.clipping_rectangle), layout.to_window3() * box, attributes);
573 return overlaps(context.gfx_context.scissor_rectangle, layout.clipping_rectangle_on_window());
577 template<draw_quad_shape Shape>
578 [[nodiscard]]
constexpr static quad make_quad(Shape
const& shape)
noexcept
580 if constexpr (std::is_same_v<Shape, aarectangle>) {
581 return narrow_cast<aarectangle>(shape);
590 auto right = line.direction();
592 hilet radius = width * 0.5f;
594 hilet up = n * width;
595 hilet t = normalize(right);
597 auto origin = line.origin() - n * radius;
600 hilet radius_offset = t * radius;
602 origin -= radius_offset;
603 right += radius_offset;
606 right += radius_offset;
614 hilet circle_ = f32x4{circle};
615 hilet origin = point3{circle_.xyz1() - circle_.ww00()};
617 hilet up = vector3{circle_._0w00() * 2.0f};
621 [[nodiscard]]
constexpr static corner_radii make_corner_radii(
float width,
line_end_cap c1,
line_end_cap c2)
noexcept
623 auto r = f32x4::broadcast(width * 0.5f);
626 r = set_zero<0b0101>(r);
629 r = set_zero<0b1010>(r);
632 return corner_radii{r};
635 [[nodiscard]]
constexpr static corner_radii make_corner_radii(
hi::circle const& circle)
noexcept
637 return corner_radii{f32x4{circle}.wwww()};
640 void _override_alpha(aarectangle
const& clipping_rectangle, quad box, draw_attributes
const& attributes)
noexcept;
642 void _draw_box(aarectangle
const& clipping_rectangle, quad box, draw_attributes
const& attributes)
noexcept;
645 aarectangle
const& clipping_rectangle,
647 text_shaper
const& text,
648 draw_attributes
const& attributes)
noexcept;
650 void _draw_text_selection(
651 aarectangle
const& clipping_rectangle,
653 text_shaper
const& text,
654 text_selection
const& selection,
655 draw_attributes
const& attributes)
noexcept;
657 void _draw_text_insertion_cursor_empty(
658 aarectangle
const& clipping_rectangle,
660 text_shaper
const& text,
661 draw_attributes
const& attributes)
noexcept;
663 void _draw_text_insertion_cursor(
664 aarectangle
const& clipping_rectangle,
666 text_shaper
const& text,
669 draw_attributes
const& attributes)
noexcept;
671 void _draw_text_overwrite_cursor(
672 aarectangle
const& clipping_rectangle,
674 text_shaper::char_const_iterator it,
675 draw_attributes
const& attributes)
noexcept;
677 void _draw_text_cursors(
678 aarectangle
const& clipping_rectangle,
680 text_shaper
const& text,
683 bool dead_character_mode,
684 draw_attributes
const& attributes)
noexcept;
687 aarectangle
const& clipping_rectangle,
689 hi::font
const& font,
690 glyph_id
const& glyph,
691 draw_attributes
const& attributes)
noexcept;
694 _draw_image(aarectangle
const& clipping_rectangle, quad
const& box, paged_image
const& image)
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
@ 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 widget_draw_context.hpp:22
@ 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.
geo::matrix< 3 > matrix3
A 3D homogenious transformation matrix.
Definition matrix.hpp:614
@ normal
A font that is normal, non-italic.
A color for each corner of a quad.
Definition quad_color.hpp:19
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:27
static constexpr axis_aligned_rectangle large() noexcept
Create a large axis aligned rectangle.
Definition axis_aligned_rectangle.hpp:40
A type defining a 2D circle.
Definition circle.hpp:18
Identity transform.
Definition identity.hpp:20
Line segment.
Definition line_segment.hpp:19
A 2D or 3D homogenius matrix for transforming homogenious vectors and points.
Definition matrix.hpp:33
Definition gfx_draw_context.hpp:17
The draw attributes used to draw shaped into the draw context.
Definition widget_draw_context.hpp:44
aarectangle clipping_rectangle
The rectangle used the clip the shape when drawing.
Definition widget_draw_context.hpp:78
hi::border_side border_side
The side on which side of the edge of a shape the border should be drawn.
Definition widget_draw_context.hpp:67
float line_width
The width of a line, or the width of a border.
Definition widget_draw_context.hpp:63
line_end_cap end_line_cap
The shape of the beginning of a line.
Definition widget_draw_context.hpp:86
quad_color fill_color
The fill color used for the color of a box inside the border.
Definition widget_draw_context.hpp:53
quad_color line_color
The line color used for the color of the border of the box.
Definition widget_draw_context.hpp:59
line_end_cap begin_line_cap
The shape of the beginning of a line.
Definition widget_draw_context.hpp:82
hi::corner_radii border_radius
The radii of each corner of a quad.
Definition widget_draw_context.hpp:71
Draw context for drawing using the HikoGUI shaders.
Definition widget_draw_context.hpp:204
void draw_text_selection(widget_layout const &layout, text_shaper const &text, text_selection const &selection, draw_attributes const &attributes) noexcept
Draw text-selection of shaped text.
Definition widget_draw_context.hpp:459
void draw_hole(widget_layout const &layout, Shape const &box, Attributes const &...attributes) noexcept
Make a hole in the user interface.
Definition widget_draw_context.hpp:559
bool draw_image(widget_layout const &layout, draw_quad_shape auto const &box, paged_image &image, Attributes const &...attributes) noexcept
Draw an image.
Definition widget_draw_context.hpp:324
void draw_circle(widget_layout const &layout, hi::circle const &circle, draw_attributes const &attributes) noexcept
Draw a circle.
Definition widget_draw_context.hpp:279
void draw_circle(widget_layout const &layout, hi::circle const &circle, Attributes const &...attributes) noexcept
Draw a circle.
Definition widget_draw_context.hpp:293
void draw_line(widget_layout const &layout, line_segment const &line, Attributes const &...attributes) noexcept
Draw a line.
Definition widget_draw_context.hpp:268
void draw_text(widget_layout const &layout, text_shaper const &text, Attributes const &...attributes) noexcept
Draw shaped text.
Definition widget_draw_context.hpp:447
void draw_glyph(widget_layout const &layout, quad const &box, hi::font const &font, glyph_id glyph, draw_attributes const &attributes) noexcept
Draw a glyph.
Definition widget_draw_context.hpp:337
friend bool overlaps(widget_draw_context const &context, widget_layout const &layout) noexcept
Checks if a widget's layout overlaps with the part of the window that is being drawn.
Definition widget_draw_context.hpp:571
void draw_text(widget_layout const &layout, matrix3 const &transform, text_shaper const &text, Attributes const &...attributes) noexcept
Draw shaped text.
Definition widget_draw_context.hpp:434
void draw_text(widget_layout const &layout, matrix3 const &transform, text_shaper const &text, draw_attributes const &attributes) noexcept
Draw shaped text.
Definition widget_draw_context.hpp:416
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) noexcept
Draw text cursors of shaped text.
Definition widget_draw_context.hpp:495
void draw_box(widget_layout const &layout, Shape const &shape, Attributes const &...attributes) noexcept
Draw a box.
Definition widget_draw_context.hpp:239
bool draw_image(widget_layout const &layout, quad const &box, paged_image &image, draw_attributes const &attributes) noexcept
Draw an image.
Definition widget_draw_context.hpp:308
void draw_text_selection(widget_layout const &layout, text_shaper const &text, text_selection const &selection, Attributes const &...attributes) noexcept
Draw text-selection of shaped text.
Definition widget_draw_context.hpp:477
void draw_glyph(widget_layout const &layout, quad const &box, font_book::font_glyph_type font_glyph, draw_attributes const &attributes) noexcept
Draw a glyph.
Definition widget_draw_context.hpp:377
void draw_box(widget_layout const &layout, quad const &box, draw_attributes const &attributes) noexcept
Draw a box.
Definition widget_draw_context.hpp:226
void draw_glyph(widget_layout const &layout, Shape const &box, hi::font const &font, glyph_id glyph, Attributes const &...attributes) noexcept
Draw a glyph.
Definition widget_draw_context.hpp:360
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) noexcept
Draw text cursors of shaped text.
Definition widget_draw_context.hpp:523
void draw_line(widget_layout const &layout, line_segment const &line, draw_attributes const &attributes) noexcept
Draw a line.
Definition widget_draw_context.hpp:250
void draw_hole(widget_layout const &layout, quad const &box, draw_attributes const &attributes) noexcept
Make a hole in the user interface.
Definition widget_draw_context.hpp:543
utc_nanoseconds display_time_point
The time when the drawing will appear on the screen.
Definition widget_draw_context.hpp:210
void draw_glyph(widget_layout const &layout, Shape const &box, font_book::font_glyph_type font_glyph, Attributes const &...attributes) noexcept
Draw a glyph.
Definition widget_draw_context.hpp:399
The layout of a widget.
Definition widget_layout.hpp:37
Definition widget_draw_context.hpp:37
Definition widget_draw_context.hpp:200