Exemplo n.º 1
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");
        }
Exemplo n.º 2
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" ) ;
        }