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 /// @ingroup custom_control
/// ///
////////////
// Includes
#include "config.h" #include "config.h"
#ifndef AGI_PRE #ifndef AGI_PRE
@ -47,42 +44,20 @@
#include "config.h" #include "config.h"
#include "dialog_colorpicker.h" #include "dialog_colorpicker.h"
ColourButton::ColourButton(wxWindow* parent, wxWindowID id, const wxSize& size, wxColour col)
/// @brief Constructor : wxBitmapButton(parent, id, wxBitmap(size))
/// @param parent , bmp(GetBitmapLabel())
/// @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
SetColour(col); SetColour(col);
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ColourButton::OnClick, this);
// Connect to click event
Connect(GetId(),wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(ColourButton::OnClick));
} }
/// @brief Destructor
///
ColourButton::~ColourButton() { ColourButton::~ColourButton() {
} }
/// @brief Callback for the color picker dialog
/// @param col New color
/// @brief Set colour
/// @param col
///
void ColourButton::SetColour(wxColour col) { void ColourButton::SetColour(wxColour col) {
// Set colour
colour = col; colour = col;
// Draw colour // Draw colour
@ -92,44 +67,24 @@ void ColourButton::SetColour(wxColour col) {
dc.SetBrush(wxBrush(colour)); dc.SetBrush(wxBrush(colour));
dc.DrawRectangle(0,0,bmp.GetWidth(),bmp.GetHeight()); dc.DrawRectangle(0,0,bmp.GetWidth(),bmp.GetHeight());
} }
// Set bitmap
SetBitmapLabel(bmp); SetBitmapLabel(bmp);
// Set link colour // Trigger a click event on this as some stuff relies on that to know
if (linkColour) *linkColour = colour; // when the color has changed
wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
evt.SetClientData(this);
AddPendingEvent(evt);
} }
/// @brief Get Colour
/// @return
///
wxColour ColourButton::GetColour() { wxColour ColourButton::GetColour() {
return colour; return colour;
} }
/// @brief Click handler
/// @brief Click
/// @param event /// @param event
///
void ColourButton::OnClick(wxCommandEvent &event) { void ColourButton::OnClick(wxCommandEvent &event) {
DialogColorPicker dlg(GetParent(), colour); if (event.GetClientData() != this)
if (dlg.ShowModal() == wxID_OK) { GetColorFromUser<ColourButton, &ColourButton::SetColour>(GetParent(), colour, this);
SetColour(dlg.GetColor()); else
} event.Skip();
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 /// @ingroup custom_control
/// ///
////////////
// Includes
#ifndef AGI_PRE #ifndef AGI_PRE
#include <wx/bmpbuttn.h> #include <wx/bmpbuttn.h>
#endif #endif
@ -49,25 +46,14 @@
/// DOCME /// DOCME
class ColourButton: public wxBitmapButton { class ColourButton: public wxBitmapButton {
private: private:
wxBitmap bmp; /// The button's bitmap label
/// DOCME wxColour colour; /// The current colour
wxBitmap bmp;
/// DOCME
wxColour colour;
/// DOCME
wxColour *linkColour;
void OnClick(wxCommandEvent &event); void OnClick(wxCommandEvent &event);
void SetColour(wxColour colour);
public: public:
ColourButton(wxWindow* parent, wxWindowID id, const wxSize& size, wxColour col=wxColour(0,0,0)); ColourButton(wxWindow* parent, wxWindowID id, const wxSize& size, wxColour col=wxColour(0,0,0));
~ColourButton(); ~ColourButton();
void SetColour(wxColour colour);
wxColour GetColour(); wxColour GetColour();
void SetLinkColour(wxColour *colour);
}; };

View file

@ -38,19 +38,27 @@
#ifndef AGI_PRE #ifndef AGI_PRE
#include <stdio.h> #include <stdio.h>
#include <vector>
#include <wx/bitmap.h>
#include <wx/button.h>
#include <wx/choice.h>
#include <wx/clipbrd.h> #include <wx/clipbrd.h>
#include <wx/dataobj.h> #include <wx/dataobj.h>
#include <wx/dcclient.h> #include <wx/dcclient.h>
#include <wx/dcmemory.h> #include <wx/dcmemory.h>
#include <wx/dcscreen.h> #include <wx/dcscreen.h>
#include <wx/dialog.h>
#include <wx/event.h> #include <wx/event.h>
#include <wx/gbsizer.h> #include <wx/gbsizer.h>
#include <wx/image.h> #include <wx/image.h>
#include <wx/settings.h> #include <wx/settings.h>
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/spinctrl.h>
#include <wx/statbmp.h>
#include <wx/statbox.h> #include <wx/statbox.h>
#include <wx/stattext.h> #include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/tokenzr.h> #include <wx/tokenzr.h>
#endif #endif
@ -64,6 +72,330 @@
#include "options.h" #include "options.h"
#include "utils.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 #ifdef WIN32
@ -75,12 +407,9 @@
#define STATIC_BORDER_FLAG wxSIMPLE_BORDER #define STATIC_BORDER_FLAG wxSIMPLE_BORDER
#endif #endif
/// DOCME /// DOCME
static const int spectrum_horz_vert_arrow_size = 4; static const int spectrum_horz_vert_arrow_size = 4;
/// @brief DOCME /// @brief DOCME
/// @param parent /// @param parent
/// @param id /// @param id
@ -103,7 +432,6 @@ ColorPickerSpectrum::ColorPickerSpectrum(wxWindow *parent, wxWindowID id, wxBitm
SetMinSize(GetSize()); SetMinSize(GetSize());
} }
/// @brief DOCME /// @brief DOCME
/// @param xx /// @param xx
/// @param yy /// @param yy
@ -114,7 +442,6 @@ void ColorPickerSpectrum::GetXY(int &xx, int &yy)
yy = y; yy = y;
} }
/// @brief DOCME /// @brief DOCME
/// @param xx /// @param xx
/// @param yy /// @param yy
@ -126,7 +453,6 @@ void ColorPickerSpectrum::SetXY(int xx, int yy)
Refresh(true); Refresh(true);
} }
/// @brief DOCME /// @brief DOCME
/// @param new_background /// @param new_background
/// @return /// @return
@ -145,7 +471,6 @@ END_EVENT_TABLE()
DEFINE_EVENT_TYPE(wxSPECTRUM_CHANGE) DEFINE_EVENT_TYPE(wxSPECTRUM_CHANGE)
/// @brief DOCME /// @brief DOCME
/// @param evt /// @param evt
/// @return /// @return
@ -208,7 +533,6 @@ void ColorPickerSpectrum::OnPaint(wxPaintEvent &evt)
dc.DrawRectangle(0, 0, background->GetWidth()+2, background->GetHeight()+2); dc.DrawRectangle(0, 0, background->GetWidth()+2, background->GetHeight()+2);
} }
/// @brief DOCME /// @brief DOCME
/// @param evt /// @param evt
/// @return /// @return
@ -245,9 +569,6 @@ void ColorPickerSpectrum::OnMouse(wxMouseEvent &evt)
} }
} }
/// @brief DOCME /// @brief DOCME
/// @param parent /// @param parent
/// @param id /// @param id
@ -271,7 +592,6 @@ ColorPickerRecent::ColorPickerRecent(wxWindow *parent, wxWindowID id, int _cols,
SetCursor(*wxCROSS_CURSOR); SetCursor(*wxCROSS_CURSOR);
} }
/// @brief DOCME /// @brief DOCME
/// @param recent_string /// @param recent_string
/// ///
@ -292,7 +612,6 @@ void ColorPickerRecent::LoadFromString(const wxString &recent_string)
background_valid = false; background_valid = false;
} }
/// @brief DOCME /// @brief DOCME
/// @return /// @return
/// ///
@ -307,7 +626,6 @@ wxString ColorPickerRecent::StoreToString()
return res; return res;
} }
/// @brief DOCME /// @brief DOCME
/// @param color /// @param color
/// ///
@ -335,7 +653,6 @@ END_EVENT_TABLE()
DEFINE_EVENT_TYPE(wxRECENT_SELECT) DEFINE_EVENT_TYPE(wxRECENT_SELECT)
/// @brief DOCME /// @brief DOCME
/// @param evt /// @param evt
/// @return /// @return
@ -356,7 +673,6 @@ void ColorPickerRecent::OnClick(wxMouseEvent &evt)
} }
} }
/// @brief DOCME /// @brief DOCME
/// @param evt /// @param evt
/// ///
@ -393,7 +709,6 @@ void ColorPickerRecent::OnPaint(wxPaintEvent &evt)
pdc.DrawBitmap(background, 0, 0, false); pdc.DrawBitmap(background, 0, 0, false);
} }
/// @brief DOCME /// @brief DOCME
/// @param evt /// @param evt
/// ///
@ -406,9 +721,6 @@ void ColorPickerRecent::OnSize(wxSizeEvent &evt)
Refresh(); Refresh();
} }
/// @brief DOCME /// @brief DOCME
/// @param parent /// @param parent
/// @param id /// @param id
@ -440,7 +752,6 @@ END_EVENT_TABLE()
DEFINE_EVENT_TYPE(wxDROPPER_SELECT) DEFINE_EVENT_TYPE(wxDROPPER_SELECT)
/// @brief DOCME /// @brief DOCME
/// @param evt /// @param evt
/// ///
@ -478,7 +789,6 @@ void ColorPickerScreenDropper::OnMouse(wxMouseEvent &evt)
} }
} }
/// @brief DOCME /// @brief DOCME
/// @param evt /// @param evt
/// ///
@ -513,8 +823,6 @@ void ColorPickerScreenDropper::OnPaint(wxPaintEvent &evt)
} }
} }
/// @brief DOCME /// @brief DOCME
/// @param x /// @param x
/// @param y /// @param y
@ -532,32 +840,30 @@ void ColorPickerScreenDropper::DropFromScreenXY(int x, int y)
Refresh(false); Refresh(false);
} }
/// @brief DOCME /// @brief DOCME
/// @param parent /// @param parent
/// @param original /// @param original
/// @return /// @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) { if (dialog.ShowModal() == wxID_OK) {
return dialog.GetColor(); return dialog.GetColor();
} else { } else {
if (callback) callback(userdata, original);
return original; return original;
} }
} }
/// @brief Constructor /// @brief Constructor
/// @param parent /// @param parent
/// @param initial_color /// @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) : wxDialog(parent, -1, _("Select Colour"), wxDefaultPosition, wxDefaultSize)
, callback(callback)
, callbackUserdata(userdata)
{ {
rgb_spectrum[0] = rgb_spectrum[0] =
rgb_spectrum[1] = 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); screen_dropper_icon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(DialogColorPicker::OnDropperMouse), 0, this);
} }
/// @brief Destructor /// @brief Destructor
/// ///
DialogColorPicker::~DialogColorPicker() DialogColorPicker::~DialogColorPicker()
@ -801,8 +1105,6 @@ DialogColorPicker::~DialogColorPicker()
if (screen_dropper_icon->HasCapture()) screen_dropper_icon->ReleaseMouse(); if (screen_dropper_icon->HasCapture()) screen_dropper_icon->ReleaseMouse();
} }
/// @brief Sets the currently selected color, and updates all controls /// @brief Sets the currently selected color, and updates all controls
/// @param new_color /// @param new_color
/// ///
@ -815,8 +1117,6 @@ void DialogColorPicker::SetColor(wxColour new_color)
UpdateFromRGB(); UpdateFromRGB();
} }
/// @brief Get the currently selected color /// @brief Get the currently selected color
/// @return /// @return
/// ///
@ -827,8 +1127,6 @@ wxColour DialogColorPicker::GetColor()
return cur_color; return cur_color;
} }
/// @brief Use the values entered in the RGB controls to update the other controls /// @brief Use the values entered in the RGB controls to update the other controls
/// @return /// @return
/// ///
@ -857,8 +1155,6 @@ void DialogColorPicker::UpdateFromRGB()
updating_controls = false; updating_controls = false;
} }
/// @brief Use the values entered in the HSL controls to update the other controls /// @brief Use the values entered in the HSL controls to update the other controls
/// @return /// @return
/// ///
@ -887,8 +1183,6 @@ void DialogColorPicker::UpdateFromHSL()
updating_controls = false; updating_controls = false;
} }
/// @brief DOCME /// @brief DOCME
/// @return /// @return
/// ///
@ -918,8 +1212,6 @@ void DialogColorPicker::UpdateFromHSV()
updating_controls = false; updating_controls = false;
} }
/// @brief Use the value entered in the ASS hex control to update the other controls /// @brief Use the value entered in the ASS hex control to update the other controls
/// @return /// @return
/// ///
@ -952,8 +1244,6 @@ void DialogColorPicker::UpdateFromASS()
updating_controls = false; updating_controls = false;
} }
/// @brief DOCME /// @brief DOCME
/// @return /// @return
/// ///
@ -985,8 +1275,6 @@ void DialogColorPicker::UpdateFromHTML()
updating_controls = false; updating_controls = false;
} }
/// @brief DOCME /// @brief DOCME
/// ///
void DialogColorPicker::UpdateSpectrumDisplay() void DialogColorPicker::UpdateSpectrumDisplay()
@ -1040,10 +1328,10 @@ void DialogColorPicker::UpdateSpectrumDisplay()
previewdc.DrawRectangle(0, 0, 40, 40); previewdc.DrawRectangle(0, 0, 40, 40);
} }
preview_box->SetBitmap(tempBmp); preview_box->SetBitmap(tempBmp);
if (callback) callback(callbackUserdata, cur_color);
} }
/// @brief DOCME /// @brief DOCME
/// @return /// @return
/// ///
@ -1068,8 +1356,6 @@ wxBitmap *DialogColorPicker::MakeGBSpectrum()
return rgb_spectrum[0]; return rgb_spectrum[0];
} }
/// @brief DOCME /// @brief DOCME
/// @return /// @return
/// ///
@ -1094,8 +1380,6 @@ wxBitmap *DialogColorPicker::MakeRBSpectrum()
return rgb_spectrum[1]; return rgb_spectrum[1];
} }
/// @brief DOCME /// @brief DOCME
/// @return /// @return
/// ///
@ -1120,8 +1404,6 @@ wxBitmap *DialogColorPicker::MakeRGSpectrum()
return rgb_spectrum[2]; return rgb_spectrum[2];
} }
/// @brief DOCME /// @brief DOCME
/// @return /// @return
/// ///
@ -1151,8 +1433,6 @@ wxBitmap *DialogColorPicker::MakeHSSpectrum()
return hsl_spectrum; return hsl_spectrum;
} }
/// @brief DOCME /// @brief DOCME
/// @return /// @return
/// ///
@ -1190,8 +1470,6 @@ wxBitmap *DialogColorPicker::MakeSVSpectrum()
return hsv_spectrum; return hsv_spectrum;
} }
BEGIN_EVENT_TABLE(DialogColorPicker, wxDialog) BEGIN_EVENT_TABLE(DialogColorPicker, wxDialog)
EVT_SPINCTRL(SELECTOR_RGB_R, DialogColorPicker::OnSpinRGB) EVT_SPINCTRL(SELECTOR_RGB_R, DialogColorPicker::OnSpinRGB)
EVT_SPINCTRL(SELECTOR_RGB_G, DialogColorPicker::OnSpinRGB) EVT_SPINCTRL(SELECTOR_RGB_G, DialogColorPicker::OnSpinRGB)
@ -1222,8 +1500,6 @@ BEGIN_EVENT_TABLE(DialogColorPicker, wxDialog)
EVT_MOUSE_EVENTS(DialogColorPicker::OnMouse) EVT_MOUSE_EVENTS(DialogColorPicker::OnMouse)
END_EVENT_TABLE() END_EVENT_TABLE()
/// @brief DOCME /// @brief DOCME
/// @param evt /// @param evt
/// ///
@ -1234,8 +1510,6 @@ void DialogColorPicker::OnSpinRGB(wxSpinEvent &evt)
UpdateFromRGB(); UpdateFromRGB();
} }
/// @brief DOCME /// @brief DOCME
/// @param evt /// @param evt
/// ///
@ -1246,8 +1520,6 @@ void DialogColorPicker::OnSpinHSL(wxSpinEvent &evt)
UpdateFromHSL(); UpdateFromHSL();
} }
/// @brief DOCME /// @brief DOCME
/// @param evt /// @param evt
/// ///
@ -1258,8 +1530,6 @@ void DialogColorPicker::OnSpinHSV(wxSpinEvent &evt)
UpdateFromHSV(); UpdateFromHSV();
} }
/// @brief DOCME /// @brief DOCME
/// @param evt /// @param evt
/// ///
@ -1270,8 +1540,6 @@ void DialogColorPicker::OnChangeRGB(wxCommandEvent &evt)
UpdateFromRGB(); UpdateFromRGB();
} }
/// @brief DOCME /// @brief DOCME
/// @param evt /// @param evt
/// ///
@ -1282,8 +1550,6 @@ void DialogColorPicker::OnChangeHSL(wxCommandEvent &evt)
UpdateFromHSL(); UpdateFromHSL();
} }
/// @brief DOCME /// @brief DOCME
/// @param evt /// @param evt
/// ///
@ -1294,8 +1560,6 @@ void DialogColorPicker::OnChangeHSV(wxCommandEvent &evt)
UpdateFromHSV(); UpdateFromHSV();
} }
/// @brief DOCME /// @brief DOCME
/// @param evt /// @param evt
/// ///
@ -1306,8 +1570,6 @@ void DialogColorPicker::OnChangeASS(wxCommandEvent &evt)
UpdateFromASS(); UpdateFromASS();
} }
/// @brief DOCME /// @brief DOCME
/// @param evt /// @param evt
/// ///
@ -1318,8 +1580,6 @@ void DialogColorPicker::OnChangeHTML(wxCommandEvent &evt)
UpdateFromHTML(); UpdateFromHTML();
} }
/// @brief DOCME /// @brief DOCME
/// @param evt /// @param evt
/// ///
@ -1331,8 +1591,6 @@ void DialogColorPicker::OnChangeMode(wxCommandEvent &evt)
UpdateSpectrumDisplay(); UpdateSpectrumDisplay();
} }
/// @brief DOCME /// @brief DOCME
/// @param evt /// @param evt
/// ///
@ -1378,8 +1636,6 @@ void DialogColorPicker::OnSpectrumChange(wxCommandEvent &evt)
} }
/// @brief DOCME /// @brief DOCME
/// @param evt Ignored /// @param evt Ignored
/// ///
@ -1413,8 +1669,6 @@ void DialogColorPicker::OnSliderChange(wxCommandEvent &evt)
} }
} }
/// @brief DOCME /// @brief DOCME
/// @param evt /// @param evt
/// ///
@ -1428,8 +1682,6 @@ void DialogColorPicker::OnRecentSelect(wxCommandEvent &evt)
SetColor(color.GetWXColor()); SetColor(color.GetWXColor());
} }
/// @brief DOCME /// @brief DOCME
/// @param evt /// @param evt
/// ///
@ -1469,8 +1721,6 @@ void DialogColorPicker::OnDropperMouse(wxMouseEvent &evt)
} }
} }
/// @brief Hack to redirect events to the screen dropper icon /// @brief Hack to redirect events to the screen dropper icon
/// @param evt /// @param evt
/// ///
@ -1486,8 +1736,6 @@ void DialogColorPicker::OnMouse(wxMouseEvent &evt)
evt.Skip(); evt.Skip();
} }
/// @brief rgbadjust() tool /// @brief rgbadjust() tool
/// @param evt /// @param evt
/// ///
@ -1506,12 +1754,9 @@ void DialogColorPicker::OnRGBAdjust(wxCommandEvent &evt)
} }
} }
/// DOCME /// DOCME
int DialogColorPicker::lastx = -1; int DialogColorPicker::lastx = -1;
/// DOCME /// DOCME
int DialogColorPicker::lasty = -1; 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. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
@ -34,358 +34,35 @@
/// @ingroup tools_ui /// @ingroup tools_ui
/// ///
#ifndef AGI_PRE #ifndef AGI_PRE
#include <vector>
#include <wx/bitmap.h>
#include <wx/button.h>
#include <wx/choice.h>
#include <wx/colour.h> #include <wx/colour.h>
#include <wx/dialog.h>
#include <wx/spinctrl.h>
#include <wx/statbmp.h>
#include <wx/textctrl.h>
#endif #endif
/// Callback function for GetColorFromUser
/// DOCME typedef void (*ColorCallback)(void* userdata, wxColor color);
/// @class ColorPickerSpectrum
/// @brief DOCME /// Wrapper used by templated version of GetColorFromUser
/// template<class T, void (T::*method)(wxColor)>
/// DOCME void ColorCallbackWrapper(void* obj, wxColor color) {
class ColorPickerSpectrum : public wxControl { (static_cast<T*>(obj)->*method)(color);
public: }
/// DOCME /// @brief Get a color from the user via a color picker dialog
enum PickerDirection { /// @param parent Parent window
/// @param original Initial color to select
/// DOCME /// @param callback Function called whenever the selected color changes if not NULL
HorzVert, /// @param userdata Passed to callback function
/// @return Last selected color when dialog is closed, or original if the dialog was cancelled
/// DOCME wxColor GetColorFromUser(wxWindow* parent, wxColor original, ColorCallback callback = NULL, void* userdata = NULL);
Horz,
/// @brief Get a color from the user via a color picker dialog
/// DOCME /// @param T Class which the callback method belongs to
Vert /// @param method Callback method
}; /// @param parent Parent window
private: /// @param original Initial color to select
/// @param callbackObj Object to call callback method on. Must be of type T.
/// DOCME /// @return Last selected color when dialog is closed, or original if the dialog was cancelled
template<class T, void (T::*method)(wxColor)>
/// DOCME wxColor GetColorFromUser(wxWindow* parent, wxColor original, T* callbackObj) {
int x, y; return GetColorFromUser(parent, original, &ColorCallbackWrapper<T, method>, callbackObj);
}
/// 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
};

View file

@ -51,7 +51,6 @@
#include "ass_style.h" #include "ass_style.h"
#include "ass_style_storage.h" #include "ass_style_storage.h"
#include "compat.h" #include "compat.h"
#include "dialog_colorpicker.h"
#include "dialog_style_editor.h" #include "dialog_style_editor.h"
#include "help_button.h" #include "help_button.h"
#include "libresrc/libresrc.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: { case agi::OptionValue::Type_Colour: {
flex->Add(new wxStaticText(parent, wxID_ANY, name), 1, wxALIGN_CENTRE_VERTICAL); flex->Add(new wxStaticText(parent, wxID_ANY, name), 1, wxALIGN_CENTRE_VERTICAL);
ColourButton *colour = new ColourButton(parent, wxID_ANY, wxSize(40,10)); flex->Add(new ColourButton(parent, wxID_ANY, wxSize(40,10), lagi_wxColour(opt->GetColour())));
wxColour current(opt->GetColour());
colour->SetColour(current);
flex->Add(colour);
break; break;
} }