this repo has no description
0
fork

Configure Feed

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

#2526: added flags editbox (#2527)

authored by

Vadim Grigoruk and committed by
GitHub
9e2fe18f ebc2c3d5

+101 -22
+95 -22
src/studio/editors/sprite.c
··· 783 783 784 784 tic_api_print(tic, (char[]){'0' + i, '\0'}, rect.x + (Size+2), rect.y, tic_color_light_grey, false, 1, true); 785 785 } 786 + 787 + // draw flags editbox 788 + { 789 + tic_rect rect = {x, y + (Size+1)*BITS_IN_BYTE + 2, TIC_ALTFONT_WIDTH * 2 + 1, TIC_FONT_HEIGHT + 1}; 790 + 791 + if(checkMousePos(sprite->studio, &rect)) 792 + { 793 + setCursor(sprite->studio, tic_cursor_hand); 794 + 795 + if(checkMouseClick(sprite->studio, &rect, tic_mouse_left)) 796 + { 797 + sprite->flags.edit = true; 798 + sprite->flags.pos = (tic_api_mouse(tic).x - rect.x) / (TIC_ALTFONT_WIDTH + 1); 799 + } 800 + } 801 + else if(checkMouseDown(sprite->studio, &(tic_rect){0, 0, TIC80_WIDTH, TIC80_HEIGHT}, tic_mouse_left)) 802 + { 803 + sprite->flags.edit = false; 804 + } 805 + 806 + if(sprite->flags.edit) 807 + { 808 + drawPanelBorder(tic, rect.x, rect.y, rect.w, rect.h); 809 + tic_api_rect(tic, rect.x, rect.y, rect.w, rect.h, tic_color_black); 810 + 811 + tic_api_rect(tic, rect.x + sprite->flags.pos * TIC_ALTFONT_WIDTH, rect.y, TIC_ALTFONT_WIDTH + 1, rect.h, tic_color_red); 812 + } 813 + 814 + char buf[sizeof "FF"]; 815 + sprintf(buf, "%02X", and); 816 + 817 + tic_api_print(tic, buf, rect.x + 1, rect.y + 1, sprite->flags.edit ? tic_color_white : tic_color_light_grey, false, 1, true); 818 + } 786 819 } 787 820 788 821 static void switchBitMode(Sprite* sprite, tic_bpp bpp) ··· 1073 1106 1074 1107 sprite->palette.focus = mx / Width + my / Height * Cols; 1075 1108 } 1109 + } 1110 + else if(checkMouseDown(sprite->studio, &(tic_rect){0, 0, TIC80_WIDTH, TIC80_HEIGHT}, tic_mouse_left)) 1111 + { 1112 + sprite->palette.focus = -1; 1076 1113 } 1077 1114 1078 1115 bool hasFocus = sprite->palette.focus >= 0; ··· 1780 1817 if(tic_api_key(tic, tic_key_alt)) 1781 1818 return; 1782 1819 1783 - if(sprite->palette.edit) 1820 + if(sprite->palette.edit && sprite->palette.focus >= 0) 1784 1821 { 1785 - if(sprite->palette.focus >= 0) 1822 + enum{Cols = BITS_IN_BYTE / TIC_PALETTE_BPP, Rows = sizeof(tic_rgb)}; 1823 + s32 col = sprite->palette.focus % Cols; 1824 + s32 row = sprite->palette.focus / Cols; 1825 + 1826 + if(keyWasPressed(sprite->studio, tic_key_up)) --row; 1827 + else if(keyWasPressed(sprite->studio, tic_key_down)) ++row; 1828 + else if(keyWasPressed(sprite->studio, tic_key_left)) --col; 1829 + else if(keyWasPressed(sprite->studio, tic_key_right)) ++col; 1830 + else 1786 1831 { 1787 - enum{Cols = BITS_IN_BYTE / TIC_PALETTE_BPP, Rows = sizeof(tic_rgb)}; 1788 - s32 col = sprite->palette.focus % Cols; 1789 - s32 row = sprite->palette.focus / Cols; 1832 + char sym = getKeyboardText(sprite->studio); 1790 1833 1791 - if(keyWasPressed(sprite->studio, tic_key_up)) --row; 1792 - else if(keyWasPressed(sprite->studio, tic_key_down)) ++row; 1793 - else if(keyWasPressed(sprite->studio, tic_key_left)) --col; 1794 - else if(keyWasPressed(sprite->studio, tic_key_right)) ++col; 1795 - else 1834 + if(isxdigit(sym)) 1796 1835 { 1797 - char sym = getKeyboardText(sprite->studio); 1798 - 1799 - if(isxdigit(sym)) 1800 - { 1801 - u8* data = &getBankPalette(sprite->studio, sprite->palette.vbank1)->data[sprite->color * Rows + row]; 1802 - char buf[sizeof "FF"]; 1803 - sprintf(buf, "%02X", *data); 1804 - buf[col] = toupper(sym); 1805 - *data = (u8)strtol(buf, NULL, 16); 1806 - ++col; 1807 - } 1836 + u8* data = &getBankPalette(sprite->studio, sprite->palette.vbank1)->data[sprite->color * Rows + row]; 1837 + char buf[sizeof "FF"]; 1838 + sprintf(buf, "%02X", *data); 1839 + buf[col] = toupper(sym); 1840 + *data = (u8)strtol(buf, NULL, 16); 1841 + ++col; 1808 1842 } 1843 + } 1809 1844 1810 - sprite->palette.focus = (col + row * Cols + Cols * Rows) % (Cols * Rows); 1845 + sprite->palette.focus = (col + row * Cols + Cols * Rows) % (Cols * Rows); 1846 + } 1847 + else if(sprite->flags.edit) 1848 + { 1849 + if(keyWasPressed(sprite->studio, tic_key_left)) 1850 + { 1851 + if(sprite->flags.pos) 1852 + sprite->flags.pos--; 1853 + } 1854 + else if(keyWasPressed(sprite->studio, tic_key_right)) 1855 + { 1856 + if(!sprite->flags.pos) 1857 + sprite->flags.pos++; 1858 + } 1859 + else 1860 + { 1861 + char sym = getKeyboardText(sprite->studio); 1862 + 1863 + if(isxdigit(sym)) 1864 + { 1865 + u8 mask = 0xff; 1866 + 1867 + u8* flags = getBankFlags(sprite->studio)->data; 1868 + const s32* indexes = getSpriteIndexes(sprite); 1869 + 1870 + for(const s32* i = indexes; *i; i++) 1871 + mask &= flags[*i]; 1872 + 1873 + char buf[sizeof "FF"]; 1874 + sprintf(buf, "%02X", mask); 1875 + buf[sprite->flags.pos] = toupper(sym); 1876 + u8 value = strtol(buf, NULL, 16); 1877 + 1878 + for(const s32* i = indexes; *i; i++) 1879 + flags[*i] = value; 1880 + 1881 + if(!sprite->flags.pos) 1882 + sprite->flags.pos++; 1883 + } 1811 1884 } 1812 1885 } 1813 1886 else
+6
src/studio/editors/sprite.h
··· 69 69 u8* front; 70 70 } select; 71 71 72 + struct 73 + { 74 + bool edit; 75 + s32 pos; 76 + } flags; 77 + 72 78 enum 73 79 { 74 80 SPRITE_DRAW_MODE,