Exemplo n.º 1
0
        private static Vector2 DrawEntity(RenderInfo info, Vector2 topLeft, Entity entity)
        {
            Circle  circle  = entity.Shape as Circle;
            OABB    oabb    = entity.Shape as OABB;
            Polygon polygon = entity.Shape as Polygon;

            if (circle != null)
            {
                info.Canvas.StrokeCircle(entity.Position - topLeft, circle.Radius);
                info.Canvas.StrokeLine(entity.Position - topLeft, entity.Position + entity.Direction * circle.Radius - topLeft);
            }
            else if (oabb != null)
            {
                info.Canvas.StrokeRect(entity.Position - topLeft, oabb.HalfSize, entity.Orientation);
            }
            else if (polygon != null)
            {
                Vector2   pos   = entity.Position - topLeft;
                Vector2[] verts = polygon.RotatedVertices(entity.Orientation);
                info.Canvas.Begin();
                info.Canvas.MoveTo(pos + verts[verts.Length - 1]);
                for (int i = 0; i < verts.Length; i++)
                {
                    info.Canvas.LineTo(pos + verts[i]);
                }
                info.Canvas.Stroke();
            }
            return(topLeft);
        }
Exemplo n.º 2
0
 public EditBox(string name, string text, Vector2 position, OABB shape, int textLength, UIAction onChange, UIAction onExit, UIAction onEnter)
     : base(name, position, shape)
 {
     this.OnChange   = onChange;
     this.OnBlur     = onExit;
     this.OnEnter    = onEnter;
     this.Text       = text;
     this.w          = shape.HalfSize.X - 4;
     this.h          = UILayer.Font.LineSpacing * 0.5f;
     this.TextLength = textLength;
     this.keyMap     = new Konsoul.KeyMap();
 }
Exemplo n.º 3
0
        public static void DrawShape(RenderInfo info, Vector2 position, Shape shape, Color fill, Color stroke, float strokeWidth)
        {
            Circle  circle  = shape as Circle;
            OABB    oabb    = shape as OABB;
            Polygon polygon = shape as Polygon;

            info.Canvas.FillColor   = fill;
            info.Canvas.StrokeColor = stroke;
            info.Canvas.LineWidth   = strokeWidth;
            if (circle != null)
            {
                if (fill.A > 0)
                {
                    info.Canvas.FillCircle(position, circle.Radius);
                }
                if (strokeWidth > 0)
                {
                    info.Canvas.StrokeCircle(position, circle.Radius);
                }
            }
            else if (oabb != null)
            {
                if (fill.A > 0)
                {
                    info.Canvas.FillRect(position, oabb.HalfSize, 0);
                }
                if (strokeWidth > 0)
                {
                    info.Canvas.StrokeRect(position, oabb.HalfSize, 0);
                }
            }
            else if (polygon != null)
            {
                Vector2[] verts = polygon.RotatedVertices(0);
                info.Canvas.Begin();
                info.Canvas.MoveTo(position + verts[verts.Length - 1]);
                for (int i = 0; i < verts.Length; i++)
                {
                    info.Canvas.LineTo(position + verts[i]);
                }
                if (fill.A > 0)
                {
                    info.Canvas.Fill();
                }
                if (strokeWidth > 0)
                {
                    info.Canvas.Stroke();
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Creates a slider with a numbe of fixed options.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="caption"></param>
 /// <param name="position"></param>
 /// <param name="shape"></param>
 /// <param name="currentOption"></param>
 /// <param name="orientation"></param>
 /// <param name="options"></param>
 public Slider(string name, string caption, Vector2 position, OABB shape, int currentOption, UIAction onChange, SliderOrientation orientation, params string[] options)
     : base(name, position, shape)
 {
     this.minValue          = 0;
     this.maxValue          = options.Length - 1;
     this.options           = options;
     this.step              = 1;
     this.Caption           = caption;
     this.rect              = shape;
     this.sliderOrientation = orientation;
     this.snap              = true;
     currentValue           = -1;
     SetValue(currentValue);
     this.OnChange = onChange;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a value slider
 /// </summary>
 /// <param name="name"></param>
 /// <param name="caption"></param>
 /// <param name="position"></param>
 /// <param name="shape"></param>
 /// <param name="minValue"></param>
 /// <param name="maxValue"></param>
 /// <param name="currentValue"></param>
 /// <param name="step"></param>
 /// <param name="orientation"></param>
 /// <param name="snap">The value always snaps to the indicated steps</param>
 public Slider(string name, string caption, Vector2 position, OABB shape, float minValue, float maxValue, float currentValue, float step, UIAction onChange, SliderOrientation orientation, bool snap)
     : base(name, position, shape)
 {
     this.minValue          = minValue;
     this.maxValue          = maxValue;
     this.step              = step;
     this.Caption           = caption;
     this.rect              = shape;
     this.sliderOrientation = orientation;
     this.snap              = snap;
     this.currentValue      = -1;
     SetValue(currentValue);
     this.OnChange = onChange;
     OnMouseDown   = DoMouseDown;
     OnMouseUp     = DoMouseUp;
     OnMouseMove   = DoMouseMove;
 }
Exemplo n.º 6
0
        public object Visit(OABB shape, RenderInfo info)
        {
            Vector2 position = shape.Entity.Position;

            if (this.fill.A > 0)
            {
                info.Canvas.FillColor = this.fill;
                info.Canvas.FillRect(position, shape.HalfSize, shape.Entity.Orientation);
            }
            if (this.stroke.A > 0)
            {
                info.Canvas.StrokeColor = this.stroke;
                info.Canvas.LineWidth   = this.thickness;
                info.Canvas.StrokeRect(position, shape.HalfSize, shape.Entity.Orientation);
            }
            return(null);
        }
Exemplo n.º 7
0
        public InventoryContainer(string name, string caption, Vector2 position, OABB shape, int width, int height)
            : base(name, caption, position, shape)
        {
            this.Width    = Math.Max(1, width);
            this.Height   = Math.Max(1, height);
            this.Size     = shape.HalfSize * 2;
            this.SlotSize = this.Size;
            SlotSize.X   /= this.Width;
            SlotSize.Y   /= this.Height;

            Slots = new InventoryContainerItem[this.Width, this.Height];
            for (int y = 0; y < this.Height; y++)
            {
                for (int x = 0; x < this.Width; x++)
                {
                    Slots[x, y] = null;
                }
            }
        }
Exemplo n.º 8
0
        public Carousel(string name, Vector2 position, OABB shape, UIElementOrientation orientation, int visibleOptions, bool wrap, float offset, float fallOff)
            : base(name, position, shape)
        {
            this.ElementOrientation = orientation;
            this.VisibleOptions     = visibleOptions;
            this.Wrap       = wrap;
            this.fallOff    = fallOff;
            elements        = new List <UIElement>();
            selectedElement = -1;
            switch (orientation)
            {
            default:
            case UIElementOrientation.LeftRight:
                this.offset = new Vector2(offset, 0);
                break;

            case UIElementOrientation.TopDown:
                this.offset = new Vector2(0, offset);
                break;
            }
        }
Exemplo n.º 9
0
        public CarouselContainer(string name, string caption, Vector2 position, OABB shape, int capacity, UIElementOrientation orientation, int visibleOptions, bool wrap, float offset)
            : base(name, caption, position, shape)
        {
            this.ElementOrientation = orientation;
            this.Contents           = new List <ContainerItem>();
            this.Capacity           = capacity;
            this.VisibleOptions     = visibleOptions;
            this.Wrap            = wrap;
            this.selectedContent = -1;
            this.hovering        = null;

            switch (orientation)
            {
            default:
            case UIElementOrientation.LeftRight:
                this.offset = new Vector2(offset, 0);
                break;

            case UIElementOrientation.TopDown:
                this.offset = new Vector2(0, offset);
                break;
            }
        }
Exemplo n.º 10
0
 public Slider(string name, string caption, Vector2 position, OABB shape, float minValue, float maxValue, float currentValue, UIAction onChange)
     : this(name, caption, position, shape, minValue, maxValue, currentValue, (maxValue - minValue) * 0.1f, onChange, SliderOrientation.Horizontal, false)
 {
 }
Exemplo n.º 11
0
 public Slider(string name, string caption, Vector2 position, OABB shape, float minValue, float maxValue, float currentValue, float step, UIAction onChange, SliderOrientation orientation)
     : this(name, caption, position, shape, minValue, maxValue, currentValue, step, onChange, orientation, false)
 {
 }
Exemplo n.º 12
0
 public CollisionData Visit(OABB other, Circle self)
 {
     return(CollisionChecks.CirclePolygon(self, other));
 }
Exemplo n.º 13
0
 public CollisionData Visit(OABB other, Polygon self)
 {
     return(CollisionChecks.PolygonPolygon(self, other));
 }