2017-02-21 12:31:19 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-07-26 23:47:26 +00:00
|
|
|
* Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-02-21 12:31:19 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COLOR_SWATCH__H_
|
|
|
|
#define COLOR_SWATCH__H_
|
|
|
|
|
2020-10-26 02:33:14 +00:00
|
|
|
#include <wx/bitmap.h>
|
|
|
|
#include <wx/gdicmn.h>
|
|
|
|
#include <wx/panel.h>
|
|
|
|
#include <wx/statbmp.h>
|
|
|
|
#include <wx/window.h>
|
|
|
|
|
|
|
|
#include <functional>
|
2017-02-21 12:31:19 +00:00
|
|
|
|
|
|
|
#include <gal/color4d.h>
|
2021-06-11 09:17:52 +00:00
|
|
|
#include <dialogs/dialog_color_picker.h>
|
2017-02-21 12:31:19 +00:00
|
|
|
|
2020-08-17 12:55:56 +00:00
|
|
|
enum SWATCH_SIZE
|
|
|
|
{
|
|
|
|
SWATCH_SMALL,
|
|
|
|
SWATCH_MEDIUM,
|
2020-08-20 01:11:22 +00:00
|
|
|
SWATCH_LARGE,
|
2022-07-01 18:37:55 +00:00
|
|
|
SWATCH_EXPAND
|
2020-08-17 12:55:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const static wxSize SWATCH_SIZE_SMALL_DU( 8, 6 );
|
|
|
|
const static wxSize SWATCH_SIZE_MEDIUM_DU( 24, 10 );
|
|
|
|
const static wxSize SWATCH_SIZE_LARGE_DU( 24, 16 );
|
|
|
|
const static wxSize CHECKERBOARD_SIZE_DU( 3, 3 );
|
|
|
|
|
|
|
|
|
2017-02-21 12:31:19 +00:00
|
|
|
/**
|
2021-07-26 23:47:26 +00:00
|
|
|
* A simple color swatch of the kind used to set layer colors.
|
2017-02-21 12:31:19 +00:00
|
|
|
*/
|
|
|
|
class COLOR_SWATCH: public wxPanel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a COLOR_SWATCH
|
|
|
|
*
|
|
|
|
* @param aParent parent window
|
|
|
|
* @param aColor initial swatch color
|
|
|
|
* @param aID id to use when sending swatch events
|
|
|
|
*/
|
2021-07-26 23:47:26 +00:00
|
|
|
COLOR_SWATCH( wxWindow* aParent, const KIGFX::COLOR4D& aColor, int aID,
|
|
|
|
const KIGFX::COLOR4D& aBackground, const KIGFX::COLOR4D& aDefault,
|
|
|
|
SWATCH_SIZE aSwatchType );
|
2020-03-08 02:18:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* constructor for wxFormBuilder
|
|
|
|
*/
|
|
|
|
COLOR_SWATCH( wxWindow *aParent, wxWindowID aId, const wxPoint &aPos = wxDefaultPosition,
|
|
|
|
const wxSize &aSize = wxDefaultSize, long aStyle = 0 );
|
2017-02-21 12:31:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the current swatch color directly.
|
|
|
|
*/
|
2021-07-26 23:47:26 +00:00
|
|
|
void SetSwatchColor( const KIGFX::COLOR4D& aColor, bool aSendEvent );
|
2017-02-21 12:31:19 +00:00
|
|
|
|
2020-07-30 01:16:07 +00:00
|
|
|
/**
|
|
|
|
* Sets the color that will be chosen with the "Reset to Default" button in the chooser
|
|
|
|
*/
|
2021-07-26 23:47:26 +00:00
|
|
|
void SetDefaultColor( const KIGFX::COLOR4D& aColor );
|
2020-07-30 01:16:07 +00:00
|
|
|
|
2018-01-03 22:38:25 +00:00
|
|
|
/**
|
|
|
|
* Set the swatch background color.
|
|
|
|
*/
|
2021-07-26 23:47:26 +00:00
|
|
|
void SetSwatchBackground( const KIGFX::COLOR4D& aBackground );
|
2018-01-03 22:38:25 +00:00
|
|
|
|
2021-06-11 09:17:52 +00:00
|
|
|
/**
|
|
|
|
* Fetch a reference to the user colors list.
|
|
|
|
*/
|
|
|
|
void SetUserColors( CUSTOM_COLORS_LIST* aUserColors ) { m_userColors = aUserColors; }
|
|
|
|
|
2017-02-21 12:31:19 +00:00
|
|
|
/**
|
|
|
|
* @return the current swatch color
|
|
|
|
*/
|
|
|
|
KIGFX::COLOR4D GetSwatchColor() const;
|
|
|
|
|
2021-10-09 20:22:09 +00:00
|
|
|
/**
|
|
|
|
* Updates the window ID of this control and its children
|
|
|
|
* @param aId new Window ID to set
|
|
|
|
*/
|
|
|
|
void SetWindowID( wxWindowID aId )
|
|
|
|
{
|
|
|
|
SetId( aId );
|
|
|
|
m_swatch->SetId( aId );
|
|
|
|
}
|
|
|
|
|
2017-02-21 12:31:19 +00:00
|
|
|
/**
|
|
|
|
* Prompt for a new colour, using the colour picker dialog.
|
|
|
|
*
|
|
|
|
* A colour change event will be sent if it's set.
|
|
|
|
*/
|
|
|
|
void GetNewSwatchColor();
|
|
|
|
|
2020-10-15 01:57:36 +00:00
|
|
|
void SetReadOnly( bool aReadOnly = true ) { m_readOnly = aReadOnly; }
|
|
|
|
bool IsReadOnly() const { return m_readOnly; }
|
|
|
|
|
2021-06-11 09:17:52 +00:00
|
|
|
void SetSupportsOpacity( bool aSupportsOpacity ) { m_supportsOpacity = aSupportsOpacity; }
|
|
|
|
|
2020-10-15 01:57:36 +00:00
|
|
|
/// Registers a handler for when the user tries to interact with a read-only swatch
|
|
|
|
void SetReadOnlyCallback( std::function<void()> aCallback ) { m_readOnlyCallback = aCallback; }
|
|
|
|
|
2022-11-06 00:34:13 +00:00
|
|
|
/// Respond to a change in the OS's DarkMode setting.
|
|
|
|
void OnDarkModeToggle();
|
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
static wxBitmap MakeBitmap( const KIGFX::COLOR4D& aColor, const KIGFX::COLOR4D& aBackground,
|
|
|
|
const wxSize& aSize, const wxSize& aCheckerboardSize,
|
|
|
|
const KIGFX::COLOR4D& aCheckerboardBackground );
|
2018-05-04 14:43:59 +00:00
|
|
|
|
2023-06-29 03:54:27 +00:00
|
|
|
static void RenderToDC( wxDC* aDC, const KIGFX::COLOR4D& aColor,
|
|
|
|
const KIGFX::COLOR4D& aBackground, const wxRect& aRect,
|
|
|
|
const wxSize& aCheckerboardSize,
|
|
|
|
const KIGFX::COLOR4D& aCheckerboardBackground );
|
|
|
|
|
2017-02-21 12:31:19 +00:00
|
|
|
private:
|
2020-03-08 02:18:45 +00:00
|
|
|
void setupEvents();
|
2017-02-21 12:31:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Pass unwanted events on to listeners of this object
|
|
|
|
*/
|
2020-11-07 21:40:56 +00:00
|
|
|
void rePostEvent( wxEvent& aEvent );
|
2017-02-21 12:31:19 +00:00
|
|
|
|
2021-06-11 09:17:52 +00:00
|
|
|
KIGFX::COLOR4D m_color;
|
|
|
|
KIGFX::COLOR4D m_background;
|
|
|
|
KIGFX::COLOR4D m_default;
|
|
|
|
CUSTOM_COLORS_LIST* m_userColors;
|
2019-08-21 20:57:53 +00:00
|
|
|
|
2021-06-11 09:17:52 +00:00
|
|
|
wxStaticBitmap* m_swatch;
|
2020-03-08 02:18:45 +00:00
|
|
|
|
2021-06-11 09:17:52 +00:00
|
|
|
wxSize m_size;
|
|
|
|
wxSize m_checkerboardSize;
|
|
|
|
KIGFX::COLOR4D m_checkerboardBg;
|
2020-10-15 01:57:36 +00:00
|
|
|
|
|
|
|
/// A read-only swatch won't show the color chooser dialog but otherwise works normally
|
2021-06-11 09:17:52 +00:00
|
|
|
bool m_readOnly;
|
2020-10-15 01:57:36 +00:00
|
|
|
std::function<void()> m_readOnlyCallback;
|
2021-06-11 09:17:52 +00:00
|
|
|
|
|
|
|
/// If opacity is not supported the color chooser dialog will be displayed without it
|
|
|
|
bool m_supportsOpacity;
|
2017-02-21 12:31:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-07-26 23:47:26 +00:00
|
|
|
* Event signaling a swatch has changed color
|
2017-02-21 12:31:19 +00:00
|
|
|
*/
|
|
|
|
wxDECLARE_EVENT(COLOR_SWATCH_CHANGED, wxCommandEvent);
|
|
|
|
|
|
|
|
#endif // COLOR_SWATCH__H_
|