Ejemplo n.º 1
0
        public RendererParams( Camera camera, 
			UserActionInEditor userActionInEditor, 
			Rectangle selectionRectangle, 
			EntityCreation entityCreation, 
			SnapPoint snapPoint )
        {
            Camera = camera ;
            UserActionInEditor = userActionInEditor ;
            SelectionRectangle = selectionRectangle ;
            EntityCreation = entityCreation ;
            SnapPoint = snapPoint ;
            ItemsToRender=ItemsToRender.Everything;
        }
Ejemplo n.º 2
0
 public void SetModeTo(UserActionInEditor userAction)
 {
     _userActionInEditor = userAction;
 }
Ejemplo n.º 3
0
        public void SetModeToIdle()
        {
            _userActionInEditor = UserActionInEditor.Idle;

            _mainForm.SetCursorForCanvas(Cursors.Default);
        }
Ejemplo n.º 4
0
        void destroyPrimitiveBrush( )
        {
            _userActionInEditor = UserActionInEditor.Idle;

            _mainForm.SetCursorForCanvas(Cursors.Default);
        }
Ejemplo n.º 5
0
        //ItemEditor buildPrimitiveEditorReadyForDesigning( IEntityCreationProperties creationProperties )
        //{
        //    var extensibility = ObjectFactory.GetInstance<IExtensibility>( ) ;
        //    IEditorPlugin plugin = extensibility.FindPluginInstanceForType( creationProperties.PluginType ) ;
        //    var editor = (ItemEditor) Activator.CreateInstance( plugin.EditorType ) ;
        //    editor.CreateInDesignMode( _model.Level.ActiveLayer, creationProperties ) ;
        //    return editor ;
        //}
        //void paintPrimitiveBrush()
        //{
        //    int nextnum = Level.GetNextItemNumber();
        //    IExtensibility extensibility = ObjectFactory.GetInstance<IExtensibility>( ) ;
        //    extensibility.
        //    switch (_currentPrimitive)
        //    {
        //        case PrimitiveType.Rectangle:
        //            ItemEditor rectangleEditor;
        //            if (_customEntity)
        //            {
        //                rectangleEditor = (ItemEditor)Activator.CreateInstance(_customEntityType, Extensions.RectangleFromVectors(_clickedPoints[0], _clickedPoints[1]));
        //            }
        //            else
        //            {
        //                rectangleEditor = new RectangleItemEditor(
        //                    SelectedLayer,
        //                    new CreationProperties
        //                        {
        //                            CurrentMousePosition = _mouseWorldPos,
        //                            ClickPositions = _clickedPoints.ToArray( )
        //                        } ) ;
        //            }
        //            rectangleEditor.ItemProperties.Id = generateID(nextnum);
        //            rectangleEditor.ItemProperties.Name = rectangleEditor.GetNamePrefix() + nextnum;
        //            BeginCommand(string.Format( @"Add Item ""{0}""", rectangleEditor.ItemProperties.Name ));
        //            addItemEditor(rectangleEditor);
        //            EndCommand();
        //            _mainForm.SetToolStripStatusLabel1(Resources.Rectangle_Entered);
        //            break;
        //        case PrimitiveType.Circle:
        //            ItemEditor circleEditor;
        //            if (_customEntity)
        //            {
        //                circleEditor = (ItemEditor)Activator.CreateInstance(_customEntityType, _clickedPoints[0], (_mouseWorldPos - _clickedPoints[0]).Length());
        //            }
        //            else
        //            {
        //                circleEditor = new CircleItemEditor(
        //                    SelectedLayer,
        //                    new CreationProperties
        //                        {
        //                            CurrentMousePosition = _mouseWorldPos,
        //                            ClickPositions = _clickedPoints.ToArray(  )
        //                        } );
        //            }
        //            circleEditor.ItemProperties.Id = generateID(nextnum);
        //            circleEditor.ItemProperties.Name = circleEditor.GetNamePrefix() + nextnum;// level.getNextItemNumber();
        //            BeginCommand(string.Format( "Add Item \"{0}\"", circleEditor.ItemProperties.Name ));
        //            addItemEditor(circleEditor);
        //            EndCommand();
        //            _mainForm.SetToolStripStatusLabel1(Resources.Circle_Entered);
        //            break;
        //        case PrimitiveType.Path:
        //            PathItemEditor itemEditor;
        //            if (_customEntity)
        //            {
        //                itemEditor = (PathItemEditor)Activator.CreateInstance(_customEntityType, _clickedPoints.ToArray());
        //            }
        //            else
        //            {
        //                itemEditor = new PathItemEditor(
        //                    SelectedLayer,
        //                    new CreationProperties
        //                        {
        //                            ClickPositions = _clickedPoints.ToArray( )
        //                        } ) ;
        //            }
        //            itemEditor.ItemProperties.Id = generateID(nextnum);
        //            itemEditor.ItemProperties.Name = itemEditor.GetNamePrefix()+nextnum;//
        //            BeginCommand(string.Format( "Add Item \"{0}\"", itemEditor.ItemProperties.Name ));
        //            addItemEditor(itemEditor);
        //            EndCommand();
        //            _mainForm.SetToolStripStatusLabel1(Resources.Path_Entered);
        //            break;
        //    }
        //    UpdateTreeView();
        //}
        void startMoving( )
        {
            _grabbedPoint = MouseStatus.WorldPosition ;

            //save the distance to mouse for each item
            _positionsBeforeUserInteraction.Clear( ) ;

            foreach( ItemEditor selitem in selectedEditors( ) )
            {
                _positionsBeforeUserInteraction.Add( selitem.ItemProperties.Position ) ;
            }

            _userActionInEditor = UserActionInEditor.MovingItems ;
        }
Ejemplo n.º 6
0
        void startCreatingEntity( IEntityCreationProperties properties, bool addToCanvasNow )
        {
            if( _model.Level.ActiveLayer == null )
            {
                MessageBox.Show( Resources.No_Layer ) ;

                return ;
            }

            _userActionInEditor = UserActionInEditor.AddingAnItem ;

            _mainForm.SetCursorForCanvas( Cursors.Cross ) ;

            _entityCreation.StartedCreating = addToCanvasNow ;
            _entityCreation.CreationProperties = properties ;

            var extensibility = ObjectFactory.GetInstance<IExtensibility>( ) ;

            var plugin = extensibility.FindPluginInstanceForType( properties.PluginType ) ;

            var newEditor = (ItemEditor) Activator.CreateInstance( plugin.EditorType ) ;

            newEditor.WhenChosenFromToolbox( ) ;

            if (addToCanvasNow)
            {
                newEditor.CreateInDesignMode( _model.Level.ActiveLayer, _entityCreation.CreationProperties ) ;
                _entityCreation.CurrentEditor = newEditor;
            }
        }
Ejemplo n.º 7
0
        public void CreateSelectionRectangle()
        {
            _model.SelectLayer( _model.ActiveLayer ) ;

            _grabbedPoint = MouseStatus.WorldPosition ;
            _selectionRectangle = Rectangle.Empty ;
            _userActionInEditor = UserActionInEditor.CreatingSelectionBoxByDragging ;
            _model.SelectLayer( _model.ActiveLayer ) ;
        }
Ejemplo n.º 8
0
 public void StopCreatingEntity()
 {
     _userActionInEditor=UserActionInEditor.Idle;
 }
Ejemplo n.º 9
0
        void destroyPrimitiveBrush( )
        {
            _userActionInEditor = UserActionInEditor.Idle ;

            _mainForm.SetCursorForCanvas( Cursors.Default ) ;
        }
Ejemplo n.º 10
0
        public void StartRotatingItems()
        {
            _grabbedPoint = MouseStatus.WorldPosition - selectedEditors( ).First( ).ItemProperties.Position ;

            //save the initial rotation for each item
            _rotationsBeforeUserInteraction.Clear( ) ;

            foreach( ItemEditor eachSelectedItem in selectedEditors( ) )
            {
                if( eachSelectedItem.CanRotate( ) )
                {
                    _rotationsBeforeUserInteraction.Add( eachSelectedItem.Rotation ) ;
                }
            }

            _userActionInEditor = UserActionInEditor.RotatingItems ;
            _mainForm.SetCursorForCanvas( _cursorRotate ) ;

            IoC.Memento.BeginCommand( "Rotate Item(s)" ) ;
        }
Ejemplo n.º 11
0
        public void StartScalingSelectedItems()
        {
            _grabbedPoint = MouseStatus.WorldPosition - selectedEditors( ).First( ).ItemProperties.Position ;

            //save the initial scale for each item
            _scalesBeforeUserInteraction.Clear( ) ;
            foreach( ItemEditor selitem in selectedEditors( ) )
            {
                if( selitem.CanScale )
                {
                    _scalesBeforeUserInteraction.Add( selitem.Scale ) ;
                }
            }

            _userActionInEditor = UserActionInEditor.ScalingItems ;

            _mainForm.SetCursorForCanvas( _cursorScale ) ;

            IoC.Memento.BeginCommand( "Scale Item(s)" ) ;
        }
Ejemplo n.º 12
0
 public void StartMovingCamera()
 {
     _grabbedPoint = MouseStatus.ScreenPosition ;
     _initialCameraPosition = Camera.Position ;
     _userActionInEditor = UserActionInEditor.MovingTheCamera ;
     _mainForm.SetCursorForCanvas( Cursors.SizeAll ) ;
 }
Ejemplo n.º 13
0
        public void SetModeToIdle()
        {
            _userActionInEditor = UserActionInEditor.Idle ;

            _mainForm.SetCursorForCanvas( Cursors.Default ) ;
        }
Ejemplo n.º 14
0
 public void SetModeTo( UserActionInEditor userAction )
 {
     _userActionInEditor = userAction ;
 }
Ejemplo n.º 15
0
 public void StopCreatingEntity()
 {
     _userActionInEditor = UserActionInEditor.Idle;
 }
Ejemplo n.º 16
0
        public Canvas( IMainForm mainForm, IModel model )
        {
            _inputHandlerForWhenEditorIdle = new InputHandlerForWhenEditorIdle( this );
            _inputHandlerForWhenMovingOrCopyingItems = new InputHandlerForWhenMovingOrCopyingItems( this );
            _inputHandlerWhenRotatingItems = new InputHandlerWhenRotatingItems( this );
            _inputHandlerWhenScalingItems = new InputHandlerWhenScalingItems( this );
            _inputHandlerWhenCreatingTheSelectionRectangle = new InputHandlerWhenCreatingTheSelectionRectangle( this );

            _mainForm = mainForm ;

            _model = model ;

            _model.NewModelLoaded += newModelLoaded ;

            _entityCreation = new EntityCreation( whenEntityReadyToBeAdded: ( ) =>
                    {
                        addTheEntityCurrentlyBeingCreated( ) ;
                        _entityCreation.ClearCurrentEditor( ) ;
                        _entityCreation.StartedCreating = false ;
                    } ) ;

            _inputActionLookup = new Dictionary<UserActionInEditor, Action>
                {
                    {
                        UserActionInEditor.Idle, _inputHandlerForWhenEditorIdle.Update
                        },
                    {
                        UserActionInEditor.MovingItems, _inputHandlerForWhenMovingOrCopyingItems.Update
                        },
                    {
                        UserActionInEditor.CopyingItems, _inputHandlerForWhenMovingOrCopyingItems.Update
                        },
                    {
                        UserActionInEditor.RotatingItems, _inputHandlerWhenRotatingItems.Update
                        },
                    {
                        UserActionInEditor.ScalingItems, _inputHandlerWhenScalingItems.Update
                        },
                    {
                        UserActionInEditor.MovingTheCamera, handleUpdateWhenMovingTheCamera
                        },
                    {
                        UserActionInEditor.CreatingSelectionBoxByDragging, _inputHandlerWhenCreatingTheSelectionRectangle.Update
                        },
                    {
                        UserActionInEditor.AddingAnItem, handleInputWhenAddingAnEntity
                        },
                } ;

            _userActionInEditor = UserActionInEditor.Idle ;

            _positionsBeforeUserInteraction = new List<Vector2>( ) ;

            _rotationsBeforeUserInteraction = new List<float>( ) ;

            _scalesBeforeUserInteraction = new List<Vector2>( ) ;

            Stream stream = safeGetManifestResourceStream(@"Oglr.Resources.cursors.dragcopy.cur");

            new Cursor( stream ) ;

            stream = safeGetManifestResourceStream(@"Oglr.Resources.cursors.rotate.cur");
            _cursorRotate = new Cursor( stream ) ;

            stream = safeGetManifestResourceStream(@"Oglr.Resources.cursors.scale.cur");
            _cursorScale = new Cursor( stream ) ;

            Constants.TryToLoadOtherwiseSetDefaults( @"settings.xml" ) ;
        }
Ejemplo n.º 17
0
 public void CancelCreatingEntity()
 {
     _entityCreation.ClearCurrentEditor();
     _userActionInEditor = UserActionInEditor.Idle;
 }
Ejemplo n.º 18
0
        void handleUpdateWhenMovingTheCamera( )
        {
            Vector2 distance = ( MouseStatus.ScreenPosition - _grabbedPoint ) / Camera.Scale ;
            if( distance.Length( ) > 0 )
            {
                Camera.Position = _initialCameraPosition - distance ;
            }

            if( MouseStatus.MiddleButton == ButtonState.Released )
            {
                _userActionInEditor = UserActionInEditor.Idle ;
                _mainForm.SetCursorForCanvas( Cursors.Default ) ;
            }
        }
Ejemplo n.º 19
0
 void drawCurrentItemBeingCreatedIfNeeded( UserActionInEditor userActionInEditor, EntityCreation entityCreation )
 {
     if( userActionInEditor == UserActionInEditor.AddingAnItem && entityCreation.StartedCreating )
     {
         entityCreation.CurrentEditor.DrawInEditor( _game.SpriteBatch ) ;
     }
 }
Ejemplo n.º 20
0
 public void CancelCreatingEntity()
 {
     _entityCreation.ClearCurrentEditor();
     _userActionInEditor=UserActionInEditor.Idle;
 }