nux-1.14.0
ColorGradientPropertyItem.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 "ColorGradientPropertyItem.h"
00027 
00028 namespace nux
00029 {
00030 
00031   ColorGradientPropertyItem::ColorGradientPropertyItem (const TCHAR *name, float Value, float MinValue, float MaxValue)
00032     :   SectionProperty (name, NODE_TYPE_RANGE)
00033   {
00034     SetRange (MinValue, MaxValue);
00035     SetValue (Value);
00036     m_ValueString->SetMinimumSize (DEFAULT_WIDGET_WIDTH, DEFAULT_WIDGET_HEIGHT);
00037     m_Percentage->SetMinimumSize (2 * DEFAULT_WIDGET_WIDTH, DEFAULT_WIDGET_HEIGHT);
00038     SetMaximumHeight (14);
00039 
00040     NODE_SIG_CONNECT (sigValueChanged, ColorGradientPropertyItem, RecvPropertyChange);
00041   }
00042 
00043   ColorGradientPropertyItem::~ColorGradientPropertyItem()
00044   {
00045 
00046   }
00047 
00048   long ColorGradientPropertyItem::ProcessPropertyEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
00049   {
00050     long ret = TraverseInfo;
00051 
00052     Geometry geo = m_ItemGeometryVector[1];
00053 
00054     if ( (ievent.e_event == NUX_MOUSE_PRESSED) && geo.IsPointInside (ievent.e_x, ievent.e_y) == false)
00055     {
00056       // This will filter out mouse down event that happened in the item in the same row on the right.
00057       // This is necessary because the widget we are testing maybe larger that the table element where it resides.
00058       //
00059       //      ____________________________________________________________
00060       //      | NAME      | WIDGET         |     :             |
00061       //      |___________|________________|_____:_____________|___________
00062       //                                         ^
00063       //                                         |
00064       //                                   end of widget
00065       //
00066       ret = ProcessEvent (ievent, TraverseInfo, eDoNotProcess | ProcessEventInfo);
00067     }
00068     else
00069     {
00070       ret = ProcessEvent (ievent, TraverseInfo, ProcessEventInfo);
00071     }
00072 
00073     return ret;
00074   }
00075 
00076   void ColorGradientPropertyItem::DrawProperty (GraphicsEngine &GfxContext, TableCtrl *table, bool force_draw, Geometry geo, const BasePainter &Painter,
00077       RowHeader *row, const std::vector<ColumnHeader>& column_vector, Color ItemBackgroundColor)
00078   {
00079     if (isDirtyItem() || IsRedrawNeeded() )
00080     {
00081       t_u32 nBackground = table->PushItemBackground (GfxContext, this);
00082       Painter.PaintTextLineStatic (GfxContext, GetFont (), m_FirstColumnUsableGeometry, row->_table_item->GetName(), GetItemTextColor() );
00083 
00084       if (m_ItemGeometryVector.size() >= 2)
00085       {
00086         Geometry geo2 = m_ItemGeometryVector[1];
00087         Geometry prop_geo;
00088         prop_geo.SetX (geo.x + geo.GetWidth() );
00089         prop_geo.SetY (geo.y);
00090         prop_geo.SetWidth (column_vector[1].m_header_area->GetBaseWidth() );
00091         prop_geo.SetHeight (geo.GetHeight() );
00092 
00093         geo2.Expand (-PROPERTY_BORDER_X, -PROPERTY_BORDER_Y);
00094         GfxContext.PushClippingRectangle (geo2);
00095         GfxContext.PushClippingRectangle (prop_geo);
00096         ProcessDraw (GfxContext, true);
00097         GfxContext.PopClippingRectangle();
00098         GfxContext.PopClippingRectangle();
00099       }
00100 
00101       table->PopItemBackground (GfxContext, nBackground);
00102     }
00103   }
00104 
00105   void ColorGradientPropertyItem::ComputePropertyLayout (int x, int y, RowHeader *row, const std::vector<ColumnHeader>& column_vector)
00106   {
00107     if (m_ItemGeometryVector.size() >= 2)
00108     {
00109       Geometry geo;
00110       geo = m_ItemGeometryVector[1];
00111       geo = geo.GetExpand (-PROPERTY_BORDER_X, -PROPERTY_BORDER_Y);
00112       SetGeometry (geo);
00113     }
00114   }
00115 
00116   int ColorGradientPropertyItem::GetItemBestHeight()
00117   {
00118     Size sz = GetMinimumSize();
00119     return sz.height + 2 * PROPERTY_BORDER_Y;
00120   }
00121 
00122 }
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends