doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BindWindow.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 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.
23 
24 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.
25 
26 ===========================================================================
27 */
28 
29 #include "../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 #include "DeviceContext.h"
33 #include "Window.h"
34 #include "UserInterfaceLocal.h"
35 #include "BindWindow.h"
36 
37 
39  bindName = "";
40  waitingOnKey = false;
41 }
42 
44  dc = d;
45  gui = g;
46  CommonInit();
47 }
48 
50  gui = g;
51  CommonInit();
52 }
53 
55 
56 }
57 
58 
59 const char *idBindWindow::HandleEvent(const sysEvent_t *event, bool *updateVisuals) {
60  static char ret[ 256 ];
61 
62  if (!(event->evType == SE_KEY && event->evValue2)) {
63  return "";
64  }
65 
66  int key = event->evValue;
67 
68  if (waitingOnKey) {
69  waitingOnKey = false;
70  if (key == K_ESCAPE) {
71  idStr::snPrintf( ret, sizeof( ret ), "clearbind \"%s\"", bindName.GetName());
72  } else {
73  idStr::snPrintf( ret, sizeof( ret ), "bind %i \"%s\"", key, bindName.GetName());
74  }
75  return ret;
76  } else {
77  if (key == K_MOUSE1) {
78  waitingOnKey = true;
79  gui->SetBindHandler(this);
80  return "";
81  }
82  }
83 
84  return "";
85 }
86 
87 idWinVar *idBindWindow::GetWinVarByName(const char *_name, bool fixup, drawWin_t** owner) {
88 
89  if (idStr::Icmp(_name, "bind") == 0) {
90  return &bindName;
91  }
92 
93  return idWindow::GetWinVarByName(_name, fixup,owner);
94 }
95 
99  bindName.Update();
100  //bindName = state.GetString("bind");
102 }
103 
104 void idBindWindow::Draw(int time, float x, float y) {
106 
107  idStr str;
108  if ( waitingOnKey ) {
109  str = common->GetLanguageDict()->GetString( "#str_07000" );
110  } else if ( bindName.Length() ) {
111  str = bindName.c_str();
112  } else {
113  str = common->GetLanguageDict()->GetString( "#str_07001" );
114  }
115 
116  if ( waitingOnKey || ( hover && !noEvents && Contains(gui->CursorX(), gui->CursorY()) ) ) {
117  color = hoverColor;
118  } else {
119  hover = false;
120  }
121 
122  dc->DrawText(str, textScale, textAlign, color, textRect, false, -1);
123 }
124 
125 void idBindWindow::Activate( bool activate, idStr &act ) {
126  idWindow::Activate( activate, act );
127  bindName.Update();
128 }
GLubyte g
Definition: glext.h:4662
byte color[4]
Definition: MegaTexture.cpp:54
virtual void Draw(int time, float x, float y)
Definition: BindWindow.cpp:104
static int snPrintf(char *dest, int size, const char *fmt,...) id_attribute((format(printf
Definition: Str.cpp:1465
idWinFloat textScale
Definition: Window.h:405
int Length()
Definition: Winvar.h:192
bool Contains(float x, float y)
Definition: Window.cpp:681
virtual void virtual void virtual const idLangDict * GetLanguageDict(void)=0
unsigned int flags
Definition: Window.h:371
idWinBool noEvents
Definition: Window.h:398
GLenum GLint GLint y
Definition: glext.h:2849
virtual void PostParse()
Definition: BindWindow.cpp:96
signed char textAlign
Definition: Window.h:394
idDeviceContext * dc
Definition: Window.h:425
GLenum GLint x
Definition: glext.h:2849
void SetBindHandler(idWindow *win)
int Icmp(const char *text) const
Definition: Str.h:667
void SetGuiInfo(idDict *gd, const char *_name)
Definition: Winvar.cpp:47
idBindWindow(idUserInterfaceLocal *gui)
Definition: BindWindow.cpp:49
virtual void Activate(bool activate, idStr &act)
Definition: Window.cpp:481
virtual void PostParse()
Definition: Window.cpp:1709
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)
Definition: Vector.h:808
idCommon * common
Definition: Common.cpp:206
int evValue2
Definition: sys_public.h:218
void CommonInit()
Definition: BindWindow.cpp:38
virtual float CursorY()
idWinVec4 foreColor
Definition: Window.h:402
virtual const char * HandleEvent(const sysEvent_t *event, bool *updateVisuals)
Definition: BindWindow.cpp:59
const int WIN_CANFOCUS
Definition: Window.h:50
const char * GetString(const char *str) const
Definition: LangDict.cpp:148
sysEventType_t evType
Definition: sys_public.h:216
idUserInterfaceLocal * gui
Definition: Window.h:427
virtual ~idBindWindow()
Definition: BindWindow.cpp:54
virtual idWinVar * GetWinVarByName(const char *_name, bool winLookup=false, drawWin_t **owner=NULL)
Definition: BindWindow.cpp:87
Definition: Str.h:116
virtual const char * c_str() const
Definition: Winvar.h:204
idWinStr bindName
Definition: BindWindow.h:50
bool hover
Definition: Window.h:423
const char * GetName() const
Definition: Winvar.h:44
const int WIN_HOLDCAPTURE
Definition: Window.h:53
virtual float CursorX()
virtual idWinVar * GetWinVarByName(const char *_name, bool winLookup=false, drawWin_t **owner=NULL)
Definition: Window.cpp:1776
bool waitingOnKey
Definition: BindWindow.h:51
virtual void Activate(bool activate, idStr &act)
Definition: BindWindow.cpp:125
virtual void Update()
Definition: Winvar.h:215
idRectangle textRect
Definition: Window.h:413
idWinVec4 hoverColor
Definition: Window.h:403