Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/test/checkbox.c

    r1fa6292 r806d761  
    3636#include <ui/resource.h>
    3737#include "../private/checkbox.h"
    38 #include "../private/testgc.h"
    3938
    4039PCUT_INIT;
    4140
    4241PCUT_TEST_SUITE(checkbox);
     42
     43static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
     44static errno_t testgc_set_color(void *, gfx_color_t *);
     45static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     46static errno_t testgc_update(void *);
     47static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
     48    gfx_bitmap_alloc_t *, void **);
     49static errno_t testgc_bitmap_destroy(void *);
     50static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
     51static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
     52
     53static gfx_context_ops_t ops = {
     54        .set_clip_rect = testgc_set_clip_rect,
     55        .set_color = testgc_set_color,
     56        .fill_rect = testgc_fill_rect,
     57        .update = testgc_update,
     58        .bitmap_create = testgc_bitmap_create,
     59        .bitmap_destroy = testgc_bitmap_destroy,
     60        .bitmap_render = testgc_bitmap_render,
     61        .bitmap_get_alloc = testgc_bitmap_get_alloc
     62};
    4363
    4464static void test_checkbox_switched(ui_checkbox_t *, void *, bool);
     
    5070static ui_checkbox_cb_t dummy_checkbox_cb = {
    5171};
     72
     73typedef struct {
     74        bool bm_created;
     75        bool bm_destroyed;
     76        gfx_bitmap_params_t bm_params;
     77        void *bm_pixels;
     78        gfx_rect_t bm_srect;
     79        gfx_coord2_t bm_offs;
     80        bool bm_rendered;
     81        bool bm_got_alloc;
     82} test_gc_t;
     83
     84typedef struct {
     85        test_gc_t *tgc;
     86        gfx_bitmap_alloc_t alloc;
     87        bool myalloc;
     88} testgc_bitmap_t;
    5289
    5390typedef struct {
     
    512549}
    513550
     551static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     552{
     553        (void) arg;
     554        (void) rect;
     555        return EOK;
     556}
     557
     558static errno_t testgc_set_color(void *arg, gfx_color_t *color)
     559{
     560        (void) arg;
     561        (void) color;
     562        return EOK;
     563}
     564
     565static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
     566{
     567        (void) arg;
     568        (void) rect;
     569        return EOK;
     570}
     571
     572static errno_t testgc_update(void *arg)
     573{
     574        (void) arg;
     575        return EOK;
     576}
     577
     578static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
     579    gfx_bitmap_alloc_t *alloc, void **rbm)
     580{
     581        test_gc_t *tgc = (test_gc_t *) arg;
     582        testgc_bitmap_t *tbm;
     583
     584        tbm = calloc(1, sizeof(testgc_bitmap_t));
     585        if (tbm == NULL)
     586                return ENOMEM;
     587
     588        if (alloc == NULL) {
     589                tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
     590                    sizeof(uint32_t);
     591                tbm->alloc.off0 = 0;
     592                tbm->alloc.pixels = calloc(sizeof(uint32_t),
     593                    (params->rect.p1.x - params->rect.p0.x) *
     594                    (params->rect.p1.y - params->rect.p0.y));
     595                tbm->myalloc = true;
     596                if (tbm->alloc.pixels == NULL) {
     597                        free(tbm);
     598                        return ENOMEM;
     599                }
     600        } else {
     601                tbm->alloc = *alloc;
     602        }
     603
     604        tbm->tgc = tgc;
     605        tgc->bm_created = true;
     606        tgc->bm_params = *params;
     607        tgc->bm_pixels = tbm->alloc.pixels;
     608        *rbm = (void *)tbm;
     609        return EOK;
     610}
     611
     612static errno_t testgc_bitmap_destroy(void *bm)
     613{
     614        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     615        if (tbm->myalloc)
     616                free(tbm->alloc.pixels);
     617        tbm->tgc->bm_destroyed = true;
     618        free(tbm);
     619        return EOK;
     620}
     621
     622static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
     623    gfx_coord2_t *offs)
     624{
     625        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     626        tbm->tgc->bm_rendered = true;
     627        tbm->tgc->bm_srect = *srect;
     628        tbm->tgc->bm_offs = *offs;
     629        return EOK;
     630}
     631
     632static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
     633{
     634        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     635        *alloc = tbm->alloc;
     636        tbm->tgc->bm_got_alloc = true;
     637        return EOK;
     638}
     639
    514640static void test_checkbox_switched(ui_checkbox_t *checkbox, void *arg,
    515641    bool checked)
Note: See TracChangeset for help on using the changeset viewer.