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