-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwindow.c
99 lines (82 loc) · 2.81 KB
/
window.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
96
97
98
99
#include <SDL2/SDL.h>
#include "aoakvm.h"
#include "window.h"
#include <unistd.h>
int
window_initWindow( struct aoakvmMSGScreens *msgScreen,
struct aoakvmWindowProperties_t *props,
SDL_Window *window,
SDL_Renderer **renderer) {
window = SDL_CreateWindow(props->titel, props->x, props->y, props->width , props->height, props->flags);
if (window == NULL) {
log_error("Could not create window: %s", SDL_GetError());
return -1;
}
*renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (!*renderer) {
log_error("Could not create renderer: %s", SDL_GetError());
return -1;
log_debug("Renderer Created");
}
int dw;
int dh;
SDL_GL_GetDrawableSize(window, &dw, &dh);
SDL_Rect rect;
SDL_GetDisplayUsableBounds(0, &rect);
log_trace("Display Bounds: \t %d x %d", rect.w, rect.h);
log_debug("create renderer");
window_changeMsgscreenTo(msgScreen ,*renderer, window, WAIT_FOR_DEVICE);
mainwindow = window;
return 0;
}
int
window_setMsgscreens(struct aoakvmMSGScreens *msgScreen,
const char *waitDevice,
const char *aoaInit,
const char *dataTrans) {
if( access(waitDevice, F_OK) != 0 ) {
log_error("\"Wait for Device\"-Screen does not exist.");
return -1;
}
msgScreen->waitForDevice = SDL_LoadBMP(waitDevice);
if( access(aoaInit, F_OK) != 0 ) {
log_error("\"AOA Initialized\"-Screen does not exist.");
return -1;
}
msgScreen->aoaInitialized = SDL_LoadBMP(aoaInit);
if( access(dataTrans, F_OK) != 0 ) {
log_error("\"Wait for Data Transmission\"-Screen does not exist.");
return -1;
}
msgScreen->waitForDataTransmission = SDL_LoadBMP(dataTrans);
return 0;
}
int
window_changeMsgscreenTo(struct aoakvmMSGScreens *msgScreens,
SDL_Renderer *renderer,
SDL_Window *window,
enum aoakvm_msgscreen_states_enum img_num){
SDL_Surface *image = NULL;
switch (img_num) {
case WAIT_FOR_DEVICE:
image = msgScreens->waitForDevice;
break;
case AOA_INITIALIZED:
image = msgScreens->aoaInitialized;
break;
case WAIT_FOR_DATA_TRANSMISSION:
image = msgScreens->waitForDataTransmission;
break;
default:
log_error("window_changeMsgscreenTo called without proper argument %d", img_num);
return -1;
break;
}
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, image);
SDL_SetWindowSize(window, image->w / 2, image->h / 2);
SDL_SetWindowResizable(window, false);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_DestroyTexture(texture);
SDL_RenderPresent(renderer);
return 0;
}