@@ -37,7 +37,7 @@ static int offsets[1024];
3737 * if the value is 0, the windown lives,
3838 * otherwise the windown quit.
3939 */
40- static int exit_window = 0 ;
40+ static bool exit_window = 0 ;
4141
4242static int init (int argc , char * * argv )
4343{
@@ -46,7 +46,7 @@ static int init(int argc, char **argv)
4646 return 0 ;
4747 }
4848
49- window = SDL_CreateWindow ("Twin Fedit " , SDL_WINDOWPOS_CENTERED ,
49+ window = SDL_CreateWindow ("Font Editor " , SDL_WINDOWPOS_CENTERED ,
5050 SDL_WINDOWPOS_CENTERED , width , height ,
5151 SDL_WINDOW_SHOWN );
5252 if (!window ) {
@@ -501,54 +501,52 @@ static void play(char_t *c)
501501 SDL_StopTextInput ();
502502
503503 SDL_Event event ;
504- int quit_state = 0 ;
504+ SDL_Keycode key_event ;
505505
506506 /* keep track of the selected spline */
507507 cmd_t * spline = NULL ;
508- while (!quit_state ) {
508+ draw_char (c );
509+
510+ for (;;){
509511 while (SDL_PollEvent (& event )) {
510512 switch (event .type ) {
511513 /* If SDL event is detected */
512514 case SDL_QUIT :
513515 /* Click the "X" on the top of screen to exit the program */
514- quit_state = 1 ;
515516 exit_window = 1 ;
516- break ;
517+ return ;
517518 case SDL_KEYDOWN :
518519 /* If any key event is detected */
519- SDL_Keycode key_event = event .key .keysym .sym ;
520+ key_event = event .key .keysym .sym ;
521+
520522 switch (key_event ) {
521523 case SDLK_q :
522- /* Press "q" key to exit play()
524+ /* To exit play()
523525 * This allows the user to display the next character.
524526 */
525- quit_state = 1 ;
526- break ;
527+ return ;
527528 case SDLK_ESCAPE :
528- /* Press "ESC" key to quit the program */
529- quit_state = 1 ;
529+ /* To quit the program */
530530 exit_window = 1 ;
531- break ;
531+ return ;
532532 case SDLK_s :
533- /* Press "s" key to split the command between first and last
534- */
533+ /* To split the command between first char and last char */
535534 if (c -> first && c -> last ) {
536535 split (c , c -> first , c -> last );
537536 }
538537 break ;
539538 case SDLK_u :
540- /* Press "u" key to undo the last operation */
539+ /* To undo the last operation */
541540 undo (c );
542541 break ;
543542 case SDLK_f :
544- /* Press "f" key to replace with spline between first and
545- * last */
543+ /* To replace with spline between first and last */
546544 if (c -> first && c -> last ) {
547545 replace_with_spline (c , c -> first , c -> last );
548546 }
549547 break ;
550548 case SDLK_d :
551- /* Press "d" key to delete the first command */
549+ /* To delete the first command */
552550 if (c -> first ) {
553551 delete (c , c -> first );
554552 }
@@ -569,25 +567,22 @@ static void play(char_t *c)
569567 }
570568 break ;
571569 }
572- draw_char (
573- c ); // Ensure the content is redrawn after every key press
570+ /* Ensure the content is redrawn after every key press */
574571 break ;
575- /* End if key event detected */
572+ /* End if key event detected */
576573 case SDL_WINDOWEVENT :
577574 if (event .window .event == SDL_WINDOWEVENT_EXPOSED )
578- draw_char ( c ) ;
575+ break ;
579576 break ;
580577 case SDL_MOUSEBUTTONDOWN :
578+ /* Redraw the content after mouse button interaction */
581579 button (c , & event .button );
582- draw_char (
583- c ); // Redraw the content after mouse button interaction
584- break ;
585580 break ;
586- /* End if SDL event detected */
587581 }
582+ /* End if SDL event detected */
588583 }
589584
590- // Ensure the window surface is updated
585+ /* Ensure the SDL window surface is updated */
591586 SDL_UpdateWindowSurface (window );
592587 }
593588}
0 commit comments