Implemented input handling for scenes (skip, fullscreen, quit), and pulled input handling for textboxes out into its own function
Derek Stevens nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAlupTXIACgkQO3+8IhRO Y5hjiQ//drDTUjAjrTIJjAQGMEetNd8MDdrq+pOA7Wh0H8Lzob7zI9FOwyiYl0El XLzwqlFzwATMY4Yc1BBNrRwba8KWiP7Ua8J6nC1tSA8IVKVTIGVl+kg4V83uJ61n 3fWMsQcmiYBW1tX/wju5TkzG03YvkWrn4ud7O5VARKQvcwpOLM2xVQu3np6JZcm9 boP58YKyNzafHFm9jQE6ICFHs6djZ0SY6sfcT9qBftWgl2NedGu0YjO3mENY76pl mywCJCMITDr7dRisk0NIZHYFT9N3r5bX9x+ZIsBKIDpngsx3sXHIVeVpgemr4lkZ kg9WeSJPrGZP2Ka+sRoIajUwEXeI372MF6JmcDwB4d/xj2RwLkdmf3/OxwV2DM76 PaWKa63+UKhCmI0sC5P64/gFC7ikAM1Jw/9akjj5WrFvdO3dxny6U6pWZOy0+0cx 3jXnYksS5W9fv0e2G69MmGo1Qe31nRGjDeQ7pf+mQ6Og5D3du9HlCzTedEXWlZST MPDflQVRahh9ezh2zvEe8Z/fYxLxxiyQkmmNmSIP8SrTa8Hve6VB8lwQwH/Ft9kb QkIhWbAdac47p3v9C72C04p6lvpNDB7/8J/RuM17HAmB0qZOerSdgIWBqOQfZXIb 7L93+R1t5A512r+CwxbPSUa6SsKsPAPtzajhDRY8CPHUf7rTY9s= =jd4C -----END PGP SIGNATURE-----
M
Scene.c
→
Scene.c
@@ -68,6 +68,41 @@ self->sprites[self->nSprites] = sprite;
self->nSprites++; } +void sceneInput(Scene* self, int* counter) +{ + while (SDL_PollEvent(&event)) + { + switch (event.type) + { + case SDL_KEYDOWN: + switch (event.key.keysym.sym) + { + case SDLK_j: + *counter = self->time - 1; + break; + case SDLK_f: + toggleFullscreen(); + break; + default: break; + } + break; + case SDL_QUIT: + if (playing) + { + playing = 0; + quit = 1; + } + else + { + *counter = self->time - 1; + playing = 0; + quit = 1; + } + break; + } + } +} + void playScene(Scene* self) { int i, j;@@ -88,6 +123,7 @@
for (i = 0; i < self->time; i++) { timeStart(fps); + sceneInput(self, &i); for (j = 0; j < self->nSprites; j++) { applySurface(self->sprites[j]->x, self->sprites[j]->y, self->sprites[j]->sprite, screen, NULL);
M
TextBox.c
→
TextBox.c
@@ -64,34 +64,8 @@ self->message[self->lines] = TTF_RenderText_Solid(font, text, textColor);
self->lines++; } -void displayTextBox(TextBox* self) +void textBoxInput(TextBox* self, int* textIsRelevent) { - int textIsRelevent = 1; - int offset = -32; - int i; - SDL_Rect textScroller = {0, 0, 0, 14}; - actionbutton = 0; - while (textIsRelevent) - { - timeStart(fps); - renderBackground(); - renderForeground(); - - applySurface(22, 51, textBoxBG, screen, NULL); - if (self->portrait) - { - applySurface(32, 58, self->portrait, screen, NULL); - offset = 0; - } - - for (i = self->scrollFrom; i < self->scroll; i++) - { - applySurface(106 + offset, 64+(14*(i%4)), self->message[i], screen, NULL); - } - - textScroller.w = self->cursor*10; - applySurface(106 + offset, 64+(14*(self->scroll%4)), self->message[self->scroll], screen, &textScroller); - if (self->cursor != 17) { self->cursor++;@@ -99,7 +73,7 @@ while (SDL_PollEvent(&event))
{ switch (event.type) { - case SDL_QUIT: quit=1; playing = 0; textIsRelevent = 0; break; + case SDL_QUIT: quit=1; playing = 0; *textIsRelevent = 0; break; case SDL_KEYDOWN: switch (event.key.keysym.sym) {@@ -125,7 +99,7 @@ while (SDL_PollEvent(&event))
{ switch (event.type) { - case SDL_QUIT: quit = 1; playing = 0; textIsRelevent = 0; break; + case SDL_QUIT: quit = 1; playing = 0; *textIsRelevent = 0; break; case SDL_KEYDOWN: switch (event.key.keysym.sym) {@@ -136,7 +110,7 @@ self->cursor = 0;
self->scroll++; self->scrollFrom += 4; } - else textIsRelevent = 0; + else *textIsRelevent = 0; break; case SDLK_f: toggleFullscreen();@@ -147,6 +121,38 @@ }
} } } +} + +void displayTextBox(TextBox* self) +{ + int textIsRelevent = 1; + int offset = -32; + int i; + SDL_Rect textScroller = {0, 0, 0, 14}; + actionbutton = 0; + while (textIsRelevent) + { + timeStart(fps); + renderBackground(); + renderForeground(); + + applySurface(22, 51, textBoxBG, screen, NULL); + if (self->portrait) + { + applySurface(32, 58, self->portrait, screen, NULL); + offset = 0; + } + + for (i = self->scrollFrom; i < self->scroll; i++) + { + applySurface(106 + offset, 64+(14*(i%4)), self->message[i], screen, NULL); + } + + textScroller.w = self->cursor*10; + applySurface(106 + offset, 64+(14*(self->scroll%4)), self->message[self->scroll], screen, &textScroller); + + textBoxInput(self, &textIsRelevent); + SDL_Flip(screen); timeDilation();