From 61055148ef5fe613c63a7752b4b17ab45a524563 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 24 Jun 2022 21:33:24 +0200 Subject: [PATCH] some fixes and doc changes to make MLEM.FNA more in line with MLEM --- Demos.DesktopGL/Demos.DesktopGL.FNA.csproj | 2 +- Demos.DesktopGL/{FNA => FnaNative}/FAudio.dll | Bin Demos.DesktopGL/{FNA => FnaNative}/FNA3D.dll | Bin Demos.DesktopGL/{FNA => FnaNative}/SDL2.dll | Bin .../{FNA => FnaNative}/libFAudio.0.dylib | Bin .../{FNA => FnaNative}/libFAudio.so.0 | Bin .../{FNA => FnaNative}/libFNA3D.0.dylib | Bin .../{FNA => FnaNative}/libFNA3D.so.0 | Bin .../{FNA => FnaNative}/libMoltenVK.dylib | Bin .../{FNA => FnaNative}/libSDL2-2.0.0.dylib | Bin .../{FNA => FnaNative}/libSDL2-2.0.so.0 | Bin .../{FNA => FnaNative}/libtheorafile.dll | Bin .../{FNA => FnaNative}/libtheorafile.dylib | Bin .../{FNA => FnaNative}/libtheorafile.so | Bin .../{FNA => FnaNative}/libvulkan.1.dylib | Bin Docs/articles/ui.md | 18 +++++++++++------- Docs/index.md | 14 +++++++------- MLEM/Formatting/Codes/ImageCode.cs | 6 ++++++ MLEM/Misc/MlemPlatform.cs | 4 ++-- README.md | 14 +++++++------- Tests/{FNA => FnaNative}/FAudio.dll | Bin Tests/{FNA => FnaNative}/FNA3D.dll | Bin Tests/{FNA => FnaNative}/SDL2.dll | Bin Tests/{FNA => FnaNative}/libFAudio.0.dylib | Bin Tests/{FNA => FnaNative}/libFAudio.so.0 | Bin Tests/{FNA => FnaNative}/libFNA3D.0.dylib | Bin Tests/{FNA => FnaNative}/libFNA3D.so.0 | Bin Tests/{FNA => FnaNative}/libMoltenVK.dylib | Bin Tests/{FNA => FnaNative}/libSDL2-2.0.0.dylib | Bin Tests/{FNA => FnaNative}/libSDL2-2.0.so.0 | Bin Tests/{FNA => FnaNative}/libtheorafile.dll | Bin Tests/{FNA => FnaNative}/libtheorafile.dylib | Bin Tests/{FNA => FnaNative}/libtheorafile.so | Bin Tests/{FNA => FnaNative}/libvulkan.1.dylib | Bin Tests/Tests.FNA.csproj | 2 +- 35 files changed, 35 insertions(+), 25 deletions(-) rename Demos.DesktopGL/{FNA => FnaNative}/FAudio.dll (100%) rename Demos.DesktopGL/{FNA => FnaNative}/FNA3D.dll (100%) rename Demos.DesktopGL/{FNA => FnaNative}/SDL2.dll (100%) rename Demos.DesktopGL/{FNA => FnaNative}/libFAudio.0.dylib (100%) rename Demos.DesktopGL/{FNA => FnaNative}/libFAudio.so.0 (100%) rename Demos.DesktopGL/{FNA => FnaNative}/libFNA3D.0.dylib (100%) rename Demos.DesktopGL/{FNA => FnaNative}/libFNA3D.so.0 (100%) rename Demos.DesktopGL/{FNA => FnaNative}/libMoltenVK.dylib (100%) rename Demos.DesktopGL/{FNA => FnaNative}/libSDL2-2.0.0.dylib (100%) rename Demos.DesktopGL/{FNA => FnaNative}/libSDL2-2.0.so.0 (100%) rename Demos.DesktopGL/{FNA => FnaNative}/libtheorafile.dll (100%) rename Demos.DesktopGL/{FNA => FnaNative}/libtheorafile.dylib (100%) rename Demos.DesktopGL/{FNA => FnaNative}/libtheorafile.so (100%) rename Demos.DesktopGL/{FNA => FnaNative}/libvulkan.1.dylib (100%) rename Tests/{FNA => FnaNative}/FAudio.dll (100%) rename Tests/{FNA => FnaNative}/FNA3D.dll (100%) rename Tests/{FNA => FnaNative}/SDL2.dll (100%) rename Tests/{FNA => FnaNative}/libFAudio.0.dylib (100%) rename Tests/{FNA => FnaNative}/libFAudio.so.0 (100%) rename Tests/{FNA => FnaNative}/libFNA3D.0.dylib (100%) rename Tests/{FNA => FnaNative}/libFNA3D.so.0 (100%) rename Tests/{FNA => FnaNative}/libMoltenVK.dylib (100%) rename Tests/{FNA => FnaNative}/libSDL2-2.0.0.dylib (100%) rename Tests/{FNA => FnaNative}/libSDL2-2.0.so.0 (100%) rename Tests/{FNA => FnaNative}/libtheorafile.dll (100%) rename Tests/{FNA => FnaNative}/libtheorafile.dylib (100%) rename Tests/{FNA => FnaNative}/libtheorafile.so (100%) rename Tests/{FNA => FnaNative}/libvulkan.1.dylib (100%) diff --git a/Demos.DesktopGL/Demos.DesktopGL.FNA.csproj b/Demos.DesktopGL/Demos.DesktopGL.FNA.csproj index 988c685..58a5df6 100644 --- a/Demos.DesktopGL/Demos.DesktopGL.FNA.csproj +++ b/Demos.DesktopGL/Demos.DesktopGL.FNA.csproj @@ -28,7 +28,7 @@ - + PreserveNewest %(Filename)%(Extension) diff --git a/Demos.DesktopGL/FNA/FAudio.dll b/Demos.DesktopGL/FnaNative/FAudio.dll similarity index 100% rename from Demos.DesktopGL/FNA/FAudio.dll rename to Demos.DesktopGL/FnaNative/FAudio.dll diff --git a/Demos.DesktopGL/FNA/FNA3D.dll b/Demos.DesktopGL/FnaNative/FNA3D.dll similarity index 100% rename from Demos.DesktopGL/FNA/FNA3D.dll rename to Demos.DesktopGL/FnaNative/FNA3D.dll diff --git a/Demos.DesktopGL/FNA/SDL2.dll b/Demos.DesktopGL/FnaNative/SDL2.dll similarity index 100% rename from Demos.DesktopGL/FNA/SDL2.dll rename to Demos.DesktopGL/FnaNative/SDL2.dll diff --git a/Demos.DesktopGL/FNA/libFAudio.0.dylib b/Demos.DesktopGL/FnaNative/libFAudio.0.dylib similarity index 100% rename from Demos.DesktopGL/FNA/libFAudio.0.dylib rename to Demos.DesktopGL/FnaNative/libFAudio.0.dylib diff --git a/Demos.DesktopGL/FNA/libFAudio.so.0 b/Demos.DesktopGL/FnaNative/libFAudio.so.0 similarity index 100% rename from Demos.DesktopGL/FNA/libFAudio.so.0 rename to Demos.DesktopGL/FnaNative/libFAudio.so.0 diff --git a/Demos.DesktopGL/FNA/libFNA3D.0.dylib b/Demos.DesktopGL/FnaNative/libFNA3D.0.dylib similarity index 100% rename from Demos.DesktopGL/FNA/libFNA3D.0.dylib rename to Demos.DesktopGL/FnaNative/libFNA3D.0.dylib diff --git a/Demos.DesktopGL/FNA/libFNA3D.so.0 b/Demos.DesktopGL/FnaNative/libFNA3D.so.0 similarity index 100% rename from Demos.DesktopGL/FNA/libFNA3D.so.0 rename to Demos.DesktopGL/FnaNative/libFNA3D.so.0 diff --git a/Demos.DesktopGL/FNA/libMoltenVK.dylib b/Demos.DesktopGL/FnaNative/libMoltenVK.dylib similarity index 100% rename from Demos.DesktopGL/FNA/libMoltenVK.dylib rename to Demos.DesktopGL/FnaNative/libMoltenVK.dylib diff --git a/Demos.DesktopGL/FNA/libSDL2-2.0.0.dylib b/Demos.DesktopGL/FnaNative/libSDL2-2.0.0.dylib similarity index 100% rename from Demos.DesktopGL/FNA/libSDL2-2.0.0.dylib rename to Demos.DesktopGL/FnaNative/libSDL2-2.0.0.dylib diff --git a/Demos.DesktopGL/FNA/libSDL2-2.0.so.0 b/Demos.DesktopGL/FnaNative/libSDL2-2.0.so.0 similarity index 100% rename from Demos.DesktopGL/FNA/libSDL2-2.0.so.0 rename to Demos.DesktopGL/FnaNative/libSDL2-2.0.so.0 diff --git a/Demos.DesktopGL/FNA/libtheorafile.dll b/Demos.DesktopGL/FnaNative/libtheorafile.dll similarity index 100% rename from Demos.DesktopGL/FNA/libtheorafile.dll rename to Demos.DesktopGL/FnaNative/libtheorafile.dll diff --git a/Demos.DesktopGL/FNA/libtheorafile.dylib b/Demos.DesktopGL/FnaNative/libtheorafile.dylib similarity index 100% rename from Demos.DesktopGL/FNA/libtheorafile.dylib rename to Demos.DesktopGL/FnaNative/libtheorafile.dylib diff --git a/Demos.DesktopGL/FNA/libtheorafile.so b/Demos.DesktopGL/FnaNative/libtheorafile.so similarity index 100% rename from Demos.DesktopGL/FNA/libtheorafile.so rename to Demos.DesktopGL/FnaNative/libtheorafile.so diff --git a/Demos.DesktopGL/FNA/libvulkan.1.dylib b/Demos.DesktopGL/FnaNative/libvulkan.1.dylib similarity index 100% rename from Demos.DesktopGL/FNA/libvulkan.1.dylib rename to Demos.DesktopGL/FnaNative/libvulkan.1.dylib diff --git a/Docs/articles/ui.md b/Docs/articles/ui.md index 98a3403..20d7d9b 100644 --- a/Docs/articles/ui.md +++ b/Docs/articles/ui.md @@ -1,6 +1,6 @@ # MLEM.Ui -**MLEM.Ui** is a Ui framework for MonoGame that features elements with automatic positioning and sizing. It contains various ready-made element types like buttons, paragraphs, text fields and more, along with the ability to easily create custom controls. It supports **mouse**, **keyboard**, **gamepad** and **touch** input with little to no additional setup work required. +**MLEM.Ui** is a Ui framework for MonoGame and FNA that features elements with automatic positioning and sizing. It contains various ready-made element types like buttons, paragraphs, text fields and more, along with the ability to easily create custom controls. It supports **mouse**, **keyboard**, **gamepad** and **touch** input with little to no additional setup work required. To see some of what MLEM.Ui can do, you can check out [the demo](https://github.com/Ellpeck/MLEM/blob/main/Demos/UiDemo.cs) as well. @@ -11,7 +11,7 @@ public UiSystem UiSystem; protected override void LoadContent() { // Load your other content here - + // Initialize the Ui system this.UiSystem = new UiSystem(this.Window, this.GraphicsDevice, new UntexturedStyle(this.SpriteBatch)); } @@ -24,26 +24,30 @@ protected override void Update(GameTime gameTime) { protected override void Draw(GameTime gameTime) { this.GraphicsDevice.Clear(Color.CornflowerBlue); // Do your regular game drawing here - + // Call Draw at the end to draw the Ui on top of your game this.UiSystem.Draw(gameTime, this.SpriteBatch); } ``` ### Text Input -On desktop devices, MonoGame provides the `Window.TextInput` event that gets called automatically with the correct characters for the keys that you're pressing, even for non-American keyboards. However, this function doesn't exist on other devices. Similarly, MonoGame provides the `KeyboardInput` class for showing an on-screen keyboard on mobile devices and consoles, but not on desktop. +On desktop devices, MonoGame provides the `Window.TextInput` event that gets called automatically with the correct characters for the keys that you're pressing, even for non-American keyboards. However, this function doesn't exist on other devices. Similarly, MonoGame provides the `KeyboardInput` class for showing an on-screen keyboard on mobile devices and consoles, but not on desktop. To make MLEM compatible with all devices without publishing a separate version for each MonoGame platform, you have to set up the `MlemPlatform` class based on the system you're using MLEM.Ui with. This has to be done *before* initializing your `UiSystem`. -DesktopGL: +DesktopGL and WindowsDX using MonoGame: ```cs MlemPlatform.Current = new MlemPlatform.DesktopGl((w, c) => w.TextInput += c); ``` +Desktop using FNA: +```cs +MlemPlatform.Current = new MlemPlatform.DesktopFna(a => TextInputEXT.TextInput += a); +``` Mobile devices and consoles: ```cs MlemPlatform.Current = new MlemPlatform.Mobile(KeyboardInput.Show, l => this.StartActivity(new Intent(Intent.ActionView, Uri.Parse(l)))); ``` -If you're not using text input, you can just set the platform to a stub one like so: +If you're not using text input, you can leave the platform uninitialized or just set it to a stub one like so: ```cs MlemPlatform.Current = new MlemPlatform.None(); ``` @@ -89,4 +93,4 @@ this.UiSystem.Add("InfoBox", box); Note that, when setting the width and height of any element, there are some things to note: - Each element has a `SetWidthBasedOnChildren` and a `SetHeightBasedOnChildren` property, which allow them to change their size automatically based on their content - When specifying a width or height *lower than or equal to 1*, it is seen as a percentage based on the parent's size instead. For example, a paragraph with a width of `0.5F` inside of a panel width a width of `200` will be `100` units wide. -- When specifying a width *lower than 0*, it is seen as a percentage based on the element's height, and vice versa. For example, a panel with a width of `200` and a height of `-2` will be `400` units tall. \ No newline at end of file +- When specifying a width *lower than 0*, it is seen as a percentage based on the element's height, and vice versa. For example, a panel with a width of `200` and a height of `-2` will be `400` units tall. diff --git a/Docs/index.md b/Docs/index.md index ae31940..d5e3713 100644 --- a/Docs/index.md +++ b/Docs/index.md @@ -11,12 +11,12 @@ - See [the changelog](https://mlem.ellpeck.de/CHANGELOG.html) for information on updates # Packages -- **MLEM** is the base package, which provides extension methods and additional features for MonoGame -- **MLEM.Ui** features a mouse, keyboard, gamepad and touch ready Ui system that features automatic anchoring, sizing and several ready-to-use element types -- **MLEM.Extended** ties in with MonoGame.Extended and other MonoGame libraries -- **MLEM.Data** provides simple loading and processing of textures and other data, including the ability to load non-XNB content files easily -- **MLEM.Startup** combines MLEM with some other useful libraries into a quick Game startup class -- **MLEM.Templates** contains cross-platform project templates +- **MLEM** is the base package, which provides extension methods and additional features for MonoGame and FNA. +- **MLEM.Ui** features a mouse, keyboard, gamepad and touch ready Ui system that features automatic anchoring, sizing and several ready-to-use element types. +- **MLEM.Extended** ties in with MonoGame.Extended and other MonoGame and FNA libraries. +- **MLEM.Data** provides simple loading and processing of textures and other data, including the ability to load non-XNB content files easily. +- **MLEM.Startup** combines MLEM with some other useful libraries into a quick Game startup class. +- **MLEM.Templates** contains cross-platform project templates. # Made with MLEM - [A Breath of Spring Air](https://ellpeck.itch.io/a-breath-of-spring-air), a short platformer ([Source](https://git.ellpeck.de/Ellpeck/GreatSpringGameJam)) @@ -38,7 +38,7 @@ MLEM's [text formatting system](https://mlem.ellpeck.de/articles/text_formatting ![An image showing text with various colors and other formatting](https://raw.githubusercontent.com/Ellpeck/MLEM/release/Media/Formatting.png) # Friends of MLEM -There are several other libraries and tools that work well in combination with MonoGame and MLEM. Here are some of them: +There are several other libraries and tools that work well in combination with MonoGame, FNA and MLEM. Here are some of them: - [Contentless](https://github.com/Ellpeck/Contentless), a tool that removes the need to add assets to the MonoGame Content Pipeline manually - [GameBundle](https://github.com/Ellpeck/GameBundle), a tool that packages MonoGame and other .NET Core applications into several distributable formats - [MonoGame.Extended](https://github.com/craftworkgames/MonoGame.Extended), a package that also provides several additional features for MonoGame diff --git a/MLEM/Formatting/Codes/ImageCode.cs b/MLEM/Formatting/Codes/ImageCode.cs index 79fd6be..66c600b 100644 --- a/MLEM/Formatting/Codes/ImageCode.cs +++ b/MLEM/Formatting/Codes/ImageCode.cs @@ -41,6 +41,12 @@ namespace MLEM.Formatting.Codes { batch.Draw(this.image.CurrentRegion, new RectangleF(pos, new Vector2(font.LineHeight * scale)), actualColor); } + /// + public override bool DrawCharacter(GameTime time, SpriteBatch batch, char c, string cString, Token token, int indexInToken, ref Vector2 pos, GenericFont font, ref Color color, ref float scale, float depth) { + // we don't want to draw the first (space) character (in case it is set to a missing character in FNA) + return indexInToken == 0; + } + } /// diff --git a/MLEM/Misc/MlemPlatform.cs b/MLEM/Misc/MlemPlatform.cs index eacbb07..c9ad24b 100644 --- a/MLEM/Misc/MlemPlatform.cs +++ b/MLEM/Misc/MlemPlatform.cs @@ -9,7 +9,7 @@ using MLEM.Formatting.Codes; namespace MLEM.Misc { /// /// MlemPlatform is a wrapper around some of MonoGame's platform-dependent behavior to allow for MLEM to stay platform-independent. - /// See , and for information on the specific platforms. + /// See , , and for information on the specific platforms. /// The MLEM demos' main classes also make use of this functionality: https://github.com/Ellpeck/MLEM/blob/main/Demos.DesktopGL/Program.cs#L8 and https://github.com/Ellpeck/MLEM/blob/main/Demos.Android/Activity1.cs#L33. /// public abstract class MlemPlatform { @@ -63,7 +63,7 @@ namespace MLEM.Misc { public delegate void TextInputCallback(object sender, Keys key, char character); /// - /// The MLEM DesktopGL platform. + /// The MLEM DesktopGL platform, which is also compatible with other desktop distributions of MonoGame, like WindowsDX. /// This platform uses the built-in MonoGame TextInput event, which makes this listener work with any keyboard localization natively. /// This platform is initialized as follows: /// diff --git a/README.md b/README.md index 4b04166..3e3bc2d 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,12 @@ - See [the changelog](https://github.com/Ellpeck/MLEM/blob/main/CHANGELOG.md) for information on updates # Packages -- **MLEM** is the base package, which provides extension methods and additional features for MonoGame -- **MLEM.Ui** features a mouse, keyboard, gamepad and touch ready Ui system that features automatic anchoring, sizing and several ready-to-use element types -- **MLEM.Extended** ties in with MonoGame.Extended and other MonoGame libraries -- **MLEM.Data** provides simple loading and processing of textures and other data, including the ability to load non-XNB content files easily -- **MLEM.Startup** combines MLEM with some other useful libraries into a quick Game startup class -- **MLEM.Templates** contains cross-platform project templates +- **MLEM** is the base package, which provides extension methods and additional features for MonoGame and FNA. +- **MLEM.Ui** features a mouse, keyboard, gamepad and touch ready Ui system that features automatic anchoring, sizing and several ready-to-use element types. +- **MLEM.Extended** ties in with MonoGame.Extended and other MonoGame and FNA libraries. +- **MLEM.Data** provides simple loading and processing of textures and other data, including the ability to load non-XNB content files easily. +- **MLEM.Startup** combines MLEM with some other useful libraries into a quick Game startup class. +- **MLEM.Templates** contains cross-platform project templates. # Made with MLEM - [A Breath of Spring Air](https://ellpeck.itch.io/a-breath-of-spring-air), a short platformer ([Source](https://git.ellpeck.de/Ellpeck/GreatSpringGameJam)) @@ -38,7 +38,7 @@ MLEM's [text formatting system](https://mlem.ellpeck.de/articles/text_formatting ![An image showing text with various colors and other formatting](https://raw.githubusercontent.com/Ellpeck/MLEM/main/Media/Formatting.png) # Friends of MLEM -There are several other libraries and tools that work well in combination with MonoGame and MLEM. Here are some of them: +There are several other libraries and tools that work well in combination with MonoGame, FNA and MLEM. Here are some of them: - [Contentless](https://github.com/Ellpeck/Contentless), a tool that removes the need to add assets to the MonoGame Content Pipeline manually - [GameBundle](https://github.com/Ellpeck/GameBundle), a tool that packages MonoGame and other .NET Core applications into several distributable formats - [MonoGame.Extended](https://github.com/craftworkgames/MonoGame.Extended), a package that also provides several additional features for MonoGame diff --git a/Tests/FNA/FAudio.dll b/Tests/FnaNative/FAudio.dll similarity index 100% rename from Tests/FNA/FAudio.dll rename to Tests/FnaNative/FAudio.dll diff --git a/Tests/FNA/FNA3D.dll b/Tests/FnaNative/FNA3D.dll similarity index 100% rename from Tests/FNA/FNA3D.dll rename to Tests/FnaNative/FNA3D.dll diff --git a/Tests/FNA/SDL2.dll b/Tests/FnaNative/SDL2.dll similarity index 100% rename from Tests/FNA/SDL2.dll rename to Tests/FnaNative/SDL2.dll diff --git a/Tests/FNA/libFAudio.0.dylib b/Tests/FnaNative/libFAudio.0.dylib similarity index 100% rename from Tests/FNA/libFAudio.0.dylib rename to Tests/FnaNative/libFAudio.0.dylib diff --git a/Tests/FNA/libFAudio.so.0 b/Tests/FnaNative/libFAudio.so.0 similarity index 100% rename from Tests/FNA/libFAudio.so.0 rename to Tests/FnaNative/libFAudio.so.0 diff --git a/Tests/FNA/libFNA3D.0.dylib b/Tests/FnaNative/libFNA3D.0.dylib similarity index 100% rename from Tests/FNA/libFNA3D.0.dylib rename to Tests/FnaNative/libFNA3D.0.dylib diff --git a/Tests/FNA/libFNA3D.so.0 b/Tests/FnaNative/libFNA3D.so.0 similarity index 100% rename from Tests/FNA/libFNA3D.so.0 rename to Tests/FnaNative/libFNA3D.so.0 diff --git a/Tests/FNA/libMoltenVK.dylib b/Tests/FnaNative/libMoltenVK.dylib similarity index 100% rename from Tests/FNA/libMoltenVK.dylib rename to Tests/FnaNative/libMoltenVK.dylib diff --git a/Tests/FNA/libSDL2-2.0.0.dylib b/Tests/FnaNative/libSDL2-2.0.0.dylib similarity index 100% rename from Tests/FNA/libSDL2-2.0.0.dylib rename to Tests/FnaNative/libSDL2-2.0.0.dylib diff --git a/Tests/FNA/libSDL2-2.0.so.0 b/Tests/FnaNative/libSDL2-2.0.so.0 similarity index 100% rename from Tests/FNA/libSDL2-2.0.so.0 rename to Tests/FnaNative/libSDL2-2.0.so.0 diff --git a/Tests/FNA/libtheorafile.dll b/Tests/FnaNative/libtheorafile.dll similarity index 100% rename from Tests/FNA/libtheorafile.dll rename to Tests/FnaNative/libtheorafile.dll diff --git a/Tests/FNA/libtheorafile.dylib b/Tests/FnaNative/libtheorafile.dylib similarity index 100% rename from Tests/FNA/libtheorafile.dylib rename to Tests/FnaNative/libtheorafile.dylib diff --git a/Tests/FNA/libtheorafile.so b/Tests/FnaNative/libtheorafile.so similarity index 100% rename from Tests/FNA/libtheorafile.so rename to Tests/FnaNative/libtheorafile.so diff --git a/Tests/FNA/libvulkan.1.dylib b/Tests/FnaNative/libvulkan.1.dylib similarity index 100% rename from Tests/FNA/libvulkan.1.dylib rename to Tests/FnaNative/libvulkan.1.dylib diff --git a/Tests/Tests.FNA.csproj b/Tests/Tests.FNA.csproj index 8bb56c8..8f1fe64 100644 --- a/Tests/Tests.FNA.csproj +++ b/Tests/Tests.FNA.csproj @@ -30,7 +30,7 @@ PreserveNewest - + PreserveNewest %(Filename)%(Extension)