HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
draw_context.hpp
1// Copyright Take Vos 2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "pipeline_flat_vertex.hpp"
8#include "pipeline_box_vertex.hpp"
9#include "pipeline_image_vertex.hpp"
10#include "pipeline_SDF_vertex.hpp"
11#include "../geometry/axis_aligned_rectangle.hpp"
12#include "../geometry/matrix.hpp"
13#include "../geometry/corner_shapes.hpp"
14#include "../geometry/identity.hpp"
15#include "../color/color.hpp"
16#include "../vspan.hpp"
17
18namespace tt {
19class gfx_device;
20class gfx_device_vulkan;
21class shaped_text;
22class font_glyph_ids;
23namespace pipeline_image {
24struct image;
25}
26
30public:
31 draw_context(draw_context const &rhs) noexcept = default;
32 draw_context(draw_context &&rhs) noexcept = default;
33 draw_context &operator=(draw_context const &rhs) noexcept = default;
34 draw_context &operator=(draw_context &&rhs) noexcept = default;
35 ~draw_context() = default;
36
38 gfx_device_vulkan &device,
39 size_t frame_buffer_index,
40 extent2 surface_size,
41 aarectangle scissor_rectangle,
42 vspan<pipeline_flat::vertex> &flatVertices,
43 vspan<pipeline_box::vertex> &boxVertices,
44 vspan<pipeline_image::vertex> &imageVertices,
45 vspan<pipeline_SDF::vertex> &sdfVertices) noexcept;
46
47 [[nodiscard]] draw_context
48 make_child_context(matrix3 parent_to_local, matrix3 local_to_window, aarectangle clipping_rectangle) const noexcept;
49
50 [[nodiscard]] size_t frame_buffer_index() const noexcept;
51
52 [[nodiscard]] aarectangle scissor_rectangle() const noexcept;
53
54 [[nodiscard]] aarectangle clipping_rectangle() const noexcept;
55
56 void set_clipping_rectangle(aarectangle clipping_rectangle) noexcept;
57
58 [[nodiscard]] matrix3 transform() const noexcept;
59
60 gfx_device &device() const noexcept;
61
69 void draw_filled_quad(point3 p1, point3 p2, point3 p3, point3 p4, color fill_color) const noexcept;
70
78 void draw_filled_quad(rectangle r, color fill_color) const noexcept;
79
92 rectangle box,
93 color fill_color,
94 color line_color,
95 float line_width = 1.0,
97
98 void draw_box(rectangle box, color fill_color, color line_color, tt::corner_shapes corner_shapes) const noexcept;
99
100 void draw_box(rectangle box, color fill_color, tt::corner_shapes corner_shapes) const noexcept;
101
119 color fill_color,
120 color line_color,
121 float line_width = 1.0,
123
125 const noexcept;
126
145 color fill_color,
146 color line_color,
147 float line_width = 1.0,
149
151 const noexcept;
152
159 void draw_image(pipeline_image::image &image, matrix3 image_transform) const noexcept;
160
171 void
172 draw_text(shaped_text const &text, std::optional<color> text_color = {}, matrix3 transform = geo::identity{}) const noexcept;
173
174 void draw_glyph(font_glyph_ids const &glyph, rectangle box, color text_color) const noexcept;
175
176 [[nodiscard]] friend bool overlaps(draw_context const &context, aarectangle const &rectangle) noexcept
177 {
178 return overlaps(context._scissor_rectangle, rectangle);
179 }
180
181private:
182 gfx_device_vulkan &_device;
183
184 vspan<pipeline_flat::vertex> *_flat_vertices;
185 vspan<pipeline_box::vertex> *_box_vertices;
186 vspan<pipeline_image::vertex> *_image_vertices;
187 vspan<pipeline_SDF::vertex> *_sdf_vertices;
188
191 size_t _frame_buffer_index;
192
196 aarectangle _scissor_rectangle;
197
201 aarectangle _clipping_rectangle;
202
207 matrix3 _transform = geo::identity{};
208};
209
210} // namespace tt
This is a RGBA floating point color.
Definition color.hpp:36
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:20
Definition corner_shapes.hpp:9
Definition identity.hpp:11
Class which represents an rectangle.
Definition rectangle.hpp:16
Draw context for drawing using the TTauri shaders.
Definition draw_context.hpp:29
void draw_image(pipeline_image::image &image, matrix3 image_transform) const noexcept
Draw an image This function will draw an image.
void draw_filled_quad(rectangle r, color fill_color) const noexcept
Draw a rectangle of one color.
void draw_filled_quad(point3 p1, point3 p2, point3 p3, point3 p4, color fill_color) const noexcept
Draw a polygon with four corners of one color.
void draw_box_with_border_inside(rectangle rectangle, color fill_color, color line_color, float line_width=1.0, tt::corner_shapes corner_shapes=tt::corner_shapes{}) const noexcept
Draw an axis aligned box This function will shrink to include the size of the border inside the given...
void draw_text(shaped_text const &text, std::optional< color > text_color={}, matrix3 transform=geo::identity{}) const noexcept
Draw shaped text.
void draw_box_with_border_outside(rectangle rectangle, color fill_color, color line_color, float line_width=1.0, tt::corner_shapes corner_shapes=tt::corner_shapes{}) const noexcept
Draw an axis aligned box This function will expand to include the size of the border outside the give...
void draw_box(rectangle box, color fill_color, color line_color, float line_width=1.0, tt::corner_shapes corner_shapes=tt::corner_shapes{}) const noexcept
Draw an axis aligned box This function will draw the given box.
Definition gfx_device.hpp:22
Definition gfx_device_vulkan.hpp:24
This is a image that is uploaded into the texture atlas.
Definition pipeline_image_image.hpp:30
shaped_text represent a piece of text shaped to be displayed.
Definition shaped_text.hpp:23
Definition vspan.hpp:73