keyboard works in the Sprite Editor

This commit is contained in:
BADIM-PC\Vadim 2018-02-12 19:37:44 +03:00
parent 0b693b3365
commit d7ef53a457
1 changed files with 68 additions and 93 deletions

View File

@ -274,6 +274,7 @@ static void replaceColor(Sprite* sprite, s32 l, s32 t, s32 r, s32 b, s32 x, s32
static void processFillCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 l, s32 t) static void processFillCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 l, s32 t)
{ {
tic_mem* tic = sprite->tic;
tic_rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; tic_rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE};
const s32 Size = CANVAS_SIZE / sprite->size; const s32 Size = CANVAS_SIZE / sprite->size;
@ -294,20 +295,18 @@ static void processFillCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 l, s32 t)
if(left || right) if(left || right)
{ {
// s32 sx = l + mx / Size; s32 sx = l + mx / Size;
// s32 sy = t + my / Size; s32 sy = t + my / Size;
// u8 color = getSheetPixel(sprite, sx, sy); u8 color = getSheetPixel(sprite, sx, sy);
// u8 fill = left ? sprite->color : sprite->color2; u8 fill = left ? sprite->color : sprite->color2;
// if(color != fill) if(color != fill)
// { {
// SDL_Keymod keymod = SDL_GetModState(); tic->api.key(tic, tic_key_ctrl)
? replaceColor(sprite, l, t, l + sprite->size-1, t + sprite->size-1, sx, sy, color, fill)
// keymod & TIC_MOD_CTRL : floodFill(sprite, l, t, l + sprite->size-1, t + sprite->size-1, sx, sy, color, fill);
// ? replaceColor(sprite, l, t, l + sprite->size-1, t + sprite->size-1, sx, sy, color, fill) }
// : floodFill(sprite, l, t, l + sprite->size-1, t + sprite->size-1, sx, sy, color, fill);
// }
history_add(sprite->history); history_add(sprite->history);
} }
@ -1428,81 +1427,66 @@ static void switchBanks(Sprite* sprite)
clearCanvasSelection(sprite); clearCanvasSelection(sprite);
} }
// static void processKeydown(Sprite* sprite, tic_keycode keycode) static void processKeyboard(Sprite* sprite)
// { {
// switch(getClipboardEvent()) tic_mem* tic = sprite->tic;
// {
// case TIC_CLIPBOARD_CUT: cutToClipboard(sprite); break;
// case TIC_CLIPBOARD_COPY: copyToClipboard(sprite); break;
// case TIC_CLIPBOARD_PASTE: copyFromClipboard(sprite); break;
// default: break;
// }
// SDL_Keymod keymod = SDL_GetModState(); switch(getClipboardEvent())
{
case TIC_CLIPBOARD_CUT: cutToClipboard(sprite); break;
case TIC_CLIPBOARD_COPY: copyToClipboard(sprite); break;
case TIC_CLIPBOARD_PASTE: copyFromClipboard(sprite); break;
default: break;
}
// if(keymod & TIC_MOD_CTRL) bool ctrl = tic->api.key(tic, tic_key_ctrl);
// {
// switch(keycode)
// {
// case SDLK_z: undo(sprite); break;
// case SDLK_y: redo(sprite); break;
// }
// }
// else
// {
// if(hasCanvasSelection(sprite))
// {
// switch(keycode)
// {
// case SDLK_UP: upCanvas(sprite); break;
// case SDLK_DOWN: downCanvas(sprite); break;
// case SDLK_LEFT: leftCanvas(sprite); break;
// case SDLK_RIGHT: rightCanvas(sprite); break;
// case SDLK_DELETE: deleteCanvas(sprite); break;
// }
// }
// else
// {
// switch(keycode)
// {
// case SDLK_DELETE: deleteSprite(sprite); break;
// case SDLK_UP: upSprite(sprite); break;
// case SDLK_DOWN: downSprite(sprite); break;
// case SDLK_LEFT: leftSprite(sprite); break;
// case SDLK_RIGHT: rightSprite(sprite); break;
// case SDLK_TAB: switchBanks(sprite); break;
// }
// if(!sprite->editPalette) if(ctrl)
// { {
// switch(keycode) if(isKeyBeenPressed(tic_key_z)) undo(sprite);
// { else if(isKeyBeenPressed(tic_key_y)) redo(sprite);
// case SDLK_1: }
// case SDLK_2: else
// case SDLK_3: {
// case SDLK_4: if(hasCanvasSelection(sprite))
// sprite->mode = keycode - SDLK_1; {
// break; if(isKeyBeenPressed(tic_key_up)) upCanvas(sprite);
// case SDLK_5: else if(isKeyBeenPressed(tic_key_down)) downCanvas(sprite);
// case SDLK_6: else if(isKeyBeenPressed(tic_key_left)) leftCanvas(sprite);
// case SDLK_7: else if(isKeyBeenPressed(tic_key_right)) rightCanvas(sprite);
// case SDLK_8: else if(isKeyBeenPressed(tic_key_delete)) deleteCanvas(sprite);
// SpriteToolsFunc[keycode - SDLK_5](sprite); }
// break; else
// } {
if(isKeyBeenPressed(tic_key_up)) upSprite(sprite);
else if(isKeyBeenPressed(tic_key_down)) downSprite(sprite);
else if(isKeyBeenPressed(tic_key_left)) leftSprite(sprite);
else if(isKeyBeenPressed(tic_key_right)) rightSprite(sprite);
else if(isKeyBeenPressed(tic_key_delete)) deleteSprite(sprite);
else if(isKeyBeenPressed(tic_key_tab)) switchBanks(sprite);
// if(sprite->mode == SPRITE_DRAW_MODE) if(!sprite->editPalette)
// { {
// switch(keycode)
// { if(isKeyBeenPressed(tic_key_1)) sprite->mode = SPRITE_DRAW_MODE;
// case SDLK_LEFTBRACKET: if(sprite->brushSize > 1) sprite->brushSize--; break; else if(isKeyBeenPressed(tic_key_2)) sprite->mode = SPRITE_PICK_MODE;
// case SDLK_RIGHTBRACKET: if(sprite->brushSize < 4) sprite->brushSize++; break; else if(isKeyBeenPressed(tic_key_3)) sprite->mode = SPRITE_SELECT_MODE;
// } else if(isKeyBeenPressed(tic_key_4)) sprite->mode = SPRITE_FILL_MODE;
// }
// } else if(isKeyBeenPressed(tic_key_5)) flipSpriteHorz(sprite);
// } else if(isKeyBeenPressed(tic_key_6)) flipSpriteVert(sprite);
// } else if(isKeyBeenPressed(tic_key_7)) rotateSprite(sprite);
// } else if(isKeyBeenPressed(tic_key_8)) deleteSprite(sprite);
if(sprite->mode == SPRITE_DRAW_MODE)
{
if(isKeyBeenPressed(tic_key_leftbracket)) {if(sprite->brushSize > 1) sprite->brushSize--;}
else if(isKeyBeenPressed(tic_key_rightbracket)) {if(sprite->brushSize < 4) sprite->brushSize++;}
}
}
}
}
}
static void drawSpriteToolbar(Sprite* sprite) static void drawSpriteToolbar(Sprite* sprite)
{ {
@ -1607,16 +1591,7 @@ static void tick(Sprite* sprite)
} }
} }
// SDL_Event* event = NULL; processKeyboard(sprite);
// while ((event = pollEvent()))
// {
// switch(event->type)
// {
// case SDL_KEYDOWN:
// processKeydown(sprite, event->key.keysym.sym);
// break;
// }
// }
sprite->tic->api.clear(sprite->tic, (tic_color_gray)); sprite->tic->api.clear(sprite->tic, (tic_color_gray));