Пример #1
0
 public void Save()
 {
     Context.Save();
     dataStack.Push(new Data()
     {
         PatternAlpha = PatternAlpha
     });
 }
Пример #2
0
        public override void Render(Cairo.Context context, Point scale)
        {
            context.Save();
            RenderArea(context, scale);
            context.Restore();

            base.Render(context, scale);
        }
Пример #3
0
 protected override bool OnDrawn(Cairo.Context cr)
 {
     cr.Save();
     cr.SetSourceRGB(0.0, 0.0, 0.0);
     cr.Rectangle(0, 0, Allocation.Width, Allocation.Height);
     cr.Fill();
     cr.Restore();
     return(base.OnDrawn(cr));
 }
Пример #4
0
        private void DrawFocusRect(Cairo.Context cr, float x, float y, float width, float height)
        {
            cr.Save();

            cr.Rectangle(x, y, width, height);
            CairoHelper.PaintFocus(cr, gtk_style, state);

            cr.Restore();
        }
Пример #5
0
 public void Save()
 {
     Context.Save();
     stackTop = new Data {
         PatternAlpha = PatternAlpha,
         GlobalAlpha  = GlobalAlpha,
         Previous     = stackTop,
     };
 }
Пример #6
0
        public void Render(List <Layer> layers, Cairo.ImageSurface dst, Point offset)
        {
            dst.Flush();

            // Our rectangle of interest
            var r   = new Rectangle(offset, dst.GetBounds().Size).ToCairoRectangle();
            var doc = PintaCore.Workspace.ActiveDocument;

            using (var g = new Cairo.Context(dst)) {
                // Create the transparent checkerboard background
                g.Translate(-offset.X, -offset.Y);
                g.FillRectangle(r, tranparent_pattern, new Cairo.PointD(offset.X, offset.Y));

                for (var i = 0; i < layers.Count; i++)
                {
                    var layer = layers[i];

                    // If we're in LivePreview, substitute current layer with the preview layer
                    if (layer == doc.Layers.CurrentUserLayer && PintaCore.LivePreview.IsEnabled)
                    {
                        layer = CreateLivePreviewLayer(layer);
                    }

                    // If the layer is offset, handle it here
                    if (!layer.Transform.IsIdentity())
                    {
                        layer = CreateOffsetLayer(layer);
                    }

                    // No need to resize the surface if we're at 100% zoom
                    if (scale_factor.Ratio == 1)
                    {
                        layer.Draw(g, layer.Surface, layer.Opacity, false);
                    }
                    else
                    {
                        using (var scaled = CairoExtensions.CreateImageSurface(Cairo.Format.Argb32, dst.Width, dst.Height)) {
                            g.Save();
                            // Have to undo the translate set above
                            g.Translate(offset.X, offset.Y);
                            CopyScaled(layer.Surface, scaled, r.ToGdkRectangle());
                            layer.Draw(g, scaled, layer.Opacity, false);
                            g.Restore();
                        }
                    }
                }
            }

            // If we are at least 200% and grid is requested, draw it
            if (enable_pixel_grid && PintaCore.Actions.View.PixelGrid.Value && scale_factor.Ratio <= 0.5d)
            {
                RenderPixelGrid(dst, offset);
            }

            dst.MarkDirty();
        }
Пример #7
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);
        }
Пример #8
0
 public static void RenderLine(Cairo.Context g, Cairo.Color c, double lw, double x0, double y0, double x1, double y1)
 {
     g.Save();
     g.Color     = c;
     g.LineWidth = 3;
     g.MoveTo(x0, y0);
     g.LineTo(x1, y1);
     g.Stroke();
     g.Restore();
 }
        public override void DrawForeground(MonoTextEditor editor, Cairo.Context cr, MarginDrawMetrics metrics)
        {
            var tx = Math.Round(metrics.X + (metrics.Width - cache.errorPixbuf.Width) / 2) - 1;
            var ty = Math.Floor(metrics.Y + (metrics.Height - cache.errorPixbuf.Height) / 2);

            cr.Save();
            cr.Translate(tx, ty);
            cr.DrawImage(editor, errors.Any(e => e.IsError) ? cache.errorPixbuf : cache.warningPixbuf, 0, 0);
            cr.Restore();
        }
Пример #10
0
 public void Draw(GraphicsHandler graphics, Pango.Layout layout, Cairo.Context context, PointF location)
 {
     Setup(layout);
     context.Save();
     ForegroundBrush.Apply(graphics);
     context.MoveTo(location.X, location.Y);
     Pango.CairoHelper.LayoutPath(context, layout);
     context.Fill();
     context.Restore();
 }
Пример #11
0
        public virtual void Render(Cairo.Context cr)
        {
            double opacity = Opacity;

            if (ContentAllocation.Width <= 0 || ContentAllocation.Height <= 0 || opacity <= 0)
            {
                return;
            }

            cr.Save();

            if (opacity < 1.0)
            {
                cr.PushGroup();
            }

            MarginStyle margin_style = MarginStyle;

            if (margin_style != null && margin_style != MarginStyle.None)
            {
                cr.Translate(Math.Round(Allocation.X), Math.Round(Allocation.Y));
                cr.Save();
                margin_style.Apply(this, cr);
                cr.Restore();
                cr.Translate(Math.Round(Margin.Left), Math.Round(Margin.Top));
            }
            else
            {
                cr.Translate(Math.Round(ContentAllocation.X), Math.Round(ContentAllocation.Y));
            }

            cr.Antialias = Cairo.Antialias.Default;
            ClippedRender(cr);

            if (opacity < 1.0)
            {
                cr.PopGroupToSource();
                cr.PaintWithAlpha(Opacity);
            }

            cr.Restore();
        }
Пример #12
0
        protected void RenderLine(Cairo.Context context, Point scale, int idx, int length)
        {
            context.Save();

            SetLineStyle(context);

            CreatePath(context, scale, idx, length);

            context.Stroke();
            context.Restore();
        }
Пример #13
0
 protected void paintTrail(Cairo.Context context, int x, int y)
 {
     context.Save();
     context.SetSourceRGB(0, 1, 0);
     context.Translate(x, y);
     context.Rectangle(new Cairo.Rectangle(0, 0, fieldSize, fieldSize));
     context.SetSourceRGBA(0, 1, 0, 0.3);
     context.FillPreserve();
     context.NewPath();
     context.Restore();
 }
Пример #14
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();
 }
Пример #15
0
 protected override bool OnDrawn(Cairo.Context cr)
 {
     cr.Save();
     Gdk.RGBA color = Hyena.Gui.GtkUtilities.ColorBlend(
         StyleContext.GetBackgroundColor(StateFlags.Normal),
         StyleContext.GetColor(StateFlags.Normal));
     cr.SetSourceRGBA(color.Red, color.Green, color.Blue, color.Alpha);
     DrawCairo(cr);
     cr.Restore();
     return(false);
 }
Пример #16
0
 protected void paintSquare(Cairo.Context context, int x, int y, bool fill)
 {
     context.Save();
     context.SetSourceRGB(0, 0, 1);
     context.Translate(x, y);
     context.Rectangle(new Cairo.Rectangle(0, 0, fieldSize, fieldSize));
     context.SetSourceRGBA(0, 0, 0, fill ? 0.5 : 0.3);
     context.FillPreserve();
     context.NewPath();
     context.Restore();
 }
Пример #17
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();
 }
Пример #18
0
        private void PaintHeaderCell(Cairo.Context cr, Rectangle area, int ci, bool dragging, ref bool have_drawn_separator)
        {
            if (ci < 0 || column_cache.Length <= ci)
            {
                return;
            }

            if (ci == ActiveColumn && HasFocus && HeaderFocused)
            {
                Theme.DrawColumnHeaderFocus(cr, area);
            }

            if (dragging)
            {
                Cairo.Color dark_color = CairoExtensions.GdkRGBAToCairoColor(StyleContext.GetBackgroundColor(StateFlags.Normal));
                dark_color = CairoExtensions.ColorShade(dark_color, 0.7);

                Theme.DrawColumnHighlight(cr, area, dark_color);

                StyleContext.Save();
                StyleContext.AddClass("entry");
                Cairo.Color base_color = CairoExtensions.GdkRGBAToCairoColor(StyleContext.GetBackgroundColor(StateFlags.Normal));
                StyleContext.Restore();

                Cairo.Color stroke_color = CairoExtensions.ColorShade(base_color, 0.0);
                stroke_color.A = 0.3;

                cr.Color = stroke_color;
                cr.MoveTo(area.X + 0.5, area.Y + 1.0);
                cr.LineTo(area.X + 0.5, area.Bottom);
                cr.MoveTo(area.Right - 0.5, area.Y + 1.0);
                cr.LineTo(area.Right - 0.5, area.Bottom);
                cr.Stroke();
            }

            ColumnCell cell = column_cache[ci].Column.HeaderCell;

            if (cell != null)
            {
                cr.Save();
                cr.Translate(area.X, area.Y);
                cell_context.Area  = area;
                cell_context.State = StateFlags.Normal;
                cell.Render(cell_context, area.Width, area.Height);
                cr.Restore();
            }

            if (!dragging && ci < column_cache.Length - 1 && (have_drawn_separator ||
                                                              column_cache[ci].MaxWidth != column_cache[ci].MinWidth))
            {
                have_drawn_separator = true;
                Theme.DrawHeaderSeparator(cr, area, area.Right);
            }
        }
Пример #19
0
        internal static void DrawEllipse(Cairo.Context context, Ellipse el, double startAngle = 0, double endAngle = Math.PI * 2)
        {
            var radius = Math.Max(el.AxisA.Length, el.AxisB.Length);
            var scaleX = el.AxisA.Length / radius;
            var scaleY = el.AxisB.Length / radius;

            context.Save();
            context.Scale(scaleX, scaleY);
            context.Arc(el.Center.X, el.Center.Y, radius, startAngle, endAngle);
            context.Stroke();
            context.Restore();
        }
Пример #20
0
        /// <summary>
        /// Draws a bitmap image.
        /// </summary>
        /// <param name="source">The bitmap image.</param>
        /// <param name="opacity">The opacity to draw with.</param>
        /// <param name="sourceRect">The rect in the image to draw.</param>
        /// <param name="destRect">The rect in the output to draw to.</param>
        public void DrawImage(IBitmap bitmap, double opacity, Rect sourceRect, Rect destRect)
        {
            var impl  = bitmap.PlatformImpl as BitmapImpl;
            var size  = new Size(impl.PixelWidth, impl.PixelHeight);
            var scale = new Vector(destRect.Width / sourceRect.Width, destRect.Height / sourceRect.Height);

            _context.Save();
            _context.Scale(scale.X, scale.Y);
            destRect /= scale;

            if (opacityOverride < 1.0f)
            {
                _context.PushGroup();
                Gdk.CairoHelper.SetSourcePixbuf(
                    _context,
                    impl.Surface,
                    -sourceRect.X + destRect.X,
                    -sourceRect.Y + destRect.Y);

                _context.Rectangle(destRect.ToCairo());
                _context.Fill();
                _context.PopGroupToSource();
                _context.PaintWithAlpha(opacityOverride);
            }
            else
            {
                _context.PushGroup();
                Gdk.CairoHelper.SetSourcePixbuf(
                    _context,
                    impl.Surface,
                    -sourceRect.X + destRect.X,
                    -sourceRect.Y + destRect.Y);

                _context.Rectangle(destRect.ToCairo());
                _context.Fill();
                _context.PopGroupToSource();
                _context.PaintWithAlpha(opacityOverride);
            }
            _context.Restore();
        }
Пример #21
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            base.DrawBackground(cr);

            cr.Save();

            cr.Translate(XOffset, YOffset);
            cr.Scale(Scale, Scale);

            hoveringComponent = null;

            foreach (RoomComponent com in roomComponents)
            {
                cr.SetSourceColor(com.BoxColor);
                cr.Rectangle(com.BoxRectangle);
                cr.Fill();
                com.Draw(cr);

                if (DrawRoomComponentHover)
                {
                    if (CairoHelper.PointInRect(mouseX, mouseY, com.BoxRectangle))
                    {
                        hoveringComponent = com;
                    }
                }
            }

            if (SelectRoomComponents)
            {
                // Object hovering over
                if (hoveringComponent != null)
                {
                    cr.SetSourceColor(ObjectHoverColor);
                    CairoHelper.DrawRectOutline(cr, 1, hoveringComponent.BoxRectangle);
                }
                // Object selected
                if (selectedComponent != null)
                {
                    cr.SetSourceColor(TileGridViewer.DefaultSelectionColor);
                    CairoHelper.DrawRectOutline(cr, 1, selectedComponent.BoxRectangle);
                }
            }

            cr.Restore();

            if (DrawTileHover)
            {
                base.DrawHoverAndSelection(cr);
            }

            return(true);
        }
Пример #22
0
        public static void FillEllipse(this Cairo.Context dc, double x, double y, double width, double height)
        {
            dc.Save();
            dc.Translate(x + width / 2, y + height / 2);
            dc.Scale(width / 2, height / 2);
            dc.Arc(0, 0, 1, 0, 2 * Math.PI);

            //dc.fill.SetupFill();
            //dc.fill_preserve()
            //dc.SetupStroke()
            dc.Fill();
            dc.Restore();
        }
        public static void DrawText(Cairo.Context context, float x, float y, double angle, string text)
        {
            var ext = context.TextExtents(text);

            context.Save();
            context.Translate(x, y);
            context.Rotate(angle - Math.PI / 2);
            context.Translate(-ext.Width / 2, 0);
            context.ShowText(text);
            context.Stroke();

            context.Restore();
        }
Пример #24
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();
        }
Пример #25
0
		protected override void onDraw (Cairo.Context gr)
		{
			gr.Save ();

			drawTechBorder1 (gr);

			if (child != null) {
				if (child.Visible)
					child.Paint (ref gr);
			}

			gr.Restore ();
		}
Пример #26
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();
        }
 public override void DrawForeground(TextEditor editor, Cairo.Context cr, MarginDrawMetrics metrics)
 {
     cr.Save();
     cr.Translate(
         metrics.X + 0.5 + (metrics.Width - 2 - cache.errorPixbuf.Width) / 2,
         metrics.Y + 0.5 + (metrics.Height - cache.errorPixbuf.Height) / 2
         );
     Gdk.CairoHelper.SetSourcePixbuf(
         cr,
         errors.Any(e => e.IsError) ? cache.errorPixbuf : cache.warningPixbuf, 0, 0);
     cr.Paint();
     cr.Restore();
 }
Пример #28
0
        public void DrawImage(IBitmap bitmap, double opacity, Rect sourceRect, Rect destRect)
        {
            var impl   = bitmap.PlatformImpl as BitmapImpl;
            var size   = new Size(impl.PixelWidth, impl.PixelHeight);
            var scaleX = destRect.Size.Width / sourceRect.Size.Width;
            var scaleY = destRect.Size.Height / sourceRect.Size.Height;

            _context.Save();
            _context.Scale(scaleX, scaleY);
            _context.SetSourceSurface(impl.Surface, (int)sourceRect.X, (int)sourceRect.Y);
            _context.Rectangle(sourceRect.ToCairo());
            _context.Fill();
            _context.Restore();
        }
Пример #29
0
        public static void ShadowedText(Cairo.Context g, Cairo.Color c, string text, double x, double y)
        {
            g.Save();

            g.MoveTo(x + Graphics.SHADOW_SPACING, y + Graphics.SHADOW_SPACING);
            g.Color = new Cairo.Color(0, 0, 0);
            g.ShowText(text);

            g.MoveTo(x, y);
            g.Color = c;
            g.ShowText(text);

            g.Restore();
        }
Пример #30
0
        void RenderLineNumberIcon(Widget widget, Cairo.Context cr, Gdk.Rectangle cell_area, int markupHeight, int yOffset)
        {
            if (Frame == null)
            {
                return;
            }

            cr.Save();

                        #if CENTER_ROUNDED_RECTANGLE
            cr.Translate(cell_area.X + Padding, (cell_area.Y + (cell_area.Height - RoundedRectangleHeight) / 2.0));
                        #else
            cr.Translate(cell_area.X + Padding, cell_area.Y + Padding + yOffset);
                        #endif

            cr.Antialias = Cairo.Antialias.Subpixel;

            cr.RoundedRectangle(0.0, 0.0, RoundedRectangleWidth, RoundedRectangleHeight, RoundedRectangleRadius);
            cr.Clip();

            if (IsUserCode)
            {
                cr.SetSourceColor(Styles.ExceptionCaughtDialog.LineNumberInUserCodeBackgroundColor.ToCairoColor());                   // 230, 152, 223
            }
            else
            {
                cr.SetSourceColor(Styles.ExceptionCaughtDialog.LineNumberBackgroundColor.ToCairoColor());                   // 197, 197, 197
            }
            cr.RoundedRectangle(0.0, 0.0, RoundedRectangleWidth, RoundedRectangleHeight, RoundedRectangleRadius);
            cr.Fill();

            var lineNumber = !string.IsNullOrEmpty(Frame.File) ? Frame.Line : -1;

            using (var layout = PangoUtil.CreateLayout(widget, lineNumber != -1 ? lineNumber.ToString() : "???")) {
                layout.Alignment       = Pango.Alignment.Left;
                layout.FontDescription = LineNumberFont;

                int width, height;
                layout.GetPixelSize(out width, out height);

                double y_offset = (RoundedRectangleHeight - height) / 2.0;
                double x_offset = (RoundedRectangleWidth - width) / 2.0;

                cr.SetSourceColor(Styles.ExceptionCaughtDialog.LineNumberTextColor.ToCairoColor());
                cr.Translate(x_offset, y_offset);
                cr.ShowLayout(layout);
            }

            cr.Restore();
        }
Пример #31
0
		public void Render (List<Layer> layers, Cairo.ImageSurface dst, Gdk.Point offset)
		{
			dst.Flush ();

            // Our rectangle of interest
            var r = new Gdk.Rectangle (offset, dst.GetBounds ().Size).ToCairoRectangle ();

            using (var g = new Cairo.Context (dst)) {
                // Create the transparent checkerboard background
                g.Translate (-offset.X, -offset.Y);
                g.FillRectangle (r, tranparent_pattern, new Cairo.PointD (offset.X, offset.Y));

                for (var i = 0; i < layers.Count; i++) {
                    var layer = layers[i];

                    // If we're in LivePreview, substitute current layer with the preview layer
                    if (layer == PintaCore.Layers.CurrentLayer && PintaCore.LivePreview.IsEnabled)
                        layer = CreateLivePreviewLayer (layer);

                    // If the layer is offset, handle it here
                    if (!layer.Transform.IsIdentity ())
                        layer = CreateOffsetLayer (layer);

                    // No need to resize the surface if we're at 100% zoom
                    if (scale_factor.Ratio == 1)
                        layer.Draw (g, layer.Surface, layer.Opacity, false);
                    else {
                        using (var scaled = new Cairo.ImageSurface (Cairo.Format.Argb32, dst.Width, dst.Height)) {
                            g.Save ();
                            // Have to undo the translate set above
                            g.Translate (offset.X, offset.Y);
                            CopyScaled (layer.Surface, scaled, r.ToGdkRectangle ());
                            layer.Draw (g, scaled, layer.Opacity, false);
                            g.Restore ();
                        }
                    }
                }
            }

            // If we are at least 200% and grid is requested, draw it
            if (enable_pixel_grid && PintaCore.Actions.View.PixelGrid.Active && scale_factor.Ratio <= 0.5d)
                RenderPixelGrid (dst, offset);
			
			dst.MarkDirty ();
		}
Пример #32
0
		// Called from asynchronously from Renderer.OnCompletion ()
		void HandleApply ()
		{
			Debug.WriteLine ("LivePreviewManager.HandleApply()");

			using (var ctx = new Cairo.Context (layer.Surface)) {
				
				ctx.Save ();
				PintaCore.Workspace.ActiveDocument.Selection.Clip (ctx);
			
				ctx.Operator = Cairo.Operator.Source;
				
				layer.Draw(ctx, live_preview_surface, 1);
				ctx.Restore ();
			}
			
			PintaCore.History.PushNewItem (history_item);
			history_item = null;
			
			FireLivePreviewEndedEvent(RenderStatus.Completed, null);
			
			live_preview_enabled = false;
			
			PintaCore.Workspace.Invalidate (); //TODO keep track of dirty bounds.
			CleanUp ();
		}
Пример #33
0
		// Called from asynchronously from Renderer.OnCompletion ()
		void HandleApply ()
		{
			Debug.WriteLine ("LivePreviewManager.HandleApply()");

			var item = new SimpleHistoryItem (effect.Icon, effect.Name);
			item.TakeSnapshotOfLayer (PintaCore.Layers.CurrentLayerIndex);			
			
			using (var ctx = new Cairo.Context (layer.Surface)) {
				
				ctx.Save ();
				ctx.AppendPath (PintaCore.Workspace.ActiveDocument.Selection.SelectionPath);
				ctx.FillRule = Cairo.FillRule.EvenOdd;
				ctx.Clip ();				
			
				ctx.Operator = Cairo.Operator.Source;
				
				ctx.SetSourceSurface (live_preview_surface, (int)layer.Offset.X, (int)layer.Offset.Y);
				ctx.Paint ();
				ctx.Restore ();
			}
			
			PintaCore.History.PushNewItem (item);
			
			FireLivePreviewEndedEvent(RenderStatus.Completed, null);
			
			live_preview_enabled = false;
			
			PintaCore.Workspace.Invalidate (); //TODO keep track of dirty bounds.
			CleanUp ();
		}
Пример #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;
        }
Пример #35
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;
        }
Пример #36
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;
        }