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 "SplineCurvePreview.h" 00027 #include "SplineCurvePropertyItem.h" 00028 00029 namespace nux 00030 { 00031 00032 SplineCurvePropertyItem::SplineCurvePropertyItem (const TCHAR *name) 00033 : SectionProperty (name, NODE_TYPE_SPLINE) 00034 { 00035 SetMinMaxSize (32, 32); 00036 NODE_SIG_CONNECT (sigSplineChanged, SplineCurvePropertyItem, RecvPropertyChange); 00037 } 00038 00039 SplineCurvePropertyItem::~SplineCurvePropertyItem() 00040 { 00041 00042 } 00043 00044 long SplineCurvePropertyItem::ProcessPropertyEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo) 00045 { 00046 long ret = TraverseInfo; 00047 00048 Geometry geo = m_ItemGeometryVector[1]; 00049 00050 if ( (ievent.e_event == NUX_MOUSE_PRESSED) && geo.IsPointInside (ievent.e_x, ievent.e_y) == false) 00051 { 00052 ret = ProcessEvent (ievent, TraverseInfo, eDoNotProcess | ProcessEventInfo); 00053 } 00054 else 00055 { 00056 ret = ProcessEvent (ievent, TraverseInfo, ProcessEventInfo); 00057 } 00058 00059 return ret; 00060 } 00061 00062 void SplineCurvePropertyItem::DrawProperty (GraphicsEngine &GfxContext, TableCtrl *table, bool force_draw, Geometry geo, const BasePainter &Painter, 00063 RowHeader *row, const std::vector<ColumnHeader>& column_vector, Color ItemBackgroundColor) 00064 { 00065 if (isDirtyItem() || IsRedrawNeeded() ) 00066 { 00067 t_u32 nBackground = table->PushItemBackground (GfxContext, this); 00068 Painter.PaintTextLineStatic (GfxContext, GetFont (), m_FirstColumnUsableGeometry, row->_table_item->GetName(), GetItemTextColor() ); 00069 00070 if (m_ItemGeometryVector.size() >= 2) 00071 { 00072 Geometry geo2 = m_ItemGeometryVector[1]; 00073 Geometry prop_geo; 00074 prop_geo.SetX (geo.x + geo.GetWidth() ); 00075 prop_geo.SetY (geo.y); 00076 prop_geo.SetWidth (column_vector[1].m_header_area->GetBaseWidth() ); 00077 prop_geo.SetHeight (geo.GetHeight() ); 00078 00079 geo2.Expand (-PROPERTY_BORDER_X, -PROPERTY_BORDER_Y); 00080 GfxContext.PushClippingRectangle (geo2); 00081 GfxContext.PushClippingRectangle (prop_geo); 00082 ProcessDraw (GfxContext, true); 00083 GfxContext.PopClippingRectangle(); 00084 GfxContext.PopClippingRectangle(); 00085 } 00086 00087 table->PopItemBackground (GfxContext, nBackground); 00088 } 00089 } 00090 00091 void SplineCurvePropertyItem::ComputePropertyLayout (int x, int y, RowHeader *row, const std::vector<ColumnHeader>& column_vector) 00092 { 00093 if (m_ItemGeometryVector.size() >= 2) 00094 { 00095 Geometry geo; 00096 geo = m_ItemGeometryVector[1]; 00097 geo = geo.GetExpand (-PROPERTY_BORDER_X, -PROPERTY_BORDER_Y); 00098 SetGeometry (geo); 00099 } 00100 } 00101 00102 int SplineCurvePropertyItem::GetItemBestHeight() 00103 { 00104 Size sz = GetMinimumSize(); 00105 return sz.height + 2 * PROPERTY_BORDER_Y; 00106 } 00107 00108 SplineCurvePropertyItem *SplineCurvePropertyItem::CreateFromXML (const TiXmlElement *elementxml, NodeNetCom *parent, const char *Name, int id) 00109 { 00110 SplineCurvePropertyItem *node = new SplineCurvePropertyItem (Name); 00111 00112 int NumKnot = 0; 00113 QueryNodeXMLIntAttribute (elementxml, "NumKnot", &NumKnot, id); 00114 const TiXmlElement *childxml = elementxml->FirstChildElement(); 00115 int i = 0; 00116 node->Reset(); 00117 00118 while (childxml && (i < NumKnot) ) 00119 { 00120 double x, y; 00121 QueryNodeXMLDoubleAttribute (childxml, TEXT ("X"), &x, -1); 00122 QueryNodeXMLDoubleAttribute (childxml, TEXT ("Y"), &y, -1); // - 1 means do not care about he ID 00123 00124 node->AddKnot (x, y, false); 00125 00126 ++i; 00127 childxml = childxml->NextSiblingElement(); 00128 } 00129 00130 node->SetID (id); 00131 return node; 00132 } 00133 00134 TiXmlElement *SplineCurvePropertyItem::ToXML() const 00135 { 00136 TiXmlElement *elementxml = NodeNetCom::ToXML(); 00137 elementxml->SetAttribute ("NumKnot", GetNumKnot() ); 00138 00139 for (int i = 0; i < GetNumKnot(); i++) 00140 { 00141 TiXmlElement *childxml = new TiXmlElement ("SplineKnot"); 00142 childxml->SetDoubleAttribute (TEXT ("X"), GetKnot (i).GetX() ); 00143 childxml->SetDoubleAttribute (TEXT ("Y"), GetKnot (i).GetY() ); 00144 elementxml->LinkEndChild (childxml); 00145 } 00146 00147 return elementxml; 00148 } 00149 00150 bool SplineCurvePropertyItem::FromXML (const TiXmlElement *elementxml) 00151 { 00152 int NumKnot = 0; 00153 QueryNodeXMLIntAttribute (elementxml, "NumKnot", &NumKnot, GetID() ); 00154 const TiXmlElement *childxml = elementxml->FirstChildElement(); 00155 int i = 0; 00156 00157 while (childxml && (i < NumKnot) ) 00158 { 00159 double x, y; 00160 QueryNodeXMLDoubleAttribute (childxml, TEXT ("X"), &x, -1); 00161 QueryNodeXMLDoubleAttribute (childxml, TEXT ("Y"), &y, -1); // - 1 means do not care about he ID 00162 00163 AddKnot (x, y, false); 00164 ++i; 00165 childxml = childxml->NextSiblingElement(); 00166 } 00167 00168 return NodeNetCom::FromXML (elementxml); 00169 } 00170 }