Esempio n. 1
0
        void Render(Cairo.Context context)
        {
            var hourRadians = (time.Hour % 12 + time.Minute / 60F) * 30 * Math.PI / 180;

            DrawHand(3, hourLength, hourColor, hourRadians, context);

            var minuteRadians = (time.Minute) * 6 * Math.PI / 180;

            DrawHand(2, minuteLength, minuteColor, minuteRadians, context);

            var secondRadians = (time.Second) * 6 * Math.PI / 180;

            DrawHand(1, secondLength, secondColor, secondRadians, context);

            for (int i = 0; i < 60; i++)
            {
                if (i % 5 == 0)
                {
                    var p1 = new Cairo.PointD(center.X + (radius / 1.50 * Math.Sin(i * 6 * Math.PI / 180)), center.Y - (radius / 1.50 * Math.Cos(i * 6 * Math.PI / 180)));
                    var p2 = new Cairo.PointD(center.X + (radius / 1.65 * Math.Sin(i * 6 * Math.PI / 180)), center.Y - (radius / 1.65 * Math.Cos(i * 6 * Math.PI / 180)));
                    context.LineWidth = 1;
                    context.Color     = ticksColor;
                    context.MoveTo(p1);
                    context.LineTo(p2);
                    context.ClosePath();
                    context.Stroke();
                }
                else
                {
                    var p1 = new Cairo.PointD(center.X + (radius / 1.50 * Math.Sin(i * 6 * Math.PI / 180)), center.Y - (radius / 1.50 * Math.Cos(i * 6 * Math.PI / 180)));
                    var p2 = new Cairo.PointD(center.X + (radius / 1.55 * Math.Sin(i * 6 * Math.PI / 180)), center.Y - (radius / 1.55 * Math.Cos(i * 6 * Math.PI / 180)));
                    context.LineWidth = 1;
                    context.Color     = ticksColor;
                    context.MoveTo(p1);
                    context.LineTo(p2);
                    context.ClosePath();
                    context.Stroke();
                }
            }
            //DrawFace (center, (radius / 2) + 17, e);
            //DrawFace (center, 8, e);
        }
Esempio n. 2
0
        public void DrawLine(Cairo.Context cr, PlotColor color, int x1, int y1, int x2, int y2)
        {
            cr.MoveTo(x1 + DEFUZZ, y1 + DEFUZZ);
            cr.LineTo(x2 + DEFUZZ, y2 + DEFUZZ);

            //cr.Color = colors[(int)color];
            cr.SetSourceRGBA(colors[(int)color].R, colors[(int)color].G, colors[(int)color].B, colors[(int)color].A);

            cr.LineWidth = 1.0f;
            cr.Stroke();
        }
Esempio n. 3
0
 public static void RenderCircle(Cairo.Context g, Cairo.Color c, double r, double x, double y)
 {
     g.Save();
     g.Color = c;
     g.MoveTo(x, y);
     g.Arc(x, y, r, 0, 6.28);
     g.LineWidth = 3;
     g.ClosePath();
     g.Fill();
     g.Restore();
 }
Esempio n. 4
0
        void DrawBlockBg(Cairo.Context ctx, double x, int width, BlockInfo block)
        {
            if (!IsChangeBlock(block.Type))
            {
                return;
            }

            x += 0.5;
            Gdk.Color color  = block.Type == BlockType.Added ? baseAddColor : baseRemoveColor;
            double    y      = block.YStart + 0.5;
            int       height = block.YEnd - block.YStart;

            double markerx = x + LeftPaddingBlock - 0.5;
            double rd      = RoundedSectionRadius;

            if (block.SectionStart)
            {
                ctx.Arc(x + rd, y + rd, rd, 180 * (Math.PI / 180), 270 * (Math.PI / 180));
                ctx.LineTo(markerx, y);
            }
            else
            {
                ctx.MoveTo(markerx, y);
            }

            ctx.LineTo(markerx, y + height);

            if (block.SectionEnd)
            {
                ctx.LineTo(x + rd, y + height);
                ctx.Arc(x + rd, y + height - rd, rd, 90 * (Math.PI / 180), 180 * (Math.PI / 180));
            }
            else
            {
                ctx.LineTo(x, y + height);
            }
            if (block.SectionStart)
            {
                ctx.LineTo(x, y + rd);
            }
            else
            {
                ctx.LineTo(x, y);
            }
            ctx.Color = color.AddLight(0.1).ToCairoColor();
            ctx.Fill();

            ctx.Rectangle(markerx, y, width - markerx, height);
            Cairo.Gradient pat = new Cairo.LinearGradient(x, y, x + width, y);
            pat.AddColorStop(0, color.AddLight(0.21).ToCairoColor());
            pat.AddColorStop(1, color.AddLight(0.3).ToCairoColor());
            ctx.Pattern = pat;
            ctx.Fill();
        }
Esempio n. 5
0
        public override void Draw(Cairo.Context context)
        {
            context.MoveTo(_points[0].X, _points[0].Y);

            foreach (var point in _points)
            {
                context.LineTo(point.X, point.Y);
            }

            context.ClosePath();
        }
Esempio n. 6
0
        private static void MakeSquare(Cairo.Context context, Point scale, Point item, double msize, double lw)
        {
            double size = msize - lw;

            context.MoveTo(item.X * scale.X, item.Y * scale.Y);
            context.RelMoveTo(-size / 2, -size / 2);
            context.RelLineTo(size, 0);
            context.RelLineTo(0, size);
            context.RelLineTo(-size, 0);
            context.ClosePath();
        }
Esempio n. 7
0
 void DrawHand(double fThickness, double length, Cairo.Color color, double radians, Cairo.Context e)
 {
     e.MoveTo(new Cairo.PointD(center.X - (length / 9 * Math.Sin(radians)), center.Y + (length / 9 * Math.Cos(radians))));
     e.LineTo(new Cairo.PointD(center.X + (length * Math.Sin(radians)), center.Y - (length * Math.Cos(radians))));
     e.ClosePath();
     e.LineCap   = Cairo.LineCap.Round;
     e.LineJoin  = Cairo.LineJoin.Round;
     e.Color     = color;
     e.LineWidth = fThickness;
     e.Stroke();
 }
Esempio n. 8
0
        protected override void onDraw(Cairo.Context gr)
        {
            base.onDraw(gr);
            Foreground.SetAsSource(gr);
            Rectangle r = ClientRectangle;
            double    x = r.Center.X - 0.5;
            double    y;

            gr.LineWidth = 1;
            gr.MoveTo(x, r.Y);
            gr.LineTo(x, r.Bottom - 8);

            for (y = 8.5 + r.Y; y < r.Bottom; y += 18)
            {
                gr.MoveTo(x, y);
                gr.LineTo(x * 2, y);
            }

            gr.Stroke();
        }
Esempio n. 9
0
        /// <summary>
        /// Renders the pager text using the results of SetupPagerText.
        /// </summary>
        protected virtual void RenderPagerText(Cairo.Context context, Pango.Layout layout, Gdk.Rectangle bounds)
        {
            int w, h;

            layout.GetPixelSize(out w, out h);

            context.MoveTo(bounds.X + (bounds.Width - w) / 2, bounds.Y + (bounds.Height - h) / 2);

            context.SetSourceColor(PagerTextColor);
            Pango.CairoHelper.ShowLayout(context, layout);
        }
Esempio n. 10
0
		static void DrawRectangle (Cairo.Context g, double x, double y, double width, double height)
		{
			double right = x + width;
			double bottom = y + height;
			g.MoveTo (new Cairo.PointD (x, y));
			g.LineTo (new Cairo.PointD (right, y));
			g.LineTo (new Cairo.PointD (right, bottom));
			g.LineTo (new Cairo.PointD (x, bottom));
			g.LineTo (new Cairo.PointD (x, y));
			g.ClosePath ();
		}
Esempio n. 11
0
 internal static void DrawLine(this Cairo.Context g, Point p0, Point p1, float width, Color color)
 {
     g.NewPath();
     g.Save();
     g.SetSourceColor(color);
     g.LineWidth = width;
     g.MoveTo(p0.ToPointD());
     g.LineTo(p1.ToPointD());
     g.Stroke();
     g.Restore();
 }
Esempio n. 12
0
        public override void Draw(Cairo.Context surface, int x, int y)
        {
            X = x;
            Y = y;
            int waveTops    = Radius / 3;
            int waveBottoms = Radius / 2;
            int waveDepths  = Radius / 6;

            WaterTemperature = CurrentData.GetCurrentValueByIdFloat(XIVELY_DATA_STREAM_ID);
            //WaterTemperature = WaterTemperature / 100;


            // CIRCLE
            surface.SetSourceRGBA(1, 1, 1, 0.3);
            surface.Arc(X, Y, Radius, 0, Math.PI * 2);
            surface.Fill();

            surface.SetSourceRGBA(1, 1, 1, WaterLight);
            surface.Arc(X, Y, Radius + 5, 0, Math.PI * 2);
            surface.Stroke();
            surface.Fill();

            // WAVEFORMED CIRCLE
            surface.CurveTo(X - Radius, Y - waveDepths, X - waveBottoms, Y + waveDepths, X - waveTops, Y - waveDepths);
            surface.CurveTo(X - waveTops, Y - waveDepths, X, Y + waveDepths, X + waveTops, Y - waveDepths);
            surface.CurveTo(X + waveTops, Y - waveDepths, X + waveBottoms, Y + waveDepths, X + Radius, Y - waveDepths);
            surface.SetSourceRGBA(colorWater[0], colorWater[1], colorWater[2], alphaChannel);
            surface.Arc(X, Y, Radius, 0, Math.PI * 1);
            surface.Fill();

            // TEXT
            surface.SetSourceRGBA(1, 1, 1, 0.1);
            surface.MoveTo(X, Y);
            surface.SetFontSize(Radius / 2);
            string widgetText = Convert.ToString(WaterTemperature);

            Cairo.TextExtents text = surface.TextExtents(widgetText);
            surface.MoveTo(X - (text.Width / 2), Y + (text.Height / 2));
            surface.ShowText(widgetText);
            surface.Fill();
        }
        /*
         * static double min (params double[] arr)
         * {
         *      int minp = 0;
         *      for (int i = 1; i < arr.Length; i++)
         *              if (arr[i] < arr[minp])
         *                      minp = i;
         *      return arr[minp];
         * }*/

        static void DrawRectangle(Cairo.Context g, int x, int y, int width, int height)
        {
            int right  = x + width;
            int bottom = y + height;

            g.MoveTo(new Cairo.PointD(x, y));
            g.LineTo(new Cairo.PointD(right, y));
            g.LineTo(new Cairo.PointD(right, bottom));
            g.LineTo(new Cairo.PointD(x, bottom));
            g.LineTo(new Cairo.PointD(x, y));
            g.ClosePath();
        }
Esempio n. 14
0
        void DrawTriangle(Cairo.Context ctx, int x, int y, double scale)
        {
            int width  = (int)(scale * dropdownTriangleWidth);
            int height = (int)(scale * dropdownTriangleHeight);

            SetSourceColor(ctx, triangleColor.ToCairoColor());
            ctx.MoveTo(x, y);
            ctx.LineTo(x + width, y);
            ctx.LineTo(x + (width / 2), y + height);
            ctx.LineTo(x, y);
            ctx.Fill();
        }
Esempio n. 15
0
 protected void DrawDiamond(Cairo.Context cr, double x, double y, double size)
 {
     x    += 0.5; y += 0.5;
     size -= 2;
     cr.NewPath();
     cr.MoveTo(x + size / 2, y);
     cr.LineTo(x + size, y + size / 2);
     cr.LineTo(x + size / 2, y + size);
     cr.LineTo(x, y + size / 2);
     cr.LineTo(x + size / 2, y);
     cr.ClosePath();
 }
        void DrawTriangle(Cairo.Context ctx, int x, int y)
        {
            int width  = dropdownTriangleWidth;
            int height = dropdownTriangleHeight;

            SetSourceColor(ctx, Styles.NewProjectDialog.TemplateLanguageButtonTriangle.ToCairoColor());
            ctx.MoveTo(x, y);
            ctx.LineTo(x + width, y);
            ctx.LineTo(x + (width / 2), y + height);
            ctx.LineTo(x, y);
            ctx.Fill();
        }
 protected void DrawLeftBorder(Cairo.Context cr)
 {
     cr.MoveTo(0.5, 1.5);
     cr.LineTo(0.5, Allocation.Height - 1);
     if (TextEditor.ColorStyle != null)
     {
         var col = (HslColor)TextEditor.ColorStyle.Default.CairoBackgroundColor;
         col.L   *= 0.88;
         cr.Color = col;
     }
     cr.Stroke();
 }
Esempio n. 18
0
        void DrawVersionNumber(Cairo.Context c, ref Cairo.PointD bottomRight, string text)
        {
            c.SelectFontFace(SplashFontFamily, Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
            c.SetFontSize(SplashFontSize);

            var extents = c.TextExtents(text);

            c.MoveTo(bottomRight.X - extents.Width - 1, bottomRight.Y - extents.Height);

            c.SetSourceRGB(1, 1, 1);
            c.ShowText(text);
        }
Esempio n. 19
0
 protected void paintSniffer(Cairo.Context context, Monster monster)
 {
     context.Save();
     context.Translate(monster.X, monster.Y);
     rotateContext(context, monster.Direction);
     context.Arc(fieldSize / 2, fieldSize / 2, fieldSize / 3, 0, 2 * Math.PI);
     context.FillPreserve();
     context.MoveTo(0, 0);
     context.LineTo(fieldSize, fieldSize);
     context.Stroke();
     context.NewPath();
     context.MoveTo(fieldSize, 0);
     context.LineTo(0, fieldSize);
     context.Stroke();
     context.NewPath();
     context.MoveTo(0, fieldSize / 2);
     context.LineTo(fieldSize, fieldSize / 2);
     context.Stroke();
     context.NewPath();
     context.Restore();
 }
Esempio n. 20
0
        void DrawClosedFolding(Cairo.Context cr, Cairo.Color col, double x, double y)
        {
            var drawArea = new Cairo.Rectangle(System.Math.Floor(x + (Width - foldSegmentSize) / 2) + 0.5,
                                               System.Math.Floor(y + (editor.LineHeight - foldSegmentSize) / 2) + 0.5, foldSegmentSize, foldSegmentSize);

            cr.MoveTo(new Cairo.PointD(drawArea.X, drawArea.Y));
            cr.LineTo(new Cairo.PointD(drawArea.X, drawArea.Y + drawArea.Height));
            cr.LineTo(new Cairo.PointD(drawArea.X + drawArea.Width, drawArea.Y + drawArea.Height / 2));
            cr.ClosePath();
            cr.Color = GetColor(col);
            cr.Fill();
        }
Esempio n. 21
0
        /* private methods */
        private void DrawPointGlyph(Cairo.Context cr, PointShape type, float x, float y, float side_size)
        {
            float half_size = side_size / 2;

            switch (type)
            {
            case PointShape.Square:
                cr.Rectangle(x - half_size, y - half_size,
                             side_size, side_size);
                break;

            case PointShape.Circle:
                cr.MoveTo(x + half_size, y);
                cr.Arc(x, y, half_size, 0, 2 * Math.PI);
                cr.ClosePath();
                break;

            case PointShape.Diamond:
                cr.MoveTo(x - half_size, y);
                cr.LineTo(x, y - half_size);
                cr.LineTo(x + half_size, y);
                cr.LineTo(x, y + half_size);
                cr.ClosePath();
                break;

            case PointShape.Triangle:
                cr.MoveTo(x - half_size, y + half_size);
                cr.LineTo(x, y - half_size);
                cr.LineTo(x + half_size, y + half_size);
                cr.ClosePath();
                break;

            case PointShape.X:
                cr.MoveTo(x - half_size, y - half_size);
                cr.LineTo(x + half_size, y + half_size);
                cr.MoveTo(x + half_size, y - half_size);
                cr.LineTo(x - half_size, y + half_size);
                break;
            }
        }
Esempio n. 22
0
        public static void RenderInvertedTriangle(Cairo.Context g, Cairo.Color c, double x, double y, int side)
        {
            g.Save();

            g.Color = c;
            g.MoveTo(x, y);
            g.LineTo(x - side / 2, y - side);
            g.LineTo(x + side / 2, y - side);
            g.LineTo(x, y);
            g.Fill();

            g.Restore();
        }
Esempio n. 23
0
        public override void Draw(Cairo.Context context)
        {
            Cairo.Matrix oldMatrix = context.Matrix;
            double       a         = MinorAxis / _majorAxis;

            context.Translate(0.0, _position.Y * (1 - a));
            context.Scale(1.0, a);
            context.MoveTo(_position.X + _majorAxis, _position.Y);
            context.Arc(_position.X, _position.Y, _majorAxis, 0.0, 2 * Math.PI);
            context.ClosePath();
            //todo change in order to process rotated ellipses (i.e. MajorAxis is collinear with OY)
            context.Matrix = oldMatrix;
        }
Esempio n. 24
0
			protected override void Render (Gdk.Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags)
			{
				using (Cairo.Context cr = Gdk.CairoHelper.Create (window)) {
					cr.LineWidth = 2.0;
					double center_x = cell_area.X + Math.Round ((double) (cell_area.Width / 2d));
					double center_y = cell_area.Y + Math.Round ((double) (cell_area.Height / 2d));
					cr.Arc (center_x, center_y, 5, 0, 2 * Math.PI);
					cr.Color = new Cairo.Color (0, 0, 0);
					cr.Stroke ();
					if (!FirstNode) {
						cr.MoveTo (center_x, cell_area.Y - 2);
						cr.LineTo (center_x, center_y - 5);
						cr.Stroke ();
					}
					
					if (!LastNode) {
						cr.MoveTo (center_x, cell_area.Y + cell_area.Height + 2);
						cr.LineTo (center_x, center_y + 5);
						cr.Stroke ();
					}
				}
			}
Esempio n. 25
0
        /// <summary>
        /// Renders a single pager arrow inside a bounding box.
        /// </summary>
        protected virtual void RenderPagerArrow(Cairo.Context context, Gdk.Rectangle bounds, ArrowType direction)
        {
            switch (direction)
            {
            case ArrowType.Up:
                context.MoveTo(bounds.X + bounds.Width / 2.0, bounds.Y);
                context.LineTo(bounds.X, bounds.Y + bounds.Height);
                context.LineTo(bounds.X + bounds.Width, bounds.Y + bounds.Height);
                context.ClosePath();
                break;

            case ArrowType.Down:
                context.MoveTo(bounds.X + bounds.Width / 2.0, bounds.Y + bounds.Height);
                context.LineTo(bounds.X, bounds.Y);
                context.LineTo(bounds.X + bounds.Width, bounds.Y);
                context.ClosePath();
                break;

            case ArrowType.Left:
                context.MoveTo(bounds.X, bounds.Y + bounds.Height / 2.0);
                context.LineTo(bounds.X + bounds.Width, bounds.Y);
                context.LineTo(bounds.X + bounds.Width, bounds.Y + bounds.Height);
                context.ClosePath();
                break;

            case ArrowType.Right:
                context.MoveTo(bounds.X + bounds.Width, bounds.Y + bounds.Height / 2.0);
                context.LineTo(bounds.X, bounds.Y);
                context.LineTo(bounds.X, bounds.Y + bounds.Height);
                context.ClosePath();
                break;

            default:
                return;
            }

            context.SetSourceColor(PagerTriangleColor);
            context.Fill();
        }
Esempio n. 26
0
            protected override void Render(Gdk.Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags)
            {
                using (Cairo.Context cr = Gdk.CairoHelper.Create(window)) {
                    cr.Arc(cell_area.X + cell_area.Width / 2, cell_area.Y + cell_area.Height / 2, 5, 0, 2 * Math.PI);
                    cr.Color = new Cairo.Color(0, 0, 0);
                    cr.Stroke();
                    double h = (cell_area.Height - 10) / 2;
                    if (!FirstNode)
                    {
                        cr.MoveTo(cell_area.X + cell_area.Width / 2, cell_area.Y - 1);
                        cr.LineTo(cell_area.X + cell_area.Width / 2, cell_area.Y + h);
                        cr.Stroke();
                    }

                    if (!LastNode)
                    {
                        cr.MoveTo(cell_area.X + cell_area.Width / 2, cell_area.Y + cell_area.Height + 1);
                        cr.LineTo(cell_area.X + cell_area.Width / 2, cell_area.Y + cell_area.Height - h);
                        cr.Stroke();
                    }
                }
            }
Esempio n. 27
0
        public virtual void Render(Drawable window, Cairo.Context ctx, Rectangle bounds, StateType state)
        {
            int w, h;

            layout.GetPixelSize(out w, out h);
            int dy = (bounds.Height - h) / 2;

            ctx.Save();
            ctx.SetSourceColor(container.Style.Text(state).ToCairoColor());
            ctx.MoveTo(bounds.X, dy + bounds.Y);
            Pango.CairoHelper.ShowLayout(ctx, layout);
            ctx.Restore();
        }
Esempio n. 28
0
        private static void DrawArrow(Cairo.Context graphics, double x, double y, double pos)
        {
            graphics.MoveTo(x, y);
            graphics.Rotate(pos);
            graphics.RelMoveTo(0, (pos + 0.5 * System.Math.PI < System.Math.PI ? -1 : 1) * s_arrowSize / 2);

            graphics.RelLineTo(-s_arrowSize, 0);
            graphics.RelLineTo(s_arrowSize, -s_arrowSize);
            graphics.RelLineTo(s_arrowSize, s_arrowSize);
            graphics.RelLineTo(-s_arrowSize, 0);

            graphics.Fill();
        }
Esempio n. 29
0
        public override void Draw(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics)
        {
            var color = SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.FoldLine);

            cr.SetSourceColor(color);

            cr.LineWidth = 1 * editor.Options.Zoom;
            var y = metrics.LineYRenderStartPosition;

            cr.MoveTo(metrics.TextRenderStartPosition, y + metrics.LineHeight - 1.5);
            cr.LineTo(editor.Allocation.Width, y + metrics.LineHeight - 1.5);
            cr.Stroke();
        }
Esempio n. 30
0
        void DrawTab(Gdk.EventExpose evnt, Tab tab, int pos)
        {
            Gdk.Rectangle rect = GetTabArea(tab, pos);
            StateType     st;

            if (tab.Active)
            {
                st = StateType.Normal;
            }
            else
            {
                st = StateType.Active;
            }

            if (DockFrame.IsWindows)
            {
                GdkWindow.DrawRectangle(Style.DarkGC(Gtk.StateType.Normal), false, rect);
                rect.X++;
                rect.Width--;
                if (tab.Active)
                {
                    GdkWindow.DrawRectangle(Style.LightGC(Gtk.StateType.Normal), true, rect);
                }
                else
                {
                    using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window))
                    {
                        cr.NewPath();
                        cr.MoveTo(rect.X, rect.Y);
                        cr.RelLineTo(rect.Width, 0);
                        cr.RelLineTo(0, rect.Height);
                        cr.RelLineTo(-rect.Width, 0);
                        cr.RelLineTo(0, -rect.Height);
                        cr.ClosePath();
                        Cairo.Gradient pat    = new Cairo.LinearGradient(rect.X, rect.Y, rect.X, rect.Y + rect.Height);
                        Cairo.Color    color1 = DockFrame.ToCairoColor(Style.Mid(Gtk.StateType.Normal));
                        pat.AddColorStop(0, color1);
                        color1.R *= 1.2;
                        color1.G *= 1.2;
                        color1.B *= 1.2;
                        pat.AddColorStop(1, color1);
                        cr.Pattern = pat;
                        cr.FillPreserve();
                    }
                }
            }
            else
            {
                Gtk.Style.PaintExtension(Style, GdkWindow, st, ShadowType.Out, evnt.Area, this, "tab", rect.X, rect.Y, rect.Width, rect.Height, Gtk.PositionType.Top);
            }
        }
Esempio n. 31
0
        /// <summary>
        /// Draws the text.
        /// </summary>
        /// <param name="showCursor">Whether or not to show the mouse cursor in the drawing.</param>
        /// <param name="useTextLayer">Whether or not to use the TextLayer (as opposed to the Userlayer).</param>
        private void RedrawText(bool showCursor, bool useTextLayer)
        {
            Rectangle r = CurrentTextEngine.GetLayoutBounds();
            r.Inflate(10 + OutlineWidth, 10 + OutlineWidth);
            CurrentTextBounds = r;

            Rectangle cursorBounds = Rectangle.Zero;

            Cairo.ImageSurface surf;

            if (!useTextLayer)
            {
                //Draw text on the current UserLayer's surface as finalized text.
                surf = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.Surface;
            }
            else
            {
                //Draw text on the current UserLayer's TextLayer's surface as re-editable text.
                surf = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.TextLayer.Surface;

                ClearTextLayer();
            }

            using (var g = new Cairo.Context (surf)) {
                g.Save ();

                // Show selection if on text layer
                if (useTextLayer) {
                    // Selected Text
                    Cairo.Color c = new Cairo.Color (0.7, 0.8, 0.9, 0.5);
                    foreach (Rectangle rect in CurrentTextEngine.SelectionRectangles)
                        g.FillRectangle (rect.ToCairoRectangle (), c);
                }
                g.AppendPath (PintaCore.Workspace.ActiveDocument.Selection.SelectionPath);
                g.FillRule = Cairo.FillRule.EvenOdd;
                g.Clip ();

                g.MoveTo (new Cairo.PointD (CurrentTextEngine.Origin.X, CurrentTextEngine.Origin.Y));

                g.Color = PintaCore.Palette.PrimaryColor;

                //Fill in background
                if (BackgroundFill) {
                    using (var g2 = new Cairo.Context (surf)) {
                        g2.FillRectangle(CurrentTextEngine.GetLayoutBounds().ToCairoRectangle(), PintaCore.Palette.SecondaryColor);
                    }
                }

                // Draw the text
                if (FillText)
                    Pango.CairoHelper.ShowLayout (g, CurrentTextEngine.Layout);

                if (FillText && StrokeText) {
                    g.Color = PintaCore.Palette.SecondaryColor;
                    g.LineWidth = OutlineWidth;

                    Pango.CairoHelper.LayoutPath (g, CurrentTextEngine.Layout);
                    g.Stroke ();
                } else if (StrokeText) {
                    g.Color = PintaCore.Palette.PrimaryColor;
                    g.LineWidth = OutlineWidth;

                    Pango.CairoHelper.LayoutPath (g, CurrentTextEngine.Layout);
                    g.Stroke ();
                }

                if (showCursor) {
                    var loc = CurrentTextEngine.GetCursorLocation ();

                    g.Antialias = Cairo.Antialias.None;
                    g.DrawLine (new Cairo.PointD (loc.X, loc.Y), new Cairo.PointD (loc.X, loc.Y + loc.Height), new Cairo.Color (0, 0, 0, 1), 1);

                    cursorBounds = Rectangle.Inflate (loc, 2, 10);
                }

                g.Restore ();

                if (useTextLayer && (is_editing || ctrlKey) && !CurrentTextEngine.IsEmpty())
                {
                    //Draw the text edit rectangle.

                    g.Save();

                    g.Translate(.5, .5);

                    using (Cairo.Path p = g.CreateRectanglePath(new Cairo.Rectangle(CurrentTextBounds.Left, CurrentTextBounds.Top,
                        CurrentTextBounds.Width, CurrentTextBounds.Height - FontSize)))
                    {
                        g.AppendPath(p);
                    }

                    g.LineWidth = 1;

                    g.Color = new Cairo.Color(1, 1, 1);
                    g.StrokePreserve();

                    g.SetDash(new double[] { 2, 4 }, 0);
                    g.Color = new Cairo.Color(1, .1, .2);

                    g.Stroke();

                    g.Restore();
                }
            }

            InflateAndInvalidate(PintaCore.Workspace.ActiveDocument.CurrentUserLayer.previousTextBounds);
            PintaCore.Workspace.Invalidate(old_cursor_bounds);
            PintaCore.Workspace.Invalidate(r);
            PintaCore.Workspace.Invalidate(cursorBounds);

            old_cursor_bounds = cursorBounds;
        }
Esempio n. 32
0
        internal static Gdk.Pixbuf CreateBitmap(string stockId, double width, double height, double scaleFactor)
        {
            Gdk.Pixbuf result = null;

            Gtk.IconSet iconset = Gtk.IconFactory.LookupDefault (stockId);
            if (iconset != null) {
                // Find the size that better fits the requested size
                Gtk.IconSize gsize = Util.GetBestSizeFit (width);
                result = iconset.RenderIcon (Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize, null, null, scaleFactor);
                if (result == null || result.Width < width * scaleFactor) {
                    var gsize2x = Util.GetBestSizeFit (width * scaleFactor, iconset.Sizes);
                    if (gsize2x != Gtk.IconSize.Invalid && gsize2x != gsize)
                        // Don't dispose the previous result since the icon is owned by the IconSet
                        result = iconset.RenderIcon (Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize2x, null, null);
                }
            }

            if (result == null && Gtk.IconTheme.Default.HasIcon (stockId))
                result = Gtk.IconTheme.Default.LoadIcon (stockId, (int)width, (Gtk.IconLookupFlags)0);

            if (result == null)
            {
                // render a custom gtk-missing-image icon
                // if Gtk.Stock.MissingImage is not found
                int w = (int)width;
                int h = (int)height;
                #if XWT_GTK3
                Cairo.ImageSurface s = new Cairo.ImageSurface(Cairo.Format.ARGB32, w, h);
                Cairo.Context cr = new Cairo.Context(s);
                cr.SetSourceRGB(255, 255, 255);
                cr.Rectangle(0, 0, w, h);
                cr.Fill();
                cr.SetSourceRGB(0, 0, 0);
                cr.LineWidth = 1;
                cr.Rectangle(0.5, 0.5, w - 1, h - 1);
                cr.Stroke();
                cr.SetSourceRGB(255, 0, 0);
                cr.LineWidth = 3;
                cr.LineCap = Cairo.LineCap.Round;
                cr.LineJoin = Cairo.LineJoin.Round;
                cr.MoveTo(w / 4, h / 4);
                cr.LineTo((w - 1) - w / 4, (h - 1) - h / 4);
                cr.MoveTo(w / 4, (h - 1) - h / 4);
                cr.LineTo((w - 1) - w / 4, h / 4);
                cr.Stroke();
                result = Gtk3Extensions.GetFromSurface(s, 0, 0, w, h);
                #else
                using (Gdk.Pixmap pmap = new Gdk.Pixmap (Gdk.Screen.Default.RootWindow, w, h))
                using (Gdk.GC gc = new Gdk.GC (pmap)) {
                    gc.RgbFgColor = new Gdk.Color (255, 255, 255);
                    pmap.DrawRectangle (gc, true, 0, 0, w, h);
                    gc.RgbFgColor = new Gdk.Color (0, 0, 0);
                    pmap.DrawRectangle (gc, false, 0, 0, (w - 1), (h - 1));
                    gc.SetLineAttributes (3, Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round);
                    gc.RgbFgColor = new Gdk.Color (255, 0, 0);
                    pmap.DrawLine (gc, (w / 4), (h / 4), ((w - 1) - (w / 4)), ((h - 1) - (h / 4)));
                    pmap.DrawLine (gc, ((w - 1) - (w / 4)), (h / 4), (w / 4), ((h - 1) - (h / 4)));
                    result = Gdk.Pixbuf.FromDrawable (pmap, pmap.Colormap, 0, 0, 0, 0, w, h);
                }
                #endif
            }
            return result;
        }
Esempio n. 33
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            if (!painting || offset.IsNotSet ())
                return;

            int x = (int)point.X;
            int y = (int)point.Y;

            if (last_point.IsNotSet ()) {
                last_point = new Point (x, y);
                return;
            }

            using (Cairo.Context g = new Cairo.Context (PintaCore.Layers.ToolLayer.Surface)) {
                g.AppendPath (PintaCore.Layers.SelectionPath);
                g.FillRule = Cairo.FillRule.EvenOdd;
                g.Clip ();

                g.Antialias = Cairo.Antialias.Subpixel;

                g.MoveTo (last_point.X, last_point.Y);
                g.LineTo (x, y);

                g.SetSource (PintaCore.Workspace.ActiveDocument.CurrentLayer.Surface, offset.X, offset.Y);
                g.LineWidth = BrushWidth;
                g.LineCap = Cairo.LineCap.Round;

                g.Stroke ();
            }

            var dirty_rect = GetRectangleFromPoints (last_point, new Point (x, y));

            last_point = new Point (x, y);
            surface_modified = true;
            PintaCore.Workspace.Invalidate (dirty_rect);
        }
Esempio n. 34
0
        private void RedrawText(bool showCursor, bool useToolLayer)
        {
            Cairo.ImageSurface surf;
            var invalidate_cursor = old_cursor_bounds;

            if (!useToolLayer)
                surf = PintaCore.Workspace.ActiveDocument.CurrentLayer.Surface;
            else {
                surf = PintaCore.Workspace.ActiveDocument.ToolLayer.Surface;
                surf.Clear ();
            }

            using (var g = new Cairo.Context (surf)) {
                g.Save ();

                // Show selection if on tool layer
                if (useToolLayer) {
                    // Selected Text
                    Cairo.Color c = new Cairo.Color (0.7, 0.8, 0.9, 0.5);
                    foreach (Rectangle rect in engine.SelectionRectangles)
                        g.FillRectangle (rect.ToCairoRectangle (), c);
                }
                g.AppendPath (PintaCore.Workspace.ActiveDocument.SelectionPath);
                g.FillRule = Cairo.FillRule.EvenOdd;
                g.Clip ();
                g.MoveTo (new Cairo.PointD (engine.Origin.X, engine.Origin.Y));
                g.Color = PintaCore.Palette.PrimaryColor;

                if (BackgroundFill)	{

                    using (var g2 = new Cairo.Context (surf)) {

                        g2.FillRectangle (engine.GetLayoutBounds ().ToCairoRectangle (),PintaCore.Palette.SecondaryColor);

                    }
            }

                if (FillText) {
                    Pango.CairoHelper.ShowLayout (g, engine.Layout);
            }

                if (FillText && StrokeText) {
                    g.Color = PintaCore.Palette.SecondaryColor;
                    g.LineWidth = OutlineWidth;

                    Pango.CairoHelper.LayoutPath (g, engine.Layout);
                    g.Stroke ();
                } else if (StrokeText) {
                    g.Color = PintaCore.Palette.PrimaryColor;
                    g.LineWidth = OutlineWidth;

                    Pango.CairoHelper.LayoutPath (g, engine.Layout);
                    g.Stroke ();
                }

                if (showCursor) {
                    var loc = engine.GetCursorLocation ();

                    g.Antialias = Cairo.Antialias.None;
                    g.DrawLine (new Cairo.PointD (loc.X, loc.Y), new Cairo.PointD (loc.X, loc.Y + loc.Height), new Cairo.Color (0, 0, 0, 1), 1);

                    loc.Inflate (2, 10);
                    old_cursor_bounds = loc;
                }

                g.Restore ();
            }

            Rectangle r = engine.GetLayoutBounds ();
            r.Inflate (10 + OutlineWidth, 10 + OutlineWidth);

            PintaCore.Workspace.Invalidate (old_bounds);
            PintaCore.Workspace.Invalidate (invalidate_cursor);
            PintaCore.Workspace.Invalidate (r);

            old_bounds = r;
        }
Esempio n. 35
0
        protected Gdk.Pixbuf DrawConstDataIcon()
        {
            using (var surface = new Cairo.ImageSurface (Cairo.Format.Argb32, rectSizing.Width, rectSizing.Height)) {
                using (Cairo.Context cr = new Cairo.Context (surface)) {
                    // background
                    cr.SetSourceRGB (0.7, 0.7, 0.7);
                    cr.Paint ();

                    // text
                    cr.SetSourceRGB (1, 0, 0);
                    // simple Cairo text API instead of Pango
                    //cr.MoveTo (10, 0.3 * height);
                    //cr.SetFontSize (20);
                    //cr.ShowText ("const");

                    using (var layout = Pango.CairoHelper.CreateLayout (cr)) {
                        // font size 12 seems suitable for iconHeight 48 pixels
                        float fontSize = 12 * rectSizing.Height / 48f;
                        layout.FontDescription = Pango.FontDescription.FromString ("Sans " + fontSize.ToString ());
                        layout.SetText ("const");
                        layout.Width = rectSizing.Width;
                        layout.Alignment = Pango.Alignment.Center;
                        int lwidth, lheight;
                        layout.GetPixelSize (out lwidth, out lheight);
                        // 0, 0 = left top
                        //cr.MoveTo (0.5 * (width - lwidth), 0.5 * (height - lheight));
                        cr.MoveTo (0.5 * rectSizing.Width, 0.5 * (rectSizing.Height - lheight));
                        Pango.CairoHelper.ShowLayout (cr, layout);
                    }
                }
                return new Gdk.Pixbuf (surface.Data, Gdk.Colorspace.Rgb, true, 8, rectSizing.Width, rectSizing.Height, surface.Stride, null);
            }
        }