2009-07-21 05:51:13 +00:00
|
|
|
|
|
|
|
|
|
#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 System.Windows.Forms.VisualStyles;
|
|
|
|
|
using System.Drawing.Imaging;
|
2009-07-21 13:42:36 +00:00
|
|
|
|
using System.Drawing.Text;
|
2009-07-21 05:51:13 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Controls
|
|
|
|
|
{
|
|
|
|
|
internal class DockersTabsControl : TabControl
|
|
|
|
|
{
|
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Variables
|
2009-08-21 08:37:02 +00:00
|
|
|
|
|
2009-07-21 05:51:13 +00:00
|
|
|
|
private Bitmap tabsimage;
|
2009-07-21 13:42:36 +00:00
|
|
|
|
private int highlighttab;
|
|
|
|
|
|
2009-07-21 05:51:13 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Constructor
|
|
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
|
public DockersTabsControl()
|
|
|
|
|
{
|
|
|
|
|
if(VisualStyleInformation.IsSupportedByOS && VisualStyleInformation.IsEnabledByUser)
|
|
|
|
|
{
|
2009-07-21 13:42:36 +00:00
|
|
|
|
// Style settings
|
2009-08-21 09:40:07 +00:00
|
|
|
|
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
2009-07-21 05:51:13 +00:00
|
|
|
|
this.SetStyle(ControlStyles.SupportsTransparentBackColor, false);
|
|
|
|
|
this.SetStyle(ControlStyles.UserPaint, true);
|
|
|
|
|
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
|
|
|
|
this.SetStyle(ControlStyles.Opaque, true);
|
|
|
|
|
this.UpdateStyles();
|
|
|
|
|
}
|
2009-07-21 13:42:36 +00:00
|
|
|
|
|
|
|
|
|
highlighttab = -1;
|
2009-07-21 05:51:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Disposer
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if(tabsimage != null)
|
|
|
|
|
{
|
|
|
|
|
tabsimage.Dispose();
|
|
|
|
|
tabsimage = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Methods
|
2009-07-21 13:42:36 +00:00
|
|
|
|
|
2009-07-21 05:51:13 +00:00
|
|
|
|
// This redraws the tabs
|
|
|
|
|
protected unsafe void RedrawTabs()
|
|
|
|
|
{
|
|
|
|
|
// Determine length and width in pixels
|
2009-07-21 13:42:36 +00:00
|
|
|
|
int tabslength = 0;
|
|
|
|
|
for(int i = 0; i < this.TabPages.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
Rectangle r = this.GetTabRect(i);
|
|
|
|
|
tabslength += r.Height;
|
|
|
|
|
}
|
|
|
|
|
tabslength += 4;
|
|
|
|
|
int tabswidth = this.ItemSize.Height + 2;
|
2009-07-21 05:51:13 +00:00
|
|
|
|
|
|
|
|
|
// Dispose old image
|
|
|
|
|
if(tabsimage != null)
|
|
|
|
|
{
|
|
|
|
|
tabsimage.Dispose();
|
|
|
|
|
tabsimage = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(VisualStyleInformation.IsSupportedByOS && VisualStyleInformation.IsEnabledByUser)
|
|
|
|
|
{
|
2009-07-21 13:42:36 +00:00
|
|
|
|
StringFormat drawformat = new StringFormat();
|
|
|
|
|
drawformat.Alignment = StringAlignment.Center;
|
|
|
|
|
drawformat.HotkeyPrefix = HotkeyPrefix.None;
|
|
|
|
|
drawformat.LineAlignment = StringAlignment.Center;
|
|
|
|
|
|
|
|
|
|
// Create images
|
|
|
|
|
tabsimage = new Bitmap(tabswidth, tabslength, PixelFormat.Format32bppArgb);
|
|
|
|
|
Bitmap drawimage = new Bitmap(tabslength, tabswidth, PixelFormat.Format32bppArgb);
|
|
|
|
|
Graphics g = Graphics.FromImage(drawimage);
|
|
|
|
|
|
|
|
|
|
// Render the tabs (backwards when right-aligned)
|
|
|
|
|
int posoffset = 0;
|
|
|
|
|
int selectedposoffset = -1;
|
|
|
|
|
int start = (this.Alignment == TabAlignment.Left) ? 0 : (this.TabPages.Count - 1);
|
|
|
|
|
int end = (this.Alignment == TabAlignment.Left) ? this.TabPages.Count : -1;
|
|
|
|
|
int step = (this.Alignment == TabAlignment.Left) ? 1 : -1;
|
|
|
|
|
for(int i = start; i != end; i += step)
|
2009-07-21 05:51:13 +00:00
|
|
|
|
{
|
2009-07-21 13:42:36 +00:00
|
|
|
|
VisualStyleRenderer renderer;
|
|
|
|
|
Rectangle tr = this.GetTabRect(i);
|
Visual mode, UDMF: added "Scale Texture Up (X)", "Scale Texture Down (X)", "Scale Texture Up (Y)", "Scale Texture Down (Y)" actions. Default keys are Num6, Num4, Num8, Num5.
Visual mode, UDMF: renamed "Rotate Thing Clockwise" and "Rotate Thing Counterclockwise" actions to "Rotate Clockwise" and "Rotate Counterclockwise". These actions can now be used to change rotation of floor/ceiling textures.
Visual mode, UDMF: "Reset Texture Offsets" action now also resets sidedef's scale and floor/ceiling's scale and rotation.
Visual mode, UDMF: control line's OffsetX and OffsetY were not taken into account when calculating texture offsets of 3d floors' sides.
Visual mode, UDMF: fixed a ton of bugs in Auto align functions.
Visual mode, UDMF: when using "Move Texture Left/Right/Up/Down by 1" actions texture offsets were not updated properly when texture's scale was < 1.0.
Visual mode, UDMF: OffsetX and OffsetY were not taken into account in "Fit Texture Width/Height" actions.
Dockers Panel: added Pin/Unpin button, which acts the same as "Preferences -> Interface -> Side panels -> Auto hide" checkbox.
Texture size labels can now be disabled by unchecking "Preferences -> Interface -> Show texture and flat sizes in browsers" checkbox.
Texture size labels now are not shown for unknown textures.
Most of texture size labels had incorrect bg color.
ZDoom_linedefs.cfg: action specials 223 and 224 had incorrect Arg0.
2013-06-24 14:21:13 +00:00
|
|
|
|
|
2009-07-21 13:42:36 +00:00
|
|
|
|
// Tab selected?
|
|
|
|
|
if(i == this.SelectedIndex)
|
|
|
|
|
{
|
|
|
|
|
// We will draw this later
|
|
|
|
|
selectedposoffset = posoffset;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(i == highlighttab)
|
|
|
|
|
renderer = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Hot);
|
|
|
|
|
else
|
|
|
|
|
renderer = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Normal);
|
|
|
|
|
|
|
|
|
|
// Draw tab
|
2015-01-09 08:11:42 +00:00
|
|
|
|
Rectangle r = new Rectangle(posoffset + 2, 2, tr.Height, tr.Width - 2);
|
2009-07-21 13:42:36 +00:00
|
|
|
|
renderer.DrawBackground(g, r);
|
|
|
|
|
g.DrawString(this.TabPages[i].Text, this.Font, SystemBrushes.ControlText, new RectangleF(r.Location, r.Size), drawformat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
posoffset += tr.Height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Render the selected tab, because it is slightly larger and overlapping the others
|
|
|
|
|
if(selectedposoffset > -1)
|
|
|
|
|
{
|
|
|
|
|
VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Pressed);
|
|
|
|
|
Rectangle tr = this.GetTabRect(this.SelectedIndex);
|
|
|
|
|
Rectangle r = new Rectangle(selectedposoffset, 0, tr.Height + 4, tr.Width);
|
|
|
|
|
renderer.DrawBackground(g, r);
|
|
|
|
|
g.DrawString(this.TabPages[this.SelectedIndex].Text, this.Font, SystemBrushes.ControlText, new RectangleF(r.X, r.Y, r.Width, r.Height - 2), drawformat);
|
2009-07-21 05:51:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Rotate the image and copy to tabsimage
|
|
|
|
|
BitmapData drawndata = drawimage.LockBits(new Rectangle(0, 0, drawimage.Size.Width, drawimage.Size.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
|
|
|
|
BitmapData targetdata = tabsimage.LockBits(new Rectangle(0, 0, tabsimage.Size.Width, tabsimage.Size.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
|
|
|
|
|
int* dd = (int*)drawndata.Scan0.ToPointer();
|
|
|
|
|
int* td = (int*)targetdata.Scan0.ToPointer();
|
2009-07-21 13:42:36 +00:00
|
|
|
|
if(this.Alignment == TabAlignment.Right)
|
2009-07-21 05:51:13 +00:00
|
|
|
|
{
|
2009-07-21 13:42:36 +00:00
|
|
|
|
for(int y = 0; y < drawndata.Height; y++)
|
2009-07-21 05:51:13 +00:00
|
|
|
|
{
|
2009-07-21 13:42:36 +00:00
|
|
|
|
for(int x = 0; x < drawndata.Width; x++)
|
|
|
|
|
{
|
|
|
|
|
td[(drawndata.Width - 1 - x) * targetdata.Width + y] = *dd;
|
|
|
|
|
dd++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for(int y = 0; y < drawndata.Height; y++)
|
|
|
|
|
{
|
|
|
|
|
for(int x = 0; x < drawndata.Width; x++)
|
|
|
|
|
{
|
|
|
|
|
td[x * targetdata.Width + (drawndata.Height - 1 - y)] = *dd;
|
|
|
|
|
dd++;
|
|
|
|
|
}
|
2009-07-21 05:51:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
drawimage.UnlockBits(drawndata);
|
|
|
|
|
tabsimage.UnlockBits(targetdata);
|
2009-07-21 13:42:36 +00:00
|
|
|
|
|
|
|
|
|
// Clean up
|
|
|
|
|
g.Dispose();
|
|
|
|
|
drawimage.Dispose();
|
2009-07-21 05:51:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-21 13:42:36 +00:00
|
|
|
|
|
2009-07-21 05:51:13 +00:00
|
|
|
|
#endregion
|
2009-07-21 13:42:36 +00:00
|
|
|
|
|
2009-07-21 05:51:13 +00:00
|
|
|
|
#region ================== Events
|
2009-07-21 13:42:36 +00:00
|
|
|
|
|
|
|
|
|
// Redrawing needed
|
2009-07-21 05:51:13 +00:00
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Point p;
|
|
|
|
|
|
|
|
|
|
if(VisualStyleInformation.IsSupportedByOS && VisualStyleInformation.IsEnabledByUser)
|
|
|
|
|
{
|
|
|
|
|
RedrawTabs();
|
2009-07-21 13:42:36 +00:00
|
|
|
|
|
|
|
|
|
e.Graphics.Clear(SystemColors.Control);
|
|
|
|
|
|
2009-07-21 05:51:13 +00:00
|
|
|
|
if(this.Alignment == TabAlignment.Left)
|
|
|
|
|
{
|
|
|
|
|
p = new Point(0, 0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int left = this.ClientSize.Width - tabsimage.Size.Width;
|
|
|
|
|
if(left < 0) left = 0;
|
|
|
|
|
p = new Point(left, 0);
|
|
|
|
|
}
|
2009-07-21 15:15:38 +00:00
|
|
|
|
|
2009-07-21 05:51:13 +00:00
|
|
|
|
e.Graphics.DrawImage(tabsimage, p);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
base.OnPaint(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-21 13:42:36 +00:00
|
|
|
|
// Mouse moves
|
|
|
|
|
protected override void OnMouseMove(MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(VisualStyleInformation.IsSupportedByOS && VisualStyleInformation.IsEnabledByUser)
|
|
|
|
|
{
|
|
|
|
|
int foundindex = -1;
|
|
|
|
|
Rectangle prect = new Rectangle(e.Location, Size.Empty);
|
|
|
|
|
|
|
|
|
|
// Check in which tab the mouse is
|
2009-07-21 18:48:00 +00:00
|
|
|
|
for(int i = this.TabPages.Count - 1; i >= 0; i--)
|
2009-07-21 13:42:36 +00:00
|
|
|
|
{
|
|
|
|
|
Rectangle tabrect = this.GetTabRect(i);
|
2009-07-21 18:48:00 +00:00
|
|
|
|
tabrect.Inflate(1, 1);
|
2009-07-21 13:42:36 +00:00
|
|
|
|
if(tabrect.IntersectsWith(prect))
|
|
|
|
|
{
|
|
|
|
|
foundindex = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Redraw?
|
|
|
|
|
if(foundindex != highlighttab)
|
|
|
|
|
{
|
|
|
|
|
highlighttab = foundindex;
|
|
|
|
|
this.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.OnMouseMove(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mouse leaves
|
|
|
|
|
protected override void OnMouseLeave(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(VisualStyleInformation.IsSupportedByOS && VisualStyleInformation.IsEnabledByUser)
|
|
|
|
|
{
|
|
|
|
|
// Redraw?
|
|
|
|
|
if(highlighttab != -1)
|
|
|
|
|
{
|
|
|
|
|
highlighttab = -1;
|
|
|
|
|
this.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.OnMouseLeave(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Tabs don't process keys
|
|
|
|
|
protected override void OnKeyDown(KeyEventArgs ke)
|
|
|
|
|
{
|
2009-08-21 08:37:02 +00:00
|
|
|
|
if(this.Parent is DockersControl)
|
|
|
|
|
{
|
|
|
|
|
// Only absorb the key press when no focused on an input control, otherwise
|
|
|
|
|
// the input controls may not receive certain keys such as delete and arrow keys
|
|
|
|
|
DockersControl docker = (this.Parent as DockersControl);
|
|
|
|
|
if(!docker.IsFocused)
|
|
|
|
|
ke.Handled = true;
|
|
|
|
|
}
|
2009-07-21 13:42:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Tabs don't process keys
|
|
|
|
|
protected override void OnKeyUp(KeyEventArgs e)
|
|
|
|
|
{
|
2009-08-21 08:37:02 +00:00
|
|
|
|
if(this.Parent is DockersControl)
|
|
|
|
|
{
|
|
|
|
|
// Only absorb the key press when no focused on an input control, otherwise
|
|
|
|
|
// the input controls may not receive certain keys such as delete and arrow keys
|
|
|
|
|
DockersControl docker = (this.Parent as DockersControl);
|
|
|
|
|
if(!docker.IsFocused)
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
2009-07-21 13:42:36 +00:00
|
|
|
|
}
|
2009-08-21 08:37:02 +00:00
|
|
|
|
|
2009-07-21 05:51:13 +00:00
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|