Beispiel #1
0
        private void DoDragBegin(Gtk.Widget child, Gdk.DragContext context)
        {
            Gdk.Pixbuf icon;

            Plotting.Graph graph = (Plotting.Graph)child;

            d_dragRenderer  = null;
            d_unmerged      = null;
            d_dragHighlight = null;

            // Check if this is going to drag a label
            if (graph.Canvas.Graph.LabelHitTest(new Point(d_lastPress), out d_dragRenderer))
            {
                icon = PixbufForRenderer(graph.Canvas.Graph, d_dragRenderer);
            }
            else
            {
                icon = graph.CreateDragIcon();
            }

            if (icon != null)
            {
                Gtk.Drag.SetIconPixbuf(context, icon, icon.Width / 2, icon.Height / 2);
            }

            d_dragging = graph;

            IndexOf(child, out d_dragRow, out d_dragColumn);

            Gdk.EventMotion evnt = Utils.GetCurrentEvent() as Gdk.EventMotion;

            d_dragmerge = (evnt != null && (evnt.State & Gdk.ModifierType.ShiftMask) != 0);

            IndexOf(child, out d_dragRow, out d_dragColumn);

            QueueDraw();
        }
Beispiel #2
0
        private Gdk.Pixbuf PixbufForRenderer(Plot.Graph graph, Plot.Renderers.Renderer renderer)
        {
            Plot.Renderers.ILabeled lbl = renderer as Plot.Renderers.ILabeled;

            if (lbl == null)
            {
                return(null);
            }

            Plot.Renderers.IColored col = renderer as Plot.Renderers.IColored;

            string s;

            if (lbl.YLabelMarkup != null)
            {
                s = lbl.YLabelMarkup;
            }
            else
            {
                s = System.Security.SecurityElement.Escape(lbl.YLabel);
            }

            if (col != null)
            {
                string hex = String.Format("#{0:x2}{1:x2}{2:x2}",
                                           (int)(col.Color.R * 255),
                                           (int)(col.Color.G * 255),
                                           (int)(col.Color.B * 255));

                s = String.Format("<span color=\"{0}\">{1}</span>", hex, s);
            }

            Pango.Layout layout = CreatePangoLayout("");
            layout.SetMarkup(s);

            if (graph.Font != null)
            {
                layout.FontDescription = graph.Font;
            }

            int w;
            int h;

            layout.GetPixelSize(out w, out h);

            int xpadding = 4;
            int ypadding = 3;

            w += 2 * xpadding;
            h += 2 * ypadding;

            Gdk.Pixmap map = new Gdk.Pixmap(GdkWindow, w, h);

            using (Cairo.Context ctx = Gdk.CairoHelper.Create(map))
            {
                ctx.Rectangle(0.5, 0.5, w - 1, h - 1);
                ctx.LineWidth = 1;

                ctx.SetSourceRGB(1, 1, 1);
                ctx.FillPreserve();

                graph.AxisLabelColors.Bg.Set(ctx);
                ctx.FillPreserve();

                graph.AxisLabelColors.Fg.Set(ctx);
                ctx.Stroke();

                ctx.Translate(xpadding + 1, ypadding);

                Pango.CairoHelper.ShowLayout(ctx, layout);
            }

            return(Gdk.Pixbuf.FromDrawable(map, map.Colormap, 0, 0, 0, 0, w, h));
        }