~hikiko/nux/arb-srgba-shader

« back to all changes in this revision

Viewing changes to Nux/PropertyItem/DoubleValuatorPropertyItem.cpp

  • Committer: Neil Jagdish Patel
  • Date: 2010-09-02 03:28:11 UTC
  • Revision ID: neil.patel@canonical.com-20100902032811-i2m18tfb6pkasnvt
Remove Win EOL chars

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 */
21
21
 
22
22
 
23
 
#include "Nux.h"
24
 
#include "PropertyList.h"
25
 
 
26
 
#include "ValuatorDouble.h"
27
 
#include "DoubleValuatorPropertyItem.h"
28
 
 
29
 
NAMESPACE_BEGIN_GUI
30
 
 
31
 
DoubleValuatorPropertyItem::DoubleValuatorPropertyItem(const TCHAR* name, float Value, float Step, float MinValue, float MaxValue)
32
 
:   SectionProperty(name, NODE_TYPE_DOUBLEVALUATOR)
33
 
{
34
 
    SetRange(MinValue, MaxValue);
35
 
    SetValue(Value);
36
 
    SetStep(Step);
37
 
    NODE_SIG_CONNECT(sigValueChanged, DoubleValuatorPropertyItem, RecvPropertyChange);
38
 
}
39
 
 
40
 
DoubleValuatorPropertyItem::~DoubleValuatorPropertyItem()
41
 
{
42
 
 
43
 
}
44
 
 
45
 
long DoubleValuatorPropertyItem::ProcessPropertyEvent(IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
46
 
{
47
 
    long ret = TraverseInfo;
48
 
 
49
 
    Geometry geo = m_ItemGeometryVector[1];
50
 
    if((ievent.e_event == INL_MOUSE_PRESSED) && geo.IsPointInside(ievent.e_x, ievent.e_y) == false)
51
 
    {
52
 
        // This will filter out mouse down event that happened in the item in the same row on the right.
53
 
        // This is necessary because the widget we are testing maybe larger that the table element where it resides.
54
 
        // 
55
 
        //      ____________________________________________________________
56
 
        //      | NAME      | WIDGET         |     :             |
57
 
        //      |___________|________________|_____:_____________|___________
58
 
        //                                         ^
59
 
        //                                         |
60
 
        //                                   end of widget
61
 
        //
62
 
        ret = ProcessEvent(ievent, TraverseInfo, eDoNotProcess | ProcessEventInfo);
63
 
    }
64
 
    else
65
 
    {
66
 
        ret = ProcessEvent(ievent, TraverseInfo, ProcessEventInfo);
67
 
    }
68
 
    return ret;
69
 
}
70
 
 
71
 
void DoubleValuatorPropertyItem::DrawProperty(GraphicsContext& GfxContext, TableCtrl* table, bool force_draw, Geometry geo, const BasePainter& Painter, 
72
 
                                              RowHeader* row, const std::vector<header2>& column_vector, Color ItemBackgroundColor)
73
 
{
74
 
    bool isSelected = (this == table->GetSelectedItem());
75
 
    if(isDirtyItem() || IsRedrawNeeded())
76
 
    {
77
 
        UINT nBackground = table->PushItemBackground(GfxContext, this);
78
 
        Painter.PaintTextLineStatic(GfxContext, GetFont(), m_FirstColumnUsableGeometry, row->item->GetName(), GetItemTextColor()); 
79
 
 
80
 
        if(m_ItemGeometryVector.size() >= 2)
81
 
        {
82
 
            Geometry geo2 = m_ItemGeometryVector[1];
83
 
            Geometry prop_geo;
84
 
            prop_geo.SetX(geo.x + geo.GetWidth());
85
 
            prop_geo.SetY(geo.y);
86
 
            prop_geo.SetWidth(column_vector[1].header.GetBaseWidth());
87
 
            prop_geo.SetHeight(geo.GetHeight());
88
 
 
89
 
            geo2.Expand(-PROPERTY_BORDER_X, -PROPERTY_BORDER_Y);
90
 
            GfxContext.PushClippingRectangle(geo2);
91
 
            GfxContext.PushClippingRectangle(prop_geo);
92
 
            ProcessDraw(GfxContext, true);
93
 
            GfxContext.PopClippingRectangle();
94
 
            GfxContext.PopClippingRectangle();
95
 
        }
96
 
        table->PopItemBackground(GfxContext, nBackground);
97
 
    }
98
 
}
99
 
 
100
 
void DoubleValuatorPropertyItem::ComputePropertyLayout(int x, int y, RowHeader* row, const std::vector<header2>& column_vector)
101
 
{
102
 
    if(m_ItemGeometryVector.size() >= 2)
103
 
    {
104
 
        Geometry geo;
105
 
        geo = m_ItemGeometryVector[1];
106
 
        geo = geo.GetExpand(-PROPERTY_BORDER_X, -PROPERTY_BORDER_Y);
107
 
        setGeometry(geo);
108
 
    }
109
 
}
110
 
 
111
 
int DoubleValuatorPropertyItem::GetItemBestHeight()
112
 
{
113
 
    Size sz = GetMinimumSize();
114
 
    return sz.GetHeight() + 2 * PROPERTY_BORDER_Y;
115
 
}
116
 
 
117
 
DoubleValuatorPropertyItem* DoubleValuatorPropertyItem::CreateFromXML(const TiXmlElement* elementxml, NodeNetCom* parent, const char* Name, int id)
118
 
{
119
 
    double value = 0.0;
120
 
    double minvalue = 0.0;
121
 
    double maxvalue = 100.0;
122
 
    double step = 0.1;
123
 
    QueryNodeXMLDoubleAttribute(elementxml, TEXT("Value"),       &value,     -1);
124
 
    QueryNodeXMLDoubleAttribute(elementxml, TEXT("Value"),       &value,     -1);
125
 
    QueryNodeXMLDoubleAttribute(elementxml, TEXT("Step"),        &step,      -1);
126
 
    QueryNodeXMLDoubleAttribute(elementxml, TEXT("MinValue"),    &minvalue,  -1);
127
 
    QueryNodeXMLDoubleAttribute(elementxml, TEXT("MaxValue"),    &maxvalue,  -1);
128
 
 
129
 
    DoubleValuatorPropertyItem *node = new DoubleValuatorPropertyItem(Name, value, step, minvalue, maxvalue);
130
 
    node->SetID(id);
131
 
    return node;
132
 
}
133
 
 
134
 
TiXmlElement* DoubleValuatorPropertyItem::ToXML() const
135
 
{
136
 
    TiXmlElement* elementxml = NodeNetCom::ToXML();
137
 
    elementxml->SetDoubleAttribute(TEXT("Value"), GetValue());
138
 
    elementxml->SetDoubleAttribute(TEXT("Step"), GetStep());
139
 
    elementxml->SetDoubleAttribute(TEXT("MinValue"), GetMinValue());
140
 
    elementxml->SetDoubleAttribute(TEXT("MaxValue"), GetMaxValue());
141
 
    return elementxml;
142
 
}
143
 
 
144
 
bool DoubleValuatorPropertyItem::FromXML(const TiXmlElement* elementxml)
145
 
{
146
 
    double value = 0.0;
147
 
    double step = 0.0;
148
 
    double minvalue = 0.0;
149
 
    double maxvalue = 1.0;
150
 
    //double step = 1;
151
 
    QueryNodeXMLDoubleAttribute(elementxml, TEXT("Value"),       &value,     GetID());
152
 
    QueryNodeXMLDoubleAttribute(elementxml, TEXT("Step"),        &step,      GetID());
153
 
    QueryNodeXMLDoubleAttribute(elementxml, TEXT("MinValue"),    &minvalue,  GetID());
154
 
    QueryNodeXMLDoubleAttribute(elementxml, TEXT("MaxValue"),    &maxvalue,  GetID());
155
 
    //QueryNodeXMLIntAttribute(elementxml, "Step",        &step,      GetID());
156
 
    SetRange(minvalue, maxvalue);
157
 
    SetValue(value);
158
 
    SetStep(step);
159
 
    return NodeNetCom::FromXML(elementxml);
160
 
}
161
 
NAMESPACE_END_GUI
 
23
#include "Nux.h"
 
24
#include "PropertyList.h"
 
25
 
 
26
#include "ValuatorDouble.h"
 
27
#include "DoubleValuatorPropertyItem.h"
 
28
 
 
29
NAMESPACE_BEGIN_GUI
 
30
 
 
31
DoubleValuatorPropertyItem::DoubleValuatorPropertyItem(const TCHAR* name, float Value, float Step, float MinValue, float MaxValue)
 
32
:   SectionProperty(name, NODE_TYPE_DOUBLEVALUATOR)
 
33
{
 
34
    SetRange(MinValue, MaxValue);
 
35
    SetValue(Value);
 
36
    SetStep(Step);
 
37
    NODE_SIG_CONNECT(sigValueChanged, DoubleValuatorPropertyItem, RecvPropertyChange);
 
38
}
 
39
 
 
40
DoubleValuatorPropertyItem::~DoubleValuatorPropertyItem()
 
41
{
 
42
 
 
43
}
 
44
 
 
45
long DoubleValuatorPropertyItem::ProcessPropertyEvent(IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
 
46
{
 
47
    long ret = TraverseInfo;
 
48
 
 
49
    Geometry geo = m_ItemGeometryVector[1];
 
50
    if((ievent.e_event == INL_MOUSE_PRESSED) && geo.IsPointInside(ievent.e_x, ievent.e_y) == false)
 
51
    {
 
52
        // This will filter out mouse down event that happened in the item in the same row on the right.
 
53
        // This is necessary because the widget we are testing maybe larger that the table element where it resides.
 
54
        // 
 
55
        //      ____________________________________________________________
 
56
        //      | NAME      | WIDGET         |     :             |
 
57
        //      |___________|________________|_____:_____________|___________
 
58
        //                                         ^
 
59
        //                                         |
 
60
        //                                   end of widget
 
61
        //
 
62
        ret = ProcessEvent(ievent, TraverseInfo, eDoNotProcess | ProcessEventInfo);
 
63
    }
 
64
    else
 
65
    {
 
66
        ret = ProcessEvent(ievent, TraverseInfo, ProcessEventInfo);
 
67
    }
 
68
    return ret;
 
69
}
 
70
 
 
71
void DoubleValuatorPropertyItem::DrawProperty(GraphicsContext& GfxContext, TableCtrl* table, bool force_draw, Geometry geo, const BasePainter& Painter, 
 
72
                                              RowHeader* row, const std::vector<header2>& column_vector, Color ItemBackgroundColor)
 
73
{
 
74
    bool isSelected = (this == table->GetSelectedItem());
 
75
    if(isDirtyItem() || IsRedrawNeeded())
 
76
    {
 
77
        UINT nBackground = table->PushItemBackground(GfxContext, this);
 
78
        Painter.PaintTextLineStatic(GfxContext, GetFont(), m_FirstColumnUsableGeometry, row->item->GetName(), GetItemTextColor()); 
 
79
 
 
80
        if(m_ItemGeometryVector.size() >= 2)
 
81
        {
 
82
            Geometry geo2 = m_ItemGeometryVector[1];
 
83
            Geometry prop_geo;
 
84
            prop_geo.SetX(geo.x + geo.GetWidth());
 
85
            prop_geo.SetY(geo.y);
 
86
            prop_geo.SetWidth(column_vector[1].header.GetBaseWidth());
 
87
            prop_geo.SetHeight(geo.GetHeight());
 
88
 
 
89
            geo2.Expand(-PROPERTY_BORDER_X, -PROPERTY_BORDER_Y);
 
90
            GfxContext.PushClippingRectangle(geo2);
 
91
            GfxContext.PushClippingRectangle(prop_geo);
 
92
            ProcessDraw(GfxContext, true);
 
93
            GfxContext.PopClippingRectangle();
 
94
            GfxContext.PopClippingRectangle();
 
95
        }
 
96
        table->PopItemBackground(GfxContext, nBackground);
 
97
    }
 
98
}
 
99
 
 
100
void DoubleValuatorPropertyItem::ComputePropertyLayout(int x, int y, RowHeader* row, const std::vector<header2>& column_vector)
 
101
{
 
102
    if(m_ItemGeometryVector.size() >= 2)
 
103
    {
 
104
        Geometry geo;
 
105
        geo = m_ItemGeometryVector[1];
 
106
        geo = geo.GetExpand(-PROPERTY_BORDER_X, -PROPERTY_BORDER_Y);
 
107
        setGeometry(geo);
 
108
    }
 
109
}
 
110
 
 
111
int DoubleValuatorPropertyItem::GetItemBestHeight()
 
112
{
 
113
    Size sz = GetMinimumSize();
 
114
    return sz.GetHeight() + 2 * PROPERTY_BORDER_Y;
 
115
}
 
116
 
 
117
DoubleValuatorPropertyItem* DoubleValuatorPropertyItem::CreateFromXML(const TiXmlElement* elementxml, NodeNetCom* parent, const char* Name, int id)
 
118
{
 
119
    double value = 0.0;
 
120
    double minvalue = 0.0;
 
121
    double maxvalue = 100.0;
 
122
    double step = 0.1;
 
123
    QueryNodeXMLDoubleAttribute(elementxml, TEXT("Value"),       &value,     -1);
 
124
    QueryNodeXMLDoubleAttribute(elementxml, TEXT("Value"),       &value,     -1);
 
125
    QueryNodeXMLDoubleAttribute(elementxml, TEXT("Step"),        &step,      -1);
 
126
    QueryNodeXMLDoubleAttribute(elementxml, TEXT("MinValue"),    &minvalue,  -1);
 
127
    QueryNodeXMLDoubleAttribute(elementxml, TEXT("MaxValue"),    &maxvalue,  -1);
 
128
 
 
129
    DoubleValuatorPropertyItem *node = new DoubleValuatorPropertyItem(Name, value, step, minvalue, maxvalue);
 
130
    node->SetID(id);
 
131
    return node;
 
132
}
 
133
 
 
134
TiXmlElement* DoubleValuatorPropertyItem::ToXML() const
 
135
{
 
136
    TiXmlElement* elementxml = NodeNetCom::ToXML();
 
137
    elementxml->SetDoubleAttribute(TEXT("Value"), GetValue());
 
138
    elementxml->SetDoubleAttribute(TEXT("Step"), GetStep());
 
139
    elementxml->SetDoubleAttribute(TEXT("MinValue"), GetMinValue());
 
140
    elementxml->SetDoubleAttribute(TEXT("MaxValue"), GetMaxValue());
 
141
    return elementxml;
 
142
}
 
143
 
 
144
bool DoubleValuatorPropertyItem::FromXML(const TiXmlElement* elementxml)
 
145
{
 
146
    double value = 0.0;
 
147
    double step = 0.0;
 
148
    double minvalue = 0.0;
 
149
    double maxvalue = 1.0;
 
150
    //double step = 1;
 
151
    QueryNodeXMLDoubleAttribute(elementxml, TEXT("Value"),       &value,     GetID());
 
152
    QueryNodeXMLDoubleAttribute(elementxml, TEXT("Step"),        &step,      GetID());
 
153
    QueryNodeXMLDoubleAttribute(elementxml, TEXT("MinValue"),    &minvalue,  GetID());
 
154
    QueryNodeXMLDoubleAttribute(elementxml, TEXT("MaxValue"),    &maxvalue,  GetID());
 
155
    //QueryNodeXMLIntAttribute(elementxml, "Step",        &step,      GetID());
 
156
    SetRange(minvalue, maxvalue);
 
157
    SetValue(value);
 
158
    SetStep(step);
 
159
    return NodeNetCom::FromXML(elementxml);
 
160
}
 
161
NAMESPACE_END_GUI