Make the color picker dialog update the color instantly when used from the style editor, rather than waiting for the dialog to be closed, and revert if the dialog is cancelled. Updates #355.

Originally committed to SVN as r4469.
This commit is contained in:
Thomas Goyne 2010-06-09 08:14:50 +00:00
parent ea577f8245
commit d278c99652
6 changed files with 390 additions and 531 deletions

View file

@ -34,9 +34,6 @@
/// @ingroup custom_control
///
////////////
// Includes
#include "config.h"
#ifndef AGI_PRE
@ -47,42 +44,20 @@
#include "config.h"
#include "dialog_colorpicker.h"
/// @brief Constructor
/// @param parent
/// @param id
/// @param size
/// @param col
///
ColourButton::ColourButton(wxWindow* parent, wxWindowID id, const wxSize& size, wxColour col) {
// Variables
linkColour = NULL;
// Create base
wxBitmapButton::Create(parent,id,wxBitmap(size.GetWidth(),size.GetHeight()),wxDefaultPosition,wxDefaultSize,wxBU_AUTODRAW);
bmp = GetBitmapLabel();
// Set colour
ColourButton::ColourButton(wxWindow* parent, wxWindowID id, const wxSize& size, wxColour col)
: wxBitmapButton(parent, id, wxBitmap(size))
, bmp(GetBitmapLabel())
{
SetColour(col);
// Connect to click event
Connect(GetId(),wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(ColourButton::OnClick));
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ColourButton::OnClick, this);
}
/// @brief Destructor
///
ColourButton::~ColourButton() {
}
/// @brief Set colour
/// @param col
///
/// @brief Callback for the color picker dialog
/// @param col New color
void ColourButton::SetColour(wxColour col) {
// Set colour
colour = col;
// Draw colour
@ -92,44 +67,24 @@ void ColourButton::SetColour(wxColour col) {
dc.SetBrush(wxBrush(colour));
dc.DrawRectangle(0,0,bmp.GetWidth(),bmp.GetHeight());
}
// Set bitmap
SetBitmapLabel(bmp);
// Set link colour
if (linkColour) *linkColour = colour;
// Trigger a click event on this as some stuff relies on that to know
// when the color has changed
wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
evt.SetClientData(this);
AddPendingEvent(evt);
}
/// @brief Get Colour
/// @return
///
wxColour ColourButton::GetColour() {
return colour;
}
/// @brief Click
/// @brief Click handler
/// @param event
///
void ColourButton::OnClick(wxCommandEvent &event) {
DialogColorPicker dlg(GetParent(), colour);
if (dlg.ShowModal() == wxID_OK) {
SetColour(dlg.GetColor());
}
event.Skip();
if (event.GetClientData() != this)
GetColorFromUser<ColourButton, &ColourButton::SetColour>(GetParent(), colour, this);
else
event.Skip();
}
/// @brief Set Link Colour
/// @param col
///
void ColourButton::SetLinkColour(wxColour *col) {
linkColour = col;
if (linkColour) SetColour(*linkColour);
}

View file

@ -34,9 +34,6 @@
/// @ingroup custom_control
///
////////////
// Includes
#ifndef AGI_PRE
#include <wx/bmpbuttn.h>
#endif
@ -49,25 +46,14 @@
/// DOCME
class ColourButton: public wxBitmapButton {
private:
/// DOCME
wxBitmap bmp;
/// DOCME
wxColour colour;
/// DOCME
wxColour *linkColour;
wxBitmap bmp; /// The button's bitmap label
wxColour colour; /// The current colour
void OnClick(wxCommandEvent &event);
void SetColour(wxColour colour);
public:
ColourButton(wxWindow* parent, wxWindowID id, const wxSize& size, wxColour col=wxColour(0,0,0));
~ColourButton();
void SetColour(wxColour colour);
wxColour GetColour();
void SetLinkColour(wxColour *colour);
};

View file

@ -38,19 +38,27 @@
#ifndef AGI_PRE
#include <stdio.h>
#include <vector>
#include <wx/bitmap.h>
#include <wx/button.h>
#include <wx/choice.h>
#include <wx/clipbrd.h>
#include <wx/dataobj.h>
#include <wx/dcclient.h>
#include <wx/dcmemory.h>
#include <wx/dcscreen.h>
#include <wx/dialog.h>
#include <wx/event.h>
#include <wx/gbsizer.h>
#include <wx/image.h>
#include <wx/settings.h>
#include <wx/sizer.h>
#include <wx/spinctrl.h>
#include <wx/statbmp.h>
#include <wx/statbox.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/tokenzr.h>
#endif
@ -64,6 +72,330 @@
#include "options.h"
#include "utils.h"
/// DOCME
/// @class ColorPickerSpectrum
/// @brief DOCME
///
/// DOCME
class ColorPickerSpectrum : public wxControl {
public:
/// DOCME
enum PickerDirection {
/// DOCME
HorzVert,
/// DOCME
Horz,
/// DOCME
Vert
};
private:
/// DOCME
/// DOCME
int x, y;
/// DOCME
wxBitmap *background;
/// DOCME
PickerDirection direction;
void OnPaint(wxPaintEvent &evt);
void OnMouse(wxMouseEvent &evt);
public:
ColorPickerSpectrum(wxWindow *parent, wxWindowID id, wxBitmap *_background, int xx, int yy, PickerDirection _direction, wxSize _size);
void GetXY(int &xx, int &yy);
void SetXY(int xx, int yy);
void SetBackground(wxBitmap *new_background);
DECLARE_EVENT_TABLE()
};
DECLARE_EVENT_TYPE(wxSPECTRUM_CHANGE, -1)
/// DOCME
/// @class ColorPickerRecent
/// @brief DOCME
///
/// DOCME
class ColorPickerRecent : public wxControl {
private:
/// DOCME
/// DOCME
int rows, cols;
/// DOCME
int cellsize;
/// DOCME
wxPoint internal_control_offset;
/// DOCME
std::vector<wxColour> colors;
/// DOCME
bool background_valid;
/// DOCME
wxBitmap background;
void OnClick(wxMouseEvent &evt);
void OnPaint(wxPaintEvent &evt);
void OnSize(wxSizeEvent &evt);
public:
ColorPickerRecent(wxWindow *parent, wxWindowID id, int _cols, int _rows, int _cellsize);
void LoadFromString(const wxString &recent_string);
wxString StoreToString();
void AddColor(wxColour color);
/// @brief DOCME
/// @param n
/// @return
///
wxColour GetColor(int n) { return colors.at(n); }
DECLARE_EVENT_TABLE()
};
DECLARE_EVENT_TYPE(wxRECENT_SELECT, -1)
/// DOCME
/// @class ColorPickerScreenDropper
/// @brief DOCME
///
/// DOCME
class ColorPickerScreenDropper : public wxControl {
private:
/// DOCME
wxBitmap capture;
/// DOCME
/// DOCME
int resx, resy;
/// DOCME
int magnification;
/// DOCME
bool integrated_dropper;
void OnMouse(wxMouseEvent &evt);
void OnPaint(wxPaintEvent &evt);
public:
ColorPickerScreenDropper(wxWindow *parent, wxWindowID id, int _resx, int _resy, int _magnification, bool _integrated_dropper);
void DropFromScreenXY(int x, int y);
DECLARE_EVENT_TABLE()
};
DECLARE_EVENT_TYPE(wxDROPPER_SELECT, -1)
/// DOCME
/// @class DialogColorPicker
/// @brief DOCME
///
/// DOCME
class DialogColorPicker : public wxDialog {
private:
/// DOCME
wxColour cur_color;
/// DOCME
bool updating_controls;
/// DOCME
bool spectrum_dirty;
/// DOCME
ColorPickerSpectrum *spectrum;
/// DOCME
ColorPickerSpectrum *slider;
/// DOCME
wxChoice *colorspace_choice;
/// DOCME
static const int slider_width = 10; // width in pixels of the color slider control
/// DOCME
wxSpinCtrl *rgb_input[3];
/// DOCME
wxBitmap *rgb_spectrum[3]; // x/y spectrum bitmap where color "i" is excluded from
/// DOCME
wxBitmap *rgb_slider[3]; // z spectrum for color "i"
/// DOCME
wxSpinCtrl *hsl_input[3];
/// DOCME
wxBitmap *hsl_spectrum; // h/s spectrum
/// DOCME
wxBitmap *hsl_slider; // l spectrum
/// DOCME
wxSpinCtrl *hsv_input[3];
/// DOCME
wxBitmap *hsv_spectrum; // s/v spectrum
/// DOCME
wxBitmap *hsv_slider; // h spectrum
/// DOCME
wxBitmap eyedropper_bitmap;
/// DOCME
wxPoint eyedropper_grab_point;
/// DOCME
bool eyedropper_is_grabbed;
/// DOCME
wxTextCtrl *ass_input; // ASS hex format input
/// DOCME
wxTextCtrl *html_input; // HTML hex format input
/// DOCME
wxStaticBitmap *preview_box;
/// DOCME
wxBitmap preview_bitmap;
/// DOCME
ColorPickerRecent *recent_box;
/// DOCME
ColorPickerScreenDropper *screen_dropper;
/// DOCME
wxStaticBitmap *screen_dropper_icon;
void UpdateFromRGB(); // Update all other controls as a result of modifying an RGB control
void UpdateFromHSL(); // Update all other controls as a result of modifying an HSL control
void UpdateFromHSV(); // Update all other controls as a result of modifying an HSV control
void UpdateFromASS(); // Update all other controls as a result of modifying the ASS format control
void UpdateFromHTML(); // Update all other controls as a result of modifying the HTML format control
void UpdateSpectrumDisplay(); // Redraw the spectrum display
wxBitmap *MakeGBSpectrum();
wxBitmap *MakeRBSpectrum();
wxBitmap *MakeRGSpectrum();
wxBitmap *MakeHSSpectrum();
wxBitmap *MakeSVSpectrum();
void OnSpinRGB(wxSpinEvent &evt);
void OnSpinHSL(wxSpinEvent &evt);
void OnSpinHSV(wxSpinEvent &evt);
void OnChangeRGB(wxCommandEvent &evt);
void OnChangeHSL(wxCommandEvent &evt);
void OnChangeHSV(wxCommandEvent &evt);
void OnChangeASS(wxCommandEvent &evt);
void OnChangeHTML(wxCommandEvent &evt);
void OnChangeMode(wxCommandEvent &evt);
void OnSpectrumChange(wxCommandEvent &evt);
void OnSliderChange(wxCommandEvent &evt);
void OnRecentSelect(wxCommandEvent &evt); // also handles dropper pick
void OnRGBAdjust(wxCommandEvent &evt);
void OnDropperMouse(wxMouseEvent &evt);
void OnMouse(wxMouseEvent &evt);
/// DOCME
/// DOCME
static int lastx, lasty;
ColorCallback callback;
void *callbackUserdata;
public:
DialogColorPicker(wxWindow *parent, wxColour initial_color, ColorCallback callback = NULL, void *userdata = NULL);
~DialogColorPicker();
void SetColor(wxColour new_color);
wxColour GetColor();
DECLARE_EVENT_TABLE()
};
enum {
/// DOCME
SELECTOR_SPECTRUM = 4000,
/// DOCME
SELECTOR_SLIDER,
/// DOCME
SELECTOR_MODE,
/// DOCME
SELECTOR_RGB_R,
/// DOCME
SELECTOR_RGB_G,
/// DOCME
SELECTOR_RGB_B,
/// DOCME
SELECTOR_HSL_H,
/// DOCME
SELECTOR_HSL_S,
/// DOCME
SELECTOR_HSL_L,
/// DOCME
SELECTOR_HSV_H,
/// DOCME
SELECTOR_HSV_S,
/// DOCME
SELECTOR_HSV_V,
/// DOCME
SELECTOR_ASS_INPUT,
/// DOCME
SELECTOR_HTML_INPUT,
/// DOCME
SELECTOR_RECENT,
/// DOCME
SELECTOR_DROPPER,
/// DOCME
SELECTOR_DROPPER_PICK,
/// DOCME
BUTTON_RGBADJUST
};
#ifdef WIN32
@ -75,12 +407,9 @@
#define STATIC_BORDER_FLAG wxSIMPLE_BORDER
#endif
/// DOCME
static const int spectrum_horz_vert_arrow_size = 4;
/// @brief DOCME
/// @param parent
/// @param id
@ -103,7 +432,6 @@ ColorPickerSpectrum::ColorPickerSpectrum(wxWindow *parent, wxWindowID id, wxBitm
SetMinSize(GetSize());
}
/// @brief DOCME
/// @param xx
/// @param yy
@ -114,7 +442,6 @@ void ColorPickerSpectrum::GetXY(int &xx, int &yy)
yy = y;
}
/// @brief DOCME
/// @param xx
/// @param yy
@ -126,7 +453,6 @@ void ColorPickerSpectrum::SetXY(int xx, int yy)
Refresh(true);
}
/// @brief DOCME
/// @param new_background
/// @return
@ -145,7 +471,6 @@ END_EVENT_TABLE()
DEFINE_EVENT_TYPE(wxSPECTRUM_CHANGE)
/// @brief DOCME
/// @param evt
/// @return
@ -208,7 +533,6 @@ void ColorPickerSpectrum::OnPaint(wxPaintEvent &evt)
dc.DrawRectangle(0, 0, background->GetWidth()+2, background->GetHeight()+2);
}
/// @brief DOCME
/// @param evt
/// @return
@ -245,9 +569,6 @@ void ColorPickerSpectrum::OnMouse(wxMouseEvent &evt)
}
}
/// @brief DOCME
/// @param parent
/// @param id
@ -271,7 +592,6 @@ ColorPickerRecent::ColorPickerRecent(wxWindow *parent, wxWindowID id, int _cols,
SetCursor(*wxCROSS_CURSOR);
}
/// @brief DOCME
/// @param recent_string
///
@ -292,7 +612,6 @@ void ColorPickerRecent::LoadFromString(const wxString &recent_string)
background_valid = false;
}
/// @brief DOCME
/// @return
///
@ -307,7 +626,6 @@ wxString ColorPickerRecent::StoreToString()
return res;
}
/// @brief DOCME
/// @param color
///
@ -335,7 +653,6 @@ END_EVENT_TABLE()
DEFINE_EVENT_TYPE(wxRECENT_SELECT)
/// @brief DOCME
/// @param evt
/// @return
@ -356,7 +673,6 @@ void ColorPickerRecent::OnClick(wxMouseEvent &evt)
}
}
/// @brief DOCME
/// @param evt
///
@ -393,7 +709,6 @@ void ColorPickerRecent::OnPaint(wxPaintEvent &evt)
pdc.DrawBitmap(background, 0, 0, false);
}
/// @brief DOCME
/// @param evt
///
@ -406,9 +721,6 @@ void ColorPickerRecent::OnSize(wxSizeEvent &evt)
Refresh();
}
/// @brief DOCME
/// @param parent
/// @param id
@ -440,7 +752,6 @@ END_EVENT_TABLE()
DEFINE_EVENT_TYPE(wxDROPPER_SELECT)
/// @brief DOCME
/// @param evt
///
@ -478,7 +789,6 @@ void ColorPickerScreenDropper::OnMouse(wxMouseEvent &evt)
}
}
/// @brief DOCME
/// @param evt
///
@ -513,8 +823,6 @@ void ColorPickerScreenDropper::OnPaint(wxPaintEvent &evt)
}
}
/// @brief DOCME
/// @param x
/// @param y
@ -532,32 +840,30 @@ void ColorPickerScreenDropper::DropFromScreenXY(int x, int y)
Refresh(false);
}
/// @brief DOCME
/// @param parent
/// @param original
/// @return
///
wxColour GetColorFromUser(wxWindow *parent, wxColour original)
wxColour GetColorFromUser(wxWindow *parent, wxColour original, ColorCallback callback, void* userdata)
{
DialogColorPicker dialog(parent, original);
DialogColorPicker dialog(parent, original, callback, userdata);
if (dialog.ShowModal() == wxID_OK) {
return dialog.GetColor();
} else {
if (callback) callback(userdata, original);
return original;
}
}
/// @brief Constructor
/// @param parent
/// @param initial_color
///
DialogColorPicker::DialogColorPicker(wxWindow *parent, wxColour initial_color)
DialogColorPicker::DialogColorPicker(wxWindow *parent, wxColour initial_color, ColorCallback callback, void* userdata)
: wxDialog(parent, -1, _("Select Colour"), wxDefaultPosition, wxDefaultSize)
, callback(callback)
, callbackUserdata(userdata)
{
rgb_spectrum[0] =
rgb_spectrum[1] =
@ -779,8 +1085,6 @@ DialogColorPicker::DialogColorPicker(wxWindow *parent, wxColour initial_color)
screen_dropper_icon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(DialogColorPicker::OnDropperMouse), 0, this);
}
/// @brief Destructor
///
DialogColorPicker::~DialogColorPicker()
@ -801,8 +1105,6 @@ DialogColorPicker::~DialogColorPicker()
if (screen_dropper_icon->HasCapture()) screen_dropper_icon->ReleaseMouse();
}
/// @brief Sets the currently selected color, and updates all controls
/// @param new_color
///
@ -815,8 +1117,6 @@ void DialogColorPicker::SetColor(wxColour new_color)
UpdateFromRGB();
}
/// @brief Get the currently selected color
/// @return
///
@ -827,8 +1127,6 @@ wxColour DialogColorPicker::GetColor()
return cur_color;
}
/// @brief Use the values entered in the RGB controls to update the other controls
/// @return
///
@ -857,8 +1155,6 @@ void DialogColorPicker::UpdateFromRGB()
updating_controls = false;
}
/// @brief Use the values entered in the HSL controls to update the other controls
/// @return
///
@ -887,8 +1183,6 @@ void DialogColorPicker::UpdateFromHSL()
updating_controls = false;
}
/// @brief DOCME
/// @return
///
@ -918,8 +1212,6 @@ void DialogColorPicker::UpdateFromHSV()
updating_controls = false;
}
/// @brief Use the value entered in the ASS hex control to update the other controls
/// @return
///
@ -952,8 +1244,6 @@ void DialogColorPicker::UpdateFromASS()
updating_controls = false;
}
/// @brief DOCME
/// @return
///
@ -985,8 +1275,6 @@ void DialogColorPicker::UpdateFromHTML()
updating_controls = false;
}
/// @brief DOCME
///
void DialogColorPicker::UpdateSpectrumDisplay()
@ -1040,10 +1328,10 @@ void DialogColorPicker::UpdateSpectrumDisplay()
previewdc.DrawRectangle(0, 0, 40, 40);
}
preview_box->SetBitmap(tempBmp);
if (callback) callback(callbackUserdata, cur_color);
}
/// @brief DOCME
/// @return
///
@ -1068,8 +1356,6 @@ wxBitmap *DialogColorPicker::MakeGBSpectrum()
return rgb_spectrum[0];
}
/// @brief DOCME
/// @return
///
@ -1094,8 +1380,6 @@ wxBitmap *DialogColorPicker::MakeRBSpectrum()
return rgb_spectrum[1];
}
/// @brief DOCME
/// @return
///
@ -1120,8 +1404,6 @@ wxBitmap *DialogColorPicker::MakeRGSpectrum()
return rgb_spectrum[2];
}
/// @brief DOCME
/// @return
///
@ -1151,8 +1433,6 @@ wxBitmap *DialogColorPicker::MakeHSSpectrum()
return hsl_spectrum;
}
/// @brief DOCME
/// @return
///
@ -1190,8 +1470,6 @@ wxBitmap *DialogColorPicker::MakeSVSpectrum()
return hsv_spectrum;
}
BEGIN_EVENT_TABLE(DialogColorPicker, wxDialog)
EVT_SPINCTRL(SELECTOR_RGB_R, DialogColorPicker::OnSpinRGB)
EVT_SPINCTRL(SELECTOR_RGB_G, DialogColorPicker::OnSpinRGB)
@ -1222,8 +1500,6 @@ BEGIN_EVENT_TABLE(DialogColorPicker, wxDialog)
EVT_MOUSE_EVENTS(DialogColorPicker::OnMouse)
END_EVENT_TABLE()
/// @brief DOCME
/// @param evt
///
@ -1234,8 +1510,6 @@ void DialogColorPicker::OnSpinRGB(wxSpinEvent &evt)
UpdateFromRGB();
}
/// @brief DOCME
/// @param evt
///
@ -1246,8 +1520,6 @@ void DialogColorPicker::OnSpinHSL(wxSpinEvent &evt)
UpdateFromHSL();
}
/// @brief DOCME
/// @param evt
///
@ -1258,8 +1530,6 @@ void DialogColorPicker::OnSpinHSV(wxSpinEvent &evt)
UpdateFromHSV();
}
/// @brief DOCME
/// @param evt
///
@ -1270,8 +1540,6 @@ void DialogColorPicker::OnChangeRGB(wxCommandEvent &evt)
UpdateFromRGB();
}
/// @brief DOCME
/// @param evt
///
@ -1282,8 +1550,6 @@ void DialogColorPicker::OnChangeHSL(wxCommandEvent &evt)
UpdateFromHSL();
}
/// @brief DOCME
/// @param evt
///
@ -1294,8 +1560,6 @@ void DialogColorPicker::OnChangeHSV(wxCommandEvent &evt)
UpdateFromHSV();
}
/// @brief DOCME
/// @param evt
///
@ -1306,8 +1570,6 @@ void DialogColorPicker::OnChangeASS(wxCommandEvent &evt)
UpdateFromASS();
}
/// @brief DOCME
/// @param evt
///
@ -1318,8 +1580,6 @@ void DialogColorPicker::OnChangeHTML(wxCommandEvent &evt)
UpdateFromHTML();
}
/// @brief DOCME
/// @param evt
///
@ -1331,8 +1591,6 @@ void DialogColorPicker::OnChangeMode(wxCommandEvent &evt)
UpdateSpectrumDisplay();
}
/// @brief DOCME
/// @param evt
///
@ -1378,8 +1636,6 @@ void DialogColorPicker::OnSpectrumChange(wxCommandEvent &evt)
}
/// @brief DOCME
/// @param evt Ignored
///
@ -1413,8 +1669,6 @@ void DialogColorPicker::OnSliderChange(wxCommandEvent &evt)
}
}
/// @brief DOCME
/// @param evt
///
@ -1428,8 +1682,6 @@ void DialogColorPicker::OnRecentSelect(wxCommandEvent &evt)
SetColor(color.GetWXColor());
}
/// @brief DOCME
/// @param evt
///
@ -1469,8 +1721,6 @@ void DialogColorPicker::OnDropperMouse(wxMouseEvent &evt)
}
}
/// @brief Hack to redirect events to the screen dropper icon
/// @param evt
///
@ -1486,8 +1736,6 @@ void DialogColorPicker::OnMouse(wxMouseEvent &evt)
evt.Skip();
}
/// @brief rgbadjust() tool
/// @param evt
///
@ -1506,12 +1754,9 @@ void DialogColorPicker::OnRGBAdjust(wxCommandEvent &evt)
}
}
/// DOCME
int DialogColorPicker::lastx = -1;
/// DOCME
int DialogColorPicker::lasty = -1;

View file

@ -1,4 +1,4 @@
// Copyright (c) 2005, Niels Martin Hansen
// Copyright (c) 2010, Thomas Goyne <plorkyeran@aegisub.org>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@ -34,358 +34,35 @@
/// @ingroup tools_ui
///
#ifndef AGI_PRE
#include <vector>
#include <wx/bitmap.h>
#include <wx/button.h>
#include <wx/choice.h>
#include <wx/colour.h>
#include <wx/dialog.h>
#include <wx/spinctrl.h>
#include <wx/statbmp.h>
#include <wx/textctrl.h>
#endif
/// DOCME
/// @class ColorPickerSpectrum
/// @brief DOCME
///
/// DOCME
class ColorPickerSpectrum : public wxControl {
public:
/// DOCME
enum PickerDirection {
/// DOCME
HorzVert,
/// DOCME
Horz,
/// DOCME
Vert
};
private:
/// DOCME
/// DOCME
int x, y;
/// DOCME
wxBitmap *background;
/// DOCME
PickerDirection direction;
void OnPaint(wxPaintEvent &evt);
void OnMouse(wxMouseEvent &evt);
public:
ColorPickerSpectrum(wxWindow *parent, wxWindowID id, wxBitmap *_background, int xx, int yy, PickerDirection _direction, wxSize _size);
void GetXY(int &xx, int &yy);
void SetXY(int xx, int yy);
void SetBackground(wxBitmap *new_background);
DECLARE_EVENT_TABLE()
};
DECLARE_EVENT_TYPE(wxSPECTRUM_CHANGE, -1)
/// DOCME
/// @class ColorPickerRecent
/// @brief DOCME
///
/// DOCME
class ColorPickerRecent : public wxControl {
private:
/// DOCME
/// DOCME
int rows, cols;
/// DOCME
int cellsize;
/// DOCME
wxPoint internal_control_offset;
/// DOCME
std::vector<wxColour> colors;
/// DOCME
bool background_valid;
/// DOCME
wxBitmap background;
void OnClick(wxMouseEvent &evt);
void OnPaint(wxPaintEvent &evt);
void OnSize(wxSizeEvent &evt);
public:
ColorPickerRecent(wxWindow *parent, wxWindowID id, int _cols, int _rows, int _cellsize);
void LoadFromString(const wxString &recent_string);
wxString StoreToString();
void AddColor(wxColour color);
/// @brief DOCME
/// @param n
/// @return
///
wxColour GetColor(int n) { return colors.at(n); }
DECLARE_EVENT_TABLE()
};
DECLARE_EVENT_TYPE(wxRECENT_SELECT, -1)
/// DOCME
/// @class ColorPickerScreenDropper
/// @brief DOCME
///
/// DOCME
class ColorPickerScreenDropper : public wxControl {
private:
/// DOCME
wxBitmap capture;
/// DOCME
/// DOCME
int resx, resy;
/// DOCME
int magnification;
/// DOCME
bool integrated_dropper;
void OnMouse(wxMouseEvent &evt);
void OnPaint(wxPaintEvent &evt);
public:
ColorPickerScreenDropper(wxWindow *parent, wxWindowID id, int _resx, int _resy, int _magnification, bool _integrated_dropper);
void DropFromScreenXY(int x, int y);
DECLARE_EVENT_TABLE()
};
DECLARE_EVENT_TYPE(wxDROPPER_SELECT, -1)
wxColour GetColorFromUser(wxWindow *parent, wxColour original);
/// DOCME
/// @class DialogColorPicker
/// @brief DOCME
///
/// DOCME
class DialogColorPicker : public wxDialog {
private:
/// DOCME
wxColour cur_color;
/// DOCME
bool updating_controls;
/// DOCME
bool spectrum_dirty;
/// DOCME
ColorPickerSpectrum *spectrum;
/// DOCME
ColorPickerSpectrum *slider;
/// DOCME
wxChoice *colorspace_choice;
/// DOCME
static const int slider_width = 10; // width in pixels of the color slider control
/// DOCME
wxSpinCtrl *rgb_input[3];
/// DOCME
wxBitmap *rgb_spectrum[3]; // x/y spectrum bitmap where color "i" is excluded from
/// DOCME
wxBitmap *rgb_slider[3]; // z spectrum for color "i"
/// DOCME
wxSpinCtrl *hsl_input[3];
/// DOCME
wxBitmap *hsl_spectrum; // h/s spectrum
/// DOCME
wxBitmap *hsl_slider; // l spectrum
/// DOCME
wxSpinCtrl *hsv_input[3];
/// DOCME
wxBitmap *hsv_spectrum; // s/v spectrum
/// DOCME
wxBitmap *hsv_slider; // h spectrum
/// DOCME
wxBitmap eyedropper_bitmap;
/// DOCME
wxPoint eyedropper_grab_point;
/// DOCME
bool eyedropper_is_grabbed;
/// DOCME
wxTextCtrl *ass_input; // ASS hex format input
/// DOCME
wxTextCtrl *html_input; // HTML hex format input
/// DOCME
wxStaticBitmap *preview_box;
/// DOCME
wxBitmap preview_bitmap;
/// DOCME
ColorPickerRecent *recent_box;
/// DOCME
ColorPickerScreenDropper *screen_dropper;
/// DOCME
wxStaticBitmap *screen_dropper_icon;
void UpdateFromRGB(); // Update all other controls as a result of modifying an RGB control
void UpdateFromHSL(); // Update all other controls as a result of modifying an HSL control
void UpdateFromHSV(); // Update all other controls as a result of modifying an HSV control
void UpdateFromASS(); // Update all other controls as a result of modifying the ASS format control
void UpdateFromHTML(); // Update all other controls as a result of modifying the HTML format control
void UpdateSpectrumDisplay(); // Redraw the spectrum display
wxBitmap *MakeGBSpectrum();
wxBitmap *MakeRBSpectrum();
wxBitmap *MakeRGSpectrum();
wxBitmap *MakeHSSpectrum();
wxBitmap *MakeSVSpectrum();
void OnSpinRGB(wxSpinEvent &evt);
void OnSpinHSL(wxSpinEvent &evt);
void OnSpinHSV(wxSpinEvent &evt);
void OnChangeRGB(wxCommandEvent &evt);
void OnChangeHSL(wxCommandEvent &evt);
void OnChangeHSV(wxCommandEvent &evt);
void OnChangeASS(wxCommandEvent &evt);
void OnChangeHTML(wxCommandEvent &evt);
void OnChangeMode(wxCommandEvent &evt);
void OnSpectrumChange(wxCommandEvent &evt);
void OnSliderChange(wxCommandEvent &evt);
void OnRecentSelect(wxCommandEvent &evt); // also handles dropper pick
void OnRGBAdjust(wxCommandEvent &evt);
void OnDropperMouse(wxMouseEvent &evt);
void OnMouse(wxMouseEvent &evt);
/// DOCME
/// DOCME
static int lastx, lasty;
public:
DialogColorPicker(wxWindow *parent, wxColour initial_color);
~DialogColorPicker();
void SetColor(wxColour new_color);
wxColour GetColor();
DECLARE_EVENT_TABLE()
};
enum {
/// DOCME
SELECTOR_SPECTRUM = 4000,
/// DOCME
SELECTOR_SLIDER,
/// DOCME
SELECTOR_MODE,
/// DOCME
SELECTOR_RGB_R,
/// DOCME
SELECTOR_RGB_G,
/// DOCME
SELECTOR_RGB_B,
/// DOCME
SELECTOR_HSL_H,
/// DOCME
SELECTOR_HSL_S,
/// DOCME
SELECTOR_HSL_L,
/// DOCME
SELECTOR_HSV_H,
/// DOCME
SELECTOR_HSV_S,
/// DOCME
SELECTOR_HSV_V,
/// DOCME
SELECTOR_ASS_INPUT,
/// DOCME
SELECTOR_HTML_INPUT,
/// DOCME
SELECTOR_RECENT,
/// DOCME
SELECTOR_DROPPER,
/// DOCME
SELECTOR_DROPPER_PICK,
/// DOCME
BUTTON_RGBADJUST
};
/// Callback function for GetColorFromUser
typedef void (*ColorCallback)(void* userdata, wxColor color);
/// Wrapper used by templated version of GetColorFromUser
template<class T, void (T::*method)(wxColor)>
void ColorCallbackWrapper(void* obj, wxColor color) {
(static_cast<T*>(obj)->*method)(color);
}
/// @brief Get a color from the user via a color picker dialog
/// @param parent Parent window
/// @param original Initial color to select
/// @param callback Function called whenever the selected color changes if not NULL
/// @param userdata Passed to callback function
/// @return Last selected color when dialog is closed, or original if the dialog was cancelled
wxColor GetColorFromUser(wxWindow* parent, wxColor original, ColorCallback callback = NULL, void* userdata = NULL);
/// @brief Get a color from the user via a color picker dialog
/// @param T Class which the callback method belongs to
/// @param method Callback method
/// @param parent Parent window
/// @param original Initial color to select
/// @param callbackObj Object to call callback method on. Must be of type T.
/// @return Last selected color when dialog is closed, or original if the dialog was cancelled
template<class T, void (T::*method)(wxColor)>
wxColor GetColorFromUser(wxWindow* parent, wxColor original, T* callbackObj) {
return GetColorFromUser(parent, original, &ColorCallbackWrapper<T, method>, callbackObj);
}

View file

@ -51,7 +51,6 @@
#include "ass_style.h"
#include "ass_style_storage.h"
#include "compat.h"
#include "dialog_colorpicker.h"
#include "dialog_style_editor.h"
#include "help_button.h"
#include "libresrc/libresrc.h"

View file

@ -180,10 +180,7 @@ void Preferences::OptionAdd(wxPanel *parent, wxFlexGridSizer *flex, const wxStri
case agi::OptionValue::Type_Colour: {
flex->Add(new wxStaticText(parent, wxID_ANY, name), 1, wxALIGN_CENTRE_VERTICAL);
ColourButton *colour = new ColourButton(parent, wxID_ANY, wxSize(40,10));
wxColour current(opt->GetColour());
colour->SetColour(current);
flex->Add(colour);
flex->Add(new ColourButton(parent, wxID_ANY, wxSize(40,10), lagi_wxColour(opt->GetColour())));
break;
}