Changeset 1388f7f0 in mainline


Ignore:
Timestamp:
2020-02-21T10:50:48Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
265989d
Parents:
6c2aba3
git-author:
Jiri Svoboda <jiri@…> (2020-02-19 19:38:03)
git-committer:
Jiri Svoboda <jiri@…> (2020-02-21 10:50:48)
Message:

Support absolute movement events from input device

Location:
uspace
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/gfx/include/gfx/coord.h

    r6c2aba3 r1388f7f0  
    4343extern void gfx_coord2_subtract(gfx_coord2_t *, gfx_coord2_t *, gfx_coord2_t *);
    4444extern void gfx_coord2_clip(gfx_coord2_t *, gfx_rect_t *, gfx_coord2_t *);
     45extern void gfx_coord2_project(gfx_coord2_t *, gfx_rect_t *, gfx_rect_t *,
     46    gfx_coord2_t *);
    4547extern void gfx_span_points_sort(gfx_coord_t, gfx_coord_t, gfx_coord_t *,
    4648    gfx_coord_t *);
  • uspace/lib/gfx/src/coord.c

    r6c2aba3 r1388f7f0  
    6262}
    6363
     64/** Clip point coordinates to be within a rectangle.
     65 *
     66 * @param a Pixel coordinates
     67 * @param clip Clipping rectangle
     68 * @param d Place to store clipped coordinates
     69 */
    6470void gfx_coord2_clip(gfx_coord2_t *a, gfx_rect_t *clip, gfx_coord2_t *d)
    6571{
     
    7480        d->x = max(clip->p0.x, t.x);
    7581        d->y = max(clip->p0.y, t.y);
     82}
     83
     84/** Transform coordinates via rectangle to rectangle projection.
     85 *
     86 * Transform pixel coordinate via a projection that maps one rectangle
     87 * onto another rectangle. The source rectangle must have both dimensions
     88 * greater than one.
     89 *
     90 * @param a Pixel coordinates
     91 * @param srect Source rectangle
     92 * @param drect Destination rectangle
     93 * @param d Place to store resulting coordinates.
     94 */
     95void gfx_coord2_project(gfx_coord2_t *a, gfx_rect_t *srect, gfx_rect_t *drect,
     96    gfx_coord2_t *d)
     97{
     98        gfx_rect_t sr;
     99        gfx_rect_t dr;
     100
     101        gfx_rect_points_sort(srect, &sr);
     102        gfx_rect_points_sort(drect, &dr);
     103
     104        d->x = dr.p0.x + (a->x - sr.p0.x) * (dr.p1.x - dr.p0.x - 1) /
     105            (sr.p1.x - sr.p0.x - 1);
     106        d->y = dr.p0.y + (a->y - sr.p0.y) * (dr.p1.y - dr.p0.y - 1) /
     107            (sr.p1.y - sr.p0.y - 1);
    76108}
    77109
  • uspace/lib/gfx/test/coord.c

    r6c2aba3 r1388f7f0  
    131131}
    132132
     133/** gfx_coord2_project projects pixel from one rectangle to another  */
     134PCUT_TEST(coord2_project)
     135{
     136        gfx_coord2_t a, d;
     137        gfx_rect_t srect, drect;
     138
     139        srect.p0.x = 10;
     140        srect.p0.y = 10;
     141        srect.p1.x = 20 + 1;
     142        srect.p1.y = 20 + 1;
     143
     144        drect.p0.x = 100;
     145        drect.p0.y = 100;
     146        drect.p1.x = 200 + 1;
     147        drect.p1.y = 200 + 1;
     148
     149        a.x = 10;
     150        a.y = 10;
     151        gfx_coord2_project(&a, &srect, &drect, &d);
     152        PCUT_ASSERT_INT_EQUALS(100, d.x);
     153        PCUT_ASSERT_INT_EQUALS(100, d.y);
     154
     155        a.x = 15;
     156        a.y = 15;
     157        gfx_coord2_project(&a, &srect, &drect, &d);
     158        PCUT_ASSERT_INT_EQUALS(150, d.x);
     159        PCUT_ASSERT_INT_EQUALS(150, d.y);
     160
     161        a.x = 12;
     162        a.y = 16;
     163        gfx_coord2_project(&a, &srect, &drect, &d);
     164        PCUT_ASSERT_INT_EQUALS(120, d.x);
     165        PCUT_ASSERT_INT_EQUALS(160, d.y);
     166
     167        a.x = 20;
     168        a.y = 20;
     169        gfx_coord2_project(&a, &srect, &drect, &d);
     170        PCUT_ASSERT_INT_EQUALS(200, d.x);
     171        PCUT_ASSERT_INT_EQUALS(200, d.y);
     172}
     173
    133174/** gfx_rect_translate should translate rectangle */
    134175PCUT_TEST(rect_translate)
  • uspace/srv/hid/display/input.c

    r6c2aba3 r1388f7f0  
    9797    unsigned max_x, unsigned max_y)
    9898{
    99         printf("ds_input_ev_abs_move x=%u y=%u mx=%u my=%u\n",
    100             x, y, max_x, max_y);
    101         return EOK;
     99        ds_display_t *disp = (ds_display_t *) input->user;
     100        ptd_event_t event;
     101
     102        event.type = PTD_ABS_MOVE;
     103        event.apos.x = x;
     104        event.apos.y = y;
     105        event.abounds.p0.x = 0;
     106        event.abounds.p0.y = 0;
     107        event.abounds.p1.x = max_x + 1;
     108        event.abounds.p1.y = max_y + 1;
     109
     110        return ds_display_post_ptd_event(disp, &event);
    102111}
    103112
  • uspace/srv/hid/display/seat.c

    r6c2aba3 r1388f7f0  
    256256 * @return EOK on success or an error code
    257257 */
     258#include <stdio.h>
    258259errno_t ds_seat_post_ptd_event(ds_seat_t *seat, ptd_event_t *event)
    259260{
     
    306307        }
    307308
     309        if (event->type == PTD_ABS_MOVE) {
     310                /*
     311                 * Project input device area onto display area. Technically
     312                 * we probably want to project onto the area of a particular
     313                 * display device. The tricky part is figuring out which
     314                 * display device the input device is associated with.
     315                 */
     316                gfx_coord2_project(&event->apos, &event->abounds,
     317                    &disp->rect, &npos);
     318
     319                gfx_coord2_clip(&npos, &disp->rect, &npos);
     320
     321                (void) ds_seat_clear_pointer(seat);
     322                seat->pntpos = npos;
     323
     324                pevent.pos_id = 0;
     325                pevent.type = POS_UPDATE;
     326                pevent.btn_num = 0;
     327                pevent.hpos = seat->pntpos.x;
     328                pevent.vpos = seat->pntpos.y;
     329
     330                rc = ds_seat_post_pos_event(seat, &pevent);
     331                if (rc != EOK)
     332                        return rc;
     333
     334                (void) ds_seat_draw_pointer(seat);
     335        }
     336
    308337        return EOK;
    309338}
  • uspace/srv/hid/display/types/display/ptd_event.h

    r6c2aba3 r1388f7f0  
    4040typedef enum {
    4141        PTD_MOVE,
     42        PTD_ABS_MOVE,
    4243        PTD_PRESS,
    4344        PTD_RELEASE
     
    5152        /** Relative move vector for PTD_MOVE */
    5253        gfx_coord2_t dmove;
     54        /** Absolute position for PTD_ABS_MOVE */
     55        gfx_coord2_t apos;
     56        /** Absolute position bounds for PTD_ABS_MOVE */
     57        gfx_rect_t abounds;
    5358} ptd_event_t;
    5459
Note: See TracChangeset for help on using the changeset viewer.