From e9f5879b1efa61c2c78d5f5d87ae578997e6ed55 Mon Sep 17 00:00:00 2001 From: chrisf Date: Sat, 7 Jul 2007 08:14:15 +0000 Subject: [PATCH] git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1137 993157c7-ee19-0410-b2c4-bb4e9862e678 --- OpenRa.Game/MainWindow.cs | 36 +++++++++++++++++++++++++++++++++--- diffuse.fx | 3 ++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index 15da6b7c74..c42c2866e6 100644 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -31,7 +31,7 @@ namespace OpenRa.Game Dictionary drawBatches = new Dictionary(); Effect effect; - IntPtr textureParameter; + IntPtr texture, scroll; SpriteHelper spriteHelper; FontHelper fontHelper; @@ -144,7 +144,8 @@ namespace OpenRa.Game LoadVertexBuffer(); effect = new Effect(device, File.OpenRead("../../../" + shaderName)); - textureParameter = effect.GetHandle("DiffuseTexture"); + texture = effect.GetHandle("DiffuseTexture"); + scroll = effect.GetHandle("Scroll"); spriteHelper = new SpriteHelper(device); fontHelper = new FontHelper(device, "Tahoma", 10, false); @@ -159,6 +160,33 @@ namespace OpenRa.Game } } + PointF scrollPos = new PointF(1, 5); + PointF oldPos; + int x1,y1; + + protected override void OnMouseDown(MouseEventArgs e) + { + base.OnMouseDown(e); + + x1 = e.X; + y1 = e.Y; + oldPos = scrollPos; + } + + protected override void OnMouseMove(MouseEventArgs e) + { + base.OnMouseMove(e); + + if (e.Button != 0) + { + int dx = x1 - e.X; + int dy = y1 - e.Y; + scrollPos = oldPos; + scrollPos.X += (float)dx / 320.0f; + scrollPos.Y += (float)dy / 240.0f; + } + } + void Frame() { device.Begin(); @@ -170,9 +198,11 @@ namespace OpenRa.Game effect.Begin(); effect.BeginPass(0); + effect.SetValue(scroll, scrollPos); + foreach (KeyValuePair batch in drawBatches) { - effect.SetTexture(textureParameter, batch.Key.texture); + effect.SetTexture(texture, batch.Key.texture); effect.Commit(); batch.Value.Bind(); diff --git a/diffuse.fx b/diffuse.fx index 797cd0a25c..e22f1c1386 100644 --- a/diffuse.fx +++ b/diffuse.fx @@ -3,6 +3,7 @@ //-------------------------------------------------------- shared texture DiffuseTexture; +shared float2 Scroll; sampler s_DiffuseTexture = sampler_state { Texture = ; @@ -31,7 +32,7 @@ struct FragmentIn { VertexOut Simple_vp(VertexIn v) { VertexOut o; - o.Position = float4( v.Position.x / 320.0f - 0.5f - 2, 5-v.Position.y / 240.0f, 0, 1 ); + o.Position = float4( v.Position.x / 320.0f - 0.5f - Scroll.x, Scroll.y - v.Position.y / 240.0f, 0, 1 ); o.Tex0 = v.Tex0; return o; }