Commit 7177c574 authored by Denis Marion's avatar Denis Marion
Browse files

* clip_surface now takes a box as argument

* show voice names and mute indicator
* show help for controls (core option)
parent 9024bd26
Pipeline #95301 failed with stages
in 1 minute and 9 seconds
......@@ -54,22 +54,22 @@ void free_surface(surface *surf)
}
}
surface *clip_surface(surface *src_surf, int x_src, int y_src, int x0, int y0, int x1, int y1)
surface *clip_surface(surface *src_surf, int x_src, int y_src, box clip_box)
{
int wx0,wy0,wx1,wy1; //world coord
int lx,ly,lw,lh; //local coord
surface *clipped_surf = NULL;
//check if completely out of bounds
if( (x_src+src_surf->width) <x0
|| (x_src > x1)
|| (y_src+src_surf->height) < y0
|| (y_src > y1))
if( (x_src+src_surf->width) <clip_box.x0
|| (x_src > clip_box.x1)
|| (y_src+src_surf->height) < clip_box.y0
|| (y_src > clip_box.y1))
return clipped_surf;
wx0 = MAX(x_src,x0);
wy0 = MAX(y_src,y0);
wx1 = MIN(x_src+src_surf->width,x1);
wy1 = MIN(y_src+src_surf->height,y1);
wx0 = MAX(x_src,clip_box.x0);
wy0 = MAX(y_src,clip_box.y0);
wx1 = MIN(x_src+src_surf->width,clip_box.x1);
wy1 = MIN(y_src+src_surf->height,clip_box.y1);
lx = wx0 - x_src;
ly = wy0 - y_src;
lw = wx1 - wx0;
......@@ -159,7 +159,7 @@ void draw_letter(surface *surf, unsigned short color, char letter, int pos_x, in
}
}
void draw_string(surface *surf, unsigned short color, char* text, int pos_x, int pos_y, unsigned int framecounter)
void draw_string(surface *surf, unsigned short color, char* text, int pos_x, int pos_y, unsigned int framecounter, box clip_box)
{
int x;
int x_offset = 0;
......@@ -185,7 +185,7 @@ void draw_string(surface *surf, unsigned short color, char* text, int pos_x, int
x_offset = MIN(x_offset,delta); //clamp right to add delay
}
clipped_surface = clip_surface(temp_surface,pos_x-x_offset,pos_y,21,21,(surf->width-21),(surf->height-21));
clipped_surface = clip_surface(temp_surface,pos_x-x_offset,pos_y, clip_box);
if(clipped_surface)
{
copy_surface(clipped_surface,surf,0,0,pos_x,pos_y,clipped_surface->width,clipped_surface->height);
......
......@@ -39,12 +39,13 @@ bool is_font_pixel(unsigned char letter, int x, int y);
unsigned short get_color(char r, char g, char b);
surface *create_surface(unsigned int width, unsigned int height, unsigned int bpp);
void free_surface(surface *surf);
surface *clip_surface(surface *src_surf, int x_src, int y_src, box clip_box);
void copy_surface(surface *src_surf, surface *dst_surf, int x_src, int y_src, int x_dst, int y_dst, int w, int h);
void draw_line(surface *surf, unsigned short color, int start_x, int start_y, int end_x, int end_y);
void draw_box(surface *surf, unsigned short color, box b);
void draw_shape(surface *surf, unsigned short color, int pos_x, int pos_y, int w, int h);
void draw_letter(surface *surf, unsigned short color, char letter, int pos_x, int pos_y);
void draw_string(surface *surf, unsigned short color, char* text, int pos_x, int pos_y, unsigned int framecounter);
void draw_string(surface *surf, unsigned short color, char* text, int pos_x, int pos_y, unsigned int framecounter, box clip_box);
int get_string_length(char* text);
#endif
......@@ -14,7 +14,8 @@ static surface *framebuffer = NULL;
static uint16_t previnput = 0;
static float last_aspect = 0.0f;
static float last_scale = 0.0f;
static bool display_rainbow;
static int selected_voice = 0;
static bool show_help = true;
// Callbacks
retro_log_printf_t log_cb;
......@@ -43,7 +44,7 @@ void retro_set_environment(retro_environment_t cb)
static const struct retro_variable vars[] = {
{ "gme_aspect", "Aspect Ratio; 16:9|4:3"},
{ "gme_scale", "Scale; 1x|2x"},
{ "display_rainbow", "Display Rainbow Animation; false|true"},
{ "gme_showhelp", "Show Help; true|false"},
{ NULL, NULL},
};
cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars);
......@@ -72,23 +73,21 @@ void retro_cheat_set(unsigned index, bool enabled, const char *code) {}
static int draw_text_centered(char* text,unsigned short color, int y, int maxlen)
{
box clipbox = {21,21,(framebuffer->width-21),(framebuffer->height-21)};
int centerx = framebuffer->width/2;
int msglen = get_string_length(text);
draw_string(framebuffer,color,text,MAX(centerx-(msglen/2),21), y,get_track_elapsed_frames());
draw_string(framebuffer,color,text,MAX(centerx-(msglen/2),21), y,get_track_elapsed_frames(), clipbox);
return MAX(msglen,maxlen);
}
// Custom functions
static void draw_ui(void)
{
int offset;
int maxlen = 0;
int centerx = framebuffer->width/2;
int centery = framebuffer->height/2;
box ob = {5,5,framebuffer->width-5,framebuffer->height-5};
box ib = {20,20,framebuffer->width-20,framebuffer->height-20};
char colorstart = 0;
unsigned short lc = 0;
char *message = malloc(100);
//lines
draw_box(framebuffer,gme_white,ob);
......@@ -97,28 +96,36 @@ static void draw_ui(void)
draw_line(framebuffer,gme_gray,ob.x0,ob.y1,ib.x0,ib.y1); //bottom-left corner
draw_line(framebuffer,gme_gray,ob.x1,ob.y1,ib.x1,ib.y1);
draw_box(framebuffer,gme_gray,ib);
//display rainbow if variable is set
if(display_rainbow)
//voice boxes
int voicenr;
int box_width = ((framebuffer->width - 50)>>2);
int box_height = box_width >> 1;
for(voicenr=0;voicenr<get_num_voices();voicenr++)
{
colorstart = (get_track_elapsed_frames() % 30) >> 2;
for(offset=1;offset<15;offset++)
{
lc = gme_rainbow7[(colorstart + (offset >> 1)) % 7];
draw_line(framebuffer,lc,ob.x0+offset,ob.y0+1+offset,ob.x0+offset,ob.y1-1-offset); //left
draw_line(framebuffer,lc,ob.x0+1+offset,ob.y0+offset,ob.x1-1-offset,ob.y0+offset); //top
draw_line(framebuffer,lc,ob.x1-offset,ob.y0+1+offset,ob.x1-offset,ob.y1-1-offset); //right
draw_line(framebuffer,lc,ob.x0+1+offset,ob.y1-offset,ob.x1-1-offset,ob.y1-offset); //top
}
int box_x = 25+(box_width*(voicenr%4));
int box_y = 22+(box_height*(voicenr>>2));
unsigned short vc = voicenr == selected_voice ? gme_red : gme_white;
box vb = {box_x, box_y, box_x + box_width -1 , box_y + box_height -1};
draw_box(framebuffer,vc,vb);
draw_string(framebuffer,vc, get_voice_name(voicenr),box_x+2, box_y+2, get_track_elapsed_frames(), vb);
if(is_voice_muted(voicenr))
draw_string(framebuffer, gme_red, "muted", box_x+4, box_y+10, get_track_elapsed_frames(), vb);
}
draw_string(framebuffer,gme_white,get_num_voices(message),30, 30,get_track_elapsed_frames());
//text
maxlen = draw_text_centered(get_game_name(message),gme_red,centery-20,maxlen);
maxlen = draw_text_centered(get_track_count(message),gme_yellow,centery-10,maxlen);
maxlen = draw_text_centered(get_song_name(message),gme_blue,centery,maxlen);
maxlen = draw_text_centered(get_author(message),gme_green,centery+10,maxlen);
maxlen = draw_text_centered(get_track_position(message),gme_white,centery+20,maxlen);
if(show_help)
{
box help_box_top = {20,7, framebuffer->width-20, 19};
box help_box_bottom = {20,framebuffer->height-20, framebuffer->width-20, framebuffer->height};
draw_string(framebuffer, gme_white, "Left/Right: Voice A: Mute/Unmute", 22 ,10, get_track_elapsed_frames(),help_box_top);
draw_string(framebuffer, gme_white, "L: Prev R: Next Start: Play/Pause", 22 ,framebuffer->height-18, get_track_elapsed_frames(),help_box_bottom);
}
maxlen = draw_text_centered(get_game_name(message),gme_red,centery,maxlen);
maxlen = draw_text_centered(get_track_count(message),gme_yellow,centery+10,maxlen);
maxlen = draw_text_centered(get_song_name(message),gme_blue,centery+20,maxlen);
maxlen = draw_text_centered(get_author(message),gme_green,centery+30,maxlen);
maxlen = draw_text_centered(get_track_position(message),gme_white,centery+40,maxlen);
maxlen = MIN(maxlen,framebuffer->width-40);
box tb = {centerx-(maxlen/2)-2,centery-22,centerx+(maxlen/2)+2,centery+30};
box tb = {centerx-(maxlen/2)-1,centery-2,centerx+(maxlen/2)+2,centery+50};
draw_box(framebuffer,gme_violet,tb);
free(message);
}
......@@ -173,13 +180,13 @@ void retro_get_system_av_info(struct retro_system_av_info *info)
height = 180 * scale;
}
}
var.key = "display_rainbow";
if(environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
var.key = "gme_showhelp";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if(!strcmp(var.value,"true"))
display_rainbow = true;
else
display_rainbow = false;
if (!strcmp(var.value, "true"))
show_help = true;
else if (!strcmp(var.value, "false"))
show_help = false;
}
int pixel_format = RETRO_PIXEL_FORMAT_RGB565;
memset(info, 0, sizeof(*info));
......@@ -251,6 +258,15 @@ void retro_run(void)
if(input & (1<<RETRO_DEVICE_ID_JOYPAD_START))
play_pause();
if(input & (1<<RETRO_DEVICE_ID_JOYPAD_B))
mute_voice(selected_voice);
if(input & (1<<RETRO_DEVICE_ID_JOYPAD_LEFT))
selected_voice = (selected_voice-1) % get_num_voices();
if(input & (1<<RETRO_DEVICE_ID_JOYPAD_RIGHT))
selected_voice = (selected_voice+1) % get_num_voices();
//graphic handling
memset(framebuffer->pixel_data,0,framebuffer->bytes_per_pixel * framebuffer->width * framebuffer->height);
draw_ui();
......
......@@ -17,6 +17,7 @@ static short audio_buffer[8192];
static bool is_playing_;
static long sample_rate_;
static int current_track;
static unsigned char mute_mask;
bool is_emu_loaded(void)
{
......@@ -48,6 +49,7 @@ void close_file(void)
void start_track(int tracknr)
{
memset(audio_buffer,0,8192 * sizeof(short));
mute_mask = 0;
current_track = tracknr;
track = plist->tracks[tracknr];
if(track)
......@@ -105,6 +107,24 @@ void prev_track(void)
start_track(--current_track);
}
bool is_voice_muted(int index)
{
int bit = 1 << index;
return (mute_mask & bit) != 0;
}
void mute_voice(int index)
{
if(index<gme_voice_count(emu))
{
bool mute = !is_voice_muted(index);
gme_mute_voice(emu,index, mute);
mute_mask |= (1 << index);
if(!mute)
mute_mask ^= (1 << index);
}
}
char *get_game_name(char *buf)
{
sprintf(buf, "%s",track->game_name);
......@@ -129,10 +149,17 @@ char *get_author(char *buf)
return buf;
}
char *get_num_voices(char *buf)
int get_num_voices(void)
{
sprintf(buf, "Num voices: %i", gme_voice_count(emu));
return buf;
return gme_voice_count(emu);
}
char *get_voice_name(int index)
{
if(index<gme_voice_count(emu))
return (char*)gme_voice_name(emu, index);
else
return "";
}
char *get_track_position(char *buf)
......
......@@ -18,6 +18,10 @@ void next_track(void);
void prev_track(void);
bool is_voice_muted(int index);
void mute_voice(int index);
char *get_game_name(char *buf);
char *get_track_count(char *buf);
......@@ -26,7 +30,9 @@ char *get_song_name(char *buf);
char *get_author(char *buf);
char *get_num_voices(char *buf);
int get_num_voices(void);
char *get_voice_name(int index);
char *get_track_position(char *buf);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment