summaryrefslogtreecommitdiff
path: root/src
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
parentd2711061b06a95bdf0170e86c1c723a32a6527ba (diff)
collection view 2
Diffstat (limited to 'src')
-rw-r--r--src/main.c7
-rw-r--r--src/puzzles/collection.c40
-rw-r--r--src/puzzles/puzzle.h5
-rw-r--r--src/scenes/collectionScene.c2
4 files changed, 35 insertions, 19 deletions
diff --git a/src/main.c b/src/main.c
index 771f165..39f6a68 100644
--- a/src/main.c
+++ b/src/main.c
@@ -13,6 +13,10 @@ int main(void) {
Puzzle *puzzle = ReadPuzzleFromFile("puzzles/test.pz");
PrintPuzzle(puzzle);
+ SetConfigFlags(FLAG_WINDOW_RESIZABLE);
+ InitWindow(800, 600, "Programming game");
+ LoadResources();
+
if (!ReadConfig(DEFAULT_CONFIG_LOCATION)) {
return 1;
}
@@ -37,9 +41,6 @@ int main(void) {
// return 1;
// }
- SetConfigFlags(FLAG_WINDOW_RESIZABLE);
- InitWindow(800, 600, "Programming game");
- LoadResources();
SetExitKey(KEY_NULL);
SetTargetFPS(60);
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);
}
diff --git a/src/puzzles/puzzle.h b/src/puzzles/puzzle.h
index a65ae6f..cea0dba 100644
--- a/src/puzzles/puzzle.h
+++ b/src/puzzles/puzzle.h
@@ -100,16 +100,17 @@ typedef enum {
} CollectionElementType;
typedef struct CollectionElement {
+ Texture2D icon;
char *path;
char *name;
struct CollectionElement *children;
size_t childCount;
- Texture2D *icon;
bool IsInitialized;
+ bool hasIcon;
CollectionElementType type;
} CollectionElement;
void InitializeCollection(CollectionElement *el);
-void DrawCollectionElement(CollectionElement *el, Rectangle rec);
+void DrawCollectionElement(CollectionElement *el, CollectionElement *parent, Rectangle rec);
#endif // PUZZLE_H
diff --git a/src/scenes/collectionScene.c b/src/scenes/collectionScene.c
index a5a650f..17d36c9 100644
--- a/src/scenes/collectionScene.c
+++ b/src/scenes/collectionScene.c
@@ -54,7 +54,7 @@ bool drawCollectionScene(void *self) {
DrawPageView(GetScreenHeight() - 60, 5, 2);
for (size_t i = 0; i < data->collection->childCount; ++i) {
- DrawCollectionElement(&data->collection->children[i], (Rectangle) {
+ DrawCollectionElement(&data->collection->children[i], data->collection, (Rectangle) {
.x = 10 + 210 * i,
.y = 80,
.width = 200,