Skip to content

Commit 313786a

Browse files
committed
Modify font editor
Modify some contents in font editor 1. Move the headers from twin-fedit.h to twin-efdit.c. 2. Rewrite some commnets in C-style. 3. Include bool.h to replace int type with bool type for exit_window 4. Let draw_char(c) be called befor SDL_PollEvent(&event)
1 parent 720241d commit 313786a

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

tools/font-edit/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
TARGET = twin-fedit
22

3-
CFLAGS = $(shell pkg-config --cflags cairo) $(shell sdl2-config --cflags) -g -Wall
3+
CFLAGS = $(shell pkg-config --cflags cairo) $(shell sdl2-config --cflags) -g -Wall
44
LIBS = $(shell pkg-config --libs cairo) $(shell sdl2-config --libs)
55

66
OBJS = \

tools/font-edit/twin-fedit.c

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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

4242
static 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
}

tools/font-edit/twin-fedit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <stdlib.h>
3232
#include <string.h>
3333
#include <unistd.h>
34+
#include <stdbool.h>
3435

3536
/* Geometric types */
3637

0 commit comments

Comments
 (0)