right_on_gump = false;
if (right_on_gump && !(gump_man->can_right_click_close() && gump_man->gump_mode() && gump_man->find_gump(event.motion.x / scale, event.motion.y / scale, false))) { right_on_gump = false; }
static void Handle_event	(	SDL_Event& event	)	{	// Mouse scale factor	int scale = gwin->get_fastmouse() ? 1 : gwin->get_win()->get_scale();	bool dont_move_mode = gwin->main_actor_dont_move() &&				!cheat.in_map_editor();	// We want this	Gump_manager *gump_man = gwin->get_gump_man();	static bool right_on_gump = false;	Gump *gump = 0;					// For detecting double-clicks.	static uint32 last_b1_click = 0, last_b3_click = 0;	//cout << "Event " << (int) event.type << " received"<<endl;	switch (event.type)		{	case SDL_MOUSEBUTTONDOWN:		{        	if (dont_move_mode)        		break;		int x = event.button.x/scale, y = event.button.y/scale;		if (event.button.button == 1)			{#ifdef USE_EXULTSTUDIO			if (cheat.in_map_editor())				{	// Paint if shift-click.				if (cheat.get_edit_shape() >= 0 &&					// But always if painting.			    	    (cheat.get_edit_mode() == Cheat::paint ||					(SDL_GetModState() & KMOD_SHIFT)))					{					Paint_with_shape(event, false);					break;					}				else if (cheat.get_edit_chunknum() >= 0 &&				  cheat.get_edit_mode() == Cheat::paint_chunks)					{					Paint_with_chunk(event, false);					break;					}					// Don't drag if not in 'move' mode.				else if (cheat.get_edit_mode() != Cheat::move)					break;				}#endif			dragging = gwin->start_dragging(x, y);			//Mouse::mouse->set_shape(Mouse::hand);			dragged = false;			}					// Move sprite toward mouse					//  when right button pressed.		if (gwin->get_mouse3rd())			if (event.button.button == 2)				{					ActionTarget(0);				}		if (event.button.button == 3) {						// Try removing old queue entry.			gwin->get_tqueue()->remove(gwin->get_main_actor());			if (!dragging &&	// Causes crash if dragging.				gump_man->can_right_click_close() &&					gump_man->gump_mode() && 					gump_man->find_gump(x, y, false)) {				gump = 0;				right_on_gump = true;			}			else 				gwin->start_actor(x, y, 						Mouse::mouse->avatar_speed);		}		if (event.button.button == 4 || event.button.button == 5) 			{			if (!cheat()) break;			SDLMod mod = SDL_GetModState();			if (event.button.button == 4)				if (mod & KMOD_ALT)					ActionScrollLeft(0);				else					ActionScrollUp(0);			else				if (mod & KMOD_ALT)					ActionScrollRight(0);				else					ActionScrollDown(0);			}		break;		}	case SDL_MOUSEBUTTONUP:		{	        if (dont_move_mode)        	    break;		int x = event.button.x/scale, y = event.button.y/scale;		if (event.button.button == 3)			{			uint32 curtime = SDL_GetTicks();					// Last click within .5 secs?			if (gwin->get_allow_double_right_move() && curtime - last_b3_click < 500)				gwin->start_actor_along_path(x, y,						Mouse::mouse->avatar_speed);			else if (right_on_gump && 				(gump = gump_man->find_gump(x, y, false))) {				Rectangle dirty = gump->get_dirty();				gwin->add_dirty(dirty);				gump_man->close_gump(gump);				gump = 0;				right_on_gump = false;			}			else				{				gwin->stop_actor();				if (Combat::is_paused() && gwin->in_combat())					gwin->paused_combat_select(x, y);				}			last_b3_click = curtime;			}		else if (event.button.button == 1)			{			uint32 curtime = SDL_GetTicks();			bool click_handled = false;			if (dragging) {				click_handled = gwin->drop_dragged(x, y,								dragged);				Mouse::mouse->set_speed_cursor();			}					// Last click within .5 secs?			if (curtime - last_b1_click < 500)				{				dragging = dragged = false;				gwin->double_clicked(x, y);				Mouse::mouse->set_speed_cursor();				break;				}			if (!dragging || !dragged)				last_b1_click = curtime;			if (!click_handled) {					// Identify item(s) clicked on.				gwin->show_items(x, y, 					(SDL_GetModState() & KMOD_CTRL) != 0);			}			dragging = dragged = false;			}		break;		}	case SDL_MOUSEMOTION:		{		Mouse::mouse->move(event.motion.x / scale, 						event.motion.y / scale);		if (!dragging)			Mouse::mouse->set_speed_cursor();		Mouse::mouse_update = true;	// Need to blit mouse.		right_on_gump = false;					// Dragging with left button?		if (event.motion.state & SDL_BUTTON(1))			{#ifdef USE_EXULTSTUDIO			// Painting?			if (cheat.in_map_editor())				{ 				if (cheat.get_edit_shape() >= 0 &&				    (cheat.get_edit_mode() == Cheat::paint ||					(SDL_GetModState() & KMOD_SHIFT)))					{					Paint_with_shape(event, true);					break;					}				else if (cheat.get_edit_chunknum() >= 0 &&				  cheat.get_edit_mode() == Cheat::paint_chunks)					{					Paint_with_chunk(event, true);					break;					}				}#endif			dragged = gwin->drag(event.motion.x / scale, 						event.motion.y / scale);			}					// Dragging with right?		else if ((event.motion.state & SDL_BUTTON(3)))			gwin->start_actor(event.motion.x / scale, 			event.motion.y / scale, Mouse::mouse->avatar_speed);#ifdef USE_EXULTSTUDIO			// Painting?		else if (cheat.in_map_editor() && 			 cheat.get_edit_shape() >= 0 &&			 (cheat.get_edit_mode() == Cheat::paint ||					(SDL_GetModState() & KMOD_SHIFT)))			{			static int prevx = -1, prevy = -1;			Move_dragged_shape(cheat.get_edit_shape(),				cheat.get_edit_frame(), 				event.motion.x, event.motion.y, 						prevx, prevy, false);			prevx = event.motion.x; prevy = event.motion.y;			}#endif		break;		}	case SDL_ACTIVEEVENT:		if (event.active.state & SDL_APPMOUSEFOCUS)			{			if (event.active.gain)				{				int x, y;				SDL_GetMouseState(&x, &y);				Mouse::mouse->set_location(x/scale, y/scale);				}			gwin->set_painted();			}		if (event.active.state & SDL_APPINPUTFOCUS)			{			if (event.active.gain)				gwin->get_focus();			else				gwin->lose_focus();			}#if 0		if (event.active.state & SDL_APPACTIVE)					// Became active.			if (event.active.gain)				gwin->init_actors();#endif		break;#if 0	case ConfigureNotify:		// Resize.		gwin->resized(event.xconfigure.window,			event.xconfigure.width, event.xconfigure.height);		break;#endif	case SDL_QUIT:		gwin->get_gump_man()->okay_to_quit();		break;	case SDL_KEYDOWN:		// Keystroke.	case SDL_KEYUP:		if (!dragging &&	// ESC while dragging causes crashes.		    !gwin->get_gump_man()->handle_kbd_event(&event))			keybinder->HandleEvent(event);		break;#ifdef USE_EXULTSTUDIO#ifndef WIN32	case SDL_SYSWMEVENT:		{		XEvent& ev = event.syswm.msg->event.xevent;		if (ev.type == ClientMessage)			xdnd->client_msg((XClientMessageEvent&) ev);		else if (ev.type == SelectionNotify)			xdnd->select_msg((XSelectionEvent&) ev);		break;		}#endif#endif#if 0//#ifdef WIN32	case SDL_SYSWMEVENT://		printf("SYSWMEVENT received, %x\n", event.syswm.msg->msg);		if (event.syswm.msg->msg == MM_MCINOTIFY) {#if DEBUG			cerr << "MM_MCINOTIFY message received"<<endl;#endif			((Windows_MCI*)(Audio::get_ptr()->get_midi()))->callback(event.syswm.msg->wParam, 							event.syswm.msg->hwnd);		}		break;#endif		}	}