Can now resize dock regions

This commit is contained in:
Robin 2015-09-19 14:39:06 +01:00
parent d266fbea86
commit 12f227f542
7 changed files with 112 additions and 27 deletions

View File

@ -108,6 +108,7 @@
</Compile>
<Compile Include="Docking\Items\DarkDockSplitter.cs" />
<Compile Include="Extensions\BitmapExtensions.cs" />
<Compile Include="Extensions\IEnumerableExtensions.cs" />
<Compile Include="Forms\DarkDialog.cs">
<SubType>Form</SubType>
</Compile>

View File

@ -86,7 +86,6 @@ namespace DarkUI
var newGroup = new DarkDockGroup(DockPanel, this);
_groups.Add(newGroup);
Controls.Add(newGroup);
newGroup.BringToFront();
PositionGroups();
@ -121,10 +120,21 @@ namespace DarkUI
}
if (_groups.Count == 1)
{
_groups[0].Dock = DockStyle.Fill;
}
else if (_groups.Count > 1)
{
foreach (var group in _groups)
group.Dock = dockStyle;
{
group.SendToBack();
if (_groups.IsLast(group))
group.Dock = dockStyle;
else
group.Dock = DockStyle.Fill;
}
}
}
private void BuildProperties()

View File

@ -44,6 +44,25 @@ namespace DarkUI
#region Method Region
public void Move(Point difference)
{
switch (_splitterType)
{
case DarkSplitterType.Left:
_control.Width += difference.X;
break;
case DarkSplitterType.Right:
_control.Width -= difference.X;
break;
case DarkSplitterType.Top:
_control.Height += difference.Y;
break;
case DarkSplitterType.Bottom:
_control.Height -= difference.Y;
break;
}
}
public void UpdateBounds()
{
switch (_splitterType)

View File

@ -2,9 +2,9 @@
namespace DarkUI
{
public static class BitmapExtensions
internal static class BitmapExtensions
{
public static Bitmap SetColor(this Bitmap bitmap, Color color)
internal static Bitmap SetColor(this Bitmap bitmap, Color color)
{
var newBitmap = new Bitmap(bitmap.Width, bitmap.Height);
for (int i = 0; i < bitmap.Width; i++)
@ -19,7 +19,7 @@ namespace DarkUI
return newBitmap;
}
public static Bitmap ChangeColor(this Bitmap bitmap, Color oldColor, Color newColor)
internal static Bitmap ChangeColor(this Bitmap bitmap, Color oldColor, Color newColor)
{
var newBitmap = new Bitmap(bitmap.Width, bitmap.Height);
for (int i = 0; i < bitmap.Width; i++)

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DarkUI
{
internal static class IEnumerableExtensions
{
internal static bool IsLast<T>(this IEnumerable<T> items, T item)
{
var last = items.LastOrDefault();
if (last == null)
return false;
return item.Equals(last); // OR Object.ReferenceEquals(last, item)
}
internal static bool IsFirst<T>(this IEnumerable<T> items, T item)
{
var first = items.FirstOrDefault();
if (first == null)
return false;
return item.Equals(first);
}
internal static bool IsFirstOrLast<T>(this IEnumerable<T> items, T item)
{
return items.IsFirst(item) || items.IsLast(item);
}
}
}

View File

@ -1,4 +1,5 @@
using System.Drawing;
using System;
using System.Drawing;
using System.Windows.Forms;
namespace DarkUI
@ -10,6 +11,7 @@ namespace DarkUI
private DarkDockPanel _dockPanel;
private bool _isDragging;
private Point _initialContact;
private DarkDockSplitter _activeSplitter;
#endregion
@ -33,16 +35,13 @@ namespace DarkUI
m.Msg == (int)WM.RBUTTONDOWN || m.Msg == (int)WM.RBUTTONUP || m.Msg == (int)WM.RBUTTONDBLCLK))
return false;
// Exit out early if we're simply releasing a drag over the area
// Exit out early if we're simply releasing a non-splitter drag over the area
if (m.Msg == (int)WM.LBUTTONUP && !_isDragging)
return false;
// Force cursor if already dragging.
ForceDraggingCursor();
// Stop all events from going through if we're dragging a splitter.
if (_isDragging)
return true;
Cursor.Current = _activeSplitter.ResizeCursor;
// Return out early if we're dragging something that's not a splitter.
if (m.Msg == (int)WM.MOUSEMOVE && !_isDragging && _dockPanel.MouseButtonState != MouseButtons.None)
@ -65,17 +64,26 @@ namespace DarkUI
// Start drag.
if (m.Msg == (int)WM.LBUTTONDOWN)
{
foreach (var splitter in _dockPanel.Splitters)
{
if (splitter.Bounds.Contains(_dockPanel.PointToClient(Cursor.Position)))
{
StartDrag(splitter);
return true;
}
}
}
// Stop drag.
if (m.Msg == (int)WM.LBUTTONUP)
{
if (_isDragging)
{
StopDrag();
return true;
}
}
// Stop events passing through if we just started to drag something
if (_isDragging)
return true;
// Stop events passing through if we're hovering over a splitter
foreach (var splitter in _dockPanel.Splitters)
{
@ -83,6 +91,10 @@ namespace DarkUI
return true;
}
// Stop all events from going through if we're dragging a splitter.
if (_isDragging)
return true;
return false;
}
@ -90,19 +102,25 @@ namespace DarkUI
#region Method Region
private void ForceDraggingCursor()
private void StartDrag(DarkDockSplitter splitter)
{
if (_isDragging)
{
SetCursor(_activeSplitter.ResizeCursor);
return;
}
Console.WriteLine("Start drag");
_activeSplitter = splitter;
Cursor.Current = _activeSplitter.ResizeCursor;
_initialContact = Cursor.Position;
_isDragging = true;
}
private void ResetCursor()
private void StopDrag()
{
Cursor.Current = Cursors.Default;
CheckCursor();
Console.WriteLine("Stop drag");
var difference = new Point(_initialContact.X - Cursor.Position.X, _initialContact.Y - Cursor.Position.Y);
_activeSplitter.Move(difference);
_isDragging = false;
}
private void CheckCursor()
@ -114,15 +132,16 @@ namespace DarkUI
{
if (splitter.Bounds.Contains(_dockPanel.PointToClient(Cursor.Position)))
{
SetCursor(splitter.ResizeCursor);
Cursor.Current = splitter.ResizeCursor;
return;
}
}
}
private void SetCursor(Cursor cursor)
private void ResetCursor()
{
Cursor.Current = cursor;
Cursor.Current = Cursors.Default;
CheckCursor();
}
#endregion

View File

@ -43,6 +43,11 @@ namespace Example
DockPanel.AddContent(_dockLayers);
DockPanel.AddContent(_dockHistory);
// Add 3 dummy documents to the main document area of the dock panel
DockPanel.AddContent(new DockDocument { DockText = "Document 1" });
DockPanel.AddContent(new DockDocument { DockText = "Document 2" });
DockPanel.AddContent(new DockDocument { DockText = "Document 3" });
// Show the tool windows as visible in the 'Window' menu
mnuProject.Checked = true;
mnuProperties.Checked = true;