summaryrefslogtreecommitdiff
path: root/src/puzzles/collection.c
diff options
context:
space:
mode:
authorphysick <mynameisgennadiy@vk.com>2026-08-30 20:40:31 +0500
committerphysick <mynameisgennadiy@vk.com>2026-08-30 20:40:31 +0500
commitce9cbb6c0dbd8c920fdb87389332028cdd60ccc1 (patch)
treeb6aee4d8a225c267ee05675e9074c5d860f40478 /src/puzzles/collection.c
parentd2711061b06a95bdf0170e86c1c723a32a6527ba (diff)
collection view 2
Diffstat (limited to 'src/puzzles/collection.c')
-rw-r--r--src/puzzles/collection.c40
1 files changed, 27 insertions, 13 deletions
diff --git a/src/puzzles/collection.c b/src/puzzles/collection.c
index 8abc3fa..c382259 100644
--- a/src/puzzles/collection.c
+++ b/src/puzzles/collection.c
@@ -11,6 +11,7 @@
#include <string.h>
static const char *IMAGE_NAME = "icon.png";
+static const float NAME_IN_CARD_RATIO = 0.2f;
CollectionElementType getTypeFromPath(char *fullPath) {
struct stat st;
@@ -32,6 +33,10 @@ void addIcon(CollectionElement *el, struct dirent *entry) {
if (el == NULL || entry == NULL) return;
char fullPath[1024];
snprintf(fullPath, sizeof(fullPath), "%s/%s", el->path, entry->d_name);
+ TraceLog(LOG_INFO, "Loading texture %s for element %s", fullPath, el->path);
+ el->icon = LoadTexture(fullPath);
+ TraceLog(LOG_INFO, "Texture dimentions: %d;%d, id %u", el->icon.width, el->icon.height, el->icon.id);
+ el->hasIcon = true;
}
bool isPuzzle(char *path) {
@@ -92,6 +97,7 @@ void initCollectionFromDir(CollectionElement *el) {
return;
}
+ el->hasIcon = false;
el->childCount = getElementCount(dir, el);
el->children = malloc(sizeof(CollectionElement) * el->childCount);
// printf("element count: %zu\n", el->childCount);
@@ -126,7 +132,6 @@ void initCollectionFromDir(CollectionElement *el) {
read_el->IsInitialized = false;
read_el->path = strdup(full_path_buf);
read_el->name = getName(entry->d_name);
- read_el->icon = NULL;
idx += 1;
}
@@ -150,19 +155,28 @@ void InitializeCollection(CollectionElement *el) {
}
}
-void DrawCollectionElement(CollectionElement *el, Rectangle rec) {
- if (el == NULL) return;
- if (el->icon != NULL) {
- printf("xdx\n");
- DrawTexturePro(*el->icon, (Rectangle) {
+void DrawCollectionElement(CollectionElement *el, CollectionElement *parent, Rectangle rec) {
+ if (el == NULL || parent == NULL) return;
+ DrawRecBordered(rec, COLORSCHEME_WHITE, COLORSCHEME_ORANGE, BORDER);
+ if (el->type == COLLECTION_ELEMENT_PUZZLE && parent->hasIcon) {
+ Rectangle texture_rec = {
+ .x = rec.x + BORDER,
+ .y = rec.y + BORDER + rec.height * NAME_IN_CARD_RATIO,
+ .width = rec.width - BORDER * 2,
+ .height = rec.height * (1 - NAME_IN_CARD_RATIO) - BORDER * 2,
+ };
+ DrawTexturePro(parent->icon, (Rectangle) {
.x = 0,
.y = 0,
- .width = el->icon->width,
- .height = el->icon->height,
- }, rec, (Vector2) { .x = 0, .y = 0 }, 0, WHITE);
- } else {
- DrawRecBordered(rec, COLORSCHEME_WHITE, COLORSCHEME_ORANGE, BORDER);
- }
+ .width = parent->icon.width,
+ .height = parent->icon.height,
+ }, texture_rec, (Vector2) { .x = 0, .y = 0 }, 0, WHITE);
+ }
int scroll = 0;
- DrawTextInRec(rec, el->name, GetMainFont(), 20, COLORSCHEME_BROWN, 1, &scroll);
+ DrawTextInRec((Rectangle) {
+ .x = rec.x + BORDER,
+ .y = rec.y + BORDER,
+ .width = rec.width - BORDER * 2,
+ .height = rec.height * NAME_IN_CARD_RATIO - BORDER * 2,
+ }, el->name, GetMainFont(), 20, COLORSCHEME_BROWN, 1, &scroll);
}