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

interface.cpp File Reference
#include "stratagus.h"
#include "interface.h"
#include "ai.h"
#include "commands.h"
#include "cursor.h"
#include "font.h"
#include "iolib.h"
#include "network.h"
#include "player.h"
#include "replay.h"
#include "sound.h"
#include "sound_server.h"
#include "translate.h"
#include "ui.h"
#include "unit.h"
#include "unit_find.h"
#include "unittype.h"
#include "video.h"
#include "widgets.h"

interface.cpp - The interface.

int ScrollMarginTop = 15
 
int ScrollMarginBottom = 16
 
int ScrollMarginLeft = 15
 
int ScrollMarginRight = 16
 
const char Cursor [] = "~!_"
 
static Vec2i SavedMapPosition [3]
 Input cursor. More...
 
static char Input [80]
 Saved map position. More...
 
static int InputIndex
 line input for messages/long commands More...
 
static char InputStatusLine [99]
 current index into input More...
 
constexpr int MaxInputHistorySize = 16
 Last input status line. More...
 
static char InputHistory [MaxInputHistorySize *sizeof(Input)] = { '\0' }
 Max history of inputs. More...
 
static int InputHistoryIdx = 0
 History of inputs. More...
 
static int InputHistoryPos = 0
 Next history idx. More...
 
static int InputHistorySize = 0
 Current position in history. More...
 
const char DefaultGroupKeys [] = "0123456789`"
 History fill size. More...
 
std::string UiGroupKeys = DefaultGroupKeys
 Default group keys. More...
 
bool GameRunning
 Up to 11 keys, last unselect. Default for qwerty. More...
 
bool GamePaused
 Current running state. More...
 
bool GameObserve
 Current pause state. More...
 
bool GameEstablishing
 Observe mode. More...
 
char SkipGameCycle
 Game establishing mode. More...
 
char BigMapMode
 Skip the next game cycle. More...
 
enum _iface_state_ InterfaceState
 Show only the map. More...
 
bool GodMode
 Current interface state. More...
 
enum _key_state_ KeyState
 Invincibility cheat. More...
 
CUnitLastIdleWorker
 current key state More...
 
int DoubleClickDelay = 300
 Time to detect double clicks. More...
 
int HoldClickDelay = 1000
 Time to detect double clicks. More...
 
static enum { ... }  MouseState
 Time to detect hold clicks. More...
 
static PixelPos LastMousePos
 Current state of mouse. More...
 
static unsigned LastMouseButton
 Last mouse position. More...
 
static unsigned StartMouseTicks
 last mouse button handled More...
 
static unsigned LastMouseTicks
 Ticks of first click. More...
 
static const int HoldKeyDelay = 250
 
static const int HoldKeyAdditionalDelay = 50
 Time to detect hold key. More...
 
static unsigned LastIKey
 Time to detect additional hold key. More...
 
static unsigned LastIKeyChar
 last key handled More...
 
static unsigned LastKeyTicks
 last keychar handled More...
 
static unsigned DoubleKey
 Ticks of last key. More...
 
static void moveInputContent (int targetPos, int srcPos)
 Last called idle worker. More...
 
static void removeCursorFromInput ()
 
static void addCursorToInput ()
 
static void ShowInput ()
 
static void UiBeginInput ()
 
static void UiUnselectAll ()
 
static void UiCenterOnGroup (unsigned group, GroupSelectionMode mode=SELECTABLE_BY_RECTANGLE_ONLY)
 
static void UiSelectGroup (unsigned group, GroupSelectionMode mode=SELECT_ALL)
 
static void UiAddGroupToSelection (unsigned group)
 
static void UiDefineGroup (unsigned group)
 
static void UiAddToGroup (unsigned group)
 
static void UiToggleSound ()
 
static void UiToggleMusic ()
 
void UiTogglePause ()
 Toggle pause mode. More...
 
void UiToggleBigMap ()
 Toggle big map. More...
 
static void UiIncreaseGameSpeed ()
 
static void UiDecreaseGameSpeed ()
 
static void UiSetDefaultGameSpeed ()
 
static void UiCenterOnSelected ()
 
static void UiSaveMapPosition (unsigned position)
 
static void UiRecallMapPosition (unsigned position)
 
void UiToggleTerrain ()
 Toggle terrain display on/off. More...
 
void UiFindIdleWorker ()
 Find the next idle worker. More...
 
static void UiToggleGrabMouse ()
 
void UiTrackUnit ()
 Track unit, the viewport follows the unit. More...
 
bool HandleCommandKey (int key)
 Call the lua function HandleCommandKey. More...
 
static void CommandKey_Group (int group)
 
static void CommandKey_MapPosition (int index)
 
static bool CommandKey (int key)
 
int HandleCheats (const std::string &input)
 Handle cheats. More...
 
static void Replace2TildeByTilde (char *s)
 
static void ReplaceTildeBy2Tilde (char *s)
 
static void InputKey (int key)
 
static void Screenshot ()
 
int HandleKeyModifiersDown (unsigned key, unsigned)
 Update KeyModifiers if a key is pressed. More...
 
int HandleKeyModifiersUp (unsigned key, unsigned)
 Update KeyModifiers if a key is released. More...
 
static bool IsKeyPad (unsigned key, unsigned *kp)
 
void HandleKeyDown (unsigned key, unsigned keychar)
 Called if a key is pressed. More...
 
void HandleKeyUp (unsigned key, unsigned keychar)
 Called when a key is released. More...
 
void HandleKeyRepeat (unsigned, unsigned keychar)
 Called when a key is repeated. More...
 
bool HandleMouseScrollArea (const PixelPos &mousePos)
 Handle the mouse in scroll area. More...
 
void HandleCursorMove (int *x, int *y)
 Keep coordinates in window and update cursor position. More...
 
void HandleMouseMove (const PixelPos &screenPos)
 Called if the mouse is moved. More...
 
void HandleButtonDown (unsigned button)
 Called if any mouse button is pressed down. More...
 
void HandleButtonUp (unsigned button)
 Called if any mouse button is released up. More...
 
void InputMouseButtonPress (const EventCallback &callbacks, unsigned ticks, unsigned button)
 Ticks of last mouse event. More...
 
void InputMouseButtonRelease (const EventCallback &callbacks, unsigned ticks, unsigned button)
 Called if any mouse button is released up. More...
 
void InputMouseMove (const EventCallback &callbacks, unsigned ticks, int x, int y)
 Called if the mouse is moved. More...
 
void InputMouseExit (const EventCallback &callbacks, unsigned)
 Called if the mouse exits the game window (when supported by videomode) More...
 
void InputMouseTimeout (const EventCallback &callbacks, unsigned ticks)
 Called to look for mouse timeouts. More...
 
void InputKeyButtonPress (const EventCallback &callbacks, unsigned ticks, unsigned ikey, unsigned ikeychar)
 last key pressed More...
 
void InputKeyButtonRelease (const EventCallback &callbacks, unsigned ticks, unsigned ikey, unsigned ikeychar)
 Called if any key button is released up. More...
 
void InputKeyTimeout (const EventCallback &callbacks, unsigned ticks)
 Called to look for key timeouts. More...
 
int GetDoubleClickDelay ()
 Get double click delay. More...
 
void SetDoubleClickDelay (int delay)
 Set double click delay. More...
 
int GetHoldClickDelay ()
 Get hold click delay. More...
 
void SetHoldClickDelay (int delay)
 Set hold click delay. More...
 
void SetScrollMargins (unsigned int top, unsigned int right, unsigned int bottom, unsigned int left)
 Scroll margins on screen. More...
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Time to detect hold clicks.

Enumerator
InitialMouseState 
ClickedMouseState 

start state

button is clicked

Function Documentation

◆ addCursorToInput()

static void addCursorToInput ( )
static

◆ CommandKey()

static bool CommandKey ( int  key)
static

Handle keys in command mode.

Parameters
keyKey scancode.
Returns
True, if key is handled; otherwise false.

◆ CommandKey_Group()

static void CommandKey_Group ( int  group)
static

◆ CommandKey_MapPosition()

static void CommandKey_MapPosition ( int  index)
static

◆ GetDoubleClickDelay()

int GetDoubleClickDelay ( )

Get double click delay.

Get double click delay

◆ GetHoldClickDelay()

int GetHoldClickDelay ( )

Get hold click delay.

Get hold click delay

◆ HandleButtonDown()

void HandleButtonDown ( unsigned  button)

Called if any mouse button is pressed down.

Called if mouse button pressed down.

Parameters
buttonMouse button number (0 left, 1 middle, 2 right)

◆ HandleButtonUp()

void HandleButtonUp ( unsigned  button)

Called if any mouse button is released up.

Called if mouse button released.

Todo:

FIXME: the mouse handling should be complete rewritten

FIXME: this is needed for double click, long click,...

Parameters
buttonMouse button number (0 left, 1 middle, 2 right)

◆ HandleCheats()

int HandleCheats ( const std::string &  input)

Handle cheats.

Handle cheats

Returns
1 if a cheat was handled, 0 otherwise

◆ HandleCommandKey()

bool HandleCommandKey ( int  key)

Call the lua function HandleCommandKey.

Call the lua function HandleCommandKey

◆ HandleCursorMove()

void HandleCursorMove ( int *  x,
int *  y 
)

Keep coordinates in window and update cursor position.

Keep coordinates in window and update cursor position

Parameters
xscreen pixel X position.
yscreen pixel Y position.

◆ HandleKeyDown()

void HandleKeyDown ( unsigned  key,
unsigned  keychar 
)

Called if a key is pressed.

Handle key down.

Parameters
keyKey scancode.
keycharCharacter code.

◆ HandleKeyModifiersDown()

int HandleKeyModifiersDown ( unsigned  key,
unsigned   
)

Update KeyModifiers if a key is pressed.

Update KeyModifiers if a key is pressed.

Parameters
keyKey scancode.
keycharCharacter code.
Returns
1 if modifier found, 0 otherwise

◆ HandleKeyModifiersUp()

int HandleKeyModifiersUp ( unsigned  key,
unsigned   
)

Update KeyModifiers if a key is released.

Update KeyModifiers if a key is released.

Parameters
keyKey scancode.
keycharCharacter code.
Returns
1 if modifier found, 0 otherwise

◆ HandleKeyRepeat()

void HandleKeyRepeat ( unsigned  ,
unsigned  keychar 
)

Called when a key is repeated.

Handle key up.

Parameters
keyKey scancode.
keycharCharacter code.

◆ HandleKeyUp()

void HandleKeyUp ( unsigned  key,
unsigned  keychar 
)

Called when a key is released.

Handle key up.

Parameters
keyKey scancode.
keycharCharacter code.

◆ HandleMouseMove()

void HandleMouseMove ( const PixelPos screenPos)

Called if the mouse is moved.

Handle movement of the cursor.

Parameters
screePosscreen pixel position.

◆ HandleMouseScrollArea()

bool HandleMouseScrollArea ( const PixelPos mousePos)

Handle the mouse in scroll area.

Handle the mouse in scroll area

Parameters
mousePosScreen position.
Returns
true if the mouse is in the scroll area, false otherwise

◆ InputKey()

static void InputKey ( int  key)
static

Handle keys in input mode.

Parameters
keyKey scancode.

◆ InputKeyButtonPress()

void InputKeyButtonPress ( const EventCallback callbacks,
unsigned  ticks,
unsigned  ikey,
unsigned  ikeychar 
)

last key pressed

Called if any key button is pressed down.

Handle keyboard key press.

Parameters
callbacksCallback structure for events.
ticksDenotes time-stamp of video-system
ikeyKey scancode.
ikeycharCharacter code.

◆ InputKeyButtonRelease()

void InputKeyButtonRelease ( const EventCallback callbacks,
unsigned  ticks,
unsigned  ikey,
unsigned  ikeychar 
)

Called if any key button is released up.

Handle keyboard key release.

Parameters
callbacksCallback structure for events.
ticksDenotes time-stamp of video-system
ikeyKey scancode.
ikeycharCharacter code.

◆ InputKeyTimeout()

void InputKeyTimeout ( const EventCallback callbacks,
unsigned  ticks 
)

Called to look for key timeouts.

Called each frame to handle keyboard timeouts.

Parameters
callbacksCallback structure for events.
ticksDenotes time-stamp of video-system

◆ InputMouseButtonPress()

void InputMouseButtonPress ( const EventCallback callbacks,
unsigned  ticks,
unsigned  button 
)

Ticks of last mouse event.

Called if any mouse button is pressed down.

Called if any mouse button is pressed down

Handles event conversion to double click, dragging, hold.

FIXME: dragging is not supported.

Parameters
callbacksCallback structure for events.
ticksDenotes time-stamp of video-system
buttonMouse button pressed.

◆ InputMouseButtonRelease()

void InputMouseButtonRelease ( const EventCallback callbacks,
unsigned  ticks,
unsigned  button 
)

Called if any mouse button is released up.

Called if any mouse button is released up

Parameters
callbacksCallback structure for events.
ticksDenotes time-stamp of video-system
buttonMouse button released.

◆ InputMouseExit()

void InputMouseExit ( const EventCallback callbacks,
unsigned   
)

Called if the mouse exits the game window (when supported by videomode)

Called if the mouse exits the game window (when supported by videomode)

Parameters
callbacksCallback structure for events.
ticksDenotes time-stamp of video-system

◆ InputMouseMove()

void InputMouseMove ( const EventCallback callbacks,
unsigned  ticks,
int  x,
int  y 
)

Called if the mouse is moved.

Called if the mouse is moved

Parameters
callbacksCallback structure for events.
ticksDenotes time-stamp of video-system
xX movement
yY movement

◆ InputMouseTimeout()

void InputMouseTimeout ( const EventCallback callbacks,
unsigned  ticks 
)

Called to look for mouse timeouts.

Called each frame to handle mouse timeouts.

Parameters
callbacksCallback structure for events.
ticksDenotes time-stamp of video-system

◆ IsKeyPad()

static bool IsKeyPad ( unsigned  key,
unsigned *  kp 
)
static

Check if a key is from the keypad and convert to ascii

◆ moveInputContent()

static void moveInputContent ( int  targetPos,
int  srcPos 
)
static

Last called idle worker.

◆ removeCursorFromInput()

static void removeCursorFromInput ( )
static

◆ Replace2TildeByTilde()

static void Replace2TildeByTilde ( char *  s)
static

◆ ReplaceTildeBy2Tilde()

static void ReplaceTildeBy2Tilde ( char *  s)
static

◆ Screenshot()

static void Screenshot ( )
static

Save a screenshot.

◆ SetDoubleClickDelay()

void SetDoubleClickDelay ( int  delay)

Set double click delay.

Set double click delay

Parameters
delayDouble click delay

◆ SetHoldClickDelay()

void SetHoldClickDelay ( int  delay)

Set hold click delay.

Set hold click delay

Parameters
delayHold click delay

◆ SetScrollMargins()

void SetScrollMargins ( unsigned int  top,
unsigned int  right,
unsigned int  bottom,
unsigned int  left 
)

Scroll margins on screen.

Configure margins (in pixels) on screen where map scrolling starts.

◆ ShowInput()

static void ShowInput ( )
static

Show input.

◆ UiAddGroupToSelection()

static void UiAddGroupToSelection ( unsigned  group)
static

Add group to current selection.

Parameters
groupGroup number to add.

◆ UiAddToGroup()

static void UiAddToGroup ( unsigned  group)
static

Add to group. The current selected units are added to the group.

Parameters
groupGroup number to be expanded.

◆ UiBeginInput()

static void UiBeginInput ( )
static

Begin input.

◆ UiCenterOnGroup()

static void UiCenterOnGroup ( unsigned  group,
GroupSelectionMode  mode = SELECTABLE_BY_RECTANGLE_ONLY 
)
static

Center on group.

Parameters
groupGroup number to center on.
Todo:
Improve this function, try to show all selected units or the most possible units.

◆ UiCenterOnSelected()

static void UiCenterOnSelected ( )
static

Center on the selected units.

Todo:
Improve this function, try to show all selected units or the most possible units.

◆ UiDecreaseGameSpeed()

static void UiDecreaseGameSpeed ( )
static

Decrease game speed.

◆ UiDefineGroup()

static void UiDefineGroup ( unsigned  group)
static

Define a group. The current selected units become a new group.

Parameters
groupGroup number to create.

◆ UiFindIdleWorker()

void UiFindIdleWorker ( )

Find the next idle worker.

Find the next idle worker, select it, and center on it

◆ UiIncreaseGameSpeed()

static void UiIncreaseGameSpeed ( )
static

Increase game speed.

◆ UiRecallMapPosition()

static void UiRecallMapPosition ( unsigned  position)
static

Recall map position.

Parameters
positionMap position slot.

◆ UiSaveMapPosition()

static void UiSaveMapPosition ( unsigned  position)
static

Save current map position.

Parameters
positionMap position slot.

◆ UiSelectGroup()

static void UiSelectGroup ( unsigned  group,
GroupSelectionMode  mode = SELECT_ALL 
)
static

Select group.

Parameters
groupGroup number to select.

◆ UiSetDefaultGameSpeed()

static void UiSetDefaultGameSpeed ( )
static

Set default game speed.

◆ UiToggleBigMap()

void UiToggleBigMap ( )

Toggle big map.

Toggle big map mode.

Todo:
FIXME: We should try to keep the same view, if possible

◆ UiToggleGrabMouse()

static void UiToggleGrabMouse ( )
static

Toggle grab mouse on/off.

◆ UiToggleMusic()

static void UiToggleMusic ( )
static

Toggle music on / off.

◆ UiTogglePause()

void UiTogglePause ( )

Toggle pause mode.

Toggle pause on / off.

◆ UiToggleSound()

static void UiToggleSound ( )
static

Toggle sound on / off.

◆ UiToggleTerrain()

void UiToggleTerrain ( )

Toggle terrain display on/off.

Toggle terrain display on/off.

◆ UiTrackUnit()

void UiTrackUnit ( )

Track unit, the viewport follows the unit.

Track unit, the viewport follows the unit.

◆ UiUnselectAll()

static void UiUnselectAll ( )
static

Unselect all currently selected units.

Variable Documentation

◆ BigMapMode

char BigMapMode

Skip the next game cycle.

Whether the map is the only thing displayed or not.

◆ Cursor

const char Cursor[] = "~!_"

◆ DefaultGroupKeys

const char DefaultGroupKeys[] = "0123456789`"

History fill size.

right button attacks

◆ DoubleClickDelay

int DoubleClickDelay = 300

Time to detect double clicks.

◆ DoubleKey

unsigned DoubleKey
static

Ticks of last key.

◆ GameEstablishing

bool GameEstablishing

Observe mode.

Flag telling if the game is in establishing mode.

◆ GameObserve

bool GameObserve

Current pause state.

Flag telling if the game is in observe mode.

◆ GamePaused

bool GamePaused

Current running state.

Flag telling if the game is paused.

◆ GameRunning

bool GameRunning

Up to 11 keys, last unselect. Default for qwerty.

Flag telling if the game is running.

◆ GodMode

bool GodMode

Current interface state.

Invincibility cheat.

◆ HoldClickDelay

int HoldClickDelay = 1000

Time to detect double clicks.

Time to detect hold clicks.

◆ HoldKeyAdditionalDelay

const int HoldKeyAdditionalDelay = 50
static

Time to detect hold key.

◆ HoldKeyDelay

const int HoldKeyDelay = 250
static

◆ Input

char Input[80]
static

Saved map position.

◆ InputHistory

char InputHistory[MaxInputHistorySize *sizeof(Input)] = { '\0' }
static

Max history of inputs.

◆ InputHistoryIdx

int InputHistoryIdx = 0
static

History of inputs.

◆ InputHistoryPos

int InputHistoryPos = 0
static

Next history idx.

◆ InputHistorySize

int InputHistorySize = 0
static

Current position in history.

◆ InputIndex

int InputIndex
static

line input for messages/long commands

◆ InputStatusLine

char InputStatusLine[99]
static

current index into input

◆ InterfaceState

enum _iface_state_ InterfaceState

Show only the map.

current interface state

◆ KeyState

enum _key_state_ KeyState

Invincibility cheat.

current key state

◆ LastIdleWorker

CUnit* LastIdleWorker

current key state

◆ LastIKey

unsigned LastIKey
static

Time to detect additional hold key.

◆ LastIKeyChar

unsigned LastIKeyChar
static

last key handled

◆ LastKeyTicks

unsigned LastKeyTicks
static

last keychar handled

◆ LastMouseButton

unsigned LastMouseButton
static

Last mouse position.

◆ LastMousePos

PixelPos LastMousePos
static

Current state of mouse.

◆ LastMouseTicks

unsigned LastMouseTicks
static

Ticks of first click.

◆ MaxInputHistorySize

constexpr int MaxInputHistorySize = 16
constexpr

Last input status line.

◆ MouseState

enum { ... } MouseState

Time to detect hold clicks.

◆ SavedMapPosition

Vec2i SavedMapPosition[3]
static

Input cursor.

◆ ScrollMarginBottom

int ScrollMarginBottom = 16

◆ ScrollMarginLeft

int ScrollMarginLeft = 15

◆ ScrollMarginRight

int ScrollMarginRight = 16

◆ ScrollMarginTop

int ScrollMarginTop = 15

◆ SkipGameCycle

char SkipGameCycle

Game establishing mode.

Flag telling not to advance to the next game cycle.

◆ StartMouseTicks

unsigned StartMouseTicks
static

last mouse button handled

◆ UiGroupKeys

std::string UiGroupKeys = DefaultGroupKeys

Default group keys.

(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.