protected Vector2 ApplyAlignment(Vector2 vector, RectAlignment alignment = RectAlignment.MiddleCenter) { switch (alignment) { case RectAlignment.MiddleCenter: return(new Vector2((1 - vector.x) / 2, (1 - vector.y) / 2)); case RectAlignment.MiddleLeft: return(new Vector2(0, (1 - vector.y) / 2)); case RectAlignment.MiddleRight: return(new Vector2(1 - vector.x, (1 - vector.y) / 2)); case RectAlignment.UpperCenter: return(new Vector2((1 - vector.x) / 2, 1 - vector.y)); case RectAlignment.LowerCenter: return(new Vector2((1 - vector.x) / 2, 0f)); case RectAlignment.UpperLeft: return(new Vector2(0, 1 - vector.y)); case RectAlignment.UpperRight: return(new Vector2(1 - vector.x, 1 - vector.y)); case RectAlignment.LowerLeft: return(new Vector2(0, 0)); case RectAlignment.LowerRight: return(new Vector2(1 - vector.x, 0)); } return(vector); }
public DrawRect(Point pos, int width, int height) : this() { m_alignment = RectAlignment.Absolute; m_pos = pos; m_size = new Size(width, height); m_rect = new Rectangle(pos.X, pos.Y, width, height); }
public Struct37(float A_0, float A_1) { this.rectAlignment_0 = RectAlignment.TopLeft; this.flipOrientation_0 = FlipOrientation.None; this.float_0 = A_0; this.float_1 = A_1; this.float_2 = 0f; this.float_3 = 0f; }
public DrawRect Add(RectAlignment alignment, int size) { DrawRect res = CreateInstance(); res.m_size = new Size(size, size); res.m_alignment = alignment; Add(res); return(res); }
public Rect AllocateRect(float width, float height, RectAlignment alignment, float spacing = float.NegativeInfinity) { var bigRect = AllocateRect(width, height, spacing); if (alignment == RectAlignment.Full || allocator == RectAllocator.Center || allocator == RectAllocator.LeftAlign || allocator == RectAllocator.RightAlign) { return(bigRect); } return(AlignRect(bigRect, alignment, width, height)); }
protected RectAlignment GetRectAlignment(string alignment) { RectAlignment rectAlignment = RectAlignment.MiddleCenter; if (Enum.GetNames(typeof(RectAlignment)).Contains(alignment, StringComparer.OrdinalIgnoreCase)) { rectAlignment = (RectAlignment)Enum.Parse(typeof(RectAlignment), alignment, true); } return(rectAlignment); }
public DrawRect(Control control, Point pos, int width, int height) : this() { m_LockControl = control; m_alignment = RectAlignment.Absolute; m_pos = pos; m_size = new Size(width, height); m_rect = new Rectangle(pos.X, pos.Y, width, height); m_freeRect = GetClientRect(); m_invalidateRegion = new Region(); }
protected RectAlignmentStruct GetRectAlignmentStruct(RectAlignment alignment) { Vector2 pivot = new Vector2(0.5f, 0.5f); Vector2 anchorMin = new Vector2(0, 0); Vector2 anchorMax = new Vector2(1, 1); switch (alignment) { case RectAlignment.LowerCenter: pivot = new Vector2(0.5f, 0); break; case RectAlignment.LowerLeft: pivot = new Vector2(0, 0); break; case RectAlignment.LowerRight: pivot = new Vector2(1, 0); break; case RectAlignment.MiddleCenter: break; case RectAlignment.MiddleLeft: pivot = new Vector2(0, 0.5f); break; case RectAlignment.MiddleRight: pivot = new Vector2(1, 0.5f); break; case RectAlignment.UpperCenter: pivot = new Vector2(0.5f, 1); break; case RectAlignment.UpperLeft: pivot = new Vector2(0, 1); break; case RectAlignment.UpperRight: pivot = new Vector2(1, 1); break; } return(new RectAlignmentStruct { Pivot = pivot, AnchorMin = anchorMin, AnchorMax = anchorMax }); }
public static Rect Align(Vector2 rectSize, Rect container, RectAlignment alignment) { Vector2 position = Vector2.zero; Vector2 middleRectSize = rectSize / 2f; switch (alignment) { case RectAlignment.TopLeft: position = container.position; break; case RectAlignment.TopCenter: position = new Vector2(container.center.x - middleRectSize.x, container.yMin); break; case RectAlignment.TopRight: position = new Vector2(container.xMax - rectSize.x, container.yMin); break; case RectAlignment.CenterLeft: position = new Vector2(container.xMin, container.center.y - middleRectSize.y); break; case RectAlignment.Center: position = container.center - middleRectSize; break; case RectAlignment.CenterRight: position = new Vector2(container.xMax - rectSize.x, container.center.y - middleRectSize.y); break; case RectAlignment.BottomLeft: position = new Vector2(container.xMin, container.yMax - rectSize.y); break; case RectAlignment.BottomCenter: position = new Vector2(container.center.x - middleRectSize.x, container.yMax - rectSize.y); break; case RectAlignment.BottomRight: position = new Vector2(container.xMax - rectSize.x, container.yMax - rectSize.y); break; } return(new Rect(position, rectSize)); }
public static Rect AlignRect(Rect boundary, RectAlignment alignment, float width, float height) { switch (alignment) { case RectAlignment.Middle: return(new Rect(boundary.X + (boundary.Width - width) * 0.5f, boundary.Y + (boundary.Height - height) * 0.5f, width, height)); case RectAlignment.MiddleLeft: return(new Rect(boundary.X, boundary.Y + (boundary.Height - height) * 0.5f, width, height)); case RectAlignment.MiddleRight: return(new Rect(boundary.X, boundary.Y + (boundary.Height - height) * 0.5f, width, height)); case RectAlignment.UpperCenter: return(new Rect(boundary.X + (boundary.Width - width) * 0.5f, boundary.Y, width, height)); case RectAlignment.MiddleFullRow: return(new Rect(boundary.X, boundary.Y + (boundary.Height - height) * 0.5f, boundary.Width, height)); default: return(boundary); } }
public bool BuildTextInput(string text, out string newText, string placeholder, FontFile.FontSize fontSize, bool delayed, Icon icon, Padding padding, RectAlignment alignment, SchemeColor color) { newText = text; Rect textRect, realTextRect; using (gui.EnterGroup(padding, RectAllocator.LeftRow)) { var lineSize = gui.PixelsToUnits(fontSize.lineSize); if (icon != Icon.None) { gui.BuildIcon(icon, lineSize, color + 3); } textRect = gui.RemainingRow(0.3f).AllocateRect(0, lineSize, RectAlignment.MiddleFullRow); } var boundingRect = gui.lastRect; var focused = rect == boundingRect; if (focused && this.text == null) { this.text = text ?? ""; SetCaret(0, this.text.Length); } switch (gui.action) { case ImGuiAction.MouseDown: if (gui.actionParameter != SDL.SDL_BUTTON_LEFT) { break; } if (gui.ConsumeMouseDown(boundingRect)) { SetFocus(boundingRect, text ?? ""); GetTextParameters(this.text, textRect, fontSize, alignment, out _, out _, out _, out realTextRect); SetCaret(FindCaretIndex(text, gui.mousePosition.X - realTextRect.X, fontSize, textRect.Width)); } break; case ImGuiAction.MouseMove: if (focused && gui.actionParameter == SDL.SDL_BUTTON_LEFT) { GetTextParameters(this.text, textRect, fontSize, alignment, out _, out _, out _, out realTextRect); SetCaret(caret, FindCaretIndex(this.text, gui.mousePosition.X - realTextRect.X, fontSize, textRect.Width)); } gui.ConsumeMouseOver(boundingRect, RenderingUtils.cursorCaret, false); break; case ImGuiAction.Build: var textColor = color + 2; string textToBuild; if (focused) { textToBuild = this.text; } else if (string.IsNullOrEmpty(text)) { textToBuild = placeholder; textColor = color + 3; } else { textToBuild = text; } GetTextParameters(textToBuild, textRect, fontSize, alignment, out var cachedText, out var scale, out var textWidth, out realTextRect); if (cachedText != null) { gui.DrawRenderable(realTextRect, cachedText, textColor); } if (focused) { if (selectionAnchor != caret) { var left = GetCharacterPosition(Math.Min(selectionAnchor, caret), fontSize, textWidth) * scale; var right = GetCharacterPosition(Math.Max(selectionAnchor, caret), fontSize, textWidth) * scale; gui.DrawRectangle(new Rect(left + realTextRect.X, realTextRect.Y, right - left, realTextRect.Height), SchemeColor.TextSelection); } else { if (nextCaretTimer <= Ui.time) { nextCaretTimer = Ui.time + 500; caretVisible = !caretVisible; } gui.SetNextRebuild(nextCaretTimer); if (caretVisible) { var caretPosition = GetCharacterPosition(caret, fontSize, textWidth) * scale; gui.DrawRectangle(new Rect(caretPosition + realTextRect.X - 0.05f, realTextRect.Y, 0.1f, realTextRect.Height), color + 2); } } } gui.DrawRectangle(boundingRect, color); break; } if (boundingRect == prevRect) { var changed = text != prevText; if (changed) { newText = prevText; } prevRect = default; prevText = null; return(changed); } if (focused && !delayed && this.text != text) { newText = this.text; return(true); } return(false); }
private void GetTextParameters(string textToBuild, Rect textRect, FontFile.FontSize fontSize, RectAlignment alignment, out TextCache cachedText, out float scale, out float textWidth, out Rect realTextRect) { realTextRect = textRect; scale = 1f; textWidth = 0f; if (!string.IsNullOrEmpty(textToBuild)) { cachedText = gui.textCache.GetCached((fontSize, textToBuild, uint.MaxValue)); textWidth = gui.PixelsToUnits(cachedText.texRect.w); if (textWidth > realTextRect.Width) { scale = realTextRect.Width / textWidth; } else { realTextRect = ImGui.AlignRect(textRect, alignment, textWidth, textRect.Height); } } else { realTextRect = ImGui.AlignRect(textRect, alignment, 0f, textRect.Height); cachedText = null; } }
private void method_5(ref RectangleF A_0, RectangleF A_1, RectAlignment A_2) { float num = 0f; float num2 = 0f; switch (A_2) { case RectAlignment.TopLeft: break; case RectAlignment.Bottom: num = A_1.Height - A_0.Height; num2 = (A_1.Width - A_0.Width) / 2f; A_0.X += num2; A_0.Y += num; return; case RectAlignment.BottomLeft: num = A_1.Height - A_0.Height; A_0.Y += num; return; case RectAlignment.BottomRight: num = A_1.Height - A_0.Height; num2 = A_1.Width - A_0.Width; A_0.X += num2; A_0.Y += num; return; case RectAlignment.Center: num = (A_1.Height - A_0.Height) / 2f; num2 = (A_1.Width - A_0.Width) / 2f; A_0.X += num2; A_0.Y += num; return; case RectAlignment.Left: num = (A_1.Height - A_0.Height) / 2f; A_0.Y += num; return; case RectAlignment.Right: num = (A_1.Height - A_0.Height) / 2f; num2 = A_1.Width - A_0.Width; A_0.X += num2; A_0.Y += num; return; case RectAlignment.Top: num2 = (A_1.Width - A_0.Width) / 2f; A_0.X += num2; return; case RectAlignment.TopRight: num2 = A_1.Width - A_0.Width; A_0.X += num2; break; default: return; } }
protected RectAlignmentStruct GetAlignmentStruct(float width, float height, Vector2 position, RectAlignment alignment = RectAlignment.MiddleCenter) { Vector2 pivot = new Vector2(0.5f, 0.5f); Vector2 anchorMin = new Vector2(0.5f, 0.5f); Vector2 anchorMax = new Vector2(0.5f, 0.5f); var halfWidth = width / 2f; var halfHeight = height / 2f; switch (alignment) { case RectAlignment.LowerCenter: pivot = new Vector2(0.5f, 0); anchorMin = new Vector2(0.5f, 0); anchorMax = new Vector2(0.5f, 0); position = new Vector2(0, halfHeight); break; case RectAlignment.LowerLeft: pivot = new Vector2(0, 0); anchorMin = new Vector2(0, 0); anchorMax = new Vector2(0, 0); position = new Vector2(halfWidth, halfHeight); break; case RectAlignment.LowerRight: pivot = new Vector2(1, 0); anchorMin = new Vector2(1, 0); anchorMax = new Vector2(1, 0); position = new Vector2(-halfWidth, halfHeight); break; case RectAlignment.MiddleCenter: break; case RectAlignment.MiddleLeft: pivot = new Vector2(0, 0.5f); anchorMin = new Vector2(0, 0.5f); anchorMax = new Vector2(0, 0.5f); position = new Vector2(halfWidth, 0); break; case RectAlignment.MiddleRight: pivot = new Vector2(1, 0.5f); anchorMin = new Vector2(1, 0.5f); anchorMax = new Vector2(1, 0.5f); position = new Vector2(-halfWidth, 0); break; case RectAlignment.UpperCenter: pivot = new Vector2(0.5f, 1); anchorMin = new Vector2(0.5f, 1); anchorMax = new Vector2(0.5f, 1); position = new Vector2(0, -halfHeight); break; case RectAlignment.UpperLeft: pivot = new Vector2(0, 1); anchorMin = new Vector2(0, 1); anchorMax = new Vector2(0, 1); position = new Vector2(halfWidth, -halfHeight); break; case RectAlignment.UpperRight: pivot = new Vector2(1, 1); anchorMin = new Vector2(1, 1); anchorMax = new Vector2(1, 1); position = new Vector2(-halfWidth, -halfHeight); break; } return(new RectAlignmentStruct { Pivot = pivot, AnchorMin = anchorMin, AnchorMax = anchorMax, Position = position }); }
public DrawRect(RectAlignment alignment, int size) { m_alignment = alignment; m_size = new Size(size, size); }
internal static string smethod_70(RectAlignment A_0) { return((string)Class791.smethod_3(hashtable_59, A_0, "")); }