Proper mouseover support.
This commit is contained in:
@@ -117,7 +117,7 @@ namespace OpenRA.Widgets
|
|||||||
var s = font.Measure(text);
|
var s = font.Measure(text);
|
||||||
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
|
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
|
||||||
|
|
||||||
DrawBackground("button", rb, disabled, Depressed, rb.Contains(Viewport.LastMousePos));
|
DrawBackground("button", rb, disabled, Depressed, Widget.MouseOverWidget == this);
|
||||||
font.DrawText(text, new int2(rb.X + (UsableWidth - s.X)/ 2, rb.Y + (Bounds.Height - s.Y) / 2) + stateOffset,
|
font.DrawText(text, new int2(rb.X + (UsableWidth - s.X)/ 2, rb.Y + (Bounds.Height - s.Y) / 2) + stateOffset,
|
||||||
disabled ? Color.Gray : Color.White);
|
disabled ? Color.Gray : Color.White);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace OpenRA.Widgets
|
|||||||
var check = new Rectangle(rect.Location, new Size(Bounds.Height, Bounds.Height));
|
var check = new Rectangle(rect.Location, new Size(Bounds.Height, Bounds.Height));
|
||||||
var state = disabled ? "checkbox-disabled" :
|
var state = disabled ? "checkbox-disabled" :
|
||||||
Depressed && HasPressedState ? "checkbox-pressed" :
|
Depressed && HasPressedState ? "checkbox-pressed" :
|
||||||
RenderBounds.Contains(Viewport.LastMousePos) ? "checkbox-hover" :
|
Widget.MouseOverWidget == this ? "checkbox-hover" :
|
||||||
"checkbox";
|
"checkbox";
|
||||||
|
|
||||||
WidgetUtils.DrawPanel(state, check);
|
WidgetUtils.DrawPanel(state, check);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ namespace OpenRA.Widgets
|
|||||||
{
|
{
|
||||||
IsVisible = () => false;
|
IsVisible = () => false;
|
||||||
VisualHeight = 0;
|
VisualHeight = 0;
|
||||||
|
IgnoreChildMouseOver = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ScrollItemWidget(ScrollItemWidget other)
|
protected ScrollItemWidget(ScrollItemWidget other)
|
||||||
@@ -28,6 +29,7 @@ namespace OpenRA.Widgets
|
|||||||
{
|
{
|
||||||
IsVisible = () => false;
|
IsVisible = () => false;
|
||||||
VisualHeight = 0;
|
VisualHeight = 0;
|
||||||
|
IgnoreChildMouseOver = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Func<bool> IsSelected = () => false;
|
public Func<bool> IsSelected = () => false;
|
||||||
@@ -35,7 +37,7 @@ namespace OpenRA.Widgets
|
|||||||
public override void Draw()
|
public override void Draw()
|
||||||
{
|
{
|
||||||
var state = IsSelected() ? "scrollitem-selected" :
|
var state = IsSelected() ? "scrollitem-selected" :
|
||||||
RenderBounds.Contains(Viewport.LastMousePos) ? "scrollitem-hover" :
|
Widget.MouseOverWidget == this ? "scrollitem-hover" :
|
||||||
null;
|
null;
|
||||||
|
|
||||||
if (state != null)
|
if (state != null)
|
||||||
|
|||||||
@@ -76,19 +76,21 @@ namespace OpenRA.Widgets
|
|||||||
scrollbarRect = new Rectangle(rb.Right - ScrollbarWidth, rb.Y + ScrollbarWidth - 1, ScrollbarWidth, ScrollbarHeight + 2);
|
scrollbarRect = new Rectangle(rb.Right - ScrollbarWidth, rb.Y + ScrollbarWidth - 1, ScrollbarWidth, ScrollbarHeight + 2);
|
||||||
thumbRect = new Rectangle(rb.Right - ScrollbarWidth, thumbOrigin, ScrollbarWidth, thumbHeight);
|
thumbRect = new Rectangle(rb.Right - ScrollbarWidth, thumbOrigin, ScrollbarWidth, thumbHeight);
|
||||||
|
|
||||||
|
var upHover = Widget.MouseOverWidget == this && upButtonRect.Contains(Viewport.LastMousePos);
|
||||||
|
var upDisabled = thumbHeight == 0 || ListOffset >= 0;
|
||||||
|
|
||||||
|
var downHover = Widget.MouseOverWidget == this && downButtonRect.Contains(Viewport.LastMousePos);
|
||||||
|
var downDisabled = thumbHeight == 0 || ListOffset <= Bounds.Height - ContentHeight;
|
||||||
|
|
||||||
|
var thumbHover = Widget.MouseOverWidget == this && thumbRect.Contains(Viewport.LastMousePos);
|
||||||
WidgetUtils.DrawPanel(Background, backgroundRect);
|
WidgetUtils.DrawPanel(Background, backgroundRect);
|
||||||
WidgetUtils.DrawPanel("scrollpanel-bg", scrollbarRect);
|
WidgetUtils.DrawPanel("scrollpanel-bg", scrollbarRect);
|
||||||
ButtonWidget.DrawBackground("button", upButtonRect, (thumbHeight == 0 || ListOffset >= 0),
|
ButtonWidget.DrawBackground("button", upButtonRect, upDisabled, UpPressed, upHover);
|
||||||
UpPressed, upButtonRect.Contains(Viewport.LastMousePos));
|
ButtonWidget.DrawBackground("button", downButtonRect, downDisabled, DownPressed, downHover);
|
||||||
ButtonWidget.DrawBackground("button", downButtonRect, (thumbHeight == 0 || ListOffset <= Bounds.Height - ContentHeight),
|
|
||||||
DownPressed, downButtonRect.Contains(Viewport.LastMousePos));
|
|
||||||
|
|
||||||
if (thumbHeight > 0)
|
if (thumbHeight > 0)
|
||||||
ButtonWidget.DrawBackground("scrollthumb", thumbRect, false, (Focused && thumbRect.Contains(Viewport.LastMousePos)),
|
ButtonWidget.DrawBackground("scrollthumb", thumbRect, false, Focused && thumbHover, thumbHover);
|
||||||
thumbRect.Contains(Viewport.LastMousePos));
|
|
||||||
|
|
||||||
var upDisabled = thumbHeight == 0 || ListOffset >= 0;
|
|
||||||
var downDisabled = thumbHeight == 0 || ListOffset <= Bounds.Height - ContentHeight;
|
|
||||||
var upOffset = !UpPressed || upDisabled ? 4 : 4 + ButtonDepth;
|
var upOffset = !UpPressed || upDisabled ? 4 : 4 + ButtonDepth;
|
||||||
var downOffset = !DownPressed || downDisabled ? 4 : 4 + ButtonDepth;
|
var downOffset = !DownPressed || downDisabled ? 4 : 4 + ButtonDepth;
|
||||||
|
|
||||||
|
|||||||
@@ -196,7 +196,8 @@ namespace OpenRA.Widgets
|
|||||||
WidgetUtils.DrawPanel("slider-track", trackRect);
|
WidgetUtils.DrawPanel("slider-track", trackRect);
|
||||||
|
|
||||||
// Thumb
|
// Thumb
|
||||||
ButtonWidget.DrawBackground("scrollthumb", tr, IsDisabled(), isMoving, tr.Contains(Viewport.LastMousePos));
|
var thumbHover = Widget.MouseOverWidget == this && tr.Contains(Viewport.LastMousePos);
|
||||||
|
ButtonWidget.DrawBackground("scrollthumb", tr, IsDisabled(), isMoving, thumbHover);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ namespace OpenRA.Widgets
|
|||||||
var disabled = IsDisabled();
|
var disabled = IsDisabled();
|
||||||
var state = disabled ? "textfield-disabled" :
|
var state = disabled ? "textfield-disabled" :
|
||||||
Focused ? "textfield-focused" :
|
Focused ? "textfield-focused" :
|
||||||
RenderBounds.Contains(Viewport.LastMousePos) ? "textfield-hover" :
|
Widget.MouseOverWidget == this ? "textfield-hover" :
|
||||||
"textfield";
|
"textfield";
|
||||||
|
|
||||||
WidgetUtils.DrawPanel(state,
|
WidgetUtils.DrawPanel(state,
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ namespace OpenRA.Widgets
|
|||||||
static Widget rootWidget = new ContainerWidget();
|
static Widget rootWidget = new ContainerWidget();
|
||||||
static Stack<Widget> WindowList = new Stack<Widget>();
|
static Stack<Widget> WindowList = new Stack<Widget>();
|
||||||
public static Widget SelectedWidget;
|
public static Widget SelectedWidget;
|
||||||
|
public static Widget MouseOverWidget;
|
||||||
|
|
||||||
public static void CloseWindow()
|
public static void CloseWindow()
|
||||||
{
|
{
|
||||||
@@ -68,6 +69,9 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
public static bool DoHandleInput(MouseInput mi)
|
public static bool DoHandleInput(MouseInput mi)
|
||||||
{
|
{
|
||||||
|
if (mi.Event == MouseInputEvent.Move)
|
||||||
|
MouseOverWidget = null;
|
||||||
|
|
||||||
bool handled = false;
|
bool handled = false;
|
||||||
if (SelectedWidget != null && SelectedWidget.HandleMouseInputOuter(mi))
|
if (SelectedWidget != null && SelectedWidget.HandleMouseInputOuter(mi))
|
||||||
handled = true;
|
handled = true;
|
||||||
@@ -80,6 +84,7 @@ namespace OpenRA.Widgets
|
|||||||
Viewport.LastMousePos = mi.Location;
|
Viewport.LastMousePos = mi.Location;
|
||||||
Viewport.TicksSinceLastMove = 0;
|
Viewport.TicksSinceLastMove = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,6 +115,7 @@ namespace OpenRA.Widgets
|
|||||||
public string Logic = null;
|
public string Logic = null;
|
||||||
public object LogicObject { get; private set; }
|
public object LogicObject { get; private set; }
|
||||||
public bool Visible = true;
|
public bool Visible = true;
|
||||||
|
public bool IgnoreChildMouseOver;
|
||||||
|
|
||||||
// Calculated internally
|
// Calculated internally
|
||||||
public Rectangle Bounds;
|
public Rectangle Bounds;
|
||||||
@@ -132,6 +138,7 @@ namespace OpenRA.Widgets
|
|||||||
Parent = widget.Parent;
|
Parent = widget.Parent;
|
||||||
|
|
||||||
IsVisible = widget.IsVisible;
|
IsVisible = widget.IsVisible;
|
||||||
|
IgnoreChildMouseOver = widget.IgnoreChildMouseOver;
|
||||||
|
|
||||||
foreach (var child in widget.Children)
|
foreach (var child in widget.Children)
|
||||||
AddChild(child.Clone());
|
AddChild(child.Clone());
|
||||||
@@ -215,6 +222,7 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
if (SelectedWidget != null && !SelectedWidget.LoseFocus(mi))
|
if (SelectedWidget != null && !SelectedWidget.LoseFocus(mi))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
SelectedWidget = this;
|
SelectedWidget = this;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -259,11 +267,18 @@ namespace OpenRA.Widgets
|
|||||||
if (!(Focused || (IsVisible() && GetEventBounds().Contains(mi.Location.X, mi.Location.Y))))
|
if (!(Focused || (IsVisible() && GetEventBounds().Contains(mi.Location.X, mi.Location.Y))))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
var oldMouseOver = MouseOverWidget;
|
||||||
// Send the event to the deepest children first and bubble up if unhandled
|
// Send the event to the deepest children first and bubble up if unhandled
|
||||||
foreach (var child in Children.OfType<Widget>().Reverse())
|
foreach (var child in Children.OfType<Widget>().Reverse())
|
||||||
if (child.HandleMouseInputOuter(mi))
|
if (child.HandleMouseInputOuter(mi))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (IgnoreChildMouseOver)
|
||||||
|
MouseOverWidget = oldMouseOver;
|
||||||
|
|
||||||
|
if (mi.Event == MouseInputEvent.Move && MouseOverWidget == null)
|
||||||
|
MouseOverWidget = this;
|
||||||
|
|
||||||
return HandleMouseInput(mi);
|
return HandleMouseInput(mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,13 +107,13 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
rightButtonRect = new Rectangle(rb.Right - ArrowWidth, rb.Y, ArrowWidth, rb.Height);
|
rightButtonRect = new Rectangle(rb.Right - ArrowWidth, rb.Y, ArrowWidth, rb.Height);
|
||||||
|
|
||||||
var leftDisabled = ListOffset >= 0;
|
var leftDisabled = ListOffset >= 0;
|
||||||
|
var leftHover = Widget.MouseOverWidget == this && leftButtonRect.Contains(Viewport.LastMousePos);
|
||||||
var rightDisabled = ListOffset <= Bounds.Width - rightButtonRect.Width - leftButtonRect.Width - ContentWidth;
|
var rightDisabled = ListOffset <= Bounds.Width - rightButtonRect.Width - leftButtonRect.Width - ContentWidth;
|
||||||
|
var rightHover = Widget.MouseOverWidget == this && rightButtonRect.Contains(Viewport.LastMousePos);
|
||||||
|
|
||||||
WidgetUtils.DrawPanel("panel-black", rb);
|
WidgetUtils.DrawPanel("panel-black", rb);
|
||||||
ButtonWidget.DrawBackground("button", leftButtonRect, leftDisabled,
|
ButtonWidget.DrawBackground("button", leftButtonRect, leftDisabled, leftPressed, leftHover);
|
||||||
leftPressed, leftButtonRect.Contains(Viewport.LastMousePos));
|
ButtonWidget.DrawBackground("button", rightButtonRect, rightDisabled, rightPressed, rightHover);
|
||||||
ButtonWidget.DrawBackground("button", rightButtonRect, rightDisabled,
|
|
||||||
rightPressed, rightButtonRect.Contains(Viewport.LastMousePos));
|
|
||||||
|
|
||||||
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", leftPressed || leftDisabled ? "up_pressed" : "up_arrow"),
|
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", leftPressed || leftDisabled ? "up_pressed" : "up_arrow"),
|
||||||
new float2(leftButtonRect.Left + 2, leftButtonRect.Top + 2));
|
new float2(leftButtonRect.Left + 2, leftButtonRect.Top + 2));
|
||||||
@@ -126,10 +126,12 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
var origin = new int2(leftButtonRect.Right - 1 + (int)ListOffset, leftButtonRect.Y);
|
var origin = new int2(leftButtonRect.Right - 1 + (int)ListOffset, leftButtonRect.Y);
|
||||||
SpriteFont font = Game.Renderer.Fonts["TinyBold"];
|
SpriteFont font = Game.Renderer.Fonts["TinyBold"];
|
||||||
ContentWidth = 0;
|
ContentWidth = 0;
|
||||||
|
|
||||||
foreach (var tab in Groups[queueGroup].Tabs)
|
foreach (var tab in Groups[queueGroup].Tabs)
|
||||||
{
|
{
|
||||||
var rect = new Rectangle(origin.X + ContentWidth, origin.Y, TabWidth, rb.Height);
|
var rect = new Rectangle(origin.X + ContentWidth, origin.Y, TabWidth, rb.Height);
|
||||||
ButtonWidget.DrawBackground("button", rect, false, tab.Queue == palette.CurrentQueue, rect.Contains(Viewport.LastMousePos));
|
var hover = !leftHover && !rightHover && Widget.MouseOverWidget == this && rect.Contains(Viewport.LastMousePos);
|
||||||
|
ButtonWidget.DrawBackground("button", rect, false, tab.Queue == palette.CurrentQueue, hover);
|
||||||
ContentWidth += TabWidth - 1;
|
ContentWidth += TabWidth - 1;
|
||||||
|
|
||||||
int2 textSize = font.Measure(tab.Name);
|
int2 textSize = font.Measure(tab.Name);
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ Container@SERVER_LOBBY:
|
|||||||
Height:25
|
Height:25
|
||||||
X:155
|
X:155
|
||||||
Font:Regular
|
Font:Regular
|
||||||
|
IgnoreChildMouseOver: true
|
||||||
Children:
|
Children:
|
||||||
ColorBlock@COLORBLOCK:
|
ColorBlock@COLORBLOCK:
|
||||||
Id:COLORBLOCK
|
Id:COLORBLOCK
|
||||||
@@ -95,6 +96,7 @@ Container@SERVER_LOBBY:
|
|||||||
Height:25
|
Height:25
|
||||||
X:230
|
X:230
|
||||||
Font:Regular
|
Font:Regular
|
||||||
|
IgnoreChildMouseOver: true
|
||||||
Children:
|
Children:
|
||||||
Image@FACTIONFLAG:
|
Image@FACTIONFLAG:
|
||||||
Id:FACTIONFLAG
|
Id:FACTIONFLAG
|
||||||
@@ -260,6 +262,7 @@ Container@SERVER_LOBBY:
|
|||||||
Height:25
|
Height:25
|
||||||
X:155
|
X:155
|
||||||
Font:Regular
|
Font:Regular
|
||||||
|
IgnoreChildMouseOver: true
|
||||||
Children:
|
Children:
|
||||||
ColorBlock@COLORBLOCK:
|
ColorBlock@COLORBLOCK:
|
||||||
Id:COLORBLOCK
|
Id:COLORBLOCK
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ Container@SETTINGS_PANEL:
|
|||||||
Y:40
|
Y:40
|
||||||
Width:80
|
Width:80
|
||||||
Height:25
|
Height:25
|
||||||
|
IgnoreChildMouseOver: true
|
||||||
Children:
|
Children:
|
||||||
ColorBlock@COLORBLOCK:
|
ColorBlock@COLORBLOCK:
|
||||||
Id:COLORBLOCK
|
Id:COLORBLOCK
|
||||||
|
|||||||
Reference in New Issue
Block a user