7#include "draw_context.hpp"
8#include "gfx_pipeline_box_vulkan_impl.hpp"
9#include "gfx_pipeline_image_vulkan_impl.hpp"
10#include "gfx_pipeline_SDF_vulkan_impl.hpp"
11#include "gfx_pipeline_alpha_vulkan_impl.hpp"
12#include "gfx_device_vulkan.hpp"
13#include "../text/module.hpp"
14#include "../macros.hpp"
16namespace hi {
inline namespace v1 {
18inline draw_context::draw_context(
32 _box_vertices->clear();
33 _image_vertices->clear();
34 _sdf_vertices->clear();
35 _alpha_vertices->clear();
39draw_context::_override_alpha(aarectangle
const& clipping_rectangle, quad
box, draw_attributes
const&
attributes)
const noexcept
41 if (_alpha_vertices->full()) {
43 ++global_counter<
"override_alpha::overflow">;
47 gfx_pipeline_alpha::device_shared::place_vertices(*_alpha_vertices, clipping_rectangle,
box,
attributes.fill_color.p0.a());
51draw_context::_draw_box(aarectangle
const& clipping_rectangle, quad
box, draw_attributes
const&
attributes)
const noexcept
66 if (_box_vertices->full()) {
68 ++global_counter<
"draw_box::overflow">;
72 gfx_pipeline_box::device_shared::place_vertices(
82[[
nodiscard]]
inline bool draw_context::_draw_image(
83 aarectangle
const& clipping_rectangle,
85 gfx_pipeline_image::paged_image
const& image)
const noexcept
87 hi_assert_not_null(_image_vertices);
89 if (image.state != gfx_pipeline_image::paged_image::state_type::uploaded) {
93 device->image_pipeline->place_vertices(*_image_vertices, clipping_rectangle,
box, image);
97inline void draw_context::_draw_glyph(
98 aarectangle
const& clipping_rectangle,
102 draw_attributes
const&
attributes)
const noexcept
104 hi_assert_not_null(_sdf_vertices);
106 if (_sdf_vertices->full()) {
110 ++global_counter<
"draw_glyph::overflow">;
115 device->SDF_pipeline->place_vertices(*_sdf_vertices, clipping_rectangle,
box, font, glyph,
attributes.fill_color);
118 device->SDF_pipeline->prepare_atlas_for_rendering();
122inline void draw_context::_draw_text(
123 aarectangle
const& clipping_rectangle,
124 matrix3
const& transform,
125 text_shaper
const& text,
126 draw_attributes
const&
attributes)
const noexcept
128 hi_assert_not_null(_sdf_vertices);
131 for (hilet& c : text) {
132 hilet
box = translate2{c.position} * c.metrics.bounding_rectangle;
135 if (
not is_visible(c.general_category)) {
138 }
else if (_sdf_vertices->full()) {
142 ++global_counter<
"draw_glyph::overflow">;
147 *_sdf_vertices, clipping_rectangle, transform *
box, *c.glyphs.font, c.glyphs.ids.front(), color);
151 device->SDF_pipeline->prepare_atlas_for_rendering();
155inline void draw_context::_draw_text_selection(
156 aarectangle
const& clipping_rectangle,
157 matrix3
const& transform,
158 text_shaper
const& text,
159 text_selection
const& selection,
160 draw_attributes
const&
attributes)
const noexcept
162 hilet[first, last] = selection.selection_indices();
163 hilet
first_ = text.begin() + first;
164 hilet
last_ = text.begin() + last;
165 hi_axiom(
first_ <= text.end());
166 hi_axiom(
last_ <= text.end());
170 _draw_box(clipping_rectangle, transform *
it->rectangle,
attributes);
174inline void draw_context::_draw_text_insertion_cursor_empty(
175 aarectangle
const& clipping_rectangle,
176 matrix3
const& transform,
177 text_shaper
const& text,
178 draw_attributes
const&
attributes)
const noexcept
192inline void draw_context::_draw_text_insertion_cursor(
193 aarectangle
const& clipping_rectangle,
194 matrix3
const& transform,
195 text_shaper
const& text,
198 draw_attributes
const&
attributes)
const noexcept
203 hilet
it = text.get_it(cursor);
204 hilet& line = text.lines()[
it->line_nr];
205 hilet
ltr =
it->direction == unicode_bidi_class::L;
214 hilet
line_ltr = line.paragraph_direction == unicode_bidi_class::L;
242inline void draw_context::_draw_text_overwrite_cursor(
243 aarectangle
const& clipping_rectangle,
244 matrix3
const& transform,
245 text_shaper::char_const_iterator
it,
246 draw_attributes
const&
attributes)
const noexcept
252inline void draw_context::_draw_text_cursors(
253 aarectangle
const& clipping_rectangle,
254 matrix3
const& transform,
255 text_shaper
const& text,
256 text_cursor primary_cursor,
259 draw_attributes
const&
attributes)
const noexcept
265 return _draw_text_insertion_cursor_empty(clipping_rectangle, transform, text,
attributes);
270 hi_assert_bounds(primary_cursor.index(), text);
273 hi_assert(primary_cursor.before());
277 return _draw_text_overwrite_cursor(
278 clipping_rectangle, transform, text.begin() + primary_cursor.index(),
cursor_attributes);
286 return _draw_text_overwrite_cursor(
287 clipping_rectangle, transform, text.begin() + primary_cursor.index(),
cursor_attributes);
291 hilet
primary_it = text.begin() + primary_cursor.index();
297 if (primary_cursor.start_of_text()
or primary_cursor.end_of_text(text.size())) {
302 hilet secondary_cursor = primary_cursor.neighbor(text.size());
303 hilet
secondary_it = text.begin() + secondary_cursor.index();
323 _draw_text_insertion_cursor(clipping_rectangle, transform, text, primary_cursor,
draw_flags,
attributes);
@ bottom
Align to the bottom.
@ left
Align the text to the left side.
@ rectangle
The gui_event has rectangle data.
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
This is a RGBA floating point color.
Definition color.hpp:45