2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
|
|
|
// Copyright (C) 2001-2015 David Capello
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License version 2 as
|
|
|
|
// published by the Free Software Foundation.
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2013-03-31 00:43:00 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
|
|
|
|
2013-11-10 06:59:05 +08:00
|
|
|
#include "app/ui/context_bar.h"
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/app.h"
|
2015-04-27 11:08:04 +08:00
|
|
|
#include "app/commands/commands.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/modules/gui.h"
|
2015-04-28 23:38:15 +08:00
|
|
|
#include "app/modules/palettes.h"
|
2015-04-27 11:08:04 +08:00
|
|
|
#include "app/pref/preferences.h"
|
2014-01-26 03:26:49 +08:00
|
|
|
#include "app/tools/controller.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/tools/ink.h"
|
2015-05-19 03:53:25 +08:00
|
|
|
#include "app/tools/ink_type.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/tools/point_shape.h"
|
2015-05-19 03:53:25 +08:00
|
|
|
#include "app/tools/selection_mode.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/tools/tool.h"
|
2014-01-26 03:26:49 +08:00
|
|
|
#include "app/tools/tool_box.h"
|
2015-04-28 23:38:15 +08:00
|
|
|
#include "app/ui/brush_popup.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/button_set.h"
|
2013-11-30 04:59:28 +08:00
|
|
|
#include "app/ui/color_button.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/skin/skin_theme.h"
|
|
|
|
#include "app/ui_context.h"
|
2013-11-30 04:59:28 +08:00
|
|
|
#include "base/bind.h"
|
2014-10-25 23:10:52 +08:00
|
|
|
#include "base/scoped_value.h"
|
2013-03-31 00:43:00 +08:00
|
|
|
#include "base/unique_ptr.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/brush.h"
|
|
|
|
#include "doc/conversion_she.h"
|
|
|
|
#include "doc/image.h"
|
|
|
|
#include "doc/palette.h"
|
2014-06-23 05:53:14 +08:00
|
|
|
#include "she/surface.h"
|
|
|
|
#include "she/system.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"
|
2013-12-30 04:11:56 +08:00
|
|
|
#include "ui/listitem.h"
|
2015-07-03 00:16:06 +08:00
|
|
|
#include "ui/menu.h"
|
2013-03-31 07:46:04 +08:00
|
|
|
#include "ui/popup_window.h"
|
2013-03-31 00:43:00 +08:00
|
|
|
#include "ui/preferred_size_event.h"
|
|
|
|
#include "ui/theme.h"
|
2013-03-31 08:31:34 +08:00
|
|
|
#include "ui/tooltips.h"
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
|
|
|
|
|
|
|
using namespace app::skin;
|
2013-03-31 00:43:00 +08:00
|
|
|
using namespace gfx;
|
|
|
|
using namespace ui;
|
|
|
|
using namespace tools;
|
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
static bool g_updatingFromCode = false;
|
2014-10-25 23:10:52 +08:00
|
|
|
|
2015-04-30 02:00:05 +08:00
|
|
|
class ContextBar::BrushTypeField : public ButtonSet
|
|
|
|
, public BrushPopupDelegate {
|
2013-03-31 00:43:00 +08:00
|
|
|
public:
|
2015-04-29 05:21:33 +08:00
|
|
|
BrushTypeField(ContextBar* owner)
|
|
|
|
: ButtonSet(1)
|
2015-04-30 02:00:05 +08:00
|
|
|
, m_owner(owner)
|
|
|
|
, m_popupWindow(this) {
|
2015-08-05 06:38:52 +08:00
|
|
|
SkinPartPtr part(new SkinPart);
|
|
|
|
part->setBitmap(
|
|
|
|
0, BrushPopup::createSurfaceForBrush(BrushRef(nullptr)));
|
|
|
|
|
|
|
|
addItem(part);
|
2015-04-30 03:34:21 +08:00
|
|
|
m_popupWindow.BrushChange.connect(&BrushTypeField::onBrushChange, this);
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
~BrushTypeField() {
|
2013-03-31 07:46:04 +08:00
|
|
|
closePopup();
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
|
2015-04-29 05:21:33 +08:00
|
|
|
void updateBrush(tools::Tool* tool = nullptr) {
|
2015-08-05 06:38:52 +08:00
|
|
|
SkinPartPtr part(new SkinPart);
|
|
|
|
part->setBitmap(
|
|
|
|
0, BrushPopup::createSurfaceForBrush(
|
|
|
|
m_owner->activeBrush(tool)));
|
2015-04-28 23:38:15 +08:00
|
|
|
|
2015-08-05 06:38:52 +08:00
|
|
|
getItem(0)->setIcon(part);
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
|
2015-04-29 23:32:44 +08:00
|
|
|
void setupTooltips(TooltipManager* tooltipManager) {
|
|
|
|
m_popupWindow.setupTooltips(tooltipManager);
|
|
|
|
}
|
|
|
|
|
2013-03-31 00:43:00 +08:00
|
|
|
protected:
|
2014-09-08 13:27:41 +08:00
|
|
|
void onItemChange() override {
|
|
|
|
ButtonSet::onItemChange();
|
2013-03-31 07:46:04 +08:00
|
|
|
|
2015-04-28 23:53:02 +08:00
|
|
|
if (!m_popupWindow.isVisible())
|
2013-03-31 07:46:04 +08:00
|
|
|
openPopup();
|
|
|
|
else
|
|
|
|
closePopup();
|
|
|
|
}
|
|
|
|
|
2013-03-31 00:43:00 +08:00
|
|
|
void onPreferredSize(PreferredSizeEvent& ev) {
|
2014-11-26 09:33:45 +08:00
|
|
|
ev.setPreferredSize(Size(16, 18)*guiscale());
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 02:00:05 +08:00
|
|
|
// BrushPopupDelegate impl
|
|
|
|
void onDeleteBrushSlot(int slot) override {
|
|
|
|
m_owner->removeBrush(slot);
|
|
|
|
}
|
|
|
|
|
2015-04-30 04:26:25 +08:00
|
|
|
void onDeleteAllBrushes() override {
|
2015-04-30 22:59:47 +08:00
|
|
|
m_owner->removeAllBrushes();
|
2015-04-30 04:26:25 +08:00
|
|
|
}
|
|
|
|
|
2015-05-07 04:39:40 +08:00
|
|
|
bool onIsBrushSlotLocked(int slot) const override {
|
|
|
|
return m_owner->isBrushSlotLocked(slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onLockBrushSlot(int slot) override {
|
|
|
|
m_owner->lockBrushSlot(slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onUnlockBrushSlot(int slot) override {
|
|
|
|
m_owner->unlockBrushSlot(slot);
|
|
|
|
}
|
|
|
|
|
2013-03-31 00:43:00 +08:00
|
|
|
private:
|
2015-04-30 02:00:05 +08:00
|
|
|
// Returns a little rectangle that can be used by the popup as the
|
|
|
|
// first brush position.
|
|
|
|
gfx::Rect getPopupBox() {
|
2013-03-31 07:46:04 +08:00
|
|
|
Rect rc = getBounds();
|
2014-11-26 09:33:45 +08:00
|
|
|
rc.y += rc.h - 2*guiscale();
|
2014-09-08 13:27:41 +08:00
|
|
|
rc.setSize(getPreferredSize());
|
2015-04-30 02:00:05 +08:00
|
|
|
return rc;
|
|
|
|
}
|
2015-04-28 23:38:15 +08:00
|
|
|
|
2015-04-30 02:00:05 +08:00
|
|
|
void openPopup() {
|
2015-04-29 05:21:33 +08:00
|
|
|
doc::BrushRef brush = m_owner->activeBrush();
|
2015-04-28 23:38:15 +08:00
|
|
|
|
2015-04-30 22:59:47 +08:00
|
|
|
m_popupWindow.regenerate(getPopupBox(), m_owner->getBrushes());
|
2015-04-28 23:53:02 +08:00
|
|
|
m_popupWindow.setBrush(brush.get());
|
2013-03-31 07:46:04 +08:00
|
|
|
|
2015-04-28 23:53:02 +08:00
|
|
|
Region rgn(m_popupWindow.getBounds().createUnion(getBounds()));
|
|
|
|
m_popupWindow.setHotRegion(rgn);
|
2015-04-28 23:38:15 +08:00
|
|
|
|
2015-04-28 23:53:02 +08:00
|
|
|
m_popupWindow.openWindow();
|
2013-03-31 07:46:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void closePopup() {
|
2015-04-28 23:53:02 +08:00
|
|
|
m_popupWindow.closeWindow(NULL);
|
2015-07-03 00:16:06 +08:00
|
|
|
deselectItems();
|
2013-03-31 07:46:04 +08:00
|
|
|
}
|
|
|
|
|
2015-04-29 23:32:44 +08:00
|
|
|
void onBrushChange(const BrushRef& brush) {
|
|
|
|
if (brush->type() == kImageBrushType)
|
|
|
|
m_owner->setActiveBrush(brush);
|
|
|
|
else {
|
2015-05-19 03:53:25 +08:00
|
|
|
Tool* tool = App::instance()->activeTool();
|
|
|
|
ToolPreferences::Brush& brushPref = Preferences::instance().tool(tool).brush;
|
|
|
|
|
|
|
|
brushPref.type(static_cast<app::gen::BrushType>(brush->type()));
|
2013-03-31 07:46:04 +08:00
|
|
|
|
2015-04-29 23:32:44 +08:00
|
|
|
m_owner->setActiveBrush(
|
2015-05-19 03:53:25 +08:00
|
|
|
ContextBar::createBrushFromPreferences(&brushPref));
|
2015-04-29 23:32:44 +08:00
|
|
|
}
|
2013-03-31 07:46:04 +08:00
|
|
|
}
|
|
|
|
|
2015-04-29 05:21:33 +08:00
|
|
|
ContextBar* m_owner;
|
2015-04-28 23:53:02 +08:00
|
|
|
BrushPopup m_popupWindow;
|
2013-03-31 00:43:00 +08:00
|
|
|
};
|
|
|
|
|
2015-07-04 00:41:50 +08:00
|
|
|
class ContextBar::BrushSizeField : public IntEntry {
|
2013-03-31 00:43:00 +08:00
|
|
|
public:
|
2014-12-08 07:50:26 +08:00
|
|
|
BrushSizeField() : IntEntry(Brush::kMinBrushSize, Brush::kMaxBrushSize) {
|
2013-03-31 00:43:00 +08:00
|
|
|
setSuffix("px");
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-08-15 10:07:47 +08:00
|
|
|
void onValueChange() override {
|
2015-05-19 03:53:25 +08:00
|
|
|
if (g_updatingFromCode)
|
2014-10-25 23:10:52 +08:00
|
|
|
return;
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
IntEntry::onValueChange();
|
|
|
|
base::ScopedValue<bool> lockFlag(g_updatingFromCode, true, g_updatingFromCode);
|
|
|
|
|
|
|
|
Tool* tool = App::instance()->activeTool();
|
|
|
|
Preferences::instance().tool(tool).brush.size(getValue());
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ContextBar::BrushAngleField : public IntEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BrushAngleField(BrushTypeField* brushType)
|
|
|
|
: IntEntry(0, 180)
|
|
|
|
, m_brushType(brushType) {
|
2013-11-24 05:01:42 +08:00
|
|
|
setSuffix("\xc2\xb0");
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-08-15 10:07:47 +08:00
|
|
|
void onValueChange() override {
|
2015-05-19 03:53:25 +08:00
|
|
|
if (g_updatingFromCode)
|
2014-10-25 23:10:52 +08:00
|
|
|
return;
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
IntEntry::onValueChange();
|
|
|
|
base::ScopedValue<bool> lockFlag(g_updatingFromCode, true, g_updatingFromCode);
|
|
|
|
|
|
|
|
Tool* tool = App::instance()->activeTool();
|
|
|
|
Preferences::instance().tool(tool).brush.angle(getValue());
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2015-04-29 05:21:33 +08:00
|
|
|
m_brushType->updateBrush();
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
BrushTypeField* m_brushType;
|
|
|
|
};
|
|
|
|
|
2015-04-27 11:08:04 +08:00
|
|
|
class ContextBar::BrushPatternField : public ComboBox
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BrushPatternField() : m_lock(false) {
|
2015-04-27 22:45:00 +08:00
|
|
|
addItem("Pattern aligned to source");
|
2015-04-27 11:08:04 +08:00
|
|
|
addItem("Pattern aligned to destination");
|
|
|
|
addItem("Paint brush");
|
|
|
|
}
|
|
|
|
|
|
|
|
void setBrushPattern(BrushPattern type) {
|
|
|
|
int index = 0;
|
|
|
|
|
|
|
|
switch (type) {
|
2015-04-27 22:45:00 +08:00
|
|
|
case BrushPattern::ALIGNED_TO_SRC: index = 0; break;
|
2015-04-27 11:08:04 +08:00
|
|
|
case BrushPattern::ALIGNED_TO_DST: index = 1; break;
|
|
|
|
case BrushPattern::PAINT_BRUSH: index = 2; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_lock = true;
|
|
|
|
setSelectedItemIndex(index);
|
|
|
|
m_lock = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void onChange() override {
|
|
|
|
ComboBox::onChange();
|
|
|
|
|
|
|
|
if (m_lock)
|
|
|
|
return;
|
|
|
|
|
2015-04-27 22:45:00 +08:00
|
|
|
BrushPattern type = BrushPattern::ALIGNED_TO_SRC;
|
2015-04-27 11:08:04 +08:00
|
|
|
|
|
|
|
switch (getSelectedItemIndex()) {
|
2015-04-27 22:45:00 +08:00
|
|
|
case 0: type = BrushPattern::ALIGNED_TO_SRC; break;
|
2015-04-27 11:08:04 +08:00
|
|
|
case 1: type = BrushPattern::ALIGNED_TO_DST; break;
|
|
|
|
case 2: type = BrushPattern::PAINT_BRUSH; break;
|
|
|
|
}
|
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
Preferences::instance().brush.pattern(type);
|
2015-04-27 11:08:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool m_lock;
|
|
|
|
};
|
|
|
|
|
2013-03-31 00:43:00 +08:00
|
|
|
class ContextBar::ToleranceField : public IntEntry
|
|
|
|
{
|
|
|
|
public:
|
2013-03-31 08:14:52 +08:00
|
|
|
ToleranceField() : IntEntry(0, 255) {
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-08-15 10:07:47 +08:00
|
|
|
void onValueChange() override {
|
2015-05-19 03:53:25 +08:00
|
|
|
if (g_updatingFromCode)
|
2014-10-25 23:10:52 +08:00
|
|
|
return;
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
IntEntry::onValueChange();
|
|
|
|
|
|
|
|
Tool* tool = App::instance()->activeTool();
|
|
|
|
Preferences::instance().tool(tool).tolerance(getValue());
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-07 11:07:24 +08:00
|
|
|
class ContextBar::ContiguousField : public CheckBox
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ContiguousField() : CheckBox("Contiguous") {
|
|
|
|
setup_mini_font(this);
|
|
|
|
}
|
|
|
|
|
2015-06-18 00:22:46 +08:00
|
|
|
protected:
|
|
|
|
void onClick(Event& ev) override {
|
|
|
|
CheckBox::onClick(ev);
|
|
|
|
|
|
|
|
Tool* tool = App::instance()->activeTool();
|
|
|
|
Preferences::instance().tool(tool).contiguous(isSelected());
|
|
|
|
|
|
|
|
releaseFocus();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ContextBar::StopAtGridField : public CheckBox
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
StopAtGridField() : CheckBox("Stop at Grid") {
|
|
|
|
setup_mini_font(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setStopAtGrid(bool state) {
|
2014-08-07 11:07:24 +08:00
|
|
|
setSelected(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-08-15 10:07:47 +08:00
|
|
|
void onClick(Event& ev) override {
|
2014-08-07 11:07:24 +08:00
|
|
|
CheckBox::onClick(ev);
|
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
Tool* tool = App::instance()->activeTool();
|
2015-06-18 00:22:46 +08:00
|
|
|
Preferences::instance().tool(tool).floodfill.stopAtGrid(
|
|
|
|
(isSelected() ? app::gen::StopAtGrid::IF_VISIBLE:
|
|
|
|
app::gen::StopAtGrid::NEVER));
|
2014-08-07 11:07:24 +08:00
|
|
|
|
|
|
|
releaseFocus();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-03 00:16:06 +08:00
|
|
|
class ContextBar::InkTypeField : public ButtonSet
|
2013-03-31 00:43:00 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-07-03 00:16:06 +08:00
|
|
|
InkTypeField(ContextBar* owner) : ButtonSet(1)
|
|
|
|
, m_owner(owner) {
|
2015-08-05 06:38:52 +08:00
|
|
|
SkinTheme* theme = SkinTheme::instance();
|
|
|
|
addItem(theme->parts.inkDefault());
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
|
2013-04-02 07:20:58 +08:00
|
|
|
void setInkType(InkType inkType) {
|
2015-08-05 06:38:52 +08:00
|
|
|
SkinTheme* theme = SkinTheme::instance();
|
|
|
|
SkinPartPtr part = theme->parts.inkDefault();
|
2014-03-09 08:00:14 +08:00
|
|
|
|
|
|
|
switch (inkType) {
|
2015-08-05 06:38:52 +08:00
|
|
|
case InkType::ALPHA_COMPOSITING: part = theme->parts.inkDefault(); break;
|
|
|
|
case InkType::COPY_COLOR: part = theme->parts.inkCopyColor(); break;
|
|
|
|
case InkType::LOCK_ALPHA: part = theme->parts.inkLockAlpha(); break;
|
2014-03-09 08:00:14 +08:00
|
|
|
}
|
|
|
|
|
2015-08-05 06:38:52 +08:00
|
|
|
getItem(0)->setIcon(part);
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-07-03 00:16:06 +08:00
|
|
|
void onItemChange() override {
|
|
|
|
ButtonSet::onItemChange();
|
2013-04-02 07:20:58 +08:00
|
|
|
|
2015-07-03 00:16:06 +08:00
|
|
|
gfx::Rect bounds = getBounds();
|
2014-04-22 09:23:22 +08:00
|
|
|
|
2015-07-03 00:16:06 +08:00
|
|
|
Menu menu;
|
|
|
|
MenuItem
|
|
|
|
alphacompo("Alpha Compositing"),
|
2015-07-27 22:24:00 +08:00
|
|
|
copycolor("Copy Color+Alpha"),
|
2015-07-23 21:07:07 +08:00
|
|
|
lockalpha("Lock Alpha"),
|
|
|
|
alltools("Same in all Tools");
|
2015-07-03 00:16:06 +08:00
|
|
|
menu.addChild(&alphacompo);
|
2015-07-27 22:24:00 +08:00
|
|
|
menu.addChild(©color);
|
2015-07-03 00:16:06 +08:00
|
|
|
menu.addChild(&lockalpha);
|
2015-07-23 21:07:07 +08:00
|
|
|
menu.addChild(new MenuSeparator);
|
|
|
|
menu.addChild(&alltools);
|
2014-03-09 07:37:43 +08:00
|
|
|
|
2015-07-03 00:16:06 +08:00
|
|
|
Tool* tool = App::instance()->activeTool();
|
|
|
|
switch (Preferences::instance().tool(tool).ink()) {
|
|
|
|
case tools::InkType::ALPHA_COMPOSITING: alphacompo.setSelected(true); break;
|
2015-07-27 22:24:00 +08:00
|
|
|
case tools::InkType::COPY_COLOR: copycolor.setSelected(true); break;
|
2015-07-03 00:16:06 +08:00
|
|
|
case tools::InkType::LOCK_ALPHA: lockalpha.setSelected(true); break;
|
2014-03-09 07:37:43 +08:00
|
|
|
}
|
2015-07-23 21:07:07 +08:00
|
|
|
alltools.setSelected(Preferences::instance().shared.shareInk());
|
2014-03-09 07:37:43 +08:00
|
|
|
|
2015-07-03 00:16:06 +08:00
|
|
|
alphacompo.Click.connect(Bind<void>(&InkTypeField::selectInk, this, InkType::ALPHA_COMPOSITING));
|
2015-07-27 22:24:00 +08:00
|
|
|
copycolor.Click.connect(Bind<void>(&InkTypeField::selectInk, this, InkType::COPY_COLOR));
|
2015-07-03 00:16:06 +08:00
|
|
|
lockalpha.Click.connect(Bind<void>(&InkTypeField::selectInk, this, InkType::LOCK_ALPHA));
|
2015-07-23 21:07:07 +08:00
|
|
|
alltools.Click.connect(Bind<void>(&InkTypeField::onSameInAllTools, this));
|
2015-07-03 00:16:06 +08:00
|
|
|
|
|
|
|
menu.showPopup(gfx::Point(bounds.x, bounds.y+bounds.h));
|
|
|
|
|
|
|
|
deselectItems();
|
|
|
|
}
|
|
|
|
|
|
|
|
void selectInk(InkType inkType) {
|
2015-07-23 21:07:07 +08:00
|
|
|
Preferences& pref = Preferences::instance();
|
|
|
|
|
|
|
|
if (pref.shared.shareInk()) {
|
|
|
|
for (Tool* tool : *App::instance()->getToolBox())
|
|
|
|
pref.tool(tool).ink(inkType);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Tool* tool = App::instance()->activeTool();
|
|
|
|
pref.tool(tool).ink(inkType);
|
|
|
|
}
|
2014-03-09 07:31:55 +08:00
|
|
|
|
2015-07-03 00:16:06 +08:00
|
|
|
m_owner->updateForCurrentTool();
|
2014-03-09 07:31:55 +08:00
|
|
|
}
|
2014-04-22 09:23:22 +08:00
|
|
|
|
2015-07-23 21:07:07 +08:00
|
|
|
void onSameInAllTools() {
|
|
|
|
Preferences& pref = Preferences::instance();
|
|
|
|
bool newState = !pref.shared.shareInk();
|
|
|
|
pref.shared.shareInk(newState);
|
|
|
|
|
|
|
|
if (newState) {
|
|
|
|
Tool* activeTool = App::instance()->activeTool();
|
|
|
|
InkType inkType = pref.tool(activeTool).ink();
|
|
|
|
int opacity = pref.tool(activeTool).opacity();
|
|
|
|
|
|
|
|
for (Tool* tool : *App::instance()->getToolBox()) {
|
|
|
|
if (tool != activeTool) {
|
|
|
|
pref.tool(tool).ink(inkType);
|
|
|
|
pref.tool(tool).opacity(opacity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-03 00:16:06 +08:00
|
|
|
ContextBar* m_owner;
|
2013-03-31 00:43:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ContextBar::InkOpacityField : public IntEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
InkOpacityField() : IntEntry(0, 255) {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-08-15 10:07:47 +08:00
|
|
|
void onValueChange() override {
|
2015-05-19 03:53:25 +08:00
|
|
|
if (g_updatingFromCode)
|
2014-10-25 23:10:52 +08:00
|
|
|
return;
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
IntEntry::onValueChange();
|
|
|
|
base::ScopedValue<bool> lockFlag(g_updatingFromCode, true, g_updatingFromCode);
|
|
|
|
|
|
|
|
int newValue = getValue();
|
2015-07-23 21:07:07 +08:00
|
|
|
Preferences& pref = Preferences::instance();
|
|
|
|
if (pref.shared.shareInk()) {
|
|
|
|
for (Tool* tool : *App::instance()->getToolBox())
|
|
|
|
pref.tool(tool).opacity(newValue);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Tool* tool = App::instance()->activeTool();
|
|
|
|
pref.tool(tool).opacity(newValue);
|
|
|
|
}
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-03-31 08:31:34 +08:00
|
|
|
class ContextBar::SprayWidthField : public IntEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SprayWidthField() : IntEntry(1, 32) {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-08-15 10:07:47 +08:00
|
|
|
void onValueChange() override {
|
2013-03-31 08:31:34 +08:00
|
|
|
IntEntry::onValueChange();
|
2015-05-19 03:53:25 +08:00
|
|
|
if (g_updatingFromCode)
|
2014-10-25 23:10:52 +08:00
|
|
|
return;
|
2013-03-31 08:31:34 +08:00
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
Tool* tool = App::instance()->activeTool();
|
|
|
|
Preferences::instance().tool(tool).spray.width(getValue());
|
2013-03-31 08:31:34 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ContextBar::SpraySpeedField : public IntEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SpraySpeedField() : IntEntry(1, 100) {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-08-15 10:07:47 +08:00
|
|
|
void onValueChange() override {
|
2015-05-19 03:53:25 +08:00
|
|
|
if (g_updatingFromCode)
|
2014-10-25 23:10:52 +08:00
|
|
|
return;
|
2013-03-31 08:31:34 +08:00
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
IntEntry::onValueChange();
|
|
|
|
|
|
|
|
Tool* tool = App::instance()->activeTool();
|
|
|
|
Preferences::instance().tool(tool).spray.speed(getValue());
|
2013-03-31 08:31:34 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-24 09:42:14 +08:00
|
|
|
class ContextBar::TransparentColorField : public HBox {
|
2013-11-30 04:59:28 +08:00
|
|
|
public:
|
2015-07-24 09:42:14 +08:00
|
|
|
TransparentColorField(ContextBar* owner)
|
|
|
|
: m_icon(1)
|
|
|
|
, m_maskColor(app::Color::fromMask(), IMAGE_RGB)
|
|
|
|
, m_owner(owner) {
|
2015-08-05 06:38:52 +08:00
|
|
|
SkinTheme* theme = SkinTheme::instance();
|
|
|
|
|
2015-07-24 09:42:14 +08:00
|
|
|
addChild(&m_icon);
|
|
|
|
addChild(&m_maskColor);
|
|
|
|
|
2015-08-05 06:38:52 +08:00
|
|
|
m_icon.addItem(theme->parts.selectionOpaque());
|
2015-07-24 09:42:14 +08:00
|
|
|
gfx::Size sz = m_icon.getItem(0)->getPreferredSize();
|
|
|
|
sz.w += 2*guiscale();
|
|
|
|
m_icon.getItem(0)->setMinSize(sz);
|
|
|
|
|
|
|
|
m_icon.ItemChange.connect(Bind<void>(&TransparentColorField::onPopup, this));
|
|
|
|
m_maskColor.Change.connect(Bind<void>(&TransparentColorField::onChangeColor, this));
|
2015-07-27 22:43:48 +08:00
|
|
|
|
|
|
|
Preferences::instance().selection.opaque.AfterChange.connect(
|
|
|
|
Bind<void>(&TransparentColorField::onOpaqueChange, this));
|
|
|
|
|
2015-07-28 22:14:12 +08:00
|
|
|
onOpaqueChange();
|
2013-11-30 04:59:28 +08:00
|
|
|
}
|
|
|
|
|
2015-07-24 09:42:14 +08:00
|
|
|
private:
|
|
|
|
|
|
|
|
void onPopup() {
|
|
|
|
gfx::Rect bounds = getBounds();
|
|
|
|
|
|
|
|
Menu menu;
|
|
|
|
MenuItem
|
|
|
|
opaque("Opaque"),
|
|
|
|
masked("Transparent");
|
|
|
|
menu.addChild(&opaque);
|
|
|
|
menu.addChild(&masked);
|
|
|
|
|
|
|
|
if (Preferences::instance().selection.opaque())
|
|
|
|
opaque.setSelected(true);
|
|
|
|
else
|
|
|
|
masked.setSelected(true);
|
|
|
|
|
|
|
|
opaque.Click.connect(Bind<void>(&TransparentColorField::setOpaque, this, true));
|
|
|
|
masked.Click.connect(Bind<void>(&TransparentColorField::setOpaque, this, false));
|
|
|
|
|
|
|
|
menu.showPopup(gfx::Point(bounds.x, bounds.y+bounds.h));
|
2013-11-30 04:59:28 +08:00
|
|
|
}
|
2015-07-24 09:42:14 +08:00
|
|
|
|
|
|
|
void onChangeColor() {
|
|
|
|
Preferences::instance().selection.transparentColor(
|
|
|
|
m_maskColor.getColor());
|
|
|
|
}
|
|
|
|
|
|
|
|
void setOpaque(bool opaque) {
|
2015-07-27 22:43:48 +08:00
|
|
|
Preferences::instance().selection.opaque(opaque);
|
|
|
|
}
|
|
|
|
|
|
|
|
// When the preference is changed from outside the context bar
|
|
|
|
void onOpaqueChange() {
|
|
|
|
bool opaque = Preferences::instance().selection.opaque();
|
|
|
|
|
2015-08-05 06:38:52 +08:00
|
|
|
SkinTheme* theme = SkinTheme::instance();
|
|
|
|
SkinPartPtr part = (opaque ? theme->parts.selectionOpaque():
|
|
|
|
theme->parts.selectionMasked());
|
|
|
|
m_icon.getItem(0)->setIcon(part);
|
2015-07-24 09:42:14 +08:00
|
|
|
|
|
|
|
m_maskColor.setVisible(!opaque);
|
|
|
|
if (!opaque) {
|
|
|
|
Preferences::instance().selection.transparentColor(
|
|
|
|
m_maskColor.getColor());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_owner)
|
|
|
|
m_owner->layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
ButtonSet m_icon;
|
|
|
|
ColorButton m_maskColor;
|
|
|
|
ContextBar* m_owner;
|
2013-11-30 04:59:28 +08:00
|
|
|
};
|
|
|
|
|
2015-07-30 03:35:34 +08:00
|
|
|
class ContextBar::PivotField : public ButtonSet {
|
|
|
|
public:
|
|
|
|
PivotField()
|
|
|
|
: ButtonSet(1) {
|
2015-08-05 06:38:52 +08:00
|
|
|
addItem(SkinTheme::instance()->parts.pivotHidden());
|
2015-07-30 03:35:34 +08:00
|
|
|
|
|
|
|
ItemChange.connect(Bind<void>(&PivotField::onPopup, this));
|
|
|
|
|
|
|
|
Preferences::instance().selection.pivot.AfterChange.connect(
|
|
|
|
Bind<void>(&PivotField::onPivotChange, this));
|
|
|
|
|
|
|
|
onPivotChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void onPopup() {
|
|
|
|
SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
|
|
|
|
|
|
|
|
gfx::Rect bounds = getBounds();
|
|
|
|
|
|
|
|
Menu menu;
|
|
|
|
CheckBox hidden("Hidden pivot by default");
|
|
|
|
HBox box;
|
|
|
|
ButtonSet buttonset(3);
|
2015-08-05 06:38:52 +08:00
|
|
|
buttonset.addItem(theme->parts.pivotNorthwest());
|
|
|
|
buttonset.addItem(theme->parts.pivotNorth());
|
|
|
|
buttonset.addItem(theme->parts.pivotNortheast());
|
|
|
|
buttonset.addItem(theme->parts.pivotWest());
|
|
|
|
buttonset.addItem(theme->parts.pivotCenter());
|
|
|
|
buttonset.addItem(theme->parts.pivotEast());
|
|
|
|
buttonset.addItem(theme->parts.pivotSouthwest());
|
|
|
|
buttonset.addItem(theme->parts.pivotSouth());
|
|
|
|
buttonset.addItem(theme->parts.pivotSoutheast());
|
2015-07-30 03:35:34 +08:00
|
|
|
box.addChild(&buttonset);
|
|
|
|
|
|
|
|
menu.addChild(&hidden);
|
|
|
|
menu.addChild(new MenuSeparator);
|
|
|
|
menu.addChild(&box);
|
|
|
|
|
|
|
|
app::gen::PivotMode mode = Preferences::instance().selection.pivot();
|
|
|
|
if (mode == app::gen::PivotMode::HIDDEN)
|
|
|
|
hidden.setSelected(true);
|
|
|
|
else {
|
|
|
|
buttonset.setSelectedItem(int(mode)-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
hidden.Click.connect(
|
|
|
|
[&hidden](Event&){
|
|
|
|
Preferences::instance().selection.pivot(app::gen::PivotMode::HIDDEN);
|
|
|
|
hidden.closeWindow();
|
|
|
|
});
|
|
|
|
|
|
|
|
buttonset.ItemChange.connect(
|
|
|
|
[&buttonset](){
|
|
|
|
Preferences::instance().selection.pivot(app::gen::PivotMode(buttonset.selectedItem()+1));
|
|
|
|
buttonset.closeWindow();
|
|
|
|
});
|
|
|
|
|
|
|
|
menu.showPopup(gfx::Point(bounds.x, bounds.y+bounds.h));
|
|
|
|
}
|
|
|
|
|
|
|
|
void onPivotChange() {
|
2015-08-05 06:38:52 +08:00
|
|
|
SkinTheme* theme = SkinTheme::instance();
|
|
|
|
SkinPartPtr part;
|
|
|
|
switch (Preferences::instance().selection.pivot()) {
|
|
|
|
case app::gen::PivotMode::HIDDEN: part = theme->parts.pivotHidden(); break;
|
|
|
|
case app::gen::PivotMode::NORTHWEST: part = theme->parts.pivotNorthwest(); break;
|
|
|
|
case app::gen::PivotMode::NORTH: part = theme->parts.pivotNorth(); break;
|
|
|
|
case app::gen::PivotMode::NORTHEAST: part = theme->parts.pivotNortheast(); break;
|
|
|
|
case app::gen::PivotMode::WEST: part = theme->parts.pivotWest(); break;
|
|
|
|
case app::gen::PivotMode::CENTER: part = theme->parts.pivotCenter(); break;
|
|
|
|
case app::gen::PivotMode::EAST: part = theme->parts.pivotEast(); break;
|
|
|
|
case app::gen::PivotMode::SOUTHWEST: part = theme->parts.pivotSouthwest(); break;
|
|
|
|
case app::gen::PivotMode::SOUTH: part = theme->parts.pivotSouth(); break;
|
|
|
|
case app::gen::PivotMode::SOUTHEAST: part = theme->parts.pivotSoutheast(); break;
|
|
|
|
}
|
|
|
|
if (part)
|
|
|
|
getItem(0)->setIcon(part);
|
2015-07-30 03:35:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class ContextBar::RotAlgorithmField : public ComboBox {
|
2013-12-30 04:11:56 +08:00
|
|
|
public:
|
|
|
|
RotAlgorithmField() {
|
2014-06-14 12:35:04 +08:00
|
|
|
// 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;
|
2015-05-19 03:53:25 +08:00
|
|
|
addItem(new Item("Fast Rotation", tools::RotationAlgorithm::FAST));
|
|
|
|
addItem(new Item("RotSprite", tools::RotationAlgorithm::ROTSPRITE));
|
2014-06-14 12:35:04 +08:00
|
|
|
m_lockChange = false;
|
2013-12-30 04:11:56 +08:00
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
setSelectedItemIndex((int)Preferences::instance().selection.rotationAlgorithm());
|
2013-12-30 04:11:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-08-15 10:07:47 +08:00
|
|
|
void onChange() override {
|
2014-06-14 12:35:04 +08:00
|
|
|
if (m_lockChange)
|
|
|
|
return;
|
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
Preferences::instance().selection.rotationAlgorithm(
|
|
|
|
static_cast<Item*>(getSelectedItem())->algo());
|
2013-12-30 04:11:56 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
void onCloseListBox() override {
|
2014-03-09 07:31:55 +08:00
|
|
|
releaseFocus();
|
|
|
|
}
|
|
|
|
|
2013-12-30 04:11:56 +08:00
|
|
|
private:
|
|
|
|
class Item : public ListItem {
|
|
|
|
public:
|
2015-05-19 03:53:25 +08:00
|
|
|
Item(const std::string& text, tools::RotationAlgorithm algo) :
|
2013-12-30 04:11:56 +08:00
|
|
|
ListItem(text),
|
|
|
|
m_algo(algo) {
|
|
|
|
}
|
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
tools::RotationAlgorithm algo() const { return m_algo; }
|
2013-12-30 04:11:56 +08:00
|
|
|
|
|
|
|
private:
|
2015-05-19 03:53:25 +08:00
|
|
|
tools::RotationAlgorithm m_algo;
|
2013-12-30 04:11:56 +08:00
|
|
|
};
|
2014-06-14 12:35:04 +08:00
|
|
|
|
|
|
|
bool m_lockChange;
|
2013-12-30 04:11:56 +08:00
|
|
|
};
|
|
|
|
|
2014-07-17 20:54:04 +08:00
|
|
|
#if 0 // TODO for v1.1 to avoid changing the UI
|
|
|
|
|
2014-06-15 15:14:53 +08:00
|
|
|
class ContextBar::FreehandAlgorithmField : public Button
|
|
|
|
, public IButtonIcon
|
2014-01-26 03:26:49 +08:00
|
|
|
{
|
|
|
|
public:
|
2014-06-15 15:14:53 +08:00
|
|
|
FreehandAlgorithmField()
|
|
|
|
: Button("")
|
|
|
|
, m_popupWindow(NULL)
|
|
|
|
, m_tooltipManager(NULL) {
|
|
|
|
setup_mini_look(this);
|
|
|
|
setIconInterface(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
~FreehandAlgorithmField() {
|
|
|
|
closePopup();
|
|
|
|
setIconInterface(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setupTooltips(TooltipManager* tooltipManager) {
|
|
|
|
m_tooltipManager = tooltipManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setFreehandAlgorithm(FreehandAlgorithm algo) {
|
2015-08-05 06:38:52 +08:00
|
|
|
SkinTheme* theme = SkinTheme::instance();
|
|
|
|
SkinPartPtr part = theme->parts.freehandAlgoDefault();
|
2014-06-15 15:14:53 +08:00
|
|
|
m_freehandAlgo = algo;
|
|
|
|
switch (m_freehandAlgo) {
|
|
|
|
case kDefaultFreehandAlgorithm:
|
2015-08-05 06:38:52 +08:00
|
|
|
part = theme->parts.freehandAlgoDefault();
|
2014-06-15 15:14:53 +08:00
|
|
|
break;
|
|
|
|
case kPixelPerfectFreehandAlgorithm:
|
2015-08-05 06:38:52 +08:00
|
|
|
part = theme->parts.freehandAlgoPixelPerfect();
|
2014-06-15 15:14:53 +08:00
|
|
|
break;
|
|
|
|
case kDotsFreehandAlgorithm:
|
2015-08-05 06:38:52 +08:00
|
|
|
part = theme->parts.freehandAlgoDots();
|
2014-06-15 15:14:53 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-08-05 06:38:52 +08:00
|
|
|
m_bitmap = part;
|
2014-06-15 15:14:53 +08:00
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
// IButtonIcon implementation
|
2014-08-15 10:07:47 +08:00
|
|
|
void destroy() override {
|
2014-06-15 15:14:53 +08:00
|
|
|
// Do nothing, BrushTypeField is added as a widget in the
|
|
|
|
// ContextBar, so it will be destroyed together with the
|
|
|
|
// ContextBar.
|
|
|
|
}
|
|
|
|
|
2015-08-05 06:38:52 +08:00
|
|
|
gfx::Size getSize() override {
|
|
|
|
return m_bitmap->getSize();
|
2014-06-15 15:14:53 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
she::Surface* getNormalIcon() override {
|
2015-08-05 06:38:52 +08:00
|
|
|
return m_bitmap->getBitmap(0);
|
2014-06-15 15:14:53 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
she::Surface* getSelectedIcon() override {
|
2015-08-05 06:38:52 +08:00
|
|
|
return m_bitmap->getBitmap(0);
|
2014-06-15 15:14:53 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
she::Surface* getDisabledIcon() override {
|
2015-08-05 06:38:52 +08:00
|
|
|
return m_bitmap->getBitmap(0);
|
2014-06-15 15:14:53 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
int getIconAlign() override {
|
2015-06-24 01:00:00 +08:00
|
|
|
return CENTER | MIDDLE;
|
2014-01-26 03:26:49 +08:00
|
|
|
}
|
|
|
|
|
2014-06-15 15:14:53 +08:00
|
|
|
protected:
|
2014-08-15 10:07:47 +08:00
|
|
|
void onClick(Event& ev) override {
|
2014-06-15 15:14:53 +08:00
|
|
|
Button::onClick(ev);
|
|
|
|
|
|
|
|
if (!m_popupWindow || !m_popupWindow->isVisible())
|
|
|
|
openPopup();
|
|
|
|
else
|
|
|
|
closePopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void onPreferredSize(PreferredSizeEvent& ev) {
|
2014-11-26 09:33:45 +08:00
|
|
|
ev.setPreferredSize(Size(16, 18)*guiscale());
|
2014-06-15 15:14:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void openPopup() {
|
2014-09-08 13:27:41 +08:00
|
|
|
SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
|
|
|
|
|
2014-11-26 09:33:45 +08:00
|
|
|
Border border = Border(2, 2, 2, 3)*guiscale();
|
2014-06-15 15:14:53 +08:00
|
|
|
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-09-08 13:27:41 +08:00
|
|
|
m_freehandAlgoButton = new ButtonSet(3);
|
2015-08-05 06:38:52 +08:00
|
|
|
m_freehandAlgoButton->addItem(theme->parts.freehandAlgoDefault());
|
|
|
|
m_freehandAlgoButton->addItem(theme->parts.freehandAlgoPixelPerfect());
|
|
|
|
m_freehandAlgoButton->addItem(theme->parts.freehandAlgoDots());
|
2014-09-08 13:27:41 +08:00
|
|
|
m_freehandAlgoButton->setSelectedItem((int)m_freehandAlgo);
|
2014-06-15 15:14:53 +08:00
|
|
|
m_freehandAlgoButton->ItemChange.connect(&FreehandAlgorithmField::onFreehandAlgoChange, this);
|
|
|
|
m_freehandAlgoButton->setTransparent(true);
|
2014-06-29 03:10:39 +08:00
|
|
|
m_freehandAlgoButton->setBgColor(gfx::ColorNone);
|
2014-06-15 15:14:53 +08:00
|
|
|
|
2015-06-24 01:00:00 +08:00
|
|
|
m_tooltipManager->addTooltipFor(at(0), "Normal trace", TOP);
|
|
|
|
m_tooltipManager->addTooltipFor(at(1), "Pixel-perfect trace", TOP);
|
|
|
|
m_tooltipManager->addTooltipFor(at(2), "Dots", TOP);
|
2014-06-15 15:14:53 +08:00
|
|
|
|
|
|
|
m_popupWindow->addChild(m_freehandAlgoButton);
|
|
|
|
m_popupWindow->openWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
void closePopup() {
|
|
|
|
if (m_popupWindow) {
|
|
|
|
m_popupWindow->closeWindow(NULL);
|
|
|
|
delete m_popupWindow;
|
|
|
|
m_popupWindow = NULL;
|
|
|
|
m_freehandAlgoButton = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void onFreehandAlgoChange() {
|
|
|
|
setFreehandAlgorithm(
|
|
|
|
(FreehandAlgorithm)m_freehandAlgoButton->getSelectedItem());
|
2014-01-26 03:26:49 +08:00
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
Tool* tool = App::instance()->activeTool();
|
|
|
|
Preferences::instance().tool(tool).freehandAlgorithm(m_freehandAlgo);
|
2014-01-26 03:26:49 +08:00
|
|
|
}
|
2014-06-15 15:14:53 +08:00
|
|
|
|
2015-08-05 06:38:52 +08:00
|
|
|
SkinPartPtr m_bitmap;
|
2014-06-15 15:14:53 +08:00
|
|
|
FreehandAlgorithm m_freehandAlgo;
|
|
|
|
PopupWindow* m_popupWindow;
|
|
|
|
ButtonSet* m_freehandAlgoButton;
|
|
|
|
TooltipManager* m_tooltipManager;
|
2014-01-26 03:26:49 +08:00
|
|
|
};
|
|
|
|
|
2014-07-17 20:54:04 +08:00
|
|
|
#else
|
|
|
|
|
|
|
|
class ContextBar::FreehandAlgorithmField : public CheckBox
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FreehandAlgorithmField() : CheckBox("Pixel-perfect") {
|
|
|
|
setup_mini_font(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setupTooltips(TooltipManager* tooltipManager) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
void setFreehandAlgorithm(tools::FreehandAlgorithm algo) {
|
2014-07-17 20:54:04 +08:00
|
|
|
switch (algo) {
|
2015-05-19 03:53:25 +08:00
|
|
|
case tools::FreehandAlgorithm::DEFAULT:
|
2014-07-17 20:54:04 +08:00
|
|
|
setSelected(false);
|
|
|
|
break;
|
2015-05-19 03:53:25 +08:00
|
|
|
case tools::FreehandAlgorithm::PIXEL_PERFECT:
|
2014-07-17 20:54:04 +08:00
|
|
|
setSelected(true);
|
|
|
|
break;
|
2015-05-19 03:53:25 +08:00
|
|
|
case tools::FreehandAlgorithm::DOTS:
|
2014-07-17 20:54:04 +08:00
|
|
|
// Not available
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-08-15 10:07:47 +08:00
|
|
|
void onClick(Event& ev) override {
|
2014-07-17 20:54:04 +08:00
|
|
|
CheckBox::onClick(ev);
|
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
Tool* tool = App::instance()->activeTool();
|
|
|
|
Preferences::instance().tool(tool).freehandAlgorithm(
|
|
|
|
isSelected() ?
|
|
|
|
tools::FreehandAlgorithm::PIXEL_PERFECT:
|
|
|
|
tools::FreehandAlgorithm::DEFAULT);
|
2014-07-17 20:54:04 +08:00
|
|
|
|
|
|
|
releaseFocus();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2014-01-26 04:58:29 +08:00
|
|
|
class ContextBar::SelectionModeField : public ButtonSet
|
|
|
|
{
|
|
|
|
public:
|
2014-09-08 13:27:41 +08:00
|
|
|
SelectionModeField() : ButtonSet(3) {
|
|
|
|
SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
|
|
|
|
|
2015-08-05 06:38:52 +08:00
|
|
|
addItem(theme->parts.selectionReplace());
|
|
|
|
addItem(theme->parts.selectionAdd());
|
|
|
|
addItem(theme->parts.selectionSubtract());
|
2014-09-08 13:27:41 +08:00
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
setSelectedItem((int)Preferences::instance().selection.mode());
|
2014-01-26 04:58:29 +08:00
|
|
|
}
|
|
|
|
|
2014-06-15 15:14:53 +08:00
|
|
|
void setupTooltips(TooltipManager* tooltipManager) {
|
2015-06-24 01:00:00 +08:00
|
|
|
tooltipManager->addTooltipFor(at(0), "Replace selection", BOTTOM);
|
|
|
|
tooltipManager->addTooltipFor(at(1), "Add to selection\n(Shift)", BOTTOM);
|
|
|
|
tooltipManager->addTooltipFor(at(2), "Subtract from selection\n(Shift+Alt)", BOTTOM);
|
2014-08-25 06:19:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void setSelectionMode(SelectionMode mode) {
|
|
|
|
setSelectedItem((int)mode);
|
|
|
|
invalidate();
|
2014-01-26 04:58:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-08-15 10:07:47 +08:00
|
|
|
void onItemChange() override {
|
2014-01-26 04:58:29 +08:00
|
|
|
ButtonSet::onItemChange();
|
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
Preferences::instance().selection.mode(
|
|
|
|
(tools::SelectionMode)selectedItem());
|
2014-01-26 04:58:29 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-05-26 11:20:16 +08:00
|
|
|
class ContextBar::DropPixelsField : public ButtonSet
|
|
|
|
{
|
|
|
|
public:
|
2014-09-08 13:27:41 +08:00
|
|
|
DropPixelsField() : ButtonSet(2) {
|
|
|
|
SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
|
|
|
|
|
2015-08-05 06:38:52 +08:00
|
|
|
addItem(theme->parts.dropPixelsOk());
|
|
|
|
addItem(theme->parts.dropPixelsCancel());
|
2014-09-08 13:27:41 +08:00
|
|
|
setOfferCapture(false);
|
2014-05-26 11:20:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void setupTooltips(TooltipManager* tooltipManager) {
|
2015-06-24 01:00:00 +08:00
|
|
|
tooltipManager->addTooltipFor(at(0), "Drop pixels here", BOTTOM);
|
|
|
|
tooltipManager->addTooltipFor(at(1), "Cancel drag and drop", BOTTOM);
|
2014-05-26 11:20:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Signal1<void, ContextBarObserver::DropAction> DropPixels;
|
|
|
|
|
|
|
|
protected:
|
2014-08-15 10:07:47 +08:00
|
|
|
void onItemChange() override {
|
2014-05-26 11:20:16 +08:00
|
|
|
ButtonSet::onItemChange();
|
|
|
|
|
2014-09-08 13:27:41 +08:00
|
|
|
switch (selectedItem()) {
|
2014-05-26 11:20:16 +08:00
|
|
|
case 0: DropPixels(ContextBarObserver::DropPixels); break;
|
|
|
|
case 1: DropPixels(ContextBarObserver::CancelDrag); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-03 05:13:47 +08:00
|
|
|
class ContextBar::EyedropperField : public HBox
|
2014-01-29 10:56:44 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-07-03 05:13:47 +08:00
|
|
|
EyedropperField() {
|
|
|
|
m_channel.addItem("Color+Alpha");
|
|
|
|
m_channel.addItem("Color");
|
|
|
|
m_channel.addItem("Alpha");
|
|
|
|
m_channel.addItem("RGB+Alpha");
|
|
|
|
m_channel.addItem("RGB");
|
|
|
|
m_channel.addItem("HSB+Alpha");
|
|
|
|
m_channel.addItem("HSB");
|
|
|
|
m_channel.addItem("Gray+Alpha");
|
|
|
|
m_channel.addItem("Gray");
|
|
|
|
m_channel.addItem("Best fit Index");
|
|
|
|
|
|
|
|
m_sample.addItem("All Layers");
|
|
|
|
m_sample.addItem("Current Layer");
|
|
|
|
|
|
|
|
addChild(new Label("Pick:"));
|
|
|
|
addChild(&m_channel);
|
|
|
|
addChild(new Label("Sample:"));
|
|
|
|
addChild(&m_sample);
|
|
|
|
|
|
|
|
m_channel.Change.connect(Bind<void>(&EyedropperField::onChannelChange, this));
|
|
|
|
m_sample.Change.connect(Bind<void>(&EyedropperField::onSampleChange, this));
|
2014-01-29 10:56:44 +08:00
|
|
|
}
|
|
|
|
|
2015-07-03 05:13:47 +08:00
|
|
|
void updateFromPreferences(app::Preferences::Eyedropper& prefEyedropper) {
|
|
|
|
m_channel.setSelectedItemIndex((int)prefEyedropper.channel());
|
|
|
|
m_sample.setSelectedItemIndex((int)prefEyedropper.sample());
|
|
|
|
}
|
2014-01-29 10:56:44 +08:00
|
|
|
|
2015-07-03 05:13:47 +08:00
|
|
|
private:
|
|
|
|
void onChannelChange() {
|
|
|
|
Preferences::instance().eyedropper.channel(
|
|
|
|
(app::gen::EyedropperChannel)m_channel.getSelectedItemIndex());
|
|
|
|
}
|
2014-03-09 07:31:55 +08:00
|
|
|
|
2015-07-03 05:13:47 +08:00
|
|
|
void onSampleChange() {
|
|
|
|
Preferences::instance().eyedropper.sample(
|
|
|
|
(app::gen::EyedropperSample)m_sample.getSelectedItemIndex());
|
2014-01-29 10:56:44 +08:00
|
|
|
}
|
2015-07-03 05:13:47 +08:00
|
|
|
|
|
|
|
ComboBox m_channel;
|
|
|
|
ComboBox m_sample;
|
2014-01-29 10:56:44 +08:00
|
|
|
};
|
|
|
|
|
2014-11-17 05:33:31 +08:00
|
|
|
class ContextBar::AutoSelectLayerField : public CheckBox
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AutoSelectLayerField() : CheckBox("Auto Select Layer") {
|
|
|
|
setup_mini_font(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void onClick(Event& ev) override {
|
|
|
|
CheckBox::onClick(ev);
|
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
Preferences::instance().editor.autoSelectLayer(isSelected());
|
2014-11-17 05:33:31 +08:00
|
|
|
|
|
|
|
releaseFocus();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-03-31 00:43:00 +08:00
|
|
|
ContextBar::ContextBar()
|
2015-06-24 01:00:00 +08:00
|
|
|
: Box(HORIZONTAL)
|
2013-03-31 00:43:00 +08:00
|
|
|
{
|
2015-06-24 06:20:49 +08:00
|
|
|
gfx::Border border = this->border();
|
|
|
|
border.bottom(2*guiscale());
|
|
|
|
setBorder(border);
|
2013-03-31 00:43:00 +08:00
|
|
|
|
|
|
|
SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
|
2015-02-16 02:29:16 +08:00
|
|
|
setBgColor(theme->colors.workspace());
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2014-01-26 04:58:29 +08:00
|
|
|
addChild(m_selectionOptionsBox = new HBox());
|
2014-05-26 11:20:16 +08:00
|
|
|
m_selectionOptionsBox->addChild(m_dropPixels = new DropPixelsField());
|
2014-01-26 04:58:29 +08:00
|
|
|
m_selectionOptionsBox->addChild(m_selectionMode = new SelectionModeField);
|
2015-07-24 09:42:14 +08:00
|
|
|
m_selectionOptionsBox->addChild(m_transparentColor = new TransparentColorField(this));
|
2015-07-30 03:35:34 +08:00
|
|
|
m_selectionOptionsBox->addChild(m_pivot = new PivotField);
|
2014-01-26 04:58:29 +08:00
|
|
|
m_selectionOptionsBox->addChild(m_rotAlgo = new RotAlgorithmField());
|
|
|
|
|
2015-04-29 05:21:33 +08:00
|
|
|
addChild(m_brushType = new BrushTypeField(this));
|
2013-03-31 00:43:00 +08:00
|
|
|
addChild(m_brushSize = new BrushSizeField());
|
|
|
|
addChild(m_brushAngle = new BrushAngleField(m_brushType));
|
2015-04-27 11:08:04 +08:00
|
|
|
addChild(m_brushPatternField = new BrushPatternField());
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2013-03-31 08:12:09 +08:00
|
|
|
addChild(m_toleranceLabel = new Label("Tolerance:"));
|
2013-03-31 00:43:00 +08:00
|
|
|
addChild(m_tolerance = new ToleranceField());
|
2014-08-07 11:07:24 +08:00
|
|
|
addChild(m_contiguous = new ContiguousField());
|
2015-06-18 00:22:46 +08:00
|
|
|
addChild(m_stopAtGrid = new StopAtGridField());
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2015-07-03 00:16:06 +08:00
|
|
|
addChild(m_inkType = new InkTypeField(this));
|
2013-03-31 08:12:09 +08:00
|
|
|
|
2015-07-03 00:16:06 +08:00
|
|
|
addChild(m_inkOpacityLabel = new Label("Opacity:"));
|
2013-03-31 00:43:00 +08:00
|
|
|
addChild(m_inkOpacity = new InkOpacityField());
|
2014-01-29 10:56:44 +08:00
|
|
|
|
2015-07-03 05:13:47 +08:00
|
|
|
addChild(m_eyedropperField = new EyedropperField());
|
2014-01-29 10:56:44 +08:00
|
|
|
|
2014-11-17 05:33:31 +08:00
|
|
|
addChild(m_autoSelectLayer = new AutoSelectLayerField());
|
|
|
|
|
2013-03-31 00:43:00 +08:00
|
|
|
// addChild(new InkChannelTargetField());
|
|
|
|
// addChild(new InkShadeField());
|
|
|
|
// addChild(new InkSelectionField());
|
|
|
|
|
2013-03-31 08:31:34 +08:00
|
|
|
addChild(m_sprayBox = new HBox());
|
2015-05-06 06:14:33 +08:00
|
|
|
m_sprayBox->addChild(m_sprayLabel = new Label("Spray:"));
|
2013-03-31 08:31:34 +08:00
|
|
|
m_sprayBox->addChild(m_sprayWidth = new SprayWidthField());
|
|
|
|
m_sprayBox->addChild(m_spraySpeed = new SpraySpeedField());
|
|
|
|
|
2015-05-08 00:11:44 +08:00
|
|
|
addChild(m_selectBoxHelp = new Label(""));
|
|
|
|
|
2015-05-06 06:14:33 +08:00
|
|
|
setup_mini_font(m_sprayLabel);
|
|
|
|
|
2014-01-26 03:37:38 +08:00
|
|
|
addChild(m_freehandBox = new HBox());
|
2014-07-17 20:54:04 +08:00
|
|
|
#if 0 // TODO for v1.1
|
2015-05-06 06:14:33 +08:00
|
|
|
m_freehandBox->addChild(m_freehandLabel = new Label("Freehand:"));
|
|
|
|
setup_mini_font(m_freehandLabel);
|
2014-07-17 20:54:04 +08:00
|
|
|
#endif
|
2014-01-26 03:37:38 +08:00
|
|
|
m_freehandBox->addChild(m_freehandAlgo = new FreehandAlgorithmField());
|
|
|
|
|
2014-01-26 19:40:16 +08:00
|
|
|
setup_mini_font(m_toleranceLabel);
|
2015-07-03 00:16:06 +08:00
|
|
|
setup_mini_font(m_inkOpacityLabel);
|
2014-01-26 19:40:16 +08:00
|
|
|
|
2013-03-31 08:31:34 +08:00
|
|
|
TooltipManager* tooltipManager = new TooltipManager();
|
|
|
|
addChild(tooltipManager);
|
|
|
|
|
2015-06-24 01:00:00 +08:00
|
|
|
tooltipManager->addTooltipFor(m_brushType, "Brush Type", BOTTOM);
|
|
|
|
tooltipManager->addTooltipFor(m_brushSize, "Brush Size (in pixels)", BOTTOM);
|
|
|
|
tooltipManager->addTooltipFor(m_brushAngle, "Brush Angle (in degrees)", BOTTOM);
|
2015-07-03 00:16:06 +08:00
|
|
|
tooltipManager->addTooltipFor(m_inkType, "Ink", BOTTOM);
|
|
|
|
tooltipManager->addTooltipFor(m_inkOpacity, "Opacity (paint intensity)", BOTTOM);
|
2015-06-24 01:00:00 +08:00
|
|
|
tooltipManager->addTooltipFor(m_sprayWidth, "Spray Width", BOTTOM);
|
|
|
|
tooltipManager->addTooltipFor(m_spraySpeed, "Spray Speed", BOTTOM);
|
2015-07-30 03:35:34 +08:00
|
|
|
tooltipManager->addTooltipFor(m_pivot, "Rotation Pivot", BOTTOM);
|
2015-06-24 01:00:00 +08:00
|
|
|
tooltipManager->addTooltipFor(m_transparentColor, "Transparent Color", BOTTOM);
|
|
|
|
tooltipManager->addTooltipFor(m_rotAlgo, "Rotation Algorithm", BOTTOM);
|
|
|
|
tooltipManager->addTooltipFor(m_freehandAlgo, "Freehand trace algorithm", BOTTOM);
|
2015-04-29 23:32:44 +08:00
|
|
|
|
|
|
|
m_brushType->setupTooltips(tooltipManager);
|
2014-01-26 04:58:29 +08:00
|
|
|
m_selectionMode->setupTooltips(tooltipManager);
|
2014-05-26 11:20:16 +08:00
|
|
|
m_dropPixels->setupTooltips(tooltipManager);
|
2014-06-15 15:14:53 +08:00
|
|
|
m_freehandAlgo->setupTooltips(tooltipManager);
|
2013-03-31 08:31:34 +08:00
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
Preferences::instance().toolBox.activeTool.AfterChange.connect(
|
|
|
|
Bind<void>(&ContextBar::onCurrentToolChange, this));
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
m_dropPixels->DropPixels.connect(&ContextBar::onDropPixels, this);
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
setActiveBrush(createBrushFromPreferences());
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
|
2014-02-03 08:07:12 +08:00
|
|
|
void ContextBar::onPreferredSize(PreferredSizeEvent& ev)
|
|
|
|
{
|
2014-11-26 09:33:45 +08:00
|
|
|
ev.setPreferredSize(gfx::Size(0, 18*guiscale())); // TODO calculate height
|
2014-02-03 08:07:12 +08:00
|
|
|
}
|
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
void ContextBar::onToolSetOpacity(const int& newOpacity)
|
2014-01-29 10:56:44 +08:00
|
|
|
{
|
2015-05-19 03:53:25 +08:00
|
|
|
if (g_updatingFromCode)
|
|
|
|
return;
|
|
|
|
|
2014-01-29 10:56:44 +08:00
|
|
|
m_inkOpacity->setTextf("%d", newOpacity);
|
|
|
|
}
|
|
|
|
|
2014-06-15 02:09:43 +08:00
|
|
|
void ContextBar::onBrushSizeChange()
|
2013-03-31 00:43:00 +08:00
|
|
|
{
|
2015-04-29 05:21:33 +08:00
|
|
|
if (m_activeBrush->type() != kImageBrushType)
|
|
|
|
discardActiveBrush();
|
2015-07-04 00:41:50 +08:00
|
|
|
|
|
|
|
updateForCurrentTool();
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
|
2014-06-15 02:09:43 +08:00
|
|
|
void ContextBar::onBrushAngleChange()
|
2013-05-23 10:58:32 +08:00
|
|
|
{
|
2015-04-29 05:21:33 +08:00
|
|
|
if (m_activeBrush->type() != kImageBrushType)
|
|
|
|
discardActiveBrush();
|
2013-05-23 10:58:32 +08:00
|
|
|
}
|
|
|
|
|
2013-03-31 00:43:00 +08:00
|
|
|
void ContextBar::onCurrentToolChange()
|
|
|
|
{
|
2015-04-29 05:21:33 +08:00
|
|
|
if (m_activeBrush->type() != kImageBrushType)
|
2015-05-19 03:53:25 +08:00
|
|
|
setActiveBrush(ContextBar::createBrushFromPreferences());
|
2015-04-29 05:21:33 +08:00
|
|
|
else {
|
2015-05-07 23:32:08 +08:00
|
|
|
updateForCurrentTool();
|
2015-04-29 05:21:33 +08:00
|
|
|
}
|
2014-01-29 10:56:44 +08:00
|
|
|
}
|
|
|
|
|
2014-05-26 11:20:16 +08:00
|
|
|
void ContextBar::onDropPixels(ContextBarObserver::DropAction action)
|
|
|
|
{
|
|
|
|
notifyObservers(&ContextBarObserver::onDropPixels, action);
|
|
|
|
}
|
|
|
|
|
2015-05-07 23:32:08 +08:00
|
|
|
void ContextBar::updateForCurrentTool()
|
|
|
|
{
|
2015-05-19 03:53:25 +08:00
|
|
|
updateForTool(App::instance()->activeTool());
|
2015-05-07 23:32:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContextBar::updateForTool(tools::Tool* tool)
|
2014-01-29 10:56:44 +08:00
|
|
|
{
|
2015-05-19 03:53:25 +08:00
|
|
|
base::ScopedValue<bool> lockFlag(g_updatingFromCode, true, g_updatingFromCode);
|
2014-10-25 23:10:52 +08:00
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
ToolPreferences* toolPref = nullptr;
|
|
|
|
ToolPreferences::Brush* brushPref = nullptr;
|
|
|
|
Preferences& preferences = Preferences::instance();
|
2015-05-08 00:11:44 +08:00
|
|
|
|
|
|
|
if (tool) {
|
2015-05-19 03:53:25 +08:00
|
|
|
toolPref = &preferences.tool(tool);
|
|
|
|
brushPref = &toolPref->brush;
|
2015-05-08 00:11:44 +08:00
|
|
|
}
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
if (toolPref) {
|
|
|
|
m_sizeConn = brushPref->size.AfterChange.connect(Bind<void>(&ContextBar::onBrushSizeChange, this));
|
|
|
|
m_angleConn = brushPref->angle.AfterChange.connect(Bind<void>(&ContextBar::onBrushAngleChange, this));
|
|
|
|
m_opacityConn = toolPref->opacity.AfterChange.connect(&ContextBar::onToolSetOpacity, this);
|
|
|
|
}
|
2015-05-08 00:11:44 +08:00
|
|
|
|
|
|
|
if (tool)
|
|
|
|
m_brushType->updateBrush(tool);
|
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
if (brushPref) {
|
|
|
|
m_brushSize->setTextf("%d", brushPref->size());
|
|
|
|
m_brushAngle->setTextf("%d", brushPref->angle());
|
2015-05-08 00:11:44 +08:00
|
|
|
}
|
2014-01-29 10:56:44 +08:00
|
|
|
|
2015-04-27 11:08:04 +08:00
|
|
|
m_brushPatternField->setBrushPattern(
|
2015-05-13 22:46:49 +08:00
|
|
|
preferences.brush.pattern());
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2015-07-03 00:16:06 +08:00
|
|
|
// Tool ink
|
|
|
|
bool isPaint = tool &&
|
|
|
|
(tool->getInk(0)->isPaint() ||
|
|
|
|
tool->getInk(1)->isPaint());
|
|
|
|
bool isEffect = tool &&
|
|
|
|
(tool->getInk(0)->isEffect() ||
|
|
|
|
tool->getInk(1)->isEffect());
|
|
|
|
|
|
|
|
// True if the current tool support opacity slider
|
|
|
|
bool supportOpacity = (isPaint || isEffect);
|
|
|
|
|
|
|
|
// True if it makes sense to change the ink property for the current
|
|
|
|
// tool.
|
|
|
|
bool hasInk = tool &&
|
|
|
|
((tool->getInk(0)->isPaint() && !tool->getInk(0)->isEffect()) ||
|
|
|
|
(tool->getInk(1)->isPaint() && !tool->getInk(1)->isEffect()));
|
|
|
|
|
|
|
|
bool hasInkWithOpacity = false;
|
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
if (toolPref) {
|
|
|
|
m_tolerance->setTextf("%d", toolPref->tolerance());
|
|
|
|
m_contiguous->setSelected(toolPref->contiguous());
|
2015-06-18 00:22:46 +08:00
|
|
|
m_stopAtGrid->setSelected(
|
|
|
|
toolPref->floodfill.stopAtGrid() == app::gen::StopAtGrid::IF_VISIBLE ? true: false);
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
m_inkType->setInkType(toolPref->ink());
|
|
|
|
m_inkOpacity->setTextf("%d", toolPref->opacity());
|
2013-03-31 08:12:09 +08:00
|
|
|
|
2015-07-03 00:16:06 +08:00
|
|
|
hasInkWithOpacity =
|
2015-07-27 22:24:00 +08:00
|
|
|
((isPaint && toolPref->ink() != tools::InkType::COPY_COLOR) ||
|
2015-07-03 00:16:06 +08:00
|
|
|
(isEffect));
|
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
m_freehandAlgo->setFreehandAlgorithm(toolPref->freehandAlgorithm());
|
2014-01-26 03:26:49 +08:00
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
m_sprayWidth->setValue(toolPref->spray.width());
|
|
|
|
m_spraySpeed->setValue(toolPref->spray.speed());
|
2015-05-08 00:11:44 +08:00
|
|
|
}
|
|
|
|
|
2015-07-03 05:13:47 +08:00
|
|
|
m_eyedropperField->updateFromPreferences(preferences.eyedropper);
|
2015-05-19 03:53:25 +08:00
|
|
|
m_autoSelectLayer->setSelected(preferences.editor.autoSelectLayer());
|
2013-03-31 08:31:34 +08:00
|
|
|
|
2015-04-27 11:08:04 +08:00
|
|
|
// True if we have an image as brush
|
2015-04-29 05:21:33 +08:00
|
|
|
bool hasImageBrush = (activeBrush()->type() == kImageBrushType);
|
2015-04-27 11:08:04 +08:00
|
|
|
|
2015-07-04 00:41:50 +08:00
|
|
|
// True if the brush type supports angle.
|
|
|
|
bool hasBrushWithAngle =
|
|
|
|
(activeBrush()->size() > 1) &&
|
|
|
|
(activeBrush()->type() == kSquareBrushType ||
|
|
|
|
activeBrush()->type() == kLineBrushType);
|
|
|
|
|
2014-01-29 10:56:44 +08:00
|
|
|
// True if the current tool is eyedropper.
|
2015-05-08 00:11:44 +08:00
|
|
|
bool isEyedropper = tool &&
|
2014-01-29 10:56:44 +08:00
|
|
|
(tool->getInk(0)->isEyedropper() ||
|
|
|
|
tool->getInk(1)->isEyedropper());
|
2013-03-31 08:12:09 +08:00
|
|
|
|
2014-11-17 05:33:31 +08:00
|
|
|
// True if the current tool is move tool.
|
2015-05-08 00:11:44 +08:00
|
|
|
bool isMove = tool &&
|
2014-11-17 05:33:31 +08:00
|
|
|
(tool->getInk(0)->isCelMovement() ||
|
|
|
|
tool->getInk(1)->isCelMovement());
|
|
|
|
|
2015-06-18 00:22:46 +08:00
|
|
|
// True if the current tool is floodfill
|
|
|
|
bool isFloodfill = tool &&
|
|
|
|
(tool->getPointShape(0)->isFloodFill() ||
|
|
|
|
tool->getPointShape(1)->isFloodFill());
|
|
|
|
|
2013-03-31 08:12:09 +08:00
|
|
|
// True if the current tool needs tolerance options
|
2015-05-08 00:11:44 +08:00
|
|
|
bool hasTolerance = tool &&
|
|
|
|
(tool->getPointShape(0)->isFloodFill() ||
|
|
|
|
tool->getPointShape(1)->isFloodFill());
|
2013-03-31 08:12:09 +08:00
|
|
|
|
|
|
|
// True if the current tool needs spray options
|
2015-05-08 00:11:44 +08:00
|
|
|
bool hasSprayOptions = tool &&
|
|
|
|
(tool->getPointShape(0)->isSpray() ||
|
|
|
|
tool->getPointShape(1)->isSpray());
|
2013-03-31 08:12:09 +08:00
|
|
|
|
2015-05-08 00:11:44 +08:00
|
|
|
bool hasSelectOptions = tool &&
|
|
|
|
(tool->getInk(0)->isSelection() ||
|
|
|
|
tool->getInk(1)->isSelection());
|
2013-11-30 04:59:28 +08:00
|
|
|
|
2015-05-08 00:11:44 +08:00
|
|
|
bool isFreehand = tool &&
|
2014-01-29 10:56:44 +08:00
|
|
|
(tool->getController(0)->isFreehand() ||
|
|
|
|
tool->getController(1)->isFreehand());
|
2014-01-26 03:26:49 +08:00
|
|
|
|
2015-07-23 21:43:16 +08:00
|
|
|
bool showOpacity =
|
|
|
|
(supportOpacity) &&
|
|
|
|
((isPaint && (hasInkWithOpacity || hasImageBrush)) ||
|
|
|
|
(isEffect));
|
|
|
|
|
2013-03-31 08:12:09 +08:00
|
|
|
// Show/Hide fields
|
2015-07-03 00:16:06 +08:00
|
|
|
m_brushType->setVisible(supportOpacity && (!isFloodfill || (isFloodfill && hasImageBrush)));
|
|
|
|
m_brushSize->setVisible(supportOpacity && !isFloodfill && !hasImageBrush);
|
2015-07-04 00:41:50 +08:00
|
|
|
m_brushAngle->setVisible(supportOpacity && !isFloodfill && !hasImageBrush && hasBrushWithAngle);
|
2015-07-03 00:16:06 +08:00
|
|
|
m_brushPatternField->setVisible(supportOpacity && hasImageBrush);
|
2015-04-27 11:08:04 +08:00
|
|
|
m_inkType->setVisible(hasInk && !hasImageBrush);
|
2015-07-23 21:43:16 +08:00
|
|
|
m_inkOpacityLabel->setVisible(showOpacity);
|
|
|
|
m_inkOpacity->setVisible(showOpacity);
|
2015-07-03 05:13:47 +08:00
|
|
|
m_eyedropperField->setVisible(isEyedropper);
|
2014-11-17 05:33:31 +08:00
|
|
|
m_autoSelectLayer->setVisible(isMove);
|
2015-07-03 00:16:06 +08:00
|
|
|
m_freehandBox->setVisible(isFreehand && supportOpacity);
|
2013-03-31 08:12:09 +08:00
|
|
|
m_toleranceLabel->setVisible(hasTolerance);
|
|
|
|
m_tolerance->setVisible(hasTolerance);
|
2014-08-07 11:07:24 +08:00
|
|
|
m_contiguous->setVisible(hasTolerance);
|
2015-06-18 00:22:46 +08:00
|
|
|
m_stopAtGrid->setVisible(hasTolerance);
|
2013-03-31 08:31:34 +08:00
|
|
|
m_sprayBox->setVisible(hasSprayOptions);
|
2013-11-30 04:59:28 +08:00
|
|
|
m_selectionOptionsBox->setVisible(hasSelectOptions);
|
2014-05-26 11:20:16 +08:00
|
|
|
m_selectionMode->setVisible(true);
|
2015-07-30 03:35:34 +08:00
|
|
|
m_pivot->setVisible(true);
|
2014-05-26 11:20:16 +08:00
|
|
|
m_dropPixels->setVisible(false);
|
2015-05-08 00:11:44 +08:00
|
|
|
m_selectBoxHelp->setVisible(false);
|
2013-03-31 08:12:09 +08:00
|
|
|
|
|
|
|
layout();
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
2014-05-26 11:20:16 +08:00
|
|
|
void ContextBar::updateForMovingPixels()
|
|
|
|
{
|
|
|
|
tools::Tool* tool = App::instance()->getToolBox()->getToolById(
|
|
|
|
tools::WellKnownTools::RectangularMarquee);
|
|
|
|
if (tool)
|
2015-05-07 23:32:08 +08:00
|
|
|
updateForTool(tool);
|
2014-05-26 11:20:16 +08:00
|
|
|
|
|
|
|
m_dropPixels->deselectItems();
|
|
|
|
m_dropPixels->setVisible(true);
|
|
|
|
m_selectionMode->setVisible(false);
|
|
|
|
layout();
|
|
|
|
}
|
|
|
|
|
2015-05-08 00:11:44 +08:00
|
|
|
void ContextBar::updateForSelectingBox(const std::string& text)
|
|
|
|
{
|
|
|
|
if (m_selectBoxHelp->isVisible() && m_selectBoxHelp->getText() == text)
|
|
|
|
return;
|
|
|
|
|
|
|
|
updateForTool(nullptr);
|
|
|
|
m_selectBoxHelp->setText(text);
|
|
|
|
m_selectBoxHelp->setVisible(true);
|
|
|
|
layout();
|
|
|
|
}
|
|
|
|
|
2014-11-17 05:33:31 +08:00
|
|
|
void ContextBar::updateSelectionMode(SelectionMode mode)
|
2014-08-25 06:19:38 +08:00
|
|
|
{
|
|
|
|
if (!m_selectionMode->isVisible())
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_selectionMode->setSelectionMode(mode);
|
|
|
|
}
|
|
|
|
|
2014-11-17 05:33:31 +08:00
|
|
|
void ContextBar::updateAutoSelectLayer(bool state)
|
|
|
|
{
|
|
|
|
if (!m_autoSelectLayer->isVisible())
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_autoSelectLayer->setSelected(state);
|
|
|
|
}
|
|
|
|
|
2015-04-29 23:32:44 +08:00
|
|
|
int ContextBar::addBrush(const doc::BrushRef& brush)
|
|
|
|
{
|
2015-04-30 02:00:05 +08:00
|
|
|
// Use an empty slot
|
|
|
|
for (size_t i=0; i<m_brushes.size(); ++i) {
|
2015-04-30 22:59:47 +08:00
|
|
|
if (!m_brushes[i].locked ||
|
|
|
|
!m_brushes[i].brush) {
|
|
|
|
m_brushes[i].brush = brush;
|
2015-04-30 02:00:05 +08:00
|
|
|
return i+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 22:59:47 +08:00
|
|
|
m_brushes.push_back(BrushSlot(brush));
|
2015-04-29 23:32:44 +08:00
|
|
|
return (int)m_brushes.size(); // Returns the slot
|
|
|
|
}
|
|
|
|
|
2015-04-30 02:00:05 +08:00
|
|
|
void ContextBar::removeBrush(int slot)
|
2015-04-29 23:32:44 +08:00
|
|
|
{
|
|
|
|
--slot;
|
2015-04-30 04:26:25 +08:00
|
|
|
if (slot >= 0 && slot < (int)m_brushes.size()) {
|
2015-04-30 22:59:47 +08:00
|
|
|
m_brushes[slot].brush.reset();
|
2015-04-30 04:26:25 +08:00
|
|
|
|
|
|
|
// Erase empty trailing slots
|
|
|
|
while (!m_brushes.empty() &&
|
2015-04-30 22:59:47 +08:00
|
|
|
!m_brushes[m_brushes.size()-1].brush)
|
2015-04-30 04:26:25 +08:00
|
|
|
m_brushes.erase(--m_brushes.end());
|
|
|
|
}
|
2015-04-30 02:00:05 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 22:59:47 +08:00
|
|
|
void ContextBar::removeAllBrushes()
|
|
|
|
{
|
|
|
|
while (!m_brushes.empty())
|
|
|
|
m_brushes.erase(--m_brushes.end());
|
|
|
|
}
|
|
|
|
|
2015-04-30 02:00:05 +08:00
|
|
|
void ContextBar::setActiveBrushBySlot(int slot)
|
|
|
|
{
|
|
|
|
--slot;
|
|
|
|
if (slot >= 0 && slot < (int)m_brushes.size() &&
|
2015-04-30 22:59:47 +08:00
|
|
|
m_brushes[slot].brush) {
|
|
|
|
m_brushes[slot].locked = true;
|
|
|
|
setActiveBrush(m_brushes[slot].brush);
|
2015-04-30 02:00:05 +08:00
|
|
|
}
|
2015-04-29 23:32:44 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 22:59:47 +08:00
|
|
|
Brushes ContextBar::getBrushes()
|
|
|
|
{
|
|
|
|
Brushes brushes;
|
|
|
|
for (const auto& slot : m_brushes)
|
|
|
|
brushes.push_back(slot.brush);
|
|
|
|
return brushes;
|
|
|
|
}
|
|
|
|
|
2015-05-07 04:39:40 +08:00
|
|
|
void ContextBar::lockBrushSlot(int slot)
|
|
|
|
{
|
|
|
|
--slot;
|
|
|
|
if (slot >= 0 && slot < (int)m_brushes.size() &&
|
|
|
|
m_brushes[slot].brush) {
|
|
|
|
m_brushes[slot].locked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContextBar::unlockBrushSlot(int slot)
|
|
|
|
{
|
|
|
|
--slot;
|
|
|
|
if (slot >= 0 && slot < (int)m_brushes.size() &&
|
|
|
|
m_brushes[slot].brush) {
|
|
|
|
m_brushes[slot].locked = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ContextBar::isBrushSlotLocked(int slot) const
|
|
|
|
{
|
|
|
|
--slot;
|
|
|
|
if (slot >= 0 && slot < (int)m_brushes.size() &&
|
|
|
|
m_brushes[slot].brush) {
|
|
|
|
return m_brushes[slot].locked;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-29 05:21:33 +08:00
|
|
|
void ContextBar::setActiveBrush(const doc::BrushRef& brush)
|
|
|
|
{
|
|
|
|
m_activeBrush = brush;
|
2015-07-07 00:05:06 +08:00
|
|
|
BrushChange();
|
2015-04-29 05:21:33 +08:00
|
|
|
|
2015-05-07 23:32:08 +08:00
|
|
|
updateForCurrentTool();
|
2015-04-29 05:21:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
doc::BrushRef ContextBar::activeBrush(tools::Tool* tool) const
|
|
|
|
{
|
|
|
|
if (!tool ||
|
|
|
|
(tool->getInk(0)->isPaint() &&
|
|
|
|
m_activeBrush->type() == kImageBrushType)) {
|
2015-05-19 03:53:25 +08:00
|
|
|
m_activeBrush->setPattern(Preferences::instance().brush.pattern());
|
2015-04-29 05:21:33 +08:00
|
|
|
return m_activeBrush;
|
|
|
|
}
|
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
return ContextBar::createBrushFromPreferences(
|
|
|
|
&Preferences::instance().tool(tool).brush);
|
2015-04-29 05:21:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContextBar::discardActiveBrush()
|
|
|
|
{
|
2015-05-19 03:53:25 +08:00
|
|
|
setActiveBrush(ContextBar::createBrushFromPreferences());
|
2015-04-29 05:21:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2015-05-19 03:53:25 +08:00
|
|
|
doc::BrushRef ContextBar::createBrushFromPreferences(ToolPreferences::Brush* brushPref)
|
2015-04-29 05:21:33 +08:00
|
|
|
{
|
2015-05-19 03:53:25 +08:00
|
|
|
if (brushPref == nullptr) {
|
|
|
|
tools::Tool* tool = App::instance()->activeTool();
|
|
|
|
brushPref = &Preferences::instance().tool(tool).brush;
|
2015-04-29 05:21:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
doc::BrushRef brush;
|
|
|
|
brush.reset(
|
|
|
|
new Brush(
|
2015-05-19 03:53:25 +08:00
|
|
|
static_cast<doc::BrushType>(brushPref->type()),
|
|
|
|
brushPref->size(),
|
|
|
|
brushPref->angle()));
|
2015-04-29 05:21:33 +08:00
|
|
|
return brush;
|
|
|
|
}
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
} // namespace app
|