PageRenderTime 15ms CodeModel.GetById 1ms app.highlight 11ms RepoModel.GetById 2ms app.codeStats 0ms

/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 
 26#include "llviewerprecompiledheaders.h"
 27
 28#include "llfloaterwindowsize.h"
 29
 30// Viewer includes
 31#include "llviewerwindow.h"
 32
 33// Linden library includes
 34#include "llcombobox.h"
 35#include "llfloater.h"
 36#include "llfloaterreg.h"
 37#include "lluictrl.h"
 38
 39// System libraries
 40#include <boost/regex.hpp>
 41
 42// Extract from strings of the form "<width> x <height>", e.g. "640 x 480".
 43bool extractWindowSizeFromString(const std::string& instr, U32 *width, U32 *height)
 44{
 45	boost::cmatch what;
 46	// matches (any number)(any non-number)(any number)
 47	const boost::regex expression("([0-9]+)[^0-9]+([0-9]+)");
 48	if (boost::regex_match(instr.c_str(), what, expression))
 49	{
 50		*width = atoi(what[1].first);
 51		*height = atoi(what[2].first);
 52		return true;
 53	}
 54	
 55	*width = 0;
 56	*height = 0;
 57	return false;
 58}
 59
 60
 61LLFloaterWindowSize::LLFloaterWindowSize(const LLSD& key) 
 62:	LLFloater(key)
 63{}
 64
 65LLFloaterWindowSize::~LLFloaterWindowSize()
 66{}
 67
 68BOOL LLFloaterWindowSize::postBuild()
 69{
 70	center();
 71	initWindowSizeControls();
 72	getChild<LLUICtrl>("set_btn")->setCommitCallback(
 73		boost::bind(&LLFloaterWindowSize::onClickSet, this));
 74	getChild<LLUICtrl>("cancel_btn")->setCommitCallback(
 75		boost::bind(&LLFloaterWindowSize::onClickCancel, this));
 76	setDefaultBtn("set_btn");
 77	return TRUE;
 78}
 79
 80void LLFloaterWindowSize::initWindowSizeControls()
 81{
 82	LLComboBox* ctrl_window_size = getChild<LLComboBox>("window_size_combo");
 83	
 84	// Look to see if current window size matches existing window sizes, if so then
 85	// just set the selection value...
 86	const U32 height = gViewerWindow->getWindowHeightRaw();
 87	const U32 width = gViewerWindow->getWindowWidthRaw();
 88	for (S32 i=0; i < ctrl_window_size->getItemCount(); i++)
 89	{
 90		U32 height_test = 0;
 91		U32 width_test = 0;
 92		ctrl_window_size->setCurrentByIndex(i);
 93		std::string resolution = ctrl_window_size->getValue().asString();
 94		if (extractWindowSizeFromString(resolution, &width_test, &height_test))
 95		{
 96			if ((height_test == height) && (width_test == width))
 97			{
 98				return;
 99			}
100		}
101	}
102	// ...otherwise, add a new entry with the current window height/width.
103	LLUIString resolution_label = getString("resolution_format");
104	resolution_label.setArg("[RES_X]", llformat("%d", width));
105	resolution_label.setArg("[RES_Y]", llformat("%d", height));
106	ctrl_window_size->add(resolution_label, ADD_TOP);
107	ctrl_window_size->setCurrentByIndex(0);
108}
109
110void LLFloaterWindowSize::onClickSet()
111{
112	LLComboBox* ctrl_window_size = getChild<LLComboBox>("window_size_combo");
113	U32 width = 0;
114	U32 height = 0;
115	std::string resolution = ctrl_window_size->getValue().asString();
116	if (extractWindowSizeFromString(resolution, &width, &height))
117	{
118		LLViewerWindow::movieSize(width, height);
119	}
120	closeFloater();
121}
122
123void LLFloaterWindowSize::onClickCancel()
124{
125	closeFloater();
126}