/* * TextEntity.cs * Authors: Karl Orosz * Copyright (c) 2007-2008 Cornell University 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. */ using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework; namespace StarJack { class TextEntity:Entity { protected String mText = "Button"; public string Text { get { return mText; } set { mText = value; } } protected Color mShadowColor; public Color ShadowColor { get { return mShadowColor; } set { mShadowColor = value; } } protected string mFontName; public String FontName { get { return mFontName; } set { mFontName = value; } } protected SpriteFont mSpriteFont; public SpriteFont SpriteFont { get { return mSpriteFont; } set { mSpriteFont = value; } } protected Vector2 mScale; protected Vector2 mPos; public override int X { get { return (int)(mPos.X); } set { mPos.X = value; } } public override int Y { get { return (int)(mPos.Y); } set { mPos.Y = value; } } public TextEntity(String text) :base(text) { Text = text; mPos = Vector2.Zero; FontName = "dialogFont"; mShadowColor = Color.Black; } public override void LoadContent(Microsoft.Xna.Framework.Content.ContentManager content) { mSpriteFont = content.Load(@"Fonts\" + mFontName); calcScale(mSpriteFont.MeasureString(Name)); } private void calcScale(Vector2 size) { mScale = new Vector2(); if (Width == 0) { Width = (int)(size.X); } if (Height == 0) { Height = (int)(size.Y); } mScale.X = Width / size.X; mScale.Y = Height / size.Y; } public override void Update(Microsoft.Xna.Framework.GameTime time) { } public override void Draw(SpriteBatch pSpriteBatch) { // pSpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.FrontToBack, SaveStateMode.None); // pSpriteBatch.DrawString(mSpriteFont, Text, new Vector2(mPos.X + 1, mPos.Y + 1), mShadowColor, Rotation, Vector2.Zero, mScale, SpriteEffects.None, (Depth -0.001f)); pSpriteBatch.DrawString(mSpriteFont, Text, mPos, mColor, Rotation, Vector2.Zero, mScale, SpriteEffects.None, Depth) ; //pSpriteBatch.End(); } } }