Beispiel #1
0
        public override void Fill(object backend)
        {
            var gtkc = (CairoContextBackend)backend;

            Cairo.Context ctx   = gtkc.Context;
            var           alpha = gtkc.GlobalAlpha * gtkc.PatternAlpha;

            if (alpha == 1)
            {
                ctx.Fill();
            }
            else
            {
                ctx.Save();
                ctx.Clip();
                ctx.PaintWithAlpha(alpha);
                ctx.Restore();
            }
        }
Beispiel #2
0
        protected override void onDraw(Cairo.Context gr)
        {
            //onDraw is overrided to prevent default drawing of background, template top container
            //may have a binding to root background or a fixed one.
            //this allow applying root background to random template component
            gr.Save();

            if (ClipToClientRect)
            {
                //clip to client zone
                CairoHelpers.CairoRectangle(gr, ClientRectangle, CornerRadius);
                gr.Clip();
            }

            if (child != null)
            {
                child.Paint(ref gr);
            }
            gr.Restore();
        }
Beispiel #3
0
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            base.OnExposeEvent(evnt);

            if (!GLSupported())
            {
                return(false);
            }

            GLDo(() => {
                // Render in cairo image
                using (Cairo.Context ctx = new Cairo.Context(d_surface))
                {
                    Gdk.CairoHelper.Rectangle(ctx, evnt.Area);
                    ctx.Clip();

                    DrawTo(ctx);
                }

                Gl.glMatrixMode(Gl.GL_MODELVIEW);
                Gl.glLoadIdentity();

                Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);

                // Then blit the image in the texture
                Gl.glBindTexture(Gl.GL_TEXTURE_RECTANGLE_ARB, d_texture);
                Gl.glTexImage2D(Gl.GL_TEXTURE_RECTANGLE_ARB,
                                0,
                                Gl.GL_RGBA,
                                d_surface.Width,
                                d_surface.Height,
                                0,
                                Gl.GL_BGRA,
                                Gl.GL_UNSIGNED_BYTE,
                                d_surface.Data);

                DrawRectangle();
            });

            return(true);
        }
Beispiel #4
0
        protected override bool OnDamageEvent(Gdk.EventExpose evnt)
        {
            if (canvas_child == null || !canvas_child.Visible || !Visible || !IsMapped)
            {
                return(true);
            }

            Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window);
            context.Context = cr;

            for (int i = 0; i < evnt.Region.NumRectangles; i++)
            {
                var damage = evnt.Region.GetRectangle(i);
                cr.Rectangle(damage.X, damage.Y, damage.Width, damage.Height);
                cr.Clip();

                cr.Translate(Allocation.X, Allocation.Y);
                canvas_child.Render(context);
                cr.Translate(-Allocation.X, -Allocation.Y);

                if (Debug)
                {
                    cr.LineWidth = 1.0;
                    cr.SetSourceColor(CairoExtensions.RgbToColor(
                                          (uint)(rand = rand ?? new Random()).Next(0, 0xffffff)));
                    cr.Rectangle(damage.X + 0.5, damage.Y + 0.5, damage.Width - 1, damage.Height - 1);
                    cr.Stroke();
                }

                cr.ResetClip();
            }

            CairoExtensions.DisposeContext(cr);

            if (fps.Update())
            {
                // Console.WriteLine ("FPS: {0}", fps.FramesPerSecond);
            }

            return(true);
        }
Beispiel #5
0
        private static void MakeReflection(Cairo.Context context, Cairo.ImageSurface source, int w, int h)
        {
            context.ResetClip();
            context.SetSourceSurface(source, 2, 2);
            context.Paint();

            double alpha = -0.3;
            double step  = 1.0 / (double)source.Height;

            context.Translate(0, h);
            context.Scale(1, -1);
            context.SetSourceSurface(source, 2, 2);
            for (int i = 0; i < source.Height; i++)
            {
                context.Rectangle(0, i + 2, w, 1);
                context.Clip();
                alpha += step;
                context.PaintWithAlpha(Math.Max(Math.Min(alpha, 0.7), 0.0));
                context.ResetClip();
            }
        }
Beispiel #6
0
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            base.OnExposeEvent(evnt);

            if (d_overrideDraw)
            {
                return(true);
            }

            using (Cairo.Context ctx = Gdk.CairoHelper.Create(evnt.Window))
            {
                Gdk.CairoHelper.Rectangle(ctx, evnt.Area);
                ctx.Clip();

                DrawTo(ctx);

                ((IDisposable)ctx.Target).Dispose();
            }

            return(true);
        }
Beispiel #7
0
        private void PaintView(Cairo.Context cr, Rect clip)
        {
            clip.Intersect((Rect)list_rendering_alloc);
            cr.Rectangle((Cairo.Rectangle)clip);
            cr.Clip();

            cell_context.Clip             = (Gdk.Rectangle)clip;
            cell_context.TextAsForeground = false;

            selected_rows.Clear();

            for (int layout_index = 0; layout_index < ViewLayout.ChildCount; layout_index++)
            {
                var layout_child     = ViewLayout[layout_index];
                var child_allocation = layout_child.Allocation;

                if (!child_allocation.IntersectsWith(clip) || ViewLayout.GetModelIndex(layout_child) >= Model.Count)
                {
                    continue;
                }

                if (Selection != null && Selection.Contains(ViewLayout.GetModelIndex(layout_child)))
                {
                    selected_rows.Add(ViewLayout.GetModelIndex(layout_child));

                    PaintRowSelection(cr, (int)child_allocation.X, (int)child_allocation.Y,
                                      (int)child_allocation.Width, (int)child_allocation.Height);

                    cell_context.Selected = true;
                }
                else
                {
                    cell_context.Selected = false;
                }

                layout_child.Render(cell_context);
            }

            cr.ResetClip();
        }
Beispiel #8
0
        private void PaintHeader(Cairo.Context cr)
        {
            Rectangle clip = header_rendering_alloc;

            clip.Height += Theme.BorderWidth;
            clip.Intersect(new Gdk.Rectangle(0, 0, Allocation.Width, Allocation.Height));
            cr.Rectangle(clip.X, clip.Y, clip.Width, clip.Height);
            cr.Clip();

            Rectangle cell_area = new Rectangle();

            cell_area.Y      = header_rendering_alloc.Y;
            cell_area.Height = header_rendering_alloc.Height;

            cell_context.Clip             = clip;
            cell_context.Opaque           = true;
            cell_context.TextAsForeground = true;

            for (int ci = 0; ci < column_cache.Length; ci++)
            {
                if (pressed_column_is_dragging && pressed_column_index == ci)
                {
                    continue;
                }

                cell_area.X     = column_cache[ci].X1 + Theme.TotalBorderWidth + header_rendering_alloc.X - HadjustmentValue;
                cell_area.Width = column_cache[ci].Width;
                PaintHeaderCell(cr, cell_area, ci, false);
            }

            if (pressed_column_is_dragging && pressed_column_index >= 0)
            {
                cell_area.X     = pressed_column_x_drag - HadjustmentValue;
                cell_area.Width = column_cache[pressed_column_index].Width;
                PaintHeaderCell(cr, cell_area, pressed_column_index, true);
            }

            cr.ResetClip();
        }
Beispiel #9
0
        /// <summary>
        /// Renders the pager.
        /// </summary>
        public virtual void RenderPager(Cairo.Context context, Pango.Context pangoContext, Gdk.Rectangle region)
        {
            //set global clip to avoid going outside general rendering area
            CairoExtensions.RoundedRectangle(context, region.X, region.Y, region.Width, region.Height, CornerRadius);
            context.Clip();

            Pango.Layout layout      = SetupPagerText(pangoContext);
            var          boundingBox = GetPagerBounds(layout, region);

            RenderPagerBackground(context, boundingBox);

            Gdk.Rectangle arrowRect = new Gdk.Rectangle(boundingBox.X + pagerArrowPadding,
                                                        boundingBox.Y + (boundingBox.Height - Styles.PopoverWindow.PagerTriangleSize) / 2,
                                                        Styles.PopoverWindow.PagerTriangleSize,
                                                        Styles.PopoverWindow.PagerTriangleSize);

            RenderPagerArrow(context, arrowRect, PagerVertical ? ArrowType.Up : ArrowType.Left);
            arrowRect.X = boundingBox.X + boundingBox.Width - (pagerArrowPadding + Styles.PopoverWindow.PagerTriangleSize);
            RenderPagerArrow(context, arrowRect, PagerVertical ? ArrowType.Down : ArrowType.Right);

            RenderPagerText(context, layout, boundingBox);
        }
Beispiel #10
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            if (canvas_child == null || !canvas_child.Visible || !Visible || !IsMapped)
            {
                return(true);
            }

            foreach (Gdk.Rectangle damage in evnt.Region.GetRectangles())
            {
                cr.Rectangle(damage.X, damage.Y, damage.Width, damage.Height);
                cr.Clip();

                cr.Translate(Allocation.X, Allocation.Y);
                canvas_child.Render(cr);
                cr.Translate(-Allocation.X, -Allocation.Y);

                if (Debug)
                {
                    cr.LineWidth = 1.0;
                    cr.Color     = CairoExtensions.RgbToColor(
                        (uint)(rand = rand ?? new Random()).Next(0, 0xffffff));
                    cr.Rectangle(damage.X + 0.5, damage.Y + 0.5, damage.Width - 1, damage.Height - 1);
                    cr.Stroke();
                }

                cr.ResetClip();
            }

            CairoExtensions.DisposeContext(cr);

            if (fps.Update())
            {
                // Console.WriteLine ("FPS: {0}", fps.FramesPerSecond);
            }

            return(true);
        }
Beispiel #11
0
            void OnConfigured(object o, ConfigureEventArgs args)
            {
                pixmap = new Pixmap (args.Event.Window,
                             Allocation.Width,
                             Allocation.Height);
                cairo = Gdk.CairoHelper.Create (pixmap);
                cairo.Rectangle (0, 0,
                         Allocation.Width,
                         Allocation.Height);
                cairo.Clip ();

                ArrayList oldlist = points;
                points = new ArrayList ();

                ComputePositions ();
                foreach (GraphPoint point in oldlist)
                {
                    __AddGameInfo (point.info);
                }

                UpdatePixmap ();
            }
Beispiel #12
0
 /// <summary>
 /// Pushes a clip rectange.
 /// </summary>
 /// <param name="clip">The clip rectangle.</param>
 /// <returns>A disposable used to undo the clip rectangle.</returns>
 public void PushClip(Rect clip)
 {
     _context.Save();
     _context.Rectangle(clip.ToCairo());
     _context.Clip();
 }
Beispiel #13
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();

                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;

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

                // Draw the text
                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;
        }
Beispiel #14
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;
        }
Beispiel #15
0
        public void Draw(Gdk.Drawable window, Cairo.Context ctx, Gdk.Rectangle bounds, StateType state)
        {
            if (noise == null)
            {
                return;
            }

            var drawBounds  = GraphAreaFromBounds(new RectangleF(bounds.X, bounds.Y, bounds.Width, bounds.Height));
            var outerBounds = drawBounds.Inflated(3);

            // Outer clip area
            ctx.Save();
            ctx.Rectangle(outerBounds.X, outerBounds.Y, outerBounds.Width, outerBounds.Height);
            ctx.Clip();

            var colorSelectedBackground = WidgetTools.ColorSelectedBackground;
            var colorBorder             = WidgetTools.ColorBorder;
            var colorLine = WidgetTools.ColorLine;

            // Background
            if (state == StateType.Selected)
            {
                WidgetTools.SetColor(ctx, colorSelectedBackground);
                ctx.Rectangle(outerBounds.X, outerBounds.Y, outerBounds.Width, outerBounds.Height);
                ctx.Fill();
            }

            // Border
            WidgetTools.SetColor(ctx, colorBorder);
            ctx.LineWidth = 1.0;
            ctx.Rectangle(outerBounds.X, outerBounds.Y, outerBounds.Width, outerBounds.Height);
            ctx.Stroke();

            // Zero line
            if (HasZeroLine)
            {
                var height = ToScreen(Vector2.Zero, drawBounds);
                WidgetTools.SetColor(ctx, colorBorder);
                ctx.MoveTo(outerBounds.X, height.Y);
                ctx.LineTo(outerBounds.X + outerBounds.Width, height.Y);
                ctx.LineWidth = 1.0;
                WidgetTools.SetDash(ctx, true);
                ctx.Stroke();
            }

            ////// Inner clip area
            ////ctx.Rectangle(drawBounds.X, drawBounds.Y, drawBounds.Width, drawBounds.Height);
            ////ctx.Clip();

            //if (noise.Count > 0)
            {
                WidgetTools.SetColor(ctx, colorLine);

                int numSteps = (int)drawBounds.Width;

                var p = Evaluate(0, drawBounds);
                ctx.MoveTo(p.X, p.Y);
                ctx.LineWidth = 1.2;
                WidgetTools.SetDash(ctx, false);

                int part = 0;

                for (int i = 0; numSteps > 0 && i <= numSteps; i++)
                {
                    var fraction = (float)i / numSteps;

                    //if (fraction >= startFraction && part == 0)
                    //{
                    //    p = ToScreen(noise.Front.Value, drawBounds);
                    //    ctx.LineTo(p.X, p.Y);
                    //    ctx.Stroke();
                    //    SetDash(ctx, false);
                    //    ctx.MoveTo(p.X, p.Y);

                    //    part++;
                    //}

                    //if (fraction >= endFraction && part == 1)
                    //{
                    //    p = ToScreen(noise.End.Value, drawBounds);
                    //    ctx.LineTo(p.X, p.Y);
                    //    ctx.Stroke();
                    //    SetDash(ctx, true);
                    //    ctx.MoveTo(p.X, p.Y);

                    //    part++;
                    //}

                    p = Evaluate(fraction, drawBounds);
                    ctx.LineTo(p.X, p.Y);
                }

                ctx.Stroke();
                //SetDash(ctx, false);

                //foreach (var entry in noise)
                //{
                //    var b = ToScreen(entry.Value, drawBounds);
                //    float size = 4;
                //    float outerSize = size + 1;

                //    var color = colorLine;
                //    var outerColor = MG.Framework.Numerics.Color.Transparent;


                //    if (outerColor.A != 0)
                //    {
                //        SetColor(ctx, outerColor);
                //        ctx.Rectangle(b.X - outerSize / 2, b.Y - outerSize / 2, outerSize, outerSize);
                //        ctx.LineWidth = 1.0;
                //        ctx.Stroke();
                //    }

                //    SetColor(ctx, color);
                //    ctx.Rectangle(b.X - size / 2, b.Y - size / 2, size, size);
                //    ctx.Fill();
                //}
            }

            ctx.Restore();
        }
Beispiel #16
0
        protected override void onDraw(Cairo.Context gr)
        {
            gr.Save();

            Rectangle rBack = new Rectangle(Slot.Size);

            Background.SetAsSource(gr, rBack);
            CairoHelpers.CairoRectangle(gr, rBack, CornerRadius);
            gr.Fill();

            if (ClipToClientRect)
            {
                //clip to client zone
                CairoHelpers.CairoRectangle(gr, ClientRectangle, CornerRadius);
                gr.Clip();
            }

            childrenRWLock.EnterReadLock();

            foreach (GraphicObject g in Children)
            {
                g.Paint(ref gr);
            }

            childrenRWLock.ExitReadLock();


            if (!IsDropTarget)
            {
                gr.Restore();
                return;
            }

            DockWindow dw = IFace.DragAndDropOperation.DragSource as DockWindow;

            if (dw == null)
            {
                return;
            }
            if (!dw.IsDocked)
            {
                Rectangle cb     = ClientRectangle;
                double    minDim = Math.Min(cb.Width, cb.Height);

                Rectangle r = rIn;
                if (Children.Count <= 1 || dw.DockingPosition.GetOrientation() == Orientation)
                {
                    r = cb;
                }

                switch (dw.DockingPosition)
                {
                case Alignment.Top:
                    gr.Rectangle(r.Left, r.Top, r.Width, r.Height * dockThresh);
                    break;

                case Alignment.Bottom:
                    gr.Rectangle(r.Left, r.Bottom - r.Height * dockThresh, r.Width, r.Height * dockThresh);
                    break;

                case Alignment.Left:
                    gr.Rectangle(r.Left, r.Top, r.Width * dockThresh, r.Height);
                    break;

                case Alignment.Right:
                    gr.Rectangle(r.Right - r.Width * dockThresh, r.Top, r.Width * dockThresh, r.Height);
                    break;

                case Alignment.Center:
                    r.Inflate((int)Math.Ceiling(Math.Min(r.Width, r.Height) * -0.05));
                    gr.Rectangle(r);
                    break;
                }
                gr.LineWidth = 1;
                gr.SetSourceRGBA(0.4, 0.4, 0.9, 0.4);
                gr.FillPreserve();
                gr.SetSourceRGBA(0.9, 0.9, 1.0, 0.8);
                gr.Stroke();
            }
            gr.Restore();
        }
Beispiel #17
0
        private void Redraw(Cairo.Context cr)
        {
            // Clear the background
            cr.Rectangle(0, 0, Allocation.Width, Allocation.Height);
            Gdk.CairoHelper.SetSourceColor(cr, Style.Base(State));
            cr.Fill();

            if (model == null)
            {
                if (hadj != null)
                {
                    hadj.Upper = hadj.Lower = 0;
                    hadj.Change();
                }

                if (vadj != null)
                {
                    vadj.Upper = 0;
                    vadj.Change();
                }
                return;
            }

            if (rows == 0 || cols == 0)
            {
                return;
            }

            Gdk.Rectangle background_area = cell_size;
            background_area.Width  += padding;
            background_area.Height += padding;

            TreeIter iter;

            if (model.GetIterFirst(out iter))
            {
                do
                {
                    TreePath path = model.GetPath(iter);

                    int x, y;
                    GetCellPosition(path.Indices[0], out x, out y);

                    if (hadj != null &&
                        (x + cell_size.Width < hadj.Value ||
                         x > hadj.Value + hadj.PageSize))
                    {
                        continue;
                    }

                    if (vadj != null &&
                        (y + cell_size.Height < vadj.Value ||
                         y > vadj.Value + vadj.PageSize))
                    {
                        continue;
                    }

                    if (data_func != null)
                    {
                        data_func(this, renderer, model, iter);
                    }

                    cell_size.X = x;
                    cell_size.Y = y;

                    if (hadj != null)
                    {
                        cell_size.X -= (int)hadj.Value;
                    }

                    if (vadj != null)
                    {
                        cell_size.Y -= (int)vadj.Value;
                    }

                    background_area.X = cell_size.X - (padding / 2);
                    background_area.Y = cell_size.Y - (padding / 2);

                    cr.Rectangle(background_area.X, background_area.Y,
                                 background_area.Width, background_area.Height);
                    cr.Clip();

                    renderer.Render(cr, this, background_area,
                                    cell_size, GetCellState(path));

                    cr.ResetClip();
                } while (model.IterNext(ref iter));
            }

            if (have_rubberband_selection)
            {
                int hadj_val = (hadj != null) ? (int)hadj.Value : 0;
                int vadj_val = (vadj != null) ? (int)vadj.Value : 0;

                cr.Rectangle(sel_rect.X - hadj_val + 0.5f, sel_rect.Y - vadj_val + 0.5f,
                             sel_rect.Width, sel_rect.Height);

                Cairo.Color sel_cairo_color = CairoHelper.GetCairoColor(Style.Background(StateType.Selected));



                //cr.Color = sel_cairo_color;
                cr.SetSourceRGBA(sel_cairo_color.R, sel_cairo_color.G, sel_cairo_color.B, sel_cairo_color.A);

                cr.LineWidth = 1.0f;
                cr.StrokePreserve();

                sel_cairo_color.A = 0.3f;
                //cr.Color = sel_cairo_color;
                cr.SetSourceRGBA(sel_cairo_color.R, sel_cairo_color.G, sel_cairo_color.B, sel_cairo_color.A);

                cr.Fill();
            }
        }
Beispiel #18
0
        protected override bool OnExposeEvent(EventExpose e)
        {
            base.OnExposeEvent(e);

            if (!PintaCore.Workspace.HasOpenDocuments)
            {
                return(true);
            }

            double scale = PintaCore.Workspace.Scale;

            int x = (int)PintaCore.Workspace.Offset.X;
            int y = (int)PintaCore.Workspace.Offset.Y;

            // Translate our expose area for the whole drawingarea to just our canvas
            Rectangle canvas_bounds = new Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width, PintaCore.Workspace.CanvasSize.Height);

            canvas_bounds.Intersect(e.Area);

            if (canvas_bounds.IsEmpty)
            {
                return(true);
            }

            canvas_bounds.X -= x;
            canvas_bounds.Y -= y;

            // Resize our offscreen surface to a surface the size of our drawing area
            if (canvas == null || canvas.Width != canvas_bounds.Width || canvas.Height != canvas_bounds.Height)
            {
                if (canvas != null)
                {
                    (canvas as IDisposable).Dispose();
                }

                canvas = new Cairo.ImageSurface(Cairo.Format.Argb32, canvas_bounds.Width, canvas_bounds.Height);
            }

            cr.Initialize(PintaCore.Workspace.ImageSize, PintaCore.Workspace.CanvasSize);

            using (Cairo.Context g = CairoHelper.Create(GdkWindow)) {
                // Draw our canvas drop shadow
                g.DrawRectangle(new Cairo.Rectangle(x - 1, y - 1, PintaCore.Workspace.CanvasSize.Width + 2, PintaCore.Workspace.CanvasSize.Height + 2), new Cairo.Color(.5, .5, .5), 1);
                g.DrawRectangle(new Cairo.Rectangle(x - 2, y - 2, PintaCore.Workspace.CanvasSize.Width + 4, PintaCore.Workspace.CanvasSize.Height + 4), new Cairo.Color(.8, .8, .8), 1);
                g.DrawRectangle(new Cairo.Rectangle(x - 3, y - 3, PintaCore.Workspace.CanvasSize.Width + 6, PintaCore.Workspace.CanvasSize.Height + 6), new Cairo.Color(.9, .9, .9), 1);

                // Set up our clip rectangle
                g.Rectangle(new Cairo.Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width, PintaCore.Workspace.CanvasSize.Height));
                g.Clip();

                g.Translate(x, y);

                // Render all the layers to a surface
                var layers = PintaCore.Layers.GetLayersToPaint();
                if (layers.Count == 0)
                {
                    canvas.Clear();
                }
                cr.Render(layers, canvas, canvas_bounds.Location);

                // Paint the surface to our canvas
                g.SetSourceSurface(canvas, canvas_bounds.X + (int)(0 * scale), canvas_bounds.Y + (int)(0 * scale));
                g.Paint();

                // Selection outline
                if (PintaCore.Layers.ShowSelection)
                {
                    bool fillSelection = PintaCore.Tools.CurrentTool.Name.Contains("Select") &&
                                         !PintaCore.Tools.CurrentTool.Name.Contains("Selected");
                    PintaCore.Workspace.ActiveDocument.Selection.Draw(g, scale, fillSelection);
                }
            }

            return(true);
        }
 public void Clip(Cairo.Context aContext)
 {
     DrawPath(aContext);
     aContext.Clip();
 }
Beispiel #20
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.SetSourceRGBA(0.90, 0.60, 0.87, 1.0);                  // 230, 152, 223
            }
            else
            {
                cr.SetSourceRGBA(0.77, 0.77, 0.77, 1.0);                  // 197, 197, 197
            }
            cr.RoundedRectangle(0.0, 0.0, RoundedRectangleWidth, RoundedRectangleHeight, RoundedRectangleRadius);
            cr.Fill();

            cr.SetSourceRGBA(0.0, 0.0, 0.0, 0.11);
            cr.RoundedRectangle(0.0, 0.0, RoundedRectangleWidth, RoundedRectangleHeight, RoundedRectangleRadius);
            cr.LineWidth = 2;
            cr.Stroke();

            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;

                // render the text shadow
                cr.Save();
                cr.SetSourceRGBA(0.0, 0.0, 0.0, 0.34);
                cr.Translate(x_offset, y_offset + 1);
                cr.ShowLayout(layout);
                cr.Restore();

                cr.SetSourceRGBA(1.0, 1.0, 1.0, 1.0);
                cr.Translate(x_offset, y_offset);
                cr.ShowLayout(layout);
            }

            cr.Restore();
        }
        protected override bool OnDrawn(Cairo.Context cr)
        {
            int  bar_width  = (int)((double)Allocation.Width * buffering_progress);
            bool render_bar = false;

            var border = StyleContext.GetBorder(StateFlags);

            if (bar_width > 0 && IsBuffering)
            {
                bar_width -= border.Left + border.Right;
                render_bar = true;

                StyleContext.Save();
                StyleContext.AddClass("trough");
                StyleContext.RenderBackground(cr, 0, 0, Allocation.Width, Allocation.Height);
                StyleContext.RenderFrame(cr, 0, 0, Allocation.Width, Allocation.Height);
                StyleContext.Restore();

                if (bar_width > 0)
                {
                    StyleContext.Save();
                    StyleContext.AddClass("progressbar");
                    StyleContext.RenderActivity(cr,
                                                border.Left, border.Top,
                                                bar_width, Allocation.Height - (border.Top + border.Bottom));
                    StyleContext.Restore();
                }
            }

            int width, height;

            layout.GetPixelSize(out width, out height);

            int x = (Allocation.Width - width) / 2;
            int y = (Allocation.Height - height) / 2;

            Gdk.Rectangle rect = new Gdk.Rectangle(0, 0, Allocation.Width, Allocation.Height);

            if (render_bar)
            {
                // First render the text that is on the progressbar
                int full_bar_width = bar_width + border.Left;
                rect.Width = full_bar_width;

                cr.Save();
                Gdk.CairoHelper.Rectangle(cr, rect);
                cr.Clip();
                StyleContext.Save();
                // The entry class is need so that the text get the "selected" color
                StyleContext.AddClass("entry");
                StyleContext.AddClass("progressbar");
                StyleContext.RenderLayout(cr, x, y, layout);
                StyleContext.Restore();
                cr.Restore();

                // Adjust the rectangle so that the rest of the text is rendered as expected
                rect.X    += rect.Width;
                rect.Width = Allocation.Width - rect.Width;
            }

            cr.Save();
            Gdk.CairoHelper.Rectangle(cr, rect);
            cr.Clip();
            StyleContext.Save();
            StyleContext.AddClass("trough");
            StyleContext.RenderLayout(cr, x, y, layout);
            StyleContext.Restore();
            cr.Restore();

            return(true);
        }
Beispiel #22
0
        protected override bool OnExposeEvent(EventExpose e)
        {
            base.OnExposeEvent(e);

            if (!PintaCore.Workspace.HasOpenDocuments)
            {
                return(true);
            }

            double scale = PintaCore.Workspace.Scale;

            int x = (int)PintaCore.Workspace.Offset.X;
            int y = (int)PintaCore.Workspace.Offset.Y;

            // Translate our expose area for the whole drawingarea to just our canvas
            Rectangle canvas_bounds = new Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width, PintaCore.Workspace.CanvasSize.Height);

            canvas_bounds.Intersect(e.Area);

            if (canvas_bounds.IsEmpty)
            {
                return(true);
            }

            canvas_bounds.X -= x;
            canvas_bounds.Y -= y;

            // Resize our offscreen surface to a surface the size of our drawing area
            if (canvas == null || canvas.Width != canvas_bounds.Width || canvas.Height != canvas_bounds.Height)
            {
                if (canvas != null)
                {
                    (canvas as IDisposable).Dispose();
                }

                canvas = new Cairo.ImageSurface(Cairo.Format.Argb32, canvas_bounds.Width, canvas_bounds.Height);
            }

            cr.Initialize(PintaCore.Workspace.ImageSize, PintaCore.Workspace.CanvasSize);

            using (Cairo.Context g = CairoHelper.Create(GdkWindow)) {
                // Draw our 1 px black border
                g.DrawRectangle(new Cairo.Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width + 1, PintaCore.Workspace.CanvasSize.Height + 1), new Cairo.Color(0, 0, 0), 1);

                // Set up our clip rectangle
                g.Rectangle(new Cairo.Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width, PintaCore.Workspace.CanvasSize.Height));
                g.Clip();

                g.Translate(x, y);

                bool checker = true;

                // Resize each layer and paint it to the screen
                foreach (Layer layer in PintaCore.Layers.GetLayersToPaint())
                {
                    cr.Render(layer.Surface, canvas, canvas_bounds.Location, checker);
                    g.SetSourceSurface(canvas, canvas_bounds.X + (int)(layer.Offset.X * scale), canvas_bounds.Y + (int)(layer.Offset.Y * scale));
                    g.PaintWithAlpha(layer.Opacity);

                    if (layer == PintaCore.Layers.CurrentLayer && PintaCore.LivePreview.IsEnabled)
                    {
                        cr.Render(PintaCore.LivePreview.LivePreviewSurface, canvas, canvas_bounds.Location, checker);

                        g.Save();
                        g.Scale(scale, scale);
                        g.AppendPath(PintaCore.Layers.SelectionPath);
                        g.Clip();

                        g.Scale(1 / scale, 1 / scale);
                        g.SetSourceSurface(canvas, canvas_bounds.X, canvas_bounds.Y);
                        g.PaintWithAlpha(layer.Opacity);

                        g.Restore();
                    }

                    checker = false;
                }

                // If we are at least 200% and grid is requested, draw it
                if (PintaCore.Actions.View.PixelGrid.Active && cr.ScaleFactor.Ratio <= 0.5d)
                {
                    gr.Render(canvas, canvas_bounds.Location);
                    g.SetSourceSurface(canvas, canvas_bounds.X, canvas_bounds.Y);
                    g.Paint();
                }

                // Selection outline
                if (PintaCore.Layers.ShowSelection)
                {
                    g.Save();
                    g.Translate(0.5, 0.5);
                    g.Scale(scale, scale);

                    g.AppendPath(PintaCore.Layers.SelectionPath);

                    if (PintaCore.Tools.CurrentTool.Name.Contains("Select") && !PintaCore.Tools.CurrentTool.Name.Contains("Selected"))
                    {
                        g.Color    = new Cairo.Color(0.7, 0.8, 0.9, 0.2);
                        g.FillRule = Cairo.FillRule.EvenOdd;
                        g.FillPreserve();
                    }

                    g.LineWidth = 1 / scale;

                    // Draw a white line first so it shows up on dark backgrounds
                    g.Color = new Cairo.Color(1, 1, 1);
                    g.StrokePreserve();

                    // Draw a black dashed line over the white line
                    g.SetDash(new double[] { 2 / scale, 4 / scale }, 0);
                    g.Color = new Cairo.Color(0, 0, 0);

                    g.Stroke();
                    g.Restore();
                }
            }

            return(true);
        }
Beispiel #23
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;
        }
Beispiel #24
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);
        }
Beispiel #25
0
            protected override bool OnExposeEvent(Gdk.EventExpose e)
            {
                using (Cairo.Context cr = Gdk.CairoHelper.Create(e.Window)) {
                    cr.LineWidth = Math.Max(1.0, widget.Editor.Options.Zoom);

                    cr.Rectangle(leftSpacer, 0, Allocation.Width, Allocation.Height);
                    cr.SetSourceRGB(0.95, 0.95, 0.95);
                    cr.Fill();

                    int    startLine = widget.Editor.YToLine((int)widget.Editor.VAdjustment.Value);
                    double startY    = widget.Editor.LineToY(startLine);
                    while (startLine > 1 && startLine < annotations.Count && annotations[startLine - 1] != null && annotations[startLine] != null && annotations[startLine - 1].Revision == annotations[startLine].Revision)
                    {
                        startLine--;
                        startY -= widget.Editor.GetLineHeight(widget.Editor.Document.GetLine(startLine));
                    }
                    double curY = startY - widget.Editor.VAdjustment.Value;
                    int    line = startLine;
                    while (curY < Allocation.Bottom && line <= widget.Editor.LineCount)
                    {
                        double curStart = curY;
//						widget.JumpOverFoldings (ref line);
                        int        lineStart = line;
                        int        authorWidth = 0, revisionWidth = 0, dateWidth = 0, h = 16;
                        Annotation ann = line <= annotations.Count ? annotations[line - 1] : null;
                        if (ann != null)
                        {
                            do
                            {
                                widget.JumpOverFoldings(ref line);
                                line++;
                            } while (line <= annotations.Count && annotations[line - 1] != null && annotations[line - 1].Revision == ann.Revision);

                            double nextY = widget.editor.LineToY(line) - widget.editor.VAdjustment.Value;
                            if (highlightAnnotation != null && highlightAnnotation.Revision == ann.Revision && curStart <= highlightPositon && highlightPositon < nextY)
                            {
                                cr.Rectangle(leftSpacer, curStart + cr.LineWidth, Allocation.Width - leftSpacer, nextY - curStart - cr.LineWidth);
                                cr.SetSourceRGB(1, 1, 1);
                                cr.Fill();
                            }

                            // use a fixed size revision to get a approx. revision width
                            layout.SetText("88888888");
                            layout.GetPixelSize(out revisionWidth, out h);
                            layout.SetText(TruncRevision(ann.Revision));
                            e.Window.DrawLayout(Style.BlackGC, Allocation.Width - revisionWidth - margin, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout);

                            const int dateRevisionSpacing = 16;
                            if (ann.HasDate)
                            {
                                string dateTime = ann.Date.ToShortDateString();
                                // use a fixed size date to get a approx. date width
                                layout.SetText(new DateTime(1999, 10, 10).ToShortDateString());
                                layout.GetPixelSize(out dateWidth, out h);
                                layout.SetText(dateTime);
                                e.Window.DrawLayout(Style.BlackGC, Allocation.Width - revisionWidth - margin - revisionWidth - dateRevisionSpacing, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout);
                            }

                            using (var authorLayout = PangoUtil.CreateLayout(this)) {
                                var description = Pango.FontDescription.FromString("Tahoma " + (int)(10 * widget.Editor.Options.Zoom));
                                authorLayout.FontDescription = description;
                                authorLayout.SetText(ann.Author);
                                authorLayout.GetPixelSize(out authorWidth, out h);

                                var maxWidth = Allocation.Width - revisionWidth - margin - revisionWidth - dateRevisionSpacing;

                                /*				if (authorWidth > maxWidth) {
                                 *                                      int idx = ann.Author.IndexOf ('<');
                                 *                                      if (idx > 0)
                                 *                                              authorLayout.SetText (ann.Author.Substring (0, idx) + Environment.NewLine + ann.Author.Substring (idx));
                                 *                                      authorLayout.GetPixelSize (out authorWidth, out h);
                                 *                              }*/

                                cr.Save();
                                cr.Rectangle(0, 0, maxWidth, Allocation.Height);
                                cr.Clip();
                                cr.Translate(leftSpacer + margin, (int)(curY + (widget.Editor.LineHeight - h) / 2));
                                cr.SetSourceRGB(0, 0, 0);
                                cr.ShowLayout(authorLayout);
                                cr.ResetClip();
                                cr.Restore();
                            }

                            curY = nextY;
                        }
                        else
                        {
                            curY += widget.Editor.GetLineHeight(line);
                            line++;
                            widget.JumpOverFoldings(ref line);
                        }

                        if (ann != null && line - lineStart > 1)
                        {
                            string msg = GetCommitMessage(lineStart, false);
                            if (!string.IsNullOrEmpty(msg))
                            {
                                msg = Revision.FormatMessage(msg);

                                layout.SetText(msg);
                                layout.Width = (int)(Allocation.Width * Pango.Scale.PangoScale);
                                using (var gc = new Gdk.GC(e.Window)) {
                                    gc.RgbFgColor    = Style.Dark(State);
                                    gc.ClipRectangle = new Rectangle(0, (int)curStart, Allocation.Width, (int)(curY - curStart));
                                    e.Window.DrawLayout(gc, (int)(leftSpacer + margin), (int)(curStart + h), layout);
                                }
                            }
                        }

                        cr.Rectangle(0, curStart, leftSpacer, curY - curStart);

                        if (ann != null && ann != locallyModified && !string.IsNullOrEmpty(ann.Author))
                        {
                            double a;

                            if (ann != null && (maxDate - minDate).TotalHours > 0)
                            {
                                a = 1 - (ann.Date - minDate).TotalHours / (maxDate - minDate).TotalHours;
                            }
                            else
                            {
                                a = 1;
                            }
                            HslColor color = new Cairo.Color(0.90, 0.90, 1);
                            color.L = 0.4 + a / 2;
                            color.S = 1 - a / 2;
                            cr.SetSourceColor(color);
                        }
                        else
                        {
                            cr.SetSourceColor(ann != null ? new Cairo.Color(1, 1, 0) : new Cairo.Color(0.95, 0.95, 0.95));
                        }
                        cr.Fill();

                        if (ann != null)
                        {
                            cr.MoveTo(0, curY + 0.5);
                            cr.LineTo(Allocation.Width, curY + 0.5);
                            cr.SetSourceRGB(0.6, 0.6, 0.6);
                            cr.Stroke();
                        }
                    }
                }
                return(true);
            }
Beispiel #26
0
        private void DrawImageSized(PageImage pi, Gdk.Pixbuf im, Cairo.Context g, Cairo.Rectangle r)
        {
            double    height, width;   // some work variables
            StyleInfo si = pi.SI;

            // adjust drawing rectangle based on padding
//            System.Drawing.RectangleF r2 = new System.Drawing.RectangleF(r.Left + PixelsX(si.PaddingLeft),
//                r.Top + PixelsY(si.PaddingTop),
//                r.Width - PixelsX(si.PaddingLeft + si.PaddingRight),
//                r.Height - PixelsY(si.PaddingTop + si.PaddingBottom));
            Cairo.Rectangle r2 = new Cairo.Rectangle(r.X + PixelsX(si.PaddingLeft),
                                                     r.Y + PixelsY(si.PaddingTop),
                                                     r.Width - PixelsX(si.PaddingLeft + si.PaddingRight),
                                                     r.Height - PixelsY(si.PaddingTop + si.PaddingBottom));

            Cairo.Rectangle ir;   // int work rectangle
            switch (pi.Sizing)
            {
            case ImageSizingEnum.AutoSize:
//                    // Note: GDI+ will stretch an image when you only provide
//                    //  the left/top coordinates.  This seems pretty stupid since
//                    //  it results in the image being out of focus even though
//                    //  you don't want the image resized.
//                    if (g.DpiX == im.HorizontalResolution &&
//                        g.DpiY == im.VerticalResolution)
                float imwidth  = PixelsX(im.Width);
                float imheight = PixelsX(im.Height);
                ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
                                         imwidth, imheight);
//                    else
//                        ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
//                                           Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height));
                //g.DrawImage(im, ir);
                im = im.ScaleSimple((int)r2.Width, (int)r2.Height, Gdk.InterpType.Hyper);
                g.DrawPixbufRect(im, ir);
                break;

            case ImageSizingEnum.Clip:
//                    Region saveRegion = g.Clip;
                g.Save();
//                    Region clipRegion = new Region(g.Clip.GetRegionData());
//                    clipRegion.Intersect(r2);
//                    g.Clip = clipRegion;
                g.Rectangle(r2);
                g.Clip();

//                    if (dpiX == im.HorizontalResolution &&
//                        dpiY == im.VerticalResolution)
                ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
                                         im.Width, im.Height);
//                    else
//                        ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
//                                           Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height));
//                    g.DrawImage(im, ir);
                g.DrawPixbufRect(im, ir);
//                    g.Clip = saveRegion;
                g.Restore();
                break;

            case ImageSizingEnum.FitProportional:
                double ratioIm = (float)im.Height / (float)im.Width;
                double ratioR  = r2.Height / r2.Width;
                height = r2.Height;
                width  = r2.Width;
                if (ratioIm > ratioR)
                {
                    // this means the rectangle width must be corrected
                    width = height * (1 / ratioIm);
                }
                else if (ratioIm < ratioR)
                {
                    // this means the ractangle height must be corrected
                    height = width * ratioIm;
                }
                r2 = new Cairo.Rectangle(r2.X, r2.Y, width, height);
                g.DrawPixbufRect(im, r2);
                break;

            case ImageSizingEnum.Fit:
            default:
                g.DrawPixbufRect(im, r2);
                break;
            }
        }
Beispiel #27
0
 public override void Clip(object backend)
 {
     Cairo.Context ctx = ((CairoContextBackend)backend).Context;
     ctx.Clip();
 }
Beispiel #28
0
        protected override bool OnExposeEvent(EventExpose e)
        {
            base.OnExposeEvent(e);

            if (!PintaCore.Workspace.HasOpenDocuments)
            {
                return(true);
            }

            double scale = PintaCore.Workspace.Scale;

            int x = (int)PintaCore.Workspace.Offset.X;
            int y = (int)PintaCore.Workspace.Offset.Y;

            // Translate our expose area for the whole drawingarea to just our canvas
            Rectangle canvas_bounds = new Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width, PintaCore.Workspace.CanvasSize.Height);

            canvas_bounds.Intersect(e.Area);

            if (canvas_bounds.IsEmpty)
            {
                return(true);
            }

            canvas_bounds.X -= x;
            canvas_bounds.Y -= y;

            // Resize our offscreen surface to a surface the size of our drawing area
            if (canvas == null || canvas.Width != canvas_bounds.Width || canvas.Height != canvas_bounds.Height)
            {
                if (canvas != null)
                {
                    (canvas as IDisposable).Dispose();
                }

                canvas = new Cairo.ImageSurface(Cairo.Format.Argb32, canvas_bounds.Width, canvas_bounds.Height);
            }

            cr.Initialize(PintaCore.Workspace.ImageSize, PintaCore.Workspace.CanvasSize);

            using (Cairo.Context g = CairoHelper.Create(GdkWindow)) {
                // Draw our canvas drop shadow
                g.DrawRectangle(new Cairo.Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width + 1, PintaCore.Workspace.CanvasSize.Height + 1), new Cairo.Color(.5, .5, .5), 1);
                g.DrawRectangle(new Cairo.Rectangle(x - 1, y - 1, PintaCore.Workspace.CanvasSize.Width + 3, PintaCore.Workspace.CanvasSize.Height + 3), new Cairo.Color(.8, .8, .8), 1);
                g.DrawRectangle(new Cairo.Rectangle(x - 2, y - 2, PintaCore.Workspace.CanvasSize.Width + 5, PintaCore.Workspace.CanvasSize.Height + 5), new Cairo.Color(.9, .9, .9), 1);

                // Set up our clip rectangle
                g.Rectangle(new Cairo.Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width, PintaCore.Workspace.CanvasSize.Height));
                g.Clip();

                g.Translate(x, y);

                // Render all the layers to a surface
                var layers = PintaCore.Layers.GetLayersToPaint();
                if (layers.Count == 0)
                {
                    canvas.Clear();
                }
                cr.Render(layers, canvas, canvas_bounds.Location);

                // Paint the surface to our canvas
                g.SetSourceSurface(canvas, canvas_bounds.X + (int)(0 * scale), canvas_bounds.Y + (int)(0 * scale));
                g.Paint();

                // Selection outline
                if (PintaCore.Layers.ShowSelection)
                {
                    g.Save();
                    g.Translate(0.5, 0.5);
                    g.Scale(scale, scale);

                    g.AppendPath(PintaCore.Workspace.ActiveDocument.Selection.SelectionPath);

                    if (PintaCore.Tools.CurrentTool.Name.Contains("Select") && !PintaCore.Tools.CurrentTool.Name.Contains("Selected"))
                    {
                        g.Color    = new Cairo.Color(0.7, 0.8, 0.9, 0.2);
                        g.FillRule = Cairo.FillRule.EvenOdd;
                        g.FillPreserve();
                    }

                    g.LineWidth = 1 / scale;

                    // Draw a white line first so it shows up on dark backgrounds
                    g.Color = new Cairo.Color(1, 1, 1);
                    g.StrokePreserve();

                    // Draw a black dashed line over the white line
                    g.SetDash(new double[] { 2 / scale, 4 / scale }, 0);
                    g.Color = new Cairo.Color(0, 0, 0);

                    g.Stroke();
                    g.Restore();
                }
            }

            return(true);
        }
Beispiel #29
0
 public void Clip(object backend)
 {
     Cairo.Context ctx = ((GtkContext)backend).Context;
     ctx.Clip();
 }
Beispiel #30
0
            protected override bool OnExposeEvent(EventExpose evnt)
            {
                bool hideButton = widget.MainEditor.Document.IsReadOnly;

                using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) {
                    cr.Rectangle(evnt.Region.Clipbox.X, evnt.Region.Clipbox.Y, evnt.Region.Clipbox.Width, evnt.Region.Clipbox.Height);
                    cr.Clip();
                    int delta = widget.MainEditor.Allocation.Y - Allocation.Y;
                    if (Diff != null)
                    {
                        foreach (Hunk hunk in Diff)
                        {
                            double z1 = delta + fromEditor.LineToY(hunk.RemoveStart) - fromEditor.VAdjustment.Value;
                            double z2 = delta + fromEditor.LineToY(hunk.RemoveStart + hunk.Removed) - fromEditor.VAdjustment.Value;
                            if (z1 == z2)
                            {
                                z2 = z1 + 1;
                            }

                            double y1 = delta + toEditor.LineToY(hunk.InsertStart) - toEditor.VAdjustment.Value;
                            double y2 = delta + toEditor.LineToY(hunk.InsertStart + hunk.Inserted) - toEditor.VAdjustment.Value;

                            if (y1 == y2)
                            {
                                y2 = y1 + 1;
                            }

                            if (!useLeft)
                            {
                                var tmp = z1;
                                z1 = y1;
                                y1 = tmp;

                                tmp = z2;
                                z2  = y2;
                                y2  = tmp;
                            }

                            int x1 = 0;
                            int x2 = Allocation.Width;

                            if (!hideButton)
                            {
                                if (useLeft && hunk.Removed > 0 || !useLeft && hunk.Removed == 0)
                                {
                                    x1 += 16;
                                }
                                else
                                {
                                    x2 -= 16;
                                }
                            }

                            if (z1 == z2)
                            {
                                z2 = z1 + 1;
                            }

                            cr.MoveTo(x1, z1);

                            cr.CurveTo(x1 + (x2 - x1) / 4, z1,
                                       x1 + (x2 - x1) * 3 / 4, y1,
                                       x2, y1);

                            cr.LineTo(x2, y2);
                            cr.CurveTo(x1 + (x2 - x1) * 3 / 4, y2,
                                       x1 + (x2 - x1) / 4, z2,
                                       x1, z2);
                            cr.ClosePath();
                            cr.SetSourceColor(GetColor(hunk, this.useLeft, false, 1.0));
                            cr.Fill();

                            cr.SetSourceColor(GetColor(hunk, this.useLeft, true, 1.0));
                            cr.MoveTo(x1, z1);
                            cr.CurveTo(x1 + (x2 - x1) / 4, z1,
                                       x1 + (x2 - x1) * 3 / 4, y1,
                                       x2, y1);
                            cr.Stroke();

                            cr.MoveTo(x2, y2);
                            cr.CurveTo(x1 + (x2 - x1) * 3 / 4, y2,
                                       x1 + (x2 - x1) / 4, z2,
                                       x1, z2);
                            cr.Stroke();

                            if (!hideButton)
                            {
                                bool isButtonSelected = hunk == selectedHunk;

                                double x, y, w, h;
                                bool   drawArrow = useLeft ? GetButtonPosition(hunk, y1, y2, z1, z2, out x, out y, out w, out h) :
                                                   GetButtonPosition(hunk, z1, z2, y1, y2, out x, out y, out w, out h);

                                cr.Rectangle(x, y, w, h);
                                if (isButtonSelected)
                                {
                                    int mx, my;
                                    GetPointer(out mx, out my);
                                    //	mx -= (int)x;
                                    //	my -= (int)y;
                                    using (var gradient = new Cairo.RadialGradient(mx, my, h, mx, my, 2)) {
                                        var color = (MonoDevelop.Components.HslColor)Style.Mid(StateType.Normal);
                                        color.L *= 1.05;
                                        gradient.AddColorStop(0, color);
                                        color.L *= 1.07;
                                        gradient.AddColorStop(1, color);
                                        cr.SetSource(gradient);
                                    }
                                }
                                else
                                {
                                    cr.SetSourceColor((MonoDevelop.Components.HslColor)Style.Mid(StateType.Normal));
                                }
                                cr.FillPreserve();

                                cr.SetSourceColor((MonoDevelop.Components.HslColor)Style.Dark(StateType.Normal));
                                cr.Stroke();
                                cr.LineWidth = 1;
                                cr.SetSourceColor(MonoDevelop.Ide.Gui.Styles.BaseForegroundColor.ToCairoColor());
                                if (drawArrow)
                                {
                                    DrawArrow(cr, x + w / 1.5, y + h / 2);
                                    DrawArrow(cr, x + w / 2.5, y + h / 2);
                                }
                                else
                                {
                                    DrawCross(cr, x + w / 2, y + (h) / 2);
                                }
                                cr.Stroke();
                            }
                        }
                    }
                }
//				var result = base.OnExposeEvent (evnt);
//
//				Gdk.GC gc = Style.DarkGC (State);
//				evnt.Window.DrawLine (gc, Allocation.X, Allocation.Top, Allocation.X, Allocation.Bottom);
//				evnt.Window.DrawLine (gc, Allocation.Right, Allocation.Top, Allocation.Right, Allocation.Bottom);
//
//				evnt.Window.DrawLine (gc, Allocation.Left, Allocation.Y, Allocation.Right, Allocation.Y);
//				evnt.Window.DrawLine (gc, Allocation.Left, Allocation.Bottom, Allocation.Right, Allocation.Bottom);

                return(true);
            }
Beispiel #31
0
        protected override void Redraw(Cairo.Context cr)
        {
            // no axes, or have we not been SizeAllocated yet?
            if (axis_requisitions.Count <= 0)
            {
                return;
            }

            // remember, Gdk.Rectangle is a ValueType.
            Gdk.Rectangle alloc = plot_alloc;

            // render the field
            style_prov.DrawField(cr, alloc.X, alloc.Y,
                                 alloc.Width, alloc.Height);

            Gdk.Rectangle inner_alloc = alloc;
            inner_alloc.X      += style_prov.FieldLineThickness;
            inner_alloc.Y      += style_prov.FieldLineThickness;
            inner_alloc.Width  -= (style_prov.FieldLineThickness * 2);
            inner_alloc.Height -= (style_prov.FieldLineThickness * 2);


            // create an ArrayList of axes for each location
            ArrayList[] axes_by_location = new ArrayList[4];
            foreach (IAxis axis in axes)
            {
                if (!axis.Visible)
                {
                    continue;
                }

                ArrayList list = axes_by_location[(int)axis.Location];
                if (list == null)
                {
                    list = new ArrayList();
                }

                list.Add(axis);

                axes_by_location[(int)axis.Location] = list;
            }

            for (int i = 0; i < 4; i++)
            {
                int x = 0, y = 0;

                AxisLocation l = (AxisLocation)i;
                switch (l)
                {
                case AxisLocation.Top:
                    y = alloc.Y;
                    break;

                case AxisLocation.Bottom:
                    y = alloc.Y + alloc.Height;
                    break;

                case AxisLocation.Left:
                    x = alloc.X;
                    break;

                case AxisLocation.Right:
                    x = alloc.X + alloc.Width;
                    break;
                }

                ArrayList list = axes_by_location[i];
                if (list == null)
                {
                    continue;
                }

                foreach (IAxis axis in list)
                {
                    if (!axis_requisitions.ContainsKey(axis))
                    {
                        // hasn't been size requested.  we'll get it next redraw
                        continue;
                    }

                    Requisition req = (Requisition)axis_requisitions[axis];

                    Gdk.Rectangle a = new Gdk.Rectangle();
                    switch ((AxisLocation)i)
                    {
                    case AxisLocation.Top:
                        a.X      = alloc.X;
                        a.Y      = y - req.Height;
                        a.Width  = alloc.Width;
                        a.Height = req.Height;

                        y -= a.Height;
                        break;

                    case AxisLocation.Bottom:
                        a.X      = alloc.X;
                        a.Y      = y;
                        a.Width  = alloc.Width;
                        a.Height = req.Height;

                        y += a.Height;
                        break;

                    case AxisLocation.Left:
                        a.X      = x - req.Width;
                        a.Y      = alloc.Y;
                        a.Width  = req.Width;
                        a.Height = alloc.Height;

                        x -= a.Width;
                        break;

                    case AxisLocation.Right:
                        a.X      = x;
                        a.Y      = alloc.Y;
                        a.Width  = req.Width;
                        a.Height = alloc.Height;

                        x += a.Width;
                        break;
                    }

                    if (a.Width > 0 && a.Height > 0)
                    {
                        cr.Rectangle(a.X, a.Y, a.Width, a.Height);
                        cr.Clip();

                        axis.DrawTicks(a, cr);

                        cr.ResetClip();
                    }

                    if (draw_grid_lines)
                    {
                        cr.Rectangle(inner_alloc.X - 0.5f, inner_alloc.Y - 0.5f,
                                     inner_alloc.Width + 0.5f, inner_alloc.Height + 0.5f);
                        cr.Clip();

                        axis.DrawGridLines(inner_alloc, cr);

                        cr.ResetClip();
                    }
                }
            }

            // clip drawing to plot_alloc
            cr.Rectangle(inner_alloc.X - 0.5f, inner_alloc.Y,
                         inner_alloc.Width, inner_alloc.Height);
            cr.Clip();

            // draw all plots
            foreach (IPlot plot in plots)
            {
                plot.SizeAllocate(plot_alloc);
                plot.Draw(cr);
            }

            // draw selection rect
            if (selection_started)
            {
                style_prov.DrawSelectionRectangle(cr, sel_rect.X,
                                                  sel_rect.Y,
                                                  sel_rect.Width,
                                                  sel_rect.Height);
            }

            cr.ResetClip();
        }
Beispiel #32
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 = CurrentTextLayout.GetLayoutBounds();

            r.Inflate(10 + OutlineWidth, 10 + OutlineWidth);
            InflateAndInvalidate(r);
            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.Layer.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 CurrentTextLayout.SelectionRectangles)
                    {
                        g.FillRectangle(rect.ToCairoRectangle(), c);
                    }
                }

                if (selection != null)
                {
                    g.AppendPath(selection.SelectionPath);
                    g.FillRule = Cairo.FillRule.EvenOdd;
                    g.Clip();
                }

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

                g.SetSourceColor(PintaCore.Palette.PrimaryColor);

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

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

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

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

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

                if (showCursor)
                {
                    var loc   = CurrentTextLayout.GetCursorLocation();
                    var color = PintaCore.Palette.PrimaryColor;

                    g.Antialias = Cairo.Antialias.None;
                    g.DrawLine(new Cairo.PointD(loc.X, loc.Y),
                               new Cairo.PointD(loc.X, loc.Y + loc.Height),
                               color, 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(CurrentTextBounds.ToCairoRectangle()))
                    {
                        g.AppendPath(p);
                    }

                    g.LineWidth = 1;

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

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

                    g.Stroke();

                    g.Restore();
                }
            }

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

            old_cursor_bounds = cursorBounds;
        }
Beispiel #33
0
        private void PaintList(Cairo.Context cr, Rectangle clip)
        {
            if (ChildSize.Height <= 0)
            {
                return;
            }

            // TODO factor this out?
            // Render the sort effect to the GdkWindow.
            if (sort_column_index != -1 && (!pressed_column_is_dragging || pressed_column_index != sort_column_index))
            {
                CachedColumn col = column_cache[sort_column_index];
                StyleContext.AddRegion("column", RegionFlags.Sorted);
                StyleContext.RenderBackground(cr,
                                              list_rendering_alloc.X + col.X1 - HadjustmentValue,
                                              header_rendering_alloc.Bottom + Theme.BorderWidth,
                                              col.Width, list_rendering_alloc.Height + Theme.InnerBorderWidth * 2);
                StyleContext.RemoveRegion("column");
            }

            clip.Intersect(list_rendering_alloc);
            cr.Rectangle(clip.X, clip.Y, clip.Width, clip.Height);
            cr.Clip();

            cell_context.Clip             = clip;
            cell_context.TextAsForeground = false;

            int vadjustment_value = VadjustmentValue;
            int first_row         = vadjustment_value / ChildSize.Height;
            int last_row          = Math.Min(model.Count, first_row + RowsInView);
            int offset            = list_rendering_alloc.Y - vadjustment_value % ChildSize.Height;

            Rectangle selected_focus_alloc = Rectangle.Zero;
            Rectangle single_list_alloc    = new Rectangle();

            single_list_alloc.X      = list_rendering_alloc.X - HadjustmentValue;
            single_list_alloc.Y      = offset;
            single_list_alloc.Width  = list_rendering_alloc.Width + HadjustmentValue;
            single_list_alloc.Height = ChildSize.Height;

            int selection_height = 0;
            int selection_y      = 0;

            selected_rows.Clear();

            for (int ri = first_row; ri < last_row; ri++)
            {
                if (Selection != null && Selection.Contains(ri))
                {
                    if (selection_height == 0)
                    {
                        selection_y = single_list_alloc.Y;
                    }

                    selection_height += single_list_alloc.Height;
                    selected_rows.Add(ri);

                    if (Selection.FocusedIndex == ri)
                    {
                        selected_focus_alloc = single_list_alloc;
                    }
                }
                else
                {
                    StyleContext.AddClass("cell");
                    if (rules_hint)   // TODO: check also gtk_widget_style_get(widget,"allow-rules",&allow_rules,NULL);
                    {
                        StyleContext.AddRegion("row", ri % 2 != 0 ? RegionFlags.Odd : RegionFlags.Even);
                    }
                    StyleContext.RenderBackground(cr, single_list_alloc.X, single_list_alloc.Y,
                                                  single_list_alloc.Width, single_list_alloc.Height);
                    StyleContext.RemoveRegion("row");
                    StyleContext.RemoveClass("cell");

                    PaintReorderLine(cr, ri, single_list_alloc);

                    if (Selection != null && Selection.FocusedIndex == ri && !Selection.Contains(ri) && HasFocus)
                    {
                        CairoCorners corners = CairoCorners.All;

                        if (Selection.Contains(ri - 1))
                        {
                            corners &= ~(CairoCorners.TopLeft | CairoCorners.TopRight);
                        }

                        if (Selection.Contains(ri + 1))
                        {
                            corners &= ~(CairoCorners.BottomLeft | CairoCorners.BottomRight);
                        }

                        if (HasFocus && !HeaderFocused) // Cursor out of selection.
                        {
                            Theme.DrawRowCursor(cr, single_list_alloc.X, single_list_alloc.Y,
                                                single_list_alloc.Width, single_list_alloc.Height,
                                                CairoExtensions.ColorShade(CairoExtensions.GdkRGBAToCairoColor(StyleContext.GetBackgroundColor(StateFlags.Selected)), 0.85));
                        }
                    }

                    if (selection_height > 0)
                    {
                        StyleContext.AddClass("cell");
                        var bg_selected_color = StyleContext.GetBackgroundColor(StateFlags.Selected);

                        if (bg_selected_color.Equals(StyleContext.GetBackgroundColor(StateFlags.Normal)))
                        {
                            // see https://bugs.launchpad.net/bugs/1211831
                            Hyena.Log.Warning("Buggy CSS theme: same background-color for .cell:selected and .cell");
                            StyleContext.RemoveClass("cell");
                            bg_selected_color = StyleContext.GetBackgroundColor(StateFlags.Selected);
                            StyleContext.AddClass("cell");
                        }
                        Cairo.Color selection_color = CairoExtensions.GdkRGBAToCairoColor(bg_selected_color);

                        if (!HasFocus || HeaderFocused)
                        {
                            selection_color = CairoExtensions.ColorShade(selection_color, 1.1);
                        }

                        Theme.DrawRowSelection(cr, list_rendering_alloc.X, selection_y, list_rendering_alloc.Width, selection_height,
                                               true, true, selection_color, CairoCorners.All);
                        StyleContext.RemoveClass("cell");
                        selection_height = 0;
                    }

                    PaintRow(cr, ri, single_list_alloc, StateFlags.Normal);
                }

                single_list_alloc.Y += single_list_alloc.Height;
            }

            // In case the user is dragging to the end of the list
            PaintReorderLine(cr, last_row, single_list_alloc);

            if (selection_height > 0)
            {
                Theme.DrawRowSelection(cr, list_rendering_alloc.X, selection_y,
                                       list_rendering_alloc.Width, selection_height);
            }

            if (Selection != null && Selection.Count > 1 &&
                !selected_focus_alloc.Equals(Rectangle.Zero) &&
                HasFocus && !HeaderFocused)   // Cursor inside selection.
            // Use entry to get text color
            {
                StyleContext.Save();
                StyleContext.AddClass("entry");
                Cairo.Color text_color = CairoExtensions.GdkRGBAToCairoColor(StyleContext.GetColor(StateFlags.Selected));
                StyleContext.Restore();

                Theme.DrawRowCursor(cr, selected_focus_alloc.X, selected_focus_alloc.Y,
                                    selected_focus_alloc.Width, selected_focus_alloc.Height, text_color);
            }

            foreach (int ri in selected_rows)
            {
                single_list_alloc.Y = offset + ((ri - first_row) * single_list_alloc.Height);
                PaintRow(cr, ri, single_list_alloc, StateFlags.Selected);
            }

            cr.ResetClip();
        }
		// 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 ();
		}
Beispiel #35
0
        public void Draw(Gdk.Drawable window, Cairo.Context ctx, Gdk.Rectangle bounds, StateType state)
        {
            if (curve == null)
            {
                return;
            }

            var drawBounds  = GraphAreaFromBounds(new RectangleF(bounds.X, bounds.Y, bounds.Width, bounds.Height));
            var outerBounds = drawBounds.Inflated(3);

            // Outer clip area
            ctx.Save();
            ctx.Rectangle(outerBounds.X, outerBounds.Y, outerBounds.Width, outerBounds.Height);
            ctx.Clip();

            var colorSelectedBackground = WidgetTools.ColorSelectedBackground;
            var colorBorder             = WidgetTools.ColorBorder;
            var colorLine          = WidgetTools.ColorLine;
            var colorHoveredEntry  = WidgetTools.ColorHoveredEntry;
            var colorSelectedEntry = WidgetTools.ColorSelectedEntry;

            // Background
            if (state == StateType.Selected)
            {
                WidgetTools.SetColor(ctx, colorSelectedBackground);
                ctx.Rectangle(outerBounds.X, outerBounds.Y, outerBounds.Width, outerBounds.Height);
                ctx.Fill();
            }

            // Border
            WidgetTools.SetColor(ctx, colorBorder);
            ctx.LineWidth = 1.0;
            ctx.Rectangle(outerBounds.X, outerBounds.Y, outerBounds.Width, outerBounds.Height);
            ctx.Stroke();

            // Zero line
            if (HasZeroLine)
            {
                var height = ToScreen(Vector2.Zero, drawBounds);
                WidgetTools.SetColor(ctx, colorBorder);
                ctx.MoveTo(outerBounds.X, height.Y);
                ctx.LineTo(outerBounds.X + outerBounds.Width, height.Y);
                ctx.LineWidth = 1.0;
                WidgetTools.SetDash(ctx, true);
                ctx.Stroke();
            }

            //// Inner clip area
            //ctx.Rectangle(drawBounds.X, drawBounds.Y, drawBounds.Width, drawBounds.Height);
            //ctx.Clip();

            if (curve.Count > 0)
            {
                WidgetTools.SetColor(ctx, colorLine);

                int numSteps = (int)drawBounds.Width;

                var p = Evaluate(0, drawBounds);
                ctx.MoveTo(p.X, p.Y);
                ctx.LineWidth = 1.2;
                WidgetTools.SetDash(ctx, true);

                var startFraction = curve.Front.Value.X;
                var endFraction   = curve.End.Value.X;
                int part          = 0;

                for (int i = 0; numSteps > 0 && i <= numSteps; i++)
                {
                    var fraction = (float)i / numSteps;

                    if (fraction >= startFraction && part == 0)
                    {
                        p = ToScreen(curve.Front.Value, drawBounds);
                        ctx.LineTo(p.X, p.Y);
                        ctx.Stroke();
                        WidgetTools.SetDash(ctx, false);
                        ctx.MoveTo(p.X, p.Y);

                        part++;
                    }

                    if (fraction >= endFraction && part == 1)
                    {
                        p = ToScreen(curve.End.Value, drawBounds);
                        ctx.LineTo(p.X, p.Y);
                        ctx.Stroke();
                        WidgetTools.SetDash(ctx, true);
                        ctx.MoveTo(p.X, p.Y);

                        part++;
                    }

                    p = Evaluate(fraction, drawBounds);
                    ctx.LineTo(p.X, p.Y);
                }

                ctx.Stroke();
                WidgetTools.SetDash(ctx, false);

                foreach (var entry in curve)
                {
                    var   b         = ToScreen(entry.Value, drawBounds);
                    float size      = 4;
                    float outerSize = size + 1;

                    var color      = colorLine;
                    var outerColor = MG.Framework.Numerics.Color.Transparent;
                    if (entry == hoveredEntry)
                    {
                        color = colorHoveredEntry;
                    }

                    if (entry == selectedEntry)
                    {
                        color      = colorHoveredEntry;
                        outerColor = colorSelectedEntry;

                        ctx.LineWidth = 1.0;
                        WidgetTools.SetColor(ctx, outerColor);

                        if (entry.Type == CurveEntry.EntryType.Bezier)
                        {
                            ctx.MoveTo(b.X, b.Y);
                            p = ToScreen(entry.LeftHandle, drawBounds);
                            ctx.LineTo(p.X, p.Y);
                            ctx.Stroke();

                            WidgetTools.SetColor(ctx, hoveredHandle == Handle.Left ? colorHoveredEntry : outerColor);
                            ctx.Arc(p.X, p.Y, 2, 0, 2 * Math.PI);
                            ctx.Fill();

                            WidgetTools.SetColor(ctx, outerColor);
                            ctx.MoveTo(b.X, b.Y);
                            p = ToScreen(entry.RightHandle, drawBounds);
                            ctx.LineTo(p.X, p.Y);
                            ctx.Stroke();

                            WidgetTools.SetColor(ctx, hoveredHandle == Handle.Right ? colorHoveredEntry : outerColor);
                            ctx.Arc(p.X, p.Y, 2, 0, 2 * Math.PI);
                            ctx.Fill();
                        }
                    }

                    if (outerColor.A != 0)
                    {
                        WidgetTools.SetColor(ctx, outerColor);
                        ctx.Rectangle(b.X - outerSize / 2, b.Y - outerSize / 2, outerSize, outerSize);
                        ctx.LineWidth = 1.0;
                        ctx.Stroke();
                    }

                    WidgetTools.SetColor(ctx, color);
                    ctx.Rectangle(b.X - size / 2, b.Y - size / 2, size, size);
                    ctx.Fill();
                }
            }

            ctx.Restore();
        }