2
* Copyright 2010 Inalogic Inc.
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.
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.
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/>
18
* Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
24
#include "NuxGraphics/GLTextureResourceManager.h"
28
#include "ActionItem.h"
29
#include "ToolButton.h"
34
ToolButton::ToolButton (const TCHAR *BitmapFilename, NUX_FILE_LINE_DECL)
35
: View (NUX_FILE_LINE_PARAM)
38
m_Texture = GetThreadGLDeviceFactory()->CreateSystemCapableTexture();
41
m_Texture->Update (BitmapFilename);
44
SetBaseString (TEXT ("ToolButton") );
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) );
54
SetMinimumSize (28, 28);
55
SetGeometry (Geometry (0, 0, 24, 24) );
58
ToolButton::~ToolButton()
60
m_Texture->UnReference ();
63
long ToolButton::ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
65
long ret = TraverseInfo;
67
ret = PostProcessEvent2 (ievent, ret, ProcessEventInfo);
71
void ToolButton::Draw (GraphicsEngine &GfxContext, bool force_draw)
73
Geometry base = GetGeometry();
75
if (IsMouseInside() && !HasMouseFocus() )
77
GetPainter().PaintBackground (GfxContext, base);
78
GetPainter().PaintShape (GfxContext, base, Color (COLOR_BACKGROUND_SECONDARY), eSHAPE_CORNER_ROUND2);
80
else if (HasMouseFocus() )
82
GetPainter().PaintBackground (GfxContext, base);
83
GetPainter().PaintShape (GfxContext, base, Color (0xFF2A2A2A), eSHAPE_CORNER_ROUND2);
87
GetPainter().PaintBackground (GfxContext, base);
88
GetPainter().PaintShape (GfxContext, base, Color (COLOR_BACKGROUND_PRIMARY), eSHAPE_CORNER_ROUND2);
92
GetPainter().Draw2DTextureAligned (GfxContext, m_Texture, base, TextureAlignmentStyle (eTACenter, eTACenter) );
95
void ToolButton::DrawContent (GraphicsEngine &GfxContext, bool force_draw)
100
void ToolButton::PostDraw (GraphicsEngine &GfxContext, bool force_draw)
105
void ToolButton::SetState (bool b)
110
void ToolButton::SetBitmap (const BaseTexture* Texture)
113
NUX_RETURN_IF_NULL (Texture);
116
m_Texture->UnReference ();
117
m_Texture = Texture->Clone();
120
void ToolButton::EmitClick (int x, int y, unsigned long button_flags, unsigned long key_flags)
123
m_ActionItem->Trigger();
126
void ToolButton::RecvMouseDoubleClick (int x, int y, unsigned long button_flags, unsigned long key_flags)
131
void ToolButton::RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags)
136
void ToolButton::RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags)
141
void ToolButton::RecvMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags)
146
void ToolButton::RecvMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags)
151
void ToolButton::SetAction (ActionItem *action)
153
m_ActionItem = action;