Skip to content

Commit 70836d9

Browse files
committed
huge change! made the UserInterface no longer a static class, there's now UserInterface.Active that point to the currently active UI.
1 parent 6d3575b commit 70836d9

21 files changed

+249
-220
lines changed

GeonBit.UI/GeonBit.UI/DrawUtils.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public class DrawUtils
3030
public void PushRenderTarget(RenderTarget2D target)
3131
{
3232
// sanity check - make sure we are in use-render-target mode
33-
if (!UserInterface.UseRenderTarget)
33+
if (!UserInterface.Active.UseRenderTarget)
3434
{
35-
throw new System.Exception("UserInterface.UseRenderTarget must be 'true' to use render-target features!");
35+
throw new System.Exception("UserInterface.Active.UseRenderTarget must be 'true' to use render-target features!");
3636
}
3737

3838
// add render target
@@ -151,7 +151,7 @@ public virtual void DrawSurface(SpriteBatch spriteBatch, Texture2D texture, Rect
151151
Rectangle destRect = new Rectangle();
152152

153153
// factor used to scale between source in texture file and dest on the screen
154-
float ScaleFactor = UserInterface.GlobalScale * frameScale;
154+
float ScaleFactor = UserInterface.Active.GlobalScale * frameScale;
155155

156156
// calc the surface frame size in texture file (Src) and for drawing destination (Dest)
157157
Vector2 frameSizeSrcVec = new Vector2(texture.Width, texture.Height) * textureFrameWidth;
@@ -559,7 +559,7 @@ protected virtual void UpdateRenderTarget(SpriteBatch spriteBatch)
559559
}
560560
else
561561
{
562-
newRenderTarget = UserInterface.RenderTarget;
562+
newRenderTarget = UserInterface.Active.RenderTarget;
563563
}
564564

565565
// only if changed, set render target (costly function)

GeonBit.UI/GeonBit.UI/Entities/Button.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,12 @@ override protected void DrawEntity(SpriteBatch spriteBatch)
171171
if (frameSize.Length() > 0)
172172
{
173173
float scale = frameSize.Y > 0 ? Scale : 1f;
174-
UserInterface.DrawUtils.DrawSurface(spriteBatch, texture, _destRect, frameSize, 1, FillColor, scale);
174+
UserInterface.Active.DrawUtils.DrawSurface(spriteBatch, texture, _destRect, frameSize, 1, FillColor, scale);
175175
}
176176
// draw the button background without frame (just stretch texture)
177177
else
178178
{
179-
UserInterface.DrawUtils.DrawImage(spriteBatch, texture, _destRect, FillColor, 1);
179+
UserInterface.Active.DrawUtils.DrawImage(spriteBatch, texture, _destRect, FillColor, 1);
180180
}
181181

182182
// call base draw function

GeonBit.UI/GeonBit.UI/Entities/CheckBox.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ override protected void DrawEntity(SpriteBatch spriteBatch)
108108
Texture2D texture = GetTexture();
109109

110110
// calculate actual size
111-
Vector2 actualSize = CHECKBOX_SIZE * UserInterface.GlobalScale;
111+
Vector2 actualSize = CHECKBOX_SIZE * UserInterface.Active.GlobalScale;
112112

113113
// update internal dest rect to adjust text position
114114
_destRectInternal.X += (int)(actualSize.X * 0.75f);
@@ -118,7 +118,7 @@ override protected void DrawEntity(SpriteBatch spriteBatch)
118118
(int)(_destRect.Y + _destRect.Height / 2 - actualSize.Y / 2),
119119
(int)(actualSize.X),
120120
(int)(actualSize.Y));
121-
dest = UserInterface.DrawUtils.ScaleRect(dest, Scale);
121+
dest = UserInterface.Active.DrawUtils.ScaleRect(dest, Scale);
122122

123123
// source rect
124124
Rectangle src = new Rectangle(0, 0, texture.Width, texture.Height);

GeonBit.UI/GeonBit.UI/Entities/Dropdown.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ private void OnDropDownVisibilityChange()
280280

281281
// focus on selectlist
282282
_selectList.IsFocused = true;
283-
UserInterface.ActiveEntity = _selectList;
283+
UserInterface.Active.ActiveEntity = _selectList;
284284

285285
// update destination rectangles
286286
_selectList.UpdateDestinationRects();

GeonBit.UI/GeonBit.UI/Entities/Entity.cs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public Vector2 EntityDefaultSize
367367
protected virtual void DoOnFirstUpdate()
368368
{
369369
// call the spawn event
370-
UserInterface.OnEntitySpawn?.Invoke(this);
370+
UserInterface.Active.OnEntitySpawn?.Invoke(this);
371371

372372
// make parent dirty
373373
if (_parent != null) { _parent.MarkAsDirty(); }
@@ -419,19 +419,19 @@ public void UpdateStyle(StyleSheet updates)
419419
}
420420

421421
/// <summary>Get extra space after with current UI scale applied. </summary>
422-
protected Vector2 _scaledSpaceAfter { get { return SpaceAfter * UserInterface.GlobalScale; } }
422+
protected Vector2 _scaledSpaceAfter { get { return SpaceAfter * UserInterface.Active.GlobalScale; } }
423423

424424
/// <summary>Get extra space before with current UI scale applied. </summary>
425-
protected Vector2 _scaledSpaceBefore { get { return SpaceBefore * UserInterface.GlobalScale; } }
425+
protected Vector2 _scaledSpaceBefore { get { return SpaceBefore * UserInterface.Active.GlobalScale; } }
426426

427427
/// <summary>Get size with current UI scale applied. </summary>
428-
protected Vector2 _scaledSize { get { return _size * UserInterface.GlobalScale; } }
428+
protected Vector2 _scaledSize { get { return _size * UserInterface.Active.GlobalScale; } }
429429

430430
/// <summary>Get offset with current UI scale applied. </summary>
431-
protected Vector2 _scaledOffset { get { return _offset * UserInterface.GlobalScale; } }
431+
protected Vector2 _scaledOffset { get { return _offset * UserInterface.Active.GlobalScale; } }
432432

433433
/// <summary>Get offset with current UI scale applied. </summary>
434-
protected Vector2 _scaledPadding { get { return Padding * UserInterface.GlobalScale; } }
434+
protected Vector2 _scaledPadding { get { return Padding * UserInterface.Active.GlobalScale; } }
435435

436436
/// <summary>
437437
/// Set / get visibility.
@@ -894,9 +894,9 @@ virtual public void Draw(SpriteBatch spriteBatch)
894894
DrawEntityOutline(spriteBatch);
895895

896896
// draw the entity itself
897-
UserInterface.DrawUtils.StartDraw(spriteBatch, _isCurrentlyDisabled);
897+
UserInterface.Active.DrawUtils.StartDraw(spriteBatch, _isCurrentlyDisabled);
898898
DrawEntity(spriteBatch);
899-
UserInterface.DrawUtils.EndDraw(spriteBatch);
899+
UserInterface.Active.DrawUtils.EndDraw(spriteBatch);
900900

901901
// do stuff before drawing children
902902
BeforeDrawChildren(spriteBatch);
@@ -974,9 +974,9 @@ virtual protected void DrawEntityShadow(SpriteBatch spriteBatch)
974974
}
975975

976976
// draw with shadow effect
977-
UserInterface.DrawUtils.StartDrawSilhouette(spriteBatch);
977+
UserInterface.Active.DrawUtils.StartDrawSilhouette(spriteBatch);
978978
DrawEntity(spriteBatch);
979-
UserInterface.DrawUtils.EndDraw(spriteBatch);
979+
UserInterface.Active.DrawUtils.EndDraw(spriteBatch);
980980

981981
// return position and colors back to what they were
982982
_destRect.X -= (int)ShadowOffset.X;
@@ -1024,7 +1024,7 @@ virtual protected void DrawEntityOutline(SpriteBatch spriteBatch)
10241024
SetStyleProperty(StylePropertyIds.FillColor, new StyleProperty(outlineColor), oldState, markAsDirty: false);
10251025

10261026
// draw the entity outline
1027-
UserInterface.DrawUtils.StartDrawSilhouette(spriteBatch);
1027+
UserInterface.Active.DrawUtils.StartDrawSilhouette(spriteBatch);
10281028
_destRect.Location = originalDest.Location + new Point(-outlineWidth, 0);
10291029
DrawEntity(spriteBatch);
10301030
_destRect.Location = originalDest.Location + new Point(0, -outlineWidth);
@@ -1033,7 +1033,7 @@ virtual protected void DrawEntityOutline(SpriteBatch spriteBatch)
10331033
DrawEntity(spriteBatch);
10341034
_destRect.Location = originalDest.Location + new Point(0, outlineWidth);
10351035
DrawEntity(spriteBatch);
1036-
UserInterface.DrawUtils.EndDraw(spriteBatch);
1036+
UserInterface.Active.DrawUtils.EndDraw(spriteBatch);
10371037

10381038
// turn back to previous fill color
10391039
SetStyleProperty(StylePropertyIds.FillColor, new StyleProperty(oldFill), oldState, markAsDirty: false);
@@ -1059,7 +1059,7 @@ virtual protected void DrawEntity(SpriteBatch spriteBatch)
10591059
virtual protected void OnAfterDraw(SpriteBatch spriteBatch)
10601060
{
10611061
AfterDraw?.Invoke(this);
1062-
UserInterface.AfterDraw?.Invoke(this);
1062+
UserInterface.Active.AfterDraw?.Invoke(this);
10631063
}
10641064

10651065
/// <summary>
@@ -1069,7 +1069,7 @@ virtual protected void OnAfterDraw(SpriteBatch spriteBatch)
10691069
virtual protected void OnBeforeDraw(SpriteBatch spriteBatch)
10701070
{
10711071
BeforeDraw?.Invoke(this);
1072-
UserInterface.BeforeDraw?.Invoke(this);
1072+
UserInterface.Active.BeforeDraw?.Invoke(this);
10731073
}
10741074

10751075
/// <summary>
@@ -1453,7 +1453,7 @@ protected Entity GetPreviousEntity(bool skipInvisibles = false)
14531453
virtual protected void DoOnMouseDown(InputHelper input)
14541454
{
14551455
OnMouseDown?.Invoke(this);
1456-
UserInterface.OnMouseDown?.Invoke(this);
1456+
UserInterface.Active.OnMouseDown?.Invoke(this);
14571457
}
14581458

14591459
/// <summary>
@@ -1463,7 +1463,7 @@ virtual protected void DoOnMouseDown(InputHelper input)
14631463
virtual protected void DoOnMouseReleased(InputHelper input)
14641464
{
14651465
OnMouseReleased?.Invoke(this);
1466-
UserInterface.OnMouseReleased?.Invoke(this);
1466+
UserInterface.Active.OnMouseReleased?.Invoke(this);
14671467
}
14681468

14691469
/// <summary>
@@ -1473,7 +1473,7 @@ virtual protected void DoOnMouseReleased(InputHelper input)
14731473
virtual protected void DoOnClick(InputHelper input)
14741474
{
14751475
OnClick?.Invoke(this);
1476-
UserInterface.OnClick?.Invoke(this);
1476+
UserInterface.Active.OnClick?.Invoke(this);
14771477
}
14781478

14791479
/// <summary>
@@ -1483,7 +1483,7 @@ virtual protected void DoOnClick(InputHelper input)
14831483
virtual protected void DoWhileMouseDown(InputHelper input)
14841484
{
14851485
WhileMouseDown?.Invoke(this);
1486-
UserInterface.WhileMouseDown?.Invoke(this);
1486+
UserInterface.Active.WhileMouseDown?.Invoke(this);
14871487
}
14881488

14891489
/// <summary>
@@ -1493,7 +1493,7 @@ virtual protected void DoWhileMouseDown(InputHelper input)
14931493
virtual protected void DoWhileMouseHover(InputHelper input)
14941494
{
14951495
WhileMouseHover?.Invoke(this);
1496-
UserInterface.WhileMouseHover?.Invoke(this);
1496+
UserInterface.Active.WhileMouseHover?.Invoke(this);
14971497
}
14981498

14991499
/// <summary>
@@ -1502,7 +1502,7 @@ virtual protected void DoWhileMouseHover(InputHelper input)
15021502
virtual protected void DoOnValueChange()
15031503
{
15041504
OnValueChange?.Invoke(this);
1505-
UserInterface.OnValueChange?.Invoke(this);
1505+
UserInterface.Active.OnValueChange?.Invoke(this);
15061506
}
15071507

15081508
/// <summary>
@@ -1512,7 +1512,7 @@ virtual protected void DoOnValueChange()
15121512
virtual protected void DoOnMouseEnter(InputHelper input)
15131513
{
15141514
OnMouseEnter?.Invoke(this);
1515-
UserInterface.OnMouseEnter?.Invoke(this);
1515+
UserInterface.Active.OnMouseEnter?.Invoke(this);
15161516
}
15171517

15181518
/// <summary>
@@ -1522,7 +1522,7 @@ virtual protected void DoOnMouseEnter(InputHelper input)
15221522
virtual protected void DoOnMouseLeave(InputHelper input)
15231523
{
15241524
OnMouseLeave?.Invoke(this);
1525-
UserInterface.OnMouseLeave?.Invoke(this);
1525+
UserInterface.Active.OnMouseLeave?.Invoke(this);
15261526
}
15271527

15281528
/// <summary>
@@ -1532,7 +1532,7 @@ virtual protected void DoOnMouseLeave(InputHelper input)
15321532
virtual protected void DoOnStartDrag(InputHelper input)
15331533
{
15341534
OnStartDrag?.Invoke(this);
1535-
UserInterface.OnStartDrag?.Invoke(this);
1535+
UserInterface.Active.OnStartDrag?.Invoke(this);
15361536
}
15371537

15381538
/// <summary>
@@ -1542,7 +1542,7 @@ virtual protected void DoOnStartDrag(InputHelper input)
15421542
virtual protected void DoOnStopDrag(InputHelper input)
15431543
{
15441544
OnStopDrag?.Invoke(this);
1545-
UserInterface.OnStopDrag?.Invoke(this);
1545+
UserInterface.Active.OnStopDrag?.Invoke(this);
15461546
}
15471547

15481548
/// <summary>
@@ -1552,7 +1552,7 @@ virtual protected void DoOnStopDrag(InputHelper input)
15521552
virtual protected void DoWhileDragging(InputHelper input)
15531553
{
15541554
WhileDragging?.Invoke(this);
1555-
UserInterface.WhileDragging?.Invoke(this);
1555+
UserInterface.Active.WhileDragging?.Invoke(this);
15561556
}
15571557

15581558
/// <summary>
@@ -1562,7 +1562,7 @@ virtual protected void DoWhileDragging(InputHelper input)
15621562
virtual protected void DoOnMouseWheelScroll(InputHelper input)
15631563
{
15641564
OnMouseWheelScroll?.Invoke(this);
1565-
UserInterface.OnMouseWheelScroll?.Invoke(this);
1565+
UserInterface.Active.OnMouseWheelScroll?.Invoke(this);
15661566
}
15671567

15681568
/// <summary>
@@ -1572,7 +1572,7 @@ virtual protected void DoOnMouseWheelScroll(InputHelper input)
15721572
virtual protected void DoAfterUpdate(InputHelper input)
15731573
{
15741574
AfterUpdate?.Invoke(this);
1575-
UserInterface.AfterUpdate?.Invoke(this);
1575+
UserInterface.Active.AfterUpdate?.Invoke(this);
15761576
}
15771577

15781578
/// <summary>
@@ -1582,7 +1582,7 @@ virtual protected void DoOnVisibilityChange()
15821582
{
15831583
// invoke callbacks
15841584
OnVisiblityChange?.Invoke(this);
1585-
UserInterface.OnVisiblityChange?.Invoke(this);
1585+
UserInterface.Active.OnVisiblityChange?.Invoke(this);
15861586
}
15871587

15881588
/// <summary>
@@ -1592,7 +1592,7 @@ virtual protected void DoOnVisibilityChange()
15921592
virtual protected void DoBeforeUpdate(InputHelper input)
15931593
{
15941594
BeforeUpdate?.Invoke(this);
1595-
UserInterface.BeforeUpdate?.Invoke(this);
1595+
UserInterface.Active.BeforeUpdate?.Invoke(this);
15961596
}
15971597

15981598
/// <summary>
@@ -1873,7 +1873,7 @@ virtual public void Update(InputHelper input, ref Entity targetEntity, ref Entit
18731873
}
18741874

18751875
// handle mouse wheel scroll over this entity
1876-
if (targetEntity == this || UserInterface.ActiveEntity == this)
1876+
if (targetEntity == this || UserInterface.Active.ActiveEntity == this)
18771877
{
18781878
if (input.MouseWheelChange != 0)
18791879
{

GeonBit.UI/GeonBit.UI/Entities/HorizontalLine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ override protected void DrawEntity(SpriteBatch spriteBatch)
5454
Texture2D texture = Resources.HorizontalLineTexture;
5555

5656
// draw panel
57-
UserInterface.DrawUtils.DrawSurface(spriteBatch, texture, _destRect, FRAME_WIDTH, 1, FillColor);
57+
UserInterface.Active.DrawUtils.DrawSurface(spriteBatch, texture, _destRect, FRAME_WIDTH, 1, FillColor);
5858

5959
// call base draw function
6060
base.DrawEntity(spriteBatch);

GeonBit.UI/GeonBit.UI/Entities/Icon.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ override protected void DrawEntity(SpriteBatch spriteBatch)
189189
// get background dest rect
190190
Rectangle dest = _destRect;
191191
dest.X -= BackgroundSize / 2; dest.Y -= BackgroundSize / 2; dest.Width += BackgroundSize; dest.Height += BackgroundSize;
192-
UserInterface.DrawUtils.DrawImage(spriteBatch, Resources.IconBackgroundTexture, dest, GetActiveStyle("BackgroundColor").asColor);
192+
UserInterface.Active.DrawUtils.DrawImage(spriteBatch, Resources.IconBackgroundTexture, dest, GetActiveStyle("BackgroundColor").asColor);
193193
}
194194

195195
// now draw the image itself

GeonBit.UI/GeonBit.UI/Entities/Image.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ override protected void DrawEntity(SpriteBatch spriteBatch)
7676
{
7777
// panel mode
7878
case ImageDrawMode.Panel:
79-
UserInterface.DrawUtils.DrawSurface(spriteBatch, Texture, _destRect, FrameWidth, Scale, FillColor);
79+
UserInterface.Active.DrawUtils.DrawSurface(spriteBatch, Texture, _destRect, FrameWidth, Scale, FillColor);
8080
break;
8181

8282
// stretch mode
8383
case ImageDrawMode.Stretch:
84-
UserInterface.DrawUtils.DrawImage(spriteBatch, Texture, _destRect, FillColor, Scale, SourceRectangle);
84+
UserInterface.Active.DrawUtils.DrawImage(spriteBatch, Texture, _destRect, FillColor, Scale, SourceRectangle);
8585
break;
8686
}
8787

GeonBit.UI/GeonBit.UI/Entities/LineSpace.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public LineSpace(int spacesCount = 1) :
3838
// set size based on space count
3939
_size.X = 0f;
4040
_size.Y = spacesCount != 0 ?
41-
SpaceSize * UserInterface.GlobalScale * System.Math.Max(spacesCount, 0) : -1;
41+
SpaceSize * UserInterface.Active.GlobalScale * System.Math.Max(spacesCount, 0) : -1;
4242

4343
// default padding and spacing zero
4444
SpaceAfter = SpaceBefore = Padding = Vector2.Zero;

GeonBit.UI/GeonBit.UI/Entities/Panel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ protected override void BeforeDrawChildren(SpriteBatch spriteBatch)
166166
spriteBatch.GraphicsDevice.Clear(Color.Transparent);
167167

168168
// bind the render target
169-
UserInterface.DrawUtils.PushRenderTarget(_renderTarget);
169+
UserInterface.Active.DrawUtils.PushRenderTarget(_renderTarget);
170170

171171
// set internal dest rect
172172
_originalInternalDestRect = _destRectInternal;
@@ -216,7 +216,7 @@ protected override void AfterDrawChildren(SpriteBatch spriteBatch)
216216
if (_renderTarget != null)
217217
{
218218
// unbind the render target
219-
UserInterface.DrawUtils.PopRenderTarget();
219+
UserInterface.Active.DrawUtils.PopRenderTarget();
220220

221221
// fix children's dest rect for the update loop
222222
foreach (Entity child in GetChildren())
@@ -232,9 +232,9 @@ protected override void AfterDrawChildren(SpriteBatch spriteBatch)
232232
_destRectInternal = _originalInternalDestRect;
233233

234234
// draw the render target itself
235-
UserInterface.DrawUtils.StartDraw(spriteBatch, IsDisabled());
235+
UserInterface.Active.DrawUtils.StartDraw(spriteBatch, IsDisabled());
236236
spriteBatch.Draw(_renderTarget, _destRectInternal, Color.White);
237-
UserInterface.DrawUtils.EndDraw(spriteBatch);
237+
UserInterface.Active.DrawUtils.EndDraw(spriteBatch);
238238

239239
// fix scrollbar positioning etc
240240
_destRectInternal.Y -= _scrollbar.Value;
@@ -280,7 +280,7 @@ override protected void DrawEntity(SpriteBatch spriteBatch)
280280
Vector2 frameSize = new Vector2(data.FrameWidth, data.FrameHeight);
281281

282282
// draw panel
283-
UserInterface.DrawUtils.DrawSurface(spriteBatch, texture, _destRect, frameSize, 1f, FillColor, Scale);
283+
UserInterface.Active.DrawUtils.DrawSurface(spriteBatch, texture, _destRect, frameSize, 1f, FillColor, Scale);
284284
}
285285

286286
// call base draw function

0 commit comments

Comments
 (0)