From a525df2eba9d9411be3485d00c4ee4716694e808 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Thu, 1 Feb 2018 19:34:42 +0300 Subject: [PATCH] removed SDL_Rect and SDL_Point --- src/code.c | 6 +- src/code.h | 4 +- src/console.c | 2 +- src/dialog.c | 8 +-- src/dialog.h | 4 +- src/map.c | 68 +++++++++--------- src/map.h | 12 ++-- src/menu.c | 22 +++--- src/menu.h | 4 +- src/music.c | 42 +++++------ src/music.h | 4 +- src/sfx.c | 40 +++++------ src/sprite.c | 92 ++++++++++++------------ src/sprite.h | 4 +- src/studio.c | 194 ++++++++++++++++++++++++++------------------------ src/studio.h | 18 +++-- src/world.c | 2 +- 17 files changed, 272 insertions(+), 254 deletions(-) diff --git a/src/code.c b/src/code.c index a2d45e7..8919b4e 100644 --- a/src/code.c +++ b/src/code.c @@ -968,7 +968,7 @@ static void processKeydown(Code* code, SDL_Keycode keycode) static void processGestures(Code* code) { - SDL_Point point = {0, 0}; + tic_point point = {0, 0}; if(getGesturePos(&point)) { @@ -1276,7 +1276,7 @@ static void textGoToTick(Code* code) static void drawOutlineBar(Code* code, s32 x, s32 y) { - SDL_Rect rect = {x, y, TIC80_WIDTH - x, TIC80_HEIGHT - y}; + tic_rect rect = {x, y, TIC80_WIDTH - x, TIC80_HEIGHT - y}; if(checkMousePos(&rect)) { @@ -1429,7 +1429,7 @@ static void drawCodeToolbar(Code* code) for(s32 i = 0; i < Count; i++) { - SDL_Rect rect = {TIC80_WIDTH + (i - Count) * Size, 0, Size, Size}; + tic_rect rect = {TIC80_WIDTH + (i - Count) * Size, 0, Size, Size}; bool over = false; if(checkMousePos(&rect)) diff --git a/src/code.h b/src/code.h index 70e196d..b387f8d 100644 --- a/src/code.h +++ b/src/code.h @@ -47,14 +47,14 @@ struct Code s32 delay; } cursor; - SDL_Rect rect; + tic_rect rect; struct { s32 x; s32 y; - SDL_Point start; + tic_point start; bool active; bool gesture; diff --git a/src/console.c b/src/console.c index 95129a1..40ffc08 100644 --- a/src/console.c +++ b/src/console.c @@ -2493,7 +2493,7 @@ static void setScroll(Console* console, s32 val) static void processGesture(Console* console) { - SDL_Point point = {0, 0}; + tic_point point = {0, 0}; if(getGesturePos(&point)) { diff --git a/src/dialog.c b/src/dialog.c index 9aa55f3..20a11f4 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -28,7 +28,7 @@ static void drawButton(Dialog* dlg, const char* label, s32 x, s32 y, u8 color, u enum {BtnWidth = 20, BtnHeight = 9}; - SDL_Rect rect = {x, y, BtnWidth, BtnHeight}; + tic_rect rect = {x, y, BtnWidth, BtnHeight}; bool down = false; bool over = false; @@ -121,12 +121,12 @@ static void drawDialog(Dialog* dlg) tic_mem* tic = dlg->tic; - SDL_Rect rect = {(TIC80_WIDTH - Width)/2, (TIC80_HEIGHT - Height)/2, Width, Height}; + tic_rect rect = {(TIC80_WIDTH - Width)/2, (TIC80_HEIGHT - Height)/2, Width, Height}; rect.x -= dlg->pos.x; rect.y -= dlg->pos.y; - SDL_Rect header = {rect.x, rect.y-(TOOLBAR_SIZE-1), rect.w, TOOLBAR_SIZE}; + tic_rect header = {rect.x, rect.y-(TOOLBAR_SIZE-1), rect.w, TOOLBAR_SIZE}; if(checkMousePos(&header)) { @@ -151,7 +151,7 @@ static void drawDialog(Dialog* dlg) dlg->pos.x = dlg->drag.start.x - getMouseX(); dlg->pos.y = dlg->drag.start.y - getMouseY(); - SDL_Rect rect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT}; + tic_rect rect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT}; if(!checkMouseDown(&rect, tic_mouse_left)) dlg->drag.active = false; } diff --git a/src/dialog.h b/src/dialog.h index 09326c6..3f4504c 100644 --- a/src/dialog.h +++ b/src/dialog.h @@ -39,11 +39,11 @@ struct Dialog u32 focus; - SDL_Point pos; + tic_point pos; struct { - SDL_Point start; + tic_point start; bool active; } drag; diff --git a/src/map.c b/src/map.c index 50230a3..411e43e 100644 --- a/src/map.c +++ b/src/map.c @@ -47,14 +47,14 @@ static void normalizeMap(s32* x, s32* y) while(*y >= MAX_SCROLL_Y) *y -= MAX_SCROLL_Y; } -static SDL_Point getTileOffset(Map* map) +static tic_point getTileOffset(Map* map) { - return (SDL_Point){(map->sheet.rect.w - 1)*TIC_SPRITESIZE / 2, (map->sheet.rect.h - 1)*TIC_SPRITESIZE / 2}; + return (tic_point){(map->sheet.rect.w - 1)*TIC_SPRITESIZE / 2, (map->sheet.rect.h - 1)*TIC_SPRITESIZE / 2}; } static void getMouseMap(Map* map, s32* x, s32* y) { - SDL_Point offset = getTileOffset(map); + tic_point offset = getTileOffset(map); s32 mx = getMouseX() + map->scroll.x - offset.x; s32 my = getMouseY() + map->scroll.y - offset.y; @@ -83,7 +83,7 @@ static s32 drawWorldButton(Map* map, s32 x, s32 y) x -= Size; - SDL_Rect rect = {x, y, Size, ICON_SIZE}; + tic_rect rect = {x, y, Size, ICON_SIZE}; bool over = false; @@ -121,7 +121,7 @@ static s32 drawGridButton(Map* map, s32 x, s32 y) x -= ICON_SIZE; - SDL_Rect rect = {x, y, ICON_SIZE, ICON_SIZE}; + tic_rect rect = {x, y, ICON_SIZE, ICON_SIZE}; bool over = false; @@ -170,7 +170,7 @@ static s32 drawSheetButton(Map* map, s32 x, s32 y) x -= ICON_SIZE; - SDL_Rect rect = {x, y, ICON_SIZE, ICON_SIZE}; + tic_rect rect = {x, y, ICON_SIZE, ICON_SIZE}; bool over = false; if(checkMousePos(&rect)) @@ -195,7 +195,7 @@ static s32 drawToolButton(Map* map, s32 x, s32 y, const u8* Icon, s32 width, con { x -= width; - SDL_Rect rect = {x, y, width, ICON_SIZE}; + tic_rect rect = {x, y, width, ICON_SIZE}; bool over = false; if(checkMousePos(&rect)) @@ -293,7 +293,7 @@ static void drawTileIndex(Map* map, s32 x, s32 y) if(map->sheet.show) { - SDL_Rect rect = {TIC80_WIDTH - TIC_SPRITESHEET_SIZE - 1, TOOLBAR_SIZE, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; + tic_rect rect = {TIC80_WIDTH - TIC_SPRITESHEET_SIZE - 1, TOOLBAR_SIZE, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; if(checkMousePos(&rect)) { @@ -308,7 +308,7 @@ static void drawTileIndex(Map* map, s32 x, s32 y) } else { - SDL_Rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; + tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; if(checkMousePos(&rect)) { @@ -346,7 +346,7 @@ static void drawSheet(Map* map, s32 x, s32 y) { if(!map->sheet.show)return; - SDL_Rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; + tic_rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; map->tic->api.rect_border(map->tic, rect.x - 1, rect.y - 1, rect.w + 2, rect.h + 2, (tic_color_white)); } @@ -355,7 +355,7 @@ static void drawSheetOvr(Map* map, s32 x, s32 y) { if(!map->sheet.show)return; - SDL_Rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; + tic_rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; if(checkMousePos(&rect)) { @@ -376,14 +376,14 @@ static void drawSheetOvr(Map* map, s32 x, s32 y) s32 rr = SDL_max(mx, map->sheet.start.x); s32 rb = SDL_max(my, map->sheet.start.y); - map->sheet.rect = (SDL_Rect){rl, rt, rr-rl+1, rb-rt+1}; + map->sheet.rect = (tic_rect){rl, rt, rr-rl+1, rb-rt+1}; map->mode = MAP_DRAW_MODE; } else { map->sheet.drag = true; - map->sheet.start = (SDL_Point){mx, my}; + map->sheet.start = (tic_point){mx, my}; } } else @@ -447,7 +447,7 @@ static void drawTileCursor(Map* map) if(map->scroll.active) return; - SDL_Point offset = getTileOffset(map); + tic_point offset = getTileOffset(map); s32 mx = getMouseX() + map->scroll.x - offset.x; s32 my = getMouseY() + map->scroll.y - offset.y; @@ -478,7 +478,7 @@ static void drawTileCursor(Map* map) static void processMouseDrawMode(Map* map) { - SDL_Rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; + tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; setCursor(SDL_SYSTEM_CURSOR_HAND); @@ -500,7 +500,7 @@ static void processMouseDrawMode(Map* map) else { map->canvas.draw = true; - map->canvas.start = (SDL_Point){tx, ty}; + map->canvas.start = (tic_point){tx, ty}; } } else @@ -514,13 +514,13 @@ static void processMouseDrawMode(Map* map) getMouseMap(map, &tx, &ty); s32 index = map->tic->api.map_get(map->tic, map->src, tx, ty); - map->sheet.rect = (SDL_Rect){index % SHEET_COLS, index / SHEET_COLS, 1, 1}; + map->sheet.rect = (tic_rect){index % SHEET_COLS, index / SHEET_COLS, 1, 1}; } } static void processScrolling(Map* map, bool pressed) { - SDL_Rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; + tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; if(map->scroll.active) { @@ -549,7 +549,7 @@ static void processScrolling(Map* map, bool pressed) static void processMouseDragMode(Map* map) { - SDL_Rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; + tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; processScrolling(map, checkMouseDown(&rect, tic_mouse_left) || checkMouseDown(&rect, tic_mouse_right)); @@ -557,7 +557,7 @@ static void processMouseDragMode(Map* map) static void resetSelection(Map* map) { - map->select.rect = (SDL_Rect){0,0,0,0}; + map->select.rect = (tic_rect){0,0,0,0}; } static void drawSelectionRect(Map* map, s32 x, s32 y, s32 w, s32 h) @@ -582,7 +582,7 @@ static void drawPasteData(Map* map) s32 mx = getMouseX() + map->scroll.x - (w - 1)*TIC_SPRITESIZE / 2; s32 my = getMouseY() + map->scroll.y - (h - 1)*TIC_SPRITESIZE / 2; - SDL_Rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; + tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; if(checkMouseClick(&rect, tic_mouse_left)) { @@ -626,7 +626,7 @@ static void normalizeMapRect(s32* x, s32* y) static void processMouseSelectMode(Map* map) { - SDL_Rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; + tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; if(checkMousePos(&rect)) { @@ -651,13 +651,13 @@ static void processMouseSelectMode(Map* map) s32 rr = SDL_max(mx, map->select.start.x); s32 rb = SDL_max(my, map->select.start.y); - map->select.rect = (SDL_Rect){rl, rt, rr - rl + 1, rb - rt + 1}; + map->select.rect = (tic_rect){rl, rt, rr - rl + 1, rb - rt + 1}; } else { map->select.drag = true; - map->select.start = (SDL_Point){mx, my}; - map->select.rect = (SDL_Rect){map->select.start.x, map->select.start.y, 1, 1}; + map->select.start = (tic_point){mx, my}; + map->select.rect = (tic_rect){map->select.start.x, map->select.start.y, 1, 1}; } } else if(map->select.drag) @@ -673,8 +673,8 @@ static void processMouseSelectMode(Map* map) typedef struct { - SDL_Point* data; - SDL_Point* head; + tic_point* data; + tic_point* head; } FillStack; static bool push(FillStack* stack, s32 x, s32 y) @@ -732,7 +732,7 @@ static void fillMap(Map* map, s32 x, s32 y, u8 tile) static FillStack stack = {NULL, NULL}; if(!stack.data) - stack.data = (SDL_Point*)SDL_malloc(FILL_STACK_SIZE * sizeof(SDL_Point)); + stack.data = (tic_point*)SDL_malloc(FILL_STACK_SIZE * sizeof(tic_point)); stack.head = NULL; @@ -790,7 +790,7 @@ static void fillMap(Map* map, s32 x, s32 y, u8 tile) static void processMouseFillMode(Map* map) { - SDL_Rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; + tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; setCursor(SDL_SYSTEM_CURSOR_HAND); @@ -808,7 +808,7 @@ static void processMouseFillMode(Map* map) static void drawSelection(Map* map) { - SDL_Rect* sel = &map->select.rect; + tic_rect* sel = &map->select.rect; if(sel->w > 0 && sel->h > 0) { @@ -859,7 +859,7 @@ static void drawGrid(Map* map) static void drawMapOvr(Map* map) { - SDL_Rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; + tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; s32 scrollX = map->scroll.x % TIC_SPRITESIZE; s32 scrollY = map->scroll.y % TIC_SPRITESIZE; @@ -933,7 +933,7 @@ static void redo(Map* map) static void copySelectionToClipboard(Map* map) { - SDL_Rect* sel = &map->select.rect; + tic_rect* sel = &map->select.rect; if(sel->w > 0 && sel->h > 0) { @@ -971,7 +971,7 @@ static void copyToClipboard(Map* map) static void deleteSelection(Map* map) { - SDL_Rect* sel = &map->select.rect; + tic_rect* sel = &map->select.rect; if(sel->w > 0 && sel->h > 0) { @@ -1079,7 +1079,7 @@ static void processKeyup(Map* map, SDL_Keycode keycode) static void processGesture(Map* map) { - SDL_Point point = {0, 0}; + tic_point point = {0, 0}; if(getGesturePos(&point)) { diff --git a/src/map.h b/src/map.h index 7c9f173..cd02071 100644 --- a/src/map.h +++ b/src/map.h @@ -46,14 +46,14 @@ struct Map { bool grid; bool draw; - SDL_Point start; + tic_point start; } canvas; struct { bool show; - SDL_Rect rect; - SDL_Point start; + tic_rect rect; + tic_point start; bool drag; } sheet; @@ -62,7 +62,7 @@ struct Map s32 x; s32 y; - SDL_Point start; + tic_point start; bool active; bool gesture; @@ -71,8 +71,8 @@ struct Map struct { - SDL_Rect rect; - SDL_Point start; + tic_rect rect; + tic_point start; bool drag; } select; diff --git a/src/menu.c b/src/menu.c index 972607f..0cb7953 100644 --- a/src/menu.c +++ b/src/menu.c @@ -63,9 +63,9 @@ static void exitToTIC(Menu* menu) static void(*const MenuHandlers[])(Menu*) = {resumeGame, resetGame, gamepadConfig, NULL, exitToTIC}; -static SDL_Rect getRect(Menu* menu) +static tic_rect getRect(Menu* menu) { - SDL_Rect rect = {(TIC80_WIDTH - DIALOG_WIDTH)/2, (TIC80_HEIGHT - DIALOG_HEIGHT)/2, DIALOG_WIDTH, DIALOG_HEIGHT}; + tic_rect rect = {(TIC80_WIDTH - DIALOG_WIDTH)/2, (TIC80_HEIGHT - DIALOG_HEIGHT)/2, DIALOG_WIDTH, DIALOG_HEIGHT}; rect.x -= menu->pos.x; rect.y -= menu->pos.y; @@ -74,11 +74,11 @@ static SDL_Rect getRect(Menu* menu) } static void drawDialog(Menu* menu) { - SDL_Rect rect = getRect(menu); + tic_rect rect = getRect(menu); tic_mem* tic = menu->tic; - SDL_Rect header = {rect.x, rect.y-(TOOLBAR_SIZE-1), rect.w, TOOLBAR_SIZE}; + tic_rect header = {rect.x, rect.y-(TOOLBAR_SIZE-1), rect.w, TOOLBAR_SIZE}; if(checkMousePos(&header)) { @@ -103,7 +103,7 @@ static void drawDialog(Menu* menu) menu->pos.x = menu->drag.start.x - getMouseX(); menu->pos.y = menu->drag.start.y - getMouseY(); - SDL_Rect rect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT}; + tic_rect rect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT}; if(!checkMouseDown(&rect, tic_mouse_left)) menu->drag.active = false; } @@ -133,7 +133,7 @@ static void drawTabDisabled(Menu* menu, s32 x, s32 y, s32 id) enum{Width = 15, Height = 7}; tic_mem* tic = menu->tic; - SDL_Rect rect = {x, y, Width, Height}; + tic_rect rect = {x, y, Width, Height}; bool over = false; if(menu->gamepad.tab != id && checkMousePos(&rect)) @@ -189,7 +189,7 @@ static void drawPlayerButtons(Menu* menu, s32 x, s32 y) for(s32 i = 0; i < Buttons; i++) { - SDL_Rect rect = {x + i / Rows * (Width+2), y + (i%Rows)*(Height+1), Width, TIC_SPRITESIZE}; + tic_rect rect = {x + i / Rows * (Width+2), y + (i%Rows)*(Height+1), Width, TIC_SPRITESIZE}; bool over = false; s32 index = i+menu->gamepad.tab * Buttons; @@ -246,11 +246,11 @@ static void drawGamepadMenu(Menu* menu) tic_mem* tic = menu->tic; - SDL_Rect dlgRect = getRect(menu); + tic_rect dlgRect = getRect(menu); static const char Label[] = "BACK"; - SDL_Rect rect = {dlgRect.x + 25, dlgRect.y + 49, (sizeof(Label)-1)*TIC_FONT_WIDTH, TIC_FONT_HEIGHT}; + tic_rect rect = {dlgRect.x + 25, dlgRect.y + 49, (sizeof(Label)-1)*TIC_FONT_WIDTH, TIC_FONT_HEIGHT}; bool over = false; bool down = false; @@ -311,14 +311,14 @@ static void drawMainMenu(Menu* menu) drawDialog(menu); - SDL_Rect rect = getRect(menu); + tic_rect rect = getRect(menu); { for(s32 i = 0; i < COUNT_OF(Rows); i++) { if(!*Rows[i])continue; - SDL_Rect label = {rect.x + 22, rect.y + (TIC_FONT_HEIGHT+1)*i + 16, 86, TIC_FONT_HEIGHT+1}; + tic_rect label = {rect.x + 22, rect.y + (TIC_FONT_HEIGHT+1)*i + 16, 86, TIC_FONT_HEIGHT+1}; bool over = false; bool down = false; diff --git a/src/menu.h b/src/menu.h index b290516..95731bb 100644 --- a/src/menu.h +++ b/src/menu.h @@ -46,11 +46,11 @@ struct Menu s32 selected; } gamepad; - SDL_Point pos; + tic_point pos; struct { - SDL_Point start; + tic_point start; bool active; } drag; diff --git a/src/music.c b/src/music.c index 307a6ea..b1d0b70 100644 --- a/src/music.c +++ b/src/music.c @@ -91,7 +91,7 @@ static void drawEditbox(Music* music, s32 x, s32 y, s32 value, void(*set)(Music* }; { - SDL_Rect rect = { x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT }; + tic_rect rect = { x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT }; bool over = false; bool down = false; @@ -113,7 +113,7 @@ static void drawEditbox(Music* music, s32 x, s32 y, s32 value, void(*set)(Music* { x += TIC_FONT_WIDTH; - SDL_Rect rect = { x-1, y-1, TIC_FONT_WIDTH*2+1, TIC_FONT_HEIGHT+1 }; + tic_rect rect = { x-1, y-1, TIC_FONT_WIDTH*2+1, TIC_FONT_HEIGHT+1 }; if (checkMousePos(&rect)) { @@ -145,7 +145,7 @@ static void drawEditbox(Music* music, s32 x, s32 y, s32 value, void(*set)(Music* { x += 2*TIC_FONT_WIDTH; - SDL_Rect rect = { x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT }; + tic_rect rect = { x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT }; bool over = false; bool down = false; @@ -197,7 +197,7 @@ static void drawSwitch(Music* music, s32 x, s32 y, const char* label, s32 value, { x += (s32)strlen(label)*TIC_FONT_WIDTH; - SDL_Rect rect = { x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT }; + tic_rect rect = { x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT }; bool over = false; bool down = false; @@ -227,7 +227,7 @@ static void drawSwitch(Music* music, s32 x, s32 y, const char* label, s32 value, { x += (value > 99 ? 3 : 2)*TIC_FONT_WIDTH; - SDL_Rect rect = { x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT }; + tic_rect rect = { x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT }; bool over = false; bool down = false; @@ -546,8 +546,8 @@ static void stopTrack(Music* music) static void resetSelection(Music* music) { - music->tracker.select.start = (SDL_Point){-1, -1}; - music->tracker.select.rect = (SDL_Rect){0, 0, 0, 0}; + music->tracker.select.start = (tic_point){-1, -1}; + music->tracker.select.rect = (tic_rect){0, 0, 0, 0}; } static void deleteSelection(Music* music) @@ -556,7 +556,7 @@ static void deleteSelection(Music* music) if(pattern) { - SDL_Rect rect = music->tracker.select.rect; + tic_rect rect = music->tracker.select.rect; if(rect.h <= 0) { @@ -580,7 +580,7 @@ static void copyToClipboard(Music* music, bool cut) if(pattern) { - SDL_Rect rect = music->tracker.select.rect; + tic_rect rect = music->tracker.select.rect; if(rect.h <= 0) { @@ -731,8 +731,8 @@ static void updateSelection(Music* music) s32 rr = SDL_max(music->tracker.col, music->tracker.select.start.x); s32 rb = SDL_max(music->tracker.row, music->tracker.select.start.y); - SDL_Rect* rect = &music->tracker.select.rect; - *rect = (SDL_Rect){rl, rt, rr - rl + 1, rb - rt + 1}; + tic_rect* rect = &music->tracker.select.rect; + *rect = (tic_rect){rl, rt, rr - rl + 1, rb - rt + 1}; if(rect->x % CHANNEL_COLS + rect->w > CHANNEL_COLS) resetSelection(music); @@ -996,7 +996,7 @@ static void selectAll(Music* music) s32 col = music->tracker.col - music->tracker.col % CHANNEL_COLS; - music->tracker.select.start = (SDL_Point){col, 0}; + music->tracker.select.start = (tic_point){col, 0}; music->tracker.col = col + CHANNEL_COLS-1; music->tracker.row = MUSIC_PATTERN_ROWS-1; @@ -1134,7 +1134,7 @@ static void drawTrackerFrames(Music* music, s32 x, s32 y) }; { - SDL_Rect rect = { x - Border, y - Border, Width, MUSIC_FRAMES * TIC_FONT_HEIGHT + Border }; + tic_rect rect = { x - Border, y - Border, Width, MUSIC_FRAMES * TIC_FONT_HEIGHT + Border }; if (checkMousePos(&rect)) { @@ -1216,7 +1216,7 @@ static void drawTrackerChannel(Music* music, s32 x, s32 y, s32 channel) Width = TIC_FONT_WIDTH * 8 + Border, }; - SDL_Rect rect = {x - Border, y - Border, Width, Rows*TIC_FONT_HEIGHT + Border}; + tic_rect rect = {x - Border, y - Border, Width, Rows*TIC_FONT_HEIGHT + Border}; if(checkMousePos(&rect)) { @@ -1237,7 +1237,7 @@ static void drawTrackerChannel(Music* music, s32 x, s32 y, s32 channel) else { resetSelection(music); - music->tracker.select.start = (SDL_Point){col, row}; + music->tracker.select.start = (tic_point){col, row}; music->tracker.select.drag = true; } @@ -1246,7 +1246,7 @@ static void drawTrackerChannel(Music* music, s32 x, s32 y, s32 channel) if(music->tracker.select.drag) { - SDL_Rect rect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT}; + tic_rect rect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT}; if(!checkMouseDown(&rect, tic_mouse_left)) { music->tracker.select.drag = false; @@ -1274,7 +1274,7 @@ static void drawTrackerChannel(Music* music, s32 x, s32 y, s32 channel) // draw selection if (selectedChannel) { - SDL_Rect rect = music->tracker.select.rect; + tic_rect rect = music->tracker.select.rect; if (rect.h > 1 && i >= rect.y && i < rect.y + rect.h) { s32 sx = x - 1; @@ -1346,7 +1346,7 @@ static void drawTumbler(Music* music, s32 x, s32 y, s32 index) enum{On=36, Off = 52, Size=5, Chroma=14}; - SDL_Rect rect = {x, y, Size, Size}; + tic_rect rect = {x, y, Size, Size}; if(checkMousePos(&rect)) { @@ -1438,7 +1438,7 @@ static void drawPlayButtons(Music* music) for (s32 i = 0; i < Count; i++) { - SDL_Rect rect = { Offset + Width * i, 0, Width, Height }; + tic_rect rect = { Offset + Width * i, 0, Width, Height }; bool over = false; @@ -1490,7 +1490,7 @@ static void drawModeTabs(Music* music) for (s32 i = 0; i < Count; i++) { - SDL_Rect rect = { TIC80_WIDTH - Width * (Count - i), 0, Width, Height }; + tic_rect rect = { TIC80_WIDTH - Width * (Count - i), 0, Width, Height }; static const s32 Tabs[] = { MUSIC_PIANO_TAB, MUSIC_TRACKER_TAB }; @@ -1544,7 +1544,7 @@ static void scrollNotes(Music* music, s32 delta) if(pattern) { - SDL_Rect rect = music->tracker.select.rect; + tic_rect rect = music->tracker.select.rect; if(rect.h <= 0) { diff --git a/src/music.h b/src/music.h index 01782dd..e6975b4 100644 --- a/src/music.h +++ b/src/music.h @@ -54,8 +54,8 @@ struct Music struct { - SDL_Point start; - SDL_Rect rect; + tic_point start; + tic_rect rect; bool drag; } select; diff --git a/src/sfx.c b/src/sfx.c index 0b45f2d..0421fa7 100644 --- a/src/sfx.c +++ b/src/sfx.c @@ -68,7 +68,7 @@ static void drawSwitch(Sfx* sfx, s32 x, s32 y, const char* label, s32 value, voi { x += (s32)strlen(label)*TIC_FONT_WIDTH; - SDL_Rect rect = {x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT}; + tic_rect rect = {x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT}; if(checkMousePos(&rect)) { @@ -90,7 +90,7 @@ static void drawSwitch(Sfx* sfx, s32 x, s32 y, const char* label, s32 value, voi { x += 2*TIC_FONT_WIDTH; - SDL_Rect rect = {x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT}; + tic_rect rect = {x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT}; if(checkMousePos(&rect)) { @@ -207,7 +207,7 @@ static void drawWaveButtons(Sfx* sfx, s32 x, s32 y) for(s32 i = 0; i < Count; i++) { - SDL_Rect rect = {x, y + (Count - i - 1)*(Height+Gap), Width, Height}; + tic_rect rect = {x, y + (Count - i - 1)*(Height+Gap), Width, Height}; bool over = false; @@ -238,7 +238,7 @@ static void drawWaveButtons(Sfx* sfx, s32 x, s32 y) { enum{Size = 5}; - SDL_Rect iconRect = {x+Width+HGap, y + (Count - i - 1)*(Height+Gap), Size, Size}; + tic_rect iconRect = {x+Width+HGap, y + (Count - i - 1)*(Height+Gap), Size, Size}; bool over = false; if(checkMousePos(&iconRect)) @@ -295,7 +295,7 @@ static void drawCanvasTabs(Sfx* sfx, s32 x, s32 y) { s32 size = sfx->tic->api.text(sfx->tic, Labels[i], 0, -TIC_FONT_HEIGHT, (tic_color_black)); - SDL_Rect rect = {x - size, sy, size, TIC_FONT_HEIGHT}; + tic_rect rect = {x - size, sy, size, TIC_FONT_HEIGHT}; if(checkMousePos(&rect)) { @@ -318,7 +318,7 @@ static void drawCanvasTabs(Sfx* sfx, s32 x, s32 y) { static const char Label[] = "x16"; enum{Width = (sizeof Label - 1) * TIC_FONT_WIDTH}; - SDL_Rect rect = {(x - Width)/2, y + Height * 6, Width, TIC_FONT_HEIGHT}; + tic_rect rect = {(x - Width)/2, y + Height * 6, Width, TIC_FONT_HEIGHT}; if(checkMousePos(&rect)) { @@ -335,7 +335,7 @@ static void drawCanvasTabs(Sfx* sfx, s32 x, s32 y) { static const char Label[] = "DOWN"; enum{Width = (sizeof Label - 1) * TIC_FONT_WIDTH}; - SDL_Rect rect = {(x - Width)/2, y + Height * 6, Width, TIC_FONT_HEIGHT}; + tic_rect rect = {(x - Width)/2, y + Height * 6, Width, TIC_FONT_HEIGHT}; if(checkMousePos(&rect)) { @@ -370,7 +370,7 @@ static void drawCanvas(Sfx* sfx, s32 x, s32 y) sfx->tic->api.rect(sfx->tic, x + tickIndex * CANVAS_SIZE, y, CANVAS_SIZE + 1, CANVAS_HEIGHT + 1, (tic_color_white)); } - SDL_Rect rect = {x, y, CANVAS_WIDTH, CANVAS_HEIGHT}; + tic_rect rect = {x, y, CANVAS_WIDTH, CANVAS_HEIGHT}; tic_sample* effect = getEffect(sfx); @@ -451,16 +451,16 @@ static void drawPiano(Sfx* sfx, s32 x, s32 y) static const s32 ButtonIndixes[] = {0, 2, 4, 5, 7, 9, 11, 1, 3, -1, 6, 8, 10}; - SDL_Rect buttons[COUNT_OF(ButtonIndixes)]; + tic_rect buttons[COUNT_OF(ButtonIndixes)]; for(s32 i = 0; i < COUNT_OF(buttons); i++) { buttons[i] = i < PIANO_WHITE_BUTTONS - ? (SDL_Rect){x + (PIANO_BUTTON_WIDTH+1)*i, y, PIANO_BUTTON_WIDTH + 1, PIANO_BUTTON_HEIGHT} - : (SDL_Rect){x + (7 + 3) * (i - PIANO_WHITE_BUTTONS) + 6, y, 7, 8}; + ? (tic_rect){x + (PIANO_BUTTON_WIDTH+1)*i, y, PIANO_BUTTON_WIDTH + 1, PIANO_BUTTON_HEIGHT} + : (tic_rect){x + (7 + 3) * (i - PIANO_WHITE_BUTTONS) + 6, y, 7, 8}; } - SDL_Rect rect = {x, y, PIANO_WIDTH, PIANO_HEIGHT}; + tic_rect rect = {x, y, PIANO_WIDTH, PIANO_HEIGHT}; if(checkMousePos(&rect)) { @@ -470,7 +470,7 @@ static void drawPiano(Sfx* sfx, s32 x, s32 y) for(s32 i = COUNT_OF(buttons) - 1; i >= 0; i--) { - SDL_Rect* rect = buttons + i; + tic_rect* rect = buttons + i; if(checkMousePos(rect)) if(ButtonIndixes[i] >= 0) @@ -484,7 +484,7 @@ static void drawPiano(Sfx* sfx, s32 x, s32 y) { for(s32 i = COUNT_OF(buttons) - 1; i >= 0; i--) { - SDL_Rect* rect = buttons + i; + tic_rect* rect = buttons + i; s32 index = ButtonIndixes[i]; if(index >= 0) @@ -502,7 +502,7 @@ static void drawPiano(Sfx* sfx, s32 x, s32 y) for(s32 i = 0; i < COUNT_OF(buttons); i++) { - SDL_Rect* rect = buttons + i; + tic_rect* rect = buttons + i; bool white = i < PIANO_WHITE_BUTTONS; s32 index = ButtonIndixes[i]; @@ -525,7 +525,7 @@ static void drawOctavePanel(Sfx* sfx, s32 x, s32 y) for(s32 i = 0; i < OCTAVES; i++) { - SDL_Rect rect = {x + i * (TIC_FONT_WIDTH + Gap), y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT}; + tic_rect rect = {x + i * (TIC_FONT_WIDTH + Gap), y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT}; if(checkMousePos(&rect)) { @@ -761,7 +761,7 @@ static void drawModeTabs(Sfx* sfx) for (s32 i = 0; i < Count; i++) { - SDL_Rect rect = { TIC80_WIDTH - Width * (Count - i), 0, Width, Height }; + tic_rect rect = { TIC80_WIDTH - Width * (Count - i), 0, Width, Height }; bool over = false; @@ -794,7 +794,7 @@ static void drawSfxToolbar(Sfx* sfx) s32 x = TIC80_WIDTH - Width - TIC_SPRITESIZE*3; s32 y = 1; - SDL_Rect rect = {x, y, Width, TIC_FONT_HEIGHT}; + tic_rect rect = {x, y, Width, TIC_FONT_HEIGHT}; bool over = false; if(checkMousePos(&rect)) @@ -871,7 +871,7 @@ static void drawWaveformBar(Sfx* sfx, s32 x, s32 y) for(s32 i = 0; i < ENVELOPES_COUNT; i++) { - SDL_Rect rect = {x + (i%Cols)*(Width+Gap), y + (i/Cols)*(Height+Gap), Width, Height}; + tic_rect rect = {x + (i%Cols)*(Width+Gap), y + (i/Cols)*(Height+Gap), Width, Height}; if(checkMousePos(&rect)) { @@ -911,7 +911,7 @@ static void drawWaveformCanvas(Sfx* sfx, s32 x, s32 y) { enum {Rows = CANVAS_ROWS, Width = ENVELOPE_VALUES * CANVAS_SIZE, Height = CANVAS_HEIGHT}; - SDL_Rect rect = {x, y, Width, Height}; + tic_rect rect = {x, y, Width, Height}; sfx->tic->api.rect(sfx->tic, rect.x, rect.y, rect.w, rect.h, (tic_color_dark_red)); diff --git a/src/sprite.c b/src/sprite.c index 3f2ed6e..6153634 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -33,7 +33,7 @@ static void clearCanvasSelection(Sprite* sprite) { - SDL_memset(&sprite->select.rect, 0, sizeof(SDL_Rect)); + SDL_memset(&sprite->select.rect, 0, sizeof(tic_rect)); } static u8 getSheetPixel(Sprite* sprite, s32 x, s32 y) @@ -70,12 +70,12 @@ static void drawSelection(Sprite* sprite, s32 x, s32 y, s32 w, s32 h) for(s32 i = (y+h-1); i >= y; i--) { sprite->tic->api.pixel(sprite->tic, x, i, index++ % Step ? color : 0);} } -static SDL_Rect getSpriteRect(Sprite* sprite) +static tic_rect getSpriteRect(Sprite* sprite) { s32 x = getIndexPosX(sprite); s32 y = getIndexPosY(sprite); - return (SDL_Rect){x, y, sprite->size, sprite->size}; + return (tic_rect){x, y, sprite->size, sprite->size}; } static void drawCursorBorder(Sprite* sprite, s32 x, s32 y, s32 w, s32 h) @@ -86,7 +86,7 @@ static void drawCursorBorder(Sprite* sprite, s32 x, s32 y, s32 w, s32 h) static void processPickerCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 sx, s32 sy) { - SDL_Rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; + tic_rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; const s32 Size = CANVAS_SIZE / sprite->size; if(checkMousePos(&rect)) @@ -111,7 +111,7 @@ static void processPickerCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 sx, s32 s static void processDrawCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 sx, s32 sy) { - SDL_Rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; + tic_rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; const s32 Size = CANVAS_SIZE / sprite->size; if(checkMousePos(&rect)) @@ -167,7 +167,7 @@ static void pasteSelection(Sprite* sprite) for(s32 sx = l; sx < r; sx++) setSheetPixel(sprite, sx, sy, sprite->select.back[i++]); - SDL_Rect* rect = &sprite->select.rect; + tic_rect* rect = &sprite->select.rect; l += rect->x; t += rect->y; @@ -183,7 +183,7 @@ static void pasteSelection(Sprite* sprite) static void copySelection(Sprite* sprite) { - SDL_Rect rect = getSpriteRect(sprite); + tic_rect rect = getSpriteRect(sprite); s32 r = rect.x + rect.w; s32 b = rect.y + rect.h; @@ -192,7 +192,7 @@ static void copySelection(Sprite* sprite) sprite->select.back[i++] = getSheetPixel(sprite, sx, sy); { - SDL_Rect* rect = &sprite->select.rect; + tic_rect* rect = &sprite->select.rect; SDL_memset(sprite->select.front, 0, CANVAS_SIZE * CANVAS_SIZE); for(s32 j = rect->y, index = 0; j < (rect->y + rect->h); j++) @@ -207,7 +207,7 @@ static void copySelection(Sprite* sprite) static void processSelectCanvasMouse(Sprite* sprite, s32 x, s32 y) { - SDL_Rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; + tic_rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; const s32 Size = CANVAS_SIZE / sprite->size; if(checkMousePos(&rect)) @@ -234,13 +234,13 @@ static void processSelectCanvasMouse(Sprite* sprite, s32 x, s32 y) s32 rr = SDL_max(x, sprite->select.start.x); s32 rb = SDL_max(y, sprite->select.start.y); - sprite->select.rect = (SDL_Rect){rl, rt, rr - rl + 1, rb - rt + 1}; + sprite->select.rect = (tic_rect){rl, rt, rr - rl + 1, rb - rt + 1}; } else { sprite->select.drag = true; - sprite->select.start = (SDL_Point){mx / Size, my / Size}; - sprite->select.rect = (SDL_Rect){sprite->select.start.x, sprite->select.start.y, 1, 1}; + sprite->select.start = (tic_point){mx / Size, my / Size}; + sprite->select.rect = (tic_rect){sprite->select.start.x, sprite->select.start.y, 1, 1}; } } else if(sprite->select.drag) @@ -274,7 +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) { - SDL_Rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; + tic_rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; const s32 Size = CANVAS_SIZE / sprite->size; if(checkMousePos(&rect)) @@ -323,7 +323,7 @@ static void drawBrushSlider(Sprite* sprite, s32 x, s32 y) { enum {Count = 4, Size = 5}; - SDL_Rect rect = {x, y, Size, (Size+1)*Count}; + tic_rect rect = {x, y, Size, (Size+1)*Count}; bool over = false; if(checkMousePos(&rect)) @@ -386,7 +386,7 @@ static void drawCanvas(Sprite* sprite, s32 x, s32 y) static void drawCanvasOvr(Sprite* sprite, s32 x, s32 y) { - SDL_Rect rect = getSpriteRect(sprite); + tic_rect rect = getSpriteRect(sprite); s32 r = rect.x + rect.w; s32 b = rect.y + rect.h; @@ -414,7 +414,7 @@ static void drawCanvasOvr(Sprite* sprite, s32 x, s32 y) } } - SDL_Rect canvasRect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; + tic_rect canvasRect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; if(checkMouseDown(&canvasRect, SDL_BUTTON_MIDDLE)) { s32 mx = getMouseX() - x; @@ -425,35 +425,35 @@ static void drawCanvasOvr(Sprite* sprite, s32 x, s32 y) static void upCanvas(Sprite* sprite) { - SDL_Rect* rect = &sprite->select.rect; + tic_rect* rect = &sprite->select.rect; if(rect->y > 0) rect->y--; pasteSelection(sprite); } static void downCanvas(Sprite* sprite) { - SDL_Rect* rect = &sprite->select.rect; + tic_rect* rect = &sprite->select.rect; if(rect->y + rect->h < sprite->size) rect->y++; pasteSelection(sprite); } static void leftCanvas(Sprite* sprite) { - SDL_Rect* rect = &sprite->select.rect; + tic_rect* rect = &sprite->select.rect; if(rect->x > 0) rect->x--; pasteSelection(sprite); } static void rightCanvas(Sprite* sprite) { - SDL_Rect* rect = &sprite->select.rect; + tic_rect* rect = &sprite->select.rect; if(rect->x + rect->w < sprite->size) rect->x++; pasteSelection(sprite); } static void rotateSelectRect(Sprite* sprite) { - SDL_Rect rect = sprite->select.rect; + tic_rect rect = sprite->select.rect; s32 selection_center_x = rect.x + rect.w/2; s32 selection_center_y = rect.y + rect.h/2; @@ -488,7 +488,7 @@ static void rotateCanvas(Sprite* sprite) if(buffer) { { - SDL_Rect rect = sprite->select.rect; + tic_rect rect = sprite->select.rect; const s32 Size = rect.h * rect.w; s32 diff = 0; @@ -513,7 +513,7 @@ static void rotateCanvas(Sprite* sprite) static void deleteCanvas(Sprite* sprite) { - SDL_Rect* rect = &sprite->select.rect; + tic_rect* rect = &sprite->select.rect; s32 left = getIndexPosX(sprite) + rect->x; s32 top = getIndexPosY(sprite) + rect->y; @@ -531,7 +531,7 @@ static void deleteCanvas(Sprite* sprite) static void flipCanvasHorz(Sprite* sprite) { - SDL_Rect* rect = &sprite->select.rect; + tic_rect* rect = &sprite->select.rect; s32 sprite_x = getIndexPosX(sprite); s32 sprite_y = getIndexPosY(sprite); @@ -553,7 +553,7 @@ static void flipCanvasHorz(Sprite* sprite) static void flipCanvasVert(Sprite* sprite) { - SDL_Rect* rect = &sprite->select.rect; + tic_rect* rect = &sprite->select.rect; s32 sprite_x = getIndexPosX(sprite); s32 sprite_y = getIndexPosY(sprite); @@ -619,7 +619,7 @@ static void drawMoveButtons(Sprite* sprite) 0b00000000, }; - static const SDL_Rect Rects[] = + 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}, @@ -668,7 +668,7 @@ static void drawRGBSlider(Sprite* sprite, s32 x, s32 y, u8* value) 0b00000000, }; - SDL_Rect rect = {x, y-2, Size, 5}; + tic_rect rect = {x, y-2, Size, 5}; if(checkMousePos(&rect)) { @@ -710,7 +710,7 @@ static void drawRGBSlider(Sprite* sprite, s32 x, s32 y, u8* value) 0b00000000, }; - SDL_Rect rect = {x - 4, y - 1, 2, 3}; + tic_rect rect = {x - 4, y - 1, 2, 3}; bool down = false; if(checkMousePos(&rect)) @@ -748,7 +748,7 @@ static void drawRGBSlider(Sprite* sprite, s32 x, s32 y, u8* value) 0b00000000, }; - SDL_Rect rect = {x + Size + 2, y - 1, 2, 3}; + tic_rect rect = {x + Size + 2, y - 1, 2, 3}; bool down = false; if(checkMousePos(&rect)) @@ -796,7 +796,7 @@ static void drawRGBTools(Sprite* sprite, s32 x, s32 y) 0b00000000, }; - SDL_Rect rect = {x, y, Size, Size}; + tic_rect rect = {x, y, Size, Size}; bool over = false; bool down = false; @@ -840,7 +840,7 @@ static void drawRGBTools(Sprite* sprite, s32 x, s32 y) 0b00000000, }; - SDL_Rect rect = {x + 8, y, Size, Size}; + tic_rect rect = {x + 8, y, Size, Size}; bool over = false; bool down = false; @@ -898,7 +898,7 @@ static void drawRGBSlidersOvr(Sprite* sprite, s32 x, s32 y) static void drawPalette(Sprite* sprite, s32 x, s32 y) { - SDL_Rect rect = {x, y, PALETTE_WIDTH-1, PALETTE_HEIGHT-1}; + tic_rect rect = {x, y, PALETTE_WIDTH-1, PALETTE_HEIGHT-1}; if(checkMousePos(&rect)) { @@ -946,7 +946,7 @@ static void drawPalette(Sprite* sprite, s32 x, s32 y) 0b11111111, }; - SDL_Rect rect = {x + PALETTE_WIDTH + 3, y + (PALETTE_HEIGHT-8)/2-1, 8, 8}; + tic_rect rect = {x + PALETTE_WIDTH + 3, y + (PALETTE_HEIGHT-8)/2-1, 8, 8}; bool down = false; bool over = false; @@ -1040,7 +1040,7 @@ static void updateSpriteSize(Sprite* sprite, s32 size) static void drawSheet(Sprite* sprite, s32 x, s32 y) { - SDL_Rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; + tic_rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; sprite->tic->api.rect_border(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, rect.y, rect.w, rect.h, (tic_color_black)); @@ -1059,7 +1059,7 @@ static void drawSheet(Sprite* sprite, s32 x, s32 y) static void drawSheetOvr(Sprite* sprite, s32 x, s32 y) { - SDL_Rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; + tic_rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; for(s32 j = 0, index = (sprite->index - sprite->index % TIC_BANK_SPRITES); j < rect.h; j += TIC_SPRITESIZE) for(s32 i = 0; i < rect.w; i += TIC_SPRITESIZE, index++) @@ -1074,7 +1074,7 @@ static void drawSheetOvr(Sprite* sprite, s32 x, s32 y) static void flipSpriteHorz(Sprite* sprite) { - SDL_Rect rect = getSpriteRect(sprite); + tic_rect rect = getSpriteRect(sprite); s32 r = rect.x + rect.w/2; s32 b = rect.y + rect.h; @@ -1091,7 +1091,7 @@ static void flipSpriteHorz(Sprite* sprite) static void flipSpriteVert(Sprite* sprite) { - SDL_Rect rect = getSpriteRect(sprite); + tic_rect rect = getSpriteRect(sprite); s32 r = rect.x + rect.w; s32 b = rect.y + rect.h/2; @@ -1114,7 +1114,7 @@ static void rotateSprite(Sprite* sprite) if(buffer) { { - SDL_Rect rect = getSpriteRect(sprite); + tic_rect rect = getSpriteRect(sprite); s32 r = rect.x + rect.w; s32 b = rect.y + rect.h; @@ -1135,7 +1135,7 @@ static void rotateSprite(Sprite* sprite) static void deleteSprite(Sprite* sprite) { - SDL_Rect rect = getSpriteRect(sprite); + tic_rect rect = getSpriteRect(sprite); s32 r = rect.x + rect.w; s32 b = rect.y + rect.h; @@ -1200,7 +1200,7 @@ static void drawSpriteTools(Sprite* sprite, s32 x, s32 y) bool pushed = false; bool over = false; - SDL_Rect rect = {x + i * Gap, y, TIC_SPRITESIZE, TIC_SPRITESIZE}; + tic_rect rect = {x + i * Gap, y, TIC_SPRITESIZE, TIC_SPRITESIZE}; if(checkMousePos(&rect)) { @@ -1283,7 +1283,7 @@ static void drawTools(Sprite* sprite, s32 x, s32 y) for(s32 i = 0; i < COUNT_OF(Icons)/BITS_IN_BYTE; i++) { - SDL_Rect rect = {x + i * Gap, y, TIC_SPRITESIZE, TIC_SPRITESIZE}; + tic_rect rect = {x + i * Gap, y, TIC_SPRITESIZE, TIC_SPRITESIZE}; bool over = false; if(checkMousePos(&rect)) @@ -1341,7 +1341,7 @@ static void copyToClipboard(Sprite* sprite) if(buffer) { - SDL_Rect rect = getSpriteRect(sprite); + tic_rect rect = getSpriteRect(sprite); s32 r = rect.x + rect.w; s32 b = rect.y + rect.h; @@ -1373,7 +1373,7 @@ static void copyFromClipboard(Sprite* sprite) { if(fromClipboard(buffer, size, true, false)) { - SDL_Rect rect = getSpriteRect(sprite); + tic_rect rect = getSpriteRect(sprite); s32 r = rect.x + rect.w; s32 b = rect.y + rect.h; @@ -1510,7 +1510,7 @@ static void drawSpriteToolbar(Sprite* sprite) // draw sprite size control { - SDL_Rect rect = {TIC80_WIDTH - 58, 1, 23, 5}; + tic_rect rect = {TIC80_WIDTH - 58, 1, 23, 5}; if(checkMousePos(&rect)) { @@ -1547,7 +1547,7 @@ static void drawSpriteToolbar(Sprite* sprite) { static const char Label[] = "BG"; - SDL_Rect rect = {TIC80_WIDTH - 2 * TIC_FONT_WIDTH - 2, 0, 2 * TIC_FONT_WIDTH + 1, TIC_SPRITESIZE-1}; + 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)); @@ -1567,7 +1567,7 @@ static void drawSpriteToolbar(Sprite* sprite) { static const char Label[] = "FG"; - SDL_Rect rect = {TIC80_WIDTH - 4 * TIC_FONT_WIDTH - 4, 0, 2 * TIC_FONT_WIDTH + 1, TIC_SPRITESIZE-1}; + 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)); diff --git a/src/sprite.h b/src/sprite.h index 2b13752..f2a3d5b 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -44,8 +44,8 @@ struct Sprite struct { - SDL_Rect rect; - SDL_Point start; + tic_rect rect; + tic_point start; bool drag; u8* back; u8* front; diff --git a/src/studio.c b/src/studio.c index fb19441..2cb65e4 100644 --- a/src/studio.c +++ b/src/studio.c @@ -70,8 +70,8 @@ typedef struct bool down; bool click; - SDL_Point start; - SDL_Point end; + tic_point start; + tic_point end; } MouseState; @@ -115,7 +115,7 @@ static struct struct { - // SDL_Point cursor; + // tic_point cursor; // u32 button; MouseState state[3]; @@ -127,7 +127,7 @@ static struct struct { - SDL_Point pos; + tic_point pos; bool active; } gesture; @@ -151,11 +151,11 @@ static struct // struct // { // s32 size; - // SDL_Point axis; - // SDL_Point a; - // SDL_Point b; - // SDL_Point x; - // SDL_Point y; + // tic_point axis; + // tic_point a; + // tic_point b; + // tic_point x; + // tic_point y; // } part; // } gamepad; @@ -574,7 +574,7 @@ static void drawExtrabar(tic_mem* tic) for(s32 i = 0; i < sizeof Icons / BITS_IN_BYTE; i++) { - SDL_Rect rect = {x + i*Size, y, Size, Size}; + tic_rect rect = {x + i*Size, y, Size, Size}; u8 bgcolor = (tic_color_white); u8 color = (tic_color_light_blue); @@ -613,7 +613,7 @@ static void drawBankIcon(s32 x, s32 y) { tic_mem* tic = studioImpl.studio.tic; - SDL_Rect rect = {x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT}; + tic_rect rect = {x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT}; static const u8 Icon[] = { @@ -657,7 +657,7 @@ static void drawBankIcon(s32 x, s32 y) for(s32 i = 0; i < TIC_EDITOR_BANKS; i++) { - SDL_Rect rect = {x + 2 + (i+1)*Size, 0, Size, Size}; + tic_rect rect = {x + 2 + (i+1)*Size, 0, Size, Size}; bool over = false; if(checkMousePos(&rect)) @@ -693,7 +693,7 @@ static void drawBankIcon(s32 x, s32 y) 0b00000000, }; - SDL_Rect rect = {x + 4 + (TIC_EDITOR_BANKS+1)*Size, 0, Size, Size}; + tic_rect rect = {x + 4 + (TIC_EDITOR_BANKS+1)*Size, 0, Size, Size}; bool over = false; @@ -796,7 +796,7 @@ void drawToolbar(tic_mem* tic, u8 color, bool bg) for(s32 i = 0; i < COUNT_OF(Modes); i++) { - SDL_Rect rect = {i * Size, 0, Size, Size}; + tic_rect rect = {i * Size, 0, Size, Size}; bool over = false; @@ -1071,15 +1071,15 @@ EditorMode getStudioMode() void changeStudioMode(s32 dir) { - const size_t modeCount = sizeof(Modes)/sizeof(Modes[0]); - for(size_t i = 0; i < modeCount; i++) - { - if(studioImpl.mode == Modes[i]) - { - setStudioMode(Modes[(i+dir+modeCount) % modeCount]); - return; - } - } + const size_t modeCount = sizeof(Modes)/sizeof(Modes[0]); + for(size_t i = 0; i < modeCount; i++) + { + if(studioImpl.mode == Modes[i]) + { + setStudioMode(Modes[(i+dir+modeCount) % modeCount]); + return; + } + } } static void showGameMenu() @@ -1111,34 +1111,42 @@ s32 getMouseY() return tic->ram.input.mouse.y; } -bool checkMousePos(const SDL_Rect* rect) +static inline bool pointInRect(const tic_point* pt, const tic_rect* rect) { - SDL_Point pos = {getMouseX(), getMouseY()}; - return SDL_PointInRect(&pos, rect); + return (pt->x >= rect->x) + && (pt->x < (rect->x + rect->w)) + && (pt->y >= rect->y) + && (pt->y < (rect->y + rect->h)); } -bool checkMouseClick(const SDL_Rect* rect, s32 button) +bool checkMousePos(const tic_rect* rect) +{ + tic_point pos = {getMouseX(), getMouseY()}; + return pointInRect(&pos, rect); +} + +bool checkMouseClick(const tic_rect* rect, s32 button) { MouseState* state = &studioImpl.mouse.state[button]; bool value = state->click - && SDL_PointInRect(&state->start, rect) - && SDL_PointInRect(&state->end, rect); + && pointInRect(&state->start, rect) + && pointInRect(&state->end, rect); if(value) state->click = false; return value; } -bool checkMouseDown(const SDL_Rect* rect, s32 button) +bool checkMouseDown(const tic_rect* rect, s32 button) { MouseState* state = &studioImpl.mouse.state[button]; - return state->down && SDL_PointInRect(&state->start, rect); + return state->down && pointInRect(&state->start, rect); } -bool getGesturePos(SDL_Point* pos) +bool getGesturePos(tic_point* pos) { if(studioImpl.gesture.active) { @@ -1245,7 +1253,7 @@ bool studioCartChanged() // static void updateGamepadParts(); -// static void calcTextureRect(SDL_Rect* rect) +// static void calcTextureRect(tic_rect* rect) // { // SDL_GetWindowSize(studioImpl.window, &rect->w, &rect->h); @@ -1293,7 +1301,7 @@ static void processGamepadMapping() // #if !defined(__EMSCRIPTEN__) && !defined(__MACOSX__) -// static bool checkTouch(const SDL_Rect* rect, s32* x, s32* y) +// static bool checkTouch(const tic_rect* rect, s32* x, s32* y) // { // s32 devices = SDL_GetNumTouchDevices(); // s32 width = 0, height = 0; @@ -1327,8 +1335,8 @@ static void processGamepadMapping() // if (finger && finger->pressure > 0.0f) // { -// SDL_Point point = { (s32)(finger->x * width), (s32)(finger->y * height) }; -// if (SDL_PointInRect(&point, rect)) +// tic_point point = { (s32)(finger->x * width), (s32)(finger->y * height) }; +// if (pointInRect(&point, rect)) // { // *x = point.x; // *y = point.y; @@ -1350,7 +1358,7 @@ static void processGamepadMapping() // s32 x = 0, y = 0; // { -// SDL_Rect axis = {studioImpl.gamepad.part.axis.x, studioImpl.gamepad.part.axis.y, size*3, size*3}; +// tic_rect axis = {studioImpl.gamepad.part.axis.x, studioImpl.gamepad.part.axis.y, size*3, size*3}; // if(checkTouch(&axis, &x, &y)) // { @@ -1381,22 +1389,22 @@ static void processGamepadMapping() // } // { -// SDL_Rect a = {studioImpl.gamepad.part.a.x, studioImpl.gamepad.part.a.y, size, size}; +// tic_rect a = {studioImpl.gamepad.part.a.x, studioImpl.gamepad.part.a.y, size, size}; // if(checkTouch(&a, &x, &y)) studioImpl.gamepad.touch.first.a = true; // } // { -// SDL_Rect b = {studioImpl.gamepad.part.b.x, studioImpl.gamepad.part.b.y, size, size}; +// tic_rect b = {studioImpl.gamepad.part.b.x, studioImpl.gamepad.part.b.y, size, size}; // if(checkTouch(&b, &x, &y)) studioImpl.gamepad.touch.first.b = true; // } // { -// SDL_Rect xb = {studioImpl.gamepad.part.x.x, studioImpl.gamepad.part.x.y, size, size}; +// tic_rect xb = {studioImpl.gamepad.part.x.x, studioImpl.gamepad.part.x.y, size, size}; // if(checkTouch(&xb, &x, &y)) studioImpl.gamepad.touch.first.x = true; // } // { -// SDL_Rect yb = {studioImpl.gamepad.part.y.x, studioImpl.gamepad.part.y.y, size, size}; +// tic_rect yb = {studioImpl.gamepad.part.y.x, studioImpl.gamepad.part.y.y, size, size}; // if(checkTouch(&yb, &x, &y)) studioImpl.gamepad.touch.first.y = true; // } // } @@ -1587,7 +1595,7 @@ static void processGesture() if(fingers == Fingers) { - SDL_Point point = {0, 0}; + tic_point point = {0, 0}; for(s32 f = 0; f < fingers; f++) { @@ -1611,7 +1619,7 @@ static void processGesture() // studioImpl.mouse.button = SDL_GetMouseState(&studioImpl.mouse.cursor.x, &studioImpl.mouse.cursor.y); // { -// SDL_Rect rect = {0, 0, 0, 0}; +// tic_rect rect = {0, 0, 0, 0}; // calcTextureRect(&rect); // if(rect.w) studioImpl.mouse.cursor.x = (studioImpl.mouse.cursor.x - rect.x) * TIC80_WIDTH / rect.w; @@ -1675,7 +1683,7 @@ static void saveProject() else showPopupMessage("SAVE ERROR :("); } -static void screen2buffer(u32* buffer, const u32* pixels, SDL_Rect rect) +static void screen2buffer(u32* buffer, const u32* pixels, tic_rect rect) { pixels += rect.y * TIC80_FULLWIDTH; @@ -1701,7 +1709,7 @@ static void setCoverImage() // if(buffer) // { - // SDL_Rect rect = {OFFSET_LEFT, OFFSET_TOP, TIC80_WIDTH, TIC80_HEIGHT}; + // tic_rect rect = {OFFSET_LEFT, OFFSET_TOP, TIC80_WIDTH, TIC80_HEIGHT}; // screen2buffer(buffer, tic->screen, rect); @@ -1778,7 +1786,7 @@ static void takeScreenshot() } } -static inline bool wasKeyPressed(s32 key) +static inline bool isKeyWasDownOnce(s32 key) { tic_mem* tic = studioImpl.studio.tic; @@ -1836,13 +1844,13 @@ static void processShortcuts() if(alt) { - if(wasKeyPressed(tic_key_grave)) setStudioMode(TIC_CONSOLE_MODE); - else if(wasKeyPressed(tic_key_1)) setStudioMode(TIC_CODE_MODE); - else if(wasKeyPressed(tic_key_2)) setStudioMode(TIC_SPRITE_MODE); - else if(wasKeyPressed(tic_key_3)) setStudioMode(TIC_MAP_MODE); - else if(wasKeyPressed(tic_key_4)) setStudioMode(TIC_SFX_MODE); - else if(wasKeyPressed(tic_key_5)) setStudioMode(TIC_MUSIC_MODE); - else if(wasKeyPressed(tic_key_return)) goFullscreen(); + if(isKeyWasDownOnce(tic_key_grave)) setStudioMode(TIC_CONSOLE_MODE); + else if(isKeyWasDownOnce(tic_key_1)) setStudioMode(TIC_CODE_MODE); + else if(isKeyWasDownOnce(tic_key_2)) setStudioMode(TIC_SPRITE_MODE); + else if(isKeyWasDownOnce(tic_key_3)) setStudioMode(TIC_MAP_MODE); + else if(isKeyWasDownOnce(tic_key_4)) setStudioMode(TIC_SFX_MODE); + else if(isKeyWasDownOnce(tic_key_5)) setStudioMode(TIC_MUSIC_MODE); + else if(isKeyWasDownOnce(tic_key_return)) goFullscreen(); // switch(event->keysym.sym) // { @@ -1855,14 +1863,14 @@ static void processShortcuts() // default: break; // } } - else if(ctrl) - { - if(wasKeyPressed(tic_key_pageup)) changeStudioMode(-1); - else if(wasKeyPressed(tic_key_pagedown)) changeStudioMode(1); - else if(wasKeyPressed(tic_key_q)) exitStudio(); - else if(wasKeyPressed(tic_key_r)) runProject(); - else if(wasKeyPressed(tic_key_return)) runProject(); - else if(wasKeyPressed(tic_key_s)) saveProject(); + else if(ctrl) + { + if(isKeyWasDownOnce(tic_key_pageup)) changeStudioMode(-1); + else if(isKeyWasDownOnce(tic_key_pagedown)) changeStudioMode(1); + else if(isKeyWasDownOnce(tic_key_q)) exitStudio(); + else if(isKeyWasDownOnce(tic_key_r)) runProject(); + else if(isKeyWasDownOnce(tic_key_return)) runProject(); + else if(isKeyWasDownOnce(tic_key_s)) saveProject(); // switch(event->keysym.sym) @@ -1870,21 +1878,21 @@ static void processShortcuts() // case SDLK_PAGEUP: changeStudioMode(-1); return true; // case SDLK_PAGEDOWN: changeStudioMode(1); return true; // } - } + } else { - if(wasKeyPressed(tic_key_f1)) setStudioMode(TIC_CODE_MODE); - else if(wasKeyPressed(tic_key_f2)) setStudioMode(TIC_SPRITE_MODE); - else if(wasKeyPressed(tic_key_f3)) setStudioMode(TIC_MAP_MODE); - else if(wasKeyPressed(tic_key_f4)) setStudioMode(TIC_SFX_MODE); - else if(wasKeyPressed(tic_key_f5)) setStudioMode(TIC_MUSIC_MODE); - else if(wasKeyPressed(tic_key_f7)) setCoverImage(); - else if(wasKeyPressed(tic_key_f8)) takeScreenshot(); + if(isKeyWasDownOnce(tic_key_f1)) setStudioMode(TIC_CODE_MODE); + else if(isKeyWasDownOnce(tic_key_f2)) setStudioMode(TIC_SPRITE_MODE); + else if(isKeyWasDownOnce(tic_key_f3)) setStudioMode(TIC_MAP_MODE); + else if(isKeyWasDownOnce(tic_key_f4)) setStudioMode(TIC_SFX_MODE); + else if(isKeyWasDownOnce(tic_key_f5)) setStudioMode(TIC_MUSIC_MODE); + else if(isKeyWasDownOnce(tic_key_f7)) setCoverImage(); + else if(isKeyWasDownOnce(tic_key_f8)) takeScreenshot(); #if !defined(__EMSCRIPTEN__) - else if(wasKeyPressed(tic_key_f9)) startVideoRecord(); + else if(isKeyWasDownOnce(tic_key_f9)) startVideoRecord(); #endif - else if(wasKeyPressed(tic_key_f11)) goFullscreen(); - else if(wasKeyPressed(tic_key_escape)) + else if(isKeyWasDownOnce(tic_key_f11)) goFullscreen(); + else if(isKeyWasDownOnce(tic_key_escape)) { Code* code = studioImpl.editor[studioImpl.bank.index.code].code; @@ -2253,7 +2261,7 @@ static void recordFrame(u32* pixels) { if(studioImpl.video.frame < studioImpl.video.frames) { - SDL_Rect rect = {0, 0, TIC80_FULLWIDTH, TIC80_FULLHEIGHT}; + tic_rect rect = {0, 0, TIC80_FULLWIDTH, TIC80_FULLHEIGHT}; screen2buffer(studioImpl.video.buffer + (TIC80_FULLWIDTH*TIC80_FULLHEIGHT) * studioImpl.video.frame, pixels, rect); if(studioImpl.video.frame % TIC_FRAMERATE < TIC_FRAMERATE / 2) @@ -2275,7 +2283,7 @@ static void recordFrame(u32* pixels) // static void blitTexture() // { // tic_mem* tic = studioImpl.studio.tic; -// SDL_Rect rect = {0, 0, 0, 0}; +// tic_rect rect = {0, 0, 0, 0}; // calcTextureRect(&rect); // void* pixels = NULL; @@ -2320,8 +2328,8 @@ static void recordFrame(u32* pixels) // { // enum {Header = OFFSET_TOP}; -// SDL_Rect srcRect = {0, 0, TIC80_FULLWIDTH, Header}; -// SDL_Rect dstRect = {0}; +// tic_rect srcRect = {0, 0, TIC80_FULLWIDTH, Header}; +// tic_rect dstRect = {0}; // SDL_GetWindowSize(studioImpl.window, &dstRect.w, &dstRect.h); // dstRect.h = rect.y; // SDL_RenderCopy(studioImpl.renderer, studioImpl.texture, &srcRect, &dstRect); @@ -2329,8 +2337,8 @@ static void recordFrame(u32* pixels) // { // enum {Header = OFFSET_TOP}; -// SDL_Rect srcRect = {0, TIC80_FULLHEIGHT - Header, TIC80_FULLWIDTH, Header}; -// SDL_Rect dstRect = {0}; +// tic_rect srcRect = {0, TIC80_FULLHEIGHT - Header, TIC80_FULLWIDTH, Header}; +// tic_rect dstRect = {0}; // SDL_GetWindowSize(studioImpl.window, &dstRect.w, &dstRect.h); // dstRect.y = rect.y + rect.h; // dstRect.h = rect.y; @@ -2340,8 +2348,8 @@ static void recordFrame(u32* pixels) // { // enum {Header = OFFSET_TOP}; // enum {Left = OFFSET_LEFT}; -// SDL_Rect srcRect = {0, Header, Left, TIC80_HEIGHT}; -// SDL_Rect dstRect = {0}; +// tic_rect srcRect = {0, Header, Left, TIC80_HEIGHT}; +// tic_rect dstRect = {0}; // SDL_GetWindowSize(studioImpl.window, &dstRect.w, &dstRect.h); // dstRect.y = rect.y; // dstRect.h = rect.h; @@ -2352,7 +2360,7 @@ static void recordFrame(u32* pixels) // enum {Top = OFFSET_TOP}; // enum {Left = OFFSET_LEFT}; -// SDL_Rect srcRect = {Left, Top, TIC80_WIDTH, TIC80_HEIGHT}; +// tic_rect srcRect = {Left, Top, TIC80_WIDTH, TIC80_HEIGHT}; // SDL_RenderCopy(studioImpl.renderer, studioImpl.texture, &srcRect, &rect); // } @@ -2393,12 +2401,12 @@ static void blitCursor(const u8* in) // SDL_UnlockTexture(studioImpl.mouse.texture); // } - // SDL_Rect rect = {0, 0, 0, 0}; + // tic_rect rect = {0, 0, 0, 0}; // calcTextureRect(&rect); // s32 scale = rect.w / TIC80_WIDTH; - // SDL_Rect src = {0, 0, TIC_SPRITESIZE, TIC_SPRITESIZE}; - // SDL_Rect dst = {0, 0, TIC_SPRITESIZE * scale, TIC_SPRITESIZE * scale}; + // tic_rect src = {0, 0, TIC_SPRITESIZE, TIC_SPRITESIZE}; + // tic_rect dst = {0, 0, TIC_SPRITESIZE * scale, TIC_SPRITESIZE * scale}; // SDL_GetMouseState(&dst.x, &dst.y); @@ -2557,7 +2565,7 @@ static void renderStudio() // { // s32 tileSize = TIC_SPRITESIZE; // s32 offset = 0; -// SDL_Rect rect; +// tic_rect rect; // const s32 JoySize = 3; // SDL_GetWindowSize(studioImpl.window, &rect.w, &rect.h); @@ -2574,11 +2582,11 @@ static void renderStudio() // } // studioImpl.gamepad.part.size = tileSize; -// studioImpl.gamepad.part.axis = (SDL_Point){0, offset}; -// studioImpl.gamepad.part.a = (SDL_Point){rect.w - 2*tileSize, 2*tileSize + offset}; -// studioImpl.gamepad.part.b = (SDL_Point){rect.w - 1*tileSize, 1*tileSize + offset}; -// studioImpl.gamepad.part.x = (SDL_Point){rect.w - 3*tileSize, 1*tileSize + offset}; -// studioImpl.gamepad.part.y = (SDL_Point){rect.w - 2*tileSize, 0*tileSize + offset}; +// studioImpl.gamepad.part.axis = (tic_point){0, offset}; +// studioImpl.gamepad.part.a = (tic_point){rect.w - 2*tileSize, 2*tileSize + offset}; +// studioImpl.gamepad.part.b = (tic_point){rect.w - 1*tileSize, 1*tileSize + offset}; +// studioImpl.gamepad.part.x = (tic_point){rect.w - 3*tileSize, 1*tileSize + offset}; +// studioImpl.gamepad.part.y = (tic_point){rect.w - 2*tileSize, 0*tileSize + offset}; // } // static void renderGamepad() @@ -2586,7 +2594,7 @@ static void renderStudio() // if(studioImpl.gamepad.show || studioImpl.gamepad.alpha); else return; // const s32 tileSize = studioImpl.gamepad.part.size; -// const SDL_Point axis = studioImpl.gamepad.part.axis; +// const tic_point axis = studioImpl.gamepad.part.axis; // typedef struct { bool press; s32 x; s32 y;} Tile; // const Tile Tiles[] = // { @@ -2606,8 +2614,8 @@ static void renderStudio() // for(s32 i = 0; i < COUNT_OF(Tiles); i++) // { // const Tile* tile = Tiles + i; -// SDL_Rect src = {(tile->press ? ButtonsCount + i : i) * TIC_SPRITESIZE, 0, TIC_SPRITESIZE, TIC_SPRITESIZE}; -// SDL_Rect dest = {tile->x, tile->y, tileSize, tileSize}; +// tic_rect src = {(tile->press ? ButtonsCount + i : i) * TIC_SPRITESIZE, 0, TIC_SPRITESIZE, TIC_SPRITESIZE}; +// tic_rect dest = {tile->x, tile->y, tileSize, tileSize}; // SDL_RenderCopy(studioImpl.renderer, studioImpl.gamepad.texture, &src, &dest); // } diff --git a/src/studio.h b/src/studio.h index 32fb0f7..2e870a7 100644 --- a/src/studio.h +++ b/src/studio.h @@ -122,16 +122,26 @@ typedef enum TIC_SURF_MODE, } EditorMode; +typedef struct +{ + s32 x, y; +} tic_point; + +typedef struct +{ + s32 x, y, w, h; +} tic_rect; + // SDL_Event* pollEvent(); void setCursor(SDL_SystemCursor id); s32 getMouseX(); s32 getMouseY(); -bool checkMousePos(const SDL_Rect* rect); -bool checkMouseClick(const SDL_Rect* rect, s32 button); -bool checkMouseDown(const SDL_Rect* rect, s32 button); +bool checkMousePos(const tic_rect* rect); +bool checkMouseClick(const tic_rect* rect, s32 button); +bool checkMouseDown(const tic_rect* rect, s32 button); -bool getGesturePos(SDL_Point* pos); +bool getGesturePos(tic_point* pos); // const u8* getKeyboard(); diff --git a/src/world.c b/src/world.c index 4a928c4..865673e 100644 --- a/src/world.c +++ b/src/world.c @@ -38,7 +38,7 @@ static void drawGrid(World* world) world->tic->api.rect_border(world->tic, 0, 0, TIC80_WIDTH, TIC80_HEIGHT, color); - SDL_Rect rect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT}; + tic_rect rect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT}; if(checkMousePos(&rect)) {