private void draw(int id) { GUI.DragWindow(new Rect(0, 0, 365, 28)); if (GUI.Button(new Rect(370, 3, 28, 28), "X")) { ProceduralObjectsLogic.PlaySound(); CloseWindow(); } else { // texture display // GUI.Box(new Rect(5, 30, 390, 300), string.Empty); // GUI.Label(new Rect(10, 35, 380, 290), windowTex); scrollTex = GUI.BeginScrollView(new Rect(5, 30, 390, 300), scrollTex, new Rect(0, 0, windowTex.width * zoomFactor, windowTex.height * zoomFactor)); GUI.DrawTexture(new Rect(0, 0, windowTex.width * zoomFactor, windowTex.height * zoomFactor), windowTex as Texture); if (movingField == -1) { for (int i = 0; i < parameters.Count(); i++) { if (!parameters[i].locked) { if (GUI.Button(new Rect(parameters[i].x * zoomFactor, parameters[i].y * zoomFactor, parameters[i].texWidth * zoomFactor, parameters[i].texHeight * zoomFactor), string.Empty, GUI.skin.label)) { ProceduralObjectsLogic.PlaySound(); movingField = i; } } } } GUI.EndScrollView(); GUI.Label(new Rect(11, 335, 260, 27), "<size=17>" + LocalizationManager.instance.current["text_fields"] + "</size>"); GUI.Label(new Rect(285, 337, 220, 27), LocalizationManager.instance.current["zoom"]); if (GUI.RepeatButton(new Rect(340, 335, 28, 26), "<size=20><b>+</b></size>")) { zoomIn(); } if (GUI.RepeatButton(new Rect(370, 335, 28, 26), "<size=22><b>-</b></size>")) { zoomOut(); } // parameters box if (parameters.Count() == 0) { GUI.Box(new Rect(5, 363, 390, 232), string.Empty); } scrollParams = GUI.BeginScrollView(new Rect(10, 368, 380, 222), scrollParams, new Rect(0, 0, 355, parameters.m_textFields.Where(p => !p.minimized).Count() * 125 + parameters.m_textFields.Where(p => p.minimized).Count() * 33 + 69)); int j = 2; for (int i = 0; i < parameters.Count(); i++) { bool minimized = parameters[i].minimized; parameters[i].DrawUI(new Vector2(3, j), this, ShowCharTable, movingField == -1); if (minimized) { j += 33; } else { j += 125; } } if (GUI.Button(new Rect(3, j, 350, 30), "<b>+</b> " + LocalizationManager.instance.current["add_field"])) { ProceduralObjectsLogic.PlaySound(); parameters.AddField(fontManager.Arial, 0); } if (GUI.Button(new Rect(3, j + 33, 350, 30), "<b>+</b> " + LocalizationManager.instance.current["add_color_rect"])) { ProceduralObjectsLogic.PlaySound(); parameters.AddField(fontManager.Arial, 1); } GUI.EndScrollView(); } }
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; } } }