public void CloseWindow()
 {
     CloseCharTable();
     showWindow          = false;
     editingObject       = null;
     originalTex         = null;
     windowTex           = null;
     parameters          = null;
     parametersOld       = null;
     colorPickerSelected = null;
     if (selectedField != null)
     {
         selectedField.expandFontsSelector = false;
         selectedField.scrollFontsPos      = Vector2.zero;
         selectedField = null;
     }
     scrollParams = Vector2.zero;
     scrollTex    = Vector2.zero;
     updateTimer  = 0f;
     dragTimer    = 0f;
     placingText  = false;
     placingRect  = false;
     _justPlacedTextNowFocusField = false;
     placingRectFirstpoint        = Vector2.down;
     zoomFactor  = 1f;
     movingField = -1;
     dragTexPos  = Vector2.zero;
     // GUIUtils.SetMouseScrolling(true);
 }
        protected void RemoveColorAt(int X, int Y)
        {
            SequentialProcedure(() =>
            {
                Vector2 PointPosition = new Vector2(X, Y);

                GUIPainter.GetInstance().RemovePointAt(PointPosition);
            });
        }
        protected void PaintColorAt(int X, int Y, UnityEngine.Color PointColor)
        {
            SequentialProcedure(() =>
            {
                Vector2 PointPosition = new Vector2(X, Y);

                GUIPainter.GetInstance().PaintPointAt(PointPosition, PointColor);
            });
        }
 public void DrawWindow()
 {
     if (canDrawWindow)
     {
         windowRect = GUIUtils.Window(99043, windowRect, draw, LocalizationManager.instance.current["text_customization"]);
         if (colorPickerSelected != null)
         {
             colorPickerSelected.pickerPosition = new Vector2(windowRect.xMax + 2, windowRect.y + 265);
             GUIPainter.DrawPicker(colorPickerSelected, Color.HSVToRGB(colorPickerSelected.H, colorPickerSelected.S, colorPickerSelected.V));
         }
     }
     if (selectedCharTable != null)
     {
         charTableRect = GUIUtils.Window(99044, charTableRect, drawCharTable, LocalizationManager.instance.current["char_table"]);
     }
 }
 public override void OnActionGUI(Vector2 uiPos)
 {
     GUI.DrawTexture(new Rect(uiPos.x, uiPos.y, 100, 22), gradientTex);
     painterA = GUIPainter.DrawPainter(painterA, new Vector2(uiPos.x, uiPos.y + 24), new Vector2(uiPos.x, uiPos.y + 46), A, (c) => { A = c; UpdateGradient(); }, () => { });
     painterB = GUIPainter.DrawPainter(painterB, new Vector2(uiPos.x + 74, uiPos.y + 24), new Vector2(uiPos.x + 74, uiPos.y + 46), B, (c) => { B = c; UpdateGradient(); }, () => { });
     if (GUI.Button(new Rect(uiPos.x + 102, uiPos.y, 32, 22), LocalizationManager.instance.current["ok"]))
     {
         ProceduralObjectsLogic.PlaySound();
         confirmed = true;
         ExitAction();
         return;
     }
     if (GUI.Button(new Rect(uiPos.x + 136, uiPos.y, 80, 22), LocalizationManager.instance.current["cancel"]))
     {
         ProceduralObjectsLogic.PlaySound();
         ExitAction();
         return;
     }
 }
        public void Edit(ProceduralObject obj, Vector2 position)
        {
            selectedField = null;
            editingObject = obj;
            scrollParams  = Vector2.zero;
            scrollTex     = Vector2.zero;
            movingField   = -1;
            dragTexPos    = Vector2.zero;
            // windowRect.position = position;
            Texture tex = ProceduralUtils.GetOriginalTexture(obj);

            originalTex = new Texture2D(tex.width, tex.height, TextureFormat.RGBA32, false);
            originalTex.SetPixels(((Texture2D)tex).GetPixels());
            windowTex           = (Texture2D)GameObject.Instantiate(originalTex);
            colorPickerSelected = null;
            // load stored data if it exists
            if (editingObject.m_textParameters == null)
            {
                parameters    = new TextParameters();
                parametersOld = new TextParameters();
            }
            else
            {
                parameters    = editingObject.m_textParameters;
                parametersOld = TextParameters.Clone(editingObject.m_textParameters, false);
                windowTex     = parameters.ApplyParameters(originalTex);
                editingObject.m_material.mainTexture = windowTex as Texture;
            }
            updateTimer = 0f;
            dragTimer   = 0f;
            zoomFactor  = 1f;
            if (!showWindow)
            {
                showWindow = true;
            }
        }
 public override void OnUpdate()
 {
     GUIPainter.UpdatePainter(painterA);
     GUIPainter.UpdatePainter(painterB);
 }
        public void DrawUI(Rect rect, TextCustomizationManager textManager, Action <TextureFont> openCharTable)
        {
            // GUI.Box(rect, string.Empty);
            GUI.BeginGroup(rect);
            // copy
            if (GUI.Button(new Rect(220, 3, 25, 23), ProceduralObjectsMod.Icons[15]))
            {
                ProceduralObjectsLogic.PlaySound();
                textManager.copiedField = TextField.Clone(this, false);
            }
            if (m_type == 0)
            {
                if (!m_font.m_disableColorOverwriting)
                {
                    painter = GUIPainter.DrawPainterSampleOnly(painter, new Vector2(3, 4), m_fontColor,
                                                               (c) => { m_fontColor = c; },
                                                               () =>
                    {
                        if (textManager.colorPickerSelected == painter)
                        {
                            textManager.colorPickerSelected = null;
                        }
                        else
                        {
                            textManager.colorPickerSelected = painter;
                        }
                    });
                }
                GUI.SetNextControlName("TextFieldPOTextCustom");
                m_text = GUI.TextField(new Rect(m_font.m_disableColorOverwriting ? 3 : 31, 3, m_font.m_disableColorOverwriting ? 214 : 186, 25), m_text);
            }
            else // if m_type == 1
            {
                painter = GUIPainter.DrawPainterSampleOnly(painter, new Vector2(3, 4), m_fontColor,
                                                           (c) => { m_fontColor = c.KeepAlphaFrom(m_fontColor); },
                                                           () =>
                {
                    if (textManager.colorPickerSelected == painter)
                    {
                        textManager.colorPickerSelected = null;
                    }
                    else
                    {
                        textManager.colorPickerSelected = painter;
                    }
                });
                GUI.Label(new Rect(30, 5, 190, 23), LocalizationManager.instance.current["colorRect"]);
            }


            GUIUtils.DrawSeparator(new Vector2(3, 75), 241);

            if (m_type == 0) // TEXT FIELD
            {
                //size
                GUI.Label(new Rect(3, 80, 95, 22), "<size=12>" + LocalizationManager.instance.current["font_size"] + " : " + m_fontSize.ToString() + "</size>");
                m_fontSize = (uint)Mathf.FloorToInt(GUI.HorizontalSlider(new Rect(100, 85, 140, 25), m_fontSize, 5, 150));

                //spacing
                GUI.Label(new Rect(3, 105, 95, 22), "<size=12>" + LocalizationManager.instance.current["font_spacing"] + " : " + m_spacing.ToString() + "</size>");
                m_spacing = (uint)Mathf.FloorToInt(GUI.HorizontalSlider(new Rect(100, 110, 140, 25), m_spacing, 0, 9));

                //scale
                GUI.Label(new Rect(3, 130, 120, 26), LocalizationManager.instance.current["scale_txt"] + " :");
                if (GUI.Button(new Rect(3, 155, 24, 26), "X :", GUI.skin.label))
                {
                    m_scaleX = 1f;
                }
                m_scaleX = GUI.HorizontalSlider(new Rect(30, 158, 90, 18), m_scaleX, 0.1f, 5f);
                if (GUI.Button(new Rect(125, 155, 24, 26), "Y :", GUI.skin.label))
                {
                    m_scaleY = 1f;
                }
                m_scaleY = GUI.HorizontalSlider(new Rect(150, 158, 90, 18), m_scaleY, 0.1f, 5f);

                //font
                bool supportStyles = m_font.m_boldExists && m_font.m_italicExists;
                if (GUI.Button(new Rect(3, 180, (supportStyles ? 126 : 213), 25), m_fontName))
                {
                    ProceduralObjectsLogic.PlaySound();
                    openCharTable.Invoke(m_font);
                }
                if (GUI.Button(new Rect((supportStyles ? 128 : 215), 180, 26, 25), "▼"))
                {
                    ProceduralObjectsLogic.PlaySound();
                    // SetFont(textManager.fontManager.GetNextFont(m_font));
                    scrollFontsPos      = Vector2.zero;
                    expandFontsSelector = !expandFontsSelector;
                }
                if (supportStyles)
                {
                    string[] styles = new string[] { LocalizationManager.instance.current["textStyle_normal"], "<b>" + LocalizationManager.instance.current["textStyle_bold"] + "</b>", "<i>" + LocalizationManager.instance.current["textStyle_italic"] + "</i>" };
                    if (m_font.m_stylesNames != null)
                    {
                        if (m_font.m_stylesNames.Length == 3)
                        {
                            styles = m_font.m_stylesNames;
                        }
                    }
                    m_style = TextCustomizationManager.IntToStyle(GUI.Toolbar(new Rect(158, 180, 85, 25), TextCustomizationManager.SelectedStyle(m_style), styles));
                }
                if (expandFontsSelector)
                {
                    TextureFont fontSelected;
                    if (FontManager.instance.FontSelector(new Rect(3, 207, 240, 160), scrollFontsPos, out fontSelected, out scrollFontsPos))
                    {
                        SetFont(fontSelected);
                        expandFontsSelector = false;
                        scrollFontsPos      = Vector2.zero;
                    }
                }
            }
            else if (m_type == 1) // COLOR RECT
            {
                GUI.Label(new Rect(4, 80, 100, 22), "<size=12>" + LocalizationManager.instance.current["colorRect_width"] + " :</size>");
                //   m_width = (uint)Mathf.FloorToInt(GUI.HorizontalSlider(new Rect(4, 44, 200, 25), m_width, 1, 2048));
                if (widthField == null)
                {
                    widthField = new GUIUtils.FloatInputField(m_width);
                }
                m_width = (uint)widthField.DrawField(new Rect(74, 79, 170, 35), m_width, false, 0f, 1024f, true, Mathf.Abs(Mathf.Round(textManager.windowTex.width - x))).returnValue;

                GUI.Label(new Rect(4, 115, 100, 22), "<size=12>" + LocalizationManager.instance.current["colorRect_height"] + " :</size>");
                if (heightField == null)
                {
                    heightField = new GUIUtils.FloatInputField(m_height);
                }
                m_height = (uint)heightField.DrawField(new Rect(74, 117, 170, 35), m_height, false, 0f, 1024f, true, Mathf.Abs(Mathf.Round(textManager.windowTex.height - y))).returnValue;

                GUI.Label(new Rect(4, 154, 200, 22), "<size=12>" + LocalizationManager.instance.current["colorRect_opacity"] + " : " + ((int)(m_fontColor.a * 100)).ToString() + "%</size>");
                m_fontColor.a = GUI.HorizontalSlider(new Rect(4, 176, 200, 25), m_fontColor.a, 0f, 1f);

                if (borderColor == null)
                {
                    borderColor = Color.white;
                }
                GUI.Label(new Rect(4, 193, 200, 22), "<size=12>" + LocalizationManager.instance.current["colorRect_border"] + " : " + borderSize.ToString() + " px</size>");
                borderSize    = (uint)Mathf.RoundToInt(GUI.HorizontalSlider(new Rect(4, 215, 200, 25), borderSize, 0f, 20f));
                borderPainter = GUIPainter.DrawPainterSampleOnly(borderPainter, new Vector2(214, 198), borderColor,
                                                                 (c) => { borderColor = c; },
                                                                 () =>
                {
                    if (textManager.colorPickerSelected == borderPainter)
                    {
                        textManager.colorPickerSelected = null;
                    }
                    else
                    {
                        textManager.colorPickerSelected = borderPainter;
                    }
                });
            }

            // POSITION

            GUIUtils.DrawSeparator(new Vector2(3, 29), 241);

            GUI.Label(new Rect(3, 30, 75, 21), "<size=12>" + LocalizationManager.instance.current["position"] + " :</size>");
            //  float newX, newY;
            if (posXfield == null)
            {
                posXfield = new GUIUtils.FloatInputField(x);
                posYfield = new GUIUtils.FloatInputField(y);
            }
            GUI.Label(new Rect(3, 51, 24, 22), "<size=12>X :</size>");
            x = posXfield.DrawField(new Rect(27, 50, 83, 22), "textPosX", x, true).returnValue;
            GUI.Label(new Rect(111, 51, 24, 22), "<size=12>Y :</size>");
            y = posYfield.DrawField(new Rect(135, 50, 83, 22), "textPosY", y, true).returnValue;

            // rotation
            if (GUI.Button(new Rect(220, 50, 25, 23), ProceduralObjectsMod.Icons[5]))
            {
                ProceduralObjectsLogic.PlaySound();
                if (m_type == 0)
                {
                    if (m_rotation == 0)
                    {
                        m_rotation = 4;
                    }
                    else if (m_rotation == 4)
                    {
                        m_rotation = 1;
                    }
                    else if (m_rotation == 1)
                    {
                        m_rotation = 2;
                    }
                    else if (m_rotation == 2)
                    {
                        m_rotation = 0;
                    }
                }
                else if (m_type == 1)
                {
                    var h = m_height;
                    m_height = m_width;
                    m_width  = h;
                }
            }


            GUI.EndGroup();
        }
        public void Update()
        {
            if (canDrawWindow)
            {
                /*
                 * if (showWindow)
                 *  GUIUtils.SetMouseScrolling(!windowRect.IsMouseInside());
                 * */
                updateTimer += TimeUtils.deltaTime;
                var mousePos = GUIUtils.MousePos;
                if (colorPickerSelected != null)
                {
                    GUIPainter.UpdatePainter(colorPickerSelected, () => { colorPickerSelected = null; });
                }

                if (dragTimer < .14f && dragTimer != 0f)
                {
                    dragTimer += TimeUtils.deltaTime;
                }
                cursorIsInsideTextureArea = windowRect.IsMouseInside();
                if (new Rect(windowRect.x + 5, windowRect.y + 30, windowRect.width - 285, windowRect.height - 80).IsMouseInside())
                {
                    if (Input.GetKey(KeyCode.LeftControl))
                    {
                        zoomFactor *= 1f + Input.mouseScrollDelta.y * 0.3f;
                    }

                    if (placingText)
                    {
                        if (Input.GetMouseButtonDown(0))
                        {
                            var field = parameters.AddField(fontManager.Arial, 0);
                            field.x       = (mousePos.x - windowRect.x - 5 + scrollTex.x) / zoomFactor;
                            field.y       = (mousePos.y - windowRect.y - 30 + scrollTex.y) / zoomFactor;
                            selectedField = field;
                            placingText   = false;
                            _justPlacedTextNowFocusField = true;
                        }
                    }
                    else if (placingRect)
                    {
                        if (placingRectFirstpoint != Vector2.down)
                        {
                            var field       = selectedField;
                            var secondPoint = new Vector2((mousePos.x - windowRect.x - 5 + scrollTex.x) / zoomFactor,
                                                          (mousePos.y - windowRect.y - 30 + scrollTex.y) / zoomFactor);
                            field.x        = Mathf.Min(placingRectFirstpoint.x, secondPoint.x);
                            field.y        = Mathf.Min(placingRectFirstpoint.y, secondPoint.y);
                            field.m_width  = (uint)Mathf.RoundToInt(Mathf.Abs(secondPoint.x - placingRectFirstpoint.x));
                            field.m_height = (uint)Mathf.RoundToInt(Mathf.Abs(secondPoint.y - placingRectFirstpoint.y));
                        }
                        if (Input.GetMouseButtonDown(0))
                        {
                            if (placingRectFirstpoint == Vector2.down)
                            {
                                ProceduralObjectsLogic.PlaySound();
                                var field = parameters.AddField(fontManager.Arial, 1);
                                placingRectFirstpoint = new Vector2((mousePos.x - windowRect.x - 5 + scrollTex.x) / zoomFactor,
                                                                    (mousePos.y - windowRect.y - 30 + scrollTex.y) / zoomFactor);
                                field.x       = placingRectFirstpoint.x;
                                field.y       = placingRectFirstpoint.y;
                                selectedField = field;
                            }
                            else
                            {
                                ProceduralObjectsLogic.PlaySound();
                                placingRectFirstpoint = Vector2.down;
                                placingRect           = false;
                            }
                        }
                    }
                    else
                    {
                        if (movingField > -1)
                        {
                            parameters[movingField].x = ((mousePos.x - windowRect.x - 5 + scrollTex.x) / zoomFactor) - dragTexPos.x;
                            parameters[movingField].y = ((mousePos.y - windowRect.y - 30 + scrollTex.y) / zoomFactor) - dragTexPos.y;
                            if (Input.GetMouseButtonDown(0))
                            {
                                ProceduralObjectsLogic.PlaySound();
                                dragTexPos  = Vector2.zero;
                                movingField = -1;
                            }
                        }
                        else if (movingField == -1)
                        {
                            if (Input.GetMouseButtonDown(0))
                            {
                                dragTimer = 0.0001f;
                            }
                            if (Input.GetMouseButton(0))
                            {
                                if (dragTimer >= .14f)
                                {
                                    if (dragTexPos == Vector2.zero)
                                    {
                                        dragTexPos = new Vector2((mousePos.x - windowRect.x - 5 + scrollTex.x) / zoomFactor, (mousePos.y - windowRect.y - 30 + scrollTex.y) / zoomFactor);
                                    }
                                }
                            }
                        }
                    }
                }

                if (Input.GetMouseButton(0))
                {
                    if (movingField == -2)
                    {
                        var size = mousePos - windowRect.position;
                        windowRect.size = new Vector2(Mathf.Max(windowRect.x + 400, size.x), Mathf.Max(windowRect.y + 350, size.y));
                    }
                    else if (movingField == -3)
                    {
                        separatorListEditionZone = Mathf.Clamp(mousePos.y - windowRect.y, 125, 450);
                    }
                    else if (dragTimer >= .14f)
                    {
                        if (dragTexPos != Vector2.zero)
                        {
                            scrollTex = new Vector2(zoomFactor * dragTexPos.x - mousePos.x + windowRect.x + 5, zoomFactor * dragTexPos.y - mousePos.y + windowRect.y + 30);
                        }
                    }
                }
                else if (Input.GetMouseButtonUp(0))
                {
                    if (movingField <= -2)
                    {
                        movingField = -1;
                    }

                    if (movingField <= -1)
                    {
                        dragTexPos = Vector2.zero;
                    }
                    dragTimer = 0f;
                }
                else
                {
                    if (movingField == -2)
                    {
                        movingField = -1;
                    }
                }
                if (updateTimer > .1f)
                {
                    if (TextParameters.IsDifference(parameters, parametersOld))
                    {
                        var oldTex = windowTex;
                        // apply changes
                        windowTex = parameters.ApplyParameters(originalTex);
                        editingObject.m_material.mainTexture = windowTex as Texture;
                        // save textparameters to the editingObject instance
                        editingObject.m_textParameters = parameters;
                        // try save on RAM usage
                        if (!TextParameters.IsEmpty(parametersOld))
                        {
                            oldTex.DisposeTexFromMemory();
                        }
                    }
                    parametersOld = TextParameters.Clone(parameters, false);
                    updateTimer   = 0f;
                }
            }
        }