Changeset 2d879f7 in mainline


Ignore:
Timestamp:
2020-11-26T11:59:59Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
554a5f1
Parents:
d8ddf7a
git-author:
Jiri Svoboda <jiri@…> (2020-11-25 18:46:07)
git-committer:
Jiri Svoboda <jiri@…> (2020-11-26 11:59:59)
Message:

Basic support for window resizing

Location:
uspace
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/uidemo/uidemo.c

    rd8ddf7a r2d879f7  
    120120        ui_wnd_params_init(&params);
    121121        params.caption = "UI Demo";
     122        params.style |= ui_wds_resizable;
    122123        params.rect.p0.x = 0;
    123124        params.rect.p0.y = 0;
  • uspace/lib/display/include/types/display/wndparams.h

    rd8ddf7a r2d879f7  
    4141 *
    4242 * The window's dimensions are determined by the bounding rectangle,
    43  * the position of which does not relate to its positon on the display,
     43 * the position of which does not relate to its position on the display,
    4444 * it just determines which range of logical coordinates is used
    4545 * by the window.
  • uspace/lib/ui/include/types/ui/wdecor.h

    rd8ddf7a r2d879f7  
    3838
    3939#include <gfx/coord.h>
     40#include <types/ui/cursor.h>
    4041
    4142struct ui_wdecor;
    4243typedef struct ui_wdecor ui_wdecor_t;
     44
     45/** Window decoration style */
     46typedef enum {
     47        ui_wds_none = 0x0,
     48        ui_wds_resizable = 0x1
     49} ui_wdecor_style_t;
     50
     51/** Window resize type */
     52typedef enum {
     53        ui_wr_none = 0,
     54
     55        ui_wr_top = 0x1,
     56        ui_wr_left = 0x2,
     57        ui_wr_bottom = 0x4,
     58        ui_wr_right = 0x8,
     59
     60        ui_wr_top_left = ui_wr_top | ui_wr_left,
     61        ui_wr_bottom_left = ui_wr_bottom | ui_wr_left,
     62        ui_wr_bottom_right = ui_wr_bottom | ui_wr_right,
     63        ui_wr_top_right = ui_wr_top | ui_wr_right
     64} ui_wdecor_rsztype_t;
    4365
    4466/** Window decoration callbacks */
     
    4668        void (*close)(ui_wdecor_t *, void *);
    4769        void (*move)(ui_wdecor_t *, void *, gfx_coord2_t *);
     70        void (*resize)(ui_wdecor_t *, void *, ui_wdecor_rsztype_t,
     71            gfx_coord2_t *);
     72        void (*set_cursor)(ui_wdecor_t *, void *, ui_stock_cursor_t);
    4873} ui_wdecor_cb_t;
    4974
  • uspace/lib/ui/include/types/ui/window.h

    rd8ddf7a r2d879f7  
    4040#include <io/kbd_event.h>
    4141#include <io/pos_event.h>
     42#include <types/ui/wdecor.h>
    4243
    4344struct ui_window;
     
    6465        /** Window caption */
    6566        const char *caption;
     67        /** Window decoration style */
     68        ui_wdecor_style_t style;
    6669        /** Window placement */
    6770        ui_wnd_placement_t placement;
  • uspace/lib/ui/include/ui/wdecor.h

    rd8ddf7a r2d879f7  
    4545
    4646extern errno_t ui_wdecor_create(ui_resource_t *, const char *,
    47     ui_wdecor_t **);
     47    ui_wdecor_style_t, ui_wdecor_t **);
    4848extern void ui_wdecor_destroy(ui_wdecor_t *);
    4949extern void ui_wdecor_set_cb(ui_wdecor_t *, ui_wdecor_cb_t *, void *);
  • uspace/lib/ui/private/wdecor.h

    rd8ddf7a r2d879f7  
    3939
    4040#include <gfx/coord.h>
     41#include <io/pos_event.h>
    4142#include <stdbool.h>
     43#include <types/ui/cursor.h>
    4244#include <types/ui/wdecor.h>
    4345
     
    5557        /** Window decoration rectangle */
    5658        gfx_rect_t rect;
     59        /** Style */
     60        ui_wdecor_style_t style;
    5761        /** Caption */
    5862        char *caption;
     
    8084extern void ui_wdecor_close(ui_wdecor_t *);
    8185extern void ui_wdecor_move(ui_wdecor_t *, gfx_coord2_t *);
     86extern void ui_wdecor_resize(ui_wdecor_t *, ui_wdecor_rsztype_t,
     87    gfx_coord2_t *);
     88extern void ui_wdecor_set_cursor(ui_wdecor_t *, ui_stock_cursor_t);
    8289extern void ui_wdecor_get_geom(ui_wdecor_t *, ui_wdecor_geom_t *);
     90extern void ui_wdecor_frame_pos_event(ui_wdecor_t *, pos_event_t *);
     91extern ui_wdecor_rsztype_t ui_wdecor_get_rsztype(ui_wdecor_t *,
     92    gfx_coord2_t *);
     93extern ui_stock_cursor_t ui_wdecor_cursor_from_rsztype(ui_wdecor_rsztype_t);
    8394
    8495#endif
  • uspace/lib/ui/private/window.h

    rd8ddf7a r2d879f7  
    5959        /** Window GC */
    6060        gfx_context_t *gc;
     61        /** Window rectangle */
     62        gfx_rect_t rect;
    6163        /** Application area bitmap */
    6264        gfx_bitmap_t *app_bmp;
     
    6971        /** Top-level control in the application area */
    7072        struct ui_control *control;
     73        /** Current cursor */
     74        ui_stock_cursor_t cursor;
    7175};
    7276
  • uspace/lib/ui/src/wdecor.c

    rd8ddf7a r2d879f7  
    3434 */
    3535
     36#include <assert.h>
    3637#include <errno.h>
    3738#include <gfx/color.h>
     
    5455};
    5556
     57enum {
     58        wdecor_corner_w = 24,
     59        wdecor_corner_h = 24,
     60        wdecor_edge_w = 4,
     61        wdecor_edge_h = 4
     62};
     63
    5664/** Create new window decoration.
    5765 *
    5866 * @param resource UI resource
    5967 * @param caption Window caption
     68 * @param style Style
    6069 * @param rwdecor Place to store pointer to new window decoration
    6170 * @return EOK on success, ENOMEM if out of memory
    6271 */
    6372errno_t ui_wdecor_create(ui_resource_t *resource, const char *caption,
    64     ui_wdecor_t **rwdecor)
     73    ui_wdecor_style_t style, ui_wdecor_t **rwdecor)
    6574{
    6675        ui_wdecor_t *wdecor;
     
    8998        wdecor->res = resource;
    9099        wdecor->active = true;
     100        wdecor->style = style;
    91101        *rwdecor = wdecor;
    92102        return EOK;
     
    244254}
    245255
     256/** Send decoration resize event.
     257 *
     258 * @param wdecor Window decoration
     259 * @param rsztype Resize type
     260 * @param pos Position where the button was pressed
     261 */
     262void ui_wdecor_resize(ui_wdecor_t *wdecor, ui_wdecor_rsztype_t rsztype,
     263    gfx_coord2_t *pos)
     264{
     265        if (wdecor->cb != NULL && wdecor->cb->resize != NULL)
     266                wdecor->cb->resize(wdecor, wdecor->arg, rsztype, pos);
     267}
     268
     269/** Send cursor change event.
     270 *
     271 * @param wdecor Window decoration
     272 * @param cursor Cursor
     273 */
     274void ui_wdecor_set_cursor(ui_wdecor_t *wdecor, ui_stock_cursor_t cursor)
     275{
     276        if (wdecor->cb != NULL && wdecor->cb->set_cursor != NULL)
     277                wdecor->cb->set_cursor(wdecor, wdecor->arg, cursor);
     278}
     279
    246280/** Get window decoration geometry.
    247281 *
     
    287321}
    288322
     323/** Get resize type for pointer at the specified position.
     324 *
     325 * @param wdecor Window decoration
     326 * @param pos Pointer position
     327 * @return Resize type
     328 */
     329ui_wdecor_rsztype_t ui_wdecor_get_rsztype(ui_wdecor_t *wdecor,
     330    gfx_coord2_t *pos)
     331{
     332        bool eleft, eright;
     333        bool etop, ebottom;
     334        bool edge;
     335        bool cleft, cright;
     336        bool ctop, cbottom;
     337
     338        /* Window not resizable? */
     339        if ((wdecor->style & ui_wds_resizable) == 0)
     340                return ui_wr_none;
     341
     342        /* Position not inside window? */
     343        if (!gfx_pix_inside_rect(pos, &wdecor->rect))
     344                return ui_wr_none;
     345
     346        /* Position is within edge width from the outside */
     347        eleft = (pos->x < wdecor->rect.p0.x + wdecor_edge_w);
     348        eright = (pos->x >= wdecor->rect.p1.x - wdecor_edge_w);
     349        etop = (pos->y < wdecor->rect.p0.y + wdecor_edge_h);
     350        ebottom = (pos->y >= wdecor->rect.p1.y - wdecor_edge_h);
     351
     352        /* Position is on one of the four edges */
     353        edge = eleft || eright || etop || ebottom;
     354
     355        /* Position is within resize-corner distance from the outside */
     356        cleft = (pos->x < wdecor->rect.p0.x + wdecor_corner_w);
     357        cright = (pos->x >= wdecor->rect.p1.x - wdecor_corner_w);
     358        ctop = (pos->y < wdecor->rect.p0.y + wdecor_corner_h);
     359        cbottom = (pos->y >= wdecor->rect.p1.y - wdecor_corner_h);
     360
     361        /* Top-left corner */
     362        if (edge && cleft && ctop)
     363                return ui_wr_top_left;
     364
     365        /* Top-right corner */
     366        if (edge && cright && ctop)
     367                return ui_wr_top_right;
     368
     369        /* Bottom-left corner */
     370        if (edge && cleft && cbottom)
     371                return ui_wr_bottom_left;
     372
     373        /* Bottom-right corner */
     374        if (edge && cright && cbottom)
     375                return ui_wr_bottom_right;
     376
     377        /* Left edge */
     378        if (eleft)
     379                return ui_wr_left;
     380
     381        /* Right edge */
     382        if (eright)
     383                return ui_wr_right;
     384
     385        /* Top edge */
     386        if (etop)
     387                return ui_wr_top;
     388
     389        /* Bottom edge */
     390        if (ebottom)
     391                return ui_wr_bottom;
     392
     393        return ui_wr_none;
     394}
     395
     396/** Get stock cursor to use for the specified window resize type.
     397 *
     398 * The resize type must be valid, otherwise behavior is undefined.
     399 *
     400 * @param rsztype Resize type
     401 * @return Cursor to use for this resize type
     402 */
     403ui_stock_cursor_t ui_wdecor_cursor_from_rsztype(ui_wdecor_rsztype_t rsztype)
     404{
     405        switch (rsztype) {
     406        case ui_wr_none:
     407                return ui_curs_arrow;
     408
     409        case ui_wr_top:
     410        case ui_wr_bottom:
     411                return ui_curs_size_ud;
     412
     413        case ui_wr_left:
     414        case ui_wr_right:
     415                return ui_curs_size_lr;
     416
     417        case ui_wr_top_left:
     418        case ui_wr_bottom_right:
     419                return ui_curs_size_uldr;
     420
     421        case ui_wr_top_right:
     422        case ui_wr_bottom_left:
     423                return ui_curs_size_urdl;
     424
     425        default:
     426                assert(false);
     427                return ui_curs_arrow;
     428        }
     429}
     430
     431/** Handle window frame position event.
     432 *
     433 * @param wdecor Window decoration
     434 * @param pos_event Position event
     435 */
     436void ui_wdecor_frame_pos_event(ui_wdecor_t *wdecor, pos_event_t *event)
     437{
     438        gfx_coord2_t pos;
     439        ui_wdecor_rsztype_t rsztype;
     440        ui_stock_cursor_t cursor;
     441
     442        pos.x = event->hpos;
     443        pos.y = event->vpos;
     444
     445        /* Set appropriate resizing cursor, or set arrow cursor */
     446
     447        rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
     448        cursor = ui_wdecor_cursor_from_rsztype(rsztype);
     449
     450        ui_wdecor_set_cursor(wdecor, cursor);
     451
     452        /* Press on window border? */
     453        if (rsztype != ui_wr_none && event->type == POS_PRESS)
     454                ui_wdecor_resize(wdecor, rsztype, &pos);
     455}
     456
    289457/** Handle window decoration position event.
    290458 *
     
    307475                return;
    308476
     477        ui_wdecor_frame_pos_event(wdecor, event);
     478
    309479        if (event->type == POS_PRESS &&
    310480            gfx_pix_inside_rect(&pos, &geom.title_bar_rect))
  • uspace/lib/ui/src/window.c

    rd8ddf7a r2d879f7  
    5959static void dwnd_kbd_event(void *, kbd_event_t *);
    6060static void dwnd_pos_event(void *, pos_event_t *);
     61static void dwnd_resize_event(void *, gfx_rect_t *);
    6162static void dwnd_unfocus_event(void *);
    6263
     
    6667        .kbd_event = dwnd_kbd_event,
    6768        .pos_event = dwnd_pos_event,
     69        .resize_event = dwnd_resize_event,
    6870        .unfocus_event = dwnd_unfocus_event
    6971};
     
    7173static void wd_close(ui_wdecor_t *, void *);
    7274static void wd_move(ui_wdecor_t *, void *, gfx_coord2_t *);
     75static void wd_resize(ui_wdecor_t *, void *, ui_wdecor_rsztype_t,
     76    gfx_coord2_t *);
     77static void wd_set_cursor(ui_wdecor_t *, void *, ui_stock_cursor_t);
    7378
    7479static ui_wdecor_cb_t wdecor_cb = {
    7580        .close = wd_close,
    76         .move = wd_move
     81        .move = wd_move,
     82        .resize = wd_resize,
     83        .set_cursor = wd_set_cursor
    7784};
    7885
     
    118125        display_wnd_params_init(&dparams);
    119126        dparams.rect = params->rect;
     127        /* Only allow making the window larger */
     128        gfx_rect_dims(&params->rect, &dparams.min_size);
    120129
    121130        if (ui->display != NULL) {
     
    175184                goto error;
    176185
    177         rc = ui_wdecor_create(res, params->caption, &wdecor);
     186        rc = ui_wdecor_create(res, params->caption, params->style, &wdecor);
    178187        if (rc != EOK)
    179188                goto error;
     
    185194        window->ui = ui;
    186195        window->dwindow = dwindow;
     196        window->rect = params->rect;
    187197        window->gc = gc;
    188198        window->res = res;
    189199        window->wdecor = wdecor;
     200        window->cursor = ui_curs_arrow;
    190201        *rwindow = window;
    191202        return EOK;
     
    435446}
    436447
     448/** Handle window resize event */
     449static void dwnd_resize_event(void *arg, gfx_rect_t *rect)
     450{
     451        ui_window_t *window = (ui_window_t *) arg;
     452
     453        /* Make sure we don't process events until fully initialized */
     454        if (window->wdecor == NULL)
     455                return;
     456
     457        if ((window->wdecor->style & ui_wds_resizable) == 0)
     458                return;
     459
     460        (void) ui_window_resize(window, rect);
     461        (void) ui_window_paint(window);
     462}
     463
    437464/** Handle window unfocus event. */
    438465static void dwnd_unfocus_event(void *arg)
     
    451478 *
    452479 * @param wdecor Window decoration
    453  * @param arg Argument (demo)
     480 * @param arg Argument (window)
    454481 */
    455482static void wd_close(ui_wdecor_t *wdecor, void *arg)
     
    463490 *
    464491 * @param wdecor Window decoration
    465  * @param arg Argument (demo)
     492 * @param arg Argument (window)
    466493 * @param pos Position where the title bar was pressed
    467494 */
     
    471498
    472499        (void) display_window_move_req(window->dwindow, pos);
     500}
     501
     502/** Window decoration requested window resize.
     503 *
     504 * @param wdecor Window decoration
     505 * @param arg Argument (window)
     506 * @param rsztype Resize type
     507 * @param pos Position where the button was pressed
     508 */
     509static void wd_resize(ui_wdecor_t *wdecor, void *arg,
     510    ui_wdecor_rsztype_t rsztype, gfx_coord2_t *pos)
     511{
     512        ui_window_t *window = (ui_window_t *) arg;
     513
     514        (void) display_window_resize_req(window->dwindow, rsztype, pos);
     515}
     516
     517/** Window decoration requested changing cursor.
     518 *
     519 * @param wdecor Window decoration
     520 * @param arg Argument (window)
     521 * @param cursor Cursor to set
     522 */
     523static void wd_set_cursor(ui_wdecor_t *wdecor, void *arg,
     524    ui_stock_cursor_t cursor)
     525{
     526        ui_window_t *window = (ui_window_t *) arg;
     527        display_stock_cursor_t dcursor;
     528
     529        if (cursor == window->cursor)
     530                return;
     531
     532        dcursor = dcurs_arrow;
     533
     534        switch (cursor) {
     535        case ui_curs_arrow:
     536                dcursor = dcurs_arrow;
     537                break;
     538        case ui_curs_size_ud:
     539                dcursor = dcurs_size_ud;
     540                break;
     541        case ui_curs_size_lr:
     542                dcursor = dcurs_size_lr;
     543                break;
     544        case ui_curs_size_uldr:
     545                dcursor = dcurs_size_uldr;
     546                break;
     547        case ui_curs_size_urdl:
     548                dcursor = dcurs_size_urdl;
     549                break;
     550        }
     551
     552        (void) display_window_set_cursor(window->dwindow, dcursor);
     553        window->cursor = cursor;
    473554}
    474555
  • uspace/lib/ui/test/wdecor.c

    rd8ddf7a r2d879f7  
    6060static void test_wdecor_close(ui_wdecor_t *, void *);
    6161static void test_wdecor_move(ui_wdecor_t *, void *, gfx_coord2_t *);
     62static void test_wdecor_resize(ui_wdecor_t *, void *, ui_wdecor_rsztype_t,
     63    gfx_coord2_t *);
     64static void test_wdecor_set_cursor(ui_wdecor_t *, void *, ui_stock_cursor_t);
    6265
    6366static ui_wdecor_cb_t test_wdecor_cb = {
    6467        .close = test_wdecor_close,
    65         .move = test_wdecor_move
     68        .move = test_wdecor_move,
     69        .resize = test_wdecor_resize,
     70        .set_cursor = test_wdecor_set_cursor
    6671};
    6772
     
    9095        bool move;
    9196        gfx_coord2_t pos;
     97        bool resize;
     98        ui_wdecor_rsztype_t rsztype;
     99        bool set_cursor;
     100        ui_stock_cursor_t cursor;
    92101} test_cb_resp_t;
    93102
     
    98107        errno_t rc;
    99108
    100         rc = ui_wdecor_create(NULL, "Hello", &wdecor);
     109        rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
    101110        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    102111        PCUT_ASSERT_NOT_NULL(wdecor);
     
    118127        errno_t rc;
    119128
    120         rc = ui_wdecor_create(NULL, "Hello", &wdecor);
     129        rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
    121130        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    122131
     
    141150        errno_t rc;
    142151
    143         rc = ui_wdecor_create(NULL, "Hello", &wdecor);
     152        rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
    144153        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    145154
     
    172181        PCUT_ASSERT_NOT_NULL(resource);
    173182
    174         rc = ui_wdecor_create(resource, "Hello", &wdecor);
     183        rc = ui_wdecor_create(resource, "Hello", ui_wds_none, &wdecor);
    175184        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    176185
     
    192201        test_cb_resp_t resp;
    193202
    194         rc = ui_wdecor_create(NULL, "Hello", &wdecor);
     203        rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
    195204        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    196205
     
    219228        gfx_coord2_t pos;
    220229
    221         rc = ui_wdecor_create(NULL, "Hello", &wdecor);
     230        rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
    222231        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    223232
     
    245254}
    246255
     256/** Test ui_wdecor_resize() */
     257PCUT_TEST(resize)
     258{
     259        errno_t rc;
     260        ui_wdecor_t *wdecor;
     261        test_cb_resp_t resp;
     262        ui_wdecor_rsztype_t rsztype;
     263        gfx_coord2_t pos;
     264
     265        rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
     266        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     267
     268        rsztype = ui_wr_bottom;
     269        pos.x = 3;
     270        pos.y = 4;
     271
     272        /* Resize callback with no callbacks set */
     273        ui_wdecor_resize(wdecor, rsztype, &pos);
     274
     275        /* Resize callback with move callback not implemented */
     276        ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
     277        ui_wdecor_resize(wdecor, rsztype, &pos);
     278
     279        /* Resize callback with real callback set */
     280        resp.resize = false;
     281        resp.rsztype = ui_wr_none;
     282        resp.pos.x = 0;
     283        resp.pos.y = 0;
     284        ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
     285        ui_wdecor_resize(wdecor, rsztype, &pos);
     286        PCUT_ASSERT_TRUE(resp.resize);
     287        PCUT_ASSERT_INT_EQUALS(rsztype, resp.rsztype);
     288        PCUT_ASSERT_INT_EQUALS(pos.x, resp.pos.x);
     289        PCUT_ASSERT_INT_EQUALS(pos.y, resp.pos.y);
     290
     291        ui_wdecor_destroy(wdecor);
     292}
     293
     294/** Test ui_wdecor_set_cursor() */
     295PCUT_TEST(set_cursor)
     296{
     297        errno_t rc;
     298        ui_wdecor_t *wdecor;
     299        test_cb_resp_t resp;
     300        ui_stock_cursor_t cursor;
     301
     302        rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
     303        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     304
     305        cursor = ui_curs_size_uldr;
     306
     307        /* Set cursor callback with no callbacks set */
     308        ui_wdecor_set_cursor(wdecor, cursor);
     309
     310        /* Set cursor callback with move callback not implemented */
     311        ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
     312        ui_wdecor_set_cursor(wdecor, cursor);
     313
     314        /* Set cursor callback with real callback set */
     315        resp.set_cursor = false;
     316        resp.cursor = ui_curs_arrow;
     317        ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
     318        ui_wdecor_set_cursor(wdecor, cursor);
     319        PCUT_ASSERT_TRUE(resp.set_cursor);
     320        PCUT_ASSERT_INT_EQUALS(cursor, resp.cursor);
     321
     322        ui_wdecor_destroy(wdecor);
     323}
     324
    247325/** Clicking the close button generates close callback */
    248326PCUT_TEST(close_btn_clicked)
     
    253331        errno_t rc;
    254332
    255         rc = ui_wdecor_create(NULL, "Hello", &wdecor);
     333        rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
    256334        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    257335
     
    282360        errno_t rc;
    283361
    284         rc = ui_wdecor_create(NULL, "Hello", &wdecor);
     362        rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
    285363        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    286364
     
    318396        errno_t rc;
    319397
    320         rc = ui_wdecor_create(NULL, "Hello", &wdecor);
     398        rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
    321399        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    322400
     
    369447        PCUT_ASSERT_INT_EQUALS(100, rect.p1.x);
    370448        PCUT_ASSERT_INT_EQUALS(200, rect.p1.y);
     449}
     450
     451/** Test ui_wdecor_get_rsztype() */
     452PCUT_TEST(get_rsztype)
     453{
     454        ui_wdecor_t *wdecor;
     455        gfx_rect_t rect;
     456        ui_wdecor_rsztype_t rsztype;
     457        gfx_coord2_t pos;
     458        errno_t rc;
     459
     460        rc = ui_wdecor_create(NULL, "Hello", ui_wds_resizable, &wdecor);
     461        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     462
     463        rect.p0.x = 10;
     464        rect.p0.y = 20;
     465        rect.p1.x = 100;
     466        rect.p1.y = 200;
     467
     468        ui_wdecor_set_rect(wdecor, &rect);
     469
     470        /* Outside of the window */
     471        pos.x = 0;
     472        pos.y = -1;
     473        rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
     474        PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
     475
     476        /* Middle of the window */
     477        pos.x = 50;
     478        pos.y = 100;
     479        rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
     480        PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
     481
     482        /* Top-left corner, but not on edge */
     483        pos.x = 20;
     484        pos.y = 30;
     485        rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
     486        PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
     487
     488        /* Top-left corner on top edge */
     489        pos.x = 20;
     490        pos.y = 20;
     491        rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
     492        PCUT_ASSERT_EQUALS(ui_wr_top_left, rsztype);
     493
     494        /* Top-left corner on left edge */
     495        pos.x = 10;
     496        pos.y = 30;
     497        rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
     498        PCUT_ASSERT_EQUALS(ui_wr_top_left, rsztype);
     499
     500        /* Top-right corner on top edge */
     501        pos.x = 90;
     502        pos.y = 20;
     503        rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
     504        PCUT_ASSERT_EQUALS(ui_wr_top_right, rsztype);
     505
     506        /* Top-right corner on right edge */
     507        pos.x = 99;
     508        pos.y = 30;
     509        rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
     510        PCUT_ASSERT_EQUALS(ui_wr_top_right, rsztype);
     511
     512        /* Top edge */
     513        pos.x = 50;
     514        pos.y = 20;
     515        rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
     516        PCUT_ASSERT_EQUALS(ui_wr_top, rsztype);
     517
     518        /* Bottom edge */
     519        pos.x = 50;
     520        pos.y = 199;
     521        rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
     522        PCUT_ASSERT_EQUALS(ui_wr_bottom, rsztype);
     523
     524        /* Left edge */
     525        pos.x = 10;
     526        pos.y = 100;
     527        rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
     528        PCUT_ASSERT_EQUALS(ui_wr_left, rsztype);
     529
     530        /* Right edge */
     531        pos.x = 99;
     532        pos.y = 100;
     533        rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
     534        PCUT_ASSERT_EQUALS(ui_wr_right, rsztype);
     535
     536        ui_wdecor_destroy(wdecor);
     537
     538        /* Non-resizable window */
     539
     540        rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
     541        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     542
     543        rect.p0.x = 10;
     544        rect.p0.y = 20;
     545        rect.p1.x = 100;
     546        rect.p1.y = 200;
     547
     548        ui_wdecor_set_rect(wdecor, &rect);
     549
     550        pos.x = 10;
     551        pos.y = 20;
     552        rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
     553        PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
     554
     555        ui_wdecor_destroy(wdecor);
     556}
     557
     558/** Test ui_wdecor_cursor_from_rsztype() */
     559PCUT_TEST(cursor_from_rsztype)
     560{
     561        PCUT_ASSERT_EQUALS(ui_curs_arrow,
     562            ui_wdecor_cursor_from_rsztype(ui_wr_none));
     563        PCUT_ASSERT_EQUALS(ui_curs_size_ud,
     564            ui_wdecor_cursor_from_rsztype(ui_wr_top));
     565        PCUT_ASSERT_EQUALS(ui_curs_size_ud,
     566            ui_wdecor_cursor_from_rsztype(ui_wr_bottom));
     567        PCUT_ASSERT_EQUALS(ui_curs_size_lr,
     568            ui_wdecor_cursor_from_rsztype(ui_wr_left));
     569        PCUT_ASSERT_EQUALS(ui_curs_size_lr,
     570            ui_wdecor_cursor_from_rsztype(ui_wr_right));
     571        PCUT_ASSERT_EQUALS(ui_curs_size_uldr,
     572            ui_wdecor_cursor_from_rsztype(ui_wr_top_left));
     573        PCUT_ASSERT_EQUALS(ui_curs_size_uldr,
     574            ui_wdecor_cursor_from_rsztype(ui_wr_bottom_right));
     575        PCUT_ASSERT_EQUALS(ui_curs_size_urdl,
     576            ui_wdecor_cursor_from_rsztype(ui_wr_top_right));
     577        PCUT_ASSERT_EQUALS(ui_curs_size_urdl,
     578            ui_wdecor_cursor_from_rsztype(ui_wr_bottom_left));
     579}
     580
     581/** Test ui_wdecor_frame_pos_event() */
     582PCUT_TEST(frame_pos_event)
     583{
     584        ui_wdecor_t *wdecor;
     585        gfx_rect_t rect;
     586        test_cb_resp_t resp;
     587        pos_event_t event;
     588        errno_t rc;
     589
     590        rc = ui_wdecor_create(NULL, "Hello", ui_wds_resizable, &wdecor);
     591        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     592
     593        rect.p0.x = 10;
     594        rect.p0.y = 20;
     595        rect.p1.x = 100;
     596        rect.p1.y = 200;
     597
     598        ui_wdecor_set_rect(wdecor, &rect);
     599        ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
     600
     601        /* Release on window border should do nothing */
     602        resp.resize = false;
     603        event.type = POS_RELEASE;
     604        event.hpos = 10;
     605        event.vpos = 10;
     606        ui_wdecor_frame_pos_event(wdecor, &event);
     607        PCUT_ASSERT_FALSE(resp.resize);
     608
     609        /* Press in the middle of the window should do nothing */
     610        resp.resize = false;
     611        event.type = POS_PRESS;
     612        event.hpos = 50;
     613        event.vpos = 100;
     614        ui_wdecor_frame_pos_event(wdecor, &event);
     615        PCUT_ASSERT_FALSE(resp.resize);
     616
     617        /* Press on window border should cause resize to be called */
     618        resp.resize = false;
     619        event.type = POS_PRESS;
     620        event.hpos = 10;
     621        event.vpos = 20;
     622        ui_wdecor_frame_pos_event(wdecor, &event);
     623        PCUT_ASSERT_TRUE(resp.resize);
     624
     625        ui_wdecor_destroy(wdecor);
    371626}
    372627
     
    462717}
    463718
     719static void test_wdecor_resize(ui_wdecor_t *wdecor, void *arg,
     720    ui_wdecor_rsztype_t rsztype, gfx_coord2_t *pos)
     721{
     722        test_cb_resp_t *resp = (test_cb_resp_t *) arg;
     723
     724        resp->resize = true;
     725        resp->rsztype = rsztype;
     726        resp->pos = *pos;
     727}
     728
     729static void test_wdecor_set_cursor(ui_wdecor_t *wdecor, void *arg,
     730    ui_stock_cursor_t cursor)
     731{
     732        test_cb_resp_t *resp = (test_cb_resp_t *) arg;
     733
     734        resp->set_cursor = true;
     735        resp->cursor = cursor;
     736}
     737
    464738PCUT_EXPORT(wdecor);
Note: See TracChangeset for help on using the changeset viewer.