More features

Added SLK_layer_set_tint
Added SLK_core_set_title
Added SLK_core_set_fullscreen
Added SLK_core_set_icon
This commit is contained in:
Captain4LK 2020-04-25 17:52:18 +02:00
parent 375ca2e372
commit 577147ffe0
8 changed files with 71 additions and 19 deletions

View file

@ -24,6 +24,7 @@ SLK_RGB_sprite *gui_01;
int frame = 0; int frame = 0;
char time_stat[48]; char time_stat[48];
int render_mode = 0; int render_mode = 0;
int fullscreen = 0;
void add_entity(); void add_entity();
void load_pal_sprites(); void load_pal_sprites();
@ -49,6 +50,9 @@ int main(int argc, char *argv[])
SLK_layer_set_current(0); SLK_layer_set_current(0);
SLK_layer_set_current(1); SLK_layer_set_current(1);
SLK_layer_set_tint(1,SLK_color_create(255,255,255,128));
SLK_layer_set_tint(2,SLK_color_create(255,255,255,128));
SLK_draw_pal_set_clear_paxel(SLK_color_create_paxel(0,SLK_TRANSPARENT)); SLK_draw_pal_set_clear_paxel(SLK_color_create_paxel(0,SLK_TRANSPARENT));
SLK_draw_pal_clear(); SLK_draw_pal_clear();
SLK_draw_rgb_set_clear_color(SLK_color_create(255,255,255,0)); SLK_draw_rgb_set_clear_color(SLK_color_create(255,255,255,0));
@ -147,6 +151,11 @@ int main(int argc, char *argv[])
SLK_draw_rgb_sprite(gui_01,206,2); SLK_draw_rgb_sprite(gui_01,206,2);
SLK_draw_rgb_string(214,10,1,"rgb renderer",SLK_color_create(255,255,255,255)); SLK_draw_rgb_string(214,10,1,"rgb renderer",SLK_color_create(255,255,255,255));
} }
if(SLK_key_pressed(SLK_KEY_F))
{
fullscreen = !fullscreen;
SLK_core_set_fullscreen(fullscreen);
}
SLK_layer_set_current(0); SLK_layer_set_current(0);

View file

@ -102,6 +102,7 @@ int SLK_mouse_down(const int key);
int SLK_mouse_pressed(const int key); int SLK_mouse_pressed(const int key);
int SLK_mouse_released(const int key); int SLK_mouse_released(const int key);
void SLK_mouse_get_pos(int *x, int *y); void SLK_mouse_get_pos(int *x, int *y);
void SLK_mouse_show_cursor(int shown);
void SLK_text_input_start(char *text); void SLK_text_input_start(char *text);
void SLK_text_input_stop(); void SLK_text_input_stop();
@ -109,15 +110,17 @@ void SLK_text_input_stop();
void SLK_layer_create(const unsigned index, const int type); void SLK_layer_create(const unsigned index, const int type);
void SLK_layer_activate(const unsigned index, const int active); void SLK_layer_activate(const unsigned index, const int active);
void SLK_layer_set_palette(const unsigned index, SLK_Palette *pal); void SLK_layer_set_palette(const unsigned index, SLK_Palette *pal);
void SLK_layer_set_tint(unsigned index, SLK_Color tint);
void SLK_layer_set_current(const unsigned index); void SLK_layer_set_current(const unsigned index);
//Core subsystem: SLK_core.c //Core subsystem: SLK_core.c
void SLK_setup(const int width, const int height, const int layer_num, const char *title, const int fullscreen, int pixel_scale); void SLK_setup(const int width, const int height, const int layer_num, const char *title, const int fullscreen, int scale);
void SLK_end(); void SLK_core_set_title(const char *title);
void SLK_core_set_fullscreen(int fullscreen);
void SLK_core_set_icon(const SLK_RGB_sprite *icon);
void SLK_update(); void SLK_update();
void SLK_update_viewport(); void SLK_update_viewport();
void SLK_update_mouse(int x, int y); void SLK_update_mouse(int x, int y);
void SLK_show_cursor(int shown);
int SLK_running(); int SLK_running();
void SLK_quit(); void SLK_quit();

View file

@ -95,6 +95,7 @@ typedef struct
{ {
int type; int type;
int active; int active;
SLK_Color tint;
union union
{ {

View file

@ -31,9 +31,35 @@ int SLK_running()
return running; return running;
} }
void SLK_show_cursor(int shown)
void SLK_core_set_title(const char *title)
{ {
SDL_ShowCursor(shown?SDL_ENABLE:SDL_DISABLE); SDL_SetWindowTitle(sdl_window,title);
}
void SLK_core_set_fullscreen(int fullscreen)
{
if(fullscreen)
{
SDL_SetWindowFullscreen(sdl_window,SDL_WINDOW_FULLSCREEN_DESKTOP);
}
else
{
SDL_SetWindowFullscreen(sdl_window,0);
SDL_SetWindowSize(sdl_window,screen_width*pixel_scale,screen_height*pixel_scale);
}
SDL_GetWindowSize(sdl_window,&window_width,&window_height);
SLK_update_viewport();
}
void SLK_core_set_icon(const SLK_RGB_sprite *icon)
{
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(icon->data,icon->width,icon->height,32,icon->width*4,0xf000,0x0f00,0x00f0,0x000f);
SDL_SetWindowIcon(sdl_window,surface);
SDL_FreeSurface(surface);
} }
void SLK_update() void SLK_update()
@ -126,17 +152,20 @@ void SLK_update()
void SLK_update_viewport() void SLK_update_viewport()
{ {
if (view_height<window_height) view_width = screen_width*pixel_scale;
view_height = screen_height*pixel_scale;
if(view_height<window_height)
{ {
int pixel_scale = window_height/screen_height; int p_scale = window_height/screen_height;
view_width = screen_width*pixel_scale; view_width = screen_width*p_scale;
view_height = screen_height*pixel_scale; view_height = screen_height*p_scale;
} }
else else
{ {
int pixel_scale = window_width/screen_width; int p_scale = window_width/screen_width;
view_width = screen_width*pixel_scale; view_width = screen_width*p_scale;
view_height = screen_height*pixel_scale; view_height = screen_height*p_scale;
} }
view_x = (window_width-view_width)/2; view_x = (window_width-view_width)/2;
@ -162,8 +191,9 @@ void SLK_update_mouse(int x, int y)
mouse_y_cache = 1; mouse_y_cache = 1;
} }
void SLK_setup(const int width, const int height, const int layer_num, const char *title, const int fullscreen, int pixel_scale) void SLK_setup(const int width, const int height, const int layer_num, const char *title, const int fullscreen, int scale)
{ {
pixel_scale = scale;
screen_width = width; screen_width = width;
screen_height = height; screen_height = height;
layer_count = layer_num; layer_count = layer_num;
@ -176,6 +206,7 @@ void SLK_setup(const int width, const int height, const int layer_num, const cha
exit(-1); exit(-1);
} }
if(pixel_scale==SLK_WINDOW_MAX) if(pixel_scale==SLK_WINDOW_MAX)
{ {
SDL_Rect max_size; SDL_Rect max_size;
@ -327,9 +358,3 @@ void SLK_setup(const int width, const int height, const int layer_num, const cha
memset(new_key_state,0,sizeof(new_key_state)); memset(new_key_state,0,sizeof(new_key_state));
memset(new_mouse_state,0,sizeof(new_mouse_state)); memset(new_mouse_state,0,sizeof(new_mouse_state));
} }
void SLK_end()
{
}

View file

@ -57,6 +57,11 @@ void SLK_mouse_get_pos(int *x, int *y)
*y = mouse_y_cache; *y = mouse_y_cache;
} }
void SLK_mouse_show_cursor(int shown)
{
SDL_ShowCursor(shown?SDL_ENABLE:SDL_DISABLE);
}
void SLK_text_input_start(char *text) void SLK_text_input_start(char *text)
{ {
text_input = text; text_input = text;

View file

@ -28,6 +28,7 @@ void SLK_layer_create(const unsigned index, const int type)
layers[index].type = type; layers[index].type = type;
layers[index].active = 1; layers[index].active = 1;
layers[index].tint = SLK_color_create(255,255,255,255);
switch(type) switch(type)
{ {
@ -79,6 +80,11 @@ void SLK_layer_set_palette(const unsigned index, SLK_Palette *pal)
layers[index].type_0.palette = pal; layers[index].type_0.palette = pal;
} }
void SLK_layer_set_tint(unsigned index, SLK_Color tint)
{
layers[index].tint = tint;
}
void SLK_layer_set_current(const unsigned index) void SLK_layer_set_current(const unsigned index)
{ {
if(index>=layer_count) if(index>=layer_count)

View file

@ -60,6 +60,7 @@ void SLK_render_update()
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,screen_width,screen_height,0,GL_RGBA,GL_UNSIGNED_BYTE,layers[l].type_0.render->data); glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,screen_width,screen_height,0,GL_RGBA,GL_UNSIGNED_BYTE,layers[l].type_0.render->data);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor4ub(layers[l].tint.r,layers[l].tint.g,layers[l].tint.b,layers[l].tint.a);
glTexCoord2f(0.0, 1.0); glTexCoord2f(0.0, 1.0);
glVertex3f(-1.0f,-1.0f,0.0f); glVertex3f(-1.0f,-1.0f,0.0f);
glTexCoord2f(0.0, 0.0); glTexCoord2f(0.0, 0.0);
@ -76,6 +77,7 @@ void SLK_render_update()
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,screen_width,screen_height,0,GL_RGBA,GL_UNSIGNED_BYTE,layers[l].type_1.target->data); glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,screen_width,screen_height,0,GL_RGBA,GL_UNSIGNED_BYTE,layers[l].type_1.target->data);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor4ub(layers[l].tint.r,layers[l].tint.g,layers[l].tint.b,layers[l].tint.a);
glTexCoord2f(0.0, 1.0); glTexCoord2f(0.0, 1.0);
glVertex3f(-1.0f,-1.0f,0.0f); glVertex3f(-1.0f,-1.0f,0.0f);
glTexCoord2f(0.0, 0.0); glTexCoord2f(0.0, 0.0);

View file

@ -36,6 +36,7 @@ SLK_RGB_sprite *text_sprite_rgb;
int screen_width; int screen_width;
int screen_height; int screen_height;
int pixel_scale;
int window_width; int window_width;
int window_height; int window_height;
int view_x; int view_x;