From d51d95b66dee211ef654693fb23238d5a234f48c Mon Sep 17 00:00:00 2001 From: physick Date: Sat, 29 Aug 2026 14:12:24 +0500 Subject: merged branches --- src/scenes/collectionScene.c | 74 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/scenes/collectionScene.c (limited to 'src/scenes/collectionScene.c') diff --git a/src/scenes/collectionScene.c b/src/scenes/collectionScene.c new file mode 100644 index 0000000..2173619 --- /dev/null +++ b/src/scenes/collectionScene.c @@ -0,0 +1,74 @@ +#include "scenes.h" +#include +#include +#include "../ui_elements/UI.h" +#include "../resources/resources.h" + +typedef struct { + char *DirPath; + char *Name; +} CollectionSceneData; + +CollectionSceneData *getData(void *self) { + return ((Scene *)self)->data; +} + +void DrawCollectionName(char *name) { + Vector2 width = MeasureTextEx(*GetMainFont(), name, 50, 1); + int screen_width = GetScreenWidth(); + Vector2 pos = { .y = 20, .x = (screen_width - width.x) / 2, }; + DrawTextEx(*GetMainFont(), name, pos, HEADER_FONT_SIZE, 1, COLORSCHEME_BROWN); +} + +// Does not allocate the memory +char *getCollectionName(char *path) { + char *outp = path; + size_t len = strlen(path); + for (size_t i = 0; i < len; ++i) { + if ((path[i] == '/' || path[i] == '\\') && path[i+1] != 0x0) { + outp = path + i + 1; + } + } + return outp; +} + +bool updateCollectionScene(void *self) { + return true; +} + +bool drawCollectionScene(void *self) { + CollectionSceneData *data = getData(self); + DrawBackground(); + DrawCollectionName(data->Name); + DrawPageView(GetScreenHeight() - 60, 5, 2); + return true; +} + +void deinitCollectionScene(void *self) { + TraceLog(LOG_INFO, "Deleting a collection scene"); + CollectionSceneData *data = getData(self); + if (data != NULL) free(data); + free((Scene *)self); +} + +Scene *CreatePuzzleCollectionScene(char *path) { + TraceLog(LOG_INFO, "Creating a collection scene"); + Scene *outp = malloc(sizeof(Scene)); + if (outp == NULL) return NULL; + outp->Update = updateCollectionScene; + outp->Draw = drawCollectionScene; + outp->Deint = deinitCollectionScene; + outp->IsTransparent = false; + + CollectionSceneData *data = malloc(sizeof(CollectionSceneData)); + if (data == NULL) { + free(outp); + return NULL; + } + data->DirPath = strdup(path); + data->Name = getCollectionName(path); + + outp->data = data; + + return outp; +} -- cgit v1.3