Code:
class UIWidget extends Object
abstract;
var Vector2D Location, Size;
var string Label;
var delegate<ClickCallback> Click;
delegate ClickCallback();
function Update( Canvas C, Vector2D mouse, bool bMouseClicked );
function bool MouseOver( Vector2D mouse )
{
return ( mouse.x > Location.x && mouse.y > Location.y && mouse.x < Location.x + Size.x && mouse.y < Location.y + Size.y );
}
Code:
class CustomHUD extends HUD;
var array<UIWidget> AllWidgets;
// called from PostRender
function Update()
{
local UIWidget W;
foreach AllWidgets(W)
{
W.Update(Canvas, mousePosition, bMouseWasClicked);
}
}
event PostBeginPlay()
{
local UIWidget W;
W = new (self) class'UIButton';
W.Location.x = 100;
W.Location.y = 100;
W.Size.x = 128;
W.Size.y = 48;
W.Label = "Click me!";
W.Click = ButtonHandler1;
AllWidgets.AddItem(W);
}
function ButtonHandler1()
{
`log("Hurrah!");
}
Code:
class UIButton extends UIWidget;
function Update( Canvas C, Vector2D mouse, bool bMouseClicked )
{
// button rendering here...
// ...
if( bMouseClicked && MouseOver(mouse) )
{
Click();
}
}
Bookmarks