示例#1
0
        /// <summary>
        /// Export the map to an image.
        /// </summary>
        public Image Export()
        {
            // Create a Bitmap and draw the DataGridView on it.
            int width;
            int height;

            if (ProcessUtilities.CurrentOS.IsWindows)
            {
                // Give the browser half a second to run all its scripts
                // It would be better if we could tap into the browser's Javascript engine
                // and see whether loading of the map was complete, but my attempts to do
                // so were not entirely successful.
                Stopwatch watch = new Stopwatch();
                watch.Start();
                while (watch.ElapsedMilliseconds < 500)
                {
                    Gtk.Application.RunIteration();
                }
            }
            Gdk.Window gridWindow = MainWidget.GdkWindow;
            gridWindow.GetSize(out width, out height);
            Gdk.Pixbuf   screenshot = Gdk.Pixbuf.FromDrawable(gridWindow, gridWindow.Colormap, 0, 0, 0, 0, width, height);
            byte[]       buffer     = screenshot.SaveToBuffer("png");
            MemoryStream stream     = new MemoryStream(buffer);

            System.Drawing.Bitmap bitmap = new Bitmap(stream);
            return(bitmap);
        }
        void OnDrawingareaExposeEvent(object o, ExposeEventArgs args)
        {
            if (!this.DockItem.ContentVisible)
            {
                return;
            }

            Gdk.EventExpose expose = args.Args[0] as Gdk.EventExpose;
            Gdk.Window      win = expose.Window;
            int             width, height;

            win.GetSize(out width, out height);
            Gdk.Rectangle exposeRect = expose.Area;


            if (m_Nodes.Count == 0)
            {
                var layout = new Pango.Layout(PangoContext)
                {
                    FontDescription = Pango.FontDescription.FromString("Tahoma 12")
                };
                var gc = new Gdk.GC(win)
                {
                    RgbFgColor = Color.Blue.ToGdk(),
                };
                var text = "Add some nodes by clicking into window.\n" +
                           "Move nodes with the mouse.\n" +
                           "Remove nodes by moving out of inner area";
                layout.SetText(text);
                Drawing.DrawLayout(win, gc, layout, width / 2, height / 2, Drawing.Origin.Center, Drawing.Origin.Center);
            }

            lock (m_Nodes)
            {
                using (var context = Gdk.CairoHelper.Create(win))
                {
                    // collect all straight line segments
                    var straights = new List <PointF>();
                    straights.Add(m_Nodes.FirstOrDefault());

                    // Draw connection
                    if (m_Properties.DrawConnections)
                    {
                        DrawConnections(context);
                    }

                    // Draw text at connections
                    if (m_Properties.DrawInformation)
                    {
                        DrawInfos(context);
                    }

                    // Calculate & draw clothoides
                    CalculateAndDrawClothoides(context, straights);

                    // Draw nodes
                    DrawNodes(win, context);
                }
            }
        }
示例#3
0
        Rectangle WindowPositionAndSize(Gdk.Window window)
        {
            int x, y, width, height;

            window.GetPosition(out x, out y);
            window.GetSize(out width, out height);
            return(new Rectangle(x, y, width, height));
        }
示例#4
0
        private static CSWindow CreateWin32(Gdk.Window gdkWindow)
        {
            NativeGdkWin.Gdk_window_ensure_native(gdkWindow.Handle);
            IntPtr windowHandle = NativeGdkWin.GetWindowHandle(gdkWindow.Handle);
            int    width;
            int    height;

            gdkWindow.GetSize(out width, out height);
            return(new CSWindow(windowHandle.ToInt32(), width, height, WindowHelp.GetStartupPath()));
        }
示例#5
0
        public void DrawTable()
        {
            if (isRunning == false)
            {
                return;
            }

            int       x, y;
            int       width, height;
            int       tileSize;
            Graphics  gfx = Gtk.DotNet.Graphics.FromDrawable(gdkWindowTable);
            Rectangle recTable;
            Brush     brBakcground     = new SolidBrush(backgroundColor);
            Brush     brUnflippedPiece = new SolidBrush(primaryColor);
            Brush     brFlippedPiece   = new SolidBrush(secondaryColor);

            gdkWindowTable.GetSize(out width, out height);
            tileSize = (width - tableSize * tileSpacing) / tableSize;
            recTable = new Rectangle(0, 0, width, height);

            gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;

            gfx.FillRectangle(brBakcground, recTable);

            for (y = 0; y < tableSize; y++)
            {
                for (x = 0; x < tableSize; x++)
                {
                    recTable = new Rectangle(
                        tileSpacing / 2 + x * tileSize + x * tileSpacing,
                        tileSpacing / 2 + y * tileSize + y * tileSpacing,
                        tileSize, tileSize);

                    if (gameTable.Pieces[x, y].IsFlipped)
                    {
                        gfx.FillRectangle(brFlippedPiece, recTable);

                        Bitmap bmpPicture = Gdk.Pixbuf.LoadFromResource(
                            "MemoryBlocks.Resources.Pieces.piece" +
                            gameTable.Pieces[x, y].Value + ".png").ToBitmap();

                        gfx.DrawImage(bmpPicture, recTable);
                    }
                    else if (gameTable.Pieces[x, y].IsCleared == false)
                    {
                        gfx.FillRectangle(brUnflippedPiece, recTable);
                    }
                }
            }

            gfx.Dispose();
        }
示例#6
0
        /// <summary>Get screenshot of right hand panel.</summary>
        public System.Drawing.Image GetScreenshotOfRightHandPanel()
        {
            // Create a Bitmap and draw the panel
            int width;
            int height;

            Gdk.Window panelWindow = rightHandView.Child.GdkWindow;
            panelWindow.GetSize(out width, out height);
            Gdk.Pixbuf             screenshot = Gdk.Pixbuf.FromDrawable(panelWindow, panelWindow.Colormap, 0, 0, 0, 0, width, height);
            byte[]                 buffer     = screenshot.SaveToBuffer("png");
            System.IO.MemoryStream stream     = new System.IO.MemoryStream(buffer);
            System.Drawing.Bitmap  bitmap     = new System.Drawing.Bitmap(stream);
            return(bitmap);
        }
        void OnDrawingareaExposeEvent(object o, ExposeEventArgs args)
        {
            Gdk.EventExpose expose = args.Args[0] as Gdk.EventExpose;
            Gdk.Window      win = expose.Window;
            int             width, height;

            win.GetSize(out width, out height);
            Gdk.Rectangle exposeRect = expose.Area;


            if (true)
            {
                var layout = new Pango.Layout(PangoContext)
                {
                    FontDescription = Pango.FontDescription.FromString("Tahoma 12")
                };
                var gc = new Gdk.GC(win)
                {
                    RgbFgColor = Color.Blue.ToGdk(),
                };
                var text = "CompassNeedle.ShortHelp".Localized();
                layout.SetText(text);
                Drawing.DrawLayout(win, gc, layout, width / 2, height / 3 * 2, Drawing.Origin.Center, Drawing.Origin.Center);
            }

            using (var context = Gdk.CairoHelper.Create(win))
            {
                double scale = Math.Min(width, height) / 100.0 / 2;
                context.Translate(width / 2, height / 2);
                context.Scale(scale, scale);

                // draw clock tick marks
                {
                    context.Save();

                    // minute tick marks
                    context.SetDash(new double[] { 1.5, 3 * Math.PI - 1.5 }, 1);
                    Drawing.Ellipse(context, PointF.Empty, 90, Color.Black, false, 3);

                    // hour tick marks
                    context.SetDash(new double[] { 1.5, 15 * Math.PI - 1.5 }, 1);
                    Drawing.Ellipse(context, PointF.Empty, 90, Color.Blue, false, 5);

                    context.Restore();
                }

                DrawHand(context, m_AngleCurrent, Color.DarkBlue);
                DrawQuota(context, m_AngleQuota, Color.DarkRed);
            }
        }
        /// <summary>Get screenshot of grid.</summary>
        public System.Drawing.Image GetScreenshot()
        {
            // Create a Bitmap and draw the DataGridView on it.
            int width;
            int height;

            Gdk.Window gridWindow = hbox1.GdkWindow;  // Should we draw from hbox1 or from gridview?
            gridWindow.GetSize(out width, out height);
            Gdk.Pixbuf   screenshot = Gdk.Pixbuf.FromDrawable(gridWindow, gridWindow.Colormap, 0, 0, 0, 0, width, height);
            byte[]       buffer     = screenshot.SaveToBuffer("png");
            MemoryStream stream     = new MemoryStream(buffer);

            System.Drawing.Bitmap bitmap = new Bitmap(stream);
            return(bitmap);
        }
示例#9
0
        /// <summary>Get screenshot of right hand panel.</summary>
        public System.Drawing.Image GetScreenshotOfRightHandPanel()
        {
#if NETFRAMEWORK
            // Create a Bitmap and draw the panel
            int        width;
            int        height;
            Gdk.Window panelWindow = CurrentRightHandView.MainWidget.GdkWindow;
            panelWindow.GetSize(out width, out height);
            Gdk.Pixbuf             screenshot = Gdk.Pixbuf.FromDrawable(panelWindow, panelWindow.Colormap, 0, 0, 0, 0, width, height);
            byte[]                 buffer     = screenshot.SaveToBuffer("png");
            System.IO.MemoryStream stream     = new System.IO.MemoryStream(buffer);
            System.Drawing.Bitmap  bitmap     = new System.Drawing.Bitmap(stream);
            return(bitmap);
#else
            throw new NotImplementedException();
#endif
        }
示例#10
0
        private void Move()
        {
            Gdk.Window treewindow = d_treeview.GdkWindow;

            Realize();

            int treeX;
            int treeY;
            int treeWidth;
            int treeHeight;

            treewindow.GetOrigin(out treeX, out treeY);
            treewindow.GetSize(out treeWidth, out treeHeight);

            int x = treeX + treeWidth - Allocation.Width - 6;
            int y = treeY + treeHeight - Allocation.Height - 6;

            Move(x, y);
        }
        protected void OnDrawingareaExposeEvent(object o, Gtk.ExposeEventArgs args)
        {
            Gdk.EventExpose expose = args.Args[0] as Gdk.EventExpose;
            Gdk.Window      win = expose.Window;
            int             width, height;

            win.GetSize(out width, out height);
            Gdk.Rectangle exposeRect = expose.Area;
            bool          fulldraw   = width == exposeRect.Width && height == exposeRect.Height;

            win.DrawRectangle(Style.LightGC(StateType.Normal), true, exposeRect);
            if (GetContentDelegate == null)
            {
                return; // todo: an error message could be displayed
            }
            int offset = (int)vscrollbar1.Value;

            if (fulldraw)
            {
                TopVisibleRow    = offset;
                BottomVisibleRow = offset;
            }
            int hscrollRange = 0;
            int dy           = exposeRect.Top;

            offset += dy / ConstantHeight;
            dy     -= dy % ConstantHeight;

            Gdk.GC backgound = new Gdk.GC((Gdk.Drawable)base.GdkWindow);
            Gdk.GC text      = new Gdk.GC((Gdk.Drawable)base.GdkWindow);

            ColumnControl.Column[] columns = mColumnControl.GetVisibleColumnsInDrawOrder();

            for (int row = offset; row < RowCount; row++)
            {
                int           dx   = -(int)hscrollbar1.Value;
                Gdk.Rectangle rect = new Gdk.Rectangle(dx, dy, 0, ConstantHeight);

                System.Drawing.Color backColor = System.Drawing.Color.WhiteSmoke;
                System.Drawing.Color textColor = System.Drawing.Color.Black;

                if (isRowSelected(row))
                {
                    if (HasFocus)
                    {
                        backColor = System.Drawing.Color.DarkGray;
                    }
                    else
                    {
                        backColor = System.Drawing.Color.LightGray;
                    }
                }
                else
                {
                    if (GetColorDelegate != null)
                    {
                        GetColorDelegate(row, ref backColor, ref textColor);
                    }
                }

                backgound.RgbFgColor = new Gdk.Color(backColor.R, backColor.G, backColor.B);
                text.RgbFgColor      = new Gdk.Color(textColor.R, textColor.G, textColor.B);

                for (int c = 0; c < columns.Length; c++)
                {
                    ColumnControl.Column column = columns[c];
                    int columnIndex             = column.SortOrder;
                    int xwidth = column.Width;
                    if (dx > exposeRect.Right)
                    {
                        break;
                    }
                    rect = new Gdk.Rectangle(rect.Left, rect.Top, xwidth + mColumnControl.GripperWidth, ConstantHeight);
                    if (c == columns.Length - 1)
                    {
                        rect.Width = Math.Max(rect.Width, exposeRect.Right - rect.Left + 1);
                    }
                    object content = GetContentDelegate(row, columnIndex);
                    if (content is Gdk.Pixbuf)
                    {
                        Gdk.Pixbuf image = (Gdk.Pixbuf)content;
                        win.DrawRectangle(backgound, true, rect);
                        dx += 2;
                        image.RenderToDrawable(win, text, 0, 0, dx, dy, image.Width, image.Height, Gdk.RgbDither.Normal, 0, 0);
                        dx += xwidth + mColumnControl.GripperWidth - 2;
                        rect.Offset(xwidth + mColumnControl.GripperWidth, 0);
                    }
                    else
                    {
                        LineLayout.SetText(content.ToString());
                        win.DrawRectangle(backgound, true, rect);
                        dx += 2;
                        win.DrawLayout(text, dx, dy, LineLayout);
                        dx += xwidth + mColumnControl.GripperWidth - 2;
                        rect.Offset(xwidth + mColumnControl.GripperWidth, 0);
                    }
                }
                hscrollRange = Math.Max(hscrollRange, dx + rect.Width);
                dy          += ConstantHeight;
                if (dy > exposeRect.Bottom)
                {
                    break;
                }
                if (fulldraw && exposeRect.Height - dy >= ConstantHeight)
                {
                    BottomVisibleRow++;
                }
            }

            if (fulldraw)
            {
                int pageSize = BottomVisibleRow - TopVisibleRow;
                if (vscrollbar1.Adjustment.PageSize != pageSize)
                {
                    vscrollbar1.Adjustment.PageSize      = pageSize;
                    vscrollbar1.Adjustment.PageIncrement = pageSize;
                }
                hscrollRange += (int)hscrollbar1.Value;
                if (hscrollRange > 0)
                {
                    hscrollbar1.SetRange(0, hscrollRange);
                }

                // position current row inside visible area
                // TODO: please think about, because of double redraw a more sophisticated solution could be possible
                if (CurrentRow >= 0 && CurrentRow < RowCount)
                {
                    if (CurrentRow < TopVisibleRow)
                    {
                        OffsetCursor(TopVisibleRow - CurrentRow);
                    }
                    else if (CurrentRow > BottomVisibleRow)
                    {
                        OffsetCursor(BottomVisibleRow - CurrentRow);
                    }
                }
            }

#if DEBUG2
            if (ComponentManager != null)
            {
                String t1 = String.Format("Expose.Area={0}, size={1}.{2}",
                                          expose.Area.ToString(), width, height);
                String t2 = String.Format("{0} T={1} B={2}", fulldraw ? "FULL" : "PART", TopVisibleRow, BottomVisibleRow);
                ComponentManager.MessageWriteLineInvoke(String.Format("{0} {1}", t1, t2));
            }
#endif
        }
        void DrawFocus(Gdk.Window window, Color c)
        {
            int x, y, width, height;

            window.GetPosition(out x, out y);
            window.GetSize(out width, out height);
            System.Drawing.Rectangle r = new System.Drawing.Rectangle(x, y, width, height);

            using (Cairo.Context context = Gdk.CairoHelper.Create(window))
            {
                uint b = mainBox.BorderWidth;

                // Top
                using (Cairo.Gradient gradient = createGradient(0.0, 0.0, 0, b, c))
                {
                    context.SetSource(gradient);
                    context.MoveTo(0, 0);
                    context.LineTo(r.Width, 0);
                    context.LineTo(r.Width - b + 1, b);
                    context.LineTo(b - 1, b);
                    context.ClosePath();
                    context.Fill();
                }

                // Left
                using  (Cairo.Gradient gradient = createGradient(0.0, 0.0, b, 0, c))
                {
                    context.SetSource(gradient);
                    context.MoveTo(0, 0);
                    context.LineTo(b, b - 1);
                    context.LineTo(b, r.Height - b + 1);
                    context.LineTo(0, r.Height);
                    context.ClosePath();
                    context.Fill();
                }

                // Bottom
                using (Cairo.Gradient gradient = createGradient(0.0, r.Height, 0, r.Height - b, c))
                {
                    context.SetSource(gradient);
                    context.MoveTo(0, r.Height);
                    context.LineTo(b - 1, r.Height - b);
                    context.LineTo(r.Width - b + 1, r.Height - b);
                    context.LineTo(r.Width, r.Height);
                    context.ClosePath();
                    context.Fill();
                }

                // Right
                using (Cairo.Gradient gradient = createGradient(r.Width, 0, r.Width - b, 0, c))
                {
                    context.SetSource(gradient);
                    context.MoveTo(r.Width, 0);
                    context.LineTo(r.Width - b, b - 1);
                    context.LineTo(r.Width - b, r.Height - b + 1);
                    context.LineTo(r.Width, r.Height);
                    context.ClosePath();
                    context.Fill();
                }
            }
        }