internal string uwfDrawTextField(string s, Font font, Color color, float x, float y, float width, float height, HorizontalAlignment alignment)
        {
            if (s == null)
            {
                s = "";
            }

            UE.GUI.skin.textField.alignment = UE.TextAnchor.UpperLeft;
            switch (alignment)
            {
            case HorizontalAlignment.Center:
                UE.GUI.skin.textField.alignment = UE.TextAnchor.MiddleCenter;
                break;

            default:
                UE.GUI.skin.textField.alignment = UE.TextAnchor.MiddleLeft;
                break;

            case HorizontalAlignment.Right:
                UE.GUI.skin.textField.alignment = UE.TextAnchor.MiddleRight;
                break;
            }

            GUI_SetFont(UE.GUI.skin.textField, font);

            UE.GUI.color = color.ToUnityColor();
            UE.GUI.skin.textField.hover.background   = null;
            UE.GUI.skin.textField.active.background  = null;
            UE.GUI.skin.textField.focused.background = null;
            UE.GUI.skin.textField.normal.background  = null;

            return(UE.GUI.TextField(new UE.Rect(x, y, width, height), s));
        }
        public static void ColorField(string name, global::UWinForms.System.Drawing.Color value, Action <global::UWinForms.System.Drawing.Color> setColor)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(name + ":", GUILayout.Width(_nameWidth));
            if (WinFormsCompatible)
            {
                if (Button(value.ToString()))
                {
                    var colorForm = new ColorPickerForm();
                    colorForm.Color = value;
                    colorForm.Show();
                    colorForm.ColorChanged += (s, a) =>
                    {
                        if (setColor != null)
                        {
                            setColor.Invoke(colorForm.Color);
                        }
                    };
                }
            }

#if UNITY_EDITOR
            else
            {
                var colorBuffer = UnityEditor.EditorGUILayout.ColorField(value.ToUnityColor(), GUILayout.Width(_contentWidth)).ToColor();
                if (colorBuffer != value && setColor != null)
                {
                    setColor.Invoke(colorBuffer);
                }
            }
#endif
            GUILayout.EndHorizontal();
        }
        public void Clear(Color color)
        {
            var colors = new Color[Width * Height];

            for (int i = 0; i < colors.Length; i++)
            {
                colors[i] = color;
            }

            SetPixels(colors);
        }
        public Color[] GetPixels(int x, int y, int width, int height)
        {
            // Fix: updside down.
            var ucs = texture.GetPixels(x, y, width, height);
            var cs  = new Color[ucs.Length];

            for (int i = 0; i < ucs.Length; i++)
            {
                cs[i] = ucs[i].ToColor();
            }

            return(cs);
        }
        public void FillRectangle(Color color, float x, float y, float width, float height, object material = null)
        {
            var rect = new UE.Rect(x, y, width, height);

            if (material == null || material is UE.Material == false)
            {
                UE.GUI.color = color.ToUnityColor();
                UE.GUI.DrawTexture(rect, defaultTexture);
                return;
            }

            var umat = (UE.Material)material;

            umat.color = color.ToUnityColor();
            UE.Graphics.DrawTexture(rect, defaultTexture, umat);
        }
        public void DrawImage(Image image, Color color, float x, float y, float width, float height, float angle)
        {
            if (image == null || width <= 0 || height <= 0)
            {
                return;
            }

            var unityGdiSprite = image.uTexture as UnityGdiSprite;

            if (unityGdiSprite != null && unityGdiSprite.sprite != null)
            {
                var spriteRect = unityGdiSprite.sprite.rect;
                var texture    = unityGdiSprite.sprite.texture;
                var sx         = spriteRect.x / texture.width;
                var sy         = spriteRect.y / texture.height;
                var sw         = spriteRect.width / texture.width;
                var sh         = spriteRect.height / texture.height;
                UE.GUI.color = color.ToUnityColor();
                UE.GUI.DrawTextureWithTexCoords(new UE.Rect(x, y, width, height), unityGdiSprite.sprite.texture, new UE.Rect(sx, sy, sw, sh));
                return;
            }

            var textureToDraw = defaultTexture;
            var imageTexture  = image.uTexture as UnityGdiTexture;

            if (imageTexture != null)
            {
                textureToDraw = imageTexture.texture;
            }

            if (angle != 0)
            {
                UE.Matrix4x4 matrixBackup = UE.GUI.matrix;
                UE.GUIUtility.RotateAroundPivot(angle, new UE.Vector2(x + width / 2, y + height / 2));
                UE.GUI.DrawTexture(new UE.Rect(x, y, width, height), ((UnityGdiTexture)image.uTexture).texture);
                UE.GUI.matrix = matrixBackup;
                return;
            }

            UE.GUI.color = color.ToUnityColor();
            UE.GUI.DrawTexture(new UE.Rect(x, y, width, height), textureToDraw);
        }
        internal string uwfDrawTextArea(string s, Font font, Color color, float x, float y, float width, float height)
        {
            if (s == null)
            {
                s = "";
            }

            UE.GUI.skin.textArea.alignment = UE.TextAnchor.UpperLeft;

            UE.GUI.color = color.ToUnityColor();
            //GUI.skin.textArea.hover.textColor = brush.Color.ToUColor();

            GUI_SetFont(UE.GUI.skin.textArea, font);

            UE.GUI.skin.textArea.hover.background   = null;
            UE.GUI.skin.textArea.active.background  = null;
            UE.GUI.skin.textArea.focused.background = null;
            UE.GUI.skin.textArea.normal.background  = null;

            return(UE.GUI.TextArea(new UE.Rect(x, y, width, height), s));
        }
        private void uwfDrawTexture(UE.Texture texture, float x, float y, float width, float height, Color color, float angle, PointF pivot)
        {
            if (texture == null)
            {
                return;
            }

            UE.GUI.color = color.ToUnityColor();

            if (angle != 0)
            {
                UE.Matrix4x4 matrixBackup = UE.GUI.matrix;
                UE.GUIUtility.RotateAroundPivot(angle, new UE.Vector2(x + pivot.X, y + pivot.Y));
                UE.GUI.DrawTexture(new UE.Rect(x, y, width, height), texture);
                UE.GUI.matrix = matrixBackup;
            }
            else
            {
                UE.GUI.DrawTexture(new UE.Rect(x, y, width, height), texture);
            }
        }
        public void DrawString(string text, Font font, Color color, float x, float y, float width, float height, ContentAlignment align, object material = null)
        {
            if (text == null || font == null)
            {
                return;
            }

            // TODO: material not supported.

            // Set align.
            var uAlign = UE.TextAnchor.UpperLeft;

            switch (align)
            {
            case ContentAlignment.BottomCenter:
                uAlign = UE.TextAnchor.LowerCenter;
                break;

            case ContentAlignment.BottomLeft:
                uAlign = UE.TextAnchor.LowerLeft;
                break;

            case ContentAlignment.BottomRight:
                uAlign = UE.TextAnchor.LowerRight;
                break;

            case ContentAlignment.MiddleCenter:
                uAlign = UE.TextAnchor.MiddleCenter;
                break;

            case ContentAlignment.MiddleLeft:
                uAlign = UE.TextAnchor.MiddleLeft;
                break;

            case ContentAlignment.MiddleRight:
                uAlign = UE.TextAnchor.MiddleRight;
                break;

            case ContentAlignment.TopCenter:
                uAlign = UE.TextAnchor.UpperCenter;
                break;

            case ContentAlignment.TopLeft:
                uAlign = UE.TextAnchor.UpperLeft;
                break;

            case ContentAlignment.TopRight:
                uAlign = UE.TextAnchor.UpperRight;
                break;
            }

            var labelSkin             = UE.GUI.skin.label;
            int guiSkinFontSizeBuffer = GUI_SetFont(labelSkin, font);

            UE.GUI.color        = color.ToUnityColor();
            labelSkin.alignment = uAlign;

            textContent.text = text;

            // It's faster to invoke less methods and use your own GUIContent. Not that much, but anyway.
            UE.GUI.Label(new UE.Rect(x, y, width, height), textContent, labelSkin);

            labelSkin.fontSize = guiSkinFontSizeBuffer;
        }
 public void Clear(Color color)
 {
     UE.GUI.color = color.ToUnityColor();
 }
 public void SetPixel(int x, int y, Color color)
 {
     texture.SetPixel(x, texture.height - y - 1, color.ToUnityColor());
 }
 public static void SetBackColor(global::UWinForms.System.Drawing.Color color)
 {
     GUI.backgroundColor = color.ToUnityColor();
 }
 public static UE.Color ToUnityColor(this Color color)
 {
     return(new UnityEngine.Color((float)color.R / 255, (float)color.G / 255, (float)color.B / 255, (float)color.A / 255));
 }
 public static Color ToColor(this UE.Color color)
 {
     return(Color.FromArgb((int)(color.a * 255), (int)(color.r * 255), (int)(color.g * 255), (int)(color.b * 255)));
 }