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


Ignore:
Timestamp:
2020-03-24T11:03:08Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1b443cc0
Parents:
0b7e394
git-author:
Jiri Svoboda <jiri@…> (2020-03-23 18:39:29)
git-committer:
Jiri Svoboda <jiri@…> (2020-03-24 11:03:08)
Message:

Deduplicate code between _start_move/resize and _move_req/_resize_req

File:
1 edited

Legend:

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

    r0b7e394 r76a02db  
    405405 *
    406406 * @param wnd Window
    407  * @param event Button press event
    408  */
    409 static void ds_window_start_move(ds_window_t *wnd, pos_event_t *event)
     407 * @param pos Position where mouse button was pressed
     408 */
     409static void ds_window_start_move(ds_window_t *wnd, gfx_coord2_t *pos)
    410410{
    411411        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_start_move (%d, %d)",
    412             (int) event->hpos, (int) event->vpos);
     412            (int) pos->x, (int) pos->y);
    413413
    414414        if (wnd->state != dsw_idle)
    415415                return;
    416416
    417         wnd->orig_pos.x = event->hpos;
    418         wnd->orig_pos.y = event->vpos;
     417        wnd->orig_pos = *pos;
    419418        wnd->state = dsw_moving;
    420419}
     
    423422 *
    424423 * @param wnd Window
    425  * @param event Button release event
    426  */
    427 static void ds_window_finish_move(ds_window_t *wnd, pos_event_t *event)
    428 {
    429         gfx_coord2_t pos;
     424 * @param pos Position where mouse button was released
     425 */
     426static void ds_window_finish_move(ds_window_t *wnd, gfx_coord2_t *pos)
     427{
    430428        gfx_coord2_t dmove;
    431429        gfx_coord2_t nwpos;
    432430
    433431        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_finish_move (%d, %d)",
    434             (int) event->hpos, (int) event->vpos);
     432            (int) pos->x, (int) pos->y);
    435433
    436434        if (wnd->state != dsw_moving)
    437435                return;
    438436
    439         pos.x = event->hpos;
    440         pos.y = event->vpos;
    441         gfx_coord2_subtract(&pos, &wnd->orig_pos, &dmove);
     437        gfx_coord2_subtract(pos, &wnd->orig_pos, &dmove);
    442438
    443439        gfx_coord2_add(&wnd->dpos, &dmove, &nwpos);
     
    451447 *
    452448 * @param wnd Window
    453  * @param event Position update event
    454  */
    455 static void ds_window_update_move(ds_window_t *wnd, pos_event_t *event)
    456 {
    457         gfx_coord2_t pos;
     449 * @param pos Current mouse position
     450 */
     451static void ds_window_update_move(ds_window_t *wnd, gfx_coord2_t *pos)
     452{
    458453        gfx_coord2_t dmove;
    459454        gfx_coord2_t nwpos;
     
    464459
    465460        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_update_move (%d, %d)",
    466             (int) event->hpos, (int) event->vpos);
     461            (int) pos->x, (int) pos->y);
    467462
    468463        if (wnd->state != dsw_moving)
     
    477472        }
    478473
    479         pos.x = event->hpos;
    480         pos.y = event->vpos;
    481         gfx_coord2_subtract(&pos, &wnd->orig_pos, &dmove);
     474        gfx_coord2_subtract(pos, &wnd->orig_pos, &dmove);
    482475
    483476        gfx_coord2_add(&wnd->dpos, &dmove, &nwpos);
    484477        gfx_rect_translate(&nwpos, &wnd->rect, &drect);
    485478
    486         wnd->orig_pos = pos;
     479        wnd->orig_pos = *pos;
    487480        wnd->dpos = nwpos;
    488481
     
    500493}
    501494
     495/** Start resizing a window by mouse drag.
     496 *
     497 * @param wnd Window
     498 * @param rsztype Resize type (which part of window is being dragged)
     499 * @param pos Position where mouse button was pressed
     500 */
     501static void ds_window_start_resize(ds_window_t *wnd,
     502    display_wnd_rsztype_t rsztype, gfx_coord2_t *pos)
     503{
     504        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_start_resize (%d, %d)",
     505            (int) pos->x, (int) pos->y);
     506
     507        if (wnd->state != dsw_idle)
     508                return;
     509
     510        wnd->orig_pos = *pos;
     511        wnd->state = dsw_resizing;
     512        wnd->rsztype = rsztype;
     513}
     514
    502515/** Finish resizing a window by mouse drag.
    503516 *
    504517 * @param wnd Window
    505  * @param event Button release event
    506  */
    507 static void ds_window_finish_resize(ds_window_t *wnd, pos_event_t *event)
    508 {
    509         gfx_coord2_t pos;
     518 * @param pos Position where mouse button was released
     519 */
     520static void ds_window_finish_resize(ds_window_t *wnd, gfx_coord2_t *pos)
     521{
    510522        gfx_coord2_t dresize;
    511523        gfx_rect_t nrect;
    512524
    513525        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_finish_resize (%d, %d)",
    514             (int) event->hpos, (int) event->vpos);
     526            (int) pos->x, (int) pos->y);
    515527
    516528        if (wnd->state != dsw_resizing)
     
    519531        (void) ds_display_paint(wnd->display, NULL);
    520532
    521         pos.x = event->hpos;
    522         pos.y = event->vpos;
    523         gfx_coord2_subtract(&pos, &wnd->orig_pos, &dresize);
     533        gfx_coord2_subtract(pos, &wnd->orig_pos, &dresize);
    524534
    525535        /* Compute new rectangle */
     
    533543 *
    534544 * @param wnd Window
    535  * @param event Position update event
    536  */
    537 static void ds_window_update_resize(ds_window_t *wnd, pos_event_t *event)
    538 {
    539         gfx_coord2_t pos;
     545 * @param pos Current mouse position
     546 */
     547static void ds_window_update_resize(ds_window_t *wnd, gfx_coord2_t *pos)
     548{
    540549        gfx_coord2_t dresize;
    541550        gfx_rect_t nrect;
     
    546555
    547556        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_update_resize (%d, %d)",
    548             (int) event->hpos, (int) event->vpos);
     557            (int) pos->x, (int) pos->y);
    549558
    550559        if (wnd->state != dsw_resizing)
     
    559568        }
    560569
    561         pos.x = event->hpos;
    562         pos.y = event->vpos;
    563         gfx_coord2_subtract(&pos, &wnd->orig_pos, &dresize);
     570        gfx_coord2_subtract(pos, &wnd->orig_pos, &dresize);
    564571
    565572        ds_window_calc_resize(wnd, &dresize, &nrect);
     
    623630
    624631        if (event->type == POS_PRESS && event->btn_num == 2 && inside)
    625                 ds_window_start_move(wnd, event);
     632                ds_window_start_move(wnd, &pos);
    626633
    627634        if (event->type == POS_RELEASE) {
    628                 ds_window_finish_move(wnd, event);
    629                 ds_window_finish_resize(wnd, event);
     635                ds_window_finish_move(wnd, &pos);
     636                ds_window_finish_resize(wnd, &pos);
    630637        }
    631638
    632639        if (event->type == POS_UPDATE) {
    633                 ds_window_update_move(wnd, event);
    634                 ds_window_update_resize(wnd, event);
     640                ds_window_update_move(wnd, &pos);
     641                ds_window_update_resize(wnd, &pos);
    635642        }
    636643
     
    674681void ds_window_move_req(ds_window_t *wnd, gfx_coord2_t *pos)
    675682{
     683        gfx_coord2_t orig_pos;
     684
    676685        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_move_req (%d, %d)",
    677686            (int) pos->x, (int) pos->y);
    678687
    679         if (wnd->state != dsw_idle)
    680                 return;
    681 
    682         gfx_coord2_add(&wnd->dpos, pos, &wnd->orig_pos);
    683         wnd->state = dsw_moving;
     688        gfx_coord2_add(&wnd->dpos, pos, &orig_pos);
     689        ds_window_start_move(wnd, &orig_pos);
    684690}
    685691
     
    705711    gfx_coord2_t *pos)
    706712{
     713        gfx_coord2_t orig_pos;
     714
    707715        log_msg(LOG_DEFAULT, LVL_NOTE, "ds_window_resize_req (%d, %d, %d)",
    708716            (int) rsztype, (int) pos->x, (int) pos->y);
    709717
    710         if (wnd->state != dsw_idle)
    711                 return;
    712 
    713         gfx_coord2_add(&wnd->dpos, pos, &wnd->orig_pos);
    714         wnd->state = dsw_resizing;
    715         wnd->rsztype = rsztype;
     718        gfx_coord2_add(&wnd->dpos, pos, &orig_pos);
     719        ds_window_start_resize(wnd, rsztype, &orig_pos);
    716720}
    717721
Note: See TracChangeset for help on using the changeset viewer.