Changeset e022819 in mainline for uspace/srv/hid/display/window.c


Ignore:
Timestamp:
2020-03-14T00:30:53Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
03c8081
Parents:
1e4a937
Message:

Resizing windows

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/display/window.c

    r1e4a937 re022819  
    436436}
    437437
    438 /** Start moving a window, detected by client.
    439  *
    440  * @param wnd Window
    441  * @param pos Position where the pointer was when the move started
    442  *            relative to the window
    443  * @param event Button press event
    444  */
    445 void ds_window_move_req(ds_window_t *wnd, gfx_coord2_t *pos)
    446 {
    447         log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_move_req (%d, %d)",
    448             (int) pos->x, (int) pos->y);
    449 
    450         if (wnd->state != dsw_idle)
    451                 return;
    452 
    453         gfx_coord2_add(&wnd->dpos, pos, &wnd->orig_pos);
    454         wnd->state = dsw_moving;
    455 }
    456 
    457438/** Start moving a window by mouse drag.
    458439 *
     
    553534}
    554535
     536/** Finish resizing a window by mouse drag.
     537 *
     538 * @param wnd Window
     539 * @param event Button release event
     540 */
     541static void ds_window_finish_resize(ds_window_t *wnd, pos_event_t *event)
     542{
     543        gfx_coord2_t pos;
     544        gfx_coord2_t dresize;
     545        gfx_rect_t nrect;
     546
     547        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_finish_resize (%d, %d)",
     548            (int) event->hpos, (int) event->vpos);
     549
     550        if (wnd->state != dsw_resizing)
     551                return;
     552
     553        pos.x = event->hpos;
     554        pos.y = event->vpos;
     555        gfx_coord2_subtract(&pos, &wnd->orig_pos, &dresize);
     556
     557        /* Compute new rectangle */
     558        ds_window_calc_resize(wnd, &dresize, &nrect);
     559
     560        wnd->state = dsw_idle;
     561        ds_client_post_resize_event(wnd->client, wnd, &nrect);
     562}
     563
     564/** Update window position when resizing by mouse drag.
     565 *
     566 * @param wnd Window
     567 * @param event Position update event
     568 */
     569static void ds_window_update_resize(ds_window_t *wnd, pos_event_t *event)
     570{
     571        gfx_coord2_t pos;
     572        gfx_coord2_t dresize;
     573        gfx_rect_t nrect;
     574        gfx_rect_t drect;
     575        gfx_color_t *color;
     576        gfx_context_t *gc;
     577        errno_t rc;
     578
     579        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_update_resize (%d, %d)",
     580            (int) event->hpos, (int) event->vpos);
     581
     582        if (wnd->state != dsw_resizing)
     583                return;
     584
     585        gfx_rect_translate(&wnd->dpos, &wnd->rect, &drect);
     586
     587        gc = ds_display_get_gc(wnd->display); // XXX
     588        if (gc != NULL) {
     589                gfx_set_color(gc, wnd->display->bg_color);
     590                gfx_fill_rect(gc, &drect);
     591        }
     592
     593        pos.x = event->hpos;
     594        pos.y = event->vpos;
     595        gfx_coord2_subtract(&pos, &wnd->orig_pos, &dresize);
     596
     597        ds_window_calc_resize(wnd, &dresize, &nrect);
     598        gfx_rect_translate(&wnd->dpos, &nrect, &drect);
     599
     600        rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
     601        if (rc != EOK)
     602                return;
     603
     604        gc = ds_display_get_gc(wnd->display); // XXX
     605        if (gc != NULL) {
     606                gfx_set_color(gc, color);
     607                gfx_fill_rect(gc, &drect);
     608        }
     609
     610        gfx_color_delete(color);
     611}
     612
    555613/** Post keyboard event to window.
    556614 *
     
    599657                ds_window_start_move(wnd, event);
    600658
    601         if (event->type == POS_RELEASE)
     659        if (event->type == POS_RELEASE) {
    602660                ds_window_finish_move(wnd, event);
    603 
    604         if (event->type == POS_UPDATE)
     661                ds_window_finish_resize(wnd, event);
     662        }
     663
     664        if (event->type == POS_UPDATE) {
    605665                ds_window_update_move(wnd, event);
     666                ds_window_update_resize(wnd, event);
     667        }
    606668
    607669        /* Transform event coordinates to window-local */
     
    635697}
    636698
     699/** Start moving a window, detected by client.
     700 *
     701 * @param wnd Window
     702 * @param pos Position where the pointer was when the move started
     703 *            relative to the window
     704 * @param event Button press event
     705 */
     706void ds_window_move_req(ds_window_t *wnd, gfx_coord2_t *pos)
     707{
     708        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_move_req (%d, %d)",
     709            (int) pos->x, (int) pos->y);
     710
     711        if (wnd->state != dsw_idle)
     712                return;
     713
     714        gfx_coord2_add(&wnd->dpos, pos, &wnd->orig_pos);
     715        wnd->state = dsw_moving;
     716}
     717
     718/** Start resizing a window, detected by client.
     719 *
     720 * @param wnd Window
     721 * @param rsztype Resize type (which part of window is being dragged)
     722 * @param pos Position where the pointer was when the resize started
     723 *            relative to the window
     724 * @param event Button press event
     725 */
     726void ds_window_resize_req(ds_window_t *wnd, display_wnd_rsztype_t rsztype,
     727    gfx_coord2_t *pos)
     728{
     729        log_msg(LOG_DEFAULT, LVL_NOTE, "ds_window_resize_req (%d, %d, %d)",
     730            (int) rsztype, (int) pos->x, (int) pos->y);
     731
     732        if (wnd->state != dsw_idle)
     733                return;
     734
     735        gfx_coord2_add(&wnd->dpos, pos, &wnd->orig_pos);
     736        wnd->state = dsw_resizing;
     737        wnd->rsztype = rsztype;
     738}
     739
     740/** Compute new window rectangle after resize operation.
     741 *
     742 * @param wnd Window which is being resized (in dsw_resizing state and thus
     743 *            has rsztype set)
     744 * @param dresize Amount by which to resize
     745 * @param nrect Place to store new rectangle
     746 */
     747void ds_window_calc_resize(ds_window_t *wnd, gfx_coord2_t *dresize,
     748    gfx_rect_t *nrect)
     749{
     750        *nrect = wnd->rect;
     751
     752        if ((wnd->rsztype & display_wr_top) != 0)
     753                nrect->p0.y += dresize->y;
     754        if ((wnd->rsztype & display_wr_left) != 0)
     755                nrect->p0.x += dresize->x;
     756        if ((wnd->rsztype & display_wr_bottom) != 0)
     757                nrect->p1.y += dresize->y;
     758        if ((wnd->rsztype & display_wr_right) != 0)
     759                nrect->p1.x += dresize->x;
     760}
     761
    637762/** @}
    638763 */
Note: See TracChangeset for help on using the changeset viewer.