Skip to content

Commit

Permalink
Draw scrollbar thumbs.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote committed Dec 31, 2010
1 parent cf17bc7 commit d98e09e
Show file tree
Hide file tree
Showing 20 changed files with 441 additions and 417 deletions.
26 changes: 20 additions & 6 deletions OpenRA.Game/Widgets/ScrollPanelWidget.cs
Expand Up @@ -10,6 +10,7 @@

using System.Drawing;
using OpenRA.Graphics;
using System;

namespace OpenRA.Widgets
{
Expand All @@ -29,6 +30,7 @@ public class ScrollPanelWidget : Widget
Rectangle downButtonRect;
Rectangle backgroundRect;
Rectangle scrollbarRect;
Rectangle thumbRect;

public ScrollPanelWidget() : base() {}
protected ScrollPanelWidget(ScrollPanelWidget other)
Expand All @@ -39,6 +41,7 @@ protected ScrollPanelWidget(ScrollPanelWidget other)
downButtonRect = other.downButtonRect;
scrollbarRect = other.scrollbarRect;
backgroundRect = other.backgroundRect;
thumbRect = other.thumbRect;

UpPressed = other.UpPressed;
DownPressed = other.DownPressed;
Expand All @@ -49,20 +52,31 @@ public override void Draw( WorldRenderer wr )
{
if (!IsVisible())
return;


// Height/ContentHeight*Height
var ScrollbarHeight = RenderBounds.Height - 2 * ScrollbarWidth;

var thumbHeight = ContentHeight == 0 ? 0 : (int)(ScrollbarHeight*Math.Min(RenderBounds.Height*1f/ContentHeight, 1f));
var thumbOrigin = RenderBounds.Y + ScrollbarWidth + (int)((ScrollbarHeight - thumbHeight)*(-1f*ListOffset/(ContentHeight - RenderBounds.Height)));

backgroundRect = new Rectangle(RenderBounds.X, RenderBounds.Y, RenderBounds.Width - ScrollbarWidth, RenderBounds.Height);
upButtonRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Y, ScrollbarWidth, ScrollbarWidth);
downButtonRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Bottom - ScrollbarWidth, ScrollbarWidth, ScrollbarWidth);
scrollbarRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Y + ScrollbarWidth, ScrollbarWidth, RenderBounds.Height - 2 * ScrollbarWidth);

string upButtonBg = (UpPressed) ? "dialog3" : "dialog2";
string downButtonBg = (DownPressed) ? "dialog3" : "dialog2";
scrollbarRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Y + ScrollbarWidth, ScrollbarWidth, ScrollbarHeight);
thumbRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, thumbOrigin, ScrollbarWidth, thumbHeight);

string upButtonBg = UpPressed ? "dialog3" : "dialog2";
string downButtonBg = DownPressed ? "dialog3" : "dialog2";
string scrollbarBg = "dialog3";
string thumbBg = "dialog2";

WidgetUtils.DrawPanel(Background, backgroundRect);
WidgetUtils.DrawPanel(upButtonBg, upButtonRect);
WidgetUtils.DrawPanel(downButtonBg, downButtonRect);
WidgetUtils.DrawPanel(scrollbarBg, scrollbarRect);

if (thumbHeight > 0)
WidgetUtils.DrawPanel(thumbBg, thumbRect);

var upOffset = UpPressed ? 4 : 3;
var downOffset = DownPressed ? 4 : 3;
Expand Down Expand Up @@ -91,7 +105,7 @@ public override void Tick ()
if (UpPressed && ListOffset <= 0) ListOffset += ScrollVelocity;
if (DownPressed) ListOffset -= ScrollVelocity;

if (ListOffset > 0) ListOffset = 0;
ListOffset = Math.Min(0,Math.Max(RenderBounds.Height - ContentHeight, ListOffset));
}

public override bool LoseFocus (MouseInput mi)
Expand Down
20 changes: 13 additions & 7 deletions OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs
Expand Up @@ -21,8 +21,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
{
public class LobbyDelegate : IWidgetDelegate
{
Widget Players, LocalPlayerTemplate, RemotePlayerTemplate, EmptySlotTemplate, EmptySlotTemplateHost;

Widget LocalPlayerTemplate, RemotePlayerTemplate, EmptySlotTemplate, EmptySlotTemplateHost;
ScrollPanelWidget Players;
Dictionary<string, string> CountryNames;
string MapUid;
Map Map;
Expand All @@ -41,7 +41,7 @@ internal LobbyDelegate( [ObjectCreator.Param( "widget" )] Widget lobby, [ObjectC
CurrentColorPreview1 = Game.Settings.Player.Color1;
CurrentColorPreview2 = Game.Settings.Player.Color2;

Players = lobby.GetWidget("PLAYERS");
Players = lobby.GetWidget<ScrollPanelWidget>("PLAYERS");
LocalPlayerTemplate = Players.GetWidget("TEMPLATE_LOCAL");
RemotePlayerTemplate = Players.GetWidget("TEMPLATE_REMOTE");
EmptySlotTemplate = Players.GetWidget("TEMPLATE_EMPTY");
Expand Down Expand Up @@ -73,7 +73,6 @@ internal LobbyDelegate( [ObjectCreator.Param( "widget" )] Widget lobby, [ObjectC
};

CountryNames = Rules.Info["world"].Traits.WithInterface<OpenRA.Traits.CountryInfo>().ToDictionary(a => a.Race, a => a.Name);

CountryNames.Add("random", "Random");

var mapButton = lobby.GetWidget("CHANGEMAP_BUTTON");
Expand Down Expand Up @@ -295,7 +294,8 @@ void UpdatePlayerList()
// This causes problems for people who are in the process of editing their names (the widgets vanish from beneath them)
// Todo: handle this nicer
Players.Children.Clear();

Players.ContentHeight = 0;

int offset = 0;
foreach (var slot in orderManager.LobbyInfo.Slots)
{
Expand Down Expand Up @@ -448,12 +448,18 @@ void UpdatePlayerList()
template.Id = "SLOT_{0}".F(s.Index);
template.Parent = Players;

template.Bounds = new Rectangle(0, offset, template.Bounds.Width, template.Bounds.Height);
template.Bounds = new Rectangle(template.Bounds.X, template.Bounds.Y + offset, template.Bounds.Width, template.Bounds.Height);
template.IsVisible = () => true;
Players.AddChild(template);

offset += template.Bounds.Height;
}

// Hack to ensure correct ContentHeight
if (Players.ContentHeight == 0)
Players.ContentHeight += template.Bounds.Y;

Players.ContentHeight += template.Bounds.Height;
}
}

bool SpawnPointAvailable(int index) { return (index == 0) || orderManager.LobbyInfo.Clients.All(c => c.SpawnPoint != index); }
Expand Down
4 changes: 4 additions & 0 deletions OpenRA.Mods.RA/Widgets/Delegates/MapChooserDelegate.cs
Expand Up @@ -74,6 +74,10 @@ public class MapChooserDelegate : IWidgetDelegate
ml.AddChild(template);

offset += template.Bounds.Height;

// Padding hack
if (ml.ContentHeight == 0)
ml.ContentHeight += 2*template.Bounds.Y;
ml.ContentHeight += template.Bounds.Height;
}
}
Expand Down
6 changes: 6 additions & 0 deletions OpenRA.Mods.RA/Widgets/Delegates/MusicPlayerDelegate.cs
Expand Up @@ -133,7 +133,13 @@ public MusicPlayerDelegate()
ml.AddChild(template);

offset += template.Bounds.Height;

// Padding hack
if (ml.ContentHeight == 0)
ml.ContentHeight += 2*template.Bounds.Y;

ml.ContentHeight += template.Bounds.Height;

}
}

Expand Down
4 changes: 4 additions & 0 deletions OpenRA.Mods.RA/Widgets/Delegates/ReplayBrowserDelegate.cs
Expand Up @@ -116,6 +116,10 @@ void AddReplay(ScrollPanelWidget list, string filename, LabelWidget template, re
CurrentReplay = filename;

offset += template.Bounds.Height;
// Padding hack
if (list.ContentHeight == 0)
list.ContentHeight += 2*template.Bounds.Y;

list.ContentHeight += template.Bounds.Height;
}
}
Expand Down
4 changes: 4 additions & 0 deletions OpenRA.Mods.RA/Widgets/Delegates/ServerBrowserDelegate.cs
Expand Up @@ -183,6 +183,10 @@ void RefreshServerList(IEnumerable<GameServer> games)
if (i == 0) currentServer = game;

offset += template.Bounds.Height;
// Padding hack
if (sl.ContentHeight == 0)
sl.ContentHeight += 2*template.Bounds.Y;

sl.ContentHeight += template.Bounds.Height;
i++;
}
Expand Down

0 comments on commit d98e09e

Please sign in to comment.