From 7923fd29a019eae168b6793ed6e388bc27bc288e Mon Sep 17 00:00:00 2001 From: Arthur Valadares Date: Fri, 21 Aug 2009 21:12:22 -0300 Subject: Adds osDrawPolygon to OSSL. Works a little different then other OS Drawing functions, this one has no start and end point, but a number of points that will form the desired polygon. Only FilledPolygon implemented so far. * Also added some LSL transparent type conversion, as it's done in LSL scripting (string to integer, float to string, etc) --- .../Shared/Api/Implementation/OSSL_Api.cs | 19 ++++++++++ .../ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 1 + .../ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 5 +++ OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | 43 ++++++++++++++++++---- 4 files changed, 61 insertions(+), 7 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 6190349..b40e441 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -833,6 +833,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return drawList; } + public string osDrawFilledPolygon(string drawList, LSL_List x, LSL_List y) + { + CheckThreatLevel(ThreatLevel.None, "osDrawFilledPolygon"); + + m_host.AddScriptLPS(1); + + if (x.Length != y.Length || x.Length < 3) + { + return ""; + } + drawList += "FillPolygon " + x.GetLSLStringItem(0) + "," + y.GetLSLStringItem(0); + for (int i = 1; i < x.Length; i++) + { + drawList += "," + x.GetLSLStringItem(i) + "," + y.GetLSLStringItem(i); + } + drawList += "; "; + return drawList; + } + public string osSetFontSize(string drawList, int fontSize) { CheckThreatLevel(ThreatLevel.None, "osSetFontSize"); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index c24dae8..202bf41 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs @@ -97,6 +97,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces string osDrawEllipse(string drawList, int width, int height); string osDrawRectangle(string drawList, int width, int height); string osDrawFilledRectangle(string drawList, int width, int height); + string osDrawFilledPolygon(string drawList, LSL_List x, LSL_List y); string osSetFontSize(string drawList, int fontSize); string osSetPenSize(string drawList, int penSize); string osSetPenColour(string drawList, string colour); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index 605f67b..b6bfb43 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs @@ -267,6 +267,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase return m_OSSL_Functions.osDrawFilledRectangle(drawList, width, height); } + public string osDrawFilledPolygon(string drawList, LSL_List x, LSL_List y) + { + return m_OSSL_Functions.osDrawFilledPolygon(drawList, x, y); + } + public string osSetFontSize(string drawList, int fontSize) { return m_OSSL_Functions.osSetFontSize(drawList, fontSize); diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index bdacf8b..2842f6b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs @@ -439,6 +439,13 @@ namespace OpenSim.Region.ScriptEngine.Shared set {m_data = value; } } + // Function to obtain LSL type from an index. This is needed + // because LSL lists allow for multiple types, and safely + // iterating in them requires a type check. + public Type GetLSLListItemType(int itemIndex) + { + return m_data[itemIndex].GetType(); + } // Member functions to obtain item as specific types. // For cases where implicit conversions would apply if items @@ -465,6 +472,10 @@ namespace OpenSim.Region.ScriptEngine.Shared { return new LSL_Types.LSLFloat((Double)m_data[itemIndex]); } + else if (m_data[itemIndex] is LSL_Types.LSLString) + { + return new LSL_Types.LSLFloat(m_data[itemIndex].ToString()); + } else { return (LSL_Types.LSLFloat)m_data[itemIndex]; @@ -481,20 +492,32 @@ namespace OpenSim.Region.ScriptEngine.Shared { return new LSL_Types.LSLString((string)m_data[itemIndex]); } + else if (m_data[itemIndex] is LSL_Types.LSLFloat) + { + return new LSL_Types.LSLString((LSLFloat)m_data[itemIndex]); + } + else if (m_data[itemIndex] is LSL_Types.LSLInteger) + { + return new LSL_Types.LSLString((LSLInteger)m_data[itemIndex]); + } else { - return (LSL_Types.LSLString)m_data[itemIndex]; + return (LSL_Types.LSLString)m_data[itemIndex]; } } public LSL_Types.LSLInteger GetLSLIntegerItem(int itemIndex) { - if (m_data[itemIndex] is LSL_Types.LSLInteger) - return (LSL_Types.LSLInteger)m_data[itemIndex]; - else if (m_data[itemIndex] is Int32) - return new LSLInteger((int)m_data[itemIndex]); - else - throw new InvalidCastException(); + if (m_data[itemIndex] is LSL_Types.LSLInteger) + return (LSL_Types.LSLInteger)m_data[itemIndex]; + if (m_data[itemIndex] is LSL_Types.LSLFloat) + return new LSLInteger((int)m_data[itemIndex]); + else if (m_data[itemIndex] is Int32) + return new LSLInteger((int)m_data[itemIndex]); + else if (m_data[itemIndex] is LSL_Types.LSLString) + return new LSLInteger((string)m_data[itemIndex]); + else + throw new InvalidCastException(); } public LSL_Types.Vector3 GetVector3Item(int itemIndex) @@ -1331,6 +1354,12 @@ namespace OpenSim.Region.ScriptEngine.Shared m_string=s; } + public LSLString(LSLInteger i) + { + string s = String.Format("{0}", i); + m_string = s; + } + #endregion #region Operators -- cgit v1.1