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 override bool EndClick(ColorGrabber pixels, Skin skin, MouseEventArgs e) { base.EndClick(pixels, skin, e); _seed = _noise.Next(); _noise = _noise2 = new Random(_seed); return(false); }
public override bool EndClick(ColorGrabber pixels, Skin skin, MouseEventArgs e) { base.EndClick(pixels, skin, e); _seed = _noise.Next(); _noise = _noise2 = new Random(_seed); return false; }
public bool EndClick(ColorGrabber pixels, Skin skin, MouseEventArgs e) { _done = false; if (_undo.Points.Count != 0) skin.Undo.AddBuffer(_undo); _undo = null; Editor.MainForm.CheckUndo(); return false; }
public bool MouseMoveOnSkin(ColorGrabber pixels, Skin skin, int x, int y) { ColorPixel c = pixels[x, y]; ColorManager oldColor = ColorManager.FromRGBA(c.Red, c.Green, c.Blue, c.Alpha); if ((Control.ModifierKeys & Keys.Shift) != 0) Editor.MainForm.ColorPanel.UnselectedColor = oldColor; else Editor.MainForm.ColorPanel.SelectedColor = oldColor; return false; }
public bool EndClick(ColorGrabber pixels, Skin skin, MouseEventArgs e) { _done = false; if (_undo.Points.Count != 0) { skin.Undo.AddBuffer(_undo); } _undo = null; Editor.MainForm.CheckUndo(); return(false); }
public virtual bool EndClick(ColorGrabber pixels, Skin skin, MouseEventArgs e) { if (_undo.Points.Count != 0) { skin.Undo.AddBuffer(_undo); Editor.MainForm.CheckUndo(); _oldPixel = new Point(-1, -1); } _undo = null; return(false); }
public virtual bool EndClick(ColorGrabber pixels, Skin skin, MouseEventArgs e) { if (_undo.Points.Count != 0) { skin.Undo.AddBuffer(_undo); Editor.MainForm.CheckUndo(); _oldPixel = new Point(-1, -1); } _undo = null; return false; }
public bool MouseMoveOnSkin(ColorGrabber pixels, Skin skin, int x, int y) { ColorPixel c = pixels[x, y]; ColorManager oldColor = ColorManager.FromRGBA(c.Red, c.Green, c.Blue, c.Alpha); if ((Control.ModifierKeys & Keys.Shift) != 0) { Editor.MainForm.ColorPanel.UnselectedColor = oldColor; } else { Editor.MainForm.ColorPanel.SelectedColor = oldColor; } return(false); }
private void FloodFill(int x, int y, Color oldColor, ColorManager newColor, ColorGrabber pixels) { Queue q = new Queue(); q.Enqueue(new Point(x, y)); while (q.Count != 0) { Point pop = (Point)q.Dequeue(); ColorPixel c = pixels[pop.X, pop.Y]; Color real = Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue); if (!SimilarColor2(oldColor, real, _threshold)) { continue; } if (!_undo.Points.ContainsKey(pop)) { _undo.Points.Add(pop, Tuple.MakeTuple(real, new ColorAlpha(newColor.RGB, 0))); pixels[pop.X, pop.Y] = new ColorPixel(newColor.RGB.R | (newColor.RGB.G << 8) | (newColor.RGB.B << 16) | (newColor.RGB.A << 24)); if (_boundBox.Contains(pop.X - 1, pop.Y)) { q.Enqueue(new Point(pop.X - 1, pop.Y)); } if (_boundBox.Contains(pop.X + 1, pop.Y)) { q.Enqueue(new Point(pop.X + 1, pop.Y)); } if (_boundBox.Contains(pop.X, pop.Y - 1)) { q.Enqueue(new Point(pop.X, pop.Y - 1)); } if (_boundBox.Contains(pop.X, pop.Y + 1)) { q.Enqueue(new Point(pop.X, pop.Y + 1)); } } } }
public void SetTransparentParts() { using (var grabber = new ColorGrabber(GLImage, Width, Height)) { grabber.Load(); int mesh = 0; TransparentParts.Clear(); foreach (Mesh m in Model.Meshes) { TransparentParts.Add(mesh, false); CheckTransparentPart(grabber, mesh); mesh++; } } }
public virtual bool RequestPreview(ColorGrabber pixels, Skin skin, int x, int y) { if (x == -1) { return(false); } Brush brush = Brushes.SelectedBrush; int startX = x - (brush.Width / 2); int startY = y - (brush.Height / 2); IsPreview = true; for (int ry = 0; ry < brush.Height; ++ry) { for (int rx = 0; rx < brush.Width; ++rx) { int xx = startX + rx; int yy = startY + ry; if (xx < 0 || xx >= skin.Width || yy < 0 || yy >= skin.Height) { continue; } if (brush[rx, ry] == 0.0f) { continue; } ColorPixel c = pixels[xx, yy]; Color oldColor = Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue); Color color = GetLeftColor(); color = Color.FromArgb((byte)(brush[rx, ry] * 255 * (color.A / 255.0f)), color); Color newColor = BlendColor(color, oldColor); pixels[xx, yy] = new ColorPixel(newColor.R | (newColor.G << 8) | (newColor.B << 16) | (newColor.A << 24)); } } return(true); }
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 bool MouseMoveOnSkin(ColorGrabber pixels, Skin skin, int x, int y) { if (_done) { return(false); } var curve = new BezierCurveQuadric(new Vector2(1, 0), new Vector2(0, 1), new Vector2(1, 2)); _threshold = (byte)((1 - (curve.CalculatePoint(Threshold)).X) * 255); //(byte)((1 - Math.Sin((1 - Threshold) * (Math.PI / 2))) * 255); ColorPixel c = pixels[x, y]; Color oldColor = Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue); ColorManager newColor = ((Control.ModifierKeys & Keys.Shift) != 0) ? Editor.MainForm.ColorPanel.UnselectedColor : Editor.MainForm.ColorPanel.SelectedColor; FloodFill(x, y, oldColor, newColor, pixels); _done = true; return(true); }
public void CheckTransparentPart(ColorGrabber grabber, int index) { foreach (Face f in Model.Meshes[index].Faces) { var bounds = new Bounds(new Point(9999, 9999), new Point(-9999, -9999)); foreach (Vector2 c in f.TexCoords) { var coord = new Vector2(c.X * Width, c.Y * Height); bounds.AddPoint(new Point((int)coord.X, (int)coord.Y)); } Rectangle rect = bounds.ToRectangle(); bool gotOne = false; for (int y = rect.Y; !gotOne && y < rect.Y + rect.Height; ++y) { for (int x = rect.X; x < rect.X + rect.Width; ++x) { ColorPixel pixel = grabber[x, y]; if (pixel.Alpha != 255) { gotOne = true; break; } } } if (gotOne) { TransparentParts[index] = gotOne; return; } } TransparentParts[index] = false; }
public bool RequestPreview(ColorGrabber pixels, Skin skin, int x, int y) { if (x == -1) { return(false); } var highlightPoint = new Point(x, y); bool doHighlight = ((Control.ModifierKeys & Keys.Control) != 0); Color newColor; if (doHighlight) { Rectangle part = Editor.CurrentModel.GetTextureFaceBounds(highlightPoint, skin); for (int ry = part.Y; ry < part.Y + part.Height; ++ry) { for (int rx = part.X; rx < part.X + part.Width; ++rx) { ColorPixel px = pixels[rx, ry]; Color c = Color.FromArgb(px.Alpha, px.Red, px.Green, px.Blue); Color blendMe = Color.FromArgb(64, Color.Green); newColor = (Color)ColorBlending.AlphaBlend(blendMe, c); pixels[rx, ry] = new ColorPixel((newColor.R << 0) | (newColor.G << 8) | (newColor.B << 16) | (newColor.A << 24)); } } } newColor = (((Control.ModifierKeys & Keys.Shift) != 0) ? Editor.MainForm.ColorPanel.UnselectedColor : Editor.MainForm.ColorPanel.SelectedColor).RGB; pixels[x, y] = new ColorPixel(newColor.R | (newColor.G << 8) | (newColor.B << 16) | (newColor.A << 24)); return(true); }
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 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 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_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 SetPartTransparencies() { using (var grabber = new ColorGrabber(GlobalDirtiness.CurrentSkin, _lastSkin.Width, _lastSkin.Height)) { grabber.Load(); var paintedParts = new Dictionary<int, bool>(); foreach (var p in _paintedPixels) { List<int> parts = CurrentModel.GetIntersectingParts(p.Key, _lastSkin); foreach (int part in parts) { if (!paintedParts.ContainsKey(part)) paintedParts.Add(part, true); } } foreach (var p in paintedParts) _lastSkin.CheckTransparentPart(grabber, p.Key); } _paintedPixels.Clear(); }
public bool MouseMoveOnSkin(ColorGrabber pixels, Skin skin, int x, int y) { return(false); }
public bool RequestPreview(ColorGrabber pixels, Skin skin, int x, int y) { if (x == -1) return false; var highlightPoint = new Point(x, y); bool doHighlight = ((Control.ModifierKeys & Keys.Control) != 0); Color newColor; if (doHighlight) { Rectangle part = Editor.CurrentModel.GetTextureFaceBounds(highlightPoint, skin); for (int ry = part.Y; ry < part.Y + part.Height; ++ry) { for (int rx = part.X; rx < part.X + part.Width; ++rx) { ColorPixel px = pixels[rx, ry]; Color c = Color.FromArgb(px.Alpha, px.Red, px.Green, px.Blue); Color blendMe = Color.FromArgb(64, Color.Green); newColor = (Color) ColorBlending.AlphaBlend(blendMe, c); pixels[rx, ry] = new ColorPixel((newColor.R << 0) | (newColor.G << 8) | (newColor.B << 16) | (newColor.A << 24)); } } } newColor = (((Control.ModifierKeys & Keys.Shift) != 0) ? Editor.MainForm.ColorPanel.UnselectedColor : Editor.MainForm.ColorPanel.SelectedColor).RGB; pixels[x, y] = new ColorPixel(newColor.R | (newColor.G << 8) | (newColor.B << 16) | (newColor.A << 24)); return true; }
public void CheckTransparentPart(ColorGrabber grabber, int index) { foreach (Face f in Model.Meshes[index].Faces) { var bounds = new Bounds(new Point(9999, 9999), new Point(-9999, -9999)); foreach (Vector2 c in f.TexCoords) { var coord = new Vector2(c.X * Width, c.Y * Height); bounds.AddPoint(new Point((int) coord.X, (int) coord.Y)); } Rectangle rect = bounds.ToRectangle(); bool gotOne = false; for (int y = rect.Y; !gotOne && y < rect.Y + rect.Height; ++y) { for (int x = rect.X; x < rect.X + rect.Width; ++x) { ColorPixel pixel = grabber[x, y]; if (pixel.Alpha != 255) { gotOne = true; break; } } } if (gotOne) { TransparentParts[index] = gotOne; return; } } TransparentParts[index] = false; }
public virtual bool RequestPreview(ColorGrabber pixels, Skin skin, int x, int y) { if (x == -1) return false; Brush brush = Brushes.SelectedBrush; int startX = x - (brush.Width / 2); int startY = y - (brush.Height / 2); IsPreview = true; for (int ry = 0; ry < brush.Height; ++ry) { for (int rx = 0; rx < brush.Width; ++rx) { int xx = startX + rx; int yy = startY + ry; if (xx < 0 || xx >= skin.Width || yy < 0 || yy >= skin.Height) continue; if (brush[rx, ry] == 0.0f) continue; ColorPixel c = pixels[xx, yy]; Color oldColor = Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue); Color color = GetLeftColor(); color = Color.FromArgb((byte) (brush[rx, ry] * 255 * (color.A / 255.0f)), color); Color newColor = BlendColor(color, oldColor); pixels[xx, yy] = new ColorPixel(newColor.R | (newColor.G << 8) | (newColor.B << 16) | (newColor.A << 24)); } } return true; }
public override bool MouseMoveOnSkin(ColorGrabber pixels, Skin skin, int x, int y) { return(MouseMoveOnSkin(pixels, skin, x, y, false)); }
public bool MouseMoveOnSkin(ColorGrabber pixels, Skin skin, int x, int y) { return(MouseMoveOnSkin(pixels, skin, x, y, GlobalSettings.PencilIncremental)); }
public bool MouseMoveOnSkin(ColorGrabber pixels, Skin skin, int x, int y, bool incremental) { Brush brush = Brushes.SelectedBrush; if (_brushThatWasStamped != brush) { _stampedBrush = null; } if (x == _oldPixel.X && y == _oldPixel.Y) { return(false); } if (_stampedBrush == null && !HoldingShift) { return(false); } IsPreview = false; int startX = x - (brush.Width / 2); int startY = y - (brush.Height / 2); for (int ry = 0; ry < brush.Height; ++ry) { for (int rx = 0; rx < brush.Width; ++rx) { int xx = startX + rx; int yy = startY + ry; if (xx < 0 || xx >= skin.Width || yy < 0 || yy >= skin.Height) { continue; } if (brush[rx, ry] == 0.0f) { continue; } ColorPixel c = pixels[xx, yy]; if (HoldingShift) { if (_stampedBrush == null) { _stampedBrush = new ColorPixel[brush.Width, brush.Height]; } _brushThatWasStamped = brush; _stampedBrush[rx, ry] = c; continue; } Color oldColor = Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue); Color color = Color.FromArgb(_stampedBrush[rx, ry].Alpha, _stampedBrush[rx, ry].Red, _stampedBrush[rx, ry].Green, _stampedBrush[rx, ry].Blue); byte maxAlpha = color.A; var alphaToAdd = (float) (byte)(brush[rx, ry] * 255 * ((Editor.MainForm.ColorPanel.SelectedColor.RGB.A / 255.0f) * (color.A / 255.0f))); if (!incremental && _undo.Points.ContainsKey(new Point(xx, yy)) && _undo.Points[new Point(xx, yy)].Item2.TotalAlpha >= maxAlpha) { continue; } if (!incremental && _undo.Points.ContainsKey(new Point(xx, yy)) && _undo.Points[new Point(xx, yy)].Item2.TotalAlpha + alphaToAdd >= maxAlpha) { alphaToAdd = maxAlpha - _undo.Points[new Point(xx, yy)].Item2.TotalAlpha; } color = Color.FromArgb((byte)(alphaToAdd), color); Color newColor = BlendColor(color, oldColor); if (oldColor == newColor) { continue; } if (_undo.Points.ContainsKey(new Point(xx, yy))) { Tuple <Color, ColorAlpha> tupl = _undo.Points[new Point(xx, yy)]; tupl.Item2 = new ColorAlpha(newColor, tupl.Item2.TotalAlpha + alphaToAdd); _undo.Points[new Point(xx, yy)] = tupl; } else { _undo.Points.Add(new Point(xx, yy), Tuple.MakeTuple(oldColor, new ColorAlpha(newColor, alphaToAdd))); } pixels[xx, yy] = new ColorPixel(newColor.R | (newColor.G << 8) | (newColor.B << 16) | (newColor.A << 24)); } } _oldPixel = new Point(x, y); return(!HoldingShift); }
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 override bool RequestPreview(ColorGrabber pixels, Skin skin, int x, int y) { _noise = new Random(_seed); return(base.RequestPreview(pixels, skin, x, y)); }
public override bool RequestPreview(ColorGrabber pixels, Skin skin, int x, int y) { _noise = new Random(_seed); return base.RequestPreview(pixels, skin, x, y); }
public abstract bool MouseMoveOnSkin(ColorGrabber pixels, Skin skin, int x, int y);
public override bool MouseMoveOnSkin(ColorGrabber pixels, Skin skin, int x, int y) { return(MouseMoveOnSkin(pixels, skin, x, y, GlobalSettings.DarkenLightenIncremental)); }
public bool MouseMoveOnSkin(ColorGrabber pixels, Skin skin, int x, int y, bool incremental) { if (x == _oldPixel.X && y == _oldPixel.Y) return false; IsPreview = false; Brush brush = Brushes.SelectedBrush; int startX = x - (brush.Width / 2); int startY = y - (brush.Height / 2); for (int ry = 0; ry < brush.Height; ++ry) { for (int rx = 0; rx < brush.Width; ++rx) { int xx = startX + rx; int yy = startY + ry; if (xx < 0 || xx >= skin.Width || yy < 0 || yy >= skin.Height) continue; if (brush[rx, ry] == 0.0f) continue; ColorPixel c = pixels[xx, yy]; Color oldColor = Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue); ColorManager.RGBColor color = (((Control.ModifierKeys & Keys.Shift) != 0) ? Editor.MainForm.ColorPanel.UnselectedColor : Editor.MainForm.ColorPanel.SelectedColor).RGB; byte maxAlpha = color.A; var alphaToAdd = (float) (byte) (brush[rx, ry] * 255 * (Editor.MainForm.ColorPanel.SelectedColor.RGB.A / 255.0f)); if (!incremental && _undo.Points.ContainsKey(new Point(xx, yy)) && _undo.Points[new Point(xx, yy)].Item2.TotalAlpha >= maxAlpha) continue; if (!incremental && _undo.Points.ContainsKey(new Point(xx, yy)) && _undo.Points[new Point(xx, yy)].Item2.TotalAlpha + alphaToAdd >= maxAlpha) alphaToAdd = maxAlpha - _undo.Points[new Point(xx, yy)].Item2.TotalAlpha; color = Color.FromArgb((byte) (alphaToAdd), color); Color newColor = BlendColor(color, oldColor); if (oldColor == newColor) continue; if (_undo.Points.ContainsKey(new Point(xx, yy))) { Tuple<Color, ColorAlpha> tupl = _undo.Points[new Point(xx, yy)]; tupl.Item2 = new ColorAlpha(newColor, tupl.Item2.TotalAlpha + alphaToAdd); _undo.Points[new Point(xx, yy)] = tupl; } else _undo.Points.Add(new Point(xx, yy), Tuple.MakeTuple(oldColor, new ColorAlpha(newColor, alphaToAdd))); pixels[xx, yy] = new ColorPixel(newColor.R | (newColor.G << 8) | (newColor.B << 16) | (newColor.A << 24)); } } _oldPixel = new Point(x, y); return true; }
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 bool RequestPreview(ColorGrabber pixels, Skin skin, int x, int y) { return(false); }
private void PerformSaveAs() { Skin skin = _lastSkin; using (var grabber = new ColorGrabber(GlobalDirtiness.CurrentSkin, skin.Width, skin.Height)) { grabber.Load(); var b = new Bitmap(skin.Width, skin.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); BitmapData locked = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb); unsafe { void *inPixels = grabber.Array; void *outPixels = locked.Scan0.ToPointer(); var inInt = (int*)inPixels; var outInt = (int*)outPixels; for (int y = 0; y < b.Height; ++y) { for (int x = 0; x < b.Width; ++x) { Color color = Color.FromArgb((*inInt >> 24) & 0xFF, (*inInt >> 0) & 0xFF, (*inInt >> 8) & 0xFF, (*inInt >> 16) & 0xFF); *outInt = color.ToArgb(); inInt++; outInt++; } } } b.UnlockBits(locked); using (var sfd = new SaveFileDialog()) { sfd.Filter = "Skin Image|*.png"; sfd.RestoreDirectory = true; if (sfd.ShowDialog() == DialogResult.OK) b.Save(sfd.FileName); } b.Dispose(); } }
public bool MouseMoveOnSkin(ColorGrabber pixels, Skin skin, int x, int y) { return false; }
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; } } }
public bool MouseMoveOnSkin(ColorGrabber pixels, Skin skin, int x, int y) { if (_done) return false; var curve = new BezierCurveQuadric(new Vector2(1, 0), new Vector2(0, 1), new Vector2(1, 2)); _threshold = (byte) ((1 - (curve.CalculatePoint(Threshold)).X) * 255); //(byte)((1 - Math.Sin((1 - Threshold) * (Math.PI / 2))) * 255); ColorPixel c = pixels[x, y]; Color oldColor = Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue); ColorManager newColor = ((Control.ModifierKeys & Keys.Shift) != 0) ? Editor.MainForm.ColorPanel.UnselectedColor : Editor.MainForm.ColorPanel.SelectedColor; FloodFill(x, y, oldColor, newColor, pixels); _done = true; return true; }
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(); }*/ } } }
public bool EndClick(ColorGrabber pixels, Skin skin, MouseEventArgs e) { return false; }
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 FloodFill(int x, int y, Color oldColor, ColorManager newColor, ColorGrabber pixels) { Queue q = new Queue(); q.Enqueue(new Point(x, y)); while (q.Count != 0) { Point pop = (Point)q.Dequeue(); ColorPixel c = pixels[pop.X, pop.Y]; Color real = Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue); if (!SimilarColor2(oldColor, real, _threshold)) continue; if (!_undo.Points.ContainsKey(pop)) { _undo.Points.Add(pop, Tuple.MakeTuple(real, new ColorAlpha(newColor.RGB, 0))); pixels[pop.X, pop.Y] = new ColorPixel(newColor.RGB.R | (newColor.RGB.G << 8) | (newColor.RGB.B << 16) | (newColor.RGB.A << 24)); if (_boundBox.Contains(pop.X - 1, pop.Y)) q.Enqueue(new Point(pop.X - 1, pop.Y)); if (_boundBox.Contains(pop.X + 1, pop.Y)) q.Enqueue(new Point(pop.X + 1, pop.Y)); if (_boundBox.Contains(pop.X, pop.Y - 1)) q.Enqueue(new Point(pop.X, pop.Y - 1)); if (_boundBox.Contains(pop.X, pop.Y + 1)) q.Enqueue(new Point(pop.X, pop.Y + 1)); } } }
public bool RequestPreview(ColorGrabber pixels, Skin skin, int x, int y) { return false; }
public override bool MouseMoveOnSkin(ColorGrabber pixels, Skin skin, int x, int y) { return MouseMoveOnSkin(pixels, skin, x, y, false); }
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 override bool MouseMoveOnSkin(ColorGrabber pixels, Skin skin, int x, int y) { return MouseMoveOnSkin(pixels, skin, x, y, GlobalSettings.PencilIncremental); }
public bool EndClick(ColorGrabber pixels, Skin skin, MouseEventArgs e) { return(false); }
public bool MouseMoveOnSkin(ColorGrabber pixels, Skin skin, int x, int y, bool incremental) { if (x == _oldPixel.X && y == _oldPixel.Y) { return(false); } IsPreview = false; Brush brush = Brushes.SelectedBrush; int startX = x - (brush.Width / 2); int startY = y - (brush.Height / 2); for (int ry = 0; ry < brush.Height; ++ry) { for (int rx = 0; rx < brush.Width; ++rx) { int xx = startX + rx; int yy = startY + ry; if (xx < 0 || xx >= skin.Width || yy < 0 || yy >= skin.Height) { continue; } if (brush[rx, ry] == 0.0f) { continue; } ColorPixel c = pixels[xx, yy]; Color oldColor = Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue); ColorManager.RGBColor color = (((Control.ModifierKeys & Keys.Shift) != 0) ? Editor.MainForm.ColorPanel.UnselectedColor : Editor.MainForm.ColorPanel.SelectedColor).RGB; byte maxAlpha = color.A; var alphaToAdd = (float)(byte)(brush[rx, ry] * 255 * (Editor.MainForm.ColorPanel.SelectedColor.RGB.A / 255.0f)); if (!incremental && _undo.Points.ContainsKey(new Point(xx, yy)) && _undo.Points[new Point(xx, yy)].Item2.TotalAlpha >= maxAlpha) { continue; } if (!incremental && _undo.Points.ContainsKey(new Point(xx, yy)) && _undo.Points[new Point(xx, yy)].Item2.TotalAlpha + alphaToAdd >= maxAlpha) { alphaToAdd = maxAlpha - _undo.Points[new Point(xx, yy)].Item2.TotalAlpha; } color = Color.FromArgb((byte)(alphaToAdd), color); Color newColor = BlendColor(color, oldColor); if (oldColor == newColor) { continue; } if (_undo.Points.ContainsKey(new Point(xx, yy))) { Tuple <Color, ColorAlpha> tupl = _undo.Points[new Point(xx, yy)]; _undo.Points[new Point(xx, yy)] = Tuple.Create(tupl.Item1, new ColorAlpha(newColor, tupl.Item2.TotalAlpha + alphaToAdd)); } else { _undo.Points.Add(new Point(xx, yy), Tuple.Create(oldColor, new ColorAlpha(newColor, alphaToAdd))); } pixels[xx, yy] = new ColorPixel(newColor.R | (newColor.G << 8) | (newColor.B << 16) | (newColor.A << 24)); } } _oldPixel = new Point(x, y); return(true); }