📄 wxbitmapbuttonnobackground.cpp
字号:
/* * Roadnav * wxBitmapButtonNoBackground.cpp * * Copyright (c) 2004 - 2007 Richard L. Lynch <rllynch@users.sourceforge.net> * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public License * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ ///////////////////////////////////////////////////////////////////////////////// \file////// Contains wxBitmapButtonNoBackground - a class similar to wxBitmapButton,/// but one that does not draw any sort of background and is therefore/// suitable for arbitrary shaped buttons./////////////////////////////////////////////////////////////////////////////////#ifdef HAVE_CONFIG_H# include <config.h>#endif#ifdef _MSC_VER#pragma warning(disable: 4786)#endif#include <wx/wx.h>#include "wxBitmapButtonNoBackground.h"BEGIN_EVENT_TABLE(wxBitmapButtonNoBackground, wxControl) EVT_ERASE_BACKGROUND(wxBitmapButtonNoBackground::OnEraseBackground) EVT_PAINT(wxBitmapButtonNoBackground::OnPaint) EVT_LEFT_UP(wxBitmapButtonNoBackground::OnLeftUp) EVT_LEFT_DOWN(wxBitmapButtonNoBackground::OnLeftDown) EVT_LEAVE_WINDOW(wxBitmapButtonNoBackground::OnMouseLeaveWindow)END_EVENT_TABLE()//////////////////////////////////////////////////////////////////////////////////// \brief Constructor - takes same parameters as wxBitmapButton./////////////////////////////////////////////////////////////////////////////////wxBitmapButtonNoBackground::wxBitmapButtonNoBackground( wxWindow* parent, wxWindowID id, const wxBitmap& bitmap, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name){ m_pParent = parent; m_iID = id; m_bmpDefault = bitmap; m_bmpSelected = bitmap; m_bSelected = false; m_bActive = false; Create( parent, id, pos, size, #if wxCHECK_VERSION(2, 5, 0) wxNO_BORDER#else 0#endif );}//////////////////////////////////////////////////////////////////////////////////// \brief Change bitmap to use when button is depressed./////////////////////////////////////////////////////////////////////////////////void wxBitmapButtonNoBackground::SetBitmapSelected(const wxBitmap& bitmap){ m_bmpSelected = bitmap;}//////////////////////////////////////////////////////////////////////////////////// \brief Change bitmap to use when button is active./////////////////////////////////////////////////////////////////////////////////void wxBitmapButtonNoBackground::SetBitmapActive(const wxBitmap & bitmap){ m_bmpActive = bitmap;}//////////////////////////////////////////////////////////////////////////////////// \brief Handles erase background message - does nothing./////////////////////////////////////////////////////////////////////////////////void wxBitmapButtonNoBackground::OnEraseBackground(wxEraseEvent& event){}//////////////////////////////////////////////////////////////////////////////////// \brief Paint button./////////////////////////////////////////////////////////////////////////////////void wxBitmapButtonNoBackground::OnPaint(wxPaintEvent& event){ wxPaintDC dc(this); if (m_bSelected) dc.DrawBitmap(m_bmpSelected, 0, 0, true); else if (m_bActive) dc.DrawBitmap(m_bmpActive, 0, 0, true); else dc.DrawBitmap(m_bmpDefault, 0, 0, true);}//////////////////////////////////////////////////////////////////////////////////// \brief Handles left mouse button being released. Trigger button if/// mouse was depressed inside button./////////////////////////////////////////////////////////////////////////////////void wxBitmapButtonNoBackground::OnLeftUp(wxMouseEvent& event){ if (m_bSelected) { wxCommandEvent ev(wxEVT_COMMAND_BUTTON_CLICKED, m_iID); m_bSelected = false; Refresh(); m_pParent->AddPendingEvent(ev); }}//////////////////////////////////////////////////////////////////////////////////// \brief Handles left mouse button being pressed./////////////////////////////////////////////////////////////////////////////////void wxBitmapButtonNoBackground::OnLeftDown(wxMouseEvent& event){ m_bSelected = true; Refresh();}//////////////////////////////////////////////////////////////////////////////////// \brief Mouse has left the button - deselect button./////////////////////////////////////////////////////////////////////////////////void wxBitmapButtonNoBackground::OnMouseLeaveWindow(wxMouseEvent& event){ if (m_bSelected) { m_bSelected = false; Refresh(); }}//////////////////////////////////////////////////////////////////////////////////// \brief Update active state/////////////////////////////////////////////////////////////////////////////////void wxBitmapButtonNoBackground::SetActive(bool bActive){ if (m_bActive != bActive) { m_bActive = bActive; Refresh(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -