3 #include <boost/iostreams/categories.hpp>
4 #include <boost/iostreams/copy.hpp>
5 #include <boost/iostreams/stream.hpp>
6 #include <boost/iostreams/stream_buffer.hpp>
7 #include <boost/iostreams/filter/symmetric.hpp>
8 #include <boost/iostreams/filter/zlib.hpp>
9 #include <boost/iostreams/filtering_stream.hpp>
10 #include <boost/iostreams/device/back_inserter.hpp>
14 function_ptr_command
<> identify_key("show-plugins", "Show plugins in use",
15 "Syntax: show-plugins\nShows plugins in use.\n",
16 []() throw(std::bad_alloc
, std::runtime_error
) {
17 window::message(std::string("Graphics:\t") + graphics_plugin_name
);
18 window::message(std::string("Sound:\t") + sound_plugin_name
);
19 window::message(std::string("Joystick:\t") + joystick_plugin_name
);
22 function_ptr_command
<const std::string
&> enable_sound("enable-sound", "Enable/Disable sound",
23 "Syntax: enable-sound <on/off>\nEnable or disable sound.\n",
24 [](const std::string
& args
) throw(std::bad_alloc
, std::runtime_error
) {
26 if(s
== "on" || s
== "true" || s
== "1" || s
== "enable" || s
== "enabled") {
27 if(!window::sound_initialized())
28 throw std::runtime_error("Sound failed to initialize and is disabled");
29 window::sound_enable(true);
30 } else if(s
== "off" || s
== "false" || s
== "0" || s
== "disable" || s
== "disabled") {
31 if(window::sound_initialized())
32 window::sound_enable(false);
34 throw std::runtime_error("Bad sound setting");
37 function_ptr_command
<const std::string
&> set_sound_device("set-sound-device", "Set sound device",
38 "Syntax: set-sound-device <id>\nSet sound device to <id>.\n",
39 [](const std::string
& args
) throw(std::bad_alloc
, std::runtime_error
) {
40 if(!window::sound_initialized())
41 throw std::runtime_error("Sound failed to initialize and is disabled");
42 window::set_sound_device(args
);
45 function_ptr_command
<> get_sound_devices("show-sound-devices", "Show sound devices",
46 "Syntax: show-sound-devices\nShow listing of available sound devices\n",
47 []() throw(std::bad_alloc
, std::runtime_error
) {
48 if(!window::sound_initialized())
49 throw std::runtime_error("Sound failed to initialize and is disabled");
50 auto r
= window::get_sound_devices();
51 auto s
= window::get_current_sound_device();
52 std::string dname
= "unknown";
55 window::out() << "Detected " << r
.size() << " sound output devices."
58 window::out() << "Audio device " << i
.first
<< ": " << i
.second
<< std::endl
;
59 window::out() << "Currently using device " << window::get_current_sound_device() << " ("
60 << dname
<< ")" << std::endl
;
63 function_ptr_command
<> get_sound_status("show-sound-status", "Show sound status",
64 "Syntax: show-sound-status\nShow current sound status\n",
65 []() throw(std::bad_alloc
, std::runtime_error
) {
66 window::out() << "Sound plugin: " << sound_plugin_name
<< std::endl
;
67 if(!window::sound_initialized())
68 window::out() << "Sound initialization failed, sound disabled" << std::endl
;
70 auto r
= window::get_sound_devices();
71 auto s
= window::get_current_sound_device();
72 std::string dname
= "unknown";
75 window::out() << "Current sound device " << s
<< " (" << dname
<< ")" << std::endl
;
82 typedef char char_type
;
83 typedef boost::iostreams::sink_tag category
;
84 window_output(window
* win
)
92 std::streamsize
write(const char* s
, std::streamsize n
)
94 size_t oldsize
= stream
.size();
95 stream
.resize(oldsize
+ n
);
96 memcpy(&stream
[oldsize
], s
, n
);
98 size_t lf
= stream
.size();
99 for(size_t i
= 0; i
< stream
.size(); i
++)
100 if(stream
[i
] == '\n') {
104 if(lf
== stream
.size())
106 std::string
foo(stream
.begin(), stream
.begin() + lf
);
107 window::message(foo
);
108 if(lf
+ 1 < stream
.size())
109 memmove(&stream
[0], &stream
[lf
+ 1], stream
.size() - lf
- 1);
110 stream
.resize(stream
.size() - lf
- 1);
115 std::vector
<char> stream
;
118 window_callback
* wcb
= NULL
;
135 std::ostream
& window::out() throw(std::bad_alloc
)
137 static std::ostream
* cached
= NULL
;
140 cached
= new boost::iostreams::stream
<window_output
>(win
);
144 window_callback::~window_callback() throw()
148 void window_callback::on_close() throw()
152 void window_callback::on_click(int32_t x
, int32_t y
, uint32_t buttonmask
) throw()
156 void window_callback::do_close() throw()
162 void window_callback::do_click(int32_t x
, int32_t y
, uint32_t buttonmask
) throw()
165 wcb
->on_click(x
, y
, buttonmask
);
168 void window_callback::set_callback_handler(window_callback
& cb
) throw()