public override void DrawAppLauncher(GraphicsContext gfx, Rectangle rect, UIButtonState state) { var font = _theme.Theme.GetFont(TextFontStyle.Highlight); var measure = font.MeasureString(_appMenuTitle); gfx.DrawString(_appMenuTitle, rect.X + ((rect.Width - (int)measure.X) / 2), rect.Y + ((rect.Height - (int)measure.Y) / 2), (state != UIButtonState.Idle) ? _theme.Theme.GetAccentColor() : _theme.Theme.GetFontColor(TextFontStyle.Highlight), font, TextAlignment.Left, rect.Width, Plex.Engine.TextRenderers.WrapMode.None); }
/** * Garbage function for testing */ public void DefaultButtonCallback(Vector2 pos, Object piss, int mouse) { if (mouse == 1) { state = UIButtonState.Pressed; } }
public override void Update(GameTime gameTime, MouseState mouseState, KeyboardState keyboardState) { if (!Enabled) { return; } if (drawArea.Contains(mouseState.Position)) { if (mouseState.LeftButton == ButtonState.Pressed) { state = UIButtonState.CLICKED; } if (mouseState.LeftButton == ButtonState.Pressed && oldState.LeftButton != ButtonState.Pressed) { OnClick?.Invoke(this, null); } else if (mouseState.LeftButton != ButtonState.Pressed) { state = UIButtonState.HOVER; } } else { state = UIButtonState.IDLE; } oldState = mouseState; }
internal void Update(float deltaTime) { if (mouseIsOverSelf()) { if (InputManager.IsMouseClicked()) { if (_signalButtonClick != null) { _signalButtonClick(this); } } else if (InputManager.IsMouseDown()) { _state = UIButtonState.PRESSED; } else { _state = UIButtonState.NORMAL; } } else { _state = UIButtonState.NORMAL; } }
/** * AIO setup function for buttons.. probably needs refactoring! */ void Setup(ButtonType _type, Vector2 _position, Vector2 _size, String _tex, Rectangle _srcRect, Point _pressedOffset, Point _cornerSize, Color _pal) { pal = _pal; type = _type; state = UIButtonState.Released; if (_type == ButtonType.Invisible) { Size = _size; position = _position; } else { Size = _size; position = _position; gfx = new UIElement[2]; if (type != ButtonType.Static) { gfx[0] = new UIRect("ui", Vector2.Zero, _size, _srcRect, _cornerSize); gfx[1] = new UIRect("ui", Vector2.Zero, _size, new Rectangle(_srcRect.X + _pressedOffset.X, _srcRect.Y + _pressedOffset.Y, _srcRect.Width, _srcRect.Height), _cornerSize); } else { gfx[0] = new UISprite(Vector2.Zero, "ui", _srcRect); gfx[1] = new UISprite(Vector2.Zero, "ui", new Rectangle(_srcRect.X + _pressedOffset.X, _srcRect.Y + _pressedOffset.Y, _srcRect.Width, _srcRect.Height)); Size = new Vector2(_srcRect.Width, _srcRect.Height); } for (int i = 0; i < gfx.Length; i++) { gfx[i].pal = pal; } AddChild(gfx[0]); AddChild(gfx[1]); } mousePressedCallback = DefaultButtonCallback; }
public override void DrawButtonBackground(GraphicsContext gfx, UIButtonState state, ButtonStyle style) { int rounding = ButtonPaddingY / 2; var color = _controlLight; switch (style) { case ButtonStyle.Danger: color = _controlDanger; break; case ButtonStyle.Primary: color = _controlPrimary; break; case ButtonStyle.Success: color = _controlSuccess; break; case ButtonStyle.Warning: color = _controlWarning; break; } if (state == UIButtonState.Hover) { color = color.Lighten(0.25F); } else if (state == UIButtonState.Pressed) { color = color.Darken(0.25F); } gfx.FillRoundedRectangle(0, 0, gfx.Width, gfx.Height, rounding, color); }
public Button(UIElement parent, Vector2 position, Vector2 size, Texture2D buttonTex, Action action, string text="") : base(parent, position) { buttonBorder = new Panel(this, Vector2.Zero, size, buttonTex); this.AddChild(buttonBorder); _action=action; _size = size; if (_font == null) _font = ContentInterface.LoadFont("font2"); Text = text; _state = UIButtonState.Nothing; }
/** * Yikes */ public UITextInput(Vector2 _position, Vector2 _size) { state = UIButtonState.Released; depth = 0.05f; Size = _size; position = _position; buttons = new UIButton[2]; buttons[1] = new UIButton(new Vector2(-8, 4), new Vector2(6, 6), Default_TextInputButton); buttons[0] = new UIButton(new Vector2(0, 0), new Vector2(_size.X, _size.Y), Default_TextInputField); label = new UILabel("", new Vector2(2, 4), FontManager.UIFont, Color.White); AddChild(buttons[1]); AddChild(buttons[0]); AddChild(label); mousePressedCallback = SetActiveTextInput; }
public override void DrawTextBoxBackground(GraphicsContext gfx, UIButtonState state) { gfx.Clear(_controlDark); var barColor = _controlLight; if (state == UIButtonState.Hover) { barColor = barColor.Lighten(0.25F); } else if (state == UIButtonState.Pressed) { barColor = _controlPrimary; } gfx.FillRectangle(0, gfx.Height - 2, gfx.Width, 2, barColor); }
/// <inheritdoc/> protected override void OnPaint(GameTime time, GraphicsContext gfx) { UIButtonState state = UIButtonState.Idle; if (HasFocused) { state = UIButtonState.Pressed; } else if (ContainsMouse) { state = UIButtonState.Hover; } Theme.DrawTextBoxBackground(gfx, state); if (state != UIButtonState.Pressed) { if (string.IsNullOrEmpty(Text)) { if (!string.IsNullOrWhiteSpace(Label)) { Theme.DrawTextBoxLabel(gfx, Label); } } } if (!string.IsNullOrWhiteSpace(Text)) { Theme.DrawTextBoxText(gfx, Text, _drawOffset); } if (HasFocused) { if (_showCaret) { Theme.DrawTextBoxCaret(gfx, _caretX - _drawOffset); } } }
void InputEvents_MouseMoved(MouseData md) { if (Visible && Enabled) { //check mouse bool mouseOver = (md.X >= PositionAndSize.Left) && (md.X <= PositionAndSize.Right) && (md.Y >= PositionAndSize.Top) && (md.Y <= PositionAndSize.Bottom); State = (mouseOver ? (md.Left ? UIButtonState.NormalPressed : UIButtonState.Hilite) : UIButtonState.Normal); } }
public override void DrawAppLauncher(GraphicsContext gfx, Rectangle rect, UIButtonState state) { gfx.DrawRectangle(rect.X, rect.Y, rect.Width, rect.Height, _appBG); }
/// <inheritdoc/> public override void DrawButton(GraphicsContext gfx, string text, Texture2D image, UIButtonState state, bool showImage, Rectangle imageRect, Rectangle textRect) { var bg = GetAccentColor().Darken(0.35F); var fg = _bStateTextIdle; switch (state) { case UIButtonState.Hover: bg = bg.Lighten(0.2F); fg = _bStateTextHover; break; case UIButtonState.Pressed: bg = bg.Darken(0.2F); fg = _bStateTextIdle; break; } gfx.Clear(bg); if (showImage) { gfx.DrawRectangle(imageRect.X, imageRect.Y, imageRect.Width, imageRect.Height, image, fg); } gfx.DrawString(text, textRect.X, textRect.Y, fg, _highlight, TextAlignment.Left, textRect.Width, Plex.Engine.TextRenderers.WrapMode.Words); }
public void InputEvents_MouseMovedLeftChangedOrLeftRepeated(MouseData md) { Handled = false; if (Visible && Enabled) { //check mouse bool mouseOver = (md.X >= PositionAndSize.Left) && (md.X <= PositionAndSize.Right) && (md.Y >= PositionAndSize.Top) && (md.Y <= PositionAndSize.Bottom); State = (mouseOver ? (md.Left ? UIButtonState.NormalPressed : UIButtonState.Hilite) : UIButtonState.Normal); Handled = mouseOver; if (State == UIButtonState.NormalPressed) Parent.Value = Parent.Value + (IsPlusButton ? 1 : -1); } }
public override void DrawArrow(GraphicsContext gfx, int x, int y, int width, int height, UIButtonState state, ArrowDirection direction) { }
public void RenderButton(UIButtonStyle style, string text, Rectangle position, UIButtonState state) { //TODO: UI Styles Rock.SpriteBatch.Draw(blank, position, (state == UIButtonState.Hovering ? DefaultHoverColor : DefaultNormalColor)); var stringSize = font.MeasureString(text); Rock.SpriteBatch.DrawString(font, text, new Vector2(position.X + position.Width / 2 - stringSize.X / 2, position.Y + position.Height / 2 - stringSize.Y / 2), DefaultTextColor); }
public void Deactivate() { State = UIButtonState.Inactive; }
public override void DrawButtonBackground(GraphicsContext gfx, UIButtonState state, ButtonStyle style) { gfx.Clear(Color.Gray); }
public void Enable() { m_State = UIButtonState.NORMAL; }
public override Color GetButtonTextColor(UIButtonState state, ButtonStyle style) { return(_buttonText); }
public void Disable() { m_State = UIButtonState.DISABLED; }
protected virtual void Update() { if(m_Toggle != null && m_Toggle.uiEnabled == false) { if(m_State != UIButtonState.DISABLED) { m_State = UIButtonState.DISABLED_TOGGLE; } } else { if(m_State != UIButtonState.DISABLED) { m_State = UIButtonState.NORMAL; } } if(m_State != UIButtonState.DISABLED && m_State != UIButtonState.DISABLED_TOGGLE) { if (m_MouseDown == true && m_MouseInBounds == true) { m_State = UIButtonState.DOWN; } else if(m_MouseInBounds == true) { m_State = UIButtonState.HOVER; } else { m_State = UIButtonState.NORMAL; } } SetTexture(); SetTextColor(); }
public override void DrawPanelButton(GraphicsContext gfx, Rectangle rect, PanelButtonState state, UIButtonState mouseState, string text) { var font = _theme.Theme.GetFont(TextFontStyle.Highlight); switch (state) { case PanelButtonState.Default: _theme.Theme.DrawControlLightBG(gfx, rect.X, rect.Y, rect.Width, rect.Height); break; case PanelButtonState.Active: _theme.Theme.DrawControlDarkBG(gfx, rect.X, rect.Y, rect.Width, rect.Height); break; case PanelButtonState.Minimized: _theme.Theme.DrawControlBG(gfx, rect.X, rect.Y, rect.Width, rect.Height); break; } var measure = font.MeasureString(text); gfx.DrawString(text, new Vector2(rect.X + 6, rect.Y + ((rect.Height - (int)measure.Y) / 2)), (mouseState == UIButtonState.Idle) ? _theme.Theme.GetFontColor(TextFontStyle.Highlight) : _theme.Theme.GetAccentColor(), font, TextAlignment.Left, rect.Width, WrapMode.None); }
public override void DrawPanelButton(GraphicsContext gfx, Rectangle rect, PanelButtonState state, UIButtonState mouseState, string text) { gfx.DrawRectangle(rect.X, rect.Y, rect.Width, rect.Height, _buttonBG); var measure = _theme.Theme.GetFont(TextFontStyle.System).MeasureString(text); gfx.DrawString(text, new Vector2(rect.X + 22, rect.Y + ((rect.Height - measure.Y) / 2)), Color.White, _theme.Theme.GetFont(TextFontStyle.System), TextAlignment.Left, rect.Width, WrapMode.None); }
public override void Update(float ms, MouseState mouse) { if (!(mouse.LeftButton == ButtonState.Pressed && _state == UIButtonState.Clicked)) { if (_state == UIButtonState.Clicked) { _action.Invoke(); } _state = UIButtonState.Nothing; if (new Rectangle((int)buttonBorder.TotalOffset.X, (int)buttonBorder.TotalOffset.Y, (int)_size.X, (int)_size.Y).Contains(mouse.X, mouse.Y)) { _state = UIButtonState.Hover; if (mouse.LeftButton == ButtonState.Pressed && _lastMouse.LeftButton == ButtonState.Released) { _state = UIButtonState.Clicked; } } } base.Update(ms,mouse); }
public void Activate() { State = UIButtonState.Active; }
public void InputEvents_MouseMovedLeftChangedOrRepeat(MouseData md) { Handled = false; if (Visible && Enabled) { //check mouse bool mouseOver = (md.X >= PositionAndSize.Left) && (md.X <= PositionAndSize.Right) && (md.Y >= PositionAndSize.Top) && (md.Y <= PositionAndSize.Bottom); UIButtonState old_State = State; State = (mouseOver ? (md.Left ? UIButtonState.NormalPressed : UIButtonState.Hilite) : UIButtonState.Normal); Handled = mouseOver; if ((State == UIButtonState.NormalPressed) && (old_State == State) && (Parent.IsVertical ? (md.Y != md.old_Y) : (md.X != md.old_X))) { int scrollSpaceSize = (Parent.IsVertical ? Parent.PositionAndSize.Height - Parent.btnMinus.PositionAndSize.Height - Parent.btnPlus.PositionAndSize.Height : Parent.PositionAndSize.Width - Parent.btnMinus.PositionAndSize.Width - Parent.btnPlus.PositionAndSize.Width); int thumbLength = (int)(scrollSpaceSize * ((Parent.ValuesOnScreen + 0.5) / (double)(Parent.MaximalValue - Parent.MinimalValue + 1))); if (thumbLength < (Parent.IsVertical ? Edges[0].Height + Edges[3].Height + 1 : Edges[1].Width + Edges[2].Width + 1)) thumbLength = (Parent.IsVertical ? Edges[0].Height + Edges[3].Height + 1 : Edges[1].Width + Edges[2].Width + 1); int scrollPositionsSize = scrollSpaceSize - thumbLength; double scrollPositionSize = scrollPositionsSize / (double)(Parent.MaximalValue - Parent.MinimalValue); Vector2 DragDistance = new Vector2(md.X - Parent.btnMinus.PositionAndSize.Right - thumbLength / 4, md.Y - Parent.btnMinus.PositionAndSize.Bottom - thumbLength / 4); Parent.Value = (int)(Parent.IsVertical ? Math.Truncate(DragDistance.Y / scrollPositionSize) : Math.Truncate(DragDistance.X / scrollPositionSize)); } } }
/// <inheritdoc/> public override void DrawStatedString(GraphicsContext graphics, string text, int x, int y, int width, int height, TextFontStyle style, UIButtonState state) { throw new NotImplementedException(); }
public abstract void DrawTextBoxBackground(GraphicsContext gfx, UIButtonState state);
public override void DrawStatedString(GraphicsContext graphics, string text, int x, int y, int width, int height, TextFontStyle style, UIButtonState state) { }
/// <inheritdoc/> public override void DrawArrow(GraphicsContext gfx, int x, int y, int width, int height, UIButtonState state, ArrowDirection direction) { var arrow = _arrowup; var cstate = _bStateTextIdle; switch (direction) { case ArrowDirection.Down: arrow = _arrowdown; break; case ArrowDirection.Up: arrow = _arrowup; break; case ArrowDirection.Right: arrow = _arrowright; break; case ArrowDirection.Left: arrow = _arrowleft; break; } switch (state) { case UIButtonState.Hover: cstate = _bStateTextHover; break; case UIButtonState.Pressed: cstate = _bStateTextPressed; break; } gfx.DrawRectangle(x, y, width, height, arrow, cstate, System.Windows.Forms.ImageLayout.Zoom); }
public override void DrawButton(GraphicsContext gfx, string text, Texture2D image, UIButtonState state, bool showImage, Rectangle imageRect, Rectangle textRect) { Color bg = Color.White; Color fg = Color.Black; switch (state) { case UIButtonState.Hover: bg = Color.Gray; fg = Color.White; break; case UIButtonState.Pressed: bg = Color.Black; fg = Color.White; break; } gfx.DrawRectangle(0, 0, gfx.Width, gfx.Height, Color.Black); gfx.DrawRectangle(2, 2, gfx.Width - 4, gfx.Height - 4, bg); if (showImage) { gfx.DrawRectangle(imageRect.X, imageRect.Y, imageRect.Width, imageRect.Height, image, fg); } gfx.DrawString(text, new Vector2(textRect.X, textRect.Y), fg, GetFont(TextFontStyle.Highlight), TextAlignment.Left, textRect.Width, WrapMode.Words); }
public override Color GetButtonTextColor(UIButtonState state, ButtonStyle style) { return(Color.White); }
private void SetState(UIButtonState newState) => state = newState;
void InputEvents_MouseLeftChanged(MouseData md) { if (Visible && Enabled) { //check mouse bool mouseOver = (md.X >= PositionAndSize.Left) && (md.X <= PositionAndSize.Right) && (md.Y >= PositionAndSize.Top) && (md.Y <= PositionAndSize.Bottom); bool mlbtnClicked = (md.Left != md.old_Left) && !md.Left; State = (mouseOver ? (md.Left ? UIButtonState.NormalPressed : UIButtonState.Hilite) : UIButtonState.Normal); if (mouseOver && mlbtnClicked && (Action != null)) Action(this); } }
/// <summary> /// set sprite order /// </summary> public void SetSpriteOrder(UIButtonState state, int spriteNum) { spriteOrder[(int)state] = spriteNum; State = UIButtonState.RELEASE; }
public override void DrawTextBoxBackground(GraphicsContext gfx, UIButtonState state) { gfx.Clear(Color.Black); gfx.FillRectangle(2, 2, gfx.Width - 4, gfx.Height - 4, Color.White); }
public abstract Color GetButtonTextColor(UIButtonState state, ButtonStyle style);
public abstract void DrawAppLauncher(GraphicsContext gfx, Rectangle rect, UIButtonState state);
public abstract void DrawButtonBackground(GraphicsContext gfx, UIButtonState state, ButtonStyle style);
public abstract void DrawPanelButton(GraphicsContext gfx, Rectangle rect, PanelButtonState state, UIButtonState mouseState, string text);