示例#1
0
        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();
        }
示例#2
0
        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++;
                }
            }
        }
示例#3
0
        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;
                }
            }
        }
示例#4
0
        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();
            }
        }
示例#5
0
        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();
        }
示例#6
0
        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();
        }
示例#7
0
        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();
                    }*/
                }
            }
        }
示例#8
0
        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();
        }
示例#9
0
        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;
                }
            }
        }
示例#10
0
        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;
                }
            }
        }
示例#11
0
        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();
            }
        }
示例#12
0
        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();
        }
示例#13
0
        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();
        }
示例#14
0
        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();
        }
示例#15
0
文件: Skin.cs 项目: rmbzlib/mcskin3d
        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++;
                }
            }
        }
示例#16
0
文件: Skin.cs 项目: rmbzlib/mcskin3d
        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;
                }
            }
        }