diff options
author | Thomas Günther <tom@toms-cafe.de> | 2008-03-16 21:12:52 +0100 |
---|---|---|
committer | Thomas Günther <tom@toms-cafe.de> | 2008-03-16 21:12:52 +0100 |
commit | 7aaa70fa39a1e9968ff08ffab4462231e80fbb67 (patch) | |
tree | 425f5c5f5eb55a99fb5733e31d4ebf00aa65bec9 | |
parent | baa63378b3de16c365255f29a3431488cf6656b3 (diff) | |
download | vdr-plugin-sudoku-7aaa70fa39a1e9968ff08ffab4462231e80fbb67.tar.gz vdr-plugin-sudoku-7aaa70fa39a1e9968ff08ffab4462231e80fbb67.tar.bz2 |
Added commands menu
-rw-r--r-- | HISTORY | 1 | ||||
-rw-r--r-- | README | 15 | ||||
-rw-r--r-- | commands.cpp | 86 | ||||
-rw-r--r-- | commands.h | 76 | ||||
-rw-r--r-- | i18n.h | 3 | ||||
-rw-r--r-- | menu.cpp | 64 | ||||
-rw-r--r-- | menu.h | 16 |
7 files changed, 241 insertions, 20 deletions
@@ -34,3 +34,4 @@ ____-__-__: Version _._._ - Show possible numbers as digits (VDR >= 1.5.4). - Paint numbers with a larger font (VDR >= 1.5.4). - Changed the background color of marked cells to darkgreen. +- Added commands menu. @@ -54,9 +54,7 @@ current cell. Each time the plug-in is started from the main menu the same puzzle is shown. A new puzzle is only generated on VDR startup or if it has been requested by -pressing the blue key. This key has two functions. If no numbers are set a new -puzzle is generated. Otherwise all numbers are reset so that only the givens are -shown. +selecting this command in the commands menu, which is opened with the blue key. Setup: @@ -100,11 +98,18 @@ Keys: possible numbers. - Red Set the next possible number for the current cell - reset the number if greater numbers are not possible. -- Blue Reset the puzzle (if some numbers set). - Start a new puzzle (if no numbers set). +- Blue Open the commands menu. - Back Quit the plug-in. +Commands menu: +-------------- + +- Generate a new puzzle Generate a random puzzle. +- Reset the puzzle Reset the numbers in all cells, excluding the givens. +- Exit Quit the plug-in. + + Cell colors: ------------ diff --git a/commands.cpp b/commands.cpp new file mode 100644 index 0000000..2319e81 --- /dev/null +++ b/commands.cpp @@ -0,0 +1,86 @@ +/* + * Sudoku: A plug-in for the Video Disk Recorder + * + * Copyright (C) 2008, Thomas Günther <tom@toms-cafe.de> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * $Id: commands.cpp 113 2008-03-16 20:12:52Z tom $ + */ + +#include "commands.h" +#include "menu.h" +#include "i18n.h" +#include <vdr/config.h> +#include <vdr/osdbase.h> +#include <vdr/osd.h> +#include <assert.h> + +using namespace SudokuPlugin; + + +//--- class SudokuPlugin::CommandMenu ------------------------------------------ + +/** Constructor */ +CommandMenu::CommandMenu() : + cOsdMenu(trVDR("Commands")) +{ + SetHasHotkeys(); + Add(new Command(hk(tr("Generate a new puzzle")), &Menu::generate)); + Add(new Command(hk(tr("Reset the puzzle")), &Menu::reset)); + Add(new Command(hk(tr("Exit")), &Menu::exit)); + command = NULL; +} + +/** Get the selected menu command. */ +CommandType CommandMenu::get_selected_command() const +{ + return command; +} + +/** Process user events. */ +eOSState CommandMenu::ProcessKey(eKeys key) +{ + eOSState state = cOsdMenu::ProcessKey(key); + if (state == osUnknown) + { + state = osContinue; + if (key == kOk) + { + Command* item = (Command*)Get(Current()); + if (item) + command = item->get_command(); + state = osBack; + } + } + return state; +} + + +//--- class SudokuPlugin::Command ---------------------------------------------- + +/** Constructor */ +Command::Command(const char* text, CommandType command) : + cOsdItem(text), command(command) +{ + assert(text != NULL); + assert(command != NULL); +} + +/** Get the menu command. */ +CommandType Command::get_command() const +{ + return command; +} diff --git a/commands.h b/commands.h new file mode 100644 index 0000000..48f32f9 --- /dev/null +++ b/commands.h @@ -0,0 +1,76 @@ +/* + * Sudoku: A plug-in for the Video Disk Recorder + * + * Copyright (C) 2008, Thomas Günther <tom@toms-cafe.de> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * $Id: commands.h 113 2008-03-16 20:12:52Z tom $ + */ + +#ifndef VDR_SUDOKU_COMMANDS_H +#define VDR_SUDOKU_COMMANDS_H + +#include "sudoku.h" +#include <vdr/osdbase.h> + + +namespace SudokuPlugin +{ + class Menu; + + /** Type of menu commands: pointer to member function of class Menu */ + typedef eOSState (Menu::*CommandType)(); + + + //--- class SudokuPlugin::CommandMenu ---------------------------------------- + + /** Commands menu of the plugin */ + class CommandMenu : public cOsdMenu + { + CommandType command; + + public: + + /** Constructor */ + CommandMenu(); + + /** Get the selected menu command. */ + CommandType get_selected_command() const; + + /** Process user events. */ + virtual eOSState ProcessKey(eKeys key); + }; + + + //--- class SudokuPlugin::Command -------------------------------------------- + + /** Item in commands menu */ + class Command : public cOsdItem + { + CommandType command; + + public: + + /** Constructor */ + Command(const char* text, CommandType command); + + /** Get the menu command. */ + CommandType get_command() const; + }; + +} // namespace SudokuPlugin + +#endif // VDR_SUDOKU_COMMANDS_H @@ -17,7 +17,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * $Id: i18n.h 106 2007-12-03 23:28:24Z tom $ + * $Id: i18n.h 113 2008-03-16 20:12:52Z tom $ */ #ifndef VDR_SUDOKU_I18N_H @@ -31,6 +31,7 @@ #if VDRVERSNUM < 10507 #define trNOOP(s) (s) +#define trVDR(s) tr(s) namespace SudokuPlugin { @@ -17,13 +17,14 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * $Id: menu.cpp 112 2008-03-16 17:56:36Z tom $ + * $Id: menu.cpp 113 2008-03-16 20:12:52Z tom $ */ #include "menu.h" #include "puzzle.h" #include "setup.h" #include "bitmap.h" +#include "commands.h" #include "i18n.h" #include <vdr/config.h> #include <vdr/osdbase.h> @@ -77,11 +78,13 @@ Menu::Menu(const SetupData& setup, Puzzle& puzzle, Pos& curr) : maxi_font = cFont::GetFont(fontFix); mini_font = NULL; #endif + command_menu = NULL; } /** Destructor */ Menu::~Menu() { + delete command_menu; #if VDRVERSNUM >= 10504 delete maxi_font; delete mini_font; @@ -108,18 +111,39 @@ void Menu::Show() /** Process user events. */ eOSState Menu::ProcessKey(eKeys key) { + if (command_menu) + { + eOSState state = command_menu->ProcessKey(key); + if (state == osBack) + { + state = osContinue; + CommandType command = command_menu->get_selected_command(); + DELETENULL(command_menu); + if (command) + state = (this->*command)(); + if (state == osContinue) + Show(); + } + return state; + } + eOSState state = cOsdObject::ProcessKey(key); if (state == osUnknown) { if (key == kBack) - return osEnd; + return exit(); + if (key == kBlue) + { + osd->Flush(); + DELETENULL(osd); + command_menu = new CommandMenu(); + command_menu->Display(); + return osContinue; + } if (new_puzzle_request) { if (key == kOk) - { - new_puzzle_request = false; - puzzle.generate(setup.givens_count, setup.symmetric); - } + generate(); } else { @@ -163,12 +187,6 @@ eOSState Menu::ProcessKey(eKeys key) if (puzzle.next_free(curr) <= Pos::last()) curr = puzzle.next_free(curr); break; - case kBlue: - if (puzzle.untouched()) - puzzle.generate(setup.givens_count, setup.symmetric); - else - puzzle.reset(setup.clear_marks); - break; default: return osContinue; } @@ -184,6 +202,26 @@ eOSState Menu::ProcessKey(eKeys key) return state; } +/** Generate a new puzzle. */ +eOSState Menu::generate() +{ + puzzle.generate(setup.givens_count, setup.symmetric); + return osContinue; +} + +/** Reset the puzzle. */ +eOSState Menu::reset() +{ + puzzle.reset(setup.clear_marks); + return osContinue; +} + +/** Exit plugin menu. */ +eOSState Menu::exit() +{ + return osEnd; +} + /** Paint all pieces of the menu. */ void Menu::paint() { @@ -273,6 +311,8 @@ void Menu::paint() osd->DrawBitmap(xPos + 10, yPos + 10, *info); infoText = NULL; } + else + new_puzzle_request = false; osd->Flush(); } @@ -17,14 +17,13 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * $Id: menu.h 111 2008-01-07 00:04:25Z tom $ + * $Id: menu.h 113 2008-03-16 20:12:52Z tom $ */ #ifndef VDR_SUDOKU_MENU_H #define VDR_SUDOKU_MENU_H #include "sudoku.h" -namespace SudokuPlugin { class SetupData; class Bitmap; } namespace Sudoku { class Puzzle; class Pos; } #include <vdr/config.h> #include <vdr/osdbase.h> @@ -33,6 +32,9 @@ namespace Sudoku { class Puzzle; class Pos; } namespace SudokuPlugin { + class SetupData; + class Bitmap; + class CommandMenu; //--- class SudokuPlugin::Menu ----------------------------------------------- @@ -49,6 +51,7 @@ namespace SudokuPlugin bool new_puzzle_request; const cFont* maxi_font; const cFont* mini_font; + CommandMenu* command_menu; public: @@ -64,6 +67,15 @@ namespace SudokuPlugin /** Process user events. */ virtual eOSState ProcessKey(eKeys key); + /** Generate a new puzzle. */ + eOSState generate(); + + /** Reset the puzzle. */ + eOSState reset(); + + /** Exit plugin menu. */ + eOSState exit(); + private: /** Paint all pieces of the menu. */ |