Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/src/wdecor.c

    r252d03c rb48e680f  
    6161        wdecor_edge_h = 4,
    6262        wdecor_tbar_h = 22,
    63         wdecor_tbar_h_text = 1,
    6463        wdecor_frame_w = 4,
    6564        wdecor_frame_w_text = 1
     
    160159}
    161160
     161/** Change caption.
     162 *
     163 * @param wdecor Window decoration
     164 * @param caption New caption
     165 *
     166 * @return EOK on success or an error code
     167 */
     168errno_t ui_wdecor_set_caption(ui_wdecor_t *wdecor, const char *caption)
     169{
     170        char *cdup;
     171
     172        cdup = str_dup(caption);
     173        if (cdup == NULL)
     174                return ENOMEM;
     175
     176        free(wdecor->caption);
     177        wdecor->caption = cdup;
     178
     179        ui_wdecor_paint(wdecor);
     180        return EOK;
     181}
     182
    162183/** Paint window decoration.
    163184 *
     
    170191        gfx_rect_t rect;
    171192        gfx_rect_t trect;
     193        gfx_rect_t text_rect;
    172194        gfx_text_fmt_t fmt;
    173195        gfx_coord2_t pos;
     
    180202
    181203                if (wdecor->res->textmode != false) {
    182                         rc = ui_paint_bevel(wdecor->res->gc, &rect,
    183                             wdecor->res->wnd_frame_hi_color,
    184                             wdecor->res->wnd_frame_sh_color, 1, &rect);
     204                        rc = ui_paint_text_box(wdecor->res, &rect,
     205                            ui_box_double, wdecor->res->wnd_face_color);
    185206                        if (rc != EOK)
    186207                                return rc;
     
    208229                        if (rc != EOK)
    209230                                return rc;
     231
     232                        rc = gfx_set_color(wdecor->res->gc, wdecor->active ?
     233                            wdecor->res->tbar_act_bg_color :
     234                            wdecor->res->tbar_inact_bg_color);
     235                        if (rc != EOK)
     236                                return rc;
     237
     238                        rc = gfx_fill_rect(wdecor->res->gc, &trect);
     239                        if (rc != EOK)
     240                                return rc;
    210241                }
    211 
    212                 rc = gfx_set_color(wdecor->res->gc, wdecor->active ?
    213                     wdecor->res->tbar_act_bg_color :
    214                     wdecor->res->tbar_inact_bg_color);
    215                 if (rc != EOK)
    216                         return rc;
    217 
    218                 rc = gfx_fill_rect(wdecor->res->gc, &trect);
    219                 if (rc != EOK)
    220                         return rc;
    221242
    222243                gfx_text_fmt_init(&fmt);
     
    230251                pos.y = (trect.p0.y + trect.p1.y) / 2;
    231252
     253                if (wdecor->res->textmode) {
     254                        /* Make space around caption text */
     255                        gfx_text_rect(wdecor->res->font, &pos, &fmt,
     256                            wdecor->caption, &text_rect);
     257
     258                        /* Only make space if caption is non-empty */
     259                        if (text_rect.p0.x < text_rect.p1.x) {
     260                                text_rect.p0.x -= 1;
     261                                text_rect.p1.x += 1;
     262                        }
     263
     264                        rc = gfx_set_color(wdecor->res->gc, wdecor->active ?
     265                            wdecor->res->tbar_act_bg_color :
     266                            wdecor->res->tbar_inact_bg_color);
     267                        if (rc != EOK)
     268                                return rc;
     269
     270                        rc = gfx_fill_rect(wdecor->res->gc, &text_rect);
     271                        if (rc != EOK)
     272                                return rc;
     273                }
     274
    232275                rc = gfx_puttext(wdecor->res->font, &pos, &fmt, wdecor->caption);
    233276                if (rc != EOK)
     
    301344{
    302345        gfx_coord_t frame_w;
    303         gfx_coord_t tbar_h;
    304346
    305347        /* Does window have a frame? */
     
    318360        /* Does window have a title bar? */
    319361        if ((wdecor->style & ui_wds_titlebar) != 0) {
    320                 tbar_h = wdecor->res->textmode ?
    321                     wdecor_tbar_h_text : wdecor_tbar_h;
    322 
    323                 geom->title_bar_rect.p0 = geom->interior_rect.p0;
    324                 geom->title_bar_rect.p1.x = geom->interior_rect.p1.x;
    325                 geom->title_bar_rect.p1.y = geom->interior_rect.p0.y + tbar_h;
     362                if (wdecor->res->textmode) {
     363                        geom->title_bar_rect.p0 = wdecor->rect.p0;
     364                        geom->title_bar_rect.p1.x = wdecor->rect.p1.x;
     365                        geom->title_bar_rect.p1.y = wdecor->rect.p0.y + 1;
     366                } else {
     367                        geom->title_bar_rect.p0 = geom->interior_rect.p0;
     368                        geom->title_bar_rect.p1.x = geom->interior_rect.p1.x;
     369                        geom->title_bar_rect.p1.y = geom->interior_rect.p0.y +
     370                            wdecor_tbar_h;
     371                }
    326372
    327373                geom->app_area_rect.p0.x = geom->interior_rect.p0.x;
Note: See TracChangeset for help on using the changeset viewer.