2
0

spriteeditor.c 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538
  1. // WORK IN PROGRESS CONVERSION....
  2. // WORK IN PROGRESS CONVERSION....
  3. //
  4. // Added - Save eveything (F5) Load everything(F6 - Very slow!!)
  5. // Added - Press p to paste 8x8 sprite back into the editor. (key 'c' to copy current sprite as c array into clipboard.
  6. // Added - Press tab to switch between sprite editor and map editor
  7. // Conversion from the Monkey2 version that I wrote.
  8. //
  9. // Todo : Add isometric/hexagon map edit/view, Fix update preview and spritelib), Floodfill(more testing), ovals!(find solution for layout), testing.
  10. #include "raylib.h"
  11. #include <math.h>
  12. #include <string.h>
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. // This one is for getting the sprite from the clipboard
  16. static int tempmap[32][32] = {0};
  17. // start setup
  18. static int weasel=0;
  19. static int startsetuppalettemode; // '0=c64 1=db32
  20. static bool startsetupdone;
  21. static int startsetupx;
  22. static int startsetupy;
  23. static int startsetupwidth;
  24. static int startsetupheight;
  25. static RenderTexture2D startsetupim[5]; //5=numstartsetup
  26. //Field startsetupcan:Canvas[]
  27. static int startsetupselected;
  28. static int startsetup8x8id;
  29. static int startsetup16x16id = 1;
  30. static int startsetup32x32id = 2;
  31. static int startsetupc64id = 3;
  32. static int startsetupdb32id = 4;
  33. static int numstartsetup = 5;
  34. //'
  35. //'tool view
  36. static int toolx;
  37. static int tooly;
  38. static int toolwidth;
  39. static int toolheight;
  40. static RenderTexture2D toolim[16]; //16 = numtools
  41. //Field toolcan:Canvas[]
  42. static bool toolgridtoggle = true;
  43. static int toolselected = 0;
  44. static int toolpencilid = 0;
  45. static int tooleraserid = 1;
  46. static int toolfillid = 2;
  47. static int toollineid = 3;
  48. static int toolselectionid = 4;
  49. static int toolcopyid = 5;
  50. static int toolpasteid = 6;
  51. static int toolcutid = 7;
  52. static int toolflipverticalid = 8;
  53. static int toolfliphorizontalid = 9;
  54. static int toolcolorpickerid = 10;
  55. static int toolgridid = 11;
  56. static int toolfilledrectid = 12;
  57. static int tooloutlinerectid = 13;
  58. static int toolfilledcircleid = 14;
  59. static int tooloutlinecircleid = 15;
  60. static int numtools = 16;
  61. static int delay;
  62. static int delaydefault = 20;
  63. //'
  64. //' sprite library
  65. static int spritelibx;
  66. static int spriteliby;
  67. static int spritelibwidth;
  68. static int spritelibheight;
  69. static int numspritelib;
  70. static RenderTexture2D spritelibim[80*4]; // 80*4 = numspritelib
  71. //Field spritelibcan:Canvas[]
  72. static int spritelibmap[80*4][32][32]; // numspritelib,
  73. static int spritelibselected = 0;
  74. static float spritelibscale;
  75. //'
  76. //'preview
  77. static RenderTexture2D previewim;
  78. //Field previewcan:Canvas
  79. static int previewx;
  80. static int previewy;
  81. static int previewwidth;
  82. static int previewheight;
  83. static int previewcellwidth;
  84. static int previewcellheight;
  85. // tile map view
  86. static int tilemapx;
  87. static int tilemapy;
  88. static int tilemapwidth;
  89. static int tilemapheight;
  90. static int tilemaptileshorizontal;
  91. static int tilemaptilesvertical;
  92. static int tilemaptilesscreenhorizontal=100;
  93. static int tilemaptilesscreenvertical=100;
  94. static int tilemap[100][100]={0};
  95. //'
  96. //'sprite view
  97. static int map[32][32]; // 8 = edit canvas width
  98. static int canvasx;
  99. static int canvasy; //'canvas x and y position on the scrern
  100. static float canvaswidth=256;
  101. static float canvasheight=256; //'width and height of our canvas
  102. static float gridwidth;
  103. static float gridheight;// ' grids width and height
  104. static int spritewidth;
  105. static int spriteheight;// ' our main sprite width and height
  106. static bool spriteviewaction=false;
  107. //' line tool fields
  108. static bool linepressed=false;
  109. static bool lineactive=false;
  110. static int linestartx;
  111. static int linestarty;
  112. static int lineendx;
  113. static int lineendy;
  114. //' Selection fields
  115. static bool selectionpressed = false ;
  116. static bool selectionactive = false;
  117. static int selectionstartx;
  118. static int selectionstarty;
  119. static int selectionendx;
  120. static int selectionendy;
  121. static int selectionbuffer[32][32]; //'our copy paste buffer
  122. static int selectionbufferstartx;
  123. static int selectionbufferstarty;
  124. static int selectionbufferendx;
  125. static int selectionbufferendy;
  126. static bool selectionnegativeswitchx = false;// ' switch if negative selection
  127. static bool selectionnegativeswitchy = false;
  128. //' filled/outlined rectsangles and circles fields
  129. static bool bcselectionpressed = false;
  130. static bool bcselectionactive = false;
  131. static int bcselectionstartx;
  132. static int bcselectionstarty;
  133. static int bcselectionendx;
  134. static int bcselectionendy;
  135. static int bcselectionbuffer[32][32];// 'our copy paste buffer
  136. static int bcselectionbufferstartx;
  137. static int bcselectionbufferstarty;
  138. static int bcselectionbufferendx;
  139. static int bcselectionbufferendy;
  140. static bool bcselectionnegativeswitchx = false; // ' switch if negative selection
  141. static bool bcselectionnegativeswitchy = false;
  142. //'
  143. //' palette
  144. static Color c64color[16]; //' our colors
  145. static Color db32color[32];// ' our colors
  146. static int paletteselected;// ' our selected color from palette
  147. static int paletteundermouse; // for floodfill
  148. static int paletteeraser;
  149. static int palettex;
  150. static int palettey; //'screen x and y
  151. static float palettewidth;
  152. static float paletteheight;// ' our palette screen w and h
  153. static float palettecellwidth;
  154. static float palettecellheight; //'cell width and height of color
  155. static int numpalette;// 'number of colors (holds the amount of the selected palette.)
  156. //'
  157. //' Top Bar
  158. static int topbarx;
  159. static int topbary;
  160. static int topbarwidth;
  161. static int topbarheight;
  162. static Color topbarcolor;
  163. static RenderTexture2D topbarim[3];
  164. //Field topbarcan:Canvas[]
  165. static int topbarspriteeditid = 0;
  166. static int topbarmapeditid = 1;
  167. static int numtopbaricons = 2;
  168. static int topbarcurrentid = 0;
  169. //'
  170. //' Middle bar
  171. static int middlebarx;
  172. static int middlebary;
  173. static int middlebarwidth;
  174. static int middlebarheight;
  175. static Color middlebarcolor;
  176. static RenderTexture2D middlebarim[4]; //nummiddlebaricons
  177. //Field middlebarcan:Canvas[]
  178. static int middlebar0id = 0;
  179. static int middlebar1id = 1;
  180. static int middlebar2id = 2;
  181. static int middlebar3id = 3;
  182. static int nummiddlebaricons = 4;
  183. static int middlebarcurrentid = 0;
  184. //'
  185. //' Bottom Bar
  186. static int bottombarx;
  187. static int bottombary;
  188. static int bottombarwidth;
  189. static int bottombarheight;
  190. static Color bottombarcolor;
  191. static void inic64colors(void);
  192. static void inidb32colors(void);
  193. static bool rectsoverlap(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2);
  194. static bool circlerectcollide(int cx,int cy,int cr,int rx,int ry,int rw,int rh);
  195. static float Clamp(float value, float min, float max);
  196. static void startsetupsetup(void);
  197. static void startsetupview(void);
  198. static void bottombarview(void);
  199. static void middlebarview();
  200. static void setupmiddlebar(void);
  201. static void setuptopbar(void);
  202. static void topbarview(void);
  203. static void setuptoolview(void);
  204. static void paletteview(void);
  205. static void spritegrid(void);
  206. static void toolview(void);
  207. static void spritelibview(void);
  208. static void spriteview(void);
  209. static void updatespritelib(void);
  210. static void updatepreview(void);
  211. static void previewview(void);
  212. static void spritelibcopytocanvas(void);
  213. static void previewline(bool drawit);
  214. static void previewselection(bool drawit);
  215. static void tilemapview(void);
  216. static void fillatposition(int x, int y,int oldcolor,int newcolor);
  217. static void midptellipse(int rx, int ry, int xc, int yc);
  218. static void loadspritelib();
  219. static void savespritelib();
  220. // for the copy from clipboard
  221. static int countcommas(char *in);
  222. static int countnumbers(char *in);
  223. static void copyfromclipboard(void);
  224. static void copytoclipboard(void);
  225. static bool importspriteis8x8(int in);
  226. static bool importspriteis16x16(int in);
  227. static bool importspriteis32x32(int in);
  228. static void readtempsprite(int w,int h,char *in);
  229. int main(void)
  230. {
  231. // Initialization
  232. //--------------------------------------------------------------------------------------
  233. const int screenWidth = 640;
  234. const int screenHeight = 480;
  235. InitWindow(screenWidth, screenHeight, "raylib example.");
  236. //ToggleFullscreen();
  237. //'start setup setup
  238. //' be sure to start the editor with the selection
  239. startsetupdone=false;
  240. startsetupx = 320-80;
  241. startsetupy = 150;
  242. startsetupwidth = 150;
  243. startsetupheight = 200-35;
  244. //startsetupim = New Image[numstartsetup];
  245. //startsetupcan = New Canvas[numstartsetup]
  246. for(int i=0;i<numstartsetup;i++){
  247. startsetupim[i] = LoadRenderTexture(32, 32);
  248. BeginTextureMode(startsetupim[i]);
  249. ClearBackground(BLANK); // Make the entire Sprite Transparent.
  250. EndTextureMode();
  251. //startsetupcan[i] = New Canvas(startsetupim[i])
  252. }
  253. inic64colors();
  254. inidb32colors();
  255. startsetupsetup();
  256. paletteeraser = 0;
  257. palettex = 640-150;
  258. palettey = 32;
  259. palettewidth = 32*4;
  260. paletteheight = 32*4;
  261. numpalette = 16;
  262. palettecellwidth = 32;
  263. palettecellheight = 32;
  264. //sprite canvas setup
  265. canvasx = 32;
  266. canvasy = 28;
  267. //spritewidth = 16;
  268. //spriteheight = 16;
  269. //map = New Int[spritewidth,spriteheight]
  270. //selectionbuffer = New Int[spritewidth,spriteheight]
  271. canvaswidth=256;
  272. canvasheight=256;
  273. // gridwidth = canvaswidth/spritewidth;
  274. // gridheight = canvasheight/spriteheight;
  275. //'Bottom bar (global)
  276. bottombarx = 0;
  277. bottombary = 480-24;
  278. bottombarwidth = 640;
  279. bottombarheight = 24;
  280. bottombarcolor = (Color){ 78, 22, 9,255 };//Color.Puce
  281. //'
  282. //' Middle bar
  283. middlebarx = 0;
  284. middlebary = canvasheight+32;
  285. middlebarwidth = 640;
  286. middlebarheight = 32;
  287. middlebarcolor = GRAY;
  288. nummiddlebaricons = 4;
  289. //middlebarim = New Image[nummiddlebaricons]
  290. //middlebarcan = New Canvas[nummiddlebaricons]
  291. for(int i=0;i<nummiddlebaricons;i++){
  292. middlebarim[i] = LoadRenderTexture(32, 32);
  293. BeginTextureMode(middlebarim[i]);
  294. ClearBackground(BLANK);
  295. EndTextureMode();
  296. //middlebarcan[i] = New Canvas(middlebarim[i])
  297. }
  298. setupmiddlebar();
  299. //Top bar (global)
  300. topbarx = 0;
  301. topbary = 0;
  302. topbarwidth = 640;
  303. topbarheight = 24;
  304. topbarcolor = (Color){ 78, 22, 9,255};//Color.Puce
  305. //topbarim = New Image[3]
  306. //topbarcan = New Canvas[3]
  307. for(int i=0;i<2;i++){
  308. topbarim[i] = LoadRenderTexture(32, 32);
  309. BeginTextureMode(topbarim[i]);
  310. ClearBackground(BLANK);
  311. EndTextureMode();
  312. }
  313. setuptopbar();
  314. //'
  315. //'spritelib setup
  316. spritelibx = 0;
  317. spriteliby = canvasheight+32+32;
  318. spritelibwidth = 640;
  319. spritelibheight = 128;
  320. numspritelib = 80*4;
  321. spritelibselected = 0;
  322. spritelibscale = 2;
  323. //spritelibim = New Image[numspritelib]
  324. //spritelibcan = New Canvas[numspritelib]
  325. // For Local i:Int=0 Until numspritelib
  326. // spritelibim[i] = New Image(spritewidth*spritelibscale,spriteheight*spritelibscale)
  327. // spritelibcan[i] = New Canvas(spritelibim[i])
  328. // spritelibcan[i].Clear(Color.Black)
  329. // spritelibcan[i].Flush()
  330. // Next
  331. for(int i=0;i<numspritelib;i++){
  332. spritelibim[i] = LoadRenderTexture(32, 32);
  333. BeginTextureMode(spritelibim[i]);
  334. ClearBackground(BLANK);
  335. EndTextureMode();
  336. }
  337. //' tool view
  338. toolx = 340;
  339. tooly = 186-32;
  340. toolwidth = 32*4;
  341. toolheight = 32*4;
  342. //'numtools = 12
  343. //toolim = New Image[numtools]
  344. //toolcan = New Canvas[numtools]
  345. for(int i=0;i<numtools;i++){
  346. toolim[i] = LoadRenderTexture(32,32);
  347. BeginTextureMode(toolim[i]);
  348. ClearBackground(BLANK);
  349. EndTextureMode();
  350. //toolcan[i] = New Canvas(toolim[i])
  351. //toolcan[i].Clear(Color.Black)
  352. //toolcan[i].Flush()
  353. }
  354. setuptoolview();
  355. //' previewview setup
  356. previewx = 640-100;
  357. previewy = 200;
  358. previewcellwidth = 2;
  359. previewcellheight = 2;
  360. previewwidth = 64;
  361. previewheight = 64;
  362. previewim = LoadRenderTexture(previewwidth,previewheight);//New Image(previewwidth,previewheight)
  363. BeginTextureMode(previewim);
  364. ClearBackground(BLANK);
  365. EndTextureMode();
  366. //previewcan = New Canvas(previewim)
  367. updatepreview();
  368. //tilemap setup
  369. tilemapx = 0;
  370. tilemapy = 32;
  371. tilemaptileshorizontal = 100;
  372. tilemaptilesvertical = 100;
  373. tilemapwidth = 640;
  374. tilemapheight= 256;
  375. //tilemaptilesscreenhorizontal = tilemapwidth/(spritewidth*spritelibscale);
  376. //tilemaptilesscreenvertical = tilemapheight/(spriteheight*spritelibscale);
  377. //tilemap = New Int[tilemaptileshorizontal,tilemaptilesvertical]
  378. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  379. //--------------------------------------------------------------------------------------
  380. int timeupd=0; // update what is being drawn into preview window and lib
  381. // Main game loop
  382. while (!WindowShouldClose()) // Detect window close button or ESC key
  383. {
  384. // Update
  385. //----------------------------------------------------------------------------------
  386. //----------------------------------------------------------------------------------
  387. // Draw
  388. //----------------------------------------------------------------------------------
  389. BeginDrawing();
  390. ClearBackground(DARKGRAY);
  391. //' We start the sprite editor with the sprite dimension
  392. //' resolution selection.
  393. if(startsetupdone==false){
  394. startsetupview();
  395. }else{
  396. //' Here is the map and sprite editor section
  397. if(topbarcurrentid == topbarspriteeditid){
  398. bottombarview();
  399. middlebarview();
  400. topbarview();
  401. spriteview();
  402. previewline(false);
  403. spritegrid();
  404. previewselection(false);
  405. paletteview();
  406. previewview();
  407. spritelibview();
  408. toolview();
  409. // The editing got a little slow with the update so here
  410. // it now updates the preview and lib every 100 frames.
  411. timeupd++;
  412. if(timeupd>100){
  413. updatepreview();
  414. updatespritelib();
  415. timeupd=0;
  416. }
  417. }else if(topbarcurrentid == topbarmapeditid){
  418. tilemapview();
  419. bottombarview();
  420. middlebarview();
  421. topbarview();
  422. spritelibview();
  423. }
  424. }
  425. DrawText(FormatText("%i",weasel),0,0,20,BLACK);
  426. EndDrawing();
  427. //----------------------------------------------------------------------------------
  428. }
  429. // De-Initialization
  430. //--------------------------------------------------------------------------------------
  431. for(int i=0;i<numstartsetup;i++){
  432. UnloadRenderTexture(startsetupim[i]);
  433. }
  434. for(int i=0;i<numtools;i++){
  435. UnloadRenderTexture(toolim[i]);
  436. }
  437. for(int i=0;i<numspritelib;i++){
  438. UnloadRenderTexture(spritelibim[i]);
  439. }
  440. UnloadRenderTexture(previewim);
  441. for(int i=0;i<2;i++){
  442. UnloadRenderTexture(topbarim[i]);
  443. }
  444. for(int i=0;i<4;i++){
  445. UnloadRenderTexture(middlebarim[i]);
  446. }
  447. CloseWindow(); // Close window and OpenGL context
  448. //--------------------------------------------------------------------------------------
  449. return 0;
  450. }
  451. void inic64colors(void){
  452. c64color[0 ] = (Color){0 , 0 , 0 , 255 };//Black
  453. c64color[1 ] = (Color){255,255,255, 255 };//White
  454. c64color[2 ] = (Color){136,0 ,0 , 255 };//Red
  455. c64color[3 ] = (Color){170,255,238, 255 };//Cyan
  456. c64color[4 ] = (Color){204,68 ,204, 255 };//Violet / Purple
  457. c64color[5 ] = (Color){0 ,204,85 , 255 };//Green
  458. c64color[6 ] = (Color){0 ,0 ,170, 255 };//Blue
  459. c64color[7 ] = (Color){238,238,119, 255 };//Yellow
  460. c64color[8 ] = (Color){221,136,85 , 255 };//Orange
  461. c64color[9 ] = (Color){102,68 ,0 , 255 };//Brown
  462. c64color[10] = (Color){255,119,119, 255 };//Light red
  463. c64color[11] = (Color){51 ,51 ,51 , 255 };//Dark grey / Grey 1
  464. c64color[12] = (Color){119,119,119, 255 };//Grey 2
  465. c64color[13] = (Color){170,255,102, 255 };//Light green
  466. c64color[14] = (Color){0 ,136,255, 255 };//Light blue
  467. c64color[15] = (Color){187,187,187, 255 };//Light grey / grey 3
  468. }
  469. void inidb32colors(){
  470. db32color[0 ] = (Color){0 ,0 ,0 ,255};
  471. db32color[1 ] = (Color){34 ,32 ,52 ,255};
  472. db32color[2 ] = (Color){69 ,40 ,60 ,255};
  473. db32color[3 ] = (Color){102 ,57 ,49 ,255};
  474. db32color[4 ] = (Color){143 ,86 ,59 ,255};
  475. db32color[5 ] = (Color){223 ,113 ,38 ,255};
  476. db32color[6 ] = (Color){217 ,160 ,102 ,255};
  477. db32color[7 ] = (Color){238 ,195 ,154 ,255};
  478. db32color[8 ] = (Color){251 ,242 ,54 ,255};
  479. db32color[9 ] = (Color){153 ,229 ,80 ,255};
  480. db32color[10] = (Color){106 ,190 ,48 ,255};
  481. db32color[11] = (Color){55 ,148 ,110 ,255};
  482. db32color[12] = (Color){75 ,105 ,47 ,255};
  483. db32color[13] = (Color){82 ,75 ,36 ,255};
  484. db32color[14] = (Color){50 ,60 ,57 ,255};
  485. db32color[15] = (Color){63 ,63 ,116 ,255};
  486. db32color[16] = (Color){48 ,96 ,130 ,255};
  487. db32color[17] = (Color){91 ,110 ,225 ,255};
  488. db32color[18] = (Color){99 ,155 ,225 ,255};
  489. db32color[19] = (Color){95 ,205 ,228 ,255};
  490. db32color[20] = (Color){203 ,219 ,252 ,255};
  491. db32color[21] = (Color){255 ,255 ,255 ,255};
  492. db32color[22] = (Color){155 ,173 ,183 ,255};
  493. db32color[23] = (Color){132 ,126 ,135 ,255};
  494. db32color[24] = (Color){105 ,106 ,106 ,255};
  495. db32color[25] = (Color){89 ,86 ,82 ,255};
  496. db32color[26] = (Color){118 ,66 ,138 ,255};
  497. db32color[27] = (Color){172 ,50 ,50 ,255};
  498. db32color[28] = (Color){217 ,87 ,99 ,255};
  499. db32color[29] = (Color){215 ,123 ,186 ,255};
  500. db32color[30] = (Color){143 ,151 ,74 ,255};
  501. db32color[31] = (Color){138 ,111 ,48 ,255};
  502. }
  503. void startsetupsetup(){
  504. // the 8x8 selection button
  505. int eightxeight[16][16] = {
  506. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  507. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  508. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  509. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  510. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  511. {12,12,1,1,1,12,12,12,12,12,1,1,1,12,12,12},
  512. {12,12,1,12,1,12,1,12,1,12,1,12,1,12,12,12},
  513. {12,12,1,1,1,12,12,1,12,12,1,1,1,12,12,12},
  514. {12,12,1,12,1,12,1,12,1,12,1,12,1,12,12,12},
  515. {12,12,1,1,1,12,12,12,12,12,1,1,1,12,12,12},
  516. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  517. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  518. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  519. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  520. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  521. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}};
  522. for(int y=0;y<16;y++){
  523. for(int x=0;x<16;x++){
  524. BeginTextureMode(startsetupim[startsetup8x8id]);
  525. //startsetupcan[startsetup8x8id].Color = c64color[eightxeight[y][x]]
  526. //If eightxeight[y][x] = 0 Then startsetupcan[startsetup8x8id].Alpha=0 Else startsetupcan[startsetup8x8id].Alpha=1
  527. //startsetupcan[startsetup8x8id].DrawRect(x*2,y*2,2,2)
  528. if(eightxeight[y][x]>0)DrawRectangle(x*2,y*2,2,2,c64color[eightxeight[y][x]]);
  529. EndTextureMode();
  530. }}
  531. //startsetupcan[startsetup8x8id].Flush()
  532. //the 16x16 selection button
  533. int sixteenxsixteen[16][16] = {
  534. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  535. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  536. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  537. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  538. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  539. {1,12,1,1,1,12,12,12,12,12,1,12,1,1,1,12},
  540. {1,12,1,12,12,12,1,12,1,12,1,12,1,12,12,12},
  541. {1,12,1,1,1,12,12,1,12,12,1,12,1,1,1,12},
  542. {1,12,1,12,1,12,1,12,1,12,1,12,1,12,1,12},
  543. {1,12,1,1,1,12,12,12,12,12,1,12,1,1,1,12},
  544. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  545. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  546. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  547. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  548. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  549. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}};
  550. for(int y=0;y<16;y++){
  551. for(int x=0;x<16;x++){
  552. BeginTextureMode(startsetupim[startsetup16x16id]);
  553. //startsetupcan[startsetup16x16id].Color = c64color[sixteenxsixteen[y][x]]
  554. //If sixteenxsixteen[y][x] = 0 Then startsetupcan[startsetup16x16id].Alpha=0 Else startsetupcan[startsetup16x16id].Alpha=1
  555. if(sixteenxsixteen[15-y][x]>0)DrawRectangle(x*2,y*2,2,2,c64color[sixteenxsixteen[15-y][x]]);
  556. //startsetupcan[startsetup16x16id].DrawRect(x*2,y*2,2,2)
  557. EndTextureMode();
  558. }}
  559. //startsetupcan[startsetup16x16id].Flush()
  560. // the 32x32 selection button
  561. int thirtytwoxthirtytwo[16][16] = {
  562. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  563. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  564. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  565. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  566. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  567. {1,1,12,1,1,12,12,12,12,12,1,1,12,1,1,12},
  568. {12,1,12,12,1,12,1,12,1,12,12,1,12,12,1,12},
  569. {1,1,12,1,1,12,12,1,12,12,1,1,12,1,1,12},
  570. {12,1,12,1,12,12,1,12,1,12,12,1,12,1,12,12},
  571. {1,1,12,1,1,12,12,12,12,12,1,1,12,1,1,12},
  572. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  573. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  574. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  575. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  576. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  577. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}};
  578. for(int y=0;y<16;y++){
  579. for(int x=0;x<16;x++){
  580. BeginTextureMode(startsetupim[startsetup32x32id]);
  581. //startsetupcan[startsetup32x32id].Color = c64color[thirtytwoxthirtytwo[y][x]]
  582. //If thirtytwoxthirtytwo[y][x] = 0 Then startsetupcan[startsetup32x32id].Alpha=0 Else startsetupcan[startsetup32x32id].Alpha=1
  583. //startsetupcan[startsetup32x32id].DrawRect(x*2,y*2,2,2)
  584. if(thirtytwoxthirtytwo[15-y][x]>0)DrawRectangle(x*2,y*2,2,2,c64color[thirtytwoxthirtytwo[15-y][x]]);
  585. EndTextureMode();
  586. }}
  587. //startsetupcan[startsetup32x32id].Flush()
  588. // the c64 palette selection button
  589. int c641616[16][16] = {
  590. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  591. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  592. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  593. {12,12,1,1,12,12,12,1,1,12,12,1,12,12,12,12},
  594. {12,1,12,12,12,12,1,12,12,12,12,1,12,12,12,12},
  595. {12,1,12,12,12,12,1,12,12,12,12,1,12,12,1,12},
  596. {12,1,12,12,12,12,1,1,1,12,12,1,1,1,1,12},
  597. {12,1,12,12,12,12,1,12,12,1,12,12,12,12,1,12},
  598. {12,1,12,12,12,12,1,12,12,1,12,12,12,12,1,12},
  599. {12,12,1,1,12,12,12,1,1,12,12,12,12,12,1,12},
  600. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  601. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  602. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  603. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  604. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  605. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}};
  606. for(int y=0;y<16;y++){
  607. for(int x=0;x<16;x++){
  608. BeginTextureMode(startsetupim[startsetupc64id]);
  609. //startsetupcan[startsetupc64id].Color = c64color[c641616[y][x]]
  610. //If c641616[y][x] = 0 Then startsetupcan[startsetupc64id].Alpha=0 Else startsetupcan[startsetupc64id].Alpha=1
  611. //startsetupcan[startsetupc64id].DrawRect(x*2,y*2,2,2)
  612. if(c641616[15-y][x]>0)DrawRectangle(x*2,y*2,2,2,c64color[c641616[15-y][x]]);
  613. EndTextureMode();
  614. }}
  615. //startsetupcan[startsetupc64id].Flush()
  616. // the db32 palette selection button
  617. int db321616[16][16] = {
  618. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  619. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  620. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  621. {12,12,1,12,1,12,12,12,1,1,12,12,1,1,1,12},
  622. {12,12,1,12,1,12,12,12,12,12,1,12,12,12,1,12},
  623. {12,12,1,12,1,12,12,12,12,12,1,12,12,12,1,12},
  624. {12,1,1,12,1,1,12,12,1,1,12,12,1,1,1,12},
  625. {1,12,1,12,1,12,1,12,12,12,1,12,1,12,12,12},
  626. {1,12,1,12,1,12,1,12,12,12,1,12,1,12,12,12},
  627. {1,1,1,12,1,1,1,12,1,1,12,12,1,1,1,12},
  628. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  629. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  630. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  631. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  632. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  633. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}};
  634. for(int y=0;y<16;y++){
  635. for(int x=0;x<16;x++){
  636. BeginTextureMode(startsetupim[startsetupdb32id]);
  637. //startsetupcan[startsetupdb32id].Color = c64color[db321616[y][x]]
  638. //If db321616[y][x] = 0 Then startsetupcan[startsetupdb32id].Alpha=0 Else startsetupcan[startsetupdb32id].Alpha=1
  639. //startsetupcan[startsetupdb32id].DrawRect(x*2,y*2,2,2)
  640. if(db321616[15-y][x]>0)DrawRectangle(x*2,y*2,2,2,c64color[db321616[15-y][x]]);
  641. EndTextureMode();
  642. }}
  643. //startsetupcan[startsetupdb32id].Flush()
  644. }
  645. void startsetupview(){
  646. //canvas.Color = Color.Black
  647. DrawRectangle(startsetupx-1,startsetupy-1,startsetupwidth+2,startsetupheight+2,BLACK);
  648. //canvas.Color = c64color[12]
  649. DrawRectangle(startsetupx,startsetupy,startsetupwidth,startsetupheight,c64color[12]);
  650. //Local selected:Bool=False
  651. bool selected = false;
  652. for(int i=0;i<3;i++){
  653. //canvas.Color = Color.Grey.Blend(Color.Black,.5)
  654. //DrawRectangle(startsetupx+8+20,startsetupy+8+i*48,32,32,GRAY);
  655. //canvas.Color = Color.White
  656. DrawTexture(startsetupim[i].texture,startsetupx+9+20,startsetupy+9+i*48,WHITE);
  657. //' draw the palette buttons
  658. //canvas.Color = Color.Black
  659. //DrawRectangle(startsetupx+8+50,startsetupy+8+i*48,32,32,BLACK);
  660. //canvas.Color = Color.White
  661. //DrawTexture(startsetupim[3],startsetupx+9+50,startsetupy+9+i*48,0,.9,.9)
  662. DrawTexture(startsetupim[3].texture,startsetupx+9+60,startsetupy+9+i*48,WHITE);
  663. //canvas.Color = Color.Black
  664. //DrawRectangle(startsetupx+8+80,startsetupy+8+i*48,32,32,BLACK);
  665. //canvas.Color = Color.White
  666. DrawTexture(startsetupim[4].texture,startsetupx+9+100,startsetupy+9+i*48,WHITE);
  667. if(IsMouseButtonDown(0)){
  668. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,startsetupx+9+60,startsetupy+9+i*48,32,32)){
  669. startsetupselected = i;
  670. startsetuppalettemode = 0;
  671. selected = true;
  672. }
  673. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,startsetupx+9+100,startsetupy+9+i*48,32,32)){
  674. startsetupselected = i;
  675. startsetuppalettemode = 1;
  676. selected = true;
  677. }
  678. }
  679. }
  680. if(selected == true){
  681. if(startsetuppalettemode == 1){// ' if the db32 palette was selected
  682. paletteeraser = 0;
  683. palettex = 640-150;
  684. palettey = 32;
  685. palettewidth = 32*4;
  686. paletteheight = 32*4;
  687. numpalette = 32;
  688. palettecellwidth = 32*4/4;
  689. palettecellheight = 32*4/8;
  690. }
  691. switch (startsetupselected){
  692. case 0:
  693. spritelibscale = 4;
  694. spritewidth = 8;
  695. spriteheight = 8;
  696. //map = New Int[spritewidth,spriteheight]
  697. //selectionbuffer = New Int[spritewidth,spriteheight];
  698. gridwidth = canvaswidth/spritewidth;
  699. gridheight = canvasheight/spriteheight;
  700. //weasel = tilemaptilesscreenhorizontal;
  701. //spritelibmap = New Int[numspritelib,spritewidth,spriteheight];
  702. break;
  703. case 1:
  704. spritelibscale = 2;
  705. spritewidth = 16;
  706. spriteheight = 16;
  707. //map = New Int[spritewidth,spriteheight];
  708. //selectionbuffer = New Int[spritewidth,spriteheight];
  709. gridwidth = canvaswidth/spritewidth;
  710. gridheight = canvasheight/spriteheight;
  711. //spritelibmap = New Int[numspritelib,spritewidth,spriteheight];
  712. break;
  713. case 2:
  714. spritelibscale = 1;
  715. spritewidth = 32;
  716. spriteheight = 32;
  717. //map = New Int[spritewidth,spriteheight];
  718. //selectionbuffer = New Int[spritewidth,spriteheight];
  719. gridwidth = canvaswidth/spritewidth;
  720. gridheight = canvasheight/spriteheight;
  721. //spritelibmap = New Int[numspritelib,spritewidth,spriteheight];
  722. break;
  723. }
  724. startsetupdone = true;
  725. }
  726. }
  727. void bottombarview(){
  728. //canvas.Color = bottombarcolor
  729. DrawRectangle(bottombarx,bottombary,bottombarwidth,bottombarheight,bottombarcolor);
  730. //canvas.Color = bottombarcolor/2
  731. DrawRectangle(bottombarx,bottombary+bottombarheight/2,bottombarwidth,bottombarheight/2,(Color){50,5,2,255});
  732. }
  733. void middlebarview(){
  734. //canvas.Color = middlebarcolor
  735. DrawRectangle(middlebarx,middlebary,middlebarwidth,middlebarheight,middlebarcolor);
  736. //canvas.Color = middlebarcolor/2
  737. DrawRectangle(middlebarx,middlebary+middlebarheight/2,middlebarwidth,middlebarheight/2,DARKGRAY);
  738. //' Draw the icons ..
  739. int num = 0;
  740. for(int x = 640-128;x<640;x+=32){
  741. if(num>=nummiddlebaricons)continue;
  742. int pointx=x+middlebarx;
  743. int pointy=middlebary;
  744. if(middlebarcurrentid == num){
  745. //canvas.Color=Color.White
  746. DrawTexture(middlebarim[num].texture,pointx,pointy,WHITE);
  747. }else{
  748. DrawTexture(middlebarim[num].texture,pointx,pointy,DARKGRAY);
  749. //canvas.Color=Color.DarkGrey
  750. }
  751. //canvas.DrawImage(middlebarim[num],pointx,pointy)
  752. //'
  753. //' Selection of the sprite editor or the map editor
  754. if(spriteviewaction==false && IsMouseButtonDown(0)){
  755. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,32,32)){
  756. middlebarcurrentid = num;
  757. }
  758. }
  759. num+=1;
  760. }
  761. }
  762. void setupmiddlebar(){
  763. int zero[8][8]={
  764. {0,12,12,12,12,12,12,0},
  765. {12,12,12,1,1,1,12,12},
  766. {12,12,12,1,12,1,12,12},
  767. {12,12,12,1,12,1,12,12},
  768. {12,12,12,1,12,1,12,12},
  769. {12,12,12,1,1,1,12,12},
  770. {12,12,12,12,12,12,12,12},
  771. {12,12,12,12,12,12,12,12}};
  772. for(int y=0;y<8;y++){
  773. for(int x=0;x<8;x++){
  774. //middlebarcan[middlebar0id].Color = c64color[zero[y][x]]
  775. //If zero[y][x] = 0 Then middlebarcan[middlebar0id].Alpha=0 Else middlebarcan[middlebar0id].Alpha=1
  776. BeginTextureMode(middlebarim[middlebar0id]);
  777. DrawRectangle(x*4,y*4,4,4,c64color[zero[7-y][x]]);
  778. EndTextureMode();
  779. }}
  780. //middlebarcan[middlebar0id].Flush()
  781. int one[8][8]={
  782. {0,12,12,12,12,12,12,0},
  783. {12,12,12,1,1,12,12,12},
  784. {12,12,12,12,1,12,12,12},
  785. {12,12,12,12,1,12,12,12},
  786. {12,12,12,12,1,12,12,12},
  787. {12,12,12,1,1,1,12,12},
  788. {12,12,12,12,12,12,12,12},
  789. {12,12,12,12,12,12,12,12}};
  790. for(int y=0;y<8;y++){
  791. for(int x=0;x<8;x++){
  792. //middlebarcan[middlebar1id].Color = c64color[one[y][x]]
  793. //If one[y][x] = 0 Then middlebarcan[middlebar1id].Alpha=0 Else middlebarcan[middlebar1id].Alpha=1
  794. BeginTextureMode(middlebarim[middlebar1id]);
  795. DrawRectangle(x*4,y*4,4,4,c64color[one[7-y][x]]);
  796. EndTextureMode();
  797. }}
  798. //middlebarcan[middlebar1id].Flush()
  799. int two[8][8]={
  800. {0,12,12,12,12,12,12,0},
  801. {12,12,12,1,1,1,12,12},
  802. {12,12,12,12,12,1,12,12},
  803. {12,12,12,12,1,12,12,12},
  804. {12,12,12,1,12,12,12,12},
  805. {12,12,12,1,1,1,12,12},
  806. {12,12,12,12,12,12,12,12},
  807. {12,12,12,12,12,12,12,12}};
  808. for(int y=0;y<8;y++){
  809. for(int x=0;x<8;x++){
  810. //middlebarcan[middlebar2id].Color = c64color[two[y][x]]
  811. //If two[y][x] = 0 Then middlebarcan[middlebar2id].Alpha=0 Else middlebarcan[middlebar2id].Alpha=1
  812. BeginTextureMode(middlebarim[middlebar2id]);
  813. DrawRectangle(x*4,y*4,4,4,c64color[two[7-y][x]]);
  814. EndTextureMode();
  815. }}
  816. //middlebarcan[middlebar2id].Flush()
  817. int three[8][8]={
  818. {0,12,12,12,12,12,12,0},
  819. {12,12,12,1,1,1,12,12},
  820. {12,12,12,12,12,1,12,12},
  821. {12,12,12,12,1,1,12,12},
  822. {12,12,12,12,12,1,12,12},
  823. {12,12,12,1,1,1,12,12},
  824. {12,12,12,12,12,12,12,12},
  825. {12,12,12,12,12,12,12,12}};
  826. for(int y=0;y<8;y++){
  827. for(int x=0;x<8;x++){
  828. //middlebarcan[middlebar3id].Color = c64color[three[y][x]]
  829. //If three[y][x] = 0 Then middlebarcan[middlebar3id].Alpha=0 Else middlebarcan[middlebar3id].Alpha=1
  830. BeginTextureMode(middlebarim[middlebar3id]);
  831. DrawRectangle(x*4,y*4,4,4,c64color[three[7-y][x]]);
  832. EndTextureMode();
  833. }}
  834. //middlebarcan[middlebar3id].Flush()
  835. }
  836. void setuptopbar(){
  837. int mapedit[8][8] = {
  838. {1,1,1,0,0,1,1,0},
  839. {1,1,1,0,0,1,1,0},
  840. {1,1,1,0,0,0,0,0},
  841. {0,0,0,1,1,1,1,1},
  842. {1,1,0,1,1,1,1,1},
  843. {1,1,0,1,1,1,1,1},
  844. {0,0,0,1,1,1,1,1},
  845. {0,0,0,1,1,1,1,1}};
  846. for(int y=0;y<8;y++){
  847. for(int x=0;x<8;x++){
  848. //topbarcan[topbarmapeditid].Color = c64color[mapedit[y][x]]
  849. //If mapedit[y][x] = 0 Then topbarcan[topbarmapeditid].Alpha=0 Else topbarcan[topbarmapeditid].Alpha=1
  850. BeginTextureMode(topbarim[topbarmapeditid]);
  851. if(mapedit[7-y][x]>0)DrawRectangle(x*4,y*4,4,4,c64color[mapedit[7-y][x]]);
  852. EndTextureMode();
  853. }}
  854. //topbarcan[topbarmapeditid].Flush()
  855. int spriteedit[8][8] = {
  856. {1,0,0,0,0,0,0,1},
  857. {0,1,0,0,0,0,1,0},
  858. {0,1,0,1,1,0,1,0},
  859. {0,0,1,1,1,1,0,0},
  860. {0,1,1,0,0,1,1,0},
  861. {0,1,1,1,1,1,1,0},
  862. {0,0,1,1,1,1,0,0},
  863. {0,1,0,1,1,0,1,0}};
  864. for(int y=0;y<8;y++){
  865. for(int x=0;x<8;x++){
  866. //topbarcan[topbarspriteeditid].Color = c64color[spriteedit[y][x]]
  867. //If spriteedit[y][x] = 0 Then topbarcan[topbarspriteeditid].Alpha=0 Else topbarcan[topbarspriteeditid].Alpha=1
  868. BeginTextureMode(topbarim[topbarspriteeditid]);
  869. if(spriteedit[7-y][x]>0)DrawRectangle(x*4,y*4,4,4,c64color[spriteedit[7-y][x]]);
  870. EndTextureMode();
  871. }}
  872. //topbarcan[topbarspriteeditid].Flush()
  873. }
  874. void topbarview(){
  875. //canvas.Color = topbarcolor
  876. DrawRectangle(topbarx,topbary,topbarwidth,topbarheight,topbarcolor);
  877. //canvas.Color = topbarcolor/2
  878. DrawRectangle(topbarx,topbary+topbarheight/2,topbarwidth,topbarheight/2,(Color){50,5,2,255});
  879. //'
  880. //' Draw the icons ..
  881. int num = 0;
  882. for(int x=640-200;x<640;x+=32){
  883. if(num>=numtopbaricons) continue;
  884. int pointx=x+topbarx;
  885. int pointy=topbary+3;
  886. if(topbarcurrentid == num){
  887. //canvas.Color=Color.White
  888. DrawTextureEx(topbarim[num].texture,(Vector2){pointx,pointy},0,0.6f,WHITE);
  889. }else{
  890. DrawTextureEx(topbarim[num].texture,(Vector2){pointx,pointy},0,0.6f,DARKGRAY);
  891. //canvas.Color=Color.DarkGrey
  892. }
  893. //canvas.DrawImage(topbarim[num],pointx,pointy,0,.6,.6)
  894. //'
  895. //' Selection of the sprite editor or the map editor
  896. if(spriteviewaction==false && IsMouseButtonDown(0)){
  897. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,32,32)){
  898. topbarcurrentid = num;
  899. }
  900. }
  901. num+=1;
  902. }
  903. }
  904. void paletteview(){
  905. //canvas.Color = Color.Black
  906. DrawRectangle(palettex,palettey,palettewidth,paletteheight,BLACK);
  907. //canvas.Scissor = New Recti(palettex+2,palettey+2,palettex+2+palettewidth-4,palettey+2+paletteheight-4)
  908. //canvas.Color = Color.White
  909. int cc=0;
  910. for(int y=0;y<paletteheight;y+=palettecellheight){
  911. for(int x=0;x<palettewidth;x+=palettecellwidth){
  912. if(cc>=numpalette)break;
  913. float pointx=x+palettex;
  914. float pointy=y+palettey;
  915. //'
  916. //' Draw our color
  917. if(startsetuppalettemode == 0){
  918. //canvas.Color = c64color[cc]
  919. DrawRectangle(pointx,pointy,palettecellwidth,palettecellheight,c64color[cc]);
  920. }else{
  921. //canvas.Color = db32color[cc]
  922. DrawRectangle(pointx,pointy,palettecellwidth,palettecellheight,db32color[cc]);
  923. }
  924. //canvas.DrawRect(pointx,pointy,palettecellwidth,palettecellheight)
  925. //'
  926. //' Draw a white bar around the currently selected color
  927. if(paletteselected == cc){
  928. //canvas.OutlineMode = OutlineMode.Solid
  929. //canvas.OutlineWidth = 3
  930. //canvas.OutlineColor = Color.Black
  931. //canvas.DrawRect(pointx+2,pointy+2,palettecellwidth-4,palettecellheight-4)
  932. DrawRectangleLinesEx((Rectangle){pointx+2,pointy+2,palettecellwidth-4,palettecellheight-4}, 3, BLACK);
  933. //canvas.OutlineMode = OutlineMode.Solid
  934. //canvas.OutlineWidth = 1
  935. //canvas.OutlineColor = Color.Yellow
  936. //canvas.DrawRect(pointx+2,pointy+2,palettecellwidth-4,palettecellheight-4)
  937. DrawRectangleLinesEx((Rectangle){pointx+2,pointy+2,palettecellwidth-4,palettecellheight-4}, 1, YELLOW);
  938. //canvas.OutlineMode = OutlineMode.None
  939. }
  940. //'
  941. //' Select our color
  942. if(spriteviewaction==false && IsMouseButtonDown(0)){
  943. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,palettecellwidth,palettecellheight)){
  944. paletteselected = cc;
  945. }
  946. }
  947. //'
  948. cc+=1;
  949. }}
  950. //canvas.Scissor = New Recti(0,0,640,480)
  951. //'canvas.Color = c64color[2]
  952. }
  953. void spritegrid(){
  954. //' If grid noview then exit this method
  955. if(toolgridtoggle == false)return;
  956. //' draw our grid
  957. //canvas.Color = Color.Grey
  958. for(int y=0;y<spriteheight;y++){
  959. for(int x=0;x<spritewidth;x++){
  960. int pointx=(x*gridwidth)+canvasx;
  961. int pointy=(y*gridheight)+canvasy;
  962. DrawLine(pointx,pointy,pointx+gridwidth,pointy,GRAY);
  963. DrawLine(pointx,pointy,pointx,pointy+gridheight,GRAY);
  964. }}
  965. }
  966. void setuptoolview(){
  967. //'read icons
  968. int pencil[8][8] = {
  969. {12,12,12,12,12,12,12,12},
  970. {12,1,1,1,1,12,12,12},
  971. {12,1,1,1,12,1,12,12},
  972. {12,1,1,12,1,1,1,12},
  973. {12,1,12,1,1,1,1,1},
  974. {12,12,1,1,1,1,1,1},
  975. {12,12,12,1,1,1,1,1},
  976. {12,12,12,12,1,1,1,1}};
  977. for(int y=0;y<8;y++){
  978. for(int x=0;x<8;x++){
  979. //toolcan[toolpencilid].Color = c64color[pencil[y][x]]
  980. BeginTextureMode(toolim[toolpencilid]);
  981. DrawRectangle(x*4,y*4,4,4,c64color[pencil[7-y][x]]);
  982. EndTextureMode();
  983. }
  984. }
  985. //toolcan[toolpencilid].Flush()
  986. int eraser[8][8] = {
  987. {12,12,12,12,12,12,12,12},
  988. {12,12,12,1,12,12,12,12},
  989. {12,12,1,1,1,12,12,12},
  990. {12,1,1,12,1,1,12,12},
  991. {12,12,1,1,12,1,1,12},
  992. {12,12,12,1,1,1,12,12},
  993. {12,12,12,12,1,12,12,12},
  994. {12,12,12,12,12,12,12,12}};
  995. for(int y=0;y<8;y++){
  996. for(int x=0;x<8;x++){
  997. //toolcan[tooleraserid].Color = c64color[eraser[y][x]]
  998. BeginTextureMode(toolim[tooleraserid]);
  999. DrawRectangle(x*4,y*4,4,4,c64color[eraser[7-y][x]]);
  1000. EndTextureMode();
  1001. }
  1002. }
  1003. //toolcan[tooleraserid].Flush()
  1004. int fill[8][8] = {
  1005. {12,12,12,1,12,12,12,12},
  1006. {12,12,12,12,1,12,12,12},
  1007. {12,12,12,12,12,1,12,12},
  1008. {1,1,1,1,1,1,1,12},
  1009. {12,1,1,1,1,1,1,1},
  1010. {1,12,1,1,1,1,1,12},
  1011. {12,12,12,1,1,1,12,12},
  1012. {1,12,12,12,1,12,12,12}};
  1013. for(int y=0;y<8;y++){
  1014. for(int x=0;x<8;x++){
  1015. //toolcan[toolfillid].Color = c64color[fill[y][x]]
  1016. BeginTextureMode(toolim[toolfillid]);
  1017. DrawRectangle(x*4,y*4,4,4,c64color[fill[7-y][x]]);
  1018. EndTextureMode();
  1019. }
  1020. }
  1021. //toolcan[toolfillid].Flush()
  1022. int line[8][8] = {
  1023. {12,12,12,12,12,12,12,12},
  1024. {12,1,12,12,12,12,12,12},
  1025. {12,12,1,12,12,12,12,12},
  1026. {12,12,12,1,12,12,12,12},
  1027. {12,12,12,12,1,12,12,12},
  1028. {12,12,12,12,12,1,12,12},
  1029. {12,12,12,12,12,12,1,12},
  1030. {12,12,12,12,12,12,12,12}};
  1031. for(int y=0;y<8;y++){
  1032. for(int x=0;x<8;x++){
  1033. //toolcan[toollineid].Color = c64color[line[y][x]]
  1034. BeginTextureMode(toolim[toollineid]);
  1035. DrawRectangle(x*4,y*4,4,4,c64color[line[7-y][x]]);
  1036. EndTextureMode();
  1037. }
  1038. }
  1039. //toolcan[toollineid].Flush()
  1040. int selection[8][8] = {
  1041. {12,12,12,12,12,12,12,12},
  1042. {12,1,12,1,1,12,1,12},
  1043. {12,12,12,12,12,12,12,12},
  1044. {12,1,12,12,12,12,1,12},
  1045. {12,1,12,12,12,12,1,12},
  1046. {12,12,12,12,12,12,12,12},
  1047. {12,1,12,1,1,12,1,12},
  1048. {12,12,12,12,12,12,12,12}};
  1049. for(int y=0;y<8;y++){
  1050. for(int x=0;x<8;x++){
  1051. //toolcan[toolselectionid].Color = c64color[selection[y][x]]
  1052. BeginTextureMode(toolim[toolselectionid]);
  1053. DrawRectangle(x*4,y*4,4,4,c64color[selection[7-y][x]]);
  1054. EndTextureMode();
  1055. }
  1056. }
  1057. //toolcan[toolselectionid].Flush()
  1058. int copy[8][8] = {
  1059. {1,12,12,12,12,12,12,12},
  1060. {1,1,12,1,1,12,1,12},
  1061. {1,1,1,12,12,12,12,12},
  1062. {1,1,1,1,12,12,1,12},
  1063. {1,1,1,12,12,12,1,12},
  1064. {1,1,12,12,12,12,12,12},
  1065. {1,12,12,1,1,12,1,12},
  1066. {12,12,12,12,12,12,12,12}};
  1067. for(int y=0;y<8;y++){
  1068. for(int x=0;x<8;x++){
  1069. //toolcan[toolcopyid].Color = c64color[copy[y][x]]
  1070. BeginTextureMode(toolim[toolcopyid]);
  1071. DrawRectangle(x*4,y*4,4,4,c64color[copy[7-y][x]]);
  1072. EndTextureMode();
  1073. }
  1074. }
  1075. //toolcan[toolcopyid].Flush()
  1076. int paste[8][8] = {
  1077. {12,12,12,1,12,12,12,12},
  1078. {12,12,1,1,1,12,1,12},
  1079. {12,1,1,1,12,12,12,12},
  1080. {1,1,1,1,12,12,1,12},
  1081. {12,1,1,1,12,12,1,12},
  1082. {12,12,1,1,12,12,12,12},
  1083. {12,12,12,1,1,12,1,12},
  1084. {12,12,12,12,12,12,12,12}};
  1085. for(int y=0;y<8;y++){
  1086. for(int x=0;x<8;x++){
  1087. //toolcan[toolpasteid].Color = c64color[paste[y][x]]
  1088. BeginTextureMode(toolim[toolpasteid]);
  1089. DrawRectangle(x*4,y*4,4,4,c64color[paste[7-y][x]]);
  1090. EndTextureMode();
  1091. }
  1092. }
  1093. //toolcan[toolpasteid].Flush()
  1094. int cut[8][8] = {
  1095. {12,12,12,12,12,12,12,12},
  1096. {12,12,12,1,12,12,12,12},
  1097. {12,12,12,12,1,12,12,12},
  1098. {12,1,12,12,1,12,12,12},
  1099. {12,12,1,1,12,1,1,12},
  1100. {12,12,12,12,1,12,1,1},
  1101. {12,12,12,12,1,1,12,12},
  1102. {12,12,12,12,12,1,1,12}};
  1103. for(int y=0;y<8;y++){
  1104. for(int x=0;x<8;x++){
  1105. //toolcan[toolcutid].Color = c64color[cut[y][x]]
  1106. BeginTextureMode(toolim[toolcutid]);
  1107. DrawRectangle(x*4,y*4,4,4,c64color[cut[7-y][x]]);
  1108. EndTextureMode();
  1109. }
  1110. }
  1111. //toolcan[toolcutid].Flush()
  1112. int flipvertical[8][8] = {
  1113. {12,12,12,1,1,12,12,12},
  1114. {12,12,1,1,1,1,12,12},
  1115. {12,1,1,1,1,1,1,12},
  1116. {12,12,12,1,1,12,12,12},
  1117. {12,12,12,1,1,12,12,12},
  1118. {12,1,1,1,1,1,1,12},
  1119. {12,12,1,1,1,1,12,12},
  1120. {12,12,12,1,1,12,12,12}};
  1121. for(int y=0;y<8;y++){
  1122. for(int x=0;x<8;x++){
  1123. //toolcan[toolflipverticalid].Color = c64color[flipvertical[y][x]]
  1124. BeginTextureMode(toolim[toolflipverticalid]);
  1125. DrawRectangle(x*4,y*4,4,4,c64color[flipvertical[7-y][x]]);
  1126. EndTextureMode();
  1127. }
  1128. }
  1129. //toolcan[toolflipverticalid].Flush()
  1130. int fliphorizontal[8][8] = {
  1131. {12,12,12,12,12,12,12,12},
  1132. {12,12,1,12,12,1,12,12},
  1133. {12,1,1,12,12,1,1,12},
  1134. {1,1,1,1,1,1,1,1},
  1135. {1,1,1,1,1,1,1,1},
  1136. {12,1,1,12,12,1,1,12},
  1137. {12,12,1,12,12,1,12,12},
  1138. {12,12,12,12,12,12,12,12}};
  1139. for(int y=0;y<8;y++){
  1140. for(int x=0;x<8;x++){
  1141. //toolcan[toolfliphorizontalid].Color = c64color[fliphorizontal[y][x]]
  1142. BeginTextureMode(toolim[toolfliphorizontalid]);
  1143. DrawRectangle(x*4,y*4,4,4,c64color[fliphorizontal[7-y][x]]);
  1144. EndTextureMode();
  1145. }
  1146. }
  1147. //toolcan[toolfliphorizontalid].Flush()
  1148. int colorpicker[8][8] = {
  1149. {12,1,1,12,12,12,12,12},
  1150. {1,1,12,12,1,12,12,12},
  1151. {1,12,12,1,12,12,12,12},
  1152. {12,12,1,12,1,12,12,12},
  1153. {12,1,12,1,12,1,12,12},
  1154. {12,12,12,12,1,12,1,12},
  1155. {12,12,12,12,12,1,1,12},
  1156. {12,12,12,12,12,12,12,1}};
  1157. for(int y=0;y<8;y++){
  1158. for(int x=0;x<8;x++){
  1159. //toolcan[toolcolorpickerid].Color = c64color[colorpicker[y][x]]
  1160. BeginTextureMode(toolim[toolcolorpickerid]);
  1161. DrawRectangle(x*4,y*4,4,4,c64color[colorpicker[7-y][x]]);
  1162. EndTextureMode();
  1163. }
  1164. }
  1165. //toolcan[toolcolorpickerid].Flush()
  1166. int grid[8][8] = {
  1167. {12,12,12,12,12,12,12,12},
  1168. {12,12,1,12,12,1,12,12},
  1169. {12,1,1,1,1,1,1,12},
  1170. {12,12,1,12,12,1,12,12},
  1171. {12,12,1,12,12,1,12,12},
  1172. {12,1,1,1,1,1,1,12},
  1173. {12,12,1,12,12,1,12,12},
  1174. {12,12,12,12,12,12,12,12}};
  1175. for(int y=0;y<8;y++){
  1176. for(int x=0;x<8;x++){
  1177. //toolcan[toolgridid].Color = c64color[grid[y][x]]
  1178. BeginTextureMode(toolim[toolgridid]);
  1179. DrawRectangle(x*4,y*4,4,4,c64color[grid[7-y][x]]);
  1180. EndTextureMode();
  1181. }
  1182. }
  1183. //toolcan[toolgridid].Flush()
  1184. int filledrect[8][8] = {
  1185. {12,12,12,12,12,12,12,12},
  1186. {12,1,1,1,1,1,1,12},
  1187. {12,1,1,1,1,1,1,12},
  1188. {12,1,1,1,1,1,1,12},
  1189. {12,1,1,1,1,1,1,12},
  1190. {12,1,1,1,1,1,1,12},
  1191. {12,1,1,1,1,1,1,12},
  1192. {12,12,12,12,12,12,12,12}};
  1193. for(int y=0;y<8;y++){
  1194. for(int x=0;x<8;x++){
  1195. //toolcan[toolfilledrectid].Color = c64color[filledrect[y][x]]
  1196. BeginTextureMode(toolim[toolfilledrectid]);
  1197. DrawRectangle(x*4,y*4,4,4,c64color[filledrect[7-y][x]]);
  1198. EndTextureMode();
  1199. }
  1200. }
  1201. //toolcan[toolfilledrectid].Flush()
  1202. int outlinerect[8][8] = {
  1203. {12,12,12,12,12,12,12,12},
  1204. {12,1,1,1,1,1,1,12},
  1205. {12,1,12,12,12,12,1,12},
  1206. {12,1,12,12,12,12,1,12},
  1207. {12,1,12,12,12,12,1,12},
  1208. {12,1,12,12,12,12,1,12},
  1209. {12,1,1,1,1,1,1,12},
  1210. {12,12,12,12,12,12,12,12}};
  1211. for(int y=0;y<8;y++){
  1212. for(int x=0;x<8;x++){
  1213. //toolcan[tooloutlinerectid].Color = c64color[outlinerect[y][x]]
  1214. BeginTextureMode(toolim[tooloutlinerectid]);
  1215. DrawRectangle(x*4,y*4,4,4,c64color[outlinerect[7-y][x]]);
  1216. EndTextureMode();
  1217. }
  1218. }
  1219. //toolcan[tooloutlinerectid].Flush()
  1220. int filledcircle[8][8] = {
  1221. {12,12,12,1,1,12,12,12},
  1222. {12,12,1,1,1,1,12,12},
  1223. {12,1,1,1,1,1,1,12},
  1224. {1,1,1,1,1,1,1,1},
  1225. {1,1,1,1,1,1,1,1},
  1226. {12,1,1,1,1,1,1,12},
  1227. {12,12,1,1,1,1,12,12},
  1228. {12,12,12,1,1,12,12,12}};
  1229. for(int y=0;y<8;y++){
  1230. for(int x=0;x<8;x++){
  1231. int p=filledcircle[7-y][x];
  1232. //toolcan[toolfilledcircleid].Color = c64color[p]
  1233. BeginTextureMode(toolim[toolfilledcircleid]);
  1234. DrawRectangle(x*4,y*4,4,4,c64color[p]);
  1235. EndTextureMode();
  1236. }
  1237. }
  1238. //toolcan[toolfilledcircleid].Flush()
  1239. int outlinecircle[8][8] = {
  1240. {12,12,12,1,1,12,12,12},
  1241. {12,12,1,12,12,1,12,12},
  1242. {12,1,12,12,12,12,1,12},
  1243. {1,12,12,12,12,12,12,1},
  1244. {1,12,12,12,12,12,12,1},
  1245. {12,1,12,12,12,12,1,12},
  1246. {12,12,1,12,12,1,12,12},
  1247. {12,12,12,1,1,12,12,12}};
  1248. for(int y=0;y<8;y++){
  1249. for(int x=0;x<8;x++){
  1250. int p=outlinecircle[7-y][x];
  1251. //toolcan[tooloutlinecircleid].Color = c64color[p]
  1252. BeginTextureMode(toolim[tooloutlinecircleid]);
  1253. DrawRectangle(x*4,y*4,4,4,c64color[p]);
  1254. EndTextureMode();
  1255. }
  1256. }
  1257. //toolcan[tooloutlinecircleid].Flush()
  1258. }
  1259. void toolview(){
  1260. //canvas.Color=Color.Black
  1261. DrawRectangle(toolx,tooly,toolwidth,toolheight,BLACK);
  1262. //canvas.Color=Color.White
  1263. if(delay>0)delay-=1;
  1264. int num=0;
  1265. for(int y=tooly;y<tooly+toolheight;y+=32){
  1266. for(int x=toolx;x<toolx+toolwidth;x+=32){
  1267. if(num>=numtools)continue;
  1268. int pointx=x;
  1269. int pointy=y;
  1270. if(toolselected == num){
  1271. //canvas.Color = Color.Yellow
  1272. DrawRectangle(pointx,pointy,32,32,YELLOW);
  1273. //canvas.Color = Color.White
  1274. //canvas.Scissor = New Recti(pointx+2,pointy+2,pointx+30,pointy+30)
  1275. DrawTexture(toolim[num].texture,pointx,pointy,WHITE);
  1276. //canvas.Scissor = New Recti(0,0,640,480)
  1277. }else{
  1278. DrawTexture(toolim[num].texture,pointx,pointy,WHITE);
  1279. }
  1280. //'
  1281. //'/ Interaction with the tool area
  1282. //'
  1283. if(spriteviewaction==false && IsMouseButtonDown(0)){
  1284. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,32,32)){
  1285. toolselected = num;
  1286. //' Pastethe selected area
  1287. if(toolselected == toolpasteid){
  1288. if(selectionstartx == selectionendx && selectionstarty == selectionendy){
  1289. }else{
  1290. for(int y1=selectionbufferstarty; y1<=selectionbufferendy;y1++){
  1291. for(int x1=selectionbufferstartx; x1<=selectionbufferendx;x1++){
  1292. int destx=selectionstartx+x1-selectionbufferstartx;
  1293. int desty=selectionstarty+y1-selectionbufferstarty;
  1294. if(x1<0 || y1<0 || x1>=32 || y1>=32) continue;
  1295. if(destx<0 || desty<0 || destx>=32 || desty>=32)continue;
  1296. if(destx>selectionendx || desty>selectionendy)continue;
  1297. map[destx][desty] = selectionbuffer[x1][y1];
  1298. }
  1299. }
  1300. toolselected = toolpencilid;
  1301. }
  1302. }
  1303. //' Copy the selected area
  1304. if(toolselected == toolcopyid){
  1305. if(selectionstartx == selectionendx && selectionstarty == selectionendy){
  1306. }else{
  1307. selectionbufferstartx = selectionstartx;
  1308. selectionbufferstarty = selectionstarty;
  1309. selectionbufferendx = selectionendx;
  1310. selectionbufferendy = selectionendy;
  1311. for(int y1=selectionstarty;y1<=selectionendy;y1++){
  1312. for(int x1=selectionstartx;x1<=selectionendx;x1++){
  1313. selectionbuffer[x1][y1] = map[x1][y1];
  1314. }
  1315. }
  1316. toolselected = toolpencilid;
  1317. }
  1318. }
  1319. // Cut the selected area
  1320. if(toolselected == toolcutid){
  1321. if(selectionstartx == selectionendx && selectionstarty == selectionendy){
  1322. }else{
  1323. for(int y1=selectionstarty;y1<=selectionendy;y1++){
  1324. for(int x1=selectionstartx;x1<=selectionendx;x1++){
  1325. map[x1][y1] = paletteeraser;
  1326. }
  1327. }
  1328. toolselected = toolpencilid;
  1329. }
  1330. }
  1331. //' Mirror vertically
  1332. if(toolselected == toolflipverticalid && delay <= 0)
  1333. {
  1334. //int tempmap[32][32] = {0};
  1335. for(int y1=0;y1<spriteheight;y1++){
  1336. for(int x1=0;x1<spritewidth;x1++){
  1337. tempmap[x1][y1] = map[x1][y1];
  1338. }
  1339. }
  1340. for(int y1=0;y1<spriteheight;y1++){
  1341. for(int x1=0;x1<spritewidth;x1++){
  1342. map[x1][y1] = tempmap[x1][spriteheight-1-y1];
  1343. }
  1344. }
  1345. delay = delaydefault;
  1346. toolselected = toolpencilid;
  1347. }
  1348. //Mirror Horizontal
  1349. if(toolselected == toolfliphorizontalid && delay <= 0){
  1350. //int tempmap[spritewidth][spriteheight];
  1351. for(int y1=0;y1<spriteheight;y1++){
  1352. for(int x1=0;x1<spritewidth;x1++){
  1353. tempmap[x1][y1] = map[x1][y1];
  1354. }
  1355. }
  1356. for(int y1=0;y1<spriteheight;y1++){
  1357. for(int x1=0;x1<spritewidth;x1++){
  1358. map[x1][y1] = tempmap[spritewidth-1-x1][y1];
  1359. }
  1360. }
  1361. delay = delaydefault;
  1362. toolselected = toolpencilid;
  1363. }
  1364. //' Grid toggle
  1365. if(toolselected == toolgridid && delay <= 0){
  1366. if(toolgridtoggle == true){
  1367. toolgridtoggle = false;
  1368. }else{
  1369. toolgridtoggle = true;
  1370. }
  1371. delay = delaydefault;
  1372. toolselected = toolpencilid;
  1373. }
  1374. }
  1375. }
  1376. num+=1;
  1377. }
  1378. }
  1379. }
  1380. void spritelibview(){
  1381. //canvas.Color = Color.Black
  1382. DrawRectangle(spritelibx,spriteliby,spritelibwidth,spritelibheight,BLACK);
  1383. //canvas.Color = Color.White
  1384. int num=(middlebarcurrentid*80);
  1385. for(int y=spriteliby;y<spriteliby+spritelibheight;y+=spriteheight*spritelibscale){
  1386. for(int x=spritelibx;x<spritelibx+spritelibwidth;x+=spritewidth*spritelibscale){
  1387. int pointx=x;
  1388. int pointy=y;
  1389. if(num == spritelibselected){
  1390. //canvas.Color = Color.White
  1391. //DrawRectangle(pointx,pointy,spritewidth*spritelibscale,spriteheight*spritelibscale,WHITE);
  1392. //canvas.Scissor = New Recti(pointx+2,pointy+2,pointx+spritewidth*spritelibscale-3,pointy+spriteheight*spritelibscale-3)
  1393. //'canvas.Scissor(z1)
  1394. //DrawTextureRec(spritelibim[num].texture,(Rectangle){0,0,spritewidth,spriteheight},pointx,pointy,WHITE);
  1395. //DrawTextureEx(spritelibim[num].texture,(Vector2){pointx,pointy},0,spritelibscale,WHITE);
  1396. //DrawTexture(spritelibim[num].texture,pointx,pointy,WHITE);
  1397. // NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
  1398. DrawTextureRec(spritelibim[num].texture, (Rectangle){ 0, 0, spritelibim[num].texture.width, -spritelibim[num].texture.height }, (Vector2){pointx,pointy}, WHITE);
  1399. DrawRectangle(pointx,pointy,spritewidth*spritelibscale,spriteheight*spritelibscale,(Color){100,100,100,100});
  1400. //'Local z2:=New Recti(0,0,640,480)
  1401. //canvas.Scissor = New Recti(0,0,640,480)
  1402. }else{
  1403. //canvas.Color = Color.White
  1404. //canvas.DrawImage(spritelibim[num],pointx,pointy)
  1405. //DrawTexture(spritelibim[num].texture,pointx,pointy,WHITE);
  1406. //DrawTextureEx(spritelibim[num].texture,(Vector2){pointx,pointy},0,spritelibscale,WHITE);
  1407. //DrawTexture(spritelibim[num].texture,pointx,pointy,WHITE);
  1408. //DrawTextureRec(spritelibim[num].texture, (Rectangle){ 0, 0, spritewidth, -spriteheight }, (Vector2){ 0, 0 }, WHITE);
  1409. DrawTextureRec(spritelibim[num].texture, (Rectangle){ 0, 0, spritelibim[num].texture.width, -spritelibim[num].texture.height }, (Vector2){pointx,pointy}, WHITE);
  1410. }
  1411. if(spriteviewaction==false && IsMouseButtonDown(0)){
  1412. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,spritewidth*spritelibscale,spriteheight*spritelibscale)){
  1413. spritelibselected = num;
  1414. spritelibcopytocanvas();
  1415. }
  1416. }
  1417. num+=1;
  1418. if(num>=numspritelib)break;
  1419. }
  1420. if(num>=numspritelib)break;
  1421. }
  1422. }
  1423. void spriteview(){
  1424. // If drawing then do not allow presses outside spriteview unless mouse is not pressed.
  1425. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,canvasx,canvasy,canvaswidth,canvasheight) && IsMouseButtonDown(0) || IsMouseButtonDown(1)){
  1426. spriteviewaction=true;
  1427. }
  1428. if(IsMouseButtonDown(0)==false && IsMouseButtonDown(1)==false){
  1429. spriteviewaction=false;
  1430. }
  1431. for(int y=0;y<spriteheight;y++){
  1432. for(int x=0;x<spritewidth;x++){
  1433. int pointx=(x*gridwidth)+canvasx;
  1434. int pointy=(y*gridheight)+canvasy;
  1435. //'canvas.DrawRect()
  1436. if(startsetuppalettemode == 0){
  1437. //canvas.Color = c64color[map[x,y]]
  1438. DrawRectangle(pointx,pointy,gridwidth,gridheight,c64color[map[x][y]]);
  1439. }else{
  1440. //canvas.Color = db32color[map[x,y]]
  1441. DrawRectangle(pointx,pointy,gridwidth,gridheight,db32color[map[x][y]]);
  1442. }
  1443. //canvas.DrawRect(pointx,pointy,gridwidth,gridheight)
  1444. //'
  1445. //' Mouse down (LEFT)
  1446. if(IsMouseButtonDown(0)){
  1447. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,gridwidth,gridheight)){
  1448. if(toolselected == toolpencilid){
  1449. map[x][y] = paletteselected;
  1450. }
  1451. if(toolselected == tooleraserid){
  1452. map[x][y] = paletteeraser;
  1453. }
  1454. }
  1455. }
  1456. if(IsMouseButtonPressed(0)){
  1457. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,gridwidth,gridheight)){
  1458. if(toolselected == toolfillid){
  1459. paletteundermouse = map[x][y];
  1460. if(paletteundermouse!=paletteselected)fillatposition(x,y,map[x][y],paletteselected);
  1461. }
  1462. }
  1463. }
  1464. // Line tool
  1465. if(IsMouseButtonDown(0)){
  1466. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,gridwidth,gridheight)){
  1467. if(toolselected == toollineid){
  1468. if(linepressed == false && lineactive == false){
  1469. lineactive = true;
  1470. linepressed = true;
  1471. linestartx = x;
  1472. linestarty = y;
  1473. }
  1474. if(lineactive == true){
  1475. lineendx = x;
  1476. lineendy = y;
  1477. }
  1478. }
  1479. }
  1480. }
  1481. if(IsMouseButtonDown(0) == false){
  1482. if(toolselected == toollineid){
  1483. if(lineactive == true){
  1484. previewline(true);
  1485. lineactive = false;
  1486. linepressed = false;
  1487. }
  1488. }
  1489. }
  1490. //' Selection Tool
  1491. if(IsMouseButtonDown(0)){
  1492. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,gridwidth,gridheight)){
  1493. if(toolselected == toolselectionid){
  1494. if(selectionpressed == false && selectionactive == false){
  1495. selectionactive = true;
  1496. selectionpressed = true;
  1497. selectionstartx = x;
  1498. selectionstarty = y;
  1499. selectionnegativeswitchx = true;
  1500. selectionnegativeswitchy = true;
  1501. }
  1502. if(selectionactive == true){
  1503. selectionendx = x;
  1504. selectionendy = y;
  1505. if(selectionendx < selectionstartx){
  1506. selectionendx-=1;
  1507. if(selectionnegativeswitchx){
  1508. selectionnegativeswitchx = false;
  1509. selectionstartx+=1;
  1510. }
  1511. }
  1512. if(selectionendy < selectionstarty){
  1513. selectionendy-=1;
  1514. if(selectionnegativeswitchy){
  1515. selectionnegativeswitchy = false;
  1516. selectionstarty+=1;
  1517. }
  1518. }
  1519. }
  1520. }
  1521. }
  1522. }
  1523. if(IsMouseButtonDown(0) == false){
  1524. if(toolselected == toolselectionid){
  1525. if(selectionactive == true){
  1526. //'previewselection(canvas,True)
  1527. selectionactive = false;
  1528. selectionpressed = false;
  1529. //' if the end is smaller then then start then switch them
  1530. if(selectionendx<selectionstartx){
  1531. int a=selectionstartx;
  1532. int b=selectionendx;
  1533. selectionstartx = b+1;
  1534. selectionendx = a -1;
  1535. }
  1536. if(selectionendy<selectionstarty){
  1537. int a=selectionstarty;
  1538. int b=selectionendy;
  1539. selectionstarty = b +1;
  1540. selectionendy = a -1 ;
  1541. }
  1542. }
  1543. }
  1544. }
  1545. //' Remove the selection with rmb
  1546. if(IsMouseButtonDown(1) == true){
  1547. selectionstartx=0;
  1548. selectionstarty=0;
  1549. selectionendx=0;
  1550. selectionendy=0;
  1551. }
  1552. //'
  1553. //' Mouse down (MIDDLE) Color Picker
  1554. if(IsMouseButtonDown(2)){
  1555. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,gridwidth,gridheight)){
  1556. paletteselected = map[x][y];
  1557. }
  1558. }
  1559. if(IsMouseButtonDown(0)){
  1560. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,gridwidth,gridheight)){
  1561. if(toolselected == toolcolorpickerid){
  1562. paletteselected = map[x][y];
  1563. }
  1564. }
  1565. }
  1566. //'
  1567. //' Mouse Down(LEFT) Filled rect / outlined rect / filled circle / outlined circle
  1568. if(IsMouseButtonDown(0)){
  1569. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,gridwidth,gridheight)){
  1570. if(toolselected == toolfilledrectid || toolselected == tooloutlinerectid || toolselected == toolfilledcircleid || toolselected == tooloutlinecircleid){
  1571. if(bcselectionpressed == false && bcselectionactive == false){
  1572. bcselectionactive = true;
  1573. bcselectionpressed = true;
  1574. bcselectionstartx = x;
  1575. bcselectionstarty = y;
  1576. bcselectionnegativeswitchx = true;
  1577. bcselectionnegativeswitchy = true;
  1578. }
  1579. if(bcselectionactive == true){
  1580. bcselectionendx = x;
  1581. bcselectionendy = y;
  1582. if(bcselectionendx < bcselectionstartx){
  1583. bcselectionendx-=1;
  1584. if(bcselectionnegativeswitchx){
  1585. bcselectionnegativeswitchx = false;
  1586. bcselectionstartx+=1;
  1587. }
  1588. }
  1589. if(bcselectionendy < bcselectionstarty){
  1590. bcselectionendy-=1;
  1591. if(bcselectionnegativeswitchy){
  1592. bcselectionnegativeswitchy = false;
  1593. bcselectionstarty+=1;
  1594. }
  1595. }
  1596. }
  1597. }
  1598. }
  1599. }
  1600. if(IsMouseButtonDown(0) == false){
  1601. if(toolselected == toolfilledrectid || toolselected == tooloutlinerectid || toolselected == toolfilledcircleid || toolselected == tooloutlinecircleid){
  1602. if(bcselectionactive == true){
  1603. //'previewselection(canvas,True)
  1604. bcselectionactive = false;
  1605. bcselectionpressed = false;
  1606. //' if the end is smaller then then start then switch them
  1607. if(bcselectionendx<bcselectionstartx){
  1608. int a=bcselectionstartx;
  1609. int b=bcselectionendx;
  1610. bcselectionstartx = b+1;
  1611. bcselectionendx = a -1;
  1612. }
  1613. if(bcselectionendy<bcselectionstarty){
  1614. int a=bcselectionstarty;
  1615. int b=bcselectionendy;
  1616. bcselectionstarty = b +1;
  1617. bcselectionendy = a -1;
  1618. }
  1619. //'
  1620. //' Do the filling
  1621. if(toolselected == toolfilledrectid || toolselected == tooloutlinerectid){
  1622. for(int y=bcselectionstarty;y<=bcselectionendy;y++){
  1623. for(int x=bcselectionstartx;x<=bcselectionendx;x++){
  1624. if(toolselected == toolfilledrectid)map[x][y] = paletteselected;
  1625. if(toolselected == tooloutlinerectid){
  1626. if(x == bcselectionstartx || x == bcselectionendx || y == bcselectionendy || y==bcselectionstarty){
  1627. map[x][y] = paletteselected;
  1628. }
  1629. }
  1630. }
  1631. }
  1632. }else if(toolselected == toolfilledcircleid || toolselected == tooloutlinecircleid){
  1633. //' add circle code here
  1634. int w=abs(bcselectionstartx-bcselectionendx)+1;
  1635. int h=abs(bcselectionstarty-bcselectionendy)+1;
  1636. if(toolselected == tooloutlinecircleid){
  1637. //Local ti:Image = New Image(spritewidth,spriteheight)
  1638. //Local tc:Canvas = New Canvas(ti)
  1639. //tc.Clear(Color.Black)
  1640. //tc.Color = Color.White
  1641. //BeginTextureMode(ti);
  1642. //ClearBackground(BLANK);
  1643. //EndTextureMode();
  1644. //tc.OutlineMode=OutlineMode.Smooth
  1645. //tc.OutlineColor = Color.Green
  1646. //tc.OutlineWidth = 0
  1647. //tc.DrawOval(bcselectionstartx,bcselectionstarty,w-1,h-1)
  1648. //tc.DrawOval(bcselectionstartx,bcselectionstarty,w-1,h-1)
  1649. midptellipse((w/2)-1,(h/2)-1,bcselectionstartx+w/2,bcselectionstarty+h/2);
  1650. //tc.Flush()
  1651. for(int y=0;y<spriteheight;y++){
  1652. for(int x=0;x<spritewidth;x++){
  1653. if(tempmap[x][y] == 1){
  1654. map[x][y] = paletteselected;
  1655. }
  1656. }
  1657. }
  1658. }else{
  1659. /*
  1660. Local ti:Image = New Image(spritewidth,spriteheight)
  1661. Local tc:Canvas = New Canvas(ti)
  1662. tc.Clear(Color.Black)
  1663. tc.Color = Color.White
  1664. tc.DrawOval(bcselectionstartx-1,bcselectionstarty-1,w+1,h+1)
  1665. tc.Flush()
  1666. For Local y:Int=0 Until spriteheight
  1667. For Local x:Int=0 Until spritewidth
  1668. If ti.GetPixel(x,y) <> Color.Black
  1669. map[x,y] = paletteselected
  1670. End If
  1671. Next
  1672. Next
  1673. */
  1674. }
  1675. }
  1676. bcselectionendy=0;
  1677. bcselectionendx=0;
  1678. bcselectionstarty=0;
  1679. bcselectionstartx=0;
  1680. }
  1681. }
  1682. }
  1683. // Tab between map view and sprite view.
  1684. if(IsKeyReleased(KEY_TAB)){
  1685. spriteviewaction = false;
  1686. topbarcurrentid = topbarmapeditid;
  1687. }
  1688. //' Read from disk..
  1689. if(IsKeyReleased(KEY_F6)){
  1690. loadspritelib();
  1691. }
  1692. //' Save to disk..
  1693. if(IsKeyReleased(KEY_F5)){
  1694. savespritelib();
  1695. }
  1696. //' Copy to clipboard
  1697. if(IsKeyReleased(KEY_C)){
  1698. copytoclipboard();
  1699. }
  1700. // Copy FROM clipboard.
  1701. if(IsKeyReleased(KEY_P)){
  1702. copyfromclipboard();
  1703. updatepreview();
  1704. updatespritelib();
  1705. }
  1706. }
  1707. }
  1708. // updatepreview()
  1709. // updatespritelib()
  1710. }
  1711. void updatepreview(){
  1712. if(spritewidth==8)previewcellwidth=8;
  1713. if(spritewidth==16)previewcellwidth=4;
  1714. if(spritewidth==32)previewcellwidth=2;
  1715. //previewcan.Clear(Color.Black)
  1716. for(int y=0;y<spriteheight;y++){
  1717. for(int x=0;x<spritewidth;x++){
  1718. int pointx=x*previewcellwidth;
  1719. int pointy=y*previewcellwidth;
  1720. BeginTextureMode(previewim);
  1721. if(startsetuppalettemode == 0){
  1722. DrawRectangle(pointx,pointy,previewcellwidth,previewcellwidth,c64color[map[x][y]]);
  1723. //previewcan.Color = c64color[map[x,y]]
  1724. }else{
  1725. //previewcan.Color = db32color[map[x,y]]
  1726. DrawRectangle(pointx,pointy,previewcellwidth,previewcellwidth,db32color[map[x][y]]);
  1727. }
  1728. EndTextureMode();
  1729. //previewcan.DrawRect(pointx,pointy,previewcellwidth,previewcellheight)
  1730. }
  1731. }
  1732. //previewcan.Flush()
  1733. }
  1734. void loadspritelib(){
  1735. // Read the array from disk..
  1736. FILE *fp;
  1737. fp=fopen("spritedata.spr","r");
  1738. fread(spritelibmap,sizeof(spritelibmap),1,fp); /* read the entire file into the array */
  1739. fclose(fp);
  1740. // rebuild the sprite images..
  1741. for(int i=0;i<80*4;i++){
  1742. bool empty=true;
  1743. for(int y=0;y<spriteheight;y++){
  1744. for(int x=0;x<spritewidth;x++){
  1745. if(spritelibmap[i][x][y]>0){
  1746. empty=false;
  1747. }
  1748. }}
  1749. if(empty==true)continue;
  1750. for(int y=0;y<spriteheight;y++){
  1751. for(int x=0;x<spritewidth;x++){
  1752. float pointx=x*spritelibscale;
  1753. float pointy=y*spritelibscale;
  1754. BeginTextureMode(spritelibim[i]);
  1755. if(startsetuppalettemode == 0){
  1756. DrawRectangle(pointx,pointy,spritelibscale,spritelibscale,c64color[spritelibmap[i][x][y]]);
  1757. //spritelibcan[spritelibselected].Color = c64color[map[x,y]]
  1758. }else{
  1759. DrawRectangle(pointx,pointy,spritelibscale,spritelibscale,db32color[spritelibmap[i][x][y]]);
  1760. //spritelibcan[spritelibselected].Color = db32color[map[x,y]]
  1761. }
  1762. EndTextureMode();
  1763. }
  1764. }
  1765. }
  1766. //updatepreview();
  1767. //updatespritelib();
  1768. // First put the current selected into the map[]
  1769. //map[0][0]=1;
  1770. for(int y=0;y<spriteheight;y++){
  1771. for(int x=0;x<spritewidth;x++){
  1772. map[x][y] = spritelibmap[spritelibselected][x][y];
  1773. }}
  1774. //updatespritelib();
  1775. updatepreview();
  1776. }
  1777. void savespritelib(){
  1778. // Create out file pointer.
  1779. FILE *fp;
  1780. // Write the array to disk.
  1781. fp=fopen("spritedata.spr","w");
  1782. fwrite(spritelibmap,sizeof(spritelibmap),1,fp); /* Write to File */
  1783. fclose(fp);
  1784. }
  1785. void updatespritelib(){
  1786. for(int y=0;y<spriteheight;y++){
  1787. for(int x=0;x<spritewidth;x++){
  1788. float pointx=x*spritelibscale;
  1789. float pointy=y*spritelibscale;
  1790. BeginTextureMode(spritelibim[spritelibselected]);
  1791. if(startsetuppalettemode == 0){
  1792. DrawRectangle(pointx,pointy,spritelibscale,spritelibscale,c64color[map[x][y]]);
  1793. //spritelibcan[spritelibselected].Color = c64color[map[x,y]]
  1794. }else{
  1795. DrawRectangle(pointx,pointy,spritelibscale,spritelibscale,db32color[map[x][y]]);
  1796. //spritelibcan[spritelibselected].Color = db32color[map[x,y]]
  1797. }
  1798. //spritelibcan[spritelibselected].DrawRect(pointx,pointy,spritelibscale,spritelibscale)
  1799. spritelibmap[spritelibselected][x][y] = map[x][y];
  1800. EndTextureMode();
  1801. }
  1802. }
  1803. //spritelibcan[spritelibselected].Flush()
  1804. }
  1805. /*
  1806. void fillatposition(int x,int y){
  1807. Local ol:List<pathnode> = New List<pathnode>
  1808. ' Add the start position on the list
  1809. ol.AddLast(New pathnode(x,y))
  1810. ' set the cloes map at the start position to distance 1
  1811. Local colorundermouse:Int=map[x,y]
  1812. map[x,y] = paletteselected
  1813. ' some helper arrays. We can determine the top,right,and bottom
  1814. ' and left position cells with these numbers.
  1815. Local dx:Int[] = New Int[](0,1,0,-1)
  1816. Local dy:Int[] = New Int[](-1,0,1,0)
  1817. ' While there is contents in the list
  1818. While ol.Count() <> 0
  1819. ' Get the current location
  1820. Local x1:Int=ol.First.x
  1821. Local y1:Int=ol.First.y
  1822. ' Remove the current location from the list
  1823. ol.RemoveFirst()
  1824. ' Get 4 new positions around the current positions
  1825. For Local i:=0 Until 4
  1826. ' Set new x and y
  1827. Local nx:Int=x1+dx[i]
  1828. Local ny:Int=y1+dy[i]
  1829. ' If the coordinates are inside the map
  1830. If nx>=0 And ny>=0 And nx<spritewidth And ny<spriteheight
  1831. ' If the closedmap is not written to yet
  1832. If map[nx,ny] = colorundermouse And map[nx,ny] <> paletteselected
  1833. ' Set the new distance based on the current distance
  1834. map[nx,ny] = paletteselected
  1835. ' Add new position to the list
  1836. ol.AddLast(New pathnode(nx,ny))
  1837. End If
  1838. End If
  1839. Next
  1840. Wend
  1841. }
  1842. */
  1843. void previewview(){
  1844. //canvas.Color = Color.White
  1845. DrawRectangle(previewx,previewy,previewwidth,previewheight,WHITE);
  1846. //DrawTexture(previewim.texture,previewx+1,previewy+1,WHITE);
  1847. DrawTextureRec(previewim.texture, (Rectangle){ 0,0, 64, -64 }, (Vector2){previewx,previewy}, WHITE);
  1848. }
  1849. void spritelibcopytocanvas(){
  1850. for(int y=0;y<spriteheight;y++){
  1851. for(int x=0;x<spritewidth;x++){
  1852. map[x][y] = spritelibmap[spritelibselected][x][y];
  1853. }
  1854. }
  1855. }
  1856. void previewline(bool drawit){
  1857. if(lineactive == false)return;
  1858. int x1=linestartx;
  1859. int y1=linestarty;
  1860. int x2=lineendx;
  1861. int y2=lineendy;
  1862. int dx;
  1863. int dy;
  1864. int sx;
  1865. int sy;
  1866. int e;
  1867. dx = abs(x2 - x1);
  1868. sx = -1;
  1869. if(x1 < x2)sx = 1;
  1870. dy = abs(y2 - y1);
  1871. sy = -1;
  1872. if(y1 < y2)sy = 1;
  1873. if(dx < dy){
  1874. e = dx / 2;
  1875. }else{
  1876. e = dy / 2;
  1877. }
  1878. bool exitloop=false;
  1879. while(exitloop == false){
  1880. int pointx=canvasx+(x1*gridwidth);
  1881. int pointy=canvasy+(y1*gridheight);
  1882. if(startsetuppalettemode == 0){
  1883. //canvas.Color = c64color[paletteselected]
  1884. DrawRectangle(pointx,pointy,gridwidth,gridheight,c64color[paletteselected]);
  1885. }else{
  1886. //canvas.Color = db32color[paletteselected]
  1887. DrawRectangle(pointx,pointy,gridwidth,gridheight,db32color[paletteselected]);
  1888. }
  1889. //canvas.DrawRect(pointx,pointy,gridwidth,gridheight)
  1890. if(drawit==true){
  1891. if(x1<0 || y1<0 || x1>=spritewidth || y1>=spriteheight)break;
  1892. map[x1][y1] = paletteselected;
  1893. }
  1894. if(x1 == x2){
  1895. if(y1 == y2){
  1896. exitloop = true;
  1897. }
  1898. }
  1899. if(dx > dy){
  1900. x1 += sx;
  1901. e -= dy;
  1902. if(e < 0){
  1903. e += dx;
  1904. y1 += sy;
  1905. }
  1906. }else{
  1907. y1 += sy;
  1908. e -= dx;
  1909. if(e < 0){
  1910. e += dy;
  1911. x1 += sx;
  1912. }
  1913. }
  1914. }
  1915. }
  1916. //' Selection for the selection tool or the filled outlined tools
  1917. //'
  1918. void previewselection(bool drawit){
  1919. //' the selection rectangle
  1920. if(selectionstartx == selectionendx && selectionstarty == selectionendy){
  1921. }else{
  1922. int x1=canvasx+(selectionstartx*gridwidth);
  1923. int y1=canvasy+(selectionstarty*gridheight);
  1924. int x2=canvasx+((selectionendx+1)*gridwidth);
  1925. int y2=canvasy+((selectionendy+1)*gridheight);
  1926. //canvas.Color = Color.White
  1927. DrawLine(x1,y1,x2,y1,WHITE);
  1928. DrawLine(x1,y1,x1,y2,WHITE);
  1929. DrawLine(x1,y2,x2,y2,WHITE);
  1930. DrawLine(x2,y1,x2,y2,WHITE);
  1931. //Color = Color.Black
  1932. x1+=1;y1+=1;x2-=1;y2-=1;
  1933. DrawLine(x1,y1,x2,y1,BLACK);
  1934. DrawLine(x1,y1,x1,y2,BLACK);
  1935. DrawLine(x1,y2,x2,y2,BLACK);
  1936. DrawLine(x2,y1,x2,y2,BLACK);
  1937. x1+=2;y1+=2;x2-=2;y2-=2;
  1938. DrawLine(x1,y1,x2,y1,BLACK);
  1939. DrawLine(x1,y1,x1,y2,BLACK);
  1940. DrawLine(x1,y2,x2,y2,BLACK);
  1941. DrawLine(x2,y1,x2,y2,BLACK);
  1942. }
  1943. //' the filled outlined tool
  1944. if(bcselectionstartx == bcselectionendx && bcselectionstarty == bcselectionendy){
  1945. }else{
  1946. int x1=canvasx+(bcselectionstartx*gridwidth);
  1947. int y1=canvasy+(bcselectionstarty*gridheight);
  1948. int x2=canvasx+((bcselectionendx+1)*gridwidth);
  1949. int y2=canvasy+((bcselectionendy+1)*gridheight);
  1950. //canvas.Color = Color.White
  1951. DrawLine(x1,y1,x2,y1,WHITE);
  1952. DrawLine(x1,y1,x1,y2,WHITE);
  1953. DrawLine(x1,y2,x2,y2,WHITE);
  1954. DrawLine(x2,y1,x2,y2,WHITE);
  1955. //canvas.Color = Color.Black
  1956. x1+=1;y1+=1;x2-=1;y2-=1;
  1957. DrawLine(x1,y1,x2,y1,BLACK);
  1958. DrawLine(x1,y1,x1,y2,BLACK);
  1959. DrawLine(x1,y2,x2,y2,BLACK);
  1960. DrawLine(x2,y1,x2,y2,BLACK);
  1961. x1+=2;y1+=2;x2-=2;y2-=2;
  1962. DrawLine(x1,y1,x2,y1,BLACK);
  1963. DrawLine(x1,y1,x1,y2,BLACK);
  1964. DrawLine(x1,y2,x2,y2,BLACK);
  1965. DrawLine(x2,y1,x2,y2,BLACK);
  1966. }
  1967. }
  1968. void copytoclipboard(){
  1969. /*
  1970. //This is the original code from the monkey2 language..
  1971. Local out:String="int sprite["+spriteheight+"]["+spritewidth+"] = {"+String.FromChar(10)
  1972. For Local y:Int=spriteheight-1 to 0 Step -1
  1973. Local a:String
  1974. For Local x:Int=0 Until spritewidth
  1975. a+=map[x,y]+","
  1976. Next
  1977. Local l:Int=a.Length
  1978. a=a.Slice(0,a.Length-1)
  1979. out += "{"+a+"},"+String.FromChar(10)
  1980. Next
  1981. out=out.Slice(0,out.Length-2)
  1982. out+="};"
  1983. instance.ClipboardText = out
  1984. */
  1985. // Here we create a copy and paste ready
  1986. // text that can be pasted into a code editor.
  1987. // It shows how to convert a array into c language code.
  1988. char output1[1000] = "int sprite[";
  1989. char output2[32];
  1990. sprintf(output2, "%d", spritewidth);
  1991. strcat(output1,output2);
  1992. strcat(output1,"][");
  1993. sprintf(output2, "%d", spriteheight);
  1994. strcat(output1,output2);
  1995. strcat(output1,"] = {\n");
  1996. int x=0;int y=0;
  1997. for (y=0;y<spriteheight;y++){
  1998. for(x=0;x<spritewidth-1;x++){
  1999. if(x==0)strcat(output1,"{");
  2000. char num[16];
  2001. sprintf(num, "%d", map[y][x]);
  2002. strcat(output1,num);
  2003. strcat(output1,",");
  2004. }
  2005. char num2[16];
  2006. sprintf(num2, "%d", map[y][spritewidth-1]);
  2007. strcat(output1,num2);
  2008. if(y<spriteheight-1){
  2009. strcat(output1,"},\n");
  2010. }else{
  2011. strcat(output1,"}};\n");
  2012. }
  2013. }
  2014. SetClipboardText(output1);
  2015. }
  2016. void tilemapview(){
  2017. // canvas.Color = Color.Black
  2018. // canvas.DrawRect(tilemapx,tilemapy,tilemapwidth,tilemapheight)
  2019. DrawRectangle(tilemapx,tilemapy,tilemapwidth,tilemapheight,BLACK);
  2020. // canvas.Color = Color.White
  2021. for(int y=0; y<tilemaptilesscreenvertical;y++){
  2022. for(int x=0; x<tilemaptilesscreenhorizontal;x++){
  2023. int pointx=(x*spritewidth*spritelibscale)+tilemapx;
  2024. int pointy=(y*spriteheight*spritelibscale)+tilemapy;
  2025. //canvas.DrawImage(spritelibim[tilemap[x,y]],pointx,pointy)
  2026. //DrawTexture(spritelibim[tilemap[x][y]].texture,pointx,pointy,WHITE);
  2027. DrawTextureRec( spritelibim[tilemap[x][y]].texture,
  2028. (Rectangle){ 0, 0,
  2029. spritelibim[tilemap[x][y]].texture.width,
  2030. -spritelibim[tilemap[x][y]].texture.height },
  2031. (Vector2){pointx,pointy}, WHITE);
  2032. }}
  2033. if(IsMouseButtonDown(0)){
  2034. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,tilemapx,tilemapy,tilemapwidth,tilemapheight)){
  2035. int x=(GetMouseX()-tilemapx) / (spritewidth*spritelibscale);
  2036. int y=(GetMouseY()-tilemapy) / (spriteheight*spritelibscale);
  2037. if(x<0 || y<0 || x>=tilemaptileshorizontal || y>=tilemaptilesvertical){
  2038. }else{
  2039. tilemap[x][y] = spritelibselected;
  2040. }
  2041. }
  2042. }
  2043. // Tab back to sprite view
  2044. if(IsKeyReleased(KEY_TAB)){
  2045. topbarcurrentid = topbarspriteeditid;
  2046. }
  2047. }
  2048. void fillatposition(int x, int y,int oldcolor,int newcolor)
  2049. {
  2050. if(x<0 || x>=10 || y<0 || y>=10)return;
  2051. if(map[x][y] == oldcolor){
  2052. map[x][y] = newcolor;
  2053. fillatposition(x-1,y,oldcolor,newcolor);
  2054. fillatposition(x+1,y,oldcolor,newcolor);
  2055. fillatposition(x,y-1,oldcolor,newcolor);
  2056. fillatposition(x,y+1,oldcolor,newcolor);
  2057. return;
  2058. }
  2059. }
  2060. /*
  2061. Method fillatposition(x:Int,y:Int)
  2062. Local ol:List<pathnode> = New List<pathnode>
  2063. ' Add the start position on the list
  2064. ol.AddLast(New pathnode(x,y))
  2065. ' set the cloes map at the start position to distance 1
  2066. Local colorundermouse:Int=map[x,y]
  2067. map[x,y] = paletteselected
  2068. ' some helper arrays. We can determine the top,right,and bottom
  2069. ' and left position cells with these numbers.
  2070. Local dx:Int[] = New Int[](0,1,0,-1)
  2071. Local dy:Int[] = New Int[](-1,0,1,0)
  2072. ' While there is contents in the list
  2073. While ol.Count() <> 0
  2074. ' Get the current location
  2075. Local x1:Int=ol.First.x
  2076. Local y1:Int=ol.First.y
  2077. ' Remove the current location from the list
  2078. ol.RemoveFirst()
  2079. ' Get 4 new positions around the current positions
  2080. For Local i:=0 Until 4
  2081. ' Set new x and y
  2082. Local nx:Int=x1+dx[i]
  2083. Local ny:Int=y1+dy[i]
  2084. ' If the coordinates are inside the map
  2085. If nx>=0 And ny>=0 And nx<spritewidth And ny<spriteheight
  2086. ' If the closedmap is not written to yet
  2087. If map[nx,ny] = colorundermouse And map[nx,ny] <> paletteselected
  2088. ' Set the new distance based on the current distance
  2089. map[nx,ny] = paletteselected
  2090. ' Add new position to the list
  2091. ol.AddLast(New pathnode(nx,ny))
  2092. End If
  2093. End If
  2094. Next
  2095. Wend
  2096. End Method
  2097. */
  2098. // For creating ovals(circles)
  2099. //
  2100. void midptellipse(int rx, int ry,
  2101. int xc, int yc){
  2102. // Erase the tempmap array.
  2103. for(int y=0;y<32;y++){
  2104. for(int x=0;x<32;x++){
  2105. tempmap[x][y] = 0;
  2106. }
  2107. }
  2108. float dx, dy, d1, d2, x, y;
  2109. x = 0;
  2110. y = ry;
  2111. // Initial decision parameter of region 1
  2112. d1 = (ry * ry) - (rx * rx * ry) +
  2113. (0.25 * rx * rx);
  2114. dx = 2 * ry * ry * x;
  2115. dy = 2 * rx * rx * y;
  2116. // For region 1
  2117. while (dx < dy)
  2118. {
  2119. // Print points based on 4-way symmetry
  2120. int tx[4] = {x+xc,-x+xc,x+xc,-x+xc};
  2121. int ty[4] = {y+yc,y+yc,-y+yc,-y+yc};
  2122. for(int i=0;i<4;i++){
  2123. if(tx[i]>=0 && tx[i]<32 && ty[i]>=0 && ty[i]<32)tempmap[tx[i]][ty[i]] = 1;
  2124. }
  2125. // Checking and updating value of
  2126. // decision parameter based on algorithm
  2127. if (d1 < 0)
  2128. {
  2129. x++;
  2130. dx = dx + (2 * ry * ry);
  2131. d1 = d1 + dx + (ry * ry);
  2132. }
  2133. else
  2134. {
  2135. x++;
  2136. y--;
  2137. dx = dx + (2 * ry * ry);
  2138. dy = dy - (2 * rx * rx);
  2139. d1 = d1 + dx - dy + (ry * ry);
  2140. }
  2141. }
  2142. // Decision parameter of region 2
  2143. d2 = ((ry * ry) * ((x + 0.5) * (x + 0.5))) +
  2144. ((rx * rx) * ((y - 1) * (y - 1))) -
  2145. (rx * rx * ry * ry);
  2146. // Plotting points of region 2
  2147. while (y >= 0)
  2148. {
  2149. int tx[4] = {x+xc,-x+xc,x+xc,-x+xc};
  2150. int ty[4] = {y+yc,y+yc,-y+yc,-y+yc};
  2151. for(int i=0;i<4;i++){
  2152. if(tx[i]>=0 && tx[i]<32 && ty[i]>=0 && ty[i]<32)tempmap[tx[i]][ty[i]] = 1;
  2153. }
  2154. // Checking and updating parameter
  2155. // value based on algorithm
  2156. if (d2 > 0)
  2157. {
  2158. y--;
  2159. dy = dy - (2 * rx * rx);
  2160. d2 = d2 + (rx * rx) - dy;
  2161. }
  2162. else
  2163. {
  2164. y--;
  2165. x++;
  2166. dx = dx + (2 * ry * ry);
  2167. dy = dy - (2 * rx * rx);
  2168. d2 = d2 + dx - dy + (rx * rx);
  2169. }
  2170. }
  2171. }
  2172. bool rectsoverlap(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2){
  2173. if((x1 >= (x2 + w2) || (x1 + w1) <= x2))return false;
  2174. if((y1 >= (y2 + h2) || (y1 + h1) <= y2))return false;
  2175. return true;
  2176. }
  2177. bool circlerectcollide(int cx,int cy,int cr,int rx,int ry,int rw,int rh){
  2178. float closestx = Clamp(cx, rx, rx+rw);
  2179. float closesty = Clamp(cy, ry, ry+rh);
  2180. float distancex = cx - closestx;
  2181. float distancey = cy - closesty;
  2182. float distancesquared = (distancex * distancex) + (distancey * distancey);
  2183. return distancesquared < (cr * cr);
  2184. }
  2185. // Clamp float value
  2186. float Clamp(float value, float min, float max)
  2187. {
  2188. const float res = value < min ? min : value;
  2189. return res > max ? max : res;
  2190. }
  2191. void copyfromclipboard(){
  2192. for(int y=0;y<32;y++){
  2193. for(int x=0;x<32;x++){
  2194. tempmap[x][y]=0;
  2195. }
  2196. }
  2197. // Create a char to read the clipboard with.
  2198. char clipBoardTxt[10024];
  2199. // Create a pointer to the clipboardtxt char
  2200. const char *clipPointer = clipBoardTxt;
  2201. // Read the contents of the clipboard into the clipboardtxt pointer
  2202. clipPointer = GetClipboardText();
  2203. // create a char
  2204. char work[1024];
  2205. if(strlen(clipPointer)<1000){
  2206. // copy the contents of the char that has a pointer containing the clipboard txt into this work char
  2207. strcpy(work,clipPointer);
  2208. }
  2209. // count the comma's and the numbers.
  2210. // int numCommas = countcommas(work);
  2211. int numNumbers = countnumbers(work);
  2212. if(importspriteis8x8(numNumbers)){
  2213. readtempsprite(8,8,work);
  2214. //create8x8sprite();
  2215. }
  2216. }
  2217. void readtempsprite(int w,int h,char *in){
  2218. int cnt=0;
  2219. int x=0;
  2220. int y=0;
  2221. bool insidearray=false;
  2222. int cnt2=0;
  2223. for(int i=0;in[i];i++){
  2224. if(cnt2<2 && in[i]=='{')cnt2++;
  2225. if(cnt2>=1)insidearray=true;
  2226. if(insidearray && in[i] >= '0' && in[i] <='9'){
  2227. int z=0;
  2228. int num=0;
  2229. char charnum[14]="";
  2230. //while(in[i]!=','){
  2231. do{
  2232. charnum[z]=in[i];
  2233. i++;
  2234. z++;
  2235. if(i+1>=strlen(in))break;//no longer numbers than 3
  2236. }while(in[i]!=',');
  2237. num = atoi(charnum);
  2238. cnt++;
  2239. if(cnt>1){
  2240. y++;
  2241. if(y>=h){
  2242. y=0;
  2243. x++;
  2244. }
  2245. }
  2246. if(num>=numpalette)num=0;
  2247. //tempsprite[x][y] = num;//in[i]-'0';
  2248. map[x][y] = num;//in[i]-'0';
  2249. //if(num>15)map[x][y]=0;
  2250. }
  2251. }
  2252. }
  2253. int countcommas(char *in){
  2254. int out=0;
  2255. for(int i=0;in[i];i++){
  2256. if(in[i] == ',')out++;
  2257. }
  2258. return out;
  2259. }
  2260. int countnumbers(char *in){
  2261. int out=0;
  2262. for(int i=0;in[i];i++){
  2263. if(in[i] >= '0' && in[i] <= '9'){
  2264. while(in[i] >= '0' && in[i] <= '9' && i<strlen(in)){
  2265. i++;
  2266. }
  2267. out++;
  2268. }
  2269. }
  2270. return out;
  2271. }
  2272. bool importspriteis8x8(int in){
  2273. if(in-2 == 8*8)return true;
  2274. return false;
  2275. }
  2276. bool importspriteis16x16(int in){
  2277. if(in-2 == 16*16)return true;
  2278. return false;
  2279. }
  2280. bool importspriteis32x32(int in){
  2281. if(in-2 == 32*32)return true;
  2282. return false;
  2283. }