Back to index

nux  3.0.0
ColorPreview.cpp
Go to the documentation of this file.
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("", 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("[ 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->time_expires.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   void ColorPreview::Draw(GraphicsEngine &graphics_engine, bool force_draw)
00079   {
00080     Geometry base = GetGeometry();
00081 
00082     GetPainter().PaintBackground(graphics_engine, base);
00083     GetPainter().PaintShape(graphics_engine, m_ColorArea->GetGeometry(), m_Color, eSHAPE_CORNER_ROUND4, false);
00084     //GetPainter().Paint2DQuadWireFrameColor(graphics_engine, base, Color(COLOR_BACKGROUND_SECONDARY));
00085     m_ColorValue->QueueDraw();
00086   }
00087 
00088   void ColorPreview::DrawContent(GraphicsEngine &graphics_engine, bool force_draw)
00089   {
00090     m_ColorValue->ProcessDraw(graphics_engine, force_draw);
00091   }
00092 
00093   void ColorPreview::PostDraw(GraphicsEngine &graphics_engine, bool force_draw)
00094   {
00095 
00096   }
00097 
00098   void ColorPreview::RecvClick(int x, int y, unsigned long button_flags, unsigned long key_flags)
00099   {
00100     m_DialogThreadProxy->SetColor(m_Color);
00101     m_DialogThreadProxy->Start();
00102 
00103     m_ChangeTimerHandler = GetTimer().AddTimerHandler(33, m_ChangeDetectionTimer, this);
00104   }
00105 
00106   void ColorPreview::RecvTimer(void *v)
00107   {
00108     if (m_DialogThreadProxy->m_bDialogChange && m_DialogThreadProxy->m_bDialogRunning)
00109     {
00110       m_DialogThreadProxy->m_bDialogChange = false;
00111       m_Color = m_DialogThreadProxy->GetColor();
00112       QueueDraw();
00113     }
00114 
00115     if (m_DialogThreadProxy->IsActive())
00116     {
00117       m_ChangeTimerHandler = GetTimer().AddTimerHandler(33, m_ChangeDetectionTimer, this);
00118     }
00119     else
00120     {
00121       if (m_ChangeTimerHandler.IsValid())
00122         GetTimer().RemoveTimerHandler(m_ChangeTimerHandler);
00123 
00124       m_ChangeTimerHandler = 0;
00125       m_Color = m_DialogThreadProxy->GetColor();
00126       QueueDraw();
00127     }
00128   }
00129 
00130   Color const& ColorPreview::GetRGBColor() const
00131   {
00132     return m_Color;
00133   }
00134 
00135   void ColorPreview::SetColor(Color const& color)
00136   {
00137     m_Color = color;
00138   }
00139 
00140 }