StaticImage.cs :  » Game » RealmForge » CrayzEdsGui » Base » Widgets » 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 » Widgets » StaticImage.cs
using System;

namespace CrayzEdsGui.Base.Widgets{
  /// <summary>
  ///    Static image widget class.
  /// </summary>
  /// <remarks>
  ///    This base class performs it's own rendering.  There is no need to override this widget to perform rendering
  ///    of static images.
  /// </remarks>
  public class StaticImage : Static {
    #region Fields

    /// <summary>
    ///    RenderableImage that does most of the work for us.
    /// </summary>
    protected RenderableImage image = new RenderableImage();
    /// <summary>
    ///    Colors to use for the image.
    /// </summary>
    protected ColorRect imageColors = new ColorRect();

    #endregion Fields

    #region Constructor

    /// <summary>
    ///    Constructor.
    /// </summary>
    /// <param name="name">Name of this widget.</param>
    public StaticImage(string name) : base(name) {
      Color white = new Color(1,1,1,1);

      imageColors = new ColorRect(white, white, white, white);

      // default to stretched image
      image.HorizontalFormat = HorizontalImageFormat.Stretched;
      image.VerticalFormat = VerticalImageFormat.Stretched;
    }

    #endregion Constructor

    #region Members

    #region Properties

    /// <summary>
    ///    Return a reference to the current image displayed by this widget.
    /// </summary>
    [WidgetProperty("Image")]
    public Image Image {
      get {
        return image.Image;
      }
    }

    /// <summary>
    ///    Set the formatting required for the image.
    /// </summary>
    /// <value>One of the <see cref="HorizontalImageFormat"/> enumerated values specifying the formatting required.</value>
    [HorzizontalImageFormatProperty( "HorzFormatting" )]
    public HorizontalImageFormat HorizontalFormat {
      get {
        return image.HorizontalFormat;
      }
      set {
        image.HorizontalFormat = value;
        RequestRedraw();
      }
    }

    /// <summary>
    ///    Set the formatting required for the image.
    /// </summary>
    /// <value>One of the <see cref="VerticalImageFormat"/> enumerated values specifying the formatting required.</value>
    [VerticalImageFormatProperty( "VertFormatting" )]
    public VerticalImageFormat VerticalFormat {
      get {
        return image.VerticalFormat;
      }
      set {
        image.VerticalFormat = value;
        RequestRedraw();
      }
    }

    #endregion Properties

    #region Methods

    /// <summary>
    ///    Set the <see cref="Image"/> object to be drawn by this widget.
    /// </summary>
    /// <param name="image">
    ///    Reference to the <see cref="Image"/> object to be rendered.  
    ///    Can be 'null' to specify no image is to be rendered.
    ///  </param>
    public void SetImage(Image image) {
      this.image.Image = image;
      RequestRedraw();
    }

    /// <summary>
    ///    Set the <see cref="Image"/> object to be drawn by this widget.
    /// </summary>
    /// <param name="imagesetName">Imageset that the image is contained in.</param>
    /// <param name="imageName">Name of the image within the specified imageset.</param>
    public void SetImage(string imagesetName, string imageName) {
      SetImage(ImagesetManager.Instance.GetImageset(imagesetName).GetImage(imageName));
    }

    /// <summary>
    ///    
    /// </summary>
    /// <param name="colors"></param>
    public void SetImageColors(ColorRect colors) {
      imageColors = colors;
      UpdateRenderableImageColors();
      RequestRedraw();
    }

    /// <summary>
    ///    
    /// </summary>
    /// <param name="topLeft"></param>
    /// <param name="topRight"></param>
    /// <param name="bottomLeft"></param>
    /// <param name="bottomRight"></param>
    public void SetImageColors(Color topLeft, Color topRight, Color bottomLeft, Color bottomRight) {
      imageColors.topLeft = topLeft;
      imageColors.topRight = topRight;
      imageColors.bottomLeft = bottomLeft;
      imageColors.bottomRight = bottomRight;

      UpdateRenderableImageColors();

      RequestRedraw();
    }

    /// <summary>
    ///    Update the internal RenderableImaeg with currently set colors and alpha settings.
    /// </summary>
    protected void UpdateRenderableImageColors() {
      float alpha = EffectiveAlpha;

      ColorRect colors = image.Colors;
      colors.topLeft = imageColors.topLeft;
      colors.topRight = imageColors.topRight;
      colors.bottomLeft = imageColors.bottomLeft;
      colors.bottomRight = imageColors.bottomRight;
      colors.SetAlpha(alpha);
    }

    #endregion Methods

    #endregion Members

    #region Window Members

    /// <summary>
    ///    Perform the actual rendering for this Window.
    /// </summary>
    /// <param name="z">float value specifying the base Z co-ordinate that should be used when rendering.</param>
    protected override void DrawSelf(float z) {
      // do base class rendering first
      base.DrawSelf(z);

      // render the image
      Rect area = UnclippedInnerRect;
      image.Draw(new Vector3(area.left, area.top, z), PixelRect.GetIntersection(area));
    }

      
    #endregion Window Members

    #region Events

    #region Overridden Event Trigger Methods

    /// <summary>
    /// 
    /// </summary>
    /// <param name="e"></param>
    protected internal override void OnSized(GuiEventArgs e) {
      // base class handling
      base.OnSized (e);

      image.Size = UnclippedInnerRect.Size;

      e.Handled = true;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="e"></param>
    protected internal override void OnAlphaChanged(GuiEventArgs e) {
      // base class handling
      base.OnAlphaChanged (e);

      UpdateRenderableImageColors();

      e.Handled = true;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="e"></param>
    protected override void OnStaticFrameChanged(WindowEventArgs e) {
      // base class processing
      base.OnStaticFrameChanged (e);

      // update the size of the image to reflect changes made to the frame in the base class
      image.Size = UnclippedInnerRect.Size;

      e.Handled = true;
    }

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