-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port font editor to SDL2 #59
Conversation
You don't have to write the message |
54d876b
to
dd01a82
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can I control the second control point, pt[1], when I press pt[2]? I can currently only control the first control point, pt[0].
Sorry, this function is not supported now. I'm trying to figure out how to let the second control point be moved by user. |
{ | ||
char_t *c; | ||
|
||
if (!init(argc, argv)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dump the usage before calling exit
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+ char_t *c;
+
+ /*
+ * Use the following command to start twin-fedit:
Don't do that. Dump the message.
What kind of usage should I dump here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can simply change the behavior of this font editor, allowing read a file from given filename (argv[1]
). Thus, you can check argument count and the existence of file to proceed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (argc < 2) {
printf("Usage: %s <filename>\n", argv[0]);
return 0;
}
FILE *file = fopen(argv[1], "r");
if (!file) {
printf("Failed to open file: %s\n", argv[1]);
return 0;
}
if (!init(argc, argv))
exit(1);
while ((c = read_char(file)) && !exit_window) {
play(c);
print_char(c);
}
fclose(file);
Before initializing init()
, use fopen
to read the content of argv[1]
and replace the previous method of reading strings from stdin
in read_char()
.
I adopted this approach to make the file reading process clearer and improve the readability of the code. I'm not sure if there is a better way to improve it.
3c63548
to
fd57d77
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use backtick characters in git commit messages for the sake of terminal compatibility. Also, avoid unnecessary bullets.
96170cf
to
77b1872
Compare
int i = !!is_2nd_point; | ||
|
||
push(c); | ||
first->pt[i].x += dx; | ||
first->pt[i].y += dy; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two !.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of !!
is a common trick to make sure the result will be either 0
or 1
.
ff93165
to
cd0516c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Append Close #7
at the end of git commit messages. Messages should use complete sentences and proper indentation.
Port font editor from X11 to SDL2, improving portability, cross-platform support, and maintainability. Window creation now uses SDL_CreateWindow, replacing X11 XCreateWindow. Event handling is migrated to SDL2 SDL_PollEvent, streamlining the capture of keyboard and mouse inputs. Rendering is updated to leverage SDL_Renderer and SDL_Surface, replacing X11 rendering functions. Key event behaviors have been refined for better usability. Pressing SDLK_ESCAPE or clicking the window close button (SDL_QUIT) now exits the application. To address a formatting issue with clang-format, the function delete() has been renamed to delete_first_cmd(), avoiding conflicts with the C++ keyword delete. File reading has also been simplified using fopen for improved clarity. The README has been expanded with a background on twin-fedit, key bindings, a quick start guide, and a demo GIF to help users get started. Close sysprog21#7
I adopted the 50/72 rule and refined the commit message to improve readability. |
Thank @jouae for contributing! |
Replace X11 with SDL2 to improve the portability and cross-platform support
Migrated window creation from X11's
XCreateWindow
toSDL_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
andSDL_Surface
, replacing X11's rendering functions.