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}; const s32 Size = CANVAS_SIZE / sprite->size; if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); s32 mx = getMouseX() - x; s32 my = getMouseY() - y; mx -= mx % Size; my -= my % Size; drawCursorBorder(sprite, x + mx, y + my, Size, Size); bool left = checkMouseClick(&rect, tic_mouse_left); bool right = checkMouseClick(&rect, tic_mouse_right); if(left || right) { s32 sx = l + mx / Size; s32 sy = t + my / Size; u8 color = getSheetPixel(sprite, sx, sy); u8 fill = left ? sprite->color : sprite->color2; if(color != fill) { tic->api.key(tic, tic_key_ctrl) ? 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); } } }
void PauseScene::checkEvents(sf::RenderWindow & window) { sf::Event event; while (window.pollEvent(event)) { checkMouseOnButtons(sf::Mouse::getPosition(window)); checkMouseClick(window, event); if (event.type == sf::Event::Closed) { window.close(); } } }
static void drawPalette(Sprite* sprite, s32 x, s32 y) { tic_rect rect = {x, y, PALETTE_WIDTH-1, PALETTE_HEIGHT-1}; if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); bool left = checkMouseDown(&rect, tic_mouse_left); bool right = checkMouseDown(&rect, tic_mouse_right); if(left || right) { s32 mx = getMouseX() - x; s32 my = getMouseY() - y; mx /= PALETTE_CELL_SIZE; my /= PALETTE_CELL_SIZE; s32 index = mx + my * PALETTE_COLS; if(left) sprite->color = index; if(right) sprite->color2 = index; } } sprite->tic->api.rect(sprite->tic, rect.x-1, rect.y-1, rect.w+2, rect.h+2, (tic_color_white)); sprite->tic->api.rect(sprite->tic, rect.x-1, rect.y+rect.h+1, PALETTE_WIDTH+1, 1, (tic_color_black)); { s32 offsetX = x + (sprite->color % PALETTE_COLS) * PALETTE_CELL_SIZE; s32 offsetY = y + (sprite->color / PALETTE_COLS) * PALETTE_CELL_SIZE; if(offsetY > y) sprite->tic->api.rect(sprite->tic, offsetX - 2, rect.y + rect.h+2, PALETTE_CELL_SIZE+3, 1, (tic_color_black)); } { static const u8 Icon[] = { 0b01000000, 0b11111111, 0b00000000, 0b00000010, 0b11111111, 0b00000000, 0b00010000, 0b11111111, }; tic_rect rect = {x + PALETTE_WIDTH + 3, y + (PALETTE_HEIGHT-8)/2-1, 8, 8}; bool down = false; bool over = false; if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); over = true; showTooltip("EDIT PALETTE"); if(checkMouseDown(&rect, tic_mouse_left)) down = true; if(checkMouseClick(&rect, tic_mouse_left)) sprite->editPalette = !sprite->editPalette; } if(sprite->editPalette || down) { drawBitIcon(rect.x, rect.y+1, Icon, (over ? tic_color_light_blue : tic_color_white)); } else { drawBitIcon(rect.x, rect.y+1, Icon, (tic_color_black)); drawBitIcon(rect.x, rect.y, Icon, (over ? tic_color_light_blue : tic_color_white)); } } }
static void drawRGBTools(Sprite* sprite, s32 x, s32 y) { { enum{Size = 5}; static const u8 Icon[] = { 0b11110000, 0b10010000, 0b10111000, 0b11101000, 0b00111000, 0b00000000, 0b00000000, 0b00000000, }; tic_rect rect = {x, y, Size, Size}; bool over = false; bool down = false; if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); showTooltip("COPY PALETTE"); over = true; if(checkMouseDown(&rect, tic_mouse_left)) down = true; if(checkMouseClick(&rect, tic_mouse_left)) toClipboard(getBankPalette()->data, sizeof(tic_palette), false); } if(down) { drawBitIcon(rect.x, rect.y+1, Icon, (tic_color_light_blue)); } else { drawBitIcon(rect.x, rect.y+1, Icon, (tic_color_black)); drawBitIcon(rect.x, rect.y, Icon, (over ? tic_color_light_blue : tic_color_white)); } } { enum{Size = 5}; static const u8 Icon[] = { 0b01110000, 0b10001000, 0b11111000, 0b11011000, 0b11111000, 0b00000000, 0b00000000, 0b00000000, }; tic_rect rect = {x + 8, y, Size, Size}; bool over = false; bool down = false; if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); showTooltip("PASTE PALETTE"); over = true; if(checkMouseDown(&rect, tic_mouse_left)) down = true; if(checkMouseClick(&rect, tic_mouse_left)) { pasteColor(sprite); } } if(down) { drawBitIcon(rect.x, rect.y+1, Icon, (tic_color_light_blue)); } else { drawBitIcon(rect.x, rect.y+1, Icon, (tic_color_black)); drawBitIcon(rect.x, rect.y, Icon, (over ? tic_color_light_blue : tic_color_white)); } } }
static void drawRGBSlider(Sprite* sprite, s32 x, s32 y, u8* value) { enum {Size = CANVAS_SIZE, Max = 255}; { static const u8 Icon[] = { 0b11100000, 0b11100000, 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, }; tic_rect rect = {x, y-2, Size, 5}; if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); if(checkMouseDown(&rect, tic_mouse_left)) { s32 mx = getMouseX() - x; *value = mx * Max / (Size-1); } } sprite->tic->api.rect(sprite->tic, x, y+1, Size, 1, (tic_color_black)); sprite->tic->api.rect(sprite->tic, x, y, Size, 1, (tic_color_white)); { s32 offset = x + *value * (Size-1) / Max - 1; drawBitIcon(offset, y, Icon, (tic_color_black)); drawBitIcon(offset, y-1, Icon, (tic_color_white)); } { char buf[] = "FF"; sprintf(buf, "%02X", *value); sprite->tic->api.text(sprite->tic, buf, x - 18, y - 2, (tic_color_dark_gray)); } } { static const u8 Icon[] = { 0b01000000, 0b11000000, 0b01000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, }; tic_rect rect = {x - 4, y - 1, 2, 3}; bool down = false; if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); if(checkMouseDown(&rect, tic_mouse_left)) down = true; if(checkMouseClick(&rect, tic_mouse_left)) (*value)--; } if(down) { drawBitIcon(rect.x, rect.y+1, Icon, (tic_color_white)); } else { drawBitIcon(rect.x, rect.y+1, Icon, (tic_color_black)); drawBitIcon(rect.x, rect.y, Icon, (tic_color_white)); } } { static const u8 Icon[] = { 0b10000000, 0b11000000, 0b10000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, }; tic_rect rect = {x + Size + 2, y - 1, 2, 3}; bool down = false; if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); if(checkMouseDown(&rect, tic_mouse_left)) down = true; if(checkMouseClick(&rect, tic_mouse_left)) (*value)++; } if(down) { drawBitIcon(rect.x, rect.y+1, Icon, (tic_color_white)); } else { drawBitIcon(rect.x, rect.y+1, Icon, (tic_color_black)); drawBitIcon(rect.x, rect.y, Icon, (tic_color_white)); } } }
static void drawMoveButtons(Sprite* sprite) { if(hasCanvasSelection(sprite)) { enum { x = 24 }; enum { y = 20 }; static const u8 Icons[] = { 0b00010000, 0b00111000, 0b01111100, 0b11111110, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11111110, 0b01111100, 0b00111000, 0b00010000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00010000, 0b00110000, 0b01110000, 0b11110000, 0b01110000, 0b00110000, 0b00010000, 0b00000000, 0b10000000, 0b11000000, 0b11100000, 0b11110000, 0b11100000, 0b11000000, 0b10000000, 0b00000000, }; static const tic_rect Rects[] = { {x + (CANVAS_SIZE - TIC_SPRITESIZE)/2, y - TIC_SPRITESIZE, TIC_SPRITESIZE, TIC_SPRITESIZE/2}, {x + (CANVAS_SIZE - TIC_SPRITESIZE)/2, y + CANVAS_SIZE + TIC_SPRITESIZE/2, TIC_SPRITESIZE, TIC_SPRITESIZE/2}, {x - TIC_SPRITESIZE, y + (CANVAS_SIZE - TIC_SPRITESIZE)/2, TIC_SPRITESIZE/2, TIC_SPRITESIZE}, {x + CANVAS_SIZE + TIC_SPRITESIZE/2, y + (CANVAS_SIZE - TIC_SPRITESIZE)/2, TIC_SPRITESIZE/2, TIC_SPRITESIZE}, }; static void(* const Func[])(Sprite*) = {upCanvas, downCanvas, leftCanvas, rightCanvas}; bool down = false; for(s32 i = 0; i < sizeof Icons / 8; i++) { down = false; if(checkMousePos(&Rects[i])) { setCursor(tic_cursor_hand); if(checkMouseDown(&Rects[i], tic_mouse_left)) down = true; if(checkMouseClick(&Rects[i], tic_mouse_left)) Func[i](sprite); } drawBitIcon(Rects[i].x, Rects[i].y+1, Icons + i*8, down ? (tic_color_white) : (tic_color_black)); if(!down) drawBitIcon(Rects[i].x, Rects[i].y, Icons + i*8, (tic_color_white)); } } }
static void drawSpriteToolbar(Sprite* sprite) { tic_mem* tic = sprite->tic; sprite->tic->api.rect(sprite->tic, 0, 0, TIC80_WIDTH, TOOLBAR_SIZE, (tic_color_white)); // draw sprite size control { tic_rect rect = {TIC80_WIDTH - 58, 1, 23, 5}; if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); showTooltip("CANVAS ZOOM"); if(checkMouseDown(&rect, tic_mouse_left)) { s32 mx = getMouseX() - rect.x; mx /= 6; s32 size = 1; while(mx--) size <<= 1; updateSpriteSize(sprite, size * TIC_SPRITESIZE); } } for(s32 i = 0; i < 4; i++) sprite->tic->api.rect(sprite->tic, rect.x + i*6, 1, 5, 5, (tic_color_black)); sprite->tic->api.rect(sprite->tic, rect.x, 2, 23, 3, (tic_color_black)); sprite->tic->api.rect(sprite->tic, rect.x+1, 3, 21, 1, (tic_color_white)); s32 size = sprite->size / TIC_SPRITESIZE, val = 0; while(size >>= 1) val++; sprite->tic->api.rect(sprite->tic, rect.x + val*6, 1, 5, 5, (tic_color_black)); sprite->tic->api.rect(sprite->tic, rect.x+1 + val*6, 2, 3, 3, (tic_color_white)); } bool bg = sprite->index < TIC_BANK_SPRITES; { static const char Label[] = "BG"; tic_rect rect = {TIC80_WIDTH - 2 * tic->font.width - 2, 0, 2 * tic->font.width + 1, TIC_SPRITESIZE-1}; sprite->tic->api.rect(sprite->tic, rect.x, rect.y, rect.w, rect.h, bg ? (tic_color_black) : (tic_color_gray)); sprite->tic->api.fixed_text(sprite->tic, Label, rect.x+1, rect.y+1, (tic_color_white)); if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); showTooltip("TILES [tab]"); if(!bg && checkMouseClick(&rect, tic_mouse_left)) { sprite->index -= TIC_BANK_SPRITES; clearCanvasSelection(sprite); } } } { static const char Label[] = "FG"; tic_rect rect = {TIC80_WIDTH - 4 * tic->font.width - 4, 0, 2 * tic->font.width + 1, TIC_SPRITESIZE-1}; sprite->tic->api.rect(sprite->tic, rect.x, rect.y, rect.w, rect.h, bg ? (tic_color_gray) : (tic_color_black)); sprite->tic->api.fixed_text(sprite->tic, Label, rect.x+1, rect.y+1, (tic_color_white)); if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); showTooltip("SPRITES [tab]"); if(bg && checkMouseClick(&rect, tic_mouse_left)) { sprite->index += TIC_BANK_SPRITES; clearCanvasSelection(sprite); } } } }
static void drawTools(Sprite* sprite, s32 x, s32 y) { static const u8 Icons[] = { 0b00001000, 0b00011100, 0b00111110, 0b01111100, 0b10111000, 0b10010000, 0b11100000, 0b00000000, 0b00111000, 0b00111000, 0b01111100, 0b00101000, 0b00101000, 0b00101000, 0b00010000, 0b00000000, 0b10101010, 0b00000000, 0b10000010, 0b00000000, 0b10000010, 0b00000000, 0b10101010, 0b00000000, 0b00001000, 0b00000100, 0b00000010, 0b01111111, 0b10111110, 0b10011100, 0b10001000, 0b00000000, }; enum{Gap = TIC_SPRITESIZE + 3}; for(s32 i = 0; i < COUNT_OF(Icons)/BITS_IN_BYTE; i++) { tic_rect rect = {x + i * Gap, y, TIC_SPRITESIZE, TIC_SPRITESIZE}; bool over = false; if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); over = true; static const char* Tooltips[] = {"BRUSH [1]", "COLOR PICKER [2]", "SELECT [3]", "FILL [4]"}; showTooltip(Tooltips[i]); if(checkMouseClick(&rect, tic_mouse_left)) { sprite->mode = i; clearCanvasSelection(sprite); } } bool pushed = i == sprite->mode; if(pushed) { static const u8 Icon[] = { 0b01111100, 0b00111000, 0b00010000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, }; drawBitIcon(rect.x, y - 4, Icon, (tic_color_black)); drawBitIcon(rect.x, y - 5, Icon, (tic_color_white)); drawBitIcon(rect.x, y + 1, Icons + i*BITS_IN_BYTE, (over ? tic_color_light_blue : tic_color_white)); } else { drawBitIcon(rect.x, y+1, Icons + i*BITS_IN_BYTE, (tic_color_black)); drawBitIcon(rect.x, y, Icons + i*BITS_IN_BYTE, (over ? tic_color_light_blue : tic_color_white)); } } drawSpriteTools(sprite, x + COUNT_OF(Icons)/BITS_IN_BYTE * Gap + 1, y); }
static void drawSpriteTools(Sprite* sprite, s32 x, s32 y) { static const u8 Icons[] = { 0b11101110, 0b11010110, 0b11101110, 0b11101110, 0b11101110, 0b11010110, 0b11101110, 0b00000000, 0b11111110, 0b11111110, 0b10111010, 0b01000100, 0b10111010, 0b11111110, 0b11111110, 0b00000000, 0b00111000, 0b01000100, 0b10010101, 0b10001110, 0b10000100, 0b01000000, 0b00111000, 0b00000000, 0b00111110, 0b01111111, 0b00101010, 0b00101010, 0b00101010, 0b00101010, 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++) { bool pushed = false; bool over = false; tic_rect rect = {x + i * Gap, y, TIC_SPRITESIZE, TIC_SPRITESIZE}; if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); over = true; showTooltip(Tooltips[i]); if(checkMouseDown(&rect, tic_mouse_left)) pushed = true; if(checkMouseClick(&rect, tic_mouse_left)) { if(hasCanvasSelection(sprite)) { CanvasToolsFunc[i](sprite); } else { SpriteToolsFunc[i](sprite); clearCanvasSelection(sprite); } } } if(pushed) { drawBitIcon(rect.x, y + 1, Icons + i*BITS_IN_BYTE, (over ? tic_color_light_blue : tic_color_white)); } else { drawBitIcon(rect.x, y+1, Icons + i*BITS_IN_BYTE, (tic_color_black)); drawBitIcon(rect.x, y, Icons + i*BITS_IN_BYTE, (over ? tic_color_light_blue : tic_color_white)); } } }