summaryrefslogtreecommitdiff
path: root/src/client/interface.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/interface.c')
-rw-r--r--src/client/interface.c200
1 files changed, 89 insertions, 111 deletions
diff --git a/src/client/interface.c b/src/client/interface.c
index 53119e4..e8f1971 100644
--- a/src/client/interface.c
+++ b/src/client/interface.c
@@ -1,4 +1,3 @@
-
#include <stdlib.h>
#include "main.h"
@@ -9,20 +8,14 @@
#include "keyboardBuffer.h"
#include "hotKey.h"
-// window surface
-static SDL_Surface *screen;
-//static SDL_Surface *my_surface;
-
-// timer
-static SDL_TimerID timer;
-// window flags
-static Uint32 g_win_flags;
+static SDL_Surface *screen; /* window surface */
+/*static SDL_Surface *my_surface;*/
+static SDL_TimerID timer; /* timer */
+static Uint32 g_win_flags; /* window flags */
static bool_t isInterfaceInit = FALSE;
-
-// flag, kterym se ridi zarazovani klaves do bufferu
-static bool_t keyboardBufferEnabled = FALSE;
+static bool_t keyboardBufferEnabled = FALSE; /* flag that controls organising keys into the buffer */
static bool_t use_open_gl;
bool_t interface_is_use_open_gl()
@@ -63,20 +56,21 @@ void interface_disable_keyboard_buffer()
void hotkey_screen()
{
- if (g_win_flags & SDL_FULLSCREEN)
+ if (g_win_flags & SDL_FULLSCREEN) {
g_win_flags &= ~SDL_FULLSCREEN;
- else
+ } else {
g_win_flags |= SDL_FULLSCREEN;
+ }
if (SDL_WM_ToggleFullScreen(screen) == 0) {
- fprintf(stderr, _("Unable to switch to FULLSCREEN mode!\n"));
+ fprintf(stderr, _("[Error] Unable to switch to the fullscreen mode\n"));
SDL_FreeSurface(screen);
screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, WIN_BPP, g_win_flags);
if (screen == NULL) {
- fprintf(stderr, _("Unable to switch to WINDOW mode! Error: %s\n"),
- SDL_GetError());
+ fprintf(stderr, _("[Error] Unable to switch to the window mode: %s\n"),
+ SDL_GetError());
return;
}
}
@@ -86,7 +80,7 @@ void hotkey_screen()
/*
* Sets video mode and sets up OpenGL for this change
*/
-SDL_Surface * SetVideoMode(int width, int height, int bpp, Uint32 flags)
+SDL_Surface *SetVideoMode(int width, int height, int bpp, Uint32 flags)
{
SDL_Surface *rval = 0;
@@ -102,13 +96,13 @@ SDL_Surface * SetVideoMode(int width, int height, int bpp, Uint32 flags)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
#ifdef SDL_GL_SWAP_CONTROL
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
-#endif
+#endif /* SDL_GL_SWAP_CONTROL */
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrtho(0.0f,width, height,0.0f,-1.0f,1.0f);
+ glOrtho(0.0f, width, height, 0.0f, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@@ -118,16 +112,15 @@ SDL_Surface * SetVideoMode(int width, int height, int bpp, Uint32 flags)
return rval;
}
-#endif
+#endif /* SUPPORT_OPENGL */
int interface_init()
{
-#ifdef DEBUG
- DEBUG_MSG(_("Initializing SDL system\n"));
-#endif
- // initialization of SDL
+ DEBUG_MSG(_("[Debug] Initializing SDL\n"));
+
+ /* initialization of SDL */
if (SDL_Init(SDL_SUBSYSTEMS) == -1) {
- fprintf(stderr, "SDL_Init %s\n", SDL_GetError());
+ fprintf(stderr, _("[Error] Unable to initialize SDL: %s\n"), SDL_GetError());
SDL_Quit();
return -1;
}
@@ -137,42 +130,38 @@ int interface_init()
g_win_flags = SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_ANYFORMAT;
screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, 0, g_win_flags);
-#endif
-
-#ifdef SUPPORT_OPENGL
- use_open_gl = ! isParamFlag("--disable-opengl");
+#else /* SUPPORT_OPENGL */
+ use_open_gl = !isParamFlag("--disable-opengl");
- if( interface_is_use_open_gl() )
- {
+ if (interface_is_use_open_gl()) {
g_win_flags = SDL_OPENGL;
screen = SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, 0, g_win_flags);
- if( screen == NULL )
- {
+ if (screen == NULL) {
use_open_gl = FALSE;
g_win_flags = SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_ANYFORMAT;
screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, 0, g_win_flags);
}
- }
- else
- {
+ } else {
g_win_flags = SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_ANYFORMAT;
screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, 0, g_win_flags);
}
-#endif
+#endif /* SUPPORT_OPENGL */
if (screen == NULL) {
- fprintf(stderr, "SDL_SetVideoMode %s\n", SDL_GetError());
+ fprintf(stderr, _("[Error] Unable to create interface: %s\n"), SDL_GetError());
SDL_Quit();
return -1;
}
- // Enable unicode by default for keyboard support.
- // It is bit more consuming than the nonsdl but can draw more characters.
+ /*
+ * enable unicode by default for keyboard support - it is bit more
+ * consuming than the nonsdl but can draw more characters
+ */
SDL_EnableUNICODE(1);
SDL_WM_SetCaption(WINDOW_TITLE, NULL);
- // Keyboard repeating
+ /* keyboard repeating */
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
timer = SDL_AddTimer(INTERVAL, TimerCallback, NULL);
@@ -189,7 +178,7 @@ int interface_init()
SDL_Surface *interface_get_screen()
{
- //return my_surface;
+ /*return my_surface;*/
return screen;
}
@@ -197,18 +186,13 @@ void interface_refresh()
{
#ifndef SUPPORT_OPENGL
SDL_Flip(screen);
-#endif
-
-#ifdef SUPPORT_OPENGL
- if( interface_is_use_open_gl() )
- {
+#else /* SUPPORT_OPENGL */
+ if (interface_is_use_open_gl()) {
SDL_GL_SwapBuffers();
- }
- else
- {
+ } else {
SDL_Flip(screen);
}
-#endif
+#endif /* SUPPORT_OPENGL */
}
void interface_get_mouse_position(int *x, int *y)
@@ -245,7 +229,7 @@ void printPressAnyKey()
for (i = SDLK_BACKSPACE; i < SDLK_KP9; i++)
if (mapa[i] == SDL_PRESSED) {
- printf(_("Pressed key with SDL value: %d\n"), i);
+ printf(_("[Debug] Pressed key [SDL: %d]\n"), i);
}
}
@@ -258,33 +242,29 @@ int hack_slow()
currentTime = timer_get_current_time();
- if( lastTime == 0 )
- {
+ if (lastTime == 0) {
lastTime = currentTime;
return 0;
}
- //printf("DEBUG: time interval %d\n", currentTime - lastTime);
+ /*printf("DEBUG: time interval %d\n", currentTime - lastTime);*/
- if( isSlowHack == FALSE && currentTime - lastTime >= 100 )
- {
- //printf("start slow hack (%d)\n", currentTime - lastTime);
+ if (isSlowHack == FALSE && currentTime - lastTime >= 100) {
+ /*printf("start slow hack (%d)\n", currentTime - lastTime);*/
isSlowHack = TRUE;
lastTime = timer_get_current_time();
return 1;
}
- if( isSlowHack == TRUE && currentTime - lastTime >= 50 )
- {
- //printf("stop slow hack (%d)\n", currentTime - lastTime);
+ if (isSlowHack == TRUE && currentTime - lastTime >= 50) {
+ /*printf("stop slow hack (%d)\n", currentTime - lastTime);*/
isSlowHack = FALSE;
lastTime = timer_get_current_time();
return 0;
}
- if( isSlowHack == TRUE )
- {
- //printf("hack time interval %d\n", currentTime - lastTime);
+ if (isSlowHack == TRUE) {
+ /*printf("hack time interval %d\n", currentTime - lastTime);*/
}
lastTime = timer_get_current_time();
@@ -296,59 +276,56 @@ int eventAction()
{
SDL_Event event;
-
while (SDL_WaitEvent(&event)) {
switch (event.type) {
- case SDL_KEYDOWN:
- switch (event.key.keysym.sym) {
- default:
- //neni potreba vyuzivat frontu stale
- if (keyboardBufferEnabled == TRUE)
- keyboard_buffer_push(event.key.keysym);
- break;
- }
- break;
-
- case SDL_USEREVENT:
- switch (event.user.code) {
- case USR_EVT_TIMER:
- if( hack_slow() )
- {
- break;
+ case SDL_KEYDOWN:
+ switch (event.key.keysym.sym) {
+ default:
+ /* it is not necessary to always use the buffer */
+ if (keyboardBufferEnabled == TRUE) {
+ keyboard_buffer_push(event.key.keysym);
+ }
+ break;
}
-
- screen_draw();
- screen_event();
- hot_key_event();
- screen_switch();
break;
- default:
+ case SDL_USEREVENT:
+ switch (event.user.code) {
+ case USR_EVT_TIMER:
+ if (hack_slow()) {
+ break;
+ }
+
+ screen_draw();
+ screen_event();
+ hot_key_event();
+ screen_switch();
+ break;
+
+ default:
+ break;
+ }
break;
- }
- break;
-
- // change of window size
- case SDL_VIDEORESIZE:
- screen =
- SDL_SetVideoMode(event.resize.w, event.resize.h, WIN_BPP,
- g_win_flags);
-
- if (screen == NULL) {
- fprintf(stderr,
- _("Unable to change WINDOW resolution! Error: %s\n"),
+
+ /* change the window size */
+ case SDL_VIDEORESIZE:
+ screen = SDL_SetVideoMode(event.resize.w, event.resize.h,
+ WIN_BPP, g_win_flags);
+
+ if (screen == NULL) {
+ fprintf(stderr, _("[Error] Unable to change resolution of the window: %s\n"),
SDL_GetError());
- return 0;
- }
- break;
+ return 0;
+ }
+ break;
- // termination request
- case SDL_QUIT:
- return -1;
- break;
+ /* termination request */
+ case SDL_QUIT:
+ return -1;
+ break;
- default:
- break;
+ default:
+ break;
}
}
@@ -358,14 +335,15 @@ int eventAction()
void interface_event()
{
while (1) {
- if (eventAction() == -1)
+ if (eventAction() == -1) {
return;
+ }
}
}
void interface_quit()
{
- DEBUG_MSG(_("Quitting SDL\n"));
+ DEBUG_MSG(_("[Debug] Shutting down SDL\n"));
hot_key_quit();
keyboard_buffer_quit();