-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextInputEvent.c
97 lines (80 loc) · 2.82 KB
/
TextInputEvent.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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
//
// Created by Gabriel Mitterrutzner on 30.04.17.
//
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//#include <SDL2/SDL.h>
#include <stdbool.h>
//
#include <SDL2/SDL.h>
#include <stdio.h>
#include <stdbool.h>
#include <sys/param.h>
int main(int argc, char *argv[])
{
int status = 0;
SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "0");
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError());
status = 1;
SDL_Quit();
return status;
}
SDL_Window *window = SDL_CreateWindow("SDL Test",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
400,
400,
(SDL_WINDOW_SHOWN |
SDL_WINDOW_ALLOW_HIGHDPI));
if (!window) {
fprintf(stderr, "SDL_CreateWindow failed: %s\n", SDL_GetError());
status = 1;
}
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1,
SDL_RENDERER_ACCELERATED);
if (!renderer) {
fprintf(stderr, "SDL_CreateRenderer failed: %s\n", SDL_GetError());
status = 1;
SDL_Quit();
return status;
}
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
SDL_RenderSetLogicalSize(renderer, 400, 400);
bool done = false;
do {
SDL_Event e;
if (SDL_PollEvent(&e)) {
switch (e.type) {
case SDL_KEYDOWN:
if (e.key.keysym.sym == 'f') {
uint32_t flags = SDL_GetWindowFlags(window);
flags ^= SDL_WINDOW_FULLSCREEN_DESKTOP;
if (!SDL_SetWindowFullscreen(window, flags)) {
//fprintf(stderr, "Toggle window mode failed: %s\n", SDL_GetError());
}
} else if (e.key.keysym.sym == 'm') {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION,
"This is a message box",
"Forfee I got off the freeway!",
window);
} else if (e.key.keysym.sym == 'q') {
done = true;
}
break;
case SDL_QUIT:
done = true;
break;
case SDL_TEXTINPUT:
break;
}
}
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
} while (!done);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return status;
}