This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
DrawContext.h
90 lines (70 loc) · 3.97 KB
/
DrawContext.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
This file is part of duckOS.
duckOS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
duckOS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with duckOS. If not, see <https://www.gnu.org/licenses/>.
Copyright (c) Byteduck 2016-2021. All rights reserved.
*/
#pragma once
#include "Theme.h"
#include <libgraphics/Image.h>
#include <libgraphics/Graphics.h>
#include "TextLayout.h"
namespace UI {
enum TextAlignment {
BEGINNING, CENTER, END
};
class DrawContext {
public:
DrawContext(const Gfx::Framebuffer& framebuffer);
///Properties
int width() const;
int height() const;
Gfx::Dimensions dimensions() const;
Gfx::Rect rect() const;
const Gfx::Framebuffer& framebuffer() const;
///Drawing
void fill(Gfx::Rect rect, Gfx::Color color) const;
void fill_gradient_h(Gfx::Rect rect, Gfx::Color color_a, Gfx::Color color_b) const;
void fill_gradient_v(Gfx::Rect rect, Gfx::Color color_a, Gfx::Color color_b) const;
void fill_ellipse(Gfx::Rect rect, Gfx::Color color) const;
void fill_rounded_rect(Gfx::Rect rect, Gfx::Color color, int radius = 5) const;
using TruncationMode = TextLayout::TruncationMode;
void draw_text(const TextLayout& layout, Gfx::Rect rect, TextAlignment h_align, TextAlignment v_align, Gfx::Color color) const;
void draw_text(const char* str, Gfx::Rect rect, TextAlignment h_align, TextAlignment v_align, Gfx::Font* font, Gfx::Color color, TruncationMode truncation = TruncationMode::ELLIPSIS) const;
void draw_text(const char* str, Gfx::Point pos, Gfx::Font* font, Gfx::Color color) const;
void draw_text(const char* str, Gfx::Point pos, Gfx::Color color) const;
void draw_glyph(Gfx::Font* font, uint32_t codepoint, Gfx::Point pos, Gfx::Color color) const;
void draw_image(Duck::Ptr<const Gfx::Image> img, Gfx::Point pos) const;
void draw_image(Duck::Ptr<const Gfx::Image> img, Gfx::Rect rect) const;
void draw_image(const std::string& name, Gfx::Point pos) const;
void draw_inset_outline(Gfx::Rect rect, Gfx::Color shadow_1, Gfx::Color shadow_2, Gfx::Color highlight) const;
void draw_inset_outline(Gfx::Rect rect) const;
void draw_inset_rect(Gfx::Rect rect, Gfx::Color bg1, Gfx::Color bg2, Gfx::Color shadow_1, Gfx::Color shadow_2, Gfx::Color highlight) const;
void draw_inset_rect(Gfx::Rect rect, Gfx::Color bg, Gfx::Color shadow_1, Gfx::Color shadow_2, Gfx::Color highlight) const;
void draw_inset_rect(Gfx::Rect rect, Gfx::Color bg1, Gfx::Color bg2) const;
void draw_inset_rect(Gfx::Rect rect, Gfx::Color bg) const;
void draw_inset_rect(Gfx::Rect rect) const;
void draw_outset_rect(Gfx::Rect rect, Gfx::Color bg1, Gfx::Color bg2, Gfx::Color shadow_1, Gfx::Color shadow_2, Gfx::Color highlight) const;
void draw_outset_rect(Gfx::Rect rect, Gfx::Color bg, Gfx::Color shadow_1, Gfx::Color shadow_2, Gfx::Color highlight) const;
void draw_outset_rect(Gfx::Rect rect, Gfx::Color bg1, Gfx::Color bg2) const;
void draw_outset_rect(Gfx::Rect rect, Gfx::Color bg) const;
void draw_outset_rect(Gfx::Rect rect) const;
void draw_button_base(Gfx::Rect button, bool pressed) const;
void draw_button_base(Gfx::Rect button, bool pressed, Gfx::Color color) const;
void draw_button(Gfx::Rect button, const std::string& text, bool pressed) const;
void draw_button(Gfx::Rect button, const Gfx::Framebuffer& img, bool pressed) const;
void draw_button(Gfx::Rect rect, Duck::Ptr<const Gfx::Image> img, bool pressed) const;
void draw_vertical_scrollbar(Gfx::Rect area, Gfx::Rect handle_area, bool enabled) const;
void draw_progressbar(Gfx::Rect area, double progress) const;
private:
const Gfx::Framebuffer* fb;
};
}