View.cs :  » Game » SDL » SdlDotNetExamples » Isotope » 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 » Isotope » View.cs
#region LICENSE
/* 
 * (c) 2005 Simon Gillespie
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; 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.Drawing;

using SdlDotNet.Graphics;

namespace SdlDotNetExamples.Isotope{
    /// <summary>
    /// 
    /// </summary>
    public class View
    {
        /*Draws a scene in an isometric view 

           surface: The surface to draw the isometric view into: surface class
           scene: The scene to draw in the isometric view: scene class
           skin_group: The skins to use for the images representing the objects: list of skin class
           display_offset: 2 dimensional vector of the offset for the 0,0,0 origin point
              in the view: list of 2 integers [x,y]

           old_rect: The areas of the view that are tagged to be updated: list of rect class
        */

        //private int[] viewSize ={ 400, 300 };

        //remember the surface
        Surface surface;

        public Surface Surface
        {
            get { return surface; }
            set { surface = value; }
        }
        //offset from the top left corner of the window for the isotope display
        private int[] displayOffset = { 200, 150 };

        private Rectangle[] oldRect ={ };

        // Initialize
        public View(Surface surface, Scene scene, Skin[] skinGroup, int[] displayOffset)
        {
            //Dimensions of the window for the isotope display
            //view_size=(int[])surface.GetSize();
            //remember the surface
            this.surface = surface;
            //offset from the top left corner of the window for the isotope display
            this.displayOffset = displayOffset;
            RedrawDisplay(scene, skinGroup);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="skin_group"></param>
        public void DisplayUpdate(Scene scene, Skin[] skinGroup)
        {
            if (scene == null)
            {
                throw new ArgumentNullException("scene");
            }
            if (skinGroup == null)
            {
                throw new ArgumentNullException("skinGroup");
            }
            // Updates the isometric display using update rectangles
            // Clear the old sprite positions with the background
            Surface background = (Surface)skinGroup[scene.SceneType].Images[0];
            //Surface subsurface;
            if (oldRect.Length > 0)
            {
                foreach (Rectangle clear_rect in oldRect)
                {
                    //subsurface=background.CreateSurfaceFromClipRectangle(clear_rect);
                    Surface.Blit(background, clear_rect, clear_rect);
                }
            }
            // Update Isometric view
            // Copy the scene objects Array List KLUDGY!!!
            Object3d[] objectGroup = new Object3d[scene.ObjectGroup.Count];
            //for(int obj=0;obj<=scene.objectGroup.Count;obj++)
            //   objectGroup[obj]=scene.objectGroup[obj];
            scene.ObjectGroup.CopyTo(objectGroup, 0);
            oldRect = Isometric.ViewUpdate(Surface, objectGroup, skinGroup,
                displayOffset, oldRect);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="skin_group"></param>
        public void RedrawDisplay(Scene scene, Skin[] skinGroup)
        {
            if (scene == null)
            {
                throw new ArgumentNullException("scene");
            }
            if (skinGroup == null)
            {
                throw new ArgumentNullException("skinGroup");
            }
            // Redraws the entire display, including background
            //Display the background
            //Console.WriteLine(scene);
            Surface.Blit((Surface)skinGroup[scene.SceneType].Images[0], ((Surface)skinGroup[scene.SceneType].Images[0]).Rectangle);
            Surface.Update();
            DisplayUpdate(scene, skinGroup);
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.