Skip to content

Commit 7231d62

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 7231d62

File tree

3 files changed

+29
-32
lines changed

3 files changed

+29
-32
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: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
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+
2530
static SDL_Window *window;
2631
static cairo_t *cr;
2732
static 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

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

tools/font-edit/twin-fedit.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
#ifndef _TWIN_FEDIT_H_
2424
#define _TWIN_FEDIT_H_
2525

26-
#include <SDL2/SDL.h>
27-
#include <SDL2/SDL_keycode.h>
28-
#include <cairo.h>
2926
#include <math.h>
3027
#include <stdio.h>
3128
#include <stdlib.h>

0 commit comments

Comments
 (0)