From 58719994ef50de9f88c0d2839617621ba57b6efc Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Tue, 16 Jun 2020 20:05:12 +0930 Subject: cheat: show mine positions when left control pressed --- MainWindow.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ MainWindow.h | 3 +++ 2 files changed, 64 insertions(+) diff --git a/MainWindow.cpp b/MainWindow.cpp index 1c0cc27..36963be 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -27,6 +27,8 @@ FXDEFMAP(MainWindow) MainWindow_Map[]= FXMAPFUNC(SEL_COMMAND, MainWindow::UI_New, MainWindow::on_New_Click), FXMAPFUNC(SEL_RIGHTBUTTONPRESS, MainWindow::UI_Tile, MainWindow::on_Tile_Right_Click), FXMAPFUNC(SEL_TIMEOUT, MainWindow::UI_Timer_Tick, MainWindow::on_Timer_Tick), + FXMAPFUNC(SEL_KEYPRESS, 0, MainWindow::on_Key_Press), + FXMAPFUNC(SEL_KEYRELEASE, 0, MainWindow::on_Key_Release), }; FXIMPLEMENT(MainWindow, FXMainWindow, MainWindow_Map, ARRAYNUMBER(MainWindow_Map)) @@ -353,3 +355,62 @@ MainWindow::on_New_Click(FXObject *sender, FXSelector sel, void *data) } return 1; } + +long +MainWindow::on_Key_Press(FXObject *sender, FXSelector sel, void *data) +{ + FXEvent* event=(FXEvent*)data; + switch(event->code) + { + /* show mine positons while left control held */ + case KEY_Control_L: + FXButton *button; + Tile *tile; + int x, y; + for(auto b = tile_buttons.begin(); b != tile_buttons.end(); ++b) + { + button = (*b).get(); + x = matrix->colOfChild(button); + y = matrix->rowOfChild(button); + tile = board->get_tile_at(x, y); + if (tile->is_mine()) + { + button->setBackColor(FXRGB(0, 255, 0)); // make mines green + } + } + break; + default: + break; + } + return 1; +} + +long +MainWindow::on_Key_Release(FXObject *sender, FXSelector sel, void *data) +{ + FXEvent* event=(FXEvent*)data; + switch(event->code) + { + case KEY_Control_L: + FXButton *button; + Tile *tile; + int x, y; + for(auto b = tile_buttons.begin(); b != tile_buttons.end(); ++b) + { + button = (*b).get(); + x = matrix->colOfChild(button); + y = matrix->rowOfChild(button); + tile = board->get_tile_at(x, y); + if (tile->is_mine()) + { + button->setBackColor(canvasFrame->getBackColor()); // make mines normal + } + } + break; + + default: + break; + } + + return 1; +} diff --git a/MainWindow.h b/MainWindow.h index 50d7493..ed252c7 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -21,6 +21,7 @@ #include #include #include +#include #include "Board.h" #include "icons.h" @@ -46,6 +47,8 @@ class MainWindow : public FXMainWindow long on_New_Click(FXObject *sender, FXSelector sel, void *data); long on_Tile_Right_Click(FXObject *sender, FXSelector sel, void *data); long on_Timer_Tick(FXObject *sender, FXSelector sel, void *data); + long on_Key_Press(FXObject *sender, FXSelector sel, void *data); + long on_Key_Release(FXObject *sender, FXSelector sel, void *data); FXApp *get_app(){ return app; }; -- cgit v1.2.3