public void Redo(object obj) { var skin = (Skin)obj; using (var grabber = new ColorGrabber(GlobalDirtiness.CurrentSkin, skin.Width, skin.Height)) { grabber.Load(); foreach (var kvp in Points) { Point p = kvp.Key; Tuple <Color, ColorAlpha> color = kvp.Value; grabber[p.X, p.Y] = new ColorPixel(color.Item2.Color.R | (color.Item2.Color.G << 8) | (color.Item2.Color.B << 16) | (color.Item2.Color.A << 24)); if (!Editor.MainForm.PaintedPixels.ContainsKey(p)) { Editor.MainForm.PaintedPixels.Add(p, true); } } grabber.Save(); } Editor.MainForm.SetPartTransparencies(); }
public void CommitChanges(Texture currentSkin, bool save) { using (var grabber = new ColorGrabber(currentSkin, Width, Height)) { grabber.Load(); if (currentSkin != GLImage) { grabber.Texture = GLImage; grabber.Save(); } if (save) { var newBitmap = new Bitmap(Width, Height); using (var fp = new FastPixel(newBitmap, true)) { for (int y = 0; y < Height; ++y) { for (int x = 0; x < Width; ++x) { ColorPixel c = grabber[x, y]; fp.SetPixel(x, y, Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue)); } } } newBitmap.Save(File.FullName); newBitmap.Dispose(); var md = new Dictionary <string, string>(); md.Add("Model", Model.Path); PNGMetadata.WriteMetadata(File.FullName, md); SetImages(true); Dirty = false; } } }
public void PerformIncreaseResolution() { if (!treeView1.Enabled) return; if (_lastSkin == null) return; if (!ShowDontAskAgain()) return; _lastSkin.Resize(_lastSkin.Width * 2, _lastSkin.Height * 2); using (var grabber = new ColorGrabber(_lastSkin.GLImage, _lastSkin.Width, _lastSkin.Height)) { grabber.Load(); grabber.Texture = GlobalDirtiness.CurrentSkin; grabber.Save(); grabber.Texture = _previewPaint; grabber.Save(); } }
private void UseToolOnViewport(int x, int y, bool begin = false) { if (_lastSkin == null) return; if (_isValidPick) { Skin skin = _lastSkin; using (var currentSkin = new ColorGrabber(GlobalDirtiness.CurrentSkin, skin.Width, skin.Height)) { currentSkin.Load(); currentSkin.OnWrite = PixelWritten; if (_selectedTool.Tool.MouseMoveOnSkin(currentSkin, skin, _pickPosition.X, _pickPosition.Y)) { SetCanSave(true); skin.Dirty = true; currentSkin.Save(); } } } Renderer.Invalidate(); }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { if (treeView1.SelectedNode == _lastSkin || !(e.Node is Skin)) return; Renderer.MakeCurrent(); if (_lastSkin != null && treeView1.SelectedNode != _lastSkin) { // Copy over the current changes to the tex stored in the skin. // This allows us to pick up where we left off later, without undoing any work. _lastSkin.CommitChanges(GlobalDirtiness.CurrentSkin, false); // if we aren't dirty, unload if (!_lastSkin.Dirty) _lastSkin.Unload(); } //if (_lastSkin != null) // _lastSkin.Undo.Clear(); var skin = (Skin) treeView1.SelectedNode; SetCanSave(skin.Dirty); if (skin.GLImage == null) skin.Create(); if (skin == null) { _currentUndoBuffer = null; TextureGL.Unbind(); using (var currentSkin = new ColorGrabber(GlobalDirtiness.CurrentSkin, 64, 32)) currentSkin.Save(); undoToolStripMenuItem.Enabled = undoToolStripButton.Enabled = false; redoToolStripMenuItem.Enabled = redoToolStripButton.Enabled = false; } else { using (var glImage = new ColorGrabber(skin.GLImage, skin.Width, skin.Height)) { glImage.Load(); glImage.Texture = GlobalDirtiness.CurrentSkin; glImage.Save(); glImage.Texture = _previewPaint; glImage.Save(); } _currentUndoBuffer = skin.Undo; CheckUndo(); } _lastSkin = (Skin) treeView1.SelectedNode; SetModel(skin.Model); Renderer.Invalidate(); VerifySelectionButtons(); FillPartList(); }
private void SetPreview() { if (_lastSkin == null) { using (var preview = new ColorGrabber(_previewPaint, 64, 32)) preview.Save(); } else { Skin skin = _lastSkin; using (var currentSkin = new ColorGrabber(GlobalDirtiness.CurrentSkin, skin.Width, skin.Height)) { bool pick = GetPick(_mousePoint.X, _mousePoint.Y, ref _pickPosition); //if (pick) { currentSkin.Load(); if (_selectedTool.Tool.RequestPreview(currentSkin, skin, _pickPosition.X, _pickPosition.Y)) { currentSkin.Texture = _previewPaint; currentSkin.Save(); } else { currentSkin.Texture = _previewPaint; currentSkin.Save(); } } /*else { currentSkin.Texture = _lastSkin.GLImage; currentSkin.Load(); currentSkin.Texture = _previewPaint; currentSkin.Save(); }*/ } } }
private void rendererControl_MouseUp(object sender, MouseEventArgs e) { Skin skin = _lastSkin; if (skin == null) return; using (var backup = new ColorGrabber(GlobalDirtiness.CurrentSkin, skin.Width, skin.Height)) { backup.Load(); try { if (_mouseIsDown) { var currentSkin = new ColorGrabber(); if (e.Button == MouseButtons.Left) { currentSkin = new ColorGrabber(GlobalDirtiness.CurrentSkin, skin.Width, skin.Height); currentSkin.Load(); if (_selectedTool.Tool.EndClick(currentSkin, skin, e)) { SetCanSave(true); skin.Dirty = true; treeView1.Invalidate(); currentSkin.Save(); } SetPartTransparencies(); } else _tools[(int)Tools.Camera].Tool.EndClick(currentSkin, _lastSkin, e); } } catch (Exception ex) { backup.Save(); this.saveAllToolStripMenuItem_Click(null, null); throw ex; } } _mouseIsDown = false; treeView1.Invalidate(); }
private void rendererControl_MouseMove(object sender, MouseEventArgs e) { Skin skin = _lastSkin; if (skin == null) return; _isValidPick = GetPick(e.X, e.Y, ref _pickPosition); using (var backup = new ColorGrabber(GlobalDirtiness.CurrentSkin, skin.Width, skin.Height)) { backup.Load(); try { if (_mouseIsDown) { if (e.Button == MouseButtons.Left) { _selectedTool.Tool.MouseMove(_lastSkin, e); UseToolOnViewport(e.X, e.Y); } else _tools[(int)Tools.Camera].Tool.MouseMove(_lastSkin, e); } _mousePoint = e.Location; Renderer.Invalidate(); } catch (Exception ex) { backup.Save(); this.saveAllToolStripMenuItem_Click(null, null); throw ex; } } }
private void rendererControl_MouseDown(object sender, MouseEventArgs e) { Skin skin = _lastSkin; if (skin == null) return; CheckMouse(e.Y); float halfWidth = Renderer.Width / 2.0f; float halfImgWidth = 56.0f / 2.0f; var rect = new RectangleF(halfWidth - halfImgWidth, 0, halfImgWidth * 2, 22); _mousePoint = e.Location; if (rect.Contains(e.Location)) { if (splitContainer4.SplitterDistance == 0) _opening = true; else _opening = false; _animTimer.Start(); return; } _mouseIsDown = true; //_isValidPick = GetPick(e.X, e.Y, ref _pickPosition); using (var backup = new ColorGrabber(GlobalDirtiness.CurrentSkin, skin.Width, skin.Height)) { backup.Load(); try { if (e.Button == MouseButtons.Left) { if (_isValidPick) _selectedTool.Tool.BeginClick(_lastSkin, _pickPosition, e); else _selectedTool.Tool.BeginClick(_lastSkin, new Point(-1, -1), e); UseToolOnViewport(e.X, e.Y); } else _tools[(int)Tools.Camera].Tool.BeginClick(_lastSkin, Point.Empty, e); } catch (Exception ex) { backup.Save(); this.saveAllToolStripMenuItem_Click(null, null); throw ex; } } }
public void SetModel(Model Model) { if (_lastSkin == null) return; if (_oldModel != null && _oldModel.Model == Model) return; if (_lastSkin.Model != Model) { var oldAspect = (float)_lastSkin.Width / (float)_lastSkin.Height; var newAspect = (float)Model.DefaultWidth / (float)Model.DefaultHeight; if (Math.Abs(oldAspect - newAspect) > 0.01f) { ResizeType resizeType; if ((resizeType = SkinSizeMismatch.Show(GetLanguageString("M_SKINSIZEMISMATCH"))) == ResizeType.None) return; _lastSkin.Model = Model; _lastSkin.Resize((int)Model.DefaultWidth, (int)Model.DefaultHeight, resizeType); using (var grabber = new ColorGrabber(_lastSkin.GLImage, _lastSkin.Width, _lastSkin.Height)) { grabber.Load(); grabber.Texture = GlobalDirtiness.CurrentSkin; grabber.Save(); grabber.Texture = _previewPaint; grabber.Save(); } } else _lastSkin.Model = Model; _lastSkin.Dirty = true; SetCanSave(true); CheckUndo(); } if (_oldModel != null) { _oldModel.Checked = false; for (ToolStripItem parent = _oldModel.OwnerItem; parent != null; parent = parent.OwnerItem) parent.Image = null; } toolStripDropDownButton1.Text = _lastSkin.Model.Name; _oldModel = _lastSkin.Model.DropDownItem; _oldModel.Checked = true; _lastSkin.TransparentParts.Clear(); _lastSkin.SetTransparentParts(); FillPartList(); for (ToolStripItem parent = _oldModel.OwnerItem; parent != null; parent = parent.OwnerItem) parent.Image = Resources.right_arrow_next; CalculateMatrices(); Renderer.Invalidate(); }
public void Redo(object obj) { var skin = (Skin) obj; using (var grabber = new ColorGrabber(GlobalDirtiness.CurrentSkin, skin.Width, skin.Height)) { grabber.Load(); foreach (var kvp in Points) { Point p = kvp.Key; Tuple<Color, ColorAlpha> color = kvp.Value; grabber[p.X, p.Y] = new ColorPixel(color.Item2.Color.R | (color.Item2.Color.G << 8) | (color.Item2.Color.B << 16) | (color.Item2.Color.A << 24)); if (!Editor.MainForm.PaintedPixels.ContainsKey(p)) Editor.MainForm.PaintedPixels.Add(p, true); } grabber.Save(); } Editor.MainForm.SetPartTransparencies(); }
public void CommitChanges(Texture currentSkin, bool save) { using (var grabber = new ColorGrabber(currentSkin, Width, Height)) { grabber.Load(); if (currentSkin != GLImage) { grabber.Texture = GLImage; grabber.Save(); } if (save) { var newBitmap = new Bitmap(Width, Height); using (var fp = new FastPixel(newBitmap, true)) { for (int y = 0; y < Height; ++y) { for (int x = 0; x < Width; ++x) { ColorPixel c = grabber[x, y]; fp.SetPixel(x, y, Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue)); } } } newBitmap.Save(File.FullName); newBitmap.Dispose(); var md = new Dictionary<string, string>(); md.Add("Model", Model.Path); PNGMetadata.WriteMetadata(File.FullName, md); SetImages(true); Dirty = false; } } }