2
0

spriteeditor.c 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877
  1. // WORK IN PROGRESS CONVERSION....
  2. //
  3. #include "raylib.h"
  4. #include <math.h>
  5. static int tempmap[32][32] = {0};
  6. // start setup
  7. static int weasel=0;
  8. static int startsetuppalettemode; // '0=c64 1=db32
  9. static bool startsetupdone;
  10. static int startsetupx;
  11. static int startsetupy;
  12. static int startsetupwidth;
  13. static int startsetupheight;
  14. static RenderTexture2D startsetupim[5]; //5=numstartsetup
  15. //Field startsetupcan:Canvas[]
  16. static int startsetupselected;
  17. static int startsetup8x8id;
  18. static int startsetup16x16id = 1;
  19. static int startsetup32x32id = 2;
  20. static int startsetupc64id = 3;
  21. static int startsetupdb32id = 4;
  22. static int numstartsetup = 5;
  23. //'
  24. //'tool view
  25. static int toolx;
  26. static int tooly;
  27. static int toolwidth;
  28. static int toolheight;
  29. static RenderTexture2D toolim[16]; //16 = numtools
  30. //Field toolcan:Canvas[]
  31. static bool toolgridtoggle = true;
  32. static int toolselected = 0;
  33. static int toolpencilid = 0;
  34. static int tooleraserid = 1;
  35. static int toolfillid = 2;
  36. static int toollineid = 3;
  37. static int toolselectionid = 4;
  38. static int toolcopyid = 5;
  39. static int toolpasteid = 6;
  40. static int toolcutid = 7;
  41. static int toolflipverticalid = 8;
  42. static int toolfliphorizontalid = 9;
  43. static int toolcolorpickerid = 10;
  44. static int toolgridid = 11;
  45. static int toolfilledrectid = 12;
  46. static int tooloutlinerectid = 13;
  47. static int toolfilledcircleid = 14;
  48. static int tooloutlinecircleid = 15;
  49. static int numtools = 16;
  50. static int delay;
  51. static int delaydefault = 20;
  52. //'
  53. //' sprite library
  54. static int spritelibx;
  55. static int spriteliby;
  56. static int spritelibwidth;
  57. static int spritelibheight;
  58. static int numspritelib;
  59. static RenderTexture2D spritelibim[80*4]; // 80*4 = numspritelib
  60. //Field spritelibcan:Canvas[]
  61. static int spritelibmap[80*4][32][32]; // numspritelib,
  62. static int spritelibselected = 0;
  63. static float spritelibscale;
  64. //'
  65. //'preview
  66. static RenderTexture2D previewim;
  67. //Field previewcan:Canvas
  68. static int previewx;
  69. static int previewy;
  70. static int previewwidth;
  71. static int previewheight;
  72. static int previewcellwidth;
  73. static int previewcellheight;
  74. // tile map view
  75. static int tilemapx;
  76. static int tilemapy;
  77. static int tilemapwidth;
  78. static int tilemapheight;
  79. static int tilemaptileshorizontal;
  80. static int tilemaptilesvertical;
  81. static int tilemaptilesscreenhorizontal=100;
  82. static int tilemaptilesscreenvertical=100;
  83. static int tilemap[100][100];
  84. //'
  85. //'sprite view
  86. static int map[32][32]; // 8 = edit canvas width
  87. static int canvasx;
  88. static int canvasy; //'canvas x and y position on the scrern
  89. static float canvaswidth=256;
  90. static float canvasheight=256; //'width and height of our canvas
  91. static float gridwidth;
  92. static float gridheight;// ' grids width and height
  93. static int spritewidth;
  94. static int spriteheight;// ' our main sprite width and height
  95. //' line tool fields
  96. static bool linepressed=false;
  97. static bool lineactive=false;
  98. static int linestartx;
  99. static int linestarty;
  100. static int lineendx;
  101. static int lineendy;
  102. //' Selection fields
  103. static bool selectionpressed = false ;
  104. static bool selectionactive = false;
  105. static int selectionstartx;
  106. static int selectionstarty;
  107. static int selectionendx;
  108. static int selectionendy;
  109. static int selectionbuffer[32][32]; //'our copy paste buffer
  110. static int selectionbufferstartx;
  111. static int selectionbufferstarty;
  112. static int selectionbufferendx;
  113. static int selectionbufferendy;
  114. static bool selectionnegativeswitchx = false;// ' switch if negative selection
  115. static bool selectionnegativeswitchy = false;
  116. //' filled/outlined rectsangles and circles fields
  117. static bool bcselectionpressed = false;
  118. static bool bcselectionactive = false;
  119. static int bcselectionstartx;
  120. static int bcselectionstarty;
  121. static int bcselectionendx;
  122. static int bcselectionendy;
  123. static int bcselectionbuffer[32][32];// 'our copy paste buffer
  124. static int bcselectionbufferstartx;
  125. static int bcselectionbufferstarty;
  126. static int bcselectionbufferendx;
  127. static int bcselectionbufferendy;
  128. static bool bcselectionnegativeswitchx = false; // ' switch if negative selection
  129. static bool bcselectionnegativeswitchy = false;
  130. //'
  131. //' palette
  132. static Color c64color[16]; //' our colors
  133. static Color db32color[32];// ' our colors
  134. static int paletteselected;// ' our selected color from palette
  135. static int paletteeraser;
  136. static int palettex;
  137. static int palettey; //'screen x and y
  138. static float palettewidth;
  139. static float paletteheight;// ' our palette screen w and h
  140. static float palettecellwidth;
  141. static float palettecellheight; //'cell width and height of color
  142. static int numpalette;// 'number of colors
  143. //'
  144. //' Top Bar
  145. static int topbarx;
  146. static int topbary;
  147. static int topbarwidth;
  148. static int topbarheight;
  149. static Color topbarcolor;
  150. static RenderTexture2D topbarim[3];
  151. //Field topbarcan:Canvas[]
  152. static int topbarspriteeditid = 0;
  153. static int topbarmapeditid = 1;
  154. static int numtopbaricons = 2;
  155. static int topbarcurrentid = 0;
  156. //'
  157. //' Middle bar
  158. static int middlebarx;
  159. static int middlebary;
  160. static int middlebarwidth;
  161. static int middlebarheight;
  162. static Color middlebarcolor;
  163. static RenderTexture2D middlebarim[4]; //nummiddlebaricons
  164. //Field middlebarcan:Canvas[]
  165. static int middlebar0id = 0;
  166. static int middlebar1id = 1;
  167. static int middlebar2id = 2;
  168. static int middlebar3id = 3;
  169. static int nummiddlebaricons = 4;
  170. static int middlebarcurrentid = 0;
  171. //'
  172. //' Bottom Bar
  173. static int bottombarx;
  174. static int bottombary;
  175. static int bottombarwidth;
  176. static int bottombarheight;
  177. static Color bottombarcolor;
  178. static void inic64colors(void);
  179. static void inidb32colors(void);
  180. static bool rectsoverlap(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2);
  181. static bool circlerectcollide(int cx,int cy,int cr,int rx,int ry,int rw,int rh);
  182. static float Clamp(float value, float min, float max);
  183. static void startsetupsetup(void);
  184. static void startsetupview(void);
  185. static void bottombarview(void);
  186. static void middlebarview();
  187. static void setupmiddlebar(void);
  188. static void setuptopbar(void);
  189. static void paletteview(void);
  190. static void spritegrid(void);
  191. static void toolview(void);
  192. static void spritelibview(void);
  193. static void spriteview(void);
  194. static void updatespritelib(void);
  195. static void updatepreview(void);
  196. static void spritelibcopytocanvas(void);
  197. int main(void)
  198. {
  199. // Initialization
  200. //--------------------------------------------------------------------------------------
  201. const int screenWidth = 640;
  202. const int screenHeight = 480;
  203. InitWindow(screenWidth, screenHeight, "raylib example.");
  204. //'start setup setup
  205. //' be sure to start the editor with the selection
  206. startsetupdone=false;
  207. startsetupx = 320-80;
  208. startsetupy = 150;
  209. startsetupwidth = 150;
  210. startsetupheight = 200-35;
  211. //startsetupim = New Image[numstartsetup];
  212. //startsetupcan = New Canvas[numstartsetup]
  213. for(int i=0;i<numstartsetup;i++){
  214. startsetupim[i] = LoadRenderTexture(32, 32);
  215. BeginTextureMode(startsetupim[i]);
  216. ClearBackground(BLANK); // Make the entire Sprite Transparent.
  217. EndTextureMode();
  218. //startsetupcan[i] = New Canvas(startsetupim[i])
  219. }
  220. inic64colors();
  221. inidb32colors();
  222. startsetupsetup();
  223. paletteeraser = 0;
  224. palettex = 640-150;
  225. palettey = 32;
  226. palettewidth = 32*4;
  227. paletteheight = 32*4;
  228. numpalette = 16;
  229. palettecellwidth = 32;
  230. palettecellheight = 32;
  231. //sprite canvas setup
  232. canvasx = 32;
  233. canvasy = 28;
  234. //spritewidth = 16;
  235. //spriteheight = 16;
  236. //map = New Int[spritewidth,spriteheight]
  237. //selectionbuffer = New Int[spritewidth,spriteheight]
  238. canvaswidth=256;
  239. canvasheight=256;
  240. // gridwidth = canvaswidth/spritewidth;
  241. // gridheight = canvasheight/spriteheight;
  242. //'Bottom bar (global)
  243. bottombarx = 0;
  244. bottombary = 480-24;
  245. bottombarwidth = 640;
  246. bottombarheight = 24;
  247. bottombarcolor = (Color){ 78, 22, 9,255 };//Color.Puce
  248. //'
  249. //' Middle bar
  250. middlebarx = 0;
  251. middlebary = canvasheight+32;
  252. middlebarwidth = 640;
  253. middlebarheight = 32;
  254. middlebarcolor = GRAY;
  255. nummiddlebaricons = 4;
  256. //middlebarim = New Image[nummiddlebaricons]
  257. //middlebarcan = New Canvas[nummiddlebaricons]
  258. for(int i=0;i<nummiddlebaricons;i++){
  259. middlebarim[i] = LoadRenderTexture(32, 32);
  260. BeginTextureMode(middlebarim[i]);
  261. ClearBackground(BLANK);
  262. EndTextureMode();
  263. //middlebarcan[i] = New Canvas(middlebarim[i])
  264. }
  265. setupmiddlebar();
  266. //Top bar (global)
  267. topbarx = 0;
  268. topbary = 0;
  269. topbarwidth = 640;
  270. topbarheight = 24;
  271. topbarcolor = (Color){ 78, 22, 9,255};//Color.Puce
  272. //topbarim = New Image[3]
  273. //topbarcan = New Canvas[3]
  274. for(int i=0;i<2;i++){
  275. topbarim[i] = LoadRenderTexture(32, 32);
  276. BeginTextureMode(topbarim[i]);
  277. ClearBackground(BLANK);
  278. EndTextureMode();
  279. }
  280. setuptopbar();
  281. //'
  282. //'spritelib setup
  283. spritelibx = 0;
  284. spriteliby = canvasheight+32+32;
  285. spritelibwidth = 640;
  286. spritelibheight = 128;
  287. numspritelib = 80*4;
  288. spritelibselected = 0;
  289. spritelibscale = 2;
  290. //spritelibim = New Image[numspritelib]
  291. //spritelibcan = New Canvas[numspritelib]
  292. // For Local i:Int=0 Until numspritelib
  293. // spritelibim[i] = New Image(spritewidth*spritelibscale,spriteheight*spritelibscale)
  294. // spritelibcan[i] = New Canvas(spritelibim[i])
  295. // spritelibcan[i].Clear(Color.Black)
  296. // spritelibcan[i].Flush()
  297. // Next
  298. for(int i=0;i<numspritelib;i++){
  299. spritelibim[i] = LoadRenderTexture(32, 32);
  300. BeginTextureMode(spritelibim[i]);
  301. ClearBackground(BLANK);
  302. EndTextureMode();
  303. }
  304. //' tool view
  305. toolx = 340;
  306. tooly = 186-32;
  307. toolwidth = 32*4;
  308. toolheight = 32*4;
  309. //'numtools = 12
  310. //toolim = New Image[numtools]
  311. //toolcan = New Canvas[numtools]
  312. for(int i=0;i<numtools;i++){
  313. toolim[i] = LoadRenderTexture(32,32);
  314. BeginTextureMode(toolim[i]);
  315. ClearBackground(BLANK);
  316. EndTextureMode();
  317. //toolcan[i] = New Canvas(toolim[i])
  318. //toolcan[i].Clear(Color.Black)
  319. //toolcan[i].Flush()
  320. }
  321. setuptoolview();
  322. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  323. //--------------------------------------------------------------------------------------
  324. // Main game loop
  325. while (!WindowShouldClose()) // Detect window close button or ESC key
  326. {
  327. // Update
  328. //----------------------------------------------------------------------------------
  329. //----------------------------------------------------------------------------------
  330. // Draw
  331. //----------------------------------------------------------------------------------
  332. BeginDrawing();
  333. ClearBackground(DARKGRAY);
  334. //' We start the sprite editor with the sprite dimension
  335. //' resolution selection.
  336. if(startsetupdone==false){
  337. startsetupview();
  338. }else{
  339. //' Here is the map and sprite editor section
  340. if(topbarcurrentid == topbarspriteeditid){
  341. bottombarview();
  342. middlebarview();
  343. topbarview();
  344. spriteview();
  345. //previewline();
  346. spritegrid();
  347. //previewselection();
  348. paletteview();
  349. //previewview();
  350. spritelibview();
  351. toolview();
  352. }else if(topbarcurrentid == topbarmapeditid){
  353. //bottombarview();
  354. //middlebarview();
  355. //topbarview();
  356. //tilemapview();
  357. //spritelibview();
  358. }
  359. }
  360. //DrawText(FormatText("%i",spritewidth),0,0,20,BLACK);
  361. EndDrawing();
  362. //----------------------------------------------------------------------------------
  363. }
  364. // De-Initialization
  365. //--------------------------------------------------------------------------------------
  366. for(int i=0;i<5;i++){
  367. UnloadRenderTexture(startsetupim[i]);
  368. }
  369. for(int i=0;i<16;i++){
  370. UnloadRenderTexture(toolim[i]);
  371. }
  372. for(int i=0;i<80*4;i++){
  373. UnloadRenderTexture(spritelibim[i]);
  374. }
  375. UnloadRenderTexture(previewim);
  376. for(int i=0;i<3;i++){
  377. UnloadRenderTexture(topbarim[i]);
  378. }
  379. for(int i=0;i<4;i++){
  380. UnloadRenderTexture(middlebarim[i]);
  381. }
  382. CloseWindow(); // Close window and OpenGL context
  383. //--------------------------------------------------------------------------------------
  384. return 0;
  385. }
  386. void inic64colors(void){
  387. c64color[0 ] = (Color){0 , 0 , 0 , 255 };//Black
  388. c64color[1 ] = (Color){255,255,255, 255 };//White
  389. c64color[2 ] = (Color){136,0 ,0 , 255 };//Red
  390. c64color[3 ] = (Color){170,255,238, 255 };//Cyan
  391. c64color[4 ] = (Color){204,68 ,204, 255 };//Violet / Purple
  392. c64color[5 ] = (Color){0 ,204,85 , 255 };//Green
  393. c64color[6 ] = (Color){0 ,0 ,170, 255 };//Blue
  394. c64color[7 ] = (Color){238,238,119, 255 };//Yellow
  395. c64color[8 ] = (Color){221,136,85 , 255 };//Orange
  396. c64color[9 ] = (Color){102,68 ,0 , 255 };//Brown
  397. c64color[10] = (Color){255,119,119, 255 };//Light red
  398. c64color[11] = (Color){51 ,51 ,51 , 255 };//Dark grey / Grey 1
  399. c64color[12] = (Color){119,119,119, 255 };//Grey 2
  400. c64color[13] = (Color){170,255,102, 255 };//Light green
  401. c64color[14] = (Color){0 ,136,255, 255 };//Light blue
  402. c64color[15] = (Color){187,187,187, 255 };//Light grey / grey 3
  403. }
  404. void inidb32colors(){
  405. db32color[0 ] = (Color){0 ,0 ,0 ,255};
  406. db32color[1 ] = (Color){34 ,32 ,52 ,255};
  407. db32color[2 ] = (Color){69 ,40 ,60 ,255};
  408. db32color[3 ] = (Color){102 ,57 ,49 ,255};
  409. db32color[4 ] = (Color){143 ,86 ,59 ,255};
  410. db32color[5 ] = (Color){223 ,113 ,38 ,255};
  411. db32color[6 ] = (Color){217 ,160 ,102 ,255};
  412. db32color[7 ] = (Color){238 ,195 ,154 ,255};
  413. db32color[8 ] = (Color){251 ,242 ,54 ,255};
  414. db32color[9 ] = (Color){153 ,229 ,80 ,255};
  415. db32color[10] = (Color){106 ,190 ,48 ,255};
  416. db32color[11] = (Color){55 ,148 ,110 ,255};
  417. db32color[12] = (Color){75 ,105 ,47 ,255};
  418. db32color[13] = (Color){82 ,75 ,36 ,255};
  419. db32color[14] = (Color){50 ,60 ,57 ,255};
  420. db32color[15] = (Color){63 ,63 ,116 ,255};
  421. db32color[16] = (Color){48 ,96 ,130 ,255};
  422. db32color[17] = (Color){91 ,110 ,225 ,255};
  423. db32color[18] = (Color){99 ,155 ,225 ,255};
  424. db32color[19] = (Color){95 ,205 ,228 ,255};
  425. db32color[20] = (Color){203 ,219 ,252 ,255};
  426. db32color[21] = (Color){255 ,255 ,255 ,255};
  427. db32color[22] = (Color){155 ,173 ,183 ,255};
  428. db32color[23] = (Color){132 ,126 ,135 ,255};
  429. db32color[24] = (Color){105 ,106 ,106 ,255};
  430. db32color[25] = (Color){89 ,86 ,82 ,255};
  431. db32color[26] = (Color){118 ,66 ,138 ,255};
  432. db32color[27] = (Color){172 ,50 ,50 ,255};
  433. db32color[28] = (Color){217 ,87 ,99 ,255};
  434. db32color[29] = (Color){215 ,123 ,186 ,255};
  435. db32color[30] = (Color){143 ,151 ,74 ,255};
  436. db32color[31] = (Color){138 ,111 ,48 ,255};
  437. }
  438. void startsetupsetup(){
  439. // the 8x8 selection button
  440. int eightxeight[16][16] = {
  441. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  442. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  443. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  444. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  445. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  446. {12,12,1,1,1,12,12,12,12,12,1,1,1,12,12,12},
  447. {12,12,1,12,1,12,1,12,1,12,1,12,1,12,12,12},
  448. {12,12,1,1,1,12,12,1,12,12,1,1,1,12,12,12},
  449. {12,12,1,12,1,12,1,12,1,12,1,12,1,12,12,12},
  450. {12,12,1,1,1,12,12,12,12,12,1,1,1,12,12,12},
  451. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  452. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  453. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  454. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  455. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  456. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}};
  457. for(int y=0;y<16;y++){
  458. for(int x=0;x<16;x++){
  459. BeginTextureMode(startsetupim[startsetup8x8id]);
  460. //startsetupcan[startsetup8x8id].Color = c64color[eightxeight[y][x]]
  461. //If eightxeight[y][x] = 0 Then startsetupcan[startsetup8x8id].Alpha=0 Else startsetupcan[startsetup8x8id].Alpha=1
  462. //startsetupcan[startsetup8x8id].DrawRect(x*2,y*2,2,2)
  463. if(eightxeight[y][x]>0)DrawRectangle(x*2,y*2,2,2,c64color[eightxeight[y][x]]);
  464. EndTextureMode();
  465. }}
  466. //startsetupcan[startsetup8x8id].Flush()
  467. //the 16x16 selection button
  468. int sixteenxsixteen[16][16] = {
  469. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  470. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  471. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  472. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  473. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  474. {1,12,1,1,1,12,12,12,12,12,1,12,1,1,1,12},
  475. {1,12,1,12,12,12,1,12,1,12,1,12,1,12,12,12},
  476. {1,12,1,1,1,12,12,1,12,12,1,12,1,1,1,12},
  477. {1,12,1,12,1,12,1,12,1,12,1,12,1,12,1,12},
  478. {1,12,1,1,1,12,12,12,12,12,1,12,1,1,1,12},
  479. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  480. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  481. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  482. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  483. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  484. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}};
  485. for(int y=0;y<16;y++){
  486. for(int x=0;x<16;x++){
  487. BeginTextureMode(startsetupim[startsetup16x16id]);
  488. //startsetupcan[startsetup16x16id].Color = c64color[sixteenxsixteen[y][x]]
  489. //If sixteenxsixteen[y][x] = 0 Then startsetupcan[startsetup16x16id].Alpha=0 Else startsetupcan[startsetup16x16id].Alpha=1
  490. if(sixteenxsixteen[15-y][x]>0)DrawRectangle(x*2,y*2,2,2,c64color[sixteenxsixteen[15-y][x]]);
  491. //startsetupcan[startsetup16x16id].DrawRect(x*2,y*2,2,2)
  492. EndTextureMode();
  493. }}
  494. //startsetupcan[startsetup16x16id].Flush()
  495. // the 32x32 selection button
  496. int thirtytwoxthirtytwo[16][16] = {
  497. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  498. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  499. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  500. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  501. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  502. {1,1,12,1,1,12,12,12,12,12,1,1,12,1,1,12},
  503. {12,1,12,12,1,12,1,12,1,12,12,1,12,12,1,12},
  504. {1,1,12,1,1,12,12,1,12,12,1,1,12,1,1,12},
  505. {12,1,12,1,12,12,1,12,1,12,12,1,12,1,12,12},
  506. {1,1,12,1,1,12,12,12,12,12,1,1,12,1,1,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,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  512. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}};
  513. for(int y=0;y<16;y++){
  514. for(int x=0;x<16;x++){
  515. BeginTextureMode(startsetupim[startsetup32x32id]);
  516. //startsetupcan[startsetup32x32id].Color = c64color[thirtytwoxthirtytwo[y][x]]
  517. //If thirtytwoxthirtytwo[y][x] = 0 Then startsetupcan[startsetup32x32id].Alpha=0 Else startsetupcan[startsetup32x32id].Alpha=1
  518. //startsetupcan[startsetup32x32id].DrawRect(x*2,y*2,2,2)
  519. if(thirtytwoxthirtytwo[15-y][x]>0)DrawRectangle(x*2,y*2,2,2,c64color[thirtytwoxthirtytwo[15-y][x]]);
  520. EndTextureMode();
  521. }}
  522. //startsetupcan[startsetup32x32id].Flush()
  523. // the c64 palette selection button
  524. int c641616[16][16] = {
  525. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  526. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  527. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  528. {12,12,1,1,12,12,12,1,1,12,12,1,12,12,12,12},
  529. {12,1,12,12,12,12,1,12,12,12,12,1,12,12,12,12},
  530. {12,1,12,12,12,12,1,12,12,12,12,1,12,12,1,12},
  531. {12,1,12,12,12,12,1,1,1,12,12,1,1,1,1,12},
  532. {12,1,12,12,12,12,1,12,12,1,12,12,12,12,1,12},
  533. {12,1,12,12,12,12,1,12,12,1,12,12,12,12,1,12},
  534. {12,12,1,1,12,12,12,1,1,12,12,12,12,12,1,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. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  540. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}};
  541. for(int y=0;y<16;y++){
  542. for(int x=0;x<16;x++){
  543. BeginTextureMode(startsetupim[startsetupc64id]);
  544. //startsetupcan[startsetupc64id].Color = c64color[c641616[y][x]]
  545. //If c641616[y][x] = 0 Then startsetupcan[startsetupc64id].Alpha=0 Else startsetupcan[startsetupc64id].Alpha=1
  546. //startsetupcan[startsetupc64id].DrawRect(x*2,y*2,2,2)
  547. if(c641616[15-y][x]>0)DrawRectangle(x*2,y*2,2,2,c64color[c641616[15-y][x]]);
  548. EndTextureMode();
  549. }}
  550. //startsetupcan[startsetupc64id].Flush()
  551. // the db32 palette selection button
  552. int db321616[16][16] = {
  553. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  554. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  555. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  556. {12,12,1,12,1,12,12,12,1,1,12,12,1,1,1,12},
  557. {12,12,1,12,1,12,12,12,12,12,1,12,12,12,1,12},
  558. {12,12,1,12,1,12,12,12,12,12,1,12,12,12,1,12},
  559. {12,1,1,12,1,1,12,12,1,1,12,12,1,1,1,12},
  560. {1,12,1,12,1,12,1,12,12,12,1,12,1,12,12,12},
  561. {1,12,1,12,1,12,1,12,12,12,1,12,1,12,12,12},
  562. {1,1,1,12,1,1,1,12,1,1,12,12,1,1,1,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. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
  568. {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}};
  569. for(int y=0;y<16;y++){
  570. for(int x=0;x<16;x++){
  571. BeginTextureMode(startsetupim[startsetupdb32id]);
  572. //startsetupcan[startsetupdb32id].Color = c64color[db321616[y][x]]
  573. //If db321616[y][x] = 0 Then startsetupcan[startsetupdb32id].Alpha=0 Else startsetupcan[startsetupdb32id].Alpha=1
  574. //startsetupcan[startsetupdb32id].DrawRect(x*2,y*2,2,2)
  575. if(db321616[15-y][x]>0)DrawRectangle(x*2,y*2,2,2,c64color[db321616[15-y][x]]);
  576. EndTextureMode();
  577. }}
  578. //startsetupcan[startsetupdb32id].Flush()
  579. }
  580. void startsetupview(){
  581. //canvas.Color = Color.Black
  582. DrawRectangle(startsetupx-1,startsetupy-1,startsetupwidth+2,startsetupheight+2,BLACK);
  583. //canvas.Color = c64color[12]
  584. DrawRectangle(startsetupx,startsetupy,startsetupwidth,startsetupheight,c64color[12]);
  585. //Local selected:Bool=False
  586. bool selected = false;
  587. for(int i=0;i<3;i++){
  588. //canvas.Color = Color.Grey.Blend(Color.Black,.5)
  589. //DrawRectangle(startsetupx+8+20,startsetupy+8+i*48,32,32,GRAY);
  590. //canvas.Color = Color.White
  591. DrawTexture(startsetupim[i].texture,startsetupx+9+20,startsetupy+9+i*48,WHITE);
  592. //' draw the palette buttons
  593. //canvas.Color = Color.Black
  594. //DrawRectangle(startsetupx+8+50,startsetupy+8+i*48,32,32,BLACK);
  595. //canvas.Color = Color.White
  596. //DrawTexture(startsetupim[3],startsetupx+9+50,startsetupy+9+i*48,0,.9,.9)
  597. DrawTexture(startsetupim[3].texture,startsetupx+9+60,startsetupy+9+i*48,WHITE);
  598. //canvas.Color = Color.Black
  599. //DrawRectangle(startsetupx+8+80,startsetupy+8+i*48,32,32,BLACK);
  600. //canvas.Color = Color.White
  601. DrawTexture(startsetupim[4].texture,startsetupx+9+100,startsetupy+9+i*48,WHITE);
  602. if(IsMouseButtonDown(0)){
  603. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,startsetupx+9+60,startsetupy+9+i*48,32,32)){
  604. startsetupselected = i;
  605. startsetuppalettemode = 0;
  606. selected = true;
  607. }
  608. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,startsetupx+9+100,startsetupy+9+i*48,32,32)){
  609. startsetupselected = i;
  610. startsetuppalettemode = 1;
  611. selected = true;
  612. }
  613. }
  614. }
  615. if(selected == true){
  616. if(startsetuppalettemode == 1){// ' if the db32 palette was selected
  617. paletteeraser = 0;
  618. palettex = 640-150;
  619. palettey = 32;
  620. palettewidth = 32*4;
  621. paletteheight = 32*4;
  622. numpalette = 32;
  623. palettecellwidth = 32*4/4;
  624. palettecellheight = 32*4/8;
  625. }
  626. switch (startsetupselected){
  627. case 0:
  628. spritelibscale = 4;
  629. spritewidth = 8;
  630. spriteheight = 8;
  631. //map = New Int[spritewidth,spriteheight]
  632. //selectionbuffer = New Int[spritewidth,spriteheight];
  633. gridwidth = canvaswidth/spritewidth;
  634. gridheight = canvasheight/spriteheight;
  635. //spritelibmap = New Int[numspritelib,spritewidth,spriteheight];
  636. break;
  637. case 1:
  638. spritelibscale = 2;
  639. spritewidth = 16;
  640. spriteheight = 16;
  641. //map = New Int[spritewidth,spriteheight];
  642. //selectionbuffer = New Int[spritewidth,spriteheight];
  643. gridwidth = canvaswidth/spritewidth;
  644. gridheight = canvasheight/spriteheight;
  645. //spritelibmap = New Int[numspritelib,spritewidth,spriteheight];
  646. break;
  647. case 2:
  648. spritelibscale = 1;
  649. spritewidth = 32;
  650. spriteheight = 32;
  651. //map = New Int[spritewidth,spriteheight];
  652. //selectionbuffer = New Int[spritewidth,spriteheight];
  653. gridwidth = canvaswidth/spritewidth;
  654. gridheight = canvasheight/spriteheight;
  655. //spritelibmap = New Int[numspritelib,spritewidth,spriteheight];
  656. break;
  657. }
  658. startsetupdone = true;
  659. }
  660. }
  661. void bottombarview(){
  662. //canvas.Color = bottombarcolor
  663. DrawRectangle(bottombarx,bottombary,bottombarwidth,bottombarheight,bottombarcolor);
  664. //canvas.Color = bottombarcolor/2
  665. DrawRectangle(bottombarx,bottombary+bottombarheight/2,bottombarwidth,bottombarheight/2,(Color){50,5,2,255});
  666. }
  667. void middlebarview(){
  668. //canvas.Color = middlebarcolor
  669. DrawRectangle(middlebarx,middlebary,middlebarwidth,middlebarheight,middlebarcolor);
  670. //canvas.Color = middlebarcolor/2
  671. DrawRectangle(middlebarx,middlebary+middlebarheight/2,middlebarwidth,middlebarheight/2,DARKGRAY);
  672. //' Draw the icons ..
  673. int num = 0;
  674. for(int x = 640-128;x<640;x+=32){
  675. if(num>=nummiddlebaricons)continue;
  676. int pointx=x+middlebarx;
  677. int pointy=middlebary;
  678. if(middlebarcurrentid == num){
  679. //canvas.Color=Color.White
  680. DrawTexture(middlebarim[num].texture,pointx,pointy,WHITE);
  681. }else{
  682. DrawTexture(middlebarim[num].texture,pointx,pointy,DARKGRAY);
  683. //canvas.Color=Color.DarkGrey
  684. }
  685. //canvas.DrawImage(middlebarim[num],pointx,pointy)
  686. //'
  687. //' Selection of the sprite editor or the map editor
  688. if(IsMouseButtonDown(0)){
  689. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,32,32)){
  690. middlebarcurrentid = num;
  691. }
  692. }
  693. num+=1;
  694. }
  695. }
  696. void setupmiddlebar(){
  697. int zero[8][8]={
  698. {0,12,12,12,12,12,12,0},
  699. {12,12,12,1,1,1,12,12},
  700. {12,12,12,1,12,1,12,12},
  701. {12,12,12,1,12,1,12,12},
  702. {12,12,12,1,12,1,12,12},
  703. {12,12,12,1,1,1,12,12},
  704. {12,12,12,12,12,12,12,12},
  705. {12,12,12,12,12,12,12,12}};
  706. for(int y=0;y<8;y++){
  707. for(int x=0;x<8;x++){
  708. //middlebarcan[middlebar0id].Color = c64color[zero[y][x]]
  709. //If zero[y][x] = 0 Then middlebarcan[middlebar0id].Alpha=0 Else middlebarcan[middlebar0id].Alpha=1
  710. BeginTextureMode(middlebarim[middlebar0id]);
  711. DrawRectangle(x*4,y*4,4,4,c64color[zero[7-y][x]]);
  712. EndTextureMode();
  713. }}
  714. //middlebarcan[middlebar0id].Flush()
  715. int one[8][8]={
  716. {0,12,12,12,12,12,12,0},
  717. {12,12,12,1,1,12,12,12},
  718. {12,12,12,12,1,12,12,12},
  719. {12,12,12,12,1,12,12,12},
  720. {12,12,12,12,1,12,12,12},
  721. {12,12,12,1,1,1,12,12},
  722. {12,12,12,12,12,12,12,12},
  723. {12,12,12,12,12,12,12,12}};
  724. for(int y=0;y<8;y++){
  725. for(int x=0;x<8;x++){
  726. //middlebarcan[middlebar1id].Color = c64color[one[y][x]]
  727. //If one[y][x] = 0 Then middlebarcan[middlebar1id].Alpha=0 Else middlebarcan[middlebar1id].Alpha=1
  728. BeginTextureMode(middlebarim[middlebar1id]);
  729. DrawRectangle(x*4,y*4,4,4,c64color[one[7-y][x]]);
  730. EndTextureMode();
  731. }}
  732. //middlebarcan[middlebar1id].Flush()
  733. int two[8][8]={
  734. {0,12,12,12,12,12,12,0},
  735. {12,12,12,1,1,1,12,12},
  736. {12,12,12,12,12,1,12,12},
  737. {12,12,12,12,1,12,12,12},
  738. {12,12,12,1,12,12,12,12},
  739. {12,12,12,1,1,1,12,12},
  740. {12,12,12,12,12,12,12,12},
  741. {12,12,12,12,12,12,12,12}};
  742. for(int y=0;y<8;y++){
  743. for(int x=0;x<8;x++){
  744. //middlebarcan[middlebar2id].Color = c64color[two[y][x]]
  745. //If two[y][x] = 0 Then middlebarcan[middlebar2id].Alpha=0 Else middlebarcan[middlebar2id].Alpha=1
  746. BeginTextureMode(middlebarim[middlebar2id]);
  747. DrawRectangle(x*4,y*4,4,4,c64color[two[7-y][x]]);
  748. EndTextureMode();
  749. }}
  750. //middlebarcan[middlebar2id].Flush()
  751. int three[8][8]={
  752. {0,12,12,12,12,12,12,0},
  753. {12,12,12,1,1,1,12,12},
  754. {12,12,12,12,12,1,12,12},
  755. {12,12,12,12,1,1,12,12},
  756. {12,12,12,12,12,1,12,12},
  757. {12,12,12,1,1,1,12,12},
  758. {12,12,12,12,12,12,12,12},
  759. {12,12,12,12,12,12,12,12}};
  760. for(int y=0;y<8;y++){
  761. for(int x=0;x<8;x++){
  762. //middlebarcan[middlebar3id].Color = c64color[three[y][x]]
  763. //If three[y][x] = 0 Then middlebarcan[middlebar3id].Alpha=0 Else middlebarcan[middlebar3id].Alpha=1
  764. BeginTextureMode(middlebarim[middlebar3id]);
  765. DrawRectangle(x*4,y*4,4,4,c64color[three[7-y][x]]);
  766. EndTextureMode();
  767. }}
  768. //middlebarcan[middlebar3id].Flush()
  769. }
  770. void setuptopbar(){
  771. int mapedit[8][8] = {
  772. {1,1,1,0,0,1,1,0},
  773. {1,1,1,0,0,1,1,0},
  774. {1,1,1,0,0,0,0,0},
  775. {0,0,0,1,1,1,1,1},
  776. {1,1,0,1,1,1,1,1},
  777. {1,1,0,1,1,1,1,1},
  778. {0,0,0,1,1,1,1,1},
  779. {0,0,0,1,1,1,1,1}};
  780. for(int y=0;y<8;y++){
  781. for(int x=0;x<8;x++){
  782. //topbarcan[topbarmapeditid].Color = c64color[mapedit[y][x]]
  783. //If mapedit[y][x] = 0 Then topbarcan[topbarmapeditid].Alpha=0 Else topbarcan[topbarmapeditid].Alpha=1
  784. BeginTextureMode(topbarim[topbarmapeditid]);
  785. if(mapedit[7-y][x]>0)DrawRectangle(x*4,y*4,4,4,c64color[mapedit[7-y][x]]);
  786. EndTextureMode();
  787. }}
  788. //topbarcan[topbarmapeditid].Flush()
  789. int spriteedit[8][8] = {
  790. {1,0,0,0,0,0,0,1},
  791. {0,1,0,0,0,0,1,0},
  792. {0,1,0,1,1,0,1,0},
  793. {0,0,1,1,1,1,0,0},
  794. {0,1,1,0,0,1,1,0},
  795. {0,1,1,1,1,1,1,0},
  796. {0,0,1,1,1,1,0,0},
  797. {0,1,0,1,1,0,1,0}};
  798. for(int y=0;y<8;y++){
  799. for(int x=0;x<8;x++){
  800. //topbarcan[topbarspriteeditid].Color = c64color[spriteedit[y][x]]
  801. //If spriteedit[y][x] = 0 Then topbarcan[topbarspriteeditid].Alpha=0 Else topbarcan[topbarspriteeditid].Alpha=1
  802. BeginTextureMode(topbarim[topbarspriteeditid]);
  803. if(spriteedit[7-y][x]>0)DrawRectangle(x*4,y*4,4,4,c64color[spriteedit[7-y][x]]);
  804. EndTextureMode();
  805. }}
  806. //topbarcan[topbarspriteeditid].Flush()
  807. }
  808. void topbarview(){
  809. //canvas.Color = topbarcolor
  810. DrawRectangle(topbarx,topbary,topbarwidth,topbarheight,topbarcolor);
  811. //canvas.Color = topbarcolor/2
  812. DrawRectangle(topbarx,topbary+topbarheight/2,topbarwidth,topbarheight/2,(Color){50,5,2,255});
  813. //'
  814. //' Draw the icons ..
  815. int num = 0;
  816. for(int x=640-200;x<640;x+=32){
  817. if(num>=numtopbaricons) continue;
  818. int pointx=x+topbarx;
  819. int pointy=topbary+3;
  820. if(topbarcurrentid == num){
  821. //canvas.Color=Color.White
  822. DrawTextureEx(topbarim[num].texture,(Vector2){pointx,pointy},0,0.6f,WHITE);
  823. }else{
  824. DrawTextureEx(topbarim[num].texture,(Vector2){pointx,pointy},0,0.6f,DARKGRAY);
  825. //canvas.Color=Color.DarkGrey
  826. }
  827. //canvas.DrawImage(topbarim[num],pointx,pointy,0,.6,.6)
  828. //'
  829. //' Selection of the sprite editor or the map editor
  830. if(IsMouseButtonDown(0)){
  831. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,32,32)){
  832. topbarcurrentid = num;
  833. }
  834. }
  835. num+=1;
  836. }
  837. }
  838. void paletteview(){
  839. //canvas.Color = Color.Black
  840. DrawRectangle(palettex,palettey,palettewidth,paletteheight,BLACK);
  841. //canvas.Scissor = New Recti(palettex+2,palettey+2,palettex+2+palettewidth-4,palettey+2+paletteheight-4)
  842. //canvas.Color = Color.White
  843. int cc=0;
  844. for(int y=0;y<paletteheight;y+=palettecellheight){
  845. for(int x=0;x<palettewidth;x+=palettecellwidth){
  846. if(cc>=numpalette)break;
  847. float pointx=x+palettex;
  848. float pointy=y+palettey;
  849. //'
  850. //' Draw our color
  851. if(startsetuppalettemode == 0){
  852. //canvas.Color = c64color[cc]
  853. DrawRectangle(pointx,pointy,palettecellwidth,palettecellheight,c64color[cc]);
  854. }else{
  855. //canvas.Color = db32color[cc]
  856. DrawRectangle(pointx,pointy,palettecellwidth,palettecellheight,db32color[cc]);
  857. }
  858. //canvas.DrawRect(pointx,pointy,palettecellwidth,palettecellheight)
  859. //'
  860. //' Draw a white bar around the currently selected color
  861. if(paletteselected == cc){
  862. //canvas.OutlineMode = OutlineMode.Solid
  863. //canvas.OutlineWidth = 3
  864. //canvas.OutlineColor = Color.Black
  865. //canvas.DrawRect(pointx+2,pointy+2,palettecellwidth-4,palettecellheight-4)
  866. DrawRectangleLinesEx((Rectangle){pointx+2,pointy+2,palettecellwidth-4,palettecellheight-4}, 3, BLACK);
  867. //canvas.OutlineMode = OutlineMode.Solid
  868. //canvas.OutlineWidth = 1
  869. //canvas.OutlineColor = Color.Yellow
  870. //canvas.DrawRect(pointx+2,pointy+2,palettecellwidth-4,palettecellheight-4)
  871. DrawRectangleLinesEx((Rectangle){pointx+2,pointy+2,palettecellwidth-4,palettecellheight-4}, 1, YELLOW);
  872. //canvas.OutlineMode = OutlineMode.None
  873. }
  874. //'
  875. //' Select our color
  876. if(IsMouseButtonDown(0)){
  877. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,palettecellwidth,palettecellheight)){
  878. paletteselected = cc;
  879. }
  880. }
  881. //'
  882. cc+=1;
  883. }}
  884. //canvas.Scissor = New Recti(0,0,640,480)
  885. //'canvas.Color = c64color[2]
  886. }
  887. void spritegrid(){
  888. //' If grid noview then exit this method
  889. if(toolgridtoggle == false)return;
  890. //' draw our grid
  891. //canvas.Color = Color.Grey
  892. for(int y=0;y<spriteheight;y++){
  893. for(int x=0;x<spritewidth;x++){
  894. int pointx=(x*gridwidth)+canvasx;
  895. int pointy=(y*gridheight)+canvasy;
  896. DrawLine(pointx,pointy,pointx+gridwidth,pointy,GRAY);
  897. DrawLine(pointx,pointy,pointx,pointy+gridheight,GRAY);
  898. }}
  899. }
  900. void setuptoolview(){
  901. //'read icons
  902. int pencil[8][8] = {
  903. {12,12,12,12,12,12,12,12},
  904. {12,1,1,1,1,12,12,12},
  905. {12,1,1,1,12,1,12,12},
  906. {12,1,1,12,1,1,1,12},
  907. {12,1,12,1,1,1,1,1},
  908. {12,12,1,1,1,1,1,1},
  909. {12,12,12,1,1,1,1,1},
  910. {12,12,12,12,1,1,1,1}};
  911. for(int y=0;y<8;y++){
  912. for(int x=0;x<8;x++){
  913. //toolcan[toolpencilid].Color = c64color[pencil[y][x]]
  914. BeginTextureMode(toolim[toolpencilid]);
  915. DrawRectangle(x*4,y*4,4,4,c64color[pencil[7-y][x]]);
  916. EndTextureMode();
  917. }
  918. }
  919. //toolcan[toolpencilid].Flush()
  920. int eraser[8][8] = {
  921. {12,12,12,12,12,12,12,12},
  922. {12,12,12,1,12,12,12,12},
  923. {12,12,1,1,1,12,12,12},
  924. {12,1,1,12,1,1,12,12},
  925. {12,12,1,1,12,1,1,12},
  926. {12,12,12,1,1,1,12,12},
  927. {12,12,12,12,1,12,12,12},
  928. {12,12,12,12,12,12,12,12}};
  929. for(int y=0;y<8;y++){
  930. for(int x=0;x<8;x++){
  931. //toolcan[tooleraserid].Color = c64color[eraser[y][x]]
  932. BeginTextureMode(toolim[tooleraserid]);
  933. DrawRectangle(x*4,y*4,4,4,c64color[eraser[7-y][x]]);
  934. EndTextureMode();
  935. }
  936. }
  937. //toolcan[tooleraserid].Flush()
  938. int fill[8][8] = {
  939. {12,12,12,1,12,12,12,12},
  940. {12,12,12,12,1,12,12,12},
  941. {12,12,12,12,12,1,12,12},
  942. {1,1,1,1,1,1,1,12},
  943. {12,1,1,1,1,1,1,1},
  944. {1,12,1,1,1,1,1,12},
  945. {12,12,12,1,1,1,12,12},
  946. {1,12,12,12,1,12,12,12}};
  947. for(int y=0;y<8;y++){
  948. for(int x=0;x<8;x++){
  949. //toolcan[toolfillid].Color = c64color[fill[y][x]]
  950. BeginTextureMode(toolim[toolfillid]);
  951. DrawRectangle(x*4,y*4,4,4,c64color[fill[7-y][x]]);
  952. EndTextureMode();
  953. }
  954. }
  955. //toolcan[toolfillid].Flush()
  956. int line[8][8] = {
  957. {12,12,12,12,12,12,12,12},
  958. {12,1,12,12,12,12,12,12},
  959. {12,12,1,12,12,12,12,12},
  960. {12,12,12,1,12,12,12,12},
  961. {12,12,12,12,1,12,12,12},
  962. {12,12,12,12,12,1,12,12},
  963. {12,12,12,12,12,12,1,12},
  964. {12,12,12,12,12,12,12,12}};
  965. for(int y=0;y<8;y++){
  966. for(int x=0;x<8;x++){
  967. //toolcan[toollineid].Color = c64color[line[y][x]]
  968. BeginTextureMode(toolim[toollineid]);
  969. DrawRectangle(x*4,y*4,4,4,c64color[line[7-y][x]]);
  970. EndTextureMode();
  971. }
  972. }
  973. //toolcan[toollineid].Flush()
  974. int selection[8][8] = {
  975. {12,12,12,12,12,12,12,12},
  976. {12,1,12,1,1,12,1,12},
  977. {12,12,12,12,12,12,12,12},
  978. {12,1,12,12,12,12,1,12},
  979. {12,1,12,12,12,12,1,12},
  980. {12,12,12,12,12,12,12,12},
  981. {12,1,12,1,1,12,1,12},
  982. {12,12,12,12,12,12,12,12}};
  983. for(int y=0;y<8;y++){
  984. for(int x=0;x<8;x++){
  985. //toolcan[toolselectionid].Color = c64color[selection[y][x]]
  986. BeginTextureMode(toolim[toolselectionid]);
  987. DrawRectangle(x*4,y*4,4,4,c64color[selection[7-y][x]]);
  988. EndTextureMode();
  989. }
  990. }
  991. //toolcan[toolselectionid].Flush()
  992. int copy[8][8] = {
  993. {1,12,12,12,12,12,12,12},
  994. {1,1,12,1,1,12,1,12},
  995. {1,1,1,12,12,12,12,12},
  996. {1,1,1,1,12,12,1,12},
  997. {1,1,1,12,12,12,1,12},
  998. {1,1,12,12,12,12,12,12},
  999. {1,12,12,1,1,12,1,12},
  1000. {12,12,12,12,12,12,12,12}};
  1001. for(int y=0;y<8;y++){
  1002. for(int x=0;x<8;x++){
  1003. //toolcan[toolcopyid].Color = c64color[copy[y][x]]
  1004. BeginTextureMode(toolim[toolcopyid]);
  1005. DrawRectangle(x*4,y*4,4,4,c64color[copy[7-y][x]]);
  1006. EndTextureMode();
  1007. }
  1008. }
  1009. //toolcan[toolcopyid].Flush()
  1010. int paste[8][8] = {
  1011. {12,12,12,1,12,12,12,12},
  1012. {12,12,1,1,1,12,1,12},
  1013. {12,1,1,1,12,12,12,12},
  1014. {1,1,1,1,12,12,1,12},
  1015. {12,1,1,1,12,12,1,12},
  1016. {12,12,1,1,12,12,12,12},
  1017. {12,12,12,1,1,12,1,12},
  1018. {12,12,12,12,12,12,12,12}};
  1019. for(int y=0;y<8;y++){
  1020. for(int x=0;x<8;x++){
  1021. //toolcan[toolpasteid].Color = c64color[paste[y][x]]
  1022. BeginTextureMode(toolim[toolpasteid]);
  1023. DrawRectangle(x*4,y*4,4,4,c64color[paste[7-y][x]]);
  1024. EndTextureMode();
  1025. }
  1026. }
  1027. //toolcan[toolpasteid].Flush()
  1028. int cut[8][8] = {
  1029. {12,12,12,12,12,12,12,12},
  1030. {12,12,12,1,12,12,12,12},
  1031. {12,12,12,12,1,12,12,12},
  1032. {12,1,12,12,1,12,12,12},
  1033. {12,12,1,1,12,1,1,12},
  1034. {12,12,12,12,1,12,1,1},
  1035. {12,12,12,12,1,1,12,12},
  1036. {12,12,12,12,12,1,1,12}};
  1037. for(int y=0;y<8;y++){
  1038. for(int x=0;x<8;x++){
  1039. //toolcan[toolcutid].Color = c64color[cut[y][x]]
  1040. BeginTextureMode(toolim[toolcutid]);
  1041. DrawRectangle(x*4,y*4,4,4,c64color[cut[7-y][x]]);
  1042. EndTextureMode();
  1043. }
  1044. }
  1045. //toolcan[toolcutid].Flush()
  1046. int flipvertical[8][8] = {
  1047. {12,12,12,1,1,12,12,12},
  1048. {12,12,1,1,1,1,12,12},
  1049. {12,1,1,1,1,1,1,12},
  1050. {12,12,12,1,1,12,12,12},
  1051. {12,12,12,1,1,12,12,12},
  1052. {12,1,1,1,1,1,1,12},
  1053. {12,12,1,1,1,1,12,12},
  1054. {12,12,12,1,1,12,12,12}};
  1055. for(int y=0;y<8;y++){
  1056. for(int x=0;x<8;x++){
  1057. //toolcan[toolflipverticalid].Color = c64color[flipvertical[y][x]]
  1058. BeginTextureMode(toolim[toolflipverticalid]);
  1059. DrawRectangle(x*4,y*4,4,4,c64color[flipvertical[7-y][x]]);
  1060. EndTextureMode();
  1061. }
  1062. }
  1063. //toolcan[toolflipverticalid].Flush()
  1064. int fliphorizontal[8][8] = {
  1065. {12,12,12,12,12,12,12,12},
  1066. {12,12,1,12,12,1,12,12},
  1067. {12,1,1,12,12,1,1,12},
  1068. {1,1,1,1,1,1,1,1},
  1069. {1,1,1,1,1,1,1,1},
  1070. {12,1,1,12,12,1,1,12},
  1071. {12,12,1,12,12,1,12,12},
  1072. {12,12,12,12,12,12,12,12}};
  1073. for(int y=0;y<8;y++){
  1074. for(int x=0;x<8;x++){
  1075. //toolcan[toolfliphorizontalid].Color = c64color[fliphorizontal[y][x]]
  1076. BeginTextureMode(toolim[toolfliphorizontalid]);
  1077. DrawRectangle(x*4,y*4,4,4,c64color[fliphorizontal[7-y][x]]);
  1078. EndTextureMode();
  1079. }
  1080. }
  1081. //toolcan[toolfliphorizontalid].Flush()
  1082. int colorpicker[8][8] = {
  1083. {12,1,1,12,12,12,12,12},
  1084. {1,1,12,12,1,12,12,12},
  1085. {1,12,12,1,12,12,12,12},
  1086. {12,12,1,12,1,12,12,12},
  1087. {12,1,12,1,12,1,12,12},
  1088. {12,12,12,12,1,12,1,12},
  1089. {12,12,12,12,12,1,1,12},
  1090. {12,12,12,12,12,12,12,1}};
  1091. for(int y=0;y<8;y++){
  1092. for(int x=0;x<8;x++){
  1093. //toolcan[toolcolorpickerid].Color = c64color[colorpicker[y][x]]
  1094. BeginTextureMode(toolim[toolcolorpickerid]);
  1095. DrawRectangle(x*4,y*4,4,4,c64color[colorpicker[7-y][x]]);
  1096. EndTextureMode();
  1097. }
  1098. }
  1099. //toolcan[toolcolorpickerid].Flush()
  1100. int grid[8][8] = {
  1101. {12,12,12,12,12,12,12,12},
  1102. {12,12,1,12,12,1,12,12},
  1103. {12,1,1,1,1,1,1,12},
  1104. {12,12,1,12,12,1,12,12},
  1105. {12,12,1,12,12,1,12,12},
  1106. {12,1,1,1,1,1,1,12},
  1107. {12,12,1,12,12,1,12,12},
  1108. {12,12,12,12,12,12,12,12}};
  1109. for(int y=0;y<8;y++){
  1110. for(int x=0;x<8;x++){
  1111. //toolcan[toolgridid].Color = c64color[grid[y][x]]
  1112. BeginTextureMode(toolim[toolgridid]);
  1113. DrawRectangle(x*4,y*4,4,4,c64color[grid[7-y][x]]);
  1114. EndTextureMode();
  1115. }
  1116. }
  1117. //toolcan[toolgridid].Flush()
  1118. int filledrect[8][8] = {
  1119. {12,12,12,12,12,12,12,12},
  1120. {12,1,1,1,1,1,1,12},
  1121. {12,1,1,1,1,1,1,12},
  1122. {12,1,1,1,1,1,1,12},
  1123. {12,1,1,1,1,1,1,12},
  1124. {12,1,1,1,1,1,1,12},
  1125. {12,1,1,1,1,1,1,12},
  1126. {12,12,12,12,12,12,12,12}};
  1127. for(int y=0;y<8;y++){
  1128. for(int x=0;x<8;x++){
  1129. //toolcan[toolfilledrectid].Color = c64color[filledrect[y][x]]
  1130. BeginTextureMode(toolim[toolfilledrectid]);
  1131. DrawRectangle(x*4,y*4,4,4,c64color[filledrect[7-y][x]]);
  1132. EndTextureMode();
  1133. }
  1134. }
  1135. //toolcan[toolfilledrectid].Flush()
  1136. int outlinerect[8][8] = {
  1137. {12,12,12,12,12,12,12,12},
  1138. {12,1,1,1,1,1,1,12},
  1139. {12,1,12,12,12,12,1,12},
  1140. {12,1,12,12,12,12,1,12},
  1141. {12,1,12,12,12,12,1,12},
  1142. {12,1,12,12,12,12,1,12},
  1143. {12,1,1,1,1,1,1,12},
  1144. {12,12,12,12,12,12,12,12}};
  1145. for(int y=0;y<8;y++){
  1146. for(int x=0;x<8;x++){
  1147. //toolcan[tooloutlinerectid].Color = c64color[outlinerect[y][x]]
  1148. BeginTextureMode(toolim[tooloutlinerectid]);
  1149. DrawRectangle(x*4,y*4,4,4,c64color[outlinerect[7-y][x]]);
  1150. EndTextureMode();
  1151. }
  1152. }
  1153. //toolcan[tooloutlinerectid].Flush()
  1154. int filledcircle[8][8] = {
  1155. {12,12,12,1,1,12,12,12},
  1156. {12,12,1,1,1,1,12,12},
  1157. {12,1,1,1,1,1,1,12},
  1158. {1,1,1,1,1,1,1,1},
  1159. {1,1,1,1,1,1,1,1},
  1160. {12,1,1,1,1,1,1,12},
  1161. {12,12,1,1,1,1,12,12},
  1162. {12,12,12,1,1,12,12,12}};
  1163. for(int y=0;y<8;y++){
  1164. for(int x=0;x<8;x++){
  1165. int p=filledcircle[7-y][x];
  1166. //toolcan[toolfilledcircleid].Color = c64color[p]
  1167. BeginTextureMode(toolim[toolfilledcircleid]);
  1168. DrawRectangle(x*4,y*4,4,4,c64color[p]);
  1169. EndTextureMode();
  1170. }
  1171. }
  1172. //toolcan[toolfilledcircleid].Flush()
  1173. int outlinecircle[8][8] = {
  1174. {12,12,12,1,1,12,12,12},
  1175. {12,12,1,12,12,1,12,12},
  1176. {12,1,12,12,12,12,1,12},
  1177. {1,12,12,12,12,12,12,1},
  1178. {1,12,12,12,12,12,12,1},
  1179. {12,1,12,12,12,12,1,12},
  1180. {12,12,1,12,12,1,12,12},
  1181. {12,12,12,1,1,12,12,12}};
  1182. for(int y=0;y<8;y++){
  1183. for(int x=0;x<8;x++){
  1184. int p=outlinecircle[7-y][x];
  1185. //toolcan[tooloutlinecircleid].Color = c64color[p]
  1186. BeginTextureMode(toolim[tooloutlinecircleid]);
  1187. DrawRectangle(x*4,y*4,4,4,c64color[p]);
  1188. EndTextureMode();
  1189. }
  1190. }
  1191. //toolcan[tooloutlinecircleid].Flush()
  1192. }
  1193. void toolview(){
  1194. //canvas.Color=Color.Black
  1195. DrawRectangle(toolx,tooly,toolwidth,toolheight,BLACK);
  1196. //canvas.Color=Color.White
  1197. if(delay>0)delay-=1;
  1198. int num=0;
  1199. for(int y=tooly;y<tooly+toolheight;y+=32){
  1200. for(int x=toolx;x<toolx+toolwidth;x+=32){
  1201. if(num>=numtools)continue;
  1202. int pointx=x;
  1203. int pointy=y;
  1204. if(toolselected == num){
  1205. //canvas.Color = Color.Yellow
  1206. DrawRectangle(pointx,pointy,32,32,YELLOW);
  1207. //canvas.Color = Color.White
  1208. //canvas.Scissor = New Recti(pointx+2,pointy+2,pointx+30,pointy+30)
  1209. DrawTexture(toolim[num].texture,pointx,pointy,WHITE);
  1210. //canvas.Scissor = New Recti(0,0,640,480)
  1211. }else{
  1212. DrawTexture(toolim[num].texture,pointx,pointy,WHITE);
  1213. }
  1214. //'
  1215. //'/ Interaction with the tool area
  1216. //'
  1217. if(IsMouseButtonDown(0)){
  1218. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,32,32)){
  1219. toolselected = num;
  1220. //' Pastethe selected area
  1221. if(toolselected == toolpasteid){
  1222. if(selectionstartx == selectionendx && selectionstarty == selectionendy){
  1223. }else{
  1224. for(int y1=selectionbufferstarty; y1<selectionbufferendy;y1++){
  1225. for(int x1=selectionbufferstartx; x1<selectionbufferendx;x1++){
  1226. int destx=selectionstartx+x1-selectionbufferstartx;
  1227. int desty=selectionstarty+y1-selectionbufferstarty;
  1228. if(x1<0 || y1<0 || x1>=32 || y1>=32) continue;
  1229. if(destx<0 || desty<0 || destx>=32 || desty>=32)continue;
  1230. if(destx>selectionendx || desty>selectionendy)continue;
  1231. map[destx][desty] = selectionbuffer[x1][y1];
  1232. }
  1233. }
  1234. toolselected = toolpencilid;
  1235. }
  1236. }
  1237. //' Copy the selected area
  1238. if(toolselected == toolcopyid){
  1239. if(selectionstartx == selectionendx && selectionstarty == selectionendy){
  1240. }else{
  1241. selectionbufferstartx = selectionstartx;
  1242. selectionbufferstarty = selectionstarty;
  1243. selectionbufferendx = selectionendx;
  1244. selectionbufferendy = selectionendy;
  1245. for(int y1=selectionstarty;y1<selectionendy;y1++){
  1246. for(int x1=selectionstartx;x1<selectionendx;x1++){
  1247. selectionbuffer[x1][y1] = map[x1][y1];
  1248. }
  1249. }
  1250. toolselected = toolpencilid;
  1251. }
  1252. }
  1253. // Cut the selected area
  1254. if(toolselected == toolcutid){
  1255. if(selectionstartx == selectionendx && selectionstarty == selectionendy){
  1256. }else{
  1257. for(int y1=selectionstarty;y1<selectionendy;y1++){
  1258. for(int x1=selectionstartx;x1<selectionendx;x1++){
  1259. map[x1][y1] = paletteeraser;
  1260. }
  1261. }
  1262. toolselected = toolpencilid;
  1263. }
  1264. }
  1265. //' Mirror vertically
  1266. if(toolselected == toolflipverticalid && delay <= 0)
  1267. {
  1268. //int tempmap[32][32] = {0};
  1269. for(int y1=0;y1<spriteheight;y1++){
  1270. for(int x1=0;x1<spritewidth;x1++){
  1271. tempmap[x1][y1] = map[x1][y1];
  1272. }
  1273. }
  1274. for(int y1=0;y1<spriteheight;y1++){
  1275. for(int x1=0;x1<spritewidth;x1++){
  1276. map[x1][y1] = tempmap[x1][spriteheight-1-y1];
  1277. }
  1278. }
  1279. delay = delaydefault;
  1280. toolselected = toolpencilid;
  1281. }
  1282. //Mirror Horizontal
  1283. if(toolselected == toolfliphorizontalid && delay <= 0){
  1284. //int tempmap[spritewidth][spriteheight];
  1285. for(int y1=0;y1<spriteheight;y1++){
  1286. for(int x1=0;x1<spritewidth;x1++){
  1287. tempmap[x1][y1] = map[x1][y1];
  1288. }
  1289. }
  1290. for(int y1=0;y1<spriteheight;y1++){
  1291. for(int x1=0;x1<spritewidth;x1++){
  1292. map[x1][y1] = tempmap[spritewidth-1-x1][y1];
  1293. }
  1294. }
  1295. delay = delaydefault;
  1296. toolselected = toolpencilid;
  1297. }
  1298. //' Grid toggle
  1299. if(toolselected == toolgridid && delay <= 0){
  1300. if(toolgridtoggle == true){
  1301. toolgridtoggle = false;
  1302. }else{
  1303. toolgridtoggle = true;
  1304. }
  1305. delay = delaydefault;
  1306. toolselected = toolpencilid;
  1307. }
  1308. }
  1309. }
  1310. num+=1;
  1311. }
  1312. }
  1313. }
  1314. void spritelibview(){
  1315. //canvas.Color = Color.Black
  1316. DrawRectangle(spritelibx,spriteliby,spritelibwidth,spritelibheight,BLACK);
  1317. //canvas.Color = Color.White
  1318. int num=(middlebarcurrentid*80);
  1319. for(int y=spriteliby;y<spriteliby+spritelibheight;y+=spriteheight*spritelibscale){
  1320. for(int x=spritelibx;x<spritelibx+spritelibwidth;x+=spritewidth*spritelibscale){
  1321. int pointx=x;
  1322. int pointy=y;
  1323. if(num == spritelibselected){
  1324. //canvas.Color = Color.White
  1325. //DrawRectangle(pointx,pointy,spritewidth*spritelibscale,spriteheight*spritelibscale,WHITE);
  1326. //canvas.Scissor = New Recti(pointx+2,pointy+2,pointx+spritewidth*spritelibscale-3,pointy+spriteheight*spritelibscale-3)
  1327. //'canvas.Scissor(z1)
  1328. //DrawTextureRec(spritelibim[num].texture,(Rectangle){0,0,spritewidth,spriteheight},pointx,pointy,WHITE);
  1329. //DrawTextureEx(spritelibim[num].texture,(Vector2){pointx,pointy},0,spritelibscale,WHITE);
  1330. //DrawTexture(spritelibim[num].texture,pointx,pointy,WHITE);
  1331. // NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
  1332. DrawTextureRec(spritelibim[num].texture, (Rectangle){ 0, 0, spritelibim[num].texture.width, -spritelibim[num].texture.height }, (Vector2){pointx,pointy}, WHITE);
  1333. DrawRectangle(pointx,pointy,spritewidth*spritelibscale,spriteheight*spritelibscale,(Color){100,100,100,100});
  1334. //'Local z2:=New Recti(0,0,640,480)
  1335. //canvas.Scissor = New Recti(0,0,640,480)
  1336. }else{
  1337. //canvas.Color = Color.White
  1338. //canvas.DrawImage(spritelibim[num],pointx,pointy)
  1339. //DrawTexture(spritelibim[num].texture,pointx,pointy,WHITE);
  1340. //DrawTextureEx(spritelibim[num].texture,(Vector2){pointx,pointy},0,spritelibscale,WHITE);
  1341. //DrawTexture(spritelibim[num].texture,pointx,pointy,WHITE);
  1342. //DrawTextureRec(spritelibim[num].texture, (Rectangle){ 0, 0, spritewidth, -spriteheight }, (Vector2){ 0, 0 }, WHITE);
  1343. DrawTextureRec(spritelibim[num].texture, (Rectangle){ 0, 0, spritelibim[num].texture.width, -spritelibim[num].texture.height }, (Vector2){pointx,pointy}, WHITE);
  1344. }
  1345. if(IsMouseButtonDown(0)){
  1346. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,spritewidth*spritelibscale,spriteheight*spritelibscale)){
  1347. spritelibselected = num;
  1348. spritelibcopytocanvas();
  1349. }
  1350. }
  1351. num+=1;
  1352. if(num>=numspritelib)break;
  1353. }
  1354. if(num>=numspritelib)break;
  1355. }
  1356. }
  1357. void spriteview(){
  1358. //canvas.Color = Color.Grey
  1359. for(int y=0;y<spriteheight;y++){
  1360. for(int x=0;x<spritewidth;x++){
  1361. int pointx=(x*gridwidth)+canvasx;
  1362. int pointy=(y*gridheight)+canvasy;
  1363. //'canvas.DrawRect()
  1364. if(startsetuppalettemode == 0){
  1365. //canvas.Color = c64color[map[x,y]]
  1366. DrawRectangle(pointx,pointy,gridwidth,gridheight,c64color[map[x][y]]);
  1367. }else{
  1368. //canvas.Color = db32color[map[x,y]]
  1369. DrawRectangle(pointx,pointy,gridwidth,gridheight,db32color[map[x][y]]);
  1370. }
  1371. //canvas.DrawRect(pointx,pointy,gridwidth,gridheight)
  1372. //'
  1373. //' Mouse down (LEFT)
  1374. if(IsMouseButtonDown(0)){
  1375. if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,gridwidth,gridheight)){
  1376. if(toolselected == toolpencilid){
  1377. map[x][y] = paletteselected;
  1378. }
  1379. if(toolselected == tooleraserid){
  1380. map[x][y] = paletteeraser;
  1381. }
  1382. if(toolselected == toolfillid){
  1383. fillatposition(x,y);
  1384. }
  1385. }
  1386. }
  1387. /*
  1388. ' Line tool
  1389. If Mouse.ButtonDown(MouseButton.Left)
  1390. If rectsoverlap(Mouse.X,Mouse.Y,1,1,pointx,pointy,gridwidth,gridheight)
  1391. If toolselected = toollineid
  1392. If linepressed = False And lineactive = False
  1393. lineactive = True
  1394. linepressed = True
  1395. linestartx = x
  1396. linestarty = y
  1397. End If
  1398. If lineactive = True
  1399. lineendx = x
  1400. lineendy = y
  1401. End If
  1402. End If
  1403. End If
  1404. End If
  1405. If Mouse.ButtonDown(MouseButton.Left) = False
  1406. If toolselected = toollineid
  1407. If lineactive = True
  1408. previewline(canvas,True)
  1409. lineactive = False
  1410. linepressed = False
  1411. End If
  1412. End If
  1413. End if
  1414. ' Selection Tool
  1415. If Mouse.ButtonDown(MouseButton.Left)
  1416. If rectsoverlap(Mouse.X,Mouse.Y,1,1,pointx,pointy,gridwidth,gridheight)
  1417. If toolselected = toolselectionid
  1418. If selectionpressed = False And selectionactive = False
  1419. selectionactive = True
  1420. selectionpressed = True
  1421. selectionstartx = x
  1422. selectionstarty = y
  1423. selectionnegativeswitchx = True
  1424. selectionnegativeswitchy = True
  1425. End If
  1426. If selectionactive = True
  1427. selectionendx = x
  1428. selectionendy = y
  1429. If selectionendx < selectionstartx Then
  1430. selectionendx-=1
  1431. If selectionnegativeswitchx Then
  1432. selectionnegativeswitchx = False
  1433. selectionstartx+=1
  1434. End If
  1435. End If
  1436. If selectionendy < selectionstarty Then
  1437. selectionendy-=1
  1438. If selectionnegativeswitchy Then
  1439. selectionnegativeswitchy = False
  1440. selectionstarty+=1
  1441. End If
  1442. End If
  1443. End If
  1444. End If
  1445. End If
  1446. End If
  1447. If Mouse.ButtonDown(MouseButton.Left) = False
  1448. If toolselected = toolselectionid
  1449. If selectionactive = True
  1450. 'previewselection(canvas,True)
  1451. selectionactive = False
  1452. selectionpressed = False
  1453. ' if the end is smaller then then start then switch them
  1454. If selectionendx<selectionstartx Then
  1455. Local a:Int=selectionstartx
  1456. Local b:Int=selectionendx
  1457. selectionstartx = b+1
  1458. selectionendx = a -1
  1459. End If
  1460. If selectionendy<selectionstarty Then
  1461. Local a:Int=selectionstarty
  1462. Local b:Int=selectionendy
  1463. selectionstarty = b +1
  1464. selectionendy = a -1
  1465. End If
  1466. '
  1467. End If
  1468. End If
  1469. End if
  1470. ' Remove the selection with rmb
  1471. If Mouse.ButtonDown(MouseButton.Right) = True
  1472. selectionstartx=0
  1473. selectionstarty=0
  1474. selectionendx=0
  1475. selectionendy=0
  1476. End If
  1477. '
  1478. ' Mouse down (MIDDLE) Color Picker
  1479. If Mouse.ButtonDown(MouseButton.Middle)
  1480. If rectsoverlap(Mouse.X,Mouse.Y,1,1,pointx,pointy,gridwidth,gridheight)
  1481. paletteselected = map[x,y]
  1482. End If
  1483. End if
  1484. If Mouse.ButtonDown(MouseButton.Left)
  1485. If rectsoverlap(Mouse.X,Mouse.Y,1,1,pointx,pointy,gridwidth,gridheight)
  1486. If toolselected = toolcolorpickerid
  1487. paletteselected = map[x,y]
  1488. End If
  1489. End If
  1490. End if
  1491. '
  1492. ' Mouse Down(LEFT) Filled rect / outlined rect / filled circle / outlined circle
  1493. If Mouse.ButtonDown(MouseButton.Left)
  1494. If rectsoverlap(Mouse.X,Mouse.Y,1,1,pointx,pointy,gridwidth,gridheight)
  1495. If toolselected = toolfilledrectid Or toolselected = tooloutlinerectid Or toolselected = toolfilledcircleid Or toolselected = tooloutlinecircleid
  1496. If bcselectionpressed = False And bcselectionactive = False
  1497. bcselectionactive = True
  1498. bcselectionpressed = True
  1499. bcselectionstartx = x
  1500. bcselectionstarty = y
  1501. bcselectionnegativeswitchx = True
  1502. bcselectionnegativeswitchy = True
  1503. End If
  1504. If bcselectionactive = True
  1505. bcselectionendx = x
  1506. bcselectionendy = y
  1507. If bcselectionendx < bcselectionstartx Then
  1508. bcselectionendx-=1
  1509. If bcselectionnegativeswitchx Then
  1510. bcselectionnegativeswitchx = False
  1511. bcselectionstartx+=1
  1512. End If
  1513. End If
  1514. If bcselectionendy < bcselectionstarty Then
  1515. bcselectionendy-=1
  1516. If bcselectionnegativeswitchy Then
  1517. bcselectionnegativeswitchy = False
  1518. bcselectionstarty+=1
  1519. End If
  1520. End If
  1521. End If
  1522. End If
  1523. End If
  1524. End If
  1525. If Mouse.ButtonDown(MouseButton.Left) = False
  1526. If toolselected = toolfilledrectid Or toolselected = tooloutlinerectid Or toolselected = toolfilledcircleid Or toolselected = tooloutlinecircleid
  1527. If bcselectionactive = True
  1528. 'previewselection(canvas,True)
  1529. bcselectionactive = False
  1530. bcselectionpressed = False
  1531. ' if the end is smaller then then start then switch them
  1532. If bcselectionendx<bcselectionstartx Then
  1533. Local a:Int=bcselectionstartx
  1534. Local b:Int=bcselectionendx
  1535. bcselectionstartx = b+1
  1536. bcselectionendx = a -1
  1537. End If
  1538. If bcselectionendy<bcselectionstarty Then
  1539. Local a:Int=bcselectionstarty
  1540. Local b:Int=bcselectionendy
  1541. bcselectionstarty = b +1
  1542. bcselectionendy = a -1
  1543. End If
  1544. '
  1545. ' Do the filling
  1546. If toolselected = toolfilledrectid Or toolselected = tooloutlinerectid
  1547. For Local y:Int=bcselectionstarty To bcselectionendy
  1548. For Local x:Int=bcselectionstartx To bcselectionendx
  1549. If toolselected = toolfilledrectid Then map[x,y] = paletteselected
  1550. If toolselected = tooloutlinerectid
  1551. If x = bcselectionstartx Or x = bcselectionendx Or y = bcselectionendy Or y=bcselectionstarty
  1552. map[x,y] = paletteselected
  1553. End If
  1554. End If
  1555. Next
  1556. Next
  1557. Elseif toolselected = toolfilledcircleid Or toolselected = tooloutlinecircleid
  1558. ' add circle code here
  1559. Local w:Int=Abs(bcselectionstartx-bcselectionendx)+1
  1560. Local h:Int=Abs(bcselectionstarty-bcselectionendy)+1
  1561. If toolselected = tooloutlinecircleid
  1562. Local ti:Image = New Image(spritewidth,spriteheight)
  1563. Local tc:Canvas = New Canvas(ti)
  1564. tc.Clear(Color.Black)
  1565. tc.Color = Color.White
  1566. tc.OutlineMode=OutlineMode.Smooth
  1567. tc.OutlineColor = Color.Green
  1568. tc.OutlineWidth = 0
  1569. tc.DrawOval(bcselectionstartx,bcselectionstarty,w-1,h-1)
  1570. tc.Flush()
  1571. For Local y:Int=0 Until spriteheight
  1572. For Local x:Int=0 Until spritewidth
  1573. If ti.GetPixel(x,y) = Color.Green
  1574. map[x,y] = paletteselected
  1575. End If
  1576. Next
  1577. Next
  1578. Else
  1579. Local ti:Image = New Image(spritewidth,spriteheight)
  1580. Local tc:Canvas = New Canvas(ti)
  1581. tc.Clear(Color.Black)
  1582. tc.Color = Color.White
  1583. tc.DrawOval(bcselectionstartx-1,bcselectionstarty-1,w+1,h+1)
  1584. tc.Flush()
  1585. For Local y:Int=0 Until spriteheight
  1586. For Local x:Int=0 Until spritewidth
  1587. If ti.GetPixel(x,y) <> Color.Black
  1588. map[x,y] = paletteselected
  1589. End If
  1590. Next
  1591. Next
  1592. End If
  1593. End If
  1594. '
  1595. bcselectionendy=0
  1596. bcselectionendx=0
  1597. bcselectionstarty=0
  1598. bcselectionstartx=0
  1599. End If
  1600. End If
  1601. End if
  1602. ' Copy to clipboard
  1603. If Keyboard.KeyReleased(Key.C)
  1604. copytoclipboard()
  1605. End if
  1606. */
  1607. }
  1608. }
  1609. updatepreview();
  1610. updatespritelib();
  1611. }
  1612. void updatepreview(){
  1613. /*
  1614. previewcan.Clear(Color.Black)
  1615. For Local y:Int=0 Until map.GetSize(1)
  1616. For Local x:Int=0 Until map.GetSize(0)
  1617. Local pointx:Int=x*previewcellwidth
  1618. Local pointy:Int=y*previewcellheight
  1619. If startsetuppalettemode = 0
  1620. previewcan.Color = c64color[map[x,y]]
  1621. Else
  1622. previewcan.Color = db32color[map[x,y]]
  1623. End If
  1624. previewcan.DrawRect(pointx,pointy,previewcellwidth,previewcellheight)
  1625. Next
  1626. Next
  1627. previewcan.Flush()
  1628. */
  1629. }
  1630. void updatespritelib(){
  1631. for(int y=0;y<spriteheight;y++){
  1632. for(int x=0;x<spritewidth;x++){
  1633. float pointx=x*spritelibscale;
  1634. float pointy=y*spritelibscale;
  1635. BeginTextureMode(spritelibim[spritelibselected]);
  1636. if(startsetuppalettemode == 0){
  1637. DrawRectangle(pointx,pointy,spritelibscale,spritelibscale,c64color[map[x][y]]);
  1638. //spritelibcan[spritelibselected].Color = c64color[map[x,y]]
  1639. }else{
  1640. DrawRectangle(pointx,pointy,spritelibscale,spritelibscale,db32color[map[x][y]]);
  1641. //spritelibcan[spritelibselected].Color = db32color[map[x,y]]
  1642. }
  1643. //spritelibcan[spritelibselected].DrawRect(pointx,pointy,spritelibscale,spritelibscale)
  1644. spritelibmap[spritelibselected][x][y] = map[x][y];
  1645. EndTextureMode();
  1646. }
  1647. }
  1648. //spritelibcan[spritelibselected].Flush()
  1649. }
  1650. void fillatposition(int x,int y){
  1651. /*
  1652. Local ol:List<pathnode> = New List<pathnode>
  1653. ' Add the start position on the list
  1654. ol.AddLast(New pathnode(x,y))
  1655. ' set the cloes map at the start position to distance 1
  1656. Local colorundermouse:Int=map[x,y]
  1657. map[x,y] = paletteselected
  1658. ' some helper arrays. We can determine the top,right,and bottom
  1659. ' and left position cells with these numbers.
  1660. Local dx:Int[] = New Int[](0,1,0,-1)
  1661. Local dy:Int[] = New Int[](-1,0,1,0)
  1662. ' While there is contents in the list
  1663. While ol.Count() <> 0
  1664. ' Get the current location
  1665. Local x1:Int=ol.First.x
  1666. Local y1:Int=ol.First.y
  1667. ' Remove the current location from the list
  1668. ol.RemoveFirst()
  1669. ' Get 4 new positions around the current positions
  1670. For Local i:=0 Until 4
  1671. ' Set new x and y
  1672. Local nx:Int=x1+dx[i]
  1673. Local ny:Int=y1+dy[i]
  1674. ' If the coordinates are inside the map
  1675. If nx>=0 And ny>=0 And nx<spritewidth And ny<spriteheight
  1676. ' If the closedmap is not written to yet
  1677. If map[nx,ny] = colorundermouse And map[nx,ny] <> paletteselected
  1678. ' Set the new distance based on the current distance
  1679. map[nx,ny] = paletteselected
  1680. ' Add new position to the list
  1681. ol.AddLast(New pathnode(nx,ny))
  1682. End If
  1683. End If
  1684. Next
  1685. Wend
  1686. */
  1687. }
  1688. void spritelibcopytocanvas(){
  1689. for(int y=0;y<spriteheight;y++){
  1690. for(int x=0;x<spritewidth;x++){
  1691. map[x][y] = spritelibmap[spritelibselected][x][y];
  1692. }
  1693. }
  1694. }
  1695. bool rectsoverlap(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2){
  1696. if((x1 >= (x2 + w2) || (x1 + w1) <= x2))return false;
  1697. if((y1 >= (y2 + h2) || (y1 + h1) <= y2))return false;
  1698. return true;
  1699. }
  1700. bool circlerectcollide(int cx,int cy,int cr,int rx,int ry,int rw,int rh){
  1701. float closestx = Clamp(cx, rx, rx+rw);
  1702. float closesty = Clamp(cy, ry, ry+rh);
  1703. float distancex = cx - closestx;
  1704. float distancey = cy - closesty;
  1705. float distancesquared = (distancex * distancex) + (distancey * distancey);
  1706. return distancesquared < (cr * cr);
  1707. }
  1708. // Clamp float value
  1709. float Clamp(float value, float min, float max)
  1710. {
  1711. const float res = value < min ? min : value;
  1712. return res > max ? max : res;
  1713. }