Aegisub/aegisub/src/dialog_colorpicker.h

392 lines
7.6 KiB
C
Raw Normal View History

2006-01-16 22:02:54 +01:00
// Copyright (c) 2005, Niels Martin Hansen
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Aegisub Project http://www.aegisub.org/
2006-01-16 22:02:54 +01:00
//
// $Id$
/// @file dialog_colorpicker.h
/// @see dialog_colorpicker.cpp
/// @ingroup tools_ui
///
2006-01-16 22:02:54 +01:00
2006-01-16 22:02:54 +01:00
#ifndef AGI_PRE
#include <vector>
2006-01-16 22:02:54 +01:00
#include <wx/bitmap.h>
#include <wx/button.h>
#include <wx/choice.h>
#include <wx/colour.h>
#include <wx/dialog.h>
#include <wx/spinctrl.h>
2006-01-16 22:02:54 +01:00
#include <wx/statbmp.h>
#include <wx/textctrl.h>
#endif
2006-01-16 22:02:54 +01:00
/// DOCME
/// @class ColorPickerSpectrum
/// @brief DOCME
///
/// DOCME
2006-01-16 22:02:54 +01:00
class ColorPickerSpectrum : public wxControl {
public:
/// DOCME
2006-01-16 22:02:54 +01:00
enum PickerDirection {
/// DOCME
2006-01-16 22:02:54 +01:00
HorzVert,
/// DOCME
2006-01-16 22:02:54 +01:00
Horz,
/// DOCME
2006-01-16 22:02:54 +01:00
Vert
};
private:
/// DOCME
/// DOCME
2006-01-16 22:02:54 +01:00
int x, y;
/// DOCME
2006-01-16 22:02:54 +01:00
wxBitmap *background;
/// DOCME
2006-01-16 22:02:54 +01:00
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);
2006-01-16 22:02:54 +01:00
void GetXY(int &xx, int &yy);
void SetXY(int xx, int yy);
void SetBackground(wxBitmap *new_background);
DECLARE_EVENT_TABLE()
2006-01-16 22:02:54 +01:00
};
DECLARE_EVENT_TYPE(wxSPECTRUM_CHANGE, -1)
/// DOCME
/// @class ColorPickerRecent
/// @brief DOCME
///
/// DOCME
2006-01-16 22:02:54 +01:00
class ColorPickerRecent : public wxControl {
private:
/// DOCME
/// DOCME
2006-01-16 22:02:54 +01:00
int rows, cols;
/// DOCME
int cellsize;
/// DOCME
wxPoint internal_control_offset;
/// DOCME
2006-01-16 22:02:54 +01:00
std::vector<wxColour> colors;
/// DOCME
bool background_valid;
/// DOCME
wxBitmap background;
2006-01-16 22:02:54 +01:00
void OnClick(wxMouseEvent &evt);
void OnPaint(wxPaintEvent &evt);
void OnSize(wxSizeEvent &evt);
2006-01-16 22:02:54 +01:00
public:
ColorPickerRecent(wxWindow *parent, wxWindowID id, int _cols, int _rows, int _cellsize);
2006-01-16 22:02:54 +01:00
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); }
2006-01-16 22:02:54 +01:00
DECLARE_EVENT_TABLE()
2006-01-16 22:02:54 +01:00
};
DECLARE_EVENT_TYPE(wxRECENT_SELECT, -1)
/// DOCME
/// @class ColorPickerScreenDropper
/// @brief DOCME
///
/// DOCME
2006-01-16 22:02:54 +01:00
class ColorPickerScreenDropper : public wxControl {
private:
/// DOCME
2006-01-16 22:02:54 +01:00
wxBitmap capture;
/// DOCME
/// DOCME
2006-01-16 22:02:54 +01:00
int resx, resy;
/// DOCME
2006-01-16 22:02:54 +01:00
int magnification;
/// DOCME
bool integrated_dropper;
2006-01-16 22:02:54 +01:00
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);
2006-01-16 22:02:54 +01:00
DECLARE_EVENT_TABLE()
2006-01-16 22:02:54 +01:00
};
DECLARE_EVENT_TYPE(wxDROPPER_SELECT, -1)
2006-01-16 22:02:54 +01:00
wxColour GetColorFromUser(wxWindow *parent, wxColour original);
/// DOCME
/// @class DialogColorPicker
/// @brief DOCME
///
/// DOCME
2006-01-16 22:02:54 +01:00
class DialogColorPicker : public wxDialog {
private:
/// DOCME
2006-01-16 22:02:54 +01:00
wxColour cur_color;
/// DOCME
2006-01-16 22:02:54 +01:00
bool updating_controls;
/// DOCME
2006-01-16 22:02:54 +01:00
bool spectrum_dirty;
/// DOCME
2006-01-16 22:02:54 +01:00
ColorPickerSpectrum *spectrum;
/// DOCME
2006-01-16 22:02:54 +01:00
ColorPickerSpectrum *slider;
/// DOCME
2006-01-16 22:02:54 +01:00
wxChoice *colorspace_choice;
/// DOCME
2006-01-16 22:02:54 +01:00
static const int slider_width = 10; // width in pixels of the color slider control
/// DOCME
2006-01-16 22:02:54 +01:00
wxSpinCtrl *rgb_input[3];
/// DOCME
2006-01-16 22:02:54 +01:00
wxBitmap *rgb_spectrum[3]; // x/y spectrum bitmap where color "i" is excluded from
/// DOCME
2006-01-16 22:02:54 +01:00
wxBitmap *rgb_slider[3]; // z spectrum for color "i"
/// DOCME
2006-01-16 22:02:54 +01:00
wxSpinCtrl *hsl_input[3];
/// DOCME
2006-01-16 22:02:54 +01:00
wxBitmap *hsl_spectrum; // h/s spectrum
/// DOCME
2006-01-16 22:02:54 +01:00
wxBitmap *hsl_slider; // l spectrum
/// DOCME
2006-01-16 22:02:54 +01:00
wxSpinCtrl *hsv_input[3];
/// DOCME
2006-01-16 22:02:54 +01:00
wxBitmap *hsv_spectrum; // s/v spectrum
/// DOCME
2006-01-16 22:02:54 +01:00
wxBitmap *hsv_slider; // h spectrum
/// DOCME
wxBitmap eyedropper_bitmap;
/// DOCME
wxPoint eyedropper_grab_point;
/// DOCME
bool eyedropper_is_grabbed;
/// DOCME
2006-01-16 22:02:54 +01:00
wxTextCtrl *ass_input; // ASS hex format input
/// DOCME
2006-01-16 22:02:54 +01:00
wxTextCtrl *html_input; // HTML hex format input
/// DOCME
2006-01-16 22:02:54 +01:00
wxStaticBitmap *preview_box;
/// DOCME
2006-01-16 22:02:54 +01:00
wxBitmap preview_bitmap;
/// DOCME
2006-01-16 22:02:54 +01:00
ColorPickerRecent *recent_box;
/// DOCME
2006-01-16 22:02:54 +01:00
ColorPickerScreenDropper *screen_dropper;
/// DOCME
wxStaticBitmap *screen_dropper_icon;
2006-01-16 22:02:54 +01:00
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);
2006-01-16 22:02:54 +01:00
/// DOCME
/// DOCME
static int lastx, lasty;
2006-01-16 22:02:54 +01:00
public:
DialogColorPicker(wxWindow *parent, wxColour initial_color);
~DialogColorPicker();
void SetColor(wxColour new_color);
wxColour GetColor();
DECLARE_EVENT_TABLE()
2006-01-16 22:02:54 +01:00
};
enum {
/// DOCME
2006-01-16 22:02:54 +01:00
SELECTOR_SPECTRUM = 4000,
/// DOCME
2006-01-16 22:02:54 +01:00
SELECTOR_SLIDER,
/// DOCME
2006-01-16 22:02:54 +01:00
SELECTOR_MODE,
/// DOCME
2006-01-16 22:02:54 +01:00
SELECTOR_RGB_R,
/// DOCME
2006-01-16 22:02:54 +01:00
SELECTOR_RGB_G,
/// DOCME
2006-01-16 22:02:54 +01:00
SELECTOR_RGB_B,
/// DOCME
2006-01-16 22:02:54 +01:00
SELECTOR_HSL_H,
/// DOCME
2006-01-16 22:02:54 +01:00
SELECTOR_HSL_S,
/// DOCME
2006-01-16 22:02:54 +01:00
SELECTOR_HSL_L,
/// DOCME
2006-01-16 22:02:54 +01:00
SELECTOR_HSV_H,
/// DOCME
2006-01-16 22:02:54 +01:00
SELECTOR_HSV_S,
/// DOCME
2006-01-16 22:02:54 +01:00
SELECTOR_HSV_V,
/// DOCME
2006-01-16 22:02:54 +01:00
SELECTOR_ASS_INPUT,
/// DOCME
2006-01-16 22:02:54 +01:00
SELECTOR_HTML_INPUT,
/// DOCME
2006-01-16 22:02:54 +01:00
SELECTOR_RECENT,
/// DOCME
SELECTOR_DROPPER,
/// DOCME
SELECTOR_DROPPER_PICK,
/// DOCME
BUTTON_RGBADJUST
2006-01-16 22:02:54 +01:00
};