瀏覽代碼

Update spriteeditor.c

Rudy Boudewijn van Etten 5 年之前
父節點
當前提交
5083af350f
共有 1 個文件被更改,包括 26 次插入7 次删除
  1. 26 7
      SpriteEditor/spriteeditor.c

+ 26 - 7
SpriteEditor/spriteeditor.c

@@ -5,7 +5,7 @@
 //
 //
 // Added - Save eveything (F5) Load everything(F6 - Very slow!!)
 // 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 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.
 // 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. 
 // Todo : Add isometric/hexagon map edit/view, Fix update preview and spritelib), Floodfill(more testing),  ovals!(find solution for layout), testing. 
@@ -111,6 +111,7 @@ static	float gridwidth;
 static  float gridheight;//	 ' grids width and height
 static  float gridheight;//	 ' grids width and height
 static	int spritewidth;
 static	int spritewidth;
 static  int spriteheight;// ' our main sprite width and height
 static  int spriteheight;// ' our main sprite width and height
+static bool spriteviewaction=false;
 	//' line tool fields
 	//' line tool fields
 static	bool linepressed=false;
 static	bool linepressed=false;
 static	bool lineactive=false;
 static	bool lineactive=false;
@@ -833,7 +834,7 @@ void middlebarview(){
         //canvas.DrawImage(middlebarim[num],pointx,pointy)
         //canvas.DrawImage(middlebarim[num],pointx,pointy)
         //'
         //'
         //' Selection of the sprite editor or the map editor
         //' Selection of the sprite editor or the map editor
-        if(IsMouseButtonDown(0)){
+        if(spriteviewaction==false && IsMouseButtonDown(0)){
             if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,32,32)){
             if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,32,32)){
                 middlebarcurrentid = num;
                 middlebarcurrentid = num;
             }
             }
@@ -988,7 +989,7 @@ void topbarview(){
         //canvas.DrawImage(topbarim[num],pointx,pointy,0,.6,.6)
         //canvas.DrawImage(topbarim[num],pointx,pointy,0,.6,.6)
         //'
         //'
         //' Selection of the sprite editor or the map editor
         //' Selection of the sprite editor or the map editor
-        if(IsMouseButtonDown(0)){
+        if(spriteviewaction==false && IsMouseButtonDown(0)){
             if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,32,32)){
             if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,32,32)){
                 topbarcurrentid = num;
                 topbarcurrentid = num;
             }
             }
@@ -1036,7 +1037,7 @@ void paletteview(){
         }
         }
         //'
         //'
         //' Select our color
         //' Select our color
-        if(IsMouseButtonDown(0)){				
+        if(spriteviewaction==false && IsMouseButtonDown(0)){				
             if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,palettecellwidth,palettecellheight)){
             if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,palettecellwidth,palettecellheight)){
                 paletteselected = cc;
                 paletteselected = cc;
             }
             }
@@ -1404,7 +1405,7 @@ void toolview(){
         //'
         //'
         //'/ Interaction with the tool area
         //'/ Interaction with the tool area
         //'
         //'
-        if(IsMouseButtonDown(0)){
+        if(spriteviewaction==false && IsMouseButtonDown(0)){
             if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,32,32)){
             if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,32,32)){
                 toolselected = num;
                 toolselected = num;
 
 
@@ -1548,7 +1549,7 @@ void spritelibview(){
 
 
 
 
         
         
-        if(IsMouseButtonDown(0)){
+        if(spriteviewaction==false && IsMouseButtonDown(0)){
             if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,spritewidth*spritelibscale,spriteheight*spritelibscale)){
             if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,spritewidth*spritelibscale,spriteheight*spritelibscale)){
                 spritelibselected = num;
                 spritelibselected = num;
                 spritelibcopytocanvas();
                 spritelibcopytocanvas();
@@ -1565,7 +1566,14 @@ void spritelibview(){
 
 
 
 
 void spriteview(){
 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 y=0;y<spriteheight;y++){
     for(int x=0;x<spritewidth;x++){
     for(int x=0;x<spritewidth;x++){
@@ -1848,6 +1856,12 @@ void spriteview(){
                 }
                 }
             }
             }
         }
         }
+
+        // Tab between map view and sprite view.
+        if(IsKeyReleased(KEY_TAB)){
+            spriteviewaction = false;
+            topbarcurrentid = topbarmapeditid;
+        }
        
        
         //' Read from disk..
         //' Read from disk..
         if(IsKeyReleased(KEY_F6)){
         if(IsKeyReleased(KEY_F6)){
@@ -2244,6 +2258,11 @@ void tilemapview(){
             }
             }
         }
         }
     }
     }
+    
+    // Tab back to sprite view
+    if(IsKeyReleased(KEY_TAB)){
+        topbarcurrentid = topbarspriteeditid;
+    }
 }
 }