unsnarled the input a bit
This commit is contained in:
@@ -6,18 +6,18 @@ namespace OpenRa.Game.Graphics
|
||||
{
|
||||
class Region
|
||||
{
|
||||
float2 location;
|
||||
int2 location;
|
||||
Viewport viewport;
|
||||
|
||||
public float2 Location
|
||||
public int2 Location
|
||||
{
|
||||
get { return location + viewport.Location; } // WTF HACK HACK HACK
|
||||
get { return location + new int2( (int)viewport.Location.X, (int)viewport.Location.Y ); } // WTF HACK HACK HACK
|
||||
}
|
||||
|
||||
public readonly float2 Size;
|
||||
|
||||
Action drawFunction;
|
||||
MouseEventHandler mouseHandler;
|
||||
Action<MouseInput> mouseHandler;
|
||||
Rectangle rect;
|
||||
|
||||
static int2 MakeSize(Viewport v, DockStyle d, int size)
|
||||
@@ -37,12 +37,19 @@ namespace OpenRa.Game.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
public void Clicked(MouseEventArgs e)
|
||||
{
|
||||
mouseHandler(this, new MouseEventArgs(e.Button, e.Clicks, e.X - rect.Left, e.Y - rect.Top, e.Delta));
|
||||
}
|
||||
public bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
/* todo: route to the mousehandler once that's sorted */
|
||||
if (mouseHandler != null) mouseHandler(new MouseInput
|
||||
{
|
||||
Button = mi.Button,
|
||||
Event = mi.Event,
|
||||
Location = mi.Location - Location
|
||||
});
|
||||
return mouseHandler != null;
|
||||
}
|
||||
|
||||
public static Region Create(Viewport v, DockStyle d, int size, Action f, MouseEventHandler m)
|
||||
public static Region Create(Viewport v, DockStyle d, int size, Action f, Action<MouseInput> m)
|
||||
{
|
||||
int2 s = MakeSize(v, d, size);
|
||||
|
||||
@@ -61,7 +68,7 @@ namespace OpenRa.Game.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
Region(int2 location, int2 size, Viewport viewport, Action drawFunction, MouseEventHandler mouseHandler)
|
||||
Region(int2 location, int2 size, Viewport viewport, Action drawFunction, Action<MouseInput> mouseHandler)
|
||||
{
|
||||
this.location = location;
|
||||
this.Size = size;
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace OpenRa.Game.Graphics
|
||||
public TerrainRenderer(Renderer renderer, Map map, Viewport viewport)
|
||||
{
|
||||
this.renderer = renderer;
|
||||
region = Region.Create(viewport, DockStyle.Left, viewport.Width - 128, Draw, (_, e) => { } );
|
||||
region = Region.Create(viewport, DockStyle.Left, viewport.Width - 128, Draw, null );
|
||||
viewport.AddRegion(region);
|
||||
this.map = map;
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenRa.Game.Graphics
|
||||
{
|
||||
@@ -44,6 +46,18 @@ namespace OpenRa.Game.Graphics
|
||||
renderer.EndFrame();
|
||||
}
|
||||
|
||||
public IEnumerable<Region> Regions { get { return regions; } }
|
||||
Region dragRegion = null;
|
||||
public void DispatchMouseInput(MouseInput mi)
|
||||
{
|
||||
if (dragRegion != null) {
|
||||
dragRegion.HandleMouseInput( mi );
|
||||
if (mi.Event == MouseInputEvent.Up) dragRegion = null;
|
||||
return;
|
||||
}
|
||||
|
||||
dragRegion = regions.FirstOrDefault(r => r.Contains(mi.Location) && r.HandleMouseInput(mi));
|
||||
if (mi.Event != MouseInputEvent.Down)
|
||||
dragRegion = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,9 @@ namespace OpenRa.Game.Graphics
|
||||
// TODO: this is layout policy. it belongs at a higher level than this.
|
||||
|
||||
region = Region.Create(world.game.viewport, DockStyle.Left,
|
||||
world.game.viewport.Width - 128, Draw, world.game.controller.WorldClicked); // TODO: world.WorldClicked is part of the CONTROLLER
|
||||
world.game.viewport.Width - 128, Draw,
|
||||
world.game.controller.HandleMouseInput);
|
||||
|
||||
world.game.viewport.AddRegion(region);
|
||||
|
||||
spriteRenderer = new SpriteRenderer(renderer, true);
|
||||
|
||||
Reference in New Issue
Block a user