Changeset bea947f in mainline for uspace/app/gfxdemo/gfxdemo.c
- Timestamp:
- 2020-05-24T17:59:02Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b3b00b6
- Parents:
- ef20a91
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/gfxdemo/gfxdemo.c
ref20a91 rbea947f 215 215 } 216 216 217 /** Render circle to a bitmap. 218 * 219 * @param bitmap Bitmap 220 * @param w Bitmap width 221 * @param h Bitmap height 222 * @return EOK on success or an error code 223 */ 224 static errno_t bitmap_circle(gfx_bitmap_t *bitmap, gfx_coord_t w, gfx_coord_t h) 225 { 226 int i, j; 227 int k; 228 pixelmap_t pixelmap; 229 gfx_bitmap_alloc_t alloc; 230 errno_t rc; 231 232 rc = gfx_bitmap_get_alloc(bitmap, &alloc); 233 if (rc != EOK) 234 return rc; 235 236 /* In absence of anything else, use pixelmap */ 237 pixelmap.width = w; 238 pixelmap.height = h; 239 pixelmap.data = alloc.pixels; 240 241 for (i = 0; i < w; i++) { 242 for (j = 0; j < h; j++) { 243 k = i * i + j * j; 244 pixelmap_put_pixel(&pixelmap, i, j, 245 k < w * w / 2 ? PIXEL(255, 0, 255, 0) : 246 PIXEL(0, 255, 0, 255)); 247 } 248 } 249 250 return EOK; 251 } 252 217 253 /** Run bitmap demo on a graphic context. 218 254 * … … 329 365 return rc; 330 366 } 331 332 /** Run demo loop on a graphic context. 367 /** Run bitmap color key demo on a graphic context. 333 368 * 334 369 * @param gc Graphic context … … 336 371 * @param h Height 337 372 */ 373 static errno_t demo_bitmap_kc(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h) 374 { 375 gfx_bitmap_t *bitmap; 376 gfx_bitmap_params_t params; 377 int i, j; 378 gfx_coord2_t offs; 379 errno_t rc; 380 381 rc = clear_scr(gc, w, h); 382 if (rc != EOK) 383 return rc; 384 385 params.rect.p0.x = 0; 386 params.rect.p0.y = 0; 387 params.rect.p1.x = 40; 388 params.rect.p1.y = 40; 389 params.flags = bmpf_color_key; 390 params.key_color = PIXEL(0, 255, 0, 255); 391 392 rc = gfx_bitmap_create(gc, ¶ms, NULL, &bitmap); 393 if (rc != EOK) 394 return rc; 395 396 rc = bitmap_circle(bitmap, 40, 40); 397 if (rc != EOK) 398 goto error; 399 400 for (j = 0; j < 10; j++) { 401 for (i = 0; i < 10; i++) { 402 offs.x = j * 20 + i * 20; 403 offs.y = i * 20; 404 405 rc = gfx_bitmap_render(bitmap, NULL, &offs); 406 if (rc != EOK) 407 goto error; 408 } 409 410 fibril_usleep(500 * 1000); 411 412 if (quit) 413 break; 414 } 415 416 gfx_bitmap_destroy(bitmap); 417 418 return EOK; 419 error: 420 gfx_bitmap_destroy(bitmap); 421 return rc; 422 } 423 424 /** Run demo loop on a graphic context. 425 * 426 * @param gc Graphic context 427 * @param w Width 428 * @param h Height 429 */ 338 430 static errno_t demo_loop(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h) 339 431 { … … 350 442 351 443 rc = demo_bitmap2(gc, w, h); 444 if (rc != EOK) 445 return rc; 446 447 rc = demo_bitmap_kc(gc, w, h); 352 448 if (rc != EOK) 353 449 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.