Reorganize the window code a bit
[lsnes.git] / generic / window.hpp
blob3bea5daccb7874f5db2a7acadd3897e9d758bf35
1 #ifndef _window__hpp__included__
2 #define _window__hpp__included__
4 #include "render.hpp"
5 #include <string>
6 #include <map>
7 #include <list>
8 #include <stdexcept>
10 #define WINSTATE_NORMAL 0
11 #define WINSTATE_COMMAND 1
12 #define WINSTATE_MODAL 2
13 #define WINSTATE_IDENTIFY 3
15 class window;
17 /**
18 * Some backnotifications.
20 class window_callback
22 public:
23 virtual ~window_callback() throw();
24 /**
25 * Called when user tries to close the window.
27 virtual void on_close() throw();
28 /**
29 * Called when user clicks on the screen.
31 virtual void on_click(int32_t x, int32_t y, uint32_t buttonmask) throw();
32 /**
33 * Do try to close the window.
35 static void do_close() throw();
36 /**
37 * Do click on the screen.
39 static void do_click(int32_t x, int32_t y, uint32_t buttonmask) throw();
40 /**
41 * Set the callback handler.
43 static void set_callback_handler(window_callback& cb) throw();
46 /**
47 * Sound/Graphics init/quit functions. Sound init is called after graphics init, and vice versa for quit.
49 * These need to be implemented by the corresponding plugins.
51 void graphics_init();
52 void sound_init();
53 void sound_quit();
54 void graphics_quit();
55 void joystick_init();
56 void joystick_quit();
58 /**
59 * This is a handle to graphics system. Note that creating multiple contexts produces undefined results.
61 class window
63 public:
64 /**
65 * Window constructor.
67 window() throw() {}
69 /**
70 * Initialize the graphics system.
72 * Implemented by generic window code.
74 static void init();
76 /**
77 * Shut down the graphics system.
79 * Implemented by generic window code.
81 static void quit();
83 /**
84 * Get output stream printing into message queue.
86 * Note that lines printed there should be terminated by '\n'.
88 * Implemented by the generic window code.
90 * returns: The output stream.
91 * throws std::bad_alloc: Not enough memory.
93 static std::ostream& out() throw(std::bad_alloc);
95 /**
96 * Get emulator status area
98 * Implemented by the generic window code.
100 * returns: Emulator status area.
102 static std::map<std::string, std::string>& get_emustatus() throw();
105 * Adds a messages to mesage queue to be shown.
107 * Needs to be implemented by the graphics plugin.
109 * parameter msg: The messages to add (split by '\n').
110 * throws std::bad_alloc: Not enough memory.
112 static void message(const std::string& msg) throw(std::bad_alloc);
115 * Displays a modal message, not returning until the message is acknowledged. Keybindings are not available, but
116 * should quit be generated somehow, modal message will be closed and command callback triggered.
118 * Needs to be implemented by the graphics plugin.
120 * parameter msg: The message to show.
121 * parameter confirm: If true, ask for Ok/cancel type input.
122 * returns: If confirm is true, true if ok was chosen, false if cancel was chosen. Otherwise always false.
123 * throws std::bad_alloc: Not enough memory.
125 static bool modal_message(const std::string& msg, bool confirm = false) throw(std::bad_alloc);
128 * Displays fatal error message, quitting after the user acks it.
130 * Needs to be implemented by the graphics plugin.
132 static void fatal_error() throw();
135 * Processes inputs. If in non-modal mode (normal mode without pause), this returns quickly. Otherwise it waits
136 * for modal mode to exit. Also needs to call poll_joysticks().
138 * Needs to be implemented by the graphics plugin.
140 * throws std::bad_alloc: Not enough memory.
142 static void poll_inputs() throw(std::bad_alloc);
145 * Notify that the screen has been updated.
147 * Needs to be implemented by the graphics plugin.
149 * parameter full: Do full refresh if true.
151 static void notify_screen_update(bool full = false) throw();
154 * Set the screen to use as main surface.
156 * Needs to be implemented by the graphics plugin.
158 * parameter scr: The screen to use.
160 static void set_main_surface(screen& scr) throw();
163 * Enable/Disable pause mode.
165 * Needs to be implemented by the graphics plugin.
167 * parameter enable: Enable pause if true, disable otherwise.
169 static void paused(bool enable) throw();
172 * Wait specified number of microseconds (polling for input).
174 * Needs to be implemented by the graphics plugin.
176 * parameter usec: Number of us to wait.
177 * throws std::bad_alloc: Not enough memory.
179 static void wait_usec(uint64_t usec) throw(std::bad_alloc);
182 * Cancel pending wait_usec, making it return now.
184 * Needs to be implemented by the graphics plugin.
186 static void cancel_wait() throw();
189 * Set window main screen compensation parameters. This is used for mouse click reporting.
191 * Needs to be implemented by the graphics plugin.
193 * parameter xoffset: X coordinate of origin.
194 * parameter yoffset: Y coordinate of origin.
195 * parameter hscl: Horizontal scaling factor.
196 * parameter vscl: Vertical scaling factor.
198 static void set_window_compensation(uint32_t xoffset, uint32_t yoffset, uint32_t hscl, uint32_t vscl);
201 * Enable or disable sound.
203 * Needs to be implemented by the sound plugin.
205 * parameter enable: Enable sounds if true, otherwise disable sounds.
207 static void sound_enable(bool enable) throw();
210 * Input audio sample (at specified rate).
212 * Needs to be implemented by the sound plugin.
214 * parameter left: Left sample.
215 * parameter right: Right sample.
217 static void play_audio_sample(uint16_t left, uint16_t right) throw();
220 * Set sound sampling rate.
222 * Needs to be implemented by the sound plugin.
224 * parameter rate_n: Numerator of sampling rate.
225 * parameter rate_d: Denomerator of sampling rate.
227 static void set_sound_rate(uint32_t rate_n, uint32_t rate_d);
230 * Has the sound system been successfully initialized?
232 * Needs to be implemented by the sound plugin.
234 static bool sound_initialized();
237 * Set sound device.
239 * Needs to be implemented by the sound plugin.
241 static void set_sound_device(const std::string& dev);
244 * Get current sound device.
246 * Needs to be implemented by the sound plugin.
248 static std::string get_current_sound_device();
251 * Get available sound devices.
253 * Needs to be implemented by the sound plugin.
255 static std::map<std::string, std::string> get_sound_devices();
257 * Poll joysticks.
259 * Needs to be implemented by the joystick plugin.
261 static void poll_joysticks();
262 private:
263 window(const window&);
264 window& operator==(const window&);
268 * Names of plugins.
270 extern const char* sound_plugin_name;
271 extern const char* graphics_plugin_name;
272 extern const char* joystick_plugin_name;
274 #endif