예제 #1
0
파일: TextList.cs 프로젝트: tomaszmat/code
 /// <summary>
 /// The Copy Constructor
 /// </summary>
 /// <param name="rhs">The TextItem object from which to copy</param>
 public TextItem(TextItem rhs)
 {
     text            = rhs.Text;
     alignV          = rhs.AlignV;
     alignH          = rhs.AlignH;
     x               = rhs.X;
     y               = rhs.Y;
     coordinateFrame = rhs.CoordinateFrame;
     fontSpec        = new FontSpec(rhs.FontSpec);
 }
예제 #2
0
파일: TextList.cs 프로젝트: tomaszmat/code
        /// <summary>
        /// Initialization method that sets all <see cref="TextItem"/> properties to default
        /// values as defined in the <see cref="Def"/> class.
        /// </summary>
        protected void Init()
        {
            text            = "Text";
            alignV          = Def.Text.AlignV;
            alignH          = Def.Text.AlignH;
            x               = 0;
            y               = 0;
            coordinateFrame = Def.Text.CoordFrame;

            this.fontSpec = new FontSpec(
                Def.Text.FontFamily, Def.Text.FontSize,
                Def.Text.FontColor, Def.Text.FontBold,
                Def.Text.FontItalic, Def.Text.FontUnderline);
        }
예제 #3
0
        /// <summary>
        /// The Copy Constructor
        /// </summary>
        /// <param name="rhs">The TextItem object from which to copy</param>
        public TextItem(TextItem rhs)
        {
            text    = rhs.Text;
            alignV  = rhs.AlignV;
            alignH  = rhs.AlignH;
            x       = rhs.X;
            y       = rhs.Y;
            widthx  = rhs.widthx;
            heighty = rhs.heighty;

            blnForCurveLabel    = rhs.blnForCurveLabel;
            blnForHighPeakLabel = rhs.blnForHighPeakLabel;
            coordinateFrame     = rhs.CoordinateFrame;
            fontSpec            = new FontSpecs(rhs.FontSpec);
        }
예제 #4
0
        /// <summary>
        /// Initialization method that sets all <see cref="TextItem"/> properties to default
        /// values as defined in the <see cref="Def"/> class.
        /// </summary>
        protected void Init()
        {
            text    = "Text";
            alignV  = Defaults.Text.AlignV;
            alignH  = Defaults.Text.AlignH;
            x       = 0;
            y       = 0;
            widthx  = 0;
            heighty = 0;

            coordinateFrame = Defaults.Text.CoordFrame;

            this.fontSpec = new FontSpecs(
                Defaults.Text.FontFamily, Defaults.Text.FontSize,
                Defaults.Text.FontColor, Defaults.Text.FontBold,
                Defaults.Text.FontItalic, Defaults.Text.FontUnderline);

            //widthx  = (this.fontSpec.GetWidth( * (float) text.Length );
            //heighty  = (this.fontSpec.GetHeight);	//* (flot) text.Length ;
            blnForCurveLabel    = false;
            blnForHighPeakLabel = false;
        }
예제 #5
0
        /// <summary>
        /// Render the specified <paramref name="text"/> to the specifed
        /// <see cref="Graphics"/> device.  The text, frame, and fill options
        /// will be rendered as required.
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="text">A string value containing the text to be
        /// displayed.  This can be multiple lines, separated by newline ('\n')
        /// characters</param>
        /// <param name="x">The X location to display the text, in screen
        /// coordinates, relative to the horizontal (<see cref="FontAlignH"/>)
        /// alignment parameter <paramref name="alignH"/></param>
        /// <param name="y">The Y location to display the text, in screen
        /// coordinates, relative to the vertical (<see cref="FontAlignV"/>
        /// alignment parameter <paramref name="alignV"/></param>
        /// <param name="alignH">A horizontal alignment parameter specified
        /// using the <see cref="FontAlignH"/> enum type</param>
        /// <param name="alignV">A vertical alignment parameter specified
        /// using the <see cref="FontAlignV"/> enum type</param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects.  This is calculated and
        /// passed down by the parent <see cref="AldysPane"/> object using the
        /// <see cref="AldysPane.CalcScaleFactor"/> method, and is used to proportionally adjust
        /// font sizes, etc. according to the actual size of the graph.
        /// </param>
        public void Draw(Graphics g, string text, float x,
                         float y, FontAlignH alignH, FontAlignV alignV,
                         double scaleFactor)
        {
            // make sure the font size is properly scaled
            Remake(scaleFactor);

            // Get the width and height of the text
            SizeF sizeF = g.MeasureString(text, this.font);

            // Save the old transform matrix for later restoration
            Matrix matrix = g.Transform;

            // Move the coordinate system to local coordinates
            // of this text object (that is, at the specified
            // x,y location)
            g.TranslateTransform(x, y);

            // Since the text will be drawn by g.DrawString()
            // assuming the location is the TopCenter
            // (the Font is aligned using StringFormat to the
            // center so multi-line text is center justified),
            // shift the coordinate system so that we are
            // actually aligned per the caller specified position
            if (alignH == FontAlignH.Left)
            {
                x = sizeF.Width / 2.0F;
            }
            else if (alignH == FontAlignH.Right)
            {
                x = -sizeF.Width / 2.0F;
            }
            else
            {
                x = 0.0F;
            }

            if (alignV == FontAlignV.Center)
            {
                y = -sizeF.Height / 2.0F;
            }
            else if (alignV == FontAlignV.Bottom)
            {
                y = -sizeF.Height;
            }
            else
            {
                y = 0.0F;
            }

            // Rotate the coordinate system according to the
            // specified angle of the FontSpec
            if (angle != 0.0F)
            {
                g.RotateTransform(-angle);
            }

            // Shift the coordinates to accomodate the alignment
            // parameters
            g.TranslateTransform(x, y);

            // make a solid brush for rendering the font itself
            SolidBrush brush = new SolidBrush(this.fontColor);

            // make a center justified StringFormat alignment
            // for drawing the text
            StringFormat strFormat = new StringFormat();

            strFormat.Alignment = StringAlignment.Center;

            // Create a rectangle representing the frame around the
            // text.  Note that, while the text is drawn based on the
            // TopCenter position, the rectangle is drawn based on
            // the TopLeft position.  Therefore, move the rectangle
            // width/2 to the left to align it properly
            RectangleF rectF = new RectangleF(-sizeF.Width / 2.0F, 0.0F,
                                              sizeF.Width, sizeF.Height);

            // If the background is to be filled, fill it
            if (isFilled)
            {
                SolidBrush fillBrush = new SolidBrush(this.fillColor);
                g.FillRectangle(fillBrush, rectF);
            }

            // Draw the frame around the text if required
            if (isFramed)
            {
                Pen pen = new Pen(this.frameColor, this.frameWidth);
                g.DrawRectangle(pen, Rectangle.Round(rectF));
            }

            // Draw the actual text.  Note that the coordinate system
            // is set up such that 0,0 is at the location where the
            // CenterTop of the text needs to be.
            g.DrawString(text, this.font, brush, 0.0F, 0.0F, strFormat);

            // Restore the transform matrix back to original
            g.Transform = matrix;
        }