Changes in uspace/lib/gui/button.c [5a6cc679:a35b458] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gui/button.c
r5a6cc679 ra35b458 50 50 { 51 51 button_t *btn = (button_t *) widget; 52 52 53 53 surface_t *surface = window_claim(btn->widget.window); 54 54 if (!surface) 55 55 window_yield(btn->widget.window); 56 56 57 57 source_t source; 58 58 source_init(&source); 59 59 60 60 drawctx_t drawctx; 61 61 drawctx_init(&drawctx, surface); 62 62 63 63 drawctx_set_source(&drawctx, &btn->background); 64 64 drawctx_transfer(&drawctx, widget->hpos, widget->vpos, 65 65 widget->width, widget->height); 66 66 67 67 if ((widget->width >= 8) && (widget->height >= 8)) { 68 68 drawctx_set_source(&drawctx, &source); … … 70 70 widget->width - 6, widget->height - 6, color_highlight, 71 71 color_shadow); 72 72 73 73 drawctx_set_source(&drawctx, &btn->foreground); 74 74 drawctx_transfer(&drawctx, widget->hpos + 4, widget->vpos + 4, 75 75 widget->width - 8, widget->height - 8); 76 76 } 77 77 78 78 sysarg_t cpt_width; 79 79 sysarg_t cpt_height; 80 80 font_get_box(btn->font, btn->caption, &cpt_width, &cpt_height); 81 81 82 82 if ((widget->width >= cpt_width) && (widget->height >= cpt_height)) { 83 83 sysarg_t x = ((widget->width - cpt_width) / 2) + widget->hpos; 84 84 sysarg_t y = ((widget->height - cpt_height) / 2) + widget->vpos; 85 85 86 86 drawctx_set_source(&drawctx, &btn->text); 87 87 drawctx_set_font(&drawctx, btn->font); 88 88 89 89 if (btn->caption) 90 90 drawctx_print(&drawctx, btn->caption, x, y); 91 91 } 92 92 93 93 window_yield(btn->widget.window); 94 94 } … … 104 104 { 105 105 button_t *btn = (button_t *) widget; 106 106 107 107 deinit_button(btn); 108 108 free(btn); … … 130 130 { 131 131 button_t *btn = (button_t *) widget; 132 132 133 133 if (event.key == KC_ENTER && event.type == KEY_PRESS) 134 134 sig_send(&btn->clicked, NULL); … … 139 139 button_t *btn = (button_t *) widget; 140 140 widget->window->focus = widget; 141 141 142 142 // TODO make the click logic more robust (mouse grabbing, mouse moves) 143 143 if (event.btn_num == 1) { … … 152 152 { 153 153 widget_init(&btn->widget, parent, data); 154 154 155 155 btn->widget.destroy = button_destroy; 156 156 btn->widget.reconfigure = button_reconfigure; … … 159 159 btn->widget.handle_keyboard_event = button_handle_keyboard_event; 160 160 btn->widget.handle_position_event = button_handle_position_event; 161 161 162 162 source_init(&btn->background); 163 163 source_set_color(&btn->background, background); 164 164 165 165 source_init(&btn->foreground); 166 166 source_set_color(&btn->foreground, foreground); 167 167 168 168 source_init(&btn->text); 169 169 source_set_color(&btn->text, text); 170 170 171 171 if (caption == NULL) 172 172 btn->caption = NULL; 173 173 else 174 174 btn->caption = str_dup(caption); 175 175 176 176 errno_t rc = embedded_font_create(&btn->font, points); 177 177 if (rc != EOK) { … … 180 180 return false; 181 181 } 182 182 183 183 sysarg_t cpt_width; 184 184 sysarg_t cpt_height; … … 188 188 btn->widget.width_ideal = cpt_width + 30; 189 189 btn->widget.height_ideal = cpt_height + 10; 190 190 191 191 return true; 192 192 } … … 198 198 if (!btn) 199 199 return NULL; 200 200 201 201 if (init_button(btn, parent, data, caption, points, background, foreground, 202 202 text)) 203 203 return btn; 204 204 205 205 free(btn); 206 206 return NULL;
Note:
See TracChangeset
for help on using the changeset viewer.