public override void Draw(SpriteBatch spriteBatch, float alpha) { Color dynamicListColor = new Color(new Vector4(ColorBgDefault.ToVector3().X, ColorBgDefault.ToVector3().Y, ColorBgDefault.ToVector3().Z, alpha)); spriteBatch.Draw(listBackground, Position, dynamicListColor); //Items int endIndex = Items.Count; if (startIndex + visibleItems < Items.Count) { endIndex = startIndex + visibleItems; } int lastItem = Items.Count; if (lastItem > visibleItems) { lastItem = visibleItems; } for (int i = 0; i < lastItem; i++) { Color dynamicTextColor = new Color(new Vector4(ColorFgDefault.ToVector3().X, ColorFgDefault.ToVector3().Y, ColorFgDefault.ToVector3().Z, alpha)); spriteBatch.DrawString(SpriteFont, Items[i + startIndex] as string, Position + new Vector2(4f, 4f) + new Vector2(0f, SpriteFont.LineSpacing * i), dynamicTextColor); //Selected Area Color dynamicAreaColor = new Color(new Vector4(Color.White.ToVector3().X, Color.White.ToVector3().Y, Color.White.ToVector3().Z, alpha)); if ((Items[i + startIndex] as string) == SelectedItem) { spriteBatch.Draw(selectionArea, Position + new Vector2(4f, 4f) + new Vector2(0f, SpriteFont.LineSpacing * i), dynamicAreaColor); } //Selection Area if (MouseState.LeftButton == ButtonState.Released && !Form.InUse) { if (bIsOverItem(i)) { spriteBatch.Draw(selectionArea, Position + new Vector2(4f, 4f) + new Vector2(0f, SpriteFont.LineSpacing * i), dynamicAreaColor); } } } if (Scrollbar != null) { Scrollbar.Draw(spriteBatch, alpha); } }
public override void Draw(SpriteBatch spriteBatch, float alpha) { Color dynamicColor = new Color(new Vector4(ColorFgDefault.ToVector3(), alpha)); Vector2 drawPos = Position; Vector2 textSize = SpriteFont.MeasureString(Text); string[] Lines = Text.Split(new char[] { '\n' }); if (ColorBgDefault != Color.Transparent) { Color dynBg = new Color(new Vector4(ColorBgDefault.ToVector3(), alpha)); mButtonArea = new Rectangle((int)Position.X - Value, (int)Position.Y - Value, ControlSize.X, ControlSize.Y); if (ControlSize.X == 0) { mButtonArea.Width = (int)textSize.X + 5; } if (ControlSize.Y == 0) { mButtonArea.Height = (int)textSize.Y + 5; } if (mTextureBlank == null) { mTextureBlank = EngineCore.ContentLoader.Load <Texture2D>(@"Interface\blank"); } spriteBatch.Draw(mTextureBlank, mButtonArea, dynBg); if (BorderColor != Color.Transparent) { Texture2D tex = DrawHelper.Rect2Texture(1, 1, 0, BorderColor); spriteBatch.DrawRectangle(tex, mButtonArea, 1, BorderColor); } } else { mButtonArea = new Rectangle(mButtonArea.X, mButtonArea.Y, ControlSize.X, ControlSize.Y); } for (int i = 0; i < Lines.Length; i++) { if (i > 0) { drawPos.Y += SpriteFont.LineSpacing; } spriteBatch.DrawString(SpriteFont, Lines[i], drawPos, dynamicColor); } }
public override void Draw(SpriteBatch spriteBatch, float alpha) { Color dynamicColor = new Color(new Vector4(ColorBgDefault.ToVector3().X, ColorBgDefault.ToVector3().Y, ColorBgDefault.ToVector3().Z, alpha)); Color dynamicTextColor = new Color(new Vector4(ColorFgDefault.ToVector3().X, ColorFgDefault.ToVector3().Y, ColorFgDefault.ToVector3().Z, alpha)); spriteBatch.Draw(ControlTextures[0], Position, dynamicColor); spriteBatch.Draw(ControlTextures[1], ControlRectangles[0], dynamicColor); spriteBatch.Draw(ControlTextures[2], Position + new Vector2(ControlTextures[0].Width + ControlRectangles[0].Width, 0f), dynamicColor); spriteBatch.Draw(ControlTextures[3], ControlRectangles[1], dynamicColor); spriteBatch.Draw(ControlTextures[4], ControlRectangles[2], dynamicColor); spriteBatch.Draw(ControlTextures[5], ControlRectangles[3], dynamicColor); spriteBatch.Draw(ControlTextures[6], Position + new Vector2(0f, ControlTextures[0].Height + ControlRectangles[1].Height), dynamicColor); spriteBatch.Draw(ControlTextures[7], ControlRectangles[4], dynamicColor); spriteBatch.Draw(ControlTextures[8], Position + new Vector2(ControlTextures[0].Width + ControlRectangles[0].Width, ControlTextures[0].Height + ControlRectangles[1].Height), dynamicColor); visibleText = GetTextFrom(startIndex.X); if (passChar != string.Empty) { string passText = ""; for (int i = 0; i < visibleText.Length; i++) { passText += passChar; } visibleText = passText; } Vector2 drawPos = Position + new Vector2(5f, ControlRectangles[0].Height + (ControlRectangles[2].Height - SpriteFont.LineSpacing) / 2f); drawPos.X = (int)drawPos.X; drawPos.Y = (int)drawPos.Y; spriteBatch.DrawString(SpriteFont, visibleText, drawPos, dynamicTextColor); if (!bLocked && bHasFocus && bCursorVisible && Form.TopForm == this.Owner) { DrawCursor(spriteBatch, dynamicTextColor); } }
public override void InitTextures() { listBackground = new Texture2D(Constants.GraphicsDevice, ControlSize.X, ControlSize.Y, true, SurfaceFormat.Color); Color[] pixels = new Color[ControlSize.X * ControlSize.Y]; for (int y = 0; y < ControlSize.Y; y++) { for (int x = 0; x < ControlSize.X; x++) { if (x < 3 || y < 3 || x > ControlSize.X - 3 || y > ControlSize.Y - 3) { if (x == 0 || y == 0 || x == ControlSize.X - 1 || y == ControlSize.Y - 1) { pixels[x + y * ControlSize.X] = Color.Black; } if (x == 1 || y == 1 || x == ControlSize.X - 2 || y == ControlSize.Y - 2) { pixels[x + y * ControlSize.X] = Color.LightGray; } if (x == 2 || y == 2 || x == ControlSize.X - 3 || y == ControlSize.Y - 3) { pixels[x + y * ControlSize.X] = Color.Gray; } } else { float cX = ColorBgDefault.ToVector3().X; float cY = ColorBgDefault.ToVector3().X; float cZ = ColorBgDefault.ToVector3().X; cX *= 1.0f - ((float)y / (float)ControlSize.Y) * 0.4f; cY *= 1.0f - ((float)y / (float)ControlSize.Y) * 0.4f; cZ *= 1.0f - ((float)y / (float)ControlSize.Y) * 0.4f; pixels[x + y * ControlSize.X] = new Color(new Vector4(cX, cY, cZ, ColorBgDefault.ToVector4().W)); } float currentX = pixels[x + y * ControlSize.X].ToVector3().X; float currentY = pixels[x + y * ControlSize.X].ToVector3().X; float currentZ = pixels[x + y * ControlSize.X].ToVector3().X; pixels[x + y * ControlSize.X] = new Color(new Vector4(currentX, currentY, currentZ, 0.85f)); } } pixels[0] = Color.Transparent; pixels[ControlSize.X] = Color.Transparent; pixels[(ControlSize.Y - 1) * ControlSize.X] = Color.Transparent; pixels[ControlSize.X - 1 + (ControlSize.Y - 1) * ControlSize.X] = Color.Transparent; listBackground.SetData <Color>(pixels); selectionArea = new Texture2D(Constants.GraphicsDevice, ControlSize.X - 8, SpriteFont.LineSpacing, true, SurfaceFormat.Color); pixels = new Color[selectionArea.Width * selectionArea.Height]; for (int y = 0; y < selectionArea.Height; y++) { for (int x = 0; x < selectionArea.Width; x++) { pixels[x + y * selectionArea.Width] = new Color(new Vector4(0f, 0f, 0f, 0.3f)); } } selectionArea.SetData <Color>(pixels); }
public override void InitTextures() { ControlTextures = new Texture2D[2]; ControlTextures[0] = new Texture2D(Constants.GraphicsDevice, ControlSize.X, 18, true, SurfaceFormat.Color); ControlTextures[1] = new Texture2D(Constants.GraphicsDevice, ControlSize.X - 8, ControlTextures[0].Height - 8, true, SurfaceFormat.Color); ControlRectangles = new Rectangle[2]; ControlRectangles[0] = new Rectangle(0, 0, ControlTextures[1].Width, ControlTextures[1].Height); ControlRectangles[1] = new Rectangle(0, 0, ControlTextures[1].Width, ControlTextures[1].Height); Color[] borderPixel = new Color[ControlTextures[0].Width * ControlTextures[0].Height]; Color[] progressBarPixel = new Color[ControlTextures[1].Width * ControlTextures[1].Height]; for (int y = 0; y < ControlTextures[0].Height; y++) { for (int x = 0; x < ControlTextures[0].Width; x++) { if (x < 3 || y < 3 || x > ControlTextures[0].Width - 3 || y > ControlTextures[0].Height - 3) { if (x == 0 || y == 0 || x == ControlTextures[0].Width - 1 || y == ControlTextures[0].Height - 1) { borderPixel[x + y * ControlTextures[0].Width] = Color.Black; } if (x == 1 || y == 1 || x == ControlTextures[0].Width - 2 || y == ControlTextures[0].Height - 2) { borderPixel[x + y * ControlTextures[0].Width] = Color.LightGray; } if (x == 2 || y == 2 || x == ControlTextures[0].Width - 3 || y == ControlTextures[0].Height - 3) { borderPixel[x + y * ControlTextures[0].Width] = Color.Gray; } } else { borderPixel[x + y * ControlTextures[0].Width] = new Color(new Vector4(ColorBgDefault.ToVector3(), 1f)); } } } for (int y = 0; y < ControlTextures[1].Height; y++) { for (int x = 0; x < ControlTextures[1].Width; x++) { bool bInvisiblePixel = false; if (ProgressBarStyle == EProgressBarStyle.Blocks) { int xPos = x % (int)(ControlTextures[1].Width / (float)numberOfBlocks); if (xPos == 0 || xPos == 1) { bInvisiblePixel = true; } } if (!bInvisiblePixel) { float gradient = 1.0f - y * 0.035f; Color pixelColor = new Color(new Vector4(ColorFgDefault.ToVector3() * gradient, 1f)); progressBarPixel[x + y * ControlTextures[1].Width] = pixelColor; } } } ControlTextures[0].SetData <Color>(borderPixel); ControlTextures[1].SetData <Color>(progressBarPixel); }