コード例 #1
0
ファイル: MainMenu.cs プロジェクト: Czeslav/Costam
 private void AddButton(int ID, string text)
 {
     //calculate position for new button
     int height = 50;
     int width = (int)(rectangle.Width * 0.8f);
     int topSpacing = 20;
     int sideSpacing = (int)(0.1f * rectangle.Width);
     int y = ID * height + ID * topSpacing + rectangle.Y + 30;
     int x = rectangle.X + sideSpacing;
     //create new rectangle with freschly calculated parameters
     Rectangle rec = new Rectangle(x,y,width,height);
     //create button and add it to array of buttons
     buttons[ID] = new Button(ID, rec, text);
 }
コード例 #2
0
ファイル: MessageBox.cs プロジェクト: Czeslav/Costam
        private void Construct()
        {
            screen = new Rectangle(0, 0, viewport.Width, viewport.Height);

            //calculate message box position and size
            int height = 0;
            int width = 400;
            foreach (var item in lines)
            {
                if (item == null)
                {
                    break;
                }

                height += (int)SpriteBank.font.MeasureString(item).Y;
                height += 10;

            }
            height += 100;
            rectangle.Height = height;

            int x = screen.Center.X - width / 2;
            int y = screen.Center.Y - height / 2;

            rectangle = new Rectangle(x, y, width, height);
            //calculate center position (dunno why)
            center.X = rectangle.Center.X;
            center.Y = rectangle.Center.Y;

            //create OK button
            width = 100;
            height = 40;
            Rectangle buttonRec = new Rectangle(rectangle.X + rectangle.Width / 2 - width / 2, rectangle.Bottom - height - 20, width, height);
            exitButton = new Button(1, buttonRec, "OK");
        }