nux-1.16.0
ColorPreviewPropertyItem.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 "ColorPreview.h"
00027 #include "ColorPreviewPropertyItem.h"
00028 
00029 namespace nux
00030 {
00031 
00032   ColorPreviewPropertyItem::ColorPreviewPropertyItem(const TCHAR *name, float red, float green, float blue, color::Model colormodel)
00033     : SectionProperty(name, NODE_TYPE_COLORPREVIEW)
00034     , ColorPreview(Color(red, green, blue))
00035   {
00036     NODE_SIG_CONNECT (sigColorChanged, ColorPreviewPropertyItem, RecvPropertyChange);
00037   }
00038 
00039   ColorPreviewPropertyItem::~ColorPreviewPropertyItem()
00040   {
00041   }
00042 
00043   long ColorPreviewPropertyItem::ProcessPropertyEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
00044   {
00045     long ret = TraverseInfo;
00046 
00047     Geometry geo = m_ItemGeometryVector[1];
00048 
00049     if ( (ievent.e_event == NUX_MOUSE_PRESSED) && geo.IsPointInside (ievent.e_x, ievent.e_y) == false)
00050     {
00051       ret = ProcessEvent (ievent, TraverseInfo, eDoNotProcess | ProcessEventInfo);
00052     }
00053     else
00054     {
00055       ret = ProcessEvent (ievent, TraverseInfo, ProcessEventInfo);
00056     }
00057 
00058     return ret;
00059   }
00060 
00061   void ColorPreviewPropertyItem::DrawProperty (GraphicsEngine &GfxContext, TableCtrl *table, bool force_draw, Geometry geo, const BasePainter &Painter,
00062       RowHeader *row, const std::vector<ColumnHeader>& column_vector, Color ItemBackgroundColor)
00063   {
00064     if (isDirtyItem() || IsRedrawNeeded() )
00065     {
00066       t_u32 nBackground = table->PushItemBackground (GfxContext, this);
00067       Painter.PaintTextLineStatic (GfxContext, GetFont (), m_FirstColumnUsableGeometry, row->_table_item->GetName(), GetItemTextColor() );
00068 
00069       if (m_ItemGeometryVector.size() >= 2)
00070       {
00071         Geometry geo2 = m_ItemGeometryVector[1];
00072         Geometry prop_geo;
00073         prop_geo.SetX (geo.x + geo.GetWidth() );
00074         prop_geo.SetY (geo.y);
00075         prop_geo.SetWidth (column_vector[1].m_header_area->GetBaseWidth() );
00076         prop_geo.SetHeight (geo.GetHeight() );
00077 
00078         geo2.Expand (-PROPERTY_BORDER_X, -PROPERTY_BORDER_Y);
00079         GfxContext.PushClippingRectangle (geo2);
00080         GfxContext.PushClippingRectangle (prop_geo);
00081         ProcessDraw (GfxContext, true);
00082         GfxContext.PopClippingRectangle();
00083         GfxContext.PopClippingRectangle();
00084       }
00085 
00086       table->PopItemBackground (GfxContext, nBackground);
00087     }
00088   }
00089 
00090   void ColorPreviewPropertyItem::ComputePropertyLayout (int x, int y, RowHeader *row, const std::vector<ColumnHeader>& column_vector)
00091   {
00092     if (m_ItemGeometryVector.size() >= 2)
00093     {
00094       Geometry geo;
00095       geo = m_ItemGeometryVector[1];
00096       geo = geo.GetExpand (-PROPERTY_BORDER_X, -PROPERTY_BORDER_Y);
00097       SetGeometry (geo);
00098     }
00099   }
00100 
00101   int ColorPreviewPropertyItem::GetItemBestHeight()
00102   {
00103     Size sz = GetMinimumSize();
00104     return sz.height + 2 * PROPERTY_BORDER_Y;
00105   }
00106 
00107   ColorPreviewPropertyItem *ColorPreviewPropertyItem::CreateFromXML (const TiXmlElement *elementxml, NodeNetCom *parent, const char *Name, int id)
00108   {
00109     ColorPreviewPropertyItem *node = new ColorPreviewPropertyItem (Name, 0, 0, 0, color::RGB);
00110     double red, green, blue;
00111     tstring colormodel;
00112 
00113     const TiXmlElement *childxml = elementxml->FirstChildElement();
00114     QueryNodeXMLDoubleAttribute (childxml, TEXT ("Red"),        &red,     -1);
00115     childxml = childxml->NextSiblingElement();
00116     QueryNodeXMLDoubleAttribute (childxml, TEXT ("Green"),      &green,     -1);
00117     childxml = childxml->NextSiblingElement();
00118     QueryNodeXMLDoubleAttribute (childxml, TEXT ("Blue"),       &blue,     -1);
00119 
00120     node->SetColor(Color(static_cast<float>(red),
00121                          static_cast<float>(green),
00122                          static_cast<float>(blue)));
00123     node->SetID (id);
00124     return node;
00125   }
00126 
00127   TiXmlElement *ColorPreviewPropertyItem::ToXML() const
00128   {
00129     TiXmlElement *elementxml = NodeNetCom::ToXML();
00130     TiXmlElement *childxml;
00131     Color color = GetRGBColor();
00132     childxml = new TiXmlElement (TEXT ("RGBComponent") );
00133     childxml->SetDoubleAttribute (TEXT ("Red"), color.red );
00134     elementxml->LinkEndChild (childxml);
00135     childxml = new TiXmlElement (TEXT ("RGBComponent") );
00136     childxml->SetDoubleAttribute (TEXT ("Green"), color.green );
00137     elementxml->LinkEndChild (childxml);
00138     childxml = new TiXmlElement (TEXT ("RGBComponent") );
00139     childxml->SetDoubleAttribute (TEXT ("Blue"), color.blue );
00140     elementxml->LinkEndChild (childxml);
00141 
00142     return elementxml;
00143   }
00144 
00145   bool ColorPreviewPropertyItem::FromXML (const TiXmlElement *elementxml)
00146   {
00147     double red, green, blue;
00148     tstring NameX, NameY, NameZ, NameW;
00149     const TiXmlElement *childxml;
00150     childxml = elementxml->FirstChildElement();
00151     QueryNodeXMLDoubleAttribute (childxml, TEXT ("Red"),       &red,     -1);
00152     childxml = childxml->NextSiblingElement();
00153     QueryNodeXMLDoubleAttribute (childxml, TEXT ("Green"),       &green,     -1);
00154     childxml = childxml->NextSiblingElement();
00155     QueryNodeXMLDoubleAttribute (childxml, TEXT ("Blue"),       &blue,     -1);
00156 
00157     SetColor(Color(static_cast<float>(red),
00158                    static_cast<float>(green),
00159                    static_cast<float>(blue)));
00160 
00161     return NodeNetCom::FromXML (elementxml);
00162   }
00163 
00164 }
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends