2013-08-09 08:01:20 +08:00
|
|
|
/* Aseprite
|
2013-01-27 23:13:13 +08:00
|
|
|
* Copyright (C) 2001-2013 David Capello
|
2007-09-19 07:57:02 +08:00
|
|
|
*
|
|
|
|
* 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
|
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
|
|
|
|
|
|
|
#include <allegro.h>
|
|
|
|
#include <allegro/internal/aintern.h>
|
|
|
|
|
2014-06-29 03:10:39 +08:00
|
|
|
#include "gfx/color.h"
|
2012-06-18 09:49:58 +08:00
|
|
|
#include "ui/intern.h"
|
|
|
|
#include "ui/system.h"
|
|
|
|
#include "ui/theme.h"
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/app.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"
|
|
|
|
#include "app/ini_file.h"
|
|
|
|
#include "app/modules/gfx.h"
|
|
|
|
#include "app/modules/gui.h"
|
|
|
|
#include "app/modules/palettes.h"
|
2014-06-29 03:10:39 +08:00
|
|
|
#include "app/ui/editor/editor.h"
|
|
|
|
#include "app/ui/skin/skin_theme.h"
|
|
|
|
#include "gfx/point.h"
|
|
|
|
#include "gfx/rect.h"
|
2008-03-23 02:43:56 +08:00
|
|
|
#include "raster/blend.h"
|
|
|
|
#include "raster/image.h"
|
2010-06-02 09:41:26 +08:00
|
|
|
#include "raster/palette.h"
|
2010-03-28 04:03:25 +08:00
|
|
|
|
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;
|
|
|
|
|
2007-09-19 07:57:02 +08:00
|
|
|
void dotted_mode(int offset)
|
|
|
|
{
|
|
|
|
/* these pattern were taken from The GIMP:
|
|
|
|
gimp-1.3.11/app/display/gimpdisplayshell-marching-ants.h */
|
|
|
|
static int pattern_data[8][8] = {
|
|
|
|
{
|
|
|
|
0xF0, /* ####---- */
|
|
|
|
0xE1, /* ###----# */
|
|
|
|
0xC3, /* ##----## */
|
|
|
|
0x87, /* #----### */
|
|
|
|
0x0F, /* ----#### */
|
|
|
|
0x1E, /* ---####- */
|
|
|
|
0x3C, /* --####-- */
|
|
|
|
0x78, /* -####--- */
|
|
|
|
},
|
|
|
|
{
|
|
|
|
0xE1, /* ###----# */
|
|
|
|
0xC3, /* ##----## */
|
|
|
|
0x87, /* #----### */
|
|
|
|
0x0F, /* ----#### */
|
|
|
|
0x1E, /* ---####- */
|
|
|
|
0x3C, /* --####-- */
|
|
|
|
0x78, /* -####--- */
|
|
|
|
0xF0, /* ####---- */
|
|
|
|
},
|
|
|
|
{
|
|
|
|
0xC3, /* ##----## */
|
|
|
|
0x87, /* #----### */
|
|
|
|
0x0F, /* ----#### */
|
|
|
|
0x1E, /* ---####- */
|
|
|
|
0x3C, /* --####-- */
|
|
|
|
0x78, /* -####--- */
|
|
|
|
0xF0, /* ####---- */
|
|
|
|
0xE1, /* ###----# */
|
|
|
|
},
|
|
|
|
{
|
|
|
|
0x87, /* #----### */
|
|
|
|
0x0F, /* ----#### */
|
|
|
|
0x1E, /* ---####- */
|
|
|
|
0x3C, /* --####-- */
|
|
|
|
0x78, /* -####--- */
|
|
|
|
0xF0, /* ####---- */
|
|
|
|
0xE1, /* ###----# */
|
|
|
|
0xC3, /* ##----## */
|
|
|
|
},
|
|
|
|
{
|
|
|
|
0x0F, /* ----#### */
|
|
|
|
0x1E, /* ---####- */
|
|
|
|
0x3C, /* --####-- */
|
|
|
|
0x78, /* -####--- */
|
|
|
|
0xF0, /* ####---- */
|
|
|
|
0xE1, /* ###----# */
|
|
|
|
0xC3, /* ##----## */
|
|
|
|
0x87, /* #----### */
|
|
|
|
},
|
|
|
|
{
|
|
|
|
0x1E, /* ---####- */
|
|
|
|
0x3C, /* --####-- */
|
|
|
|
0x78, /* -####--- */
|
|
|
|
0xF0, /* ####---- */
|
|
|
|
0xE1, /* ###----# */
|
|
|
|
0xC3, /* ##----## */
|
|
|
|
0x87, /* #----### */
|
|
|
|
0x0F, /* ----#### */
|
|
|
|
},
|
|
|
|
{
|
|
|
|
0x3C, /* --####-- */
|
|
|
|
0x78, /* -####--- */
|
|
|
|
0xF0, /* ####---- */
|
|
|
|
0xE1, /* ###----# */
|
|
|
|
0xC3, /* ##----## */
|
|
|
|
0x87, /* #----### */
|
|
|
|
0x0F, /* ----#### */
|
|
|
|
0x1E, /* ---####- */
|
|
|
|
},
|
|
|
|
{
|
|
|
|
0x78, /* -####--- */
|
|
|
|
0xF0, /* ####---- */
|
|
|
|
0xE1, /* ###----# */
|
|
|
|
0xC3, /* ##----## */
|
|
|
|
0x87, /* #----### */
|
|
|
|
0x0F, /* ----#### */
|
|
|
|
0x1E, /* ---####- */
|
|
|
|
0x3C, /* --####-- */
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2009-10-16 10:26:28 +08:00
|
|
|
static BITMAP* pattern = NULL;
|
2007-09-19 07:57:02 +08:00
|
|
|
int x, y, fg, bg;
|
|
|
|
|
|
|
|
if (offset < 0) {
|
|
|
|
if (pattern) {
|
2008-01-07 23:10:17 +08:00
|
|
|
destroy_bitmap(pattern);
|
2007-09-19 07:57:02 +08:00
|
|
|
pattern = NULL;
|
|
|
|
}
|
2008-01-07 23:10:17 +08:00
|
|
|
drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
|
2007-09-19 07:57:02 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pattern)
|
2008-01-07 23:10:17 +08:00
|
|
|
pattern = create_bitmap(8, 8);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
offset = 7 - (offset & 7);
|
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
bg = makecol(0, 0, 0);
|
|
|
|
fg = makecol(255, 255, 255);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
clear_bitmap(pattern);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
for (y=0; y<8; y++)
|
|
|
|
for (x=0; x<8; x++)
|
2008-01-07 23:10:17 +08:00
|
|
|
putpixel(pattern, x, y,
|
2012-01-06 06:45:03 +08:00
|
|
|
(pattern_data[offset][y] & (1<<(7-x)))? fg: bg);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
drawing_mode(DRAW_MODE_COPY_PATTERN, pattern, 0, 0);
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2013-12-30 08:12:23 +08:00
|
|
|
static void rectgrid(ui::Graphics* g, const gfx::Rect& rc, const gfx::Size& tile)
|
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;
|
2014-06-29 03:10:39 +08:00
|
|
|
gfx::Color c1 = gfx::rgba(128, 128, 128);
|
|
|
|
gfx::Color c2 = gfx::rgba(192, 192, 192);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-02 05:15:11 +08:00
|
|
|
static void draw_color(ui::Graphics* g, const Rect& rc, const app::Color& color)
|
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;
|
|
|
|
|
2013-01-07 01:45:43 +08:00
|
|
|
app::Color::Type type = color.getType();
|
2008-03-23 02:43:56 +08:00
|
|
|
|
2013-01-07 01:45:43 +08:00
|
|
|
if (type == app::Color::MaskType) {
|
2013-12-30 08:12:23 +08:00
|
|
|
rectgrid(g, rc, gfx::Size(rc.w/4, rc.h/2));
|
2010-06-25 10:25:30 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-01-07 01:45:43 +08:00
|
|
|
else if (type == app::Color::IndexType) {
|
2010-08-25 11:26:37 +08:00
|
|
|
int index = color.getIndex();
|
2010-06-02 09:41:26 +08:00
|
|
|
|
|
|
|
if (index >= 0 && index < get_current_palette()->size()) {
|
2013-12-30 08:12:23 +08:00
|
|
|
g->fillRect(color_utils::color_for_ui(color), rc);
|
2010-06-02 09:41:26 +08:00
|
|
|
}
|
|
|
|
else {
|
2014-06-29 03:10:39 +08:00
|
|
|
g->fillRect(gfx::rgba(0, 0, 0), rc);
|
|
|
|
g->drawLine(gfx::rgba(255, 255, 255),
|
2013-12-30 08:12:23 +08:00
|
|
|
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
|
|
|
}
|
2008-03-23 02:43:56 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-02 05:15:11 +08:00
|
|
|
g->fillRect(color_utils::color_for_ui(color), rc);
|
2008-03-23 02:43:56 +08:00
|
|
|
}
|
|
|
|
|
2013-12-30 08:12:23 +08:00
|
|
|
void draw_color_button(ui::Graphics* g,
|
2014-06-02 05:15:11 +08:00
|
|
|
const Rect& rc, const app::Color& color,
|
|
|
|
bool hot, bool drag)
|
2008-03-23 02:43:56 +08:00
|
|
|
{
|
2012-06-18 09:02:54 +08:00
|
|
|
SkinTheme* theme = (SkinTheme*)ui::CurrentTheme::get();
|
|
|
|
int scale = ui::jguiscale();
|
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,
|
|
|
|
Rect(rc.x+1*scale,
|
|
|
|
rc.y+1*scale,
|
2014-06-02 05:15:11 +08:00
|
|
|
rc.w-2*scale,
|
|
|
|
rc.h-2*scale), color);
|
2010-03-28 06:41:39 +08:00
|
|
|
|
|
|
|
// Draw opaque border
|
|
|
|
{
|
|
|
|
int parts[8] = {
|
2014-06-02 05:15:11 +08:00
|
|
|
PART_COLORBAR_0_NW,
|
|
|
|
PART_COLORBAR_0_N,
|
|
|
|
PART_COLORBAR_1_NE,
|
|
|
|
PART_COLORBAR_1_E,
|
|
|
|
PART_COLORBAR_3_SE,
|
|
|
|
PART_COLORBAR_2_S,
|
|
|
|
PART_COLORBAR_2_SW,
|
|
|
|
PART_COLORBAR_0_W
|
2010-03-28 06:41:39 +08:00
|
|
|
};
|
2013-12-30 08:12:23 +08:00
|
|
|
theme->draw_bounds_array(g, rc, parts);
|
2008-03-23 02:43:56 +08:00
|
|
|
}
|
|
|
|
|
2010-03-28 06:41:39 +08:00
|
|
|
// Draw hot
|
|
|
|
if (hot) {
|
2013-12-30 08:12:23 +08:00
|
|
|
theme->draw_bounds_nw(g,
|
2014-06-02 05:15:11 +08:00
|
|
|
gfx::Rect(rc.x, rc.y, rc.w, rc.h-1 - 1*scale),
|
2013-12-30 08:12:23 +08:00
|
|
|
PART_COLORBAR_BORDER_HOTFG_NW);
|
2008-09-28 02:04:55 +08:00
|
|
|
}
|
2008-03-23 02:43:56 +08:00
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|