From 2537311dfe71571b7bdb401ad4943cd932573747 Mon Sep 17 00:00:00 2001 From: Latif Khalifa Date: Mon, 31 May 2010 03:41:28 +0000 Subject: [PATCH] Show location of people on the map. git-svn-id: https://radegast.googlecode.com/svn/branches/legacy_map@662 f7a694da-4d33-11de-9ad6-1127a62b9fcd --- Radegast/Core/Types/MapControl.cs | 136 +++++++++++++++++++++++++----- Radegast/Properties/Resources.Designer.cs | 7 ++ Radegast/Properties/Resources.resx | 3 + Radegast/Radegast.csproj | 1 + Radegast/Resources/map_dot.png | Bin 0 -> 2927 bytes 5 files changed, 125 insertions(+), 22 deletions(-) create mode 100644 Radegast/Resources/map_dot.png diff --git a/Radegast/Core/Types/MapControl.cs b/Radegast/Core/Types/MapControl.cs index a510a8e..73a7eaa 100644 --- a/Radegast/Core/Types/MapControl.cs +++ b/Radegast/Core/Types/MapControl.cs @@ -26,15 +26,19 @@ namespace Radegast Font textFont; Brush textBrush; Brush textBackgroudBrush; + Brush dotBrush; + Pen blackPen; uint regionSize = 256; float pixelsPerMeter; double centerX, centerY, targetX, targetY; - #pragma warning disable 0649 +#pragma warning disable 0649 GridRegion targetRegion, nullRegion; bool centered = false; int PixRegS; - float maxZoom = 8f, minZoom = 0.5f; + float maxZoom = 6f, minZoom = 0.5f; string targetParcelName = null; + System.Threading.Timer repaint; + bool needRepaint = false; public bool UseExternalTiles = false; public event EventHandler MapTargetChanged; @@ -54,8 +58,12 @@ namespace Radegast background = Color.FromArgb(4, 4, 75); textFont = new Font(FontFamily.GenericSansSerif, 8.0f, FontStyle.Bold); textBrush = new SolidBrush(Color.FromArgb(255, 200, 200, 200)); + dotBrush = new SolidBrush(Color.FromArgb(255, 30, 210, 30)); + blackPen = new Pen(Color.Black, 2.0f); textBackgroudBrush = new SolidBrush(Color.Black); + repaint = new System.Threading.Timer(RepaintTick, null, 1000, 1000); + Instance.ClientChanged += new EventHandler(Instance_ClientChanged); RegisterClientEvents(); } @@ -64,14 +72,28 @@ namespace Radegast { UnregisterClientEvents(Client); - downloader.Dispose(); + if (repaint != null) + { + repaint.Dispose(); + repaint = null; + } - lock (regionTiles) + if (downloader != null) { - foreach (Image img in regionTiles.Values) - if (img != null) - img.Dispose(); - regionTiles.Clear(); + downloader.Dispose(); + downloader = null; + } + + if (regionTiles != null) + { + lock (regionTiles) + { + foreach (Image img in regionTiles.Values) + if (img != null) + img.Dispose(); + regionTiles.Clear(); + } + regionTiles = null; } } @@ -91,25 +113,45 @@ namespace Radegast Client.Grid.GridLayer -= new EventHandler(Grid_GridLayer); } + void RepaintTick(object sync) + { + if (needRepaint) + { + needRepaint = false; + SafeInvalidate(); + } + } + void Grid_GridLayer(object sender, GridLayerEventArgs e) { - // int foo = 1; } - Dictionary regionMapItems = new Dictionary(); + Dictionary> regionMapItems = new Dictionary>(); Dictionary regions = new Dictionary(); void Grid_GridItems(object sender, GridItemsEventArgs e) { foreach (MapItem item in e.Items) { - regionMapItems[item.RegionHandle] = item; + if (item is MapAgentLocation) + { + MapAgentLocation loc = (MapAgentLocation)item; + lock (regionMapItems) + { + if (!regionMapItems.ContainsKey(item.RegionHandle)) + { + regionMapItems[loc.RegionHandle] = new List(); + } + regionMapItems[loc.RegionHandle].Add(loc); + } + if (loc.AvatarCount > 0) needRepaint = true; + } } - } void Grid_GridRegion(object sender, GridRegionEventArgs e) { + needRepaint = true; regions[e.Region.RegionHandle] = e.Region; if (!UseExternalTiles && e.Region.Access != SimAccess.NonExistent @@ -145,11 +187,10 @@ namespace Radegast { targetRegion = nullRegion; targetX = targetY = -5000000000d; - SafeInvalidate(); ThreadPool.QueueUserWorkItem(sync => { Thread.Sleep(500); - SafeInvalidate(); + needRepaint = true; } ); } @@ -180,6 +221,11 @@ namespace Radegast centerX = (double)regionX * 256 + (double)localX; centerY = (double)regionY * 256 + (double)localY; centered = true; + // opensim grids need extra push + if (!Instance.Netcom.Grid.ID.ToLower().Contains("secondlife")) + { + Client.Grid.RequestMapLayer(GridLayerType.Objects); + } SafeInvalidate(); } @@ -234,7 +280,7 @@ namespace Radegast if (OpenMetaverse.Imaging.OpenJPEG.DecodeToImage(Client.Assets.Cache.GetCachedAssetBytes(imageID), out mi, out img)) { regionTiles[handle] = img; - SafeInvalidate(); + needRepaint = true; } lock (tileRequests) if (tileRequests.Contains(handle)) @@ -256,7 +302,7 @@ namespace Radegast if (OpenMetaverse.Imaging.OpenJPEG.DecodeToImage(responseData, out mi, out img)) { regionTiles[handle] = img; - SafeInvalidate(); + needRepaint = true; Client.Assets.Cache.SaveAssetToCache(imageID, responseData); } } @@ -287,7 +333,7 @@ namespace Radegast if (OpenMetaverse.Imaging.OpenJPEG.DecodeToImage(assetTexture.AssetData, out mi, out img)) { regionTiles[handle] = img; - SafeInvalidate(); + needRepaint = true; } } goto default; @@ -347,7 +393,7 @@ namespace Radegast lock (regionTiles) { regionTiles[handle] = Image.FromStream(s); - SafeInvalidate(); + needRepaint = true; } } } @@ -377,6 +423,7 @@ namespace Radegast string name = GetRegionName(handle); Image tile = null; + // Get and draw image tile if (UseExternalTiles) tile = GetRegionTileExternal(handle); else @@ -385,7 +432,7 @@ namespace Radegast if (tile != null) { int targetSize = 256; - for (targetSize = 128; targetSize > PixRegS; targetSize /= 2); + for (targetSize = 128; targetSize > PixRegS; targetSize /= 2) ; targetSize *= 2; if (targetSize != 256) { @@ -409,12 +456,15 @@ namespace Radegast g.DrawImage(tile, new Rectangle(x, y - PixRegS, PixRegS, PixRegS)); } + // Print region name if (!string.IsNullOrEmpty(name) && zoom < 3f) + { Print(g, x + 2, y - 16, name); - + } } List requestedBlocks = new List(); + List requestedLocations = new List(); private void MapControl_Paint(object sender, PaintEventArgs e) { @@ -456,7 +506,15 @@ namespace Radegast int pixY = pixCenterRegionY - (ry - (int)regY) * PixRegS; ulong handle = Utils.UIntsToLong((uint)rx * regionSize, (uint)ry * regionSize); - //Client.Grid.RequestMapItems(handle, OpenMetaverse.GridItemType.AgentLocations, GridLayerType.Objects); + lock (requestedLocations) + { + if (!requestedLocations.Contains(handle)) + { + requestedLocations.Add(handle); + Client.Grid.RequestMapItems(handle, OpenMetaverse.GridItemType.AgentLocations, GridLayerType.Objects); + } + } + DrawRegion(g, pixX, pixY, @@ -474,6 +532,40 @@ namespace Radegast float ratio = (float)PixRegS / (float)regionSize; + // Draw agent dots + for (int ry = regBottom; ry <= regYMax; ry++) + { + for (int rx = regLeft; rx <= regXMax; rx++) + { + int pixX = pixCenterRegionX - ((int)regX - rx) * PixRegS; + int pixY = pixCenterRegionY - (ry - (int)regY) * PixRegS; + ulong handle = Utils.UIntsToLong((uint)rx * regionSize, (uint)ry * regionSize); + + lock (regionMapItems) + { + if (regionMapItems.ContainsKey(handle)) + { + foreach (MapItem i in regionMapItems[handle]) + { + if (i is MapAgentLocation) + { + MapAgentLocation loc = (MapAgentLocation)i; + if (loc.AvatarCount == 0) continue; + int dotX = pixX + (int)((float)loc.LocalX * ratio); + int dotY = pixY - (int)((float)loc.LocalY * ratio); + for (int j = 0; j < loc.AvatarCount; j++) + { + g.FillEllipse(dotBrush, dotX, dotY - (j * 3), 7, 7); + g.DrawEllipse(blackPen, dotX, dotY - (j * 3), 7, 7); + //g.DrawImageUnscaled(Properties.Resources.map_dot, dotX, dotY - (j * 4)); + } + } + } + } + } + } + } + if (foundMyPos) { int myPosX = (int)(myRegX + Client.Self.SimPosition.X * ratio); @@ -564,7 +656,7 @@ namespace Radegast { targetParcelName = e.Parcel.Name; done.Set(); - SafeInvalidate(); + needRepaint = true; } }; Client.Parcels.ParcelInfoReply += handler; diff --git a/Radegast/Properties/Resources.Designer.cs b/Radegast/Properties/Resources.Designer.cs index 7689981..819d4aa 100644 --- a/Radegast/Properties/Resources.Designer.cs +++ b/Radegast/Properties/Resources.Designer.cs @@ -568,6 +568,13 @@ namespace Radegast.Properties { } } + public static System.Drawing.Bitmap map_dot { + get { + object obj = ResourceManager.GetObject("map_dot", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + public static System.Drawing.Bitmap mic { get { object obj = ResourceManager.GetObject("mic", resourceCulture); diff --git a/Radegast/Properties/Resources.resx b/Radegast/Properties/Resources.resx index 90ba3b4..32ecf4f 100644 --- a/Radegast/Properties/Resources.resx +++ b/Radegast/Properties/Resources.resx @@ -379,4 +379,7 @@ ..\Resources\target_map_pos.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\map_dot.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/Radegast/Radegast.csproj b/Radegast/Radegast.csproj index c1b9d27..995c743 100644 --- a/Radegast/Radegast.csproj +++ b/Radegast/Radegast.csproj @@ -1117,6 +1117,7 @@ + diff --git a/Radegast/Resources/map_dot.png b/Radegast/Resources/map_dot.png new file mode 100644 index 0000000000000000000000000000000000000000..6bcf4f4a091bbd9a8e09ef99a6420ee93d5b259e GIT binary patch literal 2927 zcmV-#3y}1QP)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%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