/// <summary> /// 构造函数 /// </summary> /// <param name="frame">包含滚动条的框架</param> /// <param name="scrollButton">包含按钮宽高设置的矩形</param> /// <param name="buttonColor">按钮颜色</param> /// <param name="barColor">空白颜色</param> /// <param name="type">滚动条的类型</param> /// <param name="rollingDistance">鼠标滚轮的距离</param> public Scrollbar(Frame frame, Rectangle scrollButton, Color buttonColor, Color barColor, ScrollbarType type = ScrollbarType.Vertical, int rollingDistance = 20) { baseFrame = frame; scrollbarType = type; ScrollButton = scrollButton; ButtonColor = buttonColor; BarColor = barColor; BarPos = new Vector2(); ButtonPos = new Vector2(); RollingDistance = rollingDistance; //if (type == ScrollbarType.Vertical) // BarColor = Color.Black; ButtonTexture = CreateScollbarTexture(ScrollButton.Width, ScrollButton.Height, ButtonColor); //生成滚动条按钮的材质 switch (scrollbarType) //根据不同类型重新设置框架可是范围和生成滚动条的材质 { case ScrollbarType.Horizontal: //baseFrame.VisualFrame.Height -= ScrollButton.Height; BarTexture = CreateScollbarTexture(baseFrame.VisualFrame.Width, ScrollButton.Height, BarColor); BarPos.X = baseFrame.Position.X; //将滚动条位置设置放构造函数内可以使滚动条与框架的位置分离 BarPos.Y = baseFrame.Position.Y + baseFrame.VisualFrame.Height; break; case ScrollbarType.Vertical: //baseFrame.VisualFrame.Width -= ScrollButton.Width; BarTexture = CreateScollbarTexture(ScrollButton.Width, baseFrame.VisualFrame.Height, BarColor); BarPos.X = baseFrame.Position.X + baseFrame.VisualFrame.Width; BarPos.Y = baseFrame.Position.Y; break; } DisValue = 0f;//此处必须放在BarTexture生成之后 }
public ScrollThumb(Microsoft.Xna.Framework.Game game, ScrollbarType type) : base(game) { this.type = type; renderer = new BasicScrollThumbRenderer(game, this); ParentChanged += new GuiEventHandler <GuiParentEventArgs>(ScrollThumb_Parentd); }
public ScrollBar(Microsoft.Xna.Framework.Game game, ScrollbarType type) : base(game) { this.type = type; childs = new ChildCollection(this); renderer = new BasicScrollbarRenderer(game, this); focusable = false; value = 0; thumb = new ScrollThumb(game, type); childs.AddChild(thumb); thumb.SetParent(this); }
public UITextEdit(AddTextEditNode Node, ParserState State, UIScreen Screen) : base(Screen) { Name = Node.Name; m_ID = Node.ID; m_KeyboardInput = true; //UITextEdit needs to receive input from keyboard! if (!State.InSharedPropertiesGroup) { if (Node.TextEditPosition.Numbers.Count > 0) { Position = new Vector2(Node.TextEditPosition.Numbers[0], Node.TextEditPosition.Numbers[1]) + Screen.Position; m_TextPosition = Position; } if (State.InSharedPropertiesGroup) m_Size = State.Size; else { m_Size = new Vector2(); m_Size.X = Node.Size.Numbers[0]; m_Size.Y = Node.Size.Numbers[1]; } if (Node.Tooltip != "") Tooltip = m_Screen.GetString(Node.Tooltip); Transparent = (Node.Transparent == 1) ? true : false; if (Node.Lines != null) m_NumLines = (int)Node.Lines; if (Node.Capacity != null) m_MaxChars = (int)Node.Capacity; if (Node.Alignment != null) m_Alignment = (TextEditAlignment)Node.Alignment; if (Node.FlashOnEmpty != null) m_FlashOnEmpty = (Node.FlashOnEmpty == 1) ? true : false; if (Node.FrameOnFocus != null) m_FrameOnFocus = (Node.FrameOnFocus == 1) ? true : false; if (State.InSharedPropertiesGroup) TextColor = State.Color; else TextColor = new Color(Node.Color.Numbers[0], Node.Color.Numbers[1], Node.Color.Numbers[2]); if (Node.BackColor != null) { m_BackColor = new Color(Node.Color.Numbers[0], Node.Color.Numbers[1], Node.Color.Numbers[2]); /*Image = new UIImage(FileManager.GetTexture((ulong)FileIDs.UIFileIDs.dialog_textboxbackground), m_Screen); if(Position != null) Image.Position = Position; Image.Slicer = new NineSlicer(new Vector2(0, 0), (int)Image.Texture.Width, (int)Image.Texture.Width, 15, 15, 15, 15); Image.SetSize((int)Size.X, (int)Size.Y);*/ } else { m_BackColor = new Color(57, 81, 110, 255); /*Image = new UIImage(FileManager.GetTexture((ulong)FileIDs.UIFileIDs.dialog_textboxbackground), m_Screen); if(Position != null) Image.Position = Position; Image.Slicer = new NineSlicer(new Vector2(0, 0), (int)Image.Texture.Width, Image.Texture.Height, 15, 15, 15, 15); Image.SetSize((int)Size.X, (int)Size.Y);*/ } if (Node.Mode != null) m_Mode = (Node.Mode == "kReadOnly") ? TextEditMode.ReadOnly : TextEditMode.Insert; if (Node.ScrollbarImage != string.Empty) m_ScrollbarImage = m_Screen.GetImage(Node.ScrollbarImage).Image.Texture; if (Node.ScrollbarGutter != null) m_ScrollbarWidth = (int)Node.ScrollbarGutter; if (Node.ScrollbarType != null) m_ScrollbarType = (ScrollbarType)Node.ScrollbarType; if (Node.ResizeForExactLineHeight != null) m_ResizeForExactLineHeight = (Node.ResizeForExactLineHeight == 1) ? true : false; if (Node.EnableIME != null) m_EnableInputModeEditing = (Node.EnableIME == 1) ? true : false; if (Node.CursorColor != null) m_CursorColor = new Color(Node.CursorColor.Numbers[0], Node.CursorColor.Numbers[1], Node.CursorColor.Numbers[2]); if (Node.FrameColor != null) m_FrameColor = new Color(Node.FrameColor.Numbers[0], Node.FrameColor.Numbers[1], Node.FrameColor.Numbers[2]); } else { if (State.BackColor != null) m_BackColor = State.BackColor; if (State.Color != null) TextColor = State.Color; if (State.CursorColor != null) m_CursorColor = State.CursorColor; if (State.Position != null) { Position = new Vector2(State.Position[0], State.Position[1]) + Screen.Position; m_TextPosition = Position; //Image.Position = Position; } if (State.Tooltip != "") Tooltip = State.Tooltip; } m_Lines.Add(new RenderableText() { SBuilder = new StringBuilder(), Position = m_TextPosition, Visible = true }); int Font = 0; if (Node.Font != 0) Font = Node.Font; else Font = State.Font; switch(Font) { case 9: m_Font = Screen.Font9px; break; case 10: m_Font = Screen.Font10px; break; case 12: m_Font = Screen.Font12px; break; case 14: m_Font = Screen.Font14px; break; case 16: m_Font = Screen.Font16px; break; } m_Cursor.Position = Position; m_CursorVisibilityTimer = new Timer(100); m_CursorVisibilityTimer.Enabled = true; m_CursorVisibilityTimer.Elapsed += M_CursorVisibilityTimer_Elapsed; m_CursorVisibilityTimer.Start(); m_Screen.Manager.OnTextInput += Manager_OnTextInput; }
public static uint GetScrollbarGraphicIndex(ScrollbarType scrollbarType) => UICustomGraphicOffset + (uint)scrollbarType;
public void UpdateInput(FancyInputHandler input, float elapsedSeconds, bool allowScrollWheel) { var relMouse = new Point((int)(input.MousePosition.X), (int)(input.MousePosition.Y)); if (CurrentScroll == ScrollbarType.None && input.LeftClickDown) { if (!DisableHorizontalScroll && HorizontalBox.Contains(relMouse)) { CurrentScroll = ScrollbarType.Horizontal; HorizontalBoxGrabOffset = new Point(relMouse.X - HorizontalBox.X, relMouse.Y - HorizontalBox.Y); } else if (!DisableVerticalScroll && VerticalBox.Contains(relMouse)) { CurrentScroll = ScrollbarType.Vertical; VerticalBoxGrabOffset = new Point(relMouse.X - VerticalBox.X, relMouse.Y - VerticalBox.Y); } } else if (CurrentScroll == ScrollbarType.Horizontal) { //ScrollByPixels(new Vector2(input.MousePositionDelta.X, 0)); ScrollHorizontalBarToMouse(relMouse); } else if (CurrentScroll == ScrollbarType.Vertical) { //ScrollByPixels(new Vector2(0, input.MousePositionDelta.Y)); ScrollVerticalBarToMouse(relMouse); } if (!input.LeftClickHeld) { CurrentScroll = ScrollbarType.None; } ScrollUpButtonHeld = CurrentScroll == ScrollbarType.None && !DisableVerticalScroll && input.LeftClickHeld && ScrollUpArrowBox.Contains(relMouse); ScrollDownButtonHeld = CurrentScroll == ScrollbarType.None && !DisableVerticalScroll && input.LeftClickHeld && ScrollDownArrowBox.Contains(relMouse); ScrollLeftButtonHeld = CurrentScroll == ScrollbarType.None && !DisableHorizontalScroll && input.LeftClickHeld && ScrollLeftArrowBox.Contains(relMouse); ScrollRightButtonHeld = CurrentScroll == ScrollbarType.None && !DisableHorizontalScroll && input.LeftClickHeld && ScrollRightArrowBox.Contains(relMouse); if (!DisableVerticalScroll) { if (ScrollUpButton.Update(elapsedSeconds, ScrollUpButtonHeld)) { ScrollByVirtualScrollUnits(new Vector2(0, -ScrollArrowButtonVirtualScrollAmountY)); } if (ScrollDownButton.Update(elapsedSeconds, ScrollDownButtonHeld)) { ScrollByVirtualScrollUnits(new Vector2(0, ScrollArrowButtonVirtualScrollAmountY)); } } if (!DisableHorizontalScroll) { if (ScrollLeftButton.Update(elapsedSeconds, ScrollLeftButtonHeld)) { ScrollByVirtualScrollUnits(new Vector2(-ScrollArrowButtonVirtualScrollAmountX, 0)); } if (ScrollRightButton.Update(elapsedSeconds, ScrollRightButtonHeld)) { ScrollByVirtualScrollUnits(new Vector2(ScrollArrowButtonVirtualScrollAmountX, 0)); } } var scrollWheel = allowScrollWheel ? input.ScrollDelta : 0; if (scrollWheel != 0) { if (input.KeyHeld(Microsoft.Xna.Framework.Input.Keys.LeftShift) || input.KeyHeld(Microsoft.Xna.Framework.Input.Keys.RightShift)) { if (!DisableHorizontalScroll) { ScrollByVirtualScrollUnits(new Vector2(-scrollWheel * ScrollWheelVirtualScrollAmountX, 0)); } } else { if (!DisableVerticalScroll) { ScrollByVirtualScrollUnits(new Vector2(0, -scrollWheel * ScrollWheelVirtualScrollAmountY)); } } } }
/// <summary> /// Constructs a new UITextEdit control from a parsed UIScript. /// </summary> /// <param name="Node">The AddTextEditNode that defines this UITextEdit control.</param> /// <param name="State">The ParserState returned when parsing the UIScript.</param> /// <param name="Screen">A UIScreen instance.</param> public UITextEdit2(AddTextEditNode Node, ParserState State, UIScreen Screen) : base(Screen) { Name = Node.Name; m_ID = Node.ID; m_KeyboardInput = true; //UITextEdit needs to receive input from keyboard! if (!State.InSharedPropertiesGroup) { if (Node.TextEditPosition.Numbers.Count > 0) { Position = new Vector2(Node.TextEditPosition.Numbers[0], Node.TextEditPosition.Numbers[1]) + Screen.Position; m_TextPosition = Position; } if (State.InSharedPropertiesGroup) { m_Size = State.Size; } else { m_Size = new Vector2(); m_Size.X = Node.Size.Numbers[0]; m_Size.Y = Node.Size.Numbers[1]; } if (Node.Tooltip != "") { Tooltip = m_Screen.GetString(Node.Tooltip); } Transparent = (Node.Transparent == 1) ? true : false; if (Node.Lines != null) { m_NumLines = (int)Node.Lines; } if (Node.Capacity != null) { m_MaxChars = (int)Node.Capacity; } if (Node.Alignment != null) { m_Alignment = (TextEditAlignment)Node.Alignment; } if (Node.FlashOnEmpty != null) { m_FlashOnEmpty = (Node.FlashOnEmpty == 1) ? true : false; } if (Node.FrameOnFocus != null) { m_FrameOnFocus = (Node.FrameOnFocus == 1) ? true : false; } if (State.InSharedPropertiesGroup) { TextColor = State.Color; } else { TextColor = new Color(Node.Color.Numbers[0], Node.Color.Numbers[1], Node.Color.Numbers[2]); } if (Node.BackColor != null) { m_BackColor = new Color(Node.Color.Numbers[0], Node.Color.Numbers[1], Node.Color.Numbers[2]); } else { m_BackColor = new Color(57, 81, 110, 255); } if (Node.Mode != null) { m_Mode = (Node.Mode == "kReadOnly") ? TextEditMode.ReadOnly : TextEditMode.Insert; } if (Node.ScrollbarImage != string.Empty) { m_ScrollbarImage = m_Screen.GetImage(Node.ScrollbarImage).Image.Texture; } if (Node.ScrollbarGutter != null) { m_ScrollbarWidth = (int)Node.ScrollbarGutter; } if (Node.ScrollbarType != null) { m_ScrollbarType = (ScrollbarType)Node.ScrollbarType; } if (Node.ResizeForExactLineHeight != null) { m_ResizeForExactLineHeight = (Node.ResizeForExactLineHeight == 1) ? true : false; } if (Node.EnableIME != null) { m_EnableInputModeEditing = (Node.EnableIME == 1) ? true : false; } if (Node.CursorColor != null) { m_CursorColor = new Color(Node.CursorColor.Numbers[0], Node.CursorColor.Numbers[1], Node.CursorColor.Numbers[2]); } if (Node.FrameColor != null) { m_FrameColor = new Color(Node.FrameColor.Numbers[0], Node.FrameColor.Numbers[1], Node.FrameColor.Numbers[2]); } } else { if (State.BackColor != null) { m_BackColor = State.BackColor; } if (State.Color != null) { TextColor = State.Color; } if (State.CursorColor != null) { m_CursorColor = State.CursorColor; } if (State.Position != null) { Position = new Vector2(State.Position[0], State.Position[1]) + Screen.Position; m_TextPosition = Position; } if (State.Tooltip != "") { Tooltip = State.Tooltip; } } int Font = 0; if (Node.Font != 0) { Font = Node.Font; } else { Font = State.Font; } switch (Font) { case 9: m_Font = Screen.Font9px; break; case 10: m_Font = Screen.Font10px; break; case 12: m_Font = Screen.Font12px; break; case 14: m_Font = Screen.Font14px; break; case 16: m_Font = Screen.Font16px; break; } m_Renderer = new TextRenderer((m_NumLines > 1) ? true : false, Position, Size, m_ScrollFactor, Lineheight, m_Font, TextColor, m_NumLines); m_Cursor.Position = Position; m_CursorVisibilityTimer = new Timer(100); m_CursorVisibilityTimer.Enabled = true; m_CursorVisibilityTimer.Elapsed += M_CursorVisibilityTimer_Elapsed; m_CursorVisibilityTimer.Start(); m_Screen.Manager.OnTextInput += Manager_OnTextInput; }
/// <summary> /// 构造函数 /// </summary> /// <param name="frame">包含滚动条的框架</param> /// <param name="type">滚动条的类型</param> public Scrollbar(Frame frame, ScrollbarType type = ScrollbarType.Vertical) : this(frame, type == ScrollbarType.Vertical ? new Rectangle(0, 0, 13, 28) : new Rectangle(0, 0, 25, 13), Color.DeepSkyBlue, Color.DimGray, type) { }