agate-svn-commit Mailing List for AgateLib (Page 24)
Status: Alpha
Brought to you by:
kanato
You can subscribe to this list here.
2009 |
Jan
|
Feb
|
Mar
|
Apr
(86) |
May
(77) |
Jun
|
Jul
(1) |
Aug
(31) |
Sep
(12) |
Oct
(31) |
Nov
(53) |
Dec
(39) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2010 |
Jan
(53) |
Feb
(14) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
|
Oct
|
Nov
(7) |
Dec
(13) |
2011 |
Jan
(17) |
Feb
(5) |
Mar
(1) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(10) |
Nov
(21) |
Dec
|
2012 |
Jan
(6) |
Feb
(14) |
Mar
(5) |
Apr
(4) |
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
(1) |
Feb
(8) |
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
(1) |
Oct
(5) |
Nov
(9) |
Dec
(5) |
2014 |
Jan
(3) |
Feb
(2) |
Mar
(4) |
Apr
(3) |
May
|
Jun
(5) |
Jul
(33) |
Aug
(69) |
Sep
(35) |
Oct
(4) |
Nov
(1) |
Dec
|
From: <ka...@us...> - 2009-05-09 22:07:15
|
Revision: 962 http://agate.svn.sourceforge.net/agate/?rev=962&view=rev Author: kanato Date: 2009-05-09 22:06:59 +0000 (Sat, 09 May 2009) Log Message: ----------- Implement driver preference option when AgateLib is initialized. Modified Paths: -------------- branches/agate3d-3.2/AgateLib/AgateApplication.cs branches/agate3d-3.2/AgateLib/AgateSetup.cs branches/agate3d-3.2/AgateLib/AppInitParameters.cs branches/agate3d-3.2/AgateLib/Drivers/IUserSetSystems.cs branches/agate3d-3.2/AgateLib/Drivers/Registrar.cs branches/agate3d-3.2/Drivers/AgateLib.WinForms/SetSystemsForm.Designer.cs branches/agate3d-3.2/Drivers/AgateLib.WinForms/SetSystemsForm.cs branches/agate3d-3.2/Tests/Display3D/Glsl.cs branches/agate3d-3.2/Tests/Display3D/Hlsl.cs branches/agate3d-3.2/Tests/frmLauncher.cs Modified: branches/agate3d-3.2/AgateLib/AgateApplication.cs =================================================================== --- branches/agate3d-3.2/AgateLib/AgateApplication.cs 2009-05-07 17:07:44 UTC (rev 961) +++ branches/agate3d-3.2/AgateLib/AgateApplication.cs 2009-05-09 22:06:59 UTC (rev 962) @@ -49,7 +49,7 @@ double totalSplashTime = 0; bool splashFadeDone = false; - #region --- Run Methods --- + #region --- Run Method --- /// <summary> /// Runs the application. @@ -68,6 +68,10 @@ { using (AgateSetup setup = new AgateSetup(args)) { + setup.PreferredDisplay = InitParams.PreferredDisplay; + setup.PreferredAudio = InitParams.PreferredAudio; + setup.PreferredInput = InitParams.PreferredInput; + setup.Initialize( InitParams.InitializeDisplay, InitParams.InitializeAudio, Modified: branches/agate3d-3.2/AgateLib/AgateSetup.cs =================================================================== --- branches/agate3d-3.2/AgateLib/AgateSetup.cs 2009-05-07 17:07:44 UTC (rev 961) +++ branches/agate3d-3.2/AgateLib/AgateSetup.cs 2009-05-09 22:06:59 UTC (rev 962) @@ -66,10 +66,29 @@ private bool mUseAudio = true; private bool mUseInput = true; + private DisplayTypeID mPreferredDisplay = DisplayTypeID.AutoSelect; + private AudioTypeID mPreferredAudio = AudioTypeID.AutoSelect; + private InputTypeID mPreferredInput = InputTypeID.AutoSelect; + private DisplayTypeID mSelectDisplay = DisplayTypeID.AutoSelect; private AudioTypeID mSelectAudio = AudioTypeID.AutoSelect; private InputTypeID mSelectInput = InputTypeID.AutoSelect; + public DisplayTypeID PreferredDisplay + { + get { return mPreferredDisplay; } + set { mPreferredDisplay = value; } + } + public AudioTypeID PreferredAudio + { + get { return mPreferredAudio; } + set { mPreferredAudio = value; } + } + public InputTypeID PreferredInput + { + get { return mPreferredInput; } + set { mPreferredInput = value; } + } /// <summary> /// Constructs a Setup object. @@ -280,8 +299,10 @@ return; mWasCanceled = !Registrar.UserSelectDrivers(mUseDisplay, mUseAudio, mUseInput, - out mSelectDisplay, out mSelectAudio, out mSelectInput); + mPreferredDisplay, mPreferredAudio, mPreferredInput , + out mSelectDisplay, out mSelectAudio, out mSelectInput); + mAlreadyAsked = true; } Modified: branches/agate3d-3.2/AgateLib/AppInitParameters.cs =================================================================== --- branches/agate3d-3.2/AgateLib/AppInitParameters.cs 2009-05-07 17:07:44 UTC (rev 961) +++ branches/agate3d-3.2/AgateLib/AppInitParameters.cs 2009-05-09 22:06:59 UTC (rev 962) @@ -23,5 +23,10 @@ public bool InitializeDisplay { get; set; } public bool InitializeAudio { get; set; } public bool InitializeJoysticks { get; set; } + + public Drivers.DisplayTypeID PreferredDisplay { get; set; } + public Drivers.AudioTypeID PreferredAudio { get; set; } + public Drivers.InputTypeID PreferredInput { get; set; } + } } Modified: branches/agate3d-3.2/AgateLib/Drivers/IUserSetSystems.cs =================================================================== --- branches/agate3d-3.2/AgateLib/Drivers/IUserSetSystems.cs 2009-05-07 17:07:44 UTC (rev 961) +++ branches/agate3d-3.2/AgateLib/Drivers/IUserSetSystems.cs 2009-05-09 22:06:59 UTC (rev 962) @@ -82,8 +82,7 @@ /// <param name="chooseDisplay"></param> /// <param name="chooseAudio"></param> /// <param name="chooseInput"></param> - void SetChoices(bool chooseDisplay, bool chooseAudio, bool chooseInput); - - + void SetChoices(bool chooseDisplay, bool chooseAudio, bool chooseInput, + DisplayTypeID preferredDisplay, AudioTypeID preferredAudio, InputTypeID preferredInput); } } Modified: branches/agate3d-3.2/AgateLib/Drivers/Registrar.cs =================================================================== --- branches/agate3d-3.2/AgateLib/Drivers/Registrar.cs 2009-05-07 17:07:44 UTC (rev 961) +++ branches/agate3d-3.2/AgateLib/Drivers/Registrar.cs 2009-05-09 22:06:59 UTC (rev 962) @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Linq; using System.Reflection; using System.Text; @@ -45,10 +46,31 @@ private static IDesktopDriver mDesktop; private static readonly string[] KnownNativeLibraries = new string[] - { - "SDL.dll", - }; + { + "SDL.dll", + }; + + static bool Contains(this List<AgateDriverInfo> list, DisplayTypeID type) + { + return list.Any( + x => comparator(x, DriverType.Display, (int)type)); + } + static bool Contains(this List<AgateDriverInfo> list, AudioTypeID type) + { + return list.Any( + x => comparator(x, DriverType.Audio, (int)type)); + } + static bool Contains(this List<AgateDriverInfo> list, InputTypeID type) + { + return list.Any( + x => comparator(x, DriverType.Input, (int)type)); + } + static bool comparator(AgateDriverInfo info, DriverType driverType, int type) + { + return info.DriverType == driverType && info.DriverTypeID == type; + } + static Registrar() { } @@ -199,20 +221,21 @@ /// <param name="selectedInput"></param> /// <returns></returns> internal static bool UserSelectDrivers(bool chooseDisplay, bool chooseAudio, bool chooseInput, + DisplayTypeID preferredDisplay, AudioTypeID preferredAudio, InputTypeID preferredInput, out DisplayTypeID selectedDisplay, out AudioTypeID selectedAudio, out InputTypeID selectedInput) { if (mDesktop == null) { CreateDesktopDriver(); + if (mDesktop == null) SelectBestDrivers(chooseDisplay, chooseAudio, chooseInput, + preferredDisplay, preferredAudio, preferredInput, out selectedDisplay, out selectedAudio, out selectedInput); } IUserSetSystems frm = mDesktop.CreateUserSetSystems(); - frm.SetChoices(chooseDisplay, chooseAudio, chooseInput); - // set default values. selectedDisplay = DisplayTypeID.AutoSelect; selectedAudio = AudioTypeID.AutoSelect; @@ -231,6 +254,10 @@ frm.AddInputType(info); } + frm.SetChoices(chooseDisplay, chooseAudio, chooseInput, + preferredDisplay, preferredAudio, preferredInput); + + // run the dialog asking user which drivers to use. if (frm.RunDialog() == SetSystemsDialogResult.Cancel) { return false; @@ -245,17 +272,27 @@ } private static void SelectBestDrivers(bool chooseDisplay, bool chooseAudio, bool chooseInput, + DisplayTypeID preferredDisplay, AudioTypeID preferredAudio, InputTypeID preferredInput, out DisplayTypeID selectedDisplay, out AudioTypeID selectedAudio, out InputTypeID selectedInput) { + // initial return values if a driver isn't selected. selectedDisplay = DisplayTypeID.AutoSelect; selectedAudio = AudioTypeID.AutoSelect; selectedInput = InputTypeID.AutoSelect; - if (displayDrivers.Count > 0) + if (preferredDisplay != DisplayTypeID.AutoSelect && displayDrivers.Contains(preferredDisplay)) + selectedDisplay = preferredDisplay; + else if (displayDrivers.Count > 0) selectedDisplay = (DisplayTypeID)displayDrivers[0].DriverTypeID; - if (audioDrivers.Count > 0) + + if (preferredAudio != AudioTypeID.AutoSelect && audioDrivers.Contains(preferredAudio)) + selectedAudio = preferredAudio; + else if (audioDrivers.Count > 0) selectedAudio = (AudioTypeID)audioDrivers[0].DriverTypeID; - if (inputDrivers.Count > 0) + + if (preferredInput != InputTypeID.AutoSelect && inputDrivers.Contains(preferredInput)) + selectedInput = preferredInput; + else if (inputDrivers.Count > 0) selectedInput = (InputTypeID)inputDrivers[0].DriverTypeID; } @@ -409,5 +446,6 @@ get { return inputDrivers; } } + } } Modified: branches/agate3d-3.2/Drivers/AgateLib.WinForms/SetSystemsForm.Designer.cs =================================================================== --- branches/agate3d-3.2/Drivers/AgateLib.WinForms/SetSystemsForm.Designer.cs 2009-05-07 17:07:44 UTC (rev 961) +++ branches/agate3d-3.2/Drivers/AgateLib.WinForms/SetSystemsForm.Designer.cs 2009-05-09 22:06:59 UTC (rev 962) @@ -163,7 +163,6 @@ this.MaximizeBox = false; this.Name = "SetSystemsForm"; this.Text = "Select Drivers"; - this.Load += new System.EventHandler(this.frmSetSystems_Load); this.ResumeLayout(false); } Modified: branches/agate3d-3.2/Drivers/AgateLib.WinForms/SetSystemsForm.cs =================================================================== --- branches/agate3d-3.2/Drivers/AgateLib.WinForms/SetSystemsForm.cs 2009-05-07 17:07:44 UTC (rev 961) +++ branches/agate3d-3.2/Drivers/AgateLib.WinForms/SetSystemsForm.cs 2009-05-09 22:06:59 UTC (rev 962) @@ -71,19 +71,7 @@ Icon = FormUtil.AgateLibIcon; } - /// <summary> - /// Constructs the form. Specifies whether display, audio and input - /// should be allowed to be chosen. - /// </summary> - /// <param name="chooseDisplay"></param> - /// <param name="chooseAudio"></param> - /// <param name="chooseInput"></param> - public SetSystemsForm(bool chooseDisplay, bool chooseAudio, bool chooseInput) - { - InitializeComponent(); - } - /// <summary> /// Adds. /// </summary> @@ -130,22 +118,59 @@ } } - private void frmSetSystems_Load(object sender, EventArgs e) - { - SelectFirst(displayList); - SelectFirst(audioList); - SelectFirst(inputList); - } - private void SelectFirst(ComboBox theComboBox) { if (theComboBox.Items.Count > 0) theComboBox.SelectedIndex = 0; } + private void SelectItem(ComboBox theComboBox, int driverTypeID) + { + for (int i = 0; i < theComboBox.Items.Count; i++) + { + AgateDriverInfo item = (AgateDriverInfo)theComboBox.Items[i]; + + if (item.DriverTypeID == driverTypeID) + { + theComboBox.SelectedIndex = i; + return; + } + } + + SelectFirst(theComboBox); + } + #region IUserSetSystems Members + public void SetChoices(bool chooseDisplay, bool chooseAudio, bool chooseInput, + DisplayTypeID preferredDisplay, AudioTypeID preferredAudio, InputTypeID preferredInput) + { + mChooseDisplay = chooseDisplay; + mChooseAudio = chooseAudio; + mChooseInput = chooseInput; + displayList.Enabled = mChooseDisplay; + audioList.Enabled = mChooseAudio; + inputList.Enabled = mChooseInput; + + if (preferredDisplay != DisplayTypeID.AutoSelect) + SelectItem(displayList, (int)preferredDisplay); + else + SelectFirst(displayList); + + if (preferredAudio != AudioTypeID.AutoSelect) + SelectItem(audioList, (int)preferredAudio); + else + SelectFirst(audioList); + + if (preferredInput != InputTypeID.AutoSelect) + SelectItem(inputList, (int)preferredInput); + else + SelectFirst(inputList); + } + + + public SetSystemsDialogResult RunDialog() { if (displayList.Items.Count == 0 && mChooseDisplay) @@ -164,20 +189,7 @@ } } - public void SetChoices(bool chooseDisplay, bool chooseAudio, bool chooseInput) - { - mChooseDisplay = chooseDisplay; - mChooseAudio = chooseAudio; - mChooseInput = chooseInput; - - displayList.Enabled = mChooseDisplay; - audioList.Enabled = mChooseAudio; - inputList.Enabled = mChooseInput; - } - - #endregion - } } \ No newline at end of file Modified: branches/agate3d-3.2/Tests/Display3D/Glsl.cs =================================================================== --- branches/agate3d-3.2/Tests/Display3D/Glsl.cs 2009-05-07 17:07:44 UTC (rev 961) +++ branches/agate3d-3.2/Tests/Display3D/Glsl.cs 2009-05-09 22:06:59 UTC (rev 962) @@ -59,6 +59,7 @@ { using (AgateSetup setup = new AgateSetup(args)) { + setup.PreferredDisplay = AgateLib.Drivers.DisplayTypeID.OpenGL; setup.Initialize(true, false, false); if (setup.WasCanceled) return; Modified: branches/agate3d-3.2/Tests/Display3D/Hlsl.cs =================================================================== --- branches/agate3d-3.2/Tests/Display3D/Hlsl.cs 2009-05-07 17:07:44 UTC (rev 961) +++ branches/agate3d-3.2/Tests/Display3D/Hlsl.cs 2009-05-09 22:06:59 UTC (rev 962) @@ -59,11 +59,12 @@ { using (AgateSetup setup = new AgateSetup(args)) { + setup.PreferredDisplay = AgateLib.Drivers.DisplayTypeID.Direct3D_MDX_1_1; setup.Initialize(true, false, false); if (setup.WasCanceled) return; - wind = DisplayWindow.CreateWindowed("GLSL", 800, 600); + wind = DisplayWindow.CreateWindowed("HLSL", 800, 600); Mouse.MouseDown += new InputEventHandler(Mouse_MouseDown); FontSurface font = new FontSurface("Arial", 14.0f); Modified: branches/agate3d-3.2/Tests/frmLauncher.cs =================================================================== --- branches/agate3d-3.2/Tests/frmLauncher.cs 2009-05-07 17:07:44 UTC (rev 961) +++ branches/agate3d-3.2/Tests/frmLauncher.cs 2009-05-09 22:06:59 UTC (rev 962) @@ -116,6 +116,7 @@ finally { this.Show(); + Cursor.Show(); this.TopMost = true; this.TopMost = false; this.Activate(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ac...@us...> - 2009-05-07 17:07:54
|
Revision: 961 http://agate.svn.sourceforge.net/agate/?rev=961&view=rev Author: accagon Date: 2009-05-07 17:07:44 +0000 (Thu, 07 May 2009) Log Message: ----------- * ParticleEmitter.cs: Call update for each particle * Particle.cs: - Add enum Condition as property - Adjust IsAlive to use Condition - Only update alive particles - Use temp euler method to update particle * Emitters/PixelEmitter.cs: - Add EmitLife property - Adjust code to new Particle.Condition property - Set new particles to emitter properties and default values Modified Paths: -------------- branches/particles/AgateLib/Particles/Emitters/PixelEmitter.cs branches/particles/AgateLib/Particles/Particle.cs branches/particles/AgateLib/Particles/ParticleEmitter.cs Modified: branches/particles/AgateLib/Particles/Emitters/PixelEmitter.cs =================================================================== --- branches/particles/AgateLib/Particles/Emitters/PixelEmitter.cs 2009-05-07 15:53:01 UTC (rev 960) +++ branches/particles/AgateLib/Particles/Emitters/PixelEmitter.cs 2009-05-07 17:07:44 UTC (rev 961) @@ -30,6 +30,7 @@ public class PixelEmitter : ParticleEmitter { private Color mEmitColor = Color.White; + private float mEmitLife = 1f; private Surface drawSurf = new Surface(2, 2); private float time = 0f; @@ -43,6 +44,15 @@ set { mEmitColor = value; } } + /// <value> + /// Gets or sets the life of particles which will be emitted in future. + /// </value> + public float EmitLife + { + get { return mEmitLife; } + set { mEmitLife = value; } + } + /// <summary> /// Constructs a pixel particle emitter. /// </summary> @@ -73,7 +83,7 @@ { foreach(PixelParticle ptl in Particles) { - if(ptl.IsALive == true) + if(ptl.Condition == Condition.ALive || ptl.Condition == Condition.Frozen) { Display.DrawEllipse(new Rectangle((int)ptl.Position.X, (int)ptl.Position.Y, 2, 2), ptl.Color); //drawSurf.Color = ptl.Color; @@ -100,15 +110,20 @@ { // TODO: recyle dead particles PixelParticle pp = new PixelParticle(EmitColor); - pp.Position = Position; - pp.Life = 10f; + pp.Acceleration = Vector2.Empty; + pp.Color = EmitColor; + pp.Condition = Condition.ALive; + pp.Life = EmitLife; + pp.Position = Position; + pp.Velocity = Vector2.Empty; + Particles.Add(pp); time -= frequenzy; } - // updates own position and calls manipulators + // updates own position, particle positions and calls manipulators base.Update (time_ms); } } Modified: branches/particles/AgateLib/Particles/Particle.cs =================================================================== --- branches/particles/AgateLib/Particles/Particle.cs 2009-05-07 15:53:01 UTC (rev 960) +++ branches/particles/AgateLib/Particles/Particle.cs 2009-05-07 17:07:44 UTC (rev 961) @@ -29,7 +29,7 @@ public class Particle { private float mLife = 10f; - private bool mIsALive = false; + private Condition mCondition = Condition.Paused; private Vector2 mAcceleration = Vector2.Empty; private Vector2 mPosition = Vector2.Empty; @@ -46,14 +46,28 @@ } /// <value> - /// Is particle dead. + /// Is particle alive. /// </value> public bool IsALive { - get { return mIsALive; } + get { + if(mCondition == Condition.Dead) + return false; + else + return true; + } } /// <value> + /// Gets or sets the condition. + /// </value> + public Condition Condition + { + get { return mCondition; } + set { mCondition = value; } + } + + /// <value> /// Gets or sets the acceleration. /// </value> public Vector2 Acceleration @@ -88,20 +102,24 @@ /// </param> public virtual void Update(float time_ms) { + // If the particle is not alive don't simulate + if(mCondition != Condition.ALive) + return; + // passed time in seconds float time = time_ms/1000; mLife -= time; if(mLife <= 0) { - mIsALive = false; + mCondition = Condition.Dead; } // Euler method // v = v + a * dt // x = x + v * dt - // mVelocity = mVelocity + mAcceleration * time; - // mPosition = mPosition + mVelocity * time; + mVelocity = mVelocity + mAcceleration * time; + mPosition = mPosition + mVelocity * time; // verlet integration // xi+1 = xi + (xi - xi-1) + a * dt * dt @@ -112,4 +130,27 @@ // mPosition = mPosition + (mPosition - mPosition - 1) * (time / time - 1) + mAcceleration * time * time; } } + + /// <summary> + /// Describes the condition of an Particle + /// </summary> + public enum Condition + { + /// <summary> + /// Particle is alive and will be simulated. + /// </summary> + ALive, + /// <summary> + /// Particle is dead and is ready to get recycled. + /// </summary> + Dead, + /// <summary> + /// Particle is paused and will not be simulated. + /// </summary> + Paused, + /// <summary> + /// Particle is frozen and will not be simulated but drawn. + /// </summary> + Frozen + } } Modified: branches/particles/AgateLib/Particles/ParticleEmitter.cs =================================================================== --- branches/particles/AgateLib/Particles/ParticleEmitter.cs 2009-05-07 15:53:01 UTC (rev 960) +++ branches/particles/AgateLib/Particles/ParticleEmitter.cs 2009-05-07 17:07:44 UTC (rev 961) @@ -91,6 +91,11 @@ if ( OnUpdate != null) OnUpdate(new UpdateArgs(this, time_ms)); + foreach(Particle pt in Particles) + { + pt.Update(time_ms); + } + base.Update (time_ms); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-05-07 15:53:17
|
Revision: 960 http://agate.svn.sourceforge.net/agate/?rev=960&view=rev Author: kanato Date: 2009-05-07 15:53:01 +0000 (Thu, 07 May 2009) Log Message: ----------- Initial implementation of compiling HLSL vertex and pixel shaders. Modified Paths: -------------- branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderCompiler.cs branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderProgram.cs branches/agate3d-3.2/AgateLib/ImplementationBase/ShaderCompilerImpl.cs branches/agate3d-3.2/Drivers/AgateMDX/HlslCompiler.cs branches/agate3d-3.2/Drivers/AgateMDX/HlslShaderProgram.cs branches/agate3d-3.2/Tests/Display3D/Hlsl.cs Added Paths: ----------- branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/Effect.cs branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/Technique.cs branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_pixel.txt branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_vertex.txt Removed Paths: ------------- branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_fragment.txt branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_vertex.txt Added: branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/Effect.cs =================================================================== --- branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/Effect.cs (rev 0) +++ branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/Effect.cs 2009-05-07 15:53:01 UTC (rev 960) @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AgateLib.DisplayLib.Shaders +{ + public class Effect + { + } +} Modified: branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderCompiler.cs =================================================================== --- branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderCompiler.cs 2009-05-07 13:19:02 UTC (rev 959) +++ branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderCompiler.cs 2009-05-07 15:53:01 UTC (rev 960) @@ -27,6 +27,10 @@ impl = null; } + public static ShaderProgram CompileEffect(ShaderLanguage language, string effectSource) + { + return impl.CompileEffect(language, effectSource); + } public static ShaderProgram CompileShader(ShaderLanguage language, string vertexShaderSource, string pixelShaderSource) { return impl.CompileShader(language, vertexShaderSource, pixelShaderSource); Modified: branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderProgram.cs =================================================================== --- branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderProgram.cs 2009-05-07 13:19:02 UTC (rev 959) +++ branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderProgram.cs 2009-05-07 15:53:01 UTC (rev 960) @@ -34,5 +34,9 @@ } public VertexLayout VertexDefinition { get; set; } + + public abstract void Render(RenderHandler handler, object obj); } + + public delegate void RenderHandler(object obj); } Added: branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/Technique.cs =================================================================== --- branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/Technique.cs (rev 0) +++ branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/Technique.cs 2009-05-07 15:53:01 UTC (rev 960) @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AgateLib.DisplayLib.Shaders +{ + public class Technique + { + } +} Modified: branches/agate3d-3.2/AgateLib/ImplementationBase/ShaderCompilerImpl.cs =================================================================== --- branches/agate3d-3.2/AgateLib/ImplementationBase/ShaderCompilerImpl.cs 2009-05-07 13:19:02 UTC (rev 959) +++ branches/agate3d-3.2/AgateLib/ImplementationBase/ShaderCompilerImpl.cs 2009-05-07 15:53:01 UTC (rev 960) @@ -9,5 +9,6 @@ public abstract class ShaderCompilerImpl { public abstract ShaderProgram CompileShader(ShaderLanguage language, string vertexShaderSource, string pixelShaderSource); + public abstract ShaderProgram CompileEffect(ShaderLanguage language, string effectSource); } } Modified: branches/agate3d-3.2/Drivers/AgateMDX/HlslCompiler.cs =================================================================== --- branches/agate3d-3.2/Drivers/AgateMDX/HlslCompiler.cs 2009-05-07 13:19:02 UTC (rev 959) +++ branches/agate3d-3.2/Drivers/AgateMDX/HlslCompiler.cs 2009-05-07 15:53:01 UTC (rev 960) @@ -4,6 +4,7 @@ using System.Text; using AgateLib.DisplayLib.Shaders; using AgateLib.ImplementationBase; +using Direct3D = Microsoft.DirectX.Direct3D; namespace AgateMDX { @@ -16,8 +17,27 @@ mDisplay = display; } + public override ShaderProgram CompileEffect(ShaderLanguage language, string effectSource) + { + Direct3D.Effect effect = Direct3D.Effect.FromString(mDisplay.D3D_Device.Device, + effectSource, null, null, Direct3D.ShaderFlags.None, null); + + return new HlslShaderProgram(effect); + } public override ShaderProgram CompileShader(ShaderLanguage language, string vertexShaderSource, string pixelShaderSource) { + var vertexShaderStream = Direct3D.ShaderLoader.CompileShader( + vertexShaderSource, "main", null, "vs_1_1", Direct3D.ShaderFlags.None); + + + var vertexShader = new Direct3D.VertexShader(mDisplay.D3D_Device.Device, vertexShaderStream); + + + var pixelShaderStream = Direct3D.ShaderLoader.CompileShader( + pixelShaderSource, "main", null, "ps_1_1", Direct3D.ShaderFlags.None); + + var pixelShader = new Direct3D.PixelShader(mDisplay.D3D_Device.Device, pixelShaderStream); + throw new NotImplementedException(); //return new HlslShaderProgram(); Modified: branches/agate3d-3.2/Drivers/AgateMDX/HlslShaderProgram.cs =================================================================== --- branches/agate3d-3.2/Drivers/AgateMDX/HlslShaderProgram.cs 2009-05-07 13:19:02 UTC (rev 959) +++ branches/agate3d-3.2/Drivers/AgateMDX/HlslShaderProgram.cs 2009-05-07 15:53:01 UTC (rev 960) @@ -3,11 +3,18 @@ using System.Linq; using System.Text; using AgateLib.DisplayLib.Shaders; +using Direct3D = Microsoft.DirectX.Direct3D; namespace AgateMDX { class HlslShaderProgram : ShaderProgram { + Direct3D.Effect mEffect; + + public HlslShaderProgram(Direct3D.Effect effect) + { + mEffect = effect; + } public override PixelShader PixelShader { get { throw new NotImplementedException(); } @@ -32,6 +39,20 @@ { get { throw new NotImplementedException(); } } + + public override void Render(RenderHandler handler, object obj) + { + int passcount = mEffect.Begin(Microsoft.DirectX.Direct3D.FX.None); + + for (int i = 0; i < passcount; i++) + { + mEffect.BeginPass(i); + handler(obj); + mEffect.EndPass(); + } + + mEffect.End(); + } } class HlslPixelShader : PixelShader Deleted: branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_fragment.txt =================================================================== --- branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_fragment.txt 2009-05-07 13:19:02 UTC (rev 959) +++ branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_fragment.txt 2009-05-07 15:53:01 UTC (rev 960) @@ -1,40 +0,0 @@ -varying vec4 diffuse,ambientGlobal, ambient; -varying vec3 normal,lightDir,halfVector; -varying float dist; -uniform sampler2D texture0; - - -void main() -{ - vec3 n,halfV,viewV,ldir; - float NdotL,NdotHV; - vec4 color = ambientGlobal; - float att; - - /* a fragment shader can't write a varying variable, hence we need - a new variable to store the normalized interpolated normal */ - n = normalize(normal); - - /* compute the dot product between normal and normalized lightdir */ - NdotL = max(dot(n,normalize(lightDir)),0.0); - - if (NdotL > 0.0) { - att = 1.0 / (gl_LightSource[0].constantAttenuation + - gl_LightSource[0].linearAttenuation * dist + - gl_LightSource[0].quadraticAttenuation * dist * dist); - - color += att * (diffuse * NdotL + ambient); - - halfV = normalize(halfVector); - NdotHV = max(dot(n,halfV),0.0); - color += att * gl_FrontMaterial.specular * gl_LightSource[0].specular * - pow(NdotHV,gl_FrontMaterial.shininess); - } - - vec4 texcolor = texture2D(texture0,gl_TexCoord[0].st); - - color.rgb *= texcolor.rgb; - - gl_FragColor = color; -} - Added: branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_pixel.txt =================================================================== (Binary files differ) Property changes on: branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_pixel.txt ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_vertex.txt =================================================================== --- branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_vertex.txt 2009-05-07 13:19:02 UTC (rev 959) +++ branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_vertex.txt 2009-05-07 15:53:01 UTC (rev 960) @@ -1,31 +0,0 @@ -varying vec4 diffuse,ambientGlobal,ambient; -varying vec3 normal,lightDir,halfVector; -varying float dist; - -void main() -{ - vec4 ecPos; - vec3 aux; - - normal = normalize(gl_NormalMatrix * gl_Normal); - - /* these are the new lines of code to compute the light's direction */ - ecPos = gl_ModelViewMatrix * gl_Vertex; - aux = vec3(gl_LightSource[0].position-ecPos); - lightDir = normalize(aux); - dist = length(aux); - - halfVector = normalize(gl_LightSource[0].halfVector.xyz); - - /* Compute the diffuse, ambient and globalAmbient terms */ - diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse; - - /* The ambient terms have been separated since one of them */ - /* suffers attenuation */ - ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient; - ambientGlobal = gl_LightModel.ambient * gl_FrontMaterial.ambient; - - - gl_Position = ftransform(); - gl_TexCoord[0] = gl_MultiTexCoord0; -} Copied: branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_vertex.txt (from rev 958, branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_fragment.txt) =================================================================== --- branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_vertex.txt (rev 0) +++ branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_vertex.txt 2009-05-07 15:53:01 UTC (rev 960) @@ -0,0 +1,31 @@ +float4x4 worldViewProj; + +struct VS_INPUT +{ + float3 position : POSITION; + float4 color0 : COLOR0; + float2 texcoord0 : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 hposition : POSITION; + float4 color0 : COLOR0; + float2 texcoord0 : TEXCOORD0; +}; + +VS_OUTPUT main( VS_INPUT IN ) +{ + VS_OUTPUT OUT; + + float4 v = float4( IN.position.x, + IN.position.y, + IN.position.z, + 1.0f ); + + OUT.hposition = mul( v, worldViewProj ); + OUT.color0 = IN.color0; + OUT.texcoord0 = IN.texcoord0; + + return OUT; +} Modified: branches/agate3d-3.2/Tests/Display3D/Hlsl.cs =================================================================== --- branches/agate3d-3.2/Tests/Display3D/Hlsl.cs 2009-05-07 13:19:02 UTC (rev 959) +++ branches/agate3d-3.2/Tests/Display3D/Hlsl.cs 2009-05-07 15:53:01 UTC (rev 960) @@ -86,8 +86,8 @@ const float size = 25; var shader = ShaderCompiler.CompileShader(ShaderLanguage.Glsl, - File.ReadAllText("Data/shaders/glsl/BumpMap_vertex.txt"), - File.ReadAllText("Data/shaders/glsl/BumpMap_fragment.txt")); + File.ReadAllText("Data/shaders/hlsl/PerPixelLighting_vertex.txt"), + File.ReadAllText("Data/shaders/hlsl/PerPixelLighting_pixel.txt")); //HeightMapTerrain b = new HeightMapTerrain(height.ReadPixels()); //b.Width = size; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ac...@us...> - 2009-05-07 13:19:21
|
Revision: 959 http://agate.svn.sourceforge.net/agate/?rev=959&view=rev Author: accagon Date: 2009-05-07 13:19:02 +0000 (Thu, 07 May 2009) Log Message: ----------- * PixelEmitter.cs: - Change draw code to draw directly to the display - Adjust particle alive check to the new property - Add maxParticle option Modified Paths: -------------- branches/particles/AgateLib/Particles/Emitters/PixelEmitter.cs Modified: branches/particles/AgateLib/Particles/Emitters/PixelEmitter.cs =================================================================== --- branches/particles/AgateLib/Particles/Emitters/PixelEmitter.cs 2009-05-07 04:17:58 UTC (rev 958) +++ branches/particles/AgateLib/Particles/Emitters/PixelEmitter.cs 2009-05-07 13:19:02 UTC (rev 959) @@ -17,6 +17,7 @@ // Contributor(s): Marcel Hauf. // using System; +using System.Collections.Generic; using AgateLib.DisplayLib; using AgateLib.Geometry; @@ -46,13 +47,24 @@ /// Constructs a pixel particle emitter. /// </summary> /// <param name="color">Emit color.</param> - /// <param name="position"></param> + /// <param name="position">Position of the emitter.</param> public PixelEmitter(Vector2 position, Color color) { Position = position; mEmitColor = color; } + /// <summary> + /// Constructs a pixel particle emitter. + /// </summary> + /// <param name="position">Position of the emitter.</param> + /// <param name="color">Emit color.</param> + /// <param name="maxParticles">Maximum amount of particles.</param> + public PixelEmitter(Vector2 position, Color color, int maxParticles) : this(position, color) + { + Particles = new List<Particle>(maxParticles); + } + /// <summary>s /// Overridden Draw method. /// Draws each living particle. @@ -61,10 +73,11 @@ { foreach(PixelParticle ptl in Particles) { - if(ptl.Condition == Condition.ALive) + if(ptl.IsALive == true) { - drawSurf.Color = ptl.Color; - drawSurf.Draw(ptl.Position.X, ptl.Position.Y); + Display.DrawEllipse(new Rectangle((int)ptl.Position.X, (int)ptl.Position.Y, 2, 2), ptl.Color); + //drawSurf.Color = ptl.Color; + //drawSurf.Draw(ptl.Position.X, ptl.Position.Y); } } } @@ -83,11 +96,13 @@ time += time_ms; float frequenzy = EmitFrequenzy*1000; - while(time >= frequenzy) + while(time >= frequenzy && Particles.Count < Particles.Capacity) { // TODO: recyle dead particles PixelParticle pp = new PixelParticle(EmitColor); - pp.Position = Position; + pp.Position = Position; + pp.Life = 10f; + Particles.Add(pp); time -= frequenzy; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-05-07 04:18:19
|
Revision: 958 http://agate.svn.sourceforge.net/agate/?rev=958&view=rev Author: kanato Date: 2009-05-07 04:17:58 +0000 (Thu, 07 May 2009) Log Message: ----------- Introduce HLSL classes. Modified Paths: -------------- branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderLanguage.cs branches/agate3d-3.2/AgateLib/ImplementationBase/DisplayImpl.cs branches/agate3d-3.2/Drivers/AgateMDX/DrawBuffer.cs branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs branches/agate3d-3.2/Drivers/AgateOTK/GL_Display.cs branches/agate3d-3.2/Tests/Display3D/Glsl.cs Added Paths: ----------- branches/agate3d-3.2/Drivers/AgateMDX/HlslCompiler.cs branches/agate3d-3.2/Drivers/AgateMDX/HlslShaderProgram.cs branches/agate3d-3.2/Tests/Data/shaders/glsl/ branches/agate3d-3.2/Tests/Data/shaders/glsl/BumpMap_fragment.txt branches/agate3d-3.2/Tests/Data/shaders/glsl/BumpMap_vertex.txt branches/agate3d-3.2/Tests/Data/shaders/glsl/PerPixelLighting_fragment.txt branches/agate3d-3.2/Tests/Data/shaders/glsl/PerPixelLighting_vertex.txt branches/agate3d-3.2/Tests/Data/shaders/hlsl/ branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_fragment.txt branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_vertex.txt branches/agate3d-3.2/Tests/Display3D/Hlsl.cs Removed Paths: ------------- branches/agate3d-3.2/Tests/Data/shaders/BumpMap_fragment.txt branches/agate3d-3.2/Tests/Data/shaders/BumpMap_vertex.txt branches/agate3d-3.2/Tests/Data/shaders/PerPixelLighting_fragment.txt branches/agate3d-3.2/Tests/Data/shaders/PerPixelLighting_vertex.txt Modified: branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderLanguage.cs =================================================================== --- branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderLanguage.cs 2009-05-07 02:02:28 UTC (rev 957) +++ branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderLanguage.cs 2009-05-07 04:17:58 UTC (rev 958) @@ -10,7 +10,7 @@ Unknown, Glsl, - // Hlsl, + Hlsl, // Cg, } Modified: branches/agate3d-3.2/AgateLib/ImplementationBase/DisplayImpl.cs =================================================================== --- branches/agate3d-3.2/AgateLib/ImplementationBase/DisplayImpl.cs 2009-05-07 02:02:28 UTC (rev 957) +++ branches/agate3d-3.2/AgateLib/ImplementationBase/DisplayImpl.cs 2009-05-07 04:17:58 UTC (rev 958) @@ -650,6 +650,5 @@ ShaderCompiler.Disable(); } - } } Modified: branches/agate3d-3.2/Drivers/AgateMDX/DrawBuffer.cs =================================================================== --- branches/agate3d-3.2/Drivers/AgateMDX/DrawBuffer.cs 2009-05-07 02:02:28 UTC (rev 957) +++ branches/agate3d-3.2/Drivers/AgateMDX/DrawBuffer.cs 2009-05-07 04:17:58 UTC (rev 958) @@ -46,7 +46,6 @@ Texture mTexture; bool mAlphaBlend; - public DrawBuffer(D3DDevice device) { mDevice = device; Added: branches/agate3d-3.2/Drivers/AgateMDX/HlslCompiler.cs =================================================================== --- branches/agate3d-3.2/Drivers/AgateMDX/HlslCompiler.cs (rev 0) +++ branches/agate3d-3.2/Drivers/AgateMDX/HlslCompiler.cs 2009-05-07 04:17:58 UTC (rev 958) @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib.DisplayLib.Shaders; +using AgateLib.ImplementationBase; + +namespace AgateMDX +{ + class HlslCompiler : ShaderCompilerImpl + { + MDX1_Display mDisplay; + + public HlslCompiler(MDX1_Display display) + { + mDisplay = display; + } + + public override ShaderProgram CompileShader(ShaderLanguage language, string vertexShaderSource, string pixelShaderSource) + { + throw new NotImplementedException(); + + //return new HlslShaderProgram(); + } + } +} Added: branches/agate3d-3.2/Drivers/AgateMDX/HlslShaderProgram.cs =================================================================== --- branches/agate3d-3.2/Drivers/AgateMDX/HlslShaderProgram.cs (rev 0) +++ branches/agate3d-3.2/Drivers/AgateMDX/HlslShaderProgram.cs 2009-05-07 04:17:58 UTC (rev 958) @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib.DisplayLib.Shaders; + +namespace AgateMDX +{ + class HlslShaderProgram : ShaderProgram + { + public override PixelShader PixelShader + { + get { throw new NotImplementedException(); } + } + + public override void SetUniform(string name, AgateLib.Geometry.Matrix4 matrix) + { + throw new NotImplementedException(); + } + + public override void SetUniform(string name, params int[] v) + { + throw new NotImplementedException(); + } + + public override void SetUniform(string name, params float[] v) + { + throw new NotImplementedException(); + } + + public override VertexShader VertexShader + { + get { throw new NotImplementedException(); } + } + } + + class HlslPixelShader : PixelShader + { + } + + class HlslVertexShader : VertexShader + { } +} Modified: branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs =================================================================== --- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs 2009-05-07 02:02:28 UTC (rev 957) +++ branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs 2009-05-07 04:17:58 UTC (rev 958) @@ -121,6 +121,7 @@ mDevice = new D3DDevice(device); + InitializeShaders(); } @@ -239,6 +240,10 @@ { return BitmapFontUtil.ConstructFromOSFont(bitmapOptions); } + protected override ShaderCompilerImpl CreateShaderCompiler() + { + return new HlslCompiler(this); + } #endregion @@ -882,12 +887,12 @@ } bool IDisplayCaps.SupportsShaders { - get { return false; } + get { return true; } } AgateLib.DisplayLib.Shaders.ShaderLanguage IDisplayCaps.ShaderLanguage { - get { return AgateLib.DisplayLib.Shaders.ShaderLanguage.Unknown; } + get { return AgateLib.DisplayLib.Shaders.ShaderLanguage.Hlsl; } } #endregion Modified: branches/agate3d-3.2/Drivers/AgateOTK/GL_Display.cs =================================================================== --- branches/agate3d-3.2/Drivers/AgateOTK/GL_Display.cs 2009-05-07 02:02:28 UTC (rev 957) +++ branches/agate3d-3.2/Drivers/AgateOTK/GL_Display.cs 2009-05-07 04:17:58 UTC (rev 958) @@ -428,8 +428,7 @@ mSupportsShaders = true; } - if (mSupportsShaders) - InitializeShaders(); + InitializeShaders(); glInitialized = true; Deleted: branches/agate3d-3.2/Tests/Data/shaders/BumpMap_fragment.txt =================================================================== --- branches/agate3d-3.2/Tests/Data/shaders/BumpMap_fragment.txt 2009-05-07 02:02:28 UTC (rev 957) +++ branches/agate3d-3.2/Tests/Data/shaders/BumpMap_fragment.txt 2009-05-07 04:17:58 UTC (rev 958) @@ -1,46 +0,0 @@ -varying vec4 diffuse,ambientGlobal, ambient; -varying vec3 normal,lightDir,halfVector; -varying float dist; -uniform sampler2D texture0; -uniform sampler2D texture1; - -void main() -{ - vec3 n,halfV,viewV,ldir; - float NdotL,NdotHV; - vec4 color = ambientGlobal; - float att; - - /* a fragment shader can't write a varying variable, hence we need - a new variable to store the normalized interpolated normal */ - n = normalize(normal); - - // calculate the bumpmap properties - vec4 bumpcolor = texture2D(texture1,gl_TexCoord[0].st); - bumpcolor = bumpcolor * 2.0 - 1.0; - n = normalize(bumpcolor.rgb); - //n = vec3(0.707,0,0.707); - - /* compute the dot product between normal and normalized lightdir */ - NdotL = max(dot(n,normalize(lightDir)),0.0); - - if (NdotL > 0.0) { - att = 1.0 / (gl_LightSource[0].constantAttenuation + - gl_LightSource[0].linearAttenuation * dist + - gl_LightSource[0].quadraticAttenuation * dist * dist); - - color += att * (diffuse * NdotL + ambient); - - halfV = normalize(halfVector); - NdotHV = max(dot(n,halfV),0.0); - color += att * gl_FrontMaterial.specular * gl_LightSource[0].specular * - pow(NdotHV,gl_FrontMaterial.shininess); - } - - vec4 texcolor = texture2D(texture0,gl_TexCoord[0].st); - - color.rgb *= texcolor.rgb; - - gl_FragColor = color; -} - Deleted: branches/agate3d-3.2/Tests/Data/shaders/BumpMap_vertex.txt =================================================================== --- branches/agate3d-3.2/Tests/Data/shaders/BumpMap_vertex.txt 2009-05-07 02:02:28 UTC (rev 957) +++ branches/agate3d-3.2/Tests/Data/shaders/BumpMap_vertex.txt 2009-05-07 04:17:58 UTC (rev 958) @@ -1,43 +0,0 @@ - -attribute vec3 tangent; //The inverse tangent to the geometry -attribute vec3 bitangent; //The inverse binormal to the geometry - -varying vec4 diffuse,ambientGlobal,ambient; -varying vec3 normal,lightDir,halfVector; -varying float dist; - -void main() -{ - vec3 aux; - - normal = normalize(gl_Normal); - - // Building the matrix Eye Space -> Tangent Space - vec3 n = normalize (gl_NormalMatrix * gl_Normal); - vec3 t = normalize (gl_NormalMatrix * tangent); - vec3 b = normalize (gl_NormalMatrix * bitangent); - - vec4 evPos = gl_ModelViewMatrix * gl_Vertex; - vec3 lightVec = vec3(gl_LightSource[0].position.xyz - evPos.xyz); - - vec3 v; - v.x = dot(lightVec, t); - v.y = dot(lightVec, b); - v.z = dot(lightVec, n); - lightDir = normalize(v); - - dist = length(lightVec); - - halfVector = normalize(gl_LightSource[0].halfVector.xyz); - - /* Compute the diffuse, ambient and globalAmbient terms */ - diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse; - - /* The ambient terms have been separated since one of them */ - /* suffers attenuation */ - ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient; - ambientGlobal = gl_LightModel.ambient * gl_FrontMaterial.ambient; - - gl_Position = ftransform(); - gl_TexCoord[0] = gl_MultiTexCoord0; -} Deleted: branches/agate3d-3.2/Tests/Data/shaders/PerPixelLighting_fragment.txt =================================================================== --- branches/agate3d-3.2/Tests/Data/shaders/PerPixelLighting_fragment.txt 2009-05-07 02:02:28 UTC (rev 957) +++ branches/agate3d-3.2/Tests/Data/shaders/PerPixelLighting_fragment.txt 2009-05-07 04:17:58 UTC (rev 958) @@ -1,40 +0,0 @@ -varying vec4 diffuse,ambientGlobal, ambient; -varying vec3 normal,lightDir,halfVector; -varying float dist; -uniform sampler2D texture0; - - -void main() -{ - vec3 n,halfV,viewV,ldir; - float NdotL,NdotHV; - vec4 color = ambientGlobal; - float att; - - /* a fragment shader can't write a varying variable, hence we need - a new variable to store the normalized interpolated normal */ - n = normalize(normal); - - /* compute the dot product between normal and normalized lightdir */ - NdotL = max(dot(n,normalize(lightDir)),0.0); - - if (NdotL > 0.0) { - att = 1.0 / (gl_LightSource[0].constantAttenuation + - gl_LightSource[0].linearAttenuation * dist + - gl_LightSource[0].quadraticAttenuation * dist * dist); - - color += att * (diffuse * NdotL + ambient); - - halfV = normalize(halfVector); - NdotHV = max(dot(n,halfV),0.0); - color += att * gl_FrontMaterial.specular * gl_LightSource[0].specular * - pow(NdotHV,gl_FrontMaterial.shininess); - } - - vec4 texcolor = texture2D(texture0,gl_TexCoord[0].st); - - color.rgb *= texcolor.rgb; - - gl_FragColor = color; -} - Deleted: branches/agate3d-3.2/Tests/Data/shaders/PerPixelLighting_vertex.txt =================================================================== --- branches/agate3d-3.2/Tests/Data/shaders/PerPixelLighting_vertex.txt 2009-05-07 02:02:28 UTC (rev 957) +++ branches/agate3d-3.2/Tests/Data/shaders/PerPixelLighting_vertex.txt 2009-05-07 04:17:58 UTC (rev 958) @@ -1,31 +0,0 @@ -varying vec4 diffuse,ambientGlobal,ambient; -varying vec3 normal,lightDir,halfVector; -varying float dist; - -void main() -{ - vec4 ecPos; - vec3 aux; - - normal = normalize(gl_NormalMatrix * gl_Normal); - - /* these are the new lines of code to compute the light's direction */ - ecPos = gl_ModelViewMatrix * gl_Vertex; - aux = vec3(gl_LightSource[0].position-ecPos); - lightDir = normalize(aux); - dist = length(aux); - - halfVector = normalize(gl_LightSource[0].halfVector.xyz); - - /* Compute the diffuse, ambient and globalAmbient terms */ - diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse; - - /* The ambient terms have been separated since one of them */ - /* suffers attenuation */ - ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient; - ambientGlobal = gl_LightModel.ambient * gl_FrontMaterial.ambient; - - - gl_Position = ftransform(); - gl_TexCoord[0] = gl_MultiTexCoord0; -} Copied: branches/agate3d-3.2/Tests/Data/shaders/glsl/BumpMap_fragment.txt (from rev 924, branches/agate3d-3.2/Tests/Data/shaders/BumpMap_fragment.txt) =================================================================== --- branches/agate3d-3.2/Tests/Data/shaders/glsl/BumpMap_fragment.txt (rev 0) +++ branches/agate3d-3.2/Tests/Data/shaders/glsl/BumpMap_fragment.txt 2009-05-07 04:17:58 UTC (rev 958) @@ -0,0 +1,46 @@ +varying vec4 diffuse,ambientGlobal, ambient; +varying vec3 normal,lightDir,halfVector; +varying float dist; +uniform sampler2D texture0; +uniform sampler2D texture1; + +void main() +{ + vec3 n,halfV,viewV,ldir; + float NdotL,NdotHV; + vec4 color = ambientGlobal; + float att; + + /* a fragment shader can't write a varying variable, hence we need + a new variable to store the normalized interpolated normal */ + n = normalize(normal); + + // calculate the bumpmap properties + vec4 bumpcolor = texture2D(texture1,gl_TexCoord[0].st); + bumpcolor = bumpcolor * 2.0 - 1.0; + n = normalize(bumpcolor.rgb); + //n = vec3(0.707,0,0.707); + + /* compute the dot product between normal and normalized lightdir */ + NdotL = max(dot(n,normalize(lightDir)),0.0); + + if (NdotL > 0.0) { + att = 1.0 / (gl_LightSource[0].constantAttenuation + + gl_LightSource[0].linearAttenuation * dist + + gl_LightSource[0].quadraticAttenuation * dist * dist); + + color += att * (diffuse * NdotL + ambient); + + halfV = normalize(halfVector); + NdotHV = max(dot(n,halfV),0.0); + color += att * gl_FrontMaterial.specular * gl_LightSource[0].specular * + pow(NdotHV,gl_FrontMaterial.shininess); + } + + vec4 texcolor = texture2D(texture0,gl_TexCoord[0].st); + + color.rgb *= texcolor.rgb; + + gl_FragColor = color; +} + Copied: branches/agate3d-3.2/Tests/Data/shaders/glsl/BumpMap_vertex.txt (from rev 924, branches/agate3d-3.2/Tests/Data/shaders/BumpMap_vertex.txt) =================================================================== --- branches/agate3d-3.2/Tests/Data/shaders/glsl/BumpMap_vertex.txt (rev 0) +++ branches/agate3d-3.2/Tests/Data/shaders/glsl/BumpMap_vertex.txt 2009-05-07 04:17:58 UTC (rev 958) @@ -0,0 +1,43 @@ + +attribute vec3 tangent; //The inverse tangent to the geometry +attribute vec3 bitangent; //The inverse binormal to the geometry + +varying vec4 diffuse,ambientGlobal,ambient; +varying vec3 normal,lightDir,halfVector; +varying float dist; + +void main() +{ + vec3 aux; + + normal = normalize(gl_Normal); + + // Building the matrix Eye Space -> Tangent Space + vec3 n = normalize (gl_NormalMatrix * gl_Normal); + vec3 t = normalize (gl_NormalMatrix * tangent); + vec3 b = normalize (gl_NormalMatrix * bitangent); + + vec4 evPos = gl_ModelViewMatrix * gl_Vertex; + vec3 lightVec = vec3(gl_LightSource[0].position.xyz - evPos.xyz); + + vec3 v; + v.x = dot(lightVec, t); + v.y = dot(lightVec, b); + v.z = dot(lightVec, n); + lightDir = normalize(v); + + dist = length(lightVec); + + halfVector = normalize(gl_LightSource[0].halfVector.xyz); + + /* Compute the diffuse, ambient and globalAmbient terms */ + diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse; + + /* The ambient terms have been separated since one of them */ + /* suffers attenuation */ + ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient; + ambientGlobal = gl_LightModel.ambient * gl_FrontMaterial.ambient; + + gl_Position = ftransform(); + gl_TexCoord[0] = gl_MultiTexCoord0; +} Copied: branches/agate3d-3.2/Tests/Data/shaders/glsl/PerPixelLighting_fragment.txt (from rev 924, branches/agate3d-3.2/Tests/Data/shaders/PerPixelLighting_fragment.txt) =================================================================== --- branches/agate3d-3.2/Tests/Data/shaders/glsl/PerPixelLighting_fragment.txt (rev 0) +++ branches/agate3d-3.2/Tests/Data/shaders/glsl/PerPixelLighting_fragment.txt 2009-05-07 04:17:58 UTC (rev 958) @@ -0,0 +1,40 @@ +varying vec4 diffuse,ambientGlobal, ambient; +varying vec3 normal,lightDir,halfVector; +varying float dist; +uniform sampler2D texture0; + + +void main() +{ + vec3 n,halfV,viewV,ldir; + float NdotL,NdotHV; + vec4 color = ambientGlobal; + float att; + + /* a fragment shader can't write a varying variable, hence we need + a new variable to store the normalized interpolated normal */ + n = normalize(normal); + + /* compute the dot product between normal and normalized lightdir */ + NdotL = max(dot(n,normalize(lightDir)),0.0); + + if (NdotL > 0.0) { + att = 1.0 / (gl_LightSource[0].constantAttenuation + + gl_LightSource[0].linearAttenuation * dist + + gl_LightSource[0].quadraticAttenuation * dist * dist); + + color += att * (diffuse * NdotL + ambient); + + halfV = normalize(halfVector); + NdotHV = max(dot(n,halfV),0.0); + color += att * gl_FrontMaterial.specular * gl_LightSource[0].specular * + pow(NdotHV,gl_FrontMaterial.shininess); + } + + vec4 texcolor = texture2D(texture0,gl_TexCoord[0].st); + + color.rgb *= texcolor.rgb; + + gl_FragColor = color; +} + Copied: branches/agate3d-3.2/Tests/Data/shaders/glsl/PerPixelLighting_vertex.txt (from rev 924, branches/agate3d-3.2/Tests/Data/shaders/PerPixelLighting_vertex.txt) =================================================================== --- branches/agate3d-3.2/Tests/Data/shaders/glsl/PerPixelLighting_vertex.txt (rev 0) +++ branches/agate3d-3.2/Tests/Data/shaders/glsl/PerPixelLighting_vertex.txt 2009-05-07 04:17:58 UTC (rev 958) @@ -0,0 +1,31 @@ +varying vec4 diffuse,ambientGlobal,ambient; +varying vec3 normal,lightDir,halfVector; +varying float dist; + +void main() +{ + vec4 ecPos; + vec3 aux; + + normal = normalize(gl_NormalMatrix * gl_Normal); + + /* these are the new lines of code to compute the light's direction */ + ecPos = gl_ModelViewMatrix * gl_Vertex; + aux = vec3(gl_LightSource[0].position-ecPos); + lightDir = normalize(aux); + dist = length(aux); + + halfVector = normalize(gl_LightSource[0].halfVector.xyz); + + /* Compute the diffuse, ambient and globalAmbient terms */ + diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse; + + /* The ambient terms have been separated since one of them */ + /* suffers attenuation */ + ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient; + ambientGlobal = gl_LightModel.ambient * gl_FrontMaterial.ambient; + + + gl_Position = ftransform(); + gl_TexCoord[0] = gl_MultiTexCoord0; +} Copied: branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_fragment.txt (from rev 924, branches/agate3d-3.2/Tests/Data/shaders/PerPixelLighting_fragment.txt) =================================================================== --- branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_fragment.txt (rev 0) +++ branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_fragment.txt 2009-05-07 04:17:58 UTC (rev 958) @@ -0,0 +1,40 @@ +varying vec4 diffuse,ambientGlobal, ambient; +varying vec3 normal,lightDir,halfVector; +varying float dist; +uniform sampler2D texture0; + + +void main() +{ + vec3 n,halfV,viewV,ldir; + float NdotL,NdotHV; + vec4 color = ambientGlobal; + float att; + + /* a fragment shader can't write a varying variable, hence we need + a new variable to store the normalized interpolated normal */ + n = normalize(normal); + + /* compute the dot product between normal and normalized lightdir */ + NdotL = max(dot(n,normalize(lightDir)),0.0); + + if (NdotL > 0.0) { + att = 1.0 / (gl_LightSource[0].constantAttenuation + + gl_LightSource[0].linearAttenuation * dist + + gl_LightSource[0].quadraticAttenuation * dist * dist); + + color += att * (diffuse * NdotL + ambient); + + halfV = normalize(halfVector); + NdotHV = max(dot(n,halfV),0.0); + color += att * gl_FrontMaterial.specular * gl_LightSource[0].specular * + pow(NdotHV,gl_FrontMaterial.shininess); + } + + vec4 texcolor = texture2D(texture0,gl_TexCoord[0].st); + + color.rgb *= texcolor.rgb; + + gl_FragColor = color; +} + Copied: branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_vertex.txt (from rev 924, branches/agate3d-3.2/Tests/Data/shaders/PerPixelLighting_vertex.txt) =================================================================== --- branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_vertex.txt (rev 0) +++ branches/agate3d-3.2/Tests/Data/shaders/hlsl/PerPixelLighting_vertex.txt 2009-05-07 04:17:58 UTC (rev 958) @@ -0,0 +1,31 @@ +varying vec4 diffuse,ambientGlobal,ambient; +varying vec3 normal,lightDir,halfVector; +varying float dist; + +void main() +{ + vec4 ecPos; + vec3 aux; + + normal = normalize(gl_NormalMatrix * gl_Normal); + + /* these are the new lines of code to compute the light's direction */ + ecPos = gl_ModelViewMatrix * gl_Vertex; + aux = vec3(gl_LightSource[0].position-ecPos); + lightDir = normalize(aux); + dist = length(aux); + + halfVector = normalize(gl_LightSource[0].halfVector.xyz); + + /* Compute the diffuse, ambient and globalAmbient terms */ + diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse; + + /* The ambient terms have been separated since one of them */ + /* suffers attenuation */ + ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient; + ambientGlobal = gl_LightModel.ambient * gl_FrontMaterial.ambient; + + + gl_Position = ftransform(); + gl_TexCoord[0] = gl_MultiTexCoord0; +} Modified: branches/agate3d-3.2/Tests/Display3D/Glsl.cs =================================================================== --- branches/agate3d-3.2/Tests/Display3D/Glsl.cs 2009-05-07 02:02:28 UTC (rev 957) +++ branches/agate3d-3.2/Tests/Display3D/Glsl.cs 2009-05-07 04:17:58 UTC (rev 958) @@ -19,7 +19,7 @@ public string Name { - get { return "Glsl"; } + get { return "Glsl (OpenGL only)"; } } public string Category @@ -85,13 +85,9 @@ double frequency = 2 * Math.PI / 5; const float size = 25; - //var shader = ShaderCompiler.CompileShader(ShaderLanguage.Glsl, - // Shaders.PerPixelLighting_vertex, Shaders.PerPixelLighting_fragment); var shader = ShaderCompiler.CompileShader(ShaderLanguage.Glsl, - File.ReadAllText("Data/shaders/BumpMap_vertex.txt"), - File.ReadAllText("Data/shaders/BumpMap_fragment.txt")); - //var shader = ShaderCompiler.CompileShader(ShaderLanguage.Glsl, - // Shaders.BumpMap_vertex, Shaders.PerPixelLighting_fragment); + File.ReadAllText("Data/shaders/glsl/BumpMap_vertex.txt"), + File.ReadAllText("Data/shaders/glsl/BumpMap_fragment.txt")); //HeightMapTerrain b = new HeightMapTerrain(height.ReadPixels()); //b.Width = size; Copied: branches/agate3d-3.2/Tests/Display3D/Hlsl.cs (from rev 925, branches/agate3d-3.2/Tests/Display3D/Glsl.cs) =================================================================== --- branches/agate3d-3.2/Tests/Display3D/Hlsl.cs (rev 0) +++ branches/agate3d-3.2/Tests/Display3D/Hlsl.cs 2009-05-07 04:17:58 UTC (rev 958) @@ -0,0 +1,186 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using AgateLib; +using AgateLib.Geometry.Builders; +using AgateLib.DisplayLib; +using AgateLib.DisplayLib.Shaders; +using AgateLib.Geometry; +using AgateLib.InputLib; + +namespace Tests.Display3D.Glsl +{ + public class Hlsl: IAgateTest + { + #region IAgateTest Members + + public string Name + { + get { return "Hlsl (Direct3D only)"; } + } + + public string Category + { + get { return "Display 3D"; } + } + + void IAgateTest.Main(string[] args) + { + Run(args); + } + + #endregion + + bool rotating = false; + const float velocity = 0.04f; + const float mousevelocity = 0.004f; + float theta = (float)Math.PI / 2; + float phi = (float)-Math.PI / 2; + Vector3 eye = new Vector3(0, 70, 20); + Vector3 up = new Vector3(0, 0, 1); + DisplayWindow wind; + + Vector3 lookDir + { + get { return Vector3.FromPolar(1, theta, phi); } + } + Vector2 centerPoint + { + get { return new Vector2(wind.Width / 2, wind.Height / 2); } + } + void resetmouse() + { + Mouse.Position = new Point(wind.Width / 2, wind.Height / 2); + } + private void Run(string[] args) + { + using (AgateSetup setup = new AgateSetup(args)) + { + setup.Initialize(true, false, false); + if (setup.WasCanceled) + return; + + wind = DisplayWindow.CreateWindowed("GLSL", 800, 600); + Mouse.MouseDown += new InputEventHandler(Mouse_MouseDown); + + FontSurface font = new FontSurface("Arial", 14.0f); + + Surface texture = new Surface("bg-bricks.png"); + Surface height = new Surface("bg-bricks-heightmap.png"); + //Surface height = new Surface("jellybean.png"); + + LightManager m = new LightManager(); + m.AddPointLight(new Vector3(0, 0, 0), Color.White); + m.Enabled = true; + m.Ambient = Color.FromArgb(0, 255, 0); + m[0].AttenuationConstant = 0.0001f; + m[0].AttenuationLinear = 0.004f; + m[0].AttenuationQuadratic = 0.0001f; + m[0].Range = 200; + + double time = 0; + double frequency = 2 * Math.PI / 5; + const float size = 25; + + var shader = ShaderCompiler.CompileShader(ShaderLanguage.Glsl, + File.ReadAllText("Data/shaders/glsl/BumpMap_vertex.txt"), + File.ReadAllText("Data/shaders/glsl/BumpMap_fragment.txt")); + + //HeightMapTerrain b = new HeightMapTerrain(height.ReadPixels()); + //b.Width = size; + //b.Height = size; + //b.MaxPeak = 1; + CubeBuilder b = new CubeBuilder(); + //b.VertexType = VertexLayout.PositionNormalTangentBitangentTexture; + b.Length = size; + b.CreateVertexBuffer(); + + IndexBuffer index = b.IndexBuffer; + VertexBuffer buffer = b.VertexBuffer; + buffer.Textures[0] = texture; + buffer.Textures[1] = new Surface( + PixelBuffer.NormalMapFromHeightMap(height.ReadPixels(), 2.0f)); + buffer.Textures[1].SaveTo("normal.png"); + + + resetmouse(); + Mouse.Hide(); + + while (wind.IsClosed == false) + { + if (Core.IsActive) + { + Vector3 move = lookDir * velocity * Display.DeltaTime; + Vector3 strafe = Vector3.CrossProduct(move, up).Normalize() * velocity * Display.DeltaTime; + Vector3 fly = new Vector3(0, 0, velocity * Display.DeltaTime); + + if (Keyboard.Keys[KeyCode.W]) eye += move; + else if (Keyboard.Keys[KeyCode.S]) eye -= move; + + if (Keyboard.Keys[KeyCode.A]) eye -= strafe; + else if (Keyboard.Keys[KeyCode.D]) eye += strafe; + + if (Keyboard.Keys[KeyCode.Q]) eye += fly; + else if (Keyboard.Keys[KeyCode.E]) eye -= fly; + + if (Keyboard.Keys[KeyCode.Escape]) + return; + + Vector2 mouseDiff = new Vector2(Mouse.X, Mouse.Y) - centerPoint; + + theta += mouseDiff.Y * mousevelocity; + phi -= mouseDiff.X * mousevelocity; + resetmouse(); + + if (phi < -Math.PI) phi += (float)(Math.PI * 2); + if (phi > Math.PI) phi -= (float)(Math.PI * 2); + if (theta < 0) theta = 0; + if (theta > Math.PI) theta = (float)Math.PI; + } + + if (rotating) + { + time += Display.DeltaTime / 1000.0; + } + + Display.BeginFrame(); + Display.Clear(Color.Gray); + + Display.Shader = shader; + + Display.MatrixProjection = Matrix4.Projection(45f, wind.Width / (float)wind.Height, 1.0f, 1000f); + Display.MatrixWorld = Matrix4.Identity; + Display.MatrixView = Matrix4.Identity; + + Display.MatrixView = Matrix4.LookAt(eye, eye + lookDir, up); + + m[0].Position = eye; + m.DoLighting(); + + Display.MatrixWorld = + Matrix4.Translation(-size / 2, -size / 2, 0) * Matrix4.RotateZ((float)(frequency * time)); + + buffer.DrawIndexed(index); + + Debug.Print("x, y, z = {0}", eye.ToString()); + Debug.Print("angle = {0}", phi * 180 / Math.PI); + + Display.EndFrame(); + Core.KeepAlive(); + } + } + } + + void Mouse_MouseDown(InputEventArgs e) + { + if (e.MouseButtons == Mouse.MouseButtons.Secondary) + { + rotating = !rotating; + } + } + + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-05-07 02:02:34
|
Revision: 957 http://agate.svn.sourceforge.net/agate/?rev=957&view=rev Author: kanato Date: 2009-05-07 02:02:28 +0000 (Thu, 07 May 2009) Log Message: ----------- Revert matrices test to be what was intended. Modified Paths: -------------- branches/agate3d-3.2/Tests/Display3D/Matrices.cs Modified: branches/agate3d-3.2/Tests/Display3D/Matrices.cs =================================================================== --- branches/agate3d-3.2/Tests/Display3D/Matrices.cs 2009-05-07 02:01:18 UTC (rev 956) +++ branches/agate3d-3.2/Tests/Display3D/Matrices.cs 2009-05-07 02:02:28 UTC (rev 957) @@ -84,6 +84,8 @@ while (wind.IsClosed == false) { + //System.Threading.Thread.Sleep(1000); + Vector3 lookDirection = CalculateLookDirection(facingAngle); if (move != 0) @@ -116,7 +118,7 @@ break; case 1: - myproj = Matrix4.Projection(45, wind.Width / (float)wind.Height, 1f, 1000f); + myproj = Matrix4.Projection(45, wind.Width / (float)wind.Height, 1f, 100f); myview = Matrix4.LookAt(position, lookTarget, new Vector3(0, 0, 1)); @@ -156,7 +158,6 @@ } Display.DrawRect(new Rectangle(0, 0, 8, 8), Color.Black); - //s.Draw(); b.DrawIndexed(indices); Display.EndFrame(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-05-07 02:01:23
|
Revision: 956 http://agate.svn.sourceforge.net/agate/?rev=956&view=rev Author: kanato Date: 2009-05-07 02:01:18 +0000 (Thu, 07 May 2009) Log Message: ----------- Fix Z-buffer issue. Remove reference to crappy ID3DXLine object Modified Paths: -------------- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs Modified: branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs =================================================================== --- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs 2009-05-05 07:38:07 UTC (rev 955) +++ branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs 2009-05-07 02:01:18 UTC (rev 956) @@ -46,9 +46,7 @@ private bool mInitialized = false; // variables for drawing primitives - Direct3D.Line mLine; - - //Vector2[] mDrawLinePts = new Vector2[4]; + CustomVertex.PositionColored[] mLines = new CustomVertex.PositionColored[5]; CustomVertex.PositionColored[] mFillRectVerts = new CustomVertex.PositionColored[6]; private bool mVSync = true; @@ -82,9 +80,6 @@ // ok, create D3D device PresentParameters present = CreateWindowedPresentParameters(window, 0, 0); - present.BackBufferWidth = 1; - present.BackBufferHeight = 1; - DeviceType dtype = DeviceType.Hardware; int adapterOrdinal = Direct3D.Manager.Adapters.Default.Adapter; @@ -127,9 +122,6 @@ mDevice = new D3DDevice(device); - // create primitive objects - mLine = new Direct3D.Line(device); - } private void SetHaveDepthStencil(DepthFormat depthFormat) @@ -159,12 +151,6 @@ public override void Dispose() { - if (mLine != null) - { - mLine.Dispose(); - mLine = null; - } - mDevice.Dispose(); } @@ -187,7 +173,6 @@ private void OnDeviceReset() { - mLine = new Line(mDevice.Device); System.Diagnostics.Debug.Print("{0} Device Reset", DateTime.Now); if (DeviceReset != null) @@ -195,12 +180,6 @@ } private void OnDeviceLost() { - if (mLine != null) - { - mLine.Dispose(); - mLine = null; - } - System.Diagnostics.Debug.Print("{0} Device Lost", DateTime.Now); if (DeviceLost != null) @@ -208,13 +187,6 @@ } private void OnDeviceAboutToReset() { - if (mLine != null) - { - mLine.Dispose(); - mLine = null; - } - - System.Diagnostics.Debug.Print("{0} Device About to Reset", DateTime.Now); if (DeviceAboutToReset != null) @@ -372,6 +344,18 @@ mDevice.DrawBuffer.Flush(); mDevice.Clear(ClearFlags, color.ToArgb(), mDepthClear, mStencilClear); + + var device = mDevice.Device; + + device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, color.ToArgb(), 1.0f, 0); + + device.Clear(ClearFlags.Target, color.ToArgb(), 0, 0); + device.Clear(ClearFlags.ZBuffer, 0, 1.0f, 0); + + System.Drawing.Rectangle[] rect = new System.Drawing.Rectangle[1]; + rect[0] = new System.Drawing.Rectangle(0, 0, 800, 600); + device.Clear(ClearFlags.ZBuffer, color.ToArgb(), 1.0f, 0, rect); + } public override void Clear(Color color, Rectangle rect) { @@ -392,31 +376,26 @@ { mDevice.DrawBuffer.Flush(); - Vector2[] pts = new Vector2[2]; + mLines[0] = new CustomVertex.PositionColored(a.X, a.Y, 0, color.ToArgb()); + mLines[1] = new CustomVertex.PositionColored(b.X, b.Y, 0, color.ToArgb()); - pts[0] = new Vector2(a.X, a.Y); - pts[1] = new Vector2(b.X, b.Y); - - - mLine.Begin(); - mLine.Draw(pts, color.ToArgb()); - mLine.End(); - + mDevice.VertexFormat = CustomVertex.PositionColored.Format; + mDevice.Device.DrawUserPrimitives(Microsoft.DirectX.Direct3D.PrimitiveType.LineList, 1, mLines); } public override void DrawLines(Point[] pt, Color color) { mDevice.DrawBuffer.Flush(); - Vector2[] pts = new Vector2[pt.Length]; + if (pt.Length > mLines.Length) + mLines = new CustomVertex.PositionColored[pt.Length]; for (int i = 0; i < pt.Length; i++) - pts[i] = new Vector2(pt[i].X, pt[i].Y); + { + mLines[i] = new CustomVertex.PositionColored(pt[i].X, pt[i].Y, 0, color.ToArgb()); + } - - mLine.Begin(); - mLine.Draw(pts, color.ToArgb()); - mLine.End(); - + mDevice.VertexFormat = CustomVertex.PositionColored.Format; + mDevice.Device.DrawUserPrimitives(Direct3D.PrimitiveType.LineList, pt.Length / 2, mLines); } public override void DrawRect(Rectangle rect, Color color) { @@ -426,17 +405,16 @@ { mDevice.DrawBuffer.Flush(); - Microsoft.DirectX.Vector3[] pts = new Microsoft.DirectX.Vector3[5]; + int c = color.ToArgb(); - pts[0] = new Microsoft.DirectX.Vector3(rect.X, rect.Y, 0); - pts[1] = new Microsoft.DirectX.Vector3(rect.X + rect.Width, rect.Y, 0); - pts[2] = new Microsoft.DirectX.Vector3(rect.X + rect.Width, rect.Y + rect.Height, 0); - pts[3] = new Microsoft.DirectX.Vector3(rect.X, rect.Y + rect.Height, 0); - pts[4] = pts[0]; - - mLine.Begin(); - mLine.DrawTransform(pts, GetTotalTransform(), color.ToArgb()); - mLine.End(); + mLines[0] = new CustomVertex.PositionColored(rect.X, rect.Y, 0, c); + mLines[1] = new CustomVertex.PositionColored(rect.Right, rect.Y, 0, c); + mLines[2] = new CustomVertex.PositionColored(rect.Right, rect.Bottom, 0, c); + mLines[3] = new CustomVertex.PositionColored(rect.X, rect.Bottom, 0, c); + mLines[4] = new CustomVertex.PositionColored(rect.X, rect.Y, 0, c); + + mDevice.VertexFormat = CustomVertex.PositionColored.Format; + mDevice.Device.DrawUserPrimitives(Direct3D.PrimitiveType.LineStrip, 4, mLines); } public override void FillRect(Rectangle rect, Color color) @@ -969,6 +947,10 @@ } set { + //value = Matrix4.Projection(45, 800 / 600f, 1f, 1000f); + var x = Microsoft.DirectX.Matrix.PerspectiveFovRH( + (float)(45 * Math.PI / 180), 800 / 600f, 1f, 1000f); + projection = value; mDevice.Device.SetTransform(TransformType.Projection, TransformAgateMatrix(value)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-05-05 07:38:15
|
Revision: 955 http://agate.svn.sourceforge.net/agate/?rev=955&view=rev Author: kanato Date: 2009-05-05 07:38:07 +0000 (Tue, 05 May 2009) Log Message: ----------- Add HScrollBar and VScrollBar. Modified Paths: -------------- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/MercuryScheme.cs Added Paths: ----------- branches/gui-3.2/AgateLib/Gui/HScrollBar.cs branches/gui-3.2/AgateLib/Gui/VScrollBar.cs Added: branches/gui-3.2/AgateLib/Gui/HScrollBar.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/HScrollBar.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/HScrollBar.cs 2009-05-05 07:38:07 UTC (rev 955) @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AgateLib.Gui +{ + public class HScrollBar : Widget + { + } +} Modified: branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/MercuryScheme.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/MercuryScheme.cs 2009-05-05 07:31:44 UTC (rev 954) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/MercuryScheme.cs 2009-05-05 07:38:07 UTC (rev 955) @@ -153,7 +153,6 @@ return retval.ToArray(); } - public int InsertionPointHeight { get { return WidgetFont.FontHeight - 2; } Added: branches/gui-3.2/AgateLib/Gui/VScrollBar.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/VScrollBar.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/VScrollBar.cs 2009-05-05 07:38:07 UTC (rev 955) @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AgateLib.Gui +{ + public class VScrollBar : Widget + { + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-05-05 07:31:53
|
Revision: 954 http://agate.svn.sourceforge.net/agate/?rev=954&view=rev Author: kanato Date: 2009-05-05 07:31:44 +0000 (Tue, 05 May 2009) Log Message: ----------- Add base code for ComboBox and ListBox. Modified Paths: -------------- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/MercuryScheme.cs Added Paths: ----------- branches/gui-3.2/AgateLib/Gui/ComboBox.cs branches/gui-3.2/AgateLib/Gui/ListBox.cs Added: branches/gui-3.2/AgateLib/Gui/ComboBox.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ComboBox.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/ComboBox.cs 2009-05-05 07:31:44 UTC (rev 954) @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AgateLib.Gui +{ + class ComboBox : Widget + { + } +} Added: branches/gui-3.2/AgateLib/Gui/ListBox.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ListBox.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/ListBox.cs 2009-05-05 07:31:44 UTC (rev 954) @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AgateLib.Gui +{ + public class ListBox : Widget + { + } +} Modified: branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/MercuryScheme.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/MercuryScheme.cs 2009-05-05 07:24:02 UTC (rev 953) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/MercuryScheme.cs 2009-05-05 07:31:44 UTC (rev 954) @@ -16,6 +16,7 @@ MercuryCheckBox mCheckBox = new MercuryCheckBox(); MercuryCheckBox mRadioButton = new MercuryCheckBox(); MercuryTextBox mTextBox = new MercuryTextBox(); + MercuryListBox mListBox = new MercuryListBox(); private MercuryScheme() { @@ -40,7 +41,7 @@ FontColorDisabled = Color.Gray; DropShadowSize = 10; - SelectionColor = Color.Black; + SelectionFontColor = Color.Black; SelectionBackColor = Color.Yellow; Window.NoTitle = new Surface(files, "window_no_title.png"); @@ -175,7 +176,7 @@ public Color FontColor { get; set; } public Color FontColorDisabled { get; set; } - public Color SelectionColor { get; set; } + public Color SelectionFontColor { get; set; } public Color SelectionBackColor { get; set; } public MercuryWindow Window @@ -205,6 +206,15 @@ mTextBox = value; } } + public MercuryListBox ListBox + { + get { return mListBox; } + set + { + if (value == null) throw new ArgumentNullException(); + mListBox = value; + } + } public MercuryCheckBox CheckBox { get { return mCheckBox; } @@ -271,7 +281,20 @@ { Margin = 3; } + } + public class MercuryListBox + { + public Surface Image { get; set; } + public Surface Disabled { get; set; } + public Surface Hover { get; set; } + public Surface Focus { get; set; } + public Rectangle StretchRegion { get; set; } + public int Margin { get; set; } + public MercuryListBox() + { + Margin = 3; + } } public class MercuryCheckBox { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-05-05 07:24:15
|
Revision: 953 http://agate.svn.sourceforge.net/agate/?rev=953&view=rev Author: kanato Date: 2009-05-05 07:24:02 +0000 (Tue, 05 May 2009) Log Message: ----------- Add selection color properties. Modified Paths: -------------- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/MercuryScheme.cs Modified: branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/MercuryScheme.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/MercuryScheme.cs 2009-05-05 07:19:12 UTC (rev 952) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/MercuryScheme.cs 2009-05-05 07:24:02 UTC (rev 953) @@ -17,7 +17,7 @@ MercuryCheckBox mRadioButton = new MercuryCheckBox(); MercuryTextBox mTextBox = new MercuryTextBox(); - public MercuryScheme() + private MercuryScheme() { } @@ -40,6 +40,9 @@ FontColorDisabled = Color.Gray; DropShadowSize = 10; + SelectionColor = Color.Black; + SelectionBackColor = Color.Yellow; + Window.NoTitle = new Surface(files, "window_no_title.png"); Window.WithTitle = new Surface(files, "window_client.png"); Window.TitleBar = new Surface(files, "window_titlebar.png"); @@ -50,7 +53,6 @@ SetButtonImages(new Surface(files, "button.png"), new Size(64, 32)); Button.StretchRegion = new Rectangle(6, 6, 52, 20); - SetCheckBoxImages(new Surface(files, "checkbox.png"), new Size(16, 16)); SetRadioButtonImages(new Surface(files, "radiobutton.png"), new Size(16, 16)); @@ -173,6 +175,8 @@ public Color FontColor { get; set; } public Color FontColorDisabled { get; set; } + public Color SelectionColor { get; set; } + public Color SelectionBackColor { get; set; } public MercuryWindow Window { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-05-05 07:19:17
|
Revision: 952 http://agate.svn.sourceforge.net/agate/?rev=952&view=rev Author: kanato Date: 2009-05-05 07:19:12 +0000 (Tue, 05 May 2009) Log Message: ----------- Selection with mouse in textbox works. Modified Paths: -------------- branches/gui-3.2/AgateLib/Gui/IGuiThemeEngine.cs branches/gui-3.2/AgateLib/Gui/TextBox.cs branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs Modified: branches/gui-3.2/AgateLib/Gui/IGuiThemeEngine.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/IGuiThemeEngine.cs 2009-05-05 07:12:56 UTC (rev 951) +++ branches/gui-3.2/AgateLib/Gui/IGuiThemeEngine.cs 2009-05-05 07:19:12 UTC (rev 952) @@ -63,5 +63,9 @@ void Update(GuiRoot guiRoot); void MouseDownInWidget(Widget widget, Point clientLocation); + + void MouseMoveInWidget(Widget widget, Point clientLocation); + + void MouseUpInWidget(Widget widget, Point clientLocation); } } Modified: branches/gui-3.2/AgateLib/Gui/TextBox.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/TextBox.cs 2009-05-05 07:12:56 UTC (rev 951) +++ branches/gui-3.2/AgateLib/Gui/TextBox.cs 2009-05-05 07:19:12 UTC (rev 952) @@ -36,6 +36,7 @@ SelectionStart = InsertionPoint; mInsertionPoint = newLoc; + ResetIPBlinking(); if (expandSel) ExpandSelection(); @@ -51,6 +52,23 @@ Root.ThemeEngine.MouseDownInWidget(this, PointToClient(e.MousePosition)); } } + protected internal override void SendMouseMove(InputEventArgs e) + { + base.SendMouseMove(e); + if (Root != null) + { + Root.ThemeEngine.MouseMoveInWidget(this, PointToClient(e.MousePosition)); + } + } + protected internal override void SendMouseUp(InputEventArgs e) + { + base.SendMouseUp(e); + if (Root != null) + { + Root.ThemeEngine.MouseUpInWidget(this, PointToClient(e.MousePosition)); + } + } + protected internal override void SendKeyDown(AgateLib.InputLib.InputEventArgs e) { ResetIPBlinking(); Modified: branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs 2009-05-05 07:12:56 UTC (rev 951) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs 2009-05-05 07:19:12 UTC (rev 952) @@ -104,14 +104,42 @@ public void MouseDownInWidget(Widget widget, Point clientLocation) { if (widget is TextBox) MouseDownInTextBox((TextBox)widget, clientLocation); - } + public void MouseMoveInWidget(Widget widget, Point clientLocation) + { + if (widget is TextBox) MouseMoveInTextBox((TextBox)widget, clientLocation); + } + public void MouseUpInWidget(Widget widget, Point clientLocation) + { + if (widget is TextBox) MouseUpInTextBox((TextBox)widget, clientLocation); + } + #endregion #region --- TextBox --- + + private void MouseDownInTextBox(TextBox textBox, Point clientLocation) + { + textBox.MoveInsertionPoint( + TextBoxClientToTextLocation(textBox, clientLocation), false); + + } + private void MouseMoveInTextBox(TextBox textBox, Point clientLocation) + { + if (textBox.MouseDownIn) + { + textBox.MoveInsertionPoint( + TextBoxClientToTextLocation(textBox, clientLocation), true); + } + } + private void MouseUpInTextBox(TextBox textBox, Point clientLocation) + { + + } + private static TextBoxCache GetTextBoxCache(TextBox textBox) { if (textBox.Cache == null) @@ -234,11 +262,6 @@ } } - private void MouseDownInTextBox(TextBox textBox, Point clientLocation) - { - textBox.MoveInsertionPoint( - TextBoxClientToTextLocation(textBox, clientLocation), false); - } private int TextBoxClientToTextLocation(TextBox textBox, Point clientLocation) { TextBoxCache c = GetTextBoxCache(textBox); @@ -810,10 +833,5 @@ Scheme.WidgetFont.Color = Scheme.FontColorDisabled; } - #region IGuiThemeEngine Members - - - - #endregion } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-05-05 07:13:01
|
Revision: 951 http://agate.svn.sourceforge.net/agate/?rev=951&view=rev Author: kanato Date: 2009-05-05 07:12:56 +0000 (Tue, 05 May 2009) Log Message: ----------- Add Textboxes.cs test. Modified Paths: -------------- branches/gui-3.2/Tests/frmLauncher.Designer.cs Added Paths: ----------- branches/gui-3.2/Tests/GuiTests/Textboxes.cs Added: branches/gui-3.2/Tests/GuiTests/Textboxes.cs =================================================================== --- branches/gui-3.2/Tests/GuiTests/Textboxes.cs (rev 0) +++ branches/gui-3.2/Tests/GuiTests/Textboxes.cs 2009-05-05 07:12:56 UTC (rev 951) @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib; +using AgateLib.Gui; + +namespace Tests.GuiTests +{ + class Textboxes: AgateApplication , IAgateTest + { + #region IAgateTest Members + + public string Name + { + get { return "Textboxes"; } + } + + public string Category + { + get { return "Gui"; } + } + + public void Main(string[] args) + { + Run(args); + } + + #endregion + + protected override void AdjustAppInitParameters(ref AppInitParameters initParams) + { + initParams.ShowSplashScreen = false; + } + protected override void Initialize() + { + this.GuiRoot = new GuiRoot(); + + Window wind = new Window("Textboxes test"); + wind.Size = new AgateLib.Geometry.Size(500, 400); + + TextBox b = new TextBox(); + b.Text = "This is a single line textbox."; + + wind.Children.Add(b); + + TextBox multi = new TextBox(); + multi.Text = "This is a multiline textbox.\nYou can enter multiple lines.\n" + + "In code, these lines are separated by the usual \"\\n\" character."; + + multi.MultiLine = true; + + wind.Children.Add(multi); + + this.GuiRoot.Children.Add(wind); + } + } +} Modified: branches/gui-3.2/Tests/frmLauncher.Designer.cs =================================================================== --- branches/gui-3.2/Tests/frmLauncher.Designer.cs 2009-05-05 07:11:43 UTC (rev 950) +++ branches/gui-3.2/Tests/frmLauncher.Designer.cs 2009-05-05 07:12:56 UTC (rev 951) @@ -38,7 +38,7 @@ | System.Windows.Forms.AnchorStyles.Right))); this.tree.Location = new System.Drawing.Point(12, 12); this.tree.Name = "tree"; - this.tree.Size = new System.Drawing.Size(275, 510); + this.tree.Size = new System.Drawing.Size(275, 559); this.tree.TabIndex = 0; this.tree.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.tree_NodeMouseDoubleClick); // @@ -46,7 +46,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(299, 534); + this.ClientSize = new System.Drawing.Size(299, 583); this.Controls.Add(this.tree); this.Name = "frmLauncher"; this.Text = "AgateLib Test Launcher"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-05-05 07:11:53
|
Revision: 950 http://agate.svn.sourceforge.net/agate/?rev=950&view=rev Author: kanato Date: 2009-05-05 07:11:43 +0000 (Tue, 05 May 2009) Log Message: ----------- Make MeasureString take a start parameter. Modified Paths: -------------- branches/gui-3.2/AgateLib/BitmapFont/BitmapFontImpl.cs branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs branches/gui-3.2/AgateLib/ImplementationBase/FontSurfaceImpl.cs branches/gui-3.2/Drivers/AgateDrawing/Drawing_FontSurface.cs branches/gui-3.2/Drivers/AgateMDX/MDX1_FontSurface.cs Modified: branches/gui-3.2/AgateLib/BitmapFont/BitmapFontImpl.cs =================================================================== --- branches/gui-3.2/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-05-05 07:10:24 UTC (rev 949) +++ branches/gui-3.2/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-05-05 07:11:43 UTC (rev 950) @@ -378,10 +378,10 @@ DrawText(destPt.X, destPt.Y, text); } - public override Size MeasureString(string text, int length) + public override Size MeasureString(string text, int start, int length) { - return new Size(StringDisplayWidth(text.Substring(0, length)), - StringDisplayHeight(text.Substring(0, length))); + return new Size(StringDisplayWidth(text.Substring(start, length)), + StringDisplayHeight(text.Substring(start, length))); } } Modified: branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs =================================================================== --- branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs 2009-05-05 07:10:24 UTC (rev 949) +++ branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs 2009-05-05 07:11:43 UTC (rev 950) @@ -282,7 +282,7 @@ /// </summary> /// <param name="text"></param> /// <returns></returns> - public Size StringDisplaySize(string text) { return MeasureString(text, text.Length); } + public Size StringDisplaySize(string text) { return MeasureString(text, 0, text.Length); } /// <summary> /// Measures the display size of the specified string. @@ -290,7 +290,10 @@ /// <param name="text"></param> /// <param name="length"></param> /// <returns></returns> - public Size MeasureString(string text, int length) { return impl.MeasureString(text, length); } + public Size MeasureString(string text, int start, int length) + { + return impl.MeasureString(text, start, length); + } /// <summary> /// Gets the height in pixels of a single line of text. /// </summary> @@ -436,5 +439,6 @@ #endregion + } } Modified: branches/gui-3.2/AgateLib/ImplementationBase/FontSurfaceImpl.cs =================================================================== --- branches/gui-3.2/AgateLib/ImplementationBase/FontSurfaceImpl.cs 2009-05-05 07:10:24 UTC (rev 949) +++ branches/gui-3.2/AgateLib/ImplementationBase/FontSurfaceImpl.cs 2009-05-05 07:11:43 UTC (rev 950) @@ -174,7 +174,7 @@ public abstract void Dispose(); - public abstract Size MeasureString(string text, int length); + public abstract Size MeasureString(string text, int start, int length); } } Modified: branches/gui-3.2/Drivers/AgateDrawing/Drawing_FontSurface.cs =================================================================== --- branches/gui-3.2/Drivers/AgateDrawing/Drawing_FontSurface.cs 2009-05-05 07:10:24 UTC (rev 949) +++ branches/gui-3.2/Drivers/AgateDrawing/Drawing_FontSurface.cs 2009-05-05 07:11:43 UTC (rev 950) @@ -128,9 +128,9 @@ } - public override AgateLib.Geometry.Size MeasureString(string text, int length) + public override AgateLib.Geometry.Size MeasureString(string text, int start, int length) { - return StringDisplaySize(text.Substring(0, length)); + return StringDisplaySize(text.Substring(start, length)); } } Modified: branches/gui-3.2/Drivers/AgateMDX/MDX1_FontSurface.cs =================================================================== --- branches/gui-3.2/Drivers/AgateMDX/MDX1_FontSurface.cs 2009-05-05 07:10:24 UTC (rev 949) +++ branches/gui-3.2/Drivers/AgateMDX/MDX1_FontSurface.cs 2009-05-05 07:11:43 UTC (rev 950) @@ -175,9 +175,9 @@ DrawText(new Point((int)dest_x, (int)dest_y), text); } - public override Size MeasureString(string text, int length) + public override Size MeasureString(string text, int start, int length) { - return StringDisplaySize(text.Substring(0, length)); + return StringDisplaySize(text.Substring(start, length)); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-05-05 07:10:33
|
Revision: 949 http://agate.svn.sourceforge.net/agate/?rev=949&view=rev Author: kanato Date: 2009-05-05 07:10:24 +0000 (Tue, 05 May 2009) Log Message: ----------- TextBox: Mouse clicks place insertion point in correct location. Text can be selected with cursor keys Modified Paths: -------------- branches/gui-3.2/AgateLib/Gui/Button.cs branches/gui-3.2/AgateLib/Gui/TextBox.cs branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs branches/gui-3.2/AgateLib/Gui/Widget.cs Modified: branches/gui-3.2/AgateLib/Gui/Button.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/Button.cs 2009-05-05 05:03:16 UTC (rev 948) +++ branches/gui-3.2/AgateLib/Gui/Button.cs 2009-05-05 07:10:24 UTC (rev 949) @@ -11,7 +11,6 @@ public Button() { Name = "Button"; } public Button(string text) { Name = text; Text = text; } - bool mouseDownIn = false; bool spaceDownFocus = false; public override bool CanHaveFocus @@ -23,7 +22,7 @@ } internal bool DrawActivated { - get { return mouseDownIn && MouseIn || spaceDownFocus; } + get { return MouseDownIn && MouseIn || spaceDownFocus; } } internal bool IsDefaultButton { @@ -57,21 +56,14 @@ base.OnKeyUp(e); } - protected internal override void OnMouseDown(InputEventArgs e) + protected internal override void SendMouseUp(InputEventArgs e) { - if (Enabled == false) - return; + if (MouseIn && MouseDownIn) + OnClick(); - mouseDownIn = true; + base.SendMouseUp(e); } - protected internal override void OnMouseUp(InputEventArgs e) - { - mouseDownIn = false; - if (MouseIn) - OnClick(); - } - private void OnClick() { if (Click != null) Modified: branches/gui-3.2/AgateLib/Gui/TextBox.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/TextBox.cs 2009-05-05 05:03:16 UTC (rev 948) +++ branches/gui-3.2/AgateLib/Gui/TextBox.cs 2009-05-05 07:10:24 UTC (rev 949) @@ -2,12 +2,15 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using AgateLib.InputLib; namespace AgateLib.Gui { public class TextBox : Widget { int mInsertionPoint; + int mSelectionStart; + int mSelectionLength; public override bool CanHaveFocus { @@ -16,13 +19,28 @@ public int InsertionPoint { get { return mInsertionPoint; } - set - { - if (value < 0) value = 0; - if (value > Text.Length) value = Text.Length; + } + /// <summary> + /// Moves the insertion point to a new location. + /// </summary> + /// <param name="newLoc">The new location of the insertion point. This must be between 0 + /// and Text.Length, inclusive.</param> + /// <param name="expandSel">Pass true to expand the current selection to include text + /// up to the new location. Pass false to clear the selection.</param> + public void MoveInsertionPoint(int newLoc, bool expandSel) + { + if (newLoc < 0) newLoc = 0; + if (newLoc > Text.Length) newLoc = Text.Length; - mInsertionPoint = value; - } + if (SelectionLength == 0) + SelectionStart = InsertionPoint; + + mInsertionPoint = newLoc; + + if (expandSel) + ExpandSelection(); + else + SelectionLength = 0; } protected internal override void SendMouseDown(AgateLib.InputLib.InputEventArgs e) @@ -36,92 +54,185 @@ protected internal override void SendKeyDown(AgateLib.InputLib.InputEventArgs e) { ResetIPBlinking(); + base.SendKeyDown(e); switch (e.KeyCode) { - case AgateLib.InputLib.KeyCode.Shift: - case AgateLib.InputLib.KeyCode.ShiftLeft: - case AgateLib.InputLib.KeyCode.ShiftRight: - case AgateLib.InputLib.KeyCode.Control: - case AgateLib.InputLib.KeyCode.ControlLeft: - case AgateLib.InputLib.KeyCode.ControlRight: - case AgateLib.InputLib.KeyCode.Alt: - case AgateLib.InputLib.KeyCode.CapsLock: + case KeyCode.Shift: + case KeyCode.ShiftLeft: + case KeyCode.ShiftRight: + case KeyCode.Control: + case KeyCode.ControlLeft: + case KeyCode.ControlRight: + case KeyCode.Alt: + case KeyCode.CapsLock: return; - case AgateLib.InputLib.KeyCode.Left: - InsertionPoint--; + case KeyCode.Escape: + DeleteSelectedText(); break; - case AgateLib.InputLib.KeyCode.Right: - InsertionPoint++; + case KeyCode.Up: + TypeUp(); break; - case AgateLib.InputLib.KeyCode.Home: - InsertionPoint = 0; + case KeyCode.Down: + TypeDown(); break; - case AgateLib.InputLib.KeyCode.End: - InsertionPoint = Text.Length; + case KeyCode.Left: + TypeLeft(); break; - case AgateLib.InputLib.KeyCode.BackSpace: - if (InsertionPoint == 0) - break; + case KeyCode.Right: + TypeRight(); + break; - if (InsertionPoint == Text.Length) - { - InsertionPoint--; - Text = Text.Substring(0, Text.Length - 1); - } - else - { - InsertionPoint--; - Text = Text.Substring(0, InsertionPoint) + Text.Substring(InsertionPoint + 1); - } + case KeyCode.Home: + TypeHome(); + break; + case KeyCode.End: + TypeEnd(); break; - case AgateLib.InputLib.KeyCode.Delete: - if (InsertionPoint == Text.Length) - break; - else if (InsertionPoint == 0) - Text = Text.Substring(1); - else - Text = Text.Substring(0, InsertionPoint) + Text.Substring(InsertionPoint + 1); + case KeyCode.BackSpace: + TypeBackspace(); break; + case KeyCode.Delete: + TypeDelete(); + break; + default: - if (InsertionPoint == Text.Length) - Text += e.KeyString; - else if (InsertionPoint == 0) - Text = e.KeyString + Text; - else - Text = Text.Substring(0, InsertionPoint) + e.KeyString + Text.Substring(InsertionPoint); - - InsertionPoint++; - + TypeKey(e.KeyString); break; } SetDirty(); } + + private bool ShiftKey + { + get + { + return Keyboard.Keys[KeyCode.Shift] || + Keyboard.Keys[KeyCode.ShiftLeft] || + Keyboard.Keys[KeyCode.ShiftRight]; + } + } + private void TypeKey(string key) + { + if (SelectionLength > 0) + { + ReplaceSelectedText(key); + return; + } + + if (InsertionPoint == Text.Length) + Text += key; + else if (InsertionPoint == 0) + Text = key + Text; + else + Text = Text.Substring(0, InsertionPoint) + key + Text.Substring(InsertionPoint); + + MoveInsertionPoint(InsertionPoint + 1, ShiftKey); + } + private void TypeDelete() + { + if (SelectionLength > 0) + { + DeleteSelectedText(); + return; + } + + if (InsertionPoint == Text.Length) + return; + + else if (InsertionPoint == 0) + Text = Text.Substring(1); + else + Text = Text.Substring(0, InsertionPoint) + Text.Substring(InsertionPoint + 1); + } + private void TypeEnd() + { + MoveInsertionPoint(Text.Length, ShiftKey); + } + private void TypeHome() + { + MoveInsertionPoint(0, ShiftKey); + } + private void TypeRight() + { + MoveInsertionPoint(InsertionPoint + 1, ShiftKey); + + if (Keyboard.Keys[KeyCode.Shift]) + ExpandSelection(); + } + private void TypeLeft() + { + MoveInsertionPoint(InsertionPoint - 1, ShiftKey); + } + private void TypeDown() + { + } + private void TypeUp() + { + } + private void TypeBackspace() + { + if (InsertionPoint == 0) + return; + + if (SelectionLength > 0) + { + DeleteSelectedText(); + return; + } + + if (InsertionPoint == Text.Length) + { + MoveInsertionPoint(InsertionPoint - 1, false); + Text = Text.Substring(0, Text.Length - 1); + } + else + { + MoveInsertionPoint(InsertionPoint - 1, false); + Text = Text.Substring(0, InsertionPoint) + Text.Substring(InsertionPoint + 1); + } + } + + private string TextBeforeSelection + { + get { return Text.Substring(0, SelectionStart); } + } + private string TextAfterSelection + { + get { return Text.Substring(SelectionEnd); } + } + protected internal override bool AcceptInputKey(AgateLib.InputLib.KeyCode keyCode) { switch (keyCode) { - case AgateLib.InputLib.KeyCode.Left: - case AgateLib.InputLib.KeyCode.Right: + case KeyCode.Left: + case KeyCode.Right: return true; - case AgateLib.InputLib.KeyCode.Up: - case AgateLib.InputLib.KeyCode.Down: - case AgateLib.InputLib.KeyCode.Enter: + case KeyCode.Up: + case KeyCode.Down: + case KeyCode.Enter: if (MultiLine) return true; else return false; + case KeyCode.Escape: + if (SelectionLength == 0) + return false; + else + return true; + default: return false; } @@ -136,23 +247,17 @@ { base.Text = value; - if (InsertionPoint > Text.Length) - InsertionPoint = Text.Length; + if (mInsertionPoint > Text.Length) + mInsertionPoint = Text.Length; + SelectionLength = 0; + ResetIPBlinking(); SetDirty(); } } - private void SetDirty() - { - if (Cache == null) - return; - - Cache.Dirty = true; - } - private void ResetIPBlinking() { IPTime = Timing.TotalMilliseconds; @@ -162,10 +267,77 @@ public bool MultiLine { get; set; } - protected internal override void OnEnabledChanged() + #region --- Selection properties and methods --- + + public int SelectionStart { - base.OnEnabledChanged(); - SetDirty(); + get { return mSelectionStart; } + set + { + if (value < 0) + throw new AgateGuiException( + "Selection start cannot be negative."); + if (value > Text.Length) + throw new AgateGuiException( + "Selection start cannot be larger than text length."); + + mSelectionStart = value; + } } + public int SelectionLength + { + get { return mSelectionLength; } + set + { + if (SelectionStart + value > Text.Length) + throw new AgateGuiException( + "The selection cannot extend past the length of the text."); + if (value < 0) + throw new AgateGuiException( + "The selection length cannot be less than zero."); + + mSelectionLength = value; + } + } + int SelectionEnd + { + get { return SelectionStart + SelectionLength; } + } + public string SelectedText + { + get { return Text.Substring(SelectionStart, SelectionLength); } + } + public void ReplaceSelectedText(string newText) + { + Text = TextBeforeSelection + newText + TextAfterSelection; + + SelectionLength = newText.Length; + MoveInsertionPoint(SelectionStart + SelectionLength, false); + } + public void DeleteSelectedText() + { + Text = TextBeforeSelection + TextAfterSelection; + + MoveInsertionPoint(SelectionStart, false); + SelectionLength = 0; + } + + /// <summary> + /// Expands the selection to include the current location of the insertion point. + /// </summary> + private void ExpandSelection() + { + if (InsertionPoint < SelectionStart) + { + SelectionLength += SelectionStart - InsertionPoint; + SelectionStart = InsertionPoint; + } + else if (InsertionPoint > SelectionStart) + { + SelectionLength = InsertionPoint - SelectionStart; + } + } + + #endregion } } Modified: branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs 2009-05-05 05:03:16 UTC (rev 948) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs 2009-05-05 07:10:24 UTC (rev 949) @@ -72,7 +72,7 @@ if (widget is Label) return CalcMinLabelSize((Label)widget); if (widget is Button) return CalcMinButtonSize((Button)widget); if (widget is CheckBox) return CalcMinCheckBoxSize((CheckBox)widget); - if (widget is TextBox) return CalcMinTextBoxSize((TextBox)widget); + if (widget is TextBox) return CalcTextBoxMinSize((TextBox)widget); if (widget is RadioButton) return CalcMinRadioButtonSize((RadioButton)widget); return Size.Empty; @@ -236,6 +236,11 @@ private void MouseDownInTextBox(TextBox textBox, Point clientLocation) { + textBox.MoveInsertionPoint( + TextBoxClientToTextLocation(textBox, clientLocation), false); + } + private int TextBoxClientToTextLocation(TextBox textBox, Point clientLocation) + { TextBoxCache c = GetTextBoxCache(textBox); clientLocation.X += c.Origin.X - Scheme.TextBox.StretchRegion.X; @@ -245,13 +250,31 @@ int last = 0; int index; - for (index = 1; index < textBox.Text.Length; index++) + int line = clientLocation.Y / Scheme.WidgetFont.FontHeight; + int linestart = 0; + for (index = 0; index < textBox.Text.Length; index++) { - sz = Scheme.WidgetFont.MeasureString(textBox.Text, index); + if (textBox.Text[index] == '\n') + { + line--; + linestart = index; + } + if (line == 0) + goto searchX; + } + + // we only get here if the mouse click was below the last line. + index = linestart; + + searchX: + for (; index < textBox.Text.Length; index++) + { + sz = Scheme.WidgetFont.MeasureString(textBox.Text, linestart, index - linestart); + if (sz.Width > clientLocation.X) { - goto found; + goto found; } last = sz.Width; @@ -263,11 +286,9 @@ // if it's halfway over, put the insertion on the right side of the character, // otherwise put it on the left. if (pass <= 0.5) - textBox.InsertionPoint = index; + return index; else - textBox.InsertionPoint = index - 1; - - return; + return index - 1; } /// <summary> @@ -277,18 +298,24 @@ /// <returns></returns> private Point InsertionPointLocation(TextBox textBox) { - Size sz = Scheme.WidgetFont.MeasureString(textBox.Text, textBox.InsertionPoint); + int lineStart = 0; + int lines = 0; - int lines = 0; if (textBox.MultiLine) { - for (int i = 0; i < textBox.Text.Length; i++) + for (int i = 0; i < textBox.InsertionPoint; i++) { if (textBox.Text[i] == '\n') + { + lineStart = i; lines++; + } } } + Size sz = Scheme.WidgetFont.StringDisplaySize( + textBox.Text.Substring(lineStart, textBox.InsertionPoint - lineStart)); + Point loc = new Point( sz.Width + Scheme.TextBox.StretchRegion.X, lines * Scheme.WidgetFont.FontHeight + Scheme.TextBox.StretchRegion.Y); @@ -319,7 +346,7 @@ Scheme.WidgetFont.Color); } - private Size CalcMinTextBoxSize(TextBox textBox) + private Size CalcTextBoxMinSize(TextBox textBox) { Size retval = new Size(); @@ -331,10 +358,13 @@ } private Size CalcTextBoxMaxSize(TextBox textBox) { - Size retval = CalcMinTextBoxSize(textBox); + Size retval = CalcTextBoxMinSize(textBox); retval.Width = 9000; + if (textBox.MultiLine) + retval.Height = 9000; + return retval; } Modified: branches/gui-3.2/AgateLib/Gui/Widget.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/Widget.cs 2009-05-05 05:03:16 UTC (rev 948) +++ branches/gui-3.2/AgateLib/Gui/Widget.cs 2009-05-05 07:10:24 UTC (rev 949) @@ -22,7 +22,8 @@ bool mEnabled = true; bool suspendLayout = false; - + bool mMouseDownIn = false; + public Widget() { mText = string.Empty; @@ -361,10 +362,36 @@ } public bool MouseIn { get; protected set; } - protected internal virtual void SendMouseDown(InputEventArgs e) { OnMouseDown(e); } - protected internal virtual void SendMouseUp(InputEventArgs e) { OnMouseUp(e); } - protected internal virtual void SendMouseMove(InputEventArgs e) { OnMouseMove(e); } - protected internal virtual void SendMouseDoubleClick(InputEventArgs e) { OnMouseDoubleClick(e); } + public bool MouseDownIn { get { return mMouseDownIn; } } + + protected internal virtual void SendMouseDown(InputEventArgs e) + { + if (Enabled == false) + return; + + mMouseDownIn = true; + OnMouseDown(e); + } + protected internal virtual void SendMouseUp(InputEventArgs e) + { + if (Enabled == false) + return; + + mMouseDownIn = false; + OnMouseUp(e); + } + protected internal virtual void SendMouseMove(InputEventArgs e) + { + if (Enabled == false) + return; + OnMouseMove(e); + } + protected internal virtual void SendMouseDoubleClick(InputEventArgs e) + { + if (Enabled == false) + return; + OnMouseDoubleClick(e); + } protected internal virtual void SendKeyDown(InputEventArgs e) { OnKeyDown(e); } protected internal virtual void SendKeyUp(InputEventArgs e) { OnKeyUp(e); } /// <summary> @@ -372,15 +399,39 @@ /// If overriding this, be sure to set MouseIn to true, and provide /// some logic for calling OnMouseEnter on the control. /// </summary> - protected internal virtual void SendMouseEnter() { MouseIn = true; OnMouseEnter(); } + protected internal virtual void SendMouseEnter() + { + MouseIn = true; + if (Enabled == false) + return; + OnMouseEnter(); + } /// <summary> /// Sends the MouseLeave event to this control. /// If overriding this, be sure to set MouseIn to false, and provide /// some logic for calling OnMouseLeave on the control. /// /// </summary> - protected internal virtual void SendMouseLeave() { MouseIn = false; OnMouseLeave(); } + protected internal virtual void SendMouseLeave() + { + MouseIn = false; + if (Enabled == false) + return; + OnMouseLeave(); + } + /// <summary> + /// Sets the dirty flag in the cache so that it is updated on the next + /// frame. + /// </summary> + protected void SetDirty() + { + if (Cache == null) + return; + + Cache.Dirty = true; + } + protected internal virtual void OnMouseDown(InputEventArgs e) { } protected internal virtual void OnMouseUp(InputEventArgs e) { } protected internal virtual void OnMouseMove(InputEventArgs e) { } @@ -390,7 +441,7 @@ protected internal virtual void OnMouseEnter() { } protected internal virtual void OnMouseLeave() { } - protected internal virtual void OnEnabledChanged() { } + protected internal virtual void OnEnabledChanged() { SetDirty(); } public bool ContainsScreenPoint(Point screenMousePoint) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-05-05 05:03:25
|
Revision: 948 http://agate.svn.sourceforge.net/agate/?rev=948&view=rev Author: kanato Date: 2009-05-05 05:03:16 +0000 (Tue, 05 May 2009) Log Message: ----------- Implement mouse down behavior in text boxes. Modified Paths: -------------- branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs branches/gui-3.2/AgateLib/Gui/GuiRoot.cs branches/gui-3.2/AgateLib/Gui/IGuiThemeEngine.cs branches/gui-3.2/AgateLib/Gui/TextBox.cs branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs Modified: branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs =================================================================== --- branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs 2009-05-05 05:02:30 UTC (rev 947) +++ branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs 2009-05-05 05:03:16 UTC (rev 948) @@ -290,7 +290,7 @@ /// <param name="text"></param> /// <param name="length"></param> /// <returns></returns> - public Size MeasureString(string text, int length) { return impl.MeasureText(text, length); } + public Size MeasureString(string text, int length) { return impl.MeasureString(text, length); } /// <summary> /// Gets the height in pixels of a single line of text. /// </summary> Modified: branches/gui-3.2/AgateLib/Gui/GuiRoot.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/GuiRoot.cs 2009-05-05 05:02:30 UTC (rev 947) +++ branches/gui-3.2/AgateLib/Gui/GuiRoot.cs 2009-05-05 05:03:16 UTC (rev 948) @@ -509,5 +509,6 @@ SetFocusControl(((Container)newFocus).NearestChildTo(nearPoint, true), direction, nearPoint); } } + } } Modified: branches/gui-3.2/AgateLib/Gui/IGuiThemeEngine.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/IGuiThemeEngine.cs 2009-05-05 05:02:30 UTC (rev 947) +++ branches/gui-3.2/AgateLib/Gui/IGuiThemeEngine.cs 2009-05-05 05:03:16 UTC (rev 948) @@ -61,5 +61,7 @@ bool HitTest(Widget widget, Point screenLocation); void Update(GuiRoot guiRoot); + + void MouseDownInWidget(Widget widget, Point clientLocation); } } Modified: branches/gui-3.2/AgateLib/Gui/TextBox.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/TextBox.cs 2009-05-05 05:02:30 UTC (rev 947) +++ branches/gui-3.2/AgateLib/Gui/TextBox.cs 2009-05-05 05:03:16 UTC (rev 948) @@ -24,6 +24,15 @@ mInsertionPoint = value; } } + + protected internal override void SendMouseDown(AgateLib.InputLib.InputEventArgs e) + { + base.SendMouseDown(e); + if (Root != null) + { + Root.ThemeEngine.MouseDownInWidget(this, PointToClient(e.MousePosition)); + } + } protected internal override void SendKeyDown(AgateLib.InputLib.InputEventArgs e) { ResetIPBlinking(); Modified: branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs 2009-05-05 05:02:30 UTC (rev 947) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury/Mercury.cs 2009-05-05 05:03:16 UTC (rev 948) @@ -101,18 +101,27 @@ return 0; } + public void MouseDownInWidget(Widget widget, Point clientLocation) + { + if (widget is TextBox) MouseDownInTextBox((TextBox)widget, clientLocation); + } + + #endregion #region --- TextBox --- - - private void UpdateCache(TextBox textBox) + private static TextBoxCache GetTextBoxCache(TextBox textBox) { if (textBox.Cache == null) textBox.Cache = new TextBoxCache(); - TextBoxCache c = (TextBoxCache)textBox.Cache; + return (TextBoxCache)textBox.Cache; + } + private void UpdateCache(TextBox textBox) + { + TextBoxCache c = GetTextBoxCache(textBox); if (c.Dirty == false) return; @@ -167,7 +176,6 @@ c.Dirty = false; } - private void DrawTextBox(TextBox textBox) { Surface image = Scheme.TextBox.Image; @@ -226,6 +234,42 @@ } } + private void MouseDownInTextBox(TextBox textBox, Point clientLocation) + { + TextBoxCache c = GetTextBoxCache(textBox); + + clientLocation.X += c.Origin.X - Scheme.TextBox.StretchRegion.X; + clientLocation.Y += c.Origin.Y - Scheme.TextBox.StretchRegion.Y; + + Size sz = Size.Empty; + int last = 0; + int index; + + for (index = 1; index < textBox.Text.Length; index++) + { + sz = Scheme.WidgetFont.MeasureString(textBox.Text, index); + + if (sz.Width > clientLocation.X) + { + goto found; + } + + last = sz.Width; + } + + found: + double pass = (sz.Width - clientLocation.X) / (double)(sz.Width - last); + + // if it's halfway over, put the insertion on the right side of the character, + // otherwise put it on the left. + if (pass <= 0.5) + textBox.InsertionPoint = index; + else + textBox.InsertionPoint = index - 1; + + return; + } + /// <summary> /// Returns the local insertion point location in the textbox in pixels. /// </summary> @@ -233,8 +277,7 @@ /// <returns></returns> private Point InsertionPointLocation(TextBox textBox) { - Size sz = Scheme.WidgetFont.StringDisplaySize( - textBox.Text.Substring(0, textBox.InsertionPoint)); + Size sz = Scheme.WidgetFont.MeasureString(textBox.Text, textBox.InsertionPoint); int lines = 0; if (textBox.MultiLine) @@ -736,5 +779,11 @@ else Scheme.WidgetFont.Color = Scheme.FontColorDisabled; } + + #region IGuiThemeEngine Members + + + + #endregion } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-05-05 05:02:38
|
Revision: 947 http://agate.svn.sourceforge.net/agate/?rev=947&view=rev Author: kanato Date: 2009-05-05 05:02:30 +0000 (Tue, 05 May 2009) Log Message: ----------- Add MeasureString method. Modified Paths: -------------- branches/gui-3.2/Drivers/AgateDrawing/Drawing_FontSurface.cs branches/gui-3.2/Drivers/AgateMDX/MDX1_FontSurface.cs Modified: branches/gui-3.2/Drivers/AgateDrawing/Drawing_FontSurface.cs =================================================================== --- branches/gui-3.2/Drivers/AgateDrawing/Drawing_FontSurface.cs 2009-05-05 05:01:56 UTC (rev 946) +++ branches/gui-3.2/Drivers/AgateDrawing/Drawing_FontSurface.cs 2009-05-05 05:02:30 UTC (rev 947) @@ -127,6 +127,11 @@ return new Geometry.Size((int)result.Width, (int)result.Height); } + + public override AgateLib.Geometry.Size MeasureString(string text, int length) + { + return StringDisplaySize(text.Substring(0, length)); + } } } Modified: branches/gui-3.2/Drivers/AgateMDX/MDX1_FontSurface.cs =================================================================== --- branches/gui-3.2/Drivers/AgateMDX/MDX1_FontSurface.cs 2009-05-05 05:01:56 UTC (rev 946) +++ branches/gui-3.2/Drivers/AgateMDX/MDX1_FontSurface.cs 2009-05-05 05:02:30 UTC (rev 947) @@ -174,5 +174,10 @@ { DrawText(new Point((int)dest_x, (int)dest_y), text); } + + public override Size MeasureString(string text, int length) + { + return StringDisplaySize(text.Substring(0, length)); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-05-05 05:02:18
|
Revision: 946 http://agate.svn.sourceforge.net/agate/?rev=946&view=rev Author: kanato Date: 2009-05-05 05:01:56 +0000 (Tue, 05 May 2009) Log Message: ----------- Rename MeasureText to MeasureString. Modified Paths: -------------- branches/gui-3.2/AgateLib/BitmapFont/BitmapFontImpl.cs branches/gui-3.2/AgateLib/ImplementationBase/FontSurfaceImpl.cs Modified: branches/gui-3.2/AgateLib/BitmapFont/BitmapFontImpl.cs =================================================================== --- branches/gui-3.2/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-05-05 04:45:35 UTC (rev 945) +++ branches/gui-3.2/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-05-05 05:01:56 UTC (rev 946) @@ -378,7 +378,7 @@ DrawText(destPt.X, destPt.Y, text); } - public override Size MeasureText(string text, int length) + public override Size MeasureString(string text, int length) { return new Size(StringDisplayWidth(text.Substring(0, length)), StringDisplayHeight(text.Substring(0, length))); Modified: branches/gui-3.2/AgateLib/ImplementationBase/FontSurfaceImpl.cs =================================================================== --- branches/gui-3.2/AgateLib/ImplementationBase/FontSurfaceImpl.cs 2009-05-05 04:45:35 UTC (rev 945) +++ branches/gui-3.2/AgateLib/ImplementationBase/FontSurfaceImpl.cs 2009-05-05 05:01:56 UTC (rev 946) @@ -174,7 +174,7 @@ public abstract void Dispose(); - public abstract Size MeasureText(string text, int length); + public abstract Size MeasureString(string text, int length); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-05-05 04:45:44
|
Revision: 945 http://agate.svn.sourceforge.net/agate/?rev=945&view=rev Author: kanato Date: 2009-05-05 04:45:35 +0000 (Tue, 05 May 2009) Log Message: ----------- Add MeasureString(string, int) overload to FontSurface. Modified Paths: -------------- branches/gui-3.2/AgateLib/BitmapFont/BitmapFontImpl.cs branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs branches/gui-3.2/AgateLib/ImplementationBase/FontSurfaceImpl.cs Modified: branches/gui-3.2/AgateLib/BitmapFont/BitmapFontImpl.cs =================================================================== --- branches/gui-3.2/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-05-05 02:41:47 UTC (rev 944) +++ branches/gui-3.2/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-05-05 04:45:35 UTC (rev 945) @@ -378,6 +378,11 @@ DrawText(destPt.X, destPt.Y, text); } + public override Size MeasureText(string text, int length) + { + return new Size(StringDisplayWidth(text.Substring(0, length)), + StringDisplayHeight(text.Substring(0, length))); + } } /// <summary> Modified: branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs =================================================================== --- branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs 2009-05-05 02:41:47 UTC (rev 944) +++ branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs 2009-05-05 04:45:35 UTC (rev 945) @@ -282,9 +282,16 @@ /// </summary> /// <param name="text"></param> /// <returns></returns> - public Size StringDisplaySize(string text) { return impl.StringDisplaySize(text); } + public Size StringDisplaySize(string text) { return MeasureString(text, text.Length); } /// <summary> + /// Measures the display size of the specified string. + /// </summary> + /// <param name="text"></param> + /// <param name="length"></param> + /// <returns></returns> + public Size MeasureString(string text, int length) { return impl.MeasureText(text, length); } + /// <summary> /// Gets the height in pixels of a single line of text. /// </summary> public int FontHeight @@ -428,5 +435,6 @@ } #endregion + } } Modified: branches/gui-3.2/AgateLib/ImplementationBase/FontSurfaceImpl.cs =================================================================== --- branches/gui-3.2/AgateLib/ImplementationBase/FontSurfaceImpl.cs 2009-05-05 02:41:47 UTC (rev 944) +++ branches/gui-3.2/AgateLib/ImplementationBase/FontSurfaceImpl.cs 2009-05-05 04:45:35 UTC (rev 945) @@ -173,6 +173,8 @@ /// </summary> public abstract void Dispose(); + + public abstract Size MeasureText(string text, int length); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-05-05 02:41:51
|
Revision: 944 http://agate.svn.sourceforge.net/agate/?rev=944&view=rev Author: kanato Date: 2009-05-05 02:41:47 +0000 (Tue, 05 May 2009) Log Message: ----------- Set Z clear value to 1.0. Modified Paths: -------------- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs Modified: branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs =================================================================== --- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs 2009-05-04 17:09:45 UTC (rev 943) +++ branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs 2009-05-05 02:41:47 UTC (rev 944) @@ -55,7 +55,7 @@ private bool mHasDepth; private bool mHasStencil; - private float mDepthClear = 1000.0f; + private float mDepthClear = 1.0f; private int mStencilClear = 0; #endregion @@ -119,12 +119,14 @@ device.DeviceLost += new EventHandler(mDevice_DeviceLost); device.DeviceReset += new EventHandler(mDevice_DeviceReset); + device.RenderState.StencilEnable = false; + device.RenderState.ZBufferEnable = true; + device.RenderState.ZBufferFunction = Compare.LessEqual; + device.RenderState.ZBufferWriteEnable = true; + mDevice = new D3DDevice(device); - mDevice.Device.RenderState.StencilEnable = false; - mDevice.Device.RenderState.ZBufferEnable = false; - // create primitive objects mLine = new Direct3D.Line(device); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-05-04 17:09:52
|
Revision: 943 http://agate.svn.sourceforge.net/agate/?rev=943&view=rev Author: kanato Date: 2009-05-04 17:09:45 +0000 (Mon, 04 May 2009) Log Message: ----------- Remove Test3D from ths list of available tests. Update parameters in Matrices test. Modified Paths: -------------- branches/agate3d-3.2/Tests/Display3D/Matrices.cs branches/agate3d-3.2/Tests/Display3D/Test3d.cs Modified: branches/agate3d-3.2/Tests/Display3D/Matrices.cs =================================================================== --- branches/agate3d-3.2/Tests/Display3D/Matrices.cs 2009-05-04 17:07:55 UTC (rev 942) +++ branches/agate3d-3.2/Tests/Display3D/Matrices.cs 2009-05-04 17:09:45 UTC (rev 943) @@ -55,8 +55,8 @@ Surface surf = new Surface("bg-bricks.png"); CubeBuilder cube = new CubeBuilder(); - cube.Length = 58; - cube.Location = new Vector3(cube.Length / 2, cube.Length / 2, 0); + cube.Length = 8; + cube.Location = new Vector3(cube.Length / 2 + 6, cube.Length / 2 + 6, 0); cube.CreateVertexBuffer(); IndexBuffer indices = cube.IndexBuffer; @@ -75,11 +75,13 @@ m[0].AttenuationLinear = 0.00f; m[0].AttenuationQuadratic = 0.002f; - Vector3 position = new Vector3(-5, 0, 2); - float facingAngle = 0; + Vector3 position = new Vector3(-5, 0, 10); + double facingAngle = Math.PI / 4; float speed = 0.03f; float turnSpeed = 0.004f; + Surface s = new Surface("ball.png"); + while (wind.IsClosed == false) { Vector3 lookDirection = CalculateLookDirection(facingAngle); @@ -93,7 +95,8 @@ facingAngle -= turn * turnSpeed * (float)Display.DeltaTime; } - Vector3 lookTarget = position + lookDirection; + Vector3 lookTarget = position + lookDirection* 20; + lookTarget.Z = 0; Display.BeginFrame(); Display.Clear(Color.Gray); @@ -139,7 +142,7 @@ m[0].Position = position; //m.DoLighting(); - + // draw a weird checkerboard for (int x = 0; x < 8; x += 2) { @@ -152,7 +155,8 @@ } } Display.DrawRect(new Rectangle(0, 0, 8, 8), Color.Black); - + + //s.Draw(); b.DrawIndexed(indices); Display.EndFrame(); @@ -161,7 +165,7 @@ } } - private static Vector3 CalculateLookDirection(float facingAngle) + private static Vector3 CalculateLookDirection(double facingAngle) { return new Vector3(Math.Cos(facingAngle), Math.Sin(facingAngle), 0); } Modified: branches/agate3d-3.2/Tests/Display3D/Test3d.cs =================================================================== --- branches/agate3d-3.2/Tests/Display3D/Test3d.cs 2009-05-04 17:07:55 UTC (rev 942) +++ branches/agate3d-3.2/Tests/Display3D/Test3d.cs 2009-05-04 17:09:45 UTC (rev 943) @@ -11,7 +11,7 @@ namespace Tests.Display3D.Test3D { - class Test3d : IAgateTest + class Test3d //: IAgateTest { #region IAgateTest Members @@ -25,7 +25,7 @@ get { return "Display 3D"; } } - void IAgateTest.Main(string[] args) + public void Main(string[] args) { Run(args); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-05-04 17:08:00
|
Revision: 942 http://agate.svn.sourceforge.net/agate/?rev=942&view=rev Author: kanato Date: 2009-05-04 17:07:55 +0000 (Mon, 04 May 2009) Log Message: ----------- Fix consistency between vertex/index buffer creation flags and writing flags. Fix generation of vertex declaration. Modified Paths: -------------- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs branches/agate3d-3.2/Drivers/AgateMDX/MDX1_IndexBuffer.cs branches/agate3d-3.2/Drivers/AgateMDX/MDX1_VertexBuffer.cs Modified: branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs =================================================================== --- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs 2009-05-03 17:20:27 UTC (rev 941) +++ branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs 2009-05-04 17:07:55 UTC (rev 942) @@ -53,8 +53,9 @@ private bool mVSync = true; - private bool mHasDepth , mHasStencil; - private float mDepthClear = 0; + private bool mHasDepth; + private bool mHasStencil; + private float mDepthClear = 1000.0f; private int mStencilClear = 0; #endregion @@ -438,7 +439,7 @@ public override void FillRect(Rectangle rect, Color color) { - FillRect(rect, new Gradient(color)); + FillRect((RectangleF)rect, new Gradient(color)); } public override void FillRect(RectangleF rect, Color color) { @@ -446,7 +447,7 @@ } public override void FillRect(Rectangle rect, Gradient color) { - FillRect(new RectangleF(rect.X, rect.Y, rect.Width, rect.Height), color); + FillRect((RectangleF)rect, color); } public override void FillRect(RectangleF rect, Gradient color) { @@ -461,15 +462,11 @@ mFillRectVerts[2].Color = color.BottomLeft.ToArgb(); mFillRectVerts[3] = mFillRectVerts[1]; - //vert[3].Position = new Vector4(rect.Right, rect.Top, 0f, 1f); - //vert[3].Color = clr; mFillRectVerts[4].Position = new Microsoft.DirectX.Vector3(rect.Right, rect.Bottom, 0f); mFillRectVerts[4].Color = color.BottomRight.ToArgb(); mFillRectVerts[5] = mFillRectVerts[2]; - //vert[5].Position = new Vector4(rect.Left, rect.Bottom, 0f, 1f); - //vert[5].Color = clr; mDevice.DrawBuffer.Flush(); @@ -480,7 +477,7 @@ mDevice.VertexFormat = CustomVertex.PositionColored.Format; mDevice.Device.DrawUserPrimitives(Direct3D.PrimitiveType.TriangleList, 2, mFillRectVerts); - + mDevice.AlphaArgument1 = TextureArgument.TextureColor; } @@ -579,6 +576,9 @@ present.Windowed = true; present.PresentFlag = PresentFlag.LockableBackBuffer; + if (present.AutoDepthStencilFormat == DepthFormat.Unknown) + present.EnableAutoDepthStencil = false; + if (VSync) present.PresentationInterval = PresentInterval.Default; else Modified: branches/agate3d-3.2/Drivers/AgateMDX/MDX1_IndexBuffer.cs =================================================================== --- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_IndexBuffer.cs 2009-05-03 17:20:27 UTC (rev 941) +++ branches/agate3d-3.2/Drivers/AgateMDX/MDX1_IndexBuffer.cs 2009-05-04 17:07:55 UTC (rev 942) @@ -14,7 +14,7 @@ IndexBufferType mType; int mCount; Direct3D.IndexBuffer mBuffer; - object data; + int maxIndex; public MDX1_IndexBuffer(MDX1_Display disp, IndexBufferType type, int count) { @@ -29,9 +29,9 @@ { get { return mBuffer; } } - public object Data + public int MaxIndex { - get { return data; } + get { return maxIndex; } } private void CreateIndexBuffer() @@ -61,14 +61,14 @@ public override void WriteIndices(int[] indices) { - mBuffer.SetData(indices, 0, Microsoft.DirectX.Direct3D.LockFlags.Discard); - data = indices; + mBuffer.SetData(indices, 0, 0); + maxIndex = indices.Max(); } public override void WriteIndices(short[] indices) { - mBuffer.SetData(indices, 0, Microsoft.DirectX.Direct3D.LockFlags.Discard); - data = indices; + mBuffer.SetData(indices, 0, 0); + maxIndex = indices.Max(); } } } Modified: branches/agate3d-3.2/Drivers/AgateMDX/MDX1_VertexBuffer.cs =================================================================== --- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_VertexBuffer.cs 2009-05-03 17:20:27 UTC (rev 941) +++ branches/agate3d-3.2/Drivers/AgateMDX/MDX1_VertexBuffer.cs 2009-05-04 17:07:55 UTC (rev 942) @@ -18,15 +18,24 @@ Direct3D.VertexFormats mFormats; int mCount; object data; + VertexLayout mLayout; + static StringBuilder b; + public MDX1_VertexBuffer(MDX1_Display display, VertexLayout layout, int vertexCount) { mDisplay = display; mCount = vertexCount; + b = new StringBuilder(); + mDeclaration = CreateVertexDeclaration(layout); mFormats = CreateVertexFormats(layout); + System.Diagnostics.Debug.WriteLine(b.ToString()); + + mLayout = layout; + mBuffer = new Microsoft.DirectX.Direct3D.VertexBuffer( mDisplay.D3D_Device.Device, vertexCount * layout.VertexSize, @@ -73,17 +82,16 @@ } private Direct3D.VertexDeclaration CreateVertexDeclaration(VertexLayout layout) { - List<Direct3D.VertexElement> formats = new List<Microsoft.DirectX.Direct3D.VertexElement>(); + List<Direct3D.VertexElement> formats = new List<Direct3D.VertexElement>(); + short loc = 0; for (int i = 0; i < layout.Count; i++) { var element = layout[i]; - short loc = 0; - int size; - Direct3D.VertexElement d3d_element = ConvertElement(element, out size); - d3d_element.Offset = loc; - loc += (short)size; + Direct3D.VertexElement d3d_element = ConvertElement(element, ref loc); + + formats.Add(d3d_element); } formats.Add(Direct3D.VertexElement.VertexDeclarationEnd); @@ -91,12 +99,14 @@ return new Direct3D.VertexDeclaration( mDisplay.D3D_Device.Device, formats.ToArray()); } - private Direct3D.VertexElement ConvertElement(VertexElementDesc element, out int size) + private Direct3D.VertexElement ConvertElement(VertexElementDesc element, ref short loc) { - Direct3D.DeclarationType declType; Direct3D.DeclarationMethod declMethod = Microsoft.DirectX.Direct3D.DeclarationMethod.Default; Direct3D.DeclarationUsage declUsage; + Direct3D.DeclarationType declType; + int size = VertexLayout.SizeOf(element.DataType); + switch(element.DataType) { case VertexElementDataType.Float1: @@ -116,8 +126,6 @@ element.DataType.ToString() + " not implemented."); } - size = VertexLayout.SizeOf(element.DataType); - switch(element.ElementType) { case VertexElement.Position: @@ -143,7 +151,11 @@ element.ElementType.ToString() + " not implemented."); } - return new Direct3D.VertexElement(0, 0, declType, declMethod, declUsage, 0); + b.AppendFormat("{0} {1} {2} {3}\n", declType, declUsage, loc, size); + + loc += (short)size; + + return new Direct3D.VertexElement(0, (short)(loc - size), declType, declMethod, declUsage, 0); } private Direct3D.PrimitiveType GetPrimitiveType(ref int vertexCount) @@ -184,22 +196,20 @@ int primitiveCount = count; MDX1_IndexBuffer indexbuffer = _indexbuffer.Impl as MDX1_IndexBuffer; - // after calling GetPrimitiveType, count is the number of primitives + // after calling GetPrimitiveType, primitiveCount is the number of primitives // instead of the number of vertices. Direct3D.PrimitiveType primType = GetPrimitiveType(ref primitiveCount); SetTextures(); + mDisplay.D3D_Device.AlphaArgument1 = Direct3D.TextureArgument.TextureColor; + + mDisplay.D3D_Device.VertexFormat = Microsoft.DirectX.Direct3D.VertexFormats.None; + mDisplay.D3D_Device.Device.VertexDeclaration = mDeclaration; mDisplay.D3D_Device.Device.Indices = indexbuffer.DeviceIndexBuffer; - mDisplay.D3D_Device.Device.SetStreamSource(0, mBuffer, 0); - mDisplay.D3D_Device.VertexFormat = mFormats; - mDisplay.D3D_Device.Device.VertexDeclaration = mDeclaration; - //mDisplay.D3D_Device.Device.DrawIndexedPrimitives(primType, 0, 0, count, start, primitiveCount); - mDisplay.D3D_Device.Device.DrawIndexedUserPrimitives(primType, 0, - count, primitiveCount, - indexbuffer.Data, indexbuffer.IndexType == IndexBufferType.Int16, - data); - + mDisplay.D3D_Device.Device.SetStreamSource(0, mBuffer, 0, mLayout.VertexSize); + mDisplay.D3D_Device.Device.DrawIndexedPrimitives( + primType, 0, 0, indexbuffer.MaxIndex, start, primitiveCount); } private void SetTextures() @@ -224,7 +234,7 @@ public override void Write<T>(T[] vertices) { - mBuffer.SetData(vertices, 0, Microsoft.DirectX.Direct3D.LockFlags.Discard); + mBuffer.SetData(vertices, 0, 0); data = vertices; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ac...@us...> - 2009-05-03 17:20:33
|
Revision: 941 http://agate.svn.sourceforge.net/agate/?rev=941&view=rev Author: accagon Date: 2009-05-03 17:20:27 +0000 (Sun, 03 May 2009) Log Message: ----------- * ParticleEmitter.cs: Add emit velocity and emit acceleration Modified Paths: -------------- branches/particles/AgateLib/Particles/ParticleEmitter.cs Modified: branches/particles/AgateLib/Particles/ParticleEmitter.cs =================================================================== --- branches/particles/AgateLib/Particles/ParticleEmitter.cs 2009-05-03 16:22:34 UTC (rev 940) +++ branches/particles/AgateLib/Particles/ParticleEmitter.cs 2009-05-03 17:20:27 UTC (rev 941) @@ -34,7 +34,10 @@ // 1 = emit each second a particle // 2 = emit every two seconds private float mEmitFrequenzy = 1f; - + + private Vector2 mEmitAcceleration = Vector2.Empty; + private Vector2 mEmitVelocity = Vector2.Empty; + /// <value> /// Gets or sets the particles. /// </value> @@ -53,6 +56,24 @@ set { mEmitFrequenzy = value; } } + /// <value> + /// Gets or sets the emit acceleration. + /// </value> + public Vector2 EmitAcceleration + { + get { return mEmitAcceleration; } + set { mEmitAcceleration = value; } + } + + /// <value> + /// Gets or sets the emit velocity. + /// </value> + public Vector2 EmitVelocity + { + get { return mEmitVelocity; } + set { mEmitVelocity = value; } + } + /// <summary> /// Draws each particle. /// </summary> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ac...@us...> - 2009-05-03 16:22:42
|
Revision: 940 http://agate.svn.sourceforge.net/agate/?rev=940&view=rev Author: accagon Date: 2009-05-03 16:22:34 +0000 (Sun, 03 May 2009) Log Message: ----------- * ParticleEmitter.cs: - Change method Draw from virtual to abstraact - Add trigger and check of OnUpdate event Modified Paths: -------------- branches/particles/AgateLib/Particles/ParticleEmitter.cs Modified: branches/particles/AgateLib/Particles/ParticleEmitter.cs =================================================================== --- branches/particles/AgateLib/Particles/ParticleEmitter.cs 2009-05-03 16:06:28 UTC (rev 939) +++ branches/particles/AgateLib/Particles/ParticleEmitter.cs 2009-05-03 16:22:34 UTC (rev 940) @@ -56,10 +56,7 @@ /// <summary> /// Draws each particle. /// </summary> - public virtual void Draw () - { - // Draws particles - } + public abstract void Draw (); /// <summary> /// Overridden update method. @@ -70,10 +67,11 @@ /// </param> public override void Update (float time_ms) { + if ( OnUpdate != null) + OnUpdate(new UpdateArgs(this, time_ms)); + base.Update (time_ms); } - // TODO: Draw event - // TODO: Emitter dead event public delegate void ParticleEventHandler(object sender, ParticleArgs args); public event ParticleEventHandler OnNewParticle; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ac...@us...> - 2009-05-03 16:06:34
|
Revision: 939 http://agate.svn.sourceforge.net/agate/?rev=939&view=rev Author: accagon Date: 2009-05-03 16:06:28 +0000 (Sun, 03 May 2009) Log Message: ----------- * GravityManipulator.cs: - Use new events instead of pure delegate. - Merge Strength and Position to Gravity which stores the direction and strength at the same time. Modified Paths: -------------- branches/particles/AgateLib/Particles/Manipulators/GravityManipulator.cs Modified: branches/particles/AgateLib/Particles/Manipulators/GravityManipulator.cs =================================================================== --- branches/particles/AgateLib/Particles/Manipulators/GravityManipulator.cs 2009-05-03 15:59:29 UTC (rev 938) +++ branches/particles/AgateLib/Particles/Manipulators/GravityManipulator.cs 2009-05-03 16:06:28 UTC (rev 939) @@ -27,37 +27,25 @@ /// A gravity particle manipulator. /// </summary> public class GravityManipulator - { - private float mStrength = 1f; - private Vector2 mPosition = Vector2.Empty; + { + private Vector2 mGravity = Vector2.Empty; /// <value> - /// Gets or sets the strength. + /// Gets or sets the gravity strength and direction. /// </value> - public float Strength + public Vector2 Gravity { - get { return mStrength; } - set { mStrength = value; } + get { return mGravity; } + set { mGravity = value; } } - /// <value> - /// Gets or sets the position. - /// </value> - public Vector2 Position - { - get { return mPosition; } - set { mPosition = value; } - } - /// <summary> /// Constructs a gravitiy manipulator. /// </summary> - /// <param name="position"></param> - /// <param name="strength"></param> - public GravityManipulator(Vector2 position, float strength) + /// <param name="gravity">Gravity strength and direction.</param> + public GravityManipulator(Vector2 gravity) { - mPosition = position; - mStrength = strength; + mGravity = gravity; } /// <summary> @@ -66,12 +54,20 @@ /// <param name="emitter"></param> public void SubscribeToEmitter(ParticleEmitter emitter) { - emitter.UpdateParticles += Manipulate; + emitter.OnUpdate +=HandleOnUpdate; } - - internal void Manipulate(List<Particle> particles, float time_ms) + + void HandleOnUpdate(UpdateArgs args) { - // TODO: add missing calculation to gravity manipulator + // TODO: Adjust pseudo math to new gravity property + foreach(Particle pt in args.Emitter.Particles) + { + if(pt.IsALive == true) + { + // pt.Acceleration = pt.Acceleration + Position * Strength * args.Time_ms; + // pt.Velocity = pt.Velocity + Position * Strength * args.Time_ms; + } + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ac...@us...> - 2009-05-03 15:59:33
|
Revision: 938 http://agate.svn.sourceforge.net/agate/?rev=938&view=rev Author: accagon Date: 2009-05-03 15:59:29 +0000 (Sun, 03 May 2009) Log Message: ----------- * ParticleEmitter.cs: - Replace delegate UpdateParticles with OnUpdate event - Add new OnNewParticle, OnDeadParticle, OnRecyledParticle event Modified Paths: -------------- branches/particles/AgateLib/Particles/ParticleEmitter.cs Modified: branches/particles/AgateLib/Particles/ParticleEmitter.cs =================================================================== --- branches/particles/AgateLib/Particles/ParticleEmitter.cs 2009-05-03 15:23:56 UTC (rev 937) +++ branches/particles/AgateLib/Particles/ParticleEmitter.cs 2009-05-03 15:59:29 UTC (rev 938) @@ -25,18 +25,14 @@ namespace AgateLib.Particles { /// <summary> - /// Updates particles. - /// Provides a list of particles and passed time in milliseconds since last update. - /// </summary> - public delegate void UpdateParticles(List<Particle> particles, float time_ms); - - /// <summary> /// Base class for particle emitters. /// </summary> public abstract class ParticleEmitter : Particle { private List<Particle> mParticles = new List<Particle>(); + // 1 = emit each second a particle + // 2 = emit every two seconds private float mEmitFrequenzy = 1f; /// <value> @@ -58,12 +54,6 @@ } /// <summary> - /// Delegate to update particles. - /// Particle manipulators should subscribe here. - /// </summary> - public UpdateParticles UpdateParticles; - - /// <summary> /// Draws each particle. /// </summary> public virtual void Draw () @@ -80,10 +70,76 @@ /// </param> public override void Update (float time_ms) { - if(UpdateParticles != null) - UpdateParticles(mParticles, time_ms); - base.Update (time_ms); } + // TODO: Draw event + // TODO: Emitter dead event + + public delegate void ParticleEventHandler(object sender, ParticleArgs args); + public event ParticleEventHandler OnNewParticle; + public event ParticleEventHandler OnDeadParticle; + public event ParticleEventHandler OnRecyledParticle; + + public delegate void UpdateEventHandler(UpdateArgs args); + public event UpdateEventHandler OnUpdate; } + + /// <summary> + /// Particle event args. + /// </summary> + public class ParticleArgs : EventArgs + { + /// <summary> + /// Constructs ParticleArgs. + /// </summary> + /// <param name="particle">Particle that changed condition.</param> + public ParticleArgs(Particle particle) + { + mParticle = particle; + } + + private Particle mParticle; + /// <value> + /// Particle that changed condition. + /// </value> + public Particle Particle + { + get{ return mParticle; } + } + } + + /// <summary> + /// Update event args. + /// </summary> + public class UpdateArgs : EventArgs + { + /// <summary> + /// Constructs UpdateArgs. + /// </summary> + /// <param name="emitter">Emitter that triggered the update event.</param> + /// <param name="time_ms">Passed time in milliseconds since last update.</param> + public UpdateArgs(ParticleEmitter emitter, float time_ms) + { + mEmitter = emitter; + mTime_ms = time_ms; + } + + private ParticleEmitter mEmitter; + /// <value> + /// Emitter that triggered the update event. + /// </value> + public ParticleEmitter Emitter + { + get { return mEmitter; } + } + + private float mTime_ms; + /// <value> + /// Passed time in milliseconds since last update. + /// </value> + public float Time_ms + { + get { return mTime_ms; } + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |