diff options
| author | physick <mynameisgennadiy@vk.com> | 2026-07-12 13:08:33 +0500 |
|---|---|---|
| committer | physick <mynameisgennadiy@vk.com> | 2026-07-12 13:08:33 +0500 |
| commit | f314b56da42e1ead200e2373e9b214f77290d03b (patch) | |
| tree | 52e535e99fe8c82a3a4834f67825ba2183e44283 /src/scenes/resultView.c | |
| parent | 71e1f2dc8e9e1b3ee595a2712ec24d11ce243f1c (diff) | |
fun popup animation
Diffstat (limited to 'src/scenes/resultView.c')
| -rw-r--r-- | src/scenes/resultView.c | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/scenes/resultView.c b/src/scenes/resultView.c index 9985319..b433bd0 100644 --- a/src/scenes/resultView.c +++ b/src/scenes/resultView.c @@ -6,37 +6,56 @@ #include "../ui_elements/UI.h" #include "../resources/resources.h" -static const int PADDING = 10; +static const int PADDING = 20; static const int BORDER = 2; +static const int SCROLL_SPEED = 10; typedef struct { char *value; int scroll; + /// For the fun popping up effect + float scroll_up; + bool isClosing; } ResultViewData; -Rectangle GetResultViewBodyRect() { +Rectangle GetResultViewBodyRect(float scroll_up) { int HeaderOffset = PADDING * 2; + int height = GetScreenHeight(); Rectangle outp = { .x = PADDING, - .y = HeaderOffset, + .y = HeaderOffset + (height * scroll_up), .width = GetScreenWidth() - PADDING * 2, - .height = GetScreenHeight() - HeaderOffset - PADDING * 3, + .height = height - HeaderOffset - PADDING * 3, }; + return outp; } bool updateResultView(void *self) { - if (IsKeyDown(KEY_ESCAPE)) { - DeleteSceneFromStack(); + ResultViewData *data = ((Scene *)self)->data; + + if (data->isClosing) { + data->scroll_up += SCROLL_SPEED * GetFrameTime(); + if (data->scroll_up > 1) DeleteSceneFromStack(); return true; } + + if (data->scroll_up != 0) { + data->scroll_up -= SCROLL_SPEED * GetFrameTime(); + if (data->scroll_up < 0) data->scroll_up = 0; + } + + if (IsKeyPressed(KEY_ESCAPE)) { + data->isClosing = true; + } + return true; } bool drawResultView(void *self) { ResultViewData *data = ((Scene *)self)->data; - DrawBackground(); - Rectangle body = GetResultViewBodyRect(); + // DrawBackground(); + Rectangle body = GetResultViewBodyRect(data->scroll_up); DrawRecBordered(body, WHITE, COLORSCHEME_ORANGE, BORDER); DrawTextInRec(body, data->value, GetMainFont(), 20, COLORSCHEME_BROWN, 3, &data->scroll); @@ -54,6 +73,7 @@ Scene *CreateResultView(char *result) { outp->Draw = drawResultView; outp->Update = updateResultView; outp->Deint = deinitResultView; + outp->IsTransparent = true; ResultViewData *data = malloc(sizeof(ResultViewData)); if (data == NULL) { @@ -62,6 +82,8 @@ Scene *CreateResultView(char *result) { } data->value = result; data->scroll = 0; + data->scroll_up = 1; + data->isClosing = false; outp->data = data; return outp; |
