2using System.Collections.Generic;
4using System.Reflection;
5using System.Diagnostics;
8using Microsoft.Xna.Framework;
9using Microsoft.Xna.Framework.Input;
10using Microsoft.Xna.Framework.Graphics;
15 public partial class CUI
17 public const float Pi2 = (float)(Math.PI / 2.0);
20 public static SamplerState NoSmoothing =
new SamplerState()
22 Filter = TextureFilter.Point,
23 AddressU = TextureAddressMode.Clamp,
24 AddressV = TextureAddressMode.Clamp,
25 AddressW = TextureAddressMode.Clamp,
26 BorderColor = Color.White,
29 MipMapLevelOfDetailBias = -0.8f,
30 ComparisonFunction = CompareFunction.Never,
31 FilterMode = TextureFilterMode.Default,
34 public static void DrawTexture(SpriteBatch sb, CUIRect cuirect, Texture2D texture, Color cl, CUISpriteDrawMode drawMode = CUISpriteDrawMode.Resize)
36 Rectangle sourceRect = drawMode
switch
38 CUISpriteDrawMode.Resize => texture.Bounds,
39 CUISpriteDrawMode.Wrap =>
new Rectangle(0, 0, (
int)cuirect.Width, (
int)cuirect.Height),
40 CUISpriteDrawMode.Static => cuirect.Box,
41 CUISpriteDrawMode.StaticDeep => cuirect.Zoom(0.9f),
45 sb.Draw(texture, cuirect.Box, sourceRect, cl, 0.0f, Vector2.Zero, SpriteEffects.None, 0);
47 public static void DrawRectangle(SpriteBatch sb, CUIRect cuirect, Color cl, CUISprite sprite,
float depth = 0.0f)
49 Rectangle sourceRect = sprite.DrawMode
switch
51 CUISpriteDrawMode.Resize => sprite.SourceRect,
52 CUISpriteDrawMode.Wrap =>
new Rectangle(0, 0, (
int)cuirect.Width, (
int)cuirect.Height),
53 CUISpriteDrawMode.Static => cuirect.Box,
54 CUISpriteDrawMode.StaticDeep => cuirect.Zoom(0.9f),
55 _ => sprite.SourceRect,
58 Rectangle rect =
new Rectangle(
59 (
int)(cuirect.Left + sprite.Offset.X * cuirect.Width),
60 (
int)(cuirect.Top + sprite.Offset.Y * cuirect.Height),
67 sb.Draw(sprite.Texture, rect, sourceRect, cl, sprite.Rotation, sprite.Origin, sprite.Effects, depth);
72 public static void DrawBorders(SpriteBatch sb, CUIComponent component,
float depth = 0.0f)
74 Texture2D texture = component.BorderSprite.Texture;
75 Rectangle sourceRect = texture.Bounds;
79 float rotation = 0.0f;
80 float thickness = 1.0f;
84 visible = component.RigthBorder?.Visible ?? component.Border?.Visible ??
false;
85 thickness = component.RigthBorder?.Thickness ?? component.Border?.Thickness ?? 0;
86 cl = component.RigthBorder?.Color ?? component.Border?.Color ?? Color.Transparent;
87 targetRect = CUIRect.CreateRect(
88 component.Real.Left + component.Real.Width,
90 component.Real.Height,
93 sourceRect = CUIRect.CreateRect(
95 targetRect.Width, texture.Height
98 sb.Draw(texture, targetRect, sourceRect, cl, rotation, Vector2.Zero, SpriteEffects.None, depth);
101 visible = component.LeftBorder?.Visible ?? component.Border?.Visible ??
false;
102 thickness = component.LeftBorder?.Thickness ?? component.Border?.Thickness ?? 0;
103 cl = component.LeftBorder?.Color ?? component.Border?.Color ?? Color.Transparent;
104 targetRect = CUIRect.CreateRect(
105 component.Real.Left + thickness,
107 component.Real.Height,
110 sourceRect = CUIRect.CreateRect(
112 targetRect.Width, texture.Height
115 sb.Draw(texture, targetRect, sourceRect, cl, rotation, Vector2.Zero, SpriteEffects.FlipVertically, depth);
119 visible = component.TopBorder?.Visible ?? component.Border?.Visible ??
false;
120 thickness = component.TopBorder?.Thickness ?? component.Border?.Thickness ?? 0;
121 cl = component.TopBorder?.Color ?? component.Border?.Color ?? Color.Transparent;
122 targetRect = CUIRect.CreateRect(
125 component.Real.Width,
128 sourceRect = CUIRect.CreateRect(
130 targetRect.Width, texture.Height
133 sb.Draw(texture, targetRect, sourceRect, cl, rotation, Vector2.Zero, SpriteEffects.None, depth);
138 visible = component.BottomBorder?.Visible ?? component.Border?.Visible ??
false;
139 thickness = component.BottomBorder?.Thickness ?? component.Border?.Thickness ?? 0;
140 cl = component.BottomBorder?.Color ?? component.Border?.Color ?? Color.Transparent;
141 targetRect = CUIRect.CreateRect(
143 component.Real.Bottom - thickness,
144 component.Real.Width,
147 sourceRect = CUIRect.CreateRect(
149 targetRect.Width, texture.Height
152 sb.Draw(texture, targetRect, sourceRect, cl, rotation, Vector2.Zero, SpriteEffects.FlipVertically, depth);