NodeEffectText.cs :  » Game » SokoSolve-Sokoban » SokoSolve » Core » UI » Nodes » Effects » 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 » SokoSolve Sokoban 
SokoSolve Sokoban » SokoSolve » Core » UI » Nodes » Effects » NodeEffectText.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using SokoSolve.Common.Math;
using SokoSolve.Core.UI.Paths;



namespace SokoSolve.Core.UI.Nodes.Effects{
    /// <summary>
    /// Display text
    /// </summary>
    public class NodeEffectText : NodeEffect
    {
        /// <summary>
        /// Simple Constructor. No path, Arial 12, White, Shaddow. No path.
        /// </summary>
        /// <param name="myGameUI">GameUI</param>
        /// <param name="myDepth">Depth Z-order</param>
        /// <param name="Text">Display Message</param>
        /// <param name="Start">StartPosition</param>
        public NodeEffectText(GameUI myGameUI, int myDepth, string Text, VectorInt Start) : base(myGameUI, myDepth)
        {
            CurrentAbsolute = Start;
            text = Text;
            font = myGameUI.ResourceFactory[ResourceID.GameMiscFontDefault].DataAsFont;
            brush = myGameUI.ResourceFactory[ResourceID.GameMiscFontDefaultBrush].DataAsBrush;
            brushShaddow = myGameUI.ResourceFactory[ResourceID.GameMiscFontDefaultBrushShaddow].DataAsBrush; 
            Path = null;
            IsVisible = true;

            UpdateSize();
        }

        /// <summary>
        /// Simple Constructor. Display a random message
        /// Linear Path (diagonal), Arial 12, Yellow, Shaddow. 
        /// </summary>
        /// <param name="myGameUI">GameUI</param>
        /// <param name="myDepth">Depth Z-order</param>
        /// <param name="Text">Display Message</param>
        /// <param name="Start">StartPosition</param>
        public NodeEffectText(GameUI myGameUI, int myDepth, string[] Text, VectorInt Start) : base(myGameUI, myDepth)
        {
            CurrentAbsolute = Start;

            font = myGameUI.ResourceFactory[ResourceID.GameMiscFontDefault].DataAsFont;
            brush = myGameUI.ResourceFactory[ResourceID.GameMiscFontDefaultBrush].DataAsBrush;
            brushShaddow = myGameUI.ResourceFactory[ResourceID.GameMiscFontDefaultBrushShaddow].DataAsBrush; 
            Path = new Linear(CurrentAbsolute, new VectorInt(20, 20), new VectorDouble(1, 1), false);
            text = RandomHelper.Select<string>(Text);
            IsVisible = true;

            UpdateSize();
        }

        /// <summary>
        /// Full Constructor.
        /// </summary>
        /// <param name="myGameUI">GameUI</param>
        /// <param name="myDepth">Depth Z-order</param>
        /// <param name="brush">Text Font Brush</param>
        /// <param name="brushShaddow">Shaddow Brush (Null for none)</param>
        /// <param name="text">Message</param>
        /// <param name="font">Text Font</param>
        public NodeEffectText(GameUI myGameUI, int myDepth, string text, Font font, Brush brush, Brush brushShaddow, VectorInt start) : base(myGameUI, myDepth)
        {
            CurrentAbsolute = start;
            this.brush = brush;
            this.brushShaddow = brushShaddow;
            this.text = text;
            this.font = font;
            IsVisible = true;
        }

        private void UpdateSize()
        {
            if (text != null && font != null && GameUI.Graphics != null)
            {
                try
                {
                    SizeF sizeF = GameUI.Graphics.MeasureString(text, font);
                    this.Size = new SizeInt((int)sizeF.Width, (int)sizeF.Height);
                }
                catch(Exception ex)
                {
                    this.Size = new SizeInt(400, 20);
                    throw new Exception("This can only be called during a render phase, otherwise Graphics is not valid");
                }
            }
        }

        /// <summary>
        /// Render the text
        /// </summary>
        public override void Render()
        {
            if (!isVisible) return;

            UpdateSize();

            if (!CurrentAbsolute.IsNull)
            {
                if (brushBackGround != null)
                {
                    GameUI.Graphics.FillRectangle(brushBackGround, CurrentRect.ToDrawingRect());
                }

                if (brushShaddow != null)
                {
                    GameUI.Graphics.DrawString(text, font, brushShaddow, CurrentAbsolute.X + 1, CurrentAbsolute.Y + 1, stringFormat);
                }
                GameUI.Graphics.DrawString(text, font, brush, CurrentAbsolute.X, CurrentAbsolute.Y, stringFormat);    
            }
        }

        /// <summary>
        /// Current Font
        /// </summary>
        public Font Font
        {
            get { return font; }
            set { font = value; }
        }

        /// <summary>
        /// Current Brush
        /// </summary>
        public Brush Brush
        {
            get { return brush; }
            set { brush = value;}
        }
        
        /// <summary>
        /// The shadow or back brush. Null means no shaddow.
        /// </summary>
        public Brush BrushShaddow
        {
            get { return brushShaddow; }
            set { brushShaddow = value; }
        }

        /// <summary>
        /// If not null, draw a background rectangle of this color
        /// </summary>
        public Brush BrushBackGround
        {
            get { return brushBackGround; }
            set { brushBackGround = value; }
        }

        /// <summary>
        /// Current Text
        /// </summary>
        public string Text
        {
            get { return text; }
            set { text = value; }
        }

        /// <summary>
        /// Current String Formatting options.
        /// </summary>
        public StringFormat StringFormat
        {
            get { return stringFormat; }
            set { stringFormat = value; }
        }


        public bool IsVisible
        {
            get { return isVisible; }
            set { isVisible = value; }
        }

        Brush brush;
        Brush brushShaddow;
        private Brush brushBackGround;
        string text;
        Font font;
        StringFormat stringFormat = new StringFormat();
        private IPath alphaPath;
        private bool isVisible;
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.