doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ListGUI.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 "ListGUILocal.h"
33 
34 /*
35 ====================
36 idListGUILocal::StateChanged
37 ====================
38 */
40  int i;
41 
42  if ( !m_stateUpdates ) {
43  return;
44  }
45 
46  for( i = 0; i < Num(); i++ ) {
47  m_pGUI->SetStateString( va( "%s_item_%i", m_name.c_str(), i ), (*this)[i].c_str() );
48  }
49  for( i = Num() ; i < m_water ; i++ ) {
50  m_pGUI->SetStateString( va( "%s_item_%i", m_name.c_str(), i ), "" );
51  }
52  m_water = Num();
54 }
55 
56 /*
57 ====================
58 idListGUILocal::GetNumSelections
59 ====================
60 */
62  return m_pGUI->State().GetInt( va( "%s_numsel", m_name.c_str() ) );
63 }
64 
65 /*
66 ====================
67 idListGUILocal::GetSelection
68 ====================
69 */
70 int idListGUILocal::GetSelection( char *s, int size, int _sel ) const {
71  if ( s ) {
72  s[ 0 ] = '\0';
73  }
74  int sel = m_pGUI->State().GetInt( va( "%s_sel_%i", m_name.c_str(), _sel ), "-1" );
75  if ( sel == -1 || sel >= m_ids.Num() ) {
76  return -1;
77  }
78  if ( s ) {
79  idStr::snPrintf( s, size, m_pGUI->State().GetString( va( "%s_item_%i", m_name.c_str(), sel ), "" ) );
80  }
81  // don't let overflow
82  if ( sel >= m_ids.Num() ) {
83  sel = 0;
84  }
85  m_pGUI->SetStateInt( va( "%s_selid_0", m_name.c_str() ), m_ids[ sel ] );
86  return m_ids[ sel ];
87 }
88 
89 /*
90 ====================
91 idListGUILocal::SetSelection
92 ====================
93 */
95  m_pGUI->SetStateInt( va( "%s_sel_0", m_name.c_str() ), sel );
96  StateChanged();
97 }
98 
99 /*
100 ====================
101 idListGUILocal::Add
102 ====================
103 */
104 void idListGUILocal::Add( int id, const idStr &s ) {
105  int i = m_ids.FindIndex( id );
106  if ( i == -1 ) {
107  Append( s );
108  m_ids.Append( id );
109  } else {
110  (*this)[ i ] = s;
111  }
112  StateChanged();
113 }
114 
115 /*
116 ====================
117 idListGUILocal::Push
118 ====================
119 */
120 void idListGUILocal::Push( const idStr& s ) {
121  Append( s );
122  m_ids.Append( m_ids.Num() );
123  StateChanged();
124 }
125 
126 /*
127 ====================
128 idListGUILocal::Del
129 ====================
130 */
131 bool idListGUILocal::Del(int id) {
132  int i = m_ids.FindIndex(id);
133  if ( i == -1 ) {
134  return false;
135  }
136  m_ids.RemoveIndex( i );
137  this->RemoveIndex( i );
138  StateChanged();
139  return true;
140 }
141 
142 /*
143 ====================
144 idListGUILocal::Clear
145 ====================
146 */
148  m_ids.Clear();
150  if ( m_pGUI ) {
151  // will clear all the GUI variables and will set m_water back to 0
152  StateChanged();
153  }
154 }
155 
156 /*
157 ====================
158 idListGUILocal::IsConfigured
159 ====================
160 */
161 bool idListGUILocal::IsConfigured( void ) const {
162  return m_pGUI != NULL;
163 }
164 
165 /*
166 ====================
167 idListGUILocal::SetStateChanges
168 ====================
169 */
170 void idListGUILocal::SetStateChanges( bool enable ) {
171  m_stateUpdates = enable;
172  StateChanged();
173 }
174 
175 /*
176 ====================
177 idListGUILocal::Shutdown
178 ====================
179 */
181  m_pGUI = NULL;
182  m_name.Clear();
183  Clear();
184 }
static int snPrintf(char *dest, int size, const char *fmt,...) id_attribute((format(printf
Definition: Str.cpp:1465
int GetInt(const char *key, const char *defaultString="0") const
Definition: Dict.h:252
virtual void StateChanged(int time, bool redraw=false)=0
virtual void SetStateString(const char *varName, const char *value)=0
void Push(const idStr &s)
Definition: ListGUI.cpp:120
bool IsConfigured(void) const
Definition: ListGUI.cpp:161
virtual void SetStateInt(const char *varName, const int value)=0
int com_frameTime
Definition: Common.cpp:94
GLdouble s
Definition: glext.h:2935
int i
Definition: process.py:33
const char * GetString(const char *key, const char *defaultString="") const
Definition: Dict.h:240
void Shutdown(void)
Definition: ListGUI.cpp:180
#define NULL
Definition: Lib.h:88
void SetSelection(int sel)
Definition: ListGUI.cpp:94
void Add(int id, const idStr &s)
Definition: ListGUI.cpp:104
bool Del(int id)
Definition: ListGUI.cpp:131
void Clear(void)
Definition: Str.h:724
virtual const idDict & State() const =0
int Num(void)
Definition: ListGUILocal.h:52
int Append(const idStr &obj)
idUserInterface * m_pGUI
Definition: ListGUILocal.h:61
idList< int > m_ids
Definition: ListGUILocal.h:64
int GetSelection(char *s, int size, int sel=0) const
Definition: ListGUI.cpp:70
int Num(void) const
Definition: List.h:265
bool RemoveIndex(int index)
Definition: List.h:849
GLsizeiptr size
Definition: glext.h:3112
int GetNumSelections()
Definition: ListGUI.cpp:61
Definition: Str.h:116
void SetStateChanges(bool enable)
Definition: ListGUI.cpp:170
const char * c_str(void) const
Definition: Str.h:487
int FindIndex(const type &obj) const
Definition: List.h:761
char * va(const char *fmt,...)
Definition: Str.cpp:1568
void Clear(void)
Definition: ListGUI.cpp:147
void StateChanged()
Definition: ListGUI.cpp:39
void Clear(void)
Definition: List.h:184