summaryrefslogtreecommitdiff
path: root/gui.c
diff options
context:
space:
mode:
Diffstat (limited to 'gui.c')
-rw-r--r--gui.c62
1 files changed, 34 insertions, 28 deletions
diff --git a/gui.c b/gui.c
index 1b3606e..12f8f47 100644
--- a/gui.c
+++ b/gui.c
@@ -45,6 +45,8 @@ struct GuiContext *init() {
ctx->pixels = malloc(sizeof(uint32_t) * 640 * 480);
memset(ctx->pixels, 255, 640 * 480 * sizeof(uint32_t));
+ SDL_Init(SDL_INIT_VIDEO);
+
return ctx;
}
@@ -60,50 +62,54 @@ void deinit(struct GuiContext *ctx) {
free(ctx);
}
-void gui_run(void) {
-
- struct GuiContext *ctx = init();
+bool create_window(struct GuiContext *ctx) {
- SDL_Init(SDL_INIT_VIDEO);
ctx->window = SDL_CreateWindow("LimoX",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480,
SDL_WINDOW_RESIZABLE
);
- fprintf(stderr, "SDL2 video driver: %s\n", SDL_GetCurrentVideoDriver());
-
ctx->renderer = SDL_CreateRenderer(ctx->window, -1, 0);
ctx->texture = SDL_CreateTexture(ctx->renderer, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STATIC, 640, 480);
- if (ctx->window == NULL) {
+ return ctx->window != NULL;
+}
+
+void gui_run(void) {
+
+ struct GuiContext *ctx = init();
+
+ fprintf(stderr, "SDL2 video driver: %s\n", SDL_GetCurrentVideoDriver());
+
+ if (!create_window(ctx)) {
fprintf(stderr, "Failed to create SDL2 window!\n");
return;
- } else {
- while (!ctx->quit) {
- SDL_UpdateTexture(ctx->texture, NULL, ctx->pixels, 640 * sizeof(uint32_t));
- SDL_WaitEvent(&ctx->event);
- switch (ctx->event.type) {
- case SDL_QUIT:
- ctx->quit = true;
- break;
- case SDL_MOUSEBUTTONDOWN:
- if (ctx->xmpp_fd == -1) {
- ctx->xmpp_fd = xmpp_connect();
- } else {
- close(ctx->xmpp_fd);
- ctx->xmpp_fd = -1;
- printf("Closed XMPP connection.\n");
- }
- break;
+ }
+
+ while (!ctx->quit) {
+ SDL_UpdateTexture(ctx->texture, NULL, ctx->pixels, 640 * sizeof(uint32_t));
+ SDL_WaitEvent(&ctx->event);
+ switch (ctx->event.type) {
+ case SDL_QUIT:
+ ctx->quit = true;
+ break;
+ case SDL_MOUSEBUTTONDOWN:
+ if (ctx->xmpp_fd == -1) {
+ ctx->xmpp_fd = xmpp_connect();
+ } else {
+ close(ctx->xmpp_fd);
+ ctx->xmpp_fd = -1;
+ printf("Closed XMPP connection.\n");
}
- SDL_RenderClear(ctx->renderer);
- SDL_RenderCopy(ctx->renderer, ctx->texture, NULL, NULL);
- SDL_RenderPresent(ctx->renderer);
+ break;
}
- SDL_DestroyWindow(ctx->window);
+ SDL_RenderClear(ctx->renderer);
+ SDL_RenderCopy(ctx->renderer, ctx->texture, NULL, NULL);
+ SDL_RenderPresent(ctx->renderer);
}
+ SDL_DestroyWindow(ctx->window);
deinit(ctx);
}