Changeset 19b3cc6 in mainline for uspace/lib/gui/label.c
- Timestamp:
- 2014-01-17T23:12:10Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e26a9d95
- Parents:
- fddffb2 (diff), facc34d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gui/label.c
rfddffb2 r19b3cc6 36 36 #include <str.h> 37 37 #include <malloc.h> 38 39 38 #include <drawctx.h> 40 39 #include <surface.h> 41 42 40 #include "window.h" 43 41 #include "label.h" 44 42 45 static void paint_internal(widget_t *w )43 static void paint_internal(widget_t *widget) 46 44 { 47 label_t *lbl = (label_t *) w ;45 label_t *lbl = (label_t *) widget; 48 46 49 47 surface_t *surface = window_claim(lbl->widget.window); 50 if (!surface) {48 if (!surface) 51 49 window_yield(lbl->widget.window); 52 } 53 50 54 51 drawctx_t drawctx; 55 56 52 drawctx_init(&drawctx, surface); 53 57 54 drawctx_set_source(&drawctx, &lbl->background); 58 drawctx_transfer(&drawctx, w->hpos, w->vpos, w->width, w->height); 59 55 drawctx_transfer(&drawctx, widget->hpos, widget->vpos, widget->width, 56 widget->height); 57 60 58 sysarg_t cpt_width; 61 59 sysarg_t cpt_height; 62 60 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); 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); 65 67 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) { 68 69 if (lbl->caption) 69 70 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 80 81 const char *new_caption = (const char *) data; 81 82 lbl->caption = str_dup(new_caption); 82 83 83 84 sysarg_t cpt_width; 84 85 sysarg_t cpt_height; 85 86 font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height); 87 86 88 lbl->widget.width_min = cpt_width + 4; 87 89 lbl->widget.height_min = cpt_height + 4; 88 90 lbl->widget.width_ideal = lbl->widget.width_min; 89 91 lbl->widget.height_ideal = lbl->widget.height_min; 90 92 91 93 window_refresh(lbl->widget.window); 92 94 } … … 103 105 { 104 106 label_t *lbl = (label_t *) widget; 105 107 106 108 deinit_label(lbl); 107 108 109 free(lbl); 109 110 } … … 137 138 } 138 139 139 bool init_label(label_t *lbl, widget_t *parent, 140 const char *caption, uint16_t points, pixel_t background, pixel_t foreground)140 bool init_label(label_t *lbl, widget_t *parent, const char *caption, 141 uint16_t points, pixel_t background, pixel_t text) 141 142 { 142 143 widget_init(&lbl->widget, parent); 143 144 144 145 lbl->widget.destroy = label_destroy; 145 146 lbl->widget.reconfigure = label_reconfigure; … … 148 149 lbl->widget.handle_keyboard_event = label_handle_keyboard_event; 149 150 lbl->widget.handle_position_event = label_handle_position_event; 150 151 151 152 source_init(&lbl->background); 152 153 source_set_color(&lbl->background, background); 153 source_init(&lbl->foreground); 154 source_set_color(&lbl->foreground, foreground); 155 156 if (caption == NULL) { 154 155 source_init(&lbl->text); 156 source_set_color(&lbl->text, text); 157 158 if (caption == NULL) 157 159 lbl->caption = NULL; 158 } else {160 else 159 161 lbl->caption = str_dup(caption); 160 }162 161 163 font_init(&lbl->font, FONT_DECODER_EMBEDDED, NULL, points); 162 164 163 165 sysarg_t cpt_width; 164 166 sysarg_t cpt_height; 165 167 font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height); 168 166 169 lbl->widget.width_min = cpt_width + 4; 167 170 lbl->widget.height_min = cpt_height + 4; 168 171 lbl->widget.width_ideal = lbl->widget.width_min; 169 172 lbl->widget.height_ideal = lbl->widget.height_min; 170 173 171 174 lbl->rewrite = on_rewrite; 172 175 173 176 return true; 174 177 } 175 178 176 label_t *create_label(widget_t *parent, 177 const char *caption, uint16_t points, pixel_t background, pixel_t foreground)179 label_t *create_label(widget_t *parent, const char *caption, uint16_t points, 180 pixel_t background, pixel_t text) 178 181 { 179 182 label_t *lbl = (label_t *) malloc(sizeof(label_t)); 180 if (!lbl) {183 if (!lbl) 181 184 return NULL; 182 } 183 184 if (init_label(lbl, parent, caption, points, background, foreground)) { 185 186 if (init_label(lbl, parent, caption, points, background, text)) 185 187 return lbl; 186 } else { 187 free(lbl); 188 return NULL; 189 } 188 189 free(lbl); 190 return NULL; 190 191 } 191 192 192 193 /** @} 193 194 */ 194
Note:
See TracChangeset
for help on using the changeset viewer.