Exemplo n.º 1
0
void XBOX_PumpEvents(_THIS)
{
	XInput_GetEvents();

	mouse_update();
	keyboard_update();
}
Exemplo n.º 2
0
/*
===========
IN_Commands
===========
*/
void RW_IN_Commands (void)
{
	if (!UseMouse)
		return;

	// poll mouse values
	mouse_update();

	// perform button actions
	if ((mouse_buttonstate & MOUSE_LEFTBUTTON) &&
		!(mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
		in_state->Key_Event_fp (K_MOUSE1, true);
	else if (!(mouse_buttonstate & MOUSE_LEFTBUTTON) &&
		(mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
		in_state->Key_Event_fp (K_MOUSE1, false);

	if ((mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
		!(mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
		in_state->Key_Event_fp (K_MOUSE2, true);
	else if (!(mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
		(mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
		in_state->Key_Event_fp (K_MOUSE2, false);

	if ((mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
		!(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
		Key_Event_fp (K_MOUSE3, true);
	else if (!(mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
		(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
		in_state->Key_Event_fp (K_MOUSE3, false);

	mouse_oldbuttonstate = mouse_buttonstate;
}
Exemplo n.º 3
0
static void
msg_loop()
{
    unsigned int previous_time;

    SDL_Event event;
    while( framework_running ) {
	SDL_PumpEvents();
	keyboard_update();
	mouse_update();
	while( SDL_PollEvent( &event ) ) {
	    switch( event.type ) {
		case SDL_MOUSEMOTION:
		    handle_mouse(&event.motion);
		    break;
		case SDL_VIDEORESIZE:
		    handle_resize(event.resize.w, event.resize.h);
		    break;
		default:
		    break;
	    }
	}
	previous_time = SDL_GetTicks();
	draw_frame(delta_time);
	SDL_GL_SwapBuffers();	
	delta_time = SDL_GetTicks() - previous_time;
	calc_fps();
    }
}
Exemplo n.º 4
0
int
ui_event( void )
{
  keyboard_update();
  mouse_update();
  return 0;
}
Exemplo n.º 5
0
void
client_main_loop (void)
{
    int quit = 0;
    int engine_updated = 0;

    /* Set up the game */
    reset_start_time ();

    update_avail_modules (0);

    screen_full_refresh ();

    if (no_init_help == 0) {
	block_help_exit = 1;
	help_flag = 1;
	if (make_dir_ok_flag) {
	    activate_help ("ask-dir.hlp");
	    make_dir_ok_flag = 0;
	} else {
	    activate_help ("opening.hlp");
	}
    }

    /* Set speed */
#if defined (CS_PROFILE) || defined (START_FAST_SPEED)
    select_fast ();
#else
    select_medium ();
#endif
    /* Main Loop */
    do {
	int key;

	/* Get timestamp for this iteration */
	get_real_time();

	/* Process events */
#if defined (LC_X11)
	call_event ();
	key = x_key_value;
	x_key_value = 0;
#elif defined (WIN32)
	call_event ();
	key = GetKeystroke ();
#else
	mouse_update ();
	key = vga_getkey ();
#endif
	/* nothing happened if key == 0 XXX: right? */
	/* GCS: I'm not sure */
	if (key != 0) {
            process_keystrokes (key);
	}
	/* Simulate the timestep */
	quit = execute_timestep ();
    } while (quit == 0);
}
Exemplo n.º 6
0
int get_svga_message(void)
{
	if ((savechar = vga_getkey()))
		return GuiKeyboardEvent;

	if (mouse_update())
		return GuiMouseEvent;
			
	return FALSE;
}
Exemplo n.º 7
0
void I_StartTic (void)
{
	keyboard_update();

	if (usemouse)
		mouse_update();

#ifdef USE_JOYSTICK
	if (usejoystick)
		joystick_events();
#endif
}
Exemplo n.º 8
0
void
IN_Move ( usercmd_t *cmd )
{
	if (!UseMouse) return;

	/* Poll mouse values */
	while (mouse_update())
		;

	if (m_filter->value) {
		mouse_x = (mx + old_mouse_x) * 0.5;
		mouse_y = (my + old_mouse_y) * 0.5;
	} else {
		mouse_x = mx;
		mouse_y = my;
	}
	old_mouse_x = mx;
	old_mouse_y = my;
	/* Clear for next update */
	mx = my = 0;

	mouse_x *= sensitivity->value;
	mouse_y *= sensitivity->value;

	/* Add mouse X/Y movement to cmd */
	if ( (in_strafe.state & 1) ||
		(lookstrafe->value && (in_mlook.state & 1) )) {
		cmd->sidemove += m_side->value * mouse_x;
	} else {
		cl.viewangles[YAW] -= m_yaw->value * mouse_x;
	}

	if ((in_mlook.state & 1)) V_StopPitchDrift();

	if ((in_mlook.state & 1) && !(in_strafe.state & 1)) {
		cl.viewangles[PITCH] += m_pitch->value * mouse_y;
		if (cl.viewangles[PITCH] > 80) {
			cl.viewangles[PITCH] = 80;
		}
		if (cl.viewangles[PITCH] < -70) {
			cl.viewangles[PITCH] = -70;
		}
	} else {
		if ((in_strafe.state & 1) && noclip_anglehack) {
			cmd->upmove -= m_forward->value * mouse_y;
		} else {
			cmd->forwardmove -= m_forward->value * mouse_y;
		}
	}
}
Exemplo n.º 9
0
/*
===========
IN_Move
===========
*/
void RW_IN_Move (usercmd_t *cmd)
{
	if (!UseMouse)
		return;

	// poll mouse values
	mouse_update();

	if (m_filter->value)
	{
		mouse_x = (mx + old_mouse_x) * 0.5;
		mouse_y = (my + old_mouse_y) * 0.5;
	}
	else
	{
		mouse_x = mx;
		mouse_y = my;
	}
	old_mouse_x = mx;
	old_mouse_y = my;

	if (!mx && !my)
		return;

	mx = my = 0; // clear for next update

	mouse_x *= sensitivity->value;
	mouse_y *= sensitivity->value;

// add mouse X/Y movement to cmd
	if ( (*in_state->in_strafe_state & 1) || 
		(lookstrafe->value && mlooking ))
		cmd->sidemove += m_side->value * mouse_x;
	else
		in_state->viewangles[YAW] -= m_yaw->value * mouse_x;

	if ( (mlooking || freelook->value) && 
		!(*in_state->in_strafe_state & 1))
	{
		in_state->viewangles[PITCH] += m_pitch->value * mouse_y;
	}
	else
	{
		cmd->forwardmove -= m_forward->value * mouse_y;
	}
}
Exemplo n.º 10
0
static int 
Qvfb_Read(
	int *px, 
	int *py, 
	int *pb
)
{   
	if(mouse_flag<0)
		acoral_delay_self(50);
	else
		mouse_flag--;
	if(mouse_update()){			
		mouse_getxy(px,py);
		*pb = mouse_getbutton();
		mouse_flag=MOUSE_SENSE;
		return 1;
	}
	return 0;
}
Exemplo n.º 11
0
void mouseb_svgalib_poll(void)
{
	log_debug(("mouseb:svgalib: mouseb_svgalib_poll()\n"));

	/* update the position */
	mouse_update();

	/* get the new position */
	svgalib_state.x += mouse_getx();
	svgalib_state.y += mouse_gety();
	svgalib_state.button_mask = mouse_getbutton();

	/* clear the current position */
	mouse_setposition(0, 0);

	/* the range must be reset on a video mode change */
	mouse_setxrange(-8191, 8191);
	mouse_setyrange(-8191, 8191);

	log_debug(("mouseb:svgalib: mouseb_svgalib_poll() -> %d,%d,%d\n", svgalib_state.x, svgalib_state.y, svgalib_state.button_mask));
}
Exemplo n.º 12
0
static int wait_event (int which, fd_set *in, fd_set *out, fd_set *except, 
                struct timeval *timeout)
#endif
{
    ggi_event_mask mask = 0;
    int retval;

    if (which & IAL_MOUSEEVENT) {
        mask |= emKeyPress | emKeyRelease;
    }
    if (which & IAL_KEYEVENT) {
        mask |= emPointer;
    }

#ifdef _LITE_VERSION
    retval = ggiEventSelect(PHYSICALGC.visual, &mask, maxfd + 1, in, out, except,
                timeout);
#else
    /* GRR, this braindead vga_waitevent() doesn't take the n argument of
       select() */
    retval = ggiEventSelect(PHYSICALGC.visual, &mask, FD_SETSIZE, in, out, except,
                timeout);
#endif
    if (retval < 0) {
        return -1;
    }

    retval = 0;
    if (mask & emPointer) {
        retval |= IAL_MOUSEEVENT;

        mouse_update();
    }
    if (mask & (emKeyPress | emKeyRelease)) {
        retval |= IAL_KEYEVENT;
        keyboard_update();
    }

    return retval;
}
Exemplo n.º 13
0
Arquivo: svga.c Projeto: bernds/UAE
void handle_events (void)
{
    int button = mouse_getbutton ();

    gui_requested = 0;
    keyboard_update ();
    mouse_update ();
    lastmx += mouse_getx ();
    lastmy += mouse_gety ();
    mouse_setposition (0, 0);

    buttonstate[0] = button & 4;
    buttonstate[1] = button & 2;
    buttonstate[2] = button & 1;

#ifdef PICASSO96
    if (screen_is_picasso && !picasso_vidinfo.extra_mem) {
	int i;
	char *addr = gfxmemory + (picasso96_state.Address - gfxmem_start);
	for (i = 0; i < picasso_vidinfo.height; i++, addr += picasso96_state.BytesPerRow) {
	    if (!picasso_invalid_lines[i])
		continue;
	    picasso_invalid_lines[i] = 0;
	    vga_drawscanline (i, addr);
	}
    }
#endif

    if (!screen_is_picasso && gui_requested) {
	leave_graphics_mode ();
	gui_changesettings ();
	enter_graphics_mode (vgamode);
	if (linear_mem != NULL && !need_dither)
	    gfxvidinfo.bufmem = linear_mem;
	restore_vga_colors ();
	notice_screen_contents_lost ();
    }
}
Exemplo n.º 14
0
void
IN_Frame ( void )
{
#ifdef QUAKEWORLD
	if (UseMouse)
#else
	if (UseMouse && cls.state != ca_dedicated)
#endif
	{
		/* Poll mouse values */
		while (mouse_update())
			;

		/* Perform button actions */
		if ((mouse_buttonstate & MOUSE_LEFTBUTTON) &&
			!(mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
			Key_Event (K_MOUSE1, true);
		else if (!(mouse_buttonstate & MOUSE_LEFTBUTTON) &&
			(mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
			Key_Event (K_MOUSE1, false);

		if ((mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
			!(mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
			Key_Event (K_MOUSE2, true);
		else if (!(mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
			(mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
			Key_Event (K_MOUSE2, false);

		if ((mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
			!(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
			Key_Event (K_MOUSE3, true);
		else if (!(mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
			(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
			Key_Event (K_MOUSE3, false);

		mouse_oldbuttonstate = mouse_buttonstate;
	}
}
Exemplo n.º 15
0
int ImouseRead( int *xcurs, int *ycurs)
{
#ifdef GGI
 struct timeval tv={0,0};

 while (ggiEventPoll(ggiVis, emPointer, &tv) > 0)
 {
  ggi_event ev;
  int oldbutton=xg_mousebutton;

  ggiEventRead(ggiVis, &ev, emPointer);

  if (ev.any.type == evPtrButtonPress)
   xg_mousebutton = ev.pbutton.button;

  if (ev.any.type == evPtrButtonRelease)
   xg_mousebutton = 0;

  if (ev.any.type == evPtrRelative)
  {
   *xcurs += ev.pmove.x;
   *ycurs += ev.pmove.y;
  }

  if (ev.any.type == evPtrAbsolute)
  {
   *xcurs = ev.pmove.x;
   *ycurs = ev.pmove.y;
  }
  if(*xcurs<xg_mouserange_xmin)
   *xcurs=xg_mouserange_xmin;
  if(*xcurs>xg_mouserange_xmax)
   *xcurs=xg_mouserange_xmax;
  if(*ycurs<xg_mouserange_ymin)
   *ycurs=xg_mouserange_ymin;
  if(*ycurs>xg_mouserange_ymax)
   *ycurs=xg_mouserange_ymax;

  if(xg_mousebutton!=oldbutton) //otherwise we would catch mouse release event on slow PCs...
   return xg_mousebutton;
 }//loop
 return xg_mousebutton;

#else
 if(MouseWasUpdatedInThread || mouse_update())
 {
  MouseWasUpdatedInThread=0;
  xg_mousebutton=mouse_getbutton();
  *xcurs=mouse_getx();
  *ycurs=mouse_gety();
//  if(button!=0)
//   printf("[mouse=%d]",button);

  switch(xg_mousebutton) //?? SVGAlib mouse events ....
  {
   case 4:
   xg_mousebutton=1;
   break;
   case 1:
   xg_mousebutton=2;
   break;
   case 2:
   xg_mousebutton=4; //?
   break;
  }
 }
 return xg_mousebutton;
#endif
}
Exemplo n.º 16
0
/* The "guts" of main loop is here. */
int 
execute_timestep (void)
{
    static int next_time_step = 0;
    int engine_updated = 0;
    int real_quit_flag = 0;

    if (market_cb_flag == 0 && help_flag == 0 
	&& port_cb_flag == 0 && prefs_flag == 0)
    {

	if ((real_time < next_time_step || pause_flag || mt_flag)
	    && save_flag == 0 && load_flag == 0)
	{
	    if ((let_one_through == 0) || mt_flag)
	    {
		lc_usleep (1);
		return 0;
	    }
	    else
		let_one_through = 0;
	}

	if (slow_flag)
	    next_time_step = real_time + (SLOW_TIME_FOR_YEAR
					  * 1000 / NUMOF_DAYS_IN_YEAR);
	else if (fast_flag)
	    next_time_step = real_time + (FAST_TIME_FOR_YEAR
					  * 1000 / NUMOF_DAYS_IN_YEAR);
	else if (med_flag)
	    next_time_step = real_time + (MED_TIME_FOR_YEAR
					  * 1000 / NUMOF_DAYS_IN_YEAR);

	do_time_step ();

#ifdef CS_PROFILE
	if (--prof_countdown <= 0)
	    real_quit_flag = 1;
#endif

	update_main_screen (0);

	/* XXX: Shouldn't the rest be handled in update_main_screen()? */
	/* GCS: No, I don't think so.  These remaining items are 
		outside of the main screen */

	print_stats ();

	if (market_cb_flag)
	    draw_market_cb ();
	else if (port_cb_flag)	/* else- can't have both */
	    draw_port_cb ();
    }
    else /* if game is "stalled" */
    {
	if (market_cb_flag != 0 && market_cb_drawn_flag == 0)
	    draw_market_cb ();
	if (port_cb_flag != 0 && port_cb_drawn_flag == 0)
	    draw_port_cb ();
#if defined (SVGALIB)
	mouse_update ();
#endif
    }

#if defined (NETWORK_ENABLE)
    if (network_flag != 0) {
	do_network_screen ();
	network_flag = 0;
	let_one_through = 1;	/* if we are paused we need */
    }			        /* this to redraw the screen */
#endif

    if (prefs_flag != 0 && prefs_drawn_flag == 0) {
	do_prefs_screen ();
	let_one_through = 1;	/* if we are paused we need */
    }			        /* this to redraw the screen */

    if (load_flag != 0) {
#if defined (WIN32)
	DisableWindowsMenuItems ();
#endif
	if (help_flag == 0)	/* block loading when in help */
	    do_load_city ();
	load_flag = 0;
	let_one_through = 1;	/* if we are paused we need */
    }			        /* this to redraw the screen */

    else if (save_flag != 0) {
#if defined (WIN32)
	DisableWindowsMenuItems ();
#endif
	if (help_flag == 0)
	    do_save_city ();
	save_flag = 0;
	let_one_through = 1;
    }

    else if (quit_flag != 0) {
#if defined (WIN32)
	DisableWindowsMenuItems ();
#endif
	if (yn_dial_box (_("Quit The Game?")
			 ,_("Do you really want to quit?")
			 ,_("If you want to save the game select NO.")
			 ,""     /* GCS: This can't be translated!. */
			 ) != 0)
	    real_quit_flag = 1;
	else
	    quit_flag = 0;
    }

    if (help_flag != 0)
	lc_usleep (1);

    if (make_dir_ok_flag)
	make_savedir ();	/* sorry a bit crude :( */
    return real_quit_flag;
}
Exemplo n.º 17
0
Arquivo: event.c Projeto: rxi/lovedos
void event_pump(void) {
  keyboard_update();
  mouse_update();
}
Exemplo n.º 18
0
void IN_MouseMove (usercmd_t *cmd)
{
	static int old_mouse_x = 0, old_mouse_y = 0;

	if (!mouseinitialized)
		return;

#ifdef _Soft_SVGA
	// poll mouse values
	while (mouse_update())
		; // FIXME: is there was missed ; or it was ok ?
#endif

	//
	// Do not move the player if we're in HUD editor or menu mode.
	// And don't apply ingame sensitivity, since that will make movements jerky.
	//
	if(key_dest == key_hudeditor || key_dest == key_menu)
	{
		old_mouse_x = mouse_x = mx * cursor_sensitivity.value;
		old_mouse_y = mouse_y = my * cursor_sensitivity.value;
	}
	else
	{
		// Normal game mode.

		if (m_filter.value) {
			float filterfrac = bound (0.0f, m_filter.value, 1.0f) / 2.0f;
			mouse_x = (mx * (1.0f - filterfrac) + old_mouse_x * filterfrac);
			mouse_y = (my * (1.0f - filterfrac) + old_mouse_y * filterfrac);
		} else {
			mouse_x = mx;
			mouse_y = my;
		}

		old_mouse_x = mx;
		old_mouse_y = my;

		if (m_accel.value) {
			float mousespeed = (sqrt (mx * mx + my * my)) / (1000.0f * (float) cls.trueframetime);
			mouse_x *= (mousespeed * m_accel.value + sensitivity.value);
			mouse_y *= (mousespeed * m_accel.value + sensitivity.value);
		} else {
			mouse_x *= sensitivity.value;
			mouse_y *= sensitivity.value;
		}

		// add mouse X/Y movement to cmd
		if ((in_strafe.state & 1) || (lookstrafe.value && mlook_active))
			cmd->sidemove += m_side.value * mouse_x;
		else
			cl.viewangles[YAW] -= m_yaw.value * mouse_x;

		if (mlook_active)
			V_StopPitchDrift ();

		if (mlook_active && !(in_strafe.state & 1))
		{
			cl.viewangles[PITCH] += m_pitch.value * mouse_y;
			if (cl.viewangles[PITCH] > cl.maxpitch)
				cl.viewangles[PITCH] = cl.maxpitch;
			if (cl.viewangles[PITCH] < cl.minpitch)
				cl.viewangles[PITCH] = cl.minpitch;
		} else {
			cmd->forwardmove -= m_forward.value * mouse_y;
		}
	}

	mx = my = 0; // clear for next update
}
Exemplo n.º 19
0
void mouse_handler_base::mouse_press(const SDL_MouseButtonEvent& event, const bool browse)
{
	if(is_middle_click(event) && !preferences::middle_click_scrolls()) {
		simple_warp_ = true;
	}
	show_menu_ = false;
	map_location loc = gui().hex_clicked_on(event.x,event.y);
	mouse_update(browse, loc);
#if !SDL_VERSION_ATLEAST(2,0,0)
	int scrollx = 0;
	int scrolly = 0;
#endif

	if (is_left_click(event)) {
		if (event.state == SDL_PRESSED) {
			cancel_dragging();
			init_dragging(dragging_left_);
			left_click(event.x, event.y, browse);
		} else if (event.state == SDL_RELEASED) {
			minimap_scrolling_ = false;
			clear_dragging(event, browse);
			left_mouse_up(event.x, event.y, browse);
		}
	} else if (is_right_click(event)) {
		if (event.state == SDL_PRESSED) {
			cancel_dragging();
			init_dragging(dragging_right_);
			right_click(event.x, event.y, browse);
		} else if (event.state == SDL_RELEASED) {
			minimap_scrolling_ = false;
			clear_dragging(event, browse);
			right_mouse_up(event.x, event.y, browse);
		}
	} else if (is_middle_click(event)) {
		if (event.state == SDL_PRESSED) {
			set_scroll_start(event.x, event.y);
			scroll_started_ = true;

			map_location loc = gui().minimap_location_on(event.x,event.y);
			minimap_scrolling_ = false;
			if(loc.valid()) {
				simple_warp_ = false;
				minimap_scrolling_ = true;
				last_hex_ = loc;
				gui().scroll_to_tile(loc,display::WARP,false);
			} else if(simple_warp_) {
				// middle click not on minimap, check gamemap instead
				loc = gui().hex_clicked_on(event.x,event.y);
				if(loc.valid()) {
					last_hex_ = loc;
					gui().scroll_to_tile(loc,display::WARP,false);
				}
			}
		} else if (event.state == SDL_RELEASED) {
			minimap_scrolling_ = false;
			simple_warp_ = false;
			scroll_started_ = false;
		}
	}
#if !SDL_VERSION_ATLEAST(2,0,0)
	else if (allow_mouse_wheel_scroll(event.x, event.y)) {
		if (event.button == SDL_BUTTON_WHEELUP) {
			scrolly = - preferences::scroll_speed();
			mouse_wheel_up(event.x, event.y, browse);
		} else if (event.button == SDL_BUTTON_WHEELDOWN) {
			scrolly = preferences::scroll_speed();
			mouse_wheel_down(event.x, event.y, browse);
		} else if (event.button == SDL_BUTTON_WHEELLEFT) {
			scrollx = - preferences::scroll_speed();
			mouse_wheel_left(event.x, event.y, browse);
		} else if (event.button == SDL_BUTTON_WHEELRIGHT) {
			scrollx = preferences::scroll_speed();
			mouse_wheel_right(event.x, event.y, browse);
		}

		// Don't scroll map and map zoom slider at same time
		gui::slider* s = gui().find_slider("map-zoom-slider");
		if (s && sdl::point_in_rect(event.x, event.y, s->location())) {
			scrollx = 0; scrolly = 0;
		}
	}

	if (scrollx != 0 || scrolly != 0) {
		CKey pressed;
		// Alt + mousewheel do an 90° rotation on the scroll direction
		if (pressed[SDLK_LALT] || pressed[SDLK_RALT])
			gui().scroll(scrolly,scrollx);
		else
			gui().scroll(scrollx,scrolly);
	}
#endif
	if (!dragging_left_ && !dragging_right_ && dragging_started_) {
		dragging_started_ = false;
		cursor::set_dragging(false);
	}
	mouse_update(browse, loc);
}
void mouse_handler_base::mouse_press(const SDL_MouseButtonEvent& event, const bool browse)
{
	x_ = event.x;
	y_ = event.y;

	if(is_middle_click(event) && !preferences::middle_click_scrolls()) {
		simple_warp_ = true;
	}
	show_menu_ = false;
	mouse_update(browse);
	int scrollx = 0;
	int scrolly = 0;

	if (is_left_click(event)) {
		if (event.state == SDL_PRESSED) {
			cancel_dragging();
			init_dragging(dragging_left_);
			left_click(event.x, event.y, browse);
		} else if (event.state == SDL_RELEASED) {
			minimap_scrolling_ = false;
			clear_dragging(event, browse);
			left_mouse_up(event.x, event.y, browse);
		}
	} else if (is_right_click(event)) {
		if (event.state == SDL_PRESSED) {
			cancel_dragging();
			init_dragging(dragging_right_);
			right_click(event.x, event.y, browse);
		} else if (event.state == SDL_RELEASED) {
			minimap_scrolling_ = false;
			clear_dragging(event, browse);
			right_mouse_up(event.x, event.y, browse);
		}
	} else if (is_middle_click(event)) {
		if (event.state == SDL_PRESSED) {
			map_location loc = gui().minimap_location_on(event.x,event.y);
			minimap_scrolling_ = false;
			if(loc.valid()) {
				simple_warp_ = false;
				minimap_scrolling_ = true;
				last_hex_ = loc;
				gui().scroll_to_tile(loc,display::WARP,false);
			} else if(simple_warp_) {
				// middle click not on minimap, check gamemap instead
				loc = gui().hex_clicked_on(event.x,event.y);
				if(loc.valid()) {
					last_hex_ = loc;
					gui().scroll_to_tile(loc,display::WARP,false);
				}
			}
		} else if (event.state == SDL_RELEASED) {
			minimap_scrolling_ = false;
			simple_warp_ = false;
		}
	} else if (allow_mouse_wheel_scroll(event.x, event.y)) {
		if (event.button == SDL_BUTTON_WHEELUP) {
			scrolly = - preferences::scroll_speed();
		} else if (event.button == SDL_BUTTON_WHEELDOWN) {
			scrolly = preferences::scroll_speed();
		} else if (event.button == SDL_BUTTON_WHEELLEFT) {
			scrollx = - preferences::scroll_speed();
		} else if (event.button == SDL_BUTTON_WHEELRIGHT) {
			scrollx = preferences::scroll_speed();
		}
	}

	if (scrollx != 0 || scrolly != 0) {
		CKey pressed;
		// Alt + mousewheel do an 90° rotation on the scroll direction
		if (pressed[SDLK_LALT] || pressed[SDLK_RALT])
			gui().scroll(scrolly,scrollx);
		else
			gui().scroll(scrollx,scrolly);
	}
	if (!dragging_left_ && !dragging_right_ && dragging_started_) {
		dragging_started_ = false;
		cursor::set_dragging(false);
	}
	mouse_update(browse);
}
Exemplo n.º 21
0
void mouse_handler_base::mouse_press(const SDL_MouseButtonEvent& event, const bool browse)
{
	if(is_middle_click(event) && !preferences::middle_click_scrolls()) {
		simple_warp_ = true;
	}
	show_menu_ = false;
	map_location loc = gui().hex_clicked_on(event.x,event.y);
	mouse_update(browse, loc);

	if (is_left_click(event)) {
		if (event.state == SDL_PRESSED) {
			cancel_dragging();
			init_dragging(dragging_left_);
			left_click(event.x, event.y, browse);
		} else if (event.state == SDL_RELEASED) {
			minimap_scrolling_ = false;
			clear_dragging(event, browse);
			left_mouse_up(event.x, event.y, browse);
		}
	} else if (is_right_click(event)) {
		if (event.state == SDL_PRESSED) {
			cancel_dragging();
			init_dragging(dragging_right_);
			right_click(event.x, event.y, browse);
		} else if (event.state == SDL_RELEASED) {
			minimap_scrolling_ = false;
			clear_dragging(event, browse);
			right_mouse_up(event.x, event.y, browse);
		}
	} else if (is_middle_click(event)) {
		if (event.state == SDL_PRESSED) {
			set_scroll_start(event.x, event.y);
			scroll_started_ = true;

			map_location loc = gui().minimap_location_on(event.x,event.y);
			minimap_scrolling_ = false;
			if(loc.valid()) {
				simple_warp_ = false;
				minimap_scrolling_ = true;
				last_hex_ = loc;
				gui().scroll_to_tile(loc,display::WARP,false);
			} else if(simple_warp_) {
				// middle click not on minimap, check gamemap instead
				loc = gui().hex_clicked_on(event.x,event.y);
				if(loc.valid()) {
					last_hex_ = loc;
					gui().scroll_to_tile(loc,display::WARP,false);
				}
			}
		} else if (event.state == SDL_RELEASED) {
			minimap_scrolling_ = false;
			simple_warp_ = false;
			scroll_started_ = false;
		}
	}
	if (!dragging_left_ && !dragging_right_ && dragging_started_) {
		dragging_started_ = false;
		cursor::set_dragging(false);
	}
	mouse_update(browse, loc);
}