private static TransformedColouredTexturedVertex MakeVertex(Vector2 position, Vector2 textureCoordinate)
 {
     return new TransformedColouredTexturedVertex(
         position.AsVector4(),
         textureCoordinate,
         new Color4(1.0f, 1.0f, 1.0f, 1.0f));
 }
 public TransformedColouredTexturedVertex(Vector4 position, Vector2 textureCoordinate, Color4 colour)
     : this()
 {
     Colour = colour;
     Position = position;
     TextureCoordinate = textureCoordinate;
 }
        public void Rectangle(Vector2 topLeft, Vector2 bottomRight, Color4 backgroundColour, Color4 borderColour, bool border = true)
        {
            var dataStream = _primitiveRenderer.LockVertexBuffer();

            var primitiveCount = 0;

            var tl = topLeft + _offset;
            var br = bottomRight + _offset;

            if (border)
            {
                WriteRectangle(
                    new Rectangle { TopLeft = tl, BottomRight = br },
                    borderColour,
                    dataStream);
                primitiveCount = 2;

                tl = tl + new Vector2(Dimensions.WidgetBorder, Dimensions.WidgetBorder);
                br = br + new Vector2(-Dimensions.WidgetBorder, -Dimensions.WidgetBorder);
            }

            WriteRectangle(
                new Rectangle { TopLeft = tl, BottomRight = br },
                backgroundColour,
                dataStream);
            primitiveCount += 2;

            _primitiveRenderer.UnlockVertexBuffer();

            _primitiveRenderer.Render(PrimitiveType.TriangleList, 0, primitiveCount);
        }
Exemple #4
0
        public void Image(string imageName, 
            Vector2? size = null, Vector2? topLeft = null, 
            float horizontalCrop = 1.0f, float verticalCrop = 1.0f, 
            Vector2 margin = new Vector2(), float alpha = 1f, float intensity = 1f)
        {
            if (topLeft == null)
            {
                topLeft = new Vector2();
            }

            var texture = _graphicsContext.GetTexture(imageName).TextureArea;

            if (size == null)
            {
                size = texture.Size;
            }

            var dataStream = _textureRenderer.LockVertexBuffer();

            var rect = new Rectangle(margin, size.Value - margin).Translate(_offset + topLeft.Value);

            WriteCroppedQuad(texture, rect, dataStream, horizontalCrop, verticalCrop);

            _textureRenderer.UnlockVertexBuffer();
            _textureRenderer.Render(PrimitiveType.TriangleList, 0, 2, texture, alpha, intensity);
        }
 public ColouredTexturedVertexNormal4(Vector4 position, Color4 colour, Vector3 normal, Vector2 texture)
     : this()
 {
     Position = position;
     Colour = colour;
     Normal = normal;
     Texture = texture;
 }
Exemple #6
0
 internal override void IntMouseMove(Vector2 position)
 {
     base.IntMouseMove(position);
     if (IsMouseDown)
     {
         UpdateValue(position);
     }
 }
Exemple #7
0
        private void UpdateValue(Vector2 position)
        {
            var positionScale = (position.X - SliderMargin) / (Size.X - (SliderMargin * 2));
            positionScale = positionScale.Clamp(0.0f, 1.0f);

            Value = (int)(MinimumValue + ((MaximumValue - MinimumValue) * positionScale));
            OnChange();
        }
 private TextureAtlasTextureDefinition(int id, string name, Vector2 topLeft, Vector2 bottomRight, int width, int height)
 {
     Id = id;
     Name = name;
     TopLeft = topLeft;
     BottomRight = bottomRight;
     Width = width;
     Height = height;
 }
Exemple #9
0
        internal override void IntMouseClick(Vector2 position, MouseButton button)
        {
            base.IntMouseClick(position, button);

            if (button == MouseButton.Left)
            {
                Value = !Value;
                OnChange();
            }
        }
Exemple #10
0
        public void Rectangle(Vector2 topLeft, Vector2 bottomRight, Color4 borderColour)
        {
            // todo: optimize this

            var topRight = new Vector2(bottomRight.X, topLeft.Y);
            var bottomLeft = new Vector2(topLeft.X, bottomRight.Y);

            Line(topLeft, topRight, borderColour);
            Line(topLeft, bottomLeft, borderColour);
            Line(topRight, bottomRight, borderColour);
            Line(bottomLeft, bottomRight, borderColour);
        }
Exemple #11
0
        internal override void IntMouseClick(Vector2 position, MouseButton button)
        {
            base.IntMouseClick(position, button);

            if (_selectionWindow.Visible)
            {
                _selectionWindow.Hide();
            }
            else
            {
                _selectionWindow.Show();
            }
        }
        /// <summary>
        /// Normalize the pixels coordinates to the range of 0.0-1.0
        /// by specifying the dimensions of a texture
        /// </summary>
        /// <param name="width">Width of texture in pixels</param>
        /// <param name="height">Height of texture in pixels</param>
        public void NormalizeTextureCoordinates(int width, int height)
        {
            TopLeft = new Vector2
                          {
                              X = TopLeft.X / width,
                              Y = TopLeft.Y / height
                          };

            BottomRight = new Vector2
                              {
                                  X = BottomRight.X / width,
                                  Y = BottomRight.Y / height
                              };
        }
Exemple #13
0
        protected override void Render(IGuiRenderer guiRenderer)
        {
            base.Render(guiRenderer);
            var positionScale = Value/(float)(MaximumValue - MinimumValue);

            guiRenderer.NinePatch(Size, _ninePatchHandle, "guiskin_down.png");

            var railSize = new Vector2(Size.X - (SliderMargin * 2), 4);
            guiRenderer.Image("slider_rail", railSize, new Vector2(SliderMargin, Size.Y / 2));

            var x = (int)((positionScale * (Size.X - (SliderMargin * 2)))) - (SliderWidth / 2);
            var y = (Size.Y / 2) - (SliderHeight / 2);
            guiRenderer.Image("slider", null, new Vector2(x + SliderMargin, y));
        }
Exemple #14
0
        public void Line(Vector2 startPosition, Vector2 endPosition, Color4 start, Color4 end)
        {
            var dataStream = _primitiveRenderer.LockVertexBuffer();

            var startPositionTranslated = startPosition + _offset;
            var endPositionTranslated = endPosition + _offset;

            dataStream.Write(new TransformedColouredVertex(new Vector4(startPositionTranslated, 1.0f, 1.0f), start));
            dataStream.Write(new TransformedColouredVertex(new Vector4(endPositionTranslated, 1.0f, 1.0f), end));

            _primitiveRenderer.UnlockVertexBuffer();

            _primitiveRenderer.Render(PrimitiveType.LineList, 0, 2);
        }
Exemple #15
0
        public void NinePatch(Vector2 size, NinePatchHandle ninePatchHandle, 
            string overrideTexture = null, float alpha = 1.0f)
        {
            var textures = new TexturePatch
            {
                T = _graphicsContext.GetTexture(ninePatchHandle.Top).TextureArea,
                TR = _graphicsContext.GetTexture(ninePatchHandle.TopRight).TextureArea,
                TL = _graphicsContext.GetTexture(ninePatchHandle.TopLeft).TextureArea,
                BL = _graphicsContext.GetTexture(ninePatchHandle.BottomLeft).TextureArea,
                BR = _graphicsContext.GetTexture(ninePatchHandle.BottomRight).TextureArea,
                B = _graphicsContext.GetTexture(ninePatchHandle.Bottom).TextureArea,
                L = _graphicsContext.GetTexture(ninePatchHandle.Left).TextureArea,
                C = _graphicsContext.GetTexture(ninePatchHandle.Centre).TextureArea,
                R = _graphicsContext.GetTexture(ninePatchHandle.Right).TextureArea
            };

            PerformUpdate(size, textures, overrideTexture, alpha);
        }
Exemple #16
0
 public MouseEventArguments(Vector2 position, MouseButton button)
 {
     Position = position;
     Button = button;
 }
Exemple #17
0
 internal override void IntMouseDown(Vector2 position, MouseButton button)
 {
     base.IntMouseDown(position, button);
     Core.Logging.Logger.Write(string.Format("Desktop down {0}", position));
 }
Exemple #18
0
        internal override void IntMouseClick(Vector2 position, MouseButton button)
        {
            base.IntMouseClick(position, button);
            var rowIndex = GetRowIndex(position);

            if (rowIndex != _selectedRowIndex && rowIndex != -1)
            {
                OnRowSelected(rowIndex);
            }
            _selectedRowIndex = rowIndex;
        }
Exemple #19
0
 public CachedTexture(int textureId, Vector2 topLeft, Vector2 bottomRight, int width, int height)
     : base(textureId, topLeft, bottomRight, width, height)
 {
 }
Exemple #20
0
 internal GuiWindow(GuiManager guiManager, Widget parent)
     : base(guiManager, parent)
 {
     Margin = new Vector2(5, 5);
     _ninePatchHandle = NinePatchHandle.Create("button");
 }
Exemple #21
0
 /// <summary>
 /// Renders a Rectangle from the top-left of the control (Position) to the bottom right (bottomRight)
 /// </summary>
 /// <param name="bottomRight"></param>
 /// <param name="backgroundColour"></param>
 /// <param name="borderColour"></param>
 /// <param name="border"></param>
 public void Rectangle(Vector2 bottomRight, Color4 backgroundColour, Color4 borderColour, bool border = true)
 {
     Rectangle(new Vector2(), bottomRight, backgroundColour, borderColour, border);
 }
Exemple #22
0
            internal override void IntMouseDown(Vector2 position, MouseButton button)
            {
                base.IntMouseDown(position, button);

                var rowIndex = (int)(position.Y / RowHeight);
                _dropdownList.SelectRow(rowIndex);
            }
Exemple #23
0
 /// <summary>
 /// Get row index using a coordinate within the widgets area. Returns
 /// -1 if no row exists at the specified coordinates.
 /// </summary>
 /// <param name="position"></param>
 /// <returns></returns>
 private int GetRowIndex(Vector2 position)
 {
     var rowIndex = (int)((position.Y - HeaderHeight)/RowHeight);
     return rowIndex > (Data.Count - 1) ? -1 : rowIndex;
 }
Exemple #24
0
 internal override void IntMouseDown(Vector2 position, MouseButton button)
 {
     base.IntMouseDown(position, button);
     UpdateValue(position);
 }
Exemple #25
0
        internal override void IntMouseMove(Vector2 position)
        {
            base.IntMouseMove(position);
            var rowIndex = GetRowIndex(position);

            if (rowIndex != _previousHighlightedRowIndex)
            {
                _previousHighlightedRowIndex = rowIndex;
                _mouseOverFade = 0.0f;
            }

            _highlightedRowIndex = rowIndex;
        }
 public static void WriteVectorXY(this BinaryWriter writer, Vector2 vector)
 {
     writer.Write(vector.X);
     writer.Write(vector.Y);
 }
Exemple #27
0
        private void PerformUpdate(Vector2 size, TexturePatch textures,
            string overrideTexture = null, float alpha = 1.0f)
        {
            var rectTL =
                new Rectangle
                {
                    TopLeft = new Vector2(0, 0),
                    BottomRight = new Vector2(textures.TL.Width, textures.TL.Height)
                };

            var rectT =
                new Rectangle
                {
                    TopLeft = new Vector2(textures.TL.Width, 0),
                    BottomRight = new Vector2(size.X - rectTL.Width, textures.T.Height)
                };

            var rectTR =
                new Rectangle
                {
                    TopLeft = new Vector2(rectT.Width + rectTL.Width, 0),
                    BottomRight = new Vector2(rectT.Width + rectTL.Width + textures.TR.Width, textures.TR.Height)
                };

            var rectL =
                new Rectangle
                {
                    TopLeft = new Vector2(0, rectTL.Height),
                    BottomRight = new Vector2(textures.L.Width, size.Y - rectTL.Height)
                };

            var rectC =
                new Rectangle
                {
                    TopLeft = new Vector2(textures.TL.Width, textures.TL.Height),
                    BottomRight = new Vector2(size.X - rectTL.Width, size.Y - rectTL.Height)
                };

            var rectR =
                new Rectangle
                {
                    TopLeft = new Vector2(size.X - rectTL.Width, rectTR.Height),
                    BottomRight = new Vector2(size.X, size.Y - rectTL.Height)
                };

            var rectBL =
                new Rectangle
                {
                    TopLeft = new Vector2(0, size.Y - textures.BL.Height),
                    BottomRight = new Vector2(textures.BL.Width, size.Y)
                };

            var rectB =
                new Rectangle
                {
                    TopLeft = new Vector2(textures.BL.Width, size.Y - textures.B.Height),
                    BottomRight = new Vector2(size.X - textures.BR.Width, size.Y)
                };

            var rectBR =
                new Rectangle
                {
                    TopLeft = new Vector2(size.X - textures.BR.Width, size.Y - textures.BR.Height),
                    BottomRight = new Vector2(size.X, size.Y)
                };

            rectTL = rectTL.Translate(_offset);
            rectT = rectT.Translate(_offset);
            rectTR = rectTR.Translate(_offset);
            rectL = rectL.Translate(_offset);
            rectC = rectC.Translate(_offset);
            rectR = rectR.Translate(_offset);
            rectBL = rectBL.Translate(_offset);
            rectB = rectB.Translate(_offset);
            rectBR = rectBR.Translate(_offset);

            var dataStream = _textureRenderer.LockVertexBuffer();

            WriteQuad(textures.TL, rectTL, dataStream, alpha);
            WriteQuad(textures.T, rectT, dataStream, alpha);
            WriteQuad(textures.TR, rectTR, dataStream, alpha);
            WriteQuad(textures.L, rectL, dataStream, alpha);
            WriteQuad(textures.C, rectC, dataStream, alpha);
            WriteQuad(textures.R, rectR, dataStream, alpha);
            WriteQuad(textures.BL, rectBL, dataStream, alpha);
            WriteQuad(textures.B, rectB, dataStream, alpha);
            WriteQuad(textures.BR, rectBR, dataStream, alpha);

            var texture = textures.TL;

            if (!string.IsNullOrEmpty(overrideTexture))
            {
                texture = _graphicsContext.GetTexture(overrideTexture).TextureArea;
            }

            _textureRenderer.UnlockVertexBuffer();
            _textureRenderer.Render(PrimitiveType.TriangleList, 0, 18, texture, alpha, 1);
        }
Exemple #28
0
            protected internal void Show()
            {
                Size = new Vector2(_dropdownList.Size.X, GetDropdownHeight());
                // todo: move to above the dropdown list if there isn't enough room on the screen

                Position = _dropdownList.GetAbsolutePosition() + new Vector2(0, _dropdownList.Size.Y);

                if (Position.Y + Size.Y > GuiManager.ViewportSize.Y)
                {
                    Position = Position.Translate(0, -(Size.Y + _dropdownList.Size.Y));
                }

                Visible = true;
                BringToFront();
            }
Exemple #29
0
 public GetWidgetResult()
 {
     Widget = null;
     WindowPosition = new Vector2();
     Position = new Vector2();
 }