internal static Texture2D CreateText(string text, float size, Vector2 restrictBounds, Color color, bool shadow, bool bold, bool underline, Alignment alignment, bool forceAa, out Vector2 measured, Color background, Color border, int borderWidth, bool measureOnly) { if (text == null) { measured = Vector2.Zero; return(null); } SizeF measuredSize; StringFormat sf = new StringFormat(); FontStyle fs = FontStyle.Regular; if (bold) { fs |= FontStyle.Bold; } if (underline) { fs |= FontStyle.Underline; } Font f = new Font(General.FONT_FACE_DEFAULT, size, fs); switch (alignment) { case Alignment.Left: case Alignment.LeftFixed: sf.Alignment = StringAlignment.Near; break; case Alignment.Centre: sf.Alignment = StringAlignment.Center; break; case Alignment.Right: sf.Alignment = StringAlignment.Far; break; } System.Drawing.Graphics sGraphics = System.Drawing.Graphics.FromHwnd(IntPtr.Zero); if (alignment == Alignment.LeftFixed && restrictBounds.Y != 0) { measuredSize = new SizeF(restrictBounds.X, restrictBounds.Y); } else if (restrictBounds != Vector2.Zero) { measuredSize = sGraphics.MeasureString(text, f, new SizeF(restrictBounds.X, restrictBounds.Y), sf); } else { measuredSize = sGraphics.MeasureString(text, f); } int width = (int)(Alignment.Left == alignment ? measuredSize.Width + 1 : restrictBounds.X); int height = (int)measuredSize.Height + 1; if (restrictBounds.Y != 0) { height = (int)Math.Min(height, restrictBounds.Y); } int startSpace = 0; int endSpace = 0; if (alignment != Alignment.LeftFixed) { int i = 0; while (i < text.Length && text[i++] == ' ') { startSpace++; } int j = text.Length - 1; while (j >= i && text[j--] == ' ') { endSpace++; } if (startSpace == text.Length) { endSpace += startSpace; } } measured = new Vector2(width + ((endSpace) * 5.15f * size / 12), height); if (measureOnly) { return(null); } Bitmap b = new Bitmap(width, height, PixelFormat.Format32bppArgb); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(b); //Quality settings g.TextRenderingHint = forceAa ? TextRenderingHint.AntiAlias : TextRenderingHint.AntiAliasGridFit; g.SmoothingMode = SmoothingMode.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; Brush brush = new SolidBrush(GeneralHelper.CConvert(color)); if (background != Color.TransparentWhite) { g.Clear(GeneralHelper.CConvert(background)); } if (border != Color.TransparentWhite) { g.DrawRectangle(new Pen(GeneralHelper.CConvert(border), borderWidth), new Rectangle(0 + borderWidth / 2, 0 + borderWidth / 2, (int)(measured.X - borderWidth), (int)(measured.Y - borderWidth))); } if (restrictBounds != Vector2.Zero) { if (shadow) { g.DrawString(text, f, Brushes.Black, new RectangleF(1, 1, restrictBounds.X, restrictBounds.Y), sf); } g.DrawString(text, f, brush, new RectangleF(0, 0, restrictBounds.X, restrictBounds.Y), sf); } else { if (shadow) { g.DrawString(text, f, Brushes.Black, 1, 1); } g.DrawString(text, f, brush, 0, 0); } Texture2D tex = null; try { tex = new Texture2D(GameBase.graphics.GraphicsDevice, width, height, 1, ResourceUsage.None, SurfaceFormat.Color); } catch { } if (tex != null) { BitmapData data = b.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, b.PixelFormat); int length = data.Stride * b.Height; byte[] bitmap = new byte[length]; Marshal.Copy(data.Scan0, bitmap, 0, length); tex.SetData(bitmap); b.UnlockBits(data); b.Dispose(); return(tex); } return(null); }
internal SongSetup(bool restrict) { InitializeComponent(); DialogResult = DialogResult.Cancel; title.Text = BeatmapManager.Current.Title; artist.Text = BeatmapManager.Current.Artist; creator.Text = (BeatmapManager.Current.Creator.Length > 0 ? BeatmapManager.Current.Creator : ConfigManager.sUsername); source.Text = BeatmapManager.Current.Source; if (creator.Text == ConfigManager.sUsername) { creator.Enabled = false; } version.Text = BeatmapManager.Current.Version; hpDrainRate.Value = BeatmapManager.Current.DifficultyHpDrainRate; overallDifficulty.Value = BeatmapManager.Current.DifficultyOverall; circleSize.Value = BeatmapManager.Current.DifficultyCircleSize; sampleNormal.Checked = AudioEngine.CurrentSampleSet == SampleSet.Normal; sampleSoft.Checked = AudioEngine.CurrentSampleSet == SampleSet.Soft; sampleCustom.Checked = AudioEngine.CustomSamples; audioLeadIn.Value = BeatmapManager.Current.AudioLeadIn; stackLeniency.Value = (int)Math.Round(BeatmapManager.Current.StackLeniency * 10); taikoMod.Checked = BeatmapManager.Current.Mode == 1; volume1.Value = BeatmapManager.Current.SampleVolume; checkCountdown.Checked = BeatmapManager.Current.Countdown != Countdown.Disabled; countdownDouble.Checked = BeatmapManager.Current.Countdown == Countdown.DoubleSpeed; countdownHalf.Checked = BeatmapManager.Current.Countdown == Countdown.HalfSpeed; countdownNormal.Checked = BeatmapManager.Current.Countdown == Countdown.Normal; panelCountdownRate.Enabled = checkCountdown.Checked; if (AudioEngine.TimingPoints.Count > 0) { SampleSet def = AudioEngine.TimingPoints[0].sampleSet; bool cus = AudioEngine.TimingPoints[0].customSamples; int volume = AudioEngine.TimingPoints[0].volume; foreach (TimingPoint p in AudioEngine.TimingPoints) { if (p.sampleSet != def || p.customSamples != cus) { hideSampleSettings.Visible = true; resetSampleSettings = false; } if (p.volume != volume) { hideSampleVolume.Visible = true; resetVolumeSettings = false; } } } combo1.BackColor = GeneralHelper.CConvert(SkinManager.LoadColour("Combo1")); combo2.BackColor = GeneralHelper.CConvert(SkinManager.LoadColour("Combo2")); combo3.BackColor = GeneralHelper.CConvert(SkinManager.LoadColour("Combo3")); combo4.BackColor = GeneralHelper.CConvert(SkinManager.LoadColour("Combo4")); combo5.BackColor = GeneralHelper.CConvert(SkinManager.LoadColour("Combo5")); backgroundColour.BackColor = GeneralHelper.CConvert(EventManager.backgroundTexture.StartColour); comboEnable3 = combo3.BackColor.A != 0; comboEnable4 = combo4.BackColor.A != 0; comboEnable5 = combo5.BackColor.A != 0; customColour.Checked = BeatmapManager.Current.CustomColours; CalculateDifficulty(); if (restrict) { difficulty.Focus(); artist.Enabled = false; title.Enabled = false; } else { artist.Focus(); } }