mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-30 04:20:23 +00:00
Merged all preview commands (fit screen/tiled/normal) to just one Preview command (F8).
- Improved preview to show checked background as default background for transparent sprites. - Added RenderEngine::renderImage() and renderCheckedBackground(). - Removed F6 and F7 shortcuts.
This commit is contained in:
parent
c8ae9cbf8a
commit
61150ad31e
10
data/gui.xml
10
data/gui.xml
@ -59,9 +59,7 @@
|
||||
<key command="split_editor_vertically" shortcut="Ctrl+2" />
|
||||
<key command="split_editor_horizontally" shortcut="Ctrl+3" />
|
||||
<key command="close_editor" shortcut="Ctrl+4" />
|
||||
<key command="preview_fit_to_screen" shortcut="F6" />
|
||||
<key command="preview_normal" shortcut="F7" />
|
||||
<key command="preview_tiled" shortcut="F8" />
|
||||
<key command="preview" shortcut="F8" />
|
||||
<key command="show_grid" shortcut="Shift+G" />
|
||||
<key command="snap_to_grid" shortcut="Shift+S" />
|
||||
<!-- tools -->
|
||||
@ -280,11 +278,7 @@
|
||||
<item command="show_grid" text="Show &Grid" />
|
||||
<item command="snap_to_grid" text="&Snap to Grid" />
|
||||
</menu>
|
||||
<menu text="&Preview">
|
||||
<item command="preview_fit_to_screen" text="&Fit to screen" />
|
||||
<item command="preview_normal" text="&Normal" />
|
||||
<item command="preview_tiled" text="&Tiled" />
|
||||
</menu>
|
||||
<item command="preview" text="&Preview" />
|
||||
<separator />
|
||||
<item command="refresh" text="&Refresh" />
|
||||
<item command="configure_screen" text="Configure &Screen" />
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "modules/gfx.h"
|
||||
#include "modules/gui.h"
|
||||
#include "raster/image.h"
|
||||
#include "raster/palette.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "util/render.h"
|
||||
#include "widgets/editor.h"
|
||||
@ -45,18 +46,17 @@
|
||||
class PreviewCommand : public Command
|
||||
{
|
||||
public:
|
||||
PreviewCommand(const char* short_name, const char* friendly_name);
|
||||
PreviewCommand();
|
||||
Command* clone() { return new PreviewCommand(*this); }
|
||||
|
||||
protected:
|
||||
bool enabled(Context* context);
|
||||
|
||||
void preview_sprite(Context* context, int flags);
|
||||
void execute(Context* context);
|
||||
};
|
||||
|
||||
PreviewCommand::PreviewCommand(const char* short_name, const char* friendly_name)
|
||||
: Command(short_name,
|
||||
friendly_name,
|
||||
PreviewCommand::PreviewCommand()
|
||||
: Command("preview",
|
||||
"Preview",
|
||||
CmdUIOnlyFlag)
|
||||
{
|
||||
}
|
||||
@ -72,326 +72,177 @@ bool PreviewCommand::enabled(Context* context)
|
||||
/**
|
||||
* Shows the sprite using the complete screen.
|
||||
*/
|
||||
void PreviewCommand::preview_sprite(Context* context, int flags)
|
||||
void PreviewCommand::execute(Context* context)
|
||||
{
|
||||
Editor* editor = current_editor;
|
||||
|
||||
if (editor && editor->getSprite()) {
|
||||
Sprite *sprite = editor->getSprite();
|
||||
JWidget view = jwidget_get_view(editor);
|
||||
int old_mouse_x, old_mouse_y;
|
||||
int scroll_x, scroll_y;
|
||||
int u, v, x, y, w, h;
|
||||
int shiftx, shifty;
|
||||
Image *image;
|
||||
BITMAP *bmp;
|
||||
int redraw;
|
||||
JRect vp;
|
||||
int bg_color, index_bg_color = -1;
|
||||
TiledMode tiled;
|
||||
// Cancel operation if current editor does not have a sprite
|
||||
if (!editor || !editor->getSprite())
|
||||
return;
|
||||
|
||||
if (flags & PREVIEW_TILED) {
|
||||
tiled = context->getSettings()->getTiledMode();
|
||||
if (tiled == TILED_NONE)
|
||||
tiled = TILED_BOTH;
|
||||
}
|
||||
else
|
||||
tiled = TILED_NONE;
|
||||
SpriteWriter sprite(editor->getSprite());
|
||||
const Palette* pal = sprite->getCurrentPalette();
|
||||
JWidget view = jwidget_get_view(editor);
|
||||
int scroll_x, scroll_y;
|
||||
int u, v, x, y;
|
||||
int index_bg_color = -1;
|
||||
TiledMode tiled = context->getSettings()->getTiledMode();
|
||||
|
||||
jmanager_free_mouse();
|
||||
// Free mouse
|
||||
jmanager_free_mouse();
|
||||
|
||||
vp = jview_get_viewport_position(view);
|
||||
jview_get_scroll(view, &scroll_x, &scroll_y);
|
||||
// Clear extras (e.g. pen preview)
|
||||
sprite->destroyExtraCel();
|
||||
|
||||
old_mouse_x = jmouse_x(0);
|
||||
old_mouse_y = jmouse_y(0);
|
||||
JRect vp = jview_get_viewport_position(view);
|
||||
jview_get_scroll(view, &scroll_x, &scroll_y);
|
||||
|
||||
bmp = create_bitmap(sprite->getWidth(), sprite->getHeight());
|
||||
if (bmp) {
|
||||
/* print a informative text */
|
||||
app_get_statusbar()->setStatusText(1, _("Rendering..."));
|
||||
jwidget_flush_redraw(app_get_statusbar());
|
||||
jmanager_dispatch_messages(ji_get_default_manager());
|
||||
int old_mouse_x = jmouse_x(0);
|
||||
int old_mouse_y = jmouse_y(0);
|
||||
|
||||
jmouse_set_cursor(JI_CURSOR_NULL);
|
||||
jmouse_set_cursor(JI_CURSOR_NULL);
|
||||
jmouse_set_position(JI_SCREEN_W/2, JI_SCREEN_H/2);
|
||||
|
||||
int pos_x = - scroll_x + vp->x1 + editor->editor_get_offset_x();
|
||||
int pos_y = - scroll_y + vp->y1 + editor->editor_get_offset_y();
|
||||
int delta_x = 0;
|
||||
int delta_y = 0;
|
||||
|
||||
int zoom = editor->editor_get_zoom();
|
||||
int w = sprite->getWidth() << zoom;
|
||||
int h = sprite->getHeight() << zoom;
|
||||
|
||||
bool redraw = true;
|
||||
|
||||
// Render the sprite
|
||||
Image* render = NULL;
|
||||
Image* doublebuf = image_new(IMAGE_RGB, JI_SCREEN_W, JI_SCREEN_H);
|
||||
|
||||
do {
|
||||
// Update scroll
|
||||
if (jmouse_poll()) {
|
||||
delta_x += (jmouse_x(0) - JI_SCREEN_W/2);
|
||||
delta_y += (jmouse_y(0) - JI_SCREEN_H/2);
|
||||
jmouse_set_position(JI_SCREEN_W/2, JI_SCREEN_H/2);
|
||||
|
||||
/* render the sprite in the bitmap */
|
||||
image = RenderEngine::renderSprite(sprite, 0, 0, sprite->getWidth(), sprite->getHeight(),
|
||||
sprite->getCurrentFrame(), 0);
|
||||
if (image) {
|
||||
image_to_allegro(image, bmp, 0, 0, sprite->getCurrentPalette());
|
||||
image_free(image);
|
||||
}
|
||||
|
||||
if (!(flags & PREVIEW_TILED))
|
||||
bg_color = palette_color[index_bg_color=0];
|
||||
else
|
||||
bg_color = makecol(128, 128, 128);
|
||||
|
||||
shiftx = - scroll_x + vp->x1 + editor->editor_get_offset_x();
|
||||
shifty = - scroll_y + vp->y1 + editor->editor_get_offset_y();
|
||||
|
||||
w = sprite->getWidth() << editor->editor_get_zoom();
|
||||
h = sprite->getHeight() << editor->editor_get_zoom();
|
||||
jmouse_poll();
|
||||
|
||||
redraw = true;
|
||||
do {
|
||||
/* update scroll */
|
||||
if (jmouse_poll()) {
|
||||
shiftx += jmouse_x(0) - JI_SCREEN_W/2;
|
||||
shifty += jmouse_y(0) - JI_SCREEN_H/2;
|
||||
jmouse_set_position(JI_SCREEN_W/2, JI_SCREEN_H/2);
|
||||
jmouse_poll();
|
||||
|
||||
redraw = true;
|
||||
}
|
||||
|
||||
if (redraw) {
|
||||
redraw = false;
|
||||
|
||||
/* fit on screen */
|
||||
if (flags & PREVIEW_FIT_ON_SCREEN) {
|
||||
double sx, sy, scale, outw, outh;
|
||||
|
||||
sx = (double)JI_SCREEN_W / (double)bmp->w;
|
||||
sy = (double)JI_SCREEN_H / (double)bmp->h;
|
||||
scale = MIN(sx, sy);
|
||||
|
||||
outw = (double)bmp->w * (double)scale;
|
||||
outh = (double)bmp->h * (double)scale;
|
||||
|
||||
stretch_blit(bmp, ji_screen, 0, 0, bmp->w, bmp->h, 0, 0, outw, outh);
|
||||
jrectexclude(ji_screen, 0, 0, JI_SCREEN_W-1, JI_SCREEN_H-1,
|
||||
0, 0, outw-1, outh-1, bg_color);
|
||||
}
|
||||
/* draw in normal size */
|
||||
else {
|
||||
if (tiled & TILED_X_AXIS)
|
||||
x = SGN(shiftx) * (ABS(shiftx)%w);
|
||||
else
|
||||
x = shiftx;
|
||||
|
||||
if (tiled & TILED_Y_AXIS)
|
||||
y = SGN(shifty) * (ABS(shifty)%h);
|
||||
else
|
||||
y = shifty;
|
||||
|
||||
if (tiled != TILED_BOTH) {
|
||||
/* rectfill_exclude(ji_screen, 0, 0, JI_SCREEN_W-1, JI_SCREEN_H-1, */
|
||||
/* x, y, x+w-1, y+h-1, bg_color); */
|
||||
clear_to_color(ji_screen, bg_color);
|
||||
}
|
||||
|
||||
if (!editor->editor_get_zoom()) {
|
||||
/* in the center */
|
||||
if (!(flags & PREVIEW_TILED))
|
||||
draw_sprite(ji_screen, bmp, x, y);
|
||||
/* tiled */
|
||||
else {
|
||||
switch (tiled) {
|
||||
case TILED_X_AXIS:
|
||||
for (u=x-w; u<JI_SCREEN_W+w; u+=w)
|
||||
blit(bmp, ji_screen, 0, 0, u, y, w, h);
|
||||
break;
|
||||
case TILED_Y_AXIS:
|
||||
for (v=y-h; v<JI_SCREEN_H+h; v+=h)
|
||||
blit(bmp, ji_screen, 0, 0, x, v, w, h);
|
||||
break;
|
||||
case TILED_BOTH:
|
||||
for (v=y-h; v<JI_SCREEN_H+h; v+=h)
|
||||
for (u=x-w; u<JI_SCREEN_W+w; u+=w)
|
||||
blit(bmp, ji_screen, 0, 0, u, v, w, h);
|
||||
break;
|
||||
case TILED_NONE:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* in the center */
|
||||
if (!(flags & PREVIEW_TILED))
|
||||
masked_stretch_blit(bmp, ji_screen, 0, 0, bmp->w, bmp->h, x, y, w, h);
|
||||
/* tiled */
|
||||
else {
|
||||
switch (tiled) {
|
||||
case TILED_X_AXIS:
|
||||
for (u=x-w; u<JI_SCREEN_W+w; u+=w)
|
||||
stretch_blit(bmp, ji_screen, 0, 0, bmp->w, bmp->h, u, y, w, h);
|
||||
break;
|
||||
case TILED_Y_AXIS:
|
||||
for (v=y-h; v<JI_SCREEN_H+h; v+=h)
|
||||
stretch_blit(bmp, ji_screen, 0, 0, bmp->w, bmp->h, x, v, w, h);
|
||||
break;
|
||||
case TILED_BOTH:
|
||||
for (v=y-h; v<JI_SCREEN_H+h; v+=h)
|
||||
for (u=x-w; u<JI_SCREEN_W+w; u+=w)
|
||||
stretch_blit(bmp, ji_screen, 0, 0, bmp->w, bmp->h, u, v, w, h);
|
||||
break;
|
||||
case TILED_NONE:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gui_feedback();
|
||||
|
||||
if (keypressed()) {
|
||||
int readkey_value = readkey();
|
||||
JMessage msg = jmessage_new_key_related(JM_KEYPRESSED, readkey_value);
|
||||
Command* command = get_command_from_key_message(msg);
|
||||
jmessage_free(msg);
|
||||
|
||||
/* change frame */
|
||||
if (command != NULL &&
|
||||
(strcmp(command->short_name(), CommandId::goto_first_frame) == 0 ||
|
||||
strcmp(command->short_name(), CommandId::goto_previous_frame) == 0 ||
|
||||
strcmp(command->short_name(), CommandId::goto_next_frame) == 0 ||
|
||||
strcmp(command->short_name(), CommandId::goto_last_frame) == 0)) {
|
||||
/* execute the command */
|
||||
context->execute_command(command);
|
||||
|
||||
/* redraw */
|
||||
redraw = true;
|
||||
|
||||
/* render the sprite in the bitmap */
|
||||
image = RenderEngine::renderSprite(sprite, 0, 0, sprite->getWidth(), sprite->getHeight(),
|
||||
sprite->getCurrentFrame(), 0);
|
||||
if (image) {
|
||||
image_to_allegro(image, bmp, 0, 0, sprite->getCurrentPalette());
|
||||
image_free(image);
|
||||
}
|
||||
}
|
||||
/* play the animation */
|
||||
else if (command != NULL &&
|
||||
strcmp(command->short_name(), CommandId::play_animation) == 0) {
|
||||
/* TODO */
|
||||
}
|
||||
/* change background color */
|
||||
else if ((readkey_value>>8) == KEY_PLUS_PAD) {
|
||||
if (index_bg_color < 255) {
|
||||
bg_color = palette_color[++index_bg_color];
|
||||
redraw = true;
|
||||
}
|
||||
}
|
||||
else if ((readkey_value>>8) == KEY_MINUS_PAD) {
|
||||
if (index_bg_color > 0) {
|
||||
bg_color = palette_color[--index_bg_color];
|
||||
redraw = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
} while (!jmouse_b(0));
|
||||
|
||||
destroy_bitmap(bmp);
|
||||
}
|
||||
|
||||
do {
|
||||
jmouse_poll();
|
||||
gui_feedback();
|
||||
} while (jmouse_b(0));
|
||||
clear_keybuf();
|
||||
// Render sprite and leave the result in 'render' variable
|
||||
if (render == NULL)
|
||||
render = RenderEngine::renderSprite(sprite, 0, 0, sprite->getWidth(), sprite->getHeight(),
|
||||
sprite->getCurrentFrame(), 0, false);
|
||||
|
||||
jmouse_set_position(old_mouse_x, old_mouse_y);
|
||||
jmouse_set_cursor(JI_CURSOR_NORMAL);
|
||||
// Redraw the screen
|
||||
if (redraw) {
|
||||
redraw = false;
|
||||
|
||||
jmanager_refresh_screen();
|
||||
jrect_free(vp);
|
||||
}
|
||||
}
|
||||
x = pos_x + ((delta_x >> zoom) << zoom);
|
||||
y = pos_y + ((delta_y >> zoom) << zoom);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// preview_fit_to_screen
|
||||
if (tiled & TILED_X_AXIS) x = SGN(x) * (ABS(x)%w);
|
||||
if (tiled & TILED_Y_AXIS) y = SGN(y) * (ABS(y)%h);
|
||||
|
||||
class PreviewFitToScreenCommand : public PreviewCommand
|
||||
{
|
||||
public:
|
||||
PreviewFitToScreenCommand();
|
||||
Command* clone() { return new PreviewFitToScreenCommand(*this); }
|
||||
if (index_bg_color == -1)
|
||||
RenderEngine::renderCheckedBackground(doublebuf, -pos_x, -pos_y, zoom);
|
||||
else
|
||||
image_clear(doublebuf, pal->getEntry(index_bg_color));
|
||||
|
||||
protected:
|
||||
void execute(Context* context);
|
||||
};
|
||||
switch (tiled) {
|
||||
case TILED_NONE:
|
||||
RenderEngine::renderImage(doublebuf, render, x, y, zoom);
|
||||
break;
|
||||
case TILED_X_AXIS:
|
||||
for (u=x-w; u<JI_SCREEN_W+w; u+=w)
|
||||
RenderEngine::renderImage(doublebuf, render, u, y, zoom);
|
||||
break;
|
||||
case TILED_Y_AXIS:
|
||||
for (v=y-h; v<JI_SCREEN_H+h; v+=h)
|
||||
RenderEngine::renderImage(doublebuf, render, x, v, zoom);
|
||||
break;
|
||||
case TILED_BOTH:
|
||||
for (v=y-h; v<JI_SCREEN_H+h; v+=h)
|
||||
for (u=x-w; u<JI_SCREEN_W+w; u+=w)
|
||||
RenderEngine::renderImage(doublebuf, render, u, v, zoom);
|
||||
break;
|
||||
}
|
||||
|
||||
PreviewFitToScreenCommand::PreviewFitToScreenCommand()
|
||||
: PreviewCommand("preview_fit_to_screen",
|
||||
"Preview Fit to Screen")
|
||||
{
|
||||
}
|
||||
image_to_allegro(doublebuf, ji_screen, 0, 0, pal);
|
||||
}
|
||||
|
||||
void PreviewFitToScreenCommand::execute(Context* context)
|
||||
{
|
||||
preview_sprite(context, PREVIEW_FIT_ON_SCREEN);
|
||||
}
|
||||
// It is necessary in case ji_screen is double-bufferred
|
||||
gui_feedback();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// preview_normal
|
||||
if (keypressed()) {
|
||||
int readkey_value = readkey();
|
||||
JMessage msg = jmessage_new_key_related(JM_KEYPRESSED, readkey_value);
|
||||
Command* command = get_command_from_key_message(msg);
|
||||
jmessage_free(msg);
|
||||
|
||||
class PreviewNormalCommand : public PreviewCommand
|
||||
{
|
||||
public:
|
||||
PreviewNormalCommand();
|
||||
Command* clone() { return new PreviewNormalCommand(*this); }
|
||||
// Change frame
|
||||
if (command != NULL &&
|
||||
(strcmp(command->short_name(), CommandId::goto_first_frame) == 0 ||
|
||||
strcmp(command->short_name(), CommandId::goto_previous_frame) == 0 ||
|
||||
strcmp(command->short_name(), CommandId::goto_next_frame) == 0 ||
|
||||
strcmp(command->short_name(), CommandId::goto_last_frame) == 0)) {
|
||||
// Execute the command
|
||||
context->execute_command(command);
|
||||
|
||||
protected:
|
||||
void execute(Context* context);
|
||||
};
|
||||
// Redraw
|
||||
redraw = true;
|
||||
|
||||
PreviewNormalCommand::PreviewNormalCommand()
|
||||
: PreviewCommand("preview_normal",
|
||||
"Preview Normal")
|
||||
{
|
||||
}
|
||||
// Re-render
|
||||
if (render)
|
||||
image_free(render);
|
||||
render = NULL;
|
||||
}
|
||||
// Play the animation
|
||||
else if (command != NULL &&
|
||||
strcmp(command->short_name(), CommandId::play_animation) == 0) {
|
||||
// TODO
|
||||
}
|
||||
// Change background color
|
||||
else if ((readkey_value>>8) == KEY_PLUS_PAD ||
|
||||
(readkey_value&0xff) == '+') {
|
||||
if (index_bg_color == -1 ||
|
||||
index_bg_color < pal->size()-1) {
|
||||
++index_bg_color;
|
||||
redraw = true;
|
||||
}
|
||||
}
|
||||
else if ((readkey_value>>8) == KEY_MINUS_PAD ||
|
||||
(readkey_value&0xff) == '-') {
|
||||
if (index_bg_color >= 0) {
|
||||
--index_bg_color; // can be -1 which is the checked background
|
||||
redraw = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
} while (!jmouse_b(0));
|
||||
|
||||
void PreviewNormalCommand::execute(Context* context)
|
||||
{
|
||||
preview_sprite(context, 0);
|
||||
}
|
||||
if (render) image_free(render);
|
||||
if (doublebuf) image_free(doublebuf);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// preview_tiled
|
||||
do {
|
||||
jmouse_poll();
|
||||
gui_feedback();
|
||||
} while (jmouse_b(0));
|
||||
clear_keybuf();
|
||||
|
||||
class PreviewTiledCommand : public PreviewCommand
|
||||
{
|
||||
public:
|
||||
PreviewTiledCommand();
|
||||
Command* clone() { return new PreviewTiledCommand(*this); }
|
||||
jmouse_set_position(old_mouse_x, old_mouse_y);
|
||||
jmouse_set_cursor(JI_CURSOR_NORMAL);
|
||||
|
||||
protected:
|
||||
void execute(Context* context);
|
||||
};
|
||||
|
||||
PreviewTiledCommand::PreviewTiledCommand()
|
||||
: PreviewCommand("preview_tiled",
|
||||
"Preview Tiled")
|
||||
{
|
||||
}
|
||||
|
||||
void PreviewTiledCommand::execute(Context* context)
|
||||
{
|
||||
preview_sprite(context, PREVIEW_TILED);
|
||||
jmanager_refresh_screen();
|
||||
jrect_free(vp);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// CommandFactory
|
||||
|
||||
Command* CommandFactory::create_preview_fit_to_screen_command()
|
||||
Command* CommandFactory::create_preview_command()
|
||||
{
|
||||
return new PreviewFitToScreenCommand;
|
||||
}
|
||||
|
||||
Command* CommandFactory::create_preview_normal_command()
|
||||
{
|
||||
return new PreviewNormalCommand;
|
||||
}
|
||||
|
||||
Command* CommandFactory::create_preview_tiled_command()
|
||||
{
|
||||
return new PreviewTiledCommand;
|
||||
return new PreviewCommand;
|
||||
}
|
||||
|
@ -74,9 +74,7 @@ FOR_EACH_COMMAND(options)
|
||||
FOR_EACH_COMMAND(palette_editor)
|
||||
FOR_EACH_COMMAND(paste)
|
||||
FOR_EACH_COMMAND(play_animation)
|
||||
FOR_EACH_COMMAND(preview_fit_to_screen)
|
||||
FOR_EACH_COMMAND(preview_normal)
|
||||
FOR_EACH_COMMAND(preview_tiled)
|
||||
FOR_EACH_COMMAND(preview)
|
||||
FOR_EACH_COMMAND(quick_reference)
|
||||
FOR_EACH_COMMAND(record_screen)
|
||||
FOR_EACH_COMMAND(redo)
|
||||
|
@ -38,7 +38,7 @@ class BlenderHelper
|
||||
{
|
||||
BLEND_COLOR m_blend_color;
|
||||
public:
|
||||
BlenderHelper(int blend_mode, Image* src)
|
||||
BlenderHelper(int blend_mode, const Image* src)
|
||||
{
|
||||
m_blend_color = SrcTraits::get_blender(blend_mode);
|
||||
}
|
||||
@ -56,7 +56,7 @@ class BlenderHelper<RgbTraits, GrayscaleTraits>
|
||||
{
|
||||
BLEND_COLOR m_blend_color;
|
||||
public:
|
||||
BlenderHelper(int blend_mode, Image* src)
|
||||
BlenderHelper(int blend_mode, const Image* src)
|
||||
{
|
||||
m_blend_color = RgbTraits::get_blender(blend_mode);
|
||||
}
|
||||
@ -76,7 +76,7 @@ class BlenderHelper<RgbTraits, IndexedTraits>
|
||||
int m_blend_mode;
|
||||
int m_mask_color;
|
||||
public:
|
||||
BlenderHelper(int blend_mode, Image* src)
|
||||
BlenderHelper(int blend_mode, const Image* src)
|
||||
{
|
||||
m_blend_mode = blend_mode;
|
||||
m_mask_color = src->mask_color;
|
||||
@ -102,7 +102,7 @@ public:
|
||||
};
|
||||
|
||||
template<class DstTraits, class SrcTraits>
|
||||
static void merge_zoomed_image(Image* dst, Image* src,
|
||||
static void merge_zoomed_image(Image* dst, const Image* src,
|
||||
int x, int y, int opacity,
|
||||
int blend_mode, int zoom)
|
||||
{
|
||||
@ -346,13 +346,14 @@ void RenderEngine::setPreviewImage(Layer *layer, Image *image)
|
||||
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,
|
||||
Image* RenderEngine::renderSprite(const Sprite* sprite,
|
||||
int source_x, int source_y,
|
||||
int width, int height,
|
||||
int frame, int zoom)
|
||||
int frame, int zoom,
|
||||
bool draw_tiled_bg)
|
||||
{
|
||||
void (*zoomed_func)(Image*, Image*, int, int, int, int, int);
|
||||
LayerImage* background = sprite->getBackgroundLayer();
|
||||
void (*zoomed_func)(Image*, const Image*, int, int, int, int, int);
|
||||
const LayerImage* background = sprite->getBackgroundLayer();
|
||||
bool need_checked_bg = (background != NULL ? !background->is_readable(): true);
|
||||
Image *image;
|
||||
|
||||
@ -380,70 +381,8 @@ Image* RenderEngine::renderSprite(Sprite* sprite,
|
||||
return NULL;
|
||||
|
||||
// Draw checked background
|
||||
if (need_checked_bg) {
|
||||
int x, y, u, v;
|
||||
int tile_x = 0;
|
||||
int tile_y = 0;
|
||||
int tile_w = 16;
|
||||
int tile_h = 16;
|
||||
int c1 = get_color_for_image(image->imgtype, checked_bg_color1);
|
||||
int c2 = get_color_for_image(image->imgtype, checked_bg_color2);
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (need_checked_bg && draw_tiled_bg)
|
||||
renderCheckedBackground(image, source_x, source_y, zoom);
|
||||
else
|
||||
image_clear(image, 0);
|
||||
|
||||
@ -490,10 +429,106 @@ Image* RenderEngine::renderSprite(Sprite* sprite,
|
||||
return image;
|
||||
}
|
||||
|
||||
void RenderEngine::renderLayer(Sprite *sprite, Layer *layer, Image *image,
|
||||
void RenderEngine::renderCheckedBackground(Image* image,
|
||||
int source_x, int source_y,
|
||||
int zoom)
|
||||
{
|
||||
int x, y, u, v;
|
||||
int tile_x = 0;
|
||||
int tile_y = 0;
|
||||
int tile_w = 16;
|
||||
int tile_h = 16;
|
||||
int c1 = get_color_for_image(image->imgtype, checked_bg_color1);
|
||||
int c2 = get_color_for_image(image->imgtype, checked_bg_color2);
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
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 / 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-tile_h; y<image->h+tile_h; y+=tile_h) {
|
||||
for (x=x_start-tile_w; x<image->w+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;
|
||||
}
|
||||
}
|
||||
|
||||
void RenderEngine::renderImage(Image* rgb_image, Image* src_image,
|
||||
int x, int y, int zoom)
|
||||
{
|
||||
void (*zoomed_func)(Image*, const Image*, int, int, int, int, int);
|
||||
|
||||
assert(rgb_image->imgtype == IMAGE_RGB && "renderImage accepts RGB destination images only");
|
||||
|
||||
switch (src_image->imgtype) {
|
||||
|
||||
case IMAGE_RGB:
|
||||
zoomed_func = merge_zoomed_image<RgbTraits, RgbTraits>;
|
||||
break;
|
||||
|
||||
case IMAGE_GRAYSCALE:
|
||||
zoomed_func = merge_zoomed_image<RgbTraits, GrayscaleTraits>;
|
||||
break;
|
||||
|
||||
case IMAGE_INDEXED:
|
||||
zoomed_func = merge_zoomed_image<RgbTraits, IndexedTraits>;
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
(*zoomed_func)(rgb_image, src_image, x, y, 255, BLEND_MODE_NORMAL, zoom);
|
||||
}
|
||||
|
||||
void RenderEngine::renderLayer(const Sprite *sprite,
|
||||
const Layer *layer,
|
||||
Image *image,
|
||||
int source_x, int source_y,
|
||||
int frame, int zoom,
|
||||
void (*zoomed_func)(Image *, Image *, int, int, int, int, int),
|
||||
void (*zoomed_func)(Image*, const Image*, int, int, int, int, int),
|
||||
bool render_background,
|
||||
bool render_transparent)
|
||||
{
|
||||
@ -508,9 +543,9 @@ void RenderEngine::renderLayer(Sprite *sprite, Layer *layer, Image *image,
|
||||
(!render_transparent && !layer->is_background()))
|
||||
break;
|
||||
|
||||
Cel* cel = static_cast<LayerImage*>(layer)->get_cel(frame);
|
||||
const Cel* cel = static_cast<const LayerImage*>(layer)->get_cel(frame);
|
||||
if (cel != NULL) {
|
||||
Image* src_image;
|
||||
const Image* src_image;
|
||||
|
||||
/* is the 'rastering_image' setted to be used with this layer? */
|
||||
if ((frame == sprite->getCurrentFrame()) &&
|
||||
@ -535,15 +570,16 @@ void RenderEngine::renderLayer(Sprite *sprite, Layer *layer, Image *image,
|
||||
(*zoomed_func)(image, src_image,
|
||||
(cel->x << zoom) - source_x,
|
||||
(cel->y << zoom) - source_y,
|
||||
output_opacity, static_cast<LayerImage*>(layer)->get_blend_mode(), zoom);
|
||||
output_opacity,
|
||||
static_cast<const LayerImage*>(layer)->get_blend_mode(), zoom);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case GFXOBJ_LAYER_FOLDER: {
|
||||
LayerIterator it = static_cast<LayerFolder*>(layer)->get_layer_begin();
|
||||
LayerIterator end = static_cast<LayerFolder*>(layer)->get_layer_end();
|
||||
LayerConstIterator it = static_cast<const LayerFolder*>(layer)->get_layer_begin();
|
||||
LayerConstIterator end = static_cast<const LayerFolder*>(layer)->get_layer_end();
|
||||
|
||||
for (; it != end; ++it) {
|
||||
renderLayer(sprite, *it, image,
|
||||
|
@ -55,16 +55,29 @@ public:
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Main function used by sprite-editors to render the sprite
|
||||
|
||||
static Image* renderSprite(Sprite* sprite,
|
||||
static Image* renderSprite(const Sprite* sprite,
|
||||
int source_x, int source_y,
|
||||
int width, int height,
|
||||
int frpos, int zoom);
|
||||
int frpos, int zoom,
|
||||
bool draw_tiled_bg);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Extra functions
|
||||
|
||||
static void renderCheckedBackground(Image* image,
|
||||
int source_x, int source_y,
|
||||
int zoom);
|
||||
|
||||
static void renderImage(Image* rgb_image, Image* src_image,
|
||||
int x, int y, int zoom);
|
||||
|
||||
private:
|
||||
static void renderLayer(Sprite* sprite, Layer* layer, Image* image,
|
||||
static void renderLayer(const Sprite* sprite,
|
||||
const Layer* layer,
|
||||
Image* image,
|
||||
int source_x, int source_y,
|
||||
int frame, int zoom,
|
||||
void (*zoomed_func)(Image*, Image*, int, int, int, int, int),
|
||||
void (*zoomed_func)(Image*, const Image*, int, int, int, int, int),
|
||||
bool render_background,
|
||||
bool render_transparent);
|
||||
};
|
||||
|
@ -304,7 +304,7 @@ void Editor::editor_draw_sprite(int x1, int y1, int x2, int y2)
|
||||
source_x, source_y,
|
||||
width, height,
|
||||
m_sprite->getCurrentFrame(),
|
||||
m_zoom);
|
||||
m_zoom, true);
|
||||
|
||||
if (rendered) {
|
||||
#ifdef DRAWSPRITE_DOUBLEBUFFERED
|
||||
|
Loading…
x
Reference in New Issue
Block a user