void LLFloaterColorPicker::onTextEntryChanged ( LLUICtrl* ctrl )
{
	// value in RGB boxes changed
	std::string name = ctrl->getName();
	if ( ( name == "rspin" ) || ( name == "gspin" ) || ( name == "bspin" ) )
	{
		// get current RGB
		F32 rVal, gVal, bVal;
		getCurRgb ( rVal, gVal, bVal );

		// update component value with new value from text
		if ( name == "rspin" )
		{
			rVal = (F32)ctrl->getValue().asReal() / 255.0f;
		}
		else
		if ( name == "gspin" )
		{
			gVal = (F32)ctrl->getValue().asReal() / 255.0f;
		}
		else
		if ( name == "bspin" )
		{
			bVal = (F32)ctrl->getValue().asReal() / 255.0f;
		}

		// update current RGB (and implicitly HSL)
		setCurRgb ( rVal, gVal, bVal );

		updateTextEntry ();
	}
	else
	// value in HSL boxes changed
	if ( ( name == "hspin" ) || ( name == "sspin" ) || ( name == "lspin" ) )
	{
		// get current HSL
		F32 hVal, sVal, lVal;
		getCurHsl ( hVal, sVal, lVal );

		// update component value with new value from text
		if ( name == "hspin" )
			hVal = (F32)ctrl->getValue().asReal() / 360.0f;
		else
		if ( name == "sspin" )
			sVal = (F32)ctrl->getValue().asReal() / 100.0f;
		else
		if ( name == "lspin" )
			lVal = (F32)ctrl->getValue().asReal() / 100.0f;

		// update current HSL (and implicitly RGB)
		setCurHsl ( hVal, sVal, lVal );

		updateTextEntry ();
	}

	if (mApplyImmediateCheck->get())
	{
		LLColorSwatchCtrl::onColorChanged ( getSwatch (), LLColorSwatchCtrl::COLOR_CHANGE );
	}
}
//////////////////////////////////////////////////////////////////////////////
// mutator for current RGB value
void LLFloaterColorPicker::setCurRgb ( F32 curRIn, F32 curGIn, F32 curBIn )
{
	// save current RGB
	curR = curRIn;
	curG = curGIn;
	curB = curBIn;

	// update corresponding HSL values and
	LLColor3(curRIn, curGIn, curBIn).calcHSL(&curH, &curS, &curL);

	// color changed so update text fields
    updateTextEntry();
}
Exemple #3
0
//Called when a hex value is entered into the Hex field  - Convert and set values.
void LLFloaterColorPicker::onHexCommit(const LLSD& value)
{
	char* pStop;
	int num = strtol(value.asString().c_str(), &pStop, 16);
	int r = (num & 0xFF0000) >> 16;
	int g = (num & 0xFF00) >> 8;
	int b = num & 0xFF;
	setCurRgb (r / 255.0f, g / 255.0f, b / 255.0f);

	updateTextEntry();
	if (mApplyImmediateCheck->get())
	{
		LLColorSwatchCtrl::onColorChanged(getSwatch(), LLColorSwatchCtrl::COLOR_CHANGE);
	}
}
void LLFloaterColorPicker::initUI ( F32 rValIn, F32 gValIn, F32 bValIn )
{
	// under some circumstances, we get rogue values that can be calmed by clamping...
	rValIn = llclamp ( rValIn, 0.0f, 1.0f );
	gValIn = llclamp ( gValIn, 0.0f, 1.0f );
	bValIn = llclamp ( bValIn, 0.0f, 1.0f );

	// store initial value in case cancel or revert is selected
	setOrigRgb ( rValIn, gValIn, bValIn );

	// starting point for current value to
	setCurRgb ( rValIn, gValIn, bValIn );

	// unpdate text entry fields
	updateTextEntry ();
}
//////////////////////////////////////////////////////////////////////////////
// mutator for current RGB value
void
LLFloaterColorPicker::
setCurRgb ( F32 curRIn, F32 curGIn, F32 curBIn )
{
	// save current RGB
	curR = curRIn;
	curG = curGIn;
	curB = curBIn;

	// update corresponding HSL values and
	LLColor3(curRIn, curGIn, curBIn).calcHSL(&curH, &curS, &curL);

	// color changed so update text fields (fixes SL-16968)
    // HACK: turn off the call back wilst we update the text or we recurse ourselves into oblivion
    // CP: this was required when I first wrote the code but this may not be necessary anymore - leaving it there just in case
    enableTextCallbacks( FALSE );
    updateTextEntry();
    enableTextCallbacks( TRUE );
}
BOOL LLFloaterColorPicker::handleHover ( S32 x, S32 y, MASK mask )
{
	// if we're the front most window
	if ( isFrontmost () )
	{
		// mouse was pressed within region
		if ( getMouseDownInHueRegion() || getMouseDownInLumRegion())
		{
			S32 clamped_x, clamped_y;
			if (getMouseDownInHueRegion())
			{
				clamped_x = llclamp(x, mRGBViewerImageLeft, mRGBViewerImageLeft + mRGBViewerImageWidth);
				clamped_y = llclamp(y, mRGBViewerImageTop - mRGBViewerImageHeight, mRGBViewerImageTop);
			}
			else
			{
				clamped_x = llclamp(x, mLumRegionLeft, mLumRegionLeft + mLumRegionWidth);
				clamped_y = llclamp(y, mLumRegionTop - mLumRegionHeight, mLumRegionTop);
			}

			// update the stored RGB/HSL values using the mouse position - returns TRUE if RGB was updated
			if ( updateRgbHslFromPoint ( clamped_x, clamped_y ) )
			{
				// update text entry fields
				updateTextEntry ();

				// RN: apparently changing color when dragging generates too much traffic and results in sporadic updates
				//// commit changed color to swatch subject
				//// REVIEW: this gets sent each time a color changes - is this okay ?
				//if (mApplyImmediateCheck->get())
				//{
				//	LLColorSwatchCtrl::onColorChanged ( getSwatch () );
				//}
			}
		}

		highlightEntry = -1;

		if ( mMouseDownInSwatch )
		{
			getWindow()->setCursor ( UI_CURSOR_ARROWDRAG );

			// if cursor if over a palette entry
			LLRect paletteRect ( mPaletteRegionLeft,
								mPaletteRegionTop,
								mPaletteRegionLeft + mPaletteRegionWidth,
								mPaletteRegionTop - mPaletteRegionHeight );

			if ( paletteRect.pointInRect ( x, y ) )
			{
				// find row/column in palette
				S32 xOffset = ( ( x - mPaletteRegionLeft ) * numPaletteColumns ) / mPaletteRegionWidth;
				S32 yOffset = ( ( mPaletteRegionTop - y - 1 ) * numPaletteRows ) / mPaletteRegionHeight;

				// calculate the entry 0..n-1 to highlight and set variable to next draw() picks it up
				highlightEntry = xOffset + yOffset * numPaletteColumns;
			}

			return TRUE;
		}
	}

	// dispatch to base class for the rest of things
	return LLFloater::handleHover ( x, y, mask );
}
BOOL LLFloaterColorPicker::handleMouseDown ( S32 x, S32 y, MASK mask )
{
	// make it the frontmost
	gFloaterView->bringToFront(this);

	// rect containing RGB area
	LLRect rgbAreaRect ( mRGBViewerImageLeft,
						 mRGBViewerImageTop,
						 mRGBViewerImageLeft + mRGBViewerImageWidth,
						 mRGBViewerImageTop - mRGBViewerImageHeight );

	if ( rgbAreaRect.pointInRect ( x, y ) )
	{
		gFocusMgr.setMouseCapture(this);
		// mouse button down
		setMouseDownInHueRegion ( TRUE );

		// update all values based on initial click
		updateRgbHslFromPoint ( x, y );

		// required by base class
		return TRUE;
	}

	// rect containing RGB area
	LLRect lumAreaRect ( mLumRegionLeft,
						 mLumRegionTop,
						 mLumRegionLeft + mLumRegionWidth + mLumMarkerSize,
						 mLumRegionTop - mLumRegionHeight );

	if ( lumAreaRect.pointInRect ( x, y ) )
	{
		gFocusMgr.setMouseCapture(this);
		// mouse button down
		setMouseDownInLumRegion ( TRUE );

		// required by base class
		return TRUE;
	}

	// rect containing swatch area
	LLRect swatchRect ( mSwatchRegionLeft,
						mSwatchRegionTop,
						mSwatchRegionLeft + mSwatchRegionWidth,
						mSwatchRegionTop - mSwatchRegionHeight );

	setMouseDownInSwatch( FALSE );
	if ( swatchRect.pointInRect ( x, y ) )
	{
		setMouseDownInSwatch( TRUE );

		// required - dont drag windows here.
		return TRUE;
	}

	// rect containing palette area
	LLRect paletteRect ( mPaletteRegionLeft,
						 mPaletteRegionTop,
						 mPaletteRegionLeft + mPaletteRegionWidth,
						 mPaletteRegionTop - mPaletteRegionHeight );

	if ( paletteRect.pointInRect ( x, y ) )
	{
		// release keyboard focus so we can change text values
		if (gFocusMgr.childHasKeyboardFocus(this))
		{
			mSelectBtn->setFocus(TRUE);
		}

		// calculate which palette index we selected
		S32 c = ( ( x - mPaletteRegionLeft ) * numPaletteColumns ) / mPaletteRegionWidth;
		S32 r = ( ( y - ( mPaletteRegionTop - mPaletteRegionHeight ) ) * numPaletteRows ) / mPaletteRegionHeight;

		U32 index = ( numPaletteRows - r - 1 ) * numPaletteColumns + c;

		if ( index <= mPalette.size () )
		{
			LLColor4 selected = *mPalette [ index ];

			setCurRgb ( selected [ 0 ], selected [ 1 ], selected [ 2 ] );

			if (mApplyImmediateCheck->get())
			{
				LLColorSwatchCtrl::onColorChanged ( getSwatch (), LLColorSwatchCtrl::COLOR_CHANGE );
			}

			updateTextEntry ();
		}

		return TRUE;
	}

	// dispatch to base class for the rest of things
	
	return LLFloater::handleMouseDown ( x, y, mask );
}
void LLFloaterColorPicker::onTextEntryChanged ( LLUICtrl* ctrl )
{
	// value in RGB boxes changed
	std::string name = ctrl->getName();
	if ( ( name == "rspin" ) || ( name == "gspin" ) || ( name == "bspin" ) )
	{
		// get current RGB
		F32 rVal, gVal, bVal;
		getCurRgb ( rVal, gVal, bVal );

		// update component value with new value from text
		if ( name == "rspin" )
		{
			rVal = (F32)ctrl->getValue().asReal() / 255.0f;
		}
		else
		if ( name == "gspin" )
		{
			gVal = (F32)ctrl->getValue().asReal() / 255.0f;
		}
		else
		if ( name == "bspin" )
		{
			bVal = (F32)ctrl->getValue().asReal() / 255.0f;
		}

		// update current RGB (and implicitly HSL)
		selectCurRgb ( rVal, gVal, bVal );

		updateTextEntry ();
	}
	// <FS:Zi> Add float LSL color entry widgets
	else if ( ( name == "rspin_lsl" ) || ( name == "gspin_lsl" ) || ( name == "bspin_lsl" ) )
	{
		// get current RGB
		F32 rVal, gVal, bVal;
		getCurRgb ( rVal, gVal, bVal );

		// update component value with new value from text
		if ( name == "rspin_lsl" )
		{
			rVal = (F32)ctrl->getValue().asReal();
		}
		else
		if ( name == "gspin_lsl" )
		{
			gVal = (F32)ctrl->getValue().asReal();
		}
		else
		if ( name == "bspin_lsl" )
		{
			bVal = (F32)ctrl->getValue().asReal();
		}

		// update current RGB (and implicitly HSL)
		setCurRgb ( rVal, gVal, bVal );

		updateTextEntry ();
	}
	else if ( name == "hex_value" )
	{
		// get current RGB
		S32 r, g, b;
		F32 rVal, gVal, bVal;
		getCurRgb ( rVal, gVal, bVal );

		std::string hex_string=ctrl->getValue().asString();

		if(hex_string.length()!=6)
			return;

		LLStringUtil::toLower(hex_string);

		if(hex_string.find_first_not_of("0123456789abcdef")!=std::string::npos)
			return;

		sscanf(hex_string.c_str(),"%02x%02x%02x", &r,&g,&b);

		rVal=(F32) r/255.0;
		gVal=(F32) g/255.0;
		bVal=(F32) b/255.0;

		// update current RGB (and implicitly HSL)
		setCurRgb ( rVal, gVal, bVal );

		updateTextEntry ();
	}
	// </FS:Zi>
	else
	// value in HSL boxes changed
	if ( ( name == "hspin" ) || ( name == "sspin" ) || ( name == "lspin" ) )
	{
		// get current HSL
		F32 hVal, sVal, lVal;
		getCurHsl ( hVal, sVal, lVal );

		// update component value with new value from text
		if ( name == "hspin" )
			hVal = (F32)ctrl->getValue().asReal() / 360.0f;
		else
		if ( name == "sspin" )
			sVal = (F32)ctrl->getValue().asReal() / 100.0f;
		else
		if ( name == "lspin" )
			lVal = (F32)ctrl->getValue().asReal() / 100.0f;

		// update current HSL (and implicitly RGB)
		selectCurHsl ( hVal, sVal, lVal );

		updateTextEntry ();
	}
}