示例#1
0
        public void SpriteGUI(SpriteHandle handle)
        {
            var sprite = Sprites.GetSprite(handle.SpriteDef);

            sprite.Color    = handle.Color;
            sprite.Position = handle.Position;
            sprite.Origin   = handle.Origin;
            sprite.Rotation = handle.Rotation;
            sprite.Scale    = handle.Scale;
            sprite.Draw(_win, RenderStates.Default);
        }
 public void DrawSpriteAt(SpriteHandle sprite, Vec2 shapeSize, Vec2 pivot, Vec2?scale = null)
 {
     sprite.Position = _transform.TransformPoint(shapeSize.X * pivot.X, shapeSize.Y * pivot.Y);
     sprite.Rotation = GlobalRot - 180;
     sprite.Origin   = new Vector2f(sprite.TextureRect.X / 2, sprite.TextureRect.Y / 2);
     if (scale.HasValue)
     {
         sprite.Scale = new Vector2f(shapeSize.X / sprite.TextureRect.X * scale.Value.X, shapeSize.Y / sprite.TextureRect.Y * scale.Value.Y);
     }
     else
     {
         sprite.Scale = new Vector2f(shapeSize.X / sprite.TextureRect.X, shapeSize.Y / sprite.TextureRect.Y);
     }
     EnvironmentAPI.Draw.Sprite(sprite);
 }
示例#3
0
 public static bool SlotButton(Vector2f position, Vector2f size, SpriteHandle sprite)
 {
     /*_index++;
      *
      * if (_hotControl == _index)
      *  sprite.Color = new Color(100, 100, 100, 255);
      * else
      *  sprite.Color = new Color(140, 140, 140, 255);
      *
      * if (!GUI.IsActive)
      *  sprite.Color = new Color(200, 100, 100, 255);
      * sprite.Scale = new Vector2f(size.X / sprite.TextureRect.X, size.Y / sprite.TextureRect.Y);
      * sprite.Origin = new Vector2f(sprite.TextureRect.X / 2, sprite.TextureRect.Y / 2);
      * sprite.Position = position;
      * EnvironmentAPI.Draw.SpriteGUI(sprite);
      *
      * if (GUI.IsActive)
      * {
      *  if (!Mouse.IsButtonPressed(Mouse.Button.Left) && _pressed)
      *  {
      *      var hc = _hotControl;
      *      if (_index == hc)
      *      {
      *          _pressed = false;
      *          _hotControl = -1;
      *          if (new FloatRect(sprite.Position - sprite.Origin * sprite.Scale.X, size).Contains(Mouse.GetPosition(Win).X, Mouse.GetPosition(Win).Y))
      *          {
      *              return true;
      *          }
      *      }
      *  }
      *  if (Mouse.IsButtonPressed(Mouse.Button.Left))
      *  {
      *      _pressed = true;
      *      if (new FloatRect(sprite.Position - sprite.Origin * sprite.Scale.X, size).Contains(Mouse.GetPosition(Win).X, Mouse.GetPosition(Win).Y))
      *      {
      *          _hotControl = _index;
      *      }
      *  }
      * }
      * return false;*/
     return(EnvironmentAPI.Imgui.Button(position, size, $"{sprite.SpriteDef.____GetDebugShortName()}", sprite, false));
 }
示例#4
0
 public static bool Button(Vector2f position, Vector2f size, string text, SpriteHandle sprite, bool scaleToFit = false)
 {
     /*_index++;
      * if (_buttonText == null)
      * {
      *  _buttonText = new Text();
      *  _buttonText.Font = Font;
      *  _buttonShape = new RectangleShape();
      *  _buttonShape.FillColor = new Color(140, 140, 140, 255);
      * }
      *
      * if (_hotControl == _index)
      *  _buttonShape.FillColor = new Color(100, 100, 100, 255);
      * else
      *  _buttonShape.FillColor = new Color(140, 140, 140, 255);
      *
      * if (!GUI.IsActive)
      *  _buttonShape.FillColor = new Color(200, 100, 100, 255);
      * _buttonText.DisplayedString = text;
      * _buttonText.Position = position;
      * _buttonShape.Position = position;
      * _buttonShape.Size = size;
      * _buttonShape.Draw(Win, RenderStates.Default);
      * if (sprite.SpriteDef != null)
      * {
      *  if (scaleToFit)
      *      sprite.Scale = new Vector2f(size.X / sprite.TextureRect.X, size.Y / sprite.TextureRect.Y);
      *  else
      *      sprite.Scale = new Vector2f(1, 1);
      *  sprite.Origin = new Vector2f(sprite.TextureRect.X / 2, sprite.TextureRect.Y / 2);
      *  sprite.Position = position;
      *  EnvironmentAPI.Draw.SpriteGUI(sprite);
      * }
      * _buttonText.Draw(Win, RenderStates.Default);
      *
      * if (GUI.IsActive)
      * {
      *  if (!EnvironmentAPI.Input.IsButtonPressed(Mouse.Button.Left) && _pressed)
      *  {
      *      var hc = _hotControl;
      *      if (_index == hc)
      *      {
      *          _pressed = false;
      *          _hotControl = -1;
      *          if (new FloatRect(_buttonShape.Position, _buttonShape.Size).Contains(Mouse.GetPosition(Win).X, Mouse.GetPosition(Win).Y))
      *          {
      *              return true;
      *          }
      *      }
      *  }
      *  if (EnvironmentAPI.Input.IsButtonPressed(Mouse.Button.Left))
      *  {
      *      _pressed = true;
      *      if (new FloatRect(_buttonShape.Position, _buttonShape.Size).Contains(Mouse.GetPosition(Win).X, Mouse.GetPosition(Win).Y))
      *      {
      *          _hotControl = _index;
      *      }
      *  }
      * }
      * return false;*/
     return(EnvironmentAPI.Imgui.Button(position, size, text, sprite, scaleToFit));
 }
示例#5
0
 public static bool SlotButton(Vector2f position, SpriteHandle sprite)
 {
     return(SlotButton(position, new Vector2f(sprite.TextureRect.X, sprite.TextureRect.Y), sprite));
 }
示例#6
0
 public static bool Button(Vector2f position, string text, SpriteHandle sprite = default)
 {
     return(Button(position, new Vector2f(text.Length * 20, 40), text, sprite, false));
 }
示例#7
0
 public static bool Button(Vector2f position, SpriteHandle sprite, string text = null)
 {
     return(Button(position, new Vector2f(sprite.TextureRect.X, sprite.TextureRect.Y), text, sprite));
 }