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