~om26er/ubuntu/oneiric/nux/sru-819721

« back to all changes in this revision

Viewing changes to Nux/ToolButton.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-11-18 19:17:32 UTC
  • Revision ID: james.westby@ubuntu.com-20101118191732-rn35790vekj6o4my
Tags: upstream-0.9.4
ImportĀ upstreamĀ versionĀ 0.9.4

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 "NuxGraphics/GLTextureResourceManager.h"
 
25
#include "Layout.h"
 
26
#include "HLayout.h"
 
27
#include "VLayout.h"
 
28
#include "ActionItem.h"
 
29
#include "ToolButton.h"
 
30
 
 
31
namespace nux
 
32
{
 
33
 
 
34
  ToolButton::ToolButton (const TCHAR *BitmapFilename, NUX_FILE_LINE_DECL)
 
35
    :   View (NUX_FILE_LINE_PARAM)
 
36
    ,   m_ActionItem (0)
 
37
  {
 
38
    m_Texture = GetThreadGLDeviceFactory()->CreateSystemCapableTexture();
 
39
 
 
40
    if (BitmapFilename)
 
41
      m_Texture->Update (BitmapFilename);
 
42
 
 
43
    // Set Original State
 
44
    SetBaseString (TEXT ("ToolButton") );
 
45
 
 
46
    // Set Signals
 
47
    OnMouseClick.connect (sigc::mem_fun (this, &ToolButton::EmitClick) );
 
48
    OnMouseDoubleClick.connect (sigc::mem_fun (this, &ToolButton::RecvMouseDoubleClick) );
 
49
    OnMouseDown.connect (sigc::mem_fun (this, &ToolButton::RecvMouseDown) );
 
50
    OnMouseUp.connect (sigc::mem_fun (this, &ToolButton::RecvMouseUp) );
 
51
    OnMouseEnter.connect (sigc::mem_fun (this, &ToolButton::RecvMouseEnter) );
 
52
    OnMouseLeave.connect (sigc::mem_fun (this, &ToolButton::RecvMouseLeave) );
 
53
 
 
54
    SetMinimumSize (28, 28);
 
55
    SetGeometry (Geometry (0, 0, 24, 24) );
 
56
  }
 
57
 
 
58
  ToolButton::~ToolButton()
 
59
  {
 
60
    m_Texture->UnReference ();
 
61
  }
 
62
 
 
63
  long ToolButton::ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
 
64
  {
 
65
    long ret = TraverseInfo;
 
66
 
 
67
    ret = PostProcessEvent2 (ievent, ret, ProcessEventInfo);
 
68
    return ret;
 
69
  }
 
70
 
 
71
  void ToolButton::Draw (GraphicsEngine &GfxContext, bool force_draw)
 
72
  {
 
73
    Geometry base = GetGeometry();
 
74
 
 
75
    if (IsMouseInside() && !HasMouseFocus() )
 
76
    {
 
77
      GetPainter().PaintBackground (GfxContext, base);
 
78
      GetPainter().PaintShape (GfxContext, base, Color (COLOR_BACKGROUND_SECONDARY),  eSHAPE_CORNER_ROUND2);
 
79
    }
 
80
    else if (HasMouseFocus() )
 
81
    {
 
82
      GetPainter().PaintBackground (GfxContext, base);
 
83
      GetPainter().PaintShape (GfxContext, base, Color (0xFF2A2A2A),  eSHAPE_CORNER_ROUND2);
 
84
    }
 
85
    else
 
86
    {
 
87
      GetPainter().PaintBackground (GfxContext, base);
 
88
      GetPainter().PaintShape (GfxContext, base, Color (COLOR_BACKGROUND_PRIMARY),  eSHAPE_CORNER_ROUND2);
 
89
    }
 
90
 
 
91
    if (m_Texture)
 
92
      GetPainter().Draw2DTextureAligned (GfxContext, m_Texture, base, TextureAlignmentStyle (eTACenter, eTACenter) );
 
93
  }
 
94
 
 
95
  void ToolButton::DrawContent (GraphicsEngine &GfxContext, bool force_draw)
 
96
  {
 
97
 
 
98
  }
 
99
 
 
100
  void ToolButton::PostDraw (GraphicsEngine &GfxContext, bool force_draw)
 
101
  {
 
102
 
 
103
  }
 
104
 
 
105
  void ToolButton::SetState (bool b)
 
106
  {
 
107
 
 
108
  }
 
109
 
 
110
  void ToolButton::SetBitmap (const BaseTexture* Texture)
 
111
  {
 
112
    nuxAssert (Texture);
 
113
    NUX_RETURN_IF_NULL (Texture);
 
114
 
 
115
    if (m_Texture)
 
116
      m_Texture->UnReference ();
 
117
    m_Texture = Texture->Clone();
 
118
  }
 
119
 
 
120
  void ToolButton::EmitClick (int x, int y, unsigned long button_flags, unsigned long key_flags)
 
121
  {
 
122
    sigClick.emit();
 
123
    m_ActionItem->Trigger();
 
124
  }
 
125
 
 
126
  void ToolButton::RecvMouseDoubleClick (int x, int y, unsigned long button_flags, unsigned long key_flags)
 
127
  {
 
128
    NeedRedraw();
 
129
  }
 
130
 
 
131
  void ToolButton::RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags)
 
132
  {
 
133
    NeedRedraw();
 
134
  }
 
135
 
 
136
  void ToolButton::RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags)
 
137
  {
 
138
    NeedRedraw();
 
139
  }
 
140
 
 
141
  void ToolButton::RecvMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags)
 
142
  {
 
143
    NeedRedraw();
 
144
  }
 
145
 
 
146
  void ToolButton::RecvMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags)
 
147
  {
 
148
    NeedRedraw();
 
149
  }
 
150
 
 
151
  void ToolButton::SetAction (ActionItem *action)
 
152
  {
 
153
    m_ActionItem = action;
 
154
  }
 
155
 
 
156
}