Example #1
0
        public Label()
        {
            RegisterService <ILayout>(this);
            RegisterService <IRenderer>(this);

            Font    = DefaultFont;
            Pen     = DefaultPen;
            Padding = new Vector2(5, 5);
        }
Example #2
0
 private System.Drawing.Font GetFont(AnyFont handle)
 {
     if (fonts.ContainsKey(handle))
     {
         return(fonts[handle]);
     }
     else
     {
         var font = new System.Drawing.Font(handle.FontName, handle.Size);
         fonts[handle] = font;
         return(font);
     }
 }
Example #3
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);
            }
        }
Example #4
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;
        }
Example #5
0
        public Vector2 MeasureString(string text, AnyFont font, float maxWidth = 0)
        {
            var size = Graphics.MeasureString(text, GetFont(font), (int)(maxWidth * ScalingFactor));

            return(new Vector2(size.Width / ScalingFactor, size.Height / ScalingFactor));
        }