Example #1
0
 public override void Input()
 {
     base.Input();
     IsDragging = false;
     InBorder   = false;
     if (IsFocused)
     {
         var mousePos = (Vec2)GuiData.getMousePos();
         InBorder = IsInBorder(mousePos);
         if (!InBorder && !IsPressed && GuiData.isMouseLeftDown())
         {
             OriginalClickPosition = mousePos - Rect.Position;
             ClickPositionOffset   = OriginalClickPosition - Rect.Position;
         }
         if (IsPressed)
         {
             var movePos = new Vec2(MovedPosition);
             if (XBound != null)
             {
                 movePos.X = mousePos.X - Rect.X - OriginalClickPosition.X;
                 movePos.X = Math.Min(Math.Max(Rect.Y + movePos.X, XBound.Y), XBound.X) - Rect.X;
             }
             if (YBound != null)
             {
                 movePos.Y = mousePos.Y - Rect.Y - OriginalClickPosition.Y;
                 movePos.Y = Math.Min(Math.Max(Rect.Y + movePos.Y, YBound.Y), YBound.X) - Rect.Y;
             }
             MovedPosition = movePos;
             IsDragging    = true;
         }
         GuiData.blockingInput |= IsFocused || IsPressed;
     }
 }
Example #2
0
        public static bool doHoldDownButton(int myID, int x, int y, int width, int height, string text, bool hasOutline,
                                            Color?outlineColor, Color?selectedColor)
        {
            wasPressedDown = false;
            wasReleased    = false;
            if (!outlineColor.HasValue)
            {
                outlineColor = Color.White;
            }
            if (!selectedColor.HasValue)
            {
                selectedColor = GuiData.Default_Selected_Color;
            }
            var destinationRectangle = GuiData.tmpRect;

            destinationRectangle.X      = x;
            destinationRectangle.Y      = y;
            destinationRectangle.Width  = width;
            destinationRectangle.Height = height;
            var flag = GuiData.isMouseLeftDown() && GuiData.active == myID;

            if (destinationRectangle.Contains(GuiData.getMousePoint()))
            {
                GuiData.hot = myID;
                if (GuiData.mouseWasPressed())
                {
                    wasPressedDown = true;
                }
                if (GuiData.isMouseLeftDown())
                {
                    GuiData.active = myID;
                    flag           = true;
                }
            }
            else
            {
                if (GuiData.hot == myID)
                {
                    GuiData.hot = -1;
                }
                if (!GuiData.isMouseLeftDown() && GuiData.active == myID && GuiData.active == myID)
                {
                    GuiData.active = -1;
                }
            }
            if (GuiData.mouseLeftUp())
            {
                wasReleased = true;
            }
            GuiData.spriteBatch.Draw(Utils.white, destinationRectangle,
                                     GuiData.active == myID
                    ? selectedColor.Value
                    : (GuiData.hot == myID ? GuiData.Default_Lit_Backing_Color : GuiData.Default_Light_Backing_Color));
            if (hasOutline)
            {
                RenderedRectangle.doRectangleOutline(x, y, width, height, 2, outlineColor);
            }
            return(flag);
        }
Example #3
0
        public static bool doCheckBox(int myID, int x, int y, bool isChecked, Color?selectedColor)
        {
            if (!selectedColor.HasValue)
            {
                selectedColor = GuiData.Default_Selected_Color;
            }
            if (GuiData.hot == myID && GuiData.active == myID && GuiData.mouseLeftUp())
            {
                isChecked      = !isChecked;
                GuiData.active = -1;
            }
            RenderedRectangle.doRectangleOutline(x, y, 20, 20, 2,
                                                 GuiData.hot == myID ? GuiData.Default_Lit_Backing_Color : GuiData.Default_Light_Backing_Color);
            RenderedRectangle.doRectangle(x + 4, y + 4, 12, 12,
                                          isChecked
                    ? selectedColor
                    : (GuiData.active == myID ? GuiData.Default_Unselected_Color : GuiData.Default_Backing_Color));
            var rectangle = GuiData.tmpRect;

            rectangle.X      = x;
            rectangle.Y      = y;
            rectangle.Width  = 20;
            rectangle.Height = 20;
            if (rectangle.Contains(GuiData.getMousePoint()))
            {
                GuiData.hot = myID;
                if (GuiData.isMouseLeftDown())
                {
                    GuiData.active = myID;
                }
            }
            else
            {
                if (GuiData.hot == myID)
                {
                    GuiData.hot = -1;
                }
                if (GuiData.isMouseLeftDown() && GuiData.active == myID && GuiData.active == myID)
                {
                    GuiData.active = -1;
                }
            }
            return(isChecked);
        }
Example #4
0
        public static bool doButton(int myID, int x, int y, int width, int height, string text, Color?selectedColor,
                                    Texture2D tex)
        {
            var flag = false;

            if (GuiData.hot == myID && !GuiData.blockingInput && GuiData.active == myID &&
                (GuiData.mouseLeftUp() || GuiData.mouse.LeftButton == ButtonState.Released))
            {
                flag           = true;
                GuiData.active = -1;
            }
            var rectangle = GuiData.tmpRect;

            rectangle.X      = x;
            rectangle.Y      = y;
            rectangle.Width  = width;
            rectangle.Height = height;
            if (rectangle.Contains(GuiData.getMousePoint()) && !GuiData.blockingInput)
            {
                GuiData.hot = myID;
                if (GuiData.isMouseLeftDown() && (!DisableIfAnotherIsActive || GuiData.active == -1))
                {
                    GuiData.active = myID;
                }
            }
            else
            {
                if (GuiData.hot == myID)
                {
                    GuiData.hot = -1;
                }
                if (GuiData.isMouseLeftDown() && GuiData.active == myID && GuiData.active == myID)
                {
                    GuiData.active = -1;
                }
            }
            drawModernButton(myID, x, y, width, height, text, selectedColor, tex);
            return(flag);
        }
Example #5
0
        public static float doSliderBar(int myID, int x, int y, int width, int height, float maxValue, float minValue,
                                        float currentValue, float barStep)
        {
            var num1 = -1f;
            var val1 = currentValue;

            if (GuiData.hot == myID)
            {
                if (GuiData.isMouseLeftDown())
                {
                    GuiData.active = myID;
                }
                else if (GuiData.active == myID)
                {
                    GuiData.active = -1;
                }
                if (GuiData.active == myID)
                {
                    num1 = Math.Min(Math.Max((GuiData.mouse.X - x) / (float)width, 0.0f), 1f);
                    val1 = minValue + num1 * (maxValue - minValue);
                }
                val1 += barStep * GuiData.getMouseWheelScroll();
            }
            if (num1 == -1.0)
            {
                var num2 = maxValue - minValue;
                num1 = currentValue / num2;
                if (minValue < 0.0)
                {
                    num1 += 0.5f;
                }
            }
            GuiData.tmpRect.X      = x;
            GuiData.tmpRect.Y      = y;
            GuiData.tmpRect.Width  = width;
            GuiData.tmpRect.Height = height;
            if (GuiData.tmpRect.Contains(GuiData.getMousePoint()))
            {
                GuiData.hot = myID;
            }
            else if (GuiData.hot == myID && GuiData.mouse.LeftButton == ButtonState.Released)
            {
                GuiData.hot = -1;
                if (GuiData.active == myID)
                {
                    GuiData.active = -1;
                }
            }
            var num3 = Math.Min(Math.Max(val1, minValue), maxValue);

            GuiData.tmpRect.Width  = width;
            GuiData.tmpRect.X      = x;
            GuiData.tmpRect.Height = 10;
            GuiData.tmpRect.Y      = y + height / 4;
            GuiData.spriteBatch.Draw(Utils.white, GuiData.tmpRect, GuiData.Default_Backing_Color);
            GuiData.tmpRect.Width  -= 4;
            GuiData.tmpRect.X      += 2;
            GuiData.tmpRect.Height -= 4;
            GuiData.tmpRect.Y      += 2;
            GuiData.spriteBatch.Draw(Utils.white, GuiData.tmpRect, GuiData.Default_Dark_Background_Color);
            GuiData.tmpRect.Width  = 8;
            GuiData.tmpRect.X      = (int)(x + num1 * (double)width) - 4;
            GuiData.tmpRect.Y      = y - 5;
            GuiData.tmpRect.Height = height;
            GuiData.spriteBatch.Draw(Utils.white, GuiData.tmpRect,
                                     GuiData.active != myID
                    ? (GuiData.hot == myID ? GuiData.Default_Lit_Backing_Color : GuiData.Default_Selected_Color)
                    : GuiData.Default_Unselected_Color);
            if (GuiData.active == myID || GuiData.hot == myID)
            {
                var format = "0.000";
                var text   = num3.ToString(format) ?? "";
                text.TrimEnd('0');
                GuiData.temp.X = (int)(x + num1 * (double)width) + 4;
                GuiData.temp.Y = y - GuiData.smallfont.MeasureString(text).Y *0.8f;
                GuiData.spriteBatch.DrawString(GuiData.smallfont, text, GuiData.temp + Vector2.One, Color.Gray, 0.0f,
                                               Vector2.Zero, 0.8f, SpriteEffects.None, 0.51f);
                GuiData.spriteBatch.DrawString(GuiData.smallfont, text, GuiData.temp, Color.White, 0.0f, Vector2.Zero,
                                               0.8f, SpriteEffects.None, 0.5f);
            }
            return(num3);
        }