From ec2e197c9342b04cae6ef24cb293eabe57100dc8 Mon Sep 17 00:00:00 2001 From: scratko Date: Fri, 22 Nov 2024 02:31:26 +0300 Subject: Program termination Termination of the program while the computer is solving the algorithm (by esc key) --- main.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index d1646e1..539130d 100644 --- a/main.cpp +++ b/main.cpp @@ -9,10 +9,26 @@ #include "gameplay.hpp" #include "menu_callbacks.hpp" +class MainWindow : public Fl_Window { +public: + MainWindow(int w, int h, const char *title) : Fl_Window(w, h, title) {} + /* + * Ending program by esc key while the computer is solving a puzzle + */ + int handle(int event) { + if(event == FL_KEYDOWN && Fl::event_length() != 0 && + Fl::event_key() == FL_Escape) + { + exit(0); + } + return Fl_Window::handle(event); + } +}; + int main() { srand(time(nullptr)); - Fl_Window *win = new Fl_Window(320, 355, "Picture puzzle"); + MainWindow *win = new MainWindow(320, 355, "Picture puzzle"); GameParams *params = GameParams::SetUpParams(win); Fl_Sys_Menu_Bar *sys_bar = new Fl_Sys_Menu_Bar(0, 0, 355, 20, nullptr); sys_bar->add("&File/&New game", nullptr, new_game_callback, params); -- cgit v1.2.3