Skip to content

Commit

Permalink
Port font editor to SDL2
Browse files Browse the repository at this point in the history
Replace X11 with SDL2 to improve the portability and cross-platform support

Migrated window creation from X11's `XCreateWindow` to `SDL_CreateWindow`.

Replaced X11 event handling with SDL2’s event loop (`SDL_PollEvent`)
to capture input events such as keyboard and mouse interactions.

Updated rendering to use `SDL_Renderer` and `SDL_Surface`,
replacing X11's rendering functions.

* Modified some key event logic:
1. SDLK_ESCAPE: ESC now exits the program.
2. SDL_QUIT: Clicking the "X" on the window exits the program.

* Unchanged key event logic:
1. SDLK_q: Switches to the next font.

* Rename delete function:
1. Rename delete() to delete_char() to avoid `clang-format` misinterpreting
`delete()` as the C++ the keyword, which cauese an extra space to be
added when running `clang-format`, turning `delete()` to `delete ()`.

* Add operation instructions in the READMD.
  • Loading branch information
jouae committed Nov 23, 2024
1 parent 35ddf50 commit dd01a82
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 144 deletions.
4 changes: 2 additions & 2 deletions tools/font-edit/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
TARGET = twin-fedit

CFLAGS = $(shell pkg-config --cflags cairo x11) -g -Wall
LIBS = $(shell pkg-config --libs cairo x11)
CFLAGS = $(shell pkg-config --cflags cairo) $(shell sdl2-config --cflags) -g -Wall
LIBS = $(shell pkg-config --libs cairo) $(shell sdl2-config --libs)

OBJS = \
twin-fedit.o \
Expand Down
13 changes: 11 additions & 2 deletions tools/font-edit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ screens.

## Build Dependency
```shell
sudo apt-get install libx11-dev libcairo2-dev
sudo apt-get install libsdl2-dev libcairo2-dev
```

## Usage
Expand All @@ -14,4 +14,13 @@ make
./twin-fedit < nchars
```

(press 'q' to next character)
| Key binding | Function |
| --- | --- |
| `esc` | Exit program |
| `left mouse button` | Select a point as start point |
| `right mouse button` | Select a point as end point |
| `d` | Delete selected point|
| `f`| Replace a line with a spline |
| `q` | Next character |
| `s` | Split a spline into two splines by start point and end point |
| `u` | Undo the last operation |
Loading

0 comments on commit dd01a82

Please sign in to comment.