hello world

This commit is contained in:
Timothee 'TTimo' Besset
2011-11-22 15:28:15 -06:00
commit fb1609f554
2155 changed files with 1017022 additions and 0 deletions

128
neo/ui/BindWindow.cpp Normal file
View File

@@ -0,0 +1,128 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "DeviceContext.h"
#include "Window.h"
#include "UserInterfaceLocal.h"
#include "BindWindow.h"
void idBindWindow::CommonInit() {
bindName = "";
waitingOnKey = false;
}
idBindWindow::idBindWindow(idDeviceContext *d, idUserInterfaceLocal *g) : idWindow(d, g) {
dc = d;
gui = g;
CommonInit();
}
idBindWindow::idBindWindow(idUserInterfaceLocal *g) : idWindow(g) {
gui = g;
CommonInit();
}
idBindWindow::~idBindWindow() {
}
const char *idBindWindow::HandleEvent(const sysEvent_t *event, bool *updateVisuals) {
static char ret[ 256 ];
if (!(event->evType == SE_KEY && event->evValue2)) {
return "";
}
int key = event->evValue;
if (waitingOnKey) {
waitingOnKey = false;
if (key == K_ESCAPE) {
idStr::snPrintf( ret, sizeof( ret ), "clearbind \"%s\"", bindName.GetName());
} else {
idStr::snPrintf( ret, sizeof( ret ), "bind %i \"%s\"", key, bindName.GetName());
}
return ret;
} else {
if (key == K_MOUSE1) {
waitingOnKey = true;
gui->SetBindHandler(this);
return "";
}
}
return "";
}
idWinVar *idBindWindow::GetWinVarByName(const char *_name, bool fixup, drawWin_t** owner) {
if (idStr::Icmp(_name, "bind") == 0) {
return &bindName;
}
return idWindow::GetWinVarByName(_name, fixup,owner);
}
void idBindWindow::PostParse() {
idWindow::PostParse();
bindName.SetGuiInfo( gui->GetStateDict(), bindName );
bindName.Update();
//bindName = state.GetString("bind");
flags |= (WIN_HOLDCAPTURE | WIN_CANFOCUS);
}
void idBindWindow::Draw(int time, float x, float y) {
idVec4 color = foreColor;
idStr str;
if ( waitingOnKey ) {
str = common->GetLanguageDict()->GetString( "#str_07000" );
} else if ( bindName.Length() ) {
str = bindName.c_str();
} else {
str = common->GetLanguageDict()->GetString( "#str_07001" );
}
if ( waitingOnKey || ( hover && !noEvents && Contains(gui->CursorX(), gui->CursorY()) ) ) {
color = hoverColor;
} else {
hover = false;
}
dc->DrawText(str, textScale, textAlign, color, textRect, false, -1);
}
void idBindWindow::Activate( bool activate, idStr &act ) {
idWindow::Activate( activate, act );
bindName.Update();
}

54
neo/ui/BindWindow.h Normal file
View File

@@ -0,0 +1,54 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __BINDWINDOW_H
#define __BINDWINDOW_H
class idUserInterfaceLocal;
class idBindWindow : public idWindow {
public:
idBindWindow(idUserInterfaceLocal *gui);
idBindWindow(idDeviceContext *d, idUserInterfaceLocal *gui);
virtual ~idBindWindow();
virtual const char *HandleEvent(const sysEvent_t *event, bool *updateVisuals);
virtual void PostParse();
virtual void Draw(int time, float x, float y);
virtual size_t Allocated(){return idWindow::Allocated();};
//
//
virtual idWinVar *GetWinVarByName(const char *_name, bool winLookup = false, drawWin_t** owner = NULL );
//
virtual void Activate( bool activate, idStr &act );
private:
void CommonInit();
idWinStr bindName;
bool waitingOnKey;
};
#endif // __BINDWINDOW_H

402
neo/ui/ChoiceWindow.cpp Normal file
View File

@@ -0,0 +1,402 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "DeviceContext.h"
#include "Window.h"
#include "UserInterfaceLocal.h"
#include "ChoiceWindow.h"
/*
============
idChoiceWindow::InitVars
============
*/
void idChoiceWindow::InitVars( ) {
if ( cvarStr.Length() ) {
cvar = cvarSystem->Find( cvarStr );
if ( !cvar ) {
common->Warning( "idChoiceWindow::InitVars: gui '%s' window '%s' references undefined cvar '%s'", gui->GetSourceFile(), name.c_str(), cvarStr.c_str() );
return;
}
updateStr.Append( &cvarStr );
}
if ( guiStr.Length() ) {
updateStr.Append( &guiStr );
}
updateStr.SetGuiInfo( gui->GetStateDict() );
updateStr.Update();
}
/*
============
idChoiceWindow::CommonInit
============
*/
void idChoiceWindow::CommonInit() {
currentChoice = 0;
choiceType = 0;
cvar = NULL;
liveUpdate = true;
choices.Clear();
}
idChoiceWindow::idChoiceWindow(idDeviceContext *d, idUserInterfaceLocal *g) : idWindow(d, g) {
dc = d;
gui = g;
CommonInit();
}
idChoiceWindow::idChoiceWindow(idUserInterfaceLocal *g) : idWindow(g) {
gui = g;
CommonInit();
}
idChoiceWindow::~idChoiceWindow() {
}
void idChoiceWindow::RunNamedEvent( const char* eventName ) {
idStr event, group;
if ( !idStr::Cmpn( eventName, "cvar read ", 10 ) ) {
event = eventName;
group = event.Mid( 10, event.Length() - 10 );
if ( !group.Cmp( updateGroup ) ) {
UpdateVars( true, true );
}
} else if ( !idStr::Cmpn( eventName, "cvar write ", 11 ) ) {
event = eventName;
group = event.Mid( 11, event.Length() - 11 );
if ( !group.Cmp( updateGroup ) ) {
UpdateVars( false, true );
}
}
}
void idChoiceWindow::UpdateVars( bool read, bool force ) {
if ( force || liveUpdate ) {
if ( cvar && cvarStr.NeedsUpdate() ) {
if ( read ) {
cvarStr.Set( cvar->GetString() );
} else {
cvar->SetString( cvarStr.c_str() );
}
}
if ( !read && guiStr.NeedsUpdate() ) {
guiStr.Set( va( "%i", currentChoice ) );
}
}
}
const char *idChoiceWindow::HandleEvent(const sysEvent_t *event, bool *updateVisuals) {
int key;
bool runAction = false;
bool runAction2 = false;
if ( event->evType == SE_KEY ) {
key = event->evValue;
if ( key == K_RIGHTARROW || key == K_KP_RIGHTARROW || key == K_MOUSE1) {
// never affects the state, but we want to execute script handlers anyway
if ( !event->evValue2 ) {
RunScript( ON_ACTIONRELEASE );
return cmd;
}
currentChoice++;
if (currentChoice >= choices.Num()) {
currentChoice = 0;
}
runAction = true;
}
if ( key == K_LEFTARROW || key == K_KP_LEFTARROW || key == K_MOUSE2) {
// never affects the state, but we want to execute script handlers anyway
if ( !event->evValue2 ) {
RunScript( ON_ACTIONRELEASE );
return cmd;
}
currentChoice--;
if (currentChoice < 0) {
currentChoice = choices.Num() - 1;
}
runAction = true;
}
if ( !event->evValue2 ) {
// is a key release with no action catch
return "";
}
} else if ( event->evType == SE_CHAR ) {
key = event->evValue;
int potentialChoice = -1;
for ( int i = 0; i < choices.Num(); i++ ) {
if ( toupper(key) == toupper(choices[i][0]) ) {
if ( i < currentChoice && potentialChoice < 0 ) {
potentialChoice = i;
} else if ( i > currentChoice ) {
potentialChoice = -1;
currentChoice = i;
break;
}
}
}
if ( potentialChoice >= 0 ) {
currentChoice = potentialChoice;
}
runAction = true;
runAction2 = true;
} else {
return "";
}
if ( runAction ) {
RunScript( ON_ACTION );
}
if ( choiceType == 0 ) {
cvarStr.Set( va( "%i", currentChoice ) );
} else if ( values.Num() ) {
cvarStr.Set( values[ currentChoice ] );
} else {
cvarStr.Set( choices[ currentChoice ] );
}
UpdateVars( false );
if ( runAction2 ) {
RunScript( ON_ACTIONRELEASE );
}
return cmd;
}
void idChoiceWindow::ValidateChoice() {
if ( currentChoice < 0 || currentChoice >= choices.Num() ) {
currentChoice = 0;
}
if ( choices.Num() == 0 ) {
choices.Append( "No Choices Defined" );
}
}
void idChoiceWindow::UpdateChoice() {
if ( !updateStr.Num() ) {
return;
}
UpdateVars( true );
updateStr.Update();
if ( choiceType == 0 ) {
// ChoiceType 0 stores current as an integer in either cvar or gui
// If both cvar and gui are defined then cvar wins, but they are both updated
if ( updateStr[ 0 ]->NeedsUpdate() ) {
currentChoice = atoi( updateStr[ 0 ]->c_str() );
}
ValidateChoice();
} else {
// ChoiceType 1 stores current as a cvar string
int c = ( values.Num() ) ? values.Num() : choices.Num();
int i;
for ( i = 0; i < c; i++ ) {
if ( idStr::Icmp( cvarStr.c_str(), ( values.Num() ) ? values[i] : choices[i] ) == 0 ) {
break;
}
}
if (i == c) {
i = 0;
}
currentChoice = i;
ValidateChoice();
}
}
bool idChoiceWindow::ParseInternalVar(const char *_name, idParser *src) {
if (idStr::Icmp(_name, "choicetype") == 0) {
choiceType = src->ParseInt();
return true;
}
if (idStr::Icmp(_name, "currentchoice") == 0) {
currentChoice = src->ParseInt();
return true;
}
return idWindow::ParseInternalVar(_name, src);
}
idWinVar *idChoiceWindow::GetWinVarByName(const char *_name, bool fixup, drawWin_t** owner) {
if ( idStr::Icmp( _name, "choices" ) == 0 ) {
return &choicesStr;
}
if ( idStr::Icmp( _name, "values" ) == 0 ) {
return &choiceVals;
}
if ( idStr::Icmp( _name, "cvar" ) == 0 ) {
return &cvarStr;
}
if ( idStr::Icmp( _name, "gui" ) == 0 ) {
return &guiStr;
}
if ( idStr::Icmp( _name, "liveUpdate" ) == 0 ) {
return &liveUpdate;
}
if ( idStr::Icmp( _name, "updateGroup" ) == 0 ) {
return &updateGroup;
}
return idWindow::GetWinVarByName(_name, fixup, owner);
}
// update the lists whenever the WinVar have changed
void idChoiceWindow::UpdateChoicesAndVals( void ) {
idToken token;
idStr str2, str3;
idLexer src;
if ( latchedChoices.Icmp( choicesStr ) ) {
choices.Clear();
src.FreeSource();
src.SetFlags( LEXFL_NOFATALERRORS | LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT );
src.LoadMemory( choicesStr, choicesStr.Length(), "<ChoiceList>" );
if ( src.IsLoaded() ) {
while( src.ReadToken( &token ) ) {
if ( token == ";" ) {
if ( str2.Length() ) {
str2.StripTrailingWhitespace();
str2 = common->GetLanguageDict()->GetString( str2 );
choices.Append(str2);
str2 = "";
}
continue;
}
str2 += token;
str2 += " ";
}
if ( str2.Length() ) {
str2.StripTrailingWhitespace();
choices.Append( str2 );
}
}
latchedChoices = choicesStr.c_str();
}
if ( choiceVals.Length() && latchedVals.Icmp( choiceVals ) ) {
values.Clear();
src.FreeSource();
src.SetFlags( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT );
src.LoadMemory( choiceVals, choiceVals.Length(), "<ChoiceVals>" );
str2 = "";
bool negNum = false;
if ( src.IsLoaded() ) {
while( src.ReadToken( &token ) ) {
if (token == "-") {
negNum = true;
continue;
}
if (token == ";") {
if (str2.Length()) {
str2.StripTrailingWhitespace();
values.Append( str2 );
str2 = "";
}
continue;
}
if ( negNum ) {
str2 += "-";
negNum = false;
}
str2 += token;
str2 += " ";
}
if ( str2.Length() ) {
str2.StripTrailingWhitespace();
values.Append( str2 );
}
}
if ( choices.Num() != values.Num() ) {
common->Warning( "idChoiceWindow:: gui '%s' window '%s' has value count unequal to choices count", gui->GetSourceFile(), name.c_str());
}
latchedVals = choiceVals.c_str();
}
}
void idChoiceWindow::PostParse() {
idWindow::PostParse();
UpdateChoicesAndVals();
InitVars();
UpdateChoice();
UpdateVars(false);
flags |= WIN_CANFOCUS;
}
void idChoiceWindow::Draw(int time, float x, float y) {
idVec4 color = foreColor;
UpdateChoicesAndVals();
UpdateChoice();
// FIXME: It'd be really cool if textAlign worked, but a lot of the guis have it set wrong because it used to not work
textAlign = 0;
if ( textShadow ) {
idStr shadowText = choices[currentChoice];
idRectangle shadowRect = textRect;
shadowText.RemoveColors();
shadowRect.x += textShadow;
shadowRect.y += textShadow;
dc->DrawText( shadowText, textScale, textAlign, colorBlack, shadowRect, false, -1 );
}
if ( hover && !noEvents && Contains(gui->CursorX(), gui->CursorY()) ) {
color = hoverColor;
} else {
hover = false;
}
if ( flags & WIN_FOCUS ) {
color = hoverColor;
}
dc->DrawText( choices[currentChoice], textScale, textAlign, color, textRect, false, -1 );
}
void idChoiceWindow::Activate( bool activate, idStr &act ) {
idWindow::Activate( activate, act );
if ( activate ) {
// sets the gui state based on the current choice the window contains
UpdateChoice();
}
}

82
neo/ui/ChoiceWindow.h Normal file
View File

@@ -0,0 +1,82 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __CHOICEWINDOW_H
#define __CHOICEWINDOW_H
#include "Window.h"
class idUserInterfaceLocal;
class idChoiceWindow : public idWindow {
public:
idChoiceWindow(idUserInterfaceLocal *gui);
idChoiceWindow(idDeviceContext *d, idUserInterfaceLocal *gui);
virtual ~idChoiceWindow();
virtual const char *HandleEvent(const sysEvent_t *event, bool *updateVisuals);
virtual void PostParse();
virtual void Draw(int time, float x, float y);
virtual void Activate( bool activate, idStr &act );
virtual size_t Allocated(){return idWindow::Allocated();};
virtual idWinVar *GetWinVarByName(const char *_name, bool winLookup = false, drawWin_t** owner = NULL);
void RunNamedEvent( const char* eventName );
private:
virtual bool ParseInternalVar(const char *name, idParser *src);
void CommonInit();
void UpdateChoice();
void ValidateChoice();
void InitVars();
// true: read the updated cvar from cvar system, gui from dict
// false: write to the cvar system, to the gui dict
// force == true overrides liveUpdate 0
void UpdateVars( bool read, bool force = false );
void UpdateChoicesAndVals( void );
int currentChoice;
int choiceType;
idStr latchedChoices;
idWinStr choicesStr;
idStr latchedVals;
idWinStr choiceVals;
idStrList choices;
idStrList values;
idWinStr guiStr;
idWinStr cvarStr;
idCVar * cvar;
idMultiWinVar updateStr;
idWinBool liveUpdate;
idWinStr updateGroup;
};
#endif // __CHOICEWINDOW_H

1098
neo/ui/DeviceContext.cpp Normal file

File diff suppressed because it is too large Load Diff

168
neo/ui/DeviceContext.h Normal file
View File

@@ -0,0 +1,168 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __DEVICECONTEXT_H__
#define __DEVICECONTEXT_H__
// device context support for gui stuff
//
#include "Rectangle.h"
const int VIRTUAL_WIDTH = 640;
const int VIRTUAL_HEIGHT = 480;
const int BLINK_DIVISOR = 200;
class idDeviceContext {
public:
idDeviceContext();
~idDeviceContext() { }
void Init();
void Shutdown();
bool Initialized() { return initialized; }
void EnableLocalization();
void GetTransformInfo(idVec3& origin, idMat3& mat );
void SetTransformInfo(const idVec3 &origin, const idMat3 &mat);
void DrawMaterial(float x, float y, float w, float h, const idMaterial *mat, const idVec4 &color, float scalex = 1.0, float scaley = 1.0);
void DrawRect(float x, float y, float width, float height, float size, const idVec4 &color);
void DrawFilledRect(float x, float y, float width, float height, const idVec4 &color);
int DrawText(const char *text, float textScale, int textAlign, idVec4 color, idRectangle rectDraw, bool wrap, int cursor = -1, bool calcOnly = false, idList<int> *breaks = NULL, int limit = 0 );
void DrawMaterialRect( float x, float y, float w, float h, float size, const idMaterial *mat, const idVec4 &color);
void DrawStretchPic(float x, float y, float w, float h, float s0, float t0, float s1, float t1, const idMaterial *mat);
void DrawMaterialRotated(float x, float y, float w, float h, const idMaterial *mat, const idVec4 &color, float scalex = 1.0, float scaley = 1.0, float angle = 0.0f);
void DrawStretchPicRotated(float x, float y, float w, float h, float s0, float t0, float s1, float t1, const idMaterial *mat, float angle = 0.0f);
int CharWidth( const char c, float scale );
int TextWidth(const char *text, float scale, int limit);
int TextHeight(const char *text, float scale, int limit);
int MaxCharHeight(float scale);
int MaxCharWidth(float scale);
int FindFont( const char *name );
void SetupFonts();
idRegion *GetTextRegion(const char *text, float textScale, idRectangle rectDraw, float xStart, float yStart);
void SetSize(float width, float height);
const idMaterial *GetScrollBarImage(int index);
void DrawCursor(float *x, float *y, float size);
void SetCursor(int n);
void AdjustCoords(float *x, float *y, float *w, float *h);
bool ClippedCoords(float *x, float *y, float *w, float *h);
bool ClippedCoords(float *x, float *y, float *w, float *h, float *s1, float *t1, float *s2, float *t2);
void PushClipRect(float x, float y, float w, float h);
void PushClipRect(idRectangle r);
void PopClipRect();
void EnableClipping(bool b) { enableClipping = b; };
void SetFont( int num );
void SetOverStrike(bool b) { overStrikeMode = b; }
bool GetOverStrike() { return overStrikeMode; }
void DrawEditCursor(float x, float y, float scale);
enum {
CURSOR_ARROW,
CURSOR_HAND,
CURSOR_COUNT
};
enum {
ALIGN_LEFT,
ALIGN_CENTER,
ALIGN_RIGHT
};
enum {
SCROLLBAR_HBACK,
SCROLLBAR_VBACK,
SCROLLBAR_THUMB,
SCROLLBAR_RIGHT,
SCROLLBAR_LEFT,
SCROLLBAR_UP,
SCROLLBAR_DOWN,
SCROLLBAR_COUNT
};
static idVec4 colorPurple;
static idVec4 colorOrange;
static idVec4 colorYellow;
static idVec4 colorGreen;
static idVec4 colorBlue;
static idVec4 colorRed;
static idVec4 colorWhite;
static idVec4 colorBlack;
static idVec4 colorNone;
private:
int DrawText(float x, float y, float scale, idVec4 color, const char *text, float adjust, int limit, int style, int cursor = -1);
void PaintChar(float x,float y,float width,float height,float scale,float s,float t,float s2,float t2,const idMaterial *hShader);
void SetFontByScale( float scale );
void Clear( void );
const idMaterial *cursorImages[CURSOR_COUNT];
const idMaterial *scrollBarImages[SCROLLBAR_COUNT];
const idMaterial *whiteImage;
fontInfoEx_t *activeFont;
fontInfo_t *useFont;
idStr fontName;
float xScale;
float yScale;
float vidHeight;
float vidWidth;
int cursor;
idList<idRectangle> clipRects;
static idList<fontInfoEx_t> fonts;
idStr fontLang;
bool enableClipping;
bool overStrikeMode;
idMat3 mat;
idVec3 origin;
bool initialized;
bool mbcs;
};
#endif /* !__DEVICECONTEXT_H__ */

648
neo/ui/EditWindow.cpp Normal file
View File

@@ -0,0 +1,648 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "DeviceContext.h"
#include "Window.h"
#include "UserInterfaceLocal.h"
#include "SliderWindow.h"
#include "EditWindow.h"
bool idEditWindow::ParseInternalVar( const char *_name, idParser *src ) {
if ( idStr::Icmp( _name, "maxchars" ) == 0) {
maxChars = src->ParseInt();
return true;
}
if ( idStr::Icmp( _name, "numeric" ) == 0) {
numeric = src->ParseBool();
return true;
}
if ( idStr::Icmp( _name, "wrap" ) == 0) {
wrap = src->ParseBool();
return true;
}
if ( idStr::Icmp( _name, "readonly" ) == 0) {
readonly = src->ParseBool();
return true;
}
if ( idStr::Icmp( _name, "forceScroll" ) == 0) {
forceScroll = src->ParseBool();
return true;
}
if ( idStr::Icmp( _name, "source" ) == 0) {
ParseString( src, sourceFile );
return true;
}
if ( idStr::Icmp( _name, "password" ) == 0 ) {
password = src->ParseBool();
return true;
}
if ( idStr::Icmp( _name, "cvarMax" ) == 0) {
cvarMax = src->ParseInt();
return true;
}
return idWindow::ParseInternalVar( _name, src );
}
idWinVar *idEditWindow::GetWinVarByName( const char *_name, bool fixup, drawWin_t** owner ) {
if ( idStr::Icmp( _name, "cvar" ) == 0 ) {
return &cvarStr;
}
if ( idStr::Icmp( _name, "password" ) == 0 ) {
return &password;
}
if ( idStr::Icmp( _name, "liveUpdate" ) == 0 ) {
return &liveUpdate;
}
if ( idStr::Icmp( _name, "cvarGroup" ) == 0 ) {
return &cvarGroup;
}
return idWindow::GetWinVarByName( _name, fixup, owner );
}
void idEditWindow::CommonInit() {
maxChars = 128;
numeric = false;
paintOffset = 0;
cursorPos = 0;
cursorLine = 0;
cvarMax = 0;
wrap = false;
sourceFile = "";
scroller = NULL;
sizeBias = 0;
lastTextLength = 0;
forceScroll = false;
password = false;
cvar = NULL;
liveUpdate = true;
readonly = false;
scroller = new idSliderWindow(dc, gui);
}
idEditWindow::idEditWindow( idDeviceContext *d, idUserInterfaceLocal *g ) : idWindow(d, g) {
dc = d;
gui = g;
CommonInit();
}
idEditWindow::idEditWindow( idUserInterfaceLocal *g ) : idWindow(g) {
gui = g;
CommonInit();
}
idEditWindow::~idEditWindow() {
}
void idEditWindow::GainFocus() {
cursorPos = text.Length();
EnsureCursorVisible();
}
void idEditWindow::Draw( int time, float x, float y ) {
idVec4 color = foreColor;
UpdateCvar( true );
int len = text.Length();
if ( len != lastTextLength ) {
scroller->SetValue( 0.0f );
EnsureCursorVisible();
lastTextLength = len;
}
float scale = textScale;
idStr pass;
const char* buffer;
if ( password ) {
const char* temp = text;
for ( ; *temp; temp++ ) {
pass += "*";
}
buffer = pass;
} else {
buffer = text;
}
if ( cursorPos > len ) {
cursorPos = len;
}
idRectangle rect = textRect;
rect.x -= paintOffset;
rect.w += paintOffset;
if ( wrap && scroller->GetHigh() > 0.0f ) {
float lineHeight = GetMaxCharHeight( ) + 5;
rect.y -= scroller->GetValue() * lineHeight;
rect.w -= sizeBias;
rect.h = ( breaks.Num() + 1 ) * lineHeight;
}
if ( hover && !noEvents && Contains(gui->CursorX(), gui->CursorY()) ) {
color = hoverColor;
} else {
hover = false;
}
if ( flags & WIN_FOCUS ) {
color = hoverColor;
}
dc->DrawText( buffer, scale, 0, color, rect, wrap, (flags & WIN_FOCUS) ? cursorPos : -1);
}
/*
=============
idEditWindow::HandleEvent
=============
*/
const char *idEditWindow::HandleEvent(const sysEvent_t *event, bool *updateVisuals) {
static char buffer[ MAX_EDITFIELD ];
const char *ret = "";
if ( wrap ) {
// need to call this to allow proper focus and capturing on embedded children
ret = idWindow::HandleEvent( event, updateVisuals );
if ( ret && *ret ) {
return ret;
}
}
if ( ( event->evType != SE_CHAR && event->evType != SE_KEY ) ) {
return ret;
}
idStr::Copynz( buffer, text.c_str(), sizeof( buffer ) );
int key = event->evValue;
int len = text.Length();
if ( event->evType == SE_CHAR ) {
if ( event->evValue == Sys_GetConsoleKey( false ) || event->evValue == Sys_GetConsoleKey( true ) ) {
return "";
}
if ( updateVisuals ) {
*updateVisuals = true;
}
if ( maxChars && len > maxChars ) {
len = maxChars;
}
if ( ( key == K_ENTER || key == K_KP_ENTER ) && event->evValue2 ) {
RunScript( ON_ACTION );
RunScript( ON_ENTER );
return cmd;
}
if ( key == K_ESCAPE ) {
RunScript( ON_ESC );
return cmd;
}
if ( readonly ) {
return "";
}
if ( key == 'h' - 'a' + 1 || key == K_BACKSPACE ) { // ctrl-h is backspace
if ( cursorPos > 0 ) {
if ( cursorPos >= len ) {
buffer[len - 1] = 0;
cursorPos = len - 1;
} else {
memmove( &buffer[ cursorPos - 1 ], &buffer[ cursorPos ], len + 1 - cursorPos);
cursorPos--;
}
text = buffer;
UpdateCvar( false );
RunScript( ON_ACTION );
}
return "";
}
//
// ignore any non printable chars (except enter when wrap is enabled)
//
if ( wrap && (key == K_ENTER || key == K_KP_ENTER) ) {
} else if ( !idStr::CharIsPrintable( key ) ) {
return "";
}
if ( numeric ) {
if ( ( key < '0' || key > '9' ) && key != '.' ) {
return "";
}
}
if ( dc->GetOverStrike() ) {
if ( maxChars && cursorPos >= maxChars ) {
return "";
}
} else {
if ( ( len == MAX_EDITFIELD - 1 ) || ( maxChars && len >= maxChars ) ) {
return "";
}
memmove( &buffer[ cursorPos + 1 ], &buffer[ cursorPos ], len + 1 - cursorPos );
}
buffer[ cursorPos ] = key;
text = buffer;
UpdateCvar( false );
RunScript( ON_ACTION );
if ( cursorPos < len + 1 ) {
cursorPos++;
}
EnsureCursorVisible();
} else if ( event->evType == SE_KEY && event->evValue2 ) {
if ( updateVisuals ) {
*updateVisuals = true;
}
if ( key == K_DEL ) {
if ( readonly ) {
return ret;
}
if ( cursorPos < len ) {
memmove( &buffer[cursorPos], &buffer[cursorPos + 1], len - cursorPos);
text = buffer;
UpdateCvar( false );
RunScript( ON_ACTION );
}
return ret;
}
if ( key == K_RIGHTARROW ) {
if ( cursorPos < len ) {
if ( idKeyInput::IsDown( K_CTRL ) ) {
// skip to next word
while( ( cursorPos < len ) && ( buffer[ cursorPos ] != ' ' ) ) {
cursorPos++;
}
while( ( cursorPos < len ) && ( buffer[ cursorPos ] == ' ' ) ) {
cursorPos++;
}
} else {
if ( cursorPos < len ) {
cursorPos++;
}
}
}
EnsureCursorVisible();
return ret;
}
if ( key == K_LEFTARROW ) {
if ( idKeyInput::IsDown( K_CTRL ) ) {
// skip to previous word
while( ( cursorPos > 0 ) && ( buffer[ cursorPos - 1 ] == ' ' ) ) {
cursorPos--;
}
while( ( cursorPos > 0 ) && ( buffer[ cursorPos - 1 ] != ' ' ) ) {
cursorPos--;
}
} else {
if ( cursorPos > 0 ) {
cursorPos--;
}
}
EnsureCursorVisible();
return ret;
}
if ( key == K_HOME ) {
if ( idKeyInput::IsDown( K_CTRL ) || cursorLine <= 0 || ( cursorLine >= breaks.Num() ) ) {
cursorPos = 0;
} else {
cursorPos = breaks[cursorLine];
}
EnsureCursorVisible();
return ret;
}
if ( key == K_END ) {
if ( idKeyInput::IsDown( K_CTRL ) || (cursorLine < -1) || ( cursorLine >= breaks.Num() - 1 ) ) {
cursorPos = len;
} else {
cursorPos = breaks[cursorLine + 1] - 1;
}
EnsureCursorVisible();
return ret;
}
if ( key == K_INS ) {
if ( !readonly ) {
dc->SetOverStrike( !dc->GetOverStrike() );
}
return ret;
}
if ( key == K_DOWNARROW ) {
if ( idKeyInput::IsDown( K_CTRL ) ) {
scroller->SetValue( scroller->GetValue() + 1.0f );
} else {
if ( cursorLine < breaks.Num() - 1 ) {
int offset = cursorPos - breaks[cursorLine];
cursorPos = breaks[cursorLine + 1] + offset;
EnsureCursorVisible();
}
}
}
if (key == K_UPARROW ) {
if ( idKeyInput::IsDown( K_CTRL ) ) {
scroller->SetValue( scroller->GetValue() - 1.0f );
} else {
if ( cursorLine > 0 ) {
int offset = cursorPos - breaks[cursorLine];
cursorPos = breaks[cursorLine - 1] + offset;
EnsureCursorVisible();
}
}
}
if ( key == K_ENTER || key == K_KP_ENTER ) {
RunScript( ON_ACTION );
RunScript( ON_ENTER );
return cmd;
}
if ( key == K_ESCAPE ) {
RunScript( ON_ESC );
return cmd;
}
} else if ( event->evType == SE_KEY && !event->evValue2 ) {
if ( key == K_ENTER || key == K_KP_ENTER ) {
RunScript( ON_ENTERRELEASE );
return cmd;
} else {
RunScript( ON_ACTIONRELEASE );
}
}
return ret;
}
void idEditWindow::PostParse() {
idWindow::PostParse();
if ( maxChars == 0 ) {
maxChars = 10;
}
if ( sourceFile.Length() ) {
void *buffer;
fileSystem->ReadFile( sourceFile, &buffer );
text = (char *) buffer;
fileSystem->FreeFile( buffer );
}
InitCvar();
InitScroller(false);
EnsureCursorVisible();
flags |= WIN_CANFOCUS;
}
/*
================
idEditWindow::InitScroller
This is the same as in idListWindow
================
*/
void idEditWindow::InitScroller( bool horizontal )
{
const char *thumbImage = "guis/assets/scrollbar_thumb.tga";
const char *barImage = "guis/assets/scrollbarv.tga";
const char *scrollerName = "_scrollerWinV";
if (horizontal) {
barImage = "guis/assets/scrollbarh.tga";
scrollerName = "_scrollerWinH";
}
const idMaterial *mat = declManager->FindMaterial( barImage );
mat->SetSort( SS_GUI );
sizeBias = mat->GetImageWidth();
idRectangle scrollRect;
if (horizontal) {
sizeBias = mat->GetImageHeight();
scrollRect.x = 0;
scrollRect.y = (clientRect.h - sizeBias);
scrollRect.w = clientRect.w;
scrollRect.h = sizeBias;
} else {
scrollRect.x = (clientRect.w - sizeBias);
scrollRect.y = 0;
scrollRect.w = sizeBias;
scrollRect.h = clientRect.h;
}
scroller->InitWithDefaults(scrollerName, scrollRect, foreColor, matColor, mat->GetName(), thumbImage, !horizontal, true);
InsertChild(scroller, NULL);
scroller->SetBuddy(this);
}
void idEditWindow::HandleBuddyUpdate( idWindow *buddy ) {
}
void idEditWindow::EnsureCursorVisible()
{
if ( readonly ) {
cursorPos = -1;
} else if ( maxChars == 1 ) {
cursorPos = 0;
}
if ( !dc ) {
return;
}
SetFont();
if ( !wrap ) {
int cursorX = 0;
if ( password ) {
cursorX = cursorPos * dc->CharWidth( '*', textScale );
} else {
int i = 0;
while ( i < text.Length() && i < cursorPos ) {
if ( idStr::IsColor( &text[i] ) ) {
i += 2;
} else {
cursorX += dc->CharWidth( text[i], textScale );
i++;
}
}
}
int maxWidth = GetMaxCharWidth( );
int left = cursorX - maxWidth;
int right = ( cursorX - textRect.w ) + maxWidth;
if ( paintOffset > left ) {
// When we go past the left side, we want the text to jump 6 characters
paintOffset = left - maxWidth * 6;
}
if ( paintOffset < right) {
paintOffset = right;
}
if ( paintOffset < 0 ) {
paintOffset = 0;
}
scroller->SetRange(0.0f, 0.0f, 1.0f);
} else {
// Word wrap
breaks.Clear();
idRectangle rect = textRect;
rect.w -= sizeBias;
dc->DrawText(text, textScale, textAlign, colorWhite, rect, true, (flags & WIN_FOCUS) ? cursorPos : -1, true, &breaks );
int fit = textRect.h / (GetMaxCharHeight() + 5);
if ( fit < breaks.Num() + 1 ) {
scroller->SetRange(0, breaks.Num() + 1 - fit, 1);
} else {
// The text fits completely in the box
scroller->SetRange(0.0f, 0.0f, 1.0f);
}
if ( forceScroll ) {
scroller->SetValue( breaks.Num() - fit );
} else if ( readonly ) {
} else {
cursorLine = 0;
for ( int i = 1; i < breaks.Num(); i++ ) {
if ( cursorPos >= breaks[i] ) {
cursorLine = i;
} else {
break;
}
}
int topLine = idMath::FtoiFast( scroller->GetValue() );
if ( cursorLine < topLine ) {
scroller->SetValue( cursorLine );
} else if ( cursorLine >= topLine + fit) {
scroller->SetValue( ( cursorLine - fit ) + 1 );
}
}
}
}
void idEditWindow::Activate(bool activate, idStr &act) {
idWindow::Activate(activate, act);
if ( activate ) {
UpdateCvar( true, true );
EnsureCursorVisible();
}
}
/*
============
idEditWindow::InitCvar
============
*/
void idEditWindow::InitCvar( ) {
if ( cvarStr[0] == '\0' ) {
if ( text.GetName() == NULL ) {
common->Warning( "idEditWindow::InitCvar: gui '%s' window '%s' has an empty cvar string", gui->GetSourceFile(), name.c_str() );
}
cvar = NULL;
return;
}
cvar = cvarSystem->Find( cvarStr );
if ( !cvar ) {
common->Warning( "idEditWindow::InitCvar: gui '%s' window '%s' references undefined cvar '%s'", gui->GetSourceFile(), name.c_str(), cvarStr.c_str() );
return;
}
}
/*
============
idEditWindow::UpdateCvar
============
*/
void idEditWindow::UpdateCvar( bool read, bool force ) {
if ( force || liveUpdate ) {
if ( cvar ) {
if ( read ) {
text = cvar->GetString();
} else {
cvar->SetString( text );
if ( cvarMax && ( cvar->GetInteger() > cvarMax ) ) {
cvar->SetInteger( cvarMax );
}
}
}
}
}
/*
============
idEditWindow::RunNamedEvent
============
*/
void idEditWindow::RunNamedEvent( const char* eventName ) {
idStr event, group;
if ( !idStr::Cmpn( eventName, "cvar read ", 10 ) ) {
event = eventName;
group = event.Mid( 10, event.Length() - 10 );
if ( !group.Cmp( cvarGroup ) ) {
UpdateCvar( true, true );
}
} else if ( !idStr::Cmpn( eventName, "cvar write ", 11 ) ) {
event = eventName;
group = event.Mid( 11, event.Length() - 11 );
if ( !group.Cmp( cvarGroup ) ) {
UpdateCvar( false, true );
}
}
}

96
neo/ui/EditWindow.h Normal file
View File

@@ -0,0 +1,96 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __EDITWINDOW_H__
#define __EDITWINDOW_H__
#include "Window.h"
const int MAX_EDITFIELD = 4096;
class idUserInterfaceLocal;
class idSliderWindow;
class idEditWindow : public idWindow {
public:
idEditWindow(idUserInterfaceLocal *gui);
idEditWindow(idDeviceContext *d, idUserInterfaceLocal *gui);
virtual ~idEditWindow();
virtual void Draw( int time, float x, float y );
virtual const char *HandleEvent( const sysEvent_t *event, bool *updateVisuals );
virtual void PostParse();
virtual void GainFocus();
virtual size_t Allocated(){return idWindow::Allocated();};
virtual idWinVar * GetWinVarByName(const char *_name, bool winLookup = false, drawWin_t** owner = NULL );
virtual void HandleBuddyUpdate(idWindow *buddy);
virtual void Activate(bool activate, idStr &act);
void RunNamedEvent( const char* eventName );
private:
virtual bool ParseInternalVar(const char *name, idParser *src);
void InitCvar();
// true: read the updated cvar from cvar system
// false: write to the cvar system
// force == true overrides liveUpdate 0
void UpdateCvar( bool read, bool force = false );
void CommonInit();
void EnsureCursorVisible();
void InitScroller( bool horizontal );
int maxChars;
int paintOffset;
int cursorPos;
int cursorLine;
int cvarMax;
bool wrap;
bool readonly;
bool numeric;
idStr sourceFile;
idSliderWindow * scroller;
idList<int> breaks;
float sizeBias;
int textIndex;
int lastTextLength;
bool forceScroll;
idWinBool password;
idWinStr cvarStr;
idCVar * cvar;
idWinBool liveUpdate;
idWinStr cvarGroup;
};
#endif /* !__EDITWINDOW_H__ */

105
neo/ui/FieldWindow.cpp Normal file
View File

@@ -0,0 +1,105 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "DeviceContext.h"
#include "Window.h"
#include "UserInterfaceLocal.h"
#include "FieldWindow.h"
void idFieldWindow::CommonInit() {
cursorPos = 0;
lastTextLength = 0;
lastCursorPos = 0;
paintOffset = 0;
showCursor = false;
}
idFieldWindow::idFieldWindow(idDeviceContext *d, idUserInterfaceLocal *g) : idWindow(d, g) {
dc = d;
gui = g;
CommonInit();
}
idFieldWindow::idFieldWindow(idUserInterfaceLocal *g) : idWindow(g) {
gui = g;
CommonInit();
}
idFieldWindow::~idFieldWindow() {
}
bool idFieldWindow::ParseInternalVar(const char *_name, idParser *src) {
if (idStr::Icmp(_name, "cursorvar") == 0) {
ParseString(src, cursorVar);
return true;
}
if (idStr::Icmp(_name, "showcursor") == 0) {
showCursor = src->ParseBool();
return true;
}
return idWindow::ParseInternalVar(_name, src);
}
void idFieldWindow::CalcPaintOffset(int len) {
lastCursorPos = cursorPos;
lastTextLength = len;
paintOffset = 0;
int tw = dc->TextWidth(text, textScale, -1);
if (tw < textRect.w) {
return;
}
while (tw > textRect.w && len > 0) {
tw = dc->TextWidth(text, textScale, --len);
paintOffset++;
}
}
void idFieldWindow::Draw(int time, float x, float y) {
float scale = textScale;
int len = text.Length();
cursorPos = gui->State().GetInt( cursorVar );
if (len != lastTextLength || cursorPos != lastCursorPos) {
CalcPaintOffset(len);
}
idRectangle rect = textRect;
if (paintOffset >= len) {
paintOffset = 0;
}
if (cursorPos > len) {
cursorPos = len;
}
dc->DrawText(&text[paintOffset], scale, 0, foreColor, rect, false, ((flags & WIN_FOCUS) || showCursor) ? cursorPos - paintOffset : -1);
}

54
neo/ui/FieldWindow.h Normal file
View File

@@ -0,0 +1,54 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __FIELDWINDOW_H
#define __FIELDWINDOW_H
#include "Window.h"
class idFieldWindow : public idWindow {
public:
idFieldWindow(idUserInterfaceLocal *gui);
idFieldWindow(idDeviceContext *d, idUserInterfaceLocal *gui);
virtual ~idFieldWindow();
virtual void Draw(int time, float x, float y);
private:
virtual bool ParseInternalVar(const char *name, idParser *src);
void CommonInit();
void CalcPaintOffset(int len);
int cursorPos;
int lastTextLength;
int lastCursorPos;
int paintOffset;
bool showCursor;
idStr cursorVar;
};
#endif // __FIELDWINDOW_H

View File

@@ -0,0 +1,895 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "../framework/Session_local.h"
#include "DeviceContext.h"
#include "Window.h"
#include "UserInterfaceLocal.h"
#include "GameBearShootWindow.h"
#define BEAR_GRAVITY 240
#define BEAR_SIZE 24.f
#define BEAR_SHRINK_TIME 2000.f
#define MAX_WINDFORCE 100.f
idCVar bearTurretAngle( "bearTurretAngle", "0", CVAR_FLOAT, "" );
idCVar bearTurretForce( "bearTurretForce", "200", CVAR_FLOAT, "" );
/*
*****************************************************************************
* BSEntity
****************************************************************************
*/
BSEntity::BSEntity(idGameBearShootWindow* _game) {
game = _game;
visible = true;
entColor = colorWhite;
materialName = "";
material = NULL;
width = height = 8;
rotation = 0.f;
rotationSpeed = 0.f;
fadeIn = false;
fadeOut = false;
position.Zero();
velocity.Zero();
}
BSEntity::~BSEntity() {
}
/*
======================
BSEntity::WriteToSaveGame
======================
*/
void BSEntity::WriteToSaveGame( idFile *savefile ) {
game->WriteSaveGameString( materialName, savefile );
savefile->Write( &width, sizeof(width) );
savefile->Write( &height, sizeof(height) );
savefile->Write( &visible, sizeof(visible) );
savefile->Write( &entColor, sizeof(entColor) );
savefile->Write( &position, sizeof(position) );
savefile->Write( &rotation, sizeof(rotation) );
savefile->Write( &rotationSpeed, sizeof(rotationSpeed) );
savefile->Write( &velocity, sizeof(velocity) );
savefile->Write( &fadeIn, sizeof(fadeIn) );
savefile->Write( &fadeOut, sizeof(fadeOut) );
}
/*
======================
BSEntity::ReadFromSaveGame
======================
*/
void BSEntity::ReadFromSaveGame( idFile *savefile, idGameBearShootWindow* _game ) {
game = _game;
game->ReadSaveGameString( materialName, savefile );
SetMaterial( materialName );
savefile->Read( &width, sizeof(width) );
savefile->Read( &height, sizeof(height) );
savefile->Read( &visible, sizeof(visible) );
savefile->Read( &entColor, sizeof(entColor) );
savefile->Read( &position, sizeof(position) );
savefile->Read( &rotation, sizeof(rotation) );
savefile->Read( &rotationSpeed, sizeof(rotationSpeed) );
savefile->Read( &velocity, sizeof(velocity) );
savefile->Read( &fadeIn, sizeof(fadeIn) );
savefile->Read( &fadeOut, sizeof(fadeOut) );
}
/*
======================
BSEntity::SetMaterial
======================
*/
void BSEntity::SetMaterial(const char* name) {
materialName = name;
material = declManager->FindMaterial( name );
material->SetSort( SS_GUI );
}
/*
======================
BSEntity::SetSize
======================
*/
void BSEntity::SetSize( float _width, float _height ) {
width = _width;
height = _height;
}
/*
======================
BSEntity::SetVisible
======================
*/
void BSEntity::SetVisible( bool isVisible ) {
visible = isVisible;
}
/*
======================
BSEntity::Update
======================
*/
void BSEntity::Update( float timeslice ) {
if ( !visible ) {
return;
}
// Fades
if ( fadeIn && entColor.w < 1.f ) {
entColor.w += 1 * timeslice;
if ( entColor.w >= 1.f ) {
entColor.w = 1.f;
fadeIn = false;
}
}
if ( fadeOut && entColor.w > 0.f ) {
entColor.w -= 1 * timeslice;
if ( entColor.w <= 0.f ) {
entColor.w = 0.f;
fadeOut = false;
}
}
// Move the entity
position += velocity * timeslice;
// Rotate Entity
rotation += rotationSpeed * timeslice;
}
/*
======================
BSEntity::Draw
======================
*/
void BSEntity::Draw(idDeviceContext *dc) {
if ( visible ) {
dc->DrawMaterialRotated( position.x, position.y, width, height, material, entColor, 1.0f, 1.0f, DEG2RAD(rotation) );
}
}
/*
*****************************************************************************
* idGameBearShootWindow
****************************************************************************
*/
idGameBearShootWindow::idGameBearShootWindow(idDeviceContext *d, idUserInterfaceLocal *g) : idWindow(d, g) {
dc = d;
gui = g;
CommonInit();
}
idGameBearShootWindow::idGameBearShootWindow(idUserInterfaceLocal *g) : idWindow(g) {
gui = g;
CommonInit();
}
idGameBearShootWindow::~idGameBearShootWindow() {
entities.DeleteContents(true);
}
/*
=============================
idGameBearShootWindow::WriteToSaveGame
=============================
*/
void idGameBearShootWindow::WriteToSaveGame( idFile *savefile ) {
idWindow::WriteToSaveGame( savefile );
gamerunning.WriteToSaveGame( savefile );
onFire.WriteToSaveGame( savefile );
onContinue.WriteToSaveGame( savefile );
onNewGame.WriteToSaveGame( savefile );
savefile->Write( &timeSlice, sizeof(timeSlice) );
savefile->Write( &timeRemaining, sizeof(timeRemaining) );
savefile->Write( &gameOver, sizeof(gameOver) );
savefile->Write( &currentLevel, sizeof(currentLevel) );
savefile->Write( &goalsHit, sizeof(goalsHit) );
savefile->Write( &updateScore, sizeof(updateScore) );
savefile->Write( &bearHitTarget, sizeof(bearHitTarget) );
savefile->Write( &bearScale, sizeof(bearScale) );
savefile->Write( &bearIsShrinking, sizeof(bearIsShrinking) );
savefile->Write( &bearShrinkStartTime, sizeof(bearShrinkStartTime) );
savefile->Write( &turretAngle, sizeof(turretAngle) );
savefile->Write( &turretForce, sizeof(turretForce) );
savefile->Write( &windForce, sizeof(windForce) );
savefile->Write( &windUpdateTime, sizeof(windUpdateTime) );
int numberOfEnts = entities.Num();
savefile->Write( &numberOfEnts, sizeof(numberOfEnts) );
for ( int i=0; i<numberOfEnts; i++ ) {
entities[i]->WriteToSaveGame( savefile );
}
int index;
index = entities.FindIndex( turret );
savefile->Write( &index, sizeof(index) );
index = entities.FindIndex( bear );
savefile->Write( &index, sizeof(index) );
index = entities.FindIndex( helicopter );
savefile->Write( &index, sizeof(index) );
index = entities.FindIndex( goal );
savefile->Write( &index, sizeof(index) );
index = entities.FindIndex( wind );
savefile->Write( &index, sizeof(index) );
index = entities.FindIndex( gunblast );
savefile->Write( &index, sizeof(index) );
}
/*
=============================
idGameBearShootWindow::ReadFromSaveGame
=============================
*/
void idGameBearShootWindow::ReadFromSaveGame( idFile *savefile ) {
idWindow::ReadFromSaveGame( savefile );
// Remove all existing entities
entities.DeleteContents(true);
gamerunning.ReadFromSaveGame( savefile );
onFire.ReadFromSaveGame( savefile );
onContinue.ReadFromSaveGame( savefile );
onNewGame.ReadFromSaveGame( savefile );
savefile->Read( &timeSlice, sizeof(timeSlice) );
savefile->Read( &timeRemaining, sizeof(timeRemaining) );
savefile->Read( &gameOver, sizeof(gameOver) );
savefile->Read( &currentLevel, sizeof(currentLevel) );
savefile->Read( &goalsHit, sizeof(goalsHit) );
savefile->Read( &updateScore, sizeof(updateScore) );
savefile->Read( &bearHitTarget, sizeof(bearHitTarget) );
savefile->Read( &bearScale, sizeof(bearScale) );
savefile->Read( &bearIsShrinking, sizeof(bearIsShrinking) );
savefile->Read( &bearShrinkStartTime, sizeof(bearShrinkStartTime) );
savefile->Read( &turretAngle, sizeof(turretAngle) );
savefile->Read( &turretForce, sizeof(turretForce) );
savefile->Read( &windForce, sizeof(windForce) );
savefile->Read( &windUpdateTime, sizeof(windUpdateTime) );
int numberOfEnts;
savefile->Read( &numberOfEnts, sizeof(numberOfEnts) );
for ( int i=0; i<numberOfEnts; i++ ) {
BSEntity *ent;
ent = new BSEntity( this );
ent->ReadFromSaveGame( savefile, this );
entities.Append( ent );
}
int index;
savefile->Read( &index, sizeof(index) );
turret = entities[index];
savefile->Read( &index, sizeof(index) );
bear = entities[index];
savefile->Read( &index, sizeof(index) );
helicopter = entities[index];
savefile->Read( &index, sizeof(index) );
goal = entities[index];
savefile->Read( &index, sizeof(index) );
wind = entities[index];
savefile->Read( &index, sizeof(index) );
gunblast = entities[index];
}
/*
=============================
idGameBearShootWindow::ResetGameState
=============================
*/
void idGameBearShootWindow::ResetGameState() {
gamerunning = false;
gameOver = false;
onFire = false;
onContinue = false;
onNewGame = false;
// Game moves forward 16 milliseconds every frame
timeSlice = 0.016f;
timeRemaining = 60.f;
goalsHit = 0;
updateScore = false;
bearHitTarget = false;
currentLevel = 1;
turretAngle = 0.f;
turretForce = 200.f;
windForce = 0.f;
windUpdateTime = 0;
bearIsShrinking = false;
bearShrinkStartTime = 0;
bearScale = 1.f;
}
/*
=============================
idGameBearShootWindow::CommonInit
=============================
*/
void idGameBearShootWindow::CommonInit() {
BSEntity * ent;
// Precache sounds
declManager->FindSound( "arcade_beargroan" );
declManager->FindSound( "arcade_sargeshoot" );
declManager->FindSound( "arcade_balloonpop" );
declManager->FindSound( "arcade_levelcomplete1" );
// Precache dynamically used materials
declManager->FindMaterial( "game/bearshoot/helicopter_broken" );
declManager->FindMaterial( "game/bearshoot/goal_dead" );
declManager->FindMaterial( "game/bearshoot/gun_blast" );
ResetGameState();
ent = new BSEntity( this );
turret = ent;
ent->SetMaterial( "game/bearshoot/turret" );
ent->SetSize( 272, 144 );
ent->position.x = -44;
ent->position.y = 260;
entities.Append( ent );
ent = new BSEntity( this );
ent->SetMaterial( "game/bearshoot/turret_base" );
ent->SetSize( 144, 160 );
ent->position.x = 16;
ent->position.y = 280;
entities.Append( ent );
ent = new BSEntity( this );
bear = ent;
ent->SetMaterial( "game/bearshoot/bear" );
ent->SetSize( BEAR_SIZE, BEAR_SIZE );
ent->SetVisible( false );
ent->position.x = 0;
ent->position.y = 0;
entities.Append( ent );
ent = new BSEntity( this );
helicopter = ent;
ent->SetMaterial( "game/bearshoot/helicopter" );
ent->SetSize( 64, 64 );
ent->position.x = 550;
ent->position.y = 100;
entities.Append( ent );
ent = new BSEntity( this );
goal = ent;
ent->SetMaterial( "game/bearshoot/goal" );
ent->SetSize( 64, 64 );
ent->position.x = 550;
ent->position.y = 164;
entities.Append( ent );
ent = new BSEntity( this );
wind = ent;
ent->SetMaterial( "game/bearshoot/wind" );
ent->SetSize( 100, 40 );
ent->position.x = 500;
ent->position.y = 430;
entities.Append( ent );
ent = new BSEntity( this );
gunblast = ent;
ent->SetMaterial( "game/bearshoot/gun_blast" );
ent->SetSize( 64, 64 );
ent->SetVisible( false );
entities.Append( ent );
}
/*
=============================
idGameBearShootWindow::HandleEvent
=============================
*/
const char *idGameBearShootWindow::HandleEvent(const sysEvent_t *event, bool *updateVisuals) {
int key = event->evValue;
// need to call this to allow proper focus and capturing on embedded children
const char *ret = idWindow::HandleEvent(event, updateVisuals);
if ( event->evType == SE_KEY ) {
if ( !event->evValue2 ) {
return ret;
}
if ( key == K_MOUSE1) {
// Mouse was clicked
} else {
return ret;
}
}
return ret;
}
/*
=============================
idGameBearShootWindow::ParseInternalVar
=============================
*/
bool idGameBearShootWindow::ParseInternalVar(const char *_name, idParser *src) {
if ( idStr::Icmp(_name, "gamerunning") == 0 ) {
gamerunning = src->ParseBool();
return true;
}
if ( idStr::Icmp(_name, "onFire") == 0 ) {
onFire = src->ParseBool();
return true;
}
if ( idStr::Icmp(_name, "onContinue") == 0 ) {
onContinue = src->ParseBool();
return true;
}
if ( idStr::Icmp(_name, "onNewGame") == 0 ) {
onNewGame = src->ParseBool();
return true;
}
return idWindow::ParseInternalVar(_name, src);
}
/*
=============================
idGameBearShootWindow::GetWinVarByName
=============================
*/
idWinVar *idGameBearShootWindow::GetWinVarByName(const char *_name, bool winLookup, drawWin_t** owner) {
idWinVar *retVar = NULL;
if ( idStr::Icmp(_name, "gamerunning") == 0 ) {
retVar = &gamerunning;
} else if ( idStr::Icmp(_name, "onFire") == 0 ) {
retVar = &onFire;
} else if ( idStr::Icmp(_name, "onContinue") == 0 ) {
retVar = &onContinue;
} else if ( idStr::Icmp(_name, "onNewGame") == 0 ) {
retVar = &onNewGame;
}
if(retVar) {
return retVar;
}
return idWindow::GetWinVarByName(_name, winLookup, owner);
}
/*
=============================
idGameBearShootWindow::PostParse
=============================
*/
void idGameBearShootWindow::PostParse() {
idWindow::PostParse();
}
/*
=============================
idGameBearShootWindow::Draw
=============================
*/
void idGameBearShootWindow::Draw(int time, float x, float y) {
int i;
//Update the game every frame before drawing
UpdateGame();
for( i = entities.Num()-1; i >= 0; i-- ) {
entities[i]->Draw(dc);
}
}
/*
=============================
idGameBearShootWindow::Activate
=============================
*/
const char *idGameBearShootWindow::Activate(bool activate) {
return "";
}
/*
=============================
idGameBearShootWindow::UpdateTurret
=============================
*/
void idGameBearShootWindow::UpdateTurret() {
idVec2 pt;
idVec2 turretOrig;
idVec2 right;
float dot, angle;
pt.x = gui->CursorX();
pt.y = gui->CursorY();
turretOrig.Set( 80.f, 348.f );
pt = pt - turretOrig;
pt.NormalizeFast();
right.x = 1.f;
right.y = 0.f;
dot = pt * right;
angle = RAD2DEG( acosf( dot ) );
turretAngle = idMath::ClampFloat( 0.f, 90.f, angle );
}
/*
=============================
idGameBearShootWindow::UpdateBear
=============================
*/
void idGameBearShootWindow::UpdateBear() {
int time = gui->GetTime();
bool startShrink = false;
// Apply gravity
bear->velocity.y += BEAR_GRAVITY * timeSlice;
// Apply wind
bear->velocity.x += windForce * timeSlice;
// Check for collisions
if ( !bearHitTarget && !gameOver ) {
idVec2 bearCenter;
bool collision = false;
bearCenter.x = bear->position.x + bear->width/2;
bearCenter.y = bear->position.y + bear->height/2;
if ( bearCenter.x > (helicopter->position.x + 16) && bearCenter.x < (helicopter->position.x + helicopter->width - 29) ) {
if ( bearCenter.y > (helicopter->position.y + 12) && bearCenter.y < (helicopter->position.y + helicopter->height - 7) ) {
collision = true;
}
}
if ( collision ) {
// balloons pop and bear tumbles to ground
helicopter->SetMaterial( "game/bearshoot/helicopter_broken" );
helicopter->velocity.y = 230.f;
goal->velocity.y = 230.f;
session->sw->PlayShaderDirectly( "arcade_balloonpop" );
bear->SetVisible( false );
if ( bear->velocity.x > 0 ) {
bear->velocity.x *= -1.f;
}
bear->velocity *= 0.666f;
bearHitTarget = true;
updateScore = true;
startShrink = true;
}
}
// Check for ground collision
if ( bear->position.y > 380 ) {
bear->position.y = 380;
if ( bear->velocity.Length() < 25 ) {
bear->velocity.Zero();
} else {
startShrink = true;
bear->velocity.y *= -1.f;
bear->velocity *= 0.5f;
if ( bearScale ) {
session->sw->PlayShaderDirectly( "arcade_balloonpop" );
}
}
}
// Bear rotation is based on velocity
float angle;
idVec2 dir;
dir = bear->velocity;
dir.NormalizeFast();
angle = RAD2DEG( atan2( dir.x, dir.y ) );
bear->rotation = angle - 90;
// Update Bear scale
if ( bear->position.x > 650 ) {
startShrink = true;
}
if ( !bearIsShrinking && bearScale && startShrink ) {
bearShrinkStartTime = time;
bearIsShrinking = true;
}
if ( bearIsShrinking ) {
if ( bearHitTarget ) {
bearScale = 1 - ( (float)(time - bearShrinkStartTime) / BEAR_SHRINK_TIME );
} else {
bearScale = 1 - ( (float)(time - bearShrinkStartTime) / 750 );
}
bearScale *= BEAR_SIZE;
bear->SetSize( bearScale, bearScale );
if ( bearScale < 0 ) {
gui->HandleNamedEvent( "EnableFireButton" );
bearIsShrinking = false;
bearScale = 0.f;
if ( bearHitTarget ) {
goal->SetMaterial( "game/bearshoot/goal" );
goal->position.x = 550;
goal->position.y = 164;
goal->velocity.Zero();
goal->velocity.y = (currentLevel-1) * 30;
goal->entColor.w = 0.f;
goal->fadeIn = true;
goal->fadeOut = false;
helicopter->SetVisible( true );
helicopter->SetMaterial( "game/bearshoot/helicopter" );
helicopter->position.x = 550;
helicopter->position.y = 100;
helicopter->velocity.Zero();
helicopter->velocity.y = goal->velocity.y;
helicopter->entColor.w = 0.f;
helicopter->fadeIn = true;
helicopter->fadeOut = false;
}
}
}
}
/*
=============================
idGameBearShootWindow::UpdateHelicopter
=============================
*/
void idGameBearShootWindow::UpdateHelicopter() {
if ( bearHitTarget && bearIsShrinking ) {
if ( helicopter->velocity.y != 0 && helicopter->position.y > 264 ) {
helicopter->velocity.y = 0;
goal->velocity.y = 0;
helicopter->SetVisible( false );
goal->SetMaterial( "game/bearshoot/goal_dead" );
session->sw->PlayShaderDirectly( "arcade_beargroan", 1 );
helicopter->fadeOut = true;
goal->fadeOut = true;
}
} else if ( currentLevel > 1 ) {
int height = helicopter->position.y;
float speed = (currentLevel-1) * 30;
if ( height > 240 ) {
helicopter->velocity.y = -speed;
goal->velocity.y = -speed;
} else if ( height < 30 ) {
helicopter->velocity.y = speed;
goal->velocity.y = speed;
}
}
}
/*
=============================
idGameBearShootWindow::UpdateButtons
=============================
*/
void idGameBearShootWindow::UpdateButtons() {
if ( onFire ) {
idVec2 vec;
gui->HandleNamedEvent( "DisableFireButton" );
session->sw->PlayShaderDirectly( "arcade_sargeshoot" );
bear->SetVisible( true );
bearScale = 1.f;
bear->SetSize( BEAR_SIZE, BEAR_SIZE );
vec.x = idMath::Cos( DEG2RAD(turretAngle) );
vec.x += ( 1 - vec.x ) * 0.18f;
vec.y = -idMath::Sin( DEG2RAD(turretAngle) );
turretForce = bearTurretForce.GetFloat();
bear->position.x = 80 + ( 96 * vec.x );
bear->position.y = 334 + ( 96 * vec.y );
bear->velocity.x = vec.x * turretForce;
bear->velocity.y = vec.y * turretForce;
gunblast->position.x = 55 + ( 96 * vec.x );
gunblast->position.y = 310 + ( 100 * vec.y );
gunblast->SetVisible( true );
gunblast->entColor.w = 1.f;
gunblast->rotation = turretAngle;
gunblast->fadeOut = true;
bearHitTarget = false;
onFire = false;
}
}
/*
=============================
idGameBearShootWindow::UpdateScore
=============================
*/
void idGameBearShootWindow::UpdateScore() {
if ( gameOver ) {
gui->HandleNamedEvent( "GameOver" );
return;
}
goalsHit++;
gui->SetStateString( "player_score", va("%i", goalsHit ) );
// Check for level progression
if ( !(goalsHit % 5) ) {
currentLevel++;
gui->SetStateString( "current_level", va("%i", currentLevel ) );
session->sw->PlayShaderDirectly( "arcade_levelcomplete1", 3 );
timeRemaining += 30;
}
}
/*
=============================
idGameBearShootWindow::UpdateGame
=============================
*/
void idGameBearShootWindow::UpdateGame() {
int i;
if ( onNewGame ) {
ResetGameState();
goal->position.x = 550;
goal->position.y = 164;
goal->velocity.Zero();
helicopter->position.x = 550;
helicopter->position.y = 100;
helicopter->velocity.Zero();
bear->SetVisible( false );
bearTurretAngle.SetFloat( 0.f );
bearTurretForce.SetFloat( 200.f );
gamerunning = true;
}
if ( onContinue ) {
gameOver = false;
timeRemaining = 60.f;
onContinue = false;
}
if(gamerunning == true) {
int current_time = gui->GetTime();
idRandom rnd( current_time );
// Check for button presses
UpdateButtons();
if ( bear ) {
UpdateBear();
}
if ( helicopter && goal ) {
UpdateHelicopter();
}
// Update Wind
if ( windUpdateTime < current_time ) {
float scale;
int width;
windForce = rnd.CRandomFloat() * ( MAX_WINDFORCE * 0.75f );
if (windForce > 0) {
windForce += ( MAX_WINDFORCE * 0.25f );
wind->rotation = 0;
} else {
windForce -= ( MAX_WINDFORCE * 0.25f );
wind->rotation = 180;
}
scale = 1.f - (( MAX_WINDFORCE - idMath::Fabs(windForce) ) / MAX_WINDFORCE);
width = 100*scale;
if ( windForce < 0 ) {
wind->position.x = 500 - width + 1;
} else {
wind->position.x = 500;
}
wind->SetSize( width, 40 );
windUpdateTime = current_time + 7000 + rnd.RandomInt(5000);
}
// Update turret rotation angle
if ( turret ) {
turretAngle = bearTurretAngle.GetFloat();
turret->rotation = turretAngle;
}
for( i = 0; i < entities.Num(); i++ ) {
entities[i]->Update( timeSlice );
}
// Update countdown timer
timeRemaining -= timeSlice;
timeRemaining = idMath::ClampFloat( 0.f, 99999.f, timeRemaining );
gui->SetStateString( "time_remaining", va("%2.1f", timeRemaining ) );
if ( timeRemaining <= 0.f && !gameOver ) {
gameOver = true;
updateScore = true;
}
if ( updateScore ) {
UpdateScore();
updateScore = false;
}
}
}

View File

@@ -0,0 +1,133 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __GAME_BEARSHOOT_WINDOW_H__
#define __GAME_BEARSHOOT_WINDOW_H__
class idGameBearShootWindow;
class BSEntity {
public:
const idMaterial * material;
idStr materialName;
float width, height;
bool visible;
idVec4 entColor;
idVec2 position;
float rotation;
float rotationSpeed;
idVec2 velocity;
bool fadeIn;
bool fadeOut;
idGameBearShootWindow * game;
public:
BSEntity(idGameBearShootWindow* _game);
virtual ~BSEntity();
virtual void WriteToSaveGame( idFile *savefile );
virtual void ReadFromSaveGame( idFile *savefile, idGameBearShootWindow* _game );
void SetMaterial(const char* name);
void SetSize( float _width, float _height );
void SetVisible( bool isVisible );
virtual void Update( float timeslice );
virtual void Draw(idDeviceContext *dc);
private:
};
class idGameBearShootWindow : public idWindow {
public:
idGameBearShootWindow(idUserInterfaceLocal *gui);
idGameBearShootWindow(idDeviceContext *d, idUserInterfaceLocal *gui);
~idGameBearShootWindow();
virtual void WriteToSaveGame( idFile *savefile );
virtual void ReadFromSaveGame( idFile *savefile );
virtual const char* HandleEvent(const sysEvent_t *event, bool *updateVisuals);
virtual void PostParse();
virtual void Draw(int time, float x, float y);
virtual const char* Activate(bool activate);
virtual idWinVar * GetWinVarByName (const char *_name, bool winLookup = false, drawWin_t** owner = NULL);
private:
void CommonInit();
void ResetGameState();
void UpdateBear();
void UpdateHelicopter();
void UpdateTurret();
void UpdateButtons();
void UpdateGame();
void UpdateScore();
virtual bool ParseInternalVar(const char *name, idParser *src);
private:
idWinBool gamerunning;
idWinBool onFire;
idWinBool onContinue;
idWinBool onNewGame;
float timeSlice;
float timeRemaining;
bool gameOver;
int currentLevel;
int goalsHit;
bool updateScore;
bool bearHitTarget;
float bearScale;
bool bearIsShrinking;
int bearShrinkStartTime;
float turretAngle;
float turretForce;
float windForce;
int windUpdateTime;
idList<BSEntity*> entities;
BSEntity *turret;
BSEntity *bear;
BSEntity *helicopter;
BSEntity *goal;
BSEntity *wind;
BSEntity *gunblast;
};
#endif //__GAME_BEARSHOOT_WINDOW_H__

1342
neo/ui/GameBustOutWindow.cpp Normal file

File diff suppressed because it is too large Load Diff

186
neo/ui/GameBustOutWindow.h Normal file
View File

@@ -0,0 +1,186 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __GAME_BUSTOUT_WINDOW_H__
#define __GAME_BUSTOUT_WINDOW_H__
class idGameBustOutWindow;
typedef enum {
POWERUP_NONE = 0,
POWERUP_BIGPADDLE,
POWERUP_MULTIBALL
} powerupType_t;
class BOEntity {
public:
bool visible;
idStr materialName;
const idMaterial * material;
float width, height;
idVec4 color;
idVec2 position;
idVec2 velocity;
powerupType_t powerup;
bool removed;
bool fadeOut;
idGameBustOutWindow * game;
public:
BOEntity(idGameBustOutWindow* _game);
virtual ~BOEntity();
virtual void WriteToSaveGame( idFile *savefile );
virtual void ReadFromSaveGame( idFile *savefile, idGameBustOutWindow* _game );
void SetMaterial(const char* name);
void SetSize( float _width, float _height );
void SetColor( float r, float g, float b, float a );
void SetVisible( bool isVisible );
virtual void Update( float timeslice, int guiTime );
virtual void Draw(idDeviceContext *dc);
private:
};
typedef enum {
COLLIDE_NONE = 0,
COLLIDE_DOWN,
COLLIDE_UP,
COLLIDE_LEFT,
COLLIDE_RIGHT
} collideDir_t;
class BOBrick {
public:
float x;
float y;
float width;
float height;
powerupType_t powerup;
bool isBroken;
BOEntity *ent;
public:
BOBrick();
BOBrick( BOEntity *_ent, float _x, float _y, float _width, float _height );
~BOBrick();
virtual void WriteToSaveGame( idFile *savefile );
virtual void ReadFromSaveGame( idFile *savefile, idGameBustOutWindow *game );
void SetColor( idVec4 bcolor );
collideDir_t checkCollision( idVec2 pos, idVec2 vel );
private:
};
#define BOARD_ROWS 12
class idGameBustOutWindow : public idWindow {
public:
idGameBustOutWindow(idUserInterfaceLocal *gui);
idGameBustOutWindow(idDeviceContext *d, idUserInterfaceLocal *gui);
~idGameBustOutWindow();
virtual void WriteToSaveGame( idFile *savefile );
virtual void ReadFromSaveGame( idFile *savefile );
virtual const char* HandleEvent(const sysEvent_t *event, bool *updateVisuals);
virtual void PostParse();
virtual void Draw(int time, float x, float y);
virtual const char* Activate(bool activate);
virtual idWinVar * GetWinVarByName (const char *_name, bool winLookup = false, drawWin_t** owner = NULL);
idList<BOEntity*> entities;
private:
void CommonInit();
void ResetGameState();
void ClearBoard();
void ClearPowerups();
void ClearBalls();
void LoadBoardFiles();
void SetCurrentBoard();
void UpdateGame();
void UpdatePowerups();
void UpdatePaddle();
void UpdateBall();
void UpdateScore();
BOEntity * CreateNewBall();
BOEntity * CreatePowerup( BOBrick *brick );
virtual bool ParseInternalVar(const char *name, idParser *src);
private:
idWinBool gamerunning;
idWinBool onFire;
idWinBool onContinue;
idWinBool onNewGame;
idWinBool onNewLevel;
float timeSlice;
bool gameOver;
int numLevels;
byte * levelBoardData;
bool boardDataLoaded;
int numBricks;
int currentLevel;
bool updateScore;
int gameScore;
int nextBallScore;
int bigPaddleTime;
float paddleVelocity;
float ballSpeed;
int ballsRemaining;
int ballsInPlay;
bool ballHitCeiling;
idList<BOEntity*> balls;
idList<BOEntity*> powerUps;
BOBrick *paddle;
idList<BOBrick*> board[BOARD_ROWS];
};
#endif //__GAME_BUSTOUT_WINDOW_H__

2299
neo/ui/GameSSDWindow.cpp Normal file

File diff suppressed because it is too large Load Diff

616
neo/ui/GameSSDWindow.h Normal file
View File

@@ -0,0 +1,616 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __GAME_SSD_WINDOW_H__
#define __GAME_SSD_WINDOW_H__
class idGameSSDWindow;
class SSDCrossHair {
public:
enum {
CROSSHAIR_STANDARD = 0,
CROSSHAIR_SUPER,
CROSSHAIR_COUNT
};
const idMaterial* crosshairMaterial[CROSSHAIR_COUNT];
int currentCrosshair;
float crosshairWidth, crosshairHeight;
public:
SSDCrossHair();
~SSDCrossHair();
virtual void WriteToSaveGame( idFile *savefile );
virtual void ReadFromSaveGame( idFile *savefile );
void InitCrosshairs();
void Draw(idDeviceContext *dc, const idVec2& cursor);
};
enum {
SSD_ENTITY_BASE = 0,
SSD_ENTITY_ASTEROID,
SSD_ENTITY_ASTRONAUT,
SSD_ENTITY_EXPLOSION,
SSD_ENTITY_POINTS,
SSD_ENTITY_PROJECTILE,
SSD_ENTITY_POWERUP
};
class SSDEntity {
public:
//SSDEntity Information
int type;
int id;
idStr materialName;
const idMaterial* material;
idVec3 position;
idVec2 size;
float radius;
float hitRadius;
float rotation;
idVec4 matColor;
idStr text;
float textScale;
idVec4 foreColor;
idGameSSDWindow* game;
int currentTime;
int lastUpdate;
int elapsed;
bool destroyed;
bool noHit;
bool noPlayerDamage;
bool inUse;
public:
SSDEntity();
virtual ~SSDEntity();
virtual void WriteToSaveGame( idFile *savefile );
virtual void ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game );
void EntityInit();
void SetGame(idGameSSDWindow* _game);
void SetMaterial(const char* _name);
void SetPosition(const idVec3& _position);
void SetSize(const idVec2& _size);
void SetRadius(float _radius, float _hitFactor = 1.0f);
void SetRotation(float _rotation);
void Update();
bool HitTest(const idVec2& pt);
virtual void EntityUpdate() {};
virtual void Draw(idDeviceContext *dc);
virtual void DestroyEntity();
virtual void OnHit(int key) {};
virtual void OnStrikePlayer() {};
idBounds WorldToScreen(const idBounds worldBounds);
idVec3 WorldToScreen(const idVec3& worldPos);
idVec3 ScreenToWorld(const idVec3& screenPos);
};
/*
*****************************************************************************
* SSDMover
****************************************************************************
*/
class SSDMover : public SSDEntity {
public:
idVec3 speed;
float rotationSpeed;
public:
SSDMover();
virtual ~SSDMover();
virtual void WriteToSaveGame( idFile *savefile );
virtual void ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game );
void MoverInit(const idVec3& _speed, float _rotationSpeed);
virtual void EntityUpdate();
};
/*
*****************************************************************************
* SSDAsteroid
****************************************************************************
*/
#define MAX_ASTEROIDS 64
class SSDAsteroid : public SSDMover {
public:
int health;
public:
SSDAsteroid();
~SSDAsteroid();
virtual void WriteToSaveGame( idFile *savefile );
virtual void ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game );
void Init(idGameSSDWindow* _game, const idVec3& startPosition, const idVec2& _size, float _speed, float rotate, int _health);
virtual void EntityUpdate();
static SSDAsteroid* GetNewAsteroid(idGameSSDWindow* _game, const idVec3& startPosition, const idVec2& _size, float _speed, float rotate, int _health);
static SSDAsteroid* GetSpecificAsteroid(int id);
static void WriteAsteroids(idFile* savefile);
static void ReadAsteroids(idFile* savefile, idGameSSDWindow* _game);
protected:
static SSDAsteroid asteroidPool[MAX_ASTEROIDS];
};
/*
*****************************************************************************
* SSDAstronaut
****************************************************************************
*/
#define MAX_ASTRONAUT 8
class SSDAstronaut : public SSDMover {
public:
int health;
public:
SSDAstronaut();
~SSDAstronaut();
virtual void WriteToSaveGame( idFile *savefile );
virtual void ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game );
void Init(idGameSSDWindow* _game, const idVec3& startPosition, float _speed, float rotate, int _health);
static SSDAstronaut* GetNewAstronaut(idGameSSDWindow* _game, const idVec3& startPosition, float _speed, float rotate, int _health);
static SSDAstronaut* GetSpecificAstronaut(int id);
static void WriteAstronauts(idFile* savefile);
static void ReadAstronauts(idFile* savefile, idGameSSDWindow* _game);
protected:
static SSDAstronaut astronautPool[MAX_ASTRONAUT];
};
/*
*****************************************************************************
* SSDExplosion
****************************************************************************
*/
#define MAX_EXPLOSIONS 64
class SSDExplosion : public SSDEntity {
public:
idVec2 finalSize;
int length;
int beginTime;
int endTime;
int explosionType;
//The entity that is exploding
SSDEntity* buddy;
bool killBuddy;
bool followBuddy;
enum {
EXPLOSION_NORMAL = 0,
EXPLOSION_TELEPORT = 1
};
public:
SSDExplosion();
~SSDExplosion();
virtual void WriteToSaveGame( idFile *savefile );
virtual void ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game );
void Init(idGameSSDWindow* _game, const idVec3& _position, const idVec2& _size, int _length, int _type, SSDEntity* _buddy, bool _killBuddy = true, bool _followBuddy = true);
virtual void EntityUpdate();
static SSDExplosion* GetNewExplosion(idGameSSDWindow* _game, const idVec3& _position, const idVec2& _size, int _length, int _type, SSDEntity* _buddy, bool _killBuddy = true, bool _followBuddy = true);
static SSDExplosion* GetSpecificExplosion(int id);
static void WriteExplosions(idFile* savefile);
static void ReadExplosions(idFile* savefile, idGameSSDWindow* _game);
protected:
static SSDExplosion explosionPool[MAX_EXPLOSIONS];
};
#define MAX_POINTS 16
class SSDPoints : public SSDEntity {
int length;
int distance;
int beginTime;
int endTime;
idVec3 beginPosition;
idVec3 endPosition;
idVec4 beginColor;
idVec4 endColor;
public:
SSDPoints();
~SSDPoints();
virtual void WriteToSaveGame( idFile *savefile );
virtual void ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game );
void Init(idGameSSDWindow* _game, SSDEntity* _ent, int _points, int _length, int _distance, const idVec4& color);
virtual void EntityUpdate();
static SSDPoints* GetNewPoints(idGameSSDWindow* _game, SSDEntity* _ent, int _points, int _length, int _distance, const idVec4& color);
static SSDPoints* GetSpecificPoints(int id);
static void WritePoints(idFile* savefile);
static void ReadPoints(idFile* savefile, idGameSSDWindow* _game);
protected:
static SSDPoints pointsPool[MAX_POINTS];
};
#define MAX_PROJECTILES 64
class SSDProjectile : public SSDEntity {
idVec3 dir;
idVec3 speed;
int beginTime;
int endTime;
idVec3 endPosition;
public:
SSDProjectile();
~SSDProjectile();
virtual void WriteToSaveGame( idFile *savefile );
virtual void ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game );
void Init(idGameSSDWindow* _game, const idVec3& _beginPosition, const idVec3& _endPosition, float _speed, float _size);
virtual void EntityUpdate();
static SSDProjectile* GetNewProjectile(idGameSSDWindow* _game, const idVec3& _beginPosition, const idVec3& _endPosition, float _speed, float _size);
static SSDProjectile* GetSpecificProjectile(int id);
static void WriteProjectiles(idFile* savefile);
static void ReadProjectiles(idFile* savefile, idGameSSDWindow* _game);
protected:
static SSDProjectile projectilePool[MAX_PROJECTILES];
};
#define MAX_POWERUPS 64
/**
* Powerups work in two phases:
* 1.) Closed container hurls at you
* If you shoot the container it open
* 3.) If an opened powerup hits the player he aquires the powerup
* Powerup Types:
* Health - Give a specific amount of health
* Super Blaster - Increases the power of the blaster (lasts a specific amount of time)
* Asteroid Nuke - Destroys all asteroids on screen as soon as it is aquired
* Rescue Powerup - Rescues all astronauts as soon as it is acquited
* Bonus Points - Gives some bonus points when acquired
*/
class SSDPowerup : public SSDMover {
enum {
POWERUP_STATE_CLOSED = 0,
POWERUP_STATE_OPEN
};
enum {
POWERUP_TYPE_HEALTH = 0,
POWERUP_TYPE_SUPER_BLASTER,
POWERUP_TYPE_ASTEROID_NUKE,
POWERUP_TYPE_RESCUE_ALL,
POWERUP_TYPE_BONUS_POINTS,
POWERUP_TYPE_DAMAGE,
POWERUP_TYPE_MAX
};
int powerupState;
int powerupType;
public:
public:
SSDPowerup();
virtual ~SSDPowerup();
virtual void WriteToSaveGame( idFile *savefile );
virtual void ReadFromSaveGame( idFile *savefile, idGameSSDWindow* _game );
virtual void OnHit(int key);
virtual void OnStrikePlayer();
void OnOpenPowerup();
void OnActivatePowerup();
void Init(idGameSSDWindow* _game, float _speed, float _rotation);
static SSDPowerup* GetNewPowerup(idGameSSDWindow* _game, float _speed, float _rotation);
static SSDPowerup* GetSpecificPowerup(int id);
static void WritePowerups(idFile* savefile);
static void ReadPowerups(idFile* savefile, idGameSSDWindow* _game);
protected:
static SSDPowerup powerupPool[MAX_POWERUPS];
};
typedef struct {
float spawnBuffer;
int needToWin;
} SSDLevelData_t;
typedef struct {
float speedMin, speedMax;
float sizeMin, sizeMax;
float rotateMin, rotateMax;
int spawnMin, spawnMax;
int asteroidHealth;
int asteroidPoints;
int asteroidDamage;
} SSDAsteroidData_t;
typedef struct {
float speedMin, speedMax;
float rotateMin, rotateMax;
int spawnMin, spawnMax;
int health;
int points;
int penalty;
} SSDAstronautData_t;
typedef struct {
float speedMin, speedMax;
float rotateMin, rotateMax;
int spawnMin, spawnMax;
} SSDPowerupData_t;
typedef struct {
float speed;
int damage;
int size;
} SSDWeaponData_t;
/**
* SSDLevelStats_t
* Data that is used for each level. This data is reset
* each new level.
*/
typedef struct {
int shotCount;
int hitCount;
int destroyedAsteroids;
int nextAsteroidSpawnTime;
int killedAstronauts;
int savedAstronauts;
//Astronaut Level Data
int nextAstronautSpawnTime;
//Powerup Level Data
int nextPowerupSpawnTime;
SSDEntity* targetEnt;
} SSDLevelStats_t;
/**
* SSDGameStats_t
* Data that is used for the game that is currently running. Memset this
* to completely reset the game
*/
typedef struct {
bool gameRunning;
int score;
int prebonusscore;
int health;
int currentWeapon;
int currentLevel;
int nextLevel;
SSDLevelStats_t levelStats;
} SSDGameStats_t;
class idGameSSDWindow : public idWindow {
public:
idGameSSDWindow(idUserInterfaceLocal *gui);
idGameSSDWindow(idDeviceContext *d, idUserInterfaceLocal *gui);
~idGameSSDWindow();
virtual void WriteToSaveGame( idFile *savefile );
virtual void ReadFromSaveGame( idFile *savefile );
virtual const char* HandleEvent(const sysEvent_t *event, bool *updateVisuals);
virtual idWinVar* GetWinVarByName (const char *_name, bool winLookup = false, drawWin_t** owner = NULL);
virtual void Draw(int time, float x, float y);
void AddHealth(int health);
void AddScore(SSDEntity* ent, int points);
void AddDamage(int damage);
void OnNuke();
void OnRescueAll();
void OnSuperBlaster();
SSDEntity* GetSpecificEntity(int type, int id);
void PlaySound(const char* sound);
static idRandom random;
int ssdTime;
private:
//Initialization
virtual bool ParseInternalVar(const char *name, idParser *src);
void ParseLevelData(int level, const idStr& levelDataString);
void ParseAsteroidData(int level, const idStr& asteroidDataString);
void ParseWeaponData(int weapon, const idStr& weaponDataString);
void ParseAstronautData(int level, const idStr& astronautDataString);
void ParsePowerupData(int level, const idStr& powerupDataString);
void CommonInit();
void ResetGameStats();
void ResetLevelStats();
void ResetEntities();
//Game Running Methods
void StartGame();
void StopGame();
void GameOver();
//Starting the Game
void BeginLevel(int level);
void ContinueGame();
//Stopping the Game
void LevelComplete();
void GameComplete();
void UpdateGame();
void CheckForHits();
void ZOrderEntities();
void SpawnAsteroid();
void FireWeapon(int key);
SSDEntity* EntityHitTest(const idVec2& pt);
void HitAsteroid(SSDAsteroid* asteroid, int key);
void AsteroidStruckPlayer(SSDAsteroid* asteroid);
void RefreshGuiData();
idVec2 GetCursorWorld();
//Astronaut Methods
void SpawnAstronaut();
void HitAstronaut(SSDAstronaut* astronaut, int key);
void AstronautStruckPlayer(SSDAstronaut* astronaut);
//Powerup Methods
void SpawnPowerup();
void StartSuperBlaster();
void StopSuperBlaster();
//void FreeSoundEmitter( bool immediate );
public:
//WinVars used to call functions from the guis
idWinBool beginLevel;
idWinBool resetGame;
idWinBool continueGame;
idWinBool refreshGuiData;
SSDCrossHair crosshair;
idBounds screenBounds;
//Level Data
int levelCount;
idList<SSDLevelData_t> levelData;
idList<SSDAsteroidData_t> asteroidData;
idList<SSDAstronautData_t> astronautData;
idList<SSDPowerupData_t> powerupData;
//Weapon Data
int weaponCount;
idList<SSDWeaponData_t> weaponData;
int superBlasterTimeout;
//All current game data is stored in this structure (except the entity list)
SSDGameStats_t gameStats;
idList<SSDEntity*> entities;
int currentSound;
};
#endif //__GAME_SSD_WINDOW_H__

52
neo/ui/GameWindow.cpp Normal file
View File

@@ -0,0 +1,52 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "DeviceContext.h"
#include "Window.h"
#include "UserInterfaceLocal.h"
#include "GameWindow.h"
/*
================
idGameWindowProxy::idGameWindowProxy
================
*/
idGameWindowProxy::idGameWindowProxy( idDeviceContext *d, idUserInterfaceLocal *g ) : idWindow( d, g ) { }
/*
================
idGameWindowProxy::Draw
================
*/
void idGameWindowProxy::Draw( int time, float x, float y ) {
common->Printf( "TODO: idGameWindowProxy::Draw\n" );
}

38
neo/ui/GameWindow.h Normal file
View File

@@ -0,0 +1,38 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __GAMEWINDOW_H__
#define __GAMEWINDOW_H__
class idGameWindowProxy : public idWindow {
public:
idGameWindowProxy( idDeviceContext *d, idUserInterfaceLocal *gui );
void Draw( int time, float x, float y );
};
#endif

625
neo/ui/GuiScript.cpp Normal file
View File

@@ -0,0 +1,625 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "Window.h"
#include "Winvar.h"
#include "GuiScript.h"
#include "UserInterfaceLocal.h"
/*
=========================
Script_Set
=========================
*/
void Script_Set(idWindow *window, idList<idGSWinVar> *src) {
idStr key, val;
idWinStr *dest = dynamic_cast<idWinStr*>((*src)[0].var);
if (dest) {
if (idStr::Icmp(*dest, "cmd") == 0) {
dest = dynamic_cast<idWinStr*>((*src)[1].var);
int parmCount = src->Num();
if (parmCount > 2) {
val = dest->c_str();
int i = 2;
while (i < parmCount) {
val += " \"";
val += (*src)[i].var->c_str();
val += "\"";
i++;
}
window->AddCommand(val);
} else {
window->AddCommand(*dest);
}
return;
}
}
(*src)[0].var->Set((*src)[1].var->c_str());
(*src)[0].var->SetEval(false);
}
/*
=========================
Script_SetFocus
=========================
*/
void Script_SetFocus(idWindow *window, idList<idGSWinVar> *src) {
idWinStr *parm = dynamic_cast<idWinStr*>((*src)[0].var);
if (parm) {
drawWin_t *win = window->GetGui()->GetDesktop()->FindChildByName(*parm);
if (win && win->win) {
window->SetFocus(win->win);
}
}
}
/*
=========================
Script_ShowCursor
=========================
*/
void Script_ShowCursor(idWindow *window, idList<idGSWinVar> *src) {
idWinStr *parm = dynamic_cast<idWinStr*>((*src)[0].var);
if ( parm ) {
if ( atoi( *parm ) ) {
window->GetGui()->GetDesktop()->ClearFlag( WIN_NOCURSOR );
} else {
window->GetGui()->GetDesktop()->SetFlag( WIN_NOCURSOR );
}
}
}
/*
=========================
Script_RunScript
run scripts must come after any set cmd set's in the script
=========================
*/
void Script_RunScript(idWindow *window, idList<idGSWinVar> *src) {
idWinStr *parm = dynamic_cast<idWinStr*>((*src)[0].var);
if (parm) {
idStr str = window->cmd;
str += " ; runScript ";
str += parm->c_str();
window->cmd = str;
}
}
/*
=========================
Script_LocalSound
=========================
*/
void Script_LocalSound(idWindow *window, idList<idGSWinVar> *src) {
idWinStr *parm = dynamic_cast<idWinStr*>((*src)[0].var);
if (parm) {
session->sw->PlayShaderDirectly(*parm);
}
}
/*
=========================
Script_EvalRegs
=========================
*/
void Script_EvalRegs(idWindow *window, idList<idGSWinVar> *src) {
window->EvalRegs(-1, true);
}
/*
=========================
Script_EndGame
=========================
*/
void Script_EndGame( idWindow *window, idList<idGSWinVar> *src ) {
cvarSystem->SetCVarBool( "g_nightmare", true );
cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "disconnect\n" );
}
/*
=========================
Script_ResetTime
=========================
*/
void Script_ResetTime(idWindow *window, idList<idGSWinVar> *src) {
idWinStr *parm = dynamic_cast<idWinStr*>((*src)[0].var);
drawWin_t *win = NULL;
if (parm && src->Num() > 1) {
win = window->GetGui()->GetDesktop()->FindChildByName(*parm);
parm = dynamic_cast<idWinStr*>((*src)[1].var);
}
if (win && win->win) {
win->win->ResetTime(atoi(*parm));
win->win->EvalRegs(-1, true);
} else {
window->ResetTime(atoi(*parm));
window->EvalRegs(-1, true);
}
}
/*
=========================
Script_ResetCinematics
=========================
*/
void Script_ResetCinematics(idWindow *window, idList<idGSWinVar> *src) {
window->ResetCinematics();
}
/*
=========================
Script_Transition
=========================
*/
void Script_Transition(idWindow *window, idList<idGSWinVar> *src) {
// transitions always affect rect or vec4 vars
if (src->Num() >= 4) {
idWinRectangle *rect = NULL;
idWinVec4 *vec4 = dynamic_cast<idWinVec4*>((*src)[0].var);
//
// added float variable
idWinFloat* val = NULL;
//
if (vec4 == NULL) {
rect = dynamic_cast<idWinRectangle*>((*src)[0].var);
//
// added float variable
if ( NULL == rect ) {
val = dynamic_cast<idWinFloat*>((*src)[0].var);
}
//
}
idWinVec4 *from = dynamic_cast<idWinVec4*>((*src)[1].var);
idWinVec4 *to = dynamic_cast<idWinVec4*>((*src)[2].var);
idWinStr *timeStr = dynamic_cast<idWinStr*>((*src)[3].var);
//
// added float variable
if (!((vec4 || rect || val) && from && to && timeStr)) {
//
common->Warning("Bad transition in gui %s in window %s\n", window->GetGui()->GetSourceFile(), window->GetName());
return;
}
int time = atoi(*timeStr);
float ac = 0.0f;
float dc = 0.0f;
if (src->Num() > 4) {
idWinStr *acv = dynamic_cast<idWinStr*>((*src)[4].var);
idWinStr *dcv = dynamic_cast<idWinStr*>((*src)[5].var);
assert(acv && dcv);
ac = atof(*acv);
dc = atof(*dcv);
}
if (vec4) {
vec4->SetEval(false);
window->AddTransition(vec4, *from, *to, time, ac, dc);
//
// added float variable
} else if ( val ) {
val->SetEval ( false );
window->AddTransition(val, *from, *to, time, ac, dc);
//
} else {
rect->SetEval(false);
window->AddTransition(rect, *from, *to, time, ac, dc);
}
window->StartTransition();
}
}
typedef struct {
const char *name;
void (*handler) (idWindow *window, idList<idGSWinVar> *src);
int mMinParms;
int mMaxParms;
} guiCommandDef_t;
guiCommandDef_t commandList[] = {
{ "set", Script_Set, 2, 999 },
{ "setFocus", Script_SetFocus, 1, 1 },
{ "endGame", Script_EndGame, 0, 0 },
{ "resetTime", Script_ResetTime, 0, 2 },
{ "showCursor", Script_ShowCursor, 1, 1 },
{ "resetCinematics", Script_ResetCinematics, 0, 2 },
{ "transition", Script_Transition, 4, 6 },
{ "localSound", Script_LocalSound, 1, 1 },
{ "runScript", Script_RunScript, 1, 1 },
{ "evalRegs", Script_EvalRegs, 0, 0 }
};
int scriptCommandCount = sizeof(commandList) / sizeof(guiCommandDef_t);
/*
=========================
idGuiScript::idGuiScript
=========================
*/
idGuiScript::idGuiScript() {
ifList = NULL;
elseList = NULL;
conditionReg = -1;
handler = NULL;
parms.SetGranularity( 2 );
}
/*
=========================
idGuiScript::~idGuiScript
=========================
*/
idGuiScript::~idGuiScript() {
delete ifList;
delete elseList;
int c = parms.Num();
for ( int i = 0; i < c; i++ ) {
if ( parms[i].own ) {
delete parms[i].var;
}
}
}
/*
=========================
idGuiScript::WriteToSaveGame
=========================
*/
void idGuiScript::WriteToSaveGame( idFile *savefile ) {
int i;
if ( ifList ) {
ifList->WriteToSaveGame( savefile );
}
if ( elseList ) {
elseList->WriteToSaveGame( savefile );
}
savefile->Write( &conditionReg, sizeof( conditionReg ) );
for ( i = 0; i < parms.Num(); i++ ) {
if ( parms[i].own ) {
parms[i].var->WriteToSaveGame( savefile );
}
}
}
/*
=========================
idGuiScript::ReadFromSaveGame
=========================
*/
void idGuiScript::ReadFromSaveGame( idFile *savefile ) {
int i;
if ( ifList ) {
ifList->ReadFromSaveGame( savefile );
}
if ( elseList ) {
elseList->ReadFromSaveGame( savefile );
}
savefile->Read( &conditionReg, sizeof( conditionReg ) );
for ( i = 0; i < parms.Num(); i++ ) {
if ( parms[i].own ) {
parms[i].var->ReadFromSaveGame( savefile );
}
}
}
/*
=========================
idGuiScript::Parse
=========================
*/
bool idGuiScript::Parse(idParser *src) {
int i;
// first token should be function call
// then a potentially variable set of parms
// ended with a ;
idToken token;
if ( !src->ReadToken(&token) ) {
src->Error( "Unexpected end of file" );
return false;
}
handler = NULL;
for ( i = 0; i < scriptCommandCount ; i++ ) {
if ( idStr::Icmp(token, commandList[i].name) == 0 ) {
handler = commandList[i].handler;
break;
}
}
if (handler == NULL) {
src->Error("Uknown script call %s", token.c_str());
}
// now read parms til ;
// all parms are read as idWinStr's but will be fixed up later
// to be proper types
while (1) {
if ( !src->ReadToken(&token) ) {
src->Error( "Unexpected end of file" );
return false;
}
if (idStr::Icmp(token, ";") == 0) {
break;
}
if (idStr::Icmp(token, "}") == 0) {
src->UnreadToken(&token);
break;
}
idWinStr *str = new idWinStr();
*str = token;
idGSWinVar wv;
wv.own = true;
wv.var = str;
parms.Append( wv );
}
//
// verify min/max params
if ( handler && (parms.Num() < commandList[i].mMinParms || parms.Num() > commandList[i].mMaxParms ) ) {
src->Error("incorrect number of parameters for script %s", commandList[i].name );
}
//
return true;
}
/*
=========================
idGuiScriptList::Execute
=========================
*/
void idGuiScriptList::Execute(idWindow *win) {
int c = list.Num();
for (int i = 0; i < c; i++) {
idGuiScript *gs = list[i];
assert(gs);
if (gs->conditionReg >= 0) {
if (win->HasOps()) {
float f = win->EvalRegs(gs->conditionReg);
if (f) {
if (gs->ifList) {
win->RunScriptList(gs->ifList);
}
} else if (gs->elseList) {
win->RunScriptList(gs->elseList);
}
}
}
gs->Execute(win);
}
}
/*
=========================
idGuiScriptList::FixupParms
=========================
*/
void idGuiScript::FixupParms(idWindow *win) {
if (handler == &Script_Set) {
bool precacheBackground = false;
bool precacheSounds = false;
idWinStr *str = dynamic_cast<idWinStr*>(parms[0].var);
assert(str);
idWinVar *dest = win->GetWinVarByName(*str, true);
if (dest) {
delete parms[0].var;
parms[0].var = dest;
parms[0].own = false;
if ( dynamic_cast<idWinBackground *>(dest) != NULL ) {
precacheBackground = true;
}
} else if ( idStr::Icmp( str->c_str(), "cmd" ) == 0 ) {
precacheSounds = true;
}
int parmCount = parms.Num();
for (int i = 1; i < parmCount; i++) {
idWinStr *str = dynamic_cast<idWinStr*>(parms[i].var);
if (idStr::Icmpn(*str, "gui::", 5) == 0) {
// always use a string here, no point using a float if it is one
// FIXME: This creates duplicate variables, while not technically a problem since they
// are all bound to the same guiDict, it does consume extra memory and is generally a bad thing
idWinStr* defvar = new idWinStr();
defvar->Init ( *str, win );
win->AddDefinedVar ( defvar );
delete parms[i].var;
parms[i].var = defvar;
parms[i].own = false;
//dest = win->GetWinVarByName(*str, true);
//if (dest) {
// delete parms[i].var;
// parms[i].var = dest;
// parms[i].own = false;
//}
//
} else if ((*str[0]) == '$') {
//
// dont include the $ when asking for variable
dest = win->GetGui()->GetDesktop()->GetWinVarByName((const char*)(*str) + 1, true);
//
if (dest) {
delete parms[i].var;
parms[i].var = dest;
parms[i].own = false;
}
} else if ( idStr::Cmpn( str->c_str(), STRTABLE_ID, STRTABLE_ID_LENGTH ) == 0 ) {
str->Set( common->GetLanguageDict()->GetString( str->c_str() ) );
} else if ( precacheBackground ) {
const idMaterial *mat = declManager->FindMaterial( str->c_str() );
mat->SetSort( SS_GUI );
} else if ( precacheSounds ) {
// Search for "play <...>"
idToken token;
idParser parser( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT );
parser.LoadMemory(str->c_str(), str->Length(), "command");
while ( parser.ReadToken(&token) ) {
if ( token.Icmp("play") == 0 ) {
if ( parser.ReadToken(&token) && ( token != "" ) ) {
declManager->FindSound( token.c_str() );
}
}
}
}
}
} else if (handler == &Script_Transition) {
if (parms.Num() < 4) {
common->Warning("Window %s in gui %s has a bad transition definition", win->GetName(), win->GetGui()->GetSourceFile());
}
idWinStr *str = dynamic_cast<idWinStr*>(parms[0].var);
assert(str);
//
drawWin_t *destowner;
idWinVar *dest = win->GetWinVarByName(*str, true, &destowner );
//
if (dest) {
delete parms[0].var;
parms[0].var = dest;
parms[0].own = false;
} else {
common->Warning("Window %s in gui %s: a transition does not have a valid destination var %s", win->GetName(), win->GetGui()->GetSourceFile(),str->c_str());
}
//
// support variables as parameters
int c;
for ( c = 1; c < 3; c ++ ) {
str = dynamic_cast<idWinStr*>(parms[c].var);
idWinVec4 *v4 = new idWinVec4;
parms[c].var = v4;
parms[c].own = true;
drawWin_t* owner;
if ( (*str[0]) == '$' ) {
dest = win->GetWinVarByName ( (const char*)(*str) + 1, true, &owner );
} else {
dest = NULL;
}
if ( dest ) {
idWindow* ownerparent;
idWindow* destparent;
if ( owner ) {
ownerparent = owner->simp?owner->simp->GetParent():owner->win->GetParent();
destparent = destowner->simp?destowner->simp->GetParent():destowner->win->GetParent();
// If its the rectangle they are referencing then adjust it
if ( ownerparent && destparent &&
(dest == (owner->simp?owner->simp->GetWinVarByName ( "rect" ):owner->win->GetWinVarByName ( "rect" ) ) ) )
{
idRectangle rect;
rect = *(dynamic_cast<idWinRectangle*>(dest));
ownerparent->ClientToScreen ( &rect );
destparent->ScreenToClient ( &rect );
*v4 = rect.ToVec4 ( );
} else {
v4->Set ( dest->c_str ( ) );
}
} else {
v4->Set ( dest->c_str ( ) );
}
} else {
v4->Set(*str);
}
delete str;
}
//
} else {
int c = parms.Num();
for (int i = 0; i < c; i++) {
parms[i].var->Init(parms[i].var->c_str(), win);
}
}
}
/*
=========================
idGuiScriptList::FixupParms
=========================
*/
void idGuiScriptList::FixupParms(idWindow *win) {
int c = list.Num();
for (int i = 0; i < c; i++) {
idGuiScript *gs = list[i];
gs->FixupParms(win);
if (gs->ifList) {
gs->ifList->FixupParms(win);
}
if (gs->elseList) {
gs->elseList->FixupParms(win);
}
}
}
/*
=========================
idGuiScriptList::WriteToSaveGame
=========================
*/
void idGuiScriptList::WriteToSaveGame( idFile *savefile ) {
int i;
for ( i = 0; i < list.Num(); i++ ) {
list[i]->WriteToSaveGame( savefile );
}
}
/*
=========================
idGuiScriptList::ReadFromSaveGame
=========================
*/
void idGuiScriptList::ReadFromSaveGame( idFile *savefile ) {
int i;
for ( i = 0; i < list.Num(); i++ ) {
list[i]->ReadFromSaveGame( savefile );
}
}

105
neo/ui/GuiScript.h Normal file
View File

@@ -0,0 +1,105 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __GUISCRIPT_H
#define __GUISCRIPT_H
#include "Window.h"
#include "Winvar.h"
struct idGSWinVar {
idGSWinVar() {
var = NULL;
own = false;
}
idWinVar* var;
bool own;
};
class idGuiScriptList;
class idGuiScript {
friend class idGuiScriptList;
friend class idWindow;
public:
idGuiScript();
~idGuiScript();
bool Parse(idParser *src);
void Execute(idWindow *win) {
if (handler) {
handler(win, &parms);
}
}
void FixupParms(idWindow *win);
size_t Size() {
int sz = sizeof(*this);
for (int i = 0; i < parms.Num(); i++) {
sz += parms[i].var->Size();
}
return sz;
}
void WriteToSaveGame( idFile *savefile );
void ReadFromSaveGame( idFile *savefile );
protected:
int conditionReg;
idGuiScriptList *ifList;
idGuiScriptList *elseList;
idList<idGSWinVar> parms;
void (*handler) (idWindow *window, idList<idGSWinVar> *src);
};
class idGuiScriptList {
idList<idGuiScript*> list;
public:
idGuiScriptList() { list.SetGranularity( 4 ); };
~idGuiScriptList() { list.DeleteContents(true); };
void Execute(idWindow *win);
void Append(idGuiScript* gs) {
list.Append(gs);
}
size_t Size() {
int sz = sizeof(*this);
for (int i = 0; i < list.Num(); i++) {
sz += list[i]->Size();
}
return sz;
}
void FixupParms(idWindow *win);
void ReadFromDemoFile( class idDemoFile *f ) {};
void WriteToDemoFile( class idDemoFile *f ) {};
void WriteToSaveGame( idFile *savefile );
void ReadFromSaveGame( idFile *savefile );
};
#endif // __GUISCRIPT_H

184
neo/ui/ListGUI.cpp Normal file
View File

@@ -0,0 +1,184 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "ListGUILocal.h"
/*
====================
idListGUILocal::StateChanged
====================
*/
void idListGUILocal::StateChanged() {
int i;
if ( !m_stateUpdates ) {
return;
}
for( i = 0; i < Num(); i++ ) {
m_pGUI->SetStateString( va( "%s_item_%i", m_name.c_str(), i ), (*this)[i].c_str() );
}
for( i = Num() ; i < m_water ; i++ ) {
m_pGUI->SetStateString( va( "%s_item_%i", m_name.c_str(), i ), "" );
}
m_water = Num();
m_pGUI->StateChanged( com_frameTime );
}
/*
====================
idListGUILocal::GetNumSelections
====================
*/
int idListGUILocal::GetNumSelections() {
return m_pGUI->State().GetInt( va( "%s_numsel", m_name.c_str() ) );
}
/*
====================
idListGUILocal::GetSelection
====================
*/
int idListGUILocal::GetSelection( char *s, int size, int _sel ) const {
if ( s ) {
s[ 0 ] = '\0';
}
int sel = m_pGUI->State().GetInt( va( "%s_sel_%i", m_name.c_str(), _sel ), "-1" );
if ( sel == -1 || sel >= m_ids.Num() ) {
return -1;
}
if ( s ) {
idStr::snPrintf( s, size, m_pGUI->State().GetString( va( "%s_item_%i", m_name.c_str(), sel ), "" ) );
}
// don't let overflow
if ( sel >= m_ids.Num() ) {
sel = 0;
}
m_pGUI->SetStateInt( va( "%s_selid_0", m_name.c_str() ), m_ids[ sel ] );
return m_ids[ sel ];
}
/*
====================
idListGUILocal::SetSelection
====================
*/
void idListGUILocal::SetSelection( int sel ) {
m_pGUI->SetStateInt( va( "%s_sel_0", m_name.c_str() ), sel );
StateChanged();
}
/*
====================
idListGUILocal::Add
====================
*/
void idListGUILocal::Add( int id, const idStr &s ) {
int i = m_ids.FindIndex( id );
if ( i == -1 ) {
Append( s );
m_ids.Append( id );
} else {
(*this)[ i ] = s;
}
StateChanged();
}
/*
====================
idListGUILocal::Push
====================
*/
void idListGUILocal::Push( const idStr& s ) {
Append( s );
m_ids.Append( m_ids.Num() );
StateChanged();
}
/*
====================
idListGUILocal::Del
====================
*/
bool idListGUILocal::Del(int id) {
int i = m_ids.FindIndex(id);
if ( i == -1 ) {
return false;
}
m_ids.RemoveIndex( i );
this->RemoveIndex( i );
StateChanged();
return true;
}
/*
====================
idListGUILocal::Clear
====================
*/
void idListGUILocal::Clear() {
m_ids.Clear();
idList<idStr>::Clear();
if ( m_pGUI ) {
// will clear all the GUI variables and will set m_water back to 0
StateChanged();
}
}
/*
====================
idListGUILocal::IsConfigured
====================
*/
bool idListGUILocal::IsConfigured( void ) const {
return m_pGUI != NULL;
}
/*
====================
idListGUILocal::SetStateChanges
====================
*/
void idListGUILocal::SetStateChanges( bool enable ) {
m_stateUpdates = enable;
StateChanged();
}
/*
====================
idListGUILocal::Shutdown
====================
*/
void idListGUILocal::Shutdown( void ) {
m_pGUI = NULL;
m_name.Clear();
Clear();
}

61
neo/ui/ListGUI.h Normal file
View File

@@ -0,0 +1,61 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __LISTGUI_H__
#define __LISTGUI_H__
/*
===============================================================================
feed data to a listDef
each item has an id and a display string
===============================================================================
*/
class idListGUI {
public:
virtual ~idListGUI() { }
virtual void Config( idUserInterface *pGUI, const char *name ) = 0;
virtual void Add( int id, const idStr& s ) = 0;
// use the element count as index for the ids
virtual void Push( const idStr& s ) = 0;
virtual bool Del( int id ) = 0;
virtual void Clear( void ) = 0;
virtual int Num( void ) = 0;
virtual int GetSelection( char *s, int size, int sel = 0 ) const = 0; // returns the id, not the list index (or -1)
virtual void SetSelection( int sel ) = 0;
virtual int GetNumSelections() = 0;
virtual bool IsConfigured( void ) const = 0;
// by default, any modification to the list will trigger a full GUI refresh immediately
virtual void SetStateChanges( bool enable ) = 0;
virtual void Shutdown( void ) = 0;
};
#endif /* !__LISTGUI_H__ */

70
neo/ui/ListGUILocal.h Normal file
View File

@@ -0,0 +1,70 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __LISTGUILOCAL_H__
#define __LISTGUILOCAL_H__
/*
===============================================================================
feed data to a listDef
each item has an id and a display string
===============================================================================
*/
class idListGUILocal : protected idList<idStr>, public idListGUI {
public:
idListGUILocal() { m_pGUI = NULL; m_water = 0; m_stateUpdates = true; }
// idListGUI interface
void Config( idUserInterface *pGUI, const char *name ) { m_pGUI = pGUI; m_name = name; }
void Add( int id, const idStr& s );
// use the element count as index for the ids
void Push( const idStr& s );
bool Del( int id );
void Clear( void );
int Num( void ) { return idList<idStr>::Num(); }
int GetSelection( char *s, int size, int sel = 0 ) const; // returns the id, not the list index (or -1)
void SetSelection( int sel );
int GetNumSelections();
bool IsConfigured( void ) const;
void SetStateChanges( bool enable );
void Shutdown( void );
private:
idUserInterface * m_pGUI;
idStr m_name;
int m_water;
idList<int> m_ids;
bool m_stateUpdates;
void StateChanged();
};
#endif /* !__LISTGUILOCAL_H__ */

630
neo/ui/ListWindow.cpp Normal file
View File

@@ -0,0 +1,630 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "../framework/Session_local.h"
#include "DeviceContext.h"
#include "Window.h"
#include "UserInterfaceLocal.h"
#include "SliderWindow.h"
#include "ListWindow.h"
// Number of pixels above the text that the rect starts
static const int pixelOffset = 3;
// number of pixels between columns
static const int tabBorder = 4;
// Time in milliseconds between clicks to register as a double-click
static const int doubleClickSpeed = 300;
void idListWindow::CommonInit() {
typed = "";
typedTime = 0;
clickTime = 0;
currentSel.Clear();
top = 0;
sizeBias = 0;
horizontal = false;
scroller = new idSliderWindow(dc, gui);
multipleSel = false;
}
idListWindow::idListWindow(idDeviceContext *d, idUserInterfaceLocal *g) : idWindow(d, g) {
dc = d;
gui = g;
CommonInit();
}
idListWindow::idListWindow(idUserInterfaceLocal *g) : idWindow(g) {
gui = g;
CommonInit();
}
void idListWindow::SetCurrentSel( int sel ) {
currentSel.Clear();
currentSel.Append( sel );
}
void idListWindow::ClearSelection( int sel ) {
int cur = currentSel.FindIndex( sel );
if ( cur >= 0 ) {
currentSel.RemoveIndex( cur );
}
}
void idListWindow::AddCurrentSel( int sel ) {
currentSel.Append( sel );
}
int idListWindow::GetCurrentSel() {
return ( currentSel.Num() ) ? currentSel[0] : 0;
}
bool idListWindow::IsSelected( int index ) {
return ( currentSel.FindIndex( index ) >= 0 );
}
const char *idListWindow::HandleEvent(const sysEvent_t *event, bool *updateVisuals) {
// need to call this to allow proper focus and capturing on embedded children
const char *ret = idWindow::HandleEvent(event, updateVisuals);
float vert = GetMaxCharHeight();
int numVisibleLines = textRect.h / vert;
int key = event->evValue;
if ( event->evType == SE_KEY ) {
if ( !event->evValue2 ) {
// We only care about key down, not up
return ret;
}
if ( key == K_MOUSE1 || key == K_MOUSE2 ) {
// If the user clicked in the scroller, then ignore it
if ( scroller->Contains(gui->CursorX(), gui->CursorY()) ) {
return ret;
}
}
if ( ( key == K_ENTER || key == K_KP_ENTER ) ) {
RunScript( ON_ENTER );
return cmd;
}
if ( key == K_MWHEELUP ) {
key = K_UPARROW;
} else if ( key == K_MWHEELDOWN ) {
key = K_DOWNARROW;
}
if ( key == K_MOUSE1) {
if (Contains(gui->CursorX(), gui->CursorY())) {
int cur = ( int )( ( gui->CursorY() - actualY - pixelOffset ) / vert ) + top;
if ( cur >= 0 && cur < listItems.Num() ) {
if ( multipleSel && idKeyInput::IsDown( K_CTRL ) ) {
if ( IsSelected( cur ) ) {
ClearSelection( cur );
} else {
AddCurrentSel( cur );
}
} else {
if ( IsSelected( cur ) && ( gui->GetTime() < clickTime + doubleClickSpeed ) ) {
// Double-click causes ON_ENTER to get run
RunScript(ON_ENTER);
return cmd;
}
SetCurrentSel( cur );
clickTime = gui->GetTime();
}
} else {
SetCurrentSel( listItems.Num() - 1 );
}
}
} else if ( key == K_UPARROW || key == K_PGUP || key == K_DOWNARROW || key == K_PGDN ) {
int numLines = 1;
if ( key == K_PGUP || key == K_PGDN ) {
numLines = numVisibleLines / 2;
}
if ( key == K_UPARROW || key == K_PGUP ) {
numLines = -numLines;
}
if ( idKeyInput::IsDown( K_CTRL ) ) {
top += numLines;
} else {
SetCurrentSel( GetCurrentSel() + numLines );
}
} else {
return ret;
}
} else if ( event->evType == SE_CHAR ) {
if ( !idStr::CharIsPrintable(key) ) {
return ret;
}
if ( gui->GetTime() > typedTime + 1000 ) {
typed = "";
}
typedTime = gui->GetTime();
typed.Append( key );
for ( int i=0; i<listItems.Num(); i++ ) {
if ( idStr::Icmpn( typed, listItems[i], typed.Length() ) == 0 ) {
SetCurrentSel( i );
break;
}
}
} else {
return ret;
}
if ( GetCurrentSel() < 0 ) {
SetCurrentSel( 0 );
}
if ( GetCurrentSel() >= listItems.Num() ) {
SetCurrentSel( listItems.Num() - 1 );
}
if ( scroller->GetHigh() > 0.0f ) {
if ( !idKeyInput::IsDown( K_CTRL ) ) {
if ( top > GetCurrentSel() - 1 ) {
top = GetCurrentSel() - 1;
}
if ( top < GetCurrentSel() - numVisibleLines + 2 ) {
top = GetCurrentSel() - numVisibleLines + 2;
}
}
if ( top > listItems.Num() - 2 ) {
top = listItems.Num() - 2;
}
if ( top < 0 ) {
top = 0;
}
scroller->SetValue(top);
} else {
top = 0;
scroller->SetValue(0.0f);
}
if ( key != K_MOUSE1 ) {
// Send a fake mouse click event so onAction gets run in our parents
const sysEvent_t ev = sys->GenerateMouseButtonEvent( 1, true );
idWindow::HandleEvent(&ev, updateVisuals);
}
if ( currentSel.Num() > 0 ) {
for ( int i = 0; i < currentSel.Num(); i++ ) {
gui->SetStateInt( va( "%s_sel_%i", listName.c_str(), i ), currentSel[i] );
}
} else {
gui->SetStateInt( va( "%s_sel_0", listName.c_str() ), 0 );
}
gui->SetStateInt( va( "%s_numsel", listName.c_str() ), currentSel.Num() );
return ret;
}
bool idListWindow::ParseInternalVar(const char *_name, idParser *src) {
if (idStr::Icmp(_name, "horizontal") == 0) {
horizontal = src->ParseBool();
return true;
}
if (idStr::Icmp(_name, "listname") == 0) {
ParseString(src, listName);
return true;
}
if (idStr::Icmp(_name, "tabstops") == 0) {
ParseString(src, tabStopStr);
return true;
}
if (idStr::Icmp(_name, "tabaligns") == 0) {
ParseString(src, tabAlignStr);
return true;
}
if (idStr::Icmp(_name, "multipleSel") == 0) {
multipleSel = src->ParseBool();
return true;
}
if(idStr::Icmp(_name, "tabvaligns") == 0) {
ParseString(src, tabVAlignStr);
return true;
}
if(idStr::Icmp(_name, "tabTypes") == 0) {
ParseString(src, tabTypeStr);
return true;
}
if(idStr::Icmp(_name, "tabIconSizes") == 0) {
ParseString(src, tabIconSizeStr);
return true;
}
if(idStr::Icmp(_name, "tabIconVOffset") == 0) {
ParseString(src, tabIconVOffsetStr);
return true;
}
idStr strName = _name;
if(idStr::Icmp(strName.Left(4), "mtr_") == 0) {
idStr matName;
const idMaterial* mat;
ParseString(src, matName);
mat = declManager->FindMaterial(matName);
mat->SetImageClassifications( 1 ); // just for resource tracking
if ( mat && !mat->TestMaterialFlag( MF_DEFAULTED ) ) {
mat->SetSort(SS_GUI );
}
iconMaterials.Set(_name, mat);
return true;
}
return idWindow::ParseInternalVar(_name, src);
}
idWinVar *idListWindow::GetWinVarByName(const char *_name, bool fixup, drawWin_t** owner) {
return idWindow::GetWinVarByName(_name, fixup, owner);
}
void idListWindow::PostParse() {
idWindow::PostParse();
InitScroller(horizontal);
idList<int> tabStops;
idList<int> tabAligns;
if (tabStopStr.Length()) {
idParser src(tabStopStr, tabStopStr.Length(), "tabstops", LEXFL_NOFATALERRORS | LEXFL_NOSTRINGCONCAT | LEXFL_NOSTRINGESCAPECHARS);
idToken tok;
while (src.ReadToken(&tok)) {
if (tok == ",") {
continue;
}
tabStops.Append(atoi(tok));
}
}
if (tabAlignStr.Length()) {
idParser src(tabAlignStr, tabAlignStr.Length(), "tabaligns", LEXFL_NOFATALERRORS | LEXFL_NOSTRINGCONCAT | LEXFL_NOSTRINGESCAPECHARS);
idToken tok;
while (src.ReadToken(&tok)) {
if (tok == ",") {
continue;
}
tabAligns.Append(atoi(tok));
}
}
idList<int> tabVAligns;
if (tabVAlignStr.Length()) {
idParser src(tabVAlignStr, tabVAlignStr.Length(), "tabvaligns", LEXFL_NOFATALERRORS | LEXFL_NOSTRINGCONCAT | LEXFL_NOSTRINGESCAPECHARS);
idToken tok;
while (src.ReadToken(&tok)) {
if (tok == ",") {
continue;
}
tabVAligns.Append(atoi(tok));
}
}
idList<int> tabTypes;
if (tabTypeStr.Length()) {
idParser src(tabTypeStr, tabTypeStr.Length(), "tabtypes", LEXFL_NOFATALERRORS | LEXFL_NOSTRINGCONCAT | LEXFL_NOSTRINGESCAPECHARS);
idToken tok;
while (src.ReadToken(&tok)) {
if (tok == ",") {
continue;
}
tabTypes.Append(atoi(tok));
}
}
idList<idVec2> tabSizes;
if (tabIconSizeStr.Length()) {
idParser src(tabIconSizeStr, tabIconSizeStr.Length(), "tabiconsizes", LEXFL_NOFATALERRORS | LEXFL_NOSTRINGCONCAT | LEXFL_NOSTRINGESCAPECHARS);
idToken tok;
while (src.ReadToken(&tok)) {
if (tok == ",") {
continue;
}
idVec2 size;
size.x = atoi(tok);
src.ReadToken(&tok); //","
src.ReadToken(&tok);
size.y = atoi(tok);
tabSizes.Append(size);
}
}
idList<float> tabIconVOffsets;
if (tabIconVOffsetStr.Length()) {
idParser src(tabIconVOffsetStr, tabIconVOffsetStr.Length(), "tabiconvoffsets", LEXFL_NOFATALERRORS | LEXFL_NOSTRINGCONCAT | LEXFL_NOSTRINGESCAPECHARS);
idToken tok;
while (src.ReadToken(&tok)) {
if (tok == ",") {
continue;
}
tabIconVOffsets.Append(atof(tok));
}
}
int c = tabStops.Num();
bool doAligns = (tabAligns.Num() == tabStops.Num());
for (int i = 0; i < c; i++) {
idTabRect r;
r.x = tabStops[i];
r.w = (i < c - 1) ? tabStops[i+1] - r.x - tabBorder : -1;
r.align = (doAligns) ? tabAligns[i] : 0;
if(tabVAligns.Num() > 0) {
r.valign = tabVAligns[i];
} else {
r.valign = 0;
}
if(tabTypes.Num() > 0) {
r.type = tabTypes[i];
} else {
r.type = TAB_TYPE_TEXT;
}
if(tabSizes.Num() > 0) {
r.iconSize = tabSizes[i];
} else {
r.iconSize.Zero();
}
if(tabIconVOffsets.Num() > 0 ) {
r.iconVOffset = tabIconVOffsets[i];
} else {
r.iconVOffset = 0;
}
tabInfo.Append(r);
}
flags |= WIN_CANFOCUS;
}
/*
================
idListWindow::InitScroller
This is the same as in idEditWindow
================
*/
void idListWindow::InitScroller( bool horizontal )
{
const char *thumbImage = "guis/assets/scrollbar_thumb.tga";
const char *barImage = "guis/assets/scrollbarv.tga";
const char *scrollerName = "_scrollerWinV";
if (horizontal) {
barImage = "guis/assets/scrollbarh.tga";
scrollerName = "_scrollerWinH";
}
const idMaterial *mat = declManager->FindMaterial( barImage );
mat->SetSort( SS_GUI );
sizeBias = mat->GetImageWidth();
idRectangle scrollRect;
if (horizontal) {
sizeBias = mat->GetImageHeight();
scrollRect.x = 0;
scrollRect.y = (clientRect.h - sizeBias);
scrollRect.w = clientRect.w;
scrollRect.h = sizeBias;
} else {
scrollRect.x = (clientRect.w - sizeBias);
scrollRect.y = 0;
scrollRect.w = sizeBias;
scrollRect.h = clientRect.h;
}
scroller->InitWithDefaults(scrollerName, scrollRect, foreColor, matColor, mat->GetName(), thumbImage, !horizontal, true);
InsertChild(scroller, NULL);
scroller->SetBuddy(this);
}
void idListWindow::Draw(int time, float x, float y) {
idVec4 color;
idStr work;
int count = listItems.Num();
idRectangle rect = textRect;
float scale = textScale;
float lineHeight = GetMaxCharHeight();
float bottom = textRect.Bottom();
float width = textRect.w;
if ( scroller->GetHigh() > 0.0f ) {
if ( horizontal ) {
bottom -= sizeBias;
} else {
width -= sizeBias;
rect.w = width;
}
}
if ( noEvents || !Contains(gui->CursorX(), gui->CursorY()) ) {
hover = false;
}
for (int i = top; i < count; i++) {
if ( IsSelected( i ) ) {
rect.h = lineHeight;
dc->DrawFilledRect(rect.x, rect.y + pixelOffset, rect.w, rect.h, borderColor);
if ( flags & WIN_FOCUS ) {
idVec4 color = borderColor;
color.w = 1.0f;
dc->DrawRect(rect.x, rect.y + pixelOffset, rect.w, rect.h, 1.0f, color );
}
}
rect.y ++;
rect.h = lineHeight - 1;
if ( hover && !noEvents && Contains(rect, gui->CursorX(), gui->CursorY()) ) {
color = hoverColor;
} else {
color = foreColor;
}
rect.h = lineHeight + pixelOffset;
rect.y --;
if ( tabInfo.Num() > 0 ) {
int start = 0;
int tab = 0;
int stop = listItems[i].Find('\t', 0);
while ( start < listItems[i].Length() ) {
if ( tab >= tabInfo.Num() ) {
common->Warning( "idListWindow::Draw: gui '%s' window '%s' tabInfo.Num() exceeded", gui->GetSourceFile(), name.c_str() );
break;
}
listItems[i].Mid(start, stop - start, work);
rect.x = textRect.x + tabInfo[tab].x;
rect.w = (tabInfo[tab].w == -1) ? width - tabInfo[tab].x : tabInfo[tab].w;
dc->PushClipRect( rect );
if ( tabInfo[tab].type == TAB_TYPE_TEXT ) {
dc->DrawText(work, scale, tabInfo[tab].align, color, rect, false, -1);
} else if (tabInfo[tab].type == TAB_TYPE_ICON) {
const idMaterial **hashMat;
const idMaterial *iconMat;
// leaving the icon name empty doesn't draw anything
if ( work[0] != '\0' ) {
if ( iconMaterials.Get(work, &hashMat) == false ) {
iconMat = declManager->FindMaterial("_default");
} else {
iconMat = *hashMat;
}
idRectangle iconRect;
iconRect.w = tabInfo[tab].iconSize.x;
iconRect.h = tabInfo[tab].iconSize.y;
if(tabInfo[tab].align == idDeviceContext::ALIGN_LEFT) {
iconRect.x = rect.x;
} else if (tabInfo[tab].align == idDeviceContext::ALIGN_CENTER) {
iconRect.x = rect.x + rect.w/2.0f - iconRect.w/2.0f;
} else if (tabInfo[tab].align == idDeviceContext::ALIGN_RIGHT) {
iconRect.x = rect.x + rect.w - iconRect.w;
}
if(tabInfo[tab].valign == 0) { //Top
iconRect.y = rect.y + tabInfo[tab].iconVOffset;
} else if(tabInfo[tab].valign == 1) { //Center
iconRect.y = rect.y + rect.h/2.0f - iconRect.h/2.0f + tabInfo[tab].iconVOffset;
} else if(tabInfo[tab].valign == 2) { //Bottom
iconRect.y = rect.y + rect.h - iconRect.h + tabInfo[tab].iconVOffset;
}
dc->DrawMaterial(iconRect.x, iconRect.y, iconRect.w, iconRect.h, iconMat, idVec4(1.0f,1.0f,1.0f,1.0f), 1.0f, 1.0f);
}
}
dc->PopClipRect();
start = stop + 1;
stop = listItems[i].Find('\t', start);
if ( stop < 0 ) {
stop = listItems[i].Length();
}
tab++;
}
rect.x = textRect.x;
rect.w = width;
} else {
dc->DrawText(listItems[i], scale, 0, color, rect, false, -1);
}
rect.y += lineHeight;
if ( rect.y > bottom ) {
break;
}
}
}
void idListWindow::Activate(bool activate, idStr &act) {
idWindow::Activate(activate, act);
if ( activate ) {
UpdateList();
}
}
void idListWindow::HandleBuddyUpdate(idWindow *buddy) {
top = scroller->GetValue();
}
void idListWindow::UpdateList() {
idStr str, strName;
listItems.Clear();
for (int i = 0; i < MAX_LIST_ITEMS; i++) {
if (gui->State().GetString( va("%s_item_%i", listName.c_str(), i), "", str) ) {
if ( str.Length() ) {
listItems.Append(str);
}
} else {
break;
}
}
float vert = GetMaxCharHeight();
int fit = textRect.h / vert;
if ( listItems.Num() < fit ) {
scroller->SetRange(0.0f, 0.0f, 1.0f);
} else {
scroller->SetRange(0.0f, (listItems.Num() - fit) + 1.0f, 1.0f);
}
SetCurrentSel( gui->State().GetInt( va( "%s_sel_0", listName.c_str() ) ) );
float value = scroller->GetValue();
if ( value > listItems.Num() - 1 ) {
value = listItems.Num() - 1;
}
if ( value < 0.0f ) {
value = 0.0f;
}
scroller->SetValue(value);
top = value;
typedTime = 0;
clickTime = 0;
typed = "";
}
void idListWindow::StateChanged( bool redraw ) {
UpdateList();
}

98
neo/ui/ListWindow.h Normal file
View File

@@ -0,0 +1,98 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __LISTWINDOW_H
#define __LISTWINDOW_H
class idSliderWindow;
enum {
TAB_TYPE_TEXT = 0,
TAB_TYPE_ICON = 1
};
struct idTabRect {
int x;
int w;
int align;
int valign;
int type;
idVec2 iconSize;
float iconVOffset;
};
class idListWindow : public idWindow {
public:
idListWindow(idUserInterfaceLocal *gui);
idListWindow(idDeviceContext *d, idUserInterfaceLocal *gui);
virtual const char* HandleEvent(const sysEvent_t *event, bool *updateVisuals);
virtual void PostParse();
virtual void Draw(int time, float x, float y);
virtual void Activate(bool activate, idStr &act);
virtual void HandleBuddyUpdate(idWindow *buddy);
virtual void StateChanged( bool redraw = false );
virtual size_t Allocated(){return idWindow::Allocated();};
virtual idWinVar* GetWinVarByName(const char *_name, bool winLookup = false, drawWin_t** owner = NULL);
void UpdateList();
private:
virtual bool ParseInternalVar(const char *name, idParser *src);
void CommonInit();
void InitScroller( bool horizontal );
void SetCurrentSel( int sel );
void AddCurrentSel( int sel );
int GetCurrentSel();
bool IsSelected( int index );
void ClearSelection( int sel );
idList<idTabRect> tabInfo;
int top;
float sizeBias;
bool horizontal;
idStr tabStopStr;
idStr tabAlignStr;
idStr tabVAlignStr;
idStr tabTypeStr;
idStr tabIconSizeStr;
idStr tabIconVOffsetStr;
idHashTable<const idMaterial*> iconMaterials;
bool multipleSel;
idStrList listItems;
idSliderWindow* scroller;
idList<int> currentSel;
idStr listName;
int clickTime;
int typedTime;
idStr typed;
};
#endif // __LISTWINDOW_H

359
neo/ui/MarkerWindow.cpp Normal file
View File

@@ -0,0 +1,359 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
// included for image uploading for player stat graph
#include "../renderer/Image.h"
#include "DeviceContext.h"
#include "Window.h"
#include "UserInterfaceLocal.h"
#include "MarkerWindow.h"
class idImage;
void idMarkerWindow::CommonInit() {
numStats = 0;
currentTime = -1;
currentMarker = -1;
stopTime = -1;
imageBuff = NULL;
markerMat = NULL;
markerStop = NULL;
}
idMarkerWindow::idMarkerWindow(idDeviceContext *d, idUserInterfaceLocal *g) : idWindow(d, g) {
dc = d;
gui = g;
CommonInit();
}
idMarkerWindow::idMarkerWindow(idUserInterfaceLocal *g) : idWindow(g) {
gui = g;
CommonInit();
}
idMarkerWindow::~idMarkerWindow() {
}
bool idMarkerWindow::ParseInternalVar(const char *_name, idParser *src) {
if (idStr::Icmp(_name, "markerMat") == 0) {
idStr str;
ParseString(src, str);
markerMat = declManager->FindMaterial(str);
markerMat->SetSort( SS_GUI );
return true;
}
if (idStr::Icmp(_name, "markerStop") == 0) {
idStr str;
ParseString(src, str);
markerStop = declManager->FindMaterial(str);
markerStop->SetSort( SS_GUI );
return true;
}
if (idStr::Icmp(_name, "markerColor") == 0) {
ParseVec4(src, markerColor);
return true;
}
return idWindow::ParseInternalVar(_name, src);
}
idWinVar *idMarkerWindow::GetWinVarByName(const char *_name, bool fixup) {
return idWindow::GetWinVarByName(_name, fixup);
}
const char *idMarkerWindow::HandleEvent(const sysEvent_t *event, bool *updateVisuals) {
if (!(event->evType == SE_KEY && event->evValue2)) {
return "";
}
int key = event->evValue;
if (event->evValue2 && key == K_MOUSE1) {
gui->GetDesktop()->SetChildWinVarVal("markerText", "text", "");
idRectangle r;
int c = markerTimes.Num();
int i;
for (i = 0; i < c; i++) {
markerData_t &md = markerTimes[i];
if (md.rect.Contains(gui->CursorX(), gui->CursorY())) {
currentMarker = i;
gui->SetStateInt( "currentMarker", md.time );
stopTime = md.time;
gui->GetDesktop()->SetChildWinVarVal("markerText", "text", va("Marker set at %.2i:%.2i", md.time / 60 / 60, (md.time / 60) % 60));
gui->GetDesktop()->SetChildWinVarVal("markerText", "visible", "1");
gui->GetDesktop()->SetChildWinVarVal("markerBackground", "matcolor", "1 1 1 1");
gui->GetDesktop()->SetChildWinVarVal("markerBackground", "text", "");
gui->GetDesktop()->SetChildWinVarVal("markerBackground", "background", md.mat->GetName());
break;
}
}
if ( i == c ) {
// no marker selected;
currentMarker = -1;
gui->SetStateInt( "currentMarker", currentTime );
stopTime = currentTime;
gui->GetDesktop()->SetChildWinVarVal("markerText", "text", va("Marker set at %.2i:%.2i", currentTime / 60 / 60, (currentTime / 60) % 60));
gui->GetDesktop()->SetChildWinVarVal("markerText", "visible", "1");
gui->GetDesktop()->SetChildWinVarVal("markerBackground", "matcolor", "0 0 0 0");
gui->GetDesktop()->SetChildWinVarVal("markerBackground", "text", "No Preview");
}
float pct = gui->State().GetFloat( "loadPct" );
int len = gui->State().GetInt( "loadLength" );
if (stopTime > len * pct) {
return "cmdDemoGotoMarker";
}
} else if (key == K_MOUSE2) {
stopTime = -1;
gui->GetDesktop()->SetChildWinVarVal("markerText", "text", "");
gui->SetStateInt( "currentMarker", -1 );
return "cmdDemoGotoMarker";
} else if (key == K_SPACE) {
return "cmdDemoPauseFrame";
}
return "";
}
void idMarkerWindow::PostParse() {
idWindow::PostParse();
}
static const int HEALTH_MAX = 100;
static const int COMBAT_MAX = 100;
static const int RATE_MAX = 125;
static const int STAMINA_MAX = 12;
void idMarkerWindow::Draw(int time, float x, float y) {
float pct;
idRectangle r = clientRect;
int len = gui->State().GetInt( "loadLength" );
if (len == 0) {
len = 1;
}
if (numStats > 1) {
int c = markerTimes.Num();
if (c > 0) {
for (int i = 0; i < c; i++) {
markerData_t &md = markerTimes[i];
if (md.rect.w == 0) {
md.rect.x = (r.x + r.w * ((float)md.time / len)) - 8;
md.rect.y = r.y + r.h - 20;
md.rect.w = 16;
md.rect.h = 16;
}
dc->DrawMaterial(md.rect.x, md.rect.y, md.rect.w, md.rect.h, markerMat, markerColor);
}
}
}
r.y += 10;
if (r.w > 0 && r.Contains(gui->CursorX(), gui->CursorY())) {
pct = (gui->CursorX() - r.x) / r.w;
currentTime = len * pct;
r.x = (gui->CursorX() > r.x + r.w - 40) ? gui->CursorX() - 40 : gui->CursorX();
r.y = gui->CursorY() - 15;
r.w = 40;
r.h = 20;
dc->DrawText(va("%.2i:%.2i", currentTime / 60 / 60, (currentTime / 60) % 60), 0.25, 0, idDeviceContext::colorWhite, r, false);
}
if (stopTime >= 0 && markerStop) {
r = clientRect;
r.y += (r.h - 32) / 2;
pct = (float)stopTime / len;
r.x += (r.w * pct) - 16;
idVec4 color(1, 1, 1, 0.65f);
dc->DrawMaterial(r.x, r.y, 32, 32, markerStop, color);
}
}
const char *idMarkerWindow::RouteMouseCoords(float xd, float yd) {
const char * ret = idWindow::RouteMouseCoords(xd, yd);
idRectangle r;
int i, c = markerTimes.Num();
int len = gui->State().GetInt( "loadLength" );
if (len == 0) {
len = 1;
}
for (i = 0; i < c; i++) {
markerData_t &md = markerTimes[i];
if (md.rect.Contains(gui->CursorY(), gui->CursorX())) {
gui->GetDesktop()->SetChildWinVarVal("markerBackground", "background", md.mat->GetName());
gui->GetDesktop()->SetChildWinVarVal("markerBackground", "matcolor", "1 1 1 1");
gui->GetDesktop()->SetChildWinVarVal("markerBackground", "text", "");
break;
}
}
if (i >= c) {
if (currentMarker == -1) {
gui->GetDesktop()->SetChildWinVarVal("markerBackground", "matcolor", "0 0 0 0");
gui->GetDesktop()->SetChildWinVarVal("markerBackground", "text", "No Preview");
} else {
markerData_t &md = markerTimes[currentMarker];
gui->GetDesktop()->SetChildWinVarVal("markerBackground", "background", md.mat->GetName());
gui->GetDesktop()->SetChildWinVarVal("markerBackground", "matcolor", "1 1 1 1");
gui->GetDesktop()->SetChildWinVarVal("markerBackground", "text", "");
}
}
return ret;
}
void idMarkerWindow::Point(int x, int y, dword *out, dword color) {
int index = (63-y) * 512 + x;
if (index >= 0 && index < 512 * 64) {
out[index] = color;
} else {
common->Warning("Out of bounds on point %i : %i", x, y);
}
}
void idMarkerWindow::Line(int x1, int y1, int x2, int y2, dword* out, dword color) {
int deltax = abs(x2 - x1);
int deltay = abs(y2 - y1);
int incx = (x1 > x2) ? -1 : 1;
int incy = (y1 > y2) ? -1 : 1;
int right, up, dir;
if (deltax > deltay) {
right = deltay * 2;
up = right - deltax * 2;
dir = right - deltax;
while (deltax-- >= 0) {
Point(x1, y1, out, color);
x1 += incx;
y1 += (dir > 0) ? incy : 0;
dir += (dir > 0) ? up : right;
}
} else {
right = deltax * 2;
up = right - deltay * 2;
dir = right - deltay;
while ( deltay-- >= 0) {
Point(x1, y1, out, color);
x1 += (dir > 0) ? incx : 0;
y1 += incy;
dir += (dir > 0) ? up : right;
}
}
}
void idMarkerWindow::Activate(bool activate, idStr &act) {
idWindow::Activate(activate, act);
if (activate) {
int i;
gui->GetDesktop()->SetChildWinVarVal("markerText", "text", "");
imageBuff = (dword*)Mem_Alloc(512*64*4);
markerTimes.Clear();
currentMarker = -1;
currentTime = -1;
stopTime = -1;
statData = gui->State().GetString( "statData" );
numStats = 0;
if (statData.Length()) {
idFile *file = fileSystem->OpenFileRead(statData);
if (file) {
file->Read(&numStats, sizeof(numStats));
file->Read(loggedStats, numStats * sizeof(loggedStats[0]));
for (i = 0; i < numStats; i++) {
if (loggedStats[i].health < 0) {
loggedStats[i].health = 0;
}
if (loggedStats[i].stamina < 0) {
loggedStats[i].stamina = 0;
}
if (loggedStats[i].heartRate < 0) {
loggedStats[i].heartRate = 0;
}
if (loggedStats[i].combat < 0) {
loggedStats[i].combat = 0;
}
}
fileSystem->CloseFile(file);
}
}
if (numStats > 1 && background) {
idStr markerPath = statData;
markerPath.StripFilename();
idFileList *markers;
markers = fileSystem->ListFiles( markerPath, ".tga", false, true );
idStr name;
for ( i = 0; i < markers->GetNumFiles(); i++ ) {
name = markers->GetFile( i );
markerData_t md;
md.mat = declManager->FindMaterial( name );
md.mat->SetSort( SS_GUI );
name.StripPath();
name.StripFileExtension();
md.time = atoi(name);
markerTimes.Append(md);
}
fileSystem->FreeFileList( markers );
memset(imageBuff, 0, 512*64*4);
float step = 511.0f / (numStats - 1);
float startX = 0;
float x1, y1, x2, y2;
x1 = 0 - step;
for (i = 0; i < numStats-1; i++) {
x1 += step;
x2 = x1 + step;
y1 = 63 * ((float)loggedStats[i].health / HEALTH_MAX);
y2 = 63 * ((float)loggedStats[i+1].health / HEALTH_MAX);
Line(x1, y1, x2, y2, imageBuff, 0xff0000ff);
y1 = 63 * ((float)loggedStats[i].heartRate / RATE_MAX);
y2 = 63 * ((float)loggedStats[i+1].heartRate / RATE_MAX);
Line(x1, y1, x2, y2, imageBuff, 0xff00ff00);
// stamina not quite as high on graph so health does not get obscured with both at 100%
y1 = 62 * ((float)loggedStats[i].stamina / STAMINA_MAX);
y2 = 62 * ((float)loggedStats[i+1].stamina / STAMINA_MAX);
Line(x1, y1, x2, y2, imageBuff, 0xffff0000);
y1 = 63 * ((float)loggedStats[i].combat / COMBAT_MAX);
y2 = 63 * ((float)loggedStats[i+1].combat / COMBAT_MAX);
Line(x1, y1, x2, y2, imageBuff, 0xff00ffff);
}
const shaderStage_t *stage = background->GetStage(0);
if (stage) {
stage->texture.image->UploadScratch((byte*)imageBuff, 512, 64);
}
Mem_Free(imageBuff);
}
}
}
void idMarkerWindow::MouseExit() {
idWindow::MouseExit();
}
void idMarkerWindow::MouseEnter() {
idWindow::MouseEnter();
}

74
neo/ui/MarkerWindow.h Normal file
View File

@@ -0,0 +1,74 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __MARKERWINDOW_H
#define __MARKERWINDOW_H
class idUserInterfaceLocal;
typedef struct {
int time;
const idMaterial *mat;
idRectangle rect;
} markerData_t;
class idMarkerWindow : public idWindow {
public:
idMarkerWindow(idUserInterfaceLocal *gui);
idMarkerWindow(idDeviceContext *d, idUserInterfaceLocal *gui);
virtual ~idMarkerWindow();
virtual size_t Allocated(){return idWindow::Allocated();};
virtual idWinVar *GetWinVarByName(const char *_name, bool winLookup = false);
virtual const char *HandleEvent(const sysEvent_t *event, bool *updateVisuals);
virtual void PostParse();
virtual void Draw(int time, float x, float y);
virtual const char *RouteMouseCoords(float xd, float yd);
virtual void Activate(bool activate, idStr &act);
virtual void MouseExit();
virtual void MouseEnter();
private:
virtual bool ParseInternalVar(const char *name, idParser *src);
void CommonInit();
void Line(int x1, int y1, int x2, int y2, dword* out, dword color);
void Point(int x, int y, dword *out, dword color);
logStats_t loggedStats[MAX_LOGGED_STATS];
idList<markerData_t> markerTimes;
idStr statData;
int numStats;
dword *imageBuff;
const idMaterial *markerMat;
const idMaterial *markerStop;
idVec4 markerColor;
int currentMarker;
int currentTime;
int stopTime;
};
#endif // __MARKERWINDOW_H

222
neo/ui/Rectangle.h Normal file
View File

@@ -0,0 +1,222 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef IDRECTANGLE_H_
#define IDRECTANGLE_H_
//
// simple rectangle
//
extern void RotateVector(idVec3 &v, idVec3 origin, float a, float c, float s);
class idRectangle {
public:
float x; // horiz position
float y; // vert position
float w; // width
float h; // height;
idRectangle() { x = y = w= h = 0.0; }
idRectangle(float ix, float iy, float iw, float ih) { x = ix; y = iy; w = iw; h = ih; }
float Bottom() const { return y + h; }
float Right() const { return x + w; }
void Offset (float x, float y) {
this->x += x;
this->y += y;
}
bool Contains(float xt, float yt) {
if (w == 0.0 && h == 0.0) {
return false;
}
if (xt >= x && xt <= Right() && yt >= y && yt <= Bottom()) {
return true;
}
return false;
}
void Empty() { x = y = w = h = 0.0; };
void ClipAgainst(idRectangle r, bool sizeOnly) {
if (!sizeOnly) {
if (x < r.x) {
x = r.x;
}
if (y < r.y) {
y = r.y;
}
}
if (x + w > r.x + r.w) {
w = (r.x + r.w) - x;
}
if (y + h > r.y + r.h) {
h = (r.y + r.h) - y;
}
}
void Rotate(float a, idRectangle &out) {
idVec3 p1, p2, p3, p4, p5;
float c, s;
idVec3 center;
center.Set((x + w) / 2.0, (y + h) / 2.0, 0);
p1.Set(x, y, 0);
p2.Set(Right(), y, 0);
p4.Set(x, Bottom(), 0);
if (a) {
s = sin( DEG2RAD( a ) );
c = cos( DEG2RAD( a ) );
}
else {
s = c = 0;
}
RotateVector(p1, center, a, c, s);
RotateVector(p2, center, a, c, s);
RotateVector(p4, center, a, c, s);
out.x = p1.x;
out.y = p1.y;
out.w = (p2 - p1).Length();
out.h = (p4 - p1).Length();
}
idRectangle & operator+=( const idRectangle &a );
idRectangle & operator-=( const idRectangle &a );
idRectangle & operator/=( const idRectangle &a );
idRectangle & operator/=( const float a );
idRectangle & operator*=( const float a );
idRectangle & operator=( const idVec4 v );
int operator==(const idRectangle &a) const;
float & operator[]( const int index );
char * String( void ) const;
const idVec4& ToVec4() const;
};
ID_INLINE const idVec4 &idRectangle::ToVec4() const {
return *reinterpret_cast<const idVec4 *>(&x);
}
ID_INLINE idRectangle &idRectangle::operator+=( const idRectangle &a ) {
x += a.x;
y += a.y;
w += a.w;
h += a.h;
return *this;
}
ID_INLINE idRectangle &idRectangle::operator/=( const idRectangle &a ) {
x /= a.x;
y /= a.y;
w /= a.w;
h /= a.h;
return *this;
}
ID_INLINE idRectangle &idRectangle::operator/=( const float a ) {
float inva = 1.0f / a;
x *= inva;
y *= inva;
w *= inva;
h *= inva;
return *this;
}
ID_INLINE idRectangle &idRectangle::operator-=( const idRectangle &a ) {
x -= a.x;
y -= a.y;
w -= a.w;
h -= a.h;
return *this;
}
ID_INLINE idRectangle &idRectangle::operator*=( const float a ) {
x *= a;
y *= a;
w *= a;
h *= a;
return *this;
}
ID_INLINE idRectangle &idRectangle::operator=( const idVec4 v ) {
x = v.x;
y = v.y;
w = v.z;
h = v.w;
return *this;
}
ID_INLINE int idRectangle::operator==( const idRectangle &a ) const {
return (x == a.x && y == a.y && w == a.w && a.h);
}
ID_INLINE float& idRectangle::operator[]( int index ) {
return ( &x )[ index ];
}
class idRegion {
public:
idRegion() { };
void Empty() {
rects.Clear();
}
bool Contains(float xt, float yt) {
int c = rects.Num();
for (int i = 0; i < c; i++) {
if (rects[i].Contains(xt, yt)) {
return true;
}
}
return false;
}
void AddRect(float x, float y, float w, float h) {
rects.Append(idRectangle(x, y, w, h));
}
int GetRectCount() {
return rects.Num();
}
idRectangle *GetRect(int index) {
if (index >= 0 && index < rects.Num()) {
return &rects[index];
}
return NULL;
}
protected:
idList<idRectangle> rects;
};
#endif

402
neo/ui/RegExp.cpp Normal file
View File

@@ -0,0 +1,402 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "RegExp.h"
#include "DeviceContext.h"
#include "Window.h"
#include "UserInterfaceLocal.h"
int idRegister::REGCOUNT[NUMTYPES] = {4, 1, 1, 1, 0, 2, 3, 4};
/*
====================
idRegister::SetToRegs
====================
*/
void idRegister::SetToRegs( float *registers ) {
int i;
idVec4 v;
idVec2 v2;
idVec3 v3;
idRectangle rect;
if ( !enabled || var == NULL || ( var && ( var->GetDict() || !var->GetEval() ) ) ) {
return;
}
switch( type ) {
case VEC4: {
v = *static_cast<idWinVec4*>(var);
break;
}
case RECTANGLE: {
rect = *static_cast<idWinRectangle*>(var);
v = rect.ToVec4();
break;
}
case VEC2: {
v2 = *static_cast<idWinVec2*>(var);
v[0] = v2[0];
v[1] = v2[1];
break;
}
case VEC3: {
v3 = *static_cast<idWinVec3*>(var);
v[0] = v3[0];
v[1] = v3[1];
v[2] = v3[2];
break;
}
case FLOAT: {
v[0] = *static_cast<idWinFloat*>(var);
break;
}
case INT: {
v[0] = *static_cast<idWinInt*>(var);
break;
}
case BOOL: {
v[0] = *static_cast<idWinBool*>(var);
break;
}
default: {
common->FatalError( "idRegister::SetToRegs: bad reg type" );
break;
}
}
for ( i = 0; i < regCount; i++ ) {
registers[ regs[ i ] ] = v[i];
}
}
/*
=================
idRegister::GetFromRegs
=================
*/
void idRegister::GetFromRegs( float *registers ) {
idVec4 v;
idRectangle rect;
if (!enabled || var == NULL || (var && (var->GetDict() || !var->GetEval()))) {
return;
}
for ( int i = 0; i < regCount; i++ ) {
v[i] = registers[regs[i]];
}
switch( type ) {
case VEC4: {
*dynamic_cast<idWinVec4*>(var) = v;
break;
}
case RECTANGLE: {
rect.x = v.x;
rect.y = v.y;
rect.w = v.z;
rect.h = v.w;
*static_cast<idWinRectangle*>(var) = rect;
break;
}
case VEC2: {
*static_cast<idWinVec2*>(var) = v.ToVec2();
break;
}
case VEC3: {
*static_cast<idWinVec3*>(var) = v.ToVec3();
break;
}
case FLOAT: {
*static_cast<idWinFloat*>(var) = v[0];
break;
}
case INT: {
*static_cast<idWinInt*>(var) = v[0];
break;
}
case BOOL: {
*static_cast<idWinBool*>(var) = ( v[0] != 0.0f );
break;
}
default: {
common->FatalError( "idRegister::GetFromRegs: bad reg type" );
break;
}
}
}
/*
=================
idRegister::ReadFromDemoFile
=================
*/
void idRegister::ReadFromDemoFile(idDemoFile *f) {
f->ReadBool( enabled );
f->ReadShort( type );
f->ReadInt( regCount );
for ( int i = 0; i < 4; i++ )
f->ReadUnsignedShort( regs[i] );
name = f->ReadHashString();
}
/*
=================
idRegister::WriteToDemoFile
=================
*/
void idRegister::WriteToDemoFile( idDemoFile *f ) {
f->WriteBool( enabled );
f->WriteShort( type );
f->WriteInt( regCount );
for (int i = 0; i < 4; i++)
f->WriteUnsignedShort( regs[i] );
f->WriteHashString( name );
}
/*
=================
idRegister::WriteToSaveGame
=================
*/
void idRegister::WriteToSaveGame( idFile *savefile ) {
int len;
savefile->Write( &enabled, sizeof( enabled ) );
savefile->Write( &type, sizeof( type ) );
savefile->Write( &regCount, sizeof( regCount ) );
savefile->Write( &regs[0], sizeof( regs ) );
len = name.Length();
savefile->Write( &len, sizeof( len ) );
savefile->Write( name.c_str(), len );
var->WriteToSaveGame( savefile );
}
/*
================
idRegister::ReadFromSaveGame
================
*/
void idRegister::ReadFromSaveGame( idFile *savefile ) {
int len;
savefile->Read( &enabled, sizeof( enabled ) );
savefile->Read( &type, sizeof( type ) );
savefile->Read( &regCount, sizeof( regCount ) );
savefile->Read( &regs[0], sizeof( regs ) );
savefile->Read( &len, sizeof( len ) );
name.Fill( ' ', len );
savefile->Read( &name[0], len );
var->ReadFromSaveGame( savefile );
}
/*
====================
idRegisterList::AddReg
====================
*/
void idRegisterList::AddReg( const char *name, int type, idVec4 data, idWindow *win, idWinVar *var ) {
if ( FindReg( name ) == NULL ) {
assert( type >= 0 && type < idRegister::NUMTYPES );
int numRegs = idRegister::REGCOUNT[type];
idRegister *reg = new idRegister( name, type );
reg->var = var;
for ( int i = 0; i < numRegs; i++ ) {
reg->regs[i] = win->ExpressionConstant(data[i]);
}
int hash = regHash.GenerateKey( name, false );
regHash.Add( hash, regs.Append( reg ) );
}
}
/*
====================
idRegisterList::AddReg
====================
*/
void idRegisterList::AddReg( const char *name, int type, idParser *src, idWindow *win, idWinVar *var ) {
idRegister* reg;
reg = FindReg( name );
if ( reg == NULL ) {
assert(type >= 0 && type < idRegister::NUMTYPES);
int numRegs = idRegister::REGCOUNT[type];
reg = new idRegister( name, type );
reg->var = var;
if ( type == idRegister::STRING ) {
idToken tok;
if ( src->ReadToken( &tok ) ) {
tok = common->GetLanguageDict()->GetString( tok );
var->Init( tok, win );
}
} else {
for ( int i = 0; i < numRegs; i++ ) {
reg->regs[i] = win->ParseExpression(src, NULL);
if ( i < numRegs-1 ) {
src->ExpectTokenString(",");
}
}
}
int hash = regHash.GenerateKey( name, false );
regHash.Add( hash, regs.Append( reg ) );
} else {
int numRegs = idRegister::REGCOUNT[type];
reg->var = var;
if ( type == idRegister::STRING ) {
idToken tok;
if ( src->ReadToken( &tok ) ) {
var->Init( tok, win );
}
} else {
for ( int i = 0; i < numRegs; i++ ) {
reg->regs[i] = win->ParseExpression( src, NULL );
if ( i < numRegs-1 ) {
src->ExpectTokenString(",");
}
}
}
}
}
/*
====================
idRegisterList::GetFromRegs
====================
*/
void idRegisterList::GetFromRegs(float *registers) {
for ( int i = 0; i < regs.Num(); i++ ) {
regs[i]->GetFromRegs( registers );
}
}
/*
====================
idRegisterList::SetToRegs
====================
*/
void idRegisterList::SetToRegs( float *registers ) {
int i;
for ( i = 0; i < regs.Num(); i++ ) {
regs[i]->SetToRegs( registers );
}
}
/*
====================
idRegisterList::FindReg
====================
*/
idRegister *idRegisterList::FindReg( const char *name ) {
int hash = regHash.GenerateKey( name, false );
for ( int i = regHash.First( hash ); i != -1; i = regHash.Next( i ) ) {
if ( regs[i]->name.Icmp( name ) == 0 ) {
return regs[i];
}
}
return NULL;
}
/*
====================
idRegisterList::Reset
====================
*/
void idRegisterList::Reset() {
regs.DeleteContents( true );
regHash.Clear();
}
/*
====================
idRegisterList::ReadFromSaveGame
====================
*/
void idRegisterList::ReadFromDemoFile(idDemoFile *f) {
int c;
f->ReadInt( c );
regs.DeleteContents( true );
for ( int i = 0; i < c; i++ ) {
idRegister *reg = new idRegister;
reg->ReadFromDemoFile( f );
regs.Append( reg );
}
}
/*
====================
idRegisterList::ReadFromSaveGame
====================
*/
void idRegisterList::WriteToDemoFile(idDemoFile *f) {
int c = regs.Num();
f->WriteInt( c );
for ( int i = 0 ; i < c; i++ ) {
regs[i]->WriteToDemoFile(f);
}
}
/*
=====================
idRegisterList::WriteToSaveGame
=====================
*/
void idRegisterList::WriteToSaveGame( idFile *savefile ) {
int i, num;
num = regs.Num();
savefile->Write( &num, sizeof( num ) );
for ( i = 0; i < num; i++ ) {
regs[i]->WriteToSaveGame( savefile );
}
}
/*
====================
idRegisterList::ReadFromSaveGame
====================
*/
void idRegisterList::ReadFromSaveGame( idFile *savefile ) {
int i, num;
savefile->Read( &num, sizeof( num ) );
for ( i = 0; i < num; i++ ) {
regs[i]->ReadFromSaveGame( savefile );
}
}

111
neo/ui/RegExp.h Normal file
View File

@@ -0,0 +1,111 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __REGEXP_H__
#define __REGEXP_H__
class idWindow;
class idWinVar;
class idRegister {
public:
idRegister();
idRegister( const char *p, int t );
enum REGTYPE { VEC4 = 0, FLOAT, BOOL, INT, STRING, VEC2, VEC3, RECTANGLE, NUMTYPES } ;
static int REGCOUNT[NUMTYPES];
bool enabled;
short type;
idStr name;
int regCount;
unsigned short regs[4];
idWinVar * var;
void SetToRegs( float *registers );
void GetFromRegs( float *registers );
void CopyRegs( idRegister *src );
void Enable( bool b ) { enabled = b; }
void ReadFromDemoFile( idDemoFile *f );
void WriteToDemoFile( idDemoFile *f );
void WriteToSaveGame( idFile *savefile );
void ReadFromSaveGame( idFile *savefile );
};
ID_INLINE idRegister::idRegister( void ) {
}
ID_INLINE idRegister::idRegister( const char *p, int t ) {
name = p;
type = t;
assert( t >= 0 && t < NUMTYPES );
regCount = REGCOUNT[t];
enabled = ( type == STRING ) ? false : true;
var = NULL;
};
ID_INLINE void idRegister::CopyRegs( idRegister *src ) {
regs[0] = src->regs[0];
regs[1] = src->regs[1];
regs[2] = src->regs[2];
regs[3] = src->regs[3];
}
class idRegisterList {
public:
idRegisterList();
~idRegisterList();
void AddReg( const char *name, int type, idParser *src, idWindow *win, idWinVar *var );
void AddReg( const char *name, int type, idVec4 data, idWindow *win, idWinVar *var );
idRegister * FindReg( const char *name );
void SetToRegs( float *registers );
void GetFromRegs( float *registers );
void Reset();
void ReadFromDemoFile( idDemoFile *f );
void WriteToDemoFile( idDemoFile *f );
void WriteToSaveGame( idFile *savefile );
void ReadFromSaveGame( idFile *savefile );
private:
idList<idRegister*> regs;
idHashIndex regHash;
};
ID_INLINE idRegisterList::idRegisterList() {
regs.SetGranularity( 4 );
regHash.SetGranularity( 4 );
regHash.Clear( 32, 4 );
}
ID_INLINE idRegisterList::~idRegisterList() {
}
#endif /* !__REGEXP_H__ */

87
neo/ui/RegExp_old.h Normal file
View File

@@ -0,0 +1,87 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef REGEXP_H_
#define REGEXP_H_
class idWindow;
class idRegister {
public:
idRegister() {};
idRegister(const char *p, int t) {
name = p;
type = t;
assert(t >= 0 && t < NUMTYPES);
regCount = REGCOUNT[t];
enabled = (type == STRING) ? false : true;
};
bool enabled;
int type;
int regCount;
enum REGTYPE { VEC4 = 0, FLOAT, BOOL, INT, STRING, VEC2, VEC3, NUMTYPES } ;
static int REGCOUNT[NUMTYPES];
idStr name;
int regs[4];
void SetToRegs(float *registers, idTypedDict *state);
void SetToRegList(idList<float> *registers, idTypedDict *state);
void GetFromRegs(float *registers, idTypedDict *state);
void CopyRegs(idRegister *src) {
regs[0] = src->regs[0];
regs[1] = src->regs[1];
regs[2] = src->regs[2];
regs[3] = src->regs[3];
}
void Enable(bool b) {
enabled = b;
}
void ReadFromDemoFile(idDemoFile *f);
void WriteToDemoFile(idDemoFile *f);
};
class idRegisterList {
idList<idRegister> regs;
public:
//
void RemoveReg ( const char* name );
//
void AddReg(const char *name, int type, idParser *src, idWindow *win);
void AddReg(const char *name, int type, idVec4 data, idWindow *win);
idRegister *FindReg(const char *name);
int FindRegIndex ( const char* name );
void SetToRegs(float *registers, idTypedDict *state);
void GetFromRegs(float *registers, idTypedDict *state);
void Reset();
void ReadFromDemoFile(idDemoFile *f);
void WriteToDemoFile(idDemoFile *f);
};
#endif

212
neo/ui/RenderWindow.cpp Normal file
View File

@@ -0,0 +1,212 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "DeviceContext.h"
#include "Window.h"
#include "UserInterfaceLocal.h"
#include "RenderWindow.h"
idRenderWindow::idRenderWindow(idDeviceContext *d, idUserInterfaceLocal *g) : idWindow(d, g) {
dc = d;
gui = g;
CommonInit();
}
idRenderWindow::idRenderWindow(idUserInterfaceLocal *g) : idWindow(g) {
gui = g;
CommonInit();
}
idRenderWindow::~idRenderWindow() {
renderSystem->FreeRenderWorld( world );
}
void idRenderWindow::CommonInit() {
world = renderSystem->AllocRenderWorld();
needsRender = true;
lightOrigin = idVec4(-128.0f, 0.0f, 0.0f, 1.0f);
lightColor = idVec4(1.0f, 1.0f, 1.0f, 1.0f);
modelOrigin.Zero();
viewOffset = idVec4(-128.0f, 0.0f, 0.0f, 1.0f);
modelAnim = NULL;
animLength = 0;
animEndTime = -1;
modelDef = -1;
updateAnimation = true;
}
void idRenderWindow::BuildAnimation(int time) {
if (!updateAnimation) {
return;
}
if (animName.Length() && animClass.Length()) {
worldEntity.numJoints = worldEntity.hModel->NumJoints();
worldEntity.joints = ( idJointMat * )Mem_Alloc16( worldEntity.numJoints * sizeof( *worldEntity.joints ) );
modelAnim = gameEdit->ANIM_GetAnimFromEntityDef(animClass, animName);
if (modelAnim) {
animLength = gameEdit->ANIM_GetLength(modelAnim);
animEndTime = time + animLength;
}
}
updateAnimation = false;
}
void idRenderWindow::PreRender() {
if (needsRender) {
world->InitFromMap( NULL );
idDict spawnArgs;
spawnArgs.Set("classname", "light");
spawnArgs.Set("name", "light_1");
spawnArgs.Set("origin", lightOrigin.ToVec3().ToString());
spawnArgs.Set("_color", lightColor.ToVec3().ToString());
gameEdit->ParseSpawnArgsToRenderLight( &spawnArgs, &rLight );
lightDef = world->AddLightDef( &rLight );
if ( !modelName[0] ) {
common->Warning( "Window '%s' in gui '%s': no model set", GetName(), GetGui()->GetSourceFile() );
}
memset( &worldEntity, 0, sizeof( worldEntity ) );
spawnArgs.Clear();
spawnArgs.Set("classname", "func_static");
spawnArgs.Set("model", modelName);
spawnArgs.Set("origin", modelOrigin.c_str());
gameEdit->ParseSpawnArgsToRenderEntity( &spawnArgs, &worldEntity );
if ( worldEntity.hModel ) {
idVec3 v = modelRotate.ToVec3();
worldEntity.axis = v.ToMat3();
worldEntity.shaderParms[0] = 1;
worldEntity.shaderParms[1] = 1;
worldEntity.shaderParms[2] = 1;
worldEntity.shaderParms[3] = 1;
modelDef = world->AddEntityDef( &worldEntity );
}
needsRender = false;
}
}
void idRenderWindow::Render( int time ) {
rLight.origin = lightOrigin.ToVec3();
rLight.shaderParms[SHADERPARM_RED] = lightColor.x();
rLight.shaderParms[SHADERPARM_GREEN] = lightColor.y();
rLight.shaderParms[SHADERPARM_BLUE] = lightColor.z();
world->UpdateLightDef(lightDef, &rLight);
if ( worldEntity.hModel ) {
if (updateAnimation) {
BuildAnimation(time);
}
if (modelAnim) {
if (time > animEndTime) {
animEndTime = time + animLength;
}
gameEdit->ANIM_CreateAnimFrame(worldEntity.hModel, modelAnim, worldEntity.numJoints, worldEntity.joints, animLength - (animEndTime - time), vec3_origin, false );
}
worldEntity.axis = idAngles(modelRotate.x(), modelRotate.y(), modelRotate.z()).ToMat3();
world->UpdateEntityDef(modelDef, &worldEntity);
}
}
void idRenderWindow::Draw(int time, float x, float y) {
PreRender();
Render(time);
memset( &refdef, 0, sizeof( refdef ) );
refdef.vieworg = viewOffset.ToVec3();;
//refdef.vieworg.Set(-128, 0, 0);
refdef.viewaxis.Identity();
refdef.shaderParms[0] = 1;
refdef.shaderParms[1] = 1;
refdef.shaderParms[2] = 1;
refdef.shaderParms[3] = 1;
refdef.x = drawRect.x;
refdef.y = drawRect.y;
refdef.width = drawRect.w;
refdef.height = drawRect.h;
refdef.fov_x = 90;
refdef.fov_y = 2 * atan((float)drawRect.h / drawRect.w) * idMath::M_RAD2DEG;
refdef.time = time;
world->RenderScene(&refdef);
}
void idRenderWindow::PostParse() {
idWindow::PostParse();
}
//
//
idWinVar *idRenderWindow::GetWinVarByName(const char *_name, bool fixup, drawWin_t** owner ) {
//
if (idStr::Icmp(_name, "model") == 0) {
return &modelName;
}
if (idStr::Icmp(_name, "anim") == 0) {
return &animName;
}
if (idStr::Icmp(_name, "lightOrigin") == 0) {
return &lightOrigin;
}
if (idStr::Icmp(_name, "lightColor") == 0) {
return &lightColor;
}
if (idStr::Icmp(_name, "modelOrigin") == 0) {
return &modelOrigin;
}
if (idStr::Icmp(_name, "modelRotate") == 0) {
return &modelRotate;
}
if (idStr::Icmp(_name, "viewOffset") == 0) {
return &viewOffset;
}
if (idStr::Icmp(_name, "needsRender") == 0) {
return &needsRender;
}
//
//
return idWindow::GetWinVarByName(_name, fixup, owner);
//
}
bool idRenderWindow::ParseInternalVar(const char *_name, idParser *src) {
if (idStr::Icmp(_name, "animClass") == 0) {
ParseString(src, animClass);
return true;
}
return idWindow::ParseInternalVar(_name, src);
}

75
neo/ui/RenderWindow.h Normal file
View File

@@ -0,0 +1,75 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __RENDERWINDOW_H
#define __RENDERWINDOW_H
class idUserInterfaceLocal;
class idRenderWindow : public idWindow {
public:
idRenderWindow(idUserInterfaceLocal *gui);
idRenderWindow(idDeviceContext *d, idUserInterfaceLocal *gui);
virtual ~idRenderWindow();
virtual void PostParse();
virtual void Draw(int time, float x, float y);
virtual size_t Allocated(){return idWindow::Allocated();};
//
//
virtual idWinVar *GetWinVarByName(const char *_name, bool winLookup = false, drawWin_t** owner = NULL);
//
private:
void CommonInit();
virtual bool ParseInternalVar(const char *name, idParser *src);
void Render(int time);
void PreRender();
void BuildAnimation(int time);
renderView_t refdef;
idRenderWorld *world;
renderEntity_t worldEntity;
renderLight_t rLight;
const idMD5Anim *modelAnim;
qhandle_t worldModelDef;
qhandle_t lightDef;
qhandle_t modelDef;
idWinStr modelName;
idWinStr animName;
idStr animClass;
idWinVec4 lightOrigin;
idWinVec4 lightColor;
idWinVec4 modelOrigin;
idWinVec4 modelRotate;
idWinVec4 viewOffset;
idWinBool needsRender;
int animLength;
int animEndTime;
bool updateAnimation;
};
#endif // __RENDERWINDOW_H

439
neo/ui/SimpleWindow.cpp Normal file
View File

@@ -0,0 +1,439 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "DeviceContext.h"
#include "Window.h"
#include "UserInterfaceLocal.h"
#include "SimpleWindow.h"
idSimpleWindow::idSimpleWindow(idWindow *win) {
gui = win->GetGui();
dc = win->dc;
drawRect = win->drawRect;
clientRect = win->clientRect;
textRect = win->textRect;
origin = win->origin;
fontNum = win->fontNum;
name = win->name;
matScalex = win->matScalex;
matScaley = win->matScaley;
borderSize = win->borderSize;
textAlign = win->textAlign;
textAlignx = win->textAlignx;
textAligny = win->textAligny;
background = win->background;
flags = win->flags;
textShadow = win->textShadow;
visible = win->visible;
text = win->text;
rect = win->rect;
backColor = win->backColor;
matColor = win->matColor;
foreColor = win->foreColor;
borderColor = win->borderColor;
textScale = win->textScale;
rotate = win->rotate;
shear = win->shear;
backGroundName = win->backGroundName;
if (backGroundName.Length()) {
background = declManager->FindMaterial(backGroundName);
background->SetSort( SS_GUI );
background->SetImageClassifications( 1 ); // just for resource tracking
}
backGroundName.SetMaterialPtr(&background);
//
// added parent
mParent = win->GetParent();
//
hideCursor = win->hideCursor;
idWindow *parent = win->GetParent();
if (parent) {
if (text.NeedsUpdate()) {
parent->AddUpdateVar(&text);
}
if (visible.NeedsUpdate()) {
parent->AddUpdateVar(&visible);
}
if (rect.NeedsUpdate()) {
parent->AddUpdateVar(&rect);
}
if (backColor.NeedsUpdate()) {
parent->AddUpdateVar(&backColor);
}
if (matColor.NeedsUpdate()) {
parent->AddUpdateVar(&matColor);
}
if (foreColor.NeedsUpdate()) {
parent->AddUpdateVar(&foreColor);
}
if (borderColor.NeedsUpdate()) {
parent->AddUpdateVar(&borderColor);
}
if (textScale.NeedsUpdate()) {
parent->AddUpdateVar(&textScale);
}
if (rotate.NeedsUpdate()) {
parent->AddUpdateVar(&rotate);
}
if (shear.NeedsUpdate()) {
parent->AddUpdateVar(&shear);
}
if (backGroundName.NeedsUpdate()) {
parent->AddUpdateVar(&backGroundName);
}
}
}
idSimpleWindow::~idSimpleWindow() {
}
void idSimpleWindow::StateChanged( bool redraw ) {
if ( redraw && background && background->CinematicLength() ) {
background->UpdateCinematic( gui->GetTime() );
}
}
void idSimpleWindow::SetupTransforms(float x, float y) {
static idMat3 trans;
static idVec3 org;
trans.Identity();
org.Set( origin.x + x, origin.y + y, 0 );
if ( rotate ) {
static idRotation rot;
static idVec3 vec( 0, 0, 1 );
rot.Set( org, vec, rotate );
trans = rot.ToMat3();
}
static idMat3 smat;
smat.Identity();
if (shear.x() || shear.y()) {
smat[0][1] = shear.x();
smat[1][0] = shear.y();
trans *= smat;
}
if ( !trans.IsIdentity() ) {
dc->SetTransformInfo( org, trans );
}
}
void idSimpleWindow::DrawBackground(const idRectangle &drawRect) {
if (backColor.w() > 0) {
dc->DrawFilledRect(drawRect.x, drawRect.y, drawRect.w, drawRect.h, backColor);
}
if (background) {
if (matColor.w() > 0) {
float scalex, scaley;
if ( flags & WIN_NATURALMAT ) {
scalex = drawRect.w / background->GetImageWidth();
scaley = drawRect.h / background->GetImageHeight();
} else {
scalex = matScalex;
scaley = matScaley;
}
dc->DrawMaterial(drawRect.x, drawRect.y, drawRect.w, drawRect.h, background, matColor, scalex, scaley);
}
}
}
void idSimpleWindow::DrawBorderAndCaption(const idRectangle &drawRect) {
if (flags & WIN_BORDER) {
if (borderSize) {
dc->DrawRect(drawRect.x, drawRect.y, drawRect.w, drawRect.h, borderSize, borderColor);
}
}
}
void idSimpleWindow::CalcClientRect(float xofs, float yofs) {
drawRect = rect;
if ( flags & WIN_INVERTRECT ) {
drawRect.x = rect.x() - rect.w();
drawRect.y = rect.y() - rect.h();
}
drawRect.x += xofs;
drawRect.y += yofs;
clientRect = drawRect;
if (rect.h() > 0.0 && rect.w() > 0.0) {
if (flags & WIN_BORDER && borderSize != 0.0) {
clientRect.x += borderSize;
clientRect.y += borderSize;
clientRect.w -= borderSize;
clientRect.h -= borderSize;
}
textRect = clientRect;
textRect.x += 2.0;
textRect.w -= 2.0;
textRect.y += 2.0;
textRect.h -= 2.0;
textRect.x += textAlignx;
textRect.y += textAligny;
}
origin.Set( rect.x() + ( rect.w() / 2 ), rect.y() + ( rect.h() / 2 ) );
}
void idSimpleWindow::Redraw(float x, float y) {
if (!visible) {
return;
}
CalcClientRect(0, 0);
dc->SetFont(fontNum);
drawRect.Offset(x, y);
clientRect.Offset(x, y);
textRect.Offset(x, y);
SetupTransforms(x, y);
if ( flags & WIN_NOCLIP ) {
dc->EnableClipping( false );
}
DrawBackground(drawRect);
DrawBorderAndCaption(drawRect);
if ( textShadow ) {
idStr shadowText = text;
idRectangle shadowRect = textRect;
shadowText.RemoveColors();
shadowRect.x += textShadow;
shadowRect.y += textShadow;
dc->DrawText( shadowText, textScale, textAlign, colorBlack, shadowRect, !( flags & WIN_NOWRAP ), -1 );
}
dc->DrawText(text, textScale, textAlign, foreColor, textRect, !( flags & WIN_NOWRAP ), -1);
dc->SetTransformInfo(vec3_origin, mat3_identity);
if ( flags & WIN_NOCLIP ) {
dc->EnableClipping( true );
}
drawRect.Offset(-x, -y);
clientRect.Offset(-x, -y);
textRect.Offset(-x, -y);
}
int idSimpleWindow::GetWinVarOffset( idWinVar *wv, drawWin_t* owner) {
int ret = -1;
if ( wv == &rect ) {
ret = (int)&( ( idSimpleWindow * ) 0 )->rect;
}
if ( wv == &backColor ) {
ret = (int)&( ( idSimpleWindow * ) 0 )->backColor;
}
if ( wv == &matColor ) {
ret = (int)&( ( idSimpleWindow * ) 0 )->matColor;
}
if ( wv == &foreColor ) {
ret = (int)&( ( idSimpleWindow * ) 0 )->foreColor;
}
if ( wv == &borderColor ) {
ret = (int)&( ( idSimpleWindow * ) 0 )->borderColor;
}
if ( wv == &textScale ) {
ret = (int)&( ( idSimpleWindow * ) 0 )->textScale;
}
if ( wv == &rotate ) {
ret = (int)&( ( idSimpleWindow * ) 0 )->rotate;
}
if ( ret != -1 ) {
owner->simp = this;
}
return ret;
}
idWinVar *idSimpleWindow::GetWinVarByName(const char *_name) {
idWinVar *retVar = NULL;
if (idStr::Icmp(_name, "background") == 0) {
retVar = &backGroundName;
}
if (idStr::Icmp(_name, "visible") == 0) {
retVar = &visible;
}
if (idStr::Icmp(_name, "rect") == 0) {
retVar = &rect;
}
if (idStr::Icmp(_name, "backColor") == 0) {
retVar = &backColor;
}
if (idStr::Icmp(_name, "matColor") == 0) {
retVar = &matColor;
}
if (idStr::Icmp(_name, "foreColor") == 0) {
retVar = &foreColor;
}
if (idStr::Icmp(_name, "borderColor") == 0) {
retVar = &borderColor;
}
if (idStr::Icmp(_name, "textScale") == 0) {
retVar = &textScale;
}
if (idStr::Icmp(_name, "rotate") == 0) {
retVar = &rotate;
}
if (idStr::Icmp(_name, "shear") == 0) {
retVar = &shear;
}
if (idStr::Icmp(_name, "text") == 0) {
retVar = &text;
}
return retVar;
}
/*
========================
idSimpleWindow::WriteToSaveGame
========================
*/
void idSimpleWindow::WriteToSaveGame( idFile *savefile ) {
savefile->Write( &flags, sizeof( flags ) );
savefile->Write( &drawRect, sizeof( drawRect ) );
savefile->Write( &clientRect, sizeof( clientRect ) );
savefile->Write( &textRect, sizeof( textRect ) );
savefile->Write( &origin, sizeof( origin ) );
savefile->Write( &fontNum, sizeof( fontNum ) );
savefile->Write( &matScalex, sizeof( matScalex ) );
savefile->Write( &matScaley, sizeof( matScaley ) );
savefile->Write( &borderSize, sizeof( borderSize ) );
savefile->Write( &textAlign, sizeof( textAlign ) );
savefile->Write( &textAlignx, sizeof( textAlignx ) );
savefile->Write( &textAligny, sizeof( textAligny ) );
savefile->Write( &textShadow, sizeof( textShadow ) );
text.WriteToSaveGame( savefile );
visible.WriteToSaveGame( savefile );
rect.WriteToSaveGame( savefile );
backColor.WriteToSaveGame( savefile );
matColor.WriteToSaveGame( savefile );
foreColor.WriteToSaveGame( savefile );
borderColor.WriteToSaveGame( savefile );
textScale.WriteToSaveGame( savefile );
rotate.WriteToSaveGame( savefile );
shear.WriteToSaveGame( savefile );
backGroundName.WriteToSaveGame( savefile );
int stringLen;
if ( background ) {
stringLen = strlen( background->GetName() );
savefile->Write( &stringLen, sizeof( stringLen ) );
savefile->Write( background->GetName(), stringLen );
} else {
stringLen = 0;
savefile->Write( &stringLen, sizeof( stringLen ) );
}
}
/*
========================
idSimpleWindow::ReadFromSaveGame
========================
*/
void idSimpleWindow::ReadFromSaveGame( idFile *savefile ) {
savefile->Read( &flags, sizeof( flags ) );
savefile->Read( &drawRect, sizeof( drawRect ) );
savefile->Read( &clientRect, sizeof( clientRect ) );
savefile->Read( &textRect, sizeof( textRect ) );
savefile->Read( &origin, sizeof( origin ) );
savefile->Read( &fontNum, sizeof( fontNum ) );
savefile->Read( &matScalex, sizeof( matScalex ) );
savefile->Read( &matScaley, sizeof( matScaley ) );
savefile->Read( &borderSize, sizeof( borderSize ) );
savefile->Read( &textAlign, sizeof( textAlign ) );
savefile->Read( &textAlignx, sizeof( textAlignx ) );
savefile->Read( &textAligny, sizeof( textAligny ) );
savefile->Read( &textShadow, sizeof( textShadow ) );
text.ReadFromSaveGame( savefile );
visible.ReadFromSaveGame( savefile );
rect.ReadFromSaveGame( savefile );
backColor.ReadFromSaveGame( savefile );
matColor.ReadFromSaveGame( savefile );
foreColor.ReadFromSaveGame( savefile );
borderColor.ReadFromSaveGame( savefile );
textScale.ReadFromSaveGame( savefile );
rotate.ReadFromSaveGame( savefile );
shear.ReadFromSaveGame( savefile );
backGroundName.ReadFromSaveGame( savefile );
int stringLen;
savefile->Read( &stringLen, sizeof( stringLen ) );
if ( stringLen > 0 ) {
idStr backName;
backName.Fill( ' ', stringLen );
savefile->Read( &(backName)[0], stringLen );
background = declManager->FindMaterial( backName );
background->SetSort( SS_GUI );
} else {
background = NULL;
}
}
/*
===============================
*/
size_t idSimpleWindow::Size() {
size_t sz = sizeof(*this);
sz += name.Size();
sz += text.Size();
sz += backGroundName.Size();
return sz;
}

101
neo/ui/SimpleWindow.h Normal file
View File

@@ -0,0 +1,101 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __SIMPLEWIN_H__
#define __SIMPLEWIN_H__
class idUserInterfaceLocal;
class idDeviceContext;
class idSimpleWindow;
typedef struct {
idWindow *win;
idSimpleWindow *simp;
} drawWin_t;
class idSimpleWindow {
friend class idWindow;
public:
idSimpleWindow(idWindow* win);
virtual ~idSimpleWindow();
void Redraw(float x, float y);
void StateChanged( bool redraw );
idStr name;
idWinVar * GetWinVarByName(const char *_name);
int GetWinVarOffset( idWinVar *wv, drawWin_t* owner);
size_t Size();
idWindow* GetParent ( void ) { return mParent; }
virtual void WriteToSaveGame( idFile *savefile );
virtual void ReadFromSaveGame( idFile *savefile );
protected:
void CalcClientRect(float xofs, float yofs);
void SetupTransforms(float x, float y);
void DrawBackground(const idRectangle &drawRect);
void DrawBorderAndCaption(const idRectangle &drawRect);
idUserInterfaceLocal *gui;
idDeviceContext *dc;
int flags;
idRectangle drawRect; // overall rect
idRectangle clientRect; // client area
idRectangle textRect;
idVec2 origin;
int fontNum;
float matScalex;
float matScaley;
float borderSize;
int textAlign;
float textAlignx;
float textAligny;
int textShadow;
idWinStr text;
idWinBool visible;
idWinRectangle rect; // overall rect
idWinVec4 backColor;
idWinVec4 matColor;
idWinVec4 foreColor;
idWinVec4 borderColor;
idWinFloat textScale;
idWinFloat rotate;
idWinVec2 shear;
idWinBackground backGroundName;
const idMaterial* background;
idWindow * mParent;
idWinBool hideCursor;
};
#endif /* !__SIMPLEWIN_H__ */

416
neo/ui/SliderWindow.cpp Normal file
View File

@@ -0,0 +1,416 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "DeviceContext.h"
#include "Window.h"
#include "UserInterfaceLocal.h"
#include "SliderWindow.h"
/*
============
idSliderWindow::CommonInit
============
*/
void idSliderWindow::CommonInit() {
value = 0.0;
low = 0.0;
high = 100.0;
stepSize = 1.0;
thumbMat = declManager->FindMaterial("_default");
buddyWin = NULL;
cvar = NULL;
cvar_init = false;
liveUpdate = true;
vertical = false;
scrollbar = false;
verticalFlip = false;
}
idSliderWindow::idSliderWindow(idDeviceContext *d, idUserInterfaceLocal *g) : idWindow(d, g) {
dc = d;
gui = g;
CommonInit();
}
idSliderWindow::idSliderWindow(idUserInterfaceLocal *g) : idWindow(g) {
gui = g;
CommonInit();
}
idSliderWindow::~idSliderWindow() {
}
bool idSliderWindow::ParseInternalVar(const char *_name, idParser *src) {
if (idStr::Icmp(_name, "stepsize") == 0 || idStr::Icmp(_name, "step") == 0) {
stepSize = src->ParseFloat();
return true;
}
if (idStr::Icmp(_name, "low") == 0) {
low = src->ParseFloat();
return true;
}
if (idStr::Icmp(_name, "high") == 0) {
high = src->ParseFloat();
return true;
}
if (idStr::Icmp(_name, "vertical") == 0) {
vertical = src->ParseBool();
return true;
}
if (idStr::Icmp(_name, "verticalflip") == 0) {
verticalFlip = src->ParseBool();
return true;
}
if (idStr::Icmp(_name, "scrollbar") == 0) {
scrollbar = src->ParseBool();
return true;
}
if (idStr::Icmp(_name, "thumbshader") == 0) {
ParseString(src, thumbShader);
declManager->FindMaterial(thumbShader);
return true;
}
return idWindow::ParseInternalVar(_name, src);
}
idWinVar *idSliderWindow::GetWinVarByName(const char *_name, bool fixup, drawWin_t** owner) {
if (idStr::Icmp(_name, "value") == 0) {
return &value;
}
if (idStr::Icmp(_name, "cvar") == 0) {
return &cvarStr;
}
if ( idStr::Icmp( _name, "liveUpdate" ) == 0 ) {
return &liveUpdate;
}
if ( idStr::Icmp( _name, "cvarGroup" ) == 0 ) {
return &cvarGroup;
}
return idWindow::GetWinVarByName(_name, fixup, owner);
}
const char *idSliderWindow::HandleEvent(const sysEvent_t *event, bool *updateVisuals) {
if (!(event->evType == SE_KEY && event->evValue2)) {
return "";
}
int key = event->evValue;
if ( event->evValue2 && key == K_MOUSE1 ) {
SetCapture(this);
RouteMouseCoords(0.0f, 0.0f);
return "";
}
if ( key == K_RIGHTARROW || key == K_KP_RIGHTARROW || ( key == K_MOUSE2 && gui->CursorY() > thumbRect.y ) ) {
value = value + stepSize;
}
if ( key == K_LEFTARROW || key == K_KP_LEFTARROW || ( key == K_MOUSE2 && gui->CursorY() < thumbRect.y ) ) {
value = value - stepSize;
}
if (buddyWin) {
buddyWin->HandleBuddyUpdate(this);
} else {
gui->SetStateFloat( cvarStr, value );
UpdateCvar( false );
}
return "";
}
void idSliderWindow::SetBuddy(idWindow *buddy) {
buddyWin = buddy;
}
void idSliderWindow::PostParse() {
idWindow::PostParse();
value = 0.0;
thumbMat = declManager->FindMaterial(thumbShader);
thumbMat->SetSort( SS_GUI );
thumbWidth = thumbMat->GetImageWidth();
thumbHeight = thumbMat->GetImageHeight();
//vertical = state.GetBool("vertical");
//scrollbar = state.GetBool("scrollbar");
flags |= (WIN_HOLDCAPTURE | WIN_CANFOCUS);
InitCvar();
}
void idSliderWindow::InitWithDefaults(const char *_name, const idRectangle &_rect, const idVec4 &_foreColor, const idVec4 &_matColor, const char *_background, const char *thumbShader, bool _vertical, bool _scrollbar) {
SetInitialState(_name);
rect = _rect;
foreColor = _foreColor;
matColor = _matColor;
thumbMat = declManager->FindMaterial(thumbShader);
thumbMat->SetSort( SS_GUI );
thumbWidth = thumbMat->GetImageWidth();
thumbHeight = thumbMat->GetImageHeight();
background = declManager->FindMaterial(_background);
background->SetSort( SS_GUI );
vertical = _vertical;
scrollbar = _scrollbar;
flags |= WIN_HOLDCAPTURE;
}
void idSliderWindow::SetRange(float _low, float _high, float _step) {
low = _low;
high = _high;
stepSize = _step;
}
void idSliderWindow::SetValue(float _value) {
value = _value;
}
void idSliderWindow::Draw(int time, float x, float y) {
idVec4 color = foreColor;
if ( !cvar && !buddyWin ) {
return;
}
if ( !thumbWidth || !thumbHeight ) {
thumbWidth = thumbMat->GetImageWidth();
thumbHeight = thumbMat->GetImageHeight();
}
UpdateCvar( true );
if ( value > high ) {
value = high;
} else if ( value < low ) {
value = low;
}
float range = high - low;
if ( range <= 0.0f ) {
return;
}
float thumbPos = (range) ? (value - low) / range : 0.0;
if (vertical) {
if ( verticalFlip ) {
thumbPos = 1.f - thumbPos;
}
thumbPos *= drawRect.h - thumbHeight;
thumbPos += drawRect.y;
thumbRect.y = thumbPos;
thumbRect.x = drawRect.x;
} else {
thumbPos *= drawRect.w - thumbWidth;
thumbPos += drawRect.x;
thumbRect.x = thumbPos;
thumbRect.y = drawRect.y;
}
thumbRect.w = thumbWidth;
thumbRect.h = thumbHeight;
if ( hover && !noEvents && Contains(gui->CursorX(), gui->CursorY()) ) {
color = hoverColor;
} else {
hover = false;
}
if ( flags & WIN_CAPTURE ) {
color = hoverColor;
hover = true;
}
dc->DrawMaterial(thumbRect.x, thumbRect.y, thumbRect.w, thumbRect.h, thumbMat, color);
if ( flags & WIN_FOCUS ) {
dc->DrawRect(thumbRect.x+1.0f, thumbRect.y+1.0f, thumbRect.w-2.0f, thumbRect.h-2.0f, 1.0f, color);
}
}
void idSliderWindow::DrawBackground(const idRectangle &_drawRect) {
if ( !cvar && !buddyWin ) {
return;
}
if ( high - low <= 0.0f ) {
return;
}
idRectangle r = _drawRect;
if (!scrollbar) {
if ( vertical ) {
r.y += thumbHeight / 2.f;
r.h -= thumbHeight;
} else {
r.x += thumbWidth / 2.0;
r.w -= thumbWidth;
}
}
idWindow::DrawBackground(r);
}
const char *idSliderWindow::RouteMouseCoords(float xd, float yd) {
float pct;
if (!(flags & WIN_CAPTURE)) {
return "";
}
idRectangle r = drawRect;
r.x = actualX;
r.y = actualY;
r.x += thumbWidth / 2.0;
r.w -= thumbWidth;
if (vertical) {
r.y += thumbHeight / 2;
r.h -= thumbHeight;
if (gui->CursorY() >= r.y && gui->CursorY() <= r.Bottom()) {
pct = (gui->CursorY() - r.y) / r.h;
if ( verticalFlip ) {
pct = 1.f - pct;
}
value = low + (high - low) * pct;
} else if (gui->CursorY() < r.y) {
if ( verticalFlip ) {
value = high;
} else {
value = low;
}
} else {
if ( verticalFlip ) {
value = low;
} else {
value = high;
}
}
} else {
r.x += thumbWidth / 2;
r.w -= thumbWidth;
if (gui->CursorX() >= r.x && gui->CursorX() <= r.Right()) {
pct = (gui->CursorX() - r.x) / r.w;
value = low + (high - low) * pct;
} else if (gui->CursorX() < r.x) {
value = low;
} else {
value = high;
}
}
if (buddyWin) {
buddyWin->HandleBuddyUpdate(this);
} else {
gui->SetStateFloat( cvarStr, value );
}
UpdateCvar( false );
return "";
}
void idSliderWindow::Activate(bool activate, idStr &act) {
idWindow::Activate(activate, act);
if ( activate ) {
UpdateCvar( true, true );
}
}
/*
============
idSliderWindow::InitCvar
============
*/
void idSliderWindow::InitCvar( ) {
if ( cvarStr[0] == '\0' ) {
if ( !buddyWin ) {
common->Warning( "idSliderWindow::InitCvar: gui '%s' window '%s' has an empty cvar string", gui->GetSourceFile(), name.c_str() );
}
cvar_init = true;
cvar = NULL;
return;
}
cvar = cvarSystem->Find( cvarStr );
if ( !cvar ) {
common->Warning( "idSliderWindow::InitCvar: gui '%s' window '%s' references undefined cvar '%s'", gui->GetSourceFile(), name.c_str(), cvarStr.c_str() );
cvar_init = true;
return;
}
}
/*
============
idSliderWindow::UpdateCvar
============
*/
void idSliderWindow::UpdateCvar( bool read, bool force ) {
if ( buddyWin || !cvar ) {
return;
}
if ( force || liveUpdate ) {
value = cvar->GetFloat();
if ( value != gui->State().GetFloat( cvarStr ) ) {
if ( read ) {
gui->SetStateFloat( cvarStr, value );
} else {
value = gui->State().GetFloat( cvarStr );
cvar->SetFloat( value );
}
}
}
}
/*
============
idSliderWindow::RunNamedEvent
============
*/
void idSliderWindow::RunNamedEvent( const char* eventName ) {
idStr event, group;
if ( !idStr::Cmpn( eventName, "cvar read ", 10 ) ) {
event = eventName;
group = event.Mid( 10, event.Length() - 10 );
if ( !group.Cmp( cvarGroup ) ) {
UpdateCvar( true, true );
}
} else if ( !idStr::Cmpn( eventName, "cvar write ", 11 ) ) {
event = eventName;
group = event.Mid( 11, event.Length() - 11 );
if ( !group.Cmp( cvarGroup ) ) {
UpdateCvar( false, true );
}
}
}

93
neo/ui/SliderWindow.h Normal file
View File

@@ -0,0 +1,93 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __SLIDERWINDOW_H__
#define __SLIDERWINDOW_H__
class idUserInterfaceLocal;
class idSliderWindow : public idWindow {
public:
idSliderWindow(idUserInterfaceLocal *gui);
idSliderWindow(idDeviceContext *d, idUserInterfaceLocal *gui);
virtual ~idSliderWindow();
void InitWithDefaults(const char *_name, const idRectangle &rect, const idVec4 &foreColor, const idVec4 &matColor, const char *_background, const char *thumbShader, bool _vertical, bool _scrollbar);
void SetRange(float _low, float _high, float _step);
float GetLow() { return low; }
float GetHigh() { return high; }
void SetValue(float _value);
float GetValue() { return value; };
virtual size_t Allocated(){return idWindow::Allocated();};
virtual idWinVar * GetWinVarByName(const char *_name, bool winLookup = false, drawWin_t** owner = NULL);
virtual const char *HandleEvent(const sysEvent_t *event, bool *updateVisuals);
virtual void PostParse();
virtual void Draw(int time, float x, float y);
virtual void DrawBackground(const idRectangle &drawRect);
virtual const char *RouteMouseCoords(float xd, float yd);
virtual void Activate(bool activate, idStr &act);
virtual void SetBuddy(idWindow *buddy);
void RunNamedEvent( const char* eventName );
private:
virtual bool ParseInternalVar(const char *name, idParser *src);
void CommonInit();
void InitCvar();
// true: read the updated cvar from cvar system
// false: write to the cvar system
// force == true overrides liveUpdate 0
void UpdateCvar( bool read, bool force = false );
idWinFloat value;
float low;
float high;
float thumbWidth;
float thumbHeight;
float stepSize;
float lastValue;
idRectangle thumbRect;
const idMaterial * thumbMat;
bool vertical;
bool verticalFlip;
bool scrollbar;
idWindow * buddyWin;
idStr thumbShader;
idWinStr cvarStr;
idCVar * cvar;
bool cvar_init;
idWinBool liveUpdate;
idWinStr cvarGroup;
};
#endif /* !__SLIDERWINDOW_H__ */

640
neo/ui/UserInterface.cpp Normal file
View File

@@ -0,0 +1,640 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "ListGUILocal.h"
#include "DeviceContext.h"
#include "Window.h"
#include "UserInterfaceLocal.h"
extern idCVar r_skipGuiShaders; // 1 = don't render any gui elements on surfaces
idUserInterfaceManagerLocal uiManagerLocal;
idUserInterfaceManager * uiManager = &uiManagerLocal;
/*
===============================================================================
idUserInterfaceManagerLocal
===============================================================================
*/
void idUserInterfaceManagerLocal::Init() {
screenRect = idRectangle(0, 0, 640, 480);
dc.Init();
}
void idUserInterfaceManagerLocal::Shutdown() {
guis.DeleteContents( true );
demoGuis.DeleteContents( true );
dc.Shutdown();
}
void idUserInterfaceManagerLocal::Touch( const char *name ) {
idUserInterface *gui = Alloc();
gui->InitFromFile( name );
// delete gui;
}
void idUserInterfaceManagerLocal::WritePrecacheCommands( idFile *f ) {
int c = guis.Num();
for( int i = 0; i < c; i++ ) {
char str[1024];
sprintf( str, "touchGui %s\n", guis[i]->Name() );
common->Printf( "%s", str );
f->Printf( "%s", str );
}
}
void idUserInterfaceManagerLocal::SetSize( float width, float height ) {
dc.SetSize( width, height );
}
void idUserInterfaceManagerLocal::BeginLevelLoad() {
int c = guis.Num();
for ( int i = 0; i < c; i++ ) {
if ( (guis[ i ]->GetDesktop()->GetFlags() & WIN_MENUGUI) == 0 ) {
guis[ i ]->ClearRefs();
/*
delete guis[ i ];
guis.RemoveIndex( i );
i--; c--;
*/
}
}
}
void idUserInterfaceManagerLocal::EndLevelLoad() {
int c = guis.Num();
for ( int i = 0; i < c; i++ ) {
if ( guis[i]->GetRefs() == 0 ) {
//common->Printf( "purging %s.\n", guis[i]->GetSourceFile() );
// use this to make sure no materials still reference this gui
bool remove = true;
for ( int j = 0; j < declManager->GetNumDecls( DECL_MATERIAL ); j++ ) {
const idMaterial *material = static_cast<const idMaterial *>(declManager->DeclByIndex( DECL_MATERIAL, j, false ));
if ( material->GlobalGui() == guis[i] ) {
remove = false;
break;
}
}
if ( remove ) {
delete guis[ i ];
guis.RemoveIndex( i );
i--; c--;
}
}
}
}
void idUserInterfaceManagerLocal::Reload( bool all ) {
ID_TIME_T ts;
int c = guis.Num();
for ( int i = 0; i < c; i++ ) {
if ( !all ) {
fileSystem->ReadFile( guis[i]->GetSourceFile(), NULL, &ts );
if ( ts <= guis[i]->GetTimeStamp() ) {
continue;
}
}
guis[i]->InitFromFile( guis[i]->GetSourceFile() );
common->Printf( "reloading %s.\n", guis[i]->GetSourceFile() );
}
}
void idUserInterfaceManagerLocal::ListGuis() const {
int c = guis.Num();
common->Printf( "\n size refs name\n" );
size_t total = 0;
int copies = 0;
int unique = 0;
for ( int i = 0; i < c; i++ ) {
idUserInterfaceLocal *gui = guis[i];
size_t sz = gui->Size();
bool isUnique = guis[i]->interactive;
if ( isUnique ) {
unique++;
} else {
copies++;
}
common->Printf( "%6.1fk %4i (%s) %s ( %i transitions )\n", sz / 1024.0f, guis[i]->GetRefs(), isUnique ? "unique" : "copy", guis[i]->GetSourceFile(), guis[i]->desktop->NumTransitions() );
total += sz;
}
common->Printf( "===========\n %i total Guis ( %i copies, %i unique ), %.2f total Mbytes", c, copies, unique, total / ( 1024.0f * 1024.0f ) );
}
bool idUserInterfaceManagerLocal::CheckGui( const char *qpath ) const {
idFile *file = fileSystem->OpenFileRead( qpath );
if ( file ) {
fileSystem->CloseFile( file );
return true;
}
return false;
}
idUserInterface *idUserInterfaceManagerLocal::Alloc( void ) const {
return new idUserInterfaceLocal();
}
void idUserInterfaceManagerLocal::DeAlloc( idUserInterface *gui ) {
if ( gui ) {
int c = guis.Num();
for ( int i = 0; i < c; i++ ) {
if ( guis[i] == gui ) {
delete guis[i];
guis.RemoveIndex( i );
return;
}
}
}
}
idUserInterface *idUserInterfaceManagerLocal::FindGui( const char *qpath, bool autoLoad, bool needUnique, bool forceNOTUnique ) {
int c = guis.Num();
for ( int i = 0; i < c; i++ ) {
idUserInterfaceLocal *gui = guis[i];
if ( !idStr::Icmp( guis[i]->GetSourceFile(), qpath ) ) {
if ( !forceNOTUnique && ( needUnique || guis[i]->IsInteractive() ) ) {
break;
}
guis[i]->AddRef();
return guis[i];
}
}
if ( autoLoad ) {
idUserInterface *gui = Alloc();
if ( gui->InitFromFile( qpath ) ) {
gui->SetUniqued( forceNOTUnique ? false : needUnique );
return gui;
} else {
delete gui;
}
}
return NULL;
}
idUserInterface *idUserInterfaceManagerLocal::FindDemoGui( const char *qpath ) {
int c = demoGuis.Num();
for ( int i = 0; i < c; i++ ) {
if ( !idStr::Icmp( demoGuis[i]->GetSourceFile(), qpath ) ) {
return demoGuis[i];
}
}
return NULL;
}
idListGUI * idUserInterfaceManagerLocal::AllocListGUI( void ) const {
return new idListGUILocal();
}
void idUserInterfaceManagerLocal::FreeListGUI( idListGUI *listgui ) {
delete listgui;
}
/*
===============================================================================
idUserInterfaceLocal
===============================================================================
*/
idUserInterfaceLocal::idUserInterfaceLocal() {
cursorX = cursorY = 0.0;
desktop = NULL;
loading = false;
active = false;
interactive = false;
uniqued = false;
bindHandler = NULL;
//so the reg eval in gui parsing doesn't get bogus values
time = 0;
refs = 1;
}
idUserInterfaceLocal::~idUserInterfaceLocal() {
delete desktop;
desktop = NULL;
}
const char *idUserInterfaceLocal::Name() const {
return source;
}
const char *idUserInterfaceLocal::Comment() const {
if ( desktop ) {
return desktop->GetComment();
}
return "";
}
bool idUserInterfaceLocal::IsInteractive() const {
return interactive;
}
bool idUserInterfaceLocal::InitFromFile( const char *qpath, bool rebuild, bool cache ) {
if ( !( qpath && *qpath ) ) {
// FIXME: Memory leak!!
return false;
}
int sz = sizeof( idWindow );
sz = sizeof( idSimpleWindow );
loading = true;
if ( rebuild ) {
delete desktop;
desktop = new idWindow( this );
} else if ( desktop == NULL ) {
desktop = new idWindow( this );
}
source = qpath;
state.Set( "text", "Test Text!" );
idParser src( LEXFL_NOFATALERRORS | LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT );
//Load the timestamp so reload guis will work correctly
fileSystem->ReadFile(qpath, NULL, &timeStamp);
src.LoadFile( qpath );
if ( src.IsLoaded() ) {
idToken token;
while( src.ReadToken( &token ) ) {
if ( idStr::Icmp( token, "windowDef" ) == 0 ) {
desktop->SetDC( &uiManagerLocal.dc );
if ( desktop->Parse( &src, rebuild ) ) {
desktop->SetFlag( WIN_DESKTOP );
desktop->FixupParms();
}
continue;
}
}
state.Set( "name", qpath );
} else {
desktop->SetDC( &uiManagerLocal.dc );
desktop->SetFlag( WIN_DESKTOP );
desktop->name = "Desktop";
desktop->text = va( "Invalid GUI: %s", qpath );
desktop->rect = idRectangle( 0.0f, 0.0f, 640.0f, 480.0f );
desktop->drawRect = desktop->rect;
desktop->foreColor = idVec4( 1.0f, 1.0f, 1.0f, 1.0f );
desktop->backColor = idVec4( 0.0f, 0.0f, 0.0f, 1.0f );
desktop->SetupFromState();
common->Warning( "Couldn't load gui: '%s'", qpath );
}
interactive = desktop->Interactive();
if ( uiManagerLocal.guis.Find( this ) == NULL ) {
uiManagerLocal.guis.Append( this );
}
loading = false;
return true;
}
const char *idUserInterfaceLocal::HandleEvent( const sysEvent_t *event, int _time, bool *updateVisuals ) {
time = _time;
if ( bindHandler && event->evType == SE_KEY && event->evValue2 == 1 ) {
const char *ret = bindHandler->HandleEvent( event, updateVisuals );
bindHandler = NULL;
return ret;
}
if ( event->evType == SE_MOUSE ) {
cursorX += event->evValue;
cursorY += event->evValue2;
if (cursorX < 0) {
cursorX = 0;
}
if (cursorY < 0) {
cursorY = 0;
}
}
if ( desktop ) {
return desktop->HandleEvent( event, updateVisuals );
}
return "";
}
void idUserInterfaceLocal::HandleNamedEvent ( const char* eventName ) {
desktop->RunNamedEvent( eventName );
}
void idUserInterfaceLocal::Redraw( int _time ) {
if ( r_skipGuiShaders.GetInteger() > 5 ) {
return;
}
if ( !loading && desktop ) {
time = _time;
uiManagerLocal.dc.PushClipRect( uiManagerLocal.screenRect );
desktop->Redraw( 0, 0 );
uiManagerLocal.dc.PopClipRect();
}
}
void idUserInterfaceLocal::DrawCursor() {
if ( !desktop || desktop->GetFlags() & WIN_MENUGUI ) {
uiManagerLocal.dc.DrawCursor(&cursorX, &cursorY, 32.0f );
} else {
uiManagerLocal.dc.DrawCursor(&cursorX, &cursorY, 64.0f );
}
}
const idDict &idUserInterfaceLocal::State() const {
return state;
}
void idUserInterfaceLocal::DeleteStateVar( const char *varName ) {
state.Delete( varName );
}
void idUserInterfaceLocal::SetStateString( const char *varName, const char *value ) {
state.Set( varName, value );
}
void idUserInterfaceLocal::SetStateBool( const char *varName, const bool value ) {
state.SetBool( varName, value );
}
void idUserInterfaceLocal::SetStateInt( const char *varName, const int value ) {
state.SetInt( varName, value );
}
void idUserInterfaceLocal::SetStateFloat( const char *varName, const float value ) {
state.SetFloat( varName, value );
}
const char* idUserInterfaceLocal::GetStateString( const char *varName, const char* defaultString ) const {
return state.GetString(varName, defaultString);
}
bool idUserInterfaceLocal::GetStateBool( const char *varName, const char* defaultString ) const {
return state.GetBool(varName, defaultString);
}
int idUserInterfaceLocal::GetStateInt( const char *varName, const char* defaultString ) const {
return state.GetInt(varName, defaultString);
}
float idUserInterfaceLocal::GetStateFloat( const char *varName, const char* defaultString ) const {
return state.GetFloat(varName, defaultString);
}
void idUserInterfaceLocal::StateChanged( int _time, bool redraw ) {
time = _time;
if (desktop) {
desktop->StateChanged( redraw );
}
if ( state.GetBool( "noninteractive" ) ) {
interactive = false;
}
else {
if (desktop) {
interactive = desktop->Interactive();
} else {
interactive = false;
}
}
}
const char *idUserInterfaceLocal::Activate(bool activate, int _time) {
time = _time;
active = activate;
if ( desktop ) {
activateStr = "";
desktop->Activate( activate, activateStr );
return activateStr;
}
return "";
}
void idUserInterfaceLocal::Trigger(int _time) {
time = _time;
if ( desktop ) {
desktop->Trigger();
}
}
void idUserInterfaceLocal::ReadFromDemoFile( class idDemoFile *f ) {
idStr work;
f->ReadDict( state );
source = state.GetString("name");
if (desktop == NULL) {
f->Log("creating new gui\n");
desktop = new idWindow(this);
desktop->SetFlag( WIN_DESKTOP );
desktop->SetDC( &uiManagerLocal.dc );
desktop->ReadFromDemoFile(f);
} else {
f->Log("re-using gui\n");
desktop->ReadFromDemoFile(f, false);
}
f->ReadFloat( cursorX );
f->ReadFloat( cursorY );
bool add = true;
int c = uiManagerLocal.demoGuis.Num();
for ( int i = 0; i < c; i++ ) {
if ( uiManagerLocal.demoGuis[i] == this ) {
add = false;
break;
}
}
if (add) {
uiManagerLocal.demoGuis.Append(this);
}
}
void idUserInterfaceLocal::WriteToDemoFile( class idDemoFile *f ) {
idStr work;
f->WriteDict( state );
if (desktop) {
desktop->WriteToDemoFile(f);
}
f->WriteFloat( cursorX );
f->WriteFloat( cursorY );
}
bool idUserInterfaceLocal::WriteToSaveGame( idFile *savefile ) const {
int len;
const idKeyValue *kv;
const char *string;
int num = state.GetNumKeyVals();
savefile->Write( &num, sizeof( num ) );
for( int i = 0; i < num; i++ ) {
kv = state.GetKeyVal( i );
len = kv->GetKey().Length();
string = kv->GetKey().c_str();
savefile->Write( &len, sizeof( len ) );
savefile->Write( string, len );
len = kv->GetValue().Length();
string = kv->GetValue().c_str();
savefile->Write( &len, sizeof( len ) );
savefile->Write( string, len );
}
savefile->Write( &active, sizeof( active ) );
savefile->Write( &interactive, sizeof( interactive ) );
savefile->Write( &uniqued, sizeof( uniqued ) );
savefile->Write( &time, sizeof( time ) );
len = activateStr.Length();
savefile->Write( &len, sizeof( len ) );
savefile->Write( activateStr.c_str(), len );
len = pendingCmd.Length();
savefile->Write( &len, sizeof( len ) );
savefile->Write( pendingCmd.c_str(), len );
len = returnCmd.Length();
savefile->Write( &len, sizeof( len ) );
savefile->Write( returnCmd.c_str(), len );
savefile->Write( &cursorX, sizeof( cursorX ) );
savefile->Write( &cursorY, sizeof( cursorY ) );
desktop->WriteToSaveGame( savefile );
return true;
}
bool idUserInterfaceLocal::ReadFromSaveGame( idFile *savefile ) {
int num;
int i, len;
idStr key;
idStr value;
savefile->Read( &num, sizeof( num ) );
state.Clear();
for( i = 0; i < num; i++ ) {
savefile->Read( &len, sizeof( len ) );
key.Fill( ' ', len );
savefile->Read( &key[0], len );
savefile->Read( &len, sizeof( len ) );
value.Fill( ' ', len );
savefile->Read( &value[0], len );
state.Set( key, value );
}
savefile->Read( &active, sizeof( active ) );
savefile->Read( &interactive, sizeof( interactive ) );
savefile->Read( &uniqued, sizeof( uniqued ) );
savefile->Read( &time, sizeof( time ) );
savefile->Read( &len, sizeof( len ) );
activateStr.Fill( ' ', len );
savefile->Read( &activateStr[0], len );
savefile->Read( &len, sizeof( len ) );
pendingCmd.Fill( ' ', len );
savefile->Read( &pendingCmd[0], len );
savefile->Read( &len, sizeof( len ) );
returnCmd.Fill( ' ', len );
savefile->Read( &returnCmd[0], len );
savefile->Read( &cursorX, sizeof( cursorX ) );
savefile->Read( &cursorY, sizeof( cursorY ) );
desktop->ReadFromSaveGame( savefile );
return true;
}
size_t idUserInterfaceLocal::Size() {
size_t sz = sizeof(*this) + state.Size() + source.Allocated();
if ( desktop ) {
sz += desktop->Size();
}
return sz;
}
void idUserInterfaceLocal::RecurseSetKeyBindingNames( idWindow *window ) {
int i;
idWinVar *v = window->GetWinVarByName( "bind" );
if ( v ) {
SetStateString( v->GetName(), idKeyInput::KeysFromBinding( v->GetName() ) );
}
i = 0;
while ( i < window->GetChildCount() ) {
idWindow *next = window->GetChild( i );
if ( next ) {
RecurseSetKeyBindingNames( next );
}
i++;
}
}
/*
==============
idUserInterfaceLocal::SetKeyBindingNames
==============
*/
void idUserInterfaceLocal::SetKeyBindingNames( void ) {
if ( !desktop ) {
return;
}
// walk the windows
RecurseSetKeyBindingNames( desktop );
}
/*
==============
idUserInterfaceLocal::SetCursor
==============
*/
void idUserInterfaceLocal::SetCursor( float x, float y ) {
cursorX = x;
cursorY = y;
}

162
neo/ui/UserInterface.h Normal file
View File

@@ -0,0 +1,162 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __USERINTERFACE_H__
#define __USERINTERFACE_H__
/*
===============================================================================
Draws an interactive 2D surface.
Used for all user interaction with the game.
===============================================================================
*/
class idFile;
class idDemoFile;
class idUserInterface {
public:
virtual ~idUserInterface() {};
// Returns the name of the gui.
virtual const char * Name() const = 0;
// Returns a comment on the gui.
virtual const char * Comment() const = 0;
// Returns true if the gui is interactive.
virtual bool IsInteractive() const = 0;
virtual bool IsUniqued() const = 0;
virtual void SetUniqued( bool b ) = 0;
// returns false if it failed to load
virtual bool InitFromFile( const char *qpath, bool rebuild = true, bool cache = true ) = 0;
// handles an event, can return an action string, the caller interprets
// any return and acts accordingly
virtual const char * HandleEvent( const sysEvent_t *event, int time, bool *updateVisuals = NULL ) = 0;
// handles a named event
virtual void HandleNamedEvent( const char *eventName ) = 0;
// repaints the ui
virtual void Redraw( int time ) = 0;
// repaints the cursor
virtual void DrawCursor() = 0;
// Provides read access to the idDict that holds this gui's state.
virtual const idDict & State() const = 0;
// Removes a gui state variable
virtual void DeleteStateVar( const char *varName ) = 0;
// Sets a gui state variable.
virtual void SetStateString( const char *varName, const char *value ) = 0;
virtual void SetStateBool( const char *varName, const bool value ) = 0;
virtual void SetStateInt( const char *varName, const int value ) = 0;
virtual void SetStateFloat( const char *varName, const float value ) = 0;
// Gets a gui state variable
virtual const char* GetStateString( const char *varName, const char* defaultString = "" ) const = 0;
virtual bool GetStateBool( const char *varName, const char* defaultString = "0" ) const = 0;
virtual int GetStateInt( const char *varName, const char* defaultString = "0" ) const = 0;
virtual float GetStateFloat( const char *varName, const char* defaultString = "0" ) const = 0;
// The state has changed and the gui needs to update from the state idDict.
virtual void StateChanged( int time, bool redraw = false ) = 0;
// Activated the gui.
virtual const char * Activate( bool activate, int time ) = 0;
// Triggers the gui and runs the onTrigger scripts.
virtual void Trigger( int time ) = 0;
virtual void ReadFromDemoFile( class idDemoFile *f ) = 0;
virtual void WriteToDemoFile( class idDemoFile *f ) = 0;
virtual bool WriteToSaveGame( idFile *savefile ) const = 0;
virtual bool ReadFromSaveGame( idFile *savefile ) = 0;
virtual void SetKeyBindingNames( void ) = 0;
virtual void SetCursor( float x, float y ) = 0;
virtual float CursorX() = 0;
virtual float CursorY() = 0;
};
class idUserInterfaceManager {
public:
virtual ~idUserInterfaceManager( void ) {};
virtual void Init() = 0;
virtual void Shutdown() = 0;
virtual void Touch( const char *name ) = 0;
virtual void WritePrecacheCommands( idFile *f ) = 0;
// Sets the size for 640x480 adjustment.
virtual void SetSize( float width, float height ) = 0;
virtual void BeginLevelLoad() = 0;
virtual void EndLevelLoad() = 0;
// Reloads changed guis, or all guis.
virtual void Reload( bool all ) = 0;
// lists all guis
virtual void ListGuis() const = 0;
// Returns true if gui exists.
virtual bool CheckGui( const char *qpath ) const = 0;
// Allocates a new gui.
virtual idUserInterface * Alloc( void ) const = 0;
// De-allocates a gui.. ONLY USE FOR PRECACHING
virtual void DeAlloc( idUserInterface *gui ) = 0;
// Returns NULL if gui by that name does not exist.
virtual idUserInterface * FindGui( const char *qpath, bool autoLoad = false, bool needUnique = false, bool forceUnique = false ) = 0;
// Returns NULL if gui by that name does not exist.
virtual idUserInterface * FindDemoGui( const char *qpath ) = 0;
// Allocates a new GUI list handler
virtual idListGUI * AllocListGUI( void ) const = 0;
// De-allocates a list gui
virtual void FreeListGUI( idListGUI *listgui ) = 0;
};
extern idUserInterfaceManager * uiManager;
#endif /* !__USERINTERFACE_H__ */

146
neo/ui/UserInterfaceLocal.h Normal file
View File

@@ -0,0 +1,146 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
class idWindow;
class idUserInterfaceLocal : public idUserInterface {
friend class idUserInterfaceManagerLocal;
public:
idUserInterfaceLocal();
virtual ~idUserInterfaceLocal();
virtual const char * Name() const;
virtual const char * Comment() const;
virtual bool IsInteractive() const;
virtual bool InitFromFile( const char *qpath, bool rebuild = true, bool cache = true );
virtual const char * HandleEvent( const sysEvent_t *event, int time, bool *updateVisuals );
virtual void HandleNamedEvent( const char* namedEvent );
virtual void Redraw( int time );
virtual void DrawCursor();
virtual const idDict & State() const;
virtual void DeleteStateVar( const char *varName );
virtual void SetStateString( const char *varName, const char *value );
virtual void SetStateBool( const char *varName, const bool value );
virtual void SetStateInt( const char *varName, const int value );
virtual void SetStateFloat( const char *varName, const float value );
// Gets a gui state variable
virtual const char* GetStateString( const char *varName, const char* defaultString = "" ) const;
virtual bool GetStateBool( const char *varName, const char* defaultString = "0" ) const;
virtual int GetStateInt( const char *varName, const char* defaultString = "0" ) const;
virtual float GetStateFloat( const char *varName, const char* defaultString = "0" ) const;
virtual void StateChanged( int time, bool redraw );
virtual const char * Activate( bool activate, int time );
virtual void Trigger( int time );
virtual void ReadFromDemoFile( class idDemoFile *f );
virtual void WriteToDemoFile( class idDemoFile *f );
virtual bool WriteToSaveGame( idFile *savefile ) const;
virtual bool ReadFromSaveGame( idFile *savefile );
virtual void SetKeyBindingNames( void );
virtual bool IsUniqued() const { return uniqued; };
virtual void SetUniqued( bool b ) { uniqued = b; };
virtual void SetCursor( float x, float y );
virtual float CursorX() { return cursorX; }
virtual float CursorY() { return cursorY; }
size_t Size();
idDict * GetStateDict() { return &state; }
const char * GetSourceFile( void ) const { return source; }
ID_TIME_T GetTimeStamp( void ) const { return timeStamp; }
idWindow * GetDesktop() const { return desktop; }
void SetBindHandler( idWindow *win ) { bindHandler = win; }
bool Active() const { return active; }
int GetTime() const { return time; }
void SetTime( int _time ) { time = _time; }
void ClearRefs() { refs = 0; }
void AddRef() { refs++; }
int GetRefs() { return refs; }
void RecurseSetKeyBindingNames( idWindow *window );
idStr &GetPendingCmd() { return pendingCmd; };
idStr &GetReturnCmd() { return returnCmd; };
private:
bool active;
bool loading;
bool interactive;
bool uniqued;
idDict state;
idWindow * desktop;
idWindow * bindHandler;
idStr source;
idStr activateStr;
idStr pendingCmd;
idStr returnCmd;
ID_TIME_T timeStamp;
float cursorX;
float cursorY;
int time;
int refs;
};
class idUserInterfaceManagerLocal : public idUserInterfaceManager {
friend class idUserInterfaceLocal;
public:
virtual void Init();
virtual void Shutdown();
virtual void Touch( const char *name );
virtual void WritePrecacheCommands( idFile *f );
virtual void SetSize( float width, float height );
virtual void BeginLevelLoad();
virtual void EndLevelLoad();
virtual void Reload( bool all );
virtual void ListGuis() const;
virtual bool CheckGui( const char *qpath ) const;
virtual idUserInterface * Alloc( void ) const;
virtual void DeAlloc( idUserInterface *gui );
virtual idUserInterface * FindGui( const char *qpath, bool autoLoad = false, bool needInteractive = false, bool forceUnique = false );
virtual idUserInterface * FindDemoGui( const char *qpath );
virtual idListGUI * AllocListGUI( void ) const;
virtual void FreeListGUI( idListGUI *listgui );
private:
idRectangle screenRect;
idDeviceContext dc;
idList<idUserInterfaceLocal*> guis;
idList<idUserInterfaceLocal*> demoGuis;
};

4230
neo/ui/Window.cpp Normal file

File diff suppressed because it is too large Load Diff

455
neo/ui/Window.h Normal file
View File

@@ -0,0 +1,455 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __WINDOW_H__
#define __WINDOW_H__
#include "Rectangle.h"
#include "DeviceContext.h"
#include "RegExp.h"
#include "Winvar.h"
#include "GuiScript.h"
#include "SimpleWindow.h"
const int WIN_CHILD = 0x00000001;
const int WIN_CAPTION = 0x00000002;
const int WIN_BORDER = 0x00000004;
const int WIN_SIZABLE = 0x00000008;
const int WIN_MOVABLE = 0x00000010;
const int WIN_FOCUS = 0x00000020;
const int WIN_CAPTURE = 0x00000040;
const int WIN_HCENTER = 0x00000080;
const int WIN_VCENTER = 0x00000100;
const int WIN_MODAL = 0x00000200;
const int WIN_INTRANSITION = 0x00000400;
const int WIN_CANFOCUS = 0x00000800;
const int WIN_SELECTED = 0x00001000;
const int WIN_TRANSFORM = 0x00002000;
const int WIN_HOLDCAPTURE = 0x00004000;
const int WIN_NOWRAP = 0x00008000;
const int WIN_NOCLIP = 0x00010000;
const int WIN_INVERTRECT = 0x00020000;
const int WIN_NATURALMAT = 0x00040000;
const int WIN_NOCURSOR = 0x00080000;
const int WIN_MENUGUI = 0x00100000;
const int WIN_ACTIVE = 0x00200000;
const int WIN_SHOWCOORDS = 0x00400000;
const int WIN_SHOWTIME = 0x00800000;
const int WIN_WANTENTER = 0x01000000;
const int WIN_DESKTOP = 0x10000000;
const char CAPTION_HEIGHT[] = "16.0";
const char SCROLLER_SIZE[] = "16.0";
const int SCROLLBAR_SIZE = 16;
const int MAX_WINDOW_NAME = 32;
const int MAX_LIST_ITEMS = 1024;
const char DEFAULT_BACKCOLOR[] = "1 1 1 1";
const char DEFAULT_FORECOLOR[] = "0 0 0 1";
const char DEFAULT_BORDERCOLOR[] = "0 0 0 1";
const char DEFAULT_TEXTSCALE[] = "0.4";
typedef enum {
WOP_TYPE_ADD,
WOP_TYPE_SUBTRACT,
WOP_TYPE_MULTIPLY,
WOP_TYPE_DIVIDE,
WOP_TYPE_MOD,
WOP_TYPE_TABLE,
WOP_TYPE_GT,
WOP_TYPE_GE,
WOP_TYPE_LT,
WOP_TYPE_LE,
WOP_TYPE_EQ,
WOP_TYPE_NE,
WOP_TYPE_AND,
WOP_TYPE_OR,
WOP_TYPE_VAR,
WOP_TYPE_VARS,
WOP_TYPE_VARF,
WOP_TYPE_VARI,
WOP_TYPE_VARB,
WOP_TYPE_COND
} wexpOpType_t;
typedef enum {
WEXP_REG_TIME,
WEXP_REG_NUM_PREDEFINED
} wexpRegister_t;
typedef struct {
wexpOpType_t opType;
int a, b, c, d;
} wexpOp_t;
struct idRegEntry {
const char *name;
idRegister::REGTYPE type;
int index;
};
class rvGEWindowWrapper;
class idWindow;
struct idTimeLineEvent {
idTimeLineEvent() {
event = new idGuiScriptList;
}
~idTimeLineEvent() {
delete event;
}
int time;
idGuiScriptList *event;
bool pending;
size_t Size() {
return sizeof(*this) + event->Size();
}
};
class rvNamedEvent
{
public:
rvNamedEvent(const char* name)
{
mEvent = new idGuiScriptList;
mName = name;
}
~rvNamedEvent(void)
{
delete mEvent;
}
size_t Size()
{
return sizeof(*this) + mEvent->Size();
}
idStr mName;
idGuiScriptList* mEvent;
};
struct idTransitionData {
idWinVar *data;
int offset;
idInterpolateAccelDecelLinear<idVec4> interp;
};
class idUserInterfaceLocal;
class idWindow {
public:
idWindow(idUserInterfaceLocal *gui);
idWindow(idDeviceContext *d, idUserInterfaceLocal *gui);
virtual ~idWindow();
enum {
ON_MOUSEENTER = 0,
ON_MOUSEEXIT,
ON_ACTION,
ON_ACTIVATE,
ON_DEACTIVATE,
ON_ESC,
ON_FRAME,
ON_TRIGGER,
ON_ACTIONRELEASE,
ON_ENTER,
ON_ENTERRELEASE,
SCRIPT_COUNT
};
enum {
ADJUST_MOVE = 0,
ADJUST_TOP,
ADJUST_RIGHT,
ADJUST_BOTTOM,
ADJUST_LEFT,
ADJUST_TOPLEFT,
ADJUST_BOTTOMRIGHT,
ADJUST_TOPRIGHT,
ADJUST_BOTTOMLEFT
};
static const char *ScriptNames[SCRIPT_COUNT];
static const idRegEntry RegisterVars[];
static const int NumRegisterVars;
void SetDC(idDeviceContext *d);
idDeviceContext* GetDC ( void ) { return dc; }
idWindow *SetFocus(idWindow *w, bool scripts = true);
idWindow *SetCapture(idWindow *w);
void SetParent(idWindow *w);
void SetFlag(unsigned int f);
void ClearFlag(unsigned int f);
unsigned GetFlags() {return flags;};
void Move(float x, float y);
void BringToTop(idWindow *w);
void Adjust(float xd, float yd);
void SetAdjustMode(idWindow *child);
void Size(float x, float y, float w, float h);
void SetupFromState();
void SetupBackground();
drawWin_t *FindChildByName(const char *name);
idSimpleWindow *FindSimpleWinByName(const char *_name);
idWindow *GetParent() { return parent; }
idUserInterfaceLocal *GetGui() {return gui;};
bool Contains(float x, float y);
size_t Size();
virtual size_t Allocated();
idStr* GetStrPtrByName(const char *_name);
virtual idWinVar *GetWinVarByName (const char *_name, bool winLookup = false, drawWin_t** owner = NULL);
int GetWinVarOffset( idWinVar *wv, drawWin_t *dw );
float GetMaxCharHeight();
float GetMaxCharWidth();
void SetFont();
void SetInitialState(const char *_name);
void AddChild(idWindow *win);
void DebugDraw(int time, float x, float y);
void CalcClientRect(float xofs, float yofs);
void CommonInit();
void CleanUp();
void DrawBorderAndCaption(const idRectangle &drawRect);
void DrawCaption(int time, float x, float y);
void SetupTransforms(float x, float y);
bool Contains(const idRectangle &sr, float x, float y);
const char *GetName() { return name; };
virtual bool Parse(idParser *src, bool rebuild = true);
virtual const char *HandleEvent(const sysEvent_t *event, bool *updateVisuals);
void CalcRects(float x, float y);
virtual void Redraw(float x, float y);
virtual void ArchiveToDictionary(idDict *dict, bool useNames = true);
virtual void InitFromDictionary(idDict *dict, bool byName = true);
virtual void PostParse();
virtual void Activate( bool activate, idStr &act );
virtual void Trigger();
virtual void GainFocus();
virtual void LoseFocus();
virtual void GainCapture();
virtual void LoseCapture();
virtual void Sized();
virtual void Moved();
virtual void Draw(int time, float x, float y);
virtual void MouseExit();
virtual void MouseEnter();
virtual void DrawBackground(const idRectangle &drawRect);
virtual const char *RouteMouseCoords(float xd, float yd);
virtual void SetBuddy(idWindow *buddy) {};
virtual void HandleBuddyUpdate(idWindow *buddy) {};
virtual void StateChanged( bool redraw );
virtual void ReadFromDemoFile( class idDemoFile *f, bool rebuild = true );
virtual void WriteToDemoFile( class idDemoFile *f );
// SaveGame support
void WriteSaveGameString( const char *string, idFile *savefile );
void WriteSaveGameTransition( idTransitionData &trans, idFile *savefile );
virtual void WriteToSaveGame( idFile *savefile );
void ReadSaveGameString( idStr &string, idFile *savefile );
void ReadSaveGameTransition( idTransitionData & trans, idFile *savefile );
virtual void ReadFromSaveGame( idFile *savefile );
void FixupTransitions();
virtual void HasAction(){};
virtual void HasScripts(){};
void FixupParms();
void GetScriptString(const char *name, idStr &out);
void SetScriptParams();
bool HasOps() { return (ops.Num() > 0); };
float EvalRegs(int test = -1, bool force = false);
void StartTransition();
void AddTransition(idWinVar *dest, idVec4 from, idVec4 to, int time, float accelTime, float decelTime);
void ResetTime(int time);
void ResetCinematics();
int NumTransitions();
bool ParseScript(idParser *src, idGuiScriptList &list, int *timeParm = NULL, bool allowIf = false);
bool RunScript(int n);
bool RunScriptList(idGuiScriptList *src);
void SetRegs(const char *key, const char *val);
int ParseExpression( idParser *src, idWinVar *var = NULL, int component = 0 );
int ExpressionConstant(float f);
idRegisterList *RegList() { return &regList; }
void AddCommand(const char *cmd);
void AddUpdateVar(idWinVar *var);
bool Interactive();
bool ContainsStateVars();
void SetChildWinVarVal(const char *name, const char *var, const char *val);
idWindow *GetFocusedChild();
idWindow *GetCaptureChild();
const char *GetComment() { return comment; }
void SetComment( const char * p) { comment = p; }
idStr cmd;
virtual void RunNamedEvent ( const char* eventName );
void AddDefinedVar ( idWinVar* var );
idWindow* FindChildByPoint ( float x, float y, idWindow* below = NULL );
int GetChildIndex ( idWindow* window );
int GetChildCount ( void );
idWindow* GetChild ( int index );
void RemoveChild ( idWindow *win );
bool InsertChild ( idWindow *win, idWindow* before );
void ScreenToClient ( idRectangle* rect );
void ClientToScreen ( idRectangle* rect );
bool UpdateFromDictionary ( idDict& dict );
protected:
friend class rvGEWindowWrapper;
idWindow* FindChildByPoint ( float x, float y, idWindow** below );
void SetDefaults ( void );
friend class idSimpleWindow;
friend class idUserInterfaceLocal;
bool IsSimple();
void UpdateWinVars();
void DisableRegister(const char *_name);
void Transition();
void Time();
bool RunTimeEvents(int time);
void Dump();
int ExpressionTemporary();
wexpOp_t *ExpressionOp();
int EmitOp( int a, int b, wexpOpType_t opType, wexpOp_t **opp = NULL );
int ParseEmitOp( idParser *src, int a, wexpOpType_t opType, int priority, wexpOp_t **opp = NULL );
int ParseTerm( idParser *src, idWinVar *var = NULL, int component = 0 );
int ParseExpressionPriority( idParser *src, int priority, idWinVar *var = NULL, int component = 0 );
void EvaluateRegisters(float *registers);
void SaveExpressionParseState();
void RestoreExpressionParseState();
void ParseBracedExpression(idParser *src);
bool ParseScriptEntry(const char *name, idParser *src);
bool ParseRegEntry(const char *name, idParser *src);
virtual bool ParseInternalVar(const char *name, idParser *src);
void ParseString(idParser *src, idStr &out);
void ParseVec4(idParser *src, idVec4 &out);
void ConvertRegEntry(const char *name, idParser *src, idStr &out, int tabs);
float actualX; // physical coords
float actualY; // ''
int childID; // this childs id
unsigned int flags; // visible, focus, mouseover, cursor, border, etc..
int lastTimeRun; //
idRectangle drawRect; // overall rect
idRectangle clientRect; // client area
idVec2 origin;
int timeLine; // time stamp used for various fx
float xOffset;
float yOffset;
float forceAspectWidth;
float forceAspectHeight;
float matScalex;
float matScaley;
float borderSize;
float textAlignx;
float textAligny;
idStr name;
idStr comment;
idVec2 shear;
signed char textShadow;
unsigned char fontNum;
unsigned char cursor; //
signed char textAlign;
idWinBool noTime; //
idWinBool visible; //
idWinBool noEvents;
idWinRectangle rect; // overall rect
idWinVec4 backColor;
idWinVec4 matColor;
idWinVec4 foreColor;
idWinVec4 hoverColor;
idWinVec4 borderColor;
idWinFloat textScale;
idWinFloat rotate;
idWinStr text;
idWinBackground backGroundName; //
idList<idWinVar*> definedVars;
idList<idWinVar*> updateVars;
idRectangle textRect; // text extented rect
const idMaterial *background; // background asset
idWindow *parent; // parent window
idList<idWindow*> children; // child windows
idList<drawWin_t> drawWindows;
idWindow *focusedChild; // if a child window has the focus
idWindow *captureChild; // if a child window has mouse capture
idWindow *overChild; // if a child window has mouse capture
bool hover;
idDeviceContext *dc;
idUserInterfaceLocal *gui;
static idCVar gui_debug;
static idCVar gui_edit;
idGuiScriptList *scripts[SCRIPT_COUNT];
bool *saveTemps;
idList<idTimeLineEvent*> timeLineEvents;
idList<idTransitionData> transitions;
static bool registerIsTemporary[MAX_EXPRESSION_REGISTERS]; // statics to assist during parsing
idList<wexpOp_t> ops; // evaluate to make expressionRegisters
idList<float> expressionRegisters;
idList<wexpOp_t> *saveOps; // evaluate to make expressionRegisters
idList<rvNamedEvent*> namedEvents; // added named events
idList<float> *saveRegs;
idRegisterList regList;
idWinBool hideCursor;
};
ID_INLINE void idWindow::AddDefinedVar( idWinVar* var ) {
definedVars.AddUnique( var );
}
#endif /* !__WINDOW_H__ */

83
neo/ui/Winvar.cpp Normal file
View File

@@ -0,0 +1,83 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "Window.h"
#include "Winvar.h"
#include "UserInterfaceLocal.h"
idWinVar::idWinVar() {
guiDict = NULL;
name = NULL;
eval = true;
}
idWinVar::~idWinVar() {
delete name;
name = NULL;
}
void idWinVar::SetGuiInfo(idDict *gd, const char *_name) {
guiDict = gd;
SetName(_name);
}
void idWinVar::Init(const char *_name, idWindow *win) {
idStr key = _name;
guiDict = NULL;
int len = key.Length();
if (len > 5 && key[0] == 'g' && key[1] == 'u' && key[2] == 'i' && key[3] == ':') {
key = key.Right(len - VAR_GUIPREFIX_LEN);
SetGuiInfo( win->GetGui()->GetStateDict(), key );
win->AddUpdateVar(this);
} else {
Set(_name);
}
}
void idMultiWinVar::Set( const char *val ) {
for ( int i = 0; i < Num(); i++ ) {
(*this)[i]->Set( val );
}
}
void idMultiWinVar::Update( void ) {
for ( int i = 0; i < Num(); i++ ) {
(*this)[i]->Update();
}
}
void idMultiWinVar::SetGuiInfo( idDict *dict ) {
for ( int i = 0; i < Num(); i++ ) {
(*this)[i]->SetGuiInfo( dict, (*this)[i]->c_str() );
}
}

856
neo/ui/Winvar.h Normal file
View File

@@ -0,0 +1,856 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#ifndef __WINVAR_H__
#define __WINVAR_H__
#include "Rectangle.h"
static const char *VAR_GUIPREFIX = "gui::";
static const int VAR_GUIPREFIX_LEN = strlen(VAR_GUIPREFIX);
class idWindow;
class idWinVar {
public:
idWinVar();
virtual ~idWinVar();
void SetGuiInfo(idDict *gd, const char *_name);
const char *GetName() const {
if (name) {
if (guiDict && *name == '*') {
return guiDict->GetString(&name[1]);
}
return name;
}
return "";
}
void SetName(const char *_name) {
delete []name;
name = NULL;
if (_name) {
name = new char[strlen(_name)+1];
strcpy(name, _name);
}
}
idWinVar &operator=( const idWinVar &other ) {
guiDict = other.guiDict;
SetName(other.name);
return *this;
}
idDict *GetDict() const { return guiDict; }
bool NeedsUpdate() { return (guiDict != NULL); }
virtual void Init(const char *_name, idWindow* win) = 0;
virtual void Set(const char *val) = 0;
virtual void Update() = 0;
virtual const char *c_str() const = 0;
virtual size_t Size() { size_t sz = (name) ? strlen(name) : 0; return sz + sizeof(*this); }
virtual void WriteToSaveGame( idFile *savefile ) = 0;
virtual void ReadFromSaveGame( idFile *savefile ) = 0;
virtual float x( void ) const = 0;
void SetEval(bool b) {
eval = b;
}
bool GetEval() {
return eval;
}
protected:
idDict *guiDict;
char *name;
bool eval;
};
class idWinBool : public idWinVar {
public:
idWinBool() : idWinVar() {};
~idWinBool() {};
virtual void Init(const char *_name, idWindow *win) { idWinVar::Init(_name, win);
if (guiDict) {
data = guiDict->GetBool(GetName());
}
}
int operator==( const bool &other ) { return (other == data); }
bool &operator=( const bool &other ) {
data = other;
if (guiDict) {
guiDict->SetBool(GetName(), data);
}
return data;
}
idWinBool &operator=( const idWinBool &other ) {
idWinVar::operator=(other);
data = other.data;
return *this;
}
operator bool() const { return data; }
virtual void Set(const char *val) {
data = ( atoi( val ) != 0 );
if (guiDict) {
guiDict->SetBool(GetName(), data);
}
}
virtual void Update() {
const char *s = GetName();
if ( guiDict && s[0] != '\0' ) {
data = guiDict->GetBool( s );
}
}
virtual const char *c_str() const {return va("%i", data); }
// SaveGames
virtual void WriteToSaveGame( idFile *savefile ) {
savefile->Write( &eval, sizeof( eval ) );
savefile->Write( &data, sizeof( data ) );
}
virtual void ReadFromSaveGame( idFile *savefile ) {
savefile->Read( &eval, sizeof( eval ) );
savefile->Read( &data, sizeof( data ) );
}
virtual float x( void ) const { return data ? 1.0f : 0.0f; };
protected:
bool data;
};
class idWinStr : public idWinVar {
public:
idWinStr() : idWinVar() {};
~idWinStr() {};
virtual void Init(const char *_name, idWindow *win) {
idWinVar::Init(_name, win);
if (guiDict) {
data = guiDict->GetString(GetName());
}
}
int operator==( const idStr &other ) const {
return (other == data);
}
int operator==( const char *other ) const {
return (data == other);
}
idStr &operator=( const idStr &other ) {
data = other;
if (guiDict) {
guiDict->Set(GetName(), data);
}
return data;
}
idWinStr &operator=( const idWinStr &other ) {
idWinVar::operator=(other);
data = other.data;
return *this;
}
operator const char *() const {
return data.c_str();
}
operator const idStr &() const {
return data;
}
int LengthWithoutColors() {
if (guiDict && name && *name) {
data = guiDict->GetString(GetName());
}
return data.LengthWithoutColors();
}
int Length() {
if (guiDict && name && *name) {
data = guiDict->GetString(GetName());
}
return data.Length();
}
void RemoveColors() {
if (guiDict && name && *name) {
data = guiDict->GetString(GetName());
}
data.RemoveColors();
}
virtual const char *c_str() const {
return data.c_str();
}
virtual void Set(const char *val) {
data = val;
if ( guiDict ) {
guiDict->Set(GetName(), data);
}
}
virtual void Update() {
const char *s = GetName();
if ( guiDict && s[0] != '\0' ) {
data = guiDict->GetString( s );
}
}
virtual size_t Size() {
size_t sz = idWinVar::Size();
return sz +data.Allocated();
}
// SaveGames
virtual void WriteToSaveGame( idFile *savefile ) {
savefile->Write( &eval, sizeof( eval ) );
int len = data.Length();
savefile->Write( &len, sizeof( len ) );
if ( len > 0 ) {
savefile->Write( data.c_str(), len );
}
}
virtual void ReadFromSaveGame( idFile *savefile ) {
savefile->Read( &eval, sizeof( eval ) );
int len;
savefile->Read( &len, sizeof( len ) );
if ( len > 0 ) {
data.Fill( ' ', len );
savefile->Read( &data[0], len );
}
}
// return wether string is emtpy
virtual float x( void ) const { return data[0] ? 1.0f : 0.0f; };
protected:
idStr data;
};
class idWinInt : public idWinVar {
public:
idWinInt() : idWinVar() {};
~idWinInt() {};
virtual void Init(const char *_name, idWindow *win) {
idWinVar::Init(_name, win);
if (guiDict) {
data = guiDict->GetInt(GetName());
}
}
int &operator=( const int &other ) {
data = other;
if (guiDict) {
guiDict->SetInt(GetName(), data);
}
return data;
}
idWinInt &operator=( const idWinInt &other ) {
idWinVar::operator=(other);
data = other.data;
return *this;
}
operator int () const {
return data;
}
virtual void Set(const char *val) {
data = atoi(val);;
if (guiDict) {
guiDict->SetInt(GetName(), data);
}
}
virtual void Update() {
const char *s = GetName();
if ( guiDict && s[0] != '\0' ) {
data = guiDict->GetInt( s );
}
}
virtual const char *c_str() const {
return va("%i", data);
}
// SaveGames
virtual void WriteToSaveGame( idFile *savefile ) {
savefile->Write( &eval, sizeof( eval ) );
savefile->Write( &data, sizeof( data ) );
}
virtual void ReadFromSaveGame( idFile *savefile ) {
savefile->Read( &eval, sizeof( eval ) );
savefile->Read( &data, sizeof( data ) );
}
// no suitable conversion
virtual float x( void ) const { assert( false ); return 0.0f; };
protected:
int data;
};
class idWinFloat : public idWinVar {
public:
idWinFloat() : idWinVar() {};
~idWinFloat() {};
virtual void Init(const char *_name, idWindow *win) {
idWinVar::Init(_name, win);
if (guiDict) {
data = guiDict->GetFloat(GetName());
}
}
idWinFloat &operator=( const idWinFloat &other ) {
idWinVar::operator=(other);
data = other.data;
return *this;
}
float &operator=( const float &other ) {
data = other;
if (guiDict) {
guiDict->SetFloat(GetName(), data);
}
return data;
}
operator float() const {
return data;
}
virtual void Set(const char *val) {
data = atof(val);
if (guiDict) {
guiDict->SetFloat(GetName(), data);
}
}
virtual void Update() {
const char *s = GetName();
if ( guiDict && s[0] != '\0' ) {
data = guiDict->GetFloat( s );
}
}
virtual const char *c_str() const {
return va("%f", data);
}
virtual void WriteToSaveGame( idFile *savefile ) {
savefile->Write( &eval, sizeof( eval ) );
savefile->Write( &data, sizeof( data ) );
}
virtual void ReadFromSaveGame( idFile *savefile ) {
savefile->Read( &eval, sizeof( eval ) );
savefile->Read( &data, sizeof( data ) );
}
virtual float x( void ) const { return data; };
protected:
float data;
};
class idWinRectangle : public idWinVar {
public:
idWinRectangle() : idWinVar() {};
~idWinRectangle() {};
virtual void Init(const char *_name, idWindow *win) {
idWinVar::Init(_name, win);
if (guiDict) {
idVec4 v = guiDict->GetVec4(GetName());
data.x = v.x;
data.y = v.y;
data.w = v.z;
data.h = v.w;
}
}
int operator==( const idRectangle &other ) const {
return (other == data);
}
idWinRectangle &operator=( const idWinRectangle &other ) {
idWinVar::operator=(other);
data = other.data;
return *this;
}
idRectangle &operator=( const idVec4 &other ) {
data = other;
if (guiDict) {
guiDict->SetVec4(GetName(), other);
}
return data;
}
idRectangle &operator=( const idRectangle &other ) {
data = other;
if (guiDict) {
idVec4 v = data.ToVec4();
guiDict->SetVec4(GetName(), v);
}
return data;
}
operator const idRectangle&() const {
return data;
}
float x() const {
return data.x;
}
float y() const {
return data.y;
}
float w() const {
return data.w;
}
float h() const {
return data.h;
}
float Right() const {
return data.Right();
}
float Bottom() const {
return data.Bottom();
}
idVec4 &ToVec4() {
static idVec4 ret;
ret = data.ToVec4();
return ret;
}
virtual void Set(const char *val) {
if ( strchr ( val, ',' ) ) {
sscanf( val, "%f,%f,%f,%f", &data.x, &data.y, &data.w, &data.h );
} else {
sscanf( val, "%f %f %f %f", &data.x, &data.y, &data.w, &data.h );
}
if (guiDict) {
idVec4 v = data.ToVec4();
guiDict->SetVec4(GetName(), v);
}
}
virtual void Update() {
const char *s = GetName();
if ( guiDict && s[0] != '\0' ) {
idVec4 v = guiDict->GetVec4( s );
data.x = v.x;
data.y = v.y;
data.w = v.z;
data.h = v.w;
}
}
virtual const char *c_str() const {
return data.ToVec4().ToString();
}
virtual void WriteToSaveGame( idFile *savefile ) {
savefile->Write( &eval, sizeof( eval ) );
savefile->Write( &data, sizeof( data ) );
}
virtual void ReadFromSaveGame( idFile *savefile ) {
savefile->Read( &eval, sizeof( eval ) );
savefile->Read( &data, sizeof( data ) );
}
protected:
idRectangle data;
};
class idWinVec2 : public idWinVar {
public:
idWinVec2() : idWinVar() {};
~idWinVec2() {};
virtual void Init(const char *_name, idWindow *win) {
idWinVar::Init(_name, win);
if (guiDict) {
data = guiDict->GetVec2(GetName());
}
}
int operator==( const idVec2 &other ) const {
return (other == data);
}
idWinVec2 &operator=( const idWinVec2 &other ) {
idWinVar::operator=(other);
data = other.data;
return *this;
}
idVec2 &operator=( const idVec2 &other ) {
data = other;
if (guiDict) {
guiDict->SetVec2(GetName(), data);
}
return data;
}
float x() const {
return data.x;
}
float y() const {
return data.y;
}
virtual void Set(const char *val) {
if ( strchr ( val, ',' ) ) {
sscanf( val, "%f,%f", &data.x, &data.y );
} else {
sscanf( val, "%f %f", &data.x, &data.y);
}
if (guiDict) {
guiDict->SetVec2(GetName(), data);
}
}
operator const idVec2&() const {
return data;
}
virtual void Update() {
const char *s = GetName();
if ( guiDict && s[0] != '\0' ) {
data = guiDict->GetVec2( s );
}
}
virtual const char *c_str() const {
return data.ToString();
}
void Zero() {
data.Zero();
}
virtual void WriteToSaveGame( idFile *savefile ) {
savefile->Write( &eval, sizeof( eval ) );
savefile->Write( &data, sizeof( data ) );
}
virtual void ReadFromSaveGame( idFile *savefile ) {
savefile->Read( &eval, sizeof( eval ) );
savefile->Read( &data, sizeof( data ) );
}
protected:
idVec2 data;
};
class idWinVec4 : public idWinVar {
public:
idWinVec4() : idWinVar() {};
~idWinVec4() {};
virtual void Init(const char *_name, idWindow *win) {
idWinVar::Init(_name, win);
if (guiDict) {
data = guiDict->GetVec4(GetName());
}
}
int operator==( const idVec4 &other ) const {
return (other == data);
}
idWinVec4 &operator=( const idWinVec4 &other ) {
idWinVar::operator=(other);
data = other.data;
return *this;
}
idVec4 &operator=( const idVec4 &other ) {
data = other;
if (guiDict) {
guiDict->SetVec4(GetName(), data);
}
return data;
}
operator const idVec4&() const {
return data;
}
float x() const {
return data.x;
}
float y() const {
return data.y;
}
float z() const {
return data.z;
}
float w() const {
return data.w;
}
virtual void Set(const char *val) {
if ( strchr ( val, ',' ) ) {
sscanf( val, "%f,%f,%f,%f", &data.x, &data.y, &data.z, &data.w );
} else {
sscanf( val, "%f %f %f %f", &data.x, &data.y, &data.z, &data.w);
}
if ( guiDict ) {
guiDict->SetVec4( GetName(), data );
}
}
virtual void Update() {
const char *s = GetName();
if ( guiDict && s[0] != '\0' ) {
data = guiDict->GetVec4( s );
}
}
virtual const char *c_str() const {
return data.ToString();
}
void Zero() {
data.Zero();
if ( guiDict ) {
guiDict->SetVec4(GetName(), data);
}
}
const idVec3 &ToVec3() const {
return data.ToVec3();
}
virtual void WriteToSaveGame( idFile *savefile ) {
savefile->Write( &eval, sizeof( eval ) );
savefile->Write( &data, sizeof( data ) );
}
virtual void ReadFromSaveGame( idFile *savefile ) {
savefile->Read( &eval, sizeof( eval ) );
savefile->Read( &data, sizeof( data ) );
}
protected:
idVec4 data;
};
class idWinVec3 : public idWinVar {
public:
idWinVec3() : idWinVar() {};
~idWinVec3() {};
virtual void Init(const char *_name, idWindow *win) {
idWinVar::Init(_name, win);
if (guiDict) {
data = guiDict->GetVector(GetName());
}
}
int operator==( const idVec3 &other ) const {
return (other == data);
}
idWinVec3 &operator=( const idWinVec3 &other ) {
idWinVar::operator=(other);
data = other.data;
return *this;
}
idVec3 &operator=( const idVec3 &other ) {
data = other;
if (guiDict) {
guiDict->SetVector(GetName(), data);
}
return data;
}
operator const idVec3&() const {
return data;
}
float x() const {
return data.x;
}
float y() const {
return data.y;
}
float z() const {
return data.z;
}
virtual void Set(const char *val) {
sscanf( val, "%f %f %f", &data.x, &data.y, &data.z);
if (guiDict) {
guiDict->SetVector(GetName(), data);
}
}
virtual void Update() {
const char *s = GetName();
if ( guiDict && s[0] != '\0' ) {
data = guiDict->GetVector( s );
}
}
virtual const char *c_str() const {
return data.ToString();
}
void Zero() {
data.Zero();
if (guiDict) {
guiDict->SetVector(GetName(), data);
}
}
virtual void WriteToSaveGame( idFile *savefile ) {
savefile->Write( &eval, sizeof( eval ) );
savefile->Write( &data, sizeof( data ) );
}
virtual void ReadFromSaveGame( idFile *savefile ) {
savefile->Read( &eval, sizeof( eval ) );
savefile->Read( &data, sizeof( data ) );
}
protected:
idVec3 data;
};
class idWinBackground : public idWinStr {
public:
idWinBackground() : idWinStr() {
mat = NULL;
};
~idWinBackground() {};
virtual void Init(const char *_name, idWindow *win) {
idWinStr::Init(_name, win);
if (guiDict) {
data = guiDict->GetString(GetName());
}
}
int operator==( const idStr &other ) const {
return (other == data);
}
int operator==( const char *other ) const {
return (data == other);
}
idStr &operator=( const idStr &other ) {
data = other;
if (guiDict) {
guiDict->Set(GetName(), data);
}
if (mat) {
if ( data == "" ) {
(*mat) = NULL;
} else {
(*mat) = declManager->FindMaterial(data);
}
}
return data;
}
idWinBackground &operator=( const idWinBackground &other ) {
idWinVar::operator=(other);
data = other.data;
mat = other.mat;
if (mat) {
if ( data == "" ) {
(*mat) = NULL;
} else {
(*mat) = declManager->FindMaterial(data);
}
}
return *this;
}
operator const char *() const {
return data.c_str();
}
operator const idStr &() const {
return data;
}
int Length() {
if (guiDict) {
data = guiDict->GetString(GetName());
}
return data.Length();
}
virtual const char *c_str() const {
return data.c_str();
}
virtual void Set(const char *val) {
data = val;
if (guiDict) {
guiDict->Set(GetName(), data);
}
if (mat) {
if ( data == "" ) {
(*mat) = NULL;
} else {
(*mat) = declManager->FindMaterial(data);
}
}
}
virtual void Update() {
const char *s = GetName();
if ( guiDict && s[0] != '\0' ) {
data = guiDict->GetString( s );
if (mat) {
if ( data == "" ) {
(*mat) = NULL;
} else {
(*mat) = declManager->FindMaterial(data);
}
}
}
}
virtual size_t Size() {
size_t sz = idWinVar::Size();
return sz +data.Allocated();
}
void SetMaterialPtr( const idMaterial **m ) {
mat = m;
}
virtual void WriteToSaveGame( idFile *savefile ) {
savefile->Write( &eval, sizeof( eval ) );
int len = data.Length();
savefile->Write( &len, sizeof( len ) );
if ( len > 0 ) {
savefile->Write( data.c_str(), len );
}
}
virtual void ReadFromSaveGame( idFile *savefile ) {
savefile->Read( &eval, sizeof( eval ) );
int len;
savefile->Read( &len, sizeof( len ) );
if ( len > 0 ) {
data.Fill( ' ', len );
savefile->Read( &data[0], len );
}
if ( mat ) {
if ( len > 0 ) {
(*mat) = declManager->FindMaterial( data );
} else {
(*mat) = NULL;
}
}
}
protected:
idStr data;
const idMaterial **mat;
};
/*
================
idMultiWinVar
multiplexes access to a list if idWinVar*
================
*/
class idMultiWinVar : public idList< idWinVar * > {
public:
void Set( const char *val );
void Update( void );
void SetGuiInfo( idDict *dict );
};
#endif /* !__WINVAR_H__ */