doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GEOptions.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 "../../ui/Window.h"
33 #include "../../ui/UserInterfaceLocal.h"
34 
35 #include "GEOptions.h"
36 
38  // Grid options
39  mGridColor.Set ( 0.2f, 0.2f, 1.0f, 1.0f );
40  mGridWidth = 10;
41  mGridHeight = 10;
42  mGridSnap = false;
43  mGridVisible = false;
44  mNavigatorVisible = true;
45  mTransformerVisible = true;
46  mIgnoreDesktopSelect = true;
47  mStatusBarVisible = true;
48  mPropertiesVisible = true;
49 
50  mWorkspaceColor.Set ( 0.0f, 0.0f, 0.0f, 1.0f );
51  mSelectionColor.Set ( 0.5f, 0.5f, 1.0f, 1.0f );
52 
53  memset ( mCustomColors, 0, sizeof(mCustomColors) );
54 }
55 
56 /*
57 ================
58 rvGEOptions::Init
59 ================
60 */
61 void rvGEOptions::Init( void ) {
62  mRegistry.Init( "Software\\id Software\\DOOM3\\Tools\\GUIEditor" );
63 }
64 
65 /*
66 ================
67 rvGEOptions::Save
68 
69 Writes the options to the registry so they can later be read using the Load method
70 ================
71 */
72 bool rvGEOptions::Save ( void )
73 {
74  // Write the last page we visited
75  mRegistry.SetLong ( "lastOptionsPage", mLastOptionsPage );
76 
77  // Write the grid settings
78  mRegistry.SetVec4 ( "gridColor", idVec4(mGridColor[0],mGridColor[1],mGridColor[2],1.0f) );
79  mRegistry.SetLong ( "gridWidth", mGridWidth );
80  mRegistry.SetLong ( "gridHeight", mGridHeight );
81  mRegistry.SetBool ( "gridSnap", mGridSnap );
82  mRegistry.SetBool ( "gridVisible", mGridVisible );
83 
84  // Tool window states
85  mRegistry.SetBool ( "navigatorVisible", mNavigatorVisible );
86  mRegistry.SetBool ( "PropertiesVisible", mPropertiesVisible );
87  mRegistry.SetBool ( "transformerVisible", mTransformerVisible );
88  mRegistry.SetBool ( "statusBarVisible", mStatusBarVisible );
89 
90  // General stuff
91  mRegistry.SetVec4 ( "selectionColor", mSelectionColor );
92  mRegistry.SetBool ( "ignoreDesktopSelect", mIgnoreDesktopSelect );
93 
94  // Custom colors
95  int i;
96  for ( i = 0; i < 16; i ++ )
97  {
98  mRegistry.SetLong ( va("customcol%d",i), mCustomColors[i] );
99  }
100 
101  return mRegistry.Save ( );
102 }
103 
104 /*
105 ================
106 rvGEOptions::Load
107 
108 Loads previsouly saved options from the registry
109 ================
110 */
111 bool rvGEOptions::Load ( void )
112 {
113  if ( !mRegistry.Load ( ) )
114  {
115  return false;
116  }
117 
118  // Read the general stuff
119  mLastOptionsPage = mRegistry.GetLong ( "lastOptionsPage" );
120 
121  // Read the grid settings
122  mGridColor = mRegistry.GetVec4 ( "gridColor" );
123  mGridWidth = mRegistry.GetLong ( "gridWidth" );
124  mGridHeight = mRegistry.GetLong ( "gridHeight" );
125  mGridSnap = mRegistry.GetBool ( "gridSnap" );
126  mGridVisible = mRegistry.GetBool ( "gridVisible" );
127 
128  // Tool window states
129  mNavigatorVisible = mRegistry.GetBool ( "navigatorVisible" );
130  mPropertiesVisible = mRegistry.GetBool ( "PropertiesVisible" );
131  mTransformerVisible = mRegistry.GetBool ( "transformerVisible" );
132  mStatusBarVisible = mRegistry.GetBool ( "statusBarVisible" );
133 
134  // General stuff
135  mSelectionColor = mRegistry.GetVec4 ( "selectionColor" );
136  mIgnoreDesktopSelect = mRegistry.GetBool ( "ignoreDesktopSelect" );
137 
138  // Custom colors
139  int i;
140  for ( i = 0; i < 16; i ++ )
141  {
142  mCustomColors[i] = mRegistry.GetLong ( va("customcol%d",i) );
143  }
144 
145  return true;
146 }
147 
148 /*
149 ================
150 rvGEOptions::SnapRectToGrid
151 
152 Snap the rectangle to the grid
153 ================
154 */
155 void rvGEOptions::SnapRectToGrid ( idRectangle& rect, bool snapLeft, bool snapTop, bool snapWidth, bool snapHeight )
156 {
157  if ( snapLeft )
158  {
159  float offset = (int)(rect.x + GetGridWidth() / 2) / GetGridWidth() * GetGridWidth();
160  offset -= rect.x;
161  rect.x += offset;
162  rect.w -= offset;
163  }
164 
165  if ( snapWidth )
166  {
167  float offset = (int)(rect.x + rect.w + GetGridWidth() / 2) / GetGridWidth() * GetGridWidth();
168  offset -= rect.x;
169  offset -= rect.w;
170  rect.w += offset;
171  }
172 
173  if ( snapTop )
174  {
175  float offset = (int)(rect.y + GetGridHeight() / 2) / GetGridHeight() * GetGridHeight();
176  offset -= rect.y;
177  rect.y += offset;
178  rect.h -= offset;
179  }
180 
181  if ( snapHeight )
182  {
183  float offset = (int)(rect.y + rect.h + GetGridHeight() / 2) / GetGridHeight() * GetGridHeight();
184  offset -= rect.y;
185  offset -= rect.h;
186  rect.h += offset;
187  }
188 }
189 
190 
bool mPropertiesVisible
Definition: GEOptions.h:111
idVec4 mGridColor
Definition: GEOptions.h:101
void SetLong(const char *name, long v)
int GetGridHeight(void)
Definition: GEOptions.h:218
void Init(const char *key)
void SetVec4(const char *name, idVec4 &v)
bool mGridVisible
Definition: GEOptions.h:105
idVec4 mWorkspaceColor
Definition: GEOptions.h:107
void SnapRectToGrid(idRectangle &rect, bool snapLeft=true, bool snapTop=true, bool snapWidth=true, bool snapHeight=true)
Definition: GEOptions.cpp:155
case const int
Definition: Callbacks.cpp:52
bool mGridSnap
Definition: GEOptions.h:104
idVec4 GetVec4(const char *name)
bool Save(void)
Definition: GEOptions.cpp:72
bool mNavigatorVisible
Definition: GEOptions.h:110
int i
Definition: process.py:33
GLintptr offset
Definition: glext.h:3113
rvRegistryOptions mRegistry
Definition: GEOptions.h:120
bool mIgnoreDesktopSelect
Definition: GEOptions.h:114
Definition: Vector.h:808
float y
Definition: Rectangle.h:37
void Init(void)
Definition: GEOptions.cpp:61
bool mStatusBarVisible
Definition: GEOptions.h:113
void SetBool(const char *name, bool v)
bool Load(void)
Definition: GEOptions.cpp:111
COLORREF mCustomColors[16]
Definition: GEOptions.h:118
float x
Definition: Rectangle.h:36
int GetGridWidth(void)
Definition: GEOptions.h:213
tuple f
Definition: idal.py:89
bool GetBool(const char *name)
float w
Definition: Rectangle.h:38
int mGridHeight
Definition: GEOptions.h:103
int mGridWidth
Definition: GEOptions.h:102
int mLastOptionsPage
Definition: GEOptions.h:99
float h
Definition: Rectangle.h:39
long GetLong(const char *name)
idVec4 mSelectionColor
Definition: GEOptions.h:108
char * va(const char *fmt,...)
Definition: Str.cpp:1568
void Set(const float x, const float y, const float z, const float w)
Definition: Vector.h:873
bool mTransformerVisible
Definition: GEOptions.h:112