strat9_kernel/arch/x86_64/vga/
canvas.rs1use super::{
26 api::*,
27 status_line::{draw_system_status_line, ui_draw_status_bar},
28 types::*,
29};
30
31pub struct Canvas {
32 fg: RgbColor,
33 bg: RgbColor,
34}
35
36impl Default for Canvas {
37 fn default() -> Self {
39 Self {
40 fg: RgbColor::LIGHT_GREY,
41 bg: RgbColor::BLACK,
42 }
43 }
44}
45
46impl Canvas {
47 pub const fn new(fg: RgbColor, bg: RgbColor) -> Self {
49 Self { fg, bg }
50 }
51
52 pub fn set_fg(&mut self, fg: RgbColor) {
54 self.fg = fg;
55 }
56
57 pub fn set_bg(&mut self, bg: RgbColor) {
59 self.bg = bg;
60 }
61
62 pub fn set_colors(&mut self, fg: RgbColor, bg: RgbColor) {
64 self.fg = fg;
65 self.bg = bg;
66 }
67
68 pub fn set_clip_rect(&self, x: usize, y: usize, w: usize, h: usize) {
70 set_clip_rect(x, y, w, h);
71 }
72
73 pub fn reset_clip_rect(&self) {
75 reset_clip_rect();
76 }
77
78 pub fn clear(&self) {
80 fill_rect(0, 0, width(), height(), self.bg);
81 }
82
83 pub fn pixel(&self, x: usize, y: usize) {
85 draw_pixel(x, y, self.fg);
86 }
87
88 pub fn line(&self, x0: isize, y0: isize, x1: isize, y1: isize) {
90 draw_line(x0, y0, x1, y1, self.fg);
91 }
92
93 pub fn rect(&self, x: usize, y: usize, w: usize, h: usize) {
95 draw_rect(x, y, w, h, self.fg);
96 }
97
98 pub fn fill_rect(&self, x: usize, y: usize, w: usize, h: usize) {
100 fill_rect(x, y, w, h, self.fg);
101 }
102
103 pub fn fill_rect_alpha(&self, x: usize, y: usize, w: usize, h: usize, alpha: u8) {
105 fill_rect_alpha(x, y, w, h, self.fg, alpha);
106 }
107
108 pub fn text(&self, x: usize, y: usize, text: &str) {
110 draw_text_at(x, y, text, self.fg, self.bg);
111 }
112
113 pub fn text_opts(
115 &self,
116 x: usize,
117 y: usize,
118 text: &str,
119 align: TextAlign,
120 wrap: bool,
121 max_width: Option<usize>,
122 ) -> TextMetrics {
123 draw_text(
124 x,
125 y,
126 text,
127 TextOptions {
128 fg: self.fg,
129 bg: self.bg,
130 align,
131 wrap,
132 max_width,
133 },
134 )
135 }
136
137 pub fn measure_text(&self, text: &str, max_width: Option<usize>, wrap: bool) -> TextMetrics {
139 measure_text(text, max_width, wrap)
140 }
141
142 pub fn blit_rgb(&self, x: usize, y: usize, w: usize, h: usize, pixels: &[RgbColor]) -> bool {
144 blit_rgb(x, y, w, h, pixels)
145 }
146
147 pub fn blit_rgb24(&self, x: usize, y: usize, w: usize, h: usize, bytes: &[u8]) -> bool {
149 blit_rgb24(x, y, w, h, bytes)
150 }
151
152 pub fn blit_rgba(
154 &self,
155 x: usize,
156 y: usize,
157 w: usize,
158 h: usize,
159 bytes: &[u8],
160 global_alpha: u8,
161 ) -> bool {
162 blit_rgba(x, y, w, h, bytes, global_alpha)
163 }
164
165 pub fn blit_sprite_rgba(
167 &self,
168 x: usize,
169 y: usize,
170 sprite: SpriteRgba<'_>,
171 global_alpha: u8,
172 ) -> bool {
173 blit_sprite_rgba(x, y, sprite, global_alpha)
174 }
175
176 pub fn begin_frame(&self) -> bool {
178 begin_frame()
179 }
180
181 pub fn end_frame(&self) {
183 end_frame();
184 }
185
186 pub fn ui_clear(&self, theme: UiTheme) {
188 ui_clear(theme);
189 }
190
191 pub fn ui_panel(
193 &self,
194 x: usize,
195 y: usize,
196 w: usize,
197 h: usize,
198 title: &str,
199 body: &str,
200 theme: UiTheme,
201 ) {
202 ui_draw_panel(x, y, w, h, title, body, theme);
203 }
204
205 pub fn ui_status_bar(&self, left: &str, right: &str, theme: UiTheme) {
207 ui_draw_status_bar(left, right, theme);
208 }
209
210 pub fn system_status_line(&self, theme: UiTheme) {
212 draw_system_status_line(theme);
213 }
214
215 pub fn layout_screen(&self) -> UiDockLayout {
217 UiDockLayout::from_screen()
218 }
219
220 pub fn ui_label(&self, label: &UiLabel<'_>) {
222 ui_draw_label(label);
223 }
224
225 pub fn ui_progress_bar(&self, bar: UiProgressBar) {
227 ui_draw_progress_bar(bar);
228 }
229
230 pub fn ui_table(&self, table: &UiTable) {
232 ui_draw_table(table);
233 }
234}