aseprite/src/app/ui/context_bar.cpp

752 lines
20 KiB
C++
Raw Normal View History

/* Aseprite
2013-03-31 00:43:00 +08:00
* Copyright (C) 2001-2013 David Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
2013-03-31 00:43:00 +08:00
#include "config.h"
#endif
#include "app/ui/context_bar.h"
#include "app/app.h"
#include "app/modules/gui.h"
#include "app/settings/ink_type.h"
#include "app/settings/selection_mode.h"
#include "app/settings/settings.h"
#include "app/settings/settings_observers.h"
#include "app/tools/controller.h"
#include "app/tools/ink.h"
#include "app/tools/point_shape.h"
#include "app/tools/tool.h"
#include "app/tools/tool_box.h"
#include "app/ui/button_set.h"
#include "app/ui/color_button.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui_context.h"
#include "base/bind.h"
2013-03-31 00:43:00 +08:00
#include "base/unique_ptr.h"
2014-06-15 02:09:43 +08:00
#include "raster/brush.h"
#include "raster/conversion_alleg.h"
2013-03-31 00:43:00 +08:00
#include "raster/image.h"
#include "raster/palette.h"
2013-03-31 00:43:00 +08:00
#include "ui/button.h"
#include "ui/combobox.h"
#include "ui/int_entry.h"
#include "ui/label.h"
#include "ui/listitem.h"
#include "ui/popup_window.h"
2013-03-31 00:43:00 +08:00
#include "ui/preferred_size_event.h"
#include "ui/theme.h"
#include "ui/tooltips.h"
2013-03-31 00:43:00 +08:00
#include <allegro.h>
namespace app {
using namespace app::skin;
2013-03-31 00:43:00 +08:00
using namespace gfx;
using namespace ui;
using namespace tools;
class ContextBar::BrushTypeField : public Button
, public IButtonIcon
{
public:
BrushTypeField()
: Button("")
, m_popupWindow(NULL)
2014-06-15 02:09:43 +08:00
, m_brushTypeButton(NULL) {
2013-03-31 00:43:00 +08:00
setup_mini_look(this);
setIconInterface(this);
m_bitmap = create_bitmap_ex(32, 8, 8);
clear(m_bitmap);
}
~BrushTypeField() {
closePopup();
2013-03-31 00:43:00 +08:00
setIconInterface(NULL);
destroy_bitmap(m_bitmap);
}
2014-06-15 02:09:43 +08:00
void setBrushSettings(IBrushSettings* brushSettings) {
base::UniquePtr<Palette> palette(new Palette(FrameNumber(0), 2));
palette->setEntry(0, raster::rgba(0, 0, 0, 0));
palette->setEntry(1, raster::rgba(0, 0, 0, 255));
2014-06-15 02:09:43 +08:00
base::UniquePtr<Brush> brush(
new Brush(
m_brushType = brushSettings->getType(),
std::min(10, brushSettings->getSize()),
brushSettings->getAngle()));
Image* image = brush->get_image();
2013-03-31 00:43:00 +08:00
if (m_bitmap)
destroy_bitmap(m_bitmap);
m_bitmap = create_bitmap_ex(32, image->getWidth(), image->getHeight());
2013-03-31 00:43:00 +08:00
clear(m_bitmap);
convert_image_to_allegro(image, m_bitmap, 0, 0, palette);
2013-03-31 00:43:00 +08:00
invalidate();
}
// IButtonIcon implementation
void destroy() OVERRIDE {
// Do nothing, BrushTypeField is added as a widget in the
// ContextBar, so it will be destroyed together with the
// ContextBar.
}
int getWidth() OVERRIDE {
return m_bitmap->w;
}
int getHeight() OVERRIDE {
return m_bitmap->h;
}
BITMAP* getNormalIcon() OVERRIDE {
return m_bitmap;
}
BITMAP* getSelectedIcon() OVERRIDE {
return m_bitmap;
}
BITMAP* getDisabledIcon() OVERRIDE {
return m_bitmap;
}
int getIconAlign() OVERRIDE {
return JI_CENTER | JI_MIDDLE;
}
protected:
void onClick(Event& ev) OVERRIDE {
Button::onClick(ev);
if (!m_popupWindow || !m_popupWindow->isVisible())
openPopup();
else
closePopup();
}
2013-03-31 00:43:00 +08:00
void onPreferredSize(PreferredSizeEvent& ev) {
ev.setPreferredSize(Size(16*jguiscale(),
16*jguiscale()));
}
private:
void openPopup() {
Border border = Border(2, 2, 2, 3)*jguiscale();
Rect rc = getBounds();
rc.y += rc.h;
rc.w *= 3;
m_popupWindow = new PopupWindow("", PopupWindow::kCloseOnClickInOtherWindow);
m_popupWindow->setAutoRemap(false);
m_popupWindow->setBorder(border);
m_popupWindow->setBounds(rc + border);
Region rgn(m_popupWindow->getBounds().createUnion(getBounds()));
m_popupWindow->setHotRegion(rgn);
2014-06-15 02:09:43 +08:00
m_brushTypeButton = new ButtonSet(3, 1, m_brushType,
PART_BRUSH_CIRCLE,
PART_BRUSH_SQUARE,
PART_BRUSH_LINE);
2014-06-15 02:09:43 +08:00
m_brushTypeButton->ItemChange.connect(&BrushTypeField::onBrushTypeChange, this);
m_brushTypeButton->setTransparent(true);
m_brushTypeButton->setBgColor(ui::ColorNone);
2014-06-15 02:09:43 +08:00
m_popupWindow->addChild(m_brushTypeButton);
m_popupWindow->openWindow();
}
void closePopup() {
if (m_popupWindow) {
m_popupWindow->closeWindow(NULL);
delete m_popupWindow;
m_popupWindow = NULL;
2014-06-15 02:09:43 +08:00
m_brushTypeButton = NULL;
}
}
void onBrushTypeChange() {
2014-06-15 02:09:43 +08:00
m_brushType = (BrushType)m_brushTypeButton->getSelectedItem();
ISettings* settings = UIContext::instance()->getSettings();
Tool* currentTool = settings->getCurrentTool();
2014-06-15 02:09:43 +08:00
IBrushSettings* brushSettings = settings->getToolSettings(currentTool)->getBrush();
brushSettings->setType(m_brushType);
2014-06-15 02:09:43 +08:00
setBrushSettings(brushSettings);
}
2013-03-31 00:43:00 +08:00
BITMAP* m_bitmap;
2014-06-15 02:09:43 +08:00
BrushType m_brushType;
PopupWindow* m_popupWindow;
2014-06-15 02:09:43 +08:00
ButtonSet* m_brushTypeButton;
2013-03-31 00:43:00 +08:00
};
class ContextBar::BrushSizeField : public IntEntry
{
public:
BrushSizeField() : IntEntry(1, 32) {
setSuffix("px");
}
private:
void onValueChange() OVERRIDE {
IntEntry::onValueChange();
ISettings* settings = UIContext::instance()->getSettings();
Tool* currentTool = settings->getCurrentTool();
settings->getToolSettings(currentTool)
2014-06-15 02:09:43 +08:00
->getBrush()
2013-03-31 00:43:00 +08:00
->setSize(getValue());
}
};
class ContextBar::BrushAngleField : public IntEntry
{
public:
BrushAngleField(BrushTypeField* brushType)
: IntEntry(0, 180)
, m_brushType(brushType) {
setSuffix("\xc2\xb0");
2013-03-31 00:43:00 +08:00
}
protected:
void onValueChange() OVERRIDE {
IntEntry::onValueChange();
ISettings* settings = UIContext::instance()->getSettings();
Tool* currentTool = settings->getCurrentTool();
settings->getToolSettings(currentTool)
2014-06-15 02:09:43 +08:00
->getBrush()
2013-03-31 00:43:00 +08:00
->setAngle(getValue());
IToolSettings* toolSettings = settings->getToolSettings(currentTool);
2014-06-15 02:09:43 +08:00
IBrushSettings* brushSettings = toolSettings->getBrush();
m_brushType->setBrushSettings(brushSettings);
2013-03-31 00:43:00 +08:00
}
private:
BrushTypeField* m_brushType;
};
class ContextBar::ToleranceField : public IntEntry
{
public:
ToleranceField() : IntEntry(0, 255) {
2013-03-31 00:43:00 +08:00
}
protected:
void onValueChange() OVERRIDE {
IntEntry::onValueChange();
ISettings* settings = UIContext::instance()->getSettings();
Tool* currentTool = settings->getCurrentTool();
settings->getToolSettings(currentTool)
->setTolerance(getValue());
}
};
class ContextBar::InkTypeField : public ComboBox
{
public:
InkTypeField() : m_lock(false) {
2013-04-02 07:20:58 +08:00
// The same order as in InkType
addItem("Default Ink");
#if 0
2013-04-02 07:20:58 +08:00
addItem("Opaque");
#endif
2014-05-05 09:20:33 +08:00
addItem("Set Alpha");
2014-05-05 09:16:30 +08:00
addItem("Lock Alpha");
#if 0
2013-03-31 00:43:00 +08:00
addItem("Merge");
2013-04-02 07:20:58 +08:00
addItem("Shading");
addItem("Replace");
2013-04-02 07:55:29 +08:00
addItem("Erase");
2013-03-31 00:43:00 +08:00
addItem("Selection");
2013-04-02 07:20:58 +08:00
addItem("Blur");
addItem("Jumble");
#endif
2013-03-31 00:43:00 +08:00
}
2013-04-02 07:20:58 +08:00
void setInkType(InkType inkType) {
int index = 0;
switch (inkType) {
case kDefaultInk: index = 0; break;
2014-05-05 09:20:33 +08:00
case kSetAlphaInk: index = 1; break;
2014-05-05 09:16:30 +08:00
case kLockAlphaInk: index = 2; break;
}
m_lock = true;
setSelectedItemIndex(index);
m_lock = false;
2013-03-31 00:43:00 +08:00
}
protected:
void onChange() OVERRIDE {
ComboBox::onChange();
2013-04-02 07:20:58 +08:00
if (m_lock)
return;
InkType inkType = kDefaultInk;
switch (getSelectedItemIndex()) {
case 0: inkType = kDefaultInk; break;
2014-05-05 09:20:33 +08:00
case 1: inkType = kSetAlphaInk; break;
2014-05-05 09:16:30 +08:00
case 2: inkType = kLockAlphaInk; break;
}
2013-04-02 07:20:58 +08:00
ISettings* settings = UIContext::instance()->getSettings();
Tool* currentTool = settings->getCurrentTool();
settings->getToolSettings(currentTool)->setInkType(inkType);
2013-03-31 00:43:00 +08:00
}
void onCloseListBox() OVERRIDE {
releaseFocus();
}
bool m_lock;
2013-03-31 00:43:00 +08:00
};
class ContextBar::InkOpacityField : public IntEntry
{
public:
InkOpacityField() : IntEntry(0, 255) {
}
protected:
void onValueChange() OVERRIDE {
IntEntry::onValueChange();
ISettings* settings = UIContext::instance()->getSettings();
Tool* currentTool = settings->getCurrentTool();
settings->getToolSettings(currentTool)
->setOpacity(getValue());
}
};
class ContextBar::SprayWidthField : public IntEntry
{
public:
SprayWidthField() : IntEntry(1, 32) {
}
protected:
void onValueChange() OVERRIDE {
IntEntry::onValueChange();
ISettings* settings = UIContext::instance()->getSettings();
Tool* currentTool = settings->getCurrentTool();
settings->getToolSettings(currentTool)
->setSprayWidth(getValue());
}
};
class ContextBar::SpraySpeedField : public IntEntry
{
public:
SpraySpeedField() : IntEntry(1, 100) {
}
protected:
void onValueChange() OVERRIDE {
IntEntry::onValueChange();
ISettings* settings = UIContext::instance()->getSettings();
Tool* currentTool = settings->getCurrentTool();
settings->getToolSettings(currentTool)
->setSpraySpeed(getValue());
}
};
class ContextBar::TransparentColorField : public ColorButton
{
public:
TransparentColorField() : ColorButton(app::Color::fromMask(), IMAGE_RGB) {
Change.connect(Bind<void>(&TransparentColorField::onChange, this));
}
protected:
void onChange() {
UIContext::instance()->settings()->selection()->setMoveTransparentColor(getColor());
}
};
class ContextBar::RotAlgorithmField : public ComboBox
{
public:
RotAlgorithmField() {
// We use "m_lockChange" variable to avoid setting the rotation
// algorithm when we call ComboBox::addItem() (because the first
// addItem() generates an onChange() event).
m_lockChange = true;
addItem(new Item("Fast Rotation", kFastRotationAlgorithm));
addItem(new Item("RotSprite", kRotSpriteRotationAlgorithm));
m_lockChange = false;
setSelectedItemIndex((int)UIContext::instance()->settings()
->selection()->getRotationAlgorithm());
}
protected:
void onChange() OVERRIDE {
if (m_lockChange)
return;
UIContext::instance()->settings()->selection()
->setRotationAlgorithm(static_cast<Item*>(getSelectedItem())->algo());
}
void onCloseListBox() OVERRIDE {
releaseFocus();
}
private:
class Item : public ListItem {
public:
Item(const std::string& text, RotationAlgorithm algo) :
ListItem(text),
m_algo(algo) {
}
RotationAlgorithm algo() const { return m_algo; }
private:
RotationAlgorithm m_algo;
};
bool m_lockChange;
};
class ContextBar::FreehandAlgorithmField : public CheckBox
{
public:
FreehandAlgorithmField() : CheckBox("Pixel-perfect") {
setup_mini_font(this);
}
void onClick(Event& ev) OVERRIDE {
CheckBox::onClick(ev);
ISettings* settings = UIContext::instance()->getSettings();
Tool* currentTool = settings->getCurrentTool();
settings->getToolSettings(currentTool)
->setFreehandAlgorithm(isSelected() ?
kPixelPerfectFreehandAlgorithm:
kDefaultFreehandAlgorithm);
releaseFocus(
);
}
};
class ContextBar::SelectionModeField : public ButtonSet
{
public:
SelectionModeField() : ButtonSet(3, 1, 0,
PART_SELECTION_REPLACE,
PART_SELECTION_ADD,
PART_SELECTION_SUBTRACT) {
setSelectedItem(
(int)UIContext::instance()->settings()
->selection()->getSelectionMode());
}
void setupTooltips(TooltipManager* tooltipManager)
{
tooltipManager->addTooltipFor(getButtonAt(0), "Replace selection", JI_BOTTOM);
tooltipManager->addTooltipFor(getButtonAt(1), "Add to selection", JI_BOTTOM);
tooltipManager->addTooltipFor(getButtonAt(2), "Subtract from selection", JI_BOTTOM);
}
protected:
void onItemChange() OVERRIDE {
ButtonSet::onItemChange();
int item = getSelectedItem();
UIContext::instance()->settings()->selection()
->setSelectionMode((SelectionMode)item);
}
};
class ContextBar::DropPixelsField : public ButtonSet
{
public:
DropPixelsField() : ButtonSet(2, 1, -1,
PART_DROP_PIXELS_OK,
PART_DROP_PIXELS_CANCEL) {
}
void setupTooltips(TooltipManager* tooltipManager) {
tooltipManager->addTooltipFor(getButtonAt(0), "Drop pixels here", JI_BOTTOM);
tooltipManager->addTooltipFor(getButtonAt(1), "Cancel drag and drop", JI_BOTTOM);
}
Signal1<void, ContextBarObserver::DropAction> DropPixels;
protected:
void onItemChange() OVERRIDE {
ButtonSet::onItemChange();
switch (getSelectedItem()) {
case 0: DropPixels(ContextBarObserver::DropPixels); break;
case 1: DropPixels(ContextBarObserver::CancelDrag); break;
}
}
};
class ContextBar::GrabAlphaField : public CheckBox
{
public:
GrabAlphaField() : CheckBox("Grab Alpha") {
setup_mini_font(this);
}
protected:
void onClick(Event& ev) OVERRIDE {
CheckBox::onClick(ev);
UIContext::instance()->settings()->setGrabAlpha(isSelected());
releaseFocus();
}
};
2013-03-31 00:43:00 +08:00
ContextBar::ContextBar()
: Box(JI_HORIZONTAL)
, m_toolSettings(NULL)
2013-03-31 00:43:00 +08:00
{
border_width.b = 2*jguiscale();
SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
setBgColor(theme->getColor(ThemeColor::Workspace));
addChild(m_selectionOptionsBox = new HBox());
m_selectionOptionsBox->addChild(m_dropPixels = new DropPixelsField());
m_selectionOptionsBox->addChild(m_selectionMode = new SelectionModeField);
m_selectionOptionsBox->addChild(m_transparentColor = new TransparentColorField);
m_selectionOptionsBox->addChild(m_rotAlgo = new RotAlgorithmField());
2013-03-31 00:43:00 +08:00
addChild(m_brushType = new BrushTypeField());
addChild(m_brushSize = new BrushSizeField());
addChild(m_brushAngle = new BrushAngleField(m_brushType));
addChild(m_toleranceLabel = new Label("Tolerance:"));
2013-03-31 00:43:00 +08:00
addChild(m_tolerance = new ToleranceField());
addChild(m_inkType = new InkTypeField());
addChild(m_opacityLabel = new Label("Opacity:"));
2013-03-31 00:43:00 +08:00
addChild(m_inkOpacity = new InkOpacityField());
addChild(m_grabAlpha = new GrabAlphaField());
2013-03-31 00:43:00 +08:00
// addChild(new InkChannelTargetField());
// addChild(new InkShadeField());
// addChild(new InkSelectionField());
addChild(m_sprayBox = new HBox());
m_sprayBox->addChild(setup_mini_font(new Label("Spray:")));
m_sprayBox->addChild(m_sprayWidth = new SprayWidthField());
m_sprayBox->addChild(m_spraySpeed = new SpraySpeedField());
addChild(m_freehandBox = new HBox());
m_freehandBox->addChild(m_freehandAlgo = new FreehandAlgorithmField());
setup_mini_font(m_toleranceLabel);
setup_mini_font(m_opacityLabel);
TooltipManager* tooltipManager = new TooltipManager();
addChild(tooltipManager);
tooltipManager->addTooltipFor(m_brushType, "Brush Type", JI_BOTTOM);
tooltipManager->addTooltipFor(m_brushSize, "Brush Size (in pixels)", JI_BOTTOM);
tooltipManager->addTooltipFor(m_brushAngle, "Brush Angle (in degrees)", JI_BOTTOM);
tooltipManager->addTooltipFor(m_inkOpacity, "Opacity (Alpha value in RGBA)", JI_BOTTOM);
tooltipManager->addTooltipFor(m_sprayWidth, "Spray Width", JI_BOTTOM);
tooltipManager->addTooltipFor(m_spraySpeed, "Spray Speed", JI_BOTTOM);
tooltipManager->addTooltipFor(m_transparentColor, "Transparent Color", JI_BOTTOM);
tooltipManager->addTooltipFor(m_rotAlgo, "Rotation Algorithm", JI_BOTTOM);
tooltipManager->addTooltipFor(m_freehandAlgo, "Freehand trace algorithm", JI_BOTTOM);
tooltipManager->addTooltipFor(m_grabAlpha,
"When checked the tool picks the color from the active layer, and its alpha\n"
"component is used to setup the opacity level of all drawing tools.\n\n"
"When unchecked -the default behavior- the color is picked\n"
"from the composition of all sprite layers.", JI_LEFT | JI_TOP);
m_selectionMode->setupTooltips(tooltipManager);
m_dropPixels->setupTooltips(tooltipManager);
2014-06-15 02:09:43 +08:00
App::instance()->BrushSizeAfterChange.connect(&ContextBar::onBrushSizeChange, this);
App::instance()->BrushAngleAfterChange.connect(&ContextBar::onBrushAngleChange, this);
2013-03-31 00:43:00 +08:00
App::instance()->CurrentToolChange.connect(&ContextBar::onCurrentToolChange, this);
m_dropPixels->DropPixels.connect(&ContextBar::onDropPixels, this);
2013-03-31 00:43:00 +08:00
onCurrentToolChange();
}
ContextBar::~ContextBar()
{
if (m_toolSettings)
m_toolSettings->removeObserver(this);
2013-03-31 00:43:00 +08:00
}
bool ContextBar::onProcessMessage(Message* msg)
{
return Box::onProcessMessage(msg);
}
void ContextBar::onPreferredSize(PreferredSizeEvent& ev)
{
ev.setPreferredSize(gfx::Size(0, 18*jguiscale())); // TODO calculate height
}
void ContextBar::onSetOpacity(int newOpacity)
{
m_inkOpacity->setTextf("%d", newOpacity);
}
2014-06-15 02:09:43 +08:00
void ContextBar::onBrushSizeChange()
2013-03-31 00:43:00 +08:00
{
ISettings* settings = UIContext::instance()->getSettings();
Tool* currentTool = settings->getCurrentTool();
IToolSettings* toolSettings = settings->getToolSettings(currentTool);
2014-06-15 02:09:43 +08:00
IBrushSettings* brushSettings = toolSettings->getBrush();
2013-03-31 00:43:00 +08:00
2014-06-15 02:09:43 +08:00
m_brushType->setBrushSettings(brushSettings);
m_brushSize->setTextf("%d", brushSettings->getSize());
2013-03-31 00:43:00 +08:00
}
2014-06-15 02:09:43 +08:00
void ContextBar::onBrushAngleChange()
{
ISettings* settings = UIContext::instance()->getSettings();
Tool* currentTool = settings->getCurrentTool();
IToolSettings* toolSettings = settings->getToolSettings(currentTool);
2014-06-15 02:09:43 +08:00
IBrushSettings* brushSettings = toolSettings->getBrush();
2014-06-15 02:09:43 +08:00
m_brushType->setBrushSettings(brushSettings);
m_brushAngle->setTextf("%d", brushSettings->getAngle());
}
2013-03-31 00:43:00 +08:00
void ContextBar::onCurrentToolChange()
{
ISettings* settings = UIContext::instance()->getSettings();
updateFromTool(settings->getCurrentTool());
}
void ContextBar::onDropPixels(ContextBarObserver::DropAction action)
{
notifyObservers(&ContextBarObserver::onDropPixels, action);
}
void ContextBar::updateFromTool(tools::Tool* tool)
{
ISettings* settings = UIContext::instance()->getSettings();
IToolSettings* toolSettings = settings->getToolSettings(tool);
2014-06-15 02:09:43 +08:00
IBrushSettings* brushSettings = toolSettings->getBrush();
2013-03-31 00:43:00 +08:00
if (m_toolSettings)
m_toolSettings->removeObserver(this);
m_toolSettings = toolSettings;
m_toolSettings->addObserver(this);
2014-06-15 02:09:43 +08:00
m_brushType->setBrushSettings(brushSettings);
m_brushSize->setTextf("%d", brushSettings->getSize());
m_brushAngle->setTextf("%d", brushSettings->getAngle());
2013-03-31 00:43:00 +08:00
m_tolerance->setTextf("%d", toolSettings->getTolerance());
2013-04-02 07:20:58 +08:00
m_inkType->setInkType(toolSettings->getInkType());
2013-03-31 00:43:00 +08:00
m_inkOpacity->setTextf("%d", toolSettings->getOpacity());
m_grabAlpha->setSelected(settings->getGrabAlpha());
m_freehandAlgo->setSelected(toolSettings->getFreehandAlgorithm() == kPixelPerfectFreehandAlgorithm);
m_sprayWidth->setValue(toolSettings->getSprayWidth());
m_spraySpeed->setValue(toolSettings->getSpraySpeed());
// True if the current tool needs opacity options
bool hasOpacity = (tool->getInk(0)->isPaint() ||
tool->getInk(0)->isEffect() ||
tool->getInk(1)->isPaint() ||
tool->getInk(1)->isEffect());
// True if the current tool is eyedropper.
bool isEyedropper =
(tool->getInk(0)->isEyedropper() ||
tool->getInk(1)->isEyedropper());
// True if it makes sense to change the ink property for the current
// tool.
bool hasInk = hasOpacity;
// True if the current tool needs tolerance options
bool hasTolerance = (tool->getPointShape(0)->isFloodFill() ||
tool->getPointShape(1)->isFloodFill());
// True if the current tool needs spray options
bool hasSprayOptions = (tool->getPointShape(0)->isSpray() ||
tool->getPointShape(1)->isSpray());
bool hasSelectOptions = (tool->getInk(0)->isSelection() ||
tool->getInk(1)->isSelection());
bool isFreehand =
(tool->getController(0)->isFreehand() ||
tool->getController(1)->isFreehand());
// Show/Hide fields
m_brushType->setVisible(hasOpacity);
m_brushSize->setVisible(hasOpacity);
m_brushAngle->setVisible(hasOpacity);
m_opacityLabel->setVisible(hasOpacity);
m_inkType->setVisible(hasInk);
m_inkOpacity->setVisible(hasOpacity);
m_grabAlpha->setVisible(isEyedropper);
m_freehandBox->setVisible(isFreehand && hasOpacity);
m_toleranceLabel->setVisible(hasTolerance);
m_tolerance->setVisible(hasTolerance);
m_sprayBox->setVisible(hasSprayOptions);
m_selectionOptionsBox->setVisible(hasSelectOptions);
m_selectionMode->setVisible(true);
m_dropPixels->setVisible(false);
layout();
2013-03-31 00:43:00 +08:00
}
void ContextBar::updateForMovingPixels()
{
tools::Tool* tool = App::instance()->getToolBox()->getToolById(
tools::WellKnownTools::RectangularMarquee);
if (tool)
updateFromTool(tool);
m_dropPixels->deselectItems();
m_dropPixels->setVisible(true);
m_selectionMode->setVisible(false);
layout();
}
} // namespace app