コード例 #1
0
        public void DrawSample(Gdk.Drawable drawable, string text)
        {
            using (Cairo.Context ctx = Gdk.CairoHelper.Create(drawable))
            {
                using (Pango.Layout layout = Pango.CairoHelper.CreateLayout(ctx))
                {
                    AssignLayout(layout);
                    layout.SetText(text);

                    // dest size
                    int width, height;
                    drawable.GetSize(out width, out height);

                    // set pos
                    Pango.Rectangle te = Pango.Rectangle.Zero;
                    if (text.Length > 0)
                    {
                        Pango.Rectangle unused;
                        layout.GetPixelExtents(out unused, out te);
                        te.X = (width - te.Width) / 2;
                        te.Y = (height - te.Height) / 2;
                    }

                    // fill background
                    ctx.Save();
                    int         boxSize = 20, padding = 0;
                    Cairo.Color clr1 = Gui.CairoExtensions.RgbToColor(0xE77817);
                    Cairo.Color clr2 = Gui.CairoExtensions.RgbToColor(0x383431);
                    for (int i = 0; i < width; i++)
                    {
                        for (int j = 0; j < height; j++)
                        {
                            ctx.Rectangle(i * (boxSize + padding), j * (boxSize + padding), boxSize, boxSize);
                            if ((i + j) % 2 == 0)
                            {
                                ctx.SetSourceRGBA(clr1.R, clr1.G, clr1.B, clr1.A);
                            }
                            else
                            {
                                ctx.SetSourceRGBA(clr2.R, clr2.G, clr2.B, clr2.A);
                            }
                            ctx.Fill();
                        }
                    }
                    ctx.Restore();

                    // show text
                    if (text.Length > 0)
                    {
                        ctx.Save();
                        ctx.MoveTo(te.X, te.Y);
                        ctx.Color     = new Cairo.Color(1.0, 1.0, 1.0, 1.0);
                        ctx.Antialias = Cairo.Antialias.Gray;
                        ctx.Operator  = Cairo.Operator.Source;
                        Pango.CairoHelper.ShowLayout(ctx, layout);
                        ctx.Restore();
                    }
                }
            }
        }
コード例 #2
0
    void DrawTable(Gdk.Drawable drw)
    {
        Bitmap   bmp;
        Graphics g;
        int      width, height;

        drw.GetSize(out width, out height);
        bmp = new Bitmap(width, height);
        g   = Graphics.FromImage(bmp);

        g.FillRectangle(brBackground, new RectangleF(0, 0, width, height));

        DrawColumns(bmp);

        g.FillRectangle(brHouseColumn, rHouseTop);
        g.FillRectangle(brHouseColumn, rHouseBottom);
        g.FillRectangle(brOutColumn, rOutColumnTop);
        g.FillRectangle(brOutColumn, rOutColumnBottom);

        DrawPieces(bmp);
        DrawDice(bmp);

        g.Dispose();

        g = Gtk.DotNet.Graphics.FromDrawable(drw);
        g.DrawImage(bmp, 0, 0);

        g.Dispose();
    }
コード例 #3
0
        public static Surface CreateSurface(Gdk.Drawable d)
        {
            int width, height;

            d.GetSize(out width, out height);
            XlibSurface surface = new XlibSurface(GdkUtils.GetXDisplay(d.Display),
                                                  (IntPtr)GdkUtils.GetXid(d),
                                                  GdkUtils.GetXVisual(d.Visual),
                                                  width, height);

            return(surface);
        }
コード例 #4
0
        public void DrawLayout(Gdk.Drawable drawable, Gdk.GC gc, FontService fontService)
        {
            Gdk.Pixbuf pixbuf = BuildImage(fontService);

            int w = -1, h = -1;

            drawable.GetSize(out w, out h);

            pixbuf.RenderToDrawable(drawable, gc, 0, 0, 0, 0, w, h, Gdk.RgbDither.Normal, 0, 0);

            // manual dispose
            (pixbuf as IDisposable).Dispose();
        }
コード例 #5
0
        void DrawTable()
        {
            Gdk.Drawable drawable = GameDrawArea.GdkWindow;
            int          tableWidth, tableHeight, tileWidth, tileHeight;

            drawable.GetSize(out tableWidth, out tableHeight);
            tileWidth  = tableWidth / game.GameInfo.TableSize;
            tileHeight = tableHeight / game.GameInfo.TableSize;

            Font         font      = new Font("Sans", (int)(Math.Min(tileWidth, tileHeight) * 0.5), FontStyle.Regular);
            StringFormat strFormat = new StringFormat
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center
            };

            using (Graphics g = Gtk.DotNet.Graphics.FromDrawable(GameDrawArea.GdkWindow))
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.FillRectangle(Brushes.Black, 0, 0, tableWidth, tableHeight);

                for (int y = 0; y < game.GameInfo.TableSize; y++)
                {
                    for (int x = 0; x < game.GameInfo.TableSize; x++)
                    {
                        Tile tile = game.GetTile(x, y);

                        Rectangle desRectangle = new Rectangle(x * tileWidth, y * tileHeight, tileWidth, tileHeight);
                        Rectangle srcRectangle = new Rectangle(
                            (tile.Number - 1) % game.GameInfo.TableSize * tileWidth,
                            (tile.Number - 1) / game.GameInfo.TableSize * tileHeight,
                            desRectangle.Width, desRectangle.Height);

                        if (tile.Number != game.GameInfo.TilesCount)
                        {
                            g.DrawImage(image, desRectangle.X, desRectangle.Y, srcRectangle, GraphicsUnit.Pixel);
                            g.DrawString(tile.Number.ToString(), font, Brushes.IndianRed, desRectangle, strFormat);
                        }
                        else
                        {
                            g.FillRectangle(Brushes.Gray, desRectangle);
                        }

                        g.DrawRectangle(Pens.Black, desRectangle);
                    }
                }
            }
        }
コード例 #6
0
ファイル: GameWindow.cs プロジェクト: AndrewAran/minesweeper
        void DrawInfoBar()
        {
            Gdk.Drawable drawable     = daInfoBar.GdkWindow;
            Graphics     gfx          = Gtk.DotNet.Graphics.FromDrawable(drawable);
            Brush        brBackground = new SolidBrush(backgroundColor);
            Brush        brForeground = new SolidBrush(primaryColor);


            int width, height, widthThird;

            drawable.GetSize(out width, out height);
            widthThird = width / 3;

            Rectangle recWhole  = new Rectangle(0, 0, width, height);
            Rectangle recLeft   = new Rectangle(0, 0, widthThird, height);
            Rectangle recMiddle = new Rectangle(widthThird, 0, widthThird, height);
            Rectangle recRight  = new Rectangle(widthThird * 2, 0, widthThird, height);

            Font         f         = new Font("Sans", (int)(Math.Min(width, height) * 0.5), FontStyle.Regular);
            StringFormat strFormat = new StringFormat();

            strFormat.Alignment     = StringAlignment.Center;
            strFormat.LineAlignment = StringAlignment.Center;

            string face;

            gfx.FillRectangle(brBackground, recWhole);

            if (game.Alive)
            {
                face = ":)";
            }
            else
            {
                face = ":(";
            }

            gfx.DrawString(game.FlagsRemaining.ToString(), f, brForeground, recLeft, strFormat);
            gfx.DrawString(face, f, brForeground, recMiddle, strFormat);
            gfx.DrawString(string.Format("{0:00}:{1:00}", (game.GameTime / 60) % 60, game.GameTime % 60),
                           f, brForeground, recRight, strFormat);

            gfx.Dispose();
        }
コード例 #7
0
        public static void SetSourceDrawable(Context ctx, Gdk.Drawable d, double x, double y)
        {
            try {
                gdk_cairo_set_source_pixmap(ctx.Handle, d.Handle, x, y);
            } catch (EntryPointNotFoundException) {
                int width, height;
                d.GetSize(out width, out height);
                XlibSurface surface = new XlibSurface(GdkUtils.GetXDisplay(d.Display),
                                                      (IntPtr)GdkUtils.GetXid(d),
                                                      GdkUtils.GetXVisual(d.Visual),
                                                      width, height);

                SurfacePattern p = new SurfacePattern(surface);
                Matrix         m = new Matrix();
                m.Translate(-x, -y);
                p.Matrix   = m;
                ctx.Source = p;
            }
        }
コード例 #8
0
ファイル: GameWindow.cs プロジェクト: AndrewAran/minesweeper
        void DrawTable()
        {
            int x, y;
            int width, height;
            int tileSize;

            Gdk.Drawable drawable = daTable.GdkWindow;
            Graphics     gfx      = Gtk.DotNet.Graphics.FromDrawable(drawable);
            Rectangle    recTable;
            Brush        brBakcground  = new SolidBrush(backgroundColor);
            Brush        brActiveTile  = new SolidBrush(primaryColor);
            Brush        brClearedTile = new SolidBrush(secondaryColor);
            Font         font;
            StringFormat strFormat = new StringFormat();

            drawable.GetSize(out width, out height);
            tileSize = (width - game.TableSize * tileSpacing) / game.TableSize;
            recTable = new Rectangle(0, 0, width, height);

            font = new Font("Sans", (int)(tileSize * 0.5), FontStyle.Regular);
            strFormat.Alignment     = StringAlignment.Center;
            strFormat.LineAlignment = StringAlignment.Center;

            gfx.SmoothingMode = SmoothingMode.AntiAlias;

            gfx.FillRectangle(brBakcground, recTable);

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

                    Tile tile = game.GetTile(x, y);

                    if (tile.Cleared)
                    {
                        gfx.FillRectangle(brClearedTile, recTable);
                    }
                    else
                    {
                        gfx.FillRectangle(brActiveTile, recTable);
                    }

                    if (tile.Cleared && tile.DangerLevel > 0)
                    {
                        gfx.DrawString(
                            tile.DangerLevel.ToString(), font,
                            dangerBrushes[tile.DangerLevel], recTable, strFormat);
                    }

                    if (tile.Mined && !game.Alive)
                    {
                        gfx.DrawImage(bmpMine, recTable);
                    }

                    if (tile.Flagged)
                    {
                        gfx.DrawImage(bmpFlag, recTable);
                    }
                }
            }

            gfx.Dispose();
        }