UltimateZoneBuilder/Source/Core/Controls/CheckboxArrayControl.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

145 lines
3.8 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.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
#endregion
namespace CodeImp.DoomBuilder.Controls
{
public partial class CheckboxArrayControl : UserControl
{
// Events
public event EventHandler OnValueChanged; //mxd
// Variables
private List<CheckBox> checkboxes;
private int columns;
private int spacingY = 1; //mxd
// Properties
public List<CheckBox> Checkboxes { get { return checkboxes; } }
public int Columns { get { return columns; } set { columns = value; } }
public int VerticalSpacing { get { return spacingY; } set { spacingY = value; } } //mxd
// Constructor
public CheckboxArrayControl()
{
// Initialize
InitializeComponent();
// Setup
checkboxes = new List<CheckBox>();
}
// This adds a checkbox
public CheckBox Add(string text, object tag)
{
// Make new checkbox
CheckBox c = new CheckBox();
c.AutoSize = true;
//c.FlatStyle = FlatStyle.System;
c.UseVisualStyleBackColor = true;
c.Text = text;
c.Tag = tag;
c.CheckedChanged += checkbox_CheckedChanged; //mxd
// Add to list
this.Controls.Add(c);
checkboxes.Add(c);
// Return checkbox
return c;
}
//mxd
public int GetHeight() {
if(columns < 1) return 0;
if(checkboxes.Count < 1) return 0;
int col = (int)Math.Ceiling(checkboxes.Count / (float)columns);
return col * checkboxes[0].Height + (col * spacingY + spacingY);
}
// This positions the checkboxes
public void PositionCheckboxes()
{
int boxheight = 0;
int row = 0;
int col = 0;
// Checks
if(columns < 1) return;
if(checkboxes.Count < 1) return;
// Calculate column width
int columnwidth = this.ClientSize.Width / columns;
// Check what the biggest checkbox height is
foreach(CheckBox c in checkboxes) if(c.Height > boxheight) boxheight = c.Height;
// Check what the preferred column length is
int columnlength = 1 + (int)Math.Floor((this.ClientSize.Height - boxheight) / (float)(boxheight + spacingY));
// When not all items fit with the preferred column length
// we have to extend the column length to make it fit
if((int)Math.Ceiling(checkboxes.Count / (float)columnlength) > columns)
{
// Make a column length which works for all items
columnlength = (int)Math.Ceiling(checkboxes.Count / (float)columns);
}
// Go for all items
foreach(CheckBox c in checkboxes)
{
// Position checkbox
c.Location = new Point(col * columnwidth, row * boxheight + (row - 1) * spacingY + spacingY);
// Next position
if(++row == columnlength)
{
row = 0;
col++;
}
}
}
// When layout must change
private void CheckboxArrayControl_Layout(object sender, LayoutEventArgs e)
{
PositionCheckboxes();
}
private void CheckboxArrayControl_Paint(object sender, PaintEventArgs e)
{
if(this.DesignMode)
{
Pen p = new Pen(SystemColors.ControlDark, 1) {DashStyle = DashStyle.Dash};
e.Graphics.DrawRectangle(p, 0, 0, this.ClientRectangle.Width - 1, this.ClientRectangle.Height - 1);
}
}
//mxd
private void checkbox_CheckedChanged(object sender, EventArgs e) {
if(OnValueChanged != null) OnValueChanged(this, EventArgs.Empty);
}
}
}