PageRenderTime 68ms CodeModel.GetById 12ms app.highlight 52ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llfloaterjoystick.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 315 lines | 238 code | 47 blank | 30 comment | 13 complexity | 6bdbc73c31373234921898b98bc1a40a MD5 | raw file
  1/** 
  2 * @file llfloaterjoystick.cpp
  3 * @brief Joystick preferences panel
  4 *
  5 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library 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 GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28
 29// file include
 30#include "llfloaterjoystick.h"
 31
 32// linden library includes
 33#include "llerror.h"
 34#include "llrect.h"
 35#include "llstring.h"
 36
 37// project includes
 38#include "lluictrlfactory.h"
 39#include "llviewercontrol.h"
 40#include "llappviewer.h"
 41#include "llviewerjoystick.h"
 42#include "llcheckboxctrl.h"
 43
 44LLFloaterJoystick::LLFloaterJoystick(const LLSD& data)
 45	: LLFloater(data)
 46{
 47	initFromSettings();
 48}
 49
 50void LLFloaterJoystick::draw()
 51{
 52	bool joystick_inited = LLViewerJoystick::getInstance()->isJoystickInitialized();
 53	getChildView("enable_joystick")->setEnabled(joystick_inited);
 54	getChildView("joystick_type")->setEnabled(joystick_inited);
 55	std::string desc = LLViewerJoystick::getInstance()->getDescription();
 56	if (desc.empty()) desc = getString("NoDevice");
 57	getChild<LLUICtrl>("joystick_type")->setValue(desc);
 58
 59	LLViewerJoystick* joystick(LLViewerJoystick::getInstance());
 60	for (U32 i = 0; i < 6; i++)
 61	{
 62		F32 value = joystick->getJoystickAxis(i);
 63		mAxisStats[i]->addValue(value * gFrameIntervalSeconds);
 64		if (mAxisStatsBar[i])
 65		{
 66			F32 minbar, maxbar;
 67			mAxisStatsBar[i]->getRange(minbar, maxbar);
 68			if (llabs(value) > maxbar)
 69			{
 70				F32 range = llabs(value);
 71				mAxisStatsBar[i]->setRange(-range, range, range * 0.25f, range * 0.5f);
 72			}
 73		}
 74	}
 75
 76	LLFloater::draw();
 77}
 78
 79BOOL LLFloaterJoystick::postBuild()
 80{		
 81	center();
 82	F32 range = gSavedSettings.getBOOL("Cursor3D") ? 128.f : 2.f;
 83
 84	for (U32 i = 0; i < 6; i++)
 85	{
 86		mAxisStats[i] = new LLStat(4);
 87		std::string axisname = llformat("axis%d", i);
 88		mAxisStatsBar[i] = getChild<LLStatBar>(axisname);
 89		if (mAxisStatsBar[i])
 90		{
 91			mAxisStatsBar[i]->setStat(mAxisStats[i]);
 92			mAxisStatsBar[i]->setRange(-range, range, range * 0.25f, range * 0.5f);
 93		}
 94	}
 95	
 96	mCheckJoystickEnabled = getChild<LLCheckBoxCtrl>("enable_joystick");
 97	childSetCommitCallback("enable_joystick",onCommitJoystickEnabled,this);
 98	mCheckFlycamEnabled = getChild<LLCheckBoxCtrl>("JoystickFlycamEnabled");
 99	childSetCommitCallback("JoystickFlycamEnabled",onCommitJoystickEnabled,this);
100
101	childSetAction("SpaceNavigatorDefaults", onClickRestoreSNDefaults, this);
102	childSetAction("cancel_btn", onClickCancel, this);
103	childSetAction("ok_btn", onClickOK, this);
104
105	refresh();
106	return TRUE;
107}
108
109LLFloaterJoystick::~LLFloaterJoystick()
110{
111	// Children all cleaned up by default view destructor.
112}
113
114
115void LLFloaterJoystick::apply()
116{
117}
118
119void LLFloaterJoystick::initFromSettings()
120{
121	mJoystickEnabled = gSavedSettings.getBOOL("JoystickEnabled");
122
123	mJoystickAxis[0] = gSavedSettings.getS32("JoystickAxis0");
124	mJoystickAxis[1] = gSavedSettings.getS32("JoystickAxis1");
125	mJoystickAxis[2] = gSavedSettings.getS32("JoystickAxis2");
126	mJoystickAxis[3] = gSavedSettings.getS32("JoystickAxis3");
127	mJoystickAxis[4] = gSavedSettings.getS32("JoystickAxis4");
128	mJoystickAxis[5] = gSavedSettings.getS32("JoystickAxis5");
129	mJoystickAxis[6] = gSavedSettings.getS32("JoystickAxis6");
130	
131	m3DCursor = gSavedSettings.getBOOL("Cursor3D");
132	mAutoLeveling = gSavedSettings.getBOOL("AutoLeveling");
133	mZoomDirect  = gSavedSettings.getBOOL("ZoomDirect");
134
135	mAvatarEnabled = gSavedSettings.getBOOL("JoystickAvatarEnabled");
136	mBuildEnabled = gSavedSettings.getBOOL("JoystickBuildEnabled");
137	mFlycamEnabled = gSavedSettings.getBOOL("JoystickFlycamEnabled");
138	
139	mAvatarAxisScale[0] = gSavedSettings.getF32("AvatarAxisScale0");
140	mAvatarAxisScale[1] = gSavedSettings.getF32("AvatarAxisScale1");
141	mAvatarAxisScale[2] = gSavedSettings.getF32("AvatarAxisScale2");
142	mAvatarAxisScale[3] = gSavedSettings.getF32("AvatarAxisScale3");
143	mAvatarAxisScale[4] = gSavedSettings.getF32("AvatarAxisScale4");
144	mAvatarAxisScale[5] = gSavedSettings.getF32("AvatarAxisScale5");
145
146	mBuildAxisScale[0] = gSavedSettings.getF32("BuildAxisScale0");
147	mBuildAxisScale[1] = gSavedSettings.getF32("BuildAxisScale1");
148	mBuildAxisScale[2] = gSavedSettings.getF32("BuildAxisScale2");
149	mBuildAxisScale[3] = gSavedSettings.getF32("BuildAxisScale3");
150	mBuildAxisScale[4] = gSavedSettings.getF32("BuildAxisScale4");
151	mBuildAxisScale[5] = gSavedSettings.getF32("BuildAxisScale5");
152
153	mFlycamAxisScale[0] = gSavedSettings.getF32("FlycamAxisScale0");
154	mFlycamAxisScale[1] = gSavedSettings.getF32("FlycamAxisScale1");
155	mFlycamAxisScale[2] = gSavedSettings.getF32("FlycamAxisScale2");
156	mFlycamAxisScale[3] = gSavedSettings.getF32("FlycamAxisScale3");
157	mFlycamAxisScale[4] = gSavedSettings.getF32("FlycamAxisScale4");
158	mFlycamAxisScale[5] = gSavedSettings.getF32("FlycamAxisScale5");
159	mFlycamAxisScale[6] = gSavedSettings.getF32("FlycamAxisScale6");
160
161	mAvatarAxisDeadZone[0] = gSavedSettings.getF32("AvatarAxisDeadZone0");
162	mAvatarAxisDeadZone[1] = gSavedSettings.getF32("AvatarAxisDeadZone1");
163	mAvatarAxisDeadZone[2] = gSavedSettings.getF32("AvatarAxisDeadZone2");
164	mAvatarAxisDeadZone[3] = gSavedSettings.getF32("AvatarAxisDeadZone3");
165	mAvatarAxisDeadZone[4] = gSavedSettings.getF32("AvatarAxisDeadZone4");
166	mAvatarAxisDeadZone[5] = gSavedSettings.getF32("AvatarAxisDeadZone5");
167
168	mBuildAxisDeadZone[0] = gSavedSettings.getF32("BuildAxisDeadZone0");
169	mBuildAxisDeadZone[1] = gSavedSettings.getF32("BuildAxisDeadZone1");
170	mBuildAxisDeadZone[2] = gSavedSettings.getF32("BuildAxisDeadZone2");
171	mBuildAxisDeadZone[3] = gSavedSettings.getF32("BuildAxisDeadZone3");
172	mBuildAxisDeadZone[4] = gSavedSettings.getF32("BuildAxisDeadZone4");
173	mBuildAxisDeadZone[5] = gSavedSettings.getF32("BuildAxisDeadZone5");
174
175	mFlycamAxisDeadZone[0] = gSavedSettings.getF32("FlycamAxisDeadZone0");
176	mFlycamAxisDeadZone[1] = gSavedSettings.getF32("FlycamAxisDeadZone1");
177	mFlycamAxisDeadZone[2] = gSavedSettings.getF32("FlycamAxisDeadZone2");
178	mFlycamAxisDeadZone[3] = gSavedSettings.getF32("FlycamAxisDeadZone3");
179	mFlycamAxisDeadZone[4] = gSavedSettings.getF32("FlycamAxisDeadZone4");
180	mFlycamAxisDeadZone[5] = gSavedSettings.getF32("FlycamAxisDeadZone5");
181	mFlycamAxisDeadZone[6] = gSavedSettings.getF32("FlycamAxisDeadZone6");
182
183	mAvatarFeathering = gSavedSettings.getF32("AvatarFeathering");
184	mBuildFeathering = gSavedSettings.getF32("BuildFeathering");
185	mFlycamFeathering = gSavedSettings.getF32("FlycamFeathering");
186}
187
188void LLFloaterJoystick::refresh()
189{
190	LLFloater::refresh();
191	initFromSettings();
192}
193
194void LLFloaterJoystick::cancel()
195{
196	gSavedSettings.setBOOL("JoystickEnabled", mJoystickEnabled);
197
198	gSavedSettings.setS32("JoystickAxis0", mJoystickAxis[0]);
199	gSavedSettings.setS32("JoystickAxis1", mJoystickAxis[1]);
200	gSavedSettings.setS32("JoystickAxis2", mJoystickAxis[2]);
201	gSavedSettings.setS32("JoystickAxis3", mJoystickAxis[3]);
202	gSavedSettings.setS32("JoystickAxis4", mJoystickAxis[4]);
203	gSavedSettings.setS32("JoystickAxis5", mJoystickAxis[5]);
204	gSavedSettings.setS32("JoystickAxis6", mJoystickAxis[6]);
205
206	gSavedSettings.setBOOL("Cursor3D", m3DCursor);
207	gSavedSettings.setBOOL("AutoLeveling", mAutoLeveling);
208	gSavedSettings.setBOOL("ZoomDirect", mZoomDirect );
209
210	gSavedSettings.setBOOL("JoystickAvatarEnabled", mAvatarEnabled);
211	gSavedSettings.setBOOL("JoystickBuildEnabled", mBuildEnabled);
212	gSavedSettings.setBOOL("JoystickFlycamEnabled", mFlycamEnabled);
213	
214	gSavedSettings.setF32("AvatarAxisScale0", mAvatarAxisScale[0]);
215	gSavedSettings.setF32("AvatarAxisScale1", mAvatarAxisScale[1]);
216	gSavedSettings.setF32("AvatarAxisScale2", mAvatarAxisScale[2]);
217	gSavedSettings.setF32("AvatarAxisScale3", mAvatarAxisScale[3]);
218	gSavedSettings.setF32("AvatarAxisScale4", mAvatarAxisScale[4]);
219	gSavedSettings.setF32("AvatarAxisScale5", mAvatarAxisScale[5]);
220
221	gSavedSettings.setF32("BuildAxisScale0", mBuildAxisScale[0]);
222	gSavedSettings.setF32("BuildAxisScale1", mBuildAxisScale[1]);
223	gSavedSettings.setF32("BuildAxisScale2", mBuildAxisScale[2]);
224	gSavedSettings.setF32("BuildAxisScale3", mBuildAxisScale[3]);
225	gSavedSettings.setF32("BuildAxisScale4", mBuildAxisScale[4]);
226	gSavedSettings.setF32("BuildAxisScale5", mBuildAxisScale[5]);
227
228	gSavedSettings.setF32("FlycamAxisScale0", mFlycamAxisScale[0]);
229	gSavedSettings.setF32("FlycamAxisScale1", mFlycamAxisScale[1]);
230	gSavedSettings.setF32("FlycamAxisScale2", mFlycamAxisScale[2]);
231	gSavedSettings.setF32("FlycamAxisScale3", mFlycamAxisScale[3]);
232	gSavedSettings.setF32("FlycamAxisScale4", mFlycamAxisScale[4]);
233	gSavedSettings.setF32("FlycamAxisScale5", mFlycamAxisScale[5]);
234	gSavedSettings.setF32("FlycamAxisScale6", mFlycamAxisScale[6]);
235
236	gSavedSettings.setF32("AvatarAxisDeadZone0", mAvatarAxisDeadZone[0]);
237	gSavedSettings.setF32("AvatarAxisDeadZone1", mAvatarAxisDeadZone[1]);
238	gSavedSettings.setF32("AvatarAxisDeadZone2", mAvatarAxisDeadZone[2]);
239	gSavedSettings.setF32("AvatarAxisDeadZone3", mAvatarAxisDeadZone[3]);
240	gSavedSettings.setF32("AvatarAxisDeadZone4", mAvatarAxisDeadZone[4]);
241	gSavedSettings.setF32("AvatarAxisDeadZone5", mAvatarAxisDeadZone[5]);
242
243	gSavedSettings.setF32("BuildAxisDeadZone0", mBuildAxisDeadZone[0]);
244	gSavedSettings.setF32("BuildAxisDeadZone1", mBuildAxisDeadZone[1]);
245	gSavedSettings.setF32("BuildAxisDeadZone2", mBuildAxisDeadZone[2]);
246	gSavedSettings.setF32("BuildAxisDeadZone3", mBuildAxisDeadZone[3]);
247	gSavedSettings.setF32("BuildAxisDeadZone4", mBuildAxisDeadZone[4]);
248	gSavedSettings.setF32("BuildAxisDeadZone5", mBuildAxisDeadZone[5]);
249
250	gSavedSettings.setF32("FlycamAxisDeadZone0", mFlycamAxisDeadZone[0]);
251	gSavedSettings.setF32("FlycamAxisDeadZone1", mFlycamAxisDeadZone[1]);
252	gSavedSettings.setF32("FlycamAxisDeadZone2", mFlycamAxisDeadZone[2]);
253	gSavedSettings.setF32("FlycamAxisDeadZone3", mFlycamAxisDeadZone[3]);
254	gSavedSettings.setF32("FlycamAxisDeadZone4", mFlycamAxisDeadZone[4]);
255	gSavedSettings.setF32("FlycamAxisDeadZone5", mFlycamAxisDeadZone[5]);
256	gSavedSettings.setF32("FlycamAxisDeadZone6", mFlycamAxisDeadZone[6]);
257
258	gSavedSettings.setF32("AvatarFeathering", mAvatarFeathering);
259	gSavedSettings.setF32("BuildFeathering", mBuildFeathering);
260	gSavedSettings.setF32("FlycamFeathering", mFlycamFeathering);
261}
262
263void LLFloaterJoystick::onCommitJoystickEnabled(LLUICtrl*, void *joy_panel)
264{
265	LLFloaterJoystick* self = (LLFloaterJoystick*)joy_panel;
266	BOOL joystick_enabled = self->mCheckJoystickEnabled->get();
267	BOOL flycam_enabled = self->mCheckFlycamEnabled->get();
268
269	if (!joystick_enabled || !flycam_enabled)
270	{
271		// Turn off flycam
272		LLViewerJoystick* joystick(LLViewerJoystick::getInstance());
273		if (joystick->getOverrideCamera())
274		{
275			joystick->toggleFlycam();
276		}
277	}
278}
279
280void LLFloaterJoystick::onClickRestoreSNDefaults(void *joy_panel)
281{
282	setSNDefaults();
283}
284
285void LLFloaterJoystick::onClickCancel(void *joy_panel)
286{
287	if (joy_panel)
288	{
289		LLFloaterJoystick* self = (LLFloaterJoystick*)joy_panel;
290
291		if (self)
292		{
293			self->cancel();
294			self->closeFloater();
295		}
296	}
297}
298
299void LLFloaterJoystick::onClickOK(void *joy_panel)
300{
301	if (joy_panel)
302	{
303		LLFloaterJoystick* self = (LLFloaterJoystick*)joy_panel;
304
305		if (self)
306		{
307			self->closeFloater();
308		}
309	}
310}
311
312void LLFloaterJoystick::setSNDefaults()
313{
314	LLViewerJoystick::getInstance()->setSNDefaults();
315}