popup msg draws on top with animation

This commit is contained in:
BADIM-PC\Vadim 2017-12-08 15:03:59 +03:00
parent effcdbf485
commit 7a44b70b12
1 changed files with 26 additions and 9 deletions

View File

@ -57,6 +57,8 @@
#define OFFSET_LEFT ((TIC80_FULLWIDTH-TIC80_WIDTH)/2) #define OFFSET_LEFT ((TIC80_FULLWIDTH-TIC80_WIDTH)/2)
#define OFFSET_TOP ((TIC80_FULLHEIGHT-TIC80_HEIGHT)/2) #define OFFSET_TOP ((TIC80_FULLHEIGHT-TIC80_HEIGHT)/2)
#define POPUP_DUR (TIC_FRAMERATE*2)
typedef struct typedef struct
{ {
u8 data[16]; u8 data[16];
@ -670,7 +672,7 @@ const u8* getKeyboard()
static void showPopupMessage(const char* text) static void showPopupMessage(const char* text)
{ {
studio.popup.counter = TIC_FRAMERATE * 2; studio.popup.counter = POPUP_DUR;
strcpy(studio.popup.message, text); strcpy(studio.popup.message, text);
} }
@ -2055,6 +2057,28 @@ static void useSystemPalette()
memcpy(studio.tic->ram.vram.palette.data, studio.tic->config.palette.data, sizeof(tic_palette)); memcpy(studio.tic->ram.vram.palette.data, studio.tic->config.palette.data, sizeof(tic_palette));
} }
static void drawPopup()
{
if(studio.popup.counter > 0)
{
studio.popup.counter--;
s32 anim = 0;
enum{Dur = TIC_FRAMERATE/2};
if(studio.popup.counter < Dur)
anim = -((Dur - studio.popup.counter) * (TIC_FONT_HEIGHT+1) / Dur);
else if(studio.popup.counter >= (POPUP_DUR - Dur))
anim = (((POPUP_DUR - Dur) - studio.popup.counter) * (TIC_FONT_HEIGHT+1) / Dur);
studio.tic->api.rect(studio.tic, 0, anim, TIC80_WIDTH, TIC_FONT_HEIGHT+1, (tic_color_red));
studio.tic->api.text(studio.tic, studio.popup.message,
(s32)(TIC80_WIDTH - strlen(studio.popup.message)*TIC_FONT_WIDTH)/2,
anim + 1, (tic_color_white));
}
}
static void renderStudio() static void renderStudio()
{ {
tic_mem* tic = studio.tic; tic_mem* tic = studio.tic;
@ -2105,14 +2129,7 @@ static void renderStudio()
default: break; default: break;
} }
if(studio.popup.counter > 0) drawPopup();
{
studio.popup.counter--;
studio.tic->api.rect(studio.tic, 0, TIC80_HEIGHT - TIC_FONT_HEIGHT - 1, TIC80_WIDTH, TIC80_HEIGHT, (tic_color_red));
studio.tic->api.text(studio.tic, studio.popup.message, (s32)(TIC80_WIDTH - strlen(studio.popup.message)*TIC_FONT_WIDTH)/2,
TIC80_HEIGHT - TIC_FONT_HEIGHT, (tic_color_white));
}
if(getConfig()->noSound) if(getConfig()->noSound)
SDL_memset(tic->ram.registers, 0, sizeof tic->ram.registers); SDL_memset(tic->ram.registers, 0, sizeof tic->ram.registers);