Allow variable arguments to command functions
[lsnes.git] / window.hpp
blob8a53accbecc4ad7f208101656dbe5ae482ac3986
1 #ifndef _window__hpp__included__
2 #define _window__hpp__included__
4 #include "SDL.h"
5 #include "render.hpp"
6 #include <string>
7 #include <map>
8 #include <list>
9 #include <stdexcept>
11 #define WINSTATE_NORMAL 0
12 #define WINSTATE_COMMAND 1
13 #define WINSTATE_MODAL 2
14 #define WINSTATE_IDENTIFY 3
16 class window;
18 /**
19 * This is a handle to graphics system. Note that creating multiple contexts produces undefined results.
21 class window
23 public:
24 window() throw() {}
26 /**
27 * Initialize the graphics system.
29 static void init();
31 /**
32 * Shut down the graphics system.
34 static void quit();
36 /**
37 * Adds a messages to mesage queue to be shown.
39 * parameter msg: The messages to add (split by '\n').
40 * throws std::bad_alloc: Not enough memory.
42 static void message(const std::string& msg) throw(std::bad_alloc);
44 /**
45 * Get output stream printing into message queue.
47 * Note that lines printed there should be terminated by '\n'.
49 * returns: The output stream.
50 * throws std::bad_alloc: Not enough memory.
52 static std::ostream& out() throw(std::bad_alloc);
54 /**
55 * Displays a modal message, not returning until the message is acknowledged. Keybindings are not available, but
56 * should quit be generated somehow, modal message will be closed and command callback triggered.
58 * parameter msg: The message to show.
59 * parameter confirm: If true, ask for Ok/cancel type input.
60 * returns: If confirm is true, true if ok was chosen, false if cancel was chosen. Otherwise always false.
61 * throws std::bad_alloc: Not enough memory.
63 static bool modal_message(const std::string& msg, bool confirm = false) throw(std::bad_alloc);
65 /**
66 * Displays fatal error message, quitting after the user acks it.
68 static void fatal_error() throw();
70 /**
71 * Bind a key.
73 * parameter mod: Set of modifiers.
74 * parameter modmask: Modifier mask (set of modifiers).
75 * parameter keyname: Name of key or pseudo-key.
76 * parameter command: Command to run.
77 * throws std::bad_alloc: Not enough memory.
78 * throws std::runtime_error: Invalid key or modifier name, or conflict.
80 static void bind(std::string mod, std::string modmask, std::string keyname, std::string command)
81 throw(std::bad_alloc, std::runtime_error);
83 /**
84 * Unbind a key.
86 * parameter mod: Set of modifiers.
87 * parameter modmask: Modifier mask (set of modifiers).
88 * parameter keyname: Name of key or pseudo-key.
89 * throws std::bad_alloc: Not enough memory.
90 * throws std::runtime_error: Invalid key or modifier name, or not bound.
92 static void unbind(std::string mod, std::string modmask, std::string keyname) throw(std::bad_alloc,
93 std::runtime_error);
95 /**
96 * Dump bindings into this window.
98 * throws std::bad_alloc: Not enough memory.
100 static void dumpbindings() throw(std::bad_alloc);
103 * Processes inputs. If in non-modal mode (normal mode without pause), this returns quickly. Otherwise it waits
104 * for modal mode to exit.
106 * throws std::bad_alloc: Not enough memory.
108 static void poll_inputs() throw(std::bad_alloc);
111 * Get emulator status area
113 * returns: Emulator status area.
115 static std::map<std::string, std::string>& get_emustatus() throw();
118 * Notify that the screen has been updated.
120 * parameter full: Do full refresh if true.
122 static void notify_screen_update(bool full = false) throw();
125 * Set the screen to use as main surface.
127 * parameter scr: The screen to use.
129 static void set_main_surface(screen& scr) throw();
132 * Enable/Disable pause mode.
134 * parameter enable: Enable pause if true, disable otherwise.
136 static void paused(bool enable) throw();
139 * Wait specified number of milliseconds (polling for input).
141 * parameter msec: Number of ms to wait.
142 * throws std::bad_alloc: Not enough memory.
144 static void wait_msec(uint64_t msec) throw(std::bad_alloc);
147 * Cancel pending wait_msec, making it return now.
149 static void cancel_wait() throw();
152 * Enable or disable sound.
154 * parameter enable: Enable sounds if true, otherwise disable sounds.
156 static void sound_enable(bool enable) throw();
159 * Input audio sample (at 32040.5Hz).
161 * parameter left: Left sample.
162 * parameter right: Right sample.
164 static void play_audio_sample(uint16_t left, uint16_t right) throw();
167 * Set window main screen compensation parameters. This is used for mouse click reporting.
169 * parameter xoffset: X coordinate of origin.
170 * parameter yoffset: Y coordinate of origin.
171 * parameter hscl: Horizontal scaling factor.
172 * parameter vscl: Vertical scaling factor.
174 static void set_window_compensation(uint32_t xoffset, uint32_t yoffset, uint32_t hscl, uint32_t vscl);
175 private:
176 window(const window&);
177 window& operator==(const window&);
181 * Get number of msec since some undetermined epoch.
183 * returns: The number of milliseconds.
185 uint64_t get_ticks_msec() throw();
187 #endif