Changeset 8dbd13d in mainline
- Timestamp:
- 2021-05-10T18:36:49Z (4 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- da15002
- Parents:
- ae634f4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/gfxdemo/gfxdemo.c
rae634f4 r8dbd13d 69 69 70 70 static bool quit = false; 71 static gfx_typeface_t *tface; 72 static gfx_font_t *font; 73 static gfx_coord_t vpad; 71 74 72 75 /** Clear screen. … … 107 110 } 108 111 109 /** Run rectangle demo on a graphic context.112 /** Initialize demo font. 110 113 * 111 114 * @param gc Graphic context 112 115 * @param w Width 113 116 * @param h Height 117 * @return EOK on success or an error code 118 */ 119 static errno_t demo_font_init(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h) 120 { 121 gfx_font_info_t *finfo; 122 errno_t rc; 123 124 if (quit) 125 return EOK; 126 127 /* XXX Crude way of detecting text mode */ 128 if (w < 256) { 129 /* Create dummy font for text mode */ 130 rc = gfx_typeface_create(gc, &tface); 131 if (rc != EOK) { 132 printf("Error creating typeface\n"); 133 goto error; 134 } 135 136 rc = gfx_font_create_textmode(tface, &font); 137 if (rc != EOK) { 138 printf("Error creating font\n"); 139 goto error; 140 } 141 142 vpad = 0; 143 } else { 144 /* Load font */ 145 rc = gfx_typeface_open(gc, "/data/font/helena.tpf", &tface); 146 if (rc != EOK) { 147 printf("Error opening typeface\n"); 148 goto error; 149 } 150 151 finfo = gfx_typeface_first_font(tface); 152 if (finfo == NULL) { 153 printf("Typeface contains no font.\n"); 154 rc = ENOENT; 155 goto error; 156 } 157 158 rc = gfx_font_open(finfo, &font); 159 if (rc != EOK) { 160 printf("Error opening font.\n"); 161 goto error; 162 } 163 164 vpad = 5; 165 } 166 167 return EOK; 168 error: 169 if (tface != NULL) 170 gfx_typeface_destroy(tface); 171 return rc; 172 } 173 174 /** Finalize demo font. */ 175 static void demo_font_fini(void) 176 { 177 if (font == NULL) 178 return; 179 180 gfx_font_close(font); 181 font = NULL; 182 183 gfx_typeface_destroy(tface); 184 tface = NULL; 185 } 186 187 /** Start a new demo screen. 188 * 189 * Clear the screen, display a status line and set up clipping. 190 * 191 * @param gc Graphic context 192 * @param w Width 193 * @param h Height 194 * @param text Demo screen description 195 * @return EOK on success or an error code 196 */ 197 static errno_t demo_begin(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h, 198 const char *text) 199 { 200 gfx_text_fmt_t fmt; 201 gfx_font_metrics_t metrics; 202 gfx_coord2_t pos; 203 gfx_color_t *color; 204 gfx_rect_t rect; 205 gfx_coord_t height; 206 errno_t rc; 207 208 rc = gfx_set_clip_rect(gc, NULL); 209 if (rc != EOK) 210 return rc; 211 212 rc = clear_scr(gc, w, h); 213 if (rc != EOK) 214 return rc; 215 216 if (font != NULL) { 217 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color); 218 if (rc != EOK) 219 goto error; 220 221 gfx_text_fmt_init(&fmt); 222 fmt.color = color; 223 fmt.halign = gfx_halign_center; 224 fmt.valign = gfx_valign_bottom; 225 226 pos.x = w / 2; 227 pos.y = h - 1; 228 rc = gfx_puttext(font, &pos, &fmt, text); 229 if (rc != EOK) { 230 printf("Error rendering text.\n"); 231 gfx_color_delete(color); 232 goto error; 233 } 234 235 gfx_color_delete(color); 236 237 gfx_font_get_metrics(font, &metrics); 238 height = metrics.ascent + metrics.descent + 1; 239 } else { 240 height = 0; 241 } 242 243 rect.p0.x = 0; 244 rect.p0.y = 0; 245 rect.p1.x = w; 246 rect.p1.y = h - height - vpad; 247 rc = gfx_set_clip_rect(gc, &rect); 248 if (rc != EOK) 249 return rc; 250 251 return EOK; 252 error: 253 return rc; 254 } 255 256 /** Run rectangle demo on a graphic context. 257 * 258 * @param gc Graphic context 259 * @param w Width 260 * @param h Height 114 261 */ 115 262 static errno_t demo_rects(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h) … … 123 270 return EOK; 124 271 125 rc = clear_scr(gc, w, h);272 rc = demo_begin(gc, w, h, "Rectangle rendering"); 126 273 if (rc != EOK) 127 274 return rc; … … 282 429 return EOK; 283 430 284 rc = clear_scr(gc, w, h);431 rc = demo_begin(gc, w, h, "Bitmap rendering without offset"); 285 432 if (rc != EOK) 286 433 return rc; … … 345 492 return EOK; 346 493 347 rc = clear_scr(gc, w, h);494 rc = demo_begin(gc, w, h, "Bitmap rendering with offset"); 348 495 if (rc != EOK) 349 496 return rc; … … 404 551 return EOK; 405 552 406 rc = clear_scr(gc, w, h);553 rc = demo_begin(gc, w, h, "Bitmap rendering with color key"); 407 554 if (rc != EOK) 408 555 return rc; … … 505 652 } 506 653 507 rc = clear_scr(gc, w, h);654 rc = demo_begin(gc, w, h, "Text rendering"); 508 655 if (rc != EOK) 509 656 goto error; … … 542 689 543 690 rect.p0.x = w / 20; 544 rect.p0.y = 2* h / 15;691 rect.p0.y = 1 * h / 15; 545 692 rect.p1.x = w - w / 20; 546 rect.p1.y = 5* h / 15;693 rect.p1.y = 4 * h / 15; 547 694 548 695 rc = gfx_fill_rect(gc, &rect); … … 640 787 641 788 pos.x = w / 20; 642 pos.y = ( 7+ i) * h / 15;789 pos.y = (6 + i) * h / 15; 643 790 rc = gfx_puttext(font, &pos, &fmt, "The quick brown fox jumps over the lazy dog."); 644 791 if (rc != EOK) … … 684 831 return EOK; 685 832 686 rc = clear_scr(gc, w, h);833 rc = demo_begin(gc, w, h, "Clipping demonstration"); 687 834 if (rc != EOK) 688 835 return rc; … … 777 924 errno_t rc; 778 925 926 (void) demo_font_init(gc, w, h); 927 779 928 while (!quit) { 780 929 rc = demo_rects(gc, w, h); 781 930 if (rc != EOK) 782 return rc;931 goto error; 783 932 784 933 rc = demo_bitmap(gc, w, h); 785 934 if (rc != EOK) 786 return rc;935 goto error; 787 936 788 937 rc = demo_bitmap2(gc, w, h); 789 938 if (rc != EOK) 790 return rc;939 goto error; 791 940 792 941 rc = demo_bitmap_kc(gc, w, h); 793 942 if (rc != EOK) 794 return rc;943 goto error; 795 944 796 945 rc = demo_text(gc, w, h); 797 946 if (rc != EOK) 798 return rc;947 goto error; 799 948 800 949 rc = demo_clip(gc, w, h); 801 950 if (rc != EOK) 802 return rc; 803 } 804 805 return EOK; 951 goto error; 952 } 953 954 demo_font_fini(); 955 return EOK; 956 error: 957 demo_font_fini(); 958 return rc; 806 959 } 807 960
Note:
See TracChangeset
for help on using the changeset viewer.