Changeset 12008adf in mainline for uspace/lib/ui
- Timestamp:
- 2020-11-12T10:58:36Z (5 years ago)
- 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)
- Location:
- uspace/lib/ui
- Files:
-
- 3 edited
-
include/ui/image.h (modified) (1 diff)
-
src/image.c (modified) (2 diffs)
-
test/image.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/include/ui/image.h
r7a5825b r12008adf 48 48 extern void ui_image_destroy(ui_image_t *); 49 49 extern ui_control_t *ui_image_ctl(ui_image_t *); 50 extern void ui_image_set_bmp(ui_image_t *, gfx_bitmap_t *, gfx_rect_t *); 50 51 extern void ui_image_set_rect(ui_image_t *, gfx_rect_t *); 51 52 extern errno_t ui_image_paint(ui_image_t *); -
uspace/lib/ui/src/image.c
r7a5825b r12008adf 134 134 gfx_coord2_t offs; 135 135 136 if (image->bitmap == NULL) 137 return EOK; 138 136 139 /* 137 140 * UI image position does not depend on bitmap rectangle p0, so … … 149 152 } 150 153 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 */ 164 void 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 151 171 /** Destroy image control. 152 172 * -
uspace/lib/ui/test/image.c
r7a5825b r12008adf 87 87 PCUT_TEST(set_rect) 88 88 { 89 90 89 ui_image_t *image = NULL; 91 90 gfx_rect_t brect; … … 107 106 PCUT_ASSERT_INT_EQUALS(rect.p1.x, image->rect.p1.x); 108 107 PCUT_ASSERT_INT_EQUALS(rect.p1.y, image->rect.p1.y); 108 109 ui_image_destroy(image); 110 } 111 112 /** Set image bitmap */ 113 PCUT_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(¶ms); 145 rc = gfx_bitmap_create(gc, ¶ms, 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); 109 153 110 154 ui_image_destroy(image); … … 138 182 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 139 183 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 140 191 ui_image_destroy(image); 141 192 }
Note:
See TracChangeset
for help on using the changeset viewer.
