1
0
mirror of https://github.com/aseprite/aseprite.git synced 2025-03-23 13:20:50 +00:00

Added "checked background configuration".

Now you can configure size and color of the checked background
used in transparent sprites.
This commit is contained in:
David Capello 2010-04-25 21:29:50 -03:00
parent 9c63b4f1ba
commit befd81c63b
5 changed files with 259 additions and 56 deletions

@ -3,20 +3,50 @@
<jinete>
<window text="Options" name="options">
<box vertical="true">
<box vertical="true">
<box horizontal="true">
<box vertical="true">
<!-- Editor -->
<separator text="Editor:" horizontal="true" />
<check text="Smooth auto-scroll" name="smooth" />
<check text="2 Click Movement" name="move_click2" />
<check text="2 Click Drawing" name="draw_click2" />
<!-- Undo -->
<separator text="Undo:" horizontal="true" />
<box horizontal="true">
<label text="Undo size limit:" />
<label text="Undo Limit:" />
<entry name="undo_size_limit" maxsize="4" tooltip="Limit of memory to be used&#10;for undo information per sprite.&#10;Specified in megabytes." />
<label text="MB" />
</box>
</box>
<separator vertical="true" />
<box vertical="true">
<!-- Checked Background -->
<separator text="Checked Background:" horizontal="true" />
<box horizontal="true">
<label text="Size:" />
<combobox name="checked_bg_size" expansive="true" />
</box>
<check text="Apply Zoom" name="checked_bg_zoom" />
<grid columns="2">
<label text="Color 1" />
<box horizontal="true" name="checked_bg_color1_box" />
<label text="Color 2" />
<box horizontal="true" name="checked_bg_color2_box" />
</grid>
<button name="checked_bg_reset" text="Reset" />
</box>
</box>
<separator horizontal="true" />
<box horizontal="true">
<box horizontal="true" expansive="true" />
<box horizontal="true" homogeneous="true">

@ -60,6 +60,7 @@
#include "ui_context.h"
#include "util/boundary.h"
#include "util/recscr.h"
#include "util/render.h"
#include "widgets/colbar.h"
#include "widgets/editor.h"
#include "widgets/menuitem.h"
@ -124,6 +125,9 @@ App::App()
// init editor cursor
Editor::editor_cursor_init();
// Load RenderEngine configuration
RenderEngine::loadConfig();
/* custom default palette? */
if (palette_filename) {
PRINTF("Loading custom palette file: %s\n", palette_filename);

@ -22,18 +22,24 @@
#include "jinete/jinete.h"
#include "app.h"
#include "commands/command.h"
#include "core/cfg.h"
#include "modules/editors.h"
#include "modules/gui.h"
static JWidget slider_x, slider_y, check_lockmouse;
static bool slider_mouse_hook(JWidget widget, void *data);
#include "util/render.h"
#include "widgets/colbut.h"
//////////////////////////////////////////////////////////////////////
// options
// TODO make these variables member of OptionsCommand
static JWidget checked_bg, checked_bg_zoom;
static JWidget checked_bg_color1, checked_bg_color2;
// TODO make this a member of OptionsCommand when button signal is converted to Vaca::Signal
static bool checked_bg_reset_hook(JWidget widget, void *data);
class OptionsCommand : public Command
{
public:
@ -55,7 +61,9 @@ void OptionsCommand::execute(Context* context)
{
JWidget check_smooth;
JWidget button_ok;
JWidget move_click2, draw_click2, killer;
JWidget move_click2, draw_click2;
JWidget checked_bg_reset;
JWidget checked_bg_color1_box, checked_bg_color2_box;
JWidget undo_size_limit;
/* load the window widget */
@ -64,38 +72,84 @@ void OptionsCommand::execute(Context* context)
"smooth", &check_smooth,
"move_click2", &move_click2,
"draw_click2", &draw_click2,
"checked_bg_size", &checked_bg,
"checked_bg_zoom", &checked_bg_zoom,
"checked_bg_color1_box", &checked_bg_color1_box,
"checked_bg_color2_box", &checked_bg_color2_box,
"checked_bg_reset", &checked_bg_reset,
"undo_size_limit", &undo_size_limit,
"button_ok", &button_ok, NULL);
if (get_config_bool("Options", "MoveClick2", false))
jwidget_select(move_click2);
if (get_config_bool("Options", "DrawClick2", false))
jwidget_select(draw_click2);
if (get_config_bool("Options", "MoveSmooth", true))
jwidget_select(check_smooth);
// Checked background size
jcombobox_add_string(checked_bg, "16x16", NULL);
jcombobox_add_string(checked_bg, "8x8", NULL);
jcombobox_add_string(checked_bg, "4x4", NULL);
jcombobox_add_string(checked_bg, "2x2", NULL);
jcombobox_select_index(checked_bg, (int)RenderEngine::getCheckedBgType());
// Zoom checked background
if (RenderEngine::getCheckedBgZoom())
jwidget_select(checked_bg_zoom);
// Checked background colors
checked_bg_color1 = colorbutton_new(RenderEngine::getCheckedBgColor1(), app_get_current_image_type());
checked_bg_color2 = colorbutton_new(RenderEngine::getCheckedBgColor2(), app_get_current_image_type());
jwidget_add_child(checked_bg_color1_box, checked_bg_color1);
jwidget_add_child(checked_bg_color2_box, checked_bg_color2);
// Reset button
HOOK(checked_bg_reset, JI_SIGNAL_BUTTON_SELECT, checked_bg_reset_hook, 0);
// Undo limit
undo_size_limit->setTextf("%d", get_config_int("Options", "UndoSizeLimit", 8));
// Show the window and wait the user to close it
window->open_window_fg();
killer = window->get_killer();
if (killer == button_ok) {
if (window->get_killer() == button_ok) {
int undo_size_limit_value;
set_config_bool("Options", "MoveSmooth", jwidget_is_selected(check_smooth));
set_config_bool("Options", "MoveClick2", jwidget_is_selected(move_click2));
set_config_bool("Options", "DrawClick2", jwidget_is_selected(draw_click2));
RenderEngine::setCheckedBgType((RenderEngine::CheckedBgType)jcombobox_get_selected_index(checked_bg));
RenderEngine::setCheckedBgZoom(jwidget_is_selected(checked_bg_zoom));
RenderEngine::setCheckedBgColor1(colorbutton_get_color(checked_bg_color1));
RenderEngine::setCheckedBgColor2(colorbutton_get_color(checked_bg_color2));
undo_size_limit_value = undo_size_limit->getTextInt();
undo_size_limit_value = MID(1, undo_size_limit_value, 9999);
set_config_int("Options", "UndoSizeLimit", undo_size_limit_value);
/* save configuration */
// Save configuration
flush_config_file();
// Refresh all editors
refresh_all_editors();
}
}
static bool checked_bg_reset_hook(JWidget widget, void *data)
{
// Default values
jcombobox_select_index(checked_bg, (int)RenderEngine::CHECKED_BG_16X16);
jwidget_select(checked_bg_zoom);
colorbutton_set_color(checked_bg_color1, color_rgb(128, 128, 128));
colorbutton_set_color(checked_bg_color2, color_rgb(192, 192, 192));
return true;
}
//////////////////////////////////////////////////////////////////////
// CommandFactory

@ -16,15 +16,13 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* TODO modificable option: scalable-tiles */
#define SCALABLE_TILES
#include "config.h"
#include <assert.h>
#include "jinete/jlist.h"
#include "core/cfg.h"
#include "modules/palettes.h"
#include "raster/image.h"
#include "raster/raster.h"
@ -151,7 +149,7 @@ static void merge_zoomed_image(Image *dst, Image *src,
bottom = dst_y+dst_h-1;
// the scanline variable is used to
// the scanline variable is used to blend src/dst pixels one time for each pixel
scanline = new typename Traits::pixel_t[src_w];
// for each line to draw of the source image...
@ -255,10 +253,70 @@ done_with_blit:;
//////////////////////////////////////////////////////////////////////
// Render Engine
static RenderEngine::CheckedBgType checked_bg_type;
static bool checked_bg_zoom;
static color_t checked_bg_color1;
static color_t checked_bg_color2;
static int global_opacity = 255;
static Layer *selected_layer = NULL;
static Image *rastering_image = NULL;
void RenderEngine::loadConfig()
{
checked_bg_type = (CheckedBgType)get_config_int("Options", "CheckedBgType",
(int)RenderEngine::CHECKED_BG_16X16);
checked_bg_zoom = get_config_bool("Options", "CheckedBgZoom", true);
checked_bg_color1 = get_config_color("Options", "CheckedBgColor1", color_rgb(128, 128, 128));
checked_bg_color2 = get_config_color("Options", "CheckedBgColor2", color_rgb(192, 192, 192));
}
RenderEngine::CheckedBgType RenderEngine::getCheckedBgType()
{
return checked_bg_type;
}
void RenderEngine::setCheckedBgType(CheckedBgType type)
{
checked_bg_type = type;
set_config_int("Options", "CheckedBgType", (int)type);
}
bool RenderEngine::getCheckedBgZoom()
{
return checked_bg_zoom;
}
void RenderEngine::setCheckedBgZoom(bool state)
{
checked_bg_zoom = state;
set_config_int("Options", "CheckedBgZoom", state);
}
color_t RenderEngine::getCheckedBgColor1()
{
return checked_bg_color1;
}
void RenderEngine::setCheckedBgColor1(color_t color)
{
checked_bg_color1 = color;
set_config_color("Options", "CheckedBgColor1", color);
}
color_t RenderEngine::getCheckedBgColor2()
{
return checked_bg_color2;
}
void RenderEngine::setCheckedBgColor2(color_t color)
{
checked_bg_color2 = color;
set_config_color("Options", "CheckedBgColor2", color);
}
//////////////////////////////////////////////////////////////////////
void RenderEngine::setPreviewImage(Layer *layer, Image *image)
{
selected_layer = layer;
@ -266,11 +324,11 @@ void RenderEngine::setPreviewImage(Layer *layer, Image *image)
}
/**
* Draws the @a frame animation frame of the @a source image in the
* return image, all positions must have the zoom applied
* (sorce_x<<zoom, dest_x<<zoom, width<<zoom, etc.)
*
* This routine is used to render the sprite
Draws the @a frame of animation of the specified @a sprite
in a new image and return it.
Positions source_x, source_y, width and height must have the
zoom applied (sorce_x<<zoom, source_y<<zoom, width<<zoom, etc.)
*/
Image* RenderEngine::renderSprite(Sprite* sprite,
int source_x, int source_y,
@ -279,7 +337,7 @@ Image* RenderEngine::renderSprite(Sprite* sprite,
{
void (*zoomed_func)(Image *, Image *, int, int, int, int, int);
LayerImage* background = sprite->getBackgroundLayer();
bool need_grid = (background != NULL ? !background->is_readable(): true);
bool need_checked_bg = (background != NULL ? !background->is_readable(): true);
int depth;
Image *image;
@ -309,56 +367,86 @@ Image* RenderEngine::renderSprite(Sprite* sprite,
if (!image)
return NULL;
/* draw the background */
if (need_grid) {
// Draw checked background
if (need_checked_bg) {
int x, y, u, v, c1, c2;
int tile_x = 0;
int tile_y = 0;
int tile_w = 16;
int tile_h = 16;
switch (image->imgtype) {
case IMAGE_RGB:
c1 = _rgba(128, 128, 128, 255); /* TODO configurable grid color */
c2 = _rgba(192, 192, 192, 255);
c1 = get_color_for_image(image->imgtype, checked_bg_color1);
c2 = get_color_for_image(image->imgtype, checked_bg_color2);
break;
case IMAGE_GRAYSCALE:
c1 = _graya(128, 255);
c2 = _graya(192, 255);
c1 = get_color_for_image(image->imgtype, checked_bg_color1);
c2 = get_color_for_image(image->imgtype, checked_bg_color2);
break;
/* TODO remove this */
/* case IMAGE_INDEXED: */
/* c1 = rgb_map->data[16][16][16]; */
/* c2 = rgb_map->data[24][24][24]; */
/* break; */
// case IMAGE_INDEXED:
// c1 = get_color_for_image(image->imgtype, checked_bg_color1);
// c2 = get_color_for_image(image->imgtype, checked_bg_color2);
// break;
default:
c1 = c2 = 0;
break;
}
#ifdef SCALABLE_TILES
u = (-source_x / (16<<zoom)) * (16<<zoom);
v = (-source_y / (16<<zoom)) * (16<<zoom);
for (y=-source_y; y<height+(16<<zoom); y+=(16<<zoom)) {
for (x=-source_x; x<width+(16<<zoom); x+=(16<<zoom))
image_rectfill(image,
x,
y,
x+(16<<zoom)-1,
y+(16<<zoom)-1,
((u++)&1)? c1: c2);
u = (++v);
switch (checked_bg_type) {
case CHECKED_BG_16X16:
tile_w = 16;
tile_h = 16;
break;
case CHECKED_BG_8X8:
tile_w = 8;
tile_h = 8;
break;
case CHECKED_BG_4X4:
tile_w = 4;
tile_h = 4;
break;
case CHECKED_BG_2X2:
tile_w = 2;
tile_h = 2;
break;
}
#else
u = (-source_x / (16<<zoom)) * 16;
v = (-source_y / (16<<zoom)) * 16;
for (y=-source_y; y<height+16; y+=16) {
for (x=-source_x; x<width+16; x+=16)
image_rectfill(image,
x,
y,
x+16-1,
y+16-1,
((u++)&1)? c1: c2);
u = (++v);
if (checked_bg_zoom) {
tile_w <<= zoom;
tile_h <<= zoom;
}
// Tile size
if (tile_w < (1<<zoom)) tile_w = (1<<zoom);
if (tile_h < (1<<zoom)) tile_h = (1<<zoom);
// Tile position (u,v) is the number of tile we start in (source_x,source_y) coordinate
// u = ((source_x>>zoom) - (source_x%(1<<zoom))) / tile_w;
// v = ((source_y>>zoom) - (source_y%(1<<zoom))) / tile_h;
u = source_x / tile_w;
v = source_y / tile_h;
// Position where we start drawing the first tile in "image"
int x_start = -(source_x % tile_w);
int y_start = -(source_y % tile_h);
// Draw checked background (tile by tile)
int u_start = u;
for (y=y_start; y<height+tile_h; y+=tile_h) {
for (x=x_start; x<width+tile_w; x+=tile_w) {
image_rectfill(image, x, y, x+tile_w-1, y+tile_h-1,
(((u+v))&1)? c1: c2);
++u;
}
u = u_start;
++v;
}
#endif
}
else
image_clear(image, 0);

@ -19,6 +19,8 @@
#ifndef UTIL_RENDER_H_INCLUDED
#define UTIL_RENDER_H_INCLUDED
#include "core/color.h"
class Image;
class Layer;
class Sprite;
@ -26,8 +28,33 @@ class Sprite;
class RenderEngine
{
public:
//////////////////////////////////////////////////////////////////////
// Checked background configuration
enum CheckedBgType { CHECKED_BG_16X16,
CHECKED_BG_8X8,
CHECKED_BG_4X4,
CHECKED_BG_2X2 };
static void loadConfig();
static CheckedBgType getCheckedBgType();
static void setCheckedBgType(CheckedBgType type);
static bool getCheckedBgZoom();
static void setCheckedBgZoom(bool state);
static color_t getCheckedBgColor1();
static void setCheckedBgColor1(color_t color);
static color_t getCheckedBgColor2();
static void setCheckedBgColor2(color_t color);
//////////////////////////////////////////////////////////////////////
// Preview image
static void setPreviewImage(Layer* layer, Image* drawable);
//////////////////////////////////////////////////////////////////////
// Main function used by sprite-editors to render the sprite
static Image* renderSprite(Sprite* sprite,
int source_x, int source_y,
int width, int height,