Advertisement
maxkhl

Untitled

Jan 5th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.26 KB | None | 0 0
  1. double ViewDistance = 0.9;
  2. private int DrawSystems(List<Data.System> Systems, Rectangle ScreenRectangle)
  3. {
  4.     var DefaultOption = new SystemDrawOptions();
  5.     int DrawnSystems = 0;
  6.     List<Data.System> SystemsWithText = new List<Data.System>();
  7.  
  8.     var bitmap = new Bitmap(img);
  9.     var bitmapData = bitmap.LockBits(
  10.         new Rectangle(System.Drawing.Point.Empty, img.Size),
  11.         ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
  12.     var bitsPerPixel = (((int)bitmapData.PixelFormat >> 8) & 0xFF) / 8;
  13.     int bWidth = bitmap.Width,
  14.         bHeight = bitmap.Height;
  15.  
  16.     unsafe
  17.     {
  18.         var pixelDataPointer = (byte*)bitmapData.Scan0;
  19.  
  20.         foreach (var system in Systems)
  21.         {
  22.             var Options = DefaultOption;
  23.             if (Style.ContainsKey(system))
  24.                 Options = Style[system];
  25.  
  26.             int DrawSize = 2;
  27.             if (Options.Size > 0)
  28.                 DrawSize = Options.Size;
  29.  
  30.  
  31.  
  32.             var DrawRect = GetSystemScreenRect(system, ScreenRectangle, DrawSize);
  33.             var CheckRect = new Rectangle(new System.Drawing.Point(ScreenRectangle.X - DrawSize, ScreenRectangle.Y - DrawSize), new System.Drawing.Size(ScreenRectangle.Width + DrawSize * 2, ScreenRectangle.Height + DrawSize * 2));
  34.             if (DrawRect.IntersectsWith(CheckRect))
  35.             {
  36.  
  37.                 if (DrawRect.X > 0 && DrawRect.X < bWidth &&
  38.                     DrawRect.Y > 0 && DrawRect.Y < bHeight)
  39.                 {
  40.  
  41.                     var target = bitmapData.Stride * DrawRect.Y + 0 + DrawRect.X * bitsPerPixel;
  42.                     pixelDataPointer[target] = (byte)(255 + pixelDataPointer[target]); //Blue
  43.                     pixelDataPointer[target + 1] = (byte)(255 + pixelDataPointer[target + 1]); //Green
  44.                     pixelDataPointer[target + 2] = (byte)(255 + pixelDataPointer[target + 2]); //Red
  45.  
  46.                 }
  47.  
  48.                 if (Options.ShowName || Options.Text != null)
  49.                     SystemsWithText.Add(system);
  50.  
  51.                 DrawnSystems++;
  52.             }
  53.         }
  54.  
  55.     }
  56.     bitmap.UnlockBits(bitmapData);
  57.     img = bitmap;
  58.     graphics = Graphics.FromImage(img);
  59.     foreach (var system in SystemsWithText)
  60.     {
  61.         var Options = DefaultOption;
  62.         if (Style.ContainsKey(system))
  63.             Options = Style[system];
  64.  
  65.         int DrawSize = 1;
  66.         if (Options.Size > 0)
  67.             DrawSize = Options.Size;
  68.                
  69.         var DrawRect = GetSystemScreenRect(system, ScreenRectangle, DrawSize);
  70.         var CheckRect = new Rectangle(new System.Drawing.Point(ScreenRectangle.X - DrawSize, ScreenRectangle.Y - DrawSize), new System.Drawing.Size(ScreenRectangle.Width + DrawSize * 2, ScreenRectangle.Height + DrawSize * 2));
  71.         if (DrawRect.IntersectsWith(CheckRect))
  72.         {
  73.  
  74.             var Pos = DrawRect.Location + DrawRect.Size;
  75.             if (Options.ShowName)
  76.             {
  77.                 graphics.DrawString(system.name, System.Drawing.SystemFonts.DefaultFont, StarBrush, Pos);
  78.                 Pos.Y += 15;
  79.             }
  80.  
  81.             if (Options.Text != null)
  82.             {
  83.                 graphics.DrawString(Options.Text, System.Drawing.SystemFonts.DefaultFont, StarBrush, Pos);
  84.             }
  85.         }
  86.     }
  87.  
  88.  
  89.     return DrawnSystems;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement