/indra/newview/llfloaterwindowsize.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 126 lines · 79 code · 15 blank · 32 comment · 8 complexity · 0304454db58f7681a97a9a5edf9a8280 MD5 · raw file

  1. /**
  2. * @file llfloaterwindowsize.cpp
  3. *
  4. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  5. * Second Life Viewer Source Code
  6. * Copyright (C) 2010, Linden Research, Inc.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation;
  11. * version 2.1 of the License only.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  23. * $/LicenseInfo$
  24. */
  25. #include "llviewerprecompiledheaders.h"
  26. #include "llfloaterwindowsize.h"
  27. // Viewer includes
  28. #include "llviewerwindow.h"
  29. // Linden library includes
  30. #include "llcombobox.h"
  31. #include "llfloater.h"
  32. #include "llfloaterreg.h"
  33. #include "lluictrl.h"
  34. // System libraries
  35. #include <boost/regex.hpp>
  36. // Extract from strings of the form "<width> x <height>", e.g. "640 x 480".
  37. bool extractWindowSizeFromString(const std::string& instr, U32 *width, U32 *height)
  38. {
  39. boost::cmatch what;
  40. // matches (any number)(any non-number)(any number)
  41. const boost::regex expression("([0-9]+)[^0-9]+([0-9]+)");
  42. if (boost::regex_match(instr.c_str(), what, expression))
  43. {
  44. *width = atoi(what[1].first);
  45. *height = atoi(what[2].first);
  46. return true;
  47. }
  48. *width = 0;
  49. *height = 0;
  50. return false;
  51. }
  52. LLFloaterWindowSize::LLFloaterWindowSize(const LLSD& key)
  53. : LLFloater(key)
  54. {}
  55. LLFloaterWindowSize::~LLFloaterWindowSize()
  56. {}
  57. BOOL LLFloaterWindowSize::postBuild()
  58. {
  59. center();
  60. initWindowSizeControls();
  61. getChild<LLUICtrl>("set_btn")->setCommitCallback(
  62. boost::bind(&LLFloaterWindowSize::onClickSet, this));
  63. getChild<LLUICtrl>("cancel_btn")->setCommitCallback(
  64. boost::bind(&LLFloaterWindowSize::onClickCancel, this));
  65. setDefaultBtn("set_btn");
  66. return TRUE;
  67. }
  68. void LLFloaterWindowSize::initWindowSizeControls()
  69. {
  70. LLComboBox* ctrl_window_size = getChild<LLComboBox>("window_size_combo");
  71. // Look to see if current window size matches existing window sizes, if so then
  72. // just set the selection value...
  73. const U32 height = gViewerWindow->getWindowHeightRaw();
  74. const U32 width = gViewerWindow->getWindowWidthRaw();
  75. for (S32 i=0; i < ctrl_window_size->getItemCount(); i++)
  76. {
  77. U32 height_test = 0;
  78. U32 width_test = 0;
  79. ctrl_window_size->setCurrentByIndex(i);
  80. std::string resolution = ctrl_window_size->getValue().asString();
  81. if (extractWindowSizeFromString(resolution, &width_test, &height_test))
  82. {
  83. if ((height_test == height) && (width_test == width))
  84. {
  85. return;
  86. }
  87. }
  88. }
  89. // ...otherwise, add a new entry with the current window height/width.
  90. LLUIString resolution_label = getString("resolution_format");
  91. resolution_label.setArg("[RES_X]", llformat("%d", width));
  92. resolution_label.setArg("[RES_Y]", llformat("%d", height));
  93. ctrl_window_size->add(resolution_label, ADD_TOP);
  94. ctrl_window_size->setCurrentByIndex(0);
  95. }
  96. void LLFloaterWindowSize::onClickSet()
  97. {
  98. LLComboBox* ctrl_window_size = getChild<LLComboBox>("window_size_combo");
  99. U32 width = 0;
  100. U32 height = 0;
  101. std::string resolution = ctrl_window_size->getValue().asString();
  102. if (extractWindowSizeFromString(resolution, &width, &height))
  103. {
  104. LLViewerWindow::movieSize(width, height);
  105. }
  106. closeFloater();
  107. }
  108. void LLFloaterWindowSize::onClickCancel()
  109. {
  110. closeFloater();
  111. }