243 lines
56 KiB
C#
243 lines
56 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.IO;
|
|||
|
using Microsoft.Xna.Framework;
|
|||
|
using Microsoft.Xna.Framework.Content;
|
|||
|
using Microsoft.Xna.Framework.Graphics;
|
|||
|
|
|||
|
namespace MrAG {
|
|||
|
public class Draw {
|
|||
|
public static SpriteBatch SpriteBatch;
|
|||
|
|
|||
|
private static Texture2D Pixel;
|
|||
|
public static SpriteFont Font;
|
|||
|
public static SpriteFont _defFont;
|
|||
|
|
|||
|
public enum TextAlignmentX{Left, Center, Right};
|
|||
|
public enum TextAlignmentY{Top, Center, Bottom};
|
|||
|
|
|||
|
public static void Initialize(GraphicsDevice gd, SpriteBatch sb, ContentManager cm) {
|
|||
|
SpriteBatch = sb;
|
|||
|
|
|||
|
System.Drawing.Bitmap pix = new System.Drawing.Bitmap(1, 1);
|
|||
|
pix.SetPixel(0, 0, System.Drawing.Color.White);
|
|||
|
|
|||
|
MemoryStream mem = new MemoryStream();
|
|||
|
|
|||
|
pix.Save(mem, System.Drawing.Imaging.ImageFormat.Png);
|
|||
|
|
|||
|
Pixel = Texture2D.FromStream(gd, mem);
|
|||
|
|
|||
|
mem.Close();
|
|||
|
pix.Dispose();
|
|||
|
|
|||
|
#region massive uber sized super to the max master king byte array, realy dont open. it freezes ya VS xD
|
|||
|
File.WriteAllBytes("content/tmpfont.xnb", new byte[]{88, 78, 66, 119, 5, 0, 174, 52, 0, 0, 8, 149, 1, 77, 105, 99, 114, 111, 115, 111, 102, 116, 46, 88, 110, 97, 46, 70, 114, 97, 109, 101, 119, 111, 114, 107, 46, 67, 111, 110, 116, 101, 110, 116, 46, 83, 112, 114, 105, 116, 101, 70, 111, 110, 116, 82, 101, 97, 100, 101, 114, 44, 32, 77, 105, 99, 114, 111, 115, 111, 102, 116, 46, 88, 110, 97, 46, 70, 114, 97, 109, 101, 119, 111, 114, 107, 46, 71, 114, 97, 112, 104, 105, 99, 115, 44, 32, 86, 101, 114, 115, 105, 111, 110, 61, 52, 46, 48, 46, 48, 46, 48, 44, 32, 67, 117, 108, 116, 117, 114, 101, 61, 110, 101, 117, 116, 114, 97, 108, 44, 32, 80, 117, 98, 108, 105, 99, 75, 101, 121, 84, 111, 107, 101, 110, 61, 56, 52, 50, 99, 102, 56, 98, 101, 49, 100, 101, 53, 48, 53, 53, 51, 0, 0, 0, 0, 148, 1, 77, 105, 99, 114, 111, 115, 111, 102, 116, 46, 88, 110, 97, 46, 70, 114, 97, 109, 101, 119, 111, 114, 107, 46, 67, 111, 110, 116, 101, 110, 116, 46, 84, 101, 120, 116, 117, 114, 101, 50, 68, 82, 101, 97, 100, 101, 114, 44, 32, 77, 105, 99, 114, 111, 115, 111, 102, 116, 46, 88, 110, 97, 46, 70, 114, 97, 109, 101, 119, 111, 114, 107, 46, 71, 114, 97, 112, 104, 105, 99, 115, 44, 32, 86, 101, 114, 115, 105, 111, 110, 61, 52, 46, 48, 46, 48, 46, 48, 44, 32, 67, 117, 108, 116, 117, 114, 101, 61, 110, 101, 117, 116, 114, 97, 108, 44, 32, 80, 117, 98, 108, 105, 99, 75, 101, 121, 84, 111, 107, 101, 110, 61, 56, 52, 50, 99, 102, 56, 98, 101, 49, 100, 101, 53, 48, 53, 53, 51, 0, 0, 0, 0, 173, 1, 77, 105, 99, 114, 111, 115, 111, 102, 116, 46, 88, 110, 97, 46, 70, 114, 97, 109, 101, 119, 111, 114, 107, 46, 67, 111, 110, 116, 101, 110, 116, 46, 76, 105, 115, 116, 82, 101, 97, 100, 101, 114, 96, 49, 91, 91, 77, 105, 99, 114, 111, 115, 111, 102, 116, 46, 88, 110, 97, 46, 70, 114, 97, 109, 101, 119, 111, 114, 107, 46, 82, 101, 99, 116, 97, 110, 103, 108, 101, 44, 32, 77, 105, 99, 114, 111, 115, 111, 102, 116, 46, 88, 110, 97, 46, 70, 114, 97, 109, 101, 119, 111, 114, 107, 44, 32, 86, 101, 114, 115, 105, 111, 110, 61, 52, 46, 48, 46, 48, 46, 48, 44, 32, 67, 117, 108, 116, 117, 114, 101, 61, 110, 101, 117, 116, 114, 97, 108, 44, 32, 80, 117, 98, 108, 105, 99, 75, 101, 121, 84, 111, 107, 101, 110, 61, 56, 52, 50, 99, 102, 56, 98, 101, 49, 100, 101, 53, 48, 53, 53, 51, 93, 93, 0, 0, 0, 0, 47, 77, 105, 99, 114, 111, 115, 111, 102, 116, 46, 88, 110, 97, 46, 70, 114, 97, 109, 101, 119, 111, 114, 107, 46, 67, 111, 110, 116, 101, 110, 116, 46, 82, 101, 99, 116, 97, 110, 103, 108, 101, 82, 101, 97, 100, 101, 114, 0, 0, 0, 0, 136, 1, 77, 105, 99, 114, 111, 115, 111, 102, 116, 46, 88, 110, 97, 46, 70, 114, 97, 109, 101, 119, 111, 114, 107, 46, 67, 111, 110, 116, 101, 110, 116, 46, 76, 105, 115, 116, 82, 101, 97, 100, 101, 114, 96, 49, 91, 91, 83, 121, 115, 116, 101, 109, 46, 67, 104, 97, 114, 44, 32, 109, 115, 99, 111, 114, 108, 105, 98, 44, 32, 86, 101, 114, 115, 105, 111, 110, 61, 52, 46, 48, 46, 48, 46, 48, 44, 32, 67, 117, 108, 116, 117, 114, 101, 61, 110, 101, 117, 116, 114, 97, 108, 44, 32, 80, 117, 98, 108, 105, 99, 75, 101, 121, 84, 111, 107, 101, 110, 61, 98, 55, 55, 97, 53, 99, 53, 54, 49, 57, 51, 52, 101, 48, 56, 57, 93, 93, 0, 0, 0, 0, 42, 77, 105, 99, 114, 111, 115, 111, 102, 116, 46, 88, 110, 97, 46, 70, 114, 97, 109, 101, 119, 111, 114, 107, 46, 67, 111, 110, 116, 101, 110, 116, 46, 67, 104, 97, 114, 82, 101, 97, 100, 101, 114, 0, 0, 0, 0, 171, 1, 77, 105, 99, 114, 111, 115, 111, 102, 116, 46, 88, 110, 97, 46, 70, 114, 97, 109, 101, 119, 111, 114, 107, 46, 67, 111, 110, 116, 101, 110, 116, 46, 76, 105, 115, 116, 82, 101, 97, 100, 101, 114, 96, 49, 91, 91, 77, 105, 99, 114, 111, 115, 111, 102, 116, 46, 88, 110, 97, 46, 70, 114, 97, 109, 101, 119, 111, 114, 107, 46, 86, 101, 99, 116, 111, 114, 51, 44, 32, 77, 105, 99, 114, 111, 115, 111, 102, 116, 46, 88, 110, 97, 46, 70, 114, 97, 109, 101, 119, 111, 114, 107, 44, 32, 86, 101, 114, 115, 105, 111, 110, 61, 52, 46, 48, 46, 48, 46, 48, 44, 32, 67, 117, 108, 116, 117, 114, 101, 61, 110, 101, 117, 116, 114, 97, 108, 44, 32, 80, 117, 98, 108, 105, 99, 75, 101, 121, 84, 111, 107, 101, 110, 61, 56, 52, 5
|
|||
|
Font = cm.Load<SpriteFont>("tmpfont");
|
|||
|
_defFont = Font;
|
|||
|
File.Delete("content/tmpfont.xnb");
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
public static void SetFont(SpriteFont font) {
|
|||
|
if (font == null)
|
|||
|
return;
|
|||
|
|
|||
|
Font = font;
|
|||
|
}
|
|||
|
|
|||
|
public static void ResetFont() {
|
|||
|
Font = _defFont;
|
|||
|
}
|
|||
|
|
|||
|
public static Texture2D GetPixelTexture() {
|
|||
|
return Pixel;
|
|||
|
}
|
|||
|
|
|||
|
public static void Texture(Texture2D texture, int x, int y, int w, int h) {
|
|||
|
SpriteBatch.Draw(texture, new Rectangle(x, y, w, h), Color.White);
|
|||
|
}
|
|||
|
|
|||
|
public static void Texture(Texture2D texture, int x, int y, int w, int h, Color col) {
|
|||
|
SpriteBatch.Draw(texture, new Rectangle(x, y, w, h), col);
|
|||
|
}
|
|||
|
|
|||
|
public static void Texture(Texture2D texture, int x, int y, int w, int h, Color col, float rotation) {
|
|||
|
SpriteBatch.Draw(texture, new Rectangle(x, y, w, h), null, col, rotation, new Vector2(w / 2, h / 2), SpriteEffects.None, 0);
|
|||
|
}
|
|||
|
|
|||
|
public static void Box(int x, int y, int w, int h, Color col) {
|
|||
|
SpriteBatch.Draw(Pixel, new Rectangle(x, y, w, h), col);
|
|||
|
}
|
|||
|
|
|||
|
public static void OutlinedBox(int x, int y, int w, int h, int bordersize, Color col) {
|
|||
|
if (bordersize == 0)
|
|||
|
return;
|
|||
|
|
|||
|
SpriteBatch.Draw(Pixel, new Rectangle(x + bordersize, y, w - bordersize * 2, bordersize), col); // u
|
|||
|
SpriteBatch.Draw(Pixel, new Rectangle(x, y, bordersize, h), col); // l
|
|||
|
SpriteBatch.Draw(Pixel, new Rectangle(x + w - bordersize, y, bordersize, h), col); // r
|
|||
|
SpriteBatch.Draw(Pixel, new Rectangle(x + bordersize, y + h - bordersize, w - bordersize * 2, bordersize), col); // d
|
|||
|
}
|
|||
|
|
|||
|
public static void Text(string text, int x, int y) {
|
|||
|
SpriteBatch.DrawString(Font, text, new Vector2(x, y), Color.White);
|
|||
|
}
|
|||
|
|
|||
|
public static void Text(string text, int x, int y, Color col) {
|
|||
|
SpriteBatch.DrawString(Font, text, new Vector2(x, y), col);
|
|||
|
}
|
|||
|
|
|||
|
public static void Line(int x0, int y0, int x1, int y1, Color color){
|
|||
|
float ang = (float)-Math.Atan2(x0 - x1, y0 - y1) - (float)(Math.PI / 2);
|
|||
|
float dist = (float)Math.Sqrt(((x0 - x1) * (x0 - x1)) + ((y0 - y1) * (y0 - y1)));
|
|||
|
|
|||
|
SpriteBatch.Draw(Pixel, new Vector2(x0, y0), null, color, ang, new Vector2(0, 0), new Vector2((int)dist, 1), SpriteEffects.None, 0);
|
|||
|
}
|
|||
|
|
|||
|
public static void Line(int x0, int y0, int x1, int y1, float width, Color color)
|
|||
|
{
|
|||
|
float ang = (float)-Math.Atan2(x0 - x1, y0 - y1) - (float)(Math.PI / 2);
|
|||
|
float dist = (float)Math.Sqrt(((x0 - x1) * (x0 - x1)) + ((y0 - y1) * (y0 - y1)));
|
|||
|
|
|||
|
SpriteBatch.Draw(Pixel, new Vector2(x0, y0), null, color, ang, new Vector2(0, 0.5f), new Vector2((int)dist, width), SpriteEffects.None, 0);
|
|||
|
}
|
|||
|
|
|||
|
public static void DrawTexturePart(Texture2D texture, int x, int y, int px1, int py1, int width, int height){
|
|||
|
SpriteBatch.Draw(
|
|||
|
texture, new Vector2(x, y), new Rectangle(px1, py1, width, height),
|
|||
|
Color.White, 0, new Vector2(0, 0),
|
|||
|
1, SpriteEffects.None, 1);
|
|||
|
}
|
|||
|
|
|||
|
public static void DrawTexturePart(Texture2D texture, int x, int y, int px1, int py1, int width, int height, Color col){
|
|||
|
SpriteBatch.Draw(
|
|||
|
texture, new Vector2(x, y), new Rectangle(px1, py1, width, height),
|
|||
|
col, 0, new Vector2(0, 0),
|
|||
|
1, SpriteEffects.None, 1);
|
|||
|
}
|
|||
|
|
|||
|
public static Vector2 GetFontSize(SpriteFont font){
|
|||
|
return font.MeasureString("W");
|
|||
|
}
|
|||
|
|
|||
|
public static Vector2 GetTextSize(SpriteFont font, string text)
|
|||
|
{
|
|||
|
return font.MeasureString(text);
|
|||
|
}
|
|||
|
|
|||
|
public static Vector2 GetTextSize(string text)
|
|||
|
{
|
|||
|
return Font.MeasureString(text);
|
|||
|
}
|
|||
|
|
|||
|
public static void TextShadow(string text, int x, int y, Color col, Color shadowColor, TextAlignmentX AlignX, TextAlignmentY AlignY, int OffsetX, int OffsetY) {
|
|||
|
Text(text, x + OffsetX, y + OffsetY, shadowColor, AlignX, AlignY);
|
|||
|
Text(text, x, y, col, AlignX, AlignY);
|
|||
|
}
|
|||
|
|
|||
|
public static void Text(SpriteFont font, string text, int x, int y, Color col, TextAlignmentX AlignX, TextAlignmentY AlignY) {
|
|||
|
if (font == null)
|
|||
|
font = Font;
|
|||
|
|
|||
|
Vector2 ts = font.MeasureString(text);
|
|||
|
|
|||
|
switch(AlignX){
|
|||
|
case TextAlignmentX.Left:
|
|||
|
break;
|
|||
|
|
|||
|
case TextAlignmentX.Right:
|
|||
|
x -= (int)ts.X;
|
|||
|
break;
|
|||
|
|
|||
|
case TextAlignmentX.Center:
|
|||
|
x -= (int)(ts.X / 2);
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
switch(AlignY){
|
|||
|
case TextAlignmentY.Top:
|
|||
|
break;
|
|||
|
|
|||
|
case TextAlignmentY.Bottom:
|
|||
|
y -= (int)ts.Y;
|
|||
|
break;
|
|||
|
|
|||
|
case TextAlignmentY.Center:
|
|||
|
y -= (int)(ts.Y / 2);
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
SpriteBatch.DrawString(font, text, new Vector2(x, y), col);
|
|||
|
}
|
|||
|
|
|||
|
public static void Text(string text, int x, int y, Color col, TextAlignmentX AlignX, TextAlignmentY AlignY) {
|
|||
|
Vector2 ts = Font.MeasureString(text);
|
|||
|
|
|||
|
switch(AlignX){
|
|||
|
case TextAlignmentX.Left:
|
|||
|
break;
|
|||
|
|
|||
|
case TextAlignmentX.Right:
|
|||
|
x -= (int)ts.X;
|
|||
|
break;
|
|||
|
|
|||
|
case TextAlignmentX.Center:
|
|||
|
x -= (int)(ts.X / 2);
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
switch(AlignY){
|
|||
|
case TextAlignmentY.Top:
|
|||
|
break;
|
|||
|
|
|||
|
case TextAlignmentY.Bottom:
|
|||
|
y -= (int)ts.Y;
|
|||
|
break;
|
|||
|
|
|||
|
case TextAlignmentY.Center:
|
|||
|
y -= (int)(ts.Y / 2);
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
SpriteBatch.DrawString(Font, text, new Vector2(x, y), col);
|
|||
|
}
|
|||
|
|
|||
|
public static void Text(string text, int x, int y, Color col, TextAlignmentX AlignX, TextAlignmentY AlignY, float rotation) {
|
|||
|
Vector2 ts = Font.MeasureString(text);
|
|||
|
x += (int)(ts.X / 2);
|
|||
|
y += (int)(ts.Y / 2);
|
|||
|
|
|||
|
switch(AlignX){
|
|||
|
case TextAlignmentX.Left:
|
|||
|
break;
|
|||
|
|
|||
|
case TextAlignmentX.Right:
|
|||
|
x -= (int)ts.X;
|
|||
|
break;
|
|||
|
|
|||
|
case TextAlignmentX.Center:
|
|||
|
x -= (int)(ts.X / 2);
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
switch(AlignY){
|
|||
|
case TextAlignmentY.Top:
|
|||
|
break;
|
|||
|
|
|||
|
case TextAlignmentY.Bottom:
|
|||
|
y -= (int)ts.Y;
|
|||
|
break;
|
|||
|
|
|||
|
case TextAlignmentY.Center:
|
|||
|
y -= (int)(ts.Y / 2);
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
SpriteBatch.DrawString(Font, text, new Vector2(x, y), col, rotation, new Vector2(ts.X / 2, ts.Y / 2), 1, SpriteEffects.None, 0);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|