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"
|
2014-04-14 03:26:00 +08:00
|
|
|
#include "app/modules/gui.h"
|
|
|
|
#include "app/modules/palettes.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/palette_view.h"
|
|
|
|
#include "app/ui/status_bar.h"
|
2011-02-21 05:35:21 +08:00
|
|
|
#include "gfx/point.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/blend.h"
|
|
|
|
#include "doc/image.h"
|
|
|
|
#include "doc/palette.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"
|
2012-09-27 05:34:52 +08:00
|
|
|
#include "ui/preferred_size_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
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-01-28 20:28:54 +08:00
|
|
|
PaletteView::PaletteView(bool editable)
|
|
|
|
: Widget(palette_view_type())
|
2011-06-27 06:07:19 +08:00
|
|
|
, m_currentEntry(-1)
|
|
|
|
, m_rangeAnchor(-1)
|
2012-05-03 10:09:34 +08:00
|
|
|
, m_selectedEntries(Palette::MaxColors, false)
|
2012-07-18 12:10:43 +08:00
|
|
|
, m_isUpdatingColumns(false)
|
2008-03-15 09:54:45 +08:00
|
|
|
{
|
2014-04-14 03:26:00 +08:00
|
|
|
setFocusStop(true);
|
|
|
|
setDoubleBuffered(true);
|
|
|
|
|
2010-04-11 04:01:56 +08:00
|
|
|
m_editable = editable;
|
|
|
|
m_columns = 16;
|
2014-11-26 09:33:45 +08:00
|
|
|
m_boxsize = 6*guiscale();
|
2010-04-11 04:01:56 +08:00
|
|
|
|
2014-11-26 09:33:45 +08:00
|
|
|
this->border_width.l = this->border_width.r = 1 * guiscale();
|
|
|
|
this->border_width.t = this->border_width.b = 1 * guiscale();
|
|
|
|
this->child_spacing = 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;
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2012-05-03 10:09:34 +08:00
|
|
|
ASSERT(columns >= 1 && columns <= Palette::MaxColors);
|
2010-04-11 04:01:56 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-28 20:28:54 +08:00
|
|
|
void PaletteView::setBoxSize(int boxsize)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2010-04-11 04:01:56 +08:00
|
|
|
m_boxsize = boxsize;
|
2008-03-15 09:54:45 +08:00
|
|
|
}
|
|
|
|
|
2011-06-27 06:07:19 +08:00
|
|
|
void PaletteView::clearSelection()
|
|
|
|
{
|
|
|
|
std::fill(m_selectedEntries.begin(),
|
2012-01-06 06:45:03 +08:00
|
|
|
m_selectedEntries.end(), false);
|
2011-06-27 06:07:19 +08:00
|
|
|
}
|
|
|
|
|
2011-01-28 20:28:54 +08:00
|
|
|
void PaletteView::selectColor(int index)
|
2008-03-15 09:54:45 +08:00
|
|
|
{
|
2012-05-03 10:09:34 +08:00
|
|
|
ASSERT(index >= 0 && index < Palette::MaxColors);
|
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;
|
|
|
|
m_selectedEntries[index] = true;
|
2007-09-19 07:57:02 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-06-27 06:07:19 +08:00
|
|
|
void PaletteView::getSelectedEntries(SelectedEntries& 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
|
|
|
}
|
|
|
|
|
2013-01-07 01:45:43 +08:00
|
|
|
app::Color PaletteView::getColorByPosition(int target_x, int target_y)
|
2011-02-24 06:29:57 +08:00
|
|
|
{
|
|
|
|
Palette* palette = get_current_palette();
|
2013-05-21 07:40:18 +08:00
|
|
|
gfx::Rect cpos = getChildrenBounds();
|
2012-05-03 10:09:34 +08:00
|
|
|
div_t d = div(Palette::MaxColors, m_columns);
|
2011-02-24 06:29:57 +08:00
|
|
|
int cols = m_columns;
|
|
|
|
int rows = d.quot + ((d.rem)? 1: 0);
|
|
|
|
int req_w, req_h;
|
|
|
|
int x, y, u, v;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
request_size(&req_w, &req_h);
|
|
|
|
|
2013-05-21 07:40:18 +08:00
|
|
|
y = cpos.y;
|
2011-02-24 06:29:57 +08:00
|
|
|
c = 0;
|
|
|
|
|
|
|
|
for (v=0; v<rows; v++) {
|
2013-05-21 07:40:18 +08:00
|
|
|
x = cpos.x;
|
2011-02-24 06:29:57 +08:00
|
|
|
|
|
|
|
for (u=0; u<cols; u++) {
|
|
|
|
if (c >= palette->size())
|
2012-01-06 06:45:03 +08:00
|
|
|
break;
|
2011-02-24 06:29:57 +08:00
|
|
|
|
|
|
|
if ((target_x >= x) && (target_x <= x+m_boxsize) &&
|
2012-01-06 06:45:03 +08:00
|
|
|
(target_y >= y) && (target_y <= y+m_boxsize))
|
2013-01-07 01:45:43 +08:00
|
|
|
return app::Color::fromIndex(c);
|
2011-02-24 06:29:57 +08:00
|
|
|
|
|
|
|
x += m_boxsize+this->child_spacing;
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
|
|
|
|
y += m_boxsize+this->child_spacing;
|
|
|
|
}
|
|
|
|
|
2013-01-07 01:45:43 +08:00
|
|
|
return app::Color::fromMask();
|
2011-02-24 06:29:57 +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
|
|
|
|
2013-04-05 08:53:29 +08:00
|
|
|
case kMouseDownMessage:
|
2010-04-25 23:03:25 +08:00
|
|
|
captureMouse();
|
2007-09-19 07:57:02 +08:00
|
|
|
/* continue... */
|
|
|
|
|
2013-04-05 08:53:29 +08:00
|
|
|
case kMouseMoveMessage: {
|
2013-07-29 08:17:07 +08:00
|
|
|
MouseMessage* mouseMsg = static_cast<MouseMessage*>(msg);
|
2013-05-21 07:40:18 +08:00
|
|
|
gfx::Rect cpos = getChildrenBounds();
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2011-02-24 06:29:57 +08:00
|
|
|
int req_w, req_h;
|
|
|
|
request_size(&req_w, &req_h);
|
|
|
|
|
2013-07-29 08:17:07 +08:00
|
|
|
int mouse_x = MID(cpos.x, mouseMsg->position().x, cpos.x+req_w-this->border_width.r-1);
|
|
|
|
int mouse_y = MID(cpos.y, mouseMsg->position().y, cpos.y+req_h-this->border_width.b-1);
|
2011-02-24 06:29:57 +08:00
|
|
|
|
2013-01-07 01:45:43 +08:00
|
|
|
app::Color color = getColorByPosition(mouse_x, mouse_y);
|
|
|
|
if (color.getType() == app::Color::IndexType) {
|
2012-01-06 06:45:03 +08:00
|
|
|
int idx = color.getIndex();
|
2011-06-27 06:07:19 +08:00
|
|
|
|
2012-07-10 00:20:58 +08:00
|
|
|
StatusBar::instance()->showColor(0, "", color, 255);
|
2011-02-24 06:29:57 +08:00
|
|
|
|
2012-01-06 06:45:03 +08:00
|
|
|
if (hasCapture() && idx != m_currentEntry) {
|
2013-07-29 08:17:07 +08:00
|
|
|
if (!msg->ctrlPressed())
|
2012-01-06 06:45:03 +08:00
|
|
|
clearSelection();
|
2011-02-24 06:29:57 +08:00
|
|
|
|
2013-07-29 08:17:07 +08:00
|
|
|
if (msg->shiftPressed())
|
2012-01-06 06:45:03 +08:00
|
|
|
selectRange(m_rangeAnchor, idx);
|
|
|
|
else
|
|
|
|
selectColor(idx);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2012-06-16 10:37:59 +08:00
|
|
|
// Emit signal
|
2014-11-26 08:51:06 +08:00
|
|
|
PaletteIndexChangeEvent ev(this, idx, mouseMsg->buttons());
|
|
|
|
IndexChange(ev);
|
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:
|
2010-04-25 23:03:25 +08:00
|
|
|
releaseMouse();
|
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);
|
2011-02-20 10:44:17 +08:00
|
|
|
if (view) {
|
2012-01-06 06:45:03 +08:00
|
|
|
gfx::Point scroll = view->getViewScroll();
|
2014-04-29 09:02:56 +08:00
|
|
|
scroll += static_cast<MouseMessage*>(msg)->wheelDelta() * 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();
|
2011-02-24 06:29:57 +08:00
|
|
|
break;
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
ui::Graphics* g = ev.getGraphics();
|
|
|
|
gfx::Rect bounds = getClientBounds();
|
|
|
|
div_t d = div(Palette::MaxColors, m_columns);
|
|
|
|
int cols = m_columns;
|
|
|
|
int rows = d.quot + ((d.rem)? 1: 0);
|
|
|
|
int x, y, u, v;
|
|
|
|
int c, color;
|
|
|
|
Palette* palette = get_current_palette();
|
2014-08-22 12:32:13 +08:00
|
|
|
gfx::Color bordercolor = gfx::rgba(255, 255, 255);
|
2014-04-14 03:26:00 +08:00
|
|
|
|
2014-06-29 03:10:39 +08:00
|
|
|
g->fillRect(gfx::rgba(0 , 0, 0), bounds);
|
2014-04-14 03:26:00 +08:00
|
|
|
|
|
|
|
y = bounds.y + this->border_width.t;
|
|
|
|
c = 0;
|
|
|
|
|
|
|
|
for (v=0; v<rows; v++) {
|
|
|
|
x = bounds.x + this->border_width.l;
|
|
|
|
|
|
|
|
for (u=0; u<cols; u++) {
|
|
|
|
if (c >= palette->size())
|
|
|
|
break;
|
|
|
|
|
2014-06-29 03:10:39 +08:00
|
|
|
color = gfx::rgba(
|
2014-04-14 03:26:00 +08:00
|
|
|
rgba_getr(palette->getEntry(c)),
|
|
|
|
rgba_getg(palette->getEntry(c)),
|
|
|
|
rgba_getb(palette->getEntry(c)));
|
|
|
|
|
|
|
|
g->fillRect(color, gfx::Rect(x, y, m_boxsize, m_boxsize));
|
|
|
|
|
|
|
|
if (m_selectedEntries[c]) {
|
|
|
|
const int max = Palette::MaxColors;
|
|
|
|
bool top = (c >= m_columns && c-m_columns >= 0 ? m_selectedEntries[c-m_columns]: false);
|
|
|
|
bool bottom = (c < max-m_columns && c+m_columns < max ? m_selectedEntries[c+m_columns]: false);
|
|
|
|
bool left = ((c%m_columns)>0 && c-1 >= 0 ? m_selectedEntries[c-1]: false);
|
|
|
|
bool right = ((c%m_columns)<m_columns-1 && c+1 < max ? m_selectedEntries[c+1]: false);
|
|
|
|
|
|
|
|
if (!top ) g->drawHLine(bordercolor, x-1, y-1, m_boxsize+2);
|
|
|
|
if (!bottom) g->drawHLine(bordercolor, x-1, y+m_boxsize, m_boxsize+2);
|
|
|
|
if (!left ) g->drawVLine(bordercolor, x-1, y-1, m_boxsize+2);
|
|
|
|
if (!right ) g->drawVLine(bordercolor, x+m_boxsize, y-1, m_boxsize+2);
|
|
|
|
}
|
|
|
|
|
|
|
|
x += m_boxsize+this->child_spacing;
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
|
|
|
|
y += m_boxsize+this->child_spacing;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 =
|
|
|
|
(view->getViewportBounds().w-this->child_spacing*2)
|
|
|
|
/ (m_boxsize+this->child_spacing);
|
|
|
|
setColumns(MID(1, columns, Palette::MaxColors));
|
|
|
|
}
|
|
|
|
m_isUpdatingColumns = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget::onResize(ev);
|
|
|
|
}
|
|
|
|
|
2012-09-27 05:34:52 +08:00
|
|
|
void PaletteView::onPreferredSize(ui::PreferredSizeEvent& ev)
|
|
|
|
{
|
|
|
|
gfx::Size sz;
|
|
|
|
request_size(&sz.w, &sz.h);
|
|
|
|
ev.setPreferredSize(sz);
|
|
|
|
}
|
|
|
|
|
2011-01-28 20:28:54 +08:00
|
|
|
void PaletteView::request_size(int* w, int* h)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2012-05-03 10:09:34 +08:00
|
|
|
div_t d = div(Palette::MaxColors, m_columns);
|
2010-04-11 04:01:56 +08:00
|
|
|
int cols = m_columns;
|
2007-09-19 07:57:02 +08:00
|
|
|
int rows = d.quot + ((d.rem)? 1: 0);
|
|
|
|
|
2010-04-11 04:01:56 +08:00
|
|
|
*w = this->border_width.l + this->border_width.r +
|
2011-02-20 09:41:09 +08:00
|
|
|
+ cols*m_boxsize + (cols-1)*this->child_spacing;
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2010-04-11 04:01:56 +08:00
|
|
|
*h = this->border_width.t + this->border_width.b +
|
2011-02-20 09:41:09 +08:00
|
|
|
+ rows*m_boxsize + (rows-1)*this->child_spacing;
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2011-02-21 05:35:21 +08:00
|
|
|
gfx::Rect vp = view->getViewportBounds();
|
|
|
|
gfx::Point scroll;
|
|
|
|
int x, y, cols;
|
|
|
|
div_t d;
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2011-02-21 05:35:21 +08:00
|
|
|
scroll = view->getViewScroll();
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2012-05-03 10:09:34 +08:00
|
|
|
d = div(Palette::MaxColors, m_columns);
|
2011-02-21 05:35:21 +08:00
|
|
|
cols = m_columns;
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2011-02-21 05:35:21 +08:00
|
|
|
y = (m_boxsize+this->child_spacing) * (color / cols);
|
|
|
|
x = (m_boxsize+this->child_spacing) * (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()
|
|
|
|
{
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
} // namespace app
|