コード例 #1
0
        /// <summary> Draw text with current font of indicated graphics context. </summary>
        /// <param name="display"> The display pointer, that specifies the connection to the X server. <see cref="IntPtr"/> </param>
        /// <param name="window"> The window to draw on. <see cref="IntPtr"/> </param>
        /// <param name="gc"> The graphics context to use for drawing. <see cref="IntPtr"/> </param>
        /// <param name="text"> The tyt to draw. <see cref="X11.TChar[]"/> </param>
        /// <param name="area"> The area to draw within. <see cref="Rectangle"/> </param>
        /// <param name="horzAlign"> The horizontal alignment (0.5F is centered). <see cref="XFloat"/> </param>
        /// <param name="vertAlign"> The vertical alignment (0.5F is centered). <see cref="XFloat"/> </param>
        public virtual void DrawTextLine(IntPtr display, IntPtr window, IntPtr gc, X11.TChar[] text, X11.TRectangle area, float horzAlign, float vertAlign)
        {
            if (display == IntPtr.Zero)
            {
                Console.WriteLine(CLASS_NAME + "::DrawTextLine () ERROR: Argument null: display");
                return;
            }
            if (window == IntPtr.Zero)
            {
                Console.WriteLine(CLASS_NAME + "::DrawTextLine () ERROR: Argument null: window");
                return;
            }
            if (gc == IntPtr.Zero)
            {
                Console.WriteLine(CLASS_NAME + "::DrawTextLine () ERROR: Argument null: gc");
                return;
            }

            if (horzAlign < 0.0F || horzAlign > 1.0F)
            {
                Console.WriteLine(CLASS_NAME + "::DrawTextLine () ERROR: Argument out of range (0.0 ... 1.0): horzAlign");
                if (horzAlign < 0.0F)
                {
                    horzAlign = 0.0F;
                }
                if (horzAlign > 1.0F)
                {
                    horzAlign = 1.0F;
                }
            }
            if (vertAlign < 0.0F || vertAlign > 1.0F)
            {
                Console.WriteLine(CLASS_NAME + "::DrawTextLine () ERROR: Argument out of range (0.0 ... 1.0): vertAlign");
                if (vertAlign < 0.0F)
                {
                    vertAlign = 0.0F;
                }
                if (vertAlign > 1.0F)
                {
                    vertAlign = 1.0F;
                }
            }

            TSize textMeasure = MeasureTextLine(display, gc, text);
            int   textX       = (int)((area.Width - textMeasure.Width) * horzAlign);

            if (textX < _borderWidth + 2)
            {
                textX = _borderWidth + 2;
            }
            if (textX > area.Width - textMeasure.Width - _borderWidth - 2)
            {
                textX = area.Width - textMeasure.Width - _borderWidth - 2;
            }

            int textY = (int)((area.Height - textMeasure.Height) * vertAlign) + (int)(textMeasure.Height * 0.85F);

            X11lib.XDrawString(display, window, gc, (TInt)((int)area.Left + (int)textX), (TInt)((int)area.Top + (int)textY), text, (X11.TInt)text.Length);
        }