strat9_kernel/arch/x86_64/vga/
canvas.rs1use super::{
4 api::*,
5 status_line::{draw_system_status_line, ui_draw_status_bar},
6 types::*,
7};
8
9pub struct Canvas {
10 fg: RgbColor,
11 bg: RgbColor,
12}
13
14impl Default for Canvas {
15 fn default() -> Self {
17 Self {
18 fg: RgbColor::LIGHT_GREY,
19 bg: RgbColor::BLACK,
20 }
21 }
22}
23
24impl Canvas {
25 pub const fn new(fg: RgbColor, bg: RgbColor) -> Self {
27 Self { fg, bg }
28 }
29
30 pub fn set_fg(&mut self, fg: RgbColor) {
32 self.fg = fg;
33 }
34
35 pub fn set_bg(&mut self, bg: RgbColor) {
37 self.bg = bg;
38 }
39
40 pub fn set_colors(&mut self, fg: RgbColor, bg: RgbColor) {
42 self.fg = fg;
43 self.bg = bg;
44 }
45
46 pub fn set_clip_rect(&self, x: usize, y: usize, w: usize, h: usize) {
48 set_clip_rect(x, y, w, h);
49 }
50
51 pub fn reset_clip_rect(&self) {
53 reset_clip_rect();
54 }
55
56 pub fn clear(&self) {
58 fill_rect(0, 0, width(), height(), self.bg);
59 }
60
61 pub fn pixel(&self, x: usize, y: usize) {
63 draw_pixel(x, y, self.fg);
64 }
65
66 pub fn line(&self, x0: isize, y0: isize, x1: isize, y1: isize) {
68 draw_line(x0, y0, x1, y1, self.fg);
69 }
70
71 pub fn rect(&self, x: usize, y: usize, w: usize, h: usize) {
73 draw_rect(x, y, w, h, self.fg);
74 }
75
76 pub fn fill_rect(&self, x: usize, y: usize, w: usize, h: usize) {
78 fill_rect(x, y, w, h, self.fg);
79 }
80
81 pub fn fill_rect_alpha(&self, x: usize, y: usize, w: usize, h: usize, alpha: u8) {
83 fill_rect_alpha(x, y, w, h, self.fg, alpha);
84 }
85
86 pub fn text(&self, x: usize, y: usize, text: &str) {
88 draw_text_at(x, y, text, self.fg, self.bg);
89 }
90
91 pub fn text_opts(
93 &self,
94 x: usize,
95 y: usize,
96 text: &str,
97 align: TextAlign,
98 wrap: bool,
99 max_width: Option<usize>,
100 ) -> TextMetrics {
101 draw_text(
102 x,
103 y,
104 text,
105 TextOptions {
106 fg: self.fg,
107 bg: self.bg,
108 align,
109 wrap,
110 max_width,
111 },
112 )
113 }
114
115 pub fn measure_text(&self, text: &str, max_width: Option<usize>, wrap: bool) -> TextMetrics {
117 measure_text(text, max_width, wrap)
118 }
119
120 pub fn blit_rgb(&self, x: usize, y: usize, w: usize, h: usize, pixels: &[RgbColor]) -> bool {
122 blit_rgb(x, y, w, h, pixels)
123 }
124
125 pub fn blit_rgb24(&self, x: usize, y: usize, w: usize, h: usize, bytes: &[u8]) -> bool {
127 blit_rgb24(x, y, w, h, bytes)
128 }
129
130 pub fn blit_rgba(
132 &self,
133 x: usize,
134 y: usize,
135 w: usize,
136 h: usize,
137 bytes: &[u8],
138 global_alpha: u8,
139 ) -> bool {
140 blit_rgba(x, y, w, h, bytes, global_alpha)
141 }
142
143 pub fn blit_sprite_rgba(
145 &self,
146 x: usize,
147 y: usize,
148 sprite: SpriteRgba<'_>,
149 global_alpha: u8,
150 ) -> bool {
151 blit_sprite_rgba(x, y, sprite, global_alpha)
152 }
153
154 pub fn begin_frame(&self) -> bool {
156 begin_frame()
157 }
158
159 pub fn end_frame(&self) {
161 end_frame();
162 }
163
164 pub fn ui_clear(&self, theme: UiTheme) {
166 ui_clear(theme);
167 }
168
169 pub fn ui_panel(
171 &self,
172 x: usize,
173 y: usize,
174 w: usize,
175 h: usize,
176 title: &str,
177 body: &str,
178 theme: UiTheme,
179 ) {
180 ui_draw_panel(x, y, w, h, title, body, theme);
181 }
182
183 pub fn ui_status_bar(&self, left: &str, right: &str, theme: UiTheme) {
185 ui_draw_status_bar(left, right, theme);
186 }
187
188 pub fn system_status_line(&self, theme: UiTheme) {
190 draw_system_status_line(theme);
191 }
192
193 pub fn layout_screen(&self) -> UiDockLayout {
195 UiDockLayout::from_screen()
196 }
197
198 pub fn ui_label(&self, label: &UiLabel<'_>) {
200 ui_draw_label(label);
201 }
202
203 pub fn ui_progress_bar(&self, bar: UiProgressBar) {
205 ui_draw_progress_bar(bar);
206 }
207
208 pub fn ui_table(&self, table: &UiTable) {
210 ui_draw_table(table);
211 }
212}