nux-1.16.0
ValuatorInt.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 #include "TimerProc.h"
00025 #include "WindowCompositor.h"
00026 #include "ValuatorInt.h"
00027 
00028 namespace nux
00029 {
00030 
00031   const Color SPINBOX_BUTTON_COLOR = Color (0xFF4D4D4D);
00032   const Color SPINBOX_BUTTON_MOUSEOVER_COLOR = Color (0xFF222222);
00033 
00034   ValuatorInt::ValuatorInt (int Value, int Step, int MinValue, int MaxValue)
00035     :   m_IntValidator (MinValue, MaxValue)
00036     ,   m_Step (Step)
00037   {
00038     m_EditLine->SetValidator (&m_IntValidator);
00039     m_EditLine->SetSuffix (TEXT ("") );
00040     m_EditLine->SetPrefix (TEXT ("") );
00041     m_EditLine->SetText (NString::Printf (TEXT ("%d"), m_IntValidator.GetMinimum() ) );
00042 
00043     m_EditLine->SetMinimumSize (1.5 * DEFAULT_WIDGET_WIDTH, DEFAULT_WIDGET_HEIGHT);
00044     m_EditLine->SetGeometry (Geometry (0, 0, DEFAULT_WIDGET_WIDTH, DEFAULT_WIDGET_HEIGHT) );
00045 
00046     m_MouseControlledButton->SetMinimumSize (16 + 9, 10);
00047     m_MouseControlledButton->SetGeometry (Geometry (0, 0, 15, 10) );
00048 
00049     // Set the minimum size of this widget.
00050     // This is use by TextLineEditPropertyItem::GetItemBestHeight
00051     SetMinimumSize (DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
00052 
00053     m_hlayout = new HLayout (NUX_TRACKER_LOCATION);
00054     m_hlayout->AddView (m_MouseControlledButton, 0);
00055     m_hlayout->AddView (m_EditLine, 1);
00056     m_hlayout->SetHorizontalInternalMargin (4);
00057     SetCompositionLayout (m_hlayout);
00058 
00059     SetValue (Value);
00060   }
00061 
00062   ValuatorInt::~ValuatorInt()
00063   {
00064   }
00065 
00066   long ValuatorInt::ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
00067   {
00068     long ret = TraverseInfo;
00069     ret = m_MouseControlledButton->OnEvent (ievent, ret, ProcessEventInfo);
00070     ret = m_EditLine->ProcessEvent (ievent, ret, ProcessEventInfo);
00071     ret = PostProcessEvent2 (ievent, ret, ProcessEventInfo);
00072     return ret;
00073   }
00074 
00075   void ValuatorInt::Draw (GraphicsEngine &GfxContext, bool force_draw)
00076   {
00077     Geometry base = GetGeometry();
00078     GetPainter().PaintBackground (GfxContext, base);
00079 
00080     if (m_EditLine->IsMouseInside() ||
00081         m_MouseControlledButton->IsMouseOwner() || m_MouseControlledButton->IsMouseInside() )
00082     {
00083 
00084       GetPainter().PaintShapeCorner (GfxContext, base, SPINBOX_BUTTON_MOUSEOVER_COLOR, eSHAPE_CORNER_ROUND4,
00085                                  eCornerTopLeft | eCornerBottomLeft, false);
00086     }
00087     else
00088     {
00089       GetPainter().PaintShapeCorner (GfxContext, base, SPINBOX_BUTTON_COLOR, eSHAPE_CORNER_ROUND4,
00090                                  eCornerTopLeft | eCornerBottomLeft, false);
00091     }
00092 
00093     GeometryPositioning gp (eHACenter, eVACenter);
00094     Geometry GeoPo = ComputeGeometryPositioning (m_MouseControlledButton->GetGeometry(), GetTheme().GetImageGeometry (eVALUATORMOVE), gp);
00095 
00096     if (m_Mouse == 1)
00097     {
00098       if (m_MouseControlledButton->IsMouseInside() )
00099         GetPainter().PaintShape (GfxContext, GeoPo, Color (0xFFFFFFFF), eVALUATORHORIZONTALMOVE);
00100       else
00101         GetPainter().PaintShape (GfxContext, GeoPo, Color (0xFFFFFFFF), eVALUATORHORIZONTALMOVE);
00102     }
00103     else if (m_Mouse == 3)
00104     {
00105       if (m_MouseControlledButton->IsMouseInside() )
00106         GetPainter().PaintShape (GfxContext, GeoPo, Color (0xFFFFFFFF), eVALUATORVERTICALMOVE);
00107       else
00108         GetPainter().PaintShape (GfxContext, GeoPo, Color (0xFFFFFFFF), eVALUATORVERTICALMOVE);
00109     }
00110     else
00111     {
00112       if (m_MouseControlledButton->IsMouseInside() )
00113         GetPainter().PaintShape (GfxContext, GeoPo, Color (0xFFFFFFFF), eVALUATORMOVE);
00114       else
00115         GetPainter().PaintShape (GfxContext, GeoPo, Color (0xFFFFFFFF), eVALUATORMOVE);
00116     }
00117 
00118 
00119 
00120     Geometry geo = m_EditLine->GetGeometry();
00121     geo.OffsetPosition (-4, 0);
00122     GetPainter().PaintShapeCorner (GfxContext, geo, m_EditLine->GetTextBackgroundColor(), eSHAPE_CORNER_ROUND4,
00123                                eCornerTopLeft | eCornerBottomLeft, false);
00124 
00125     m_EditLine->QueueDraw();
00126   }
00127 
00128   void ValuatorInt::DrawContent (GraphicsEngine &GfxContext, bool force_draw)
00129   {
00130     m_EditLine->ProcessDraw (GfxContext, force_draw);
00131   }
00132 
00133   void ValuatorInt::PostDraw (GraphicsEngine &GfxContext, bool force_draw)
00134   {
00135 
00136   }
00137 
00138   void ValuatorInt::SetValue (int value)
00139   {
00140     m_iValue = m_IntValidator.GetClampedValue (value);
00141     m_EditLine->SetText (NString::Printf ("%d", m_iValue) );
00142     sigValueChanged.emit (this);
00143     sigValue.emit (m_iValue);
00144     QueueDraw();
00145   }
00146 
00147   int ValuatorInt::GetValue() const
00148   {
00149     return m_iValue;
00150   }
00151 
00152   void ValuatorInt::SetStep (int i)
00153   {
00154     m_Step = i;
00155 
00156     if (m_Step <= 0)
00157       m_Step = 1;
00158 
00159     QueueDraw();
00160   }
00161 
00162   int ValuatorInt::GetStep() const
00163   {
00164     return m_Step;
00165   }
00166 
00167   int ValuatorInt::GetMinValue() const
00168   {
00169     return m_IntValidator.GetMinimum();
00170   }
00171 
00172   int ValuatorInt::GetMaxValue() const
00173   {
00174     return m_IntValidator.GetMaximum();
00175   }
00176 
00177   void ValuatorInt::SetRange (int MinValue, int Maxvalue)
00178   {
00179     m_IntValidator.SetMinimum (MinValue);
00180     m_IntValidator.SetMaximum (Maxvalue);
00181     m_iValue = m_IntValidator.GetClampedValue (m_iValue);
00182     sigValueChanged.emit (this);
00183     sigValue.emit (m_iValue);
00184     QueueDraw();
00185   }
00186 
00187   void ValuatorInt::ImplementIncrementBtn()
00188   {
00189     SetValue (m_iValue + m_Step);
00190 
00191     if (m_iValue < m_IntValidator.GetMaximum() )
00192     {
00193       QueueDraw();
00194     }
00195 
00196     sigValueChanged.emit (this);
00197     sigIncrement.emit (this);
00198     sigValue.emit (m_iValue);
00199   }
00200 
00201   void ValuatorInt::ImplementDecrementBtn()
00202   {
00203     SetValue (m_iValue - m_Step);
00204 
00205     if (m_iValue > m_IntValidator.GetMinimum() )
00206     {
00207       QueueDraw();
00208     }
00209 
00210     sigValueChanged.emit (this);
00211     sigDecrement.emit (this);
00212     sigValue.emit (m_iValue);
00213   }
00214 
00215   void ValuatorInt::ImplementValidateEntry()
00216   {
00217     double ret = 0;
00218     ret = CharToDouble (m_EditLine->GetCleanText().GetTCharPtr() );
00219     {
00220       m_iValue = m_IntValidator.GetClampedValue (ret);
00221       m_EditLine->SetText (NString::Printf ("%d", m_iValue) );
00222       sigValueChanged.emit (this);
00223       sigValue.emit (m_iValue);
00224 //
00225 //        if(m_iValue < m_IntValidator.GetMinimum())
00226 //        {
00227 //            m_iValue = m_IntValidator.GetMinimum();
00228 //            m_EditLine->SetText(NString::Printf("%d", m_iValue));
00229 //        }
00230 //        if(m_iValue > m_IntValidator.GetMaximum())
00231 //        {
00232 //            m_iValue = m_IntValidator.GetMaximum();
00233 //            m_EditLine->SetText(NString::Printf("%d", m_iValue));
00234 //        }
00235     }
00236 //     else
00237 //     {
00238 //         m_EditLine->SetText(NString::Printf("%d", m_iValue));
00239 //         sigValueChanged.emit(this);
00240 //         sigValue.emit(m_iValue);
00241 //     }
00242   }
00243 
00244 
00245 
00246 }
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends