Merge pull request #495 from frenetic/flip_canvas

Enable horizontal or vertical flipping of a sprite selection
This commit is contained in:
Vadim Grigoruk 2018-01-04 13:18:15 +03:00 committed by GitHub
commit 908757880b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 55 additions and 3 deletions

View File

@ -469,6 +469,48 @@ static void deleteCanvas(Sprite* sprite)
history_add(sprite->history); history_add(sprite->history);
} }
static void flipCanvasHorz(Sprite* sprite)
{
SDL_Rect* rect = &sprite->select.rect;
s32 sprite_x = getIndexPosX(sprite);
s32 sprite_y = getIndexPosY(sprite);
s32 right = sprite_x + rect->x + rect->w/2;
s32 bottom = sprite_y + rect->y + rect->h;
for(s32 y = sprite_y + rect->y; y < bottom; y++)
for(s32 x = sprite_x + rect->x, i = sprite_x + rect->x + rect->w - 1; x < right; x++, i--)
{
u8 color = getSheetPixel(sprite, x, y);
setSheetPixel(sprite, x, y, getSheetPixel(sprite, i, y));
setSheetPixel(sprite, i, y, color);
}
history_add(sprite->history);
}
static void flipCanvasVert(Sprite* sprite)
{
SDL_Rect* rect = &sprite->select.rect;
s32 sprite_x = getIndexPosX(sprite);
s32 sprite_y = getIndexPosY(sprite);
s32 right = sprite_x + rect->x + rect->w;
s32 bottom = sprite_y + rect->y + rect->h/2;
for(s32 y = sprite_y + rect->y, i = sprite_y + rect->y + rect->h - 1; y < bottom; y++, i--)
for(s32 x = sprite_x + rect->x; x < right; x++)
{
u8 color = getSheetPixel(sprite, x, y);
setSheetPixel(sprite, x, y, getSheetPixel(sprite, x, i));
setSheetPixel(sprite, x, i, color);
}
history_add(sprite->history);
}
static void drawMoveButtons(Sprite* sprite) static void drawMoveButtons(Sprite* sprite)
{ {
if(hasCanvasSelection(sprite)) if(hasCanvasSelection(sprite))
@ -1045,6 +1087,7 @@ static void deleteSprite(Sprite* sprite)
} }
static void(* const SpriteToolsFunc[])(Sprite*) = {flipSpriteHorz, flipSpriteVert, rotateSprite, deleteSprite}; static void(* const SpriteToolsFunc[])(Sprite*) = {flipSpriteHorz, flipSpriteVert, rotateSprite, deleteSprite};
static void(* const CanvasToolsFunc[])(Sprite*) = {flipCanvasHorz, flipCanvasVert, rotateSprite, deleteCanvas};
static void drawSpriteTools(Sprite* sprite, s32 x, s32 y) static void drawSpriteTools(Sprite* sprite, s32 x, s32 y)
{ {
@ -1108,9 +1151,18 @@ static void drawSpriteTools(Sprite* sprite, s32 x, s32 y)
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) pushed = true; if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) pushed = true;
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, SDL_BUTTON_LEFT))
{ {
SpriteToolsFunc[i](sprite); if(hasCanvasSelection(sprite))
clearCanvasSelection(sprite); {
CanvasToolsFunc[i](sprite);
// we have to do this until we deal with rotateSprite for canvas
if(i == 2) clearCanvasSelection(sprite);
}
else
{
SpriteToolsFunc[i](sprite);
clearCanvasSelection(sprite);
}
} }
} }