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

src/ui/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 "tileset.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.

#define SCROLL_UP   15
 Scrolling area (<= 15 y).
#define SCROLL_DOWN   (Video.Height - 16)
 Scrolling area (>= VideoHeight - 16 y).
#define SCROLL_LEFT   15
 Scrolling area (<= 15 y).
#define SCROLL_RIGHT   (Video.Width - 16)
 Scrolling area (>= VideoWidth - 16 x).
static Vec2i SavedMapPosition [3]
static char Input [80]
 Saved map position.
static int InputIndex
 line input for messages/long commands
static char InputStatusLine [99]
 current index into input
const char DefaultGroupKeys [] = "0123456789`"
 Last input status line.
std::string UiGroupKeys = DefaultGroupKeys
 Default group keys.
bool GameRunning
 Up to 11 keys, last unselect. Default for qwerty.
bool GamePaused
 Current running state.
bool GameObserve
 Current pause state.
char SkipGameCycle
 Observe mode.
char BigMapMode
 Skip the next game cycle.
enum _iface_state_ InterfaceState
 Show only the map.
bool GodMode
 Current interface state.
enum _key_state_ KeyState
 Invincibility cheat.
int DoubleClickDelay = 300
 Time to detect double clicks.
int HoldClickDelay = 1000
 Time to detect double clicks.
static enum { InitialMouseState, ClickedMouseStateMouseState
 Time to detect hold clicks.
static int MouseX
 Current state of mouse.
static int MouseY
 Last mouse X position.
static unsigned LastMouseButton
 Last mouse Y position.
static unsigned StartMouseTicks
 last mouse button handled
static unsigned LastMouseTicks
 Ticks of first click.
static const int HoldKeyDelay = 250
static const int HoldKeyAdditionalDelay = 50
 Time to detect hold key.
static unsigned LastIKey
 Time to detect additional hold key.
static unsigned LastIKeyChar
 last key handled
static unsigned LastKeyTicks
 last keychar handled
static unsigned DoubleKey
 Ticks of last key.
static void ShowInput ()
 current key state
static void UiBeginInput ()
static void UiUnselectAll ()
static void UiCenterOnGroup (unsigned group, GroupSelectionMode mode=SELECTABLE_BY_RECTANGLE_ONLY)
static void UiSelectGroup (unsigned group, GroupSelectionMode mode=SELECTABLE_BY_RECTANGLE_ONLY)
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.
void UiToggleBigMap ()
 Toggle big map.
static void UiIncreaseGameSpeed ()
static void UiDecreaseGameSpeed ()
static void UiSetDefaultGameSpeed ()
static void UiCenterOnSelected ()
static void UiSaveMapPosition (unsigned position)
static void UiRecallMapPosition (unsigned position)
static void UiToggleTerrain ()
static void UiFindIdleWorker ()
static void UiToggleGrabMouse ()
static void UiTrackUnit ()
bool HandleCommandKey (int key)
 Call the lua function HandleCommandKey.
static bool CommandKey (int key)
int HandleCheats (const std::string &input)
 Handle cheats.
static int InputKey (int key)
static void Screenshot ()
int HandleKeyModifiersDown (unsigned key, unsigned)
 Update KeyModifiers if a key is pressed.
int HandleKeyModifiersUp (unsigned key, unsigned)
 Update KeyModifiers if a key is released.
static bool IsKeyPad (unsigned key, unsigned *kp)
void HandleKeyDown (unsigned key, unsigned keychar)
 Called if a key is pressed.
void HandleKeyUp (unsigned key, unsigned keychar)
 Called when a key is released.
void HandleKeyRepeat (unsigned, unsigned keychar)
 Called when a key is repeated.
bool HandleMouseScrollArea (const PixelPos &mousePos)
 Handle the mouse in scroll area.
void HandleCursorMove (int *x, int *y)
 Keep coordinates in window and update cursor position.
void HandleMouseMove (const PixelPos &screenPos)
 Called if the mouse is moved.
void HandleButtonDown (unsigned button)
 Called if any mouse button is pressed down.
void HandleButtonUp (unsigned button)
 Called if any mouse button is released up.
void InputMouseButtonPress (const EventCallback &callbacks, unsigned ticks, unsigned button)
 Ticks of last mouse event.
void InputMouseButtonRelease (const EventCallback &callbacks, unsigned ticks, unsigned button)
 Called if any mouse button is released up.
void InputMouseMove (const EventCallback &callbacks, unsigned ticks, int x, int y)
 Called if the mouse is moved.
void InputMouseExit (const EventCallback &callbacks, unsigned)
 Called if the mouse exits the game window (when supported by videomode).
void InputMouseTimeout (const EventCallback &callbacks, unsigned ticks)
 Called to look for mouse timeouts.
void InputKeyButtonPress (const EventCallback &callbacks, unsigned ticks, unsigned ikey, unsigned ikeychar)
 last key pressed
void InputKeyButtonRelease (const EventCallback &callbacks, unsigned ticks, unsigned ikey, unsigned ikeychar)
 Called if any key button is released up.
void InputKeyTimeout (const EventCallback &callbacks, unsigned ticks)
 Called to look for key timeouts.
int GetDoubleClickDelay ()
 Get double click delay.
void SetDoubleClickDelay (int delay)
 Set double click delay.
int GetHoldClickDelay ()
 Get hold click delay.
void SetHoldClickDelay (int delay)
 Set hold click delay.

Define Documentation

#define SCROLL_DOWN   (Video.Height - 16)

Scrolling area (>= VideoHeight - 16 y).

#define SCROLL_LEFT   15

Scrolling area (<= 15 y).

#define SCROLL_RIGHT   (Video.Width - 16)

Scrolling area (>= VideoWidth - 16 x).

#define SCROLL_UP   15

Scrolling area (<= 15 y).


Enumeration Type Documentation

anonymous enum

Time to detect hold clicks.

Enumerator:
InitialMouseState 
ClickedMouseState  start state

button is clicked


Function Documentation

static bool CommandKey ( int  key  )  [static]

Handle keys in command mode.

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

int GetDoubleClickDelay (  ) 

Get double click delay.

Get double click delay

int GetHoldClickDelay (  ) 

Get hold click delay.

Get hold click delay

void HandleButtonDown ( unsigned  button  ) 

Called if any mouse button is pressed down.

Called if mouse button pressed down.

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

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
Todo:
FIXME: this is needed for double click, long click,...
Parameters:
button Mouse button number (0 left, 1 middle, 2 right)

int HandleCheats ( const std::string &  input  ) 

Handle cheats.

Handle cheats

Returns:
1 if a cheat was handled, 0 otherwise

bool HandleCommandKey ( int  key  ) 

Call the lua function HandleCommandKey.

Call the lua function HandleCommandKey

void HandleCursorMove ( int *  x,
int *  y 
)

Keep coordinates in window and update cursor position.

Keep coordinates in window and update cursor position

Parameters:
x screen pixel X position.
y screen pixel Y position.

void HandleKeyDown ( unsigned  key,
unsigned  keychar 
)

Called if a key is pressed.

Handle key down.

Parameters:
key Key scancode.
keychar Character code.

int HandleKeyModifiersDown ( unsigned  key,
unsigned   
)

Update KeyModifiers if a key is pressed.

Update KeyModifiers if a key is pressed.

Parameters:
key Key scancode.
keychar Character code.
Returns:
1 if modifier found, 0 otherwise

int HandleKeyModifiersUp ( unsigned  key,
unsigned   
)

Update KeyModifiers if a key is released.

Update KeyModifiers if a key is released.

Parameters:
key Key scancode.
keychar Character code.
Returns:
1 if modifier found, 0 otherwise

void HandleKeyRepeat ( unsigned  ,
unsigned  keychar 
)

Called when a key is repeated.

Handle key up.

Parameters:
key Key scancode.
keychar Character code.

void HandleKeyUp ( unsigned  key,
unsigned  keychar 
)

Called when a key is released.

Handle key up.

Parameters:
key Key scancode.
keychar Character code.

void HandleMouseMove ( const PixelPos screenPos  ) 

Called if the mouse is moved.

Handle movement of the cursor.

Parameters:
x screen pixel X position.
y screen pixel Y position.

bool HandleMouseScrollArea ( const PixelPos mousePos  ) 

Handle the mouse in scroll area.

Handle the mouse in scroll area

Parameters:
x Screen X position.
y Screen Y position.
Returns:
true if the mouse is in the scroll area, false otherwise

static int InputKey ( int  key  )  [static]

Handle keys in input mode.

Parameters:
key Key scancode.
Returns:
True input finished.

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:
callbacks Callback structure for events.
ticks Denotes time-stamp of video-system
ikey Key scancode.
ikeychar Character code.

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

Called if any key button is released up.

Handle keyboard key release.

Parameters:
callbacks Callback structure for events.
ticks Denotes time-stamp of video-system
ikey Key scancode.
ikeychar Character code.

void InputKeyTimeout ( const EventCallback callbacks,
unsigned  ticks 
)

Called to look for key timeouts.

Called each frame to handle keyboard timeouts.

Parameters:
callbacks Callback structure for events.
ticks Denotes time-stamp of video-system

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:
callbacks Callback structure for events.
ticks Denotes time-stamp of video-system
button Mouse button pressed.

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:
callbacks Callback structure for events.
ticks Denotes time-stamp of video-system
button Mouse button released.

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:
callbacks Callback structure for events.
ticks Denotes time-stamp of video-system

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

Called if the mouse is moved.

Called if the mouse is moved

Parameters:
callbacks Callback structure for events.
ticks Denotes time-stamp of video-system
x X movement
y Y movement

void InputMouseTimeout ( const EventCallback callbacks,
unsigned  ticks 
)

Called to look for mouse timeouts.

Called each frame to handle mouse timeouts.

Parameters:
callbacks Callback structure for events.
ticks Denotes time-stamp of video-system

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

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

static void Screenshot (  )  [static]

Save a screenshot.

void SetDoubleClickDelay ( int  delay  ) 

Set double click delay.

Set double click delay

Parameters:
delay Double click delay

void SetHoldClickDelay ( int  delay  ) 

Set hold click delay.

Set hold click delay

Parameters:
delay Hold click delay

static void ShowInput (  )  [static]

current key state

Show input.

static void UiAddGroupToSelection ( unsigned  group  )  [static]

Add group to current selection.

Parameters:
group Group number to add.

static void UiAddToGroup ( unsigned  group  )  [static]

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

Parameters:
group Group number to be expanded.

static void UiBeginInput (  )  [static]

Begin input.

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

Center on group.

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

static void UiCenterOnSelected (  )  [static]

Center on the selected units.

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

static void UiDecreaseGameSpeed (  )  [static]

Decrease game speed.

static void UiDefineGroup ( unsigned  group  )  [static]

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

Parameters:
group Group number to create.

static void UiFindIdleWorker (  )  [static]

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

static void UiIncreaseGameSpeed (  )  [static]

Increase game speed.

static void UiRecallMapPosition ( unsigned  position  )  [static]

Recall map position.

Parameters:
position Map position slot.

static void UiSaveMapPosition ( unsigned  position  )  [static]

Save current map position.

Parameters:
position Map position slot.

static void UiSelectGroup ( unsigned  group,
GroupSelectionMode  mode = SELECTABLE_BY_RECTANGLE_ONLY 
) [static]

Select group.

Parameters:
group Group number to select.

static void UiSetDefaultGameSpeed (  )  [static]

Set default game speed.

void UiToggleBigMap (  ) 

Toggle big map.

Toggle big map mode.

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

static void UiToggleGrabMouse (  )  [static]

Toggle grab mouse on/off.

static void UiToggleMusic (  )  [static]

Toggle music on / off.

void UiTogglePause (  ) 

Toggle pause mode.

Toggle pause on / off.

static void UiToggleSound (  )  [static]

Toggle sound on / off.

static void UiToggleTerrain (  )  [static]

Toggle terrain display on/off.

static void UiTrackUnit (  )  [static]

Track unit, the viewport follows the unit.

static void UiUnselectAll (  )  [static]

Unselect all currently selected units.


Variable Documentation

char BigMapMode

Skip the next game cycle.

Whether the map is the only thing displayed or not.

const char DefaultGroupKeys[] = "0123456789`"

Last input status line.

right button attacks

int DoubleClickDelay = 300

Time to detect double clicks.

unsigned DoubleKey [static]

Ticks of last key.

Current pause state.

Flag telling if the game is in observe mode.

bool GamePaused

Current running state.

Flag telling if the game is paused.

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

Flag telling if the game is running.

bool GodMode

Current interface state.

Invincibility cheat.

int HoldClickDelay = 1000

Time to detect double clicks.

Time to detect hold clicks.

const int HoldKeyAdditionalDelay = 50 [static]

Time to detect hold key.

const int HoldKeyDelay = 250 [static]

char Input[80] [static]

Saved map position.

int InputIndex [static]

line input for messages/long commands

char InputStatusLine[99] [static]

current index into input

Show only the map.

current interface state

Invincibility cheat.

current key state

unsigned LastIKey [static]

Time to detect additional hold key.

unsigned LastIKeyChar [static]

last key handled

unsigned LastKeyTicks [static]

last keychar handled

unsigned LastMouseButton [static]

Last mouse Y position.

unsigned LastMouseTicks [static]

Ticks of first click.

enum { ... } MouseState [static]

Time to detect hold clicks.

int MouseX [static]

Current state of mouse.

int MouseY [static]

Last mouse X position.

Vec2i SavedMapPosition[3] [static]

Observe mode.

Flag telling not to advance to the next game cycle.

unsigned StartMouseTicks [static]

last mouse button handled

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.