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


Ignore:
Timestamp:
2020-06-05T20:20:06Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8aef01c
Parents:
d70e7b7b
Message:

Window previews need to be drawn as part of ds_display_paint

File:
1 edited

Legend:

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

    rd70e7b7b r6301a24f  
    5050
    5151static void ds_window_update_cb(void *, gfx_rect_t *);
     52static void ds_window_get_preview_rect(ds_window_t *, gfx_rect_t *);
    5253
    5354/** Create window.
     
    205206}
    206207
    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 */
     216static 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 */
     244errno_t ds_window_paint_preview(ds_window_t *wnd, gfx_rect_t *rect)
     245{
     246        errno_t rc;
    214247        gfx_color_t *color;
     248        gfx_rect_t prect;
     249        gfx_rect_t drect;
    215250        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);
    228266
    229267        rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
    230268        if (rc != EOK)
    231                 return;
    232 
    233         gfx_rect_translate(&wnd->dpos, &wnd->rect, &drect);
     269                return rc;
    234270
    235271        gc = ds_display_get_gc(wnd->display); // XXX
     
    240276
    241277        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 */
     293static 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 */
     346static 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);
    242359}
    243360
     
    251368        gfx_coord2_t dmove;
    252369        gfx_coord2_t nwpos;
     370        gfx_rect_t old_rect;
    253371
    254372        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_finish_move (%d, %d)",
     
    258376
    259377        gfx_coord2_subtract(pos, &wnd->orig_pos, &dmove);
    260 
    261378        gfx_coord2_add(&wnd->dpos, &dmove, &nwpos);
     379
     380        ds_window_get_preview_rect(wnd, &old_rect);
     381
    262382        wnd->dpos = nwpos;
    263383        wnd->state = dsw_idle;
     
    275395        gfx_coord2_t dmove;
    276396        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;
    281398
    282399        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_update_move (%d, %d)",
     
    285402        assert(wnd->state == dsw_moving);
    286403
    287         gfx_rect_translate(&wnd->preview_pos, &wnd->rect, &drect);
    288         ds_display_paint(wnd->display, &drect);
    289 
    290404        gfx_coord2_subtract(pos, &wnd->orig_pos, &dmove);
    291 
    292405        gfx_coord2_add(&wnd->dpos, &dmove, &nwpos);
     406
     407        ds_window_get_preview_rect(wnd, &old_rect);
    293408        wnd->preview_pos = nwpos;
    294409
    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);
    308411}
    309412
     
    335438        ctype = display_cursor_from_wrsz(rsztype);
    336439        ds_seat_set_wm_cursor(seat, wnd->display->cursor[ctype]);
     440
     441        (void) ds_window_repaint_preview(wnd, NULL);
    337442}
    338443
     
    352457
    353458        assert(wnd->state == dsw_resizing);
    354 
    355         (void) ds_display_paint(wnd->display, NULL);
    356 
    357459        gfx_coord2_subtract(pos, &wnd->orig_pos, &dresize);
    358460
     
    366468        seat = ds_display_first_seat(wnd->display);
    367469        ds_seat_set_wm_cursor(seat, NULL);
     470
     471        (void) ds_display_paint(wnd->display, NULL);
    368472}
    369473
     
    377481        gfx_coord2_t dresize;
    378482        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;
    383484
    384485        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_update_resize (%d, %d)",
     
    387488        assert(wnd->state == dsw_resizing);
    388489
    389         gfx_rect_translate(&wnd->dpos, &wnd->preview_rect, &drect);
    390         (void) ds_display_paint(wnd->display, &drect);
    391 
    392490        gfx_coord2_subtract(pos, &wnd->orig_pos, &dresize);
    393 
    394491        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);
    396494        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);
    409496}
    410497
Note: See TracChangeset for help on using the changeset viewer.