this repo has no description
0
fork

Configure Feed

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

added bookmarks sidebar #1819

nesbox 199af532 54d5eb8d

+114 -64
+111 -62
src/studio/editors/code.c
··· 32 32 #define CODE_EDITOR_WIDTH (TIC80_WIDTH - BOOKMARK_WIDTH) 33 33 #define CODE_EDITOR_HEIGHT (TIC80_HEIGHT - TOOLBAR_SIZE - STUDIO_TEXT_HEIGHT) 34 34 #define TEXT_BUFFER_HEIGHT (CODE_EDITOR_HEIGHT / STUDIO_TEXT_HEIGHT) 35 - #define OUTLINE_WIDTH (13 * TIC_FONT_WIDTH) 35 + #define SIDEBAR_WIDTH (12 * TIC_FONT_WIDTH) 36 36 37 37 #if defined(TIC80_PRO) 38 38 # define MAX_CODE sizeof(tic_code) ··· 1225 1225 normalizeScroll(code); 1226 1226 } 1227 1227 1228 - static void updateOutlineCode(Code* code) 1228 + static void updateSidebarCode(Code* code) 1229 1229 { 1230 1230 tic_mem* tic = code->tic; 1231 1231 1232 - const tic_outline_item* item = code->outline.items + code->outline.index; 1232 + const tic_outline_item* item = code->sidebar.items + code->sidebar.index; 1233 1233 1234 - if(item && item->pos) 1234 + if(code->sidebar.size && item && item->pos) 1235 1235 { 1236 1236 code->cursor.position = (char*)item->pos; 1237 1237 code->cursor.selection = (char*)item->pos + item->size; ··· 1277 1277 } 1278 1278 } 1279 1279 1280 - static void initOutlineMode(Code* code) 1280 + static void initSidebarMode(Code* code) 1281 1281 { 1282 1282 tic_mem* tic = code->tic; 1283 1283 1284 - if(code->outline.items) 1285 - { 1286 - free(code->outline.items); 1287 - code->outline.items = NULL; 1288 - code->outline.size = 0; 1289 - } 1284 + code->sidebar.size = 0; 1290 1285 1291 1286 const tic_script_config* config = tic_core_script_config(tic); 1292 1287 ··· 1313 1308 if(*filter && !isFilterMatch(buffer, filter)) 1314 1309 continue; 1315 1310 1316 - s32 last = code->outline.size++; 1317 - code->outline.items = realloc(code->outline.items, code->outline.size * sizeof(tic_outline_item)); 1318 - code->outline.items[last] = *item; 1311 + s32 last = code->sidebar.size++; 1312 + code->sidebar.items = realloc(code->sidebar.items, code->sidebar.size * sizeof(tic_outline_item)); 1313 + code->sidebar.items[last] = *item; 1319 1314 } 1320 1315 } 1321 1316 } 1322 1317 } 1323 1318 1319 + static void setBookmarkMode(Code* code) 1320 + { 1321 + code->sidebar.index = 0; 1322 + code->sidebar.scroll = 0; 1323 + code->sidebar.size = 0; 1324 + 1325 + const char* ptr = code->src; 1326 + const CodeState* state = code->state; 1327 + 1328 + while(*ptr) 1329 + { 1330 + if(state->bookmark) 1331 + { 1332 + s32 last = code->sidebar.size++; 1333 + code->sidebar.items = realloc(code->sidebar.items, code->sidebar.size * sizeof(tic_outline_item)); 1334 + tic_outline_item* item = &code->sidebar.items[last]; 1335 + 1336 + item->pos = ptr; 1337 + item->size = MIN(SIDEBAR_WIDTH / TIC_ALTFONT_WIDTH, getLineSize(ptr)); 1338 + } 1339 + 1340 + ptr++; 1341 + state++; 1342 + } 1343 + 1344 + updateSidebarCode(code); 1345 + } 1346 + 1324 1347 static void setOutlineMode(Code* code) 1325 1348 { 1326 - code->outline.index = 0; 1327 - code->outline.scroll = 0; 1349 + code->sidebar.index = 0; 1350 + code->sidebar.scroll = 0; 1328 1351 1329 - initOutlineMode(code); 1352 + initSidebarMode(code); 1330 1353 1331 - qsort(code->outline.items, code->outline.size, sizeof(tic_outline_item), funcCompare); 1332 - updateOutlineCode(code); 1354 + qsort(code->sidebar.items, code->sidebar.size, sizeof(tic_outline_item), funcCompare); 1355 + updateSidebarCode(code); 1333 1356 } 1334 1357 1335 1358 static bool isIdle(Code* code) ··· 1352 1375 { 1353 1376 case TEXT_FIND_MODE: setFindMode(code); break; 1354 1377 case TEXT_GOTO_MODE: setGotoMode(code); break; 1378 + case TEXT_BOOKMARK_MODE: setBookmarkMode(code); break; 1355 1379 case TEXT_OUTLINE_MODE: setOutlineMode(code); break; 1356 1380 default: break; 1357 1381 } ··· 1591 1615 else if(keyWasPressed(code->studio, tic_key_y)) redo(code); 1592 1616 else if(keyWasPressed(code->studio, tic_key_f)) setCodeMode(code, TEXT_FIND_MODE); 1593 1617 else if(keyWasPressed(code->studio, tic_key_g)) setCodeMode(code, TEXT_GOTO_MODE); 1618 + else if(keyWasPressed(code->studio, tic_key_b)) setCodeMode(code, TEXT_BOOKMARK_MODE); 1594 1619 else if(keyWasPressed(code->studio, tic_key_o)) setCodeMode(code, TEXT_OUTLINE_MODE); 1595 1620 else if(keyWasPressed(code->studio, tic_key_n)) downLine(code); 1596 1621 else if(keyWasPressed(code->studio, tic_key_p)) upLine(code); ··· 1928 1953 drawStatus(code); 1929 1954 } 1930 1955 1931 - static void drawOutlineBar(Code* code, s32 x, s32 y) 1956 + static void drawSidebarBar(Code* code, s32 x, s32 y) 1932 1957 { 1933 1958 tic_mem* tic = code->tic; 1934 1959 tic_rect rect = {x, y, TIC80_WIDTH - x, TIC80_HEIGHT - y}; ··· 1937 1962 { 1938 1963 s32 mx = tic_api_mouse(tic).y - rect.y; 1939 1964 mx /= STUDIO_TEXT_HEIGHT; 1940 - mx += code->outline.scroll; 1965 + mx += code->sidebar.scroll; 1941 1966 1942 - if(mx >= 0 && mx < code->outline.size && code->outline.items[mx].pos) 1967 + if(mx >= 0 && mx < code->sidebar.size && code->sidebar.items[mx].pos) 1943 1968 { 1944 1969 setCursor(code->studio, tic_cursor_hand); 1945 1970 1946 1971 if(checkMouseDown(code->studio, &rect, tic_mouse_left)) 1947 1972 { 1948 - code->outline.index = mx; 1949 - updateOutlineCode(code); 1973 + code->sidebar.index = mx; 1974 + updateSidebarCode(code); 1950 1975 } 1951 1976 1952 1977 if(checkMouseClick(code->studio, &rect, tic_mouse_left)) ··· 1956 1981 1957 1982 tic_api_rect(code->tic, rect.x-1, rect.y, rect.w+1, rect.h, tic_color_grey); 1958 1983 1959 - y -= code->outline.scroll * STUDIO_TEXT_HEIGHT - 1; 1984 + y -= code->sidebar.scroll * STUDIO_TEXT_HEIGHT - 1; 1960 1985 1961 1986 char filter[STUDIO_TEXT_BUFFER_WIDTH]; 1962 1987 strncpy(filter, code->popup.text, sizeof(filter)); 1963 1988 1964 - if(code->outline.items) 1989 + if(code->sidebar.size) 1965 1990 { 1966 - tic_api_rect(code->tic, rect.x - 1, rect.y + (code->outline.index - code->outline.scroll) * STUDIO_TEXT_HEIGHT, 1991 + tic_api_rect(code->tic, rect.x - 1, rect.y + (code->sidebar.index - code->sidebar.scroll) * STUDIO_TEXT_HEIGHT, 1967 1992 rect.w + 1, TIC_FONT_HEIGHT + 2, tic_color_red); 1968 1993 1969 - for(const tic_outline_item* ptr = code->outline.items, *end = ptr + code->outline.size; 1994 + for(const tic_outline_item* ptr = code->sidebar.items, *end = ptr + code->sidebar.size; 1970 1995 ptr < end; ptr++, y += STUDIO_TEXT_HEIGHT) 1971 1996 { 1972 1997 char orig[STUDIO_TEXT_BUFFER_WIDTH] = {0}; ··· 1983 2008 } 1984 2009 } 1985 2010 1986 - static void normOutlineScroll(Code* code) 2011 + static void normSidebarScroll(Code* code) 1987 2012 { 1988 - code->outline.scroll = code->outline.size > TEXT_BUFFER_HEIGHT 1989 - ? CLAMP(code->outline.scroll, 0, code->outline.size - TEXT_BUFFER_HEIGHT) : 0; 2013 + code->sidebar.scroll = code->sidebar.size > TEXT_BUFFER_HEIGHT 2014 + ? CLAMP(code->sidebar.scroll, 0, code->sidebar.size - TEXT_BUFFER_HEIGHT) : 0; 1990 2015 } 1991 2016 1992 - static void updateOutlineIndex(Code* code, s32 value) 2017 + static void updateSidebarIndex(Code* code, s32 value) 1993 2018 { 1994 - if(code->outline.size == 0) 2019 + if(code->sidebar.size == 0) 1995 2020 return; 1996 2021 1997 - code->outline.index = CLAMP(value, 0, code->outline.size - 1); 2022 + code->sidebar.index = CLAMP(value, 0, code->sidebar.size - 1); 1998 2023 1999 - if(code->outline.index - code->outline.scroll < 0) 2000 - code->outline.scroll -= TEXT_BUFFER_HEIGHT; 2001 - else if(code->outline.index - code->outline.scroll >= TEXT_BUFFER_HEIGHT) 2002 - code->outline.scroll += TEXT_BUFFER_HEIGHT; 2024 + if(code->sidebar.index - code->sidebar.scroll < 0) 2025 + code->sidebar.scroll -= TEXT_BUFFER_HEIGHT; 2026 + else if(code->sidebar.index - code->sidebar.scroll >= TEXT_BUFFER_HEIGHT) 2027 + code->sidebar.scroll += TEXT_BUFFER_HEIGHT; 2003 2028 2004 - updateOutlineCode(code); 2005 - normOutlineScroll(code); 2029 + updateSidebarCode(code); 2030 + normSidebarScroll(code); 2006 2031 } 2007 2032 2008 - static void textOutlineTick(Code* code) 2033 + static void processSidebar(Code* code) 2009 2034 { 2010 2035 // process scroll 2011 2036 { ··· 2015 2040 { 2016 2041 enum{Scroll = 3}; 2017 2042 s32 delta = input->mouse.scrolly > 0 ? -Scroll : Scroll; 2018 - code->outline.scroll += delta; 2019 - normOutlineScroll(code); 2043 + code->sidebar.scroll += delta; 2044 + normSidebarScroll(code); 2020 2045 } 2021 2046 } 2022 2047 2023 2048 if(keyWasPressed(code->studio, tic_key_up)) 2024 - updateOutlineIndex(code, code->outline.index - 1); 2049 + updateSidebarIndex(code, code->sidebar.index - 1); 2025 2050 2026 2051 else if(keyWasPressed(code->studio, tic_key_down)) 2027 - updateOutlineIndex(code, code->outline.index + 1); 2052 + updateSidebarIndex(code, code->sidebar.index + 1); 2028 2053 2029 2054 else if(keyWasPressed(code->studio, tic_key_left) || keyWasPressed(code->studio, tic_key_pageup)) 2030 - updateOutlineIndex(code, code->outline.index - TEXT_BUFFER_HEIGHT); 2055 + updateSidebarIndex(code, code->sidebar.index - TEXT_BUFFER_HEIGHT); 2031 2056 2032 2057 else if(keyWasPressed(code->studio, tic_key_right) || keyWasPressed(code->studio, tic_key_pagedown)) 2033 - updateOutlineIndex(code, code->outline.index + TEXT_BUFFER_HEIGHT); 2058 + updateSidebarIndex(code, code->sidebar.index + TEXT_BUFFER_HEIGHT); 2034 2059 2035 2060 else if(keyWasPressed(code->studio, tic_key_home)) 2036 - updateOutlineIndex(code, 0); 2061 + updateSidebarIndex(code, 0); 2037 2062 2038 2063 else if(keyWasPressed(code->studio, tic_key_end)) 2039 - updateOutlineIndex(code, code->outline.size - 1); 2064 + updateSidebarIndex(code, code->sidebar.size - 1); 2040 2065 2041 2066 else if(keyWasPressed(code->studio, tic_key_return)) 2042 2067 { 2043 - updateOutlineCode(code); 2068 + updateSidebarCode(code); 2044 2069 setCodeMode(code, TEXT_EDIT_MODE); 2045 2070 } 2046 - else if(keyWasPressed(code->studio, tic_key_backspace)) 2071 + } 2072 + 2073 + static void textBookmarkTick(Code* code) 2074 + { 2075 + processSidebar(code); 2076 + 2077 + tic_api_cls(code->tic, getConfig(code->studio)->theme.code.BG); 2078 + 2079 + drawCode(code, false); 2080 + drawStatus(code); 2081 + drawSidebarBar(code, (TIC80_WIDTH - SIDEBAR_WIDTH) + code->anim.sidebar, TIC_FONT_HEIGHT+1); 2082 + } 2083 + 2084 + static void textOutlineTick(Code* code) 2085 + { 2086 + processSidebar(code); 2087 + 2088 + if(keyWasPressed(code->studio, tic_key_backspace)) 2047 2089 { 2048 2090 if(*code->popup.text) 2049 2091 { ··· 2068 2110 2069 2111 drawCode(code, false); 2070 2112 drawStatus(code); 2071 - drawOutlineBar(code, (TIC80_WIDTH - OUTLINE_WIDTH) + code->anim.outline, 2*(TIC_FONT_HEIGHT+1)); 2113 + drawSidebarBar(code, (TIC80_WIDTH - SIDEBAR_WIDTH) + code->anim.sidebar, 2*(TIC_FONT_HEIGHT+1)); 2072 2114 drawPopupBar(code, "FUNC:"); 2073 2115 } 2074 2116 ··· 2150 2192 { 2151 2193 tic_api_rect(code->tic, 0, 0, TIC80_WIDTH, TOOLBAR_SIZE, tic_color_white); 2152 2194 2153 - static u8 Icons[] = {tic_icon_hand, tic_icon_find, tic_icon_goto, tic_icon_outline}; 2154 - static const char* Tips[] = {"DRAG [right mouse]", "FIND [ctrl+f]", "GOTO [ctrl+g]", "OUTLINE [ctrl+o]"}; 2195 + static const struct Button {u8 icon; const char* tip;} Buttons[] = 2196 + { 2197 + {tic_icon_hand, "DRAG [right mouse]"}, 2198 + {tic_icon_find, "FIND [ctrl+f]"}, 2199 + {tic_icon_goto, "GOTO [ctrl+g]"}, 2200 + {tic_icon_bookmark, "BOOKMARKS [ctrl+b]"}, 2201 + {tic_icon_outline, "OUTLINE [ctrl+o]"}, 2202 + }; 2155 2203 2156 - enum {Count = COUNT_OF(Icons)}; 2157 - enum {Size = 7}; 2204 + enum {Count = COUNT_OF(Buttons), Size = 7}; 2158 2205 2159 2206 for(s32 i = 0; i < Count; i++) 2160 2207 { 2208 + const struct Button* btn = &Buttons[i]; 2161 2209 tic_rect rect = {TIC80_WIDTH + (i - Count) * Size, 0, Size, Size}; 2162 2210 2163 2211 bool over = false; ··· 2165 2213 { 2166 2214 setCursor(code->studio, tic_cursor_hand); 2167 2215 2168 - showTooltip(code->studio, Tips[i]); 2216 + showTooltip(code->studio, btn->tip); 2169 2217 2170 2218 over = true; 2171 2219 ··· 2180 2228 if (active) 2181 2229 { 2182 2230 tic_api_rect(code->tic, rect.x, rect.y, Size, Size, tic_color_grey); 2183 - drawBitIcon(code->studio, Icons[i], rect.x, rect.y + 1, tic_color_black); 2231 + drawBitIcon(code->studio, btn->icon, rect.x, rect.y + 1, tic_color_black); 2184 2232 } 2185 2233 2186 - drawBitIcon(code->studio, Icons[i], rect.x, rect.y, active ? tic_color_white : (over ? tic_color_grey : tic_color_light_grey)); 2234 + drawBitIcon(code->studio, btn->icon, rect.x, rect.y, active ? tic_color_white : (over ? tic_color_grey : tic_color_light_grey)); 2187 2235 } 2188 2236 2189 2237 drawFontButton(code, TIC80_WIDTH - (Count+3) * Size, 1); ··· 2206 2254 case TEXT_EDIT_MODE: textEditTick(code); break; 2207 2255 case TEXT_FIND_MODE: textFindTick(code); break; 2208 2256 case TEXT_GOTO_MODE: textGoToTick(code); break; 2257 + case TEXT_BOOKMARK_MODE:textBookmarkTick(code); break; 2209 2258 case TEXT_OUTLINE_MODE: textOutlineTick(code); break; 2210 2259 } 2211 2260 ··· 2294 2343 .prevPos = NULL, 2295 2344 .prevSel = NULL, 2296 2345 }, 2297 - .outline = 2346 + .sidebar = 2298 2347 { 2299 2348 .items = NULL, 2300 2349 .size = 0, ··· 2311 2360 .show = MOVIE_DEF(STUDIO_ANIM_TIME, setIdle, 2312 2361 { 2313 2362 {-TOOLBAR_SIZE, 0, STUDIO_ANIM_TIME, &code->anim.pos, AnimEaseIn}, 2314 - {OUTLINE_WIDTH, 0, STUDIO_ANIM_TIME, &code->anim.outline, AnimEaseIn}, 2363 + {SIDEBAR_WIDTH, 0, STUDIO_ANIM_TIME, &code->anim.sidebar, AnimEaseIn}, 2315 2364 }), 2316 2365 2317 2366 .hide = MOVIE_DEF(STUDIO_ANIM_TIME, setEditMode, 2318 2367 { 2319 2368 {0, -TOOLBAR_SIZE, STUDIO_ANIM_TIME, &code->anim.pos, AnimEaseIn}, 2320 - {0, OUTLINE_WIDTH, STUDIO_ANIM_TIME, &code->anim.outline, AnimEaseIn}, 2369 + {0, SIDEBAR_WIDTH, STUDIO_ANIM_TIME, &code->anim.sidebar, AnimEaseIn}, 2321 2370 }), 2322 2371 }, 2323 2372 .event = onStudioEvent,
+3 -2
src/studio/editors/code.h
··· 86 86 TEXT_DRAG_CODE, 87 87 TEXT_FIND_MODE, 88 88 TEXT_GOTO_MODE, 89 + TEXT_BOOKMARK_MODE, 89 90 TEXT_OUTLINE_MODE, 90 91 TEXT_EDIT_MODE, 91 92 } mode; ··· 110 111 s32 size; 111 112 s32 index; 112 113 s32 scroll; 113 - } outline; 114 + } sidebar; 114 115 115 116 const char* matchedDelim; 116 117 bool altFont; ··· 119 120 struct 120 121 { 121 122 s32 pos; 122 - s32 outline; 123 + s32 sidebar; 123 124 124 125 Movie* movie; 125 126