00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "commands.h"
00022 #include "menu.h"
00023 #include <vdr/i18n.h>
00024 #include <vdr/config.h>
00025 #include <vdr/osdbase.h>
00026 #include <vdr/osd.h>
00027 #include <assert.h>
00028
00029
00030 namespace SudokuPlugin
00031 {
00032
00033 enum
00034 {
00035 Cmd_LowerEdge = 100,
00036 CmdGenerate,
00037 CmdReset,
00038 CmdExit,
00039 CmdMark,
00040 CmdNextCell,
00041 CmdNextNumber,
00042 CmdLoad,
00043 CmdSave,
00044 CmdSetup,
00045 CmdUndo,
00046 CmdRedo,
00047
00048 Cmd_UpperEdge,
00049 Cmd_Count = Cmd_UpperEdge-Cmd_LowerEdge-1,
00050
00051 Cmd_KeyRedDefault = CmdMark,
00052 Cmd_KeyGreenDefault = CmdUndo,
00053 Cmd_KeyYellowDefault = CmdRedo
00054 };
00055 }
00056
00057
00058 using namespace SudokuPlugin;
00059
00060
00061
00062
00063
00064 const struct CommandList::List CommandList::list[] =
00065 {
00066 { CmdGenerate, trNOOP("Generate a new puzzle"), &Menu::generate },
00067 { CmdLoad, trNOOP("Load a puzzle"), &Menu::load },
00068 { CmdSave, trNOOP("Save the puzzle"), &Menu::save },
00069 { CmdUndo, trNOOP("Undo last action"), &Menu::undo },
00070 { CmdRedo, trNOOP("Redo last action"), &Menu::redo },
00071 { CmdMark, trNOOP("Mark/unmark"), &Menu::toggle_mark },
00072 { CmdNextCell, trNOOP("Next cell"), &Menu::next_cell },
00073 { CmdNextNumber, trNOOP("Next number"), &Menu::next_number },
00074 { CmdReset, trNOOP("Reset the puzzle"), &Menu::reset },
00075 { CmdSetup, trNOOP("Open setup menu"), &Menu::open_setup },
00076 { CmdExit, trNOOP("Exit"), &Menu::exit }
00077 };
00078
00079
00080 int CommandList::id(int index)
00081 {
00082 assert(index >= 0 && index < count());
00083 return list[index].id;
00084 }
00085
00086
00087 const char* CommandList::text(int index)
00088 {
00089 assert(index >= 0 && index < count());
00090 return tr(list[index].text);
00091 }
00092
00093
00094 CommandType CommandList::command(int index)
00095 {
00096 assert(index >= 0 && index < count());
00097 return list[index].cmd;
00098 }
00099
00100
00101 int CommandList::count()
00102 {
00103 assert(Cmd_Count == sizeof(list)/sizeof(*list));
00104 return Cmd_Count;
00105 }
00106
00107
00108 const char* const* CommandList::texts()
00109 {
00110 static const char* text_list[Cmd_Count];
00111 for (int idx = 0; idx < count(); ++idx)
00112 text_list[idx] = tr(list[idx].text);
00113 return text_list;
00114 }
00115
00116
00117 int CommandList::id_to_index(int id, int default_index)
00118 {
00119 int idx = 0;
00120 for (; idx < count(); ++idx)
00121 if (list[idx].id == id)
00122 break;
00123 if (idx >= count())
00124 idx = default_index;
00125 assert(idx >= 0 && idx < count());
00126 return idx;
00127 }
00128
00129
00130 int CommandList::key_red_default_index()
00131 {
00132 return id_to_index(Cmd_KeyRedDefault);
00133 }
00134
00135
00136 int CommandList::key_green_default_index()
00137 {
00138 return id_to_index(Cmd_KeyGreenDefault);
00139 }
00140
00141
00142 int CommandList::key_yellow_default_index()
00143 {
00144 return id_to_index(Cmd_KeyYellowDefault);
00145 }
00146
00147
00148
00149
00150
00151 CommandMenu::CommandMenu() :
00152 cOsdMenu(trVDR("Commands"))
00153 {
00154 SetHasHotkeys();
00155 for (int idx = 0; idx < CommandList::count(); ++idx)
00156 Add(new Command(hk(CommandList::text(idx)), CommandList::command(idx)));
00157 command = NULL;
00158 }
00159
00160
00161 CommandType CommandMenu::get_selected_command() const
00162 {
00163 return command;
00164 }
00165
00166
00167 eOSState CommandMenu::ProcessKey(eKeys key)
00168 {
00169 eOSState state = cOsdMenu::ProcessKey(key);
00170 if (state == osUnknown)
00171 {
00172 state = osContinue;
00173 if (key == kOk)
00174 {
00175 Command* item = (Command*)Get(Current());
00176 if (item)
00177 command = item->get_command();
00178 state = osBack;
00179 }
00180 }
00181 return state;
00182 }
00183
00184
00185
00186
00187
00188 Command::Command(const char* text, CommandType command) :
00189 cOsdItem(text), command(command)
00190 {
00191 assert(text != NULL);
00192 assert(command != NULL);
00193 }
00194
00195
00196 CommandType Command::get_command() const
00197 {
00198 return command;
00199 }