Hex Values in color picker, as well as general cleanup of the color picker.

Signed-off-by: Beeks <HgDelirium@gmail.com>
This commit is contained in:
Beeks
2010-09-21 14:44:52 -04:00
parent 8c7055b835
commit 64abd1889f
3 changed files with 87 additions and 28 deletions

View File

@@ -96,7 +96,7 @@ LLFloaterColorPicker (LLColorSwatchCtrl* swatch, BOOL show_apply_immediate )
mLumMarkerSize ( 6 ),
// *TODO: Specify this in XML
mSwatchRegionLeft ( 12 ),
mSwatchRegionTop ( 190 ),
mSwatchRegionTop ( 170 ),
mSwatchRegionWidth ( 116 ),
mSwatchRegionHeight ( 60 ),
mSwatchView ( NULL ),
@@ -105,7 +105,7 @@ LLFloaterColorPicker (LLColorSwatchCtrl* swatch, BOOL show_apply_immediate )
numPaletteRows ( 2 ),
highlightEntry ( -1 ),
mPaletteRegionLeft ( 11 ),
mPaletteRegionTop ( 100 - 8 ),
mPaletteRegionTop ( 92 ),
mPaletteRegionWidth ( mLumRegionLeft + mLumRegionWidth - 10 ),
mPaletteRegionHeight ( 40 ),
mSwatch ( swatch ),
@@ -249,6 +249,7 @@ postBuild()
childSetCommitCallback("hspin", onTextCommit, (void*)this );
childSetCommitCallback("sspin", onTextCommit, (void*)this );
childSetCommitCallback("lspin", onTextCommit, (void*)this );
childSetCommitCallback("hexval", onHexCommit, (void*)this );
return TRUE;
}
@@ -615,8 +616,8 @@ void LLFloaterColorPicker::draw()
// create rgb area outline
gl_rect_2d ( mRGBViewerImageLeft,
mRGBViewerImageTop - mRGBViewerImageHeight,
mRGBViewerImageLeft + mRGBViewerImageWidth,
mRGBViewerImageTop - mRGBViewerImageHeight + 1,
mRGBViewerImageLeft + mRGBViewerImageWidth + 1,
mRGBViewerImageTop,
LLColor4 ( 0.0f, 0.0f, 0.0f, 1.0f ),
FALSE );
@@ -635,7 +636,7 @@ void LLFloaterColorPicker::draw()
}
// draw luninance marker
// draw luminance marker
S32 startX = mLumRegionLeft + mLumRegionWidth;
S32 startY = mLumRegionTop - mLumRegionHeight + ( S32 ) ( mLumRegionHeight * getCurL () );
gl_triangle_2d ( startX, startY,
@@ -645,8 +646,8 @@ void LLFloaterColorPicker::draw()
// draw luminance slider outline
gl_rect_2d ( mLumRegionLeft,
mLumRegionTop - mLumRegionHeight,
mLumRegionLeft + mLumRegionWidth,
mLumRegionTop - mLumRegionHeight + 1,
mLumRegionLeft + mLumRegionWidth + 1,
mLumRegionTop,
LLColor4 ( 0.0f, 0.0f, 0.0f, 1.0f ),
FALSE );
@@ -661,8 +662,8 @@ void LLFloaterColorPicker::draw()
// draw selected color swatch outline
gl_rect_2d ( mSwatchRegionLeft,
mSwatchRegionTop - mSwatchRegionHeight,
mSwatchRegionLeft + mSwatchRegionWidth,
mSwatchRegionTop - mSwatchRegionHeight + 1,
mSwatchRegionLeft + mSwatchRegionWidth + 1,
mSwatchRegionTop,
LLColor4 ( 0.0f, 0.0f, 0.0f, 1.0f ),
FALSE );
@@ -714,7 +715,7 @@ drawPalette ()
// draw palette entry color
if ( mPalette [ curEntry ] )
{
gl_rect_2d ( x1 + 2, y1 - 2, x2 - 2, y2 + 2, *mPalette [ curEntry++ ], TRUE );
gl_rect_2d ( x1 + 1, y1 - 2, x2 - 2, y2 + 1, *mPalette [ curEntry++ ], TRUE );
gl_rect_2d ( x1 + 1, y1 - 1, x2 - 1, y2 + 1, LLColor4 ( 0.0f, 0.0f, 0.0f, 1.0f ), FALSE );
}
}
@@ -746,6 +747,50 @@ drawPalette ()
}
}
//Convert to Hex.
std::string RGBToHex(int rNum, int gNum, int bNum)
{
std::string result;
char chr[255];
sprintf_s(chr, "%.2X", rNum);
result.append(chr);
sprintf_s(chr, "%.2X", gNum);
result.append(chr);
sprintf_s(chr, "%.2X", bNum);
result.append(chr);
return result;
}
//Called when a hex value is entered into the Hex field - Convert and set values.
void
LLFloaterColorPicker::
onHexCommit ( LLUICtrl* ctrl, void* data )
{
if ( data )
{
LLFloaterColorPicker* self = ( LLFloaterColorPicker* )data;
if ( self )
{
char* pStop;
int num = strtol(ctrl->getValue().asString().c_str(), &pStop, 16);
int r = (num & 0xFF0000) >> 16;
int g = (num & 0xFF00) >> 8;
int b = num & 0xFF;
self->setCurRgb (r / 255.0f, g / 255.0f, b / 255.0f);
// HACK: turn off the call back wilst we update the text or we recurse ourselves into oblivion
self->enableTextCallbacks ( FALSE );
self->updateTextEntry ();
self->enableTextCallbacks ( TRUE );
if (self->mApplyImmediateCheck->get())
{
LLColorSwatchCtrl::onColorChanged ( self->getSwatch (), LLColorSwatchCtrl::COLOR_CHANGE );
}
}
}
}
//////////////////////////////////////////////////////////////////////////////
// update text entry values for RGB/HSL (can't be done in ::draw () since this overwrites input
void
@@ -759,6 +804,7 @@ updateTextEntry ()
childSetValue("hspin", ( getCurH () * 360.0f ) );
childSetValue("sspin", ( getCurS () * 100.0f ) );
childSetValue("lspin", ( getCurL () * 100.0f ) );
childSetValue("hexval", RGBToHex(getCurR() * 255, getCurG() * 255, getCurB() * 255));
}
//////////////////////////////////////////////////////////////////////////////
@@ -775,6 +821,7 @@ enableTextCallbacks ( BOOL stateIn )
childSetCommitCallback("hspin", onTextCommit, (void*)this );
childSetCommitCallback("sspin", onTextCommit, (void*)this );
childSetCommitCallback("lspin", onTextCommit, (void*)this );
childSetCommitCallback("hexval", onHexCommit, (void*)this );
}
else
{
@@ -784,6 +831,7 @@ enableTextCallbacks ( BOOL stateIn )
childSetCommitCallback("hspin", 0, (void*)this );
childSetCommitCallback("sspin", 0, (void*)this );
childSetCommitCallback("lspin", 0, (void*)this );
childSetCommitCallback("hexval", 0, (void*)this );
}
}

View File

@@ -116,7 +116,7 @@ class LLFloaterColorPicker
// convert RGB to HSL and vice-versa
void hslToRgb ( F32 hValIn, F32 sValIn, F32 lValIn, F32& rValOut, F32& gValOut, F32& bValOut );
F32 hueToRgb ( F32 val1In, F32 val2In, F32 valHUeIn );
void setActive(BOOL active);
protected:
@@ -125,6 +125,7 @@ class LLFloaterColorPicker
static void onClickSelect ( void* data );
static void onClickPipette ( void* data );
static void onTextCommit ( LLUICtrl* ctrl, void* data );
static void onHexCommit ( LLUICtrl* ctrl, void* data );
static void onImmediateCheck ( LLUICtrl* ctrl, void* data );
static void onColorSelect( const LLTextureEntry& te, void *data );
private:

View File

@@ -55,30 +55,40 @@
Lum:
</text>
<spinner bottom="-166" decimal_digits="0" follows="left" height="16" increment="1"
initial_val="50" left="75" max_val="100" min_val="0" mouse_opaque="true"
name="lspin" width="50" />
initial_val="50" left="75" max_val="100" min_val="0" mouse_opaque="true"
name="lspin" width="50" />
<check_box bottom="-373" follows="left|bottom" font="SansSerifSmall" height="20"
initial_value="false" label="Apply Immediately" left="12"
mouse_opaque="true" name="apply_immediate" width="100" />
initial_value="false" label="Apply Immediately" left="12"
mouse_opaque="true" name="apply_immediate" width="100" />
<button bottom="-373" follows="left|top" font="SansSerif" halign="center" height="32"
label="" label_selected="" left_delta="130" mouse_opaque="true"
name="color_pipette" width="32" />
label="" label_selected="" left_delta="130" mouse_opaque="true"
name="color_pipette" width="32" />
<button bottom="-373" follows="right|bottom" font="SansSerif" halign="center"
height="20" label="Cancel" label_selected="Cancel" left_delta="75"
mouse_opaque="true" name="cancel_btn" width="100" />
height="20" label="Cancel" label_selected="Cancel" left_delta="75"
mouse_opaque="true" name="cancel_btn" width="100" />
<button bottom="-373" follows="right|bottom" font="SansSerif" halign="center"
height="20" label="Select" label_selected="Select" left_delta="104"
mouse_opaque="true" name="select_btn" width="100" />
height="20" label="Select" label_selected="Select" left_delta="104"
mouse_opaque="true" name="select_btn" width="100" />
<text bg_visible="false" border_drop_shadow_visible="false" border_visible="false"
bottom="-188" drop_shadow_visible="true" follows="left|top"
font="SansSerifSmall" h_pad="0" halign="left" height="16" left="12"
mouse_opaque="true" name="Current color:" v_pad="0" width="110">
bottom="-190" drop_shadow_visible="true" follows="left|top"
font="SansSerifSmall" h_pad="0" halign="left" height="16" left="12"
mouse_opaque="true" name="Hex Value:" v_pad="0" width="110">
Hex:
</text>
<line_editor bevel_style="in" border_style="line" border_thickness="1" bottom_delta="0" follows="left|top"
font="SansSerifSmall" height="18" left_delta="64" max_length="7" mouse_opaque="true"
tool_tip="" name="hexval" control_name="ColorHexValue"
width="49"/>
<text bg_visible="false" border_drop_shadow_visible="false" border_visible="false"
bottom="-210" drop_shadow_visible="true" follows="left|top"
font="SansSerifSmall" h_pad="0" halign="left" height="16" left="12"
mouse_opaque="true" name="Current color:" v_pad="0" width="110">
Current color:
</text>
<text bg_visible="false" border_drop_shadow_visible="false" border_visible="false"
bottom="-270" drop_shadow_visible="true" follows="left|top"
font="SansSerifSmall" h_pad="0" halign="left" height="16" left="12"
mouse_opaque="true" name="(Drag below to save.)" v_pad="0" width="110">
(Drag below to save.)
bottom="-288" drop_shadow_visible="true" follows="left|top"
font="SansSerifSmall" h_pad="0" halign="left" height="16" left="12"
mouse_opaque="true" name="(Drag below to save.)" v_pad="0" width="110">
Drag below to save.
</text>
</floater>