____                _       __
    / __ )____  _____   | |     / /___ ___________
   / __  / __ \/ ___/   | | /| / / __ `/ ___/ ___/
  / /_/ / /_/ (__  )    | |/ |/ / /_/ / /  (__  )
 /_____/\____/____/     |__/|__/\__,_/_/  /____/

       A futuristic real-time strategy game.
          This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project. Distributed under the "GNU General Public License"

mouse.cpp File Reference

The mouse handling. More...

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "stratagus.h"
#include "video.h"
#include "map.h"
#include "sound.h"
#include "unitsound.h"
#include "unittype.h"
#include "player.h"
#include "unit.h"
#include "missile.h"
#include "commands.h"
#include "minimap.h"
#include "font.h"
#include "cursor.h"
#include "interface.h"
#include "menus.h"
#include "ui.h"
#include "network.h"
#include "spells.h"
#include "widgets.h"

Go to the source code of this file.

Defines

#define ICON_SIZE_X   (UI.ButtonPanel.Buttons[0].Style->Width)
#define ICON_SIZE_Y   (UI.ButtonPanel.Buttons[0].Style->Height)
#define LongSelected   (MouseButtons & ((LeftButton << MouseHoldShift)))

Functions

static void HandlePieMenuMouseSelection (void)
void CancelBuildingMode (void)
 Draw menu button area.
void DoRightButton (int sx, int sy)
 < Called if right mouse button is pressed
static bool OnButton (int x, int y, CUIButton *button)
static bool OnGraphic (int x, int y, CGraphic *g, int gx, int gy)
static void HandleMouseOn (int x, int y)
void HandleMouseExit (void)
 Update KeyModifiers if a key is pressed.
void RestrictCursorToViewport (void)
 Restrict mouse cursor to minimap.
void RestrictCursorToMinimap (void)
 Get viewport for screen pixel position.
void MouseScrollMap (int x, int y)
 Check if mouse scrolling is enabled.
void UIHandleMouseMove (int x, int y)
 Called if any mouse button is pressed down.
static int SendRepair (int sx, int sy)
static int SendMove (int sx, int sy)
static int SendAttack (int sx, int sy)
static int SendAttackGround (int sx, int sy)
static int SendPatrol (int sx, int sy)
static int SendResource (int sx, int sy)
static int SendUnload (int sx, int sy)
static int SendSpellCast (int sx, int sy)
static void SendCommand (int sx, int sy)
static void DoSelectionButtons (int num, unsigned button)
static void UISelectStateButtonDown (unsigned button)
void UIHandleButtonDown (unsigned button)
 Called if any mouse button is released up.
void UIHandleButtonUp (unsigned button)
 Restrict mouse cursor to viewport.
static int GetPieUnderCursor (void)
void DrawPieMenu (void)
 Handle the mouse in scroll area.

Variables

int MouseButtons
 Current pressed mouse buttons.
int KeyModifiers
 Current keyboard modifiers.
CUnitUnitUnderCursor
 Unit under cursor.
int ButtonAreaUnderCursor = -1
 Button area under cursor.
int ButtonUnderCursor = -1
 Button under cursor.
bool GameMenuButtonClicked
 Menu button was clicked.
bool GameDiplomacyButtonClicked
 Diplomacy button was clicked.
bool LeaveStops
 Mouse leaves windows stops scroll.
enum _cursor_on_ CursorOn = CursorOnUnknown
 Cursor on field.


Detailed Description

The mouse handling.

Definition in file mouse.cpp.


Define Documentation

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

Definition at line 31 of file mouse.cpp.

Referenced by DrawPieMenu(), and GetPieUnderCursor().

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

Definition at line 32 of file mouse.cpp.

Referenced by DrawPieMenu(), and GetPieUnderCursor().

#define LongSelected   (MouseButtons & ((LeftButton << MouseHoldShift)))

Referenced by UIHandleButtonDown().


Function Documentation

void CancelBuildingMode ( void   ) 

Draw menu button area.

Cancel building cursor mode.

Definition at line 88 of file mouse.cpp.

References CUserInterface::ButtonPanel, CStatusLine::Clear(), ClearCosts(), CurrentButtonLevel, CursorBuilding, CUserInterface::StatusLine, UI, and CButtonPanel::Update().

Referenced by DoActionMove(), CUnit::Remove(), and UIHandleButtonDown().

void DoRightButton ( int  sx,
int  sy 
)

static void DoSelectionButtons ( int  num,
unsigned  button 
) [static]

void DrawPieMenu ( void   ) 

static int GetPieUnderCursor ( void   )  [static]

Get pie menu under the cursor

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

Definition at line 1809 of file mouse.cpp.

References CursorStartX, CursorStartY, CursorX, CursorY, ICON_SIZE_X, ICON_SIZE_Y, CUserInterface::PieMenu, UI, CPieMenu::X, CPieMenu::Y, and y.

Referenced by DrawPieMenu(), and HandlePieMenuMouseSelection().

void HandleMouseExit ( void   ) 

Update KeyModifiers if a key is pressed.

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.

Definition at line 570 of file mouse.cpp.

References CursorConfig::Cursor, CursorOn, CursorOnUnknown, CursorX, CursorY, GameCursor, CVideo::Height, KeyScrollState, LeaveStops, MouseScrollState, CUserInterface::Point, ScrollNone, UI, Video, and CVideo::Width.

Referenced by InitGameCallbacks(), and initGuichan().

static void HandleMouseOn ( int  x,
int  y 
) [static]

static void HandlePieMenuMouseSelection ( void   )  [static]

void MouseScrollMap ( int  x,
int  y 
)

static bool OnButton ( int  x,
int  y,
CUIButton button 
) [inline, static]

Check if the mouse is on a button

Parameters:
x X coordinate.
y Y coordinate.
button Button to check.
Returns:
True if mouse is on the button, False otherwise.

Definition at line 368 of file mouse.cpp.

References ButtonStyle::Height, CUIButton::Style, ButtonStyle::Width, CUIButton::X, and CUIButton::Y.

Referenced by HandleMouseOn().

static bool OnGraphic ( int  x,
int  y,
CGraphic g,
int  gx,
int  gy 
) [inline, static]

Check if the mouse is on a graphic

Parameters:
x X coordinate.
y Y coordinate.
g Graphic.
gx Graphic X coordinate.
gy Graphic Y coordinate.
Returns:
True if mouse is on the graphic, False otherwise.

Definition at line 385 of file mouse.cpp.

References CGraphic::TransparentPixel().

Referenced by HandleMouseOn().

void RestrictCursorToMinimap ( void   ) 

Get viewport for screen pixel position.

Restrict mouse cursor to minimap

Definition at line 618 of file mouse.cpp.

References CursorOn, CursorOnMinimap, CursorStartX, CursorStartY, CursorX, CursorY, CMinimap::H, CUserInterface::Minimap, CUserInterface::MouseWarpX, CUserInterface::MouseWarpY, UI, CMinimap::W, CMinimap::X, and CMinimap::Y.

Referenced by EditorCallbackMouse(), and UIHandleMouseMove().

void RestrictCursorToViewport ( void   ) 

Restrict mouse cursor to minimap.

Restrict mouse cursor to viewport.

Definition at line 592 of file mouse.cpp.

References CursorOn, CursorOnMap, CursorStartX, CursorStartY, CursorX, CursorY, CViewport::EndX, CViewport::EndY, CUserInterface::MouseWarpX, CUserInterface::MouseWarpY, CUserInterface::SelectedViewport, UI, CViewport::X, and CViewport::Y.

Referenced by EditorCallbackMouse().

static int SendAttack ( int  sx,
int  sy 
) [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:
sx X screen map position.
sy Y screen map position.
Returns:
1 if any unit have a new order, 0 else.
See also:
Selected,

NumSelected

Definition at line 921 of file mouse.cpp.

References CUnit::Blink, CUnitType::CanAttack, CanMove(), CanTarget(), CUnitType::Decoration, KeyModifiers, ModifierShift, NumSelected, Selected, SendCommandAttack(), SendCommandMove(), TileSizeX, TileSizeY, and CUnit::Type.

Referenced by SendCommand().

static int SendAttackGround ( int  sx,
int  sy 
) [static]

Send the current selected group ground attacking.

Parameters:
sx X screen map position.
sy Y screen map position.

Definition at line 961 of file mouse.cpp.

References CUnitType::CanAttack, KeyModifiers, ModifierShift, NumSelected, Selected, SendCommandAttackGround(), SendCommandMove(), TileSizeX, TileSizeY, and CUnit::Type.

Referenced by SendCommand().

static void SendCommand ( int  sx,
int  sy 
) [static]

static int SendMove ( int  sx,
int  sy 
) [static]

Send selected units to point.

Parameters:
sx X screen tile position.
sy Y screen tile position.
Todo:
To reduce the CPU load for pathfinder, we should check if the destination is reachable and handle nice group movements.

Definition at line 863 of file mouse.cpp.

References CUnit::Blink, CanTransport(), CUnitType::CanTransport, KeyModifiers, ModifierShift, NumSelected, Selected, SendCommandBoard(), SendCommandFollow(), SendCommandMove(), SendCommandStopUnit(), TileSizeX, TileSizeY, and CUnit::Type.

Referenced by SendCommand().

static int SendPatrol ( int  sx,
int  sy 
) [static]

Let units patrol between current postion and the selected.

Parameters:
sx X screen map position.
sy Y screen map position.

Definition at line 986 of file mouse.cpp.

References KeyModifiers, ModifierShift, NumSelected, Selected, SendCommandPatrol(), TileSizeX, and TileSizeY.

Referenced by SendCommand().

static int SendRepair ( int  sx,
int  sy 
) [static]

Send selected units to repair

Parameters:
sx X screen map position.
sy Y screen map position.

Definition at line 831 of file mouse.cpp.

References DebugPrint, HP_INDEX, CPlayer::IsAllied(), KeyModifiers, CVariable::Max, ModifierShift, NumSelected, CUnit::Player, CUnitType::RepairHP, CUnitType::RepairRange, Selected, SendCommandRepair(), ThisPlayer, TileSizeX, TileSizeY, CUnit::Type, CVariable::Value, and CUnit::Variable.

Referenced by SendCommand().

static int SendResource ( int  sx,
int  sy 
) [static]

Let units harvest wood/mine gold/haul oil

Parameters:
sx X screen map position
sy Y screen map position
See also:
Selected

Definition at line 1007 of file mouse.cpp.

References CUnit::Blink, CUnitType::CanHarvestFrom, CanMove(), CUnitType::Harvester, KeyModifiers, ModifierShift, NumSelected, Selected, SendCommandMove(), SendCommandResource(), TileSizeX, TileSizeY, CUnit::Type, and y.

Referenced by SendCommand().

static int SendSpellCast ( int  sx,
int  sy 
) [static]

Send the current selected group for spell cast.

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

Parameters:
sx X screen map position.
sy Y screen map position.
See also:
Selected,

NumSelected

Definition at line 1077 of file mouse.cpp.

References _C_, CUnitType::CanCastSpell, CursorValue, DebugPrint, KeyModifiers, ModifierShift, CUnitType::Name, NumSelected, Selected, SendCommandSpellCast(), CUnit::Slot, TileSizeX, TileSizeY, and CUnit::Type.

Referenced by SendCommand().

static int SendUnload ( int  sx,
int  sy 
) [static]

Send selected units to unload passengers.

Parameters:
sx X screen map position.
sy Y screen map position.

Definition at line 1052 of file mouse.cpp.

References KeyModifiers, ModifierShift, NoUnitP, NumSelected, Selected, SendCommandUnload(), TileSizeX, and TileSizeY.

Referenced by SendCommand().

void UIHandleButtonDown ( unsigned  button  ) 

Called if any mouse button is released up.

Called if mouse button pressed down.

Parameters:
button Button pressed down.

Detect long selection click, FIXME: tempory hack to test the feature.

Definition at line 1300 of file mouse.cpp.

References _C_, Assert, CUnit::Blink, CUnit::Boarded, ButtonAreaButton, ButtonAreaMenu, ButtonAreaSelected, ButtonAreaTraining, ButtonAreaTransporting, ButtonAreaUnderCursor, CUserInterface::ButtonPanel, ButtonUnderCursor, ButtonUnderMenu, ButtonUnderNetworkDiplomacy, ButtonUnderNetworkMenu, CanBuildUnitType(), CancelBuildingMode(), CViewport::Center(), GameSound::Click, ClickMissile, CUserInterface::Cross, CursorConfig::Cursor, CursorBuilding, CursorOn, CursorOnButton, CursorOnMap, CursorOnMinimap, CursorStartScrMapX, CursorStartScrMapY, CursorStartX, CursorStartY, CursorState, CursorStatePieMenu, CursorStatePoint, CursorStateRectangle, CursorStateSelect, CursorX, CursorY, DebugPrint, CUnitType::Decoration, CButtonPanel::DoClicked(), DoRightButton(), DoSelectionButtons(), GameCursor, GameDiplomacyButtonClicked, GameMenuButtonClicked, GameObserve, GamePaused, GameSounds, HandleMouseOn(), HandlePieMenuMouseSelection(), CMap::IsFieldExplored(), CViewport::IsInsideMapArea(), CPlayer::IsTeamed(), KeyModifiers, LeftButton, LongSelected, MakeLocalMissile(), Map, CViewport::MapX, CViewport::MapY, MaxSampleVolume, MiddleButton, CUserInterface::Minimap, MissileTypeByIdent(), ModifierAlt, ModifierShift, CPieMenu::MouseButton, MouseButtons, CUserInterface::MouseViewport, CUnit::NextContained, NumSelected, CViewport::OffsetX, CViewport::OffsetY, CUserInterface::PieMenu, GameSound::PlacementError, GameSound::PlacementSuccess, PlayGameSound(), CUserInterface::Point, Preference, ReplayRevealMap, RightButton, CMinimap::Screen2MapX(), CMinimap::Screen2MapY(), CUserInterface::Scroll, Selected, CUserInterface::SelectedViewport, SendCommandBuildBuilding(), SendCommandCancelTraining(), SendCommandUnload(), CPreference::ShowAttackRange, CPreference::ShowReactionRange, CPreference::ShowSightRange, SoundConfig::Sound, ThisPlayer, CUnitType::TileHeight, TileSizeX, TileSizeY, CUnitType::TileWidth, CUnit::Type, UI, UISelectStateButtonDown(), CViewport::Unit, UnitActionTrain, CUnit::UnitInside, UnitOnMapTile(), CViewport::Viewport2MapX(), CViewport::Viewport2MapY(), CUserInterface::Viewports, CViewport::X, CViewport::Y, and y.

Referenced by HandleButtonDown().

void UIHandleButtonUp ( unsigned  button  ) 

Restrict mouse cursor to viewport.

Called if mouse button released.

Parameters:
button Button released.

Definition at line 1586 of file mouse.cpp.

References _, LuaActionListener::action(), AddGroupFromUnitToSelection(), AddSelectedAirUnitsInRectangle(), AddSelectedGroundUnitsInRectangle(), AddSelectedUnitsInRectangle(), CUnitType::Building, ButtonAreaMenu, ButtonAreaUnderCursor, ButtonUnderCursor, ButtonUnderMenu, ButtonUnderNetworkDiplomacy, ButtonUnderNetworkMenu, CUIButton::Callback, CStatusLine::Clear(), ClearCosts(), GameSound::Click, CurrentButtonLevel, CursorConfig::Cursor, CursorStartScrMapX, CursorStartScrMapY, CursorStartX, CursorStartY, CursorState, CursorStatePieMenu, CursorStatePoint, CursorStateRectangle, CursorX, CursorY, GameCursor, GameDiplomacyButtonClicked, GameMenuButtonClicked, GamePaused, GameSounds, HandlePieMenuMouseSelection(), CMap::IsFieldVisible(), IsNetworkGame, CPlayer::IsTeamed(), KeyModifiers, CUnit::LastGroup, LeftButton, Map, CViewport::MapX, CViewport::MapY, MaxSampleVolume, CUserInterface::MenuButton, ModifierAlt, ModifierControl, ModifierShift, MouseButtons, MouseDoubleShift, CUserInterface::MouseViewport, CUnitType::Name, CUserInterface::NetworkDiplomacyButton, CUserInterface::NetworkMenuButton, NumSelected, CViewport::OffsetX, CViewport::OffsetY, CUnit::Player, PlayerNeutral, PlayGameSound(), PlayUnitSound(), CUserInterface::Point, ReplayRevealMap, CUserInterface::Scroll, SelectAirUnitsInRectangle(), Selected, SelectGroundUnitsInRectangle(), SelectGroupFromUnit(), SelectionChanged(), SelectSingleUnit(), SelectUnitsByType(), SelectUnitsInRectangle(), CStatusLine::Set(), CUnitType::Slot, SoundConfig::Sound, SoundForName(), sprintf_s(), CUserInterface::StatusLine, ThisPlayer, TileSizeX, TileSizeY, ToggleSelectUnit(), ToggleUnitsByType(), CPlayer::Type, CUnit::Type, UI, UnitActionBuilt, UnitOnScreen(), CViewport::Viewport2MapX(), CViewport::Viewport2MapY(), VoiceBuilding, VoiceSelected, CViewport::X, and CViewport::Y.

Referenced by HandleButtonUp().

void UIHandleMouseMove ( int  x,
int  y 
)

Called if any mouse button is pressed down.

Handle movement of the cursor.

Parameters:
x Screen X position.
y Screen Y position.

Definition at line 670 of file mouse.cpp.

References CViewport::Center(), CursorConfig::Cursor, CursorOn, CursorOnMap, CursorOnMinimap, CursorStartX, CursorStartY, CursorState, CursorStatePieMenu, CursorStateRectangle, CursorStateSelect, CursorX, CursorY, CUnitType::Decoration, CViewport::EndX, CViewport::EndY, GameCursor, GameDiplomacyButtonClicked, GameMenuButtonClicked, CUserInterface::Glass, CUserInterface::GreenHair, HandleMouseOn(), CPlayer::Index, CPlayer::IsAllied(), CMap::IsFieldExplored(), CViewport::IsInsideMapArea(), CUnit::IsVisible(), CUnit::IsVisibleAsGoal(), LeftButton, Map, CViewport::MapX, CViewport::MapY, CUserInterface::Minimap, MouseButtons, MouseScrollMap(), CUserInterface::MouseViewport, CUserInterface::MouseWarpX, CUserInterface::MouseWarpY, CViewport::OffsetX, CViewport::OffsetY, CUserInterface::PieMenu, CUnit::Player, PlayerNumNeutral, CUserInterface::Point, CUserInterface::RedHair, ReplayRevealMap, RestrictCursorToMinimap(), RightButton, CMinimap::Screen2MapX(), CMinimap::Screen2MapY(), CUserInterface::Scroll, CUserInterface::SelectedViewport, ThisPlayer, TileSizeX, TileSizeY, CUnit::Type, UI, UnitOnMapTile(), UnitOnScreen(), CViewport::Viewport2MapX(), CViewport::Viewport2MapY(), CPieMenu::X, CViewport::X, CPieMenu::Y, CViewport::Y, and CUserInterface::YellowHair.

Referenced by HandleMouseMove(), HandlePieMenuMouseSelection(), and MenuScreen::stop().

static void UISelectStateButtonDown ( unsigned  button  )  [static]


Variable Documentation

enum _cursor_on_ CursorOn = CursorOnUnknown

Diplomacy button was clicked.

Mouse leaves windows stops scroll.

Definition at line 75 of file mouse.cpp.

Referenced by DrawMenuButtonArea(), UIHandleButtonDown(), UIHandleButtonUp(), and UIHandleMouseMove().

Menu button was clicked.

diplomacy button was clicked down

Definition at line 74 of file mouse.cpp.

Referenced by DrawMenuButtonArea(), EditorCallbackButtonDown(), EditorCallbackButtonUp(), EditorUpdateDisplay(), UIHandleButtonDown(), UIHandleButtonUp(), and UIHandleMouseMove().

bool LeaveStops

Mouse leaves windows stops scroll.

current CursorOn field

Definition at line 76 of file mouse.cpp.

Referenced by GetLeaveStops(), HandleMouseExit(), and SetLeaveStops().

Unit under cursor.

button area under the cursor

Definition at line 71 of file mouse.cpp.

Referenced by CleanCursors(), CleanGame(), CreateGame(), DrawInfoPanelNoneSelected(), DrawMapCursor(), DrawUnitSelection(), EditorCallbackKeyDown(), EditorCallbackMouse(), and CUnit::Remove().


Generated on Sat Feb 21 00:28:17 2009 for Bos Wars by  doxygen 1.5.6