⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 colorpickercontrol.cpp

📁 Powerful and Portable GPS application -- support Linux, Windows, Windows CE GPS navigation and Map m
💻 CPP
字号:
/* *  Roadnav *  ColorPickerControl.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////// This file contains a control that allows the user to select a color. ////// The selected color is shown in the control./////////////////////////////////////////////////////////////////////////////////#ifdef HAVE_CONFIG_H#  include <config.h>#endif#ifdef _MSC_VER#pragma warning(disable: 4786)#endif#include "ColorPickerControl.h"#include <wx/wx.h>#include <wx/colordlg.h>//////////////////////////////////////////////////////////////////////////////////// MapControl events/////////////////////////////////////////////////////////////////////////////////BEGIN_EVENT_TABLE(ColorPickerControl, wxControl)	EVT_PAINT(ColorPickerControl::OnPaint)	EVT_LEFT_UP(ColorPickerControl::OnLeftUp)END_EVENT_TABLE()IMPLEMENT_DYNAMIC_CLASS(ColorPickerControl, wxControl);//////////////////////////////////////////////////////////////////////////////////// \brief ColorPickerControl constructor/////////////////////////////////////////////////////////////////////////////////ColorPickerControl::ColorPickerControl(){}//////////////////////////////////////////////////////////////////////////////////// \brief ColorPickerControl constructor/////////////////////////////////////////////////////////////////////////////////ColorPickerControl::ColorPickerControl(wxWindow* parent, wxWindowID id, wxPoint pt, wxSize sz){	Create(parent, id, pt, sz, wxSUNKEN_BORDER | wxTAB_TRAVERSAL);		m_clrSelection.Set(0, 0, 0);}//////////////////////////////////////////////////////////////////////////////////// \brief Repaint the control/////////////////////////////////////////////////////////////////////////////////void ColorPickerControl::OnPaint(wxPaintEvent& event){	wxPaintDC dc(this);	wxRect rect;	wxBrush brOld;	wxPen penOld;		if (IsEnabled())	{		wxBrush brThis(m_clrSelection, wxSOLID);		wxPen penThis(m_clrSelection, 1, wxSOLID);				rect = GetClientRect();				brOld = dc.GetBrush();		dc.SetBrush(brThis);				penOld = dc.GetPen();		dc.SetPen(penThis);				dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);	}	else	{		wxBrush brThis(*wxWHITE, wxSOLID);		wxPen penThis(*wxWHITE, 1, wxSOLID);		wxPen penRedLine(*wxRED, 2, wxSOLID);				rect = GetClientRect();				brOld = dc.GetBrush();		dc.SetBrush(brThis);				penOld = dc.GetPen();		dc.SetPen(penThis);				dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);				dc.SetPen(penRedLine);		dc.DrawLine(0, 0, rect.width, rect.height);	}		dc.SetBrush(brOld);	dc.SetPen(penOld);}//////////////////////////////////////////////////////////////////////////////////// \brief Left mouse button released - user wants to change the color////// When the left mouse button is pressed in the control, a wxColourDialog/// is shown to let the user pick a new color. The new color is then/// stored in m_clrSelection, and the parent is notified with a/// wxEVT_COMMAND_BUTTON_CLICKED event./////////////////////////////////////////////////////////////////////////////////void ColorPickerControl::OnLeftUp(wxMouseEvent& event){	wxColourDialog dlgColor(this);		dlgColor.GetColourData().SetColour(m_clrSelection);		if (dlgColor.ShowModal() == wxID_OK)	{		m_clrSelection = dlgColor.GetColourData().GetColour();				Refresh();		wxCommandEvent ev(wxEVT_COMMAND_BUTTON_CLICKED, GetId());			GetParent()->AddPendingEvent(ev);	}}//////////////////////////////////////////////////////////////////////////////////// \brief Assign a color to this control and refresh the control so the new/// color is shown./////////////////////////////////////////////////////////////////////////////////void ColorPickerControl::SetColor(wxColour clrColor){	m_clrSelection = clrColor;		Refresh();}//////////////////////////////////////////////////////////////////////////////////// \brief Retrieve the color selected/////////////////////////////////////////////////////////////////////////////////wxColour ColorPickerControl::GetColor(){	return m_clrSelection;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -