UltimateZoneBuilder/Source/Core/Controls/AngleControl.cs
MaxED 592887a086 Configurations: increased game configuration loading speed (in previous builds it took ~650 ms. to load a single game configuration, now it takes ~120 ms. to load all 64 of them). As a side effect, New\Open Map Options, Map Options and Game Configurations windows are now opened noticeably faster. The editor starts up a bit faster as well.
Configurations: all 64 game configuration are now available by default.
Game Configurations window: game configurations can now be disabled. This setting is mostly cosmetic. When a game configuration is disabled, it won't be shown in "game configuration" dropdowns in New\Open Map Options and Map Options windows. If a map's .dbs file specifies a disabled configuration, it will be picked as a map configuration anyway.
Linedefs mode: vertex insert preview logic used Highlight range instead of Stitch range (which is used when draw mode engages).
Visual mode: double-sided middle textures were not selected when using "Select" action with "with same texture" modifier.
Textures: some optimizations in patch blending code.
ZDoom ACS script configuration: added definitions for StrLeft, StrMid and StrRight functions.
2014-02-18 14:04:14 +00:00

173 lines
4.2 KiB
C#

#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Drawing;
using System.Windows.Forms;
using CodeImp.DoomBuilder.Geometry;
using System.Drawing.Drawing2D;
#endregion
namespace CodeImp.DoomBuilder.Controls
{
/// <summary>
/// Control which allows you to click on one of the buttons to select a rotation by 45 degrees.
/// </summary>
public partial class AngleControl : UserControl
{
#region ================== Constants
private const float LINE_THICKNESS = 3f;
#endregion
#region ================== Events
public event EventHandler ValueChanged;
public event EventHandler ButtonClicked;
#endregion
#region ================== Variables
// Buttons
private RadioButton[] buttons;
// Result
private int angle;
private bool settingangle;
#endregion
#region ================== Properties
public int Value { get { return angle; } set { SetAngle(value, true); } }
#endregion
#region ================== Constructor / Disposer
// Constructor
public AngleControl()
{
// Initialize
InitializeComponent();
// Make array from buttons
buttons = new RadioButton[8];
buttons[0] = button0;
buttons[1] = button1;
buttons[2] = button2;
buttons[3] = button3;
buttons[4] = button4;
buttons[5] = button5;
buttons[6] = button6;
buttons[7] = button7;
}
#endregion
#region ================== Interface
// Size changed
protected override void OnClientSizeChanged(EventArgs e)
{
base.OnClientSizeChanged(e);
AngleControl_Resize(this, e);
}
// Layout changed
private void AngleControl_Layout(object sender, LayoutEventArgs e)
{
AngleControl_Resize(sender, e);
}
// Size changed
private void AngleControl_Resize(object sender, EventArgs e)
{
//this.Size = new Size(84, 84);
}
// Redraw the control
private void AngleControl_Paint(object sender, PaintEventArgs e)
{
float rad = Angle2D.DegToRad(angle);
e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
e.Graphics.InterpolationMode = InterpolationMode.High;
e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
e.Graphics.Clear(this.BackColor);
Pen linepen = new Pen(SystemColors.ControlText, LINE_THICKNESS);
PointF start = new PointF(this.Size.Width * 0.5f, this.Size.Height * 0.5f);
float line_length = this.Size.Width * 0.26f;
if((rad >= 0) && (rad < 360))
{
PointF end = new PointF(start.X + (float)Math.Sin(rad + Angle2D.PIHALF) * line_length,
start.Y + (float)Math.Cos(rad + Angle2D.PIHALF) * line_length);
e.Graphics.DrawLine(linepen, start, end);
}
else
{
e.Graphics.DrawLine(linepen, start, start);
}
}
#endregion
#region ================== Control
// This sets an angle manually
private void SetAngle(int newangle, bool changebuttons)
{
// Normalize and apply angle
bool changed = (newangle != angle);
angle = newangle;
// Check if it matches an angle from the buttons
if(changebuttons)
{
settingangle = true;
for(int i = 0; i < 8; i++)
buttons[i].Checked = (angle == i * 45);
settingangle = false;
}
// Redraw
this.Invalidate();
// Raise event
if((ValueChanged != null) && changed) ValueChanged(this, EventArgs.Empty);
}
// When checked state of a button changes
private void button_CheckedChanged(object sender, EventArgs e)
{
if(!settingangle)
{
// Check if we can get the angle from one of the buttons
for(int i = 0; i < 8; i++)
if(buttons[i].Checked) SetAngle(i * 45, false);
// Raise event
if(ButtonClicked != null) ButtonClicked(this, EventArgs.Empty);
}
}
#endregion
}
}