Skip to content

Commit

Permalink
#10 Removed SystemWindows.Forms.MouseEventArgs usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Wouters-Yaowanasap authored and Stefan Wouters-Yaowanasap committed May 17, 2016
1 parent b669a57 commit 50d0b62
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/Win32/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Threading;
using System.Windows.Forms;
using CivOne.Enums;
using CivOne.Events;
using CivOne.GFX;
using CivOne.Interfaces;
using CivOne.Screens;
Expand Down Expand Up @@ -165,10 +166,13 @@ private void ToggleFullScreen()
LoadCursors();
}

private void ScaleMouseEventArgs(ref MouseEventArgs args)
private ScreenEventArgs ScaleMouseEventArgs(MouseEventArgs args)
{
int xx = args.X - CanvasX, yy = args.Y - CanvasY;
args = new MouseEventArgs(args.Button, args.Clicks, (int)Math.Floor((float)xx / ScaleX), (int)Math.Floor((float)yy / ScaleY), args.Delta);
MouseButton buttons = MouseButton.None;
if (args.Button == MouseButtons.Left) buttons = MouseButton.Left;
else if (args.Button == MouseButtons.Right) buttons = MouseButton.Right;
return new ScreenEventArgs((int)Math.Floor((float)xx / ScaleX), (int)Math.Floor((float)yy / ScaleY), buttons);
}

private void OnFormClosing(object sender, FormClosingEventArgs args)
Expand Down Expand Up @@ -240,20 +244,20 @@ private void OnKeyDown(object sender, KeyEventArgs args)

private void OnMouseDown(object sender, MouseEventArgs args)
{
ScaleMouseEventArgs(ref args);
if (TopScreen != null && TopScreen.MouseDown(args)) ScreenUpdate();
ScreenEventArgs screenArgs = ScaleMouseEventArgs(args);
if (TopScreen != null && TopScreen.MouseDown(screenArgs)) ScreenUpdate();
}

private void OnMouseUp(object sender, MouseEventArgs args)
{
ScaleMouseEventArgs(ref args);
if (TopScreen != null && TopScreen.MouseUp(args)) ScreenUpdate();
ScreenEventArgs screenArgs = ScaleMouseEventArgs(args);
if (TopScreen != null && TopScreen.MouseUp(screenArgs)) ScreenUpdate();
}

private void MouseDrag(MouseEventArgs args)
{
ScaleMouseEventArgs(ref args);
if (TopScreen != null && TopScreen.MouseDrag(args)) ScreenUpdate();
ScreenEventArgs screenArgs = ScaleMouseEventArgs(args);
if (TopScreen != null && TopScreen.MouseDrag(screenArgs)) ScreenUpdate();
}

private void OnMouseMove(object sender, MouseEventArgs args)
Expand Down

0 comments on commit 50d0b62

Please sign in to comment.