Changeset 172188a in mainline
- Timestamp:
- 2020-10-21T21:26:56Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a2f173b
- Parents:
- 20d2c6c
- Location:
- uspace/lib/ui
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/private/wdecor.h
r20d2c6c r172188a 63 63 }; 64 64 65 /** Window decoration geometry. 66 * 67 * Computed rectangles of window decoration elements. 68 */ 69 typedef 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 65 80 extern void ui_wdecor_close(ui_wdecor_t *); 66 81 extern void ui_wdecor_move(ui_wdecor_t *, gfx_coord2_t *); 82 extern void ui_wdecor_get_geom(ui_wdecor_t *, ui_wdecor_geom_t *); 67 83 68 84 #endif -
uspace/lib/ui/src/wdecor.c
r20d2c6c r172188a 126 126 void ui_wdecor_set_rect(ui_wdecor_t *wdecor, gfx_rect_t *rect) 127 127 { 128 gfx_rect_t crect;128 ui_wdecor_geom_t geom; 129 129 130 130 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); 137 134 } 138 135 … … 161 158 gfx_text_fmt_t fmt; 162 159 gfx_coord2_t pos; 160 ui_wdecor_geom_t geom; 163 161 164 162 rect = wdecor->rect; 163 ui_wdecor_get_geom(wdecor, &geom); 165 164 166 165 rc = ui_paint_bevel(wdecor->res->gc, &rect, … … 182 181 return rc; 183 182 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; 187 184 188 185 rc = ui_paint_bevel(wdecor->res->gc, &trect, … … 248 245 } 249 246 247 /** Get window decoration geometry. 248 * 249 * @param wdecor Window decoration 250 * @param geom Structure to fill in with computed geometry 251 */ 252 void 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 250 273 /** Handle window decoration position event. 251 274 * … … 255 278 void ui_wdecor_pos_event(ui_wdecor_t *wdecor, pos_event_t *event) 256 279 { 257 gfx_rect_t trect;258 gfx_rect_t cbrect;259 280 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; 270 282 271 283 pos.x = event->hpos; 272 284 pos.y = event->vpos; 273 285 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)) { 275 289 ui_pbutton_pos_event(wdecor->btn_close, event); 276 290 return; 277 291 } 278 292 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)) 280 295 ui_wdecor_move(wdecor, &pos); 281 296 } -
uspace/lib/ui/test/wdecor.c
r20d2c6c r172188a 310 310 } 311 311 312 PCUT_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 312 353 static errno_t testgc_set_color(void *arg, gfx_color_t *color) 313 354 {
Note:
See TracChangeset
for help on using the changeset viewer.