_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

mouse.cpp File Reference
#include <ctype.h>
#include <stdexcept>
#include "stratagus.h"
#include "ui.h"
#include "action/action_build.h"
#include "action/action_train.h"
#include "actions.h"
#include "commands.h"
#include "cursor.h"
#include "font.h"
#include "interface.h"
#include "map.h"
#include "menus.h"
#include "minimap.h"
#include "missile.h"
#include "network.h"
#include "player.h"
#include "sound.h"
#include "spells.h"
#include "translate.h"
#include "unit.h"
#include "unit_find.h"
#include "unitsound.h"
#include "unittype.h"
#include "video.h"
#include "widgets.h"

mouse.cpp - The mouse handling.

#define ICON_SIZE_X   (UI.ButtonPanel.Buttons[0].Style->Width)
 
#define ICON_SIZE_Y   (UI.ButtonPanel.Buttons[0].Style->Height)
 
int MouseButtons
 pressed mouse buttons (normal,double,dragged,long) More...
 
int KeyModifiers
 Current pressed mouse buttons. More...
 
CUnitUnitUnderCursor
 Current keyboard modifiers. More...
 
int ButtonAreaUnderCursor = -1
 Unit under cursor. More...
 
int ButtonUnderCursor = -1
 Button area under cursor. More...
 
int OldButtonUnderCursor = -1
 Button under cursor. More...
 
bool GameMenuButtonClicked
 Button under cursor. More...
 
bool GameDiplomacyButtonClicked
 Menu button was clicked. More...
 
bool LeaveStops
 Diplomacy button was clicked. More...
 
enum _cursor_on_ CursorOn = CursorOnUnknown
 Mouse leaves windows stops scroll. More...
 
static void HandlePieMenuMouseSelection ()
 Cursor on field. More...
 
CUnitGetUnitUnderCursor ()
 
void CancelBuildingMode ()
 Cancel the building input mode. More...
 
static bool CanBuildOnArea (const CUnit &unit, const Vec2i &pos)
 
static void DoRightButton_ForForeignUnit (CUnit *dest)
 
static bool DoRightButton_Transporter (CUnit &unit, CUnit *dest, int flush, int &acknowledged)
 
static bool DoRightButton_Harvest_Unit (CUnit &unit, CUnit &dest, int flush, int &acknowledged)
 
static bool DoRightButton_Harvest_Pos (CUnit &unit, const Vec2i &pos, int flush, int &acknowledged)
 
static bool DoRightButton_Worker (CUnit &unit, CUnit *dest, const Vec2i &pos, int flush, int &acknowledged)
 
static bool DoRightButton_AttackUnit (CUnit &unit, CUnit &dest, const Vec2i &pos, int flush, int &acknowledged)
 
static void DoRightButton_Attack (CUnit &unit, CUnit *dest, const Vec2i &pos, int flush, int &acknowledged)
 
static bool DoRightButton_Follow (CUnit &unit, CUnit &dest, int flush, int &acknowledged)
 
static bool DoRightButton_Harvest_Reverse (CUnit &unit, CUnit &dest, int flush, int &acknowledged)
 
static bool DoRightButton_NewOrder (CUnit &unit, CUnit *dest, const Vec2i &pos, int flush, int &acknowledged)
 
static void DoRightButton_ForSelectedUnit (CUnit &unit, CUnit *dest, const Vec2i &pos, int &acknowledged)
 
void DoRightButton (const PixelPos &mapPixelPos)
 
static void HandleMouseOn (const PixelPos screenPos)
 
void HandleMouseExit ()
 Called if the mouse exits the game window (only for some videomodes) More...
 
void RestrictCursorToViewport ()
 Restrict mouse cursor to viewport. More...
 
void RestrictCursorToMinimap ()
 Restrict mouse cursor to minimap. More...
 
static void MouseScrollMap (const PixelPos &pos)
 
void UIHandleMouseMove (const PixelPos &cursorPos)
 Called if the mouse is moved in Normal interface state. More...
 
static int SendRepair (const Vec2i &tilePos)
 
static int SendMove (const Vec2i &tilePos)
 
static int SendAttack (const Vec2i &tilePos)
 
static int SendAttackGround (const Vec2i &tilePos)
 
static int SendPatrol (const Vec2i &tilePos)
 
static int SendResource (const Vec2i &pos)
 
static int SendUnload (const Vec2i &tilePos)
 
static int SendSpellCast (const Vec2i &tilePos)
 
static void SendCommand (const Vec2i &tilePos)
 
static void DoSelectionButtons (int num, unsigned)
 
static void UISelectStateButtonDown (unsigned)
 
static void UIHandleButtonDown_OnMap (unsigned button)
 
static void UIHandleButtonDown_OnMinimap (unsigned button)
 
static void UIHandleButtonDown_OnButton (unsigned button)
 
void UIHandleButtonDown (unsigned button)
 Called if any mouse button is pressed down. More...
 
void UIHandleButtonUp (unsigned button)
 Called if any mouse button is released up. More...
 
static int GetPieUnderCursor ()
 
void DrawPieMenu ()
 Draw the Pie Menu. More...
 

Macro Definition Documentation

◆ ICON_SIZE_X

#define ICON_SIZE_X   (UI.ButtonPanel.Buttons[0].Style->Width)

◆ ICON_SIZE_Y

#define ICON_SIZE_Y   (UI.ButtonPanel.Buttons[0].Style->Height)

Function Documentation

◆ CanBuildOnArea()

static bool CanBuildOnArea ( const CUnit unit,
const Vec2i pos 
)
static

◆ CancelBuildingMode()

void CancelBuildingMode ( )

Cancel the building input mode.

Cancel building cursor mode.

◆ DoRightButton()

void DoRightButton ( const PixelPos mapPixelPos)

Called when right button is pressed

Parameters
mapPixelPosmap position in pixels.

◆ DoRightButton_Attack()

static void DoRightButton_Attack ( CUnit unit,
CUnit dest,
const Vec2i pos,
int  flush,
int &  acknowledged 
)
static

◆ DoRightButton_AttackUnit()

static bool DoRightButton_AttackUnit ( CUnit unit,
CUnit dest,
const Vec2i pos,
int  flush,
int &  acknowledged 
)
static

◆ DoRightButton_Follow()

static bool DoRightButton_Follow ( CUnit unit,
CUnit dest,
int  flush,
int &  acknowledged 
)
static

◆ DoRightButton_ForForeignUnit()

static void DoRightButton_ForForeignUnit ( CUnit dest)
static

◆ DoRightButton_ForSelectedUnit()

static void DoRightButton_ForSelectedUnit ( CUnit unit,
CUnit dest,
const Vec2i pos,
int &  acknowledged 
)
static

◆ DoRightButton_Harvest_Pos()

static bool DoRightButton_Harvest_Pos ( CUnit unit,
const Vec2i pos,
int  flush,
int &  acknowledged 
)
static

◆ DoRightButton_Harvest_Reverse()

static bool DoRightButton_Harvest_Reverse ( CUnit unit,
CUnit dest,
int  flush,
int &  acknowledged 
)
static

◆ DoRightButton_Harvest_Unit()

static bool DoRightButton_Harvest_Unit ( CUnit unit,
CUnit dest,
int  flush,
int &  acknowledged 
)
static

◆ DoRightButton_NewOrder()

static bool DoRightButton_NewOrder ( CUnit unit,
CUnit dest,
const Vec2i pos,
int  flush,
int &  acknowledged 
)
static

◆ DoRightButton_Transporter()

static bool DoRightButton_Transporter ( CUnit unit,
CUnit dest,
int  flush,
int &  acknowledged 
)
static

◆ DoRightButton_Worker()

static bool DoRightButton_Worker ( CUnit unit,
CUnit dest,
const Vec2i pos,
int  flush,
int &  acknowledged 
)
static

◆ DoSelectionButtons()

static void DoSelectionButtons ( int  num,
unsigned   
)
static

Mouse button press on selection/group area.

Parameters
numButton number.
buttonMouse Button pressed.

◆ DrawPieMenu()

void DrawPieMenu ( )

Draw the Pie Menu.

Draw Pie Menu

◆ GetPieUnderCursor()

static int GetPieUnderCursor ( )
static

Get pie menu under the cursor

Returns
Index of the pie menu under the cursor or -1 for none

◆ GetUnitUnderCursor()

CUnit* GetUnitUnderCursor ( )

◆ HandleMouseExit()

void HandleMouseExit ( )

Called if the mouse exits the game window (only for some videomodes)

Handle cursor exits the game window (only for some videomodes)

Todo:
FIXME: make it so that the game is partially 'paused'. Game should run (for network play), but not react on or show interactive events.

◆ HandleMouseOn()

static void HandleMouseOn ( const PixelPos  screenPos)
static

Set flag on which area is the cursor.

Parameters
screenPosscreen position.

◆ HandlePieMenuMouseSelection()

static void HandlePieMenuMouseSelection ( )
static

Cursor on field.

Handle pie menu mouse selection

◆ MouseScrollMap()

static void MouseScrollMap ( const PixelPos pos)
static

Use the mouse to scroll the map

Parameters
posScreen position.

◆ RestrictCursorToMinimap()

void RestrictCursorToMinimap ( )

Restrict mouse cursor to minimap.

Restrict mouse cursor to minimap

◆ RestrictCursorToViewport()

void RestrictCursorToViewport ( )

Restrict mouse cursor to viewport.

Restrict mouse cursor to viewport.

◆ SendAttack()

static int SendAttack ( const Vec2i tilePos)
static

Send the current selected group attacking.

To empty field: Move to this field attacking all enemy units in reaction range.

To unit: Move to unit attacking and tracing the unit until dead.

Parameters
tilePostile map position.
Returns
1 if any unit have a new order, 0 else.
See also
Selected

◆ SendAttackGround()

static int SendAttackGround ( const Vec2i tilePos)
static

Send the current selected group ground attacking.

Parameters
tilePostile map position.

◆ SendCommand()

static void SendCommand ( const Vec2i tilePos)
static

Send a command to selected units.

Parameters
tilePostile map position.

◆ SendMove()

static int SendMove ( const Vec2i tilePos)
static

Send selected units to point.

Parameters
tilePostile map position.
Todo:
To reduce the CPU load for pathfinder, we should check if the destination is reachable and handle nice group movements.

◆ SendPatrol()

static int SendPatrol ( const Vec2i tilePos)
static

Let units patrol between current position and the selected.

Parameters
tilePostile map position.

◆ SendRepair()

static int SendRepair ( const Vec2i tilePos)
static

Send selected units to repair

Parameters
tilePostile map position.

◆ SendResource()

static int SendResource ( const Vec2i pos)
static

Let units harvest wood/mine gold/haul oil

Parameters
postile map position
See also
Selected

By disabling this, we allow the harvester to find the nearest tile with a resource by itself, in case mf is empty.

◆ SendSpellCast()

static int SendSpellCast ( const Vec2i tilePos)
static

Send the current selected group for spell cast.

To empty field: To unit: Spell cast on unit or on map spot.

Parameters
tilePostile map position.
See also
Selected

◆ SendUnload()

static int SendUnload ( const Vec2i tilePos)
static

Send selected units to unload passengers.

Parameters
tilePostile map position.

◆ UIHandleButtonDown()

void UIHandleButtonDown ( unsigned  button)

Called if any mouse button is pressed down.

Called if mouse button pressed down.

Parameters
buttonButton pressed down.

◆ UIHandleButtonDown_OnButton()

static void UIHandleButtonDown_OnButton ( unsigned  button)
static

◆ UIHandleButtonDown_OnMap()

static void UIHandleButtonDown_OnMap ( unsigned  button)
static

◆ UIHandleButtonDown_OnMinimap()

static void UIHandleButtonDown_OnMinimap ( unsigned  button)
static

◆ UIHandleButtonUp()

void UIHandleButtonUp ( unsigned  button)

Called if any mouse button is released up.

Called if mouse button released.

Parameters
buttonButton released.

◆ UIHandleMouseMove()

void UIHandleMouseMove ( const PixelPos cursorPos)

Called if the mouse is moved in Normal interface state.

Handle movement of the cursor.

Parameters
cursorPosScreen X position.

◆ UISelectStateButtonDown()

static void UISelectStateButtonDown ( unsigned  )
static

Handle mouse button pressed in select state.

Select state is used for target of patrol, attack, move, ....

Parameters
buttonButton pressed down.

Variable Documentation

◆ ButtonAreaUnderCursor

int ButtonAreaUnderCursor = -1

Unit under cursor.

button area under the cursor

◆ ButtonUnderCursor

int ButtonUnderCursor = -1

Button area under cursor.

button number under the cursor

◆ CursorOn

enum _cursor_on_ CursorOn = CursorOnUnknown

Mouse leaves windows stops scroll.

current CursorOn field

◆ GameDiplomacyButtonClicked

bool GameDiplomacyButtonClicked

Menu button was clicked.

diplomacy button was clicked down

◆ GameMenuButtonClicked

bool GameMenuButtonClicked

Button under cursor.

menu button was clicked down

◆ KeyModifiers

int KeyModifiers

Current pressed mouse buttons.

current active modifiers

◆ LeaveStops

bool LeaveStops

Diplomacy button was clicked.

Mouse leaves windows stops scroll.

◆ MouseButtons

int MouseButtons

pressed mouse buttons (normal,double,dragged,long)

◆ OldButtonUnderCursor

int OldButtonUnderCursor = -1

Button under cursor.

oldbutton number under the cursor

◆ UnitUnderCursor

CUnit* UnitUnderCursor

Current keyboard modifiers.

shared pointer to unit under the cursor

(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.