Changeset 5828554 in mainline for uspace/lib/gui/label.c


Ignore:
Timestamp:
2014-01-19T14:37:22Z (10 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cf982ff
Parents:
2f591127 (diff), 476f62c (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.
Message:

merge mainline changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/gui/label.c

    r2f591127 r5828554  
    3636#include <str.h>
    3737#include <malloc.h>
    38 
    3938#include <drawctx.h>
    4039#include <surface.h>
    41 
    4240#include "window.h"
    4341#include "label.h"
    4442
    45 static void paint_internal(widget_t *w)
     43static void paint_internal(widget_t *widget)
    4644{
    47         label_t *lbl = (label_t *) w;
     45        label_t *lbl = (label_t *) widget;
    4846
    4947        surface_t *surface = window_claim(lbl->widget.window);
    50         if (!surface) {
     48        if (!surface)
    5149                window_yield(lbl->widget.window);
    52         }
    53 
     50       
    5451        drawctx_t drawctx;
    55 
    5652        drawctx_init(&drawctx, surface);
     53       
    5754        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       
    6058        sysarg_t cpt_width;
    6159        sysarg_t cpt_height;
    6260        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);
    6567                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)
    6970                        drawctx_print(&drawctx, lbl->caption, x, y);
    70                 }
    7171        }
    72 
     72       
    7373        window_yield(lbl->widget.window);
    7474}
     
    7878        if (data != NULL) {
    7979                label_t *lbl = (label_t *) widget;
     80               
    8081                const char *new_caption = (const char *) data;
    8182                lbl->caption = str_dup(new_caption);
    82 
     83               
    8384                sysarg_t cpt_width;
    8485                sysarg_t cpt_height;
    8586                font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height);
     87               
    8688                lbl->widget.width_min = cpt_width + 4;
    8789                lbl->widget.height_min = cpt_height + 4;
    8890                lbl->widget.width_ideal = lbl->widget.width_min;
    8991                lbl->widget.height_ideal = lbl->widget.height_min;
    90 
     92               
    9193                window_refresh(lbl->widget.window);
    9294        }
     
    103105{
    104106        label_t *lbl = (label_t *) widget;
    105 
     107       
    106108        deinit_label(lbl);
    107        
    108109        free(lbl);
    109110}
     
    137138}
    138139
    139 bool init_label(label_t *lbl, widget_t *parent,
    140     const char *caption, uint16_t points, pixel_t background, pixel_t foreground)
     140bool init_label(label_t *lbl, widget_t *parent, const char *caption,
     141    uint16_t points, pixel_t background, pixel_t text)
    141142{
    142143        widget_init(&lbl->widget, parent);
    143 
     144       
    144145        lbl->widget.destroy = label_destroy;
    145146        lbl->widget.reconfigure = label_reconfigure;
     
    148149        lbl->widget.handle_keyboard_event = label_handle_keyboard_event;
    149150        lbl->widget.handle_position_event = label_handle_position_event;
    150 
     151       
    151152        source_init(&lbl->background);
    152153        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)
    157159                lbl->caption = NULL;
    158         } else {
     160        else
    159161                lbl->caption = str_dup(caption);
    160         }
     162       
    161163        font_init(&lbl->font, FONT_DECODER_EMBEDDED, NULL, points);
    162 
     164       
    163165        sysarg_t cpt_width;
    164166        sysarg_t cpt_height;
    165167        font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height);
     168       
    166169        lbl->widget.width_min = cpt_width + 4;
    167170        lbl->widget.height_min = cpt_height + 4;
    168171        lbl->widget.width_ideal = lbl->widget.width_min;
    169172        lbl->widget.height_ideal = lbl->widget.height_min;
    170 
     173       
    171174        lbl->rewrite = on_rewrite;
    172 
     175       
    173176        return true;
    174177}
    175178
    176 label_t *create_label(widget_t *parent,
    177     const char *caption, uint16_t points, pixel_t background, pixel_t foreground)
     179label_t *create_label(widget_t *parent, const char *caption, uint16_t points,
     180    pixel_t background, pixel_t text)
    178181{
    179182        label_t *lbl = (label_t *) malloc(sizeof(label_t));
    180         if (!lbl) {
     183        if (!lbl)
    181184                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))
    185187                return lbl;
    186         } else {
    187                 free(lbl);
    188                 return NULL;
    189         }
     188       
     189        free(lbl);
     190        return NULL;
    190191}
    191192
    192193/** @}
    193194 */
    194 
Note: See TracChangeset for help on using the changeset viewer.