コード例 #1
0
        protected override void OnDrawBackground(GuiGraphics graphics)
        {
            base.OnDrawBackground(graphics);

            int borderWidth = 10;

            int startIndex = 0;
            int endIndex   = items.Count - 1;

            int localI = 0;

            int itemHeight = 40;

            //Draw selection rectangle
            if (selectedIndex != -1)
            {
                Viewport oldViewport = graphics.Device.Viewport;

                Viewport newViewport = oldViewport;

                newViewport.X     += borderWidth;
                newViewport.Y     += borderWidth + selectedIndex * itemHeight;
                newViewport.Height = itemHeight;
                newViewport.Width  = (int)Size.X - borderWidth - borderWidth;

                graphics.Device.Viewport = newViewport;

                graphics.Device.Clear(Color.LightBlue);


                graphics.Device.Viewport = oldViewport;
            }


            for (int i = startIndex; i <= endIndex; i++)
            {
                graphics.DrawText(font, items[i].Text, textColor, new Microsoft.Xna.Framework.Rectangle(
                                      borderWidth, borderWidth + itemHeight * localI, (int)Size.X - borderWidth - borderWidth, itemHeight), textAlign);

                localI++;
            }
        }
コード例 #2
0
        protected override void OnDrawBackground(GuiGraphics graphics)
        {
            base.OnDrawBackground(graphics);

            Rectangle bounding = GetBounding();

            int width  = (int)Size.X;
            int height = (int)Size.Y;


            TileSet target = new TileSet(0, 0,
                                         new int[] { tileSet.ColumnWidths[0] >> 1, width - (tileSet.ColumnWidths[0] >> 1) - (tileSet.ColumnWidths[2] >> 1), tileSet.ColumnWidths[2] >> 1 },
                                         new int[] { tileSet.RowHeights[0] >> 1, height - (tileSet.RowHeights[0] >> 1) - (tileSet.RowHeights[2] >> 1), tileSet.RowHeights[2] >> 1 }
                                         );



            for (int x = 0; x < 3; x++)
            {
                for (int y = 0; y < 3; y++)
                {
                    Rectangle source = tileSet.GetTileRectangle(x, y);
                    Rectangle dest   = target.GetTileRectangle(x, y);

                    if (x == 1 || y == 1)
                    {
                        Vector2 minSize = new Vector2(source.Width, source.Height) * 0.5f;

                        graphics.Draw(texture, source, dest, new Vector2(0.5f));
                    }
                    else
                    {
                        graphics.Draw(texture, source, dest, GuiAlign.None);
                    }
                }
            }

            graphics.DrawText(font, text, textColor,
                              new Rectangle(textBorderSize, textBorderSize,
                                            bounding.Width - textBorderSize * 2, bounding.Height - textBorderSize * 2), textAlign);
        }