示例#1
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;
        }
示例#2
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 ();
 }
示例#3
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();
        }
示例#4
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 ();
		}
示例#5
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;
 }
示例#6
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;
 }
示例#7
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();
                    }
                }
            }
        }
示例#8
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);
                }
            }
        }
示例#9
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;
        }
示例#10
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;
 }
示例#11
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");
        }
示例#12
0
文件: Mask.cs 项目: jfreax/BAIMP
        /// <summary>
        /// Renders new mask position.
        /// </summary>
        /// <param name="ctx">Context.</param>
        /// <param name="bufferSize">Buffer size (entries that should not be rendered, used by undo function).</param>
        public void FlushMaskPositions(XD.Context ctx, int bufferSize = 30)
        {
            bool first = true;
            if (MaskPositions.Count >= bufferSize) {
                wasResetted = false;

                ctx.SetColor(maskColor);
                for (int i = 0; i < MaskPositions.Count - bufferSize; i++) {
                    switch (MaskPositions[i].type) {
                    case MaskEntryType.Point:
                        ctx.SetLineWidth(MaskPositions[i].pointerSize * 2);
                        if (first) {
                            first = false;
                            ctx.MoveTo(MaskPositions[i].position);
                        } else {
                            ctx.LineTo(MaskPositions[i].position);
                        }
                        ctx.Stroke();

                        ctx.Arc(
                            MaskPositions[i].position.X, MaskPositions[i].position.Y,
                            MaskPositions[i].pointerSize, 0, 360);
                        ctx.Fill();

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

                        using (XD.ImageBuilder ibnew =
                            new XD.ImageBuilder(MaskPositions[i].pointerSize * 2, MaskPositions[i].pointerSize * 2)) {
                            XD.BitmapImage bi = ibnew.ToBitmap();
                            scan.GetAsImage(CurrentScanType, false).WithBoxSize(scan.Size).ToBitmap().CopyArea(
                                newX, newY, MaskPositions[i].pointerSize * 2, MaskPositions[i].pointerSize * 2,
                                bi, 0, 0);
                            ctx.DrawImage(bi, new Xwt.Point(newX, newY));
                        }
                        ctx.Restore();
                        ctx.ClosePath();
                        break;
                    }
                }
                ctx.Stroke();

                MaskPositions.RemoveRange(0, MaskPositions.Count - bufferSize);

                scan.NotifyChange("mask");
            }
        }
示例#13
0
        public DrawingTest()
            : base()
        {
            // Canvas size requests
            WidthRequest = 400;
            HeightRequest = 400;

            Point p = new Point (centre, centre);
            ib = new ImageBuilder (size, size);
            // Draw off-screen images and convert to bitmap/vector
            ib.Context.SetColor (Colors.Green);
            DrawFocus (ib.Context, p);
            bitmap = ib.ToBitmap ();
            ib.Context.SetColor (Colors.Blue);
            DrawFocus (ib.Context, p);
            vectorImage = ib.ToVectorImage ();
        }