Direct framebuffer
[lsnes.git] / include / core / window.hpp
blobc099f49e0cf801faad914eaa37d206ab789c929f
1 #ifndef _window__hpp__included__
2 #define _window__hpp__included__
4 #include "render.hpp"
5 #include "messagebuffer.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 * Sound/Graphics init/quit functions. Sound init is called after graphics init, and vice versa for quit.
21 * These need to be implemented by the corresponding plugins.
23 void graphics_init();
24 void sound_init();
25 void sound_quit();
26 void graphics_quit();
27 void joystick_init();
28 void joystick_quit();
30 /**
31 * This is a handle to graphics system. Note that creating multiple contexts produces undefined results.
33 class window
35 public:
36 /**
37 * Window constructor.
39 window() throw() {}
41 /**
42 * Initialize the graphics system.
44 * Implemented by generic window code.
46 static void init();
48 /**
49 * Shut down the graphics system.
51 * Implemented by generic window code.
53 static void quit();
55 /**
56 * Get output stream printing into message queue.
58 * Note that lines printed there should be terminated by '\n'.
60 * Implemented by the generic window code.
62 * returns: The output stream.
63 * throws std::bad_alloc: Not enough memory.
65 static std::ostream& out() throw(std::bad_alloc);
67 /**
68 * Get emulator status area
70 * Implemented by the generic window code.
72 * returns: Emulator status area.
74 static std::map<std::string, std::string>& get_emustatus() throw();
76 /**
77 * Message buffer.
79 * Implemented by the generic window code.
81 static messagebuffer msgbuf;
83 /**
84 * Adds a messages to mesage queue to be shown.
86 * Implemented by the generic window code.
88 * parameter msg: The messages to add (split by '\n').
89 * throws std::bad_alloc: Not enough memory.
91 static void message(const std::string& msg) throw(std::bad_alloc);
93 /**
94 * Displays fatal error message, quitting after the user acks it (called by fatal_error()).
96 * Needs to be implemented by the graphics plugin.
98 static void fatal_error() throw();
101 * Enable or disable sound.
103 * Implemented by the generic window code.
105 * parameter enable: Enable sounds if true, otherwise disable sounds.
107 static void sound_enable(bool enable) throw();
110 * Are sounds enabled?
112 static bool is_sound_enabled() throw();
115 * Set sound device.
117 * Implemented by the generic window code.
119 static void set_sound_device(const std::string& dev) throw();
121 /******************************** GRAPHICS PLUGIN **********************************/
123 * Notification when messages get updated.
125 * Needs to be implemented by the graphics plugin.
127 static void notify_message() throw(std::bad_alloc, std::runtime_error);
130 * Displays a modal message, not returning until the message is acknowledged. Keybindings are not available, but
131 * should quit be generated somehow, modal message will be closed and command callback triggered.
133 * Needs to be implemented by the graphics plugin.
135 * parameter msg: The message to show.
136 * parameter confirm: If true, ask for Ok/cancel type input.
137 * returns: If confirm is true, true if ok was chosen, false if cancel was chosen. Otherwise always false.
138 * throws std::bad_alloc: Not enough memory.
140 static bool modal_message(const std::string& msg, bool confirm = false) throw(std::bad_alloc);
143 * Displays fatal error message, quitting after the user acks it (called by fatal_error()).
145 * Needs to be implemented by the graphics plugin.
147 static void fatal_error2() throw();
150 * Processes inputs. If in non-modal mode (normal mode without pause), this returns quickly. Otherwise it waits
151 * for modal mode to exit. Also needs to call window::poll_joysticks().
153 * Needs to be implemented by the graphics plugin.
155 * throws std::bad_alloc: Not enough memory.
157 static void poll_inputs() throw(std::bad_alloc);
160 * Enable/Disable pause mode.
162 * Needs to be implemented by the graphics plugin.
164 * parameter enable: Enable pause if true, disable otherwise.
166 static void paused(bool enable) throw();
169 * Wait specified number of microseconds (polling for input).
171 * Needs to be implemented by the graphics plugin.
173 * parameter usec: Number of us to wait.
174 * throws std::bad_alloc: Not enough memory.
176 static void wait_usec(uint64_t usec) throw(std::bad_alloc);
179 * Cancel pending wait_usec, making it return now.
181 * Needs to be implemented by the graphics plugin.
183 static void cancel_wait() throw();
185 /******************************** SOUND PLUGIN **********************************/
187 * Enable or disable sound.
189 * Needs to be implemented by the sound plugin.
191 * parameter enable: Enable sounds if true, otherwise disable sounds.
193 static void _sound_enable(bool enable) throw();
196 * Input audio sample (at specified rate).
198 * Needs to be implemented by the sound plugin.
200 * parameter left: Left sample.
201 * parameter right: Right sample.
203 static void play_audio_sample(uint16_t left, uint16_t right) throw();
206 * Has the sound system been successfully initialized?
208 * Needs to be implemented by the sound plugin.
210 static bool sound_initialized();
213 * Set sound device.
215 * Needs to be implemented by the sound plugin.
217 static void _set_sound_device(const std::string& dev);
220 * Get current sound device.
222 * Needs to be implemented by the sound plugin.
224 static std::string get_current_sound_device();
227 * Get available sound devices.
229 * Needs to be implemented by the sound plugin.
231 static std::map<std::string, std::string> get_sound_devices();
233 /******************************** JOYSTICK PLUGIN **********************************/
235 * Poll joysticks.
237 * Needs to be implemented by the joystick plugin.
239 static void poll_joysticks();
240 private:
241 window(const window&);
242 window& operator==(const window&);
247 * Names of plugins.
249 extern const char* sound_plugin_name;
250 extern const char* graphics_plugin_name;
251 extern const char* joystick_plugin_name;
253 #endif