Changeset 296e124e in mainline for uspace/lib/gui/window.c


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.