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_box_vertex.hpp"
8#include "pipeline_image_vertex.hpp"
9#include "pipeline_SDF_vertex.hpp"
10#include "../geometry/axis_aligned_rectangle.hpp"
11#include "../geometry/matrix.hpp"
12#include "../geometry/corner_shapes.hpp"
13#include "../geometry/identity.hpp"
14#include "../color/color.hpp"
15#include "../vspan.hpp"
16
17namespace tt {
18class gfx_device;
19class gfx_device_vulkan;
20class shaped_text;
21class font_glyph_ids;
22namespace pipeline_image {
23struct image;
24}
25
29public:
30 draw_context(draw_context const &rhs) noexcept = default;
31 draw_context(draw_context &&rhs) noexcept = default;
32 draw_context &operator=(draw_context const &rhs) noexcept = default;
33 draw_context &operator=(draw_context &&rhs) noexcept = default;
34 ~draw_context() = default;
35
37 gfx_device_vulkan &device,
38 size_t frame_buffer_index,
39 extent2 surface_size,
40 aarectangle scissor_rectangle,
41 vspan<pipeline_box::vertex> &boxVertices,
42 vspan<pipeline_image::vertex> &imageVertices,
43 vspan<pipeline_SDF::vertex> &sdfVertices) noexcept;
44
45 [[nodiscard]] draw_context
46 make_child_context(matrix3 parent_to_local, matrix3 local_to_window, aarectangle clipping_rectangle) const noexcept;
47
48 [[nodiscard]] size_t frame_buffer_index() const noexcept;
49
50 [[nodiscard]] aarectangle scissor_rectangle() const noexcept;
51
52 [[nodiscard]] aarectangle clipping_rectangle() const noexcept;
53
54 void set_clipping_rectangle(aarectangle clipping_rectangle) noexcept;
55
56 [[nodiscard]] matrix3 transform() const noexcept;
57
58 gfx_device &device() const noexcept;
59
72 rectangle box,
73 color fill_color,
74 color line_color,
75 float line_width = 1.0,
77
78 void draw_box(rectangle box, color fill_color, color line_color, tt::corner_shapes corner_shapes) const noexcept;
79
80 void draw_box(rectangle box, color fill_color, tt::corner_shapes corner_shapes) const noexcept;
81
82 void draw_box(rectangle box, color fill_color) const noexcept;
83
101 color fill_color,
102 color line_color,
103 float line_width = 1.0,
105
107 const noexcept;
108
127 color fill_color,
128 color line_color,
129 float line_width = 1.0,
131
133 const noexcept;
134
141 void draw_image(pipeline_image::image &image, matrix3 image_transform) const noexcept;
142
153 void
154 draw_text(shaped_text const &text, std::optional<color> text_color = {}, matrix3 transform = geo::identity{}) const noexcept;
155
164 void draw_glyph(font_glyph_ids const &glyph, float glyph_size, rectangle box, color text_color) const noexcept;
165
166 [[nodiscard]] friend bool overlaps(draw_context const &context, aarectangle const &rectangle) noexcept
167 {
168 return overlaps(context._scissor_rectangle, rectangle);
169 }
170
171private:
172 gfx_device_vulkan &_device;
173
174 vspan<pipeline_box::vertex> *_box_vertices;
175 vspan<pipeline_image::vertex> *_image_vertices;
176 vspan<pipeline_SDF::vertex> *_sdf_vertices;
177
180 size_t _frame_buffer_index;
181
185 aarectangle _scissor_rectangle;
186
190 aarectangle _clipping_rectangle;
191
196 matrix3 _transform = geo::identity{};
197};
198
199} // 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:28
void draw_image(pipeline_image::image &image, matrix3 image_transform) const noexcept
Draw an image This function will draw an image.
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.
void draw_glyph(font_glyph_ids const &glyph, float glyph_size, rectangle box, color text_color) const noexcept
Draw a glyph.
Definition gfx_device.hpp:22
Definition gfx_device_vulkan.hpp:23
This is a image that is uploaded into the texture atlas.
Definition pipeline_image_image.hpp:30
Definition font_glyph_ids.hpp:80
shaped_text represent a piece of text shaped to be displayed.
Definition shaped_text.hpp:23
Definition vspan.hpp:73