From 7daf31813461b278f7918ff92d989abdaa3e0686 Mon Sep 17 00:00:00 2001 From: adelikat Date: Mon, 26 Mar 2012 02:58:24 +0000 Subject: [PATCH] gui.text() - add a 5th parameters "anchor" that will anchor the text to top, left, bottom, or right. Same functionality as the message config anchor option. --- BizHawk.MultiClient/LuaImplementation.cs | 16 +++++++++++++--- BizHawk.MultiClient/RenderPanel.cs | 20 ++++++++++++-------- BizHawk.MultiClient/tools/RamWatch.cs | 2 +- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/BizHawk.MultiClient/LuaImplementation.cs b/BizHawk.MultiClient/LuaImplementation.cs index 76499794d5..a4e0c8da09 100644 --- a/BizHawk.MultiClient/LuaImplementation.cs +++ b/BizHawk.MultiClient/LuaImplementation.cs @@ -347,14 +347,24 @@ namespace BizHawk.MultiClient //---------------------------------------------------- //Gui library //---------------------------------------------------- - public void gui_text(object luaX, object luaY, object luaStr) + public void gui_text(object luaX, object luaY, object luaStr, object anchor = null) { - Global.RenderPanel.AddGUIText(luaStr.ToString(), LuaInt(luaX), LuaInt(luaY), false); + gui_text_implementation(LuaVarArgs(luaX, luaY, luaStr, anchor)); + } + + private void gui_text_implementation(object[] parameters) + { + int anchor; + if (parameters.Length == 3) + anchor = 0; + else + anchor = LuaInt(parameters[3]); + Global.RenderPanel.AddGUIText(parameters[2].ToString(), LuaInt(parameters[0]), LuaInt(parameters[1]), false, anchor); } public void gui_alert(object luaX, object luaY, object luaStr) { - Global.RenderPanel.AddGUIText(luaStr.ToString(), LuaInt(luaX), LuaInt(luaY), true); + Global.RenderPanel.AddGUIText(luaStr.ToString(), LuaInt(luaX), LuaInt(luaY), true, 0); } //---------------------------------------------------- diff --git a/BizHawk.MultiClient/RenderPanel.cs b/BizHawk.MultiClient/RenderPanel.cs index a8d344c2ea..d8aec94dae 100644 --- a/BizHawk.MultiClient/RenderPanel.cs +++ b/BizHawk.MultiClient/RenderPanel.cs @@ -115,7 +115,7 @@ namespace BizHawk.MultiClient void Render(IVideoProvider video); bool Resized { get; set; } void AddMessage(string msg); - void AddGUIText(string msg, int x, int y, bool alert); + void AddGUIText(string msg, int x, int y, bool alert, int anchor); void ClearGUIText(); string FPS { get; set; } string MT { get; set; } @@ -148,7 +148,7 @@ namespace BizHawk.MultiClient } RetainedViewportPanel backingControl; public void AddMessage(string msg) { } - public void AddGUIText(string msg, int x, int y, bool alert) { } + public void AddGUIText(string msg, int x, int y, bool alert, int anchor) { } public void ClearGUIText() { } } @@ -481,9 +481,9 @@ namespace BizHawk.MultiClient messages.Add(new UIMessage { Message = message, ExpireAt = DateTime.Now + TimeSpan.FromSeconds(2) }); } - public void AddGUIText(string message, int x, int y, bool alert) + public void AddGUIText(string message, int x, int y, bool alert, int anchor) { - GUITextList.Add(new UIDisplay { Message = message, X = x, Y = y, Alert = alert }); + GUITextList.Add(new UIDisplay { Message = message, X = x, Y = y, Alert = alert, Anchor = anchor}); } public void ClearGUIText() @@ -505,17 +505,20 @@ namespace BizHawk.MultiClient } for (int x = 0; x < GUITextList.Count; x++) { + int posx = GetX(GUITextList[x].X, GUITextList[x].Anchor); + int posy = GetX(GUITextList[x].X, GUITextList[x].Anchor); + MessageFont.DrawString(null, GUITextList[x].Message, - GUITextList[x].X + 2, GUITextList[x].Y + 2, Color.Black); + posx + 2, posy + 2, Color.Black); MessageFont.DrawString(null, GUITextList[x].Message, - GUITextList[x].X + 1, GUITextList[x].Y + 1, Color.Gray); + posx + 1, posy + 1, Color.Gray); if (GUITextList[x].Alert) MessageFont.DrawString(null, GUITextList[x].Message, - GUITextList[x].X, GUITextList[x].Y, Color.FromArgb(Global.Config.AlertMessageColor)); + posx, posy, Color.FromArgb(Global.Config.AlertMessageColor)); else MessageFont.DrawString(null, GUITextList[x].Message, - GUITextList[x].X, GUITextList[x].Y, Color.FromArgb(Global.Config.MessagesColor)); + posx, posy, Color.FromArgb(Global.Config.MessagesColor)); } } @@ -565,5 +568,6 @@ namespace BizHawk.MultiClient public int X; public int Y; public bool Alert; + public int Anchor; } } diff --git a/BizHawk.MultiClient/tools/RamWatch.cs b/BizHawk.MultiClient/tools/RamWatch.cs index e6c87d1c34..e70f8477c4 100644 --- a/BizHawk.MultiClient/tools/RamWatch.cs +++ b/BizHawk.MultiClient/tools/RamWatch.cs @@ -80,7 +80,7 @@ namespace BizHawk.MultiClient { bool alert = Global.CheatList.IsActiveCheat(Domain, watchList[x].address); Global.RenderPanel.AddGUIText(watchList[x].ToString(), - Global.Config.DispRamWatchx, (Global.Config.DispRamWatchy + (x * 12)), alert); + Global.Config.DispRamWatchx, (Global.Config.DispRamWatchy + (x * 12)), alert, 0); } }