#include #include #include #include #include "scenes.h" #include "../ui_elements/UI.h" #include "../resources/resources.h" 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(float scroll_up) { int HeaderOffset = PADDING * 2; int height = GetScreenHeight(); Rectangle outp = { .x = PADDING, .y = HeaderOffset + (height * scroll_up), .width = GetScreenWidth() - PADDING * 2, .height = height - HeaderOffset - PADDING * 3, }; return outp; } bool updateResultView(void *self) { 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(data->scroll_up); DrawRecBordered(body, WHITE, COLORSCHEME_ORANGE, BORDER); DrawTextInRec(body, data->value, GetMainFont(), 20, COLORSCHEME_BROWN, 3, &data->scroll); return true; } void deinitResultView(void *self) { TraceLog(LOG_INFO, "Deleting a result view"); free((Scene *)self); } Scene *CreateResultView(char *result) { TraceLog(LOG_INFO, "Creating a main menu"); Scene *outp = malloc(sizeof(Scene)); outp->Draw = drawResultView; outp->Update = updateResultView; outp->Deint = deinitResultView; outp->IsTransparent = true; ResultViewData *data = malloc(sizeof(ResultViewData)); if (data == NULL) { free(outp); return NULL; } data->value = result; data->scroll = 0; data->scroll_up = 1; data->isClosing = false; outp->data = data; return outp; }