nux-1.14.0
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #include "Nux.h" 00024 #include "NuxGraphics/GLTextureResourceManager.h" 00025 #include "HLayout.h" 00026 #include "VLayout.h" 00027 #include "EditTextBox.h" 00028 #include "ToggleButton.h" 00029 #include "HexRegExpValidator.h" 00030 #include "IntegerValidator.h" 00031 #include "DoubleValidator.h" 00032 #include "RGBValuator.h" 00033 00034 namespace nux 00035 { 00036 NUX_IMPLEMENT_OBJECT_TYPE(RGBValuator); 00037 00038 RGBValuator::RGBValuator (NUX_FILE_LINE_DECL) 00039 : View(NUX_FILE_LINE_PARAM) 00040 , rgb_(1, 1, 1) 00041 , hsv_(rgb_) 00042 , hls_(rgb_) 00043 , m_color_model(color::RGB) 00044 , m_color_format(color::FLOAT) 00045 { 00046 InitializeLayout(); 00047 SetColorModel (m_color_model); 00048 SetColorFormat (m_color_format); 00049 SetRGBA (1.0f, 1.0f, 1.0f, 1.0f); 00050 InitializeWidgets(); 00051 } 00052 00053 RGBValuator::RGBValuator (Color const& color, NUX_FILE_LINE_DECL) 00054 : View (NUX_FILE_LINE_PARAM) 00055 , rgb_(1, 1, 1) 00056 , hsv_(rgb_) 00057 , hls_(rgb_) 00058 , m_color_model (color::RGB) 00059 , m_color_format (color::FLOAT) 00060 { 00061 InitializeLayout(); 00062 SetColorModel (m_color_model); 00063 SetColorFormat (m_color_format); 00064 SetRGBA (color); 00065 InitializeWidgets(); 00066 } 00067 00068 RGBValuator::RGBValuator (color::Model colorModel, float x, float y, float z, float alpha, NUX_FILE_LINE_DECL) 00069 : View (NUX_FILE_LINE_PARAM) 00070 , rgb_(1, 1, 1) 00071 , hsv_(rgb_) 00072 , hls_(rgb_) 00073 , m_color_model (colorModel) 00074 , m_color_format (color::FLOAT) 00075 { 00076 InitializeLayout(); 00077 00078 switch (m_color_model) 00079 { 00080 case color::HSV: 00081 { 00082 SetColorModel (color::HSV); 00083 SetHSV (x, y, z); 00084 SetAlpha (alpha); 00085 } 00086 case color::HLS: 00087 { 00088 SetColorModel (color::HLS); 00089 SetHLS (x, y, z); 00090 SetAlpha (alpha); 00091 } 00092 default: 00093 case color::RGB: 00094 { 00095 SetColorModel (color::RGB); 00096 SetRGBA (x, y, z, alpha); 00097 } 00098 } 00099 00100 SetColorFormat (m_color_format); 00101 00102 InitializeWidgets(); 00103 00104 } 00105 void RGBValuator::InitializeLayout() 00106 { 00107 hlayout = new HLayout (TEXT ("RGBValuatorLayout"), NUX_TRACKER_LOCATION); 00108 redlayout = new HLayout (TEXT ("RedLayout"), NUX_TRACKER_LOCATION); 00109 greenlayout = new HLayout (TEXT ("GreenLayout"), NUX_TRACKER_LOCATION); 00110 bluelayout = new HLayout (TEXT ("BlueLayout"), NUX_TRACKER_LOCATION); 00111 alphalayout = new HLayout (TEXT ("AlphaLayout"), NUX_TRACKER_LOCATION); 00112 vlayout = new VLayout (TEXT ("RGBVLayout"), NUX_TRACKER_LOCATION); 00113 colormodel_layout = new VLayout (TEXT ("ColorModel"), NUX_TRACKER_LOCATION); 00114 00115 m_ColorModel = new ToggleButton(); 00116 m_ColorFormat = new ToggleButton(); 00117 00118 m_RedCaption = new EditTextBox (TEXT (""), NUX_TRACKER_LOCATION); 00119 m_GreenCaption = new EditTextBox (TEXT (""), NUX_TRACKER_LOCATION); 00120 m_BlueCaption = new EditTextBox (TEXT (""), NUX_TRACKER_LOCATION); 00121 m_AlphaCaption = new EditTextBox (TEXT (""), NUX_TRACKER_LOCATION); 00122 00123 m_RedValuator = new InputArea (NUX_TRACKER_LOCATION); 00124 m_GreenValuator = new InputArea (NUX_TRACKER_LOCATION); 00125 m_BlueValuator = new InputArea (NUX_TRACKER_LOCATION); 00126 m_AlphaValuator = new InputArea (NUX_TRACKER_LOCATION); 00127 m_ColorSquare = new InputArea (NUX_TRACKER_LOCATION); 00128 00129 m_ComponentLabel0 = new InputArea (NUX_TRACKER_LOCATION); 00130 m_ComponentLabel1 = new InputArea (NUX_TRACKER_LOCATION); 00131 m_ComponentLabel2 = new InputArea (NUX_TRACKER_LOCATION); 00132 m_ComponentAlpha = new InputArea (NUX_TRACKER_LOCATION); 00133 } 00134 00135 void RGBValuator::InitializeWidgets() 00136 { 00137 m_HexRegExp.SetMaximum (255); 00138 m_HexRegExp.SetMinimum (0); 00139 m_IntRegExp.SetMaximum (255); 00140 m_IntRegExp.SetMinimum (0); 00141 m_DoubleRegExp.SetMaximum (1.0); 00142 m_DoubleRegExp.SetMinimum (0); 00143 00144 // Set Signals 00145 m_RedValuator->mouse_down.connect (sigc::mem_fun (this, &RGBValuator::OnReceiveMouseDown_Red) ); 00146 m_GreenValuator->mouse_down.connect (sigc::mem_fun (this, &RGBValuator::OnReceiveMouseDown_Green) ); 00147 m_BlueValuator->mouse_down.connect (sigc::mem_fun (this, &RGBValuator::OnReceiveMouseDown_Blue) ); 00148 m_AlphaValuator->mouse_down.connect (sigc::mem_fun (this, &RGBValuator::OnReceiveMouseDown_Alpha) ); 00149 m_RedValuator->mouse_drag.connect (sigc::mem_fun (this, &RGBValuator::OnReceiveMouseDrag_Red) ); 00150 m_GreenValuator->mouse_drag.connect (sigc::mem_fun (this, &RGBValuator::OnReceiveMouseDrag_Green) ); 00151 m_BlueValuator->mouse_drag.connect (sigc::mem_fun (this, &RGBValuator::OnReceiveMouseDrag_Blue) ); 00152 m_AlphaValuator->mouse_drag.connect (sigc::mem_fun (this, &RGBValuator::OnReceiveMouseDrag_Alpha) ); 00153 //FIXME - m_ColorModel->sigClick.connect (sigc::mem_fun (this, &RGBValuator::OnChangeColorModel) ); 00154 //FIXME - m_ColorFormat->sigClick.connect (sigc::mem_fun (this, &RGBValuator::OnChangeColorFormat) ); 00155 // m_ColorModel->mouse_down.connect(sigc::mem_fun(this, &RGBValuator::RecvColorModelEvent)); 00156 // m_ColorModel->mouse_up.connect(sigc::mem_fun(this, &RGBValuator::RecvColorModelEvent)); 00157 // m_ColorModel->mouse_enter.connect(sigc::mem_fun(this, &RGBValuator::RecvColorModelEvent)); 00158 00159 00160 m_ColorModel->SetFont (GetSysBoldFont() ); 00161 m_ColorFormat->SetFont (GetSysBoldFont() ); 00162 00163 m_RedValuator->mouse_up.connect (sigc::mem_fun (this, &RGBValuator::OnReceiveMouseUp_Red) ); 00164 m_GreenValuator->mouse_up.connect (sigc::mem_fun (this, &RGBValuator::OnReceiveMouseUp_Green) ); 00165 m_BlueValuator->mouse_up.connect (sigc::mem_fun (this, &RGBValuator::OnReceiveMouseUp_Blue) ); 00166 00167 m_RedCaption->sigValidateKeyboardEntry.connect (sigc::bind (sigc::mem_fun (this, &RGBValuator::OnComponentInput), 0) ); 00168 m_GreenCaption->sigValidateKeyboardEntry.connect (sigc::bind (sigc::mem_fun (this, &RGBValuator::OnComponentInput), 1) ); 00169 m_BlueCaption->sigValidateKeyboardEntry.connect (sigc::bind (sigc::mem_fun (this, &RGBValuator::OnComponentInput), 2) ); 00170 m_AlphaCaption->sigValidateKeyboardEntry.connect (sigc::bind (sigc::mem_fun (this, &RGBValuator::OnComponentInput), 3) ); 00171 00172 // Set Geometry 00173 00174 m_RedCaption->SetGeometry (Geometry (0, 0, 42, DEFAULT_WIDGET_HEIGHT) ); 00175 m_RedCaption->SetMaximumHeight (15); 00176 00177 m_GreenCaption->SetGeometry (Geometry (0, 0, 42, DEFAULT_WIDGET_HEIGHT) ); 00178 m_GreenCaption->SetMaximumHeight (15); 00179 00180 m_BlueCaption->SetGeometry (Geometry (0, 0, 42, DEFAULT_WIDGET_HEIGHT) ); 00181 m_BlueCaption->SetMaximumHeight (15); 00182 00183 m_AlphaCaption->SetGeometry (Geometry (0, 0, 42, DEFAULT_WIDGET_HEIGHT) ); 00184 m_AlphaCaption->SetMaximumHeight (15); 00185 00186 m_ComponentLabel0->SetMinimumSize (10, DEFAULT_WIDGET_HEIGHT); 00187 m_ComponentLabel0->SetMaximumHeight (15); 00188 //m_ComponentLabel0->SetGeometry(Geometry(0, 0, 15, DEFAULT_WIDGET_HEIGHT)); 00189 00190 m_ComponentLabel1->SetMinimumSize (10, DEFAULT_WIDGET_HEIGHT); 00191 m_ComponentLabel1->SetMaximumHeight (15); 00192 //m_ComponentLabel1->SetGeometry(Geometry(0, 0, 15, DEFAULT_WIDGET_HEIGHT)); 00193 00194 m_ComponentLabel2->SetMinimumSize (10, DEFAULT_WIDGET_HEIGHT); 00195 m_ComponentLabel2->SetMaximumHeight (15); 00196 //m_ComponentLabel2->SetGeometry(Geometry(0, 0, 15, DEFAULT_WIDGET_HEIGHT)); 00197 00198 m_ComponentAlpha->SetMinimumSize (10, DEFAULT_WIDGET_HEIGHT); 00199 m_ComponentAlpha->SetMaximumHeight (15); 00200 //m_ComponentAlpha->SetGeometry(Geometry(0, 0, 15, DEFAULT_WIDGET_HEIGHT)); 00201 00202 m_RedValuator->SetMinimumSize (3 * DEFAULT_WIDGET_WIDTH, 15); 00203 m_RedValuator->SetMaximumHeight (15); 00204 m_RedValuator->SetGeometry (Geometry (0, 0, DEFAULT_WIDGET_WIDTH, DEFAULT_WIDGET_HEIGHT) ); 00205 00206 m_GreenValuator->SetMinimumSize (3 * DEFAULT_WIDGET_WIDTH, 15); 00207 m_GreenValuator->SetMaximumHeight (15); 00208 m_GreenValuator->SetGeometry (Geometry (0, 0, DEFAULT_WIDGET_WIDTH, DEFAULT_WIDGET_HEIGHT) ); 00209 00210 m_BlueValuator->SetMinimumSize (3 * DEFAULT_WIDGET_WIDTH, 15); 00211 m_BlueValuator->SetMaximumHeight (15); 00212 m_BlueValuator->SetGeometry (Geometry (0, 0, DEFAULT_WIDGET_WIDTH, DEFAULT_WIDGET_HEIGHT) ); 00213 00214 m_AlphaValuator->SetMinimumSize (3 * DEFAULT_WIDGET_WIDTH, 15); 00215 m_AlphaValuator->SetMaximumHeight (15); 00216 m_AlphaValuator->SetGeometry (Geometry (0, 0, DEFAULT_WIDGET_WIDTH, DEFAULT_WIDGET_HEIGHT) ); 00217 00218 m_ColorSquare->SetMinimumSize (40, 40); 00219 m_ColorSquare->SetGeometry (Geometry (0, 0, 40, 40) ); 00220 m_ColorModel->SetMinimumSize (20, 16 /*PRACTICAL_WIDGET_HEIGHT*/); 00221 m_ColorFormat->SetMinimumSize (20, 16 /*PRACTICAL_WIDGET_HEIGHT*/); 00222 00223 redlayout->AddView (m_ComponentLabel0, 0); 00224 redlayout->AddView (m_RedCaption, 0); 00225 redlayout->AddView (m_RedValuator, 1); 00226 redlayout->SetHorizontalInternalMargin (4); 00227 00228 greenlayout->AddView (m_ComponentLabel1, 0); 00229 greenlayout->AddView (m_GreenCaption, 0); 00230 greenlayout->AddView (m_GreenValuator, 1); 00231 greenlayout->SetHorizontalInternalMargin (4); 00232 00233 bluelayout->AddView (m_ComponentLabel2, 0); 00234 bluelayout->AddView (m_BlueCaption, 0); 00235 bluelayout->AddView (m_BlueValuator, 1); 00236 bluelayout->SetHorizontalInternalMargin (4); 00237 00238 alphalayout->AddView (m_ComponentAlpha, 0); 00239 alphalayout->AddView (m_AlphaCaption, 0); 00240 alphalayout->AddView (m_AlphaValuator, 1); 00241 alphalayout->SetHorizontalInternalMargin (4); 00242 00243 // Set layout 00244 colormodel_layout->AddView (m_ColorSquare, 0, eCenter, eFix); 00245 colormodel_layout->AddView (m_ColorModel, 0, eCenter, eFull); 00246 colormodel_layout->AddView (m_ColorFormat, 0, eCenter, eFull); 00247 colormodel_layout->SetVerticalInternalMargin (2); 00248 00249 hlayout->AddView (colormodel_layout, 0, eCenter , eFull); 00250 00251 vlayout->AddLayout (redlayout, 1); 00252 vlayout->AddLayout (greenlayout, 1); 00253 vlayout->AddLayout (bluelayout, 1); 00254 vlayout->AddLayout (alphalayout, 1); 00255 vlayout->SetVerticalInternalMargin (2); 00256 vlayout->SetVerticalExternalMargin (4); 00257 vlayout->SetHorizontalExternalMargin (4); 00258 00259 00260 hlayout->AddLayout (vlayout, 10); 00261 hlayout->SetHorizontalInternalMargin (2); 00262 hlayout->SetHorizontalExternalMargin (6); 00263 hlayout->SetVerticalExternalMargin (4); 00264 00265 SetCompositionLayout (hlayout); 00266 00267 NTextureData image; 00268 MakeCheckBoardImage (image.GetSurface (0), 64, 64, Color (0xff000000), Color (0xff323232), 4, 4); 00269 BaseTexture* CheckboardPattern = GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableTexture (); 00270 CheckboardPattern->Update (&image); 00271 00272 TexCoordXForm texxform; 00273 texxform.SetTexCoordType (TexCoordXForm::OFFSET_COORD); 00274 texxform.SetWrap (TEXWRAP_REPEAT, TEXWRAP_REPEAT); 00275 m_CheckboardLayer = new TextureLayer (CheckboardPattern->GetDeviceTexture(), texxform, color::White); 00276 00277 CheckboardPattern->UnReference (); 00278 } 00279 00280 RGBValuator::~RGBValuator() 00281 { 00282 NUX_SAFE_DELETE (m_CheckboardLayer); 00283 } 00284 00285 void RGBValuator::DrawRedMarker (GraphicsEngine &GfxContext) 00286 { 00287 int marker_position_x; 00288 int marker_position_y; 00289 00290 float percent = 0.0f; 00291 00292 if (m_color_model == color::RGB) 00293 percent = rgb_.red; 00294 00295 if (m_color_model == color::HSV) 00296 percent = hsv_.hue; 00297 00298 if (m_color_model == color::HLS) 00299 percent = hls_.hue; 00300 00301 GfxContext.PushClippingRectangle (m_RedValuator->GetGeometry() ); 00302 00303 marker_position_x = m_RedValuator->GetBaseX() + percent * m_RedValuator->GetBaseWidth(); 00304 marker_position_y = m_RedValuator->GetBaseY() + m_RedValuator->GetBaseHeight(); 00305 GetPainter().Draw2DTriangleColor (GfxContext, marker_position_x - 5, marker_position_y, 00306 marker_position_x, marker_position_y - 5, 00307 marker_position_x + 5, marker_position_y, Color (0xFF000000) ); 00308 00309 GetPainter().Draw2DTriangleColor (GfxContext, marker_position_x - 4, marker_position_y, 00310 marker_position_x, marker_position_y - 4, 00311 marker_position_x + 4, marker_position_y, Color (0.7f, 0.7f, 0.7f, 1.0f) ); 00312 00313 GfxContext.PopClippingRectangle(); 00314 } 00315 00316 void RGBValuator::DrawGreenMarker (GraphicsEngine &GfxContext) 00317 { 00318 int marker_position_x; 00319 int marker_position_y; 00320 00321 float percent = 0.0f; 00322 00323 if (m_color_model == color::RGB) 00324 percent = rgb_.green; 00325 00326 if (m_color_model == color::HSV) 00327 percent = hsv_.saturation; 00328 00329 if (m_color_model == color::HLS) 00330 percent = hls_.lightness; 00331 00332 GfxContext.PushClippingRectangle (m_GreenValuator->GetGeometry() ); 00333 00334 marker_position_x = m_GreenValuator->GetBaseX() + percent * m_GreenValuator->GetBaseWidth(); 00335 marker_position_y = m_GreenValuator->GetBaseY() + m_GreenValuator->GetBaseHeight(); 00336 GetPainter().Draw2DTriangleColor (GfxContext, marker_position_x - 5, marker_position_y, 00337 marker_position_x, marker_position_y - 5, 00338 marker_position_x + 5, marker_position_y, Color (0.0f, 0.0f, 0.0f, 1.0f) ); 00339 00340 GetPainter().Draw2DTriangleColor (GfxContext, marker_position_x - 4, marker_position_y, 00341 marker_position_x, marker_position_y - 4, 00342 marker_position_x + 4, marker_position_y, Color (0.7f, 0.7f, 0.7f, 1.0f) ); 00343 00344 GfxContext.PopClippingRectangle(); 00345 } 00346 00347 void RGBValuator::DrawBlueMarker (GraphicsEngine &GfxContext) 00348 { 00349 int marker_position_x; 00350 int marker_position_y; 00351 00352 float percent = 0.0f; 00353 00354 if (m_color_model == color::RGB) 00355 percent = rgb_.blue; 00356 00357 if (m_color_model == color::HSV) 00358 percent = hsv_.value; 00359 00360 if (m_color_model == color::HLS) 00361 percent = hls_.saturation; 00362 00363 GfxContext.PushClippingRectangle (m_BlueValuator->GetGeometry() ); 00364 00365 marker_position_x = m_BlueValuator->GetBaseX() + percent * m_BlueValuator->GetBaseWidth(); 00366 marker_position_y = m_BlueValuator->GetBaseY() + m_BlueValuator->GetBaseHeight(); 00367 GetPainter().Draw2DTriangleColor (GfxContext, marker_position_x - 5, marker_position_y, 00368 marker_position_x, marker_position_y - 5, 00369 marker_position_x + 5, marker_position_y, Color (0.0f, 0.0f, 0.0f, 1.0f) ); 00370 00371 GetPainter().Draw2DTriangleColor (GfxContext, marker_position_x - 4, marker_position_y, 00372 marker_position_x, marker_position_y - 4, 00373 marker_position_x + 4, marker_position_y, Color (0.7f, 0.7f, 0.7f, 1.0f) ); 00374 00375 GfxContext.PopClippingRectangle(); 00376 } 00377 00378 void RGBValuator::DrawAlphaMarker (GraphicsEngine &GfxContext) 00379 { 00380 int marker_position_x; 00381 int marker_position_y; 00382 00383 GfxContext.PushClippingRectangle (m_AlphaValuator->GetGeometry() ); 00384 00385 marker_position_x = m_AlphaValuator->GetBaseX() + alpha_ * m_AlphaValuator->GetBaseWidth(); 00386 marker_position_y = m_AlphaValuator->GetBaseY() + m_AlphaValuator->GetBaseHeight(); 00387 GetPainter().Draw2DTriangleColor (GfxContext, marker_position_x - 5, marker_position_y, 00388 marker_position_x, marker_position_y - 5, 00389 marker_position_x + 5, marker_position_y, Color (0.0f, 0.0f, 0.0f, 1.0f) ); 00390 00391 GetPainter().Draw2DTriangleColor (GfxContext, marker_position_x - 4, marker_position_y, 00392 marker_position_x, marker_position_y - 4, 00393 marker_position_x + 4, marker_position_y, Color (0.7f, 0.7f, 0.7f, 1.0f) ); 00394 00395 GfxContext.PopClippingRectangle(); 00396 } 00397 00398 void RGBValuator::Draw (GraphicsEngine &GfxContext, bool force_draw) 00399 { 00400 Geometry base = GetGeometry(); 00401 00402 GfxContext.PushClippingRectangle (base); 00403 GetPainter().PushDrawShapeLayer (GfxContext, vlayout->GetGeometry(), eSHAPE_CORNER_ROUND4, Color (0xFF000000), eAllCorners); 00404 00405 if (m_color_model == color::RGB) 00406 { 00407 DrawRGB (GfxContext); 00408 } 00409 else if (m_color_model == color::HSV) 00410 { 00411 DrawHSV (GfxContext); 00412 } 00413 else if (m_color_model == color::HLS) 00414 { 00415 DrawHLS (GfxContext); 00416 } 00417 00418 GetPainter().PaintTextLineStatic (GfxContext, GetSysBoldFont(), m_ComponentLabel0->GetGeometry(), m_ComponentLabel0->GetBaseString().GetTCharPtr(), Color (0xFFFFFFFF) ); 00419 GetPainter().PaintTextLineStatic (GfxContext, GetSysBoldFont(), m_ComponentLabel1->GetGeometry(), m_ComponentLabel1->GetBaseString().GetTCharPtr(), Color (0xFFFFFFFF) ); 00420 GetPainter().PaintTextLineStatic (GfxContext, GetSysBoldFont(), m_ComponentLabel2->GetGeometry(), m_ComponentLabel2->GetBaseString().GetTCharPtr(), Color (0xFFFFFFFF) ); 00421 GetPainter().PaintTextLineStatic (GfxContext, GetSysBoldFont(), m_ComponentAlpha->GetGeometry(), m_ComponentAlpha->GetBaseString().GetTCharPtr(), Color (0xFFFFFFFF) ); 00422 00423 DrawRedMarker (GfxContext); 00424 DrawGreenMarker (GfxContext); 00425 DrawBlueMarker (GfxContext); 00426 DrawAlphaMarker (GfxContext); 00427 00428 m_RedCaption->QueueDraw(); 00429 m_GreenCaption->QueueDraw(); 00430 m_BlueCaption->QueueDraw(); 00431 m_AlphaCaption->QueueDraw(); 00432 m_ColorModel->QueueDraw(); 00433 m_ColorFormat->QueueDraw(); 00434 00435 GetPainter().PopBackground(); 00436 GfxContext.PopClippingRectangle(); 00437 } 00438 00439 void RGBValuator::DrawContent (GraphicsEngine &GfxContext, bool force_draw) 00440 { 00441 Geometry base = GetGeometry(); 00442 GfxContext.PushClippingRectangle (base); 00443 00444 m_RedCaption->ProcessDraw (GfxContext, force_draw); 00445 m_GreenCaption->ProcessDraw (GfxContext, force_draw); 00446 m_BlueCaption->ProcessDraw (GfxContext, force_draw); 00447 m_AlphaCaption->ProcessDraw (GfxContext, force_draw); 00448 00449 m_ColorModel->ProcessDraw (GfxContext, force_draw); // the button has round corner. That is why we need to push the background. 00450 m_ColorFormat->ProcessDraw (GfxContext, force_draw); // the button has round corner. That is why we need to push the background. 00451 GfxContext.PopClippingRectangle(); 00452 } 00453 00454 void RGBValuator::PostDraw (GraphicsEngine &GfxContext, bool force_draw) 00455 { 00456 00457 } 00458 00459 void RGBValuator::DrawRGB (GraphicsEngine &GfxContext) 00460 { 00461 // Red 00462 Geometry P = m_RedValuator->GetGeometry(); 00463 GetPainter().Paint2DQuadColor (GfxContext, P, Color (0.0f, rgb_.green, rgb_.blue), Color (0.0f, rgb_.green, rgb_.blue), 00464 Color (1.0f, rgb_.green, rgb_.blue), Color (1.0f, rgb_.green, rgb_.blue) ); 00465 00466 // Green 00467 P = m_GreenValuator->GetGeometry(); 00468 GetPainter().Paint2DQuadColor (GfxContext, P, Color (rgb_.red, 0.0f, rgb_.blue), Color (rgb_.red, 0.0f, rgb_.blue), 00469 Color (rgb_.red, 1.0f, rgb_.blue), Color (rgb_.red, 1.0f, rgb_.blue) ); 00470 00471 // Blue 00472 P = m_BlueValuator->GetGeometry(); 00473 GetPainter().Paint2DQuadColor (GfxContext, P, Color (rgb_.red, rgb_.green, 0.0f), Color (rgb_.red, rgb_.green, 0.0f), 00474 Color (rgb_.red, rgb_.green, 1.0f), Color (rgb_.red, rgb_.green, 1.0f) ); 00475 00476 // Alpha 00477 P = m_AlphaValuator->GetGeometry(); 00478 m_CheckboardLayer->SetGeometry (P); 00479 m_CheckboardLayer->Renderlayer (GfxContext); 00480 00481 GfxContext.GetRenderStates().SetBlend (true, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00482 GetPainter().Paint2DQuadColor (GfxContext, P, Color (0.0f, 0.0f, 0.0f, 0.0f), Color (0.0f, 0.0f, 0.0f, 0.0f), 00483 Color (rgb_.red, rgb_.green, rgb_.blue, 1.0f), Color (rgb_.red, rgb_.green, rgb_.blue, 1.0f) ); 00484 GfxContext.GetRenderStates().SetBlend (false); 00485 00486 P = m_ColorSquare->GetGeometry(); 00487 Geometry shadow_quad = P; 00488 P.OffsetSize (-2, -2); 00489 shadow_quad.OffsetSize (-2, -2); 00490 shadow_quad.OffsetPosition (2, 2); 00491 GetPainter().Paint2DQuadColor (GfxContext, shadow_quad, Color (0, 0, 0) ); 00492 GetPainter().Paint2DQuadColor (GfxContext, P, Color (rgb_.red, rgb_.green, rgb_.blue), Color (rgb_.red, rgb_.green, rgb_.blue), 00493 Color (rgb_.red, rgb_.green, rgb_.blue), Color (rgb_.red, rgb_.green, rgb_.blue) ); 00494 GetPainter().Paint2DQuadWireframe (GfxContext, P, Color (0, 0, 0) ); 00495 00496 m_ColorModel->ProcessDraw (GfxContext, true); 00497 m_ColorFormat->ProcessDraw (GfxContext, true); 00498 } 00499 00500 void RGBValuator::DrawHSV (GraphicsEngine &GfxContext) 00501 { 00502 // Red 00503 Geometry P = m_RedValuator->GetGeometry(); 00504 float s = 0; //XSI: 1.0f - hsv_.saturation; 00505 float v = 1; //XSI: hsv_.value; 00506 float fw = P.GetWidth() / 6; 00507 00508 Geometry p = Geometry (P.x, P.y, fw, P.GetHeight() ); 00509 GetPainter().Paint2DQuadColor (GfxContext, p, Color (1.0f * v, s * v, s * v), Color (1.0f * v, s * v, s * v), Color (1.0f * v, 1.0f * v, s * v), Color (1.0f * v, 1.0f * v, s * v) ); 00510 p.SetX (P.x + fw); 00511 GetPainter().Paint2DQuadColor (GfxContext, p, Color (1.0f * v, 1.0f * v, s * v), Color (1.0f * v, 1.0f * v, s * v), Color (s * v, 1.0f * v, s * v), Color (s * v, 1.0f * v, s * v) ); 00512 00513 p.SetX (P.x + 2 * fw); 00514 GetPainter().Paint2DQuadColor (GfxContext, p, Color (s * v, 1.0f * v, s * v), Color (s * v, 1.0f * v, s * v), Color (s * v, 1.0f * v, 1.0f * v), Color (s * v, 1.0f * v, 1.0f * v) ); 00515 p.SetX (P.x + 3 * fw); 00516 GetPainter().Paint2DQuadColor (GfxContext, p, Color (s * v, 1.0f * v, 1.0f * v), Color (s * v, 1.0f * v, 1.0f * v), Color (s * v, s * v, 1.0f * v), Color (s * v, s * v, 1.0f * v) ); 00517 00518 p.SetX (P.x + 4 * fw); 00519 GetPainter().Paint2DQuadColor (GfxContext, p, Color (s * v, s * v, 1.0f * v), Color (s * v, s * v, 1.0f * v), Color (1.0f * v, s * v, 1.0f * v), Color (1.0f * v, s * v, 1.0f * v) ); 00520 p.SetX (P.x + 5 * fw); 00521 p.SetWidth (P.GetWidth() - 5 * fw); // correct rounding errors 00522 GetPainter().Paint2DQuadColor (GfxContext, p, Color (1.0f * v, s * v, 1.0f * v), Color (1.0f * v, s * v, 1.0f * v), Color (1.0f * v, s * v, s * v), Color (1.0f * v, s * v, s * v) ); 00523 00524 s = 1.0f - hsv_.saturation; 00525 v = hsv_.value; 00526 00527 float hue = hsv_.hue; 00528 if (hue == 1.0f) 00529 hue = 0.0f; 00530 00531 color::RedGreenBlue rgb(color::HueSaturationValue(hue, 1, 1)); 00532 Color value_gray(v, v, v); 00533 Color value_color(Color(rgb) * v); 00534 // Green 00535 P = m_GreenValuator->GetGeometry(); 00536 GetPainter().Paint2DQuadColor(GfxContext, P, value_gray, value_gray, value_color, value_color); 00537 00538 rgb = color::RedGreenBlue(color::HueSaturationValue(hue, hsv_.saturation, 1)); 00539 // Blue 00540 P = m_BlueValuator->GetGeometry(); 00541 GetPainter().Paint2DQuadColor (GfxContext, P, color::Black, color::Black, Color(rgb), Color(rgb) ); 00542 00543 rgb = color::RedGreenBlue(color::HueSaturationValue(hue, hsv_.saturation, hsv_.value)); 00544 00545 // Alpha 00546 P = m_AlphaValuator->GetGeometry(); 00547 m_CheckboardLayer->SetGeometry (P); 00548 m_CheckboardLayer->Renderlayer (GfxContext); 00549 00550 GfxContext.GetRenderStates().SetBlend (true, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00551 GetPainter().Paint2DQuadColor (GfxContext, P, Color(0.0f, 0.0f, 0.0f, 0.0f), Color(0.0f, 0.0f, 0.0f, 0.0f), Color(rgb), Color(rgb) ); 00552 GfxContext.GetRenderStates().SetBlend (false); 00553 00554 P = m_ColorSquare->GetGeometry(); 00555 Geometry shadow_quad = P; 00556 P.OffsetSize (-2, -2); 00557 shadow_quad.OffsetSize (-2, -2); 00558 shadow_quad.OffsetPosition (2, 2); 00559 GetPainter().Paint2DQuadColor (GfxContext, shadow_quad, Color (0, 0, 0) ); 00560 GetPainter().Paint2DQuadColor (GfxContext, P, Color (rgb) ); 00561 GetPainter().Paint2DQuadWireframe (GfxContext, P, Color (0, 0, 0) ); 00562 00563 m_ColorModel->ProcessDraw (GfxContext, true); 00564 m_ColorFormat->ProcessDraw (GfxContext, true); 00565 } 00566 00567 void RGBValuator::DrawHLS (GraphicsEngine &GfxContext) 00568 { 00569 // Red 00570 Geometry P = m_RedValuator->GetGeometry(); 00571 float s = 0; //XSI: 1.0f - hls_.saturation; 00572 float l = 1; //XSI: hls_.lightness; 00573 float fw = P.GetWidth() / 6; 00574 00575 Geometry p = Geometry (P.x, P.y, fw, P.GetHeight() ); 00576 GetPainter().Paint2DQuadColor (GfxContext, p, Color (1.0f * l, s * l, s * l), Color (1.0f * l, s * l, s * l), Color (1.0f * l, 1.0f * l, s * l), Color (1.0f * l, 1.0f * l, s * l) ); 00577 p.SetX (P.x + fw); 00578 GetPainter().Paint2DQuadColor (GfxContext, p, Color (1.0f * l, 1.0f * l, s * l), Color (1.0f * l, 1.0f * l, s * l), Color (s * l, 1.0f * l, s * l), Color (s * l, 1.0f * l, s * l) ); 00579 00580 p.SetX (P.x + 2 * fw); 00581 GetPainter().Paint2DQuadColor (GfxContext, p, Color (s * l, 1.0f * l, s * l), Color (s * l, 1.0f * l, s * l), Color (s * l, 1.0f * l, 1.0f * l), Color (s * l, 1.0f * l, 1.0f * l) ); 00582 p.SetX (P.x + 3 * fw); 00583 GetPainter().Paint2DQuadColor (GfxContext, p, Color (s * l, 1.0f * l, 1.0f * l), Color (s * l, 1.0f * l, 1.0f * l), Color (s * l, s * l, 1.0f * l), Color (s * l, s * l, 1.0f * l) ); 00584 00585 p.SetX (P.x + 4 * fw); 00586 GetPainter().Paint2DQuadColor (GfxContext, p, Color (s * l, s * l, 1.0f * l), Color (s * l, s * l, 1.0f * l), Color (1.0f * l, s * l, 1.0f * l), Color (1.0f * l, s * l, 1.0f * l) ); 00587 p.SetX (P.x + 5 * fw); 00588 p.SetWidth (P.GetWidth() - 5 * fw); // correct rounding errors 00589 GetPainter().Paint2DQuadColor (GfxContext, p, Color (1.0f * l, s * l, 1.0f * l), Color (1.0f * l, s * l, 1.0f * l), Color (1.0f * l, s * l, s * l), Color (1.0f * l, s * l, s * l) ); 00590 00591 s = 1.0f - hls_.saturation; 00592 l = hls_.lightness; 00593 00594 float Hue; 00595 00596 if (hls_.hue == 1.0f) 00597 Hue = 0.0f; 00598 else 00599 Hue = hls_.hue; 00600 00601 // TODO: Tim Penhey 2011-05-13 00602 // refactor this code to use the same methods as the RGB(A)Property classes. 00603 color::RedGreenBlue rgb(color::HueSaturationValue(Hue, 1, 1)); 00604 // Need to use HSVtoRGB to compute the color 00605 float r = rgb.red; 00606 float g = rgb.green; 00607 float b = rgb.blue; 00608 00609 // Green 00610 P = m_GreenValuator->GetGeometry(); 00611 fw = P.GetWidth() / 2; 00612 p = Geometry (P.x, P.y, fw, P.GetHeight() ); 00613 GetPainter().Paint2DQuadColor (GfxContext, p, Color (0.0f, 0.0f, 0.0f), Color (0.0f, 0.0f, 0.0f), Color (r* (1 - s) + 0.5f * s, g* (1 - s) + 0.5f * s, b* (1 - s) + 0.5f * s), Color (r* (1 - s) + 0.5f * s, g* (1 - s) + 0.5f * s, b* (1 - s) + 0.5f * s) ); 00614 p.SetX (P.x + fw); 00615 GetPainter().Paint2DQuadColor (GfxContext, p, Color (r* (1 - s) + 0.5f * s, g* (1 - s) + 0.5f * s, b* (1 - s) + 0.5f * s), Color (r* (1 - s) + 0.5f * s, g* (1 - s) + 0.5f * s, b* (1 - s) + 0.5f * s), Color (1.0f, 1.0f, 1.0f), Color (1.0f, 1.0f, 1.0f) ); 00616 00617 00618 //HLStoRGB(r, g, b, Hue, hsv_.saturation, 1.0f); 00619 // Blue 00620 float cr, cg, cb; 00621 00622 if (l > 0.5) 00623 { 00624 float factor = (l - 0.5f) / 0.5f; 00625 cr = (1 - factor) * r * (1 - s) + 0.5 * s + factor * 1.0f; 00626 cg = (1 - factor) * g * (1 - s) + 0.5 * s + factor * 1.0f; 00627 cb = (1 - factor) * b * (1 - s) + 0.5 * s + factor * 1.0f; 00628 } 00629 else 00630 { 00631 float factor = l / 0.5f; 00632 cr = (factor) * r * (1 - s) + 0.5 * s; 00633 cg = (factor) * g * (1 - s) + 0.5 * s; 00634 cb = (factor) * b * (1 - s) + 0.5 * s; 00635 } 00636 00637 P = m_BlueValuator->GetGeometry(); 00638 GetPainter().Paint2DQuadColor (GfxContext, P, Color (l, l, l), Color (l, l, l), Color (cr, cg, cb), Color (cr, cg, cb) ); 00639 00640 // TODO: Tim Penhey 2011-05-13 00641 // Can we just use the rgb_ member variable? Check later. 00642 rgb = color::RedGreenBlue(hls_); 00643 00644 // Alpha 00645 P = m_AlphaValuator->GetGeometry(); 00646 m_CheckboardLayer->SetGeometry (P); 00647 m_CheckboardLayer->Renderlayer (GfxContext); 00648 00649 GfxContext.GetRenderStates().SetBlend (true, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00650 GetPainter().Paint2DQuadColor(GfxContext, P, Color(0.0f, 0.0f, 0.0f, 0.0f), Color (0.0f, 0.0f, 0.0f, 0.0f), Color(rgb), Color(rgb) ); 00651 GfxContext.GetRenderStates().SetBlend (false); 00652 00653 P = m_ColorSquare->GetGeometry(); 00654 Geometry shadow_quad = P; 00655 P.OffsetSize (-2, -2); 00656 shadow_quad.OffsetSize (-2, -2); 00657 shadow_quad.OffsetPosition (2, 2); 00658 GetPainter().Paint2DQuadColor (GfxContext, shadow_quad, Color (0, 0, 0) ); 00659 GetPainter().Paint2DQuadColor (GfxContext, P, Color (rgb) ); 00660 GetPainter().Paint2DQuadWireframe (GfxContext, P, Color (0, 0, 0) ); 00661 00662 m_ColorModel->ProcessDraw (GfxContext, true); 00663 m_ColorFormat->ProcessDraw (GfxContext, true); 00664 } 00665 00666 void RGBValuator::SetRGBA(Color const& color) 00667 { 00668 SetRGBA(color.red, color.green, color.blue, color.alpha); 00669 } 00670 00671 void RGBValuator::SetRGBA(float r, float g, float b, float a) 00672 { 00673 SetRGB(r, g, b); 00674 SetAlpha(a); 00675 } 00676 00677 void RGBValuator::SetRGB(Color const& color) 00678 { 00679 SetRGB(color.red, color.green, color.blue); 00680 } 00681 00682 void RGBValuator::SetRGB (float r, float g, float b) 00683 { 00684 rgb_.red = Clamp (r, 0.0f, 1.0f); 00685 rgb_.green = Clamp (g, 0.0f, 1.0f); 00686 rgb_.blue = Clamp (b, 0.0f, 1.0f); 00687 00688 bool RedEditSelected = m_RedCaption->IsTextSelected(); 00689 bool GreenEditSelected = m_GreenCaption->IsTextSelected(); 00690 bool BlueEditSelected = m_BlueCaption->IsTextSelected(); 00691 00692 if (m_color_format == color::HEX) 00693 { 00694 m_RedCaption->SetText (NString::Printf ("%x", (int) (rgb_.red * 255) ) ); 00695 m_GreenCaption->SetText (NString::Printf ("%x", (int) (rgb_.green * 255) ) ); 00696 m_BlueCaption->SetText (NString::Printf ("%x", (int) (rgb_.blue * 255) ) ); 00697 } 00698 else if (m_color_format == color::INT) 00699 { 00700 m_RedCaption->SetText (NString::Printf ("%d", (int) (rgb_.red * 255) ) ); 00701 m_GreenCaption->SetText (NString::Printf ("%d", (int) (rgb_.green * 255) ) ); 00702 m_BlueCaption->SetText (NString::Printf ("%d", (int) (rgb_.blue * 255) ) ); 00703 } 00704 else 00705 { 00706 m_RedCaption->SetText (NString::Printf ("%.3f", rgb_.red) ); 00707 m_GreenCaption->SetText (NString::Printf ("%.3f", rgb_.green) ); 00708 m_BlueCaption->SetText (NString::Printf ("%.3f", rgb_.blue) ); 00709 } 00710 00711 // Restore text selection if necessary. 00712 // This solves a problem when an EditTextBox of the widget gets the focus and has its text selected 00713 // but another who is losing the focus will cause it to lose the text selection by calling SetRGB. 00714 if (RedEditSelected) m_RedCaption->m_KeyboardHandler.SelectAllText(); 00715 00716 if (GreenEditSelected) m_GreenCaption->m_KeyboardHandler.SelectAllText(); 00717 00718 if (BlueEditSelected) m_BlueCaption->m_KeyboardHandler.SelectAllText(); 00719 00720 sigColorChanged.emit (rgb_.red, rgb_.green, rgb_.blue, alpha_); 00721 } 00722 00723 void RGBValuator::SetHSV (float h, float s, float v) 00724 { 00725 hsv_.hue = Clamp (h, 0.0f, 1.0f); 00726 hsv_.saturation = Clamp (s, 0.0f, 1.0f); 00727 hsv_.value = Clamp (v, 0.0f, 1.0f); 00728 00729 bool RedEditSelected = m_RedCaption->IsTextSelected(); 00730 bool GreenEditSelected = m_GreenCaption->IsTextSelected(); 00731 bool BlueEditSelected = m_BlueCaption->IsTextSelected(); 00732 00733 if (m_color_format == color::HEX) 00734 { 00735 m_RedCaption->SetText (NString::Printf ("%x", (int) (hsv_.hue * 255) ) ); 00736 m_GreenCaption->SetText (NString::Printf ("%x", (int) (hsv_.saturation * 255) ) ); 00737 m_BlueCaption->SetText (NString::Printf ("%x", (int) (hsv_.value * 255) ) ); 00738 } 00739 else if (m_color_format == color::INT) 00740 { 00741 m_RedCaption->SetText (NString::Printf ("%d", (int) (hsv_.hue * 255) ) ); 00742 m_GreenCaption->SetText (NString::Printf ("%d", (int) (hsv_.saturation * 255) ) ); 00743 m_BlueCaption->SetText (NString::Printf ("%d", (int) (hsv_.value * 255) ) ); 00744 } 00745 else 00746 { 00747 m_RedCaption->SetText (NString::Printf ("%.3f", hsv_.hue) ); 00748 m_GreenCaption->SetText (NString::Printf ("%.3f", hsv_.saturation) ); 00749 m_BlueCaption->SetText (NString::Printf ("%.3f", hsv_.value) ); 00750 } 00751 00752 if (hsv_.hue >= 1.0f) 00753 { 00754 hsv_.hue = 1.0f; 00755 // XSI: hsv_.hue = 0.0f; 00756 } 00757 00758 if (RedEditSelected) m_RedCaption->m_KeyboardHandler.SelectAllText(); 00759 00760 if (GreenEditSelected) m_GreenCaption->m_KeyboardHandler.SelectAllText(); 00761 00762 if (BlueEditSelected) m_BlueCaption->m_KeyboardHandler.SelectAllText(); 00763 00764 rgb_ = color::RedGreenBlue(hsv_); 00765 sigColorChanged.emit (rgb_.red, rgb_.green, rgb_.blue, alpha_); 00766 } 00767 00768 void RGBValuator::SetHLS (float h, float l, float s) 00769 { 00770 hls_.hue = Clamp (h, 0.0f, 1.0f); 00771 hls_.lightness = Clamp (l, 0.0f, 1.0f); 00772 hls_.saturation = Clamp (s, 0.0f, 1.0f); 00773 00774 bool RedEditSelected = m_RedCaption->IsTextSelected(); 00775 bool GreenEditSelected = m_GreenCaption->IsTextSelected(); 00776 bool BlueEditSelected = m_BlueCaption->IsTextSelected(); 00777 00778 if (m_color_format == color::HEX) 00779 { 00780 m_RedCaption->SetText (NString::Printf (TEXT ("%x"), (int) (hls_.hue * 255) ) ); 00781 m_GreenCaption->SetText (NString::Printf ("%x", (int) (hls_.lightness * 255) ) ); 00782 m_BlueCaption->SetText (NString::Printf ("%x", (int) (hls_.saturation * 255) ) ); 00783 } 00784 else if (m_color_format == color::INT) 00785 { 00786 m_RedCaption->SetText (NString::Printf (TEXT ("%d"), (int) (hls_.hue * 255) ) ); 00787 m_GreenCaption->SetText (NString::Printf ("%d", (int) (hls_.lightness * 255) ) ); 00788 m_BlueCaption->SetText (NString::Printf ("%d", (int) (hls_.saturation * 255) ) ); 00789 } 00790 else 00791 { 00792 m_RedCaption->SetText (NString::Printf (TEXT ("%.3f"), hls_.hue) ); 00793 m_GreenCaption->SetText (NString::Printf ("%.3f", hls_.lightness) ); 00794 m_BlueCaption->SetText (NString::Printf ("%.3f", hls_.saturation) ); 00795 } 00796 00797 if (hls_.hue >= 1.0f) 00798 { 00799 hls_.hue = 1.0f; 00800 // XSI: hls_.hue = 0.0f; 00801 } 00802 00803 if (RedEditSelected) m_RedCaption->m_KeyboardHandler.SelectAllText(); 00804 00805 if (GreenEditSelected) m_GreenCaption->m_KeyboardHandler.SelectAllText(); 00806 00807 if (BlueEditSelected) m_BlueCaption->m_KeyboardHandler.SelectAllText(); 00808 00809 rgb_ = color::RedGreenBlue(hls_); 00810 sigColorChanged.emit (rgb_.red, rgb_.green, rgb_.blue, alpha_); 00811 } 00812 00813 void RGBValuator::SetAlpha(float alpha) 00814 { 00815 alpha_ = Clamp (alpha, 0.0f, 1.0f); 00816 00817 if (m_color_format == color::HEX) 00818 { 00819 m_AlphaCaption->SetText (NString::Printf ("%x", (int) (alpha_ * 255) ) ); 00820 } 00821 else if (m_color_format == color::INT) 00822 { 00823 m_AlphaCaption->SetText (NString::Printf ("%d", (int) (alpha_ * 255) ) ); 00824 } 00825 else 00826 { 00827 m_AlphaCaption->SetText (NString::Printf ("%.3f", alpha_) ); 00828 } 00829 00830 sigColorChanged.emit(rgb_.red, rgb_.green, rgb_.blue, alpha_); 00831 } 00832 00833 void RGBValuator::OnReceiveMouseDown_Red (int x, int y, unsigned long button_flags, unsigned long key_flags) 00834 { 00835 if (m_color_model == color::RGB) 00836 { 00837 if (x < 0) 00838 rgb_.red = 0.0f; 00839 else if (x > m_RedValuator->GetBaseWidth() ) 00840 rgb_.red = 1.0f; 00841 else 00842 rgb_.red = (float) x / (float) m_RedValuator->GetBaseWidth(); 00843 00844 if (key_flags & NUX_STATE_CTRL) 00845 { 00846 SetRGB (rgb_.red, rgb_.red, rgb_.red); 00847 } 00848 else 00849 { 00850 SetRGB (rgb_.red, rgb_.green, rgb_.blue); 00851 } 00852 } 00853 else if (m_color_model == color::HSV) 00854 { 00855 if (x < 0) 00856 hsv_.hue = 0.0f; 00857 else if (x > m_RedValuator->GetBaseWidth() ) 00858 hsv_.hue = 1.0f; 00859 else 00860 hsv_.hue = (float) x / (float) m_RedValuator->GetBaseWidth(); 00861 00862 if (key_flags & NUX_STATE_CTRL) 00863 { 00864 SetHSV (hsv_.hue, hsv_.hue, hsv_.hue); 00865 } 00866 else 00867 { 00868 SetHSV (hsv_.hue, hsv_.saturation, hsv_.value); 00869 } 00870 } 00871 else if (m_color_model == color::HLS) 00872 { 00873 if (x < 0) 00874 hls_.hue = 0.0f; 00875 else if (x > m_RedValuator->GetBaseWidth() ) 00876 hls_.hue = 1.0f; 00877 else 00878 hls_.hue = (float) x / (float) m_RedValuator->GetBaseWidth(); 00879 00880 if (key_flags & NUX_STATE_CTRL) 00881 { 00882 SetHLS (hls_.hue, hls_.hue, hls_.hue); 00883 } 00884 else 00885 { 00886 SetHLS (hls_.hue, hls_.lightness, hls_.saturation); 00887 } 00888 } 00889 00890 QueueDraw(); 00891 } 00892 00893 void RGBValuator::OnReceiveMouseDown_Green (int x, int y, unsigned long button_flags, unsigned long key_flags) 00894 { 00895 if (m_color_model == color::RGB) 00896 { 00897 if (x < 0) 00898 rgb_.green = 0.0f; 00899 else if (x > m_GreenValuator->GetBaseWidth() ) 00900 rgb_.green = 1.0f; 00901 else 00902 rgb_.green = (float) x / (float) m_GreenValuator->GetBaseWidth(); 00903 00904 if (key_flags & NUX_STATE_CTRL) 00905 { 00906 SetRGB (rgb_.green, rgb_.green, rgb_.green); 00907 } 00908 else 00909 { 00910 SetRGB (rgb_.red, rgb_.green, rgb_.blue); 00911 } 00912 } 00913 else if (m_color_model == color::HSV) 00914 { 00915 if (x < 0) 00916 hsv_.saturation = 0.0f; 00917 else if (x > m_GreenValuator->GetBaseWidth() ) 00918 hsv_.saturation = 1.0f; 00919 else 00920 hsv_.saturation = (float) x / (float) m_GreenValuator->GetBaseWidth(); 00921 00922 if (key_flags & NUX_STATE_CTRL) 00923 { 00924 SetHSV (hsv_.saturation, hsv_.saturation, hsv_.saturation); 00925 } 00926 else 00927 { 00928 SetHSV (hsv_.hue, hsv_.saturation, hsv_.value); 00929 } 00930 } 00931 else if (m_color_model == color::HLS) 00932 { 00933 if (x < 0) 00934 hls_.lightness = 0.0f; 00935 else if (x > m_GreenValuator->GetBaseWidth() ) 00936 hls_.lightness = 1.0f; 00937 else 00938 hls_.lightness = (float) x / (float) m_GreenValuator->GetBaseWidth(); 00939 00940 if (key_flags & NUX_STATE_CTRL) 00941 { 00942 SetHLS (hls_.lightness, hls_.lightness, hls_.lightness); 00943 } 00944 else 00945 { 00946 SetHLS (hls_.hue, hls_.lightness, hls_.saturation); 00947 } 00948 } 00949 00950 QueueDraw(); 00951 } 00952 00953 void RGBValuator::OnReceiveMouseDown_Blue (int x, int y, unsigned long button_flags, unsigned long key_flags) 00954 { 00955 if (m_color_model == color::RGB) 00956 { 00957 if (x < 0) 00958 rgb_.blue = 0.0f; 00959 else if (x > m_BlueValuator->GetBaseWidth() ) 00960 rgb_.blue = 1.0f; 00961 else 00962 rgb_.blue = (float) x / (float) m_BlueValuator->GetBaseWidth(); 00963 00964 if (key_flags & NUX_STATE_CTRL) 00965 { 00966 SetRGB (rgb_.blue, rgb_.blue, rgb_.blue); 00967 } 00968 else 00969 { 00970 SetRGB (rgb_.red, rgb_.green, rgb_.blue); 00971 } 00972 } 00973 else if (m_color_model == color::HSV) 00974 { 00975 if (x < 0) 00976 hsv_.value = 0.0f; 00977 else if (x > m_BlueValuator->GetBaseWidth() ) 00978 hsv_.value = 1.0f; 00979 else 00980 hsv_.value = (float) x / (float) m_BlueValuator->GetBaseWidth(); 00981 00982 if (key_flags & NUX_STATE_CTRL) 00983 { 00984 SetHSV (hsv_.value, hsv_.value, hsv_.value); 00985 } 00986 else 00987 { 00988 SetHSV (hsv_.hue, hsv_.saturation, hsv_.value); 00989 } 00990 } 00991 else if (m_color_model == color::HLS) 00992 { 00993 if (x < 0) 00994 hls_.saturation = 0.0f; 00995 else if (x > m_BlueValuator->GetBaseWidth() ) 00996 hls_.saturation = 1.0f; 00997 else 00998 hls_.saturation = (float) x / (float) m_BlueValuator->GetBaseWidth(); 00999 01000 if (key_flags & NUX_STATE_CTRL) 01001 { 01002 SetHLS (hls_.saturation, hls_.saturation, hls_.saturation); 01003 } 01004 else 01005 { 01006 SetHLS (hls_.hue, hls_.lightness, hls_.saturation); 01007 } 01008 } 01009 01010 QueueDraw(); 01011 } 01012 01013 void RGBValuator::OnReceiveMouseDown_Alpha (int x, int y, unsigned long button_flags, unsigned long key_flags) 01014 { 01015 if (x < 0) 01016 alpha_ = 0.0f; 01017 else if (x > m_AlphaValuator->GetBaseWidth() ) 01018 alpha_ = 1.0f; 01019 else 01020 alpha_ = (float) x / (float) m_AlphaValuator->GetBaseWidth(); 01021 01022 SetAlpha (alpha_); 01023 QueueDraw(); 01024 } 01025 01026 void RGBValuator::OnReceiveMouseDrag_Red (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags) 01027 { 01028 OnReceiveMouseDown_Red (x, y, button_flags, key_flags); 01029 } 01030 01031 void RGBValuator::OnReceiveMouseDrag_Green (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags) 01032 { 01033 OnReceiveMouseDown_Green (x, y, button_flags, key_flags); 01034 } 01035 01036 void RGBValuator::OnReceiveMouseDrag_Blue (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags) 01037 { 01038 OnReceiveMouseDown_Blue (x, y, button_flags, key_flags); 01039 } 01040 01041 void RGBValuator::OnReceiveMouseDrag_Alpha (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags) 01042 { 01043 OnReceiveMouseDown_Alpha (x, y, button_flags, key_flags); 01044 } 01045 01046 void RGBValuator::OnReceiveMouseUp_Red (int x, int y, unsigned long button_flags, unsigned long key_flags) 01047 { 01048 if (m_color_model == color::HSV) 01049 { 01050 if (hsv_.hue >= 1.0f) 01051 { 01052 hsv_.hue = 1.0f; 01053 // XSI: hsv_.hue = 0.0f; 01054 } 01055 01056 if (hsv_.saturation <= 0.0f) 01057 { 01058 // XSI: hsv_.hue = 0.0f; 01059 } 01060 01061 if (hsv_.value <= 0.0f) 01062 { 01063 // XSI: hsv_.hue = 0.0f; 01064 // XSI: hsv_.saturation = 0.0f; 01065 } 01066 01067 SetHSV (hsv_.hue, hsv_.saturation, hsv_.value); 01068 } 01069 01070 if (m_color_model == color::HLS) 01071 { 01072 if (hls_.hue >= 1.0f) 01073 { 01074 hls_.hue = 1.0f; 01075 // XSI: hls_.hue = 0.0f; 01076 } 01077 01078 if (hls_.saturation <= 0.0f) 01079 { 01080 // XSI: hls_.hue = 0.0f; 01081 } 01082 01083 if (hls_.lightness <= 0.0f || hls_.lightness >= 1.0f) 01084 { 01085 // XSI: hls_.hue = 0.0f; 01086 // XSI: hls_.saturation = 0.0f; 01087 } 01088 01089 SetHLS (hls_.hue, hls_.lightness, hls_.saturation); 01090 } 01091 01092 QueueDraw(); 01093 } 01094 01095 void RGBValuator::OnReceiveMouseUp_Green (int x, int y, unsigned long button_flags, unsigned long key_flags) 01096 { 01097 if (m_color_model == color::HSV) 01098 { 01099 if (hsv_.hue >= 1.0f) 01100 { 01101 hsv_.hue = 1.0f; 01102 // XSI: hsv_.hue = 0.0f; 01103 } 01104 01105 if (hsv_.saturation <= 0.0f) 01106 { 01107 // XSI: hsv_.hue = 0.0f; 01108 } 01109 01110 if (hsv_.value <= 0.0f) 01111 { 01112 // XSI: hsv_.hue = 0.0f; 01113 // XSI: hsv_.saturation = 0.0f; 01114 } 01115 01116 SetHSV (hsv_.hue, hsv_.saturation, hsv_.value); 01117 } 01118 01119 if (m_color_model == color::HLS) 01120 { 01121 if (hls_.hue >= 1.0f) 01122 { 01123 hls_.hue = 1.0f; 01124 // XSI: hls_.hue = 0.0f; 01125 } 01126 01127 if (hls_.saturation <= 0.0f) 01128 { 01129 // XSI: hls_.hue = 0.0f; 01130 } 01131 01132 if (hls_.lightness <= 0.0f || hls_.lightness >= 1.0f) 01133 { 01134 // XSI: hls_.hue = 0.0f; 01135 // XSI: hls_.saturation = 0.0f; 01136 } 01137 01138 SetHLS (hls_.hue, hls_.lightness, hls_.saturation); 01139 } 01140 01141 QueueDraw(); 01142 } 01143 01144 void RGBValuator::OnReceiveMouseUp_Blue (int x, int y, unsigned long button_flags, unsigned long key_flags) 01145 { 01146 if (m_color_model == color::HSV) 01147 { 01148 if (hsv_.hue >= 1.0f) 01149 { 01150 hsv_.hue = 1.0f; 01151 // XSI: hsv_.hue = 0.0f; 01152 } 01153 01154 if (hsv_.saturation <= 0.0f) 01155 { 01156 // XSI: hsv_.hue = 0.0f; 01157 } 01158 01159 if (hsv_.value <= 0.0f) 01160 { 01161 // XSI: hsv_.hue = 0.0f; 01162 // XSI: hsv_.saturation = 0.0f; 01163 } 01164 01165 SetHSV (hsv_.hue, hsv_.saturation, hsv_.value); 01166 } 01167 01168 if (m_color_model == color::HLS) 01169 { 01170 if (hls_.hue >= 1.0f) 01171 { 01172 hls_.hue = 1.0f; 01173 // XSI: hls_.hue = 0.0f; 01174 } 01175 01176 if (hls_.saturation <= 0.0f) 01177 { 01178 // XSI: hls_.hue = 0.0f; 01179 } 01180 01181 if (hls_.lightness <= 0.0f || hls_.lightness >= 1.0f) 01182 { 01183 // XSI: hls_.hue = 0.0f; 01184 // XSI: hls_.saturation = 0.0f; 01185 } 01186 01187 SetHLS (hls_.hue, hls_.lightness, hls_.saturation); 01188 } 01189 01190 QueueDraw(); 01191 } 01192 01193 void RGBValuator::RecvMouseDownColorModel (int x, int y, unsigned long button_flags, unsigned long key_flags) 01194 { 01195 QueueDraw(); 01196 } 01197 01198 void RGBValuator::OnChangeColorModel() 01199 { 01200 if (m_color_model == color::RGB) 01201 { 01202 SetColorModel (color::HLS); 01203 hls_ = color::HueLightnessSaturation(rgb_); 01204 SetHLS (hls_.hue, hls_.lightness, hls_.saturation); 01205 } 01206 else if (m_color_model == color::HLS) 01207 { 01208 SetColorModel (color::HSV); 01209 rgb_ = color::RedGreenBlue(hls_); 01210 hsv_ = color::HueSaturationValue(rgb_); 01211 SetHSV (hsv_.hue, hsv_.saturation, hsv_.value); 01212 01213 if (hsv_.hue == -1.0f) 01214 { 01215 hsv_.hue = 0; 01216 } 01217 } 01218 else if (m_color_model == color::HSV) 01219 { 01220 SetColorModel (color::RGB); 01221 rgb_ = color::RedGreenBlue(hsv_); 01222 SetRGB (rgb_.red, rgb_.green, rgb_.blue); 01223 } 01224 01225 QueueDraw(); 01226 } 01227 01228 void RGBValuator::OnChangeColorFormat() 01229 { 01230 if (m_color_format == color::FLOAT) 01231 { 01232 SetColorFormat (color::INT); 01233 } 01234 else if (m_color_format == color::INT) 01235 { 01236 SetColorFormat (color::HEX); 01237 } 01238 else if (m_color_format == color::HEX) 01239 { 01240 SetColorFormat (color::FLOAT); 01241 } 01242 01243 } 01244 01245 void RGBValuator::OnComponentInput (EditTextBox *textbox, const NString &s, int componentIndex) 01246 { 01247 float f = 0; 01248 01249 if ( (m_color_format == color::HEX) && (m_HexRegExp.Validate (s.GetTCharPtr() ) == Validator::Acceptable) ) 01250 { 01251 f = (float) m_HexRegExp.ToInteger (s.GetTCharPtr() ) / 255.0f; 01252 } 01253 else if ( (m_color_format == color::INT) && (m_IntRegExp.Validate (s.GetTCharPtr() ) == Validator::Acceptable) ) 01254 { 01255 f = (float) m_IntRegExp.ToInteger (s.GetTCharPtr() ) / 255.0f; 01256 } 01257 else 01258 { 01259 f = (float) m_DoubleRegExp.ToDouble (s.GetTCharPtr() ); 01260 } 01261 01262 f = Clamp (f, 0.0f, 1.0f); 01263 01264 if (componentIndex == 0) 01265 { 01266 f = Clamp (f, 0.0f, 1.0f); 01267 01268 if (m_color_model == color::RGB) 01269 { 01270 rgb_.red = f; 01271 SetRGB (rgb_.red, rgb_.green, rgb_.blue); 01272 } 01273 else if (m_color_model == color::HSV) 01274 { 01275 hsv_.hue = f; 01276 OnReceiveMouseUp_Red (0, 0, 0, 0); 01277 SetHSV (hsv_.hue, hsv_.saturation, hsv_.value); 01278 } 01279 else if (m_color_model == color::HLS) 01280 { 01281 hls_.hue = f; 01282 OnReceiveMouseUp_Red (0, 0, 0, 0); 01283 SetHLS (hls_.hue, hls_.lightness, hls_.saturation); 01284 } 01285 } 01286 01287 if (componentIndex == 1) 01288 { 01289 f = Clamp (f, 0.0f, 1.0f); 01290 01291 if (m_color_model == color::RGB) 01292 { 01293 rgb_.green = f; 01294 SetRGB (rgb_.red, rgb_.green, rgb_.blue); 01295 } 01296 else if (m_color_model == color::HSV) 01297 { 01298 hsv_.saturation = f; 01299 OnReceiveMouseUp_Green (0, 0, 0, 0); 01300 SetHSV (hsv_.hue, hsv_.saturation, hsv_.value); 01301 } 01302 else if (m_color_model == color::HLS) 01303 { 01304 hls_.lightness = f; 01305 OnReceiveMouseUp_Green (0, 0, 0, 0); 01306 SetHLS (hls_.hue, hls_.lightness, hls_.saturation); 01307 } 01308 } 01309 01310 if (componentIndex == 2) 01311 { 01312 f = Clamp (f, 0.0f, 1.0f); 01313 01314 if (m_color_model == color::RGB) 01315 { 01316 rgb_.blue = f; 01317 SetRGB (rgb_.red, rgb_.green, rgb_.blue); 01318 } 01319 else if (m_color_model == color::HSV) 01320 { 01321 hsv_.value = f; 01322 OnReceiveMouseUp_Blue (0, 0, 0, 0); 01323 SetHSV (hsv_.hue, hsv_.saturation, hsv_.value); 01324 } 01325 else if (m_color_model == color::HLS) 01326 { 01327 hls_.saturation = f; 01328 OnReceiveMouseUp_Blue (0, 0, 0, 0); 01329 SetHLS (hls_.hue, hls_.lightness, hls_.saturation); 01330 } 01331 } 01332 01333 if (componentIndex == 3) 01334 { 01335 float f = 0; 01336 f = CharToDouble (s.GetTCharPtr() ); 01337 f = Clamp (f, 0.0f, 1.0f); 01338 //if(m_color_model == color::RGB) 01339 { 01340 alpha_ = f; 01341 SetAlpha (alpha_); 01342 } 01343 } 01344 01345 QueueDraw(); 01346 } 01347 01348 01349 void RGBValuator::SetColorModel(color::Model cm) 01350 { 01351 if (cm == color::RGB) 01352 { 01353 m_color_model = color::RGB; 01354 //FIXME - m_ColorModel->SetCaption (TEXT ("RGB") ); 01355 01356 m_ComponentLabel0->SetBaseString (TEXT ("R") ); 01357 m_ComponentLabel1->SetBaseString (TEXT ("G") ); 01358 m_ComponentLabel2->SetBaseString (TEXT ("B") ); 01359 m_ComponentAlpha->SetBaseString (TEXT ("A") ); 01360 01361 } 01362 01363 if (cm == color::HSV) 01364 { 01365 m_color_model = color::HSV; 01366 //FIXME - m_ColorModel->SetCaption (TEXT ("HSV") ); 01367 01368 m_ComponentLabel0->SetBaseString (TEXT ("H") ); 01369 m_ComponentLabel1->SetBaseString (TEXT ("S") ); 01370 m_ComponentLabel2->SetBaseString (TEXT ("V") ); 01371 m_ComponentAlpha->SetBaseString (TEXT ("A") ); 01372 } 01373 01374 if (cm == color::HLS) 01375 { 01376 m_color_model = color::HLS; 01377 //FIXME - m_ColorModel->SetCaption (TEXT ("HLS") ); 01378 01379 m_ComponentLabel0->SetBaseString (TEXT ("H") ); 01380 m_ComponentLabel1->SetBaseString (TEXT ("L") ); 01381 m_ComponentLabel2->SetBaseString (TEXT ("S") ); 01382 m_ComponentAlpha->SetBaseString (TEXT ("A") ); 01383 } 01384 01385 if (cm == color::YUV) 01386 { 01387 m_color_model = color::YUV; 01388 m_ColorModel->SetBaseString (TEXT ("YUV") ); 01389 01390 m_ComponentLabel0->SetBaseString (TEXT ("Y") ); 01391 m_ComponentLabel1->SetBaseString (TEXT ("U") ); 01392 m_ComponentLabel2->SetBaseString (TEXT ("V") ); 01393 m_ComponentAlpha->SetBaseString (TEXT ("A") ); 01394 } 01395 } 01396 01397 void RGBValuator::SetColorFormat (color::Format cf) 01398 { 01399 if (cf == color::FLOAT) 01400 { 01401 m_color_format = color::FLOAT; 01402 m_ColorFormat->SetBaseString (TEXT ("float") ); 01403 m_RedCaption->SetKeyEntryType (BaseKeyboardHandler::eAlphaNumeric); 01404 m_GreenCaption->SetKeyEntryType (BaseKeyboardHandler::eAlphaNumeric); 01405 m_BlueCaption->SetKeyEntryType (BaseKeyboardHandler::eAlphaNumeric); 01406 01407 m_RedCaption->SetPrefix (TEXT ("") ); 01408 m_GreenCaption->SetPrefix (TEXT ("") ); 01409 m_BlueCaption->SetPrefix (TEXT ("") ); 01410 m_AlphaCaption->SetPrefix (TEXT ("") ); 01411 } 01412 01413 if (cf == color::INT) 01414 { 01415 m_color_format = color::INT; 01416 m_ColorFormat->SetBaseString (TEXT ("int") ); 01417 m_RedCaption->SetKeyEntryType (BaseKeyboardHandler::eIntegerNumber); 01418 m_GreenCaption->SetKeyEntryType (BaseKeyboardHandler::eIntegerNumber); 01419 m_BlueCaption->SetKeyEntryType (BaseKeyboardHandler::eIntegerNumber); 01420 01421 m_RedCaption->SetPrefix (TEXT ("") ); 01422 m_GreenCaption->SetPrefix (TEXT ("") ); 01423 m_BlueCaption->SetPrefix (TEXT ("") ); 01424 m_AlphaCaption->SetPrefix (TEXT ("") ); 01425 } 01426 01427 if (cf == color::HEX) 01428 { 01429 m_color_format = color::HEX; 01430 m_ColorFormat->SetBaseString (TEXT ("hex") ); 01431 m_RedCaption->SetKeyEntryType (BaseKeyboardHandler::eHexadecimalNumber); 01432 m_GreenCaption->SetKeyEntryType (BaseKeyboardHandler::eHexadecimalNumber); 01433 m_BlueCaption->SetKeyEntryType (BaseKeyboardHandler::eHexadecimalNumber); 01434 01435 m_RedCaption->SetPrefix (TEXT ("0x") ); 01436 m_GreenCaption->SetPrefix (TEXT ("0x") ); 01437 m_BlueCaption->SetPrefix (TEXT ("0x") ); 01438 m_AlphaCaption->SetPrefix (TEXT ("0x") ); 01439 } 01440 01441 if (m_color_model == color::RGB) 01442 { 01443 SetRGBA (rgb_.red, rgb_.green, rgb_.blue, alpha_); 01444 } 01445 else if (m_color_model == color::HLS) 01446 { 01447 SetHLS (hls_.hue, hls_.lightness, hls_.saturation); 01448 SetAlpha (alpha_); 01449 } 01450 else if (m_color_model == color::HSV) 01451 { 01452 SetHSV (hsv_.hue, hsv_.saturation, hsv_.value); 01453 SetAlpha (alpha_); 01454 } 01455 } 01456 01457 long RGBValuator::ComputeChildLayout() 01458 { 01459 return View::ComputeChildLayout(); 01460 } 01461 01462 Color RGBValuator::GetColor() const 01463 { 01464 return Color(rgb_, alpha_); 01465 } 01466 01467 void RGBValuator::EmitColorChangedSignal() 01468 { 01469 sigColorChanged.emit (rgb_.red, rgb_.green, rgb_.blue, alpha_); 01470 } 01471 01472 bool RGBValuator::AcceptKeyNavFocus() 01473 { 01474 return false; 01475 } 01476 }