-
Notifications
You must be signed in to change notification settings - Fork 3
GemGui Controls
All controls inherit from the abstract class AControl
which has the following properties and methods.
Rendering.Sprite Sprite { get; set; }
IText Text { get; set; }
ViewEvents Events { get; set; }
RenderParameters RenderParameters { get; set; }
IRenderStyle Style { get; set; }
Settings.Options Options { get; set; }
Region Region { get; set; }
Padding Padding { get; set; }
virtual void Align(Region viewPort)
virtual void Update(double deltaTime)
virtual void Render(SpriteBatch batch, RenderTemplate template)
IDisposable AddTransformation(ITransformation transformation)
The control's style is controlled by a class that implements the abstract ARenderStyle
.
To define your own style, you need to override the following properties
virtual Func<AControl, ITransformation> FocusStyle
{
get { return control => new NoTransformation(); }
}
virtual Func<AControl, ITransformation> DefaultStyle
{
get { return control => new NoTransformation(); }
}
virtual Func<AControl, ITransformation> HoverStyle
{
get { return control => new NoTransformation(); }
}
virtual Func<AControl, ITransformation> ClickedStyle
{
get { return control => new NoTransformation(); }
}
When instantiating a new control, u can use the Styles.Style
class to specify the style.
Style.Transparent
Style.Bordered
Style.ColorMap(Color defaultColor,
Color colorMap)
Style.CustomisedTransparent(float focusedAlpha,
float hoverAlpha,
float defaultAlpha)
TransparentControlStyle()
The TransparentControlStyle
changes the control's alpha channel when an event is fired.
By changing the TransparentControlStyle's properties you can make your own effect.
[DefaultValue(1.0f)]
public float FocusAlpha { get; set; }
[DefaultValue(0.8f)]
public float HoverAlpha { get; set; }
[DefaultValue(0.6f)]
public float DefaultAlpha { get; set; }
[DefaultValue(4.0f)]
public float AlphaLerpStep { get; set; }
You can easily transform a control (region render parameters) by adding an intance of ITransformation
.
IDisposable AddTransformation(ITransformation transformation)
The disposable holds the reference to the list and the current transformation. Disposing it causes the effect to stop.
There are two predefined transformations.
-
The
PredicateTransformation
is instantiated with a predicate that causes the transformation to expire and an action that performs the actual transformation.public PredicateTransformation(Predicate<ITransformable> expirationPredicate, Action<double, ITransformable> transformer) button.AddTransformation(new PredicateTransformation( control=> control.Region.Position.X==0.0f, (deltaTime,control)=> control.RegionPosition.X--);
-
The
TimedTransformation
is instantiated with a value that indicates how long the transformation occurs in seconds before it expires and an action that performs the actual transformation.public TimedTransformation(double duration, Action<double, ITransformable> transformer)
Each control has an optional IText
instance which represents the controls' readable label.
The IText
has the following members
event EventHandler<TextEventArgs> OnTextChanged;
Region Region { get; }
Padding Padding { get; }
SpriteFont Font { get; }
string Value { get; set; }
IRenderStyle RenderStyle { get; }
RenderParameters RenderParameters { get; }
Alignment.AlignmentContext Alignment { get; }
The AlignmentContext
has the text to control alignment properties. Alignment is performed when a control changes size or manualy.
IHorizontalAlignable HorizontalAlignment { get; set; }
IVerticalAlignable VerticalAlignment { get; set; }
IAlignmentTransition Transition { get; set; }
The Alignments can be instantiated buy a static property in the HorizontalAlignment
/ VerticalAlignment
class.
Defaults are the Manual
alignments.
IAlignmentTransition
describes how a transition is performed when an alignment occurs. It can be either FixedTransition()
which the text takes the alignment position directly, or SmoothTransition()
which makes the text "move" towards the aligned position.
Additionally you can implement IVerticalAlignable
or IHorizontalAlignable
for your own alignment logic.
Defined Alignments
HorizontalAlignment.Left
HorizontalAlignment.Right
HorizontalAlignment.Center
HorizontalAlignment.Manual
HorizontalAlignment.RelativeTo(Func<float> relativeX)
VerticalAlignment.Left
VerticalAlignment.Right
VerticalAlignment.Center
VerticalAlignment.Manual
VerticalAlignment.RelativeTo(Func<float> relativeY)
Events can respond to touch / mouse / keyboard / gamepad. It is decided by the AggregationTarget
passed to the GemGui's constructor. If the hardware doesn't support it then nothing happens.
event GotFocus;
event LostFocus;
event Clicked;
event GotMouseCapture;
event LostMouseCapture;
[Flags]
enum AggregationTarget
{
None = 0,
Mouse = 1,
Keyboard = 2,
GamePad = 4,
Touch = 8,
All = Mouse | Keyboard | GamePad | Touch
}
[DefaultValue(true)]
bool IsVisible { get; set; }
[DefaultValue(true)]
bool IsEnabled { get; set; }
[DefaultValue(true)]
bool IsHoverEnabled { get; set; }
[DefaultValue(true)]
public bool IsFocusEnabled { get; set; }
[DefaultValue(true)]
public bool AllowTransformations { get; set; }
A style has render style parameters an instance of IControlDrawable
and ITextDrawable
which renders using spriteBatch and render instructions upon multiple events
event EventHandler<EventArgs> OnScaleChange;
[DefaultValue(Vector2.Zero)]
Vector2 Origin { get; set; }
[DefaultValue(Color.White)]
Color Color { get; set; }
[DefaultValue(Vector2.One)]
Vector2 Scale { get; set; }
[DefaultValue(1.0f)]
float Transparency { get; set; }
[DefaultValue(1.0f)]
float Layer { get; set; }
[DefaultValue(0.0f)]
float Rotation { get; set; }
[DefaultValue(SpriteEffects.None)]
SpriteEffects SpriteEffect { get; set; }
A Control may hold multiple sprites. Each sprite instance defines two properties and a readonly sprite container.
Texture2D Texture { get;} }
Rectangle? SourceRectangle { get; }
You can add a new sprite to the container by using
bool Add(string spriteId,
Texture2D texture,
Rectangle? sourceRectangle = null)
and switch to the new sprite with
bool SwitchSprite(string spriteId = "default")
Controls are aggregated using IAggregator
instances
interface IAggregator
{
bool IsEnabled { get; set; }
void Aggregate(GuiEntry entry, AggregationContext context);
}
The MouseControlAggregator
aggregates gui entries using mouse coordinates from InputManager.Mouse
which is an instance of MouseInputHelper
The ScriptAggregator
class ScriptAggregator<TInputHelper> : IAggregator
where TInputHelper : Input.IInputHelper
uses delegates to handle the events
public ScriptAggregator(TInputHelper inputHelper,
Func<TInputHelper,bool> next,
Func<TInputHelper,bool> previous,
Func<TInputHelper,bool> trigger)
Keyboard aggregator uses the ScriptAggregator
in combination with the KeyboardInputKeys
for keyboard GamePadInputButtons
for gamepad which is located in InputManager
.
[DefaultValue(Keys.Right)]
public Keys Right { get; set; }
[DefaultValue(Keys.Left)]
public Keys Left { get; set; }
[DefaultValue(Keys.Down)]
public Keys Next { get; set; }
[DefaultValue(Keys.Up)]
public Keys Previous { get; set; }
[DefaultValue(Keys.Enter)]
public Keys Trigger { get; set; }
You can change the Keys
to add your own control enumeration logic.
If you want to change how the controls are aggregated, you can resolve your own IAggregator
via an implementation of IConfigurationResolver
at the GemGui
's constructor