Changeset 47728678 in mainline for uspace/app/uidemo/uidemo.c
- Timestamp:
- 2020-10-13T09:24:56Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f6df5a3
- Parents:
- f80690a
- git-author:
- Jiri Svoboda <jiri@…> (2020-10-12 21:24:39)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-10-13 09:24:56)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
rf80690a r47728678 36 36 #include <stdio.h> 37 37 #include <str.h> 38 #include <task.h> 38 39 #include <ui/pbutton.h> 40 #include <ui/resource.h> 41 42 static void wnd_close_event(void *); 43 static void wnd_kbd_event(void *, kbd_event_t *); 44 45 static display_wnd_cb_t wnd_cb = { 46 .close_event = wnd_close_event, 47 .kbd_event = wnd_kbd_event 48 }; 49 50 static bool quit = false; 39 51 40 52 static void print_syntax(void) … … 43 55 } 44 56 57 static void wnd_close_event(void *arg) 58 { 59 printf("Close event\n"); 60 quit = true; 61 } 62 63 static void wnd_kbd_event(void *arg, kbd_event_t *event) 64 { 65 printf("Keyboard event type=%d key=%d\n", event->type, event->key); 66 if (event->type == KEY_PRESS) 67 quit = true; 68 } 69 70 /** Run UI demo on display server. */ 71 static errno_t ui_demo_display(const char *display_svc) 72 { 73 display_t *display = NULL; 74 gfx_context_t *gc; 75 display_wnd_params_t params; 76 display_window_t *window = NULL; 77 ui_resource_t *ui_res; 78 ui_pbutton_t *pb1; 79 ui_pbutton_t *pb2; 80 gfx_rect_t rect; 81 errno_t rc; 82 83 printf("Init display..\n"); 84 85 rc = display_open(display_svc, &display); 86 if (rc != EOK) { 87 printf("Error opening display.\n"); 88 return rc; 89 } 90 91 display_wnd_params_init(¶ms); 92 params.rect.p0.x = 0; 93 params.rect.p0.y = 0; 94 params.rect.p1.x = 220; 95 params.rect.p1.y = 100; 96 97 rc = display_window_create(display, ¶ms, &wnd_cb, NULL, &window); 98 if (rc != EOK) { 99 printf("Error creating window.\n"); 100 return rc; 101 } 102 103 rc = display_window_get_gc(window, &gc); 104 if (rc != EOK) { 105 printf("Error getting graphics context.\n"); 106 return rc; 107 } 108 109 task_retval(0); 110 111 rc = ui_resource_create(gc, &ui_res); 112 if (rc != EOK) { 113 printf("Error creating UI.\n"); 114 return 1; 115 } 116 117 rc = ui_pbutton_create(ui_res, "Confirm", &pb1); 118 if (rc != EOK) { 119 printf("Error creating button.\n"); 120 return 1; 121 } 122 123 rect.p0.x = 20; 124 rect.p0.y = 50; 125 rect.p1.x = 100; 126 rect.p1.y = 80; 127 ui_pbutton_set_rect(pb1, &rect); 128 129 rc = ui_pbutton_create(ui_res, "Cancel", &pb2); 130 if (rc != EOK) { 131 printf("Error creating button.\n"); 132 return 1; 133 } 134 135 rect.p0.x = 120; 136 rect.p0.y = 50; 137 rect.p1.x = 200; 138 rect.p1.y = 80; 139 ui_pbutton_set_rect(pb2, &rect); 140 141 rc = ui_pbutton_paint(pb1); 142 if (rc != EOK) { 143 printf("Error painting button.\n"); 144 return 1; 145 } 146 147 rc = ui_pbutton_paint(pb2); 148 if (rc != EOK) { 149 printf("Error painting button.\n"); 150 return 1; 151 } 152 153 while (!quit) { 154 fibril_usleep(100 * 1000); 155 } 156 157 ui_pbutton_destroy(pb1); 158 ui_pbutton_destroy(pb2); 159 160 rc = gfx_context_delete(gc); 161 if (rc != EOK) 162 return rc; 163 164 display_window_destroy(window); 165 display_close(display); 166 167 return EOK; 168 } 169 45 170 int main(int argc, char *argv[]) 46 171 { 47 172 const char *display_svc = DISPLAY_DEFAULT; 48 ui_pbutton_t *pbutton;49 173 errno_t rc; 50 174 int i; … … 73 197 } 74 198 75 printf("Display service: %s\n", display_svc); 76 77 rc = ui_pbutton_create("Hello", &pbutton); 78 if (rc != EOK) { 79 printf("Error creating button.\n"); 80 return 1; 81 } 82 83 ui_pbutton_destroy(pbutton); 199 rc = ui_demo_display(display_svc); 200 if (rc != EOK) 201 return 1; 202 84 203 return 0; 85 204 }
Note:
See TracChangeset
for help on using the changeset viewer.