1
// Copyright (c) 2005, Niels Martin Hansen
2
// All rights reserved.
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are met:
7
// * Redistributions of source code must retain the above copyright notice,
8
// this list of conditions and the following disclaimer.
9
// * Redistributions in binary form must reproduce the above copyright notice,
10
// this list of conditions and the following disclaimer in the documentation
11
// and/or other materials provided with the distribution.
12
// * Neither the name of the Aegisub Group nor the names of its contributors
13
// may be used to endorse or promote products derived from this software
14
// without specific prior written permission.
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
// POSSIBILITY OF SUCH DAMAGE.
28
// -----------------------------------------------------------------------------
32
// Website: http://aegisub.cellosoft.com
33
// Contact: mailto:zeratul@cellosoft.com
39
#include <wx/statbox.h>
40
#include <wx/stattext.h>
42
#include <wx/gbsizer.h>
44
#include <wx/tokenzr.h>
45
#include <wx/dcclient.h>
46
#include <wx/dcmemory.h>
47
#include <wx/dcscreen.h>
48
#include <wx/settings.h>
49
#include <wx/clipbrd.h>
50
#include "dialog_colorpicker.h"
51
#include "colorspace.h"
52
#include "ass_style.h"
54
#include "help_button.h"
61
#define STATIC_BORDER_FLAG wxSTATIC_BORDER
63
#define STATIC_BORDER_FLAG wxSIMPLE_BORDER
67
static const int spectrum_horz_vert_arrow_size = 4;
69
ColorPickerSpectrum::ColorPickerSpectrum(wxWindow *parent, wxWindowID id, wxBitmap *_background, int xx, int yy, PickerDirection _direction, wxSize _size)
70
: wxControl(parent, id, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE), x(xx), y(yy), background(_background), direction(_direction)
75
if (direction == Vert) _size.x += spectrum_horz_vert_arrow_size + 1;
76
if (direction == Horz) _size.y += spectrum_horz_vert_arrow_size + 1;
79
SetMinSize(GetSize());
82
void ColorPickerSpectrum::GetXY(int &xx, int &yy)
88
void ColorPickerSpectrum::SetXY(int xx, int yy)
95
void ColorPickerSpectrum::SetBackground(wxBitmap *new_background)
97
if (background == new_background) return;
98
background = new_background;
102
BEGIN_EVENT_TABLE(ColorPickerSpectrum, wxControl)
103
EVT_PAINT(ColorPickerSpectrum::OnPaint)
104
EVT_MOUSE_EVENTS(ColorPickerSpectrum::OnMouse)
107
DEFINE_EVENT_TYPE(wxSPECTRUM_CHANGE)
109
void ColorPickerSpectrum::OnPaint(wxPaintEvent &evt)
111
if (!background) return;
116
memdc.SelectObject(*background);
117
dc.Blit(1, 1, background->GetWidth(), background->GetHeight(), &memdc, 0, 0);
119
wxPen invpen(*wxWHITE, 3);
120
invpen.SetCap(wxCAP_BUTT);
121
wxPen blkpen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), 1);
122
blkpen.SetCap(wxCAP_BUTT);
126
dc.SetLogicalFunction(wxXOR);
130
// Make a little cross
131
dc.DrawLine(x-4, y+1, x+7, y+1);
132
dc.DrawLine(x+1, y-4, x+1, y+7);
135
// Make a vertical line stretching all the way across
136
dc.DrawLine(x+1, 1, x+1, background->GetHeight()+1);
138
arrow[0] = wxPoint(x+1, background->GetHeight()+2);
139
arrow[1] = wxPoint(x+1-spectrum_horz_vert_arrow_size, background->GetHeight()+2+spectrum_horz_vert_arrow_size);
140
arrow[2] = wxPoint(x+1+spectrum_horz_vert_arrow_size, background->GetHeight()+2+spectrum_horz_vert_arrow_size);
143
// Make a horizontal line stretching all the way across
144
dc.DrawLine(1, y+1, background->GetWidth()+1, y+1);
146
arrow[0] = wxPoint(background->GetWidth()+2, y+1);
147
arrow[1] = wxPoint(background->GetWidth()+2+spectrum_horz_vert_arrow_size, y+1-spectrum_horz_vert_arrow_size);
148
arrow[2] = wxPoint(background->GetWidth()+2+spectrum_horz_vert_arrow_size, y+1+spectrum_horz_vert_arrow_size);
152
if (direction == Horz || direction == Vert) {
153
// Arrow pointing at current point
154
dc.SetLogicalFunction(wxCOPY);
155
dc.SetPen(*wxTRANSPARENT_PEN);
156
dc.SetBrush(*wxBLACK_BRUSH);
157
dc.DrawPolygon(3, arrow);
160
// Border around the spectrum
161
dc.SetLogicalFunction(wxCOPY);
163
dc.SetBrush(*wxTRANSPARENT_BRUSH);
164
dc.DrawRectangle(0, 0, background->GetWidth()+2, background->GetHeight()+2);
167
void ColorPickerSpectrum::OnMouse(wxMouseEvent &evt)
171
if (!evt.IsButton() && !evt.Dragging()) {
175
int newx = evt.GetX();
176
if (newx < 0) newx = 0;
177
if (newx >= GetClientSize().x) newx = GetClientSize().x-1;
178
int newy = evt.GetY();
179
if (newy < 0) newy = 0;
180
if (newy >= GetClientSize().y) newy = GetClientSize().y-1;
182
if (evt.LeftDown()) {
184
SetCursor(wxCursor(wxCURSOR_BLANK));
185
} else if (evt.LeftUp() && HasCapture()) {
187
SetCursor(wxNullCursor);
190
if (evt.LeftDown() || (HasCapture() && evt.LeftIsDown())) {
194
wxCommandEvent evt2(wxSPECTRUM_CHANGE, GetId());
195
AddPendingEvent(evt2);
201
ColorPickerRecent::ColorPickerRecent(wxWindow *parent, wxWindowID id, int _cols, int _rows, int _cellsize)
202
: wxControl(parent, id, wxDefaultPosition, wxDefaultSize, STATIC_BORDER_FLAG)
205
, cellsize(_cellsize)
206
, internal_control_offset(0,0)
207
, background_valid(false)
210
LoadFromString(wxEmptyString);
211
SetClientSize(cols*cellsize, rows*cellsize);
212
SetMinSize(GetSize());
213
SetMaxSize(GetSize());
214
SetCursor(*wxCROSS_CURSOR);
217
void ColorPickerRecent::LoadFromString(const wxString &recent_string)
220
wxStringTokenizer toker(recent_string, _T(" "), false);
221
while (toker.HasMoreTokens()) {
223
color.Parse(toker.NextToken());
224
color.a = 0; // opaque
225
colors.push_back(color.GetWXColor());
227
while ((int)colors.size() < rows*cols) {
228
colors.push_back(*wxBLACK);
231
background_valid = false;
234
wxString ColorPickerRecent::StoreToString()
237
for (int i = 0; i < rows*cols; i++) {
238
AssColor color(colors[i]);
239
res << color.GetASSFormatted(false, false, false) << _T(" ");
245
void ColorPickerRecent::AddColor(wxColour color)
247
for (std::vector<wxColor>::iterator i = colors.begin(); i != colors.end(); ++i) {
254
colors.insert(colors.begin(), color);
256
background_valid = false;
261
BEGIN_EVENT_TABLE(ColorPickerRecent, wxControl)
262
EVT_PAINT(ColorPickerRecent::OnPaint)
263
EVT_LEFT_DOWN(ColorPickerRecent::OnClick)
264
EVT_SIZE(ColorPickerRecent::OnSize)
267
DEFINE_EVENT_TYPE(wxRECENT_SELECT)
269
void ColorPickerRecent::OnClick(wxMouseEvent &evt)
272
wxSize cs = GetClientSize();
273
cx = (evt.GetX() - internal_control_offset.x) * cols / cs.x;
274
cy = (evt.GetY() - internal_control_offset.y) * rows / cs.y;
275
if (cx < 0 || cx > cols || cy < 0 || cy > rows) return;
277
if (i >= 0 && i < (int)colors.size()) {
278
AssColor color(colors[i]);
279
wxCommandEvent evt(wxRECENT_SELECT, GetId());
280
evt.SetString(color.GetASSFormatted(false, false, false));
281
AddPendingEvent(evt);
285
void ColorPickerRecent::OnPaint(wxPaintEvent &evt)
290
if (!background_valid) {
291
wxSize sz = pdc.GetSize();
293
background = wxBitmap(sz.x, sz.y);
294
wxMemoryDC dc(background);
297
dc.SetPen(*wxTRANSPARENT_PEN);
299
for (int cy = 0; cy < rows; cy++) {
300
for (int cx = 0; cx < cols; cx++) {
302
x = cx * cellsize + internal_control_offset.x;
303
y = cy * cellsize + internal_control_offset.y;
305
dc.SetBrush(wxBrush(colors[i]));
306
dc.DrawRectangle(x, y, x+cellsize, y+cellsize);
312
background_valid = true;
315
pdc.DrawBitmap(background, 0, 0, false);
318
void ColorPickerRecent::OnSize(wxSizeEvent &evt)
320
wxSize size = GetClientSize();
321
background_valid = false;
322
//internal_control_offset.x = (size.GetWidth() - cellsize * cols) / 2;
323
//internal_control_offset.y = (size.GetHeight() - cellsize * rows) / 2;
329
ColorPickerScreenDropper::ColorPickerScreenDropper(wxWindow *parent, wxWindowID id, int _resx, int _resy, int _magnification, bool _integrated_dropper)
330
: wxControl(parent, id, wxDefaultPosition, wxDefaultSize, STATIC_BORDER_FLAG), resx(_resx), resy(_resy), magnification(_magnification), integrated_dropper(_integrated_dropper)
332
SetClientSize(resx*magnification, resy*magnification);
333
SetMinSize(GetSize());
334
SetMaxSize(GetSize());
335
SetCursor(*wxCROSS_CURSOR);
337
capture = wxBitmap(resx, resy);
339
capdc.SelectObject(capture);
340
capdc.SetPen(*wxTRANSPARENT_PEN);
341
capdc.SetBrush(*wxWHITE_BRUSH);
342
capdc.DrawRectangle(0, 0, resx, resy);
345
BEGIN_EVENT_TABLE(ColorPickerScreenDropper, wxControl)
346
EVT_PAINT(ColorPickerScreenDropper::OnPaint)
347
EVT_MOUSE_EVENTS(ColorPickerScreenDropper::OnMouse)
350
DEFINE_EVENT_TYPE(wxDROPPER_SELECT)
352
void ColorPickerScreenDropper::OnMouse(wxMouseEvent &evt)
355
x = evt.GetX() / magnification;
356
y = evt.GetY() / magnification;
358
if (HasCapture() && evt.LeftIsDown()) {
360
wxPoint pos = ClientToScreen(evt.GetPosition());
361
DropFromScreenXY(pos.x, pos.y);
363
} else if (evt.LeftDown()) {
365
if (x == 0 && y == 0 && integrated_dropper) {
366
//SetCursor(*wxCROSS_CURSOR);
369
} else if (x >= 0 && y >= 0 && x < resx && y < resy) {
372
// wxMemoryDC::GetPixel() isn't implemented on OS X
373
// Work around it by reading pixel data from the bitmap instead
374
wxAlphaPixelData cappd(capture);
375
wxAlphaPixelData::Iterator cappdi(cappd);
376
cappdi.MoveTo(cappd, x, y);
377
color.Set(cappdi.Red(), cappdi.Green(), cappdi.Blue());
379
wxMemoryDC capdc(capture);
380
capdc.GetPixel(x, y, &color);
382
color = wxColour(color.Red(), color.Green(), color.Blue(), wxALPHA_OPAQUE);
384
wxCommandEvent evt(wxDROPPER_SELECT, GetId());
385
evt.SetString(ass.GetASSFormatted(false, false, false));
386
AddPendingEvent(evt);
389
} else if (HasCapture() && evt.LeftUp()) {
391
//SetCursor(wxNullCursor);
395
void ColorPickerScreenDropper::OnPaint(wxPaintEvent &evt)
400
// See OnMouse() above
401
wxAlphaPixelData cappd(capture);
402
wxAlphaPixelData::Iterator cappdi(cappd);
404
wxMemoryDC capdc(capture);
407
pdc.SetPen(*wxTRANSPARENT_PEN);
409
for (int x = 0; x < resx; x++) {
410
for (int y = 0; y < resy; y++) {
411
if (x==0 && y==0 && integrated_dropper) continue;
415
cappdi.MoveTo(cappd, x, y);
416
color.Set(cappdi.Red(), cappdi.Green(), cappdi.Blue());
418
capdc.GetPixel(x, y, &color);
420
pdc.SetBrush(wxBrush(color));
422
pdc.DrawRectangle(x*magnification, y*magnification, magnification, magnification);
426
if (integrated_dropper) {
427
wxBrush cbrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
428
pdc.SetBrush(cbrush);
429
pdc.DrawRectangle(0, 0, magnification, magnification);
430
cbrush.SetStyle(wxCROSSDIAG_HATCH);
431
cbrush.SetColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
432
pdc.SetBrush(cbrush);
433
pdc.DrawRectangle(0, 0, magnification, magnification);
439
void ColorPickerScreenDropper::DropFromScreenXY(int x, int y)
441
wxMemoryDC capdc(capture);
445
wxBitmap screenbmp = screen.GetAsBitmap().GetSubBitmap(wxRect(x-resx/2, y-resy/2, resx, resy));
446
capdc.DrawBitmap(screenbmp, 0, 0);
448
screen.StartDrawingOnTop();
449
capdc.Blit(0, 0, resx, resy, &screen, x-resx/2, y-resy/2);
450
screen.EndDrawingOnTop();
458
wxColour GetColorFromUser(wxWindow *parent, wxColour original)
460
DialogColorPicker dialog(parent, original);
461
if (dialog.ShowModal() == wxID_OK) {
462
return dialog.GetColor();
470
DialogColorPicker::DialogColorPicker(wxWindow *parent, wxColour initial_color)
471
: wxDialog(parent, -1, _("Select Colour"), wxDefaultPosition, wxDefaultSize)
478
spectrum_dirty = true;
480
// generate spectrum slider bar images
481
wxImage sliderimg(slider_width, 256, true);
482
unsigned char *oslid, *slid;
485
oslid = slid = (unsigned char *)malloc(slider_width*256*3);
486
for (int y = 0; y < 256; y++) {
487
for (int x = 0; x < slider_width; x++) {
488
*slid++ = clip_colorval(y);
493
sliderimg.SetData(oslid);
494
rgb_slider[0] = new wxBitmap(sliderimg);
497
oslid = slid = (unsigned char *)malloc(slider_width*256*3);
498
for (int y = 0; y < 256; y++) {
499
for (int x = 0; x < slider_width; x++) {
501
*slid++ = clip_colorval(y);
505
sliderimg.SetData(oslid);
506
rgb_slider[1] = new wxBitmap(sliderimg);
509
oslid = slid = (unsigned char *)malloc(slider_width*256*3);
510
for (int y = 0; y < 256; y++) {
511
for (int x = 0; x < slider_width; x++) {
514
*slid++ = clip_colorval(y);
517
sliderimg.SetData(oslid);
518
rgb_slider[2] = new wxBitmap(sliderimg);
521
oslid = slid = (unsigned char *)malloc(slider_width*256*3);
522
for (int y = 0; y < 256; y++) {
524
for (; x < slider_width; x++) {
525
*slid++ = clip_colorval(y);
526
*slid++ = clip_colorval(y);
527
*slid++ = clip_colorval(y);
530
sliderimg.SetData(oslid);
531
hsl_slider = new wxBitmap(sliderimg);
533
oslid = slid = (unsigned char *)malloc(slider_width*256*3);
534
for (int y = 0; y < 256; y++) {
535
for (int x = 0; x < slider_width; x++) {
536
hsv_to_rgb(y, 255, 255, slid, slid+1, slid+2);
540
sliderimg.SetData(oslid);
541
hsv_slider = new wxBitmap(sliderimg);
543
// Create the controls for the dialog
544
wxSizer *spectrum_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Colour spectrum"));
545
spectrum = new ColorPickerSpectrum(this, SELECTOR_SPECTRUM, 0, -1, -1, ColorPickerSpectrum::HorzVert, wxSize(256, 256));
546
slider = new ColorPickerSpectrum(this, SELECTOR_SLIDER, 0, -1, -1, ColorPickerSpectrum::Vert, wxSize(slider_width, 256));
547
wxString modes[] = { _("RGB/R"), _("RGB/G"), _("RGB/B"), _("HSL/L"), _("HSV/H") };
548
colorspace_choice = new wxChoice(this, SELECTOR_MODE, wxDefaultPosition, wxDefaultSize, 5, modes);
550
wxSize colorinput_size(70, -1);
551
wxSize colorinput_labelsize(40, -1);
553
wxSizer *rgb_box = new wxStaticBoxSizer(wxHORIZONTAL, this, _("RGB colour"));
554
rgb_input[0] = new wxSpinCtrl(this, SELECTOR_RGB_R, _T(""), wxDefaultPosition, colorinput_size, wxSP_ARROW_KEYS, 0, 255);
555
rgb_input[1] = new wxSpinCtrl(this, SELECTOR_RGB_G, _T(""), wxDefaultPosition, colorinput_size, wxSP_ARROW_KEYS, 0, 255);
556
rgb_input[2] = new wxSpinCtrl(this, SELECTOR_RGB_B, _T(""), wxDefaultPosition, colorinput_size, wxSP_ARROW_KEYS, 0, 255);
558
wxSizer *hsl_box = new wxStaticBoxSizer(wxVERTICAL, this, _("HSL colour"));
559
hsl_input[0] = new wxSpinCtrl(this, SELECTOR_HSL_H, _T(""), wxDefaultPosition, colorinput_size, wxSP_ARROW_KEYS, 0, 255);
560
hsl_input[1] = new wxSpinCtrl(this, SELECTOR_HSL_S, _T(""), wxDefaultPosition, colorinput_size, wxSP_ARROW_KEYS, 0, 255);
561
hsl_input[2] = new wxSpinCtrl(this, SELECTOR_HSL_L, _T(""), wxDefaultPosition, colorinput_size, wxSP_ARROW_KEYS, 0, 255);
563
wxSizer *hsv_box = new wxStaticBoxSizer(wxVERTICAL, this, _("HSV colour"));
564
hsv_input[0] = new wxSpinCtrl(this, SELECTOR_HSV_H, _T(""), wxDefaultPosition, colorinput_size, wxSP_ARROW_KEYS, 0, 255);
565
hsv_input[1] = new wxSpinCtrl(this, SELECTOR_HSV_S, _T(""), wxDefaultPosition, colorinput_size, wxSP_ARROW_KEYS, 0, 255);
566
hsv_input[2] = new wxSpinCtrl(this, SELECTOR_HSV_V, _T(""), wxDefaultPosition, colorinput_size, wxSP_ARROW_KEYS, 0, 255);
568
ass_input = new wxTextCtrl(this, SELECTOR_ASS_INPUT, _T(""), wxDefaultPosition, colorinput_size);
569
html_input = new wxTextCtrl(this, SELECTOR_HTML_INPUT, _T(""), wxDefaultPosition, colorinput_size);
571
preview_bitmap = wxBitmap(40, 40, 24);
572
preview_box = new wxStaticBitmap(this, -1, preview_bitmap, wxDefaultPosition, wxSize(40, 40), STATIC_BORDER_FLAG);
574
recent_box = new ColorPickerRecent(this, SELECTOR_RECENT, 8, 4, 16);
576
eyedropper_bitmap = wxBITMAP(eyedropper_tool);
577
eyedropper_bitmap.SetMask(new wxMask(eyedropper_bitmap, wxColour(255, 0, 255)));
578
screen_dropper_icon = new wxStaticBitmap(this, SELECTOR_DROPPER, eyedropper_bitmap, wxDefaultPosition, wxDefaultSize, wxRAISED_BORDER);
579
screen_dropper = new ColorPickerScreenDropper(this, SELECTOR_DROPPER_PICK, 7, 7, 8, false);
581
// Arrange the controls in a nice way
582
wxSizer *spectop_sizer = new wxBoxSizer(wxHORIZONTAL);
583
spectop_sizer->Add(new wxStaticText(this, -1, _("Spectrum mode:")), 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxRIGHT, 5);
584
spectop_sizer->Add(colorspace_choice, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT);
585
spectop_sizer->Add(5, 5, 1, wxEXPAND);
586
spectop_sizer->Add(preview_box, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT);
587
wxSizer *spectrum_sizer = new wxFlexGridSizer(2, 5, 5);
588
spectrum_sizer->Add(spectop_sizer, wxEXPAND);
589
spectrum_sizer->AddStretchSpacer(1);
590
spectrum_sizer->Add(spectrum);
591
spectrum_sizer->Add(slider);
592
spectrum_box->Add(spectrum_sizer, 0, wxALL, 3);
594
wxFlexGridSizer *rgb_sizer = new wxFlexGridSizer(2, 5, 5);
595
rgb_sizer->Add(new wxStaticText(this, -1, _("Red:"), wxDefaultPosition, colorinput_labelsize), 1, wxALIGN_CENTER_VERTICAL|wxEXPAND);
596
rgb_sizer->Add(rgb_input[0], 0);
597
rgb_sizer->Add(new wxStaticText(this, -1, _("Green:"), wxDefaultPosition, colorinput_labelsize), 1, wxALIGN_CENTER_VERTICAL|wxEXPAND);
598
rgb_sizer->Add(rgb_input[1], 0);
599
rgb_sizer->Add(new wxStaticText(this, -1, _("Blue:"), wxDefaultPosition, colorinput_labelsize), 1, wxALIGN_CENTER_VERTICAL|wxEXPAND);
600
rgb_sizer->Add(rgb_input[2], 0);
601
rgb_sizer->AddGrowableCol(0,1);
602
rgb_box->Add(rgb_sizer, 1, wxEXPAND | wxALL, 3);
604
wxFlexGridSizer *ass_input_sizer = new wxFlexGridSizer(2, 5, 5);
605
ass_input_sizer->Add(new wxStaticText(this, -1, _T("ASS:"), wxDefaultPosition, colorinput_labelsize), 1, wxALIGN_CENTER_VERTICAL|wxEXPAND);
606
ass_input_sizer->Add(ass_input, 0);
607
ass_input_sizer->Add(new wxStaticText(this, -1, _T("HTML:"), wxDefaultPosition, colorinput_labelsize), 1, wxALIGN_CENTER_VERTICAL|wxEXPAND);
608
ass_input_sizer->Add(html_input, 0);
609
ass_input_sizer->AddStretchSpacer();
610
ass_input_sizer->AddGrowableCol(0,1);
611
rgb_box->Add(ass_input_sizer, 0, wxALL|wxCENTER|wxEXPAND, 3);
613
wxFlexGridSizer *hsl_sizer = new wxFlexGridSizer(2, 5, 5);
614
hsl_sizer->Add(new wxStaticText(this, -1, _("Hue:"), wxDefaultPosition, colorinput_labelsize), 1, wxALIGN_CENTER_VERTICAL|wxEXPAND);
615
hsl_sizer->Add(hsl_input[0], 0);
616
hsl_sizer->Add(new wxStaticText(this, -1, _("Sat.:"), wxDefaultPosition, colorinput_labelsize), 1, wxALIGN_CENTER_VERTICAL|wxEXPAND);
617
hsl_sizer->Add(hsl_input[1], 0);
618
hsl_sizer->Add(new wxStaticText(this, -1, _("Lum.:"), wxDefaultPosition, colorinput_labelsize), 1, wxALIGN_CENTER_VERTICAL|wxEXPAND);
619
hsl_sizer->Add(hsl_input[2], 0);
620
hsl_sizer->AddGrowableCol(0,1);
621
hsl_box->Add(hsl_sizer, 0, wxALL|wxEXPAND, 3);
623
wxFlexGridSizer *hsv_sizer = new wxFlexGridSizer(2, 5, 5);
624
hsv_sizer->Add(new wxStaticText(this, -1, _("Hue:"), wxDefaultPosition, colorinput_labelsize), 1, wxALIGN_CENTER_VERTICAL|wxEXPAND);
625
hsv_sizer->Add(hsv_input[0], 0);
626
hsv_sizer->Add(new wxStaticText(this, -1, _("Sat.:"), wxDefaultPosition, colorinput_labelsize), 1, wxALIGN_CENTER_VERTICAL|wxEXPAND);
627
hsv_sizer->Add(hsv_input[1], 0);
628
hsv_sizer->Add(new wxStaticText(this, -1, _("Value:"), wxDefaultPosition, colorinput_labelsize), 1, wxALIGN_CENTER_VERTICAL|wxEXPAND);
629
hsv_sizer->Add(hsv_input[2], 0);
630
hsv_sizer->AddGrowableCol(0,1);
631
hsv_box->Add(hsv_sizer, 0, wxALL|wxEXPAND, 3);
633
wxSizer *hsx_sizer = new wxBoxSizer(wxHORIZONTAL);
634
hsx_sizer->Add(hsl_box);
635
hsx_sizer->AddSpacer(5);
636
hsx_sizer->Add(hsv_box);
638
wxSizer *recent_sizer = new wxBoxSizer(wxVERTICAL);
639
recent_sizer->Add(recent_box, 1, wxEXPAND);
640
if (Options.AsBool(_T("RGBAdjust Tool"))) recent_sizer->Add(new wxButton(this,BUTTON_RGBADJUST,_T("rgbadjust()")), 0, wxEXPAND);
642
wxSizer *picker_sizer = new wxBoxSizer(wxHORIZONTAL);
643
picker_sizer->AddStretchSpacer();
644
picker_sizer->Add(screen_dropper_icon, 0, wxALIGN_CENTER|wxRIGHT, 5);
645
picker_sizer->Add(screen_dropper, 0, wxALIGN_CENTER);
646
picker_sizer->AddStretchSpacer();
647
picker_sizer->Add(recent_sizer, 0, wxALIGN_CENTER);
648
picker_sizer->AddStretchSpacer();
650
wxStdDialogButtonSizer *button_sizer = new wxStdDialogButtonSizer();
651
button_sizer->AddButton(new wxButton(this,wxID_OK));
652
button_sizer->AddButton(new wxButton(this,wxID_CANCEL));
653
button_sizer->AddButton(new HelpButton(this,_("Colour Picker")));
654
button_sizer->Realize();
656
wxSizer *input_sizer = new wxBoxSizer(wxVERTICAL);
657
input_sizer->Add(rgb_box, 0, wxALIGN_CENTER|wxEXPAND);
658
input_sizer->AddSpacer(5);
659
input_sizer->Add(hsx_sizer, 0, wxALIGN_CENTER|wxEXPAND);
660
input_sizer->AddStretchSpacer(1);
661
input_sizer->Add(picker_sizer, 0, wxALIGN_CENTER|wxEXPAND);
662
input_sizer->AddStretchSpacer(2);
663
input_sizer->Add(button_sizer, 0, wxALIGN_RIGHT|wxALIGN_BOTTOM);
665
wxSizer *main_sizer = new wxBoxSizer(wxHORIZONTAL);
666
main_sizer->Add(spectrum_box, 1, wxALL | wxEXPAND, 5);
667
main_sizer->Add(input_sizer, 0, (wxALL&~wxLEFT)|wxEXPAND, 5);
669
SetSizer(main_sizer);
670
main_sizer->SetSizeHints(this);
672
ass_input->SetFocus();
675
if (lastx == -1 && lasty == -1) {
682
updating_controls = false;
683
int mode = Options.AsInt(_T("Color Picker Mode"));
684
if (mode < 0 || mode > 4) mode = 3; // HSL default
685
colorspace_choice->SetSelection(mode);
686
SetColor(initial_color);
687
recent_box->LoadFromString(Options.AsText(_T("Color Picker Recent")));
689
// The mouse event handler for the Dropper control must be manually assigned
690
// The EVT_MOUSE_EVENTS macro can't take a control id
691
screen_dropper_icon->Connect(wxEVT_MOTION, wxMouseEventHandler(DialogColorPicker::OnDropperMouse), 0, this);
692
screen_dropper_icon->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(DialogColorPicker::OnDropperMouse), 0, this);
693
screen_dropper_icon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(DialogColorPicker::OnDropperMouse), 0, this);
698
DialogColorPicker::~DialogColorPicker()
700
GetPosition(&lastx, &lasty);
702
delete rgb_spectrum[0];
703
delete rgb_spectrum[1];
704
delete rgb_spectrum[2];
707
delete rgb_slider[0];
708
delete rgb_slider[1];
709
delete rgb_slider[2];
713
if (screen_dropper_icon->HasCapture()) screen_dropper_icon->ReleaseMouse();
717
// Sets the currently selected color, and updates all controls
718
void DialogColorPicker::SetColor(wxColour new_color)
720
cur_color = new_color;
721
rgb_input[0]->SetValue(new_color.Red());
722
rgb_input[1]->SetValue(new_color.Green());
723
rgb_input[2]->SetValue(new_color.Blue());
728
// Get the currently selected color
729
wxColour DialogColorPicker::GetColor()
731
recent_box->AddColor(cur_color);
732
Options.SetText(_T("Color Picker Recent"), recent_box->StoreToString());
738
// Use the values entered in the RGB controls to update the other controls
739
void DialogColorPicker::UpdateFromRGB()
741
if (updating_controls) return;
742
updating_controls = true;
744
unsigned char r, g, b, h, s, l, h2, s2, v2;
745
r = rgb_input[0]->GetValue();
746
g = rgb_input[1]->GetValue();
747
b = rgb_input[2]->GetValue();
748
rgb_to_hsl(r, g, b, &h, &s, &l);
749
rgb_to_hsv(r, g, b, &h2, &s2, &v2);
750
hsl_input[0]->SetValue(h);
751
hsl_input[1]->SetValue(s);
752
hsl_input[2]->SetValue(l);
753
hsv_input[0]->SetValue(h2);
754
hsv_input[1]->SetValue(s2);
755
hsv_input[2]->SetValue(v2);
756
cur_color = wxColour(r, g, b, wxALPHA_OPAQUE);
757
ass_input->SetValue(AssColor(cur_color).GetASSFormatted(false, false, false));
758
html_input->SetValue(color_to_html(cur_color));
759
UpdateSpectrumDisplay();
761
updating_controls = false;
765
// Use the values entered in the HSL controls to update the other controls
766
void DialogColorPicker::UpdateFromHSL()
768
if (updating_controls) return;
769
updating_controls = true;
771
unsigned char r, g, b, h, s, l, h2, s2, v2;
772
h = hsl_input[0]->GetValue();
773
s = hsl_input[1]->GetValue();
774
l = hsl_input[2]->GetValue();
775
hsl_to_rgb(h, s, l, &r, &g, &b);
776
hsl_to_hsv(h, s, l, &h2, &s2, &v2);
777
rgb_input[0]->SetValue(r);
778
rgb_input[1]->SetValue(g);
779
rgb_input[2]->SetValue(b);
780
hsv_input[0]->SetValue(h2);
781
hsv_input[1]->SetValue(s2);
782
hsv_input[2]->SetValue(v2);
783
cur_color = wxColour(r, g, b, wxALPHA_OPAQUE);
784
ass_input->SetValue(AssColor(cur_color).GetASSFormatted(false, false, false));
785
html_input->SetValue(color_to_html(cur_color));
786
UpdateSpectrumDisplay();
788
updating_controls = false;
792
void DialogColorPicker::UpdateFromHSV()
794
if (updating_controls) return;
795
updating_controls = true;
797
unsigned char r, g, b, h, s, l, h2, s2, v2;
798
//int r, g, b, h2, s2, v2;
799
h2 = hsv_input[0]->GetValue();
800
s2 = hsv_input[1]->GetValue();
801
v2 = hsv_input[2]->GetValue();
802
hsv_to_rgb(h2, s2, v2, &r, &g, &b);
803
hsv_to_hsl(h2, s2, v2, &h, &s, &l);
804
rgb_input[0]->SetValue(r);
805
rgb_input[1]->SetValue(g);
806
rgb_input[2]->SetValue(b);
807
hsl_input[0]->SetValue(h);
808
hsl_input[1]->SetValue(s);
809
hsl_input[2]->SetValue(l);
810
cur_color = wxColour(r, g, b, wxALPHA_OPAQUE);
811
ass_input->SetValue(AssColor(cur_color).GetASSFormatted(false, false, false));
812
html_input->SetValue(color_to_html(cur_color));
813
UpdateSpectrumDisplay();
815
updating_controls = false;
819
// Use the value entered in the ASS hex control to update the other controls
820
void DialogColorPicker::UpdateFromASS()
822
if (updating_controls) return;
823
updating_controls = true;
825
unsigned char r, g, b, h, s, l, h2, s2, v2;
827
ass.Parse(ass_input->GetValue());
831
rgb_to_hsl(r, g, b, &h, &s, &l);
832
rgb_to_hsv(r, g, b, &h2, &s2, &v2);
833
rgb_input[0]->SetValue(r);
834
rgb_input[1]->SetValue(g);
835
rgb_input[2]->SetValue(b);
836
hsl_input[0]->SetValue(h);
837
hsl_input[1]->SetValue(s);
838
hsl_input[2]->SetValue(l);
839
hsv_input[0]->SetValue(h2);
840
hsv_input[1]->SetValue(s2);
841
hsv_input[2]->SetValue(v2);
842
cur_color = wxColour(r, g, b, wxALPHA_OPAQUE);
843
html_input->SetValue(color_to_html(cur_color));
844
UpdateSpectrumDisplay();
846
updating_controls = false;
850
void DialogColorPicker::UpdateFromHTML()
852
if (updating_controls) return;
853
updating_controls = true;
855
unsigned char r, g, b, h, s, l, h2, s2, v2;
856
cur_color = html_to_color(html_input->GetValue());
858
g = cur_color.Green();
859
b = cur_color.Blue();
860
rgb_to_hsl(r, g, b, &h, &s, &l);
861
rgb_to_hsv(r, g, b, &h2, &s2, &v2);
862
rgb_input[0]->SetValue(r);
863
rgb_input[1]->SetValue(g);
864
rgb_input[2]->SetValue(b);
865
hsl_input[0]->SetValue(h);
866
hsl_input[1]->SetValue(s);
867
hsl_input[2]->SetValue(l);
868
hsv_input[0]->SetValue(h2);
869
hsv_input[1]->SetValue(s2);
870
hsv_input[2]->SetValue(v2);
871
cur_color = wxColour(r, g, b, wxALPHA_OPAQUE);
872
ass_input->SetValue(AssColor(cur_color).GetASSFormatted(false, false, false));
873
UpdateSpectrumDisplay();
875
updating_controls = false;
879
void DialogColorPicker::UpdateSpectrumDisplay()
881
int i = colorspace_choice->GetSelection();
885
spectrum->SetBackground(MakeGBSpectrum());
886
slider->SetBackground(rgb_slider[0]);
887
slider->SetXY(0, rgb_input[0]->GetValue());
888
spectrum->SetXY(rgb_input[2]->GetValue(), rgb_input[1]->GetValue());
892
spectrum->SetBackground(MakeRBSpectrum());
893
slider->SetBackground(rgb_slider[1]);
894
slider->SetXY(0, rgb_input[1]->GetValue());
895
spectrum->SetXY(rgb_input[2]->GetValue(), rgb_input[0]->GetValue());
899
spectrum->SetBackground(MakeRGSpectrum());
900
slider->SetBackground(rgb_slider[2]);
901
slider->SetXY(0, rgb_input[2]->GetValue());
902
spectrum->SetXY(rgb_input[1]->GetValue(), rgb_input[0]->GetValue());
906
spectrum->SetBackground(MakeHSSpectrum());
907
slider->SetBackground(hsl_slider);
908
slider->SetXY(0, hsl_input[2]->GetValue());
909
spectrum->SetXY(hsl_input[1]->GetValue(), hsl_input[0]->GetValue());
913
spectrum->SetBackground(MakeSVSpectrum());
914
slider->SetBackground(hsv_slider);
915
slider->SetXY(0, hsv_input[0]->GetValue());
916
spectrum->SetXY(hsv_input[1]->GetValue(), hsv_input[2]->GetValue());
919
spectrum_dirty = false;
921
wxBitmap tempBmp = preview_box->GetBitmap();
923
wxMemoryDC previewdc;
924
previewdc.SelectObject(tempBmp);
925
previewdc.SetPen(*wxTRANSPARENT_PEN);
926
previewdc.SetBrush(wxBrush(cur_color));
927
previewdc.DrawRectangle(0, 0, 40, 40);
929
preview_box->SetBitmap(tempBmp);
933
wxBitmap *DialogColorPicker::MakeGBSpectrum()
935
if (rgb_spectrum[0]) delete rgb_spectrum[0];
937
wxImage spectrum_image(256, 256, false);
938
unsigned char *ospec, *spec;
940
ospec = spec = (unsigned char *)malloc(256*256*3);
941
for (int g = 0; g < 256; g++) {
942
for (int b = 0; b < 256; b++) {
943
*spec++ = cur_color.Red();
948
spectrum_image.SetData(ospec);
949
rgb_spectrum[0] = new wxBitmap(spectrum_image);
951
return rgb_spectrum[0];
955
wxBitmap *DialogColorPicker::MakeRBSpectrum()
957
if (rgb_spectrum[1]) delete rgb_spectrum[1];
959
wxImage spectrum_image(256, 256, false);
960
unsigned char *ospec, *spec;
962
ospec = spec = (unsigned char *)malloc(256*256*3);
963
for (int r = 0; r < 256; r++) {
964
for (int b = 0; b < 256; b++) {
966
*spec++ = cur_color.Green();
970
spectrum_image.SetData(ospec);
971
rgb_spectrum[1] = new wxBitmap(spectrum_image);
973
return rgb_spectrum[1];
977
wxBitmap *DialogColorPicker::MakeRGSpectrum()
979
if (rgb_spectrum[2]) delete rgb_spectrum[2];
981
wxImage spectrum_image(256, 256, false);
982
unsigned char *ospec, *spec;
984
ospec = spec = (unsigned char *)malloc(256*256*3);
985
for (int r = 0; r < 256; r++) {
986
for (int g = 0; g < 256; g++) {
989
*spec++ = cur_color.Blue();
992
spectrum_image.SetData(ospec);
993
rgb_spectrum[2] = new wxBitmap(spectrum_image);
995
return rgb_spectrum[2];
999
wxBitmap *DialogColorPicker::MakeHSSpectrum()
1001
if (hsl_spectrum) delete hsl_spectrum;
1003
wxImage spectrum_image(256, 256, false);
1004
unsigned char *ospec, *spec;
1006
ospec = spec = (unsigned char *)malloc(256*256*3);
1007
int l = hsl_input[2]->GetValue();
1009
for (int h = 0; h < 256; h++) {
1010
unsigned char maxr, maxg, maxb;
1011
hsl_to_rgb(h, 255, l, &maxr, &maxg, &maxb);
1013
for (int s = 0; s < 256; s++) {
1014
*spec++ = maxr * s / 256 + (255-s) * l / 256;
1015
*spec++ = maxg * s / 256 + (255-s) * l / 256;
1016
*spec++ = maxb * s / 256 + (255-s) * l / 256;
1019
spectrum_image.SetData(ospec);
1020
hsl_spectrum = new wxBitmap(spectrum_image);
1022
return hsl_spectrum;
1026
wxBitmap *DialogColorPicker::MakeSVSpectrum()
1028
if (hsv_spectrum) delete hsv_spectrum;
1030
wxImage spectrum_image(256, 256, false);
1031
unsigned char *ospec, *spec;
1033
ospec = spec = (unsigned char *)malloc(256*256*3);
1035
int h = hsv_input[0]->GetValue();
1036
unsigned char maxr, maxg, maxb;
1037
hsv_to_rgb(h, 255, 255, &maxr, &maxg, &maxb);
1039
for (int v = 0; v < 256; v++) {
1041
rr = (255-maxr) * v / 256;
1042
rg = (255-maxg) * v / 256;
1043
rb = (255-maxb) * v / 256;
1044
for (int s = 0; s < 256; s++) {
1046
r = 255 - rr * s / 256 - (255-v);
1047
g = 255 - rg * s / 256 - (255-v);
1048
b = 255 - rb * s / 256 - (255-v);
1054
spectrum_image.SetData(ospec);
1055
hsv_spectrum = new wxBitmap(spectrum_image);
1057
return hsv_spectrum;
1062
BEGIN_EVENT_TABLE(DialogColorPicker, wxDialog)
1063
EVT_SPINCTRL(SELECTOR_RGB_R, DialogColorPicker::OnSpinRGB)
1064
EVT_SPINCTRL(SELECTOR_RGB_G, DialogColorPicker::OnSpinRGB)
1065
EVT_SPINCTRL(SELECTOR_RGB_B, DialogColorPicker::OnSpinRGB)
1066
EVT_SPINCTRL(SELECTOR_HSL_H, DialogColorPicker::OnSpinHSL)
1067
EVT_SPINCTRL(SELECTOR_HSL_S, DialogColorPicker::OnSpinHSL)
1068
EVT_SPINCTRL(SELECTOR_HSL_L, DialogColorPicker::OnSpinHSL)
1069
EVT_SPINCTRL(SELECTOR_HSV_H, DialogColorPicker::OnSpinHSV)
1070
EVT_SPINCTRL(SELECTOR_HSV_S, DialogColorPicker::OnSpinHSV)
1071
EVT_SPINCTRL(SELECTOR_HSV_V, DialogColorPicker::OnSpinHSV)
1072
EVT_TEXT(SELECTOR_RGB_R, DialogColorPicker::OnChangeRGB)
1073
EVT_TEXT(SELECTOR_RGB_G, DialogColorPicker::OnChangeRGB)
1074
EVT_TEXT(SELECTOR_RGB_B, DialogColorPicker::OnChangeRGB)
1075
EVT_TEXT(SELECTOR_HSL_H, DialogColorPicker::OnChangeHSL)
1076
EVT_TEXT(SELECTOR_HSL_S, DialogColorPicker::OnChangeHSL)
1077
EVT_TEXT(SELECTOR_HSL_L, DialogColorPicker::OnChangeHSL)
1078
EVT_TEXT(SELECTOR_HSV_H, DialogColorPicker::OnChangeHSV)
1079
EVT_TEXT(SELECTOR_HSV_S, DialogColorPicker::OnChangeHSV)
1080
EVT_TEXT(SELECTOR_HSV_V, DialogColorPicker::OnChangeHSV)
1081
EVT_TEXT(SELECTOR_ASS_INPUT, DialogColorPicker::OnChangeASS)
1082
EVT_TEXT(SELECTOR_HTML_INPUT, DialogColorPicker::OnChangeHTML)
1083
EVT_CHOICE(SELECTOR_MODE, DialogColorPicker::OnChangeMode)
1084
EVT_COMMAND(SELECTOR_SPECTRUM, wxSPECTRUM_CHANGE, DialogColorPicker::OnSpectrumChange)
1085
EVT_COMMAND(SELECTOR_SLIDER, wxSPECTRUM_CHANGE, DialogColorPicker::OnSliderChange)
1086
EVT_COMMAND(SELECTOR_RECENT, wxRECENT_SELECT, DialogColorPicker::OnRecentSelect)
1087
EVT_COMMAND(SELECTOR_DROPPER_PICK, wxDROPPER_SELECT, DialogColorPicker::OnRecentSelect)
1088
EVT_BUTTON(BUTTON_RGBADJUST, DialogColorPicker::OnRGBAdjust)
1089
EVT_MOUSE_EVENTS(DialogColorPicker::OnMouse)
1093
void DialogColorPicker::OnSpinRGB(wxSpinEvent &evt)
1095
if (!updating_controls)
1096
spectrum_dirty = true;
1101
void DialogColorPicker::OnSpinHSL(wxSpinEvent &evt)
1103
if (!updating_controls)
1104
spectrum_dirty = true;
1109
void DialogColorPicker::OnSpinHSV(wxSpinEvent &evt)
1111
if (!updating_controls)
1112
spectrum_dirty = true;
1117
void DialogColorPicker::OnChangeRGB(wxCommandEvent &evt)
1119
if (!updating_controls)
1120
spectrum_dirty = true;
1125
void DialogColorPicker::OnChangeHSL(wxCommandEvent &evt)
1127
if (!updating_controls)
1128
spectrum_dirty = true;
1133
void DialogColorPicker::OnChangeHSV(wxCommandEvent &evt)
1135
if (!updating_controls)
1136
spectrum_dirty = true;
1141
void DialogColorPicker::OnChangeASS(wxCommandEvent &evt)
1143
if (!updating_controls)
1144
spectrum_dirty = true;
1149
void DialogColorPicker::OnChangeHTML(wxCommandEvent &evt)
1151
if (!updating_controls)
1152
spectrum_dirty = true;
1157
void DialogColorPicker::OnChangeMode(wxCommandEvent &evt)
1159
if (!updating_controls)
1160
spectrum_dirty = true;
1161
Options.SetInt(_T("Color Picker Mode"), colorspace_choice->GetSelection());
1162
UpdateSpectrumDisplay();
1166
void DialogColorPicker::OnSpectrumChange(wxCommandEvent &evt)
1168
updating_controls = true;
1170
int i = colorspace_choice->GetSelection();
1172
spectrum->GetXY(x, y);
1175
rgb_input[2]->SetValue(x);
1176
rgb_input[1]->SetValue(y);
1177
updating_controls = false;
1181
rgb_input[2]->SetValue(x);
1182
rgb_input[0]->SetValue(y);
1183
updating_controls = false;
1187
rgb_input[1]->SetValue(x);
1188
rgb_input[0]->SetValue(y);
1189
updating_controls = false;
1193
hsl_input[1]->SetValue(x);
1194
hsl_input[0]->SetValue(y);
1195
updating_controls = false;
1199
hsv_input[1]->SetValue(x);
1200
hsv_input[2]->SetValue(y);
1201
updating_controls = false;
1209
void DialogColorPicker::OnSliderChange(wxCommandEvent &evt)
1211
spectrum_dirty = true;
1212
int i = colorspace_choice->GetSelection();
1213
int x, y; // only y is used, x is garbage for this control
1214
slider->GetXY(x, y);
1216
// setting the value of a component input automatically invalidates the spectrum
1217
// and calls the according UpdateFromXXX() function in wxMSW and wxMac, wxGTK must be manually updated
1219
rgb_input[0]->SetValue(y);
1225
rgb_input[1]->SetValue(y);
1231
rgb_input[2]->SetValue(y);
1237
hsl_input[2]->SetValue(y);
1243
hsv_input[0]->SetValue(y);
1252
void DialogColorPicker::OnRecentSelect(wxCommandEvent &evt)
1254
// The colour picked is stored in the event string
1255
// Allows this event handler to be shared by recent and dropper controls
1258
color.Parse(evt.GetString());
1259
SetColor(color.GetWXColor());
1263
void DialogColorPicker::OnDropperMouse(wxMouseEvent &evt)
1265
if (evt.LeftDown() && !screen_dropper_icon->HasCapture()) {
1267
screen_dropper_icon->SetCursor(wxCursor(_T("eyedropper_cursor")));
1269
screen_dropper_icon->SetCursor(*wxCROSS_CURSOR);
1271
screen_dropper_icon->SetBitmap(wxNullBitmap);
1272
screen_dropper_icon->CaptureMouse();
1273
eyedropper_grab_point = evt.GetPosition();
1274
eyedropper_is_grabbed = false;
1278
#define ABS(x) (x < 0 ? -x : x)
1279
wxPoint ptdiff = evt.GetPosition() - eyedropper_grab_point;
1280
bool release_now = eyedropper_is_grabbed || ABS(ptdiff.x) + ABS(ptdiff.y) > 7;
1282
screen_dropper_icon->ReleaseMouse();
1283
eyedropper_is_grabbed = false;
1284
screen_dropper_icon->SetCursor(wxNullCursor);
1285
screen_dropper_icon->SetBitmap(eyedropper_bitmap);
1287
eyedropper_is_grabbed = true;
1291
if (screen_dropper_icon->HasCapture()) {
1292
wxPoint scrpos = screen_dropper_icon->ClientToScreen(evt.GetPosition());
1293
screen_dropper->DropFromScreenXY(scrpos.x, scrpos.y);
1299
/// @brief Hack to redirect events to the screen dropper icon
1302
void DialogColorPicker::OnMouse(wxMouseEvent &evt)
1304
if (screen_dropper_icon->HasCapture()) {
1305
wxPoint dropper_pos = screen_dropper_icon->ScreenToClient(ClientToScreen(evt.GetPosition()));
1306
evt.m_x = dropper_pos.x;
1307
evt.m_y = dropper_pos.y;
1308
screen_dropper_icon->GetEventHandler()->ProcessEvent(evt);
1317
void DialogColorPicker::OnRGBAdjust(wxCommandEvent &evt)
1319
wxColour cur = cur_color;
1320
wxColour old = recent_box->GetColor(0);
1321
double r = double(cur.Red()) / double(old.Red());
1322
double g = double(cur.Green()) / double(old.Green());
1323
double b = double(cur.Blue()) / double(old.Blue());
1324
wxString data = wxString(_T("rgbadjust(")) + PrettyFloatD(r) + _T(",") + PrettyFloatD(g) + _T(",") + PrettyFloatD(b) + _T(")");
1326
if (wxTheClipboard->Open()) {
1327
wxTheClipboard->SetData(new wxTextDataObject(data));
1328
wxTheClipboard->Close();
1333
// Static values for last position of the dialog in this Aegisub session
1334
int DialogColorPicker::lastx = -1;
1335
int DialogColorPicker::lasty = -1;