this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

hid Studio definition, removed static Studio variable

nesbox b5027782 3dc2feac

+1611 -1588
+2 -2
CMakeLists.txt
··· 829 829 ${TIC80LIB_DIR}/studio/screens/console.c 830 830 ${TIC80LIB_DIR}/studio/screens/run.c 831 831 ${TIC80LIB_DIR}/studio/screens/menu.c 832 - ${TIC80LIB_DIR}/studio/screens/main_menu.c 832 + ${TIC80LIB_DIR}/studio/screens/mainmenu.c 833 833 ${TIC80LIB_DIR}/studio/screens/surf.c 834 834 ${TIC80LIB_DIR}/studio/screens/start.c 835 835 ${TIC80LIB_DIR}/studio/editors/code.c ··· 1116 1116 src/system/sdl/main.c 1117 1117 src/studio/screens/run.c 1118 1118 src/studio/screens/menu.c 1119 - src/studio/screens/main_menu.c 1119 + src/studio/screens/mainmenu.c 1120 1120 src/studio/screens/start.c 1121 1121 src/studio/config.c 1122 1122 src/studio/studio.c
+1 -1
src/core/core.c
··· 693 693 tic_mem* tic_core_create(s32 samplerate, tic80_pixel_color_format format) 694 694 { 695 695 tic_core* core = (tic_core*)malloc(sizeof(tic_core)); 696 - *core = (tic_core){0}; 696 + memset(core, 0, sizeof(tic_core)); 697 697 698 698 tic80* product = &core->memory.product; 699 699
+91
src/studio/anim.h
··· 1 + // MIT License 2 + 3 + // Copyright (c) 2017 Vadim Grigoruk @nesbox // grigoruk@gmail.com 4 + 5 + // Permission is hereby granted, free of charge, to any person obtaining a copy 6 + // of this software and associated documentation files (the "Software"), to deal 7 + // in the Software without restriction, including without limitation the rights 8 + // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 + // copies of the Software, and to permit persons to whom the Software is 10 + // furnished to do so, subject to the following conditions: 11 + 12 + // The above copyright notice and this permission notice shall be included in all 13 + // copies or substantial portions of the Software. 14 + 15 + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 + // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 + // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 + // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 + // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 + // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 + // SOFTWARE. 22 + 23 + #pragma once 24 + 25 + typedef enum 26 + { 27 + AnimLinear, 28 + AnimEaseIn, 29 + AnimEaseOut, 30 + AnimEaseInOut, 31 + AnimEaseInCubic, 32 + AnimEaseOutCubic, 33 + AnimEaseInOutCubic, 34 + AnimEaseInQuart, 35 + AnimEaseOutQuart, 36 + AnimEaseInOutQuart, 37 + AnimEaseInQuint, 38 + AnimEaseOutQuint, 39 + AnimEaseInOutQuint, 40 + AnimEaseInSine, 41 + AnimEaseOutSine, 42 + AnimEaseInOutSine, 43 + AnimEaseInExpo, 44 + AnimEaseOutExpo, 45 + AnimEaseInOutExpo, 46 + AnimEaseInCirc, 47 + AnimEaseOutCirc, 48 + AnimEaseInOutCirc, 49 + AnimEaseInBack, 50 + AnimEaseOutBack, 51 + AnimEaseInOutBack, 52 + AnimEaseInElastic, 53 + AnimEaseOutElastic, 54 + AnimEaseInOutElastic, 55 + AnimEaseInBounce, 56 + AnimEaseOutBounce, 57 + AnimEaseInOutBounce, 58 + } AnimEffect; 59 + 60 + typedef struct 61 + { 62 + s32 start; 63 + s32 end; 64 + s32 time; 65 + 66 + s32 *value; 67 + 68 + AnimEffect effect; 69 + } Anim; 70 + 71 + typedef struct 72 + { 73 + void(*done)(void *data); 74 + 75 + s32 time; 76 + s32 tick; 77 + 78 + s32 count; 79 + Anim* items; 80 + } Movie; 81 + 82 + #define MOVIE_DEF(TIME, DONE, ...) \ 83 + { \ 84 + .time = TIME, \ 85 + .done = DONE, \ 86 + .count = COUNT_OF(((Anim[])__VA_ARGS__)), \ 87 + .items = MOVE((Anim[])__VA_ARGS__), \ 88 + } 89 + 90 + void processAnim(Movie* movie, void* data); 91 + Movie* resetMovie(Movie* movie);
+6 -5
src/studio/config.c
··· 221 221 tic_cart_load(config->cart, buffer, size); 222 222 223 223 readConfig(config); 224 - studioConfigChanged(); 224 + studioConfigChanged(config->studio); 225 225 } 226 226 227 227 static void setDefault(Config* config) ··· 286 286 readConfig(config); 287 287 saveConfig(config, true); 288 288 289 - studioConfigChanged(); 289 + studioConfigChanged(config->studio); 290 290 } 291 291 292 292 static const char OptionsDatPath[] = TIC_LOCAL_VERSION "options.dat"; ··· 301 301 memcpy(dst, data, size); 302 302 } 303 303 304 - void initConfig(Config* config, tic_mem* tic, tic_fs* fs) 304 + void initConfig(Config* config, Studio* studio, tic_fs* fs) 305 305 { 306 306 *config = (Config) 307 307 { 308 - .tic = tic, 308 + .studio = studio, 309 + .tic = getMemory(studio), 309 310 .cart = realloc(config->cart, sizeof(tic_cartridge)), 310 311 .save = save, 311 312 .reset = reset, ··· 330 331 331 332 loadConfigData(fs, OptionsDatPath, &config->data.options, sizeof config->data.options); 332 333 333 - tic_api_reset(tic); 334 + tic_api_reset(config->tic); 334 335 } 335 336 336 337 void freeConfig(Config* config)
+2 -1
src/studio/config.h
··· 28 28 29 29 struct Config 30 30 { 31 + Studio* studio; 31 32 tic_mem* tic; 32 33 struct tic_fs* fs; 33 34 ··· 38 39 void(*reset)(Config*); 39 40 }; 40 41 41 - void initConfig(Config* config, tic_mem* tic, struct tic_fs* fs); 42 + void initConfig(Config* config, Studio* studio, struct tic_fs* fs); 42 43 void freeConfig(Config* config);
+120 -119
src/studio/editors/code.c
··· 84 84 enum {Height = TIC_FONT_HEIGHT + 1, StatusY = TIC80_HEIGHT - TIC_FONT_HEIGHT}; 85 85 86 86 tic_api_rect(code->tic, 0, TIC80_HEIGHT - Height, TIC80_WIDTH, Height, code->status.color); 87 - tic_api_print(code->tic, code->status.line, 0, StatusY, getConfig()->theme.code.BG, true, 1, false); 87 + tic_api_print(code->tic, code->status.line, 0, StatusY, getConfig(code->studio)->theme.code.BG, true, 1, false); 88 88 tic_api_print(code->tic, code->status.size, TIC80_WIDTH - (s32)strlen(code->status.size) * TIC_FONT_WIDTH, 89 - StatusY, getConfig()->theme.code.BG, true, 1, false); 89 + StatusY, getConfig(code->studio)->theme.code.BG, true, 1, false); 90 90 } 91 91 92 92 static char* getPosByLine(char* ptr, s32 line) ··· 143 143 144 144 tic_api_rect(code->tic, rect.x, rect.y, rect.w, rect.h, tic_color_grey); 145 145 146 - if(checkMousePos(&rect)) 146 + if(checkMousePos(code->studio, &rect)) 147 147 { 148 - setCursor(tic_cursor_hand); 148 + setCursor(code->studio, tic_cursor_hand); 149 149 150 - showTooltip("BOOKMARK [ctrl+f1]"); 150 + showTooltip(code->studio, "BOOKMARK [ctrl+f1]"); 151 151 152 152 s32 line = (tic_api_mouse(tic).y - rect.y) / STUDIO_TEXT_HEIGHT; 153 153 154 - drawBitIcon(tic_icon_bookmark, rect.x, rect.y + line * STUDIO_TEXT_HEIGHT - 1, tic_color_dark_grey); 154 + drawBitIcon(code->studio, tic_icon_bookmark, rect.x, rect.y + line * STUDIO_TEXT_HEIGHT - 1, tic_color_dark_grey); 155 155 156 - if(checkMouseClick(&rect, tic_mouse_left)) 156 + if(checkMouseClick(code->studio, &rect, tic_mouse_left)) 157 157 toggleBookmark(code, getPosByLine(code->src, line + code->scroll.y)); 158 158 } 159 159 ··· 165 165 { 166 166 if(syntaxPointer++->bookmark) 167 167 { 168 - drawBitIcon(tic_icon_bookmark, rect.x, rect.y + y * STUDIO_TEXT_HEIGHT, tic_color_black); 169 - drawBitIcon(tic_icon_bookmark, rect.x, rect.y + y * STUDIO_TEXT_HEIGHT - 1, tic_color_yellow); 168 + drawBitIcon(code->studio, tic_icon_bookmark, rect.x, rect.y + y * STUDIO_TEXT_HEIGHT, tic_color_black); 169 + drawBitIcon(code->studio, tic_icon_bookmark, rect.x, rect.y + y * STUDIO_TEXT_HEIGHT - 1, tic_color_yellow); 170 170 } 171 171 172 172 if(*pointer++ == '\n')y++; ··· 192 192 if(code->shadowText) 193 193 tic_api_rect(code->tic, x, y, getFontWidth(code)+1, TIC_FONT_HEIGHT+1, 0); 194 194 195 - tic_api_rect(code->tic, x-1, y-1, getFontWidth(code)+1, TIC_FONT_HEIGHT+1, getConfig()->theme.code.cursor); 195 + tic_api_rect(code->tic, x-1, y-1, getFontWidth(code)+1, TIC_FONT_HEIGHT+1, getConfig(code->studio)->theme.code.cursor); 196 196 197 197 if(symbol) 198 - drawChar(code->tic, symbol, x, y, getConfig()->theme.code.BG, code->altFont); 198 + drawChar(code->tic, symbol, x, y, getConfig(code->studio)->theme.code.BG, code->altFont); 199 199 } 200 200 } 201 201 202 202 static void drawMatchedDelim(Code* code, s32 x, s32 y, char symbol, u8 color) 203 203 { 204 204 tic_api_rectb(code->tic, x-1, y-1, (getFontWidth(code))+1, TIC_FONT_HEIGHT+1, 205 - getConfig()->theme.code.cursor); 205 + getConfig(code->studio)->theme.code.cursor); 206 206 drawChar(code->tic, symbol, x, y, color, code->altFont); 207 207 } 208 208 ··· 215 215 s32 y = rect.y - code->scroll.y * STUDIO_TEXT_HEIGHT; 216 216 const char* pointer = code->src; 217 217 218 - u8 selectColor = getConfig()->theme.code.select; 218 + u8 selectColor = getConfig(code->studio)->theme.code.select; 219 219 220 - const u8* colors = (const u8*)&getConfig()->theme.code; 220 + const u8* colors = (const u8*)&getConfig(code->studio)->theme.code; 221 221 const CodeState* syntaxPointer = code->state; 222 222 223 223 struct { char* start; char* end; } selection = ··· 367 367 s32 column = 0; 368 368 s32 line = 0; 369 369 getCursorPosition(code, &column, &line); 370 - if(getConfig()->theme.code.matchDelimiters) 370 + if(getConfig(code->studio)->theme.code.matchDelimiters) 371 371 code->matchedDelim = findMatchedDelim(code, code->cursor.position); 372 372 373 373 const s32 BufferWidth = CODE_EDITOR_WIDTH / getFontWidth(code); ··· 1521 1521 1522 1522 bool usedClipboard = true; 1523 1523 1524 - switch(getClipboardEvent()) 1524 + switch(getClipboardEvent(code->studio)) 1525 1525 { 1526 1526 case TIC_CLIPBOARD_CUT: cutToClipboard(code); break; 1527 1527 case TIC_CLIPBOARD_COPY: copyToClipboard(code); break; ··· 1534 1534 bool alt = tic_api_key(tic, tic_key_alt); 1535 1535 1536 1536 bool changedSelection = false; 1537 - if(keyWasPressed(tic_key_up) 1538 - || keyWasPressed(tic_key_down) 1539 - || keyWasPressed(tic_key_left) 1540 - || keyWasPressed(tic_key_right) 1541 - || keyWasPressed(tic_key_home) 1542 - || keyWasPressed(tic_key_end) 1543 - || keyWasPressed(tic_key_pageup) 1544 - || keyWasPressed(tic_key_pagedown)) 1537 + if(keyWasPressed(code->studio, tic_key_up) 1538 + || keyWasPressed(code->studio, tic_key_down) 1539 + || keyWasPressed(code->studio, tic_key_left) 1540 + || keyWasPressed(code->studio, tic_key_right) 1541 + || keyWasPressed(code->studio, tic_key_home) 1542 + || keyWasPressed(code->studio, tic_key_end) 1543 + || keyWasPressed(code->studio, tic_key_pageup) 1544 + || keyWasPressed(code->studio, tic_key_pagedown)) 1545 1545 { 1546 1546 if(!shift) code->cursor.selection = NULL; 1547 1547 else if(code->cursor.selection == NULL) code->cursor.selection = code->cursor.position; ··· 1551 1551 bool usedKeybinding = true; 1552 1552 1553 1553 // handle bookmarks 1554 - if(keyWasPressed(tic_key_f1)) 1554 + if(keyWasPressed(code->studio, tic_key_f1)) 1555 1555 { 1556 1556 if(ctrl && shift) 1557 1557 { ··· 1577 1577 1578 1578 if(ctrl) 1579 1579 { 1580 - if(keyWasPressed(tic_key_left)) leftWord(code); 1581 - else if(keyWasPressed(tic_key_right)) rightWord(code); 1582 - else if(keyWasPressed(tic_key_tab)) doTab(code, shift, ctrl); 1583 - else if(keyWasPressed(tic_key_a)) selectAll(code); 1584 - else if(keyWasPressed(tic_key_z)) undo(code); 1585 - else if(keyWasPressed(tic_key_y)) redo(code); 1586 - else if(keyWasPressed(tic_key_f)) setCodeMode(code, TEXT_FIND_MODE); 1587 - else if(keyWasPressed(tic_key_g)) setCodeMode(code, TEXT_GOTO_MODE); 1588 - else if(keyWasPressed(tic_key_o)) setCodeMode(code, TEXT_OUTLINE_MODE); 1589 - else if(keyWasPressed(tic_key_n)) downLine(code); 1590 - else if(keyWasPressed(tic_key_p)) upLine(code); 1591 - else if(keyWasPressed(tic_key_e)) endLine(code); 1592 - else if(keyWasPressed(tic_key_slash)) commentLine(code); 1593 - else if(keyWasPressed(tic_key_home)) goCodeHome(code); 1594 - else if(keyWasPressed(tic_key_end)) goCodeEnd(code); 1595 - else if(keyWasPressed(tic_key_delete)) deleteWord(code); 1596 - else if(keyWasPressed(tic_key_backspace)) backspaceWord(code); 1580 + if(keyWasPressed(code->studio, tic_key_left)) leftWord(code); 1581 + else if(keyWasPressed(code->studio, tic_key_right)) rightWord(code); 1582 + else if(keyWasPressed(code->studio, tic_key_tab)) doTab(code, shift, ctrl); 1583 + else if(keyWasPressed(code->studio, tic_key_a)) selectAll(code); 1584 + else if(keyWasPressed(code->studio, tic_key_z)) undo(code); 1585 + else if(keyWasPressed(code->studio, tic_key_y)) redo(code); 1586 + else if(keyWasPressed(code->studio, tic_key_f)) setCodeMode(code, TEXT_FIND_MODE); 1587 + else if(keyWasPressed(code->studio, tic_key_g)) setCodeMode(code, TEXT_GOTO_MODE); 1588 + else if(keyWasPressed(code->studio, tic_key_o)) setCodeMode(code, TEXT_OUTLINE_MODE); 1589 + else if(keyWasPressed(code->studio, tic_key_n)) downLine(code); 1590 + else if(keyWasPressed(code->studio, tic_key_p)) upLine(code); 1591 + else if(keyWasPressed(code->studio, tic_key_e)) endLine(code); 1592 + else if(keyWasPressed(code->studio, tic_key_slash)) commentLine(code); 1593 + else if(keyWasPressed(code->studio, tic_key_home)) goCodeHome(code); 1594 + else if(keyWasPressed(code->studio, tic_key_end)) goCodeEnd(code); 1595 + else if(keyWasPressed(code->studio, tic_key_delete)) deleteWord(code); 1596 + else if(keyWasPressed(code->studio, tic_key_backspace)) backspaceWord(code); 1597 1597 else usedKeybinding = false; 1598 1598 } 1599 1599 else if(alt) 1600 1600 { 1601 - if(keyWasPressed(tic_key_left)) leftWord(code); 1602 - else if(keyWasPressed(tic_key_right)) rightWord(code); 1601 + if(keyWasPressed(code->studio, tic_key_left)) leftWord(code); 1602 + else if(keyWasPressed(code->studio, tic_key_right)) rightWord(code); 1603 1603 else usedKeybinding = false; 1604 1604 } 1605 1605 else 1606 1606 { 1607 - if(keyWasPressed(tic_key_up)) upLine(code); 1608 - else if(keyWasPressed(tic_key_down)) downLine(code); 1609 - else if(keyWasPressed(tic_key_left)) leftColumn(code); 1610 - else if(keyWasPressed(tic_key_right)) rightColumn(code); 1611 - else if(keyWasPressed(tic_key_home)) goHome(code); 1612 - else if(keyWasPressed(tic_key_end)) goEnd(code); 1613 - else if(keyWasPressed(tic_key_pageup)) pageUp(code); 1614 - else if(keyWasPressed(tic_key_pagedown)) pageDown(code); 1615 - else if(keyWasPressed(tic_key_delete)) deleteChar(code); 1616 - else if(keyWasPressed(tic_key_backspace)) backspaceChar(code); 1617 - else if(keyWasPressed(tic_key_return)) newLine(code); 1618 - else if(keyWasPressed(tic_key_tab)) doTab(code, shift, ctrl); 1607 + if(keyWasPressed(code->studio, tic_key_up)) upLine(code); 1608 + else if(keyWasPressed(code->studio, tic_key_down)) downLine(code); 1609 + else if(keyWasPressed(code->studio, tic_key_left)) leftColumn(code); 1610 + else if(keyWasPressed(code->studio, tic_key_right)) rightColumn(code); 1611 + else if(keyWasPressed(code->studio, tic_key_home)) goHome(code); 1612 + else if(keyWasPressed(code->studio, tic_key_end)) goEnd(code); 1613 + else if(keyWasPressed(code->studio, tic_key_pageup)) pageUp(code); 1614 + else if(keyWasPressed(code->studio, tic_key_pagedown)) pageDown(code); 1615 + else if(keyWasPressed(code->studio, tic_key_delete)) deleteChar(code); 1616 + else if(keyWasPressed(code->studio, tic_key_backspace)) backspaceChar(code); 1617 + else if(keyWasPressed(code->studio, tic_key_return)) newLine(code); 1618 + else if(keyWasPressed(code->studio, tic_key_tab)) doTab(code, shift, ctrl); 1619 1619 else usedKeybinding = false; 1620 1620 } 1621 1621 1622 1622 if(!usedKeybinding) 1623 1623 { 1624 - if(shift && keyWasPressed(tic_key_return)) 1624 + if(shift && keyWasPressed(code->studio, tic_key_return)) 1625 1625 { 1626 1626 newLineAutoClose(code); 1627 1627 usedKeybinding = true; ··· 1637 1637 1638 1638 tic_rect rect = {BOOKMARK_WIDTH, TOOLBAR_SIZE, CODE_EDITOR_WIDTH, CODE_EDITOR_HEIGHT}; 1639 1639 1640 - if(checkMousePos(&rect)) 1640 + if(checkMousePos(code->studio, &rect)) 1641 1641 { 1642 - bool useDrag = (code->mode == TEXT_DRAG_CODE && checkMouseDown(&rect, tic_mouse_left)) || checkMouseDown(&rect, tic_mouse_right); 1643 - setCursor(code->mode == TEXT_DRAG_CODE || useDrag ? tic_cursor_hand : tic_cursor_ibeam); 1642 + bool useDrag = (code->mode == TEXT_DRAG_CODE && checkMouseDown(code->studio, &rect, tic_mouse_left)) || checkMouseDown(code->studio, &rect, tic_mouse_right); 1643 + setCursor(code->studio, code->mode == TEXT_DRAG_CODE || useDrag ? tic_cursor_hand : tic_cursor_ibeam); 1644 1644 1645 1645 if(code->scroll.active) 1646 1646 { ··· 1664 1664 } 1665 1665 else 1666 1666 { 1667 - if(checkMouseDown(&rect, tic_mouse_left)) 1667 + if(checkMouseDown(code->studio, &rect, tic_mouse_left)) 1668 1668 { 1669 1669 s32 mx = tic_api_mouse(tic).x; 1670 1670 s32 my = tic_api_mouse(tic).y; ··· 1704 1704 1705 1705 processMouse(code); 1706 1706 1707 - tic_api_cls(code->tic, getConfig()->theme.code.BG); 1707 + tic_api_cls(code->tic, getConfig(code->studio)->theme.code.BG); 1708 1708 1709 1709 drawCode(code, true); 1710 1710 drawStatus(code); ··· 1738 1738 1739 1739 if(!tic_api_key(tic, tic_key_ctrl) && !tic_api_key(tic, tic_key_alt)) 1740 1740 { 1741 - char sym = getKeyboardText(); 1741 + char sym = getKeyboardText(code->studio); 1742 1742 1743 1743 if(sym) 1744 1744 { ··· 1749 1749 1750 1750 processMouse(code); 1751 1751 1752 - tic_api_cls(code->tic, getConfig()->theme.code.BG); 1752 + tic_api_cls(code->tic, getConfig(code->studio)->theme.code.BG); 1753 1753 1754 1754 drawCode(code, true); 1755 1755 drawStatus(code); ··· 1817 1817 1818 1818 static void textFindTick(Code* code) 1819 1819 { 1820 - if(keyWasPressed(tic_key_return)) setCodeMode(code, TEXT_EDIT_MODE); 1821 - else if(keyWasPressed(tic_key_up) 1822 - || keyWasPressed(tic_key_down) 1823 - || keyWasPressed(tic_key_left) 1824 - || keyWasPressed(tic_key_right)) 1820 + if(keyWasPressed(code->studio, tic_key_return)) setCodeMode(code, TEXT_EDIT_MODE); 1821 + else if(keyWasPressed(code->studio, tic_key_up) 1822 + || keyWasPressed(code->studio, tic_key_down) 1823 + || keyWasPressed(code->studio, tic_key_left) 1824 + || keyWasPressed(code->studio, tic_key_right)) 1825 1825 { 1826 1826 if(*code->popup.text) 1827 1827 { 1828 - bool reverse = keyWasPressed(tic_key_up) || keyWasPressed(tic_key_left); 1828 + bool reverse = keyWasPressed(code->studio, tic_key_up) || keyWasPressed(code->studio, tic_key_left); 1829 1829 char* (*func)(const char*, const char*, const char*) = reverse ? upStrStr : downStrStr; 1830 1830 char* from = reverse ? MIN(code->cursor.position, code->cursor.selection) : MAX(code->cursor.position, code->cursor.selection); 1831 1831 char* pos = func(code->src, from, code->popup.text); 1832 1832 updateFindCode(code, pos); 1833 1833 } 1834 1834 } 1835 - else if(keyWasPressed(tic_key_backspace)) 1835 + else if(keyWasPressed(code->studio, tic_key_backspace)) 1836 1836 { 1837 1837 if(*code->popup.text) 1838 1838 { ··· 1841 1841 } 1842 1842 } 1843 1843 1844 - char sym = getKeyboardText(); 1844 + char sym = getKeyboardText(code->studio); 1845 1845 1846 1846 if(sym) 1847 1847 { ··· 1853 1853 } 1854 1854 } 1855 1855 1856 - tic_api_cls(code->tic, getConfig()->theme.code.BG); 1856 + tic_api_cls(code->tic, getConfig(code->studio)->theme.code.BG); 1857 1857 1858 1858 drawCode(code, false); 1859 1859 drawPopupBar(code, "FIND:"); ··· 1883 1883 { 1884 1884 tic_mem* tic = code->tic; 1885 1885 1886 - if(keyWasPressed(tic_key_return)) 1886 + if(keyWasPressed(code->studio, tic_key_return)) 1887 1887 { 1888 1888 if(*code->popup.text) 1889 1889 updateGotoCode(code); 1890 1890 1891 1891 setCodeMode(code, TEXT_EDIT_MODE); 1892 1892 } 1893 - else if(keyWasPressed(tic_key_backspace)) 1893 + else if(keyWasPressed(code->studio, tic_key_backspace)) 1894 1894 { 1895 1895 if(*code->popup.text) 1896 1896 { ··· 1899 1899 } 1900 1900 } 1901 1901 1902 - char sym = getKeyboardText(); 1902 + char sym = getKeyboardText(code->studio); 1903 1903 1904 1904 if(sym) 1905 1905 { ··· 1911 1911 } 1912 1912 } 1913 1913 1914 - tic_api_cls(tic, getConfig()->theme.code.BG); 1914 + tic_api_cls(tic, getConfig(code->studio)->theme.code.BG); 1915 1915 1916 1916 if(code->jump.line >= 0) 1917 1917 tic_api_rect(tic, 0, (code->jump.line - code->scroll.y) * (TIC_FONT_HEIGHT+1) + TOOLBAR_SIZE, 1918 - TIC80_WIDTH, TIC_FONT_HEIGHT+2, getConfig()->theme.code.select); 1918 + TIC80_WIDTH, TIC_FONT_HEIGHT+2, getConfig(code->studio)->theme.code.select); 1919 1919 1920 1920 drawCode(code, false); 1921 1921 drawPopupBar(code, "GOTO:"); ··· 1927 1927 tic_mem* tic = code->tic; 1928 1928 tic_rect rect = {x, y, TIC80_WIDTH - x, TIC80_HEIGHT - y}; 1929 1929 1930 - if(checkMousePos(&rect)) 1930 + if(checkMousePos(code->studio, &rect)) 1931 1931 { 1932 1932 s32 mx = tic_api_mouse(tic).y - rect.y; 1933 1933 mx /= STUDIO_TEXT_HEIGHT; ··· 1935 1935 1936 1936 if(mx >= 0 && mx < code->outline.size && code->outline.items[mx].pos) 1937 1937 { 1938 - setCursor(tic_cursor_hand); 1938 + setCursor(code->studio, tic_cursor_hand); 1939 1939 1940 - if(checkMouseDown(&rect, tic_mouse_left)) 1940 + if(checkMouseDown(code->studio, &rect, tic_mouse_left)) 1941 1941 { 1942 1942 code->outline.index = mx; 1943 1943 updateOutlineCode(code); 1944 1944 } 1945 1945 1946 - if(checkMouseClick(&rect, tic_mouse_left)) 1946 + if(checkMouseClick(code->studio, &rect, tic_mouse_left)) 1947 1947 setCodeMode(code, TEXT_EDIT_MODE); 1948 1948 } 1949 1949 } ··· 2014 2014 } 2015 2015 } 2016 2016 2017 - if(keyWasPressed(tic_key_up)) 2017 + if(keyWasPressed(code->studio, tic_key_up)) 2018 2018 updateOutlineIndex(code, code->outline.index - 1); 2019 2019 2020 - else if(keyWasPressed(tic_key_down)) 2020 + else if(keyWasPressed(code->studio, tic_key_down)) 2021 2021 updateOutlineIndex(code, code->outline.index + 1); 2022 2022 2023 - else if(keyWasPressed(tic_key_left) || keyWasPressed(tic_key_pageup)) 2023 + else if(keyWasPressed(code->studio, tic_key_left) || keyWasPressed(code->studio, tic_key_pageup)) 2024 2024 updateOutlineIndex(code, code->outline.index - TEXT_BUFFER_HEIGHT); 2025 2025 2026 - else if(keyWasPressed(tic_key_right) || keyWasPressed(tic_key_pagedown)) 2026 + else if(keyWasPressed(code->studio, tic_key_right) || keyWasPressed(code->studio, tic_key_pagedown)) 2027 2027 updateOutlineIndex(code, code->outline.index + TEXT_BUFFER_HEIGHT); 2028 2028 2029 - else if(keyWasPressed(tic_key_home)) 2029 + else if(keyWasPressed(code->studio, tic_key_home)) 2030 2030 updateOutlineIndex(code, 0); 2031 2031 2032 - else if(keyWasPressed(tic_key_end)) 2032 + else if(keyWasPressed(code->studio, tic_key_end)) 2033 2033 updateOutlineIndex(code, code->outline.size - 1); 2034 2034 2035 - else if(keyWasPressed(tic_key_return)) 2035 + else if(keyWasPressed(code->studio, tic_key_return)) 2036 2036 { 2037 2037 updateOutlineCode(code); 2038 2038 setCodeMode(code, TEXT_EDIT_MODE); 2039 2039 } 2040 - else if(keyWasPressed(tic_key_backspace)) 2040 + else if(keyWasPressed(code->studio, tic_key_backspace)) 2041 2041 { 2042 2042 if(*code->popup.text) 2043 2043 { ··· 2046 2046 } 2047 2047 } 2048 2048 2049 - char sym = getKeyboardText(); 2049 + char sym = getKeyboardText(code->studio); 2050 2050 2051 2051 if(sym) 2052 2052 { ··· 2058 2058 } 2059 2059 } 2060 2060 2061 - tic_api_cls(code->tic, getConfig()->theme.code.BG); 2061 + tic_api_cls(code->tic, getConfig(code->studio)->theme.code.BG); 2062 2062 2063 2063 drawCode(code, false); 2064 2064 drawStatus(code); ··· 2074 2074 tic_rect rect = {x, y, Size, Size}; 2075 2075 2076 2076 bool over = false; 2077 - if(checkMousePos(&rect)) 2077 + if(checkMousePos(code->studio, &rect)) 2078 2078 { 2079 - setCursor(tic_cursor_hand); 2079 + setCursor(code->studio, tic_cursor_hand); 2080 2080 2081 - showTooltip("SWITCH FONT"); 2081 + showTooltip(code->studio, "SWITCH FONT"); 2082 2082 2083 2083 over = true; 2084 2084 2085 - if(checkMouseClick(&rect, tic_mouse_left)) 2085 + if(checkMouseClick(code->studio, &rect, tic_mouse_left)) 2086 2086 { 2087 2087 code->altFont = !code->altFont; 2088 2088 } ··· 2099 2099 tic_rect rect = {x, y, Size, Size}; 2100 2100 2101 2101 bool over = false; 2102 - if(checkMousePos(&rect)) 2102 + if(checkMousePos(code->studio, &rect)) 2103 2103 { 2104 - setCursor(tic_cursor_hand); 2104 + setCursor(code->studio, tic_cursor_hand); 2105 2105 2106 - showTooltip("SHOW SHADOW"); 2106 + showTooltip(code->studio, "SHOW SHADOW"); 2107 2107 2108 2108 over = true; 2109 2109 2110 - if(checkMouseClick(&rect, tic_mouse_left)) 2110 + if(checkMouseClick(code->studio, &rect, tic_mouse_left)) 2111 2111 { 2112 2112 code->shadowText = !code->shadowText; 2113 2113 } 2114 2114 } 2115 2115 2116 - drawBitIcon(tic_icon_shadow, x, y, over && !code->shadowText ? tic_color_grey : tic_color_light_grey); 2116 + drawBitIcon(code->studio, tic_icon_shadow, x, y, over && !code->shadowText ? tic_color_grey : tic_color_light_grey); 2117 2117 2118 2118 if(code->shadowText) 2119 - drawBitIcon(tic_icon_shadow2, x, y, tic_color_black); 2119 + drawBitIcon(code->studio, tic_icon_shadow2, x, y, tic_color_black); 2120 2120 } 2121 2121 2122 2122 static void drawRunButton(Code* code, s32 x, s32 y) ··· 2127 2127 tic_rect rect = {x, y, Size, Size}; 2128 2128 2129 2129 bool over = false; 2130 - if(checkMousePos(&rect)) 2130 + if(checkMousePos(code->studio, &rect)) 2131 2131 { 2132 - setCursor(tic_cursor_hand); 2133 - showTooltip("RUN [ctrl+r]"); 2132 + setCursor(code->studio, tic_cursor_hand); 2133 + showTooltip(code->studio, "RUN [ctrl+r]"); 2134 2134 over = true; 2135 2135 2136 - if(checkMouseClick(&rect, tic_mouse_left)) 2137 - runGame(); 2136 + if(checkMouseClick(code->studio, &rect, tic_mouse_left)) 2137 + runGame(code->studio); 2138 2138 } 2139 2139 2140 - drawBitIcon(tic_icon_run, x, y, over ? tic_color_grey : tic_color_light_grey); 2140 + drawBitIcon(code->studio, tic_icon_run, x, y, over ? tic_color_grey : tic_color_light_grey); 2141 2141 } 2142 2142 2143 2143 static void drawCodeToolbar(Code* code) ··· 2155 2155 tic_rect rect = {TIC80_WIDTH + (i - Count) * Size, 0, Size, Size}; 2156 2156 2157 2157 bool over = false; 2158 - if(checkMousePos(&rect)) 2158 + if(checkMousePos(code->studio, &rect)) 2159 2159 { 2160 - setCursor(tic_cursor_hand); 2160 + setCursor(code->studio, tic_cursor_hand); 2161 2161 2162 - showTooltip(Tips[i]); 2162 + showTooltip(code->studio, Tips[i]); 2163 2163 2164 2164 over = true; 2165 2165 2166 - if(checkMouseClick(&rect, tic_mouse_left)) 2166 + if(checkMouseClick(code->studio, &rect, tic_mouse_left)) 2167 2167 { 2168 2168 if(code->mode == i) code->escape(code); 2169 2169 else setCodeMode(code, i); ··· 2174 2174 if (active) 2175 2175 { 2176 2176 tic_api_rect(code->tic, rect.x, rect.y, Size, Size, tic_color_grey); 2177 - drawBitIcon(Icons[i], rect.x, rect.y + 1, tic_color_black); 2177 + drawBitIcon(code->studio, Icons[i], rect.x, rect.y + 1, tic_color_black); 2178 2178 } 2179 2179 2180 - drawBitIcon(Icons[i], rect.x, rect.y, active ? tic_color_white : (over ? tic_color_grey : tic_color_light_grey)); 2180 + drawBitIcon(code->studio, Icons[i], rect.x, rect.y, active ? tic_color_white : (over ? tic_color_grey : tic_color_light_grey)); 2181 2181 } 2182 2182 2183 2183 drawFontButton(code, TIC80_WIDTH - (Count+3) * Size, 1); 2184 2184 drawShadowButton(code, TIC80_WIDTH - (Count+2) * Size, 0); 2185 2185 drawRunButton(code, TIC80_WIDTH - (Count+1) * Size, 0); 2186 2186 2187 - drawToolbar(code->tic, false); 2187 + drawToolbar(code->studio, code->tic, false); 2188 2188 } 2189 2189 2190 2190 static void tick(Code* code) ··· 2261 2261 FREE(code->anim.hide.items); 2262 2262 } 2263 2263 2264 - void initCode(Code* code, tic_mem* tic, tic_code* src) 2264 + void initCode(Code* code, Studio* studio, tic_code* src) 2265 2265 { 2266 2266 bool firstLoad = code->state == NULL; 2267 2267 FREE(code->state); ··· 2271 2271 2272 2272 *code = (Code) 2273 2273 { 2274 - .tic = tic, 2274 + .studio = studio, 2275 + .tic = getMemory(studio), 2275 2276 .src = src->data, 2276 2277 .tick = tick, 2277 2278 .escape = escape, ··· 2295 2296 .scroll = 0, 2296 2297 }, 2297 2298 .matchedDelim = NULL, 2298 - .altFont = firstLoad ? getConfig()->theme.code.altFont : code->altFont, 2299 - .shadowText = getConfig()->theme.code.shadow, 2299 + .altFont = firstLoad ? getConfig(studio)->theme.code.altFont : code->altFont, 2300 + .shadowText = getConfig(studio)->theme.code.shadow, 2300 2301 .anim = 2301 2302 { 2302 2303 .idle = {.done = emptyDone,},
+2 -1
src/studio/editors/code.h
··· 28 28 29 29 struct Code 30 30 { 31 + Studio* studio; 31 32 tic_mem* tic; 32 33 33 34 char* src; ··· 134 135 void(*update)(Code*); 135 136 }; 136 137 137 - void initCode(Code*, tic_mem*, tic_code* src); 138 + void initCode(Code*, Studio* studio, tic_code* src); 138 139 void freeCode(Code*);
+76 -74
src/studio/editors/map.c
··· 74 74 75 75 bool over = false; 76 76 77 - if(checkMousePos(&rect)) 77 + if(checkMousePos(map->studio, &rect)) 78 78 { 79 - setCursor(tic_cursor_hand); 79 + setCursor(map->studio, tic_cursor_hand); 80 80 81 81 over = true; 82 82 83 - showTooltip("WORLD MAP [tab]"); 83 + showTooltip(map->studio, "WORLD MAP [tab]"); 84 84 85 - if(checkMouseClick(&rect, tic_mouse_left)) 86 - setStudioMode(TIC_WORLD_MODE); 85 + if(checkMouseClick(map->studio, &rect, tic_mouse_left)) 86 + setStudioMode(map->studio, TIC_WORLD_MODE); 87 87 } 88 88 89 - drawBitIcon(tic_icon_world, x, y, over ? tic_color_grey : tic_color_light_grey); 89 + drawBitIcon(map->studio, tic_icon_world, x, y, over ? tic_color_grey : tic_color_light_grey); 90 90 91 91 return x; 92 92 ··· 100 100 101 101 bool over = false; 102 102 103 - if(checkMousePos(&rect)) 103 + if(checkMousePos(map->studio, &rect)) 104 104 { 105 - setCursor(tic_cursor_hand); 105 + setCursor(map->studio, tic_cursor_hand); 106 106 107 107 over = true; 108 108 109 - showTooltip("SHOW/HIDE GRID [`]"); 109 + showTooltip(map->studio, "SHOW/HIDE GRID [`]"); 110 110 111 - if(checkMouseClick(&rect, tic_mouse_left)) 111 + if(checkMouseClick(map->studio, &rect, tic_mouse_left)) 112 112 map->canvas.grid = !map->canvas.grid; 113 113 } 114 114 115 - drawBitIcon(tic_icon_grid, x, y, map->canvas.grid ? tic_color_black : over ? tic_color_grey : tic_color_light_grey); 115 + drawBitIcon(map->studio, tic_icon_grid, x, y, map->canvas.grid ? tic_color_black : over ? tic_color_grey : tic_color_light_grey); 116 116 117 117 return x; 118 118 } ··· 134 134 tic_rect rect = {x, y, ICON_SIZE, ICON_SIZE}; 135 135 136 136 bool over = false; 137 - if(checkMousePos(&rect)) 137 + if(checkMousePos(map->studio, &rect)) 138 138 { 139 - setCursor(tic_cursor_hand); 139 + setCursor(map->studio, tic_cursor_hand); 140 140 141 141 over = true; 142 - showTooltip("SHOW TILES [shift]"); 142 + showTooltip(map->studio, "SHOW TILES [shift]"); 143 143 144 - if(isIdle(map) && checkMouseClick(&rect, tic_mouse_left)) 144 + if(isIdle(map) && checkMouseClick(map->studio, &rect, tic_mouse_left)) 145 145 { 146 146 map->anim.movie = resetMovie(sheetVisible(map) ? &map->anim.hide : &map->anim.show); 147 147 map->sheet.keep = true; 148 148 } 149 149 } 150 150 151 - drawBitIcon(sheetVisible(map) ? tic_icon_up : tic_icon_down, rect.x, rect.y, 151 + drawBitIcon(map->studio, sheetVisible(map) ? tic_icon_up : tic_icon_down, rect.x, rect.y, 152 152 over ? tic_color_grey : tic_color_light_grey); 153 153 154 154 return x; ··· 161 161 tic_rect rect = {x, y, width, ICON_SIZE}; 162 162 163 163 bool over = false; 164 - if(checkMousePos(&rect)) 164 + if(checkMousePos(map->studio, &rect)) 165 165 { 166 - setCursor(tic_cursor_hand); 166 + setCursor(map->studio, tic_cursor_hand); 167 167 168 168 over = true; 169 169 170 - showTooltip(tip); 170 + showTooltip(map->studio, tip); 171 171 172 - if(checkMouseClick(&rect, tic_mouse_left)) 172 + if(checkMouseClick(map->studio, &rect, tic_mouse_left)) 173 173 { 174 174 map->mode = mode; 175 175 } 176 176 } 177 177 178 - drawBitIcon(icon, rect.x, rect.y, map->mode == mode ? tic_color_black : over ? tic_color_grey : tic_color_light_grey); 178 + drawBitIcon(map->studio, icon, rect.x, rect.y, map->mode == mode ? tic_color_black : over ? tic_color_grey : tic_color_light_grey); 179 179 180 180 return x; 181 181 } ··· 211 211 { 212 212 tic_rect rect = {TIC80_WIDTH - TIC_SPRITESHEET_SIZE - 1, TOOLBAR_SIZE, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; 213 213 214 - if(checkMousePos(&rect)) 214 + if(checkMousePos(map->studio, &rect)) 215 215 { 216 216 s32 mx = tic_api_mouse(tic).x - rect.x; 217 217 s32 my = tic_api_mouse(tic).y - rect.y; ··· 226 226 { 227 227 tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; 228 228 229 - if(checkMousePos(&rect)) 229 + if(checkMousePos(map->studio, &rect)) 230 230 { 231 231 s32 tx = 0, ty = 0; 232 232 getMouseMap(map, &tx, &ty); ··· 255 255 tic_bpp mode = 1 << (2 - i); 256 256 257 257 bool hover = false; 258 - if(checkMousePos(&rect)) 258 + if(checkMousePos(map->studio, &rect)) 259 259 { 260 - setCursor(tic_cursor_hand); 260 + setCursor(map->studio, tic_cursor_hand); 261 261 hover = true; 262 262 263 263 if(mode > 1) 264 - SHOW_TOOLTIP("%iBITS PER PIXEL", mode); 264 + SHOW_TOOLTIP(map->studio, "%iBITS PER PIXEL", mode); 265 265 else 266 - SHOW_TOOLTIP("%iBIT PER PIXEL", mode); 266 + SHOW_TOOLTIP(map->studio, "%iBIT PER PIXEL", mode); 267 267 268 - if(checkMouseClick(&rect, tic_mouse_left)) 268 + if(checkMouseClick(map->studio, &rect, tic_mouse_left)) 269 269 { 270 270 tic_blit_update_bpp(&map->sheet.blit, mode); 271 271 } ··· 295 295 tic_rect rect = {x + i * Size, y, Size, Size}; 296 296 297 297 bool hover = false; 298 - if(checkMousePos(&rect)) 298 + if(checkMousePos(map->studio, &rect)) 299 299 { 300 - setCursor(tic_cursor_hand); 300 + setCursor(map->studio, tic_cursor_hand); 301 301 hover = true; 302 302 303 - showTooltip(i ? "SPRITES" : "TILES"); 303 + showTooltip(map->studio, i ? "SPRITES" : "TILES"); 304 304 305 - if(isIdle(map) && checkMouseClick(&rect, tic_mouse_left)) 305 + if(isIdle(map) && checkMouseClick(map->studio, &rect, tic_mouse_left)) 306 306 { 307 307 Anim* anim = map->anim.bank.items; 308 308 anim->start = (i - map->sheet.blit.bank) * TIC_SPRITESHEET_SIZE; ··· 312 312 } 313 313 } 314 314 315 - drawBitIcon(Icons[i], rect.x, rect.y, 315 + drawBitIcon(map->studio, Icons[i], rect.x, rect.y, 316 316 i == map->sheet.blit.bank 317 317 ? tic_color_dark_grey 318 318 : hover ··· 332 332 tic_rect rect = {x + i * Width - 1, y, Width, Height}; 333 333 334 334 bool hover = false; 335 - if(checkMousePos(&rect)) 335 + if(checkMousePos(map->studio, &rect)) 336 336 { 337 - setCursor(tic_cursor_hand); 337 + setCursor(map->studio, tic_cursor_hand); 338 338 hover = true; 339 339 340 - SHOW_TOOLTIP("PAGE %i", i); 340 + SHOW_TOOLTIP(map->studio, "PAGE %i", i); 341 341 342 - if(isIdle(map) && checkMouseClick(&rect, tic_mouse_left)) 342 + if(isIdle(map) && checkMouseClick(map->studio, &rect, tic_mouse_left)) 343 343 { 344 344 Anim* anim = map->anim.page.items; 345 345 anim->start = (i - map->sheet.blit.page) * TIC_SPRITESHEET_SIZE; ··· 431 431 static void initBlitMode(Map* map) 432 432 { 433 433 tic_mem* tic = map->tic; 434 - tiles2ram(&tic->ram, getBankTiles()); 434 + tiles2ram(&tic->ram, getBankTiles(map->studio)); 435 435 tic->ram.vram.blit.segment = tic_blit_calc_segment(&map->sheet.blit); 436 436 } 437 437 ··· 446 446 447 447 tic_rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; 448 448 449 - if(isIdle(map) && sheetVisible(map) && checkMousePos(&rect)) 449 + if(isIdle(map) && sheetVisible(map) && checkMousePos(map->studio, &rect)) 450 450 { 451 - setCursor(tic_cursor_hand); 451 + setCursor(map->studio, tic_cursor_hand); 452 452 453 - if(checkMouseDown(&rect, tic_mouse_left)) 453 + if(checkMouseDown(map->studio, &rect, tic_mouse_left)) 454 454 { 455 455 s32 mx = tic_api_mouse(tic).x - rect.x; 456 456 s32 my = tic_api_mouse(tic).y - rect.y; ··· 486 486 487 487 tic_api_clip(tic, x, y + map->anim.pos.sheet, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE); 488 488 489 - tiles2ram(&tic->ram, getBankTiles()); 489 + tiles2ram(&tic->ram, getBankTiles(map->studio)); 490 490 491 491 tic_blit blit = map->sheet.blit; 492 492 SCOPE(resetBlitMode(map->tic), tic_api_clip(tic, 0, 0, TIC80_WIDTH, TIC80_HEIGHT)) ··· 611 611 { 612 612 tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; 613 613 614 - setCursor(tic_cursor_hand); 614 + setCursor(map->studio, tic_cursor_hand); 615 615 616 616 drawTileCursor(map); 617 617 618 - if(checkMouseDown(&rect, tic_mouse_left)) 618 + if(checkMouseDown(map->studio, &rect, tic_mouse_left)) 619 619 { 620 620 s32 tx = 0, ty = 0; 621 621 getMouseMap(map, &tx, &ty); ··· 639 639 map->canvas.draw = false; 640 640 } 641 641 642 - if(checkMouseDown(&rect, tic_mouse_middle)) 642 + if(checkMouseDown(map->studio, &rect, tic_mouse_middle)) 643 643 { 644 644 s32 tx = 0, ty = 0; 645 645 getMouseMap(map, &tx, &ty); ··· 666 666 667 667 normalizeMap(&map->scroll.x, &map->scroll.y); 668 668 669 - setCursor(tic_cursor_hand); 669 + setCursor(map->studio, tic_cursor_hand); 670 670 } 671 671 else map->scroll.active = false; 672 672 } 673 - else if(checkMousePos(&rect)) 673 + else if(checkMousePos(map->studio, &rect)) 674 674 { 675 675 if(pressed) 676 676 { ··· 686 686 { 687 687 tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; 688 688 689 - processScrolling(map, checkMouseDown(&rect, tic_mouse_left) || 690 - checkMouseDown(&rect, tic_mouse_right)); 689 + processScrolling(map, checkMouseDown(map->studio, &rect, tic_mouse_left) || 690 + checkMouseDown(map->studio, &rect, tic_mouse_right)); 691 691 } 692 692 693 693 static void resetSelection(Map* map) ··· 721 721 722 722 tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; 723 723 724 - if(checkMouseClick(&rect, tic_mouse_left)) 724 + if(checkMouseClick(map->studio, &rect, tic_mouse_left)) 725 725 { 726 726 normalizeMap(&mx, &my); 727 727 ··· 794 794 tic_mem* tic = map->tic; 795 795 tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; 796 796 797 - if(checkMousePos(&rect)) 797 + if(checkMousePos(map->studio, &rect)) 798 798 { 799 799 if(map->paste) 800 800 drawPasteData(map); 801 801 else 802 802 { 803 - if(checkMouseDown(&rect, tic_mouse_left)) 803 + if(checkMouseDown(map->studio, &rect, tic_mouse_left)) 804 804 { 805 805 s32 mx = tic_api_mouse(tic).x + map->scroll.x; 806 806 s32 my = tic_api_mouse(tic).y + map->scroll.y; ··· 1001 1001 { 1002 1002 tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; 1003 1003 1004 - setCursor(tic_cursor_hand); 1004 + setCursor(map->studio, tic_cursor_hand); 1005 1005 1006 1006 drawTileCursor(map); 1007 1007 1008 - if(checkMouseClick(&rect, tic_mouse_left)) 1008 + if(checkMouseClick(map->studio, &rect, tic_mouse_left)) 1009 1009 { 1010 1010 s32 tx = 0, ty = 0; 1011 1011 getMouseMap(map, &tx, &ty); ··· 1080 1080 tic_mem* tic = map->tic; 1081 1081 tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; 1082 1082 1083 - bool handle = !sheetVisible(map) && checkMousePos(&rect); 1083 + bool handle = !sheetVisible(map) && checkMousePos(map->studio, &rect); 1084 1084 bool space = tic_api_key(tic, tic_key_space); 1085 1085 1086 1086 if(handle) 1087 1087 processScrolling(map, 1088 - ((space || map->mode == MAP_DRAG_MODE) && checkMouseDown(&rect, tic_mouse_left)) || 1089 - checkMouseDown(&rect, tic_mouse_right)); 1088 + ((space || map->mode == MAP_DRAG_MODE) && checkMouseDown(map->studio, &rect, tic_mouse_left)) || 1089 + checkMouseDown(map->studio, &rect, tic_mouse_right)); 1090 1090 1091 1091 { 1092 1092 s32 scrollX = map->scroll.x % TIC_SPRITESIZE; ··· 1239 1239 1240 1240 bool ctrl = tic_api_key(tic, tic_key_ctrl); 1241 1241 1242 - switch(getClipboardEvent()) 1242 + switch(getClipboardEvent(map->studio)) 1243 1243 { 1244 1244 case TIC_CLIPBOARD_CUT: cutToClipboard(map); break; 1245 1245 case TIC_CLIPBOARD_COPY: copyToClipboard(map); break; ··· 1252 1252 1253 1253 if(ctrl) 1254 1254 { 1255 - if(keyWasPressed(tic_key_z)) undo(map); 1256 - else if(keyWasPressed(tic_key_y)) redo(map); 1255 + if(keyWasPressed(map->studio, tic_key_z)) undo(map); 1256 + else if(keyWasPressed(map->studio, tic_key_y)) redo(map); 1257 1257 } 1258 1258 else 1259 1259 { 1260 - if(keyWasPressed(tic_key_tab)) setStudioMode(TIC_WORLD_MODE); 1261 - else if(keyWasPressed(tic_key_1)) map->mode = MAP_DRAW_MODE; 1262 - else if(keyWasPressed(tic_key_2)) map->mode = MAP_DRAG_MODE; 1263 - else if(keyWasPressed(tic_key_3)) map->mode = MAP_SELECT_MODE; 1264 - else if(keyWasPressed(tic_key_4)) map->mode = MAP_FILL_MODE; 1265 - else if(keyWasPressed(tic_key_delete)) deleteSelection(map); 1266 - else if(keyWasPressed(tic_key_grave)) map->canvas.grid = !map->canvas.grid; 1260 + if(keyWasPressed(map->studio, tic_key_tab)) setStudioMode(map->studio, TIC_WORLD_MODE); 1261 + else if(keyWasPressed(map->studio, tic_key_1)) map->mode = MAP_DRAW_MODE; 1262 + else if(keyWasPressed(map->studio, tic_key_2)) map->mode = MAP_DRAG_MODE; 1263 + else if(keyWasPressed(map->studio, tic_key_3)) map->mode = MAP_SELECT_MODE; 1264 + else if(keyWasPressed(map->studio, tic_key_4)) map->mode = MAP_FILL_MODE; 1265 + else if(keyWasPressed(map->studio, tic_key_delete)) deleteSelection(map); 1266 + else if(keyWasPressed(map->studio, tic_key_grave)) map->canvas.grid = !map->canvas.grid; 1267 1267 } 1268 1268 1269 1269 enum{Step = 1}; ··· 1293 1293 // process scroll 1294 1294 if(tic->ram.input.mouse.scrolly > 0) 1295 1295 { 1296 - setStudioMode(TIC_WORLD_MODE); 1296 + setStudioMode(map->studio, TIC_WORLD_MODE); 1297 1297 return; 1298 1298 } 1299 1299 ··· 1306 1306 { 1307 1307 tic_api_cls(tic, tic->ram.vram.vars.clear = tic_color_dark_blue); 1308 1308 1309 - memcpy(tic->ram.vram.palette.data, getConfig()->cart->bank0.palette.vbank0.data, sizeof(tic_palette)); 1309 + memcpy(tic->ram.vram.palette.data, getConfig(map->studio)->cart->bank0.palette.vbank0.data, sizeof(tic_palette)); 1310 1310 1311 1311 tic_api_clip(tic, 0, TOOLBAR_SIZE, TIC80_WIDTH - (sheetVisible(map) ? TIC_SPRITESHEET_SIZE+2 : 0), TIC80_HEIGHT - TOOLBAR_SIZE); 1312 1312 { ··· 1322 1322 1323 1323 { 1324 1324 tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; 1325 - if(!sheetVisible(map) && checkMousePos(&rect) && !tic_api_key(tic, tic_key_space)) 1325 + if(!sheetVisible(map) && checkMousePos(map->studio, &rect) && !tic_api_key(tic, tic_key_space)) 1326 1326 { 1327 1327 switch(map->mode) 1328 1328 { ··· 1344 1344 drawSelectionVBank1(map); 1345 1345 1346 1346 drawMapToolbar(map, TIC80_WIDTH, 1); 1347 - drawToolbar(map->tic, false); 1347 + drawToolbar(map->studio, map->tic, false); 1348 1348 } 1349 1349 } 1350 1350 ··· 1363 1363 1364 1364 static void scanline(tic_mem* tic, s32 row, void* data) 1365 1365 { 1366 + Map* map = data; 1366 1367 if(row == 0) 1367 - memcpy(&tic->ram.vram.palette, getBankPalette(false), sizeof(tic_palette)); 1368 + memcpy(&tic->ram.vram.palette, getBankPalette(map->studio, false), sizeof(tic_palette)); 1368 1369 } 1369 1370 1370 1371 static void emptyDone(void* data) {} ··· 1383 1384 FREE(map->anim.page.items); 1384 1385 } 1385 1386 1386 - void initMap(Map* map, tic_mem* tic, tic_map* src) 1387 + void initMap(Map* map, Studio* studio, tic_map* src) 1387 1388 { 1388 1389 enum {SheetStart = -(TIC_SPRITESHEET_SIZE + TOOLBAR_SIZE)}; 1389 1390 ··· 1392 1393 1393 1394 *map = (Map) 1394 1395 { 1395 - .tic = tic, 1396 + .studio = studio, 1397 + .tic = getMemory(studio), 1396 1398 .tick = tick, 1397 1399 .src = src, 1398 1400 .mode = MAP_DRAW_MODE,
+2 -1
src/studio/editors/map.h
··· 29 29 30 30 struct Map 31 31 { 32 + Studio* studio; 32 33 tic_mem* tic; 33 34 34 35 tic_map* src; ··· 107 108 void (*scanline)(tic_mem* tic, s32 row, void* data); 108 109 }; 109 110 110 - void initMap(Map*, tic_mem*, tic_map* src); 111 + void initMap(Map*, Studio* studio, tic_map* src); 111 112 void freeMap(Map* map);
+130 -129
src/studio/editors/music.c
··· 94 94 95 95 bool over = false; 96 96 bool down = false; 97 - if (checkMousePos(&rect)) 97 + if (checkMousePos(music->studio, &rect)) 98 98 { 99 - setCursor(tic_cursor_hand); 99 + setCursor(music->studio, tic_cursor_hand); 100 100 over = true; 101 101 102 - if (checkMouseDown(&rect, tic_mouse_left)) 102 + if (checkMouseDown(music->studio, &rect, tic_mouse_left)) 103 103 down = true; 104 104 105 - if (checkMouseClick(&rect, tic_mouse_left)) 105 + if (checkMouseClick(music->studio, &rect, tic_mouse_left)) 106 106 set(music, -1, channel); 107 107 } 108 108 109 - drawBitIcon(tic_icon_left, rect.x - 2, rect.y + (down ? 1 : 0), tic_color_black); 110 - drawBitIcon(tic_icon_left, rect.x - 2, rect.y + (down ? 0 : -1), (over ? tic_color_light_grey : tic_color_dark_grey)); 109 + drawBitIcon(music->studio, tic_icon_left, rect.x - 2, rect.y + (down ? 1 : 0), tic_color_black); 110 + drawBitIcon(music->studio, tic_icon_left, rect.x - 2, rect.y + (down ? 0 : -1), (over ? tic_color_light_grey : tic_color_dark_grey)); 111 111 } 112 112 113 113 { 114 114 tic_rect rect = { x-1, y-1, TIC_FONT_WIDTH*2+1, TIC_FONT_HEIGHT+1 }; 115 115 116 - if (checkMousePos(&rect)) 116 + if (checkMousePos(music->studio, &rect)) 117 117 { 118 - setCursor(tic_cursor_hand); 118 + setCursor(music->studio, tic_cursor_hand); 119 119 120 - showTooltip("select pattern ID"); 120 + showTooltip(music->studio, "select pattern ID"); 121 121 122 - if (checkMouseClick(&rect, tic_mouse_left)) 122 + if (checkMouseClick(music->studio, &rect, tic_mouse_left)) 123 123 { 124 124 music->tracker.edit.y = -1; 125 125 music->tracker.edit.x = channel * CHANNEL_COLS; ··· 146 146 147 147 bool over = false; 148 148 bool down = false; 149 - if (checkMousePos(&rect)) 149 + if (checkMousePos(music->studio, &rect)) 150 150 { 151 - setCursor(tic_cursor_hand); 151 + setCursor(music->studio, tic_cursor_hand); 152 152 over = true; 153 153 154 - if (checkMouseDown(&rect, tic_mouse_left)) 154 + if (checkMouseDown(music->studio, &rect, tic_mouse_left)) 155 155 down = true; 156 156 157 - if (checkMouseClick(&rect, tic_mouse_left)) 157 + if (checkMouseClick(music->studio, &rect, tic_mouse_left)) 158 158 set(music, +1, channel); 159 159 } 160 160 161 - drawBitIcon(tic_icon_right, rect.x - 1, rect.y + (down ? 1 : 0), tic_color_black); 162 - drawBitIcon(tic_icon_right, rect.x - 1, rect.y + (down ? 0 : -1), (over ? tic_color_light_grey : tic_color_dark_grey)); 161 + drawBitIcon(music->studio, tic_icon_right, rect.x - 1, rect.y + (down ? 1 : 0), tic_color_black); 162 + drawBitIcon(music->studio, tic_icon_right, rect.x - 1, rect.y + (down ? 0 : -1), (over ? tic_color_light_grey : tic_color_dark_grey)); 163 163 } 164 164 } 165 165 ··· 175 175 176 176 bool over = false; 177 177 bool down = false; 178 - if (checkMousePos(&rect)) 178 + if (checkMousePos(music->studio, &rect)) 179 179 { 180 - setCursor(tic_cursor_hand); 180 + setCursor(music->studio, tic_cursor_hand); 181 181 182 182 over = true; 183 183 184 - if (checkMouseDown(&rect, tic_mouse_left)) 184 + if (checkMouseDown(music->studio, &rect, tic_mouse_left)) 185 185 down = true; 186 186 187 - if (checkMouseClick(&rect, tic_mouse_left)) 187 + if (checkMouseClick(music->studio, &rect, tic_mouse_left)) 188 188 set(music, -1, data); 189 189 } 190 190 191 - drawBitIcon(tic_icon_left, rect.x - 2, rect.y + (down ? 1 : 0), tic_color_black); 192 - drawBitIcon(tic_icon_left, rect.x - 2, rect.y + (down ? 0 : -1), over ? tic_color_light_grey : tic_color_dark_grey); 191 + drawBitIcon(music->studio, tic_icon_left, rect.x - 2, rect.y + (down ? 1 : 0), tic_color_black); 192 + drawBitIcon(music->studio, tic_icon_left, rect.x - 2, rect.y + (down ? 0 : -1), over ? tic_color_light_grey : tic_color_dark_grey); 193 193 } 194 194 195 195 { ··· 204 204 205 205 bool over = false; 206 206 bool down = false; 207 - if (checkMousePos(&rect)) 207 + if (checkMousePos(music->studio, &rect)) 208 208 { 209 - setCursor(tic_cursor_hand); 209 + setCursor(music->studio, tic_cursor_hand); 210 210 211 211 over = true; 212 212 213 - if (checkMouseDown(&rect, tic_mouse_left)) 213 + if (checkMouseDown(music->studio, &rect, tic_mouse_left)) 214 214 down = true; 215 215 216 - if (checkMouseClick(&rect, tic_mouse_left)) 216 + if (checkMouseClick(music->studio, &rect, tic_mouse_left)) 217 217 set(music, +1, data); 218 218 } 219 219 220 - drawBitIcon(tic_icon_right, rect.x - 2, rect.y + (down ? 1 : 0), tic_color_black); 221 - drawBitIcon(tic_icon_right, rect.x - 2, rect.y + (down ? 0 : -1), over ? tic_color_light_grey : tic_color_dark_grey); 220 + drawBitIcon(music->studio, tic_icon_right, rect.x - 2, rect.y + (down ? 1 : 0), tic_color_black); 221 + drawBitIcon(music->studio, tic_icon_right, rect.x - 2, rect.y + (down ? 0 : -1), over ? tic_color_light_grey : tic_color_dark_grey); 222 222 } 223 223 } 224 224 ··· 1016 1016 }; 1017 1017 1018 1018 for(const struct Handler *ptr = Handlers, *end = ptr + COUNT_OF(Handlers); ptr < end; ptr++) 1019 - if(keyWasPressed(ptr->key)) 1019 + if(keyWasPressed(music->studio, ptr->key)) 1020 1020 { 1021 1021 if(shift && ptr->select) 1022 1022 startSelection(music); ··· 1078 1078 { 1079 1079 case ColumnNote: 1080 1080 case ColumnSemitone: 1081 - if (keyWasPressed(tic_key_1) || keyWasPressed(tic_key_a)) 1081 + if (keyWasPressed(music->studio, tic_key_1) || keyWasPressed(music->studio, tic_key_a)) 1082 1082 { 1083 1083 setStopNote(music); 1084 1084 downRow(music); ··· 1089 1089 1090 1090 for (s32 i = 0; i < COUNT_OF(Piano); i++) 1091 1091 { 1092 - if (keyWasPressed(Piano[i])) 1092 + if (keyWasPressed(music->studio, Piano[i])) 1093 1093 { 1094 1094 s32 note = i % NOTES; 1095 1095 s32 octave = i / NOTES + music->last.octave; ··· 1108 1108 { 1109 1109 s32 octave = -1; 1110 1110 1111 - char sym = getKeyboardText(); 1111 + char sym = getKeyboardText(music->studio); 1112 1112 1113 1113 if(sym >= '1' && sym <= '8') octave = sym - '1'; 1114 1114 ··· 1123 1123 case ColumnSfxLow: 1124 1124 if(getNote(music) >= 0) 1125 1125 { 1126 - s32 val = sym2dec(getKeyboardText()); 1126 + s32 val = sym2dec(getKeyboardText(music->studio)); 1127 1127 1128 1128 if(val >= 0) 1129 1129 { ··· 1138 1138 break; 1139 1139 case ColumnCommand: 1140 1140 { 1141 - char sym = getKeyboardText(); 1141 + char sym = getKeyboardText(music->studio); 1142 1142 1143 1143 if(sym) 1144 1144 { ··· 1152 1152 case ColumnParameter1: 1153 1153 case ColumnParameter2: 1154 1154 { 1155 - s32 val = sym2hex(getKeyboardText()); 1155 + s32 val = sym2hex(getKeyboardText(music->studio)); 1156 1156 1157 1157 if(val >= 0) 1158 1158 { ··· 1167 1167 history_add(music->history); 1168 1168 } 1169 1169 1170 - switch (getKeyboardText()) 1170 + switch (getKeyboardText(music->studio)) 1171 1171 { 1172 1172 case '+': setChannelPattern(music, +1, music->tracker.edit.x / CHANNEL_COLS); break; 1173 1173 case '-': setChannelPattern(music, -1, music->tracker.edit.x / CHANNEL_COLS); break; ··· 1183 1183 if(tic_api_key(tic, tic_key_ctrl) || tic_api_key(tic, tic_key_alt)) 1184 1184 return; 1185 1185 1186 - if(keyWasPressed(tic_key_delete)) setChannelPatternValue(music, 0, music->frame, channel); 1187 - else if(keyWasPressed(tic_key_tab)) nextPattern(music); 1188 - else if(keyWasPressed(tic_key_left)) colLeft(music); 1189 - else if(keyWasPressed(tic_key_right)) colRight(music); 1190 - else if(keyWasPressed(tic_key_down) 1191 - || keyWasPressed(tic_key_return)) 1186 + if(keyWasPressed(music->studio, tic_key_delete)) setChannelPatternValue(music, 0, music->frame, channel); 1187 + else if(keyWasPressed(music->studio, tic_key_tab)) nextPattern(music); 1188 + else if(keyWasPressed(music->studio, tic_key_left)) colLeft(music); 1189 + else if(keyWasPressed(music->studio, tic_key_right)) colRight(music); 1190 + else if(keyWasPressed(music->studio, tic_key_down) 1191 + || keyWasPressed(music->studio, tic_key_return)) 1192 1192 music->tracker.edit.y = music->scroll.pos; 1193 1193 else 1194 1194 { 1195 - s32 val = sym2dec(getKeyboardText()); 1195 + s32 val = sym2dec(getKeyboardText(music->studio)); 1196 1196 1197 1197 if(val >= 0) 1198 1198 { ··· 1335 1335 { 1336 1336 tic_mem* tic = music->tic; 1337 1337 1338 - if(keyWasPressed(tic_key_up)) music->piano.edit.y--; 1339 - else if(keyWasPressed(tic_key_down)) music->piano.edit.y++; 1340 - else if(keyWasPressed(tic_key_left)) music->piano.edit.x--; 1341 - else if(keyWasPressed(tic_key_right)) music->piano.edit.x++; 1342 - else if(keyWasPressed(tic_key_home)) music->piano.edit.x = PianoChannel1Column; 1343 - else if(keyWasPressed(tic_key_end)) music->piano.edit.x = PianoColumnsCount*2+1; 1344 - else if(keyWasPressed(tic_key_pageup)) music->piano.edit.y -= TRACKER_ROWS; 1345 - else if(keyWasPressed(tic_key_pagedown)) music->piano.edit.y += TRACKER_ROWS; 1338 + if(keyWasPressed(music->studio, tic_key_up)) music->piano.edit.y--; 1339 + else if(keyWasPressed(music->studio, tic_key_down)) music->piano.edit.y++; 1340 + else if(keyWasPressed(music->studio, tic_key_left)) music->piano.edit.x--; 1341 + else if(keyWasPressed(music->studio, tic_key_right)) music->piano.edit.x++; 1342 + else if(keyWasPressed(music->studio, tic_key_home)) music->piano.edit.x = PianoChannel1Column; 1343 + else if(keyWasPressed(music->studio, tic_key_end)) music->piano.edit.x = PianoColumnsCount*2+1; 1344 + else if(keyWasPressed(music->studio, tic_key_pageup)) music->piano.edit.y -= TRACKER_ROWS; 1345 + else if(keyWasPressed(music->studio, tic_key_pagedown)) music->piano.edit.y += TRACKER_ROWS; 1346 1346 1347 1347 updatePianoEditPos(music); 1348 1348 1349 - if(keyWasPressed(tic_key_delete)) 1349 + if(keyWasPressed(music->studio, tic_key_delete)) 1350 1350 { 1351 1351 s32 col = music->piano.edit.x / 2; 1352 1352 switch(col) ··· 1380 1380 } 1381 1381 } 1382 1382 1383 - if(getKeyboardText()) 1384 - setPianoValue(music, getKeyboardText()); 1383 + if(getKeyboardText(music->studio)) 1384 + setPianoValue(music, getKeyboardText(music->studio)); 1385 1385 } 1386 1386 1387 1387 static void selectAll(Music* music) ··· 1401 1401 { 1402 1402 tic_mem* tic = music->tic; 1403 1403 1404 - switch(getClipboardEvent()) 1404 + switch(getClipboardEvent(music->studio)) 1405 1405 { 1406 1406 case TIC_CLIPBOARD_CUT: copyToClipboard(music, true); break; 1407 1407 case TIC_CLIPBOARD_COPY: copyToClipboard(music, false); break; ··· 1417 1417 1418 1418 if (ctrl) 1419 1419 { 1420 - if(keyWasPressed(tic_key_a)) selectAll(music); 1421 - else if(keyWasPressed(tic_key_z)) undo(music); 1422 - else if(keyWasPressed(tic_key_y)) redo(music); 1423 - else if(keyWasPressed(tic_key_f)) toggleFollowMode(music); 1420 + if(keyWasPressed(music->studio, tic_key_a)) selectAll(music); 1421 + else if(keyWasPressed(music->studio, tic_key_z)) undo(music); 1422 + else if(keyWasPressed(music->studio, tic_key_y)) redo(music); 1423 + else if(keyWasPressed(music->studio, tic_key_f)) toggleFollowMode(music); 1424 1424 } 1425 1425 1426 1426 { 1427 1427 bool stopped = getMusicPos(music)->music.track < 0; 1428 1428 1429 - if(keyWasPressed(tic_key_space)) 1429 + if(keyWasPressed(music->studio, tic_key_space)) 1430 1430 { 1431 1431 stopped 1432 1432 ? playTrack(music) 1433 1433 : stopTrack(music); 1434 1434 } 1435 - else if(keyWasPressed(tic_key_return)) 1435 + else if(keyWasPressed(music->studio, tic_key_return)) 1436 1436 { 1437 1437 stopped 1438 1438 ? (shift && music->tab == MUSIC_TRACKER_TAB ··· 1553 1553 { 1554 1554 tic_rect rect = { x - Border, y - Border, Width, MUSIC_FRAMES * TIC_FONT_HEIGHT + Border }; 1555 1555 1556 - if (checkMousePos(&rect)) 1556 + if (checkMousePos(music->studio, &rect)) 1557 1557 { 1558 - setCursor(tic_cursor_hand); 1558 + setCursor(music->studio, tic_cursor_hand); 1559 1559 1560 - showTooltip("select frame"); 1560 + showTooltip(music->studio, "select frame"); 1561 1561 1562 - if (checkMouseDown(&rect, tic_mouse_left)) 1562 + if (checkMouseDown(music->studio, &rect, tic_mouse_left)) 1563 1563 { 1564 1564 s32 my = tic_api_mouse(tic).y - rect.y - Border; 1565 1565 music->frame = my / TIC_FONT_HEIGHT; ··· 1573 1573 { 1574 1574 if (checkPlayFrame(music, i)) 1575 1575 { 1576 - drawBitIcon(tic_icon_right, x - TIC_FONT_WIDTH-2, y + i*TIC_FONT_HEIGHT, tic_color_black); 1577 - drawBitIcon(tic_icon_right, x - TIC_FONT_WIDTH-2, y - 1 + i*TIC_FONT_HEIGHT, tic_color_white); 1576 + drawBitIcon(music->studio, tic_icon_right, x - TIC_FONT_WIDTH-2, y + i*TIC_FONT_HEIGHT, tic_color_black); 1577 + drawBitIcon(music->studio, tic_icon_right, x - TIC_FONT_WIDTH-2, y - 1 + i*TIC_FONT_HEIGHT, tic_color_white); 1578 1578 } 1579 1579 1580 1580 char buf[sizeof "99"]; ··· 1615 1615 1616 1616 tic_rect rect = {x - Border, y - Border, Width, Rows*TIC_FONT_HEIGHT + Border}; 1617 1617 1618 - if(checkMousePos(&rect)) 1618 + if(checkMousePos(music->studio, &rect)) 1619 1619 { 1620 - setCursor(tic_cursor_hand); 1620 + setCursor(music->studio, tic_cursor_hand); 1621 1621 1622 - if(checkMouseDown(&rect, tic_mouse_left)) 1622 + if(checkMouseDown(music->studio, &rect, tic_mouse_left)) 1623 1623 { 1624 1624 s32 mx = tic_api_mouse(tic).x - rect.x - Border; 1625 1625 s32 my = tic_api_mouse(tic).y - rect.y - Border; ··· 1644 1644 if(music->tracker.select.drag) 1645 1645 { 1646 1646 tic_rect rect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT}; 1647 - if(!checkMouseDown(&rect, tic_mouse_left)) 1647 + if(!checkMouseDown(music->studio, &rect, tic_mouse_left)) 1648 1648 { 1649 1649 music->tracker.select.drag = false; 1650 1650 } ··· 1743 1743 1744 1744 tic_rect rect = {x, y, Width, Height}; 1745 1745 1746 - if(checkMousePos(&rect)) 1746 + if(checkMousePos(music->studio, &rect)) 1747 1747 { 1748 - setCursor(tic_cursor_hand); 1748 + setCursor(music->studio, tic_cursor_hand); 1749 1749 1750 - showTooltip("on/off channel"); 1750 + showTooltip(music->studio, "on/off channel"); 1751 1751 1752 - if(checkMouseClick(&rect, tic_mouse_left)) 1752 + if(checkMouseClick(music->studio, &rect, tic_mouse_left)) 1753 1753 { 1754 1754 if (tic_api_key(tic, tic_key_ctrl)) 1755 1755 { ··· 1763 1763 drawEditPanel(music, x, y, Width, Height); 1764 1764 1765 1765 u8 color = tic_color_black; 1766 - tiles2ram(&tic->ram, &getConfig()->cart->bank0.tiles); 1766 + tiles2ram(&tic->ram, &getConfig(music->studio)->cart->bank0.tiles); 1767 1767 tic_api_spr(tic, music->on[index] ? On : Off, x, y, 1, 1, &color, 1, 1, tic_no_flip, tic_no_rotate); 1768 1768 } 1769 1769 ··· 1861 1861 { 1862 1862 bool over = false; 1863 1863 1864 - if (checkMousePos(&rect)) 1864 + if (checkMousePos(music->studio, &rect)) 1865 1865 { 1866 - setCursor(tic_cursor_hand); 1866 + setCursor(music->studio, tic_cursor_hand); 1867 1867 over = true; 1868 1868 1869 - showTooltip(btn->alt && music->tickCounter % (TIC80_FRAMERATE * 2) < TIC80_FRAMERATE ? btn->alt : btn->tip); 1869 + showTooltip(music->studio, btn->alt && music->tickCounter % (TIC80_FRAMERATE * 2) < TIC80_FRAMERATE ? btn->alt : btn->tip); 1870 1870 1871 - if (checkMouseClick(&rect, tic_mouse_left)) 1871 + if (checkMouseClick(music->studio, &rect, tic_mouse_left)) 1872 1872 btn->handler(music); 1873 1873 } 1874 1874 1875 1875 if(btn->id == FollowButton && music->follow) 1876 - drawBitIcon(btn->icon, rect.x, rect.y, tic_color_green); 1876 + drawBitIcon(music->studio, btn->icon, rect.x, rect.y, tic_color_green); 1877 1877 1878 1878 else if(btn->id == SustainButton && music->sustain) 1879 - drawBitIcon(btn->icon, rect.x, rect.y, tic_color_green); 1879 + drawBitIcon(music->studio, btn->icon, rect.x, rect.y, tic_color_green); 1880 1880 1881 1881 else 1882 - drawBitIcon(btn->icon, rect.x, rect.y, over ? tic_color_grey : tic_color_light_grey); 1882 + drawBitIcon(music->studio, btn->icon, rect.x, rect.y, over ? tic_color_grey : tic_color_light_grey); 1883 1883 } 1884 1884 } 1885 1885 ··· 1897 1897 1898 1898 bool over = false; 1899 1899 1900 - if (checkMousePos(&rect)) 1900 + if (checkMousePos(music->studio, &rect)) 1901 1901 { 1902 - setCursor(tic_cursor_hand); 1902 + setCursor(music->studio, tic_cursor_hand); 1903 1903 over = true; 1904 1904 1905 1905 static const char* Tooltips[] = { "PIANO MODE", "TRACKER MODE" }; 1906 - showTooltip(Tooltips[i]); 1906 + showTooltip(music->studio, Tooltips[i]); 1907 1907 1908 - if (checkMouseClick(&rect, tic_mouse_left)) 1908 + if (checkMouseClick(music->studio, &rect, tic_mouse_left)) 1909 1909 music->tab = Tabs[i]; 1910 1910 } 1911 1911 1912 1912 if (music->tab == Tabs[i]) 1913 1913 { 1914 1914 tic_api_rect(music->tic, rect.x, rect.y, rect.w, rect.h, tic_color_grey); 1915 - drawBitIcon(Icons[i], rect.x, rect.y + 1, tic_color_black); 1915 + drawBitIcon(music->studio, Icons[i], rect.x, rect.y + 1, tic_color_black); 1916 1916 } 1917 1917 1918 - drawBitIcon(Icons[i], rect.x, rect.y, music->tab == Tabs[i] ? tic_color_white : over ? tic_color_grey : tic_color_light_grey); 1918 + drawBitIcon(music->studio, Icons[i], rect.x, rect.y, music->tab == Tabs[i] ? tic_color_white : over ? tic_color_grey : tic_color_light_grey); 1919 1919 } 1920 1920 } 1921 1921 ··· 1974 1974 1975 1975 if(playFrame >= 0) 1976 1976 { 1977 - drawBitIcon(tic_icon_right, x - TIC_ALTFONT_WIDTH - 1, y + playFrame * TIC_FONT_HEIGHT + Header, tic_color_black); 1978 - drawBitIcon(tic_icon_right, x - TIC_ALTFONT_WIDTH - 1, y + playFrame * TIC_FONT_HEIGHT + (Header - 1), tic_color_white); 1977 + drawBitIcon(music->studio, tic_icon_right, x - TIC_ALTFONT_WIDTH - 1, y + playFrame * TIC_FONT_HEIGHT + Header, tic_color_black); 1978 + drawBitIcon(music->studio, tic_icon_right, x - TIC_ALTFONT_WIDTH - 1, y + playFrame * TIC_FONT_HEIGHT + (Header - 1), tic_color_white); 1979 1979 } 1980 1980 } 1981 1981 ··· 1984 1984 { 1985 1985 tic_rect rect = {x, y + Header - 1, (TIC_FONT_WIDTH * 2 + 1) * TIC_SOUND_CHANNELS, MUSIC_FRAMES * TIC_FONT_HEIGHT + 1}; 1986 1986 1987 - if(checkMousePos(&rect)) 1987 + if(checkMousePos(music->studio, &rect)) 1988 1988 { 1989 - setCursor(tic_cursor_hand); 1989 + setCursor(music->studio, tic_cursor_hand); 1990 1990 1991 - if(checkMouseClick(&rect, tic_mouse_left)) 1991 + if(checkMouseClick(music->studio, &rect, tic_mouse_left)) 1992 1992 { 1993 1993 s32 col = (tic_api_mouse(tic).x - rect.x) * TIC_SOUND_CHANNELS / rect.w; 1994 1994 s32 row = (tic_api_mouse(tic).y - rect.y) * MUSIC_FRAMES / rect.h; ··· 2089 2089 {10, 41, 42, 36, tic_no_flip}, 2090 2090 }; 2091 2091 2092 - tiles2ram(&tic->ram, &getConfig()->cart->bank0.tiles); 2092 + tiles2ram(&tic->ram, &getConfig(music->studio)->cart->bank0.tiles); 2093 2093 2094 2094 for(s32 i = 0; i < COUNT_OF(Buttons); i++) 2095 2095 { ··· 2108 2108 2109 2109 tic_rect rect = {x, y, TIC_FONT_WIDTH*2 + 1, TRACKER_ROWS*TIC_FONT_HEIGHT + Header}; 2110 2110 2111 - if(checkMousePos(&rect)) 2111 + if(checkMousePos(music->studio, &rect)) 2112 2112 { 2113 - if(checkMouseDown(&rect, tic_mouse_left) || checkMouseDown(&rect, tic_mouse_right)) 2113 + if(checkMouseDown(music->studio, &rect, tic_mouse_left) || checkMouseDown(music->studio, &rect, tic_mouse_right)) 2114 2114 { 2115 - setCursor(tic_cursor_hand); 2115 + setCursor(music->studio, tic_cursor_hand); 2116 2116 2117 2117 if(music->scroll.active) 2118 2118 { ··· 2148 2148 2149 2149 tic_rect rect = {x, y + Header, NoteWidth * NOTES - 1, NoteHeight * TRACKER_ROWS - 1}; 2150 2150 2151 - if(checkMousePos(&rect)) 2151 + if(checkMousePos(music->studio, &rect)) 2152 2152 { 2153 2153 { 2154 2154 static const char Notes[] = "C D EF G A B"; 2155 2155 tic_api_print(tic, Notes, xpos, ypos, tic_color_dark_grey, true, 1, true); 2156 2156 } 2157 2157 2158 - showTooltip("set note"); 2158 + showTooltip(music->studio, "set note"); 2159 2159 2160 2160 static const char* Notes[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"}; 2161 2161 static const s32 Offsets[] = {0, 0, 2, 2, 4, 5, 5, 7, 7, 9, 9, 11}; ··· 2190 2190 tic_rect rect = {x + n * NoteWidth, y + Header + r * NoteHeight, NoteWidth - 1, NoteHeight - 1}; 2191 2191 2192 2192 bool over = false; 2193 - if(checkMousePos(&rect)) 2193 + if(checkMousePos(music->studio, &rect)) 2194 2194 { 2195 - setCursor(tic_cursor_hand); 2195 + setCursor(music->studio, tic_cursor_hand); 2196 2196 over = true; 2197 2197 2198 - if(checkMouseClick(&rect, tic_mouse_left)) 2198 + if(checkMouseClick(music->studio, &rect, tic_mouse_left)) 2199 2199 { 2200 2200 switch(row->note) 2201 2201 { ··· 2224 2224 2225 2225 history_add(music->history); 2226 2226 } 2227 - else if(checkMouseClick(&rect, tic_mouse_right)) 2227 + else if(checkMouseClick(music->studio, &rect, tic_mouse_right)) 2228 2228 { 2229 2229 switch(row->note) 2230 2230 { ··· 2296 2296 2297 2297 tic_rect rect = {x, y + Header, OctaveWidth * OCTAVES - 1, OctaveHeight * TRACKER_ROWS - 1}; 2298 2298 2299 - if(checkMousePos(&rect)) 2299 + if(checkMousePos(music->studio, &rect)) 2300 2300 { 2301 2301 s32 octave = (tic_api_mouse(tic).x - rect.x) / OctaveWidth; 2302 2302 s32 r = (tic_api_mouse(tic).y - rect.y) / OctaveHeight; ··· 2306 2306 2307 2307 if(row->note >= NoteStart) 2308 2308 { 2309 - showTooltip("set octave"); 2309 + showTooltip(music->studio, "set octave"); 2310 2310 2311 2311 tic_api_print(tic, "12345678", xpos, ypos, tic_color_dark_grey, true, 1, true); 2312 2312 tic_api_print(tic, (char[]){octave + '1', '\0'}, xpos + octave * OctaveWidth, ypos, tic_color_yellow, true, 1, true); ··· 2340 2340 tic_rect rect = {x + n * OctaveWidth, y + Header + r * OctaveHeight, OctaveWidth - 1, OctaveHeight - 1}; 2341 2341 2342 2342 bool over = false; 2343 - if(checkMousePos(&rect)) 2343 + if(checkMousePos(music->studio, &rect)) 2344 2344 { 2345 - setCursor(tic_cursor_hand); 2345 + setCursor(music->studio, tic_cursor_hand); 2346 2346 over = true; 2347 2347 2348 - if(checkMouseClick(&rect, tic_mouse_left)) 2348 + if(checkMouseClick(music->studio, &rect, tic_mouse_left)) 2349 2349 { 2350 2350 music->last.octave = row->octave = n; 2351 2351 history_add(music->history); ··· 2391 2391 { 2392 2392 tic_rect rect = {x, y + Header - 1, TIC_FONT_WIDTH * 2, TIC_FONT_HEIGHT * MUSIC_FRAMES}; 2393 2393 2394 - if(checkMousePos(&rect)) 2394 + if(checkMousePos(music->studio, &rect)) 2395 2395 { 2396 - setCursor(tic_cursor_hand); 2396 + setCursor(music->studio, tic_cursor_hand); 2397 2397 2398 - showTooltip("set sfx"); 2398 + showTooltip(music->studio, "set sfx"); 2399 2399 2400 - if(checkMouseClick(&rect, tic_mouse_left)) 2400 + if(checkMouseClick(music->studio, &rect, tic_mouse_left)) 2401 2401 { 2402 2402 music->piano.edit.x = PianoSfxColumn * 2 + (tic_api_mouse(tic).x - rect.x) / TIC_FONT_WIDTH; 2403 2403 music->piano.edit.y = (tic_api_mouse(tic).y - rect.y) / TIC_FONT_HEIGHT; ··· 2459 2459 { 2460 2460 tic_rect rect = {x, y + Header - 1, TIC_FONT_WIDTH * (tic_music_cmd_count - 1), TIC_FONT_HEIGHT * MUSIC_FRAMES}; 2461 2461 2462 - if(checkMousePos(&rect)) 2462 + if(checkMousePos(music->studio, &rect)) 2463 2463 { 2464 - setCursor(tic_cursor_hand); 2464 + setCursor(music->studio, tic_cursor_hand); 2465 2465 2466 - showTooltip("set command"); 2466 + showTooltip(music->studio, "set command"); 2467 2467 2468 2468 command = (tic_api_mouse(tic).x - rect.x) / TIC_FONT_WIDTH + 1; 2469 2469 overRow = (tic_api_mouse(tic).y - rect.y) / TIC_FONT_HEIGHT; ··· 2480 2480 tic_api_print(tic, Hints[command], 73, 129, tic_color_yellow, false, 1, true); 2481 2481 } 2482 2482 2483 - if(checkMouseClick(&rect, tic_mouse_left)) 2483 + if(checkMouseClick(music->studio, &rect, tic_mouse_left)) 2484 2484 { 2485 2485 tic_track_row* row = &pattern->rows[rowIndex(music, overRow)]; 2486 2486 ··· 2538 2538 { 2539 2539 tic_rect rect = {x, y + Header - 1, TIC_FONT_WIDTH * 2, TIC_FONT_HEIGHT * MUSIC_FRAMES}; 2540 2540 2541 - if(checkMousePos(&rect)) 2541 + if(checkMousePos(music->studio, &rect)) 2542 2542 { 2543 - setCursor(tic_cursor_hand); 2544 - showTooltip("set command XY"); 2543 + setCursor(music->studio, tic_cursor_hand); 2544 + showTooltip(music->studio, "set command XY"); 2545 2545 2546 2546 if(pattern) 2547 2547 { ··· 2556 2556 } 2557 2557 } 2558 2558 2559 - if(checkMouseClick(&rect, tic_mouse_left)) 2559 + if(checkMouseClick(music->studio, &rect, tic_mouse_left)) 2560 2560 { 2561 2561 music->piano.edit.x = PianoXYColumn * 2 + (tic_api_mouse(tic).x - rect.x) / TIC_FONT_WIDTH; 2562 2562 music->piano.edit.y = (tic_api_mouse(tic).y - rect.y) / TIC_FONT_HEIGHT; ··· 2642 2642 tic_rect rect = {x, y, (sizeof Label44 - 1) * TIC_ALTFONT_WIDTH - 1, TIC_FONT_HEIGHT - 1}; 2643 2643 2644 2644 bool down = false; 2645 - if(checkMousePos(&rect)) 2645 + if(checkMousePos(music->studio, &rect)) 2646 2646 { 2647 - setCursor(tic_cursor_hand); 2648 - showTooltip(music->beat34 ? "set 4 quarter note" : "set 3 quarter note"); 2647 + setCursor(music->studio, tic_cursor_hand); 2648 + showTooltip(music->studio, music->beat34 ? "set 4 quarter note" : "set 3 quarter note"); 2649 2649 2650 - if(checkMouseDown(&rect, tic_mouse_left)) 2650 + if(checkMouseDown(music->studio, &rect, tic_mouse_left)) 2651 2651 down = true; 2652 2652 2653 - if(checkMouseClick(&rect, tic_mouse_left)) 2653 + if(checkMouseClick(music->studio, &rect, tic_mouse_left)) 2654 2654 music->beat34 = !music->beat34; 2655 2655 } 2656 2656 ··· 2821 2821 } 2822 2822 2823 2823 drawMusicToolbar(music); 2824 - drawToolbar(music->tic, false); 2824 + drawToolbar(music->studio, music->tic, false); 2825 2825 2826 2826 music->tickCounter++; 2827 2827 } ··· 2839 2839 } 2840 2840 } 2841 2841 2842 - void initMusic(Music* music, tic_mem* tic, tic_music* src) 2842 + void initMusic(Music* music, Studio* studio, tic_music* src) 2843 2843 { 2844 2844 if (music->history) history_delete(music->history); 2845 2845 2846 2846 *music = (Music) 2847 2847 { 2848 - .tic = tic, 2848 + .studio = studio, 2849 + .tic = getMemory(studio), 2849 2850 .tick = tick, 2850 2851 .src = src, 2851 2852 .track = 0,
+2 -1
src/studio/editors/music.h
··· 28 28 29 29 struct Music 30 30 { 31 + Studio* studio; 31 32 tic_mem* tic; 32 33 tic_music* src; 33 34 ··· 87 88 void(*event)(Music*, StudioEvent); 88 89 }; 89 90 90 - void initMusic(Music*, tic_mem*, tic_music* src); 91 + void initMusic(Music*, Studio* studio, tic_music* src); 91 92 void freeMusic(Music* music);
+83 -82
src/studio/editors/sfx.c
··· 86 86 tic_sample* effect = getEffect(sfx); 87 87 tic_rect border = {-1}; 88 88 89 - if(checkMousePos(&rect)) 89 + if(checkMousePos(sfx->studio, &rect)) 90 90 { 91 - setCursor(tic_cursor_hand); 91 + setCursor(sfx->studio, tic_cursor_hand); 92 92 93 93 s32 mx = tic_api_mouse(tic).x - x; 94 94 s32 my = tic_api_mouse(tic).y - y; ··· 105 105 default: break; 106 106 } 107 107 108 - SHOW_TOOLTIP("[x=%02i y=%02i]", mx, vy); 108 + SHOW_TOOLTIP(sfx->studio, "[x=%02i y=%02i]", mx, vy); 109 109 110 - if(checkMouseDown(&rect, tic_mouse_left)) 110 + if(checkMouseDown(sfx->studio, &rect, tic_mouse_left)) 111 111 { 112 112 switch(canvasTab) 113 113 { ··· 175 175 tic_rect rect = {x, y, Width, Height}; 176 176 177 177 bool hover = false; 178 - if(checkMousePos(&rect)) 178 + if(checkMousePos(sfx->studio, &rect)) 179 179 { 180 - setCursor(tic_cursor_hand); 180 + setCursor(sfx->studio, tic_cursor_hand); 181 181 hover = true; 182 182 183 - showTooltip("left stereo"); 183 + showTooltip(sfx->studio, "left stereo"); 184 184 185 - if(checkMouseClick(&rect, tic_mouse_left)) 185 + if(checkMouseClick(sfx->studio, &rect, tic_mouse_left)) 186 186 effect->stereo_left = ~effect->stereo_left; 187 187 } 188 188 ··· 193 193 tic_rect rect = {x + 4, y, Width, Height}; 194 194 195 195 bool hover = false; 196 - if(checkMousePos(&rect)) 196 + if(checkMousePos(sfx->studio, &rect)) 197 197 { 198 - setCursor(tic_cursor_hand); 198 + setCursor(sfx->studio, tic_cursor_hand); 199 199 hover = true; 200 200 201 - showTooltip("right stereo"); 201 + showTooltip(sfx->studio, "right stereo"); 202 202 203 - if(checkMouseClick(&rect, tic_mouse_left)) 203 + if(checkMouseClick(sfx->studio, &rect, tic_mouse_left)) 204 204 effect->stereo_right = ~effect->stereo_right; 205 205 } 206 206 ··· 222 222 tic_rect rect = {x, y, Width, Height}; 223 223 224 224 bool hover = false; 225 - if(checkMousePos(&rect)) 225 + if(checkMousePos(sfx->studio, &rect)) 226 226 { 227 - setCursor(tic_cursor_hand); 227 + setCursor(sfx->studio, tic_cursor_hand); 228 228 hover = true; 229 229 230 - showTooltip("up/down arpeggio"); 230 + showTooltip(sfx->studio, "up/down arpeggio"); 231 231 232 - if(checkMouseClick(&rect, tic_mouse_left)) 232 + if(checkMouseClick(sfx->studio, &rect, tic_mouse_left)) 233 233 effect->reverse = ~effect->reverse; 234 234 } 235 235 ··· 251 251 tic_rect rect = {x, y, Width, Height}; 252 252 253 253 bool hover = false; 254 - if(checkMousePos(&rect)) 254 + if(checkMousePos(sfx->studio, &rect)) 255 255 { 256 - setCursor(tic_cursor_hand); 256 + setCursor(sfx->studio, tic_cursor_hand); 257 257 hover = true; 258 258 259 - showTooltip("x16 pitch"); 259 + showTooltip(sfx->studio, "x16 pitch"); 260 260 261 - if(checkMouseClick(&rect, tic_mouse_left)) 261 + if(checkMouseClick(sfx->studio, &rect, tic_mouse_left)) 262 262 effect->pitch16x = ~effect->pitch16x; 263 263 } 264 264 ··· 285 285 286 286 bool hover = false; 287 287 288 - if(checkMousePos(&rect)) 288 + if(checkMousePos(sfx->studio, &rect)) 289 289 { 290 - showTooltip(item->tip); 290 + showTooltip(sfx->studio, item->tip); 291 291 292 - setCursor(tic_cursor_hand); 292 + setCursor(sfx->studio, tic_cursor_hand); 293 293 294 294 hover = true; 295 295 296 - if(checkMouseClick(&rect, tic_mouse_left)) 296 + if(checkMouseClick(sfx->studio, &rect, tic_mouse_left)) 297 297 sfx->volwave = item->panel; 298 298 } 299 299 ··· 349 349 tic_rect rect = {x + 2, y + 27, ArrowWidth, ArrowHeight}; 350 350 bool hover = false; 351 351 352 - if(checkMousePos(&rect)) 352 + if(checkMousePos(sfx->studio, &rect)) 353 353 { 354 - setCursor(tic_cursor_hand); 354 + setCursor(sfx->studio, tic_cursor_hand); 355 355 hover = true; 356 356 357 - showTooltip(SetLoopPosLabel); 357 + showTooltip(sfx->studio, SetLoopPosLabel); 358 358 359 - if(checkMouseClick(&rect, tic_mouse_left)) 359 + if(checkMouseClick(sfx->studio, &rect, tic_mouse_left)) 360 360 { 361 361 effect->loops[canvasTab].start--; 362 362 history_add(sfx->history); 363 363 } 364 364 } 365 365 366 - drawBitIcon(tic_icon_left, rect.x - 2, rect.y - 1, hover ? tic_color_grey : tic_color_dark_grey); 366 + drawBitIcon(sfx->studio, tic_icon_left, rect.x - 2, rect.y - 1, hover ? tic_color_grey : tic_color_dark_grey); 367 367 } 368 368 369 369 { 370 370 tic_rect rect = {x + 10, y + 27, ArrowWidth, ArrowHeight}; 371 371 bool hover = false; 372 372 373 - if(checkMousePos(&rect)) 373 + if(checkMousePos(sfx->studio, &rect)) 374 374 { 375 - setCursor(tic_cursor_hand); 375 + setCursor(sfx->studio, tic_cursor_hand); 376 376 hover = true; 377 377 378 - showTooltip(SetLoopPosLabel); 378 + showTooltip(sfx->studio, SetLoopPosLabel); 379 379 380 - if(checkMouseClick(&rect, tic_mouse_left)) 380 + if(checkMouseClick(sfx->studio, &rect, tic_mouse_left)) 381 381 { 382 382 effect->loops[canvasTab].start++; 383 383 history_add(sfx->history); 384 384 } 385 385 } 386 386 387 - drawBitIcon(tic_icon_right, rect.x - 2, rect.y - 1, hover ? tic_color_grey : tic_color_dark_grey); 387 + drawBitIcon(sfx->studio, tic_icon_right, rect.x - 2, rect.y - 1, hover ? tic_color_grey : tic_color_dark_grey); 388 388 } 389 389 390 390 { ··· 397 397 tic_rect rect = {x + 14, y + 27, ArrowWidth, ArrowHeight}; 398 398 bool hover = false; 399 399 400 - if(checkMousePos(&rect)) 400 + if(checkMousePos(sfx->studio, &rect)) 401 401 { 402 - setCursor(tic_cursor_hand); 402 + setCursor(sfx->studio, tic_cursor_hand); 403 403 hover = true; 404 - showTooltip(SetLoopSizeLabel); 404 + showTooltip(sfx->studio, SetLoopSizeLabel); 405 405 406 - if(checkMouseClick(&rect, tic_mouse_left)) 406 + if(checkMouseClick(sfx->studio, &rect, tic_mouse_left)) 407 407 { 408 408 effect->loops[canvasTab].size--; 409 409 history_add(sfx->history); 410 410 } 411 411 } 412 412 413 - drawBitIcon(tic_icon_left, rect.x - 2, rect.y - 1, hover ? tic_color_grey : tic_color_dark_grey); 413 + drawBitIcon(sfx->studio, tic_icon_left, rect.x - 2, rect.y - 1, hover ? tic_color_grey : tic_color_dark_grey); 414 414 } 415 415 416 416 { 417 417 tic_rect rect = {x + 22, y + 27, ArrowWidth, ArrowHeight}; 418 418 bool hover = false; 419 419 420 - if(checkMousePos(&rect)) 420 + if(checkMousePos(sfx->studio, &rect)) 421 421 { 422 - setCursor(tic_cursor_hand); 422 + setCursor(sfx->studio, tic_cursor_hand); 423 423 hover = true; 424 - showTooltip(SetLoopSizeLabel); 424 + showTooltip(sfx->studio, SetLoopSizeLabel); 425 425 426 - if(checkMouseClick(&rect, tic_mouse_left)) 426 + if(checkMouseClick(sfx->studio, &rect, tic_mouse_left)) 427 427 { 428 428 effect->loops[canvasTab].size++; 429 429 history_add(sfx->history); 430 430 } 431 431 } 432 432 433 - drawBitIcon(tic_icon_right, rect.x - 2, rect.y - 1, hover ? tic_color_grey : tic_color_dark_grey); 433 + drawBitIcon(sfx->studio, tic_icon_right, rect.x - 2, rect.y - 1, hover ? tic_color_grey : tic_color_dark_grey); 434 434 } 435 435 436 436 { ··· 555 555 tic_mem* tic = sfx->tic; 556 556 bool ctrl = tic_api_key(tic, tic_key_ctrl); 557 557 558 - switch(getClipboardEvent()) 558 + switch(getClipboardEvent(sfx->studio)) 559 559 { 560 560 case TIC_CLIPBOARD_CUT: cutToClipboard(sfx); break; 561 561 case TIC_CLIPBOARD_COPY: copyToClipboard(sfx); break; ··· 565 565 566 566 if(ctrl) 567 567 { 568 - if(keyWasPressed(tic_key_z)) undo(sfx); 569 - else if(keyWasPressed(tic_key_y)) redo(sfx); 568 + if(keyWasPressed(sfx->studio, tic_key_z)) undo(sfx); 569 + else if(keyWasPressed(sfx->studio, tic_key_y)) redo(sfx); 570 570 } 571 571 572 - else if(keyWasPressed(tic_key_left)) sfx->index--; 573 - else if(keyWasPressed(tic_key_right)) sfx->index++; 574 - else if(keyWasPressed(tic_key_delete)) resetSfx(sfx); 572 + else if(keyWasPressed(sfx->studio, tic_key_left)) sfx->index--; 573 + else if(keyWasPressed(sfx->studio, tic_key_right)) sfx->index++; 574 + else if(keyWasPressed(sfx->studio, tic_key_delete)) resetSfx(sfx); 575 575 } 576 576 577 577 static tic_waveform* getWave(Sfx* sfx) ··· 653 653 654 654 bool over = false; 655 655 s32 push = 0; 656 - if(checkMousePos(&rect)) 656 + if(checkMousePos(sfx->studio, &rect)) 657 657 { 658 658 over = true; 659 - setCursor(tic_cursor_hand); 659 + setCursor(sfx->studio, tic_cursor_hand); 660 660 661 - showTooltip(it->tip); 661 + showTooltip(sfx->studio, it->tip); 662 662 663 - if(checkMouseDown(&rect, tic_mouse_left)) 663 + if(checkMouseDown(sfx->studio, &rect, tic_mouse_left)) 664 664 push = 1; 665 665 666 - if(checkMouseClick(&rect, tic_mouse_left)) 666 + if(checkMouseClick(sfx->studio, &rect, tic_mouse_left)) 667 667 it->handler(sfx); 668 668 } 669 669 670 670 if(over) 671 - drawBitIcon(it->icon, rect.x, rect.y + 1, tic_color_black); 671 + drawBitIcon(sfx->studio, it->icon, rect.x, rect.y + 1, tic_color_black); 672 672 673 - drawBitIcon(it->icon, rect.x, rect.y + push, 673 + drawBitIcon(sfx->studio, it->icon, rect.x, rect.y + push, 674 674 over ? tic_color_white : tic_color_dark_grey); 675 675 676 676 y += Size; ··· 692 692 tic_sample* effect = getEffect(sfx); 693 693 bool hover = false; 694 694 695 - if(checkMousePos(&rect)) 695 + if(checkMousePos(sfx->studio, &rect)) 696 696 { 697 - setCursor(tic_cursor_hand); 697 + setCursor(sfx->studio, tic_cursor_hand); 698 698 699 699 hover = true; 700 700 701 - SHOW_TOOLTIP("select wave #%02i", i); 701 + SHOW_TOOLTIP(sfx->studio, "select wave #%02i", i); 702 702 703 - if(checkMouseClick(&rect, tic_mouse_left)) 703 + if(checkMouseClick(sfx->studio, &rect, tic_mouse_left)) 704 704 { 705 705 for(s32 c = 0; c < SFX_TICKS; c++) 706 706 effect->data[c].wave = i; ··· 779 779 } 780 780 else 781 781 { 782 - if(checkMousePos(&rect)) 782 + if(checkMousePos(sfx->studio, &rect)) 783 783 { 784 - setCursor(tic_cursor_hand); 784 + setCursor(sfx->studio, tic_cursor_hand); 785 785 786 786 s32 cx = (tic_api_mouse(tic).x - rect.x) / Scale; 787 787 s32 cy = MaxValue - (tic_api_mouse(tic).y - rect.y) / Scale; 788 788 789 - SHOW_TOOLTIP("[x=%02i y=%02i]", cx, cy); 789 + SHOW_TOOLTIP(sfx->studio, "[x=%02i y=%02i]", cx, cy); 790 790 791 791 enum {Border = 1}; 792 792 tic_api_rectb(tic, rect.x + cx*Scale - Border, 793 793 rect.y + (MaxValue - cy) * Scale - Border, Scale + Border*2, Scale + Border*2, tic_color_dark_green); 794 794 795 - if(checkMouseDown(&rect, tic_mouse_left)) 795 + if(checkMouseDown(sfx->studio, &rect, tic_mouse_left)) 796 796 { 797 797 if(tic_tool_peek4(wave->data, cx) != cy) 798 798 { ··· 858 858 859 859 s32 hover = -1; 860 860 861 - if(checkMousePos(&rect)) 861 + if(checkMousePos(sfx->studio, &rect)) 862 862 { 863 863 for(s32 i = COUNT_OF(Buttons)-1; i >= 0; i--) 864 864 { ··· 867 867 btnRect.x += x; 868 868 btnRect.y += y; 869 869 870 - if(checkMousePos(&btnRect)) 870 + if(checkMousePos(sfx->studio, &btnRect)) 871 871 { 872 - setCursor(tic_cursor_hand); 872 + setCursor(sfx->studio, tic_cursor_hand); 873 873 874 874 hover = btn->note; 875 875 876 876 { 877 877 static const char* Notes[] = SFX_NOTES; 878 - SHOW_TOOLTIP("play %s%i note", Notes[btn->note], octave + 1); 878 + SHOW_TOOLTIP(sfx->studio, "play %s%i note", Notes[btn->note], octave + 1); 879 879 } 880 880 881 - if(checkMouseDown(&rect, tic_mouse_left)) 881 + if(checkMouseDown(sfx->studio, &rect, tic_mouse_left)) 882 882 { 883 883 effect->note = btn->note; 884 884 effect->octave = octave; ··· 942 942 tic_sample* effect = getEffect(sfx); 943 943 s32 hover = -1; 944 944 945 - if(checkMousePos(&rect)) 945 + if(checkMousePos(sfx->studio, &rect)) 946 946 { 947 - setCursor(tic_cursor_hand); 947 + setCursor(sfx->studio, tic_cursor_hand); 948 948 949 949 s32 spd = (tic_api_mouse(tic).x - rect.x) / ColWidthGap; 950 950 hover = spd; 951 951 952 - SHOW_TOOLTIP("set speed to %i", spd); 952 + SHOW_TOOLTIP(sfx->studio, "set speed to %i", spd); 953 953 954 - if(checkMouseDown(&rect, tic_mouse_left)) 954 + if(checkMouseDown(sfx->studio, &rect, tic_mouse_left)) 955 955 { 956 956 effect->speed = spd - MaxSpeed; 957 957 history_add(sfx->history); ··· 979 979 tic_rect rect = {x, y, Width, Height}; 980 980 s32 hover = -1; 981 981 982 - if(checkMousePos(&rect)) 982 + if(checkMousePos(sfx->studio, &rect)) 983 983 for(s32 g = 0, i = 0; g < Groups; g++) 984 984 for(s32 r = 0; r < Rows; r++) 985 985 for(s32 c = 0; c < Cols; c++, i++) 986 986 { 987 987 tic_rect rect = {x + c * SizeGap + g * (GroupWidth + GroupGap), y + r * SizeGap, SizeGap, SizeGap}; 988 988 989 - if(checkMousePos(&rect)) 989 + if(checkMousePos(sfx->studio, &rect)) 990 990 { 991 - setCursor(tic_cursor_hand); 991 + setCursor(sfx->studio, tic_cursor_hand); 992 992 hover = i; 993 993 994 - SHOW_TOOLTIP("edit sfx #%02i", hover); 994 + SHOW_TOOLTIP(sfx->studio, "edit sfx #%02i", hover); 995 995 996 - if(checkMouseClick(&rect, tic_mouse_left)) 996 + if(checkMouseClick(sfx->studio, &rect, tic_mouse_left)) 997 997 sfx->index = i; 998 998 999 999 goto draw; ··· 1051 1051 drawSelector(sfx, 9, 12); 1052 1052 drawPiano(sfx, 5, 127); 1053 1053 drawWavePanel(sfx, 7, 41); 1054 - drawToolbar(tic, true); 1054 + drawToolbar(sfx->studio, tic, true); 1055 1055 1056 1056 playSound(sfx); 1057 1057 ··· 1074 1074 } 1075 1075 } 1076 1076 1077 - void initSfx(Sfx* sfx, tic_mem* tic, tic_sfx* src) 1077 + void initSfx(Sfx* sfx, Studio* studio, tic_sfx* src) 1078 1078 { 1079 1079 if(sfx->history) history_delete(sfx->history); 1080 1080 if(sfx->waveHistory) history_delete(sfx->waveHistory); 1081 1081 1082 1082 *sfx = (Sfx) 1083 1083 { 1084 - .tic = tic, 1084 + .studio = studio, 1085 + .tic = getMemory(studio), 1085 1086 .tick = tick, 1086 1087 .src = src, 1087 1088 .index = 0,
+2 -1
src/studio/editors/sfx.h
··· 28 28 29 29 struct Sfx 30 30 { 31 + Studio* studio; 31 32 tic_mem* tic; 32 33 33 34 tic_sfx* src; ··· 50 51 void(*event)(Sfx*, StudioEvent); 51 52 }; 52 53 53 - void initSfx(Sfx*, tic_mem*, tic_sfx* src); 54 + void initSfx(Sfx*, Studio* studio, tic_sfx* src); 54 55 void freeSfx(Sfx* sfx);
+186 -185
src/studio/editors/sprite.c
··· 145 145 tic_rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; 146 146 const s32 Size = CANVAS_SIZE / sprite->size; 147 147 148 - if(checkMousePos(&rect)) 148 + if(checkMousePos(sprite->studio, &rect)) 149 149 { 150 - setCursor(tic_cursor_hand); 150 + setCursor(sprite->studio, tic_cursor_hand); 151 151 152 152 s32 mx = tic_api_mouse(tic).x - x; 153 153 s32 my = tic_api_mouse(tic).y - y; ··· 157 157 158 158 drawCursorBorder(sprite, x + mx, y + my, Size, Size); 159 159 160 - if(checkMouseDown(&rect, tic_mouse_left)) 160 + if(checkMouseDown(sprite->studio, &rect, tic_mouse_left)) 161 161 sprite->color = tic_tilesheet_getpix(&sprite->sheet, sx + mx / Size, sy + my / Size); 162 162 163 - if(checkMouseDown(&rect, tic_mouse_right)) 163 + if(checkMouseDown(sprite->studio, &rect, tic_mouse_right)) 164 164 sprite->color2 = tic_tilesheet_getpix(&sprite->sheet, sx + mx / Size, sy + my / Size); 165 165 } 166 166 } ··· 171 171 tic_rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; 172 172 const s32 Size = CANVAS_SIZE / sprite->size; 173 173 174 - if(checkMousePos(&rect)) 174 + if(checkMousePos(sprite->studio, &rect)) 175 175 { 176 - setCursor(tic_cursor_hand); 176 + setCursor(sprite->studio, tic_cursor_hand); 177 177 178 178 s32 mx = tic_api_mouse(tic).x - x; 179 179 s32 my = tic_api_mouse(tic).y - y; ··· 191 191 if(mx+brushSize >= CANVAS_SIZE) mx = CANVAS_SIZE - brushSize; 192 192 if(my+brushSize >= CANVAS_SIZE) my = CANVAS_SIZE - brushSize; 193 193 194 - SHOW_TOOLTIP("[x=%02i y=%02i]", mx / Size, my / Size); 194 + SHOW_TOOLTIP(sprite->studio, "[x=%02i y=%02i]", mx / Size, my / Size); 195 195 196 196 drawCursorBorder(sprite, x + mx, y + my, brushSize, brushSize); 197 197 198 - bool left = checkMouseDown(&rect, tic_mouse_left); 199 - bool right = checkMouseDown(&rect, tic_mouse_right); 198 + bool left = checkMouseDown(sprite->studio, &rect, tic_mouse_left); 199 + bool right = checkMouseDown(sprite->studio, &rect, tic_mouse_right); 200 200 201 201 if(left || right) 202 202 { ··· 272 272 273 273 bool endDrag = false; 274 274 275 - if(checkMousePos(&rect)) 275 + if(checkMousePos(sprite->studio, &rect)) 276 276 { 277 - setCursor(tic_cursor_hand); 277 + setCursor(sprite->studio, tic_cursor_hand); 278 278 279 279 s32 mx = tic_api_mouse(tic).x - x; 280 280 s32 my = tic_api_mouse(tic).y - y; ··· 284 284 285 285 drawCursorBorder(sprite, x + mx, y + my, Size, Size); 286 286 287 - if(checkMouseDown(&rect, tic_mouse_left)) 287 + if(checkMouseDown(sprite->studio, &rect, tic_mouse_left)) 288 288 { 289 289 if(sprite->select.drag) 290 290 { ··· 343 343 tic_rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; 344 344 const s32 Size = CANVAS_SIZE / sprite->size; 345 345 346 - if(checkMousePos(&rect)) 346 + if(checkMousePos(sprite->studio, &rect)) 347 347 { 348 - setCursor(tic_cursor_hand); 348 + setCursor(sprite->studio, tic_cursor_hand); 349 349 350 350 s32 mx = tic_api_mouse(tic).x - x; 351 351 s32 my = tic_api_mouse(tic).y - y; ··· 355 355 356 356 drawCursorBorder(sprite, x + mx, y + my, Size, Size); 357 357 358 - bool left = checkMouseClick(&rect, tic_mouse_left); 359 - bool right = checkMouseClick(&rect, tic_mouse_right); 358 + bool left = checkMouseClick(sprite->studio, &rect, tic_mouse_left); 359 + bool right = checkMouseClick(sprite->studio, &rect, tic_mouse_right); 360 360 361 361 if(left || right) 362 362 { ··· 392 392 tic_rect rect = {x, y, Size, (Size+1)*Count}; 393 393 394 394 bool over = false; 395 - if(checkMousePos(&rect)) 395 + if(checkMousePos(sprite->studio, &rect)) 396 396 { 397 - setCursor(tic_cursor_hand); 397 + setCursor(sprite->studio, tic_cursor_hand); 398 398 399 - showTooltip("BRUSH SIZE"); 399 + showTooltip(sprite->studio, "BRUSH SIZE"); 400 400 over = true; 401 401 402 - if(checkMouseDown(&rect, tic_mouse_left)) 402 + if(checkMouseDown(sprite->studio, &rect, tic_mouse_left)) 403 403 { 404 404 s32 my = tic_api_mouse(tic).y - y; 405 405 ··· 432 432 const tic_rect rect = getSpriteRect(sprite); 433 433 434 434 const tic_rect canvasRect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; 435 - if(checkMouseDown(&canvasRect, tic_mouse_middle)) 435 + if(checkMouseDown(sprite->studio, &canvasRect, tic_mouse_middle)) 436 436 { 437 437 s32 mx = tic_api_mouse(tic).x - x; 438 438 s32 my = tic_api_mouse(tic).y - y; ··· 664 664 665 665 enum {Size = 5}; 666 666 667 - u8* flags = getBankFlags()->data; 667 + u8* flags = getBankFlags(sprite->studio)->data; 668 668 u8 or = 0; 669 669 u8 and = 0xff; 670 670 ··· 686 686 tic_rect rect = {x, y + (Size+1)*i, Size, Size}; 687 687 688 688 bool over = false; 689 - if(checkMousePos(&rect)) 689 + if(checkMousePos(sprite->studio, &rect)) 690 690 { 691 - setCursor(tic_cursor_hand); 691 + setCursor(sprite->studio, tic_cursor_hand); 692 692 over = true; 693 693 694 - SHOW_TOOLTIP("set flag [%i]", i); 694 + SHOW_TOOLTIP(sprite->studio, "set flag [%i]", i); 695 695 696 - if(checkMouseClick(&rect, tic_mouse_left)) 696 + if(checkMouseClick(sprite->studio, &rect, tic_mouse_left)) 697 697 { 698 698 const s32* i = indexes; 699 699 ··· 754 754 tic_rect rect = {centerX - SizeX / 2 + (i-1) * OffsetX, y, SizeX, SizeY}; 755 755 756 756 bool over = false; 757 - if(checkMousePos(&rect)) 757 + if(checkMousePos(sprite->studio, &rect)) 758 758 { 759 - setCursor(tic_cursor_hand); 759 + setCursor(sprite->studio, tic_cursor_hand); 760 760 over = true; 761 761 762 762 if(mode > 1) 763 - SHOW_TOOLTIP("%iBITS PER PIXEL", mode); 763 + SHOW_TOOLTIP(sprite->studio, "%iBITS PER PIXEL", mode); 764 764 else 765 - SHOW_TOOLTIP("%iBIT PER PIXEL", mode); 765 + SHOW_TOOLTIP(sprite->studio, "%iBIT PER PIXEL", mode); 766 766 767 - if(checkMouseClick(&rect, tic_mouse_left)) 767 + if(checkMouseClick(sprite->studio, &rect, tic_mouse_left)) 768 768 { 769 769 switchBitMode(sprite, mode); 770 770 } ··· 808 808 { 809 809 down = false; 810 810 811 - if(checkMousePos(&Rects[i])) 811 + if(checkMousePos(sprite->studio, &Rects[i])) 812 812 { 813 - setCursor(tic_cursor_hand); 813 + setCursor(sprite->studio, tic_cursor_hand); 814 814 815 - if(checkMouseDown(&Rects[i], tic_mouse_left)) down = true; 815 + if(checkMouseDown(sprite->studio, &Rects[i], tic_mouse_left)) down = true; 816 816 817 - if(checkMouseClick(&Rects[i], tic_mouse_left)) 817 + if(checkMouseClick(sprite->studio, &Rects[i], tic_mouse_left)) 818 818 Func[i](sprite); 819 819 } 820 820 821 - drawBitIcon(Icons[i], Rects[i].x, Rects[i].y+1, down ? tic_color_white : tic_color_black); 821 + drawBitIcon(sprite->studio, Icons[i], Rects[i].x, Rects[i].y+1, down ? tic_color_white : tic_color_black); 822 822 823 - if(!down) drawBitIcon(Icons[i], Rects[i].x, Rects[i].y, tic_color_white); 823 + if(!down) drawBitIcon(sprite->studio, Icons[i], Rects[i].x, Rects[i].y, tic_color_white); 824 824 } 825 825 } 826 826 } ··· 834 834 { 835 835 tic_rect rect = {x, y-2, Size, 5}; 836 836 837 - if(checkMousePos(&rect)) 837 + if(checkMousePos(sprite->studio, &rect)) 838 838 { 839 - setCursor(tic_cursor_hand); 839 + setCursor(sprite->studio, tic_cursor_hand); 840 840 841 - if(checkMouseDown(&rect, tic_mouse_left)) 841 + if(checkMouseDown(sprite->studio, &rect, tic_mouse_left)) 842 842 { 843 843 s32 mx = tic_api_mouse(tic).x - x; 844 844 *value = mx * Max / (Size-1); ··· 850 850 851 851 { 852 852 s32 offset = x + *value * (Size-1) / Max - 2; 853 - drawBitIcon(tic_icon_pos, offset, y-1, tic_color_black); 854 - drawBitIcon(tic_icon_pos, offset, y-2, tic_color_white); 853 + drawBitIcon(sprite->studio, tic_icon_pos, offset, y-1, tic_color_black); 854 + drawBitIcon(sprite->studio, tic_icon_pos, offset, y-2, tic_color_white); 855 855 } 856 856 } 857 857 ··· 859 859 tic_rect rect = {x - 4, y - 1, 2, 3}; 860 860 861 861 bool down = false; 862 - if(checkMousePos(&rect)) 862 + if(checkMousePos(sprite->studio, &rect)) 863 863 { 864 - setCursor(tic_cursor_hand); 864 + setCursor(sprite->studio, tic_cursor_hand); 865 865 866 - if(checkMouseDown(&rect, tic_mouse_left)) 866 + if(checkMouseDown(sprite->studio, &rect, tic_mouse_left)) 867 867 down = true; 868 868 869 - if(checkMouseClick(&rect, tic_mouse_left)) 869 + if(checkMouseClick(sprite->studio, &rect, tic_mouse_left)) 870 870 (*value)--; 871 871 } 872 872 873 873 if(down) 874 874 { 875 - drawBitIcon(tic_icon_tinyleft, rect.x-1, rect.y, tic_color_white); 875 + drawBitIcon(sprite->studio, tic_icon_tinyleft, rect.x-1, rect.y, tic_color_white); 876 876 } 877 877 else 878 878 { 879 - drawBitIcon(tic_icon_tinyleft, rect.x-1, rect.y, tic_color_black); 880 - drawBitIcon(tic_icon_tinyleft, rect.x-1, rect.y-1, tic_color_white); 879 + drawBitIcon(sprite->studio, tic_icon_tinyleft, rect.x-1, rect.y, tic_color_black); 880 + drawBitIcon(sprite->studio, tic_icon_tinyleft, rect.x-1, rect.y-1, tic_color_white); 881 881 } 882 882 } 883 883 ··· 885 885 tic_rect rect = {x + Size + 2, y - 1, 2, 3}; 886 886 887 887 bool down = false; 888 - if(checkMousePos(&rect)) 888 + if(checkMousePos(sprite->studio, &rect)) 889 889 { 890 - setCursor(tic_cursor_hand); 890 + setCursor(sprite->studio, tic_cursor_hand); 891 891 892 - if(checkMouseDown(&rect, tic_mouse_left)) 892 + if(checkMouseDown(sprite->studio, &rect, tic_mouse_left)) 893 893 down = true; 894 894 895 - if(checkMouseClick(&rect, tic_mouse_left)) 895 + if(checkMouseClick(sprite->studio, &rect, tic_mouse_left)) 896 896 (*value)++; 897 897 } 898 898 899 899 if(down) 900 900 { 901 - drawBitIcon(tic_icon_tinyright, rect.x-1, rect.y, tic_color_white); 901 + drawBitIcon(sprite->studio, tic_icon_tinyright, rect.x-1, rect.y, tic_color_white); 902 902 } 903 903 else 904 904 { 905 - drawBitIcon(tic_icon_tinyright, rect.x-1, rect.y, tic_color_black); 906 - drawBitIcon(tic_icon_tinyright, rect.x-1, rect.y-1, tic_color_white); 905 + drawBitIcon(sprite->studio, tic_icon_tinyright, rect.x-1, rect.y, tic_color_black); 906 + drawBitIcon(sprite->studio, tic_icon_tinyright, rect.x-1, rect.y-1, tic_color_white); 907 907 } 908 908 } 909 909 } ··· 911 911 static void pasteColor(Sprite* sprite) 912 912 { 913 913 bool ovr = sprite->palette.vbank1; 914 - if(!fromClipboard(&getBankPalette(ovr)->colors[sprite->color], sizeof(tic_rgb), false, true)) 915 - fromClipboard(getBankPalette(ovr)->data, sizeof(tic_palette), false, true); 914 + if(!fromClipboard(&getBankPalette(sprite->studio, ovr)->colors[sprite->color], sizeof(tic_rgb), false, true)) 915 + fromClipboard(getBankPalette(sprite->studio, ovr)->data, sizeof(tic_palette), false, true); 916 916 } 917 917 918 918 static void drawRGBTools(Sprite* sprite, s32 x, s32 y) ··· 925 925 bool over = false; 926 926 bool down = false; 927 927 928 - if(checkMousePos(&rect)) 928 + if(checkMousePos(sprite->studio, &rect)) 929 929 { 930 - setCursor(tic_cursor_hand); 930 + setCursor(sprite->studio, tic_cursor_hand); 931 931 932 - showTooltip("COPY PALETTE"); 932 + showTooltip(sprite->studio, "COPY PALETTE"); 933 933 over = true; 934 934 935 - if(checkMouseDown(&rect, tic_mouse_left)) 935 + if(checkMouseDown(sprite->studio, &rect, tic_mouse_left)) 936 936 down = true; 937 937 938 - if(checkMouseClick(&rect, tic_mouse_left)) 939 - toClipboard(getBankPalette(sprite->palette.vbank1)->data, sizeof(tic_palette), false); 938 + if(checkMouseClick(sprite->studio, &rect, tic_mouse_left)) 939 + toClipboard(getBankPalette(sprite->studio, sprite->palette.vbank1)->data, sizeof(tic_palette), false); 940 940 } 941 941 942 942 if(down) 943 943 { 944 - drawBitIcon(tic_icon_copy, rect.x-1, rect.y, tic_color_light_grey); 944 + drawBitIcon(sprite->studio, tic_icon_copy, rect.x-1, rect.y, tic_color_light_grey); 945 945 } 946 946 else 947 947 { 948 - drawBitIcon(tic_icon_copy, rect.x-1, rect.y, tic_color_black); 949 - drawBitIcon(tic_icon_copy, rect.x-1, rect.y-1, (over ? tic_color_light_grey : tic_color_white)); 948 + drawBitIcon(sprite->studio, tic_icon_copy, rect.x-1, rect.y, tic_color_black); 949 + drawBitIcon(sprite->studio, tic_icon_copy, rect.x-1, rect.y-1, (over ? tic_color_light_grey : tic_color_white)); 950 950 } 951 951 } 952 952 ··· 957 957 bool over = false; 958 958 bool down = false; 959 959 960 - if(checkMousePos(&rect)) 960 + if(checkMousePos(sprite->studio, &rect)) 961 961 { 962 - setCursor(tic_cursor_hand); 962 + setCursor(sprite->studio, tic_cursor_hand); 963 963 964 - showTooltip("PASTE PALETTE"); 964 + showTooltip(sprite->studio, "PASTE PALETTE"); 965 965 over = true; 966 966 967 - if(checkMouseDown(&rect, tic_mouse_left)) 967 + if(checkMouseDown(sprite->studio, &rect, tic_mouse_left)) 968 968 down = true; 969 969 970 - if(checkMouseClick(&rect, tic_mouse_left)) 970 + if(checkMouseClick(sprite->studio, &rect, tic_mouse_left)) 971 971 { 972 972 pasteColor(sprite); 973 973 } ··· 975 975 976 976 if(down) 977 977 { 978 - drawBitIcon(tic_icon_paste, rect.x-1, rect.y, tic_color_light_grey); 978 + drawBitIcon(sprite->studio, tic_icon_paste, rect.x-1, rect.y, tic_color_light_grey); 979 979 } 980 980 else 981 981 { 982 - drawBitIcon(tic_icon_paste, rect.x-1, rect.y, tic_color_black); 983 - drawBitIcon(tic_icon_paste, rect.x-1, rect.y-1, (over ? tic_color_light_grey : tic_color_white)); 982 + drawBitIcon(sprite->studio, tic_icon_paste, rect.x-1, rect.y, tic_color_black); 983 + drawBitIcon(sprite->studio, tic_icon_paste, rect.x-1, rect.y-1, (over ? tic_color_light_grey : tic_color_white)); 984 984 } 985 985 } 986 986 } ··· 997 997 Height = TIC_FONT_HEIGHT + 1 998 998 }; 999 999 1000 - u8* data = &getBankPalette(sprite->palette.vbank1)->data[sprite->color * Rows]; 1000 + u8* data = &getBankPalette(sprite->studio, sprite->palette.vbank1)->data[sprite->color * Rows]; 1001 1001 1002 1002 { 1003 1003 tic_rect rect = {x - 20, y - 3, TIC_FONT_WIDTH * Cols + 1, TIC_FONT_HEIGHT * Rows + 1}; 1004 1004 1005 - if(checkMousePos(&rect)) 1005 + if(checkMousePos(sprite->studio, &rect)) 1006 1006 { 1007 - setCursor(tic_cursor_hand); 1007 + setCursor(sprite->studio, tic_cursor_hand); 1008 1008 1009 - if(checkMouseDown(&rect, tic_mouse_left)) 1009 + if(checkMouseDown(sprite->studio, &rect, tic_mouse_left)) 1010 1010 { 1011 1011 s32 mx = tic_api_mouse(tic).x - rect.x; 1012 1012 s32 my = tic_api_mouse(tic).y - rect.y; ··· 1072 1072 tic_rect rect = {x, y, PALETTE_WIDTH-1, PALETTE_HEIGHT-1}; 1073 1073 tic_palette_dimensions palette = getPaletteDimensions(sprite); 1074 1074 1075 - if(checkMousePos(&rect)) 1075 + if(checkMousePos(sprite->studio, &rect)) 1076 1076 { 1077 - setCursor(tic_cursor_hand); 1077 + setCursor(sprite->studio, tic_cursor_hand); 1078 1078 1079 1079 s32 mx = tic_api_mouse(tic).x - x; 1080 1080 s32 my = tic_api_mouse(tic).y - y; ··· 1084 1084 1085 1085 s32 index = mx + my * palette.cols; 1086 1086 1087 - SHOW_TOOLTIP("color [%02i]", index); 1087 + SHOW_TOOLTIP(sprite->studio, "color [%02i]", index); 1088 1088 1089 - bool left = checkMouseDown(&rect, tic_mouse_left); 1090 - bool right = checkMouseDown(&rect, tic_mouse_right); 1089 + bool left = checkMouseDown(sprite->studio, &rect, tic_mouse_left); 1090 + bool right = checkMouseDown(sprite->studio, &rect, tic_mouse_right); 1091 1091 1092 1092 if(left || right) 1093 1093 { ··· 1134 1134 1135 1135 bool down = false; 1136 1136 bool over = false; 1137 - if(checkMousePos(&rect)) 1137 + if(checkMousePos(sprite->studio, &rect)) 1138 1138 { 1139 - setCursor(tic_cursor_hand); 1139 + setCursor(sprite->studio, tic_cursor_hand); 1140 1140 over = true; 1141 1141 1142 - showTooltip("VBANK0 PALETTE"); 1142 + showTooltip(sprite->studio, "VBANK0 PALETTE"); 1143 1143 1144 - if(checkMouseDown(&rect, tic_mouse_left)) 1144 + if(checkMouseDown(sprite->studio, &rect, tic_mouse_left)) 1145 1145 down = true; 1146 1146 1147 - if(checkMouseClick(&rect, tic_mouse_left)) 1147 + if(checkMouseClick(sprite->studio, &rect, tic_mouse_left)) 1148 1148 sprite->palette.vbank1 = false; 1149 1149 } 1150 1150 ··· 1163 1163 1164 1164 bool down = false; 1165 1165 bool over = false; 1166 - if(checkMousePos(&rect)) 1166 + if(checkMousePos(sprite->studio, &rect)) 1167 1167 { 1168 - setCursor(tic_cursor_hand); 1168 + setCursor(sprite->studio, tic_cursor_hand); 1169 1169 over = true; 1170 1170 1171 - showTooltip("VBANK1 PALETTE"); 1171 + showTooltip(sprite->studio, "VBANK1 PALETTE"); 1172 1172 1173 - if(checkMouseDown(&rect, tic_mouse_left)) 1173 + if(checkMouseDown(sprite->studio, &rect, tic_mouse_left)) 1174 1174 down = true; 1175 1175 1176 - if(checkMouseClick(&rect, tic_mouse_left)) 1176 + if(checkMouseClick(sprite->studio, &rect, tic_mouse_left)) 1177 1177 sprite->palette.vbank1 = true; 1178 1178 } 1179 1179 ··· 1192 1192 1193 1193 bool down = false; 1194 1194 bool over = false; 1195 - if(checkMousePos(&rect)) 1195 + if(checkMousePos(sprite->studio, &rect)) 1196 1196 { 1197 - setCursor(tic_cursor_hand); 1197 + setCursor(sprite->studio, tic_cursor_hand); 1198 1198 over = true; 1199 1199 1200 - showTooltip("EDIT PALETTE"); 1200 + showTooltip(sprite->studio, "EDIT PALETTE"); 1201 1201 1202 - if(checkMouseDown(&rect, tic_mouse_left)) 1202 + if(checkMouseDown(sprite->studio, &rect, tic_mouse_left)) 1203 1203 down = true; 1204 1204 1205 - if(checkMouseClick(&rect, tic_mouse_left)) 1205 + if(checkMouseClick(sprite->studio, &rect, tic_mouse_left)) 1206 1206 { 1207 1207 sprite->palette.edit = !sprite->palette.edit; 1208 1208 ··· 1213 1213 1214 1214 if(sprite->palette.edit || down) 1215 1215 { 1216 - drawBitIcon(tic_icon_rgb, rect.x, rect.y+1, (over ? tic_color_light_grey : tic_color_white)); 1216 + drawBitIcon(sprite->studio, tic_icon_rgb, rect.x, rect.y+1, (over ? tic_color_light_grey : tic_color_white)); 1217 1217 } 1218 1218 else 1219 1219 { 1220 - drawBitIcon(tic_icon_rgb, rect.x, rect.y+1, tic_color_black); 1221 - drawBitIcon(tic_icon_rgb, rect.x, rect.y, (over ? tic_color_light_grey : tic_color_white)); 1220 + drawBitIcon(sprite->studio, tic_icon_rgb, rect.x, rect.y+1, tic_color_black); 1221 + drawBitIcon(sprite->studio, tic_icon_rgb, rect.x, rect.y, (over ? tic_color_light_grey : tic_color_white)); 1222 1222 } 1223 1223 } 1224 1224 } ··· 1279 1279 } 1280 1280 } 1281 1281 1282 - if(checkMousePos(&rect)) 1282 + if(checkMousePos(sprite->studio, &rect)) 1283 1283 { 1284 - setCursor(tic_cursor_hand); 1284 + setCursor(sprite->studio, tic_cursor_hand); 1285 1285 1286 - if(checkMouseDown(&rect, tic_mouse_left)) 1286 + if(checkMouseDown(sprite->studio, &rect, tic_mouse_left)) 1287 1287 { 1288 1288 s32 offset = (sprite->size - TIC_SPRITESIZE) / 2; 1289 1289 selectSprite(sprite, tic_api_mouse(tic).x - x - offset, tic_api_mouse(tic).y - y - offset); ··· 1414 1414 1415 1415 tic_rect rect = {x + i * Gap, y, TIC_SPRITESIZE, TIC_SPRITESIZE}; 1416 1416 1417 - if(checkMousePos(&rect)) 1417 + if(checkMousePos(sprite->studio, &rect)) 1418 1418 { 1419 - setCursor(tic_cursor_hand); 1419 + setCursor(sprite->studio, tic_cursor_hand); 1420 1420 1421 1421 over = true; 1422 1422 1423 - showTooltip(Tooltips[i]); 1423 + showTooltip(sprite->studio, Tooltips[i]); 1424 1424 1425 - if(checkMouseDown(&rect, tic_mouse_left)) pushed = true; 1425 + if(checkMouseDown(sprite->studio, &rect, tic_mouse_left)) pushed = true; 1426 1426 1427 - if(checkMouseClick(&rect, tic_mouse_left)) 1427 + if(checkMouseClick(sprite->studio, &rect, tic_mouse_left)) 1428 1428 { 1429 1429 if(hasCanvasSelection(sprite)) 1430 1430 { ··· 1440 1440 1441 1441 if(pushed) 1442 1442 { 1443 - drawBitIcon(Icons[i], rect.x, y + 1, (over ? tic_color_light_grey : tic_color_white)); 1443 + drawBitIcon(sprite->studio, Icons[i], rect.x, y + 1, (over ? tic_color_light_grey : tic_color_white)); 1444 1444 } 1445 1445 else 1446 1446 { 1447 - drawBitIcon(Icons[i], rect.x, y+1, tic_color_black); 1448 - drawBitIcon(Icons[i], rect.x, y, (over ? tic_color_light_grey : tic_color_white)); 1447 + drawBitIcon(sprite->studio, Icons[i], rect.x, y+1, tic_color_black); 1448 + drawBitIcon(sprite->studio, Icons[i], rect.x, y, (over ? tic_color_light_grey : tic_color_white)); 1449 1449 } 1450 1450 } 1451 1451 } ··· 1461 1461 tic_rect rect = {x + i * Gap, y, TIC_SPRITESIZE, TIC_SPRITESIZE}; 1462 1462 1463 1463 bool over = false; 1464 - if(checkMousePos(&rect)) 1464 + if(checkMousePos(sprite->studio, &rect)) 1465 1465 { 1466 - setCursor(tic_cursor_hand); 1466 + setCursor(sprite->studio, tic_cursor_hand); 1467 1467 over = true; 1468 1468 1469 1469 static const char* Tooltips[] = {"BRUSH [1]", "COLOR PICKER [2]", "SELECT [3]", "FILL [4]"}; 1470 1470 1471 - showTooltip(Tooltips[i]); 1471 + showTooltip(sprite->studio, Tooltips[i]); 1472 1472 1473 - if(checkMouseClick(&rect, tic_mouse_left)) 1473 + if(checkMouseClick(sprite->studio, &rect, tic_mouse_left)) 1474 1474 { 1475 1475 sprite->mode = i; 1476 1476 ··· 1482 1482 1483 1483 if(pushed) 1484 1484 { 1485 - drawBitIcon(tic_icon_down, rect.x, y - 5, tic_color_black); 1486 - drawBitIcon(tic_icon_down, rect.x, y - 6, tic_color_white); 1485 + drawBitIcon(sprite->studio, tic_icon_down, rect.x, y - 5, tic_color_black); 1486 + drawBitIcon(sprite->studio, tic_icon_down, rect.x, y - 6, tic_color_white); 1487 1487 1488 - drawBitIcon(Icons[i], rect.x, y + 1, (over ? tic_color_light_grey : tic_color_white)); 1488 + drawBitIcon(sprite->studio, Icons[i], rect.x, y + 1, (over ? tic_color_light_grey : tic_color_white)); 1489 1489 } 1490 1490 else 1491 1491 { 1492 - drawBitIcon(Icons[i], rect.x, y+1, tic_color_black); 1493 - drawBitIcon(Icons[i], rect.x, y, (over ? tic_color_light_grey : tic_color_white)); 1492 + drawBitIcon(sprite->studio, Icons[i], rect.x, y+1, tic_color_black); 1493 + drawBitIcon(sprite->studio, Icons[i], rect.x, y, (over ? tic_color_light_grey : tic_color_white)); 1494 1494 } 1495 1495 } 1496 1496 ··· 1594 1594 } 1595 1595 } 1596 1596 1597 - static void drawTab(tic_mem* tic, s32 x, s32 y, s32 w, s32 h, u8 icon, bool active, bool over) 1597 + static void drawTab(Sprite* sprite, s32 x, s32 y, s32 w, s32 h, u8 icon, bool active, bool over) 1598 1598 { 1599 1599 tic_color tab_color = active ? tic_color_white : over ? tic_color_light_grey : tic_color_dark_grey; 1600 1600 tic_color label_color = active ? tic_color_dark_grey : tic_color_grey; 1601 1601 1602 - tic_api_rect(tic, x+1, y, w-1, h, tab_color); 1603 - tic_api_line(tic, x, y+1, x, y+h-2, tab_color); 1602 + tic_api_rect(sprite->tic, x+1, y, w-1, h, tab_color); 1603 + tic_api_line(sprite->tic, x, y+1, x, y+h-2, tab_color); 1604 1604 1605 1605 if (active) 1606 1606 { 1607 - tic_api_line(tic, x+1, y + h, x + w-1, y + h, tic_color_black); 1608 - tic_api_pix(tic, x, y-1 + h, label_color, false); 1607 + tic_api_line(sprite->tic, x+1, y + h, x + w-1, y + h, tic_color_black); 1608 + tic_api_pix(sprite->tic, x, y-1 + h, label_color, false); 1609 1609 } 1610 1610 1611 - drawBitIcon(icon, x + 1, y, label_color); 1611 + drawBitIcon(sprite->studio, icon, x + 1, y, label_color); 1612 1612 } 1613 1613 1614 1614 static void drawBankTabs(Sprite* sprite, s32 x, s32 y) ··· 1629 1629 tic_rect rect = {x - SizeX, y + (SizeY + 1) * i, SizeX, SizeY}; 1630 1630 1631 1631 bool over = false; 1632 - if(checkMousePos(&rect)) 1632 + if(checkMousePos(sprite->studio, &rect)) 1633 1633 { 1634 - setCursor(tic_cursor_hand); 1634 + setCursor(sprite->studio, tic_cursor_hand); 1635 1635 over = true; 1636 1636 1637 - showTooltip(tooltips[i]); 1637 + showTooltip(sprite->studio, tooltips[i]); 1638 1638 1639 - if(checkMouseClick(&rect, tic_mouse_left)) 1639 + if(checkMouseClick(sprite->studio, &rect, tic_mouse_left)) 1640 1640 { 1641 1641 if (!current) 1642 1642 { ··· 1645 1645 } 1646 1646 } 1647 1647 1648 - drawTab(tic, rect.x, rect.y, SizeX, SizeY, Icons[i], current, over); 1648 + drawTab(sprite, rect.x, rect.y, SizeX, SizeY, Icons[i], current, over); 1649 1649 } 1650 1650 } 1651 1651 ··· 1666 1666 1667 1667 if(tic->ram.input.keyboard.data == 0) return; 1668 1668 1669 - switch(getClipboardEvent()) 1669 + switch(getClipboardEvent(sprite->studio)) 1670 1670 { 1671 1671 case TIC_CLIPBOARD_CUT: cutToClipboard(sprite); break; 1672 1672 case TIC_CLIPBOARD_COPY: copyToClipboard(sprite); break; ··· 1685 1685 s32 col = sprite->palette.focus % Cols; 1686 1686 s32 row = sprite->palette.focus / Cols; 1687 1687 1688 - if(keyWasPressed(tic_key_up)) --row; 1689 - else if(keyWasPressed(tic_key_down)) ++row; 1690 - else if(keyWasPressed(tic_key_left)) --col; 1691 - else if(keyWasPressed(tic_key_right)) ++col; 1688 + if(keyWasPressed(sprite->studio, tic_key_up)) --row; 1689 + else if(keyWasPressed(sprite->studio, tic_key_down)) ++row; 1690 + else if(keyWasPressed(sprite->studio, tic_key_left)) --col; 1691 + else if(keyWasPressed(sprite->studio, tic_key_right)) ++col; 1692 1692 else 1693 1693 { 1694 - char sym = getKeyboardText(); 1694 + char sym = getKeyboardText(sprite->studio); 1695 1695 1696 1696 if(isxdigit(sym)) 1697 1697 { 1698 - u8* data = &getBankPalette(sprite->palette.vbank1)->data[sprite->color * Rows + row]; 1698 + u8* data = &getBankPalette(sprite->studio, sprite->palette.vbank1)->data[sprite->color * Rows + row]; 1699 1699 char buf[sizeof "FF"]; 1700 1700 sprintf(buf, "%02X", *data); 1701 1701 buf[col] = toupper(sym); ··· 1713 1713 1714 1714 if(ctrl) 1715 1715 { 1716 - if(keyWasPressed(tic_key_z)) undo(sprite); 1717 - else if(keyWasPressed(tic_key_y)) redo(sprite); 1716 + if(keyWasPressed(sprite->studio, tic_key_z)) undo(sprite); 1717 + else if(keyWasPressed(sprite->studio, tic_key_y)) redo(sprite); 1718 1718 1719 - else if(keyWasPressed(tic_key_left)) leftViewport(sprite); 1720 - else if(keyWasPressed(tic_key_right)) rightViewport(sprite); 1719 + else if(keyWasPressed(sprite->studio, tic_key_left)) leftViewport(sprite); 1720 + else if(keyWasPressed(sprite->studio, tic_key_right)) rightViewport(sprite); 1721 1721 1722 - else if(keyWasPressed(tic_key_tab)) 1722 + else if(keyWasPressed(sprite->studio, tic_key_tab)) 1723 1723 switchBitMode(sprite, sprite->blit.mode == tic_bpp_4 1724 1724 ? tic_bpp_2 1725 1725 : sprite->blit.mode == tic_bpp_2 ··· 1732 1732 { 1733 1733 if(!sprite->select.drag) 1734 1734 { 1735 - if(keyWasPressed(tic_key_up)) upCanvas(sprite); 1736 - else if(keyWasPressed(tic_key_down)) downCanvas(sprite); 1737 - else if(keyWasPressed(tic_key_left)) leftCanvas(sprite); 1738 - else if(keyWasPressed(tic_key_right)) rightCanvas(sprite); 1739 - else if(keyWasPressed(tic_key_delete)) deleteCanvas(sprite); 1735 + if(keyWasPressed(sprite->studio, tic_key_up)) upCanvas(sprite); 1736 + else if(keyWasPressed(sprite->studio, tic_key_down)) downCanvas(sprite); 1737 + else if(keyWasPressed(sprite->studio, tic_key_left)) leftCanvas(sprite); 1738 + else if(keyWasPressed(sprite->studio, tic_key_right)) rightCanvas(sprite); 1739 + else if(keyWasPressed(sprite->studio, tic_key_delete)) deleteCanvas(sprite); 1740 1740 } 1741 1741 } 1742 1742 else 1743 1743 { 1744 - if(keyWasPressed(tic_key_up)) upSprite(sprite); 1745 - else if(keyWasPressed(tic_key_down)) downSprite(sprite); 1746 - else if(keyWasPressed(tic_key_left)) leftSprite(sprite); 1747 - else if(keyWasPressed(tic_key_right)) rightSprite(sprite); 1748 - else if(keyWasPressed(tic_key_delete)) deleteSprite(sprite); 1749 - else if(keyWasPressed(tic_key_tab)) switchBanks(sprite); 1744 + if(keyWasPressed(sprite->studio, tic_key_up)) upSprite(sprite); 1745 + else if(keyWasPressed(sprite->studio, tic_key_down)) downSprite(sprite); 1746 + else if(keyWasPressed(sprite->studio, tic_key_left)) leftSprite(sprite); 1747 + else if(keyWasPressed(sprite->studio, tic_key_right)) rightSprite(sprite); 1748 + else if(keyWasPressed(sprite->studio, tic_key_delete)) deleteSprite(sprite); 1749 + else if(keyWasPressed(sprite->studio, tic_key_tab)) switchBanks(sprite); 1750 1750 1751 1751 if(!sprite->palette.edit) 1752 1752 { 1753 1753 1754 - if(keyWasPressed(tic_key_1)) sprite->mode = SPRITE_DRAW_MODE; 1755 - else if(keyWasPressed(tic_key_2)) sprite->mode = SPRITE_PICK_MODE; 1756 - else if(keyWasPressed(tic_key_3)) sprite->mode = SPRITE_SELECT_MODE; 1757 - else if(keyWasPressed(tic_key_4)) sprite->mode = SPRITE_FILL_MODE; 1754 + if(keyWasPressed(sprite->studio, tic_key_1)) sprite->mode = SPRITE_DRAW_MODE; 1755 + else if(keyWasPressed(sprite->studio, tic_key_2)) sprite->mode = SPRITE_PICK_MODE; 1756 + else if(keyWasPressed(sprite->studio, tic_key_3)) sprite->mode = SPRITE_SELECT_MODE; 1757 + else if(keyWasPressed(sprite->studio, tic_key_4)) sprite->mode = SPRITE_FILL_MODE; 1758 1758 1759 - else if(keyWasPressed(tic_key_5)) flipSpriteHorz(sprite); 1760 - else if(keyWasPressed(tic_key_6)) flipSpriteVert(sprite); 1761 - else if(keyWasPressed(tic_key_7)) rotateSprite(sprite); 1762 - else if(keyWasPressed(tic_key_8)) deleteSprite(sprite); 1759 + else if(keyWasPressed(sprite->studio, tic_key_5)) flipSpriteHorz(sprite); 1760 + else if(keyWasPressed(sprite->studio, tic_key_6)) flipSpriteVert(sprite); 1761 + else if(keyWasPressed(sprite->studio, tic_key_7)) rotateSprite(sprite); 1762 + else if(keyWasPressed(sprite->studio, tic_key_8)) deleteSprite(sprite); 1763 1763 1764 1764 if(sprite->mode == SPRITE_DRAW_MODE) 1765 1765 { 1766 - if(keyWasPressed(tic_key_minus)) updateBrushSize(sprite, -1); 1767 - else if(keyWasPressed(tic_key_equals)) updateBrushSize(sprite, +1); 1768 - else if(keyWasPressed(tic_key_leftbracket)) updateColorIndex(sprite, -1); 1769 - else if(keyWasPressed(tic_key_rightbracket)) updateColorIndex(sprite, +1); 1766 + if(keyWasPressed(sprite->studio, tic_key_minus)) updateBrushSize(sprite, -1); 1767 + else if(keyWasPressed(sprite->studio, tic_key_equals)) updateBrushSize(sprite, +1); 1768 + else if(keyWasPressed(sprite->studio, tic_key_leftbracket)) updateColorIndex(sprite, -1); 1769 + else if(keyWasPressed(sprite->studio, tic_key_rightbracket)) updateColorIndex(sprite, +1); 1770 1770 } 1771 1771 } 1772 1772 } ··· 1785 1785 { 1786 1786 tic_rect rect = {TIC80_WIDTH - 58, 1, 23, 5}; 1787 1787 1788 - if(checkMousePos(&rect)) 1788 + if(checkMousePos(sprite->studio, &rect)) 1789 1789 { 1790 - setCursor(tic_cursor_hand); 1790 + setCursor(sprite->studio, tic_cursor_hand); 1791 1791 1792 - showTooltip("CANVAS ZOOM"); 1792 + showTooltip(sprite->studio, "CANVAS ZOOM"); 1793 1793 1794 - if(checkMouseDown(&rect, tic_mouse_left)) 1794 + if(checkMouseDown(sprite->studio, &rect, tic_mouse_left)) 1795 1795 { 1796 1796 s32 mx = tic_api_mouse(tic).x - rect.x; 1797 1797 mx /= 6; ··· 1829 1829 tic_rect rect = {TIC80_WIDTH - 1 - 7*(nbPages-page), 0, 7, TOOLBAR_SIZE}; 1830 1830 1831 1831 bool over = false; 1832 - if(checkMousePos(&rect)) 1832 + if(checkMousePos(sprite->studio, &rect)) 1833 1833 { 1834 - setCursor(tic_cursor_hand); 1834 + setCursor(sprite->studio, tic_cursor_hand); 1835 1835 over = true; 1836 1836 1837 - SHOW_TOOLTIP("PAGE %i", page + 1); 1837 + SHOW_TOOLTIP(sprite->studio, "PAGE %i", page + 1); 1838 1838 1839 - if(checkMouseClick(&rect, tic_mouse_left)) 1839 + if(checkMouseClick(sprite->studio, &rect, tic_mouse_left)) 1840 1840 { 1841 1841 selectViewportPage(sprite, page); 1842 1842 } ··· 1854 1854 Sprite* sprite = (Sprite*)data; 1855 1855 1856 1856 if(row == 0) 1857 - memcpy(&tic->ram.vram.palette, getBankPalette(sprite->palette.vbank1), sizeof(tic_palette)); 1857 + memcpy(&tic->ram.vram.palette, getBankPalette(sprite->studio, sprite->palette.vbank1), sizeof(tic_palette)); 1858 1858 } 1859 1859 1860 1860 static void drawAdvancedButton(Sprite* sprite, s32 x, s32 y) ··· 1864 1864 tic_rect rect = {x, y, 8, 5}; 1865 1865 1866 1866 bool over = false; 1867 - if(checkMousePos(&rect)) 1867 + if(checkMousePos(sprite->studio, &rect)) 1868 1868 { 1869 - setCursor(tic_cursor_hand); 1869 + setCursor(sprite->studio, tic_cursor_hand); 1870 1870 over = true; 1871 - showTooltip("ADVANCED MODE"); 1871 + showTooltip(sprite->studio, "ADVANCED MODE"); 1872 1872 1873 - if(checkMouseClick(&rect, tic_mouse_left)) 1873 + if(checkMouseClick(sprite->studio, &rect, tic_mouse_left)) 1874 1874 sprite->advanced = !sprite->advanced; 1875 1875 1876 1876 if(!sprite->advanced) ··· 1935 1935 {0, PaletteY + PaletteH, SheetX, TIC80_HEIGHT - PaletteY - PaletteH}, 1936 1936 }; 1937 1937 1938 - memcpy(tic->ram.vram.palette.data, getConfig()->cart->bank0.palette.vbank0.data, sizeof(tic_palette)); 1938 + memcpy(tic->ram.vram.palette.data, getConfig(sprite->studio)->cart->bank0.palette.vbank0.data, sizeof(tic_palette)); 1939 1939 1940 1940 for(const tic_rect* r = bg; r < bg + COUNT_OF(bg); r++) 1941 1941 tic_api_rect(tic, r->x, r->y, r->w, r->h, tic_color_grey); ··· 1962 1962 drawAdvancedButton(sprite, 4, 11); 1963 1963 1964 1964 drawSpriteToolbar(sprite); 1965 - drawToolbar(tic, false); 1965 + drawToolbar(sprite->studio, tic, false); 1966 1966 } 1967 1967 1968 1968 sprite->tickCounter++; ··· 1994 1994 FREE(sprite->anim.page.items); 1995 1995 } 1996 1996 1997 - void initSprite(Sprite* sprite, tic_mem* tic, tic_tiles* src) 1997 + void initSprite(Sprite* sprite, Studio* studio, tic_tiles* src) 1998 1998 { 1999 1999 if(sprite->select.back == NULL) sprite->select.back = (u8*)malloc(CANVAS_SIZE*CANVAS_SIZE); 2000 2000 if(sprite->select.front == NULL) sprite->select.front = (u8*)malloc(CANVAS_SIZE*CANVAS_SIZE); ··· 2003 2003 2004 2004 *sprite = (Sprite) 2005 2005 { 2006 - .tic = tic, 2006 + .studio = studio, 2007 + .tic = getMemory(studio), 2007 2008 .tick = tick, 2008 2009 .tickCounter = 0, 2009 2010 .src = src,
+2 -1
src/studio/editors/sprite.h
··· 29 29 30 30 struct Sprite 31 31 { 32 + Studio* studio; 32 33 tic_mem* tic; 33 34 34 35 tic_tiles* src; ··· 98 99 s32 cell_w, cell_h, cols, rows, length; 99 100 } tic_palette_dimensions; 100 101 101 - void initSprite(Sprite*, tic_mem*, tic_tiles* src); 102 + void initSprite(Sprite*, Studio* studio, tic_tiles* src); 102 103 void freeSprite(Sprite*); 103 104
+15 -13
src/studio/editors/world.c
··· 41 41 42 42 tic_rect rect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT}; 43 43 44 - if(checkMousePos(&rect)) 44 + if(checkMousePos(world->studio, &rect)) 45 45 { 46 - setCursor(tic_cursor_hand); 46 + setCursor(world->studio, tic_cursor_hand); 47 47 48 48 s32 mx = tic_api_mouse(tic).x; 49 49 s32 my = tic_api_mouse(tic).y; 50 50 51 - if(checkMouseDown(&rect, tic_mouse_left)) 51 + if(checkMouseDown(world->studio, &rect, tic_mouse_left)) 52 52 { 53 53 map->scroll.x = (mx - TIC_MAP_SCREEN_WIDTH/2) * TIC_SPRITESIZE; 54 54 map->scroll.y = (my - TIC_MAP_SCREEN_HEIGHT/2) * TIC_SPRITESIZE; ··· 58 58 map->scroll.y += TIC_MAP_HEIGHT * TIC_SPRITESIZE; 59 59 } 60 60 61 - if(checkMouseClick(&rect, tic_mouse_left)) 62 - setStudioMode(TIC_MAP_MODE); 61 + if(checkMouseClick(world->studio, &rect, tic_mouse_left)) 62 + setStudioMode(world->studio, TIC_MAP_MODE); 63 63 } 64 64 65 65 s32 x = map->scroll.x / TIC_SPRITESIZE; ··· 84 84 // process scroll 85 85 if(tic->ram.input.mouse.scrolly < 0) 86 86 { 87 - setStudioMode(TIC_MAP_MODE); 87 + setStudioMode(world->studio, TIC_MAP_MODE); 88 88 return; 89 89 } 90 90 91 - if(keyWasPressed(tic_key_tab)) setStudioMode(TIC_MAP_MODE); 91 + if(keyWasPressed(world->studio, tic_key_tab)) setStudioMode(world->studio, TIC_MAP_MODE); 92 92 93 93 memcpy(&tic->ram.vram, world->preview, PREVIEW_SIZE); 94 94 95 95 VBANK(tic, 1) 96 96 { 97 97 tic_api_cls(tic, tic->ram.vram.vars.clear = tic_color_black); 98 - memcpy(tic->ram.vram.palette.data, getConfig()->cart->bank0.palette.vbank0.data, sizeof(tic_palette)); 98 + memcpy(tic->ram.vram.palette.data, getConfig(world->studio)->cart->bank0.palette.vbank0.data, sizeof(tic_palette)); 99 99 drawGrid(world); 100 100 } 101 101 } 102 102 103 103 static void scanline(tic_mem* tic, s32 row, void* data) 104 104 { 105 + World* world = data; 105 106 if(row == 0) 106 - memcpy(&tic->ram.vram.palette, getBankPalette(false), sizeof(tic_palette)); 107 + memcpy(&tic->ram.vram.palette, getBankPalette(world->studio, false), sizeof(tic_palette)); 107 108 } 108 109 109 - void initWorld(World* world, tic_mem* tic, Map* map) 110 + void initWorld(World* world, Studio* studio, Map* map) 110 111 { 111 112 if(!world->preview) 112 113 world->preview = malloc(PREVIEW_SIZE); 113 114 114 115 *world = (World) 115 116 { 116 - .tic = tic, 117 + .studio = studio, 118 + .tic = getMemory(studio), 117 119 .map = map, 118 120 .tick = tick, 119 121 .preview = world->preview, ··· 125 127 126 128 for(s32 i = 0; i < TIC80_WIDTH * TIC80_HEIGHT; i++) 127 129 { 128 - u8 index = getBankMap()->data[i]; 130 + u8 index = getBankMap(world->studio)->data[i]; 129 131 130 132 if(index) 131 133 { 132 134 memset(colors, 0, sizeof colors); 133 135 134 - tic_tile* tile = &getBankTiles()->data[index]; 136 + tic_tile* tile = &getBankTiles(world->studio)->data[index]; 135 137 136 138 for(s32 p = 0; p < TIC_SPRITESIZE * TIC_SPRITESIZE; p++) 137 139 {
+2 -1
src/studio/editors/world.h
··· 29 29 30 30 struct World 31 31 { 32 + Studio* studio; 32 33 tic_mem* tic; 33 34 Map* map; 34 35 ··· 38 39 void (*scanline)(tic_mem* tic, s32 row, void* data); 39 40 }; 40 41 41 - void initWorld(World* world, tic_mem* tic, Map* map); 42 + void initWorld(World* world, Studio* studio, Map* map); 42 43 void freeWorld(World* world);
+60 -59
src/studio/screens/console.c
··· 80 80 macro(commands) \ 81 81 macro(api) \ 82 82 macro(keys) \ 83 - macro(buttons) \ 83 + macro(buttons) \ 84 84 macro(startup) \ 85 85 macro(terms) \ 86 86 macro(license) ··· 589 589 590 590 static void onExitCommand(Console* console) 591 591 { 592 - exitStudio(); 592 + exitStudio(console->studio); 593 593 commandDone(console); 594 594 } 595 595 ··· 691 691 tic_cart_load(&console->tic->cart, data, size); 692 692 tic_api_reset(console->tic); 693 693 694 - studioRomLoaded(); 694 + studioRomLoaded(console->studio); 695 695 696 696 printBack(console, "\ncart "); 697 697 printFront(console, console->rom.name); ··· 707 707 if(!section) 708 708 setCartName(console, name, tic_fs_path(console->fs, name)); 709 709 710 - studioRomLoaded(); 710 + studioRomLoaded(console->studio); 711 711 712 712 printBack(console, "\ncart "); 713 713 printFront(console, console->rom.name); ··· 741 741 #endif 742 742 tic_cart_load(&tic->cart, data, size); 743 743 744 - studioRomLoaded(); 744 + studioRomLoaded(console->studio); 745 745 } 746 746 } 747 747 } ··· 970 970 ConsoleConfirmCallback callback; 971 971 } CommandConfirmData; 972 972 973 - static void onConfirm(bool yes, void* data) 973 + static void onConfirm(Studio* studio, bool yes, void* data) 974 974 { 975 975 CommandConfirmData* confirmData = (CommandConfirmData*)data; 976 976 ··· 998 998 else 999 999 { 1000 1000 CommandConfirmData data = {console, callback}; 1001 - confirmDialog(text, rows, onConfirm, MOVE(data)); 1001 + confirmDialog(console->studio, text, rows, onConfirm, MOVE(data)); 1002 1002 } 1003 1003 } 1004 1004 ··· 1011 1011 tic_script_config* script; 1012 1012 } LoadDemoConfirmData; 1013 1013 1014 - static void onLoadDemoConfirm(bool yes, void* data) 1014 + static void onLoadDemoConfirm(Studio* studio, bool yes, void* data) 1015 1015 { 1016 1016 LoadDemoConfirmData* demoData = (LoadDemoConfirmData*)data; 1017 1017 ··· 1026 1026 1027 1027 static void onLoadDemoCommand(Console* console, tic_script_config* script) 1028 1028 { 1029 - if(studioCartChanged()) 1029 + if(studioCartChanged(console->studio)) 1030 1030 { 1031 1031 static const char* Rows[] = 1032 1032 { ··· 1036 1036 }; 1037 1037 1038 1038 LoadDemoConfirmData data = {console, onLoadDemoCommandConfirmed, script}; 1039 - confirmDialog(Rows, COUNT_OF(Rows), onLoadDemoConfirm, MOVE(data)); 1039 + confirmDialog(console->studio, Rows, COUNT_OF(Rows), onLoadDemoConfirm, MOVE(data)); 1040 1040 } 1041 1041 else 1042 1042 { ··· 1046 1046 1047 1047 static void onLoadCommand(Console* console) 1048 1048 { 1049 - if(studioCartChanged()) 1049 + if(studioCartChanged(console->studio)) 1050 1050 { 1051 1051 static const char* Rows[] = 1052 1052 { ··· 1081 1081 1082 1082 memset(console->rom.name, 0, sizeof console->rom.name); 1083 1083 1084 - studioRomLoaded(); 1084 + studioRomLoaded(console->studio); 1085 1085 } 1086 1086 1087 1087 static void onNewCommandConfirmed(Console* console) ··· 1122 1122 1123 1123 static void onNewCommand(Console* console) 1124 1124 { 1125 - if(studioCartChanged()) 1125 + if(studioCartChanged(console->studio)) 1126 1126 { 1127 1127 static const char* Rows[] = 1128 1128 { ··· 1444 1444 printLine(console); 1445 1445 } 1446 1446 } 1447 - FOR_EACH_LANG_END 1447 + FOR_EACH_LANG_END 1448 1448 1449 1449 tic_fs_dirback(fs); 1450 1450 } ··· 1454 1454 1455 1455 static void onGameMenuCommand(Console* console) 1456 1456 { 1457 - gotoMenu(); 1457 + gotoMenu(console->studio); 1458 1458 commandDone(console); 1459 1459 } 1460 1460 1461 1461 static void onSurfCommand(Console* console) 1462 1462 { 1463 - gotoSurf(); 1463 + gotoSurf(console->studio); 1464 1464 } 1465 1465 1466 1466 static void loadExt(Console* console, const char* path) ··· 1610 1610 memset(tic->cart.code.data, 0, Size); 1611 1611 memcpy(tic->cart.code.data, buffer, MIN(size, Size)); 1612 1612 1613 - studioRomLoaded(); 1613 + studioRomLoaded(console->studio); 1614 1614 } 1615 1615 else error = true; 1616 1616 ··· 2050 2050 bool error = true; 2051 2051 2052 2052 if(params.id >= 0 && params.id < SFX_COUNT) 2053 - error = studioExportSfx(params.id, filename) == NULL; 2053 + error = studioExportSfx(console->studio, params.id, filename) == NULL; 2054 2054 2055 2055 onFileExported(console, filename, !error); 2056 2056 } ··· 2061 2061 bool error = true; 2062 2062 2063 2063 if(params.id >= 0 && params.id < MUSIC_TRACKS) 2064 - error = studioExportMusic(params.id, filename) == NULL; 2064 + error = studioExportMusic(console->studio, params.id, filename) == NULL; 2065 2065 2066 2066 onFileExported(console, filename, !error); 2067 2067 } ··· 2160 2160 if(strcmp(name, CONFIG_TIC_PATH) == 0) 2161 2161 { 2162 2162 console->config->save(console->config); 2163 - studioRomSaved(); 2163 + studioRomSaved(console->studio); 2164 2164 free(buffer); 2165 2165 return CART_SAVE_OK; 2166 2166 } ··· 2222 2222 2223 2223 u32* ptr = img.values + PaddingTop * CoverWidth + PaddingLeft; 2224 2224 const u8* screen = tic->ram.vram.screen.data; 2225 - const tic_rgb* pal = getConfig()->cart->bank0.palette.vbank0.colors; 2225 + const tic_rgb* pal = getConfig(console->studio)->cart->bank0.palette.vbank0.colors; 2226 2226 2227 2227 for(s32 y = 0; y < Height; y++) 2228 2228 for(s32 x = 0; x < Width; x++) ··· 2266 2266 { 2267 2267 setCartName(console, name, tic_fs_path(console->fs, name)); 2268 2268 success = true; 2269 - studioRomSaved(); 2269 + studioRomSaved(console->studio); 2270 2270 } 2271 2271 } 2272 2272 ··· 2334 2334 { 2335 2335 commandDone(console); 2336 2336 2337 - runGame(); 2337 + runGame(console->studio); 2338 2338 } 2339 2339 2340 2340 static void onResumeCommand(Console* console) 2341 2341 { 2342 2342 commandDone(console); 2343 2343 2344 - resumeGame(); 2344 + resumeGame(console->studio); 2345 2345 } 2346 2346 2347 2347 static void onEvalCommand(Console* console) ··· 3583 3583 3584 3584 tic_rect rect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT}; 3585 3585 3586 - if(checkMousePos(&rect)) 3587 - setCursor(tic_cursor_ibeam); 3586 + if(checkMousePos(console->studio, &rect)) 3587 + setCursor(console->studio, tic_cursor_ibeam); 3588 3588 3589 3589 #if defined(__TIC_ANDROID__) 3590 3590 3591 - if(checkMouseDown(&rect, tic_mouse_left)) 3591 + if(checkMouseDown(console->studio, &rect, tic_mouse_left)) 3592 3592 { 3593 - setCursor(tic_cursor_hand); 3593 + setCursor(console->studio, tic_cursor_hand); 3594 3594 3595 3595 if(console->scroll.active) 3596 3596 { ··· 3606 3606 3607 3607 #else 3608 3608 3609 - if(checkMouseDown(&rect, tic_mouse_left)) 3609 + if(checkMouseDown(console->studio, &rect, tic_mouse_left)) 3610 3610 { 3611 3611 tic_point m = tic_api_mouse(tic); 3612 3612 ··· 3624 3624 3625 3625 #endif 3626 3626 3627 - if(checkMouseClick(&rect, tic_mouse_middle)) 3627 + if(checkMouseClick(console->studio, &rect, tic_mouse_middle)) 3628 3628 { 3629 3629 char* text = getSelectionText(console); 3630 3630 ··· 3661 3661 3662 3662 if(tic->ram.input.keyboard.data != 0) 3663 3663 { 3664 - switch(getClipboardEvent()) 3664 + switch(getClipboardEvent(console->studio)) 3665 3665 { 3666 3666 case TIC_CLIPBOARD_COPY: copyToClipboard(console); break; 3667 3667 case TIC_CLIPBOARD_PASTE: copyFromClipboard(console); break; ··· 3670 3670 3671 3671 console->cursor.delay = CONSOLE_CURSOR_DELAY; 3672 3672 3673 - if(keyWasPressed(tic_key_up)) onHistoryUp(console); 3674 - else if(keyWasPressed(tic_key_down)) onHistoryDown(console); 3675 - else if(keyWasPressed(tic_key_left)) 3673 + if(keyWasPressed(console->studio, tic_key_up)) onHistoryUp(console); 3674 + else if(keyWasPressed(console->studio, tic_key_down)) onHistoryDown(console); 3675 + else if(keyWasPressed(console->studio, tic_key_left)) 3676 3676 { 3677 3677 if(console->input.pos > 0) 3678 3678 console->input.pos--; 3679 3679 } 3680 - else if(keyWasPressed(tic_key_right)) 3680 + else if(keyWasPressed(console->studio, tic_key_right)) 3681 3681 { 3682 3682 console->input.pos++; 3683 3683 size_t len = strlen(console->input.text); 3684 3684 if(console->input.pos > len) 3685 3685 console->input.pos = len; 3686 3686 } 3687 - else if(keyWasPressed(tic_key_return)) processConsoleCommand(console); 3688 - else if(keyWasPressed(tic_key_backspace)) processConsoleBackspace(console); 3689 - else if(keyWasPressed(tic_key_delete)) processConsoleDel(console); 3690 - else if(keyWasPressed(tic_key_home)) processConsoleHome(console); 3691 - else if(keyWasPressed(tic_key_end)) processConsoleEnd(console); 3692 - else if(keyWasPressed(tic_key_tab)) processConsoleTab(console); 3693 - else if(keyWasPressed(tic_key_pageup)) processConsolePgUp(console); 3694 - else if(keyWasPressed(tic_key_pagedown)) processConsolePgDown(console); 3687 + else if(keyWasPressed(console->studio, tic_key_return)) processConsoleCommand(console); 3688 + else if(keyWasPressed(console->studio, tic_key_backspace)) processConsoleBackspace(console); 3689 + else if(keyWasPressed(console->studio, tic_key_delete)) processConsoleDel(console); 3690 + else if(keyWasPressed(console->studio, tic_key_home)) processConsoleHome(console); 3691 + else if(keyWasPressed(console->studio, tic_key_end)) processConsoleEnd(console); 3692 + else if(keyWasPressed(console->studio, tic_key_tab)) processConsoleTab(console); 3693 + else if(keyWasPressed(console->studio, tic_key_pageup)) processConsolePgUp(console); 3694 + else if(keyWasPressed(console->studio, tic_key_pagedown)) processConsolePgDown(console); 3695 3695 3696 3696 # if defined(__TIC_LINUX__) 3697 3697 tic_keycode clearKey = tic_key_l; ··· 3702 3702 bool modifier_CTRL = tic_api_key(tic, tic_key_ctrl); 3703 3703 3704 3704 if (modifier_CTRL) { 3705 - if (keyWasPressed(tic_key_a)) processConsoleHome(console); 3706 - else if (keyWasPressed(tic_key_e)) processConsoleEnd(console); 3707 - else if (keyWasPressed(clearKey)) { 3705 + if (keyWasPressed(console->studio, tic_key_a)) processConsoleHome(console); 3706 + else if (keyWasPressed(console->studio, tic_key_e)) processConsoleEnd(console); 3707 + else if (keyWasPressed(console->studio, clearKey)) { 3708 3708 onClsCommand(console); 3709 3709 return; 3710 3710 } 3711 3711 } 3712 3712 } 3713 3713 3714 - char sym = getKeyboardText(); 3714 + char sym = getKeyboardText(console->studio); 3715 3715 3716 3716 if(sym) 3717 3717 { ··· 3730 3730 processMouse(console); 3731 3731 processKeyboard(console); 3732 3732 3733 - Start* start = getStartScreen(); 3733 + Start* start = getStartScreen(console->studio); 3734 3734 3735 3735 if(console->tickCounter == 0) 3736 3736 { ··· 3745 3745 printBack(console, " for help\n"); 3746 3746 3747 3747 #if defined (TIC_BUILD_WITH_LUA) 3748 - if(getConfig()->checkNewVersion) 3748 + if(getConfig(console->studio)->checkNewVersion) 3749 3749 tic_net_get(console->net, "/api?fn=version", onHttpVesrsionGet, console); 3750 3750 #endif 3751 3751 } ··· 3755 3755 else printBack(console, "\n loading cart..."); 3756 3756 } 3757 3757 3758 - if (getStudioMode() != TIC_CONSOLE_MODE) return; 3758 + if (getStudioMode(console->studio) != TIC_CONSOLE_MODE) return; 3759 3759 3760 3760 tic_api_cls(tic, TIC_COLOR_BG); 3761 3761 drawConsoleText(console); ··· 3764 3764 { 3765 3765 if(console->tickCounter >= (u32)(console->args.skip ? 1 : TIC80_FRAMERATE)) 3766 3766 { 3767 - runGame(); 3767 + runGame(console->studio); 3768 3768 3769 3769 start->embed = false; 3770 - studioRomLoaded(); 3770 + studioRomLoaded(console->studio); 3771 3771 3772 3772 printLine(console); 3773 3773 commandDone(console); ··· 3795 3795 3796 3796 console->commands.current++; 3797 3797 } 3798 - else if(getConfig()->cli) 3799 - exitStudio(); 3798 + else if(getConfig(console->studio)->cli) 3799 + exitStudio(console->studio); 3800 3800 } 3801 3801 } 3802 3802 ··· 3856 3856 } 3857 3857 3858 3858 if(done) 3859 - studioRomLoaded(); 3859 + studioRomLoaded(console->studio); 3860 3860 3861 3861 return done; 3862 3862 } ··· 3871 3871 return strcmp(((const ApiItem*)a)->name, ((const ApiItem*)b)->name); 3872 3872 } 3873 3873 3874 - void initConsole(Console* console, tic_mem* tic, tic_fs* fs, tic_net* net, Config* config, StartArgs args) 3874 + void initConsole(Console* console, Studio* studio, tic_fs* fs, tic_net* net, Config* config, StartArgs args) 3875 3875 { 3876 3876 if(!console->text) console->text = malloc(CONSOLE_BUFFER_SIZE); 3877 3877 if(!console->color) console->color = malloc(CONSOLE_BUFFER_SIZE); ··· 3879 3879 3880 3880 *console = (Console) 3881 3881 { 3882 - .tic = tic, 3882 + .studio = studio, 3883 + .tic = getMemory(studio), 3883 3884 .config = config, 3884 3885 .loadByHash = loadByHash, 3885 3886 .load = loadExt, ··· 3928 3929 memset(console->color, TIC_COLOR_BG, CONSOLE_BUFFER_SIZE); 3929 3930 memset(console->desc, 0, sizeof(CommandDesc)); 3930 3931 3931 - Start* start = getStartScreen(); 3932 + Start* start = getStartScreen(console->studio); 3932 3933 3933 3934 if(!console->args.cli) 3934 3935 { ··· 3949 3950 exit(1); 3950 3951 } 3951 3952 else 3952 - getStartScreen()->embed = true; 3953 + getStartScreen(console->studio)->embed = true; 3953 3954 3954 3955 console->active = !start->embed; 3955 3956 }
+2 -1
src/studio/screens/console.h
··· 70 70 size_t pos; 71 71 } input; 72 72 73 + Studio* studio; 73 74 tic_mem* tic; 74 75 75 76 struct tic_fs* fs; ··· 114 115 CartSaveResult(*save)(Console*); 115 116 }; 116 117 117 - void initConsole(Console*, tic_mem*, struct tic_fs* fs, struct tic_net* net, struct Config* config, StartArgs args); 118 + void initConsole(Console*, Studio* studio, struct tic_fs* fs, struct tic_net* net, struct Config* config, StartArgs args); 118 119 void freeConsole(Console* console);
+21 -7
src/studio/screens/main_menu.c src/studio/screens/mainmenu.c
··· 20 20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 21 // SOFTWARE. 22 22 23 - #include "studio/studio_impl.h" 24 - #include "main_menu.h" 23 + #include "studio/studio.h" 24 + #include "studio/config.h" 25 + #include "studio/screens/menu.h" 26 + #include "mainmenu.h" 27 + 28 + typedef struct 29 + { 30 + tic_mapping mapping; 31 + s32 index; 32 + s32 key; 33 + } Gamepads; 25 34 26 35 struct StudioMainMenu 27 36 { 37 + Studio* studio; 28 38 tic_mem* tic; 29 39 Menu* menu; 30 40 ··· 49 59 { 50 60 .menu = menu, 51 61 .options = &config->data.options, 62 + .studio = config->studio, 52 63 .tic = config->tic, 53 64 .gamepads.key = -1, 54 65 }; ··· 218 229 StudioMainMenu* main = data; 219 230 tic_mem* tic = main->tic; 220 231 tic_core_script_config(tic)->callback.gamemenu(tic, pos, NULL); 221 - resumeGame(); 232 + resumeGame(main->studio); 222 233 } 223 234 224 235 static void freeItems(StudioMainMenu* menu) ··· 285 296 286 297 static void onResumeGame(void* data, s32 pos) 287 298 { 288 - resumeGame(); 299 + StudioMainMenu* main = data; 300 + resumeGame(main->studio); 289 301 } 290 302 291 303 static void onResetGame(void* data, s32 pos) 292 304 { 293 305 StudioMainMenu* main = data; 294 306 tic_api_reset(main->tic); 295 - setStudioMode(TIC_RUN_MODE); 307 + setStudioMode(main->studio, TIC_RUN_MODE); 296 308 } 297 309 298 310 static void onExitStudio(void* data, s32 pos) 299 311 { 300 - exitStudio(); 312 + StudioMainMenu* main = data; 313 + exitStudio(main->studio); 301 314 } 302 315 303 316 static void onExitGame(void* data, s32 pos) 304 317 { 305 - exitGame(); 318 + StudioMainMenu* main = data; 319 + exitGame(main->studio); 306 320 } 307 321 308 322 static const MenuItem MainMenu[] =
src/studio/screens/main_menu.h src/studio/screens/mainmenu.h
+28 -25
src/studio/screens/menu.c
··· 39 39 40 40 struct Menu 41 41 { 42 + Studio* studio; 42 43 tic_mem* tic; 43 44 44 45 s32 ticks; ··· 178 179 179 180 static void onMenuItem(Menu* menu, const MenuItem* item) 180 181 { 181 - playSystemSfx(2); 182 + playSystemSfx(menu->studio, 2); 182 183 menu->anim.movie = resetMovie(item->back ? &menu->anim.back : &menu->anim.close); 183 184 } 184 185 ··· 187 188 tic_rect left = {x - 1, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT}; 188 189 bool down = false; 189 190 bool over = false; 190 - if(checkMousePos(&left)) 191 + if(checkMousePos(menu->studio, &left)) 191 192 { 192 193 over = true; 193 - setCursor(tic_cursor_hand); 194 - down = checkMouseDown(&left, tic_mouse_left); 194 + setCursor(menu->studio, tic_cursor_hand); 195 + down = checkMouseDown(menu->studio, &left, tic_mouse_left); 195 196 196 - if(checkMouseClick(&left, tic_mouse_left)) 197 + if(checkMouseClick(menu->studio, &left, tic_mouse_left)) 197 198 { 198 - playSystemSfx(2); 199 + playSystemSfx(menu->studio, 2); 199 200 updateOption(option, delta, menu->data); 200 201 } 201 202 } 202 203 203 204 if(down) 204 205 { 205 - drawBitIcon(icon, left.x, left.y, tic_color_white); 206 + drawBitIcon(menu->studio, icon, left.x, left.y, tic_color_white); 206 207 } 207 208 else 208 209 { 209 - drawBitIcon(icon, left.x, left.y, tic_color_black); 210 - drawBitIcon(icon, left.x, left.y - 1, over ? tic_color_white : tic_color_light_grey); 210 + drawBitIcon(menu->studio, icon, left.x, left.y, tic_color_black); 211 + drawBitIcon(menu->studio, icon, left.x, left.y - 1, over ? tic_color_white : tic_color_light_grey); 211 212 } 212 213 } 213 214 214 215 static void drawMenu(Menu* menu, s32 x, s32 y) 215 216 { 216 - if (getStudioMode() != TIC_MENU_MODE) 217 + if (getStudioMode(menu->studio) != TIC_MENU_MODE) 217 218 return; 218 219 219 220 tic_mem* tic = menu->tic; ··· 223 224 if(tic_api_btnp(menu->tic, Up, Hold, Period) 224 225 || tic_api_keyp(tic, tic_key_up, Hold, Period)) 225 226 { 226 - playSystemSfx(2); 227 + playSystemSfx(menu->studio, 2); 227 228 menu->anim.movie = resetMovie(&menu->anim.up); 228 229 } 229 230 230 231 if(tic_api_btnp(menu->tic, Down, Hold, Period) 231 232 || tic_api_keyp(tic, tic_key_down, Hold, Period)) 232 233 { 233 - playSystemSfx(2); 234 + playSystemSfx(menu->studio, 2); 234 235 menu->anim.movie = resetMovie(&menu->anim.down); 235 236 } 236 237 ··· 241 242 if(tic_api_btnp(menu->tic, Left, Hold, Period) 242 243 || tic_api_keyp(tic, tic_key_left, Hold, Period)) 243 244 { 244 - playSystemSfx(2); 245 + playSystemSfx(menu->studio, 2); 245 246 updateOption(option, -1, menu->data); 246 247 } 247 248 248 249 if(tic_api_btnp(menu->tic, Right, Hold, Period) 249 250 || tic_api_keyp(tic, tic_key_right, Hold, Period)) 250 251 { 251 - playSystemSfx(2); 252 + playSystemSfx(menu->studio, 2); 252 253 updateOption(option, +1, menu->data); 253 254 } 254 255 } ··· 258 259 { 259 260 if(option) 260 261 { 261 - playSystemSfx(2); 262 + playSystemSfx(menu->studio, 2); 262 263 updateOption(option, +1, menu->data); 263 264 } 264 265 else if(menu->items[menu->pos].handler) ··· 269 270 || tic_api_keyp(tic, tic_key_backspace, Hold, Period)) 270 271 && menu->back) 271 272 { 272 - playSystemSfx(2); 273 + playSystemSfx(menu->studio, 2); 273 274 menu->anim.movie = resetMovie(&menu->anim.back); 274 275 } 275 276 } ··· 283 284 y + TextMargin + ItemHeight * (i - menu->pos) - menu->anim.pos, it->width, TIC_FONT_HEIGHT}; 284 285 285 286 bool down = false; 286 - if(animIdle(menu) && checkMousePos(&rect) && it->handler) 287 + if(animIdle(menu) && checkMousePos(menu->studio, &rect) && it->handler) 287 288 { 288 - setCursor(tic_cursor_hand); 289 + setCursor(menu->studio, tic_cursor_hand); 289 290 290 - if(checkMouseDown(&rect, tic_mouse_left)) 291 + if(checkMouseDown(menu->studio, &rect, tic_mouse_left)) 291 292 down = true; 292 293 293 - if(checkMouseClick(&rect, tic_mouse_left)) 294 + if(checkMouseClick(menu->studio, &rect, tic_mouse_left)) 294 295 { 295 296 if(it->handler) 296 297 { ··· 359 360 tic_api_rect(tic, x, y - (menu->anim.cursor - ItemHeight) / 2, TIC80_WIDTH, menu->anim.cursor, tic_color_red); 360 361 } 361 362 362 - Menu* studio_menu_create(struct tic_mem* tic) 363 + Menu* studio_menu_create(Studio* studio) 363 364 { 364 365 Menu* menu = malloc(sizeof(Menu)); 365 366 *menu = (Menu) 366 367 { 367 - .tic = tic, 368 + .studio = studio, 369 + .tic = getMemory(studio), 368 370 .anim = 369 371 { 370 372 .idle = {.done = emptyDone,}, ··· 430 432 } 431 433 } 432 434 433 - if(getStudioMode() != TIC_MENU_MODE) 435 + if(getStudioMode(menu->studio) != TIC_MENU_MODE) 434 436 return; 435 437 436 438 studio_menu_anim(tic, menu->ticks); ··· 438 440 VBANK(tic, 1) 439 441 { 440 442 tic_api_cls(tic, tic->ram.vram.vars.clear = tic_color_blue); 441 - memcpy(tic->ram.vram.palette.data, getConfig()->cart->bank0.palette.vbank0.data, sizeof(tic_palette)); 443 + memcpy(tic->ram.vram.palette.data, getConfig(menu->studio)->cart->bank0.palette.vbank0.data, sizeof(tic_palette)); 442 444 443 445 drawCursor(menu, 0, (TIC80_HEIGHT - ItemHeight) / 2); 444 446 drawMenu(menu, 0, (TIC80_HEIGHT - ItemHeight) / 2); ··· 455 457 456 458 *menu = (Menu) 457 459 { 460 + .studio = menu->studio, 458 461 .tic = menu->tic, 459 462 .anim = menu->anim, 460 463 .items = realloc(menu->items, size), ··· 497 500 { 498 501 if(menu->back) 499 502 { 500 - playSystemSfx(2); 503 + playSystemSfx(menu->studio, 2); 501 504 menu->anim.movie = resetMovie(&menu->anim.back); 502 505 } 503 506
+2 -1
src/studio/screens/menu.h
··· 26 26 27 27 typedef struct Menu Menu; 28 28 struct tic_mem; 29 + struct Studio; 29 30 30 - Menu* studio_menu_create(struct tic_mem* tic); 31 + Menu* studio_menu_create(struct Studio* studio); 31 32 void studio_menu_tick(Menu* menu); 32 33 33 34 typedef s32(*MenuOptionGetHandler)(void*);
+10 -9
src/studio/screens/run.c
··· 37 37 { 38 38 Run* run = (Run*)data; 39 39 40 - setStudioMode(TIC_CONSOLE_MODE); 40 + setStudioMode(run->studio, TIC_CONSOLE_MODE); 41 41 run->console->error(run->console, info); 42 42 } 43 43 ··· 101 101 102 102 static void tick(Run* run) 103 103 { 104 - if (getStudioMode() != TIC_RUN_MODE) 104 + if (getStudioMode(run->studio) != TIC_RUN_MODE) 105 105 return; 106 106 107 107 tic_mem* tic = run->tic; ··· 125 125 } 126 126 127 127 if(run->exit) 128 - setStudioMode(TIC_CONSOLE_MODE); 128 + setStudioMode(run->studio, TIC_CONSOLE_MODE); 129 129 } 130 130 131 - void initRun(Run* run, Console* console, tic_fs* fs, tic_mem* tic) 131 + void initRun(Run* run, Console* console, tic_fs* fs, Studio* studio) 132 132 { 133 133 *run = (Run) 134 134 { 135 - .tic = tic, 135 + .studio = studio, 136 + .tic = getMemory(studio), 136 137 .console = console, 137 138 .fs = fs, 138 139 .tick = tick, ··· 141 142 142 143 { 143 144 enum {Size = sizeof(tic_persistent)}; 144 - memset(&tic->ram.persistent, 0, Size); 145 + memset(&run->tic->ram.persistent, 0, Size); 145 146 146 147 initPMemName(run); 147 148 ··· 150 151 151 152 if(data) SCOPE(free(data)) 152 153 { 153 - memset(&tic->ram.persistent, 0, Size); 154 - memcpy(&tic->ram.persistent, data, MIN(size, Size)); 154 + memset(&run->tic->ram.persistent, 0, Size); 155 + memcpy(&run->tic->ram.persistent, data, MIN(size, Size)); 155 156 } 156 157 157 - memcpy(run->pmem.data, tic->ram.persistent.data, Size); 158 + memcpy(run->pmem.data, run->tic->ram.persistent.data, Size); 158 159 } 159 160 160 161 tic_sys_preseed();
+2 -1
src/studio/screens/run.h
··· 29 29 30 30 struct Run 31 31 { 32 + Studio* studio; 32 33 tic_mem* tic; 33 34 struct Console* console; 34 35 struct tic_fs* fs; ··· 41 42 void(*tick)(Run*); 42 43 }; 43 44 44 - void initRun(Run*, struct Console*, struct tic_fs* , tic_mem*); 45 + void initRun(Run*, struct Console*, struct tic_fs*, Studio* studio); 45 46 void freeRun(Run* run);
+11 -9
src/studio/screens/start.c
··· 55 55 56 56 static void chime(Start* start) 57 57 { 58 - playSystemSfx(1); 58 + playSystemSfx(start->studio, 1); 59 59 } 60 60 61 61 static void stop_chime(Start* start) ··· 71 71 static void start_console(Start* start) 72 72 { 73 73 drawHeader(start); 74 - setStudioMode(TIC_CONSOLE_MODE); 74 + setStudioMode(start->studio, TIC_CONSOLE_MODE); 75 75 } 76 76 77 77 static void tick(Start* start) ··· 114 114 return NULL; 115 115 } 116 116 117 - void initStart(Start* start, tic_mem* tic, const char* cart) 117 + void initStart(Start* start, Studio* studio, const char* cart) 118 118 { 119 119 enum duration { 120 120 immediate = 0, ··· 124 124 125 125 *start = (Start) 126 126 { 127 - .tic = tic, 127 + .studio = studio, 128 + .tic = getMemory(studio), 128 129 .initialized = true, 129 130 .tick = tick, 130 131 .embed = false, 131 132 .ticks = 0, 132 133 .stage = 0, 133 - .stages = { 134 + .stages = 135 + { 134 136 { reset, .ticks = one_second }, 135 137 { chime, .ticks = immediate }, 136 138 { header, .ticks = one_second }, ··· 163 165 164 166 if(data) SCOPE(free(data)) 165 167 { 166 - tic_cart_load(&tic->cart, data, size); 167 - tic_api_reset(tic); 168 + tic_cart_load(&start->tic->cart, data, size); 169 + tic_api_reset(start->tic); 168 170 start->embed = true; 169 171 } 170 172 } ··· 212 214 213 215 if(dataSize) 214 216 { 215 - tic_cart_load(&tic->cart, data, dataSize); 216 - tic_api_reset(tic); 217 + tic_cart_load(&start->tic->cart, data, dataSize); 218 + tic_api_reset(start->tic); 217 219 start->embed = true; 218 220 } 219 221
+2 -1
src/studio/screens/start.h
··· 42 42 43 43 struct Start 44 44 { 45 + Studio* studio; 45 46 tic_mem* tic; 46 47 47 48 bool initialized; ··· 59 60 void (*tick)(Start*); 60 61 }; 61 62 62 - void initStart(Start* start, tic_mem* tic, const char* cart); 63 + void initStart(Start* start, Studio* studio, const char* cart); 63 64 void freeStart(Start* start);
+15 -13
src/studio/screens/surf.c
··· 99 99 enum{Gap = 10, TipX = 150, SelectWidth = 54}; 100 100 101 101 u8 colorkey = 0; 102 - tiles2ram(&tic->ram, &getConfig()->cart->bank0.tiles); 102 + tiles2ram(&tic->ram, &getConfig(surf->studio)->cart->bank0.tiles); 103 103 tic_api_spr(tic, 12, TipX, y+1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); 104 104 { 105 105 static const char Label[] = "SELECT"; ··· 148 148 149 149 u8 colorkey = 0; 150 150 151 - tiles2ram(&tic->ram, &getConfig()->cart->bank0.tiles); 151 + tiles2ram(&tic->ram, &getConfig(surf->studio)->cart->bank0.tiles); 152 152 tic_api_spr(tic, 15, TipX + SelectWidth, y + 1, 1, 1, &colorkey, 1, 1, tic_no_flip, tic_no_rotate); 153 153 { 154 154 static const char Label[] = "WEBSITE"; ··· 528 528 529 529 if(strcmp(dir, "") != 0) 530 530 { 531 - playSystemSfx(2); 531 + playSystemSfx(surf->studio, 2); 532 532 533 533 surf->anim.movie = resetMovie(&surf->anim.goback.hide); 534 534 } ··· 542 542 } 543 543 else 544 544 { 545 - playSystemSfx(2); 545 + playSystemSfx(surf->studio, 2); 546 546 surf->anim.movie = resetMovie(&surf->anim.gotodir.hide); 547 547 } 548 548 } 549 549 550 550 static void onCartLoaded(void* data) 551 551 { 552 - runGame(); 552 + Surf* surf = data; 553 + runGame(surf->studio); 553 554 } 554 555 555 556 static void onPlayCart(void* data) ··· 559 560 560 561 if (item->hash) 561 562 { 562 - surf->console->loadByHash(surf->console, item->name, item->hash, NULL, onCartLoaded, NULL); 563 + surf->console->loadByHash(surf->console, item->name, item->hash, NULL, onCartLoaded, surf); 563 564 } 564 565 else 565 566 { 566 567 surf->console->load(surf->console, item->name); 567 - runGame(); 568 + runGame(surf->studio); 568 569 } 569 570 } 570 571 ··· 619 620 || tic_api_keyp(tic, tic_key_up, Hold, Period)) 620 621 { 621 622 move(surf, -1); 622 - playSystemSfx(2); 623 + playSystemSfx(surf->studio, 2); 623 624 } 624 625 else if(tic_api_btnp(tic, Down, Hold, Period) 625 626 || tic_api_keyp(tic, tic_key_down, Hold, Period)) 626 627 { 627 628 move(surf, +1); 628 - playSystemSfx(2); 629 + playSystemSfx(surf->studio, 2); 629 630 } 630 631 else if(tic_api_btnp(tic, Left, Hold, Period) 631 632 || tic_api_keyp(tic, tic_key_left, Hold, Period) ··· 708 709 if (isIdle(surf) && surf->menu.count > 0) 709 710 processGamepad(surf); 710 711 711 - if (getStudioMode() != TIC_SURF_MODE) return; 712 + if (getStudioMode(surf->studio) != TIC_SURF_MODE) return; 712 713 713 714 if (surf->menu.count > 0) 714 715 { ··· 723 724 VBANK(tic, 1) 724 725 { 725 726 tic_api_cls(tic, tic->ram.vram.vars.clear = tic_color_yellow); 726 - memcpy(tic->ram.vram.palette.data, getConfig()->cart->bank0.palette.vbank0.data, sizeof(tic_palette)); 727 + memcpy(tic->ram.vram.palette.data, getConfig(surf->studio)->cart->bank0.palette.vbank0.data, sizeof(tic_palette)); 727 728 728 729 if(surf->menu.count > 0) 729 730 { ··· 802 803 surf->anim.movie = resetMovie(&surf->anim.idle); 803 804 } 804 805 805 - void initSurf(Surf* surf, tic_mem* tic, struct Console* console) 806 + void initSurf(Surf* surf, Studio* studio, struct Console* console) 806 807 { 807 808 freeAnim(surf); 808 809 809 810 *surf = (Surf) 810 811 { 811 - .tic = tic, 812 + .studio = studio, 813 + .tic = getMemory(studio), 812 814 .console = console, 813 815 .fs = console->fs, 814 816 .net = console->net,
+2 -1
src/studio/screens/surf.h
··· 28 28 29 29 struct Surf 30 30 { 31 + Studio* studio; 31 32 tic_mem* tic; 32 33 struct tic_fs* fs; 33 34 struct tic_net* net; ··· 83 84 void (*scanline)(tic_mem* tic, s32 row, void* data); 84 85 }; 85 86 86 - void initSurf(Surf* surf, tic_mem* tic, struct Console* console); 87 + void initSurf(Surf* surf, Studio* studio, struct Console* console); 87 88 void freeSurf(Surf* surf);
+682 -523
src/studio/studio.c
··· 21 21 // SOFTWARE. 22 22 23 23 #include "studio.h" 24 - #include "studio_impl.h" 25 24 26 25 #if defined(BUILD_EDITORS) 27 26 ··· 41 40 #endif 42 41 43 42 #include "ext/md5.h" 43 + #include "config.h" 44 + #include "cart.h" 44 45 #include "screens/start.h" 45 46 #include "screens/run.h" 46 47 #include "screens/menu.h" 47 - #include "screens/main_menu.h" 48 - #include "config.h" 49 - #include "cart.h" 48 + #include "screens/mainmenu.h" 50 49 51 50 #include "fs.h" 52 51 ··· 57 56 #define _USE_MATH_DEFINES 58 57 #include <math.h> 59 58 60 - #if defined(BUILD_EDITORS) 59 + #define MD5_HASHSIZE 16 61 60 62 - #define FRAME_SIZE (TIC80_FULLWIDTH * TIC80_FULLHEIGHT * sizeof(u32)) 61 + #if defined(TIC80_PRO) 62 + #define TIC_EDITOR_BANKS (TIC_BANKS) 63 + #else 64 + #define TIC_EDITOR_BANKS 1 65 + #endif 63 66 64 - static const char VideoGif[] = "video%i.gif"; 65 - static const char ScreenGif[] = "screen%i.gif"; 67 + #ifdef BUILD_EDITORS 68 + typedef struct 69 + { 70 + u8 data[MD5_HASHSIZE]; 71 + } CartHash; 72 + 73 + static const EditorMode Modes[] = 74 + { 75 + TIC_CODE_MODE, 76 + TIC_SPRITE_MODE, 77 + TIC_MAP_MODE, 78 + TIC_SFX_MODE, 79 + TIC_MUSIC_MODE, 80 + }; 81 + 82 + static const EditorMode BankModes[] = 83 + { 84 + TIC_SPRITE_MODE, 85 + TIC_MAP_MODE, 86 + TIC_SFX_MODE, 87 + TIC_MUSIC_MODE, 88 + }; 66 89 67 90 #endif 68 91 69 - static void emptyDone(void* data) {} 92 + typedef struct 93 + { 94 + bool down; 95 + bool click; 96 + 97 + tic_point start; 98 + tic_point end; 99 + 100 + } MouseState; 70 101 71 - static Studio impl = 102 + struct Studio 72 103 { 73 - .mode = TIC_START_MODE, 74 - .prevMode = TIC_CODE_MODE, 104 + tic_mem* tic; 105 + 106 + bool alive; 107 + 108 + EditorMode mode; 109 + EditorMode prevMode; 110 + EditorMode toolbarMode; 111 + 112 + struct 113 + { 114 + MouseState state[3]; 115 + } mouse; 75 116 76 117 #if defined(BUILD_EDITORS) 77 - .menuMode = TIC_CONSOLE_MODE, 118 + EditorMode menuMode; 119 + 120 + struct 121 + { 122 + CartHash hash; 123 + u64 mdate; 124 + }cart; 78 125 79 - .bank = 126 + struct 80 127 { 81 - .chained = true, 82 - }, 128 + bool show; 129 + bool chained; 130 + 131 + union 132 + { 133 + struct 134 + { 135 + s8 sprites; 136 + s8 map; 137 + s8 sfx; 138 + s8 music; 139 + } index; 140 + 141 + s8 indexes[COUNT_OF(BankModes)]; 142 + }; 143 + } bank; 83 144 84 - .anim = 145 + struct 85 146 { 86 - .pos = 147 + struct 87 148 { 88 - .popup = -TOOLBAR_SIZE, 89 - }, 90 - .idle = {.done = emptyDone,} 91 - }, 149 + s32 popup; 150 + } pos; 151 + 152 + Movie* movie; 153 + 154 + Movie idle; 155 + Movie show; 156 + Movie wait; 157 + Movie hide; 158 + } anim; 159 + 160 + struct 161 + { 162 + char message[STUDIO_TEXT_BUFFER_WIDTH]; 163 + } popup; 164 + 165 + struct 166 + { 167 + char text[STUDIO_TEXT_BUFFER_WIDTH]; 168 + } tooltip; 92 169 93 - .popup = 170 + struct 94 171 { 95 - .message = "\0", 96 - }, 172 + bool record; 173 + 174 + u32* buffer; 175 + s32 frames; 176 + s32 frame; 177 + 178 + } video; 179 + 180 + Code* code; 97 181 98 - .tooltip = 182 + struct 99 183 { 100 - .text = "\0", 101 - }, 184 + Sprite* sprite[TIC_EDITOR_BANKS]; 185 + Map* map[TIC_EDITOR_BANKS]; 186 + Sfx* sfx[TIC_EDITOR_BANKS]; 187 + Music* music[TIC_EDITOR_BANKS]; 188 + } banks; 189 + 190 + Console* console; 191 + World* world; 192 + Surf* surf; 102 193 194 + tic_net* net; 103 195 #endif 196 + 197 + Start* start; 198 + Run* run; 199 + Menu* menu; 200 + Config* config; 201 + 202 + StudioMainMenu* mainmenu; 203 + 204 + tic_fs* fs; 205 + s32 samplerate; 206 + tic_font systemFont; 104 207 }; 208 + 209 + #if defined(BUILD_EDITORS) 210 + 211 + #define FRAME_SIZE (TIC80_FULLWIDTH * TIC80_FULLHEIGHT * sizeof(u32)) 212 + 213 + static const char VideoGif[] = "video%i.gif"; 214 + static const char ScreenGif[] = "screen%i.gif"; 215 + 216 + #endif 217 + 218 + static void emptyDone(void* data) {} 105 219 106 220 void fadePalette(tic_palette* pal, s32 value) 107 221 { ··· 141 255 } 142 256 143 257 #if defined(BUILD_EDITORS) 144 - static const tic_sfx* getSfxSrc() 258 + static const tic_sfx* getSfxSrc(Studio* studio) 145 259 { 146 - tic_mem* tic = impl.tic; 147 - return &tic->cart.banks[impl.bank.index.sfx].sfx; 260 + tic_mem* tic = studio->tic; 261 + return &tic->cart.banks[studio->bank.index.sfx].sfx; 148 262 } 149 263 150 - static const tic_music* getMusicSrc() 264 + static const tic_music* getMusicSrc(Studio* studio) 151 265 { 152 - tic_mem* tic = impl.tic; 153 - return &tic->cart.banks[impl.bank.index.music].music; 266 + tic_mem* tic = studio->tic; 267 + return &tic->cart.banks[studio->bank.index.music].music; 154 268 } 155 269 156 - const char* studioExportSfx(s32 index, const char* filename) 270 + const char* studioExportSfx(Studio* studio, s32 index, const char* filename) 157 271 { 158 - tic_mem* tic = impl.tic; 272 + tic_mem* tic = studio->tic; 159 273 160 - const char* path = tic_fs_path(impl.fs, filename); 274 + const char* path = tic_fs_path(studio->fs, filename); 161 275 162 - if(wave_open( impl.samplerate, path )) 276 + if(wave_open( studio->samplerate, path )) 163 277 { 164 278 165 279 #if TIC80_SAMPLE_CHANNELS == 2 166 280 wave_enable_stereo(); 167 281 #endif 168 282 169 - const tic_sfx* sfx = getSfxSrc(); 283 + const tic_sfx* sfx = getSfxSrc(studio); 170 284 171 285 sfx2ram(&tic->ram, sfx); 172 - music2ram(&tic->ram, getMusicSrc()); 286 + music2ram(&tic->ram, getMusicSrc(studio)); 173 287 174 288 { 175 289 const tic_sample* effect = &sfx->samples.data[index]; ··· 199 313 return NULL; 200 314 } 201 315 202 - const char* studioExportMusic(s32 track, const char* filename) 316 + const char* studioExportMusic(Studio* studio, s32 track, const char* filename) 203 317 { 204 - tic_mem* tic = impl.tic; 318 + tic_mem* tic = studio->tic; 205 319 206 - const char* path = tic_fs_path(impl.fs, filename); 320 + const char* path = tic_fs_path(studio->fs, filename); 207 321 208 - if(wave_open( impl.samplerate, path )) 322 + if(wave_open( studio->samplerate, path )) 209 323 { 210 324 #if TIC80_SAMPLE_CHANNELS == 2 211 325 wave_enable_stereo(); 212 326 #endif 213 327 214 - const tic_sfx* sfx = getSfxSrc(); 215 - const tic_music* music = getMusicSrc(); 328 + const tic_sfx* sfx = getSfxSrc(studio); 329 + const tic_music* music = getMusicSrc(studio); 216 330 217 331 sfx2ram(&tic->ram, sfx); 218 332 music2ram(&tic->ram, music); 219 333 220 334 const tic_music_state* state = &tic->ram.music_state; 221 - const Music* editor = impl.banks.music[impl.bank.index.music]; 335 + const Music* editor = studio->banks.music[studio->bank.index.music]; 222 336 223 337 tic_api_music(tic, track, -1, -1, false, editor->sustain, -1, -1); 224 338 ··· 260 374 tic_api_sfx(tic, -1, 0, 0, -1, channel, MAX_VOLUME, MAX_VOLUME, SFX_DEF_SPEED); 261 375 } 262 376 263 - char getKeyboardText() 377 + char getKeyboardText(Studio* studio) 264 378 { 265 379 char text; 266 380 if(!tic_sys_keyboard_text(&text)) 267 381 { 268 - tic_mem* tic = impl.tic; 382 + tic_mem* tic = studio->tic; 269 383 tic80_input* input = &tic->ram.input; 270 384 271 385 static const char Symbols[] = " abcdefghijklmnopqrstuvwxyz0123456789-=[]\\;'`,./ "; ··· 296 410 return text; 297 411 } 298 412 299 - bool keyWasPressed(tic_key key) 413 + bool keyWasPressed(Studio* studio, tic_key key) 300 414 { 301 - tic_mem* tic = impl.tic; 415 + tic_mem* tic = studio->tic; 302 416 return tic_api_keyp(tic, key, KEYBOARD_HOLD, KEYBOARD_PERIOD); 303 417 } 304 418 305 - bool anyKeyWasPressed() 419 + bool anyKeyWasPressed(Studio* studio) 306 420 { 307 - tic_mem* tic = impl.tic; 421 + tic_mem* tic = studio->tic; 308 422 309 423 for(s32 i = 0; i < TIC80_KEY_BUFFER; i++) 310 424 { ··· 318 432 } 319 433 320 434 #if defined(BUILD_EDITORS) 321 - tic_tiles* getBankTiles() 435 + tic_tiles* getBankTiles(Studio* studio) 322 436 { 323 - return &impl.tic->cart.banks[impl.bank.index.sprites].tiles; 437 + return &studio->tic->cart.banks[studio->bank.index.sprites].tiles; 324 438 } 325 439 326 - tic_map* getBankMap() 440 + tic_map* getBankMap(Studio* studio) 327 441 { 328 - return &impl.tic->cart.banks[impl.bank.index.map].map; 442 + return &studio->tic->cart.banks[studio->bank.index.map].map; 329 443 } 330 444 331 - tic_palette* getBankPalette(bool vbank) 445 + tic_palette* getBankPalette(Studio* studio, bool vbank) 332 446 { 333 - tic_bank* bank = &impl.tic->cart.banks[impl.bank.index.sprites]; 447 + tic_bank* bank = &studio->tic->cart.banks[studio->bank.index.sprites]; 334 448 return vbank ? &bank->palette.vbank1 : &bank->palette.vbank0; 335 449 } 336 450 337 - tic_flags* getBankFlags() 451 + tic_flags* getBankFlags(Studio* studio) 338 452 { 339 - return &impl.tic->cart.banks[impl.bank.index.sprites].flags; 453 + return &studio->tic->cart.banks[studio->bank.index.sprites].flags; 340 454 } 341 455 #endif 342 456 343 - void playSystemSfx(s32 id) 457 + void playSystemSfx(Studio* studio, s32 id) 344 458 { 345 - const tic_sample* effect = &impl.config->cart->bank0.sfx.samples.data[id]; 346 - tic_api_sfx(impl.tic, id, effect->note, effect->octave, -1, 0, MAX_VOLUME, MAX_VOLUME, effect->speed); 459 + const tic_sample* effect = &studio->config->cart->bank0.sfx.samples.data[id]; 460 + tic_api_sfx(studio->tic, id, effect->note, effect->octave, -1, 0, MAX_VOLUME, MAX_VOLUME, effect->speed); 347 461 } 348 462 349 463 static void md5(const void* voidData, s32 length, u8 digest[MD5_HASHSIZE]) ··· 464 578 return false; 465 579 } 466 580 467 - void showTooltip(const char* text) 581 + void showTooltip(Studio* studio, const char* text) 468 582 { 469 - strncpy(impl.tooltip.text, text, sizeof impl.tooltip.text - 1); 583 + strncpy(studio->tooltip.text, text, sizeof studio->tooltip.text - 1); 470 584 } 471 585 472 - static void drawExtrabar(tic_mem* tic) 586 + static void drawExtrabar(Studio* studio, tic_mem* tic) 473 587 { 474 588 enum {Size = 7}; 475 589 ··· 493 607 u8 bg = tic_color_white; 494 608 u8 fg = tic_color_light_grey; 495 609 496 - if(checkMousePos(&rect)) 610 + if(checkMousePos(studio, &rect)) 497 611 { 498 - setCursor(tic_cursor_hand); 612 + setCursor(studio, tic_cursor_hand); 499 613 500 614 fg = color; 501 - showTooltip(icon->tip); 615 + showTooltip(studio, icon->tip); 502 616 503 - if(checkMouseDown(&rect, tic_mouse_left)) 617 + if(checkMouseDown(studio, &rect, tic_mouse_left)) 504 618 { 505 619 bg = fg; 506 620 fg = tic_color_white; 507 621 } 508 - else if(checkMouseClick(&rect, tic_mouse_left)) 622 + else if(checkMouseClick(studio, &rect, tic_mouse_left)) 509 623 { 510 - setStudioEvent(icon->event); 624 + setStudioEvent(studio, icon->event); 511 625 } 512 626 } 513 627 514 628 tic_api_rect(tic, x, y, Size, Size, bg); 515 - drawBitIcon(icon->id, x, y, fg); 629 + drawBitIcon(studio, icon->id, x, y, fg); 516 630 517 631 x += Size; 518 632 color++; 519 633 } 520 634 } 521 635 522 - struct Sprite* getSpriteEditor() 636 + struct Sprite* getSpriteEditor(Studio* studio) 523 637 { 524 - return impl.banks.sprite[impl.bank.index.sprites]; 638 + return studio->banks.sprite[studio->bank.index.sprites]; 525 639 } 526 640 #endif 527 641 528 642 const StudioConfig* studio_config(Studio* studio) 529 643 { 530 - return &impl.config->data; 644 + return &studio->config->data; 531 645 } 532 646 533 - const StudioConfig* getConfig() 647 + const StudioConfig* getConfig(Studio* studio) 534 648 { 535 - return studio_config(&impl); 649 + return studio_config(studio); 536 650 } 537 651 538 - struct Start* getStartScreen() 652 + struct Start* getStartScreen(Studio* studio) 539 653 { 540 - return impl.start; 654 + return studio->start; 541 655 } 542 656 543 657 #if defined (TIC80_PRO) 544 658 545 - static void drawBankIcon(s32 x, s32 y) 659 + static void drawBankIcon(Studio* studio, s32 x, s32 y) 546 660 { 547 - tic_mem* tic = impl.tic; 661 + tic_mem* tic = studio->tic; 548 662 549 663 tic_rect rect = {x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT}; 550 664 ··· 552 666 EditorMode mode = 0; 553 667 554 668 for(s32 i = 0; i < COUNT_OF(BankModes); i++) 555 - if(BankModes[i] == impl.mode) 669 + if(BankModes[i] == studio->mode) 556 670 { 557 671 mode = i; 558 672 break; 559 673 } 560 674 561 - if(checkMousePos(&rect)) 675 + if(checkMousePos(studio, &rect)) 562 676 { 563 - setCursor(tic_cursor_hand); 677 + setCursor(studio, tic_cursor_hand); 564 678 565 679 over = true; 566 680 567 - showTooltip("SWITCH BANK"); 681 + showTooltip(studio, "SWITCH BANK"); 568 682 569 - if(checkMouseClick(&rect, tic_mouse_left)) 570 - impl.bank.show = !impl.bank.show; 683 + if(checkMouseClick(studio, &rect, tic_mouse_left)) 684 + studio->bank.show = !studio->bank.show; 571 685 } 572 686 573 - if(impl.bank.show) 687 + if(studio->bank.show) 574 688 { 575 - drawBitIcon(tic_icon_bank, x, y, tic_color_red); 689 + drawBitIcon(studio, tic_icon_bank, x, y, tic_color_red); 576 690 577 691 enum{Size = TOOLBAR_SIZE}; 578 692 ··· 581 695 tic_rect rect = {x + 2 + (i+1)*Size, 0, Size, Size}; 582 696 583 697 bool over = false; 584 - if(checkMousePos(&rect)) 698 + if(checkMousePos(studio, &rect)) 585 699 { 586 - setCursor(tic_cursor_hand); 700 + setCursor(studio, tic_cursor_hand); 587 701 over = true; 588 702 589 - if(checkMouseClick(&rect, tic_mouse_left)) 703 + if(checkMouseClick(studio, &rect, tic_mouse_left)) 590 704 { 591 - if(impl.bank.chained) 592 - memset(impl.bank.indexes, i, sizeof impl.bank.indexes); 593 - else impl.bank.indexes[mode] = i; 705 + if(studio->bank.chained) 706 + memset(studio->bank.indexes, i, sizeof studio->bank.indexes); 707 + else studio->bank.indexes[mode] = i; 594 708 } 595 709 } 596 710 597 - if(i == impl.bank.indexes[mode]) 711 + if(i == studio->bank.indexes[mode]) 598 712 tic_api_rect(tic, rect.x, rect.y, rect.w, rect.h, tic_color_red); 599 713 600 714 tic_api_print(tic, (char[]){'0' + i, '\0'}, rect.x+1, rect.y+1, 601 - i == impl.bank.indexes[mode] 715 + i == studio->bank.indexes[mode] 602 716 ? tic_color_white 603 717 : over 604 718 ? tic_color_red ··· 612 726 613 727 bool over = false; 614 728 615 - if(checkMousePos(&rect)) 729 + if(checkMousePos(studio, &rect)) 616 730 { 617 - setCursor(tic_cursor_hand); 731 + setCursor(studio, tic_cursor_hand); 618 732 619 733 over = true; 620 734 621 - if(checkMouseClick(&rect, tic_mouse_left)) 735 + if(checkMouseClick(studio, &rect, tic_mouse_left)) 622 736 { 623 - impl.bank.chained = !impl.bank.chained; 737 + studio->bank.chained = !studio->bank.chained; 624 738 625 - if(impl.bank.chained) 626 - memset(impl.bank.indexes, impl.bank.indexes[mode], sizeof impl.bank.indexes); 739 + if(studio->bank.chained) 740 + memset(studio->bank.indexes, studio->bank.indexes[mode], sizeof studio->bank.indexes); 627 741 } 628 742 } 629 743 630 - drawBitIcon(tic_icon_pin, rect.x, rect.y, impl.bank.chained ? tic_color_red : over ? tic_color_grey : tic_color_light_grey); 744 + drawBitIcon(studio, tic_icon_pin, rect.x, rect.y, studio->bank.chained ? tic_color_red : over ? tic_color_grey : tic_color_light_grey); 631 745 } 632 746 } 633 747 else 634 748 { 635 - drawBitIcon(tic_icon_bank, x, y, over ? tic_color_red : tic_color_light_grey); 749 + drawBitIcon(studio, tic_icon_bank, x, y, over ? tic_color_red : tic_color_light_grey); 636 750 } 637 751 } 638 752 ··· 813 927 814 928 #if defined(BUILD_EDITORS) 815 929 816 - static void drawPopup() 930 + static void drawPopup(Studio* studio) 817 931 { 818 - if(impl.anim.movie != &impl.anim.idle) 932 + if(studio->anim.movie != &studio->anim.idle) 819 933 { 820 934 enum{Width = TIC80_WIDTH, Height = TIC_FONT_HEIGHT + 1}; 821 935 822 - tic_api_rect(impl.tic, 0, impl.anim.pos.popup, Width, Height, tic_color_red); 823 - tic_api_print(impl.tic, impl.popup.message, 824 - (s32)(Width - strlen(impl.popup.message) * TIC_FONT_WIDTH)/2, 825 - impl.anim.pos.popup + 1, tic_color_white, true, 1, false); 936 + tic_api_rect(studio->tic, 0, studio->anim.pos.popup, Width, Height, tic_color_red); 937 + tic_api_print(studio->tic, studio->popup.message, 938 + (s32)(Width - strlen(studio->popup.message) * TIC_FONT_WIDTH)/2, 939 + studio->anim.pos.popup + 1, tic_color_white, true, 1, false); 826 940 827 941 // render popup message 828 942 { 829 - tic_mem* tic = impl.tic; 830 - const tic_bank* bank = &getConfig()->cart->bank0; 943 + tic_mem* tic = studio->tic; 944 + const tic_bank* bank = &getConfig(studio)->cart->bank0; 831 945 u32* dst = tic->product.screen + TIC80_MARGIN_LEFT + TIC80_MARGIN_TOP * TIC80_FULLWIDTH; 832 946 833 - for(s32 i = 0, y = 0; y < (Height + impl.anim.pos.popup); y++, dst += TIC80_MARGIN_RIGHT + TIC80_MARGIN_LEFT) 947 + for(s32 i = 0, y = 0; y < (Height + studio->anim.pos.popup); y++, dst += TIC80_MARGIN_RIGHT + TIC80_MARGIN_LEFT) 834 948 for(s32 x = 0; x < Width; x++) 835 949 *dst++ = tic_rgba(&bank->palette.vbank0.colors[tic_tool_peek4(tic->ram.vram.screen.data, i++)]); 836 950 } 837 951 } 838 952 } 839 953 840 - void drawToolbar(tic_mem* tic, bool bg) 954 + void drawToolbar(Studio* studio, tic_mem* tic, bool bg) 841 955 { 842 956 if(bg) 843 957 tic_api_rect(tic, 0, 0, TIC80_WIDTH, TOOLBAR_SIZE, tic_color_white); ··· 855 969 856 970 bool over = false; 857 971 858 - if(checkMousePos(&rect)) 972 + if(checkMousePos(studio, &rect)) 859 973 { 860 - setCursor(tic_cursor_hand); 974 + setCursor(studio, tic_cursor_hand); 861 975 862 976 over = true; 863 977 864 - showTooltip(Tips[i]); 978 + showTooltip(studio, Tips[i]); 865 979 866 - if(checkMouseClick(&rect, tic_mouse_left)) 867 - impl.toolbarMode = Modes[i]; 980 + if(checkMouseClick(studio, &rect, tic_mouse_left)) 981 + studio->toolbarMode = Modes[i]; 868 982 } 869 983 870 - if(getStudioMode() == Modes[i]) mode = i; 984 + if(getStudioMode(studio) == Modes[i]) mode = i; 871 985 872 986 if (mode == i) 873 987 { 874 - drawBitIcon(tic_icon_tab, i * Size, 0, tic_color_grey); 875 - drawBitIcon(Icons[i], i * Size, 1, tic_color_black); 988 + drawBitIcon(studio, tic_icon_tab, i * Size, 0, tic_color_grey); 989 + drawBitIcon(studio, Icons[i], i * Size, 1, tic_color_black); 876 990 } 877 991 878 - drawBitIcon(Icons[i], i * Size, 0, mode == i ? tic_color_white : (over ? tic_color_grey : tic_color_light_grey)); 992 + drawBitIcon(studio, Icons[i], i * Size, 0, mode == i ? tic_color_white : (over ? tic_color_grey : tic_color_light_grey)); 879 993 } 880 994 881 - if(mode >= 0) drawExtrabar(tic); 995 + if(mode >= 0) drawExtrabar(studio, tic); 882 996 883 997 static const char* Names[] = 884 998 { ··· 892 1006 #if defined (TIC80_PRO) 893 1007 enum {TextOffset = (COUNT_OF(Modes) + 2) * Size - 2}; 894 1008 if(mode >= 1) 895 - drawBankIcon(COUNT_OF(Modes) * Size + 2, 0); 1009 + drawBankIcon(studio, COUNT_OF(Modes) * Size + 2, 0); 896 1010 #else 897 1011 enum {TextOffset = (COUNT_OF(Modes) + 1) * Size}; 898 1012 #endif 899 1013 900 - if(mode == 0 || (mode >= 1 && !impl.bank.show)) 1014 + if(mode == 0 || (mode >= 1 && !studio->bank.show)) 901 1015 { 902 - if(strlen(impl.tooltip.text)) 1016 + if(strlen(studio->tooltip.text)) 903 1017 { 904 - tic_api_print(tic, impl.tooltip.text, TextOffset, 1, tic_color_dark_grey, false, 1, false); 1018 + tic_api_print(tic, studio->tooltip.text, TextOffset, 1, tic_color_dark_grey, false, 1, false); 905 1019 } 906 1020 else 907 1021 { ··· 910 1024 } 911 1025 } 912 1026 913 - void setStudioEvent(StudioEvent event) 1027 + void setStudioEvent(Studio* studio, StudioEvent event) 914 1028 { 915 - switch(impl.mode) 1029 + switch(studio->mode) 916 1030 { 917 1031 case TIC_CODE_MODE: 918 1032 { 919 - Code* code = impl.code; 1033 + Code* code = studio->code; 920 1034 code->event(code, event); 921 1035 } 922 1036 break; 923 1037 case TIC_SPRITE_MODE: 924 1038 { 925 - Sprite* sprite = impl.banks.sprite[impl.bank.index.sprites]; 1039 + Sprite* sprite = studio->banks.sprite[studio->bank.index.sprites]; 926 1040 sprite->event(sprite, event); 927 1041 } 928 1042 break; 929 1043 case TIC_MAP_MODE: 930 1044 { 931 - Map* map = impl.banks.map[impl.bank.index.map]; 1045 + Map* map = studio->banks.map[studio->bank.index.map]; 932 1046 map->event(map, event); 933 1047 } 934 1048 break; 935 1049 case TIC_SFX_MODE: 936 1050 { 937 - Sfx* sfx = impl.banks.sfx[impl.bank.index.sfx]; 1051 + Sfx* sfx = studio->banks.sfx[studio->bank.index.sfx]; 938 1052 sfx->event(sfx, event); 939 1053 } 940 1054 break; 941 1055 case TIC_MUSIC_MODE: 942 1056 { 943 - Music* music = impl.banks.music[impl.bank.index.music]; 1057 + Music* music = studio->banks.music[studio->bank.index.music]; 944 1058 music->event(music, event); 945 1059 } 946 1060 break; ··· 948 1062 } 949 1063 } 950 1064 951 - ClipboardEvent getClipboardEvent() 1065 + ClipboardEvent getClipboardEvent(Studio* studio) 952 1066 { 953 - tic_mem* tic = impl.tic; 1067 + tic_mem* tic = studio->tic; 954 1068 955 1069 bool shift = tic_api_key(tic, tic_key_shift); 956 1070 bool ctrl = tic_api_key(tic, tic_key_ctrl); 957 1071 958 1072 if(ctrl) 959 1073 { 960 - if(keyWasPressed(tic_key_insert) || keyWasPressed(tic_key_c)) return TIC_CLIPBOARD_COPY; 961 - else if(keyWasPressed(tic_key_x)) return TIC_CLIPBOARD_CUT; 962 - else if(keyWasPressed(tic_key_v)) return TIC_CLIPBOARD_PASTE; 1074 + if(keyWasPressed(studio, tic_key_insert) || keyWasPressed(studio, tic_key_c)) return TIC_CLIPBOARD_COPY; 1075 + else if(keyWasPressed(studio, tic_key_x)) return TIC_CLIPBOARD_CUT; 1076 + else if(keyWasPressed(studio, tic_key_v)) return TIC_CLIPBOARD_PASTE; 963 1077 } 964 1078 else if(shift) 965 1079 { 966 - if(keyWasPressed(tic_key_delete)) return TIC_CLIPBOARD_CUT; 967 - else if(keyWasPressed(tic_key_insert)) return TIC_CLIPBOARD_PASTE; 1080 + if(keyWasPressed(studio, tic_key_delete)) return TIC_CLIPBOARD_CUT; 1081 + else if(keyWasPressed(studio, tic_key_insert)) return TIC_CLIPBOARD_PASTE; 968 1082 } 969 1083 970 1084 return TIC_CLIPBOARD_NONE; 971 1085 } 972 1086 973 - static void showPopupMessage(const char* text) 1087 + static void showPopupMessage(Studio* studio, const char* text) 974 1088 { 975 - memset(impl.popup.message, '\0', sizeof impl.popup.message); 976 - strncpy(impl.popup.message, text, sizeof(impl.popup.message) - 1); 1089 + memset(studio->popup.message, '\0', sizeof studio->popup.message); 1090 + strncpy(studio->popup.message, text, sizeof(studio->popup.message) - 1); 977 1091 978 - for(char* c = impl.popup.message; c < impl.popup.message + sizeof impl.popup.message; c++) 1092 + for(char* c = studio->popup.message; c < studio->popup.message + sizeof studio->popup.message; c++) 979 1093 if(*c) *c = toupper(*c); 980 1094 981 - impl.anim.movie = resetMovie(&impl.anim.show); 1095 + studio->anim.movie = resetMovie(&studio->anim.show); 982 1096 } 983 1097 #endif 984 1098 985 - static void exitConfirm(bool yes, void* data) 1099 + static void exitConfirm(Studio* studio, bool yes, void* data) 986 1100 { 987 - impl.alive = yes; 1101 + studio->alive = yes; 988 1102 } 989 1103 990 1104 void studio_exit(Studio* studio) 991 1105 { 992 1106 #if defined(BUILD_EDITORS) 993 - if(impl.mode != TIC_START_MODE && studioCartChanged()) 1107 + if(studio->mode != TIC_START_MODE && studioCartChanged(studio)) 994 1108 { 995 1109 static const char* Rows[] = 996 1110 { ··· 999 1113 "Do you really want to exit?", 1000 1114 }; 1001 1115 1002 - confirmDialog(Rows, COUNT_OF(Rows), exitConfirm, NULL); 1116 + confirmDialog(studio, Rows, COUNT_OF(Rows), exitConfirm, NULL); 1003 1117 } 1004 1118 else 1005 1119 #endif 1006 - exitConfirm(true, NULL); 1120 + exitConfirm(studio, true, NULL); 1007 1121 } 1008 1122 1009 - void exitStudio() 1123 + void exitStudio(Studio* studio) 1010 1124 { 1011 - studio_exit(&impl); 1125 + studio_exit(studio); 1012 1126 } 1013 1127 1014 - void drawBitIcon(s32 id, s32 x, s32 y, u8 color) 1128 + void drawBitIcon(Studio* studio, s32 id, s32 x, s32 y, u8 color) 1015 1129 { 1016 - tic_mem* tic = impl.tic; 1130 + tic_mem* tic = studio->tic; 1017 1131 1018 - const tic_tile* tile = &getConfig()->cart->bank0.tiles.data[id]; 1132 + const tic_tile* tile = &getConfig(studio)->cart->bank0.tiles.data[id]; 1019 1133 1020 1134 for(s32 i = 0, sx = x, ex = sx + TIC_SPRITESIZE; i != TIC_SPRITESIZE * TIC_SPRITESIZE; ++i, ++x) 1021 1135 { ··· 1030 1144 } 1031 1145 } 1032 1146 1033 - static void initRunMode() 1147 + static void initRunMode(Studio* studio) 1034 1148 { 1035 - initRun(impl.run, 1149 + initRun(studio->run, 1036 1150 #if defined(BUILD_EDITORS) 1037 - impl.console, 1151 + studio->console, 1038 1152 #else 1039 1153 NULL, 1040 1154 #endif 1041 - impl.fs, impl.tic); 1155 + studio->fs, studio); 1042 1156 } 1043 1157 1044 1158 #if defined(BUILD_EDITORS) 1045 - static void initWorldMap() 1159 + static void initWorldMap(Studio* studio) 1046 1160 { 1047 - initWorld(impl.world, impl.tic, impl.banks.map[impl.bank.index.map]); 1161 + initWorld(studio->world, studio, studio->banks.map[studio->bank.index.map]); 1048 1162 } 1049 1163 1050 - static void initSurfMode() 1164 + static void initSurfMode(Studio* studio) 1051 1165 { 1052 - initSurf(impl.surf, impl.tic, impl.console); 1166 + initSurf(studio->surf, studio, studio->console); 1053 1167 } 1054 1168 1055 - void gotoSurf() 1169 + void gotoSurf(Studio* studio) 1056 1170 { 1057 - initSurfMode(); 1058 - setStudioMode(TIC_SURF_MODE); 1171 + initSurfMode(studio); 1172 + setStudioMode(studio, TIC_SURF_MODE); 1059 1173 } 1060 1174 1061 - void gotoCode() 1175 + void gotoCode(Studio* studio) 1062 1176 { 1063 - setStudioMode(TIC_CODE_MODE); 1177 + setStudioMode(studio, TIC_CODE_MODE); 1064 1178 } 1065 1179 1066 1180 #endif 1067 1181 1068 - void setStudioMode(EditorMode mode) 1182 + void setStudioMode(Studio* studio, EditorMode mode) 1069 1183 { 1070 - if(mode != impl.mode) 1184 + if(mode != studio->mode) 1071 1185 { 1072 - EditorMode prev = impl.mode; 1186 + EditorMode prev = studio->mode; 1073 1187 1074 1188 if(prev == TIC_RUN_MODE) 1075 - tic_core_pause(impl.tic); 1189 + tic_core_pause(studio->tic); 1076 1190 1077 1191 if(mode != TIC_RUN_MODE) 1078 - tic_api_reset(impl.tic); 1192 + tic_api_reset(studio->tic); 1079 1193 1080 1194 switch (prev) 1081 1195 { ··· 1083 1197 case TIC_CONSOLE_MODE: 1084 1198 case TIC_MENU_MODE: 1085 1199 break; 1086 - default: impl.prevMode = prev; break; 1200 + default: studio->prevMode = prev; break; 1087 1201 } 1088 1202 1089 1203 #if defined(BUILD_EDITORS) 1090 1204 switch(mode) 1091 1205 { 1092 - case TIC_RUN_MODE: initRunMode(); break; 1206 + case TIC_RUN_MODE: initRunMode(studio); break; 1093 1207 case TIC_CONSOLE_MODE: 1094 1208 if (prev == TIC_SURF_MODE) 1095 - impl.console->done(impl.console); 1209 + studio->console->done(studio->console); 1096 1210 break; 1097 - case TIC_WORLD_MODE: initWorldMap(); break; 1098 - case TIC_SURF_MODE: impl.surf->resume(impl.surf); break; 1211 + case TIC_WORLD_MODE: initWorldMap(studio); break; 1212 + case TIC_SURF_MODE: studio->surf->resume(studio->surf); break; 1099 1213 default: break; 1100 1214 } 1101 1215 1102 - impl.mode = mode; 1216 + studio->mode = mode; 1103 1217 #else 1104 1218 switch (mode) 1105 1219 { 1106 1220 case TIC_START_MODE: 1107 1221 case TIC_MENU_MODE: 1108 - impl.mode = mode; 1222 + studio->mode = mode; 1109 1223 break; 1110 1224 default: 1111 - impl.mode = TIC_RUN_MODE; 1225 + studio->mode = TIC_RUN_MODE; 1112 1226 } 1113 1227 #endif 1114 1228 } 1115 1229 } 1116 1230 1117 - EditorMode getStudioMode() 1231 + EditorMode getStudioMode(Studio* studio) 1118 1232 { 1119 - return impl.mode; 1233 + return studio->mode; 1120 1234 } 1121 1235 1122 1236 #if defined(BUILD_EDITORS) 1123 - static void changeStudioMode(s32 dir) 1237 + static void changeStudioMode(Studio* studio, s32 dir) 1124 1238 { 1125 1239 for(size_t i = 0; i < COUNT_OF(Modes); i++) 1126 1240 { 1127 - if(impl.mode == Modes[i]) 1241 + if(studio->mode == Modes[i]) 1128 1242 { 1129 - setStudioMode(Modes[(i+dir+ COUNT_OF(Modes)) % COUNT_OF(Modes)]); 1243 + setStudioMode(studio, Modes[(i+dir+ COUNT_OF(Modes)) % COUNT_OF(Modes)]); 1130 1244 return; 1131 1245 } 1132 1246 } 1133 1247 } 1134 1248 #endif 1135 1249 1136 - void resumeGame() 1250 + void resumeGame(Studio* studio) 1137 1251 { 1138 - tic_core_resume(impl.tic); 1139 - impl.mode = TIC_RUN_MODE; 1252 + tic_core_resume(studio->tic); 1253 + studio->mode = TIC_RUN_MODE; 1140 1254 } 1141 1255 1142 1256 static inline bool pointInRect(const tic_point* pt, const tic_rect* rect) ··· 1147 1261 && (pt->y < (rect->y + rect->h)); 1148 1262 } 1149 1263 1150 - bool checkMousePos(const tic_rect* rect) 1264 + bool checkMousePos(Studio* studio, const tic_rect* rect) 1151 1265 { 1152 - tic_point pos = tic_api_mouse(impl.tic); 1266 + tic_point pos = tic_api_mouse(studio->tic); 1153 1267 return pointInRect(&pos, rect); 1154 1268 } 1155 1269 1156 - bool checkMouseClick(const tic_rect* rect, tic_mouse_btn button) 1270 + bool checkMouseClick(Studio* studio, const tic_rect* rect, tic_mouse_btn button) 1157 1271 { 1158 - MouseState* state = &impl.mouse.state[button]; 1272 + MouseState* state = &studio->mouse.state[button]; 1159 1273 1160 1274 bool value = state->click 1161 1275 && pointInRect(&state->start, rect) ··· 1166 1280 return value; 1167 1281 } 1168 1282 1169 - bool checkMouseDown(const tic_rect* rect, tic_mouse_btn button) 1283 + bool checkMouseDown(Studio* studio, const tic_rect* rect, tic_mouse_btn button) 1170 1284 { 1171 - MouseState* state = &impl.mouse.state[button]; 1285 + MouseState* state = &studio->mouse.state[button]; 1172 1286 1173 1287 return state->down && pointInRect(&state->start, rect); 1174 1288 } 1175 1289 1176 - void setCursor(tic_cursor id) 1290 + void setCursor(Studio* studio, tic_cursor id) 1177 1291 { 1178 - tic_mem* tic = impl.tic; 1292 + tic_mem* tic = studio->tic; 1179 1293 1180 1294 VBANK(tic, 0) 1181 1295 { ··· 1187 1301 1188 1302 typedef struct 1189 1303 { 1304 + Studio* studio; 1190 1305 ConfirmCallback callback; 1191 1306 void* data; 1192 1307 } ConfirmData; 1193 1308 1194 1309 static void confirmHandler(bool yes, void* data) 1195 1310 { 1196 - if(impl.menuMode == TIC_RUN_MODE) 1197 - { 1198 - tic_core_resume(impl.tic); 1199 - impl.mode = TIC_RUN_MODE; 1200 - } 1201 - else setStudioMode(impl.menuMode); 1202 - 1203 1311 ConfirmData* confirmData = data; 1204 1312 SCOPE(free(confirmData)) 1205 1313 { 1206 - confirmData->callback(yes, confirmData->data); 1314 + Studio* studio = confirmData->studio; 1315 + 1316 + if(studio->menuMode == TIC_RUN_MODE) 1317 + { 1318 + tic_core_resume(studio->tic); 1319 + studio->mode = TIC_RUN_MODE; 1320 + } 1321 + else setStudioMode(studio, studio->menuMode); 1322 + 1323 + confirmData->callback(studio, yes, confirmData->data); 1207 1324 } 1208 1325 } 1209 1326 ··· 1217 1334 confirmHandler(true, data); 1218 1335 } 1219 1336 1220 - void confirmDialog(const char** text, s32 rows, ConfirmCallback callback, void* data) 1337 + void confirmDialog(Studio* studio, const char** text, s32 rows, ConfirmCallback callback, void* data) 1221 1338 { 1222 - if(impl.mode != TIC_MENU_MODE) 1339 + if(studio->mode != TIC_MENU_MODE) 1223 1340 { 1224 - impl.menuMode = impl.mode; 1225 - impl.mode = TIC_MENU_MODE; 1341 + studio->menuMode = studio->mode; 1342 + studio->mode = TIC_MENU_MODE; 1226 1343 } 1227 1344 1228 1345 static const MenuItem Answers[] = ··· 1241 1358 1242 1359 memcpy(items + rows, Answers, sizeof Answers); 1243 1360 1244 - studio_menu_init(impl.menu, items, count, count - 2, 0, 1245 - NULL, MOVE((ConfirmData){callback, data})); 1361 + studio_menu_init(studio->menu, items, count, count - 2, 0, 1362 + NULL, MOVE((ConfirmData){studio, callback, data})); 1246 1363 1247 - playSystemSfx(0); 1364 + playSystemSfx(studio, 0); 1248 1365 } 1249 1366 } 1250 1367 1251 - static void resetBanks() 1368 + static void resetBanks(Studio* studio) 1252 1369 { 1253 - memset(impl.bank.indexes, 0, sizeof impl.bank.indexes); 1370 + memset(studio->bank.indexes, 0, sizeof studio->bank.indexes); 1254 1371 } 1255 1372 1256 - static void initModules() 1373 + static void initModules(Studio* studio) 1257 1374 { 1258 - tic_mem* tic = impl.tic; 1375 + tic_mem* tic = studio->tic; 1259 1376 1260 - resetBanks(); 1377 + resetBanks(studio); 1261 1378 1262 - initCode(impl.code, impl.tic, &tic->cart.code); 1379 + initCode(studio->code, studio, &tic->cart.code); 1263 1380 1264 1381 for(s32 i = 0; i < TIC_EDITOR_BANKS; i++) 1265 1382 { 1266 - initSprite(impl.banks.sprite[i], impl.tic, &tic->cart.banks[i].tiles); 1267 - initMap(impl.banks.map[i], impl.tic, &tic->cart.banks[i].map); 1268 - initSfx(impl.banks.sfx[i], impl.tic, &tic->cart.banks[i].sfx); 1269 - initMusic(impl.banks.music[i], impl.tic, &tic->cart.banks[i].music); 1383 + initSprite(studio->banks.sprite[i], studio, &tic->cart.banks[i].tiles); 1384 + initMap(studio->banks.map[i], studio, &tic->cart.banks[i].map); 1385 + initSfx(studio->banks.sfx[i], studio, &tic->cart.banks[i].sfx); 1386 + initMusic(studio->banks.music[i], studio, &tic->cart.banks[i].music); 1270 1387 } 1271 1388 1272 - initWorldMap(); 1389 + initWorldMap(studio); 1273 1390 } 1274 1391 1275 - static void updateHash() 1392 + static void updateHash(Studio* studio) 1276 1393 { 1277 - md5(&impl.tic->cart, sizeof(tic_cartridge), impl.cart.hash.data); 1394 + md5(&studio->tic->cart, sizeof(tic_cartridge), studio->cart.hash.data); 1278 1395 } 1279 1396 1280 - static void updateMDate() 1397 + static void updateMDate(Studio* studio) 1281 1398 { 1282 - impl.cart.mdate = fs_date(impl.console->rom.path); 1399 + studio->cart.mdate = fs_date(studio->console->rom.path); 1283 1400 } 1284 1401 #endif 1285 1402 1286 - static void updateTitle() 1403 + static void updateTitle(Studio* studio) 1287 1404 { 1288 1405 char name[TICNAME_MAX] = TIC_TITLE; 1289 1406 1290 1407 #if defined(BUILD_EDITORS) 1291 - if(strlen(impl.console->rom.name)) 1292 - snprintf(name, TICNAME_MAX, "%s [%s]", TIC_TITLE, impl.console->rom.name); 1408 + if(strlen(studio->console->rom.name)) 1409 + snprintf(name, TICNAME_MAX, "%s [%s]", TIC_TITLE, studio->console->rom.name); 1293 1410 #endif 1294 1411 1295 1412 tic_sys_title(name); ··· 1320 1437 return NULL; 1321 1438 } 1322 1439 1323 - void studioRomSaved() 1440 + void studioRomSaved(Studio* studio) 1324 1441 { 1325 - updateTitle(); 1326 - updateHash(); 1327 - updateMDate(); 1442 + updateTitle(studio); 1443 + updateHash(studio); 1444 + updateMDate(studio); 1328 1445 } 1329 1446 1330 - void studioRomLoaded() 1447 + void studioRomLoaded(Studio* studio) 1331 1448 { 1332 - initModules(); 1449 + initModules(studio); 1333 1450 1334 - updateTitle(); 1335 - updateHash(); 1336 - updateMDate(); 1451 + updateTitle(studio); 1452 + updateHash(studio); 1453 + updateMDate(studio); 1337 1454 } 1338 1455 1339 - bool studioCartChanged() 1456 + bool studioCartChanged(Studio* studio) 1340 1457 { 1341 1458 CartHash hash; 1342 - md5(&impl.tic->cart, sizeof(tic_cartridge), hash.data); 1459 + md5(&studio->tic->cart, sizeof(tic_cartridge), hash.data); 1343 1460 1344 - return memcmp(hash.data, impl.cart.hash.data, sizeof(CartHash)) != 0; 1461 + return memcmp(hash.data, studio->cart.hash.data, sizeof(CartHash)) != 0; 1345 1462 } 1346 1463 #endif 1347 1464 1348 - void runGame() 1465 + void runGame(Studio* studio) 1349 1466 { 1350 1467 #if defined(BUILD_EDITORS) 1351 - if(impl.console->args.keepcmd 1352 - && impl.console->commands.count 1353 - && impl.console->commands.current >= impl.console->commands.count) 1468 + if(studio->console->args.keepcmd 1469 + && studio->console->commands.count 1470 + && studio->console->commands.current >= studio->console->commands.count) 1354 1471 { 1355 - impl.console->commands.current = 0; 1356 - setStudioMode(TIC_CONSOLE_MODE); 1472 + studio->console->commands.current = 0; 1473 + setStudioMode(studio, TIC_CONSOLE_MODE); 1357 1474 } 1358 1475 else 1359 1476 #endif 1360 1477 { 1361 - tic_api_reset(impl.tic); 1478 + tic_api_reset(studio->tic); 1362 1479 1363 - if(impl.mode == TIC_RUN_MODE) 1480 + if(studio->mode == TIC_RUN_MODE) 1364 1481 { 1365 - initRunMode(); 1482 + initRunMode(studio); 1366 1483 return; 1367 1484 } 1368 1485 1369 - setStudioMode(TIC_RUN_MODE); 1486 + setStudioMode(studio, TIC_RUN_MODE); 1370 1487 1371 1488 #if defined(BUILD_EDITORS) 1372 - if(impl.mode == TIC_SURF_MODE) 1373 - impl.prevMode = TIC_SURF_MODE; 1489 + if(studio->mode == TIC_SURF_MODE) 1490 + studio->prevMode = TIC_SURF_MODE; 1374 1491 #endif 1375 1492 } 1376 1493 } 1377 1494 1378 1495 #if defined(BUILD_EDITORS) 1379 - static void saveProject() 1496 + static void saveProject(Studio* studio) 1380 1497 { 1381 - CartSaveResult rom = impl.console->save(impl.console); 1498 + CartSaveResult rom = studio->console->save(studio->console); 1382 1499 1383 1500 if(rom == CART_SAVE_OK) 1384 1501 { 1385 1502 char buffer[STUDIO_TEXT_BUFFER_WIDTH]; 1386 1503 char str_saved[] = " saved :)"; 1387 1504 1388 - s32 name_len = (s32)strlen(impl.console->rom.name); 1505 + s32 name_len = (s32)strlen(studio->console->rom.name); 1389 1506 if (name_len + strlen(str_saved) > sizeof(buffer)){ 1390 1507 char subbuf[sizeof(buffer) - sizeof(str_saved) - 5]; 1391 1508 memset(subbuf, '\0', sizeof subbuf); 1392 - strncpy(subbuf, impl.console->rom.name, sizeof subbuf-1); 1509 + strncpy(subbuf, studio->console->rom.name, sizeof subbuf-1); 1393 1510 1394 1511 snprintf(buffer, sizeof buffer, "%s[...]%s", subbuf, str_saved); 1395 1512 } 1396 1513 else 1397 1514 { 1398 - snprintf(buffer, sizeof buffer, "%s%s", impl.console->rom.name, str_saved); 1515 + snprintf(buffer, sizeof buffer, "%s%s", studio->console->rom.name, str_saved); 1399 1516 } 1400 1517 1401 - showPopupMessage(buffer); 1518 + showPopupMessage(studio, buffer); 1402 1519 } 1403 - else if(rom == CART_SAVE_MISSING_NAME) showPopupMessage("error: missing cart name :("); 1404 - else showPopupMessage("error: file not saved :("); 1520 + else if(rom == CART_SAVE_MISSING_NAME) showPopupMessage(studio, "error: missing cart name :("); 1521 + else showPopupMessage(studio, "error: file not saved :("); 1405 1522 } 1406 1523 1407 1524 static void screen2buffer(u32* buffer, const u32* pixels, const tic_rect* rect) ··· 1416 1533 } 1417 1534 } 1418 1535 1419 - static void setCoverImage() 1536 + static void setCoverImage(Studio* studio) 1420 1537 { 1421 - tic_mem* tic = impl.tic; 1538 + tic_mem* tic = studio->tic; 1422 1539 1423 - if(impl.mode == TIC_RUN_MODE) 1540 + if(studio->mode == TIC_RUN_MODE) 1424 1541 { 1425 1542 tic_api_sync(tic, tic_sync_screen, 0, true); 1426 - showPopupMessage("cover image saved :)"); 1543 + showPopupMessage(studio, "cover image saved :)"); 1427 1544 } 1428 1545 } 1429 1546 1430 - static void stopVideoRecord(const char* name) 1547 + static void stopVideoRecord(Studio* studio, const char* name) 1431 1548 { 1432 - if(impl.video.buffer) 1549 + if(studio->video.buffer) 1433 1550 { 1434 1551 { 1435 1552 s32 size = 0; 1436 - u8* data = malloc(FRAME_SIZE * impl.video.frame); 1553 + u8* data = malloc(FRAME_SIZE * studio->video.frame); 1437 1554 s32 i = 0; 1438 1555 char filename[TICNAME_MAX]; 1439 1556 1440 - gif_write_animation(data, &size, TIC80_FULLWIDTH, TIC80_FULLHEIGHT, (const u8*)impl.video.buffer, impl.video.frame, TIC80_FRAMERATE, getConfig()->gifScale); 1557 + gif_write_animation(data, &size, TIC80_FULLWIDTH, TIC80_FULLHEIGHT, (const u8*)studio->video.buffer, studio->video.frame, TIC80_FRAMERATE, getConfig(studio)->gifScale); 1441 1558 1442 1559 // Find an available filename to save. 1443 1560 do 1444 1561 { 1445 1562 snprintf(filename, sizeof filename, name, ++i); 1446 1563 } 1447 - while(tic_fs_exists(impl.fs, filename)); 1564 + while(tic_fs_exists(studio->fs, filename)); 1448 1565 1449 1566 // Now that it has found an available filename, save it. 1450 - if(tic_fs_save(impl.fs, filename, data, size, true)) 1567 + if(tic_fs_save(studio->fs, filename, data, size, true)) 1451 1568 { 1452 1569 char msg[TICNAME_MAX]; 1453 1570 sprintf(msg, "%s saved :)", filename); 1454 - showPopupMessage(msg); 1571 + showPopupMessage(studio, msg); 1455 1572 1456 - tic_sys_open_path(tic_fs_path(impl.fs, filename)); 1573 + tic_sys_open_path(tic_fs_path(studio->fs, filename)); 1457 1574 } 1458 - else showPopupMessage("error: file not saved :("); 1575 + else showPopupMessage(studio, "error: file not saved :("); 1459 1576 } 1460 1577 1461 - free(impl.video.buffer); 1462 - impl.video.buffer = NULL; 1578 + free(studio->video.buffer); 1579 + studio->video.buffer = NULL; 1463 1580 } 1464 1581 1465 - impl.video.record = false; 1582 + studio->video.record = false; 1466 1583 } 1467 1584 1468 - static void startVideoRecord() 1585 + static void startVideoRecord(Studio* studio) 1469 1586 { 1470 - if(impl.video.record) 1587 + if(studio->video.record) 1471 1588 { 1472 - stopVideoRecord(VideoGif); 1589 + stopVideoRecord(studio, VideoGif); 1473 1590 } 1474 1591 else 1475 1592 { 1476 - impl.video.frames = getConfig()->gifLength * TIC80_FRAMERATE; 1477 - impl.video.buffer = malloc(FRAME_SIZE * impl.video.frames); 1593 + studio->video.frames = getConfig(studio)->gifLength * TIC80_FRAMERATE; 1594 + studio->video.buffer = malloc(FRAME_SIZE * studio->video.frames); 1478 1595 1479 - if(impl.video.buffer) 1596 + if(studio->video.buffer) 1480 1597 { 1481 - impl.video.record = true; 1482 - impl.video.frame = 0; 1598 + studio->video.record = true; 1599 + studio->video.frame = 0; 1483 1600 } 1484 1601 } 1485 1602 } 1486 1603 1487 - static void takeScreenshot() 1604 + static void takeScreenshot(Studio* studio) 1488 1605 { 1489 - impl.video.frames = 1; 1490 - impl.video.buffer = malloc(FRAME_SIZE); 1606 + studio->video.frames = 1; 1607 + studio->video.buffer = malloc(FRAME_SIZE); 1491 1608 1492 - if(impl.video.buffer) 1609 + if(studio->video.buffer) 1493 1610 { 1494 - impl.video.record = true; 1495 - impl.video.frame = 0; 1611 + studio->video.record = true; 1612 + studio->video.frame = 0; 1496 1613 } 1497 1614 } 1498 1615 #endif 1499 1616 1500 - static inline bool keyWasPressedOnce(s32 key) 1617 + static inline bool keyWasPressedOnce(Studio* studio, s32 key) 1501 1618 { 1502 - tic_mem* tic = impl.tic; 1619 + tic_mem* tic = studio->tic; 1503 1620 1504 1621 return tic_api_keyp(tic, key, -1, -1); 1505 1622 } 1506 1623 1507 1624 #if defined(CRT_SHADER_SUPPORT) 1508 - static void switchCrtMonitor() 1625 + static void switchCrtMonitor(Studio* studio) 1509 1626 { 1510 - impl.config->data.options.crt = !impl.config->data.options.crt; 1627 + studio->config->data.options.crt = !studio->config->data.options.crt; 1511 1628 } 1512 1629 #endif 1513 1630 1514 1631 #if defined(TIC80_PRO) 1515 1632 1516 - static void switchBank(s32 bank) 1633 + static void switchBank(Studio* studio, s32 bank) 1517 1634 { 1518 1635 for(s32 i = 0; i < COUNT_OF(BankModes); i++) 1519 - if(BankModes[i] == impl.mode) 1636 + if(BankModes[i] == studio->mode) 1520 1637 { 1521 - if(impl.bank.chained) 1522 - memset(impl.bank.indexes, bank, sizeof impl.bank.indexes); 1523 - else impl.bank.indexes[i] = bank; 1638 + if(studio->bank.chained) 1639 + memset(studio->bank.indexes, bank, sizeof studio->bank.indexes); 1640 + else studio->bank.indexes[i] = bank; 1524 1641 break; 1525 1642 } 1526 1643 } 1527 1644 1528 1645 #endif 1529 1646 1530 - void gotoMenu() 1647 + void gotoMenu(Studio* studio) 1531 1648 { 1532 - if(impl.mode != TIC_MENU_MODE) 1649 + if(studio->mode != TIC_MENU_MODE) 1533 1650 { 1534 - tic_core_pause(impl.tic); 1535 - tic_api_reset(impl.tic); 1536 - impl.mode = TIC_MENU_MODE; 1651 + tic_core_pause(studio->tic); 1652 + tic_api_reset(studio->tic); 1653 + studio->mode = TIC_MENU_MODE; 1537 1654 } 1538 1655 1539 - impl.mainmenu = studio_mainmenu_init(impl.menu, impl.config); 1656 + studio->mainmenu = studio_mainmenu_init(studio->menu, studio->config); 1540 1657 } 1541 1658 1542 - static void processShortcuts() 1659 + static void processShortcuts(Studio* studio) 1543 1660 { 1544 - tic_mem* tic = impl.tic; 1661 + tic_mem* tic = studio->tic; 1545 1662 1546 - if(impl.mode == TIC_START_MODE) return; 1663 + if(studio->mode == TIC_START_MODE) return; 1547 1664 1548 1665 #if defined(BUILD_EDITORS) 1549 - if(impl.mode == TIC_CONSOLE_MODE && !impl.console->active) return; 1666 + if(studio->mode == TIC_CONSOLE_MODE && !studio->console->active) return; 1550 1667 #endif 1551 1668 1552 - if(studio_mainmenu_keyboard(impl.mainmenu)) return; 1669 + if(studio_mainmenu_keyboard(studio->mainmenu)) return; 1553 1670 1554 1671 bool alt = tic_api_key(tic, tic_key_alt); 1555 1672 bool ctrl = tic_api_key(tic, tic_key_ctrl); 1556 1673 1557 1674 #if defined(CRT_SHADER_SUPPORT) 1558 - if(keyWasPressedOnce(tic_key_f6)) switchCrtMonitor(); 1675 + if(keyWasPressedOnce(studio, tic_key_f6)) switchCrtMonitor(studio); 1559 1676 #endif 1560 1677 1561 1678 if(alt) 1562 1679 { 1563 - if (keyWasPressedOnce(tic_key_return)) tic_sys_fullscreen_set(!tic_sys_fullscreen_get()); 1680 + if (keyWasPressedOnce(studio, tic_key_return)) tic_sys_fullscreen_set(!tic_sys_fullscreen_get()); 1564 1681 #if defined(BUILD_EDITORS) 1565 - else if(impl.mode != TIC_RUN_MODE) 1682 + else if(studio->mode != TIC_RUN_MODE) 1566 1683 { 1567 - if(keyWasPressedOnce(tic_key_grave)) setStudioMode(TIC_CONSOLE_MODE); 1568 - else if(keyWasPressedOnce(tic_key_1)) setStudioMode(TIC_CODE_MODE); 1569 - else if(keyWasPressedOnce(tic_key_2)) setStudioMode(TIC_SPRITE_MODE); 1570 - else if(keyWasPressedOnce(tic_key_3)) setStudioMode(TIC_MAP_MODE); 1571 - else if(keyWasPressedOnce(tic_key_4)) setStudioMode(TIC_SFX_MODE); 1572 - else if(keyWasPressedOnce(tic_key_5)) setStudioMode(TIC_MUSIC_MODE); 1684 + if(keyWasPressedOnce(studio, tic_key_grave)) setStudioMode(studio, TIC_CONSOLE_MODE); 1685 + else if(keyWasPressedOnce(studio, tic_key_1)) setStudioMode(studio, TIC_CODE_MODE); 1686 + else if(keyWasPressedOnce(studio, tic_key_2)) setStudioMode(studio, TIC_SPRITE_MODE); 1687 + else if(keyWasPressedOnce(studio, tic_key_3)) setStudioMode(studio, TIC_MAP_MODE); 1688 + else if(keyWasPressedOnce(studio, tic_key_4)) setStudioMode(studio, TIC_SFX_MODE); 1689 + else if(keyWasPressedOnce(studio, tic_key_5)) setStudioMode(studio, TIC_MUSIC_MODE); 1573 1690 } 1574 1691 #endif 1575 1692 } 1576 1693 else if(ctrl) 1577 1694 { 1578 - if(keyWasPressedOnce(tic_key_q)) studio_exit(&impl); 1695 + if(keyWasPressedOnce(studio, tic_key_q)) studio_exit(studio); 1579 1696 #if defined(BUILD_EDITORS) 1580 - else if(keyWasPressedOnce(tic_key_pageup)) changeStudioMode(-1); 1581 - else if(keyWasPressedOnce(tic_key_pagedown)) changeStudioMode(1); 1582 - else if(keyWasPressedOnce(tic_key_return)) runGame(); 1583 - else if(keyWasPressedOnce(tic_key_r)) runGame(); 1584 - else if(keyWasPressedOnce(tic_key_s)) saveProject(); 1697 + else if(keyWasPressedOnce(studio, tic_key_pageup)) changeStudioMode(studio, -1); 1698 + else if(keyWasPressedOnce(studio, tic_key_pagedown)) changeStudioMode(studio, +1); 1699 + else if(keyWasPressedOnce(studio, tic_key_return)) runGame(studio); 1700 + else if(keyWasPressedOnce(studio, tic_key_r)) runGame(studio); 1701 + else if(keyWasPressedOnce(studio, tic_key_s)) saveProject(studio); 1585 1702 #endif 1586 1703 1587 1704 #if defined(TIC80_PRO) 1588 1705 1589 1706 else 1590 1707 for(s32 bank = 0; bank < TIC_BANKS; bank++) 1591 - if(keyWasPressedOnce(tic_key_0 + bank)) 1592 - switchBank(bank); 1708 + if(keyWasPressedOnce(studio, tic_key_0 + bank)) 1709 + switchBank(studio, bank); 1593 1710 1594 1711 #endif 1595 1712 1596 1713 } 1597 1714 else 1598 1715 { 1599 - if (keyWasPressedOnce(tic_key_f11)) tic_sys_fullscreen_set(!tic_sys_fullscreen_get()); 1716 + if (keyWasPressedOnce(studio, tic_key_f11)) tic_sys_fullscreen_set(!tic_sys_fullscreen_get()); 1600 1717 #if defined(BUILD_EDITORS) 1601 - else if(keyWasPressedOnce(tic_key_escape)) 1718 + else if(keyWasPressedOnce(studio, tic_key_escape)) 1602 1719 { 1603 - switch(impl.mode) 1720 + switch(studio->mode) 1604 1721 { 1605 1722 case TIC_MENU_MODE: 1606 - getConfig()->options.devmode 1607 - ? setStudioMode(impl.prevMode) 1608 - : studio_menu_back(impl.menu); 1723 + getConfig(studio)->options.devmode 1724 + ? setStudioMode(studio, studio->prevMode) 1725 + : studio_menu_back(studio->menu); 1609 1726 break; 1610 1727 case TIC_RUN_MODE: 1611 - getConfig()->options.devmode 1612 - ? setStudioMode(impl.prevMode) 1613 - : gotoMenu(); 1728 + getConfig(studio)->options.devmode 1729 + ? setStudioMode(studio, studio->prevMode) 1730 + : gotoMenu(studio); 1614 1731 break; 1615 - case TIC_CONSOLE_MODE: setStudioMode(impl.prevMode); break; 1732 + case TIC_CONSOLE_MODE: setStudioMode(studio, studio->prevMode); break; 1616 1733 case TIC_CODE_MODE: 1617 - if(impl.code->mode != TEXT_EDIT_MODE) 1734 + if(studio->code->mode != TEXT_EDIT_MODE) 1618 1735 { 1619 - impl.code->escape(impl.code); 1736 + studio->code->escape(studio->code); 1620 1737 return; 1621 1738 } 1622 1739 default: 1623 - setStudioMode(TIC_CONSOLE_MODE); 1740 + setStudioMode(studio, TIC_CONSOLE_MODE); 1624 1741 } 1625 1742 } 1626 - else if(keyWasPressedOnce(tic_key_f8)) takeScreenshot(); 1627 - else if(keyWasPressedOnce(tic_key_f9)) startVideoRecord(); 1628 - else if(impl.mode == TIC_RUN_MODE && keyWasPressedOnce(tic_key_f7)) 1629 - setCoverImage(); 1743 + else if(keyWasPressedOnce(studio, tic_key_f8)) takeScreenshot(studio); 1744 + else if(keyWasPressedOnce(studio, tic_key_f9)) startVideoRecord(studio); 1745 + else if(studio->mode == TIC_RUN_MODE && keyWasPressedOnce(studio, tic_key_f7)) 1746 + setCoverImage(studio); 1630 1747 1631 - if(getConfig()->options.devmode || impl.mode != TIC_RUN_MODE) 1748 + if(getConfig(studio)->options.devmode || studio->mode != TIC_RUN_MODE) 1632 1749 { 1633 - if(keyWasPressedOnce(tic_key_f1)) setStudioMode(TIC_CODE_MODE); 1634 - else if(keyWasPressedOnce(tic_key_f2)) setStudioMode(TIC_SPRITE_MODE); 1635 - else if(keyWasPressedOnce(tic_key_f3)) setStudioMode(TIC_MAP_MODE); 1636 - else if(keyWasPressedOnce(tic_key_f4)) setStudioMode(TIC_SFX_MODE); 1637 - else if(keyWasPressedOnce(tic_key_f5)) setStudioMode(TIC_MUSIC_MODE); 1750 + if(keyWasPressedOnce(studio, tic_key_f1)) setStudioMode(studio, TIC_CODE_MODE); 1751 + else if(keyWasPressedOnce(studio, tic_key_f2)) setStudioMode(studio, TIC_SPRITE_MODE); 1752 + else if(keyWasPressedOnce(studio, tic_key_f3)) setStudioMode(studio, TIC_MAP_MODE); 1753 + else if(keyWasPressedOnce(studio, tic_key_f4)) setStudioMode(studio, TIC_SFX_MODE); 1754 + else if(keyWasPressedOnce(studio, tic_key_f5)) setStudioMode(studio, TIC_MUSIC_MODE); 1638 1755 } 1639 1756 #else 1640 - else if(keyWasPressedOnce(tic_key_escape)) 1757 + else if(keyWasPressedOnce(studio, tic_key_escape)) 1641 1758 { 1642 - switch(impl.mode) 1759 + switch(studio->mode) 1643 1760 { 1644 - case TIC_MENU_MODE: studio_menu_back(impl.menu); break; 1645 - case TIC_RUN_MODE: gotoMenu(); break; 1761 + case TIC_MENU_MODE: studio_menu_back(studio->menu); break; 1762 + case TIC_RUN_MODE: gotoMenu(studio); break; 1646 1763 } 1647 1764 } 1648 1765 #endif ··· 1650 1767 } 1651 1768 1652 1769 #if defined(BUILD_EDITORS) 1653 - static void reloadConfirm(bool yes, void* data) 1770 + static void reloadConfirm(Studio* studio, bool yes, void* data) 1654 1771 { 1655 1772 if(yes) 1656 - impl.console->updateProject(impl.console); 1773 + studio->console->updateProject(studio->console); 1657 1774 else 1658 - updateMDate(); 1775 + updateMDate(studio); 1659 1776 } 1660 1777 1661 - static void checkChanges() 1778 + static void checkChanges(Studio* studio) 1662 1779 { 1663 - switch(impl.mode) 1780 + switch(studio->mode) 1664 1781 { 1665 1782 case TIC_START_MODE: 1666 1783 break; 1667 1784 default: 1668 1785 { 1669 - Console* console = impl.console; 1786 + Console* console = studio->console; 1670 1787 1671 1788 u64 date = fs_date(console->rom.path); 1672 1789 1673 - if(impl.cart.mdate && date > impl.cart.mdate) 1790 + if(studio->cart.mdate && date > studio->cart.mdate) 1674 1791 { 1675 - if(studioCartChanged()) 1792 + if(studioCartChanged(studio)) 1676 1793 { 1677 1794 static const char* Rows[] = 1678 1795 { ··· 1681 1798 "Do you want to reload it?" 1682 1799 }; 1683 1800 1684 - confirmDialog(Rows, COUNT_OF(Rows), reloadConfirm, NULL); 1801 + confirmDialog(studio, Rows, COUNT_OF(Rows), reloadConfirm, NULL); 1685 1802 } 1686 1803 else console->updateProject(console); 1687 1804 } ··· 1689 1806 } 1690 1807 } 1691 1808 1692 - static void drawBitIconRaw(u32* frame, s32 sx, s32 sy, s32 id, tic_color color) 1809 + static void drawBitIconRaw(Studio* studio, u32* frame, s32 sx, s32 sy, s32 id, tic_color color) 1693 1810 { 1694 - const tic_bank* bank = &getConfig()->cart->bank0; 1811 + const tic_bank* bank = &getConfig(studio)->cart->bank0; 1695 1812 1696 1813 u32 *dst = frame + sx + sy * TIC80_FULLWIDTH; 1697 1814 for(s32 src = 0; src != TIC_SPRITESIZE * TIC_SPRITESIZE; dst += TIC80_FULLWIDTH - TIC_SPRITESIZE) ··· 1700 1817 *dst = tic_rgba(&bank->palette.vbank0.colors[color]); 1701 1818 } 1702 1819 1703 - static void drawRecordLabel(u32* frame, s32 sx, s32 sy) 1820 + static void drawRecordLabel(Studio* studio, u32* frame, s32 sx, s32 sy) 1704 1821 { 1705 - drawBitIconRaw(frame, sx, sy, tic_icon_rec, tic_color_red); 1706 - drawBitIconRaw(frame, sx + TIC_SPRITESIZE, sy, tic_icon_rec2, tic_color_red); 1822 + drawBitIconRaw(studio, frame, sx, sy, tic_icon_rec, tic_color_red); 1823 + drawBitIconRaw(studio, frame, sx + TIC_SPRITESIZE, sy, tic_icon_rec2, tic_color_red); 1707 1824 } 1708 1825 1709 - static bool isRecordFrame(void) 1826 + static bool isRecordFrame(Studio* studio) 1710 1827 { 1711 - return impl.video.record; 1828 + return studio->video.record; 1712 1829 } 1713 1830 1714 - static void recordFrame(u32* pixels) 1831 + static void recordFrame(Studio* studio, u32* pixels) 1715 1832 { 1716 - if(impl.video.record) 1833 + if(studio->video.record) 1717 1834 { 1718 - if(impl.video.frame < impl.video.frames) 1835 + if(studio->video.frame < studio->video.frames) 1719 1836 { 1720 1837 tic_rect rect = {0, 0, TIC80_FULLWIDTH, TIC80_FULLHEIGHT}; 1721 - screen2buffer(impl.video.buffer + (TIC80_FULLWIDTH*TIC80_FULLHEIGHT) * impl.video.frame, pixels, &rect); 1838 + screen2buffer(studio->video.buffer + (TIC80_FULLWIDTH*TIC80_FULLHEIGHT) * studio->video.frame, pixels, &rect); 1722 1839 1723 - if(impl.video.frame % TIC80_FRAMERATE < TIC80_FRAMERATE / 2) 1840 + if(studio->video.frame % TIC80_FRAMERATE < TIC80_FRAMERATE / 2) 1724 1841 { 1725 - drawRecordLabel(pixels, TIC80_WIDTH-24, 8); 1842 + drawRecordLabel(studio, pixels, TIC80_WIDTH-24, 8); 1726 1843 } 1727 1844 1728 - impl.video.frame++; 1845 + studio->video.frame++; 1729 1846 1730 1847 } 1731 1848 else 1732 1849 { 1733 - stopVideoRecord(impl.video.frame == 1 ? ScreenGif : VideoGif); 1850 + stopVideoRecord(studio, studio->video.frame == 1 ? ScreenGif : VideoGif); 1734 1851 } 1735 1852 } 1736 1853 } 1737 1854 1738 1855 #endif 1739 1856 1740 - static void renderStudio() 1857 + static void renderStudio(Studio* studio) 1741 1858 { 1742 - tic_mem* tic = impl.tic; 1859 + tic_mem* tic = studio->tic; 1743 1860 1744 1861 #if defined(BUILD_EDITORS) 1745 - showTooltip(""); 1862 + showTooltip(studio, ""); 1746 1863 #endif 1747 1864 1748 1865 { 1749 1866 const tic_sfx* sfx = NULL; 1750 1867 const tic_music* music = NULL; 1751 1868 1752 - switch(impl.mode) 1869 + switch(studio->mode) 1753 1870 { 1754 1871 case TIC_RUN_MODE: 1755 - sfx = &impl.tic->ram.sfx; 1756 - music = &impl.tic->ram.music; 1872 + sfx = &studio->tic->ram.sfx; 1873 + music = &studio->tic->ram.music; 1757 1874 break; 1758 1875 case TIC_START_MODE: 1759 1876 case TIC_MENU_MODE: 1760 1877 case TIC_SURF_MODE: 1761 - sfx = &impl.config->cart->bank0.sfx; 1762 - music = &impl.config->cart->bank0.music; 1878 + sfx = &studio->config->cart->bank0.sfx; 1879 + music = &studio->config->cart->bank0.music; 1763 1880 break; 1764 1881 default: 1765 1882 #if defined(BUILD_EDITORS) 1766 - sfx = getSfxSrc(); 1767 - music = getMusicSrc(); 1883 + sfx = getSfxSrc(studio); 1884 + music = getMusicSrc(studio); 1768 1885 #endif 1769 1886 break; 1770 1887 } ··· 1773 1890 music2ram(&tic->ram, music); 1774 1891 1775 1892 // restore mapping in all the modes except Run mode 1776 - if(impl.mode != TIC_RUN_MODE) 1777 - impl.tic->ram.mapping = getConfig()->options.mapping; 1893 + if(studio->mode != TIC_RUN_MODE) 1894 + studio->tic->ram.mapping = getConfig(studio)->options.mapping; 1778 1895 1779 1896 tic_core_tick_start(tic); 1780 1897 } ··· 1782 1899 // SECURITY: It's important that this comes before `tick` and not after 1783 1900 // to prevent misbehaving cartridges from having an opportunity to 1784 1901 // tamper with the keyboard input. 1785 - processShortcuts(); 1902 + processShortcuts(studio); 1786 1903 1787 1904 // clear screen for all the modes except the Run mode 1788 - if(impl.mode != TIC_RUN_MODE) 1905 + if(studio->mode != TIC_RUN_MODE) 1789 1906 { 1790 1907 VBANK(tic, 1) 1791 1908 { ··· 1793 1910 } 1794 1911 } 1795 1912 1796 - switch(impl.mode) 1913 + switch(studio->mode) 1797 1914 { 1798 - case TIC_START_MODE: impl.start->tick(impl.start); break; 1799 - case TIC_RUN_MODE: impl.run->tick(impl.run); break; 1800 - case TIC_MENU_MODE: studio_menu_tick(impl.menu); break; 1915 + case TIC_START_MODE: studio->start->tick(studio->start); break; 1916 + case TIC_RUN_MODE: studio->run->tick(studio->run); break; 1917 + case TIC_MENU_MODE: studio_menu_tick(studio->menu); break; 1801 1918 1802 1919 #if defined(BUILD_EDITORS) 1803 - case TIC_CONSOLE_MODE: impl.console->tick(impl.console); break; 1920 + case TIC_CONSOLE_MODE: studio->console->tick(studio->console); break; 1804 1921 case TIC_CODE_MODE: 1805 1922 { 1806 - Code* code = impl.code; 1923 + Code* code = studio->code; 1807 1924 code->tick(code); 1808 1925 } 1809 1926 break; 1810 1927 case TIC_SPRITE_MODE: 1811 1928 { 1812 - Sprite* sprite = impl.banks.sprite[impl.bank.index.sprites]; 1929 + Sprite* sprite = studio->banks.sprite[studio->bank.index.sprites]; 1813 1930 sprite->tick(sprite); 1814 1931 } 1815 1932 break; 1816 1933 case TIC_MAP_MODE: 1817 1934 { 1818 - Map* map = impl.banks.map[impl.bank.index.map]; 1935 + Map* map = studio->banks.map[studio->bank.index.map]; 1819 1936 map->tick(map); 1820 1937 } 1821 1938 break; 1822 1939 case TIC_SFX_MODE: 1823 1940 { 1824 - Sfx* sfx = impl.banks.sfx[impl.bank.index.sfx]; 1941 + Sfx* sfx = studio->banks.sfx[studio->bank.index.sfx]; 1825 1942 sfx->tick(sfx); 1826 1943 } 1827 1944 break; 1828 1945 case TIC_MUSIC_MODE: 1829 1946 { 1830 - Music* music = impl.banks.music[impl.bank.index.music]; 1947 + Music* music = studio->banks.music[studio->bank.index.music]; 1831 1948 music->tick(music); 1832 1949 } 1833 1950 break; 1834 1951 1835 - case TIC_WORLD_MODE: impl.world->tick(impl.world); break; 1836 - case TIC_SURF_MODE: impl.surf->tick(impl.surf); break; 1952 + case TIC_WORLD_MODE: studio->world->tick(studio->world); break; 1953 + case TIC_SURF_MODE: studio->surf->tick(studio->surf); break; 1837 1954 #endif 1838 1955 default: break; 1839 1956 } 1840 1957 1841 1958 tic_core_tick_end(tic); 1842 1959 1843 - switch(impl.mode) 1960 + switch(studio->mode) 1844 1961 { 1845 1962 case TIC_RUN_MODE: break; 1846 1963 case TIC_SURF_MODE: ··· 1853 1970 } 1854 1971 } 1855 1972 1856 - static void updateSystemFont() 1973 + static void updateSystemFont(Studio* studio) 1857 1974 { 1858 - tic_mem* tic = impl.tic; 1975 + tic_mem* tic = studio->tic; 1859 1976 1860 - impl.systemFont = (tic_font) 1977 + studio->systemFont = (tic_font) 1861 1978 { 1862 1979 .regular = 1863 1980 { ··· 1871 1988 } 1872 1989 }; 1873 1990 1874 - u8* dst = (u8*)&impl.systemFont; 1991 + u8* dst = (u8*)&studio->systemFont; 1875 1992 1876 1993 for(s32 i = 0; i < TIC_FONT_CHARS * 2; i++) 1877 1994 for(s32 y = 0; y < TIC_SPRITESIZE; y++) 1878 1995 for(s32 x = 0; x < TIC_SPRITESIZE; x++) 1879 - if(tic_tool_peek4(&impl.config->cart->bank0.sprites.data[i], TIC_SPRITESIZE*y + x)) 1996 + if(tic_tool_peek4(&studio->config->cart->bank0.sprites.data[i], TIC_SPRITESIZE*y + x)) 1880 1997 dst[i*BITS_IN_BYTE+y] |= 1 << x; 1881 1998 1882 - tic->ram.font = impl.systemFont; 1999 + tic->ram.font = studio->systemFont; 1883 2000 } 1884 2001 1885 - void studioConfigChanged() 2002 + void studioConfigChanged(Studio* studio) 1886 2003 { 1887 2004 #if defined(BUILD_EDITORS) 1888 - Code* code = impl.code; 2005 + Code* code = studio->code; 1889 2006 if(code->update) 1890 2007 code->update(code); 1891 2008 #endif 1892 2009 1893 - updateSystemFont(); 2010 + updateSystemFont(studio); 1894 2011 tic_sys_update_config(); 1895 2012 } 1896 2013 1897 - static void processMouseStates() 2014 + static void processMouseStates(Studio* studio) 1898 2015 { 1899 - for(s32 i = 0; i < COUNT_OF(impl.mouse.state); i++) 1900 - impl.mouse.state[i].click = false; 2016 + for(s32 i = 0; i < COUNT_OF(studio->mouse.state); i++) 2017 + studio->mouse.state[i].click = false; 1901 2018 1902 - tic_mem* tic = impl.tic; 2019 + tic_mem* tic = studio->tic; 1903 2020 1904 2021 tic->ram.vram.vars.cursor.sprite = tic_cursor_arrow; 1905 2022 tic->ram.vram.vars.cursor.system = true; 1906 2023 1907 - for(s32 i = 0; i < COUNT_OF(impl.mouse.state); i++) 2024 + for(s32 i = 0; i < COUNT_OF(studio->mouse.state); i++) 1908 2025 { 1909 - MouseState* state = &impl.mouse.state[i]; 2026 + MouseState* state = &studio->mouse.state[i]; 1910 2027 1911 2028 if(!state->down && (tic->ram.input.mouse.btns & (1 << i))) 1912 2029 { ··· 1923 2040 } 1924 2041 } 1925 2042 1926 - static void blitCursor() 2043 + static void blitCursor(Studio* studio) 1927 2044 { 1928 - tic_mem* tic = impl.tic; 2045 + tic_mem* tic = studio->tic; 1929 2046 tic80_mouse* m = &tic->ram.input.mouse; 1930 2047 1931 2048 if(tic->input.mouse && !m->relative && m->x < TIC80_FULLWIDTH && m->y < TIC80_FULLHEIGHT) ··· 1936 2053 1937 2054 if(tic->ram.vram.vars.cursor.system) 1938 2055 { 1939 - bank = &getConfig()->cart->bank0; 2056 + bank = &getConfig(studio)->cart->bank0; 1940 2057 hot = (tic_point[]) 1941 2058 { 1942 2059 {0, 0}, ··· 1962 2079 } 1963 2080 } 1964 2081 2082 + tic_mem* getMemory(Studio* studio) 2083 + { 2084 + return studio->tic; 2085 + } 2086 + 1965 2087 const tic_mem* studio_mem(Studio* studio) 1966 2088 { 1967 - return impl.tic; 2089 + return getMemory(studio); 1968 2090 } 1969 2091 1970 2092 void studio_tick(Studio* studio, tic80_input input) 1971 2093 { 1972 - tic_mem* tic = impl.tic; 2094 + tic_mem* tic = studio->tic; 1973 2095 tic->ram.input = input; 1974 2096 1975 2097 #if defined(BUILD_EDITORS) 1976 - processAnim(impl.anim.movie, &impl); 1977 - checkChanges(); 1978 - tic_net_start(impl.net); 2098 + processAnim(studio->anim.movie, studio); 2099 + checkChanges(studio); 2100 + tic_net_start(studio->net); 1979 2101 #endif 1980 2102 1981 - if(impl.toolbarMode) 2103 + if(studio->toolbarMode) 1982 2104 { 1983 - setStudioMode(impl.toolbarMode); 1984 - impl.toolbarMode = 0; 2105 + setStudioMode(studio, studio->toolbarMode); 2106 + studio->toolbarMode = 0; 1985 2107 } 1986 2108 1987 - processMouseStates(); 1988 - renderStudio(); 2109 + processMouseStates(studio); 2110 + renderStudio(studio); 1989 2111 1990 2112 { 1991 2113 #if defined(BUILD_EDITORS) 1992 - Sprite* sprite = impl.banks.sprite[impl.bank.index.sprites]; 1993 - Map* map = impl.banks.map[impl.bank.index.map]; 2114 + Sprite* sprite = studio->banks.sprite[studio->bank.index.sprites]; 2115 + Map* map = studio->banks.map[studio->bank.index.map]; 1994 2116 #endif 1995 2117 1996 2118 tic_blit_callback callback[TIC_MODES_COUNT] = 1997 2119 { 1998 - [TIC_MENU_MODE] = {studio_menu_anim_scanline, NULL, NULL, impl.menu}, 2120 + [TIC_MENU_MODE] = {studio_menu_anim_scanline, NULL, NULL, studio->menu}, 1999 2121 2000 2122 #if defined(BUILD_EDITORS) 2001 2123 [TIC_SPRITE_MODE] = {sprite->scanline, NULL, NULL, sprite}, 2002 2124 [TIC_MAP_MODE] = {map->scanline, NULL, NULL, map}, 2003 - [TIC_WORLD_MODE] = {impl.world->scanline, NULL, NULL, impl.world}, 2004 - [TIC_SURF_MODE] = {impl.surf->scanline, NULL, NULL, impl.surf}, 2125 + [TIC_WORLD_MODE] = {studio->world->scanline, NULL, NULL, studio->world}, 2126 + [TIC_SURF_MODE] = {studio->surf->scanline, NULL, NULL, studio->surf}, 2005 2127 #endif 2006 2128 }; 2007 2129 2008 - if(impl.mode != TIC_RUN_MODE) 2130 + if(studio->mode != TIC_RUN_MODE) 2009 2131 { 2010 - memcpy(tic->ram.vram.palette.data, getConfig()->cart->bank0.palette.vbank0.data, sizeof(tic_palette)); 2011 - tic->ram.font = impl.systemFont; 2132 + memcpy(tic->ram.vram.palette.data, getConfig(studio)->cart->bank0.palette.vbank0.data, sizeof(tic_palette)); 2133 + tic->ram.font = studio->systemFont; 2012 2134 } 2013 2135 2014 - callback[impl.mode].data 2015 - ? tic_core_blit_ex(tic, callback[impl.mode]) 2136 + callback[studio->mode].data 2137 + ? tic_core_blit_ex(tic, callback[studio->mode]) 2016 2138 : tic_core_blit(tic); 2017 2139 2018 - blitCursor(); 2140 + blitCursor(studio); 2019 2141 2020 2142 #if defined(BUILD_EDITORS) 2021 - if(isRecordFrame()) 2022 - recordFrame(tic->product.screen); 2143 + if(isRecordFrame(studio)) 2144 + recordFrame(studio, tic->product.screen); 2023 2145 2024 - drawPopup(); 2146 + drawPopup(studio); 2025 2147 #endif 2026 2148 } 2027 2149 2028 2150 #if defined(BUILD_EDITORS) 2029 - tic_net_end(impl.net); 2151 + tic_net_end(studio->net); 2030 2152 #endif 2031 2153 } 2032 2154 2033 2155 void studio_sound(Studio* studio) 2034 2156 { 2035 - tic_mem* tic = impl.tic; 2157 + tic_mem* tic = studio->tic; 2036 2158 tic_core_synth_sound(tic); 2037 2159 2038 - s32 volume = getConfig()->options.volume; 2160 + s32 volume = getConfig(studio)->options.volume; 2039 2161 2040 2162 if(volume != MAX_VOLUME) 2041 2163 { ··· 2048 2170 void studio_load(Studio* studio, const char* file) 2049 2171 { 2050 2172 #if defined(BUILD_EDITORS) 2051 - showPopupMessage(impl.console->loadCart(impl.console, file) 2173 + showPopupMessage(studio, studio->console->loadCart(studio->console, file) 2052 2174 ? "cart successfully loaded :)" 2053 2175 : "error: cart not loaded :("); 2054 2176 #endif 2055 2177 } 2056 2178 2057 - void exitGame() 2179 + void exitGame(Studio* studio) 2058 2180 { 2059 - if(impl.prevMode == TIC_SURF_MODE) 2181 + if(studio->prevMode == TIC_SURF_MODE) 2060 2182 { 2061 - setStudioMode(TIC_SURF_MODE); 2183 + setStudioMode(studio, TIC_SURF_MODE); 2062 2184 } 2063 2185 else 2064 2186 { 2065 - setStudioMode(TIC_CONSOLE_MODE); 2187 + setStudioMode(studio, TIC_CONSOLE_MODE); 2066 2188 } 2067 2189 } 2068 2190 ··· 2072 2194 #if defined(BUILD_EDITORS) 2073 2195 for(s32 i = 0; i < TIC_EDITOR_BANKS; i++) 2074 2196 { 2075 - freeSprite (impl.banks.sprite[i]); 2076 - freeMap (impl.banks.map[i]); 2077 - freeSfx (impl.banks.sfx[i]); 2078 - freeMusic (impl.banks.music[i]); 2197 + freeSprite (studio->banks.sprite[i]); 2198 + freeMap (studio->banks.map[i]); 2199 + freeSfx (studio->banks.sfx[i]); 2200 + freeMusic (studio->banks.music[i]); 2079 2201 } 2080 2202 2081 - freeCode (impl.code); 2082 - freeConsole (impl.console); 2083 - freeWorld (impl.world); 2084 - freeSurf (impl.surf); 2203 + freeCode (studio->code); 2204 + freeConsole (studio->console); 2205 + freeWorld (studio->world); 2206 + freeSurf (studio->surf); 2085 2207 2086 - FREE(impl.anim.show.items); 2087 - FREE(impl.anim.hide.items); 2208 + FREE(studio->anim.show.items); 2209 + FREE(studio->anim.hide.items); 2088 2210 2089 2211 #endif 2090 2212 2091 - freeStart (impl.start); 2092 - freeRun (impl.run); 2093 - freeConfig (impl.config); 2213 + freeStart (studio->start); 2214 + freeRun (studio->run); 2215 + freeConfig (studio->config); 2094 2216 2095 - studio_mainmenu_free(impl.mainmenu); 2096 - studio_menu_free(impl.menu); 2217 + studio_mainmenu_free(studio->mainmenu); 2218 + studio_menu_free(studio->menu); 2097 2219 } 2098 2220 2099 - tic_core_close(impl.tic); 2221 + tic_core_close(studio->tic); 2100 2222 2101 2223 #if defined(BUILD_EDITORS) 2102 - tic_net_close(impl.net); 2224 + tic_net_close(studio->net); 2103 2225 #endif 2104 2226 2105 - free(impl.fs); 2227 + free(studio->fs); 2228 + free(studio); 2106 2229 } 2107 2230 2108 2231 static StartArgs parseArgs(s32 argc, char **argv) ··· 2159 2282 2160 2283 bool studio_alive(Studio* studio) 2161 2284 { 2162 - return impl.alive; 2285 + return studio->alive; 2163 2286 } 2164 2287 2165 - Studio* studio_init(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_format format, const char* folder) 2288 + Studio* studio_create(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_format format, const char* folder) 2166 2289 { 2167 2290 setbuf(stdout, NULL); 2168 2291 ··· 2174 2297 exit(0); 2175 2298 } 2176 2299 2177 - impl.samplerate = samplerate; 2300 + Studio* studio = NEW(Studio); 2301 + *studio = (Studio) 2302 + { 2303 + .mode = TIC_START_MODE, 2304 + .prevMode = TIC_CODE_MODE, 2305 + 2306 + #if defined(BUILD_EDITORS) 2307 + .menuMode = TIC_CONSOLE_MODE, 2308 + 2309 + .bank = 2310 + { 2311 + .chained = true, 2312 + }, 2313 + 2314 + .anim = 2315 + { 2316 + .pos = 2317 + { 2318 + .popup = -TOOLBAR_SIZE, 2319 + }, 2320 + .idle = {.done = emptyDone,} 2321 + }, 2322 + 2323 + .popup = 2324 + { 2325 + .message = "\0", 2326 + }, 2327 + 2328 + .tooltip = 2329 + { 2330 + .text = "\0", 2331 + }, 2332 + 2333 + .samplerate = samplerate, 2334 + .net = tic_net_create("http://"TIC_HOST), 2335 + #endif 2336 + .tic = tic_core_create(samplerate, format), 2337 + }; 2338 + 2178 2339 2179 2340 #if defined(BUILD_EDITORS) 2180 - impl.net = tic_net_create("http://"TIC_HOST); 2341 + 2181 2342 #endif 2182 2343 2183 2344 { ··· 2185 2346 2186 2347 if (fs_exists(path)) 2187 2348 { 2188 - impl.fs = tic_fs_create(path, 2349 + studio->fs = tic_fs_create(path, 2189 2350 #if defined(BUILD_EDITORS) 2190 - impl.net 2351 + studio->net 2191 2352 #else 2192 2353 NULL 2193 2354 #endif ··· 2200 2361 } 2201 2362 } 2202 2363 2203 - impl.tic = tic_core_create(impl.samplerate, format); 2204 - 2205 2364 { 2206 2365 2207 2366 #if defined(BUILD_EDITORS) 2208 2367 for(s32 i = 0; i < TIC_EDITOR_BANKS; i++) 2209 2368 { 2210 - impl.banks.sprite[i] = calloc(1, sizeof(Sprite)); 2211 - impl.banks.map[i] = calloc(1, sizeof(Map)); 2212 - impl.banks.sfx[i] = calloc(1, sizeof(Sfx)); 2213 - impl.banks.music[i] = calloc(1, sizeof(Music)); 2369 + studio->banks.sprite[i] = calloc(1, sizeof(Sprite)); 2370 + studio->banks.map[i] = calloc(1, sizeof(Map)); 2371 + studio->banks.sfx[i] = calloc(1, sizeof(Sfx)); 2372 + studio->banks.music[i] = calloc(1, sizeof(Music)); 2214 2373 } 2215 2374 2216 - impl.code = calloc(1, sizeof(Code)); 2217 - impl.console = calloc(1, sizeof(Console)); 2218 - impl.world = calloc(1, sizeof(World)); 2219 - impl.surf = calloc(1, sizeof(Surf)); 2375 + studio->code = calloc(1, sizeof(Code)); 2376 + studio->console = calloc(1, sizeof(Console)); 2377 + studio->world = calloc(1, sizeof(World)); 2378 + studio->surf = calloc(1, sizeof(Surf)); 2220 2379 2221 - impl.anim.show = (Movie)MOVIE_DEF(STUDIO_ANIM_TIME, setPopupWait, 2380 + studio->anim.show = (Movie)MOVIE_DEF(STUDIO_ANIM_TIME, setPopupWait, 2222 2381 { 2223 - {-TOOLBAR_SIZE, 0, STUDIO_ANIM_TIME, &impl.anim.pos.popup, AnimEaseIn}, 2382 + {-TOOLBAR_SIZE, 0, STUDIO_ANIM_TIME, &studio->anim.pos.popup, AnimEaseIn}, 2224 2383 }); 2225 2384 2226 - impl.anim.wait = (Movie){.time = TIC80_FRAMERATE * 2, .done = setPopupHide}; 2227 - impl.anim.hide = (Movie)MOVIE_DEF(STUDIO_ANIM_TIME, setIdle, 2385 + studio->anim.wait = (Movie){.time = TIC80_FRAMERATE * 2, .done = setPopupHide}; 2386 + studio->anim.hide = (Movie)MOVIE_DEF(STUDIO_ANIM_TIME, setIdle, 2228 2387 { 2229 - {0, -TOOLBAR_SIZE, STUDIO_ANIM_TIME, &impl.anim.pos.popup, AnimEaseIn}, 2388 + {0, -TOOLBAR_SIZE, STUDIO_ANIM_TIME, &studio->anim.pos.popup, AnimEaseIn}, 2230 2389 }); 2231 2390 2232 - impl.anim.movie = resetMovie(&impl.anim.idle); 2391 + studio->anim.movie = resetMovie(&studio->anim.idle); 2233 2392 #endif 2234 2393 2235 - impl.start = calloc(1, sizeof(Start)); 2236 - impl.run = calloc(1, sizeof(Run)); 2237 - impl.menu = studio_menu_create(impl.tic); 2238 - impl.config = calloc(1, sizeof(Config)); 2394 + studio->start = calloc(1, sizeof(Start)); 2395 + studio->run = calloc(1, sizeof(Run)); 2396 + studio->menu = studio_menu_create(studio); 2397 + studio->config = calloc(1, sizeof(Config)); 2239 2398 } 2240 2399 2241 - tic_fs_makedir(impl.fs, TIC_LOCAL); 2242 - tic_fs_makedir(impl.fs, TIC_LOCAL_VERSION); 2400 + tic_fs_makedir(studio->fs, TIC_LOCAL); 2401 + tic_fs_makedir(studio->fs, TIC_LOCAL_VERSION); 2243 2402 2244 - initConfig(impl.config, impl.tic, impl.fs); 2245 - initStart(impl.start, impl.tic, args.cart); 2246 - initRunMode(); 2403 + initConfig(studio->config, studio, studio->fs); 2404 + initStart(studio->start, studio, args.cart); 2405 + initRunMode(studio); 2247 2406 2248 2407 #if defined(BUILD_EDITORS) 2249 - initConsole(impl.console, impl.tic, impl.fs, impl.net, impl.config, args); 2250 - initSurfMode(); 2251 - initModules(); 2408 + initConsole(studio->console, studio, studio->fs, studio->net, studio->config, args); 2409 + initSurfMode(studio); 2410 + initModules(studio); 2252 2411 #endif 2253 2412 2254 2413 if(args.scale) 2255 - impl.config->data.uiScale = args.scale; 2414 + studio->config->data.uiScale = args.scale; 2256 2415 2257 2416 if(args.volume >= 0) 2258 - impl.config->data.options.volume = args.volume & 0x0f; 2417 + studio->config->data.options.volume = args.volume & 0x0f; 2259 2418 2260 2419 #if defined(CRT_SHADER_SUPPORT) 2261 - impl.config->data.options.crt |= args.crt; 2420 + studio->config->data.options.crt |= args.crt; 2262 2421 #endif 2263 2422 2264 - impl.config->data.options.fullscreen |= args.fullscreen; 2265 - impl.config->data.options.vsync |= args.vsync; 2266 - impl.config->data.soft |= args.soft; 2267 - impl.config->data.cli |= args.cli; 2423 + studio->config->data.options.fullscreen |= args.fullscreen; 2424 + studio->config->data.options.vsync |= args.vsync; 2425 + studio->config->data.soft |= args.soft; 2426 + studio->config->data.cli |= args.cli; 2268 2427 2269 2428 if(args.cli) 2270 2429 args.skip = true; 2271 2430 2272 2431 if(args.skip) 2273 - setStudioMode(TIC_CONSOLE_MODE); 2432 + setStudioMode(studio, TIC_CONSOLE_MODE); 2274 2433 2275 - return &impl; 2434 + return studio; 2276 2435 }
+43 -107
src/studio/studio.h
··· 33 33 #include "defines.h" 34 34 #include "tools.h" 35 35 #include "system.h" 36 + #include "anim.h" 36 37 #include "ext/png.h" 37 38 38 39 #define KEYBOARD_HOLD 20 ··· 79 80 macro(version, bool, BOOLEAN, "", "print program version") \ 80 81 CRT_CMD_PARAM(macro) 81 82 82 - #define SHOW_TOOLTIP(FORMAT, ...) \ 83 + #define SHOW_TOOLTIP(STUDIO, FORMAT, ...) \ 83 84 do{ \ 84 85 static const char Format[] = FORMAT; \ 85 86 static char buf[sizeof Format]; \ 86 87 sprintf(buf, Format, __VA_ARGS__); \ 87 - showTooltip(buf); \ 88 + showTooltip(STUDIO, buf); \ 88 89 }while(0) 89 90 90 91 typedef struct ··· 173 174 tic_icon_bigfill = 136, 174 175 }; 175 176 176 - void setCursor(tic_cursor id); 177 + void setCursor(Studio* studio, tic_cursor id); 177 178 178 - bool checkMousePos(const tic_rect* rect); 179 - bool checkMouseClick(const tic_rect* rect, tic_mouse_btn button); 180 - bool checkMouseDown(const tic_rect* rect, tic_mouse_btn button); 179 + bool checkMousePos(Studio* studio, const tic_rect* rect); 180 + bool checkMouseClick(Studio* studio, const tic_rect* rect, tic_mouse_btn button); 181 + bool checkMouseDown(Studio* studio, const tic_rect* rect, tic_mouse_btn button); 181 182 182 - void drawToolbar(tic_mem* tic, bool bg); 183 - void drawBitIcon(s32 id, s32 x, s32 y, u8 color); 183 + void drawToolbar(Studio* studio, tic_mem* tic, bool bg); 184 + void drawBitIcon(Studio* studio, s32 id, s32 x, s32 y, u8 color); 184 185 185 186 tic_cartridge* loadPngCart(png_buffer buffer); 186 - void studioRomLoaded(); 187 - void studioRomSaved(); 188 - void studioConfigChanged(); 187 + void studioRomLoaded(Studio* studio); 188 + void studioRomSaved(Studio* studio); 189 + void studioConfigChanged(Studio* studio); 189 190 190 - void setStudioMode(EditorMode mode); 191 - EditorMode getStudioMode(); 192 - void exitStudio(); 191 + void setStudioMode(Studio* studio, EditorMode mode); 192 + EditorMode getStudioMode(Studio* studio); 193 + void exitStudio(Studio* studio); 193 194 194 195 void toClipboard(const void* data, s32 size, bool flip); 195 196 bool fromClipboard(void* data, s32 size, bool flip, bool remove_white_spaces); ··· 202 203 TIC_CLIPBOARD_PASTE, 203 204 } ClipboardEvent; 204 205 205 - ClipboardEvent getClipboardEvent(); 206 + ClipboardEvent getClipboardEvent(Studio* studio); 206 207 207 208 typedef enum 208 209 { ··· 213 214 TIC_TOOLBAR_REDO, 214 215 } StudioEvent; 215 216 216 - void setStudioEvent(StudioEvent event); 217 - void showTooltip(const char* text); 217 + void setStudioEvent(Studio* studio, StudioEvent event); 218 + void showTooltip(Studio* studio, const char* text); 218 219 219 220 void setSpritePixel(tic_tile* tiles, s32 x, s32 y, u8 color); 220 221 u8 getSpritePixel(tic_tile* tiles, s32 x, s32 y); 221 222 222 - typedef void(*ConfirmCallback)(bool yes, void* data); 223 - void confirmDialog(const char** text, s32 rows, ConfirmCallback callback, void* data); 223 + typedef void(*ConfirmCallback)(Studio* studio, bool yes, void* data); 224 + void confirmDialog(Studio* studio, const char** text, s32 rows, ConfirmCallback callback, void* data); 224 225 225 - bool studioCartChanged(); 226 - void playSystemSfx(s32 id); 226 + bool studioCartChanged(Studio* studio); 227 + void playSystemSfx(Studio* studio, s32 id); 227 228 228 - void gotoMenu(); 229 - void gotoCode(); 230 - void gotoSurf(); 229 + void gotoMenu(Studio* studio); 230 + void gotoCode(Studio* studio); 231 + void gotoSurf(Studio* studio); 231 232 232 - void runGame(); 233 - void exitGame(); 234 - void resumeGame(); 233 + void runGame(Studio* studio); 234 + void exitGame(Studio* studio); 235 + void resumeGame(Studio* studio); 235 236 236 - tic_tiles* getBankTiles(); 237 - tic_palette* getBankPalette(bool bank); 238 - tic_flags* getBankFlags(); 239 - tic_map* getBankMap(); 237 + tic_tiles* getBankTiles(Studio* studio); 238 + tic_palette* getBankPalette(Studio* studio, bool bank); 239 + tic_flags* getBankFlags(Studio* studio); 240 + tic_map* getBankMap(Studio* studio); 240 241 241 - char getKeyboardText(); 242 - bool keyWasPressed(tic_key key); 243 - bool anyKeyWasPressed(); 242 + char getKeyboardText(Studio* studio); 243 + bool keyWasPressed(Studio* studio, tic_key key); 244 + bool anyKeyWasPressed(Studio* studio); 244 245 245 - const StudioConfig* getConfig(); 246 - struct Start* getStartScreen(); 247 - struct Sprite* getSpriteEditor(); 246 + const StudioConfig* getConfig(Studio* studio); 247 + struct Start* getStartScreen(Studio* studio); 248 + struct Sprite* getSpriteEditor(Studio* studio); 249 + 250 + const char* studioExportMusic(Studio* studio, s32 track, const char* filename); 251 + const char* studioExportSfx(Studio* studio, s32 sfx, const char* filename); 252 + 253 + tic_mem* getMemory(Studio* studio); 248 254 249 255 const char* md5str(const void* data, s32 length); 250 256 void sfx_stop(tic_mem* tic, s32 channel); 251 - const char* studioExportMusic(s32 track, const char* filename); 252 - const char* studioExportSfx(s32 sfx, const char* filename); 253 257 s32 calcWaveAnimation(tic_mem* tic, u32 index, s32 channel); 254 258 void map2ram(tic_ram* ram, const tic_map* src); 255 259 void tiles2ram(tic_ram* ram, const tic_tiles* src); 256 260 void fadePalette(tic_palette* pal, s32 value); 257 - 258 - typedef enum 259 - { 260 - AnimLinear, 261 - AnimEaseIn, 262 - AnimEaseOut, 263 - AnimEaseInOut, 264 - AnimEaseInCubic, 265 - AnimEaseOutCubic, 266 - AnimEaseInOutCubic, 267 - AnimEaseInQuart, 268 - AnimEaseOutQuart, 269 - AnimEaseInOutQuart, 270 - AnimEaseInQuint, 271 - AnimEaseOutQuint, 272 - AnimEaseInOutQuint, 273 - AnimEaseInSine, 274 - AnimEaseOutSine, 275 - AnimEaseInOutSine, 276 - AnimEaseInExpo, 277 - AnimEaseOutExpo, 278 - AnimEaseInOutExpo, 279 - AnimEaseInCirc, 280 - AnimEaseOutCirc, 281 - AnimEaseInOutCirc, 282 - AnimEaseInBack, 283 - AnimEaseOutBack, 284 - AnimEaseInOutBack, 285 - AnimEaseInElastic, 286 - AnimEaseOutElastic, 287 - AnimEaseInOutElastic, 288 - AnimEaseInBounce, 289 - AnimEaseOutBounce, 290 - AnimEaseInOutBounce, 291 - } AnimEffect; 292 - 293 - typedef struct 294 - { 295 - s32 start; 296 - s32 end; 297 - s32 time; 298 - 299 - s32 *value; 300 - 301 - AnimEffect effect; 302 - } Anim; 303 - 304 - typedef struct 305 - { 306 - void(*done)(void *data); 307 - 308 - s32 time; 309 - s32 tick; 310 - 311 - s32 count; 312 - Anim* items; 313 - } Movie; 314 - 315 - #define MOVIE_DEF(TIME, DONE, ...) \ 316 - { \ 317 - .time = TIME, \ 318 - .done = DONE, \ 319 - .count = COUNT_OF(((Anim[])__VA_ARGS__)), \ 320 - .items = MOVE((Anim[])__VA_ARGS__), \ 321 - } 322 - 323 - void processAnim(Movie* movie, void* data); 324 - Movie* resetMovie(Movie* movie);
-207
src/studio/studio_impl.h
··· 1 - // MIT License 2 - 3 - // Copyright (c) 2017 Vadim Grigoruk @nesbox // grigoruk@gmail.com 4 - 5 - // Permission is hereby granted, free of charge, to any person obtaining a copy 6 - // of this software and associated documentation files (the "Software"), to deal 7 - // in the Software without restriction, including without limitation the rights 8 - // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 - // copies of the Software, and to permit persons to whom the Software is 10 - // furnished to do so, subject to the following conditions: 11 - 12 - // The above copyright notice and this permission notice shall be included in all 13 - // copies or substantial portions of the Software. 14 - 15 - // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 - // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 - // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 - // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 - // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 - // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 - // SOFTWARE. 22 - 23 - 24 - #pragma once 25 - 26 - #if defined(BUILD_EDITORS) 27 - 28 - #include "editors/code.h" 29 - #include "editors/sprite.h" 30 - #include "editors/map.h" 31 - #include "editors/world.h" 32 - #include "editors/sfx.h" 33 - #include "editors/music.h" 34 - #include "screens/console.h" 35 - #include "screens/surf.h" 36 - #include "net.h" 37 - 38 - #endif 39 - 40 - #include "screens/start.h" 41 - #include "screens/run.h" 42 - #include "screens/menu.h" 43 - #include "config.h" 44 - 45 - #include "fs.h" 46 - 47 - #define MD5_HASHSIZE 16 48 - 49 - #if defined(TIC80_PRO) 50 - #define TIC_EDITOR_BANKS (TIC_BANKS) 51 - #else 52 - #define TIC_EDITOR_BANKS 1 53 - #endif 54 - 55 - #ifdef BUILD_EDITORS 56 - typedef struct 57 - { 58 - u8 data[MD5_HASHSIZE]; 59 - } CartHash; 60 - 61 - static const EditorMode Modes[] = 62 - { 63 - TIC_CODE_MODE, 64 - TIC_SPRITE_MODE, 65 - TIC_MAP_MODE, 66 - TIC_SFX_MODE, 67 - TIC_MUSIC_MODE, 68 - }; 69 - 70 - static const EditorMode BankModes[] = 71 - { 72 - TIC_SPRITE_MODE, 73 - TIC_MAP_MODE, 74 - TIC_SFX_MODE, 75 - TIC_MUSIC_MODE, 76 - }; 77 - 78 - #endif 79 - 80 - typedef struct 81 - { 82 - bool down; 83 - bool click; 84 - 85 - tic_point start; 86 - tic_point end; 87 - 88 - } MouseState; 89 - 90 - typedef struct 91 - { 92 - tic_mapping mapping; 93 - s32 index; 94 - s32 key; 95 - } Gamepads; 96 - 97 - struct Studio 98 - { 99 - tic_mem* tic; 100 - 101 - bool alive; 102 - 103 - EditorMode mode; 104 - EditorMode prevMode; 105 - EditorMode toolbarMode; 106 - 107 - struct 108 - { 109 - MouseState state[3]; 110 - } mouse; 111 - 112 - #if defined(BUILD_EDITORS) 113 - EditorMode menuMode; 114 - 115 - struct 116 - { 117 - CartHash hash; 118 - u64 mdate; 119 - }cart; 120 - 121 - struct 122 - { 123 - bool show; 124 - bool chained; 125 - 126 - union 127 - { 128 - struct 129 - { 130 - s8 sprites; 131 - s8 map; 132 - s8 sfx; 133 - s8 music; 134 - } index; 135 - 136 - s8 indexes[COUNT_OF(BankModes)]; 137 - }; 138 - 139 - } bank; 140 - 141 - struct 142 - { 143 - struct 144 - { 145 - s32 popup; 146 - } pos; 147 - 148 - Movie* movie; 149 - 150 - Movie idle; 151 - Movie show; 152 - Movie wait; 153 - Movie hide; 154 - 155 - } anim; 156 - 157 - struct 158 - { 159 - char message[STUDIO_TEXT_BUFFER_WIDTH]; 160 - } popup; 161 - 162 - struct 163 - { 164 - char text[STUDIO_TEXT_BUFFER_WIDTH]; 165 - } tooltip; 166 - 167 - struct 168 - { 169 - bool record; 170 - 171 - u32* buffer; 172 - s32 frames; 173 - s32 frame; 174 - 175 - } video; 176 - 177 - Code* code; 178 - 179 - struct 180 - { 181 - Sprite* sprite[TIC_EDITOR_BANKS]; 182 - Map* map[TIC_EDITOR_BANKS]; 183 - Sfx* sfx[TIC_EDITOR_BANKS]; 184 - Music* music[TIC_EDITOR_BANKS]; 185 - } banks; 186 - 187 - Console* console; 188 - World* world; 189 - Surf* surf; 190 - 191 - tic_net* net; 192 - #endif 193 - 194 - Start* start; 195 - Run* run; 196 - Menu* menu; 197 - Config* config; 198 - 199 - struct StudioMainMenu* mainmenu; 200 - 201 - tic_fs* fs; 202 - 203 - s32 samplerate; 204 - 205 - tic_font systemFont; 206 - 207 - };
+1 -1
src/studio/system.h
··· 147 147 void studio_delete(Studio* studio); 148 148 const StudioConfig* studio_config(Studio* studio); 149 149 150 - Studio* studio_init(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_format format, const char* appFolder); 150 + Studio* studio_create(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_format format, const char* appFolder); 151 151 152 152 #ifdef __cplusplus 153 153 }
+3 -3
src/system/baremetalpi/kernel.cpp
··· 384 384 char* argv[] = { &arg0[0], NULL }; 385 385 int argc = 1; 386 386 malloc(88); 387 - platform.studio = studio_init(argc, argv, 44100, TIC80_PIXEL_COLOR_BGRA8888, "tic80"); 387 + platform.studio = studio_create(argc, argv, 44100, TIC80_PIXEL_COLOR_BGRA8888, "tic80"); 388 388 malloc(99); 389 389 390 390 } ··· 396 396 char* argv[] = { &arg0[0], &arg1[0], NULL }; 397 397 int argc = 2; 398 398 dbg("Without keyboard\n"); 399 - platform.studio = studio_init(argc, argv, 44100, TIC80_PIXEL_COLOR_BGRA8888, "tic80"); 399 + platform.studio = studio_create(argc, argv, 44100, TIC80_PIXEL_COLOR_BGRA8888, "tic80"); 400 400 } 401 - dbg("studio_init OK\n"); 401 + dbg("studio_create OK\n"); 402 402 403 403 if( !platform.studio) 404 404 {
+1 -1
src/system/n3ds/main.c
··· 571 571 n3ds_draw_init(); 572 572 n3ds_keyboard_init(&platform.keyboard); 573 573 574 - platform.studio = studio_init(argc_used, argv_used, AUDIO_FREQ, TIC80_PIXEL_COLOR_ABGR8888, "./"); 574 + platform.studio = studio_create(argc_used, argv_used, AUDIO_FREQ, TIC80_PIXEL_COLOR_ABGR8888, "./"); 575 575 576 576 n3ds_sound_init(AUDIO_FREQ); 577 577
+1 -1
src/system/sdl/main.c
··· 1630 1630 static s32 start(s32 argc, char **argv, const char* folder) 1631 1631 { 1632 1632 SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK); 1633 - platform.studio = studio_init(argc, argv, TIC80_SAMPLERATE, SCREEN_FORMAT, folder); 1633 + platform.studio = studio_create(argc, argv, TIC80_SAMPLERATE, SCREEN_FORMAT, folder); 1634 1634 1635 1635 SCOPE(studio_delete(platform.studio)) 1636 1636 {
+1 -1
src/system/sokol/sokol.c
··· 406 406 platform.audio.desc.num_channels = TIC80_SAMPLE_CHANNELS; 407 407 saudio_setup(&platform.audio.desc); 408 408 409 - platform.studio = studio_init(argc, argv, saudio_sample_rate(), TIC80_PIXEL_COLOR_RGBA8888, "./"); 409 + platform.studio = studio_create(argc, argv, saudio_sample_rate(), TIC80_PIXEL_COLOR_RGBA8888, "./"); 410 410 411 411 if(studio_config(platform.studio)->cli) 412 412 {