diff options
author | Jacek Antonelli | 2008-08-15 23:44:54 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:54 -0500 |
commit | b2afb8800bb033a04bb3ecdf0363068d56648ef1 (patch) | |
tree | 3568129b5bbddb47cd39d622b4137a8fbff4abaf /linden/indra/llui/llspinctrl.cpp | |
parent | Second Life viewer sources 1.14.0.1 (diff) | |
download | meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.zip meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.gz meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.bz2 meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.xz |
Second Life viewer sources 1.15.0.2
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llui/llspinctrl.cpp | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/linden/indra/llui/llspinctrl.cpp b/linden/indra/llui/llspinctrl.cpp index 1f33279..668ddfa 100644 --- a/linden/indra/llui/llspinctrl.cpp +++ b/linden/indra/llui/llspinctrl.cpp | |||
@@ -4,6 +4,7 @@ | |||
4 | * | 4 | * |
5 | * Copyright (c) 2001-2007, Linden Research, Inc. | 5 | * Copyright (c) 2001-2007, Linden Research, Inc. |
6 | * | 6 | * |
7 | * Second Life Viewer Source Code | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | 8 | * The source code in this file ("Source Code") is provided by Linden Lab |
8 | * to you under the terms of the GNU General Public License, version 2.0 | 9 | * to you under the terms of the GNU General Public License, version 2.0 |
9 | * ("GPL"), unless you have obtained a separate licensing agreement | 10 | * ("GPL"), unless you have obtained a separate licensing agreement |
@@ -142,6 +143,23 @@ LLSpinCtrl::~LLSpinCtrl() | |||
142 | } | 143 | } |
143 | 144 | ||
144 | 145 | ||
146 | F32 clamp_precision(F32 value, S32 decimal_precision) | ||
147 | { | ||
148 | // pow() isn't perfect | ||
149 | |||
150 | F64 clamped_value = value; | ||
151 | for (S32 i = 0; i < decimal_precision; i++) | ||
152 | clamped_value *= 10.0; | ||
153 | |||
154 | clamped_value = llround((F32)clamped_value); | ||
155 | |||
156 | for (S32 i = 0; i < decimal_precision; i++) | ||
157 | clamped_value /= 10.0; | ||
158 | |||
159 | return (F32)clamped_value; | ||
160 | } | ||
161 | |||
162 | |||
145 | // static | 163 | // static |
146 | void LLSpinCtrl::onUpBtn( void *userdata ) | 164 | void LLSpinCtrl::onUpBtn( void *userdata ) |
147 | { | 165 | { |
@@ -150,6 +168,7 @@ void LLSpinCtrl::onUpBtn( void *userdata ) | |||
150 | { | 168 | { |
151 | // use getValue()/setValue() to force reload from/to control | 169 | // use getValue()/setValue() to force reload from/to control |
152 | F32 val = (F32)self->getValue().asReal() + self->mIncrement; | 170 | F32 val = (F32)self->getValue().asReal() + self->mIncrement; |
171 | val = clamp_precision(val, self->mPrecision); | ||
153 | val = llmin( val, self->mMaxValue ); | 172 | val = llmin( val, self->mMaxValue ); |
154 | 173 | ||
155 | if( self->mValidateCallback ) | 174 | if( self->mValidateCallback ) |
@@ -182,6 +201,7 @@ void LLSpinCtrl::onDownBtn( void *userdata ) | |||
182 | if( self->getEnabled() ) | 201 | if( self->getEnabled() ) |
183 | { | 202 | { |
184 | F32 val = (F32)self->getValue().asReal() - self->mIncrement; | 203 | F32 val = (F32)self->getValue().asReal() - self->mIncrement; |
204 | val = clamp_precision(val, self->mPrecision); | ||
185 | val = llmax( val, self->mMinValue ); | 205 | val = llmax( val, self->mMinValue ); |
186 | 206 | ||
187 | if( self->mValidateCallback ) | 207 | if( self->mValidateCallback ) |
@@ -243,12 +263,13 @@ void LLSpinCtrl::clear() | |||
243 | } | 263 | } |
244 | 264 | ||
245 | 265 | ||
266 | |||
246 | void LLSpinCtrl::updateEditor() | 267 | void LLSpinCtrl::updateEditor() |
247 | { | 268 | { |
248 | LLLocale locale(LLLocale::USER_LOCALE); | 269 | LLLocale locale(LLLocale::USER_LOCALE); |
249 | 270 | ||
250 | // Don't display very small negative values as -0.000 | 271 | // Don't display very small negative values as -0.000 |
251 | F32 displayed_value = (F32)floor(getValue().asReal() * pow(10.0, (F64)mPrecision) + 0.5) / (F32)pow(10.0, (F64)mPrecision); | 272 | F32 displayed_value = clamp_precision((F32)getValue().asReal(), mPrecision); |
252 | 273 | ||
253 | // if( S32( displayed_value * pow( 10, mPrecision ) ) == 0 ) | 274 | // if( S32( displayed_value * pow( 10, mPrecision ) ) == 0 ) |
254 | // { | 275 | // { |
@@ -320,7 +341,7 @@ void LLSpinCtrl::setFocus(BOOL b) | |||
320 | 341 | ||
321 | void LLSpinCtrl::setEnabled(BOOL b) | 342 | void LLSpinCtrl::setEnabled(BOOL b) |
322 | { | 343 | { |
323 | LLUICtrl::setEnabled( b ); | 344 | LLView::setEnabled( b ); |
324 | mEditor->setEnabled( b ); | 345 | mEditor->setEnabled( b ); |
325 | } | 346 | } |
326 | 347 | ||
@@ -335,8 +356,8 @@ void LLSpinCtrl::setTentative(BOOL b) | |||
335 | BOOL LLSpinCtrl::isMouseHeldDown() | 356 | BOOL LLSpinCtrl::isMouseHeldDown() |
336 | { | 357 | { |
337 | return | 358 | return |
338 | gFocusMgr.getMouseCapture() == mDownBtn || | 359 | mDownBtn->hasMouseCapture() |
339 | gFocusMgr.getMouseCapture() == mUpBtn; | 360 | || mUpBtn->hasMouseCapture(); |
340 | } | 361 | } |
341 | 362 | ||
342 | void LLSpinCtrl::onCommit() | 363 | void LLSpinCtrl::onCommit() |