private void OnShown(object sender, EventArgs e)
        {
            previewGame = new AnimationGame(pictureBox_AnimationPreview.Handle, this, pictureBox_AnimationPreview, new Vector2(pictureBox_AnimationPreview.Width, pictureBox_AnimationPreview.Height));
            previewManager = new GraphicsManager(previewGame.gameGraphics);
            previewGame.gameForm.GotFocus += delegate(object o, EventArgs args)
            {
                this.Focus();
            };
            previewGame.gameGraphics.GraphicsManager.DeviceCreated += delegate(object o, EventArgs args)
            {
                previewGame.gameGraphics.AddTexture(animationTexture.Name, TextureManager.ConvertDataToTexture(animationTexture, previewGame.GraphicsDevice));
                previewGame.gameGraphics.AddDrawable(previewAnimation);
                Vector2 center = StaticMethods.GetCenter(new Vector2(previewAnimation.Frames[1].TextureSource.Width,previewAnimation.Frames[1].TextureSource.Height));
                Vector2 position = StaticMethods.GetDrawPosition(new Vector2(panel_AnimationPreview.Width, panel_AnimationPreview.Height), center);
                previewGame.gameGraphics.AddToDrawList(new DrawParam(previewAnimation.Name, previewAnimation.Name,position, DrawnType.Animation));
                LoopAction loopActon = new LoopAction
                {
                    Name = previewAnimation.Name,
                    Drawable = previewAnimation.Name,
                    Value = true
                };
                previewManager.ExecuteAction(loopActon);

            };
            previewGame.Run();
        }
 private void listBox_Animations_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listBox_Animations.SelectedItem == null)
     {
         btn_Delete.Enabled = false;
         btn_Edit.Enabled = false;
         return;
     }
     btn_Delete.Enabled = true;
     btn_Edit.Enabled = true;
     SelectedAnimation = listBox_Animations.SelectedItem.ToString();
     Animation animation = Game.gameGraphics.GetAnimation(SelectedAnimation);
     if (animation.FrameCount > 0)
     {
         Vector2 center = StaticMethods.GetCenter(new Vector2(animation.Frames[1].TextureSource.Width, animation.Frames[1].TextureSource.Height));
         Vector2 position = StaticMethods.GetDrawPosition(new Vector2(panel_AnimationPreview.Width, panel_AnimationPreview.Height), center);
         Game.gameGraphics.ClearDrawList();
         Game.gameGraphics.AddToDrawList(new DrawParam(SelectedAnimation, SelectedAnimation, position, DrawnType.Animation));
         LoopAction loopAction = new LoopAction
         {
             Name = "Loop current animation",
             Drawable = animation.Name,
             Value = true
         };
         graphicsManager.ExecuteAction(loopAction);
     }
 }
        //Send actions to make sure that the Texture continues displaying
        private void MakeTextureLoopFrame(string textureName)
        {
            FrameAction frameAction = new FrameAction
            {
                Name = textureName,
                Drawable = textureName,
                Value = 1
            };
            StatusAction statusAction = new StatusAction
            {
                Name = textureName,
                Drawable = textureName,
                Value = AnimationStatus.Paused
            };
            LoopAction loopActon = new LoopAction
            {
                Name = textureName,
                Drawable = textureName,
                Value = true
            };

            textureManager.ExecuteAction(statusAction);
            textureManager.ExecuteAction(frameAction);
            textureManager.ExecuteAction(loopActon);
        }
        //When something is selected from the listbox, display it on the Current Frame screen
        private void listBox_Frames_SelectedIndexChanged(object sender, EventArgs e)
        {
            Action action = () =>
            {
                if (listBox_Frames.SelectedItem == null)
                {
                    DisableFrameButtons();
                    return;
                }

                EnableFrameButtons();

                int selectedFrame = (int) listBox_Frames.SelectedItem;
                SetFieldsFromFrame(ReturnAnimation.Frames[selectedFrame]);
                lbl_FrameNumber.Text = selectedFrame.ToString();
                float width = ReturnAnimation.Frames[selectedFrame].TextureSource.Width;
                float height = ReturnAnimation.Frames[selectedFrame].TextureSource.Height;

                _frameGame.gameGraphics.ClearDrawList();

                Vector2 position = Vector2.Zero;

                if (width <= panel_FrameDisplay.Width && height <= panel_FrameDisplay.Height)
                {
                    Vector2 center =
                        StaticMethods.GetCenter(new Vector2(((width)*ReturnAnimation.Scale), (height)*ReturnAnimation.Scale));
                    position = StaticMethods.GetDrawPosition(new Vector2(panel_FrameDisplay.Width, panel_FrameDisplay.Height), center);
                }
                if (width > panel_FrameDisplay.Width || height > panel_FrameDisplay.Height)
                {
                    panel_FrameDisplay.AutoScrollMinSize = new Size((int) width, (int) height);
                    pictureBox_FrameDisplay.Location = new System.Drawing.Point(0, 0);
                }

                if (!_frameGame.gameGraphics.DoesDrawableExist(ReturnAnimation.Name))
                {
                    _frameGame.gameGraphics.AddToDrawList(new DrawParam(ReturnAnimation.Name, ReturnAnimation.Name,
                        position, DrawnType.Animation));
                }
                else
                {
                    _frameGame.gameGraphics.UpdateDrawPosition(new DrawParam(ReturnAnimation.Name, ReturnAnimation.Name,
                        position, DrawnType.Animation));
                }
                Animation drawAnimation = _frameGame.gameGraphics.GetDrawAnimation(ReturnAnimation.Name);
                drawAnimation.Frame = selectedFrame;
                _frameGame.gameGraphics.SetLoadedDrawn(drawAnimation);
                SetFrameData(saving);

                FrameAction frameAction = new FrameAction
                {
                    Name = ReturnAnimation.Name,
                    Drawable = ReturnAnimation.Name,
                    Value = selectedFrame
                };
                StatusAction statusAction = new StatusAction
                {
                    Name = ReturnAnimation.Name,
                    Drawable = ReturnAnimation.Name,
                    Value = AnimationStatus.Paused
                };
                LoopAction loopActon = new LoopAction
                {
                    Name = ReturnAnimation.Name,
                    Drawable = ReturnAnimation.Name,
                    Value = true
                };

                animationManager.ExecuteAction(statusAction);
                animationManager.ExecuteAction(frameAction);
                animationManager.ExecuteAction(loopActon);
            };
            if (!_frameGameLoaded)
            {
                LoadFrameGame(action);
                return;
            }
            action();
        }
        private void listBox_SpriteSheets_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox_SpriteSheets.SelectedItem == null)
            {
                DisableFields();
                return;
            }
            EnableFields();
            Game.gameGraphics.ClearDrawList();

            panel_SpriteSheetPreview.AutoScroll = true;

            string textureName = listBox_SpriteSheets.SelectedItem.ToString();
            int height = Game.gameGraphics.textureManager.Textures[textureName].Height;
            int width = Game.gameGraphics.textureManager.Textures[textureName].Width;
            Game.SetGameHeight(height);
            Game.SetGameWidth(width);
            panel_SpriteSheetPreview.AutoScrollMinSize = new Size(Game.gameGraphics.textureManager.Textures[listBox_SpriteSheets.SelectedItem.ToString()].Width, Game.gameGraphics.textureManager.Textures[listBox_SpriteSheets.SelectedItem.ToString()].Height);
            pictureBox_SpriteSheetPreview.Location = new System.Drawing.Point(0, 0);

            lbl_HeightValue.Text = height.ToString();
            lbl_WidthValue.Text = width.ToString();
            txtBox_SheetName.Text = textureName;

            Game.gameGraphics.AddToDrawList(new DrawParam(textureName, textureName, new Vector2(0, 0), DrawnType.Animation));
            LoopAction loopAnimation = new LoopAction
            {
                Name = "loop " + textureName,
                Drawable = textureName,
                Value = true
            };
            graphicsManager.ExecuteAction(loopAnimation);
            selectedTexture = Game.gameGraphics.textureManager.Textures[textureName];
        }