示例#1
0
 public void Init()
 {
     ib = new ImageBuilder (1, 1);
     context = ib.Context;
     Matrix m1 = Matrix.Identity;
     Matrix m2 = context.GetCTM ();
     CheckMatrix (m1, m2);
 }
示例#2
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;
        }
示例#3
0
		public void PatternsAndImages (Context ctx, double x, double y)
		{
			ctx.Save ();
			ctx.Translate (x, y);
			
			ctx.SetColor (Colors.Black);
			// Dashed lines

			ctx.SetLineWidth (2);
			ctx.SetLineDash (15, 10, 10, 5, 5);
			ctx.Rectangle (10, 10, 100, 100);
			ctx.Stroke ();
			ctx.SetLineDash (0);
			
			// Image
			var arcColor = new Color (1, 0, 1);
			ImageBuilder ib = new ImageBuilder (30, 30);
			ib.Context.Arc (15, 15, 15, 0, 360);
			ib.Context.SetColor (arcColor);
			ib.Context.Fill ();
			ib.Context.SetColor (Colors.DarkKhaki);
			ib.Context.Rectangle (0, 0, 5, 5);
			ib.Context.Fill ();
			var img = ib.ToVectorImage ();
			ctx.DrawImage (img, 0, 0);
			ctx.DrawImage (img, 0, 50, 50, 10);
			
			ctx.Arc (100, 100, 15, 0, 360);
			arcColor.Alpha = 0.4;
			ctx.SetColor (arcColor);
			ctx.Fill ();
			
			// ImagePattern
			
			ctx.Save ();
			
			ctx.Translate (x + 130, y);
			ctx.Pattern = new ImagePattern (img);
			ctx.Rectangle (0, 0, 100, 100);
			ctx.Fill ();
			ctx.Restore ();
			
			ctx.Restore ();
			
			// Setting pixels
			
			ctx.SetLineWidth (1);
			for (int i=0; i<50;i++) {
				for (var j=0; j<50;j++) {
					Color c = Color.FromHsl (0.5, (double)i / 50d, (double)j / 50d);
					ctx.Rectangle (i, j, 1, 1);
					ctx.SetColor (c);
					ctx.Fill ();
				}
			}
		}	
示例#4
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public OverlayCanvas()
     : base()
 {
     CanGetFocus = true;
     if (Bounds.Size == Size.Zero)
         return;
     cacheSize = Bounds.Size;
     ib = new ImageBuilder (Bounds.Width, Bounds.Height);
     cache = ib.ToBitmap ();
 }
示例#5
0
		protected void CheckImage (string refImageName, double scaleFactor = 1)
		{
			if (builder == null)
				return;
			var img = builder.ToBitmap (scaleFactor);
			builder.Dispose ();
			builder = null;

			ReferenceImageManager.CheckImage (refImageName, img);
		}
示例#6
0
		protected void InitBlank (int width = 50, int height = 50)
		{
			if (builder != null)
				builder.Dispose ();

			builder = new ImageBuilder (width, height);
			context = builder.Context;
			context.Rectangle (0, 0, width, height);
			context.SetColor (Colors.White);
			context.Fill ();
			context.SetColor (Colors.Black);
			context.SetLineWidth (1);
		}
示例#7
0
        protected override void OnBoundsChanged()
        {
            bounds = this.Bounds;

            if (plotCache != null ) {
                plotCache.Dispose ();
            }
            plotCache = new ImageBuilder ((int)bounds.Width, (int)bounds.Height, ImageFormat.ARGB32);
            cacheContext = plotCache.Context;
            UpdateCache (cacheContext);
            plotImage = plotCache.ToImage ();

            base.OnBoundsChanged ();
        }
示例#8
0
        protected override void OnDraw(Xwt.Drawing.Context ctx)
        {
            base.OnDraw (ctx);

            ctx.SetLineDash (15, 10, 10, 5, 5);
            ctx.Rectangle (100, 100, 100, 100);
            ctx.Stroke ();
            ctx.SetLineDash (0);

            ImageBuilder ib = new ImageBuilder (30, 30, ImageFormat.ARGB32);
            ib.Context.Arc (15, 15, 15, 0, 360);
            ib.Context.SetColor (new Color (1, 0, 1));
            ib.Context.Rectangle (0, 0, 5, 5);
            ib.Context.Fill ();
            var img = ib.ToImage ();
            ctx.DrawImage (img, 90, 90);
            ctx.DrawImage (img, 90, 140, 50, 10);

            ctx.Arc (190, 190, 15, 0, 360);
            ctx.SetColor (new Color (1, 0, 1, 0.4));
            ctx.Fill ();

            ctx.Save ();
            ctx.Translate (90, 220);
            ctx.Pattern = new ImagePattern (img);
            ctx.Rectangle (0, 0, 100, 70);
            ctx.Fill ();
            ctx.Restore ();

            ctx.Translate (30, 30);
            double end = 270;

            for (double n = 0; n<=end; n += 5) {
                ctx.Save ();
                ctx.Rotate (n);
                ctx.MoveTo (0, 0);
                ctx.RelLineTo (30, 0);
                double c = n / end;
                ctx.SetColor (new Color (c, c, c));
                ctx.Stroke ();
                ctx.Restore ();
            }
        }
示例#9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Baimp.FileTreeView"/> class.
        /// </summary>
        public FileTreeView()
        {
            // center tick/cross symbols
            using (ImageBuilder ib = new ImageBuilder(THUMB_SIZE, THUMB_SIZE)) {
                ib.Context.DrawImage(tick, new Point((THUMB_SIZE - tick.Width) / 2, (THUMB_SIZE - tick.Height) / 2));
                Image tickNew = ib.ToBitmap();
                tick.Dispose();
                tick = tickNew;
            }
            using (ImageBuilder ib = new ImageBuilder(THUMB_SIZE, THUMB_SIZE)) {
                ib.Context.DrawImage(cross, new Point((THUMB_SIZE - cross.Width) / 2, (THUMB_SIZE - cross.Height) / 2));
                Image crossNew = ib.ToBitmap();
                cross.Dispose();
                cross = crossNew;
            }

            store = new TreeStore(thumbnailCol, nameCol, finishCol, saveStateCol);
            storeFilter = new TreeStore(thumbnailColFilter, nameColFilter, finishColFiltered, saveStateColFilter);

            SelectionMode = SelectionMode.Multiple;
            BoundsChanged += InitializeSize;

            InitializeContextMenu();
        }
示例#10
0
文件: Mask.cs 项目: jfreax/BAIMP
        /// <summary>
        /// Saves the mask.
        /// </summary>
        public unsafe void Save()
        {
            if (MaskPositions.Count <= 1) {
                if (wasResetted) {
                    Project.RequestZipAccess(new Project.ZipUsageCallback(delegate(ZipFile zipFile) {
                        zipFile.BeginUpdate();
                        if (zipFile.FindEntry(MaskFilename, false) != -1) {
                            zipFile.Delete(zipFile.GetEntry(MaskFilename));
                        }

                        zipFile.CommitUpdate();

                        return null;
                    }));
                    wasResetted = false;
                }
                return;
            }

            MemoryStream outStream = new MemoryStream();

            using (XD.ImageBuilder mb = GetMaskBuilder()) {
                FlushMaskPositions(mb.Context, 0);

                using (XD.ImageBuilder outIb = new XD.ImageBuilder(mb.Width, mb.Height)) {
                    XD.BitmapImage mask = mb.ToBitmap();
                    outIb.Context.DrawImage(mask, new Xwt.Point(0, 0));
                    outIb.Context.DrawImage(mask, new Xwt.Point(1, 1));
                    outIb.Context.DrawImage(mask, new Xwt.Point(-1, -1));

                    mask = outIb.ToBitmap();
                    mask.Save(outStream, XD.ImageFileType.Png);
                }
            }

            outStream.Position = 0;

            Project.RequestZipAccess(new Project.ZipUsageCallback(delegate(ZipFile zipFile) {
                zipFile.BeginUpdate();

                CustomStaticDataSource source = new CustomStaticDataSource(outStream);

                zipFile.Add(source, MaskFilename);
                zipFile.IsStreamOwner = true;
                zipFile.CommitUpdate();

                return null;
            }));

            maskBuilder.Dispose();
            maskBuilder = null;

            if (bitmapCache != null) {
                bitmapCache.Dispose();
                bitmapCache = null;
            }

            scan.HasMask = true;
            scan.NotifySaved("mask");
        }
示例#11
0
			public override void OnRenderFrames ()
			{
				var prev = PreviousFrame;
				var next = NextFrame;
				for (int n=0; n<10; n++) {
					var img1 = next.WithAlpha (((double)(n))/10.0);
					var img2 = prev.WithAlpha (((double)(9-n))/10.0);
					var ib = new ImageBuilder (img1.Size.Width, img2.Size.Height);
					ib.Context.DrawImage (img1, 0, 0, ((double)(n)) / 10.0);
					ib.Context.DrawImage (img2, 0, 0, ((double)(9 - n)) / 10.0);
					AddImage (ib.ToVectorImage ());
					AddPause (60);
				}
			}
示例#12
0
 protected override void OnDraw(Context ctx, Rectangle dirtyRect)
 {
     if (colorBox == null) {
         using (var ib = new ImageBuilder (size, size)) {
             for (int i=0; i<size; i++) {
                 for (int j=0; j<size; j++) {
                     ib.Context.Rectangle (i, j, 1, 1);
                     ib.Context.SetColor (GetColor (i,j));
                     ib.Context.Fill ();
                 }
             }
             colorBox = ib.ToImage ();
         }
     }
     ctx.DrawImage (colorBox, padding, padding);
     ctx.SetLineWidth (1);
     ctx.SetColor (Colors.Black);
     ctx.Rectangle (selection.X + padding - 2 + 0.5, selection.Y + padding - 2 + 0.5, 4, 4);
     ctx.Stroke ();
 }
示例#13
0
 public void Init()
 {
     ib = new ImageBuilder (10, 10);
     context = ib.Context;
 }
示例#14
0
 public static Image DiffImages(Image img1, Image img2)
 {
     bool foundDifference = false;
     var bmp1 = img1.ToBitmap ();
     var bmp2 = img2.ToBitmap ();
     var res = new ImageBuilder ((int)Math.Min (bmp1.Size.Width, bmp2.Size.Width), (int) Math.Min (bmp1.Size.Height, bmp2.Size.Height));
     var bmpr = res.ToBitmap ();
     res.Dispose ();
     for (int y=0; y<bmp1.Size.Height && y < bmp2.Size.Height; y++) {
         for (int x=0; x<bmp1.Size.Width && x<bmp2.Size.Height; x++) {
             var p1 = bmp1.GetPixel (x, y);
             var p2 = bmp2.GetPixel (x, y);
             var col = Colors.White;
             if (p1 != p2) {
                 foundDifference = true;
                 var r = Math.Pow (p1.Red - p2.Red, 2) + Math.Pow (p1.Green - p2.Green, 2) + Math.Pow (p1.Blue - p2.Blue, 2) + Math.Pow (p1.Alpha - p2.Alpha, 2);
                 if (r < 0.01)
                     col = new Color (0.9, 0.9, 0.9);
                 else if (r < 0.1)
                     col = new Color (0.7, 0.7, 0.7);
                 else
                     col = Colors.Red;
             }
             bmpr.SetPixel (x, y, col);
         }
     }
     if (foundDifference)
         return bmpr;
     else
         return null;
 }
示例#15
0
文件: TMatrix.cs 项目: jfreax/BAIMP
        public Widget ToWidget()
        {
            long coloumns = Width;
            long rows = Height;

            if (widget == null) {
                if (rows <= 16 && coloumns <= 16) {
                    Table t = new Table();

                    if (isSparse) {
                        foreach (int i in sparseMatrix.GetRows()) {
                            foreach (KeyValuePair<int, float> value in sparseMatrix.GetRowData(i)) {
                                t.Add(new Label(value.Value.ToString()), value.Key, i);
                            }
                        }
                    } else {
                        for (int x = 0; x < coloumns; x++) {
                            for (int y = 0; y < rows; y++) {
                                t.Add(new Label(matrix[x, y].ToString()), x, y);
                            }
                        }
                    }

                    widget = t;
                } else {
                    BitmapImage bi;

                    int iScaleFactor = MathExtras.NextPowerOf2(
                        (int) Math.Round((float) Math.Max(coloumns, rows) / BaseType<int>.MaxWidgetSize.Width) + 1
                    );

                    ImageBuilder ib = new ImageBuilder(coloumns / iScaleFactor, rows / iScaleFactor);
                    bi = ib.ToBitmap();

                    if (isSparse) {
                        float max = sparseMatrix.Max();
                        float min = sparseMatrix.Min();

                        const float toMax = 65536.0f;
                        float toMaxLog = (float) Math.Log(toMax);

                        foreach (int y in sparseMatrix.GetRows()) {
                            foreach (KeyValuePair<int, float> v in sparseMatrix.GetRowData(y)) {
                                float toLog = (toMax - 1.0f) * ((v.Value - min) / (max - min)) + 1.0f;
                                byte c = (byte) ((Math.Log(toLog) / toMaxLog) * 255);

                                bi.SetPixel(v.Key / iScaleFactor, y / iScaleFactor, Color.FromBytes(c, c, c));
                            }
                        }
                    } else {

                        float max = 0.0f;
                        float[,] copy = matrix.Scale(1.0f, 65536.0f);

                        for (int x = 0; x < coloumns; x++) {
                            for (int y = 0; y < rows; y++) {
                                if (copy[x, y] > 0) {
                                    copy[x, y] = (float) (Math.Log(copy[x, y]));
                                }

                                if (copy[x, y] > max) {
                                    max = copy[x, y];
                                }
                            }
                        }

                        for (int x = 0; x < coloumns; x++) {
                            for (int y = 0; y < rows; y++) {
                                byte c = (byte) ((copy[x, y] * 255) / max);
                                if (c > 0) {
                                    bi.SetPixel(x / iScaleFactor, y / iScaleFactor, Color.FromBytes(c, c, c));
                                }
                            }
                        }
                    }

                    ib.Dispose();
                    widget = new ImageView(bi.WithBoxSize(BaseType<int>.MaxWidgetSize));
                }
            }

            return widget;
        }
示例#16
0
文件: Utils.cs 项目: parnham/NPlot
 /// <summary>
 /// Creates a BitmapImage from a tile repeated in each direction as required
 /// </summary>
 /// <param name="tile">Bitmap image to tile</param>
 /// <param name="final">final image size</param>
 /// <returns>the tiled image</returns>
 public static BitmapImage TiledImage(BitmapImage tile, Size final)
 {
     BitmapImage tiled = null;
     using (ImageBuilder ib = new ImageBuilder (final.Width, final.Height)) {
         using (Context ctx = ib.Context) {
             double w = tile.Size.Width;
             double h = tile.Size.Height;
             for (double x = 0; x < final.Width; x += w) {
                 for (double y = 0; y < final.Height; y += h) {
                     ctx.DrawImage (tile, x, y);
                 }
             }
         }
         tiled = ib.ToBitmap ();
     }
     return tiled;
 }
示例#17
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);
                }
            }
        }
示例#18
0
文件: Mask.cs 项目: jfreax/BAIMP
        /// <summary>
        /// Resets mask data
        /// </summary>
        public void ResetMask()
        {
            MaskPositions.Clear();
            if (maskBuilder != null) {
                maskBuilder.Dispose();
                maskBuilder = new XD.ImageBuilder(scan.Size.Width, scan.Size.Height);
            }

            if (scan.HasMask) {
                wasResetted = true;
                scan.HasMask = false;
                scan.NotifyChange("mask");
            }
        }
示例#19
0
文件: Axis.cs 项目: hwthomas/XwPlot
        /// <summary>
        /// returns a suitable offset for the axis label in the case that there are no
        /// ticks or tick text in the way.
        /// </summary>
        /// <param name="physicalMin">physical point corresponding to the axis world maximum.</param>
        /// <param name="physicalMax">physical point corresponding to the axis world minimum.</param>
        /// <returns>axis label offset</returns>
        protected Point getDefaultLabelOffset(Point physicalMin, Point physicalMax)
        {
            Rectangle tBoundingBox;
            Point tLabelOffset;

            using (ImageBuilder ib = new ImageBuilder (1,1)) {
                using (Context ctx = ib.Context) {
                    DrawTick (ctx, WorldMax, LargeTickSize,
                        "",
                        new Point (0,0),
                        physicalMin, physicalMax,
                        out tLabelOffset, out tBoundingBox );
                }
            }
            return tLabelOffset;
        }
示例#20
0
文件: Utils.cs 项目: hwthomas/XwPlot
 /// <summary>
 /// Creates a BitmapImage from a tile repeated in each direction as required
 /// </summary>
 /// <param name="tile">Bitmap image to tile</param>
 /// <param name="final">final image size</param>
 /// <returns>the tiled image</returns>
 /// <remarks>
 /// For correct drawing, the tile and final images MUST have integer sizes
 /// </remarks>
 public static BitmapImage TiledImage(BitmapImage tile, Size final)
 {
     BitmapImage tiled = null;
     Rectangle src, dest;
     // Trim tile and final images to integer dimensions
     double tileWidth = Math.Truncate (tile.Size.Width);
     double tileHeight = Math.Truncate (tile.Size.Height);
     double finalWidth = Math.Truncate (final.Width);
     double finalHeight = Math.Truncate (final.Height);
     src = new Rectangle (0, 0, tileWidth, tileHeight);	// Initial size for source tile
     using (ImageBuilder ib = new ImageBuilder (finalWidth, finalHeight)) {
         using (Context ctx = ib.Context) {
             double dh = tileHeight;
             double y = 0;
             while (y < finalHeight) {
                 // allow for part-height tile at end
                 if (tileHeight > (finalHeight - y)) {
                     dh = (finalHeight - y);
                     src.Height = dh;
                 }
                 double dw = tileWidth;
                 double x = 0;
                 src.Width = dw = tileWidth;		// reset source Width for each X loop
                 while (x < finalWidth) {
                     // allow for part-width tile at end
                     if (tileWidth > (finalWidth - x)) {
                         dw = (finalWidth - x);
                         src.Width = dw;
                     }
                     dest = new Rectangle (x, y, dw, dh);
                     ctx.DrawImage (tile, src, dest);
                     x += tileWidth;
                 }
                 y += tileHeight;
             }
         }
         tiled = ib.ToBitmap ();
     }
     return tiled;
 }
示例#21
0
        protected override void OnDraw(Xwt.Drawing.Context ctx)
        {
            base.OnDraw (ctx);

            // Simple rectangles

            ctx.SetLineWidth (1);
            ctx.Rectangle (100, 5, 10, 10);
            ctx.SetColor (Color.Black);
            ctx.Fill ();

            ctx.Rectangle (115, 5, 10, 10);
            ctx.SetColor (Color.Black);
            ctx.Stroke ();

            //

            ctx.SetLineWidth (3);
            ctx.Rectangle (100, 20, 10, 10);
            ctx.SetColor (Color.Black);
            ctx.Fill ();

            ctx.Rectangle (115, 20, 10, 10);
            ctx.SetColor (Color.Black);
            ctx.Stroke ();

            // Rectangle with hole

            ctx.Rectangle (10, 100, 40, 40);
            ctx.MoveTo (45, 135);
            ctx.RelLineTo (0, -20);
            ctx.RelLineTo (-20, 0);
            ctx.RelLineTo (0, 20);
            ctx.ClosePath ();
            ctx.SetColor (Color.Black);
            ctx.Fill ();

            // Dashed lines

            ctx.SetLineDash (15, 10, 10, 5, 5);
            ctx.Rectangle (100, 100, 100, 100);
            ctx.Stroke ();
            ctx.SetLineDash (0);

            ImageBuilder ib = new ImageBuilder (30, 30, ImageFormat.ARGB32);
            ib.Context.Arc (15, 15, 15, 0, 360);
            ib.Context.SetColor (new Color (1, 0, 1));
            ib.Context.Rectangle (0, 0, 5, 5);
            ib.Context.Fill ();
            var img = ib.ToImage ();
            ctx.DrawImage (img, 90, 90);
            ctx.DrawImage (img, 90, 140, 50, 10);

            ctx.Arc (190, 190, 15, 0, 360);
            ctx.SetColor (new Color (1, 0, 1, 0.4));
            ctx.Fill ();

            ctx.Save ();
            ctx.Translate (90, 220);
            ctx.Pattern = new ImagePattern (img);
            ctx.Rectangle (0, 0, 100, 70);
            ctx.Fill ();
            ctx.Restore ();

            ctx.Translate (30, 30);
            double end = 270;

            for (double n = 0; n<=end; n += 5) {
                ctx.Save ();
                ctx.Rotate (n);
                ctx.MoveTo (0, 0);
                ctx.RelLineTo (30, 0);
                double c = n / end;
                ctx.SetColor (new Color (c, c, c));
                ctx.Stroke ();
                ctx.Restore ();
            }

            ctx.ResetTransform ();
        }
示例#22
0
 /// <summary>
 /// Update the cache contents, reallocating the cache if necessary
 /// </summary>
 void UpdateCache()
 {
     if (Bounds.Size == Size.Zero)
         return;
     // reallocate cache if Bounds have changed
     if (cacheSize != Bounds.Size) {
         //if (cache != null)
         //	cache.Dispose ();
         //if (ib != null)
         //	ib.Dispose ();
         cacheSize = Bounds.Size;
         ib = new ImageBuilder (Bounds.Width, Bounds.Height);
     }
     // Clear cache to Canvas Background colour
     ib.Context.SetColor (BackgroundColor);
     ib.Context.Rectangle (Bounds);
     ib.Context.Fill ();
     // Draw into cache
     OnDrawCache (ib.Context, Bounds);
     cache = ib.ToBitmap ();
 }
示例#23
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);
            }
        }
示例#24
0
        void CheckImage(string refImageName)
        {
            if (builder == null)
                return;
            var img = builder.ToBitmap ((int)builder.Width, (int)builder.Height);
            builder.Dispose ();
            builder = null;

            ReferenceImageManager.CheckImage (refImageName, img);
        }
示例#25
0
 /// <summary>
 /// Get the bounding box of the rectangle.
 /// </summary>
 /// <param name="position">the position of the top left of the legend.</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></returns>
 /// <remarks>do implementation that doesn't call draw. Change xPos, yPos to PointF</remarks>
 public Rectangle GetBoundingBox(Point position, ArrayList plots, double scale)
 {
     Rectangle bounds;
     using (ImageBuilder ib = new ImageBuilder (1,1)) {
         using (Context ctx = ib.Context) {
             bounds = Draw (ctx, position, plots, scale);
         }
     }
     return bounds;
 }
示例#26
0
文件: ScanView.cs 项目: jfreax/BAIMP
        protected override void OnDraw(Context ctx, Rectangle dirtyRect)
        {
            base.OnDraw(ctx, dirtyRect);

            if (image != null) {
                if (Heighlighted && IsThumbnail) {
                    ctx.RoundRectangle(new Rectangle(Point.Zero, image.Size), 3);
                    ctx.SetColor(Colors.LightSteelBlue);
                    ctx.Fill();
                }

                ctx.DrawImage(image, (new Rectangle(Point.Zero, image.Size)).Inflate(-3, -3));

                if (mask != null && ShowMask) {
                    ctx.DrawImage(MaskBitmap, (new Rectangle(Point.Zero, image.Size)).Inflate(-3, -3), 0.6);
                }
            }

            if (isEditMode) {
                Point scaleFactor = new Point(
                                        scan.Size.Width / image.Size.Width,
                                        scan.Size.Height / image.Size.Height);
                ctx.SetColor(Mask.maskColor);

                foreach (MaskEntry p in scan.Mask.MaskPositions) {
                    switch (p.type) {
                    case MaskEntryType.Point:
                        ctx.SetLineWidth(p.pointerSize / scaleFactor.Y * 2);
                        ctx.LineTo(p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y);
                        ctx.Stroke();

                        ctx.Arc(
                            p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y,
                            p.pointerSize / scaleFactor.Y, 0, 360);
                        ctx.Fill();

                        ctx.MoveTo(p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y);
                        break;
                    case MaskEntryType.Space:
                        ctx.Stroke();
                        ctx.ClosePath();
                        break;
                    case MaskEntryType.Delete:
                        ctx.Arc(
                            p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y,
                            p.pointerSize / scaleFactor.Y, 0, 360);
                        ctx.Save();
                        ctx.Clip();
                        int newX = (int) Math.Min(Math.Max(
                                       p.position.X / scaleFactor.X - pointerSize / scaleFactor.Y, 0), scan.Size.Width);
                        int newY = (int) Math.Min(Math.Max(
                                       p.position.Y / scaleFactor.Y - pointerSize / scaleFactor.Y, 0), scan.Size.Height);

                        using (ImageBuilder ib =
                                   new ImageBuilder((pointerSize / scaleFactor.Y * 2), (pointerSize / scaleFactor.Y * 2))) {
                            BitmapImage bi = ib.ToBitmap();
                            image.WithBoxSize(image.Size).ToBitmap().CopyArea(
                                newX, newY,
                                (int) (pointerSize / scaleFactor.Y * 2), (int) (pointerSize / scaleFactor.Y * 2),
                                bi, 0, 0);
                            ctx.DrawImage(bi, new Point(newX, newY));
                        }
                        ctx.Restore();
                        ctx.ClosePath();
                        break;
                    }
                }

                ctx.Stroke();

                if (mousePosition != Point.Zero) {
                    ctx.Arc(mousePosition.X, mousePosition.Y, pointerSize / Math.Max(scaleFactor.X, scaleFactor.Y), 0, 360);
                    ctx.Fill();

                    if (mousePositionStart != Point.Zero) {
                        ctx.SetLineWidth((pointerSize / Math.Max(scaleFactor.X, scaleFactor.Y)) * 2);
                        ctx.SetColor(Mask.maskColor);
                        ctx.Arc(mousePositionStart.X, mousePositionStart.Y, pointerSize / Math.Max(scaleFactor.X, scaleFactor.Y), 0, 360);
                        ctx.Fill();
                        ctx.MoveTo(mousePosition);
                        ctx.LineTo(mousePositionStart);
                        ctx.Stroke();
                    }
                }
            }
        }
示例#27
0
 /// <summary>
 /// Returns the smallest rectangle that completely contains all parts of the axis [including ticks and label].
 /// </summary>
 /// <returns>the smallest rectangle that completely contains all parts of the axis [including ticks and label].</returns>
 public virtual Rectangle GetBoundingBox()
 {
     Rectangle bounds;
     using (ImageBuilder ib = new ImageBuilder (1,1)) {
         using (Context ctx = ib.Context) {
             Draw (ctx, out bounds);
         }
     }
     return bounds;
 }
示例#28
0
        /// <summary>
        /// Gets the edge at position.
        /// </summary>
        /// <param name="position">Position.</param>
        Tuple<MarkerNode, MarkerEdge> GetEdgeAt(Point position)
        {
            const double epsilon = 4.0;

            foreach (PipelineNode pNode in nodes) {
                foreach (MarkerNode mNode in pNode.mNodes) {
                    if (!mNode.IsInput) {
                        foreach (Edge e in mNode.Edges) {
                            MarkerEdge edge = (MarkerEdge) e;
                            using (ImageBuilder ib = new ImageBuilder(Bounds.Width, Bounds.Height)) {
                                ib.Context.SetLineWidth(12);
                                edge.ComputeStroke(ib.Context, mNode);
                                if (ib.Context.IsPointInStroke(position)) {
                                    double fromDist =
                                        Math.Pow(mNode.Bounds.Center.X - position.X, 2) +
                                        Math.Pow(mNode.Bounds.Center.Y - position.Y, 2);
                                    double toDist =
                                        Math.Pow(edge.to.Bounds.Center.X - position.X, 2) +
                                        Math.Pow(edge.to.Bounds.Center.Y - position.Y, 2);
                                    if (fromDist < toDist) {
                                        edge.r = 0;
                                    } else {
                                        edge.r = 1;
                                    }
                                    return new Tuple<MarkerNode, MarkerEdge>(mNode, edge);
                                }
                            }
                        }
                    }
                }
            }

            return null;
        }
示例#29
0
		protected override void OnDraw (Context ctx, Rectangle dirtyRect)
		{
			if (colorBox == null) {
				using (var ib = new ImageBuilder (size, size)) {
					for (int i=0; i<size; i++) {
						for (int j=0; j<size; j++) {
							ib.Context.Rectangle (i, j, 1, 1);
							ib.Context.SetColor (GetColor (i,j));
							ib.Context.Fill ();
						}
					}

					if (ParentWindow != null)
						colorBox = ib.ToBitmap (this); // take screen scale factor into account
					else
						colorBox = ib.ToBitmap ();
				}
			}
			ctx.DrawImage (colorBox, padding, padding);
			ctx.SetLineWidth (1);
			ctx.SetColor (Colors.Black);
			ctx.Rectangle (selection.X + padding - 2 + 0.5, selection.Y + padding - 2 + 0.5, 4, 4);
			ctx.Stroke ();
		}
示例#30
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);
        }