Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | sdl2.c: Boiler plate for keyboard code. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | ams/sdl1 |
Files: | files | file ages | folders |
SHA3-256: |
7399fa5f2a386a598d665c1d5fa5a728 |
User & Date: | ams 2024-06-04 17:59:05 |
Context
2024-06-04
| ||
18:07 | Get keyboard processing going, sorta. check-in: 27e79faddf user: ams tags: ams/sdl1 | |
17:59 | sdl2.c: Boiler plate for keyboard code. check-in: 7399fa5f2a user: ams tags: ams/sdl1 | |
17:47 | sdl2.c: Fix color. check-in: 5de619b0f2 user: ams tags: ams/sdl1 | |
Changes
Changes to sdl2.c.
︙ | ︙ | |||
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | u_minv = 0x7fffffff; u_maxv = 0; } static void process_key(SDL_KeyboardEvent *e, int keydown) { } void sdl2_event(void) { SDL_Event ev1, *ev = &ev1; send_accumulated_updates(); kbd_dequeue_key_event(); while (SDL_PollEvent(ev)) { switch (ev->type) { case SDL_WINDOWEVENT: SDL_UpdateTexture(texture, NULL, tv_bitmap, tv_width * sizeof (Uint32)); // flush SDL_RenderClear(renderer); SDL_RenderCopy(renderer, texture, NULL, NULL); SDL_RenderPresent(renderer); break; case SDL_QUIT: exit(0); break; } } } | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | u_minv = 0x7fffffff; u_maxv = 0; } static void process_key(SDL_KeyboardEvent *e, int keydown) { // KeySym keysym; // SDLKey keycode; int bi; unsigned char buf[5]; idle_keyboard_activity(); // keycode = SDL_KeysymToKeycode(e->keysym.sym); //if (event->key.code == key) ... // XLookupString(&e->xkey, (char *)buf, sizeof(buf), &keysym, &status); // keycode = x11_keysym_to_keycode(keysym); // if (keycode == NoSymbol || keysym > NELEM(x11_kbd_map)) { // NOTICE(TRACE_USIM, "kbd (cadet): unable to translate to sdl2 keycode (keysym = 0%o)\n", keysym); // return; // } if (kbd_type == 0) { if (!keydown) return; bi = 0; // if (e->xkey.state & ShiftMask) // knight_process_bucky(x11_modifier_map[ShiftMapIndex], &bi); // if (e->xkey.state & LockMask) // knight_process_bucky(x11_modifier_map[LockMapIndex], &bi); // if (e->xkey.state & ControlMask) // knight_process_bucky(x11_modifier_map[ControlMapIndex], &bi); // if (e->xkey.state & Mod1Mask) // knight_process_bucky(x11_modifier_map[Mod1MapIndex], &bi); // if (e->xkey.state & Mod2Mask) // knight_process_bucky(x11_modifier_map[Mod2MapIndex], &bi); // if (e->xkey.state & Mod3Mask) // knight_process_bucky(x11_modifier_map[Mod3MapIndex], &bi); // if (e->xkey.state & Mod4Mask) // knight_process_bucky(x11_modifier_map[Mod4MapIndex], &bi); // if (e->xkey.state & Mod5Mask) // knight_process_bucky(x11_modifier_map[Mod5MapIndex], &bi); knight_process_key(e->keysym.sym, bi, keydown, sdl2_kbd_map, sdl2_modifier_map); } else { // bi = sdl2_bucky(e->keysym.sym); bi = -1; cadet_process_key(e->keysym.sym, bi, keydown, sdl2_kbd_map, sdl2_modifier_map); } } void sdl2_event(void) { SDL_Event ev1, *ev = &ev1; send_accumulated_updates(); kbd_dequeue_key_event(); while (SDL_PollEvent(ev)) { switch (ev->type) { case SDL_WINDOWEVENT: SDL_UpdateTexture(texture, NULL, tv_bitmap, tv_width * sizeof (Uint32)); // flush SDL_RenderClear(renderer); SDL_RenderCopy(renderer, texture, NULL, NULL); SDL_RenderPresent(renderer); break; case SDL_KEYDOWN: process_key(&ev->key, 1); break; case SDL_KEYUP: process_key(&ev->key, 0); break; case SDL_MOUSEMOTION: case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: //mouse_event(e.xbutton.x, e.xbutton.y, e.xbutton.button); break; case SDL_QUIT: exit(0); break; } } } |
︙ | ︙ | |||
109 110 111 112 113 114 115 | void sdl2_init(void) { NOTICE(TRACE_USIM, "tv: using SDL backend for monitor and keyboard\n"); Foreground = 0xffffff; // White Background = 0x000000; // Black | < < < < < < < | | | < | < < < < | 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | void sdl2_init(void) { NOTICE(TRACE_USIM, "tv: using SDL backend for monitor and keyboard\n"); Foreground = 0xffffff; // White Background = 0x000000; // Black SDL_CreateWindowAndRenderer(tv_width, tv_height, SDL_WINDOW_OPENGL, &window, &renderer); // SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); // SDL_RenderClear(renderer); // SDL_RenderPresent(renderer); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); // make the scaled rendering look smoother. SDL_RenderSetLogicalSize(renderer, tv_width, tv_height); texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, tv_width, tv_height); } |