back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--main.cpp9
-rw-r--r--menu_callbacks.cpp34
-rw-r--r--menu_callbacks.hpp10
-rw-r--r--puzzle.cpp2
-rw-r--r--puzzle.hpp2
6 files changed, 55 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index a73ba82..a963df0 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-SRCMODULES = puzzle.cpp gameplay.cpp main.cpp
+SRCMODULES = puzzle.cpp gameplay.cpp menu_callbacks.cpp main.cpp
OBJMODULES = $(SRCMODULES:.cpp=.o)
CXX = g++
CXXFLAGS = -Wall -g
diff --git a/main.cpp b/main.cpp
index d5d20d5..4224965 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,16 +1,23 @@
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
+#include <FL/Fl_Sys_Menu_Bar.H>
#include <stdlib.h>
#include <time.h>
#include "puzzle.hpp"
#include "gameplay.hpp"
+#include "menu_callbacks.hpp"
int main()
{
srand(time(nullptr));
- Fl_Window *win = new Fl_Window(325, 325, "Picture puzzle");
+ Fl_Window *win = new Fl_Window(325, 355, "Picture puzzle");
+ Fl_Sys_Menu_Bar *sys_bar = new Fl_Sys_Menu_Bar(0, 0, 165, 20, nullptr);
+ sys_bar->add("&File/&Load picture", nullptr, load_file_callback);
+ sys_bar->add("&File/&Exit", nullptr, exit_callback);
+ sys_bar->add("&Option/&Show solution", nullptr, solve_problem_callback);
+ sys_bar->add("&About", nullptr, about_callback);
GameParams *params = GameParams::SetUpParams(win);
PuzzleGame::StartGame(params);
win->show();
diff --git a/menu_callbacks.cpp b/menu_callbacks.cpp
new file mode 100644
index 0000000..df70514
--- /dev/null
+++ b/menu_callbacks.cpp
@@ -0,0 +1,34 @@
+#include <FL/Fl_Native_File_Chooser.H>
+#include <stdio.h>
+#include <string>
+
+#include "menu_callbacks.hpp"
+
+void load_file_callback(Fl_Widget *sender, void *window)
+{
+ auto dialog = Fl_Native_File_Chooser{};
+ dialog.type(Fl_Native_File_Chooser::BROWSE_FILE);
+ dialog.filter("JPEG Files (*.jpg)\tPNG Files (*.png)");
+#if defined(_WIN32)
+ dialog.directory((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)
+ printf("%s\n", dialog.filename());
+}
+
+void exit_callback(Fl_Widget *w, void *params)
+{
+ w->parent()->hide();
+}
+
+void solve_problem_callback(Fl_Widget *w, void *params)
+{
+}
+
+void about_callback(Fl_Widget *w, void *params)
+{
+}
diff --git a/menu_callbacks.hpp b/menu_callbacks.hpp
new file mode 100644
index 0000000..61967a5
--- /dev/null
+++ b/menu_callbacks.hpp
@@ -0,0 +1,10 @@
+#ifndef MENU_CALLBACKS_HPP_SENTRY
+
+#include <FL/Fl_Widget.H>
+
+void load_file_callback(Fl_Widget *sender, void *window);
+void exit_callback(Fl_Widget *w, void *params);
+void solve_problem_callback(Fl_Widget *w, void *params);
+void about_callback(Fl_Widget *w, void *params);
+
+#endif
diff --git a/puzzle.cpp b/puzzle.cpp
index ca55ef9..a42be91 100644
--- a/puzzle.cpp
+++ b/puzzle.cpp
@@ -17,7 +17,7 @@ void GameParams::CalculateStandardPuzzlePos()
if(i == puzzles_per_side-1 && j == puzzles_per_side-1)
break;
tmp.x = i * (puzzle_size + spacing) + spacing;
- tmp.y = j * (puzzle_size + spacing) + spacing;
+ tmp.y = j * (puzzle_size + spacing) + spacing + 30;
standard_puzzle_coordinates[k] = tmp;
}
}
diff --git a/puzzle.hpp b/puzzle.hpp
index 39a4752..e8d85d6 100644
--- a/puzzle.hpp
+++ b/puzzle.hpp
@@ -50,7 +50,7 @@ public:
static GameParams *SetUpParams(Fl_Window *win) {
GameParams *gi = new GameParams(win);
gi->CalculateStandardPuzzlePos();
- gi->SetXYEmptyBox(215, 215);
+ gi->SetXYEmptyBox(215, 245);
return gi;
}
};