doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FieldWindow.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 "FieldWindow.h"
36 
37 
39  cursorPos = 0;
40  lastTextLength = 0;
41  lastCursorPos = 0;
42  paintOffset = 0;
43  showCursor = false;
44 }
45 
47  dc = d;
48  gui = g;
49  CommonInit();
50 }
51 
53  gui = g;
54  CommonInit();
55 }
56 
58 
59 }
60 
61 bool idFieldWindow::ParseInternalVar(const char *_name, idParser *src) {
62  if (idStr::Icmp(_name, "cursorvar") == 0) {
63  ParseString(src, cursorVar);
64  return true;
65  }
66  if (idStr::Icmp(_name, "showcursor") == 0) {
67  showCursor = src->ParseBool();
68  return true;
69  }
70  return idWindow::ParseInternalVar(_name, src);
71 }
72 
73 
77  paintOffset = 0;
78  int tw = dc->TextWidth(text, textScale, -1);
79  if (tw < textRect.w) {
80  return;
81  }
82  while (tw > textRect.w && len > 0) {
83  tw = dc->TextWidth(text, textScale, --len);
84  paintOffset++;
85  }
86 }
87 
88 
89 void idFieldWindow::Draw(int time, float x, float y) {
90  float scale = textScale;
91  int len = text.Length();
93  if (len != lastTextLength || cursorPos != lastCursorPos) {
94  CalcPaintOffset(len);
95  }
97  if (paintOffset >= len) {
98  paintOffset = 0;
99  }
100  if (cursorPos > len) {
101  cursorPos = len;
102  }
103  dc->DrawText(&text[paintOffset], scale, 0, foreColor, rect, false, ((flags & WIN_FOCUS) || showCursor) ? cursorPos - paintOffset : -1);
104 }
105 
GLubyte g
Definition: glext.h:4662
int GetInt(const char *key, const char *defaultString="0") const
Definition: Dict.h:252
idWinFloat textScale
Definition: Window.h:405
int Length()
Definition: Winvar.h:192
virtual void Draw(int time, float x, float y)
Definition: FieldWindow.cpp:89
unsigned int flags
Definition: Window.h:371
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:4804
virtual bool ParseInternalVar(const char *name, idParser *src)
Definition: Window.cpp:1915
GLenum GLint GLint y
Definition: glext.h:2849
const int WIN_FOCUS
Definition: Window.h:44
void ParseString(idParser *src, idStr &out)
Definition: Window.cpp:1883
idDeviceContext * dc
Definition: Window.h:425
GLuint src
Definition: glext.h:5390
GLenum GLsizei len
Definition: glext.h:3472
GLenum GLint x
Definition: glext.h:2849
int Icmp(const char *text) const
Definition: Str.h:667
bool ParseBool(void)
Definition: Parser.cpp:2797
idFieldWindow(idUserInterfaceLocal *gui)
Definition: FieldWindow.cpp:52
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)
int TextWidth(const char *text, float scale, int limit)
void CalcPaintOffset(int len)
Definition: FieldWindow.cpp:74
idStr cursorVar
Definition: FieldWindow.h:51
idWinVec4 foreColor
Definition: Window.h:402
int lastTextLength
Definition: FieldWindow.h:47
virtual bool ParseInternalVar(const char *name, idParser *src)
Definition: FieldWindow.cpp:61
virtual const idDict & State() const
idWinStr text
Definition: Window.h:407
idWinRectangle rect
Definition: Window.h:399
void CommonInit()
Definition: FieldWindow.cpp:38
idUserInterfaceLocal * gui
Definition: Window.h:427
float w
Definition: Rectangle.h:38
virtual ~idFieldWindow()
Definition: FieldWindow.cpp:57
idRectangle textRect
Definition: Window.h:413