Changes in uspace/lib/gui/label.c [296e124e:6d5e378] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gui/label.c
r296e124e r6d5e378 36 36 #include <str.h> 37 37 #include <malloc.h> 38 38 39 #include <drawctx.h> 39 40 #include <surface.h> 41 40 42 #include "window.h" 41 43 #include "label.h" 42 44 43 static void paint_internal(widget_t *w idget)45 static void paint_internal(widget_t *w) 44 46 { 45 label_t *lbl = (label_t *) w idget;47 label_t *lbl = (label_t *) w; 46 48 47 49 surface_t *surface = window_claim(lbl->widget.window); 48 if (!surface) 50 if (!surface) { 49 51 window_yield(lbl->widget.window); 50 52 } 53 51 54 drawctx_t drawctx; 55 52 56 drawctx_init(&drawctx, surface); 53 54 57 drawctx_set_source(&drawctx, &lbl->background); 55 drawctx_transfer(&drawctx, widget->hpos, widget->vpos, widget->width, 56 widget->height); 57 58 drawctx_transfer(&drawctx, w->hpos, w->vpos, w->width, w->height); 59 58 60 sysarg_t cpt_width; 59 61 sysarg_t cpt_height; 60 62 font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height); 61 62 if ((widget->width >= cpt_width) && (widget->height >= cpt_height)) { 63 sysarg_t x = ((widget->width - cpt_width) / 2) + widget->hpos; 64 sysarg_t y = ((widget->height - cpt_height) / 2) + widget->vpos; 65 66 drawctx_set_source(&drawctx, &lbl->text); 63 if (w->width >= cpt_width && w->height >= cpt_height) { 64 drawctx_set_source(&drawctx, &lbl->foreground); 67 65 drawctx_set_font(&drawctx, &lbl->font); 68 69 if (lbl->caption) 66 sysarg_t x = ((w->width - cpt_width) / 2) + w->hpos; 67 sysarg_t y = ((w->height - cpt_height) / 2) + w->vpos; 68 if (lbl->caption) { 70 69 drawctx_print(&drawctx, lbl->caption, x, y); 70 } 71 71 } 72 72 73 73 window_yield(lbl->widget.window); 74 74 } … … 78 78 if (data != NULL) { 79 79 label_t *lbl = (label_t *) widget; 80 81 80 const char *new_caption = (const char *) data; 82 81 lbl->caption = str_dup(new_caption); 83 82 84 83 sysarg_t cpt_width; 85 84 sysarg_t cpt_height; 86 85 font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height); 87 88 86 lbl->widget.width_min = cpt_width + 4; 89 87 lbl->widget.height_min = cpt_height + 4; 90 88 lbl->widget.width_ideal = lbl->widget.width_min; 91 89 lbl->widget.height_ideal = lbl->widget.height_min; 92 90 93 91 window_refresh(lbl->widget.window); 94 92 } … … 105 103 { 106 104 label_t *lbl = (label_t *) widget; 105 106 deinit_label(lbl); 107 107 108 deinit_label(lbl);109 108 free(lbl); 110 109 } … … 138 137 } 139 138 140 bool init_label(label_t *lbl, widget_t *parent, const char *caption,141 uint16_t points, pixel_t background, pixel_t text)139 bool init_label(label_t *lbl, widget_t *parent, 140 const char *caption, uint16_t points, pixel_t background, pixel_t foreground) 142 141 { 143 142 widget_init(&lbl->widget, parent); 144 143 145 144 lbl->widget.destroy = label_destroy; 146 145 lbl->widget.reconfigure = label_reconfigure; … … 149 148 lbl->widget.handle_keyboard_event = label_handle_keyboard_event; 150 149 lbl->widget.handle_position_event = label_handle_position_event; 151 150 152 151 source_init(&lbl->background); 153 152 source_set_color(&lbl->background, background); 154 155 source_init(&lbl->text); 156 source_set_color(&lbl->text, text); 157 158 if (caption == NULL) 153 source_init(&lbl->foreground); 154 source_set_color(&lbl->foreground, foreground); 155 156 if (caption == NULL) { 159 157 lbl->caption = NULL; 160 else158 } else { 161 159 lbl->caption = str_dup(caption); 162 160 } 163 161 font_init(&lbl->font, FONT_DECODER_EMBEDDED, NULL, points); 164 162 165 163 sysarg_t cpt_width; 166 164 sysarg_t cpt_height; 167 165 font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height); 168 169 166 lbl->widget.width_min = cpt_width + 4; 170 167 lbl->widget.height_min = cpt_height + 4; 171 168 lbl->widget.width_ideal = lbl->widget.width_min; 172 169 lbl->widget.height_ideal = lbl->widget.height_min; 173 170 174 171 lbl->rewrite = on_rewrite; 175 172 176 173 return true; 177 174 } 178 175 179 label_t *create_label(widget_t *parent, const char *caption, uint16_t points,180 pixel_t background, pixel_t text)176 label_t *create_label(widget_t *parent, 177 const char *caption, uint16_t points, pixel_t background, pixel_t foreground) 181 178 { 182 179 label_t *lbl = (label_t *) malloc(sizeof(label_t)); 183 if (!lbl) 180 if (!lbl) { 184 181 return NULL; 185 186 if (init_label(lbl, parent, caption, points, background, text)) 182 } 183 184 if (init_label(lbl, parent, caption, points, background, foreground)) { 187 185 return lbl; 188 189 free(lbl); 190 return NULL; 186 } else { 187 free(lbl); 188 return NULL; 189 } 191 190 } 192 191 193 192 /** @} 194 193 */ 194
Note:
See TracChangeset
for help on using the changeset viewer.