示例#1
0
文件: Label.cs 项目: valoni/Tinkr
        /// <summary>
        /// Is called when ever the size of the control needs to be calculated.
        /// </summary>
        /// <param name="autoSizeMode">Current <see cref="AutoSizeControl.AutoSizeMode"/></param>
        /// <returns>Returns the needed size for the control</returns>
        protected override size OnMeasureControl(AutoSizeModes autoSizeMode)
        {
            var size = FontManager.ComputeExtentEx(_font, _text);

            size.Grow(Padding.Horizontal, Padding.Vertical);
            return(size);
        }
示例#2
0
        public static Panel AddPanel(Panel panel = null, AutoSizeModes scaling = AutoSizeModes.ResizeToFill)
        {
            Panel newPanel = new Panel();

            newPanel.AutoSize = scaling;
            if (panel != null)
            {
                panel.Components.Add(newPanel);
            }

            return(newPanel);
        }
示例#3
0
 public void SetAllAutoSize(AutoSizeModes mode)
 {
     healthBar.AutoSize      = mode;
     fatigueBar.AutoSize     = mode;
     magickaBar.AutoSize     = mode;
     healthBarLoss.AutoSize  = mode;
     fatigueBarLoss.AutoSize = mode;
     magickaBarLoss.AutoSize = mode;
     healthBarGain.AutoSize  = mode;
     fatigueBarGain.AutoSize = mode;
     magickaBarGain.AutoSize = mode;
 }
示例#4
0
        /// <summary>
        /// Is called when ever the size of the control needs to be calculated.
        /// </summary>
        /// <param name="autoSizeMode">Current <see cref="AutoSizeControl.AutoSizeMode"/></param>
        /// <returns>Returns the needed size for the control</returns>
        protected override size OnMeasureControl(AutoSizeModes autoSizeMode)
        {
            int  textWidth;
            int  textHeight;
            uint textFlags;

            CalcTextMetrics(autoSizeMode, out textWidth, out textHeight, out textFlags);

            return(new size(textWidth + Padding.Horizontal, textHeight + Padding.Vertical));

            //var size = FontManager.ComputeExtentEx(_font, _text);
            //size.Grow(Padding.Horizontal, Padding.Vertical);
            //return size;
        }
示例#5
0
        private void CalcTextMetrics(AutoSizeModes autoSizeMode, out int textWidth, out int texhtHeight, out uint textFlags)
        {
            int availableWidth;
            int availHeight;

            textFlags = Bitmap.DT_TrimmingNone;

            if ((autoSizeMode & AutoSizeModes.Width) != 0)
            {
                availableWidth = Int32.MaxValue;
            }
            else
            {
                availableWidth = Width - Padding.Horizontal;
                textFlags     |= Bitmap.DT_WordWrap;
            }
            if ((autoSizeMode & AutoSizeModes.Height) != 0)
            {
                availHeight = Int32.MaxValue;
            }
            else
            {
                availHeight = Height - Padding.Vertical;
            }
            switch (HorizontalTextAlignment)
            {
            case HorizontalAlignment.Center:
                textFlags |= Bitmap.DT_AlignmentCenter;
                break;

            case HorizontalAlignment.Right:
                textFlags |= Bitmap.DT_AlignmentRight;
                break;
            }
            _font.ComputeTextInRect(_text, out textWidth, out texhtHeight, 0, 0, availableWidth, availHeight, textFlags);
        }
示例#6
0
 /// <summary>
 /// Initializes the control
 /// </summary>
 /// <param name="name">Name of the control</param>
 /// <param name="x">X position relative to it's parent</param>
 /// <param name="y">Y position relative to it's parent</param>
 /// <param name="width">Width of the control in pixel</param>
 /// <param name="height">Height of the control in pixel</param>
 /// <remarks>
 /// <see cref="AutoSizeControl.AutoSizeMode"/> is set to <see cref="AutoSizeModes.None"/>
 /// </remarks>
 protected AutoSizeControl(string name, int x, int y, int width, int height) :
     base(name, x, y, width, height)
 {
     _autoSizeMode = AutoSizeModes.None;
 }
示例#7
0
 /// <summary>
 /// Initializes the control
 /// </summary>
 /// <param name="name">Name of the control</param>
 /// <param name="x">X position relative to it's parent</param>
 /// <param name="y">Y position relative to it's parent</param>
 /// <remarks>
 /// The <see cref="Control.Width"/> and <see cref="Control.Height"/> is calculated automatically to fit the font.
 /// <see cref="AutoSizeControl.AutoSizeMode"/> is set to <see cref="AutoSizeModes.WidthAndHeight"/>
 /// </remarks>
 protected AutoSizeControl(string name, int x, int y) :
     base(name, x, y)
 {
     _autoSizeMode = AutoSizeModes.WidthAndHeight;
 }
示例#8
0
 /// <summary>
 /// Initializes the control
 /// </summary>
 /// <param name="name">Name of the control</param>
 /// <remarks>
 /// The <see cref="Control.Width"/> and <see cref="Control.Height"/> is calculated automatically to fit the font.
 /// <see cref="AutoSizeControl.AutoSizeMode"/> is set to <see cref="AutoSizeModes.WidthAndHeight"/>
 /// </remarks>
 protected AutoSizeControl(string name) :
     base(name)
 {
     _autoSizeMode = AutoSizeModes.WidthAndHeight;
 }
示例#9
0
 /// <summary>
 /// Is called when ever the size of the control needs to be calculated.
 /// </summary>
 /// <param name="autoSizeMode">Current <see cref="AutoSizeMode"/></param>
 /// <returns>Returns the needed size for the control</returns>
 protected abstract size OnMeasureControl(AutoSizeModes autoSizeMode);
        public static Panel AddPanel(Panel panel = null, AutoSizeModes scaling = AutoSizeModes.ResizeToFill)
        {
            Panel newPanel = new Panel();
            newPanel.AutoSize = scaling;
            if (panel != null)
                panel.Components.Add(newPanel);

            return newPanel;
        }