nux-1.14.0
ToolButton.cpp
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #include "Nux.h"
00024 #include "NuxGraphics/GLTextureResourceManager.h"
00025 #include "Layout.h"
00026 #include "HLayout.h"
00027 #include "VLayout.h"
00028 #include "ActionItem.h"
00029 #include "ToolButton.h"
00030 
00031 namespace nux
00032 {
00033 
00034   ToolButton::ToolButton (const TCHAR *BitmapFilename, NUX_FILE_LINE_DECL)
00035     :   View (NUX_FILE_LINE_PARAM)
00036     ,   m_ActionItem (0)
00037   {
00038     m_Texture = GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableTexture();
00039 
00040     if (BitmapFilename)
00041       m_Texture->Update (BitmapFilename);
00042 
00043     // Set Original State
00044     SetBaseString (TEXT ("ToolButton") );
00045 
00046     // Set Signals
00047     mouse_click.connect (sigc::mem_fun (this, &ToolButton::EmitClick) );
00048     mouse_double_click.connect (sigc::mem_fun (this, &ToolButton::RecvMouseDoubleClick) );
00049     mouse_down.connect (sigc::mem_fun (this, &ToolButton::RecvMouseDown) );
00050     mouse_up.connect (sigc::mem_fun (this, &ToolButton::RecvMouseUp) );
00051     mouse_enter.connect (sigc::mem_fun (this, &ToolButton::RecvMouseEnter) );
00052     mouse_leave.connect (sigc::mem_fun (this, &ToolButton::RecvMouseLeave) );
00053 
00054     SetMinimumSize (28, 28);
00055     SetGeometry (Geometry (0, 0, 24, 24) );
00056   }
00057 
00058   ToolButton::~ToolButton()
00059   {
00060     m_Texture->UnReference ();
00061   }
00062 
00063   long ToolButton::ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
00064   {
00065     long ret = TraverseInfo;
00066 
00067     ret = PostProcessEvent2 (ievent, ret, ProcessEventInfo);
00068     return ret;
00069   }
00070 
00071   void ToolButton::Draw (GraphicsEngine &GfxContext, bool force_draw)
00072   {
00073     Geometry base = GetGeometry();
00074 
00075     if (IsMouseInside() && !IsMouseOwner() )
00076     {
00077       GetPainter().PaintBackground (GfxContext, base);
00078       GetPainter().PaintShape (GfxContext, base, Color (COLOR_BACKGROUND_SECONDARY),  eSHAPE_CORNER_ROUND2);
00079     }
00080     else if (IsMouseOwner() )
00081     {
00082       GetPainter().PaintBackground (GfxContext, base);
00083       GetPainter().PaintShape (GfxContext, base, Color (0xFF2A2A2A),  eSHAPE_CORNER_ROUND2);
00084     }
00085     else
00086     {
00087       GetPainter().PaintBackground (GfxContext, base);
00088       GetPainter().PaintShape (GfxContext, base, Color (COLOR_BACKGROUND_PRIMARY),  eSHAPE_CORNER_ROUND2);
00089     }
00090 
00091     if (m_Texture)
00092       GetPainter().Draw2DTextureAligned (GfxContext, m_Texture, base, TextureAlignmentStyle (eTACenter, eTACenter) );
00093   }
00094 
00095   void ToolButton::DrawContent (GraphicsEngine &GfxContext, bool force_draw)
00096   {
00097 
00098   }
00099 
00100   void ToolButton::PostDraw (GraphicsEngine &GfxContext, bool force_draw)
00101   {
00102 
00103   }
00104 
00105   void ToolButton::SetState (bool b)
00106   {
00107 
00108   }
00109 
00110   void ToolButton::SetBitmap (const BaseTexture* Texture)
00111   {
00112     nuxAssert (Texture);
00113     NUX_RETURN_IF_NULL (Texture);
00114 
00115     if (m_Texture)
00116       m_Texture->UnReference ();
00117     m_Texture = Texture->Clone();
00118   }
00119 
00120   void ToolButton::EmitClick (int x, int y, unsigned long button_flags, unsigned long key_flags)
00121   {
00122     sigClick.emit();
00123     if(m_ActionItem)
00124       m_ActionItem->Trigger();
00125   }
00126 
00127   void ToolButton::RecvMouseDoubleClick (int x, int y, unsigned long button_flags, unsigned long key_flags)
00128   {
00129     QueueDraw();
00130   }
00131 
00132   void ToolButton::RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags)
00133   {
00134     QueueDraw();
00135   }
00136 
00137   void ToolButton::RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags)
00138   {
00139     QueueDraw();
00140   }
00141 
00142   void ToolButton::RecvMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags)
00143   {
00144     QueueDraw();
00145   }
00146 
00147   void ToolButton::RecvMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags)
00148   {
00149     QueueDraw();
00150   }
00151 
00152   void ToolButton::SetAction (ActionItem *action)
00153   {
00154     m_ActionItem = action;
00155   }
00156 
00157 }
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends