| 1 | /*
|
|---|
| 2 | * Copyright (c) 2023 Jiri Svoboda
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | #include <gfx/context.h>
|
|---|
| 30 | #include <gfx/coord.h>
|
|---|
| 31 | #include <mem.h>
|
|---|
| 32 | #include <pcut/pcut.h>
|
|---|
| 33 | #include <stdbool.h>
|
|---|
| 34 | #include <ui/paint.h>
|
|---|
| 35 | #include <ui/resource.h>
|
|---|
| 36 |
|
|---|
| 37 | PCUT_INIT;
|
|---|
| 38 |
|
|---|
| 39 | PCUT_TEST_SUITE(paint);
|
|---|
| 40 |
|
|---|
| 41 | static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
|
|---|
| 42 | static errno_t testgc_set_color(void *, gfx_color_t *);
|
|---|
| 43 | static errno_t testgc_fill_rect(void *, gfx_rect_t *);
|
|---|
| 44 | static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
|
|---|
| 45 | gfx_bitmap_alloc_t *, void **);
|
|---|
| 46 | static errno_t testgc_bitmap_destroy(void *);
|
|---|
| 47 | static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
|
|---|
| 48 | static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
|
|---|
| 49 |
|
|---|
| 50 | static gfx_context_ops_t ops = {
|
|---|
| 51 | .set_clip_rect = testgc_set_clip_rect,
|
|---|
| 52 | .set_color = testgc_set_color,
|
|---|
| 53 | .fill_rect = testgc_fill_rect,
|
|---|
| 54 | .bitmap_create = testgc_bitmap_create,
|
|---|
| 55 | .bitmap_destroy = testgc_bitmap_destroy,
|
|---|
| 56 | .bitmap_render = testgc_bitmap_render,
|
|---|
| 57 | .bitmap_get_alloc = testgc_bitmap_get_alloc
|
|---|
| 58 | };
|
|---|
| 59 |
|
|---|
| 60 | typedef struct {
|
|---|
| 61 | bool bm_created;
|
|---|
| 62 | bool bm_destroyed;
|
|---|
| 63 | gfx_bitmap_params_t bm_params;
|
|---|
| 64 | void *bm_pixels;
|
|---|
| 65 | gfx_rect_t bm_srect;
|
|---|
| 66 | gfx_coord2_t bm_offs;
|
|---|
| 67 | bool bm_rendered;
|
|---|
| 68 | bool bm_got_alloc;
|
|---|
| 69 | } test_gc_t;
|
|---|
| 70 |
|
|---|
| 71 | typedef struct {
|
|---|
| 72 | test_gc_t *tgc;
|
|---|
| 73 | gfx_bitmap_alloc_t alloc;
|
|---|
| 74 | bool myalloc;
|
|---|
| 75 | } testgc_bitmap_t;
|
|---|
| 76 |
|
|---|
| 77 | /** Test box characters */
|
|---|
| 78 | static ui_box_chars_t test_box_chars = {
|
|---|
| 79 | {
|
|---|
| 80 | { "A", "B", "C" },
|
|---|
| 81 | { "D", " ", "E" },
|
|---|
| 82 | { "F", "G", "H" }
|
|---|
| 83 | }
|
|---|
| 84 | };
|
|---|
| 85 |
|
|---|
| 86 | /** Paint bevel */
|
|---|
| 87 | PCUT_TEST(bevel)
|
|---|
| 88 | {
|
|---|
| 89 | errno_t rc;
|
|---|
| 90 | gfx_context_t *gc = NULL;
|
|---|
| 91 | test_gc_t tgc;
|
|---|
| 92 | gfx_rect_t rect;
|
|---|
| 93 | gfx_color_t *color1;
|
|---|
| 94 | gfx_color_t *color2;
|
|---|
| 95 | gfx_rect_t inside;
|
|---|
| 96 |
|
|---|
| 97 | memset(&tgc, 0, sizeof(tgc));
|
|---|
| 98 | rc = gfx_context_new(&ops, &tgc, &gc);
|
|---|
| 99 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 100 |
|
|---|
| 101 | rc = gfx_color_new_rgb_i16(1, 2, 3, &color1);
|
|---|
| 102 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 103 |
|
|---|
| 104 | rc = gfx_color_new_rgb_i16(4, 5, 6, &color2);
|
|---|
| 105 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 106 |
|
|---|
| 107 | rect.p0.x = 10;
|
|---|
| 108 | rect.p0.y = 20;
|
|---|
| 109 | rect.p1.x = 30;
|
|---|
| 110 | rect.p1.y = 40;
|
|---|
| 111 |
|
|---|
| 112 | /* Paint bevel with NULL 'inside' output parameter */
|
|---|
| 113 | rc = ui_paint_bevel(gc, &rect, color1, color2, 2, NULL);
|
|---|
| 114 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 115 |
|
|---|
| 116 | /* Paint bevel with valid 'inside' output parameter */
|
|---|
| 117 | rc = ui_paint_bevel(gc, &rect, color1, color2, 2, &inside);
|
|---|
| 118 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 119 |
|
|---|
| 120 | gfx_color_delete(color2);
|
|---|
| 121 | gfx_color_delete(color1);
|
|---|
| 122 | rc = gfx_context_delete(gc);
|
|---|
| 123 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | /** Get bevel inside */
|
|---|
| 127 | PCUT_TEST(get_bevel_inside)
|
|---|
| 128 | {
|
|---|
| 129 | errno_t rc;
|
|---|
| 130 | gfx_context_t *gc = NULL;
|
|---|
| 131 | test_gc_t tgc;
|
|---|
| 132 | gfx_rect_t rect;
|
|---|
| 133 | gfx_rect_t inside;
|
|---|
| 134 |
|
|---|
| 135 | memset(&tgc, 0, sizeof(tgc));
|
|---|
| 136 | rc = gfx_context_new(&ops, &tgc, &gc);
|
|---|
| 137 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 138 |
|
|---|
| 139 | rect.p0.x = 10;
|
|---|
| 140 | rect.p0.y = 20;
|
|---|
| 141 | rect.p1.x = 30;
|
|---|
| 142 | rect.p1.y = 40;
|
|---|
| 143 |
|
|---|
| 144 | ui_paint_get_bevel_inside(gc, &rect, 2, &inside);
|
|---|
| 145 | PCUT_ASSERT_INT_EQUALS(12, inside.p0.x);
|
|---|
| 146 | PCUT_ASSERT_INT_EQUALS(22, inside.p0.y);
|
|---|
| 147 | PCUT_ASSERT_INT_EQUALS(28, inside.p1.x);
|
|---|
| 148 | PCUT_ASSERT_INT_EQUALS(38, inside.p1.y);
|
|---|
| 149 |
|
|---|
| 150 | rc = gfx_context_delete(gc);
|
|---|
| 151 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | /** Paint inset frame */
|
|---|
| 155 | PCUT_TEST(inset_frame)
|
|---|
| 156 | {
|
|---|
| 157 | errno_t rc;
|
|---|
| 158 | gfx_context_t *gc = NULL;
|
|---|
| 159 | ui_resource_t *resource = NULL;
|
|---|
| 160 | test_gc_t tgc;
|
|---|
| 161 | gfx_rect_t rect;
|
|---|
| 162 | gfx_rect_t inside;
|
|---|
| 163 |
|
|---|
| 164 | memset(&tgc, 0, sizeof(tgc));
|
|---|
| 165 | rc = gfx_context_new(&ops, &tgc, &gc);
|
|---|
| 166 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 167 |
|
|---|
| 168 | rc = ui_resource_create(gc, false, &resource);
|
|---|
| 169 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 170 | PCUT_ASSERT_NOT_NULL(resource);
|
|---|
| 171 |
|
|---|
| 172 | rect.p0.x = 10;
|
|---|
| 173 | rect.p0.y = 20;
|
|---|
| 174 | rect.p1.x = 30;
|
|---|
| 175 | rect.p1.y = 40;
|
|---|
| 176 |
|
|---|
| 177 | /* Paint inset frame with NULL 'inside' output parameter */
|
|---|
| 178 | rc = ui_paint_inset_frame(resource, &rect, NULL);
|
|---|
| 179 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 180 |
|
|---|
| 181 | /* Paint inset frame with valid 'inside' output parameter */
|
|---|
| 182 | rc = ui_paint_inset_frame(resource, &rect, &inside);
|
|---|
| 183 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 184 |
|
|---|
| 185 | ui_resource_destroy(resource);
|
|---|
| 186 | rc = gfx_context_delete(gc);
|
|---|
| 187 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|
| 190 | /** Get inset frame inside */
|
|---|
| 191 | PCUT_TEST(get_inset_frame_inside)
|
|---|
| 192 | {
|
|---|
| 193 | errno_t rc;
|
|---|
| 194 | gfx_context_t *gc = NULL;
|
|---|
| 195 | ui_resource_t *resource = NULL;
|
|---|
| 196 | test_gc_t tgc;
|
|---|
| 197 | gfx_rect_t rect;
|
|---|
| 198 | gfx_rect_t inside;
|
|---|
| 199 |
|
|---|
| 200 | memset(&tgc, 0, sizeof(tgc));
|
|---|
| 201 | rc = gfx_context_new(&ops, &tgc, &gc);
|
|---|
| 202 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 203 |
|
|---|
| 204 | rc = ui_resource_create(gc, false, &resource);
|
|---|
| 205 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 206 | PCUT_ASSERT_NOT_NULL(resource);
|
|---|
| 207 |
|
|---|
| 208 | rect.p0.x = 10;
|
|---|
| 209 | rect.p0.y = 20;
|
|---|
| 210 | rect.p1.x = 30;
|
|---|
| 211 | rect.p1.y = 40;
|
|---|
| 212 |
|
|---|
| 213 | ui_paint_get_inset_frame_inside(resource, &rect, &inside);
|
|---|
| 214 | PCUT_ASSERT_INT_EQUALS(12, inside.p0.x);
|
|---|
| 215 | PCUT_ASSERT_INT_EQUALS(22, inside.p0.y);
|
|---|
| 216 | PCUT_ASSERT_INT_EQUALS(28, inside.p1.x);
|
|---|
| 217 | PCUT_ASSERT_INT_EQUALS(38, inside.p1.y);
|
|---|
| 218 |
|
|---|
| 219 | ui_resource_destroy(resource);
|
|---|
| 220 | rc = gfx_context_delete(gc);
|
|---|
| 221 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | /** Paint filled circle */
|
|---|
| 225 | PCUT_TEST(filled_circle)
|
|---|
| 226 | {
|
|---|
| 227 | errno_t rc;
|
|---|
| 228 | gfx_context_t *gc = NULL;
|
|---|
| 229 | test_gc_t tgc;
|
|---|
| 230 | gfx_coord2_t center;
|
|---|
| 231 |
|
|---|
| 232 | memset(&tgc, 0, sizeof(tgc));
|
|---|
| 233 | rc = gfx_context_new(&ops, &tgc, &gc);
|
|---|
| 234 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 235 |
|
|---|
| 236 | center.x = 0;
|
|---|
| 237 | center.y = 0;
|
|---|
| 238 |
|
|---|
| 239 | /* Paint filled circle / upper-left half */
|
|---|
| 240 | rc = ui_paint_filled_circle(gc, ¢er, 10, ui_fcircle_upleft);
|
|---|
| 241 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 242 |
|
|---|
| 243 | /* Paint filled circle / lower-right half */
|
|---|
| 244 | rc = ui_paint_filled_circle(gc, ¢er, 10, ui_fcircle_lowright);
|
|---|
| 245 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 246 |
|
|---|
| 247 | /* Paint entire filled circle */
|
|---|
| 248 | rc = ui_paint_filled_circle(gc, ¢er, 10, ui_fcircle_entire);
|
|---|
| 249 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 250 |
|
|---|
| 251 | rc = gfx_context_delete(gc);
|
|---|
| 252 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | /** Paint up pointing triangle */
|
|---|
| 256 | PCUT_TEST(up_triangle)
|
|---|
| 257 | {
|
|---|
| 258 | errno_t rc;
|
|---|
| 259 | gfx_context_t *gc = NULL;
|
|---|
| 260 | test_gc_t tgc;
|
|---|
| 261 | gfx_coord2_t center;
|
|---|
| 262 |
|
|---|
| 263 | memset(&tgc, 0, sizeof(tgc));
|
|---|
| 264 | rc = gfx_context_new(&ops, &tgc, &gc);
|
|---|
| 265 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 266 |
|
|---|
| 267 | center.x = 0;
|
|---|
| 268 | center.y = 0;
|
|---|
| 269 |
|
|---|
| 270 | rc = ui_paint_up_triangle(gc, ¢er, 5);
|
|---|
| 271 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 272 |
|
|---|
| 273 | rc = gfx_context_delete(gc);
|
|---|
| 274 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | /** Paint down pointing triangle */
|
|---|
| 278 | PCUT_TEST(down_triangle)
|
|---|
| 279 | {
|
|---|
| 280 | errno_t rc;
|
|---|
| 281 | gfx_context_t *gc = NULL;
|
|---|
| 282 | test_gc_t tgc;
|
|---|
| 283 | gfx_coord2_t center;
|
|---|
| 284 |
|
|---|
| 285 | memset(&tgc, 0, sizeof(tgc));
|
|---|
| 286 | rc = gfx_context_new(&ops, &tgc, &gc);
|
|---|
| 287 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 288 |
|
|---|
| 289 | center.x = 0;
|
|---|
| 290 | center.y = 0;
|
|---|
| 291 |
|
|---|
| 292 | rc = ui_paint_down_triangle(gc, ¢er, 5);
|
|---|
| 293 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 294 |
|
|---|
| 295 | rc = gfx_context_delete(gc);
|
|---|
| 296 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 297 | }
|
|---|
| 298 |
|
|---|
| 299 | /** Paint left pointing triangle */
|
|---|
| 300 | PCUT_TEST(left_triangle)
|
|---|
| 301 | {
|
|---|
| 302 | errno_t rc;
|
|---|
| 303 | gfx_context_t *gc = NULL;
|
|---|
| 304 | test_gc_t tgc;
|
|---|
| 305 | gfx_coord2_t center;
|
|---|
| 306 |
|
|---|
| 307 | memset(&tgc, 0, sizeof(tgc));
|
|---|
| 308 | rc = gfx_context_new(&ops, &tgc, &gc);
|
|---|
| 309 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 310 |
|
|---|
| 311 | center.x = 0;
|
|---|
| 312 | center.y = 0;
|
|---|
| 313 |
|
|---|
| 314 | rc = ui_paint_left_triangle(gc, ¢er, 5);
|
|---|
| 315 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 316 |
|
|---|
| 317 | rc = gfx_context_delete(gc);
|
|---|
| 318 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 319 | }
|
|---|
| 320 |
|
|---|
| 321 | /** Paint right pointing triangle */
|
|---|
| 322 | PCUT_TEST(right_triangle)
|
|---|
| 323 | {
|
|---|
| 324 | errno_t rc;
|
|---|
| 325 | gfx_context_t *gc = NULL;
|
|---|
| 326 | test_gc_t tgc;
|
|---|
| 327 | gfx_coord2_t center;
|
|---|
| 328 |
|
|---|
| 329 | memset(&tgc, 0, sizeof(tgc));
|
|---|
| 330 | rc = gfx_context_new(&ops, &tgc, &gc);
|
|---|
| 331 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 332 |
|
|---|
| 333 | center.x = 0;
|
|---|
| 334 | center.y = 0;
|
|---|
| 335 |
|
|---|
| 336 | rc = ui_paint_right_triangle(gc, ¢er, 5);
|
|---|
| 337 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 338 |
|
|---|
| 339 | rc = gfx_context_delete(gc);
|
|---|
| 340 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 341 | }
|
|---|
| 342 |
|
|---|
| 343 | /** Paint diagonal cross (X) */
|
|---|
| 344 | PCUT_TEST(cross)
|
|---|
| 345 | {
|
|---|
| 346 | errno_t rc;
|
|---|
| 347 | gfx_context_t *gc = NULL;
|
|---|
| 348 | test_gc_t tgc;
|
|---|
| 349 | gfx_coord2_t center;
|
|---|
| 350 |
|
|---|
| 351 | memset(&tgc, 0, sizeof(tgc));
|
|---|
| 352 | rc = gfx_context_new(&ops, &tgc, &gc);
|
|---|
| 353 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 354 |
|
|---|
| 355 | center.x = 0;
|
|---|
| 356 | center.y = 0;
|
|---|
| 357 |
|
|---|
| 358 | rc = ui_paint_cross(gc, ¢er, 5, 1, 2);
|
|---|
| 359 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 360 |
|
|---|
| 361 | rc = gfx_context_delete(gc);
|
|---|
| 362 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 363 | }
|
|---|
| 364 |
|
|---|
| 365 | /** Paint mimimize icon */
|
|---|
| 366 | PCUT_TEST(minicon)
|
|---|
| 367 | {
|
|---|
| 368 | errno_t rc;
|
|---|
| 369 | gfx_context_t *gc = NULL;
|
|---|
| 370 | ui_resource_t *resource = NULL;
|
|---|
| 371 | test_gc_t tgc;
|
|---|
| 372 | gfx_coord2_t center;
|
|---|
| 373 |
|
|---|
| 374 | memset(&tgc, 0, sizeof(tgc));
|
|---|
| 375 | rc = gfx_context_new(&ops, &tgc, &gc);
|
|---|
| 376 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 377 |
|
|---|
| 378 | rc = ui_resource_create(gc, false, &resource);
|
|---|
| 379 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 380 | PCUT_ASSERT_NOT_NULL(resource);
|
|---|
| 381 |
|
|---|
| 382 | center.x = 0;
|
|---|
| 383 | center.y = 0;
|
|---|
| 384 |
|
|---|
| 385 | rc = ui_paint_minicon(resource, ¢er, 8, 6);
|
|---|
| 386 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 387 |
|
|---|
| 388 | ui_resource_destroy(resource);
|
|---|
| 389 | rc = gfx_context_delete(gc);
|
|---|
| 390 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 391 | }
|
|---|
| 392 |
|
|---|
| 393 | /** Paint maximize icon */
|
|---|
| 394 | PCUT_TEST(maxicon)
|
|---|
| 395 | {
|
|---|
| 396 | errno_t rc;
|
|---|
| 397 | gfx_context_t *gc = NULL;
|
|---|
| 398 | ui_resource_t *resource = NULL;
|
|---|
| 399 | test_gc_t tgc;
|
|---|
| 400 | gfx_coord2_t center;
|
|---|
| 401 |
|
|---|
| 402 | memset(&tgc, 0, sizeof(tgc));
|
|---|
| 403 | rc = gfx_context_new(&ops, &tgc, &gc);
|
|---|
| 404 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 405 |
|
|---|
| 406 | rc = ui_resource_create(gc, false, &resource);
|
|---|
| 407 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 408 | PCUT_ASSERT_NOT_NULL(resource);
|
|---|
| 409 |
|
|---|
| 410 | center.x = 0;
|
|---|
| 411 | center.y = 0;
|
|---|
| 412 |
|
|---|
| 413 | rc = ui_paint_maxicon(resource, ¢er, 8, 6);
|
|---|
| 414 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 415 |
|
|---|
| 416 | ui_resource_destroy(resource);
|
|---|
| 417 | rc = gfx_context_delete(gc);
|
|---|
| 418 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 419 | }
|
|---|
| 420 |
|
|---|
| 421 | /** Paint unmaximize icon */
|
|---|
| 422 | PCUT_TEST(unmaxicon)
|
|---|
| 423 | {
|
|---|
| 424 | errno_t rc;
|
|---|
| 425 | gfx_context_t *gc = NULL;
|
|---|
| 426 | ui_resource_t *resource = NULL;
|
|---|
| 427 | test_gc_t tgc;
|
|---|
| 428 | gfx_coord2_t center;
|
|---|
| 429 |
|
|---|
| 430 | memset(&tgc, 0, sizeof(tgc));
|
|---|
| 431 | rc = gfx_context_new(&ops, &tgc, &gc);
|
|---|
| 432 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 433 |
|
|---|
| 434 | rc = ui_resource_create(gc, false, &resource);
|
|---|
| 435 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 436 | PCUT_ASSERT_NOT_NULL(resource);
|
|---|
| 437 |
|
|---|
| 438 | center.x = 0;
|
|---|
| 439 | center.y = 0;
|
|---|
| 440 |
|
|---|
| 441 | rc = ui_paint_unmaxicon(resource, ¢er, 8, 8, 3, 3);
|
|---|
| 442 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 443 |
|
|---|
| 444 | ui_resource_destroy(resource);
|
|---|
| 445 | rc = gfx_context_delete(gc);
|
|---|
| 446 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 447 | }
|
|---|
| 448 |
|
|---|
| 449 | /** Paint text box */
|
|---|
| 450 | PCUT_TEST(text_box)
|
|---|
| 451 | {
|
|---|
| 452 | errno_t rc;
|
|---|
| 453 | gfx_context_t *gc = NULL;
|
|---|
| 454 | ui_resource_t *resource = NULL;
|
|---|
| 455 | gfx_color_t *color = NULL;
|
|---|
| 456 | test_gc_t tgc;
|
|---|
| 457 | gfx_rect_t rect;
|
|---|
| 458 |
|
|---|
| 459 | memset(&tgc, 0, sizeof(tgc));
|
|---|
| 460 | rc = gfx_context_new(&ops, &tgc, &gc);
|
|---|
| 461 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 462 |
|
|---|
| 463 | rc = ui_resource_create(gc, false, &resource);
|
|---|
| 464 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 465 | PCUT_ASSERT_NOT_NULL(resource);
|
|---|
| 466 |
|
|---|
| 467 | rc = gfx_color_new_rgb_i16(1, 2, 3, &color);
|
|---|
| 468 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 469 |
|
|---|
| 470 | rect.p0.x = 10;
|
|---|
| 471 | rect.p0.y = 20;
|
|---|
| 472 | rect.p1.x = 30;
|
|---|
| 473 | rect.p1.y = 40;
|
|---|
| 474 |
|
|---|
| 475 | /* Paint text box */
|
|---|
| 476 | rc = ui_paint_text_box(resource, &rect, ui_box_single, color);
|
|---|
| 477 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 478 |
|
|---|
| 479 | gfx_color_delete(color);
|
|---|
| 480 | ui_resource_destroy(resource);
|
|---|
| 481 | rc = gfx_context_delete(gc);
|
|---|
| 482 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 483 | }
|
|---|
| 484 |
|
|---|
| 485 | /** Paint custom text box */
|
|---|
| 486 | PCUT_TEST(text_box_custom)
|
|---|
| 487 | {
|
|---|
| 488 | errno_t rc;
|
|---|
| 489 | gfx_context_t *gc = NULL;
|
|---|
| 490 | ui_resource_t *resource = NULL;
|
|---|
| 491 | gfx_color_t *color = NULL;
|
|---|
| 492 | test_gc_t tgc;
|
|---|
| 493 | gfx_rect_t rect;
|
|---|
| 494 |
|
|---|
| 495 | memset(&tgc, 0, sizeof(tgc));
|
|---|
| 496 | rc = gfx_context_new(&ops, &tgc, &gc);
|
|---|
| 497 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 498 |
|
|---|
| 499 | rc = ui_resource_create(gc, false, &resource);
|
|---|
| 500 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 501 | PCUT_ASSERT_NOT_NULL(resource);
|
|---|
| 502 |
|
|---|
| 503 | rc = gfx_color_new_rgb_i16(1, 2, 3, &color);
|
|---|
| 504 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 505 |
|
|---|
| 506 | rect.p0.x = 10;
|
|---|
| 507 | rect.p0.y = 20;
|
|---|
| 508 | rect.p1.x = 30;
|
|---|
| 509 | rect.p1.y = 40;
|
|---|
| 510 |
|
|---|
| 511 | /* Paint text box */
|
|---|
| 512 | rc = ui_paint_text_box_custom(resource, &rect, &test_box_chars, color);
|
|---|
| 513 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 514 |
|
|---|
| 515 | gfx_color_delete(color);
|
|---|
| 516 | ui_resource_destroy(resource);
|
|---|
| 517 | rc = gfx_context_delete(gc);
|
|---|
| 518 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 519 | }
|
|---|
| 520 |
|
|---|
| 521 | /** Paint text horizontal brace */
|
|---|
| 522 | PCUT_TEST(text_hbrace)
|
|---|
| 523 | {
|
|---|
| 524 | errno_t rc;
|
|---|
| 525 | gfx_context_t *gc = NULL;
|
|---|
| 526 | ui_resource_t *resource = NULL;
|
|---|
| 527 | gfx_color_t *color = NULL;
|
|---|
| 528 | test_gc_t tgc;
|
|---|
| 529 | gfx_rect_t rect;
|
|---|
| 530 |
|
|---|
| 531 | memset(&tgc, 0, sizeof(tgc));
|
|---|
| 532 | rc = gfx_context_new(&ops, &tgc, &gc);
|
|---|
| 533 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 534 |
|
|---|
| 535 | rc = ui_resource_create(gc, false, &resource);
|
|---|
| 536 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 537 | PCUT_ASSERT_NOT_NULL(resource);
|
|---|
| 538 |
|
|---|
| 539 | rc = gfx_color_new_rgb_i16(1, 2, 3, &color);
|
|---|
| 540 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 541 |
|
|---|
| 542 | rect.p0.x = 10;
|
|---|
| 543 | rect.p0.y = 20;
|
|---|
| 544 | rect.p1.x = 30;
|
|---|
| 545 | rect.p1.y = 40;
|
|---|
| 546 |
|
|---|
| 547 | /* Paint text horizontal brace */
|
|---|
| 548 | rc = ui_paint_text_hbrace(resource, &rect, ui_box_single,
|
|---|
| 549 | color);
|
|---|
| 550 |
|
|---|
| 551 | gfx_color_delete(color);
|
|---|
| 552 | ui_resource_destroy(resource);
|
|---|
| 553 | rc = gfx_context_delete(gc);
|
|---|
| 554 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 555 | }
|
|---|
| 556 |
|
|---|
| 557 | /** Paint text rectangle */
|
|---|
| 558 | PCUT_TEST(text_rect)
|
|---|
| 559 | {
|
|---|
| 560 | errno_t rc;
|
|---|
| 561 | gfx_context_t *gc = NULL;
|
|---|
| 562 | ui_resource_t *resource = NULL;
|
|---|
| 563 | gfx_color_t *color = NULL;
|
|---|
| 564 | test_gc_t tgc;
|
|---|
| 565 | gfx_rect_t rect;
|
|---|
| 566 |
|
|---|
| 567 | memset(&tgc, 0, sizeof(tgc));
|
|---|
| 568 | rc = gfx_context_new(&ops, &tgc, &gc);
|
|---|
| 569 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 570 |
|
|---|
| 571 | rc = ui_resource_create(gc, false, &resource);
|
|---|
| 572 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 573 | PCUT_ASSERT_NOT_NULL(resource);
|
|---|
| 574 |
|
|---|
| 575 | rc = gfx_color_new_rgb_i16(1, 2, 3, &color);
|
|---|
| 576 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 577 |
|
|---|
| 578 | rect.p0.x = 10;
|
|---|
| 579 | rect.p0.y = 20;
|
|---|
| 580 | rect.p1.x = 30;
|
|---|
| 581 | rect.p1.y = 40;
|
|---|
| 582 |
|
|---|
| 583 | /* Paint text box */
|
|---|
| 584 | rc = ui_paint_text_rect(resource, &rect, color, "A");
|
|---|
| 585 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 586 |
|
|---|
| 587 | gfx_color_delete(color);
|
|---|
| 588 | ui_resource_destroy(resource);
|
|---|
| 589 | rc = gfx_context_delete(gc);
|
|---|
| 590 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 591 | }
|
|---|
| 592 |
|
|---|
| 593 | static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
|
|---|
| 594 | {
|
|---|
| 595 | (void) arg;
|
|---|
| 596 | (void) rect;
|
|---|
| 597 | return EOK;
|
|---|
| 598 | }
|
|---|
| 599 |
|
|---|
| 600 | static errno_t testgc_set_color(void *arg, gfx_color_t *color)
|
|---|
| 601 | {
|
|---|
| 602 | (void) arg;
|
|---|
| 603 | (void) color;
|
|---|
| 604 | return EOK;
|
|---|
| 605 | }
|
|---|
| 606 |
|
|---|
| 607 | static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
|
|---|
| 608 | {
|
|---|
| 609 | (void) arg;
|
|---|
| 610 | (void) rect;
|
|---|
| 611 | return EOK;
|
|---|
| 612 | }
|
|---|
| 613 |
|
|---|
| 614 | static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
|
|---|
| 615 | gfx_bitmap_alloc_t *alloc, void **rbm)
|
|---|
| 616 | {
|
|---|
| 617 | test_gc_t *tgc = (test_gc_t *) arg;
|
|---|
| 618 | testgc_bitmap_t *tbm;
|
|---|
| 619 |
|
|---|
| 620 | tbm = calloc(1, sizeof(testgc_bitmap_t));
|
|---|
| 621 | if (tbm == NULL)
|
|---|
| 622 | return ENOMEM;
|
|---|
| 623 |
|
|---|
| 624 | if (alloc == NULL) {
|
|---|
| 625 | tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
|
|---|
| 626 | sizeof(uint32_t);
|
|---|
| 627 | tbm->alloc.off0 = 0;
|
|---|
| 628 | tbm->alloc.pixels = calloc(sizeof(uint32_t),
|
|---|
| 629 | (params->rect.p1.x - params->rect.p0.x) *
|
|---|
| 630 | (params->rect.p1.y - params->rect.p0.y));
|
|---|
| 631 | tbm->myalloc = true;
|
|---|
| 632 | if (tbm->alloc.pixels == NULL) {
|
|---|
| 633 | free(tbm);
|
|---|
| 634 | return ENOMEM;
|
|---|
| 635 | }
|
|---|
| 636 | } else {
|
|---|
| 637 | tbm->alloc = *alloc;
|
|---|
| 638 | }
|
|---|
| 639 |
|
|---|
| 640 | tbm->tgc = tgc;
|
|---|
| 641 | tgc->bm_created = true;
|
|---|
| 642 | tgc->bm_params = *params;
|
|---|
| 643 | tgc->bm_pixels = tbm->alloc.pixels;
|
|---|
| 644 | *rbm = (void *)tbm;
|
|---|
| 645 | return EOK;
|
|---|
| 646 | }
|
|---|
| 647 |
|
|---|
| 648 | static errno_t testgc_bitmap_destroy(void *bm)
|
|---|
| 649 | {
|
|---|
| 650 | testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
|
|---|
| 651 | if (tbm->myalloc)
|
|---|
| 652 | free(tbm->alloc.pixels);
|
|---|
| 653 | tbm->tgc->bm_destroyed = true;
|
|---|
| 654 | free(tbm);
|
|---|
| 655 | return EOK;
|
|---|
| 656 | }
|
|---|
| 657 |
|
|---|
| 658 | static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
|
|---|
| 659 | gfx_coord2_t *offs)
|
|---|
| 660 | {
|
|---|
| 661 | testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
|
|---|
| 662 | tbm->tgc->bm_rendered = true;
|
|---|
| 663 | tbm->tgc->bm_srect = *srect;
|
|---|
| 664 | tbm->tgc->bm_offs = *offs;
|
|---|
| 665 | return EOK;
|
|---|
| 666 | }
|
|---|
| 667 |
|
|---|
| 668 | static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
|
|---|
| 669 | {
|
|---|
| 670 | testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
|
|---|
| 671 | *alloc = tbm->alloc;
|
|---|
| 672 | tbm->tgc->bm_got_alloc = true;
|
|---|
| 673 | return EOK;
|
|---|
| 674 | }
|
|---|
| 675 |
|
|---|
| 676 | PCUT_EXPORT(paint);
|
|---|