diff options
author | untir_l <87096069+untir-l@users.noreply.github.com> | 2022-02-24 14:57:35 +0000 |
---|---|---|
committer | untir-l <87096069+untir-l@users.noreply.github.com> | 2022-02-25 09:56:49 +0000 |
commit | c23118e8e48d043e4bb9b4d813a498af8d454d73 (patch) | |
tree | 265947d2a848e8a3fb27106be38c8ae95b2fffe0 /lib | |
parent | 8a7dde79de6edee01571d2eb4a333d8256f4c342 (diff) | |
download | hitomezashi-c23118e8e48d043e4bb9b4d813a498af8d454d73.tar hitomezashi-c23118e8e48d043e4bb9b4d813a498af8d454d73.tar.gz hitomezashi-c23118e8e48d043e4bb9b4d813a498af8d454d73.zip |
Add web app frontend, restructure almost everything
- Add web app frontend code
- Add .html, .js, .wasm to .gitignore
- Restructure Makefile to work with emmake, add build targets for web app,
add .html, .js, .wasm to make clean
- Explain the pattern in the README
- Add explanation of web frontend to README
- Restructure README generally for better clarity
- Remove "make web app version" from todos in README
- Set Doxygen to EXTRACT_ALL so trivial and useless doc comments are not
needed when the naming suffices to be explanatory.
- Move ascii_binary_str_to_ints to library code in new file
hitomezashi_utils.c (and corresponding header) as web app also needs it.
- Fix SDL2 include path so it also works with Emscripten
- Remove some cluttering and unnecessary doc comments
- Improve some doc comments
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Doxyfile | 2 | ||||
-rw-r--r-- | lib/hitomezashi.c | 2 | ||||
-rw-r--r-- | lib/hitomezashi.h | 9 | ||||
-rw-r--r-- | lib/hitomezashi_utils.c | 22 | ||||
-rw-r--r-- | lib/hitomezashi_utils.h | 17 |
5 files changed, 43 insertions, 9 deletions
diff --git a/lib/Doxyfile b/lib/Doxyfile index e370a72..834117d 100644 --- a/lib/Doxyfile +++ b/lib/Doxyfile @@ -477,7 +477,7 @@ NUM_PROC_THREADS = 1 # normally produced when WARNINGS is set to YES. # The default value is: NO. -EXTRACT_ALL = NO +EXTRACT_ALL = YES # If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will # be included in the documentation. diff --git a/lib/hitomezashi.c b/lib/hitomezashi.c index 66f7440..c87073f 100644 --- a/lib/hitomezashi.c +++ b/lib/hitomezashi.c @@ -1,5 +1,5 @@ #include "hitomezashi.h" -#include "SDL.h" +#include "SDL2/SDL.h" #include <assert.h> SDL_Color HITOMEZASHI_FG_COLOUR = {.r = 0, .g = 0, .b = 0}; diff --git a/lib/hitomezashi.h b/lib/hitomezashi.h index 4453f70..64b17af 100644 --- a/lib/hitomezashi.h +++ b/lib/hitomezashi.h @@ -3,14 +3,12 @@ #ifndef HITOMEZASHI_HITOMEZASHI_H #define HITOMEZASHI_HITOMEZASHI_H -#include "SDL.h" +#include "SDL2/SDL.h" /** The state of a hitomezashi pattern. */ struct Hitomezashi_State { - /** The length of the x_pattern. */ int x_pattern_len; - /** The length of the y_pattern. */ int y_pattern_len; /** Pattern used to draw the vertical lines conceptually originating from the @@ -25,7 +23,6 @@ struct Hitomezashi_State { /** Gap between parallel lines. */ int gap; - /** Thickness of each line. */ int line_thickness; /** Width in pixels of the SDL_Surface needed to hold the pattern. This is @@ -41,7 +38,6 @@ struct Hitomezashi_State { /** Result of hitomezashi_state_init(). */ enum Hitomezashi_State_Init_Result { - /** The function completed successfully. */ Hitomezashi_State_Init_Result_Success, /** The function failed as it encountered an error initialising the SDL_Surface in state. */ @@ -50,7 +46,6 @@ enum Hitomezashi_State_Init_Result { /** Result of hitomezashi_draw() */ enum Hitomezashi_Draw_Result { - /** The function completed successfully. */ Hitomezashi_Draw_Result_Success, /** The function failed as it encountered an error "locking" the surface to write to it. */ @@ -64,7 +59,7 @@ hitomezashi_state_init(struct Hitomezashi_State *state, int x_pattern_len, int y_pattern_len, char *x_pattern, char *y_pattern, int gap, int line_thickness); -/** Draw the hitomezashi pattern to a Hitomezashi_State's surface. */ +/** Draw the hitomezashi pattern to state->surface. */ enum Hitomezashi_Draw_Result hitomezashi_draw(struct Hitomezashi_State *state); #endif // HITOMEZASHI_HITOMEZASHI_H diff --git a/lib/hitomezashi_utils.c b/lib/hitomezashi_utils.c new file mode 100644 index 0000000..32832de --- /dev/null +++ b/lib/hitomezashi_utils.c @@ -0,0 +1,22 @@ +#include "hitomezashi_utils.h" + +#include <stddef.h> +#include <stdlib.h> + +char *hitomezashi_ascii_binary_str_to_ints(char *ascii_str, size_t len) { + char *res = malloc(len); + for (int i = 0; i < len; ++i) { + switch (ascii_str[i]) { + case '0':; + res[i] = 0; + break; + case '1':; + res[i] = 1; + break; + default:; + free(res); + return NULL; + } + } + return res; +} diff --git a/lib/hitomezashi_utils.h b/lib/hitomezashi_utils.h new file mode 100644 index 0000000..040ea00 --- /dev/null +++ b/lib/hitomezashi_utils.h @@ -0,0 +1,17 @@ +/** @file + * Utilities connected with hitomezashi patterns that may be useful to + * applications. + */ +#ifndef HITOMEZASHI_UTILS_H +#define HITOMEZASHI_UTILS_H + +#include <stddef.h> + +/** Convert a string of ASCII digit 0s and 1s, eg. "1010", to a char array of + * numeric 0s and 1s. The return value is **dynamically allocated and must + * be freed**. + * @param len Length of ascii_str, not including any terminating null bytes. + */ +char *hitomezashi_ascii_binary_str_to_ints(char *ascii_str, size_t len); + +#endif // HITOMEZASHI_UTILS_H |