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 "Matrix3Preview.h" 00027 #include "Matrix3PreviewPropertyItem.h" 00028 00029 namespace nux 00030 { 00031 00032 Matrix3PreviewPropertyItem::Matrix3PreviewPropertyItem (const TCHAR *name, Matrix3 matrix) 00033 : SectionProperty (name, NODE_TYPE_MATRIX3PREVIEW) 00034 , Matrix3Preview (matrix) 00035 { 00036 NODE_SIG_CONNECT (sigMatrixChanged, Matrix3PreviewPropertyItem, RecvPropertyChange); 00037 } 00038 00039 Matrix3PreviewPropertyItem::~Matrix3PreviewPropertyItem() 00040 { 00041 00042 } 00043 00044 long Matrix3PreviewPropertyItem::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 Matrix3PreviewPropertyItem::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 Matrix3PreviewPropertyItem::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 Matrix3PreviewPropertyItem::GetItemBestHeight() 00103 { 00104 Size sz = GetMinimumSize(); 00105 return sz.height + 2 * PROPERTY_BORDER_Y; 00106 } 00107 00108 Matrix3PreviewPropertyItem *Matrix3PreviewPropertyItem::CreateFromXML (const TiXmlElement *elementxml, NodeNetCom *parent, const char *Name, int id) 00109 { 00110 Matrix3PreviewPropertyItem *node = new Matrix3PreviewPropertyItem (Name); 00111 00112 Matrix3 matrix; 00113 const TiXmlElement *childxml = elementxml->FirstChildElement(); 00114 double d; 00115 00116 for (int i = 0; i < 3; i++) 00117 { 00118 if (childxml == 0) 00119 break; 00120 00121 TCHAR m[6]; 00122 00123 for (int j = 0; j < 3; j++) 00124 { 00125 Snprintf (m, 6, 6 - 1, TEXT ("m%d%d"), i, j); 00126 QueryNodeXMLDoubleAttribute (childxml, m, &d, -1); 00127 matrix (i, j) = d; 00128 } 00129 00130 childxml = childxml->NextSiblingElement(); 00131 } 00132 00133 node->SetMatrix (matrix); 00134 return node; 00135 } 00136 00137 TiXmlElement *Matrix3PreviewPropertyItem::ToXML() const 00138 { 00139 TiXmlElement *elementxml = NodeNetCom::ToXML(); 00140 00141 for (int i = 0; i < 3; i++) 00142 { 00143 TCHAR row[6]; 00144 TCHAR m[6]; 00145 Snprintf (row, 6, 6 - 1, TEXT ("row%d"), i); 00146 TiXmlElement *childxml = new TiXmlElement (row); 00147 00148 for (int j = 0; j < 3; j++) 00149 { 00150 Snprintf (m, 6, 6 - 1, TEXT ("m%d%d"), i, j); 00151 childxml->SetDoubleAttribute (m, GetMatrix() (i, j) ); 00152 } 00153 00154 childxml = childxml->NextSiblingElement(); 00155 } 00156 00157 return elementxml; 00158 } 00159 00160 bool Matrix3PreviewPropertyItem::FromXML (const TiXmlElement *elementxml) 00161 { 00162 Matrix3 matrix; 00163 const TiXmlElement *childxml = elementxml->FirstChildElement(); 00164 double d; 00165 00166 for (int i = 0; i < 3; i++) 00167 { 00168 if (childxml == 0) 00169 break; 00170 00171 TCHAR m[6]; 00172 00173 for (int j = 0; j < 3; j++) 00174 { 00175 Snprintf (m, 6, 6 - 1, TEXT ("m%d%d"), i, j); 00176 QueryNodeXMLDoubleAttribute (childxml, m, &d, -1); 00177 matrix (i, j) = d; 00178 } 00179 00180 childxml = childxml->NextSiblingElement(); 00181 } 00182 00183 SetMatrix (matrix); 00184 return NodeNetCom::FromXML (elementxml); 00185 } 00186 }