public GUITextBox(Rectangle rect, Color?color, Color?textColor, Alignment alignment, Alignment textAlignment = Alignment.CenterLeft, string style = null, GUIComponent parent = null) : base(style) { Enabled = true; this.rect = rect; if (color != null) { this.color = (Color)color; } this.alignment = alignment; if (parent != null) { parent.AddChild(this); } textBlock = new GUITextBlock(new Rectangle(0, 0, 0, 0), "", color, textColor, textAlignment, style, this); Font = GUI.Font; GUI.Style.Apply(textBlock, style == "" ? "GUITextBox" : style); textBlock.Padding = new Vector4(3.0f, 0.0f, 3.0f, 0.0f); CaretEnabled = true; }
public GUIScrollBar(Rectangle rect, Color?color, float barSize, Alignment alignment, string style = "", GUIComponent parent = null) : base(style) { this.rect = rect; //GetDimensions(parent); this.alignment = alignment; if (parent != null) { parent.AddChild(this); } isHorizontal = (rect.Width > rect.Height); frame = new GUIFrame(new Rectangle(0, 0, 0, 0), style, this); GUI.Style.Apply(frame, isHorizontal ? "GUIFrameHorizontal" : "GUIFrameVertical", this); this.barSize = barSize; bar = new GUIButton(new Rectangle(0, 0, 0, 0), "", color, "", this); GUI.Style.Apply(bar, isHorizontal ? "GUIButtonHorizontal" : "GUIButtoneVertical", this); bar.OnPressed = SelectBar; enabled = true; UpdateRect(); }
public GUITextBlock(Rectangle rect, string text, string style, Alignment alignment = Alignment.TopLeft, Alignment textAlignment = Alignment.TopLeft, GUIComponent parent = null, bool wrap = false, ScalableFont font = null) : base(style) { this.Font = font == null ? GUI.Font : font; this.rect = rect; this.text = text; this.alignment = alignment; this.padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); this.textAlignment = textAlignment; if (parent != null) { parent.AddChild(this); } this.Wrap = wrap; SetTextPos(); TextScale = 1.0f; if (rect.Height == 0 && !string.IsNullOrEmpty(Text)) { this.rect.Height = (int)Font.MeasureString(wrappedText).Y; } }
public GUINumberInput(Rectangle rect, string style, Alignment alignment, int?minValue = null, int?maxValue = null, GUIComponent parent = null) : base(style) { this.rect = rect; this.alignment = alignment; if (parent != null) { parent.AddChild(this); } textBox = new GUITextBox(Rectangle.Empty, style, this); textBox.OnTextChanged += TextChanged; plusButton = new GUIButton(new Rectangle(0, 0, 15, rect.Height / 2), "+", null, Alignment.TopRight, Alignment.Center, style, this); plusButton.OnClicked += ChangeValue; minusButton = new GUIButton(new Rectangle(0, 0, 15, rect.Height / 2), "-", null, Alignment.BottomRight, Alignment.Center, style, this); minusButton.OnClicked += ChangeValue; MinValue = minValue; MaxValue = maxValue; value = int.MaxValue; Value = minValue != null ? (int)minValue : 0; }
public GUIImage(Rectangle rect, Rectangle sourceRect, Sprite sprite, Alignment alignment, GUIComponent parent = null) : base(null) { this.rect = rect; this.alignment = alignment; color = Color.White; //alpha = 1.0f; Scale = 1.0f; this.sprite = sprite; if (rect.Width == 0) { this.rect.Width = (int)sprite.size.X; } if (rect.Height == 0) { this.rect.Height = (int)Math.Min(sprite.size.Y, sprite.size.Y * (this.rect.Width / sprite.size.X)); } this.sourceRect = sourceRect; if (parent != null) { parent.AddChild(this); } this.parent = parent; }
public GUIButton(Rectangle rect, string text, Color?color, Alignment alignment, Alignment textAlignment, string style = "", GUIComponent parent = null) : base(style) { this.rect = rect; if (color != null) { this.color = (Color)color; } this.alignment = alignment; if (parent != null) { parent.AddChild(this); } frame = new GUIFrame(Rectangle.Empty, style, this); GUI.Style.Apply(frame, style == "" ? "GUIButton" : style); textBlock = new GUITextBlock(Rectangle.Empty, text, Color.Transparent, (this.style == null) ? Color.Black : this.style.textColor, textAlignment, null, this); GUI.Style.Apply(textBlock, style, this); Enabled = true; }
public GUINumberInput(Rectangle rect, string style, NumberType inputType, Alignment alignment, GUIComponent parent = null) : base(style) { this.rect = rect; this.alignment = alignment; if (parent != null) { parent.AddChild(this); } textBox = new GUITextBox(Rectangle.Empty, style, this); textBox.OnTextChanged += TextChanged; plusButton = new GUIButton(new Rectangle(0, 0, 15, rect.Height / 2), "+", null, Alignment.TopRight, Alignment.Center, style, this); plusButton.OnClicked += ChangeIntValue; plusButton.Visible = inputType == NumberType.Int; minusButton = new GUIButton(new Rectangle(0, 0, 15, rect.Height / 2), "-", null, Alignment.BottomRight, Alignment.Center, style, this); minusButton.OnClicked += ChangeIntValue; minusButton.Visible = inputType == NumberType.Int; if (inputType == NumberType.Int) { textBox.Text = "0"; textBox.OnEnterPressed += (txtBox, txt) => { textBox.Text = IntValue.ToString(); textBox.Deselect(); return(true); }; textBox.OnDeselected += (txtBox, key) => { textBox.Text = IntValue.ToString(); }; } else if (inputType == NumberType.Float) { textBox.Text = "0.0"; textBox.OnDeselected += (txtBox, key) => { textBox.Text = FloatValue.ToString("G", CultureInfo.InvariantCulture); }; textBox.OnEnterPressed += (txtBox, txt) => { textBox.Text = FloatValue.ToString("G", CultureInfo.InvariantCulture); textBox.Deselect(); return(true); }; } InputType = inputType; }
public GUIListBox(Rectangle rect, Color?color, Alignment alignment, string style = null, GUIComponent parent = null, bool isHorizontal = false) : base(style) { this.rect = rect; this.alignment = alignment; selected = new List <GUIComponent>(); if (color != null) { this.color = (Color)color; } if (parent != null) { parent.AddChild(this); } scrollBarHidden = true; if (isHorizontal) { scrollBar = new GUIScrollBar( new Rectangle(this.rect.X, this.rect.Bottom - 20, this.rect.Width, 20), null, 1.0f, ""); } else { scrollBar = new GUIScrollBar( new Rectangle(this.rect.Right - 20, this.rect.Y, 20, this.rect.Height), null, 1.0f, ""); } scrollBar.IsHorizontal = isHorizontal; frame = new GUIFrame(new Rectangle(0, 0, this.rect.Width, this.rect.Height), style, this); if (style != null) { GUI.Style.Apply(frame, style, this); } UpdateScrollBarSize(); children.Clear(); enabled = true; scrollBarEnabled = true; scrollBar.BarScroll = 0.0f; }
public GUIDropDown(Rectangle rect, string text, string style, GUIComponent parent = null) : base(style) { this.rect = rect; if (parent != null) parent.AddChild(this); button = new GUIButton(this.rect, text, Color.White, Alignment.TopLeft, Alignment.CenterLeft, "GUIDropDown", null); GUI.Style.Apply(button, style, this); button.OnClicked = OnClicked; listBox = new GUIListBox(new Rectangle(this.rect.X, this.rect.Bottom, this.rect.Width, 200), style, null); listBox.OnSelected = SelectItem; }
public GUIImageButton(Rectangle rect, Rectangle sourceRect, Sprite sprite, Alignment alignment, GUIComponent parent = null) : base(null) { this.rect = rect; this.alignment = alignment; color = Color.White; //alpha = 1.0f; Scale = 1.0f; this.sprite = sprite; if (rect.Width == 0) { this.rect.Width = (int)sprite.size.X; } if (rect.Height == 0) { this.rect.Height = (int)Math.Min(sprite.size.Y, sprite.size.Y * (this.rect.Width / sprite.size.X)); } this.sourceRect = sourceRect; if (parent != null) { parent.AddChild(this); } this.parent = parent; //frame = new GUIFrame(Rectangle.Empty, style, this); //GUI.Style.Apply(frame, style == "" ? "GUIButton" : style); textBlock = new GUITextBlock(Rectangle.Empty, "", Color.Transparent, (this.style == null) ? Color.Black : this.style.textColor, Alignment.CenterLeft, null, this); //GUI.Style.Apply(textBlock, style, this); Enabled = true; }
public GUITickBox(Rectangle rect, string label, Alignment alignment, ScalableFont font, GUIComponent parent) : base(null) { if (parent != null) { parent.AddChild(this); } box = new GUIFrame(rect, Color.DarkGray, "", this); box.HoverColor = Color.Gray; box.SelectedColor = Color.DarkGray; box.CanBeFocused = false; GUI.Style.Apply(box, "GUITickBox"); text = new GUITextBlock(new Rectangle(rect.Right, rect.Y, 20, rect.Height), label, "", Alignment.TopLeft, Alignment.Left | Alignment.CenterY, this, false, font); GUI.Style.Apply(text, "GUIButtonHorizontal", this); this.rect = new Rectangle(box.Rect.X, box.Rect.Y, 240, rect.Height); Enabled = true; }
public GUIFrame(Rectangle rect, Color?color, Alignment alignment, string style = "", GUIComponent parent = null) : base(style) { this.rect = rect; this.alignment = alignment; if (color != null) { this.color = (Color)color; } if (parent != null) { parent.AddChild(this); } else { UpdateDimensions(); } //if (style != null) ApplyStyle(style); }
public GUIProgressBar(Rectangle rect, Color color, string style, float barSize, Alignment alignment, GUIComponent parent = null) : base(style) { this.rect = rect; this.color = color; isHorizontal = (rect.Width > rect.Height); this.alignment = alignment; if (parent != null) { parent.AddChild(this); } frame = new GUIFrame(new Rectangle(0, 0, 0, 0), null, this); GUI.Style.Apply(frame, "", this); slider = new GUIFrame(new Rectangle(0, 0, 0, 0), null); GUI.Style.Apply(slider, "Slider", this); this.barSize = barSize; UpdateRect(); }
//private GUIComponent editingHUD; public SerializableEntityEditor(ISerializableEntity entity, bool inGame, GUIComponent parent, bool showName) : base("") { List <SerializableProperty> editableProperties = inGame ? SerializableProperty.GetProperties <InGameEditable>(entity) : SerializableProperty.GetProperties <Editable>(entity); if (parent != null) { parent.AddChild(this); } if (showName) { new GUITextBlock(new Rectangle(0, 0, 100, 20), entity.Name, "", Alignment.TopLeft, Alignment.TopLeft, this, false, GUI.Font); } int y = showName ? 30 : 10, padding = 10; foreach (var property in editableProperties) { //int boxHeight = 18; //var editable = property.Attributes.OfType<Editable>().FirstOrDefault(); //if (editable != null) boxHeight = (int)(Math.Ceiling(editable.MaxLength / 40.0f) * 18.0f); object value = property.GetValue(); GUIComponent propertyField = null; if (value is bool) { propertyField = CreateBoolField(entity, property, (bool)value, y, this); } else if (value.GetType().IsEnum) { propertyField = CreateEnumField(entity, property, value, y, this); } else if (value is string) { propertyField = CreateStringField(entity, property, (string)value, y, this); } else if (value is int) { propertyField = CreateIntField(entity, property, (int)value, y, this); } else if (value is float) { propertyField = CreateFloatField(entity, property, (float)value, y, this); } else if (value is Vector2) { propertyField = CreateVector2Field(entity, property, (Vector2)value, y, this); } else if (value is Vector3) { propertyField = CreateVector3Field(entity, property, (Vector3)value, y, this); } else if (value is Vector4) { propertyField = CreateVector4Field(entity, property, (Vector4)value, y, this); } else if (value is Color) { propertyField = CreateColorField(entity, property, (Color)value, y, this); } else if (value is Rectangle) { propertyField = CreateRectangleField(entity, property, (Rectangle)value, y, this); } if (propertyField != null) { y += propertyField.Rect.Height + padding; } } if (children.Count > 0) { SetDimensions(new Point(Rect.Width, children.Last().Rect.Bottom - Rect.Y + 10), false); } else { SetDimensions(new Point(Rect.Width, 0), false); } if (parent is GUIListBox) { ((GUIListBox)parent).UpdateScrollBarSize(); } }