Redesigned keyboard handling, supporting groups.

This commit is contained in:
johns 2001-04-21 23:21:20 +00:00
parent 21e3bd06aa
commit 0b7d5a3dd1
13 changed files with 609 additions and 386 deletions

View file

@ -217,7 +217,7 @@ freecraft [OPTIONS] [map.pud|map.pud.gz]
<LI><KBD>-</KBD><BR>
Decrease game speed.
<LI><KBD>ALT+C, CTRL+C, c (if unused)</KBD><BR>
Center on selected unit.
Center on selected units.
<LI><KBD>ALT+X, CTRL+X</KBD><BR>
Exit program.
<LI><KBD>ALT+Q, CTRL+Q</KBD><BR>
@ -239,18 +239,26 @@ freecraft [OPTIONS] [map.pud|map.pud.gz]
<LI><KBD>SHIFT+ALT + # (1-9,0)</KBD><BR>
Add to alternate unit group. All currently selected units are also added to
the group.
<LI><KBD>F1,F2,F3,F4</KBD><BR>
Recall saved map position.
<LI><KBD>SHIFT+F1,SHIFT+F2,SHIFT+F3,SHIFT+F4</KBD><BR>
Save current map position for later recall.
<LI><KBD>ALT+G, CTRL+G</KBD><BR>
Toggle mouse grab mode.
<LI><KBD>ALT+F, CTRL+F</KBD><BR>
Toggle fullscreen mode. (only with SDL supported)
<LI><KBD>ALT+P, CTRL+P</KBD> or <KBD>pause</KBD><BR>
Toggle pause mode.
<LI><KBD>CTRL+S</KBD><BR>
Toggle sound on/off.
<LI><KBD>ALT+S, F11</KBD><BR>
Save complete state.
<LI><KBD>ALT+L, F12</KBD><BR>
Load complete state.
<LI><KBD>ALT+M, F10</KBD><BR>
Enter game menu.
<LI><KBD>space</KBD><BR>
Center on last message.
</UL>
<H2><A NAME="ccl">CCL: FreeCraft Configuration Language</A></H2>

View file

@ -264,9 +264,9 @@ extern void HandleButtonUp(unsigned button);
/// Called if the mouse is moved
extern void HandleMouseMove(int x,int y);
/// Called if a key is pressed
extern void HandleKeyDown(unsigned key);
extern void HandleKeyDown(unsigned keycode,unsigned keychar);
/// Called when a key is released
extern void HandleKeyUp(unsigned key);
extern void HandleKeyUp(unsigned keycode,unsigned keychar);
/// Called if any mouse button is pressed down
extern void InputMouseButtonPress(const EventCallback*,unsigned,unsigned);

View file

@ -379,12 +379,12 @@ extern void FreeMapInfo(MapInfo* info);
/// Mark a tile as seen by the player
extern void MapMarkSeenTile(int x,int y);
/// FIXME: docu
/// Reveal the complete map, make everything known
extern void RevealMap(void);
/// FIXME: docu
/// Center map on point
extern void MapCenter(int x,int y);
/// FIXME: docu
/// Set the current map view to x,y (upper,left corner)
extern void MapSetViewpoint(int x,int y);
/// FIXME: docu

View file

@ -400,7 +400,7 @@ enum _directions_ {
** Everything belonging to an unit. FIXME: rearrange for less memory.
*/
struct _unit_ {
// int is faster than shorts.
// int is faster than shorts
unsigned Refs; /// Reference counter
unsigned Slot; /// Assignd slot number
Unit** UnitSlot; /// slot pointer of Units
@ -471,7 +471,7 @@ struct _unit_ {
char OrderFlush; /// cancel current order, take next
Order Orders[MAX_ORDERS]; /// orders to process
Order SavedOrder; /// order to continue after current
Order NewOrder; /// order for new trained units.
Order NewOrder; /// order for new trained units
union _order_data_ {
struct _order_move_ {
@ -481,7 +481,7 @@ struct _unit_ {
char Path[MAX_PATH_LENGTH]; /// directions of stored path
} Move; /// ActionMove,...
struct _order_builded_ {
Unit* Worker; /// Worker building this unit.
Unit* Worker; /// Worker building this unit
int Sum; /// HP for building
int Add;
int Val; /// Counter
@ -491,11 +491,6 @@ struct _unit_ {
struct _order_resource_ {
int Active; /// how much units are in the resource
} Resource; /// Resource still
/* FIXME: move and harvest.
struct _order_harvest_ {
unsigned WoodToHarvest; /// Ticks for harvest
} Harvest; /// Harvest action
*/
struct _order_research_ {
unsigned Ticks; /// Ticks for research
Upgrade* Upgrade; /// Upgrade researched
@ -528,7 +523,7 @@ struct _unit_ {
// FIXME: will be removed, we will get player limits
#define MAX_UNITS UnitMax /// maximal number of units supported
#define MAX_UNIT_SLOTS 65535 /// Maximal number of used slots.
#define MAX_UNIT_SLOTS 65535 /// Maximal number of used slots
/**
** Returns true, if unit is unusable. (for attacking,...)
@ -597,7 +592,7 @@ extern Unit* Selected[MaxSelectable]; /// currently selected units
extern void InitUnitsMemory(void);
/// Free memory used by unit
extern void FreeUnitMemory(Unit* unit);
/// Release an unit.
/// Release an unit
extern void ReleaseUnit(Unit* unit);
/// Create a new unit
extern Unit* MakeUnit(UnitType* type,Player* player);
@ -610,11 +605,11 @@ extern void UnitLost(const Unit* unit);
extern void UpdateForNewUnit(const Unit* unit,int upgrade);
/// FIXME: more docu
extern void NearestOfUnit(const Unit* unit,int tx,int ty,int *dx,int *dy);
/// Returns true, if unit is visible on the map.
/// Returns true, if unit is visible on the map
extern int UnitVisibleOnMap(const Unit* unit);
/// Returns true, if unit is known on the map.
/// Returns true, if unit is known on the map
extern int UnitKnownOnMap(const Unit* unit);
/// Returns true, if unit is visible on current map view.
/// Returns true, if unit is visible on current map view
extern int UnitVisibleOnScreen(const Unit* unit);
/// FIXME: more docu
extern int CheckUnitToBeDrawn(const Unit* unit);
@ -623,13 +618,13 @@ extern void GetUnitMapArea( const Unit* unit,
int *sx, int *sy, int *ex, int *ey );
/// FIXME: more docu
extern void RemoveUnit(Unit* unit);
/// Increment mana of all magic units each second.
/// Increment mana of all magic units each second
extern void UnitIncrementMana(void);
/// Increment health of all regenerating units each second.
/// Increment health of all regenerating units each second
extern void UnitIncrementHealth(void);
/// Check for rescue each second.
/// Check for rescue each second
extern void RescueUnits(void);
/// Change owner of unit.
/// Change owner of unit
extern void ChangeUnitOwner(Unit* unit,Player* old,Player* new);
/// Convert direction (dx,dy) to heading (0-255)
@ -643,7 +638,7 @@ extern void UnitHeadingFromDeltaXY(Unit* unit,int x,int y);
extern void DropOutOnSide(Unit* unit,int heading,int addx,int addy);
/// FIXME: more docu
extern void DropOutNearest(Unit* unit,int x,int y,int addx,int addy);
/// Drop out all units in the unit.
/// Drop out all units in the unit
extern void DropOutAll(const Unit* unit);
/// FIXME: more docu
@ -677,13 +672,13 @@ extern void DestroyAllInside(Unit* source);
/// FIXME: more docu
extern void HitUnit(Unit* unit,int damage);
/// Returns the map distance between two points.
/// Returns the map distance between two points
extern int MapDistance(int x1,int y1,int x2,int y2);
/// Returns the map distance between two points with unit-type.
/// Returns the map distance between two points with unit-type
extern int MapDistanceToType(int x1,int y1,const UnitType* type,int x2,int y2);
/// Returns the map distance to unit.
/// Returns the map distance to unit
extern int MapDistanceToUnit(int x,int y,const Unit* dest);
/// Returns the map distance between two units.
/// Returns the map distance between two units
extern int MapDistanceBetweenUnits(const Unit* src,const Unit* dst);
/// FIXME: more docu
@ -695,28 +690,28 @@ extern int ViewPointDistanceToUnit(Unit* dest);
extern int IsEnemy(const Player* player,const Unit* dest);
/// Return true, if unit is allied with the player
extern int IsAllied(const Player* player,const Unit* dest);
/// Can this unit-type attack the other (destination).
/// Can this unit-type attack the other (destination)
extern int CanTarget(const UnitType* type,const UnitType* dest);
extern void SaveUnit(const Unit* unit,FILE* file); /// save unit-structure
extern void SaveUnits(FILE* file); /// save all units
// in unitcache.c
/// Insert new unit into cache.
/// Insert new unit into cache
extern void UnitCacheInsert(Unit* unit);
/// Remove unit from cache.
/// Remove unit from cache
extern void UnitCacheRemove(Unit* unit);
/// Change unit position in cache.
/// Change unit position in cache
extern void UnitCacheChange(Unit* unit);
/// Select units in range.
/// Select units in range
extern int UnitCacheSelect(int x1,int y1,int x2,int y2,Unit** table);
/// Select units on tile.
/// Select units on tile
extern int UnitCacheOnTile(int x,int y,Unit** table);
/// Select unit on X,Y of type naval,fly,land.
/// Select unit on X,Y of type naval,fly,land
extern Unit* UnitCacheOnXY(int x,int y,int type);
/// Print unit-cache statistic.
/// Print unit-cache statistic
extern void UnitCacheStatistic(void);
/// Initialize unit-cache.
/// Initialize unit-cache
extern void InitUnitCache(void);
// in map.c belongs to map or unit??
@ -740,9 +735,9 @@ extern void LoadDecorations(void);
extern void DrawUnits(void);
// in unit_find.c
/// Select units in rectangle range.
/// Select units in rectangle range
extern int SelectUnits(int x1,int y1,int x2,int y2,Unit** table);
/// Select units on map tile.
/// Select units on map tile
extern int SelectUnitsOnTile(int x,int y,Unit** table);
/// Find all units of this type
@ -786,16 +781,18 @@ extern Unit* AttackUnitsInReactRange(const Unit* unit);
extern void InitGroups(void);
// 2 functions to conseal the groups internal data structures...
/// Get the number of units in a particular group.
/// Get the number of units in a particular group
extern int GetNumberUnitsOfGroup(int num);
/// Get the array of units of a particular group.
/// Get the array of units of a particular group
extern Unit** GetUnitsOfGroup(int num);
/// Remove all units from a group.
/// Remove all units from a group
extern void ClearGroup(int num);
/// Set the contents of a particular group with an array of units.
/// Add the array of units to the group
extern void AddToGroup(Unit **units,int nunits,int num);
/// Set the contents of a particular group with an array of units
extern void SetGroup(Unit **units,int nunits,int num);
/// Remove a unit from a group.
/// Remove a unit from a group
extern void RemoveUnitFromGroup(Unit *unit);
// in selection.c
@ -813,7 +810,7 @@ extern int SelectUnit(Unit* unit);
extern void SelectSingleUnit(Unit* unit);
/// Remove a unit from selection
extern void UnSelectUnit(Unit* unit);
/// Add a unit to selected if not already selected, remove it otherwise.
/// Add a unit to selected if not already selected, remove it otherwise
extern int ToggleSelectUnit(Unit* unit);
/// Select units from the same type (if selectable by rectangle)
extern int SelectUnitsByType(Unit* base);

View file

@ -252,9 +252,9 @@ typedef struct _event_callback_ {
void (*MouseMoved)(int x,int y);
/// Callback for key press
void (*KeyPressed)(unsigned key);
void (*KeyPressed)(unsigned keycode,unsigned keychar);
/// Callback for key release
void (*KeyReleased)(unsigned key);
void (*KeyReleased)(unsigned keycode,unsigned keychar);
/// Callback for network event
void (*NetworkEvent)(void);

View file

@ -9,11 +9,10 @@
// FreeCraft - A free fantasy real time strategy game engine
//
/**@name groups.c - The units' groups handling. */
/*
** (c) Copyright 1999,2000 by Patrice Fortier
**
** $Id$
*/
//
// (c) Copyright 1999-2001 by Patrice Fortier and Lutz Sammer
//
// $Id$
//@{
@ -43,9 +42,9 @@
** Defines a group of units.
*/
typedef struct _unit_group_ {
Unit *units[NUM_UNITS_PER_GROUP]; /// Units in the group
int num_units; /// How many units in the group
} UnitGroup; /// group of units
Unit* Units[NUM_UNITS_PER_GROUP]; /// Units in the group
int NumUnits; /// How many units in the group
} UnitGroup; /// group of units
global UnitGroup Groups[NUM_GROUPS]; /// Number of groups predefined
@ -61,28 +60,36 @@ global void InitGroups(void)
int i;
for( i=0; i<NUM_GROUPS; i++ ) {
Groups[i].num_units=0;
Groups[i].NumUnits=0;
}
}
/**
** Return the number of units of group #num
**
** @param num Group number.
** @return Returns the number of units in the group.
*/
global int GetNumberUnitsOfGroup(int num)
{
return Groups[num].num_units;
return Groups[num].NumUnits;
}
/**
** Return the units of group #num
**
** @param num Group number.
** @return Returns an array of all units in the group.
*/
global Unit** GetUnitsOfGroup(int num)
{
return Groups[num].units;
return Groups[num].Units;
}
/**
** Clear contents of group #num
**
** @param num Group number.
*/
global void ClearGroup(int num)
{
@ -90,35 +97,54 @@ global void ClearGroup(int num)
int i;
group=&Groups[num];
for( i=0; i<group->num_units; i++ ) {
group->units[i]->GroupId=-1;
group->units[i]=NoUnitP;
for( i=0; i<group->NumUnits; i++ ) {
group->Units[i]->GroupId=-1;
DebugCheck( group->Units[i]->Destroyed );
}
group->num_units=0;
group->NumUnits=0;
}
/**
** Set group #num contents to unit array "units"
** Add units to group #num contents from unit array "units"
**
** @param units Array of units to place into group.
** @param nunits Number of units in array.
** @param num Group number for storage.
*/
global void SetGroup(Unit **units,int nunits,int num)
global void AddToGroup(Unit **units,int nunits,int num)
{
UnitGroup *group;
int i;
DebugCheck(num>NUM_GROUPS);
ClearGroup(num);
group=&Groups[num];
for( i=0; i<nunits; i++ ) {
group->units[i]=units[i];
group->units[i]->GroupId=num;
for( i=0; group->NumUnits<NUM_UNITS_PER_GROUP && i<nunits; i++ ) {
group->Units[group->NumUnits++]=units[i];
units[i]->GroupId=num;
}
group->num_units=nunits;
}
/**
** Set group #num contents to unit array "units"
**
** @param units Array of units to place into group.
** @param nunits Number of units in array.
** @param num Group number for storage.
*/
global void SetGroup(Unit **units,int nunits,int num)
{
DebugCheck(num>NUM_GROUPS || nunits>NUM_UNITS_PER_GROUP);
ClearGroup(num);
AddToGroup(units,nunits,num);
}
/**
** Remove unit from its group
**
** @param unit Unit to remove from group.
*/
global void RemoveUnitFromGroup(Unit *unit)
{
@ -126,24 +152,21 @@ global void RemoveUnitFromGroup(Unit *unit)
int num;
int i;
// unit doesn't belong to a group
if( (num=unit->GroupId)==-1 ) {
return;
}
DebugCheck( unit->GroupId==-1 ); // unit doesn't belong to a group
num=unit->GroupId;
group=&Groups[num];
for( i=0; group->units[i]!=unit; i++ ) {
for( i=0; group->Units[i]!=unit; i++ ) {
;
}
DebugCheck( i>=group->num_units );
DebugCheck( i>=group->NumUnits ); // oops not found
// This is a clean way that will allow us to add a unit
// to a group easily, or make an easy array walk...
if( i<--group->num_units ) {
group->units[i]=group->units[group->num_units];
if( i<--group->NumUnits ) {
group->Units[i]=group->Units[group->NumUnits];
}
group->units[group->num_units]=NoUnitP;
unit->GroupId=-1;
}

View file

@ -95,6 +95,7 @@ global void ChangeSelectedUnits(Unit** units,int count)
global int SelectUnit(Unit* unit)
{
if ( unit->Revealer ) { // Revealers cannot be selected
DebugLevel0Fn("Selecting revealer?\n");
return 0;
}

View file

@ -284,6 +284,15 @@ local void WaitCallbackKey(unsigned dummy)
WaitNoEvent=0;
}
/**
** Callback for input.
*/
local void WaitCallbackKey2(unsigned dummy1,unsigned dummy2)
{
DebugLevel3Fn("Pressed %8x %8x %8x\n",MouseButtons,dummy1,dummy2);
WaitNoEvent=0;
}
/**
** Callback for input.
*/
@ -306,8 +315,8 @@ local void WaitForInput(int timeout)
callbacks.ButtonPressed=WaitCallbackKey;
callbacks.ButtonReleased=WaitCallbackKey;
callbacks.MouseMoved=WaitCallbackMouse;
callbacks.KeyPressed=WaitCallbackKey;
callbacks.KeyReleased=WaitCallbackKey;
callbacks.KeyPressed=WaitCallbackKey2;
callbacks.KeyReleased=WaitCallbackKey2;
callbacks.NetworkEvent=NetworkEvent;
callbacks.SoundReady=WriteSound;

View file

@ -54,6 +54,8 @@ local enum _key_state_ {
-- Variables
----------------------------------------------------------------------------*/
local int SavedMapPositionX[4]; /// Saved map position X
local int SavedMapPositionY[4]; /// Saved map position Y
local char Input[80]; /// line input for messages/long commands
local int InputIndex; /// current index into input
local char InputStatusLine[80]; /// Last input status line
@ -84,7 +86,7 @@ local void ShowInput(void)
/**
** Begin input.
*/
local void BeginInput(void)
local void UiBeginInput(void)
{
KeyState=KeyStateInput;
Input[0]='\0';
@ -107,6 +109,35 @@ local void UiUnselectAll(void)
UpdateButtonPanel();
}
/**
** Center on group.
**
** @param group Group number to center on.
**
** @todo Improve this function, try to show all selected units
** or the most possible units.
*/
local void UiCenterOnGroup(unsigned group)
{
Unit** units;
int n;
int x;
int y;
n=GetNumberUnitsOfGroup(group);
if( n-- ) {
units=GetUnitsOfGroup(group);
x=units[n]->X;
y=units[n]->Y;
while( n-- ) {
x+=(units[n]->X-x)/2;
y+=(units[n]->Y-y)/2;
}
MapCenter(x,y);
}
}
/**
** Select group. If already selected center on the group.
**
@ -114,9 +145,27 @@ local void UiUnselectAll(void)
*/
local void UiSelectGroup(unsigned group)
{
Unit** units;
int n;
//
// Check if group is already selected.
//
n=GetNumberUnitsOfGroup(group);
if( n && NumSelected==n ) {
units=GetUnitsOfGroup(group);
while( n-- && units[n]==Selected[n] ) {
}
if( n==-1 ) {
UiCenterOnGroup(group);
return;
}
}
SelectGroup(group);
UpdateButtonPanel();
MustRedraw|=RedrawCursor|RedrawMap|RedrawPanels;
MustRedraw|=RedrawMap|RedrawPanels;
}
/**
@ -126,9 +175,20 @@ local void UiSelectGroup(unsigned group)
*/
local void UiAddGroupToSelection(unsigned group)
{
SelectGroup(group);
Unit** units;
int n;
if( !(n=GetNumberUnitsOfGroup(group)) ) {
return;
}
units=GetUnitsOfGroup(group);
while( n-- ) {
SelectUnit(units[n]);
}
UpdateButtonPanel();
MustRedraw|=RedrawCursor|RedrawMap|RedrawPanels;
MustRedraw|=RedrawMap|RedrawPanels;
}
/**
@ -148,8 +208,11 @@ local void UiDefineGroup(unsigned group)
*/
local void UiAddToGroup(unsigned group)
{
AddToGroup(Selected,NumSelected,group);
}
#if 0
/**
** Define an alternate group. The current selected units become a new
** group. But remains in the old group.
@ -158,7 +221,6 @@ local void UiAddToGroup(unsigned group)
*/
local void UiDefineAlternateGroup(unsigned group)
{
SetGroup(Selected,NumSelected,group);
}
/**
@ -171,6 +233,8 @@ local void UiAddToAlternateGroup(unsigned group)
{
}
#endif
/**
** Toggle sound on / off.
*/
@ -180,9 +244,9 @@ local void UiToggleSound(void)
SoundOff^=1;
}
if( SoundOff ) {
SetMessage("Sound is off.");
SetStatusLine("Sound is off.");
} else {
SetMessage("Sound is off.");
SetStatusLine("Sound is on.");
}
}
@ -199,6 +263,97 @@ local void UiTogglePause(void)
}
}
/**
** Enter menu mode.
*/
local void UiEnterMenu(void)
{
GamePaused=1;
SetStatusLine("Game Paused");
ProcessMenu(MENU_GAME, 0);
}
/**
** Increment game speed.
*/
local void UiIncrementGameSpeed(void)
{
VideoSyncSpeed+=10;
SetVideoSync();
SetStatusLine("Faster");
}
/**
** Decrement game speed.
*/
local void UiDecrementGameSpeed(void)
{
VideoSyncSpeed-=10;
if( VideoSyncSpeed<=0 ) {
VideoSyncSpeed=1;
}
SetVideoSync();
SetStatusLine("Slower");
}
/**
** Center on the selected units.
**
** @todo Improve this function, try to show all selected units
** or the most possible units.
*/
local void UiCenterOnSelected(void)
{
int x;
int y;
int n;
if( (n=NumSelected) ) {
x=Selected[--n]->X;
y=Selected[n]->Y;
while( n-- ) {
x+=(Selected[n]->X-x)/2;
y+=(Selected[n]->Y-y)/2;
}
MapCenter(x,y);
}
}
/**
** Save current map position.
**
** @param position Map position slot.
*/
local void UiSaveMapPosition(unsigned position)
{
SavedMapPositionX[position]=MapX;
SavedMapPositionY[position]=MapY;
}
/**
** Recall map position.
**
** @param position Map position slot.
*/
local void UiRecallMapPosition(unsigned position)
{
MapSetViewpoint(SavedMapPositionX[position],SavedMapPositionY[position]);
}
/**
** Toggle terrain display on/off.
*/
local void UiToggleTerrain(void)
{
MinimapWithTerrain^=1;
if( MinimapWithTerrain ) {
SetStatusLine("Terrain displayed.");
} else {
SetStatusLine("Terrain hidden.");
}
MustRedraw|=RedrawMinimap;
}
/**
** Handle keys in command mode.
**
@ -209,19 +364,21 @@ local int CommandKey(int key)
{
switch( key ) {
case '\r': // Return enters chat/input mode.
BeginInput();
UiBeginInput();
return 1;
case '^': // Unselect everything
UiUnselectAll();
break;
case '0': case '1': case '2': // Group selection
case '3': case '4': case '5':
case '6': case '7': case '8':
case '9':
if( KeyModifiers&ModifierShift ) {
if( KeyModifiers&ModifierAlt ) {
UiAddToAlternateGroup(key-'0');
//UiAddToAlternateGroup(key-'0');
UiCenterOnGroup(key-'0');
} else if( KeyModifiers&ModifierControl ) {
UiAddToGroup(key-'0');
} else {
@ -229,7 +386,8 @@ local int CommandKey(int key)
}
} else {
if( KeyModifiers&ModifierAlt ) {
UiDefineAlternateGroup(key-'0');
// UiDefineAlternateGroup(key-'0');
UiCenterOnGroup(key-'0');
} else if( KeyModifiers&ModifierControl ) {
UiDefineGroup(key-'0');
} else {
@ -272,33 +430,28 @@ local int CommandKey(int key)
case KeyCodeF2:
case KeyCodeF3:
case KeyCodeF4: // Set/Goto place
DebugLevel0("FIXME: not written\n");
if( KeyModifiers&ModifierShift ) {
UiSaveMapPosition(key-KeyCodeF1);
} else {
UiRecallMapPosition(key-KeyCodeF1);
}
break;
case 'm':
case 'M': /// ALT+M, F10 Game menu
case 'M': // ALT+M, F10 Game menu
if( !(KeyModifiers&ModifierAlt) ) {
break;
}
case KeyCodeF10:
GamePaused=1;
SetStatusLine("Game Paused");
ProcessMenu(MENU_GAME, 0);
UiEnterMenu();
break;
case '+':
VideoSyncSpeed+=10;
SetVideoSync();
SetStatusLine("Faster");
case '+': // + Faster
UiIncrementGameSpeed();
break;
case '-':
VideoSyncSpeed-=10;
if( VideoSyncSpeed<=0 ) {
VideoSyncSpeed=1;
}
SetVideoSync();
SetStatusLine("Slower");
case '-': // - Slower
UiDecrementGameSpeed();
break;
case 'l': // ALT l F12 load game menu
@ -307,7 +460,7 @@ local int CommandKey(int key)
break;
}
case KeyCodeF12:
SetStatusLine("Slower");
SetStatusLine("Loading not supported");
break;
case 's'&0x1F: // Ctrl + S - Turn sound on / off
@ -316,6 +469,10 @@ local int CommandKey(int key)
case 's': // ALT s F11 save game menu
case 'S':
if( KeyModifiers&ModifierControl ) {
UiToggleSound();
break;
}
if( !(KeyModifiers&ModifierAlt) ) {
break;
}
@ -323,11 +480,9 @@ local int CommandKey(int key)
SaveAll();
break;
case 'c': // center on selected units
case 'c': // CTRL+C,ALT+C, C center on units
case 'C':
if( NumSelected==1 ) {
MapCenter(Selected[0]->X,Selected[0]->Y);
}
UiCenterOnSelected();
break;
case 'g'&0x1F:
@ -365,9 +520,7 @@ local int CommandKey(int key)
case '\t': // TAB toggles minimap.
// FIXME: more...
// FIXME: shift+TAB
DebugLevel1("TAB\n");
MinimapWithTerrain^=1;
MustRedraw|=RedrawMinimap;
UiToggleTerrain();
break;
case 'x'&0x1F:
@ -418,107 +571,107 @@ local int CommandKey(int key)
*/
local int InputKey(int key)
{
switch( key ) {
switch (key) {
case '\r':
#if defined(USE_CCL)
if( Input[0]=='(' ) {
if (Input[0] == '(') {
CclCommand(Input);
} else {
#endif
// Handle cheats
// Handle cheats
// FIXME: disable cheats
if (strcmp(Input, "there is no aliens level") == 0) {
// FIXME: no function yet.
SetMessage( "cheat enabled" );
if (strcmp(Input, "there is no aliens level") == 0) {
// FIXME: no function yet.
SetMessage("cheat enabled");
} else if (strcmp(Input, "hatchet") == 0) {
SpeedChop = 52/2;
SetMessage( "Wow -- I got jigsaw!" );
} else if (strcmp(Input, "glittering prizes") == 0) {
ThisPlayer->Resources[GoldCost] += 12000;
ThisPlayer->Resources[WoodCost] += 5000;
ThisPlayer->Resources[OilCost] += 5000;
ThisPlayer->Resources[OreCost] += 5000;
ThisPlayer->Resources[StoneCost]+= 5000;
ThisPlayer->Resources[CoalCost] += 5000;
MustRedraw|=RedrawResources;
SetMessage( "!!! :)" );
SpeedChop = 52 / 2;
SetMessage("Wow -- I got jigsaw!");
} else if (strcmp(Input, "glittering prizes") == 0) {
ThisPlayer->Resources[GoldCost] += 12000;
ThisPlayer->Resources[WoodCost] += 5000;
ThisPlayer->Resources[OilCost] += 5000;
ThisPlayer->Resources[OreCost] += 5000;
ThisPlayer->Resources[StoneCost] += 5000;
ThisPlayer->Resources[CoalCost] += 5000;
MustRedraw |= RedrawResources;
SetMessage("!!! :)");
} else if (strcmp(Input, "on screen") == 0) {
RevealMap();
RevealMap();
} else if (strcmp(Input, "fow on") == 0) {
TheMap.NoFogOfWar = 0;
MapUpdateVisible();
SetMessage( "Fog Of War is now ON" );
TheMap.NoFogOfWar = 0;
MapUpdateVisible();
SetMessage("Fog Of War is now ON");
} else if (strcmp(Input, "fow off") == 0) {
TheMap.NoFogOfWar = 1;
MapUpdateVisible();
SetMessage( "Fog Of War is now OFF" );
TheMap.NoFogOfWar = 1;
MapUpdateVisible();
SetMessage("Fog Of War is now OFF");
} else if (strcmp(Input, "fast debug") == 0) {
SpeedMine=10; // speed factor for mine gold
SpeedGold=10; // speed factor for getting gold
SpeedChop=10; // speed factor for chop
SpeedWood=10; // speed factor for getting wood
SpeedHaul=10; // speed factor for haul oil
SpeedOil=10; // speed factor for getting oil
SpeedBuild=10; // speed factor for building
SpeedTrain=10; // speed factor for training
SpeedUpgrade=10; // speed factor for upgrading
SpeedResearch=10; // speed factor for researching
SetMessage( "FAST DEBUG SPEED" );
SpeedMine = 10; // speed factor for mine gold
SpeedGold = 10; // speed factor for getting gold
SpeedChop = 10; // speed factor for chop
SpeedWood = 10; // speed factor for getting wood
SpeedHaul = 10; // speed factor for haul oil
SpeedOil = 10; // speed factor for getting oil
SpeedBuild = 10; // speed factor for building
SpeedTrain = 10; // speed factor for training
SpeedUpgrade = 10; // speed factor for upgrading
SpeedResearch = 10; // speed factor for researching
SetMessage("FAST DEBUG SPEED");
} else if (strcmp(Input, "normal debug") == 0) {
SpeedMine=1; // speed factor for mine gold
SpeedGold=1; // speed factor for getting gold
SpeedChop=1; // speed factor for chop
SpeedWood=1; // speed factor for getting wood
SpeedHaul=1; // speed factor for haul oil
SpeedOil=1; // speed factor for getting oil
SpeedBuild=1; // speed factor for building
SpeedTrain=1; // speed factor for training
SpeedUpgrade=1; // speed factor for upgrading
SpeedResearch=1; // speed factor for researching
SetMessage( "NORMAL DEBUG SPEED" );
SpeedMine = 1; // speed factor for mine gold
SpeedGold = 1; // speed factor for getting gold
SpeedChop = 1; // speed factor for chop
SpeedWood = 1; // speed factor for getting wood
SpeedHaul = 1; // speed factor for haul oil
SpeedOil = 1; // speed factor for getting oil
SpeedBuild = 1; // speed factor for building
SpeedTrain = 1; // speed factor for training
SpeedUpgrade = 1; // speed factor for upgrading
SpeedResearch = 1; // speed factor for researching
SetMessage("NORMAL DEBUG SPEED");
} else if (strcmp(Input, "make it so") == 0) {
SpeedMine=10; // speed factor for mine gold
SpeedGold=10; // speed factor for getting gold
SpeedChop=10; // speed factor for chop
SpeedWood=10; // speed factor for getting wood
SpeedHaul=10; // speed factor for haul oil
SpeedOil=10; // speed factor for getting oil
SpeedBuild=10; // speed factor for building
SpeedTrain=10; // speed factor for training
SpeedUpgrade=10; // speed factor for upgrading
SpeedResearch=10; // speed factor for researching
ThisPlayer->Resources[GoldCost] += 32000;
ThisPlayer->Resources[WoodCost] += 32000;
ThisPlayer->Resources[OilCost] += 32000;
ThisPlayer->Resources[OreCost] += 32000;
ThisPlayer->Resources[StoneCost]+= 32000;
ThisPlayer->Resources[CoalCost] += 32000;
MustRedraw|=RedrawResources;
SetMessage( "SO!" );
SpeedMine = 10; // speed factor for mine gold
SpeedGold = 10; // speed factor for getting gold
SpeedChop = 10; // speed factor for chop
SpeedWood = 10; // speed factor for getting wood
SpeedHaul = 10; // speed factor for haul oil
SpeedOil = 10; // speed factor for getting oil
SpeedBuild = 10; // speed factor for building
SpeedTrain = 10; // speed factor for training
SpeedUpgrade = 10; // speed factor for upgrading
SpeedResearch = 10; // speed factor for researching
ThisPlayer->Resources[GoldCost] += 32000;
ThisPlayer->Resources[WoodCost] += 32000;
ThisPlayer->Resources[OilCost] += 32000;
ThisPlayer->Resources[OreCost] += 32000;
ThisPlayer->Resources[StoneCost] += 32000;
ThisPlayer->Resources[CoalCost] += 32000;
MustRedraw |= RedrawResources;
SetMessage("SO!");
} else {
// FIXME: only to selected players ...
NetworkChatMessage(Input);
// FIXME: only to selected players ...
}
NetworkChatMessage(Input);
#if defined(USE_CCL)
}
#endif
case '\e':
ClearStatusLine();
KeyState=KeyStateCommand;
KeyState = KeyStateCommand;
return 1;
case '\b':
DebugLevel3("Key <-\n");
if( InputIndex ) {
Input[--InputIndex]='\0';
if (InputIndex) {
Input[--InputIndex] = '\0';
ShowInput();
}
return 1;
default:
if( key>=' ' && key<=256 ) {
if( InputIndex<sizeof(Input)-1 ) {
DebugLevel3("Key %c\n",key);
Input[InputIndex++]=key;
Input[InputIndex]='\0';
if (key >= ' ' && key <= 256) {
if (InputIndex < sizeof(Input) - 1) {
DebugLevel3("Key %c\n", key);
Input[InputIndex++] = key;
Input[InputIndex] = '\0';
ShowInput();
}
return 1;
@ -533,7 +686,7 @@ local int InputKey(int key)
**
** @param key Key scancode.
*/
global void HandleKeyDown(unsigned key)
global void HandleKeyDown(unsigned key,unsigned keychar)
{
// Handle Modifier Keys
switch( key ) {
@ -559,19 +712,23 @@ global void HandleKeyDown(unsigned key)
// Handle All other keys
switch( InterfaceState ) {
case IfaceStateNormal: // Normal Game state
switch( KeyState ) {
case KeyStateCommand:
// Command line input: for message or cheat
if( KeyState==KeyStateInput && keychar ) {
InputKey(keychar);
} else {
// If no modifier look if button bound
if( !(KeyModifiers&(ModifierControl|ModifierAlt
|ModifierSuper|ModifierHyper)) ) {
if( DoButtonPanelKey(key) ) {
return;
}
CommandKey(key);
return;
case KeyStateInput:
InputKey(key);
return;
}
CommandKey(key);
}
return;
case IfaceStateMenu: // Menu active
MenuKey(key);
MenuKey(keychar);
return;
}
}
@ -581,7 +738,7 @@ global void HandleKeyDown(unsigned key)
**
** @param key Key scancode.
*/
global void HandleKeyUp(unsigned key)
global void HandleKeyUp(unsigned key,unsigned keychar)
{
switch( key ) {
case KeyCodeShift:

View file

@ -634,6 +634,8 @@ global void UIHandleMouseMove(int x,int y)
}
}
//.............................................................................
/**
** Send selected units to repair
**
@ -912,6 +914,8 @@ local void SendCommand(int x,int y)
}
}
//.............................................................................
/**
** Handle mouse button pressed in select state.
**

View file

@ -601,30 +601,34 @@ local unsigned X112InternalKeycode(const KeySym code)
** Handle keyboard! (pressed)
**
** @param callbacks Call backs that handle the events.
** @param code X11 keysym structure pointer.
** @param keycode X11 key symbol.
** @param keychar Keyboard character
*/
local void X11HandleKeyPress(const EventCallback* callbacks,const KeySym code)
local void X11HandleKeyPress(const EventCallback* callbacks,KeySym keycode,
unsigned keychar)
{
int icode;
icode=X112InternalKeycode(code);
icode=X112InternalKeycode(keycode);
callbacks->KeyPressed(icode);
callbacks->KeyPressed(icode,keychar);
}
/**
** Handle keyboard! (release)
**
** @param callbacks Call backs that handle the events.
** @param code X11 keysym structure pointer.
** @param keycode X11 key symbol.
** @param keychar Keyboard character
*/
local void X11HandleKeyRelease(const EventCallback* callbacks,const KeySym code)
local void X11HandleKeyRelease(const EventCallback* callbacks,KeySym keycode,
unsigned keychar)
{
int icode;
icode=X112InternalKeycode(code);
icode=X112InternalKeycode(keycode);
callbacks->KeyReleased(icode);
callbacks->KeyReleased(icode,keychar);
}
/**
@ -699,22 +703,38 @@ local void X11DoEvent(const EventCallback* callbacks)
char buf[128];
int num;
KeySym keysym;
KeySym key;
X11HandleModifiers((XKeyEvent*)&event);
// FIXME: this didn't handle keypad correct!
num=XLookupString((XKeyEvent*)&event,buf,sizeof(buf),&keysym,0);
DebugLevel3("\tKey %lx `%s'\n",keysym,buf);
key=XLookupKeysym((XKeyEvent*)&event,0);
DebugLevel3("\tKeyv %lx %lx `%*.*s'\n",key,keysym,num,num,buf);
if( num==1 ) {
X11HandleKeyPress(callbacks,*buf);
X11HandleKeyPress(callbacks,key,*buf);
} else {
X11HandleKeyPress(callbacks,keysym);
X11HandleKeyPress(callbacks,key,keysym);
}
}
break;
case KeyRelease:
DebugLevel3("\tKey release\n");
X11HandleKeyRelease(callbacks,XLookupKeysym((XKeyEvent*)&event,0));
{
char buf[128];
int num;
KeySym keysym;
KeySym key;
X11HandleModifiers((XKeyEvent*)&event);
num=XLookupString((XKeyEvent*)&event,buf,sizeof(buf),&keysym,0);
key=XLookupKeysym((XKeyEvent*)&event,0);
DebugLevel3("\tKey^ %lx %lx `%*.*s'\n",key,keysym,num,num,buf);
if( num==1 ) {
X11HandleKeyRelease(callbacks,key,*buf);
} else {
X11HandleKeyRelease(callbacks,key,keysym);
}
}
break;
case ConfigureNotify: // IGNORE, not useful for us yet -
@ -917,9 +937,9 @@ global void WaitEventsAndKeepSync(void)
int morex;
int connection;
callbacks.ButtonPressed=(void*)HandleButtonDown;
callbacks.ButtonReleased=(void*)HandleButtonUp;
callbacks.MouseMoved=(void*)HandleMouseMove;
callbacks.ButtonPressed=HandleButtonDown;
callbacks.ButtonReleased=HandleButtonUp;
callbacks.MouseMoved=HandleMouseMove;
callbacks.KeyPressed=HandleKeyDown;
callbacks.KeyReleased=HandleKeyUp;

View file

@ -287,25 +287,26 @@ global void Invalidate(void)
**
** @return ASCII code or internal keycode.
*/
local int Sdl2InternalKeycode(const SDL_keysym * code)
local int Sdl2InternalKeycode(const SDL_keysym * code, int *keychar)
{
int icode;
//
// Convert SDL keycodes into internal keycodes.
//
*keychar = 0;
switch ((icode = code->sym)) {
case SDLK_ESCAPE:
icode = '\e';
*keychar = icode = '\e';
break;
case SDLK_RETURN:
icode = '\r';
*keychar = icode = '\r';
break;
case SDLK_BACKSPACE:
icode = '\b';
*keychar = icode = '\b';
break;
case SDLK_TAB:
icode = '\t';
*keychar = icode = '\t';
break;
case SDLK_UP:
icode = KeyCodeUp;
@ -410,18 +411,12 @@ local int Sdl2InternalKeycode(const SDL_keysym * code)
icode = KeyCodeSuper;
break;
default:
if (icode >= '0' && icode <= '9') {
if (code->mod & (KMOD_CTRL | KMOD_ALT | KMOD_META)) {
// Do not translate these to support grouping!
break;
}
}
if ((code->unicode & 0xFF80) == 0) {
icode = code->unicode & 0x7F;
*keychar = code->unicode & 0x7F;
} else {
// An international character..
// let's asume latin 1 for now
icode = code->unicode & 0xFF;
*keychar = code->unicode & 0xFF;
}
break;
}
@ -435,14 +430,15 @@ local int Sdl2InternalKeycode(const SDL_keysym * code)
** @param callback Callback funktion for key down.
** @param code SDL keysym structure pointer.
*/
local void SdlHandleKeyPress(void (*const callback) (unsigned),
local void SdlHandleKeyPress(void (*const callback) (unsigned,unsigned),
const SDL_keysym* code)
{
int icode;
int keychar;
icode = Sdl2InternalKeycode(code);
icode = Sdl2InternalKeycode(code,&keychar);
callback(icode);
callback(icode,keychar);
}
/**
@ -451,14 +447,15 @@ local void SdlHandleKeyPress(void (*const callback) (unsigned),
** @param callback Callback funktion for key up.
** @param code SDL keysym structure pointer.
*/
local void SdlHandleKeyRelease(void (*const callback) (unsigned),
local void SdlHandleKeyRelease(void (*const callback) (unsigned,unsigned),
const SDL_keysym* code)
{
int icode;
int keychar;
icode=Sdl2InternalKeycode(code);
icode=Sdl2InternalKeycode(code,&keychar);
callback(icode);
callback(icode,keychar);
}
/**
@ -519,12 +516,12 @@ local void SdlDoEvent(const EventCallback* callbacks, const SDL_Event * event)
break;
case SDL_KEYDOWN:
DebugLevel3("\tKey press\n");
DebugLevel2("\tKey press\n");
SdlHandleKeyPress(callbacks->KeyPressed, &event->key.keysym);
break;
case SDL_KEYUP:
DebugLevel3("\tKey release\n");
DebugLevel2("\tKey release\n");
SdlHandleKeyRelease(callbacks->KeyReleased, &event->key.keysym);
break;

View file

@ -395,192 +395,199 @@ local void MouseEvent(int button, int dx, int dy, int dz, int drx, int dry, int
/**
** Process keyboard event.
**
** @param scancode SVGAlib scancode
** @param prees True if key was pressed
**
** @todo International scancode support.
*/
local void KeyboardEvent(int scancode, int press) {
local void KeyboardEvent(int scancode, int press)
{
int icode;
int keychar;
IfDebug( icode=0; ); // keeps the compiler happy
IfDebug( icode = 0; ); // keeps the compiler happy
keychar = 0;
if(press == KEY_EVENTPRESS) {
if (press == KEY_EVENTPRESS) {
// FIXME: combine scancode -> internal keycode of press and release
switch(scancode) {
switch (scancode) {
case SCANCODE_1:
if(KeyModifiers & ModifierShift) {
keychar = icode = '1';
if (KeyModifiers & ModifierShift) {
icode = '!';
} else {
icode = '1';
}
break;
case SCANCODE_2:
if(KeyModifiers & ModifierShift) {
keychar = icode = '2';
if (KeyModifiers & ModifierShift) {
icode = '@';
} else {
icode = '2';
}
break;
case SCANCODE_3:
if(KeyModifiers & ModifierShift) {
icode = '#';
} else {
keychar = icode = '3';
if (KeyModifiers & ModifierShift) {
icode = '3';
}
break;
case SCANCODE_4:
if(KeyModifiers & ModifierShift) {
keychar = icode = '4';
if (KeyModifiers & ModifierShift) {
icode = '$';
} else {
icode = '4';
}
break;
case SCANCODE_5:
if(KeyModifiers & ModifierShift) {
keychar = icode = '5';
if (KeyModifiers & ModifierShift) {
icode = '%';
} else {
icode = '5';
}
break;
case SCANCODE_6:
if(KeyModifiers & ModifierShift) {
keychar = icode = '6';
if (KeyModifiers & ModifierShift) {
icode = '^';
} else {
icode = '6';
}
break;
case SCANCODE_7:
if(KeyModifiers & ModifierShift) {
keychar = icode = '7';
if (KeyModifiers & ModifierShift) {
icode = '&';
} else {
icode = '7';
}
break;
case SCANCODE_8:
if(KeyModifiers & ModifierShift) {
keychar = icode = '8';
if (KeyModifiers & ModifierShift) {
icode = '*';
} else {
icode = '8';
}
break;
case SCANCODE_9:
if(KeyModifiers & ModifierShift) {
keychar = icode = '9';
if (KeyModifiers & ModifierShift) {
icode = '(';
} else {
icode = '9';
}
break;
case SCANCODE_0:
if(KeyModifiers & ModifierShift) {
keychar = icode = '0';
if (KeyModifiers & ModifierShift) {
icode = ')';
} else {
icode = '0';
}
break;
case SCANCODE_A:
icode = 'a';
keychar = icode = 'a';
break;
case SCANCODE_B:
icode = 'b';
keychar = icode = 'b';
break;
case SCANCODE_C:
icode = 'c';
keychar = icode = 'c';
break;
case SCANCODE_D:
icode = 'd';
keychar = icode = 'd';
break;
case SCANCODE_E:
icode = 'e';
keychar = icode = 'e';
break;
case SCANCODE_F:
icode = 'f';
keychar = icode = 'f';
break;
case SCANCODE_G:
icode = 'g';
keychar = icode = 'g';
break;
case SCANCODE_H:
icode = 'h';
keychar = icode = 'h';
break;
case SCANCODE_I:
icode = 'i';
keychar = icode = 'i';
break;
case SCANCODE_J:
icode = 'j';
keychar = icode = 'j';
break;
case SCANCODE_K:
icode = 'k';
keychar = icode = 'k';
break;
case SCANCODE_L:
icode = 'l';
keychar = icode = 'l';
break;
case SCANCODE_M:
icode = 'm';
keychar = icode = 'm';
break;
case SCANCODE_N:
icode = 'n';
keychar = icode = 'n';
break;
case SCANCODE_O:
icode = 'o';
keychar = icode = 'o';
break;
case SCANCODE_P:
icode = 'p';
keychar = icode = 'p';
break;
case SCANCODE_Q:
icode = 'q';
keychar = icode = 'q';
break;
case SCANCODE_R:
icode = 'r';
keychar = icode = 'r';
break;
case SCANCODE_S:
icode = 's';
keychar = icode = 's';
break;
case SCANCODE_T:
icode = 't';
keychar = icode = 't';
break;
case SCANCODE_U:
icode = 'u';
keychar = icode = 'u';
break;
case SCANCODE_V:
icode = 'v';
keychar = icode = 'v';
break;
case SCANCODE_W:
icode = 'w';
keychar = icode = 'w';
break;
case SCANCODE_X:
icode = 'x';
keychar = icode = 'x';
break;
case SCANCODE_Y:
icode = 'y';
keychar = icode = 'y';
break;
case SCANCODE_Z:
icode = 'z';
keychar = icode = 'z';
break;
case SCANCODE_SPACE:
icode = ' ';
keychar = icode = ' ';
break;
case SCANCODE_MINUS:
if(KeyModifiers & ModifierShift) {
keychar = icode = '-';
if (KeyModifiers & ModifierShift) {
icode = '_';
} else {
icode = '-';
}
break;
case SCANCODE_EQUAL:
if(KeyModifiers & ModifierShift) {
keychar = icode = '=';
if (KeyModifiers & ModifierShift) {
icode = '+';
} else {
icode = '=';
}
break;
case SCANCODE_ESCAPE:
icode = '\e';
keychar = icode = '\e';
break;
case SCANCODE_ENTER:
icode = '\r';
keychar = icode = '\r';
break;
case SCANCODE_BACKSPACE:
icode = '\b';
keychar = icode = '\b';
break;
case SCANCODE_TAB:
icode = '\t';
keychar = icode = '\t';
break;
case SCANCODE_COMMA:
keychar = icode = ',';
break;
case SCANCODE_PERIOD:
keychar = icode = '.';
break;
case SCANCODE_SLASH:
keychar = icode = '/';
break;
case SCANCODE_CURSORBLOCKUP:
icode = KeyCodeUp;
break;
@ -661,7 +668,7 @@ local void KeyboardEvent(int scancode, int press) {
icode = KeyCodeKP9;
break;
// KeyCodePause
// KeyCodePause
case SCANCODE_LEFTSHIFT:
case SCANCODE_RIGHTSHIFT:
@ -674,193 +681,193 @@ local void KeyboardEvent(int scancode, int press) {
case SCANCODE_LEFTALT:
case SCANCODE_RIGHTALT:
KeyModifiers |= ModifierAlt;
// Super, Hyper
// Super, Hyper
}
if(KeyModifiers&ModifierShift){
if(icode <= 'z' && icode >= 'a')
if (KeyModifiers & ModifierShift) {
if (icode <= 'z' && icode >= 'a') {
icode -= 32;
}
}
SVGALibCallbacks->KeyPressed(icode);
} else if(press == KEY_EVENTRELEASE) {
SVGALibCallbacks->KeyPressed(icode, keychar);
} else if (press == KEY_EVENTRELEASE) {
// FIXME: combine scancode -> internal keycode of press and release
switch(scancode) {
switch (scancode) {
case SCANCODE_1:
if(KeyModifiers & ModifierShift) {
keychar = icode = '1';
if (KeyModifiers & ModifierShift) {
icode = '!';
} else {
icode = '1';
}
break;
case SCANCODE_2:
if(KeyModifiers & ModifierShift) {
keychar = icode = '2';
if (KeyModifiers & ModifierShift) {
icode = '@';
} else {
icode = '2';
}
break;
case SCANCODE_3:
if(KeyModifiers & ModifierShift) {
icode = '#';
} else {
keychar = icode = '3';
if (KeyModifiers & ModifierShift) {
icode = '3';
}
break;
case SCANCODE_4:
if(KeyModifiers & ModifierShift) {
keychar = icode = '4';
if (KeyModifiers & ModifierShift) {
icode = '$';
} else {
icode = '4';
}
break;
case SCANCODE_5:
if(KeyModifiers & ModifierShift) {
keychar = icode = '5';
if (KeyModifiers & ModifierShift) {
icode = '%';
} else {
icode = '5';
}
break;
case SCANCODE_6:
if(KeyModifiers & ModifierShift) {
keychar = icode = '6';
if (KeyModifiers & ModifierShift) {
icode = '^';
} else {
icode = '6';
}
break;
case SCANCODE_7:
if(KeyModifiers & ModifierShift) {
keychar = icode = '7';
if (KeyModifiers & ModifierShift) {
icode = '&';
} else {
icode = '7';
}
break;
case SCANCODE_8:
if(KeyModifiers & ModifierShift) {
keychar = icode = '8';
if (KeyModifiers & ModifierShift) {
icode = '*';
} else {
icode = '8';
}
break;
case SCANCODE_9:
if(KeyModifiers & ModifierShift) {
keychar = icode = '9';
if (KeyModifiers & ModifierShift) {
icode = '(';
} else {
icode = '9';
}
break;
case SCANCODE_0:
if(KeyModifiers & ModifierShift) {
keychar = icode = '0';
if (KeyModifiers & ModifierShift) {
icode = ')';
} else {
icode = '0';
}
break;
case SCANCODE_A:
icode = 'a';
keychar = icode = 'a';
break;
case SCANCODE_B:
icode = 'b';
keychar = icode = 'b';
break;
case SCANCODE_C:
icode = 'c';
keychar = icode = 'c';
break;
case SCANCODE_D:
icode = 'd';
keychar = icode = 'd';
break;
case SCANCODE_E:
icode = 'e';
keychar = icode = 'e';
break;
case SCANCODE_F:
icode = 'f';
keychar = icode = 'f';
break;
case SCANCODE_G:
icode = 'g';
keychar = icode = 'g';
break;
case SCANCODE_H:
icode = 'h';
keychar = icode = 'h';
break;
case SCANCODE_I:
icode = 'i';
keychar = icode = 'i';
break;
case SCANCODE_J:
icode = 'j';
keychar = icode = 'j';
break;
case SCANCODE_K:
icode = 'k';
keychar = icode = 'k';
break;
case SCANCODE_L:
icode = 'l';
keychar = icode = 'l';
break;
case SCANCODE_M:
icode = 'm';
keychar = icode = 'm';
break;
case SCANCODE_N:
icode = 'n';
keychar = icode = 'n';
break;
case SCANCODE_O:
icode = 'o';
keychar = icode = 'o';
break;
case SCANCODE_P:
icode = 'p';
keychar = icode = 'p';
break;
case SCANCODE_Q:
icode = 'q';
keychar = icode = 'q';
break;
case SCANCODE_R:
icode = 'r';
keychar = icode = 'r';
break;
case SCANCODE_S:
icode = 's';
keychar = icode = 's';
break;
case SCANCODE_T:
icode = 't';
keychar = icode = 't';
break;
case SCANCODE_U:
icode = 'u';
keychar = icode = 'u';
break;
case SCANCODE_V:
icode = 'v';
keychar = icode = 'v';
break;
case SCANCODE_W:
icode = 'w';
keychar = icode = 'w';
break;
case SCANCODE_X:
icode = 'x';
keychar = icode = 'x';
break;
case SCANCODE_Y:
icode = 'y';
keychar = icode = 'y';
break;
case SCANCODE_Z:
icode = 'z';
keychar = icode = 'z';
break;
case SCANCODE_SPACE:
icode = ' ';
keychar = icode = ' ';
break;
case SCANCODE_MINUS:
if(KeyModifiers & ModifierShift) {
keychar = icode = '-';
if (KeyModifiers & ModifierShift) {
icode = '_';
} else {
icode = '-';
}
break;
case SCANCODE_EQUAL:
if(KeyModifiers & ModifierShift) {
keychar = icode = '=';
if (KeyModifiers & ModifierShift) {
icode = '+';
} else {
icode = '=';
}
break;
case SCANCODE_ESCAPE:
icode = '\e';
keychar = icode = '\e';
break;
case SCANCODE_ENTER:
icode = '\r';
keychar = icode = '\r';
break;
case SCANCODE_BACKSPACE:
icode = '\b';
keychar = icode = '\b';
break;
case SCANCODE_TAB:
icode = '\t';
keychar = icode = '\t';
break;
case SCANCODE_COMMA:
keychar = icode = ',';
break;
case SCANCODE_PERIOD:
keychar = icode = '.';
break;
case SCANCODE_SLASH:
keychar = icode = '/';
break;
case SCANCODE_CURSORBLOCKUP:
icode = KeyCodeUp;
break;
@ -944,21 +951,21 @@ local void KeyboardEvent(int scancode, int press) {
case SCANCODE_LEFTSHIFT:
case SCANCODE_RIGHTSHIFT:
KeyModifiers &= ~ModifierShift;
icode=0;
icode = 0;
break;
case SCANCODE_LEFTCONTROL:
case SCANCODE_RIGHTCONTROL:
KeyModifiers &= ~ModifierControl;
icode=0;
icode = 0;
break;
case SCANCODE_LEFTALT:
case SCANCODE_RIGHTALT:
KeyModifiers &= ~ModifierAlt;
icode=0;
icode = 0;
break;
// Super ???
// Super ???
}
SVGALibCallbacks->KeyReleased(icode);
SVGALibCallbacks->KeyReleased(icode, keychar);
}
}