Changeset 172188a in mainline for uspace/lib/ui/src/wdecor.c


Ignore:
Timestamp:
2020-10-21T21:26:56Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a2f173b
Parents:
20d2c6c
Message:

Centralize computation of window decoration geometry

File:
1 edited

Legend:

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

    r20d2c6c r172188a  
    126126void ui_wdecor_set_rect(ui_wdecor_t *wdecor, gfx_rect_t *rect)
    127127{
    128         gfx_rect_t crect;
     128        ui_wdecor_geom_t geom;
    129129
    130130        wdecor->rect = *rect;
    131         crect.p0.x = rect->p1.x - 5 - 20;
    132         crect.p0.y = rect->p0.y + 5;
    133         crect.p1.x = rect->p1.x - 5;
    134         crect.p1.y = rect->p0.y + 5 + 20;
    135 
    136         ui_pbutton_set_rect(wdecor->btn_close, &crect);
     131
     132        ui_wdecor_get_geom(wdecor, &geom);
     133        ui_pbutton_set_rect(wdecor->btn_close, &geom.btn_close_rect);
    137134}
    138135
     
    161158        gfx_text_fmt_t fmt;
    162159        gfx_coord2_t pos;
     160        ui_wdecor_geom_t geom;
    163161
    164162        rect = wdecor->rect;
     163        ui_wdecor_get_geom(wdecor, &geom);
    165164
    166165        rc = ui_paint_bevel(wdecor->res->gc, &rect,
     
    182181                return rc;
    183182
    184         trect.p0 = rect.p0;
    185         trect.p1.x = rect.p1.x;
    186         trect.p1.y = rect.p0.y + 22;
     183        trect = geom.title_bar_rect;
    187184
    188185        rc = ui_paint_bevel(wdecor->res->gc, &trect,
     
    248245}
    249246
     247/** Get window decoration geometry.
     248 *
     249 * @param wdecor Window decoration
     250 * @param geom Structure to fill in with computed geometry
     251 */
     252void ui_wdecor_get_geom(ui_wdecor_t *wdecor, ui_wdecor_geom_t *geom)
     253{
     254        geom->interior_rect.p0.x = wdecor->rect.p0.x + 4;
     255        geom->interior_rect.p0.y = wdecor->rect.p0.y + 4;
     256        geom->interior_rect.p1.x = wdecor->rect.p1.x - 4;
     257        geom->interior_rect.p1.y = wdecor->rect.p1.y - 4;
     258
     259        geom->title_bar_rect.p0 = geom->interior_rect.p0;
     260        geom->title_bar_rect.p1.x = geom->interior_rect.p1.x;
     261        geom->title_bar_rect.p1.y = geom->interior_rect.p0.y + 22;
     262
     263        geom->btn_close_rect.p0.x = geom->title_bar_rect.p1.x - 1 - 20;
     264        geom->btn_close_rect.p0.y = geom->title_bar_rect.p0.y + 1;
     265        geom->btn_close_rect.p1.x = geom->title_bar_rect.p1.x - 1;
     266        geom->btn_close_rect.p1.y = geom->title_bar_rect.p0.y + 1 + 20;
     267
     268        geom->app_area_rect.p0.x = geom->interior_rect.p0.x;
     269        geom->app_area_rect.p0.y = geom->title_bar_rect.p1.y;
     270        geom->app_area_rect.p1 = geom->interior_rect.p1;
     271}
     272
    250273/** Handle window decoration position event.
    251274 *
     
    255278void ui_wdecor_pos_event(ui_wdecor_t *wdecor, pos_event_t *event)
    256279{
    257         gfx_rect_t trect;
    258         gfx_rect_t cbrect;
    259280        gfx_coord2_t pos;
    260 
    261         trect.p0.x = wdecor->rect.p0.x + 3;
    262         trect.p0.y = wdecor->rect.p0.y + 3;
    263         trect.p1.x = wdecor->rect.p1.x - 3;
    264         trect.p1.y = trect.p0.y + 22;
    265 
    266         cbrect.p0.x = wdecor->rect.p1.x - 5 - 20;
    267         cbrect.p0.y = wdecor->rect.p0.y + 5;
    268         cbrect.p1.x = wdecor->rect.p1.x - 5;
    269         cbrect.p1.y = wdecor->rect.p0.y + 5 + 20;
     281        ui_wdecor_geom_t geom;
    270282
    271283        pos.x = event->hpos;
    272284        pos.y = event->vpos;
    273285
    274         if (gfx_pix_inside_rect(&pos, &cbrect)) {
     286        ui_wdecor_get_geom(wdecor, &geom);
     287
     288        if (gfx_pix_inside_rect(&pos, &geom.btn_close_rect)) {
    275289                ui_pbutton_pos_event(wdecor->btn_close, event);
    276290                return;
    277291        }
    278292
    279         if (event->type == POS_PRESS && gfx_pix_inside_rect(&pos, &trect))
     293        if (event->type == POS_PRESS &&
     294            gfx_pix_inside_rect(&pos, &geom.title_bar_rect))
    280295                ui_wdecor_move(wdecor, &pos);
    281296}
Note: See TracChangeset for help on using the changeset viewer.