PageRenderTime 41ms CodeModel.GetById 21ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #include "llviewerprecompiledheaders.h"
  27. // file include
  28. #include "llfloaterjoystick.h"
  29. // linden library includes
  30. #include "llerror.h"
  31. #include "llrect.h"
  32. #include "llstring.h"
  33. // project includes
  34. #include "lluictrlfactory.h"
  35. #include "llviewercontrol.h"
  36. #include "llappviewer.h"
  37. #include "llviewerjoystick.h"
  38. #include "llcheckboxctrl.h"
  39. LLFloaterJoystick::LLFloaterJoystick(const LLSD& data)
  40. : LLFloater(data)
  41. {
  42. initFromSettings();
  43. }
  44. void LLFloaterJoystick::draw()
  45. {
  46. bool joystick_inited = LLViewerJoystick::getInstance()->isJoystickInitialized();
  47. getChildView("enable_joystick")->setEnabled(joystick_inited);
  48. getChildView("joystick_type")->setEnabled(joystick_inited);
  49. std::string desc = LLViewerJoystick::getInstance()->getDescription();
  50. if (desc.empty()) desc = getString("NoDevice");
  51. getChild<LLUICtrl>("joystick_type")->setValue(desc);
  52. LLViewerJoystick* joystick(LLViewerJoystick::getInstance());
  53. for (U32 i = 0; i < 6; i++)
  54. {
  55. F32 value = joystick->getJoystickAxis(i);
  56. mAxisStats[i]->addValue(value * gFrameIntervalSeconds);
  57. if (mAxisStatsBar[i])
  58. {
  59. F32 minbar, maxbar;
  60. mAxisStatsBar[i]->getRange(minbar, maxbar);
  61. if (llabs(value) > maxbar)
  62. {
  63. F32 range = llabs(value);
  64. mAxisStatsBar[i]->setRange(-range, range, range * 0.25f, range * 0.5f);
  65. }
  66. }
  67. }
  68. LLFloater::draw();
  69. }
  70. BOOL LLFloaterJoystick::postBuild()
  71. {
  72. center();
  73. F32 range = gSavedSettings.getBOOL("Cursor3D") ? 128.f : 2.f;
  74. for (U32 i = 0; i < 6; i++)
  75. {
  76. mAxisStats[i] = new LLStat(4);
  77. std::string axisname = llformat("axis%d", i);
  78. mAxisStatsBar[i] = getChild<LLStatBar>(axisname);
  79. if (mAxisStatsBar[i])
  80. {
  81. mAxisStatsBar[i]->setStat(mAxisStats[i]);
  82. mAxisStatsBar[i]->setRange(-range, range, range * 0.25f, range * 0.5f);
  83. }
  84. }
  85. mCheckJoystickEnabled = getChild<LLCheckBoxCtrl>("enable_joystick");
  86. childSetCommitCallback("enable_joystick",onCommitJoystickEnabled,this);
  87. mCheckFlycamEnabled = getChild<LLCheckBoxCtrl>("JoystickFlycamEnabled");
  88. childSetCommitCallback("JoystickFlycamEnabled",onCommitJoystickEnabled,this);
  89. childSetAction("SpaceNavigatorDefaults", onClickRestoreSNDefaults, this);
  90. childSetAction("cancel_btn", onClickCancel, this);
  91. childSetAction("ok_btn", onClickOK, this);
  92. refresh();
  93. return TRUE;
  94. }
  95. LLFloaterJoystick::~LLFloaterJoystick()
  96. {
  97. // Children all cleaned up by default view destructor.
  98. }
  99. void LLFloaterJoystick::apply()
  100. {
  101. }
  102. void LLFloaterJoystick::initFromSettings()
  103. {
  104. mJoystickEnabled = gSavedSettings.getBOOL("JoystickEnabled");
  105. mJoystickAxis[0] = gSavedSettings.getS32("JoystickAxis0");
  106. mJoystickAxis[1] = gSavedSettings.getS32("JoystickAxis1");
  107. mJoystickAxis[2] = gSavedSettings.getS32("JoystickAxis2");
  108. mJoystickAxis[3] = gSavedSettings.getS32("JoystickAxis3");
  109. mJoystickAxis[4] = gSavedSettings.getS32("JoystickAxis4");
  110. mJoystickAxis[5] = gSavedSettings.getS32("JoystickAxis5");
  111. mJoystickAxis[6] = gSavedSettings.getS32("JoystickAxis6");
  112. m3DCursor = gSavedSettings.getBOOL("Cursor3D");
  113. mAutoLeveling = gSavedSettings.getBOOL("AutoLeveling");
  114. mZoomDirect = gSavedSettings.getBOOL("ZoomDirect");
  115. mAvatarEnabled = gSavedSettings.getBOOL("JoystickAvatarEnabled");
  116. mBuildEnabled = gSavedSettings.getBOOL("JoystickBuildEnabled");
  117. mFlycamEnabled = gSavedSettings.getBOOL("JoystickFlycamEnabled");
  118. mAvatarAxisScale[0] = gSavedSettings.getF32("AvatarAxisScale0");
  119. mAvatarAxisScale[1] = gSavedSettings.getF32("AvatarAxisScale1");
  120. mAvatarAxisScale[2] = gSavedSettings.getF32("AvatarAxisScale2");
  121. mAvatarAxisScale[3] = gSavedSettings.getF32("AvatarAxisScale3");
  122. mAvatarAxisScale[4] = gSavedSettings.getF32("AvatarAxisScale4");
  123. mAvatarAxisScale[5] = gSavedSettings.getF32("AvatarAxisScale5");
  124. mBuildAxisScale[0] = gSavedSettings.getF32("BuildAxisScale0");
  125. mBuildAxisScale[1] = gSavedSettings.getF32("BuildAxisScale1");
  126. mBuildAxisScale[2] = gSavedSettings.getF32("BuildAxisScale2");
  127. mBuildAxisScale[3] = gSavedSettings.getF32("BuildAxisScale3");
  128. mBuildAxisScale[4] = gSavedSettings.getF32("BuildAxisScale4");
  129. mBuildAxisScale[5] = gSavedSettings.getF32("BuildAxisScale5");
  130. mFlycamAxisScale[0] = gSavedSettings.getF32("FlycamAxisScale0");
  131. mFlycamAxisScale[1] = gSavedSettings.getF32("FlycamAxisScale1");
  132. mFlycamAxisScale[2] = gSavedSettings.getF32("FlycamAxisScale2");
  133. mFlycamAxisScale[3] = gSavedSettings.getF32("FlycamAxisScale3");
  134. mFlycamAxisScale[4] = gSavedSettings.getF32("FlycamAxisScale4");
  135. mFlycamAxisScale[5] = gSavedSettings.getF32("FlycamAxisScale5");
  136. mFlycamAxisScale[6] = gSavedSettings.getF32("FlycamAxisScale6");
  137. mAvatarAxisDeadZone[0] = gSavedSettings.getF32("AvatarAxisDeadZone0");
  138. mAvatarAxisDeadZone[1] = gSavedSettings.getF32("AvatarAxisDeadZone1");
  139. mAvatarAxisDeadZone[2] = gSavedSettings.getF32("AvatarAxisDeadZone2");
  140. mAvatarAxisDeadZone[3] = gSavedSettings.getF32("AvatarAxisDeadZone3");
  141. mAvatarAxisDeadZone[4] = gSavedSettings.getF32("AvatarAxisDeadZone4");
  142. mAvatarAxisDeadZone[5] = gSavedSettings.getF32("AvatarAxisDeadZone5");
  143. mBuildAxisDeadZone[0] = gSavedSettings.getF32("BuildAxisDeadZone0");
  144. mBuildAxisDeadZone[1] = gSavedSettings.getF32("BuildAxisDeadZone1");
  145. mBuildAxisDeadZone[2] = gSavedSettings.getF32("BuildAxisDeadZone2");
  146. mBuildAxisDeadZone[3] = gSavedSettings.getF32("BuildAxisDeadZone3");
  147. mBuildAxisDeadZone[4] = gSavedSettings.getF32("BuildAxisDeadZone4");
  148. mBuildAxisDeadZone[5] = gSavedSettings.getF32("BuildAxisDeadZone5");
  149. mFlycamAxisDeadZone[0] = gSavedSettings.getF32("FlycamAxisDeadZone0");
  150. mFlycamAxisDeadZone[1] = gSavedSettings.getF32("FlycamAxisDeadZone1");
  151. mFlycamAxisDeadZone[2] = gSavedSettings.getF32("FlycamAxisDeadZone2");
  152. mFlycamAxisDeadZone[3] = gSavedSettings.getF32("FlycamAxisDeadZone3");
  153. mFlycamAxisDeadZone[4] = gSavedSettings.getF32("FlycamAxisDeadZone4");
  154. mFlycamAxisDeadZone[5] = gSavedSettings.getF32("FlycamAxisDeadZone5");
  155. mFlycamAxisDeadZone[6] = gSavedSettings.getF32("FlycamAxisDeadZone6");
  156. mAvatarFeathering = gSavedSettings.getF32("AvatarFeathering");
  157. mBuildFeathering = gSavedSettings.getF32("BuildFeathering");
  158. mFlycamFeathering = gSavedSettings.getF32("FlycamFeathering");
  159. }
  160. void LLFloaterJoystick::refresh()
  161. {
  162. LLFloater::refresh();
  163. initFromSettings();
  164. }
  165. void LLFloaterJoystick::cancel()
  166. {
  167. gSavedSettings.setBOOL("JoystickEnabled", mJoystickEnabled);
  168. gSavedSettings.setS32("JoystickAxis0", mJoystickAxis[0]);
  169. gSavedSettings.setS32("JoystickAxis1", mJoystickAxis[1]);
  170. gSavedSettings.setS32("JoystickAxis2", mJoystickAxis[2]);
  171. gSavedSettings.setS32("JoystickAxis3", mJoystickAxis[3]);
  172. gSavedSettings.setS32("JoystickAxis4", mJoystickAxis[4]);
  173. gSavedSettings.setS32("JoystickAxis5", mJoystickAxis[5]);
  174. gSavedSettings.setS32("JoystickAxis6", mJoystickAxis[6]);
  175. gSavedSettings.setBOOL("Cursor3D", m3DCursor);
  176. gSavedSettings.setBOOL("AutoLeveling", mAutoLeveling);
  177. gSavedSettings.setBOOL("ZoomDirect", mZoomDirect );
  178. gSavedSettings.setBOOL("JoystickAvatarEnabled", mAvatarEnabled);
  179. gSavedSettings.setBOOL("JoystickBuildEnabled", mBuildEnabled);
  180. gSavedSettings.setBOOL("JoystickFlycamEnabled", mFlycamEnabled);
  181. gSavedSettings.setF32("AvatarAxisScale0", mAvatarAxisScale[0]);
  182. gSavedSettings.setF32("AvatarAxisScale1", mAvatarAxisScale[1]);
  183. gSavedSettings.setF32("AvatarAxisScale2", mAvatarAxisScale[2]);
  184. gSavedSettings.setF32("AvatarAxisScale3", mAvatarAxisScale[3]);
  185. gSavedSettings.setF32("AvatarAxisScale4", mAvatarAxisScale[4]);
  186. gSavedSettings.setF32("AvatarAxisScale5", mAvatarAxisScale[5]);
  187. gSavedSettings.setF32("BuildAxisScale0", mBuildAxisScale[0]);
  188. gSavedSettings.setF32("BuildAxisScale1", mBuildAxisScale[1]);
  189. gSavedSettings.setF32("BuildAxisScale2", mBuildAxisScale[2]);
  190. gSavedSettings.setF32("BuildAxisScale3", mBuildAxisScale[3]);
  191. gSavedSettings.setF32("BuildAxisScale4", mBuildAxisScale[4]);
  192. gSavedSettings.setF32("BuildAxisScale5", mBuildAxisScale[5]);
  193. gSavedSettings.setF32("FlycamAxisScale0", mFlycamAxisScale[0]);
  194. gSavedSettings.setF32("FlycamAxisScale1", mFlycamAxisScale[1]);
  195. gSavedSettings.setF32("FlycamAxisScale2", mFlycamAxisScale[2]);
  196. gSavedSettings.setF32("FlycamAxisScale3", mFlycamAxisScale[3]);
  197. gSavedSettings.setF32("FlycamAxisScale4", mFlycamAxisScale[4]);
  198. gSavedSettings.setF32("FlycamAxisScale5", mFlycamAxisScale[5]);
  199. gSavedSettings.setF32("FlycamAxisScale6", mFlycamAxisScale[6]);
  200. gSavedSettings.setF32("AvatarAxisDeadZone0", mAvatarAxisDeadZone[0]);
  201. gSavedSettings.setF32("AvatarAxisDeadZone1", mAvatarAxisDeadZone[1]);
  202. gSavedSettings.setF32("AvatarAxisDeadZone2", mAvatarAxisDeadZone[2]);
  203. gSavedSettings.setF32("AvatarAxisDeadZone3", mAvatarAxisDeadZone[3]);
  204. gSavedSettings.setF32("AvatarAxisDeadZone4", mAvatarAxisDeadZone[4]);
  205. gSavedSettings.setF32("AvatarAxisDeadZone5", mAvatarAxisDeadZone[5]);
  206. gSavedSettings.setF32("BuildAxisDeadZone0", mBuildAxisDeadZone[0]);
  207. gSavedSettings.setF32("BuildAxisDeadZone1", mBuildAxisDeadZone[1]);
  208. gSavedSettings.setF32("BuildAxisDeadZone2", mBuildAxisDeadZone[2]);
  209. gSavedSettings.setF32("BuildAxisDeadZone3", mBuildAxisDeadZone[3]);
  210. gSavedSettings.setF32("BuildAxisDeadZone4", mBuildAxisDeadZone[4]);
  211. gSavedSettings.setF32("BuildAxisDeadZone5", mBuildAxisDeadZone[5]);
  212. gSavedSettings.setF32("FlycamAxisDeadZone0", mFlycamAxisDeadZone[0]);
  213. gSavedSettings.setF32("FlycamAxisDeadZone1", mFlycamAxisDeadZone[1]);
  214. gSavedSettings.setF32("FlycamAxisDeadZone2", mFlycamAxisDeadZone[2]);
  215. gSavedSettings.setF32("FlycamAxisDeadZone3", mFlycamAxisDeadZone[3]);
  216. gSavedSettings.setF32("FlycamAxisDeadZone4", mFlycamAxisDeadZone[4]);
  217. gSavedSettings.setF32("FlycamAxisDeadZone5", mFlycamAxisDeadZone[5]);
  218. gSavedSettings.setF32("FlycamAxisDeadZone6", mFlycamAxisDeadZone[6]);
  219. gSavedSettings.setF32("AvatarFeathering", mAvatarFeathering);
  220. gSavedSettings.setF32("BuildFeathering", mBuildFeathering);
  221. gSavedSettings.setF32("FlycamFeathering", mFlycamFeathering);
  222. }
  223. void LLFloaterJoystick::onCommitJoystickEnabled(LLUICtrl*, void *joy_panel)
  224. {
  225. LLFloaterJoystick* self = (LLFloaterJoystick*)joy_panel;
  226. BOOL joystick_enabled = self->mCheckJoystickEnabled->get();
  227. BOOL flycam_enabled = self->mCheckFlycamEnabled->get();
  228. if (!joystick_enabled || !flycam_enabled)
  229. {
  230. // Turn off flycam
  231. LLViewerJoystick* joystick(LLViewerJoystick::getInstance());
  232. if (joystick->getOverrideCamera())
  233. {
  234. joystick->toggleFlycam();
  235. }
  236. }
  237. }
  238. void LLFloaterJoystick::onClickRestoreSNDefaults(void *joy_panel)
  239. {
  240. setSNDefaults();
  241. }
  242. void LLFloaterJoystick::onClickCancel(void *joy_panel)
  243. {
  244. if (joy_panel)
  245. {
  246. LLFloaterJoystick* self = (LLFloaterJoystick*)joy_panel;
  247. if (self)
  248. {
  249. self->cancel();
  250. self->closeFloater();
  251. }
  252. }
  253. }
  254. void LLFloaterJoystick::onClickOK(void *joy_panel)
  255. {
  256. if (joy_panel)
  257. {
  258. LLFloaterJoystick* self = (LLFloaterJoystick*)joy_panel;
  259. if (self)
  260. {
  261. self->closeFloater();
  262. }
  263. }
  264. }
  265. void LLFloaterJoystick::setSNDefaults()
  266. {
  267. LLViewerJoystick::getInstance()->setSNDefaults();
  268. }