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 "PropertyList.h" 00025 00026 #include "EditTextLinePropertyItem.h" 00027 #include "Vector3Property.h" 00028 00029 namespace nux 00030 { 00031 00032 Vector3PropertyItem::Vector3PropertyItem (const TCHAR *name, 00033 double X, 00034 double Y, 00035 double Z, 00036 const TCHAR *XName, 00037 const TCHAR *YName, 00038 const TCHAR *ZName) 00039 : SectionProperty (name, NODE_TYPE_VECTOR3) 00040 { 00041 m_X = new EditTextLinePropertyItem (XName); 00042 m_Y = new EditTextLinePropertyItem (YName); 00043 m_Z = new EditTextLinePropertyItem (ZName); 00044 00045 DoubleValidator validator; 00046 m_X->SetValidator (&validator); 00047 m_Y->SetValidator (&validator); 00048 m_Z->SetValidator (&validator); 00049 00050 m_X->SetText (NString::Printf ("%.3f", X) ); 00051 m_Y->SetText (NString::Printf ("%.3f", Y) ); 00052 m_Z->SetText (NString::Printf ("%.3f", Z) ); 00053 00054 m_X->SetTextColor (GPropertyItemTextColor1); 00055 m_Y->SetTextColor (GPropertyItemTextColor1); 00056 m_Z->SetTextColor (GPropertyItemTextColor1); 00057 00058 PushChildBack (m_X); 00059 PushChildBack (m_Y); 00060 PushChildBack (m_Z); 00061 00062 NODE_SIG_CONNECT (m_X->sigValidateEntry, Vector3PropertyItem, RecvPropertyChange); 00063 NODE_SIG_CONNECT (m_Y->sigValidateEntry, Vector3PropertyItem, RecvPropertyChange); 00064 NODE_SIG_CONNECT (m_Z->sigValidateEntry, Vector3PropertyItem, RecvPropertyChange); 00065 } 00066 00067 Vector3PropertyItem::~Vector3PropertyItem() 00068 { 00069 NUX_SAFE_DELETE (m_X); 00070 NUX_SAFE_DELETE (m_Y); 00071 NUX_SAFE_DELETE (m_Z); 00072 } 00073 00074 long Vector3PropertyItem::ProcessPropertyEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo) 00075 { 00076 long ret = TraverseInfo; 00077 00078 //ret = ProcessEvent(ievent, TraverseInfo, ProcessEventInfo); 00079 return ret; 00080 } 00081 00082 void Vector3PropertyItem::DrawProperty (GraphicsEngine &GfxContext, TableCtrl *table, bool force_draw, Geometry ItemGeo, const BasePainter &Painter, 00083 RowHeader *row, const std::vector<ColumnHeader>& column_vector, Color ItemBackgroundColor) 00084 { 00085 bool isSelected = (this == table->GetSelectedItem() ); 00086 00087 if (isDirtyItem() || 00088 m_X->IsRedrawNeeded() || 00089 m_Y->IsRedrawNeeded() || 00090 m_Z->IsRedrawNeeded() ) 00091 { 00092 t_u32 nBackground = table->PushItemBackground (GfxContext, this); 00093 Painter.PaintTextLineStatic (GfxContext, GetSysBoldFont() /*GetFont ()*/, m_FirstColumnUsableGeometry, row->_table_item->GetName(), GetItemTextColor() ); 00094 00095 if (m_ItemGeometryVector.size() >= 2) 00096 { 00097 Geometry prop_geo = m_ItemGeometryVector[1]; 00098 prop_geo = prop_geo.GetExpand (-PROPERTY_BORDER_X, -PROPERTY_BORDER_Y); 00099 00100 TCHAR buffer[256]; 00101 Snprintf (buffer, 256, 256 - 1, TEXT (" [ %s, %s, %s ] "), m_X->GetText(), m_Y->GetText(), m_Z->GetText() ); 00102 //Painter.Paint2DQuadColor(prop_geo, ItemBackgroundColor); 00103 00104 if (isSelected && table->GetSelectedColumn() == 1) 00105 Painter.Paint2DQuadColor (GfxContext, prop_geo, table->GetSelectionColor() ); 00106 else 00107 Painter.Paint2DQuadColor (GfxContext, prop_geo, ItemBackgroundColor); 00108 00109 Painter.PaintTextLineStatic (GfxContext, GetSysBoldFont() /*GetFont ()*/, prop_geo, buffer, GetItemTextColor() ); 00110 } 00111 00112 table->PopItemBackground (GfxContext, nBackground); 00113 } 00114 } 00115 00116 void Vector3PropertyItem::ComputePropertyLayout (int x, int y, RowHeader *row, const std::vector<ColumnHeader>& column_vector) 00117 { 00118 } 00119 00120 double Vector3PropertyItem::GetX() const 00121 { 00122 double ret; 00123 ret = CharToDouble (m_X->GetText() ); 00124 return ret; 00125 } 00126 00127 double Vector3PropertyItem::GetY() const 00128 { 00129 double ret; 00130 ret = CharToDouble (m_Y->GetText() ); 00131 return ret; 00132 } 00133 00134 double Vector3PropertyItem::GetZ() const 00135 { 00136 double ret; 00137 ret = CharToDouble (m_Z->GetText() ); 00138 return ret; 00139 } 00140 00141 Vector3PropertyItem *Vector3PropertyItem::CreateFromXML (const TiXmlElement *elementxml, NodeNetCom *parent, const char *Name, int id) 00142 { 00143 double X, Y, Z; 00144 tstring NameX, NameY, NameZ; 00145 const TiXmlElement *childxml = elementxml->FirstChildElement(); 00146 QueryNodeXMLStringAttribute (childxml, TEXT ("Name"), NameX, -1); 00147 QueryNodeXMLDoubleAttribute (childxml, TEXT ("X"), &X, -1); 00148 childxml = childxml->NextSiblingElement(); 00149 QueryNodeXMLStringAttribute (childxml, TEXT ("Name"), NameY, -1); 00150 QueryNodeXMLDoubleAttribute (childxml, TEXT ("Y"), &Y, -1); 00151 childxml = childxml->NextSiblingElement(); 00152 QueryNodeXMLStringAttribute (childxml, TEXT ("Name"), NameZ, -1); 00153 QueryNodeXMLDoubleAttribute (childxml, TEXT ("Z"), &Z, -1); 00154 00155 if (NameX.size() == 0) NameX = TEXT ("X"); 00156 00157 if (NameY.size() == 0) NameY = TEXT ("Y"); 00158 00159 if (NameZ.size() == 0) NameZ = TEXT ("Z"); 00160 00161 Vector3PropertyItem *node = new Vector3PropertyItem (Name, X, Y, Z, NameX.c_str(), NameY.c_str(), NameZ.c_str() ); 00162 00163 // node->SetX(X); 00164 // node->SetY(Y); 00165 // node->SetZ(Z); 00166 00167 node->SetID (id); 00168 return node; 00169 } 00170 00171 TiXmlElement *Vector3PropertyItem::ToXML() const 00172 { 00173 TiXmlElement *elementxml = NodeNetCom::ToXML(); 00174 TiXmlElement *childxml = new TiXmlElement (TEXT ("VecX") ); 00175 childxml->SetAttribute (TEXT ("Name"), GetXLabel() ); 00176 childxml->SetDoubleAttribute (TEXT ("X"), GetX() ); 00177 elementxml->LinkEndChild (childxml); 00178 childxml = new TiXmlElement (TEXT ("VecY") ); 00179 childxml->SetAttribute (TEXT ("Name"), GetYLabel() ); 00180 childxml->SetDoubleAttribute (TEXT ("Y"), GetY() ); 00181 elementxml->LinkEndChild (childxml); 00182 childxml = new TiXmlElement (TEXT ("VecZ") ); 00183 childxml->SetAttribute (TEXT ("Name"), GetZLabel() ); 00184 childxml->SetDoubleAttribute (TEXT ("Z"), GetZ() ); 00185 elementxml->LinkEndChild (childxml); 00186 00187 return elementxml; 00188 } 00189 00190 bool Vector3PropertyItem::FromXML (const TiXmlElement *elementxml) 00191 { 00192 double X, Y, Z; 00193 tstring NameX, NameY, NameZ; 00194 const TiXmlElement *childxml = elementxml->FirstChildElement(); 00195 QueryNodeXMLStringAttribute (childxml, TEXT ("Name"), NameX, -1); 00196 QueryNodeXMLDoubleAttribute (childxml, TEXT ("X"), &X, -1); 00197 childxml = childxml->NextSiblingElement(); 00198 QueryNodeXMLStringAttribute (childxml, TEXT ("Name"), NameY, -1); 00199 QueryNodeXMLDoubleAttribute (childxml, TEXT ("Y"), &Y, -1); 00200 childxml = childxml->NextSiblingElement(); 00201 QueryNodeXMLStringAttribute (childxml, TEXT ("Name"), NameZ, -1); 00202 QueryNodeXMLDoubleAttribute (childxml, TEXT ("Z"), &Z, -1); 00203 00204 SetX (X); 00205 SetY (Y); 00206 SetZ (Z); 00207 00208 return NodeNetCom::FromXML (elementxml); 00209 } 00210 }