forked from mia/Aegisub
Tweaked colour dropper tool.
Originally committed to SVN as r1357.
This commit is contained in:
parent
d14bbbce87
commit
55a06f00b9
5 changed files with 104 additions and 40 deletions
BIN
aegisub/bitmaps/eyedropper.bmp
Normal file
BIN
aegisub/bitmaps/eyedropper.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 614 B |
BIN
aegisub/bitmaps/eyedropper.cur
Normal file
BIN
aegisub/bitmaps/eyedropper.cur
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -254,8 +254,8 @@ void ColorPickerRecent::OnSize(wxSizeEvent &evt)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ColorPickerScreenDropper::ColorPickerScreenDropper(wxWindow *parent, wxWindowID id, int _resx, int _resy, int _magnification)
|
ColorPickerScreenDropper::ColorPickerScreenDropper(wxWindow *parent, wxWindowID id, int _resx, int _resy, int _magnification, bool _integrated_dropper)
|
||||||
: wxControl(parent, id, wxDefaultPosition, wxDefaultSize, wxSTATIC_BORDER), resx(_resx), resy(_resy), magnification(_magnification)
|
: wxControl(parent, id, wxDefaultPosition, wxDefaultSize, wxSTATIC_BORDER), resx(_resx), resy(_resy), magnification(_magnification), integrated_dropper(_integrated_dropper)
|
||||||
{
|
{
|
||||||
SetClientSize(resx*magnification, resy*magnification);
|
SetClientSize(resx*magnification, resy*magnification);
|
||||||
SetMinSize(GetSize());
|
SetMinSize(GetSize());
|
||||||
|
@ -284,21 +284,12 @@ void ColorPickerScreenDropper::OnMouse(wxMouseEvent &evt)
|
||||||
|
|
||||||
if (HasCapture() && evt.LeftIsDown()) {
|
if (HasCapture() && evt.LeftIsDown()) {
|
||||||
|
|
||||||
wxMemoryDC capdc;
|
|
||||||
capdc.SelectObject(capture);
|
|
||||||
wxScreenDC screen;
|
|
||||||
|
|
||||||
wxPoint pos = ClientToScreen(evt.GetPosition());
|
wxPoint pos = ClientToScreen(evt.GetPosition());
|
||||||
|
DropFromScreenXY(pos.x, pos.y);
|
||||||
screen.StartDrawingOnTop();
|
|
||||||
capdc.Blit(0, 0, resx, resy, &screen, pos.x-resx/2, pos.y-resy/2);
|
|
||||||
screen.EndDrawingOnTop();
|
|
||||||
|
|
||||||
Refresh(false);
|
|
||||||
|
|
||||||
} else if (evt.LeftDown()) {
|
} else if (evt.LeftDown()) {
|
||||||
|
|
||||||
if (x == 0 && y == 0) {
|
if (x == 0 && y == 0 && integrated_dropper) {
|
||||||
SetCursor(*wxCROSS_CURSOR);
|
SetCursor(*wxCROSS_CURSOR);
|
||||||
CaptureMouse();
|
CaptureMouse();
|
||||||
|
|
||||||
|
@ -329,7 +320,7 @@ void ColorPickerScreenDropper::OnPaint(wxPaintEvent &evt)
|
||||||
|
|
||||||
for (int x = 0; x < resx; x++) {
|
for (int x = 0; x < resx; x++) {
|
||||||
for (int y = 0; y < resy; y++) {
|
for (int y = 0; y < resy; y++) {
|
||||||
if (x==0 && y==0) continue;
|
if (x==0 && y==0 && integrated_dropper) continue;
|
||||||
|
|
||||||
wxColour color;
|
wxColour color;
|
||||||
capdc.GetPixel(x, y, &color);
|
capdc.GetPixel(x, y, &color);
|
||||||
|
@ -339,6 +330,7 @@ void ColorPickerScreenDropper::OnPaint(wxPaintEvent &evt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (integrated_dropper) {
|
||||||
wxBrush cbrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
|
wxBrush cbrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
|
||||||
pdc.SetBrush(cbrush);
|
pdc.SetBrush(cbrush);
|
||||||
pdc.DrawRectangle(0, 0, magnification, magnification);
|
pdc.DrawRectangle(0, 0, magnification, magnification);
|
||||||
|
@ -346,6 +338,21 @@ void ColorPickerScreenDropper::OnPaint(wxPaintEvent &evt)
|
||||||
cbrush.SetColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
|
cbrush.SetColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
|
||||||
pdc.SetBrush(cbrush);
|
pdc.SetBrush(cbrush);
|
||||||
pdc.DrawRectangle(0, 0, magnification, magnification);
|
pdc.DrawRectangle(0, 0, magnification, magnification);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ColorPickerScreenDropper::DropFromScreenXY(int x, int y)
|
||||||
|
{
|
||||||
|
wxMemoryDC capdc;
|
||||||
|
capdc.SelectObject(capture);
|
||||||
|
wxScreenDC screen;
|
||||||
|
|
||||||
|
screen.StartDrawingOnTop();
|
||||||
|
capdc.Blit(0, 0, resx, resy, &screen, x-resx/2, y-resy/2);
|
||||||
|
screen.EndDrawingOnTop();
|
||||||
|
|
||||||
|
Refresh(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -368,7 +375,6 @@ DialogColorPicker::DialogColorPicker(wxWindow *parent, wxColour initial_color)
|
||||||
rgb_spectrum[0] =
|
rgb_spectrum[0] =
|
||||||
rgb_spectrum[1] =
|
rgb_spectrum[1] =
|
||||||
rgb_spectrum[2] =
|
rgb_spectrum[2] =
|
||||||
//yuv_spectrum =
|
|
||||||
hsl_spectrum =
|
hsl_spectrum =
|
||||||
hsv_spectrum = 0;
|
hsv_spectrum = 0;
|
||||||
spectrum_dirty = true;
|
spectrum_dirty = true;
|
||||||
|
@ -471,12 +477,12 @@ DialogColorPicker::DialogColorPicker(wxWindow *parent, wxColour initial_color)
|
||||||
preview_bitmap = wxBitmap(40, 40, 24);
|
preview_bitmap = wxBitmap(40, 40, 24);
|
||||||
preview_box = new wxStaticBitmap(this, -1, preview_bitmap, wxDefaultPosition, wxSize(40, 40), wxSTATIC_BORDER);
|
preview_box = new wxStaticBitmap(this, -1, preview_bitmap, wxDefaultPosition, wxSize(40, 40), wxSTATIC_BORDER);
|
||||||
|
|
||||||
recent_box = new ColorPickerRecent(this, SELECTOR_RECENT, 12, 2, 16);
|
recent_box = new ColorPickerRecent(this, SELECTOR_RECENT, 8, 4, 16);
|
||||||
|
|
||||||
screen_dropper = new ColorPickerScreenDropper(this, SELECTOR_DROPPER, 7, 7, 8);
|
eyedropper_bitmap = wxBITMAP(eyedropper_tool);
|
||||||
|
eyedropper_bitmap.SetMask(new wxMask(eyedropper_bitmap, wxColour(255, 0, 255)));
|
||||||
ok_button = new wxButton(this, wxID_OK);
|
screen_dropper_icon = new wxStaticBitmap(this, SELECTOR_DROPPER, eyedropper_bitmap);
|
||||||
cancel_button = new wxButton(this, wxID_CANCEL);
|
screen_dropper = new ColorPickerScreenDropper(this, SELECTOR_DROPPER_PICK, 7, 7, 8, false);
|
||||||
|
|
||||||
// Arrange the controls in a nice way
|
// Arrange the controls in a nice way
|
||||||
wxSizer *spectop_sizer = new wxBoxSizer(wxHORIZONTAL);
|
wxSizer *spectop_sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||||
|
@ -533,15 +539,13 @@ DialogColorPicker::DialogColorPicker(wxWindow *parent, wxColour initial_color)
|
||||||
|
|
||||||
wxSizer *picker_sizer = new wxBoxSizer(wxHORIZONTAL);
|
wxSizer *picker_sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||||
picker_sizer->AddStretchSpacer();
|
picker_sizer->AddStretchSpacer();
|
||||||
|
picker_sizer->Add(screen_dropper_icon, 0, wxALIGN_CENTER|wxRIGHT, 5);
|
||||||
picker_sizer->Add(screen_dropper, 0, wxALIGN_CENTER);
|
picker_sizer->Add(screen_dropper, 0, wxALIGN_CENTER);
|
||||||
picker_sizer->AddStretchSpacer();
|
picker_sizer->AddStretchSpacer();
|
||||||
picker_sizer->Add(recent_box, 0, wxALIGN_CENTER);
|
picker_sizer->Add(recent_box, 0, wxALIGN_CENTER);
|
||||||
picker_sizer->AddStretchSpacer();
|
picker_sizer->AddStretchSpacer();
|
||||||
|
|
||||||
wxStdDialogButtonSizer *button_sizer = new wxStdDialogButtonSizer();
|
wxSizer *button_sizer = CreateStdDialogButtonSizer(wxOK|wxCANCEL);
|
||||||
button_sizer->AddButton(ok_button);
|
|
||||||
button_sizer->AddButton(cancel_button);
|
|
||||||
button_sizer->Realize();
|
|
||||||
|
|
||||||
wxSizer *input_sizer = new wxBoxSizer(wxVERTICAL);
|
wxSizer *input_sizer = new wxBoxSizer(wxVERTICAL);
|
||||||
input_sizer->Add(rgb_box, 0, wxALIGN_CENTER|wxEXPAND);
|
input_sizer->Add(rgb_box, 0, wxALIGN_CENTER|wxEXPAND);
|
||||||
|
@ -573,6 +577,12 @@ DialogColorPicker::DialogColorPicker(wxWindow *parent, wxColour initial_color)
|
||||||
colorspace_choice->SetSelection(mode);
|
colorspace_choice->SetSelection(mode);
|
||||||
SetColor(initial_color);
|
SetColor(initial_color);
|
||||||
recent_box->LoadFromString(Options.AsText(_T("Color Picker Recent")));
|
recent_box->LoadFromString(Options.AsText(_T("Color Picker Recent")));
|
||||||
|
|
||||||
|
// The mouse event handler for the Dropper control must be manually assigned
|
||||||
|
// The EVT_MOUSE_EVENTS macro can't take a control id
|
||||||
|
screen_dropper_icon->Connect(wxEVT_MOTION, wxMouseEventHandler(DialogColorPicker::OnDropperMouse), 0, this);
|
||||||
|
screen_dropper_icon->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(DialogColorPicker::OnDropperMouse), 0, this);
|
||||||
|
screen_dropper_icon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(DialogColorPicker::OnDropperMouse), 0, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -964,7 +974,7 @@ BEGIN_EVENT_TABLE(DialogColorPicker, wxDialog)
|
||||||
EVT_COMMAND(SELECTOR_SPECTRUM, wxSPECTRUM_CHANGE, DialogColorPicker::OnSpectrumChange)
|
EVT_COMMAND(SELECTOR_SPECTRUM, wxSPECTRUM_CHANGE, DialogColorPicker::OnSpectrumChange)
|
||||||
EVT_COMMAND(SELECTOR_SLIDER, wxSPECTRUM_CHANGE, DialogColorPicker::OnSliderChange)
|
EVT_COMMAND(SELECTOR_SLIDER, wxSPECTRUM_CHANGE, DialogColorPicker::OnSliderChange)
|
||||||
EVT_COMMAND(SELECTOR_RECENT, wxRECENT_SELECT, DialogColorPicker::OnRecentSelect)
|
EVT_COMMAND(SELECTOR_RECENT, wxRECENT_SELECT, DialogColorPicker::OnRecentSelect)
|
||||||
EVT_COMMAND(SELECTOR_DROPPER, wxDROPPER_SELECT, DialogColorPicker::OnRecentSelect)
|
EVT_COMMAND(SELECTOR_DROPPER_PICK, wxDROPPER_SELECT, DialogColorPicker::OnRecentSelect)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
|
||||||
|
@ -1114,10 +1124,52 @@ void DialogColorPicker::OnSliderChange(wxCommandEvent &evt)
|
||||||
|
|
||||||
void DialogColorPicker::OnRecentSelect(wxCommandEvent &evt)
|
void DialogColorPicker::OnRecentSelect(wxCommandEvent &evt)
|
||||||
{
|
{
|
||||||
|
// The colour picked is stored in the event string
|
||||||
|
// Allows this event handler to be shared by recent and dropper controls
|
||||||
|
// Ugly hack?
|
||||||
AssColor color;
|
AssColor color;
|
||||||
color.Parse(evt.GetString());
|
color.Parse(evt.GetString());
|
||||||
SetColor(color.GetWXColor());
|
SetColor(color.GetWXColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DialogColorPicker::OnDropperMouse(wxMouseEvent &evt)
|
||||||
|
{
|
||||||
|
if (evt.LeftDown()) {
|
||||||
|
if (screen_dropper_icon->HasCapture()) {
|
||||||
|
release_capture:
|
||||||
|
screen_dropper_icon->ReleaseMouse();
|
||||||
|
screen_dropper_icon->SetCursor(wxNullCursor);
|
||||||
|
screen_dropper_icon->SetBitmap(eyedropper_bitmap);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
screen_dropper_icon->CaptureMouse();
|
||||||
|
eyedropper_grab_point = evt.GetPosition();
|
||||||
|
#ifdef WIN32
|
||||||
|
screen_dropper_icon->SetCursor(wxCursor(_T("eyedropper_cursor")));
|
||||||
|
#else
|
||||||
|
screen_dropper_icon->SetCursor(*wxCROSS_CURSOR);
|
||||||
|
#endif
|
||||||
|
screen_dropper_icon->SetBitmap(wxNullBitmap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (evt.LeftUp()) {
|
||||||
|
#define ABS(x) (x < 0 ? -x : x)
|
||||||
|
wxPoint ptdiff = evt.GetPosition() - eyedropper_grab_point;
|
||||||
|
if (ABS(ptdiff.x) + ABS(ptdiff.y) > 7)
|
||||||
|
goto release_capture;
|
||||||
|
// test failed, didn't move enough distance to "drag-grab" the tool
|
||||||
|
// treat this as a click
|
||||||
|
}
|
||||||
|
|
||||||
|
if (screen_dropper_icon->HasCapture()) {
|
||||||
|
wxPoint scrpos = screen_dropper_icon->ClientToScreen(evt.GetPosition());
|
||||||
|
screen_dropper->DropFromScreenXY(scrpos.x, scrpos.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Static values for last position of the dialog in this Aegisub session
|
||||||
int DialogColorPicker::lastx = -1;
|
int DialogColorPicker::lastx = -1;
|
||||||
int DialogColorPicker::lasty = -1;
|
int DialogColorPicker::lasty = -1;
|
|
@ -105,12 +105,15 @@ private:
|
||||||
wxBitmap capture;
|
wxBitmap capture;
|
||||||
int resx, resy;
|
int resx, resy;
|
||||||
int magnification;
|
int magnification;
|
||||||
|
bool integrated_dropper;
|
||||||
|
|
||||||
void OnMouse(wxMouseEvent &evt);
|
void OnMouse(wxMouseEvent &evt);
|
||||||
void OnPaint(wxPaintEvent &evt);
|
void OnPaint(wxPaintEvent &evt);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ColorPickerScreenDropper(wxWindow *parent, wxWindowID id, int _resx, int _resy, int _magnification);
|
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_TABLE()
|
||||||
};
|
};
|
||||||
|
@ -146,6 +149,9 @@ private:
|
||||||
wxBitmap *hsv_spectrum; // s/v spectrum
|
wxBitmap *hsv_spectrum; // s/v spectrum
|
||||||
wxBitmap *hsv_slider; // h spectrum
|
wxBitmap *hsv_slider; // h spectrum
|
||||||
|
|
||||||
|
wxBitmap eyedropper_bitmap;
|
||||||
|
wxPoint eyedropper_grab_point;
|
||||||
|
|
||||||
wxTextCtrl *ass_input; // ASS hex format input
|
wxTextCtrl *ass_input; // ASS hex format input
|
||||||
wxTextCtrl *html_input; // HTML hex format input
|
wxTextCtrl *html_input; // HTML hex format input
|
||||||
|
|
||||||
|
@ -154,9 +160,7 @@ private:
|
||||||
wxBitmap preview_bitmap;
|
wxBitmap preview_bitmap;
|
||||||
ColorPickerRecent *recent_box;
|
ColorPickerRecent *recent_box;
|
||||||
ColorPickerScreenDropper *screen_dropper;
|
ColorPickerScreenDropper *screen_dropper;
|
||||||
|
wxStaticBitmap *screen_dropper_icon;
|
||||||
wxButton *ok_button;
|
|
||||||
wxButton *cancel_button;
|
|
||||||
|
|
||||||
void UpdateFromRGB(); // Update all other controls as a result of modifying an RGB control
|
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 UpdateFromHSL(); // Update all other controls as a result of modifying an HSL control
|
||||||
|
@ -182,7 +186,8 @@ private:
|
||||||
void OnChangeMode(wxCommandEvent &evt);
|
void OnChangeMode(wxCommandEvent &evt);
|
||||||
void OnSpectrumChange(wxCommandEvent &evt);
|
void OnSpectrumChange(wxCommandEvent &evt);
|
||||||
void OnSliderChange(wxCommandEvent &evt);
|
void OnSliderChange(wxCommandEvent &evt);
|
||||||
void OnRecentSelect(wxCommandEvent &evt);
|
void OnRecentSelect(wxCommandEvent &evt); // also handles dropper pick
|
||||||
|
void OnDropperMouse(wxMouseEvent &evt);
|
||||||
|
|
||||||
static int lastx, lasty;
|
static int lastx, lasty;
|
||||||
|
|
||||||
|
@ -213,7 +218,8 @@ enum {
|
||||||
SELECTOR_ASS_INPUT,
|
SELECTOR_ASS_INPUT,
|
||||||
SELECTOR_HTML_INPUT,
|
SELECTOR_HTML_INPUT,
|
||||||
SELECTOR_RECENT,
|
SELECTOR_RECENT,
|
||||||
SELECTOR_DROPPER
|
SELECTOR_DROPPER,
|
||||||
|
SELECTOR_DROPPER_PICK,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,10 @@
|
||||||
// Contact: mailto:zeratul@cellosoft.com
|
// Contact: mailto:zeratul@cellosoft.com
|
||||||
//
|
//
|
||||||
|
|
||||||
|
// main app icon should always be first
|
||||||
|
// (windows explorer uses the first icon resource by default)
|
||||||
|
wxicon ICON "bitmaps/icon.ico"
|
||||||
|
|
||||||
blank_button BITMAP "bitmaps/blank.bmp"
|
blank_button BITMAP "bitmaps/blank.bmp"
|
||||||
|
|
||||||
new_toolbutton BITMAP "bitmaps/new.bmp"
|
new_toolbutton BITMAP "bitmaps/new.bmp"
|
||||||
|
@ -145,8 +149,10 @@ arrow_up_stop BITMAP "bitmaps/arrow_up_stop.bmp"
|
||||||
arrow_down_stop BITMAP "bitmaps/arrow_down_stop.bmp"
|
arrow_down_stop BITMAP "bitmaps/arrow_down_stop.bmp"
|
||||||
arrow_sort BITMAP "bitmaps/arrow_sort.bmp"
|
arrow_sort BITMAP "bitmaps/arrow_sort.bmp"
|
||||||
|
|
||||||
|
eyedropper_tool BITMAP "bitmaps/eyedropper.bmp"
|
||||||
|
//eyedropper_icon ICON "bitmaps/eyedropper.ico"
|
||||||
|
eyedropper_cursor CURSOR "bitmaps/eyedropper.cur"
|
||||||
|
|
||||||
splash BITMAP "bitmaps/splash.bmp"
|
splash BITMAP "bitmaps/splash.bmp"
|
||||||
|
|
||||||
wxicon ICON "bitmaps/icon.ico"
|
|
||||||
|
|
||||||
#include "wx/msw/wx.rc"
|
#include "wx/msw/wx.rc"
|
||||||
|
|
Loading…
Reference in a new issue