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.
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2007-09-19 07:57:02 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/app.h"
|
2010-08-25 11:26:37 +08:00
|
|
|
#include "app/color.h"
|
2015-03-21 01:46:48 +08:00
|
|
|
#include "app/color_utils.h"
|
2015-05-09 23:20:58 +08:00
|
|
|
#include "app/commands/commands.h"
|
|
|
|
#include "app/modules/editors.h"
|
2015-07-01 04:36:37 +08:00
|
|
|
#include "app/modules/gfx.h"
|
2014-04-14 03:26:00 +08:00
|
|
|
#include "app/modules/gui.h"
|
|
|
|
#include "app/modules/palettes.h"
|
2015-05-09 23:20:58 +08:00
|
|
|
#include "app/ui/editor/editor.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/palette_view.h"
|
2015-03-20 06:45:12 +08:00
|
|
|
#include "app/ui/skin/skin_theme.h"
|
|
|
|
#include "app/ui/skin/style.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/status_bar.h"
|
2015-05-11 08:36:46 +08:00
|
|
|
#include "app/util/clipboard.h"
|
2015-07-05 06:11:50 +08:00
|
|
|
#include "base/convert_to.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/image.h"
|
|
|
|
#include "doc/palette.h"
|
2015-03-23 23:25:32 +08:00
|
|
|
#include "doc/remap.h"
|
2015-03-20 19:44:39 +08:00
|
|
|
#include "gfx/color.h"
|
2015-03-20 06:45:12 +08:00
|
|
|
#include "gfx/point.h"
|
2015-07-05 06:11:50 +08:00
|
|
|
#include "she/font.h"
|
2015-08-20 23:08:08 +08:00
|
|
|
#include "she/surface.h"
|
2014-04-14 03:26:00 +08:00
|
|
|
#include "ui/graphics.h"
|
2012-06-18 09:49:58 +08:00
|
|
|
#include "ui/manager.h"
|
|
|
|
#include "ui/message.h"
|
2014-04-14 03:26:00 +08:00
|
|
|
#include "ui/paint_event.h"
|
2015-12-04 08:50:05 +08:00
|
|
|
#include "ui/size_hint_event.h"
|
2012-06-18 09:49:58 +08:00
|
|
|
#include "ui/system.h"
|
|
|
|
#include "ui/theme.h"
|
|
|
|
#include "ui/view.h"
|
|
|
|
#include "ui/widget.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
|
2015-03-23 23:25:32 +08:00
|
|
|
#include <algorithm>
|
2014-06-23 05:53:14 +08:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2012-06-18 09:02:54 +08:00
|
|
|
using namespace ui;
|
2015-03-20 06:45:12 +08:00
|
|
|
using namespace app::skin;
|
2012-06-18 09:02:54 +08:00
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
WidgetType palette_view_type()
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2013-04-04 09:07:24 +08:00
|
|
|
static WidgetType type = kGenericWidget;
|
|
|
|
if (type == kGenericWidget)
|
|
|
|
type = register_widget_type();
|
2007-09-19 07:57:02 +08:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2015-05-11 21:53:50 +08:00
|
|
|
PaletteView::PaletteView(bool editable, PaletteViewStyle style, PaletteViewDelegate* delegate, int boxsize)
|
2011-01-28 20:28:54 +08:00
|
|
|
: Widget(palette_view_type())
|
2015-03-21 02:29:44 +08:00
|
|
|
, m_state(State::WAITING)
|
2015-03-20 06:45:12 +08:00
|
|
|
, m_editable(editable)
|
2015-05-11 21:53:50 +08:00
|
|
|
, m_style(style)
|
2015-03-23 23:25:32 +08:00
|
|
|
, m_delegate(delegate)
|
2015-03-20 06:45:12 +08:00
|
|
|
, m_columns(16)
|
2015-03-24 01:39:21 +08:00
|
|
|
, m_boxsize(boxsize)
|
2011-06-27 06:07:19 +08:00
|
|
|
, m_currentEntry(-1)
|
|
|
|
, m_rangeAnchor(-1)
|
2012-07-18 12:10:43 +08:00
|
|
|
, m_isUpdatingColumns(false)
|
2015-03-21 01:46:48 +08:00
|
|
|
, m_hot(Hit::NONE)
|
2015-05-10 02:57:46 +08:00
|
|
|
, m_copy(false)
|
2008-03-15 09:54:45 +08:00
|
|
|
{
|
2014-04-14 03:26:00 +08:00
|
|
|
setFocusStop(true);
|
|
|
|
setDoubleBuffered(true);
|
|
|
|
|
2015-06-24 06:20:49 +08:00
|
|
|
setBorder(gfx::Border(1 * guiscale()));
|
|
|
|
setChildSpacing(1 * guiscale());
|
2014-06-02 05:09:19 +08:00
|
|
|
|
2014-06-13 09:29:19 +08:00
|
|
|
m_conn = App::instance()->PaletteChange.connect(&PaletteView::onAppPaletteChange, this);
|
2008-03-15 09:54:45 +08:00
|
|
|
}
|
|
|
|
|
2011-01-28 20:28:54 +08:00
|
|
|
void PaletteView::setColumns(int columns)
|
2008-03-15 09:54:45 +08:00
|
|
|
{
|
2010-04-11 04:01:56 +08:00
|
|
|
int old_columns = m_columns;
|
|
|
|
m_columns = columns;
|
2008-03-15 09:54:45 +08:00
|
|
|
|
2010-04-11 04:01:56 +08:00
|
|
|
if (m_columns != old_columns) {
|
2011-02-21 05:35:21 +08:00
|
|
|
View* view = View::getView(this);
|
2007-09-19 07:57:02 +08:00
|
|
|
if (view)
|
2011-02-21 05:35:21 +08:00
|
|
|
view->updateView();
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2011-01-22 06:45:04 +08:00
|
|
|
invalidate();
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-11 06:23:30 +08:00
|
|
|
void PaletteView::deselect()
|
2011-06-27 06:07:19 +08:00
|
|
|
{
|
2015-05-10 06:55:33 +08:00
|
|
|
bool invalidate = (m_selectedEntries.picks() > 0);
|
|
|
|
|
2015-06-18 23:50:33 +08:00
|
|
|
m_selectedEntries.resize(currentPalette()->size());
|
|
|
|
m_selectedEntries.clear();
|
2015-05-10 06:55:33 +08:00
|
|
|
|
|
|
|
if (invalidate)
|
|
|
|
this->invalidate();
|
2011-06-27 06:07:19 +08:00
|
|
|
}
|
|
|
|
|
2015-05-11 20:51:10 +08:00
|
|
|
void PaletteView::selectColor(int index)
|
2008-03-15 09:54:45 +08:00
|
|
|
{
|
2015-06-18 23:50:33 +08:00
|
|
|
if (index < 0 || index >= currentPalette()->size())
|
|
|
|
return;
|
2008-03-15 09:54:45 +08:00
|
|
|
|
2011-06-27 06:07:19 +08:00
|
|
|
if (m_currentEntry != index || !m_selectedEntries[index]) {
|
|
|
|
m_currentEntry = index;
|
|
|
|
m_rangeAnchor = index;
|
2015-05-10 06:55:33 +08:00
|
|
|
|
2011-06-27 06:07:19 +08:00
|
|
|
update_scroll(m_currentEntry);
|
2011-01-22 06:45:04 +08:00
|
|
|
invalidate();
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-11 22:25:53 +08:00
|
|
|
void PaletteView::selectExactMatchColor(const app::Color& color)
|
|
|
|
{
|
|
|
|
int index = findExactIndex(color);
|
|
|
|
if (index >= 0)
|
|
|
|
selectColor(index);
|
|
|
|
}
|
|
|
|
|
2011-06-27 06:07:19 +08:00
|
|
|
void PaletteView::selectRange(int index1, int index2)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2011-06-27 06:07:19 +08:00
|
|
|
m_rangeAnchor = index1;
|
|
|
|
m_currentEntry = index2;
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2011-06-27 06:07:19 +08:00
|
|
|
std::fill(m_selectedEntries.begin()+std::min(index1, index2),
|
2012-01-06 06:45:03 +08:00
|
|
|
m_selectedEntries.begin()+std::max(index1, index2)+1, true);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2011-06-27 06:07:19 +08:00
|
|
|
update_scroll(index2);
|
2011-01-22 06:45:04 +08:00
|
|
|
invalidate();
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2011-06-27 06:07:19 +08:00
|
|
|
int PaletteView::getSelectedEntry() const
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2011-06-27 06:07:19 +08:00
|
|
|
return m_currentEntry;
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2011-06-27 06:07:19 +08:00
|
|
|
bool PaletteView::getSelectedRange(int& index1, int& index2) const
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2011-06-27 06:07:19 +08:00
|
|
|
int i, i2, j;
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2011-06-27 06:07:19 +08:00
|
|
|
// Find the first selected entry
|
|
|
|
for (i=0; i<(int)m_selectedEntries.size(); ++i)
|
|
|
|
if (m_selectedEntries[i])
|
2007-09-19 07:57:02 +08:00
|
|
|
break;
|
|
|
|
|
2011-06-27 06:07:19 +08:00
|
|
|
// Find the first unselected entry after i
|
|
|
|
for (i2=i+1; i2<(int)m_selectedEntries.size(); ++i2)
|
|
|
|
if (!m_selectedEntries[i2])
|
2007-09-19 07:57:02 +08:00
|
|
|
break;
|
|
|
|
|
2011-06-27 06:07:19 +08:00
|
|
|
// Find the last selected entry
|
|
|
|
for (j=m_selectedEntries.size()-1; j>=0; --j)
|
|
|
|
if (m_selectedEntries[j])
|
|
|
|
break;
|
2008-03-15 09:54:45 +08:00
|
|
|
|
2011-06-27 06:07:19 +08:00
|
|
|
if (j-i+1 == i2-i) {
|
|
|
|
index1 = i;
|
|
|
|
index2 = j;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
2008-03-15 09:54:45 +08:00
|
|
|
}
|
|
|
|
|
2015-05-09 23:20:58 +08:00
|
|
|
void PaletteView::getSelectedEntries(PalettePicks& entries) const
|
2008-03-15 09:54:45 +08:00
|
|
|
{
|
2011-06-27 06:07:19 +08:00
|
|
|
entries = m_selectedEntries;
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2015-05-10 06:55:33 +08:00
|
|
|
int PaletteView::getSelectedEntriesCount() const
|
|
|
|
{
|
|
|
|
return m_selectedEntries.picks();
|
|
|
|
}
|
|
|
|
|
2015-03-20 19:44:39 +08:00
|
|
|
app::Color PaletteView::getColorByPosition(const gfx::Point& pos)
|
2011-02-24 06:29:57 +08:00
|
|
|
{
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
gfx::Point relPos = pos - bounds().origin();
|
2015-06-18 23:50:33 +08:00
|
|
|
Palette* palette = currentPalette();
|
2015-03-20 19:44:39 +08:00
|
|
|
for (int i=0; i<palette->size(); ++i) {
|
|
|
|
if (getPaletteEntryBounds(i).contains(relPos))
|
|
|
|
return app::Color::fromIndex(i);
|
2011-02-24 06:29:57 +08:00
|
|
|
}
|
2013-01-07 01:45:43 +08:00
|
|
|
return app::Color::fromMask();
|
2011-02-24 06:29:57 +08:00
|
|
|
}
|
|
|
|
|
2015-05-09 01:59:52 +08:00
|
|
|
int PaletteView::getBoxSize() const
|
|
|
|
{
|
|
|
|
return m_boxsize / guiscale();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PaletteView::setBoxSize(int boxsize)
|
|
|
|
{
|
|
|
|
m_boxsize = MID(4*guiscale(), boxsize, 32*guiscale());
|
|
|
|
|
|
|
|
if (m_delegate)
|
2015-05-09 04:00:44 +08:00
|
|
|
m_delegate->onPaletteViewChangeSize(m_boxsize / guiscale());
|
2015-05-09 01:59:52 +08:00
|
|
|
|
|
|
|
View* view = View::getView(this);
|
|
|
|
if (view)
|
|
|
|
view->layout();
|
|
|
|
}
|
|
|
|
|
2015-06-19 03:20:42 +08:00
|
|
|
void PaletteView::clearSelection()
|
2015-05-09 23:20:58 +08:00
|
|
|
{
|
2015-05-11 08:36:46 +08:00
|
|
|
if (!m_selectedEntries.picks())
|
|
|
|
return;
|
2015-05-09 23:20:58 +08:00
|
|
|
|
2015-06-18 23:50:33 +08:00
|
|
|
Palette palette(*currentPalette());
|
2015-05-11 08:36:46 +08:00
|
|
|
Palette newPalette(palette);
|
2015-06-19 03:20:42 +08:00
|
|
|
newPalette.resize(MAX(1, newPalette.size() - m_selectedEntries.picks()));
|
|
|
|
|
2015-05-11 08:36:46 +08:00
|
|
|
Remap remap = create_remap_to_move_picks(m_selectedEntries, palette.size());
|
|
|
|
for (int i=0; i<palette.size(); ++i) {
|
2015-06-19 03:20:42 +08:00
|
|
|
if (!m_selectedEntries[i])
|
2015-05-11 08:36:46 +08:00
|
|
|
newPalette.setEntry(remap[i], palette.getEntry(i));
|
2015-05-09 23:20:58 +08:00
|
|
|
}
|
2015-05-11 08:36:46 +08:00
|
|
|
|
|
|
|
m_currentEntry = m_selectedEntries.firstPick();
|
|
|
|
m_selectedEntries.clear();
|
|
|
|
stopMarchingAnts();
|
|
|
|
|
2015-08-20 23:08:08 +08:00
|
|
|
setNewPalette(&palette, &newPalette, PaletteViewModification::CLEAR);
|
2015-06-19 03:20:42 +08:00
|
|
|
}
|
2015-05-11 08:36:46 +08:00
|
|
|
|
2015-06-19 03:20:42 +08:00
|
|
|
void PaletteView::cutToClipboard()
|
|
|
|
{
|
|
|
|
if (!m_selectedEntries.picks())
|
|
|
|
return;
|
|
|
|
|
|
|
|
clipboard::copy_palette(currentPalette(), m_selectedEntries);
|
|
|
|
|
|
|
|
clearSelection();
|
2015-05-11 08:36:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PaletteView::copyToClipboard()
|
|
|
|
{
|
|
|
|
if (!m_selectedEntries.picks())
|
|
|
|
return;
|
|
|
|
|
2015-06-18 23:50:33 +08:00
|
|
|
clipboard::copy_palette(currentPalette(), m_selectedEntries);
|
2015-05-11 08:36:46 +08:00
|
|
|
|
|
|
|
startMarchingAnts();
|
|
|
|
invalidate();
|
2015-05-09 23:20:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PaletteView::pasteFromClipboard()
|
|
|
|
{
|
2015-05-11 08:36:46 +08:00
|
|
|
if (clipboard::get_current_format() == clipboard::ClipboardPaletteEntries) {
|
2015-05-09 23:20:58 +08:00
|
|
|
if (m_delegate)
|
|
|
|
m_delegate->onPaletteViewPasteColors(
|
2015-05-11 08:36:46 +08:00
|
|
|
clipboard::get_palette(),
|
|
|
|
clipboard::get_palette_picks(),
|
|
|
|
m_selectedEntries);
|
2015-05-09 23:20:58 +08:00
|
|
|
|
2015-05-10 06:55:33 +08:00
|
|
|
// We just hide the marching ants, the user can paste multiple
|
|
|
|
// times.
|
2015-05-09 23:20:58 +08:00
|
|
|
stopMarchingAnts();
|
2015-05-10 06:55:33 +08:00
|
|
|
invalidate();
|
2015-05-09 23:20:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-10 06:55:33 +08:00
|
|
|
void PaletteView::discardClipboardSelection()
|
|
|
|
{
|
2015-05-10 07:27:40 +08:00
|
|
|
if (isMarchingAntsRunning()) {
|
2015-05-10 06:55:33 +08:00
|
|
|
stopMarchingAnts();
|
|
|
|
invalidate();
|
2015-05-11 08:36:46 +08:00
|
|
|
}
|
2015-05-09 23:20:58 +08:00
|
|
|
}
|
|
|
|
|
2011-04-03 00:14:07 +08:00
|
|
|
bool PaletteView::onProcessMessage(Message* msg)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2013-07-29 08:17:07 +08:00
|
|
|
switch (msg->type()) {
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2015-05-10 06:55:33 +08:00
|
|
|
case kFocusEnterMessage:
|
|
|
|
FocusEnter();
|
2015-05-09 23:20:58 +08:00
|
|
|
break;
|
|
|
|
|
2015-05-10 06:55:33 +08:00
|
|
|
case kKeyDownMessage:
|
2015-05-10 02:57:46 +08:00
|
|
|
case kKeyUpMessage:
|
2015-05-10 06:55:33 +08:00
|
|
|
case kMouseEnterMessage:
|
2015-05-10 02:57:46 +08:00
|
|
|
updateCopyFlag(msg);
|
|
|
|
break;
|
|
|
|
|
2013-04-05 08:53:29 +08:00
|
|
|
case kMouseDownMessage:
|
2015-03-21 02:29:44 +08:00
|
|
|
switch (m_hot.part) {
|
2015-03-23 23:25:32 +08:00
|
|
|
|
2015-03-21 02:29:44 +08:00
|
|
|
case Hit::COLOR:
|
|
|
|
m_state = State::SELECTING_COLOR;
|
|
|
|
break;
|
2015-03-23 23:25:32 +08:00
|
|
|
|
2015-03-21 02:29:44 +08:00
|
|
|
case Hit::OUTLINE:
|
|
|
|
m_state = State::DRAGGING_OUTLINE;
|
|
|
|
break;
|
2015-08-20 23:08:08 +08:00
|
|
|
|
|
|
|
case Hit::RESIZE_HANDLE:
|
|
|
|
m_state = State::RESIZING_PALETTE;
|
|
|
|
break;
|
2015-03-21 02:29:44 +08:00
|
|
|
}
|
|
|
|
|
2010-04-25 23:03:25 +08:00
|
|
|
captureMouse();
|
2015-03-21 02:29:44 +08:00
|
|
|
|
2015-03-20 06:45:44 +08:00
|
|
|
// Continue...
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2013-04-05 08:53:29 +08:00
|
|
|
case kMouseMoveMessage: {
|
2013-07-29 08:17:07 +08:00
|
|
|
MouseMessage* mouseMsg = static_cast<MouseMessage*>(msg);
|
2011-02-24 06:29:57 +08:00
|
|
|
|
2015-07-05 06:11:50 +08:00
|
|
|
setStatusBar();
|
|
|
|
|
|
|
|
if (m_state == State::SELECTING_COLOR &&
|
|
|
|
m_hot.part == Hit::COLOR) {
|
|
|
|
int idx = m_hot.color;
|
|
|
|
idx = MID(0, idx, currentPalette()->size()-1);
|
|
|
|
|
|
|
|
MouseButtons buttons = mouseMsg->buttons();
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2015-07-05 06:11:50 +08:00
|
|
|
if (hasCapture() && ((idx != m_currentEntry) ||
|
|
|
|
(msg->type() == kMouseDownMessage) ||
|
|
|
|
((buttons & kButtonMiddle) == kButtonMiddle))) {
|
|
|
|
if ((buttons & kButtonMiddle) == 0) {
|
|
|
|
if (!msg->ctrlPressed())
|
|
|
|
deselect();
|
|
|
|
|
|
|
|
if (msg->type() == kMouseMoveMessage)
|
|
|
|
selectRange(m_rangeAnchor, idx);
|
|
|
|
else {
|
|
|
|
selectColor(idx);
|
|
|
|
m_selectedEntries[idx] = true;
|
|
|
|
}
|
2015-03-21 02:29:44 +08:00
|
|
|
}
|
2015-07-05 06:11:50 +08:00
|
|
|
|
|
|
|
// Emit signal
|
|
|
|
if (m_delegate)
|
|
|
|
m_delegate->onPaletteViewIndexChange(idx, buttons);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
2011-02-24 06:29:57 +08:00
|
|
|
}
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2011-02-24 06:29:57 +08:00
|
|
|
if (hasCapture())
|
2012-01-06 06:45:03 +08:00
|
|
|
return true;
|
2011-02-24 06:29:57 +08:00
|
|
|
|
2007-09-19 07:57:02 +08:00
|
|
|
break;
|
2011-02-24 06:29:57 +08:00
|
|
|
}
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2013-04-05 08:53:29 +08:00
|
|
|
case kMouseUpMessage:
|
2015-03-21 02:29:44 +08:00
|
|
|
if (hasCapture()) {
|
2015-03-21 01:46:48 +08:00
|
|
|
releaseMouse();
|
2015-03-21 02:29:44 +08:00
|
|
|
|
2015-08-20 23:08:08 +08:00
|
|
|
switch (m_state) {
|
|
|
|
|
|
|
|
case State::DRAGGING_OUTLINE:
|
2015-08-27 19:09:13 +08:00
|
|
|
if (m_hot.part == Hit::COLOR ||
|
|
|
|
m_hot.part == Hit::POSSIBLE_COLOR) {
|
2015-08-20 23:08:08 +08:00
|
|
|
int i = m_hot.color;
|
|
|
|
if (!m_copy && i > m_selectedEntries.firstPick())
|
|
|
|
i += m_selectedEntries.picks();
|
|
|
|
dropColors(i);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case State::RESIZING_PALETTE:
|
2015-08-27 19:09:13 +08:00
|
|
|
if (m_hot.part == Hit::COLOR ||
|
|
|
|
m_hot.part == Hit::POSSIBLE_COLOR) {
|
2015-08-20 23:08:08 +08:00
|
|
|
int newPalSize = MAX(1, m_hot.color);
|
|
|
|
Palette newPalette(*currentPalette());
|
|
|
|
newPalette.resize(newPalSize);
|
|
|
|
setNewPalette(currentPalette(), &newPalette,
|
|
|
|
PaletteViewModification::RESIZE);
|
|
|
|
}
|
|
|
|
break;
|
2015-03-23 23:25:32 +08:00
|
|
|
}
|
|
|
|
|
2015-03-21 02:29:44 +08:00
|
|
|
m_state = State::WAITING;
|
|
|
|
invalidate();
|
|
|
|
}
|
2010-01-31 00:43:13 +08:00
|
|
|
return true;
|
2011-02-20 10:44:17 +08:00
|
|
|
|
2013-04-05 08:53:29 +08:00
|
|
|
case kMouseWheelMessage: {
|
2011-02-21 05:35:21 +08:00
|
|
|
View* view = View::getView(this);
|
2015-03-24 00:28:16 +08:00
|
|
|
if (!view)
|
|
|
|
break;
|
|
|
|
|
|
|
|
gfx::Point delta = static_cast<MouseMessage*>(msg)->wheelDelta();
|
|
|
|
|
|
|
|
if (msg->onlyCtrlPressed()) {
|
|
|
|
int z = delta.x - delta.y;
|
2015-07-07 03:46:12 +08:00
|
|
|
setBoxSize(m_boxsize + z);
|
2015-03-24 00:28:16 +08:00
|
|
|
}
|
|
|
|
else {
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
gfx::Point scroll = view->viewScroll();
|
2015-03-24 00:28:16 +08:00
|
|
|
scroll += delta * 3 * m_boxsize;
|
2012-01-06 06:45:03 +08:00
|
|
|
view->setViewScroll(scroll);
|
2011-02-20 10:44:17 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-04-05 08:53:29 +08:00
|
|
|
case kMouseLeaveMessage:
|
2012-07-10 00:20:58 +08:00
|
|
|
StatusBar::instance()->clearText();
|
2015-03-21 01:46:48 +08:00
|
|
|
m_hot = Hit(Hit::NONE);
|
|
|
|
invalidate();
|
2011-02-24 06:29:57 +08:00
|
|
|
break;
|
|
|
|
|
2015-03-21 01:46:48 +08:00
|
|
|
case kSetCursorMessage: {
|
|
|
|
MouseMessage* mouseMsg = static_cast<MouseMessage*>(msg);
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
Hit hit = hitTest(mouseMsg->position() - bounds().origin());
|
2015-03-21 01:46:48 +08:00
|
|
|
if (hit != m_hot) {
|
|
|
|
m_hot = hit;
|
|
|
|
invalidate();
|
|
|
|
}
|
2015-05-10 02:57:46 +08:00
|
|
|
setCursor();
|
2015-03-21 01:46:48 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2010-08-03 08:29:56 +08:00
|
|
|
return Widget::onProcessMessage(msg);
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2014-04-14 03:26:00 +08:00
|
|
|
void PaletteView::onPaint(ui::PaintEvent& ev)
|
|
|
|
{
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
SkinTheme* theme = static_cast<SkinTheme*>(this->theme());
|
2015-03-20 06:45:12 +08:00
|
|
|
int outlineWidth = theme->dimensions.paletteOutlineWidth();
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
ui::Graphics* g = ev.graphics();
|
|
|
|
gfx::Rect bounds = clientBounds();
|
2015-06-18 23:50:33 +08:00
|
|
|
Palette* palette = currentPalette();
|
2015-05-11 21:53:50 +08:00
|
|
|
int fgIndex = -1;
|
|
|
|
int bgIndex = -1;
|
2015-05-20 22:40:22 +08:00
|
|
|
int transparentIndex = -1;
|
2015-08-27 19:09:13 +08:00
|
|
|
bool hotColor = (m_hot.part == Hit::COLOR ||
|
|
|
|
m_hot.part == Hit::POSSIBLE_COLOR);
|
|
|
|
bool dragging = (m_state == State::DRAGGING_OUTLINE && hotColor);
|
|
|
|
bool resizing = (m_state == State::RESIZING_PALETTE && hotColor);
|
2015-05-11 21:53:50 +08:00
|
|
|
|
2015-05-20 22:38:38 +08:00
|
|
|
if (m_style == FgBgColors && m_delegate) {
|
|
|
|
fgIndex = findExactIndex(m_delegate->onPaletteViewGetForegroundIndex());
|
|
|
|
bgIndex = findExactIndex(m_delegate->onPaletteViewGetBackgroundIndex());
|
2015-05-20 22:40:22 +08:00
|
|
|
|
|
|
|
if (current_editor && current_editor->sprite()->pixelFormat() == IMAGE_INDEXED)
|
|
|
|
transparentIndex = current_editor->sprite()->transparentColor();
|
2015-05-11 21:53:50 +08:00
|
|
|
}
|
2014-04-14 03:26:00 +08:00
|
|
|
|
2015-06-18 23:50:33 +08:00
|
|
|
g->fillRect(theme->colors.editorFace(), bounds);
|
2014-04-14 03:26:00 +08:00
|
|
|
|
2015-03-20 06:45:12 +08:00
|
|
|
// Draw palette entries
|
2015-07-05 06:11:50 +08:00
|
|
|
int picksCount = m_selectedEntries.picks();
|
|
|
|
int idxOffset = 0;
|
|
|
|
int boxOffset = 0;
|
2015-08-20 23:08:08 +08:00
|
|
|
int palSize = palette->size();
|
|
|
|
if (dragging && !m_copy) palSize -= picksCount;
|
|
|
|
if (resizing) palSize = m_hot.color;
|
|
|
|
|
|
|
|
for (int i=0; i<palSize; ++i) {
|
|
|
|
if (dragging) {
|
2015-07-05 06:11:50 +08:00
|
|
|
if (!m_copy) {
|
2015-07-07 00:56:53 +08:00
|
|
|
while (i+idxOffset < m_selectedEntries.size() &&
|
|
|
|
m_selectedEntries[i+idxOffset])
|
2015-07-05 06:11:50 +08:00
|
|
|
++idxOffset;
|
|
|
|
}
|
|
|
|
if (!boxOffset && m_hot.color == i) {
|
|
|
|
boxOffset += picksCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Rect box = getPaletteEntryBounds(i + boxOffset);
|
|
|
|
gfx::Color gfxColor = drawEntry(g, box, i + idxOffset);
|
2015-03-21 01:46:48 +08:00
|
|
|
|
2015-05-11 21:53:50 +08:00
|
|
|
switch (m_style) {
|
|
|
|
|
|
|
|
case SelectOneColor:
|
|
|
|
if (m_currentEntry == i)
|
2015-07-01 04:36:37 +08:00
|
|
|
g->fillRect(color_utils::blackandwhite_neg(gfxColor),
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
gfx::Rect(box.center(), gfx::Size(1, 1)));
|
2015-05-11 21:53:50 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FgBgColors:
|
|
|
|
if (fgIndex == i) {
|
2015-07-01 04:36:37 +08:00
|
|
|
gfx::Color neg = color_utils::blackandwhite_neg(gfxColor);
|
2015-05-11 21:53:50 +08:00
|
|
|
for (int i=0; i<m_boxsize/2; ++i)
|
|
|
|
g->drawHLine(neg, box.x, box.y+i, m_boxsize/2-i);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bgIndex == i) {
|
2015-07-01 04:36:37 +08:00
|
|
|
gfx::Color neg = color_utils::blackandwhite_neg(gfxColor);
|
2015-05-11 21:53:50 +08:00
|
|
|
for (int i=0; i<m_boxsize/4; ++i)
|
|
|
|
g->drawHLine(neg, box.x+box.w-(i+1), box.y+box.h-m_boxsize/4+i, i+1);
|
|
|
|
}
|
2015-05-20 22:40:22 +08:00
|
|
|
|
|
|
|
if (transparentIndex == i)
|
2015-07-01 04:36:37 +08:00
|
|
|
g->fillRect(color_utils::blackandwhite_neg(gfxColor),
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
gfx::Rect(box.center(), gfx::Size(1, 1)));
|
2015-05-11 21:53:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-03-20 06:45:12 +08:00
|
|
|
}
|
|
|
|
|
2015-08-20 23:08:08 +08:00
|
|
|
// Handle to resize palette
|
|
|
|
|
|
|
|
if (m_editable && !dragging) {
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
she::Surface* handle = theme->parts.palResize()->bitmap(0);
|
2015-08-20 23:08:08 +08:00
|
|
|
gfx::Rect box = getPaletteEntryBounds(palSize);
|
|
|
|
g->drawRgbaSurface(handle,
|
|
|
|
box.x+box.w/2-handle->width()/2,
|
|
|
|
box.y+box.h/2-handle->height()/2);
|
|
|
|
}
|
|
|
|
|
2015-03-20 06:45:12 +08:00
|
|
|
// Draw selected entries
|
2015-07-05 06:11:50 +08:00
|
|
|
|
2015-03-21 01:46:48 +08:00
|
|
|
Style::State state = Style::active();
|
|
|
|
if (m_hot.part == Hit::OUTLINE) state += Style::hover();
|
|
|
|
|
2015-07-05 06:11:50 +08:00
|
|
|
PalettePicks dragPicks;
|
|
|
|
int j = 0;
|
2015-08-20 23:08:08 +08:00
|
|
|
if (dragging) {
|
2015-07-05 06:11:50 +08:00
|
|
|
dragPicks.resize(m_hot.color+picksCount);
|
|
|
|
std::fill(dragPicks.begin()+m_hot.color, dragPicks.end(), true);
|
|
|
|
}
|
2015-08-20 23:08:08 +08:00
|
|
|
PalettePicks& picks = (dragging ? dragPicks: m_selectedEntries);
|
2015-07-05 06:11:50 +08:00
|
|
|
|
2015-03-20 19:44:39 +08:00
|
|
|
for (int i=0; i<palette->size(); ++i) {
|
|
|
|
if (!m_selectedEntries[i])
|
|
|
|
continue;
|
|
|
|
|
2015-08-20 23:08:08 +08:00
|
|
|
int k = (dragging ? m_hot.color+j: i);
|
2015-07-05 06:11:50 +08:00
|
|
|
|
2015-05-09 23:20:58 +08:00
|
|
|
gfx::Rect box, clipR;
|
2015-07-05 06:11:50 +08:00
|
|
|
getEntryBoundsAndClip(k, picks, box, clipR, outlineWidth);
|
2015-03-20 19:44:39 +08:00
|
|
|
|
|
|
|
IntersectClip clip(g, clipR);
|
|
|
|
if (clip) {
|
2015-07-05 06:11:50 +08:00
|
|
|
// Draw color being dragged + label
|
2015-08-20 23:08:08 +08:00
|
|
|
if (dragging) {
|
2015-07-05 06:11:50 +08:00
|
|
|
gfx::Rect box2 = getPaletteEntryBounds(k);
|
|
|
|
gfx::Color gfxColor = drawEntry(g, box2, i); // Draw color entry
|
|
|
|
|
|
|
|
gfx::Color neg = color_utils::blackandwhite_neg(gfxColor);
|
|
|
|
she::Font* minifont = theme->getMiniFont();
|
|
|
|
std::string text = base::convert_to<std::string>(k);
|
|
|
|
g->setFont(minifont);
|
|
|
|
g->drawString(text, neg, gfx::ColorNone,
|
|
|
|
gfx::Point(box2.x + box2.w/2 - minifont->textLength(text)/2,
|
|
|
|
box2.y + box2.h/2 - minifont->height()/2));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw outlines
|
|
|
|
theme->styles.timelineRangeOutline()->paint(
|
|
|
|
g, box, NULL, state);
|
2014-04-14 03:26:00 +08:00
|
|
|
}
|
2015-07-05 06:11:50 +08:00
|
|
|
|
|
|
|
++j;
|
2014-04-14 03:26:00 +08:00
|
|
|
}
|
2015-03-21 02:29:44 +08:00
|
|
|
|
2015-05-09 23:20:58 +08:00
|
|
|
// Draw marching ants
|
2015-07-05 06:11:50 +08:00
|
|
|
if ((m_state == State::WAITING) &&
|
|
|
|
(isMarchingAntsRunning()) &&
|
2015-05-11 08:36:46 +08:00
|
|
|
(clipboard::get_current_format() == clipboard::ClipboardPaletteEntries)) {
|
|
|
|
Palette* clipboardPalette = clipboard::get_palette();
|
|
|
|
const PalettePicks& clipboardPicks = clipboard::get_palette_picks();
|
|
|
|
|
|
|
|
if (clipboardPalette &&
|
|
|
|
clipboardPalette->countDiff(palette, nullptr, nullptr) == 0) {
|
|
|
|
for (int i=0; i<clipboardPicks.size(); ++i) {
|
|
|
|
if (!clipboardPicks[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gfx::Rect box, clipR;
|
|
|
|
getEntryBoundsAndClip(i, clipboardPicks, box, clipR, outlineWidth);
|
|
|
|
|
|
|
|
IntersectClip clip(g, clipR);
|
|
|
|
if (clip) {
|
|
|
|
CheckedDrawMode checked(g, getMarchingAntsOffset());
|
|
|
|
g->drawRect(gfx::rgba(0, 0, 0), box);
|
|
|
|
}
|
2015-05-09 23:20:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-14 03:26:00 +08:00
|
|
|
}
|
|
|
|
|
2013-05-12 04:56:27 +08:00
|
|
|
void PaletteView::onResize(ui::ResizeEvent& ev)
|
|
|
|
{
|
|
|
|
if (!m_isUpdatingColumns) {
|
|
|
|
m_isUpdatingColumns = true;
|
|
|
|
View* view = View::getView(this);
|
|
|
|
if (view) {
|
|
|
|
int columns =
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
(view->viewportBounds().w-this->childSpacing()*2)
|
2015-06-24 06:20:49 +08:00
|
|
|
/ (m_boxsize+this->childSpacing());
|
2015-06-29 23:33:41 +08:00
|
|
|
setColumns(MAX(1, columns));
|
2013-05-12 04:56:27 +08:00
|
|
|
}
|
|
|
|
m_isUpdatingColumns = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget::onResize(ev);
|
|
|
|
}
|
|
|
|
|
2015-12-04 08:50:05 +08:00
|
|
|
void PaletteView::onSizeHint(ui::SizeHintEvent& ev)
|
2012-09-27 05:34:52 +08:00
|
|
|
{
|
2015-08-27 19:09:13 +08:00
|
|
|
div_t d = div(currentPalette()->size(), m_columns);
|
|
|
|
int cols = m_columns;
|
|
|
|
int rows = d.quot + ((d.rem)? 1: 0);
|
|
|
|
|
|
|
|
if (m_editable) {
|
|
|
|
++rows;
|
|
|
|
}
|
|
|
|
|
2012-09-27 05:34:52 +08:00
|
|
|
gfx::Size sz;
|
2015-08-27 19:09:13 +08:00
|
|
|
sz.w = border().width() + cols*m_boxsize + (cols-1)*childSpacing();
|
|
|
|
sz.h = border().height() + rows*m_boxsize + (rows-1)*childSpacing();
|
|
|
|
|
2015-12-04 08:50:05 +08:00
|
|
|
ev.setSizeHint(sz);
|
2012-09-27 05:34:52 +08:00
|
|
|
}
|
|
|
|
|
2015-05-09 23:20:58 +08:00
|
|
|
void PaletteView::onDrawMarchingAnts()
|
|
|
|
{
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
2011-01-28 20:28:54 +08:00
|
|
|
void PaletteView::update_scroll(int color)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2011-02-21 05:35:21 +08:00
|
|
|
View* view = View::getView(this);
|
|
|
|
if (!view)
|
|
|
|
return;
|
2007-09-19 07:57:02 +08:00
|
|
|
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
gfx::Rect vp = view->viewportBounds();
|
2011-02-21 05:35:21 +08:00
|
|
|
gfx::Point scroll;
|
|
|
|
int x, y, cols;
|
|
|
|
div_t d;
|
2007-09-19 07:57:02 +08:00
|
|
|
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
scroll = view->viewScroll();
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2015-06-18 23:50:33 +08:00
|
|
|
d = div(currentPalette()->size(), m_columns);
|
2011-02-21 05:35:21 +08:00
|
|
|
cols = m_columns;
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2015-06-24 06:20:49 +08:00
|
|
|
y = (m_boxsize+childSpacing()) * (color / cols);
|
|
|
|
x = (m_boxsize+childSpacing()) * (color % cols);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2011-02-21 05:35:21 +08:00
|
|
|
if (scroll.x > x)
|
|
|
|
scroll.x = x;
|
|
|
|
else if (scroll.x+vp.w-m_boxsize-2 < x)
|
|
|
|
scroll.x = x-vp.w+m_boxsize+2;
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2011-02-21 05:35:21 +08:00
|
|
|
if (scroll.y > y)
|
|
|
|
scroll.y = y;
|
|
|
|
else if (scroll.y+vp.h-m_boxsize-2 < y)
|
|
|
|
scroll.y = y-vp.h+m_boxsize+2;
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2011-02-21 05:35:21 +08:00
|
|
|
view->setViewScroll(scroll);
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
2014-06-02 05:09:19 +08:00
|
|
|
void PaletteView::onAppPaletteChange()
|
|
|
|
{
|
2015-06-18 23:50:33 +08:00
|
|
|
m_selectedEntries.resize(currentPalette()->size());
|
|
|
|
|
|
|
|
View* view = View::getView(this);
|
|
|
|
if (view)
|
|
|
|
view->layout();
|
2014-06-02 05:09:19 +08:00
|
|
|
}
|
|
|
|
|
2015-05-09 23:20:58 +08:00
|
|
|
gfx::Rect PaletteView::getPaletteEntryBounds(int index) const
|
2015-03-20 19:44:39 +08:00
|
|
|
{
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
gfx::Rect bounds = clientBounds();
|
2015-03-20 19:44:39 +08:00
|
|
|
int cols = m_columns;
|
|
|
|
int col = index % cols;
|
|
|
|
int row = index / cols;
|
|
|
|
|
|
|
|
return gfx::Rect(
|
2015-06-24 06:20:49 +08:00
|
|
|
bounds.x + border().left() + col*(m_boxsize+childSpacing()),
|
|
|
|
bounds.y + border().top() + row*(m_boxsize+childSpacing()),
|
2015-03-20 19:44:39 +08:00
|
|
|
m_boxsize, m_boxsize);
|
|
|
|
}
|
|
|
|
|
2015-03-21 01:46:48 +08:00
|
|
|
PaletteView::Hit PaletteView::hitTest(const gfx::Point& pos)
|
|
|
|
{
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
SkinTheme* theme = static_cast<SkinTheme*>(this->theme());
|
2015-03-21 01:46:48 +08:00
|
|
|
int outlineWidth = theme->dimensions.paletteOutlineWidth();
|
2015-06-18 23:50:33 +08:00
|
|
|
Palette* palette = currentPalette();
|
2015-03-21 01:46:48 +08:00
|
|
|
|
2015-03-23 23:25:32 +08:00
|
|
|
if (m_state == State::WAITING && m_editable) {
|
2015-03-21 01:46:48 +08:00
|
|
|
// First check if the mouse is inside the selection outline.
|
|
|
|
for (int i=0; i<palette->size(); ++i) {
|
|
|
|
if (!m_selectedEntries[i])
|
|
|
|
continue;
|
|
|
|
|
2015-06-18 23:50:33 +08:00
|
|
|
const int max = palette->size();
|
2015-03-21 01:46:48 +08:00
|
|
|
bool top = (i >= m_columns && i-m_columns >= 0 ? m_selectedEntries[i-m_columns]: false);
|
|
|
|
bool bottom = (i < max-m_columns && i+m_columns < max ? m_selectedEntries[i+m_columns]: false);
|
|
|
|
bool left = ((i%m_columns)>0 && i-1 >= 0 ? m_selectedEntries[i-1]: false);
|
|
|
|
bool right = ((i%m_columns)<m_columns-1 && i+1 < max ? m_selectedEntries[i+1]: false);
|
|
|
|
|
|
|
|
gfx::Rect box = getPaletteEntryBounds(i);
|
|
|
|
box.enlarge(outlineWidth);
|
|
|
|
|
|
|
|
if ((!top && gfx::Rect(box.x, box.y, box.w, outlineWidth).contains(pos)) ||
|
2015-03-21 02:29:44 +08:00
|
|
|
(!bottom && gfx::Rect(box.x, box.y+box.h-outlineWidth, box.w, outlineWidth).contains(pos)) ||
|
|
|
|
(!left && gfx::Rect(box.x, box.y, outlineWidth, box.h).contains(pos)) ||
|
|
|
|
(!right && gfx::Rect(box.x+box.w-outlineWidth, box.y, outlineWidth, box.h).contains(pos)))
|
2015-03-21 01:46:48 +08:00
|
|
|
return Hit(Hit::OUTLINE, i);
|
|
|
|
}
|
2015-08-20 23:08:08 +08:00
|
|
|
|
|
|
|
// Check if we are in the resize handle
|
|
|
|
if (getPaletteEntryBounds(palette->size()).contains(pos)) {
|
|
|
|
return Hit(Hit::RESIZE_HANDLE, palette->size());
|
|
|
|
}
|
2015-03-21 01:46:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we are inside a color.
|
2015-06-19 02:50:00 +08:00
|
|
|
View* view = View::getView(this);
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
gfx::Rect vp = view->viewportBounds();
|
2015-06-19 02:50:00 +08:00
|
|
|
for (int i=0; ; ++i) {
|
2015-03-21 01:46:48 +08:00
|
|
|
gfx::Rect box = getPaletteEntryBounds(i);
|
2015-06-19 02:50:00 +08:00
|
|
|
if (i >= palette->size() && box.y2() > vp.h)
|
|
|
|
break;
|
|
|
|
|
2015-06-24 06:20:49 +08:00
|
|
|
box.w += childSpacing();
|
|
|
|
box.h += childSpacing();
|
2015-08-27 19:09:13 +08:00
|
|
|
if (box.contains(pos))
|
|
|
|
return Hit(Hit::COLOR, i);
|
2015-03-21 01:46:48 +08:00
|
|
|
}
|
|
|
|
|
2015-08-27 19:09:13 +08:00
|
|
|
gfx::Rect box = getPaletteEntryBounds(0);
|
|
|
|
box.w = (m_boxsize+childSpacing());
|
|
|
|
box.h = (m_boxsize+childSpacing());
|
|
|
|
|
|
|
|
int colsLimit = m_columns;
|
|
|
|
if (m_state == State::DRAGGING_OUTLINE)
|
|
|
|
--colsLimit;
|
|
|
|
int i = MID(0, (pos.x-vp.x)/box.w, colsLimit) + MAX(0, pos.y/box.h)*m_columns;
|
|
|
|
return Hit(Hit::POSSIBLE_COLOR, i);
|
2015-03-21 01:46:48 +08:00
|
|
|
}
|
|
|
|
|
2015-03-23 23:25:32 +08:00
|
|
|
void PaletteView::dropColors(int beforeIndex)
|
|
|
|
{
|
2015-06-18 23:50:33 +08:00
|
|
|
Palette palette(*currentPalette());
|
2015-06-19 02:50:00 +08:00
|
|
|
if (beforeIndex >= palette.size()) {
|
|
|
|
palette.resize(beforeIndex);
|
|
|
|
m_selectedEntries.resize(palette.size());
|
|
|
|
}
|
|
|
|
|
2015-05-10 02:57:46 +08:00
|
|
|
Palette newPalette(palette);
|
|
|
|
Remap remap(palette.size());
|
2015-03-23 23:25:32 +08:00
|
|
|
|
2015-05-10 02:57:46 +08:00
|
|
|
// Copy colors
|
|
|
|
if (m_copy) {
|
|
|
|
int picks = m_selectedEntries.picks();
|
2015-06-18 23:50:33 +08:00
|
|
|
ASSERT(picks >= 1);
|
|
|
|
|
2015-07-05 06:11:50 +08:00
|
|
|
remap = create_remap_to_expand_palette(palette.size()+picks,
|
|
|
|
picks,
|
|
|
|
beforeIndex);
|
2015-05-10 02:57:46 +08:00
|
|
|
|
2015-06-18 23:50:33 +08:00
|
|
|
newPalette.resize(palette.size()+picks);
|
2015-05-10 02:57:46 +08:00
|
|
|
for (int i=0; i<palette.size(); ++i)
|
|
|
|
newPalette.setEntry(remap[i], palette.getEntry(i));
|
|
|
|
|
|
|
|
for (int i=0, j=0; i<palette.size(); ++i) {
|
|
|
|
if (m_selectedEntries[i])
|
|
|
|
newPalette.setEntry(beforeIndex + (j++), palette.getEntry(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i=0, j=0; i<palette.size(); ++i) {
|
|
|
|
if (m_selectedEntries[i]) {
|
|
|
|
if (m_currentEntry == i) {
|
|
|
|
m_currentEntry = beforeIndex + j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i=0; i<palette.size(); ++i)
|
|
|
|
m_selectedEntries[i] = (i >= beforeIndex && i < beforeIndex + picks);
|
2015-03-23 23:25:32 +08:00
|
|
|
}
|
2015-05-10 02:57:46 +08:00
|
|
|
// Move colors
|
|
|
|
else {
|
|
|
|
remap = create_remap_to_move_picks(m_selectedEntries, beforeIndex);
|
2015-03-23 23:25:32 +08:00
|
|
|
|
2015-05-10 02:57:46 +08:00
|
|
|
auto oldSelectedCopies = m_selectedEntries;
|
|
|
|
for (int i=0; i<palette.size(); ++i) {
|
|
|
|
newPalette.setEntry(remap[i], palette.getEntry(i));
|
|
|
|
m_selectedEntries[remap[i]] = oldSelectedCopies[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
m_currentEntry = remap[m_currentEntry];
|
|
|
|
}
|
2015-03-23 23:25:32 +08:00
|
|
|
|
2015-08-20 23:08:08 +08:00
|
|
|
setNewPalette(&palette, &newPalette,
|
|
|
|
PaletteViewModification::DRAGANDDROP);
|
2015-03-23 23:25:32 +08:00
|
|
|
}
|
|
|
|
|
2015-05-09 23:20:58 +08:00
|
|
|
void PaletteView::getEntryBoundsAndClip(int i, const PalettePicks& entries,
|
|
|
|
gfx::Rect& box, gfx::Rect& clip,
|
|
|
|
int outlineWidth) const
|
|
|
|
{
|
|
|
|
box = clip = getPaletteEntryBounds(i);
|
|
|
|
box.enlarge(outlineWidth);
|
|
|
|
|
|
|
|
// Left
|
|
|
|
if (!pickedXY(entries, i, -1, 0)) {
|
|
|
|
clip.x -= outlineWidth;
|
|
|
|
clip.w += outlineWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Top
|
|
|
|
if (!pickedXY(entries, i, 0, -1)) {
|
|
|
|
clip.y -= outlineWidth;
|
|
|
|
clip.h += outlineWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Right
|
|
|
|
if (!pickedXY(entries, i, +1, 0))
|
|
|
|
clip.w += outlineWidth;
|
|
|
|
else {
|
|
|
|
clip.w += guiscale();
|
|
|
|
box.w += outlineWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bottom
|
|
|
|
if (!pickedXY(entries, i, 0, +1))
|
|
|
|
clip.h += outlineWidth;
|
|
|
|
else {
|
|
|
|
clip.h += guiscale();
|
|
|
|
box.h += outlineWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PaletteView::pickedXY(const doc::PalettePicks& entries, int i, int dx, int dy) const
|
|
|
|
{
|
|
|
|
int x = (i % m_columns) + dx;
|
|
|
|
int y = (i / m_columns) + dy;
|
2015-07-05 06:11:50 +08:00
|
|
|
int lastcolor = entries.size()-1;
|
2015-05-09 23:20:58 +08:00
|
|
|
|
2015-06-18 23:50:33 +08:00
|
|
|
if (x < 0 || x >= m_columns || y < 0 || y > lastcolor/m_columns)
|
2015-05-09 23:20:58 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
i = x + y*m_columns;
|
|
|
|
if (i >= 0 && i < entries.size())
|
|
|
|
return entries[i];
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-05-10 02:57:46 +08:00
|
|
|
void PaletteView::updateCopyFlag(ui::Message* msg)
|
|
|
|
{
|
|
|
|
bool oldCopy = m_copy;
|
|
|
|
m_copy = (msg->ctrlPressed() || msg->altPressed());
|
2015-07-05 06:11:50 +08:00
|
|
|
if (oldCopy != m_copy) {
|
2015-05-10 02:57:46 +08:00
|
|
|
setCursor();
|
2015-07-05 06:11:50 +08:00
|
|
|
setStatusBar();
|
|
|
|
invalidate();
|
|
|
|
}
|
2015-05-10 02:57:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PaletteView::setCursor()
|
|
|
|
{
|
|
|
|
if (m_state == State::DRAGGING_OUTLINE ||
|
2015-08-20 23:08:08 +08:00
|
|
|
(m_state == State::WAITING &&
|
|
|
|
m_hot.part == Hit::OUTLINE)) {
|
2015-05-10 02:57:46 +08:00
|
|
|
if (m_copy)
|
|
|
|
ui::set_mouse_cursor(kArrowPlusCursor);
|
|
|
|
else
|
|
|
|
ui::set_mouse_cursor(kMoveCursor);
|
|
|
|
}
|
2015-08-20 23:08:08 +08:00
|
|
|
else if (m_state == State::RESIZING_PALETTE ||
|
|
|
|
(m_state == State::WAITING &&
|
|
|
|
m_hot.part == Hit::RESIZE_HANDLE)) {
|
|
|
|
ui::set_mouse_cursor(kSizeWECursor);
|
|
|
|
}
|
2015-05-10 02:57:46 +08:00
|
|
|
else
|
|
|
|
ui::set_mouse_cursor(kArrowCursor);
|
|
|
|
}
|
|
|
|
|
2015-07-05 06:11:50 +08:00
|
|
|
void PaletteView::setStatusBar()
|
|
|
|
{
|
|
|
|
switch (m_state) {
|
|
|
|
|
|
|
|
case State::WAITING:
|
|
|
|
case State::SELECTING_COLOR:
|
|
|
|
if (m_hot.part == Hit::COLOR) {
|
|
|
|
int i = MID(0, m_hot.color, currentPalette()->size()-1);
|
|
|
|
|
|
|
|
StatusBar::instance()->showColor(
|
|
|
|
0, "", app::Color::fromIndex(i));
|
|
|
|
}
|
2015-07-06 06:41:11 +08:00
|
|
|
else {
|
|
|
|
StatusBar::instance()->clearText();
|
|
|
|
}
|
2015-07-05 06:11:50 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case State::DRAGGING_OUTLINE:
|
|
|
|
if (m_hot.part == Hit::COLOR) {
|
2015-07-06 06:41:11 +08:00
|
|
|
int picks = m_selectedEntries.picks();
|
|
|
|
int firstPick = m_selectedEntries.firstPick();
|
|
|
|
|
|
|
|
int destIndex = MAX(0, m_hot.color);
|
|
|
|
if (!m_copy && destIndex <= firstPick)
|
|
|
|
destIndex -= picks;
|
2015-07-05 06:11:50 +08:00
|
|
|
|
2015-07-06 06:41:11 +08:00
|
|
|
int palSize = currentPalette()->size();
|
|
|
|
int newPalSize =
|
|
|
|
(m_copy ? MAX(palSize + picks, destIndex + picks):
|
|
|
|
MAX(palSize, destIndex + picks));
|
2015-07-05 06:11:50 +08:00
|
|
|
|
|
|
|
StatusBar::instance()->setStatusText(
|
2015-07-06 06:41:11 +08:00
|
|
|
0, "%s to %d - New Palette Size %d",
|
|
|
|
(m_copy ? "Copy": "Move"),
|
|
|
|
destIndex, newPalSize);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
StatusBar::instance()->clearText();
|
2015-07-05 06:11:50 +08:00
|
|
|
}
|
|
|
|
break;
|
2015-08-20 23:08:08 +08:00
|
|
|
|
|
|
|
case State::RESIZING_PALETTE:
|
|
|
|
if (m_hot.part == Hit::COLOR ||
|
2015-08-27 19:09:13 +08:00
|
|
|
m_hot.part == Hit::POSSIBLE_COLOR ||
|
2015-08-20 23:08:08 +08:00
|
|
|
m_hot.part == Hit::RESIZE_HANDLE) {
|
|
|
|
int newPalSize = MAX(1, m_hot.color);
|
|
|
|
StatusBar::instance()->setStatusText(
|
|
|
|
0, "New Palette Size %d",
|
|
|
|
newPalSize);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
StatusBar::instance()->clearText();
|
|
|
|
}
|
|
|
|
break;
|
2015-07-05 06:11:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-18 23:50:33 +08:00
|
|
|
doc::Palette* PaletteView::currentPalette() const
|
|
|
|
{
|
|
|
|
return get_current_palette();
|
|
|
|
}
|
|
|
|
|
|
|
|
int PaletteView::findExactIndex(const app::Color& color) const
|
2015-05-11 21:53:50 +08:00
|
|
|
{
|
|
|
|
switch (color.getType()) {
|
|
|
|
|
|
|
|
case Color::MaskType:
|
|
|
|
return (current_editor ? current_editor->sprite()->transparentColor(): -1);
|
|
|
|
|
|
|
|
case Color::RgbType:
|
|
|
|
case Color::HsvType:
|
|
|
|
case Color::GrayType:
|
2015-07-17 23:26:11 +08:00
|
|
|
return currentPalette()->findExactMatch(
|
|
|
|
color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha(), -1);
|
2015-05-11 21:53:50 +08:00
|
|
|
|
|
|
|
case Color::IndexType:
|
|
|
|
return color.getIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT(false);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-08-20 23:08:08 +08:00
|
|
|
void PaletteView::setNewPalette(doc::Palette* oldPalette,
|
|
|
|
doc::Palette* newPalette,
|
|
|
|
PaletteViewModification mod)
|
2015-06-19 03:20:42 +08:00
|
|
|
{
|
|
|
|
// No differences
|
|
|
|
if (!newPalette->countDiff(oldPalette, nullptr, nullptr))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_delegate) {
|
2015-08-20 23:08:08 +08:00
|
|
|
m_delegate->onPaletteViewModification(newPalette, mod);
|
2015-06-19 03:20:42 +08:00
|
|
|
m_delegate->onPaletteViewIndexChange(m_currentEntry, ui::kButtonLeft);
|
|
|
|
}
|
|
|
|
|
|
|
|
set_current_palette(newPalette, false);
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
manager()->invalidate();
|
2015-06-19 03:20:42 +08:00
|
|
|
}
|
|
|
|
|
2015-07-05 06:11:50 +08:00
|
|
|
gfx::Color PaletteView::drawEntry(ui::Graphics* g, const gfx::Rect& box, int palIdx)
|
|
|
|
{
|
2015-08-20 23:08:08 +08:00
|
|
|
doc::color_t palColor =
|
|
|
|
(palIdx < currentPalette()->size() ? currentPalette()->getEntry(palIdx):
|
|
|
|
rgba(0, 0, 0, 255));
|
2015-07-05 06:11:50 +08:00
|
|
|
app::Color appColor = app::Color::fromRgb(
|
|
|
|
rgba_getr(palColor),
|
|
|
|
rgba_getg(palColor),
|
|
|
|
rgba_getb(palColor),
|
|
|
|
rgba_geta(palColor));
|
|
|
|
gfx::Color gfxColor = gfx::rgba(
|
|
|
|
rgba_getr(palColor),
|
|
|
|
rgba_getg(palColor),
|
|
|
|
rgba_getb(palColor),
|
|
|
|
rgba_geta(palColor));
|
|
|
|
|
|
|
|
g->drawRect(gfx::rgba(0, 0, 0), gfx::Rect(box).enlarge(guiscale()));
|
|
|
|
draw_color(g, box, appColor);
|
|
|
|
return gfxColor;
|
|
|
|
}
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
} // namespace app
|