aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs122
1 files changed, 80 insertions, 42 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs b/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs
index 4cecd85..8a26ab7 100644
--- a/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs
@@ -117,7 +117,7 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
117 return true; 117 return true;
118 } 118 }
119 119
120 public void GetDrawStringSize(string text, string fontName, int fontSize, 120 public void GetDrawStringSize(string text, string fontName, int fontSize,
121 out double xSize, out double ySize) 121 out double xSize, out double ySize)
122 { 122 {
123 lock (this) 123 lock (this)
@@ -209,32 +209,32 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
209 int alpha = 255; // 0 is transparent 209 int alpha = 255; // 0 is transparent
210 Color bgColor = Color.White; // Default background color 210 Color bgColor = Color.White; // Default background color
211 char altDataDelim = ';'; 211 char altDataDelim = ';';
212 212
213 char[] paramDelimiter = { ',' }; 213 char[] paramDelimiter = { ',' };
214 char[] nvpDelimiter = { ':' }; 214 char[] nvpDelimiter = { ':' };
215 215
216 extraParams = extraParams.Trim(); 216 extraParams = extraParams.Trim();
217 extraParams = extraParams.ToLower(); 217 extraParams = extraParams.ToLower();
218 218
219 string[] nvps = extraParams.Split(paramDelimiter); 219 string[] nvps = extraParams.Split(paramDelimiter);
220 220
221 int temp = -1; 221 int temp = -1;
222 foreach (string pair in nvps) 222 foreach (string pair in nvps)
223 { 223 {
224 string[] nvp = pair.Split(nvpDelimiter); 224 string[] nvp = pair.Split(nvpDelimiter);
225 string name = ""; 225 string name = "";
226 string value = ""; 226 string value = "";
227 227
228 if (nvp[0] != null) 228 if (nvp[0] != null)
229 { 229 {
230 name = nvp[0].Trim(); 230 name = nvp[0].Trim();
231 } 231 }
232 232
233 if (nvp.Length == 2) 233 if (nvp.Length == 2)
234 { 234 {
235 value = nvp[1].Trim(); 235 value = nvp[1].Trim();
236 } 236 }
237 237
238 switch (name) 238 switch (name)
239 { 239 {
240 case "width": 240 case "width":
@@ -301,7 +301,7 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
301 if (Int32.TryParse(value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out hex)) 301 if (Int32.TryParse(value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out hex))
302 { 302 {
303 bgColor = Color.FromArgb(hex); 303 bgColor = Color.FromArgb(hex);
304 } 304 }
305 else 305 else
306 { 306 {
307 bgColor = Color.FromName(value); 307 bgColor = Color.FromName(value);
@@ -321,7 +321,7 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
321 } 321 }
322 else 322 else
323 { 323 {
324 // this function used to accept an int on its own that represented both 324 // this function used to accept an int on its own that represented both
325 // width and height, this is to maintain backwards compat, could be removed 325 // width and height, this is to maintain backwards compat, could be removed
326 // but would break existing scripts 326 // but would break existing scripts
327 temp = parseIntParam(name); 327 temp = parseIntParam(name);
@@ -329,10 +329,10 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
329 { 329 {
330 if (temp > 1024) 330 if (temp > 1024)
331 temp = 1024; 331 temp = 1024;
332 332
333 if (temp < 128) 333 if (temp < 128)
334 temp = 128; 334 temp = 128;
335 335
336 width = temp; 336 width = temp;
337 height = temp; 337 height = temp;
338 } 338 }
@@ -355,36 +355,28 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
355 lock (this) 355 lock (this)
356 { 356 {
357 if (alpha == 256) 357 if (alpha == 256)
358 bitmap = new Bitmap(width, height, PixelFormat.Format32bppRgb);
359 else
360 bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
361
362 graph = Graphics.FromImage(bitmap);
363
364 // this is really just to save people filling the
365 // background color in their scripts, only do when fully opaque
366 if (alpha >= 255)
367 { 358 {
359 bitmap = new Bitmap(width, height, PixelFormat.Format32bppRgb);
360 graph = Graphics.FromImage(bitmap);
368 using (SolidBrush bgFillBrush = new SolidBrush(bgColor)) 361 using (SolidBrush bgFillBrush = new SolidBrush(bgColor))
369 { 362 {
370 graph.FillRectangle(bgFillBrush, 0, 0, width, height); 363 graph.FillRectangle(bgFillBrush, 0, 0, width, height);
371 } 364 }
372 } 365 }
373 366 else
374 for (int w = 0; w < bitmap.Width; w++)
375 { 367 {
376 if (alpha <= 255) 368 bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
369 graph = Graphics.FromImage(bitmap);
370 Color newbg = Color.FromArgb(alpha,bgColor);
371 using (SolidBrush bgFillBrush = new SolidBrush(newbg))
377 { 372 {
378 for (int h = 0; h < bitmap.Height; h++) 373 graph.FillRectangle(bgFillBrush, 0, 0, width, height);
379 {
380 bitmap.SetPixel(w, h, Color.FromArgb(alpha, bitmap.GetPixel(w, h)));
381 }
382 } 374 }
383 } 375 }
384 376
385 GDIDraw(data, graph, altDataDelim, out reuseable); 377 GDIDraw(data, graph, altDataDelim, out reuseable);
386 } 378 }
387 379
388 byte[] imageJ2000 = new byte[0]; 380 byte[] imageJ2000 = new byte[0];
389 381
390 // This code exists for testing purposes, please do not remove. 382 // This code exists for testing purposes, please do not remove.
@@ -394,7 +386,7 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
394// imageJ2000 = s_asset2Data; 386// imageJ2000 = s_asset2Data;
395// 387//
396// s_flipper = !s_flipper; 388// s_flipper = !s_flipper;
397 389
398 try 390 try
399 { 391 {
400 imageJ2000 = OpenJPEG.EncodeFromImage(bitmap, true); 392 imageJ2000 = OpenJPEG.EncodeFromImage(bitmap, true);
@@ -420,13 +412,13 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
420 { 412 {
421 if (graph != null) 413 if (graph != null)
422 graph.Dispose(); 414 graph.Dispose();
423 415
424 if (bitmap != null) 416 if (bitmap != null)
425 bitmap.Dispose(); 417 bitmap.Dispose();
426 } 418 }
427 } 419 }
428 } 420 }
429 421
430 private int parseIntParam(string strInt) 422 private int parseIntParam(string strInt)
431 { 423 {
432 int parsed; 424 int parsed;
@@ -440,7 +432,7 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
440 // m_log.Debug("Problem with Draw. Please verify parameters." + e.ToString()); 432 // m_log.Debug("Problem with Draw. Please verify parameters." + e.ToString());
441 parsed = -1; 433 parsed = -1;
442 } 434 }
443 435
444 return parsed; 436 return parsed;
445 } 437 }
446 438
@@ -519,8 +511,32 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
519 511
520// m_log.DebugFormat("[VECTOR RENDER MODULE]: Processing line '{0}'", nextLine); 512// m_log.DebugFormat("[VECTOR RENDER MODULE]: Processing line '{0}'", nextLine);
521 513
514 if (nextLine.StartsWith("ResetTransf"))
515 {
516 graph.ResetTransform();
517 }
518 else if (nextLine.StartsWith("TransTransf"))
519 {
520 float x = 0;
521 float y = 0;
522 GetParams(partsDelimiter, ref nextLine, 11, ref x, ref y);
523 graph.TranslateTransform(x, y);
524 }
525 else if (nextLine.StartsWith("ScaleTransf"))
526 {
527 float x = 0;
528 float y = 0;
529 GetParams(partsDelimiter, ref nextLine, 11, ref x, ref y);
530 graph.ScaleTransform(x, y);
531 }
532 else if (nextLine.StartsWith("RotTransf"))
533 {
534 float x = 0;
535 GetParams(partsDelimiter, ref nextLine, 9, ref x);
536 graph.RotateTransform(x);
537 }
522 //replace with switch, or even better, do some proper parsing 538 //replace with switch, or even better, do some proper parsing
523 if (nextLine.StartsWith("MoveTo")) 539 else if (nextLine.StartsWith("MoveTo"))
524 { 540 {
525 float x = 0; 541 float x = 0;
526 float y = 0; 542 float y = 0;
@@ -572,7 +588,7 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
572 graph.DrawString("not an image. Please check URL.", errorFont, 588 graph.DrawString("not an image. Please check URL.", errorFont,
573 myBrush, new Point(startPoint.X, 12 + startPoint.Y)); 589 myBrush, new Point(startPoint.X, 12 + startPoint.Y));
574 } 590 }
575 591
576 graph.DrawRectangle(drawPen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); 592 graph.DrawRectangle(drawPen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
577 } 593 }
578 } 594 }
@@ -625,6 +641,17 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
625 startPoint.X += endPoint.X; 641 startPoint.X += endPoint.X;
626 startPoint.Y += endPoint.Y; 642 startPoint.Y += endPoint.Y;
627 } 643 }
644 else if (nextLine.StartsWith("FillEllipse"))
645 {
646 float x = 0;
647 float y = 0;
648 GetParams(partsDelimiter, ref nextLine, 11, ref x, ref y);
649 endPoint.X = (int)x;
650 endPoint.Y = (int)y;
651 graph.FillEllipse(myBrush, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
652 startPoint.X += endPoint.X;
653 startPoint.Y += endPoint.Y;
654 }
628 else if (nextLine.StartsWith("FontSize")) 655 else if (nextLine.StartsWith("FontSize"))
629 { 656 {
630 nextLine = nextLine.Remove(0, 8); 657 nextLine = nextLine.Remove(0, 8);
@@ -638,11 +665,11 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
638 { 665 {
639 nextLine = nextLine.Remove(0, 8); 666 nextLine = nextLine.Remove(0, 8);
640 nextLine = nextLine.Trim(); 667 nextLine = nextLine.Trim();
641 668
642 string[] fprops = nextLine.Split(partsDelimiter); 669 string[] fprops = nextLine.Split(partsDelimiter);
643 foreach (string prop in fprops) 670 foreach (string prop in fprops)
644 { 671 {
645 672
646 switch (prop) 673 switch (prop)
647 { 674 {
648 case "B": 675 case "B":
@@ -717,7 +744,7 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
717 else if (cap[0].ToLower() != "both") 744 else if (cap[0].ToLower() != "both")
718 return; 745 return;
719 string type = cap[1].ToLower(); 746 string type = cap[1].ToLower();
720 747
721 if (end) 748 if (end)
722 { 749 {
723 switch (type) 750 switch (type)
@@ -760,7 +787,7 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
760 nextLine = nextLine.Remove(0, 9); 787 nextLine = nextLine.Remove(0, 9);
761 nextLine = nextLine.Trim(); 788 nextLine = nextLine.Trim();
762 int hex = 0; 789 int hex = 0;
763 790
764 Color newColor; 791 Color newColor;
765 if (Int32.TryParse(nextLine, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out hex)) 792 if (Int32.TryParse(nextLine, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out hex))
766 { 793 {
@@ -790,6 +817,17 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
790 } 817 }
791 } 818 }
792 819
820 private static void GetParams(char[] partsDelimiter, ref string line, int startLength, ref float x)
821 {
822 line = line.Remove(0, startLength);
823 string[] parts = line.Split(partsDelimiter);
824 if (parts.Length > 0)
825 {
826 string xVal = parts[0].Trim();
827 x = Convert.ToSingle(xVal, CultureInfo.InvariantCulture);
828 }
829 }
830
793 private static void GetParams(char[] partsDelimiter, ref string line, int startLength, ref float x, ref float y) 831 private static void GetParams(char[] partsDelimiter, ref string line, int startLength, ref float x, ref float y)
794 { 832 {
795 line = line.Remove(0, startLength); 833 line = line.Remove(0, startLength);
@@ -861,4 +899,4 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
861 return null; 899 return null;
862 } 900 }
863 } 901 }
864} \ No newline at end of file 902}