Back to index

nux  3.0.0
ToolButton.cpp
Go to the documentation of this file.
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 char *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("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   void ToolButton::Draw(GraphicsEngine &graphics_engine, bool force_draw)
00064   {
00065     Geometry base = GetGeometry();
00066 
00067     if (IsMouseInside() && !IsMouseOwner())
00068     {
00069       GetPainter().PaintBackground(graphics_engine, base);
00070       GetPainter().PaintShape(graphics_engine, base, Color(COLOR_BACKGROUND_SECONDARY),  eSHAPE_CORNER_ROUND2);
00071     }
00072     else if (IsMouseOwner())
00073     {
00074       GetPainter().PaintBackground(graphics_engine, base);
00075       GetPainter().PaintShape(graphics_engine, base, Color(0xFF2A2A2A),  eSHAPE_CORNER_ROUND2);
00076     }
00077     else
00078     {
00079       GetPainter().PaintBackground(graphics_engine, base);
00080       GetPainter().PaintShape(graphics_engine, base, Color(COLOR_BACKGROUND_PRIMARY),  eSHAPE_CORNER_ROUND2);
00081     }
00082 
00083     if (m_Texture)
00084       GetPainter().Draw2DTextureAligned(graphics_engine, m_Texture, base, TextureAlignmentStyle(eTACenter, eTACenter));
00085   }
00086 
00087   void ToolButton::DrawContent(GraphicsEngine &graphics_engine, bool force_draw)
00088   {
00089 
00090   }
00091 
00092   void ToolButton::PostDraw(GraphicsEngine &graphics_engine, bool force_draw)
00093   {
00094 
00095   }
00096 
00097   void ToolButton::SetState(bool b)
00098   {
00099 
00100   }
00101 
00102   void ToolButton::SetBitmap(const BaseTexture* Texture)
00103   {
00104     nuxAssert(Texture);
00105     NUX_RETURN_IF_NULL(Texture);
00106 
00107     if (m_Texture)
00108       m_Texture->UnReference();
00109     m_Texture = Texture->Clone();
00110   }
00111 
00112   void ToolButton::EmitClick(int x, int y, unsigned long button_flags, unsigned long key_flags)
00113   {
00114     sigClick.emit();
00115     if (m_ActionItem)
00116       m_ActionItem->Trigger();
00117   }
00118 
00119   void ToolButton::RecvMouseDoubleClick(int x, int y, unsigned long button_flags, unsigned long key_flags)
00120   {
00121     QueueDraw();
00122   }
00123 
00124   void ToolButton::RecvMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags)
00125   {
00126     QueueDraw();
00127   }
00128 
00129   void ToolButton::RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags)
00130   {
00131     QueueDraw();
00132   }
00133 
00134   void ToolButton::RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags)
00135   {
00136     QueueDraw();
00137   }
00138 
00139   void ToolButton::RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags)
00140   {
00141     QueueDraw();
00142   }
00143 
00144   void ToolButton::SetAction(ActionItem *action)
00145   {
00146     m_ActionItem = action;
00147   }
00148 
00149 }