SayoriOS  0.3.3
widget_button.c
1 #include <kernel.h>
2 #include "desktop/widget.h"
3 #include "desktop/widget_button.h"
4 #include "gui/basics.h"
5 #include "io/serial_port.h"
6 
7 void destroy_widget_button(Widget_t* widget);
8 
9 void widget_button_renderer(struct Widget* this, struct Window* container) {
10  Widget_Button_t* this_object = (Widget_Button_t*)(this->custom_widget_data);
11 
12  /*
13  qemu_log("DATA: W: %d H: %d X: %d Y: %d COLOR: %x LABEL_COLOR: %x LABEL_ADDRESS: %x",
14  this->width, this->height,
15  this->x, this->y,
16  this_object->color, this_object->label_color,
17  this_object->label);*/
18  // qemu_log("WIDGET AT: %x; IT's DATA: %x", this, this->custom_widget_data);
19 
20  draw_rectangle(this->x, this->y, this->width, this->height, 0);
21  draw_rectangle(this->x-1, this->y-1, this->width+1, this->height+1, 0);
22  draw_filled_rectangle(
23  this->x, this->y,
24  this->width, this->height,
25  this_object->color
26  );
27 
28  draw_vga_str(this_object->label, strlen(this_object->label),
29  this->x + 5,
30  this->y + (this->height - 16)/2,
31  this_object->label_color
32  );
33  // setColorFont(color);
34 }
35 
36 Widget_t* new_widget_button(char* label, uint32_t color, uint32_t label_color) {
37  Widget_t* wgt = new_bare_widget(
38  &widget_button_renderer,
39  &destroy_widget_button,
40  0, 0,
41  8*(strlen(label)), 10
42  );
43 
44  wgt->custom_widget_data = kcalloc(sizeof(Widget_Button_t), 1);
45 
46  Widget_Button_t* wgt_data = (Widget_Button_t*)wgt->custom_widget_data;
47  wgt_data->label = label;
48  wgt_data->label_color = label_color;
49  wgt_data->color = color;
50 
51  qemu_log("Created Widget Button at: %x", wgt);
52  qemu_log("Created Widget Button DATA at: %x", wgt->custom_widget_data);
53 
54  return wgt;
55 }
56 
57 void destroy_widget_button(Widget_t* widget) {
58  qemu_log("Widget button destroy its data at: %x", widget->custom_widget_data);
59  kfree(widget->custom_widget_data);
60 }
61 
size_t strlen(const char *str)
Возращает длину строки
Definition: string.c:88
Definition: widget.h:12
Definition: window.h:25