You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

256 lines
7.3 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GeoSigmaViewer
{
public partial class DrawTextDialog : Form
{
private Drawer drawer;
private TextInformation textInfo;
private Color textColor;
private double ratio; //横纵比例
private bool lockRatio;
public DrawTextDialog(ref Drawer drawer)
{
InitializeComponent();
textInfo = new TextInformation();
this.drawer = drawer;
textColor = Color.FromArgb(0, 0, 0);
ratio = 0.4;
lockRatio = true;
if (fillTextInfo(ref textInfo))
{
drawer.Geo.Text_SetTextInfo(ref textInfo);
}
}
private void heightTextBox_TextChanged(object sender, EventArgs e)
{
if (lockRatio)
{
double height = 0;
double width = 0;
try
{
height = double.Parse(heightTextBox.Text);
}
catch (SystemException)
{
return;
}
width = height * ratio;
widthTextBox.Text = width.ToString();
}
if (fillTextInfo(ref textInfo))
{
drawer.Geo.Text_SetTextInfo(ref textInfo);
drawer.Geo.EnableRedraw(true);
drawer.ReDraw();
}
}
private bool fillTextInfo(ref TextInformation info)
{
info.text = this.textBox.Text;
info.textHeight = 1000;
info.textWidth = 400;
info.r = textColor.R;
info.g = textColor.G;
info.b = textColor.B;
try
{
info.textHeight = double.Parse(this.heightTextBox.Text);
info.textWidth = double.Parse(this.widthTextBox.Text);
info.angle = double.Parse(this.angleTextBox.Text);
}
catch (ArgumentNullException)
{
MessageBox.Show("输入信息有误,请重新输入。", "出错信息");
return false;
}
catch (FormatException)
{
MessageBox.Show("输入信息有误,请重新输入。", "出错信息");
return false;
}
catch (OverflowException)
{
MessageBox.Show("输入信息有误,请重新输入。", "出错信息");
return false;
}
if (this.upDownCheckBox.CheckState == CheckState.Checked)
info.bUpDown = 1;
else
info.bUpDown = 0;
return true;
}
private void textBox_TextChanged(object sender, EventArgs e)
{
if (fillTextInfo(ref textInfo))
{
drawer.Geo.Text_SetTextInfo(ref textInfo);
drawer.Geo.EnableRedraw(true);
drawer.ReDraw();
}
}
private void angleTextBox_TextChanged(object sender, EventArgs e)
{
if (fillTextInfo(ref textInfo))
{
drawer.Geo.Text_SetTextInfo(ref textInfo);
drawer.Geo.EnableRedraw(true);
drawer.ReDraw();
}
}
private void widthTextBox_TextChanged(object sender, EventArgs e)
{
if (lockRatio)
{
double height = 0;
double width = 0;
try
{
width = double.Parse(widthTextBox.Text);
}
catch (SystemException)
{
return;
}
height = width / ratio;
heightTextBox.Text = height.ToString();
}
if (fillTextInfo(ref textInfo))
{
drawer.Geo.Text_SetTextInfo(ref textInfo);
drawer.Geo.EnableRedraw(true);
drawer.ReDraw();
}
}
private void fontButton_Click(object sender, EventArgs e)
{
DialogResult result = fontDialog.ShowDialog();
if (result != DialogResult.OK)
return;
Font font = fontDialog.Font;
SigmaDrawerStyle.LogFont logFont = SigmaDrawerStyle.LogFontConverter.convert(font);
drawer.Geo.Text_SetFont(ref logFont);
drawer.Geo.EnableRedraw(true);
drawer.ReDraw();
}
private void colorButton_Click(object sender, EventArgs e)
{
DialogResult result = colorDialog.ShowDialog();
if (result != DialogResult.OK)
return;
textColor = colorDialog.Color;
if (fillTextInfo(ref textInfo))
{
drawer.Geo.Text_SetTextInfo(ref textInfo);
drawer.Geo.EnableRedraw(true);
drawer.ReDraw();
}
}
private void upDownCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (fillTextInfo(ref textInfo))
{
drawer.Geo.Text_SetTextInfo(ref textInfo);
drawer.Geo.EnableRedraw(true);
drawer.ReDraw();
}
}
private void upDownButton_Click(object sender, EventArgs e)
{
SuperSubScriptDialog dlg = new SuperSubScriptDialog();
DialogResult result = dlg.ShowDialog();
if (result != DialogResult.OK)
return;
if (dlg.ScriptText.Length == 0)
return;
this.textBox.Text += dlg.ScriptText;
if (fillTextInfo(ref textInfo))
{
drawer.Geo.Text_SetTextInfo(ref textInfo);
drawer.Geo.EnableRedraw(true);
drawer.ReDraw();
}
}
private void OKButton_Click(object sender, EventArgs e)
{
if (fillTextInfo(ref textInfo))
{
drawer.Geo.Text_SetTextInfo(ref textInfo);
drawer.Geo.Text_Create();
drawer.Geo.EnableRedraw(true);
drawer.ReDraw();
}
drawer.ActiveTool = DrawToolType.Select;
Close();
}
private void cancelButton_Click(object sender, EventArgs e)
{
drawer.ActiveTool = DrawToolType.Select;
Close();
}
private void ratioCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (CheckState.Checked == ratioCheckBox.CheckState)
{
lockRatio = true;
double height = 0;
double width = 0;
try
{
height = double.Parse(heightTextBox.Text);
width = double.Parse(widthTextBox.Text);
}
catch (SystemException)
{
return;
}
if (Math.Abs(height) > 1e-30 && Math.Abs(height) > 1e-30)
ratio = width / height;
}
else
lockRatio = false;
}
}
}