GetSize() public method

measures the text if Width is other than -1, it measures the height according to Width Height is ignored
public GetSize ( ) : Size
return Size
Ejemplo n.º 1
0
		internal protected override void OptionsChanged ()
		{
			var layout = new TextLayout (Editor);
			layout.Font = Editor.Options.Font;
			layout.Text = ".";
//			int height;
			charWidth = layout.GetSize ().Width;
			layout.Dispose ();
		}
Ejemplo n.º 2
0
		internal protected override void OptionsChanged ()
		{
			var layout = new TextLayout (Editor);
			layout.Font = Editor.Options.Font;
			layout.Text = string.Format ("0{0:X}", Data.Length) + "_";
//			int height;
			width = layout.GetSize ().Width;
			layout.Dispose ();
		}
Ejemplo n.º 3
0
        public LogLevelChooser(LogLevel selectedLogLevel)
        {
            SelectedLogLevel = selectedLogLevel;

            // prerender
            string[] logNames = Enum.GetNames(typeof(LogLevel));
            int length = logNames.Length;
            renderedImage = new Image[length];

            using (TextLayout text = new TextLayout()) {
                for (int i = 0; i < length; i++) {
                    text.Text = logNames[i];
                    Size size = text.GetSize();
                    using (ImageBuilder ib = new ImageBuilder(size.Width + size.Height*2 + 3, size.Height)) {
                        Color color = Color.FromName(Log.LevelToColorString((LogLevel) i));

                        Draw(ib.Context, (LogLevel) i, color);
                        renderedImage[i] = ib.ToBitmap();

                        Button button = new Button { Image = renderedImage[i], ImagePosition = ContentPosition.Left };
                        button.HorizontalPlacement = WidgetPlacement.Start;
                        button.Margin = 0;
                        button.ExpandHorizontal = true;
                        button.Style = ButtonStyle.Flat;
                        buttons.PackStart(button, true, true);

                        button.CanGetFocus = false;
                        button.Tag = i;
                        button.Clicked += OnLogChange;

                        windowHeight += size.Height * 2;
                    }
                }
            }

            // hide window on lost fokus
            buttons.CanGetFocus = true;
            buttons.LostFocus += delegate {
                if (menuHide != null) {
                    menuHide(this, EventArgs.Empty);
                }

                popupWindow.Hide();
            };
            buttons.ButtonPressed += delegate {
                // do nothing
                // workaround to propagate event to each button
            };

            buttons.Spacing = 0;

            popupWindow.Padding = 0;
            popupWindow.ShowInTaskbar = false;
            popupWindow.Decorated = false;
            popupWindow.Content = buttons;
        }
Ejemplo n.º 4
0
		internal protected override void OptionsChanged ()
		{
			var layout = new TextLayout (Editor);
			layout.Font = Editor.Options.Font;
			layout.Text = "!";
//			int tmp;
			this.marginWidth = layout.GetSize ().Height;
			marginWidth *= 12;
			marginWidth /= 10;
			layout.Dispose ();
		}
Ejemplo n.º 5
0
		internal protected override void OptionsChanged ()
		{
			var layout = new TextLayout (Editor);
			layout.Font = Editor.Options.Font;
			string groupString = new string ('0', Editor.Options.GroupBytes * 2);
			layout.Text = groupString + " ";
			double lineHeight;
			var sz = layout.GetSize ();
			groupWidth = sz.Width;
			lineHeight = sz.Height;
			 
			Data.LineHeight = lineHeight;
			
			layout.Text = "00";
			byteWidth = layout.GetSize ().Width;

			layout.Dispose ();
			
//			tabArray = new Pango.TabArray (1, true);
//			tabArray.SetTab (0, Pango.TabAlign.Left, groupWidth);
		}
Ejemplo n.º 6
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);
		}
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
		double MeasureTicksSize (Context ctx, TickEnumerator e, AxisDimension ad)
		{
			double max = 0;
			TextLayout layout = new TextLayout ();
			layout.Font = chartFont;
			
			double start = GetStart (ad);
			double end = GetEnd (ad);
			
			e.Init (GetOrigin (ad));
			
			while (e.CurrentValue > start)
				e.MovePrevious ();
			
			for ( ; e.CurrentValue <= end; e.MoveNext ())
			{
				layout.Text = e.CurrentLabel;
				Size ts = layout.GetSize ();
				
				if (ad == AxisDimension.X) {
					if (ts.Height > max)
						max = ts.Height;
				} else {
					if (ts.Width > max)
						max = ts.Width;
				}
			}
			return max;
		}
Ejemplo n.º 9
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);
                    }
                }
            }
        }
		protected override Size OnGetRequiredSize ()
		{
			var layout = new TextLayout ();
			layout.Text = "W";
			layout.Font = layout.Font.WithScaledSize (0.9);
			Size size = layout.GetSize ();
			return new Size (CellWidth, size.Height * linesDisplayedCount + packageDescriptionPaddingHeight + packageDescriptionPadding.VerticalSpacing);
		}
Ejemplo n.º 11
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;
        }
Ejemplo n.º 12
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;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Measures the size of the specified text.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="fontFamily">The font family.</param>
        /// <param name="fontSize">Size of the font (in device independent units, 1/96 inch).</param>
        /// <param name="fontWeight">The font weight.</param>
        /// <returns>The size of the text (in device independent units, 1/96 inch).</returns>
        public override OxySize MeasureText(string text,
                                       string fontFamily,
                                       double fontSize,
                                       double fontWeight)
        {
            if (text == null)
                return OxySize.Empty;

            var layout = new TextLayout ();
            layout.Font = GetCachedFont (fontFamily, fontSize, fontWeight);
            layout.Text = text;

            var size = layout.GetSize ();
            return new OxySize (size.Width, size.Height);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Draws text.
        /// </summary>
        /// <param name="p">The position.</param>
        /// <param name="text">The text.</param>
        /// <param name="fill">The text color.</param>
        /// <param name="fontFamily">The font family.</param>
        /// <param name="fontSize">Size of the font (in device independent units, 1/96 inch).</param>
        /// <param name="fontWeight">The font weight.</param>
        /// <param name="rotate">The rotation angle.</param>
        /// <param name="halign">The horizontal alignment.</param>
        /// <param name="valign">The vertical alignment.</param>
        /// <param name="maxSize">The maximum size of the text (in device independent units, 1/96 inch).</param>
        public override void DrawText(ScreenPoint p,
                                 string text,
                                 OxyColor fill,
                                 string fontFamily,
                                 double fontSize,
                                 double fontWeight,
                                 double rotate,
                                 HorizontalAlignment halign,
                                 VerticalAlignment valign,
                                 OxySize? maxSize)
        {
            Context.Save ();

            var layout = new TextLayout ();
            layout.Font = GetCachedFont (fontFamily, fontSize, fontWeight);
            layout.Text = text;

            var size = layout.GetSize ();
            if (maxSize != null) {
                size.Width = Math.Min (size.Width, maxSize.Value.Width);
                size.Height = Math.Min (size.Height, maxSize.Value.Height);
            }

            double dx = 0;
            if (halign == HorizontalAlignment.Center) {
                dx = -size.Width / 2;
            }

            if (halign == HorizontalAlignment.Right) {
                dx = -size.Width;
            }

            double dy = 0;
            if (valign == VerticalAlignment.Middle) {
                dy = -size.Height / 2;
            }

            if (valign == VerticalAlignment.Bottom) {
                dy = -size.Height;
            }

            Context.Translate (p.X, p.Y);
            if (Math.Abs (rotate) > double.Epsilon) {
                Context.Rotate (rotate);
            }

            Context.Translate (dx, dy);

            Context.SetColor (fill.ToXwtColor ());
            Context.DrawTextLayout (layout, 0, 0);

            Context.Restore ();
        }
Ejemplo n.º 15
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));
            }
        }
Ejemplo n.º 16
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 ();
			}
		}
Ejemplo n.º 17
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 ();
        }
Ejemplo n.º 18
0
        public void DrawTextLayout(object backend, TextLayout layout, double x, double y)
        {
            var c = (DrawingContext)backend;
            Size measure = layout.GetSize ();
            float h = layout.Height > 0 ? (float)layout.Height : (float)measure.Height;
            System.Drawing.StringFormat stringFormat = TextLayoutContext.StringFormat;
            StringTrimming trimming = layout.Trimming.ToDrawingStringTrimming ();

            if (layout.Height > 0 && stringFormat.Trimming != trimming) {
                stringFormat = (System.Drawing.StringFormat)stringFormat.Clone ();
                stringFormat.Trimming = trimming;
            }

            c.Graphics.DrawString (layout.Text, layout.Font.ToDrawingFont (), c.Brush,
                                   new RectangleF ((float)x, (float)y, (float)measure.Width, h),
                                   stringFormat);
        }
Ejemplo n.º 19
0
        public void TextWordWrap()
        {
            // Transform is saved
            InitBlank (100, 100);
            var la = new TextLayout ();
            la.Font = Font.FromName ("Arial 12");
            la.Text = "One Two Three Four Five Six Seven Eight Nine";
            la.Width = 90;
            la.Trimming = TextTrimming.Word;
            var s = la.GetSize ();
            context.Rectangle (5.5, 5.5, s.Width, s.Height);
            context.SetColor (Colors.Blue);
            context.Stroke ();

            context.SetColor (Colors.Black);
            context.DrawTextLayout (la, 5, 5);
            CheckImage ("TextWordWrap.png");
        }
Ejemplo n.º 20
0
        protected override void OnSelectionChanged(EventArgs e)
        {
            if (SelectedRow == null)
                return;

            object value = store.GetNavigatorAt(SelectedRow).GetValue(nameCol);
            if (value is BaseAlgorithm) {

                TextLayout text = new TextLayout();
                text.Text = value.ToString();

                Size textSize = text.GetSize();
                var ib = new ImageBuilder(textSize.Width, textSize.Height);
                ib.Context.DrawTextLayout(text, 0, 0);

                var d = CreateDragOperation();
                d.Data.AddValue(value.GetType().AssemblyQualifiedName);
                d.SetDragImage(ib.ToVectorImage(), -6, -4);
                d.AllowedActions = DragDropAction.Link;
                d.Start();

                d.Finished += (object sender, DragFinishedEventArgs e2) => this.UnselectAll();

                text.Dispose();
                ib.Dispose();
            } else {
                this.UnselectRow(SelectedRow);
            }
        }
Ejemplo n.º 21
0
        void DrawColorProperty(string key, string value, Color c, ParserItem item, bool comma = true)
        {
            if (CanDraw)
            {
                double newX = X;
                if (key != null) {
                    var Item = CreateTextLayout (string.Format ("\"{0}\" : ", key));
                    CTX.DrawTextLayout (Item, X, Y);
                    newX = X + Item.GetSize ().Width;
                }

                if (DrawVisibleProperty == false) {
                    CTX.DrawTextLayout (CreateTextLayout(value), newX, Y);
                    return;
                }

                // Create value
                var Value = new TextLayout();
                Value.Font.WithSize(10);
                Value.Text = value;
                var s = Value.GetSize();
                var rect = new Rectangle(newX, Y, s.Width, s.Height).Inflate(0.2, 0.2);
                CreateClickableItem((double) newX, (double)Y, s.Width, s.Height, item);
                CTX.SetColor(c);
                CTX.Rectangle(rect);
                CTX.Fill();
                CTX.SetLineWidth(1);
                CTX.Stroke();
                CTX.SetColor(Colors.White);
                CTX.DrawTextLayout(Value, newX, Y);
                CTX.SetColor(Colors.Black);

                if (comma)
                {
                    var end = CreateTextLayout(",");
                    CTX.DrawTextLayout(end, newX + s.Width + 8, Y);
                }
            }
        }
Ejemplo n.º 22
0
        public void TextWithBlankLines()
        {
            // Transform is saved
            InitBlank (50, 150);
            var la = new TextLayout ();
            la.Font = Font.FromName ("Arial 12");
            la.Text = "\n\nHello\n\n\nWorld\n\n";

            var s = la.GetSize ();
            context.Rectangle (10.5, 10.5, s.Width, s.Height);
            context.SetColor (Colors.Blue);
            context.Stroke ();

            context.SetColor (Colors.Black);
            context.DrawTextLayout (la, 10, 10);
            CheckImage ("TextWithBlankLines.png");
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Reloads file tree information.
        /// </summary>
        /// <param name="scans">Collection of loaded scans</param>
        /// <param name="currentScan">Current focused scan</param>
        /// <param name="save">Update scan collection</param>
        public void Reload(ScanCollection scans, BaseScan currentScan = null, bool save = true)
        {
            if (scans.Count > 0) {
                scans.Sort(scans[0]);
            }

            if (save) {
                scanCollection = scans;
            }

            DataSource = store;
            store.Clear();

            TreePosition pos = null;
            fiberTypeNodes = new Dictionary<string, TreePosition>();
            foreach (BaseScan scan in scans) {
                TreePosition currentNode;
                if (fiberTypeNodes.ContainsKey(scan.FiberType)) {
                    currentNode = fiberTypeNodes[scan.FiberType];
                } else {
                    TextLayout text = new TextLayout();
                    text.Text = scan.FiberType;
                    ImageBuilder ib = new ImageBuilder(text.GetSize().Width, text.GetSize().Height);
                    ib.Context.DrawTextLayout(text, Point.Zero);

                    currentNode = store.AddNode(null).SetValue(thumbnailCol, ib.ToVectorImage()).CurrentPosition;
                    fiberTypeNodes[scan.FiberType] = currentNode;

                    text.Dispose();
                    ib.Dispose();
                }

                var v = store.AddNode(currentNode)
                    .SetValue(nameCol, scan.ToString())
                    .SetValue(finishCol, scan.IsFinish() ? tick : cross)
                    .SetValue(saveStateCol, scan.HasUnsaved() ? "*" : "")
                    .CurrentPosition;
                scan.position = v;
                scan.parentPosition = currentNode;
                if (currentScan != null) {
                    if (currentScan == scan) {
                        pos = v;
                    }
                } else {
                    if (pos == null) {
                        pos = v;
                    }
                }

                scan.ScanDataChanged += OnScanDataChanged;
            }

            if (scans.Count > 0) {
                ExpandToRow(pos);
                SelectRow(pos);
            }

            LoadPreviewsAsync(scans);
        }
Ejemplo n.º 24
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);
        }
Ejemplo n.º 25
0
        protected override void OnKeyPressed(KeyEventArgs args)
        {
            base.OnKeyPressed(args);
            switch (args.Key) {
            case Key.Delete:
                TreeStore currentStore = DataSource as TreeStore;

                if (currentStore != null) {
                    TreeNavigator selected = currentStore.GetNavigatorAt(SelectedRow);

                    if (selected != null) {
                        Dialog d = new Dialog();
                        d.Title = "Remove this scan";

                        VBox nameList = new VBox();
                        ScrollView nameListScroll = new ScrollView(nameList);

                        foreach (TreePosition selectPos in SelectedRows) {
                            nameList.PackStart(
                                new Label(currentStore.GetNavigatorAt(selectPos)
                                .GetValue(isFiltered ? nameColFilter : nameCol))
                            );
                        }
                        TextLayout text = new TextLayout();
                        text.Text = "M";
                        double textHeight = text.GetSize().Height;
                        text.Dispose();

                        nameListScroll.MinHeight = Math.Min(10, SelectedRows.Length) * textHeight;
                        d.Content = nameListScroll;
                        d.Buttons.Add(new DialogButton(Command.Delete));
                        d.Buttons.Add(new DialogButton(Command.Cancel));

                        Command r = d.Run();
                        if (r != null && r.Id == Command.Delete.Id) {
                            foreach (TreePosition selectPos in SelectedRows) {
                                string name = currentStore.GetNavigatorAt(selectPos)
                                    .GetValue(isFiltered ? nameColFilter : nameCol);
                                if (!string.IsNullOrEmpty(name)) {
                                    currentStore.GetNavigatorAt(selectPos).Remove();

                                    scanCollection.RemoveAll(scan => scan.Name == name);
                                }
                            }
                        }
                        d.Dispose();
                    }
                }
                break;
            }
        }
Ejemplo n.º 26
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);
                }
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Refresh the specified scan.
        /// </summary>
        /// <param name="scan">Scan.</param>
        /// <param name="changedFiberType">Set to true, if the fibertype of the given scan has changed</param>
        void Refresh(BaseScan scan, bool changedFiberType = false)
        {
            Image thumbnail = store.GetNavigatorAt(scan.position).GetValue(thumbnailCol);
            TreePosition currentNode = scan.position;

            if (changedFiberType) {
                TreePosition parentNodePosition;
                if (fiberTypeNodes.ContainsKey(scan.FiberType)) {
                    parentNodePosition = fiberTypeNodes[scan.FiberType];
                } else {

                    TextLayout text = new TextLayout();
                    text.Text = scan.FiberType;
                    ImageBuilder ib = new ImageBuilder(text.GetSize().Width, text.GetSize().Height);
                    ib.Context.DrawTextLayout(text, Point.Zero);

                    parentNodePosition = store.AddNode(null).SetValue(thumbnailCol, ib.ToBitmap()).CurrentPosition;
                    fiberTypeNodes[scan.FiberType] = parentNodePosition;

                    text.Dispose();
                    ib.Dispose();

                }
                store.GetNavigatorAt(currentNode).Remove();
                scan.position = currentNode = store.AddNode(parentNodePosition).CurrentPosition;

                ExpandToRow(scan.position);
                ScrollToRow(scan.position);
                SelectRow(scan.position);

                scan.parentPosition = parentNodePosition;
            }

            store.GetNavigatorAt(currentNode)
                .SetValue(nameCol, scan.ToString())
                .SetValue(thumbnailCol, thumbnail)
                .SetValue(finishCol, scan.IsFinish() ? tick : cross)
                .SetValue(saveStateCol, scan.HasUnsaved() ? "*" : "");

            if (DataSource.GetChildrenCount(scan.parentPosition) <= 0) {
                store.GetNavigatorAt(scan.parentPosition).Remove();
            }

            // update filtered store
            if (!string.IsNullOrEmpty(filterText)) {
                storeFilter.GetNavigatorAt(scan.positionFiltered)
                    .SetValue(nameColFilter, scan.ToString())
                    .SetValue(thumbnailColFilter, thumbnail)
                    .SetValue(finishColFiltered, scan.IsFinish() ? tick : cross)
                    .SetValue(saveStateColFilter, scan.HasUnsaved() ? "*" : "");

                if (changedFiberType) {
                    Filter(filterText);
                }
            }
        }
Ejemplo n.º 28
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.SetColor(Colors.DarkGreen);
            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);
        }
Ejemplo n.º 29
0
        private void DeterminePhysicalAxesToDraw(Rectangle bounds, 
			Axis xAxis1, Axis xAxis2, Axis yAxis1, Axis yAxis2,
			out PhysicalAxis pXAxis1, out PhysicalAxis pXAxis2, 
			out PhysicalAxis pYAxis1, out PhysicalAxis pYAxis2 )
        {
            Rectangle cb = bounds;

            pXAxis1 = new PhysicalAxis (xAxis1,
                new Point (cb.Left, cb.Bottom), new Point (cb.Right, cb.Bottom) );
            pYAxis1 = new PhysicalAxis (yAxis1,
                new Point (cb.Left, cb.Bottom), new Point (cb.Left, cb.Top) );
            pXAxis2 = new PhysicalAxis (xAxis2,
                new Point (cb.Left, cb.Top), new Point (cb.Right, cb.Top) );
            pYAxis2 = new PhysicalAxis (yAxis2,
                new Point (cb.Right, cb.Bottom), new Point (cb.Right, cb.Top) );

            double bottomIndent = padding;
            if (!pXAxis1.Axis.Hidden) {
                // evaluate its bounding box
                Rectangle bb = pXAxis1.GetBoundingBox ();
                // finally determine its indentation from the bottom
                bottomIndent = bottomIndent + bb.Bottom - cb.Bottom;
            }

            double leftIndent = padding;
            if (!pYAxis1.Axis.Hidden) {
                // evaluate its bounding box
                Rectangle bb = pYAxis1.GetBoundingBox();
                // finally determine its indentation from the left
                leftIndent = leftIndent - bb.Left + cb.Left;
            }

            // determine title size
            double scale = DetermineScaleFactor (bounds.Width, bounds.Height);
            Font scaled_font;
            if (AutoScaleTitle) {
                scaled_font = titleFont.WithScaledSize (scale);
            }
            else {
                scaled_font = titleFont;
            }

            Size titleSize;
            using (TextLayout layout = new TextLayout ()) {
                layout.Font = scaled_font;
                layout.Text = Title;
                titleSize = layout.GetSize ();
            };
            double topIndent = padding;

            if (!pXAxis2.Axis.Hidden) {
                // evaluate its bounding box
                Rectangle bb = pXAxis2.GetBoundingBox();
                topIndent = topIndent - bb.Top + cb.Top;

                // finally determine its indentation from the top
                // correct top indendation to take into account plot title
                if (title != "" ) {
                    topIndent += titleSize.Height * 1.3;
                }
            }

            double rightIndent = padding;
            if (!pYAxis2.Axis.Hidden) {
                // evaluate its bounding box
                Rectangle bb = pYAxis2.GetBoundingBox();

                // finally determine its indentation from the right
                rightIndent += (bb.Right-cb.Right);
            }

            // now we have all the default calculated positions and we can proceed to
            // "move" the axes to their right places

            // primary axes (bottom, left)
            pXAxis1.PhysicalMin = new Point( cb.Left+leftIndent, cb.Bottom-bottomIndent );
            pXAxis1.PhysicalMax = new Point( cb.Right-rightIndent, cb.Bottom-bottomIndent );
            pYAxis1.PhysicalMin = new Point( cb.Left+leftIndent, cb.Bottom-bottomIndent );
            pYAxis1.PhysicalMax = new Point( cb.Left+leftIndent, cb.Top+topIndent );

            // secondary axes (top, right)
            pXAxis2.PhysicalMin = new Point( cb.Left+leftIndent, cb.Top+topIndent );
            pXAxis2.PhysicalMax = new Point( cb.Right-rightIndent, cb.Top+topIndent );
            pYAxis2.PhysicalMin = new Point( cb.Right-rightIndent, cb.Bottom-bottomIndent );
            pYAxis2.PhysicalMax = new Point( cb.Right-rightIndent, cb.Top+topIndent );
        }
Ejemplo n.º 30
0
        //void SetAdjustments(Rectangle allocation)
        //{
        //    hadj.SetBounds(0, allocation.Width, 0, 0, allocation.Width);
        //    var height = System.Math.Max(allocation.Height, rowHeight * this.win.DataProvider.Count);
        //    vadj.SetBounds(0, height, rowHeight, allocation.Height, allocation.Height);
        //}

        //FIXME: we could use the expose event's clipbox to make the drawing more efficient
        protected override void OnDraw(Context cr, Rectangle dirtyRect)
        {
            var ypos      = margin;
            var lineWidth = Size.Width - margin * 2;
            int xpos      = margin + padding;

            //avoid recreating the GC objects that we use multiple times
            var textColor = Colors.Black;

            int n = 0;

            n = (int)(vadj.Value / rowHeight);

            while (ypos < Size.Height - margin && n < win.DataProvider.Count)
            {
                bool hasMarkup = false;
                IMarkupListDataProvider <T> markupListDataProvider = win.DataProvider as IMarkupListDataProvider <T>;
                if (markupListDataProvider != null)
                {
                    if (markupListDataProvider.HasMarkup(n))
                    {
                        layout.Markup = (markupListDataProvider.GetMarkup(n) ?? "&lt;null&gt;");
                        hasMarkup     = true;
                    }
                }

                if (!hasMarkup)
                {
                    layout.Text = (win.DataProvider.GetText(n) ?? "<null>");
                }

                var icon = win.DataProvider.GetIcon(n);
                int iconHeight, iconWidth;

                if (icon != null)
                {
                    iconWidth  = (int)icon.Width;
                    iconHeight = (int)icon.Height;
                }
                iconHeight = iconWidth = 24;

                var s = layout.GetSize();
                int typos, iypos;
                int he = (int)s.Height;

                typos = he < rowHeight ? ypos + (rowHeight - he) / 2 : ypos;
                iypos = iconHeight < rowHeight ? ypos + (rowHeight - iconHeight) / 2 : ypos;

                if (n == selection)
                {
                    if (!disableSelection)
                    {
                        cr.Rectangle(margin, ypos, lineWidth, he + padding);
                        cr.SetColor(Colors.DarkOrange);
                        cr.Fill();

                        cr.SetColor(Colors.White);
                        cr.DrawTextLayout(layout, xpos + iconWidth + 2, typos);
                    }
                    else
                    {
                        cr.Rectangle(margin, ypos, lineWidth, he + padding);
                        cr.SetColor(Colors.OrangeRed);
                        cr.Stroke();

                        cr.SetColor(textColor);
                        cr.DrawTextLayout(layout, xpos + iconWidth + 2, typos);
                    }
                }
                else
                {
                    cr.SetColor(textColor);
                    cr.DrawTextLayout(layout, xpos + iconWidth + 2, typos);
                }

                if (icon != null)
                {
                    cr.DrawImage(icon, xpos, iypos);
                }

                ypos += rowHeight;
                n++;

                //reset the markup or it carries over to the next SetText
                if (hasMarkup)
                {
                    layout.Markup = string.Empty;
                }
            }
        }
Ejemplo n.º 31
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;
        }