diff --git a/src/studio.c b/src/studio.c index e35bbe6..492013a 100644 --- a/src/studio.c +++ b/src/studio.c @@ -57,6 +57,8 @@ #define OFFSET_LEFT ((TIC80_FULLWIDTH-TIC80_WIDTH)/2) #define OFFSET_TOP ((TIC80_FULLHEIGHT-TIC80_HEIGHT)/2) +#define POPUP_DUR (TIC_FRAMERATE*2) + typedef struct { u8 data[16]; @@ -670,7 +672,7 @@ const u8* getKeyboard() static void showPopupMessage(const char* text) { - studio.popup.counter = TIC_FRAMERATE * 2; + studio.popup.counter = POPUP_DUR; 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)); } +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() { tic_mem* tic = studio.tic; @@ -2105,14 +2129,7 @@ static void renderStudio() default: break; } - if(studio.popup.counter > 0) - { - 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)); - } + drawPopup(); if(getConfig()->noSound) SDL_memset(tic->ram.registers, 0, sizeof tic->ram.registers);