agate-svn-commit Mailing List for AgateLib
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...> - 2014-11-15 19:21:37
|
Revision: 1538 http://sourceforge.net/p/agate/code/1538 Author: kanato Date: 2014-11-15 19:21:32 +0000 (Sat, 15 Nov 2014) Log Message: ----------- Fix asset paths for windows forms applications. Modified Paths: -------------- trunk/AgateLib/Algorithms/Inverting.cs trunk/AgateLib/Core.cs trunk/AgateLib/Drivers/IPlatformFactory.cs trunk/AgateLib.Platform.WinForms/Factories/FormsFactory.cs trunk/AgateLib.Platform.WinForms/Factories/PlatformFactory.cs trunk/AgateLib.Platform.WinForms/IO/FileSystemProvider.cs trunk/AgateLib.Platform.WinForms/WinFormsInitializer.cs trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/WindowsStorePlatformFactory.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/Fakes/FakePlatformFactory.cs trunk/AgateLib.Tests/UnitTests/Algorithms/EMathTest.cs Modified: trunk/AgateLib/Algorithms/Inverting.cs =================================================================== --- trunk/AgateLib/Algorithms/Inverting.cs 2014-10-13 02:36:59 UTC (rev 1537) +++ trunk/AgateLib/Algorithms/Inverting.cs 2014-11-15 19:21:32 UTC (rev 1538) @@ -25,16 +25,11 @@ { public class Inverting { - public static double IterateInvert(Func<double, double> func, double targetVal) + public static double IterateInvert(Func<double, double> func, double targetVal, double initialPt = 0, int itermax = 500) { - return IterateInvert(func, targetVal, 0); - } - public static double IterateInvert(Func<double, double> func, double targetVal, double initialPt) - { bool hasLower = false; bool hasUpper = false; int iter = 0; - const int itermax = 500; var p1 = new Pair<double, double>(initialPt, func(initialPt)); Pair<double, double> lowerVal, upperVal; Modified: trunk/AgateLib/Core.cs =================================================================== --- trunk/AgateLib/Core.cs 2014-10-13 02:36:59 UTC (rev 1537) +++ trunk/AgateLib/Core.cs 2014-11-15 19:21:32 UTC (rev 1538) @@ -353,7 +353,7 @@ public static void InitAssetLocations(AssetLocations assets) { - FileProvider.Initialize(mFactory.PlatformFactory.AssetFileProvider, assets); + FileProvider.Initialize(mFactory.PlatformFactory.ApplicationFolderFileProvider, assets); } public static IAgateFactory Factory Modified: trunk/AgateLib/Drivers/IPlatformFactory.cs =================================================================== --- trunk/AgateLib/Drivers/IPlatformFactory.cs 2014-10-13 02:36:59 UTC (rev 1537) +++ trunk/AgateLib/Drivers/IPlatformFactory.cs 2014-11-15 19:21:32 UTC (rev 1538) @@ -41,7 +41,7 @@ /// <summary> /// Gets a file provider which points to the application directory. /// </summary> - IReadFileProvider AssetFileProvider { get; } + IReadFileProvider ApplicationFolderFileProvider { get; } IPlatformSerialization CreateDefaultSerializationConstructor(); } Modified: trunk/AgateLib.Platform.WinForms/Factories/FormsFactory.cs =================================================================== --- trunk/AgateLib.Platform.WinForms/Factories/FormsFactory.cs 2014-10-13 02:36:59 UTC (rev 1537) +++ trunk/AgateLib.Platform.WinForms/Factories/FormsFactory.cs 2014-11-15 19:21:32 UTC (rev 1538) @@ -28,11 +28,6 @@ InputFactory = sdl; } - public void SetAssetLocations(AssetLocations assetLocations) - { - mPlatformFactory.SetAssetLocations(assetLocations); - } - public IDisplayFactory DisplayFactory { get; private set; } public IAudioFactory AudioFactory { get; private set; } public IInputFactory InputFactory { get; private set; } Modified: trunk/AgateLib.Platform.WinForms/Factories/PlatformFactory.cs =================================================================== --- trunk/AgateLib.Platform.WinForms/Factories/PlatformFactory.cs 2014-10-13 02:36:59 UTC (rev 1537) +++ trunk/AgateLib.Platform.WinForms/Factories/PlatformFactory.cs 2014-11-15 19:21:32 UTC (rev 1538) @@ -20,18 +20,16 @@ public PlatformFactory() { Info = new FormsPlatformInfo(); - AssetFileProvider = new FileSystemProvider("."); + + var appdir = Path.GetDirectoryName(System.IO.Path.GetFullPath(Assembly.GetEntryAssembly().Location)); + + ApplicationFolderFileProvider = new FileSystemProvider(appdir); } public PlatformInfo Info { get; private set; } - public IReadFileProvider AssetFileProvider { get; private set; } + public IReadFileProvider ApplicationFolderFileProvider { get; private set; } - public void SetAssetLocations(AssetLocations assetLocations) - { - AssetFileProvider = new FileSystemProvider(System.IO.Path.GetFullPath(assetLocations.Path)); - } - public IStopwatch CreateStopwatch() { return new DiagnosticsStopwatch(); Modified: trunk/AgateLib.Platform.WinForms/IO/FileSystemProvider.cs =================================================================== --- trunk/AgateLib.Platform.WinForms/IO/FileSystemProvider.cs 2014-10-13 02:36:59 UTC (rev 1537) +++ trunk/AgateLib.Platform.WinForms/IO/FileSystemProvider.cs 2014-11-15 19:21:32 UTC (rev 1538) @@ -245,8 +245,13 @@ { List<string> files = new List<string>(); - files.AddRange(Directory.GetFiles(mPath, searchPattern) - .Select(x => MakeRelativePath(x))); + try + { + files.AddRange(Directory.GetFiles(mPath, searchPattern) + .Select(x => MakeRelativePath(x))); + } + catch (DirectoryNotFoundException) + { } return files; } Modified: trunk/AgateLib.Platform.WinForms/WinFormsInitializer.cs =================================================================== --- trunk/AgateLib.Platform.WinForms/WinFormsInitializer.cs 2014-10-13 02:36:59 UTC (rev 1537) +++ trunk/AgateLib.Platform.WinForms/WinFormsInitializer.cs 2014-11-15 19:21:32 UTC (rev 1538) @@ -21,7 +21,6 @@ Core.Initialize(factory); } - factory.SetAssetLocations(parameters.AssetLocations); Core.InitAssetLocations(parameters.AssetLocations); var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); Modified: trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/WindowsStorePlatformFactory.cs =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/WindowsStorePlatformFactory.cs 2014-10-13 02:36:59 UTC (rev 1537) +++ trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/WindowsStorePlatformFactory.cs 2014-11-15 19:21:32 UTC (rev 1538) @@ -14,11 +14,11 @@ public WindowsStorePlatformFactory(bool handheld, AssetLocations assetLocations) { Info = new WindowsStorePlatformInfo(handheld); - AssetFileProvider = new WindowsStoreAssetFileProvider("."); + ApplicationFolderFileProvider = new WindowsStoreAssetFileProvider("."); FileProvider.UserFiles = new IsolatedStorageFileProvider(); } public PlatformInfo Info { get; private set;} - public IReadFileProvider AssetFileProvider { get; private set; } + public IReadFileProvider ApplicationFolderFileProvider { get; private set; } public IStopwatch CreateStopwatch() { Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/Fakes/FakePlatformFactory.cs =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/Fakes/FakePlatformFactory.cs 2014-10-13 02:36:59 UTC (rev 1537) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/Fakes/FakePlatformFactory.cs 2014-11-15 19:21:32 UTC (rev 1538) @@ -15,7 +15,7 @@ Info = new FakePlatformInfo(); } public Platform.PlatformInfo Info { get; private set; } - public IReadFileProvider AssetFileProvider { get; private set;} + public IReadFileProvider ApplicationFolderFileProvider { get; private set;} public Platform.IStopwatch CreateStopwatch() { Modified: trunk/AgateLib.Tests/UnitTests/Algorithms/EMathTest.cs =================================================================== --- trunk/AgateLib.Tests/UnitTests/Algorithms/EMathTest.cs 2014-10-13 02:36:59 UTC (rev 1537) +++ trunk/AgateLib.Tests/UnitTests/Algorithms/EMathTest.cs 2014-11-15 19:21:32 UTC (rev 1538) @@ -37,6 +37,11 @@ } [TestMethod] + public void IterateInvertMaxIterationsTest() + { + AssertThrows.Throws<Exception>(() => Inverting.IterateInvert(x => x, 4, itermax: 1)); + } + [TestMethod] public void InterateInvertTest() { Assert.AreEqual(0, Inverting.IterateInvert(x => 2 * x, 0), 0.000001); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2014-10-13 02:37:10
|
Revision: 1537 http://sourceforge.net/p/agate/code/1537 Author: kanato Date: 2014-10-13 02:36:59 +0000 (Mon, 13 Oct 2014) Log Message: ----------- Add ability to have multiple asset stores. Some fixes for windows metro/phone apps. Modified Paths: -------------- trunk/AgateLib/AgateLib.csproj trunk/AgateLib/ApplicationModels/ModelParameters.cs trunk/AgateLib/DisplayLib/Surface.cs trunk/AgateLib/Drivers/IPlatformFactory.cs trunk/AgateLib/IO/FileProvider.cs trunk/AgateLib/Serialization/Xle/XleSerializer.cs trunk/AgateLib/UserInterface/Css/Rendering/CssRenderer.cs trunk/AgateLib.Platform.WinForms/AgateLib.Platform.WinForms.csproj trunk/AgateLib.Platform.WinForms/Factories/FormsFactory.cs trunk/AgateLib.Platform.WinForms/Factories/PlatformFactory.cs trunk/AgateLib.Platform.WindowsMetro/Factories/WinPlatformFactory.cs trunk/AgateLib.Platform.WindowsMetro/Factories/WindowsFactory.cs trunk/AgateLib.Platform.WindowsMetro/WindowsInitializer.cs trunk/AgateLib.Platform.WindowsPhone/Factories/WPPlatformFactory.cs trunk/AgateLib.Platform.WindowsPhone/Factories/WindowsPhoneFactory.cs trunk/AgateLib.Platform.WindowsPhone/WindowsPhoneInitializer.cs trunk/AgateLib.Platform.WindowsStoreCommon/AgateLib.Platform.WindowsStoreCommon.csproj trunk/AgateLib.Platform.WindowsStoreCommon/AudioImplementation/XAudio2_Music.cs trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/SDX_Surface.cs trunk/AgateLib.Platform.WindowsStoreCommon/Factories/DisplayFactory.cs trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/WindowsStoreAssetFileProvider.cs trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/WindowsStorePlatformFactory.cs trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/SpriteTester/frmSpriteTester.cs trunk/AgateLib.Tests/Tests.WindowsMetro/TestContainer.xaml.cs trunk/AgateLib.Tests/Tests.WindowsPhone/TestContainer.xaml.cs trunk/AgateLib.Tests/UnitTests/Resources/SerializationTest.cs trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssParseTest.cs trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssTestBase.cs Added Paths: ----------- trunk/AgateLib/IO/AssetLocations.cs trunk/AgateLib/IO/Assets.cs trunk/AgateLib/IO/ReadFileProviderList.cs trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/AgateConsoleImpl.cs trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/IsolatedStorageFileProvider.cs Removed Paths: ------------- trunk/AgateLib/ApplicationModels/AssetLocations.cs trunk/AgateLib.Platform.WinForms/IO/FileProviderList.cs Modified: trunk/AgateLib/AgateLib.csproj =================================================================== --- trunk/AgateLib/AgateLib.csproj 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib/AgateLib.csproj 2014-10-13 02:36:59 UTC (rev 1537) @@ -68,6 +68,8 @@ <Compile Include="InputLib\GamepadMap.cs" /> <Compile Include="InputLib\GamepadMapDatabase.cs" /> <Compile Include="InputLib\GamepadStickEventArgs.cs" /> + <Compile Include="IO\Assets.cs" /> + <Compile Include="IO\ReadFileProviderList.cs" /> <Compile Include="Mathematics\MathHelper.cs" /> <Compile Include="Algorithms\PathFinding\IAStarMap.cs" /> <Compile Include="Algorithms\Pair.cs" /> @@ -75,7 +77,7 @@ <SubType>Code</SubType> </Compile> <Compile Include="ApplicationModels\AgateAppModel.cs" /> - <Compile Include="ApplicationModels\AssetLocations.cs" /> + <Compile Include="IO\AssetLocations.cs" /> <Compile Include="Geometry\CoordinateSystems\FixedAspectRatioCoordinates.cs" /> <Compile Include="Geometry\ICoordinateSystemCreator.cs" /> <Compile Include="ApplicationModels\ModelParameters.cs" /> Deleted: trunk/AgateLib/ApplicationModels/AssetLocations.cs =================================================================== --- trunk/AgateLib/ApplicationModels/AssetLocations.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib/ApplicationModels/AssetLocations.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -1,63 +0,0 @@ -// The contents of this file are subject to the Mozilla Public License -// Version 1.1 (the "License"); you may not use this file except in -// compliance with the License. You may obtain a copy of the License at -// http://www.mozilla.org/MPL/ -// -// Software distributed under the License is distributed on an "AS IS" -// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -// License for the specific language governing rights and limitations -// under the License. -// -// The Original Code is AgateLib. -// -// The Initial Developer of the Original Code is Erik Ylvisaker. -// Portions created by Erik Ylvisaker are Copyright (C) 2006-2014. -// All Rights Reserved. -// -// Contributor(s): Erik Ylvisaker -// -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AgateLib.ApplicationModels -{ - /// <summary> - /// Structure which indicates where various assets are stored. - /// </summary> - public class AssetLocations - { - public AssetLocations() - { - Path = "."; - } - - /// <summary> - /// Path prefix to load surfaces from. - /// </summary> - public string Surfaces { get; set; } - /// <summary> - /// Path prefix to load sound effects from. - /// </summary> - public string Sound { get; set; } - /// <summary> - /// Path prefix to load music files from. - /// </summary> - public string Music { get; set; } - /// <summary> - /// Path prefix to load resource files from. - /// </summary> - public string Resources { get; set; } - /// <summary> - /// Path prefix to load user interface files from. - /// </summary> - public string UserInterface { get; set; } - - /// <summary> - /// Root path used to load all assets. - /// </summary> - public string Path { get; set; } - } -} Modified: trunk/AgateLib/ApplicationModels/ModelParameters.cs =================================================================== --- trunk/AgateLib/ApplicationModels/ModelParameters.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib/ApplicationModels/ModelParameters.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -18,6 +18,7 @@ // using AgateLib.Geometry; using AgateLib.Geometry.CoordinateSystems; +using AgateLib.IO; using AgateLib.Platform; using System; using System.Collections.Generic; Modified: trunk/AgateLib/DisplayLib/Surface.cs =================================================================== --- trunk/AgateLib/DisplayLib/Surface.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib/DisplayLib/Surface.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -91,7 +91,7 @@ throw new ArgumentNullException("You must supply a file name."); if (fileprovider == null) - fileprovider = AgateLib.IO.FileProvider.SurfaceAssets; + fileprovider = AgateLib.IO.Assets.Surfaces; mImpl = Core.Factory.DisplayFactory.CreateSurface(fileprovider, filename); Modified: trunk/AgateLib/Drivers/IPlatformFactory.cs =================================================================== --- trunk/AgateLib/Drivers/IPlatformFactory.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib/Drivers/IPlatformFactory.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -38,6 +38,9 @@ IEnumerable<System.Reflection.Assembly> GetSerializationSearchAssemblies(Type objectType); + /// <summary> + /// Gets a file provider which points to the application directory. + /// </summary> IReadFileProvider AssetFileProvider { get; } IPlatformSerialization CreateDefaultSerializationConstructor(); Copied: trunk/AgateLib/IO/AssetLocations.cs (from rev 1534, trunk/AgateLib/ApplicationModels/AssetLocations.cs) =================================================================== --- trunk/AgateLib/IO/AssetLocations.cs (rev 0) +++ trunk/AgateLib/IO/AssetLocations.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -0,0 +1,65 @@ +// The contents of this file are subject to the Mozilla Public License +// Version 1.1 (the "License"); you may not use this file except in +// compliance with the License. You may obtain a copy of the License at +// http://www.mozilla.org/MPL/ +// +// Software distributed under the License is distributed on an "AS IS" +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +// License for the specific language governing rights and limitations +// under the License. +// +// The Original Code is AgateLib. +// +// The Initial Developer of the Original Code is Erik Ylvisaker. +// Portions created by Erik Ylvisaker are Copyright (C) 2006-2014. +// All Rights Reserved. +// +// Contributor(s): Erik Ylvisaker +// +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.IO +{ + /// <summary> + /// Structure which indicates where various assets are stored. + /// </summary> + public class AssetLocations + { + public AssetLocations() + { + Path = "."; + } + + /// <summary> + /// Path prefix to load surfaces from. + /// </summary> + public string Surfaces { get; set; } + /// <summary> + /// Path prefix to load sound effects from. + /// </summary> + public string Sound { get; set; } + /// <summary> + /// Path prefix to load music files from. + /// </summary> + public string Music { get; set; } + /// <summary> + /// Path prefix to load resource files from. + /// </summary> + public string Resources { get; set; } + /// <summary> + /// Path prefix to load user interface files from. + /// </summary> + public string UserInterface { get; set; } + + /// <summary> + /// Root path used to load all assets. + /// </summary> + public string Path { get; set; } + + public AssetLocations ExtraAssets { get; set; } + } +} Added: trunk/AgateLib/IO/Assets.cs =================================================================== --- trunk/AgateLib/IO/Assets.cs (rev 0) +++ trunk/AgateLib/IO/Assets.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -0,0 +1,184 @@ +using AgateLib.ApplicationModels; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.IO +{ + public static class Assets + { + static IReadFileProvider mAssetProvider; + static IReadFileProvider mSurfaces; + static IReadFileProvider mResources; + static IReadFileProvider mMusic; + static IReadFileProvider mSounds; + static IReadFileProvider mUserInterfaceAssets; + + public static void AddAssetLocations(IReadFileProvider ap, AssetLocations assetLocations) + { + // check for circular reference + VerifyNoncircular(assetLocations); + + var assetProvider = NewProviderFromSubdirectory(ap, assetLocations.Path); + var surfaces = NewProviderFromSubdirectory(assetProvider, assetLocations.Surfaces); + var sounds = NewProviderFromSubdirectory(assetProvider, assetLocations.Sound); + var music = NewProviderFromSubdirectory(assetProvider, assetLocations.Music); + var resources = NewProviderFromSubdirectory(assetProvider, assetLocations.Resources); + var userInterfaceAssets = NewProviderFromSubdirectory(assetProvider, assetLocations.UserInterface); + + AddOrCombine(ref mAssetProvider, assetProvider); + AddOrCombine(ref mSurfaces, surfaces); + AddOrCombine(ref mResources, resources); + AddOrCombine(ref mMusic, music); + AddOrCombine(ref mSounds, sounds); + AddOrCombine(ref mUserInterfaceAssets, userInterfaceAssets); + + if (assetLocations.ExtraAssets != null) + { + AddAssetLocations(ap, assetLocations.ExtraAssets); + } + } + + private static void VerifyNoncircular(AssetLocations al) + { + List<AssetLocations> examined = new List<AssetLocations>(); + + while (al.ExtraAssets != null) + { + if (examined.Contains(al)) + throw new AgateException("AssetLocations passed contains circular references."); + + examined.Add(al); + al = al.ExtraAssets; + } + } + + private static void AddOrCombine(ref IReadFileProvider storage, IReadFileProvider provider) + { + if (storage == null) + storage = provider; + else if (storage is ReadFileProviderList) + { + var rfpl = (ReadFileProviderList)storage; + + rfpl.Add(provider); + } + else + { + var rfpl = new ReadFileProviderList(); + + rfpl.Add(storage); + rfpl.Add(provider); + + storage = rfpl; + } + } + + static IReadFileProvider NewProviderFromSubdirectory(IReadFileProvider parent, string subdir) + { + if (string.IsNullOrWhiteSpace(subdir) || subdir == ".") + return parent; + + return new SubdirectoryProvider(parent, subdir); + } + + internal static IReadFileProvider AssetProvider { get { return mAssetProvider; } set { mAssetProvider = value; } } + public static IReadFileProvider Surfaces { get { return mSurfaces; } set { mSurfaces = value; } } + public static IReadFileProvider Resources { get { return mResources; } set { mResources = value; } } + public static IReadFileProvider Music { get { return mMusic; } set { mMusic = value; } } + public static IReadFileProvider Sounds { get { return mSounds; } set { mSounds = value; } } + public static IReadFileProvider UserInterfaceAssets { get { return mUserInterfaceAssets; } set { mUserInterfaceAssets = value; } } + + /// <summary> + /// Opens the specified file returning a stream. Throws + /// FileNotFoundException if the file does not exist. + /// </summary> + /// <param name="filename">The path and filename of the file to read from.</param> + /// <returns></returns> + public static Task<Stream> OpenReadAsync(string filename) + { + return mAssetProvider.OpenReadAsync(filename); + } + + /// <summary> + /// Opens the specified file returning a stream. Throws + /// FileNotFoundException if the file does not exist. + /// </summary> + /// <param name="filename">The path and filename of the file to read from.</param> + /// <returns></returns> + public static Stream OpenRead(string filename) + { + return mAssetProvider.OpenRead(filename); + } + /// <summary> + /// Checks to if the specified file exists in the file provider. + /// </summary> + /// <param name="filename"></param> + /// <returns></returns> + public static bool FileExists(string filename) + { + return mAssetProvider.FileExists(filename); + } + + /// <summary> + /// Enumerates through all existing filenames in the file provider. + /// </summary> + /// <returns></returns> + public static IEnumerable<string> GetAllFiles() + { + return mAssetProvider.GetAllFiles(); + } + + /// <summary> + /// Enumerates through all filenames which match the specified search pattern. + /// </summary> + /// <remarks>The search pattern is not regex style pattern matching, rather it should + /// be bash pattern matching, so a searchPattern of "*" would match all files, and + /// "*.*" would match all filenames with a period in them.</remarks> + /// <param name="searchPattern"></param> + /// <returns></returns> + public static IEnumerable<string> GetAllFiles(string searchPattern) + { + return mAssetProvider.GetAllFiles(searchPattern); + } + /// <summary> + /// Returns a string containing the entire contents of the specified file. + /// </summary> + /// <param name="filename">The path and filename of the file to read from.</param> + /// <returns></returns> + public static string ReadAllText(string filename) + { + return mAssetProvider.ReadAllText(filename); + } + + /// <summary> + /// Returns true if the specified filename points to an actual file on disk. + /// If this method returns false, then ResolveFile will throw an exception + /// for that file. + /// </summary> + /// <param name="filename"></param> + /// <returns></returns> + public static bool IsRealFile(string filename) + { + return mAssetProvider.IsRealFile(filename); + } + + /// <summary> + /// Returns the full path of the given filename. + /// </summary> + /// <param name="filename"></param> + /// <returns></returns> + public static string ResolveFile(string filename) + { + return mAssetProvider.ResolveFile(filename); + } + + /// <summary> + /// Returns true if the file system is not a physical file system. + /// </summary> + public static bool IsLogicalFilesystem { get { return mAssetProvider.IsLogicalFilesystem; } } + } +} Modified: trunk/AgateLib/IO/FileProvider.cs =================================================================== --- trunk/AgateLib/IO/FileProvider.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib/IO/FileProvider.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -29,32 +29,25 @@ { public static void Initialize(IReadFileProvider assetProvider, AssetLocations assetLocations) { - Assets = assetProvider; - - SurfaceAssets = NewProviderFromSubdirectory(Assets, assetLocations.Surfaces); - SoundAssets = NewProviderFromSubdirectory(Assets, assetLocations.Sound); - MusicAssets = NewProviderFromSubdirectory(Assets, assetLocations.Music); - ResourceAssets = NewProviderFromSubdirectory(Assets, assetLocations.Resources); - UserInterfaceAssets = NewProviderFromSubdirectory(Assets, assetLocations.UserInterface); + AgateLib.IO.Assets.AddAssetLocations(assetProvider, assetLocations); } - public static IReadFileProvider Assets { get; set; } + [Obsolete("Use AgateLib.IO.Assets instead.")] + public static IReadFileProvider Assets { get { return AgateLib.IO.Assets.AssetProvider; } } - public static IReadFileProvider SurfaceAssets { get; set; } - public static IReadFileProvider ResourceAssets { get; set; } - public static IReadFileProvider MusicAssets { get; set; } - public static IReadFileProvider SoundAssets { get; set; } - public static IReadFileProvider UserInterfaceAssets { get; set; } + [Obsolete("Use AgateLib.IO.Assets.Surfaces instead.")] + public static IReadFileProvider SurfaceAssets { get { return AgateLib.IO.Assets.Surfaces; } } + [Obsolete("Use AgateLib.IO.Assets.Resources instead.")] + public static IReadFileProvider ResourceAssets { get { return AgateLib.IO.Assets.Resources; } } + [Obsolete("Use AgateLib.IO.Assets.Music instead.")] + public static IReadFileProvider MusicAssets { get { return AgateLib.IO.Assets.Music; } } + [Obsolete("Use AgateLib.IO.Assets.Sounds instead.")] + public static IReadFileProvider SoundAssets { get { return AgateLib.IO.Assets.Sounds; } } + [Obsolete("Use AgateLib.IO.Assets.UserInterfaceAssets instead.")] + public static IReadFileProvider UserInterfaceAssets { get { return AgateLib.IO.Assets.UserInterfaceAssets; } } public static IReadWriteFileProvider UserFiles { get; set; } - static IReadFileProvider NewProviderFromSubdirectory(IReadFileProvider parent, string subdir) - { - if (string.IsNullOrWhiteSpace(subdir) || subdir == ".") - return parent; - return new SubdirectoryProvider(parent, subdir); - } - } } Copied: trunk/AgateLib/IO/ReadFileProviderList.cs (from rev 1534, trunk/AgateLib.Platform.WinForms/IO/FileProviderList.cs) =================================================================== --- trunk/AgateLib/IO/ReadFileProviderList.cs (rev 0) +++ trunk/AgateLib/IO/ReadFileProviderList.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -0,0 +1,310 @@ +// The contents of this file are subject to the Mozilla Public License +// Version 1.1 (the "License"); you may not use this file except in +// compliance with the License. You may obtain a copy of the License at +// http://www.mozilla.org/MPL/ +// +// Software distributed under the License is distributed on an "AS IS" +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +// License for the specific language governing rights and limitations +// under the License. +// +// The Original Code is AgateLib. +// +// The Initial Developer of the Original Code is Erik Ylvisaker. +// Portions created by Erik Ylvisaker are Copyright (C) 2006-2014. +// All Rights Reserved. +// +// Contributor(s): Erik Ylvisaker +// +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; +using System.Threading.Tasks; + +namespace AgateLib.IO +{ + /// <summary> + /// Contains a list of IFileProvider objects that are used to search for + /// and open files. + /// </summary> + public class ReadFileProviderList : IList<IReadFileProvider>, IReadFileProvider + { + List<IReadFileProvider> mProviders = new List<IReadFileProvider>(); + + /// <summary> + /// Returns the IFileProvider object which would return the specified + /// file when OpenRead is called. Throws a FileNotFoundException if the file is not available. + /// </summary> + /// <param name="filename"></param> + /// <returns></returns> + public IReadFileProvider GetProvider(string filename) + { + for (int i = mProviders.Count - 1; i >= 0; i--) + { + if (mProviders[i].FileExists(filename)) + return mProviders[i]; + } + + throw new FileNotFoundException(string.Format( + "Could not find the file {0}.", filename)); + } + /// <summary> + /// Opens a specified file by searching backwards through the list of + /// providers until a matching filename is found. A FileNotFoundException + /// is thrown if the file does not exist. + /// </summary> + /// <param name="filename">The filename to search for.</param> + /// <returns></returns> + public async Task<Stream> OpenReadAsync(string filename) + { + if (string.IsNullOrEmpty(filename)) + throw new ArgumentNullException("You must supply a file name."); + + for (int i = mProviders.Count - 1; i >= 0; i--) + { + if (mProviders[i].FileExists(filename)) + { + return await mProviders[i].OpenReadAsync(filename); + } + } + + throw new FileNotFoundException(string.Format( + "Could not find the file {0}.", filename)); + } + + + + public bool IsRealFile(string filename) + { + if (string.IsNullOrEmpty(filename)) + throw new ArgumentNullException("You must supply a file name."); + + for (int i = mProviders.Count - 1; i >= 0; i--) + { + if (mProviders[i].FileExists(filename)) + { + return mProviders[i].IsRealFile(filename); + } + } + + throw new FileNotFoundException(string.Format( + "Could not find the file {0}.", filename)); + } + + public string ResolveFile(string filename) + { + if (string.IsNullOrEmpty(filename)) + throw new ArgumentNullException("You must supply a file name."); + + for (int i = mProviders.Count - 1; i >= 0; i--) + { + if (mProviders[i].FileExists(filename)) + { + return mProviders[i].ResolveFile(filename); + } + } + + throw new FileNotFoundException(string.Format( + "Could not find the file {0}.", filename)); + } + + /// <summary> + /// Returns all filenames matching the specified filter in + /// all file providers. + /// </summary> + /// <param name="filter"></param> + /// <returns></returns> + public IEnumerable<string> GetAllFiles(string filter) + { + for (int i = mProviders.Count - 1; i >= 0; i--) + { + foreach (string files in mProviders[i].GetAllFiles(filter)) + yield return files; + } + } + /// <summary> + /// Returns all filenames in all file providers. + /// </summary> + /// <returns></returns> + public IEnumerable<string> GetAllFiles() + { + for (int i = mProviders.Count - 1; i >= 0; i--) + { + foreach (string files in mProviders[i].GetAllFiles()) + yield return files; + } + } + + /// <summary> + /// Returns true if the specified file exists in a file provider. + /// </summary> + /// <param name="filename"></param> + /// <returns></returns> + public bool FileExists(string filename) + { + for (int i = mProviders.Count - 1; i >= 0; i--) + { + if (mProviders[i].FileExists(filename)) + return true; + } + + return false; + } + + #region IList<IFileProvider> Members + + /// <summary> + /// Returns the index of the specified IFileProvider. + /// </summary> + /// <param name="item"></param> + /// <returns></returns> + public int IndexOf(IReadFileProvider item) + { + return mProviders.IndexOf(item); + } + + /// <summary> + /// Insers an IFileProvider into the list. + /// </summary> + /// <param name="index"></param> + /// <param name="item"></param> + public void Insert(int index, IReadFileProvider item) + { + if (item is ReadFileProviderList) + { + if (item == this) throw new ArgumentException("Cannot add a FileProviderList to itself!"); + } + + mProviders.Insert(index, item); + } + /// <summary> + /// Removes an IFileProvider from the list. + /// </summary> + /// <param name="index"></param> + public void RemoveAt(int index) + { + mProviders.RemoveAt(index); + } + /// <summary> + /// Gets or sets the IFileProvider at the specified location. + /// </summary> + /// <param name="index"></param> + /// <returns></returns> + public IReadFileProvider this[int index] + { + get + { + return mProviders[index]; + } + set + { + if (value is ReadFileProviderList) + { + if (value == this) throw new ArgumentException("Cannot add a FileProviderList to itself!"); + } + + mProviders[index] = value; + } + } + + #endregion + #region ICollection<IFileProvider> Members + + /// <summary> + /// Adds an IFileProvider to the list. + /// </summary> + /// <param name="item"></param> + public void Add(IReadFileProvider item) + { + if (item is ReadFileProviderList) + { + if (item == this) throw new ArgumentException("Cannot add a FileProviderList to itself!"); + } + mProviders.Add(item); + } + /// <summary> + /// Clears the list. + /// </summary> + public void Clear() + { + mProviders.Clear(); + } + /// <summary> + /// Returns true if the list contains the specified IFileProvider. + /// </summary> + /// <param name="item"></param> + /// <returns></returns> + public bool Contains(IReadFileProvider item) + { + return mProviders.Contains(item); + } + + void ICollection<IReadFileProvider>.CopyTo(IReadFileProvider[] array, int arrayIndex) + { + mProviders.CopyTo(array, arrayIndex); + } + /// <summary> + /// Gets the number of items in the list. + /// </summary> + public int Count + { + get { return mProviders.Count; } + } + /// <summary> + /// Always returns false. + /// </summary> + public bool IsReadOnly + { + get { return false; } + } + /// <summary> + /// Removes an IFileProvider from the list. + /// </summary> + /// <param name="item"></param> + /// <returns></returns> + public bool Remove(IReadFileProvider item) + { + return mProviders.Remove(item); + } + + #endregion + #region IEnumerable<IFileProvider> Members + + /// <summary> + /// Enumerates items. + /// </summary> + /// <returns></returns> + public IEnumerator<IReadFileProvider> GetEnumerator() + { + return mProviders.GetEnumerator(); + } + + #endregion + #region IEnumerable Members + + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + #endregion + + /// <summary> + /// Returns a string containing all the text in the specified file. + /// </summary> + /// <param name="filename">The name of the file to read from.</param> + /// <returns></returns> + public string ReadAllText(string filename) + { + Stream s = OpenReadAsync(filename).Result; + + return new StreamReader(s).ReadToEnd(); + } + + public bool IsLogicalFilesystem + { + get { return true; } + } + } +} Modified: trunk/AgateLib/Serialization/Xle/XleSerializer.cs =================================================================== --- trunk/AgateLib/Serialization/Xle/XleSerializer.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib/Serialization/Xle/XleSerializer.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -60,7 +60,7 @@ public XleSerializer(Type objectType, IPlatformSerialization objectConstructor = null) { if (objectConstructor == null) - objectConstructor = Core.Factory.PlatformFactory.CreateDefaultSerializationConstructor(); + objectConstructor = new AgateLib.Platform.Common.PlatformImplementation.PlatformSerialization();// Core.Factory.PlatformFactory.CreateDefaultSerializationConstructor(); ObjectConstructor = objectConstructor; Modified: trunk/AgateLib/UserInterface/Css/Rendering/CssRenderer.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Rendering/CssRenderer.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib/UserInterface/Css/Rendering/CssRenderer.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -153,7 +153,7 @@ #endregion; - public bool InTransition { get; private set;} + public bool InTransition { get; private set; } public void Draw() { @@ -176,6 +176,8 @@ { if (anim.Style.Data.Overflow == CssOverflow.Visible) return false; + if (anim.ClientRect.Width == 0 || anim.ClientRect.Height == 0) + return true; Rectangle clipRect = anim.ClientToScreen(new Rectangle(0, 0, anim.ClientRect.Width, anim.ClientRect.Height)); @@ -187,6 +189,12 @@ { bool clipping = false; + if (anim.Style.Data.Overflow != CssOverflow.Visible && + (anim.ClientRect.Width == 0 || anim.ClientRect.Height == 0)) + { + return; + } + try { clipping = PushClipRect(anim); Modified: trunk/AgateLib.Platform.WinForms/AgateLib.Platform.WinForms.csproj =================================================================== --- trunk/AgateLib.Platform.WinForms/AgateLib.Platform.WinForms.csproj 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Platform.WinForms/AgateLib.Platform.WinForms.csproj 2014-10-13 02:36:59 UTC (rev 1537) @@ -131,7 +131,6 @@ <DependentUpon>frmGuiDebug.cs</DependentUpon> </Compile> <Compile Include="PixelBufferExtensions.cs" /> - <Compile Include="IO\FileProviderList.cs" /> <Compile Include="IO\FileSystemProvider.cs" /> <Compile Include="PlatformImplementation\FormsPlatformInfo.cs" /> <Compile Include="IO\TgzFileProvider.cs" /> Modified: trunk/AgateLib.Platform.WinForms/Factories/FormsFactory.cs =================================================================== --- trunk/AgateLib.Platform.WinForms/Factories/FormsFactory.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Platform.WinForms/Factories/FormsFactory.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -2,6 +2,7 @@ using AgateLib.ApplicationModels; using AgateLib.DisplayLib; using AgateLib.Drivers; +using AgateLib.IO; using AgateLib.Platform.WinForms.Resources; using System; using System.Collections.Generic; Modified: trunk/AgateLib.Platform.WinForms/Factories/PlatformFactory.cs =================================================================== --- trunk/AgateLib.Platform.WinForms/Factories/PlatformFactory.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Platform.WinForms/Factories/PlatformFactory.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -27,7 +27,7 @@ public IReadFileProvider AssetFileProvider { get; private set; } - public void SetAssetLocations(AgateLib.ApplicationModels.AssetLocations assetLocations) + public void SetAssetLocations(AssetLocations assetLocations) { AssetFileProvider = new FileSystemProvider(System.IO.Path.GetFullPath(assetLocations.Path)); } Deleted: trunk/AgateLib.Platform.WinForms/IO/FileProviderList.cs =================================================================== --- trunk/AgateLib.Platform.WinForms/IO/FileProviderList.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Platform.WinForms/IO/FileProviderList.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -1,318 +0,0 @@ -// The contents of this file are subject to the Mozilla Public License -// Version 1.1 (the "License"); you may not use this file except in -// compliance with the License. You may obtain a copy of the License at -// http://www.mozilla.org/MPL/ -// -// Software distributed under the License is distributed on an "AS IS" -// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -// License for the specific language governing rights and limitations -// under the License. -// -// The Original Code is AgateLib. -// -// The Initial Developer of the Original Code is Erik Ylvisaker. -// Portions created by Erik Ylvisaker are Copyright (C) 2006-2014. -// All Rights Reserved. -// -// Contributor(s): Erik Ylvisaker -// -using System; -using System.Collections.Generic; -using System.Text; -using System.IO; -using System.Threading.Tasks; - -namespace AgateLib.Platform.WinForms.IO -{ - /// <summary> - /// Contains a list of IFileProvider objects that are used to search for - /// and open files. - /// </summary> - public class FileProviderList : IList<IReadFileProvider>, IReadFileProvider - { - List<IReadFileProvider> mProviders = new List<IReadFileProvider>(); - - /// <summary> - /// Returns the IFileProvider object which would return the specified - /// file when OpenRead is called. Throws a FileNotFoundException if the file is not available. - /// </summary> - /// <param name="filename"></param> - /// <returns></returns> - public IReadFileProvider GetProvider(string filename) - { - for (int i = mProviders.Count - 1; i >= 0; i--) - { - if (mProviders[i].FileExists(filename)) - return mProviders[i]; - } - - throw new FileNotFoundException(string.Format( - "Could not find the file {0}.", filename)); - } - /// <summary> - /// Opens a specified file by searching backwards through the list of - /// providers until a matching filename is found. A FileNotFoundException - /// is thrown if the file does not exist. - /// </summary> - /// <param name="filename">The filename to search for.</param> - /// <returns></returns> - public async Task<Stream> OpenReadAsync(string filename) - { - if (string.IsNullOrEmpty(filename)) - throw new ArgumentNullException("You must supply a file name."); - - for (int i = mProviders.Count - 1; i >= 0; i--) - { - if (mProviders[i].FileExists(filename)) - { - return await mProviders[i].OpenReadAsync(filename); - } - } - - throw new FileNotFoundException(string.Format( - "Could not find the file {0}.", filename)); - } - - - - public bool IsRealFile(string filename) - { - if (string.IsNullOrEmpty(filename)) - throw new ArgumentNullException("You must supply a file name."); - - for (int i = mProviders.Count - 1; i >= 0; i--) - { - if (mProviders[i].FileExists(filename)) - { - return mProviders[i].IsRealFile(filename); - } - } - - throw new FileNotFoundException(string.Format( - "Could not find the file {0}.", filename)); - } - - public string ResolveFile(string filename) - { - if (string.IsNullOrEmpty(filename)) - throw new ArgumentNullException("You must supply a file name."); - - for (int i = mProviders.Count - 1; i >= 0; i--) - { - if (mProviders[i].FileExists(filename)) - { - return mProviders[i].ResolveFile(filename); - } - } - - throw new FileNotFoundException(string.Format( - "Could not find the file {0}.", filename)); - } - - /// <summary> - /// Returns all filenames matching the specified filter in - /// all file providers. - /// </summary> - /// <param name="filter"></param> - /// <returns></returns> - public IEnumerable<string> GetAllFiles(string filter) - { - for (int i = mProviders.Count - 1; i >= 0; i--) - { - foreach (string files in mProviders[i].GetAllFiles(filter)) - yield return files; - } - } - /// <summary> - /// Returns all filenames in all file providers. - /// </summary> - /// <returns></returns> - public IEnumerable<string> GetAllFiles() - { - for (int i = mProviders.Count - 1; i >= 0; i--) - { - foreach (string files in mProviders[i].GetAllFiles()) - yield return files; - } - } - - /// <summary> - /// Returns true if the specified file exists in a file provider. - /// </summary> - /// <param name="filename"></param> - /// <returns></returns> - public bool FileExists(string filename) - { - for (int i = mProviders.Count - 1; i >= 0; i--) - { - if (mProviders[i].FileExists(filename)) - return true; - } - - return false; - } - /// <summary> - /// Adds a path in the filesystem to the list of locations to search when opening a file. - /// </summary> - /// <param name="path"></param> - public void AddPath(string path) - { - Add(new FileSystemProvider(path)); - } - - #region IList<IFileProvider> Members - - /// <summary> - /// Returns the index of the specified IFileProvider. - /// </summary> - /// <param name="item"></param> - /// <returns></returns> - public int IndexOf(IReadFileProvider item) - { - return mProviders.IndexOf(item); - } - - /// <summary> - /// Insers an IFileProvider into the list. - /// </summary> - /// <param name="index"></param> - /// <param name="item"></param> - public void Insert(int index, IReadFileProvider item) - { - if (item is FileProviderList) - { - if (item == this) throw new ArgumentException("Cannot add a FileProviderList to itself!"); - } - - mProviders.Insert(index, item); - } - /// <summary> - /// Removes an IFileProvider from the list. - /// </summary> - /// <param name="index"></param> - public void RemoveAt(int index) - { - mProviders.RemoveAt(index); - } - /// <summary> - /// Gets or sets the IFileProvider at the specified location. - /// </summary> - /// <param name="index"></param> - /// <returns></returns> - public IReadFileProvider this[int index] - { - get - { - return mProviders[index]; - } - set - { - if (value is FileProviderList) - { - if (value == this) throw new ArgumentException("Cannot add a FileProviderList to itself!"); - } - - mProviders[index] = value; - } - } - - #endregion - #region ICollection<IFileProvider> Members - - /// <summary> - /// Adds an IFileProvider to the list. - /// </summary> - /// <param name="item"></param> - public void Add(IReadFileProvider item) - { - if (item is FileProviderList) - { - if (item == this) throw new ArgumentException("Cannot add a FileProviderList to itself!"); - } - mProviders.Add(item); - } - /// <summary> - /// Clears the list. - /// </summary> - public void Clear() - { - mProviders.Clear(); - } - /// <summary> - /// Returns true if the list contains the specified IFileProvider. - /// </summary> - /// <param name="item"></param> - /// <returns></returns> - public bool Contains(IReadFileProvider item) - { - return mProviders.Contains(item); - } - - void ICollection<IReadFileProvider>.CopyTo(IReadFileProvider[] array, int arrayIndex) - { - mProviders.CopyTo(array, arrayIndex); - } - /// <summary> - /// Gets the number of items in the list. - /// </summary> - public int Count - { - get { return mProviders.Count; } - } - /// <summary> - /// Always returns false. - /// </summary> - public bool IsReadOnly - { - get { return false; } - } - /// <summary> - /// Removes an IFileProvider from the list. - /// </summary> - /// <param name="item"></param> - /// <returns></returns> - public bool Remove(IReadFileProvider item) - { - return mProviders.Remove(item); - } - - #endregion - #region IEnumerable<IFileProvider> Members - - /// <summary> - /// Enumerates items. - /// </summary> - /// <returns></returns> - public IEnumerator<IReadFileProvider> GetEnumerator() - { - return mProviders.GetEnumerator(); - } - - #endregion - #region IEnumerable Members - - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - - #endregion - - /// <summary> - /// Returns a string containing all the text in the specified file. - /// </summary> - /// <param name="filename">The name of the file to read from.</param> - /// <returns></returns> - public string ReadAllText(string filename) - { - Stream s = OpenReadAsync(filename).Result; - - return new StreamReader(s).ReadToEnd(); - } - - public bool IsLogicalFilesystem - { - get { return true; } - } - } -} Modified: trunk/AgateLib.Platform.WindowsMetro/Factories/WinPlatformFactory.cs =================================================================== --- trunk/AgateLib.Platform.WindowsMetro/Factories/WinPlatformFactory.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Platform.WindowsMetro/Factories/WinPlatformFactory.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using AgateLib.ApplicationModels; +using AgateLib.IO; namespace AgateLib.Platform.WindowsMetro.Factories { Modified: trunk/AgateLib.Platform.WindowsMetro/Factories/WindowsFactory.cs =================================================================== --- trunk/AgateLib.Platform.WindowsMetro/Factories/WindowsFactory.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Platform.WindowsMetro/Factories/WindowsFactory.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -2,6 +2,7 @@ using AgateLib.DisplayLib; using AgateLib.Drivers; using AgateLib.Drivers.NullDrivers; +using AgateLib.IO; using AgateLib.Platform.WindowsStore; using AgateLib.Platform.WindowsStore.Factories; using SharpDX.SimpleInitializer; Modified: trunk/AgateLib.Platform.WindowsMetro/WindowsInitializer.cs =================================================================== --- trunk/AgateLib.Platform.WindowsMetro/WindowsInitializer.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Platform.WindowsMetro/WindowsInitializer.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -4,6 +4,7 @@ using SharpDX.SimpleInitializer; using System; using AgateLib.Platform.WindowsMetro.Factories; +using AgateLib.IO; namespace AgateLib.Platform.WindowsMetro { Modified: trunk/AgateLib.Platform.WindowsPhone/Factories/WPPlatformFactory.cs =================================================================== --- trunk/AgateLib.Platform.WindowsPhone/Factories/WPPlatformFactory.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Platform.WindowsPhone/Factories/WPPlatformFactory.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using AgateLib.ApplicationModels; +using AgateLib.IO; namespace AgateLib.Platform.WindowsPhone.Factories { Modified: trunk/AgateLib.Platform.WindowsPhone/Factories/WindowsPhoneFactory.cs =================================================================== --- trunk/AgateLib.Platform.WindowsPhone/Factories/WindowsPhoneFactory.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Platform.WindowsPhone/Factories/WindowsPhoneFactory.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -2,6 +2,7 @@ using AgateLib.DisplayLib; using AgateLib.Drivers; using AgateLib.Drivers.NullDrivers; +using AgateLib.IO; using AgateLib.Platform.WindowsStore; using AgateLib.Platform.WindowsStore.Factories; using SharpDX.SimpleInitializer; Modified: trunk/AgateLib.Platform.WindowsPhone/WindowsPhoneInitializer.cs =================================================================== --- trunk/AgateLib.Platform.WindowsPhone/WindowsPhoneInitializer.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Platform.WindowsPhone/WindowsPhoneInitializer.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -4,6 +4,7 @@ using SharpDX.SimpleInitializer; using System; using AgateLib.Platform.WindowsPhone.Factories; +using AgateLib.IO; namespace AgateLib.Platform.WindowsPhone { Modified: trunk/AgateLib.Platform.WindowsStoreCommon/AgateLib.Platform.WindowsStoreCommon.csproj =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/AgateLib.Platform.WindowsStoreCommon.csproj 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Platform.WindowsStoreCommon/AgateLib.Platform.WindowsStoreCommon.csproj 2014-10-13 02:36:59 UTC (rev 1537) @@ -100,7 +100,9 @@ <Compile Include="Factories\FakePath.cs" /> <Compile Include="Interop.cs" /> <Compile Include="IRenderTargetAdapter.cs" /> + <Compile Include="PlatformImplementation\AgateConsoleImpl.cs" /> <Compile Include="PlatformImplementation\DiagnosticsStopwatch.cs" /> + <Compile Include="PlatformImplementation\IsolatedStorageFileProvider.cs" /> <Compile Include="PlatformImplementation\WindowsStoreAssetFileProvider.cs" /> <Compile Include="PlatformImplementation\WindowsStorePlatformFactory.cs" /> <Compile Include="PlatformImplementation\WindowsStorePlatformInfo.cs" /> Modified: trunk/AgateLib.Platform.WindowsStoreCommon/AudioImplementation/XAudio2_Music.cs =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/AudioImplementation/XAudio2_Music.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Platform.WindowsStoreCommon/AudioImplementation/XAudio2_Music.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -188,50 +188,44 @@ * */ public override void Dispose() { - throw new NotImplementedException(); } public override bool IsPlaying { - get { throw new NotImplementedException(); } + get { return false; } } protected override void OnSetLoop(bool value) { - throw new NotImplementedException(); } public override double Pan { get { - throw new NotImplementedException(); + return 0; } set { - throw new NotImplementedException(); } } public override void Play() { - throw new NotImplementedException(); } public override void Stop() { - throw new NotImplementedException(); } public override double Volume { get { - throw new NotImplementedException(); + return 1; } set { - throw new NotImplementedException(); } } } Modified: trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/SDX_Surface.cs =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/SDX_Surface.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/SDX_Surface.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -36,6 +36,7 @@ using Windows.UI.Core; using Windows.Graphics.Imaging; using Windows.Storage; +using System.Threading.Tasks; namespace AgateLib.Platform.WindowsStore.DisplayImplementation { @@ -48,6 +49,7 @@ SharpDX.Direct3D11.ShaderResourceView mTextureView; bool mIsLoaded; + IReadFileProvider mFileProvider; string mFileName; Rectangle mSrcRect; @@ -99,9 +101,10 @@ mDisplay = Display.Impl as SDX_Display; } - public SDX_Surface(string fileName) + public SDX_Surface(IReadFileProvider fileProvider, string fileName) : this() { + mFileProvider = fileProvider; mFileName = fileName; if (mDevice == null) @@ -200,14 +203,17 @@ var window = SDX_Display.MainThreadCoreWindow; - await window.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => - { - //var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(mFileName)); - //var sourceStream = await file.OpenStreamForReadAsync(); - var sourceStream = new NativeFileStream(mFileName, NativeFileMode.Open, NativeFileAccess.Read); + await window.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => await LoadFromFileDispatch()); + } + + private async Task LoadFromFileDispatch() + { + //var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(mFileName)); + //var sourceStream = await file.OpenStreamForReadAsync(); + //var sourceStream = new NativeFileStream(mFileName, NativeFileMode.Open, NativeFileAccess.Read); + var sourceStream = await mFileProvider.OpenReadAsync(mFileName); - ReadFromStream(sourceStream, true); - }); + ReadFromStream(sourceStream, true); } /// <summary> Modified: trunk/AgateLib.Platform.WindowsStoreCommon/Factories/DisplayFactory.cs =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/Factories/DisplayFactory.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Platform.WindowsStoreCommon/Factories/DisplayFactory.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -38,9 +38,9 @@ { return new SDX_DisplayWindow(owner, windowParams, RenderTargetAdapter); } - public SurfaceImpl CreateSurface(IReadFileProvider provider, string fileName) + public SurfaceImpl CreateSurface(IReadFileProvider provider, string filename) { - return new SDX_Surface(provider.ResolveFile(fileName)); + return new SDX_Surface(provider, filename); } public SurfaceImpl CreateSurface(Size surfaceSize) { Added: trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/AgateConsoleImpl.cs =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/AgateConsoleImpl.cs (rev 0) +++ trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/AgateConsoleImpl.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -0,0 +1,24 @@ +using AgateLib.Diagnostics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AgateLib.Platform.WindowsStore.PlatformImplementation +{ + class AgateConsoleImpl : AgateConsole + { + protected override void WriteLineImpl(string text) + { + } + + protected override void WriteImpl(string text) + { + } + + protected override long CurrentTime + { + get { return 0; } + } + } +} Added: trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/IsolatedStorageFileProvider.cs =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/IsolatedStorageFileProvider.cs (rev 0) +++ trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/IsolatedStorageFileProvider.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -0,0 +1,62 @@ +using AgateLib.IO; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.Platform.WindowsStore.PlatformImplementation +{ + class IsolatedStorageFileProvider : IReadWriteFileProvider + { + public async Task<Stream> OpenWriteAsync(string file) + { + return await Task.Run(() => new MemoryStream()); + } + + public void CreateDirectory(string folder) + { + } + + public async Task<Stream> OpenReadAsync(string filename) + { + return await Task.Run(() => new MemoryStream()); + } + + public bool FileExists(string filename) + { + return false; + } + + public IEnumerable<string> GetAllFiles() + { + yield break; + } + + public IEnumerable<string> GetAllFiles(string searchPattern) + { + yield break; + } + + public string ReadAllText(string filename) + { + return ""; + } + + public bool IsRealFile(string filename) + { + return true; + } + + public string ResolveFile(string filename) + { + return filename; + } + + public bool IsLogicalFilesystem + { + get { return false; } + } + } +} Modified: trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/WindowsStoreAssetFileProvider.cs =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/WindowsStoreAssetFileProvider.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/WindowsStoreAssetFileProvider.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Windows.ApplicationModel; using Windows.Storage; @@ -18,12 +19,17 @@ public WindowsStoreAssetFileProvider(string path) { - if (path.EndsWith("/") == false) - path += "/"; + if (path == ".") + uriBase = "ms-appx:///"; + else + { + if (path.EndsWith("/") == false) + path += "/"; - this.path = path; + this.path = path; - uriBase = "ms-appx:///" + path; + uriBase = "ms-appx:///" + path; + } } public async Task<System.IO.Stream> OpenReadAsync(string filename) { @@ -33,23 +39,84 @@ await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri).AsTask().ConfigureAwait(false); var randomAccessStream = await storageFile.OpenReadAsync().AsTask().ConfigureAwait(false); - + return randomAccessStream.AsStreamForRead(); } + public override string ToString() + { + return uriBase; + } public bool FileExists(string filename) { - throw new NotImplementedException(); + Uri uri = new Uri(uriBase + filename); + + try + { + StorageFile storageFile = + Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri).AsTask().Result; + + return true; + } + catch (AggregateException e) + { + if (e.InnerException is FileNotFoundException) + return false; + + throw; + } + } + IEnumerable<StorageFile> FilesInDirectory(string searchPattern, StorageFolder folder) + { + return FilesInDirectory(CreateRegex(searchPattern), folder); + } + private Regex CreateRegex(string searchPattern) + { + var regex = new Regex(searchPattern + .Replace(".", @"\.") + .Replace("?", ".") + .Replace("*", ".*")); + + return regex; + } + IEnumerable<StorageFile> FilesInDirectory(Regex searchPattern, StorageFolder folder) + { + var files = folder.GetFilesAsync().AsTask().Result; + + foreach (var file in files) + { + if (PatternMatches(searchPattern, file)) + yield return file; + } + + var folders = folder.GetFoldersAsync().AsTask().Result; + + foreach (var dir in folders) + { + foreach (var file in FilesInDirectory(searchPattern, dir)) + { + if (PatternMatches(searchPattern, file)) + yield return file; + } + } + } + + private bool PatternMatches(Regex searchPattern, StorageFile file) + { + return searchPattern.IsMatch(file.Path); + } + public IEnumerable<string> GetAllFiles() { - throw new NotImplementedException(); + return GetAllFiles("*"); } public IEnumerable<string> GetAllFiles(string searchPattern) { - throw new NotImplementedException(); + foreach(var file in FilesInDirectory(searchPattern, ApplicationData.Current.LocalFolder)) + yield return file.Path; } public string ReadAllText(string filename) Modified: trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/WindowsStorePlatformFactory.cs =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/WindowsStorePlatformFactory.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/WindowsStorePlatformFactory.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -1,5 +1,6 @@ using AgateLib.ApplicationModels; using AgateLib.Drivers; +using AgateLib.IO; using AgateLib.Platform.WindowsStore.PlatformImplementation; using System; using System.Collections.Generic; @@ -13,8 +14,8 @@ public WindowsStorePlatformFactory(bool handheld, AssetLocations assetLocations) { Info = new WindowsStorePlatformInfo(handheld); - AssetFileProvider = new WindowsStoreAssetFileProvider(assetLocations.Path); - + AssetFileProvider = new WindowsStoreAssetFileProvider("."); + FileProvider.UserFiles = new IsolatedStorageFileProvider(); } public PlatformInfo Info { get; private set;} public IReadFileProvider AssetFileProvider { get; private set; } @@ -31,7 +32,7 @@ public Diagnostics.AgateConsole CreateConsole() { - return null; + return new AgateConsoleImpl(); } public IO.IPath CreatePath() Modified: trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/SpriteTester/frmSpriteTester.cs =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/SpriteTester/frmSpriteTester.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/SpriteTester/frmSpriteTester.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -248,7 +248,7 @@ // since loading the sprite from the file failed, try it as a resource file. AgateResourceCollection resources = new AgateResourceCollection(filename); - AgateLib.IO.FileProvider.SurfaceAssets = new FileSystemProvider + AgateLib.IO.Assets.Surfaces = new FileSystemProvider (System.IO.Path.GetDirectoryName(filename)); if (resources.Sprites.ToArray().Length == 1) Modified: trunk/AgateLib.Tests/Tests.WindowsMetro/TestContainer.xaml.cs =================================================================== --- trunk/AgateLib.Tests/Tests.WindowsMetro/TestContainer.xaml.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Tests/Tests.WindowsMetro/TestContainer.xaml.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -17,6 +17,7 @@ using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; +using AgateLib.IO; // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238 Modified: trunk/AgateLib.Tests/Tests.WindowsPhone/TestContainer.xaml.cs =================================================================== --- trunk/AgateLib.Tests/Tests.WindowsPhone/TestContainer.xaml.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Tests/Tests.WindowsPhone/TestContainer.xaml.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -17,6 +17,7 @@ using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; +using AgateLib.IO; // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkID=390556 Modified: trunk/AgateLib.Tests/UnitTests/Resources/SerializationTest.cs =================================================================== --- trunk/AgateLib.Tests/UnitTests/Resources/SerializationTest.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Tests/UnitTests/Resources/SerializationTest.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -2,6 +2,7 @@ using AgateLib.DisplayLib; using AgateLib.DisplayLib.BitmapFont; using AgateLib.Geometry; +using AgateLib.IO; using AgateLib.Resources.DC; using AgateLib.Sprites; using AgateLib.Testing.Fakes; Modified: trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs =================================================================== --- trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -2,6 +2,7 @@ using AgateLib.DisplayLib; using AgateLib.DisplayLib.ImplementationBase; using AgateLib.Geometry; +using AgateLib.IO; using AgateLib.Platform.WinForms.ApplicationModels; using AgateLib.Testing.Fakes; using AgateLib.UserInterface.Css.Documents; Modified: trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssParseTest.cs =================================================================== --- trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssParseTest.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssParseTest.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -1,5 +1,6 @@ using AgateLib.ApplicationModels; using AgateLib.Geometry; +using AgateLib.IO; using AgateLib.Testing.Fakes; using AgateLib.UnitTesting; using AgateLib.UserInterface.Css.Binders; Modified: trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssTestBase.cs =================================================================== --- trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssTestBase.cs 2014-10-11 05:52:54 UTC (rev 1536) +++ trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssTestBase.cs 2014-10-13 02:36:59 UTC (rev 1537) @@ -1,5 +1,6 @@ using AgateLib.ApplicationModels; using AgateLib.Geometry; +using AgateLib.IO; using AgateLib.Testing.Fakes; using AgateLib.UserInterface.Css.Binders; using AgateLib.UserInterface.Css.Documents; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2014-10-11 05:52:59
|
Revision: 1536 http://sourceforge.net/p/agate/code/1536 Author: kanato Date: 2014-10-11 05:52:54 +0000 (Sat, 11 Oct 2014) Log Message: ----------- Trying to resolve nuget package restore issues. Modified Paths: -------------- trunk/AgateLib.Platform.WindowsStoreCommon/AgateLib.Platform.WindowsStoreCommon.csproj trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj trunk/AgateLib.Tests/Tests.WinForms/AgateLib.Tests.WinForms.csproj trunk/AgateLib.Tests/UnitTests/AgateLib.Tests.UnitTests.csproj Added Paths: ----------- trunk/AgateLib/packages.config trunk/AgateLib.AgateSDL/packages.config trunk/AgateLib.Platform.WindowsStoreCommon/packages.config trunk/AgateLib.Tests/AgateLib.Tests.Portable/packages.config trunk/AgateLib.Tests/Tests.WinForms/packages.config trunk/AgateLib.Tests/Tests.WindowsMetro/packages.config trunk/AgateLib.Tests/Tests.WindowsPhone/packages.config trunk/AgateLib.Tests/UnitTests/packages.config Removed Paths: ------------- trunk/AgateLib/packages.config trunk/AgateLib.AgateSDL/packages.config trunk/AgateLib.Platform.WindowsStoreCommon/packages.config trunk/AgateLib.Tests/AgateLib.Tests.Portable/packages.config trunk/AgateLib.Tests/Tests.WinForms/packages.config trunk/AgateLib.Tests/Tests.WindowsMetro/packages.config trunk/AgateLib.Tests/Tests.WindowsPhone/packages.config trunk/AgateLib.Tests/UnitTests/packages.config Deleted: trunk/AgateLib/packages.config =================================================================== --- trunk/AgateLib/packages.config 2014-10-11 00:30:23 UTC (rev 1535) +++ trunk/AgateLib/packages.config 2014-10-11 05:52:54 UTC (rev 1536) @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<packages> - <package id="MSBuildTasks" version="1.4.0.65" targetFramework="portable-net45+win+wpa81+wp80+MonoAndroid10+MonoTouch10" /> -</packages> \ No newline at end of file Added: trunk/AgateLib/packages.config =================================================================== --- trunk/AgateLib/packages.config (rev 0) +++ trunk/AgateLib/packages.config 2014-10-11 05:52:54 UTC (rev 1536) @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="MSBuildTasks" version="1.4.0.65" targetFramework="portable-net45+win+wpa81+wp80" /> +</packages> \ No newline at end of file Deleted: trunk/AgateLib.AgateSDL/packages.config =================================================================== --- trunk/AgateLib.AgateSDL/packages.config 2014-10-11 00:30:23 UTC (rev 1535) +++ trunk/AgateLib.AgateSDL/packages.config 2014-10-11 05:52:54 UTC (rev 1536) @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<packages> - <package id="MSBuildTasks" version="1.4.0.65" targetFramework="net45" /> -</packages> \ No newline at end of file Added: trunk/AgateLib.AgateSDL/packages.config =================================================================== --- trunk/AgateLib.AgateSDL/packages.config (rev 0) +++ trunk/AgateLib.AgateSDL/packages.config 2014-10-11 05:52:54 UTC (rev 1536) @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="MSBuildTasks" version="1.4.0.65" targetFramework="net45" /> +</packages> \ No newline at end of file Modified: trunk/AgateLib.Platform.WindowsStoreCommon/AgateLib.Platform.WindowsStoreCommon.csproj =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/AgateLib.Platform.WindowsStoreCommon.csproj 2014-10-11 00:30:23 UTC (rev 1535) +++ trunk/AgateLib.Platform.WindowsStoreCommon/AgateLib.Platform.WindowsStoreCommon.csproj 2014-10-11 05:52:54 UTC (rev 1536) @@ -15,7 +15,7 @@ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <TargetFrameworkProfile>Profile32</TargetFrameworkProfile> <TargetFrameworkVersion>v4.6</TargetFrameworkVersion> - <NuGetPackageImportStamp>2455b0df</NuGetPackageImportStamp> + <NuGetPackageImportStamp>2117cc66</NuGetPackageImportStamp> <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir> <RestorePackages>true</RestorePackages> </PropertyGroup> @@ -40,7 +40,6 @@ </PropertyGroup> <ItemGroup> <!-- A reference to the entire .NET Framework is automatically included --> - <None Include="packages.config" /> <Content Include="Assets\Fonts\AgateMono-10.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> @@ -68,6 +67,7 @@ <Content Include="Resources\Basic2Dvert.fxo"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> + <None Include="packages.config" /> <None Include="Resources\buildshaders.bat" /> <None Include="Resources\fxc.bat" /> </ItemGroup> @@ -111,6 +111,20 @@ <Compile Include="ApplicationModels\WindowsStoreSceneModelParameters.cs" /> </ItemGroup> <ItemGroup> + <Content Include="Resources\ShaderSource\Basic2Dpixel.hlsl" /> + <Content Include="Resources\ShaderSource\Basic2Dvert.hlsl" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\AgateLib\AgateLib.csproj"> + <Project>{9490b719-829e-43a7-a5fe-8001f8a81759}</Project> + <Name>AgateLib</Name> + </ProjectReference> + </ItemGroup> + <ItemGroup> + <TargetPlatform Include="Windows, Version=8.1" /> + <TargetPlatform Include="WindowsPhoneApp, Version=8.1" /> + </ItemGroup> + <ItemGroup> <Reference Include="SharpDX"> <HintPath>$(SharpDXPackageBinDir)\SharpDX.dll</HintPath> </Reference> @@ -124,36 +138,22 @@ <HintPath>..\packages\SharpDX.SimpleInitializer.1.0.0\lib\portable-netcore451+wpa81\SharpDX.SimpleInitializer.dll</HintPath> </Reference> <Reference Include="SharpDX.XAudio2"> - <HintPath>..\packages\SharpDX.2.6.2\Bin\DirectX11_2-Signed-winrt\SharpDX.XAudio2.dll</HintPath> + <HintPath>$(SharpDXPackageBinDir)\SharpDX.XAudio2.dll</HintPath> </Reference> </ItemGroup> - <ItemGroup> - <Content Include="Resources\ShaderSource\Basic2Dpixel.hlsl" /> - <Content Include="Resources\ShaderSource\Basic2Dvert.hlsl" /> - </ItemGroup> - <ItemGroup> - <ProjectReference Include="..\AgateLib\AgateLib.csproj"> - <Project>{9490b719-829e-43a7-a5fe-8001f8a81759}</Project> - <Name>AgateLib</Name> - </ProjectReference> - </ItemGroup> - <ItemGroup> - <TargetPlatform Include="Windows, Version=8.1" /> - <TargetPlatform Include="WindowsPhoneApp, Version=8.1" /> - </ItemGroup> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" /> - <Import Project="..\packages\SharpDX.2.6.2\build\SharpDX.targets" Condition="Exists('..\packages\SharpDX.2.6.2\build\SharpDX.targets')" /> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <PropertyGroup> <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> </PropertyGroup> + <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" /> <Error Condition="!Exists('..\packages\SharpDX.2.6.2\build\SharpDX.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SharpDX.2.6.2\build\SharpDX.targets'))" /> - <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" /> </Target> <PropertyGroup> <PreBuildEvent>cd "$(ProjectDir)\Resources" & "$(ProjectDir)Resources\buildshaders.bat" /Zi</PreBuildEvent> </PropertyGroup> <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> + <Import Project="..\packages\SharpDX.2.6.2\build\SharpDX.targets" Condition="Exists('..\packages\SharpDX.2.6.2\build\SharpDX.targets')" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> Deleted: trunk/AgateLib.Platform.WindowsStoreCommon/packages.config =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/packages.config 2014-10-11 00:30:23 UTC (rev 1535) +++ trunk/AgateLib.Platform.WindowsStoreCommon/packages.config 2014-10-11 05:52:54 UTC (rev 1536) @@ -1,9 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<packages> - <package id="MSBuildTasks" version="1.4.0.65" targetFramework="portable-win81+wpa81" /> - <package id="SharpDX" version="2.6.2" targetFramework="portable-win81+wpa81" /> - <package id="SharpDX.Direct3D11" version="2.6.2" targetFramework="portable-win81+wpa81" /> - <package id="SharpDX.DXGI" version="2.6.2" targetFramework="portable-win81+wpa81" /> - <package id="SharpDX.SimpleInitializer" version="1.0.0" targetFramework="portable-win81+wpa81" /> - <package id="SharpDX.XAudio2" version="2.6.2" targetFramework="portable-win81+wpa81" /> -</packages> \ No newline at end of file Added: trunk/AgateLib.Platform.WindowsStoreCommon/packages.config =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/packages.config (rev 0) +++ trunk/AgateLib.Platform.WindowsStoreCommon/packages.config 2014-10-11 05:52:54 UTC (rev 1536) @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="MSBuildTasks" version="1.4.0.65" targetFramework="portable-win81+wpa81" /> + <package id="SharpDX" version="2.6.2" targetFramework="portable-win81+wpa81" /> + <package id="SharpDX.Direct3D11" version="2.6.2" targetFramework="portable-win81+wpa81" /> + <package id="SharpDX.DXGI" version="2.6.2" targetFramework="portable-win81+wpa81" /> + <package id="SharpDX.SimpleInitializer" version="1.0.0" targetFramework="portable-win81+wpa81" /> + <package id="SharpDX.XAudio2" version="2.6.2" targetFramework="portable-win81+wpa81" /> +</packages> \ No newline at end of file Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj 2014-10-11 00:30:23 UTC (rev 1535) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj 2014-10-11 05:52:54 UTC (rev 1536) @@ -80,9 +80,6 @@ <Compile Include="UserInterfaceTests\TransitionTest.cs" /> </ItemGroup> <ItemGroup> - <None Include="packages.config" /> - </ItemGroup> - <ItemGroup> <Content Include="Assets\attacke.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> @@ -178,7 +175,9 @@ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> </ItemGroup> - <ItemGroup /> + <ItemGroup> + <None Include="packages.config" /> + </ItemGroup> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" /> <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> Deleted: trunk/AgateLib.Tests/AgateLib.Tests.Portable/packages.config =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/packages.config 2014-10-11 00:30:23 UTC (rev 1535) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/packages.config 2014-10-11 05:52:54 UTC (rev 1536) @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<packages> - <package id="MSBuildTasks" version="1.4.0.65" targetFramework="portable-net45+win+wpa81+wp80" /> -</packages> \ No newline at end of file Added: trunk/AgateLib.Tests/AgateLib.Tests.Portable/packages.config =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/packages.config (rev 0) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/packages.config 2014-10-11 05:52:54 UTC (rev 1536) @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="MSBuildTasks" version="1.4.0.65" targetFramework="portable-net45+win+wpa81+wp80" /> +</packages> \ No newline at end of file Modified: trunk/AgateLib.Tests/Tests.WinForms/AgateLib.Tests.WinForms.csproj =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/AgateLib.Tests.WinForms.csproj 2014-10-11 00:30:23 UTC (rev 1535) +++ trunk/AgateLib.Tests/Tests.WinForms/AgateLib.Tests.WinForms.csproj 2014-10-11 05:52:54 UTC (rev 1536) @@ -457,10 +457,10 @@ <None Include="Assets\CssTest.css"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> - <None Include="packages.config" /> <None Include="Assets\settings_list.txt"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> + <None Include="packages.config" /> </ItemGroup> <ItemGroup> <None Include="Assets\largeimage.png"> Deleted: trunk/AgateLib.Tests/Tests.WinForms/packages.config =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/packages.config 2014-10-11 00:30:23 UTC (rev 1535) +++ trunk/AgateLib.Tests/Tests.WinForms/packages.config 2014-10-11 05:52:54 UTC (rev 1536) @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<packages> - <package id="MSBuildTasks" version="1.4.0.65" targetFramework="net35" /> -</packages> \ No newline at end of file Added: trunk/AgateLib.Tests/Tests.WinForms/packages.config =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/packages.config (rev 0) +++ trunk/AgateLib.Tests/Tests.WinForms/packages.config 2014-10-11 05:52:54 UTC (rev 1536) @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="MSBuildTasks" version="1.4.0.65" targetFramework="net451" /> +</packages> \ No newline at end of file Deleted: trunk/AgateLib.Tests/Tests.WindowsMetro/packages.config =================================================================== --- trunk/AgateLib.Tests/Tests.WindowsMetro/packages.config 2014-10-11 00:30:23 UTC (rev 1535) +++ trunk/AgateLib.Tests/Tests.WindowsMetro/packages.config 2014-10-11 05:52:54 UTC (rev 1536) @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<packages> - <package id="MSBuildTasks" version="1.4.0.65" targetFramework="win81" /> -</packages> \ No newline at end of file Added: trunk/AgateLib.Tests/Tests.WindowsMetro/packages.config =================================================================== --- trunk/AgateLib.Tests/Tests.WindowsMetro/packages.config (rev 0) +++ trunk/AgateLib.Tests/Tests.WindowsMetro/packages.config 2014-10-11 05:52:54 UTC (rev 1536) @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="MSBuildTasks" version="1.4.0.65" targetFramework="win81" /> +</packages> \ No newline at end of file Deleted: trunk/AgateLib.Tests/Tests.WindowsPhone/packages.config =================================================================== --- trunk/AgateLib.Tests/Tests.WindowsPhone/packages.config 2014-10-11 00:30:23 UTC (rev 1535) +++ trunk/AgateLib.Tests/Tests.WindowsPhone/packages.config 2014-10-11 05:52:54 UTC (rev 1536) @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<packages> - <package id="MSBuildTasks" version="1.4.0.65" targetFramework="wpa81" /> -</packages> \ No newline at end of file Added: trunk/AgateLib.Tests/Tests.WindowsPhone/packages.config =================================================================== --- trunk/AgateLib.Tests/Tests.WindowsPhone/packages.config (rev 0) +++ trunk/AgateLib.Tests/Tests.WindowsPhone/packages.config 2014-10-11 05:52:54 UTC (rev 1536) @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="MSBuildTasks" version="1.4.0.65" targetFramework="wpa81" /> +</packages> \ No newline at end of file Modified: trunk/AgateLib.Tests/UnitTests/AgateLib.Tests.UnitTests.csproj =================================================================== --- trunk/AgateLib.Tests/UnitTests/AgateLib.Tests.UnitTests.csproj 2014-10-11 00:30:23 UTC (rev 1535) +++ trunk/AgateLib.Tests/UnitTests/AgateLib.Tests.UnitTests.csproj 2014-10-11 05:52:54 UTC (rev 1536) @@ -117,9 +117,6 @@ <Compile Include="Utility\RefTest.cs" /> </ItemGroup> <ItemGroup> - <None Include="packages.config" /> - </ItemGroup> - <ItemGroup> <ProjectReference Include="..\..\AgateLib.Platform.WinForms\AgateLib.Platform.WinForms.csproj"> <Project>{4b12561e-d37b-48a1-b6db-218e94906c22}</Project> <Name>AgateLib.Platform.WinForms</Name> @@ -133,6 +130,9 @@ <Name>AgateLib.Tests.Portable</Name> </ProjectReference> </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + </ItemGroup> <Choose> <When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'"> <ItemGroup> Deleted: trunk/AgateLib.Tests/UnitTests/packages.config =================================================================== --- trunk/AgateLib.Tests/UnitTests/packages.config 2014-10-11 00:30:23 UTC (rev 1535) +++ trunk/AgateLib.Tests/UnitTests/packages.config 2014-10-11 05:52:54 UTC (rev 1536) @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<packages> - <package id="MSBuildTasks" version="1.4.0.65" targetFramework="net45" /> -</packages> \ No newline at end of file Added: trunk/AgateLib.Tests/UnitTests/packages.config =================================================================== --- trunk/AgateLib.Tests/UnitTests/packages.config (rev 0) +++ trunk/AgateLib.Tests/UnitTests/packages.config 2014-10-11 05:52:54 UTC (rev 1536) @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="MSBuildTasks" version="1.4.0.65" targetFramework="net451" /> +</packages> \ 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...> - 2014-10-11 00:30:38
|
Revision: 1535 http://sourceforge.net/p/agate/code/1535 Author: kanato Date: 2014-10-11 00:30:23 +0000 (Sat, 11 Oct 2014) Log Message: ----------- Add writing files functionality. Modified Paths: -------------- trunk/AgateLib/Diagnostics/Log.cs trunk/AgateLib/IO/IReadWriteFileProvider.cs trunk/AgateLib.Platform.WinForms/IO/FileSystemProvider.cs trunk/AgateLib.Platform.WinForms/WinFormsInitializer.cs Modified: trunk/AgateLib/Diagnostics/Log.cs =================================================================== --- trunk/AgateLib/Diagnostics/Log.cs 2014-10-11 00:24:39 UTC (rev 1534) +++ trunk/AgateLib/Diagnostics/Log.cs 2014-10-11 00:30:23 UTC (rev 1535) @@ -34,5 +34,13 @@ { Debug.WriteLine(format, args); } + + public static void Indent() + { + } + + public static void Unindent() + { + } } } Modified: trunk/AgateLib/IO/IReadWriteFileProvider.cs =================================================================== --- trunk/AgateLib/IO/IReadWriteFileProvider.cs 2014-10-11 00:24:39 UTC (rev 1534) +++ trunk/AgateLib/IO/IReadWriteFileProvider.cs 2014-10-11 00:30:23 UTC (rev 1535) @@ -18,12 +18,17 @@ // using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; +using System.Threading.Tasks; namespace AgateLib.IO { public interface IReadWriteFileProvider : IReadFileProvider, IWriteFileProvider { + Task<Stream> OpenWriteAsync(string file); + + void CreateDirectory(string folder); } } Modified: trunk/AgateLib.Platform.WinForms/IO/FileSystemProvider.cs =================================================================== --- trunk/AgateLib.Platform.WinForms/IO/FileSystemProvider.cs 2014-10-11 00:24:39 UTC (rev 1534) +++ trunk/AgateLib.Platform.WinForms/IO/FileSystemProvider.cs 2014-10-11 00:30:23 UTC (rev 1535) @@ -30,7 +30,7 @@ /// FileSystemProvider implements IFileProvider, providing access to files /// from the operating system file system. /// </summary> - public class FileSystemProvider : IReadFileProvider + public class FileSystemProvider : IReadWriteFileProvider { string mPath; Uri mPathUri; @@ -66,7 +66,7 @@ throw new FileNotFoundException(string.Format("The file {0} was not found in the path {1}.", filename, mPath)); - return File.OpenRead(FindFileName(filename)); + return await Task.Run(() => File.OpenRead(FindFileName(filename))); } /// <summary> /// Returns true if the specified file exists. @@ -290,5 +290,18 @@ { get { return true; } } + + public async Task<Stream> OpenWriteAsync(string file) + { + string resolvedName = FindFileName(file); + + return await Task.Run(() => File.Open(resolvedName, FileMode.Create)); + } + + public void CreateDirectory(string folder) + { + DebugCrossPlatform(folder); + Directory.CreateDirectory(Path.Combine(mPath, folder)); + } } } Modified: trunk/AgateLib.Platform.WinForms/WinFormsInitializer.cs =================================================================== --- trunk/AgateLib.Platform.WinForms/WinFormsInitializer.cs 2014-10-11 00:24:39 UTC (rev 1534) +++ trunk/AgateLib.Platform.WinForms/WinFormsInitializer.cs 2014-10-11 00:30:23 UTC (rev 1535) @@ -1,8 +1,11 @@ using AgateLib.ApplicationModels; +using AgateLib.IO; using AgateLib.Platform.WinForms.ApplicationModels; using AgateLib.Platform.WinForms.Factories; using AgateLib.Platform.WinForms.IO; using AgateLib.Utility; +using System; +using System.IO; namespace AgateLib.Platform.WinForms { @@ -21,6 +24,10 @@ factory.SetAssetLocations(parameters.AssetLocations); Core.InitAssetLocations(parameters.AssetLocations); + var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + + FileProvider.UserFiles = new FileSystemProvider(Path.Combine(appData, parameters.ApplicationName)); + ////var assetProvider = new FileSystemProvider(System.IO.Path.GetFullPath(parameters.AssetLocations.Path)); ////AgateLib.IO.FileProvider.Initialize(assetProvider, parameters.AssetLocations); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2014-10-11 00:24:51
|
Revision: 1534 http://sourceforge.net/p/agate/code/1534 Author: kanato Date: 2014-10-11 00:24:39 +0000 (Sat, 11 Oct 2014) Log Message: ----------- Add synchronous extension OpenRead method. Modified Paths: -------------- trunk/AgateLib/IO/IReadFileProvider.cs Modified: trunk/AgateLib/IO/IReadFileProvider.cs =================================================================== --- trunk/AgateLib/IO/IReadFileProvider.cs 2014-10-08 02:13:43 UTC (rev 1533) +++ trunk/AgateLib/IO/IReadFileProvider.cs 2014-10-11 00:24:39 UTC (rev 1534) @@ -85,4 +85,14 @@ /// </summary> bool IsLogicalFilesystem { get; } } + + public static class FileProviderExtensions + { + public static Stream OpenRead(this IReadFileProvider provider, string filename) + { + var task = provider.OpenReadAsync(filename); + + return task.Result; + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2014-09-30 00:42:12
|
Revision: 1532 http://sourceforge.net/p/agate/code/1532 Author: kanato Date: 2014-09-30 00:42:08 +0000 (Tue, 30 Sep 2014) Log Message: ----------- Some refactorings. Modified Paths: -------------- trunk/AgateLib/Algorithms/PathFinding/AStar.cs trunk/AgateLib/ApplicationModels/Scene.cs trunk/AgateLib/Core.cs trunk/AgateLib/DisplayLib/Font.cs trunk/AgateLib/DisplayLib/IDrawable.cs trunk/AgateLib/DisplayLib/ISurface.cs trunk/AgateLib/Serialization/Xle/XleSerializationInfo.cs trunk/AgateLib.Platform.WinForms/DisplayImplementation/GL_DisplayControl.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/BasicSprite.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/ClipRect.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/ColorTest.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/Interpolation.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/ParticleTests.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/RotatingSpriteTester.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/FontTests/Builtin.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/FontTests/TextLayout.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/FoundationTests/Resources.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/BasicGuiTest.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/TransitionTest.cs trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/LargeImage.cs trunk/AgateLib.Tests/Tests.WinForms/InputTests/InputStateTester.cs trunk/AgateLib.Tests/Tests.WinForms/WinFormsTests/Converters.cs Modified: trunk/AgateLib/Algorithms/PathFinding/AStar.cs =================================================================== --- trunk/AgateLib/Algorithms/PathFinding/AStar.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib/Algorithms/PathFinding/AStar.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -38,7 +38,7 @@ : this(map, (x, y) => x.Equals(y)) { } public AStar(IAStarMap<T> map, IEqualityComparer<T> comparer) - : this(map, (x, y) => comparer.Equals(x, y)) + : this(map, comparer.Equals) { } public AStar(IAStarMap<T> map, Func<T, T, bool> comparison) { Modified: trunk/AgateLib/ApplicationModels/Scene.cs =================================================================== --- trunk/AgateLib/ApplicationModels/Scene.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib/ApplicationModels/Scene.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -19,7 +19,7 @@ protected internal virtual void OnSceneEnd() { } - public abstract void Update(double delta_t); + public abstract void Update(double deltaT); public abstract void Draw(); } } Modified: trunk/AgateLib/Core.cs =================================================================== --- trunk/AgateLib/Core.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib/Core.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -346,7 +346,7 @@ DefaultResources res = new DefaultResources(); var task = mFactory.DisplayFactory.InitializeDefaultResourcesAsync(res); - Assets.Fonts.Initialize(res); + Fonts.Initialize(res); Task.WaitAll(task); } Modified: trunk/AgateLib/DisplayLib/Font.cs =================================================================== --- trunk/AgateLib/DisplayLib/Font.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib/DisplayLib/Font.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -56,7 +56,7 @@ int MaxSize(FontStyles style) { var keys = mFontSurfaces.Keys.Where(x => x.Style == style); - if (keys.Count() > 0) + if (keys.Any()) return keys.Max(x => x.Size); else return -1; Modified: trunk/AgateLib/DisplayLib/IDrawable.cs =================================================================== --- trunk/AgateLib/DisplayLib/IDrawable.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib/DisplayLib/IDrawable.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -7,9 +7,15 @@ namespace AgateLib.DisplayLib { public interface IDrawable - { - void Draw(Point point); - + { + /// <summary> + /// Draws the surface at the specified point. + /// </summary> + /// <param name="destPt"></param> + void Draw(Point destPt); + /// <summary> + /// Gets or sets the display size of the surface, in pixels. + /// </summary> Size DisplaySize { get; set; } } } Modified: trunk/AgateLib/DisplayLib/ISurface.cs =================================================================== --- trunk/AgateLib/DisplayLib/ISurface.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib/DisplayLib/ISurface.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -49,10 +49,6 @@ /// </summary> int DisplayHeight { get; set; } /// <summary> - /// Gets or sets the display size of the surface, in pixels. - /// </summary> - Size DisplaySize { get; set; } - /// <summary> /// Gets or sets the display width of the surface, in pixels. /// </summary> int DisplayWidth { get; set; } @@ -60,11 +56,6 @@ /// Draws the surface at the specified point. /// </summary> /// <param name="destPt"></param> - void Draw(Point destPt); - /// <summary> - /// Draws the surface at the specified point. - /// </summary> - /// <param name="destPt"></param> void Draw(PointF destPt); /// <summary> /// Draws the surface at the specified point. Modified: trunk/AgateLib/Serialization/Xle/XleSerializationInfo.cs =================================================================== --- trunk/AgateLib/Serialization/Xle/XleSerializationInfo.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib/Serialization/Xle/XleSerializationInfo.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -121,8 +121,6 @@ /// <param name="asAttribute">Pass true to write the field as an attribute in the parent element.</param> public void Write(string name, string value, bool asAttribute = false) { - if (value == null) value = ""; - WriteImpl(name, value ?? string.Empty, asAttribute); } Modified: trunk/AgateLib.Platform.WinForms/DisplayImplementation/GL_DisplayControl.cs =================================================================== --- trunk/AgateLib.Platform.WinForms/DisplayImplementation/GL_DisplayControl.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib.Platform.WinForms/DisplayImplementation/GL_DisplayControl.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -81,7 +81,7 @@ if (windowParams.RenderToControl) { - if (typeof(Control).IsAssignableFrom(windowParams.RenderTarget.GetType()) == false) + if (windowParams.RenderTarget is Control == false) throw new AgateException(string.Format("The specified render target is of type {0}, " + "which does not derive from System.Windows.Forms.Control.", windowParams.RenderTarget.GetType().Name)); Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/BasicSprite.cs =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/BasicSprite.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/BasicSprite.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -36,9 +36,9 @@ p.Dispose(); } - public override void Update(double time_ms) + public override void Update(double deltaT) { - p.Update(time_ms); + p.Update(deltaT); } public override void Draw() Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/ClipRect.cs =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/ClipRect.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/ClipRect.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -42,9 +42,9 @@ get { return this; } } - public override void Update(double delta_t) + public override void Update(double deltaT) { - time += delta_t / 1000.0; + time += deltaT / 1000.0; } public override void Draw() Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/ColorTest.cs =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/ColorTest.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/ColorTest.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -21,7 +21,7 @@ get { return "Display"; } } - public override void Update(double delta_t) + public override void Update(double deltaT) { } Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/Interpolation.cs =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/Interpolation.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/Interpolation.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -47,7 +47,7 @@ surf2.Draw(500, 10); } - public override void Update(double delta_t) + public override void Update(double deltaT) { } Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/ParticleTests.cs =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/ParticleTests.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/ParticleTests.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -86,19 +86,19 @@ gpm.SubscribeToEmitter(pe); } - public override void Update(double time_ms) + public override void Update(double deltaT) { gm2.Gravity = new Vector2((float)ran.Next(-300, 300), 0f); fom.AlphaAmount = (float)ran.NextDouble() * 1.3f; fom.LifeBarrier = (float)ran.NextDouble() * 5f; - pe.Update(time_ms); + pe.Update(deltaT); pe.EmitVelocity = new Vector2((float)ran.Next(-10, 10), 0f); - sm.Update(time_ms); + sm.Update(deltaT); - se.Update(time_ms); + se.Update(deltaT); se.GetSpriteByKey(0).TimePerFrame = ran.NextDouble() * 3 + 1.5d; } Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/RotatingSpriteTester.cs =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/RotatingSpriteTester.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/RotatingSpriteTester.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -40,7 +40,7 @@ sp.RotationAngleDegrees = 90; sp.SetScale(2, 2); } - public override void Update(double delta_t) + public override void Update(double deltaT) { if (Keyboard.Keys[KeyCode.Escape]) SceneFinished = true; Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/FontTests/Builtin.cs =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/FontTests/Builtin.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/FontTests/Builtin.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -47,7 +47,7 @@ get { return this; } } - public override void Update(double delta_t) + public override void Update(double deltaT) { } Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/FontTests/TextLayout.cs =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/FontTests/TextLayout.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/FontTests/TextLayout.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -57,7 +57,7 @@ } - public override void Update(double delta_t) + public override void Update(double deltaT) { } Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/FoundationTests/Resources.cs =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/FoundationTests/Resources.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/FoundationTests/Resources.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -30,7 +30,7 @@ sprite.StartAnimation(); } - public override void Update(double delta_t) + public override void Update(double deltaT) { sprite.Update(); } Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/BasicGuiTest.cs =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/BasicGuiTest.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/BasicGuiTest.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -37,7 +37,7 @@ gs = new GuiStuff(); gs.CreateGui(); } - public override void Update(double delta_t) + public override void Update(double deltaT) { gs.Update(); } Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/TransitionTest.cs =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/TransitionTest.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/TransitionTest.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -49,7 +49,7 @@ } } - public override void Update(double delta_t) + public override void Update(double deltaT) { gs.Update(); } Modified: trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/LargeImage.cs =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/LargeImage.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/LargeImage.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -15,21 +15,21 @@ public string Name { get { return "Large Image"; } } public string Category { get { return "Display"; } } - double loadTime; - Surface someSurface; + Surface mSomeSurface; + private double mLoadTime; protected override void OnSceneStart() { - System.Diagnostics.Stopwatch watch = new Stopwatch(); + var watch = new Stopwatch(); watch.Start(); - someSurface = new Surface("largeimage.png"); - someSurface.LoadComplete += (sender, e) => + mSomeSurface = new Surface("largeimage.png"); + mSomeSurface.LoadComplete += (sender, e) => { watch.Stop(); - double loadTime = watch.ElapsedMilliseconds / 1000.0; + mLoadTime = watch.ElapsedMilliseconds / 1000.0; }; } - public override void Update(double delta_t) + public override void Update(double deltaT) { } @@ -39,8 +39,8 @@ var font = AgateLib.Assets.Fonts.AgateSans; font.Size = 24; - someSurface.Draw(); - font.DrawText(0, 0, "Load took {0} seconds.", loadTime); + mSomeSurface.Draw(); + font.DrawText(0, 0, "Load took {0} seconds.", mLoadTime); } public void ModifyModelParameters(SceneModelParameters parameters) Modified: trunk/AgateLib.Tests/Tests.WinForms/InputTests/InputStateTester.cs =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/InputTests/InputStateTester.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib.Tests/Tests.WinForms/InputTests/InputStateTester.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -25,7 +25,7 @@ get { return this; } } - public override void Update(double delta_t) + public override void Update(double deltaT) { } Modified: trunk/AgateLib.Tests/Tests.WinForms/WinFormsTests/Converters.cs =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/WinFormsTests/Converters.cs 2014-09-28 16:30:47 UTC (rev 1531) +++ trunk/AgateLib.Tests/Tests.WinForms/WinFormsTests/Converters.cs 2014-09-30 00:42:08 UTC (rev 1532) @@ -41,7 +41,7 @@ get { return this; } } - public override void Update(double delta_t) + public override void Update(double deltaT) { } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2014-09-28 16:31:00
|
Revision: 1531 http://sourceforge.net/p/agate/code/1531 Author: kanato Date: 2014-09-28 16:30:47 +0000 (Sun, 28 Sep 2014) Log Message: ----------- Fix coordinate system transform for legacy mouse events. Modified Paths: -------------- trunk/AgateLib/DisplayLib/ImplementationBase/DisplayWindowImpl.cs trunk/AgateLib/InputLib/Legacy/LegacyInputHandler.cs trunk/AgateLib/InputLib/Legacy/Mouse.cs trunk/AgateLib.OpenGL/AgateLib.OpenGL.csproj trunk/AgateLib.Platform.WinForms/AgateLib.Platform.WinForms.csproj Added Paths: ----------- trunk/AgateLib/packages.config trunk/AgateLib.AgateSDL/packages.config trunk/AgateLib.OpenGL/packages.config trunk/AgateLib.Platform.WinForms/packages.config Removed Paths: ------------- trunk/AgateLib/packages.config trunk/AgateLib.AgateSDL/packages.config trunk/AgateLib.OpenGL/packages.config trunk/AgateLib.Platform.WinForms/packages.config Modified: trunk/AgateLib/DisplayLib/ImplementationBase/DisplayWindowImpl.cs =================================================================== --- trunk/AgateLib/DisplayLib/ImplementationBase/DisplayWindowImpl.cs 2014-09-23 01:38:42 UTC (rev 1530) +++ trunk/AgateLib/DisplayLib/ImplementationBase/DisplayWindowImpl.cs 2014-09-28 16:30:47 UTC (rev 1531) @@ -91,7 +91,7 @@ [Obsolete("This is probably obsolete.")] protected void SetInternalMousePosition(AgateLib.Geometry.Point pt) { - AgateLib.InputLib.Legacy.Mouse.SetStoredPosition(pt); + AgateLib.InputLib.Legacy.Mouse.SetStoredPosition(PixelToLogicalCoords(pt)); } /// <summary> Modified: trunk/AgateLib/InputLib/Legacy/LegacyInputHandler.cs =================================================================== --- trunk/AgateLib/InputLib/Legacy/LegacyInputHandler.cs 2014-09-23 01:38:42 UTC (rev 1530) +++ trunk/AgateLib/InputLib/Legacy/LegacyInputHandler.cs 2014-09-28 16:30:47 UTC (rev 1531) @@ -13,10 +13,22 @@ { case InputEventType.KeyDown: Keyboard.OnKeyDown(args); break; case InputEventType.KeyUp: Keyboard.OnKeyUp(args); break; - case InputEventType.MouseDown: Mouse.OnMouseDown(args); break; - case InputEventType.MouseUp: Mouse.OnMouseUp(args); break; - case InputEventType.MouseWheel: Mouse.OnMouseWheel(args); break; - case InputEventType.MouseMove: Mouse.OnMouseMove(args); break; + case InputEventType.MouseDown: + Mouse.Position = args.MousePosition; + Mouse.OnMouseDown(args); + break; + case InputEventType.MouseUp: + Mouse.Position = args.MousePosition; + Mouse.OnMouseUp(args); + break; + case InputEventType.MouseWheel: + Mouse.Position = args.MousePosition; + Mouse.OnMouseWheel(args); + break; + case InputEventType.MouseMove: + Mouse.Position = args.MousePosition; + Mouse.OnMouseMove(args); + break; } } Modified: trunk/AgateLib/InputLib/Legacy/Mouse.cs =================================================================== --- trunk/AgateLib/InputLib/Legacy/Mouse.cs 2014-09-23 01:38:42 UTC (rev 1530) +++ trunk/AgateLib/InputLib/Legacy/Mouse.cs 2014-09-28 16:30:47 UTC (rev 1531) @@ -61,7 +61,7 @@ { return mMouseButtons[(int)id]; } - set + internal set { if (id == MouseButton.None) { Deleted: trunk/AgateLib/packages.config =================================================================== --- trunk/AgateLib/packages.config 2014-09-23 01:38:42 UTC (rev 1530) +++ trunk/AgateLib/packages.config 2014-09-28 16:30:47 UTC (rev 1531) @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<packages> - <package id="MSBuildTasks" version="1.4.0.65" targetFramework="net35" /> -</packages> \ No newline at end of file Added: trunk/AgateLib/packages.config =================================================================== --- trunk/AgateLib/packages.config (rev 0) +++ trunk/AgateLib/packages.config 2014-09-28 16:30:47 UTC (rev 1531) @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="MSBuildTasks" version="1.4.0.65" targetFramework="portable-net45+win+wpa81+wp80+MonoAndroid10+MonoTouch10" /> +</packages> \ No newline at end of file Deleted: trunk/AgateLib.AgateSDL/packages.config =================================================================== --- trunk/AgateLib.AgateSDL/packages.config 2014-09-23 01:38:42 UTC (rev 1530) +++ trunk/AgateLib.AgateSDL/packages.config 2014-09-28 16:30:47 UTC (rev 1531) @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<packages> - <package id="MSBuildTasks" version="1.4.0.65" targetFramework="net35" /> -</packages> \ No newline at end of file Added: trunk/AgateLib.AgateSDL/packages.config =================================================================== --- trunk/AgateLib.AgateSDL/packages.config (rev 0) +++ trunk/AgateLib.AgateSDL/packages.config 2014-09-28 16:30:47 UTC (rev 1531) @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="MSBuildTasks" version="1.4.0.65" targetFramework="net45" /> +</packages> \ No newline at end of file Modified: trunk/AgateLib.OpenGL/AgateLib.OpenGL.csproj =================================================================== --- trunk/AgateLib.OpenGL/AgateLib.OpenGL.csproj 2014-09-23 01:38:42 UTC (rev 1530) +++ trunk/AgateLib.OpenGL/AgateLib.OpenGL.csproj 2014-09-28 16:30:47 UTC (rev 1531) @@ -79,7 +79,7 @@ <ItemGroup> <Reference Include="OpenTK, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> - <HintPath>..\packages\OpenTK.1.1.1589.5942\lib\NET40\OpenTK.dll</HintPath> + <HintPath>..\..\packages\OpenTK.1.1.1589.5942\lib\NET40\OpenTK.dll</HintPath> </Reference> <Reference Include="System" /> <Reference Include="System.Core" /> @@ -140,9 +140,7 @@ </EmbeddedResource> </ItemGroup> <ItemGroup> - <None Include="packages.config"> - <SubType>Designer</SubType> - </None> + <None Include="packages.config" /> <None Include="Resources\Basic2D_pixel.txt" /> </ItemGroup> <ItemGroup> Deleted: trunk/AgateLib.OpenGL/packages.config =================================================================== --- trunk/AgateLib.OpenGL/packages.config 2014-09-23 01:38:42 UTC (rev 1530) +++ trunk/AgateLib.OpenGL/packages.config 2014-09-28 16:30:47 UTC (rev 1531) @@ -1,5 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<packages> - <package id="MSBuildTasks" version="1.4.0.65" targetFramework="net35" /> - <package id="OpenTK" version="1.1.1589.5942" targetFramework="net45" /> -</packages> \ No newline at end of file Added: trunk/AgateLib.OpenGL/packages.config =================================================================== --- trunk/AgateLib.OpenGL/packages.config (rev 0) +++ trunk/AgateLib.OpenGL/packages.config 2014-09-28 16:30:47 UTC (rev 1531) @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="MSBuildTasks" version="1.4.0.65" targetFramework="net45" /> + <package id="OpenTK" version="1.1.1589.5942" targetFramework="net45" /> +</packages> \ No newline at end of file Modified: trunk/AgateLib.Platform.WinForms/AgateLib.Platform.WinForms.csproj =================================================================== --- trunk/AgateLib.Platform.WinForms/AgateLib.Platform.WinForms.csproj 2014-09-23 01:38:42 UTC (rev 1530) +++ trunk/AgateLib.Platform.WinForms/AgateLib.Platform.WinForms.csproj 2014-09-28 16:30:47 UTC (rev 1531) @@ -79,7 +79,7 @@ </PropertyGroup> <ItemGroup> <Reference Include="OpenTK"> - <HintPath>..\packages\OpenTK.1.1.1589.5942\lib\NET40\OpenTK.dll</HintPath> + <HintPath>..\..\packages\OpenTK.1.1.1589.5942\lib\NET40\OpenTK.dll</HintPath> </Reference> <Reference Include="System" /> <Reference Include="System.Core" /> Deleted: trunk/AgateLib.Platform.WinForms/packages.config =================================================================== --- trunk/AgateLib.Platform.WinForms/packages.config 2014-09-23 01:38:42 UTC (rev 1530) +++ trunk/AgateLib.Platform.WinForms/packages.config 2014-09-28 16:30:47 UTC (rev 1531) @@ -1,5 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<packages> - <package id="MSBuildTasks" version="1.4.0.65" targetFramework="net35" /> - <package id="OpenTK" version="1.1.1589.5942" targetFramework="net45" /> -</packages> \ No newline at end of file Added: trunk/AgateLib.Platform.WinForms/packages.config =================================================================== --- trunk/AgateLib.Platform.WinForms/packages.config (rev 0) +++ trunk/AgateLib.Platform.WinForms/packages.config 2014-09-28 16:30:47 UTC (rev 1531) @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="MSBuildTasks" version="1.4.0.65" targetFramework="net45" /> + <package id="OpenTK" version="1.1.1589.5942" targetFramework="net45" /> +</packages> \ 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...> - 2014-09-23 01:38:47
|
Revision: 1530 http://sourceforge.net/p/agate/code/1530 Author: kanato Date: 2014-09-23 01:38:42 +0000 (Tue, 23 Sep 2014) Log Message: ----------- Minor fixes. Add Deselect event to MenuItem. Modified Paths: -------------- trunk/AgateLib/UserInterface/Css/Rendering/CssRenderer.cs trunk/AgateLib/UserInterface/Widgets/Menu.cs trunk/AgateLib/UserInterface/Widgets/MenuItem.cs trunk/AgateLib.OpenGL/ContextFB.cs trunk/AgateLib.Platform.WinForms/DisplayImplementation/GL_DisplayControl.cs Modified: trunk/AgateLib/UserInterface/Css/Rendering/CssRenderer.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Rendering/CssRenderer.cs 2014-09-22 00:58:07 UTC (rev 1529) +++ trunk/AgateLib/UserInterface/Css/Rendering/CssRenderer.cs 2014-09-23 01:38:42 UTC (rev 1530) @@ -81,7 +81,7 @@ public WidgetAnimator GetAnimator(Widget widget) { - return mAnimators[widget]; + return GetOrCreateAnimator(widget); } WidgetAnimator GetOrCreateAnimator(Widget widget) { @@ -90,7 +90,7 @@ mAnimators.Add(widget, new WidgetAnimator(mAdapter.GetStyle(widget))); } - return GetAnimator(widget); + return mAnimators[widget]; } Modified: trunk/AgateLib/UserInterface/Widgets/Menu.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Menu.cs 2014-09-22 00:58:07 UTC (rev 1529) +++ trunk/AgateLib/UserInterface/Widgets/Menu.cs 2014-09-23 01:38:42 UTC (rev 1530) @@ -461,8 +461,6 @@ mScrollRow++; } } - - SelectedItem.OnSelect(); } private void UpdateSelectedItem() Modified: trunk/AgateLib/UserInterface/Widgets/MenuItem.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/MenuItem.cs 2014-09-22 00:58:07 UTC (rev 1529) +++ trunk/AgateLib/UserInterface/Widgets/MenuItem.cs 2014-09-23 01:38:42 UTC (rev 1530) @@ -26,6 +26,8 @@ { public class MenuItem : Container { + bool mSelected; + public MenuItem() { Children.WidgetAdded += Children_WidgetAdded; @@ -80,12 +82,28 @@ get { return (Menu)Parent; } } - public bool Selected { get; set; } + public bool Selected + { + get { return mSelected; } + set + { + if (value == mSelected) + return; + mSelected = value; + + if (mSelected) + OnSelect(); + else + OnDeselect(); + } + } + public event EventHandler PressAccept; public event EventHandler PressToggle; public event EventHandler PressMenu; public event EventHandler Select; + public event EventHandler Deselect; public event EventHandler Discard; void Children_WidgetAdded(object sender, WidgetEventArgs e) @@ -187,6 +205,12 @@ if (Select != null) Select(this, EventArgs.Empty); } + void OnDeselect() + { + if (Deselect != null) + Deselect(this, EventArgs.Empty); + } + internal void OnPressAccept() { if (PressAccept != null) Modified: trunk/AgateLib.OpenGL/ContextFB.cs =================================================================== --- trunk/AgateLib.OpenGL/ContextFB.cs 2014-09-22 00:58:07 UTC (rev 1529) +++ trunk/AgateLib.OpenGL/ContextFB.cs 2014-09-23 01:38:42 UTC (rev 1530) @@ -37,6 +37,7 @@ IWindowInfo mWindowInfo; Size mSize; AgateLib.DisplayLib.DisplayWindow mAttachedWindow; + bool mIsDisposed; public ContextFB(AgateLib.DisplayLib.DisplayWindow attachedWindow, GraphicsMode graphicsMode, IWindowInfo window, Size size, @@ -60,6 +61,8 @@ public void CreateContextForThread() { + if (IsDisposed) + throw new InvalidOperationException("Cannot create a context for a framebuffer which is disposed."); if (mContexts.ContainsKey(Thread.CurrentThread)) return; @@ -73,6 +76,8 @@ context.ToString(), Thread.CurrentThread.ManagedThreadId)); } + public bool IsDisposed { get { return mIsDisposed; } } + GraphicsContext CurrentContext { get @@ -85,6 +90,16 @@ } public override void Dispose() { + if (mIsDisposed) + return; + + foreach(var context in mContexts.Values) + { + context.Dispose(); + } + + mContexts.Clear(); + mIsDisposed = true; } public override AgateLib.Geometry.Size Size @@ -95,6 +110,9 @@ public void SetSize(Size size) { mSize = size; + + foreach (var context in mContexts.Values) + context.Update(mWindowInfo); } public override AgateLib.DisplayLib.DisplayWindow AttachedWindow Modified: trunk/AgateLib.Platform.WinForms/DisplayImplementation/GL_DisplayControl.cs =================================================================== --- trunk/AgateLib.Platform.WinForms/DisplayImplementation/GL_DisplayControl.cs 2014-09-22 00:58:07 UTC (rev 1529) +++ trunk/AgateLib.Platform.WinForms/DisplayImplementation/GL_DisplayControl.cs 2014-09-23 01:38:42 UTC (rev 1530) @@ -49,7 +49,6 @@ DisplayWindow mOwner; Form frm; Control mRenderTarget; - IGraphicsContext mContext; IWindowInfo mWindowInfo; DesktopGLDisplay mDisplay; @@ -132,11 +131,8 @@ DetachEvents(); Form oldForm = frm; - IGraphicsContext oldcontext = mContext; IWindowInfo oldWindowInfo = mWindowInfo; - mContext = null; - frm = new frmFullScreen(); frm.Show(); @@ -162,7 +158,6 @@ mIsFullScreen = true; if (oldWindowInfo != null) oldWindowInfo.Dispose(); - if (oldcontext != null) oldcontext.Dispose(); if (oldForm != null) oldForm.Dispose(); Core.IsActive = true; @@ -173,10 +168,8 @@ DetachEvents(); Form oldForm = frm; - IGraphicsContext oldcontext = mContext; IWindowInfo oldWindowInfo = mWindowInfo; - mContext = null; mIsFullScreen = false; Form myform; @@ -201,7 +194,6 @@ AttachEvents(); if (oldWindowInfo != null) oldWindowInfo.Dispose(); - if (oldcontext != null) oldcontext.Dispose(); if (oldForm != null) oldForm.Dispose(); Core.IsActive = true; @@ -365,12 +357,6 @@ mFrameBuffer = null; } - if (mContext != null) - { - mContext.Dispose(); - mContext = null; - } - if (frm != null) { frm.Close(); @@ -463,7 +449,6 @@ } void mRenderTarget_Resize(object sender, EventArgs e) { - mContext.Update(mWindowInfo); mFrameBuffer.SetSize(new Size(mRenderTarget.Width, mRenderTarget.Height)); OnResize(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2014-09-22 00:58:21
|
Revision: 1529 http://sourceforge.net/p/agate/code/1529 Author: kanato Date: 2014-09-22 00:58:07 +0000 (Mon, 22 Sep 2014) Log Message: ----------- Fixes to layout. Modified Paths: -------------- trunk/AgateLib/UserInterface/Css/Binders/CssTypeConverter.cs trunk/AgateLib/UserInterface/Css/Documents/CssDistance.cs trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs trunk/AgateLib/UserInterface/Widgets/Label.cs trunk/AgateLib/UserInterface/Widgets/Menu.cs trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs Modified: trunk/AgateLib/UserInterface/Css/Binders/CssTypeConverter.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Binders/CssTypeConverter.cs 2014-09-21 23:27:19 UTC (rev 1528) +++ trunk/AgateLib/UserInterface/Css/Binders/CssTypeConverter.cs 2014-09-22 00:58:07 UTC (rev 1529) @@ -1,4 +1,5 @@ -// The contents of this file are subject to the Mozilla Public License +using AgateLib.Diagnostics; +// The contents of this file are subject to the Mozilla Public License // Version 1.1 (the "License"); you may not use this file except in // compliance with the License. You may obtain a copy of the License at // http://www.mozilla.org/MPL/ @@ -38,7 +39,17 @@ if (targetType == typeof(CssDistance)) return CssDistance.FromString(value); if (targetType.GetTypeInfo().IsEnum) - return Enum.Parse(targetType, value.Replace("-", "_"), true); + { + try + { + return Enum.Parse(targetType, value.Replace("-", "_"), true); + } + catch + { + Log.WriteLine("Failed to parse {0}: {1}", targetType.Name, value); + return 0; + } + } throw new NotImplementedException(); } Modified: trunk/AgateLib/UserInterface/Css/Documents/CssDistance.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Documents/CssDistance.cs 2014-09-21 23:27:19 UTC (rev 1528) +++ trunk/AgateLib/UserInterface/Css/Documents/CssDistance.cs 2014-09-22 00:58:07 UTC (rev 1529) @@ -52,6 +52,8 @@ if (string.IsNullOrWhiteSpace(value)) return new CssDistance(true); + if (value == "none") + return new CssDistance { Amount = 0, Automatic = false, DistanceUnit = DistanceUnit.Pixels }; if (value.Equals("auto", StringComparison.OrdinalIgnoreCase)) { Modified: trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs 2014-09-21 23:27:19 UTC (rev 1528) +++ trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs 2014-09-22 00:58:07 UTC (rev 1529) @@ -155,21 +155,22 @@ containerClientRect.X = 0; containerClientRect.Y = 0; - int maxWidth = ComputeMaxWidthForContainer(containerStyle); + int maxContWidth = ComputeMaxWidthForContainer(containerStyle); Point nextPos = Point.Empty; - int maxHeight = 0; + int largestHeight = 0; - maxWidth -= containerBox.Left + containerBox.Right; + maxContWidth -= containerBox.Left + containerBox.Right; int largestWidth = 0; int bottom = 0; - containerClientRect.Width = maxWidth; int? fixedContainerWidth = ConvertDistance(container, containerStyle.Data.PositionData.Width, true); int? fixedContainerHeight = ConvertDistance(container, containerStyle.Data.PositionData.Height, true); if (fixedContainerWidth != null) - maxWidth = (int)fixedContainerWidth; + maxContWidth = (int)fixedContainerWidth; + containerClientRect.Width = maxContWidth; + bool resetNextPosition = false; if (container is Desktop == false) @@ -193,7 +194,30 @@ if (style.Data.Display == CssDisplay.None) continue; - var sz = ComputeSize(child, containerStyle, forceRefresh); + style.IncludeInLayout = true; + + switch (style.Data.Position) + { + case CssPosition.Absolute: + style.IncludeInLayout = false; + child.ParentCoordinateSystem = TopLevelWidget(child, x => mAdapter.GetStyle(x).Data.Position != CssPosition.Static); + break; + + case CssPosition.Fixed: + style.IncludeInLayout = false; + child.ParentCoordinateSystem = TopLevelWidget(child, x => x is Desktop); + break; + } + + int? maxWidth = ConvertDistance(child, style.Data.PositionData.MaxWidth, true, true); + int? maxHeight = ConvertDistance(child, style.Data.PositionData.MaxHeight, true, true); + + if(style.IncludeInLayout) + { + maxWidth = maxContWidth - nextPos.X; + } + + var sz = ComputeSize(child, containerStyle, forceRefresh, maxWidth, maxHeight); var box = style.BoxModel; int? fixedWidth = ConvertDistance(child, style.Data.PositionData.Width, true); @@ -225,37 +249,23 @@ resetNextPosition = true; } - if (nextPos.X + sz.Width + style.BoxModel.Left + style.BoxModel.Right > maxWidth) + if (nextPos.X + sz.Width + style.BoxModel.Left + style.BoxModel.Right > maxContWidth) resetPosition = true; if (resetPosition) { nextPos.X = 0; - nextPos.Y += maxHeight; - maxHeight = 0; + nextPos.Y += largestHeight; + largestHeight = 0; } break; } - style.IncludeInLayout = true; - Rectangle clientRect = new Rectangle(); clientRect.Size = sz; - switch (style.Data.Position) - { - case CssPosition.Absolute: - style.IncludeInLayout = false; - child.ParentCoordinateSystem = TopLevelWidget(child, x => mAdapter.GetStyle(x).Data.Position != CssPosition.Static); - break; - case CssPosition.Fixed: - style.IncludeInLayout = false; - child.ParentCoordinateSystem = TopLevelWidget(child, x => x is Desktop); - break; - } - if (style.IncludeInLayout) { clientRect.X = nextPos.X + box.Left; @@ -291,7 +301,7 @@ break; } - maxHeight = Math.Max(maxHeight, clientRect.Height + box.Top + box.Bottom); + largestHeight = Math.Max(largestHeight, clientRect.Height + box.Top + box.Bottom); bottom = Math.Max(bottom, clientRect.Y + clientRect.Height + box.Bottom); // only add box.Bottom here, because box.Top is taken into account in child.Y. } @@ -304,7 +314,7 @@ style.Widget.ClientRect = clientRect; } - containerClientRect.Width = Math.Min(largestWidth, maxWidth); + containerClientRect.Width = Math.Min(largestWidth, maxContWidth); containerClientRect.Height = bottom; if (fixedContainerWidth != null) @@ -387,11 +397,11 @@ } } - private Size ComputeSize(Widget control, CssStyle parentStyle, bool forceRefresh) + private Size ComputeSize(Widget control, CssStyle parentStyle, bool forceRefresh, int? maxWidth, int? maxHeight) { - return ComputeSize(control, parentStyle.Data, forceRefresh); + return ComputeSize(control, parentStyle.Data, forceRefresh, maxWidth, maxHeight); } - private Size ComputeSize(Widget control, CssStyleData parentStyle, bool forceRefresh) + private Size ComputeSize(Widget control, CssStyleData parentStyle, bool forceRefresh, int? maxWidth, int? maxHeight) { if (control is Container) return ComputeContainerSize((Container)control, forceRefresh); @@ -399,11 +409,20 @@ mAdapter.SetFont(control); var style = mAdapter.GetStyle(control); - return control.ComputeSize( - ConvertDistance(control, style.Data.PositionData.MinWidth, true), - ConvertDistance(control, style.Data.PositionData.MinHeight, false), - ConvertDistance(control, style.Data.PositionData.MaxWidth, true), - ConvertDistance(control, style.Data.PositionData.MaxHeight, false)); + int? minWidth = ConvertDistance(control, style.Data.PositionData.MinWidth, true); + int? minHeight = ConvertDistance(control, style.Data.PositionData.MinHeight, false); + int? styleMaxWidth = ConvertDistance(control, style.Data.PositionData.MaxWidth, true); + int? styleMaxHeight = ConvertDistance(control, style.Data.PositionData.MaxHeight, false); + + if (maxWidth == null) maxWidth = styleMaxWidth; + else if (maxWidth != null && styleMaxWidth != null) + maxWidth = Math.Min(maxWidth.Value, styleMaxWidth.Value); + + if (maxHeight == null) maxHeight = styleMaxHeight; + else if (maxHeight != null && styleMaxHeight != null) + maxWidth = Math.Min(maxHeight.Value, styleMaxHeight.Value); + + return control.ComputeSize(minWidth, minHeight, maxWidth, maxHeight); } private int? ConvertDistance(Widget control, CssDistance cssDistance, bool width, bool autoIsNull = true) Modified: trunk/AgateLib/UserInterface/Widgets/Label.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Label.cs 2014-09-21 23:27:19 UTC (rev 1528) +++ trunk/AgateLib/UserInterface/Widgets/Label.cs 2014-09-22 00:58:07 UTC (rev 1529) @@ -34,6 +34,18 @@ double mSlowReadTime; const double mSlowReadTextPeriod = 0.05; + + public Label() + { + TextAlign = OriginAlignment.TopLeft; + WrapText = true; + } + public Label(string text) + : this() + { + this.Text = text; + } + public string Text { get { return mText; } @@ -96,7 +108,7 @@ string text = mText.Substring(lineStart, length); int width = Font.MeasureString(text).Width; - if (width > this.Width) + if (width > maxWidth) { lineStart = spacePositions[i - 1] + 1; mWrapPositions.Add(lineStart); @@ -108,18 +120,33 @@ } int WrappedHeight { - get { return (mWrapPositions.Count + 1) * Font.FontHeight; } + get { return mWrapPositions.Count * Font.FontHeight; } } + int WrappedWidth + { + get + { + int lastPos = 0; + int largestWidth = 0; - public Label() - { - TextAlign = OriginAlignment.TopLeft; + for(int i = 0; i <= mWrapPositions.Count; i++) + { + string text; + + if (i == mWrapPositions.Count) + text = mText.Substring(lastPos); + else + { + text = mText.Substring(lastPos, mWrapPositions[i] - lastPos); + lastPos = mWrapPositions[i]; + } + + largestWidth = Math.Max(largestWidth, Font.MeasureString(text).Width); + } + + return largestWidth; + } } - public Label(string text) - : this() - { - this.Text = text; - } public override void Update(double delta_t, ref bool processInput) { @@ -256,12 +283,17 @@ internal override Size ComputeSize(int? minWidth, int? minHeight, int? maxWidth, int? maxHeight) { + if (WrapText == false) + { + return Font.MeasureString(Text); + } + if (maxWidth != null) { RewrapText(maxWidth.Value); if (mWrapPositions.Count > 0) - return new Size(maxWidth.Value, WrappedHeight); + return new Size(WrappedWidth, WrappedHeight); } var retval = Font.MeasureString(Text); Modified: trunk/AgateLib/UserInterface/Widgets/Menu.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Menu.cs 2014-09-21 23:27:19 UTC (rev 1528) +++ trunk/AgateLib/UserInterface/Widgets/Menu.cs 2014-09-22 00:58:07 UTC (rev 1529) @@ -504,6 +504,9 @@ } protected internal override void OnGestureChange(Gesture gesture) { + if (mGestureItem == null) + return; + switch(gesture.GestureType) { case GestureType.Touch: Modified: trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs =================================================================== --- trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs 2014-09-21 23:27:19 UTC (rev 1528) +++ trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs 2014-09-22 00:58:07 UTC (rev 1529) @@ -125,7 +125,7 @@ Assert.AreEqual(new Point(14, 14), wind.ClientRect.Location); Assert.AreEqual(new Point(18, 14), wind.Children[0].ClientToScreen(Point.Empty)); - Assert.AreEqual(new Point(18, 14 + fh), wind.Children[1].ClientToScreen(Point.Empty)); + Assert.AreEqual(new Point(18, 22), wind.Children[1].ClientToScreen(Point.Empty)); } [TestMethod] @@ -474,5 +474,22 @@ Assert.AreEqual(new Point(18, 18), label1.ClientToScreen(Point.Empty)); } + + [TestMethod] + public void CssLTextWrapping() + { + doc.Clear(); + doc.Parse(@"window { max-width: 50px; }"); + + Window wind = new Window(); + Label lbl = new Label("This is a test label with lots of text."); + + wind.Children.Add(lbl); + gui.AddWindow(wind); + + RedoLayout(); + + Assert.AreEqual(new Rectangle(0, 0, 48, 64), lbl.ClientRect); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2014-09-21 23:27:28
|
Revision: 1528 http://sourceforge.net/p/agate/code/1528 Author: kanato Date: 2014-09-21 23:27:19 +0000 (Sun, 21 Sep 2014) Log Message: ----------- Add manual layout option to GUI. Modified Paths: -------------- trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs trunk/AgateLib/UserInterface/Widgets/Container.cs trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs Modified: trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs 2014-09-17 13:48:09 UTC (rev 1527) +++ trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs 2014-09-21 23:27:19 UTC (rev 1528) @@ -150,6 +150,7 @@ } } + Rectangle originalContainerClient = container.ClientRect; Rectangle containerClientRect = container.ClientRect; containerClientRect.X = 0; containerClientRect.Y = 0; @@ -164,7 +165,6 @@ int bottom = 0; containerClientRect.Width = maxWidth; - int? fixedContainerWidth = ConvertDistance(container, containerStyle.Data.PositionData.Width, true); int? fixedContainerHeight = ConvertDistance(container, containerStyle.Data.PositionData.Height, true); if (fixedContainerWidth != null) @@ -175,10 +175,18 @@ if (container is Desktop == false) container.ClientRect = containerClientRect; + if (container.ManualLayout) + { + containerClientRect.Size = originalContainerClient.Size; + fixedContainerWidth = originalContainerClient.Width; + fixedContainerHeight = originalContainerClient.Height; + } + foreach (var child in container.Children) { var style = mAdapter.GetStyle(child); child.Font = style.Font; + Rectangle originalClient = child.ClientRect; if (child.Visible == false) continue; @@ -186,6 +194,7 @@ continue; var sz = ComputeSize(child, containerStyle, forceRefresh); + var box = style.BoxModel; int? fixedWidth = ConvertDistance(child, style.Data.PositionData.Width, true); int? fixedHeight = ConvertDistance(child, style.Data.PositionData.Height, false); @@ -199,6 +208,7 @@ if (minWidth != null && sz.Width < (int)minWidth) sz.Width = (int)minWidth; if (minHeight != null && sz.Height < (int)minHeight) sz.Height = (int)minHeight; + bool resetPosition = false; switch (containerStyle.Data.Layout.Kind) @@ -285,6 +295,12 @@ bottom = Math.Max(bottom, clientRect.Y + clientRect.Height + box.Bottom); // only add box.Bottom here, because box.Top is taken into account in child.Y. } + if (container.ManualLayout) + { + clientRect = originalClient; + style.IncludeInLayout = false; + } + style.Widget.ClientRect = clientRect; } Modified: trunk/AgateLib/UserInterface/Widgets/Container.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Container.cs 2014-09-17 13:48:09 UTC (rev 1527) +++ trunk/AgateLib/UserInterface/Widgets/Container.cs 2014-09-21 23:27:19 UTC (rev 1528) @@ -185,5 +185,13 @@ { throw new NotImplementedException(); } + + + /// <summary> + /// If this is set to true, then the layout engine will not determine the + /// size of this control, or the size or positions of any child controls. + /// Grandchildren of this control will have layout performed as normal. + /// </summary> + public bool ManualLayout { get; set; } } } Modified: trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs =================================================================== --- trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs 2014-09-17 13:48:09 UTC (rev 1527) +++ trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs 2014-09-21 23:27:19 UTC (rev 1528) @@ -71,11 +71,38 @@ engine.UpdateLayout(gui, new Size(1000, 1000)); } + [TestMethod] + public void CssLManualLayout() + { + Window wind = new Window(); + wind.ManualLayout = true; + wind.ClientRect = new Rectangle(40, 40, 500, 600); + + Menu menu = new Menu(); + menu.ClientRect = new Rectangle(30, 50, 100, 300); + menu.Children.Add(MenuItem.OfLabel("Menu 1")); + menu.Children.Add(MenuItem.OfLabel("Menu 2")); + + wind.Children.Add(menu); + + gui.AddWindow(wind); + + RedoLayout(); + + Assert.AreEqual(new Rectangle(14, 14, 500, 600), wind.ClientRect); + Assert.AreEqual(new Rectangle(30, 50, 100, 300), menu.ClientRect); + + Assert.AreEqual(new Rectangle(0, 0, 52, 8), menu.Children[0].ClientRect); + Assert.AreEqual(new Rectangle(0, 8, 52, 8), menu.Children[1].ClientRect); + } + + [TestMethod] public void CssLBoxModel() { - CssDocument doc = CssDocument.FromText("window { border: 5px solid black; padding: 10px; margin: 20px; }"); - CssAdapter adapter = new CssAdapter(doc); + doc.Clear(); + doc.Parse("window { border: 5px solid black; padding: 10px; margin: 20px; }"); + Window wind = new Window(); var style = adapter.GetStyle(wind); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2014-09-17 13:48:21
|
Revision: 1527 http://sourceforge.net/p/agate/code/1527 Author: kanato Date: 2014-09-17 13:48:09 +0000 (Wed, 17 Sep 2014) Log Message: ----------- Refactor CSS gui renderer. Modified Paths: -------------- trunk/AgateLib/AgateLib.csproj trunk/AgateLib/InputLib/InputHandlerList.cs trunk/AgateLib/UserInterface/Css/CssAdapter.cs trunk/AgateLib/UserInterface/Css/CssStyle.cs trunk/AgateLib/UserInterface/Css/Documents/CssDistance.cs trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs trunk/AgateLib/UserInterface/Css/Rendering/CssRenderer.cs trunk/AgateLib/UserInterface/Css/Rendering/Transitions/IWidgetTransition.cs trunk/AgateLib/UserInterface/Css/Rendering/Transitions/NullTransition.cs trunk/AgateLib/UserInterface/Css/Rendering/Transitions/SlideTransition.cs trunk/AgateLib/UserInterface/Css/Selectors/CssSelectorIndividual.cs trunk/AgateLib/UserInterface/Widgets/Gui.cs trunk/AgateLib/UserInterface/Widgets/IGuiRenderer.cs trunk/AgateLib/UserInterface/Widgets/ImageBox.cs trunk/AgateLib/UserInterface/Widgets/Label.cs trunk/AgateLib/UserInterface/Widgets/Menu.cs trunk/AgateLib/UserInterface/Widgets/ProgressBar.cs trunk/AgateLib/UserInterface/Widgets/Widget.cs trunk/AgateLib/UserInterface/Widgets/WidgetList.cs trunk/AgateLib.Platform.WinForms/ApplicationModels/SceneModel.cs trunk/AgateLib.Platform.WinForms/ApplicationModels/SerialModel.cs trunk/AgateLib.Platform.WinForms/GuiDebug/frmGuiDebug.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj trunk/AgateLib.Tests/AgateLib.Tests.Portable/Assets/Style.css trunk/AgateLib.Tests/AgateLib.Tests.Portable/Fakes/FakeGuiEngine.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/GuiStuff.cs trunk/AgateLib.Tests/Tests.WinForms/frmLauncher.Designer.cs trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssBindingTest.cs trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs Added Paths: ----------- trunk/AgateLib/UserInterface/Css/Rendering/Animators/ trunk/AgateLib/UserInterface/Css/Rendering/Animators/WidgetAnimator.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/TransitionTest.cs Removed Paths: ------------- trunk/AgateLib/UserInterface/Css/Rendering/WidgetAnimator.cs Modified: trunk/AgateLib/AgateLib.csproj =================================================================== --- trunk/AgateLib/AgateLib.csproj 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib/AgateLib.csproj 2014-09-17 13:48:09 UTC (rev 1527) @@ -553,7 +553,7 @@ <Compile Include="UserInterface\Css\Rendering\Transitions\NullTransition.cs" /> <Compile Include="UserInterface\Css\Rendering\Transitions\SlideTransition.cs" /> <Compile Include="UserInterface\Css\Rendering\Transitions\TransitionFactory.cs" /> - <Compile Include="UserInterface\Css\Rendering\WidgetAnimator.cs" /> + <Compile Include="UserInterface\Css\Rendering\Animators\WidgetAnimator.cs" /> <Compile Include="UserInterface\Css\Selectors\CssSelectorIndividual.cs" /> <Compile Include="UserInterface\Css\Selectors\CssSelectorChain.cs" /> <Compile Include="UserInterface\Css\Selectors\CssSelector.cs" /> Modified: trunk/AgateLib/InputLib/InputHandlerList.cs =================================================================== --- trunk/AgateLib/InputLib/InputHandlerList.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib/InputLib/InputHandlerList.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -33,6 +33,8 @@ } public void Add(IInputHandler handler) { + if (handler == null) + throw new ArgumentNullException("Cannot add a null input handler."); if (mHandlers.Contains(handler)) throw new InvalidOperationException("Cannot add the same input handler twice."); Modified: trunk/AgateLib/UserInterface/Css/CssAdapter.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/CssAdapter.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib/UserInterface/Css/CssAdapter.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -28,6 +28,7 @@ using System.Text; using System.Threading.Tasks; using AgateLib.Platform; +using AgateLib.UserInterface.Css.Rendering.Animators; namespace AgateLib.UserInterface.Css { Modified: trunk/AgateLib/UserInterface/Css/CssStyle.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/CssStyle.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib/UserInterface/Css/CssStyle.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -19,6 +19,7 @@ using AgateLib.UserInterface.Css.Cache; using AgateLib.UserInterface.Css.Layout; using AgateLib.UserInterface.Css.Rendering; +using AgateLib.UserInterface.Css.Rendering.Animators; using AgateLib.UserInterface.Css.Selectors; using AgateLib.UserInterface.Widgets; using System; @@ -45,14 +46,11 @@ Cache = new StyleCache(); - Animator = new WidgetAnimator(this); - MatchParameters = new WidgetMatchParameters(widget); } public CssStyleData Data { get; set; } public CssBoxModel BoxModel { get; set; } - public WidgetAnimator Animator { get; set; } public Widget Widget { get; set; } @@ -73,5 +71,7 @@ public AgateLib.DisplayLib.Font Font { get; set; } public WidgetMatchParameters MatchParameters { get; private set; } + + public bool IncludeInLayout { get; set; } } } Modified: trunk/AgateLib/UserInterface/Css/Documents/CssDistance.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Documents/CssDistance.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib/UserInterface/Css/Documents/CssDistance.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -50,6 +50,9 @@ int numberLength = 0; int start = 0; + if (string.IsNullOrWhiteSpace(value)) + return new CssDistance(true); + if (value.Equals("auto", StringComparison.OrdinalIgnoreCase)) { return new CssDistance(true); Modified: trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -69,20 +69,22 @@ { var style = mAdapter.GetStyle(desktop); - style.Animator.ClientRect = new Rectangle(0, 0, desktop.Width, desktop.Height); + style.Widget.ClientRect = new Rectangle(0, 0, desktop.Width, desktop.Height); } private void RedoFixedLayout(Desktop desktop) { var deskStyle = mAdapter.GetStyle(desktop); - deskStyle.Animator.ClientRect = new Rectangle(0, 0, desktop.Width, desktop.Height); + desktop.ClientRect = new Rectangle(0, 0, desktop.Width, desktop.Height); - foreach (var child in desktop.Descendants.Where(x => { + foreach (var child in desktop.Descendants.Where(x => + { var pos = mAdapter.GetStyle(x).Data.Position; - return pos == CssPosition.Absolute || pos == CssPosition.Fixed;} )) + return pos == CssPosition.Absolute || pos == CssPosition.Fixed; + })) { var style = mAdapter.GetStyle(child); - var sz = style.Animator.ClientRect.Size; + var sz = style.Widget.ClientRect.Size; var box = style.BoxModel; switch (style.Data.Position) @@ -96,36 +98,40 @@ } private void SetFixedCoordinates(CssStyle style, CssBoxModel box, Size sz) { - var anim = style.Animator; var position = style.Data.PositionData; - var parentStyle = mAdapter.GetStyle(style.Animator.ParentCoordinateSystem); + var parentStyle = mAdapter.GetStyle(style.Widget.ParentCoordinateSystem); + var widget = style.Widget; + Rectangle clientRect = widget.ClientRect; + if (position.Left.Automatic == false) { var targetLeft = ConvertDistance(style.Widget, position.Left, true, false).Value; - anim.ClientX = targetLeft + box.Left; + clientRect.X = targetLeft + box.Left; } if (position.Right.Automatic == false) { int targetRight = ConvertDistance(style.Widget, position.Right, true, false).Value; - targetRight = parentStyle.Animator.ClientRect.Width - targetRight; + targetRight = parentStyle.Widget.ClientRect.Width - targetRight; - anim.ClientX = targetRight - anim.ClientRect.Width - box.Right; + clientRect.X = targetRight - clientRect.Width - box.Right; } if (position.Top.Automatic == false) { int targetTop = ConvertDistance(style.Widget, position.Top, false, false).Value; - anim.ClientY = targetTop + box.Top; + clientRect.Y = targetTop + box.Top; } if (position.Bottom.Automatic == false) { int targetBottom = ConvertDistance(style.Widget, position.Bottom, false, false).Value; - targetBottom = parentStyle.Animator.ClientRect.Height - targetBottom; + targetBottom = parentStyle.Widget.ClientRect.Height - targetBottom; - anim.ClientY = targetBottom - anim.ClientRect.Height - box.Bottom; + clientRect.Y = targetBottom - clientRect.Height - box.Bottom; } + + widget.ClientRect = clientRect; } public CssAdapter Adapter { get { return mAdapter; } } @@ -133,7 +139,6 @@ private void RedoLayout(Container container, bool forceRefresh = false) { var containerStyle = mAdapter.GetStyle(container); - var containerAnim = containerStyle.Animator; CssBoxModel containerBox = containerStyle.BoxModel; if (forceRefresh == false) @@ -145,8 +150,9 @@ } } - containerAnim.ClientX = 0; - containerAnim.ClientY = 0; + Rectangle containerClientRect = container.ClientRect; + containerClientRect.X = 0; + containerClientRect.Y = 0; int maxWidth = ComputeMaxWidthForContainer(containerStyle); Point nextPos = Point.Empty; @@ -157,7 +163,7 @@ int largestWidth = 0; int bottom = 0; - containerAnim.ClientWidth = maxWidth; + containerClientRect.Width = maxWidth; int? fixedContainerWidth = ConvertDistance(container, containerStyle.Data.PositionData.Width, true); int? fixedContainerHeight = ConvertDistance(container, containerStyle.Data.PositionData.Height, true); @@ -166,6 +172,9 @@ bool resetNextPosition = false; + if (container is Desktop == false) + container.ClientRect = containerClientRect; + foreach (var child in container.Children) { var style = mAdapter.GetStyle(child); @@ -218,62 +227,74 @@ break; } - var anim = style.Animator; - anim.IncludeInLayout = true; - anim.ClientWidth = sz.Width; - anim.ClientHeight = sz.Height; + style.IncludeInLayout = true; + Rectangle clientRect = new Rectangle(); + + clientRect.Size = sz; + switch (style.Data.Position) { case CssPosition.Absolute: - anim.IncludeInLayout = false; + style.IncludeInLayout = false; child.ParentCoordinateSystem = TopLevelWidget(child, x => mAdapter.GetStyle(x).Data.Position != CssPosition.Static); break; case CssPosition.Fixed: - anim.IncludeInLayout = false; + style.IncludeInLayout = false; child.ParentCoordinateSystem = TopLevelWidget(child, x => x is Desktop); break; } - if (anim.IncludeInLayout) + if (style.IncludeInLayout) { - anim.ClientX = nextPos.X + box.Left; - anim.ClientY = nextPos.Y + box.Top; + clientRect.X = nextPos.X + box.Left; + clientRect.Y = nextPos.Y + box.Top; } - anim.ClientWidgetOffset = new Point( + style.Widget.ClientWidgetOffset = new Point( box.Padding.Left + box.Border.Left, box.Padding.Top + box.Border.Top); - if (anim.IncludeInLayout) + style.Widget.WidgetSize = new Size( + clientRect.Width + box.Padding.Left + box.Border.Left + box.Padding.Right + box.Border.Right, + clientRect.Height + box.Padding.Top + box.Border.Top + box.Padding.Bottom + box.Border.Bottom); + + if (style.IncludeInLayout) { switch (containerStyle.Data.Layout.Kind) { case CssLayoutKind.Flow: - nextPos.X += anim.ClientRect.Width + box.Left + box.Right; + nextPos.X += clientRect.Width + box.Left + box.Right; largestWidth = Math.Max(largestWidth, nextPos.X); break; case CssLayoutKind.Column: nextPos.X = 0; - nextPos.Y += anim.ClientRect.Height + box.Top + box.Bottom; - largestWidth = Math.Max(largestWidth, anim.ClientRect.Width + box.Right + box.Left); + nextPos.Y += clientRect.Height + box.Top + box.Bottom; + largestWidth = Math.Max(largestWidth, clientRect.Width + box.Right + box.Left); break; + + case CssLayoutKind.Row: + nextPos.X += clientRect.Width + box.Left + box.Right; + largestWidth = Math.Max(largestWidth, nextPos.X); + break; } - maxHeight = Math.Max(maxHeight, anim.ClientRect.Height + box.Top + box.Bottom); - bottom = Math.Max(bottom, anim.ClientRect.Y + anim.ClientRect.Height + box.Bottom); // only add box.Bottom here, because box.Top is taken into account in child.Y. + maxHeight = Math.Max(maxHeight, clientRect.Height + box.Top + box.Bottom); + bottom = Math.Max(bottom, clientRect.Y + clientRect.Height + box.Bottom); // only add box.Bottom here, because box.Top is taken into account in child.Y. } + + style.Widget.ClientRect = clientRect; } - containerAnim.ClientWidth = Math.Min(largestWidth, maxWidth); - containerAnim.ClientHeight = bottom; + containerClientRect.Width = Math.Min(largestWidth, maxWidth); + containerClientRect.Height = bottom; if (fixedContainerWidth != null) - containerAnim.ClientWidth = (int)fixedContainerWidth; + containerClientRect.Width = (int)fixedContainerWidth; if (fixedContainerHeight != null) - containerAnim.ClientHeight = (int)fixedContainerHeight; + containerClientRect.Height = (int)fixedContainerHeight; switch (containerStyle.Data.Layout.Kind) { @@ -281,11 +302,10 @@ foreach (var child in container.Children) { var style = mAdapter.GetStyle(child); - var anim = style.Animator; var box = style.BoxModel; - int width = containerAnim.ClientRect.Width - box.Left - box.Right; + int width = containerClientRect.Width - box.Left - box.Right; - if (anim.IncludeInLayout == false) + if (style.IncludeInLayout == false) continue; if (style.Data.PositionData.MinWidth.Automatic == false) @@ -299,11 +319,17 @@ width = Math.Min(width, maxwidth); } - anim.ClientWidth = width; + style.Widget.ClientRect = new Rectangle( + style.Widget.ClientRect.X, + style.Widget.ClientRect.Y, + width, + style.Widget.ClientRect.Height); } break; } + if (container is Desktop == false) + container.ClientRect = containerClientRect; } private Container TopLevelWidget(Widget child) @@ -333,7 +359,7 @@ var parentStyle = mAdapter.GetStyle(container.Parent); - int availableWidth = parentStyle.Animator.ClientRect.Width - container.X; + int availableWidth = container.Parent.ClientRect.Width - container.X; if (styleData.PositionData.MaxWidth.Automatic) return availableWidth; @@ -375,9 +401,8 @@ private Size ComputeContainerSize(Container container, bool forceRefresh) { RedoLayout(container, forceRefresh); - var anim = mAdapter.GetStyle(container).Animator; - return new Size(anim.ClientRect.Width, anim.ClientRect.Height); + return container.ClientRect.Size; } } } Copied: trunk/AgateLib/UserInterface/Css/Rendering/Animators/WidgetAnimator.cs (from rev 1525, trunk/AgateLib/UserInterface/Css/Rendering/WidgetAnimator.cs) =================================================================== --- trunk/AgateLib/UserInterface/Css/Rendering/Animators/WidgetAnimator.cs (rev 0) +++ trunk/AgateLib/UserInterface/Css/Rendering/Animators/WidgetAnimator.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -0,0 +1,245 @@ +// The contents of this file are subject to the Mozilla Public License +// Version 1.1 (the "License"); you may not use this file except in +// compliance with the License. You may obtain a copy of the License at +// http://www.mozilla.org/MPL/ +// +// Software distributed under the License is distributed on an "AS IS" +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +// License for the specific language governing rights and limitations +// under the License. +// +// The Original Code is AgateLib. +// +// The Initial Developer of the Original Code is Erik Ylvisaker. +// Portions created by Erik Ylvisaker are Copyright (C) 2006-2014. +// All Rights Reserved. +// +// Contributor(s): Erik Ylvisaker +// +using AgateLib.Geometry; +using AgateLib.UserInterface.Css.Documents; +using AgateLib.UserInterface.Css.Rendering.Transitions; +using AgateLib.UserInterface.Widgets; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.UserInterface.Css.Rendering.Animators +{ + public class WidgetAnimator + { + CssStyle mStyle; + Rectangle mClientRect; + WidgetAnimator mParentCoordinates; + + public List<WidgetAnimator> Children { get; private set; } + public WidgetAnimator Parent { get; set; } + public WidgetAnimator ParentCoordinateSystem + { + get + { + return mParentCoordinates ?? Parent; + } + set { mParentCoordinates = value; } + } + + public Point ClientWidgetOffset { get { return Widget.ClientWidgetOffset; } } + public Size WidgetSize + { + get + { + var widgetSize = ClientRect.Size; + var box = mStyle.BoxModel; + + widgetSize.Width += box.Padding.Left + box.Padding.Right + box.Border.Left + box.Border.Right; + widgetSize.Height += box.Padding.Top + box.Padding.Bottom + box.Border.Bottom + box.Border.Top; + + return widgetSize; + } + } + public Rectangle ClientRect + { + get { return mClientRect; } + set { mClientRect = value; } + } + public Rectangle WidgetRect + { + get + { + return new Rectangle( + mClientRect.X - ClientWidgetOffset.X, + mClientRect.Y - ClientWidgetOffset.Y, + WidgetSize.Width, + WidgetSize.Height); + } + } + + public int X + { + get { return mClientRect.X; } + set { mClientRect.X = value; } + } + public int Y + { + get { return mClientRect.Y; } + set { mClientRect.Y = value; } + } + public int Width + { + get { return mClientRect.Width; } + set { mClientRect.Width = value; } + } + public int Height + { + get { return mClientRect.Height; } + set { mClientRect.Height = value; } + } + + public Rectangle ClientToScreen(Rectangle value) + { + Rectangle translated = value; + + translated.Location = ClientToScreen(value.Location); + + return translated; + } + public Point ClientToScreen(Point clientPoint) + { + if (Parent == null) + return clientPoint; + + Point translated = ClientToParent(clientPoint); + + return ParentCoordinateSystem.ClientToScreen(translated); + } + public Point ScreenToClient(Point screenPoint) + { + if (Parent == null) + return screenPoint; + + Point translated = ParentToClient(screenPoint); + + return Parent.ScreenToClient(translated); + } + public Point ClientToParent(Point clientPoint) + { + Point translated = clientPoint; + + translated.X += X; + translated.Y += Y; + + return translated; + } + public Point ParentToClient(Point parentClientPoint) + { + Point translated = parentClientPoint; + + translated.X -= X; + translated.Y -= Y; + + return translated; + } + + public bool IsDead { get; set; } + + public bool Active { get; private set; } + public bool Visible { get; set; } + + public Widget Widget { get { return mStyle.Widget; } } + public CssStyle Style { get { return mStyle; } } + + CssTransitionType mTransitionType; + public IWidgetTransition Transition { get; private set; } + + public bool InTransition + { + get + { + if (IsDead) return false; + if (Transition == null) return false; + + return (Transition != null && (Transition.Active || Transition.NeedTransition)); + } + } + + public WidgetAnimator(CssStyle style) + { + mStyle = style; + Children = new List<WidgetAnimator>(); + } + + public void Update(double deltaTime) + { + if (Transition == null || mTransitionType != mStyle.Data.Transition.Type) + { + mTransitionType = mStyle.Data.Transition.Type; + Transition = TransitionFactory.CreateTransition(mTransitionType); + Transition.Animator = this; + Transition.Style = mStyle; + + Transition.Initialize(); + } + + if (Transition.NeedTransition && Transition.Active == false) + { + Transition.ActivateTransition(); + } + + if (Transition.Active) + { + Transition.Update(deltaTime); + } + + + if (Transition.AnimationDead) + IsDead = true; + + if (Gesture != null) + { + AnimateForGesture(); + } + } + + private void AnimateForGesture() + { + switch (Gesture.GestureType) + { + case GestureType.Drag: + case GestureType.Swipe: + case GestureType.LongPressDrag: + AnimateDrag(); + break; + } + + } + + private void AnimateDrag() + { + if (Gesture.IsValidForTarget == false) + return; + + Vector2 delta = new Vector2(Gesture.CurrentPoint); + delta -= new Vector2(Gesture.StartPoint); + + if (Gesture.Axis == AxisType.Horizontal) + delta.Y = 0; + else if (Gesture.Axis == AxisType.Vertical) + delta.X = 0; + + ClientRect = new Rectangle( + Widget.ClientRect.X + (int)delta.X, + Widget.ClientRect.Y + (int)delta.Y, + Widget.ClientRect.Width, + Widget.ClientRect.Height); + } + + public override string ToString() + { + return "Animator: " + mStyle.Widget.ToString(); + } + + public Gesture Gesture { get; set; } + } +} Modified: trunk/AgateLib/UserInterface/Css/Rendering/CssRenderer.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Rendering/CssRenderer.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib/UserInterface/Css/Rendering/CssRenderer.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -19,6 +19,7 @@ using AgateLib.DisplayLib; using AgateLib.Geometry; using AgateLib.UserInterface.Css.Documents; +using AgateLib.UserInterface.Css.Rendering.Animators; using AgateLib.UserInterface.Widgets; using System; using System.Collections.Generic; @@ -35,9 +36,12 @@ private CssAdapter mAdapter; Surface mBlankSurface; ICssImageProvider mImageProvider = new CssDefaultImageProvider(); - private CssAdapter adapter; + Gui mGui; + Dictionary<Widget, WidgetAnimator> mAnimators = new Dictionary<Widget, WidgetAnimator>(); + WidgetAnimator mRootAnimator { get { return GetOrCreateAnimator(mGui.Desktop); } } + public CssRenderer(CssAdapter adapter) { mAdapter = adapter; @@ -48,67 +52,148 @@ mBlankSurface = new Surface(buffer); } + public Gui MyGui { get { return mGui; } set { mGui = value; } } public Gesture ActiveGesture { get; set; } - public void Update(Gui gui, double deltaTime) + public void Update(double deltaTime) { - foreach (var widget in gui.Desktop.Descendants) + UpdateAnimatorTree(); + + + InTransition = false; + + foreach (var anim in mAnimators.Values) { - var style = mAdapter.GetStyle(widget); + if (ActiveGesture != null && ActiveGesture.TargetWidget == anim.Widget) + { + anim.Gesture = ActiveGesture; + } + else + anim.Gesture = null; - if (ActiveGesture != null) - style.Animator.Gesture = ActiveGesture.TargetWidget == widget ? ActiveGesture : null; + anim.Update(deltaTime); + anim.Widget.OnUpdate(deltaTime); - style.Animator.Update(deltaTime); + if (anim.InTransition) + InTransition = true; + } + } - widget.OnUpdate(deltaTime); + public WidgetAnimator GetAnimator(Widget widget) + { + return mAnimators[widget]; + } + WidgetAnimator GetOrCreateAnimator(Widget widget) + { + if (mAnimators.ContainsKey(widget) == false) + { + mAnimators.Add(widget, new WidgetAnimator(mAdapter.GetStyle(widget))); } + + return GetAnimator(widget); } - public void Draw(Gui gui) + + #region --- Animation Tree Updating --- + + public void UpdateAnimatorTree() { - foreach (var window in gui.Desktop.Windows) + // update animator tree + var rootAnimator = GetOrCreateAnimator(MyGui.Desktop); + + TreeAddMissingAnimators(rootAnimator, MyGui.Desktop); + TreeRemoveDeadAnimators(rootAnimator, MyGui.Desktop); + } + + List<WidgetAnimator> animsToRemove = new List<WidgetAnimator>(); + + private void TreeAddMissingAnimators(WidgetAnimator anim, Container container) + { + foreach (var widget in container.Children) { - DrawComponent(window); + var childAnim = GetOrCreateAnimator(widget); + + if (anim.Children.Contains(childAnim) == false) + { + anim.Children.Add(childAnim); + childAnim.Parent = anim; + } + + if (widget is Container) + { + TreeAddMissingAnimators(childAnim, (Container)widget); + } } } + private void TreeRemoveDeadAnimators(WidgetAnimator anim, Widget widget) + { + lock (animsToRemove) + { + animsToRemove.Clear(); - private void DrawComponent(Container window) + foreach (var animator in anim.Children) + { + if (animator.IsDead) + animsToRemove.Add(animator); + } + + foreach (var deadAnimator in animsToRemove) + { + anim.Children.Remove(deadAnimator); + mAnimators.Remove(deadAnimator.Widget); + } + + + foreach (var animator in anim.Children) + { + TreeRemoveDeadAnimators(animator, animator.Widget); + } + } + } + + #endregion; + + public bool InTransition { get; private set;} + + public void Draw() { - var style = mAdapter.GetStyle(window); - if (style.Animator.Visible == false) + foreach (var anim in mRootAnimator.Children) + { + DrawComponent(anim); + } + } + + private void DrawComponent(WidgetAnimator anim) + { + if (anim.Visible == false) return; - DrawComponentStyle(window); - DrawComponentContents(window); + DrawComponentStyle(anim); + DrawComponentContents(anim); } - private bool PushClipRect(CssStyle style) + private bool PushClipRect(WidgetAnimator anim) { - Rectangle clipRect = style.Widget.ClientToScreen(new Rectangle(0, 0, style.Widget.ClientRect.Width, style.Widget.ClientRect.Height)); - - if (style.Data.Overflow == CssOverflow.Visible) + if (anim.Style.Data.Overflow == CssOverflow.Visible) return false; + Rectangle clipRect = anim.ClientToScreen(new Rectangle(0, 0, anim.ClientRect.Width, anim.ClientRect.Height)); + Display.PushClipRect(clipRect); return true; } - private void DrawComponentContents(Container window) + private void DrawComponentContents(WidgetAnimator anim) { - var style = mAdapter.GetStyle(window); bool clipping = false; try { - clipping = PushClipRect(style); + clipping = PushClipRect(anim); - foreach (var control in window.Children) + foreach (var child in anim.Children) { - if (control is Container) - DrawComponent((Container)control); - else - DrawComponentStyle(control); + DrawComponent(child); } } finally @@ -118,27 +203,27 @@ } } - private void DrawComponentStyle(Widget control) + private void DrawComponentStyle(WidgetAnimator anim) { - CssStyle style = mAdapter.GetStyle(control); + CssStyle style = anim.Style; - mAdapter.SetFont(control); + mAdapter.SetFont(anim.Widget); - if (control is ITextAlignment) + if (anim.Widget is ITextAlignment) { - ITextAlignment txa = (ITextAlignment)control; + ITextAlignment txa = (ITextAlignment)anim.Widget; txa.TextAlign = ConvertTextAlign(style.Data.Text.Align); } - if (style.Animator.Visible == false) + if (anim.Visible == false) return; - DrawBackground(style); - DrawBorder(style); + DrawBackground(anim); + DrawBorder(anim); SetFontProperties(style); - control.DrawImpl(); + anim.Widget.DrawImpl(anim.ClientToScreen(new Rectangle(Point.Empty, anim.ClientRect.Size))); } private OriginAlignment ConvertTextAlign(CssTextAlign cssTextAlign) @@ -161,33 +246,34 @@ style.Widget.FontColor = style.Data.Font.Color; } - private void DrawBackground(CssStyle style) + private void DrawBackground(WidgetAnimator anim) { Rectangle clipRect; - var control = style.Widget; + var style = anim.Style; + var control = anim.Widget; switch (style.Data.Background.Clip) { case CssBackgroundClip.Content_Box: - clipRect = control.ClientRect; + clipRect = anim.ClientRect; break; case CssBackgroundClip.Padding_Box: clipRect = Rectangle.FromLTRB( - control.WidgetRect.Left + style.BoxModel.Border.Left, - control.WidgetRect.Top + style.BoxModel.Border.Top, - control.WidgetRect.Right + style.BoxModel.Border.Right, - control.WidgetRect.Bottom + style.BoxModel.Border.Bottom); + anim.WidgetRect.Left + style.BoxModel.Border.Left, + anim.WidgetRect.Top + style.BoxModel.Border.Top, + anim.WidgetRect.Right + style.BoxModel.Border.Right, + anim.WidgetRect.Bottom + style.BoxModel.Border.Bottom); break; case CssBackgroundClip.Border_Box: default: - clipRect = control.WidgetRect; + clipRect = anim.WidgetRect; break; } - clipRect = control.Parent.ClientToScreen(clipRect); + clipRect = anim.ParentCoordinateSystem.ClientToScreen(clipRect); if (style.Data.Background.Color.A > 0) { @@ -354,9 +440,11 @@ frameSurface.Draw(src, dest); } - private void DrawBorder(CssStyle style) + private void DrawBorder(WidgetAnimator anim) { - Rectangle borderRect = style.Widget.Parent.ClientToScreen(style.Widget.WidgetRect); + Rectangle borderRect = anim.ParentCoordinateSystem.ClientToScreen( + anim.WidgetRect); + var style = anim.Style; var border = style.Data.Border; Modified: trunk/AgateLib/UserInterface/Css/Rendering/Transitions/IWidgetTransition.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Rendering/Transitions/IWidgetTransition.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib/UserInterface/Css/Rendering/Transitions/IWidgetTransition.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -1,4 +1,5 @@ -// The contents of this file are subject to the Mozilla Public License +using AgateLib.UserInterface.Css.Rendering.Animators; +// The contents of this file are subject to the Mozilla Public License // Version 1.1 (the "License"); you may not use this file except in // compliance with the License. You may obtain a copy of the License at // http://www.mozilla.org/MPL/ @@ -32,10 +33,14 @@ void Update(double deltaTime); - bool NeedTransition(); + bool NeedTransition { get; } WidgetAnimator Animator { get; set; } void Initialize(); + + void ActivateTransition(); + + bool AnimationDead { get; } } } Modified: trunk/AgateLib/UserInterface/Css/Rendering/Transitions/NullTransition.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Rendering/Transitions/NullTransition.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib/UserInterface/Css/Rendering/Transitions/NullTransition.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -1,4 +1,5 @@ -// The contents of this file are subject to the Mozilla Public License +using AgateLib.UserInterface.Css.Rendering.Animators; +// The contents of this file are subject to the Mozilla Public License // Version 1.1 (the "License"); you may not use this file except in // compliance with the License. You may obtain a copy of the License at // http://www.mozilla.org/MPL/ @@ -29,9 +30,9 @@ { bool mActive; - public CssStyle Style {get;set;} - public WidgetAnimator Animator { get;set;} - protected Widget Widget { get { return Style.Widget; } } + public CssStyle Style { get; set; } + public WidgetAnimator Animator { get; set; } + public Widget Widget { get { return Style.Widget; } } public virtual bool Active { @@ -44,7 +45,7 @@ { CopyLayoutDataToAnimator(); } - + public virtual void Update(double deltaTime) { CopyLayoutDataToAnimator(); @@ -55,37 +56,42 @@ protected void CopyLayoutDataToAnimator() { Animator.Visible = Widget.Visible; - Widget.ClientRect = Animator.ClientRect; - - Widget.ClientWidgetOffset = Animator.ClientWidgetOffset; - Widget.WidgetSize = Animator.WidgetSize; + Animator.ClientRect = Widget.ClientRect; + //Animator.WidgetSize = Widget.WidgetSize; } - public virtual bool NeedTransition() + public virtual bool NeedTransition { - bool retval = false; + get + { + if (Widget is Desktop) + return false; - if (Animator.Visible != Widget.Visible) - retval = true; - if (Animator.Visible == false && retval == false) - return false; + if (Animator.Visible != Widget.Visible) + return true; + if (Animator.Visible == false) + return false; + if (Animator.IsDead == false && Animator.Widget.Parent == null) + return true; - if (Animator.ClientRect != Widget.ClientRect) - retval = true; + if (Animator.ClientRect != Widget.ClientRect) + return true; - if (retval != mActive) - { - mActive = retval; - StartTransition(); + return false; } - - return mActive; } - protected virtual void StartTransition() + public virtual void ActivateTransition() { + CopyLayoutDataToAnimator(); + + mActive = false; + + if (Animator.Widget.Parent == null) + AnimationDead = true; } + public bool AnimationDead { get; protected set; } } } Modified: trunk/AgateLib/UserInterface/Css/Rendering/Transitions/SlideTransition.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Rendering/Transitions/SlideTransition.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib/UserInterface/Css/Rendering/Transitions/SlideTransition.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -33,7 +33,7 @@ public CssTransitionDirection TransitionType { get; private set; } - Vector2 mStartPosition; + Vector2 mOutsidePosition; Vector2 mTargetDestination; float mVelocityMag; float mAccelerationMag; @@ -54,88 +54,136 @@ TransitionType = Style.Data.Transition.Direction; mFinalTime = Style.Data.Transition.Time; - mTargetDestination = new Vector2(Animator.ClientRect.X, Animator.ClientRect.Y); - mStartPosition = mTargetDestination; + mTargetDestination = new Vector2(Widget.ClientRect.X, Widget.ClientRect.Y); + mOutsidePosition = mTargetDestination; mVelocity = Vector2.Empty; + const int leeway = 40; + switch (TransitionType) { case CssTransitionDirection.Left: - mStartPosition.X = -Widget.Width - 20; + mOutsidePosition.X = -Widget.Width - leeway; break; case CssTransitionDirection.Top: - mStartPosition.Y = -Widget.Height - 20; + mOutsidePosition.Y = -Widget.Height - leeway; break; case CssTransitionDirection.Right: - mStartPosition.X = Widget.Parent.Width + 20; + mOutsidePosition.X = Widget.Parent.Width + leeway; break; case CssTransitionDirection.Bottom: - mStartPosition.Y = Widget.Parent.Height + 20; + mOutsidePosition.Y = Widget.Parent.Height + leeway; break; } + mDestination = mTargetDestination; + SetDynamicVariables(); + + SetInitialAnimatorProperties(); + } + + private void SetDynamicVariables() + { + mPosition = new Vector2(Animator.ClientRect.Location); + // we are using a parabola to slow down as the window reaches its destination. // r controls the initial speed and amount of slowdown required. at the time // finalTime/r the window has traveled half-way. r must be larger than one. // the value chosen 2+sqrt(2) gives a zero velocity as the windows come to rest. const double r = 3.414213562; - double distance = (mStartPosition - mTargetDestination).Magnitude; + double distance = (mDestination - mPosition).Magnitude; mVelocityMag = -(float)(distance / (mFinalTime * (r - 1)) * (1 - r * r * 0.5)); mAccelerationMag = (float)(distance / (mFinalTime * mFinalTime * (r - 1)) * (r * r - 2 * r)); - - SetInitialWidgetProperties(); - } - protected override void StartTransition() + public override void ActivateTransition() { if (mFirstTransition) { TransitionIn(); mFirstTransition = false; } - else if (Widget.Visible) - TransitionIn(); + else if (Widget.Visible != Animator.Visible) + { + if (Widget.Visible) + TransitionIn(); + else + TransitionOut(); + } + else if (Widget.Parent == null) + { + TransitionOut(); + } else - TransitionOut(); + { + VisibleTransition(); + } + Active = true; } - void TransitionOut() + public override bool NeedTransition { - Initialize(); + get + { + if (Widget.Visible == false && Animator.Visible == false) + return false; + if (Widget.Parent == null) + { + if (Animator.Visible) + return true; + else + return false; + } + return base.NeedTransition; + } + } + + void VisibleTransition() + { Active = true; + movingOut = false; + mTime = 0; + mDestination = new Vector2(Widget.ClientRect.Location); + + SetDynamicVariables(); + RecalculateVectors(); + } + + void TransitionOut() + { + Active = true; movingOut = true; mTime = 0; mVelocity = Vector2.Empty; - mPosition = mTargetDestination; - mDestination = mStartPosition; + mDestination = mOutsidePosition; + SetDynamicVariables(); RecalculateVectors(); - mVelocity += (float)mFinalTime * mAcceleration; - mVelocity *= -1; - mAcceleration *= -1; + //mVelocity += (float)mFinalTime * mAcceleration; + //mVelocity *= -1; + //mAcceleration *= -1; } void TransitionIn() { - Initialize(); - Active = true; movingOut = false; + Animator.Visible = true; mTime = 0; mVelocity = Vector2.Empty; - mPosition = mStartPosition; - mDestination = mTargetDestination; - + mPosition = mOutsidePosition; + mDestination = new Vector2(Widget.ClientRect.X, Widget.ClientRect.Y); + + SetDynamicVariables(); RecalculateVectors(); } @@ -167,38 +215,31 @@ { Active = false; - Animator.Visible = Widget.Visible; + SetPosition(mDestination); - if (movingOut == false) - { - Widget.ClientRect = Animator.ClientRect; - } + if (movingOut) + Animator.Visible = false; } else { - SetWidgetPosition(mPosition); + SetPosition(mPosition); } } - void SetWidgetPosition(Vector2 pos) + void SetPosition(Vector2 pos) { - Widget.X = (int)(pos.X + 0.5); - Widget.Y = (int)(pos.Y + 0.5); - - Widget.ClientRect = new Rectangle( - Widget.ClientRect.Location, Animator.ClientRect.Size); - - Widget.ClientWidgetOffset = Animator.ClientWidgetOffset; - Widget.WidgetSize = Animator.WidgetSize; + Animator.X = (int)(pos.X + 0.5); + Animator.Y = (int)(pos.Y + 0.5); + Animator.Width = Widget.Width; + Animator.Height = Widget.Height; } - private void SetInitialWidgetProperties() + private void SetInitialAnimatorProperties() { - Animator.Visible = true; + Animator.Visible = Widget.Visible; - Widget.ClientRect = Animator.ClientRect; + Animator.ClientRect = Widget.ClientRect; - SetWidgetPosition(mStartPosition); - + SetPosition(mOutsidePosition); } } } Deleted: trunk/AgateLib/UserInterface/Css/Rendering/WidgetAnimator.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Rendering/WidgetAnimator.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib/UserInterface/Css/Rendering/WidgetAnimator.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -1,155 +0,0 @@ -// The contents of this file are subject to the Mozilla Public License -// Version 1.1 (the "License"); you may not use this file except in -// compliance with the License. You may obtain a copy of the License at -// http://www.mozilla.org/MPL/ -// -// Software distributed under the License is distributed on an "AS IS" -// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -// License for the specific language governing rights and limitations -// under the License. -// -// The Original Code is AgateLib. -// -// The Initial Developer of the Original Code is Erik Ylvisaker. -// Portions created by Erik Ylvisaker are Copyright (C) 2006-2014. -// All Rights Reserved. -// -// Contributor(s): Erik Ylvisaker -// -using AgateLib.Geometry; -using AgateLib.UserInterface.Css.Documents; -using AgateLib.UserInterface.Css.Rendering.Transitions; -using AgateLib.UserInterface.Widgets; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AgateLib.UserInterface.Css.Rendering -{ - public class WidgetAnimator - { - CssStyle mStyle; - Rectangle mClientRect; - - public Point ClientWidgetOffset { get; set; } - public Size WidgetSize - { - get - { - var widgetSize = ClientRect.Size; - var box = mStyle.BoxModel; - - widgetSize.Width += box.Padding.Left + box.Padding.Right + box.Border.Left + box.Border.Right; - widgetSize.Height += box.Padding.Top + box.Padding.Bottom + box.Border.Bottom + box.Border.Top; - - return widgetSize; - } - } - public Rectangle ClientRect - { - get { return mClientRect; } - set { mClientRect = value; } - } - public int ClientX - { - get { return mClientRect.X; } - set { mClientRect.X = value; } - } - public int ClientY - { - get { return mClientRect.Y; } - set { mClientRect.Y = value; } - } - public int ClientWidth - { - get { return mClientRect.Width; } - set { mClientRect.Width = value; } - } - public int ClientHeight - { - get { return mClientRect.Height; } - set { mClientRect.Height = value; } - } - - - public bool Active { get; private set; } - public bool Visible { get; set; } - - CssTransitionType mTransitionType; - public IWidgetTransition Transition { get; private set; } - - public WidgetAnimator(CssStyle style) - { - mStyle = style; - } - - public void Update(double deltaTime) - { - if (Transition == null || mTransitionType != mStyle.Data.Transition.Type) - { - mTransitionType = mStyle.Data.Transition.Type; - Transition = TransitionFactory.CreateTransition(mTransitionType); - Transition.Animator = this; - Transition.Style = mStyle; - - Transition.Initialize(); - } - - if (Transition.Active || Transition.NeedTransition()) - { - Transition.Update(deltaTime); - } - - if (Gesture != null) - { - AnimateForGesture(); - } - } - - private void AnimateForGesture() - { - switch (Gesture.GestureType) - { - case GestureType.Drag: - case GestureType.Swipe: - case GestureType.LongPressDrag: - AnimateDrag(); - break; - } - - } - - private void AnimateDrag() - { - if (Gesture.IsValidForTarget == false) - return; - - Vector2 delta = new Vector2(Gesture.CurrentPoint); - delta -= new Vector2(Gesture.StartPoint); - - if (Gesture.Axis == AxisType.Horizontal) - delta.Y = 0; - else if (Gesture.Axis == AxisType.Vertical) - delta.X = 0; - - mStyle.Widget.ClientRect = new Rectangle( - mClientRect.X + (int)delta.X, - mClientRect.Y + (int)delta.Y, - mClientRect.Width, - mClientRect.Height); - } - - public Container ParentCoordinateSystem { get { return mStyle.Widget.ParentCoordinateSystem; } } - - public override string ToString() - { - return "Animator: " + mStyle.Widget.ToString(); - } - - public bool IncludeInLayout { get; set; } - - public Gesture Gesture { get; set; } - } -} Modified: trunk/AgateLib/UserInterface/Css/Selectors/CssSelectorIndividual.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Selectors/CssSelectorIndividual.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib/UserInterface/Css/Selectors/CssSelectorIndividual.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -135,9 +135,7 @@ if (Id != null) { - if (Id.Equals(wmp.Id, StringComparison.OrdinalIgnoreCase)) - return true; - else + if (Id.Equals(wmp.Id, StringComparison.OrdinalIgnoreCase) == false) return false; } Modified: trunk/AgateLib/UserInterface/Widgets/Gui.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Gui.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib/UserInterface/Widgets/Gui.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -47,9 +47,13 @@ public Gui(IGuiRenderer renderer, IGuiLayoutEngine layout) { + if (renderer == null) throw new ArgumentNullException("renderer cannot be null."); + mRenderer = renderer; mLayout = layout; + mRenderer.MyGui = this; + mDesktop = new Desktop(this); InputMap = InputMap.CreateDefaultInputMap(); @@ -404,14 +408,14 @@ mGestureController.OnTimePass(); mLayout.UpdateLayout(this); - mRenderer.Update(this, delta_t); + mRenderer.Update(delta_t); DispatchEvent(window => { window.Update(delta_t, ref processInput); return false; }); } public void Draw() { mRenderer.ActiveGesture = mCurrentGesture; - mRenderer.Draw(this); + mRenderer.Draw(); } //internal void OnWindowAdded(int index) Modified: trunk/AgateLib/UserInterface/Widgets/IGuiRenderer.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/IGuiRenderer.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib/UserInterface/Widgets/IGuiRenderer.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -25,10 +25,17 @@ { public interface IGuiRenderer { - void Draw(Gui gui); + Gui MyGui { get; set; } - void Update(Gui gui, double deltaTime); + void Draw(); + void Update(double deltaTime); Gesture ActiveGesture { get; set; } + /// <summary> + /// Gets a boolean value indicating whether the renderer is currently in a transition. + /// During a transition, mouse and touch inputs are ignored and keyboard inputs + /// are queued. + /// </summary> + bool InTransition { get; } } } Modified: trunk/AgateLib/UserInterface/Widgets/ImageBox.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/ImageBox.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib/UserInterface/Widgets/ImageBox.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -32,12 +32,12 @@ public ImageBox() { } - public override void DrawImpl() + public override void DrawImpl(Rectangle screenRect) { if (Image == null) return; - Image.Draw(ClientToScreen(new Point(X, Y))); + Image.Draw(screenRect.Location); } internal override Size ComputeSize(int? minWidth, int? minHeight, int? maxWidth, int? maxHeight) Modified: trunk/AgateLib/UserInterface/Widgets/Label.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Label.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib/UserInterface/Widgets/Label.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -168,12 +168,12 @@ return false; } - public override void DrawImpl() + public override void DrawImpl(Rectangle screenRect) { Font.Color = FontColor; Font.DisplayAlignment = TextAlign; - Point dest = ClientToScreen(Point.Empty); + Point dest = screenRect.Location; switch (Font.DisplayAlignment) { Modified: trunk/AgateLib/UserInterface/Widgets/Menu.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Menu.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib/UserInterface/Widgets/Menu.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -534,6 +534,9 @@ { case GestureType.Touch: case GestureType.LongPress: + if (SelectedItem == null) + return; + SelectedItem.OnPressAccept(); break; Modified: trunk/AgateLib/UserInterface/Widgets/ProgressBar.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/ProgressBar.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib/UserInterface/Widgets/ProgressBar.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -43,11 +43,9 @@ return retval; } - - public override void DrawImpl() + public override void DrawImpl(Rectangle screenRect) { - Rectangle destRect = ClientToScreen( - new Rectangle(0, 0, Width, Height)); + Rectangle destRect = screenRect; if (Max > 0) { Modified: trunk/AgateLib/UserInterface/Widgets/Widget.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Widget.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib/UserInterface/Widgets/Widget.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -252,16 +252,9 @@ if (Visible == false) return; - DrawImpl(); + DrawImpl(ClientToScreen(new Rectangle(Point.Empty, ClientRect.Size))); } - public void Draw(Rectangle parentClient) - { - if (Visible == false) - return; - - DrawImpl(); - } - public virtual void DrawImpl() + public virtual void DrawImpl(Rectangle screenRect) { } internal virtual Size ComputeSize(int? minWidth, int? minHeight, int? maxWidth, int? maxHeight) Modified: trunk/AgateLib/UserInterface/Widgets/WidgetList.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/WidgetList.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib/UserInterface/Widgets/WidgetList.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -1,5 +1,4 @@ -using AgateLib.Geometry; -// The contents of this file are subject to the Mozilla Public License +// The contents of this file are subject to the Mozilla Public License // Version 1.1 (the "License"); you may not use this file except in // compliance with the License. You may obtain a copy of the License at // http://www.mozilla.org/MPL/ @@ -21,6 +20,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using AgateLib.Geometry; namespace AgateLib.UserInterface.Widgets { @@ -56,11 +56,14 @@ mItems.Insert(index, item); item.Parent = mParent; + OnWidgetAdded(item); } public void RemoveAt(int index) { + mParent.LayoutDirty = true; + mItems[index].Parent = null; OnWidgetRemoved(mItems[index]); mItems.RemoveAt(index); @@ -153,7 +156,7 @@ if (mItems.Contains(item)) { - item.Parent = null; + item.Parent = null; OnWidgetRemoved(item); } @@ -195,11 +198,15 @@ protected virtual void OnWidgetAdded(Widget widget) { + widget.LayoutDirty = true; + if (WidgetAdded != null) WidgetAdded(this, new WidgetEventArgs(widget)); } protected virtual void OnWidgetRemoved(Widget widget) { + mParent.LayoutDirty = true; + if (WidgetRemoved != null) WidgetRemoved(this, new WidgetEventArgs(widget)); } Modified: trunk/AgateLib.Platform.WinForms/ApplicationModels/SceneModel.cs =================================================================== --- trunk/AgateLib.Platform.WinForms/ApplicationModels/SceneModel.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib.Platform.WinForms/ApplicationModels/SceneModel.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -1,5 +1,6 @@ using AgateLib.ApplicationModels; using AgateLib.DisplayLib; +using AgateLib.Platform.WinForms.GuiDebug; using System; using System.Collections.Generic; using System.Linq; @@ -21,6 +22,18 @@ WinFormsInitializer.Initialize(Parameters); } + protected override void ProcessArgument(string arg, IList<string> parm) + { + if (arg == "--debuggui") + { + frmGuiDebug debugform = new frmGuiDebug(); + debugform.Show(); + + return; + } + + base.ProcessArgument(arg, parm); + } protected override void BeginModel() { if (sceneToStartWith != null) Modified: trunk/AgateLib.Platform.WinForms/ApplicationModels/SerialModel.cs =================================================================== --- trunk/AgateLib.Platform.WinForms/ApplicationModels/SerialModel.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib.Platform.WinForms/ApplicationModels/SerialModel.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -97,17 +97,9 @@ private void CreateGuiDebug() { - //if (createDebugForm == false) - // return; - frmGuiDebug debugform = new frmGuiDebug(); - //var gdc = AutoCreatedWindow.Impl as GL_DisplayControl; - - //if (gdc != null) - // debugform.Show(gdc.TopLevelForm); - //else - debugform.Show(); + debugform.Show(); } protected override int BeginModel(Func<int> entryPoint) Modified: trunk/AgateLib.Platform.WinForms/GuiDebug/frmGuiDebug.cs =================================================================== --- trunk/AgateLib.Platform.WinForms/GuiDebug/frmGuiDebug.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib.Platform.WinForms/GuiDebug/frmGuiDebug.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -21,20 +21,19 @@ public frmGuiDebug() { InitializeComponent(); - } - protected override CreateParams CreateParams - { - get - { - const int WS_EX_NOACTIVATE = 0x08000000; + //protected override CreateParams CreateParams + //{ + // get + // { + // const int WS_EX_NOACTIVATE = 0x08000000; - CreateParams cp = base.CreateParams; - cp.ExStyle |= WS_EX_NOACTIVATE; - return cp; - } - } + // CreateParams cp = base.CreateParams; + // cp.ExStyle |= WS_EX_NOACTIVATE; + // return cp; + // } + //} private void frmGuiDebug_Load(object sender, EventArgs e) { @@ -123,7 +122,7 @@ private void UpdateTreeView() { - foreach (var gui in AgateLib.UserInterface.GuiStack.Items.ToArray()) + foreach (var gui in AgateLib.UserInterface.GuiStack.Items.ToList()) { var adapter = GetAdapter(gui); @@ -208,10 +207,11 @@ var widget = (AgateLib.UserInterface.Widgets.Widget)e.Node.Tag; var adapter = GetAdapter(widget); var style = adapter.GetStyle(widget); + var renderer = (AgateLib.UserInterface.Css.Rendering.CssRenderer)widget.MyGui.Renderer; pgWidget.SelectedObject = widget; pgStyle.SelectedObject = style; - pgAnimator.SelectedObject = style.Animator; + pgAnimator.SelectedObject = renderer.GetAnimator(widget); } private UserInterface.Css.CssAdapter GetAdapter(UserInterface.Widgets.Widget widget) Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj 2014-09-17 13:48:09 UTC (rev 1527) @@ -77,6 +77,7 @@ <Compile Include="TestCollection.cs" /> <Compile Include="UserInterfaceTests\BasicGuiTest.cs" /> <Compile Include="UserInterfaceTests\GuiStuff.cs" /> + <Compile Include="UserInterfaceTests\TransitionTest.cs" /> </ItemGroup> <ItemGroup> <None Include="packages.config" /> Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/Assets/Style.css =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/Assets/Style.css 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/Assets/Style.css 2014-09-17 13:48:09 UTC (rev 1527) @@ -6,7 +6,7 @@ background-image: url(Images/ui_back_1.png); border-image-source: url(Images/ui_border_2.png); border-image-slice: 10; - transition: slide; + transition: slide 2; layout: column; } Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/Fakes/FakeGuiEngine.cs =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/Fakes/FakeGuiEngine.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/Fakes/FakeGuiEngine.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -9,14 +9,22 @@ { public class FakeRenderer : IGuiRenderer { - public void Draw(Gui gui) + public void Draw() { } - public void Update(Gui gui, double deltaTime) + public void Update(double deltaTime) { } - public Gesture ActiveGesture { get;set;} + public Gesture ActiveGesture { get; set; } + + + public bool InTransition + { + get { return false; } + } + + public Gui MyGui { get; set; } } public class FakeLayout : IGuiLayoutEngine { Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/GuiStuff.cs =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/GuiStuff.cs 2014-09-16 03:21:33 UTC (rev 1526) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/GuiStuff.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -38,15 +38,18 @@ adapter = new CssAdapter(doc, font); gui = new Gui(new CssRenderer(adapter), new CssLayoutEngine(adapter)); - - //var wind = CreateWindow(res); - //wind.Children.Add(new Label("This is a label") { Name = "label1" }); - //wind.Children.Add(new Label("This is another label") { Name = "label2" }); + var wind = new Window("window 1"); + wind.Children.Add(new Label("This is a label") { Name = "label1" }); + wind.Children.Add(new Label("This is another label") { Name = "label2" }); + joy = AgateLib.InputLib.JoystickInput.Joysticks.FirstOrDefault(); - var wind = CreateWindow(); + gui.AddWindow(wind); + windows.Add(wind); + + wind = new Window("window 2"); var menu = new Menu(); menu.Children.Add(MenuItem.OfLabel("First Label", "lblA")); @@ -59,6 +62,8 @@ } wind.Children.Add(menu); + gui.AddWindow(wind); + windows.Add(wind); Mouse.MouseMove += Mouse_MouseMove; Mouse.MouseDown += Mouse_MouseDown; @@ -98,16 +103,6 @@ gui.OnKeyDown(e); } - private Window CreateWindow() - { - var wind = new Window(); - - windows.Add(wind); - gui.Desktop.Children.Add(wind); - - return wind; - } - public CssAdapter Adapter { get { return adapter; } } void ctrl_MouseDown(object sender, MouseEventArgs e) @@ -166,7 +161,17 @@ public void HideShow() { - windows[index].Visible = !windows[index].Visible; + if (index % 2 == 0) + { + windows[index].Visible = !windows[index].Visible; + } + else + { + if (gui.Desktop.Children.Contains(windows[index])) + gui.RemoveWindow(windows[index]); + else + gui.AddWindow(windows[index]); + } index++; index %= windows.Count; Added: trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/TransitionTest.cs =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/TransitionTest.cs (rev 0) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/TransitionTest.cs 2014-09-17 13:48:09 UTC (rev 1527) @@ -0,0 +1,65 @@ +using AgateLib.ApplicationModels; +using AgateLib.DisplayLib; +using AgateLib.Geometry; +using AgateLib.InputLib.Legacy; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.Testing.UserInterfaceTests +{ + public class TransitionTest: Scene, ISceneModelTest + { + public void ModifyModelParameters(SceneModelParameters parameters) + { + } + + public Scene StartScene + { + get { return this; } + } + + public string Name + { + get { return "Transitions"; } + } + + public string Category + { + get { return "User Interface"; } + } + + GuiStuff gs; + + protected override void OnSceneStart() + { + gs = new GuiStuff(); + gs.CreateGui(); + + Keyboard.KeyDown += Keyboard_KeyDown; + } + + void Keyboard_KeyDown(InputEventArgs e) + { + if (e.KeyCode == InputLib.KeyCode.Space) + { + gs.HideShow(); + } + } + + public override void Update(double delta_t) + { + gs.Update(); + } + + public override void Draw() + { + Display.Clear(Color.Purple); + gs.Dr... [truncated message content] |
From: <ka...@us...> - 2014-09-16 03:21:41
|
Revision: 1526 http://sourceforge.net/p/agate/code/1526 Author: kanato Date: 2014-09-16 03:21:33 +0000 (Tue, 16 Sep 2014) Log Message: ----------- Minor fixes to UserInterface classes. Modified Paths: -------------- trunk/AgateLib/UserInterface/Widgets/Container.cs trunk/AgateLib/UserInterface/Widgets/Gui.cs trunk/AgateLib/UserInterface/Widgets/Panel.cs trunk/AgateLib/UserInterface/Widgets/WidgetList.cs Modified: trunk/AgateLib/UserInterface/Widgets/Container.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Container.cs 2014-09-14 03:19:31 UTC (rev 1525) +++ trunk/AgateLib/UserInterface/Widgets/Container.cs 2014-09-16 03:21:33 UTC (rev 1526) @@ -63,7 +63,7 @@ throw new InvalidOperationException("Selected child is not part of this container!"); Children.Remove(item); - Children.Insert(0, item); + Children.Add(item); } public override void Update(double delta_t, ref bool processInput) Modified: trunk/AgateLib/UserInterface/Widgets/Gui.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Gui.cs 2014-09-14 03:19:31 UTC (rev 1525) +++ trunk/AgateLib/UserInterface/Widgets/Gui.cs 2014-09-16 03:21:33 UTC (rev 1526) @@ -488,9 +488,17 @@ public void AddWindow(Window wind) { + if (Desktop.Children.Contains(wind)) + return; + Desktop.Children.Add(wind); } + + public void RemoveWindow(Window wind) + { + Desktop.Children.Remove(wind); + } } class WindowList : IList<Window> Modified: trunk/AgateLib/UserInterface/Widgets/Panel.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Panel.cs 2014-09-14 03:19:31 UTC (rev 1525) +++ trunk/AgateLib/UserInterface/Widgets/Panel.cs 2014-09-16 03:21:33 UTC (rev 1526) @@ -25,5 +25,10 @@ { public class Panel : Container { + public Panel() { } + public Panel(string name) : this() + { + this.Name = name; + } } } Modified: trunk/AgateLib/UserInterface/Widgets/WidgetList.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/WidgetList.cs 2014-09-14 03:19:31 UTC (rev 1525) +++ trunk/AgateLib/UserInterface/Widgets/WidgetList.cs 2014-09-16 03:21:33 UTC (rev 1526) @@ -101,6 +101,9 @@ } public void Add(params Widget[] items) { + if (items.Length == 0) + throw new ArgumentException("No items to add."); + AddRange(items); } public void AddRange(IEnumerable<Widget> items) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2014-09-14 03:19:37
|
Revision: 1525 http://sourceforge.net/p/agate/code/1525 Author: kanato Date: 2014-09-14 03:19:31 +0000 (Sun, 14 Sep 2014) Log Message: ----------- Implement FrameBuffers for WP8 projects. Modified Paths: -------------- trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/FrameBufferSurface.cs trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/SDX_Surface.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj trunk/AgateLib.Tests/Tests.WinForms/AgateLib.Tests.WinForms.csproj trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/MultipleWindows/MultipleWindowTest.cs Added Paths: ----------- trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/MultipleFramebufferTest.cs Removed Paths: ------------- trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/MultipleFramebufferTest.cs Modified: trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/FrameBufferSurface.cs =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/FrameBufferSurface.cs 2014-09-14 00:09:08 UTC (rev 1524) +++ trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/FrameBufferSurface.cs 2014-09-14 03:19:31 UTC (rev 1525) @@ -28,48 +28,39 @@ namespace AgateLib.Platform.WindowsStore.DisplayImplementation { - class FrameBufferSurface : SDX_FrameBuffer + class FrameBufferSurface : SDX_FrameBuffer { Size mSize; SDX_Display mDisplay; D3DDevice mDevice; SDX_Surface mAgateSurface; Texture2D mTexture; - SharpDX.DXGI.Surface mRenderTarget; + RenderTargetView mRenderTargetView; bool mHasDepth; bool mHasStencil; - public FrameBufferSurface(Size size) : base(new NativeCoordinates()) + public FrameBufferSurface(Size size) + : base(new NativeCoordinates()) { - throw new NotImplementedException(); - //mDisplay = Display.Impl as SDX_Display; - //mDevice = mDisplay.D3D_Device; - //mSize = size; + mDisplay = Display.Impl as SDX_Display; + mDevice = mDisplay.D3D_Device; + mSize = size; - //try - //{ - // mTexture = new Texture2D(mDevice.Device, mSize.Width, mSize.Height, - // 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default); - //} - //catch - //{ - // Size newSize = SDX_Surface.NextPowerOfTwo(mSize); + mAgateSurface = new SDX_Surface(mSize); + mTexture = mAgateSurface.D3dTexture; - // mTexture = new Texture(mDevice.Device, newSize.Width, newSize.Height, - // 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default); - //} + var rtvdesc = new RenderTargetViewDescription + { + Format = mTexture.Description.Format, + Dimension = RenderTargetViewDimension.Texture2D, + }; - //mRenderTarget = mTexture.GetSurfaceLevel(0); - - //mAgateSurface = new SDX_Surface(new AgateLib.Utility.Ref<Texture>(mTexture), - // new Rectangle(Point.Empty, Size)); - - //SetHasDepthStencil( + mRenderTargetView = new RenderTargetView(mDevice.Device, mTexture, rtvdesc); } public override void Dispose() { - mRenderTarget.Dispose(); + mRenderTargetView.Dispose(); } public override AgateLib.Geometry.Size Size @@ -79,13 +70,11 @@ public override void BeginRender() { - //mDevice.Device.SetRenderTarget(0, mRenderTarget); - //mDevice.Device.BeginScene(); + mDevice.DeviceContext.OutputMerger.SetRenderTargets(mRenderTargetView); } public override void EndRender() { - //mDevice.Device.EndScene(); } public override bool CanAccessRenderTarget Modified: trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/SDX_Surface.cs =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/SDX_Surface.cs 2014-09-14 00:09:08 UTC (rev 1524) +++ trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/SDX_Surface.cs 2014-09-14 03:19:31 UTC (rev 1525) @@ -41,7 +41,6 @@ { public class SDX_Surface : SurfaceImpl { - SDX_Display mDisplay; D3DDevice mDevice { get { return mDisplay.D3D_Device; } } Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj 2014-09-14 00:09:08 UTC (rev 1524) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj 2014-09-14 03:19:31 UTC (rev 1525) @@ -51,6 +51,7 @@ <Compile Include="DisplayTests\ColorTest.cs" /> <Compile Include="DisplayTests\CoordinateSystem.cs" /> <Compile Include="DisplayTests\Interpolation.cs" /> + <Compile Include="DisplayTests\MultipleFramebufferTest.cs" /> <Compile Include="DisplayTests\ParticleTests.cs" /> <Compile Include="DisplayTests\RotatingSpriteTester.cs" /> <Compile Include="DisplayTests\Tiling.cs" /> Copied: trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/MultipleFramebufferTest.cs (from rev 1523, trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/MultipleFramebufferTest.cs) =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/MultipleFramebufferTest.cs (rev 0) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/MultipleFramebufferTest.cs 2014-09-14 03:19:31 UTC (rev 1525) @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib; +using AgateLib.DisplayLib; +using AgateLib.Geometry; +using AgateLib.InputLib; +using AgateLib.InputLib.Legacy; + +namespace AgateLib.Testing.DisplayTests +{ + class MultipleFramebufferTest : ISerialModelTest + { + List<Surface> mRegionColors = new List<Surface>(); + + public string Name + { + get { return "Multiple Framebuffer Test"; } + } + + public string Category + { + get { return "Display"; } + } + + List<Surface> tests = new List<Surface>(); + bool done; + Font font; + Surface mySurface; + + public void EntryPoint() + { + font = Assets.Fonts.AgateSans; + font.Size = 14; + + Mouse.MouseDown += Mouse_MouseDown; + + mySurface = new Surface("9ball.png"); + + while (Display.CurrentWindow.IsClosed == false && done == false) + { + Display.RenderTarget = Display.CurrentWindow.FrameBuffer; + Display.BeginFrame(); + Display.Clear(Color.Gray); + + font.Color = Color.White; + font.DisplayAlignment = OriginAlignment.TopLeft; + font.DrawText("Click or tap to create another frame buffer."); + + int y = font.FontHeight; + int x = 10; + foreach (var surf in tests) + { + surf.Draw(x, y); + y += surf.DisplayHeight + 10; + + if (y + 42 >= Display.CurrentWindow.Height) + { + y = font.FontHeight; + x += 42; + } + } + + Display.EndFrame(); + Core.KeepAlive(); + } + } + + void Mouse_MouseDown(InputEventArgs e) + { + if (e.MouseButtons == MouseButton.Primary) + CreateTests(); + else + done = true; + } + + int hueAngle = 0; + + private void CreateTests() + { + const int angleIncrement = 373 / 8; + font.Color = Color.Black; + font.DisplayAlignment = OriginAlignment.CenterRight; + + FrameBuffer frame = new FrameBuffer(32, 32); + var clr = Color.FromHsv(hueAngle, 1, 1); + + Display.RenderTarget = frame; + Display.BeginFrame(); + Display.Clear(); + mySurface.Draw(new Rectangle(Point.Empty, frame.Size)); + Display.FillRect(new Rectangle(0, 0, 8, 32), clr); + + var pt = new Point(31, 16); + string text = tests.Count.ToString(); + + font.Color = Color.Black; + font.DrawText(pt.X - 1, pt.Y, text); + font.DrawText(pt.X + 1, pt.Y, text); + font.DrawText(pt.X, pt.Y - 1, text); + font.DrawText(pt.X, pt.Y + 1, text); + + font.Color = Color.White; + font.DrawText(pt.X, pt.Y, text); + + Display.EndFrame(); + tests.Add(frame.RenderTarget); + + hueAngle += angleIncrement; + } + + public void ModifyModelParameters(ApplicationModels.SerialModelParameters parameters) + { + } + } +} Modified: trunk/AgateLib.Tests/Tests.WinForms/AgateLib.Tests.WinForms.csproj =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/AgateLib.Tests.WinForms.csproj 2014-09-14 00:09:08 UTC (rev 1524) +++ trunk/AgateLib.Tests/Tests.WinForms/AgateLib.Tests.WinForms.csproj 2014-09-14 03:19:31 UTC (rev 1525) @@ -147,7 +147,6 @@ </Compile> <Compile Include="DisplayTests\LargeImage.cs" /> <Compile Include="DisplayTests\DisplayWindowEvents.cs" /> - <Compile Include="DisplayTests\MultipleFramebufferTest.cs" /> <Compile Include="DisplayTests\PixelBufferMask.cs" /> <Compile Include="DisplayTests\Prerendered.cs" /> <Compile Include="DisplayTests\RenderTargetContinuous.cs" /> Deleted: trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/MultipleFramebufferTest.cs =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/MultipleFramebufferTest.cs 2014-09-14 00:09:08 UTC (rev 1524) +++ trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/MultipleFramebufferTest.cs 2014-09-14 03:19:31 UTC (rev 1525) @@ -1,122 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using AgateLib; -using AgateLib.DisplayLib; -using AgateLib.Geometry; -using AgateLib.InputLib; -using AgateLib.Platform.WinForms; -using AgateLib.Platform.WinForms.Resources; -using AgateLib.Platform.WinForms.ApplicationModels; -using AgateLib.InputLib.Legacy; - -namespace AgateLib.Testing.DisplayTests -{ - class MultipleFramebufferTest : IAgateTest - { - List<Surface> mRegionColors = new List<Surface>(); - - public string Name - { - get { return "Multiple Framebuffer Test"; } - } - - public string Category - { - get { return "Display"; } - } - - List<Surface> tests = new List<Surface>(); - bool done; - Font font; - - public void Main(string[] args) - { - new PassiveModel(args).Run( () => - { - DisplayWindow wind = DisplayWindow.CreateWindowed("Multiple Framebuffer Test", - 640, 480); - - font = Assets.Fonts.AgateSans; - - CreateTests(); - - Keyboard.KeyDown += new InputEventHandler(Keyboard_KeyDown); - - while (wind.IsClosed == false && done == false) - { - Display.RenderTarget = wind.FrameBuffer; - Display.BeginFrame(); - Display.Clear(Color.Gray); - - font.Color = Color.White; - font.DisplayAlignment = OriginAlignment.TopLeft; - font.DrawText("Press space to create another frame buffer."); - - int y = font.FontHeight; - int x = 10; - foreach (var surf in tests) - { - surf.Draw(x, y); - y += surf.DisplayHeight + 10; - - if (y + 42 >= wind.Height) - { - y = font.FontHeight; - x += 42; - } - } - - Display.EndFrame(); - Core.KeepAlive(); - } - }); - } - - void Keyboard_KeyDown(InputEventArgs e) - { - if (e.KeyCode == KeyCode.Escape) - done = true; - - if (e.KeyCode == KeyCode.Space) - CreateTests(); - } - - int hueAngle = 0; - private void CreateTests() - { - const int angleIncrement = 373 / 8; - font.Color = Color.Black; - font.DisplayAlignment = OriginAlignment.CenterRight; - Surface mySurface = new Surface("jellybean.png"); - - FrameBuffer frame = new FrameBuffer(32, 32); - var clr = Color.FromHsv(hueAngle, 1, 1); - - Display.RenderTarget = frame; - Display.BeginFrame(); - Display.Clear(); - mySurface.Draw(); - Display.FillRect(new Rectangle(0, 0, 8, 32), clr); - - var pt = new Point(31, 16); - string text = tests.Count.ToString(); - - font.Color = Color.Black; - font.DrawText(pt.X - 1, pt.Y, text); - font.DrawText(pt.X + 1, pt.Y, text); - font.DrawText(pt.X, pt.Y - 1, text); - font.DrawText(pt.X, pt.Y + 1, text); - - font.Color = Color.White; - font.DrawText(pt.X, pt.Y, text); - - Display.EndFrame(); - tests.Add(frame.RenderTarget); - frame.RenderTarget.SaveTo("test.png", ImageFileFormat.Png); - - hueAngle += angleIncrement; - } - } -} Modified: trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/MultipleWindows/MultipleWindowTest.cs =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/MultipleWindows/MultipleWindowTest.cs 2014-09-14 00:09:08 UTC (rev 1524) +++ trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/MultipleWindows/MultipleWindowTest.cs 2014-09-14 03:19:31 UTC (rev 1525) @@ -10,6 +10,7 @@ using AgateLib.Platform.WinForms; using AgateLib.Platform.WinForms.Resources; using AgateLib.Platform.WinForms.ApplicationModels; +using AgateLib.ApplicationModels; namespace AgateLib.Testing.DisplayTests.MultipleWindows { @@ -31,72 +32,81 @@ public void Main(string[] args) { - new PassiveModel(args).Run( () => + var parameters = new PassiveModelParameters(args); + parameters.AssetLocations.Path = "Assets"; + + new PassiveModel(parameters).Run( () => { - MultipleRenderTargetExample myForm = new MultipleRenderTargetExample(); - myForm.Show(); + EntryPoint(); + }); + } - // create three display windows - DisplayWindow wnd_1 = DisplayWindow.CreateFromControl(myForm.pictureBox1); - DisplayWindow wnd_2 = DisplayWindow.CreateFromControl(myForm.pictureBox2); - DisplayWindow wnd_3 = DisplayWindow.CreateFromControl(myForm.pictureBox3); + private void EntryPoint() + { + MultipleRenderTargetExample myForm = new MultipleRenderTargetExample(); + myForm.Show(); - myForm.pictureBox3.Resize += new EventHandler(wnd_3_Resize); + // create three display windows + DisplayWindow wnd_1 = DisplayWindow.CreateFromControl(myForm.pictureBox1); + DisplayWindow wnd_2 = DisplayWindow.CreateFromControl(myForm.pictureBox2); + DisplayWindow wnd_3 = DisplayWindow.CreateFromControl(myForm.pictureBox3); - // this is the code that will be called when the button is pressed - myForm.btnDraw.Click += new EventHandler(btnDraw_Click); - myForm.btnClearSurface.Click += new EventHandler(btnClear_Click); - myForm.btnDrawText.Click += new EventHandler(btnDrawText_Click); - Surface image1 = new Surface("jellybean.png"); - Surface image2 = new Surface("9ball.png"); - image1.DisplayWidth = 40; - image1.DisplayHeight = (int)(image1.DisplayWidth * image1.SurfaceHeight / (double)image1.SurfaceWidth); - image2.DisplayWidth = 40; - image2.DisplayHeight = (int)(image2.DisplayWidth * image2.SurfaceHeight / (double)image2.SurfaceWidth); + myForm.pictureBox3.Resize += new EventHandler(wnd_3_Resize); - double time = 0; + // this is the code that will be called when the button is pressed + myForm.btnDraw.Click += new EventHandler(btnDraw_Click); + myForm.btnClearSurface.Click += new EventHandler(btnClear_Click); + myForm.btnDrawText.Click += new EventHandler(btnDrawText_Click); + Surface image1 = new Surface("jellybean.png"); + Surface image2 = new Surface("9ball.png"); + image1.DisplayWidth = 40; + image1.DisplayHeight = (int)(image1.DisplayWidth * image1.SurfaceHeight / (double)image1.SurfaceWidth); + image2.DisplayWidth = 40; + image2.DisplayHeight = (int)(image2.DisplayWidth * image2.SurfaceHeight / (double)image2.SurfaceWidth); - frameBuffer = new FrameBuffer(wnd_3.Width, wnd_3.Height); + double time = 0; - while (myForm.Visible) - { - // Render targets must be set before the call to BeginFrame, - // and may not be changed between BeginFrame and EndFrame. - // Use the FrameBuffer property of each DisplayWindow object - // to set the Display.RenderTarget value. - Display.RenderTarget = wnd_1.FrameBuffer; + frameBuffer = new FrameBuffer(wnd_3.Width, wnd_3.Height); + ClearFrameBuffer(); - Display.BeginFrame(); - Display.Clear(Color.Red); - Display.FillRect(new Rectangle(20, 20, 40, 30), Color.Blue); - image1.Draw(120 + (int)(30 * Math.Sin(time)), 20); + while (myForm.Visible) + { + // Render targets must be set before the call to BeginFrame, + // and may not be changed between BeginFrame and EndFrame. + // Use the FrameBuffer property of each DisplayWindow object + // to set the Display.RenderTarget value. + Display.RenderTarget = wnd_1.FrameBuffer; - Display.EndFrame(); + Display.BeginFrame(); + Display.Clear(Color.Red); + Display.FillRect(new Rectangle(20, 20, 40, 30), Color.Blue); + image1.Draw(120 + (int)(30 * Math.Sin(time)), 20); - // now do the second window. - Display.RenderTarget = wnd_2.FrameBuffer; + Display.EndFrame(); - Display.BeginFrame(); - Display.Clear(Color.Green); - Display.FillRect(new Rectangle(20, 20, 40, 30), Color.Yellow); - image2.Draw(120 + (int)(30 * Math.Cos(time)), 20); + // now do the second window. + Display.RenderTarget = wnd_2.FrameBuffer; - Display.EndFrame(); + Display.BeginFrame(); + Display.Clear(Color.Green); + Display.FillRect(new Rectangle(20, 20, 40, 30), Color.Yellow); + image2.Draw(120 + (int)(30 * Math.Cos(time)), 20); - // draw the third window from the surface - Display.RenderTarget = wnd_3.FrameBuffer; + Display.EndFrame(); - surf = frameBuffer.RenderTarget; + // draw the third window from the surface + Display.RenderTarget = wnd_3.FrameBuffer; - Display.BeginFrame(); - Display.Clear(Color.Gray); - surf.Draw(0, 0); - Display.EndFrame(); + surf = frameBuffer.RenderTarget; - Core.KeepAlive(); - time = Timing.TotalSeconds; - } - }); + Display.BeginFrame(); + Display.Clear(Color.Gray); + surf.Draw(0, 0); + Display.EndFrame(); + + Core.KeepAlive(); + time = Timing.TotalSeconds; + } } void btnDrawText_Click(object sender, EventArgs e) @@ -142,6 +152,11 @@ void btnClear_Click(object sender, EventArgs e) { + ClearFrameBuffer(); + } + + private void ClearFrameBuffer() + { Display.RenderTarget = frameBuffer; Display.BeginFrame(); Display.Clear(0, 0, 0, 0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2014-09-14 00:09:19
|
Revision: 1524 http://sourceforge.net/p/agate/code/1524 Author: kanato Date: 2014-09-14 00:09:08 +0000 (Sun, 14 Sep 2014) Log Message: ----------- Connect touch events for WP apps. Modified Paths: -------------- trunk/AgateLib/UserInterface/Widgets/MenuItem.cs trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/SDX_Surface.cs trunk/AgateLib.Platform.WindowsStoreCommon/Factories/DisplayFactory.cs trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/WindowsStoreAssetFileProvider.cs trunk/AgateLib.Platform.WindowsStoreCommon/RenderTargetAdapterBase.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj trunk/AgateLib.Tests/Tests.WinForms/AgateLib.Tests.WinForms.csproj trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/GuiTest.cs trunk/AgateLib.Tests/Tests.WindowsMetro/TestContainer.xaml.cs trunk/AgateLib.Tests/Tests.WindowsPhone/TestContainer.xaml.cs Added Paths: ----------- trunk/AgateLib.Tests/AgateLib.Tests.Portable/Assets/CssTest.css trunk/AgateLib.Tests/AgateLib.Tests.Portable/Assets/Images/ trunk/AgateLib.Tests/AgateLib.Tests.Portable/Assets/Resources/ trunk/AgateLib.Tests/AgateLib.Tests.Portable/Assets/Style.css trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/ trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/BasicGuiTest.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/GuiStuff.cs trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/frmCssEdit.Designer.cs trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/frmCssEdit.cs trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/frmCssEdit.resx Removed Paths: ------------- trunk/AgateLib.Tests/Tests.WinForms/Assets/Images/ trunk/AgateLib.Tests/Tests.WinForms/Assets/Style.css trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/Form1.Designer.cs trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/Form1.cs trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/Form1.resx trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/GuiStuff.cs Modified: trunk/AgateLib/UserInterface/Widgets/MenuItem.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/MenuItem.cs 2014-09-13 23:39:50 UTC (rev 1523) +++ trunk/AgateLib/UserInterface/Widgets/MenuItem.cs 2014-09-14 00:09:08 UTC (rev 1524) @@ -136,6 +136,7 @@ } bool mouseDown; + void widget_MouseDown(object sender, MouseEventArgs e) { OnMouseDown(e.Buttons, e.Location); Modified: trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/SDX_Surface.cs =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/SDX_Surface.cs 2014-09-13 23:39:50 UTC (rev 1523) +++ trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/SDX_Surface.cs 2014-09-14 00:09:08 UTC (rev 1524) @@ -203,9 +203,10 @@ await window.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => { - var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(mFileName)); - var sourceStream = await file.OpenStreamForReadAsync(); - + //var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(mFileName)); + //var sourceStream = await file.OpenStreamForReadAsync(); + var sourceStream = new NativeFileStream(mFileName, NativeFileMode.Open, NativeFileAccess.Read); + ReadFromStream(sourceStream, true); }); } Modified: trunk/AgateLib.Platform.WindowsStoreCommon/Factories/DisplayFactory.cs =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/Factories/DisplayFactory.cs 2014-09-13 23:39:50 UTC (rev 1523) +++ trunk/AgateLib.Platform.WindowsStoreCommon/Factories/DisplayFactory.cs 2014-09-14 00:09:08 UTC (rev 1524) @@ -82,7 +82,7 @@ if (resources == null) { - var assets = new WindowsStoreAssetFileProvider("ms-appx:///AgateLib.Platform.WindowsStoreCommon/Assets"); + var assets = new WindowsStoreAssetFileProvider("AgateLib.Platform.WindowsStoreCommon/Assets"); resources = new AgateResourceCollection(); AgateResourceLoader.LoadResources(resources, Modified: trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/WindowsStoreAssetFileProvider.cs =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/WindowsStoreAssetFileProvider.cs 2014-09-13 23:39:50 UTC (rev 1523) +++ trunk/AgateLib.Platform.WindowsStoreCommon/PlatformImplementation/WindowsStoreAssetFileProvider.cs 2014-09-14 00:09:08 UTC (rev 1524) @@ -1,4 +1,5 @@ using AgateLib.Platform.WindowsStore.DisplayImplementation; +using SharpDX.IO; using System; using System.Collections.Generic; using System.IO; @@ -13,6 +14,7 @@ public class WindowsStoreAssetFileProvider : IReadFileProvider { string path; + string uriBase; public WindowsStoreAssetFileProvider(string path) { @@ -20,10 +22,12 @@ path += "/"; this.path = path; + + uriBase = "ms-appx:///" + path; } public async Task<System.IO.Stream> OpenReadAsync(string filename) { - Uri uri = new Uri(path + filename); + Uri uri = new Uri(uriBase + filename); StorageFile storageFile = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri).AsTask().ConfigureAwait(false); @@ -50,7 +54,7 @@ public string ReadAllText(string filename) { - throw new NotImplementedException(); + return NativeFile.ReadAllText(path + filename); } public bool IsRealFile(string filename) Modified: trunk/AgateLib.Platform.WindowsStoreCommon/RenderTargetAdapterBase.cs =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/RenderTargetAdapterBase.cs 2014-09-13 23:39:50 UTC (rev 1523) +++ trunk/AgateLib.Platform.WindowsStoreCommon/RenderTargetAdapterBase.cs 2014-09-14 00:09:08 UTC (rev 1524) @@ -73,13 +73,6 @@ Disposed(this, EventArgs.Empty); } - void mRenderTarget_KeyUp(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e) - { - Input.QueueInputEvent(AgateInputEventArgs.KeyUp( - TransformKey(e.Key), - GetKeyModifiers())); - } - private KeyModifiers GetKeyModifiers() { return new KeyModifiers(false, false, false); @@ -102,9 +95,17 @@ TransformKey(e.Key), GetKeyModifiers())); } + void mRenderTarget_KeyUp(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e) + { + Input.QueueInputEvent(AgateInputEventArgs.KeyUp( + TransformKey(e.Key), + GetKeyModifiers())); + } void mRenderTarget_PointerReleased(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { + Input.QueueInputEvent(AgateInputEventArgs.MouseUp(Owner, + e.GetCurrentPoint(RenderTargetControl).Position.ToAgatePoint(), MouseButton.Primary)); } void mRenderTarget_PointerPressed(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) @@ -116,6 +117,8 @@ void mRenderTarget_PointerMoved(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { + Input.QueueInputEvent(AgateInputEventArgs.MouseMove(Owner, + e.GetCurrentPoint(RenderTargetControl).Position.ToAgatePoint())); } void mRenderTarget_PointerWheelChanged(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj 2014-09-13 23:39:50 UTC (rev 1523) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj 2014-09-14 00:09:08 UTC (rev 1524) @@ -74,6 +74,8 @@ <Compile Include="ISerialModelTest.cs" /> <Compile Include="TestInfo.cs" /> <Compile Include="TestCollection.cs" /> + <Compile Include="UserInterfaceTests\BasicGuiTest.cs" /> + <Compile Include="UserInterfaceTests\GuiStuff.cs" /> </ItemGroup> <ItemGroup> <None Include="packages.config" /> @@ -88,6 +90,9 @@ <Content Include="Assets\boxsprite.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> + <Content Include="Assets\CssTest.css"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </Content> <Content Include="Assets\fonts\MedievalSharp14.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> @@ -106,9 +111,39 @@ <Content Include="Assets\fonts\sample_font.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> + <Content Include="Assets\Images\ui_back_1.png"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> + <Content Include="Assets\Images\ui_border_1.png"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> + <Content Include="Assets\Images\ui_border_2.png"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> + <Content Include="Assets\Images\ui_widget.png"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> <Content Include="Assets\jellybean.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> + <Content Include="Assets\Resources\fonts.xml"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> + <Content Include="Assets\Resources\Fonts\MedievalSharp14.png"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> + <Content Include="Assets\Resources\Fonts\MedievalSharp18.png"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> + <Content Include="Assets\Resources\Fonts\MedievalSharpBold14.png"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> + <Content Include="Assets\Resources\Fonts\MedievalSharpBold18.png"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> + <Content Include="Assets\Resources\Fonts\MedievalSharpBold22.png"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> <Content Include="Assets\smoke.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> @@ -124,6 +159,9 @@ <Content Include="Assets\spike.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> + <Content Include="Assets\Style.css"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> <Content Include="Assets\TestResourceFile.xml"> <SubType>Designer</SubType> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> Copied: trunk/AgateLib.Tests/AgateLib.Tests.Portable/Assets/CssTest.css (from rev 1519, trunk/AgateLib.Tests/Tests.WinForms/Assets/CssTest.css) =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/Assets/CssTest.css (rev 0) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/Assets/CssTest.css 2014-09-14 00:09:08 UTC (rev 1524) @@ -0,0 +1,45 @@ + +window +{ + background-image: Window; + background-color: #000000; + background-repeat: no-repeat; +} + +button +{ + background-image: Button; + bg-image-stretch-left: 5; + bg-image-stretch-right: 5; + bg-image-stretch-top: 5; + bg-image-stretch-bottom: 5; + text-color: white; + align: center; + vertical-align: center; +} + +button:default +{ + background-image: ButtonDefault; +} + +button:pressed +{ + background-image: ButtonPressed; +} + +button:hover +{ + overlay-image: ButtonHover; +} + +button:focus +{ + overlay-image: ButtonFocus; +} + +button:disabled +{ + overlay-image: ButtonDisabled; + text-color: gray; +} \ No newline at end of file Copied: trunk/AgateLib.Tests/AgateLib.Tests.Portable/Assets/Style.css (from rev 1519, trunk/AgateLib.Tests/Tests.WinForms/Assets/Style.css) =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/Assets/Style.css (rev 0) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/Assets/Style.css 2014-09-14 00:09:08 UTC (rev 1524) @@ -0,0 +1,29 @@ + +window { + background-color: blue; + padding: 8px; + border: 10px solid black; + background-image: url(Images/ui_back_1.png); + border-image-source: url(Images/ui_border_2.png); + border-image-slice: 10; + transition: slide; + layout: column; +} + + +menuitem { + padding: 8px; +} + +menuitem:selected { + border-image-source: url(Images/ui_border_1.png); + border-image-slice: 6; +} + +label { + color: navy; +} + +label#label1 { + color: pink; +} Added: trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/BasicGuiTest.cs =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/BasicGuiTest.cs (rev 0) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/BasicGuiTest.cs 2014-09-14 00:09:08 UTC (rev 1524) @@ -0,0 +1,51 @@ +using AgateLib.ApplicationModels; +using AgateLib.DisplayLib; +using AgateLib.Geometry; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.Testing.UserInterfaceTests +{ + public class BasicGuiTest : Scene, ISceneModelTest + { + public void ModifyModelParameters(SceneModelParameters parameters) + { + } + + public Scene StartScene + { + get { return this; } + } + + public string Name + { + get { return "Basic GUI"; } + } + + public string Category + { + get { return "User Interface"; } + } + + GuiStuff gs; + + protected override void OnSceneStart() + { + gs = new GuiStuff(); + gs.CreateGui(); + } + public override void Update(double delta_t) + { + gs.Update(); + } + + public override void Draw() + { + Display.Clear(Color.Purple); + gs.Draw(); + } + } +} Copied: trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/GuiStuff.cs (from rev 1520, trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/GuiStuff.cs) =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/GuiStuff.cs (rev 0) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/UserInterfaceTests/GuiStuff.cs 2014-09-14 00:09:08 UTC (rev 1524) @@ -0,0 +1,175 @@ +using AgateLib.DisplayLib; +using AgateLib.Geometry; +using AgateLib.InputLib; +using AgateLib.InputLib.Legacy; +using AgateLib.Resources.Legacy; +using AgateLib.UserInterface.Css; +using AgateLib.UserInterface.Css.Documents; +using AgateLib.UserInterface.Css.Layout; +using AgateLib.UserInterface.Css.Rendering; +using AgateLib.UserInterface.Widgets; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.Testing.UserInterfaceTests +{ + public class GuiStuff + { + Gui gui; + CssAdapter adapter; + List<Window> windows = new List<Window>(); + Font font; + Joystick joy; + + public void CreateGui() + { + AgateResourceCollection res = new AgateResourceCollection("Resources/fonts.xml"); + + font = new Font("Medieval Sharp"); + font.AddFont(new FontSurface(res, "MedievalSharp18"), 18, FontStyles.None); + font.AddFont(new FontSurface(res, "MedievalSharp14"), 14, FontStyles.None); + + var doc = new CssDocument(); + + doc.Load("Style.css"); + adapter = new CssAdapter(doc, font); + + gui = new Gui(new CssRenderer(adapter), new CssLayoutEngine(adapter)); + + //var wind = CreateWindow(res); + + //wind.Children.Add(new Label("This is a label") { Name = "label1" }); + //wind.Children.Add(new Label("This is another label") { Name = "label2" }); + + joy = AgateLib.InputLib.JoystickInput.Joysticks.FirstOrDefault(); + + var wind = CreateWindow(); + var menu = new Menu(); + + menu.Children.Add(MenuItem.OfLabel("First Label", "lblA")); + menu.Children.Add(MenuItem.OfLabel("Second Label", "lblB")); + menu.Children.Add(MenuItem.OfLabel("Third Label", "lblC")); + + foreach(MenuItem menuItem in menu.Children) + { + menuItem.AllowDiscard = true; + } + + wind.Children.Add(menu); + + Mouse.MouseMove += Mouse_MouseMove; + Mouse.MouseDown += Mouse_MouseDown; + Mouse.MouseUp += Mouse_MouseUp; + + Keyboard.KeyDown += Keyboard_KeyDown; + Keyboard.KeyUp += Keyboard_KeyUp; + + if (joy != null) + { + joy.ButtonPressed += joy_ButtonPressed; + joy.ButtonReleased += joy_ButtonReleased; + } + + AgateLib.InputLib.Input.InputHandlers.Add(gui); + + foreach (var ctrl in gui.Desktop.Descendants) + ctrl.MouseDown += ctrl_MouseDown; + } + + void joy_ButtonReleased(object sender, JoystickEventArgs e) + { + + } + + void joy_ButtonPressed(object sender, JoystickEventArgs e) + { + } + + void Keyboard_KeyUp(InputEventArgs e) + { + gui.OnKeyUp(e); + } + + void Keyboard_KeyDown(InputEventArgs e) + { + gui.OnKeyDown(e); + } + + private Window CreateWindow() + { + var wind = new Window(); + + windows.Add(wind); + gui.Desktop.Children.Add(wind); + + return wind; + } + + public CssAdapter Adapter { get { return adapter; } } + + void ctrl_MouseDown(object sender, MouseEventArgs e) + { + if (ItemClicked != null) + ItemClicked(sender, e); + } + + void Mouse_MouseUp(InputEventArgs e) + { + gui.OnMouseUp(e); + } + + void Mouse_MouseDown(InputEventArgs e) + { + gui.OnMouseDown(e); + } + + void Mouse_MouseMove(InputEventArgs e) + { + gui.OnMouseMove(e); + } + + public event EventHandler ItemClicked; + + + public string Css + { + set + { + adapter.Document = CssDocument.FromText(value); + } + } + public void Update() + { + gui.OnUpdate(Display.DeltaTime, true); + } + public void Draw() + { + gui.Draw(); + } + + public void Render() + { + gui.OnUpdate(Display.DeltaTime / 1000.0, true); + + Display.BeginFrame(); + Display.Clear(Color.FromArgb(146, 146, 146)); + + Draw(); + + Display.EndFrame(); + } + + int index; + + public void HideShow() + { + windows[index].Visible = !windows[index].Visible; + + index++; + index %= windows.Count; + } + } +} Modified: trunk/AgateLib.Tests/Tests.WinForms/AgateLib.Tests.WinForms.csproj =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/AgateLib.Tests.WinForms.csproj 2014-09-13 23:39:50 UTC (rev 1523) +++ trunk/AgateLib.Tests/Tests.WinForms/AgateLib.Tests.WinForms.csproj 2014-09-14 00:09:08 UTC (rev 1524) @@ -324,13 +324,12 @@ <DependentUpon>LightingTestForm.cs</DependentUpon> <SubType>Code</SubType> </Compile> - <Compile Include="UserInterfaceTests\Form1.cs"> + <Compile Include="UserInterfaceTests\frmCssEdit.cs"> <SubType>Form</SubType> </Compile> - <Compile Include="UserInterfaceTests\Form1.Designer.cs"> - <DependentUpon>Form1.cs</DependentUpon> + <Compile Include="UserInterfaceTests\frmCssEdit.Designer.cs"> + <DependentUpon>frmCssEdit.cs</DependentUpon> </Compile> - <Compile Include="UserInterfaceTests\GuiStuff.cs" /> <Compile Include="UserInterfaceTests\GuiTest.cs" /> <Compile Include="WinFormsTests\Converters.cs"> <SubType>Code</SubType> @@ -403,8 +402,8 @@ <SubType>Designer</SubType> <DependentUpon>LightingTestForm.cs</DependentUpon> </EmbeddedResource> - <EmbeddedResource Include="UserInterfaceTests\Form1.resx"> - <DependentUpon>Form1.cs</DependentUpon> + <EmbeddedResource Include="UserInterfaceTests\frmCssEdit.resx"> + <DependentUpon>frmCssEdit.cs</DependentUpon> </EmbeddedResource> <None Include="app.config" /> <None Include="Assets\9ball.png"> @@ -465,9 +464,6 @@ </None> </ItemGroup> <ItemGroup> - <None Include="Assets\Style.css"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - </None> <None Include="Assets\largeimage.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> @@ -486,18 +482,6 @@ <Content Include="Assets\fonts\MedievalSharpBold22.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> - <Content Include="Assets\Images\ui_back_1.png"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - </Content> - <Content Include="Assets\Images\ui_border_1.png"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - </Content> - <Content Include="Assets\Images\ui_border_2.png"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - </Content> - <Content Include="Assets\Images\ui_widget.png"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - </Content> <Content Include="Assets\mask_bg-bricks.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> Deleted: trunk/AgateLib.Tests/Tests.WinForms/Assets/Style.css =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/Assets/Style.css 2014-09-13 23:39:50 UTC (rev 1523) +++ trunk/AgateLib.Tests/Tests.WinForms/Assets/Style.css 2014-09-14 00:09:08 UTC (rev 1524) @@ -1,32 +0,0 @@ - -window { - background-color: blue; - padding: 8px; - border: 10px solid black; - background-image: url(Images/ui_back_1.png); - border-image-source: url(Images/ui_border_2.png); - border-image-slice: 10; - transition: slide; - layout: column; -} - - -menuitem:hover { - border-image-source: url(Images/ui_border_1.png); - border-image-slice: 6; -} - -menuitem:selected { - border-image-source: url(Images/ui_border_1.png); - border-image-slice: 6; -} - -label { - color: lightgreen; - margin-left: 4px; - background-color: rgba(255, 216, 0, 0.15); -} - -label#label1 { - color: pink; -} Deleted: trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/Form1.Designer.cs =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/Form1.Designer.cs 2014-09-13 23:39:50 UTC (rev 1523) +++ trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/Form1.Designer.cs 2014-09-14 00:09:08 UTC (rev 1524) @@ -1,194 +0,0 @@ -namespace AgateLib.Testing.UserInterfaceTests -{ - partial class Form1 - { - /// <summary> - /// Required designer variable. - /// </summary> - private System.ComponentModel.IContainer components = null; - - /// <summary> - /// Clean up any resources being used. - /// </summary> - /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// <summary> - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// </summary> - private void InitializeComponent() - { - this.artGuiTest = new AgateLib.Platform.WinForms.Controls.AgateRenderTarget(); - this.splitContainer1 = new System.Windows.Forms.SplitContainer(); - this.panel1 = new System.Windows.Forms.Panel(); - this.cboPropertyItems = new System.Windows.Forms.ComboBox(); - this.propertyGrid1 = new System.Windows.Forms.PropertyGrid(); - this.lblFrames = new System.Windows.Forms.Label(); - this.txtCss = new System.Windows.Forms.TextBox(); - this.artGuiTest = new AgateLib.Platform.WinForms.Controls.AgateRenderTarget(); - this.splitContainer2 = new System.Windows.Forms.SplitContainer(); - this.btnHideShow = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); - this.splitContainer1.Panel1.SuspendLayout(); - this.splitContainer1.Panel2.SuspendLayout(); - this.splitContainer1.SuspendLayout(); - this.panel1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit(); - this.splitContainer2.Panel1.SuspendLayout(); - this.splitContainer2.Panel2.SuspendLayout(); - this.splitContainer2.SuspendLayout(); - this.SuspendLayout(); - // - // splitContainer1 - // - this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; - this.splitContainer1.Location = new System.Drawing.Point(0, 0); - this.splitContainer1.Name = "splitContainer1"; - // - // splitContainer1.Panel1 - // - this.splitContainer1.Panel1.Controls.Add(this.splitContainer2); - // - // splitContainer1.Panel2 - // - this.splitContainer1.Panel2.Controls.Add(this.artGuiTest); - this.splitContainer1.Size = new System.Drawing.Size(926, 590); - this.splitContainer1.SplitterDistance = 472; - this.splitContainer1.TabIndex = 0; - // - // panel1 - // - this.panel1.Controls.Add(this.btnHideShow); - this.panel1.Controls.Add(this.cboPropertyItems); - this.panel1.Controls.Add(this.propertyGrid1); - this.panel1.Controls.Add(this.lblFrames); - this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; - this.panel1.Location = new System.Drawing.Point(0, 0); - this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(472, 291); - this.panel1.TabIndex = 1; - // - // cboPropertyItems - // - this.cboPropertyItems.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.cboPropertyItems.FormattingEnabled = true; - this.cboPropertyItems.Location = new System.Drawing.Point(12, 47); - this.cboPropertyItems.Name = "cboPropertyItems"; - this.cboPropertyItems.Size = new System.Drawing.Size(454, 21); - this.cboPropertyItems.TabIndex = 2; - this.cboPropertyItems.SelectedIndexChanged += new System.EventHandler(this.cboPropertyItems_SelectedIndexChanged); - // - // propertyGrid1 - // - this.propertyGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.propertyGrid1.Location = new System.Drawing.Point(12, 74); - this.propertyGrid1.Name = "propertyGrid1"; - this.propertyGrid1.Size = new System.Drawing.Size(457, 208); - this.propertyGrid1.TabIndex = 1; - // - // lblFrames - // - this.lblFrames.AutoSize = true; - this.lblFrames.Location = new System.Drawing.Point(12, 15); - this.lblFrames.Name = "lblFrames"; - this.lblFrames.Size = new System.Drawing.Size(35, 13); - this.lblFrames.TabIndex = 0; - this.lblFrames.Text = "label1"; - // - // txtCss - // - this.txtCss.Dock = System.Windows.Forms.DockStyle.Fill; - this.txtCss.Location = new System.Drawing.Point(0, 0); - this.txtCss.Multiline = true; - this.txtCss.Name = "txtCss"; - this.txtCss.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.txtCss.Size = new System.Drawing.Size(472, 295); - this.txtCss.TabIndex = 0; - this.txtCss.TextChanged += new System.EventHandler(this.txtCss_TextChanged); - // - // artGuiTest - // - this.artGuiTest.Dock = System.Windows.Forms.DockStyle.Fill; - this.artGuiTest.Location = new System.Drawing.Point(0, 0); - this.artGuiTest.Name = "artGuiTest"; - this.artGuiTest.Size = new System.Drawing.Size(450, 590); - this.artGuiTest.TabIndex = 0; - // - // splitContainer2 - // - this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill; - this.splitContainer2.Location = new System.Drawing.Point(0, 0); - this.splitContainer2.Name = "splitContainer2"; - this.splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal; - // - // splitContainer2.Panel1 - // - this.splitContainer2.Panel1.Controls.Add(this.txtCss); - // - // splitContainer2.Panel2 - // - this.splitContainer2.Panel2.Controls.Add(this.panel1); - this.splitContainer2.Size = new System.Drawing.Size(472, 590); - this.splitContainer2.SplitterDistance = 295; - this.splitContainer2.TabIndex = 2; - // - // btnHideShow - // - this.btnHideShow.Location = new System.Drawing.Point(391, 10); - this.btnHideShow.Name = "btnHideShow"; - this.btnHideShow.Size = new System.Drawing.Size(75, 23); - this.btnHideShow.TabIndex = 3; - this.btnHideShow.Text = "Hide/Show"; - this.btnHideShow.UseVisualStyleBackColor = true; - this.btnHideShow.Click += new System.EventHandler(this.btnHideShow_Click); - // - // Form1 - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(926, 590); - this.Controls.Add(this.splitContainer1); - this.Name = "Form1"; - this.Text = "Form1"; - this.Load += new System.EventHandler(this.Form1_Load); - this.splitContainer1.Panel1.ResumeLayout(false); - this.splitContainer1.Panel2.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); - this.splitContainer1.ResumeLayout(false); - this.panel1.ResumeLayout(false); - this.panel1.PerformLayout(); - this.splitContainer2.Panel1.ResumeLayout(false); - this.splitContainer2.Panel1.PerformLayout(); - this.splitContainer2.Panel2.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit(); - this.splitContainer2.ResumeLayout(false); - this.ResumeLayout(false); - - } - - #endregion - - private AgateLib.Platform.WinForms.Controls.AgateRenderTarget artGuiTest; - private System.Windows.Forms.SplitContainer splitContainer1; - private System.Windows.Forms.TextBox txtCss; - private System.Windows.Forms.Panel panel1; - private System.Windows.Forms.Label lblFrames; - private System.Windows.Forms.PropertyGrid propertyGrid1; - private System.Windows.Forms.ComboBox cboPropertyItems; - private System.Windows.Forms.SplitContainer splitContainer2; - private System.Windows.Forms.Button btnHideShow; - } -} - Deleted: trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/Form1.cs =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/Form1.cs 2014-09-13 23:39:50 UTC (rev 1523) +++ trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/Form1.cs 2014-09-14 00:09:08 UTC (rev 1524) @@ -1,76 +0,0 @@ -using AgateLib.DisplayLib; -using AgateLib.UserInterface.Widgets; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace AgateLib.Testing.UserInterfaceTests -{ - public partial class Form1 : Form - { - DisplayWindow wind; - - GuiStuff gui; - - public Form1() - { - InitializeComponent(); - - gui = new GuiStuff(); - gui.CreateGui(); - gui.ItemClicked += gui_ItemClicked; - - txtCss.Text = System.IO.File.ReadAllText("Style.css"); - - - } - - void gui_ItemClicked(object sender, EventArgs e) - { - var obj = (Widget)sender; - - cboPropertyItems.Items.Clear(); - - while (obj != null) - { - cboPropertyItems.Items.Add(gui.Adapter.GetStyle(obj)); - obj = obj.Parent; - } - - cboPropertyItems.SelectedIndex = 0; - } - - private void Form1_Load(object sender, EventArgs e) - { - wind = DisplayWindow.CreateFromControl(artGuiTest); - - } - - public void RenderAgateStuff() - { - gui.Render(); - lblFrames.Text = "Frame: " + Display.FramesPerSecond; - } - - private void txtCss_TextChanged(object sender, EventArgs e) - { - gui.Css = txtCss.Text; - } - - private void cboPropertyItems_SelectedIndexChanged(object sender, EventArgs e) - { - propertyGrid1.SelectedObject = cboPropertyItems.SelectedItem; - } - - private void btnHideShow_Click(object sender, EventArgs e) - { - gui.HideShow(); - } - } -} Deleted: trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/Form1.resx =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/Form1.resx 2014-09-13 23:39:50 UTC (rev 1523) +++ trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/Form1.resx 2014-09-14 00:09:08 UTC (rev 1524) @@ -1,120 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<root> - <!-- - Microsoft ResX Schema - - Version 2.0 - - The primary goals of this format is to allow a simple XML format - that is mostly human readable. The generation and parsing of the - various data types are done through the TypeConverter classes - associated with the data types. - - Example: - - ... ado.net/XML headers & schema ... - <resheader name="resmimetype">text/microsoft-resx</resheader> - <resheader name="version">2.0</resheader> - <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> - <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> - <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> - <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> - <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> - <value>[base64 mime encoded serialized .NET Framework object]</value> - </data> - <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> - <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> - <comment>This is a comment</comment> - </data> - - There are any number of "resheader" rows that contain simple - name/value pairs. - - Each data row contains a name, and value. The row also contains a - type or mimetype. Type corresponds to a .NET class that support - text/value conversion through the TypeConverter architecture. - Classes that don't support this are serialized and stored with the - mimetype set. - - The mimetype is used for serialized objects, and tells the - ResXResourceReader how to depersist the object. This is currently not - extensible. For a given mimetype the value must be set accordingly: - - Note - application/x-microsoft.net.object.binary.base64 is the format - that the ResXResourceWriter will generate, however the reader can - read any of the formats listed below. - - mimetype: application/x-microsoft.net.object.binary.base64 - value : The object must be serialized with - : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter - : and then encoded with base64 encoding. - - mimetype: application/x-microsoft.net.object.soap.base64 - value : The object must be serialized with - : System.Runtime.Serialization.Formatters.Soap.SoapFormatter - : and then encoded with base64 encoding. - - mimetype: application/x-microsoft.net.object.bytearray.base64 - value : The object must be serialized into a byte array - : using a System.ComponentModel.TypeConverter - : and then encoded with base64 encoding. - --> - <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> - <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> - <xsd:element name="root" msdata:IsDataSet="true"> - <xsd:complexType> - <xsd:choice maxOccurs="unbounded"> - <xsd:element name="metadata"> - <xsd:complexType> - <xsd:sequence> - <xsd:element name="value" type="xsd:string" minOccurs="0" /> - </xsd:sequence> - <xsd:attribute name="name" use="required" type="xsd:string" /> - <xsd:attribute name="type" type="xsd:string" /> - <xsd:attribute name="mimetype" type="xsd:string" /> - <xsd:attribute ref="xml:space" /> - </xsd:complexType> - </xsd:element> - <xsd:element name="assembly"> - <xsd:complexType> - <xsd:attribute name="alias" type="xsd:string" /> - <xsd:attribute name="name" type="xsd:string" /> - </xsd:complexType> - </xsd:element> - <xsd:element name="data"> - <xsd:complexType> - <xsd:sequence> - <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> - <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> - </xsd:sequence> - <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> - <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> - <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> - <xsd:attribute ref="xml:space" /> - </xsd:complexType> - </xsd:element> - <xsd:element name="resheader"> - <xsd:complexType> - <xsd:sequence> - <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> - </xsd:sequence> - <xsd:attribute name="name" type="xsd:string" use="required" /> - </xsd:complexType> - </xsd:element> - </xsd:choice> - </xsd:complexType> - </xsd:element> - </xsd:schema> - <resheader name="resmimetype"> - <value>text/microsoft-resx</value> - </resheader> - <resheader name="version"> - <value>2.0</value> - </resheader> - <resheader name="reader"> - <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> - </resheader> - <resheader name="writer"> - <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> - </resheader> -</root> \ No newline at end of file Deleted: trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/GuiStuff.cs =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/GuiStuff.cs 2014-09-13 23:39:50 UTC (rev 1523) +++ trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/GuiStuff.cs 2014-09-14 00:09:08 UTC (rev 1524) @@ -1,171 +0,0 @@ -using AgateLib.DisplayLib; -using AgateLib.Geometry; -using AgateLib.InputLib; -using AgateLib.InputLib.Legacy; -using AgateLib.Resources.Legacy; -using AgateLib.UserInterface.Css; -using AgateLib.UserInterface.Css.Documents; -using AgateLib.UserInterface.Css.Layout; -using AgateLib.UserInterface.Css.Rendering; -using AgateLib.UserInterface.Widgets; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AgateLib.Testing.UserInterfaceTests -{ - class GuiStuff - { - Gui gui; - CssAdapter adapter; - List<Window> windows = new List<Window>(); - Font font; - Joystick joy; - - public void CreateGui() - { - AgateResourceCollection res = new AgateResourceCollection("Resources/fonts.xml"); - - font = new Font("Medieval Sharp"); - font.AddFont(new FontSurface(res, "MedievalSharp18"), 18, FontStyles.None); - font.AddFont(new FontSurface(res, "MedievalSharp14"), 14, FontStyles.None); - - var doc = new CssDocument(); - - doc.Load("Style.css"); - adapter = new CssAdapter(doc, font); - - gui = new Gui(new CssRenderer(adapter), new CssLayoutEngine(adapter)); - - //var wind = CreateWindow(res); - - //wind.Children.Add(new Label("This is a label") { Name = "label1" }); - //wind.Children.Add(new Label("This is another label") { Name = "label2" }); - - joy = AgateLib.InputLib.JoystickInput.Joysticks.FirstOrDefault(); - - var wind = CreateWindow(res); - var menu = new Menu(); - - menu.Children.Add(MenuItem.OfLabel("lblA", "lblA")); - menu.Children.Add(MenuItem.OfLabel("lblB", "lblB")); - menu.Children.Add(MenuItem.OfLabel("lblC", "lblC")); - - wind.Children.Add(menu); - - - Mouse.MouseMove += Mouse_MouseMove; - Mouse.MouseDown += Mouse_MouseDown; - Mouse.MouseUp += Mouse_MouseUp; - - Keyboard.KeyDown += Keyboard_KeyDown; - Keyboard.KeyUp += Keyboard_KeyUp; - - if (joy != null) - { - joy.ButtonPressed += joy_ButtonPressed; - joy.ButtonReleased += joy_ButtonReleased; - } - - - foreach (var ctrl in gui.Desktop.Descendants) - ctrl.MouseDown += ctrl_MouseDown; - } - - void joy_ButtonReleased(object sender, JoystickEventArgs e) - { - - } - - void joy_ButtonPressed(object sender, JoystickEventArgs e) - { - } - - void Keyboard_KeyUp(InputEventArgs e) - { - gui.OnKeyUp(e); - } - - void Keyboard_KeyDown(InputEventArgs e) - { - gui.OnKeyDown(e); - } - - private Window CreateWindow(AgateResourceCollection res) - { - var wind = new Window(); - wind.Font = font; - - windows.Add(wind); - gui.Desktop.Children.Add(wind); - - return wind; - } - - public CssAdapter Adapter { get { return adapter; } } - - void ctrl_MouseDown(object sender, MouseEventArgs e) - { - if (ItemClicked != null) - ItemClicked(sender, e); - } - - void Mouse_MouseUp(InputEventArgs e) - { - gui.OnMouseUp(e); - } - - void Mouse_MouseDown(InputEventArgs e) - { - gui.OnMouseDown(e); - } - - void Mouse_MouseMove(InputEventArgs e) - { - gui.OnMouseMove(e); - } - - public event EventHandler ItemClicked; - - - public string Css - { - set - { - adapter.Document = CssDocument.FromText(value); - } - } - public void Update() - { - gui.OnUpdate(Display.DeltaTime, true); - } - public void Draw() - { - gui.Draw(); - } - - internal void Render() - { - gui.OnUpdate(Display.DeltaTime / 1000.0, true); - - Display.BeginFrame(); - Display.Clear(Color.FromArgb(146, 146, 146)); - - Draw(); - - Display.EndFrame(); - } - - int index; - - internal void HideShow() - { - windows[index].Visible = !windows[index].Visible; - - index++; - index %= windows.Count; - } - } -} Modified: trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/GuiTest.cs =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/GuiTest.cs 2014-09-13 23:39:50 UTC (rev 1523) +++ trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/GuiTest.cs 2014-09-14 00:09:08 UTC (rev 1524) @@ -20,7 +20,7 @@ { new PassiveModel(args).Run(() => { - var f1 = new Form1(); + var f1 = new frmCssEdit(); f1.Show(); Display.RenderState.WaitForVerticalBlank = false; Copied: trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/frmCssEdit.Designer.cs (from rev 1523, trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/Form1.Designer.cs) =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/frmCssEdit.Designer.cs (rev 0) +++ trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/frmCssEdit.Designer.cs 2014-09-14 00:09:08 UTC (rev 1524) @@ -0,0 +1,194 @@ +namespace AgateLib.Testing.UserInterfaceTests +{ + partial class frmCssEdit + { + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.IContainer components = null; + + /// <summary> + /// Clean up any resources being used. + /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// <summary> + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// </summary> + private void InitializeComponent() + { + this.artGuiTest = new AgateLib.Platform.WinForms.Controls.AgateRenderTarget(); + this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.panel1 = new System.Windows.Forms.Panel(); + this.cboPropertyItems = new System.Windows.Forms.ComboBox(); + this.propertyGrid1 = new System.Windows.Forms.PropertyGrid(); + this.lblFrames = new System.Windows.Forms.Label(); + this.txtCss = new System.Windows.Forms.TextBox(); + this.artGuiTest = new AgateLib.Platform.WinForms.Controls.AgateRenderTarget(); + this.splitContainer2 = new System.Windows.Forms.SplitContainer(); + this.btnHideShow = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); + this.splitContainer1.Panel1.SuspendLayout(); + this.splitContainer1.Panel2.SuspendLayout(); + this.splitContainer1.SuspendLayout(); + this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit(); + this.splitContainer2.Panel1.SuspendLayout(); + this.splitContainer2.Panel2.SuspendLayout(); + this.splitContainer2.SuspendLayout(); + this.SuspendLayout(); + // + // splitContainer1 + // + this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer1.Location = new System.Drawing.Point(0, 0); + this.splitContainer1.Name = "splitContainer1"; + // + // splitContainer1.Panel1 + // + this.splitContainer1.Panel1.Controls.Add(this.splitContainer2); + // + // splitContainer1.Panel2 + // + this.splitContainer1.Panel2.Controls.Add(this.artGuiTest); + this.splitContainer1.Size = new System.Drawing.Size(926, 590); + this.splitContainer1.SplitterDistance = 472; + this.splitContainer1.TabIndex = 0; + // + // panel1 + // + this.panel1.Controls.Add(this.btnHideShow); + this.panel1.Controls.Add(this.cboPropertyItems); + this.panel1.Controls.Add(this.propertyGrid1); + this.panel1.Controls.Add(this.lblFrames); + this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(472, 291); + this.panel1.TabIndex = 1; + // + // cboPropertyItems + // + this.cboPropertyItems.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cboPropertyItems.FormattingEnabled = true; + this.cboPropertyItems.Location = new System.Drawing.Point(12, 47); + this.cboPropertyItems.Name = "cboPropertyItems"; + this.cboPropertyItems.Size = new System.Drawing.Size(454, 21); + this.cboPropertyItems.TabIndex = 2; + this.cboPropertyItems.SelectedIndexChanged += new System.EventHandler(this.cboPropertyItems_SelectedIndexChanged); + // + // propertyGrid1 + // + this.propertyGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.propertyGrid1.Location = new System.Drawing.Point(12, 74); + this.propertyGrid1.Name = "propertyGrid1"; + this.propertyGrid1.Size = new System.Drawing.Size(457, 208); + this.propertyGrid1.TabIndex = 1; + // + // lblFrames + // + this.lblFrames.AutoSize = true; + this.lblFrames.Location = new System.Drawing.Point(12, 15); + this.lblFrames.Name = "lblFrames"; + this.lblFrames.Size = new System.Drawing.Size(35, 13); + this.lblFrames.TabIndex = 0; + this.lblFrames.Text = "label1"; + // + // txtCss + // + this.txtCss.Dock = System.Windows.Forms.DockStyle.Fill; + this.txtCss.Location = new System.Drawing.Point(0, 0); + this.txtCss.Multiline = true; + this.txtCss.Name = "txtCss"; + this.txtCss.ScrollBars = System.Windows.Forms.ScrollBars.Both; + this.txtCss.Size = new System.Drawing.Size(472, 295); + this.txtCss.TabIndex = 0; + this.txtCss.TextChanged += new System.EventHandler(this.txtCss_TextChanged); + // + // artGuiTest + // + this.artGuiTest.Dock = System.Windows.Forms.DockStyle.Fill; + this.artGuiTest.Location = new System.Drawing.Point(0, 0); + this.artGuiTest.Name = "artGuiTest"; + this.artGuiTest.Size = new System.Drawing.Size(450, 590); + this.artGuiTest.TabIndex = 0; + // + // splitContainer2 + // + this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer2.Location = new System.Drawing.Point(0, 0); + this.splitContainer2.Name = "splitContainer2"; + this.splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal; + // + // splitContainer2.Panel1 + // + this.splitContainer2.Panel1.Controls.Add(this.txtCss); + // + // splitContainer2.Panel2 + // + this.splitContainer2.Panel2.Controls.Add(this.panel1); + this.splitContainer2.Size = new System.Drawing.Size(472, 590); + this.splitContainer2.SplitterDistance = 295; + this.splitContainer2.TabIndex = 2; + // + // btnHideShow + // + this.btnHideShow.Location = new System.Drawing.Point(391, 10); + this.btnHideShow.Name = "btnHideShow"; + this.btnHideShow.Size = new System.Drawing.Size(75, 23); + this.btnHideShow.TabIndex = 3; + this.btnHideShow.Text = "Hide/Show"; + this.btnHideShow.UseVisualStyleBackColor = true; + this.btnHideShow.Click += new System.EventHandler(this.btnHideShow_Click); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(926, 590); + this.Controls.Add(this.splitContainer1); + this.Name = "Form1"; + this.Text = "Form1"; + this.Load += new System.EventHandler(this.Form1_Load); + this.splitContainer1.Panel1.ResumeLayout(false); + this.splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); + this.splitContainer1.ResumeLayout(false); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + this.splitContainer2.Panel1.ResumeLayout(false); + this.splitContainer2.Panel1.PerformLayout(); + this.splitContainer2.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit(); + this.splitContainer2.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private AgateLib.Platform.WinForms.Controls.AgateRenderTarget artGuiTest; + private System.Windows.Forms.SplitContainer splitContainer1; + private System.Windows.Forms.TextBox txtCss; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.Label lblFrames; + private System.Windows.Forms.PropertyGrid propertyGrid1; + private System.Windows.Forms.ComboBox cboPropertyItems; + private System.Windows.Forms.SplitContainer splitContainer2; + private System.Windows.Forms.Button btnHideShow; + } +} + Copied: trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/frmCssEdit.cs (from rev 1519, trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/Form1.cs) =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/frmCssEdit.cs (rev 0) +++ trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/frmCssEdit.cs 2014-09-14 00:09:08 UTC (rev 1524) @@ -0,0 +1,76 @@ +using AgateLib.DisplayLib; +using AgateLib.UserInterface.Widgets; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AgateLib.Testing.UserInterfaceTests +{ + public partial class frmCssEdit : Form + { + DisplayWindow wind; + + GuiStuff gui; + + public frmCssEdit() + { + InitializeComponent(); + + gui = new GuiStuff(); + gui.CreateGui(); + gui.ItemClicked += gui_ItemClicked; + + txtCss.Text = System.IO.File.ReadAllText("Style.css"); + + + } + + void gui_ItemClicked(object sender, EventArgs e) + { + var obj = (Widget)sender; + + cboPropertyItems.Items.Clear(); + + while (obj != null) + { + cboPropertyItems.Items.Add(gui.Adapter.GetStyle(obj)); + obj = obj.Parent; + } + + cboPropertyItems.SelectedIndex = 0; + } + + private void Form1_Load(object sender, EventArgs e) + { + wind = DisplayWindow.CreateFromControl(artGuiTest); + + } + + public void RenderAgateStuff() + { + gui.Render(); + lblFrames.Text = "Frame: " + Display.FramesPerSecond; + } + + private void txtCss_TextChanged(object sender, EventArgs e) + { + gui.Css = txtCss.Text; + } + + private void cboPropertyItems_SelectedIndexChanged(object sender, EventArgs e) + { + propertyGrid1.SelectedObject = cboPropertyItems.SelectedItem; + } + + private void btnHideShow_Click(object sender, EventArgs e) + { + gui.HideShow(); + } + } +} Copied: trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/frmCssEdit.resx (from rev 1519, trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/Form1.resx) =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/frmCssEdit.resx (rev 0) +++ trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/frmCssEdit.resx 2014-09-14 00:09:08 UTC (rev 1524) @@ -0,0 +1,120 @@ +<?xml version="1.0" encoding="utf-8"?> +<root> + <!-- + Microsoft ResX Schema + + Version 2.0 + + The primary goals of this format is to allow a simple XML format + that is mostly human readable. The generation and parsing of the + various data types are done through the TypeConverter classes + associated with the data types. + + Example: + + ... ado.net/XML headers & schema ... + <resheader name="resmimetype">text/microsoft-resx</resheader> + <resheader name="version">2.0</resheader> + <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> + <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> + <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> + <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> + <value>[base64 mime encoded serialized .NET Framework object]</value> + </data> + <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> + <comment>This is a comment</comment> + </data> + + There are any number of "resheader" rows that contain simple + name/value pairs. + + Each data row contains a name, and value. The row also contains a + type or mimetype. Type corresponds to a .NET class that support + text/value conversion through the TypeConverter architecture. + Classes that don't support this are serialized and stored with the + mimetype set. + + The mimetype is used for serialized objects, and tells the + ResXResourceReader how to depersist the object. This is currently not + extensible. For a given mimetype the value must be set accordingly: + + Note - application/x-microsoft.net.object.binary.base64 is the format + that the ResXResourceWriter will generate, however the reader can + read any of the formats listed below. + + mimetype: application/x-microsoft.net.object.binary.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.soap.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Soap.SoapFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> + <xsd:element name="root" msdata:IsDataSet="true"> + <xsd:complexType> + <xsd:choice maxOccurs="unbounded"> + <xsd:element name="metadata"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> + </xsd:sequence> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="assembly"> + <xsd:complexType> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="data"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="resheader"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" /> + </xsd:complexType> + </xsd:element> + </xsd:choice> + </xsd:complexType> + </xsd:element> + </xsd:schema> + <resheader name="resmimetype"> + <value>text/microsoft-resx</value> + </resheader> + <resheader name="version"> + <value>2.0</value> + </resheader> + <resheader name="reader"> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name="writer"> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> +</root> \ No newline at end of file Modified: trunk/AgateLib.Tests/Tests.WindowsMetro/TestContainer.xaml.cs =================================================================== --- trunk/AgateLib.Tests/Tests.WindowsMetro/TestContainer.xaml.cs 2014-09-13 23:39:50 UTC (rev 1523) +++ trunk/AgateLib.Tests/Tests.WindowsMetro/TestContainer.xaml.cs 2014-09-14 00:09:08 UTC (rev 1524) @@ -85,7 +85,7 @@ private static void SetAssetPath(IAgateTest t, AssetLocations assets) { var assemblyName = t.GetType().GetTypeInfo().Assembly.GetName().Name; - assets.Path = "ms-appx:///" + assemblyName + "/Assets"; + assets.Path = assemblyName + "/Assets"; } private void btnBack_Click(object sender, RoutedEventArgs e) Modified: trunk/AgateLib.Tests/Tests.WindowsPhone/TestContainer.xaml.cs =================================================================== --- trunk/AgateLib.Tests/Tests.WindowsPhone/TestContainer.xaml.cs 2014-09-13 23:39:50 UTC (rev 1523) +++ trunk/... [truncated message content] |
From: <ka...@us...> - 2014-09-13 23:40:04
|
Revision: 1523 http://sourceforge.net/p/agate/code/1523 Author: kanato Date: 2014-09-13 23:39:50 +0000 (Sat, 13 Sep 2014) Log Message: ----------- Several fixes and additions to user interface components to make them more touch friendly. Added GUI debugger window. Added Gamepad mapper. Modified Paths: -------------- trunk/AgateLib/AgateLib.csproj trunk/AgateLib/ApplicationModels/AgateAppModel.cs trunk/AgateLib/Geometry/Vector2.cs trunk/AgateLib/InputLib/Input.cs trunk/AgateLib/InputLib/Joystick.cs trunk/AgateLib/InputLib/JoystickEventArgs.cs trunk/AgateLib/Properties/AssemblyInfo.cs trunk/AgateLib/Settings/PersistantSettings.cs trunk/AgateLib/UserInterface/Css/CssAdapter.cs trunk/AgateLib/UserInterface/Css/CssStyleData.cs trunk/AgateLib/UserInterface/Css/Documents/CssDocument.cs trunk/AgateLib/UserInterface/Css/Documents/PropertyEnums.cs trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs trunk/AgateLib/UserInterface/Css/Layout/Defaults/MenuDefaultStyle.cs trunk/AgateLib/UserInterface/Css/Parser/CssParser.cs trunk/AgateLib/UserInterface/Css/Rendering/CssRenderer.cs trunk/AgateLib/UserInterface/Css/Rendering/WidgetAnimator.cs trunk/AgateLib/UserInterface/Css/Selectors/WidgetMatchParameters.cs trunk/AgateLib/UserInterface/Widgets/Desktop.cs trunk/AgateLib/UserInterface/Widgets/Gui.cs trunk/AgateLib/UserInterface/Widgets/GuiSound.cs trunk/AgateLib/UserInterface/Widgets/IGuiRenderer.cs trunk/AgateLib/UserInterface/Widgets/InputMap.cs trunk/AgateLib/UserInterface/Widgets/Menu.cs trunk/AgateLib/UserInterface/Widgets/MenuItem.cs trunk/AgateLib/UserInterface/Widgets/Widget.cs trunk/AgateLib/UserInterface/Widgets/WidgetList.cs trunk/AgateLib.AgateSDL/SdlFactory.cs trunk/AgateLib.Platform.WinForms/AgateLib.Platform.WinForms.csproj trunk/AgateLib.Platform.WinForms/ApplicationModels/SerialModel.cs trunk/AgateLib.Platform.WinForms/DisplayImplementation/DesktopGLDisplay.cs trunk/AgateLib.Platform.WinForms/DisplayImplementation/GL_DisplayControl.cs trunk/AgateLib.Platform.WinForms/DisplayImplementation/GL_GameWindow.cs trunk/AgateLib.Platform.WinForms/PlatformImplementation/FormsPlatformInfo.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/Fakes/FakeGuiEngine.cs trunk/AgateLib.Tests/Tests.WinForms/InputTests/Input/InputTester.cs trunk/AgateLib.Tests/Tests.WinForms/InputTests/Input/frmInputTester.cs trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssBindingTest.cs Added Paths: ----------- trunk/AgateLib/InputLib/DirectionPad.cs trunk/AgateLib/InputLib/Gamepad.cs trunk/AgateLib/InputLib/GamepadButtonEventArgs.cs trunk/AgateLib/InputLib/GamepadMap.cs trunk/AgateLib/InputLib/GamepadMapDatabase.cs trunk/AgateLib/InputLib/GamepadStickEventArgs.cs trunk/AgateLib/UserInterface/GestureEffect.cs trunk/AgateLib/UserInterface/GuiStack.cs trunk/AgateLib/UserInterface/Widgets/AxisType.cs trunk/AgateLib/UserInterface/Widgets/Gesture.cs trunk/AgateLib/UserInterface/Widgets/Gestures/ trunk/AgateLib/UserInterface/Widgets/Gestures/IGestureController.cs trunk/AgateLib/UserInterface/Widgets/Gestures/MouseGesture.cs trunk/AgateLib/UserInterface/Widgets/InputMode.cs trunk/AgateLib.Platform.WinForms/GuiDebug/ trunk/AgateLib.Platform.WinForms/GuiDebug/frmGuiDebug.Designer.cs trunk/AgateLib.Platform.WinForms/GuiDebug/frmGuiDebug.cs trunk/AgateLib.Platform.WinForms/GuiDebug/frmGuiDebug.resx Modified: trunk/AgateLib/AgateLib.csproj =================================================================== --- trunk/AgateLib/AgateLib.csproj 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/AgateLib.csproj 2014-09-13 23:39:50 UTC (rev 1523) @@ -38,9 +38,6 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> - <!-- A reference to the entire .NET Framework is automatically included --> - </ItemGroup> - <ItemGroup> <Compile Include="AgateException.cs"> <SubType>Code</SubType> </Compile> @@ -65,6 +62,12 @@ <Compile Include="Drivers\NullDrivers\NullInputFactory.cs" /> <Compile Include="Drivers\NullDrivers\NullSoundFactory.cs" /> <Compile Include="Geometry\CoordinateSystems\SingleFixedDimension.cs" /> + <Compile Include="InputLib\DirectionPad.cs" /> + <Compile Include="InputLib\Gamepad.cs" /> + <Compile Include="InputLib\GamepadButtonEventArgs.cs" /> + <Compile Include="InputLib\GamepadMap.cs" /> + <Compile Include="InputLib\GamepadMapDatabase.cs" /> + <Compile Include="InputLib\GamepadStickEventArgs.cs" /> <Compile Include="Mathematics\MathHelper.cs" /> <Compile Include="Algorithms\PathFinding\IAStarMap.cs" /> <Compile Include="Algorithms\Pair.cs" /> @@ -557,11 +560,17 @@ <Compile Include="UserInterface\Css\Selectors\ICssMediaSelector.cs" /> <Compile Include="UserInterface\Css\Selectors\ICssSelector.cs" /> <Compile Include="UserInterface\Css\Selectors\WidgetMatchParameters.cs" /> + <Compile Include="UserInterface\GestureEffect.cs" /> + <Compile Include="UserInterface\GuiStack.cs" /> <Compile Include="UserInterface\IAudioPlayer.cs" /> <Compile Include="UserInterface\ISurfaceProvider.cs" /> + <Compile Include="UserInterface\Widgets\AxisType.cs" /> <Compile Include="UserInterface\Widgets\Container.cs" /> <Compile Include="UserInterface\Widgets\Desktop.cs" /> <Compile Include="UserInterface\Widgets\Extensions\WidgetExtensions.cs" /> + <Compile Include="UserInterface\Widgets\Gesture.cs" /> + <Compile Include="UserInterface\Widgets\Gestures\IGestureController.cs" /> + <Compile Include="UserInterface\Widgets\Gestures\MouseGesture.cs" /> <Compile Include="UserInterface\Widgets\Gui.cs" /> <Compile Include="UserInterface\Widgets\GuiInput.cs" /> <Compile Include="UserInterface\Widgets\GuiSound.cs" /> @@ -570,6 +579,7 @@ <Compile Include="UserInterface\Widgets\IGuiRenderer.cs" /> <Compile Include="UserInterface\Widgets\ImageBox.cs" /> <Compile Include="UserInterface\Widgets\InputMap.cs" /> + <Compile Include="UserInterface\Widgets\InputMode.cs" /> <Compile Include="UserInterface\Widgets\ITextAlignment.cs" /> <Compile Include="UserInterface\Widgets\KeyboardEventArgs.cs" /> <Compile Include="UserInterface\Widgets\Label.cs" /> Modified: trunk/AgateLib/ApplicationModels/AgateAppModel.cs =================================================================== --- trunk/AgateLib/ApplicationModels/AgateAppModel.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/ApplicationModels/AgateAppModel.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -337,6 +337,8 @@ /// </summary> public virtual void KeepAlive() { + Input.PollJoysticks(); + Input.DispatchQueuedEvents(); } } Modified: trunk/AgateLib/Geometry/Vector2.cs =================================================================== --- trunk/AgateLib/Geometry/Vector2.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/Geometry/Vector2.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -52,6 +52,16 @@ mY = (float)y; } /// <summary> + /// Constructs a Vector2 object from a Point. + /// </summary> + /// <param name="pt"></param> + public Vector2(Point pt) + { + mX = pt.X; + mY = pt.Y; + } + + /// <summary> /// X coordinate. /// </summary> public float X @@ -184,6 +194,26 @@ return new Vector2(a.X * b, a.Y * b); } /// <summary> + /// Scales a vector by a scalar floating point value. + /// </summary> + /// <param name="a"></param> + /// <param name="b"></param> + /// <returns></returns> + public static Vector2 operator *(Vector2 a, double b) + { + return new Vector2(a.X * b, a.Y * b); + } + /// <summary> + /// Scales a vector by a scalar floating point value. + /// </summary> + /// <param name="a"></param> + /// <param name="b"></param> + /// <returns></returns> + public static Vector2 operator *(double b, Vector2 a) + { + return new Vector2(a.X * b, a.Y * b); + } + /// <summary> /// Divides a vector's components by a floating point value. /// </summary> /// <param name="a"></param> @@ -195,6 +225,17 @@ } /// <summary> + /// Divides a vector's components by a floating point value. + /// </summary> + /// <param name="a"></param> + /// <param name="b"></param> + /// <returns></returns> + public static Vector2 operator /(Vector2 a, double b) + { + return a * (float)(1.0f / b); + } + + /// <summary> /// Computes and returns the dot product with another vector. /// </summary> /// <param name="b"></param> Added: trunk/AgateLib/InputLib/DirectionPad.cs =================================================================== --- trunk/AgateLib/InputLib/DirectionPad.cs (rev 0) +++ trunk/AgateLib/InputLib/DirectionPad.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.InputLib +{ + public class DirectionPad + { + public bool Up { get; internal set; } + public bool Down { get; internal set; } + public bool Left { get; internal set; } + public bool Right { get; internal set; } + + internal void OnChanged(Gamepad gamepad) + { + if (Changed != null) + Changed(gamepad, EventArgs.Empty); + } + + public event EventHandler Changed; + } +} Added: trunk/AgateLib/InputLib/Gamepad.cs =================================================================== --- trunk/AgateLib/InputLib/Gamepad.cs (rev 0) +++ trunk/AgateLib/InputLib/Gamepad.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -0,0 +1,260 @@ +using AgateLib.Geometry; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.InputLib +{ + public class Gamepad : IDisposable + { + static List<HatState> mHatUpStates = new List<HatState>(); + static List<HatState> mHatLeftStates = new List<HatState>(); + static List<HatState> mHatRightStates = new List<HatState>(); + static List<HatState> mHatDownStates = new List<HatState>(); + + static Gamepad() + { + mHatUpStates.AddRange(new[] { HatState.Up, HatState.UpLeft, HatState.UpRight }); + mHatLeftStates.AddRange(new[] { HatState.Left, HatState.UpLeft, HatState.DownLeft }); + mHatRightStates.AddRange(new[] { HatState.Right, HatState.UpRight, HatState.DownRight }); + mHatDownStates.AddRange(new[] { HatState.Down, HatState.DownLeft, HatState.DownRight }); + } + + Joystick mJoystick; + GamepadMap mMap; + Dictionary<GamepadButton, bool> mButtonState = new Dictionary<GamepadButton, bool>(); + Vector2 mLeftStick; + Vector2 mRightStick; + float mLeftTrigger, mRightTrigger; + + public Gamepad(Joystick joystick) + : this(joystick, GamepadMapDatabase.FindMap(joystick.Guid)) + { + } + + private Gamepad(Joystick joystick, GamepadMap map) + { + mMap = map; + + mJoystick = joystick; + + mJoystick.AxisChanged += joystick_AxisChanged; + mJoystick.ButtonPressed += joystick_ButtonPressed; + mJoystick.ButtonReleased += joystick_ButtonReleased; + mJoystick.HatStateChanged += joystick_HatStateChanged; + } + + /// <summary> + /// Disconnects the Gamepad instance from the hardware joystick. + /// </summary> + public void Dispose() + { + mJoystick.AxisChanged -= joystick_AxisChanged; + mJoystick.ButtonPressed -= joystick_ButtonPressed; + mJoystick.ButtonReleased -= joystick_ButtonReleased; + mJoystick.HatStateChanged -= joystick_HatStateChanged; + } + + + public DirectionPad DPad { get; private set; } + public Vector2 LeftStick { get { return mLeftStick; } } + public Vector2 RightStick { get { return mRightStick; } } + public float LeftTrigger { get { return mLeftTrigger; } } + public float RightTrigger { get { return mRightTrigger; } } + public Dictionary<GamepadButton, bool> Buttons { get { return mButtonState; } } + + void joystick_HatStateChanged(object sender, JoystickEventArgs e) + { + var hat = mJoystick.HatState[e.Index]; + + DPad.Up = mHatUpStates.Contains(hat); + DPad.Left = mHatLeftStates.Contains(hat); + DPad.Right = mHatRightStates.Contains(hat); + DPad.Down = mHatDownStates.Contains(hat); + + DPad.OnChanged(this); + } + + void joystick_AxisChanged(object sender, JoystickEventArgs e) + { + var target = mMap.AxisMap[e.Index]; + + if (target == GamepadMapTarget.None) + return; + + var value = (float)mJoystick.GetAxisValue(e.Index); + + SetValue(target, value); + } + + void joystick_ButtonReleased(object sender, JoystickEventArgs e) + { + MapButton(e.Index, 0); + } + void joystick_ButtonPressed(object sender, JoystickEventArgs e) + { + MapButton(e.Index, 1); + } + + private void MapButton(int joystickButtonIndex, int value) + { + var target = mMap.ButtonMap[joystickButtonIndex]; + + if (target == GamepadMapTarget.None) + return; + + SetValue(target, 0); + } + + private void SetValue(GamepadMapTarget target, float value) + { + switch (target) + { + case GamepadMapTarget.LeftX: + case GamepadMapTarget.LeftY: + case GamepadMapTarget.RightX: + case GamepadMapTarget.RightY: + case GamepadMapTarget.LeftTrigger: + case GamepadMapTarget.RightTrigger: + SetAxisValue(target, value); + break; + + case GamepadMapTarget.A: + case GamepadMapTarget.B: + case GamepadMapTarget.X: + case GamepadMapTarget.Y: + case GamepadMapTarget.LeftBumper: + case GamepadMapTarget.RightBumper: + case GamepadMapTarget.Select: + case GamepadMapTarget.Start: + case GamepadMapTarget.LeftStickButton: + case GamepadMapTarget.RightStickButton: + case GamepadMapTarget.DPadUp: + case GamepadMapTarget.DPadRight: + case GamepadMapTarget.DPadLeft: + case GamepadMapTarget.DPadDown: + SetButtonValue(target, value); + break; + + default: + throw new NotImplementedException(); + } + } + + void SetAxisValue(GamepadMapTarget target, float value) + { + var val = (float)value; + + switch (target) + { + case GamepadMapTarget.LeftX: mLeftStick.X = val; OnLeftStickMoved(); break; + case GamepadMapTarget.LeftY: mLeftStick.Y = val; OnLeftStickMoved(); break; + case GamepadMapTarget.RightX: mRightStick.X = val; OnRightStickMoved(); break; + case GamepadMapTarget.RightY: mRightStick.Y = val; OnRightStickMoved(); break; + case GamepadMapTarget.LeftTrigger: mLeftTrigger = val; OnLeftTriggerMoved(); break; + case GamepadMapTarget.RightTrigger: mRightTrigger = val; OnRightTriggerMoved(); break; + + default: + throw new NotImplementedException(); + } + } + + + void SetButtonValue(GamepadMapTarget target, float value) + { + if (value > 0.5) + SetButtonValue(target, true); + else + SetButtonValue(target, false); + } + + void SetButtonValue(GamepadMapTarget target, bool value) + { + GamepadButton mappedTarget; + + switch (target) + { + case GamepadMapTarget.A: mappedTarget = GamepadButton.A; break; + case GamepadMapTarget.B: mappedTarget = GamepadButton.B; break; + case GamepadMapTarget.X: mappedTarget = GamepadButton.X; break; + case GamepadMapTarget.Y: mappedTarget = GamepadButton.Y; break; + case GamepadMapTarget.LeftBumper: mappedTarget = GamepadButton.LeftBumper; break; + case GamepadMapTarget.RightBumper: mappedTarget = GamepadButton.RightBumper; break; + case GamepadMapTarget.Select: mappedTarget = GamepadButton.Select; break; + case GamepadMapTarget.Start: mappedTarget = GamepadButton.Start; break; + case GamepadMapTarget.LeftStickButton: mappedTarget = GamepadButton.LeftStickButton; break; + case GamepadMapTarget.RightStickButton: mappedTarget = GamepadButton.RightStickButton; break; + case GamepadMapTarget.Home: mappedTarget = GamepadButton.Home; break; + + case GamepadMapTarget.DPadUp: DPad.Up = value; DPad.OnChanged(this); return; + case GamepadMapTarget.DPadRight: DPad.Right = value; DPad.OnChanged(this); return; + case GamepadMapTarget.DPadLeft: DPad.Left = value; DPad.OnChanged(this); return; + case GamepadMapTarget.DPadDown: DPad.Down = value; DPad.OnChanged(this); return; + + default: + throw new NotImplementedException(); + } + + mButtonState[mappedTarget] = value; + + if (value) + OnButtonPressed(mappedTarget); + else + OnButtonReleased(mappedTarget); + } + + + private void OnLeftStickMoved() + { + if (LeftStickMoved != null) + LeftStickMoved(this, EventArgs.Empty); + } + private void OnRightStickMoved() + { + if (RightStickMoved != null) + RightStickMoved(this, EventArgs.Empty); + } + private void OnLeftTriggerMoved() + { + } + private void OnRightTriggerMoved() + { + } + + private void OnButtonPressed(GamepadButton mappedTarget) + { + if (ButtonPressed != null) + ButtonPressed(this, new GamepadButtonEventArgs(mappedTarget)); + } + private void OnButtonReleased(GamepadButton mappedTarget) + { + if (ButtonReleased != null) + ButtonReleased(this, new GamepadButtonEventArgs(mappedTarget)); + } + + public event EventHandler LeftStickMoved; + public event EventHandler RightStickMoved; + + public event EventHandler<GamepadButtonEventArgs> ButtonPressed; + public event EventHandler<GamepadButtonEventArgs> ButtonReleased; + + } + + + public enum GamepadButton + { + A, + B, + X, + Y, + LeftBumper, + RightBumper, + Select, + Start, + LeftStickButton, + RightStickButton, + Home + } +} Added: trunk/AgateLib/InputLib/GamepadButtonEventArgs.cs =================================================================== --- trunk/AgateLib/InputLib/GamepadButtonEventArgs.cs (rev 0) +++ trunk/AgateLib/InputLib/GamepadButtonEventArgs.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.InputLib +{ + public class GamepadButtonEventArgs : EventArgs + { + private GamepadButton mappedTarget; + + public GamepadButtonEventArgs(GamepadButton mappedTarget) + { + // TODO: Complete member initialization + this.mappedTarget = mappedTarget; + } + } +} Added: trunk/AgateLib/InputLib/GamepadMap.cs =================================================================== --- trunk/AgateLib/InputLib/GamepadMap.cs (rev 0) +++ trunk/AgateLib/InputLib/GamepadMap.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.InputLib +{ + public class GamepadMap + { + public GamepadMap() + { + AxisMap = new GamepadMapTarget[6]; + ButtonMap = new GamepadMapTarget[16]; + + InitializeMapTarget(AxisMap); + InitializeMapTarget(ButtonMap); + + InitializeXboxControllerMap(); + } + + private void InitializeXboxControllerMap() + { + ButtonMap[0] = GamepadMapTarget.DPadUp; + ButtonMap[1] = GamepadMapTarget.DPadDown; + ButtonMap[2] = GamepadMapTarget.DPadLeft; + ButtonMap[3] = GamepadMapTarget.DPadRight; + ButtonMap[4] = GamepadMapTarget.Start; + ButtonMap[5] = GamepadMapTarget.Select; + ButtonMap[6] = GamepadMapTarget.LeftStickButton; + ButtonMap[7] = GamepadMapTarget.RightStickButton; + ButtonMap[8] = GamepadMapTarget.LeftBumper; + ButtonMap[9] = GamepadMapTarget.RightBumper; + ButtonMap[10] = GamepadMapTarget.A; + ButtonMap[11] = GamepadMapTarget.B; + ButtonMap[12] = GamepadMapTarget.X; + ButtonMap[13] = GamepadMapTarget.Y; + ButtonMap[14] = GamepadMapTarget.Home; + } + + private void InitializeMapTarget(GamepadMapTarget[] map) + { + for (int i = 0; i < map.Length; i++) + map[i] = (GamepadMapTarget)i; + } + + public GamepadMapTarget[] AxisMap { get; set; } + public GamepadMapTarget[] ButtonMap { get; set; } + } + + + public enum GamepadMapTarget + { + None = -1, + LeftX, + LeftY, + RightX, + RightY, + LeftTrigger, + RightTrigger, + A, + B, + X, + Y, + LeftBumper, + RightBumper, + Select, + Start, + LeftStickButton, + RightStickButton, + DPadUp, + DPadDown, + DPadLeft, + DPadRight, + Home, + } + +} Added: trunk/AgateLib/InputLib/GamepadMapDatabase.cs =================================================================== --- trunk/AgateLib/InputLib/GamepadMapDatabase.cs (rev 0) +++ trunk/AgateLib/InputLib/GamepadMapDatabase.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.InputLib +{ + public static class GamepadMapDatabase + { + static Dictionary<Guid, string> mMapStrings = new Dictionary<Guid, string>(); + + /// <summary> + /// Finds the mapping from the joystick inputs to the gamepad inputs. + /// Returns a default GamepadMap object if nothing is found. + /// </summary> + /// <param name="guid"></param> + /// <returns></returns> + public static GamepadMap FindMap(Guid guid) + { + return new GamepadMap(); + } + } +} Added: trunk/AgateLib/InputLib/GamepadStickEventArgs.cs =================================================================== --- trunk/AgateLib/InputLib/GamepadStickEventArgs.cs (rev 0) +++ trunk/AgateLib/InputLib/GamepadStickEventArgs.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.InputLib +{ + public class GamepadStickEventArgs : EventArgs + { + } +} Modified: trunk/AgateLib/InputLib/Input.cs =================================================================== --- trunk/AgateLib/InputLib/Input.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/InputLib/Input.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -61,5 +61,10 @@ } public static InputHandlerList InputHandlers { get { return mInputHandlers; } } + + internal static void PollJoysticks() + { + JoystickInput.PollTimer(); + } } } Modified: trunk/AgateLib/InputLib/Joystick.cs =================================================================== --- trunk/AgateLib/InputLib/Joystick.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/InputLib/Joystick.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -33,6 +33,7 @@ JoystickImpl impl; bool[] mButtonState; HatState[] mHatState; + double[] mAxisState; internal Joystick(JoystickImpl i) { @@ -42,7 +43,7 @@ mButtonState = new bool[ButtonCount]; mHatState = new HatState[HatCount]; - + mAxisState = new double[AxisCount]; } /// <summary> @@ -222,17 +223,33 @@ OnHatStateChanged(i); } } + + for (int i = 0; i < mAxisState.Length; i++) + { + double newValue = GetAxisValue(i); + + if (Math.Abs(newValue - mAxisState[i]) > 0.001) + { + mAxisState[i] = newValue; + OnAxisChanged(i); + } + } } - + public event JoystickEventHandler AxisChanged; public event JoystickEventHandler ButtonPressed; public event JoystickEventHandler ButtonReleased; public event JoystickEventHandler HatStateChanged; + private void OnAxisChanged(int axisIndex) + { + if (AxisChanged != null) + AxisChanged(this, new JoystickEventArgs(JoystickEventType.Axis, axisIndex)); + } private void OnButtonPressed(int index) { if (ButtonPressed != null) - ButtonPressed(this, + ButtonPressed(this, new JoystickEventArgs(JoystickEventType.Button, index)); } private void OnButtonReleased(int index) Modified: trunk/AgateLib/InputLib/JoystickEventArgs.cs =================================================================== --- trunk/AgateLib/InputLib/JoystickEventArgs.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/InputLib/JoystickEventArgs.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -25,6 +25,7 @@ { public enum JoystickEventType { + Axis, Button, Hat, } Modified: trunk/AgateLib/Properties/AssemblyInfo.cs =================================================================== --- trunk/AgateLib/Properties/AssemblyInfo.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/Properties/AssemblyInfo.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -34,6 +34,7 @@ [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: InternalsVisibleTo("AgateLib.UnitTests")] +[assembly: InternalsVisibleTo("AgateLib.Platform.WinForms")] [assembly: CLSCompliant(true)] Modified: trunk/AgateLib/Settings/PersistantSettings.cs =================================================================== --- trunk/AgateLib/Settings/PersistantSettings.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/Settings/PersistantSettings.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -167,6 +167,9 @@ try { + if (FileSystem.File.Exists(SettingsFilename) == false) + return; + doc = XDocument.Load(XmlReader.Create(FileSystem.File.OpenRead(SettingsFilename))); } catch (FileNotFoundException) Modified: trunk/AgateLib/UserInterface/Css/CssAdapter.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/CssAdapter.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/UserInterface/Css/CssAdapter.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -97,7 +97,10 @@ if (refresh) { - RebuildStyle(control); + lock (Document) + { + RebuildStyle(control); + } } var style = mObjectStyles[control]; Modified: trunk/AgateLib/UserInterface/Css/CssStyleData.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/CssStyleData.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/UserInterface/Css/CssStyleData.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -49,13 +49,16 @@ Text = new CssText(); Display = CssDisplay.Initial; + Overflow = CssOverflow.Visible; } + public CssDisplay Display { get; set; } + public CssOverflow Overflow { get; set; } + public CssPosition Position { get; set; } + [CssPromoteProperties] public CssRectangle PositionData { get; set; } - public CssPosition Position { get; set; } - [CssPromoteProperties] public CssFont Font { get; set; } @@ -74,12 +77,11 @@ [CssPromoteProperties] public CssLayout Layout { get; set; } - public CssDisplay Display { get; set; } - [CssPromoteProperties(prefix: "transition")] public CssTransition Transition { get; set; } [CssPromoteProperties] public CssText Text { get; set; } + } } Modified: trunk/AgateLib/UserInterface/Css/Documents/CssDocument.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Documents/CssDocument.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/UserInterface/Css/Documents/CssDocument.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -46,17 +46,23 @@ public void Clear() { - mMedia.Clear(); + lock (this) + { + mMedia.Clear(); - var defaultMedium = new CssMediaSelector("all"); - Media.Add(defaultMedium); + var defaultMedium = new CssMediaSelector("all"); + Media.Add(defaultMedium); + } } public void Load(string filename) { CssParser parser = new CssParser(); - parser.Load(this, filename); + lock (this) + { + parser.Load(this, filename); + } OnUpdated(); } @@ -64,7 +70,10 @@ { CssParser parser = new CssParser(); - parser.ParseCss(this, css); + lock (this) + { + parser.ParseCss(this, css); + } OnUpdated(); } Modified: trunk/AgateLib/UserInterface/Css/Documents/PropertyEnums.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Documents/PropertyEnums.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/UserInterface/Css/Documents/PropertyEnums.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -113,4 +113,14 @@ Right, Center, } + + public enum CssOverflow + { + Visible, + Initial = Visible, + Hidden, + Scroll, + Auto, + Inherit, + } } Modified: trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -128,6 +128,7 @@ } } + public CssAdapter Adapter { get { return mAdapter; } } private void RedoLayout(Container container, bool forceRefresh = false) { Modified: trunk/AgateLib/UserInterface/Css/Layout/Defaults/MenuDefaultStyle.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Layout/Defaults/MenuDefaultStyle.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/UserInterface/Css/Layout/Defaults/MenuDefaultStyle.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -30,6 +30,7 @@ public override void SetDefaultStyle(CssStyle style) { style.Data.Layout.Kind = CssLayoutKind.Column; + style.Data.Overflow = CssOverflow.Hidden; } } Modified: trunk/AgateLib/UserInterface/Css/Parser/CssParser.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Parser/CssParser.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/UserInterface/Css/Parser/CssParser.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -142,7 +142,14 @@ if (mBindingMapper.FindPropertyChain(property)) { - currentBlock.AddProperty(name, value); + try + { + currentBlock.AddProperty(name, value); + } + catch(Exception) + { + Log.WriteLine(string.Format("Failed to parse property {0}.", property)); + } } else { Modified: trunk/AgateLib/UserInterface/Css/Rendering/CssRenderer.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Rendering/CssRenderer.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/UserInterface/Css/Rendering/CssRenderer.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -37,6 +37,7 @@ ICssImageProvider mImageProvider = new CssDefaultImageProvider(); private CssAdapter adapter; + public CssRenderer(CssAdapter adapter) { mAdapter = adapter; @@ -47,12 +48,17 @@ mBlankSurface = new Surface(buffer); } + public Gesture ActiveGesture { get; set; } + public void Update(Gui gui, double deltaTime) { foreach (var widget in gui.Desktop.Descendants) { var style = mAdapter.GetStyle(widget); + if (ActiveGesture != null) + style.Animator.Gesture = ActiveGesture.TargetWidget == widget ? ActiveGesture : null; + style.Animator.Update(deltaTime); widget.OnUpdate(deltaTime); @@ -77,15 +83,39 @@ DrawComponentContents(window); } + private bool PushClipRect(CssStyle style) + { + Rectangle clipRect = style.Widget.ClientToScreen(new Rectangle(0, 0, style.Widget.ClientRect.Width, style.Widget.ClientRect.Height)); + + if (style.Data.Overflow == CssOverflow.Visible) + return false; + + Display.PushClipRect(clipRect); + return true; + } + private void DrawComponentContents(Container window) { - foreach (var control in window.Children) + var style = mAdapter.GetStyle(window); + bool clipping = false; + + try { - if (control is Container) - DrawComponent((Container)control); - else - DrawComponentStyle(control); + clipping = PushClipRect(style); + + foreach (var control in window.Children) + { + if (control is Container) + DrawComponent((Container)control); + else + DrawComponentStyle(control); + } } + finally + { + if (clipping) + Display.PopClipRect(); + } } private void DrawComponentStyle(Widget control) @@ -113,7 +143,7 @@ private OriginAlignment ConvertTextAlign(CssTextAlign cssTextAlign) { - switch(cssTextAlign) + switch (cssTextAlign) { case CssTextAlign.Right: return OriginAlignment.TopRight; @@ -391,5 +421,6 @@ mBlankSurface.Color = border.Right.Color; mBlankSurface.Draw(rect); } + } } Modified: trunk/AgateLib/UserInterface/Css/Rendering/WidgetAnimator.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Rendering/WidgetAnimator.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/UserInterface/Css/Rendering/WidgetAnimator.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -101,8 +101,46 @@ { Transition.Update(deltaTime); } + + if (Gesture != null) + { + AnimateForGesture(); + } } + private void AnimateForGesture() + { + switch (Gesture.GestureType) + { + case GestureType.Drag: + case GestureType.Swipe: + case GestureType.LongPressDrag: + AnimateDrag(); + break; + } + + } + + private void AnimateDrag() + { + if (Gesture.IsValidForTarget == false) + return; + + Vector2 delta = new Vector2(Gesture.CurrentPoint); + delta -= new Vector2(Gesture.StartPoint); + + if (Gesture.Axis == AxisType.Horizontal) + delta.Y = 0; + else if (Gesture.Axis == AxisType.Vertical) + delta.X = 0; + + mStyle.Widget.ClientRect = new Rectangle( + mClientRect.X + (int)delta.X, + mClientRect.Y + (int)delta.Y, + mClientRect.Width, + mClientRect.Height); + } + public Container ParentCoordinateSystem { get { return mStyle.Widget.ParentCoordinateSystem; } } public override string ToString() @@ -111,5 +149,7 @@ } public bool IncludeInLayout { get; set; } + + public Gesture Gesture { get; set; } } } Modified: trunk/AgateLib/UserInterface/Css/Selectors/WidgetMatchParameters.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Selectors/WidgetMatchParameters.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/UserInterface/Css/Selectors/WidgetMatchParameters.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -50,6 +50,13 @@ { if (InActiveWindow(control)) { + if (control is MenuItem) + { + MenuItem mnuit = (MenuItem)control; + + if (mnuit.Selected) + return CssPseudoClass.Selected; + } if (control.MouseIn) return CssPseudoClass.Hover; if (control is Container) @@ -59,13 +66,6 @@ if (container.ChildHasMouseIn()) return CssPseudoClass.Hover; } - if (control is MenuItem) - { - MenuItem mnuit = (MenuItem)control; - - if (mnuit.Selected) - return CssPseudoClass.Selected; - } } return CssPseudoClass.None; @@ -119,5 +119,29 @@ public CssPseudoClass PseudoClass { get; private set; } public IEnumerable<string> Classes { get; private set; } + public override string ToString() + { + StringBuilder b = new StringBuilder(); + + b.Append("Match Params: "); + b.Append(mTypeNames[0]); + + var classes = GetCssClasses(mWidget); + + if (classes != null && classes.Count() > 0) + { + b.Append("."); + b.Append(string.Join(".", classes)); + } + + var pc = GetPseudoClass(mWidget); + if (pc != CssPseudoClass.None) + { + b.Append(":"); + b.Append(pc.ToString()); + } + + return b.ToString(); + } } } Added: trunk/AgateLib/UserInterface/GestureEffect.cs =================================================================== --- trunk/AgateLib/UserInterface/GestureEffect.cs (rev 0) +++ trunk/AgateLib/UserInterface/GestureEffect.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.UserInterface +{ + public enum GestureEffect + { + None, + ScrollOverflow, + MoveItem, + DiscardItem, + } +} Added: trunk/AgateLib/UserInterface/GuiStack.cs =================================================================== --- trunk/AgateLib/UserInterface/GuiStack.cs (rev 0) +++ trunk/AgateLib/UserInterface/GuiStack.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -0,0 +1,34 @@ +using AgateLib.InputLib; +using AgateLib.UserInterface.Widgets; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.UserInterface +{ + public static class GuiStack + { + static List<Gui> mStack = new List<Gui>(); + + internal static void Add(Gui gui) + { + mStack.Add(gui); + } + internal static bool Remove(Gui gui) + { + return mStack.Remove(gui); + } + + public static IEnumerable<Gui> Items { get { return mStack; } } + + internal static void ListenEvent(object sender, AgateInputEventArgs args) + { + if (GuiEvent != null) + GuiEvent(sender, args); + } + + public static event EventHandler<AgateInputEventArgs> GuiEvent; + } +} Added: trunk/AgateLib/UserInterface/Widgets/AxisType.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/AxisType.cs (rev 0) +++ trunk/AgateLib/UserInterface/Widgets/AxisType.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AgateLib.UserInterface.Widgets +{ + public enum AxisType + { + Unknown, + Vertical, + Horizontal + } +} Modified: trunk/AgateLib/UserInterface/Widgets/Desktop.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Desktop.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/UserInterface/Widgets/Desktop.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -27,19 +27,67 @@ public class Desktop : Container { private Gui gui; + Widget mFocusWidget; + class WindowList : WidgetList + { + public WindowList(Desktop owner) + : base(owner) + { } + + protected override void ValidateItem(Widget item) + { + if (item is Window == false) + throw new InvalidOperationException(); + } + } + internal Desktop(Gui gui) { this.gui = gui; + + Children = new WindowList(this); + Children.WidgetAdded += Children_WidgetAdded; + Children.WidgetRemoved += Children_WidgetRemoved; } - + + + void Children_WidgetAdded(object sender, WidgetEventArgs e) + { + UpdateFocusWidget(); + } + void Children_WidgetRemoved(object sender, WidgetEventArgs e) + { + UpdateFocusWidget(); + } + + internal void UpdateFocusWidget() + { + foreach (var window in Windows.Reverse()) + { + mFocusWidget = window.FindFocusWidget(); + + if (mFocusWidget != null) + return; + } + } + + public Widget FocusWidget + { + get { return mFocusWidget; } + set { mFocusWidget = value; } + } public Window TopWindow { - get { return (Window)Children[Children.Count - 1]; } + get + { + if (Children.Count == 0) + return null; return (Window)Children[Children.Count - 1]; + } } public IEnumerable<Window> Windows { get { return Children.OfType<Window>(); } } - protected override Gui MyGui { get { return gui; } } + protected internal override Gui MyGui { get { return gui; } } } } Added: trunk/AgateLib/UserInterface/Widgets/Gesture.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Gesture.cs (rev 0) +++ trunk/AgateLib/UserInterface/Widgets/Gesture.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -0,0 +1,82 @@ +using AgateLib.Geometry; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.UserInterface.Widgets +{ + public class Gesture + { + public GestureType GestureType { get; internal set; } + + public Point StartPoint { get; set; } + public Point CurrentPoint { get; set; } + + public double StartTime { get; set; } + public double CurrentTime { get; set; } + public Widget FocusWidget { get; set; } + + /// <summary> + /// + /// </summary> + public AxisType Axis { get; set; } + /// <summary> + /// A value set by the focus widget to indicate to the rendering engine which widget is actually affected. + /// </summary> + public Widget TargetWidget { get; set; } + + /// <summary> + /// A value set by the focus widget to indicate whether this gesture is valid for the target widget. If it is not + /// valid, the target widget will not be drawn as cooperating with the motion. + /// </summary> + public bool IsValidForTarget { get; set; } + + internal void Initialize(GestureType gestureType, Point startPoint, Widget gestureWidget) + { + this.GestureType = gestureType; + this.StartPoint = startPoint; + this.FocusWidget = this.TargetWidget = gestureWidget; + this.Axis = AxisType.Unknown; + this.StartTime = Core.GetTime(); + + IsValidForTarget = false; + } + + public Vector2 Velocity + { + get + { + Vector2 delta = AmountDragged; + + delta /= CurrentTime - StartTime; + delta *= 1000; + + return delta; + } + } + + public GestureEffect Effect { get; set; } + + public Vector2 AmountDragged { get { return new Vector2(CurrentPoint.X, CurrentPoint.Y) - new Vector2(StartPoint.X, StartPoint.Y); } } + } + + + public enum GestureType + { + None, + + Touch, + LongPress, + /// <summary> + /// Gesture where an object is touched and then immediately the finger moves. + /// </summary> + Swipe, + /// <summary> + /// Gesture where an object is moved after it has been touched and held. + /// </summary> + Drag, + LongPressDrag, + } +} Added: trunk/AgateLib/UserInterface/Widgets/Gestures/IGestureController.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Gestures/IGestureController.cs (rev 0) +++ trunk/AgateLib/UserInterface/Widgets/Gestures/IGestureController.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.UserInterface.Widgets.Gestures +{ + interface IGestureController + { + Gesture GestureData { get; set; } + + void Update(); + + + void OnBegin(); + + void OnComplete(); + + void OnTimePass(); + } +} Added: trunk/AgateLib/UserInterface/Widgets/Gestures/MouseGesture.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Gestures/MouseGesture.cs (rev 0) +++ trunk/AgateLib/UserInterface/Widgets/Gestures/MouseGesture.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -0,0 +1,74 @@ +using AgateLib.Geometry; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.UserInterface.Widgets.Gestures +{ + class MouseGesture : IGestureController + { + public Gesture GestureData { get; set; } + + public void Update() + { + if (GestureData.GestureType == GestureType.Touch || GestureData.GestureType == GestureType.LongPress) + { + var delta = GestureData.CurrentPoint; + delta.X -= GestureData.StartPoint.X; + delta.Y -= GestureData.StartPoint.Y; + + if (Math.Abs(delta.X) + Math.Abs(delta.Y) > 8) + { + if (GestureData.GestureType == GestureType.Touch) + GestureData.GestureType = GestureType.Drag; + else + GestureData.GestureType = GestureType.LongPressDrag; + } + + if (GestureData.FocusWidget.AnyDirectionGestures == false) + { + if (delta.X > delta.Y) + GestureData.Axis = AxisType.Horizontal; + else + GestureData.Axis = AxisType.Vertical; + } + + GestureData.FocusWidget.OnGestureChange(GestureData); + } + } + + public void OnBegin() + { + GestureData.FocusWidget.OnGestureBegin(GestureData); + } + + public void OnComplete() + { + GestureData.CurrentTime = Core.GetTime(); + + if (GestureData.GestureType == GestureType.Drag && GestureData.Velocity.Magnitude > 1000) + GestureData.GestureType = GestureType.Swipe; + + GestureData.FocusWidget.OnGestureComplete(GestureData); + } + + public void OnTimePass() + { + if (GestureData.GestureType == GestureType.None) + return; + + if (GestureData.GestureType == GestureType.Touch) + { + double delta = Core.GetTime() - GestureData.StartTime; + + if (delta > 1000) + { + GestureData.GestureType = GestureType.LongPress; + GestureData.FocusWidget.OnGestureChange(GestureData); + } + } + } + } +} Modified: trunk/AgateLib/UserInterface/Widgets/Gui.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Gui.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/UserInterface/Widgets/Gui.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -25,32 +25,60 @@ using AgateLib.InputLib; using AgateLib.Geometry; using AgateLib.InputLib.Legacy; +using AgateLib.UserInterface.Css.Documents; +using AgateLib.UserInterface.Widgets.Gestures; namespace AgateLib.UserInterface.Widgets { - public class Gui : IInputHandler + public class Gui : IInputHandler, IDisposable { Desktop mDesktop; IAudioPlayer mAudioPlayer; IGuiRenderer mRenderer; IGuiLayoutEngine mLayout; - Widget mFocusWidget; Widget mHoverWidget; Widget mMouseEventWidget; + Gamepad mGamepad; + Gesture mCurrentGesture = new Gesture(); + IGestureController mGestureController; + + public Gui(IGuiRenderer renderer, IGuiLayoutEngine layout) { mRenderer = renderer; mLayout = layout; mDesktop = new Desktop(this); - InputMap = InputMap.CreateDefaultMapping(); + InputMap = InputMap.CreateDefaultInputMap(); ForwardUnhandledEvents = true; + + GuiStack.Add(this); + + if (JoystickInput.Joysticks.Count > 0) + { + CreateGamepad(); + } } + private void CreateGamepad() + { + mGamepad = new Gamepad(JoystickInput.Joysticks.First()); + + mGamepad.LeftStickMoved += mGamepad_LeftStickMoved; + mGamepad.ButtonPressed += mGamepad_ButtonPressed; + mGamepad.ButtonReleased += mGamepad_ButtonReleased; + } + public InputMap InputMap { get; set; } + + public void Dispose() + { + GuiStack.Remove(this); + } + public Desktop Desktop { get { return mDesktop; } } void DispatchEvent(Func<Window, bool> action) @@ -66,31 +94,19 @@ } } - public Widget FocusWidget { - get { return mFocusWidget; } - set { mFocusWidget = value; } + get { return Desktop.FocusWidget; } + set { Desktop.FocusWidget = value; } } - private void FindFocusWidget() + private Widget WidgetAt(Point screenPoint) { - foreach (var window in mDesktop.Windows.Reverse()) - { - mFocusWidget = window.FindFocusWidget(); - - if (mFocusWidget != null) - return; - } + return WidgetAt(Desktop, screenPoint); } - - private Widget WidgetAt(Point point) - { - return WidgetAt(Desktop, point); - } private Widget WidgetAt(Container container, Point point) { - foreach (var child in container.Children) + foreach (var child in container.Children.Reverse()) { if (child.WidgetRect.Contains(point)) { @@ -105,7 +121,16 @@ return container; } + private bool WidgetContainsScreenPoint(Widget widget, Point screenPoint) + { + if (widget is Desktop) + return true; + if (widget.Parent == null) + return false; + return widget.WidgetRect.Contains(widget.Parent.ScreenToClient(screenPoint)); + } + #region --- Event Handling --- public bool ForwardUnhandledEvents { get; set; } @@ -127,15 +152,23 @@ bool handled = false; GuiInput input = InputMap.MapKey(args.KeyCode); - if (mFocusWidget == null) - FindFocusWidget(); + Widget.PreferredInputMode = InputMode.Controller; - if (mFocusWidget != null) + if (Desktop.Descendants.Contains(FocusWidget) == false) + Desktop.UpdateFocusWidget(); + + if (FocusWidget == null) + Desktop.UpdateFocusWidget(); + + if (FocusWidget != null) { - mFocusWidget.OnKeyDown(args.KeyCode, args.KeyString); + GuiStack.ListenEvent(FocusWidget, args); + + FocusWidget.OnKeyDown(args.KeyCode, args.KeyString); + if (input != GuiInput.None) { - mFocusWidget.OnGuiInput(input, ref handled); + FocusWidget.OnGuiInput(input, ref handled); } } else @@ -149,12 +182,14 @@ { bool handled = false; - if (mFocusWidget == null) - FindFocusWidget(); + if (FocusWidget == null) + Desktop.UpdateFocusWidget(); - if (mFocusWidget != null) + if (FocusWidget != null) { - mFocusWidget.OnKeyUp(args.KeyCode, args.KeyString); + GuiStack.ListenEvent(FocusWidget, args); + + FocusWidget.OnKeyUp(args.KeyCode, args.KeyString); } else { @@ -165,25 +200,56 @@ public void OnMouseMove(AgateInputEventArgs e) { Widget targetWidget = mMouseEventWidget; + Widget hoverWidget = WidgetAt(e.MousePosition); if (targetWidget == null) - targetWidget = WidgetAt(e.MousePosition); + targetWidget = hoverWidget; - if (mHoverWidget != targetWidget) + if (mHoverWidget != hoverWidget) { if (mHoverWidget != null) { - mHoverWidget.MouseIn = false; - mHoverWidget.OnMouseLeave(); + var p = mHoverWidget; + while (p.MouseIn && WidgetContainsScreenPoint(p, e.MousePosition) == false) + { + p.MouseIn = false; + + p = p.Parent; + if (p == null) + break; + } } - targetWidget.MouseIn = true; - targetWidget.OnMouseEnter(); + if (hoverWidget != null) + { + var p = hoverWidget; + while (p.MouseIn == false && WidgetContainsScreenPoint(p, e.MousePosition)) + { + p.MouseIn = true; - mHoverWidget = targetWidget; + p = p.Parent; + if (p == null) + break; + } + + mHoverWidget = hoverWidget; + } + } + if (targetWidget is Desktop == false) + Widget.PreferredInputMode = InputMode.Mouse; + + GuiStack.ListenEvent(targetWidget, e); targetWidget.OnMouseMove(targetWidget.ScreenToClient(e.MousePosition)); + + if (mGestureController != null) + { + mCurrentGesture.CurrentPoint = e.MousePosition; + mGestureController.Update(); + } + + e.Handled = true; } public void OnMouseDown(AgateInputEventArgs e) { @@ -191,8 +257,20 @@ mMouseEventWidget = targetWidget; + GuiStack.ListenEvent(targetWidget, e); targetWidget.OnMouseDown(e.MouseButton, targetWidget.ScreenToClient(e.MousePosition)); + + if (e.MouseButton == MouseButton.Primary) + { + mCurrentGesture.Initialize(GestureType.Touch, e.MousePosition, GetGestureWidget(targetWidget)); + + mGestureController = new MouseGesture { GestureData = mCurrentGesture }; + mGestureController.OnBegin(); + } + + e.Handled = true; } + public void OnMouseUp(AgateInputEventArgs e) { Widget targetWidget = mMouseEventWidget; @@ -201,24 +279,53 @@ targetWidget = WidgetAt(e.MousePosition); mMouseEventWidget = null; + GuiStack.ListenEvent(targetWidget, e); targetWidget.OnMouseUp(e.MouseButton, targetWidget.ScreenToClient(e.MousePosition)); + + if (mGestureController != null) + { + mGestureController.OnComplete(); + } + mCurrentGesture.GestureType = GestureType.None; + + e.Handled = true; } + private Widget GetGestureWidget(Widget targetWidget) + { + while (targetWidget is Desktop == false && targetWidget.AcceptGestureInput == false) + targetWidget = targetWidget.Parent; + + return targetWidget; + } + + void mGamepad_ButtonReleased(object sender, GamepadButtonEventArgs e) + { + } + + void mGamepad_ButtonPressed(object sender, GamepadButtonEventArgs e) + { + } + + void mGamepad_LeftStickMoved(object sender, EventArgs e) + { + } + [Obsolete] public void OnKeyDown(InputEventArgs args) { bool handled = false; GuiInput input = InputMap.MapKey(args.KeyCode); - if (mFocusWidget == null) - FindFocusWidget(); + if (FocusWidget == null) + Desktop.UpdateFocusWidget(); - if (mFocusWidget != null) + if (FocusWidget != null) { - mFocusWidget.OnKeyDown(args.KeyCode, args.KeyString); + FocusWidget.OnKeyDown(args.KeyCode, args.KeyString); if (input != GuiInput.None) { - mFocusWidget.OnGuiInput(input, ref handled); + FocusWidget.OnGuiInput(input, ref handled); } } else @@ -231,12 +338,12 @@ { bool handled = false; - if (mFocusWidget == null) - FindFocusWidget(); + if (FocusWidget == null) + Desktop.UpdateFocusWidget(); - if (mFocusWidget != null) + if (FocusWidget != null) { - mFocusWidget.OnKeyUp(args.KeyCode, args.KeyString); + FocusWidget.OnKeyUp(args.KeyCode, args.KeyString); } else { @@ -293,6 +400,9 @@ public void OnUpdate(double delta_t, bool processInput) { + if (mGestureController != null) + mGestureController.OnTimePass(); + mLayout.UpdateLayout(this); mRenderer.Update(this, delta_t); @@ -300,6 +410,7 @@ } public void Draw() { + mRenderer.ActiveGesture = mCurrentGesture; mRenderer.Draw(this); } @@ -364,6 +475,8 @@ mAudioPlayer.PlaySound(sound); } + public IGuiRenderer Renderer { get { return mRenderer; } } + public IGuiLayoutEngine LayoutEngine { get { return mLayout; } } //public void Refresh() //{ @@ -373,12 +486,11 @@ // } //} - internal AgateLib.UserInterface.Css.Documents.CssDocument CssDocument { get; set; } - public void AddWindow(Window wind) { Desktop.Children.Add(wind); } + } class WindowList : IList<Window> Modified: trunk/AgateLib/UserInterface/Widgets/GuiSound.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/GuiSound.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/UserInterface/Widgets/GuiSound.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -27,5 +27,7 @@ public enum GuiSound { MenuNavigate, + Invalid, + MenuSelect, } } Modified: trunk/AgateLib/UserInterface/Widgets/IGuiRenderer.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/IGuiRenderer.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/UserInterface/Widgets/IGuiRenderer.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -28,5 +28,7 @@ void Draw(Gui gui); void Update(Gui gui, double deltaTime); + + Gesture ActiveGesture { get; set; } } } Modified: trunk/AgateLib/UserInterface/Widgets/InputMap.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/InputMap.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/UserInterface/Widgets/InputMap.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -38,7 +38,7 @@ public InputMap() { } - public static InputMap CreateDefaultMapping() + public static InputMap CreateDefaultInputMap() { InputMap retval = new InputMap(); Added: trunk/AgateLib/UserInterface/Widgets/InputMode.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/InputMode.cs (rev 0) +++ trunk/AgateLib/UserInterface/Widgets/InputMode.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.UserInterface.Widgets +{ + public enum InputMode + { + Mouse, + Controller, + } +} Modified: trunk/AgateLib/UserInterface/Widgets/Menu.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Menu.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/UserInterface/Widgets/Menu.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -52,6 +52,9 @@ AcceptFocus = true; Children = new WidgetListOf<MenuItem>(this); + + if (PreferredInputMode == InputMode.Mouse) + mSelIndex = -1; } public Menu(string name) @@ -65,7 +68,8 @@ public bool WrapTopBottom { get; set; } public bool WrapLeftRight { get; set; } public bool DrawMenuItemFrame { get; set; } - + public bool AllowReorder { get; set; } + public int Columns { get { return mColumns; } @@ -88,12 +92,20 @@ get { return mSelIndex; } set { - if (value < 0) - value = 0; + if (PreferredInputMode == InputMode.Mouse) + { + if (value < 0) value = -1; + if (value >= Children.Count) value = -1; + } + else + { + if (value < 0) + value = 0; - if (value >= Children.Count) - value = Children.Count - 1; - + if (value >= Children.Count) + value = Children.Count - 1; + } + mSelIndex = value; OnSelect(false); @@ -129,7 +141,7 @@ { int index = Children.IndexOf(value); - if (index == -1) + if (index == -1 && value != null) throw new ArgumentException("MenuItem " + value.Name + " is not part of this menu!"); SelectedIndex = index; @@ -264,12 +276,12 @@ if (item == null) return; if (item.Enabled == false) { - //ZodiacAudio.PlaySound("invalid"); + MyGui.PlaySound(GuiSound.Invalid); return; } else { - //ZodiacAudio.PlaySound("menuselect"); + MyGui.PlaySound(GuiSound.MenuSelect); } if (AllowDualSelection) @@ -474,5 +486,69 @@ public event EventHandler MenuCancel; public event EventHandler DualSelect; + + protected internal override bool AcceptGestureInput + { + get { return true; } + } + + MenuItem mGestureItem; + + protected internal override void OnGestureBegin(Gesture gesture) + { + mGestureItem = (MenuItem)Children.WidgetAt(ScreenToClient(gesture.StartPoint)); + SelectedItem = mGestureItem; + + gesture.TargetWidget = mGestureItem; + + } + protected internal override void OnGestureChange(Gesture gesture) + { + switch(gesture.GestureType) + { + case GestureType.Touch: + gesture.IsValidForTarget = mGestureItem.Enabled; + break; + + case GestureType.Drag: + case GestureType.Swipe: + if (gesture.Axis == AxisType.Vertical) + { + gesture.IsValidForTarget = true; + gesture.TargetWidget = this; + gesture.Effect = GestureEffect.MoveItem; + } + else + { + gesture.IsValidForTarget = mGestureItem.AllowDiscard; + gesture.Effect = GestureEffect.DiscardItem; + } + + break; + } + } + + protected internal override void OnGestureComplete(Gesture gesture) + { + switch(gesture.GestureType) + { + case GestureType.Touch: + case GestureType.LongPress: + SelectedItem.OnPressAccept(); + break; + + case GestureType.Swipe: + case GestureType.Drag: + var item = gesture.TargetWidget as MenuItem; + + if (item != null) + { + if (gesture.AmountDragged.Magnitude > ClientRect.Width / 2 && item.AllowDiscard) + item.OnDiscard(); + } + + break; + } + } } } Modified: trunk/AgateLib/UserInterface/Widgets/MenuItem.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/MenuItem.cs 2014-09-09 05:35:01 UTC (rev 1522) +++ trunk/AgateLib/UserInterface/Widgets/MenuItem.cs 2014-09-13 23:39:50 UTC (rev 1523) @@ -32,7 +32,8 @@ Children.WidgetRemoved += Children_WidgetRemoved; } - public MenuItem(params Widget[] children) : this() + public MenuItem(params Widget[] children) + : this() { Children.AddRange(children); } @@ -43,17 +44,20 @@ } [Obsolete("Use static MenuItem.OfLabel method instead.")] - public MenuItem(string name, string text) : this() + public MenuItem(string name, string text) + : this() { Name = name; Children.Add(new Label(text)); } - public MenuItem(Widget child) : this() + public MenuItem(Widget child) + : this() { Children.Add(child); } - public MenuItem(string name, Widget child) : this() + public MenuItem(string name, Widget child) + : this() { Name = name; @@ -82,6 +86,7 @@ public event EventHandler PressToggle; public event EventHandler PressMenu; public event EventHandler Select; + public event EventHandler Discard; void Children_WidgetAdded(object sender, WidgetEventArgs e) { @@ -126,28 +131,55 @@ } widget.MouseDown -= widget_MouseDown; + widget.MouseMove -= widget_MouseMove; widget.MouseUp -= widget_MouseUp; } bool mouseDown; void widget_MouseDown(object sender, MouseEventArgs e) { - mouseDown = true; + OnMouseDown(e.Buttons, e.Location); } void widget_MouseUp(object sender, MouseEventArgs e) {... [truncated message content] |
From: <ka...@us...> - 2014-09-09 05:35:08
|
Revision: 1522 http://sourceforge.net/p/agate/code/1522 Author: kanato Date: 2014-09-09 05:35:01 +0000 (Tue, 09 Sep 2014) Log Message: ----------- Some css fixes. Modified Paths: -------------- trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs trunk/AgateLib/UserInterface/Css/Rendering/WidgetAnimator.cs trunk/AgateLib/UserInterface/Css/Selectors/CssSelectorIndividual.cs trunk/AgateLib/UserInterface/Css/Selectors/WidgetMatchParameters.cs trunk/AgateLib/UserInterface/Widgets/Gui.cs trunk/AgateLib/UserInterface/Widgets/Label.cs trunk/AgateLib/UserInterface/Widgets/Menu.cs trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssBindingTest.cs trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs Modified: trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs 2014-09-07 23:06:48 UTC (rev 1521) +++ trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs 2014-09-09 05:35:01 UTC (rev 1522) @@ -104,27 +104,27 @@ { var targetLeft = ConvertDistance(style.Widget, position.Left, true, false).Value; - anim.ClientRect.X = targetLeft + box.Left; + anim.ClientX = targetLeft + box.Left; } if (position.Right.Automatic == false) { int targetRight = ConvertDistance(style.Widget, position.Right, true, false).Value; targetRight = parentStyle.Animator.ClientRect.Width - targetRight; - anim.ClientRect.X = targetRight - anim.ClientRect.Width - box.Right; + anim.ClientX = targetRight - anim.ClientRect.Width - box.Right; } if (position.Top.Automatic == false) { int targetTop = ConvertDistance(style.Widget, position.Top, false, false).Value; - anim.ClientRect.Y = targetTop + box.Top; + anim.ClientY = targetTop + box.Top; } if (position.Bottom.Automatic == false) { int targetBottom = ConvertDistance(style.Widget, position.Bottom, false, false).Value; targetBottom = parentStyle.Animator.ClientRect.Height - targetBottom; - anim.ClientRect.Y = targetBottom - anim.ClientRect.Height - box.Bottom; + anim.ClientY = targetBottom - anim.ClientRect.Height - box.Bottom; } } @@ -144,8 +144,8 @@ } } - containerAnim.ClientRect.X = 0; - containerAnim.ClientRect.Y = 0; + containerAnim.ClientX = 0; + containerAnim.ClientY = 0; int maxWidth = ComputeMaxWidthForContainer(containerStyle); Point nextPos = Point.Empty; @@ -156,7 +156,7 @@ int largestWidth = 0; int bottom = 0; - containerAnim.ClientRect.Width = maxWidth; + containerAnim.ClientWidth = maxWidth; int? fixedContainerWidth = ConvertDistance(container, containerStyle.Data.PositionData.Width, true); int? fixedContainerHeight = ConvertDistance(container, containerStyle.Data.PositionData.Height, true); @@ -217,36 +217,35 @@ break; } - bool includeInLayout = true; - var anim = style.Animator; - anim.ClientRect.Width = sz.Width; - anim.ClientRect.Height = sz.Height; + anim.IncludeInLayout = true; + anim.ClientWidth = sz.Width; + anim.ClientHeight = sz.Height; switch (style.Data.Position) { case CssPosition.Absolute: - includeInLayout = false; - anim.ParentCoordinateSystem = TopLevelWidget(child, x => mAdapter.GetStyle(x).Data.Position == CssPosition.Static); + anim.IncludeInLayout = false; + child.ParentCoordinateSystem = TopLevelWidget(child, x => mAdapter.GetStyle(x).Data.Position != CssPosition.Static); break; case CssPosition.Fixed: - includeInLayout = false; - anim.ParentCoordinateSystem = TopLevelWidget(child); + anim.IncludeInLayout = false; + child.ParentCoordinateSystem = TopLevelWidget(child, x => x is Desktop); break; } - if (includeInLayout) + if (anim.IncludeInLayout) { - anim.ClientRect.X = nextPos.X + box.Left; - anim.ClientRect.Y = nextPos.Y + box.Top; + anim.ClientX = nextPos.X + box.Left; + anim.ClientY = nextPos.Y + box.Top; } anim.ClientWidgetOffset = new Point( box.Padding.Left + box.Border.Left, box.Padding.Top + box.Border.Top); - if (includeInLayout) + if (anim.IncludeInLayout) { switch (containerStyle.Data.Layout.Kind) { @@ -265,16 +264,15 @@ maxHeight = Math.Max(maxHeight, anim.ClientRect.Height + box.Top + box.Bottom); bottom = Math.Max(bottom, anim.ClientRect.Y + anim.ClientRect.Height + box.Bottom); // only add box.Bottom here, because box.Top is taken into account in child.Y. } - } - containerAnim.ClientRect.Width = Math.Min(largestWidth, maxWidth); - containerAnim.ClientRect.Height = bottom; + containerAnim.ClientWidth = Math.Min(largestWidth, maxWidth); + containerAnim.ClientHeight = bottom; if (fixedContainerWidth != null) - containerAnim.ClientRect.Width = (int)fixedContainerWidth; + containerAnim.ClientWidth = (int)fixedContainerWidth; if (fixedContainerHeight != null) - containerAnim.ClientRect.Height = (int)fixedContainerHeight; + containerAnim.ClientHeight = (int)fixedContainerHeight; switch (containerStyle.Data.Layout.Kind) { @@ -286,6 +284,9 @@ var box = style.BoxModel; int width = containerAnim.ClientRect.Width - box.Left - box.Right; + if (anim.IncludeInLayout == false) + continue; + if (style.Data.PositionData.MinWidth.Automatic == false) { int minwidth = mAdapter.CssDistanceToPixels(containerStyle, style.Data.PositionData.MinWidth, true); @@ -297,28 +298,28 @@ width = Math.Min(width, maxwidth); } - anim.ClientRect.Width = width; + anim.ClientWidth = width; } break; } } - private Widget TopLevelWidget(Widget child) + private Container TopLevelWidget(Widget child) { return TopLevelWidget(child, x => true); } - private Widget TopLevelWidget(Widget child, Func<Widget, bool> continueToParent) + private Container TopLevelWidget(Widget child, Func<Widget, bool> validMatch) { var retval = child.Parent; if (retval == null) - return child; + return null; - if (continueToParent(retval) == false) + if (validMatch(retval)) return retval; - return TopLevelWidget(retval, continueToParent); + return TopLevelWidget(retval, validMatch); } private int ComputeMaxWidthForContainer(CssStyle style) Modified: trunk/AgateLib/UserInterface/Css/Rendering/WidgetAnimator.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Rendering/WidgetAnimator.cs 2014-09-07 23:06:48 UTC (rev 1521) +++ trunk/AgateLib/UserInterface/Css/Rendering/WidgetAnimator.cs 2014-09-09 05:35:01 UTC (rev 1522) @@ -19,6 +19,7 @@ using AgateLib.Geometry; using AgateLib.UserInterface.Css.Documents; using AgateLib.UserInterface.Css.Rendering.Transitions; +using AgateLib.UserInterface.Widgets; using System; using System.Collections.Generic; using System.Linq; @@ -30,6 +31,7 @@ public class WidgetAnimator { CssStyle mStyle; + Rectangle mClientRect; public Point ClientWidgetOffset { get; set; } public Size WidgetSize @@ -45,8 +47,33 @@ return widgetSize; } } - public Rectangle ClientRect; + public Rectangle ClientRect + { + get { return mClientRect; } + set { mClientRect = value; } + } + public int ClientX + { + get { return mClientRect.X; } + set { mClientRect.X = value; } + } + public int ClientY + { + get { return mClientRect.Y; } + set { mClientRect.Y = value; } + } + public int ClientWidth + { + get { return mClientRect.Width; } + set { mClientRect.Width = value; } + } + public int ClientHeight + { + get { return mClientRect.Height; } + set { mClientRect.Height = value; } + } + public bool Active { get; private set; } public bool Visible { get; set; } @@ -76,6 +103,13 @@ } } - public Widgets.Widget ParentCoordinateSystem { get; set; } + public Container ParentCoordinateSystem { get { return mStyle.Widget.ParentCoordinateSystem; } } + + public override string ToString() + { + return "Animator: " + mStyle.Widget.ToString(); + } + + public bool IncludeInLayout { get; set; } } } Modified: trunk/AgateLib/UserInterface/Css/Selectors/CssSelectorIndividual.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Selectors/CssSelectorIndividual.cs 2014-09-07 23:06:48 UTC (rev 1521) +++ trunk/AgateLib/UserInterface/Css/Selectors/CssSelectorIndividual.cs 2014-09-09 05:35:01 UTC (rev 1522) @@ -113,12 +113,21 @@ public bool Matches(CssAdapter adapter, WidgetMatchParameters wmp) { - var typename = wmp.TypeName; - if (ObjectType != null && - ObjectType.Equals(typename, StringComparison.OrdinalIgnoreCase) - == false) + if (string.IsNullOrEmpty(ObjectType) == false) { - return false; + bool typeMatch = false; + + foreach (var typename in wmp.TypeNames) + { + if (ObjectType.Equals(typename, StringComparison.OrdinalIgnoreCase)) + { + typeMatch = true; + break; + } + } + + if (typeMatch == false) + return false; } if (PseudoClass != CssPseudoClass.None && PseudoClass != wmp.PseudoClass) Modified: trunk/AgateLib/UserInterface/Css/Selectors/WidgetMatchParameters.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Selectors/WidgetMatchParameters.cs 2014-09-07 23:06:48 UTC (rev 1521) +++ trunk/AgateLib/UserInterface/Css/Selectors/WidgetMatchParameters.cs 2014-09-09 05:35:01 UTC (rev 1522) @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using AgateLib.UserInterface.Widgets.Extensions; @@ -11,11 +12,13 @@ public class WidgetMatchParameters { Widget mWidget; + List<string> mTypeNames = new List<string>(); public WidgetMatchParameters(Widget w) { mWidget = w; + UpdateWidgetTypeNames(); UpdateWidgetProperties(); } @@ -26,11 +29,23 @@ public void UpdateWidgetProperties() { - TypeName = mWidget.GetType().Name; PseudoClass = GetPseudoClass(mWidget); Classes = GetCssClasses(mWidget); } + private void UpdateWidgetTypeNames() + { + mTypeNames.Clear(); + + var type = mWidget.GetType(); + + while (type != typeof(Widget)) + { + mTypeNames.Add(type.Name); + type = type.GetTypeInfo().BaseType; + } + } + private CssPseudoClass GetPseudoClass(Widget control) { if (InActiveWindow(control)) @@ -98,7 +113,7 @@ string cachedClass; - public string TypeName { get; private set; } + public IEnumerable<string> TypeNames { get { return mTypeNames; } } public string Id { get { return Widget.Name; } } public CssPseudoClass PseudoClass { get; private set; } Modified: trunk/AgateLib/UserInterface/Widgets/Gui.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Gui.cs 2014-09-07 23:06:48 UTC (rev 1521) +++ trunk/AgateLib/UserInterface/Widgets/Gui.cs 2014-09-09 05:35:01 UTC (rev 1522) @@ -50,7 +50,7 @@ ForwardUnhandledEvents = true; } - public InputMap InputMap { get ; set; } + public InputMap InputMap { get; set; } public Desktop Desktop { get { return mDesktop; } } void DispatchEvent(Func<Window, bool> action) @@ -142,6 +142,8 @@ { DispatchEvent(window => { window.OnInputButtonDown(args.KeyCode, ref handled); return handled; }); } + + args.Handled = handled; } public void OnKeyUp(AgateInputEventArgs args) { @@ -275,7 +277,8 @@ targetWidget.OnMouseDown(e.MouseButtons, targetWidget.ScreenToClient(e.MousePosition)); } - [Obsolete] public void OnMouseUp(InputEventArgs e) + [Obsolete] + public void OnMouseUp(InputEventArgs e) { Widget targetWidget = mMouseEventWidget; @@ -371,6 +374,11 @@ //} internal AgateLib.UserInterface.Css.Documents.CssDocument CssDocument { get; set; } + + public void AddWindow(Window wind) + { + Desktop.Children.Add(wind); + } } class WindowList : IList<Window> Modified: trunk/AgateLib/UserInterface/Widgets/Label.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Label.cs 2014-09-07 23:06:48 UTC (rev 1521) +++ trunk/AgateLib/UserInterface/Widgets/Label.cs 2014-09-09 05:35:01 UTC (rev 1522) @@ -65,6 +65,9 @@ private void RewrapText(int maxWidth) { + if (Font == null) + return; + mWrapPositions.Clear(); List<int> spacePositions = new List<int>(); Modified: trunk/AgateLib/UserInterface/Widgets/Menu.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Menu.cs 2014-09-07 23:06:48 UTC (rev 1521) +++ trunk/AgateLib/UserInterface/Widgets/Menu.cs 2014-09-09 05:35:01 UTC (rev 1522) @@ -248,8 +248,6 @@ OnCancelPressed(); break; } - - handled = true; } protected internal override void OnUpdate(double deltaTime) { Modified: trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssBindingTest.cs =================================================================== --- trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssBindingTest.cs 2014-09-07 23:06:48 UTC (rev 1521) +++ trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssBindingTest.cs 2014-09-09 05:35:01 UTC (rev 1522) @@ -17,7 +17,7 @@ public class CssBindingTest : CssTestBase { [TestMethod] - public void PropertyMapping() + public void CssBPropertyMapping() { CssPropertyMap pm = new CssPropertyMap(); CssBindingMapper bm = new CssBindingMapper(pm); @@ -30,7 +30,7 @@ } [TestMethod] - public void SelectorMatching() + public void CssBSelectorMatching() { Gui gui = new Gui(null, null); Desktop desktop = new Desktop(gui); @@ -66,7 +66,7 @@ } [TestMethod] - public void PseudoClassMatching() + public void CssBPseudoClassMatching() { Gui gui = new Gui(null, null); Desktop desktop = new Desktop(gui); @@ -83,7 +83,7 @@ } [TestMethod] - public void DescendentMatching() + public void CssBDescendentMatching() { CssDocument doc = CssDocument.FromText("labelimage imagebox { margin-right: 12px; }"); CssAdapter adapter = new CssAdapter(doc); @@ -102,5 +102,44 @@ style = adapter.GetStyle(ib); Assert.AreEqual(0, style.AppliedBlocks.Count); } + + class CustomWindow : Window + { + + } + + [TestMethod] + public void CssBInheritanceMatching() + { + CssDocument doc = CssDocument.FromText("window { margin: 4px; }"); + CssAdapter adapter = new CssAdapter(doc); + var customWindow = new CustomWindow(); + + var style = adapter.GetStyle(customWindow); + + Assert.AreEqual(1, style.AppliedBlocks.Count); + DistanceAssert(false, 4, DistanceUnit.Pixels, style.Data.Margin.Top); + } + + [TestMethod] + public void CssBStyleMatching() + { + CssDocument doc = CssDocument.FromText("window { transition: slide top; } window.style { transition: none; }"); + CssAdapter adapter = new CssAdapter(doc); + + var window = new Window(); + var stylish = new Window { Style = "style" }; + + var swindow = adapter.GetStyle(window); + Assert.AreEqual(1, swindow.AppliedBlocks.Count); + var selector = swindow.AppliedBlocks[0].Selector.IndividualSelectors.First(); + Assert.IsTrue(selector is CssSelectorIndividual); + + CssSelectorIndividual indv = (CssSelectorIndividual)selector; + Assert.AreEqual(0, indv.CssClasses.Count); + + var sstyle = adapter.GetStyle(stylish); + Assert.AreEqual(2, sstyle.AppliedBlocks.Count); + } } } Modified: trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs =================================================================== --- trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs 2014-09-07 23:06:48 UTC (rev 1521) +++ trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs 2014-09-09 05:35:01 UTC (rev 1522) @@ -398,5 +398,26 @@ Assert.AreEqual(new Rectangle(133, 43, 500, 400), window.ClientRect); Assert.AreEqual(new Rectangle(450, 0, 50, 40), panel.WidgetRect); } + + [TestMethod] + public void CssLAbsolutePositionSizing() + { + doc.Clear(); + doc.Parse(@"window { layout: column; } +#abs { position: absolute; width: 400px; }"); + + + var window = new Window(); + var label = new Label { Text = "text" }; + var test = new Label { Name = "abs" }; + + window.Children.Add(label, test); + gui.AddWindow(window); + + RedoLayout(); + + Assert.AreEqual(label.Width, window.Width); + Assert.AreEqual(400, test.Width); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2014-09-07 23:07:00
|
Revision: 1521 http://sourceforge.net/p/agate/code/1521 Author: kanato Date: 2014-09-07 23:06:48 +0000 (Sun, 07 Sep 2014) Log Message: ----------- Fix relative path returning in SubDirectoryProvider.cs Modified Paths: -------------- trunk/AgateLib/IO/SubDirectoryProvider.cs Modified: trunk/AgateLib/IO/SubDirectoryProvider.cs =================================================================== --- trunk/AgateLib/IO/SubDirectoryProvider.cs 2014-09-07 23:04:54 UTC (rev 1520) +++ trunk/AgateLib/IO/SubDirectoryProvider.cs 2014-09-07 23:06:48 UTC (rev 1521) @@ -65,7 +65,15 @@ public IEnumerable<string> GetAllFiles(string searchPattern) { - return parent.GetAllFiles(subdir + searchPattern); + var results = parent.GetAllFiles(subdir + searchPattern); + + foreach(var result in results) + { + if (result.StartsWith(subdir)) + yield return result.Substring(subdir.Length); + else + yield return result; + } } public string ReadAllText(string filename) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2014-09-07 23:05:02
|
Revision: 1520 http://sourceforge.net/p/agate/code/1520 Author: kanato Date: 2014-09-07 23:04:54 +0000 (Sun, 07 Sep 2014) Log Message: ----------- Fix compilation error in test project. Modified Paths: -------------- trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/GuiStuff.cs Modified: trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/GuiStuff.cs =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/GuiStuff.cs 2014-09-07 22:49:41 UTC (rev 1519) +++ trunk/AgateLib.Tests/Tests.WinForms/UserInterfaceTests/GuiStuff.cs 2014-09-07 23:04:54 UTC (rev 1520) @@ -32,7 +32,9 @@ font.AddFont(new FontSurface(res, "MedievalSharp18"), 18, FontStyles.None); font.AddFont(new FontSurface(res, "MedievalSharp14"), 14, FontStyles.None); - var doc = CssDocument.Load("Style.css"); + var doc = new CssDocument(); + + doc.Load("Style.css"); adapter = new CssAdapter(doc, font); gui = new Gui(new CssRenderer(adapter), new CssLayoutEngine(adapter)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2014-09-07 22:49:51
|
Revision: 1519 http://sourceforge.net/p/agate/code/1519 Author: kanato Date: 2014-09-07 22:49:41 +0000 (Sun, 07 Sep 2014) Log Message: ----------- Several CSS fixes and refactorings in the UI portion of the code. Modified Paths: -------------- trunk/AgateLib/AgateLib.csproj trunk/AgateLib/UserInterface/Css/CssAdapter.cs trunk/AgateLib/UserInterface/Css/CssRuleBlock.cs trunk/AgateLib/UserInterface/Css/CssStyleData.cs trunk/AgateLib/UserInterface/Css/Documents/CssDocument.cs trunk/AgateLib/UserInterface/Css/Documents/CssFont.cs trunk/AgateLib/UserInterface/Css/Documents/PropertyEnums.cs trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs trunk/AgateLib/UserInterface/Css/Layout/Defaults/DefaultStyleCollection.cs trunk/AgateLib/UserInterface/Css/Rendering/CssRenderer.cs trunk/AgateLib/UserInterface/Css/Rendering/WidgetAnimator.cs trunk/AgateLib/UserInterface/Css/Selectors/WidgetMatchParameters.cs trunk/AgateLib/UserInterface/Widgets/Container.cs trunk/AgateLib/UserInterface/Widgets/Label.cs trunk/AgateLib/UserInterface/Widgets/LabelImage.cs trunk/AgateLib/UserInterface/Widgets/Panel.cs trunk/AgateLib/UserInterface/Widgets/ProgressBar.cs trunk/AgateLib/UserInterface/Widgets/Widget.cs trunk/AgateLib/UserInterface/Widgets/WidgetList.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj trunk/AgateLib.Tests/UnitTests/AgateLib.Tests.UnitTests.csproj trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs trunk/AgateLib.Tests/UnitTests/UserInterface/Widgets/ConversionTests.cs Added Paths: ----------- trunk/AgateLib/UserInterface/Css/Documents/CssText.cs trunk/AgateLib/UserInterface/Css/Layout/Defaults/ProgressBarDefaultStyle.cs trunk/AgateLib/UserInterface/Widgets/Extensions/ trunk/AgateLib/UserInterface/Widgets/Extensions/WidgetExtensions.cs trunk/AgateLib/UserInterface/Widgets/ITextAlignment.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/Fakes/FakeGuiEngine.cs Modified: trunk/AgateLib/AgateLib.csproj =================================================================== --- trunk/AgateLib/AgateLib.csproj 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib/AgateLib.csproj 2014-09-07 22:49:41 UTC (rev 1519) @@ -509,6 +509,8 @@ <Compile Include="UserInterface\Css\Documents\CssBorder.cs" /> <Compile Include="UserInterface\Css\Documents\CssBorderImage.cs" /> <Compile Include="UserInterface\Css\Documents\CssBoxComponent.cs" /> + <Compile Include="UserInterface\Css\Documents\CssText.cs" /> + <Compile Include="UserInterface\Css\Layout\Defaults\ProgressBarDefaultStyle.cs" /> <Compile Include="UserInterface\Css\Selectors\CssMediaSelector.cs" /> <Compile Include="UserInterface\Css\Documents\PropertyEnums.cs" /> <Compile Include="UserInterface\Css\Documents\CssDistance.cs" /> @@ -559,6 +561,7 @@ <Compile Include="UserInterface\ISurfaceProvider.cs" /> <Compile Include="UserInterface\Widgets\Container.cs" /> <Compile Include="UserInterface\Widgets\Desktop.cs" /> + <Compile Include="UserInterface\Widgets\Extensions\WidgetExtensions.cs" /> <Compile Include="UserInterface\Widgets\Gui.cs" /> <Compile Include="UserInterface\Widgets\GuiInput.cs" /> <Compile Include="UserInterface\Widgets\GuiSound.cs" /> @@ -567,6 +570,7 @@ <Compile Include="UserInterface\Widgets\IGuiRenderer.cs" /> <Compile Include="UserInterface\Widgets\ImageBox.cs" /> <Compile Include="UserInterface\Widgets\InputMap.cs" /> + <Compile Include="UserInterface\Widgets\ITextAlignment.cs" /> <Compile Include="UserInterface\Widgets\KeyboardEventArgs.cs" /> <Compile Include="UserInterface\Widgets\Label.cs" /> <Compile Include="UserInterface\Widgets\LabelImage.cs" /> Modified: trunk/AgateLib/UserInterface/Css/CssAdapter.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/CssAdapter.cs 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib/UserInterface/Css/CssAdapter.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -40,7 +40,7 @@ internal CssAdapter(CssDocument doc) { Document = doc; - + Document.Updated += Document_Updated; MediumInfo = new CssMediumInfo(); switch (Core.Platform.DeviceType) @@ -114,6 +114,7 @@ { int scale = 1; double amount = distance.Amount; + Font font = null; switch (distance.DistanceUnit) { @@ -134,7 +135,7 @@ break; case DistanceUnit.FontHeight: - var font = style.Widget.Font; + font = style.Widget.Font; if (font != null) scale = font.FontHeight; @@ -143,6 +144,16 @@ break; + case DistanceUnit.FontAverageWidth: + font = style.Widget.Font; + + if (font != null) + scale = font.FontHeight / 2; + else + scale = 0; + + break; + default: throw new NotImplementedException(); } @@ -330,5 +341,26 @@ return false; } + + + void Document_Updated(object sender, EventArgs e) + { + foreach (var widget in mObjectStyles.Keys) + { + widget.LayoutDirty = true; + widget.StyleDirty = true; + + mObjectStyles[widget].AppliedBlocks.Clear(); + } + } + + + public void SetFont(Widget control) + { + var style = GetStyle(control); + + control.Font = style.Font; + control.Font.Style = style.Data.Font.Weight; + } } } Modified: trunk/AgateLib/UserInterface/Css/CssRuleBlock.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/CssRuleBlock.cs 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib/UserInterface/Css/CssRuleBlock.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -52,9 +52,9 @@ public void AddProperty(string name, string value) { - Properties.Add(name, value); + Properties[name] = value; - Bindings.Add(name, new Binding(map, name, value)); + Bindings[name] = new Binding(map, name, value); } Modified: trunk/AgateLib/UserInterface/Css/CssStyleData.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/CssStyleData.cs 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib/UserInterface/Css/CssStyleData.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -46,6 +46,7 @@ Border = new CssBorder(); Layout = new CssLayout(); Transition = new CssTransition(); + Text = new CssText(); Display = CssDisplay.Initial; } @@ -77,5 +78,8 @@ [CssPromoteProperties(prefix: "transition")] public CssTransition Transition { get; set; } + + [CssPromoteProperties] + public CssText Text { get; set; } } } Modified: trunk/AgateLib/UserInterface/Css/Documents/CssDocument.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Documents/CssDocument.cs 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib/UserInterface/Css/Documents/CssDocument.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -32,31 +32,55 @@ public CssDocument() { + Clear(); + } + + public static CssDocument FromText(string css) + { + CssDocument doc = new CssDocument(); + + doc.Parse(css); + + return doc; + } + + public void Clear() + { + mMedia.Clear(); + var defaultMedium = new CssMediaSelector("all"); Media.Add(defaultMedium); } - public static CssDocument Load(string filename) + + public void Load(string filename) { - CssDocument doc = new CssDocument(); CssParser parser = new CssParser(); - parser.Load(doc, filename); + parser.Load(this, filename); - return doc; + OnUpdated(); } - public static CssDocument FromText(string text) + public void Parse(string css) { - CssDocument doc = new CssDocument(); CssParser parser = new CssParser(); - parser.ParseCss(doc, text); + parser.ParseCss(this, css); - return doc; + OnUpdated(); } + private void OnUpdated() + { + if (Updated != null) + Updated(this, EventArgs.Empty); + } + public List<CssMediaSelector> Media { get { return mMedia; } } public CssMediaSelector DefaultMedium { get { return mMedia.First(); } } + + + public event EventHandler Updated; } } Modified: trunk/AgateLib/UserInterface/Css/Documents/CssFont.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Documents/CssFont.cs 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib/UserInterface/Css/Documents/CssFont.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -1,4 +1,5 @@ -// The contents of this file are subject to the Mozilla Public License +using AgateLib.DisplayLib; +// The contents of this file are subject to the Mozilla Public License // Version 1.1 (the "License"); you may not use this file except in // compliance with the License. You may obtain a copy of the License at // http://www.mozilla.org/MPL/ @@ -40,7 +41,12 @@ [CssAlias("font-size")] public CssDistance Size { get; set; } + [CssAlias("font-weight")] + public FontStyles Weight { get; set; } + public Color Color { get; set; } } + + } Added: trunk/AgateLib/UserInterface/Css/Documents/CssText.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Documents/CssText.cs (rev 0) +++ trunk/AgateLib/UserInterface/Css/Documents/CssText.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -0,0 +1,15 @@ +using AgateLib.UserInterface.Css.Binders; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.UserInterface.Css.Documents +{ + public class CssText + { + [CssAlias("text-align")] + public CssTextAlign Align { get; set; } + } +} Modified: trunk/AgateLib/UserInterface/Css/Documents/PropertyEnums.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Documents/PropertyEnums.cs 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib/UserInterface/Css/Documents/PropertyEnums.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -28,6 +28,7 @@ { Initial, None, + Block, } public enum CssTransitionType @@ -103,4 +104,13 @@ Absolute, Fixed, } + + public enum CssTextAlign + { + Inherit, + Initial, + Left, + Right, + Center, + } } Modified: trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib/UserInterface/Css/Layout/CssLayoutEngine.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -46,6 +46,7 @@ totalRefresh |= gui.Desktop.Width != renderTargetSize.Width; totalRefresh |= gui.Desktop.Height != renderTargetSize.Height; + totalRefresh |= gui.Desktop.LayoutDirty; gui.Desktop.Width = renderTargetSize.Width; gui.Desktop.Height = renderTargetSize.Height; @@ -54,7 +55,14 @@ RedoLayout(gui.Desktop, totalRefresh); - RedoFixedLayout(gui.Desktop); + if (totalRefresh || gui.Desktop.Descendants.Any(x => x.LayoutDirty)) + { + RedoFixedLayout(gui.Desktop); + + gui.Desktop.LayoutDirty = false; + foreach (var w in gui.Desktop.Descendants) + w.LayoutDirty = false; + } } private void SetDesktopAnimatorProperties(Desktop desktop) @@ -62,12 +70,16 @@ var style = mAdapter.GetStyle(desktop); style.Animator.ClientRect = new Rectangle(0, 0, desktop.Width, desktop.Height); - style.Animator.WidgetSize = new Size(desktop.Width, desktop.Height); } private void RedoFixedLayout(Desktop desktop) { - foreach (var child in desktop.Descendants) + var deskStyle = mAdapter.GetStyle(desktop); + deskStyle.Animator.ClientRect = new Rectangle(0, 0, desktop.Width, desktop.Height); + + foreach (var child in desktop.Descendants.Where(x => { + var pos = mAdapter.GetStyle(x).Data.Position; + return pos == CssPosition.Absolute || pos == CssPosition.Fixed;} )) { var style = mAdapter.GetStyle(child); var sz = style.Animator.ClientRect.Size; @@ -97,7 +109,7 @@ if (position.Right.Automatic == false) { int targetRight = ConvertDistance(style.Widget, position.Right, true, false).Value; - targetRight = parentStyle.Animator.WidgetSize.Width - targetRight; + targetRight = parentStyle.Animator.ClientRect.Width - targetRight; anim.ClientRect.X = targetRight - anim.ClientRect.Width - box.Right; } @@ -110,7 +122,7 @@ if (position.Bottom.Automatic == false) { int targetBottom = ConvertDistance(style.Widget, position.Bottom, false, false).Value; - targetBottom = parentStyle.Animator.WidgetSize.Height - targetBottom; + targetBottom = parentStyle.Animator.ClientRect.Height - targetBottom; anim.ClientRect.Y = targetBottom - anim.ClientRect.Height - box.Bottom; } @@ -123,21 +135,24 @@ var containerAnim = containerStyle.Animator; CssBoxModel containerBox = containerStyle.BoxModel; - containerAnim.ClientRect.X = 0; - containerAnim.ClientRect.Y = 0; - if (forceRefresh == false) { - if (container.Descendants.Any(x => x.LayoutDirty) == false) + if (container.LayoutDirty == false && + container.Descendants.Any(x => x.LayoutDirty) == false) + { return; + } } + containerAnim.ClientRect.X = 0; + containerAnim.ClientRect.Y = 0; + int maxWidth = ComputeMaxWidthForContainer(containerStyle); Point nextPos = Point.Empty; int maxHeight = 0; maxWidth -= containerBox.Left + containerBox.Right; - + int largestWidth = 0; int bottom = 0; @@ -148,12 +163,19 @@ if (fixedContainerWidth != null) maxWidth = (int)fixedContainerWidth; + bool resetNextPosition = false; + foreach (var child in container.Children) { var style = mAdapter.GetStyle(child); child.Font = style.Font; - var sz = ComputeSize(child, containerStyle); + if (child.Visible == false) + continue; + if (style.Data.Display == CssDisplay.None) + continue; + + var sz = ComputeSize(child, containerStyle, forceRefresh); var box = style.BoxModel; int? fixedWidth = ConvertDistance(child, style.Data.PositionData.Width, true); int? fixedHeight = ConvertDistance(child, style.Data.PositionData.Height, false); @@ -161,10 +183,32 @@ if (fixedWidth != null) sz.Width = (int)fixedWidth; if (fixedHeight != null) sz.Height = (int)fixedHeight; + int? minWidth = ConvertDistance(child, style.Data.PositionData.MinWidth, true, true); + int? minHeight = ConvertDistance(child, style.Data.PositionData.MinHeight, true, true); + + if (minWidth != null && sz.Width < (int)minWidth) sz.Width = (int)minWidth; + if (minHeight != null && sz.Height < (int)minHeight) sz.Height = (int)minHeight; + + bool resetPosition = false; + switch (containerStyle.Data.Layout.Kind) { case CssLayoutKind.Flow: + if (resetNextPosition) + { + resetPosition = true; + resetNextPosition = false; + } + if (style.Data.Display == CssDisplay.Block) + { + resetPosition = true; + resetNextPosition = true; + } + if (nextPos.X + sz.Width + style.BoxModel.Left + style.BoxModel.Right > maxWidth) + resetPosition = true; + + if (resetPosition) { nextPos.X = 0; nextPos.Y += maxHeight; @@ -174,11 +218,8 @@ } bool includeInLayout = true; - + var anim = style.Animator; - - anim.ClientRect.X = nextPos.X + box.Left; - anim.ClientRect.Y = nextPos.Y + box.Top; anim.ClientRect.Width = sz.Width; anim.ClientRect.Height = sz.Height; @@ -186,7 +227,7 @@ { case CssPosition.Absolute: includeInLayout = false; - anim.ParentCoordinateSystem = TopLevelWidget(child, x => mAdapter.GetStyle(x).Data.Position == CssPosition.Relative); + anim.ParentCoordinateSystem = TopLevelWidget(child, x => mAdapter.GetStyle(x).Data.Position == CssPosition.Static); break; case CssPosition.Fixed: @@ -195,14 +236,16 @@ break; } + if (includeInLayout) + { + anim.ClientRect.X = nextPos.X + box.Left; + anim.ClientRect.Y = nextPos.Y + box.Top; + } + anim.ClientWidgetOffset = new Point( box.Padding.Left + box.Border.Left, box.Padding.Top + box.Border.Top); - anim.WidgetSize = new Size( - anim.ClientRect.Width + box.Padding.Left + box.Padding.Right + box.Border.Left + box.Border.Right, - anim.ClientRect.Height + box.Padding.Top + box.Padding.Bottom + box.Border.Bottom + box.Border.Top); - if (includeInLayout) { switch (containerStyle.Data.Layout.Kind) @@ -223,7 +266,6 @@ bottom = Math.Max(bottom, anim.ClientRect.Y + anim.ClientRect.Height + box.Bottom); // only add box.Bottom here, because box.Top is taken into account in child.Y. } - child.LayoutDirty = false; } containerAnim.ClientRect.Width = Math.Min(largestWidth, maxWidth); @@ -260,7 +302,6 @@ break; } - container.LayoutDirty = false; } private Widget TopLevelWidget(Widget child) @@ -302,15 +343,16 @@ } } - private Size ComputeSize(Widget control, CssStyle parentStyle) + private Size ComputeSize(Widget control, CssStyle parentStyle, bool forceRefresh) { - return ComputeSize(control, parentStyle.Data); + return ComputeSize(control, parentStyle.Data, forceRefresh); } - private Size ComputeSize(Widget control, CssStyleData parentStyle) + private Size ComputeSize(Widget control, CssStyleData parentStyle, bool forceRefresh) { if (control is Container) - return ComputeContainerSize((Container)control); + return ComputeContainerSize((Container)control, forceRefresh); + mAdapter.SetFont(control); var style = mAdapter.GetStyle(control); return control.ComputeSize( @@ -328,9 +370,9 @@ return mAdapter.CssDistanceToPixels(control, cssDistance, width); } - private Size ComputeContainerSize(Container container) + private Size ComputeContainerSize(Container container, bool forceRefresh) { - RedoLayout(container); + RedoLayout(container, forceRefresh); var anim = mAdapter.GetStyle(container).Animator; return new Size(anim.ClientRect.Width, anim.ClientRect.Height); Modified: trunk/AgateLib/UserInterface/Css/Layout/Defaults/DefaultStyleCollection.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Layout/Defaults/DefaultStyleCollection.cs 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib/UserInterface/Css/Layout/Defaults/DefaultStyleCollection.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -34,6 +34,7 @@ { mSetters[typeof(Window)] = new WindowDefaultStyle(); mSetters[typeof(Menu)] = new MenuDefaultStyle(); + mSetters[typeof(ProgressBar)] = new ProgressBarDefaultStyle(); } public void Add(IDefaultStyleSetter styleSetter, params Type[] types) Added: trunk/AgateLib/UserInterface/Css/Layout/Defaults/ProgressBarDefaultStyle.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Layout/Defaults/ProgressBarDefaultStyle.cs (rev 0) +++ trunk/AgateLib/UserInterface/Css/Layout/Defaults/ProgressBarDefaultStyle.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -0,0 +1,19 @@ +using AgateLib.UserInterface.Css.Documents; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.UserInterface.Css.Layout.Defaults +{ + class ProgressBarDefaultStyle : BlankDefaultStyle + { + public override void SetDefaultStyle(CssStyle style) + { + style.Data.PositionData.MinWidth = CssDistance.FromString("40px"); + style.Data.PositionData.MinHeight = CssDistance.FromString("4px"); + style.Data.Border.SetValueFromText("1px solid black"); + } + } +} Modified: trunk/AgateLib/UserInterface/Css/Rendering/CssRenderer.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Rendering/CssRenderer.cs 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib/UserInterface/Css/Rendering/CssRenderer.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -92,8 +92,15 @@ { CssStyle style = mAdapter.GetStyle(control); - control.Font = style.Font; + mAdapter.SetFont(control); + if (control is ITextAlignment) + { + ITextAlignment txa = (ITextAlignment)control; + + txa.TextAlign = ConvertTextAlign(style.Data.Text.Align); + } + if (style.Animator.Visible == false) return; @@ -104,6 +111,21 @@ control.DrawImpl(); } + private OriginAlignment ConvertTextAlign(CssTextAlign cssTextAlign) + { + switch(cssTextAlign) + { + case CssTextAlign.Right: + return OriginAlignment.TopRight; + + case CssTextAlign.Center: + return OriginAlignment.TopCenter; + + default: + return OriginAlignment.TopLeft; + } + } + private void SetFontProperties(CssStyle style) { style.Widget.FontColor = style.Data.Font.Color; @@ -178,7 +200,6 @@ DrawRepeatedClipped(image, srcRect, startPt, clipRect, repeatX, repeatY); } - private void DrawRepeatedClipped(Surface image, Rectangle srcRect, Point startPt, Rectangle clipRect, bool repeatX, bool repeatY) { int countX = (int)Math.Ceiling(clipRect.Width / (double)srcRect.Width); Modified: trunk/AgateLib/UserInterface/Css/Rendering/WidgetAnimator.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Rendering/WidgetAnimator.cs 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib/UserInterface/Css/Rendering/WidgetAnimator.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -31,9 +31,20 @@ { CssStyle mStyle; + public Point ClientWidgetOffset { get; set; } + public Size WidgetSize + { + get + { + var widgetSize = ClientRect.Size; + var box = mStyle.BoxModel; - public Point ClientWidgetOffset { get; set; } - public Size WidgetSize { get; set; } + widgetSize.Width += box.Padding.Left + box.Padding.Right + box.Border.Left + box.Border.Right; + widgetSize.Height += box.Padding.Top + box.Padding.Bottom + box.Border.Bottom + box.Border.Top; + + return widgetSize; + } + } public Rectangle ClientRect; public bool Active { get; private set; } Modified: trunk/AgateLib/UserInterface/Css/Selectors/WidgetMatchParameters.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Selectors/WidgetMatchParameters.cs 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib/UserInterface/Css/Selectors/WidgetMatchParameters.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using AgateLib.UserInterface.Widgets.Extensions; namespace AgateLib.UserInterface.Css.Selectors { @@ -40,7 +41,7 @@ { Container container = (Container)control; - if (container.ChildHasMouseIn) + if (container.ChildHasMouseIn()) return CssPseudoClass.Hover; } if (control is MenuItem) Modified: trunk/AgateLib/UserInterface/Widgets/Container.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Container.cs 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib/UserInterface/Widgets/Container.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -24,7 +24,7 @@ namespace AgateLib.UserInterface.Widgets { - public class Container : Widget + public abstract class Container : Widget { public Container() { @@ -47,25 +47,16 @@ foreach (var w in Children) { yield return w; - } - foreach (var w in Children.OfType<Container>()) - { - foreach (var ww in ((Container)w).Descendants) - yield return ww; + if (w is Container) + { + foreach (var ww in ((Container)w).Descendants) + yield return ww; + } } } } - public bool ChildHasMouseIn - { - get - { - return Children.Any(x => x.MouseIn) || - Children.OfType<Container>().Any(x => x.ChildHasMouseIn); - } - } - public void BringToFront(Widget item) { if (Children.Contains(item) == false) Added: trunk/AgateLib/UserInterface/Widgets/Extensions/WidgetExtensions.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Extensions/WidgetExtensions.cs (rev 0) +++ trunk/AgateLib/UserInterface/Widgets/Extensions/WidgetExtensions.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.UserInterface.Widgets.Extensions +{ + public static class WidgetExtensions + { + public static bool ChildHasMouseIn(this Container c) + { + return c.Descendants.Any(x => x.MouseIn); + } + } +} Added: trunk/AgateLib/UserInterface/Widgets/ITextAlignment.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/ITextAlignment.cs (rev 0) +++ trunk/AgateLib/UserInterface/Widgets/ITextAlignment.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -0,0 +1,14 @@ +using AgateLib.DisplayLib; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.UserInterface.Widgets +{ + public interface ITextAlignment + { + OriginAlignment TextAlign { get; set; } + } +} Modified: trunk/AgateLib/UserInterface/Widgets/Label.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Label.cs 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib/UserInterface/Widgets/Label.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -25,7 +25,7 @@ namespace AgateLib.UserInterface.Widgets { - public class Label : Widget + public class Label : Widget, ITextAlignment { string mText = string.Empty; bool mWrapText; Modified: trunk/AgateLib/UserInterface/Widgets/LabelImage.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/LabelImage.cs 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib/UserInterface/Widgets/LabelImage.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -7,7 +7,7 @@ namespace AgateLib.UserInterface.Widgets { - public class LabelImage : Container + public class LabelImage : Container, ITextAlignment { Label mLabel; ImageBox mImageBox; @@ -21,7 +21,7 @@ Children.Add(mLabel); } public LabelImage(string text, IDrawable image) - :this() + : this() { Text = text; Image = image; @@ -32,5 +32,7 @@ public Label Label { get { return mLabel; } } public ImageBox ImageBox { get { return mImageBox; } } + + public OriginAlignment TextAlign { get { return Label.TextAlign; } set { Label.TextAlign = value; } } } } Modified: trunk/AgateLib/UserInterface/Widgets/Panel.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Panel.cs 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib/UserInterface/Widgets/Panel.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -23,7 +23,7 @@ namespace AgateLib.UserInterface.Widgets { - class Panel : Container + public class Panel : Container { } } Modified: trunk/AgateLib/UserInterface/Widgets/ProgressBar.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/ProgressBar.cs 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib/UserInterface/Widgets/ProgressBar.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -47,7 +47,7 @@ public override void DrawImpl() { Rectangle destRect = ClientToScreen( - new Rectangle(X, Y, Width, Height)); + new Rectangle(0, 0, Width, Height)); if (Max > 0) { @@ -56,6 +56,8 @@ int maxBarWidth = Width; int width = (int)(percentage * maxBarWidth); + destRect.Width = width; + var grad = new Gradient(Gradient.TopLeft); grad.TopRight = Gradient.Interpolate(width, 0); grad.BottomRight = grad.TopRight; Modified: trunk/AgateLib/UserInterface/Widgets/Widget.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Widget.cs 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib/UserInterface/Widgets/Widget.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -29,6 +29,7 @@ { public class Widget { + Container mParentCoordinateSystem; private Point mClientWidgetOffset; private Size mWidgetSize; @@ -38,6 +39,7 @@ private bool mEnabled = true; string mStyle = string.Empty; bool mLayoutDirty; + bool mVisible; public Widget() { @@ -82,7 +84,10 @@ public Size WidgetSize { get { return mWidgetSize; } - set { mWidgetSize = value; } + set + { + mWidgetSize = value; + } } public override string ToString() @@ -106,6 +111,20 @@ public bool AutoSize { get; set; } public virtual Container Parent { get; set; } + protected internal Container ParentCoordinateSystem + { + get + { + if (mParentCoordinateSystem == null) + return Parent; + else + return mParentCoordinateSystem; + } + internal set + { + mParentCoordinateSystem = value; + } + } public Font Font { get @@ -120,7 +139,7 @@ mFont = value; } } - public Color FontColor + public virtual Color FontColor { get { @@ -192,7 +211,7 @@ Point translated = ClientToParent(clientPoint); - return Parent.ClientToScreen(translated); + return ParentCoordinateSystem.ClientToScreen(translated); } public Point ScreenToClient(Point screenPoint) { @@ -261,8 +280,19 @@ public virtual void Refresh() { } - public virtual bool Visible { get; set; } + public virtual bool Visible + { + get { return mVisible; } + set + { + if (value == mVisible) + return; + mVisible = value; + LayoutDirty = true; + } + } + public string Style { get { return mStyle; } @@ -270,8 +300,11 @@ { if (value == null) throw new ArgumentNullException(); + if (value == mStyle) + return; mStyle = value; + LayoutDirty = true; } } @@ -281,7 +314,8 @@ set { mLayoutDirty = value; - StyleDirty = true; + if (value) + StyleDirty = true; } } internal bool StyleDirty { get; set; } Modified: trunk/AgateLib/UserInterface/Widgets/WidgetList.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/WidgetList.cs 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib/UserInterface/Widgets/WidgetList.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -96,6 +96,10 @@ OnWidgetAdded(item); } + public void Add(params Widget[] items) + { + AddRange(items); + } public void AddRange(IEnumerable<Widget> items) { if (items == null) throw new ArgumentNullException("item"); Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj 2014-09-07 22:49:41 UTC (rev 1519) @@ -59,6 +59,7 @@ <Compile Include="Fakes\FakeDisplayWindow.cs" /> <Compile Include="Fakes\FakeFontSurface.cs" /> <Compile Include="Fakes\FakeFrameBuffer.cs" /> + <Compile Include="Fakes\FakeGuiEngine.cs" /> <Compile Include="Fakes\FakePlatformFactory.cs" /> <Compile Include="Fakes\FakePlatformInfo.cs" /> <Compile Include="Fakes\FakeRenderTarget.cs" /> Added: trunk/AgateLib.Tests/AgateLib.Tests.Portable/Fakes/FakeGuiEngine.cs =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/Fakes/FakeGuiEngine.cs (rev 0) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/Fakes/FakeGuiEngine.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -0,0 +1,24 @@ +using AgateLib.UserInterface.Widgets; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.Testing.Fakes +{ + public class FakeRenderer : IGuiRenderer + { + public void Draw(Gui gui) + { + } + public void Update(Gui gui, double deltaTime) + { } + } + public class FakeLayout : IGuiLayoutEngine + { + public void UpdateLayout(Gui gui) + { + } + } +} Modified: trunk/AgateLib.Tests/UnitTests/AgateLib.Tests.UnitTests.csproj =================================================================== --- trunk/AgateLib.Tests/UnitTests/AgateLib.Tests.UnitTests.csproj 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib.Tests/UnitTests/AgateLib.Tests.UnitTests.csproj 2014-09-07 22:49:41 UTC (rev 1519) @@ -19,6 +19,7 @@ <TargetFrameworkProfile /> <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> <RestorePackages>true</RestorePackages> + <_ResolveReferenceDependencies>true</_ResolveReferenceDependencies> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> Modified: trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs =================================================================== --- trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -22,6 +22,7 @@ CssLayoutEngine engine; Gui gui; CssAdapter adapter; + CssDocument doc; [TestInitialize] public void CssLInit() @@ -43,18 +44,25 @@ ff.AddFont(new FontSettings(10, FontStyles.Bold), FontSurface.FromImpl(new FakeFontSurface { Height = 10 })); - CssDocument doc = CssDocument.FromText( - "window { layout: column; margin: 6px; padding: 8px;} label { margin-left: 4px; } " + - "window.fixed { position: fixed; right: 4px; bottom: 8px; margin: 14px; padding: 9px; border: 2px; } "+ - "window.fixedleft { position: fixed; left: 4px; top: 8px; margin: 14px; padding: 9px; border: 2px; }"); + doc = new CssDocument(); + doc.Parse(@" +window { layout: column; margin: 6px; padding: 8px;} +label { margin-left: 4px; } +window.fixed { position: fixed; right: 4px; bottom: 8px; margin: 14px; padding: 9px; border: 2px; } +window.fixedleft { position: fixed; left: 4px; top: 8px; margin: 14px; padding: 9px; border: 2px; } +window.minsize { min-width: 500px; min-height: 400px; } +.invisible { display: none; } +.block { display:block; } + "); + adapter = new CssAdapter(doc, ff); engine = new CssLayoutEngine(adapter); - gui = new Gui(new FakeRenderer(), engine); - + gui = new Gui(new FakeRenderer(), engine); + Core.Initialize(new FakeAgateFactory()); Core.InitAssetLocations(new AssetLocations()); } @@ -99,17 +107,28 @@ Assert.AreEqual(new Point(18, 14 + fh), wind.Children[1].ClientToScreen(Point.Empty)); } + [TestMethod] + public void CssLMinSizes() + { + Window wind = new Window { Style = "minsize" }; + gui.Desktop.Children.Add(wind); + RedoLayout(); + + Assert.AreEqual(500, wind.ClientRect.Width, "Failed to set min width"); + Assert.AreEqual(400, wind.ClientRect.Height, "Failed to set min height"); + } + [TestMethod] public void CssLFixedRightBottom() { - Window wind = new Window() { Style = "fixed" }; + Window wind = new Window { Style = "fixed" }; gui.Desktop.Children.Add(wind); RedoLayout(); Assert.AreEqual(1000 - 18, wind.WidgetRect.Right); - Assert.AreEqual(1000 -22, wind.WidgetRect.Bottom); + Assert.AreEqual(1000 - 22, wind.WidgetRect.Bottom); } [TestMethod] @@ -129,13 +148,13 @@ { Window wind = new Window(); Menu mnu = new Menu(); - Container c = new Container(); + Panel pnl = new Panel(); ImageBox ib = new ImageBox(); Label lbl1 = new Label("Test1"); Label lbl2 = new Label("Test2"); - c.Children.AddRange(new Widget[] { ib, lbl1, lbl2 }); - mnu.Children.Add(new MenuItem(c)); + pnl.Children.AddRange(new Widget[] { ib, lbl1, lbl2 }); + mnu.Children.Add(new MenuItem(pnl)); wind.Children.Add(mnu); gui.Desktop.Children.Add(wind); @@ -152,13 +171,13 @@ { Window wind = new Window(); Menu mnu = new Menu(); - Container c = new Container(); + Panel pnl = new Panel(); ImageBox ib = new ImageBox(); Label lbl1 = new Label("Test1"); Label lbl2 = new Label("Test2"); - c.Children.AddRange(new Widget[] { ib, lbl1, lbl2 }); - mnu.Children.Add(new MenuItem(c)); + pnl.Children.AddRange(new Widget[] { ib, lbl1, lbl2 }); + mnu.Children.Add(new MenuItem(pnl)); wind.Children.Add(mnu); gui.Desktop.Children.Add(wind); @@ -171,14 +190,213 @@ Assert.AreEqual(new Rectangle(0, 0, 96, 96), ib.WidgetRect); lbl1.Text = "Test1Test2Test3"; + Assert.AreEqual(120, ff.MeasureString(lbl1.Text).Width); RedoLayout(); - Assert.AreEqual(120, ff.MeasureString(lbl1.Text).Width); Assert.AreEqual(new Rectangle(100, 0, 120, 8), lbl1.WidgetRect); Assert.AreEqual(new Rectangle(224, 0, 40, 8), lbl2.WidgetRect); Assert.AreEqual(new Rectangle(0, 0, 96, 96), ib.WidgetRect); + } + [TestMethod] + public void CssLHiddenWidgets() + { + Window wind = new Window(); + Menu mnu = new Menu(); + Panel pnl = new Panel(); + ImageBox ib = new ImageBox(); + Label lbl1 = new Label("Test1"); + Label lbl2 = new Label("Test2"); + + pnl.Children.AddRange(new Widget[] { ib, lbl1, lbl2 }); + mnu.Children.Add(new MenuItem(pnl)); + wind.Children.Add(mnu); + + gui.Desktop.Children.Add(wind); + + RedoLayout(); + + Assert.AreEqual(40, ff.MeasureString(lbl1.Text).Width); + Assert.AreEqual(new Rectangle(100, 0, 40, 8), lbl1.WidgetRect); + Assert.AreEqual(new Rectangle(144, 0, 40, 8), lbl2.WidgetRect); + Assert.AreEqual(new Rectangle(0, 0, 96, 96), ib.WidgetRect); + + lbl1.Style = "invisible"; + RedoLayout(); + + Assert.AreEqual(new Rectangle(100, 0, 40, 8), lbl2.WidgetRect, "Failed to exclude display:none from layout."); + Assert.AreEqual(new Rectangle(0, 0, 96, 96), ib.WidgetRect); + + lbl1.Style = ""; + RedoLayout(); + + Assert.AreEqual(new Rectangle(144, 0, 40, 8), lbl2.WidgetRect, "Failed to reinclude display:initial in layout."); + Assert.AreEqual(new Rectangle(0, 0, 96, 96), ib.WidgetRect); + + lbl1.Visible = false; + RedoLayout(); + + Assert.AreEqual(new Rectangle(100, 0, 40, 8), lbl2.WidgetRect, "Failed to exclude visible=false from layout."); + Assert.AreEqual(new Rectangle(0, 0, 96, 96), ib.WidgetRect); } + + [TestMethod] + public void CssLDisplayBlock() + { + Window wind = new Window(); + Menu mnu = new Menu(); + Panel pnl = new Panel(); + ImageBox ib = new ImageBox(); + Label lbl1 = new Label("Test1"); + Label lbl2 = new Label("Test2"); + Label lbl3 = new Label("Test3") { Style = "block" }; + Label lbl4 = new Label("Test4"); + + pnl.Children.AddRange(new Widget[] { ib, lbl1, lbl2, lbl3, lbl4 }); + mnu.Children.Add(new MenuItem(pnl)); + wind.Children.Add(mnu); + + gui.Desktop.Children.Add(wind); + + RedoLayout(); + + Assert.AreEqual(40, ff.MeasureString(lbl1.Text).Width); + Assert.AreEqual(new Rectangle(100, 0, 40, 8), lbl1.WidgetRect); + Assert.AreEqual(new Rectangle(144, 0, 40, 8), lbl2.WidgetRect); + Assert.AreEqual(new Rectangle(0, 0, 96, 96), ib.WidgetRect); + Assert.AreEqual(new Rectangle(4, 96, 40, 8), lbl3.WidgetRect); + Assert.AreEqual(new Rectangle(4, 104, 40, 8), lbl4.WidgetRect); + } + + [TestMethod] + public void CssLFixedPositioning() + { + doc.Clear(); + doc.Parse(@" +window { position: absolute; left: 20px; top: 30px; width: 50px; height: 40px; } +label { position: fixed; left: 40px; top: 70px; width: 60px; height: 50px; } +"); + + Window wind = new Window(); + Label lbl = new Label(); + + wind.Children.Add(lbl); + + gui.Desktop.Children.Add(wind); + + RedoLayout(); + + Assert.AreEqual(new Size(50, 40), wind.ClientRect.Size); + Assert.AreEqual(new Point(20, 30), wind.ClientRect.Location); + + Assert.AreEqual(new Point(40, 70), lbl.ClientRect.Location); + } + + [TestMethod] + public void CssLAbsolutePositioning() + { + doc.Clear(); + doc.Parse(@" +window { position: absolute; top: 10px; left: 10px; width: 800px; height: 600px; } +panel { width:50px; height:30px; } +#p1 { position: absolute; top:0; left:0; } +#p2 { position: absolute; top:0; right:0; } +#p3 { position: absolute; bottom:0; left:0; } +#p4 { position: absolute; bottom:0; right:0; } +"); + + Window wind = new Window(); + Panel p1 = new Panel { Name = "p1" }; + Panel p2 = new Panel { Name = "p2" }; + Panel p3 = new Panel { Name = "p3" }; + Panel p4 = new Panel { Name = "p4" }; + + wind.Children.Add(p1, p2, p3, p4); + gui.Desktop.Children.Add(wind); + + RedoLayout(); + + Assert.AreEqual(new Rectangle(10, 10, 800, 600), wind.WidgetRect); + Assert.AreEqual(new Rectangle(0, 0, 50, 30), p1.WidgetRect, "Failed p1"); + Assert.AreEqual(new Rectangle(750, 0, 50, 30), p2.WidgetRect, "Failed p2"); + Assert.AreEqual(new Rectangle(0, 570, 50, 30), p3.WidgetRect, "Failed p3"); + Assert.AreEqual(new Rectangle(750, 570, 50, 30), p4.WidgetRect, "Failed p4"); + } + + [TestMethod] + public void CssLAbsPositionTree() + { + doc.Clear(); + doc.Parse(@" +window { position: absolute; left: 130px; top: 40px; } +.statdisplay { layout: flow; width: 400px; height: 100px; } +.statpanel { height: 100px; position: absolute; left: 105px; width:295px; } +.levelstatus { position: absolute; top: 0; right: 0; width: 100px; height: 45px; } +.hppanel { position: absolute; top: 1em; left: 0px; } +"); + var window = new Window(); + var statdisplay = new Panel { Style = "statdisplay" }; + var ibFace = new ImageBox { Style = "face" }; + var lblName = new Label { Style = "name", Text = "Name" }; + var lblLevelLabel = new Label { Style = "levelLabel", Text = "Level" }; + var lblLevel = new Label { Style = "level" }; + var pbExp = new ProgressBar { Style = "expBar" }; + + var lblHPLabel = new Label { Style = "hplabel", Text = "HP" }; + var blHP = new Panel { Style = "hp" }; + + var lblMPLabel = new Label { Style = "mplabel", Text = "MP" }; + var blMP = new Panel { Style = "mp" }; + + var statpanel = new Panel { Style = "statpanel" }; + var pnlHP = new Panel { Style = "hppanel" }; + pnlHP.Children.AddRange(new Widget[] { lblHPLabel, blHP }); + + var pnlMP = new Panel { Style = "mppanel" }; + pnlMP.Children.AddRange(new Widget[] { lblMPLabel, blMP }); + + var levelstatus = new Panel { Style = "levelstatus" }; + levelstatus.Children.Add(lblLevelLabel, lblLevel, pbExp); + + statpanel.Children.Add(lblName, levelstatus, pnlHP, pnlMP); + statdisplay.Children.Add(ibFace, statpanel); + window.Children.Add(statdisplay); + + gui.Desktop.Children.Add(window); + + RedoLayout(); + + Assert.AreEqual(new Rectangle(130, 40, 400, 100), window.WidgetRect); + Assert.AreEqual(new Rectangle(0, 0, 96, 96), ibFace.WidgetRect); + Assert.AreEqual(new Rectangle(105, 0, 295, 100), statpanel.WidgetRect); + Assert.AreEqual(new Rectangle(195, 0, 100, 45), levelstatus.WidgetRect); + Assert.AreEqual(new Rectangle(0, 0, 32, 8), lblName.WidgetRect); + Assert.AreEqual(new Rectangle(0, 8, 16, 8), pnlHP.WidgetRect); + } + + [TestMethod] + public void CssLAbsolutePositioningBoxModel() + { + doc.Clear(); + doc.Parse(@" +window { position: absolute; left: 130px; top: 40px; width: 500px; height: 400px; border: 3px solid black; } +panel { position: absolute; top: 0px; right: 0px; width: 50px; height: 40px; } +.statpanel { height: 100px; position: absolute; left: 105px; width:295px; } +.levelstatus { position: absolute; top: 0; right: 0; width: 100px; height: 45px; } +.hppanel { position: absolute; top: 1em; left: 0px; } +"); + var window = new Window(); + var panel = new Panel(); + + window.Children.Add(panel); + gui.Desktop.Children.Add(window); + + RedoLayout(); + + Assert.AreEqual(new Rectangle(130, 40, 506, 406), window.WidgetRect); + Assert.AreEqual(new Rectangle(133, 43, 500, 400), window.ClientRect); + Assert.AreEqual(new Rectangle(450, 0, 50, 40), panel.WidgetRect); + } } } Modified: trunk/AgateLib.Tests/UnitTests/UserInterface/Widgets/ConversionTests.cs =================================================================== --- trunk/AgateLib.Tests/UnitTests/UserInterface/Widgets/ConversionTests.cs 2014-09-06 07:37:48 UTC (rev 1518) +++ trunk/AgateLib.Tests/UnitTests/UserInterface/Widgets/ConversionTests.cs 2014-09-07 22:49:41 UTC (rev 1519) @@ -5,25 +5,10 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using AgateLib.Testing.Fakes; namespace AgateLib.UserInterface.Widgets.Tests { - - class FakeRenderer : IGuiRenderer - { - public void Draw(Gui gui) - { - } - public void Update(Gui gui, double deltaTime) - { } - } - class FakeLayout : IGuiLayoutEngine - { - public void UpdateLayout(Gui gui) - { - } - } - [TestClass] public class ConversionTests { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2014-09-06 07:37:54
|
Revision: 1518 http://sourceforge.net/p/agate/code/1518 Author: kanato Date: 2014-09-06 07:37:48 +0000 (Sat, 06 Sep 2014) Log Message: ----------- Fix to not allow multiple windows to be active at the same time. Modified Paths: -------------- trunk/AgateLib/Diagnostics/AgateConsole.cs trunk/AgateLib/InputLib/InputHandlerList.cs trunk/AgateLib/UserInterface/Css/CssAdapter.cs trunk/AgateLib/UserInterface/Css/CssStyle.cs trunk/AgateLib/UserInterface/Css/Selectors/WidgetMatchParameters.cs trunk/AgateLib/UserInterface/Widgets/Gui.cs trunk/AgateLib/UserInterface/Widgets/Label.cs trunk/AgateLib/UserInterface/Widgets/Widget.cs trunk/AgateLib/UserInterface/Widgets/Window.cs trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssBindingTest.cs trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs Modified: trunk/AgateLib/Diagnostics/AgateConsole.cs =================================================================== --- trunk/AgateLib/Diagnostics/AgateConsole.cs 2014-09-06 01:50:57 UTC (rev 1517) +++ trunk/AgateLib/Diagnostics/AgateConsole.cs 2014-09-06 07:37:48 UTC (rev 1518) @@ -56,6 +56,11 @@ throw new AgateException("You must initalize the console before making it visible."); sInstance.mVisible = value; + + if (sInstance.mVisible) + Input.InputHandlers.BringToTop(sInstance); + else + Input.InputHandlers.SendToBack(sInstance); } } @@ -72,7 +77,7 @@ return; sInstance = Core.Factory.PlatformFactory.CreateConsole(); - InputLib.Input.InputHandlers.Add(sInstance); + Input.InputHandlers.Add(sInstance); PrivateInitialize(); } Modified: trunk/AgateLib/InputLib/InputHandlerList.cs =================================================================== --- trunk/AgateLib/InputLib/InputHandlerList.cs 2014-09-06 01:50:57 UTC (rev 1517) +++ trunk/AgateLib/InputLib/InputHandlerList.cs 2014-09-06 07:37:48 UTC (rev 1518) @@ -58,5 +58,23 @@ break; } } + + internal void BringToTop(IInputHandler handler) + { + if (mHandlers.Contains(handler) == false) + throw new InvalidOperationException("Cannot move a handler which is not registered."); + + mHandlers.Remove(handler); + mHandlers.Add(handler); + } + + internal void SendToBack(IInputHandler handler) + { + if (mHandlers.Contains(handler) == false) + throw new InvalidOperationException("Cannot move a handler which is not registered."); + + mHandlers.Remove(handler); + mHandlers.Insert(0, handler); + } } } Modified: trunk/AgateLib/UserInterface/Css/CssAdapter.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/CssAdapter.cs 2014-09-06 01:50:57 UTC (rev 1517) +++ trunk/AgateLib/UserInterface/Css/CssAdapter.cs 2014-09-06 07:37:48 UTC (rev 1518) @@ -216,15 +216,16 @@ style.Cache.CssClasses.Clear(); style.Cache.CssClasses.AddRange(style.MatchParameters.Classes); - control.LayoutDirty = false; + control.StyleDirty = false; } private bool NeedStyleRefresh(Widget control) { CssStyle style = mObjectStyles[control]; - if (control.LayoutDirty) return true; style.MatchParameters.UpdateWidgetProperties(); + if (control.StyleDirty) return true; + IEnumerable<string> classes = style.MatchParameters.Classes; if (style.Cache.Id != style.MatchParameters.Id) return true; Modified: trunk/AgateLib/UserInterface/Css/CssStyle.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/CssStyle.cs 2014-09-06 01:50:57 UTC (rev 1517) +++ trunk/AgateLib/UserInterface/Css/CssStyle.cs 2014-09-06 07:37:48 UTC (rev 1518) @@ -37,6 +37,7 @@ public CssStyle(Widget widget) { Widget = widget; + Data = new CssStyleData(); BoxModel = new CssBoxModel(); Modified: trunk/AgateLib/UserInterface/Css/Selectors/WidgetMatchParameters.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Selectors/WidgetMatchParameters.cs 2014-09-06 01:50:57 UTC (rev 1517) +++ trunk/AgateLib/UserInterface/Css/Selectors/WidgetMatchParameters.cs 2014-09-06 07:37:48 UTC (rev 1518) @@ -32,24 +32,55 @@ private CssPseudoClass GetPseudoClass(Widget control) { - if (control.MouseIn) - return CssPseudoClass.Hover; - if (control is Container) + if (InActiveWindow(control)) { - Container container = (Container)control; + if (control.MouseIn) + return CssPseudoClass.Hover; + if (control is Container) + { + Container container = (Container)control; - if (container.ChildHasMouseIn) - return CssPseudoClass.Hover; + if (container.ChildHasMouseIn) + return CssPseudoClass.Hover; + } + if (control is MenuItem) + { + MenuItem mnuit = (MenuItem)control; + + if (mnuit.Selected) + return CssPseudoClass.Selected; + } } - if (control is MenuItem) + + return CssPseudoClass.None; + } + + private bool InActiveWindow(Widget control) + { + var window = TopWindow(control); + + if (window == null) + return false; + + if (window.IsActive) + return true; + else + return false; + } + + private Window TopWindow(Widget control) + { + var retval = control; + + while (retval != null && retval.Parent != null) { - MenuItem mnuit = (MenuItem)control; + if (retval.Parent is Desktop) + return retval as Window; - if (mnuit.Selected) - return CssPseudoClass.Selected; + retval = retval.Parent; } - return CssPseudoClass.None; + return null; } private IEnumerable<string> GetCssClasses(Widget control) Modified: trunk/AgateLib/UserInterface/Widgets/Gui.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Gui.cs 2014-09-06 01:50:57 UTC (rev 1517) +++ trunk/AgateLib/UserInterface/Widgets/Gui.cs 2014-09-06 07:37:48 UTC (rev 1518) @@ -371,7 +371,6 @@ //} internal AgateLib.UserInterface.Css.Documents.CssDocument CssDocument { get; set; } - } class WindowList : IList<Window> Modified: trunk/AgateLib/UserInterface/Widgets/Label.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Label.cs 2014-09-06 01:50:57 UTC (rev 1517) +++ trunk/AgateLib/UserInterface/Widgets/Label.cs 2014-09-06 07:37:48 UTC (rev 1518) @@ -42,8 +42,13 @@ if (value == null) value = string.Empty; - mText = value.Replace("\r", ""); + value = value.Replace("\r", ""); + if (value == mText) + return; + LayoutDirty = true; + mText = value; + if (WrapText) { RewrapText(Width); Modified: trunk/AgateLib/UserInterface/Widgets/Widget.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Widget.cs 2014-09-06 01:50:57 UTC (rev 1517) +++ trunk/AgateLib/UserInterface/Widgets/Widget.cs 2014-09-06 07:37:48 UTC (rev 1518) @@ -37,6 +37,7 @@ private Color? mFontColor; private bool mEnabled = true; string mStyle = string.Empty; + bool mLayoutDirty; public Widget() { @@ -274,7 +275,16 @@ } } - public virtual bool LayoutDirty { get; set; } + public virtual bool LayoutDirty + { + get { return mLayoutDirty; } + set + { + mLayoutDirty = value; + StyleDirty = true; + } + } + internal bool StyleDirty { get; set; } protected virtual Gui MyGui { @@ -362,7 +372,7 @@ public bool TabStop { get; set; } protected bool AcceptFocus { get; set; } - + protected internal virtual Widget FindFocusWidget() { if (AcceptFocus) Modified: trunk/AgateLib/UserInterface/Widgets/Window.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/Window.cs 2014-09-06 01:50:57 UTC (rev 1517) +++ trunk/AgateLib/UserInterface/Widgets/Window.cs 2014-09-06 07:37:48 UTC (rev 1518) @@ -38,5 +38,16 @@ : base(contents) { } + + public bool IsActive + { + get + { + if (Parent == null) + return false; + + return ((Desktop)Parent).TopWindow == this; + } + } } } Modified: trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssBindingTest.cs =================================================================== --- trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssBindingTest.cs 2014-09-06 01:50:57 UTC (rev 1517) +++ trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssBindingTest.cs 2014-09-06 07:37:48 UTC (rev 1518) @@ -32,13 +32,24 @@ [TestMethod] public void SelectorMatching() { + Gui gui = new Gui(null, null); + Desktop desktop = new Desktop(gui); + Window window = new Window(); + desktop.Children.Add(window); + var label1 = new WidgetMatchParameters( new Label { Name = "label1" }); var noname = new WidgetMatchParameters(new Label { }); var hover = new WidgetMatchParameters( new Label { MouseIn = true }); + window.Children.Add(hover.Widget); + CssSelectorIndividual sel = new CssSelectorIndividual("label"); CssAdapter adapter = new CssAdapter(CssDocument.FromText("")); + label1.UpdateWidgetProperties(); + noname.UpdateWidgetProperties(); + hover.UpdateWidgetProperties(); + Assert.IsTrue(sel.Matches(adapter, label1), "Failed match test 1."); Assert.IsTrue(sel.Matches(adapter, noname), "Failed match test 2."); Assert.IsTrue(sel.Matches(adapter, hover), "Failed match test 3."); @@ -57,9 +68,13 @@ [TestMethod] public void PseudoClassMatching() { + Gui gui = new Gui(null, null); + Desktop desktop = new Desktop(gui); + Window wind = new Window(); + desktop.Children.Add(wind); + CssDocument doc = CssDocument.FromText("window:hover { padding: 8px; }"); CssAdapter adapter = new CssAdapter(doc); - Window wind = new Window(); wind.MouseIn = true; var style = adapter.GetStyle(wind); Modified: trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs =================================================================== --- trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs 2014-09-06 01:50:57 UTC (rev 1517) +++ trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs 2014-09-06 07:37:48 UTC (rev 1518) @@ -24,7 +24,7 @@ CssAdapter adapter; [TestInitialize] - public void Init() + public void CssLInit() { Core.Initialize(new FakeAgateFactory()); Core.InitAssetLocations(new AssetLocations()); @@ -47,11 +47,13 @@ "window { layout: column; margin: 6px; padding: 8px;} label { margin-left: 4px; } " + "window.fixed { position: fixed; right: 4px; bottom: 8px; margin: 14px; padding: 9px; border: 2px; } "+ "window.fixedleft { position: fixed; left: 4px; top: 8px; margin: 14px; padding: 9px; border: 2px; }"); + adapter = new CssAdapter(doc, ff); engine = new CssLayoutEngine(adapter); - gui = new Gui(new FakeRenderer(), engine); + gui = new Gui(new FakeRenderer(), engine); + Core.Initialize(new FakeAgateFactory()); Core.InitAssetLocations(new AssetLocations()); @@ -68,7 +70,7 @@ } [TestMethod] - public void BoxModel() + public void CssLBoxModel() { CssDocument doc = CssDocument.FromText("window { border: 5px solid black; padding: 10px; margin: 20px; }"); CssAdapter adapter = new CssAdapter(doc); @@ -80,7 +82,7 @@ } [TestMethod] - public void ColumnLayout() + public void CssLColumnLayout() { int fh = ff.FontHeight; @@ -99,7 +101,7 @@ [TestMethod] - public void FixedRightBottom() + public void CssLFixedRightBottom() { Window wind = new Window() { Style = "fixed" }; gui.Desktop.Children.Add(wind); @@ -111,7 +113,7 @@ } [TestMethod] - public void FixedTopLeft() + public void CssLFixedTopLeft() { Window wind = new Window() { Style = "fixedleft" }; gui.Desktop.Children.Add(wind); @@ -121,5 +123,62 @@ Assert.AreEqual(18, wind.WidgetRect.Left); Assert.AreEqual(22, wind.WidgetRect.Top); } + + [TestMethod] + public void CssLNestedContainers() + { + Window wind = new Window(); + Menu mnu = new Menu(); + Container c = new Container(); + ImageBox ib = new ImageBox(); + Label lbl1 = new Label("Test1"); + Label lbl2 = new Label("Test2"); + + c.Children.AddRange(new Widget[] { ib, lbl1, lbl2 }); + mnu.Children.Add(new MenuItem(c)); + wind.Children.Add(mnu); + + gui.Desktop.Children.Add(wind); + + RedoLayout(); + + Assert.AreEqual(40, ff.MeasureString(lbl1.Text).Width); + Assert.AreEqual(new Rectangle(100, 0, 40, 8), lbl1.WidgetRect); + Assert.AreEqual(new Rectangle(144, 0, 40, 8), lbl2.WidgetRect); + Assert.AreEqual(new Rectangle(0, 0, 96, 96), ib.WidgetRect); + } + [TestMethod] + public void CssLNestedContainersWithUpdate() + { + Window wind = new Window(); + Menu mnu = new Menu(); + Container c = new Container(); + ImageBox ib = new ImageBox(); + Label lbl1 = new Label("Test1"); + Label lbl2 = new Label("Test2"); + + c.Children.AddRange(new Widget[] { ib, lbl1, lbl2 }); + mnu.Children.Add(new MenuItem(c)); + wind.Children.Add(mnu); + + gui.Desktop.Children.Add(wind); + + RedoLayout(); + + Assert.AreEqual(40, ff.MeasureString(lbl1.Text).Width); + Assert.AreEqual(new Rectangle(100, 0, 40, 8), lbl1.WidgetRect); + Assert.AreEqual(new Rectangle(144, 0, 40, 8), lbl2.WidgetRect); + Assert.AreEqual(new Rectangle(0, 0, 96, 96), ib.WidgetRect); + + lbl1.Text = "Test1Test2Test3"; + + RedoLayout(); + + Assert.AreEqual(120, ff.MeasureString(lbl1.Text).Width); + Assert.AreEqual(new Rectangle(100, 0, 120, 8), lbl1.WidgetRect); + Assert.AreEqual(new Rectangle(224, 0, 40, 8), lbl2.WidgetRect); + Assert.AreEqual(new Rectangle(0, 0, 96, 96), ib.WidgetRect); + + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2014-09-06 01:51:06
|
Revision: 1517 http://sourceforge.net/p/agate/code/1517 Author: kanato Date: 2014-09-06 01:50:57 +0000 (Sat, 06 Sep 2014) Log Message: ----------- Make ProgressBar at least not crash. Modified Paths: -------------- trunk/AgateLib/UserInterface/Widgets/MenuItem.cs trunk/AgateLib/UserInterface/Widgets/ProgressBar.cs Modified: trunk/AgateLib/UserInterface/Widgets/MenuItem.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/MenuItem.cs 2014-09-06 00:53:36 UTC (rev 1516) +++ trunk/AgateLib/UserInterface/Widgets/MenuItem.cs 2014-09-06 01:50:57 UTC (rev 1517) @@ -65,7 +65,7 @@ get { return base.Parent; } set { - if (value is Menu == false) + if (value != null && value is Menu == false) throw new InvalidOperationException("Cannot add a menu item to a container which is not a menu."); base.Parent = value; Modified: trunk/AgateLib/UserInterface/Widgets/ProgressBar.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/ProgressBar.cs 2014-09-06 00:53:36 UTC (rev 1516) +++ trunk/AgateLib/UserInterface/Widgets/ProgressBar.cs 2014-09-06 01:50:57 UTC (rev 1517) @@ -27,25 +27,18 @@ { public class ProgressBar : Widget { - Surface mSurf; - Rectangle innerArea = new Rectangle(3, 3, 107, 2); - public int Value { get; set; } public int Max { get; set; } public Gradient Gradient { get; set; } public ProgressBar() { - mSurf = null;//= InterfaceRenderer.GetImage("meter"); - Gradient = new AgateLib.Geometry.Gradient(Color.White); - Height = mSurf.DisplayHeight; } internal override Size ComputeSize(int? minWidth, int? minHeight, int? maxWidth, int? maxHeight) { Size retval = new Size(); - retval.Height = mSurf.DisplayHeight; retval.Width = 40; return retval; @@ -56,21 +49,13 @@ Rectangle destRect = ClientToScreen( new Rectangle(X, Y, Width, Height)); - DrawSurface(destRect); - if (Max > 0) { double percentage = Value / (double)Max; - int maxBarWidth = Width - (mSurf.SurfaceWidth - innerArea.Width); + int maxBarWidth = Width; int width = (int)(percentage * maxBarWidth); - destRect.X += innerArea.X; - destRect.Y += innerArea.Y; - - destRect.Width = width; - destRect.Height = innerArea.Height; - var grad = new Gradient(Gradient.TopLeft); grad.TopRight = Gradient.Interpolate(width, 0); grad.BottomRight = grad.TopRight; @@ -78,38 +63,5 @@ Display.FillRect(destRect, grad); } } - - private void DrawSurface(Rectangle destRect) - { - Rectangle srcRect = new Rectangle(0, 0, mSurf.SurfaceWidth, mSurf.SurfaceHeight); - Rectangle innerSrcRect = innerArea; - Rectangle innerDestRect = destRect; - Surface surf = mSurf; - - innerDestRect.X += innerArea.X; - innerDestRect.Y += innerArea.Y; - innerDestRect.Width -= (srcRect.Width - innerSrcRect.Width); - innerDestRect.Height -= (srcRect.Height - innerSrcRect.Height); - - Rectangle src, dest; - - // left - src = Rectangle.FromLTRB(srcRect.Left, srcRect.Top, innerSrcRect.Left, srcRect.Bottom); - dest = Rectangle.FromLTRB(destRect.Left, destRect.Top, innerDestRect.Left, destRect.Bottom); - - surf.Draw(src, dest); - - // middle - src = Rectangle.FromLTRB(innerSrcRect.Left, srcRect.Top, innerSrcRect.Right, srcRect.Bottom); - dest = Rectangle.FromLTRB(innerDestRect.Left, destRect.Top, innerDestRect.Right, destRect.Bottom); - - surf.Draw(src, dest); - - // right - src = Rectangle.FromLTRB(innerSrcRect.Right, srcRect.Top, srcRect.Right, srcRect.Bottom); - dest = Rectangle.FromLTRB(innerDestRect.Right, destRect.Top, destRect.Right, destRect.Bottom); - - surf.Draw(src, dest); - } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2014-09-06 00:53:44
|
Revision: 1516 http://sourceforge.net/p/agate/code/1516 Author: kanato Date: 2014-09-06 00:53:36 +0000 (Sat, 06 Sep 2014) Log Message: ----------- Fixes and cleanup to Css interpreter. Modified Paths: -------------- trunk/AgateLib/AgateLib.csproj trunk/AgateLib/ApplicationModels/AgateAppModel.cs trunk/AgateLib/DisplayLib/ISurface.cs trunk/AgateLib/UserInterface/Css/Binders/CssTypeConverter.cs trunk/AgateLib/UserInterface/Css/CssAdapter.cs trunk/AgateLib/UserInterface/Css/CssRuleBlock.cs trunk/AgateLib/UserInterface/Css/CssStyle.cs trunk/AgateLib/UserInterface/Css/Documents/CssDocument.cs trunk/AgateLib/UserInterface/Css/Extensions.cs trunk/AgateLib/UserInterface/Css/ICssCanSelect.cs trunk/AgateLib/UserInterface/Css/Parser/CssParser.cs trunk/AgateLib/UserInterface/Css/Selectors/CssSelectorChain.cs trunk/AgateLib/UserInterface/Css/Selectors/ICssSelector.cs trunk/AgateLib.AgateSDL/Audio/SDL_Audio.cs trunk/AgateLib.Tests/UnitTests/AgateLib.Tests.UnitTests.csproj trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssTestBase.cs Added Paths: ----------- trunk/AgateLib/ApplicationModels/ArgumentEventArgs.cs trunk/AgateLib/DisplayLib/IDrawable.cs trunk/AgateLib/UserInterface/Css/Selectors/CssMediaIndividualSelector.cs trunk/AgateLib/UserInterface/Css/Selectors/CssMediaSelector.cs trunk/AgateLib/UserInterface/Css/Selectors/CssSelector.cs trunk/AgateLib/UserInterface/Css/Selectors/CssSelectorIndividual.cs trunk/AgateLib/UserInterface/Css/Selectors/ICssMediaSelector.cs trunk/AgateLib/UserInterface/Css/Selectors/WidgetMatchParameters.cs trunk/AgateLib/UserInterface/Widgets/ImageBox.cs trunk/AgateLib/UserInterface/Widgets/LabelImage.cs trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssAdapterTest.cs trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssBindingTest.cs trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssLayoutTest.cs trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssParseTest.cs Removed Paths: ------------- trunk/AgateLib/UserInterface/Css/Documents/CssMediaSelector.cs trunk/AgateLib/UserInterface/Css/Selectors/CssSelector.cs trunk/AgateLib/UserInterface/Css/Selectors/CssSelectorGroup.cs trunk/AgateLib/UserInterface/Widgets/ImageDisplay.cs trunk/AgateLib.Tests/UnitTests/UserInterface/Css/AdapterTest.cs trunk/AgateLib.Tests/UnitTests/UserInterface/Css/BindingTest.cs trunk/AgateLib.Tests/UnitTests/UserInterface/Css/LayoutTest.cs trunk/AgateLib.Tests/UnitTests/UserInterface/Css/ParseTest.cs Modified: trunk/AgateLib/AgateLib.csproj =================================================================== --- trunk/AgateLib/AgateLib.csproj 2014-09-05 07:02:24 UTC (rev 1515) +++ trunk/AgateLib/AgateLib.csproj 2014-09-06 00:53:36 UTC (rev 1516) @@ -48,6 +48,7 @@ <Compile Include="Algorithms\PathFinding\AStarNode.cs" /> <Compile Include="Algorithms\PathFinding\AStarState.cs" /> <Compile Include="Algorithms\Inverting.cs" /> + <Compile Include="ApplicationModels\ArgumentEventArgs.cs" /> <Compile Include="ApplicationModels\PassiveModelParameters.cs" /> <Compile Include="ApplicationModels\SceneModelParameters.cs" /> <Compile Include="ApplicationModels\SerialModelParameters.cs" /> @@ -508,12 +509,13 @@ <Compile Include="UserInterface\Css\Documents\CssBorder.cs" /> <Compile Include="UserInterface\Css\Documents\CssBorderImage.cs" /> <Compile Include="UserInterface\Css\Documents\CssBoxComponent.cs" /> + <Compile Include="UserInterface\Css\Selectors\CssMediaSelector.cs" /> <Compile Include="UserInterface\Css\Documents\PropertyEnums.cs" /> <Compile Include="UserInterface\Css\Documents\CssDistance.cs" /> <Compile Include="UserInterface\Css\Documents\CssDocument.cs" /> <Compile Include="UserInterface\Css\Documents\CssFont.cs" /> <Compile Include="UserInterface\Css\Documents\CssLayout.cs" /> - <Compile Include="UserInterface\Css\Documents\CssMediaSelector.cs" /> + <Compile Include="UserInterface\Css\Selectors\CssMediaIndividualSelector.cs" /> <Compile Include="UserInterface\Css\CssPseudoClass.cs" /> <Compile Include="UserInterface\Css\Documents\CssRectangle.cs" /> <Compile Include="UserInterface\Css\CssRuleBlock.cs" /> @@ -547,10 +549,12 @@ <Compile Include="UserInterface\Css\Rendering\Transitions\SlideTransition.cs" /> <Compile Include="UserInterface\Css\Rendering\Transitions\TransitionFactory.cs" /> <Compile Include="UserInterface\Css\Rendering\WidgetAnimator.cs" /> + <Compile Include="UserInterface\Css\Selectors\CssSelectorIndividual.cs" /> + <Compile Include="UserInterface\Css\Selectors\CssSelectorChain.cs" /> <Compile Include="UserInterface\Css\Selectors\CssSelector.cs" /> - <Compile Include="UserInterface\Css\Selectors\CssSelectorChain.cs" /> - <Compile Include="UserInterface\Css\Selectors\CssSelectorGroup.cs" /> + <Compile Include="UserInterface\Css\Selectors\ICssMediaSelector.cs" /> <Compile Include="UserInterface\Css\Selectors\ICssSelector.cs" /> + <Compile Include="UserInterface\Css\Selectors\WidgetMatchParameters.cs" /> <Compile Include="UserInterface\IAudioPlayer.cs" /> <Compile Include="UserInterface\ISurfaceProvider.cs" /> <Compile Include="UserInterface\Widgets\Container.cs" /> @@ -558,12 +562,14 @@ <Compile Include="UserInterface\Widgets\Gui.cs" /> <Compile Include="UserInterface\Widgets\GuiInput.cs" /> <Compile Include="UserInterface\Widgets\GuiSound.cs" /> + <Compile Include="DisplayLib\IDrawable.cs" /> <Compile Include="UserInterface\Widgets\IGuiLayoutEngine.cs" /> <Compile Include="UserInterface\Widgets\IGuiRenderer.cs" /> - <Compile Include="UserInterface\Widgets\ImageDisplay.cs" /> + <Compile Include="UserInterface\Widgets\ImageBox.cs" /> <Compile Include="UserInterface\Widgets\InputMap.cs" /> <Compile Include="UserInterface\Widgets\KeyboardEventArgs.cs" /> <Compile Include="UserInterface\Widgets\Label.cs" /> + <Compile Include="UserInterface\Widgets\LabelImage.cs" /> <Compile Include="UserInterface\Widgets\Menu.cs" /> <Compile Include="UserInterface\Widgets\MenuItem.cs" /> <Compile Include="UserInterface\Widgets\MouseEventArgs.cs" /> Modified: trunk/AgateLib/ApplicationModels/AgateAppModel.cs =================================================================== --- trunk/AgateLib/ApplicationModels/AgateAppModel.cs 2014-09-05 07:02:24 UTC (rev 1515) +++ trunk/AgateLib/ApplicationModels/AgateAppModel.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -215,10 +215,30 @@ /// </remarks> protected virtual void ProcessCustomArgument(string arg, IList<string> parm) { - Log.WriteLine("Unknown command line argument:"); - Log.WriteLine(" {0} {1}", arg, string.Join(" ", parm)); + OnUnhandledArgument(arg, parm); } + private void OnUnhandledArgument(string arg, IList<string> parm) + { + bool handled = false; + if (UnhandledArgument != null) + { + var args = new ArgumentEventArgs(arg, parm); + + UnhandledArgument(this, args); + + handled = args.Handled; + } + + if (handled == false) + { + Log.WriteLine("Unknown command line argument:"); + Log.WriteLine(" {0} {1}", arg, string.Join(" ", parm)); + } + } + + public event EventHandler<ArgumentEventArgs> UnhandledArgument; + protected void PrerunInitialization() { SetPlatformEmulation(); Added: trunk/AgateLib/ApplicationModels/ArgumentEventArgs.cs =================================================================== --- trunk/AgateLib/ApplicationModels/ArgumentEventArgs.cs (rev 0) +++ trunk/AgateLib/ApplicationModels/ArgumentEventArgs.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.ApplicationModels +{ + public class ArgumentEventArgs : EventArgs + { + private string arg; + private IList<string> parm; + + public ArgumentEventArgs(string arg, IList<string> parm) + { + // TODO: Complete member initialization + this.arg = arg; + this.parm = parm; + } + + public string Argument { get { return arg; } } + public IEnumerable<string> Parameters { get { return parm; } } + public bool Handled { get; set; } + } +} Added: trunk/AgateLib/DisplayLib/IDrawable.cs =================================================================== --- trunk/AgateLib/DisplayLib/IDrawable.cs (rev 0) +++ trunk/AgateLib/DisplayLib/IDrawable.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -0,0 +1,15 @@ +using AgateLib.Geometry; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AgateLib.DisplayLib +{ + public interface IDrawable + { + void Draw(Point point); + + Size DisplaySize { get; set; } + } +} Modified: trunk/AgateLib/DisplayLib/ISurface.cs =================================================================== --- trunk/AgateLib/DisplayLib/ISurface.cs 2014-09-05 07:02:24 UTC (rev 1515) +++ trunk/AgateLib/DisplayLib/ISurface.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -24,7 +24,7 @@ /// <summary> /// Public Surface interface. /// </summary> - public interface ISurface : IDisposable + public interface ISurface : IDisposable, IDrawable { /// <summary> /// Gets or sets the alpha value for the surface. Modified: trunk/AgateLib/UserInterface/Css/Binders/CssTypeConverter.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Binders/CssTypeConverter.cs 2014-09-05 07:02:24 UTC (rev 1515) +++ trunk/AgateLib/UserInterface/Css/Binders/CssTypeConverter.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -53,8 +53,12 @@ return true; } - if (value.StartsWith("#")) + if (value == "none") { + return true; + } + else if (value.StartsWith("#")) + { string subtext = value.Substring(1); if (subtext.Length == 3) Modified: trunk/AgateLib/UserInterface/Css/CssAdapter.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/CssAdapter.cs 2014-09-05 07:02:24 UTC (rev 1515) +++ trunk/AgateLib/UserInterface/Css/CssAdapter.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -211,15 +211,11 @@ var control = style.Widget; style.Cache.Id = control.Name; - style.Cache.PseudoClass = GetPseudoClass(control); + style.Cache.PseudoClass = style.MatchParameters.PseudoClass; - var classes = GetCssClasses(style); - style.Cache.CssClasses.Clear(); + style.Cache.CssClasses.AddRange(style.MatchParameters.Classes); - if (classes != null) - style.Cache.CssClasses.AddRange(classes); - control.LayoutDirty = false; } private bool NeedStyleRefresh(Widget control) @@ -227,12 +223,12 @@ CssStyle style = mObjectStyles[control]; if (control.LayoutDirty) return true; + style.MatchParameters.UpdateWidgetProperties(); - string id = control.Name; - IEnumerable<string> classes = GetCssClasses(style); + IEnumerable<string> classes = style.MatchParameters.Classes; - if (style.Cache.Id != id) return true; - if (style.Cache.PseudoClass != GetPseudoClass(control)) return true; + if (style.Cache.Id != style.MatchParameters.Id) return true; + if (style.Cache.PseudoClass != style.MatchParameters.PseudoClass) return true; if (classes != null) { if (style.Cache.CssClasses.All(x => classes.Contains(x)) == false) return true; @@ -250,7 +246,6 @@ return; mDefaultStyles[style.Widget.GetType()].InheritParentProperties(style, GetStyle(style.Widget.Parent)); - } private void ReportError(string p) @@ -267,15 +262,13 @@ private void AssignApplicableBlocks(CssStyle style) { - var control = style.Widget; - string id = control.Name; - IEnumerable<string> classes = GetCssClasses(style); + style.MatchParameters.UpdateWidgetProperties(); foreach (var medium in ApplicableMedia) { foreach (var block in medium.RuleBlocks) { - if (BlockAppliesTo(block, control, id, classes)) + if (BlockAppliesTo(block, style.MatchParameters)) { if (style.AppliedBlocks.Contains(block) == false) { @@ -293,60 +286,23 @@ } } - private bool BlockAppliesTo(CssRuleBlock block, Widget control, string id, - IEnumerable<string> classes) + private bool BlockAppliesTo(CssRuleBlock block, WidgetMatchParameters wmp) { - CssPseudoClass pseudoClass = GetPseudoClass(control); - foreach (var selector in block.Selector.IndividualSelectors) { - if (SelectorAppliesTo(selector, control, id, pseudoClass, classes)) + if (SelectorAppliesTo(selector, wmp)) return true; } return false; } - private CssPseudoClass GetPseudoClass(Widget control) - { - if (control.MouseIn) - return CssPseudoClass.Hover; - if (control is Container) - { - Container container = (Container)control; - if (container.ChildHasMouseIn) - return CssPseudoClass.Hover; - } - if (control is MenuItem) - { - MenuItem mnuit = (MenuItem)control; - - if (mnuit.Selected) - return CssPseudoClass.Selected; - } - - return CssPseudoClass.None; - } - - private bool SelectorAppliesTo(ICssSelector selector, Widget control, - string id, CssPseudoClass pseudoClass, IEnumerable<string> classes) + private bool SelectorAppliesTo(ICssSelector selector, WidgetMatchParameters wmp) { - return selector.Matches(control, id, pseudoClass, classes); + return selector.Matches(this, wmp); } - private IEnumerable<string> GetCssClasses(CssStyle style) - { - Widget control = style.Widget; - - if (control.Style != style.ObjectClass) - { - style.ObjectClass = control.Style; - } - - return style.SplitClasses; - } - public CssMediumInfo MediumInfo { get; set; } public IEnumerable<CssMediaSelector> ApplicableMedia @@ -357,17 +313,17 @@ foreach (var medium in Document.Media) { - if (MediaSelectorApplies(medium.Selector, MediumInfo)) + if (MediaSelectorApplies(medium, MediumInfo)) yield return medium; } } } - private bool MediaSelectorApplies(CssSelectorGroup selectorGroup, CssMediumInfo medium) + private bool MediaSelectorApplies(CssMediaSelector selectorGroup, CssMediumInfo medium) { foreach (var sel in selectorGroup.IndividualSelectors) { - if (sel.Matches(medium.MediaType.ToString(), null, CssPseudoClass.None, null)) + if (sel.Matches(medium.MediaType.ToString())) return true; } Modified: trunk/AgateLib/UserInterface/Css/CssRuleBlock.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/CssRuleBlock.cs 2014-09-05 07:02:24 UTC (rev 1515) +++ trunk/AgateLib/UserInterface/Css/CssRuleBlock.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -41,7 +41,7 @@ public Dictionary<string, Binding> Bindings { get; private set; } public Dictionary<string, string> Properties { get; private set; } - public CssSelectorGroup Selector { get; set; } + public CssSelector Selector { get; set; } public override string ToString() { Modified: trunk/AgateLib/UserInterface/Css/CssStyle.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/CssStyle.cs 2014-09-05 07:02:24 UTC (rev 1515) +++ trunk/AgateLib/UserInterface/Css/CssStyle.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -19,6 +19,7 @@ using AgateLib.UserInterface.Css.Cache; using AgateLib.UserInterface.Css.Layout; using AgateLib.UserInterface.Css.Rendering; +using AgateLib.UserInterface.Css.Selectors; using AgateLib.UserInterface.Widgets; using System; using System.Collections.Generic; @@ -44,6 +45,8 @@ Cache = new StyleCache(); Animator = new WidgetAnimator(this); + + MatchParameters = new WidgetMatchParameters(widget); } public CssStyleData Data { get; set; } @@ -52,24 +55,6 @@ public Widget Widget { get; set; } - public string ObjectClass - { - get { return mClassValue; } - set - { - if (value == null) throw new ArgumentNullException(); - if (mClassValue.Equals(value, StringComparison.OrdinalIgnoreCase)) - return; - - mClassValue = value.ToLowerInvariant(); - mSplitClasses = ObjectClass - .Split(Extensions.WhiteSpace, StringSplitOptions.RemoveEmptyEntries) - .ToList(); - - mSplitClasses.Sort(); - } - } - public IEnumerable<string> SplitClasses { get { return mSplitClasses; } } public List<CssRuleBlock> AppliedBlocks { get; private set; } @@ -85,5 +70,7 @@ } public AgateLib.DisplayLib.Font Font { get; set; } + + public WidgetMatchParameters MatchParameters { get; private set; } } } Modified: trunk/AgateLib/UserInterface/Css/Documents/CssDocument.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Documents/CssDocument.cs 2014-09-05 07:02:24 UTC (rev 1515) +++ trunk/AgateLib/UserInterface/Css/Documents/CssDocument.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -17,6 +17,7 @@ // Contributor(s): Erik Ylvisaker // using AgateLib.UserInterface.Css.Binders; +using AgateLib.UserInterface.Css.Selectors; using System; using System.Collections.Generic; using System.Linq; @@ -31,7 +32,7 @@ public CssDocument() { - var defaultMedium = new CssMediaSelector { Selector = "all" }; + var defaultMedium = new CssMediaSelector("all"); Media.Add(defaultMedium); } public static CssDocument Load(string filename) @@ -56,6 +57,6 @@ public List<CssMediaSelector> Media { get { return mMedia; } } - public CssMediaSelector DefaultMedium { get { return mMedia.First(x => x.Selector.Text == "all"); } } + public CssMediaSelector DefaultMedium { get { return mMedia.First(); } } } } Deleted: trunk/AgateLib/UserInterface/Css/Documents/CssMediaSelector.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Documents/CssMediaSelector.cs 2014-09-05 07:02:24 UTC (rev 1515) +++ trunk/AgateLib/UserInterface/Css/Documents/CssMediaSelector.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -1,38 +0,0 @@ -// The contents of this file are subject to the Mozilla Public License -// Version 1.1 (the "License"); you may not use this file except in -// compliance with the License. You may obtain a copy of the License at -// http://www.mozilla.org/MPL/ -// -// Software distributed under the License is distributed on an "AS IS" -// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -// License for the specific language governing rights and limitations -// under the License. -// -// The Original Code is AgateLib. -// -// The Initial Developer of the Original Code is Erik Ylvisaker. -// Portions created by Erik Ylvisaker are Copyright (C) 2006-2014. -// All Rights Reserved. -// -// Contributor(s): Erik Ylvisaker -// -using AgateLib.UserInterface.Css.Selectors; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AgateLib.UserInterface.Css -{ - public class CssMediaSelector : ICssCanSelect - { - public CssMediaSelector() - { - RuleBlocks = new List<CssRuleBlock>(); - } - - public CssSelectorGroup Selector { get;set;} - public List<CssRuleBlock> RuleBlocks { get; private set; } - } -} Modified: trunk/AgateLib/UserInterface/Css/Extensions.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Extensions.cs 2014-09-05 07:02:24 UTC (rev 1515) +++ trunk/AgateLib/UserInterface/Css/Extensions.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -38,10 +38,14 @@ throw new Exception("the value is not found in the dictionary"); } - public static T FindExactMatch<T>(this IEnumerable<T> list, CssSelectorGroup selector) where T : ICssCanSelect + public static CssRuleBlock FindExactMatch(this IEnumerable<CssRuleBlock> list, CssSelector selector) { return list.SingleOrDefault(x => x.Selector.Equals(selector)); } + public static CssMediaSelector FindExactMatch(this IEnumerable<CssMediaSelector> list, CssMediaSelector selector) + { + return list.SingleOrDefault(x => x.Equals(selector)); + } internal static readonly char[] WhiteSpace = new char[] { ' ', '\r', '\n', '\t' }; } Modified: trunk/AgateLib/UserInterface/Css/ICssCanSelect.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/ICssCanSelect.cs 2014-09-05 07:02:24 UTC (rev 1515) +++ trunk/AgateLib/UserInterface/Css/ICssCanSelect.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -27,6 +27,6 @@ { public interface ICssCanSelect { - CssSelectorGroup Selector { get; set; } + CssSelector Selector { get; set; } } } Modified: trunk/AgateLib/UserInterface/Css/Parser/CssParser.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Parser/CssParser.cs 2014-09-05 07:02:24 UTC (rev 1515) +++ trunk/AgateLib/UserInterface/Css/Parser/CssParser.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -42,7 +42,6 @@ int index; CssMediaSelector defaultMedium; - CssMediaSelector currentMedium; CssRuleBlock currentBlock; @@ -153,7 +152,7 @@ private void ParseBlock(string token) { - CssSelectorGroup selector = ReadSelector(token); + CssSelector selector = ReadSelector(token); currentBlock = currentMedium.RuleBlocks.FindExactMatch(selector); @@ -172,13 +171,13 @@ { if (rule.StartsWith("@media")) { - CssSelectorGroup selector = ReadSelector(); + CssMediaSelector selector = ReadMediaSelector(); currentMedium = target.Media.FindExactMatch(selector); if (currentMedium == null) { - currentMedium = new CssMediaSelector { Selector = selector }; + currentMedium = selector; target.Media.Add(currentMedium); } @@ -188,12 +187,17 @@ } } - private CssSelectorGroup ReadSelector(string startText = "") + private CssSelector ReadSelector(string startText = "") { - return new CssSelectorGroup(ReadUntilToken(startText, CssTokenType.BlockOpen)); + return new CssSelector(ReadUntilToken(startText, CssTokenType.BlockOpen)); } + private CssMediaSelector ReadMediaSelector(string startText = "") + { + return new CssMediaSelector(ReadUntilToken(startText, CssTokenType.BlockOpen)); + } + private string ReadPropertyName(string startText = "") { return ReadUntilToken(startText, CssTokenType.Colon); Copied: trunk/AgateLib/UserInterface/Css/Selectors/CssMediaIndividualSelector.cs (from rev 1515, trunk/AgateLib/UserInterface/Css/Documents/CssMediaSelector.cs) =================================================================== --- trunk/AgateLib/UserInterface/Css/Selectors/CssMediaIndividualSelector.cs (rev 0) +++ trunk/AgateLib/UserInterface/Css/Selectors/CssMediaIndividualSelector.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -0,0 +1,56 @@ +// The contents of this file are subject to the Mozilla Public License +// Version 1.1 (the "License"); you may not use this file except in +// compliance with the License. You may obtain a copy of the License at +// http://www.mozilla.org/MPL/ +// +// Software distributed under the License is distributed on an "AS IS" +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +// License for the specific language governing rights and limitations +// under the License. +// +// The Original Code is AgateLib. +// +// The Initial Developer of the Original Code is Erik Ylvisaker. +// Portions created by Erik Ylvisaker are Copyright (C) 2006-2014. +// All Rights Reserved. +// +// Contributor(s): Erik Ylvisaker +// +using AgateLib.UserInterface.Css; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.UserInterface.Css.Selectors +{ + public class CssMediaIndividualSelector : ICssMediaSelector + { + public CssMediaIndividualSelector(string text) + { + Text = text.ToLowerInvariant(); + Parse(); + } + + private void Parse() + { + } + + public CssMediaSelector Selector { get; set; } + + public string Text { get; set; } + + public bool Matches(string type) + { + if (Text == "all") + return true; + + if (Text == type) + return true; + + + return false; + } + } +} Added: trunk/AgateLib/UserInterface/Css/Selectors/CssMediaSelector.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Selectors/CssMediaSelector.cs (rev 0) +++ trunk/AgateLib/UserInterface/Css/Selectors/CssMediaSelector.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AgateLib.UserInterface.Css.Selectors +{ + public class CssMediaSelector : IEquatable<CssMediaSelector> + { + public static implicit operator CssMediaSelector(string text) + { + return new CssMediaSelector { Text = text }; + } + + string mText; + static readonly char[] comma = new char[] { ',' }; + + public CssMediaSelector() + { + RuleBlocks = new List<CssRuleBlock>(); + } + public CssMediaSelector(string text) + :this() + { + Text = text; + } + + public string Text + { + get { return mText; } + set + { + mText = value; + + IndividualSelectors = mText + .Split(comma, StringSplitOptions.RemoveEmptyEntries) + .Select(x => CreateSelector(x.Trim())); + } + } + + private ICssMediaSelector CreateSelector(string text) + { + if (text.Contains(" ") || text.Contains(">")) + { + throw new NotImplementedException(); + } + else + return new CssMediaIndividualSelector(text); + } + + public IEnumerable<ICssMediaSelector> IndividualSelectors { get; private set; } + + public bool Equals(CssMediaSelector other) + { + return Text.Equals(other.Text, StringComparison.Ordinal); + } + public override bool Equals(object obj) + { + if (obj is CssMediaSelector) + return Equals((CssMediaSelector)obj); + + return false; + } + public override int GetHashCode() + { + return Text.GetHashCode(); + } + + public override string ToString() + { + return Text; + } + + public List<CssRuleBlock> RuleBlocks { get; private set; } + } +} Deleted: trunk/AgateLib/UserInterface/Css/Selectors/CssSelector.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Selectors/CssSelector.cs 2014-09-05 07:02:24 UTC (rev 1515) +++ trunk/AgateLib/UserInterface/Css/Selectors/CssSelector.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -1,142 +0,0 @@ -// The contents of this file are subject to the Mozilla Public License -// Version 1.1 (the "License"); you may not use this file except in -// compliance with the License. You may obtain a copy of the License at -// http://www.mozilla.org/MPL/ -// -// Software distributed under the License is distributed on an "AS IS" -// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -// License for the specific language governing rights and limitations -// under the License. -// -// The Original Code is AgateLib. -// -// The Initial Developer of the Original Code is Erik Ylvisaker. -// Portions created by Erik Ylvisaker are Copyright (C) 2006-2014. -// All Rights Reserved. -// -// Contributor(s): Erik Ylvisaker -// -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AgateLib.UserInterface.Css.Selectors -{ - public class CssSelector : ICssSelector - { - List<string> classes = new List<string>(); - - public CssSelector(string text) - { - Text = text.ToLowerInvariant(); - - Parse(); - } - - private void Parse() - { - if (Text.Contains(":")) - { - try - { - PseudoClass = (CssPseudoClass)Enum.Parse(typeof(CssPseudoClass), CutIdentifier(Text.IndexOf(":") + 1), true); - } - catch(Exception) - { - - } - } - if (Text.Contains("#")) - { - Id = CutIdentifier(Text.IndexOf('#') + 1); - } - - int dot = Text.IndexOf('.'); - while (dot >= 0) - { - var cls = CutIdentifier(dot + 1); - - if (cls != null) - classes.Add(cls); - - dot = Text.IndexOf('.', dot + 1); - } - - ObjectType = CutIdentifier(0); - - classes.Sort(); - } - - private string CutIdentifier(int start) - { - int nextToken = FindNextToken(".#:", start); - - if (nextToken == start) - return null; - - if (nextToken == -1) - return Text.Substring(start); - - return Text.Substring(start, nextToken - start); - } - - private int FindNextToken(string tokens, int start) - { - int retval = int.MaxValue; - - for(int i = 0; i < tokens.Length; i++) - { - int current = Text.IndexOf(tokens[i], start); - - if (current == -1) - continue; - - if (current < retval) - retval = current; - } - - if (retval == int.MaxValue) - return -1; - - return retval; - } - - public string Text { get; private set; } - - public string ObjectType { get; private set; } - public string Id { get; private set; } - public IList<string> CssClasses { get { return classes; } } - public CssPseudoClass PseudoClass { get; private set; } - - public bool Matches(string typename, string id, CssPseudoClass pc, IEnumerable<string> classes) - { - if (ObjectType != null && - ObjectType.Equals(typename, StringComparison.OrdinalIgnoreCase) - == false) - { - return false; - } - - if (PseudoClass != CssPseudoClass.None && PseudoClass != pc) - return false; - - if (Id != null) - { - if (Id.Equals(id, StringComparison.OrdinalIgnoreCase)) - return true; - else - return false; - } - - foreach (var cls in CssClasses) - { - if (classes.Contains(cls) == false) - return false; - } - - return true; - } - } -} Copied: trunk/AgateLib/UserInterface/Css/Selectors/CssSelector.cs (from rev 1515, trunk/AgateLib/UserInterface/Css/Selectors/CssSelectorGroup.cs) =================================================================== --- trunk/AgateLib/UserInterface/Css/Selectors/CssSelector.cs (rev 0) +++ trunk/AgateLib/UserInterface/Css/Selectors/CssSelector.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -0,0 +1,88 @@ +// The contents of this file are subject to the Mozilla Public License +// Version 1.1 (the "License"); you may not use this file except in +// compliance with the License. You may obtain a copy of the License at +// http://www.mozilla.org/MPL/ +// +// Software distributed under the License is distributed on an "AS IS" +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +// License for the specific language governing rights and limitations +// under the License. +// +// The Original Code is AgateLib. +// +// The Initial Developer of the Original Code is Erik Ylvisaker. +// Portions created by Erik Ylvisaker are Copyright (C) 2006-2014. +// All Rights Reserved. +// +// Contributor(s): Erik Ylvisaker +// +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.UserInterface.Css.Selectors +{ + public class CssSelector : IEquatable<CssSelector> + { + string mText; + static readonly char[] comma = new char[] { ',' }; + + public CssSelector() { } + public CssSelector(string text) + { + Text = text; + } + public static implicit operator CssSelector(string text) + { + return new CssSelector { Text = text }; + } + + public string Text + { + get { return mText; } + set + { + mText = value; + + IndividualSelectors = mText + .Split(comma, StringSplitOptions.RemoveEmptyEntries) + .Select(x => CreateSelector(x.Trim())); + } + } + + private ICssSelector CreateSelector(string text) + { + if (text.Contains(" ") || text.Contains(">")) + { + return new CssSelectorChain(text); + } + else + return new CssSelectorIndividual(text); + } + + public IEnumerable<ICssSelector> IndividualSelectors { get; private set; } + + public bool Equals(CssSelector other) + { + return Text.Equals(other.Text, StringComparison.Ordinal); + } + public override bool Equals(object obj) + { + if (obj is CssSelector) + return Equals((CssSelector)obj); + + return false; + } + public override int GetHashCode() + { + return Text.GetHashCode(); + } + + public override string ToString() + { + return Text; + } + } +} Modified: trunk/AgateLib/UserInterface/Css/Selectors/CssSelectorChain.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Selectors/CssSelectorChain.cs 2014-09-05 07:02:24 UTC (rev 1515) +++ trunk/AgateLib/UserInterface/Css/Selectors/CssSelectorChain.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -35,23 +35,39 @@ mSelectors.AddRange(text .Split(Extensions.WhiteSpace, StringSplitOptions.RemoveEmptyEntries) - .Select(x => new CssSelector(x))); + .Select(x => new CssSelectorIndividual(x))); } public string Text { get; private set; } public IEnumerable<ICssSelector> Selectors { get { return mSelectors; } } - public bool Matches(string typename, string id, CssPseudoClass pc, IEnumerable<string> classes) + public bool Matches(CssAdapter adapter, WidgetMatchParameters wmp) { - //for (int i = mSelectors.Count - 1; i >= 0; i--) - //{ - // var sel = mSelectors[i]; + // last selector must match + if (mSelectors.Last().Matches(adapter, wmp) == false) + return false; - // if (sel.Matches(control, id, classes) == false) - //} - return false; - throw new NotImplementedException(); + var ancestor = wmp.Widget; + CssStyle ancestorStyle; + + for (int i = mSelectors.Count - 2; i >= 0; i--) + { + var selector = mSelectors[i]; + + do + { + ancestor = ancestor.Parent; + + if (ancestor == null) + return false; + + ancestorStyle = adapter.GetStyle(ancestor); + + } while (selector.Matches(adapter, ancestorStyle.MatchParameters) == false); + } + + return true; } } } Deleted: trunk/AgateLib/UserInterface/Css/Selectors/CssSelectorGroup.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Selectors/CssSelectorGroup.cs 2014-09-05 07:02:24 UTC (rev 1515) +++ trunk/AgateLib/UserInterface/Css/Selectors/CssSelectorGroup.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -1,77 +0,0 @@ -// The contents of this file are subject to the Mozilla Public License -// Version 1.1 (the "License"); you may not use this file except in -// compliance with the License. You may obtain a copy of the License at -// http://www.mozilla.org/MPL/ -// -// Software distributed under the License is distributed on an "AS IS" -// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -// License for the specific language governing rights and limitations -// under the License. -// -// The Original Code is AgateLib. -// -// The Initial Developer of the Original Code is Erik Ylvisaker. -// Portions created by Erik Ylvisaker are Copyright (C) 2006-2014. -// All Rights Reserved. -// -// Contributor(s): Erik Ylvisaker -// -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AgateLib.UserInterface.Css.Selectors -{ - public class CssSelectorGroup : IEquatable<CssSelectorGroup> - { - string mText; - static readonly char[] comma = new char[] { ',' }; - - public CssSelectorGroup() { } - public CssSelectorGroup(string text) - { - Text = text; - } - public static implicit operator CssSelectorGroup(string text) - { - return new CssSelectorGroup { Text = text }; - } - - public string Text - { - get { return mText; } - set - { - mText = value; - - IndividualSelectors = mText - .Split(comma, StringSplitOptions.RemoveEmptyEntries) - .Select(x => CreateSelector(x.Trim())); - } - } - - private ICssSelector CreateSelector(string text) - { - if (text.Contains(" ")) - { - return new CssSelectorChain(text); - } - else - return new CssSelector(text); - } - - public IEnumerable<ICssSelector> IndividualSelectors { get; private set; } - - public bool Equals(CssSelectorGroup other) - { - return Text.Equals(other.Text, StringComparison.Ordinal); - } - - public override string ToString() - { - return Text; - } - } -} Copied: trunk/AgateLib/UserInterface/Css/Selectors/CssSelectorIndividual.cs (from rev 1515, trunk/AgateLib/UserInterface/Css/Selectors/CssSelector.cs) =================================================================== --- trunk/AgateLib/UserInterface/Css/Selectors/CssSelectorIndividual.cs (rev 0) +++ trunk/AgateLib/UserInterface/Css/Selectors/CssSelectorIndividual.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -0,0 +1,144 @@ +using AgateLib.UserInterface.Widgets; +// The contents of this file are subject to the Mozilla Public License +// Version 1.1 (the "License"); you may not use this file except in +// compliance with the License. You may obtain a copy of the License at +// http://www.mozilla.org/MPL/ +// +// Software distributed under the License is distributed on an "AS IS" +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +// License for the specific language governing rights and limitations +// under the License. +// +// The Original Code is AgateLib. +// +// The Initial Developer of the Original Code is Erik Ylvisaker. +// Portions created by Erik Ylvisaker are Copyright (C) 2006-2014. +// All Rights Reserved. +// +// Contributor(s): Erik Ylvisaker +// +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.UserInterface.Css.Selectors +{ + public class CssSelectorIndividual : ICssSelector + { + List<string> classes = new List<string>(); + + public CssSelectorIndividual(string text) + { + Text = text.ToLowerInvariant(); + + Parse(); + } + + private void Parse() + { + if (Text.Contains(":")) + { + try + { + PseudoClass = (CssPseudoClass)Enum.Parse(typeof(CssPseudoClass), CutIdentifier(Text.IndexOf(":") + 1), true); + } + catch(Exception) + { + + } + } + if (Text.Contains("#")) + { + Id = CutIdentifier(Text.IndexOf('#') + 1); + } + + int dot = Text.IndexOf('.'); + while (dot >= 0) + { + var cls = CutIdentifier(dot + 1); + + if (cls != null) + classes.Add(cls); + + dot = Text.IndexOf('.', dot + 1); + } + + ObjectType = CutIdentifier(0); + + classes.Sort(); + } + + private string CutIdentifier(int start) + { + int nextToken = FindNextToken(".#:", start); + + if (nextToken == start) + return null; + + if (nextToken == -1) + return Text.Substring(start); + + return Text.Substring(start, nextToken - start); + } + + private int FindNextToken(string tokens, int start) + { + int retval = int.MaxValue; + + for(int i = 0; i < tokens.Length; i++) + { + int current = Text.IndexOf(tokens[i], start); + + if (current == -1) + continue; + + if (current < retval) + retval = current; + } + + if (retval == int.MaxValue) + return -1; + + return retval; + } + + public string Text { get; private set; } + + public string ObjectType { get; private set; } + public string Id { get; private set; } + public IList<string> CssClasses { get { return classes; } } + public CssPseudoClass PseudoClass { get; private set; } + + public bool Matches(CssAdapter adapter, WidgetMatchParameters wmp) + { + var typename = wmp.TypeName; + if (ObjectType != null && + ObjectType.Equals(typename, StringComparison.OrdinalIgnoreCase) + == false) + { + return false; + } + + if (PseudoClass != CssPseudoClass.None && PseudoClass != wmp.PseudoClass) + return false; + + if (Id != null) + { + if (Id.Equals(wmp.Id, StringComparison.OrdinalIgnoreCase)) + return true; + else + return false; + } + + foreach (var cls in CssClasses) + { + if (wmp.Classes.Contains(cls) == false) + return false; + } + + return true; + } + } +} Added: trunk/AgateLib/UserInterface/Css/Selectors/ICssMediaSelector.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Selectors/ICssMediaSelector.cs (rev 0) +++ trunk/AgateLib/UserInterface/Css/Selectors/ICssMediaSelector.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.UserInterface.Css.Selectors +{ + public interface ICssMediaSelector + { + bool Matches(string type); + } +} Modified: trunk/AgateLib/UserInterface/Css/Selectors/ICssSelector.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Selectors/ICssSelector.cs 2014-09-05 07:02:24 UTC (rev 1515) +++ trunk/AgateLib/UserInterface/Css/Selectors/ICssSelector.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -27,14 +27,6 @@ { public interface ICssSelector { - bool Matches(string type, string id, CssPseudoClass pseudoClass, IEnumerable<string> classes); + bool Matches(CssAdapter adapter, WidgetMatchParameters parameters); } - - public static class SelectorExtensions - { - public static bool Matches(this ICssSelector selector, Widget widget, string id, CssPseudoClass pseudoClass, IEnumerable<string> classes) - { - return selector.Matches(widget.GetType().Name, id, pseudoClass, classes); - } - } } Added: trunk/AgateLib/UserInterface/Css/Selectors/WidgetMatchParameters.cs =================================================================== --- trunk/AgateLib/UserInterface/Css/Selectors/WidgetMatchParameters.cs (rev 0) +++ trunk/AgateLib/UserInterface/Css/Selectors/WidgetMatchParameters.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -0,0 +1,76 @@ +using AgateLib.UserInterface.Widgets; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.UserInterface.Css.Selectors +{ + public class WidgetMatchParameters + { + Widget mWidget; + + public WidgetMatchParameters(Widget w) + { + mWidget = w; + + UpdateWidgetProperties(); + } + + public Widget Widget + { + get { return mWidget; } + } + + public void UpdateWidgetProperties() + { + TypeName = mWidget.GetType().Name; + PseudoClass = GetPseudoClass(mWidget); + Classes = GetCssClasses(mWidget); + } + + private CssPseudoClass GetPseudoClass(Widget control) + { + if (control.MouseIn) + return CssPseudoClass.Hover; + if (control is Container) + { + Container container = (Container)control; + + if (container.ChildHasMouseIn) + return CssPseudoClass.Hover; + } + if (control is MenuItem) + { + MenuItem mnuit = (MenuItem)control; + + if (mnuit.Selected) + return CssPseudoClass.Selected; + } + + return CssPseudoClass.None; + } + + private IEnumerable<string> GetCssClasses(Widget control) + { + if (control.Style.Equals(cachedClass, StringComparison.OrdinalIgnoreCase) == false) + { + cachedClass = control.Style.ToLowerInvariant(); + + Classes = cachedClass.Split(Extensions.WhiteSpace, StringSplitOptions.RemoveEmptyEntries); + } + + return Classes; + } + + string cachedClass; + + public string TypeName { get; private set; } + public string Id { get { return Widget.Name; } } + + public CssPseudoClass PseudoClass { get; private set; } + public IEnumerable<string> Classes { get; private set; } + + } +} Copied: trunk/AgateLib/UserInterface/Widgets/ImageBox.cs (from rev 1515, trunk/AgateLib/UserInterface/Widgets/ImageDisplay.cs) =================================================================== --- trunk/AgateLib/UserInterface/Widgets/ImageBox.cs (rev 0) +++ trunk/AgateLib/UserInterface/Widgets/ImageBox.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -0,0 +1,51 @@ +// The contents of this file are subject to the Mozilla Public License +// Version 1.1 (the "License"); you may not use this file except in +// compliance with the License. You may obtain a copy of the License at +// http://www.mozilla.org/MPL/ +// +// Software distributed under the License is distributed on an "AS IS" +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +// License for the specific language governing rights and limitations +// under the License. +// +// The Original Code is AgateLib. +// +// The Initial Developer of the Original Code is Erik Ylvisaker. +// Portions created by Erik Ylvisaker are Copyright (C) 2006-2014. +// All Rights Reserved. +// +// Contributor(s): Erik Ylvisaker +// +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib.DisplayLib; +using AgateLib.Geometry; + +namespace AgateLib.UserInterface.Widgets +{ + public class ImageBox : Widget + { + public IDrawable Image { get; set; } + + public ImageBox() + { } + + public override void DrawImpl() + { + if (Image == null) + return; + + Image.Draw(ClientToScreen(new Point(X, Y))); + } + + internal override Size ComputeSize(int? minWidth, int? minHeight, int? maxWidth, int? maxHeight) + { + if (Image == null) + return new Size(96, 96); + + return Image.DisplaySize; + } + } +} Deleted: trunk/AgateLib/UserInterface/Widgets/ImageDisplay.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/ImageDisplay.cs 2014-09-05 07:02:24 UTC (rev 1515) +++ trunk/AgateLib/UserInterface/Widgets/ImageDisplay.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -1,54 +0,0 @@ -// The contents of this file are subject to the Mozilla Public License -// Version 1.1 (the "License"); you may not use this file except in -// compliance with the License. You may obtain a copy of the License at -// http://www.mozilla.org/MPL/ -// -// Software distributed under the License is distributed on an "AS IS" -// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -// License for the specific language governing rights and limitations -// under the License. -// -// The Original Code is AgateLib. -// -// The Initial Developer of the Original Code is Erik Ylvisaker. -// Portions created by Erik Ylvisaker are Copyright (C) 2006-2014. -// All Rights Reserved. -// -// Contributor(s): Erik Ylvisaker -// -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using AgateLib.DisplayLib; -using AgateLib.Geometry; - -namespace AgateLib.UserInterface.Widgets -{ - public class ImageDisplay : Widget - { - public Surface Surface { get; set; } - - public ImageDisplay() - { - Width = 96; - Height = 96; - } - - public override void DrawImpl() - { - if (Surface == null) - return; - - Surface.Draw(ClientToScreen(new Point(X, Y))); - } - - internal override Size ComputeSize(int? minWidth, int? minHeight, int? maxWidth, int? maxHeight) - { - if (Surface == null) - return new Size(96, 96); - - return Surface.DisplaySize; - } - } -} Added: trunk/AgateLib/UserInterface/Widgets/LabelImage.cs =================================================================== --- trunk/AgateLib/UserInterface/Widgets/LabelImage.cs (rev 0) +++ trunk/AgateLib/UserInterface/Widgets/LabelImage.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -0,0 +1,36 @@ +using AgateLib.DisplayLib; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.UserInterface.Widgets +{ + public class LabelImage : Container + { + Label mLabel; + ImageBox mImageBox; + + public LabelImage() + { + mLabel = new Label(); + mImageBox = new ImageBox(); + + Children.Add(mImageBox); + Children.Add(mLabel); + } + public LabelImage(string text, IDrawable image) + :this() + { + Text = text; + Image = image; + } + + public string Text { get { return mLabel.Text; } set { mLabel.Text = value; } } + public IDrawable Image { get { return mImageBox.Image; } set { mImageBox.Image = value; } } + + public Label Label { get { return mLabel; } } + public ImageBox ImageBox { get { return mImageBox; } } + } +} Modified: trunk/AgateLib.AgateSDL/Audio/SDL_Audio.cs =================================================================== --- trunk/AgateLib.AgateSDL/Audio/SDL_Audio.cs 2014-09-05 07:02:24 UTC (rev 1515) +++ trunk/AgateLib.AgateSDL/Audio/SDL_Audio.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -93,7 +93,7 @@ throw new AgateLib.AgateException("Failed to initialize SDL for audio playback."); } - if (sdl.Mixer.Mix_OpenAudio(44100, SDLConstants.AUDIO_S16, 2, 512) != 0) + if (sdl.Mixer.Mix_OpenAudio(44100, SDLConstants.AUDIO_S16, 2, 4096) != 0) { throw new AgateLib.AgateException("Failed to initialize SDL_mixer."); } Modified: trunk/AgateLib.Tests/UnitTests/AgateLib.Tests.UnitTests.csproj =================================================================== --- trunk/AgateLib.Tests/UnitTests/AgateLib.Tests.UnitTests.csproj 2014-09-05 07:02:24 UTC (rev 1515) +++ trunk/AgateLib.Tests/UnitTests/AgateLib.Tests.UnitTests.csproj 2014-09-06 00:53:36 UTC (rev 1516) @@ -107,11 +107,11 @@ <Compile Include="Resources\SerializationTest.cs" /> <Compile Include="Serialization\Xle\TestSerializable.cs" /> <Compile Include="Serialization\Xle\XSTests.cs" /> - <Compile Include="UserInterface\Css\AdapterTest.cs" /> - <Compile Include="UserInterface\Css\BindingTest.cs" /> + <Compile Include="UserInterface\Css\CssAdapterTest.cs" /> + <Compile Include="UserInterface\Css\CssBindingTest.cs" /> <Compile Include="UserInterface\Css\CssTestBase.cs" /> - <Compile Include="UserInterface\Css\LayoutTest.cs" /> - <Compile Include="UserInterface\Css\ParseTest.cs" /> + <Compile Include="UserInterface\Css\CssLayoutTest.cs" /> + <Compile Include="UserInterface\Css\CssParseTest.cs" /> <Compile Include="UserInterface\Widgets\ConversionTests.cs" /> <Compile Include="Utility\RefTest.cs" /> </ItemGroup> Deleted: trunk/AgateLib.Tests/UnitTests/UserInterface/Css/AdapterTest.cs =================================================================== --- trunk/AgateLib.Tests/UnitTests/UserInterface/Css/AdapterTest.cs 2014-09-05 07:02:24 UTC (rev 1515) +++ trunk/AgateLib.Tests/UnitTests/UserInterface/Css/AdapterTest.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -1,75 +0,0 @@ -using AgateLib.Geometry; -using AgateLib.UserInterface.Css.Documents; -using AgateLib.UserInterface.Widgets; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AgateLib.UserInterface.Css.Tests -{ - [TestClass] - public class AdapterTest : CssTestBase - { - [TestMethod] - public void DocumentConstruction() - { - CssDocument doc = CssDocument.FromText("window { color: red; left: 20em; padding: 4px; margin: 8px; } label { color: green; }"); - CssAdapter adapter = new CssAdapter(doc); - - var window = new Window(); - var style = adapter.GetStyle(window); - - Assert.AreEqual(Color.Red, style.Data.Font.Color); - DistanceAssert(false, 20, DistanceUnit.FontHeight, style.Data.PositionData.Left); - DistanceAssert(false, 4, DistanceUnit.Pixels, style.Data.Padding.Left); - DistanceAssert(false, 4, DistanceUnit.Pixels, style.Data.Padding.Right); - DistanceAssert(false, 4, DistanceUnit.Pixels, style.Data.Padding.Top); - DistanceAssert(false, 4, DistanceUnit.Pixels, style.Data.Padding.Bottom); - - DistanceAssert(false, 8, DistanceUnit.Pixels, style.Data.Margin.Left); - DistanceAssert(false, 8, DistanceUnit.Pixels, style.Data.Margin.Right); - DistanceAssert(false, 8, DistanceUnit.Pixels, style.Data.Margin.Top); - DistanceAssert(false, 8, DistanceUnit.Pixels, style.Data.Margin.Bottom); - - } - - [TestMethod] - public void MarginPaddingTest() - { - CssDocument doc = CssDocument.FromText( - @"window { color: red; margin-top: 4px; } - panel { margin-bottom: 5px; margin-right: 3em; padding-left: 18%; }"); - CssAdapter adapter = new CssAdapter(doc); - Window wind = new Window(); - Panel pnl = new Panel(); - - var style = adapter.GetStyle(wind); - Assert.AreEqual(new CssDistance { Amount = 4, DistanceUnit = DistanceUnit.Pixels }, style.Data.Margin.Top); - - style = adapter.GetStyle(pnl); - Assert.AreEqual(new CssDistance { Amount = 3, DistanceUnit = DistanceUnit.FontHeight }, style.Data.Margin.Right); - Assert.AreEqual(new CssDistance { Amount = 18, DistanceUnit = DistanceUnit.Percent }, style.Data.Padding.Left); - } - - - [TestMethod] - public void BorderImageSetting() - { - CssDocument doc = CssDocument.FromText("window { border-image-repeat: stretch; border-image-width: 4px 8px; border-image-outset: 34px; }"); - CssAdapter adapter = new CssAdapter(doc); - Window wind = new Window(); - - var style = adapter.GetStyle(wind); - - DistanceAssert(false, 8, DistanceUnit.Pixels, style.Data.Border.Image.Width.Right); - DistanceAssert(false, 4, DistanceUnit.Pixels, style.Data.Border.Image.Width.Bottom); - DistanceAssert(false, 34, DistanceUnit.Pixels, style.Data.Border.Image.Outset.Left); - - Assert.AreEqual(CssBorderImageRepeat.Stretch, style.Data.Border.Image.Repeat); - } - - } -} Deleted: trunk/AgateLib.Tests/UnitTests/UserInterface/Css/BindingTest.cs =================================================================== --- trunk/AgateLib.Tests/UnitTests/UserInterface/Css/BindingTest.cs 2014-09-05 07:02:24 UTC (rev 1515) +++ trunk/AgateLib.Tests/UnitTests/UserInterface/Css/BindingTest.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -1,62 +0,0 @@ -using AgateLib.UserInterface.Css.Binders; -using AgateLib.UserInterface.Css.Documents; -using AgateLib.UserInterface.Css.Selectors; -using AgateLib.UserInterface.Widgets; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AgateLib.UserInterface.Css.Tests -{ - [TestClass] - public class BindingTest : CssTestBase - { - [TestMethod] - public void PropertyMapping() - { - CssPropertyMap pm = new CssPropertyMap(); - CssBindingMapper bm = new CssBindingMapper(pm); - - Assert.IsTrue(bm.FindPropertyChain("color")); - Assert.IsTrue(bm.FindPropertyChain("background-color")); - Assert.IsTrue(bm.FindPropertyChain("background-repeat")); - - Assert.IsTrue(pm["color"].Count == 2); - } - - [TestMethod] - public void SelectorMatching() - { - Label lbl = new Label { Name = "label" }; - CssSelector sel = new CssSelector("label"); - string[] classes = new string[] { }; - - Assert.IsTrue(sel.Matches(lbl, lbl.Name, CssPseudoClass.None, classes)); - - sel = new CssSelector("label#label1"); - Assert.IsFalse(sel.Matches(lbl, lbl.Name, CssPseudoClass.None, classes)); - - sel = new CssSelector("label:hover"); - Assert.IsFalse(sel.Matches(lbl, lbl.Name, CssPseudoClass.None, classes)); - Assert.IsFalse(sel.Matches(lbl, null, CssPseudoClass.None, classes)); - Assert.IsTrue(sel.Matches(lbl, lbl.Name, CssPseudoClass.Hover, classes)); - } - - - [TestMethod] - public void PseudoClassMatching() - { - CssDocument doc = CssDocument.FromText("window:hover { padding: 8px; }"); - CssAdapter adapter = new CssAdapter(doc); - Window wind = new Window(); - wind.MouseIn = true; - - var style = adapter.GetStyle(wind); - - DistanceAssert(false, 8, DistanceUnit.Pixels, style.Data.Padding.Right); - } - } -} Copied: trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssAdapterTest.cs (from rev 1515, trunk/AgateLib.Tests/UnitTests/UserInterface/Css/AdapterTest.cs) =================================================================== --- trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssAdapterTest.cs (rev 0) +++ trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssAdapterTest.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -0,0 +1,75 @@ +using AgateLib.Geometry; +using AgateLib.UserInterface.Css.Documents; +using AgateLib.UserInterface.Widgets; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.UserInterface.Css.Tests +{ + [TestClass] + public class CssAdapterTest : CssTestBase + { + [TestMethod] + public void DocumentConstruction() + { + CssDocument doc = CssDocument.FromText("window { color: red; left: 20em; padding: 4px; margin: 8px; } label { color: green; }"); + CssAdapter adapter = new CssAdapter(doc); + + var window = new Window(); + var style = adapter.GetStyle(window); + + Assert.AreEqual(Color.Red, style.Data.Font.Color); + DistanceAssert(false, 20, DistanceUnit.FontHeight, style.Data.PositionData.Left); + DistanceAssert(false, 4, DistanceUnit.Pixels, style.Data.Padding.Left); + DistanceAssert(false, 4, DistanceUnit.Pixels, style.Data.Padding.Right); + DistanceAssert(false, 4, DistanceUnit.Pixels, style.Data.Padding.Top); + DistanceAssert(false, 4, DistanceUnit.Pixels, style.Data.Padding.Bottom); + + DistanceAssert(false, 8, DistanceUnit.Pixels, style.Data.Margin.Left); + DistanceAssert(false, 8, DistanceUnit.Pixels, style.Data.Margin.Right); + DistanceAssert(false, 8, DistanceUnit.Pixels, style.Data.Margin.Top); + DistanceAssert(false, 8, DistanceUnit.Pixels, style.Data.Margin.Bottom); + + } + + [TestMethod] + public void MarginPaddingTest() + { + CssDocument doc = CssDocument.FromText( + @"window { color: red; margin-top: 4px; } + panel { margin-bottom: 5px; margin-right: 3em; padding-left: 18%; }"); + CssAdapter adapter = new CssAdapter(doc); + Window wind = new Window(); + Panel pnl = new Panel(); + + var style = adapter.GetStyle(wind); + Assert.AreEqual(new CssDistance { Amount = 4, DistanceUnit = DistanceUnit.Pixels }, style.Data.Margin.Top); + + style = adapter.GetStyle(pnl); + Assert.AreEqual(new CssDistance { Amount = 3, DistanceUnit = DistanceUnit.FontHeight }, style.Data.Margin.Right); + Assert.AreEqual(new CssDistance { Amount = 18, DistanceUnit = DistanceUnit.Percent }, style.Data.Padding.Left); + } + + + [TestMethod] + public void BorderImageSetting() + { + CssDocument doc = CssDocument.FromText("window { border-image-repeat: stretch; border-image-width: 4px 8px; border-image-outset: 34px; }"); + CssAdapter adapter = new CssAdapter(doc); + Window wind = new Window(); + + var style = adapter.GetStyle(wind); + + DistanceAssert(false, 8, DistanceUnit.Pixels, style.Data.Border.Image.Width.Right); + DistanceAssert(false, 4, DistanceUnit.Pixels, style.Data.Border.Image.Width.Bottom); + DistanceAssert(false, 34, DistanceUnit.Pixels, style.Data.Border.Image.Outset.Left); + + Assert.AreEqual(CssBorderImageRepeat.Stretch, style.Data.Border.Image.Repeat); + } + + } +} Copied: trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssBindingTest.cs (from rev 1515, trunk/AgateLib.Tests/UnitTests/UserInterface/Css/BindingTest.cs) =================================================================== --- trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssBindingTest.cs (rev 0) +++ trunk/AgateLib.Tests/UnitTests/UserInterface/Css/CssBindingTest.cs 2014-09-06 00:53:36 UTC (rev 1516) @@ -0,0 +1,91 @@ +using AgateLib.ApplicationModels; +using AgateLib.Testing.Fakes; +using AgateLib.UserInterface.Css.Binders; +using AgateLib.UserInterface.Css.Documents; +using AgateLib.UserInterface.Css.Selectors; +using AgateLib.UserInterface.Widgets; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.UserInterface.Css.Tests +{ + [TestClass] + public class C... [truncated message content] |
From: <ka...@us...> - 2014-09-05 07:02:32
|
Revision: 1515 http://sourceforge.net/p/agate/code/1515 Author: kanato Date: 2014-09-05 07:02:24 +0000 (Fri, 05 Sep 2014) Log Message: ----------- FileSystemProvider returns relative paths in GetAllFiles. Modified Paths: -------------- trunk/AgateLib.Platform.WinForms/IO/FileSystemProvider.cs trunk/AgateLib.Tests/UnitTests/AgateLib.Tests.UnitTests.csproj Added Paths: ----------- trunk/AgateLib.Tests/UnitTests/IO/ trunk/AgateLib.Tests/UnitTests/IO/FileSystemProviderTests.cs Modified: trunk/AgateLib.Platform.WinForms/IO/FileSystemProvider.cs =================================================================== --- trunk/AgateLib.Platform.WinForms/IO/FileSystemProvider.cs 2014-09-04 15:22:39 UTC (rev 1514) +++ trunk/AgateLib.Platform.WinForms/IO/FileSystemProvider.cs 2014-09-05 07:02:24 UTC (rev 1515) @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; using AgateLib.IO; using System.Threading.Tasks; @@ -32,6 +33,7 @@ public class FileSystemProvider : IReadFileProvider { string mPath; + Uri mPathUri; /// <summary> /// Constructs a FileSystemProvider object directing it to read files from the @@ -41,6 +43,16 @@ public FileSystemProvider(string path) { mPath = path; + + if (path.EndsWith("/") == false && path.EndsWith("\\") == false) + path += "/"; + + path = path.Replace('\\', '/'); + + if (path.StartsWith("./")) + path = Directory.GetCurrentDirectory() + path.Substring(1); + + mPathUri = new Uri(path); } /// <summary> /// Opens a file. @@ -233,12 +245,26 @@ { List<string> files = new List<string>(); - files.AddRange(Directory.GetFiles(mPath, searchPattern)); + files.AddRange(Directory.GetFiles(mPath, searchPattern) + .Select(x => MakeRelativePath(x))); return files; } /// <summary> + /// Constructs a path relative to the root of this file system provider. + /// </summary> + /// <param name="fullpath"></param> + /// <returns></returns> + public string MakeRelativePath(string fullpath) + { + var uri = new Uri(fullpath); + var rel = mPathUri.MakeRelativeUri(uri); + + return rel.ToString(); + } + + /// <summary> /// Returns a string representing the FileSystemProvider object. /// </summary> /// <returns></returns> Modified: trunk/AgateLib.Tests/UnitTests/AgateLib.Tests.UnitTests.csproj =================================================================== --- trunk/AgateLib.Tests/UnitTests/AgateLib.Tests.UnitTests.csproj 2014-09-04 15:22:39 UTC (rev 1514) +++ trunk/AgateLib.Tests/UnitTests/AgateLib.Tests.UnitTests.csproj 2014-09-05 07:02:24 UTC (rev 1515) @@ -101,6 +101,7 @@ <Compile Include="Display\FontTests.cs" /> <Compile Include="Extensions\ListExtensions.cs" /> <Compile Include="Geometry\ColorTests.cs" /> + <Compile Include="IO\FileSystemProviderTests.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Platform\PlatformTests.cs" /> <Compile Include="Resources\SerializationTest.cs" /> Added: trunk/AgateLib.Tests/UnitTests/IO/FileSystemProviderTests.cs =================================================================== --- trunk/AgateLib.Tests/UnitTests/IO/FileSystemProviderTests.cs (rev 0) +++ trunk/AgateLib.Tests/UnitTests/IO/FileSystemProviderTests.cs 2014-09-05 07:02:24 UTC (rev 1515) @@ -0,0 +1,22 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using AgateLib.Platform.WinForms.IO; + +namespace AgateLib.IO +{ + [TestClass] + public class FileSystemProviderTests + { + [TestMethod] + public void FspRelativePath() + { + FileSystemProvider fsp = new FileSystemProvider(@"c:\test\path"); + + Assert.AreEqual("to/somewhere.txt", + fsp.MakeRelativePath(@"c:\test\path\to\somewhere.txt")); + + Assert.AreEqual("../alternate", + fsp.MakeRelativePath(@"c:\test\alternate")); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2014-09-04 15:22:42
|
Revision: 1514 http://sourceforge.net/p/agate/code/1514 Author: kanato Date: 2014-09-04 15:22:39 +0000 (Thu, 04 Sep 2014) Log Message: ----------- Fix build script for paths with spaces. Modified Paths: -------------- trunk/AgateLib.Platform.WindowsStoreCommon/AgateLib.Platform.WindowsStoreCommon.csproj Modified: trunk/AgateLib.Platform.WindowsStoreCommon/AgateLib.Platform.WindowsStoreCommon.csproj =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/AgateLib.Platform.WindowsStoreCommon.csproj 2014-09-04 05:40:29 UTC (rev 1513) +++ trunk/AgateLib.Platform.WindowsStoreCommon/AgateLib.Platform.WindowsStoreCommon.csproj 2014-09-04 15:22:39 UTC (rev 1514) @@ -151,7 +151,7 @@ <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" /> </Target> <PropertyGroup> - <PreBuildEvent>cd $(ProjectDir)\Resources & $(ProjectDir)Resources\buildshaders.bat /Zi</PreBuildEvent> + <PreBuildEvent>cd "$(ProjectDir)\Resources" & "$(ProjectDir)Resources\buildshaders.bat" /Zi</PreBuildEvent> </PropertyGroup> <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2014-09-04 05:40:35
|
Revision: 1513 http://sourceforge.net/p/agate/code/1513 Author: kanato Date: 2014-09-04 05:40:29 +0000 (Thu, 04 Sep 2014) Log Message: ----------- Fix coordinate system on FakeRenderTarget. Modified Paths: -------------- trunk/AgateLib.Tests/AgateLib.Tests.Portable/Fakes/FakeRenderTarget.cs Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/Fakes/FakeRenderTarget.cs =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/Fakes/FakeRenderTarget.cs 2014-09-04 05:21:16 UTC (rev 1512) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/Fakes/FakeRenderTarget.cs 2014-09-04 05:40:29 UTC (rev 1513) @@ -14,6 +14,7 @@ public FakeRenderTarget() { CoordinateSystem = new NativeCoordinates(); + CoordinateSystem.RenderTargetSize = Size; } public int Height { get { return 400; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |