Hide the alpha controls when the alpha isn't used

This commit is contained in:
Thomas Goyne 2013-01-13 11:19:13 -08:00
parent 7a3b221847
commit 0b5674e6aa
9 changed files with 27 additions and 18 deletions

View File

@ -246,7 +246,7 @@ namespace Automation4 {
wxControl *Create(wxWindow *parent)
{
agi::Color colour(from_wx(text));
wxControl *cw = new ColourButton(parent, wxSize(50*width,10*height), colour, ColorValidator(&text));
wxControl *cw = new ColourButton(parent, wxSize(50*width,10*height), false, colour, ColorValidator(&text));
cw->SetToolTip(hint);
return cw;
}

View File

@ -25,14 +25,14 @@
wxDEFINE_EVENT(EVT_COLOR, wxThreadEvent);
ColourButton::ColourButton(wxWindow *parent, wxSize const& size, agi::Color col, wxValidator const& validator)
ColourButton::ColourButton(wxWindow *parent, wxSize const& size, bool alpha, agi::Color col, wxValidator const& validator)
: wxButton(parent, -1, "", wxDefaultPosition, wxSize(size.GetWidth() + 6, size.GetHeight() + 6), 0, validator)
, bmp(size)
, colour(col)
{
UpdateBitmap();
Bind(wxEVT_COMMAND_BUTTON_CLICKED, [=](wxCommandEvent&) {
GetColorFromUser(GetParent(), colour, [=](agi::Color new_color) {
GetColorFromUser(GetParent(), colour, alpha, [=](agi::Color new_color) {
colour = new_color;
UpdateBitmap();

View File

@ -35,8 +35,9 @@ public:
/// Constructor
/// @param parent Parent window
/// @param size Size of the bitmap (note: not the size of the button)
/// @param alpha Let the user adjust the color's alpha
/// @param color Initial color to display
ColourButton(wxWindow *parent, wxSize const& size, agi::Color color = agi::Color(), wxValidator const& validator = wxDefaultValidator);
ColourButton(wxWindow *parent, wxSize const& size, bool alpha, agi::Color color = agi::Color(), wxValidator const& validator = wxDefaultValidator);
/// Get the currently selected color
agi::Color GetColor() { return colour; }

View File

@ -310,7 +310,7 @@ void show_color_picker(const agi::Context *c, agi::Color (AssStyle::*field), con
color = get_value(blocks, blockn, color, tag, alt);
int commit_id = -1;
bool ok = GetColorFromUser(c->parent, color, [&](agi::Color new_color) {
bool ok = GetColorFromUser(c->parent, color, true, [&](agi::Color new_color) {
set_tag(line, blocks, tag, new_color.GetAssOverrideFormatted(), sel_start, sel_end);
set_tag(line, blocks, alpha, str(boost::format("&H%02X&") % (int)new_color.a), sel_start, sel_end);
commit_text(c, _("set color"), sel_start, sel_end, &commit_id);

View File

@ -514,7 +514,7 @@ class DialogColorPicker : public wxDialog {
std::function<void (agi::Color)> callback;
public:
DialogColorPicker(wxWindow *parent, agi::Color initial_color, std::function<void (agi::Color)> callback);
DialogColorPicker(wxWindow *parent, agi::Color initial_color, std::function<void (agi::Color)> callback, bool alpha);
~DialogColorPicker();
void SetColor(agi::Color new_color);
@ -532,7 +532,7 @@ static wxBitmap make_slider(Func func) {
return wxBitmap(img);
}
DialogColorPicker::DialogColorPicker(wxWindow *parent, agi::Color initial_color, std::function<void (agi::Color)> callback)
DialogColorPicker::DialogColorPicker(wxWindow *parent, agi::Color initial_color, std::function<void (agi::Color)> callback, bool alpha)
: wxDialog(parent, -1, _("Select Color"))
, callback(callback)
{
@ -603,6 +603,7 @@ DialogColorPicker::DialogColorPicker(wxWindow *parent, agi::Color initial_color,
spectop_sizer->Add(colorspace_choice, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT);
spectop_sizer->Add(5, 5, 1, wxEXPAND);
spectop_sizer->Add(preview_box, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT);
wxSizer *spectrum_sizer = new wxFlexGridSizer(3, 5, 5);
spectrum_sizer->Add(spectop_sizer, wxEXPAND);
spectrum_sizer->AddStretchSpacer(1);
@ -610,6 +611,9 @@ DialogColorPicker::DialogColorPicker(wxWindow *parent, agi::Color initial_color,
spectrum_sizer->Add(spectrum);
spectrum_sizer->Add(slider);
spectrum_sizer->Add(alpha_slider);
if (!alpha)
spectrum_sizer->Hide(alpha_slider);
spectrum_box->Add(spectrum_sizer, 0, wxALL, 3);
wxString rgb_labels[] = { _("Red:"), _("Green:"), _("Blue:") };
@ -617,7 +621,10 @@ DialogColorPicker::DialogColorPicker(wxWindow *parent, agi::Color initial_color,
wxString ass_labels[] = { "ASS:", "HTML:", _("Alpha:") };
wxControl *ass_ctrls[] = { ass_input, html_input, alpha_input };
rgb_box->Add(MakeColorInputSizer(ass_labels, ass_ctrls), 0, wxALL|wxCENTER|wxEXPAND, 3);
auto ass_colors_sizer = MakeColorInputSizer(ass_labels, ass_ctrls);
if (!alpha)
ass_colors_sizer->Hide(alpha_input);
rgb_box->Add(ass_colors_sizer, 0, wxALL|wxCENTER|wxEXPAND, 3);
wxString hsl_labels[] = { _("Hue:"), _("Sat.:"), _("Lum.:") };
hsl_box->Add(MakeColorInputSizer(hsl_labels, hsl_input), 0, wxALL|wxEXPAND, 3);
@ -1106,8 +1113,8 @@ void DialogColorPicker::OnCaptureLost(wxMouseCaptureLostEvent&) {
}
bool GetColorFromUser(wxWindow* parent, agi::Color original, std::function<void (agi::Color)> callback) {
DialogColorPicker dialog(parent, original, callback);
bool GetColorFromUser(wxWindow* parent, agi::Color original, bool alpha, std::function<void (agi::Color)> callback) {
DialogColorPicker dialog(parent, original, callback, alpha);
bool ok = dialog.ShowModal() == wxID_OK;
if (!ok)
callback(original);

View File

@ -28,6 +28,7 @@ class wxWindow;
/// @brief Get a color from the user via a color picker dialog
/// @param parent Parent window
/// @param original Initial color to select
/// @param alpha Include controls for alpha
/// @param callback Function called whenever the selected color changes
/// @return Did the user accept the new color?
bool GetColorFromUser(wxWindow* parent, agi::Color original, std::function<void (agi::Color)> callback);
bool GetColorFromUser(wxWindow* parent, agi::Color original, bool alpha, std::function<void (agi::Color)> callback);

View File

@ -104,7 +104,7 @@ DialogDummyVideo::DialogDummyVideo(wxWindow *parent)
res_sizer->Add(spin_ctrl(this, 1, 10000, &height), wxSizerFlags(1).Expand());
wxBoxSizer *color_sizer = new wxBoxSizer(wxHORIZONTAL);
ColourButton *color_btn = new ColourButton(this, wxSize(30, 17), color);
ColourButton *color_btn = new ColourButton(this, wxSize(30, 17), false, color);
color_sizer->Add(color_btn, wxSizerFlags().DoubleBorder(wxRIGHT));
color_sizer->Add(new wxCheckBox(this, -1, _("Checkerboard &pattern"), wxDefaultPosition, wxDefaultSize, 0, wxGenericValidator(&pattern)), wxSizerFlags(1).Center());

View File

@ -191,10 +191,10 @@ DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Con
BoxItalic = new wxCheckBox(this, -1, _("&Italic"));
BoxUnderline = new wxCheckBox(this, -1, _("&Underline"));
BoxStrikeout = new wxCheckBox(this, -1, _("&Strikeout"));
colorButton[0] = new ColourButton(this, wxSize(55, 16), style->primary);
colorButton[1] = new ColourButton(this, wxSize(55, 16), style->secondary);
colorButton[2] = new ColourButton(this, wxSize(55, 16), style->outline);
colorButton[3] = new ColourButton(this, wxSize(55, 16), style->shadow);
colorButton[0] = new ColourButton(this, wxSize(55, 16), true, style->primary);
colorButton[1] = new ColourButton(this, wxSize(55, 16), true, style->secondary);
colorButton[2] = new ColourButton(this, wxSize(55, 16), true, style->outline);
colorButton[3] = new ColourButton(this, wxSize(55, 16), true, style->shadow);
for (int i = 0; i < 3; i++)
margin[i] = spin_ctrl(this, style->Margin[i], 9999);
Alignment = new wxRadioBox(this, -1, _("Alignment"), wxDefaultPosition, wxDefaultSize, 9, alignValues, 3, wxRA_SPECIFY_COLS);
@ -324,7 +324,7 @@ DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Con
ColourButton *previewButton = 0;
if (!SubtitlesProviderFactory::GetClasses().empty()) {
PreviewText = new wxTextCtrl(this, -1, to_wx(OPT_GET("Tool/Style Editor/Preview Text")->GetString()));
previewButton = new ColourButton(this, wxSize(45, 16), OPT_GET("Colour/Style Editor/Background/Preview")->GetColor());
previewButton = new ColourButton(this, wxSize(45, 16), false, OPT_GET("Colour/Style Editor/Background/Preview")->GetColor());
SubsPreview = new SubtitlesPreview(this, wxSize(100, 60), wxSUNKEN_BORDER, OPT_GET("Colour/Style Editor/Background/Preview")->GetColor());
SubsPreview->SetToolTip(_("Preview of current style"));

View File

@ -150,7 +150,7 @@ wxControl *OptionPage::OptionAdd(wxFlexGridSizer *flex, const wxString &name, co
}
case agi::OptionValue::Type_Color: {
ColourButton *cb = new ColourButton(this, wxSize(40,10), opt->GetColor());
ColourButton *cb = new ColourButton(this, wxSize(40,10), false, opt->GetColor());
cb->Bind(EVT_COLOR, ColourUpdater(opt_name, parent));
Add(flex, name, cb);
return cb;