git repos / sago_multi_scrambler_puzzle2

commit 8d245307

Poul Sander · 2025-11-20 17:22
8d24530754beb2491c0d1f96c667639e0a74490d patch · browse files
parent d7023ec2987e84bae041adfbe32a81b42f29e467

Add option to set an image as favorite or not while in it.

Changed files

M src/PuzzleSingleImageState.cpp before
M src/PuzzleSingleImageState.hpp before
diff --git a/src/PuzzleSingleImageState.cpp b/src/PuzzleSingleImageState.cpp index 5e7ea89..affc734 100644 --- a/src/PuzzleSingleImageState.cpp +++ b/src/PuzzleSingleImageState.cpp
@@ -27,6 +27,7 @@ https://github.com/sago007/saland
#include "globals.hpp"
#include <SDL2/SDL2_gfxPrimitives.h>
#include <time.h>
+#include <filesystem>
#include "SagoImGui.hpp"
#include "rhash.hpp"
#include "config.hpp"
@@ -162,6 +163,17 @@ void PuzzleSingleImageState::Draw(SDL_Renderer* target) {
if (ImGui::MenuItem("Shuffle")) {
Shuffle();
}
+ if (imageFilePath.length()) {
+ bool isFav = IsFavorite(imageFilePath);
+ const char* favoriteText = isFav ? "Remove from Favorites" : "Add to Favorites";
+ if (ImGui::MenuItem(favoriteText)) {
+ if (isFav) {
+ RemoveFavorite(imageFilePath);
+ } else {
+ AddFavorite(imageFilePath);
+ }
+ }
+ }
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Settings")) {
@@ -287,6 +299,7 @@ void PuzzleSingleImageState::ResizeImagePhysical() {
void PuzzleSingleImageState::LoadPictureFromFile(const std::string& filename, SDL_Renderer* renderer) {
ClearPicture();
+ imageFilePath = std::filesystem::absolute(filename).string();
IMG_Init(IMG_INIT_JPG|IMG_INIT_PNG);
SDL_Surface* bitmapSurface = IMG_Load(filename.c_str());
if (!bitmapSurface) {
diff --git a/src/PuzzleSingleImageState.hpp b/src/PuzzleSingleImageState.hpp index 25d8fe1..cbffd2a 100644 --- a/src/PuzzleSingleImageState.hpp +++ b/src/PuzzleSingleImageState.hpp
@@ -62,6 +62,7 @@ private:
bool puzzleSolved = false;
Confetti confetti;
SDL_Texture* pictureTex = NULL;
+ std::string imageFilePath = "";
int source_image_height = 1;
int source_image_width = 1;
// Swap animation