~canonical-dx-team/nux/nux.arch-cleanup

« back to all changes in this revision

Viewing changes to Nux/NumericValuator.cpp

  • Committer: Jay Taoko
  • Date: 2010-12-05 01:15:51 UTC
  • mfrom: (137.2.1 nux)
  • Revision ID: jay.taoko@canonical.com-20101205011551-706e6farovbwe23b
* Cleanup Nux Graphics
* Added GpuInfo
* Fixed end of line

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2010 Inalogic Inc.
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify it
5
 
 * under the terms of the GNU Lesser General Public License version 3, as
6
 
 * published by the  Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful, but
9
 
 * WITHOUT ANY WARRANTY; without even the implied warranties of
10
 
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11
 
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
12
 
 * License for more details.
13
 
 *
14
 
 * You should have received a copy of both the GNU Lesser General Public
15
 
 * License version 3 along with this program.  If not, see
16
 
 * <http://www.gnu.org/licenses/>
17
 
 *
18
 
 * Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
19
 
 *
20
 
 */
21
 
 
22
 
 
23
 
#include "Nux.h"
24
 
#include "HLayout.h"
25
 
#include "EditTextBox.h"
26
 
#include "DoubleValidator.h"
27
 
#include "NumericValuator.h"
28
 
 
29
 
namespace nux
30
 
{
31
 
 
32
 
  const int BTN_WIDTH = 14;
33
 
  const int BTN_HEIGHT = 14;
34
 
 
35
 
  NumericValuator::NumericValuator()
36
 
    :   m_DoubleValidator (0.0, 100.0)
37
 
    ,   m_Step (0.1f)
38
 
  {
39
 
    InitializeLayout();
40
 
    InitializeWidgets();
41
 
  }
42
 
 
43
 
  NumericValuator::~NumericValuator()
44
 
  {
45
 
    DestroyLayout();
46
 
  }
47
 
 
48
 
  void NumericValuator::InitializeWidgets()
49
 
  {
50
 
    m_EditLine->SetValidator (&m_DoubleValidator);
51
 
    m_EditLine->SetText (inlPrintf (TEXT ("%d"), m_DoubleValidator.GetMinimum() ) );
52
 
 
53
 
    m_EditLine->SetMinimumSize (2 * DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
54
 
    m_EditLine->SetGeometry (Geometry (0, 0, 2 * DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT) );
55
 
 
56
 
    m_SpinnerDownBtn->SetMinimumSize (BTN_WIDTH, BTN_HEIGHT);
57
 
    m_SpinnerDownBtn->SetGeometry (Geometry (0, 0, BTN_WIDTH, BTN_HEIGHT) );
58
 
    m_SpinnerUpBtn->SetMinimumSize (BTN_WIDTH, BTN_HEIGHT);
59
 
    m_SpinnerUpBtn->SetGeometry (Geometry (0, 0, BTN_WIDTH, BTN_HEIGHT) );
60
 
 
61
 
    hlayout->AddView (m_SpinnerDownBtn, 0);
62
 
    hlayout->AddView (m_EditLine, 1);
63
 
    hlayout->AddView (m_SpinnerUpBtn, 0);
64
 
    hlayout->SetContentDistribution (eStackLeft);
65
 
 
66
 
    SetCompositionLayout (hlayout);
67
 
  }
68
 
 
69
 
  void NumericValuator::InitializeLayout()
70
 
  {
71
 
    hlayout = new HLayout (TEXT (""), NUX_TRACKER_LOCATION);
72
 
  }
73
 
 
74
 
  void NumericValuator::DestroyLayout()
75
 
  {
76
 
  }
77
 
 
78
 
  long NumericValuator::ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
79
 
  {
80
 
    long ret = TraverseInfo;
81
 
    ret = m_SpinnerDownBtn->OnEvent (ievent, ret, ProcessEventInfo);
82
 
    ret = m_SpinnerUpBtn->OnEvent (ievent, ret, ProcessEventInfo);
83
 
    ret = m_EditLine->ProcessEvent (ievent, ret, ProcessEventInfo);
84
 
    ret = PostProcessEvent2 (ievent, ret, ProcessEventInfo);
85
 
    return ret;
86
 
  };
87
 
 
88
 
  void NumericValuator::Draw (GraphicsEngine &GfxContext, bool force_draw)
89
 
  {
90
 
    Geometry base = GetGeometry();
91
 
 
92
 
    GeometryPositioning gp (eHALeft, eVACenter);
93
 
    Geometry GeoPo = ComputeGeometryPositioning (m_SpinnerUpBtn->GetGeometry(), GetTheme().GetImageGeometry (eTRIANGLE_RIGHT), gp);
94
 
    GetPainter().PaintShape (GfxContext, GeoPo, Color (0xFFFFFFFF), eTRIANGLE_RIGHT);
95
 
 
96
 
    GeoPo = ComputeGeometryPositioning (m_SpinnerDownBtn->GetGeometry(), GetTheme().GetImageGeometry (eTRIANGLE_LEFT), gp);
97
 
    GetPainter().PaintShape (GfxContext, GeoPo, Color (0xFFFFFFFF), eTRIANGLE_LEFT);
98
 
 
99
 
    m_EditLine->NeedRedraw();
100
 
  }
101
 
 
102
 
  void NumericValuator::DrawContent (GraphicsEngine &GfxContext, bool force_draw)
103
 
  {
104
 
    m_EditLine->ProcessDraw (GfxContext, force_draw);
105
 
  }
106
 
 
107
 
  void NumericValuator::PostDraw (GraphicsEngine &GfxContext, bool force_draw)
108
 
  {
109
 
 
110
 
  }
111
 
 
112
 
  void NumericValuator::SetValue (float value)
113
 
  {
114
 
    m_fValue = value;
115
 
 
116
 
    if (m_fValue < m_DoubleValidator.GetMinimum() )
117
 
      m_fValue = m_DoubleValidator.GetMinimum();
118
 
 
119
 
    if (m_fValue > m_DoubleValidator.GetMaximum() )
120
 
      m_fValue = m_DoubleValidator.GetMaximum();
121
 
 
122
 
    m_EditLine->SetText (inlPrintf ("%f", m_fValue) );
123
 
  }
124
 
 
125
 
  float NumericValuator::GetValue() const
126
 
  {
127
 
    return m_fValue;
128
 
  }
129
 
 
130
 
  void NumericValuator::SetStep (float f)
131
 
  {
132
 
    m_Step = f;
133
 
  }
134
 
 
135
 
  float NumericValuator::GetStep()
136
 
  {
137
 
    return m_Step;
138
 
  }
139
 
 
140
 
 
141
 
  void NumericValuator::ImplementIncrementBtn()
142
 
  {
143
 
    SetValue (m_fValue + m_Step);
144
 
    sigIncrement.emit();
145
 
    sigValueChanged.emit (m_fValue);
146
 
 
147
 
    if (m_fValue < m_DoubleValidator.GetMaximum() )
148
 
    {
149
 
      m_UpTimerHandler = GetTimer().AddTimerHandler (100, m_UpTimerCallback, 0);
150
 
      NeedRedraw();
151
 
    }
152
 
  }
153
 
 
154
 
  void NumericValuator::ImplementDecrementBtn()
155
 
  {
156
 
    SetValue (m_fValue - m_Step);
157
 
    sigDecrement.emit();
158
 
    sigValueChanged.emit (m_fValue);
159
 
 
160
 
    if (m_fValue > m_DoubleValidator.GetMinimum() )
161
 
    {
162
 
      m_DownTimerHandler = GetTimer().AddTimerHandler (100, m_DownTimerCallback, 0);
163
 
      NeedRedraw();
164
 
    }
165
 
  }
166
 
 
167
 
  void NumericValuator::ImplementValidateEntry()
168
 
  {
169
 
    double ret = 0;
170
 
    ret = CharToDouble (m_EditLine->GetCleanText().GetTCharPtr() );
171
 
    {
172
 
      m_fValue = ret;
173
 
 
174
 
      if (m_fValue < m_DoubleValidator.GetMinimum() )
175
 
      {
176
 
        m_fValue = m_DoubleValidator.GetMinimum();
177
 
        m_EditLine->SetText (inlPrintf ("%f", m_fValue) );
178
 
      }
179
 
 
180
 
      if (m_fValue > m_DoubleValidator.GetMaximum() )
181
 
      {
182
 
        m_fValue = m_DoubleValidator.GetMaximum();
183
 
        m_EditLine->SetText (inlPrintf ("%f", m_fValue) );
184
 
      }
185
 
    }
186
 
//     else
187
 
//     {
188
 
//         m_EditLine->SetText(inlPrintf("%f", m_fValue));
189
 
//     }
190
 
  }
191
 
 
192
 
}
 
1
/*
 
2
 * Copyright 2010 Inalogic Inc.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser General Public License version 3, as
 
6
 * published by the  Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 
11
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
 
12
 * License for more details.
 
13
 *
 
14
 * You should have received a copy of both the GNU Lesser General Public
 
15
 * License version 3 along with this program.  If not, see
 
16
 * <http://www.gnu.org/licenses/>
 
17
 *
 
18
 * Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
 
19
 *
 
20
 */
 
21
 
 
22
 
 
23
#include "Nux.h"
 
24
#include "HLayout.h"
 
25
#include "EditTextBox.h"
 
26
#include "DoubleValidator.h"
 
27
#include "NumericValuator.h"
 
28
 
 
29
namespace nux
 
30
{
 
31
 
 
32
  const int BTN_WIDTH = 14;
 
33
  const int BTN_HEIGHT = 14;
 
34
 
 
35
  NumericValuator::NumericValuator()
 
36
    :   m_DoubleValidator (0.0, 100.0)
 
37
    ,   m_Step (0.1f)
 
38
  {
 
39
    InitializeLayout();
 
40
    InitializeWidgets();
 
41
  }
 
42
 
 
43
  NumericValuator::~NumericValuator()
 
44
  {
 
45
    DestroyLayout();
 
46
  }
 
47
 
 
48
  void NumericValuator::InitializeWidgets()
 
49
  {
 
50
    m_EditLine->SetValidator (&m_DoubleValidator);
 
51
    m_EditLine->SetText (inlPrintf (TEXT ("%d"), m_DoubleValidator.GetMinimum() ) );
 
52
 
 
53
    m_EditLine->SetMinimumSize (2 * DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
 
54
    m_EditLine->SetGeometry (Geometry (0, 0, 2 * DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT) );
 
55
 
 
56
    m_SpinnerDownBtn->SetMinimumSize (BTN_WIDTH, BTN_HEIGHT);
 
57
    m_SpinnerDownBtn->SetGeometry (Geometry (0, 0, BTN_WIDTH, BTN_HEIGHT) );
 
58
    m_SpinnerUpBtn->SetMinimumSize (BTN_WIDTH, BTN_HEIGHT);
 
59
    m_SpinnerUpBtn->SetGeometry (Geometry (0, 0, BTN_WIDTH, BTN_HEIGHT) );
 
60
 
 
61
    hlayout->AddView (m_SpinnerDownBtn, 0);
 
62
    hlayout->AddView (m_EditLine, 1);
 
63
    hlayout->AddView (m_SpinnerUpBtn, 0);
 
64
    hlayout->SetContentDistribution (eStackLeft);
 
65
 
 
66
    SetCompositionLayout (hlayout);
 
67
  }
 
68
 
 
69
  void NumericValuator::InitializeLayout()
 
70
  {
 
71
    hlayout = new HLayout (TEXT (""), NUX_TRACKER_LOCATION);
 
72
  }
 
73
 
 
74
  void NumericValuator::DestroyLayout()
 
75
  {
 
76
  }
 
77
 
 
78
  long NumericValuator::ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
 
79
  {
 
80
    long ret = TraverseInfo;
 
81
    ret = m_SpinnerDownBtn->OnEvent (ievent, ret, ProcessEventInfo);
 
82
    ret = m_SpinnerUpBtn->OnEvent (ievent, ret, ProcessEventInfo);
 
83
    ret = m_EditLine->ProcessEvent (ievent, ret, ProcessEventInfo);
 
84
    ret = PostProcessEvent2 (ievent, ret, ProcessEventInfo);
 
85
    return ret;
 
86
  };
 
87
 
 
88
  void NumericValuator::Draw (GraphicsEngine &GfxContext, bool force_draw)
 
89
  {
 
90
    Geometry base = GetGeometry();
 
91
 
 
92
    GeometryPositioning gp (eHALeft, eVACenter);
 
93
    Geometry GeoPo = ComputeGeometryPositioning (m_SpinnerUpBtn->GetGeometry(), GetTheme().GetImageGeometry (eTRIANGLE_RIGHT), gp);
 
94
    GetPainter().PaintShape (GfxContext, GeoPo, Color (0xFFFFFFFF), eTRIANGLE_RIGHT);
 
95
 
 
96
    GeoPo = ComputeGeometryPositioning (m_SpinnerDownBtn->GetGeometry(), GetTheme().GetImageGeometry (eTRIANGLE_LEFT), gp);
 
97
    GetPainter().PaintShape (GfxContext, GeoPo, Color (0xFFFFFFFF), eTRIANGLE_LEFT);
 
98
 
 
99
    m_EditLine->NeedRedraw();
 
100
  }
 
101
 
 
102
  void NumericValuator::DrawContent (GraphicsEngine &GfxContext, bool force_draw)
 
103
  {
 
104
    m_EditLine->ProcessDraw (GfxContext, force_draw);
 
105
  }
 
106
 
 
107
  void NumericValuator::PostDraw (GraphicsEngine &GfxContext, bool force_draw)
 
108
  {
 
109
 
 
110
  }
 
111
 
 
112
  void NumericValuator::SetValue (float value)
 
113
  {
 
114
    m_fValue = value;
 
115
 
 
116
    if (m_fValue < m_DoubleValidator.GetMinimum() )
 
117
      m_fValue = m_DoubleValidator.GetMinimum();
 
118
 
 
119
    if (m_fValue > m_DoubleValidator.GetMaximum() )
 
120
      m_fValue = m_DoubleValidator.GetMaximum();
 
121
 
 
122
    m_EditLine->SetText (inlPrintf ("%f", m_fValue) );
 
123
  }
 
124
 
 
125
  float NumericValuator::GetValue() const
 
126
  {
 
127
    return m_fValue;
 
128
  }
 
129
 
 
130
  void NumericValuator::SetStep (float f)
 
131
  {
 
132
    m_Step = f;
 
133
  }
 
134
 
 
135
  float NumericValuator::GetStep()
 
136
  {
 
137
    return m_Step;
 
138
  }
 
139
 
 
140
 
 
141
  void NumericValuator::ImplementIncrementBtn()
 
142
  {
 
143
    SetValue (m_fValue + m_Step);
 
144
    sigIncrement.emit();
 
145
    sigValueChanged.emit (m_fValue);
 
146
 
 
147
    if (m_fValue < m_DoubleValidator.GetMaximum() )
 
148
    {
 
149
      m_UpTimerHandler = GetTimer().AddTimerHandler (100, m_UpTimerCallback, 0);
 
150
      NeedRedraw();
 
151
    }
 
152
  }
 
153
 
 
154
  void NumericValuator::ImplementDecrementBtn()
 
155
  {
 
156
    SetValue (m_fValue - m_Step);
 
157
    sigDecrement.emit();
 
158
    sigValueChanged.emit (m_fValue);
 
159
 
 
160
    if (m_fValue > m_DoubleValidator.GetMinimum() )
 
161
    {
 
162
      m_DownTimerHandler = GetTimer().AddTimerHandler (100, m_DownTimerCallback, 0);
 
163
      NeedRedraw();
 
164
    }
 
165
  }
 
166
 
 
167
  void NumericValuator::ImplementValidateEntry()
 
168
  {
 
169
    double ret = 0;
 
170
    ret = CharToDouble (m_EditLine->GetCleanText().GetTCharPtr() );
 
171
    {
 
172
      m_fValue = ret;
 
173
 
 
174
      if (m_fValue < m_DoubleValidator.GetMinimum() )
 
175
      {
 
176
        m_fValue = m_DoubleValidator.GetMinimum();
 
177
        m_EditLine->SetText (inlPrintf ("%f", m_fValue) );
 
178
      }
 
179
 
 
180
      if (m_fValue > m_DoubleValidator.GetMaximum() )
 
181
      {
 
182
        m_fValue = m_DoubleValidator.GetMaximum();
 
183
        m_EditLine->SetText (inlPrintf ("%f", m_fValue) );
 
184
      }
 
185
    }
 
186
//     else
 
187
//     {
 
188
//         m_EditLine->SetText(inlPrintf("%f", m_fValue));
 
189
//     }
 
190
  }
 
191
 
 
192
}