diff options
author | scratko <m@scratko.xyz> | 2024-11-18 18:01:32 +0300 |
---|---|---|
committer | scratko <m@scratko.xyz> | 2024-11-18 20:36:37 +0300 |
commit | 503e7350fa3d8065e2f4814181664382154dc702 (patch) | |
tree | 18ec4fd2dc2d55e286b164c79f673b9e67e4c1bd /menu_callbacks.cpp | |
parent | 7fea2267e78de935af6010d5ac7300e51f471601 (diff) | |
download | picture-puzzle-503e7350fa3d8065e2f4814181664382154dc702.tar.gz picture-puzzle-503e7350fa3d8065e2f4814181664382154dc702.tar.bz2 picture-puzzle-503e7350fa3d8065e2f4814181664382154dc702.zip |
Random image selection
Added a dialog box about.
Checks if the selected file is correct.
Diffstat (limited to 'menu_callbacks.cpp')
-rw-r--r-- | menu_callbacks.cpp | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/menu_callbacks.cpp b/menu_callbacks.cpp index a48b899..ffc1aae 100644 --- a/menu_callbacks.cpp +++ b/menu_callbacks.cpp @@ -1,4 +1,5 @@ #include <FL/Fl_Native_File_Chooser.H> +#include <FL/fl_message.H> #include <memory> #include <stdio.h> #include <string> @@ -8,12 +9,26 @@ #include "gameplay.hpp" #include "img_handler.hpp" +void new_game_callback(Fl_Widget*, void *gp) +{ + PuzzleGame::StartGame(reinterpret_cast<GameParams*>(gp)); +} + +static bool check_correct_path_to_img(const char *path) +{ + if(path == nullptr) + return false; + std::string p(path); + std::string ext = p.substr(p.find_last_of('.')); + return ext == ".png" || ext == ".jpg"; +} + void load_file_callback(Fl_Widget *sender, void*) { const char *path = nullptr; auto dialog = Fl_Native_File_Chooser{}; dialog.type(Fl_Native_File_Chooser::BROWSE_FILE); - dialog.filter("JPEG Files (*.jpg)\tPNG Files (*.png)"); + dialog.filter("JPEG Files\t*.jpg\nPNG Files\t*.png"); #if defined(_WIN32) dialog.directory((string {getenv("HOMEPATH")} + "\\Desktop").c_str()); #else @@ -23,10 +38,14 @@ void load_file_callback(Fl_Widget *sender, void*) Fl_Native_File_Chooser::NEW_FOLDER); if (dialog.show() == 0) path = dialog.filename(); - ImageHandler ih(path); - ih.load_img(); - ih.resize_img(); - ih.save_img(); + if(check_correct_path_to_img(path)) { + ImageHandler ih(path); + ih.load_img(); + ih.resize_img(); + ih.save_img(); + fl_message_title("Info"); + fl_message("Image successfully added"); + } } void exit_callback(Fl_Widget *w, void*) @@ -45,9 +64,13 @@ void solve_problem_callback(Fl_Widget *w, void *gp) PuzzleGame::StartGame(game); else game->win->hide(); - } void about_callback(Fl_Widget *w, void*) { + fl_message_title("About"); + fl_message("This app is devoted to my friends, to who I'm appreciative for" + " their support:\nIlya Korsak\nMaxim Fadeev\n\n" + "For all questions, please contact me:\n" + "m@@scratko.xyz"); } |