From 0ced31a447bc3369e82f61dc49ca4cc5099c2c26 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 22 Jun 2017 18:39:28 -0300 Subject: [PATCH] Hide "Index" tab in FG/BG color popups The "Index" tab doesn't make sense in the foreground/background color selector because we already have the color bar at the left of the screen to click on a palette entry. --- src/app/commands/cmd_mask_by_color.cpp | 8 +-- src/app/commands/cmd_sprite_properties.cpp | 2 +- src/app/ui/color_bar.cpp | 4 +- src/app/ui/color_button.cpp | 16 +++--- src/app/ui/color_button.h | 8 +-- src/app/ui/color_button_options.h | 38 ++++++++++++++ src/app/ui/color_popup.cpp | 58 +++++++++++++++------- src/app/ui/color_popup.h | 9 ++-- src/app/ui/context_bar.cpp | 2 +- src/app/widget_loader.cpp | 13 +++-- 10 files changed, 110 insertions(+), 48 deletions(-) create mode 100644 src/app/ui/color_button_options.h diff --git a/src/app/commands/cmd_mask_by_color.cpp b/src/app/commands/cmd_mask_by_color.cpp index b853bff19..206fd4cb1 100644 --- a/src/app/commands/cmd_mask_by_color.cpp +++ b/src/app/commands/cmd_mask_by_color.cpp @@ -101,10 +101,10 @@ void MaskByColorCommand::onExecute(Context* context) box4 = new Box(HORIZONTAL | HOMOGENEOUS); label_color = new Label("Color:"); m_buttonColor = new ColorButton - (get_config_color("MaskColor", "Color", - ColorBar::instance()->getFgColor()), - sprite->pixelFormat(), - false, false); + (get_config_color("MaskColor", "Color", + ColorBar::instance()->getFgColor()), + sprite->pixelFormat(), + ColorButtonOptions()); label_tolerance = new Label("Tolerance:"); m_sliderTolerance = new Slider(0, 255, get_config_int("MaskColor", "Tolerance", 0)); m_checkPreview = new CheckBox("&Preview"); diff --git a/src/app/commands/cmd_sprite_properties.cpp b/src/app/commands/cmd_sprite_properties.cpp index 75584c428..15fccf785 100644 --- a/src/app/commands/cmd_sprite_properties.cpp +++ b/src/app/commands/cmd_sprite_properties.cpp @@ -107,7 +107,7 @@ void SpritePropertiesCommand::onExecute(Context* context) if (sprite->pixelFormat() == IMAGE_INDEXED) { color_button = new ColorButton(app::Color::fromIndex(sprite->transparentColor()), IMAGE_INDEXED, - false, false); + ColorButtonOptions()); window.transparentColorPlaceholder()->addChild(color_button); } diff --git a/src/app/ui/color_bar.cpp b/src/app/ui/color_bar.cpp index d9d2812a7..2dc2b013e 100644 --- a/src/app/ui/color_bar.cpp +++ b/src/app/ui/color_bar.cpp @@ -118,8 +118,8 @@ ColorBar::ColorBar(int align) , m_tintShadeTone(nullptr) , m_spectrum(nullptr) , m_wheel(nullptr) - , m_fgColor(app::Color::fromRgb(255, 255, 255), IMAGE_RGB, true, false) - , m_bgColor(app::Color::fromRgb(0, 0, 0), IMAGE_RGB, true, false) + , m_fgColor(app::Color::fromRgb(255, 255, 255), IMAGE_RGB, ColorBarButtonsOptions()) + , m_bgColor(app::Color::fromRgb(0, 0, 0), IMAGE_RGB, ColorBarButtonsOptions()) , m_fgWarningIcon(new WarningIcon) , m_bgWarningIcon(new WarningIcon) , m_fromPalView(false) diff --git a/src/app/ui/color_button.cpp b/src/app/ui/color_button.cpp index 5b88b5c7e..138c3d1e9 100644 --- a/src/app/ui/color_button.cpp +++ b/src/app/ui/color_button.cpp @@ -43,15 +43,13 @@ static WidgetType colorbutton_type() ColorButton::ColorButton(const app::Color& color, const PixelFormat pixelFormat, - const bool canPinSelector, - const bool showSimpleColors) + const ColorButtonOptions& options) : ButtonBase("", colorbutton_type(), kButtonWidget, kButtonWidget) , m_color(color) , m_pixelFormat(pixelFormat) , m_window(nullptr) , m_dependOnLayer(false) - , m_canPinSelector(canPinSelector) - , m_showSimpleColors(showSimpleColors) + , m_options(options) { setFocusStop(true); initTheme(); @@ -96,7 +94,7 @@ void ColorButton::setColor(const app::Color& origColor) // BeforeChange() has changed the color type (e.g. to index), we // don't care, in the window we prefer to keep the original // HSV/HSL values. - m_window->setColor(origColor, ColorPopup::DoNotChangeType); + m_window->setColor(origColor, ColorPopup::DontChangeType); } // Emit signal @@ -264,7 +262,7 @@ void ColorButton::onClick(Event& ev) void ColorButton::onLoadLayout(ui::LoadLayoutEvent& ev) { - if (m_canPinSelector) { + if (canPin()) { bool pinned = false; ev.stream() >> pinned; if (ev.stream() && pinned) @@ -274,7 +272,7 @@ void ColorButton::onLoadLayout(ui::LoadLayoutEvent& ev) void ColorButton::onSaveLayout(ui::SaveLayoutEvent& ev) { - if (m_canPinSelector && m_window && m_window->isPinned()) + if (canPin() && m_window && m_window->isPinned()) ev.stream() << 1 << ' ' << m_window->bounds(); else ev.stream() << 0; @@ -285,7 +283,7 @@ void ColorButton::openSelectorDialog() bool pinned = (!m_windowDefaultBounds.isEmpty()); if (m_window == NULL) { - m_window = new ColorPopup(m_canPinSelector, m_showSimpleColors); + m_window = new ColorPopup(m_options); m_window->ColorChange.connect(&ColorButton::onWindowColorChange, this); } @@ -339,7 +337,7 @@ void ColorButton::onActiveSiteChange(const Site& site) if (m_dependOnLayer) invalidate(); - if (m_canPinSelector) { + if (canPin()) { // Hide window if (!site.document()) { if (m_window) diff --git a/src/app/ui/color_button.h b/src/app/ui/color_button.h index 4c07d3dcc..80dc9070f 100644 --- a/src/app/ui/color_button.h +++ b/src/app/ui/color_button.h @@ -9,6 +9,7 @@ #pragma once #include "app/color.h" +#include "app/ui/color_button_options.h" #include "app/ui/color_source.h" #include "doc/context_observer.h" #include "doc/pixel_format.h" @@ -28,8 +29,7 @@ namespace app { public: ColorButton(const app::Color& color, const PixelFormat pixelFormat, - const bool canPinSelector, - const bool showSimpleColors); + const ColorButtonOptions& options); ~ColorButton(); PixelFormat pixelFormat() const; @@ -60,14 +60,14 @@ namespace app { void closeSelectorDialog(); void onWindowColorChange(const app::Color& color); void onActiveSiteChange(const Site& site) override; + bool canPin() const { return m_options.canPinSelector; } app::Color m_color; PixelFormat m_pixelFormat; ColorPopup* m_window; gfx::Rect m_windowDefaultBounds; bool m_dependOnLayer; - bool m_canPinSelector; - bool m_showSimpleColors; + ColorButtonOptions m_options; }; } // namespace app diff --git a/src/app/ui/color_button_options.h b/src/app/ui/color_button_options.h new file mode 100644 index 000000000..52b66ac64 --- /dev/null +++ b/src/app/ui/color_button_options.h @@ -0,0 +1,38 @@ +// Aseprite +// Copyright (C) 2017 David Capello +// +// This program is distributed under the terms of +// the End-User License Agreement for Aseprite. + +#ifndef APP_UI_COLOR_BUTTON_OPTIONS_H_INCLUDED +#define APP_UI_COLOR_BUTTON_OPTIONS_H_INCLUDED +#pragma once + +namespace app { + + struct ColorButtonOptions { + bool canPinSelector; + bool showSimpleColors; + bool showIndexTab; + + ColorButtonOptions() { + // Default values for regular color buttons in dialogs like + // "Replace Color" + canPinSelector = false; + showSimpleColors = false; + showIndexTab = true; + } + }; + + struct ColorBarButtonsOptions : public ColorButtonOptions { + ColorBarButtonsOptions() { + // Default values for color buttons inside the color bar + canPinSelector = true; + showSimpleColors = false; + showIndexTab = false; + } + }; + +} // namespace app + +#endif diff --git a/src/app/ui/color_popup.cpp b/src/app/ui/color_popup.cpp index d3766c902..e0d75ef27 100644 --- a/src/app/ui/color_popup.cpp +++ b/src/app/ui/color_popup.cpp @@ -164,21 +164,24 @@ void ColorPopup::CustomButtonSet::onSelectItem(Item* item, bool focusItem, ui::M } } -ColorPopup::ColorPopup(const bool canPin, - bool showSimpleColors) +ColorPopup::ColorPopup(const ColorButtonOptions& options) : PopupWindowPin(" ", // Non-empty to create title-bar and close button ClickBehavior::CloseOnClickInOtherWindow, - canPin) + options.canPinSelector) , m_vbox(VERTICAL) , m_topBox(HORIZONTAL) , m_color(app::Color::fromMask()) - , m_colorPalette(false, PaletteView::SelectOneColor, this, 7*guiscale()) + , m_colorPaletteContainer(options.showIndexTab ? + new ui::View: nullptr) + , m_colorPalette(options.showIndexTab ? + new PaletteView(false, PaletteView::SelectOneColor, this, 7*guiscale()): + nullptr) , m_simpleColors(nullptr) , m_maskLabel("Transparent Color Selected") - , m_canPin(canPin) + , m_canPin(options.canPinSelector) , m_disableHexUpdate(false) { - if (showSimpleColors) { + if (options.showSimpleColors) { if (!g_simplePal) { ResourceFinder rf; rf.includeDataDir("palettes/tags.gpl"); @@ -188,11 +191,13 @@ ColorPopup::ColorPopup(const bool canPin, if (g_simplePal) m_simpleColors = new SimpleColors(this, &m_tooltips); - else - showSimpleColors = false; } - m_colorType.addItem("Index")->setFocusStop(false); + ButtonSet::Item* item = m_colorType.addItem("Index"); + item->setFocusStop(false); + if (!options.showIndexTab) + item->setVisible(false); + m_colorType.addItem("RGB")->setFocusStop(false); m_colorType.addItem("HSV")->setFocusStop(false); m_colorType.addItem("HSL")->setFocusStop(false); @@ -202,8 +207,10 @@ ColorPopup::ColorPopup(const bool canPin, m_topBox.setBorder(gfx::Border(0)); m_topBox.setChildSpacing(0); - m_colorPaletteContainer.attachToView(&m_colorPalette); - m_colorPaletteContainer.setExpansive(true); + if (m_colorPalette) { + m_colorPaletteContainer->attachToView(m_colorPalette); + m_colorPaletteContainer->setExpansive(true); + } m_sliders.setExpansive(true); m_topBox.addChild(&m_colorType); @@ -235,7 +242,8 @@ ColorPopup::ColorPopup(const bool canPin, if (m_simpleColors) m_vbox.addChild(m_simpleColors); m_vbox.addChild(&m_topBox); - m_vbox.addChild(&m_colorPaletteContainer); + if (m_colorPaletteContainer) + m_vbox.addChild(m_colorPaletteContainer); m_vbox.addChild(&m_sliders); m_vbox.addChild(&m_maskLabel); addChild(&m_vbox); @@ -278,8 +286,10 @@ void ColorPopup::setColor(const app::Color& color, SetColorOptions options) } if (color.getType() == app::Color::IndexType) { - m_colorPalette.deselect(); - m_colorPalette.selectColor(color.getIndex()); + if (m_colorPalette) { + m_colorPalette->deselect(); + m_colorPalette->selectColor(color.getIndex()); + } } m_sliders.setColor(m_color); @@ -408,12 +418,15 @@ void ColorPopup::onColorTypeClick() void ColorPopup::onPaletteChange() { - setColor(getColor(), DoNotChangeType); + setColor(getColor(), DontChangeType); invalidate(); } void ColorPopup::findBestfitIndex(const app::Color& color) { + if (!m_colorPalette) + return; + // Find bestfit palette entry int r = color.getRed(); int g = color.getGreen(); @@ -423,8 +436,8 @@ void ColorPopup::findBestfitIndex(const app::Color& color) // Search for the closest color to the RGB values int i = get_current_palette()->findBestfit(r, g, b, a, 0); if (i >= 0) { - m_colorPalette.deselect(); - m_colorPalette.selectColor(i); + m_colorPalette->deselect(); + m_colorPalette->selectColor(i); } } @@ -438,13 +451,20 @@ void ColorPopup::setColorWithSignal(const app::Color& color) void ColorPopup::selectColorType(app::Color::Type type) { - m_colorPaletteContainer.setVisible(type == app::Color::IndexType); + if (m_colorPaletteContainer) + m_colorPaletteContainer->setVisible(type == app::Color::IndexType); + m_maskLabel.setVisible(type == app::Color::MaskType); // Count selected items. if (m_colorType.countSelectedItems() < 2) { switch (type) { - case app::Color::IndexType: m_colorType.setSelectedItem(INDEX_MODE); break; + case app::Color::IndexType: + if (m_colorPalette) + m_colorType.setSelectedItem(INDEX_MODE); + else + m_colorType.setSelectedItem(RGB_MODE); + break; case app::Color::RgbType: m_colorType.setSelectedItem(RGB_MODE); break; case app::Color::HsvType: m_colorType.setSelectedItem(HSV_MODE); break; case app::Color::HslType: m_colorType.setSelectedItem(HSL_MODE); break; diff --git a/src/app/ui/color_popup.h b/src/app/ui/color_popup.h index ef1266fb2..4db420214 100644 --- a/src/app/ui/color_popup.h +++ b/src/app/ui/color_popup.h @@ -10,6 +10,7 @@ #include "app/color.h" #include "app/ui/button_set.h" +#include "app/ui/color_button_options.h" #include "app/ui/color_sliders.h" #include "app/ui/hex_color_entry.h" #include "app/ui/palette_view.h" @@ -29,10 +30,10 @@ namespace app { public: enum SetColorOptions { ChangeType, - DoNotChangeType + DontChangeType }; - ColorPopup(const bool canPin, bool showSimpleColors); + ColorPopup(const ColorButtonOptions& options); ~ColorPopup(); void setColor(const app::Color& color, SetColorOptions options); @@ -71,8 +72,8 @@ namespace app { ui::TooltipManager m_tooltips; ui::Box m_topBox; app::Color m_color; - ui::View m_colorPaletteContainer; - PaletteView m_colorPalette; + ui::View* m_colorPaletteContainer; + PaletteView* m_colorPalette; SimpleColors* m_simpleColors; CustomButtonSet m_colorType; HexColorEntry m_hexColorEntry; diff --git a/src/app/ui/context_bar.cpp b/src/app/ui/context_bar.cpp index c764cc54c..cb287fb6b 100644 --- a/src/app/ui/context_bar.cpp +++ b/src/app/ui/context_bar.cpp @@ -928,7 +928,7 @@ class ContextBar::TransparentColorField : public HBox { public: TransparentColorField(ContextBar* owner) : m_icon(1) - , m_maskColor(app::Color::fromMask(), IMAGE_RGB, false, false) + , m_maskColor(app::Color::fromMask(), IMAGE_RGB, ColorButtonOptions()) , m_owner(owner) { SkinTheme* theme = SkinTheme::instance(); diff --git a/src/app/widget_loader.cpp b/src/app/widget_loader.cpp index 26d3d6b78..128f1afc0 100644 --- a/src/app/widget_loader.cpp +++ b/src/app/widget_loader.cpp @@ -406,11 +406,16 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget const bool rgba = bool_attr_is_true(elem, "rgba"); const bool simple = bool_attr_is_true(elem, "simple"); - if (!widget) + if (!widget) { + ColorButtonOptions options; + options.canPinSelector = false; + options.showSimpleColors = simple; + options.showIndexTab = true; widget = new ColorButton(Color::fromMask(), - rgba ? IMAGE_RGB: - app_get_current_pixel_format(), false, - simple); + (rgba ? IMAGE_RGB: + app_get_current_pixel_format()), + options); + } } else if (elem_name == "dropdownbutton") { if (!widget) {