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.
This commit is contained in:
David Capello 2017-06-22 18:39:28 -03:00
parent 84282764ee
commit 0ced31a447
10 changed files with 110 additions and 48 deletions

View File

@ -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");

View File

@ -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);
}

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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();

View File

@ -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) {