Exemplo n.º 1
0
        public void DrawRectangle(AnyPen pen, Vector2 p1, Vector2 p2, float radius = 0)
        {
            p1 *= ScalingFactor;
            p2 *= ScalingFactor;
            if (radius == 0)
            {
                float x = (int)Math.Ceiling(Math.Min(p1.x, p2.x));
                float y = (int)Math.Ceiling(Math.Min(p1.y, p2.y));
                float w = Math.Abs(p1.x - p2.x);
                float h = Math.Abs(p1.y - p2.y);

                var p = GetPen(pen);

                if (w > 0.001f && h > 0.00f)
                {
                    Graphics.DrawRectangle(p, x, y, w, h);
                }
            }
            else
            {
                using (System.Drawing.Drawing2D.GraphicsPath path = RoundedRect(p1, p2, radius))
                {
                    Graphics.DrawPath(GetPen(pen), path);
                }
            }
        }
Exemplo n.º 2
0
        public void FillSquare(AnyPen pen, Vector2 center, Vector2 anchor, float length)
        {
            var p1 = center - anchor * length;
            var p2 = p1 + new Vector2(length, length);

            FillRectangle(pen, p1, p2, 0);
        }
Exemplo n.º 3
0
        public Label()
        {
            RegisterService <ILayout>(this);
            RegisterService <IRenderer>(this);

            Font    = DefaultFont;
            Pen     = DefaultPen;
            Padding = new Vector2(5, 5);
        }
Exemplo n.º 4
0
        public void DrawLine(AnyPen pen, Vector2 p1, Vector2 p2)
        {
            var oldAntialias = Graphics.SmoothingMode;

            p1 *= ScalingFactor;
            p2 *= ScalingFactor;
            Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            Graphics.DrawLine(GetPen(pen), p1.x, p1.y, p2.x, p2.y);
            Graphics.SmoothingMode = oldAntialias;
        }
Exemplo n.º 5
0
        public override bool Equals(object obj)
        {
            if (!(obj is AnyPen))
            {
                return(false);
            }

            AnyPen other = (obj as AnyPen?).Value;

            return(other.a == a && other.b == b && other.r == r && other.g == g && other.Width == Width);
        }
Exemplo n.º 6
0
        public void DrawCircle(AnyPen penHandle, Vector2 center, Vector2 anchor, float radius)
        {
            var oldAntialias = Graphics.SmoothingMode;

            var pen = GetPen(penHandle);

            center *= ScalingFactor;
            radius *= ScalingFactor;

            Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            Graphics.DrawEllipse(pen, center.x - anchor.x * radius * 2, center.y - anchor.y * radius * 2, radius * 2, radius * 2);
            Graphics.SmoothingMode = oldAntialias;
        }
Exemplo n.º 7
0
        // private

        private System.Drawing.Pen GetPen(AnyPen handle)
        {
            handle = new AnyPen(handle.a, handle.r, handle.g, handle.b, (int)(handle.Width * ScalingFactor));
            if (pens.ContainsKey(handle))
            {
                return(pens[handle]);
            }
            else
            {
                var pen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(handle.a, handle.r, handle.g, handle.b), handle.Width)
                {
                    Alignment = System.Drawing.Drawing2D.PenAlignment.Inset
                };
                pens[handle] = pen;
                return(pen);
            }
        }
Exemplo n.º 8
0
        public void DrawString(string text, AnyPen pen, AnyFont font, Vector2 point, Vector2 anchor, float maxWidth = 0)
        {
            Vector2 measure = MeasureString(text, font, maxWidth);

            float x = point.x - anchor.x * measure.x;
            float y = point.y - anchor.y * measure.y;

            if (maxWidth == 0)
            {
                Graphics.DrawString(text, GetFont(font), GetPen(pen).Brush, x * ScalingFactor, y * ScalingFactor);
            }
            else
            {
                var layout = new System.Drawing.RectangleF(x * ScalingFactor, y * ScalingFactor, maxWidth * ScalingFactor, 10000);
                Graphics.DrawString(text, GetFont(font), GetPen(pen).Brush, layout);
            }
        }
Exemplo n.º 9
0
        public ListViewItem(T obj)
        {
            this.obj = obj;

            Padding = new Vector2(20, 50);

            font     = new AnyFont("Microsoft Sans Serif", 9);
            normalBg = new AnyPen(255, 0, 0, 0, 1);
            hoverBg  = new AnyPen(255, 255, 255, 255, 1);

            var mouse = new MouseHandler();

            RegisterService <IMouseEvents>(mouse);
            RegisterService <IRenderer>(this);
            RegisterService <ILayout>(this);

            mouse.OnMouseEnter += Mouse_OnMouseEnter;
            mouse.OnMouseExit  += Mouse_OnMouseExit;
        }