Changeset 6301a24f in mainline
- Timestamp:
- 2020-06-05T20:20:06Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8aef01c
- Parents:
- d70e7b7b
- Location:
- uspace
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfx/include/gfx/coord.h
rd70e7b7b r6301a24f 54 54 extern void gfx_rect_dims(gfx_rect_t *, gfx_coord2_t *); 55 55 extern bool gfx_rect_is_empty(gfx_rect_t *); 56 extern bool gfx_rect_is_incident(gfx_rect_t *, gfx_rect_t *); 56 57 extern bool gfx_pix_inside_rect(gfx_coord2_t *, gfx_rect_t *); 57 58 -
uspace/lib/gfx/src/coord.c
rd70e7b7b r6301a24f 37 37 #include <macros.h> 38 38 #include <stdbool.h> 39 #include <stddef.h> 39 40 40 41 /** Add two vectors. … … 192 193 * If the two rectangles do not intersect, the result will be an empty 193 194 * rectangle (check with gfx_rect_is_empty()). The resulting rectangle 194 * is always sorted. 195 * is always sorted. If @a clip is NULL, no clipping is performed. 195 196 * 196 197 * @param rect Source rectangle 197 * @param clip Clipping rectangle 198 * @param clip Clipping rectangle or @c NULL 198 199 * @param dest Place to store clipped rectangle 199 200 */ … … 201 202 { 202 203 gfx_rect_t srect, sclip; 204 205 if (clip == NULL) { 206 *dest = *rect; 207 return; 208 } 203 209 204 210 gfx_rect_points_sort(rect, &srect); … … 235 241 } 236 242 243 /** Determine if two rectangles share any pixels 244 * 245 * @param a First rectangle 246 * @param b Second rectangle 247 * @return @c true iff rectangles share any pixels 248 */ 249 bool gfx_rect_is_incident(gfx_rect_t *a, gfx_rect_t *b) 250 { 251 gfx_rect_t r; 252 253 gfx_rect_clip(a, b, &r); 254 return !gfx_rect_is_empty(&r); 255 } 256 237 257 /** Get rectangle dimensions. 238 258 * -
uspace/lib/gfx/test/coord.c
rd70e7b7b r6301a24f 560 560 } 561 561 562 /** Clip rectangle with no clipping rectangle */ 563 PCUT_TEST(rect_clip_rect_noclip) 564 { 565 gfx_rect_t rect; 566 gfx_rect_t dest; 567 568 rect.p0.x = 1; 569 rect.p0.y = 2; 570 rect.p1.x = 3; 571 rect.p1.y = 4; 572 573 gfx_rect_clip(&rect, NULL, &dest); 574 PCUT_ASSERT_INT_EQUALS(rect.p0.x, dest.p0.x); 575 PCUT_ASSERT_INT_EQUALS(rect.p0.y, dest.p0.y); 576 PCUT_ASSERT_INT_EQUALS(rect.p1.x, dest.p1.x); 577 PCUT_ASSERT_INT_EQUALS(rect.p1.y, dest.p1.y); 578 } 579 562 580 /** Sort span points that are already sorted should produde indentical points */ 563 581 PCUT_TEST(rect_points_sort_sorted) … … 638 656 } 639 657 640 /** gfx_rect_is_empty for st aright non-empty rectangle returns false */658 /** gfx_rect_is_empty for straight non-empty rectangle returns false */ 641 659 PCUT_TEST(rect_is_empty_neg) 642 660 { … … 662 680 } 663 681 682 /** gfx_rect_is_incident for neighboring rectangles returns false */ 683 PCUT_TEST(rect_is_incident_neighbor) 684 { 685 gfx_rect_t a; 686 gfx_rect_t b; 687 688 a.p0.x = 1; 689 a.p0.y = 2; 690 a.p1.x = 3; 691 a.p1.y = 4; 692 693 b.p0.x = 3; 694 b.p0.y = 2; 695 b.p1.x = 5; 696 b.p1.y = 6; 697 698 PCUT_ASSERT_FALSE(gfx_rect_is_incident(&a, &b)); 699 } 700 701 /** gfx_rect_is_incident for a inside b returns true */ 702 PCUT_TEST(rect_is_incident_a_inside_b) 703 { 704 gfx_rect_t a; 705 gfx_rect_t b; 706 707 a.p0.x = 2; 708 a.p0.y = 3; 709 a.p1.x = 4; 710 a.p1.y = 5; 711 712 b.p0.x = 1; 713 b.p0.y = 2; 714 b.p1.x = 5; 715 b.p1.y = 6; 716 717 PCUT_ASSERT_TRUE(gfx_rect_is_incident(&a, &b)); 718 } 719 720 /** gfx_rect_is_incident for b inside a returns true */ 721 PCUT_TEST(rect_is_incident_b_inside_a) 722 { 723 gfx_rect_t a; 724 gfx_rect_t b; 725 726 a.p0.x = 1; 727 a.p0.y = 2; 728 a.p1.x = 5; 729 a.p1.y = 6; 730 731 b.p0.x = 2; 732 b.p0.y = 3; 733 b.p1.x = 4; 734 b.p1.y = 5; 735 736 PCUT_ASSERT_TRUE(gfx_rect_is_incident(&a, &b)); 737 } 738 739 /** gfx_rect_is_incident for a and b sharing corner returns true */ 740 PCUT_TEST(rect_is_incident_corner) 741 { 742 gfx_rect_t a; 743 gfx_rect_t b; 744 745 a.p0.x = 1; 746 a.p0.y = 2; 747 a.p1.x = 3; 748 a.p1.y = 4; 749 750 b.p0.x = 2; 751 b.p0.y = 3; 752 b.p1.x = 4; 753 b.p1.y = 5; 754 755 PCUT_ASSERT_TRUE(gfx_rect_is_incident(&a, &b)); 756 } 757 758 /** gfx_rect_is_incident for a == b returns true */ 759 PCUT_TEST(rect_is_incident_same) 760 { 761 gfx_rect_t a; 762 gfx_rect_t b; 763 764 a.p0.x = 1; 765 a.p0.y = 2; 766 a.p1.x = 3; 767 a.p1.y = 4; 768 769 b.p0.x = 1; 770 b.p0.y = 2; 771 b.p1.x = 3; 772 b.p1.y = 4; 773 774 PCUT_ASSERT_TRUE(gfx_rect_is_incident(&a, &b)); 775 } 776 664 777 /** gfx_pix_inside_rect for */ 665 778 PCUT_TEST(pix_inside_rect) -
uspace/srv/hid/display/display.c
rd70e7b7b r6301a24f 570 570 } 571 571 572 /* Paint window previews for windows being resized or moved */ 573 wnd = ds_display_last_window(disp); 574 while (wnd != NULL) { 575 rc = ds_window_paint_preview(wnd, rect); 576 if (rc != EOK) 577 return rc; 578 579 wnd = ds_display_prev_window(wnd); 580 } 581 582 /* Paint pointers */ 572 583 seat = ds_display_first_seat(disp); 573 584 while (seat != NULL) { -
uspace/srv/hid/display/seat.c
rd70e7b7b r6301a24f 251 251 { 252 252 gfx_rect_t new_rect; 253 gfx_rect_t isect;254 253 gfx_rect_t envelope; 255 254 errno_t rc; … … 257 256 ds_seat_get_pointer_rect(seat, &new_rect); 258 257 259 gfx_rect_clip(old_rect, &new_rect, &isect); 260 if (gfx_rect_is_empty(&isect)) { 258 if (gfx_rect_is_incident(old_rect, &new_rect)) { 261 259 /* Rectangles do not intersect. Repaint them separately. */ 262 260 rc = ds_display_paint(seat->display, &new_rect); -
uspace/srv/hid/display/window.c
rd70e7b7b r6301a24f 50 50 51 51 static void ds_window_update_cb(void *, gfx_rect_t *); 52 static void ds_window_get_preview_rect(ds_window_t *, gfx_rect_t *); 52 53 53 54 /** Create window. … … 205 206 } 206 207 207 /** Start moving a window by mouse drag. 208 * 209 * @param wnd Window 210 * @param pos Position where mouse button was pressed 211 */ 212 static void ds_window_start_move(ds_window_t *wnd, gfx_coord2_t *pos) 213 { 208 /** Get the preview rectangle for a window. 209 * 210 * Get the preview rectangle if the window is being resized or moved. 211 * If the window is not being resized or moved, return an empty rectangle. 212 * 213 * @param wnd Window 214 * @param rect Place to store preview rectangle 215 */ 216 static void ds_window_get_preview_rect(ds_window_t *wnd, gfx_rect_t *rect) 217 { 218 switch (wnd->state) { 219 case dsw_idle: 220 break; 221 case dsw_moving: 222 gfx_rect_translate(&wnd->preview_pos, &wnd->rect, rect); 223 return; 224 case dsw_resizing: 225 gfx_rect_translate(&wnd->dpos, &wnd->preview_rect, rect); 226 return; 227 } 228 229 rect->p0.x = 0; 230 rect->p0.y = 0; 231 rect->p1.x = 0; 232 rect->p1.y = 0; 233 } 234 235 /** Paint window preview if the window is being moved or resized. 236 * 237 * If the window is not being resized or moved, take no action and return 238 * success. 239 * 240 * @param wnd Window for which to paint preview 241 * @param rect Clipping rectangle 242 * @return EOK on success or an error code 243 */ 244 errno_t ds_window_paint_preview(ds_window_t *wnd, gfx_rect_t *rect) 245 { 246 errno_t rc; 214 247 gfx_color_t *color; 248 gfx_rect_t prect; 249 gfx_rect_t drect; 215 250 gfx_context_t *gc; 216 gfx_rect_t drect; 217 errno_t rc; 218 219 log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_start_move (%d, %d)", 220 (int) pos->x, (int) pos->y); 221 222 if (wnd->state != dsw_idle) 223 return; 224 225 wnd->orig_pos = *pos; 226 wnd->state = dsw_moving; 227 wnd->preview_pos = wnd->dpos; 251 252 log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_paint_preview"); 253 254 /* 255 * Get preview rectangle. If the window is not being resized/moved, 256 * we should get an empty rectangle. 257 */ 258 ds_window_get_preview_rect(wnd, &prect); 259 if (gfx_rect_is_empty(&prect)) { 260 /* There is nothing to paint */ 261 return EOK; 262 } 263 264 /* Clip rendering to the clipping rectangle */ 265 gfx_rect_clip(&prect, rect, &drect); 228 266 229 267 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color); 230 268 if (rc != EOK) 231 return; 232 233 gfx_rect_translate(&wnd->dpos, &wnd->rect, &drect); 269 return rc; 234 270 235 271 gc = ds_display_get_gc(wnd->display); // XXX … … 240 276 241 277 gfx_color_delete(color); 278 return EOK; 279 } 280 281 /** Repaint window preview when resizing or moving. 282 * 283 * Repaint the window preview wich was previously at rectangle @a old_rect. 284 * The current preview rectangle is determined from window state. If 285 * the window did not previously have a preview, @a old_rect should point 286 * to an empty rectangle or be NULL. When window has finished 287 * moving or resizing, the preview will be cleared. 288 * 289 * @param wnd Window for which to paint preview 290 * @param rect Clipping rectangle 291 * @return EOK on success or an error code 292 */ 293 static errno_t ds_window_repaint_preview(ds_window_t *wnd, gfx_rect_t *old_rect) 294 { 295 errno_t rc; 296 gfx_rect_t prect; 297 gfx_rect_t envelope; 298 bool oldr; 299 bool newr; 300 301 log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_repaint_preview"); 302 303 /* 304 * Get current preview rectangle. If the window is not being resized/moved, 305 * we should get an empty rectangle. 306 */ 307 ds_window_get_preview_rect(wnd, &prect); 308 309 oldr = (old_rect != NULL) && !gfx_rect_is_empty(old_rect); 310 newr = !gfx_rect_is_empty(&prect); 311 312 if (oldr && newr && gfx_rect_is_incident(old_rect, &prect)) { 313 /* 314 * As an optimization, repaint both rectangles in a single 315 * operation. 316 */ 317 318 gfx_rect_envelope(old_rect, &prect, &envelope); 319 320 rc = ds_display_paint(wnd->display, &envelope); 321 if (rc != EOK) 322 return rc; 323 } else { 324 /* Repaint each rectangle separately */ 325 if (oldr) { 326 rc = ds_display_paint(wnd->display, old_rect); 327 if (rc != EOK) 328 return rc; 329 } 330 331 if (newr) { 332 rc = ds_display_paint(wnd->display, &prect); 333 if (rc != EOK) 334 return rc; 335 } 336 } 337 338 return EOK; 339 } 340 341 /** Start moving a window by mouse drag. 342 * 343 * @param wnd Window 344 * @param pos Position where mouse button was pressed 345 */ 346 static void ds_window_start_move(ds_window_t *wnd, gfx_coord2_t *pos) 347 { 348 log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_start_move (%d, %d)", 349 (int) pos->x, (int) pos->y); 350 351 if (wnd->state != dsw_idle) 352 return; 353 354 wnd->orig_pos = *pos; 355 wnd->state = dsw_moving; 356 wnd->preview_pos = wnd->dpos; 357 358 (void) ds_window_repaint_preview(wnd, NULL); 242 359 } 243 360 … … 251 368 gfx_coord2_t dmove; 252 369 gfx_coord2_t nwpos; 370 gfx_rect_t old_rect; 253 371 254 372 log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_finish_move (%d, %d)", … … 258 376 259 377 gfx_coord2_subtract(pos, &wnd->orig_pos, &dmove); 260 261 378 gfx_coord2_add(&wnd->dpos, &dmove, &nwpos); 379 380 ds_window_get_preview_rect(wnd, &old_rect); 381 262 382 wnd->dpos = nwpos; 263 383 wnd->state = dsw_idle; … … 275 395 gfx_coord2_t dmove; 276 396 gfx_coord2_t nwpos; 277 gfx_rect_t drect; 278 gfx_color_t *color; 279 gfx_context_t *gc; 280 errno_t rc; 397 gfx_rect_t old_rect; 281 398 282 399 log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_update_move (%d, %d)", … … 285 402 assert(wnd->state == dsw_moving); 286 403 287 gfx_rect_translate(&wnd->preview_pos, &wnd->rect, &drect);288 ds_display_paint(wnd->display, &drect);289 290 404 gfx_coord2_subtract(pos, &wnd->orig_pos, &dmove); 291 292 405 gfx_coord2_add(&wnd->dpos, &dmove, &nwpos); 406 407 ds_window_get_preview_rect(wnd, &old_rect); 293 408 wnd->preview_pos = nwpos; 294 409 295 gfx_rect_translate(&nwpos, &wnd->rect, &drect); 296 297 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color); 298 if (rc != EOK) 299 return; 300 301 gc = ds_display_get_gc(wnd->display); // XXX 302 if (gc != NULL) { 303 gfx_set_color(gc, color); 304 gfx_fill_rect(gc, &drect); 305 } 306 307 gfx_color_delete(color); 410 (void) ds_window_repaint_preview(wnd, &old_rect); 308 411 } 309 412 … … 335 438 ctype = display_cursor_from_wrsz(rsztype); 336 439 ds_seat_set_wm_cursor(seat, wnd->display->cursor[ctype]); 440 441 (void) ds_window_repaint_preview(wnd, NULL); 337 442 } 338 443 … … 352 457 353 458 assert(wnd->state == dsw_resizing); 354 355 (void) ds_display_paint(wnd->display, NULL);356 357 459 gfx_coord2_subtract(pos, &wnd->orig_pos, &dresize); 358 460 … … 366 468 seat = ds_display_first_seat(wnd->display); 367 469 ds_seat_set_wm_cursor(seat, NULL); 470 471 (void) ds_display_paint(wnd->display, NULL); 368 472 } 369 473 … … 377 481 gfx_coord2_t dresize; 378 482 gfx_rect_t nrect; 379 gfx_rect_t drect; 380 gfx_color_t *color; 381 gfx_context_t *gc; 382 errno_t rc; 483 gfx_rect_t old_rect; 383 484 384 485 log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_update_resize (%d, %d)", … … 387 488 assert(wnd->state == dsw_resizing); 388 489 389 gfx_rect_translate(&wnd->dpos, &wnd->preview_rect, &drect);390 (void) ds_display_paint(wnd->display, &drect);391 392 490 gfx_coord2_subtract(pos, &wnd->orig_pos, &dresize); 393 394 491 ds_window_calc_resize(wnd, &dresize, &nrect); 395 gfx_rect_translate(&wnd->dpos, &nrect, &drect); 492 493 ds_window_get_preview_rect(wnd, &old_rect); 396 494 wnd->preview_rect = nrect; 397 398 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color); 399 if (rc != EOK) 400 return; 401 402 gc = ds_display_get_gc(wnd->display); // XXX 403 if (gc != NULL) { 404 gfx_set_color(gc, color); 405 gfx_fill_rect(gc, &drect); 406 } 407 408 gfx_color_delete(color); 495 (void) ds_window_repaint_preview(wnd, &old_rect); 409 496 } 410 497 -
uspace/srv/hid/display/window.h
rd70e7b7b r6301a24f 56 56 extern gfx_context_t *ds_window_get_ctx(ds_window_t *); 57 57 extern errno_t ds_window_paint(ds_window_t *, gfx_rect_t *); 58 errno_t ds_window_paint_preview(ds_window_t *, gfx_rect_t *); 58 59 extern errno_t ds_window_post_kbd_event(ds_window_t *, kbd_event_t *); 59 60 extern errno_t ds_window_post_pos_event(ds_window_t *, pos_event_t *);
Note:
See TracChangeset
for help on using the changeset viewer.