private void bgPanel_Paint(object sender, PaintEventArgs e)
{
if (_gui != null)
{
IntPtr hdc = e.Graphics.GetHdc();
//Factory.NativeProxy.DrawGUI(hdc, 0, 0, _gui, Factory.AGSEditor.CurrentGame.GUIScaleFactor, (_selectedControl == null) ? -1 : _selectedControl.ID);
Factory.NativeProxy.DrawGUI(hdc, 0, 0, _gui, Factory.AGSEditor.CurrentGame.GUIScaleFactor, -1);
e.Graphics.ReleaseHdc(hdc);
if (_addingControl)
{
DrawSelectionRectangle(e.Graphics);
}
if (_drawingSelectionBox)
{
Rectangle _rectToDraw = new Rectangle(_selectionRect.X * Factory.AGSEditor.CurrentGame.GUIScaleFactor,
_selectionRect.Y * Factory.AGSEditor.CurrentGame.GUIScaleFactor,
_selectionRect.Width * Factory.AGSEditor.CurrentGame.GUIScaleFactor,
_selectionRect.Height * Factory.AGSEditor.CurrentGame.GUIScaleFactor);
e.Graphics.DrawRectangle(_drawRectanglePen, _rectToDraw);
}
//draw selection handles
if (_selected.Count > 0)
{
foreach (GUIControl _gc in _selected)
{
Rectangle _topleft = new Rectangle(_gc.Left * Factory.AGSEditor.CurrentGame.GUIScaleFactor, _gc.Top * Factory.AGSEditor.CurrentGame.GUIScaleFactor, 2, 2);
Rectangle _topright = new Rectangle((_gc.Left + _gc.Width - 1) * Factory.AGSEditor.CurrentGame.GUIScaleFactor, _gc.Top * Factory.AGSEditor.CurrentGame.GUIScaleFactor, 2, 2);
Rectangle _bottomleft = new Rectangle(_gc.Left * Factory.AGSEditor.CurrentGame.GUIScaleFactor, (_gc.Top + _gc.Height - 1) * Factory.AGSEditor.CurrentGame.GUIScaleFactor, 2, 2);
Rectangle _bottomright = new Rectangle((_gc.Left + _gc.Width - 1) * Factory.AGSEditor.CurrentGame.GUIScaleFactor, (_gc.Top + _gc.Height - 1) * Factory.AGSEditor.CurrentGame.GUIScaleFactor, 2, 2);
Pen _pen;
if (_gc == _selectedControl) _pen = _drawSelectedPen;
else _pen = _drawRectanglePen;
e.Graphics.DrawRectangle(_pen, _topleft);
e.Graphics.DrawRectangle(_pen, _topright);
e.Graphics.DrawRectangle(_pen, _bottomleft);
e.Graphics.DrawRectangle(_pen, _bottomright);
//draw cross if locked
if (_gc.Locked)
{
Point center = new Point(_gc.Left + (_gc.Width / 2), _gc.Top + (_gc.Height / 2));
center.X *= Factory.AGSEditor.CurrentGame.GUIScaleFactor;
center.Y *= Factory.AGSEditor.CurrentGame.GUIScaleFactor;
e.Graphics.DrawLine(_pen, center.X - 3, center.Y - 3, center.X + 3, center.Y + 3);
e.Graphics.DrawLine(_pen, center.X - 3, center.Y + 3, center.X + 3, center.Y - 3);
}
}
}
if (_snappedx != -1)
{
NormalGUI g = (NormalGUI)_gui;
e.Graphics.DrawLine(_drawSnapPen, _snappedx * Factory.AGSEditor.CurrentGame.GUIScaleFactor, 0, _snappedx * Factory.AGSEditor.CurrentGame.GUIScaleFactor, g.Height * Factory.AGSEditor.CurrentGame.GUIScaleFactor);
string snapxstring = String.Format("{0}px", _snappedx);
e.Graphics.DrawString(snapxstring,
DefaultFont,
_drawSnapPen.Brush,
_snappedx * Factory.AGSEditor.CurrentGame.GUIScaleFactor - e.Graphics.MeasureString(snapxstring, DefaultFont).Width,
_selectedControl.Top * Factory.AGSEditor.CurrentGame.GUIScaleFactor
);
}
if (_snappedy != -1)
{
NormalGUI g = (NormalGUI)_gui;
string snapystring = String.Format("{0}px", _snappedy);
e.Graphics.DrawLine(_drawSnapPen, 0, _snappedy * Factory.AGSEditor.CurrentGame.GUIScaleFactor, g.Width * Factory.AGSEditor.CurrentGame.GUIScaleFactor, _snappedy * Factory.AGSEditor.CurrentGame.GUIScaleFactor);
e.Graphics.DrawString(snapystring,
DefaultFont,
_drawSnapPen.Brush,
_selectedControl.Left * Factory.AGSEditor.CurrentGame.GUIScaleFactor,
_selectedControl.Top * Factory.AGSEditor.CurrentGame.GUIScaleFactor - e.Graphics.MeasureString(snapystring, DefaultFont).Height
);
}
}
base.OnPaint(e);
}