diff options
Diffstat (limited to 'src/puzzles/collection.c')
| -rw-r--r-- | src/puzzles/collection.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/puzzles/collection.c b/src/puzzles/collection.c index c382259..71eaadf 100644 --- a/src/puzzles/collection.c +++ b/src/puzzles/collection.c @@ -87,7 +87,7 @@ size_t getElementCount(DIR *dir, CollectionElement *el) { return outp; } -void initCollectionFromDir(CollectionElement *el) { +void initCollectionFromDir(CollectionElement *el, void (*callback)(CollectionElement *)) { if (el == NULL) return; TraceLog(LOG_INFO, "Initializing a collection element from %s/", el->path); @@ -132,6 +132,7 @@ void initCollectionFromDir(CollectionElement *el) { read_el->IsInitialized = false; read_el->path = strdup(full_path_buf); read_el->name = getName(entry->d_name); + read_el->callback = callback; idx += 1; } @@ -139,7 +140,7 @@ void initCollectionFromDir(CollectionElement *el) { closedir(dir); } -void InitializeCollection(CollectionElement *el) { +void InitializeCollection(CollectionElement *el, void (*callback)(CollectionElement *)) { if (el == NULL) { TraceLog(LOG_ERROR, "Failed to initialize collection element: the element is NULL"); return; @@ -147,7 +148,7 @@ void InitializeCollection(CollectionElement *el) { switch (el->type) { case COLLECTION_ELEMENT_PUZZLE: break; case COLLECTION_ELEMENT_COLLECTION: - initCollectionFromDir(el); + initCollectionFromDir(el, callback); break; default: TraceLog(LOG_WARNING, "Invalid CollectionElement type"); @@ -157,6 +158,7 @@ void InitializeCollection(CollectionElement *el) { void DrawCollectionElement(CollectionElement *el, CollectionElement *parent, Rectangle rec) { if (el == NULL || parent == NULL) return; + el->_previousFramePosition = rec; DrawRecBordered(rec, COLORSCHEME_WHITE, COLORSCHEME_ORANGE, BORDER); if (el->type == COLLECTION_ELEMENT_PUZZLE && parent->hasIcon) { Rectangle texture_rec = { @@ -180,3 +182,12 @@ void DrawCollectionElement(CollectionElement *el, CollectionElement *parent, Rec .height = rec.height * NAME_IN_CARD_RATIO - BORDER * 2, }, el->name, GetMainFont(), 20, COLORSCHEME_BROWN, 1, &scroll); } + +void UpdateCollectionElement(CollectionElement *el) { + if (el == NULL) return; + if (IsMouseInRec(el->_previousFramePosition)) { + if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) { + el->callback(el); + } + } +} |
