Exemplo n.º 1
0
		protected override void OnDraw (Context ctx, Rectangle cellArea)
		{
			PackageViewModel packageViewModel = GetValue (PackageField);
			if (packageViewModel == null) {
				return;
			}

			FillCellBackground (ctx);
			UpdateTextColor (ctx);

			DrawCheckBox (ctx, packageViewModel, cellArea);
			DrawPackageImage (ctx, cellArea);

			double packageIdWidth = cellArea.Width - packageDescriptionPadding.HorizontalSpacing - packageDescriptionLeftOffset;

			// Package download count.
			if (packageViewModel.HasDownloadCount) {
				var downloadCountTextLayout = new TextLayout ();
				downloadCountTextLayout.Text = packageViewModel.GetDownloadCountOrVersionDisplayText ();
				Size size = downloadCountTextLayout.GetSize ();
				Point location = new Point (cellArea.Right - packageDescriptionPadding.Right, cellArea.Top + packageDescriptionPadding.Top);
				Point downloadLocation = location.Offset (-size.Width, 0);
				ctx.DrawTextLayout (downloadCountTextLayout, downloadLocation);

				packageIdWidth = downloadLocation.X - cellArea.Left - packageIdRightHandPaddingWidth - packageDescriptionPadding.HorizontalSpacing - packageDescriptionLeftOffset;
			}

			// Package Id.
			var packageIdTextLayout = new TextLayout ();
			packageIdTextLayout.Font = packageIdTextLayout.Font.WithSize (12);
			packageIdTextLayout.Markup = packageViewModel.GetNameMarkup ();
			packageIdTextLayout.Trimming = TextTrimming.WordElipsis;
			Size packageIdTextSize = packageIdTextLayout.GetSize ();
			packageIdTextLayout.Width = packageIdWidth;
			ctx.DrawTextLayout (
				packageIdTextLayout,
				cellArea.Left + packageDescriptionPadding.Left + packageDescriptionLeftOffset,
				cellArea.Top + packageDescriptionPadding.Top);

			// Package description.
			var descriptionTextLayout = new TextLayout ();
			descriptionTextLayout.Font = descriptionTextLayout.Font.WithSize (11);
			descriptionTextLayout.Width = cellArea.Width - packageDescriptionPadding.HorizontalSpacing - packageDescriptionLeftOffset;
			descriptionTextLayout.Height = cellArea.Height - packageIdTextSize.Height - packageDescriptionPadding.VerticalSpacing;
			descriptionTextLayout.Text = packageViewModel.Summary;
			descriptionTextLayout.Trimming = TextTrimming.Word;

			ctx.DrawTextLayout (
				descriptionTextLayout,
				cellArea.Left + packageDescriptionPadding.Left + packageDescriptionLeftOffset,
				cellArea.Top + packageIdTextSize.Height + packageDescriptionPaddingHeight + packageDescriptionPadding.Top);
		}
Exemplo n.º 2
0
			protected override void OnDraw (Context ctx, Rectangle dirtyRect)
			{
				base.OnDraw (ctx, dirtyRect);

				ctx.Rectangle (0, 0, Size.Width, Size.Height);
				ctx.SetColor (Colors.LightGray);
				ctx.Fill ();

				ctx.SetColor (Colors.Black);
				using (var layout = new TextLayout (this))
				{
					layout.Text = text;
					ctx.DrawTextLayout (layout, new Point (0, 20));
				}
			}
Exemplo n.º 3
0
		internal protected override void Draw (Context ctx, Rectangle area, long line, double x, double y)
		{
			ctx.Rectangle (x, y, Width, Editor.LineHeight);
			ctx.SetColor (Style.HexOffsetBg);
			ctx.Fill ();

			if (line >= 0 && line * Editor.BytesInRow < Data.Length) {
				LayoutWrapper layout = GetLayout (line);
				var sz = layout.Layout.GetSize ();
				ctx.SetColor (line != Caret.Line ? Style.HexOffset : Style.HexOffsetHighlighted);
				ctx.DrawTextLayout (layout.Layout, x + Width - sz.Width - 4, y);
				if (layout.IsUncached)
					layout.Dispose ();
			}
		}
Exemplo n.º 4
0
        protected internal override void Draw(Context cr, Xwt.Rectangle area, DocumentLine line, int lineNumber, double x, double y, double height)
        {
            if (lineNumber <= editor.Document.LineCount)
            {
                TextLayout layout;
                if (!layoutDict.TryGetValue(lineNumber, out layout))
                {
                    layout = new TextLayout();
                    layout.Font = editor.Options.EditorFont;
                    layout.Text = lineNumber.ToString();

                    layoutDict[lineNumber] = layout;
                }

                cr.SetColor(Colors.Black);
                cr.DrawTextLayout(layout, x + leftPadding, y);
            }
        }
Exemplo n.º 5
0
        protected override void OnDraw(Context ctx, Rectangle dirtyRect)
        {
            base.OnDraw(ctx, dirtyRect);

            ctx.SetColor(Colors.Gray);
            ctx.SetLineWidth(1);

            ctx.RoundRectangle(0, Padding.Top / 2 - .5, Width - 4.5, Height - Padding.Bottom * 1.5, 3);
            ctx.Stroke();

            var tl = new TextLayout(this) { Text = title, Width = Width - Padding.Left - Padding.Right / 2 };

            ctx.SetColor(Colors.White);
            ctx.Rectangle(Padding.Left, 0, tl.GetSize().Width, Padding.Top);
            ctx.Fill();

            ctx.SetColor(Colors.Black);
            ctx.DrawTextLayout(tl, Padding.Left, 0);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Draws the title using the Drawing Context, Origin (x,y) and scale
        /// </summary>
        /// <returns>
        /// The Size required for the title
        /// </returns>
        /// TODO: Add a MeasureTitle routine, since can measure TextLayout now
        /// 
        private Size DrawTitle(Context ctx, Point origin, double scale)
        {
            ctx.Save ();
            ctx.SetColor (TitleColor);
            Font scaled_font;
            if (AutoScaleTitle) {
                scaled_font = titleFont.WithScaledSize (scale);
            }
            else {
                scaled_font = titleFont;
            }

            TextLayout layout = new TextLayout ();
            layout.Font = scaled_font;
            layout.Text = Title;
            Size titleSize = layout.GetSize ();
            origin.X -= titleSize.Width/2;

            ctx.DrawTextLayout (layout, origin);
            ctx.Restore ();

            return titleSize;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Raises the draw event.
        /// </summary>
        /// <param name="ctx">Context.</param>
        /// <param name="dirtyRect">Dirty rect.</param>
        protected override void OnDraw(Context ctx, Rectangle dirtyRect)
        {
            base.OnDraw(ctx, dirtyRect);

            ctx.SetLineWidth(1.0);

            if (previous != null && !previous.Active) {
                ctx.SetColor(deactiveColor);
                if (Multiple) {
                    ctx.Rectangle(0, 0, Lean.Dx * 2, Size.Height);
                    ctx.Fill();

                    ctx.SetColor(borderColor);
                    ctx.MoveTo(0, 0);
                    ctx.LineTo(Lean.Dx * 2, 0);
                    ctx.Stroke();
                } else {
                    ctx.MoveTo(0, 0);
                    ctx.CurveTo(
                        0, 0,
                        Lean.Dx, 0,
                        Lean.Dx, Lean.Dy);
                    ctx.LineTo(Lean.Dx, Size.Height - Lean.Dy);
                    ctx.CurveTo(
                        Lean.Dx, Size.Height - Lean.Dy,
                        Lean.Dx, Size.Height + 0.5,
                        Lean.Dx * 2, Size.Height + 0.5);
                    ctx.LineTo(0, Size.Height);

                    ctx.FillPreserve();

                    ctx.SetColor(borderColor);
                    ctx.Stroke();
                }
            }

            if (previous == null || Multiple || !previous.Active) {
                ctx.MoveTo(0, Size.Height + 0.5);
                ctx.CurveTo(
                    0, Size.Height + 0.5,
                    Lean.Dx, Size.Height + 0.5,
                    Lean.Dx, Size.Height - Lean.Dy);
            } else {
                ctx.MoveTo(Lean.Dx, Size.Height);
            }
            ctx.LineTo(Lean.Dx, Lean.Dy);
            ctx.CurveTo(
                Lean.Dx, Lean.Dy,
                Lean.Dx, 0,
                Lean.Dx * 2, 0);

            if (next == null) {
                ctx.LineTo(Size.Width - (Lean.Dx * 2), 0);
                ctx.CurveTo(
                    Size.Width - (Lean.Dx * 2), 0,
                    Size.Width - Lean.Dx, 0,
                    Size.Width - Lean.Dx, Lean.Dy);
                ctx.LineTo(Size.Width - Lean.Dx, Size.Height - Lean.Dy);
                ctx.CurveTo(
                    Size.Width - Lean.Dx, Size.Height - Lean.Dy,
                    Size.Width - Lean.Dx, Size.Height,
                    Size.Width, Size.Height);
            } else {
                ctx.LineTo(Size.Width, 0);
                ctx.LineTo(Size.Width, Size.Height);
            }

            ctx.SetColor(Active ? activeColor : deactiveColor);
            ctx.Fill();

            // border
            if (previous == null || Multiple || !previous.Active) {
                ctx.MoveTo(0, Size.Height + 0.5);
                ctx.CurveTo(
                    0, Size.Height + 0.5,
                    Lean.Dx, Size.Height + 0.5,
                    Lean.Dx, Size.Height - Lean.Dy);
            } else {
                ctx.MoveTo(Lean.Dx, Size.Height + 0.5 - Lean.Dy);
            }

            ctx.LineTo(Lean.Dx, Lean.Dy);
            ctx.CurveTo(
                Lean.Dx, Lean.Dy,
                Lean.Dx, 0,
                Lean.Dx * 2, 0);

            if (next == null) {
                ctx.LineTo(Size.Width - (Lean.Dx * 2), 0);
                ctx.CurveTo(
                    Size.Width - (Lean.Dx * 2), 0,
                    Size.Width - Lean.Dx, 0,
                    Size.Width - Lean.Dx, Lean.Dy);
                ctx.LineTo(Size.Width - Lean.Dx, Size.Height - Lean.Dy);
                ctx.CurveTo(
                    Size.Width - Lean.Dx, Size.Height - Lean.Dy,
                    Size.Width - Lean.Dx, Size.Height + 0.5,
                    Size.Width, Size.Height + 0.5);
            } else {
                ctx.LineTo(Size.Width, 0);
            }

            ctx.SetColor(borderColor);
            ctx.Stroke();

            if (previous != null && previous.Active) {
                ctx.SetColor(activeColor);
                if (Multiple) {
                    ctx.Rectangle(0, 0, Lean.Dx * 2, Size.Height);
                    ctx.Fill();

                    ctx.SetColor(borderColor);
                    ctx.MoveTo(0, 0);
                    ctx.LineTo(Lean.Dx * 2, 0);
                    ctx.Stroke();
                } else {
                    ctx.MoveTo(0, 0);
                    ctx.CurveTo(
                        0, 0,
                        Lean.Dx, 0,
                        Lean.Dx, Lean.Dy);
                    ctx.LineTo(Lean.Dx, Size.Height - Lean.Dy);
                    ctx.CurveTo(
                        Lean.Dx, Size.Height - Lean.Dy,
                        Lean.Dx, Size.Height + 0.5,
                        Lean.Dx * 2, Size.Height + 0.5);
                    ctx.LineTo(0, Size.Height);

                    ctx.FillPreserve();

                    ctx.SetColor(borderColor);
                    ctx.Stroke();
                }
            }

            // text
            ctx.SetColor(Active ? Colors.AliceBlue : deactiveTextColor);
            ctx.DrawTextLayout(text, new Point(padding.Left + Lean.Dx + 2, padding.Top));

            // close button
            if (Closeable) {
                ctx.DrawImage(Hovered ? closeSelected : (Active ? closeNormalInv : closeNormal),
                    new Point(
                        Size.Width - closeNormal.Width - (next == null ? padding.Right + Lean.Dx : 0),
                        (Size.Height - closeNormal.Height) / 2
                    )
                );
            }
        }
Exemplo n.º 8
0
		public void DrawCaret (Context ctx, Rectangle area)
		{
			if (!caretBlink || HexEditorData.IsSomethingSelected) 
				return;
			long caretY = HexEditorData.Caret.Line * LineHeight - (long)HexEditorData.VAdjustment.Value;
			double caretX;
			char ch;
			if (HexEditorData.Caret.InTextEditor) {
				caretX = textEditorMargin.CalculateCaretXPos (out ch);
			} else {
				caretX = hexEditorMargin.CalculateCaretXPos (out ch);
			}

			if (!area.Contains (caretX, (int)caretY))
				return;
			
			if (HexEditorData.Caret.IsInsertMode) {
				ctx.Rectangle (caretX, (int)caretY, 2, LineHeight);
			} else {
				ctx.Rectangle (caretX, (int)caretY, textEditorMargin.charWidth, LineHeight);
			}

			ctx.SetColor (HexEditorStyle.HexDigit); 
			ctx.Fill ();

			if (!HexEditorData.Caret.IsInsertMode) {
				using (var layout = new TextLayout (this)) {
					layout.Font = Options.Font;
					layout.Text = ch.ToString ();
					ctx.SetColor (HexEditorStyle.HexDigitBg);
					ctx.DrawTextLayout (layout, caretX, caretY); 
				}
			}
		}
Exemplo n.º 9
0
        protected override void OnDraw(Context ctx, Rectangle dirtyRect)
        {
            base.OnDraw(ctx, dirtyRect);

            for (int i = 0; i < Size.Width / checkerboard.Width; i++)
            {
                for (int j = 0; j < Size.Height / checkerboard.Height; j++)
                {
                    ctx.DrawImage(checkerboard, i * checkerboard.Width, j * checkerboard.Height);
                }
            }

            ctx.SetLineWidth(1);

            ctx.SetColor(color);
            ctx.Rectangle(0, 0, Size.Width - 20, Size.Height);
            ctx.Fill();

            ctx.SetColor(DefaultColor);
            ctx.Rectangle(Size.Width - 20, 0, 20, Size.Height);
            ctx.Fill();

            ctx.SetColor(Colors.Black);
            ctx.Rectangle(0, 0, Size.Width, Size.Height);
            ctx.Stroke();

            //ctx.SetColor(Color.Brightness > .5 ? Colors.White : Colors.Black);
            ctx.SetColor(((-1 * Color.Brightness) + 1) * 1.15 + (Color.Alpha) > 1.2 ? Colors.White : Colors.Black);
            ctx.DrawTextLayout(new TextLayout(this) { Text = Color.ToHexString().ToUpper() }, 2, 3);

            if (mover && (IsDefaultColor || mx <= Size.Width - 20))
            {
                ctx.SetColor(new Color(1, 1, 1, .33));
                ctx.Rectangle(0, 0, Size.Width - (IsDefaultColor ? 0 : 20), Size.Height);
                ctx.Fill();
            }

            if (!IsDefaultColor)
            {
                if (mover && mx > Size.Width - 20)
                {
                    ctx.SetColor(new Color(1, 1, 1, .33));
                    ctx.Rectangle(Size.Width - 20, 0, 20, Size.Height);
                    ctx.Fill();
                }

                ctx.SetColor(Colors.Black);
                ctx.MoveTo(Size.Width - 19.5, 0);
                ctx.RelLineTo(0, Size.Height);
                ctx.Stroke();

                if (mover)
                    ctx.DrawImage(resetImage, Size.Width - 18, (Size.Height - 16) / 2, 16, 16);
            }
        }
Exemplo n.º 10
0
		internal protected override void Draw (Context ctx, Rectangle area, long line, double x, double y)
		{
			ctx.Rectangle (x, y, Width, Editor.LineHeight);
			ctx.SetColor (Style.HexDigitBg); 
			ctx.Fill ();

			LayoutWrapper layout = GetLayout (line);
			char ch;
			if (!Data.IsSomethingSelected && Caret.InTextEditor && line == Data.Caret.Line) {
				ctx.Rectangle (CalculateCaretXPos (false, out ch), y, byteWidth, Editor.LineHeight);
				ctx.SetColor (Style.HighlightOffset); 
				ctx.Fill ();

			}
			ctx.SetColor (Style.HexDigit);
			ctx.DrawTextLayout (layout.Layout, x, y);
			if (layout.IsUncached)
				layout.Dispose ();
		}
Exemplo n.º 11
0
        protected override void OnDraw(Context ctx, Rectangle dirtyRect)
        {
            base.OnDraw(ctx, dirtyRect);

            ctx.DrawTextLayout(new TextLayout() { Text = Text }, 0, 0);
        }
Exemplo n.º 12
0
        double DrawHeader(Context ctx)
        {
            Point textOffset = new Point(8, 4);

            textLayoutBold.Text = algorithm.Headline();
            Size textSize = textLayoutBold.GetSize();

            if (textSize.Width >= AbsMaxNodeSize.Width - textSize.Height * 2) {
                textLayoutBold.Width = textSize.Width = AbsMaxNodeSize.Width;
            }
            Point textPosition = bound.Location.Offset(textOffset);

            // headline background
            contentOffset.X = 6;
            contentOffset.Y = textOffset.Y + textSize.Height + 4;

            ctx.RoundRectangle(bound.Left + 1, bound.Top + 1, bound.Width - 2, contentOffset.Y, NodeRadius);
            ctx.SetColor(NodeHeadlineBackground);
            ctx.Fill();

            // text
            ctx.SetColor(NodeHeadlineTextColor);
            ctx.DrawTextLayout(textLayoutBold, textPosition);

            // icons
            double iconWidth = 0.0;
            foreach (var icon in icons) {
                if (icon.Value.Visible) {
                    iconWidth = icon.Value.Bounds.Width;
                    icon.Value.Bounds =
                        new Rectangle(bound.Width - icon.Value.Bounds.Width - 10, 3, icon.Value.Bounds.Width, icon.Value.Bounds.Height);
                    ctx.DrawImage(
                        icon.Value.Image,
                        bound.Location.Offset(icon.Value.Bounds.Location)
                    );
                }
            }

            double width = textSize.Width + iconWidth + 10 + NodeTextMargin;

            return width;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Draws the arrow on a plot surface.
        /// </summary>
        /// <param name="ctx">the Drawing Context with which to draw</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis )
        {
            if (To.X > xAxis.Axis.WorldMax || To.X < xAxis.Axis.WorldMin) {
                return;
            }
            if (To.Y > yAxis.Axis.WorldMax || To.Y < yAxis.Axis.WorldMin) {
                return;
            }

            ctx.Save ();

            TextLayout layout = new TextLayout ();
            layout.Font = textFont_;
            layout.Text = text_;

            double angle = angle_;
            if (angle_ < 0.0) {
                int mul = -(int)(angle_ / 360.0) + 2;
                angle = angle_ + 360.0 * (double)mul;
            }

            double normAngle = (double)angle % 360.0;	// angle in range 0 -> 360.

            Point toPoint = new Point (
                xAxis.WorldToPhysical (to_.X, true).X,
                yAxis.WorldToPhysical (to_.Y, true).Y);

            double xDir = Math.Cos (normAngle * 2.0 * Math.PI / 360.0);
            double yDir = Math.Sin (normAngle * 2.0 * Math.PI / 360.0);

            toPoint.X += xDir*headOffset_;
            toPoint.Y += yDir*headOffset_;

            double xOff = physicalLength_ * xDir;
            double yOff = physicalLength_ * yDir;

            Point fromPoint = new Point(
                (int)(toPoint.X + xOff),
                (int)(toPoint.Y + yOff) );

            ctx.SetLineWidth (1);
            ctx.SetColor (arrowColor_);
            ctx.MoveTo (fromPoint);
            ctx.LineTo (toPoint);
            ctx.Stroke ();

            xOff = headSize_ * Math.Cos ((normAngle-headAngle_/2) * 2.0 * Math.PI / 360.0);
            yOff = headSize_ * Math.Sin ((normAngle-headAngle_/2) * 2.0 * Math.PI / 360.0);

            ctx.LineTo (toPoint.X + xOff, toPoint.Y + yOff);

            double xOff2 = headSize_ * Math.Cos ((normAngle+headAngle_/2) * 2.0 * Math.PI / 360.0);
            double yOff2 = headSize_ * Math.Sin ((normAngle+headAngle_/2) * 2.0 * Math.PI / 360.0);

            ctx.LineTo (toPoint.X + xOff2, toPoint.Y + yOff2);
            ctx.LineTo (toPoint);
            ctx.ClosePath ();
            ctx.SetColor (arrowColor_);
            ctx.Fill ();

            Size textSize = layout.GetSize ();
            Size halfSize = new Size (textSize.Width/2, textSize.Height/2);

            double quadrantSlideLength = halfSize.Width + halfSize.Height;

            double quadrantD = normAngle / 90.0;		// integer part gives quadrant.
            int quadrant = (int)quadrantD;				// quadrant in.
            double prop = quadrantD - (double)quadrant;	// proportion of way through this qadrant.
            double dist = prop * quadrantSlideLength;	// distance along quarter of bounds rectangle.

            // now find the offset from the middle of the text box that the
            // rear end of the arrow should end at (reverse this to get position
            // of text box with respect to rear end of arrow).
            //
            // There is almost certainly an elgant way of doing this involving
            // trig functions to get all the signs right, but I'm about ready to
            // drop off to sleep at the moment, so this blatent method will have
            // to do.
            Point offsetFromMiddle = new Point (0, 0);
            switch (quadrant) {
            case 0:
                if (dist > halfSize.Height) {
                    dist -= halfSize.Height;
                    offsetFromMiddle = new Point ( -halfSize.Width + dist, halfSize.Height );
                }
                else {
                    offsetFromMiddle = new Point ( -halfSize.Width, - dist );
                }
                break;
            case 1:
                if (dist > halfSize.Width) {
                    dist -= halfSize.Width;
                    offsetFromMiddle = new Point ( halfSize.Width, halfSize.Height - dist );
                }
                else {
                    offsetFromMiddle = new Point ( dist, halfSize.Height );
                }
                break;
            case 2:
                if (dist > halfSize.Height) {
                    dist -= halfSize.Height;
                    offsetFromMiddle = new Point ( halfSize.Width - dist, -halfSize.Height );
                }
                else {
                    offsetFromMiddle = new Point ( halfSize.Width, -dist );
                }
                break;
            case 3:
                if (dist > halfSize.Width) {
                    dist -= halfSize.Width;
                    offsetFromMiddle = new Point ( -halfSize.Width, -halfSize.Height + dist );
                }
                else {
                    offsetFromMiddle = new Point ( -dist, -halfSize.Height );
                }
                break;
            default:
                throw new XwPlotException( "Programmer error." );
            }

            ctx.SetColor (textColor_);
            double x = fromPoint.X - halfSize.Width - offsetFromMiddle.X;
            double y = fromPoint.Y - halfSize.Height + offsetFromMiddle.Y;
            ctx.DrawTextLayout (layout, x, y);

            ctx.Restore ();
        }
Exemplo n.º 14
0
        /// <summary>
        /// Draw the Axis Label
        /// </summary>
        /// <param name="ctx>The Drawing Context with which to draw.</param>
        /// <param name="offset">offset from axis. Should be calculated so as to make sure axis label misses tick labels.</param>
        /// <param name="axisPhysicalMin">The physical position corresponding to the world minimum of the axis.</param>
        /// <param name="axisPhysicalMax">The physical position corresponding to the world maximum of the axis.</param>
        /// <returns>boxed Rectangle indicating bounding box of label. null if no label printed.</returns>
        public object DrawLabel(Context ctx, Point offset, Point axisPhysicalMin, Point axisPhysicalMax)
        {
            if (Label != "") {

                // first calculate any extra offset for axis label spacing.
                double extraOffsetAmount = LabelOffset;
                extraOffsetAmount += 2; // empirically determed - text was too close to axis before this.
                if (AutoScaleText && LabelOffsetScaled) {
                    extraOffsetAmount *= FontScale;
                }
                // now extend offset.
                double offsetLength = Math.Sqrt (offset.X*offset.X + offset.Y*offset.Y);
                if (offsetLength > 0.01) {
                    double x_component = offset.X / offsetLength;
                    double y_component = offset.Y / offsetLength;

                    x_component *= extraOffsetAmount;
                    y_component *= extraOffsetAmount;

                    if (LabelOffsetAbsolute) {
                        offset.X = x_component;
                        offset.Y = y_component;
                    }
                    else {
                        offset.X += x_component;
                        offset.Y += y_component;
                    }
                }

                // determine angle of axis in degrees
                double theta = Math.Atan2 (
                    axisPhysicalMax.Y - axisPhysicalMin.Y,
                    axisPhysicalMax.X - axisPhysicalMin.X);
                theta = theta * 180.0 / Math.PI;

                Point average = new Point (
                    (axisPhysicalMax.X + axisPhysicalMin.X)/2,
                    (axisPhysicalMax.Y + axisPhysicalMin.Y)/2);

                ctx.Save ();

                ctx.Translate (average.X + offset.X , average.Y + offset.Y);	// this is done last.
                ctx.Rotate (theta);												// this is done first.

                TextLayout layout = new TextLayout ();
                layout.Font = labelFontScaled;
                layout.Text = Label;
                Size labelSize = layout.GetSize ();

                //Draw label centered around zero.
                ctx.DrawTextLayout (layout, -labelSize.Width/2, -labelSize.Height/2);

                // now work out physical bounds of Rotated and Translated label.
                Point [] recPoints = new Point [2];
                recPoints[0] = new Point (-labelSize.Width/2, -labelSize.Height/2);
                recPoints[1] = new Point ( labelSize.Width/2, labelSize.Height/2);
                ctx.TransformPoints (recPoints);

                double x1 = Math.Min (recPoints[0].X, recPoints[1].X);
                double x2 = Math.Max (recPoints[0].X, recPoints[1].X);
                double y1 = Math.Min (recPoints[0].Y, recPoints[1].Y);
                double y2 = Math.Max (recPoints[0].Y, recPoints[1].Y);

                ctx.Restore ();

                // and return label bounding box.
                return new Rectangle (x1, y1, (x2-x1), (y2-y1));
            }
            return null;
        }
Exemplo n.º 15
0
        protected override void OnDraw(Context ctx, Rectangle dirtyRect)
        {
            base.OnDraw (ctx, dirtyRect);

            if (!pset) {
                ParentWindow.BoundsChanged += delegate {
                    QueueDraw ();
                };
                pset = true;
            }

            ctx.Rectangle (Bounds);
            ctx.SetColor (Colors.LightGray);
            ctx.Fill ();

            var size = Size;
            size.Width--;
            size.Height--;
            var fx = size.Width / Desktop.Bounds.Width;

            if (Desktop.Bounds.Height * fx > size.Height)
                fx = size.Height / Desktop.Bounds.Height;

            if (Desktop.Bounds.X < 0)
                ctx.Translate (-Desktop.Bounds.X * fx, 0);
            if (Desktop.Bounds.Y < 0)
                ctx.Translate (0, -Desktop.Bounds.Y * fx);

            ctx.SetLineWidth (1);
            foreach (var s in Desktop.Screens) {
                if (s.Bounds != s.VisibleBounds) {
                    var vr = new Rectangle ((int)(s.Bounds.X * fx), (int)(s.Bounds.Y * fx), (int)(s.Bounds.Width * fx), (int)(s.Bounds.Height * fx));
                    vr = vr.Offset (0.5, 0.5);
                    ctx.Rectangle (vr);
                    ctx.SetColor (Colors.White);
                    ctx.FillPreserve ();
                    ctx.SetColor (Colors.Black);
                    ctx.Stroke ();
                }
                var r = new Rectangle ((int)(s.VisibleBounds.X * fx), (int)(s.VisibleBounds.Y * fx), (int)(s.VisibleBounds.Width * fx), (int)(s.VisibleBounds.Height * fx));
                r = r.Offset (0.5, 0.5);
                ctx.Rectangle (r);
                ctx.SetColor (new Color (0.4, 0.62, 0.83));
                ctx.FillPreserve ();
                ctx.SetColor (Colors.Black);
                ctx.Stroke ();

                TextLayout tl = new TextLayout (ctx);
                tl.Text = s.DeviceName;
                tl.Font = Font;
                ctx.DrawTextLayout (tl, r.Center.X - tl.Width / 2, r.Center.Y - tl.Height / 2);
            }

            var wr = ParentWindow.ScreenBounds;
            wr = new Rectangle ((int)(wr.X * fx), (int)(wr.Y * fx), (int)(wr.Width * fx), (int)(wr.Height * fx));
            ctx.Rectangle (wr);
            ctx.SetColor (Colors.Azure.WithAlpha (0.5));
            ctx.FillPreserve ();
            ctx.SetColor (Colors.Azure);
            ctx.Stroke ();
        }
Exemplo n.º 16
0
        void DrawPopover(Context ctx)
        {
            lock (trackerLock)
            {
                if (actualTrackerHitResult != null)
                {
                    var trackerSettings = DefaultTrackerSettings;
                    if (actualTrackerHitResult.Series != null && !string.IsNullOrEmpty(actualTrackerHitResult.Series.TrackerKey))
                        trackerSettings = trackerDefinitions[actualTrackerHitResult.Series.TrackerKey];

                    if (trackerSettings.Enabled)
                    {
                        var extents = actualTrackerHitResult.LineExtents;
                        if (Math.Abs(extents.Width) < double.Epsilon)
                        {
                            extents = new OxyRect(actualTrackerHitResult.XAxis.ScreenMin.X, extents.Top, actualTrackerHitResult.XAxis.ScreenMax.X - actualTrackerHitResult.XAxis.ScreenMin.X, extents.Height);
                        }
                        if (Math.Abs(extents.Height) < double.Epsilon)
                        {
                            extents = new OxyRect(extents.Left, actualTrackerHitResult.YAxis.ScreenMin.Y, extents.Width, actualTrackerHitResult.YAxis.ScreenMax.Y - actualTrackerHitResult.YAxis.ScreenMin.Y);
                        }

                        var pos = actualTrackerHitResult.Position;

                        if (trackerSettings.HorizontalLineVisible)
                        {

                            renderContext.DrawLine(
                                new[] { new ScreenPoint(extents.Left, pos.Y), new ScreenPoint(extents.Right, pos.Y) },
                                trackerSettings.HorizontalLineColor,
                                trackerSettings.HorizontalLineWidth,
                                trackerSettings.HorizontalLineActualDashArray,
                                LineJoin.Miter,
                                true);
                        }
                        if (trackerSettings.VerticalLineVisible)
                        {
                            renderContext.DrawLine(
                                new[] { new ScreenPoint(pos.X, extents.Top), new ScreenPoint(pos.X, extents.Bottom) },
                                trackerSettings.VerticalLineColor,
                                trackerSettings.VerticalLineWidth,
                                trackerSettings.VerticalLineActualDashArray,
                                LineJoin.Miter,
                                true);
                        }

                        TextLayout text = new TextLayout();
                        text.Font = trackerSettings.Font;
                        text.Text = actualTrackerHitResult.Text;

                        var arrowTop = actualTrackerHitResult.Position.Y <= Bounds.Height / 2;
                        const int arrowPadding = 10;

                        var textSize = text.GetSize();
                        var outerSize = new Size(textSize.Width + (trackerSettings.Padding * 2),
                                                  textSize.Height + (trackerSettings.Padding * 2) + arrowPadding);

                        var trackerBounds = new Rectangle(pos.X - (outerSize.Width / 2),
                                                           0,
                                                           outerSize.Width,
                                                           outerSize.Height - arrowPadding);
                        if (arrowTop)
                            trackerBounds.Y = pos.Y + arrowPadding + trackerSettings.BorderWidth;
                        else
                            trackerBounds.Y = pos.Y - outerSize.Height - trackerSettings.BorderWidth;

                        var borderColor = trackerSettings.BorderColor.ToXwtColor();

                        ctx.RoundRectangle(trackerBounds, 6);
                        ctx.SetLineWidth(trackerSettings.BorderWidth);
                        ctx.SetColor(borderColor);
                        ctx.StrokePreserve();
                        ctx.SetColor(trackerSettings.Background.ToXwtColor());
                        ctx.Fill();

                        ctx.Save();
                        var arrowX = trackerBounds.Center.X;
                        var arrowY = arrowTop ? trackerBounds.Top : trackerBounds.Bottom;
                        ctx.NewPath();
                        ctx.MoveTo(arrowX, arrowY);
                        var triangleSide = 2 * arrowPadding / Math.Sqrt(3);
                        var halfSide = triangleSide / 2;
                        var verticalModifier = arrowTop ? -1 : 1;
                        ctx.RelMoveTo(-halfSide, 0);
                        ctx.RelLineTo(halfSide, verticalModifier * arrowPadding);
                        ctx.RelLineTo(halfSide, verticalModifier * -arrowPadding);
                        ctx.SetColor(borderColor);
                        ctx.StrokePreserve();
                        ctx.ClosePath();
                        ctx.SetColor(trackerSettings.Background.ToXwtColor());
                        ctx.Fill();
                        ctx.Restore();

                        ctx.SetColor(trackerSettings.TextColor.ToXwtColor());
                        ctx.DrawTextLayout(text,
                                            trackerBounds.Left + trackerSettings.Padding,
                                            trackerBounds.Top + trackerSettings.Padding);
                    }
                }
            }
        }
Exemplo n.º 17
0
        protected override void OnDraw(Context ctx, Rectangle dirtyRect)
        {
            // Line arround
            ctx.SetColor(Colors.DarkGray);

            // Drive line arround
            ctx.Rectangle(Bounds);
            ctx.Fill();

            ctx.SetColor(Colors.Gray);
            ctx.Rectangle(Bounds.Inflate(-margin, -margin));
            ctx.Fill();

            // Draw image
            ctx.DrawImage(Image.FromResource(Logo), 5.0, 5.0);

            // Draw text
            ctx.SetColor(Colors.White);
            TextLayout _layout = new TextLayout();
            _layout.Font = Font.WithSize(22);
            _layout.Text = Label;
            _layout.SetFontWeight(FontWeight.Bold, 0, Label.Length);

            // Cocoa layouts
            ctx.DrawTextLayout(_layout, 45, ((Config.Cocoa || Config.Gtk) ? 5 : 2));
        }
Exemplo n.º 18
0
        /// <summary>
        /// Draws the plot using the Drawing Context and X, Y axes supplied.
        /// </summary>
        public override void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            SequenceAdapter data =
                new SequenceAdapter (this.DataSource, this.DataMember, this.OrdinateData, this.AbscissaData);

            TextDataAdapter textData =
                new TextDataAdapter (this.DataSource, this.DataMember, this.TextData);

            TextLayout layout = new TextLayout ();
            layout.Font = Font;

            ctx.Save ();
            ctx.SetColor (Colors.Black);

            for (int i=0; i<data.Count; ++i) {
                try {
                    Point p = data[i];
                    if (!Double.IsNaN(p.X) && !Double.IsNaN(p.Y)) {
                        Point xPos = xAxis.WorldToPhysical (p.X, false);
                        Point yPos = yAxis.WorldToPhysical (p.Y, false);
                        // first plot the marker
                        Marker.Draw (ctx, xPos.X, yPos.Y);
                        // then the label
                        if (textData[i] != "") {
                            layout.Text = textData[i];
                            Size size = layout.GetSize ();
                            switch (labelTextPosition) {
                            case LabelPositions.Above:
                                p.X = xPos.X-size.Width/2;
                                p.Y = yPos.Y-size.Height-Marker.Size*2/3;
                                break;
                            case LabelPositions.Below:
                                p.X = xPos.X-size.Width/2;
                                p.Y = yPos.Y+Marker.Size*2/3;
                                break;
                            case LabelPositions.Left:
                                p.X = xPos.X-size.Width-Marker.Size*2/3;
                                p.Y = yPos.Y-size.Height/2;
                                break;
                            case LabelPositions.Right:
                                p.X = xPos.X+Marker.Size*2/3;
                                p.Y = yPos.Y-size.Height/2;
                                break;
                            }
                            ctx.DrawTextLayout (layout, p);
                        }
                    }
                }
                catch {
                    throw new XwPlotException ("Error in TextPlot.Draw");
                }
            }
            ctx.Restore ();
        }
Exemplo n.º 19
0
        /// <summary>
        /// Draw the marker.
        /// </summary>
        /// <param name="ctx">Context.</param>
        public override void Draw(Context ctx)
        {
            ctx.SetColor(PipelineNode.NodeColorBorder);

            Rectangle bndTmp = Bounds;

            ctx.RoundRectangle(bndTmp.Inflate(-2, -2), 2);
            if (compatible.IsFinal()) {
                ctx.SetColor(Colors.LightGray);
            } else {
                ctx.RoundRectangle(bndTmp.Inflate(-1, -1), 3);
                using (LinearGradient g = new LinearGradient(bndTmp.Left, bndTmp.Top, bndTmp.Right, bndTmp.Bottom)) {
                    g.AddColorStop(0, Colors.Black.BlendWith(NodeColor, 0.7));
                    g.AddColorStop(1, NodeColor);
                    ctx.Pattern = g;
                    ctx.Fill();
                }

                ctx.SetColor(NodeColor);
            }
            ctx.Fill();

            if (IsInput) {
                int inputBufferSize = inputData.Count;
                List<Result> ihCopy;
                lock (inputHistoryLock) {
                    ihCopy = new List<Result>(inputHistory);
                }
                foreach (Result input in ihCopy) {
                    if (input.IsUsed(parent)) {
                        inputBufferSize++;
                    } else {
                        lock (inputHistoryLock) {
                            inputHistory.Remove(input);
                        }
                    }
                }
                if (inputBufferSize > 0) {
                    bool sourceNodeIsAbove = true;
                    if (edges.Count > 0 && edges[0] != null) {
                        if (edges[0].to.Bounds.Center.Y > Bounds.Center.Y - 4.0) {
                            sourceNodeIsAbove = false;
                        }
                    }

                    textLayout.Text = inputBufferSize.ToString();
                    double textWidth = textLayout.GetSize().Width;
                    double textHeight = textLayout.GetSize().Height;
                    Point inputbufferSizeLocation =
                        Bounds.Location.Offset(
                            -24 -(textWidth/2),
                            sourceNodeIsAbove ? textHeight + 6 : -6 - textHeight);

                    ctx.Arc(
                        inputbufferSizeLocation.X + textWidth / 2,
                        inputbufferSizeLocation.Y + textHeight / 2,
                        Math.Max(textHeight, textWidth) / 2 + 1,
                        0, 360
                    );
                    ctx.Fill();

                    ctx.SetColor(PipelineNode.NodeColor);
                    ctx.DrawTextLayout(textLayout, inputbufferSizeLocation);
                }
            } else {
                // if this is a final node
                if (parent.algorithm.Output[positionNo].IsFinal()) {
                    ctx.MoveTo(bndTmp.Right + 4, bndTmp.Top);
                    ctx.LineTo(bndTmp.Right + 4, bndTmp.Bottom);
                    ctx.Stroke();

                    // draw output size on end nodes (= number of features
                    if (parent.results != null &&
                        parent.results.Count > 0 &&
                        parent.results[0].Item1 != null &&
                        parent.results[0].Item1.Length - 1 >= Position) {

                        textLayout.Text = parent.results.Count.ToString();
                        double textWidth = textLayout.GetSize().Width;
                        double textHeight = textLayout.GetSize().Height;
                        Point outputbufferSizeLocation =
                            Bounds.Location.Offset(Bounds.Width * 1.8, 0);

                        ctx.Arc(
                            outputbufferSizeLocation.X + textWidth / 2,
                            outputbufferSizeLocation.Y + textHeight / 2,
                            Math.Max(textHeight, textWidth) / 2 + 1,
                            0, 360
                        );
                        ctx.Fill();

                        ctx.SetColor(PipelineNode.NodeColor);
                        ctx.DrawTextLayout(textLayout, outputbufferSizeLocation);
                    }
                }
            }
        }
Exemplo n.º 20
0
		void DrawTicks (Context ctx, TickEnumerator e, AxisPosition pos, AxisDimension ad, int tickSize, bool showLabels)
		{
			double rheight = Bounds.Height;
			
			TextLayout layout = null;
			
			if (showLabels) {
				layout = new TextLayout ();
				layout.Font = chartFont;
			}
			
			bool isX = pos == AxisPosition.Top || pos == AxisPosition.Bottom;
			bool isTop = pos == AxisPosition.Top || pos == AxisPosition.Right;
			
			double start = GetStart (ad);
			double end = GetEnd (ad);
			
			e.Init (GetOrigin (ad));
			
			while (e.CurrentValue > start)
				e.MovePrevious ();
			
			double lastPosLabel;
			double lastPos;
			double lastTw = 0;
			
			if (isX) {
				lastPosLabel = reverseXAxis ? left + width + MinLabelGapX : left - MinLabelGapX;
				lastPos = left - minTickStep*2;
			}
			else {
				lastPosLabel = reverseYAxis ? top - MinLabelGapY : rheight + MinLabelGapY;
				lastPos = top + height + minTickStep*2;
			}
			
			for ( ; e.CurrentValue <= end; e.MoveNext ())
			{
				double px, py;
				double tw = 0, th = 0;
				int tick = tickSize;
				
				GetPoint (e.CurrentValue, e.CurrentValue, out px, out py);
				
				if (showLabels) {
					layout.Text = e.CurrentLabel;
					var ts = layout.GetSize ();
					tw = ts.Width;
					th = ts.Height;
				}

				if (isX) {
					if (Math.Abs ((long)px - (long)lastPos) < minTickStep || px < left || px > left + width)
						continue;
					lastPos = px;
					
					bool labelFits = false;
					if ((Math.Abs (px - lastPosLabel) - (tw/2) - (lastTw/2)) >= MinLabelGapX) {
						lastPosLabel = px;
						lastTw = tw;
						labelFits = true;
					}
					
					if (isTop) {
						if (showLabels) {
							if (labelFits)
								ctx.DrawTextLayout (layout, px - (tw/2), top - AreaBorderWidth - th);
							else
								tick = tick / 2;
						}
						ctx.MoveTo (px, top);
						ctx.LineTo (px, top + tick);
						ctx.Stroke ();
					}
					else {
						if (showLabels) {
							if (labelFits)
								ctx.DrawTextLayout (layout, px - (tw/2), top + height + AreaBorderWidth);
							else
								tick = tick / 2;
						}
						ctx.MoveTo (px, top + height);
						ctx.LineTo (px, top + height - tick);
						ctx.Stroke ();
					}
				}
				else {
					if (Math.Abs ((long)lastPos - (long)py) < minTickStep || py < top || py > top + height)
						continue;
					lastPos = py;
					
					bool labelFits = false;
					if ((Math.Abs (py - lastPosLabel) - (th/2) - (lastTw/2)) >= MinLabelGapY) {
						lastPosLabel = py;
						lastTw = th;
						labelFits = true;
					}
					
					if (isTop) {
						if (showLabels) {
							if (labelFits)
								ctx.DrawTextLayout (layout, left + width + AreaBorderWidth + 1, py - (th/2));
							else
								tick = tick / 2;
						}
						ctx.MoveTo (left + width, py);
						ctx.LineTo (left + width - tick, py);
						ctx.Stroke ();
					}
					else {
						if (showLabels) {
							if (labelFits)
								ctx.DrawTextLayout (layout, left - AreaBorderWidth - tw - 1, py - (th/2));
							else
								tick = tick / 2;
						}
						ctx.MoveTo (left, py);
						ctx.LineTo (left + tick, py);
						ctx.Stroke ();
					}
				}
			}
		}
Exemplo n.º 21
0
        void DrawText(Context ctx, TextLayout tl, ref double y)
        {
            double x = 10;
            var s = tl.GetSize ();
            var rect = new Rectangle (x, y, s.Width, s.Height).Inflate (0.5, 0.5);
            ctx.SetLineWidth (1);
            ctx.SetColor (Colors.Blue);
            ctx.Rectangle (rect);
            ctx.Stroke ();
            ctx.SetColor (Colors.Black);
            ctx.DrawTextLayout (tl, x, y);

            y += s.Height + 20;
        }
Exemplo n.º 22
0
		void DrawCursorLabel (Context ctx, ChartCursor cursor)
		{
			ctx.SetColor (cursor.Color);
			
			int x, y;
			GetPoint (cursor.Value, cursor.Value, out x, out y);

			if (cursor.Dimension == AxisDimension.X) {
			
				string text;
				
				if (cursor.LabelAxis != null) {
					double minStep = GetMinTickStep (cursor.Dimension);
					TickEnumerator tenum = cursor.LabelAxis.GetTickEnumerator (minStep);
					tenum.Init (cursor.Value);
					text = tenum.CurrentLabel;
				} else {
					text = GetValueLabel (cursor.Dimension, cursor.Value);
				}
				
				if (text != null && text.Length > 0) {
					TextLayout layout = new TextLayout ();
					layout.Font = chartFont;
					layout.Text = text;
					
					Size ts = layout.GetSize ();
					double tl = x - ts.Width/2;
					double tt = top + 4;
					if (tl + ts.Width + 2 >= left + width) tl = left + width - ts.Width - 1;
					if (tl < left + 1) tl = left + 1;
					ctx.SetColor (Colors.White);
					ctx.Rectangle (tl - 1, tt - 1, ts.Width + 2, ts.Height + 2);
					ctx.Fill ();
					ctx.Rectangle (tl - 2, tt - 2, ts.Width + 3, ts.Height + 3);
					ctx.SetColor (Colors.Black);
					ctx.DrawTextLayout (layout, tl, tt);
				}
			} else {
				throw new NotSupportedException ();
			}
		}
Exemplo n.º 23
0
        protected internal override void Draw(Context cr, Xwt.Rectangle area, DocumentLine line, int lineNumber, double x, double y, double height)
        {
            if (line != null)
            {
                TextLayout layout;
                if (!layoutDict.TryGetValue(line, out layout))
                {
                    var mode = editor.Document.SyntaxMode;
                    var style = SyntaxModeService.DefaultColorStyle;
                    var chunks = GetCachedChunks(mode, editor.Document, style, line, line.Offset, line.Length);

                    layout = new TextLayout();
                    layout.Font = editor.Options.EditorFont;
                    string lineText = editor.Document.GetLineText(lineNumber);
                    var stringBuilder = new StringBuilder(lineText.Length);

                    int currentVisualColumn = 1;
                    for (int i = 0; i < lineText.Length; ++i)
                    {
                        char chr = lineText[i];
                        if (chr == '\t')
                        {
                            int length = GetNextTabstop(editor, currentVisualColumn) - currentVisualColumn;
                            stringBuilder.Append(' ', length);
                            currentVisualColumn += length;
                        }
                        else
                        {
                            stringBuilder.Append(chr);
                            if (!char.IsLowSurrogate(chr))
                            {
                                ++currentVisualColumn;
                            }
                        }
                    }
                    layout.Text = stringBuilder.ToString();

                    int visualOffset = 1;
                    foreach (var chunk in chunks)
                    {
                        var chunkStyle = style.GetChunkStyle(chunk);
                        visualOffset = DrawLinePortion(cr, chunkStyle, layout, line, visualOffset, chunk.Length);
                    }

                    //layoutDict[line] = layout;
                }

                cr.DrawTextLayout(layout, x, y);

                if (editor.CaretVisible && editor.Caret.Line == lineNumber)
                {
                    cr.SetColor(Colors.Black);
                    cr.Rectangle(x + ColumnToX(line, editor.Caret.Column), y, caretWidth, LineHeight);
                    cr.Fill();
                }
            }
        }
Exemplo n.º 24
0
		internal protected override void Draw (Context ctx, Rectangle area, long line, double x, double y)
		{
			ctx.Rectangle (x, y, Width, Editor.LineHeight);
			ctx.SetColor (Style.HexDigitBg);
			ctx.Fill ();

			LayoutWrapper layout = GetLayout (line);
			if (!Data.IsSomethingSelected && !Caret.InTextEditor && line == Data.Caret.Line) {
				var column = (int)(Caret.Offset % BytesInRow);
				var xOffset = charWidth * column;
				ctx.Rectangle (x + xOffset, y, charWidth, Editor.LineHeight);
				ctx.SetColor (Style.HighlightOffset);
				ctx.Fill ();
			}
			ctx.SetColor (Style.HexDigit);
			ctx.DrawTextLayout (layout.Layout, x, y);
			if (layout.IsUncached)
				layout.Dispose ();
		}
Exemplo n.º 25
0
        bool DrawBody(Context ctx, double headlineWidth)
        {
            bool ret = false;
            ctx.SetColor(Colors.Black);

            double inputMaxWidth = 0.0;
            double outputMaxWidth = 0.0;

            foreach (MarkerNode mNode in mNodes) {
                textLayout.Text = mNode.compatible.ToString();
                mNode.Height = textLayout.GetSize().Height;
                Point pos = mNode.Bounds.Location;
                if (mNode.IsInput) {
                    pos.X = mNode.Bounds.Right + contentOffset.X;
                    if (pos.X - bound.X + textLayout.GetSize().Width > inputMaxWidth) {
                        inputMaxWidth = pos.X - bound.X + textLayout.GetSize().Width;
                    }
                } else {
                    pos.X = mNode.Bounds.Left - contentOffset.X - textLayout.GetSize().Width;
                    if (bound.Right - pos.X > outputMaxWidth) {
                        outputMaxWidth = bound.Right - pos.X;
                    }
                }
                ctx.DrawTextLayout(textLayout, pos);
                ctx.Stroke();

                // resize height of widget if necessary
                if (pos.Y + mNode.Height + NodeInOutSpace.Height > bound.Bottom) {
                    bound.Bottom = pos.Y + mNode.Height + NodeInOutSpace.Height;
                    ret = true;
                }
            }

            // resize width
            double maxWidth = Math.Max(headlineWidth, inputMaxWidth + outputMaxWidth + NodeTextMargin);
            if (maxWidth > bound.Width) {
                bound.Width = maxWidth;
                ret = true;
            }

            return ret;
        }
Exemplo n.º 26
0
        /// <summary>
        /// Draw The legend
        /// </summary>
        /// <param name="ctx">The Drawing Context with on which to draw</param>
        /// <param name="position">The position of the top left of the axis.</param>
        /// <param name="plots">Array of plot objects to appear in the legend.</param>
        /// <param name="scale">if the legend is set to scale, the amount to scale by.</param>
        /// <returns>bounding box</returns>
        public Rectangle Draw(Context ctx, Point position, ArrayList plots, double scale )
        {
            // first of all determine the Font to use in the legend.
            Font textFont;
            if (AutoScaleText) {
                textFont = font_.WithScaledSize (scale);
            }
            else {
                textFont = font_;
            }

            ctx.Save ();

            // determine max width and max height of label strings and
            // count the labels.
            int labelCount = 0;
            int unnamedCount = 0;
            double maxHt = 0;
            double maxWd = 0;
            TextLayout layout = new TextLayout ();
            layout.Font = textFont;

            for (int i=0; i<plots.Count; ++i) {
                if (!(plots[i] is IPlot)) {
                    continue;
                }

                IPlot p = (IPlot)plots[i];

                if (!p.ShowInLegend) {
                    continue;
                }
                string label = p.Label;
                if (label == "") {
                    unnamedCount += 1;
                    label = "Series " + unnamedCount.ToString();
                }
                layout.Text = label;
                Size labelSize = layout.GetSize ();
                if (labelSize.Height > maxHt) {
                    maxHt = labelSize.Height;
                }
                if (labelSize.Width > maxWd) {
                    maxWd = labelSize.Width;
                }
                ++labelCount;
            }

            bool extendingHorizontally = numberItemsHorizontally_ == -1;
            bool extendingVertically = numberItemsVertically_ == -1;

            // determine width in legend items count units.
            int widthInItemCount = 0;
            if (extendingVertically) {
                if (labelCount >= numberItemsHorizontally_) {
                    widthInItemCount = numberItemsHorizontally_;
                }
                else {
                    widthInItemCount = labelCount;
                }
            }
            else if (extendingHorizontally) {
                widthInItemCount = labelCount / numberItemsVertically_;
                if (labelCount % numberItemsVertically_ != 0)
                    widthInItemCount += 1;
            }
            else {
                throw new NPlotException( "logic error in legend base" );
            }

            // determine height of legend in items count units.
            int heightInItemCount = 0;
            if (extendingHorizontally) {
                if (labelCount >= numberItemsVertically_) {
                    heightInItemCount = numberItemsVertically_;
                }
                else {
                    heightInItemCount = labelCount;
                }
            }
            else {		// extendingVertically
                heightInItemCount = labelCount / numberItemsHorizontally_;
                if (labelCount % numberItemsHorizontally_ != 0)
                    heightInItemCount += 1;
            }

            double lineLength = 20;
            double hSpacing = (int)(5.0f * scale);
            double vSpacing = (int)(3.0f * scale);
            double boxWidth = (int) ((float)widthInItemCount * (lineLength + maxWd + hSpacing * 2.0f ) + hSpacing);
            double boxHeight = (int)((float)heightInItemCount * (maxHt + vSpacing) + vSpacing);

            double totalWidth = boxWidth;
            double totalHeight = boxHeight;

            // draw box around the legend.
            if (BorderStyle == BorderType.Line) {
                ctx.SetColor (bgColor_);
                ctx.Rectangle (position.X, position.Y, boxWidth, boxHeight);
                ctx.FillPreserve ();
                ctx.SetColor (borderColor_);
                ctx.Stroke ();
            }
            else if (BorderStyle == BorderType.Shadow) {
                double offset = (4.0 * scale);
                Color shade = Colors.Gray;
                shade.Alpha = 0.5;
                ctx.SetColor (Colors.Gray);
                ctx.Rectangle (position.X+offset, position.Y+offset, boxWidth, boxHeight);
                ctx.Fill ();
                ctx.SetColor (bgColor_);
                ctx.Rectangle (position.X, position.Y, boxWidth, boxHeight);
                ctx.FillPreserve ();
                ctx.SetColor (borderColor_);
                ctx.Stroke ();

                totalWidth += offset;
                totalHeight += offset;
            }

            /*
               else if ( this.BorderStyle == BorderType.Curved )
               {
                   // TODO. make this nice.
               }
            */
            else {
                // do nothing.
            }

            // now draw entries in box..
            labelCount = 0;
            unnamedCount = 0;

            int plotCount = -1;
            for (int i=0; i<plots.Count; ++i) {
                if (!(plots[i] is IPlot)) {
                    continue;
                }

                IPlot p = (IPlot)plots[i];

                if (!p.ShowInLegend) {
                    continue;
                }

                plotCount += 1;

                double xpos, ypos;
                if (extendingVertically) {
                    xpos = plotCount % numberItemsHorizontally_;
                    ypos = plotCount / numberItemsHorizontally_;
                }
                else {
                    xpos = plotCount / numberItemsVertically_;
                    ypos = plotCount % numberItemsVertically_;
                }

                double lineXPos = (position.X + hSpacing + xpos * (lineLength + maxWd + hSpacing * 2.0));
                double lineYPos = (position.Y + vSpacing + ypos * (vSpacing + maxHt));
                p.DrawInLegend (ctx, new Rectangle (lineXPos, lineYPos, lineLength, maxHt));

                double textXPos = lineXPos + hSpacing + lineLength;
                double textYPos = lineYPos;
                string label = p.Label;
                if (label == "") {
                    unnamedCount += 1;
                    label = "Series " + unnamedCount.ToString();
                }

                layout.Text = label;
                ctx.DrawTextLayout (layout, textXPos, textYPos);

                ++labelCount;
            }
            ctx.Restore ();
            return new Rectangle (position.X, position.Y, totalWidth, totalHeight);
        }
Exemplo n.º 27
0
        static void Draw(Context ctx, LogLevel level, Color color)
        {
            using (TextLayout text = new TextLayout()) {
                text.Text = level.ToString();

                double height = text.GetSize().Height;

                ctx.SetColor(color);
                ctx.RoundRectangle(0, 1, height - 2, height - 2, 3);
                ctx.Fill();

                // inner shadow
                ctx.RoundRectangle(0, 1, height - 2, height - 2, 3);
                LinearGradient g = new LinearGradient(1, 2, height - 2, height - 2);
                g.AddColorStop(0, Colors.Black.BlendWith(color, 0.7));
                g.AddColorStop(1, color);
                ctx.Pattern = g;
                ctx.Fill();

                ctx.SetColor(Colors.Black);
                ctx.DrawTextLayout(text, new Point(height + 3, 0));
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Draw a tick on the axis.
        /// </summary>
        /// <param name="ctx">The Drawing Context with on which to draw.</param>
        /// <param name="w">The tick position in world coordinates.</param>
        /// <param name="size">The size of the tick (in pixels)</param>
        /// <param name="text">The text associated with the tick</param>
        /// <param name="textOffset">The Offset to draw from the auto calculated position</param>
        /// <param name="axisPhysMin">The minimum physical extent of the axis</param>
        /// <param name="axisPhysMax">The maximum physical extent of the axis</param>
        /// <param name="boundingBox">out: The bounding rectangle for the tick and tickLabel drawn</param>
        /// <param name="labelOffset">out: offset from the axies required for axis label</param>
        public virtual void DrawTick( 
			Context ctx, 
			double w,
			double size,
			string text,
			Point textOffset,
			Point axisPhysMin,
			Point axisPhysMax,
			out Point labelOffset,
			out Rectangle boundingBox )
        {
            // determine physical location where tick touches axis.
            Point tickStart = WorldToPhysical (w, axisPhysMin, axisPhysMax, true);

            // determine offset from start point.
            Point  axisDir = Utils.UnitVector (axisPhysMin, axisPhysMax);

            // rotate axisDir anti-clockwise by TicksAngle radians to get tick direction. Note that because
            // the physical (pixel) origin is at the top left, a RotationTransform by a positive angle will
            // be clockwise.  Consequently, for anti-clockwise rotations, use cos(A-B), sin(A-B) formulae
            double x1 = Math.Cos (TicksAngle) * axisDir.X + Math.Sin (TicksAngle) * axisDir.Y;
            double y1 = Math.Cos (TicksAngle) * axisDir.Y - Math.Sin (TicksAngle) * axisDir.X;

            // now get the scaled tick vector.
            Point tickVector = new Point (TickScale * size * x1, TickScale * size * y1);

            if (TicksCrossAxis) {
                tickStart.X -= tickVector.X / 2;
                tickStart.Y -= tickVector.Y / 2;
            }

            // and the end point [point off axis] of tick mark.
            Point  tickEnd = new Point (tickStart.X + tickVector.X, tickStart.Y + tickVector.Y);

            // and draw it
            ctx.SetLineWidth (1);
            ctx.SetColor (LineColor);
            ctx.MoveTo (tickStart.X+0.5, tickStart.Y+0.5);
            ctx.LineTo (tickEnd.X+0.5, tickEnd.Y+0.5);
            ctx.Stroke ();

            // calculate bounds of tick.
            double minX = Math.Min (tickStart.X, tickEnd.X);
            double minY = Math.Min (tickStart.Y, tickEnd.Y);
            double maxX = Math.Max (tickStart.X, tickEnd.X);
            double maxY = Math.Max (tickStart.Y, tickEnd.Y);
            boundingBox = new Rectangle (minX, minY, maxX-minX, maxY-minY);

            // by default, label offset from axis is 0. TODO: revise this.
            labelOffset = new Point (-tickVector.X, -tickVector.Y);

            // ------------------------

            // now draw associated text.

            // **** TODO ****
            // The following code needs revising. A few things are hard coded when
            // they should not be. Also, angled tick text currently just works for
            // the bottom x-axis. Also, it's a bit hacky.

            if (text != "" && !HideTickText) {
                TextLayout layout = new TextLayout ();
                layout.Font = tickTextFontScaled;
                layout.Text = text;
                Size textSize = layout.GetSize ();

                // determine the center point of the tick text.
                double textCenterX;
                double textCenterY;

                // if text is at pointy end of tick.
                if (!TickTextNextToAxis) {
                    // offset due to tick.
                    textCenterX = tickStart.X + tickVector.X*1.2;
                    textCenterY = tickStart.Y + tickVector.Y*1.2;

                    // offset due to text box size.
                    textCenterX += 0.5 * x1 * textSize.Width;
                    textCenterY += 0.5 * y1 * textSize.Height;
                }
                    // else it's next to the axis.
                else {
                    // start location.
                    textCenterX = tickStart.X;
                    textCenterY = tickStart.Y;

                    // offset due to text box size.
                    textCenterX -= 0.5 * x1 * textSize.Width;
                    textCenterY -= 0.5 * y1 * textSize.Height;

                    // bring text away from the axis a little bit.
                    textCenterX -= x1*(2.0+FontScale);
                    textCenterY -= y1*(2.0+FontScale);
                }

                // If tick text is angled..
                if (TickTextAngle != 0) {

                    // determine the point we want to rotate text about.
                    Point textScaledTickVector = new Point (
                                                TickScale * x1 * (textSize.Height/2),
                                                TickScale * y1 * (textSize.Height/2) );
                    Point rotatePoint;
                    if (TickTextNextToAxis) {
                        rotatePoint = new Point (
                                            tickStart.X - textScaledTickVector.X,
                                            tickStart.Y - textScaledTickVector.Y);
                    }
                    else {
                        rotatePoint = new Point (
                                            tickEnd.X + textScaledTickVector.X,
                                            tickEnd.Y + textScaledTickVector.Y);
                    }

                    double actualAngle;
                    if (FlipTickText) {
                        double radAngle = TickTextAngle * Math.PI / 180;
                        rotatePoint.X += textSize.Width * Math.Cos (radAngle);
                        rotatePoint.Y += textSize.Width * Math.Sin (radAngle);
                        actualAngle = TickTextAngle + 180;
                    }
                    else {
                        actualAngle = TickTextAngle;
                    }

                    ctx.Save ();

                    ctx.Translate (rotatePoint.X, rotatePoint.Y);
                    ctx.Rotate (actualAngle);

                    Point [] recPoints = new Point [2];
                    recPoints[0] = new Point (0.0, -textSize.Height/2);
                    recPoints[1] = new Point (textSize.Width, textSize.Height);
                    ctx.TransformPoints (recPoints);

                    double t_x1 = Math.Min (recPoints[0].X, recPoints[1].X);
                    double t_x2 = Math.Max (recPoints[0].X, recPoints[1].X);
                    double t_y1 = Math.Min (recPoints[0].Y, recPoints[1].Y);
                    double t_y2 = Math.Max (recPoints[0].Y, recPoints[1].Y);

                    boundingBox = Rectangle.Union (boundingBox, new Rectangle (t_x1, t_y1, (t_x2-t_x1), (t_y2-t_y1)));

                    ctx.DrawTextLayout (layout, 0, -textSize.Height/2);

                    t_x2 -= tickStart.X;
                    t_y2 -= tickStart.Y;
                    t_x2 *= 1.25;
                    t_y2 *= 1.25;

                    labelOffset = new Point (t_x2, t_y2);

                    ctx.Restore ();

                    //ctx.Rectangle (boundingBox.X, boundingBox.Y, boundingBox.Width, boundingBox.Height);
                    //ctx.Stroke ();

                }
                else 				{
                    double bx1 = (textCenterX - textSize.Width/2);
                    double by1 = (textCenterY - textSize.Height/2);
                    double bx2 = textSize.Width;
                    double by2 = textSize.Height;

                    Rectangle drawRect = new Rectangle (bx1, by1, bx2, by2);
                    // ctx.Rectangle (drawRect);

                    boundingBox = Rectangle.Union (boundingBox, drawRect);

                    // ctx.Rectangle (boundingBox);

                    ctx.DrawTextLayout (layout, bx1, by1);

                    textCenterX -= tickStart.X;
                    textCenterY -= tickStart.Y;
                    textCenterX *= 2.3;
                    textCenterY *= 2.3;

                    labelOffset = new Point (textCenterX, textCenterY);
                }
            }
        }
Exemplo n.º 29
0
 /// <summary>
 /// Draw a information on the ListView2Item
 /// </summary>
 /// <param name="What">What should be drawed</param>
 /// <param name="Where">Where (position by X) should be drawed</param>
 /// <param name="On">On what Drawing.Context the information should be drawed</param>
 /// <param name="MaxWidth">The limit of the picture's width</param>
 /// <param name="TextColor">The text foreground color</param>
 /// <param name="WhatFont">Which font is used to draw the onject</param>
 private void Draw(object What, double Where, Context On, double MaxWidth, Color TextColor, Font WhatFont)
 {
     if (What.GetType() != typeof (Image)
         &&
         What.GetType() != typeof (DirItem))
     {
         TextLayout tl = new TextLayout(this)
         {
             Text = What.ToString(),
             Font = WhatFont,
             Width = MaxWidth,
             Trimming = TextTrimming.WordElipsis
         };
         On.SetColor (TextColor);
         On.DrawTextLayout(tl, Where + 4, 0);
     }
     if (What is Image)
     {
         On.DrawImage(What as Image, Where + 2, 0);
     }
 }
Exemplo n.º 30
0
        public virtual void Texts(Xwt.Drawing.Context ctx, double x, double y)
        {
            ctx.Save();

            ctx.Translate(x, y);

            ctx.SetColor(Colors.Black);

            var col1 = new Rectangle();
            var col2 = new Rectangle();

            var text = new TextLayout();

            text.Font = this.Font.WithSize(24);
            Console.WriteLine(text.Font.Size);

            // first text
            text.Text = "Lorem ipsum dolor sit amet,";
            var size1 = text.GetSize();

            col1.Width   = size1.Width;
            col1.Height += size1.Height + 10;
            ctx.DrawTextLayout(text, 0, 0);


            // proofing width; test should align with text above
            ctx.SetColor(Colors.DarkMagenta);
            text.Text  = "consetetur sadipscing elitr, sed diam nonumy";
            text.Width = col1.Width;
            var size2 = text.GetSize();

            ctx.DrawTextLayout(text, 0, col1.Bottom);
            col1.Height += size2.Height + 10;

            ctx.SetColor(Colors.Black);

            // proofing scale, on second col
            ctx.Save();
            ctx.SetColor(Colors.Red);
            col2.Left = col1.Right + 10;

            text.Text = "eirmod tempor invidunt ut.";

            var scale = 1.2;

            text.Width = text.Width / scale;
            var size3 = text.GetSize();

            col2.Height = size3.Height * scale;
            col2.Width  = size3.Width * scale + 5;
            ctx.Scale(scale, scale);
            ctx.DrawTextLayout(text, col2.Left / scale, col2.Top / scale);
            ctx.Restore();

            // proofing heigth, on second col
            ctx.Save();
            ctx.SetColor(Colors.DarkCyan);
            text.Text = "Praesent ac lacus nec dolor pulvinar feugiat a id elit.";
            var size4 = text.GetSize();

            text.Height   = size4.Height / 2;
            text.Trimming = TextTrimming.WordElipsis;
            ctx.DrawTextLayout(text, col2.Left, col2.Bottom + 5);

            ctx.SetLineWidth(1);
            ctx.SetColor(Colors.Blue);
            ctx.Rectangle(new Rectangle(col2.Left, col2.Bottom + 5, text.Width, text.Height));
            ctx.Stroke();
            ctx.Restore();

            // drawing col line
            ctx.SetLineWidth(1);

            ctx.SetColor(Colors.Black.WithAlpha(.5));
            ctx.MoveTo(col1.Right + 5, col1.Top);
            ctx.LineTo(col1.Right + 5, col1.Bottom);
            ctx.Stroke();
            ctx.MoveTo(col2.Right + 5, col2.Top);
            ctx.LineTo(col2.Right + 5, col2.Bottom);
            ctx.Stroke();
            ctx.SetColor(Colors.Black);

            // proofing rotate, and printing size to see the values
            ctx.Save();

            text.Font = this.Font.WithSize(10);
            text.Text = string.Format("Size 1 {0}\r\nSize 2 {1}\r\nSize 3 {2} Scale {3}",
                                      size1, size2, size3, scale);
            text.Width  = -1;            // this clears textsize
            text.Height = -1;
            ctx.Rotate(5);
            // maybe someone knows a formula with angle and textsize to calculyte ty
            var ty = 30;

            ctx.DrawTextLayout(text, ty, col1.Bottom + 10);

            ctx.Restore();

            // scale example here:

            ctx.Restore();

            TextLayout tl0 = new TextLayout(this);

            tl0.Font = this.Font.WithSize(10);
            tl0.Text = "This text contains attributes.";
            tl0.SetUnderline(0, "This".Length);
            tl0.SetForeground(new Color(0, 1.0, 1.0), "This ".Length, "text".Length);
            tl0.SetBackground(new Color(0, 0, 0), "This ".Length, "text".Length);
            tl0.SetFontWeight(FontWeight.Bold, "This text ".Length, "contains".Length);
            tl0.SetFontStyle(FontStyle.Italic, "This text ".Length, "contains".Length);
            tl0.SetStrikethrough("This text contains ".Length, "attributes".Length);

            ctx.DrawTextLayout(tl0, col2.Left, col2.Bottom + 100);


            // Text boces

            y = 180;

            // Without wrapping

            TextLayout tl = new TextLayout(this);

            tl.Text = "Stright text";
            DrawText(ctx, tl, ref y);

            // With wrapping

            tl       = new TextLayout(this);
            tl.Text  = "The quick brown fox jumps over the lazy dog";
            tl.Width = 100;
            DrawText(ctx, tl, ref y);

            // With blank lines

            tl       = new TextLayout(this);
            tl.Text  = "\nEmpty line above\nLine break above\n\nEmpty line above\n\n\nTwo empty lines above\nEmpty line below\n";
            tl.Width = 200;
            DrawText(ctx, tl, ref y);
        }
Exemplo n.º 31
0
		/// <summary>
		/// Illustrates the use of matrix transforms to skew and reflect text
		/// </summary>
		public void Reflect (Context ctx, double x, double y)
		{
			ctx.Save ();
			ctx.SetLineWidth (1);

			TextLayout layout = new TextLayout ();
			layout.Text = "Reflected and Skewed Text";
			layout.Font = Font.WithSize (16);
			Size size = layout.GetSize ();
			Rectangle r = new Rectangle (Point.Zero, size);

			// Draw text with no transformations at (x+0.5, y+0.5)
			ctx.Translate (x+0.5, y+0.5);	// final move to specified location
			ctx.SetColor (Colors.Blue);
			ctx.DrawTextLayout (layout, 0, 0);

			// Use Matrix transforms to reflect Y-values and skew X-values by -0.5*Y
			// Note that transforms are prepended, so are actioned in reverse order
			// This is the same order that Backend Context transforms are applied

			Matrix m = new Matrix ();				// Identity matrix
			Matrix s = new Matrix (1.0, 0.0,		// new skew matrix
			                      -0.5, 1.0,
			                       0.0, 0.0);

			m.Translate (0, size.Height);			// Shift text back to place
			m.Prepend (s);							// Skew X-values
			m.Scale (1, -1);						// Reflect text Y-values
			m.Translate (0, -size.Height);			// Shift text base to (0,0)

			ctx.ModifyCTM (m);		// NB ctx.Translate (x+0.5, y+0.5) still active

			ctx.SetColor (Colors.DarkGray);
			ctx.Rectangle (r);
			ctx.Fill ();
			ctx.SetColor (Colors.LightBlue);
			ctx.DrawTextLayout (layout, 0, 0);

			ctx.Restore ();
		}