123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538 |
- // WORK IN PROGRESS CONVERSION....
- // WORK IN PROGRESS CONVERSION....
- //
- // Added - Save eveything (F5) Load everything(F6 - Very slow!!)
- // Added - Press p to paste 8x8 sprite back into the editor. (key 'c' to copy current sprite as c array into clipboard.
- // Added - Press tab to switch between sprite editor and map editor
- // Conversion from the Monkey2 version that I wrote.
- //
- // Todo : Add isometric/hexagon map edit/view, Fix update preview and spritelib), Floodfill(more testing), ovals!(find solution for layout), testing.
- #include "raylib.h"
- #include <math.h>
- #include <string.h>
- #include <stdlib.h>
- #include <stdio.h>
- // This one is for getting the sprite from the clipboard
- static int tempmap[32][32] = {0};
- // start setup
- static int weasel=0;
- static int startsetuppalettemode; // '0=c64 1=db32
- static bool startsetupdone;
- static int startsetupx;
- static int startsetupy;
- static int startsetupwidth;
- static int startsetupheight;
- static RenderTexture2D startsetupim[5]; //5=numstartsetup
- //Field startsetupcan:Canvas[]
- static int startsetupselected;
- static int startsetup8x8id;
- static int startsetup16x16id = 1;
- static int startsetup32x32id = 2;
- static int startsetupc64id = 3;
- static int startsetupdb32id = 4;
- static int numstartsetup = 5;
- //'
- //'tool view
- static int toolx;
- static int tooly;
- static int toolwidth;
- static int toolheight;
- static RenderTexture2D toolim[16]; //16 = numtools
- //Field toolcan:Canvas[]
- static bool toolgridtoggle = true;
- static int toolselected = 0;
- static int toolpencilid = 0;
- static int tooleraserid = 1;
- static int toolfillid = 2;
- static int toollineid = 3;
- static int toolselectionid = 4;
- static int toolcopyid = 5;
- static int toolpasteid = 6;
- static int toolcutid = 7;
- static int toolflipverticalid = 8;
- static int toolfliphorizontalid = 9;
- static int toolcolorpickerid = 10;
- static int toolgridid = 11;
- static int toolfilledrectid = 12;
- static int tooloutlinerectid = 13;
- static int toolfilledcircleid = 14;
- static int tooloutlinecircleid = 15;
- static int numtools = 16;
- static int delay;
- static int delaydefault = 20;
- //'
- //' sprite library
- static int spritelibx;
- static int spriteliby;
- static int spritelibwidth;
- static int spritelibheight;
- static int numspritelib;
- static RenderTexture2D spritelibim[80*4]; // 80*4 = numspritelib
- //Field spritelibcan:Canvas[]
- static int spritelibmap[80*4][32][32]; // numspritelib,
- static int spritelibselected = 0;
- static float spritelibscale;
-
- //'
- //'preview
- static RenderTexture2D previewim;
- //Field previewcan:Canvas
- static int previewx;
- static int previewy;
- static int previewwidth;
- static int previewheight;
- static int previewcellwidth;
- static int previewcellheight;
- // tile map view
- static int tilemapx;
- static int tilemapy;
- static int tilemapwidth;
- static int tilemapheight;
- static int tilemaptileshorizontal;
- static int tilemaptilesvertical;
- static int tilemaptilesscreenhorizontal=100;
- static int tilemaptilesscreenvertical=100;
- static int tilemap[100][100]={0};
- //'
- //'sprite view
- static int map[32][32]; // 8 = edit canvas width
- static int canvasx;
- static int canvasy; //'canvas x and y position on the scrern
- static float canvaswidth=256;
- static float canvasheight=256; //'width and height of our canvas
- static float gridwidth;
- static float gridheight;// ' grids width and height
- static int spritewidth;
- static int spriteheight;// ' our main sprite width and height
- static bool spriteviewaction=false;
- //' line tool fields
- static bool linepressed=false;
- static bool lineactive=false;
- static int linestartx;
- static int linestarty;
- static int lineendx;
- static int lineendy;
- //' Selection fields
- static bool selectionpressed = false ;
- static bool selectionactive = false;
- static int selectionstartx;
- static int selectionstarty;
- static int selectionendx;
- static int selectionendy;
- static int selectionbuffer[32][32]; //'our copy paste buffer
- static int selectionbufferstartx;
- static int selectionbufferstarty;
- static int selectionbufferendx;
- static int selectionbufferendy;
- static bool selectionnegativeswitchx = false;// ' switch if negative selection
- static bool selectionnegativeswitchy = false;
- //' filled/outlined rectsangles and circles fields
- static bool bcselectionpressed = false;
- static bool bcselectionactive = false;
- static int bcselectionstartx;
- static int bcselectionstarty;
- static int bcselectionendx;
- static int bcselectionendy;
- static int bcselectionbuffer[32][32];// 'our copy paste buffer
- static int bcselectionbufferstartx;
- static int bcselectionbufferstarty;
- static int bcselectionbufferendx;
- static int bcselectionbufferendy;
- static bool bcselectionnegativeswitchx = false; // ' switch if negative selection
- static bool bcselectionnegativeswitchy = false;
- //'
- //' palette
- static Color c64color[16]; //' our colors
- static Color db32color[32];// ' our colors
- static int paletteselected;// ' our selected color from palette
- static int paletteundermouse; // for floodfill
- static int paletteeraser;
- static int palettex;
- static int palettey; //'screen x and y
- static float palettewidth;
- static float paletteheight;// ' our palette screen w and h
- static float palettecellwidth;
- static float palettecellheight; //'cell width and height of color
- static int numpalette;// 'number of colors (holds the amount of the selected palette.)
-
- //'
- //' Top Bar
- static int topbarx;
- static int topbary;
- static int topbarwidth;
- static int topbarheight;
- static Color topbarcolor;
- static RenderTexture2D topbarim[3];
- //Field topbarcan:Canvas[]
- static int topbarspriteeditid = 0;
- static int topbarmapeditid = 1;
- static int numtopbaricons = 2;
- static int topbarcurrentid = 0;
- //'
- //' Middle bar
- static int middlebarx;
- static int middlebary;
- static int middlebarwidth;
- static int middlebarheight;
- static Color middlebarcolor;
- static RenderTexture2D middlebarim[4]; //nummiddlebaricons
- //Field middlebarcan:Canvas[]
- static int middlebar0id = 0;
- static int middlebar1id = 1;
- static int middlebar2id = 2;
- static int middlebar3id = 3;
- static int nummiddlebaricons = 4;
- static int middlebarcurrentid = 0;
- //'
- //' Bottom Bar
- static int bottombarx;
- static int bottombary;
- static int bottombarwidth;
- static int bottombarheight;
- static Color bottombarcolor;
- static void inic64colors(void);
- static void inidb32colors(void);
- static bool rectsoverlap(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2);
- static bool circlerectcollide(int cx,int cy,int cr,int rx,int ry,int rw,int rh);
- static float Clamp(float value, float min, float max);
- static void startsetupsetup(void);
- static void startsetupview(void);
- static void bottombarview(void);
- static void middlebarview();
- static void setupmiddlebar(void);
- static void setuptopbar(void);
- static void topbarview(void);
- static void setuptoolview(void);
- static void paletteview(void);
- static void spritegrid(void);
- static void toolview(void);
- static void spritelibview(void);
- static void spriteview(void);
- static void updatespritelib(void);
- static void updatepreview(void);
- static void previewview(void);
- static void spritelibcopytocanvas(void);
- static void previewline(bool drawit);
- static void previewselection(bool drawit);
- static void tilemapview(void);
- static void fillatposition(int x, int y,int oldcolor,int newcolor);
- static void midptellipse(int rx, int ry, int xc, int yc);
- static void loadspritelib();
- static void savespritelib();
-
- // for the copy from clipboard
- static int countcommas(char *in);
- static int countnumbers(char *in);
- static void copyfromclipboard(void);
- static void copytoclipboard(void);
- static bool importspriteis8x8(int in);
- static bool importspriteis16x16(int in);
- static bool importspriteis32x32(int in);
- static void readtempsprite(int w,int h,char *in);
-
- int main(void)
- {
- // Initialization
- //--------------------------------------------------------------------------------------
- const int screenWidth = 640;
- const int screenHeight = 480;
- InitWindow(screenWidth, screenHeight, "raylib example.");
- //ToggleFullscreen();
- //'start setup setup
- //' be sure to start the editor with the selection
- startsetupdone=false;
- startsetupx = 320-80;
- startsetupy = 150;
- startsetupwidth = 150;
- startsetupheight = 200-35;
- //startsetupim = New Image[numstartsetup];
- //startsetupcan = New Canvas[numstartsetup]
- for(int i=0;i<numstartsetup;i++){
- startsetupim[i] = LoadRenderTexture(32, 32);
- BeginTextureMode(startsetupim[i]);
- ClearBackground(BLANK); // Make the entire Sprite Transparent.
- EndTextureMode();
- //startsetupcan[i] = New Canvas(startsetupim[i])
- }
- inic64colors();
- inidb32colors();
- startsetupsetup();
-
- paletteeraser = 0;
- palettex = 640-150;
- palettey = 32;
- palettewidth = 32*4;
- paletteheight = 32*4;
- numpalette = 16;
- palettecellwidth = 32;
- palettecellheight = 32;
- //sprite canvas setup
- canvasx = 32;
- canvasy = 28;
- //spritewidth = 16;
- //spriteheight = 16;
- //map = New Int[spritewidth,spriteheight]
- //selectionbuffer = New Int[spritewidth,spriteheight]
-
- canvaswidth=256;
- canvasheight=256;
- // gridwidth = canvaswidth/spritewidth;
- // gridheight = canvasheight/spriteheight;
- //'Bottom bar (global)
- bottombarx = 0;
- bottombary = 480-24;
- bottombarwidth = 640;
- bottombarheight = 24;
- bottombarcolor = (Color){ 78, 22, 9,255 };//Color.Puce
- //'
- //' Middle bar
- middlebarx = 0;
- middlebary = canvasheight+32;
- middlebarwidth = 640;
- middlebarheight = 32;
- middlebarcolor = GRAY;
- nummiddlebaricons = 4;
- //middlebarim = New Image[nummiddlebaricons]
- //middlebarcan = New Canvas[nummiddlebaricons]
- for(int i=0;i<nummiddlebaricons;i++){
- middlebarim[i] = LoadRenderTexture(32, 32);
- BeginTextureMode(middlebarim[i]);
- ClearBackground(BLANK);
- EndTextureMode();
- //middlebarcan[i] = New Canvas(middlebarim[i])
- }
- setupmiddlebar();
- //Top bar (global)
-
- topbarx = 0;
- topbary = 0;
- topbarwidth = 640;
- topbarheight = 24;
- topbarcolor = (Color){ 78, 22, 9,255};//Color.Puce
- //topbarim = New Image[3]
- //topbarcan = New Canvas[3]
- for(int i=0;i<2;i++){
- topbarim[i] = LoadRenderTexture(32, 32);
- BeginTextureMode(topbarim[i]);
- ClearBackground(BLANK);
- EndTextureMode();
-
- }
- setuptopbar();
- //'
- //'spritelib setup
- spritelibx = 0;
- spriteliby = canvasheight+32+32;
- spritelibwidth = 640;
- spritelibheight = 128;
- numspritelib = 80*4;
- spritelibselected = 0;
- spritelibscale = 2;
- //spritelibim = New Image[numspritelib]
- //spritelibcan = New Canvas[numspritelib]
- // For Local i:Int=0 Until numspritelib
- // spritelibim[i] = New Image(spritewidth*spritelibscale,spriteheight*spritelibscale)
- // spritelibcan[i] = New Canvas(spritelibim[i])
- // spritelibcan[i].Clear(Color.Black)
- // spritelibcan[i].Flush()
- // Next
- for(int i=0;i<numspritelib;i++){
- spritelibim[i] = LoadRenderTexture(32, 32);
- BeginTextureMode(spritelibim[i]);
- ClearBackground(BLANK);
- EndTextureMode();
-
- }
-
- //' tool view
- toolx = 340;
- tooly = 186-32;
- toolwidth = 32*4;
- toolheight = 32*4;
- //'numtools = 12
- //toolim = New Image[numtools]
- //toolcan = New Canvas[numtools]
- for(int i=0;i<numtools;i++){
- toolim[i] = LoadRenderTexture(32,32);
- BeginTextureMode(toolim[i]);
- ClearBackground(BLANK);
- EndTextureMode();
- //toolcan[i] = New Canvas(toolim[i])
- //toolcan[i].Clear(Color.Black)
- //toolcan[i].Flush()
- }
- setuptoolview();
- //' previewview setup
- previewx = 640-100;
- previewy = 200;
- previewcellwidth = 2;
- previewcellheight = 2;
- previewwidth = 64;
- previewheight = 64;
- previewim = LoadRenderTexture(previewwidth,previewheight);//New Image(previewwidth,previewheight)
- BeginTextureMode(previewim);
- ClearBackground(BLANK);
- EndTextureMode();
- //previewcan = New Canvas(previewim)
- updatepreview();
- //tilemap setup
- tilemapx = 0;
- tilemapy = 32;
- tilemaptileshorizontal = 100;
- tilemaptilesvertical = 100;
- tilemapwidth = 640;
- tilemapheight= 256;
- //tilemaptilesscreenhorizontal = tilemapwidth/(spritewidth*spritelibscale);
- //tilemaptilesscreenvertical = tilemapheight/(spriteheight*spritelibscale);
- //tilemap = New Int[tilemaptileshorizontal,tilemaptilesvertical]
-
-
- SetTargetFPS(60); // Set our game to run at 60 frames-per-second
- //--------------------------------------------------------------------------------------
- int timeupd=0; // update what is being drawn into preview window and lib
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- // Update
- //----------------------------------------------------------------------------------
-
-
- //----------------------------------------------------------------------------------
- // Draw
- //----------------------------------------------------------------------------------
- BeginDrawing();
- ClearBackground(DARKGRAY);
- //' We start the sprite editor with the sprite dimension
- //' resolution selection.
- if(startsetupdone==false){
- startsetupview();
- }else{
- //' Here is the map and sprite editor section
- if(topbarcurrentid == topbarspriteeditid){
- bottombarview();
- middlebarview();
- topbarview();
- spriteview();
- previewline(false);
- spritegrid();
- previewselection(false);
- paletteview();
- previewview();
- spritelibview();
- toolview();
-
- // The editing got a little slow with the update so here
- // it now updates the preview and lib every 100 frames.
- timeupd++;
- if(timeupd>100){
- updatepreview();
- updatespritelib();
- timeupd=0;
- }
- }else if(topbarcurrentid == topbarmapeditid){
- tilemapview();
- bottombarview();
- middlebarview();
- topbarview();
- spritelibview();
- }
- }
- DrawText(FormatText("%i",weasel),0,0,20,BLACK);
- EndDrawing();
- //----------------------------------------------------------------------------------
- }
- // De-Initialization
- //--------------------------------------------------------------------------------------
- for(int i=0;i<numstartsetup;i++){
- UnloadRenderTexture(startsetupim[i]);
- }
- for(int i=0;i<numtools;i++){
- UnloadRenderTexture(toolim[i]);
- }
- for(int i=0;i<numspritelib;i++){
- UnloadRenderTexture(spritelibim[i]);
- }
- UnloadRenderTexture(previewim);
- for(int i=0;i<2;i++){
- UnloadRenderTexture(topbarim[i]);
- }
- for(int i=0;i<4;i++){
- UnloadRenderTexture(middlebarim[i]);
- }
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
- return 0;
- }
- void inic64colors(void){
- c64color[0 ] = (Color){0 , 0 , 0 , 255 };//Black
- c64color[1 ] = (Color){255,255,255, 255 };//White
- c64color[2 ] = (Color){136,0 ,0 , 255 };//Red
- c64color[3 ] = (Color){170,255,238, 255 };//Cyan
- c64color[4 ] = (Color){204,68 ,204, 255 };//Violet / Purple
- c64color[5 ] = (Color){0 ,204,85 , 255 };//Green
- c64color[6 ] = (Color){0 ,0 ,170, 255 };//Blue
- c64color[7 ] = (Color){238,238,119, 255 };//Yellow
- c64color[8 ] = (Color){221,136,85 , 255 };//Orange
- c64color[9 ] = (Color){102,68 ,0 , 255 };//Brown
- c64color[10] = (Color){255,119,119, 255 };//Light red
- c64color[11] = (Color){51 ,51 ,51 , 255 };//Dark grey / Grey 1
- c64color[12] = (Color){119,119,119, 255 };//Grey 2
- c64color[13] = (Color){170,255,102, 255 };//Light green
- c64color[14] = (Color){0 ,136,255, 255 };//Light blue
- c64color[15] = (Color){187,187,187, 255 };//Light grey / grey 3
- }
- void inidb32colors(){
- db32color[0 ] = (Color){0 ,0 ,0 ,255};
- db32color[1 ] = (Color){34 ,32 ,52 ,255};
- db32color[2 ] = (Color){69 ,40 ,60 ,255};
- db32color[3 ] = (Color){102 ,57 ,49 ,255};
- db32color[4 ] = (Color){143 ,86 ,59 ,255};
- db32color[5 ] = (Color){223 ,113 ,38 ,255};
- db32color[6 ] = (Color){217 ,160 ,102 ,255};
- db32color[7 ] = (Color){238 ,195 ,154 ,255};
- db32color[8 ] = (Color){251 ,242 ,54 ,255};
- db32color[9 ] = (Color){153 ,229 ,80 ,255};
- db32color[10] = (Color){106 ,190 ,48 ,255};
- db32color[11] = (Color){55 ,148 ,110 ,255};
- db32color[12] = (Color){75 ,105 ,47 ,255};
- db32color[13] = (Color){82 ,75 ,36 ,255};
- db32color[14] = (Color){50 ,60 ,57 ,255};
- db32color[15] = (Color){63 ,63 ,116 ,255};
- db32color[16] = (Color){48 ,96 ,130 ,255};
- db32color[17] = (Color){91 ,110 ,225 ,255};
- db32color[18] = (Color){99 ,155 ,225 ,255};
- db32color[19] = (Color){95 ,205 ,228 ,255};
- db32color[20] = (Color){203 ,219 ,252 ,255};
- db32color[21] = (Color){255 ,255 ,255 ,255};
- db32color[22] = (Color){155 ,173 ,183 ,255};
- db32color[23] = (Color){132 ,126 ,135 ,255};
- db32color[24] = (Color){105 ,106 ,106 ,255};
- db32color[25] = (Color){89 ,86 ,82 ,255};
- db32color[26] = (Color){118 ,66 ,138 ,255};
- db32color[27] = (Color){172 ,50 ,50 ,255};
- db32color[28] = (Color){217 ,87 ,99 ,255};
- db32color[29] = (Color){215 ,123 ,186 ,255};
- db32color[30] = (Color){143 ,151 ,74 ,255};
- db32color[31] = (Color){138 ,111 ,48 ,255};
- }
- void startsetupsetup(){
- // the 8x8 selection button
- int eightxeight[16][16] = {
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,1,1,1,12,12,12,12,12,1,1,1,12,12,12},
- {12,12,1,12,1,12,1,12,1,12,1,12,1,12,12,12},
- {12,12,1,1,1,12,12,1,12,12,1,1,1,12,12,12},
- {12,12,1,12,1,12,1,12,1,12,1,12,1,12,12,12},
- {12,12,1,1,1,12,12,12,12,12,1,1,1,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}};
- for(int y=0;y<16;y++){
- for(int x=0;x<16;x++){
- BeginTextureMode(startsetupim[startsetup8x8id]);
- //startsetupcan[startsetup8x8id].Color = c64color[eightxeight[y][x]]
- //If eightxeight[y][x] = 0 Then startsetupcan[startsetup8x8id].Alpha=0 Else startsetupcan[startsetup8x8id].Alpha=1
- //startsetupcan[startsetup8x8id].DrawRect(x*2,y*2,2,2)
- if(eightxeight[y][x]>0)DrawRectangle(x*2,y*2,2,2,c64color[eightxeight[y][x]]);
- EndTextureMode();
- }}
- //startsetupcan[startsetup8x8id].Flush()
-
- //the 16x16 selection button
- int sixteenxsixteen[16][16] = {
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {1,12,1,1,1,12,12,12,12,12,1,12,1,1,1,12},
- {1,12,1,12,12,12,1,12,1,12,1,12,1,12,12,12},
- {1,12,1,1,1,12,12,1,12,12,1,12,1,1,1,12},
- {1,12,1,12,1,12,1,12,1,12,1,12,1,12,1,12},
- {1,12,1,1,1,12,12,12,12,12,1,12,1,1,1,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}};
- for(int y=0;y<16;y++){
- for(int x=0;x<16;x++){
- BeginTextureMode(startsetupim[startsetup16x16id]);
- //startsetupcan[startsetup16x16id].Color = c64color[sixteenxsixteen[y][x]]
- //If sixteenxsixteen[y][x] = 0 Then startsetupcan[startsetup16x16id].Alpha=0 Else startsetupcan[startsetup16x16id].Alpha=1
- if(sixteenxsixteen[15-y][x]>0)DrawRectangle(x*2,y*2,2,2,c64color[sixteenxsixteen[15-y][x]]);
- //startsetupcan[startsetup16x16id].DrawRect(x*2,y*2,2,2)
- EndTextureMode();
- }}
- //startsetupcan[startsetup16x16id].Flush()
- // the 32x32 selection button
- int thirtytwoxthirtytwo[16][16] = {
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {1,1,12,1,1,12,12,12,12,12,1,1,12,1,1,12},
- {12,1,12,12,1,12,1,12,1,12,12,1,12,12,1,12},
- {1,1,12,1,1,12,12,1,12,12,1,1,12,1,1,12},
- {12,1,12,1,12,12,1,12,1,12,12,1,12,1,12,12},
- {1,1,12,1,1,12,12,12,12,12,1,1,12,1,1,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}};
- for(int y=0;y<16;y++){
- for(int x=0;x<16;x++){
- BeginTextureMode(startsetupim[startsetup32x32id]);
- //startsetupcan[startsetup32x32id].Color = c64color[thirtytwoxthirtytwo[y][x]]
- //If thirtytwoxthirtytwo[y][x] = 0 Then startsetupcan[startsetup32x32id].Alpha=0 Else startsetupcan[startsetup32x32id].Alpha=1
- //startsetupcan[startsetup32x32id].DrawRect(x*2,y*2,2,2)
- if(thirtytwoxthirtytwo[15-y][x]>0)DrawRectangle(x*2,y*2,2,2,c64color[thirtytwoxthirtytwo[15-y][x]]);
- EndTextureMode();
- }}
- //startsetupcan[startsetup32x32id].Flush()
- // the c64 palette selection button
- int c641616[16][16] = {
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,1,1,12,12,12,1,1,12,12,1,12,12,12,12},
- {12,1,12,12,12,12,1,12,12,12,12,1,12,12,12,12},
- {12,1,12,12,12,12,1,12,12,12,12,1,12,12,1,12},
- {12,1,12,12,12,12,1,1,1,12,12,1,1,1,1,12},
- {12,1,12,12,12,12,1,12,12,1,12,12,12,12,1,12},
- {12,1,12,12,12,12,1,12,12,1,12,12,12,12,1,12},
- {12,12,1,1,12,12,12,1,1,12,12,12,12,12,1,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}};
- for(int y=0;y<16;y++){
- for(int x=0;x<16;x++){
- BeginTextureMode(startsetupim[startsetupc64id]);
- //startsetupcan[startsetupc64id].Color = c64color[c641616[y][x]]
- //If c641616[y][x] = 0 Then startsetupcan[startsetupc64id].Alpha=0 Else startsetupcan[startsetupc64id].Alpha=1
- //startsetupcan[startsetupc64id].DrawRect(x*2,y*2,2,2)
- if(c641616[15-y][x]>0)DrawRectangle(x*2,y*2,2,2,c64color[c641616[15-y][x]]);
- EndTextureMode();
- }}
- //startsetupcan[startsetupc64id].Flush()
- // the db32 palette selection button
- int db321616[16][16] = {
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,1,12,1,12,12,12,1,1,12,12,1,1,1,12},
- {12,12,1,12,1,12,12,12,12,12,1,12,12,12,1,12},
- {12,12,1,12,1,12,12,12,12,12,1,12,12,12,1,12},
- {12,1,1,12,1,1,12,12,1,1,12,12,1,1,1,12},
- {1,12,1,12,1,12,1,12,12,12,1,12,1,12,12,12},
- {1,12,1,12,1,12,1,12,12,12,1,12,1,12,12,12},
- {1,1,1,12,1,1,1,12,1,1,12,12,1,1,1,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}};
- for(int y=0;y<16;y++){
- for(int x=0;x<16;x++){
- BeginTextureMode(startsetupim[startsetupdb32id]);
- //startsetupcan[startsetupdb32id].Color = c64color[db321616[y][x]]
- //If db321616[y][x] = 0 Then startsetupcan[startsetupdb32id].Alpha=0 Else startsetupcan[startsetupdb32id].Alpha=1
- //startsetupcan[startsetupdb32id].DrawRect(x*2,y*2,2,2)
- if(db321616[15-y][x]>0)DrawRectangle(x*2,y*2,2,2,c64color[db321616[15-y][x]]);
- EndTextureMode();
- }}
- //startsetupcan[startsetupdb32id].Flush()
- }
- void startsetupview(){
-
- //canvas.Color = Color.Black
- DrawRectangle(startsetupx-1,startsetupy-1,startsetupwidth+2,startsetupheight+2,BLACK);
- //canvas.Color = c64color[12]
- DrawRectangle(startsetupx,startsetupy,startsetupwidth,startsetupheight,c64color[12]);
- //Local selected:Bool=False
- bool selected = false;
- for(int i=0;i<3;i++){
- //canvas.Color = Color.Grey.Blend(Color.Black,.5)
- //DrawRectangle(startsetupx+8+20,startsetupy+8+i*48,32,32,GRAY);
- //canvas.Color = Color.White
- DrawTexture(startsetupim[i].texture,startsetupx+9+20,startsetupy+9+i*48,WHITE);
- //' draw the palette buttons
- //canvas.Color = Color.Black
- //DrawRectangle(startsetupx+8+50,startsetupy+8+i*48,32,32,BLACK);
- //canvas.Color = Color.White
- //DrawTexture(startsetupim[3],startsetupx+9+50,startsetupy+9+i*48,0,.9,.9)
- DrawTexture(startsetupim[3].texture,startsetupx+9+60,startsetupy+9+i*48,WHITE);
- //canvas.Color = Color.Black
- //DrawRectangle(startsetupx+8+80,startsetupy+8+i*48,32,32,BLACK);
- //canvas.Color = Color.White
- DrawTexture(startsetupim[4].texture,startsetupx+9+100,startsetupy+9+i*48,WHITE);
-
- if(IsMouseButtonDown(0)){
- if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,startsetupx+9+60,startsetupy+9+i*48,32,32)){
- startsetupselected = i;
- startsetuppalettemode = 0;
- selected = true;
- }
- if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,startsetupx+9+100,startsetupy+9+i*48,32,32)){
- startsetupselected = i;
- startsetuppalettemode = 1;
- selected = true;
- }
- }
- }
-
- if(selected == true){
- if(startsetuppalettemode == 1){// ' if the db32 palette was selected
-
- paletteeraser = 0;
- palettex = 640-150;
- palettey = 32;
- palettewidth = 32*4;
- paletteheight = 32*4;
- numpalette = 32;
- palettecellwidth = 32*4/4;
- palettecellheight = 32*4/8;
- }
-
- switch (startsetupselected){
- case 0:
- spritelibscale = 4;
- spritewidth = 8;
- spriteheight = 8;
- //map = New Int[spritewidth,spriteheight]
- //selectionbuffer = New Int[spritewidth,spriteheight];
- gridwidth = canvaswidth/spritewidth;
- gridheight = canvasheight/spriteheight;
- //weasel = tilemaptilesscreenhorizontal;
- //spritelibmap = New Int[numspritelib,spritewidth,spriteheight];
- break;
- case 1:
- spritelibscale = 2;
- spritewidth = 16;
- spriteheight = 16;
- //map = New Int[spritewidth,spriteheight];
- //selectionbuffer = New Int[spritewidth,spriteheight];
- gridwidth = canvaswidth/spritewidth;
- gridheight = canvasheight/spriteheight;
- //spritelibmap = New Int[numspritelib,spritewidth,spriteheight];
- break;
- case 2:
- spritelibscale = 1;
- spritewidth = 32;
- spriteheight = 32;
- //map = New Int[spritewidth,spriteheight];
- //selectionbuffer = New Int[spritewidth,spriteheight];
- gridwidth = canvaswidth/spritewidth;
- gridheight = canvasheight/spriteheight;
- //spritelibmap = New Int[numspritelib,spritewidth,spriteheight];
- break;
- }
- startsetupdone = true;
- }
-
- }
- void bottombarview(){
- //canvas.Color = bottombarcolor
- DrawRectangle(bottombarx,bottombary,bottombarwidth,bottombarheight,bottombarcolor);
- //canvas.Color = bottombarcolor/2
- DrawRectangle(bottombarx,bottombary+bottombarheight/2,bottombarwidth,bottombarheight/2,(Color){50,5,2,255});
- }
- void middlebarview(){
- //canvas.Color = middlebarcolor
- DrawRectangle(middlebarx,middlebary,middlebarwidth,middlebarheight,middlebarcolor);
- //canvas.Color = middlebarcolor/2
- DrawRectangle(middlebarx,middlebary+middlebarheight/2,middlebarwidth,middlebarheight/2,DARKGRAY);
- //' Draw the icons ..
- int num = 0;
- for(int x = 640-128;x<640;x+=32){
- if(num>=nummiddlebaricons)continue;
- int pointx=x+middlebarx;
- int pointy=middlebary;
- if(middlebarcurrentid == num){
- //canvas.Color=Color.White
- DrawTexture(middlebarim[num].texture,pointx,pointy,WHITE);
- }else{
- DrawTexture(middlebarim[num].texture,pointx,pointy,DARKGRAY);
- //canvas.Color=Color.DarkGrey
- }
- //canvas.DrawImage(middlebarim[num],pointx,pointy)
- //'
- //' Selection of the sprite editor or the map editor
- if(spriteviewaction==false && IsMouseButtonDown(0)){
- if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,32,32)){
- middlebarcurrentid = num;
- }
- }
-
- num+=1;
- }
-
- }
- void setupmiddlebar(){
- int zero[8][8]={
- {0,12,12,12,12,12,12,0},
- {12,12,12,1,1,1,12,12},
- {12,12,12,1,12,1,12,12},
- {12,12,12,1,12,1,12,12},
- {12,12,12,1,12,1,12,12},
- {12,12,12,1,1,1,12,12},
- {12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
- //middlebarcan[middlebar0id].Color = c64color[zero[y][x]]
- //If zero[y][x] = 0 Then middlebarcan[middlebar0id].Alpha=0 Else middlebarcan[middlebar0id].Alpha=1
- BeginTextureMode(middlebarim[middlebar0id]);
- DrawRectangle(x*4,y*4,4,4,c64color[zero[7-y][x]]);
- EndTextureMode();
- }}
- //middlebarcan[middlebar0id].Flush()
- int one[8][8]={
- {0,12,12,12,12,12,12,0},
- {12,12,12,1,1,12,12,12},
- {12,12,12,12,1,12,12,12},
- {12,12,12,12,1,12,12,12},
- {12,12,12,12,1,12,12,12},
- {12,12,12,1,1,1,12,12},
- {12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
- //middlebarcan[middlebar1id].Color = c64color[one[y][x]]
- //If one[y][x] = 0 Then middlebarcan[middlebar1id].Alpha=0 Else middlebarcan[middlebar1id].Alpha=1
- BeginTextureMode(middlebarim[middlebar1id]);
- DrawRectangle(x*4,y*4,4,4,c64color[one[7-y][x]]);
- EndTextureMode();
- }}
- //middlebarcan[middlebar1id].Flush()
-
- int two[8][8]={
- {0,12,12,12,12,12,12,0},
- {12,12,12,1,1,1,12,12},
- {12,12,12,12,12,1,12,12},
- {12,12,12,12,1,12,12,12},
- {12,12,12,1,12,12,12,12},
- {12,12,12,1,1,1,12,12},
- {12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
- //middlebarcan[middlebar2id].Color = c64color[two[y][x]]
- //If two[y][x] = 0 Then middlebarcan[middlebar2id].Alpha=0 Else middlebarcan[middlebar2id].Alpha=1
- BeginTextureMode(middlebarim[middlebar2id]);
- DrawRectangle(x*4,y*4,4,4,c64color[two[7-y][x]]);
- EndTextureMode();
- }}
- //middlebarcan[middlebar2id].Flush()
- int three[8][8]={
- {0,12,12,12,12,12,12,0},
- {12,12,12,1,1,1,12,12},
- {12,12,12,12,12,1,12,12},
- {12,12,12,12,1,1,12,12},
- {12,12,12,12,12,1,12,12},
- {12,12,12,1,1,1,12,12},
- {12,12,12,12,12,12,12,12},
- {12,12,12,12,12,12,12,12}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
- //middlebarcan[middlebar3id].Color = c64color[three[y][x]]
- //If three[y][x] = 0 Then middlebarcan[middlebar3id].Alpha=0 Else middlebarcan[middlebar3id].Alpha=1
- BeginTextureMode(middlebarim[middlebar3id]);
- DrawRectangle(x*4,y*4,4,4,c64color[three[7-y][x]]);
- EndTextureMode();
- }}
- //middlebarcan[middlebar3id].Flush()
- }
- void setuptopbar(){
- int mapedit[8][8] = {
- {1,1,1,0,0,1,1,0},
- {1,1,1,0,0,1,1,0},
- {1,1,1,0,0,0,0,0},
- {0,0,0,1,1,1,1,1},
- {1,1,0,1,1,1,1,1},
- {1,1,0,1,1,1,1,1},
- {0,0,0,1,1,1,1,1},
- {0,0,0,1,1,1,1,1}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
- //topbarcan[topbarmapeditid].Color = c64color[mapedit[y][x]]
- //If mapedit[y][x] = 0 Then topbarcan[topbarmapeditid].Alpha=0 Else topbarcan[topbarmapeditid].Alpha=1
- BeginTextureMode(topbarim[topbarmapeditid]);
- if(mapedit[7-y][x]>0)DrawRectangle(x*4,y*4,4,4,c64color[mapedit[7-y][x]]);
- EndTextureMode();
- }}
- //topbarcan[topbarmapeditid].Flush()
- int spriteedit[8][8] = {
- {1,0,0,0,0,0,0,1},
- {0,1,0,0,0,0,1,0},
- {0,1,0,1,1,0,1,0},
- {0,0,1,1,1,1,0,0},
- {0,1,1,0,0,1,1,0},
- {0,1,1,1,1,1,1,0},
- {0,0,1,1,1,1,0,0},
- {0,1,0,1,1,0,1,0}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
- //topbarcan[topbarspriteeditid].Color = c64color[spriteedit[y][x]]
- //If spriteedit[y][x] = 0 Then topbarcan[topbarspriteeditid].Alpha=0 Else topbarcan[topbarspriteeditid].Alpha=1
- BeginTextureMode(topbarim[topbarspriteeditid]);
- if(spriteedit[7-y][x]>0)DrawRectangle(x*4,y*4,4,4,c64color[spriteedit[7-y][x]]);
- EndTextureMode();
- }}
- //topbarcan[topbarspriteeditid].Flush()
-
- }
- void topbarview(){
- //canvas.Color = topbarcolor
- DrawRectangle(topbarx,topbary,topbarwidth,topbarheight,topbarcolor);
- //canvas.Color = topbarcolor/2
- DrawRectangle(topbarx,topbary+topbarheight/2,topbarwidth,topbarheight/2,(Color){50,5,2,255});
- //'
- //' Draw the icons ..
- int num = 0;
- for(int x=640-200;x<640;x+=32){
- if(num>=numtopbaricons) continue;
- int pointx=x+topbarx;
- int pointy=topbary+3;
- if(topbarcurrentid == num){
- //canvas.Color=Color.White
- DrawTextureEx(topbarim[num].texture,(Vector2){pointx,pointy},0,0.6f,WHITE);
- }else{
- DrawTextureEx(topbarim[num].texture,(Vector2){pointx,pointy},0,0.6f,DARKGRAY);
- //canvas.Color=Color.DarkGrey
- }
- //canvas.DrawImage(topbarim[num],pointx,pointy,0,.6,.6)
- //'
- //' Selection of the sprite editor or the map editor
- if(spriteviewaction==false && IsMouseButtonDown(0)){
- if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,32,32)){
- topbarcurrentid = num;
- }
- }
-
- num+=1;
- }
- }
- void paletteview(){
- //canvas.Color = Color.Black
- DrawRectangle(palettex,palettey,palettewidth,paletteheight,BLACK);
- //canvas.Scissor = New Recti(palettex+2,palettey+2,palettex+2+palettewidth-4,palettey+2+paletteheight-4)
- //canvas.Color = Color.White
- int cc=0;
- for(int y=0;y<paletteheight;y+=palettecellheight){
- for(int x=0;x<palettewidth;x+=palettecellwidth){
- if(cc>=numpalette)break;
- float pointx=x+palettex;
- float pointy=y+palettey;
- //'
- //' Draw our color
- if(startsetuppalettemode == 0){
- //canvas.Color = c64color[cc]
- DrawRectangle(pointx,pointy,palettecellwidth,palettecellheight,c64color[cc]);
- }else{
- //canvas.Color = db32color[cc]
- DrawRectangle(pointx,pointy,palettecellwidth,palettecellheight,db32color[cc]);
- }
- //canvas.DrawRect(pointx,pointy,palettecellwidth,palettecellheight)
- //'
- //' Draw a white bar around the currently selected color
- if(paletteselected == cc){
- //canvas.OutlineMode = OutlineMode.Solid
- //canvas.OutlineWidth = 3
- //canvas.OutlineColor = Color.Black
- //canvas.DrawRect(pointx+2,pointy+2,palettecellwidth-4,palettecellheight-4)
- DrawRectangleLinesEx((Rectangle){pointx+2,pointy+2,palettecellwidth-4,palettecellheight-4}, 3, BLACK);
- //canvas.OutlineMode = OutlineMode.Solid
- //canvas.OutlineWidth = 1
- //canvas.OutlineColor = Color.Yellow
- //canvas.DrawRect(pointx+2,pointy+2,palettecellwidth-4,palettecellheight-4)
- DrawRectangleLinesEx((Rectangle){pointx+2,pointy+2,palettecellwidth-4,palettecellheight-4}, 1, YELLOW);
- //canvas.OutlineMode = OutlineMode.None
- }
- //'
- //' Select our color
- if(spriteviewaction==false && IsMouseButtonDown(0)){
- if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,palettecellwidth,palettecellheight)){
- paletteselected = cc;
- }
- }
- //'
- cc+=1;
- }}
- //canvas.Scissor = New Recti(0,0,640,480)
- //'canvas.Color = c64color[2]
- }
- void spritegrid(){
- //' If grid noview then exit this method
- if(toolgridtoggle == false)return;
-
- //' draw our grid
- //canvas.Color = Color.Grey
-
- for(int y=0;y<spriteheight;y++){
- for(int x=0;x<spritewidth;x++){
- int pointx=(x*gridwidth)+canvasx;
- int pointy=(y*gridheight)+canvasy;
- DrawLine(pointx,pointy,pointx+gridwidth,pointy,GRAY);
- DrawLine(pointx,pointy,pointx,pointy+gridheight,GRAY);
- }}
- }
- void setuptoolview(){
- //'read icons
- int pencil[8][8] = {
- {12,12,12,12,12,12,12,12},
- {12,1,1,1,1,12,12,12},
- {12,1,1,1,12,1,12,12},
- {12,1,1,12,1,1,1,12},
- {12,1,12,1,1,1,1,1},
- {12,12,1,1,1,1,1,1},
- {12,12,12,1,1,1,1,1},
- {12,12,12,12,1,1,1,1}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
-
- //toolcan[toolpencilid].Color = c64color[pencil[y][x]]
- BeginTextureMode(toolim[toolpencilid]);
- DrawRectangle(x*4,y*4,4,4,c64color[pencil[7-y][x]]);
- EndTextureMode();
- }
- }
- //toolcan[toolpencilid].Flush()
-
- int eraser[8][8] = {
- {12,12,12,12,12,12,12,12},
- {12,12,12,1,12,12,12,12},
- {12,12,1,1,1,12,12,12},
- {12,1,1,12,1,1,12,12},
- {12,12,1,1,12,1,1,12},
- {12,12,12,1,1,1,12,12},
- {12,12,12,12,1,12,12,12},
- {12,12,12,12,12,12,12,12}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
- //toolcan[tooleraserid].Color = c64color[eraser[y][x]]
- BeginTextureMode(toolim[tooleraserid]);
- DrawRectangle(x*4,y*4,4,4,c64color[eraser[7-y][x]]);
- EndTextureMode();
- }
- }
- //toolcan[tooleraserid].Flush()
- int fill[8][8] = {
- {12,12,12,1,12,12,12,12},
- {12,12,12,12,1,12,12,12},
- {12,12,12,12,12,1,12,12},
- {1,1,1,1,1,1,1,12},
- {12,1,1,1,1,1,1,1},
- {1,12,1,1,1,1,1,12},
- {12,12,12,1,1,1,12,12},
- {1,12,12,12,1,12,12,12}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
- //toolcan[toolfillid].Color = c64color[fill[y][x]]
- BeginTextureMode(toolim[toolfillid]);
- DrawRectangle(x*4,y*4,4,4,c64color[fill[7-y][x]]);
- EndTextureMode();
- }
- }
- //toolcan[toolfillid].Flush()
- int line[8][8] = {
- {12,12,12,12,12,12,12,12},
- {12,1,12,12,12,12,12,12},
- {12,12,1,12,12,12,12,12},
- {12,12,12,1,12,12,12,12},
- {12,12,12,12,1,12,12,12},
- {12,12,12,12,12,1,12,12},
- {12,12,12,12,12,12,1,12},
- {12,12,12,12,12,12,12,12}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
- //toolcan[toollineid].Color = c64color[line[y][x]]
- BeginTextureMode(toolim[toollineid]);
- DrawRectangle(x*4,y*4,4,4,c64color[line[7-y][x]]);
- EndTextureMode();
- }
- }
- //toolcan[toollineid].Flush()
- int selection[8][8] = {
- {12,12,12,12,12,12,12,12},
- {12,1,12,1,1,12,1,12},
- {12,12,12,12,12,12,12,12},
- {12,1,12,12,12,12,1,12},
- {12,1,12,12,12,12,1,12},
- {12,12,12,12,12,12,12,12},
- {12,1,12,1,1,12,1,12},
- {12,12,12,12,12,12,12,12}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
- //toolcan[toolselectionid].Color = c64color[selection[y][x]]
- BeginTextureMode(toolim[toolselectionid]);
- DrawRectangle(x*4,y*4,4,4,c64color[selection[7-y][x]]);
- EndTextureMode();
- }
- }
- //toolcan[toolselectionid].Flush()
- int copy[8][8] = {
- {1,12,12,12,12,12,12,12},
- {1,1,12,1,1,12,1,12},
- {1,1,1,12,12,12,12,12},
- {1,1,1,1,12,12,1,12},
- {1,1,1,12,12,12,1,12},
- {1,1,12,12,12,12,12,12},
- {1,12,12,1,1,12,1,12},
- {12,12,12,12,12,12,12,12}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
- //toolcan[toolcopyid].Color = c64color[copy[y][x]]
- BeginTextureMode(toolim[toolcopyid]);
- DrawRectangle(x*4,y*4,4,4,c64color[copy[7-y][x]]);
- EndTextureMode();
- }
- }
- //toolcan[toolcopyid].Flush()
- int paste[8][8] = {
- {12,12,12,1,12,12,12,12},
- {12,12,1,1,1,12,1,12},
- {12,1,1,1,12,12,12,12},
- {1,1,1,1,12,12,1,12},
- {12,1,1,1,12,12,1,12},
- {12,12,1,1,12,12,12,12},
- {12,12,12,1,1,12,1,12},
- {12,12,12,12,12,12,12,12}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
- //toolcan[toolpasteid].Color = c64color[paste[y][x]]
- BeginTextureMode(toolim[toolpasteid]);
- DrawRectangle(x*4,y*4,4,4,c64color[paste[7-y][x]]);
- EndTextureMode();
- }
- }
- //toolcan[toolpasteid].Flush()
- int cut[8][8] = {
- {12,12,12,12,12,12,12,12},
- {12,12,12,1,12,12,12,12},
- {12,12,12,12,1,12,12,12},
- {12,1,12,12,1,12,12,12},
- {12,12,1,1,12,1,1,12},
- {12,12,12,12,1,12,1,1},
- {12,12,12,12,1,1,12,12},
- {12,12,12,12,12,1,1,12}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
- //toolcan[toolcutid].Color = c64color[cut[y][x]]
- BeginTextureMode(toolim[toolcutid]);
- DrawRectangle(x*4,y*4,4,4,c64color[cut[7-y][x]]);
- EndTextureMode();
- }
- }
- //toolcan[toolcutid].Flush()
- int flipvertical[8][8] = {
- {12,12,12,1,1,12,12,12},
- {12,12,1,1,1,1,12,12},
- {12,1,1,1,1,1,1,12},
- {12,12,12,1,1,12,12,12},
- {12,12,12,1,1,12,12,12},
- {12,1,1,1,1,1,1,12},
- {12,12,1,1,1,1,12,12},
- {12,12,12,1,1,12,12,12}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
- //toolcan[toolflipverticalid].Color = c64color[flipvertical[y][x]]
- BeginTextureMode(toolim[toolflipverticalid]);
- DrawRectangle(x*4,y*4,4,4,c64color[flipvertical[7-y][x]]);
- EndTextureMode();
- }
- }
- //toolcan[toolflipverticalid].Flush()
-
- int fliphorizontal[8][8] = {
- {12,12,12,12,12,12,12,12},
- {12,12,1,12,12,1,12,12},
- {12,1,1,12,12,1,1,12},
- {1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1},
- {12,1,1,12,12,1,1,12},
- {12,12,1,12,12,1,12,12},
- {12,12,12,12,12,12,12,12}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
- //toolcan[toolfliphorizontalid].Color = c64color[fliphorizontal[y][x]]
- BeginTextureMode(toolim[toolfliphorizontalid]);
- DrawRectangle(x*4,y*4,4,4,c64color[fliphorizontal[7-y][x]]);
- EndTextureMode();
- }
- }
- //toolcan[toolfliphorizontalid].Flush()
- int colorpicker[8][8] = {
- {12,1,1,12,12,12,12,12},
- {1,1,12,12,1,12,12,12},
- {1,12,12,1,12,12,12,12},
- {12,12,1,12,1,12,12,12},
- {12,1,12,1,12,1,12,12},
- {12,12,12,12,1,12,1,12},
- {12,12,12,12,12,1,1,12},
- {12,12,12,12,12,12,12,1}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
- //toolcan[toolcolorpickerid].Color = c64color[colorpicker[y][x]]
- BeginTextureMode(toolim[toolcolorpickerid]);
- DrawRectangle(x*4,y*4,4,4,c64color[colorpicker[7-y][x]]);
- EndTextureMode();
- }
- }
- //toolcan[toolcolorpickerid].Flush()
- int grid[8][8] = {
- {12,12,12,12,12,12,12,12},
- {12,12,1,12,12,1,12,12},
- {12,1,1,1,1,1,1,12},
- {12,12,1,12,12,1,12,12},
- {12,12,1,12,12,1,12,12},
- {12,1,1,1,1,1,1,12},
- {12,12,1,12,12,1,12,12},
- {12,12,12,12,12,12,12,12}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
- //toolcan[toolgridid].Color = c64color[grid[y][x]]
- BeginTextureMode(toolim[toolgridid]);
- DrawRectangle(x*4,y*4,4,4,c64color[grid[7-y][x]]);
- EndTextureMode();
- }
- }
- //toolcan[toolgridid].Flush()
-
-
- int filledrect[8][8] = {
- {12,12,12,12,12,12,12,12},
- {12,1,1,1,1,1,1,12},
- {12,1,1,1,1,1,1,12},
- {12,1,1,1,1,1,1,12},
- {12,1,1,1,1,1,1,12},
- {12,1,1,1,1,1,1,12},
- {12,1,1,1,1,1,1,12},
- {12,12,12,12,12,12,12,12}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
- //toolcan[toolfilledrectid].Color = c64color[filledrect[y][x]]
- BeginTextureMode(toolim[toolfilledrectid]);
- DrawRectangle(x*4,y*4,4,4,c64color[filledrect[7-y][x]]);
- EndTextureMode();
- }
- }
- //toolcan[toolfilledrectid].Flush()
- int outlinerect[8][8] = {
- {12,12,12,12,12,12,12,12},
- {12,1,1,1,1,1,1,12},
- {12,1,12,12,12,12,1,12},
- {12,1,12,12,12,12,1,12},
- {12,1,12,12,12,12,1,12},
- {12,1,12,12,12,12,1,12},
- {12,1,1,1,1,1,1,12},
- {12,12,12,12,12,12,12,12}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
- //toolcan[tooloutlinerectid].Color = c64color[outlinerect[y][x]]
- BeginTextureMode(toolim[tooloutlinerectid]);
- DrawRectangle(x*4,y*4,4,4,c64color[outlinerect[7-y][x]]);
- EndTextureMode();
- }
- }
- //toolcan[tooloutlinerectid].Flush()
- int filledcircle[8][8] = {
- {12,12,12,1,1,12,12,12},
- {12,12,1,1,1,1,12,12},
- {12,1,1,1,1,1,1,12},
- {1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1},
- {12,1,1,1,1,1,1,12},
- {12,12,1,1,1,1,12,12},
- {12,12,12,1,1,12,12,12}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
- int p=filledcircle[7-y][x];
- //toolcan[toolfilledcircleid].Color = c64color[p]
- BeginTextureMode(toolim[toolfilledcircleid]);
- DrawRectangle(x*4,y*4,4,4,c64color[p]);
- EndTextureMode();
- }
- }
- //toolcan[toolfilledcircleid].Flush()
- int outlinecircle[8][8] = {
- {12,12,12,1,1,12,12,12},
- {12,12,1,12,12,1,12,12},
- {12,1,12,12,12,12,1,12},
- {1,12,12,12,12,12,12,1},
- {1,12,12,12,12,12,12,1},
- {12,1,12,12,12,12,1,12},
- {12,12,1,12,12,1,12,12},
- {12,12,12,1,1,12,12,12}};
- for(int y=0;y<8;y++){
- for(int x=0;x<8;x++){
- int p=outlinecircle[7-y][x];
- //toolcan[tooloutlinecircleid].Color = c64color[p]
- BeginTextureMode(toolim[tooloutlinecircleid]);
- DrawRectangle(x*4,y*4,4,4,c64color[p]);
- EndTextureMode();
- }
- }
- //toolcan[tooloutlinecircleid].Flush()
- }
- void toolview(){
- //canvas.Color=Color.Black
- DrawRectangle(toolx,tooly,toolwidth,toolheight,BLACK);
- //canvas.Color=Color.White
- if(delay>0)delay-=1;
- int num=0;
- for(int y=tooly;y<tooly+toolheight;y+=32){
- for(int x=toolx;x<toolx+toolwidth;x+=32){
- if(num>=numtools)continue;
- int pointx=x;
- int pointy=y;
- if(toolselected == num){
- //canvas.Color = Color.Yellow
- DrawRectangle(pointx,pointy,32,32,YELLOW);
- //canvas.Color = Color.White
- //canvas.Scissor = New Recti(pointx+2,pointy+2,pointx+30,pointy+30)
- DrawTexture(toolim[num].texture,pointx,pointy,WHITE);
- //canvas.Scissor = New Recti(0,0,640,480)
- }else{
- DrawTexture(toolim[num].texture,pointx,pointy,WHITE);
- }
- //'
- //'/ Interaction with the tool area
- //'
- if(spriteviewaction==false && IsMouseButtonDown(0)){
- if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,32,32)){
- toolselected = num;
- //' Pastethe selected area
- if(toolselected == toolpasteid){
- if(selectionstartx == selectionendx && selectionstarty == selectionendy){
- }else{
- for(int y1=selectionbufferstarty; y1<=selectionbufferendy;y1++){
- for(int x1=selectionbufferstartx; x1<=selectionbufferendx;x1++){
- int destx=selectionstartx+x1-selectionbufferstartx;
- int desty=selectionstarty+y1-selectionbufferstarty;
- if(x1<0 || y1<0 || x1>=32 || y1>=32) continue;
- if(destx<0 || desty<0 || destx>=32 || desty>=32)continue;
- if(destx>selectionendx || desty>selectionendy)continue;
- map[destx][desty] = selectionbuffer[x1][y1];
- }
- }
- toolselected = toolpencilid;
- }
- }
-
-
- //' Copy the selected area
- if(toolselected == toolcopyid){
- if(selectionstartx == selectionendx && selectionstarty == selectionendy){
-
- }else{
- selectionbufferstartx = selectionstartx;
- selectionbufferstarty = selectionstarty;
- selectionbufferendx = selectionendx;
- selectionbufferendy = selectionendy;
- for(int y1=selectionstarty;y1<=selectionendy;y1++){
- for(int x1=selectionstartx;x1<=selectionendx;x1++){
- selectionbuffer[x1][y1] = map[x1][y1];
- }
- }
- toolselected = toolpencilid;
- }
- }
- // Cut the selected area
- if(toolselected == toolcutid){
- if(selectionstartx == selectionendx && selectionstarty == selectionendy){
-
- }else{
- for(int y1=selectionstarty;y1<=selectionendy;y1++){
- for(int x1=selectionstartx;x1<=selectionendx;x1++){
- map[x1][y1] = paletteeraser;
- }
- }
- toolselected = toolpencilid;
- }
- }
-
- //' Mirror vertically
- if(toolselected == toolflipverticalid && delay <= 0)
- {
- //int tempmap[32][32] = {0};
- for(int y1=0;y1<spriteheight;y1++){
- for(int x1=0;x1<spritewidth;x1++){
- tempmap[x1][y1] = map[x1][y1];
- }
- }
- for(int y1=0;y1<spriteheight;y1++){
- for(int x1=0;x1<spritewidth;x1++){
- map[x1][y1] = tempmap[x1][spriteheight-1-y1];
- }
- }
- delay = delaydefault;
- toolselected = toolpencilid;
- }
- //Mirror Horizontal
- if(toolselected == toolfliphorizontalid && delay <= 0){
- //int tempmap[spritewidth][spriteheight];
- for(int y1=0;y1<spriteheight;y1++){
- for(int x1=0;x1<spritewidth;x1++){
- tempmap[x1][y1] = map[x1][y1];
- }
- }
- for(int y1=0;y1<spriteheight;y1++){
- for(int x1=0;x1<spritewidth;x1++){
- map[x1][y1] = tempmap[spritewidth-1-x1][y1];
- }
- }
- delay = delaydefault;
- toolselected = toolpencilid;
- }
- //' Grid toggle
- if(toolselected == toolgridid && delay <= 0){
- if(toolgridtoggle == true){
- toolgridtoggle = false;
- }else{
- toolgridtoggle = true;
- }
- delay = delaydefault;
- toolselected = toolpencilid;
- }
- }
- }
- num+=1;
-
- }
- }
- }
- void spritelibview(){
- //canvas.Color = Color.Black
- DrawRectangle(spritelibx,spriteliby,spritelibwidth,spritelibheight,BLACK);
- //canvas.Color = Color.White
- int num=(middlebarcurrentid*80);
- for(int y=spriteliby;y<spriteliby+spritelibheight;y+=spriteheight*spritelibscale){
- for(int x=spritelibx;x<spritelibx+spritelibwidth;x+=spritewidth*spritelibscale){
- int pointx=x;
- int pointy=y;
- if(num == spritelibselected){
-
- //canvas.Color = Color.White
- //DrawRectangle(pointx,pointy,spritewidth*spritelibscale,spriteheight*spritelibscale,WHITE);
- //canvas.Scissor = New Recti(pointx+2,pointy+2,pointx+spritewidth*spritelibscale-3,pointy+spriteheight*spritelibscale-3)
- //'canvas.Scissor(z1)
- //DrawTextureRec(spritelibim[num].texture,(Rectangle){0,0,spritewidth,spriteheight},pointx,pointy,WHITE);
- //DrawTextureEx(spritelibim[num].texture,(Vector2){pointx,pointy},0,spritelibscale,WHITE);
- //DrawTexture(spritelibim[num].texture,pointx,pointy,WHITE);
- // NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
- DrawTextureRec(spritelibim[num].texture, (Rectangle){ 0, 0, spritelibim[num].texture.width, -spritelibim[num].texture.height }, (Vector2){pointx,pointy}, WHITE);
- DrawRectangle(pointx,pointy,spritewidth*spritelibscale,spriteheight*spritelibscale,(Color){100,100,100,100});
- //'Local z2:=New Recti(0,0,640,480)
- //canvas.Scissor = New Recti(0,0,640,480)
- }else{
- //canvas.Color = Color.White
- //canvas.DrawImage(spritelibim[num],pointx,pointy)
- //DrawTexture(spritelibim[num].texture,pointx,pointy,WHITE);
- //DrawTextureEx(spritelibim[num].texture,(Vector2){pointx,pointy},0,spritelibscale,WHITE);
- //DrawTexture(spritelibim[num].texture,pointx,pointy,WHITE);
- //DrawTextureRec(spritelibim[num].texture, (Rectangle){ 0, 0, spritewidth, -spriteheight }, (Vector2){ 0, 0 }, WHITE);
- DrawTextureRec(spritelibim[num].texture, (Rectangle){ 0, 0, spritelibim[num].texture.width, -spritelibim[num].texture.height }, (Vector2){pointx,pointy}, WHITE);
- }
-
-
- if(spriteviewaction==false && IsMouseButtonDown(0)){
- if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,spritewidth*spritelibscale,spriteheight*spritelibscale)){
- spritelibselected = num;
- spritelibcopytocanvas();
- }
- }
-
- num+=1;
- if(num>=numspritelib)break;
- }
- if(num>=numspritelib)break;
- }
- }
- void spriteview(){
- // If drawing then do not allow presses outside spriteview unless mouse is not pressed.
- if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,canvasx,canvasy,canvaswidth,canvasheight) && IsMouseButtonDown(0) || IsMouseButtonDown(1)){
- spriteviewaction=true;
- }
- if(IsMouseButtonDown(0)==false && IsMouseButtonDown(1)==false){
- spriteviewaction=false;
- }
-
- for(int y=0;y<spriteheight;y++){
- for(int x=0;x<spritewidth;x++){
- int pointx=(x*gridwidth)+canvasx;
- int pointy=(y*gridheight)+canvasy;
- //'canvas.DrawRect()
- if(startsetuppalettemode == 0){
- //canvas.Color = c64color[map[x,y]]
- DrawRectangle(pointx,pointy,gridwidth,gridheight,c64color[map[x][y]]);
- }else{
- //canvas.Color = db32color[map[x,y]]
- DrawRectangle(pointx,pointy,gridwidth,gridheight,db32color[map[x][y]]);
- }
- //canvas.DrawRect(pointx,pointy,gridwidth,gridheight)
-
- //'
- //' Mouse down (LEFT)
- if(IsMouseButtonDown(0)){
- if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,gridwidth,gridheight)){
- if(toolselected == toolpencilid){
- map[x][y] = paletteselected;
- }
- if(toolselected == tooleraserid){
- map[x][y] = paletteeraser;
- }
- }
- }
- if(IsMouseButtonPressed(0)){
- if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,gridwidth,gridheight)){
- if(toolselected == toolfillid){
- paletteundermouse = map[x][y];
- if(paletteundermouse!=paletteselected)fillatposition(x,y,map[x][y],paletteselected);
- }
- }
- }
- // Line tool
- if(IsMouseButtonDown(0)){
- if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,gridwidth,gridheight)){
- if(toolselected == toollineid){
- if(linepressed == false && lineactive == false){
- lineactive = true;
- linepressed = true;
- linestartx = x;
- linestarty = y;
- }
- if(lineactive == true){
- lineendx = x;
- lineendy = y;
- }
- }
- }
- }
- if(IsMouseButtonDown(0) == false){
- if(toolselected == toollineid){
- if(lineactive == true){
- previewline(true);
- lineactive = false;
- linepressed = false;
- }
- }
- }
-
- //' Selection Tool
- if(IsMouseButtonDown(0)){
- if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,gridwidth,gridheight)){
- if(toolselected == toolselectionid){
- if(selectionpressed == false && selectionactive == false){
- selectionactive = true;
- selectionpressed = true;
- selectionstartx = x;
- selectionstarty = y;
- selectionnegativeswitchx = true;
- selectionnegativeswitchy = true;
- }
- if(selectionactive == true){
- selectionendx = x;
- selectionendy = y;
- if(selectionendx < selectionstartx){
- selectionendx-=1;
- if(selectionnegativeswitchx){
- selectionnegativeswitchx = false;
- selectionstartx+=1;
- }
- }
- if(selectionendy < selectionstarty){
- selectionendy-=1;
- if(selectionnegativeswitchy){
- selectionnegativeswitchy = false;
- selectionstarty+=1;
- }
- }
-
- }
- }
- }
- }
- if(IsMouseButtonDown(0) == false){
- if(toolselected == toolselectionid){
- if(selectionactive == true){
- //'previewselection(canvas,True)
- selectionactive = false;
- selectionpressed = false;
- //' if the end is smaller then then start then switch them
- if(selectionendx<selectionstartx){
- int a=selectionstartx;
- int b=selectionendx;
- selectionstartx = b+1;
- selectionendx = a -1;
- }
- if(selectionendy<selectionstarty){
- int a=selectionstarty;
- int b=selectionendy;
- selectionstarty = b +1;
- selectionendy = a -1 ;
- }
- }
- }
- }
-
- //' Remove the selection with rmb
- if(IsMouseButtonDown(1) == true){
- selectionstartx=0;
- selectionstarty=0;
- selectionendx=0;
- selectionendy=0;
- }
-
-
- //'
- //' Mouse down (MIDDLE) Color Picker
- if(IsMouseButtonDown(2)){
- if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,gridwidth,gridheight)){
- paletteselected = map[x][y];
- }
- }
-
- if(IsMouseButtonDown(0)){
- if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,gridwidth,gridheight)){
- if(toolselected == toolcolorpickerid){
- paletteselected = map[x][y];
- }
- }
- }
- //'
- //' Mouse Down(LEFT) Filled rect / outlined rect / filled circle / outlined circle
- if(IsMouseButtonDown(0)){
- if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,gridwidth,gridheight)){
-
- if(toolselected == toolfilledrectid || toolselected == tooloutlinerectid || toolselected == toolfilledcircleid || toolselected == tooloutlinecircleid){
-
- if(bcselectionpressed == false && bcselectionactive == false){
-
- bcselectionactive = true;
- bcselectionpressed = true;
- bcselectionstartx = x;
- bcselectionstarty = y;
- bcselectionnegativeswitchx = true;
- bcselectionnegativeswitchy = true;
- }
- if(bcselectionactive == true){
- bcselectionendx = x;
- bcselectionendy = y;
- if(bcselectionendx < bcselectionstartx){
- bcselectionendx-=1;
- if(bcselectionnegativeswitchx){
- bcselectionnegativeswitchx = false;
- bcselectionstartx+=1;
- }
- }
- if(bcselectionendy < bcselectionstarty){
- bcselectionendy-=1;
- if(bcselectionnegativeswitchy){
- bcselectionnegativeswitchy = false;
- bcselectionstarty+=1;
- }
- }
-
- }
- }
- }
- }
-
- if(IsMouseButtonDown(0) == false){
-
- if(toolselected == toolfilledrectid || toolselected == tooloutlinerectid || toolselected == toolfilledcircleid || toolselected == tooloutlinecircleid){
-
- if(bcselectionactive == true){
- //'previewselection(canvas,True)
- bcselectionactive = false;
- bcselectionpressed = false;
- //' if the end is smaller then then start then switch them
- if(bcselectionendx<bcselectionstartx){
- int a=bcselectionstartx;
- int b=bcselectionendx;
- bcselectionstartx = b+1;
- bcselectionendx = a -1;
- }
- if(bcselectionendy<bcselectionstarty){
- int a=bcselectionstarty;
- int b=bcselectionendy;
- bcselectionstarty = b +1;
- bcselectionendy = a -1;
- }
- //'
- //' Do the filling
- if(toolselected == toolfilledrectid || toolselected == tooloutlinerectid){
-
- for(int y=bcselectionstarty;y<=bcselectionendy;y++){
- for(int x=bcselectionstartx;x<=bcselectionendx;x++){
- if(toolselected == toolfilledrectid)map[x][y] = paletteselected;
- if(toolselected == tooloutlinerectid){
- if(x == bcselectionstartx || x == bcselectionendx || y == bcselectionendy || y==bcselectionstarty){
- map[x][y] = paletteselected;
- }
- }
- }
- }
- }else if(toolselected == toolfilledcircleid || toolselected == tooloutlinecircleid){
- //' add circle code here
-
- int w=abs(bcselectionstartx-bcselectionendx)+1;
- int h=abs(bcselectionstarty-bcselectionendy)+1;
- if(toolselected == tooloutlinecircleid){
- //Local ti:Image = New Image(spritewidth,spriteheight)
- //Local tc:Canvas = New Canvas(ti)
-
- //tc.Clear(Color.Black)
- //tc.Color = Color.White
-
- //BeginTextureMode(ti);
- //ClearBackground(BLANK);
- //EndTextureMode();
- //tc.OutlineMode=OutlineMode.Smooth
- //tc.OutlineColor = Color.Green
- //tc.OutlineWidth = 0
- //tc.DrawOval(bcselectionstartx,bcselectionstarty,w-1,h-1)
- //tc.DrawOval(bcselectionstartx,bcselectionstarty,w-1,h-1)
- midptellipse((w/2)-1,(h/2)-1,bcselectionstartx+w/2,bcselectionstarty+h/2);
- //tc.Flush()
- for(int y=0;y<spriteheight;y++){
- for(int x=0;x<spritewidth;x++){
- if(tempmap[x][y] == 1){
- map[x][y] = paletteselected;
- }
- }
- }
- }else{
- /*
- Local ti:Image = New Image(spritewidth,spriteheight)
- Local tc:Canvas = New Canvas(ti)
- tc.Clear(Color.Black)
- tc.Color = Color.White
- tc.DrawOval(bcselectionstartx-1,bcselectionstarty-1,w+1,h+1)
- tc.Flush()
- For Local y:Int=0 Until spriteheight
- For Local x:Int=0 Until spritewidth
- If ti.GetPixel(x,y) <> Color.Black
- map[x,y] = paletteselected
- End If
- Next
- Next
- */
- }
-
- }
-
- bcselectionendy=0;
- bcselectionendx=0;
- bcselectionstarty=0;
- bcselectionstartx=0;
- }
- }
- }
- // Tab between map view and sprite view.
- if(IsKeyReleased(KEY_TAB)){
- spriteviewaction = false;
- topbarcurrentid = topbarmapeditid;
- }
-
- //' Read from disk..
- if(IsKeyReleased(KEY_F6)){
- loadspritelib();
- }
- //' Save to disk..
- if(IsKeyReleased(KEY_F5)){
- savespritelib();
- }
- //' Copy to clipboard
- if(IsKeyReleased(KEY_C)){
- copytoclipboard();
- }
- // Copy FROM clipboard.
- if(IsKeyReleased(KEY_P)){
- copyfromclipboard();
- updatepreview();
- updatespritelib();
- }
- }
- }
- // updatepreview()
- // updatespritelib()
- }
- void updatepreview(){
- if(spritewidth==8)previewcellwidth=8;
- if(spritewidth==16)previewcellwidth=4;
- if(spritewidth==32)previewcellwidth=2;
- //previewcan.Clear(Color.Black)
- for(int y=0;y<spriteheight;y++){
- for(int x=0;x<spritewidth;x++){
- int pointx=x*previewcellwidth;
- int pointy=y*previewcellwidth;
- BeginTextureMode(previewim);
- if(startsetuppalettemode == 0){
- DrawRectangle(pointx,pointy,previewcellwidth,previewcellwidth,c64color[map[x][y]]);
- //previewcan.Color = c64color[map[x,y]]
- }else{
- //previewcan.Color = db32color[map[x,y]]
- DrawRectangle(pointx,pointy,previewcellwidth,previewcellwidth,db32color[map[x][y]]);
- }
- EndTextureMode();
- //previewcan.DrawRect(pointx,pointy,previewcellwidth,previewcellheight)
- }
- }
- //previewcan.Flush()
- }
- void loadspritelib(){
- // Read the array from disk..
- FILE *fp;
- fp=fopen("spritedata.spr","r");
- fread(spritelibmap,sizeof(spritelibmap),1,fp); /* read the entire file into the array */
- fclose(fp);
-
- // rebuild the sprite images..
- for(int i=0;i<80*4;i++){
- bool empty=true;
- for(int y=0;y<spriteheight;y++){
- for(int x=0;x<spritewidth;x++){
- if(spritelibmap[i][x][y]>0){
- empty=false;
- }
- }}
- if(empty==true)continue;
- for(int y=0;y<spriteheight;y++){
- for(int x=0;x<spritewidth;x++){
- float pointx=x*spritelibscale;
- float pointy=y*spritelibscale;
- BeginTextureMode(spritelibim[i]);
- if(startsetuppalettemode == 0){
- DrawRectangle(pointx,pointy,spritelibscale,spritelibscale,c64color[spritelibmap[i][x][y]]);
- //spritelibcan[spritelibselected].Color = c64color[map[x,y]]
- }else{
- DrawRectangle(pointx,pointy,spritelibscale,spritelibscale,db32color[spritelibmap[i][x][y]]);
- //spritelibcan[spritelibselected].Color = db32color[map[x,y]]
- }
- EndTextureMode();
- }
- }
- }
- //updatepreview();
- //updatespritelib();
- // First put the current selected into the map[]
- //map[0][0]=1;
- for(int y=0;y<spriteheight;y++){
- for(int x=0;x<spritewidth;x++){
- map[x][y] = spritelibmap[spritelibselected][x][y];
- }}
- //updatespritelib();
- updatepreview();
- }
- void savespritelib(){
- // Create out file pointer.
- FILE *fp;
- // Write the array to disk.
- fp=fopen("spritedata.spr","w");
- fwrite(spritelibmap,sizeof(spritelibmap),1,fp); /* Write to File */
- fclose(fp);
- }
- void updatespritelib(){
- for(int y=0;y<spriteheight;y++){
- for(int x=0;x<spritewidth;x++){
- float pointx=x*spritelibscale;
- float pointy=y*spritelibscale;
- BeginTextureMode(spritelibim[spritelibselected]);
- if(startsetuppalettemode == 0){
- DrawRectangle(pointx,pointy,spritelibscale,spritelibscale,c64color[map[x][y]]);
- //spritelibcan[spritelibselected].Color = c64color[map[x,y]]
- }else{
- DrawRectangle(pointx,pointy,spritelibscale,spritelibscale,db32color[map[x][y]]);
- //spritelibcan[spritelibselected].Color = db32color[map[x,y]]
- }
- //spritelibcan[spritelibselected].DrawRect(pointx,pointy,spritelibscale,spritelibscale)
- spritelibmap[spritelibselected][x][y] = map[x][y];
- EndTextureMode();
- }
- }
- //spritelibcan[spritelibselected].Flush()
- }
- /*
- void fillatposition(int x,int y){
- Local ol:List<pathnode> = New List<pathnode>
- ' Add the start position on the list
- ol.AddLast(New pathnode(x,y))
- ' set the cloes map at the start position to distance 1
- Local colorundermouse:Int=map[x,y]
- map[x,y] = paletteselected
-
- ' some helper arrays. We can determine the top,right,and bottom
- ' and left position cells with these numbers.
- Local dx:Int[] = New Int[](0,1,0,-1)
- Local dy:Int[] = New Int[](-1,0,1,0)
- ' While there is contents in the list
- While ol.Count() <> 0
-
- ' Get the current location
- Local x1:Int=ol.First.x
- Local y1:Int=ol.First.y
- ' Remove the current location from the list
- ol.RemoveFirst()
- ' Get 4 new positions around the current positions
- For Local i:=0 Until 4
- ' Set new x and y
- Local nx:Int=x1+dx[i]
- Local ny:Int=y1+dy[i]
- ' If the coordinates are inside the map
- If nx>=0 And ny>=0 And nx<spritewidth And ny<spriteheight
- ' If the closedmap is not written to yet
- If map[nx,ny] = colorundermouse And map[nx,ny] <> paletteselected
- ' Set the new distance based on the current distance
- map[nx,ny] = paletteselected
- ' Add new position to the list
- ol.AddLast(New pathnode(nx,ny))
- End If
- End If
- Next
- Wend
-
- }
- */
- void previewview(){
- //canvas.Color = Color.White
- DrawRectangle(previewx,previewy,previewwidth,previewheight,WHITE);
- //DrawTexture(previewim.texture,previewx+1,previewy+1,WHITE);
- DrawTextureRec(previewim.texture, (Rectangle){ 0,0, 64, -64 }, (Vector2){previewx,previewy}, WHITE);
- }
- void spritelibcopytocanvas(){
- for(int y=0;y<spriteheight;y++){
- for(int x=0;x<spritewidth;x++){
- map[x][y] = spritelibmap[spritelibselected][x][y];
- }
- }
- }
- void previewline(bool drawit){
- if(lineactive == false)return;
-
- int x1=linestartx;
- int y1=linestarty;
- int x2=lineendx;
- int y2=lineendy;
- int dx;
- int dy;
- int sx;
- int sy;
- int e;
- dx = abs(x2 - x1);
- sx = -1;
- if(x1 < x2)sx = 1;
- dy = abs(y2 - y1);
- sy = -1;
- if(y1 < y2)sy = 1;
- if(dx < dy){
- e = dx / 2;
- }else{
- e = dy / 2;
- }
- bool exitloop=false;
- while(exitloop == false){
- int pointx=canvasx+(x1*gridwidth);
- int pointy=canvasy+(y1*gridheight);
- if(startsetuppalettemode == 0){
- //canvas.Color = c64color[paletteselected]
- DrawRectangle(pointx,pointy,gridwidth,gridheight,c64color[paletteselected]);
- }else{
- //canvas.Color = db32color[paletteselected]
- DrawRectangle(pointx,pointy,gridwidth,gridheight,db32color[paletteselected]);
- }
- //canvas.DrawRect(pointx,pointy,gridwidth,gridheight)
- if(drawit==true){
- if(x1<0 || y1<0 || x1>=spritewidth || y1>=spriteheight)break;
- map[x1][y1] = paletteselected;
- }
- if(x1 == x2){
- if(y1 == y2){
- exitloop = true;
- }
- }
- if(dx > dy){
- x1 += sx;
- e -= dy;
- if(e < 0){
- e += dx;
- y1 += sy;
- }
- }else{
- y1 += sy;
- e -= dx;
- if(e < 0){
- e += dy;
- x1 += sx;
- }
- }
-
- }
-
- }
- //' Selection for the selection tool or the filled outlined tools
- //'
- void previewselection(bool drawit){
- //' the selection rectangle
- if(selectionstartx == selectionendx && selectionstarty == selectionendy){
- }else{
- int x1=canvasx+(selectionstartx*gridwidth);
- int y1=canvasy+(selectionstarty*gridheight);
- int x2=canvasx+((selectionendx+1)*gridwidth);
- int y2=canvasy+((selectionendy+1)*gridheight);
-
-
- //canvas.Color = Color.White
- DrawLine(x1,y1,x2,y1,WHITE);
- DrawLine(x1,y1,x1,y2,WHITE);
- DrawLine(x1,y2,x2,y2,WHITE);
- DrawLine(x2,y1,x2,y2,WHITE);
- //Color = Color.Black
- x1+=1;y1+=1;x2-=1;y2-=1;
- DrawLine(x1,y1,x2,y1,BLACK);
- DrawLine(x1,y1,x1,y2,BLACK);
- DrawLine(x1,y2,x2,y2,BLACK);
- DrawLine(x2,y1,x2,y2,BLACK);
- x1+=2;y1+=2;x2-=2;y2-=2;
- DrawLine(x1,y1,x2,y1,BLACK);
- DrawLine(x1,y1,x1,y2,BLACK);
- DrawLine(x1,y2,x2,y2,BLACK);
- DrawLine(x2,y1,x2,y2,BLACK);
- }
- //' the filled outlined tool
- if(bcselectionstartx == bcselectionendx && bcselectionstarty == bcselectionendy){
- }else{
- int x1=canvasx+(bcselectionstartx*gridwidth);
- int y1=canvasy+(bcselectionstarty*gridheight);
- int x2=canvasx+((bcselectionendx+1)*gridwidth);
- int y2=canvasy+((bcselectionendy+1)*gridheight);
-
- //canvas.Color = Color.White
- DrawLine(x1,y1,x2,y1,WHITE);
- DrawLine(x1,y1,x1,y2,WHITE);
- DrawLine(x1,y2,x2,y2,WHITE);
- DrawLine(x2,y1,x2,y2,WHITE);
- //canvas.Color = Color.Black
- x1+=1;y1+=1;x2-=1;y2-=1;
- DrawLine(x1,y1,x2,y1,BLACK);
- DrawLine(x1,y1,x1,y2,BLACK);
- DrawLine(x1,y2,x2,y2,BLACK);
- DrawLine(x2,y1,x2,y2,BLACK);
- x1+=2;y1+=2;x2-=2;y2-=2;
- DrawLine(x1,y1,x2,y1,BLACK);
- DrawLine(x1,y1,x1,y2,BLACK);
- DrawLine(x1,y2,x2,y2,BLACK);
- DrawLine(x2,y1,x2,y2,BLACK);
- }
- }
- void copytoclipboard(){
- /*
- //This is the original code from the monkey2 language..
- Local out:String="int sprite["+spriteheight+"]["+spritewidth+"] = {"+String.FromChar(10)
- For Local y:Int=spriteheight-1 to 0 Step -1
- Local a:String
- For Local x:Int=0 Until spritewidth
- a+=map[x,y]+","
- Next
- Local l:Int=a.Length
- a=a.Slice(0,a.Length-1)
- out += "{"+a+"},"+String.FromChar(10)
- Next
- out=out.Slice(0,out.Length-2)
- out+="};"
- instance.ClipboardText = out
- */
- // Here we create a copy and paste ready
- // text that can be pasted into a code editor.
- // It shows how to convert a array into c language code.
- char output1[1000] = "int sprite[";
- char output2[32];
- sprintf(output2, "%d", spritewidth);
- strcat(output1,output2);
- strcat(output1,"][");
- sprintf(output2, "%d", spriteheight);
- strcat(output1,output2);
- strcat(output1,"] = {\n");
-
- int x=0;int y=0;
- for (y=0;y<spriteheight;y++){
- for(x=0;x<spritewidth-1;x++){
- if(x==0)strcat(output1,"{");
- char num[16];
- sprintf(num, "%d", map[y][x]);
- strcat(output1,num);
- strcat(output1,",");
- }
- char num2[16];
- sprintf(num2, "%d", map[y][spritewidth-1]);
- strcat(output1,num2);
- if(y<spriteheight-1){
- strcat(output1,"},\n");
- }else{
- strcat(output1,"}};\n");
- }
- }
- SetClipboardText(output1);
- }
- void tilemapview(){
- // canvas.Color = Color.Black
- // canvas.DrawRect(tilemapx,tilemapy,tilemapwidth,tilemapheight)
- DrawRectangle(tilemapx,tilemapy,tilemapwidth,tilemapheight,BLACK);
- // canvas.Color = Color.White
-
- for(int y=0; y<tilemaptilesscreenvertical;y++){
- for(int x=0; x<tilemaptilesscreenhorizontal;x++){
- int pointx=(x*spritewidth*spritelibscale)+tilemapx;
- int pointy=(y*spriteheight*spritelibscale)+tilemapy;
- //canvas.DrawImage(spritelibim[tilemap[x,y]],pointx,pointy)
- //DrawTexture(spritelibim[tilemap[x][y]].texture,pointx,pointy,WHITE);
- DrawTextureRec( spritelibim[tilemap[x][y]].texture,
- (Rectangle){ 0, 0,
- spritelibim[tilemap[x][y]].texture.width,
- -spritelibim[tilemap[x][y]].texture.height },
- (Vector2){pointx,pointy}, WHITE);
- }}
-
- if(IsMouseButtonDown(0)){
- if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,tilemapx,tilemapy,tilemapwidth,tilemapheight)){
- int x=(GetMouseX()-tilemapx) / (spritewidth*spritelibscale);
- int y=(GetMouseY()-tilemapy) / (spriteheight*spritelibscale);
- if(x<0 || y<0 || x>=tilemaptileshorizontal || y>=tilemaptilesvertical){
- }else{
- tilemap[x][y] = spritelibselected;
- }
- }
- }
-
- // Tab back to sprite view
- if(IsKeyReleased(KEY_TAB)){
- topbarcurrentid = topbarspriteeditid;
- }
- }
- void fillatposition(int x, int y,int oldcolor,int newcolor)
- {
- if(x<0 || x>=10 || y<0 || y>=10)return;
- if(map[x][y] == oldcolor){
- map[x][y] = newcolor;
- fillatposition(x-1,y,oldcolor,newcolor);
- fillatposition(x+1,y,oldcolor,newcolor);
- fillatposition(x,y-1,oldcolor,newcolor);
- fillatposition(x,y+1,oldcolor,newcolor);
- return;
- }
- }
- /*
- Method fillatposition(x:Int,y:Int)
- Local ol:List<pathnode> = New List<pathnode>
- ' Add the start position on the list
- ol.AddLast(New pathnode(x,y))
- ' set the cloes map at the start position to distance 1
- Local colorundermouse:Int=map[x,y]
- map[x,y] = paletteselected
-
- ' some helper arrays. We can determine the top,right,and bottom
- ' and left position cells with these numbers.
- Local dx:Int[] = New Int[](0,1,0,-1)
- Local dy:Int[] = New Int[](-1,0,1,0)
- ' While there is contents in the list
- While ol.Count() <> 0
-
- ' Get the current location
- Local x1:Int=ol.First.x
- Local y1:Int=ol.First.y
- ' Remove the current location from the list
- ol.RemoveFirst()
- ' Get 4 new positions around the current positions
- For Local i:=0 Until 4
- ' Set new x and y
- Local nx:Int=x1+dx[i]
- Local ny:Int=y1+dy[i]
- ' If the coordinates are inside the map
- If nx>=0 And ny>=0 And nx<spritewidth And ny<spriteheight
- ' If the closedmap is not written to yet
- If map[nx,ny] = colorundermouse And map[nx,ny] <> paletteselected
- ' Set the new distance based on the current distance
- map[nx,ny] = paletteselected
- ' Add new position to the list
- ol.AddLast(New pathnode(nx,ny))
- End If
- End If
- Next
- Wend
-
- End Method
- */
- // For creating ovals(circles)
- //
- void midptellipse(int rx, int ry,
- int xc, int yc){
- // Erase the tempmap array.
- for(int y=0;y<32;y++){
- for(int x=0;x<32;x++){
- tempmap[x][y] = 0;
- }
- }
- float dx, dy, d1, d2, x, y;
- x = 0;
- y = ry;
-
- // Initial decision parameter of region 1
- d1 = (ry * ry) - (rx * rx * ry) +
- (0.25 * rx * rx);
- dx = 2 * ry * ry * x;
- dy = 2 * rx * rx * y;
-
- // For region 1
- while (dx < dy)
- {
-
- // Print points based on 4-way symmetry
- int tx[4] = {x+xc,-x+xc,x+xc,-x+xc};
- int ty[4] = {y+yc,y+yc,-y+yc,-y+yc};
- for(int i=0;i<4;i++){
- if(tx[i]>=0 && tx[i]<32 && ty[i]>=0 && ty[i]<32)tempmap[tx[i]][ty[i]] = 1;
- }
- // Checking and updating value of
- // decision parameter based on algorithm
- if (d1 < 0)
- {
- x++;
- dx = dx + (2 * ry * ry);
- d1 = d1 + dx + (ry * ry);
- }
- else
- {
- x++;
- y--;
- dx = dx + (2 * ry * ry);
- dy = dy - (2 * rx * rx);
- d1 = d1 + dx - dy + (ry * ry);
- }
- }
-
- // Decision parameter of region 2
- d2 = ((ry * ry) * ((x + 0.5) * (x + 0.5))) +
- ((rx * rx) * ((y - 1) * (y - 1))) -
- (rx * rx * ry * ry);
-
- // Plotting points of region 2
- while (y >= 0)
- {
-
- int tx[4] = {x+xc,-x+xc,x+xc,-x+xc};
- int ty[4] = {y+yc,y+yc,-y+yc,-y+yc};
- for(int i=0;i<4;i++){
- if(tx[i]>=0 && tx[i]<32 && ty[i]>=0 && ty[i]<32)tempmap[tx[i]][ty[i]] = 1;
- }
- // Checking and updating parameter
- // value based on algorithm
- if (d2 > 0)
- {
- y--;
- dy = dy - (2 * rx * rx);
- d2 = d2 + (rx * rx) - dy;
- }
- else
- {
- y--;
- x++;
- dx = dx + (2 * ry * ry);
- dy = dy - (2 * rx * rx);
- d2 = d2 + dx - dy + (rx * rx);
- }
- }
- }
- bool rectsoverlap(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2){
- if((x1 >= (x2 + w2) || (x1 + w1) <= x2))return false;
- if((y1 >= (y2 + h2) || (y1 + h1) <= y2))return false;
- return true;
- }
- bool circlerectcollide(int cx,int cy,int cr,int rx,int ry,int rw,int rh){
-
- float closestx = Clamp(cx, rx, rx+rw);
- float closesty = Clamp(cy, ry, ry+rh);
- float distancex = cx - closestx;
- float distancey = cy - closesty;
- float distancesquared = (distancex * distancex) + (distancey * distancey);
- return distancesquared < (cr * cr);
- }
- // Clamp float value
- float Clamp(float value, float min, float max)
- {
- const float res = value < min ? min : value;
- return res > max ? max : res;
- }
- void copyfromclipboard(){
- for(int y=0;y<32;y++){
- for(int x=0;x<32;x++){
- tempmap[x][y]=0;
- }
- }
- // Create a char to read the clipboard with.
- char clipBoardTxt[10024];
- // Create a pointer to the clipboardtxt char
- const char *clipPointer = clipBoardTxt;
- // Read the contents of the clipboard into the clipboardtxt pointer
- clipPointer = GetClipboardText();
- // create a char
- char work[1024];
-
- if(strlen(clipPointer)<1000){
- // copy the contents of the char that has a pointer containing the clipboard txt into this work char
- strcpy(work,clipPointer);
- }
- // count the comma's and the numbers.
- // int numCommas = countcommas(work);
- int numNumbers = countnumbers(work);
- if(importspriteis8x8(numNumbers)){
- readtempsprite(8,8,work);
-
- //create8x8sprite();
- }
- }
- void readtempsprite(int w,int h,char *in){
- int cnt=0;
- int x=0;
- int y=0;
- bool insidearray=false;
- int cnt2=0;
- for(int i=0;in[i];i++){
-
- if(cnt2<2 && in[i]=='{')cnt2++;
- if(cnt2>=1)insidearray=true;
-
- if(insidearray && in[i] >= '0' && in[i] <='9'){
-
- int z=0;
- int num=0;
- char charnum[14]="";
-
- //while(in[i]!=','){
- do{
- charnum[z]=in[i];
- i++;
- z++;
- if(i+1>=strlen(in))break;//no longer numbers than 3
- }while(in[i]!=',');
-
- num = atoi(charnum);
-
- cnt++;
- if(cnt>1){
- y++;
- if(y>=h){
- y=0;
- x++;
- }
- }
-
- if(num>=numpalette)num=0;
- //tempsprite[x][y] = num;//in[i]-'0';
- map[x][y] = num;//in[i]-'0';
- //if(num>15)map[x][y]=0;
- }
- }
- }
- int countcommas(char *in){
- int out=0;
- for(int i=0;in[i];i++){
- if(in[i] == ',')out++;
- }
- return out;
- }
- int countnumbers(char *in){
- int out=0;
- for(int i=0;in[i];i++){
- if(in[i] >= '0' && in[i] <= '9'){
- while(in[i] >= '0' && in[i] <= '9' && i<strlen(in)){
- i++;
- }
- out++;
- }
- }
- return out;
- }
- bool importspriteis8x8(int in){
- if(in-2 == 8*8)return true;
- return false;
- }
- bool importspriteis16x16(int in){
- if(in-2 == 16*16)return true;
- return false;
- }
- bool importspriteis32x32(int in){
- if(in-2 == 32*32)return true;
- return false;
- }
|