2013-08-09 08:01:20 +08:00
|
|
|
/* Aseprite
|
2013-03-31 00:43:00 +08:00
|
|
|
* Copyright (C) 2001-2013 David Capello
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
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"
|
|
|
|
#include "app/modules/gui.h"
|
|
|
|
#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"
|
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"
|
2013-03-31 00:43:00 +08:00
|
|
|
#include "base/unique_ptr.h"
|
2014-06-15 02:09:43 +08:00
|
|
|
#include "raster/brush.h"
|
2013-11-10 06:59:05 +08:00
|
|
|
#include "raster/conversion_alleg.h"
|
2013-03-31 00:43:00 +08:00
|
|
|
#include "raster/image.h"
|
2013-11-10 06:59:05 +08:00
|
|
|
#include "raster/palette.h"
|
2013-03-31 00:43:00 +08:00
|
|
|
#include "ui/button.h"
|
|
|
|
#include "ui/combobox.h"
|
|
|
|
#include "ui/int_entry.h"
|
|
|
|
#include "ui/label.h"
|
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
|
|
|
|
|
|
|
#include <allegro.h>
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
class ContextBar::BrushTypeField : public Button
|
|
|
|
, public IButtonIcon
|
|
|
|
{
|
|
|
|
public:
|
2013-03-31 07:46:04 +08:00
|
|
|
BrushTypeField()
|
|
|
|
: Button("")
|
|
|
|
, m_popupWindow(NULL)
|
2014-06-15 02:09:43 +08:00
|
|
|
, m_brushTypeButton(NULL) {
|
2013-03-31 00:43:00 +08:00
|
|
|
setup_mini_look(this);
|
|
|
|
setIconInterface(this);
|
|
|
|
|
|
|
|
m_bitmap = create_bitmap_ex(32, 8, 8);
|
|
|
|
clear(m_bitmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
~BrushTypeField() {
|
2013-03-31 07:46:04 +08:00
|
|
|
closePopup();
|
2013-03-31 00:43:00 +08:00
|
|
|
setIconInterface(NULL);
|
|
|
|
destroy_bitmap(m_bitmap);
|
|
|
|
}
|
|
|
|
|
2014-06-15 02:09:43 +08:00
|
|
|
void setBrushSettings(IBrushSettings* brushSettings) {
|
2013-11-10 06:59:05 +08:00
|
|
|
base::UniquePtr<Palette> palette(new Palette(FrameNumber(0), 2));
|
|
|
|
palette->setEntry(0, raster::rgba(0, 0, 0, 0));
|
|
|
|
palette->setEntry(1, raster::rgba(0, 0, 0, 255));
|
|
|
|
|
2014-06-15 02:09:43 +08:00
|
|
|
base::UniquePtr<Brush> brush(
|
|
|
|
new Brush(
|
|
|
|
m_brushType = brushSettings->getType(),
|
|
|
|
std::min(10, brushSettings->getSize()),
|
|
|
|
brushSettings->getAngle()));
|
|
|
|
|
|
|
|
Image* image = brush->get_image();
|
2013-03-31 00:43:00 +08:00
|
|
|
|
|
|
|
if (m_bitmap)
|
|
|
|
destroy_bitmap(m_bitmap);
|
2013-11-10 06:59:05 +08:00
|
|
|
m_bitmap = create_bitmap_ex(32, image->getWidth(), image->getHeight());
|
2013-03-31 00:43:00 +08:00
|
|
|
clear(m_bitmap);
|
2013-11-10 06:59:05 +08:00
|
|
|
convert_image_to_allegro(image, m_bitmap, 0, 0, palette);
|
2013-03-31 00:43:00 +08:00
|
|
|
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
// IButtonIcon implementation
|
|
|
|
void destroy() OVERRIDE {
|
|
|
|
// Do nothing, BrushTypeField is added as a widget in the
|
|
|
|
// ContextBar, so it will be destroyed together with the
|
|
|
|
// ContextBar.
|
|
|
|
}
|
|
|
|
|
|
|
|
int getWidth() OVERRIDE {
|
|
|
|
return m_bitmap->w;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getHeight() OVERRIDE {
|
|
|
|
return m_bitmap->h;
|
|
|
|
}
|
|
|
|
|
|
|
|
BITMAP* getNormalIcon() OVERRIDE {
|
|
|
|
return m_bitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
BITMAP* getSelectedIcon() OVERRIDE {
|
|
|
|
return m_bitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
BITMAP* getDisabledIcon() OVERRIDE {
|
|
|
|
return m_bitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getIconAlign() OVERRIDE {
|
|
|
|
return JI_CENTER | JI_MIDDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2013-03-31 07:46:04 +08:00
|
|
|
void onClick(Event& ev) OVERRIDE {
|
|
|
|
Button::onClick(ev);
|
|
|
|
|
|
|
|
if (!m_popupWindow || !m_popupWindow->isVisible())
|
|
|
|
openPopup();
|
|
|
|
else
|
|
|
|
closePopup();
|
|
|
|
}
|
|
|
|
|
2013-03-31 00:43:00 +08:00
|
|
|
void onPreferredSize(PreferredSizeEvent& ev) {
|
|
|
|
ev.setPreferredSize(Size(16*jguiscale(),
|
|
|
|
16*jguiscale()));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-03-31 07:46:04 +08:00
|
|
|
void openPopup() {
|
2014-04-20 05:51:42 +08:00
|
|
|
Border border = Border(2, 2, 2, 3)*jguiscale();
|
2013-03-31 07:46:04 +08:00
|
|
|
Rect rc = getBounds();
|
|
|
|
rc.y += rc.h;
|
|
|
|
rc.w *= 3;
|
2014-04-14 06:25:06 +08:00
|
|
|
m_popupWindow = new PopupWindow("", PopupWindow::kCloseOnClickInOtherWindow);
|
2013-03-31 07:46:04 +08:00
|
|
|
m_popupWindow->setAutoRemap(false);
|
2014-04-20 05:51:42 +08:00
|
|
|
m_popupWindow->setBorder(border);
|
|
|
|
m_popupWindow->setBounds(rc + border);
|
2013-03-31 07:46:04 +08:00
|
|
|
|
2014-04-20 05:51:42 +08:00
|
|
|
Region rgn(m_popupWindow->getBounds().createUnion(getBounds()));
|
2013-03-31 07:46:04 +08:00
|
|
|
m_popupWindow->setHotRegion(rgn);
|
2014-06-15 02:09:43 +08:00
|
|
|
m_brushTypeButton = new ButtonSet(3, 1, m_brushType,
|
2014-04-20 05:51:42 +08:00
|
|
|
PART_BRUSH_CIRCLE,
|
|
|
|
PART_BRUSH_SQUARE,
|
|
|
|
PART_BRUSH_LINE);
|
2014-06-15 02:09:43 +08:00
|
|
|
m_brushTypeButton->ItemChange.connect(&BrushTypeField::onBrushTypeChange, this);
|
|
|
|
m_brushTypeButton->setTransparent(true);
|
|
|
|
m_brushTypeButton->setBgColor(ui::ColorNone);
|
2013-03-31 07:46:04 +08:00
|
|
|
|
2014-06-15 02:09:43 +08:00
|
|
|
m_popupWindow->addChild(m_brushTypeButton);
|
2013-03-31 07:46:04 +08:00
|
|
|
m_popupWindow->openWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
void closePopup() {
|
|
|
|
if (m_popupWindow) {
|
|
|
|
m_popupWindow->closeWindow(NULL);
|
|
|
|
delete m_popupWindow;
|
|
|
|
m_popupWindow = NULL;
|
2014-06-15 02:09:43 +08:00
|
|
|
m_brushTypeButton = NULL;
|
2013-03-31 07:46:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void onBrushTypeChange() {
|
2014-06-15 02:09:43 +08:00
|
|
|
m_brushType = (BrushType)m_brushTypeButton->getSelectedItem();
|
2013-03-31 07:46:04 +08:00
|
|
|
|
|
|
|
ISettings* settings = UIContext::instance()->getSettings();
|
|
|
|
Tool* currentTool = settings->getCurrentTool();
|
2014-06-15 02:09:43 +08:00
|
|
|
IBrushSettings* brushSettings = settings->getToolSettings(currentTool)->getBrush();
|
|
|
|
brushSettings->setType(m_brushType);
|
2013-03-31 07:46:04 +08:00
|
|
|
|
2014-06-15 02:09:43 +08:00
|
|
|
setBrushSettings(brushSettings);
|
2013-03-31 07:46:04 +08:00
|
|
|
}
|
|
|
|
|
2013-03-31 00:43:00 +08:00
|
|
|
BITMAP* m_bitmap;
|
2014-06-15 02:09:43 +08:00
|
|
|
BrushType m_brushType;
|
2013-03-31 07:46:04 +08:00
|
|
|
PopupWindow* m_popupWindow;
|
2014-06-15 02:09:43 +08:00
|
|
|
ButtonSet* m_brushTypeButton;
|
2013-03-31 00:43:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ContextBar::BrushSizeField : public IntEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BrushSizeField() : IntEntry(1, 32) {
|
|
|
|
setSuffix("px");
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void onValueChange() OVERRIDE {
|
|
|
|
IntEntry::onValueChange();
|
|
|
|
|
|
|
|
ISettings* settings = UIContext::instance()->getSettings();
|
|
|
|
Tool* currentTool = settings->getCurrentTool();
|
|
|
|
settings->getToolSettings(currentTool)
|
2014-06-15 02:09:43 +08:00
|
|
|
->getBrush()
|
2013-03-31 00:43:00 +08:00
|
|
|
->setSize(getValue());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ContextBar::BrushAngleField : public IntEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BrushAngleField(BrushTypeField* brushType)
|
|
|
|
: IntEntry(0, 180)
|
|
|
|
, m_brushType(brushType) {
|
2013-11-24 05:01:42 +08:00
|
|
|
setSuffix("\xc2\xb0");
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void onValueChange() OVERRIDE {
|
|
|
|
IntEntry::onValueChange();
|
|
|
|
|
|
|
|
ISettings* settings = UIContext::instance()->getSettings();
|
|
|
|
Tool* currentTool = settings->getCurrentTool();
|
|
|
|
settings->getToolSettings(currentTool)
|
2014-06-15 02:09:43 +08:00
|
|
|
->getBrush()
|
2013-03-31 00:43:00 +08:00
|
|
|
->setAngle(getValue());
|
|
|
|
|
|
|
|
IToolSettings* toolSettings = settings->getToolSettings(currentTool);
|
2014-06-15 02:09:43 +08:00
|
|
|
IBrushSettings* brushSettings = toolSettings->getBrush();
|
|
|
|
m_brushType->setBrushSettings(brushSettings);
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
BrushTypeField* m_brushType;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ContextBar::ToleranceField : public IntEntry
|
|
|
|
{
|
|
|
|
public:
|
2013-03-31 08:14:52 +08:00
|
|
|
ToleranceField() : IntEntry(0, 255) {
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void onValueChange() OVERRIDE {
|
|
|
|
IntEntry::onValueChange();
|
|
|
|
|
|
|
|
ISettings* settings = UIContext::instance()->getSettings();
|
|
|
|
Tool* currentTool = settings->getCurrentTool();
|
|
|
|
settings->getToolSettings(currentTool)
|
|
|
|
->setTolerance(getValue());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ContextBar::InkTypeField : public ComboBox
|
|
|
|
{
|
|
|
|
public:
|
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:
|
|
|
|
void onChange() OVERRIDE {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-04-02 07:20:58 +08:00
|
|
|
ISettings* settings = UIContext::instance()->getSettings();
|
|
|
|
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
|
|
|
|
|
|
|
void onCloseListBox() OVERRIDE {
|
|
|
|
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:
|
|
|
|
void onValueChange() OVERRIDE {
|
|
|
|
IntEntry::onValueChange();
|
|
|
|
|
|
|
|
ISettings* settings = UIContext::instance()->getSettings();
|
|
|
|
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:
|
|
|
|
void onValueChange() OVERRIDE {
|
|
|
|
IntEntry::onValueChange();
|
|
|
|
|
|
|
|
ISettings* settings = UIContext::instance()->getSettings();
|
|
|
|
Tool* currentTool = settings->getCurrentTool();
|
|
|
|
settings->getToolSettings(currentTool)
|
|
|
|
->setSprayWidth(getValue());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ContextBar::SpraySpeedField : public IntEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SpraySpeedField() : IntEntry(1, 100) {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void onValueChange() OVERRIDE {
|
|
|
|
IntEntry::onValueChange();
|
|
|
|
|
|
|
|
ISettings* settings = UIContext::instance()->getSettings();
|
|
|
|
Tool* currentTool = settings->getCurrentTool();
|
|
|
|
settings->getToolSettings(currentTool)
|
|
|
|
->setSpraySpeed(getValue());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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:
|
|
|
|
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-03-09 07:31:55 +08:00
|
|
|
void onCloseListBox() OVERRIDE {
|
|
|
|
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-01-26 03:26:49 +08:00
|
|
|
class ContextBar::FreehandAlgorithmField : public CheckBox
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FreehandAlgorithmField() : CheckBox("Pixel-perfect") {
|
2014-01-26 19:40:16 +08:00
|
|
|
setup_mini_font(this);
|
2014-01-26 03:26:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void onClick(Event& ev) OVERRIDE {
|
|
|
|
CheckBox::onClick(ev);
|
|
|
|
|
|
|
|
ISettings* settings = UIContext::instance()->getSettings();
|
|
|
|
Tool* currentTool = settings->getCurrentTool();
|
|
|
|
settings->getToolSettings(currentTool)
|
|
|
|
->setFreehandAlgorithm(isSelected() ?
|
|
|
|
kPixelPerfectFreehandAlgorithm:
|
|
|
|
kDefaultFreehandAlgorithm);
|
2014-03-09 07:31:55 +08:00
|
|
|
|
|
|
|
releaseFocus(
|
|
|
|
);
|
2014-01-26 03:26:49 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-01-26 04:58:29 +08:00
|
|
|
class ContextBar::SelectionModeField : public ButtonSet
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SelectionModeField() : ButtonSet(3, 1, 0,
|
|
|
|
PART_SELECTION_REPLACE,
|
|
|
|
PART_SELECTION_ADD,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void setupTooltips(TooltipManager* tooltipManager)
|
|
|
|
{
|
2014-01-26 19:40:16 +08:00
|
|
|
tooltipManager->addTooltipFor(getButtonAt(0), "Replace selection", JI_BOTTOM);
|
|
|
|
tooltipManager->addTooltipFor(getButtonAt(1), "Add to selection", JI_BOTTOM);
|
|
|
|
tooltipManager->addTooltipFor(getButtonAt(2), "Subtract from selection", JI_BOTTOM);
|
2014-01-26 04:58:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void onItemChange() OVERRIDE {
|
|
|
|
ButtonSet::onItemChange();
|
|
|
|
|
|
|
|
int item = getSelectedItem();
|
|
|
|
UIContext::instance()->settings()->selection()
|
|
|
|
->setSelectionMode((SelectionMode)item);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-05-26 11:20:16 +08:00
|
|
|
class ContextBar::DropPixelsField : public ButtonSet
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DropPixelsField() : ButtonSet(2, 1, -1,
|
|
|
|
PART_DROP_PIXELS_OK,
|
|
|
|
PART_DROP_PIXELS_CANCEL) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void setupTooltips(TooltipManager* tooltipManager) {
|
|
|
|
tooltipManager->addTooltipFor(getButtonAt(0), "Drop pixels here", JI_BOTTOM);
|
|
|
|
tooltipManager->addTooltipFor(getButtonAt(1), "Cancel drag and drop", JI_BOTTOM);
|
|
|
|
}
|
|
|
|
|
|
|
|
Signal1<void, ContextBarObserver::DropAction> DropPixels;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void onItemChange() OVERRIDE {
|
|
|
|
ButtonSet::onItemChange();
|
|
|
|
|
|
|
|
switch (getSelectedItem()) {
|
|
|
|
case 0: DropPixels(ContextBarObserver::DropPixels); break;
|
|
|
|
case 1: DropPixels(ContextBarObserver::CancelDrag); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-01-29 10:56:44 +08:00
|
|
|
class ContextBar::GrabAlphaField : public CheckBox
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GrabAlphaField() : CheckBox("Grab Alpha") {
|
|
|
|
setup_mini_font(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void onClick(Event& ev) OVERRIDE {
|
|
|
|
CheckBox::onClick(ev);
|
|
|
|
|
|
|
|
UIContext::instance()->settings()->setGrabAlpha(isSelected());
|
2014-03-09 07:31:55 +08:00
|
|
|
|
|
|
|
releaseFocus();
|
2014-01-29 10:56:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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
|
|
|
{
|
|
|
|
border_width.b = 2*jguiscale();
|
|
|
|
|
|
|
|
SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
|
|
|
|
setBgColor(theme->getColor(ThemeColor::Workspace));
|
|
|
|
|
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());
|
|
|
|
|
2013-03-31 00:43:00 +08:00
|
|
|
addChild(m_brushType = new BrushTypeField());
|
|
|
|
addChild(m_brushSize = new BrushSizeField());
|
|
|
|
addChild(m_brushAngle = new BrushAngleField(m_brushType));
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
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());
|
2014-01-26 19:40:16 +08:00
|
|
|
m_sprayBox->addChild(setup_mini_font(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());
|
|
|
|
|
2014-01-26 03:37:38 +08:00
|
|
|
addChild(m_freehandBox = new HBox());
|
|
|
|
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);
|
2014-01-26 04:58:29 +08:00
|
|
|
m_selectionMode->setupTooltips(tooltipManager);
|
2014-05-26 11:20:16 +08:00
|
|
|
m_dropPixels->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
|
|
|
|
|
|
|
onCurrentToolChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool ContextBar::onProcessMessage(Message* msg)
|
|
|
|
{
|
|
|
|
return Box::onProcessMessage(msg);
|
|
|
|
}
|
|
|
|
|
2014-02-03 08:07:12 +08:00
|
|
|
void ContextBar::onPreferredSize(PreferredSizeEvent& ev)
|
|
|
|
{
|
|
|
|
ev.setPreferredSize(gfx::Size(0, 18*jguiscale())); // TODO calculate height
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
ISettings* settings = UIContext::instance()->getSettings();
|
|
|
|
Tool* currentTool = settings->getCurrentTool();
|
|
|
|
IToolSettings* toolSettings = settings->getToolSettings(currentTool);
|
2014-06-15 02:09:43 +08:00
|
|
|
IBrushSettings* brushSettings = toolSettings->getBrush();
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2014-06-15 02:09:43 +08:00
|
|
|
m_brushType->setBrushSettings(brushSettings);
|
|
|
|
m_brushSize->setTextf("%d", brushSettings->getSize());
|
2013-03-31 00:43:00 +08:00
|
|
|
}
|
|
|
|
|
2014-06-15 02:09:43 +08:00
|
|
|
void ContextBar::onBrushAngleChange()
|
2013-05-23 10:58:32 +08:00
|
|
|
{
|
|
|
|
ISettings* settings = UIContext::instance()->getSettings();
|
|
|
|
Tool* currentTool = settings->getCurrentTool();
|
|
|
|
IToolSettings* toolSettings = settings->getToolSettings(currentTool);
|
2014-06-15 02:09:43 +08:00
|
|
|
IBrushSettings* brushSettings = toolSettings->getBrush();
|
2013-05-23 10:58:32 +08:00
|
|
|
|
2014-06-15 02:09:43 +08:00
|
|
|
m_brushType->setBrushSettings(brushSettings);
|
|
|
|
m_brushAngle->setTextf("%d", brushSettings->getAngle());
|
2013-05-23 10:58:32 +08:00
|
|
|
}
|
|
|
|
|
2013-03-31 00:43:00 +08:00
|
|
|
void ContextBar::onCurrentToolChange()
|
|
|
|
{
|
|
|
|
ISettings* settings = UIContext::instance()->getSettings();
|
2014-01-29 10:56:44 +08:00
|
|
|
updateFromTool(settings->getCurrentTool());
|
|
|
|
}
|
|
|
|
|
2014-05-26 11:20:16 +08:00
|
|
|
void ContextBar::onDropPixels(ContextBarObserver::DropAction action)
|
|
|
|
{
|
|
|
|
notifyObservers(&ContextBarObserver::onDropPixels, action);
|
|
|
|
}
|
|
|
|
|
2014-01-29 10:56:44 +08:00
|
|
|
void ContextBar::updateFromTool(tools::Tool* tool)
|
|
|
|
{
|
|
|
|
ISettings* settings = UIContext::instance()->getSettings();
|
|
|
|
IToolSettings* toolSettings = settings->getToolSettings(tool);
|
2014-06-15 02:09:43 +08:00
|
|
|
IBrushSettings* brushSettings = toolSettings->getBrush();
|
2013-03-31 00:43:00 +08:00
|
|
|
|
2014-01-29 10:56:44 +08:00
|
|
|
if (m_toolSettings)
|
|
|
|
m_toolSettings->removeObserver(this);
|
|
|
|
m_toolSettings = toolSettings;
|
|
|
|
m_toolSettings->addObserver(this);
|
|
|
|
|
2014-06-15 02:09:43 +08:00
|
|
|
m_brushType->setBrushSettings(brushSettings);
|
|
|
|
m_brushSize->setTextf("%d", brushSettings->getSize());
|
|
|
|
m_brushAngle->setTextf("%d", brushSettings->getAngle());
|
2013-03-31 00:43:00 +08:00
|
|
|
|
|
|
|
m_tolerance->setTextf("%d", toolSettings->getTolerance());
|
|
|
|
|
2013-04-02 07:20:58 +08:00
|
|
|
m_inkType->setInkType(toolSettings->getInkType());
|
2013-03-31 00:43:00 +08:00
|
|
|
m_inkOpacity->setTextf("%d", toolSettings->getOpacity());
|
2013-03-31 08:12:09 +08:00
|
|
|
|
2014-01-29 10:56:44 +08:00
|
|
|
m_grabAlpha->setSelected(settings->getGrabAlpha());
|
2014-01-26 03:26:49 +08:00
|
|
|
m_freehandAlgo->setSelected(toolSettings->getFreehandAlgorithm() == kPixelPerfectFreehandAlgorithm);
|
|
|
|
|
2013-03-31 08:31:34 +08:00
|
|
|
m_sprayWidth->setValue(toolSettings->getSprayWidth());
|
|
|
|
m_spraySpeed->setValue(toolSettings->getSpraySpeed());
|
|
|
|
|
2013-03-31 08:12:09 +08:00
|
|
|
// True if the current tool needs opacity options
|
2014-01-29 10:56:44 +08:00
|
|
|
bool hasOpacity = (tool->getInk(0)->isPaint() ||
|
|
|
|
tool->getInk(0)->isEffect() ||
|
|
|
|
tool->getInk(1)->isPaint() ||
|
|
|
|
tool->getInk(1)->isEffect());
|
|
|
|
|
|
|
|
// True if the current tool is eyedropper.
|
|
|
|
bool isEyedropper =
|
|
|
|
(tool->getInk(0)->isEyedropper() ||
|
|
|
|
tool->getInk(1)->isEyedropper());
|
2013-03-31 08:12:09 +08:00
|
|
|
|
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
|
2014-01-29 10:56:44 +08:00
|
|
|
bool hasTolerance = (tool->getPointShape(0)->isFloodFill() ||
|
|
|
|
tool->getPointShape(1)->isFloodFill());
|
2013-03-31 08:12:09 +08:00
|
|
|
|
|
|
|
// True if the current tool needs spray options
|
2014-01-29 10:56:44 +08:00
|
|
|
bool hasSprayOptions = (tool->getPointShape(0)->isSpray() ||
|
|
|
|
tool->getPointShape(1)->isSpray());
|
2013-03-31 08:12:09 +08:00
|
|
|
|
2014-01-29 10:56:44 +08:00
|
|
|
bool hasSelectOptions = (tool->getInk(0)->isSelection() ||
|
|
|
|
tool->getInk(1)->isSelection());
|
2013-11-30 04:59:28 +08:00
|
|
|
|
2014-01-26 03:26:49 +08:00
|
|
|
bool isFreehand =
|
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
|
|
|
|
m_brushType->setVisible(hasOpacity);
|
|
|
|
m_brushSize->setVisible(hasOpacity);
|
|
|
|
m_brushAngle->setVisible(hasOpacity);
|
|
|
|
m_opacityLabel->setVisible(hasOpacity);
|
2013-04-02 08:05:33 +08:00
|
|
|
m_inkType->setVisible(hasInk);
|
2013-03-31 08:12:09 +08:00
|
|
|
m_inkOpacity->setVisible(hasOpacity);
|
2014-01-29 10:56:44 +08:00
|
|
|
m_grabAlpha->setVisible(isEyedropper);
|
|
|
|
m_freehandBox->setVisible(isFreehand && hasOpacity);
|
2013-03-31 08:12:09 +08:00
|
|
|
m_toleranceLabel->setVisible(hasTolerance);
|
|
|
|
m_tolerance->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);
|
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)
|
|
|
|
updateFromTool(tool);
|
|
|
|
|
|
|
|
m_dropPixels->deselectItems();
|
|
|
|
m_dropPixels->setVisible(true);
|
|
|
|
m_selectionMode->setVisible(false);
|
|
|
|
layout();
|
|
|
|
}
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
} // namespace app
|