public TransformChangeCropResampling(string name, int layerIndex, TextureBitmap.CropMode previousCrop, ResamplingFilters previousSampling, TextureBitmap.CropMode newCrop, ResamplingFilters newSampling) : base(name) { this.LayerIndex = layerIndex; this.PreviousCrop = previousCrop; this.PreviousSampling = previousSampling; this.NewCrop = newCrop; this.NewSampling = newSampling; }
public SmartObjectLayer(SubPattern pattern, string name, TextureBitmap bitmap, int x, int y, int width, int height) : base(pattern, name) { Crop = TextureBitmap.CropMode.Scale; Resampler = ResamplingFilters.Box; Bitmap = bitmap; _ObjectX = x; _ObjectY = y; _ObjectWidth = width; _ObjectHeight = height; }
public void UpdateColors() { if (_PreviousWidth != _ObjectWidth || _PreviousHeight != _ObjectHeight || _PreviousCrop != Crop || _PreviousResampler != Resampler) { Texture.CopyFrom(Bitmap); Texture.ResampleAndCrop(this.Resampler, this.Crop, _ObjectWidth, _ObjectHeight); UpdateTexture(); _PreviousWidth = _ObjectWidth; _PreviousHeight = _ObjectHeight; _PreviousCrop = Crop; _PreviousResampler = Resampler; } }
public void SwitchTool(Tool tool) { if (tool == Tool.CropNone) { if (Editor.CurrentPattern.CurrentSubPattern.SelectedLayer is SmartObjectLayer sml) { TextureBitmap.CropMode old = sml.GetCrop(); if (old != TextureBitmap.CropMode.Scale) { sml.ChangeCrop(TextureBitmap.CropMode.Scale); sml.UpdateColors(); sml.UpdateTexture(); UpdateTransformSettings(sml); Editor.CurrentPattern.CurrentSubPattern.UpdateImage(); Editor.CurrentPattern.CurrentSubPattern.History.AddEvent(new History.TransformChangeCropResampling("Changed crop", Editor.CurrentPattern.CurrentSubPattern.Layers.IndexOf(sml), old, sml.GetResampling(), TextureBitmap.CropMode.Scale, sml.GetResampling())); } } return; } if (tool == Tool.CropFit) { if (Editor.CurrentPattern.CurrentSubPattern.SelectedLayer is SmartObjectLayer sml) { TextureBitmap.CropMode old = sml.GetCrop(); if (old != TextureBitmap.CropMode.Fit) { sml.ChangeCrop(TextureBitmap.CropMode.Fit); sml.UpdateColors(); sml.UpdateTexture(); UpdateTransformSettings(sml); Editor.CurrentPattern.CurrentSubPattern.UpdateImage(); Editor.CurrentPattern.CurrentSubPattern.History.AddEvent(new History.TransformChangeCropResampling("Changed crop", Editor.CurrentPattern.CurrentSubPattern.Layers.IndexOf(sml), old, sml.GetResampling(), TextureBitmap.CropMode.Fit, sml.GetResampling())); } } return; } if (tool == Tool.CropCover) { if (Editor.CurrentPattern.CurrentSubPattern.SelectedLayer is SmartObjectLayer sml) { TextureBitmap.CropMode old = sml.GetCrop(); if (old != TextureBitmap.CropMode.Cover) { sml.ChangeCrop(TextureBitmap.CropMode.Cover); sml.UpdateColors(); sml.UpdateTexture(); UpdateTransformSettings(sml); Editor.CurrentPattern.CurrentSubPattern.UpdateImage(); Editor.CurrentPattern.CurrentSubPattern.History.AddEvent(new History.TransformChangeCropResampling("Changed crop", Editor.CurrentPattern.CurrentSubPattern.Layers.IndexOf(sml), old, sml.GetResampling(), TextureBitmap.CropMode.Cover, sml.GetResampling())); } } return; } if (tool == Tool.SamplingBox) { if (Editor.CurrentPattern.CurrentSubPattern.SelectedLayer is SmartObjectLayer sml) { ResamplingFilters old = sml.GetResampling(); if (old != ResamplingFilters.Box) { sml.ChangeResampling(ResamplingFilters.Box); sml.UpdateColors(); sml.UpdateTexture(); UpdateTransformSettings(sml); Editor.CurrentPattern.CurrentSubPattern.UpdateImage(); Editor.CurrentPattern.CurrentSubPattern.History.AddEvent(new History.TransformChangeCropResampling("Changed sampling", Editor.CurrentPattern.CurrentSubPattern.Layers.IndexOf(sml), sml.GetCrop(), old, sml.GetCrop(), ResamplingFilters.Box)); } } return; } if (tool == Tool.SamplingLanczos8) { if (Editor.CurrentPattern.CurrentSubPattern.SelectedLayer is SmartObjectLayer sml) { ResamplingFilters old = sml.GetResampling(); if (old != ResamplingFilters.Lanczos8) { sml.ChangeResampling(ResamplingFilters.Lanczos8); sml.UpdateColors(); sml.UpdateTexture(); UpdateTransformSettings(sml); Editor.CurrentPattern.CurrentSubPattern.UpdateImage(); Editor.CurrentPattern.CurrentSubPattern.History.AddEvent(new History.TransformChangeCropResampling("Changed sampling", Editor.CurrentPattern.CurrentSubPattern.Layers.IndexOf(sml), sml.GetCrop(), old, sml.GetCrop(), ResamplingFilters.Lanczos8)); } } return; } if (tool == Tool.SamplingMitchell) { if (Editor.CurrentPattern.CurrentSubPattern.SelectedLayer is SmartObjectLayer sml) { ResamplingFilters old = sml.GetResampling(); if (old != ResamplingFilters.Mitchell) { sml.ChangeResampling(ResamplingFilters.Mitchell); sml.UpdateColors(); sml.UpdateTexture(); UpdateTransformSettings(sml); Editor.CurrentPattern.CurrentSubPattern.UpdateImage(); Editor.CurrentPattern.CurrentSubPattern.History.AddEvent(new History.TransformChangeCropResampling("Changed sampling", Editor.CurrentPattern.CurrentSubPattern.Layers.IndexOf(sml), sml.GetCrop(), old, sml.GetCrop(), ResamplingFilters.Mitchell)); } } return; } if (tool == Tool.SamplingCosine) { if (Editor.CurrentPattern.CurrentSubPattern.SelectedLayer is SmartObjectLayer sml) { ResamplingFilters old = sml.GetResampling(); if (old != ResamplingFilters.Cosine) { sml.ChangeResampling(ResamplingFilters.Cosine); sml.UpdateColors(); sml.UpdateTexture(); UpdateTransformSettings(sml); Editor.CurrentPattern.CurrentSubPattern.UpdateImage(); Editor.CurrentPattern.CurrentSubPattern.History.AddEvent(new History.TransformChangeCropResampling("Changed sampling", Editor.CurrentPattern.CurrentSubPattern.Layers.IndexOf(sml), sml.GetCrop(), old, sml.GetCrop(), ResamplingFilters.Cosine)); } } return; } if (tool == Tool.SamplingCubicConvolution) { if (Editor.CurrentPattern.CurrentSubPattern.SelectedLayer is SmartObjectLayer sml) { ResamplingFilters old = sml.GetResampling(); if (old != ResamplingFilters.CubicConvolution) { sml.ChangeResampling(ResamplingFilters.CubicConvolution); sml.UpdateColors(); sml.UpdateTexture(); UpdateTransformSettings(sml); Editor.CurrentPattern.CurrentSubPattern.UpdateImage(); Editor.CurrentPattern.CurrentSubPattern.History.AddEvent(new History.TransformChangeCropResampling("Changed sampling", Editor.CurrentPattern.CurrentSubPattern.Layers.IndexOf(sml), sml.GetCrop(), old, sml.GetCrop(), ResamplingFilters.CubicConvolution)); } } return; } if (CurrentTool != Tool.None) { ToolImages[CurrentTool].color = new UnityEngine.Color(212f / 255f, 135f / 255f, 155f / 255f, ActiveTools.Contains(CurrentTool) ? 1f : 0.5f); if ((CurrentTool == Tool.LineRect || CurrentTool == Tool.LineCircle || CurrentTool == Tool.FullRect || CurrentTool == Tool.FullCircle) && (tool != Tool.LineRect && tool != Tool.LineCircle && tool != Tool.FullRect && tool != Tool.FullCircle)) { ToolImages[Tool.Rect].color = new UnityEngine.Color(212f / 255f, 135f / 255f, 155f / 255f, ActiveTools.Contains(Tool.Rect) ? 1f : 0.5f); } } if (tool == Tool.Rect) { tool = Tool.LineRect; ToolImages[Tool.Rect].color = new UnityEngine.Color(98f / 255f, 80f / 255f, 66f / 255f); ToolImages[Tool.LineRect].color = new UnityEngine.Color(98f / 255f, 80f / 255f, 66f / 255f); ToolImages[Tool.LineCircle].color = new UnityEngine.Color(212f / 255f, 135f / 255f, 155f / 255f); ToolImages[Tool.FullRect].color = new UnityEngine.Color(212f / 255f, 135f / 255f, 155f / 255f); ToolImages[Tool.FullCircle].color = new UnityEngine.Color(212f / 255f, 135f / 255f, 155f / 255f); } CurrentTool = tool; if (ToolImages.ContainsKey(CurrentTool)) { ToolImages[CurrentTool].color = new UnityEngine.Color(98f / 255f, 80f / 255f, 66f / 255f); } if (CurrentTool == Tool.Brush || CurrentTool == Tool.Eraser) { if (CurrentTool == Tool.Brush) { Editor.ChangeTool(new BrushTool()); } if (CurrentTool == Tool.Eraser) { Editor.ChangeTool(new EraseTool()); } BrushContainer.SetParent(BrushOptions.transform); BrushContainer.anchoredPosition = new Vector2(0f, 0f); BrushContainer.localScale = new Vector3(1f, 1f, 1f); BrushOptions.PopUp(); BucketFillOptions.PopOut(); RectOptions.PopOut(); TransformOptions.PopOut(); Editor.CurrentBrush.Size = (int)BrushSize.value; Editor.CurrentBrush.Hardness = (int)BrushHardness.value; Editor.CurrentBrush.RecalculateBrush(); } if (CurrentTool == Tool.ColorPicker) { Editor.ChangeTool(new ColorPickerTool()); BrushOptions.PopOut(); BucketFillOptions.PopOut(); RectOptions.PopOut(); TransformOptions.PopOut(); Editor.CurrentBrush.Size = 1; Editor.CurrentBrush.RecalculateBrush(); } if (CurrentTool == Tool.BucketFill) { Editor.ChangeTool(new BucketFillTool()); BrushOptions.PopOut(); BucketFillOptions.PopUp(); RectOptions.PopOut(); TransformOptions.PopOut(); Editor.CurrentBrush.Size = 1; Editor.CurrentBrush.RecalculateBrush(); } if (CurrentTool == Tool.LineRect || CurrentTool == Tool.LineCircle || CurrentTool == Tool.FullRect || CurrentTool == Tool.FullCircle) { Editor.ChangeTool(new RectTool()); BrushContainer.SetParent(RectOptions.transform); BrushContainer.anchoredPosition = new Vector2(0f, 0f); BrushContainer.localScale = new Vector3(1f, 1f, 1f); BrushOptions.PopOut(); BucketFillOptions.PopOut(); RectOptions.PopUp(); TransformOptions.PopOut(); if (CurrentTool == Tool.FullRect || CurrentTool == Tool.FullCircle) { Editor.CurrentBrush.Size = 1; } else { Editor.CurrentBrush.Size = (int)BrushSize.value; Editor.CurrentBrush.Hardness = (int)BrushHardness.value; } Editor.CurrentBrush.RecalculateBrush(); } if (CurrentTool == Tool.Line) { Editor.ChangeTool(new LineTool()); BrushContainer.SetParent(BrushOptions.transform); BrushContainer.anchoredPosition = new Vector2(0f, 0f); BrushContainer.localScale = new Vector3(1f, 1f, 1f); BrushOptions.PopUp(); BucketFillOptions.PopOut(); RectOptions.PopOut(); TransformOptions.PopOut(); Editor.CurrentBrush.Size = (int)BrushSize.value; Editor.CurrentBrush.Hardness = (int)BrushHardness.value; Editor.CurrentBrush.RecalculateBrush(); } if (CurrentTool == Tool.Transform) { Editor.ChangeTool(new TransformTool()); BrushOptions.PopOut(); BucketFillOptions.PopOut(); RectOptions.PopOut(); TransformOptions.PopUp(); } if (CurrentTool == Tool.None) { Editor.ChangeTool(null); BrushOptions.PopOut(); BucketFillOptions.PopOut(); RectOptions.PopOut(); TransformOptions.PopOut(); } /* * * AddEvent(Line, new EventTrigger[] { Brush, Eraser, ColorPicker, BucketFill, Rect, Line, Shape, Quantize, Import, Select, Transform }, (evtData) => { * CurrentTool = Tool.Line; * BrushContainer.SetParent(BrushOptions.transform); * BrushContainer.anchoredPosition = new Vector2(0f, 0f); * BrushContainer.localScale = new Vector3(1f, 1f, 1f); * * BrushOptions.PopUp(); * BucketFillOptions.PopOut(); * RectOptions.PopOut(); * RecalculateBrush(); * }, "Line"); * * AddEvent(Quantize, new EventTrigger[] { Brush, Eraser, ColorPicker, BucketFill, Rect, Line, Shape, Quantize, Import, Select, Transform }, (evtData) => { * CurrentTool = Tool.Quantize; * CurrentTools = QuantizeOptions; * QuantizeOptions.gameObject.SetActive(true); * Back.gameObject.SetActive(true); * * ShowTools = true; * * BrushOptions.PopOut(); * BucketFillOptions.PopOut(); * RectOptions.PopOut(); * ForceRebuildLayout();*/ }
public void ChangeCrop(TextureBitmap.CropMode crop) { Crop = crop; }