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