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


Ignore:
Timestamp:
2020-01-09T16:44:57Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
946a666
Parents:
8e9781f
git-author:
Jiri Svoboda <jiri@…> (2020-01-09 18:44:03)
git-committer:
Jiri Svoboda <jiri@…> (2020-01-09 16:44:57)
Message:

Moving windows by mouse drag

File:
1 edited

Legend:

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

    r8e9781f ra40ae0d  
    270270}
    271271
     272/** Start moving a window by mouse drag.
     273 *
     274 * @param wnd Window
     275 * @param event Button press event
     276 */
     277static void ds_window_start_move(ds_window_t *wnd, pos_event_t *event)
     278{
     279        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_start_move (%d, %d)",
     280            (int) event->hpos, (int) event->vpos);
     281
     282        assert(wnd->state == dsw_idle);
     283
     284        wnd->orig_pos.x = event->hpos;
     285        wnd->orig_pos.y = event->vpos;
     286        wnd->state = dsw_moving;
     287}
     288
     289/** Finish moving a window by mouse drag.
     290 *
     291 * @param wnd Window
     292 * @param event Button release event
     293 */
     294static void ds_window_finish_move(ds_window_t *wnd, pos_event_t *event)
     295{
     296        gfx_coord2_t pos;
     297        gfx_coord2_t dmove;
     298        gfx_coord2_t nwpos;
     299
     300        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_finish_move (%d, %d)",
     301            (int) event->hpos, (int) event->vpos);
     302
     303        assert(wnd->state == dsw_moving);
     304        pos.x = event->hpos;
     305        pos.y = event->vpos;
     306        gfx_coord2_subtract(&pos, &wnd->orig_pos, &dmove);
     307
     308        gfx_coord2_add(&wnd->dpos, &dmove, &nwpos);
     309        wnd->dpos = nwpos;
     310        wnd->state = dsw_idle;
     311}
     312
     313/** Update window position when moving by mouse drag.
     314 *
     315 * @param wnd Window
     316 * @param event Position update event
     317 */
     318static void ds_window_update_move(ds_window_t *wnd, pos_event_t *event)
     319{
     320        gfx_coord2_t pos;
     321        gfx_coord2_t dmove;
     322        gfx_coord2_t nwpos;
     323        gfx_rect_t drect;
     324        gfx_color_t *color;
     325        gfx_context_t *gc;
     326        errno_t rc;
     327
     328        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_update_move (%d, %d)",
     329            (int) event->hpos, (int) event->vpos);
     330
     331        assert(wnd->state == dsw_moving);
     332        pos.x = event->hpos;
     333        pos.y = event->vpos;
     334        gfx_coord2_subtract(&pos, &wnd->orig_pos, &dmove);
     335
     336        gfx_coord2_add(&wnd->dpos, &dmove, &nwpos);
     337        gfx_rect_translate(&nwpos, &wnd->rect, &drect);
     338
     339        rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
     340        if (rc != EOK)
     341                return;
     342
     343        gc = ds_display_get_gc(wnd->display); // XXX
     344        if (gc != NULL) {
     345                gfx_set_color(ds_display_get_gc(wnd->display), color);
     346                gfx_fill_rect(ds_display_get_gc(wnd->display), &drect);
     347        }
     348
     349        gfx_color_delete(color);
     350}
     351
     352/** Post position event to window.
     353 *
     354 * @param wnd Window
     355 * @param event Position event
     356 */
     357errno_t ds_window_post_pos_event(ds_window_t *wnd, pos_event_t *event)
     358{
     359        log_msg(LOG_DEFAULT, LVL_DEBUG,
     360            "ds_window_post_pos_event type=%d pos=%d,%d\n", event->type,
     361            (int) event->hpos, (int) event->vpos);
     362
     363        if (event->type == POS_PRESS) {
     364                if (wnd->state == dsw_idle)
     365                        ds_window_start_move(wnd, event);
     366        }
     367
     368        if (event->type == POS_RELEASE) {
     369                if (wnd->state == dsw_moving)
     370                        ds_window_finish_move(wnd, event);
     371        }
     372
     373        if (event->type == POS_UPDATE) {
     374                if (wnd->state == dsw_moving)
     375                        ds_window_update_move(wnd, event);
     376        }
     377
     378        return EOK;
     379}
     380
    272381/** @}
    273382 */
Note: See TracChangeset for help on using the changeset viewer.