示例#1
0
        void DrawFoldSegment(Xwt.Drawing.Context ctx, double x, double y, bool isOpen, bool isSelected)
        {
            var drawArea = new Rectangle(System.Math.Floor(x + (Width - foldSegmentSize) / 2) + 0.5,
                                         System.Math.Floor(y + (editor.LineHeight - foldSegmentSize) / 2) + 0.5, foldSegmentSize, foldSegmentSize);

            ctx.Rectangle(drawArea);
            ctx.SetSourceColor(isOpen ? foldBgGC : foldToggleMarkerBackground);
            ctx.FillPreserve();
            ctx.SetSourceColor(isSelected ? foldLineHighlightedGC : foldLineGC);
            ctx.Stroke();

            ctx.DrawLine(isSelected ? foldLineHighlightedGC : foldToggleMarkerGC,
                         drawArea.X + drawArea.Width * 2 / 10,
                         drawArea.Y + drawArea.Height / 2,
                         drawArea.X + drawArea.Width - drawArea.Width * 2 / 10,
                         drawArea.Y + drawArea.Height / 2);

            if (!isOpen)
            {
                ctx.DrawLine(isSelected ? foldLineHighlightedGC : foldToggleMarkerGC,
                             drawArea.X + drawArea.Width / 2,
                             drawArea.Y + drawArea.Height * 2 / 10,
                             drawArea.X + drawArea.Width / 2,
                             drawArea.Y + drawArea.Height - drawArea.Height * 2 / 10);
            }
        }
示例#2
0
 protected override void OnDraw(Context ctx)
 {
     ctx.SetLineWidth (5);
     ctx.SetColor (new Color (1.0f, 0f, 0.5f));
     ctx.Rectangle (5, 5, 200, 100);
     ctx.FillPreserve ();
     ctx.SetColor (new Color (0f, 0f, 1f));
     ctx.Stroke ();
 }
示例#3
0
文件: ListView1.cs 项目: nbros/xwt
        protected override void OnDraw(Context ctx, Rectangle cellArea)
        {
            var pct = GetValue (ValueField);
            var size = (cellArea.Width * pct) / 100f;
            cellArea.Width = (int) size;

            ctx.SetLineWidth (1);
            ctx.Rectangle (cellArea.Inflate (-0.5, -0.5));
            ctx.SetColor (Colors.LightBlue);
            ctx.FillPreserve ();
            ctx.SetColor (Colors.Gray);
            ctx.Stroke ();
        }
示例#4
0
        public override bool DrawBackground(TextEditor editor, Xwt.Drawing.Context cr, double y, LineMetrics metrics)
        {
            var caretOffset = editor.Caret.Offset - BaseOffset;

            foreach (var link in mode.Links)
            {
                if (!link.IsEditable)
                {
                    continue;
                }
                bool isPrimaryHighlighted = link.PrimaryLink.Offset <= caretOffset && caretOffset <= link.PrimaryLink.EndOffset;
                foreach (TextSegment segment in link.Links)
                {
                    if ((BaseOffset + segment.Offset <= metrics.TextStartOffset && metrics.TextStartOffset < BaseOffset + segment.EndOffset) || (metrics.TextStartOffset <= BaseOffset + segment.Offset && BaseOffset + segment.Offset < metrics.TextEndOffset))
                    {
                        int strOffset    = BaseOffset + segment.Offset - metrics.TextStartOffset;
                        int strEndOffset = BaseOffset + segment.EndOffset - metrics.TextStartOffset;

                        var x_pos  = metrics.Layout.Layout.IndexToPos(strOffset).X;
                        var x_pos2 = metrics.Layout.Layout.IndexToPos(strEndOffset).X;

                        x_pos  = (int)(x_pos);
                        x_pos2 = (int)(x_pos2);
                        Color fillGc, rectangleGc;
                        if (segment == link.PrimaryLink)
                        {
                            fillGc      = isPrimaryHighlighted ? editor.ColorStyle.PrimaryTemplateHighlighted.SecondColor : editor.ColorStyle.PrimaryTemplate.SecondColor;
                            rectangleGc = isPrimaryHighlighted ? editor.ColorStyle.PrimaryTemplateHighlighted.SecondColor : editor.ColorStyle.PrimaryTemplate.SecondColor;
                        }
                        else
                        {
                            fillGc      = isPrimaryHighlighted ? editor.ColorStyle.SecondaryTemplateHighlighted.SecondColor : editor.ColorStyle.SecondaryTemplate.SecondColor;
                            rectangleGc = isPrimaryHighlighted ? editor.ColorStyle.SecondaryTemplateHighlighted.Color : editor.ColorStyle.SecondaryTemplate.Color;
                        }

                        // Draw segment
                        double x1 = metrics.TextRenderStartPosition + x_pos - 1;
                        double x2 = metrics.TextRenderStartPosition + x_pos2 - 1 + 0.5;

                        cr.Rectangle(x1 + 0.5, y + 0.5, x2 - x1, editor.LineHeight - 1);

                        cr.SetSourceColor(fillGc);
                        cr.FillPreserve();

                        cr.SetSourceColor(rectangleGc);
                        cr.Stroke();
                    }
                }
            }
            return(true);
        }
示例#5
0
		void DrawBookmark (Context cr, double x, double y)
		{
			var color1 = Style.BookmarkColor1;
			var color2 = Style.BookmarkColor2;
			
			DrawRoundRectangle (cr, x + 1, y + 1, 8, Width - 4, Editor.LineHeight - 4);
			using (var pat = new LinearGradient (x + Width / 4, y, x + Width / 2, y + Editor.LineHeight - 4)) {
				pat.AddColorStop (0, color1);
				pat.AddColorStop (1, color2);
				cr.Pattern = pat;
				cr.FillPreserve ();
			}
			
			using (var pat = new LinearGradient (x, y + Editor.LineHeight, x + Width, y)) {
				pat.AddColorStop (0, color2);
				//pat.AddColorStop (1, color1);
				cr.Pattern = pat;
				cr.Stroke ();
			}
		}
示例#6
0
        public virtual void Scale(Context ctx, double ax, double ay)
        {
            ctx.Save ();
            ctx.Translate (ax, ay);
            ctx.SetColor (Colors.Black);
            ctx.SetLineWidth (1);

            var x = 0d;
            var y = 0d;
            var w = 10d;
            var inc = .1d;
            for (var i = inc; i < 3.5d; i +=inc) {
                ctx.Save ();
                ctx.Scale (i, i);
                ctx.Rectangle (x, y, w, w);
                ctx.SetColor (Colors.Yellow.WithAlpha (1 / i));
                ctx.FillPreserve ();
                ctx.SetColor (Colors.Red.WithAlpha (1 / i));
                ctx.Stroke ();
                ctx.MoveTo (x += w * inc, y += w * inc / 3);
                ctx.Restore ();

            }

            ctx.Restore ();
        }
示例#7
0
文件: BasicChart.cs 项目: m13253/xwt
		void DrawCursor (Context ctx, ChartCursor cursor)
		{
			ctx.SetColor (cursor.Color);
			
			double x, y;
			GetPoint (cursor.Value, cursor.Value, out x, out y);
				
			if (cursor.Dimension == AxisDimension.X) {
				double cy = top - AreaBorderWidth - 1;
				ctx.MoveTo (x, cy);
				ctx.LineTo (x + (cursor.HandleSize/2), cy - cursor.HandleSize + 1);
				ctx.LineTo (x - (cursor.HandleSize/2), cy - cursor.HandleSize + 1);
				ctx.ClosePath ();
				if (activeCursor == cursor)
					ctx.FillPreserve ();
				ctx.Stroke ();
				ctx.MoveTo (x, top);
				ctx.RelLineTo (0, height);
				ctx.Stroke ();
			} else {
				throw new NotSupportedException ();
			}
		}
示例#8
0
 /// <summary>
 /// Draws a representation of this plot in the legend.
 /// </summary>
 /// <param name="ctx">The Drawing Context with which to draw.</param>
 /// <param name="r">
 /// A rectangle specifying the bounds of the area in the legend set aside for drawing
 /// </param>
 public void DrawInLegend(Context ctx, Rectangle r)
 {
     ctx.Save ();
     ctx.SetLineWidth (1);
     ctx.Rectangle (r);
     if (Filled) {
         if (FillGradient != null) {
             // Scale FillGradient to bar rectangle
             double sX = r.X + fillGradient.StartPoint.X * r.Width;
             double sY = r.Y + fillGradient.StartPoint.Y * r.Height;
             double eX = r.X + fillGradient.EndPoint.X * r.Width;
             double eY = r.Y + fillGradient.EndPoint.Y * r.Height;
             LinearGradient g = new LinearGradient (sX, sY, eX, eY);
             g.AddColorStop (0, FillGradient.StartColor);
             g.AddColorStop (1, FillGradient.EndColor);
             ctx.Pattern = g;
         } else {
             ctx.SetColor (FillColor);
         }
         ctx.FillPreserve ();
     }
     ctx.SetColor (BorderColor);
     ctx.Stroke ();
     ctx.Restore ();
 }
示例#9
0
 /// <summary>
 /// Draws a representation of this plot in the legend.
 /// </summary>
 /// <param name="g">The graphics surface on which to draw.</param>
 /// <param name="startEnd">A rectangle specifying the bounds of the area in the legend set aside for drawing.</param>
 public virtual void DrawInLegend(Context ctx, Rectangle startEnd)
 {
     double smallerHeight = (startEnd.Height * 0.5);
     //double heightToRemove = (startEnd.Height * 0.5f);
     ctx.Save ();
     ctx.SetColor (fillColor);
     Rectangle newRectangle = new Rectangle (startEnd.Left, startEnd.Top + smallerHeight/2, startEnd.Width, smallerHeight);
     ctx.Rectangle (newRectangle);
     ctx.FillPreserve ();
     ctx.SetColor (borderColor);
     ctx.Stroke ();
     ctx.Restore ();
 }
示例#10
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 ();
        }
示例#11
0
 /// <summary>
 /// Draws a representation of this plot in the legend.
 /// </summary>
 /// <param name="ctx">The Drawing Context with which to draw.</param>
 /// <param name="startEnd">A rectangle specifying the bounds of the area in the legend set aside for drawing.</param>
 public void DrawInLegend(Context ctx, Rectangle startEnd )
 {
     ctx.Save ();
     ctx.Rectangle (startEnd);
     if (Filled) {
         ctx.SetColor (fillColor);
         ctx.FillPreserve ();
     }
     ctx.Stroke ();
     ctx.Restore ();
 }
示例#12
0
        /// <summary>
        /// Draws the histogram.
        /// </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)
        {
            double yoff;
            SequenceAdapter data = new SequenceAdapter (DataSource, DataMember, OrdinateData, AbscissaData);

            ctx.Save ();
            ctx.SetLineWidth (1);

            for (int i=0; i<data.Count; ++i ) {

                // (1) determine the top left hand point of the bar (assuming not centered)
                Point p1 = data[i];
                if (double.IsNaN(p1.X) || double.IsNaN(p1.Y)) {
                    continue;
                }

                // (2) determine the top right hand point of the bar (assuming not centered)
                Point p2 = Point.Zero;;
                if (i+1 != data.Count) {
                    p2 = data[i+1];
                    if (double.IsNaN(p2.X) || double.IsNaN(p2.Y)) {
                        continue;
                    }
                    p2.Y = p1.Y;
                }
                else if (i != 0) {
                    p2 = data[i-1];
                    if (double.IsNaN(p2.X) || double.IsNaN(p2.Y)) {
                        continue;
                    }
                    double offset = p1.X - p2.X;
                    p2.X = p1.X + offset;
                    p2.Y = p1.Y;
                }
                else {
                    double offset = 1.0;
                    p2.X = p1.X + offset;
                    p2.Y = p1.Y;
                }

                // (3) now account for plots this may be stacked on top of.
                HistogramPlot currentPlot = this;
                yoff = 0.0;
                double yval = 0.0;
                while (currentPlot.isStacked_) {
                    SequenceAdapter stackedToData = new SequenceAdapter (
                        currentPlot.stackedTo_.DataSource,
                        currentPlot.stackedTo_.DataMember,
                        currentPlot.stackedTo_.OrdinateData,
                        currentPlot.stackedTo_.AbscissaData );

                    yval += stackedToData[i].Y;
                    yoff = yAxis.WorldToPhysical (yval, false).Y;
                    p1.Y += stackedToData[i].Y;
                    p2.Y += stackedToData[i].Y;
                    currentPlot = currentPlot.stackedTo_;
                }

                // (4) now account for centering
                if (center_) {
                    double offset = (p2.X - p1.X) / 2.0;
                    p1.X -= offset;
                    p2.X -= offset;
                }

                // (5) now account for BaseOffset (shift of bar sideways).
                p1.X += baseOffset_;
                p2.X += baseOffset_;

                // (6) now get physical coordinates of top two points.
                Point xPos1 = xAxis.WorldToPhysical (p1.X, false);
                Point yPos1 = yAxis.WorldToPhysical (p1.Y, false);
                Point xPos2 = xAxis.WorldToPhysical (p2.X, false);

                if (isStacked_) {
                    currentPlot = this;
                    while (currentPlot.isStacked_) {
                        currentPlot = currentPlot.stackedTo_;
                    }
                    baseWidth_ = currentPlot.baseWidth_;
                }

                double width = xPos2.X - xPos1.X;
                double height;
                if (isStacked_) {
                    height = -yPos1.Y+yoff;
                }
                else {
                    height = -yPos1.Y+yAxis.PhysicalMin.Y;
                }

                double xoff = (1.0 - baseWidth_)/2.0*width;
                Rectangle r = new Rectangle (xPos1.X+xoff, yPos1.Y, width-2*xoff, height);

                ctx.Rectangle (r);
                if (Filled) {
                    if (r.Height != 0 && r.Width != 0) {
                        // room for optimization maybe.
                        ctx.SetColor (fillColor);
                        ctx.FillPreserve ();
                    }
                }
                ctx.SetColor (borderColor);
                ctx.Stroke ();
            }
            ctx.Restore ();
        }
示例#13
0
文件: TabButton.cs 项目: jfreax/BAIMP
        /// <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
                    )
                );
            }
        }
示例#14
0
        /// <summary>
        /// Draws the candle plot with the specified Drawing Context and X,Y axes
        /// </summary>
        /// <param name="ctx">The Drawing Context with which to draw</param>
        /// <param name="xAxis">The physical X-Axis to draw against</param>
        /// <param name="yAxis">The physical Y-Axis to draw against</param>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            CandleDataAdapter cd = new CandleDataAdapter (DataSource, DataMember,
                AbscissaData, OpenData, LowData, HighData, CloseData);

            double offset = 0;
            if (Centered) {
                offset = CalculatePhysicalSeparation (cd,xAxis)/2;
            }

            double addAmount = StickWidth/2;
            double stickWidth = StickWidth;

            if (StickWidth == AutoScaleStickWidth) {
                // default
                addAmount = 2;
                stickWidth = 4;

                double minDist = CalculatePhysicalSeparation (cd, xAxis);

                addAmount = minDist / 3;
                stickWidth = addAmount * 2;
            }

            ctx.Save ();
            ctx.SetLineWidth (1);

            /*
            // brant hyatt proposed.
            if (Style == Styles.Stick)
            {
                p.Width = stickWidth;
                addAmount = stickWidth + 2;
            }
            */

            for (int i=0; i<cd.Count; ++i) {

                PointOLHC point = (PointOLHC)cd [i];
                if ((!double.IsNaN (point.Open)) && (!double.IsNaN(point.High))
                 && (!double.IsNaN (point.Low)) && (!double.IsNaN(point.Close))) {
                    double xPos = (xAxis.WorldToPhysical (point.X, false)).X;

                    if (xPos + offset + addAmount < xAxis.PhysicalMin.X || xAxis.PhysicalMax.X < xPos + offset - addAmount) {
                        continue;
                    }

                    double yLo  = (yAxis.WorldToPhysical (point.Low,  false)).Y;
                    double yHi  = (yAxis.WorldToPhysical (point.High, false)).Y;
                    double yOpn = (yAxis.WorldToPhysical (point.Open, false)).Y;
                    double yCls = (yAxis.WorldToPhysical (point.Close,false)).Y;

                    if (Style == Styles.Stick) {
                        /*
                        // brant hyatt proposed.
                        if (i > 0)
                        {
                            if ( ((PointOLHC)cd[i]).Close > ((PointOLHC)cd[i-1]).Close)
                            {
                                p.Color = BullishColor;
                            }
                            else
                            {
                                p.Color = BearishColor;
                            }
                        }
                        */
                        ctx.SetColor (Color);
                        ctx.MoveTo (xPos+offset, yLo);
                        ctx.LineTo (xPos+offset, yHi);		// Low to High line

                        ctx.MoveTo (xPos-addAmount+offset, yOpn);
                        ctx.LineTo (xPos+offset, yOpn);		// Open line

                        ctx.MoveTo (xPos+addAmount+offset, yCls);
                        ctx.LineTo (xPos+offset, yCls);		// Close line
                        ctx.Stroke ();
                    }
                    else if (Style == Styles.Filled) {
                        ctx.MoveTo (xPos+offset, yLo);
                        ctx.LineTo (xPos+offset, yHi);
                        ctx.Stroke ();
                        if (yOpn > yCls) {
                            ctx.SetColor (BullishColor);
                            ctx.Rectangle (xPos-addAmount+offset, yCls, stickWidth, yOpn - yCls);
                            ctx.FillPreserve ();
                            ctx.SetColor (Color);
                            ctx.Stroke ();
                        }
                        else if (yOpn < yCls) {
                            ctx.SetColor (BearishColor);
                            ctx.Rectangle (xPos-addAmount+offset, yOpn, stickWidth, yCls - yOpn);
                            ctx.FillPreserve ();
                            ctx.SetColor (Color);
                            ctx.Stroke ();
                        }
                        else {	// Cls == Opn
                            ctx.MoveTo (xPos-addAmount+offset, yOpn);
                            ctx.LineTo (xPos-addAmount+stickWidth+offset, yCls);
                            ctx.Stroke ();
                        }
                    }
                }
            }
            ctx.Restore ();
        }
示例#15
0
文件: Marker.cs 项目: hwthomas/XwPlot
        /// <summary>
        /// Draws the marker at the given position
        /// </summary>
        /// <param name="ctx">The Drawing Context with which to draw.</param>
        /// <param name="x">The [physical] x position to draw the marker.</param>
        /// <param name="y">The [physical] y position to draw the marker.</param>
        public void Draw(Context ctx, double x, double y )
        {
            ctx.Save ();
            ctx.SetLineWidth (lineWidth);
            ctx.SetColor (lineColor);

            switch (markerType) {
            case MarkerType.Cross1:
                ctx.MoveTo (x-h, y+h);
                ctx.LineTo (x+h, y-h);
                ctx.MoveTo (x+h, y+h);
                ctx.LineTo (x-h, y-h);
                ctx.Stroke ();
                break;

            case MarkerType.Cross2:
                ctx.MoveTo (x, y-h);
                ctx.LineTo (x, y+h);
                ctx.MoveTo (x-h, y);
                ctx.LineTo (x+h, y);
                ctx.Stroke ();
                break;

            case MarkerType.Circle:
                ctx.MoveTo (x+h,y);
                ctx.Arc (x, y, h, 0, 360);
                ctx.ClosePath ();
                if (filled ) {
                    ctx.SetColor (fillColor);
                    ctx.FillPreserve ();
                }
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.Square:
                ctx.Rectangle (x-h, y-h, size, size);
                ctx.ClosePath ();
                if (filled) {
                    ctx.SetColor (fillColor);
                    ctx.FillPreserve ();
                }
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.Triangle:
                ctx.MoveTo (x-h, y+h);
                ctx.LineTo (x, y-h);
                ctx.LineTo (x+h, y+h);
                ctx.ClosePath ();
                if (filled) {
                    ctx.SetColor (fillColor);
                    ctx.FillPreserve ();
                }
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.TriangleDown:
                ctx.MoveTo (x-h, y-h);
                ctx.LineTo (x, y+h);
                ctx.LineTo (x+h, y-h);
                ctx.ClosePath ();
                if (filled) {
                    ctx.SetColor (fillColor);
                    ctx.FillPreserve ();
                }
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.FilledCircle:
                ctx.MoveTo (x+h,y);
                ctx.Arc (x, y, h, 0, 360);
                ctx.ClosePath ();
                ctx.SetColor (fillColor);
                ctx.FillPreserve ();
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.FilledSquare:
                ctx.Rectangle (x-h, y-h, size, size);
                ctx.ClosePath ();
                ctx.SetColor (fillColor);
                ctx.FillPreserve ();
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.FilledTriangle:
                ctx.MoveTo (x-h, y+h);
                ctx.LineTo (x, y-h);
                ctx.LineTo (x+h, y+h);
                ctx.ClosePath ();
                ctx.SetColor (fillColor);
                ctx.FillPreserve ();
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.Diamond:
                ctx.MoveTo (x-h, y);
                ctx.LineTo (x, y-h);
                ctx.LineTo (x+h, y);
                ctx.LineTo (x, y+h);
                ctx.ClosePath ();
                if (filled) {
                    ctx.SetColor (fillColor);
                    ctx.FillPreserve ();
                }
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.Flag:
                ctx.MoveTo (x, y-size);
                ctx.LineTo (x+size, y-size+size/3);
                ctx.LineTo (x, y-size+2*size/3);
                ctx.ClosePath ();
                ctx.MoveTo (x, y);
                ctx.LineTo (x, y-size);
                if (filled) {
                    ctx.SetColor (fillColor);
                    ctx.FillPreserve ();
                }
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.FlagDown:
                ctx.MoveTo (x, y+size);
                ctx.LineTo (x+size, y+size-size/3);
                ctx.LineTo (x, y+size-2*size/3);
                ctx.ClosePath ();
                ctx.MoveTo (x, y);
                ctx.LineTo (x, y+size);
                if (filled) {
                    ctx.SetColor (fillColor);
                    ctx.FillPreserve ();
                }
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.FilledFlag:
                ctx.MoveTo (x, y-size);
                ctx.LineTo (x+size, y-size+size/3);
                ctx.LineTo (x, y-size+2*size/3);
                ctx.ClosePath ();
                ctx.MoveTo (x, y);
                ctx.LineTo (x, y-size);
                ctx.SetColor (fillColor);
                ctx.FillPreserve ();
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.None:
                    break;
            }
            ctx.Restore ();
        }
示例#16
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);
        }
示例#17
0
        /// <summary>
        /// Draws the histogram.
        /// </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)
        {
            double yoff;
            SequenceAdapter data = new SequenceAdapter (DataSource, DataMember, OrdinateData, AbscissaData);

            ctx.Save ();
            ctx.SetLineWidth (1);

            for (int i=0; i<data.Count; ++i ) {

                // (1) determine the top left hand point of the bar (assuming not centered)
                Point p1 = data[i];
                if (double.IsNaN(p1.X) || double.IsNaN(p1.Y)) {
                    continue;
                }

                // (2) determine the top right hand point of the bar (assuming not centered)
                Point p2 = Point.Zero;;
                if (i+1 != data.Count) {
                    p2 = data[i+1];
                    if (double.IsNaN(p2.X) || double.IsNaN(p2.Y)) {
                        continue;
                    }
                    p2.Y = p1.Y;
                }
                else if (i != 0) {
                    p2 = data[i-1];
                    if (double.IsNaN(p2.X) || double.IsNaN(p2.Y)) {
                        continue;
                    }
                    double offset = p1.X - p2.X;
                    p2.X = p1.X + offset;
                    p2.Y = p1.Y;
                }
                else {
                    double offset = 1.0;
                    p2.X = p1.X + offset;
                    p2.Y = p1.Y;
                }

                // (3) now account for plots this may be stacked on top of.
                HistogramPlot currentPlot = this;
                yoff = 0.0;
                double yval = 0.0;
                while (currentPlot.IsStacked) {
                    SequenceAdapter stackedToData = new SequenceAdapter (
                        currentPlot.stackedTo.DataSource,
                        currentPlot.stackedTo.DataMember,
                        currentPlot.stackedTo.OrdinateData,
                        currentPlot.stackedTo.AbscissaData );

                    yval += stackedToData[i].Y;
                    yoff = yAxis.WorldToPhysical (yval, false).Y;
                    p1.Y += stackedToData[i].Y;
                    p2.Y += stackedToData[i].Y;
                    currentPlot = currentPlot.stackedTo;
                }

                // (4) now account for centering
                if (Center) {
                    double offset = (p2.X - p1.X) / 2.0;
                    p1.X -= offset;
                    p2.X -= offset;
                }

                // (5) now account for BaseOffset (shift of bar sideways).
                p1.X += BaseOffset;
                p2.X += BaseOffset;

                // (6) now get physical coordinates of top two points.
                Point xPos1 = xAxis.WorldToPhysical (p1.X, false);
                Point yPos1 = yAxis.WorldToPhysical (p1.Y, false);
                Point xPos2 = xAxis.WorldToPhysical (p2.X, false);

                if (IsStacked) {
                    currentPlot = this;
                    while (currentPlot.IsStacked) {
                        currentPlot = currentPlot.stackedTo;
                    }
                    baseWidth = currentPlot.baseWidth;
                }

                double width = xPos2.X - xPos1.X;
                double height;
                if (IsStacked) {
                    height = -yPos1.Y+yoff;
                }
                else {
                    height = -yPos1.Y+yAxis.PhysicalMin.Y;
                }

                double xoff = (1.0 - baseWidth)/2.0*width;
                Rectangle bar = new Rectangle (xPos1.X+xoff, yPos1.Y, width-2*xoff, height);

                ctx.Rectangle (bar);
                if (Filled) {
                    if (bar.Height != 0 && bar.Width != 0) {
                        if (FillGradient != null) {
                            // Scale FillGradient to bar rectangle
                            double sX = bar.X + fillGradient.StartPoint.X * bar.Width;
                            double sY = bar.Y + fillGradient.StartPoint.Y * bar.Height;
                            double eX = bar.X + fillGradient.EndPoint.X * bar.Width;
                            double eY = bar.Y + fillGradient.EndPoint.Y * bar.Height;
                            LinearGradient g = new LinearGradient (sX, sY, eX, eY);
                            g.AddColorStop (0, FillGradient.StartColor);
                            g.AddColorStop (1, FillGradient.EndColor);
                            ctx.Pattern = g;
                        } else {
                            ctx.SetColor (FillColor);
                        }
                        ctx.FillPreserve ();
                    }
                }
                ctx.SetColor (BorderColor);
                ctx.Stroke ();
            }
            ctx.Restore ();
        }
示例#18
0
        protected override void OnDraw(Context ctx, Rectangle cellArea)
        {
            ctx.Rectangle (BackgroundBounds);
            ctx.SetColor (new Color (0.9, 0.9, 0.9));
            ctx.Fill ();

            ctx.Rectangle (Bounds);
            ctx.SetColor (new Color (0.7, 0.7, 0.7));
            ctx.Fill ();

            var pct = GetValue (ValueField);
            var size = (cellArea.Width * pct.Value) / 100f;
            cellArea.Width = (int) size;

            ctx.SetLineWidth (1);
            ctx.Rectangle (cellArea.Inflate (-0.5, -0.5));
            ctx.SetColor (Selected ? Colors.Blue : Colors.LightBlue);
            ctx.FillPreserve ();
            ctx.SetColor (Colors.Gray);
            ctx.Stroke ();

            if (pct.YPos != -1) {
                ctx.MoveTo (cellArea.Right, Bounds.Y + pct.YPos);
                ctx.Arc (cellArea.Right, Bounds.Y + pct.YPos, 2.5, 0, 360);
                ctx.SetColor (Colors.Red);
                ctx.Fill ();
            }
        }
示例#19
0
        /// <summary>
        /// Draws the line plot using the Drawing Context and x and y axes provided
        /// </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)
        {
            SequenceAdapter dataTop = new SequenceAdapter (DataSource, DataMember, OrdinateDataTop, AbscissaData);
            SequenceAdapter dataBottom = new SequenceAdapter (DataSource, DataMember, OrdinateDataBottom, AbscissaData);

            ITransform2D t = Transform2D.GetTransformer (xAxis, yAxis);

            ctx.Save ();
            for (int i=0; i<dataTop.Count; ++i) {
                Point physicalBottom = t.Transform (dataBottom[i]);
                Point physicalTop = t.Transform (dataTop[i]);

                if (physicalBottom != physicalTop) {
                    Rectangle r = new Rectangle (physicalBottom.X - BarWidth/2, physicalTop.Y,BarWidth, (physicalBottom.Y - physicalTop.Y) );
                    ctx.SetColor (fillColor);
                    ctx.Rectangle (r);
                    ctx.FillPreserve ();
                    ctx.SetColor (borderColor);
                    ctx.Stroke ();
                }
            }
            ctx.Restore ();
        }