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