//Long consturctor public UIButton(GraphicsDevice graphicsDevice, Vector2 position, Vector2 size, String text, SpriteFont font, UIElement parent) : base(position, size, parent, E_UI_TYPES.UI_BUTTON) { this.text = text; this.font = font; this.butTex = new Texture2D(graphicsDevice, (int)size.X, (int)size.Y); Color[] colorData = new Color[(int)size.X * (int)size.Y]; for (int i = 0; i < size.X * size.Y; i++) { if (i % size.X == 0 || i % size.X == size.X - 1) { colorData[i] = new Color(200, 200, 200, 255); } else if (i < size.X || (i < size.X * size.Y) && i > size.X * (size.Y - 1)) { colorData[i] = new Color(200, 200, 200, 255); } else { int texColor = 64; texColor -= i / 250; colorData[i] = new Color(texColor, texColor, texColor, 0); } } butTex.SetData<Color>(colorData); alpha = 0.3f; }
public UIAnimator(GraphicsDevice device, Vector2 position, Texture2D image, int numImages, UIElement parent = null) : base(position, new Vector2(image.Bounds.Width, image.Bounds.Height), parent, E_UI_TYPES.UI_ANIMATION) { currentTexture = image; currentImage = 0; this.device = device; }
//inheritance public UIWindow(GraphicsDevice graphicsDevice, Vector2 position, Vector2 size, UIElement parent = null) : base(position, size, parent, E_UI_TYPES.UI_WINDOW) { //initialize the window texture //remporary thing here winTex = new Texture2D(graphicsDevice, (int)size.X, (int)size.Y, false, SurfaceFormat.Color); Color[] colorData = new Color[(int)size.X * (int)size.Y]; for (int i = 0; i < size.X * size.Y; i++) { //colorData[i] = Color.Gainsboro; if (i % size.X == 0 || i % size.X == size.X-1) { colorData[i] = new Color(200, 200, 200, 255); } else if ( i < size.X || (i < size.X*size.Y) && i>size.X*(size.Y-1)) { colorData[i] = new Color(200, 200, 200, 255); } else { //int texColour = (i / (2000)); int texColor = 64; colorData[i] = new Color(texColor, texColor, texColor, 0); } } winTex.SetData<Color>(colorData); //temporary this.alpha = 0.3f; }
//static text class public UIStaticText(Vector2 position, Vector2 size, String text, SpriteFont font, UIElement parent) : base(position, size, parent, E_UI_TYPES.UI_STATIC_TEXT) { //just draw text on screen this.font = font; this.text = text; }
public UIGraph addGraph(Vector2 position, Vector2 size, UIElement parent = null) { UIGraph ret = new UIGraph(graphicsDevice, position, size, parent); if (parent == null) unparentedNodes.Add(ret); return ret; }
public UIImage addImage(Vector2 position, Texture2D image, UIElement parent = null) { UIImage ret = new UIImage(graphicsDevice, position, image, parent); if (parent == null) { unparentedNodes.Add(ret); } return ret; }
//adds a button to the scene public UIButton addButton(Vector2 position, Vector2 size, string text, SpriteFont font, UIElement parent = null) { UIButton ret = new UIButton(graphicsDevice, position, size, text, font, parent); if (parent == null) { unparentedNodes.Add(ret); } return ret; }
public UIStaticText addStaticText(Vector2 position, Vector2 size, String text, SpriteFont font, UIElement parent = null) { UIStaticText ret = new UIStaticText(position, size, text, font, parent); if (parent == null) { unparentedNodes.Add(ret); } return ret; }
public UIGraph(GraphicsDevice graphicsDevice, Vector2 position, Vector2 size, UIElement parent = null) : base(position, size, parent, E_UI_TYPES.UI_GRAPH) { this.bkg = new Texture2D(graphicsDevice, (int)size.X, (int)size.Y, false, SurfaceFormat.Color); Color[] colorData = new Color[(int)size.X * (int)size.Y]; for (int i = 0; i < (int)size.X * (int)size.Y; i++) { //fill with temp colors for now } }
//overload the constructor public UIElement(Vector2 position, UIElement parent, E_UI_TYPES type) { this.position = position; this.type = type; this.visible = true; this.parent = parent; this.children = new List<UIElement>(); //yay for c++ design pattersn if (parent != null) { parent.addChild(this); absolutePosition = parent.getPosition() + position; } else { absolutePosition = position; } }
public void removeChild(UIElement child) { children.Remove(child); children.TrimExcess(); }
public void addChild(UIElement newChild) { children.Add(newChild); }
//constructor public UIImage(GraphicsDevice graphicsDevice, Vector2 position, Texture2D image, UIElement parent = null) : base(position, new Vector2(image.Bounds.Width,image.Bounds.Height), parent, E_UI_TYPES.UI_IMAGE) { this.image = image; this.scale = new Vector2(1, 1); }
//add factory functions /* * create window with params */ public UIWindow addWindow(Vector2 position, Vector2 size, UIElement parent = null) { UIWindow ret = new UIWindow(graphicsDevice, position, size, parent); if (parent == null) { unparentedNodes.Add(ret); } return ret; }