Changeset 172188a in mainline


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

Location:
uspace/lib/ui
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/private/wdecor.h

    r20d2c6c r172188a  
    6363};
    6464
     65/** Window decoration geometry.
     66 *
     67 * Computed rectangles of window decoration elements.
     68 */
     69typedef struct {
     70        /** Interior rectangle */
     71        gfx_rect_t interior_rect;
     72        /** Title bar rectangle */
     73        gfx_rect_t title_bar_rect;
     74        /** Close button rectangle */
     75        gfx_rect_t btn_close_rect;
     76        /** Application area rectangle */
     77        gfx_rect_t app_area_rect;
     78} ui_wdecor_geom_t;
     79
    6580extern void ui_wdecor_close(ui_wdecor_t *);
    6681extern void ui_wdecor_move(ui_wdecor_t *, gfx_coord2_t *);
     82extern void ui_wdecor_get_geom(ui_wdecor_t *, ui_wdecor_geom_t *);
    6783
    6884#endif
  • 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}
  • uspace/lib/ui/test/wdecor.c

    r20d2c6c r172188a  
    310310}
    311311
     312PCUT_TEST(get_geom)
     313{
     314        ui_wdecor_t *wdecor;
     315        gfx_rect_t rect;
     316        ui_wdecor_geom_t geom;
     317        errno_t rc;
     318
     319        rc = ui_wdecor_create(NULL, "Hello", &wdecor);
     320        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     321
     322        rect.p0.x = 10;
     323        rect.p0.y = 20;
     324        rect.p1.x = 100;
     325        rect.p1.y = 200;
     326
     327        ui_wdecor_set_rect(wdecor, &rect);
     328        ui_wdecor_get_geom(wdecor, &geom);
     329
     330        PCUT_ASSERT_INT_EQUALS(14, geom.interior_rect.p0.x);
     331        PCUT_ASSERT_INT_EQUALS(24, geom.interior_rect.p0.y);
     332        PCUT_ASSERT_INT_EQUALS(96, geom.interior_rect.p1.x);
     333        PCUT_ASSERT_INT_EQUALS(196, geom.interior_rect.p1.y);
     334
     335        PCUT_ASSERT_INT_EQUALS(14, geom.title_bar_rect.p0.x);
     336        PCUT_ASSERT_INT_EQUALS(24, geom.title_bar_rect.p0.y);
     337        PCUT_ASSERT_INT_EQUALS(96, geom.title_bar_rect.p1.x);
     338        PCUT_ASSERT_INT_EQUALS(46, geom.title_bar_rect.p1.y);
     339
     340        PCUT_ASSERT_INT_EQUALS(75, geom.btn_close_rect.p0.x);
     341        PCUT_ASSERT_INT_EQUALS(25, geom.btn_close_rect.p0.y);
     342        PCUT_ASSERT_INT_EQUALS(95, geom.btn_close_rect.p1.x);
     343        PCUT_ASSERT_INT_EQUALS(45, geom.btn_close_rect.p1.y);
     344
     345        PCUT_ASSERT_INT_EQUALS(14, geom.app_area_rect.p0.x);
     346        PCUT_ASSERT_INT_EQUALS(46, geom.app_area_rect.p0.y);
     347        PCUT_ASSERT_INT_EQUALS(96, geom.app_area_rect.p1.x);
     348        PCUT_ASSERT_INT_EQUALS(196, geom.app_area_rect.p1.y);
     349
     350        ui_wdecor_destroy(wdecor);
     351}
     352
    312353static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    313354{
Note: See TracChangeset for help on using the changeset viewer.