~hikiko/nux/arb-srgba-shader

« back to all changes in this revision

Viewing changes to Nux/ActionItem.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 "NuxGraphics/GLTextureResourceManager.h"
25
 
#include "ActionItem.h"
26
 
 
27
 
NAMESPACE_BEGIN_GUI
28
 
 
29
 
IMPLEMENT_ROOT_OBJECT_TYPE(ActionItem);
30
 
 
31
 
ActionItem::ActionItem(const TCHAR* label, int UserValue)
32
 
:   m_IsActivated(true)
33
 
,   m_Menu(0)
34
 
,   m_Label(TEXT(""))
35
 
,   m_Enable(true)
36
 
,   m_UserValue(UserValue)
37
 
{
38
 
    SetLabel(label);
39
 
}
40
 
 
41
 
ActionItem::~ActionItem()
42
 
{
43
 
 
44
 
}
45
 
 
46
 
void ActionItem::DrawAsMenuItem(GraphicsContext& GfxContext, CoreArea& area, bool is_highlighted, bool draw_icone)
47
 
{
48
 
    Geometry geo = area.GetGeometry();
49
 
    Geometry icon_geo(0, 0, 20, 20);
50
 
    Geometry text_geo = geo;
51
 
 
52
 
    text_geo.OffsetPosition(24, 2);
53
 
    text_geo.OffsetSize(2 * 24, 2 * 2);
54
 
 
55
 
    icon_geo.SetX(geo.x+ 2);
56
 
    icon_geo.SetY(geo.y+ 2);
57
 
 
58
 
    const TCHAR* label = GetLabel();
59
 
 
60
 
    if(is_highlighted)
61
 
    {
62
 
        gPainter.Paint2DQuadColor(GfxContext, geo, Color(COLOR_FOREGROUND_SECONDARY));
63
 
    }
64
 
 
65
 
    gPainter.Draw2DTextureAligned(GfxContext, &m_Icon, icon_geo, TextureAlignmentStyle(eTACenter, eTACenter));
66
 
 
67
 
    gPainter.PaintTextLineStatic(GfxContext, GFont, text_geo, std::string(label), Color(0xFF000000), eAlignTextLeft);
68
 
}
69
 
 
70
 
void ActionItem::DrawAsToolButton(GraphicsContext& GfxContext, CoreArea& area)
71
 
{
72
 
    Geometry base = area.GetGeometry();
73
 
    if(area.HasMouseFocus())
74
 
    {
75
 
        if(area.IsMouseInside())
76
 
        {
77
 
            gPainter.PaintShape(GfxContext, base, Color(COLOR_BACKGROUND_SECONDARY),  eSHAPE_CORNER_ROUND2);
78
 
            gPainter.PaintShape(GfxContext, base, Color(COLOR_BLACK),  eSTROKE_CORNER_ROUND2);
79
 
         }
80
 
        else
81
 
        {
82
 
            gPainter.PaintShape(GfxContext, base, Color(COLOR_FOREGROUND_PRIMARY),  eSHAPE_CORNER_ROUND2);
83
 
            gPainter.PaintShape(GfxContext, base, Color(COLOR_BLACK),  eSTROKE_CORNER_ROUND2);
84
 
        }
85
 
    }
86
 
    else
87
 
    {
88
 
        if(area.IsMouseInside() && (!area.MouseFocusOnOtherArea()))
89
 
        {
90
 
            gPainter.PaintShape(GfxContext, base, Color(COLOR_FOREGROUND_PRIMARY),  eSHAPE_CORNER_ROUND2);
91
 
             gPainter.PaintShape(GfxContext, base, Color(COLOR_BLACK),  eSTROKE_CORNER_ROUND2);
92
 
        }
93
 
        else
94
 
        {
95
 
            gPainter.PaintShape(GfxContext, base, Color(COLOR_BACKGROUND_SECONDARY),  eSHAPE_CORNER_ROUND2);
96
 
            gPainter.PaintShape(GfxContext, base, Color(COLOR_BLACK),  eSTROKE_CORNER_ROUND2);
97
 
        }
98
 
    }
99
 
    
100
 
    gPainter.Draw2DTextureAligned(GfxContext, &m_Icon, base, TextureAlignmentStyle(eTACenter, eTACenter));
101
 
}
102
 
 
103
 
void ActionItem::Activate(bool b)
104
 
{
105
 
    m_IsActivated = b;
106
 
}
107
 
 
108
 
void ActionItem::Trigger() const
109
 
{
110
 
    sigAction.emit();
111
 
}
112
 
 
113
 
void ActionItem::Enable(bool b)
114
 
{
115
 
    m_Enable = b;
116
 
}
117
 
 
118
 
bool ActionItem::isEnabled() const
119
 
{
120
 
    return m_Enable;
121
 
}
122
 
 
123
 
void ActionItem::SetLabel(const TCHAR* label)
124
 
{
125
 
    m_Label = label;
126
 
}
127
 
 
128
 
const TCHAR* ActionItem::GetLabel() const
129
 
{
130
 
    return m_Label.GetTCharPtr();
131
 
}
132
 
 
133
 
void ActionItem::SetIcon(const NTexture2D& icon)
134
 
{
135
 
    m_Icon = icon;
136
 
}
137
 
 
138
 
NTexture2D& ActionItem::GetIcon()
139
 
{
140
 
    return m_Icon;
141
 
}
142
 
 
143
 
//void ActionItem::SetMenu(Menu* menu)
144
 
//{
145
 
//    m_Menu = menu;
146
 
//}
147
 
//Menu* ActionItem::GetMenu() const
148
 
//{
149
 
//    return m_Menu;
150
 
//}
151
 
 
152
 
 
153
 
NAMESPACE_END_GUI
 
23
#include "Nux.h"
 
24
#include "NuxGraphics/GLTextureResourceManager.h"
 
25
#include "ActionItem.h"
 
26
 
 
27
NAMESPACE_BEGIN_GUI
 
28
 
 
29
IMPLEMENT_ROOT_OBJECT_TYPE(ActionItem);
 
30
 
 
31
ActionItem::ActionItem(const TCHAR* label, int UserValue)
 
32
:   m_IsActivated(true)
 
33
,   m_Menu(0)
 
34
,   m_Label(TEXT(""))
 
35
,   m_Enable(true)
 
36
,   m_UserValue(UserValue)
 
37
{
 
38
    SetLabel(label);
 
39
}
 
40
 
 
41
ActionItem::~ActionItem()
 
42
{
 
43
 
 
44
}
 
45
 
 
46
void ActionItem::DrawAsMenuItem(GraphicsContext& GfxContext, CoreArea& area, bool is_highlighted, bool draw_icone)
 
47
{
 
48
    Geometry geo = area.GetGeometry();
 
49
    Geometry icon_geo(0, 0, 20, 20);
 
50
    Geometry text_geo = geo;
 
51
 
 
52
    text_geo.OffsetPosition(24, 2);
 
53
    text_geo.OffsetSize(2 * 24, 2 * 2);
 
54
 
 
55
    icon_geo.SetX(geo.x+ 2);
 
56
    icon_geo.SetY(geo.y+ 2);
 
57
 
 
58
    const TCHAR* label = GetLabel();
 
59
 
 
60
    if(is_highlighted)
 
61
    {
 
62
        gPainter.Paint2DQuadColor(GfxContext, geo, Color(COLOR_FOREGROUND_SECONDARY));
 
63
    }
 
64
 
 
65
    gPainter.Draw2DTextureAligned(GfxContext, &m_Icon, icon_geo, TextureAlignmentStyle(eTACenter, eTACenter));
 
66
 
 
67
    gPainter.PaintTextLineStatic(GfxContext, GFont, text_geo, std::string(label), Color(0xFF000000), eAlignTextLeft);
 
68
}
 
69
 
 
70
void ActionItem::DrawAsToolButton(GraphicsContext& GfxContext, CoreArea& area)
 
71
{
 
72
    Geometry base = area.GetGeometry();
 
73
    if(area.HasMouseFocus())
 
74
    {
 
75
        if(area.IsMouseInside())
 
76
        {
 
77
            gPainter.PaintShape(GfxContext, base, Color(COLOR_BACKGROUND_SECONDARY),  eSHAPE_CORNER_ROUND2);
 
78
            gPainter.PaintShape(GfxContext, base, Color(COLOR_BLACK),  eSTROKE_CORNER_ROUND2);
 
79
         }
 
80
        else
 
81
        {
 
82
            gPainter.PaintShape(GfxContext, base, Color(COLOR_FOREGROUND_PRIMARY),  eSHAPE_CORNER_ROUND2);
 
83
            gPainter.PaintShape(GfxContext, base, Color(COLOR_BLACK),  eSTROKE_CORNER_ROUND2);
 
84
        }
 
85
    }
 
86
    else
 
87
    {
 
88
        if(area.IsMouseInside() && (!area.MouseFocusOnOtherArea()))
 
89
        {
 
90
            gPainter.PaintShape(GfxContext, base, Color(COLOR_FOREGROUND_PRIMARY),  eSHAPE_CORNER_ROUND2);
 
91
             gPainter.PaintShape(GfxContext, base, Color(COLOR_BLACK),  eSTROKE_CORNER_ROUND2);
 
92
        }
 
93
        else
 
94
        {
 
95
            gPainter.PaintShape(GfxContext, base, Color(COLOR_BACKGROUND_SECONDARY),  eSHAPE_CORNER_ROUND2);
 
96
            gPainter.PaintShape(GfxContext, base, Color(COLOR_BLACK),  eSTROKE_CORNER_ROUND2);
 
97
        }
 
98
    }
 
99
    
 
100
    gPainter.Draw2DTextureAligned(GfxContext, &m_Icon, base, TextureAlignmentStyle(eTACenter, eTACenter));
 
101
}
 
102
 
 
103
void ActionItem::Activate(bool b)
 
104
{
 
105
    m_IsActivated = b;
 
106
}
 
107
 
 
108
void ActionItem::Trigger() const
 
109
{
 
110
    sigAction.emit();
 
111
}
 
112
 
 
113
void ActionItem::Enable(bool b)
 
114
{
 
115
    m_Enable = b;
 
116
}
 
117
 
 
118
bool ActionItem::isEnabled() const
 
119
{
 
120
    return m_Enable;
 
121
}
 
122
 
 
123
void ActionItem::SetLabel(const TCHAR* label)
 
124
{
 
125
    m_Label = label;
 
126
}
 
127
 
 
128
const TCHAR* ActionItem::GetLabel() const
 
129
{
 
130
    return m_Label.GetTCharPtr();
 
131
}
 
132
 
 
133
void ActionItem::SetIcon(const NTexture2D& icon)
 
134
{
 
135
    m_Icon = icon;
 
136
}
 
137
 
 
138
NTexture2D& ActionItem::GetIcon()
 
139
{
 
140
    return m_Icon;
 
141
}
 
142
 
 
143
//void ActionItem::SetMenu(Menu* menu)
 
144
//{
 
145
//    m_Menu = menu;
 
146
//}
 
147
//Menu* ActionItem::GetMenu() const
 
148
//{
 
149
//    return m_Menu;
 
150
//}
 
151
 
 
152
 
 
153
NAMESPACE_END_GUI