2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
2020-03-02 10:42:08 +08:00
|
|
|
// Copyright (C) 2018-2020 Igara Studio S.A.
|
2018-03-29 10:39:07 +08:00
|
|
|
// Copyright (C) 2001-2018 David Capello
|
2015-02-12 23:16:25 +08:00
|
|
|
//
|
2016-08-27 04:02:58 +08:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
// the End-User License Agreement for Aseprite.
|
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
|
|
|
|
2018-03-29 10:39:07 +08:00
|
|
|
#include "app/modules/gfx.h"
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/app.h"
|
2018-10-19 02:29:16 +08:00
|
|
|
#include "app/color_spaces.h"
|
2010-09-26 03:22:32 +08:00
|
|
|
#include "app/color_utils.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/console.h"
|
2021-09-01 23:02:29 +08:00
|
|
|
#include "app/modules/editors.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/modules/gui.h"
|
|
|
|
#include "app/modules/palettes.h"
|
2020-08-22 05:07:37 +08:00
|
|
|
#include "app/site.h"
|
2014-06-29 03:10:39 +08:00
|
|
|
#include "app/ui/editor/editor.h"
|
|
|
|
#include "app/ui/skin/skin_theme.h"
|
2020-08-22 05:07:37 +08:00
|
|
|
#include "app/util/conversion_to_surface.h"
|
2017-05-31 00:52:53 +08:00
|
|
|
#include "doc/blend_funcs.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/image.h"
|
|
|
|
#include "doc/palette.h"
|
2018-03-29 10:39:07 +08:00
|
|
|
#include "gfx/color.h"
|
2017-05-31 00:52:53 +08:00
|
|
|
#include "gfx/point.h"
|
|
|
|
#include "gfx/rect.h"
|
2018-08-09 23:58:43 +08:00
|
|
|
#include "os/surface.h"
|
2020-08-22 05:07:37 +08:00
|
|
|
#include "os/system.h"
|
2018-03-29 10:39:07 +08:00
|
|
|
#include "ui/intern.h"
|
|
|
|
#include "ui/system.h"
|
|
|
|
#include "ui/theme.h"
|
2010-03-28 04:03:25 +08:00
|
|
|
|
2020-04-08 23:03:32 +08:00
|
|
|
#include <algorithm>
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
|
|
|
|
|
|
|
using namespace app::skin;
|
2010-09-26 03:22:32 +08:00
|
|
|
using namespace gfx;
|
|
|
|
|
2017-05-31 00:52:53 +08:00
|
|
|
namespace {
|
|
|
|
|
2021-09-01 23:11:02 +08:00
|
|
|
gfx::Color gridColor1()
|
|
|
|
{
|
|
|
|
if (ui::is_ui_thread() && current_editor)
|
|
|
|
return color_utils::color_for_ui(current_editor->docPref().bg.color1());
|
|
|
|
else
|
|
|
|
return gfx::rgba(128, 128, 128);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Color gridColor2()
|
|
|
|
{
|
|
|
|
if (ui::is_ui_thread() && current_editor)
|
|
|
|
return color_utils::color_for_ui(current_editor->docPref().bg.color2());
|
|
|
|
else
|
|
|
|
return gfx::rgba(192, 192, 192);
|
|
|
|
}
|
2017-05-31 00:52:53 +08:00
|
|
|
|
2019-04-12 01:29:20 +08:00
|
|
|
void draw_checked_grid(ui::Graphics* g,
|
|
|
|
const gfx::Rect& rc,
|
|
|
|
const gfx::Size& tile,
|
|
|
|
const gfx::Color c1,
|
|
|
|
const gfx::Color c2)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2013-12-30 08:12:23 +08:00
|
|
|
if (tile.w < 1 || tile.h < 1)
|
2012-08-03 06:50:27 +08:00
|
|
|
return;
|
|
|
|
|
2013-12-30 08:12:23 +08:00
|
|
|
int x, y, u, v;
|
2017-05-31 00:38:40 +08:00
|
|
|
|
2007-09-19 07:57:02 +08:00
|
|
|
u = 0;
|
|
|
|
v = 0;
|
2013-12-30 08:12:23 +08:00
|
|
|
for (y=rc.y; y<rc.y2()-tile.h; y+=tile.h) {
|
|
|
|
for (x=rc.x; x<rc.x2()-tile.w; x+=tile.w)
|
|
|
|
g->fillRect(((u++)&1)? c1: c2, gfx::Rect(x, y, tile.w, tile.h));
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2013-12-30 08:12:23 +08:00
|
|
|
if (x < rc.x2())
|
|
|
|
g->fillRect(((u++)&1)? c1: c2, gfx::Rect(x, y, rc.x2()-x, tile.h));
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
u = (++v);
|
|
|
|
}
|
|
|
|
|
2013-12-30 08:12:23 +08:00
|
|
|
if (y < rc.y2()) {
|
|
|
|
for (x=rc.x; x<rc.x2()-tile.w; x+=tile.w)
|
|
|
|
g->fillRect(((u++)&1)? c1: c2, gfx::Rect(x, y, tile.w, rc.y2()-y));
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2013-12-30 08:12:23 +08:00
|
|
|
if (x < rc.x2())
|
|
|
|
g->fillRect(((u++)&1)? c1: c2, gfx::Rect(x, y, rc.x2()-x, rc.y2()-y));
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-12 01:29:20 +08:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
void draw_checked_grid(ui::Graphics* g,
|
|
|
|
const gfx::Rect& rc,
|
|
|
|
const gfx::Size& tile)
|
|
|
|
{
|
2021-09-01 23:11:02 +08:00
|
|
|
draw_checked_grid(g, rc, tile, gridColor1(), gridColor2());
|
2019-04-12 01:29:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void draw_checked_grid(ui::Graphics* g,
|
|
|
|
const gfx::Rect& rc,
|
|
|
|
const gfx::Size& tile,
|
|
|
|
DocumentPreferences& docPref)
|
|
|
|
{
|
2021-09-01 23:11:02 +08:00
|
|
|
draw_checked_grid(g, rc, tile, gridColor1(), gridColor2());
|
2019-04-12 01:29:20 +08:00
|
|
|
}
|
|
|
|
|
2016-02-25 06:37:20 +08:00
|
|
|
void draw_color(ui::Graphics* g,
|
|
|
|
const Rect& rc,
|
|
|
|
const app::Color& _color,
|
|
|
|
const doc::ColorMode colorMode)
|
2008-03-23 02:43:56 +08:00
|
|
|
{
|
2013-12-30 08:12:23 +08:00
|
|
|
if (rc.w < 1 || rc.h < 1)
|
2013-11-16 02:46:54 +08:00
|
|
|
return;
|
|
|
|
|
2016-02-25 06:37:20 +08:00
|
|
|
app::Color color = _color;
|
2018-10-19 02:29:16 +08:00
|
|
|
const int alpha = color.getAlpha();
|
2016-02-25 06:37:20 +08:00
|
|
|
|
2018-10-19 02:29:16 +08:00
|
|
|
// Color space conversion
|
|
|
|
auto convertColor = convert_from_current_to_screen_color_space();
|
2008-03-23 02:43:56 +08:00
|
|
|
|
2015-07-01 04:36:37 +08:00
|
|
|
if (alpha < 255) {
|
|
|
|
if (rc.w == rc.h)
|
2019-04-12 01:29:20 +08:00
|
|
|
draw_checked_grid(g, rc, gfx::Size(rc.w/2, rc.h/2));
|
2015-07-01 04:36:37 +08:00
|
|
|
else
|
2019-04-12 01:29:20 +08:00
|
|
|
draw_checked_grid(g, rc, gfx::Size(rc.w/4, rc.h/2));
|
2010-06-25 10:25:30 +08:00
|
|
|
}
|
2010-06-02 09:41:26 +08:00
|
|
|
|
2015-07-01 04:36:37 +08:00
|
|
|
if (alpha > 0) {
|
2016-02-25 06:37:20 +08:00
|
|
|
if (colorMode == doc::ColorMode::GRAYSCALE) {
|
|
|
|
color = app::Color::fromGray(
|
|
|
|
color.getGray(),
|
|
|
|
color.getAlpha());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (color.getType() == app::Color::IndexType) {
|
2015-07-01 04:36:37 +08:00
|
|
|
int index = color.getIndex();
|
|
|
|
|
|
|
|
if (index >= 0 && index < get_current_palette()->size()) {
|
2018-10-19 02:29:16 +08:00
|
|
|
g->fillRect(convertColor(color_utils::color_for_ui(color)), rc);
|
2015-07-01 04:36:37 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
g->fillRect(gfx::rgba(0, 0, 0), rc);
|
|
|
|
g->drawLine(gfx::rgba(255, 255, 255),
|
|
|
|
gfx::Point(rc.x+rc.w-2, rc.y+1),
|
|
|
|
gfx::Point(rc.x+1, rc.y+rc.h-2));
|
|
|
|
}
|
2010-06-02 09:41:26 +08:00
|
|
|
}
|
2016-02-25 06:37:20 +08:00
|
|
|
else {
|
2018-10-19 02:29:16 +08:00
|
|
|
g->fillRect(convertColor(color_utils::color_for_ui(color)), rc);
|
2016-02-25 06:37:20 +08:00
|
|
|
}
|
2008-03-23 02:43:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-30 08:12:23 +08:00
|
|
|
void draw_color_button(ui::Graphics* g,
|
2016-02-25 06:37:20 +08:00
|
|
|
const Rect& rc,
|
|
|
|
const app::Color& color,
|
|
|
|
const doc::ColorMode colorMode,
|
|
|
|
const bool hot,
|
|
|
|
const bool drag)
|
2008-03-23 02:43:56 +08:00
|
|
|
{
|
2015-08-05 06:38:52 +08:00
|
|
|
SkinTheme* theme = SkinTheme::instance();
|
2014-11-26 09:33:45 +08:00
|
|
|
int scale = ui::guiscale();
|
2008-03-23 02:43:56 +08:00
|
|
|
|
2010-03-28 06:41:39 +08:00
|
|
|
// Draw background (the color)
|
2013-12-30 08:12:23 +08:00
|
|
|
draw_color(g,
|
2016-02-25 06:37:20 +08:00
|
|
|
Rect(rc.x+1*scale,
|
|
|
|
rc.y+1*scale,
|
|
|
|
rc.w-2*scale,
|
|
|
|
rc.h-2*scale),
|
|
|
|
color,
|
|
|
|
colorMode);
|
2010-03-28 06:41:39 +08:00
|
|
|
|
|
|
|
// Draw opaque border
|
2015-08-05 06:38:52 +08:00
|
|
|
theme->drawRect(
|
|
|
|
g, rc,
|
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
|
|
|
theme->parts.colorbar0()->bitmapNW(),
|
|
|
|
theme->parts.colorbar0()->bitmapN(),
|
|
|
|
theme->parts.colorbar1()->bitmapNE(),
|
|
|
|
theme->parts.colorbar1()->bitmapE(),
|
|
|
|
theme->parts.colorbar3()->bitmapSE(),
|
|
|
|
theme->parts.colorbar2()->bitmapS(),
|
|
|
|
theme->parts.colorbar2()->bitmapSW(),
|
|
|
|
theme->parts.colorbar0()->bitmapW());
|
2008-03-23 02:43:56 +08:00
|
|
|
|
2020-08-22 05:07:37 +08:00
|
|
|
// Draw hot
|
|
|
|
if (hot) {
|
|
|
|
theme->drawRect(
|
|
|
|
g, gfx::Rect(rc.x, rc.y, rc.w, rc.h-1 - 1*scale),
|
|
|
|
theme->parts.colorbarSelection().get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_tile(ui::Graphics* g,
|
|
|
|
const Rect& rc,
|
|
|
|
const Site& site,
|
|
|
|
doc::tile_t tile)
|
|
|
|
{
|
|
|
|
if (rc.w < 1 || rc.h < 1)
|
|
|
|
return;
|
|
|
|
|
2020-11-10 06:29:35 +08:00
|
|
|
draw_checked_grid(g, rc, gfx::Size(rc.w/2, rc.h/2));
|
2020-08-22 05:07:37 +08:00
|
|
|
|
2020-10-31 03:33:34 +08:00
|
|
|
if (tile == doc::notile)
|
2020-08-22 05:07:37 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
doc::Tileset* ts = site.tileset();
|
|
|
|
if (!ts)
|
|
|
|
return;
|
|
|
|
|
|
|
|
doc::tile_index ti = doc::tile_geti(tile);
|
|
|
|
if (ti < 0 || ti >= ts->size())
|
|
|
|
return;
|
|
|
|
|
|
|
|
doc::ImageRef tileImage = ts->get(ti);
|
|
|
|
if (!tileImage)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const int w = tileImage->width();
|
|
|
|
const int h = tileImage->height();
|
|
|
|
os::SurfaceRef surface = os::instance()->makeRgbaSurface(w, h);
|
|
|
|
convert_image_to_surface(tileImage.get(), get_current_palette(),
|
|
|
|
surface.get(), 0, 0, 0, 0, w, h);
|
|
|
|
g->drawRgbaSurface(surface.get(), gfx::Rect(0, 0, w, h), rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_tile_button(ui::Graphics* g,
|
|
|
|
const gfx::Rect& rc,
|
|
|
|
const Site& site,
|
|
|
|
doc::tile_t tile,
|
|
|
|
const bool hot,
|
|
|
|
const bool drag)
|
|
|
|
{
|
|
|
|
SkinTheme* theme = SkinTheme::instance();
|
|
|
|
int scale = ui::guiscale();
|
|
|
|
|
|
|
|
// Draw background (the tile)
|
|
|
|
draw_tile(g,
|
|
|
|
Rect(rc.x+1*scale,
|
|
|
|
rc.y+1*scale,
|
|
|
|
rc.w-2*scale,
|
|
|
|
rc.h-2*scale),
|
|
|
|
site, tile);
|
|
|
|
|
|
|
|
// Draw opaque border
|
|
|
|
theme->drawRect(
|
|
|
|
g, rc,
|
|
|
|
theme->parts.colorbar0()->bitmapNW(),
|
|
|
|
theme->parts.colorbar0()->bitmapN(),
|
|
|
|
theme->parts.colorbar1()->bitmapNE(),
|
|
|
|
theme->parts.colorbar1()->bitmapE(),
|
|
|
|
theme->parts.colorbar3()->bitmapSE(),
|
|
|
|
theme->parts.colorbar2()->bitmapS(),
|
|
|
|
theme->parts.colorbar2()->bitmapSW(),
|
|
|
|
theme->parts.colorbar0()->bitmapW());
|
|
|
|
|
2010-03-28 06:41:39 +08:00
|
|
|
// Draw hot
|
|
|
|
if (hot) {
|
2015-08-05 06:38:52 +08:00
|
|
|
theme->drawRect(
|
|
|
|
g, gfx::Rect(rc.x, rc.y, rc.w, rc.h-1 - 1*scale),
|
2017-03-14 05:13:38 +08:00
|
|
|
theme->parts.colorbarSelection().get());
|
2008-09-28 02:04:55 +08:00
|
|
|
}
|
2008-03-23 02:43:56 +08:00
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
2017-05-31 00:52:53 +08:00
|
|
|
void draw_alpha_slider(ui::Graphics* g,
|
|
|
|
const gfx::Rect& rc,
|
|
|
|
const app::Color& color)
|
|
|
|
{
|
2020-04-08 23:03:32 +08:00
|
|
|
const int xmax = std::max(1, rc.w-1);
|
2017-05-31 00:52:53 +08:00
|
|
|
const doc::color_t c =
|
|
|
|
(color.getType() != app::Color::MaskType ?
|
|
|
|
doc::rgba(color.getRed(),
|
|
|
|
color.getGreen(),
|
|
|
|
color.getBlue(), 255): 0);
|
|
|
|
|
|
|
|
for (int x=0; x<rc.w; ++x) {
|
|
|
|
const int a = (255 * x / xmax);
|
2021-09-01 23:11:02 +08:00
|
|
|
const doc::color_t c1 = doc::rgba_blender_normal(gridColor1(), c, a);
|
|
|
|
const doc::color_t c2 = doc::rgba_blender_normal(gridColor2(), c, a);
|
2017-05-31 00:52:53 +08:00
|
|
|
const int mid = rc.h/2;
|
|
|
|
const int odd = (x / rc.h) & 1;
|
|
|
|
g->drawVLine(
|
|
|
|
app::color_utils::color_for_ui(app::Color::fromImage(IMAGE_RGB, odd ? c2: c1)),
|
|
|
|
rc.x+x, rc.y, mid);
|
|
|
|
g->drawVLine(
|
|
|
|
app::color_utils::color_for_ui(app::Color::fromImage(IMAGE_RGB, odd ? c1: c2)),
|
|
|
|
rc.x+x, rc.y+mid, rc.h-mid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-29 10:39:07 +08:00
|
|
|
// TODO this code is exactly the same as draw_alpha_slider() with a ui::Graphics
|
2018-08-09 23:58:43 +08:00
|
|
|
void draw_alpha_slider(os::Surface* s,
|
2018-03-29 10:39:07 +08:00
|
|
|
const gfx::Rect& rc,
|
|
|
|
const app::Color& color)
|
|
|
|
{
|
2020-04-08 23:03:32 +08:00
|
|
|
const int xmax = std::max(1, rc.w-1);
|
2018-03-29 10:39:07 +08:00
|
|
|
const doc::color_t c =
|
|
|
|
(color.getType() != app::Color::MaskType ?
|
|
|
|
doc::rgba(color.getRed(),
|
|
|
|
color.getGreen(),
|
|
|
|
color.getBlue(), 255): 0);
|
|
|
|
|
2020-03-02 10:42:08 +08:00
|
|
|
os::Paint paint;
|
2018-03-29 10:39:07 +08:00
|
|
|
for (int x=0; x<rc.w; ++x) {
|
|
|
|
const int a = (255 * x / xmax);
|
2021-09-01 23:11:02 +08:00
|
|
|
const doc::color_t c1 = doc::rgba_blender_normal(gridColor1(), c, a);
|
|
|
|
const doc::color_t c2 = doc::rgba_blender_normal(gridColor2(), c, a);
|
2018-03-29 10:39:07 +08:00
|
|
|
const int mid = rc.h/2;
|
|
|
|
const int odd = (x / rc.h) & 1;
|
2020-03-02 10:42:08 +08:00
|
|
|
|
|
|
|
paint.color(app::color_utils::color_for_ui(app::Color::fromImage(IMAGE_RGB, odd ? c2: c1)));
|
|
|
|
s->drawRect(gfx::Rect(rc.x+x, rc.y, 1, mid), paint);
|
|
|
|
|
|
|
|
paint.color(app::color_utils::color_for_ui(app::Color::fromImage(IMAGE_RGB, odd ? c1: c2)));
|
|
|
|
s->drawRect(gfx::Rect(rc.x+x, rc.y+mid, 1, rc.h-mid), paint);
|
2018-03-29 10:39:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
} // namespace app
|