Ignore:
File:
1 edited

Legend:

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

    r3c54869 r1fa6292  
    3636#include <ui/resource.h>
    3737#include "../private/pbutton.h"
     38#include "../private/testgc.h"
    3839
    3940PCUT_INIT;
    4041
    4142PCUT_TEST_SUITE(pbutton);
    42 
    43 static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    44 static errno_t testgc_set_color(void *, gfx_color_t *);
    45 static errno_t testgc_fill_rect(void *, gfx_rect_t *);
    46 static errno_t testgc_update(void *);
    47 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
    48     gfx_bitmap_alloc_t *, void **);
    49 static errno_t testgc_bitmap_destroy(void *);
    50 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
    51 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
    52 
    53 static 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 };
    6343
    6444static void test_pbutton_clicked(ui_pbutton_t *, void *);
     
    7454static ui_pbutton_cb_t dummy_pbutton_cb = {
    7555};
    76 
    77 typedef struct {
    78         bool bm_created;
    79         bool bm_destroyed;
    80         gfx_bitmap_params_t bm_params;
    81         void *bm_pixels;
    82         gfx_rect_t bm_srect;
    83         gfx_coord2_t bm_offs;
    84         bool bm_rendered;
    85         bool bm_got_alloc;
    86 } test_gc_t;
    87 
    88 typedef struct {
    89         test_gc_t *tgc;
    90         gfx_bitmap_alloc_t alloc;
    91         bool myalloc;
    92 } testgc_bitmap_t;
    9356
    9457typedef struct {
     
    625588}
    626589
    627 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
    628 {
    629         (void) arg;
    630         (void) rect;
    631         return EOK;
    632 }
    633 
    634 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    635 {
    636         (void) arg;
    637         (void) color;
    638         return EOK;
    639 }
    640 
    641 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    642 {
    643         (void) arg;
    644         (void) rect;
    645         return EOK;
    646 }
    647 
    648 static errno_t testgc_update(void *arg)
    649 {
    650         (void) arg;
    651         return EOK;
    652 }
    653 
    654 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    655     gfx_bitmap_alloc_t *alloc, void **rbm)
    656 {
    657         test_gc_t *tgc = (test_gc_t *) arg;
    658         testgc_bitmap_t *tbm;
    659 
    660         tbm = calloc(1, sizeof(testgc_bitmap_t));
    661         if (tbm == NULL)
    662                 return ENOMEM;
    663 
    664         if (alloc == NULL) {
    665                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    666                     sizeof(uint32_t);
    667                 tbm->alloc.off0 = 0;
    668                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    669                     (params->rect.p1.x - params->rect.p0.x) *
    670                     (params->rect.p1.y - params->rect.p0.y));
    671                 tbm->myalloc = true;
    672                 if (tbm->alloc.pixels == NULL) {
    673                         free(tbm);
    674                         return ENOMEM;
    675                 }
    676         } else {
    677                 tbm->alloc = *alloc;
    678         }
    679 
    680         tbm->tgc = tgc;
    681         tgc->bm_created = true;
    682         tgc->bm_params = *params;
    683         tgc->bm_pixels = tbm->alloc.pixels;
    684         *rbm = (void *)tbm;
    685         return EOK;
    686 }
    687 
    688 static errno_t testgc_bitmap_destroy(void *bm)
    689 {
    690         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    691         if (tbm->myalloc)
    692                 free(tbm->alloc.pixels);
    693         tbm->tgc->bm_destroyed = true;
    694         free(tbm);
    695         return EOK;
    696 }
    697 
    698 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    699     gfx_coord2_t *offs)
    700 {
    701         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    702         tbm->tgc->bm_rendered = true;
    703         tbm->tgc->bm_srect = *srect;
    704         tbm->tgc->bm_offs = *offs;
    705         return EOK;
    706 }
    707 
    708 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    709 {
    710         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    711         *alloc = tbm->alloc;
    712         tbm->tgc->bm_got_alloc = true;
    713         return EOK;
    714 }
    715 
    716590static void test_pbutton_clicked(ui_pbutton_t *pbutton, void *arg)
    717591{
Note: See TracChangeset for help on using the changeset viewer.