Use dedicated callbacks for mouse/close, not commands
This commit is contained in:
parent
20521e13dd
commit
f0c3f7b61c
4 changed files with 104 additions and 25 deletions
|
@ -948,7 +948,7 @@ namespace
|
|||
return;
|
||||
}
|
||||
if(e.type == SDL_QUIT) {
|
||||
command::invokeC("quit-emulator");
|
||||
window_callback::do_close();
|
||||
state = WINSTATE_NORMAL;
|
||||
return;
|
||||
}
|
||||
|
@ -978,11 +978,7 @@ namespace
|
|||
else
|
||||
mouse_mask &= ~4;
|
||||
}
|
||||
{
|
||||
std::ostringstream x;
|
||||
x << "mouse_button " << xc << " " << yc << " " << mouse_mask;
|
||||
command::invokeC(x.str());
|
||||
}
|
||||
window_callback::do_click(xc, yc, mouse_mask);
|
||||
}
|
||||
if(e.type == SDL_KEYDOWN && key == SDLK_ESCAPE)
|
||||
return;
|
||||
|
@ -1170,7 +1166,7 @@ bool window::modal_message(const std::string& msg, bool confirm) throw(std::bad_
|
|||
bool ret = modconfirm;
|
||||
if(delayed_close_flag) {
|
||||
delayed_close_flag = false;
|
||||
command::invokeC("quit-emulator");
|
||||
window_callback::do_close();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -1364,6 +1360,10 @@ void poll_inputs_internal() throw(std::bad_alloc)
|
|||
while(state != WINSTATE_NORMAL) {
|
||||
if(SDL_WaitEvent(&e))
|
||||
do_event(e);
|
||||
if(delayed_close_flag) {
|
||||
state = WINSTATE_NORMAL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -780,24 +780,6 @@ namespace
|
|||
while(1);
|
||||
});
|
||||
|
||||
function_ptr_command<tokensplitter&> mouse_button_handler("mouse_button", "no description available",
|
||||
"No help available\n",
|
||||
[](tokensplitter& t) throw(std::bad_alloc, std::runtime_error) {
|
||||
std::string x = t;
|
||||
std::string y = t;
|
||||
std::string b = t;
|
||||
int _x = atoi(x.c_str());
|
||||
int _y = atoi(y.c_str());
|
||||
int _b = atoi(b.c_str());
|
||||
if(_b & ~prev_mouse_mask & 1)
|
||||
send_analog_input(_x, _y, 0);
|
||||
if(_b & ~prev_mouse_mask & 2)
|
||||
send_analog_input(_x, _y, 1);
|
||||
if(_b & ~prev_mouse_mask & 4)
|
||||
send_analog_input(_x, _y, 2);
|
||||
prev_mouse_mask = _b;
|
||||
});
|
||||
|
||||
class button_action : public command
|
||||
{
|
||||
public:
|
||||
|
@ -867,6 +849,42 @@ namespace
|
|||
}
|
||||
} bah;
|
||||
|
||||
bool on_quit_prompt = false;
|
||||
class mywindowcallbacks : public window_callback
|
||||
{
|
||||
public:
|
||||
void on_close() throw()
|
||||
{
|
||||
if(on_quit_prompt) {
|
||||
amode = ADVANCE_QUIT;
|
||||
window::paused(false);
|
||||
window::cancel_wait();
|
||||
return;
|
||||
}
|
||||
on_quit_prompt = true;
|
||||
try {
|
||||
if(window::modal_message("Really quit?", true)) {
|
||||
amode = ADVANCE_QUIT;
|
||||
window::paused(false);
|
||||
window::cancel_wait();
|
||||
}
|
||||
} catch(...) {
|
||||
}
|
||||
on_quit_prompt = false;
|
||||
}
|
||||
|
||||
void on_click(int32_t x, int32_t y, uint32_t buttonmask) throw()
|
||||
{
|
||||
if(buttonmask & ~prev_mouse_mask & 1)
|
||||
send_analog_input(x, y, 0);
|
||||
if(buttonmask & ~prev_mouse_mask & 2)
|
||||
send_analog_input(x, y, 1);
|
||||
if(buttonmask & ~prev_mouse_mask & 4)
|
||||
send_analog_input(x, y, 2);
|
||||
prev_mouse_mask = buttonmask;
|
||||
}
|
||||
} mywcb;
|
||||
|
||||
//If there is a pending load, perform it. Return 1 on successful load, 0 if nothing to load, -1 on load
|
||||
//failing.
|
||||
int handle_load()
|
||||
|
@ -987,6 +1005,7 @@ void main_loop(struct loaded_rom& rom, struct moviefile& initial, bool load_has_
|
|||
SNES::system.interface = &intrf;
|
||||
status = &window::get_emustatus();
|
||||
autofire_pattern.push_back(controls_t());
|
||||
window_callback::set_callback_handler(mywcb);
|
||||
|
||||
//Load our given movie.
|
||||
bool first_round = false;
|
||||
|
|
|
@ -48,6 +48,8 @@ namespace
|
|||
protected:
|
||||
std::vector<char> stream;
|
||||
};
|
||||
|
||||
window_callback* wcb = NULL;
|
||||
}
|
||||
|
||||
std::ostream& window::out() throw(std::bad_alloc)
|
||||
|
@ -58,3 +60,32 @@ std::ostream& window::out() throw(std::bad_alloc)
|
|||
cached = new boost::iostreams::stream<window_output>(win);
|
||||
return *cached;
|
||||
}
|
||||
|
||||
window_callback::~window_callback() throw()
|
||||
{
|
||||
}
|
||||
|
||||
void window_callback::on_close() throw()
|
||||
{
|
||||
}
|
||||
|
||||
void window_callback::on_click(int32_t x, int32_t y, uint32_t buttonmask) throw()
|
||||
{
|
||||
}
|
||||
|
||||
void window_callback::do_close() throw()
|
||||
{
|
||||
if(wcb)
|
||||
wcb->on_close();
|
||||
}
|
||||
|
||||
void window_callback::do_click(int32_t x, int32_t y, uint32_t buttonmask) throw()
|
||||
{
|
||||
if(wcb)
|
||||
wcb->on_click(x, y, buttonmask);
|
||||
}
|
||||
|
||||
void window_callback::set_callback_handler(window_callback& cb) throw()
|
||||
{
|
||||
wcb = &cb;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,35 @@
|
|||
|
||||
class window;
|
||||
|
||||
/**
|
||||
* Some backnotifications.
|
||||
*/
|
||||
class window_callback
|
||||
{
|
||||
public:
|
||||
virtual ~window_callback() throw();
|
||||
/**
|
||||
* Called when user tries to close the window.
|
||||
*/
|
||||
virtual void on_close() throw();
|
||||
/**
|
||||
* Called when user clicks on the screen.
|
||||
*/
|
||||
virtual void on_click(int32_t x, int32_t y, uint32_t buttonmask) throw();
|
||||
/**
|
||||
* Do try to close the window.
|
||||
*/
|
||||
static void do_close() throw();
|
||||
/**
|
||||
* Do click on the screen.
|
||||
*/
|
||||
static void do_click(int32_t x, int32_t y, uint32_t buttonmask) throw();
|
||||
/**
|
||||
* Set the callback handler.
|
||||
*/
|
||||
static void set_callback_handler(window_callback& cb) throw();
|
||||
};
|
||||
|
||||
/**
|
||||
* This is a handle to graphics system. Note that creating multiple contexts produces undefined results.
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue