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)
remotes/origin/0.6.7-post-fixes
Arthur Valadares 2009-08-21 21:12:22 -03:00
parent 604ef5ba79
commit 7923fd29a0
5 changed files with 98 additions and 18 deletions

View File

@ -469,13 +469,19 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
startPoint.X += endPoint.X; startPoint.X += endPoint.X;
startPoint.Y += endPoint.Y; startPoint.Y += endPoint.Y;
} }
else if (nextLine.StartsWith("FillPolygon"))
{
PointF[] points = null;
GetParams(partsDelimiter, ref nextLine, 11, ref points);
graph.FillPolygon(myBrush, points);
}
else if (nextLine.StartsWith("Ellipse")) else if (nextLine.StartsWith("Ellipse"))
{ {
float x = 0; float x = 0;
float y = 0; float y = 0;
GetParams(partsDelimiter, ref nextLine, 7, ref x, ref y); GetParams(partsDelimiter, ref nextLine, 7, ref x, ref y);
endPoint.X = (int) x; endPoint.X = (int)x;
endPoint.Y = (int) y; endPoint.Y = (int)y;
graph.DrawEllipse(drawPen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); graph.DrawEllipse(drawPen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
startPoint.X += endPoint.X; startPoint.X += endPoint.X;
startPoint.Y += endPoint.Y; startPoint.Y += endPoint.Y;
@ -492,30 +498,31 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
nextLine = nextLine.Remove(0, 8); nextLine = nextLine.Remove(0, 8);
nextLine = nextLine.Trim(); nextLine = nextLine.Trim();
string [] fprops = nextLine.Split(partsDelimiter); string[] fprops = nextLine.Split(partsDelimiter);
foreach (string prop in fprops) { foreach (string prop in fprops)
{
switch (prop) switch (prop)
{ {
case "B": case "B":
if (!(myFont.Bold)) if (!(myFont.Bold))
myFont = new Font(myFont, myFont.Style | FontStyle.Bold); myFont = new Font(myFont, myFont.Style | FontStyle.Bold);
break; break;
case "I": case "I":
if (!(myFont.Italic)) if (!(myFont.Italic))
myFont = new Font(myFont, myFont.Style | FontStyle.Italic); myFont = new Font(myFont, myFont.Style | FontStyle.Italic);
break; break;
case "U": case "U":
if (!(myFont.Underline)) if (!(myFont.Underline))
myFont = new Font(myFont, myFont.Style | FontStyle.Underline); myFont = new Font(myFont, myFont.Style | FontStyle.Underline);
break; break;
case "S": case "S":
if (!(myFont.Strikeout)) if (!(myFont.Strikeout))
myFont = new Font(myFont, myFont.Style | FontStyle.Strikeout); myFont = new Font(myFont, myFont.Style | FontStyle.Strikeout);
break; break;
case "R": case "R":
myFont = new Font(myFont, FontStyle.Regular); myFont = new Font(myFont, FontStyle.Regular);
break; break;
} }
} }
} }
@ -582,6 +589,25 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
} }
} }
private static void GetParams(char[] partsDelimiter, ref string line, int startLength, ref PointF[] points)
{
line = line.Remove(0, startLength);
string[] parts = line.Split(partsDelimiter);
if (parts.Length > 1 && parts.Length % 2 == 0)
{
points = new PointF[parts.Length / 2];
for (int i = 0; i < parts.Length; i = i + 2)
{
string xVal = parts[i].Trim();
string yVal = parts[i+1].Trim();
float x = Convert.ToSingle(xVal, CultureInfo.InvariantCulture);
float y = Convert.ToSingle(yVal, CultureInfo.InvariantCulture);
PointF point = new PointF(x, y);
points[i / 2] = point;
}
}
}
private Bitmap ImageHttpRequest(string url) private Bitmap ImageHttpRequest(string url)
{ {
WebRequest request = HttpWebRequest.Create(url); WebRequest request = HttpWebRequest.Create(url);

View File

@ -833,6 +833,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return drawList; 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) public string osSetFontSize(string drawList, int fontSize)
{ {
CheckThreatLevel(ThreatLevel.None, "osSetFontSize"); CheckThreatLevel(ThreatLevel.None, "osSetFontSize");

View File

@ -97,6 +97,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
string osDrawEllipse(string drawList, int width, int height); string osDrawEllipse(string drawList, int width, int height);
string osDrawRectangle(string drawList, int width, int height); string osDrawRectangle(string drawList, int width, int height);
string osDrawFilledRectangle(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 osSetFontSize(string drawList, int fontSize);
string osSetPenSize(string drawList, int penSize); string osSetPenSize(string drawList, int penSize);
string osSetPenColour(string drawList, string colour); string osSetPenColour(string drawList, string colour);

View File

@ -267,6 +267,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
return m_OSSL_Functions.osDrawFilledRectangle(drawList, width, height); 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) public string osSetFontSize(string drawList, int fontSize)
{ {
return m_OSSL_Functions.osSetFontSize(drawList, fontSize); return m_OSSL_Functions.osSetFontSize(drawList, fontSize);

View File

@ -439,6 +439,13 @@ namespace OpenSim.Region.ScriptEngine.Shared
set {m_data = value; } 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. // Member functions to obtain item as specific types.
// For cases where implicit conversions would apply if items // 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]); 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 else
{ {
return (LSL_Types.LSLFloat)m_data[itemIndex]; 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]); 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 else
{ {
return (LSL_Types.LSLString)m_data[itemIndex]; return (LSL_Types.LSLString)m_data[itemIndex];
} }
} }
public LSL_Types.LSLInteger GetLSLIntegerItem(int itemIndex) public LSL_Types.LSLInteger GetLSLIntegerItem(int itemIndex)
{ {
if (m_data[itemIndex] is LSL_Types.LSLInteger) if (m_data[itemIndex] is LSL_Types.LSLInteger)
return (LSL_Types.LSLInteger)m_data[itemIndex]; return (LSL_Types.LSLInteger)m_data[itemIndex];
else if (m_data[itemIndex] is Int32) if (m_data[itemIndex] is LSL_Types.LSLFloat)
return new LSLInteger((int)m_data[itemIndex]); return new LSLInteger((int)m_data[itemIndex]);
else else if (m_data[itemIndex] is Int32)
throw new InvalidCastException(); 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) public LSL_Types.Vector3 GetVector3Item(int itemIndex)
@ -1331,6 +1354,12 @@ namespace OpenSim.Region.ScriptEngine.Shared
m_string=s; m_string=s;
} }
public LSLString(LSLInteger i)
{
string s = String.Format("{0}", i);
m_string = s;
}
#endregion #endregion
#region Operators #region Operators