Added sprite sheets

* some progress in efelder
* rgb and pal sprite sheets for easier tileset management
This commit is contained in:
Captain4LK 2020-07-16 16:16:44 +02:00
parent 012737d608
commit 6a76767bb1
20 changed files with 1108 additions and 104 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

314
examples/efelder/gui.c Normal file
View file

@ -0,0 +1,314 @@
/*
Copyright (C) 2020 by Captain4LK (Lukas Holzbeierlein)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
//This code is a big mess,
//just as always with gui code
//without the use of an actual gui framework.
//External includes
#include "../../include/SLK/SLK.h"
//-------------------------------------
//Internal includes
#include "gui.h"
#include "settings.h"
//-------------------------------------
//#defines
//-------------------------------------
//Typedefs
//-------------------------------------
//Variables
static SLK_RGB_sprite *gui_top_right;
static SLK_RGB_sprite *gui_options;
static SLK_RGB_sprite *gui_help;
static SLK_RGB_sprite *button_0_pressed;
static SLK_RGB_sprite *button_1_pressed;
static SLK_RGB_sprite *button_2_pressed;
static int button_0_anim = 0;
static int button_1_anim = 0;
static int button_2_anim = 0;
static int gui_mode;
static int can_x = 0;
static int can_y = 0;
static float can_scale = 1.0f;
static char text_help[][32] = //only use 30 letters
{
"",
};
//-------------------------------------
//Function prototypes
//-------------------------------------
//Function implementations
void gui_init()
{
//Load assets
SLK_RGB_sprite *sheet = SLK_rgb_sprite_load("assets/about.png");
gui_top_right = SLK_rgb_sprite_create(44,164);
gui_options = SLK_rgb_sprite_create(293,100);
gui_help = SLK_rgb_sprite_create(293,324);
button_0_pressed = SLK_rgb_sprite_create(44,44);
button_1_pressed = SLK_rgb_sprite_create(44,44);
button_2_pressed = SLK_rgb_sprite_create(44,44);
SLK_rgb_sprite_copy_partial(gui_top_right,sheet,0,0,229,64,44,164);
SLK_rgb_sprite_copy_partial(gui_options,sheet,0,0,317,0,293,100);
SLK_rgb_sprite_copy_partial(gui_help,sheet,0,0,610,0,293,324);
SLK_rgb_sprite_copy_partial(button_0_pressed,sheet,0,0,273,88,44,44);
SLK_rgb_sprite_copy_partial(button_1_pressed,sheet,0,0,273,136,44,44);
SLK_rgb_sprite_copy_partial(button_2_pressed,sheet,0,0,273,184,44,44);
SLK_rgb_sprite_destroy(sheet);
//Setup layers
int width_l,height_l;
SLK_layer_get_size(5,&width_l,&height_l);
SLK_layer_set_size(0,width_l/gui_scale,height_l/gui_scale);
SLK_layer_set_scale(0,gui_scale);
SLK_layer_set_pos(0,0,0);
SLK_layer_set_size(1,can_width,can_height);
SLK_layer_set_pos(1,can_x,can_y);
SLK_layer_set_scale(1,can_scale);
SLK_layer_set_size(2,can_width,can_height);
SLK_layer_set_pos(2,can_x,can_y);
SLK_layer_set_scale(2,can_scale);
SLK_layer_set_size(3,can_width,can_height);
SLK_layer_set_pos(3,can_x,can_y);
SLK_layer_set_scale(3,can_scale);
SLK_layer_set_current(0);
SLK_draw_rgb_set_clear_color(SLK_color_create(0,0,0,0));
SLK_draw_rgb_clear();
SLK_draw_rgb_set_changed(1);
}
void gui_update()
{
int width,height;
SLK_layer_get_size(0,&width,&height);
switch(gui_mode)
{
case 0: //electrical fields
case 1: //electric potential
if(SLK_mouse_down(SLK_BUTTON_MIDDLE))
{
int x,y;
SLK_mouse_get_relative_pos(&x,&y);
can_x+=x;
can_y+=y;
SLK_layer_set_pos(1,can_x,can_y);
SLK_layer_set_pos(2,can_x,can_y);
SLK_layer_set_pos(3,can_x,can_y);
}
if(SLK_mouse_pressed(SLK_BUTTON_LEFT))
{
int x,y;
SLK_mouse_get_layer_pos(0,&x,&y);
if(x>=width-44&&x<width)
{
if(y>=24&&y<68)
{
button_0_anim = 10;
gui_mode = 2;
}
if(y>=72&&y<116)
{
button_1_anim = 10;
gui_mode = 3;
}
if(y>=120&&y<164)
button_2_anim = 10;
}
}
int wheel = SLK_mouse_wheel_get_scroll();
if(wheel<0)
{
int mx,my;
SLK_mouse_get_pos(&mx,&my);
float x = ((float)mx-(float)can_x)/can_scale;
float y = ((float)my-(float)can_y)/can_scale;
float scale_change = -can_scale*0.15f;
can_scale+=can_scale*0.15f;
can_x+=x*scale_change;
can_y+=y*scale_change;
SLK_layer_set_pos(1,can_x,can_y);
SLK_layer_set_pos(2,can_x,can_y);
SLK_layer_set_pos(3,can_x,can_y);
SLK_layer_set_scale(1,can_scale);
SLK_layer_set_scale(2,can_scale);
SLK_layer_set_scale(3,can_scale);
}
else if(wheel>0)
{
int mx,my;
SLK_mouse_get_pos(&mx,&my);
float x = ((float)mx-(float)can_x)/can_scale;
float y = ((float)my-(float)can_y)/can_scale;
float scale_change = can_scale*0.15f;
can_scale-=can_scale*0.15f;
can_x+=x*scale_change;
can_y+=y*scale_change;
SLK_layer_set_pos(1,can_x,can_y);
SLK_layer_set_pos(2,can_x,can_y);
SLK_layer_set_pos(3,can_x,can_y);
SLK_layer_set_scale(1,can_scale);
SLK_layer_set_scale(2,can_scale);
SLK_layer_set_scale(3,can_scale);
}
break;
case 2: //Options
{
int pos_x = (width-gui_options->width)/2;
int pos_y = (height-gui_options->height)/2;
if(SLK_mouse_pressed(SLK_BUTTON_LEFT))
{
int x,y;
SLK_mouse_get_layer_pos(0,&x,&y);
if(y>pos_y+78&&y<pos_y+95)
{
if(x>pos_x+86&&x<pos_x+103&&gui_scale>0.1f)
{
gui_scale-=0.1f;
int width_l,height_l;
SLK_layer_get_size(5,&width_l,&height_l);
SLK_layer_set_size(0,width_l/gui_scale,height_l/gui_scale);
SLK_layer_set_scale(0,gui_scale);
SLK_layer_set_pos(0,0,0);
SLK_layer_set_current(0);
SLK_draw_rgb_set_clear_color(SLK_color_create(0,0,0,0));
SLK_draw_rgb_clear();
SLK_draw_rgb_set_changed(1);
}
else if(x>pos_x+210&&x<+pos_x+227&&gui_scale<10.0f)
{
gui_scale+=0.1f;
int width_l,height_l;
SLK_layer_get_size(5,&width_l,&height_l);
SLK_layer_set_size(0,width_l/gui_scale,height_l/gui_scale);
SLK_layer_set_scale(0,gui_scale);
SLK_layer_set_pos(0,0,0);
SLK_layer_set_current(0);
SLK_draw_rgb_set_clear_color(SLK_color_create(0,0,0,0));
SLK_draw_rgb_clear();
SLK_draw_rgb_set_changed(1);
}
}
if(x>pos_x+245&&x<pos_x+286&&y>pos_y+8&&y<pos_y+56)
{
gui_mode = 0;
SLK_layer_set_current(0);
SLK_draw_rgb_set_clear_color(SLK_color_create(0,0,0,0));
SLK_draw_rgb_clear();
SLK_draw_rgb_set_changed(1);
}
}
}
break;
case 3: //help
{
int pos_x = (width-gui_help->width)/2;
int pos_y = (height-gui_help->height)/2;
if(SLK_mouse_pressed(SLK_BUTTON_LEFT))
{
int x,y;
SLK_mouse_get_layer_pos(0,&x,&y);
if(x>pos_x+245&&x<pos_x+286&&y>pos_y+8&&y<pos_y+56)
{
gui_mode = 0;
SLK_layer_set_current(0);
SLK_draw_rgb_set_clear_color(SLK_color_create(0,0,0,0));
SLK_draw_rgb_clear();
SLK_draw_rgb_set_changed(1);
}
}
}
break;
}
}
void gui_draw()
{
if(SLK_layer_get_resized(5))
{
int width_l,height_l;
SLK_layer_get_size(5,&width_l,&height_l);
SLK_layer_set_size(0,width_l/gui_scale,height_l/gui_scale);
SLK_layer_set_scale(0,gui_scale);
SLK_layer_set_pos(0,0,0);
SLK_layer_set_current(0);
SLK_draw_rgb_set_clear_color(SLK_color_create(0,0,0,0));
SLK_draw_rgb_clear();
SLK_draw_rgb_set_changed(1);
}
SLK_layer_set_current(0);
SLK_draw_rgb_set_changed(1);
int width,height;
SLK_layer_get_size(0,&width,&height);
//Gets always drawn
SLK_draw_rgb_sprite(gui_top_right,width-44,0);
if(button_0_anim)
{
button_0_anim--;
SLK_draw_rgb_sprite(button_0_pressed,width-44,24);
}
if(button_1_anim)
{
button_1_anim--;
SLK_draw_rgb_sprite(button_1_pressed,width-44,72);
}
if(button_2_anim)
{
button_2_anim--;
SLK_draw_rgb_sprite(button_2_pressed,width-44,120);
}
//Modes:
//0,1: unused/default
//2: settings
//3: help
switch(gui_mode)
{
case 2:
{
int pos_x = (width-gui_options->width)/2;
int pos_y = (height-gui_options->height)/2;
SLK_draw_rgb_sprite(gui_options,pos_x,pos_y);
char temp_str[256] = "";
sprintf(temp_str,"%03f",gui_scale);
SLK_draw_rgb_string(pos_x+128,pos_y+83,1,temp_str,SLK_color_create(203,219,252,255));
}
break;
case 3:
{
int pos_x = (width-gui_help->width)/2;
int pos_y = (height-gui_help->height)/2;
SLK_draw_rgb_sprite(gui_help,pos_x,pos_y);
}
break;
}
}

29
examples/efelder/gui.h Normal file
View file

@ -0,0 +1,29 @@
/*
Copyright (C) 2020 by Captain4LK (Lukas Holzbeierlein)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _GUI_H_
#define _GUI_H_
int can_width;
int can_height;
void gui_init();
void gui_update();
void gui_draw();
#endif

View file

@ -15,11 +15,29 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
//External includes
#include <cjson/cJSON.h>
#include "../../include/SLK/SLK.h"
#include "ULK_file.h"
#include "ULK_vector.h"
#include <cjson/cJSON.h>
//-------------------------------------
//Internal includes
#include "gui.h"
#include "settings.h"
//-------------------------------------
//#defines
//-------------------------------------
//Typedefs
//-------------------------------------
//Variables
//-------------------------------------
//Function prototypes
//-------------------------------------
typedef struct
{
@ -45,11 +63,6 @@ int shapes_count;
int mode = 0;
int win_width;
int win_height;
int can_width;
int can_height;
int can_x = 0;
int can_y = 0;
float can_scale = 1.0f;
void load_shapes();
void draw_shapes();
@ -57,32 +70,38 @@ void calculate_circle(int shape);
void calculate();
void calculate_pos(ULK_vector_2d out, float x, float y);
//Function implementations
int main(int argc, char *argv[])
{
load_shapes();
SLK_setup(win_width,win_height,3,"SLK Engine",0,1,1);
SLK_setup(win_width,win_height,6,"SLK Engine",0,1,1);
SLK_timer_set_fps(30);
SLK_layer_create(0,SLK_LAYER_RGB); //Layer for drawing shapes
SLK_layer_create(1,SLK_LAYER_RGB); //Layer for drawing electric field
SLK_layer_create(2,SLK_LAYER_RGB);
SLK_layer_create(0,SLK_LAYER_RGB); //Layer for GUI
SLK_layer_create(1,SLK_LAYER_RGB); //Layer for shapes
SLK_layer_create(2,SLK_LAYER_RGB); //Layer for drawing electric field
SLK_layer_create(3,SLK_LAYER_RGB); //Layer for drawing electric potential
SLK_layer_create(4,SLK_LAYER_RGB); //Layer for editing layout
SLK_layer_create(5,SLK_LAYER_RGB); //Layer for background
SLK_layer_activate(0,1);
SLK_layer_set_dynamic(0,0);
SLK_layer_set_size(0,can_width,can_height);
SLK_layer_set_pos(0,can_x,can_y);
SLK_layer_set_scale(0,can_scale);
SLK_layer_activate(1,0);
SLK_layer_activate(1,1);
SLK_layer_set_dynamic(1,0);
SLK_layer_set_size(1,can_width,can_height);
SLK_layer_set_pos(1,can_x,can_y);
SLK_layer_set_scale(1,can_scale);
SLK_layer_activate(2,1);
SLK_layer_activate(2,0);
SLK_layer_set_dynamic(2,0);
SLK_layer_set_size(2,can_width,can_height);
SLK_layer_set_pos(2,can_x,can_y);
SLK_layer_set_scale(1,can_scale);
SLK_layer_activate(3,1);
SLK_layer_set_dynamic(3,0);
SLK_layer_activate(4,0);
SLK_layer_set_dynamic(4,0);
SLK_layer_activate(5,1);
SLK_layer_set_dynamic(5,1);
settings_init_default();
gui_init();
draw_shapes();
@ -91,66 +110,25 @@ int main(int argc, char *argv[])
while(SLK_core_running())
{
SLK_update();
gui_update();
if(SLK_key_pressed(SLK_KEY_M))
{
if(mode)
{
mode = 0;
SLK_layer_activate(1,0);
SLK_layer_activate(2,1);
SLK_layer_activate(2,0);
SLK_layer_activate(3,1);
}
else
{
mode = 1;
SLK_layer_activate(1,1);
SLK_layer_activate(2,0);
}
}
if(SLK_mouse_down(SLK_BUTTON_MIDDLE))
{
int x,y;
SLK_mouse_get_relative_pos(&x,&y);
can_x+=x;
can_y+=y;
SLK_layer_set_pos(0,can_x,can_y);
SLK_layer_set_pos(1,can_x,can_y);
SLK_layer_set_pos(2,can_x,can_y);
}
if(SLK_key_down(SLK_KEY_CTRL))
{
int wheel = SLK_mouse_wheel_get_scroll();
if(wheel<0)
{
can_x-=SLK_core_get_width()*can_scale*0.1f*2.f;
can_y-=SLK_core_get_height()*can_scale*0.1f*2.f;
SLK_layer_set_pos(0,can_x,can_y);
SLK_layer_set_pos(1,can_x,can_y);
SLK_layer_set_pos(2,can_x,can_y);
can_scale+=can_scale*0.1f;
SLK_layer_set_scale(0,can_scale);
SLK_layer_set_scale(1,can_scale);
SLK_layer_set_scale(2,can_scale);
}
else if(wheel>0)
{
can_x+=SLK_core_get_width()*can_scale*0.1f*2.f;
can_y+=SLK_core_get_height()*can_scale*0.1f*2.f;
SLK_layer_set_pos(0,can_x,can_y);
SLK_layer_set_pos(1,can_x,can_y);
SLK_layer_set_pos(2,can_x,can_y);
can_scale-=can_scale*0.1f;
SLK_layer_set_scale(0,can_scale);
SLK_layer_set_scale(1,can_scale);
SLK_layer_set_scale(2,can_scale);
SLK_layer_activate(2,1);
SLK_layer_activate(3,0);
}
}
gui_draw();
SLK_render_update();
}
@ -216,7 +194,7 @@ void draw_shapes()
{
int i;
SLK_layer_set_current(0);
SLK_layer_set_current(1);
SLK_draw_rgb_set_changed(1);
SLK_draw_rgb_set_clear_color(SLK_color_create(0,0,0,0));
@ -236,7 +214,7 @@ void calculate()
{
int i;
SLK_layer_set_current(1);
SLK_layer_set_current(2);
SLK_draw_rgb_set_changed(1);
SLK_draw_rgb_set_clear_color(SLK_color_create(0,0,0,0));
SLK_draw_rgb_clear();
@ -251,11 +229,11 @@ void calculate()
}
}
SLK_layer_set_current(2);
SLK_layer_set_current(3);
SLK_draw_rgb_set_changed(1);
SLK_draw_rgb_clear();
//Calculate electrical
//Calculate electrical potential
for(int x = 0;x<can_width;x++)
{
for(int y = 0;y<can_height;y++)
@ -359,3 +337,4 @@ void calculate_pos(ULK_vector_2d out, float x, float y)
{
}
//-------------------------------------

View file

@ -28,4 +28,4 @@
"test_points":45
}
]
}
}

View file

@ -0,0 +1,43 @@
/*
Copyright (C) 2020 by Captain4LK (Lukas Holzbeierlein)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
//External includes
//-------------------------------------
//Internal includes
#include "settings.h"
//-------------------------------------
//#defines
//-------------------------------------
//Typedefs
//-------------------------------------
//Variables
//-------------------------------------
//Function prototypes
//-------------------------------------
//Function implementations
void settings_init_default()
{
gui_scale = 2.0f;
}
//-------------------------------------

View file

@ -0,0 +1,26 @@
/*
Copyright (C) 2020 by Captain4LK (Lukas Holzbeierlein)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _SETTINGS_H_
#define _SETTINGS_H_
float gui_scale;
void settings_init_default();
#endif

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

@ -0,0 +1,259 @@
JASC-PAL
0100
256
0 0 0 255
32 0 0 255
64 0 0 255
96 0 0 255
128 0 0 255
160 0 0 255
192 0 0 255
224 0 0 255
0 32 0 255
32 32 0 255
64 32 0 255
96 32 0 255
128 32 0 255
160 32 0 255
192 32 0 255
224 32 0 255
0 64 0 255
32 64 0 255
64 64 0 255
96 64 0 255
128 64 0 255
160 64 0 255
192 64 0 255
224 64 0 255
0 96 0 255
32 96 0 255
64 96 0 255
96 96 0 255
128 96 0 255
160 96 0 255
192 96 0 255
224 96 0 255
0 128 0 255
32 128 0 255
64 128 0 255
96 128 0 255
128 128 0 255
160 128 0 255
192 128 0 255
224 128 0 255
0 160 0 255
32 160 0 255
64 160 0 255
96 160 0 255
128 160 0 255
160 160 0 255
192 160 0 255
224 160 0 255
0 192 0 255
32 192 0 255
64 192 0 255
96 192 0 255
128 192 0 255
160 192 0 255
192 192 0 255
224 192 0 255
0 224 0 255
32 224 0 255
64 224 0 255
96 224 0 255
128 224 0 255
160 224 0 255
192 224 0 255
224 224 0 255
0 0 64 255
32 0 64 255
64 0 64 255
96 0 64 255
128 0 64 255
160 0 64 255
192 0 64 255
224 0 64 255
0 32 64 255
32 32 64 255
64 32 64 255
96 32 64 255
128 32 64 255
160 32 64 255
192 32 64 255
224 32 64 255
0 64 64 255
32 64 64 255
64 64 64 255
96 64 64 255
128 64 64 255
160 64 64 255
192 64 64 255
224 64 64 255
0 96 64 255
32 96 64 255
64 96 64 255
96 96 64 255
128 96 64 255
160 96 64 255
192 96 64 255
224 96 64 255
0 128 64 255
32 128 64 255
64 128 64 255
96 128 64 255
128 128 64 255
160 128 64 255
192 128 64 255
224 128 64 255
0 160 64 255
32 160 64 255
64 160 64 255
96 160 64 255
128 160 64 255
160 160 64 255
192 160 64 255
224 160 64 255
0 192 64 255
32 192 64 255
64 192 64 255
96 192 64 255
128 192 64 255
160 192 64 255
192 192 64 255
224 192 64 255
0 224 64 255
32 224 64 255
64 224 64 255
96 224 64 255
128 224 64 255
160 224 64 255
192 224 64 255
224 224 64 255
0 0 128 255
32 0 128 255
64 0 128 255
96 0 128 255
128 0 128 255
160 0 128 255
192 0 128 255
224 0 128 255
0 32 128 255
32 32 128 255
64 32 128 255
96 32 128 255
128 32 128 255
160 32 128 255
192 32 128 255
224 32 128 255
0 64 128 255
32 64 128 255
64 64 128 255
96 64 128 255
128 64 128 255
160 64 128 255
192 64 128 255
224 64 128 255
0 96 128 255
32 96 128 255
64 96 128 255
96 96 128 255
128 96 128 255
160 96 128 255
192 96 128 255
224 96 128 255
0 128 128 255
32 128 128 255
64 128 128 255
96 128 128 255
128 128 128 255
160 128 128 255
192 128 128 255
224 128 128 255
0 160 128 255
32 160 128 255
64 160 128 255
96 160 128 255
128 160 128 255
160 160 128 255
192 160 128 255
224 160 128 255
0 192 128 255
32 192 128 255
64 192 128 255
96 192 128 255
128 192 128 255
160 192 128 255
192 192 128 255
224 192 128 255
0 224 128 255
32 224 128 255
64 224 128 255
96 224 128 255
128 224 128 255
160 224 128 255
192 224 128 255
224 224 128 255
0 0 192 255
32 0 192 255
64 0 192 255
96 0 192 255
128 0 192 255
160 0 192 255
192 0 192 255
224 0 192 255
0 32 192 255
32 32 192 255
64 32 192 255
96 32 192 255
128 32 192 255
160 32 192 255
192 32 192 255
224 32 192 255
0 64 192 255
32 64 192 255
64 64 192 255
96 64 192 255
128 64 192 255
160 64 192 255
192 64 192 255
224 64 192 255
0 96 192 255
32 96 192 255
64 96 192 255
96 96 192 255
128 96 192 255
160 96 192 255
192 96 192 255
224 96 192 255
0 128 192 255
32 128 192 255
64 128 192 255
96 128 192 255
128 128 192 255
160 128 192 255
192 128 192 255
224 128 192 255
0 160 192 255
32 160 192 255
64 160 192 255
96 160 192 255
128 160 192 255
160 160 192 255
192 160 192 255
224 160 192 255
0 192 192 255
32 192 192 255
64 192 192 255
96 192 192 255
128 192 192 255
160 192 192 255
192 192 192 255
224 192 192 255
0 224 192 255
32 224 192 255
64 224 192 255
96 224 192 255
128 224 192 255
160 224 192 255
192 224 192 255
224 224 192 255

View file

@ -43,6 +43,14 @@ void SLK_pal_sprite_save(const char *path, const SLK_Pal_sprite *s);
void SLK_pal_sprite_copy(SLK_Pal_sprite *dst, const SLK_Pal_sprite *src);
void SLK_pal_sprite_copy_partial(SLK_Pal_sprite *dst, const SLK_Pal_sprite *src, int x, int y, int ox, int oy, int width, int height);
//Pal sprite sheet subsystem: SLK_sheet_pal.c
SLK_Pal_sheet *SLK_pal_sheet_create(int size);
void SLK_pal_sheet_expand(SLK_Pal_sheet *sheet, int new_size);
void SLK_pal_sheet_destroy(SLK_Pal_sheet *sheet);
void SLK_pal_sheet_add(SLK_Pal_sheet *sheet, int index, SLK_Pal_sprite *sprite);
void SLK_pal_seet_add_from(SLK_Pal_sheet *sheet, int index, SLK_Pal_sprite *source, int x, int y, int width, int height);
SLK_Pal_sprite *SLK_pal_sheet_get(const SLK_Pal_sheet *sheet, int index);
//Draw pal subsystem: SLK_draw_pal.c
void SLK_draw_pal_set_target(SLK_Pal_sprite *s);
SLK_Pal_sprite *SLK_draw_pal_get_target();
@ -71,6 +79,14 @@ void SLK_rgb_sprite_save(const char *path, const SLK_RGB_sprite *s);
void SLK_rgb_sprite_copy(SLK_RGB_sprite *dst, const SLK_RGB_sprite *src);
void SLK_rgb_sprite_copy_partial(SLK_RGB_sprite *dst, const SLK_RGB_sprite *src, int x, int y, int ox, int oy, int width, int height);
//RGB sprite sheet subsystem: SLK_sheet_rgb.c
SLK_RGB_sheet *SLK_rgb_sheet_create(int size);
void SLK_rgb_sheet_expand(SLK_RGB_sheet *sheet, int new_size);
void SLK_rgb_sheet_destroy(SLK_RGB_sheet *sheet);
void SLK_rgb_sheet_add(SLK_RGB_sheet *sheet, int index, SLK_RGB_sprite *sprite);
void SLK_rgb_seet_add_from(SLK_RGB_sheet *sheet, int index, SLK_RGB_sprite *source, int x, int y, int width, int height);
SLK_RGB_sprite *SLK_rgb_sheet_get(const SLK_RGB_sheet *sheet, int index);
//Draw rgb subsystem: SLK_draw_rgb.c
SLK_RGB_sprite *SLK_draw_rgb_get_target();
void SLK_draw_rgb_set_target(SLK_RGB_sprite *s);
@ -106,6 +122,8 @@ void SLK_mouse_get_pos(int *x, int *y);
void SLK_mouse_get_relative_pos(int *x, int *y);
void SLK_mouse_get_layer_pos(unsigned index, int *x, int *y);
void SLK_mouse_show_cursor(int shown);
void SLK_mouse_set_relative(int relative);
void SLK_mouse_capture(int capture);
void SLK_text_input_start(char *text);
void SLK_text_input_stop();
@ -118,7 +136,10 @@ void SLK_layer_set_dynamic(unsigned index, int dynamic);
void SLK_layer_set_pos(unsigned index, int x, int y);
void SLK_layer_set_scale(unsigned index, float scale);
void SLK_layer_set_size(unsigned index, int width, int height);
void SLK_layer_get_size(unsigned index, int *width, int *height);
void SLK_layer_set_current(unsigned index);
int SLK_layer_get_resized(unsigned index);
SLK_Layer *SLK_layer_get(unsigned index);
//Core subsystem: SLK_core.c
void SLK_setup(int width, int height, int layer_num, const char *title, int fullscreen, int scale, int resizable);

View file

@ -64,8 +64,20 @@ typedef struct
typedef struct
{
GLint id;
}SLK_GPU_sprite;
int size;
SLK_RGB_sprite **sheet;
}SLK_RGB_sheet;
typedef struct
{
int size;
SLK_Pal_sprite **sheet;
}SLK_Pal_sheet;
typedef struct
{
}SLK_RGB_animation;
typedef struct
{
@ -81,16 +93,12 @@ typedef struct
GLuint texture;
}SLK_Layer_rgb;
typedef struct
{
}SLK_Layer_gpu;
typedef struct
{
int type;
int active;
int dynamic;
int resized;
int x;
int y;
float scale;
@ -100,7 +108,6 @@ typedef struct
{
SLK_Layer_pal type_0;
SLK_Layer_rgb type_1;
SLK_Layer_gpu type_2;
};
}SLK_Layer;

View file

@ -1,41 +1,51 @@
libSLK.a: glad.o SLK_core.o SLK_color.o SLK_draw_pal.o SLK_draw_rgb.o SLK_input.o SLK_layer.o SLK_palette.o SLK_render.o SLK_sprite_pal.o SLK_sprite_rgb.o SLK_timer.o
CC = gcc
CFLAGS+=-lm -lSDL2 -lGL -Wall
//CFLAGS+=-lm -lSDL2 -lGL -Wall -pg
libSLK.a: glad.o SLK_core.o SLK_color.o SLK_draw_pal.o SLK_draw_rgb.o SLK_input.o SLK_layer.o SLK_palette.o SLK_render.o SLK_sprite_pal.o SLK_sprite_rgb.o SLK_timer.o SLK_sheet_rgb.o SLK_sheet_pal.o
ar cr libSLK.a $^
glad.o: ../src/glad/glad.c ../include/glad/glad.h
gcc -O3 -c $< -lm -ldl -lGL -Wall
$(CC) -O3 -c $< $(CFLAGS)
SLK_core.o: ../src/SLK/SLK_core.c ../include/SLK/SLK_types.h ../include/SLK/SLK_functions.h ../src/SLK/SLK_input_i.h ../src/SLK/SLK_render_i.h ../src/SLK/SLK_draw_rgb_i.h ../src/SLK/SLK_draw_pal_i.h ../src/SLK/SLK_layer_i.h
gcc -O3 -c $< -lm -lSDL2 -ldl -lGL -Wall
$(CC) -O3 -c $< $(CFLAGS)
SLK_color.o: ../src/SLK/SLK_color.c ../include/SLK/SLK_functions.h ../include/SLK/SLK_types.h
gcc -O3 -c $< -lm -lSDL2 -ldl -lGL -Wall
$(CC) -O3 -c $< $(CFLAGS)
SLK_draw_pal.o: ../src/SLK/SLK_draw_pal.c ../include/SLK/SLK_functions.h ../include/SLK/SLK_types.h ../src/SLK/SLK_draw_pal_i.h
gcc -O3 -c $< -lm -lSDL2 -ldl -lGL -Wall
$(CC) -O3 -c $< $(CFLAGS)
SLK_draw_rgb.o: ../src/SLK/SLK_draw_rgb.c ../include/SLK/SLK_functions.h ../include/SLK/SLK_types.h ../src/SLK/SLK_draw_rgb_i.h
gcc -O3 -c $< -lm -lSDL2 -ldl -lGL -Wall
$(CC) -O3 -c $< $(CFLAGS)
SLK_input.o: ../src/SLK/SLK_input.c ../include/SLK/SLK_types.h ../src/SLK/SLK_input_i.h ../src/SLK/SLK_render_i.h ../src/SLK/SLK_layer_i.h
gcc -O3 -c $< -lm -lSDL2 -ldl -lGL -Wall
$(CC) -O3 -c $< $(CFLAGS)
SLK_layer.o: ../src/SLK/SLK_layer.c ../include/glad/glad.h ../include/SLK/SLK_types.h ../include/SLK/SLK_functions.h ../src/SLK/SLK_render_i.h ../src/SLK/SLK_draw_rgb_i.h ../src/SLK/SLK_draw_pal_i.h ../src/SLK/SLK_layer_i.h
gcc -O3 -c $< -lm -lSDL2 -ldl -lGL -Wall
$(CC) -O3 -c $< $(CFLAGS)
SLK_palette.o: ../src/SLK/SLK_palette.c ../include/SLK/SLK_types.h ../include/SLK/SLK_functions.h
gcc -O3 -c $< -lm -lSDL2 -ldl -lGL -Wall
$(CC) -O3 -c $< $(CFLAGS)
SLK_render.o: ../src/SLK/SLK_render.c ../include/glad/glad.h ../include/SLK/SLK_types.h ../include/SLK/SLK_functions.h ../src/SLK/SLK_render_i.h ../src/SLK/SLK_layer_i.h
gcc -O3 -c $< -lm -lSDL2 -ldl -lGL -Wall
$(CC) -O3 -c $< $(CFLAGS)
SLK_sprite_pal.o: ../src/SLK/SLK_sprite_pal.c ../include/SLK/SLK_types.h ../include/SLK/SLK_functions.h
gcc -O3 -c $< -lm -lSDL2 -ldl -lGL -Wall
$(CC) -O3 -c $< $(CFLAGS)
SLK_sprite_rgb.o: ../src/SLK/SLK_sprite_rgb.c ../include/SLK/SLK_types.h ../include/SLK/SLK_functions.h
gcc -O3 -c $< -lm -lSDL2 -ldl -lGL -Wall
SLK_sprite_rgb.o: ../src/SLK/SLK_sprite_rgb.c ../include/SLK/SLK_types.h ../include/SLK/SLK_functions.h
$(CC) -O3 -c $< $(CFLAGS)
SLK_timer.o: ../src/SLK/SLK_timer.c ../include/SLK/SLK_functions.h
gcc -O3 -c $< -lm -lSDL2 -ldl -lGL -Wall
SLK_timer.o: ../src/SLK/SLK_timer.c ../include/SLK/SLK_functions.h
$(CC) -O3 -c $< $(CFLAGS)
SLK_sheet_rgb.o: ../src/SLK/SLK_sheet_rgb.c ../include/SLK/SLK_functions.h ../include/SLK/SLK_types.h
$(CC) -O3 -c $< $(CFLAGS)
SLK_sheet_pal.o: ../src/SLK/SLK_sheet_pal.c ../include/SLK/SLK_functions.h ../include/SLK/SLK_types.h
$(CC) -O3 -c $< $(CFLAGS)
clean:
rm -f *.o *.a

View file

@ -123,6 +123,9 @@ void SLK_update()
memcpy(old_key_state,new_key_state,sizeof(new_key_state));
memcpy(old_mouse_state,new_mouse_state,sizeof(new_mouse_state));
mouse_x_rel = 0;
mouse_y_rel = 0;
//Event managing
SDL_Event event;
while(SDL_PollEvent(&event))
@ -158,6 +161,10 @@ void SLK_update()
case SDL_MOUSEWHEEL:
SLK_i_mouse_update_wheel(event.wheel.y);
break;
case SDL_MOUSEMOTION:
mouse_x_rel+=event.motion.xrel;
mouse_y_rel+=event.motion.yrel;
break;
case SDL_WINDOWEVENT:
if(event.window.event==SDL_WINDOWEVENT_RESIZED&&dynamic)
{
@ -259,5 +266,5 @@ void SLK_setup(int width, int height, int layer_num, const char *title, int full
text_sprite_rgb = SLK_rgb_sprite_load("data/font8x8.png");
SLK_i_input_init();
}
}
//-------------------------------------

View file

@ -33,8 +33,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
//Variables
int mouse_x;
int mouse_y;
int mouse_x_rel;
int mouse_y_rel;
int mouse_wheel;
//-------------------------------------
@ -134,15 +132,15 @@ void SLK_mouse_get_layer_pos(unsigned index, int *x, int *y)
//Used in SLK_update, no need to call yourself.
void SLK_i_mouse_update(int x, int y)
{
int mouse_x_cache = mouse_x;
int mouse_y_cache = mouse_y;
//int mouse_x_cache = mouse_x;
//int mouse_y_cache = mouse_y;
x-=view_x;
y-=view_y;
mouse_x = (int)(((float)x/(float)(window_width-(view_x*2))*(float)screen_width));
mouse_y = (int)(((float)y/(float)(window_height-(view_y*2))*(float)screen_height));
mouse_x_rel = mouse_x-mouse_x_cache;
mouse_y_rel = mouse_y-mouse_y_cache;
//mouse_x_rel = mouse_x-mouse_x_cache;
//mouse_y_rel = mouse_y-mouse_y_cache;
if(mouse_x>=screen_width)
mouse_x= screen_width-1;
@ -168,6 +166,19 @@ void SLK_mouse_show_cursor(int shown)
SDL_ShowCursor(shown?SDL_ENABLE:SDL_DISABLE);
}
//Sets wether the mouse cursor is captured and only relative
//mouse motion is registerd.
void SLK_mouse_set_relative(int relative)
{
SDL_SetRelativeMouseMode(relative);
}
//Sets wether to capture mouse events globally.
void SLK_mouse_capture(int capture)
{
SDL_CaptureMouse(capture);
}
//Starts text ínput and appends the characters
//to the provided char pointer.
//Note: SoftLK does not allocate new memory,
@ -292,7 +303,8 @@ void SLK_i_input_init()
//Clear key states, just in case,
//should already be empty since known at compile time
memset(new_key_state,0,sizeof(new_key_state));
memset(old_key_state,0,sizeof(old_key_state));
memset(new_mouse_state,0,sizeof(new_mouse_state));
memset(old_mouse_state,0,sizeof(old_mouse_state));
}
//-------------------------------------

View file

@ -11,6 +11,8 @@ uint8_t new_mouse_state[6];
uint8_t old_mouse_state[6];
uint8_t key_map[SDL_NUM_SCANCODES];
uint8_t mouse_map[6];
int mouse_x_rel;
int mouse_y_rel;
char *text_input;
int text_input_active;

View file

@ -156,6 +156,8 @@ void SLK_layer_set_size(unsigned index, int width, int height)
{
if(index<layer_count)
{
layers[index].resized = 1;
if(layers[index].type==SLK_LAYER_PAL)
{
if(layers[index].type_0.target==NULL||layers[index].type_0.render==NULL)
@ -193,6 +195,28 @@ void SLK_layer_set_size(unsigned index, int width, int height)
}
}
//Stores the dimensions of the specified layer in the specified pointers.
void SLK_layer_get_size(unsigned index, int *width, int *height)
{
if(index>=layer_count)
return;
if(layers[index].type==SLK_LAYER_RGB)
{
if(width)
*width = layers[index].type_1.target->width;
if(height)
*height = layers[index].type_1.target->height;
}
else if(layers[index].type==SLK_LAYER_PAL)
{
if(width)
*width = layers[index].type_0.target->width;
if(height)
*height = layers[index].type_0.target->height;
}
}
//Sets wich layer is the current default draw target.
//Also overwrites the current draw target.
void SLK_layer_set_current(unsigned index)
@ -213,4 +237,24 @@ void SLK_layer_set_current(unsigned index)
target_rgb = layers[index].type_1.target;
}
}
//Returns wether the layer has been resized.
//A layer counts as resized between a SLK_layer_set_size call and a SLK_render_update call.
int SLK_layer_get_resized(unsigned index)
{
if(index>=layer_count)
return 0;
return layers[index].resized;
}
//Returns the specified layer if it
//exists.
SLK_Layer *SLK_layer_get(unsigned index)
{
if(index>=layer_count)
return NULL;
return &layers[index];
}
//-------------------------------------

View file

@ -73,6 +73,8 @@ void SLK_render_update()
for(int l = layer_count-1;l>=0;l--)
{
layers[l].resized = 0;
if(layers[l].active)
{
switch(layers[l].type)

124
src/SLK/SLK_sheet_pal.c Normal file
View file

@ -0,0 +1,124 @@
/*
Copyright (c) 2020, Lukas Holzbeierlein (Captain4LK)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
//External includes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//-------------------------------------
//Internal includes
#include "../../include/SLK/SLK_types.h"
#include "../../include/SLK/SLK_functions.h"
//-------------------------------------
//#defines
//-------------------------------------
//Typedefs
//-------------------------------------
//Variables
//-------------------------------------
//Function prototypes
//-------------------------------------
//Creates a sprite sheet with the specified storage size and
//returns a pointer to it.
SLK_Pal_sheet *SLK_pal_sheet_create(int size)
{
SLK_Pal_sheet *sheet = malloc(sizeof(SLK_Pal_sheet));
memset(sheet,0,sizeof(SLK_Pal_sheet));
sheet->size = size;
sheet->sheet = malloc(sizeof(SLK_Pal_sprite *)*size);
return sheet;
}
//Expands (or shrinks) the size of a sprite sheet.
void SLK_pal_sheet_expand(SLK_Pal_sheet *sheet, int new_size)
{
int old_size = sheet->size;
if(old_size<new_size)
{
for(int i = new_size;i<sheet->size;i++)
SLK_pal_sprite_destroy(sheet->sheet[i]);
}
sheet->size = new_size;
sheet->sheet = realloc(sheet->sheet,sizeof(SLK_Pal_sprite *)*new_size);
if(old_size<new_size)
memset(sheet->sheet+old_size,0,sizeof(SLK_Pal_sprite *)*(new_size-old_size));
}
//Destroys a sprite sheet.
void SLK_pal_sheet_destroy(SLK_Pal_sheet *sheet)
{
for(int i = 0;i<sheet->size;i++)
SLK_pal_sprite_destroy(sheet->sheet[i]);
free(sheet->sheet);
free(sheet);
}
//Copies a sprite to the specified
//sprite sheet and index.
void SLK_pal_sheet_add(SLK_Pal_sheet *sheet, int index, SLK_Pal_sprite *sprite)
{
if(index<0||index>sheet->size-1)
{
printf("Error sprite sheet index out of bounds\n");
return;
}
if(sheet->sheet[index]!=NULL)
SLK_pal_sprite_destroy(sheet->sheet[index]);
sheet->sheet[index] = SLK_pal_sprite_create(sprite->width,sprite->height);
SLK_pal_sprite_copy(sheet->sheet[index],sprite);
}
//Copies a sprite from a specified image part
//to the sprite sheet.
void SLK_pal_seet_add_from(SLK_Pal_sheet *sheet, int index, SLK_Pal_sprite *source, int x, int y, int width, int height)
{
if(index<0||index>sheet->size-1)
{
printf("Error sprite sheet index out of bounds\n");
return;
}
if(source==NULL)
{
printf("Error: no source specified\n");
return;
}
if(sheet->sheet[index]!=NULL)
SLK_pal_sprite_destroy(sheet->sheet[index]);
sheet->sheet[index] = SLK_pal_sprite_create(width,height);
SLK_pal_sprite_copy_partial(sheet->sheet[index],source,0,0,x,y,width,height);
}
//Returns the sprite at the specified sprite sheet index.
SLK_Pal_sprite *SLK_pal_sheet_get(const SLK_Pal_sheet *sheet, int index)
{
if(index<0||index>sheet->size-1)
{
printf("Error sprite sheet index out of bounds\n");
return NULL;
}
return sheet->sheet[index];
}
//-------------------------------------

125
src/SLK/SLK_sheet_rgb.c Normal file
View file

@ -0,0 +1,125 @@
/*
Copyright (c) 2020, Lukas Holzbeierlein (Captain4LK)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
//External includes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//-------------------------------------
//Internal includes
#include "../../include/SLK/SLK_types.h"
#include "../../include/SLK/SLK_functions.h"
//-------------------------------------
//#defines
//-------------------------------------
//Typedefs
//-------------------------------------
//Variables
//-------------------------------------
//Function prototypes
//-------------------------------------
//Function implementations
//Creates a sprite sheet with the specified storage size and
//returns a pointer to it.
SLK_RGB_sheet *SLK_rgb_sheet_create(int size)
{
SLK_RGB_sheet *sheet = malloc(sizeof(SLK_RGB_sheet));
memset(sheet,0,sizeof(SLK_RGB_sheet));
sheet->size = size;
sheet->sheet = malloc(sizeof(SLK_RGB_sprite *)*size);
return sheet;
}
//Expands (or shrinks) the size of a sprite sheet.
void SLK_rgb_sheet_expand(SLK_RGB_sheet *sheet, int new_size)
{
int old_size = sheet->size;
if(old_size<new_size)
{
for(int i = new_size;i<sheet->size;i++)
SLK_rgb_sprite_destroy(sheet->sheet[i]);
}
sheet->size = new_size;
sheet->sheet = realloc(sheet->sheet,sizeof(SLK_RGB_sprite *)*new_size);
if(old_size<new_size)
memset(sheet->sheet+old_size,0,sizeof(SLK_RGB_sprite *)*(new_size-old_size));
}
//Destroys a sprite sheet.
void SLK_rgb_sheet_destroy(SLK_RGB_sheet *sheet)
{
for(int i = 0;i<sheet->size;i++)
SLK_rgb_sprite_destroy(sheet->sheet[i]);
free(sheet->sheet);
free(sheet);
}
//Copies a sprite to the specified
//sprite sheet and index.
void SLK_rgb_sheet_add(SLK_RGB_sheet *sheet, int index, SLK_RGB_sprite *sprite)
{
if(index<0||index>sheet->size-1)
{
printf("Error sprite sheet index out of bounds\n");
return;
}
if(sheet->sheet[index]!=NULL)
SLK_rgb_sprite_destroy(sheet->sheet[index]);
sheet->sheet[index] = SLK_rgb_sprite_create(sprite->width,sprite->height);
SLK_rgb_sprite_copy(sheet->sheet[index],sprite);
}
//Copies a sprite from a specified image part
//to the sprite sheet.
void SLK_rgb_seet_add_from(SLK_RGB_sheet *sheet, int index, SLK_RGB_sprite *source, int x, int y, int width, int height)
{
if(index<0||index>sheet->size-1)
{
printf("Error sprite sheet index out of bounds\n");
return;
}
if(source==NULL)
{
printf("Error: no source specified\n");
return;
}
if(sheet->sheet[index]!=NULL)
SLK_rgb_sprite_destroy(sheet->sheet[index]);
sheet->sheet[index] = SLK_rgb_sprite_create(width,height);
SLK_rgb_sprite_copy_partial(sheet->sheet[index],source,0,0,x,y,width,height);
}
//Returns the sprite at the specified sprite sheet index.
SLK_RGB_sprite *SLK_rgb_sheet_get(const SLK_RGB_sheet *sheet, int index)
{
if(index<0||index>sheet->size-1)
{
printf("Error sprite sheet index out of bounds\n");
return NULL;
}
return sheet->sheet[index];
}
//-------------------------------------