public static void DrawControls(SpriteBatch sb, Dictionary <string, IControl> controls, IControl selected) { foreach (var control in controls.Values) { if (control != selected) { control.Draw(sb); } } if (selected != null) { selected.Draw(sb); } }
private void DrawCitizens(SpriteBatch spriteBatch, Vector2 position, IControl image, int citizenCount) { image.Visible = true; var x = (int)position.X; var y = (int)position.Y; for (var i = 0; i < citizenCount; i++) { image.Position = new PointI(x, y); image.Draw(spriteBatch); x += image.Width; } image.Visible = false; }
public virtual void Draw() { control.Draw(); }
/// <summary> /// Draw the whole region holding the two control and the separator. /// The separator pass down the proper region to Draw of the sub-controls. /// Returns true if the window needs to be repainted. /// </summary> public bool Draw(Rect region) { float half = (WIDTH * 0.5f); float position; Rect separator, left, right, draw; Texture texture; if (orientation == SeparatorOrientation.Vertical) { size = region.width; if (perPixel) { position = division + region.x; } else { position = region.width * division + region.x; } separator = new Rect(position - half - 2, region.y, WIDTH, region.height); if (draggable) { EditorGUIUtility.AddCursorRect(separator, MouseCursor.ResizeHorizontal); } draw = new Rect(position - half, region.y, WIDTH - 4, region.height); if (PerPixel) { left = new Rect(region.x, region.y, division - half, region.height); right = new Rect(position + half, region.y, region.width - (division + half), region.height); } else { left = new Rect(region.x, region.y, region.width * division - half, region.height); right = new Rect(position + half, region.y, region.width - (region.width * division + half), region.height); } texture = SeparatorVertical; } else { size = region.height; if (perPixel) { position = division + region.y; } else { position = region.height * division + region.x; } separator = new Rect(region.x, position - half - 2, region.width, WIDTH); if (draggable) { EditorGUIUtility.AddCursorRect(separator, MouseCursor.ResizeVertical); } draw = new Rect(region.x, position - half, region.width, WIDTH - 4); if (PerPixel) { left = new Rect(region.x, region.y, region.width, division - half); right = new Rect(region.x, position + half, region.width, region.height - (division + half)); } else { left = new Rect(region.x, region.y, region.width, region.height * division - half); right = new Rect(region.x, position + half, region.width, region.height - (region.height * division + half)); } texture = SeparatorHorizontal; } bool selected = false; if (draggable) { if (drag) { GUI.color = InspectorPreferences.SeparatorSelectedColor; } else if (Event.current != null && separator.Contains(Event.current.mousePosition)) { GUI.color = HOVERED; selected = true; } else { GUI.color = InspectorPreferences.SeparatorDefaultColor; } } else { GUI.color = InspectorPreferences.SeparatorDefaultColor; } GUI.DrawTexture(draw, texture); GUI.color = Color.white; bool repaintLeft = false; bool repaintRight = false; if (leftControl != null) { repaintLeft = leftControl.Draw(left); } if (rightControl != null) { repaintRight = rightControl.Draw(right); } if (Event.current == null) { return(repaintLeft | repaintRight | selected); } if (draggable) { if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { if (separator.Contains(Event.current.mousePosition)) { drag = true; mousePosition = Event.current.mousePosition; return(true); } } else if (Event.current.type == EventType.MouseUp) { drag = false; return(true); } else if (Event.current.type == EventType.MouseDrag && drag) { Vector2 delta = Event.current.mousePosition - mousePosition; if (perPixel) { if (orientation == SeparatorOrientation.Vertical) { Division += delta.x; } else { Division += delta.y; } } else { if (orientation == SeparatorOrientation.Vertical) { Division += (delta.x / region.width); } else { Division += (delta.y / region.height); } } mousePosition = Event.current.mousePosition; return(true); } } return(repaintLeft | repaintRight | selected); }