2222
2323#include "twin-fedit.h"
2424
25+ #include <SDL2/SDL.h>
26+ #include <SDL2/SDL_keycode.h>
27+ #include <cairo.h>
28+ #include <stdbool.h>
29+
2530static SDL_Window * window ;
2631static cairo_t * cr ;
2732static cairo_surface_t * surface ;
@@ -37,7 +42,7 @@ static int offsets[1024];
3742 * if the value is 0, the windown lives,
3843 * otherwise the windown quit.
3944 */
40- static int exit_window = 0 ;
45+ static bool exit_window = 0 ;
4146
4247static int init (int argc , char * * argv )
4348{
@@ -46,7 +51,7 @@ static int init(int argc, char **argv)
4651 return 0 ;
4752 }
4853
49- window = SDL_CreateWindow ("Twin Fedit " , SDL_WINDOWPOS_CENTERED ,
54+ window = SDL_CreateWindow ("Font Editor " , SDL_WINDOWPOS_CENTERED ,
5055 SDL_WINDOWPOS_CENTERED , width , height ,
5156 SDL_WINDOW_SHOWN );
5257 if (!window ) {
@@ -501,54 +506,52 @@ static void play(char_t *c)
501506 SDL_StopTextInput ();
502507
503508 SDL_Event event ;
504- int quit_state = 0 ;
509+ SDL_Keycode key_event ;
505510
506511 /* keep track of the selected spline */
507512 cmd_t * spline = NULL ;
508- while (!quit_state ) {
513+ draw_char (c );
514+
515+ for (;;){
509516 while (SDL_PollEvent (& event )) {
510517 switch (event .type ) {
511518 /* If SDL event is detected */
512519 case SDL_QUIT :
513520 /* Click the "X" on the top of screen to exit the program */
514- quit_state = 1 ;
515521 exit_window = 1 ;
516- break ;
522+ return ;
517523 case SDL_KEYDOWN :
518524 /* If any key event is detected */
519- SDL_Keycode key_event = event .key .keysym .sym ;
525+ key_event = event .key .keysym .sym ;
526+
520527 switch (key_event ) {
521528 case SDLK_q :
522- /* Press "q" key to exit play()
529+ /* To exit play()
523530 * This allows the user to display the next character.
524531 */
525- quit_state = 1 ;
526- break ;
532+ return ;
527533 case SDLK_ESCAPE :
528- /* Press "ESC" key to quit the program */
529- quit_state = 1 ;
534+ /* To quit the program */
530535 exit_window = 1 ;
531- break ;
536+ return ;
532537 case SDLK_s :
533- /* Press "s" key to split the command between first and last
534- */
538+ /* To split the command between first char and last char */
535539 if (c -> first && c -> last ) {
536540 split (c , c -> first , c -> last );
537541 }
538542 break ;
539543 case SDLK_u :
540- /* Press "u" key to undo the last operation */
544+ /* To undo the last operation */
541545 undo (c );
542546 break ;
543547 case SDLK_f :
544- /* Press "f" key to replace with spline between first and
545- * last */
548+ /* To replace with spline between first and last */
546549 if (c -> first && c -> last ) {
547550 replace_with_spline (c , c -> first , c -> last );
548551 }
549552 break ;
550553 case SDLK_d :
551- /* Press "d" key to delete the first command */
554+ /* To delete the first command */
552555 if (c -> first ) {
553556 delete (c , c -> first );
554557 }
@@ -569,25 +572,22 @@ static void play(char_t *c)
569572 }
570573 break ;
571574 }
572- draw_char (
573- c ); // Ensure the content is redrawn after every key press
575+ /* Ensure the content is redrawn after every key press */
574576 break ;
575- /* End if key event detected */
577+ /* End if key event detected */
576578 case SDL_WINDOWEVENT :
577579 if (event .window .event == SDL_WINDOWEVENT_EXPOSED )
578- draw_char ( c ) ;
580+ break ;
579581 break ;
580582 case SDL_MOUSEBUTTONDOWN :
583+ /* Redraw the content after mouse button interaction */
581584 button (c , & event .button );
582- draw_char (
583- c ); // Redraw the content after mouse button interaction
584- break ;
585585 break ;
586- /* End if SDL event detected */
587586 }
587+ /* End if SDL event detected */
588588 }
589589
590- // Ensure the window surface is updated
590+ /* Ensure the SDL window surface is updated */
591591 SDL_UpdateWindowSurface (window );
592592 }
593593}
0 commit comments