RenderableElement.cs :  » Game » RealmForge » CrayzEdsGui » Base » 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 » RealmForge 
RealmForge » CrayzEdsGui » Base » RenderableElement.cs
#region LGPL License

/*************************************************************************
    Crazy Eddie's GUI System (http://crayzedsgui.sourceforge.net)
    Copyright (C)2004 Paul D Turner (crayzed@users.sourceforge.net)
  
  C# Port developed by Chris McGuirk (leedgitar@latenitegames.com)
  Compatible with the Axiom 3D Engine (http://axiomengine.sf.net)

    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 LGPL License

#region Using directives

using System;
using System.Text;

#endregion

namespace CrayzEdsGui.Base{
  /// <summary>
  ///    Base class for all renderable elements.
  /// </summary>
  public abstract class RenderableElement {
    #region Fields

    /// <summary>
    ///    Link to another RenderableElement.
    /// </summary>
    protected RenderableElement next;
    /// <summary>
    ///    Colors to be used for this element.
    /// </summary>
    protected ColorRect colors;
    /// <summary>
    ///    Currently defined area for this element.
    /// </summary>
    protected Rect area;

    #endregion Fields

    #region Constructors

    /// <summary>
    ///    Constructor.
    /// </summary>
    public RenderableElement() {
      colors = new ColorRect();
      area = new Rect(0, 0, 0, 0);
    }

    #endregion Constructors

    #region Base Members

    #region Methods

    /// <summary>
    ///    Draw the element chain starting with this element.
    /// </summary>
    /// <param name="position">
    ///    Vector3 object describing the base position to be used when rendering the element chain.  Each element
    ///    in the chain will be offset from this position by it's own internal position setting.
    /// </param>
    /// <param name="clipRect">Rect describing the clipping area.  No rendering will appear outside this area.</param>
    public void Draw(Vector3 position, Rect clipRect) {
      Vector3 finalPosition = position;
      finalPosition.x += area.left;
      finalPosition.y += area.top;

      // call implementation method for perform actual rendering
      DrawImpl(finalPosition, clipRect);

      // render the next element in the chain (if any)
      if(next != null) {
        next.Draw(position, clipRect);
      }
    }

    /// <summary>
    ///    Sets the colors to be applied when rendering the element.
    /// </summary>
    /// <param name="colors">ColorRect object describing the colors to be used.</param>
    public void SetColors(ColorRect colors) {
      this.colors = colors;
    }

    /// <summary>
    ///    Sets the colors to be applied when rendering the element.
    /// </summary>
    /// <param name="topLeft">Color to be applied to the top-left corner of each Image used in the element.</param>
    /// <param name="topRight">Color to be applied to the top-right corner of each Image used in the element.</param>
    /// <param name="bottomLeft">Color to be applied to the bottom-left corner of each Image used in the element.</param>
    /// <param name="bottomRight">Color to be applied to the bottom-right corner of each Image used in the element.</param>
    public void SetColors(Color topLeft, Color topRight, Color bottomLeft, Color bottomRight) {
      colors.topLeft = topLeft;
      colors.topRight = topRight;
      colors.bottomLeft = bottomLeft;
      colors.bottomRight = bottomRight;
    }

    #endregion Methods

    #region Properties

    /// <summary>
    ///    Get the rendering colors set for this RenderableElement.
    /// </summary>
    /// <value>ColourRect describing the colors to be used when rendering this RenderableElement.</value>
    public ColorRect Colors {
      get {
        return colors;
      }
    }

    /// <summary>
    ///    Get/Set another REnderableElement to this one.
    /// </summary>
    /// <remarks>
    ///    The linked element will be drawn whenever this element is drawn using the same base position and clipping area
    ///    as provided when the <see cref="RenderableElement.Draw"/> method is called.  Whole chains of Renderable Elements can be
    ///    created using this system.
    /// </remarks>
    /// <value>Reference of a RenderableElement object that will be linked to this element.</value>
    public RenderableElement NextElement {
      get {
        return next;
      }
      set {
        next = value;
      }
    }

    /// <summary>
    ///    Get/Set the offset position of this RenderableElement.
    /// </summary>
    /// <value>
    ///    Point describing the offset position that this RenderableElement is to be rendered at.  This
    ///    value is added to whatever position is specified when the <see cref="RenderableElement.Draw"/> method 
    ///    is called to obtain the final rendering position.
    /// </value>
    public Point Position {
      get {
        return new Point(area.left, area.top);
      }
      set {
        area.Position = value;
      }
    }

    /// <summary>
    ///    Get/Set the area for the element.
    /// </summary>
    /// <value>Rect describing the pixel area (offset from some unknown location) of the frame.</value>
    public Rect Rect {
      get {
        return area;
      }
      set {
        area = value;
      }
    }

    /// <summary>
    ///    Get/Set the size of this element.
    /// </summary>
    /// <value>Size object describing the current size of the RenderableElement.</value>
    public Size Size {
      get {
        return area.Size;
      }
      set {
        area.Size = value;
      }
    }

    #endregion Properties

    #endregion Base Members

    #region Abstract Members

    #region Methods

    /// <summary>
    ///    This function performs the required rendering for this element.
    /// </summary>
    /// <param name="position">Vector3 describing the final rendering position for the object.</param>
    /// <param name="clipRect">Rect describing the clipping area for the rendering.  No rendering will be performed outside this area.</param>
    protected abstract void DrawImpl(Vector3 position, Rect clipRect);

    #endregion Methods

    #endregion Abstract Members
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.