Changeset 296e124e in mainline


Ignore:
Timestamp:
2014-01-10T17:06:50Z (10 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8bb0f5d6
Parents:
4edd71f6
Message:

improve visual appearance of GUI windows and buttons

Location:
uspace
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/vdemo/vdemo.c

    r4edd71f6 r296e124e  
    117117
    118118                pixel_t grd_bg = PIXEL(255, 240, 240, 240);
    119                 pixel_t btn_bg = PIXEL(255, 0, 0, 0);
    120                 pixel_t btn_fg = PIXEL(255, 240, 240, 240);
     119               
     120                pixel_t btn_bg = PIXEL(255, 240, 240, 240);
     121                pixel_t btn_fg = PIXEL(255, 186, 186, 186);
     122                pixel_t btn_text = PIXEL(255, 0, 0, 0);
     123               
    121124                pixel_t lbl_bg = PIXEL(255, 240, 240, 240);
    122                 pixel_t lbl_fg = PIXEL(255, 0, 0, 0);
     125                pixel_t lbl_text = PIXEL(255, 0, 0, 0);
    123126
    124                 my_label_t *lbl_action = create_my_label(NULL, "Hello there!", 16, lbl_bg, lbl_fg);
    125                 button_t *btn_confirm = create_button(NULL, "Confirm", 16, btn_bg, btn_fg);
    126                 button_t *btn_cancel = create_button(NULL, "Cancel", 16, btn_bg, btn_fg);
     127                my_label_t *lbl_action = create_my_label(NULL, "Hello there!", 16,
     128                    lbl_bg, lbl_text);
     129                button_t *btn_confirm = create_button(NULL, "Confirm", 16, btn_bg,
     130                    btn_fg, btn_text);
     131                button_t *btn_cancel = create_button(NULL, "Cancel", 16, btn_bg,
     132                    btn_fg, btn_text);
    127133                grid_t *grid = create_grid(window_root(main_window), 2, 2, grd_bg);
    128134                if (!lbl_action || !btn_confirm || !btn_cancel || !grid) {
  • uspace/app/vlaunch/vlaunch.c

    r4edd71f6 r296e124e  
    122122       
    123123        pixel_t grd_bg = PIXEL(255, 255, 255, 255);
    124         pixel_t btn_bg = PIXEL(255, 0, 0, 0);
    125         pixel_t btn_fg = PIXEL(255, 240, 240, 240);
     124       
     125        pixel_t btn_bg = PIXEL(255, 255, 255, 255);
     126        pixel_t btn_fg = PIXEL(255, 186, 186, 186);
     127        pixel_t btn_text = PIXEL(255, 0, 0, 0);
     128       
    126129        pixel_t lbl_bg = PIXEL(255, 255, 255, 255);
    127         pixel_t lbl_fg = PIXEL(255, 0, 0, 0);
     130        pixel_t lbl_text = PIXEL(255, 0, 0, 0);
    128131       
    129132        canvas_t *logo_canvas = create_canvas(NULL, LOGO_WIDTH, LOGO_HEIGHT,
    130133            logo);
    131134        label_t *lbl_caption = create_label(NULL, "Launch application:", 16,
    132             lbl_bg, lbl_fg);
     135            lbl_bg, lbl_text);
    133136        button_t *btn_vterm = create_button(NULL, "vterm", 16, btn_bg,
    134             btn_fg);
     137            btn_fg, btn_text);
    135138        button_t *btn_vdemo = create_button(NULL, "vdemo", 16, btn_bg,
    136             btn_fg);
     139            btn_fg, btn_text);
    137140        button_t *btn_vlaunch = create_button(NULL, "vlaunch", 16, btn_bg,
    138             btn_fg);
     141            btn_fg, btn_text);
    139142        grid_t *grid = create_grid(window_root(main_window), 1, 5, grd_bg);
    140143       
  • uspace/app/vterm/vterm.c

    r4edd71f6 r296e124e  
    5555        }
    5656       
    57         window_resize(main_window, 650, 510);
     57        window_resize(main_window, 648, 510);
    5858        terminal_t *terminal_widget =
    5959            create_terminal(window_root(main_window), 640, 480);
  • uspace/lib/gui/Makefile

    r4edd71f6 r296e124e  
    3434
    3535SOURCES = \
     36        common.c \
    3637        button.c \
    3738        canvas.c \
  • uspace/lib/gui/button.c

    r4edd71f6 r296e124e  
    3636#include <str.h>
    3737#include <malloc.h>
    38 
    3938#include <drawctx.h>
    4039#include <surface.h>
    41 
     40#include "common.h"
    4241#include "window.h"
    4342#include "button.h"
    4443
    45 static void paint_internal(widget_t *w)
    46 {
    47         button_t *btn = (button_t *) w;
    48 
     44static pixel_t color_highlight = PIXEL(255, 255, 255, 255);
     45static pixel_t color_shadow = PIXEL(255, 85, 85, 85);
     46
     47static void paint_internal(widget_t *widget)
     48{
     49        button_t *btn = (button_t *) widget;
     50       
    4951        surface_t *surface = window_claim(btn->widget.window);
    50         if (!surface) {
     52        if (!surface)
    5153                window_yield(btn->widget.window);
     54       
     55        source_t source;
     56        source_init(&source);
     57       
     58        drawctx_t drawctx;
     59        drawctx_init(&drawctx, surface);
     60       
     61        drawctx_set_source(&drawctx, &btn->background);
     62        drawctx_transfer(&drawctx, widget->hpos, widget->vpos,
     63            widget->width, widget->height);
     64       
     65        if ((widget->width >= 8) && (widget->height >= 8)) {
     66                drawctx_set_source(&drawctx, &source);
     67                draw_bevel(&drawctx, &source, widget->hpos + 3, widget->vpos + 3,
     68                    widget->width - 6, widget->height - 6, color_highlight,
     69                    color_shadow);
     70               
     71                drawctx_set_source(&drawctx, &btn->foreground);
     72                drawctx_transfer(&drawctx, widget->hpos + 4, widget->vpos + 4,
     73                    widget->width - 8, widget->height - 8);
    5274        }
    53 
    54         drawctx_t drawctx;
    55 
    56         drawctx_init(&drawctx, surface);
    57         drawctx_set_source(&drawctx, &btn->foreground);
    58         drawctx_transfer(&drawctx, w->hpos, w->vpos, w->width, w->height);
    59 
    60         if (w->width >= 6 && w->height >= 6) {
    61                 drawctx_set_source(&drawctx, &btn->background);
    62                 drawctx_transfer(&drawctx,
    63                     w->hpos + 3, w->vpos + 3, w->width - 6, w->height - 6);
    64         }
    65 
     75       
    6676        sysarg_t cpt_width;
    6777        sysarg_t cpt_height;
    6878        font_get_box(&btn->font, btn->caption, &cpt_width, &cpt_height);
    69         if (w->width >= cpt_width && w->height >= cpt_height) {
    70                 drawctx_set_source(&drawctx, &btn->foreground);
     79       
     80        if ((widget->width >= cpt_width) && (widget->height >= cpt_height)) {
     81                sysarg_t x = ((widget->width - cpt_width) / 2) + widget->hpos;
     82                sysarg_t y = ((widget->height - cpt_height) / 2) + widget->vpos;
     83               
     84                drawctx_set_source(&drawctx, &btn->text);
    7185                drawctx_set_font(&drawctx, &btn->font);
    72                 sysarg_t x = ((w->width - cpt_width) / 2) + w->hpos;
    73                 sysarg_t y = ((w->height - cpt_height) / 2) + w->vpos;
    74                 if (btn->caption) {
     86               
     87                if (btn->caption)
    7588                        drawctx_print(&drawctx, btn->caption, x, y);
    76                 }
    7789        }
    78 
     90       
    7991        window_yield(btn->widget.window);
    8092}
     
    90102{
    91103        button_t *btn = (button_t *) widget;
    92 
     104       
    93105        deinit_button(btn);
    94        
    95106        free(btn);
    96107}
     
    117128{
    118129        button_t *btn = (button_t *) widget;
    119         if (event.key == KC_ENTER && event.type == KEY_PRESS) {
     130       
     131        if (event.key == KC_ENTER && event.type == KEY_PRESS)
    120132                sig_send(&btn->clicked, NULL);
    121         }
    122133}
    123134
     
    126137        button_t *btn = (button_t *) widget;
    127138        widget->window->focus = widget;
    128 
     139       
    129140        // TODO make the click logic more robust (mouse grabbing, mouse moves)
    130141        if (event.btn_num == 1) {
    131                 if (event.type == POS_RELEASE) {
     142                if (event.type == POS_RELEASE)
    132143                        sig_send(&btn->clicked, NULL);
    133                 }
    134144        }
    135145}
    136146
    137 bool init_button(button_t *btn, widget_t *parent,
    138     const char *caption, uint16_t points, pixel_t background, pixel_t foreground)
     147bool init_button(button_t *btn, widget_t *parent, const char *caption,
     148    uint16_t points, pixel_t background, pixel_t foreground, pixel_t text)
    139149{
    140150        widget_init(&btn->widget, parent);
    141 
     151       
    142152        btn->widget.destroy = button_destroy;
    143153        btn->widget.reconfigure = button_reconfigure;
     
    146156        btn->widget.handle_keyboard_event = button_handle_keyboard_event;
    147157        btn->widget.handle_position_event = button_handle_position_event;
    148 
     158       
    149159        source_init(&btn->background);
    150160        source_set_color(&btn->background, background);
     161       
    151162        source_init(&btn->foreground);
    152163        source_set_color(&btn->foreground, foreground);
    153 
    154         if (caption == NULL) {
     164       
     165        source_init(&btn->text);
     166        source_set_color(&btn->text, text);
     167       
     168        if (caption == NULL)
    155169                btn->caption = NULL;
    156         } else {
     170        else
    157171                btn->caption = str_dup(caption);
    158         }
     172       
    159173        font_init(&btn->font, FONT_DECODER_EMBEDDED, NULL, points);
    160 
     174       
    161175        sysarg_t cpt_width;
    162176        sysarg_t cpt_height;
    163177        font_get_box(&btn->font, btn->caption, &cpt_width, &cpt_height);
    164         btn->widget.width_min = cpt_width + 8;
    165         btn->widget.height_min = cpt_height + 8;
    166         btn->widget.width_ideal = cpt_width + 28;
    167         btn->widget.height_ideal = cpt_height + 8;
    168 
     178        btn->widget.width_min = cpt_width + 10;
     179        btn->widget.height_min = cpt_height + 10;
     180        btn->widget.width_ideal = cpt_width + 30;
     181        btn->widget.height_ideal = cpt_height + 10;
     182       
    169183        return true;
    170184}
    171185
    172 button_t *create_button(widget_t *parent,
    173     const char *caption, uint16_t points, pixel_t background, pixel_t foreground)
     186button_t *create_button(widget_t *parent, const char *caption, uint16_t points,
     187    pixel_t background, pixel_t foreground, pixel_t text)
    174188{
    175189        button_t *btn = (button_t *) malloc(sizeof(button_t));
    176         if (!btn) {
     190        if (!btn)
    177191                return NULL;
    178         }
    179 
    180         if (init_button(btn, parent, caption, points, background, foreground)) {
     192       
     193        if (init_button(btn, parent, caption, points, background, foreground,
     194            text))
    181195                return btn;
    182         } else {
    183                 free(btn);
    184                 return NULL;
    185         }
     196       
     197        free(btn);
     198        return NULL;
    186199}
    187200
  • uspace/lib/gui/button.h

    r4edd71f6 r296e124e  
    5050        source_t background;
    5151        source_t foreground;
     52        source_t text;
    5253        char *caption;
    5354        font_t font;
     
    5556} button_t;
    5657
    57 extern bool init_button(button_t *, widget_t *, const char *, uint16_t, pixel_t, pixel_t);
    58 extern button_t *create_button(widget_t *, const char *, uint16_t, pixel_t, pixel_t);
     58extern bool init_button(button_t *, widget_t *, const char *, uint16_t, pixel_t,
     59    pixel_t, pixel_t);
     60extern button_t *create_button(widget_t *, const char *, uint16_t, pixel_t,
     61    pixel_t, pixel_t);
    5962extern void deinit_button(button_t *);
    6063
  • uspace/lib/gui/label.c

    r4edd71f6 r296e124e  
    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 
  • uspace/lib/gui/label.h

    r4edd71f6 r296e124e  
    4949        widget_t widget;
    5050        source_t background;
    51         source_t foreground;
     51        source_t text;
    5252        char *caption;
    5353        font_t font;
     
    5555} label_t;
    5656
    57 extern bool init_label(label_t *, widget_t *, const char *, uint16_t, pixel_t, pixel_t);
    58 extern label_t *create_label(widget_t *, const char *, uint16_t, pixel_t, pixel_t);
     57extern bool init_label(label_t *, widget_t *, const char *, uint16_t, pixel_t,
     58    pixel_t);
     59extern label_t *create_label(widget_t *, const char *, uint16_t, pixel_t,
     60    pixel_t);
    5961extern void deinit_label(label_t *);
    6062
  • uspace/lib/gui/window.c

    r4edd71f6 r296e124e  
    5656#include <surface.h>
    5757
     58#include "common.h"
    5859#include "connection.h"
    5960#include "widget.h"
    6061#include "window.h"
    6162
    62 static sysarg_t border_thickness = 5;
    63 static sysarg_t header_height = 20;
     63static sysarg_t border_thickness = 4;
     64static sysarg_t bevel_thickness = 1;
     65static sysarg_t header_height = 22;
    6466static sysarg_t header_min_width = 40;
    65 static sysarg_t close_width = 20;
    66 
    67 static pixel_t border_color = PIXEL(255, 0, 0, 0);
    68 static pixel_t header_bg_focus_color = PIXEL(255, 88, 106, 196);
    69 static pixel_t header_fg_focus_color = PIXEL(255, 255, 255, 255);
    70 static pixel_t header_bg_unfocus_color = PIXEL(255, 12, 57, 92);
    71 static pixel_t header_fg_unfocus_color = PIXEL(255, 255, 255, 255);
    72 
    73 static void paint_internal(widget_t *w)
    74 {
    75         surface_t *surface = window_claim(w->window);
    76         if (!surface) {
    77                 window_yield(w->window);
    78         }
    79 
     67static sysarg_t close_thickness = 22;
     68
     69static pixel_t color_highlight = PIXEL(255, 255, 255, 255);
     70static pixel_t color_shadow = PIXEL(255, 85, 85, 85);
     71static pixel_t color_surface = PIXEL(255, 186, 186, 186);
     72
     73static pixel_t color_header_focus_highlight = PIXEL(255, 120, 145, 255);
     74static pixel_t color_header_focus_shadow = PIXEL(255, 40, 48, 89);
     75static pixel_t color_header_focus_surface = PIXEL(255, 88, 106, 196);
     76
     77static pixel_t color_header_unfocus_highlight = PIXEL(255, 16, 78, 126);
     78static pixel_t color_header_unfocus_shadow = PIXEL(255, 5, 26, 42);
     79static pixel_t color_header_unfocus_surface = PIXEL(255, 12, 57, 92);
     80
     81static pixel_t color_caption_focus = PIXEL(255, 255, 255, 255);
     82static pixel_t color_caption_unfocus = PIXEL(255, 207, 207, 207);
     83
     84static void paint_internal(widget_t *widget)
     85{
     86        surface_t *surface = window_claim(widget->window);
     87        if (!surface)
     88                window_yield(widget->window);
     89       
    8090        source_t source;
    81         font_t font;
     91        source_init(&source);
     92       
    8293        drawctx_t drawctx;
    83 
    84         source_init(&source);
    85         font_init(&font, FONT_DECODER_EMBEDDED, NULL, 16);
    8694        drawctx_init(&drawctx, surface);
    8795        drawctx_set_source(&drawctx, &source);
     96       
     97        /* Window border outer bevel */
     98       
     99        draw_bevel(&drawctx, &source, widget->vpos, widget->hpos,
     100            widget->width, widget->height, color_highlight, color_shadow);
     101       
     102        /* Window border surface */
     103       
     104        source_set_color(&source, color_surface);
     105        drawctx_transfer(&drawctx, widget->hpos + 1, widget->vpos + 1,
     106            widget->width - 2, 2);
     107        drawctx_transfer(&drawctx, widget->hpos + 1, widget->vpos + 1,
     108            2, widget->height - 2);
     109        drawctx_transfer(&drawctx, widget->hpos + 1,
     110            widget->vpos + widget->height - 3, widget->width - 2, 2);
     111        drawctx_transfer(&drawctx, widget->hpos + widget->width - 3,
     112            widget->vpos + 1, 2, widget->height - 4);
     113       
     114        /* Window border inner bevel */
     115       
     116        draw_bevel(&drawctx, &source, widget->hpos + 3, widget->vpos + 3,
     117            widget->width - 6, widget->height - 6, color_shadow,
     118            color_highlight);
     119       
     120        /* Header bevel */
     121       
     122        sysarg_t header_hpos = widget->hpos + border_thickness;
     123        sysarg_t header_vpos = widget->vpos + border_thickness;
     124        sysarg_t header_width = widget->width - 2 * border_thickness -
     125            close_thickness;
     126       
     127        draw_bevel(&drawctx, &source, header_hpos, header_vpos,
     128            header_width, header_height, widget->window->is_focused ?
     129            color_header_focus_highlight : color_header_unfocus_highlight,
     130            widget->window->is_focused ?
     131            color_header_focus_shadow : color_header_unfocus_shadow);
     132       
     133        /* Header surface */
     134       
     135        source_set_color(&source, widget->window->is_focused ?
     136            color_header_focus_surface : color_header_unfocus_surface);
     137        drawctx_transfer(&drawctx, header_hpos + 1, header_vpos + 1,
     138            header_width - 2, header_height - 2);
     139       
     140        /* Close button bevel */
     141       
     142        sysarg_t close_hpos = widget->hpos + widget->width -
     143            border_thickness - close_thickness;
     144        sysarg_t close_vpos = widget->vpos + border_thickness;
     145       
     146        draw_bevel(&drawctx, &source, close_hpos, close_vpos,
     147            close_thickness, close_thickness, color_highlight, color_shadow);
     148       
     149        /* Close button surface */
     150       
     151        source_set_color(&source, color_surface);
     152        drawctx_transfer(&drawctx, close_hpos + 1, close_vpos + 1,
     153            close_thickness - 2, close_thickness - 2);
     154       
     155        /* Close button icon */
     156       
     157        draw_bevel(&drawctx, &source, close_hpos + 6, close_vpos + 9,
     158            close_thickness - 12, close_thickness - 18, color_highlight,
     159            color_shadow);
     160       
     161        /* Window caption */
     162       
     163        font_t font;
     164        font_init(&font, FONT_DECODER_EMBEDDED, NULL, 16);
     165       
    88166        drawctx_set_font(&drawctx, &font);
    89 
    90         source_set_color(&source, border_color);
    91         drawctx_transfer(&drawctx, w->hpos, w->vpos, border_thickness, w->height);
    92         drawctx_transfer(&drawctx, w->hpos + w->width - border_thickness,
    93             w->vpos, border_thickness, w->height);
    94         drawctx_transfer(&drawctx, w->hpos, w->vpos, w->width, border_thickness);
    95         drawctx_transfer(&drawctx, w->hpos,
    96             w->vpos + w->height - border_thickness, w->width, border_thickness);
    97 
    98         source_set_color(&source,
    99             w->window->is_focused ? header_bg_focus_color : header_bg_unfocus_color);
    100         drawctx_transfer(&drawctx,
    101             w->hpos + border_thickness, w->vpos + border_thickness,
    102                 w->width - 2 * border_thickness, header_height);
    103 
     167        source_set_color(&source, widget->window->is_focused ?
     168            color_caption_focus : color_caption_unfocus);
     169       
    104170        sysarg_t cpt_width;
    105171        sysarg_t cpt_height;
    106         font_get_box(&font, w->window->caption, &cpt_width, &cpt_height);
    107         sysarg_t cls_width;
    108         sysarg_t cls_height;
    109         char cls_pict[] = "x";
    110         font_get_box(&font, cls_pict, &cls_width, &cls_height);
    111         source_set_color(&source,
    112             w->window->is_focused ? header_fg_focus_color : header_fg_unfocus_color);
    113         sysarg_t cls_x = ((close_width - cls_width) / 2) + w->hpos + w->width -
    114             border_thickness - close_width;
    115         sysarg_t cls_y = ((header_height - cls_height) / 2) + w->vpos + border_thickness;
    116         drawctx_print(&drawctx, cls_pict, cls_x, cls_y);
    117 
    118         bool draw_title = (w->width >= 2 * border_thickness + close_width + cpt_width);
     172        font_get_box(&font, widget->window->caption, &cpt_width, &cpt_height);
     173       
     174        bool draw_title =
     175            (widget->width >= 2 * border_thickness + 2 * bevel_thickness +
     176            close_thickness + cpt_width);
    119177        if (draw_title) {
    120                 sysarg_t cpt_x = ((w->width - cpt_width) / 2) + w->hpos;
    121                 sysarg_t cpt_y = ((header_height - cpt_height) / 2) + w->vpos + border_thickness;
    122                 if (w->window->caption) {
    123                         drawctx_print(&drawctx, w->window->caption, cpt_x, cpt_y);
    124                 }
    125         }
    126 
     178                sysarg_t cpt_x = ((widget->width - cpt_width) / 2) + widget->hpos;
     179                sysarg_t cpt_y = ((header_height - cpt_height) / 2) +
     180                    widget->vpos + border_thickness;
     181               
     182                if (widget->window->caption)
     183                        drawctx_print(&drawctx, widget->window->caption, cpt_x, cpt_y);
     184        }
     185       
    127186        font_release(&font);
    128         window_yield(w->window);
     187        window_yield(widget->window);
    129188}
    130189
     
    138197        if (widget->window->is_decorated) {
    139198                list_foreach(widget->children, link, widget_t, child) {
    140                         child->rearrange(child, 
     199                        child->rearrange(child,
    141200                            widget->hpos + border_thickness,
    142201                            widget->vpos + border_thickness + header_height,
     
    211270                    (event.vpos >= border_thickness) &&
    212271                    (event.vpos < border_thickness + header_height);
    213                 bool close = header && (event.hpos >= width - border_thickness - close_width);
     272                bool close = (header) &&
     273                    (event.hpos >= width - border_thickness - close_thickness);
    214274
    215275                if (top && left && allowed_button) {
Note: See TracChangeset for help on using the changeset viewer.