Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ycanardeau/saruhashi
Saruhashi is a UI framework for MonoGame.
https://github.com/ycanardeau/saruhashi
csharp gui monogame
Last synced: about 9 hours ago
JSON representation
Saruhashi is a UI framework for MonoGame.
- Host: GitHub
- URL: https://github.com/ycanardeau/saruhashi
- Owner: ycanardeau
- License: mit
- Created: 2020-07-25T04:55:39.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-04-23T09:35:19.000Z (almost 2 years ago)
- Last Synced: 2024-04-27T05:21:18.224Z (9 months ago)
- Topics: csharp, gui, monogame
- Language: C#
- Homepage:
- Size: 740 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Saruhashi
Saruhashi is a UI framework for [MonoGame](https://github.com/MonoGame/MonoGame). This project is mainly used by [OpenNSPW](https://github.com/OpenNSPW/OpenNSPW).## Installation
```
PM> Install-Package Aigamo.Saruhashi.MonoGame
```## Usage
### Minimal Configuration
```csharp
using Aigamo.Saruhashi;
using Aigamo.Saruhashi.MonoGame;
using Microsoft.Xna.Framework;
using MonoGame.Extended.Input.InputListeners;
using DrawingRectangle = System.Drawing.Rectangle;
using SaruhashiKeys = Aigamo.Saruhashi.Keys;
using SaruhashiMouseListener = Aigamo.Saruhashi.MonoGame.MouseListener;
using XnaKeys = Microsoft.Xna.Framework.Input.Keys;private WindowManager _windowManager;
protected override void LoadContent()
{
var mouseListener = new SaruhashiMouseListener();
var keyboardListener = new KeyboardListener(new KeyboardListenerSettings
{
InitialDelayMilliseconds = 500,
RepeatDelayMilliseconds = 30,
});
Components.Add(new InputListenerComponent(this, mouseListener, keyboardListener));_windowManager = new WindowManager(new DrawingRectangle(0, 0, 1024, 768), new MonoGameGraphicsFactory(_spriteBatch));
mouseListener.MouseDown += (sender, e) => _windowManager.OnMouseDown(e);
mouseListener.MouseMove += (sender, e) => _windowManager.OnMouseMove(e);
mouseListener.MouseUp += (sender, e) => _windowManager.OnMouseUp(e);
keyboardListener.KeyPressed += (sender, e) => _windowManager.OnKeyDown(new KeyEventArgs((SaruhashiKeys)e.Key));
keyboardListener.KeyReleased += (sender, e) => _windowManager.OnKeyUp(new KeyEventArgs((SaruhashiKeys)e.Key));
Window.TextInput += (sender, e) => _windowManager.OnKeyPress(new KeyPressEventArgs(e.Character));
}private readonly RasterizerState _rasterizerState = new RasterizerState
{
ScissorTestEnable = true,
};protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);base.Draw(gameTime);
_windowManager.Draw();
}
```### Form
```csharp
var form = new Form();
WindowManager.Root.Controls.Add(form);
form.Show();
```### Button
```csharp
var button = new Button
{
GetText = () => $"{Environment.TickCount}",
};
button.Click += (sender, e) => Game.Exit();
WindowManager.Root.Controls.Add(button);
```### CheckBox
```csharp
var @checked = false;
var checkBox = new CheckBox
{
Appearance = Appearance.Button,
AutoCheck = false,
IsChecked = () => @checked,
};
checkBox.Click += (sender, e) => @checked = !@checked;
WindowManager.Root.Controls.Add(checkBox);
```### RadioButton
```csharp
var @checked = false;
var radioButton = new RadioButton
{
Appearance = Appearance.Button,
AutoCheck = false,
IsChecked = () => @checked,
};
radioButton.Click += (sender, e) => @checked = !@checked;
WindowManager.Root.Controls.Add(radioButton);
```