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 "ColorPreview.h" 00025 #include "ColorEditor.h" 00026 #include "HLayout.h" 00027 #include "TimerProc.h" 00028 #include "StaticTextBox.h" 00029 00030 namespace nux 00031 { 00032 00033 static const int GRAPH_MARGIN = 1; 00034 00035 ColorPreview::ColorPreview(Color const& c, NUX_FILE_LINE_DECL) 00036 : View(NUX_FILE_LINE_PARAM) 00037 , m_Color(c) 00038 { 00039 //setSize(200, 100); 00040 m_hlayout = new HLayout(NUX_TRACKER_LOCATION); 00041 m_ColorArea = new InputArea(NUX_TRACKER_LOCATION); 00042 m_ColorValue = new StaticTextBox (TEXT (""), NUX_TRACKER_LOCATION); 00043 m_DialogThreadProxy = new ColorDialogProxy (true); 00044 00045 SetMaximumHeight (18); 00046 m_ColorArea->SetMaximumHeight (18); 00047 m_ColorArea->SetMinimumWidth (32); 00048 m_ColorArea->SetMaximumWidth (32); 00049 m_ColorValue->SetTextColor (Color (0xFFFFFFFF) ); 00050 m_ColorValue->SetFont (GetSysBoldFont() ); 00051 m_ColorValue->SetMinimumWidth (128); 00052 00053 NString text = NString::Printf (TEXT ("[ R:%d, G:%d, B:%d ]"), (int) (m_Color.red * 255), (int) (m_Color.green * 255), (int) (m_Color.blue * 255) ); 00054 m_ColorValue->SetText (text); 00055 00056 m_ColorArea->mouse_click.connect (sigc::mem_fun (this, &ColorPreview::RecvClick) ); 00057 00058 m_hlayout->AddView (m_ColorArea, 0); 00059 m_hlayout->AddView (m_ColorValue, 1); 00060 m_hlayout->SetHorizontalInternalMargin (4); 00061 SetCompositionLayout (m_hlayout); 00062 00063 m_ChangeDetectionTimer = new TimerFunctor(); 00064 m_ChangeDetectionTimer->OnTimerExpired.connect (sigc::mem_fun (this, &ColorPreview::RecvTimer) ); 00065 m_ChangeTimerHandler = 0; 00066 } 00067 00068 ColorPreview::~ColorPreview() 00069 { 00070 delete m_ChangeDetectionTimer; 00071 00072 if (m_ChangeTimerHandler.IsValid() ) 00073 GetTimer().RemoveTimerHandler (m_ChangeTimerHandler); 00074 00075 delete m_DialogThreadProxy; 00076 } 00077 00078 long ColorPreview::ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo) 00079 { 00080 long ret = TraverseInfo; 00081 ret = m_ColorArea->OnEvent (ievent, ret, ProcessEventInfo); 00082 ret = PostProcessEvent2 (ievent, ret, ProcessEventInfo); 00083 return ret; 00084 } 00085 00086 void ColorPreview::Draw (GraphicsEngine &GfxContext, bool force_draw) 00087 { 00088 Geometry base = GetGeometry(); 00089 00090 GetPainter().PaintBackground (GfxContext, base); 00091 GetPainter().PaintShape (GfxContext, m_ColorArea->GetGeometry(), m_Color, eSHAPE_CORNER_ROUND4, false); 00092 //GetPainter().Paint2DQuadWireFrameColor(GfxContext, base, Color(COLOR_BACKGROUND_SECONDARY)); 00093 m_ColorValue->QueueDraw(); 00094 } 00095 00096 void ColorPreview::DrawContent (GraphicsEngine &GfxContext, bool force_draw) 00097 { 00098 m_ColorValue->ProcessDraw (GfxContext, force_draw); 00099 } 00100 00101 void ColorPreview::PostDraw (GraphicsEngine &GfxContext, bool force_draw) 00102 { 00103 00104 } 00105 00106 void ColorPreview::RecvClick (int x, int y, unsigned long button_flags, unsigned long key_flags) 00107 { 00108 m_DialogThreadProxy->SetColor (m_Color); 00109 m_DialogThreadProxy->Start(); 00110 00111 m_ChangeTimerHandler = GetTimer().AddTimerHandler (33, m_ChangeDetectionTimer, this); 00112 } 00113 00114 void ColorPreview::RecvTimer (void *v) 00115 { 00116 if (m_DialogThreadProxy->m_bDialogChange && m_DialogThreadProxy->m_bDialogRunning) 00117 { 00118 m_DialogThreadProxy->m_bDialogChange = false; 00119 m_Color = m_DialogThreadProxy->GetColor(); 00120 QueueDraw(); 00121 } 00122 00123 if (m_DialogThreadProxy->IsActive() ) 00124 { 00125 m_ChangeTimerHandler = GetTimer().AddTimerHandler (33, m_ChangeDetectionTimer, this); 00126 } 00127 else 00128 { 00129 if (m_ChangeTimerHandler.IsValid() ) 00130 GetTimer().RemoveTimerHandler (m_ChangeTimerHandler); 00131 00132 m_ChangeTimerHandler = 0; 00133 m_Color = m_DialogThreadProxy->GetColor(); 00134 QueueDraw(); 00135 } 00136 } 00137 00138 Color const& ColorPreview::GetRGBColor() const 00139 { 00140 return m_Color; 00141 } 00142 00143 void ColorPreview::SetColor (Color const& color) 00144 { 00145 m_Color = color; 00146 } 00147 00148 }