blob: 5668c678caf3736880267b958dbb7df181e10be4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#include <FL/Fl.H>
#include <FL/Fl_Native_File_Chooser.H>
#include <FL/fl_message.H>
#include <memory>
#include <stdio.h>
#include <string>
#include "menu_callbacks.hpp"
#include "solution_algorithm.hpp"
#include "gameplay.hpp"
#include "img_handler.hpp"
void new_game_callback(Fl_Widget*, void *gp)
{
Fl::check();
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\t*.jpg\nPNG Files\t*.png");
#if defined(_WIN32)
dialog.directory((std::string {getenv("HOMEPATH")} + "\\Desktop").c_str());
#else
dialog.directory((std::string {getenv("HOME")} + "/Desktop").c_str());
#endif
dialog.options(Fl_Native_File_Chooser::SAVEAS_CONFIRM |
Fl_Native_File_Chooser::NEW_FOLDER);
if (dialog.show() == 0)
path = dialog.filename();
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*)
{
w->parent()->hide();
}
void solve_problem_callback(Fl_Widget *w, void *gp)
{
GameParams *game = reinterpret_cast<GameParams*>(gp);
std::unique_ptr<ASearch> algorithm = ASearch::Start(game);
Node *goal = algorithm->FindSolution();
algorithm->ShowSolution(goal);
int answer = fl_choice("Play again?", "No", "Yes", nullptr);
if(answer)
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");
}
|