nux-1.14.0
ColorEditor.cpp
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 
00025 #include "NuxGraphics/GLSh_ColorPicker.h"
00026 #include "VLayout.h"
00027 #include "HLayout.h"
00028 #include "CheckBox.h"
00029 #include "EditTextBox.h"
00030 //#include "RadioButton.h"
00031 //#include "RadioButtonGroup.h"
00032 #include "ToggleButton.h"
00033 #include "Layout.h"
00034 #include "ColorEditor.h"
00035 
00036 namespace nux
00037 {
00038 
00039   static void ThreadColorEditorDialog (NThread *thread, void *InitData)
00040   {
00041     VLayout *MainLayout (new VLayout (NUX_TRACKER_LOCATION) );
00042     ColorEditor *coloreditor (new ColorEditor() );
00043     coloreditor->ComputeChildLayout(); // necessary so all element of the widget get their rightful size.
00044     ColorDialogProxy *coloreditorproxy = static_cast<ColorDialogProxy *> (InitData);
00045 
00046     if (coloreditorproxy)
00047     {
00048       coloreditor->SetRGB (coloreditorproxy->GetColor() );
00049       coloreditor->SetColorModel (coloreditorproxy->GetColorModel(), coloreditorproxy->GetColorChannel() );
00050       coloreditor->sigChange.connect (sigc::mem_fun (coloreditorproxy, &ColorDialogProxy::RecvDialogChange) );
00051     }
00052 
00053     HLayout *ButtonLayout (new HLayout (TEXT ("Dialog Buttons"), NUX_TRACKER_LOCATION) );
00054 
00055     ToggleButton *OkButton (new ToggleButton ("OK", NUX_TRACKER_LOCATION) );
00056     OkButton->SetMinimumWidth (60);
00057     OkButton->SetMinimumHeight (20);
00058 
00059     ToggleButton *CancelButton (new ToggleButton ("Cancel", NUX_TRACKER_LOCATION) );
00060     CancelButton->SetMinimumWidth (60);
00061     CancelButton->SetMinimumHeight (20);
00062 
00063     //FIXME - OkButton->sigClick.connect (sigc::mem_fun (static_cast<WindowThread *> (thread), &WindowThread::TerminateThread) );
00064     //FIXME - OkButton->sigClick.connect (sigc::bind (sigc::mem_fun (coloreditorproxy, &ColorDialogProxy::RecvDialogOk), coloreditor) );
00065     //FIXME - CancelButton->sigClick.connect (sigc::bind (sigc::mem_fun (coloreditorproxy, &ColorDialogProxy::RecvDialogCancel), coloreditor) );
00066     //FIXME - CancelButton->sigClick.connect (sigc::mem_fun (static_cast<WindowThread *> (thread), &WindowThread::TerminateThread) );
00067 
00068     ButtonLayout->SetHorizontalInternalMargin (6);
00069     ButtonLayout->SetVerticalExternalMargin (2);
00070     ButtonLayout->AddView (OkButton, 0);
00071     ButtonLayout->AddView (CancelButton, 0);
00072 
00073     MainLayout->AddView (coloreditor);
00074     MainLayout->AddLayout (ButtonLayout, 0);
00075     static_cast<WindowThread *> (thread)->SetLayout (MainLayout);
00076 
00077     MainLayout->SetBaseWidth (1);
00078     MainLayout->SetBaseHeight (1);
00079     MainLayout->ComputeLayout2();
00080     static_cast<WindowThread *> (thread)->SetWindowSize (MainLayout->GetBaseWidth(), MainLayout->GetBaseHeight() );
00081 
00082     // Call StopThreadMonitoring in case the dialog was close by clicking the window close button.
00083     //coloreditorproxy->StopThreadMonitoring();
00084   }
00085 
00086   ColorDialogProxy::ColorDialogProxy (bool ModalWindow)
00087   {
00088     m_bDialogChange     = false;
00089     m_bDialogRunning    = false;
00090     m_ModalWindow       = ModalWindow;
00091     m_RGBColor          = Color (1.0f, 1.0f, 1.0f, 1.0f);
00092     m_ColorModel        = color::RGB;
00093     m_ColorChannel      = color::RED;
00094   }
00095 
00096   ColorDialogProxy::~ColorDialogProxy()
00097   {
00098   }
00099 
00100   void ColorDialogProxy::Start()
00101   {
00102     m_PreviousRGBColor = m_RGBColor;
00103 
00104     int Width = 290;
00105     int Height = 230;
00106     m_Thread = CreateModalWindowThread (WINDOWSTYLE_TOOL, TEXT ("Color Editor"), Width, Height, GetWindowThread (),
00107                                         ThreadColorEditorDialog,
00108                                         this);
00109 
00110     if (m_Thread)
00111     {
00112       m_DialogThreadID = m_Thread->GetThreadId();
00113       m_Thread->Start (0);
00114     }
00115 
00116     m_bDialogRunning = true;
00117   }
00118 
00119   bool ColorDialogProxy::IsActive()
00120   {
00121     return (m_Thread && (m_Thread->GetThreadState() != THREADSTOP) && m_bDialogRunning);
00122   }
00123 
00124   void ColorDialogProxy::RecvDialogOk (ColorEditor *coloreditor)
00125   {
00126     m_RGBColor = coloreditor->GetRGBColor();
00127     m_PreviousRGBColor = m_RGBColor;
00128     m_bDialogChange = true;
00129     m_bDialogRunning = false;
00130   }
00131 
00132   void ColorDialogProxy::RecvDialogCancel (ColorEditor *coloreditor)
00133   {
00134     m_RGBColor = m_PreviousRGBColor;
00135     m_bDialogChange = true;
00136     m_bDialogRunning = false;
00137   }
00138 
00139   void ColorDialogProxy::RecvDialogChange (ColorEditor *coloreditor)
00140   {
00141     m_RGBColor = coloreditor->GetRGBColor();
00142     m_bDialogChange = true;
00143   }
00144 
00145   void ColorDialogProxy::StopThreadMonitoring()
00146   {
00147     m_RGBColor = m_PreviousRGBColor;
00148     m_bDialogChange = true;
00149     m_bDialogRunning = false;
00150     m_Thread = 0;
00151     m_DialogThreadID = 0;
00152   }
00153 
00154   void ColorDialogProxy::SetColor (Color color)
00155   {
00156     m_RGBColor = color;
00157   }
00158 
00159   Color ColorDialogProxy::GetColor()
00160   {
00161     return m_RGBColor;
00162   }
00163 
00164   void ColorDialogProxy::SetPreviousColor (Color color)
00165   {
00166     m_PreviousRGBColor = color;
00167   }
00168 
00169   Color ColorDialogProxy::GetPreviousColor()
00170   {
00171     return m_PreviousRGBColor;
00172   }
00173 
00174   void ColorDialogProxy::SetColorModel (color::Model color_model)
00175   {
00176     m_ColorModel = color_model;
00177   }
00178 
00179   color::Model ColorDialogProxy::GetColorModel()
00180   {
00181     return m_ColorModel;
00182   }
00183 
00184   void ColorDialogProxy::SetColorChannel (color::Channel color_channel)
00185   {
00186     m_ColorChannel = color_channel;
00187   }
00188 
00189   color::Channel ColorDialogProxy::GetColorChannel()
00190   {
00191     return m_ColorChannel;
00192   }
00193 
00194   ColorEditor::ColorEditor (NUX_FILE_LINE_DECL)
00195     : View (NUX_FILE_LINE_PARAM)
00196     , rgb_(1.0f, 1.0f, 0.0f)
00197     , hsv_(rgb_)
00198   {
00199     m_ColorModel = color::RGB;
00200     m_ColorChannel = color::RED;
00201     m_MarkerPosition = Point (0, 0);
00202     m_VertMarkerPosition = Point (0, 0);
00203 
00204     m_Validator.SetMinimum (0.0);
00205     m_Validator.SetMaximum (1.0);
00206     m_Validator.SetDecimals (2);
00207 
00208     m_PickerArea        = new InputArea (NUX_TRACKER_LOCATION);
00209     m_BaseChannelArea   = new InputArea (NUX_TRACKER_LOCATION);
00210     m_ColorSquare       = new InputArea (NUX_TRACKER_LOCATION);
00211     m_hlayout           = new HLayout (NUX_TRACKER_LOCATION);
00212 
00213     m_BaseChannelArea->mouse_down.connect (sigc::mem_fun (this, &ColorEditor::RecvMouseDown) );
00214     m_BaseChannelArea->mouse_up.connect (sigc::mem_fun (this, &ColorEditor::RecvMouseUp) );
00215     m_BaseChannelArea->mouse_drag.connect (sigc::mem_fun (this, &ColorEditor::RecvMouseDrag) );
00216 
00217     m_PickerArea->mouse_down.connect (sigc::mem_fun (this, &ColorEditor::RecvPickerMouseDown) );
00218     m_PickerArea->mouse_up.connect (sigc::mem_fun (this, &ColorEditor::RecvPickerMouseUp) );
00219     m_PickerArea->mouse_drag.connect (sigc::mem_fun (this, &ColorEditor::RecvPickerMouseDrag) );
00220 
00221     m_ColorSquare->SetMinMaxSize (62, 32);
00222     m_PickerArea->SetMinimumSize (200, 200);
00223     m_PickerArea->SetMaximumSize (200, 200);
00224     m_BaseChannelArea->SetMaximumHeight (200);
00225     m_BaseChannelArea->SetMinimumWidth (20);
00226     m_BaseChannelArea->SetMaximumWidth (20);
00227 
00228     m_hlayout->AddView (m_PickerArea, 1);
00229     m_hlayout->AddLayout (new SpaceLayout (5, 5, 20, 20), 0);
00230     m_hlayout->AddView (m_BaseChannelArea, 0, eAbove, eFull);
00231     SetCompositionLayout (m_hlayout);
00232 
00233     // RGB
00234     {
00235       redlayout = new HLayout (NUX_TRACKER_LOCATION);
00236       {
00237         //FIXME - change to radio button
00238         redcheck = new Button ("R:" );
00239         redcheck->SetMinimumWidth (30);
00240         redtext = new EditTextBox (TEXT (""), NUX_TRACKER_LOCATION);
00241         redtext->SetMinimumWidth (36);
00242         redlayout->AddView (redcheck, 0);
00243         redlayout->AddView (redtext, 0);
00244         //FIXME - redcheck->sigStateChanged.connect (sigc::bind ( sigc::bind ( sigc::mem_fun (this, &ColorEditor::RecvCheckColorModel), CC_RED), CM_RGB ) );
00245       }
00246       greenlayout = new HLayout (NUX_TRACKER_LOCATION);
00247       {
00248         //FIXME - Change to radio button
00249         greencheck = new Button ("G:" );
00250         greencheck->SetMinimumWidth (30);
00251         greentext = new EditTextBox (TEXT (""), NUX_TRACKER_LOCATION);
00252         greentext->SetMinimumWidth (36);
00253         greenlayout->AddView (greencheck, 0);
00254         greenlayout->AddView (greentext, 0);
00255         //FIXME - greencheck->sigStateChanged.connect (sigc::bind ( sigc::bind ( sigc::mem_fun (this, &ColorEditor::RecvCheckColorModel), CC_GREEN), CM_RGB ) );
00256 
00257       }
00258       bluelayout = new HLayout (NUX_TRACKER_LOCATION);
00259       {
00260         //FIXME - change to radio button
00261         bluecheck = new Button ("B:" );
00262         bluecheck->SetMinimumWidth (30);
00263         bluetext = new EditTextBox (TEXT (""), NUX_TRACKER_LOCATION);
00264         bluetext->SetMinimumWidth (36);
00265         bluelayout->AddView (bluecheck, 0);
00266         bluelayout->AddView (bluetext, 0);
00267         //FIXME - change to radio button bluecheck->sigStateChanged.connect (sigc::bind ( sigc::bind ( sigc::mem_fun (this, &ColorEditor::RecvCheckColorModel), CC_BLUE), CM_RGB ) );
00268       }
00269     }
00270 
00271     // HSV
00272     {
00273       huelayout = new HLayout (NUX_TRACKER_LOCATION);
00274       {
00275         //FIXME - change to radio button
00276         huecheck = new Button ("H:" );
00277         huecheck->SetMinimumWidth (30);
00278         huetext = new EditTextBox (TEXT (""), NUX_TRACKER_LOCATION);
00279         huetext->SetMinimumWidth (36);
00280         huelayout->AddView (huecheck, 0);
00281         huelayout->AddView (huetext, 0);
00282         //FIXME - huecheck->sigStateChanged.connect (sigc::bind ( sigc::bind ( sigc::mem_fun (this, &ColorEditor::RecvCheckColorModel), CC_HUE), CM_HSV ) );
00283       }
00284       saturationlayout = new HLayout (NUX_TRACKER_LOCATION);
00285       {
00286         //FIXME - change to radio button
00287         saturationcheck = new Button ("S:" );
00288         saturationcheck->SetMinimumWidth (30);
00289         saturationtext = new EditTextBox (TEXT (""), NUX_TRACKER_LOCATION);
00290         saturationtext->SetMinimumWidth (36);
00291         saturationlayout->AddView (saturationcheck, 0);
00292         saturationlayout->AddView (saturationtext, 0);
00293         //FIXME - saturationcheck->sigStateChanged.connect (sigc::bind ( sigc::bind ( sigc::mem_fun (this, &ColorEditor::RecvCheckColorModel), CC_SATURATION), CM_HSV ) );
00294       }
00295       valuelayout = new HLayout (NUX_TRACKER_LOCATION);
00296       {
00297         //FIXME - change to radio button
00298         valuecheck = new Button ("V:" );
00299         valuecheck->SetMinimumWidth (30);
00300         valuetext = new EditTextBox (TEXT (""), NUX_TRACKER_LOCATION);
00301         valuetext->SetMinimumWidth (36);
00302         valuelayout->AddView (valuecheck, 0);
00303         valuelayout->AddView (valuetext, 0);
00304         //FIXME - valuecheck->sigStateChanged.connect (sigc::bind ( sigc::bind ( sigc::mem_fun (this, &ColorEditor::RecvCheckColorModel), CC_VALUE), CM_HSV ) );
00305       }
00306     }
00307 
00308     ctrllayout = new VLayout (NUX_TRACKER_LOCATION);
00309     ctrllayout->AddView (m_ColorSquare);
00310     ctrllayout->AddView (new SpaceLayout (20, 20, 10, 10), 1);
00311     ctrllayout->AddLayout (redlayout, 0);
00312     ctrllayout->AddLayout (greenlayout, 0);
00313     ctrllayout->AddLayout (bluelayout, 0);
00314     ctrllayout->AddLayout (new SpaceLayout (10, 10, 10, 10) );
00315     ctrllayout->AddLayout (huelayout, 0);
00316     ctrllayout->AddLayout (saturationlayout, 0);
00317     ctrllayout->AddLayout (valuelayout, 0);
00318     ctrllayout->SetHorizontalExternalMargin (2);
00319     ctrllayout->SetVerticalInternalMargin (2);
00320 
00321 //     //ctrllayout->AddView(new SpaceLayout(20,20,20,40), 1);
00322 //     OkButton = new ToggleButton (TEXT ("OK"), NUX_TRACKER_LOCATION);
00323 //     OkButton->SetMinimumWidth (60);
00324 //     OkButton->SetMinimumHeight (20);
00325 //
00326 //     CancelButton = new ToggleButton (TEXT ("Cancel"), NUX_TRACKER_LOCATION);
00327 //     CancelButton->SetMinimumWidth (60);
00328 //     CancelButton->SetMinimumHeight (20);
00329 //
00330 // //    ctrllayout->AddView(OkButton, 1);
00331 // //    ctrllayout->AddView(CancelButton, 1);
00332 
00333     m_hlayout->AddLayout (ctrllayout, 0);
00334 
00335     //radiogroup = new RadioButtonGroup (NUX_TRACKER_LOCATION);
00336     //radiogroup->ConnectButton (redcheck);
00337     //radiogroup->ConnectButton (greencheck);
00338     //radiogroup->ConnectButton (bluecheck);
00339     //radiogroup->ConnectButton (huecheck);
00340     //radiogroup->ConnectButton (saturationcheck);
00341     //radiogroup->ConnectButton (valuecheck);
00342 
00343     m_RedShader = new GLSh_ColorPicker (color::RED);
00344     m_GreenShader = new GLSh_ColorPicker (color::GREEN);
00345     m_BlueShader = new GLSh_ColorPicker (color::BLUE);
00346     m_HueShader = new GLSh_ColorPicker (color::HUE);
00347     m_SaturationShader = new GLSh_ColorPicker (color::SATURATION);
00348     m_ValueShader = new GLSh_ColorPicker (color::VALUE);
00349 
00350     redtext->SetText (m_Validator.ToString (255 * rgb_.red) );
00351     greentext->SetText (m_Validator.ToString (255 * rgb_.green) );
00352     bluetext->SetText (m_Validator.ToString (255 * rgb_.blue) );
00353     huetext->SetText (m_Validator.ToString (360 * hsv_.hue) );
00354     saturationtext->SetText (m_Validator.ToString (100 * hsv_.saturation) );
00355     valuetext->SetText (m_Validator.ToString (100 * hsv_.value) );
00356   }
00357 
00358   ColorEditor::~ColorEditor()
00359   {
00360     delete m_RedShader;
00361     delete m_GreenShader;
00362     delete m_BlueShader;
00363     delete m_HueShader;
00364     delete m_SaturationShader;
00365     delete m_ValueShader;
00366   }
00367 
00368 
00369   long ColorEditor::ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
00370   {
00371     long ret;
00372 
00373     ret = m_PickerArea->OnEvent (ievent, TraverseInfo, ProcessEventInfo);
00374     ret = m_BaseChannelArea->OnEvent (ievent, ret, ProcessEventInfo);
00375 
00376     // RGB
00377     {
00378       ret = redcheck->OnEvent (ievent, ret, ProcessEventInfo);
00379       ret = redtext->OnEvent (ievent, ret, ProcessEventInfo);
00380 
00381       ret = greencheck->OnEvent (ievent, ret, ProcessEventInfo);
00382       ret = greentext->OnEvent (ievent, ret, ProcessEventInfo);
00383 
00384       ret = bluecheck->OnEvent (ievent, ret, ProcessEventInfo);
00385       ret = bluetext->OnEvent (ievent, ret, ProcessEventInfo);
00386     }
00387 
00388     // HSV
00389     {
00390       ret = huecheck->OnEvent (ievent, ret, ProcessEventInfo);
00391       ret = huetext->OnEvent (ievent, ret, ProcessEventInfo);
00392 
00393       ret = saturationcheck->OnEvent (ievent, ret, ProcessEventInfo);
00394       ret = saturationtext->OnEvent (ievent, ret, ProcessEventInfo);
00395 
00396       ret = valuecheck->OnEvent (ievent, ret, ProcessEventInfo);
00397       ret = valuetext->OnEvent (ievent, ret, ProcessEventInfo);
00398     }
00399 
00400 //     OkButton->OnEvent (ievent, ret, ProcessEventInfo);
00401 //     CancelButton->OnEvent (ievent, ret, ProcessEventInfo);
00402 
00403     ret = PostProcessEvent2 (ievent, ret, ProcessEventInfo);
00404 
00405     return ret;
00406   }
00407 
00408   void ColorEditor::Draw (GraphicsEngine &GfxContext, bool force_draw)
00409   {
00410     Geometry base = GetGeometry();
00411 
00412     GetPainter().PaintBackground (GfxContext, base);
00413     //GetPainter().Paint2DQuadWireframe(GfxContext, base, Color(COLOR_BACKGROUND_SECONDARY));
00414 
00415     base.OffsetPosition (1, 1);
00416     base.OffsetSize (-2, -2);
00417 
00418     GfxContext.PushClippingRectangle (base);
00419 
00420     if (m_ColorModel == color::RGB)
00421     {
00422       DrawRGB (GfxContext, force_draw);
00423     }
00424     else
00425     {
00426       DrawHSV (GfxContext, force_draw);
00427     }
00428 
00429     redcheck->QueueDraw();
00430     redtext->QueueDraw();
00431     greencheck->QueueDraw();
00432     greentext->QueueDraw();
00433     bluecheck->QueueDraw();
00434     bluetext->QueueDraw();
00435 
00436     huecheck->QueueDraw();
00437     huetext->QueueDraw();
00438     saturationcheck->QueueDraw();
00439     saturationtext->QueueDraw();
00440     valuecheck->QueueDraw();
00441     valuetext->QueueDraw();
00442 
00443 //     OkButton->QueueDraw();
00444 //     CancelButton->QueueDraw();
00445 
00446     GfxContext.PopClippingRectangle();
00447   }
00448 
00449 // Draw Marker on Base Chanel Area
00450   void ColorEditor::DrawBaseChannelMarker (GraphicsEngine &GfxContext)
00451   {
00452     int marker_position_x;
00453     int marker_position_y;
00454 
00455     GfxContext.PushClippingRectangle (m_BaseChannelArea->GetGeometry() );
00456 
00457     marker_position_x = m_BaseChannelArea->GetBaseX();
00458     marker_position_y = m_BaseChannelArea->GetBaseY() + m_VertMarkerPosition.y;
00459     GetPainter().Draw2DTriangleColor (GfxContext, marker_position_x, marker_position_y - 5,
00460                                   marker_position_x + 5, marker_position_y,
00461                                   marker_position_x, marker_position_y + 5, Color (0.0f, 0.0f, 0.0f, 1.0f) );
00462 
00463     GetPainter().Draw2DTriangleColor (GfxContext, marker_position_x, marker_position_y - 4,
00464                                   marker_position_x + 4, marker_position_y,
00465                                   marker_position_x, marker_position_y + 4, Color (0.7f, 0.7f, 0.7f, 1.0f) );
00466 
00467     marker_position_x = m_BaseChannelArea->GetBaseX() + m_BaseChannelArea->GetBaseWidth();
00468     marker_position_y = m_BaseChannelArea->GetBaseY() + m_VertMarkerPosition.y;
00469     GetPainter().Draw2DTriangleColor (GfxContext, marker_position_x, marker_position_y - 5,
00470                                   marker_position_x - 5, marker_position_y,
00471                                   marker_position_x, marker_position_y + 5, Color (0.0f, 0.0f, 0.0f, 1.0f) );
00472 
00473     GetPainter().Draw2DTriangleColor (GfxContext, marker_position_x, marker_position_y - 4,
00474                                   marker_position_x - 4, marker_position_y,
00475                                   marker_position_x, marker_position_y + 4, Color (0.7f, 0.7f, 0.7f, 1.0f) );
00476     GfxContext.PopClippingRectangle();
00477   }
00478 
00479   void ColorEditor::DrawRGB (GraphicsEngine &GfxContext, bool force_draw)
00480   {
00481     if (m_ColorModel == color::RGB)
00482     {
00483       GetPainter().Paint2DQuadColor (GfxContext, m_ColorSquare->GetGeometry(), Color(rgb_) );
00484       Color BaseChannelTop;
00485       Color BaseChannelBottom;
00486 
00487       if (m_ColorChannel == color::RED)
00488       {
00489         m_RedShader->SetColor (rgb_.red, rgb_.green, rgb_.blue, 1.0f);
00490         m_RedShader->SetScreenPositionOffset (GfxContext.GetViewportX (), GfxContext.GetViewportY ());
00491         BaseChannelTop = Color (1.0f, rgb_.green, rgb_.blue, 1.0f);
00492         BaseChannelBottom = Color (0.0f, rgb_.green, rgb_.blue, 1.0f);
00493         m_RedShader->Render (
00494           m_PickerArea->GetBaseX(),
00495           m_PickerArea->GetBaseY(),
00496           0,
00497           m_PickerArea->GetBaseWidth(),
00498           m_PickerArea->GetBaseHeight(),
00499           GfxContext.GetViewportWidth (), GfxContext.GetViewportHeight ()
00500         );
00501       }
00502       else if (m_ColorChannel == color::GREEN)
00503       {
00504         m_GreenShader->SetColor (rgb_.red, rgb_.green, rgb_.blue, 1.0f);
00505         m_GreenShader->SetScreenPositionOffset (GfxContext.GetViewportX (), GfxContext.GetViewportY ());
00506         BaseChannelTop = Color (rgb_.red, 1.0f, rgb_.blue, 1.0f);
00507         BaseChannelBottom = Color (rgb_.red, 0.0f, rgb_.blue, 1.0f);
00508         m_GreenShader->Render (
00509           m_PickerArea->GetBaseX(),
00510           m_PickerArea->GetBaseY(),
00511           0,
00512           m_PickerArea->GetBaseWidth(),
00513           m_PickerArea->GetBaseHeight(),
00514           GfxContext.GetViewportWidth (), GfxContext.GetViewportHeight ()
00515         );
00516       }
00517       else if (m_ColorChannel == color::BLUE)
00518       {
00519         m_BlueShader->SetColor (rgb_.red, rgb_.green, rgb_.blue, 1.0f);
00520         m_BlueShader->SetScreenPositionOffset (GfxContext.GetViewportX (), GfxContext.GetViewportY ());
00521         BaseChannelTop = Color (rgb_.red, rgb_.green, 1.0f, 1.0f);
00522         BaseChannelBottom = Color (rgb_.red, rgb_.green, 0.0f, 1.0f);
00523         m_BlueShader->Render (
00524           m_PickerArea->GetBaseX(),
00525           m_PickerArea->GetBaseY(),
00526           0,
00527           m_PickerArea->GetBaseWidth(),
00528           m_PickerArea->GetBaseHeight(),
00529           GfxContext.GetViewportWidth (), GfxContext.GetViewportHeight ()
00530         );
00531       }
00532 
00533       Geometry pickermarker = Geometry (GetBaseX() + m_MarkerPosition.x - 2, GetBaseY() + m_MarkerPosition.y - 2, 5, 5);
00534       Geometry basepickermarker = Geometry (m_BaseChannelArea->GetBaseX(), m_BaseChannelArea->GetBaseY() + m_VertMarkerPosition.y, 5, 5);
00535 
00536       Color color (rgb_.red, rgb_.green, rgb_.blue);
00537       GetPainter().Paint2DQuadWireframe (GfxContext, pickermarker, OneMinusLuminance(rgb_) );
00538 
00539       GetPainter().Paint2DQuadColor (GfxContext, m_BaseChannelArea->GetGeometry(), BaseChannelTop, BaseChannelBottom, BaseChannelBottom, BaseChannelTop);
00540       // Draw Marker on Base Chanel Area
00541       DrawBaseChannelMarker (GfxContext);
00542     }
00543   }
00544 
00545   void ColorEditor::DrawHSV (GraphicsEngine &GfxContext, bool force_draw)
00546   {
00547     if (m_ColorModel == color::HSV)
00548     {
00549       color::RedGreenBlue rgb(hsv_);
00550       GetPainter().Paint2DQuadColor(GfxContext, m_ColorSquare->GetGeometry(), Color(rgb) );
00551 
00552       Color BaseChannelTop;
00553       Color BaseChannelBottom;
00554 
00555       if (m_ColorChannel == color::HUE)
00556       {
00557         m_HueShader->SetColor (hsv_.hue, hsv_.saturation, hsv_.value, 1.0f);
00558         m_HueShader->SetScreenPositionOffset (GfxContext.GetViewportX (), GfxContext.GetViewportY ());
00559         m_HueShader->Render (
00560           m_PickerArea->GetBaseX(),
00561           m_PickerArea->GetBaseY(),
00562           0,
00563           m_PickerArea->GetBaseWidth(),
00564           m_PickerArea->GetBaseHeight(),
00565           GfxContext.GetViewportWidth (), GfxContext.GetViewportHeight ()
00566         );
00567 
00568         Geometry P = m_BaseChannelArea->GetGeometry();
00569 
00570         float s = 1.0f - 1.0f;
00571         float v = 1.0f;
00572         float fw = P.GetHeight() / 6;
00573 
00574         Geometry p = Geometry (P.x, P.y, P.GetWidth(), fw);
00575         GetPainter().Paint2DQuadVGradient (GfxContext, p, Color (1.0f * v, s * v, s * v), Color (1.0f * v, s * v, 1.0f * v) );
00576         p.SetY (P.y + fw);
00577         GetPainter().Paint2DQuadVGradient (GfxContext, p, Color (1.0f * v, s * v, 1.0f * v), Color (s * v, s * v, 1.0f * v) );
00578         p.SetY (P.y + 2 * fw);
00579         GetPainter().Paint2DQuadVGradient (GfxContext, p, Color (s * v, s * v, 1.0f * v), Color (s * v, 1.0f * v, 1.0f * v) );
00580         p.SetY (P.y + 3 * fw);
00581         GetPainter().Paint2DQuadVGradient (GfxContext, p, Color (s * v, 1.0f * v, 1.0f * v), Color (s * v, 1.0f * v, s * v) );
00582         p.SetY (P.y + 4 * fw);
00583         GetPainter().Paint2DQuadVGradient (GfxContext, p, Color (s * v, 1.0f * v, s * v), Color (1.0f * v, 1.0f * v, s * v) );
00584         p.SetY (P.y + 5 * fw);
00585         p.SetHeight (P.GetHeight() - 5 * fw); // correct rounding errors
00586         GetPainter().Paint2DQuadVGradient (GfxContext, p, Color (1.0f * v, 1.0f * v, s * v), Color (1.0f * v, s * v, s * v) );
00587 
00588         Geometry pickermarker = Geometry (GetBaseX() + m_MarkerPosition.x - 2, GetBaseY() + m_MarkerPosition.y - 2, 5, 5);
00589         GetPainter().Paint2DQuadWireframe(GfxContext, pickermarker, OneMinusLuminance(rgb_));
00590       }
00591       else if (m_ColorChannel == color::SATURATION)
00592       {
00593         float value = hsv_.value;
00594         if (value < 0.3f) value = 0.3f;
00595 
00596         m_SaturationShader->SetColor(hsv_.hue, hsv_.saturation, hsv_.value, 1.0f);
00597         m_SaturationShader->SetScreenPositionOffset (GfxContext.GetViewportX (), GfxContext.GetViewportY ());
00598         BaseChannelTop = Color(color::RedGreenBlue(color::HueSaturationValue(hsv_.hue, 1.0f, value)));
00599         BaseChannelBottom = Color(value, value, value, 1.0f);
00600         m_SaturationShader->Render (
00601           m_PickerArea->GetBaseX(),
00602           m_PickerArea->GetBaseY(),
00603           0,
00604           m_PickerArea->GetBaseWidth(),
00605           m_PickerArea->GetBaseHeight(),
00606           GfxContext.GetViewportWidth (), GfxContext.GetViewportHeight ()
00607         );
00608 
00609         //Geometry pickermarker = Geometry(GetX() + x - 2, GetY() + y -2, 5, 5);
00610         Geometry pickermarker = Geometry (GetBaseX() + m_MarkerPosition.x - 2, GetBaseY() + m_MarkerPosition.y - 2, 5, 5);
00611         GetPainter().Paint2DQuadWireframe (GfxContext, pickermarker, OneMinusLuminance(rgb_) );
00612         GetPainter().Paint2DQuadColor (GfxContext, m_BaseChannelArea->GetGeometry(), BaseChannelTop, BaseChannelBottom, BaseChannelBottom, BaseChannelTop);
00613       }
00614       else if (m_ColorChannel == color::VALUE)
00615       {
00616         m_ValueShader->SetColor (hsv_.hue, hsv_.saturation, hsv_.value, 1.0f);
00617         m_ValueShader->SetScreenPositionOffset (GfxContext.GetViewportX (), GfxContext.GetViewportY ());
00618         BaseChannelTop = Color(color::RedGreenBlue(color::HueSaturationValue(hsv_.hue, hsv_.saturation, 1.0f)));
00619         BaseChannelBottom = Color(color::RedGreenBlue(color::HueSaturationValue(hsv_.hue, hsv_.saturation, 0.0f)));
00620         m_ValueShader->Render (
00621           m_PickerArea->GetBaseX(),
00622           m_PickerArea->GetBaseY(),
00623           0,
00624           m_PickerArea->GetBaseWidth(),
00625           m_PickerArea->GetBaseHeight(),
00626           GfxContext.GetViewportWidth (), GfxContext.GetViewportHeight ()
00627         );
00628 
00629         //Geometry pickermarker = Geometry(GetX() + x - 2, GetY() + y -2, 5, 5);
00630         Geometry pickermarker = Geometry (GetBaseX() + m_MarkerPosition.x - 2, GetBaseY() + m_MarkerPosition.y - 2, 5, 5);
00631         GetPainter().Paint2DQuadWireframe (GfxContext, pickermarker, OneMinusLuminance(rgb_) );
00632         GetPainter().Paint2DQuadColor (GfxContext, m_BaseChannelArea->GetGeometry(), BaseChannelTop, BaseChannelBottom, BaseChannelBottom, BaseChannelTop);
00633       }
00634 
00635       // Draw Marker on Base Chanel Area
00636       DrawBaseChannelMarker (GfxContext);
00637     }
00638   }
00639 
00640   void ColorEditor::DrawContent (GraphicsEngine &GfxContext, bool force_draw)
00641   {
00642     redcheck->ProcessDraw (GfxContext, force_draw);
00643     redtext->ProcessDraw (GfxContext, force_draw);
00644     greencheck->ProcessDraw (GfxContext, force_draw);
00645     greentext->ProcessDraw (GfxContext, force_draw);
00646     bluecheck->ProcessDraw (GfxContext, force_draw);
00647     bluetext->ProcessDraw (GfxContext, force_draw);
00648 
00649     huecheck->ProcessDraw (GfxContext, force_draw);
00650     huetext->ProcessDraw (GfxContext, force_draw);
00651     saturationcheck->ProcessDraw (GfxContext, force_draw);
00652     saturationtext->ProcessDraw (GfxContext, force_draw);
00653     valuecheck->ProcessDraw (GfxContext, force_draw);
00654     valuetext->ProcessDraw (GfxContext, force_draw);
00655   }
00656 
00657   void ColorEditor::PostDraw (GraphicsEngine &GfxContext, bool force_draw)
00658   {
00659 
00660   }
00661 
00662   void ColorEditor::RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags)
00663   {
00664     float BaseValue;
00665 
00666     if (m_ColorModel == color::RGB)
00667     {
00668       if (y < 0)
00669         BaseValue = 1.0f;
00670       else if (y > m_BaseChannelArea->GetBaseHeight() )
00671         BaseValue = 0.0f;
00672       else
00673         BaseValue = 1.0f - (float) y / (float) m_BaseChannelArea->GetBaseHeight();
00674 
00675       if (m_ColorChannel == color::RED)
00676         rgb_.red = BaseValue;
00677       else if (m_ColorChannel == color::GREEN)
00678         rgb_.green = BaseValue;
00679       else if (m_ColorChannel == color::BLUE)
00680         rgb_.blue = BaseValue;
00681 
00682       hsv_ = color::HueSaturationValue(rgb_);
00683     }
00684 
00685     if (m_ColorModel == color::HSV)
00686     {
00687       if (y < 0)
00688         BaseValue = 1.0f;
00689       else if (y > m_BaseChannelArea->GetBaseHeight() )
00690         BaseValue = 0.0f;
00691       else
00692         BaseValue = 1.0f - (float) y / (float) m_BaseChannelArea->GetBaseHeight();
00693 
00694       if (m_ColorChannel == color::HUE)
00695       {
00696         hsv_.hue = BaseValue;
00697 
00698         if (hsv_.hue >= 1.0f) hsv_.hue = 0.0f;
00699       }
00700       else if (m_ColorChannel == color::SATURATION)
00701         hsv_.saturation = BaseValue;
00702       else if (m_ColorChannel == color::VALUE)
00703         hsv_.value = BaseValue;
00704 
00705       rgb_ = color::RedGreenBlue(hsv_);
00706     }
00707 
00708     redtext->SetText (m_Validator.ToString (255 * rgb_.red) );
00709     greentext->SetText (m_Validator.ToString (255 * rgb_.green) );
00710     bluetext->SetText (m_Validator.ToString (255 * rgb_.blue) );
00711     huetext->SetText (m_Validator.ToString (360 * hsv_.hue) );
00712     saturationtext->SetText (m_Validator.ToString (100 * hsv_.saturation) );
00713     valuetext->SetText (m_Validator.ToString (100 * hsv_.value) );
00714     m_VertMarkerPosition = Point (Clamp<int> (x, 0, m_BaseChannelArea->GetBaseWidth() - 1), Clamp<int> (y, 0, m_BaseChannelArea->GetBaseHeight() - 1) );
00715 
00716     sigChange.emit (this);
00717     QueueDraw();
00718   }
00719 
00720   void ColorEditor::RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags)
00721   {
00722     QueueDraw();
00723   }
00724 
00725   void ColorEditor::RecvMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
00726   {
00727     RecvMouseDown (x, y, button_flags, key_flags);
00728   }
00729 
00730   void ColorEditor::RecvPickerMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags)
00731   {
00732     if (m_ColorModel == color::RGB)
00733     {
00734       if (m_ColorChannel == color::RED)
00735       {
00736         if (y < 0)
00737           rgb_.green = 1.0f;
00738         else if (y > m_PickerArea->GetBaseHeight() )
00739           rgb_.green = 0.0f;
00740         else
00741           rgb_.green = 1.0f - (float) y / (float) m_PickerArea->GetBaseHeight();
00742 
00743         if (x < 0)
00744           rgb_.blue = 0.0f;
00745         else if (x > m_PickerArea->GetBaseWidth() )
00746           rgb_.blue = 1.0f;
00747         else
00748           rgb_.blue = (float) x / (float) m_PickerArea->GetBaseWidth();
00749 
00750       }
00751 
00752       if (m_ColorChannel == color::GREEN)
00753       {
00754         if (y < 0)
00755           rgb_.red = 1.0f;
00756         else if (y > m_PickerArea->GetBaseHeight() )
00757           rgb_.red = 0.0f;
00758         else
00759           rgb_.red = 1.0f - (float) y / (float) m_PickerArea->GetBaseHeight();
00760 
00761         if (x < 0)
00762           rgb_.blue = 0.0f;
00763         else if (x > m_PickerArea->GetBaseWidth() )
00764           rgb_.blue = 1.0f;
00765         else
00766           rgb_.blue = (float) x / (float) m_PickerArea->GetBaseWidth();
00767 
00768       }
00769 
00770       if (m_ColorChannel == color::BLUE)
00771       {
00772         if (x < 0)
00773           rgb_.red = 0.0f;
00774         else if (x > m_PickerArea->GetBaseWidth() )
00775           rgb_.red = 1.0f;
00776         else
00777           rgb_.red = (float) x / (float) m_PickerArea->GetBaseWidth();
00778 
00779         if (y < 0)
00780           rgb_.green = 1.0f;
00781         else if (y > m_PickerArea->GetBaseHeight() )
00782           rgb_.green = 0.0f;
00783         else
00784           rgb_.green = 1.0f - (float) y / (float) m_PickerArea->GetBaseHeight();
00785       }
00786 
00787       hsv_ = color::HueSaturationValue(rgb_);
00788       m_MarkerPosition = Point (Clamp<int> (x, 0, m_PickerArea->GetBaseWidth() - 1), Clamp<int> (y, 0, m_PickerArea->GetBaseHeight() - 1) );
00789     }
00790 
00791     if (m_ColorModel == color::HSV)
00792     {
00793       if (m_ColorChannel == color::HUE)
00794       {
00795         if (y < 0)
00796           hsv_.value = 1.0f;
00797         else if (y > m_PickerArea->GetBaseHeight() )
00798           hsv_.value = 0.0f;
00799         else
00800           hsv_.value = 1.0f - (float) y / (float) m_PickerArea->GetBaseHeight();
00801 
00802         if (x < 0)
00803           hsv_.saturation = 0.0f;
00804         else if (x > m_PickerArea->GetBaseWidth() )
00805           hsv_.saturation = 1.0f;
00806         else
00807           hsv_.saturation = (float) x / (float) m_PickerArea->GetBaseWidth();
00808 
00809       }
00810 
00811       if (m_ColorChannel == color::SATURATION)
00812       {
00813         if (y < 0)
00814           hsv_.value = 1.0f;
00815         else if (y > m_PickerArea->GetBaseHeight() )
00816           hsv_.value = 0.0f;
00817         else
00818           hsv_.value = 1.0f - (float) y / (float) m_PickerArea->GetBaseHeight();
00819 
00820         if (x < 0)
00821           hsv_.hue = 0.0f;
00822         else if (x >= m_PickerArea->GetBaseWidth() )
00823           hsv_.hue = 0.0f;
00824         else
00825           hsv_.hue = (float) x / (float) m_PickerArea->GetBaseWidth();
00826 
00827       }
00828 
00829       if (m_ColorChannel == color::VALUE)
00830       {
00831         if (x < 0)
00832           hsv_.hue = 0.0f;
00833         else if (x >= m_PickerArea->GetBaseWidth() )
00834           hsv_.hue = 0.0f;
00835         else
00836           hsv_.hue = (float) x / (float) m_PickerArea->GetBaseWidth();
00837 
00838         if (y < 0)
00839           hsv_.saturation = 1.0f;
00840         else if (y > m_PickerArea->GetBaseHeight() )
00841           hsv_.saturation = 0.0f;
00842         else
00843           hsv_.saturation = 1.0f - (float) y / (float) m_PickerArea->GetBaseHeight();
00844       }
00845 
00846       rgb_ = color::RedGreenBlue(hsv_);
00847       m_MarkerPosition = Point (Clamp<int> (x, 0, m_PickerArea->GetBaseWidth() - 1), Clamp<int> (y, 0, m_PickerArea->GetBaseHeight() - 1) );
00848     }
00849 
00850 
00851     redtext->SetText (m_Validator.ToString (255 * rgb_.red) );
00852     greentext->SetText (m_Validator.ToString (255 * rgb_.green) );
00853     bluetext->SetText (m_Validator.ToString (255 * rgb_.blue) );
00854     huetext->SetText (m_Validator.ToString (360 * hsv_.hue) );
00855     saturationtext->SetText (m_Validator.ToString (100 * hsv_.saturation) );
00856     valuetext->SetText (m_Validator.ToString (100 * hsv_.value) );
00857 
00858     sigChange.emit (this);
00859     QueueDraw();
00860   }
00861 
00862   void ColorEditor::RecvPickerMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags)
00863   {
00864     QueueDraw();
00865   }
00866 
00867   void ColorEditor::RecvPickerMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
00868   {
00869     RecvPickerMouseDown (x, y, button_flags, key_flags);
00870   }
00871 
00872 void ColorEditor::RecvCheckColorModel (bool b, color::Model ColorModel, color::Channel ColorChannel)
00873   {
00874     if (b)
00875     {
00876       if ( (ColorModel == color::HSV) && (m_ColorModel == color::RGB) )
00877       {
00878         hsv_ = color::HueSaturationValue(rgb_);
00879       }
00880 
00881       if ( (ColorModel == color::RGB) && (m_ColorModel == color::HSV) )
00882       {
00883         rgb_ = color::RedGreenBlue(hsv_);
00884       }
00885 
00886       m_ColorModel = ColorModel;
00887       m_ColorChannel = ColorChannel;
00888     }
00889 
00890     if (b && (ColorModel == color::RGB) )
00891     {
00892       int x = 0;
00893       int y = 0;
00894       int z = 1;
00895 
00896       if (m_ColorChannel == color::RED)
00897       {
00898         z = (1.0f - rgb_.red) * m_PickerArea->GetBaseHeight();
00899         y = (1.0f - rgb_.green) * m_PickerArea->GetBaseHeight();
00900         x = rgb_.blue * m_PickerArea->GetBaseWidth();
00901       }
00902 
00903       if (m_ColorChannel == color::GREEN)
00904       {
00905         z = (1.0f - rgb_.green) * m_PickerArea->GetBaseHeight();
00906         y = (1.0f - rgb_.red) * m_PickerArea->GetBaseHeight();
00907         x = rgb_.blue * m_PickerArea->GetBaseWidth();
00908       }
00909 
00910       if (m_ColorChannel == color::BLUE)
00911       {
00912         z = (1.0f - rgb_.blue) * m_PickerArea->GetBaseHeight();
00913         y = (1.0f - rgb_.green) * m_PickerArea->GetBaseHeight();
00914         x = rgb_.red * m_PickerArea->GetBaseWidth();
00915       }
00916 
00917       m_VertMarkerPosition = Point (Clamp<int> (0, 0, m_BaseChannelArea->GetBaseWidth() - 1), Clamp<int> (z, 0, m_BaseChannelArea->GetBaseHeight() - 1) );
00918       m_MarkerPosition = Point (Clamp<int> (x, 0, m_PickerArea->GetBaseWidth() - 1), Clamp<int> (y, 0, m_PickerArea->GetBaseHeight() - 1) );
00919 
00920       redtext->SetText (m_Validator.ToString (255 * rgb_.red) );
00921       greentext->SetText (m_Validator.ToString (255 * rgb_.green) );
00922       bluetext->SetText (m_Validator.ToString (255 * rgb_.blue) );
00923     }
00924 
00925     if (b && (ColorModel == color::HSV) )
00926     {
00927       int x = 0;
00928       int y = 0;
00929       int z = 1;
00930 
00931       if (m_ColorChannel == color::HUE)
00932       {
00933         z = (1.0f - hsv_.hue) * m_PickerArea->GetBaseHeight();
00934         y = (1.0f - hsv_.value) * m_PickerArea->GetBaseHeight();
00935         x = hsv_.saturation * m_PickerArea->GetBaseWidth();
00936       }
00937 
00938       if (m_ColorChannel == color::SATURATION)
00939       {
00940         z = (1.0f - hsv_.saturation) * m_PickerArea->GetBaseHeight();
00941         y = (1.0f - hsv_.value) * m_PickerArea->GetBaseHeight();
00942         x = hsv_.hue * m_PickerArea->GetBaseWidth();
00943       }
00944 
00945       if (m_ColorChannel == color::VALUE)
00946       {
00947         z = (1.0f - hsv_.value) * m_PickerArea->GetBaseHeight();
00948         y = (1.0f - hsv_.saturation) * m_PickerArea->GetBaseHeight();
00949         x = hsv_.hue * m_PickerArea->GetBaseWidth();
00950       }
00951 
00952       m_VertMarkerPosition = Point (Clamp<int> (0, 0, m_BaseChannelArea->GetBaseWidth() - 1), Clamp<int> (z, 0, m_BaseChannelArea->GetBaseHeight() - 1) );
00953       m_MarkerPosition = Point (Clamp<int> (x, 0, m_PickerArea->GetBaseWidth() - 1), Clamp<int> (y, 0, m_PickerArea->GetBaseHeight() - 1) );
00954 
00955       huetext->SetText (m_Validator.ToString (360 * hsv_.hue) );
00956       saturationtext->SetText (m_Validator.ToString (100 * hsv_.saturation) );
00957       valuetext->SetText (m_Validator.ToString (100 * hsv_.value) );
00958     }
00959 
00960     QueueDraw();
00961   }
00962 
00963   Color ColorEditor::GetRGBColor() const
00964   {
00965     return Color(rgb_);
00966   }
00967 
00968   void ColorEditor::SetRGB(Color const& rgb)
00969   {
00970     SetRGB(rgb.red, rgb.green, rgb.blue );
00971   }
00972 
00973   void ColorEditor::SetRGB (double r, double g, double b)
00974   {
00975     rgb_ = color::RedGreenBlue(Clamp<double>(r, 0.0, 1.0),
00976                                Clamp<double>(g, 0.0, 1.0),
00977                                Clamp<double> (b, 0.0, 1.0));
00978     hsv_ = color::HueSaturationValue(rgb_);
00979     RecvCheckColorModel(true, m_ColorModel, m_ColorChannel);
00980     sigChange.emit (this);
00981   }
00982 
00983   void ColorEditor::SetHSV (double h, double s, double v)
00984   {
00985     hsv_ = color::HueSaturationValue(Clamp<double>(h, 0.0, 1.0),
00986                                      Clamp<double>(s, 0.0, 1.0),
00987                                      Clamp<double>(v, 0.0, 1.0));
00988     rgb_ = color::RedGreenBlue(hsv_);
00989     RecvCheckColorModel(true, m_ColorModel, m_ColorChannel);
00990     sigChange.emit (this);
00991   }
00992 
00993   void ColorEditor::SetRed(double red)
00994   {
00995     SetRGB(red, rgb_.green, rgb_.blue);
00996   }
00997 
00998   void ColorEditor::SetGreen(double green)
00999   {
01000     SetRGB(rgb_.red, green, rgb_.blue);
01001   }
01002 
01003   void ColorEditor::SetBlue(double blue)
01004   {
01005     SetRGB(rgb_.red, rgb_.green, blue);
01006   }
01007 
01008   void ColorEditor::SetHue (double hue)
01009   {
01010     SetHSV(hue, hsv_.saturation, hsv_.value);
01011   }
01012 
01013   void ColorEditor::SetSaturation(double saturation)
01014   {
01015     SetHSV(hsv_.hue, saturation, hsv_.value);
01016   }
01017 
01018   void ColorEditor::SetValue(double value)
01019   {
01020     SetHSV(hsv_.hue, hsv_.saturation, value);
01021   }
01022 
01023   void ColorEditor::SetColorModel(color::Model colormodel,
01024                                   color::Channel colorchannel)
01025   {
01026     if (colormodel == color::HSV)
01027     {
01028       if ( (colorchannel != color::HUE) &&
01029            (colorchannel != color::SATURATION) &&
01030            (colorchannel != color::VALUE) )
01031       {
01032         nuxDebugMsg (TEXT ("[ColorEditor::SetColorModel] The color model (HSV) and the color channel don't match.") );
01033         return;
01034       }
01035     }
01036 
01037     if (colormodel == color::RGB)
01038     {
01039       if ( (colorchannel != color::RED) &&
01040            (colorchannel != color::GREEN) &&
01041            (colorchannel != color::BLUE) )
01042       {
01043         nuxDebugMsg (TEXT ("[ColorEditor::SetColorModel] The color model (RGB) and the color channel don't match.") );
01044         return;
01045       }
01046     }
01047 
01048     m_ColorModel = colormodel;
01049     m_ColorChannel = colorchannel;
01050     RecvCheckColorModel (true, m_ColorModel, m_ColorChannel);
01051 
01052     /*FIXME - disabled because we lost radiogroup 
01053     if (m_ColorChannel == CC_RED)
01054       radiogroup->ActivateButton (redcheck);
01055     else if (m_ColorChannel == color::GREEN)
01056       radiogroup->ActivateButton (greencheck);
01057     else if (m_ColorChannel == color::BLUE)
01058       radiogroup->ActivateButton (bluecheck);
01059     else if (m_ColorChannel == color::HUE)
01060       radiogroup->ActivateButton (huecheck);
01061     else if (m_ColorChannel == color::SATURATION)
01062       radiogroup->ActivateButton (saturationcheck);
01063     else if (m_ColorChannel == color::VALUE)
01064       radiogroup->ActivateButton (valuecheck);
01065     */
01066 
01067   }
01068 
01069   color::Model ColorEditor::GetColorModel() const
01070   {
01071     return m_ColorModel;
01072   }
01073 
01074   color::Channel ColorEditor::GetColorChannel() const
01075   {
01076     return m_ColorChannel;
01077   }
01078 
01079   bool ColorEditor::AcceptKeyNavFocus()
01080   {
01081     return false;
01082   }
01083 }
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends