1 #include "gui/basics.h"
2 #include "gui/pointutils.h"
3 #include "desktop/window.h"
4 #include "desktop/render.h"
7 #include "drv/input/mouse.h"
13 bool dragging_mode =
false;
23 destroy_all_windows();
29 void gui_render_widgets(
Window_t* window) {
30 for (
size_t i = 0; i < window->widgets->size; i++) {
36 wgt->renderer(wgt, window);
43 void gui_render_window(
Window_t* window) {
45 if(window->state != DISPLAYING)
return;
48 draw_filled_rectangle(
53 window->canvas_bgcolor
56 draw_rectangle(window->x-1, window->y-1, window->width+1, window->height+1, 0x000000);
58 if(window->with_title_bar) {
60 draw_filled_rectangle(window->x, window->y - WINDOW_TITLEBAR_HEIGHT, window->width, WINDOW_TITLEBAR_HEIGHT, WINDOW_TITLEBAR_COLOR);
62 draw_vga_str(window->title,
strlen(window->title), window->x + 5, window->y - ((WINDOW_TITLEBAR_HEIGHT + 16) / 2), 0);
65 if(window->closable) {
66 draw_filled_rectangle(window->x + window->width - WINDOW_TITLEBAR_HEIGHT - 4, window->y - WINDOW_TITLEBAR_HEIGHT + 2, WINDOW_TITLEBAR_HEIGHT + 2, WINDOW_TITLEBAR_HEIGHT - 4, 0xdd0000);
69 window->x + window->width - WINDOW_TITLEBAR_HEIGHT + 5,
70 window->y - WINDOW_TITLEBAR_HEIGHT + 4,
75 gui_render_widgets(window);
78 Window_t* is_point_on_any_window_titlebar(
size_t x,
size_t y) {
79 for (
size_t i = 0; i < get_window_count(); i++) {
80 struct Window* window = WINDOW(i);
82 if(window->with_title_bar && point_in_rect(
86 window->y - WINDOW_TITLEBAR_HEIGHT,
88 WINDOW_TITLEBAR_HEIGHT
96 Window_t* is_point_on_any_window(ssize_t x, ssize_t y) {
97 for (
size_t i = get_window_count() - 1; i != 0 ; i--) {
114 size_t get_window_index(
Window_t* win) {
115 for(
size_t i = 0, wnds = get_window_count(); i < wnds; i++){
116 if(WINDOW(i) == win) {
124 void gui_handle_mouse() {
125 uint32_t mouse_color = 0xff0000;
127 size_t mouse_x = mouse_get_x();
128 size_t mouse_y = mouse_get_y();
130 bool left_mouse = mouse_get_b1();
131 bool right_mouse = mouse_get_b2();
134 mouse_color |= 0x00ff;
136 mouse_color = 0x00ff00;
141 if(tmp && tmp->with_title_bar) {
145 tmp->x + tmp->width - WINDOW_TITLEBAR_HEIGHT - 4,
146 tmp->y - WINDOW_TITLEBAR_HEIGHT + 2,
147 WINDOW_TITLEBAR_HEIGHT + 2,
148 WINDOW_TITLEBAR_HEIGHT - 4
149 ) && !dragging_mode) {
155 }
else if(!dragging_mode){
157 dragging_mode =
true;
159 dragx = drag_window->x -
mouse_x;
160 dragy = drag_window->y -
mouse_y;
162 size_t sw = get_window_index(tmp);
163 size_t mw = get_window_index(focused);
169 vector_swap(windows, sw, mw);
176 if(win && !dragging_mode && !click) {
182 qemu_log(
"End of click");
189 drag_window->x =
mouse_x + dragx;
190 drag_window->y =
mouse_y + dragy;
193 if(dragging_mode && (!left_mouse)) {
195 dragging_mode =
false;
198 if(click && (!left_mouse)) {
205 void gui_render_windows() {
206 for(
size_t i = 0, wnds = get_window_count(); i < wnds; i++){
208 gui_render_window(WINDOW(i));
215 draw_filled_rectangle(0, 0, getScreenWidth(), getScreenHeight(), 0x666666);
216 draw_vga_str(
"No windows in the system.", 25, (getScreenWidth() - 25 * 8) / 2, (getScreenHeight() - 8) / 2, 0);
224 gui_render_windows();
size_t strlen(const char *str)
Возращает длину строки
uint32_t mouse_x
Позиция мыши по X.
uint32_t mouse_y
Позиция мыши по Y.