public static ICollection <Cairo.Rectangle> GetDiffRectangles(TextEditor editor, int startOffset, int endOffset)
        {
            ICollection <Cairo.Rectangle> rectangles = new List <Cairo.Rectangle> ();
            var startLine = editor.GetLineByOffset(startOffset);
            var endLine   = editor.GetLineByOffset(endOffset);
            int lineCount = endLine.LineNumber - startLine.LineNumber;
            var line      = startLine;

            for (int i = 0; i <= lineCount; i++)
            {
                Cairo.Point point  = editor.LocationToPoint(editor.Document.OffsetToLocation(Math.Max(startOffset, line.Offset)), true);
                Cairo.Point point2 = editor.LocationToPoint(editor.Document.OffsetToLocation(Math.Min(line.EndOffset, endOffset)), true);
                rectangles.Add(new Cairo.Rectangle(point.X - editor.TextViewMargin.XOffset, point.Y, point2.X - point.X, editor.LineHeight));
                line = line.NextLine;
            }
            return(rectangles);
        }
示例#2
0
        public static Cairo.Rectangle GetDiffRectangle(TextEditor editor, int startOffset, int endOffset)
        {
            var point = editor.LocationToPoint(editor.Document.OffsetToLocation(startOffset), true);

            Cairo.Point point2;
            var         line = editor.GetLineByOffset(startOffset);

            if (line.Offset + line.Length < endOffset)
            {
                point2 = new Cairo.Point((int)(point.X + editor.TextViewMargin.CharWidth * (endOffset - startOffset)), point.Y);
            }
            else
            {
                point2 = editor.LocationToPoint(editor.Document.OffsetToLocation(endOffset), true);
            }
            return(new Cairo.Rectangle(point.X - editor.TextViewMargin.XOffset, point.Y, point2.X - point.X, editor.LineHeight));
        }
示例#3
0
        protected override void OnMouseUp(Document document, ToolMouseEventArgs e)
        {
            painting = false;

            using (var g = new Cairo.Context(document.Layers.CurrentUserLayer.Surface)) {
                g.SetSource(document.Layers.ToolLayer.Surface);
                g.Paint();
            }

            base.OnMouseUp(document, e);

            offset     = new Cairo.Point(int.MinValue, int.MinValue);
            last_point = new Cairo.Point(int.MinValue, int.MinValue);

            document.Layers.ToolLayer.Clear();
            document.Layers.ToolLayer.Hidden = true;
            document.Workspace.Invalidate();
        }
示例#4
0
        void OnPopupMenu(object sender, Gtk.ButtonPressEventArgs args)
        {
            if (args.Event.Button == 3)
            {
                int textEditorXOffset = (int)args.Event.X - (int)this.TextViewMargin.XOffset;
                if (textEditorXOffset < 0)
                {
                    return;
                }
                this.menuPopupLocation = new Cairo.Point((int)args.Event.X, (int)args.Event.Y);
                DocumentLocation loc = PointToLocation(textEditorXOffset, (int)args.Event.Y);
                if (!this.IsSomethingSelected || !this.SelectionRange.Contains(Document.LocationToOffset(loc)))
                {
                    Caret.Location = loc;
                }

                this.ShowPopup();
                base.ResetMouseState();
            }
        }
示例#5
0
            public FloatingQuickFixIconWidget(CodeActionEditorExtension codeActionEditorExtension, LanguageItemWindow window, SourceEditorView sourceEditorView, CodeActionContainer fixes, Cairo.Point point) : base(Gtk.WindowType.Popup)
            {
                this.ext              = codeActionEditorExtension;
                this.window           = window;
                this.sourceEditorView = sourceEditorView;
                this.fixes            = fixes;
                this.point            = point;
                this.Decorated        = false;
                this.Events          |= EventMask.ButtonPressMask | EventMask.LeaveNotifyMask | EventMask.EnterNotifyMask;
                TypeHint              = Gdk.WindowTypeHint.Utility;
                var fr = new Gtk.HBox();

                fr.BorderWidth = 2;
                var view = new ImageView(SmartTagMarginMarker.GetIconId(fixes.GetSmartTagSeverity()), Gtk.IconSize.Menu);

                fr.PackStart(view, false, false, 0);
                fr.PackEnd(new RectangleMarker(), false, false, 0);
                Add(fr);
                ext.FixesMenuClosed += Ext_FixesMenuClosed;

                ShowAll();
            }
示例#6
0
        void OnClicked(int posX, int posY, Gdk.Event triggerEvent, uint button)
        {
            Cairo.Point p = GetGridPosition(posX, posY, scale: false, offset: false);
            if (EnableTileEditing && hoveringComponent == null)
            {
                if (!IsInBounds(posX, posY, scale: false, offset: false))
                {
                    return;
                }
                if (button == 1)   // Left-click
                {
                    RoomLayout.SetTile(p.X, p.Y, TilesetViewer.SelectedIndex);
                    draggingTile = true;
                }
                else if (button == 3)   // Right-click
                {
                    TilesetViewer.SelectedIndex = RoomLayout.GetTile(p.X, p.Y);
                }
            }
            if (DrawRoomComponents)
            {
                if (hoveringComponent != null)
                {
                    selectedComponent = hoveringComponent;
                    hoveringComponent.Select();

                    if (button == 1)   // Left click
                    {
                        draggingObject = true;
                    }
                    else if (button == 3)   // Right click
                    {
                        Gtk.Menu menu = new Gtk.Menu();

                        foreach (Gtk.MenuItem item in selectedComponent.GetRightClickMenuItems())
                        {
                            menu.Add(item);
                        }

                        RoomComponent comp = selectedComponent;

                        if (comp.Deletable)
                        {
                            if (menu.Children.Length != 0)
                            {
                                menu.Add(new Gtk.SeparatorMenuItem());
                            }

                            var deleteButton = new Gtk.MenuItem("Delete");
                            deleteButton.Activated += (sender, args) => {
                                comp.Delete();
                            };
                            menu.Add(deleteButton);
                        }

                        menu.AttachToWidget(this, null);
                        menu.ShowAll();
                        menu.PopupAtPointer(triggerEvent);
                    }
                }
            }
            QueueDraw();
        }
示例#7
0
 public DocumentLocation PointToLocation(Cairo.Point p)
 {
     return(TextViewMargin.PointToLocation(p));
 }
示例#8
0
 public bool this[Cairo.Point pt] {
     get => this[pt.X, pt.Y];
     set => this[pt.X, pt.Y] = value;
示例#9
0
        public Gdk.Pixbuf BuildImage(FontService fontService)
        {
            Cairo.ImageSurface image = new Cairo.ImageSurface (Cairo.Format.ARGB32, WIDTH, HEIGHT);
            Cairo.Context ctx = new Cairo.Context (image);

            Pango.Layout layout = Pango.CairoHelper.CreateLayout (ctx);
            fontService.AssignLayout (layout);

            // fill background
            ctx.Save ();
            ctx.Color = new Cairo.Color (0.0, 0.0, 0.0, 1.0);
            ctx.Paint ();
            ctx.Restore ();

            int charCode = 0;
            int maxHeight = 0;
            Cairo.Point pos = new Cairo.Point (PADDING, PADDING);
            while ((!fontService.OnlyEnglish && charCode < 224) ||
                   (fontService.OnlyEnglish && charCode < (224 - 66))) {

                layout.SetText (alphabet[charCode].ToString());

                Pango.Rectangle te = GetTextExtents (layout, pos);

                // next line
                if (pos.X + te.Width + fontService.Spacing + PADDING > image.Width) {
                    pos.X = PADDING;
                    pos.Y = te.Y + maxHeight + PADDING;
                }
                te = DrawText (ctx, layout, pos);
                boxes[charCode] = te;

                pos.X = te.X + te.Width + fontService.Spacing + PADDING;
                maxHeight = Math.Max (maxHeight, te.Height);

                charCode++;
            }

            int cropHeight = NextP2 (boxes[charCode - 1].Y + boxes[charCode - 1].Height - 1);
            Gdk.Pixbuf pixbuf = new Gdk.Pixbuf (
                image.Data, true, 8,
                image.Width,
                cropHeight,
                image.Stride);

            // manual dispose
            (image as IDisposable).Dispose ();
            (layout as IDisposable).Dispose ();
            (ctx.Target as IDisposable).Dispose ();
            (ctx as IDisposable).Dispose ();

            return pixbuf;
        }
示例#10
0
 public static Point ToPintaPoint(this Cairo.Point point)
 {
     return(new Point(point.X, point.Y));
 }
		public static Cairo.Rectangle GetDiffRectangle (TextEditor editor, int startOffset, int endOffset)
		{
			var point = editor.LocationToPoint (editor.Document.OffsetToLocation (startOffset), true);
			Cairo.Point point2;
			var line = editor.GetLineByOffset (startOffset);
			if (line.Offset + line.Length < endOffset) {
				point2 = new Cairo.Point ((int)(point.X + editor.TextViewMargin.CharWidth * (endOffset - startOffset)), point.Y);
			} else {
				point2 = editor.LocationToPoint (editor.Document.OffsetToLocation (endOffset), true);
			}
			return new Cairo.Rectangle (point.X - editor.TextViewMargin.XOffset, point.Y, point2.X - point.X, editor.LineHeight);
		}
示例#12
0
 protected override void OnDeactivated(Document?document, BaseTool?newTool)
 {
     origin = new Cairo.Point(int.MinValue, int.MinValue);
 }
示例#13
0
 public static bool PointInRect(Cairo.Point p, Cairo.Rectangle rect)
 {
     return(p.X >= rect.X && p.Y >= rect.Y &&
            p.X < rect.X + rect.Width && p.Y < rect.Y + rect.Height);
 }
示例#14
0
        protected override bool OnExposeEvent(Gdk.EventExpose ev)
        {
            base.OnExposeEvent (ev);

            using(Cairo.Context CairoContext = Gdk.CairoHelper.Create(this.GdkWindow)) {
                //Drawing code here.

                //Graph Background
                CairoContext.LineWidth = 1;
                CairoContext.SetSourceRGB(0.2, 0.2, 0.2);
                CairoContext.Rectangle(this.graphRect);
                CairoContext.StrokePreserve();
                CairoContext.SetSourceRGB(1, 1, 1);
                CairoContext.Fill();

                if(this.data.Length <= 0)
                    return true;

                double Min = double.MaxValue;
                double Max = double.MinValue;

                foreach (float FloatItem in this.data) {
                    if(FloatItem > Max)
                        Max = FloatItem;
                    if(FloatItem < Min)
                        Min = FloatItem;
                }

                //XScale
                int XStep = 100 - ((int)(Min - Max) / 100);
                XStep = Math.Max(XStep, 1);
                for (int X = 0; X < this.scaleRectX.Width; X += XStep) {
                    CairoContext.MoveTo(this.scaleRectX.X + X, this.scaleRectX.Y);
                    CairoContext.LineTo(this.scaleRectX.X + X, this.scaleRectX.Y + this.scaleRectX.Height);
                }

                //YScale
                int YStep = 100 - (this.data.Length / 100);
                YStep = Math.Max(YStep, 1);
                for (int Y = 0; Y < this.scaleRectY.Height; Y += YStep) {
                    CairoContext.MoveTo(this.scaleRectY.X, this.scaleRectY.Y + Y);
                    CairoContext.LineTo(this.scaleRectY.X + this.scaleRectY.Width, this.scaleRectY.Y + Y);
                }

                //Graph Line
                CairoContext.LineWidth = 2;
                Cairo.Point LastValue = new Cairo.Point(0, 0);
                CairoContext.SetSourceRGB(0.5, 0.5, 0.5);
                for (int i = 0; i < this.data.Length; i ++) {

                    double X = this.graphRect.X + Scale(i, 0, (double)this.data.Length, 4d, (double)this.graphRect.Width - 8d);
                    double Y = this.graphRect.Y + Scale(this.data[i], Min, Max, (double)this.graphRect.Height - 8d, 4d);

                    if(LastValue.X != 0 && LastValue.Y != 0) {
                        CairoContext.MoveTo(X, Y);
                        CairoContext.LineTo(LastValue.X, LastValue.Y);
                    }
                    LastValue.X = (int)X;
                    LastValue.Y = (int)Y;
                }
                CairoContext.Stroke();

            }

            return true;
        }
示例#15
0
		void OnPopupMenu (object sender, Gtk.ButtonPressEventArgs args)
		{
			if (args.Event.Button == 3) {
				int textEditorXOffset = (int)args.Event.X - (int)this.TextViewMargin.XOffset;
				if (textEditorXOffset < 0)
					return;
				this.menuPopupLocation = new Cairo.Point ((int)args.Event.X, (int)args.Event.Y);
				DocumentLocation loc= PointToLocation (textEditorXOffset, (int)args.Event.Y);
				if (!this.IsSomethingSelected || !this.SelectionRange.Contains (Document.LocationToOffset (loc)))
					Caret.Location = loc;
				
				this.ShowPopup ();
				base.ResetMouseState ();
			}
		}
示例#16
0
 public Rectangle(Cairo.Point point, double width, double height)
 {
     throw null;
 }
示例#17
0
		protected override bool OnKeyPressEvent (Gdk.EventKey evnt)
		{
			isInKeyStroke = true;
			try {
				// Handle keyboard menu popup
				if (evnt.Key == Gdk.Key.Menu || (evnt.Key == Gdk.Key.F10 && (evnt.State & Gdk.ModifierType.ShiftMask) == Gdk.ModifierType.ShiftMask)) {
					this.menuPopupLocation = LocationToPoint (this.Caret.Location);
					this.menuPopupLocation.Y += (int)this.TextViewMargin.LineHeight;
					this.ShowPopup ();
					return true;
				}
				
				// Handle keyboard toolip popup
	/*			if ((evnt.Key == Gdk.Key.F1 && (evnt.State & Gdk.ModifierType.ControlMask) == Gdk.ModifierType.ControlMask)) {
					Gdk.Point p = this.TextViewMargin.LocationToDisplayCoordinates (this.Caret.Location);
					this.mx = p.X;
					this.my = p.Y;
					this.ShowTooltip ();
					return true;
				}
	*/			
				return base.OnKeyPressEvent (evnt);
			} finally {
				isInKeyStroke = false;
			}
		}
示例#18
0
        protected override bool OnExposeEvent(Gdk.EventExpose ev)
        {
            base.OnExposeEvent(ev);

            using (Cairo.Context CairoContext = Gdk.CairoHelper.Create(this.GdkWindow)) {
                //Drawing code here.

                //Graph Background
                CairoContext.LineWidth = 1;
                CairoContext.SetSourceRGB(0.2, 0.2, 0.2);
                CairoContext.Rectangle(this.graphRect);
                CairoContext.StrokePreserve();
                CairoContext.SetSourceRGB(1, 1, 1);
                CairoContext.Fill();

                if (this.data.Length <= 0)
                {
                    return(true);
                }

                double Min = double.MaxValue;
                double Max = double.MinValue;

                foreach (float FloatItem in this.data)
                {
                    if (FloatItem > Max)
                    {
                        Max = FloatItem;
                    }
                    if (FloatItem < Min)
                    {
                        Min = FloatItem;
                    }
                }

                //XScale
                int XStep = 100 - ((int)(Min - Max) / 100);
                XStep = Math.Max(XStep, 1);
                for (int X = 0; X < this.scaleRectX.Width; X += XStep)
                {
                    CairoContext.MoveTo(this.scaleRectX.X + X, this.scaleRectX.Y);
                    CairoContext.LineTo(this.scaleRectX.X + X, this.scaleRectX.Y + this.scaleRectX.Height);
                }

                //YScale
                int YStep = 100 - (this.data.Length / 100);
                YStep = Math.Max(YStep, 1);
                for (int Y = 0; Y < this.scaleRectY.Height; Y += YStep)
                {
                    CairoContext.MoveTo(this.scaleRectY.X, this.scaleRectY.Y + Y);
                    CairoContext.LineTo(this.scaleRectY.X + this.scaleRectY.Width, this.scaleRectY.Y + Y);
                }

                //Graph Line
                CairoContext.LineWidth = 2;
                Cairo.Point LastValue = new Cairo.Point(0, 0);
                CairoContext.SetSourceRGB(0.5, 0.5, 0.5);
                for (int i = 0; i < this.data.Length; i++)
                {
                    double X = this.graphRect.X + Scale(i, 0, (double)this.data.Length, 4d, (double)this.graphRect.Width - 8d);
                    double Y = this.graphRect.Y + Scale(this.data[i], Min, Max, (double)this.graphRect.Height - 8d, 4d);

                    if (LastValue.X != 0 && LastValue.Y != 0)
                    {
                        CairoContext.MoveTo(X, Y);
                        CairoContext.LineTo(LastValue.X, LastValue.Y);
                    }
                    LastValue.X = (int)X;
                    LastValue.Y = (int)Y;
                }
                CairoContext.Stroke();
            }

            return(true);
        }