Merge pull request #464 from frenetic/enable-delete-canvas
Enable deleting a selection by pressing DEL on keyboard
This commit is contained in:
commit
80695209a4
41
src/sprite.c
41
src/sprite.c
|
@ -31,6 +31,11 @@
|
|||
#define PALETTE_HEIGHT (PALETTE_ROWS * PALETTE_CELL_SIZE)
|
||||
#define SHEET_COLS (TIC_SPRITESHEET_SIZE / TIC_SPRITESIZE)
|
||||
|
||||
static void clearCanvasSelection(Sprite* sprite)
|
||||
{
|
||||
SDL_memset(&sprite->select.rect, 0, sizeof(SDL_Rect));
|
||||
}
|
||||
|
||||
static u8 getSheetPixel(Sprite* sprite, s32 x, s32 y)
|
||||
{
|
||||
return getSpritePixel(sprite->tic->cart.bank.tiles.data, x, sprite->index >= TIC_BANK_SPRITES ? y + TIC_SPRITESHEET_SIZE: y);
|
||||
|
@ -446,6 +451,24 @@ static void rightCanvas(Sprite* sprite)
|
|||
pasteSelection(sprite);
|
||||
}
|
||||
|
||||
static void deleteCanvas(Sprite* sprite)
|
||||
{
|
||||
SDL_Rect* rect = &sprite->select.rect;
|
||||
|
||||
s32 left = getIndexPosX(sprite) + rect->x;
|
||||
s32 top = getIndexPosY(sprite) + rect->y;
|
||||
s32 right = left + rect->w;
|
||||
s32 bottom = top + rect->h;
|
||||
|
||||
for(s32 pixel_y = top; pixel_y < bottom; pixel_y++)
|
||||
for(s32 pixel_x = left; pixel_x < right; pixel_x++)
|
||||
setSheetPixel(sprite, pixel_x, pixel_y, sprite->color2);
|
||||
|
||||
clearCanvasSelection(sprite);
|
||||
|
||||
history_add(sprite->history);
|
||||
}
|
||||
|
||||
static void drawMoveButtons(Sprite* sprite)
|
||||
{
|
||||
if(hasCanvasSelection(sprite))
|
||||
|
@ -502,9 +525,10 @@ static void drawMoveButtons(Sprite* sprite)
|
|||
|
||||
static void(* const Func[])(Sprite*) = {upCanvas, downCanvas, leftCanvas, rightCanvas};
|
||||
|
||||
bool down = false;
|
||||
for(s32 i = 0; i < sizeof Icons / 8; i++)
|
||||
{
|
||||
bool down = false;
|
||||
down = false;
|
||||
|
||||
if(checkMousePos(&Rects[i]))
|
||||
{
|
||||
|
@ -882,11 +906,6 @@ static void drawPaletteOvr(Sprite* sprite, s32 x, s32 y)
|
|||
}
|
||||
}
|
||||
|
||||
static void clearCanvasSelection(Sprite* sprite)
|
||||
{
|
||||
SDL_memset(&sprite->select.rect, 0, sizeof(SDL_Rect));
|
||||
}
|
||||
|
||||
static void selectSprite(Sprite* sprite, s32 x, s32 y)
|
||||
{
|
||||
{
|
||||
|
@ -1067,23 +1086,23 @@ static void drawSpriteTools(Sprite* sprite, s32 x, s32 y)
|
|||
0b00111110,
|
||||
0b00000000,
|
||||
};
|
||||
static const char* Tooltips[] = {"FLIP HORZ [5]", "FLIP VERT [6]", "ROTATE [7]", "ERASE [8]"};
|
||||
|
||||
enum{Gap = TIC_SPRITESIZE + 3};
|
||||
|
||||
for(s32 i = 0; i < COUNT_OF(Icons)/BITS_IN_BYTE; i++)
|
||||
{
|
||||
SDL_Rect rect = {x + i * Gap, y, TIC_SPRITESIZE, TIC_SPRITESIZE};
|
||||
|
||||
bool pushed = false;
|
||||
bool over = false;
|
||||
|
||||
SDL_Rect rect = {x + i * Gap, y, TIC_SPRITESIZE, TIC_SPRITESIZE};
|
||||
|
||||
if(checkMousePos(&rect))
|
||||
{
|
||||
setCursor(SDL_SYSTEM_CURSOR_HAND);
|
||||
|
||||
over = true;
|
||||
|
||||
static const char* Tooltips[] = {"FLIP HORZ [5]", "FLIP VERT [6]", "ROTATE [7]", "ERASE [8]"};
|
||||
|
||||
showTooltip(Tooltips[i]);
|
||||
|
||||
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) pushed = true;
|
||||
|
@ -1327,7 +1346,7 @@ static void processKeydown(Sprite* sprite, SDL_Keycode keycode)
|
|||
case SDLK_DOWN: downCanvas(sprite); break;
|
||||
case SDLK_LEFT: leftCanvas(sprite); break;
|
||||
case SDLK_RIGHT: rightCanvas(sprite); break;
|
||||
case SDLK_DELETE: deleteSprite(sprite); break;
|
||||
case SDLK_DELETE: deleteCanvas(sprite); break;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue