Example #1
0
        void Layout()
        {
            // Choose a smaller font if it doesn't fit
            foreach (var label in new[] { phraseLabel, translationLabel })
            {
                if (label.Font == bigFont && label.Width > GameArea.Width)
                {
                    label.Font = smallFont;
                }
                else if (label.Font == smallFont)
                {
                    using (Graphics g = GameArea.CreateGraphics()) {
                        if (g.MeasureString(label.Text, bigFont).Width < GameArea.Width)
                        {
                            label.Font = bigFont;
                        }
                    }
                }
            }

            var height = phraseLabel.Height + translationLabel.Height;

            var px = (GameArea.Width - phraseLabel.Width) / 2;
            var tx = (GameArea.Width - translationLabel.Width) / 2;

            var py = (GameArea.Height - height) / 2;
            var ty = py + phraseLabel.Height;

            phraseLabel.Location      = new System.Drawing.Point(px, py);
            translationLabel.Location = new System.Drawing.Point(tx, ty);
        }
 public LevelEditor()
 {
     InitializeComponent();
     tpi   = new Bitmap(TilePanel.Width, TilePanel.Height);
     bmp   = new Bitmap(TilePanel.Width, TilePanel.Height);
     area  = new Bitmap(GameArea.Width, GameArea.Height);
     br    = new SolidBrush(GameArea.BackColor);
     tv    = new sbyte[Map.MW + 8, Map.MH + 8];
     paths = new sbyte[Config.MPC, Config.MPL];
     for (int i = 0; i < Config.MPC; i++)
     {
         for (int j = 0; j < Config.MPL; j++)
         {
             paths[i, j] = -1;
         }
     }
     map              = new sbyte[Config.MLMAX];
     sf               = new StringFormat();
     sf.Alignment     = StringAlignment.Center;
     sf.LineAlignment = StringAlignment.Center;
     MD               = false;
     obj              = new Object();
     pea              = new PaintEventArgs(TilePanel.CreateGraphics(), TilePanel.ClientRectangle);
     gpea             = new PaintEventArgs(GameArea.CreateGraphics(), GameArea.ClientRectangle);
     hb               = new HatchBrush(HatchStyle.LargeConfetti, Color.DimGray, Color.Black);
     hb2              = new HatchBrush(HatchStyle.SmallConfetti, Color.DarkRed, Color.Black);
     ti               = 0; pap = 0; pc = 0;
     WaveFile         = String.Empty;
 }
Example #3
0
        // TODO: Make the font smaller when the form is small?
        void SizeToWidth(TextBoxBase textBox)
        {
            if (!(textBox.Visible || (bool?)textBox.Tag == true))
            {
                return;
            }

            using (Graphics g = GameArea.CreateGraphics()) {
                float min    = g.MeasureString("abcdefghi", font).Width;
                float max    = g.MeasureString("abcdefghijklmoqrstuvwxyz", font).Width;
                float actual = g.MeasureString(textBox.Text + "m", font).Width;

                bool fits = true;
                if (actual < min)
                {
                    actual = min;
                }
                else if (actual >= max)
                {
                    actual = max;
                    fits   = false;
                }

                // Room for the caret
                actual += g.MeasureString("mm", font).Width;

                int availableWidth = GameArea.ClientSize.Width - textBox.Margin.Horizontal;
                if (actual > availableWidth)
                {
                    actual = availableWidth;
                }

                textBox.Width = (int)actual;

                if (fits)
                {
                    // Make sure the text is positioned correctly in the textbox.
                    int ss = textBox.SelectionStart, sl = textBox.SelectionLength;
                    textBox.SelectionStart  = 0;
                    textBox.SelectionStart  = ss;
                    textBox.SelectionLength = sl;
                }
            }
        }