コード例 #1
0
        private void BTN_Supp_Frame_Click(object sender, EventArgs e)
        {
            if (FLP_All_Frame.Controls.Count > 1)
            {
                bool StopDeleting = false;
                for (int i = 0; i < FLP_All_Frame.Controls.Count && !StopDeleting; i++)
                {
                    PictureBox pbx = (PictureBox)FLP_All_Frame.Controls[i];
                    if (pbx.BackColor == Color.DarkGray)
                    {
                        FLP_All_Frame.Controls.RemoveAt(i);
                        OGAnimationFrame.RemoveAt(i);
                        i--;
                        if (i == -1)
                        {
                            i = FLP_All_Frame.Controls.Count - 1;
                        }
                        PictureBox NewSelectedPBox = (PictureBox)FLP_All_Frame.Controls[i];
                        NewSelectedPBox.BackColor = Color.DarkGray;
                        NewSelectedPBox.Padding   = new Padding(5);

                        Sprite = OGAnimationFrame[i].Image;
                        PNL_Canvas.Invalidate();
                        Update_Flow_Layout_Panel();

                        StopDeleting = true;
                    }
                }
            }
        }
コード例 #2
0
 private void RemoveSelection()
 {
     ActiveSelection = false;
     Selection       = null;
     PNL_Canvas.Invalidate();
     ClearTimelineSelection();
 }
コード例 #3
0
 public void Redo()
 {
     if (ActiveSelection)
     {
         if (TimelineSelectionPointer < TimelineSelection.Count - 1)
         {
             TimelineSelectionPointer++;
             Selection = TimelineSelection[TimelineSelectionPointer];
         }
     }
     else
     {
         if (TimelinePointer < Timeline.Count - 1)
         {
             TimelinePointer++;
             for (int i = 0; i < Sprite.Height; i++)
             {
                 for (int j = 0; j < Sprite.Width; j++)
                 {
                     Sprite.SetPixel(j, i, Timeline[TimelinePointer].GetPixel(j, i));
                 }
             }
         }
     }
     PNL_Canvas.Invalidate();
     Update_Flow_Layout_Panel();
     UpdateUndoButton();
 }
コード例 #4
0
 private void ChangeZoom(float newZoom)
 {
     Zoom              = newZoom;
     PNL_Canvas.Width  = (int)(Canvas_Width * Zoom);
     PNL_Canvas.Height = (int)(Canvas_Height * Zoom);
     PNL_Canvas.Invalidate();
     TXB_ZoomLevel.Text = (Zoom * 100).ToString() + '%';
 }
コード例 #5
0
        private ref Bitmap AddBitmapToAnimation()
        {
            Bitmap bitmap = new Bitmap(Sprite.Width, Sprite.Height, PixelFormat.Format32bppArgb);

            OGAnimationFrame.Add(new FrameWithIndex(bitmap, OGAnimationFrame.Count));
            Sprite = bitmap;
            ClearTimelines();
            PNL_Canvas.Invalidate();
            return(ref Sprite);
        }
コード例 #6
0
        private ref Bitmap AddLastFrameToAnimation()
        {
            Bitmap bitmap = new Bitmap(OGAnimationFrame.Last().Image, Sprite.Width, Sprite.Height);

            OGAnimationFrame.Add(new FrameWithIndex(bitmap, OGAnimationFrame.Count));
            Sprite = bitmap;
            ClearTimelines();
            PNL_Canvas.Invalidate();
            return(ref Sprite);
        }
コード例 #7
0
 private void StreamToSelection(MemoryStream strm)
 {
     StopSelecting();
     ActiveSelection      = true;
     Selection            = (Bitmap)Image.FromStream(strm);
     SelectionZone.X      = 0;
     SelectionZone.Y      = 0;
     SelectionZone.Width  = Selection.Width;
     SelectionZone.Height = Selection.Height;
     PNL_Canvas.Invalidate();
 }
コード例 #8
0
 private void StartSelectingMagicWand(ref Bitmap NewSelection, Point UpperLeftCorner)
 {
     ActiveSelection      = true;
     Selection            = NewSelection;
     SelectionZone.X      = UpperLeftCorner.X;
     SelectionZone.Y      = UpperLeftCorner.Y;
     SelectionZone.Width  = NewSelection.Width;
     SelectionZone.Height = NewSelection.Height;
     BTN_Select.Checked   = true;
     PNL_Canvas.Invalidate();
 }
コード例 #9
0
        void DragLine(ref Pen pen_, MouseEventArgs e)
        {
            if (DraggingLine)
            {
                Pen usedPen = new Pen(LineColor, pen_.Width);
                usedPen.SetLineCap(LineCap, LineCap, DashCap);

                ClearLineOverlay(usedPen);

                LineEnd       = AdaptPointToSelection(GetCursorLocationRelative(e));
                usedPen.Color = LineColor;
                LineCanvas.DrawLine(usedPen, LineStart, LineEnd);
                PNL_Canvas.Invalidate();
            }
        }
コード例 #10
0
        private void Fill(Color NewCol, MouseEventArgs e)
        {
            if (ActiveSelection)
            {
                Canvas = Graphics.FromImage(Selection);
            }
            else
            {
                Canvas = Graphics.FromImage(Sprite);
            }

            OldPoint = AdaptPointToSelection(GetCursorLocationRelative(e));

            Bitmap img        = new Bitmap(1, 1);
            bool   ActiveFill = false;

            if (ActiveSelection)
            {
                if (OldPoint.X < Selection.Width && OldPoint.X >= 0)
                {
                    if (OldPoint.Y < Selection.Height && OldPoint.Y >= 0)
                    {
                        img        = Selection;
                        ActiveFill = true;
                    }
                }
            }
            else
            {
                img        = Sprite;
                ActiveFill = true;
            }

            if (ActiveFill)
            {
                Begin_Fill(ref img, OldPoint, NewCol);
                if (ActiveSelection)
                {
                    Selection = img;
                }
                else
                {
                    Sprite = img;
                }
                PNL_Canvas.Invalidate();
                FileChanged = true;
            }
        }
コード例 #11
0
        private void DragSelectedZone(MouseEventArgs e)
        {
            if (!DraggingSelection)
            {
                DraggingSelection = true;
                Point StartingPoint = GetCursorLocationRelative(e);
                SelectionZone.X = StartingPoint.X;
                SelectionZone.Y = StartingPoint.Y;
            }
            Point CursorPoint = GetCursorLocationRelative(e);

            SelectionZone.Width  = CursorPoint.X - SelectionZone.X;
            SelectionZone.Height = CursorPoint.Y - SelectionZone.Y;

            SelectionZone = FormatRectangleInbound(SelectionZone);
            PNL_Canvas.Invalidate();
        }
コード例 #12
0
ファイル: FRM_Main.cs プロジェクト: WhitePikmin/SpriteArtist
        private void PNL_Canvas_MouseMove(object sender, MouseEventArgs e)
        {
            PNL_Canvas.Focus();
            Cursor.Current = Cursors.Cross;
            if (e.Button == MouseButtons.Left)
            {
                switch (CurrentTool)
                {
                case Tool.Pen: DrawOnCanvas(MainPen, e, false); break;

                case Tool.Eraser: DrawOnCanvas(MainPen, e, true); break;

                case Tool.Select: HandleSelection(e); break;

                case Tool.Line: DragLine(ref MainPen, e); break;
                }
            }
            else
            {
                if (e.Button == MouseButtons.Right)
                {
                    switch (CurrentTool)
                    {
                    case Tool.Pen: DrawOnCanvas(SecondPen, e, false); break;

                    case Tool.Eraser: DrawOnCanvas(SecondPen, e, true); break;

                    case Tool.Select: DisplayContextMenu(e); break;

                    case Tool.Line: DragLine(ref MainPen, e); break;
                    }
                }
                else

                if (e.Button == MouseButtons.Middle)
                {
                    DragCanvas(PNL_Drag_Zone.PointToClient(Cursor.Position));
                }

                if (DraggingSelection)
                {
                    DraggingSelection = false;
                }
            }
        }
コード例 #13
0
        private void DrawOnCanvas(Pen pen_, MouseEventArgs e, bool Erase)
        {
            if (ActiveSelection)
            {
                Canvas = Graphics.FromImage(Selection);
            }
            else
            {
                Canvas = Graphics.FromImage(Sprite);
            }

            CurrentPoint = AdaptPointToSelection(GetCursorLocationRelative(e));
            Color col_;

            if (Erase)
            {
                //Pour que l'efface puisse marcher: être capable de rendre un pixel transparent
                Canvas.CompositingMode = CompositingMode.SourceCopy;
                col_ = Color.FromArgb(0, 0, 0, 0);
            }
            else
            {
                col_ = pen_.Color;
                Canvas.CompositingMode = CompositingMode.SourceOver;
            }

            Pen usedPen = new Pen(col_, pen_.Width);

            usedPen.SetLineCap(LineCap, LineCap, DashCap);


            Canvas.DrawLine(usedPen, OldPoint, CurrentPoint);
            if (LineCap == LineCap.Flat)
            {
                int PenWidthHalf = (int)Math.Ceiling(MainPen.Width / 2);
                Canvas.FillRectangle(new SolidBrush(col_), CurrentPoint.X + 1 - PenWidthHalf, CurrentPoint.Y + 1 - PenWidthHalf, MainPen.Width, MainPen.Width);
                Canvas.FillRectangle(new SolidBrush(col_), OldPoint.X + 1 - PenWidthHalf, OldPoint.Y + 1 - PenWidthHalf, MainPen.Width, MainPen.Width);
            }

            OldPoint = CurrentPoint;
            PNL_Canvas.Invalidate();
            FileChanged = true;
        }
コード例 #14
0
ファイル: FRM_Main.cs プロジェクト: WhitePikmin/SpriteArtist
        private void InitCanvas()
        {
            ToolButtons.Add(BTN_Pen);
            ToolButtons.Add(BTN_Erase);
            ToolButtons.Add(BTN_ColorPick);
            ToolButtons.Add(BTN_Line);
            ToolButtons.Add(BTN_Select);
            ToolButtons.Add(BTN_MagicWand);
            ToolButtons.Add(BTN_Fill);

            InitializeColorPalette();


            //Set all pixels transparent
            for (int i = 0; i < Sprite.Height; i++)
            {
                for (int j = 0; j < Sprite.Width; j++)
                {
                    Sprite.SetPixel(j, i, Color.FromArgb(0, 0, 0, 0));
                }
            }

            Canvas = PNL_Canvas.CreateGraphics();
            this.PNL_Canvas.MouseWheel += PNL_Canvas_MouseWheel;
            this.PNL_Canvas.MouseUp    += new MouseEventHandler(MouseUp);

            MainPen.SetLineCap(LineCap, LineCap, DashCap);
            SecondPen.SetLineCap(LineCap, LineCap, DashCap);

            ChangeColorMainPen(Color.Black);
            ChangeColorSecondPen(Color.White);

            CenterCanvas();

            //Activer le "Double buffer"
            //Éviter que le canevas clignote
            typeof(Panel).InvokeMember("DoubleBuffered", BindingFlags.SetProperty
                                       | BindingFlags.Instance | BindingFlags.NonPublic, null,
                                       PNL_Canvas, new object[] { true });

            FileChanged = false;
        }
コード例 #15
0
 private void SelectAll()
 {
     if (SelectionZone.X == 0 &&
         SelectionZone.Y == 0 &&
         SelectionZone.Width == Sprite.Width &&
         SelectionZone.Height == Sprite.Height && ActiveSelection)
     {
         StopSelecting();
     }
     else
     {
         StopSelecting();
         SelectionZone.X      = 0;
         SelectionZone.Y      = 0;
         SelectionZone.Width  = Sprite.Width;
         SelectionZone.Height = Sprite.Height;
         StartSelecting();
     }
     PNL_Canvas.Invalidate();
 }
コード例 #16
0
        private void PasteImagetoSelection(Bitmap img_, int X, int Y)
        {
            int WidthImg  = img_.Width + X;
            int HeightImg = img_.Height + Y;

            for (int j = Y; j < HeightImg; j++)
            {
                if (j < Selection.Height && j >= 0)
                {
                    for (int i = X; i < WidthImg; i++)
                    {
                        if (i < Selection.Width && i >= 0)
                        {
                            Selection.SetPixel(i, j, OverColor(img_.GetPixel(i - X, j - Y), Selection.GetPixel(i, j)));
                        }
                    }
                }
            }
            PNL_Canvas.Invalidate();
        }
コード例 #17
0
        public void Undo()
        {
            if (ActiveSelection)
            {
                if (TimelineSelectionPointer != 0)
                {
                    if (TimelineSelectionPointer == TimelineSelection.Count)
                    {
                        TimelineSelection.Add(Selection);
                    }

                    Selection = TimelineSelection[TimelineSelectionPointer - 1];
                    TimelineSelectionPointer--;
                }
            }
            else
            {
                if (TimelinePointer != 0)
                {
                    if (TimelinePointer == Timeline.Count)
                    {
                        Timeline.Add((Bitmap)Sprite.Clone());
                    }

                    int UndoPointer = TimelinePointer - 1;

                    for (int i = 0; i < Sprite.Height; i++)
                    {
                        for (int j = 0; j < Sprite.Width; j++)
                        {
                            Sprite.SetPixel(j, i, Timeline[UndoPointer].GetPixel(j, i));
                        }
                    }

                    TimelinePointer--;
                }
            }
            PNL_Canvas.Invalidate();
            Update_Flow_Layout_Panel();
            UpdateUndoButton();
        }
コード例 #18
0
        private void FLP_All_Frame_DragDrop(object sender, DragEventArgs e)
        {
            PictureBox      picture      = (PictureBox)e.Data.GetData(typeof(PictureBox));
            FlowLayoutPanel _source      = (FlowLayoutPanel)picture.Parent;
            FlowLayoutPanel _destination = (FlowLayoutPanel)sender;

            Point p     = _destination.PointToClient(new Point(e.X, e.Y));
            var   item  = _destination.GetChildAtPoint(p);
            int   index = _destination.Controls.GetChildIndex(item, false);

            _destination.Controls.SetChildIndex(picture, index);
            _destination.Invalidate();
            if (index >= 0 && index < OGAnimationFrame.Count)
            {
                if (OGAnimationFrame[int.Parse(picture.Name)].NewIndex > index)
                {
                    for (int i = index; i < OGAnimationFrame.Count; i++)
                    {
                        OGAnimationFrame[i].OldIndex = OGAnimationFrame[i].NewIndex;
                        OGAnimationFrame[i].NewIndex = OGAnimationFrame[i].NewIndex + 1;
                    }
                }
                else if (OGAnimationFrame[int.Parse(picture.Name)].NewIndex < index)
                {
                    for (int i = index; i < OGAnimationFrame.Count; i++)
                    {
                        OGAnimationFrame[i].OldIndex = OGAnimationFrame[i].NewIndex;
                        OGAnimationFrame[i].NewIndex = OGAnimationFrame[i].NewIndex - 1;
                    }
                }
                OGAnimationFrame[int.Parse(picture.Name)].OldIndex = OGAnimationFrame[int.Parse(picture.Name)].NewIndex;
                OGAnimationFrame[int.Parse(picture.Name)].NewIndex = index;
                OGAnimationFrame = OGAnimationFrame.OrderBy(x => x.NewIndex).ToList();
                ClearTimelines();
                Sprite = OGAnimationFrame[int.Parse(picture.Name)].Image;
                PNL_Canvas.Invalidate();
                Update_Flow_Layout_Panel();
            }
        }
コード例 #19
0
        private void MoveSelection(MouseEventArgs e)
        {
            int MoveByX;
            int MoveByY;

            MovingSelection = true;

            CurrentPoint = GetCursorLocationRelative(e);

            MoveByX = OldPoint.X - CurrentPoint.X;
            MoveByY = OldPoint.Y - CurrentPoint.Y;

            SelectionZone.X -= MoveByX;
            SelectionZone.Y -= MoveByY;

            SelectionZone = FormatRectanglePositiveCoord(SelectionZone);


            OldPoint = CurrentPoint;
            PNL_Canvas.Invalidate();
            DebugWindow.UpdateValues(ActiveSelection, DraggingSelection, SelectionZone);
        }
コード例 #20
0
        private void DeleteSelection()
        {
            if (ActiveSelection)
            {
                SelectionZone = FormatRectanglePositiveCoord(SelectionZone);
                SelectionZone = FormatRectangleInbound(SelectionZone);

                int LimitY = SelectionZone.Height + SelectionZone.Y;
                int LimitX = SelectionZone.Width + SelectionZone.X;

                for (int j = SelectionZone.Y; j < LimitY; j++)
                {
                    for (int i = SelectionZone.X; i < LimitX; i++)
                    {
                        Sprite.SetPixel(i, j, Color.FromArgb(0, 0, 0, 0));
                    }
                }

                PNL_Canvas.Invalidate();
                FileChanged = true;
            }
        }
コード例 #21
0
        private void DrawSingleDotOnCanvas(Color col_, MouseEventArgs e)
        {
            if (ActiveSelection)
            {
                Canvas = Graphics.FromImage(Selection);
            }
            else
            {
                Canvas = Graphics.FromImage(Sprite);
            }

            OldPoint = AdaptPointToSelection(GetCursorLocationRelative(e));

            if (col_ == Color.Transparent)
            {
                Canvas.CompositingMode = CompositingMode.SourceCopy;
            }
            else
            {
                Canvas.CompositingMode = CompositingMode.SourceOver;
            }

            int PenWidthHalf = (int)Math.Ceiling(MainPen.Width / 2);

            if (MainPen.Width < 3 || LineCap == LineCap.Flat)
            {
                Canvas.FillRectangle(new SolidBrush(col_), OldPoint.X + 1 - PenWidthHalf, OldPoint.Y + 1 - PenWidthHalf, MainPen.Width, MainPen.Width);
            }
            else
            {
                Canvas.FillEllipse(new SolidBrush(col_), OldPoint.X - PenWidthHalf, OldPoint.Y - PenWidthHalf, MainPen.Width, MainPen.Width);
            }

            PNL_Canvas.Invalidate();
            FileChanged = true;
        }
コード例 #22
0
 private void SetGridVisible(bool visible)
 {
     DisplayGrid = visible;
     PNL_Canvas.Invalidate();
 }