public void MoveFrameDown(int currentIndex) { PIAFrame tmp = frames[currentIndex + 1]; frames[currentIndex + 1] = frames[currentIndex]; frames[currentIndex] = tmp; }
public void MoveFrameUp(int currentIndex) { PIAFrame tmp = frames[currentIndex - 1]; frames[currentIndex - 1] = frames[currentIndex]; frames[currentIndex] = tmp; }
public PIAFrame AddFrame() { PIAFrame frame = new PIAFrame(); frame.Init(this); frames.Add(frame); CurrentFrameIndex = frames.Count - 1; return(frame); }
public void CopyFrom(PIAFrame source) { textures.Clear(); foreach (var item in source.textures) { byte[] itemData = item.Texture.EncodeToPNG(); PIATexture piaTexture = AddTexture(); piaTexture.LayerIndex = item.LayerIndex; Texture2D texture = piaTexture.Texture; texture.LoadImage(itemData); texture.Apply(); } }
public void OnGUIExecute(Event e, Vector2 pixelCoordinate) { // mouse is outside the grid if (pixelCoordinate.x < 0 || pixelCoordinate.y < 0) { return; } // this is used to preview where we are going to draw PIATexture helper = PIAEditorWindow.Instance.SelectionTexture; PIAFrame frame = PIASession.Instance.ImageData.CurrentFrame; int width = PIASession.Instance.ImageData.Width; int height = PIASession.Instance.ImageData.Height; // tools state machine switch (ToolType) { case PIAToolType.Paint: if (e.type == EventType.MouseDown || e.type == EventType.MouseDrag) { if (e.button == 0) { frame.GetCurrentImage().Paint((int)pixelCoordinate.x, height - (int)pixelCoordinate.y - 1, FirstColor); Debug.Log(frame.GetCurrentImage().Texture.width + "," + frame.GetCurrentImage().Texture.height); } if (e.button == 1) { frame.GetCurrentImage().Paint((int)pixelCoordinate.x, height - (int)pixelCoordinate.y - 1, SecondColor); } } else { helper.Paint((int)pixelCoordinate.x, height - (int)pixelCoordinate.y - 1, new Color(Color.black.r, Color.black.g, Color.black.b, 0.2f), false, true, false); } break; case PIAToolType.Erase: if (e.type == EventType.MouseDown || e.type == EventType.MouseDrag) { frame.GetCurrentImage().Paint((int)pixelCoordinate.x, height - (int)pixelCoordinate.y - 1, ClearColor); } else { helper.Paint((int)pixelCoordinate.x, height - (int)pixelCoordinate.y - 1, new Color(Color.white.r, Color.white.g, Color.white.b, 0.5f), false, true, false); } break; case PIAToolType.Rectangle: if (e.type == EventType.MouseDown) { downPoint = new Vector2((int)pixelCoordinate.x, (int)pixelCoordinate.y); if (e.button == 0) { DrawRectangle(helper, downPoint, pixelCoordinate, new Color(FirstColor.r, FirstColor.g, FirstColor.b, 0.5f)); } if (e.button == 1) { DrawRectangle(helper, downPoint, pixelCoordinate, new Color(SecondColor.r, SecondColor.g, SecondColor.b, 0.5f)); } } if (e.type == EventType.MouseDrag) { if (e.button == 0) { DrawRectangle(helper, downPoint, pixelCoordinate, new Color(FirstColor.r, FirstColor.g, FirstColor.b, 0.5f)); } if (e.button == 1) { DrawRectangle(helper, downPoint, pixelCoordinate, new Color(SecondColor.r, SecondColor.g, SecondColor.b, 0.5f)); } } if (e.type == EventType.MouseUp) { upPoint = new Vector2((int)pixelCoordinate.x, (int)pixelCoordinate.y); if (e.button == 0) { DrawRectangle(frame.GetCurrentImage(), downPoint, upPoint, FirstColor); } if (e.button == 1) { DrawRectangle(frame.GetCurrentImage(), downPoint, upPoint, SecondColor); } helper.ClearTexture(true); } break; case PIAToolType.RectangleFilled: if (e.type == EventType.MouseDown) { downPoint = new Vector2((int)pixelCoordinate.x, (int)pixelCoordinate.y); if (e.button == 0) { DrawFilledRectangle(helper, downPoint, pixelCoordinate, new Color(FirstColor.r, FirstColor.g, FirstColor.b, 0.5f)); } if (e.button == 1) { DrawFilledRectangle(helper, downPoint, pixelCoordinate, new Color(SecondColor.r, SecondColor.g, SecondColor.b, 0.5f)); } } if (e.type == EventType.MouseDrag) { if (e.button == 0) { DrawFilledRectangle(helper, downPoint, pixelCoordinate, new Color(FirstColor.r, FirstColor.g, FirstColor.b, 0.5f)); } if (e.button == 1) { DrawFilledRectangle(helper, downPoint, pixelCoordinate, new Color(SecondColor.r, SecondColor.g, SecondColor.b, 0.5f)); } } if (e.type == EventType.MouseUp) { upPoint = new Vector2((int)pixelCoordinate.x, (int)pixelCoordinate.y); if (e.button == 0) { DrawFilledRectangle(frame.GetCurrentImage(), downPoint, upPoint, FirstColor); } if (e.button == 1) { DrawFilledRectangle(frame.GetCurrentImage(), downPoint, upPoint, SecondColor); } helper.ClearTexture(true); } break; case PIAToolType.Selection: if (e.type == EventType.MouseDown) { downPoint = new Vector2((int)pixelCoordinate.x, (int)pixelCoordinate.y); DrawFilledRectangle(helper, downPoint, pixelCoordinate, new Color(Color.cyan.r, Color.cyan.g, Color.cyan.b, 0.5f)); } if (e.type == EventType.MouseDrag) { selectedRect = DrawFilledRectangle(helper, downPoint, pixelCoordinate, new Color(Color.cyan.r, Color.cyan.g, Color.cyan.b, 0.5f)); } if (e.keyCode == KeyCode.Delete) { ClearRect(frame.GetCurrentImage(), selectedRect); helper.ClearTexture(true); } break; case PIAToolType.Dithering: if ((pixelCoordinate.x + pixelCoordinate.y) % 2 == 1) { helper.Paint((int)pixelCoordinate.x, height - (int)pixelCoordinate.y - 1, new Color(Color.red.r, Color.red.g, Color.red.b, 0.2f), false, true, false); return; } if (e.type == EventType.MouseDown || e.type == EventType.MouseDrag) { if (e.button == 0) { frame.GetCurrentImage().Paint((int)pixelCoordinate.x, height - (int)pixelCoordinate.y - 1, FirstColor); } if (e.button == 1) { frame.GetCurrentImage().Paint((int)pixelCoordinate.x, height - (int)pixelCoordinate.y - 1, SecondColor); } } else { helper.Paint((int)pixelCoordinate.x, height - (int)pixelCoordinate.y - 1, new Color(Color.black.r, Color.black.g, Color.black.b, 0.2f), false, true, false); } break; } }
private void DrawFrames(Rect parent) { PIAImageData imageData = PIASession.Instance.ImageData; Vector2 offset = new Vector2(20, 20); Vector2 bgSize = new Vector2(15, 15); // FRAME RECT float frameRectPositionX = offset.x; float frameRectPositionY = offset.y; float frameRectWidth = 100; float frameRectHeight = frameRectWidth; float spaceBetweenFrames = 25; // FRAME INDEX RECT float frameNumberRectWidth = 22; float frameNumberRectHeight = 22; // DELETE RECT float deleteFrameRectWidth = 32; float deleteFrameRectHeight = 32; Vector2 deleteFrameRectOffset = new Vector2(2, 2); // DUPLICATE RECT float duplicateFrameRectWidth = 32; float duplicateFrameRectHeight = 32; Vector2 duplicateFrameRectOffset = new Vector2(2, 2); // MOVE UP RECT float moveFrameUpRectWidth = 32; float moveFrameUpRectHeight = 32; Vector2 moveFrameUpRectOffset = new Vector2(2, 2); // MOVE DOWN RECT float moveFrameDownRectWidth = 32; float moveFrameDownRectHeight = 32; Vector2 moveFrameDownRectOffset = new Vector2(2, 2); // ADD FRAME RECT float addFrameIconRectWidth = 40; float addFrameIconRectHeight = 40; // SCROLL VIEW RECT Rect viewRect = new Rect(0, 0, parent.width, (frameRectHeight + spaceBetweenFrames) * (imageData.Frames.Count + 1) + offset.y); Rect sliderRect = new Rect(0, 0, parent.width, parent.height - offset.y); // caching and changing default gui skins for scroll view GUIStyle nativeVerticalScrollbarThumb = GUI.skin.verticalScrollbarThumb; GUI.skin.verticalScrollbarThumb.normal.background = PIATextureDatabase.Instance.GetTexture("empty"); GUIStyle nativeVerticalScrollbarDownButton = GUI.skin.verticalScrollbarDownButton; GUI.skin.verticalScrollbarDownButton.normal.background = PIATextureDatabase.Instance.GetTexture("empty"); GUIStyle nativeVerticalScrollbarUpButton = GUI.skin.verticalScrollbarUpButton; GUI.skin.verticalScrollbarUpButton.normal.background = PIATextureDatabase.Instance.GetTexture("empty"); // DRAWING FRAMES framesSlider = GUI.BeginScrollView(sliderRect, framesSlider, viewRect, false, false, skin.GetStyle("horizontalscrollbar"), skin.GetStyle("verticalscrollbar")); { for (int i = 0; i < imageData.Frames.Count; i++) { var item = imageData.Frames[i]; // refreshing rects Rect frameRect = new Rect(frameRectPositionX, frameRectPositionY, frameRectWidth, frameRectHeight); Rect frameBGRect = new Rect(frameRect.x - bgSize.x / 2, frameRect.y - bgSize.y / 2, frameRect.width + bgSize.x, frameRect.height + bgSize.y); Rect frameNumberBGRect = new Rect(frameBGRect.xMax, frameBGRect.center.y - frameNumberRectHeight / 2, frameNumberRectWidth, frameNumberRectHeight); Rect deleteFrameRect = new Rect(frameRect.xMax - deleteFrameRectWidth - deleteFrameRectOffset.x, frameRect.y + deleteFrameRectOffset.y, deleteFrameRectWidth, deleteFrameRectHeight); Rect duplicateFrameRect = new Rect(frameRect.xMax - duplicateFrameRectWidth - duplicateFrameRectOffset.x, frameRect.yMax - duplicateFrameRectOffset.y - duplicateFrameRectHeight, duplicateFrameRectWidth, duplicateFrameRectHeight); Rect moveFrameUpFrameRect = new Rect(frameRect.x + moveFrameUpRectOffset.x, frameRect.y + moveFrameUpRectOffset.y, moveFrameUpRectWidth, moveFrameUpRectHeight); Rect moveFrameDownFrameRect = new Rect(frameRect.x + moveFrameDownRectOffset.x, frameRect.yMax - moveFrameDownRectOffset.y - moveFrameDownRectHeight, moveFrameDownRectWidth, moveFrameDownRectHeight); // INDEX NUMBER GUI.DrawTexture(frameNumberBGRect, blackBarBG); GUI.Label(frameNumberBGRect, i.ToString(), skin.GetStyle("editorbutton2")); // BG GUI.DrawTexture(frameBGRect, blackBarBG); // FRAME CONTENT EditorGUI.DrawTextureTransparent(frameRect, imageData.Frames[i].GetFrameTexture()); if (PIAInputArea.IsMouseInsideRect(frameBGRect)) { if (imageData.Frames.Count > 1) { // DELETE if (GUI.Button(deleteFrameRect, GUIContent.none, skin.GetStyle("deleteframe"))) { PIASession.Instance.ImageData.RemoveFrame(i); } Rect deleteFrameGlobalRect = PIATooltipUtility.ChildToGlobalRect(deleteFrameRect, parent); Rect deleteFrameTooltipRect = new Rect(0, 0, 50, 22.5f); PIATooltip deleteFrameTooltip = new PIATooltip(deleteFrameTooltipRect, "Delete"); PIATooltip.SetPositionPreset(ref deleteFrameTooltip, deleteFrameGlobalRect, PIATooltip.PIATooltipPreset.Right); PIATooltipUtility.AddTooltip(deleteFrameGlobalRect, deleteFrameTooltip); } // DUPLICATE if (GUI.Button(duplicateFrameRect, GUIContent.none, skin.GetStyle("copyframe"))) { PIAFrame newFrame = PIASession.Instance.ImageData.AddFrame(); newFrame.CopyFrom(item); } Rect duplicateFrameGlobalRect = PIATooltipUtility.ChildToGlobalRect(duplicateFrameRect, parent); Rect duplicateFrameTooltipRect = new Rect(0, 0, 75, 22.5f); PIATooltip duplicateFrameTooltip = new PIATooltip(duplicateFrameTooltipRect, "Duplicate"); PIATooltip.SetPositionPreset(ref duplicateFrameTooltip, duplicateFrameGlobalRect, PIATooltip.PIATooltipPreset.Up); PIATooltipUtility.AddTooltip(duplicateFrameGlobalRect, duplicateFrameTooltip); // MOVE UP if (i > 0) { if (GUI.Button(moveFrameUpFrameRect, GUIContent.none, skin.GetStyle("moveframup"))) { imageData.MoveFrameUp(i); } Rect moveFrameUpGlobalRect = PIATooltipUtility.ChildToGlobalRect(moveFrameUpFrameRect, parent); Rect moveFrameUpTooltipRect = new Rect(0, 0, 75, 22.5f); PIATooltip moveFrameUpTooltip = new PIATooltip(moveFrameUpTooltipRect, "Move up"); PIATooltip.SetPositionPreset(ref moveFrameUpTooltip, moveFrameUpGlobalRect, PIATooltip.PIATooltipPreset.Left); PIATooltipUtility.AddTooltip(moveFrameUpGlobalRect, moveFrameUpTooltip); } // MOVE DOWN if (i < imageData.Frames.Count - 1) { if (GUI.Button(moveFrameDownFrameRect, GUIContent.none, skin.GetStyle("moveframedown"))) { imageData.MoveFrameDown(i); } Rect moveFrameDownGlobalRect = PIATooltipUtility.ChildToGlobalRect(moveFrameDownFrameRect, parent); Rect moveFrameDownTooltipRect = new Rect(0, 0, 90, 22.5f); PIATooltip moveFrameDownTooltip = new PIATooltip(moveFrameDownTooltipRect, "Move down"); PIATooltip.SetPositionPreset(ref moveFrameDownTooltip, moveFrameDownGlobalRect, PIATooltip.PIATooltipPreset.Left); PIATooltipUtility.AddTooltip(moveFrameDownGlobalRect, moveFrameDownTooltip); } } // FRAME SELECTION BG if (GUI.Button(frameBGRect, GUIContent.none, skin.GetStyle("bglayerbutton"))) { PIASession.Instance.ImageData.CurrentFrameIndex = i; } frameRectPositionY += frameRectHeight + spaceBetweenFrames; // FRAME SELECTION OVERLAY if (i == PIASession.Instance.ImageData.CurrentFrameIndex) { GUI.Label(frameBGRect, GUIContent.none, skin.GetStyle("selectedframeoverlay")); } } // ADD NEW FRAME Rect addFrameRect = new Rect(frameRectPositionX, frameRectPositionY, frameRectWidth, frameRectHeight); Rect addFrameBGRect = new Rect(addFrameRect.x - bgSize.x / 2, addFrameRect.y - bgSize.y / 2, addFrameRect.width + bgSize.x, addFrameRect.height + bgSize.y); Rect addFrameBGLabelIcon = new Rect(addFrameRect.center.x - addFrameIconRectWidth / 2, addFrameRect.center.y - addFrameIconRectHeight / 2, addFrameIconRectWidth, addFrameIconRectHeight); GUI.DrawTexture(addFrameBGRect, blackBarBG); GUI.Label(addFrameBGLabelIcon, GUIContent.none, skin.GetStyle("addframe")); if (GUI.Button(addFrameRect, GUIContent.none, skin.GetStyle("bglayerbutton"))) { PIASession.Instance.ImageData.AddFrame(); } frameRectPositionY += frameRectHeight + spaceBetweenFrames; } GUI.EndScrollView(); // resetting scroll view gui skin GUI.skin.verticalScrollbarThumb = nativeVerticalScrollbarThumb; GUI.skin.verticalScrollbarDownButton = nativeVerticalScrollbarDownButton; GUI.skin.verticalScrollbarUpButton = nativeVerticalScrollbarUpButton; }