예제 #1
0
        private void onMouseUp(object sender, MouseEventArgs e)
        {
            if (mouseMode != MouseMode.Normal)
            {
                if (mouseMode == MouseMode.Camera && !Util.Ctrl)
                {
                    SnapCamera();
                }

                //Exit mouse move mode
                mousePanMode = false;
            }
            else
            {
                //Call the layer event
                if (e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    LayerEditors[Ogmo.LayersWindow.CurrentLayerIndex].OnMouseLeftUp(LevelView.ScreenToEditor(e.Location));
                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Right)
                {
                    LayerEditors[Ogmo.LayersWindow.CurrentLayerIndex].OnMouseRightUp(LevelView.ScreenToEditor(e.Location));
                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Middle)
                {
                    //Exit mouse move mode
                    mousePanMode = false;
                }
            }
        }
예제 #2
0
 private void onKeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Home)
     {
         LevelView.Center();
     }
     else if (e.KeyCode == Keys.Oemplus)
     {
         LevelView.ZoomIn(LevelView.EditorToScreen(MousePosition));
     }
     else if (e.KeyCode == Keys.OemMinus)
     {
         LevelView.ZoomOut(LevelView.EditorToScreen(MousePosition));
     }
     else if (e.KeyCode == Keys.Left)
     {
         LevelView.Pan(new PointF(32, 0));
         foreach (var ed in LayerEditors)
         {
             ed.UpdateDrawOffset(LevelView.ScreenToEditor(new Point(0, 0)));
         }
     }
     else if (e.KeyCode == Keys.Right)
     {
         LevelView.Pan(new PointF(-32, 0));
         foreach (var ed in LayerEditors)
         {
             ed.UpdateDrawOffset(LevelView.ScreenToEditor(new Point(0, 0)));
         }
     }
     else if (e.KeyCode == Keys.Up)
     {
         LevelView.Pan(new PointF(0, 32));
         foreach (var ed in LayerEditors)
         {
             ed.UpdateDrawOffset(LevelView.ScreenToEditor(new Point(0, 0)));
         }
     }
     else if (e.KeyCode == Keys.Down)
     {
         LevelView.Pan(new PointF(0, -32));
         foreach (var ed in LayerEditors)
         {
             ed.UpdateDrawOffset(LevelView.ScreenToEditor(new Point(0, 0)));
         }
     }
     else if (mouseMode == MouseMode.Normal && e.KeyCode == Keys.Space)
     {
         mouseMode = MouseMode.Pan;
     }
     else if (mouseMode == MouseMode.Normal && e.KeyCode == Keys.C)
     {
         mouseMode = MouseMode.Camera;
     }
     else
     {
         //Call the layer event
         LayerEditors[Ogmo.LayersWindow.CurrentLayerIndex].OnKeyDown(e.KeyCode);
     }
 }
예제 #3
0
        private void onMouseMove(object sender, MouseEventArgs e)
        {
            //Pan the camera if in move mode
            if (mousePanMode)
            {
                if (mouseMode == MouseMode.Camera)
                {
                    //Update the camera position
                    Level.CameraPosition = LevelView.ScreenToEditor(e.Location);
                    foreach (var ed in LayerEditors)
                    {
                        ed.UpdateDrawOffset(Level.CameraPosition);
                    }
                }
                else
                {
                    LevelView.Pan(new Point(e.Location.X - lastMousePoint.X, e.Location.Y - lastMousePoint.Y));
                    lastMousePoint = e.Location;
                }
            }

            //Update the mouse coord display
            MousePosition = LevelView.ScreenToEditor(e.Location);
            Point mouseDraw = Ogmo.Project.LayerDefinitions[Ogmo.LayersWindow.CurrentLayerIndex].SnapToGrid(MousePosition);
            Point gridPos   = Ogmo.Project.LayerDefinitions[Ogmo.LayersWindow.CurrentLayerIndex].ConvertToGrid(MousePosition);

            Ogmo.MainWindow.MouseCoordinatesLabel.Text = "Mouse: ( " + mouseDraw.X.ToString() + ", " + mouseDraw.Y.ToString() + " )";
            Ogmo.MainWindow.GridCoordinatesLabel.Text  = "Grid: ( " + gridPos.X.ToString() + ", " + gridPos.Y.ToString() + " )";

            //Call the layer event
            LayerEditors[Ogmo.LayersWindow.CurrentLayerIndex].OnMouseMove(MousePosition);
        }
예제 #4
0
 private void onKeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Home)
     {
         LevelView.Center();
     }
     else if (e.KeyCode == Keys.Oemplus)
     {
         LevelView.ZoomIn(LevelView.EditorToScreen(MousePosition));
     }
     else if (e.KeyCode == Keys.OemMinus)
     {
         LevelView.ZoomOut(LevelView.EditorToScreen(MousePosition));
     }
     else if (mouseMode == MouseMode.Normal && e.KeyCode == Keys.Space)
     {
         mouseMode = MouseMode.Pan;
     }
     else if (mouseMode == MouseMode.Normal && e.KeyCode == Keys.C)
     {
         mouseMode = MouseMode.Camera;
     }
     else
     {
         //Call the layer event
         LayerEditors[Ogmo.LayersWindow.CurrentLayerIndex].OnKeyDown(e.KeyCode);
     }
 }
예제 #5
0
 private void onMouseWheel(object sender, MouseEventArgs e)
 {
     if (e.Delta > 0)
     {
         LevelView.ZoomIn(e.Location);
     }
     else
     {
         LevelView.ZoomOut(e.Location);
     }
 }
예제 #6
0
        private void onMouseClick(object sender, MouseEventArgs e)
        {
            Focus();
            if (mouseMode != MouseMode.Normal)
            {
                return;
            }

            //Call the layer event
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                LayerEditors[Ogmo.LayersWindow.CurrentLayerIndex].OnMouseLeftClick(LevelView.ScreenToEditor(e.Location));
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                LayerEditors[Ogmo.LayersWindow.CurrentLayerIndex].OnMouseRightClick(LevelView.ScreenToEditor(e.Location));
            }
        }
예제 #7
0
        public LevelEditor(Level level)
            : base()
        {
            Level = level;
            Dock  = System.Windows.Forms.DockStyle.Fill;
            SetAutoSizeMode(AutoSizeMode.GrowAndShrink);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

            LevelView = new LevelView(this);

            //Create the undo/redo stacks
            UndoStack = new LinkedList <OgmoAction>();
            RedoStack = new LinkedList <OgmoAction>();

            //Create the layer editors
            LayerEditors = new List <LayerEditor>();
            foreach (var l in level.Layers)
            {
                LayerEditors.Add(l.GetEditor(this));
            }

            //Init the level BG brush
            BackgroundImage = DrawUtil.ImgBG;
            levelBGBrush    = new SolidBrush(Ogmo.Project.BackgroundColor);
            gridPen         = new Pen(Color.FromArgb(130, Ogmo.Project.GridColor));

            //Events
            Application.Idle += Application_Idle;
            this.Paint       += Draw;
            this.Resize      += onResize;
            this.MouseClick  += onMouseClick;
            this.MouseDown   += onMouseDown;
            this.MouseUp     += onMouseUp;
            this.MouseMove   += onMouseMove;
            this.MouseWheel  += onMouseWheel;
            this.KeyDown     += onKeyDown;
            this.KeyUp       += onKeyUp;
        }
예제 #8
0
        private void onMouseDown(object sender, MouseEventArgs e)
        {
            if (mouseMode != MouseMode.Normal)
            {
                //Enter mouse move mode
                mousePanMode   = true;
                lastMousePoint = e.Location;

                if (mouseMode == MouseMode.Camera)
                {
                    //Update the camera position
                    Level.CameraPosition = LevelView.ScreenToEditor(e.Location);
                    foreach (var ed in LayerEditors)
                    {
                        ed.UpdateDrawOffset(Level.CameraPosition);
                    }
                }
            }
            else
            {
                //Call the layer event
                if (e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    LayerEditors[Ogmo.LayersWindow.CurrentLayerIndex].OnMouseLeftDown(LevelView.ScreenToEditor(e.Location));
                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Right)
                {
                    LayerEditors[Ogmo.LayersWindow.CurrentLayerIndex].OnMouseRightDown(LevelView.ScreenToEditor(e.Location));
                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Middle)
                {
                    //Enter mouse move mode
                    mousePanMode   = true;
                    lastMousePoint = e.Location;
                }
            }
        }
예제 #9
0
 void Application_Idle(object sender, EventArgs e)
 {
     Invalidate();
     LevelView.Update();
 }
예제 #10
0
 private void onResize(object sender, EventArgs e)
 {
     LevelView.OnParentResized();
 }
예제 #11
0
        private void Draw(object sender, PaintEventArgs e)
        {
            long start = DateTime.Now.Ticks / 10000;

            e.Graphics.CompositingQuality = CompositingQuality.HighSpeed;
            e.Graphics.SmoothingMode      = SmoothingMode.HighSpeed;
            e.Graphics.InterpolationMode  = InterpolationMode.NearestNeighbor;
            e.Graphics.Transform          = LevelView.Identity;

            //Draw the background logo
            //e.Graphics.DrawImage(DrawUtil.ImgLogo, new Rectangle(Width / 2 - DrawUtil.ImgLogo.Width / 4, Height / 2 - DrawUtil.ImgLogo.Height / 4, DrawUtil.ImgLogo.Width / 2, DrawUtil.ImgLogo.Height / 2));
            //if (!Focused)
            //    e.Graphics.FillRectangle(NoFocusBrush, new Rectangle(0, 0, Width, Height));

            //Draw the level bg
            e.Graphics.Transform = LevelView.Matrix;
            e.Graphics.FillRectangle(ShadowBrush, new Rectangle(10, 10, Level.Size.Width, Level.Size.Height));
            e.Graphics.FillRectangle(levelBGBrush, new Rectangle(0, 0, Level.Size.Width, Level.Size.Height));

            //Layers below the current one
            int i;

            for (i = 0; i < Ogmo.LayersWindow.CurrentLayerIndex; i++)
            {
                if (Ogmo.Project.LayerDefinitions[i].Visible)
                {
                    LayerEditors[i].DrawHandler(e.Graphics, false, true);
                }
            }

            //Current layer
            LayerEditors[Ogmo.LayersWindow.CurrentLayerIndex].DrawHandler(e.Graphics, true, true);

            //Layers above the current one
            for (i = Ogmo.LayersWindow.CurrentLayerIndex + 1; i < LayerEditors.Count; i++)
            {
                if (i < Ogmo.Project.LayerDefinitions.Count && Ogmo.Project.LayerDefinitions[i].Visible)
                {
                    LayerEditors[i].DrawHandler(e.Graphics, false, Ogmo.MainWindow.TransparentLayers ? false : true);
                }
            }

            //Draw the grid
            if (Ogmo.MainWindow.EditingGridVisible)
            {
                e.Graphics.Transform = LevelView.Identity;

                PointF inc = new PointF(Ogmo.LayersWindow.CurrentLayer.Definition.Grid.Width * LevelView.Zoom, Ogmo.LayersWindow.CurrentLayer.Definition.Grid.Height * LevelView.Zoom);
                while (inc.X <= 5)
                {
                    inc.X *= 2;
                }
                while (inc.Y <= 5)
                {
                    inc.Y *= 2;
                }

                float width  = Ogmo.CurrentLevel.Size.Width * LevelView.Zoom;
                float height = Ogmo.CurrentLevel.Size.Height * LevelView.Zoom;

                PointF offset = LevelView.EditorToScreen(LayerEditors[Ogmo.LayersWindow.CurrentLayerIndex].DrawOffset);

                for (float xx = inc.X; xx < width; xx += inc.X)
                {
                    e.Graphics.DrawLine(gridPen, offset.X + xx, offset.Y, offset.X + xx, offset.Y + height);
                }

                for (float yy = inc.Y; yy < height; yy += inc.Y)
                {
                    e.Graphics.DrawLine(gridPen, offset.X, offset.Y + yy, offset.X + width, offset.Y + yy);
                }

                e.Graphics.DrawRectangle(GridBorderPen, new Rectangle((int)offset.X, (int)offset.Y, (int)width + 1, (int)height));
            }

            //Draw the camera
            if (Ogmo.Project.CameraEnabled)
            {
                e.Graphics.Transform = LevelView.Matrix;
                e.Graphics.DrawRectangle(DrawUtil.CameraRectPen, new Rectangle(Level.CameraPosition.X, Level.CameraPosition.Y, Ogmo.Project.CameraSize.Width, Ogmo.Project.CameraSize.Height));
            }

            long end = DateTime.Now.Ticks / 10000;

            Ogmo.MainWindow.MouseCoordinatesLabel.Text = "Draw time: ( " + (end - start) + "ms )";
        }
예제 #12
0
        protected override void Initialize()
        {
            //Init the screen bounds and camera
            LevelView = new LevelView();
            LevelView.Origin = new Vector2(Width / 2, Height / 2);
            centerCamera();
            DrawBounds = new Rectangle(0, 0, Width, Height);

            //Events
            Repaint = delegate { Invalidate(); };
            Application.Idle += Repaint;
            this.Resize += onResize;
            this.MouseClick += onMouseClick;
            this.MouseDown += onMouseDown;
            this.MouseUp += onMouseUp;
            this.MouseMove += onMouseMove;
            this.MouseWheel += onMouseWheel;
            this.KeyDown += onKeyDown;
            this.KeyUp += onKeyUp;
        }