Changeset 12008adf in mainline for uspace/lib/ui


Ignore:
Timestamp:
2020-11-12T10:58:36Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2c9fdeed
Parents:
7a5825b
git-author:
Jiri Svoboda <jiri@…> (2020-11-11 23:58:55)
git-committer:
Jiri Svoboda <jiri@…> (2020-11-12 10:58:36)
Message:

Port barber to UI

Location:
uspace/lib/ui
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/include/ui/image.h

    r7a5825b r12008adf  
    4848extern void ui_image_destroy(ui_image_t *);
    4949extern ui_control_t *ui_image_ctl(ui_image_t *);
     50extern void ui_image_set_bmp(ui_image_t *, gfx_bitmap_t *, gfx_rect_t *);
    5051extern void ui_image_set_rect(ui_image_t *, gfx_rect_t *);
    5152extern errno_t ui_image_paint(ui_image_t *);
  • uspace/lib/ui/src/image.c

    r7a5825b r12008adf  
    134134        gfx_coord2_t offs;
    135135
     136        if (image->bitmap == NULL)
     137                return EOK;
     138
    136139        /*
    137140         * UI image position does not depend on bitmap rectangle p0, so
     
    149152}
    150153
     154/** Change image bitmap.
     155 *
     156 * Note that the caller must have saved the pointer to the previous bitmap
     157 * in the image, because this causes it to be unlinked from the image and
     158 * not destroyed (the ownership is transferred back to the caller).
     159 *
     160 * @param image Image
     161 * @param bitmap New bitmap (ownership transferred to image) or @c NULL
     162 * @param brect New bitmap rectangle
     163 */
     164void ui_image_set_bmp(ui_image_t *image, gfx_bitmap_t *bitmap,
     165    gfx_rect_t *brect)
     166{
     167        image->bitmap = bitmap;
     168        image->brect = *brect;
     169}
     170
    151171/** Destroy image control.
    152172 *
  • uspace/lib/ui/test/image.c

    r7a5825b r12008adf  
    8787PCUT_TEST(set_rect)
    8888{
    89 
    9089        ui_image_t *image = NULL;
    9190        gfx_rect_t brect;
     
    107106        PCUT_ASSERT_INT_EQUALS(rect.p1.x, image->rect.p1.x);
    108107        PCUT_ASSERT_INT_EQUALS(rect.p1.y, image->rect.p1.y);
     108
     109        ui_image_destroy(image);
     110}
     111
     112/** Set image bitmap */
     113PCUT_TEST(set_bmp)
     114{
     115        ui_image_t *image = NULL;
     116        gfx_rect_t brect;
     117        gfx_rect_t rect;
     118        gfx_bitmap_t *bitmap;
     119        gfx_bitmap_params_t params;
     120        dummy_gc_t *dgc;
     121        gfx_context_t *gc;
     122        errno_t rc;
     123
     124        rc = dummygc_create(&dgc);
     125        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     126
     127        gc = dummygc_get_ctx(dgc);
     128
     129        rc = ui_image_create(NULL, NULL, &brect, &image);
     130        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     131        PCUT_ASSERT_NOT_NULL(image);
     132
     133        rect.p0.x = 1;
     134        rect.p0.y = 2;
     135        rect.p1.x = 3;
     136        rect.p1.y = 4;
     137
     138        ui_image_set_rect(image, &rect);
     139        PCUT_ASSERT_INT_EQUALS(rect.p0.x, image->rect.p0.x);
     140        PCUT_ASSERT_INT_EQUALS(rect.p0.y, image->rect.p0.y);
     141        PCUT_ASSERT_INT_EQUALS(rect.p1.x, image->rect.p1.x);
     142        PCUT_ASSERT_INT_EQUALS(rect.p1.y, image->rect.p1.y);
     143
     144        gfx_bitmap_params_init(&params);
     145        rc = gfx_bitmap_create(gc, &params, NULL, &bitmap);
     146        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     147
     148        ui_image_set_bmp(image, bitmap, &brect);
     149        PCUT_ASSERT_EQUALS(bitmap, image->bitmap);
     150
     151        rc = ui_image_paint(image);
     152        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    109153
    110154        ui_image_destroy(image);
     
    138182        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    139183
     184        /* Check that we can paint image after setting bitmap to NULL */
     185
     186        ui_image_set_bmp(image, NULL, &brect);
     187
     188        rc = ui_image_paint(image);
     189        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     190
    140191        ui_image_destroy(image);
    141192}
Note: See TracChangeset for help on using the changeset viewer.