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"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/settings/ink_type.h"
|
2014-01-26 04:58:29 +08:00
|
|
|
#include "app/settings/selection_mode.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/settings/settings.h"
|
2013-11-30 04:59:28 +08:00
|
|
|
#include "app/settings/settings_observers.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"
|
|
|
|
#include "app/tools/point_shape.h"
|
|
|
|
#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"
|
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;
|
|
|
|
|
2014-10-25 23:10:52 +08:00
|
|
|
static bool g_updatingFromTool = false;
|
|
|
|
|
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_bitmap(BrushPopup::createSurfaceForBrush(BrushRef(nullptr)))
|
|
|
|
, m_popupWindow(this) {
|
2014-09-08 13:27:41 +08:00
|
|
|
addItem(m_bitmap);
|
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();
|
2014-06-23 05:53:14 +08:00
|
|
|
|
|
|
|
m_bitmap->dispose();
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
|
2015-04-29 05:21:33 +08:00
|
|
|
void updateBrush(tools::Tool* tool = nullptr) {
|
2013-03-31 00:43:00 +08:00
|
|
|
if (m_bitmap)
|
2014-06-23 05:53:14 +08:00
|
|
|
m_bitmap->dispose();
|
2015-04-28 23:38:15 +08:00
|
|
|
|
2015-04-29 23:32:44 +08:00
|
|
|
m_bitmap = BrushPopup::createSurfaceForBrush(
|
|
|
|
m_owner->activeBrush(tool));
|
2015-04-28 23:38:15 +08:00
|
|
|
|
2014-09-08 13:27:41 +08:00
|
|
|
getItem(0)->setIcon(m_bitmap);
|
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-28 23:38:15 +08:00
|
|
|
ISettings* settings = UIContext::instance()->settings();
|
|
|
|
Tool* currentTool = settings->getCurrentTool();
|
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);
|
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 {
|
|
|
|
ISettings* settings = UIContext::instance()->settings();
|
|
|
|
Tool* currentTool = settings->getCurrentTool();
|
|
|
|
IBrushSettings* brushSettings = settings->getToolSettings(currentTool)->getBrush();
|
|
|
|
brushSettings->setType(brush->type());
|
2013-03-31 07:46:04 +08:00
|
|
|
|
2015-04-29 23:32:44 +08:00
|
|
|
m_owner->setActiveBrush(
|
|
|
|
ContextBar::createBrushFromSettings(brushSettings));
|
|
|
|
}
|
2013-03-31 07:46:04 +08:00
|
|
|
}
|
|
|
|
|
2015-04-29 05:21:33 +08:00
|
|
|
ContextBar* m_owner;
|
2014-06-23 05:53:14 +08:00
|
|
|
she::Surface* m_bitmap;
|
2015-04-28 23:53:02 +08:00
|
|
|
BrushPopup m_popupWindow;
|
2013-03-31 00:43:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ContextBar::BrushSizeField : public IntEntry
|
|
|
|
{
|
|
|
|
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 {
|
2013-03-31 00:43:00 +08:00
|
|
|
IntEntry::onValueChange();
|
2014-10-25 23:10:52 +08:00
|
|
|
if (g_updatingFromTool)
|
|
|
|
return;
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2014-07-29 11:53:24 +08:00
|
|
|
ISettings* settings = UIContext::instance()->settings();
|
2013-03-31 00:43:00 +08:00
|
|
|
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) {
|
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 {
|
2013-03-31 00:43:00 +08:00
|
|
|
IntEntry::onValueChange();
|
2014-10-25 23:10:52 +08:00
|
|
|
if (g_updatingFromTool)
|
|
|
|
return;
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2014-07-29 11:53:24 +08:00
|
|
|
ISettings* settings = UIContext::instance()->settings();
|
2013-03-31 00:43:00 +08:00
|
|
|
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());
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
App::instance()->preferences().brush.pattern(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2013-03-31 00:43:00 +08:00
|
|
|
IntEntry::onValueChange();
|
2014-10-25 23:10:52 +08:00
|
|
|
if (g_updatingFromTool)
|
|
|
|
return;
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2014-07-29 11:53:24 +08:00
|
|
|
ISettings* settings = UIContext::instance()->settings();
|
2013-03-31 00:43:00 +08:00
|
|
|
Tool* currentTool = settings->getCurrentTool();
|
|
|
|
settings->getToolSettings(currentTool)
|
|
|
|
->setTolerance(getValue());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-07 11:07:24 +08:00
|
|
|
class ContextBar::ContiguousField : public CheckBox
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ContiguousField() : CheckBox("Contiguous") {
|
|
|
|
setup_mini_font(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setContiguous(bool state) {
|
|
|
|
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);
|
|
|
|
|
|
|
|
ISettings* settings = UIContext::instance()->settings();
|
|
|
|
Tool* currentTool = settings->getCurrentTool();
|
|
|
|
settings->getToolSettings(currentTool)
|
|
|
|
->setContiguous(isSelected());
|
|
|
|
|
|
|
|
releaseFocus();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-03-31 00:43:00 +08:00
|
|
|
class ContextBar::InkTypeField : public ComboBox
|
|
|
|
{
|
|
|
|
public:
|
2014-04-22 09:23:22 +08:00
|
|
|
InkTypeField() : m_lock(false) {
|
2013-04-02 07:20:58 +08:00
|
|
|
// The same order as in InkType
|
2014-01-26 19:40:16 +08:00
|
|
|
addItem("Default Ink");
|
2014-02-24 19:53:46 +08:00
|
|
|
#if 0
|
2013-04-02 07:20:58 +08:00
|
|
|
addItem("Opaque");
|
2014-02-24 19:53:46 +08:00
|
|
|
#endif
|
2014-05-05 09:20:33 +08:00
|
|
|
addItem("Set Alpha");
|
2014-05-05 09:16:30 +08:00
|
|
|
addItem("Lock Alpha");
|
2014-02-24 19:53:46 +08:00
|
|
|
#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");
|
2014-02-24 19:53:46 +08:00
|
|
|
#endif
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
|
2013-04-02 07:20:58 +08:00
|
|
|
void setInkType(InkType inkType) {
|
2014-03-09 08:00:14 +08:00
|
|
|
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;
|
2014-03-09 08:00:14 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 09:23:22 +08:00
|
|
|
m_lock = true;
|
2014-03-09 08:00:14 +08:00
|
|
|
setSelectedItemIndex(index);
|
2014-04-22 09:23:22 +08:00
|
|
|
m_lock = false;
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-08-15 10:07:47 +08:00
|
|
|
void onChange() override {
|
2013-03-31 00:43:00 +08:00
|
|
|
ComboBox::onChange();
|
2013-04-02 07:20:58 +08:00
|
|
|
|
2014-04-22 09:23:22 +08:00
|
|
|
if (m_lock)
|
|
|
|
return;
|
|
|
|
|
2014-03-09 07:37:43 +08:00
|
|
|
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;
|
2014-03-09 07:37:43 +08:00
|
|
|
}
|
|
|
|
|
2014-07-29 11:53:24 +08:00
|
|
|
ISettings* settings = UIContext::instance()->settings();
|
2013-04-02 07:20:58 +08:00
|
|
|
Tool* currentTool = settings->getCurrentTool();
|
2014-03-09 07:37:43 +08:00
|
|
|
settings->getToolSettings(currentTool)->setInkType(inkType);
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
2014-03-09 07:31:55 +08:00
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
void onCloseListBox() override {
|
2014-03-09 07:31:55 +08:00
|
|
|
releaseFocus();
|
|
|
|
}
|
2014-04-22 09:23:22 +08:00
|
|
|
|
|
|
|
bool m_lock;
|
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 {
|
2013-03-31 00:43:00 +08:00
|
|
|
IntEntry::onValueChange();
|
2014-10-25 23:10:52 +08:00
|
|
|
if (g_updatingFromTool)
|
|
|
|
return;
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2014-07-29 11:53:24 +08:00
|
|
|
ISettings* settings = UIContext::instance()->settings();
|
2013-03-31 00:43:00 +08:00
|
|
|
Tool* currentTool = settings->getCurrentTool();
|
|
|
|
settings->getToolSettings(currentTool)
|
|
|
|
->setOpacity(getValue());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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();
|
2014-10-25 23:10:52 +08:00
|
|
|
if (g_updatingFromTool)
|
|
|
|
return;
|
2013-03-31 08:31:34 +08:00
|
|
|
|
2014-07-29 11:53:24 +08:00
|
|
|
ISettings* settings = UIContext::instance()->settings();
|
2013-03-31 08:31:34 +08:00
|
|
|
Tool* currentTool = settings->getCurrentTool();
|
|
|
|
settings->getToolSettings(currentTool)
|
|
|
|
->setSprayWidth(getValue());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ContextBar::SpraySpeedField : public IntEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SpraySpeedField() : IntEntry(1, 100) {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-08-15 10:07:47 +08:00
|
|
|
void onValueChange() override {
|
2013-03-31 08:31:34 +08:00
|
|
|
IntEntry::onValueChange();
|
2014-10-25 23:10:52 +08:00
|
|
|
if (g_updatingFromTool)
|
|
|
|
return;
|
2013-03-31 08:31:34 +08:00
|
|
|
|
2014-07-29 11:53:24 +08:00
|
|
|
ISettings* settings = UIContext::instance()->settings();
|
2013-03-31 08:31:34 +08:00
|
|
|
Tool* currentTool = settings->getCurrentTool();
|
|
|
|
settings->getToolSettings(currentTool)
|
|
|
|
->setSpraySpeed(getValue());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-30 04:59:28 +08:00
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-12-30 04:11:56 +08:00
|
|
|
class ContextBar::RotAlgorithmField : public ComboBox
|
|
|
|
{
|
|
|
|
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;
|
2014-01-26 19:40:16 +08:00
|
|
|
addItem(new Item("Fast Rotation", kFastRotationAlgorithm));
|
2013-12-30 04:11:56 +08:00
|
|
|
addItem(new Item("RotSprite", kRotSpriteRotationAlgorithm));
|
2014-06-14 12:35:04 +08:00
|
|
|
m_lockChange = false;
|
2013-12-30 04:11:56 +08:00
|
|
|
|
2014-06-14 12:35:04 +08:00
|
|
|
setSelectedItemIndex((int)UIContext::instance()->settings()
|
|
|
|
->selection()->getRotationAlgorithm());
|
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;
|
|
|
|
|
2013-12-30 04:11:56 +08:00
|
|
|
UIContext::instance()->settings()->selection()
|
|
|
|
->setRotationAlgorithm(static_cast<Item*>(getSelectedItem())->algo());
|
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
Item(const std::string& text, RotationAlgorithm algo) :
|
|
|
|
ListItem(text),
|
|
|
|
m_algo(algo) {
|
|
|
|
}
|
|
|
|
|
|
|
|
RotationAlgorithm algo() const { return m_algo; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
RotationAlgorithm m_algo;
|
|
|
|
};
|
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) {
|
|
|
|
int part = PART_FREEHAND_ALGO_DEFAULT;
|
|
|
|
m_freehandAlgo = algo;
|
|
|
|
switch (m_freehandAlgo) {
|
|
|
|
case kDefaultFreehandAlgorithm:
|
|
|
|
part = PART_FREEHAND_ALGO_DEFAULT;
|
|
|
|
break;
|
|
|
|
case kPixelPerfectFreehandAlgorithm:
|
|
|
|
part = PART_FREEHAND_ALGO_PIXEL_PERFECT;
|
|
|
|
break;
|
|
|
|
case kDotsFreehandAlgorithm:
|
|
|
|
part = PART_FREEHAND_ALGO_DOTS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
m_bitmap = static_cast<SkinTheme*>(getTheme())->get_part(part);
|
|
|
|
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.
|
|
|
|
}
|
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
int getWidth() override {
|
2014-06-23 05:53:14 +08:00
|
|
|
return m_bitmap->width();
|
2014-06-15 15:14:53 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
int getHeight() override {
|
2014-06-23 05:53:14 +08:00
|
|
|
return m_bitmap->height();
|
2014-06-15 15:14:53 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
she::Surface* getNormalIcon() override {
|
2014-06-15 15:14:53 +08:00
|
|
|
return m_bitmap;
|
|
|
|
}
|
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
she::Surface* getSelectedIcon() override {
|
2014-06-15 15:14:53 +08:00
|
|
|
return m_bitmap;
|
|
|
|
}
|
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
she::Surface* getDisabledIcon() override {
|
2014-06-15 15:14:53 +08:00
|
|
|
return m_bitmap;
|
|
|
|
}
|
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
int getIconAlign() override {
|
2014-06-15 15:14:53 +08:00
|
|
|
return JI_CENTER | JI_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);
|
|
|
|
m_freehandAlgoButton->addItem(theme->get_part(PART_FREEHAND_ALGO_DEFAULT));
|
|
|
|
m_freehandAlgoButton->addItem(theme->get_part(PART_FREEHAND_ALGO_PIXEL_PERFECT));
|
|
|
|
m_freehandAlgoButton->addItem(theme->get_part(PART_FREEHAND_ALGO_DOTS));
|
|
|
|
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
|
|
|
|
2014-09-08 13:27:41 +08:00
|
|
|
m_tooltipManager->addTooltipFor(at(0), "Normal trace", JI_TOP);
|
|
|
|
m_tooltipManager->addTooltipFor(at(1), "Pixel-perfect trace", JI_TOP);
|
|
|
|
m_tooltipManager->addTooltipFor(at(2), "Dots", JI_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
|
|
|
|
2014-07-29 11:53:24 +08:00
|
|
|
ISettings* settings = UIContext::instance()->settings();
|
2014-01-26 03:26:49 +08:00
|
|
|
Tool* currentTool = settings->getCurrentTool();
|
|
|
|
settings->getToolSettings(currentTool)
|
2014-06-15 15:14:53 +08:00
|
|
|
->setFreehandAlgorithm(m_freehandAlgo);
|
2014-01-26 03:26:49 +08:00
|
|
|
}
|
2014-06-15 15:14:53 +08:00
|
|
|
|
2014-06-23 05:53:14 +08:00
|
|
|
she::Surface* 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
|
|
|
|
}
|
|
|
|
|
|
|
|
void setFreehandAlgorithm(FreehandAlgorithm algo) {
|
|
|
|
switch (algo) {
|
|
|
|
case kDefaultFreehandAlgorithm:
|
|
|
|
setSelected(false);
|
|
|
|
break;
|
|
|
|
case kPixelPerfectFreehandAlgorithm:
|
|
|
|
setSelected(true);
|
|
|
|
break;
|
|
|
|
case kDotsFreehandAlgorithm:
|
|
|
|
// 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);
|
|
|
|
|
2014-07-29 11:53:24 +08:00
|
|
|
ISettings* settings = UIContext::instance()->settings();
|
2014-07-17 20:54:04 +08:00
|
|
|
Tool* currentTool = settings->getCurrentTool();
|
|
|
|
settings->getToolSettings(currentTool)
|
|
|
|
->setFreehandAlgorithm(isSelected() ?
|
|
|
|
kPixelPerfectFreehandAlgorithm:
|
|
|
|
kDefaultFreehandAlgorithm);
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
addItem(theme->get_part(PART_SELECTION_REPLACE));
|
|
|
|
addItem(theme->get_part(PART_SELECTION_ADD));
|
|
|
|
addItem(theme->get_part(PART_SELECTION_SUBTRACT));
|
|
|
|
|
2014-06-14 12:35:04 +08:00
|
|
|
setSelectedItem(
|
|
|
|
(int)UIContext::instance()->settings()
|
|
|
|
->selection()->getSelectionMode());
|
2014-01-26 04:58:29 +08:00
|
|
|
}
|
|
|
|
|
2014-06-15 15:14:53 +08:00
|
|
|
void setupTooltips(TooltipManager* tooltipManager) {
|
2014-09-08 13:27:41 +08:00
|
|
|
tooltipManager->addTooltipFor(at(0), "Replace selection", JI_BOTTOM);
|
2015-04-10 21:35:45 +08:00
|
|
|
tooltipManager->addTooltipFor(at(1), "Add to selection\n(Shift)", JI_BOTTOM);
|
|
|
|
tooltipManager->addTooltipFor(at(2), "Subtract from selection\n(Shift+Alt)", JI_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();
|
|
|
|
|
|
|
|
UIContext::instance()->settings()->selection()
|
2014-09-08 13:27:41 +08:00
|
|
|
->setSelectionMode((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());
|
|
|
|
|
|
|
|
addItem(theme->get_part(PART_DROP_PIXELS_OK));
|
|
|
|
addItem(theme->get_part(PART_DROP_PIXELS_CANCEL));
|
|
|
|
setOfferCapture(false);
|
2014-05-26 11:20:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void setupTooltips(TooltipManager* tooltipManager) {
|
2014-09-08 13:27:41 +08:00
|
|
|
tooltipManager->addTooltipFor(at(0), "Drop pixels here", JI_BOTTOM);
|
|
|
|
tooltipManager->addTooltipFor(at(1), "Cancel drag and drop", JI_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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-01-29 10:56:44 +08:00
|
|
|
class ContextBar::GrabAlphaField : public CheckBox
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GrabAlphaField() : CheckBox("Grab Alpha") {
|
|
|
|
setup_mini_font(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-08-15 10:07:47 +08:00
|
|
|
void onClick(Event& ev) override {
|
2014-01-29 10:56:44 +08:00
|
|
|
CheckBox::onClick(ev);
|
|
|
|
|
|
|
|
UIContext::instance()->settings()->setGrabAlpha(isSelected());
|
2014-03-09 07:31:55 +08:00
|
|
|
|
|
|
|
releaseFocus();
|
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);
|
|
|
|
|
|
|
|
UIContext::instance()->settings()->setAutoSelectLayer(isSelected());
|
|
|
|
|
|
|
|
releaseFocus();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-03-31 00:43:00 +08:00
|
|
|
ContextBar::ContextBar()
|
|
|
|
: Box(JI_HORIZONTAL)
|
2014-01-29 10:56:44 +08:00
|
|
|
, m_toolSettings(NULL)
|
2013-03-31 00:43:00 +08:00
|
|
|
{
|
2014-11-26 09:33:45 +08:00
|
|
|
border_width.b = 2*guiscale();
|
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);
|
|
|
|
m_selectionOptionsBox->addChild(m_transparentColor = new TransparentColorField);
|
|
|
|
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());
|
2013-03-31 00:43:00 +08:00
|
|
|
|
|
|
|
addChild(m_inkType = new InkTypeField());
|
2013-03-31 08:12:09 +08:00
|
|
|
|
|
|
|
addChild(m_opacityLabel = new Label("Opacity:"));
|
2013-03-31 00:43:00 +08:00
|
|
|
addChild(m_inkOpacity = new InkOpacityField());
|
2014-01-29 10:56:44 +08:00
|
|
|
|
|
|
|
addChild(m_grabAlpha = new GrabAlphaField());
|
|
|
|
|
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);
|
|
|
|
setup_mini_font(m_opacityLabel);
|
|
|
|
|
2013-03-31 08:31:34 +08:00
|
|
|
TooltipManager* tooltipManager = new TooltipManager();
|
|
|
|
addChild(tooltipManager);
|
|
|
|
|
2014-01-26 19:40:16 +08:00
|
|
|
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);
|
2014-01-29 10:56:44 +08:00
|
|
|
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);
|
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
|
|
|
|
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);
|
2014-05-26 11:20:16 +08:00
|
|
|
m_dropPixels->DropPixels.connect(&ContextBar::onDropPixels, this);
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2015-04-29 05:21:33 +08:00
|
|
|
setActiveBrush(createBrushFromSettings());
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ContextBar::~ContextBar()
|
|
|
|
{
|
2014-01-29 10:56:44 +08:00
|
|
|
if (m_toolSettings)
|
|
|
|
m_toolSettings->removeObserver(this);
|
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
|
|
|
}
|
|
|
|
|
2014-01-29 10:56:44 +08:00
|
|
|
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
|
|
|
{
|
2015-04-29 05:21:33 +08:00
|
|
|
if (m_activeBrush->type() != kImageBrushType)
|
|
|
|
discardActiveBrush();
|
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)
|
|
|
|
setActiveBrush(ContextBar::createBrushFromSettings());
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
updateForTool(UIContext::instance()->settings()->getCurrentTool());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContextBar::updateForTool(tools::Tool* tool)
|
2014-01-29 10:56:44 +08:00
|
|
|
{
|
2014-10-25 23:10:52 +08:00
|
|
|
base::ScopedValue<bool> lockFlag(g_updatingFromTool, true, false);
|
|
|
|
|
2014-07-29 11:53:24 +08:00
|
|
|
ISettings* settings = UIContext::instance()->settings();
|
2015-05-08 00:11:44 +08:00
|
|
|
IToolSettings* toolSettings = nullptr;
|
|
|
|
IBrushSettings* brushSettings = nullptr;
|
|
|
|
|
|
|
|
if (tool) {
|
|
|
|
toolSettings = settings->getToolSettings(tool);
|
|
|
|
brushSettings = toolSettings->getBrush();
|
|
|
|
}
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2014-01-29 10:56:44 +08:00
|
|
|
if (m_toolSettings)
|
|
|
|
m_toolSettings->removeObserver(this);
|
|
|
|
m_toolSettings = toolSettings;
|
2015-05-08 00:11:44 +08:00
|
|
|
if (m_toolSettings)
|
|
|
|
m_toolSettings->addObserver(this);
|
|
|
|
|
|
|
|
if (tool)
|
|
|
|
m_brushType->updateBrush(tool);
|
|
|
|
|
|
|
|
if (brushSettings) {
|
|
|
|
m_brushSize->setTextf("%d", brushSettings->getSize());
|
|
|
|
m_brushAngle->setTextf("%d", brushSettings->getAngle());
|
|
|
|
}
|
2014-01-29 10:56:44 +08:00
|
|
|
|
2015-04-27 11:08:04 +08:00
|
|
|
m_brushPatternField->setBrushPattern(
|
|
|
|
App::instance()->preferences().brush.pattern());
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2015-05-08 00:11:44 +08:00
|
|
|
if (toolSettings) {
|
|
|
|
m_tolerance->setTextf("%d", toolSettings->getTolerance());
|
|
|
|
m_contiguous->setSelected(toolSettings->getContiguous());
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2015-05-08 00:11:44 +08:00
|
|
|
m_inkType->setInkType(toolSettings->getInkType());
|
|
|
|
m_inkOpacity->setTextf("%d", toolSettings->getOpacity());
|
2013-03-31 08:12:09 +08:00
|
|
|
|
2015-05-08 00:11:44 +08:00
|
|
|
m_freehandAlgo->setFreehandAlgorithm(toolSettings->getFreehandAlgorithm());
|
2014-01-26 03:26:49 +08:00
|
|
|
|
2015-05-08 00:11:44 +08:00
|
|
|
m_sprayWidth->setValue(toolSettings->getSprayWidth());
|
|
|
|
m_spraySpeed->setValue(toolSettings->getSpraySpeed());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (settings) {
|
|
|
|
m_grabAlpha->setSelected(settings->getGrabAlpha());
|
|
|
|
m_autoSelectLayer->setSelected(settings->getAutoSelectLayer());
|
|
|
|
}
|
2013-03-31 08:31:34 +08:00
|
|
|
|
2013-03-31 08:12:09 +08:00
|
|
|
// True if the current tool needs opacity options
|
2015-05-08 00:11:44 +08:00
|
|
|
bool hasOpacity = tool &&
|
|
|
|
(tool->getInk(0)->isPaint() ||
|
|
|
|
tool->getInk(0)->isEffect() ||
|
|
|
|
tool->getInk(1)->isPaint() ||
|
|
|
|
tool->getInk(1)->isEffect());
|
2014-01-29 10:56:44 +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
|
|
|
|
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());
|
|
|
|
|
2013-04-02 08:05:33 +08:00
|
|
|
// True if it makes sense to change the ink property for the current
|
|
|
|
// tool.
|
|
|
|
bool hasInk = hasOpacity;
|
|
|
|
|
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
|
|
|
|
2013-03-31 08:12:09 +08:00
|
|
|
// Show/Hide fields
|
2015-04-28 23:38:15 +08:00
|
|
|
m_brushType->setVisible(hasOpacity);
|
2015-04-27 11:08:04 +08:00
|
|
|
m_brushSize->setVisible(hasOpacity && !hasImageBrush);
|
|
|
|
m_brushAngle->setVisible(hasOpacity && !hasImageBrush);
|
|
|
|
m_brushPatternField->setVisible(hasOpacity && hasImageBrush);
|
2013-03-31 08:12:09 +08:00
|
|
|
m_opacityLabel->setVisible(hasOpacity);
|
2015-04-27 11:08:04 +08:00
|
|
|
m_inkType->setVisible(hasInk && !hasImageBrush);
|
2013-03-31 08:12:09 +08:00
|
|
|
m_inkOpacity->setVisible(hasOpacity);
|
2014-01-29 10:56:44 +08:00
|
|
|
m_grabAlpha->setVisible(isEyedropper);
|
2014-11-17 05:33:31 +08:00
|
|
|
m_autoSelectLayer->setVisible(isMove);
|
2014-01-29 10:56:44 +08:00
|
|
|
m_freehandBox->setVisible(isFreehand && hasOpacity);
|
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);
|
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);
|
|
|
|
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-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)) {
|
|
|
|
m_activeBrush->setPattern(App::instance()->preferences().brush.pattern());
|
|
|
|
return m_activeBrush;
|
|
|
|
}
|
|
|
|
|
|
|
|
ISettings* settings = UIContext::instance()->settings();
|
|
|
|
IToolSettings* toolSettings = settings->getToolSettings(tool);
|
|
|
|
return ContextBar::createBrushFromSettings(toolSettings->getBrush());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContextBar::discardActiveBrush()
|
|
|
|
{
|
|
|
|
setActiveBrush(ContextBar::createBrushFromSettings());
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
doc::BrushRef ContextBar::createBrushFromSettings(IBrushSettings* brushSettings)
|
|
|
|
{
|
|
|
|
if (brushSettings == nullptr) {
|
|
|
|
ISettings* settings = UIContext::instance()->settings();
|
|
|
|
tools::Tool* tool = settings->getCurrentTool();
|
|
|
|
IToolSettings* toolSettings = settings->getToolSettings(tool);
|
|
|
|
brushSettings = toolSettings->getBrush();
|
|
|
|
}
|
|
|
|
|
|
|
|
doc::BrushRef brush;
|
|
|
|
brush.reset(
|
|
|
|
new Brush(
|
|
|
|
brushSettings->getType(),
|
|
|
|
brushSettings->getSize(),
|
|
|
|
brushSettings->getAngle()));
|
|
|
|
return brush;
|
|
|
|
}
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
} // namespace app
|