fix trailing whitespace everywhere

This commit is contained in:
Chris Forbes
2011-09-25 14:37:12 +13:00
parent 0eb98ef3b5
commit 55036cd58c
596 changed files with 3194 additions and 3194 deletions

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
@@ -19,14 +19,14 @@ namespace OpenRA.Widgets
{
WidgetUtils.DrawPanel(Background, RenderBounds);
}
public BackgroundWidget() : base() { }
public override bool HandleMouseInput(MouseInput mi)
{
return !ClickThrough;
}
protected BackgroundWidget(BackgroundWidget other)
: base(other)
{

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
@@ -32,7 +32,7 @@ namespace OpenRA.Widgets
// Equivalent to OnMouseUp, but without an input arg
public Action OnClick = () => {};
public Action<KeyInput> OnKeyPress = _ => {};
public ButtonWidget()
: base()
{
@@ -60,12 +60,12 @@ namespace OpenRA.Widgets
Depressed = false;
return base.LoseFocus(mi);
}
public override bool HandleKeyPress(KeyInput e)
{
if (e.KeyName != Key || e.Event != KeyInputEvent.Down)
return false;
if (!IsDisabled())
{
OnKeyPress(e);
@@ -76,12 +76,12 @@ namespace OpenRA.Widgets
return true;
}
public override bool HandleMouseInput(MouseInput mi)
{
if (mi.Button != MouseButton.Left)
return false;
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
return false;
@@ -91,7 +91,7 @@ namespace OpenRA.Widgets
{
if (Depressed && !disabled)
OnMouseUp(mi);
return LoseFocus(mi);
}
if (mi.Event == MouseInputEvent.Down)
@@ -115,19 +115,19 @@ namespace OpenRA.Widgets
return Depressed;
}
public override int2 ChildOrigin { get { return RenderOrigin +
public override int2 ChildOrigin { get { return RenderOrigin +
((Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0)); } }
public override void Draw()
{
var rb = RenderBounds;
var disabled = IsDisabled();
var font = Game.Renderer.Fonts[Font];
var text = GetText();
var s = font.Measure(text);
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
DrawBackground(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,
disabled ? Color.Gray : Color.White);
@@ -143,11 +143,11 @@ namespace OpenRA.Widgets
public static void DrawBackground(string baseName, Rectangle rect, bool disabled, bool pressed, bool hover)
{
var state = disabled ? "-disabled" :
pressed ? "-pressed" :
hover ? "-hover" :
var state = disabled ? "-disabled" :
pressed ? "-pressed" :
hover ? "-hover" :
"";
WidgetUtils.DrawPanel(baseName + state, rect);
}
}

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
@@ -18,7 +18,7 @@ namespace OpenRA.Widgets
{
public readonly int RemoveTime = 0;
public readonly bool UseContrast = false;
const int logLength = 9;
public string Notification = "";
public bool DrawBackground = true;
@@ -54,11 +54,11 @@ namespace OpenRA.Widgets
var owner = line.Owner + ":";
inset = font.Measure(owner).X + 10;
font.DrawTextWithContrast(owner, chatpos,
font.DrawTextWithContrast(owner, chatpos,
line.Color, Color.Black, UseContrast ? 1 : 0);
}
font.DrawTextWithContrast(line.Text, chatpos + new int2(inset, 0),
font.DrawTextWithContrast(line.Text, chatpos + new int2(inset, 0),
Color.White, Color.Black, UseContrast ? 1 : 0);
}
@@ -78,12 +78,12 @@ namespace OpenRA.Widgets
public void RemoveLine()
{
if (recentLines.Count > 0) recentLines.RemoveAt(0);
if (recentLines.Count > 0) recentLines.RemoveAt(0);
}
public void ClearChat()
{
recentLines = new List<ChatLine>();
recentLines = new List<ChatLine>();
}
public override void Tick()

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
@@ -53,7 +53,7 @@ namespace OpenRA.Widgets
public override bool HandleKeyPress(KeyInput e)
{
if (e.Event == KeyInputEvent.Up) return false;
if (e.KeyName == "return" || e.KeyName == "enter" )
{
if (composing)

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
@@ -47,13 +47,13 @@ namespace OpenRA.Widgets
var font = Game.Renderer.Fonts[Font];
var rect = RenderBounds;
var check = new Rectangle(rect.Location, new Size(Bounds.Height, Bounds.Height));
var state = disabled ? "checkbox-disabled" :
Depressed && HasPressedState ? "checkbox-pressed" :
Widget.MouseOverWidget == this ? "checkbox-hover" :
var state = disabled ? "checkbox-disabled" :
Depressed && HasPressedState ? "checkbox-pressed" :
Widget.MouseOverWidget == this ? "checkbox-hover" :
"checkbox";
WidgetUtils.DrawPanel(state, check);
var textSize = font.Measure(Text);
font.DrawText(Text,
new float2(rect.Left + rect.Height * 1.5f, RenderOrigin.Y - BaseLine + (Bounds.Height - textSize.Y)/2), Color.White);

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
@@ -18,7 +18,7 @@ namespace OpenRA.Widgets
static class ChromeMetrics
{
static Dictionary<string, string> data = new Dictionary<string, string>();
public static void Initialize(string[] yaml)
{
data = new Dictionary<string, string>();

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
@@ -19,7 +19,7 @@ namespace OpenRA.Widgets
{
Widget panel;
MaskWidget fullscreenMask;
public DropDownButtonWidget()
: base()
{
@@ -34,12 +34,12 @@ namespace OpenRA.Widgets
{
base.Draw();
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
var image = ChromeProvider.GetImage("scrollbar", IsDisabled() ? "down_pressed" : "down_arrow");
var rb = RenderBounds;
WidgetUtils.DrawRGBA( image,
stateOffset + new float2( rb.Right - rb.Height + 4,
stateOffset + new float2( rb.Right - rb.Height + 4,
rb.Top + (rb.Height - image.bounds.Height) / 2 ));
WidgetUtils.FillRectWithColor(new Rectangle(stateOffset.X + rb.Right - rb.Height,
@@ -48,9 +48,9 @@ namespace OpenRA.Widgets
}
public override Widget Clone() { return new DropDownButtonWidget(this); }
// This is crap
public override int UsableWidth { get { return Bounds.Width - Bounds.Height; } } /* space for button */
public override int UsableWidth { get { return Bounds.Width - Bounds.Height; } } /* space for button */
public override void Removed()
{
@@ -73,7 +73,7 @@ namespace OpenRA.Widgets
if (panel != null)
throw new InvalidOperationException("Attempted to attach a panel to an open dropdown");
panel = p;
// Mask to prevent any clicks from being sent to other widgets
fullscreenMask = new MaskWidget();
fullscreenMask.Bounds = new Rectangle(0, 0, Game.viewport.Width, Game.viewport.Height);
@@ -84,26 +84,26 @@ namespace OpenRA.Widgets
panel.Bounds = new Rectangle(RenderOrigin.X, RenderOrigin.Y + Bounds.Height, oldBounds.Width, oldBounds.Height);
Widget.RootWidget.AddChild(panel);
}
public void ShowDropDown<T>(string panelTemplate, int height, List<T> options, Func<T, ScrollItemWidget, ScrollItemWidget> setupItem)
{
var substitutions = new Dictionary<string,int>() {{ "DROPDOWN_WIDTH", Bounds.Width }};
var panel = (ScrollPanelWidget)Widget.LoadWidget(panelTemplate, null, new WidgetArgs()
{{ "substitutions", substitutions }});
var itemTemplate = panel.GetWidget<ScrollItemWidget>("TEMPLATE");
panel.RemoveChildren();
foreach (var option in options)
{
var o = option;
ScrollItemWidget item = setupItem(o, itemTemplate);
var onClick = item.OnClick;
item.OnClick = () => { onClick(); RemovePanel(); };
panel.AddChild(item);
}
panel.Bounds.Height = Math.Min(height, panel.ContentHeight);
AttachPanel(panel);
}

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
@@ -43,7 +43,7 @@ namespace OpenRA.Widgets
var name = GetImageName();
var collection = GetImageCollection();
WidgetUtils.DrawRGBA(
ChromeProvider.GetImage(collection, name),
ChromeProvider.GetImage(collection, name),
RenderOrigin);
}
}

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
@@ -29,7 +29,7 @@ namespace OpenRA.Widgets
public Func<string> GetText;
public Func<Color> GetColor;
public Func<Color> GetContrastColor;
public LabelWidget()
: base()
{
@@ -59,16 +59,16 @@ namespace OpenRA.Widgets
var text = GetText();
if (text == null)
return;
int2 textSize = font.Measure(text);
int2 position = RenderOrigin;
if (VAlign == TextVAlign.Middle)
position += new int2(0, (Bounds.Height - textSize.Y)/2);
if (VAlign == TextVAlign.Bottom)
position += new int2(0, Bounds.Height - textSize.Y);
if (Align == TextAlign.Center)
position += new int2((Bounds.Width - textSize.X)/2, 0);

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
@@ -23,7 +23,7 @@ namespace OpenRA.Widgets
public Action<MouseInput> OnMouseDown = _ => {};
Cache<Map,Bitmap> PreviewCache = new Cache<Map, Bitmap>(stub => Minimap.RenderMapPreview( new Map( stub.Path )));
public MapPreviewWidget() : base() { }
protected MapPreviewWidget(MapPreviewWidget other)
: base(other)
@@ -47,7 +47,7 @@ namespace OpenRA.Widgets
{
return new int2(MapRect.X + (int)(PreviewScale*(point.X - map.Bounds.Left)) , MapRect.Y + (int)(PreviewScale*(point.Y - map.Bounds.Top)));
}
Sheet mapChooserSheet;
Sprite mapChooserSprite;
Map lastMap;
@@ -58,7 +58,7 @@ namespace OpenRA.Widgets
{
var map = Map();
if( map == null ) return;
if (lastMap != map)
{
lastMap = map;
@@ -70,7 +70,7 @@ namespace OpenRA.Widgets
mapChooserSheet.Texture.SetData( preview );
mapChooserSprite = new Sprite( mapChooserSheet, new Rectangle( 0, 0, map.Bounds.Width, map.Bounds.Height ), TextureChannel.Alpha );
// Update map rect
PreviewScale = Math.Min(RenderBounds.Width * 1.0f / map.Bounds.Width, RenderBounds.Height * 1.0f / map.Bounds.Height);
var size = Math.Max(map.Bounds.Width, map.Bounds.Height);
@@ -94,7 +94,7 @@ namespace OpenRA.Widgets
if (owned)
WidgetUtils.FillRectWithColor(new Rectangle(pos.X + offset.X + 2, pos.Y + offset.Y + 2, 12, 12), colors[p]);
Game.Renderer.RgbaSpriteRenderer.DrawSprite(sprite, pos + offset);
}
}

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
@@ -17,7 +17,7 @@ namespace OpenRA.Widgets
{
public int Percentage = 0;
public bool Indeterminate = false;
// Indeterminant bar properties
float offset = 0f;
float tickStep = 0.04f;
@@ -28,20 +28,20 @@ namespace OpenRA.Widgets
{
Percentage = widget.Percentage;
}
public override void Draw()
{
var rb = RenderBounds;
WidgetUtils.DrawPanel("progressbar-bg", rb);
Rectangle barRect = Indeterminate ?
new Rectangle(rb.X + 2 + (int)(0.75*offset*(rb.Width - 4)), rb.Y + 2, (rb.Width - 4) / 4, rb.Height - 4) :
Rectangle barRect = Indeterminate ?
new Rectangle(rb.X + 2 + (int)(0.75*offset*(rb.Width - 4)), rb.Y + 2, (rb.Width - 4) / 4, rb.Height - 4) :
new Rectangle(rb.X + 2, rb.Y + 2, Percentage * (rb.Width - 4) / 100, rb.Height - 4);
if (barRect.Width > 0)
WidgetUtils.DrawPanel("progressbar-thumb", barRect);
}
public override void Tick()
{
if (Indeterminate)
@@ -52,13 +52,13 @@ namespace OpenRA.Widgets
tickStep *= -1;
}
}
public void SetIndeterminate(bool value)
{
Indeterminate = value;
offset = 0f;
}
public override Widget Clone() { return new ProgressBarWidget(this); }
}
}

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
@@ -15,7 +15,7 @@ using OpenRA.Graphics;
namespace OpenRA.Widgets
{
public class ScrollItemWidget : ButtonWidget
{
{
public ScrollItemWidget()
: base()
{
@@ -23,7 +23,7 @@ namespace OpenRA.Widgets
VisualHeight = 0;
IgnoreChildMouseOver = true;
}
protected ScrollItemWidget(ScrollItemWidget other)
: base(other)
{
@@ -31,21 +31,21 @@ namespace OpenRA.Widgets
VisualHeight = 0;
IgnoreChildMouseOver = true;
}
public Func<bool> IsSelected = () => false;
public override void Draw()
{
var state = IsSelected() ? "scrollitem-selected" :
Widget.MouseOverWidget == this ? "scrollitem-hover" :
var state = IsSelected() ? "scrollitem-selected" :
Widget.MouseOverWidget == this ? "scrollitem-hover" :
null;
if (state != null)
WidgetUtils.DrawPanel(state, RenderBounds);
}
public override Widget Clone() { return new ScrollItemWidget(this); }
public static ScrollItemWidget Setup(ScrollItemWidget template, Func<bool> isSelected, Action onClick)
{
var w = template.Clone() as ScrollItemWidget;

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
@@ -17,7 +17,7 @@ namespace OpenRA.Widgets
public class ScrollPanelWidget : Widget
{
public int ScrollbarWidth = 24;
public float ScrollVelocity = 4f;
public float ScrollVelocity = 4f;
public int ItemSpacing = 2;
public int ButtonDepth = ChromeMetrics.Get<int>("ButtonDepth");
public string Background = "scrollpanel-bg";
@@ -31,45 +31,45 @@ namespace OpenRA.Widgets
protected Rectangle backgroundRect;
protected Rectangle scrollbarRect;
protected Rectangle thumbRect;
public ScrollPanelWidget() : base() {}
protected ScrollPanelWidget(ScrollPanelWidget other)
: base(other)
{
throw new NotImplementedException();
}
public override void RemoveChildren()
{
ContentHeight = 0;
base.RemoveChildren();
}
public override void AddChild(Widget child)
{
// Initial setup of margins/height
if (Children.Count == 0)
ContentHeight = ItemSpacing;
child.Bounds.Y += ContentHeight;
ContentHeight += child.Bounds.Height + ItemSpacing;
base.AddChild(child);
}
public override void DrawOuter()
{
if (!IsVisible())
return;
var rb = RenderBounds;
var ScrollbarHeight = rb.Height - 2 * ScrollbarWidth;
var thumbHeight = ContentHeight == 0 ? 0 : (int)(ScrollbarHeight*Math.Min(rb.Height*1f/ContentHeight, 1f));
var thumbOrigin = rb.Y + ScrollbarWidth + (int)((ScrollbarHeight - thumbHeight)*(-1f*ListOffset/(ContentHeight - rb.Height)));
if (thumbHeight == ScrollbarHeight)
thumbHeight = 0;
backgroundRect = new Rectangle(rb.X, rb.Y, rb.Width - ScrollbarWidth+1, rb.Height);
upButtonRect = new Rectangle(rb.Right - ScrollbarWidth, rb.Y, ScrollbarWidth, ScrollbarWidth);
downButtonRect = new Rectangle(rb.Right - ScrollbarWidth, rb.Bottom - ScrollbarWidth, ScrollbarWidth, ScrollbarWidth);
@@ -87,13 +87,13 @@ namespace OpenRA.Widgets
WidgetUtils.DrawPanel("scrollpanel-bg", scrollbarRect);
ButtonWidget.DrawBackground("button", upButtonRect, upDisabled, UpPressed, upHover);
ButtonWidget.DrawBackground("button", downButtonRect, downDisabled, DownPressed, downHover);
if (thumbHeight > 0)
ButtonWidget.DrawBackground("scrollthumb", thumbRect, false, Focused && thumbHover, thumbHover);
var upOffset = !UpPressed || upDisabled ? 4 : 4 + ButtonDepth;
var downOffset = !DownPressed || downDisabled ? 4 : 4 + ButtonDepth;
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", UpPressed || upDisabled ? "up_pressed" : "up_arrow"),
new float2(upButtonRect.Left + upOffset, upButtonRect.Top + upOffset));
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", DownPressed || downDisabled ? "down_pressed" : "down_arrow"),
@@ -113,66 +113,66 @@ namespace OpenRA.Widgets
{
return EventBounds;
}
void Scroll(int direction)
{
ListOffset += direction*ScrollVelocity;
ListOffset = Math.Min(0,Math.Max(Bounds.Height - ContentHeight, ListOffset));
}
public void ScrollToBottom()
{
ListOffset = Math.Min(0,Bounds.Height - ContentHeight);
}
public override void Tick ()
{
if (UpPressed) Scroll(1);
if (DownPressed) Scroll(-1);
}
public override bool LoseFocus (MouseInput mi)
{
UpPressed = DownPressed = ThumbPressed = false;
return base.LoseFocus(mi);
}
int2 lastMouseLocation;
public override bool HandleMouseInput(MouseInput mi)
{
{
if (mi.Button == MouseButton.WheelDown)
{
Scroll(-1);
return true;
}
if (mi.Button == MouseButton.WheelUp)
{
Scroll(1);
return true;
}
if (mi.Button != MouseButton.Left)
return false;
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
return false;
if (!Focused)
return false;
if (Focused && mi.Event == MouseInputEvent.Up)
return LoseFocus(mi);
if (ThumbPressed && mi.Event == MouseInputEvent.Move)
{
{
var rb = RenderBounds;
var ScrollbarHeight = rb.Height - 2 * ScrollbarWidth;
var thumbHeight = ContentHeight == 0 ? 0 : (int)(ScrollbarHeight*Math.Min(rb.Height*1f/ContentHeight, 1f));
var oldOffset = ListOffset;
ListOffset += (int)((lastMouseLocation.Y - mi.Location.Y)*(ContentHeight - rb.Height)*1f/(ScrollbarHeight - thumbHeight));
ListOffset = Math.Min(0,Math.Max(rb.Height - ContentHeight, ListOffset));
if (oldOffset != ListOffset)
lastMouseLocation = mi.Location;
}
@@ -184,7 +184,7 @@ namespace OpenRA.Widgets
if (ThumbPressed)
lastMouseLocation = mi.Location;
}
return (UpPressed || DownPressed || ThumbPressed);
}

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
@@ -18,11 +18,11 @@ namespace OpenRA.Widgets
public string Image = "";
public int Frame = 0;
public string Palette = "chrome";
public Func<string> GetImage;
public Func<int> GetFrame;
public Func<string> GetPalette;
readonly WorldRenderer worldRenderer;
[ObjectCreator.UseCtor]
public ShpImageWidget([ObjectCreator.Param] WorldRenderer worldRenderer)
@@ -48,7 +48,7 @@ namespace OpenRA.Widgets
public override Widget Clone() { return new ShpImageWidget(this); }
Sprite sprite = null;
string cachedImage = null;
int cachedFrame= -1;
@@ -57,7 +57,7 @@ namespace OpenRA.Widgets
var image = GetImage();
var frame = GetFrame();
var palette = GetPalette();
if (image != cachedImage || frame != cachedFrame)
{
sprite = Game.modData.SpriteLoader.LoadAllSprites(image)[frame];

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
@@ -28,17 +28,17 @@ namespace OpenRA.Widgets
public int VisualHeight = 1;
public int LeftMargin = 5;
public int RightMargin = 5;
public Func<bool> OnEnterKey = () => false;
public Func<bool> OnTabKey = () => false;
public Action OnLoseFocus = () => { };
public int CursorPosition { get; protected set; }
public Func<bool> IsDisabled = () => false;
public Color TextColor = Color.White;
public Color DisabledColor = Color.Gray;
public string Font = "Regular";
public TextFieldWidget() : base() {}
protected TextFieldWidget(TextFieldWidget widget)
: base(widget)
@@ -80,17 +80,17 @@ namespace OpenRA.Widgets
}
protected virtual string GetApparentText() { return text; }
public int ClosestCursorPosition(int x)
{
var apparentText = GetApparentText();
var font = Game.Renderer.Fonts[Font];
var textSize = font.Measure(apparentText);
var start = RenderOrigin.X + LeftMargin;
if (textSize.X > Bounds.Width - LeftMargin - RightMargin && Focused)
start += Bounds.Width - LeftMargin - RightMargin - textSize.X;
int minIndex = -1;
int minValue = int.MaxValue;
for (int i = 0; i <= apparentText.Length; i++)
@@ -110,7 +110,7 @@ namespace OpenRA.Widgets
return false;
if (e.Event == KeyInputEvent.Up) return false;
// Only take input if we are focused
if (!Focused)
return false;
@@ -136,13 +136,13 @@ namespace OpenRA.Widgets
return true;
}
if (e.KeyName == "home")
{
CursorPosition = 0;
return true;
}
if (e.KeyName == "end")
{
CursorPosition = Text.Length;
@@ -167,9 +167,9 @@ namespace OpenRA.Widgets
CursorPosition--;
Text = Text.Remove(CursorPosition, 1);
}
else if (key.IsValidInput())
{
{
if (MaxLength > 0 && Text.Length >= MaxLength)
return;
@@ -190,7 +190,7 @@ namespace OpenRA.Widgets
showCursor ^= true;
}
}
public override void Draw()
{
var apparentText = GetApparentText();

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
@@ -25,13 +25,13 @@ namespace OpenRA.Widgets
public ViewportScrollControllerWidget() : base() {}
protected ViewportScrollControllerWidget(ViewportScrollControllerWidget widget)
: base(widget) {}
public override bool HandleMouseInput(MouseInput mi)
{
{
var scrolltype = Game.Settings.Game.MouseScroll;
if (scrolltype == MouseScrollType.Disabled)
return false;
if (mi.Event == MouseInputEvent.Move &&
(mi.Button == MouseButton.Middle || mi.Button == (MouseButton.Left | MouseButton.Right)))
{
@@ -41,7 +41,7 @@ namespace OpenRA.Widgets
}
return false;
}
static readonly Dictionary<ScrollDirection, string> directions = new Dictionary<ScrollDirection, string>
{
{ ScrollDirection.Up | ScrollDirection.Left, "scroll-tl" },
@@ -61,7 +61,7 @@ namespace OpenRA.Widgets
return null;
var blockedDirections = Game.viewport.GetBlockedDirections();
foreach( var dir in directions )
if (Edge.Includes( dir.Key ))
return dir.Value + (blockedDirections.Includes( dir.Key ) ? "-blocked" : "");
@@ -74,9 +74,9 @@ namespace OpenRA.Widgets
Keyboard = ScrollDirection.None;
return base.LoseFocus(mi);
}
public override bool HandleKeyPress(KeyInput e)
{
{
switch (e.KeyName)
{
case "up": Keyboard = Keyboard.Set(ScrollDirection.Up, (e.Event == KeyInputEvent.Down)); return true;
@@ -86,7 +86,7 @@ namespace OpenRA.Widgets
}
return false;
}
public override void Tick()
{
Edge = ScrollDirection.None;
@@ -102,7 +102,7 @@ namespace OpenRA.Widgets
if (Viewport.LastMousePos.Y >= Game.viewport.Height - EdgeScrollThreshold)
Edge = Edge.Set(ScrollDirection.Down, true);
}
if(Keyboard != ScrollDirection.None || Edge != ScrollDirection.None)
{
var scroll = new float2(0, 0);
@@ -124,7 +124,7 @@ namespace OpenRA.Widgets
Game.viewport.Scroll(scroll);
}
}
public override Widget Clone() { return new ViewportScrollControllerWidget(this); }
}
}

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
@@ -25,33 +25,33 @@ namespace OpenRA.Widgets
uint[,] overlay;
bool stopped;
bool paused;
Action OnComplete;
public bool Paused { get { return paused; } }
readonly World world;
[ObjectCreator.UseCtor]
public VqaPlayerWidget( [ObjectCreator.Param] World world )
{
this.world = world;
}
public bool DrawOverlay = true;
public void Load(string filename)
{
if (filename == cachedVideo)
return;
stopped = true;
paused = true;
Sound.StopVideo();
OnComplete = () => {};
cachedVideo = filename;
video = new VqaReader(FileSystem.Open(filename));
invLength = video.Framerate*1f/video.Frames;
var size = Math.Max(video.Width, video.Height);
@@ -62,7 +62,7 @@ namespace OpenRA.Widgets
var scale = Math.Min(RenderBounds.Width / video.Width, RenderBounds.Height / video.Height);
videoOrigin = new float2(RenderBounds.X + (RenderBounds.Width - scale*video.Width)/2, RenderBounds.Y + (RenderBounds.Height - scale*video.Height)/2);
videoSize = new float2(video.Width * scale, video.Height * scale);
if (!DrawOverlay)
return;
@@ -71,16 +71,16 @@ namespace OpenRA.Widgets
for (var y = 0; y < video.Height; y++)
for (var x = 0; x < video.Width; x++)
overlay[2*y,x] = black;
overlaySprite = new Sprite(new Sheet(new Size(2*textureSize,2*textureSize)), new Rectangle( 0, 0, video.Width, 2*video.Height ), TextureChannel.Alpha);
overlaySprite.sheet.Texture.SetData(overlay);
}
public override void Draw()
{
if (video == null)
return;
if (!(stopped || paused))
{
var nextFrame = (int)float2.Lerp(0, video.Frames, Sound.VideoSeekPosition*invLength);
@@ -89,7 +89,7 @@ namespace OpenRA.Widgets
Stop();
return;
}
while (nextFrame > video.CurrentFrame)
{
video.AdvanceFrame();
@@ -97,13 +97,13 @@ namespace OpenRA.Widgets
videoSprite.sheet.Texture.SetData(video.FrameData);
}
}
Game.Renderer.RgbaSpriteRenderer.DrawSprite(videoSprite, videoOrigin, videoSize);
if (DrawOverlay)
Game.Renderer.RgbaSpriteRenderer.DrawSprite(overlaySprite, videoOrigin, videoSize);
}
public override bool HandleKeyPress(KeyInput e)
{
if (e.Event == KeyInputEvent.Down)
@@ -116,40 +116,40 @@ namespace OpenRA.Widgets
}
return false;
}
public void Play()
{
PlayThen(() => {});
PlayThen(() => {});
}
public void PlayThen(Action after)
{
if (video == null)
return;
OnComplete = after;
if (stopped)
Sound.PlayVideo(video.AudioData);
else
Sound.PlayVideo();
stopped = paused = false;
}
public void Pause()
{
if (stopped || paused || video == null)
return;
paused = true;
Sound.PauseVideo();
}
public void Stop()
{
if (stopped || video == null)
return;
stopped = true;
paused = true;
Sound.StopVideo();

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
@@ -397,15 +397,15 @@ namespace OpenRA.Widgets
public override string GetCursor(int2 pos) { return null; }
public override Widget Clone() { return new ContainerWidget(this); }
}
public class WidgetArgs : Dictionary<string, object>
{
public WidgetArgs() : base() { }
public WidgetArgs(Dictionary<string, object> args) : base(args) { }
public void Add(string key, Action val) { base.Add(key, val); }
}
// TODO: you should use this anywhere you want to do
// TODO: you should use this anywhere you want to do
// something in a logic ctor, but retain debuggability.
public interface ILogicWithInit
{

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
@@ -37,14 +37,14 @@ namespace OpenRA
MiniYamlNode ret;
if (!widgets.TryGetValue(w, out ret))
throw new InvalidDataException("Cannot find widget with Id `{0}`".F(w));
return LoadWidget( args, parent, ret );
}
public Widget LoadWidget( WidgetArgs args, Widget parent, MiniYamlNode node)
{
var widget = NewWidget(node.Key, args);
if (parent != null)
parent.AddChild( widget );

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
@@ -23,12 +23,12 @@ namespace OpenRA.Widgets
{
return ChromeProvider.GetImage("chrome-" + world.LocalPlayer.Country.Race, name);
}
public static void DrawRGBA(Sprite s, float2 pos)
{
Game.Renderer.RgbaSpriteRenderer.DrawSprite(s,pos);
}
public static void DrawSHP(Sprite s, float2 pos, WorldRenderer wr)
{
Game.Renderer.SpriteRenderer.DrawSprite(s,pos, wr, "chrome");
@@ -38,7 +38,7 @@ namespace OpenRA.Widgets
{
DrawPanelPartial(collection, Bounds, PanelSides.All);
}
public static void FillRectWithSprite(Rectangle r, Sprite s)
{
for (var x = r.Left; x < r.Right; x += (int)s.size.X)
@@ -57,12 +57,12 @@ namespace OpenRA.Widgets
DrawRGBA(ss, new float2(x, y));
}
}
public static void FillRectWithColor(Rectangle r, Color c)
{
Game.Renderer.LineRenderer.FillRect(new RectangleF(r.X, r.Y, r.Width, r.Height), c);
}
public static int[] GetBorderSizes(string collection)
{
var images = new[] { "border-t", "border-b", "border-l", "border-r" };
@@ -135,8 +135,8 @@ namespace OpenRA.Widgets
if (ps.HasFlags(PanelSides.Right | PanelSides.Bottom))
DrawRGBA(ss[7], new float2(bounds.Right - ss[7].size.X, bounds.Bottom - ss[7].size.Y));
}
public static string FormatTime(int ticks)
{
var seconds = (int)Math.Ceiling(ticks / 25f);
@@ -152,7 +152,7 @@ namespace OpenRA.Widgets
else
return "{0:D2}:{1:D2}".F(minutes, seconds % 60);
}
public static string WrapText(string text, int width, SpriteFont font)
{
var textSize = font.Measure(text);
@@ -169,7 +169,7 @@ namespace OpenRA.Widgets
var m = font.Measure(line);
var spaceIndex = 0;
var start = line.Length - 1;
if (m.X <= width)
{
if (i < lines.Length - 1)

View File

@@ -1,7 +1,7 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
@@ -23,14 +23,14 @@ namespace OpenRA.Widgets
{
protected readonly World world;
readonly WorldRenderer worldRenderer;
[ObjectCreator.UseCtor]
public WorldInteractionControllerWidget([ObjectCreator.Param] World world, [ObjectCreator.Param] WorldRenderer worldRenderer)
{
this.world = world;
this.worldRenderer = worldRenderer;
}
public override void Draw()
{
var selbox = SelectionBox;
@@ -46,7 +46,7 @@ namespace OpenRA.Widgets
foreach (var u in SelectActorsInBox(world, selbox.Value.First, selbox.Value.Second))
worldRenderer.DrawRollover(u);
}
int2 dragStart, dragEnd;
public override bool HandleMouseInput(MouseInput mi)
@@ -56,7 +56,7 @@ namespace OpenRA.Widgets
{
if (!TakeFocus(mi))
return false;
dragStart = dragEnd = xy;
ApplyOrders(world, xy, mi);
}
@@ -82,10 +82,10 @@ namespace OpenRA.Widgets
if (mi.Button == MouseButton.Right && mi.Event == MouseInputEvent.Down)
if (SelectionBox == null) /* don't issue orders while selecting */
ApplyOrders(world, xy, mi);
return true;
}
public Pair<int2, int2>? SelectionBox
{
get
@@ -94,7 +94,7 @@ namespace OpenRA.Widgets
return Pair.New(dragStart, dragEnd);
}
}
public void ApplyOrders(World world, int2 xy, MouseInput mi)
{
if (world.OrderGenerator == null) return;
@@ -104,7 +104,7 @@ namespace OpenRA.Widgets
world.PlayVoiceForOrders(orders);
}
public override string GetCursor(int2 pos)
{
return Sync.CheckSyncUnchanged( world, () =>
@@ -140,7 +140,7 @@ namespace OpenRA.Widgets
}
return false;
}
static readonly Actor[] NoActors = {};
IEnumerable<Actor> SelectActorsInBox(World world, int2 a, int2 b)
{