SpriteDemosMain.cs :  » Game » SDL » SdlDotNetExamples » LargeDemos » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » SDL 
SDL » SdlDotNetExamples » LargeDemos » SpriteDemosMain.cs
#region LICENSE
/*
 * $RCSfile: SpriteGuiDemosMain.cs,v $
 * Copyright (C) 2004 D. R. E. Moonfire (d.moonfire@mfgames.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
#endregion LICENSE

using System;
using System.IO;
using System.Collections;
using System.Drawing;
using System.Threading;
using System.Globalization;
using System.Collections.Generic;

using SdlDotNet.Graphics;
using SdlDotNet.Graphics.Sprites;
using SdlDotNet.Input;
using SdlDotNet.Core;
using SdlDotNetExamples.SpriteDemos;

namespace SdlDotNetExamples.LargeDemos{
    /// <summary>
    /// The SpriteDemosMain is a general testbed and display of various features
    /// in the SDL.NET library. It includes animated sprites and
    /// movement. To run, it currently assumes that the current
    /// directory has a "Data" directory underneath it containing
    /// various images.
    /// </summary>
    public class SpriteDemosMain : IDisposable
    {
        static int width = 800;
        static int height = 600;

        /// <summary>
        /// 
        /// </summary>
        [STAThread]
        public static void Run()
        {
            // Create the demo application
            SpriteDemosMain demo = new SpriteDemosMain();
            demo.Go();
        }

        /// <summary>
        /// 
        /// </summary>
        public void Go()
        {
            Video.WindowIcon();
            Video.WindowCaption = "SDL.NET - Sprite Demos";
            screen = Video.SetVideoMode(width, height);
            Events.Fps = 100;
            Events.KeyboardDown +=
                new EventHandler<KeyboardEventArgs>(this.KeyboardDown);
            Events.Tick += new EventHandler<TickEventArgs>(this.Tick);
            Events.Quit += new EventHandler<QuitEventArgs>(this.Quit);

            //// Load demos
            //LoadDemos();
            SwitchDemo(0);

            Events.Run();
        }

        #region Demos
        //private List<DemoMode> demos = new List<DemoMode>();

        private DemoMode currentDemo;

        

        //private void LoadDemo(DemoMode mode)
        //{
        //    // Add to the array list
        //    demos.Add(mode);
        //}

        //private void LoadDemos()
        //{
            // Load the actual demos
            //LoadDemo(new BounceMode());
            //LoadDemo(new FontMode());
            //LoadDemo(new DragMode());
            //LoadDemo(new ViewportMode());
            //LoadDemo(new MultipleMode());
        //}

        private void StopDemo()
        {
            // Stop the demo, if any
            if (currentDemo != null)
            {
                currentDemo.Stop();
                //currentDemo.Dispose();
                currentDemo = null;
            }
            //System.GC.Collect();
        }

        int demo = 1;

        private void SwitchDemo(int demo)
        {
            //// Ignore if the demo request is too high
            //if (demo < 0 || demo + 1 > demos.Count)
            //{
            //    return;
            //}
            if (demo != this.demo)
            {
                this.demo = demo;
                // Stop the demo, if any
                StopDemo();

                switch (demo)
                {
                    case 0:
                        currentDemo = new BounceMode();
                        currentDemo.Start();
                        break;
                    case 1:
                        currentDemo = new FontMode();
                        currentDemo.Start();
                        break;
                    case 2:
                        currentDemo = new DragMode();
                        currentDemo.Start();
                        break;
                    case 3:
                        currentDemo = new ViewportMode();
                        currentDemo.Start();
                        break;
                    case 4:
                        currentDemo = new MultipleMode();
                        currentDemo.Start();
                        break;
                    default:
                        currentDemo = new BounceMode();
                        currentDemo.Start();
                        break;
                }

                //// Start it
                //currentDemo = demos[demo];
                //currentDemo.Start();
            }
        }
        #endregion

        #region Events

        private void KeyboardDown(object sender, KeyboardEventArgs e)
        {
            switch (e.Key)
            {
                case Key.Escape:
                case Key.Q:
                    Events.QuitApplication();
                    break;
                case Key.C:
                    StopDemo();
                    break;
                case Key.One:
                    SwitchDemo(0);
                    break;
                case Key.Two:
                    SwitchDemo(1);
                    break;
                case Key.Three:
                    SwitchDemo(2);
                    break;
                case Key.Four:
                    SwitchDemo(3);
                    break;
                case Key.Five:
                    SwitchDemo(4);
                    break;
                case Key.M:
                    Video.IconifyWindow();
                    break;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void Tick(object sender, TickEventArgs args)
        {
            screen.Fill(Color.Black);
            if (currentDemo != null)
            {
                screen.Blit(currentDemo.RenderSurface());
            }
            screen.Update();
        }

        private void Quit(object sender, QuitEventArgs e)
        {
            Events.QuitApplication();
        }

        #endregion

        #region Properties

        private Surface screen;

        /// <summary>
        /// 
        /// </summary>
        public static Size Size
        {
            get
            {
                return new Size(width, height);
            }
        }
        #endregion

        /// <summary>
        /// Lesson Title
        /// </summary>
        public static string Title
        {
            get
            {
                return "SpriteDemos: Several demos showing sprites.";
            }
        }

        #region IDisposable Members

        private bool disposed;


        /// <summary>
        /// Closes and destroys this object
        /// </summary>
        /// <remarks>Destroys managed and unmanaged objects</remarks>
        public void Dispose()
        {
            Dispose(true);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="disposing"></param>
        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    this.screen.Dispose();
                    if (currentDemo != null)
                    {
                        currentDemo.Dispose();
                        currentDemo = null;
                    }
                }
                this.disposed = true;
            }
        }
        #endregion
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.