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 "PropertyList.h" 00025 00026 #include "ValuatorInt.h" 00027 #include "IntegerValuatorPropertyItem.h" 00028 00029 namespace nux 00030 { 00031 00032 IntValuatorPropertyItem::IntValuatorPropertyItem (const TCHAR *name, int Value, int Step, int MinValue, int MaxValue) 00033 : SectionProperty (name, NODE_TYPE_INTVALUATOR) 00034 { 00035 SetRange (MinValue, MaxValue); 00036 SetValue (Value); 00037 SetStep (Step); 00038 NODE_SIG_CONNECT (sigValueChanged, IntValuatorPropertyItem, RecvPropertyChange); 00039 } 00040 00041 IntValuatorPropertyItem::~IntValuatorPropertyItem() 00042 { 00043 00044 } 00045 00046 long IntValuatorPropertyItem::ProcessPropertyEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo) 00047 { 00048 long ret = TraverseInfo; 00049 00050 Geometry geo = m_ItemGeometryVector[1]; 00051 00052 if ( (ievent.e_event == NUX_MOUSE_PRESSED) && geo.IsPointInside (ievent.e_x, ievent.e_y) == false) 00053 { 00054 // This will filter out mouse down event that happened in the item in the same row on the right. 00055 // This is necessary because the widget we are testing maybe larger that the table element where it resides. 00056 // 00057 // ____________________________________________________________ 00058 // | NAME | WIDGET | : | 00059 // |___________|________________|_____:_____________|___________ 00060 // ^ 00061 // | 00062 // end of widget 00063 // 00064 ret = ProcessEvent (ievent, TraverseInfo, eDoNotProcess | ProcessEventInfo); 00065 } 00066 else 00067 { 00068 ret = ProcessEvent (ievent, TraverseInfo, ProcessEventInfo); 00069 } 00070 00071 return ret; 00072 } 00073 00074 void IntValuatorPropertyItem::DrawProperty (GraphicsEngine &GfxContext, TableCtrl *table, bool force_draw, Geometry geo, const BasePainter &Painter, 00075 RowHeader *row, const std::vector<ColumnHeader>& column_vector, Color ItemBackgroundColor) 00076 { 00077 if (isDirtyItem() || IsRedrawNeeded() ) 00078 { 00079 t_u32 nBackground = table->PushItemBackground (GfxContext, this); 00080 Painter.PaintTextLineStatic (GfxContext, GetFont (), m_FirstColumnUsableGeometry, row->_table_item->GetName(), GetItemTextColor() ); 00081 00082 if (m_ItemGeometryVector.size() >= 2) 00083 { 00084 Geometry geo2 = m_ItemGeometryVector[1]; 00085 Geometry prop_geo; 00086 prop_geo.SetX (geo.x + geo.GetWidth() ); 00087 prop_geo.SetY (geo.y); 00088 prop_geo.SetWidth (column_vector[1].m_header_area->GetBaseWidth() ); 00089 prop_geo.SetHeight (geo.GetHeight() ); 00090 00091 geo2.Expand (-PROPERTY_BORDER_X, -PROPERTY_BORDER_Y); 00092 GfxContext.PushClippingRectangle (geo2); 00093 GfxContext.PushClippingRectangle (prop_geo); 00094 ProcessDraw (GfxContext, true); 00095 GfxContext.PopClippingRectangle(); 00096 GfxContext.PopClippingRectangle(); 00097 } 00098 00099 table->PopItemBackground (GfxContext, nBackground); 00100 } 00101 } 00102 00103 void IntValuatorPropertyItem::ComputePropertyLayout (int x, int y, RowHeader *row, const std::vector<ColumnHeader>& column_vector) 00104 { 00105 if (m_ItemGeometryVector.size() >= 2) 00106 { 00107 Geometry geo; 00108 geo = m_ItemGeometryVector[1]; 00109 geo = geo.GetExpand (-PROPERTY_BORDER_X, -PROPERTY_BORDER_Y); 00110 SetGeometry (geo); 00111 } 00112 } 00113 00114 int IntValuatorPropertyItem::GetItemBestHeight() 00115 { 00116 Size sz = GetMinimumSize(); 00117 return sz.height + 2 * PROPERTY_BORDER_Y; 00118 } 00119 00120 IntValuatorPropertyItem *IntValuatorPropertyItem::CreateFromXML (const TiXmlElement *elementxml, NodeNetCom *parent, const char *Name, int id) 00121 { 00122 int value = 0; 00123 int minvalue = 0; 00124 int maxvalue = 100; 00125 int step = 1; 00126 QueryNodeXMLIntAttribute (elementxml, TEXT ("Value"), &value, id); 00127 QueryNodeXMLIntAttribute (elementxml, TEXT ("Step"), &step, id); 00128 QueryNodeXMLIntAttribute (elementxml, TEXT ("MinValue"), &minvalue, id); 00129 QueryNodeXMLIntAttribute (elementxml, TEXT ("MaxValue"), &maxvalue, id); 00130 //QueryNodeXMLIntAttribute(elementxml, "Step", &step, id); 00131 00132 IntValuatorPropertyItem *node = new IntValuatorPropertyItem (Name, value, step, minvalue, maxvalue); 00133 node->SetID (id); 00134 return node; 00135 } 00136 00137 TiXmlElement *IntValuatorPropertyItem::ToXML() const 00138 { 00139 TiXmlElement *elementxml = NodeNetCom::ToXML(); 00140 elementxml->SetAttribute (TEXT ("Value"), GetValue() ); 00141 elementxml->SetAttribute (TEXT ("Step"), GetStep() ); 00142 elementxml->SetAttribute (TEXT ("MinValue"), GetMinValue() ); 00143 elementxml->SetAttribute (TEXT ("MaxValue"), GetMaxValue() ); 00144 return elementxml; 00145 } 00146 00147 bool IntValuatorPropertyItem::FromXML (const TiXmlElement *elementxml) 00148 { 00149 int value = 0; 00150 int minvalue = 0; 00151 int maxvalue = 100; 00152 int step = 1; 00153 QueryNodeXMLIntAttribute (elementxml, TEXT ("Value"), &value, GetID() ); 00154 QueryNodeXMLIntAttribute (elementxml, TEXT ("Step"), &step, GetID() ); 00155 QueryNodeXMLIntAttribute (elementxml, TEXT ("MinValue"), &minvalue, GetID() ); 00156 QueryNodeXMLIntAttribute (elementxml, TEXT ("MaxValue"), &maxvalue, GetID() ); 00157 SetRange (minvalue, maxvalue); 00158 SetValue (value); 00159 SetStep (step); 00160 return NodeNetCom::FromXML (elementxml); 00161 } 00162 }