private void DrawJobItemBar(TodoItem item, float y) { if (item.status == Status.PENDING) { return; } Color color = Color.white; switch (item.status) { case Status.PENDING: color = XKCDColors.LightRed; break; case Status.IN_PROGRESS: color = XKCDColors.LightRed; Rect rect = JobRect(item, y); CustomGUIUtils.DrawFrameBox(rect, color, 1f, Color.black); rect.width = 200; GUI.Label(rect, item.name); break; case Status.DONE: color = XKCDColors.LightAquamarine; CustomGUIUtils.DrawFrameBox(JobRect(item, y), color, 1f, Color.black); break; default: statusStyle = GUIStyle.none; break; } }
private void DrawTodoItemBar(TodoItem item, float y) { if (item.status == Status.PENDING) { return; } Color color = Color.white; switch (item.status) { case Status.PENDING: color = XKCDColors.LightRed; break; case Status.IN_PROGRESS: color = XKCDColors.LightYellow; Rect rect = TodoRect(item, y); CustomGUIUtils.DrawFrameBox(rect, color, 1f, Color.black); rect.width = 200; GUI.Label(rect, item.name); break; case Status.DONE: color = XKCDColors.LightGreen; Rect rectBox = TodoRect(item, y); CustomGUIUtils.DrawFrameBox(rectBox, color, 1f, Color.black); //if (rectBox.Contains(Event.current.mousePosition)) //{ // Rect tooltip = new Rect(rectBox); // tooltip.width = 100; // CustomGUIUtils.DrawFrameBox(tooltip, XKCDColors.YellowTan, 1, XKCDColors.YellowOrange); // GUI.Label(tooltip, item.name); //} break; default: statusStyle = GUIStyle.none; break; } }
void OnGUI() { if (initialized) { #region sidebar if (sidebarOpen) { sidebarRect = openRect; } else { sidebarRect = closedRect; } CustomGUIUtils.DrawFrameBox(sidebarRect, Color.gray, 3f, Color.black); if (GUI.Button(new Rect(sidebarRect.xMax - 10, sidebarRect.height / 2 - 10, 20f, 20f), (sidebarOpen ? DefaultIconSet.ArrowsLeft : DefaultIconSet.ArrowsRight))) { sidebarOpen = !sidebarOpen; } if (sidebarOpen) { scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(openRect.width), GUILayout.Height(openRect.height)); this.guiMethod(); GUILayout.EndScrollView(); } else { } #endregion // sidebar } }
public static void ColorPicker(string name, Rect boundingRect, ref float angle, ref float radius, ref float dimm, ref Color color) { // Draw bounding Rectangle Rect newBounds = new Rect(boundingRect); newBounds.height += 70f; newBounds = newBounds.AddFrame(4); GUIAreas.Add(name, newBounds); CustomGUIUtils.DrawFrameBox(newBounds, Color.white, 1f, Color.black); CustomGUIUtils.DrawFrameBox(boundingRect, Color.white, 1f, Color.black); // Calculate box-values float boxWidth = Mathf.Min(boundingRect.width, boundingRect.height); float boxWidthHalf = boxWidth / 2f; // Draw Color-Wheel GUI.DrawTexture(boundingRect, DefaultIconSet.ColorWheel); // Get old State if (!colorPickers.TryGetValue(name, out currentColorPicker)) { currentColorPicker = new ColorPickerProperties(); //currentColorPicker.pickerXY = new Vector2(boxWidthHalf, boxWidthHalf); colorPickers.Add(name, currentColorPicker); } if (!currentColorPicker.isDragging) { // Calculate Vector for the PickerPosition Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward); Vector3 vect = rotation * Vector3.left; Debug.Log(vect); currentColorPicker.pickerXY = vect.normalized * ((boxWidthHalf / 100) * radius) + boundingRect.Position().Vector3FromVector2XY(); Debug.Log("Calculated Color Picker: " + currentColorPicker.pickerXY); currentColorPicker.dimm = dimm; currentColorPicker.angle = angle; currentColorPicker.radius = radius; } Vector3 mousePosition = Input.mousePosition.SwapScreenToWorldPoint(); Vector2 mouseXY = new Vector2(mousePosition.x, mousePosition.y); // Draw Picker Rect pickerRect = new Rect( currentColorPicker.pickerXY.x + boundingRect.xMin - 10f, currentColorPicker.pickerXY.y + boundingRect.yMin - 10f, 20f, 20f); GUI.DrawTexture(pickerRect, DefaultIconSet.Location); // Handle Mouse-Input if (pickerRect.Contains(Input.mousePosition.SwapScreenToWorldPoint()) && Input.GetMouseButtonDown(0)) { currentColorPicker.isDragging = true; } else if (currentColorPicker.isDragging && Input.GetMouseButton(0)) { // Set Color-Picker Position currentColorPicker.pickerXY = mouseXY - boundingRect.Position(); Vector2 direction = mouseXY - boundingRect.center; if (mouseXY.y > boundingRect.center.y) { angle = 360 - Vector2.Angle(-Vector2.right, direction); } else { angle = Vector2.Angle(-Vector2.right, direction); } float magnitude = direction.magnitude / (boxWidthHalf / 100); radius = Mathf.Clamp(magnitude, 0f, 100f); currentColorPicker.pickerXY = boundingRect.Position() + direction.normalized * Mathf.Clamp(magnitude, 0, boxWidthHalf); currentColorPicker.angle = angle; currentColorPicker.radius = radius; } else if (currentColorPicker.isDragging && Input.GetMouseButtonUp(0)) { currentColorPicker.isDragging = false; } // Calculate Pixel Coordinates of the picker in the ColorWheel Vector2 pixelCoords = new Vector2(); pixelCoords.x = ((float)DefaultIconSet.ColorWheel.width / boxWidth) * currentColorPicker.pickerXY.x; pixelCoords.y = DefaultIconSet.ColorWheel.height - ((float)DefaultIconSet.ColorWheel.height / boxWidth) * currentColorPicker.pickerXY.y; //Debug.Log("pixelcoords: " + pixelCoords); color = DefaultIconSet.ColorWheel.GetPixel((int)pixelCoords.x, (int)pixelCoords.y); // Draw Dimmer-Gradient-Color-View CustomGUIUtils.DrawFrameBox(new Rect(boundingRect.xMin, boundingRect.yMax + 5, boxWidth, 25), color, 1f, Color.black); GUI.DrawTexture(new Rect(boundingRect.xMin, boundingRect.yMax + 5, boxWidth, 25), BlackTransparentGradient); angle = currentColorPicker.angle; radius = currentColorPicker.radius; dimm = GUI.HorizontalSlider(new Rect(boundingRect.xMin, boundingRect.yMax + 40f, boxWidth, 20), Mathf.Clamp(currentColorPicker.dimm, 0, 100), 0f, 100f);; currentColorPicker.dimm = dimm; // Draw Dimmer-Label GUIStyle style = CustomGUIUtils.GetColorTextStyle(Color.black, 14); style.alignment = TextAnchor.MiddleCenter; GUI.Label(new Rect(boundingRect.xMin, boundingRect.yMax + 50f, boxWidth, 20), ((int)dimm).ToString(), style); //Debug.Log(currentColorPicker.pickerXY.ToString() + " angle: " + angle + " r=" + radius + " dimm=" + dimm); colorPickers[name] = currentColorPicker; }
public static DialogResultType Dialog(DialogType dialogType, string title, string message, Rect rect, float factor, ref bool showDialog) { result = DialogResultType.UNDEFINED; if (target == 0) { if (t > 0) { t -= Time.deltaTime / factor; } } else if (target == 1) { if (t < 1) { t += Time.deltaTime / factor; } } t = Mathf.Clamp01(t); if (MathUtils.AlmostEqual(t, 0f, 0.01f) && target == 0f) { //ease = false; showDialog = false; target = 1f; Debug.Log("Done?" + showDialog); } if (ease && showDialog) { if (target == 1) { currentRect = EasingCurves.EaseRect( closedRect, rect, EasingCurves.EaseType.easeOutExpo, t); } else if (target == 0) { currentRect = EasingCurves.EaseRect( closedRect, rect, EasingCurves.EaseType.easeInExpo, t); } } CustomGUIUtils.DrawFrameBox(currentRect, Color.gray, 3f, Color.black); //if(t == 1){ GUILayout.BeginArea(currentRect); GUILayout.Label(title, GUILayout.Width(currentRect.width), GUILayout.Height(30f)); GUILayout.Space(30f); GUILayout.BeginHorizontal(); GUILayout.Space(30f); GUILayout.BeginVertical(); GUILayout.Label(message); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); switch (dialogType) { case DialogType.YES_NO: if (GUILayout.Button("Yes")) { CloseDialog(); result = DialogResultType.YES; } if (GUILayout.Button("No")) { CloseDialog(); result = DialogResultType.NO; } break; case DialogType.YES_NO_CANCEL: if (GUILayout.Button("Yes")) { CloseDialog(); result = DialogResultType.YES; } if (GUILayout.Button("No")) { CloseDialog(); result = DialogResultType.NO; } if (GUILayout.Button("Cancel")) { CloseDialog(); result = DialogResultType.CANCEL; } break; case DialogType.OK: if (GUILayout.Button("OK")) { CloseDialog(); result = DialogResultType.OK; } break; case DialogType.OK_CANCEL: if (GUILayout.Button("Cancel")) { CloseDialog(); result = DialogResultType.CANCEL; } break; default: result = DialogResultType.UNDEFINED; break; } GUILayout.EndHorizontal(); GUILayout.EndArea(); return(result); }
public static Rect BeginSideBar(string sidebarName, SidebarType sidebarType, Rect boundingRect, Rect openRect, bool startStateOpen, float inset, EasingCurves.EaseType easeInType, EasingCurves.EaseType easeOutType, float factor) { SidebarProperties sidebarProperties = null; // If the Sidebar has not been created yet --> create the Sidebar if (!sidebars.ContainsKey(sidebarName)) { // create properties instance sidebarProperties = new SidebarProperties(); sidebarProperties.sidebarName = sidebarName; sidebarProperties.sidebarType = sidebarType; sidebarProperties.inset = inset; sidebarProperties.easeInType = easeInType; sidebarProperties.easeOutType = easeOutType; sidebarProperties.factor = factor; sidebarProperties.boundingRect = boundingRect; if (sidebarProperties.boundingRect.Equals(new Rect())) { sidebarProperties.boundingRect = new Rect(0f, 0f, Screen.width, Screen.height); } // initialize the Rectangles switch (sidebarType) { case SidebarType.LEFT: sidebarProperties.openRect = new Rect(sidebarProperties.boundingRect.xMin, sidebarProperties.boundingRect.yMin + openRect.yMin, openRect.width, openRect.height); sidebarProperties.closedRect = new Rect(sidebarProperties.boundingRect.xMin, sidebarProperties.boundingRect.yMin + openRect.yMin, 0f, openRect.height); break; case SidebarType.RIGHT: sidebarProperties.openRect = new Rect(sidebarProperties.boundingRect.xMax - openRect.width, sidebarProperties.boundingRect.yMin + openRect.yMin, openRect.width, openRect.height); sidebarProperties.closedRect = new Rect(sidebarProperties.boundingRect.xMax, sidebarProperties.boundingRect.yMin + openRect.yMin, 0f, openRect.height); break; case SidebarType.TOP: sidebarProperties.openRect = new Rect(sidebarProperties.boundingRect.xMin + openRect.xMin, sidebarProperties.boundingRect.yMin, openRect.width, openRect.height); sidebarProperties.closedRect = new Rect(sidebarProperties.boundingRect.xMin + openRect.xMin, sidebarProperties.boundingRect.yMin, openRect.width, 0f); break; case SidebarType.BOTTOM: sidebarProperties.openRect = new Rect(sidebarProperties.boundingRect.xMin + openRect.xMin, sidebarProperties.boundingRect.yMax - openRect.height, openRect.width, openRect.height); sidebarProperties.closedRect = new Rect(sidebarProperties.boundingRect.xMin + openRect.xMin, sidebarProperties.boundingRect.yMax, openRect.width, 0f); break; default: break; } // Initialize withe the desired state after creation if (startStateOpen) { sidebarProperties.currentRect = sidebarProperties.openRect; sidebarProperties.open = 1f; sidebarProperties.current = 1f; sidebarProperties.target = 0f; } else { sidebarProperties.currentRect = sidebarProperties.closedRect; sidebarProperties.open = 0f; sidebarProperties.current = 0f; sidebarProperties.target = 1f; } // Add SidebarProperties to the Dictionary sidebars.Add(sidebarName, sidebarProperties); } else { // A sidebar of that name already existed --> get its Properties sidebars.TryGetValue(sidebarName, out sidebarProperties); //// initialize the Rectangles switch (sidebarProperties.sidebarType) { case SidebarType.LEFT: sidebarProperties.openRect = new Rect(sidebarProperties.boundingRect.xMin, sidebarProperties.boundingRect.yMin + openRect.yMin, openRect.width, openRect.height); sidebarProperties.closedRect = new Rect(sidebarProperties.boundingRect.xMin, sidebarProperties.boundingRect.yMin + openRect.yMin, 0f, openRect.height); break; case SidebarType.RIGHT: sidebarProperties.openRect = new Rect(sidebarProperties.boundingRect.xMax - openRect.width, sidebarProperties.boundingRect.yMin + openRect.yMin, openRect.width, openRect.height); sidebarProperties.closedRect = new Rect(sidebarProperties.boundingRect.xMax, sidebarProperties.boundingRect.yMin + openRect.yMin, 0f, openRect.height); break; case SidebarType.TOP: sidebarProperties.openRect = new Rect(sidebarProperties.boundingRect.xMin + openRect.xMin, sidebarProperties.boundingRect.yMin, openRect.width, openRect.height); sidebarProperties.closedRect = new Rect(sidebarProperties.boundingRect.xMin + openRect.xMin, sidebarProperties.boundingRect.yMin, openRect.width, 0f); break; case SidebarType.BOTTOM: sidebarProperties.openRect = new Rect(sidebarProperties.boundingRect.xMin + openRect.xMin, sidebarProperties.boundingRect.yMax - openRect.height, openRect.width, openRect.height); sidebarProperties.closedRect = new Rect(sidebarProperties.boundingRect.xMin + openRect.xMin, sidebarProperties.boundingRect.yMax, openRect.width, 0f); break; default: break; } } GUIAreas.Add(sidebarProperties.sidebarName, sidebarProperties.currentRect); // Draw the current Rectangle CustomGUIUtils.DrawFrameBox(sidebarProperties.currentRect, Color.gray, 3f, Color.black); // Start GUIArea with Insets and ScrollView GUI.BeginGroup(currentRect); GUILayout.BeginArea(sidebarProperties.currentRect); GUILayout.BeginVertical(); GUILayout.Space(sidebarProperties.inset); GUILayout.BeginHorizontal(); GUILayout.Space(sidebarProperties.inset); sidebarProperties.scrollPosition = GUILayout.BeginScrollView(sidebarProperties.scrollPosition); sidebarPropertiesStack.Push(sidebarProperties); return(sidebarProperties.currentRect); }