diff --git a/data/README.md b/data/README.md new file mode 100644 index 0000000..da7f3c0 --- /dev/null +++ b/data/README.md @@ -0,0 +1,14 @@ +# Asset credits/collection + +Here is a list of all assets used by SoftLK and its examples. + +## Fonts + +Not all fonts listed here are actively used in the examples, but they can be found in the data/fonts directory and used by you. + +|File name|Image|License|Source| +|---|---|---|---| +|techno.png|![techno](fonts/techno.png)|CC0/public domain|[usr_share](https://opengameart.org/content/new-original-grafx2-font-collection) +|solar.png|![solar](fonts/solar.png)|CC0/public domain|[usr_share](https://opengameart.org/content/new-original-grafx2-font-collection) +|cursive1.png|![cursive1](fonts/cursive1.png)|CC0/public domain|[usr_share](https://opengameart.org/content/new-original-grafx2-font-collection) +|cursive2.png|![cursive2](fonts/cursive2.png)|CC0/public domain|[usr_share](https://opengameart.org/content/new-original-grafx2-font-collection) \ No newline at end of file diff --git a/data/fonts/cursive1.png b/data/fonts/cursive1.png new file mode 100644 index 0000000..6f795ad Binary files /dev/null and b/data/fonts/cursive1.png differ diff --git a/data/fonts/cursive1.slk b/data/fonts/cursive1.slk new file mode 100644 index 0000000..6cc730b Binary files /dev/null and b/data/fonts/cursive1.slk differ diff --git a/data/fonts/cursive2.png b/data/fonts/cursive2.png new file mode 100644 index 0000000..f2b2355 Binary files /dev/null and b/data/fonts/cursive2.png differ diff --git a/data/fonts/cursive2.slk b/data/fonts/cursive2.slk new file mode 100644 index 0000000..8a1dcae Binary files /dev/null and b/data/fonts/cursive2.slk differ diff --git a/data/fonts/solar.png b/data/fonts/solar.png new file mode 100644 index 0000000..e9cd8b8 Binary files /dev/null and b/data/fonts/solar.png differ diff --git a/data/fonts/solar.slk b/data/fonts/solar.slk new file mode 100644 index 0000000..e86b5d6 Binary files /dev/null and b/data/fonts/solar.slk differ diff --git a/data/fonts/techno.png b/data/fonts/techno.png new file mode 100644 index 0000000..5324aac Binary files /dev/null and b/data/fonts/techno.png differ diff --git a/data/fonts/techno.slk b/data/fonts/techno.slk new file mode 100644 index 0000000..4ec861e Binary files /dev/null and b/data/fonts/techno.slk differ diff --git a/examples/efelder/data/font8x8.png b/examples/efelder/data/font8x8.png deleted file mode 100644 index 4e3f6b8..0000000 Binary files a/examples/efelder/data/font8x8.png and /dev/null differ diff --git a/examples/efelder/data/font8x8.slk b/examples/efelder/data/font8x8.slk deleted file mode 100644 index 18b7d02..0000000 Binary files a/examples/efelder/data/font8x8.slk and /dev/null differ diff --git a/examples/efelder/data/palette.pal b/examples/efelder/data/palette.pal deleted file mode 100644 index 9bed677..0000000 --- a/examples/efelder/data/palette.pal +++ /dev/null @@ -1,20 +0,0 @@ -JASC-PAL -0100 -17 -0 0 0 -69 36 52 -20 12 28 -211 170 154 -223 239 215 -211 125 44 -219 215 93 -211 69 73 -134 77 48 -77 73 77 -48 52 109 -117 113 97 -109 195 203 -134 150 162 -109 170 44 -52 101 36 -89 125 207 diff --git a/examples/efelder/gui.c b/examples/efelder/gui.c index f95f100..1cbc0c7 100644 --- a/examples/efelder/gui.c +++ b/examples/efelder/gui.c @@ -79,7 +79,7 @@ static char text_help[GUI_HELP_LINES][36] = //only use 34 letters "You should have received a copy of", "the GNU General Public License ", "along with this program. If not, ", - ", see www.gnu.org/licenses/. ", + "see www.gnu.org/licenses/. ", "..................................", "Using this program should be ", "fairly easy, but I will try to ", diff --git a/examples/efelder/main.c b/examples/efelder/main.c index 4c9ec5d..dc402d2 100644 --- a/examples/efelder/main.c +++ b/examples/efelder/main.c @@ -72,6 +72,8 @@ int main(int argc, char *argv[]) SLK_layer_activate(5,1); SLK_layer_set_dynamic(5,1); + SLK_draw_rgb_load_font("../../data/fonts/cursive1.png"); + gui_init(); calculate(); diff --git a/examples/performance/data/font8x8.png b/examples/performance/data/font8x8.png deleted file mode 100644 index 4e3f6b8..0000000 Binary files a/examples/performance/data/font8x8.png and /dev/null differ diff --git a/examples/performance/data/font8x8.slk b/examples/performance/data/font8x8.slk deleted file mode 100644 index 18b7d02..0000000 Binary files a/examples/performance/data/font8x8.slk and /dev/null differ diff --git a/examples/performance/data/palette.pal b/examples/performance/data/palette.pal deleted file mode 100644 index 577e1bb..0000000 --- a/examples/performance/data/palette.pal +++ /dev/null @@ -1,19 +0,0 @@ -JASC-PAL -0100 -16 -69 36 52 -20 12 28 -211 170 154 -223 239 215 -211 125 44 -219 215 93 -211 69 73 -134 77 48 -77 73 77 -48 52 109 -117 113 97 -109 195 203 -134 150 162 -109 170 44 -52 101 36 -89 125 207 diff --git a/examples/performance/main.c b/examples/performance/main.c index 00cbef1..13a5ac2 100644 --- a/examples/performance/main.c +++ b/examples/performance/main.c @@ -67,6 +67,7 @@ int main(int argc, char *argv[]) load_pal_sprites(); load_rgb_sprites(); + SLK_draw_rgb_load_font("../../data/fonts/cursive1.png"); gui_00 = SLK_rgb_sprite_load("assets/gui_00.png"); gui_01 = SLK_rgb_sprite_load("assets/gui_01.png"); SLK_RGB_sprite *gui_02 = SLK_rgb_sprite_load("assets/gui_02.png"); diff --git a/examples/resize/data/3-3-2.pal b/examples/resize/assets/3-3-2.pal similarity index 100% rename from examples/resize/data/3-3-2.pal rename to examples/resize/assets/3-3-2.pal diff --git a/examples/resize/assets/0.slk b/examples/resize/assets/image.slk similarity index 100% rename from examples/resize/assets/0.slk rename to examples/resize/assets/image.slk diff --git a/examples/resize/assets/logo.png b/examples/resize/assets/logo.png deleted file mode 100644 index c078040..0000000 Binary files a/examples/resize/assets/logo.png and /dev/null differ diff --git a/examples/resize/data/font8x8.png b/examples/resize/data/font8x8.png deleted file mode 100644 index 4e3f6b8..0000000 Binary files a/examples/resize/data/font8x8.png and /dev/null differ diff --git a/examples/resize/data/font8x8.slk b/examples/resize/data/font8x8.slk deleted file mode 100644 index 18b7d02..0000000 Binary files a/examples/resize/data/font8x8.slk and /dev/null differ diff --git a/examples/resize/main.c b/examples/resize/main.c index f57483e..e5817dd 100644 --- a/examples/resize/main.c +++ b/examples/resize/main.c @@ -23,12 +23,12 @@ int main(int argc, char *argv[]) SLK_layer_set_scale(0,canvas_scale); SLK_draw_pal_set_clear_paxel(SLK_color_create_paxel(0,0)); SLK_draw_pal_clear(); - SLK_Pal_sprite *logo = SLK_pal_sprite_load("assets/0.slk"); + SLK_Pal_sprite *logo = SLK_pal_sprite_load("assets/image.slk"); SLK_layer_set_size(0,logo->width,logo->height); SLK_draw_pal_clear(); SLK_draw_pal_sprite(logo,0,0); SLK_pal_sprite_destroy(logo); - SLK_layer_set_palette(0,SLK_palette_load("data/3-3-2.pal")); + SLK_layer_set_palette(0,SLK_palette_load("assets/3-3-2.pal")); while(SLK_core_running()) diff --git a/include/SLK/SLK_functions.h b/include/SLK/SLK_functions.h index dfea56f..0c65861 100644 --- a/include/SLK/SLK_functions.h +++ b/include/SLK/SLK_functions.h @@ -55,6 +55,8 @@ SLK_Pal_sprite *SLK_pal_sheet_get(const SLK_Pal_sheet *sheet, int index); void SLK_draw_pal_set_target(SLK_Pal_sprite *s); SLK_Pal_sprite *SLK_draw_pal_get_target(); void SLK_draw_pal_set_clear_paxel(SLK_Paxel paxel); +void SLK_draw_pal_load_font(const char *path); +void SLK_draw_pal_set_font_sprite(SLK_Pal_sprite *font); void SLK_draw_pal_clear(); void SLK_draw_pal_paxel(int x, int y, SLK_Paxel paxel); void SLK_draw_pal_string(int x, int y, int scale, const char *text, SLK_Paxel paxel); @@ -92,6 +94,8 @@ SLK_RGB_sprite *SLK_draw_rgb_get_target(); void SLK_draw_rgb_set_target(SLK_RGB_sprite *s); void SLK_draw_rgb_set_clear_color(SLK_Color color); void SLK_draw_rgb_set_changed(int changed); +void SLK_draw_rgb_load_font(const char *path); +void SLK_draw_rgb_set_font_sprite(SLK_RGB_sprite *font); void SLK_draw_rgb_clear(); void SLK_draw_rgb_color(int x, int y, SLK_Color color); void SLK_draw_rgb_string(int x, int y, int scale, const char *text, SLK_Color color); diff --git a/lib/makefile b/lib/makefile index a26af3a..cc943da 100644 --- a/lib/makefile +++ b/lib/makefile @@ -8,7 +8,7 @@ DEPENDENCIES = SLK_core.o SLK_color.o SLK_draw_pal.o SLK_draw_rgb.o SLK_input.o backend_sdl2_gl: $(DEPENDENCIES) backend_sdl2_gl.o ar cr libSLK.a $^ -SLK_core.o: ../src/SLK_core.c ../include/SLK/SLK_types.h ../include/SLK/SLK_functions.h ../src/backend.h ../src/SLK_draw_rgb_i.h ../src/SLK_draw_pal_i.h ../src/SLK_layer_i.h +SLK_core.o: ../src/SLK_core.c ../include/SLK/SLK_types.h ../include/SLK/SLK_functions.h ../src/backend.h ../src/SLK_layer_i.h $(CC) -O3 -c $< $(CFLAGS) SLK_color.o: ../src/SLK_color.c ../include/SLK/SLK_functions.h ../include/SLK/SLK_types.h diff --git a/src/SLK_core.c b/src/SLK_core.c index 0b59c38..b334418 100644 --- a/src/SLK_core.c +++ b/src/SLK_core.c @@ -23,8 +23,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include "../include/SLK/SLK_types.h" #include "../include/SLK/SLK_functions.h" #include "backend.h" -#include "SLK_draw_rgb_i.h" -#include "SLK_draw_pal_i.h" #include "SLK_layer_i.h" //------------------------------------- @@ -118,10 +116,6 @@ void SLK_setup(int width, int height, int layer_num, const char *title, int full running = 1; SLK_core_set_fullscreen(fullscreen); - //Load font sprites. - text_sprite_pal = SLK_pal_sprite_load("data/font8x8.slk"); - text_sprite_rgb = SLK_rgb_sprite_load("data/font8x8.png"); - //Setup keymaps, or whatever you favourite backend does here. backend_input_init(); } diff --git a/src/SLK_draw_pal.c b/src/SLK_draw_pal.c index 5d7a148..67e5656 100644 --- a/src/SLK_draw_pal.c +++ b/src/SLK_draw_pal.c @@ -36,6 +36,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND //------------------------------------- //Variables +static SLK_Paxel target_pal_clear; +static SLK_Pal_sprite *text_sprite_pal; +static SLK_Pal_sprite *text_sprite_pal_default; //------------------------------------- //Function prototypes @@ -64,6 +67,29 @@ void SLK_draw_pal_set_target(SLK_Pal_sprite *s) target_pal = s; } +//Loads a new font sprite. +//Replaces the default font sprite. +void SLK_draw_pal_load_font(const char *path) +{ + SLK_pal_sprite_destroy(text_sprite_pal_default); + text_sprite_pal_default = SLK_pal_sprite_load(path); + text_sprite_pal = text_sprite_pal_default; +} + +//Sets the current font sprite from a +//sprite you have loaded in your code. +//Pass NULL to reset to default. +void SLK_draw_pal_set_font_sprite(SLK_Pal_sprite *font) +{ + if(font==NULL) + { + text_sprite_pal = text_sprite_pal_default; + return; + } + + text_sprite_pal = font; +} + //Sets the color wich the target is to be cleared to //when calling SLK_draw_pal_clear. void SLK_draw_pal_set_clear_paxel(SLK_Paxel paxel) @@ -96,34 +122,35 @@ void SLK_draw_pal_string(int x, int y, int scale, const char *text, SLK_Paxel pa int sx = 0; int sy = 0; - for(int i = 0;text[i];i++) + for (int i = 0;text[i];i++) { - if(text[i]=='\n') + if (text[i]=='\n') { sx = 0; sy+=8*scale; } else { - int ox = (text[i]-32) % 16; - int oy = (text[i]-32) / 16; + int ox = (text[i]-32)&15; + int oy = (text[i]-32)/16; - if(scale>1) - { for(int x_ = 0;x_<8;x_++) + { for(int y_ = 0;y_<8;y_++) + { if(!text_sprite_pal->data[(y_+oy*8)*128+x_+ox*8].mask) - for(int is = 0;isdata[(y_+oy*8)*128+x_+ox*8].mask) - SLK_draw_pal_paxel(x+sx+x_,y+sy+y_,paxel); - } + { + for(int o = 0;ochanged = changed; } +//Loads a new font sprite. +//Replaces the default font sprite. +void SLK_draw_rgb_load_font(const char *path) +{ + SLK_rgb_sprite_destroy(text_sprite_rgb_default); + text_sprite_rgb_default = SLK_rgb_sprite_load(path); + text_sprite_rgb= text_sprite_rgb_default; +} + +//Sets the current font sprite from a +//sprite you have loaded in your code. +//Pass NULL to reset to default. +void SLK_draw_rgb_set_font_sprite(SLK_RGB_sprite *font) +{ + if(font==NULL) + { + text_sprite_rgb = text_sprite_rgb_default; + + return; + } + + text_sprite_rgb = font; +} + //Clears the draw target to the color specified //by SKL_draw_rgb_set_clear_color. void SLK_draw_rgb_clear() @@ -109,25 +136,26 @@ void SLK_draw_rgb_string(int x, int y, int scale, const char *text, SLK_Color co } else { - int ox = (text[i]-32) % 16; - int oy = (text[i]-32) / 16; + int ox = (text[i]-32)&15; + int oy = (text[i]-32)/16; + + for(int x_ = 0;x_<8;x_++) + { + for(int y_ = 0;y_<8;y_++) + { + if(text_sprite_rgb->data[(y_+oy*8)*128+x_+ox*8].a) + { + for(int o = 0;o1) - { - for(int x_ = 0;x_<8;x_++) - for(int y_ = 0;y_<8;y_++) - if(text_sprite_rgb->data[(y_+oy*8)*128+x_+ox*8].a) - for(int is = 0;isdata[(y_+oy*8)*128+x_+ox*8].a) - SLK_draw_rgb_color(x+sx+x_,y+sy+y_,color); - } sx += 8*scale; } } diff --git a/src/SLK_draw_rgb_i.h b/src/SLK_draw_rgb_i.h index 288cc10..af463a6 100644 --- a/src/SLK_draw_rgb_i.h +++ b/src/SLK_draw_rgb_i.h @@ -21,7 +21,5 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND SLK_RGB_sprite *target_rgb; SLK_RGB_sprite *target_rgb_default; -SLK_Color target_rgb_clear; -SLK_RGB_sprite *text_sprite_rgb; #endif diff --git a/src/SLK_sprite_pal.c b/src/SLK_sprite_pal.c index a19b264..43a8fc9 100644 --- a/src/SLK_sprite_pal.c +++ b/src/SLK_sprite_pal.c @@ -60,6 +60,9 @@ SLK_Pal_sprite *SLK_pal_sprite_create(int width, int height) //needs to be freed. void SLK_pal_sprite_destroy(SLK_Pal_sprite *s) { + if(s==NULL) + return; + free(s->data); free(s); } diff --git a/src/SLK_sprite_rgb.c b/src/SLK_sprite_rgb.c index 9e9afdf..8e6bf45 100644 --- a/src/SLK_sprite_rgb.c +++ b/src/SLK_sprite_rgb.c @@ -65,6 +65,9 @@ SLK_RGB_sprite *SLK_rgb_sprite_create(int width, int height) //to be freed. void SLK_rgb_sprite_destroy(SLK_RGB_sprite *s) { + if(s==NULL) + return; + free(s->data); free(s); }