Changeset b93ec7c0 in mainline
- Timestamp:
- 2020-11-11T18:26:11Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7a5825b
- Parents:
- 66a2becf
- Location:
- uspace/app/gfxdemo
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/gfxdemo/gfxdemo.c
r66a2becf rb93ec7c0 33 33 */ 34 34 35 #include <canvas.h>36 35 #include <congfx/console.h> 37 #include <draw/surface.h>38 36 #include <display.h> 39 37 #include <fibril.h> 40 #include <guigfx/canvas.h>41 38 #include <gfx/bitmap.h> 42 39 #include <gfx/color.h> … … 51 48 #include <str.h> 52 49 #include <task.h> 53 #include <window.h> 50 #include <ui/ui.h> 51 #include <ui/window.h> 52 #include <ui/wdecor.h> 54 53 55 54 static void wnd_close_event(void *); … … 59 58 .close_event = wnd_close_event, 60 59 .kbd_event = wnd_kbd_event 60 }; 61 62 static void uiwnd_close_event(ui_window_t *, void *); 63 static void uiwnd_kbd_event(ui_window_t *, void *, kbd_event_t *); 64 65 static ui_window_cb_t ui_window_cb = { 66 .close = uiwnd_close_event, 67 .kbd = uiwnd_kbd_event 61 68 }; 62 69 … … 696 703 } 697 704 698 /** Run demo on canvas. */ 699 static errno_t demo_canvas(const char *display_svc) 700 { 701 canvas_gc_t *cgc = NULL; 705 /** Run demo on UI. */ 706 static errno_t demo_ui(const char *display_spec) 707 { 708 ui_t *ui = NULL; 709 ui_wnd_params_t params; 710 ui_window_t *window = NULL; 702 711 gfx_context_t *gc; 703 window_t *window = NULL; 704 pixel_t *pixbuf = NULL; 705 surface_t *surface = NULL; 706 canvas_t *canvas = NULL; 707 gfx_coord_t vw, vh; 708 errno_t rc; 709 710 printf("Init canvas..\n"); 711 712 window = window_open(display_svc, NULL, 713 WINDOW_MAIN | WINDOW_DECORATED, "GFX Demo"); 714 if (window == NULL) { 712 gfx_rect_t rect; 713 gfx_rect_t wrect; 714 gfx_coord2_t off; 715 errno_t rc; 716 717 printf("Init UI..\n"); 718 719 rc = ui_create(display_spec, &ui); 720 if (rc != EOK) { 721 printf("Error initializing UI (%s)\n", display_spec); 722 goto error; 723 } 724 725 rect.p0.x = 0; 726 rect.p0.y = 0; 727 rect.p1.x = 400; 728 rect.p1.y = 300; 729 730 ui_wnd_params_init(¶ms); 731 params.caption = "GFX Demo"; 732 733 /* 734 * Compute window rectangle such that application area corresponds 735 * to rect 736 */ 737 ui_wdecor_rect_from_app(&rect, &wrect); 738 off = wrect.p0; 739 gfx_rect_rtranslate(&off, &wrect, ¶ms.rect); 740 741 rc = ui_window_create(ui, ¶ms, &window); 742 if (rc != EOK) { 715 743 printf("Error creating window.\n"); 716 return -1; 717 } 718 719 vw = 400; 720 vh = 300; 721 722 pixbuf = calloc(vw * vh, sizeof(pixel_t)); 723 if (pixbuf == NULL) { 724 printf("Error allocating memory for pixel buffer.\n"); 725 return ENOMEM; 726 } 727 728 surface = surface_create(vw, vh, pixbuf, 0); 729 if (surface == NULL) { 730 printf("Error creating surface.\n"); 731 return EIO; 732 } 733 734 canvas = create_canvas(window_root(window), NULL, vw, vh, 735 surface); 736 if (canvas == NULL) { 737 printf("Error creating canvas.\n"); 738 return EIO; 739 } 740 741 window_resize(window, 0, 0, vw + 10, vh + 30, WINDOW_PLACEMENT_ANY); 742 window_exec(window); 743 744 printf("Create canvas GC\n"); 745 rc = canvas_gc_create(canvas, surface, &cgc); 746 if (rc != EOK) 747 return rc; 748 749 gc = canvas_gc_get_ctx(cgc); 744 goto error; 745 } 746 747 ui_window_set_cb(window, &ui_window_cb, NULL); 748 749 rc = ui_window_get_app_gc(window, &gc); 750 if (rc != EOK) { 751 printf("Error creating graphic context.\n"); 752 goto error; 753 } 750 754 751 755 task_retval(0); 752 756 753 rc = demo_loop(gc, 400, 300); 754 if (rc != EOK) 755 return rc; 756 757 rc = canvas_gc_delete(cgc); 758 if (rc != EOK) 759 return rc; 760 761 return EOK; 757 rc = demo_loop(gc, rect.p1.x, rect.p1.y); 758 if (rc != EOK) 759 goto error; 760 761 ui_window_destroy(window); 762 ui_destroy(ui); 763 764 return EOK; 765 error: 766 if (window != NULL) 767 ui_window_destroy(window); 768 if (ui != NULL) 769 ui_destroy(ui); 770 return rc; 762 771 } 763 772 … … 820 829 821 830 static void wnd_kbd_event(void *arg, kbd_event_t *event) 831 { 832 printf("Keyboard event type=%d key=%d\n", event->type, event->key); 833 if (event->type == KEY_PRESS) 834 quit = true; 835 } 836 837 static void uiwnd_close_event(ui_window_t *window, void *arg) 838 { 839 printf("Close event\n"); 840 quit = true; 841 } 842 843 static void uiwnd_kbd_event(ui_window_t *window, void *arg, kbd_event_t *event) 822 844 { 823 845 printf("Keyboard event type=%d key=%d\n", event->type, event->key); … … 863 885 if (rc != EOK) 864 886 return 1; 865 } else if (str_cmp(argv[i], " canvas") == 0) {866 rc = demo_ canvas(display_svc);887 } else if (str_cmp(argv[i], "ui") == 0) { 888 rc = demo_ui(display_svc); 867 889 if (rc != EOK) 868 890 return 1; -
uspace/app/gfxdemo/meson.build
r66a2becf rb93ec7c0 27 27 # 28 28 29 deps = [ 'gfx', 'gfxfont', ' guigfx', 'congfx', 'ipcgfx', 'display' ]29 deps = [ 'gfx', 'gfxfont', 'ui', 'congfx', 'ipcgfx', 'display' ] 30 30 src = files( 31 31 'gfxdemo.c',
Note:
See TracChangeset
for help on using the changeset viewer.