コード例 #1
0
ファイル: KMLImporter.cs プロジェクト: jpespartero/WorldWind
		public override void Render(DrawArgs drawArgs)
		{
			if(!isOn)
				return;

			if(!isInitialized)
				return;

			Vector3 referenceCenter = new Vector3(
				(float)drawArgs.WorldCamera.ReferenceCenter.X,
				(float)drawArgs.WorldCamera.ReferenceCenter.Y,
				(float)drawArgs.WorldCamera.ReferenceCenter.Z);

			// First render everything except icons
			foreach(RenderableObject ro in m_children)
			{
				if(ro is RIcon)
					continue;

				if(!ro.IsOn)
					continue;

				// Child is not an icon
				ro.Render(drawArgs);
			}

			labelRectangles.Clear();

			int closestIconDistanceSquared = int.MaxValue;
			RIcon closestIcon = null;

			// Now render just the icons
			m_sprite.Begin(SpriteFlags.AlphaBlend);
			foreach(RenderableObject ro in m_children)
			{
				if(!ro.IsOn)
					continue;

				RIcon icon = ro as RIcon;
				if(icon == null)
					continue;

				// Find closest mouse-over icon
				Vector3 projectedPoint = drawArgs.WorldCamera.Project(icon.Position - referenceCenter);

                // Ashish Datta - Show/Hide the description bubble.
                
                if (icon.IsDescriptionVisible == true)
                {
                    if (!drawArgs.WorldCamera.ViewFrustum.ContainsPoint(icon.Position))
                    {
                        icon.DescriptionBubble.Hide();
                        icon.IsDescriptionVisible = false;
                    }
                    else
                    {
                        if (icon.DescriptionBubble.isVisible == true)
                        {
                            icon.DescriptionBubble.Location = new Point((int)projectedPoint.X + (icon.Width/4), (int)projectedPoint.Y);
                            icon.DescriptionBubble.Show();

                            if(icon.DescriptionBubble.HTMLIsSet == false)
                                icon.DescriptionBubble.SetHTML(icon.Description);
                            
                            icon.DescriptionBubble.BringToFront();
                        }

                    }
                }

				int dx = DrawArgs.LastMousePosition.X - (int)projectedPoint.X;
				int dy = DrawArgs.LastMousePosition.Y - (int)projectedPoint.Y;
				if( icon.SelectionRectangle.Contains( dx, dy ) )
				{
					// Mouse is over, check whether this icon is closest
					int distanceSquared = dx*dx + dy*dy;
					if(distanceSquared < closestIconDistanceSquared)
					{
						closestIconDistanceSquared = distanceSquared;
						closestIcon = icon;
					}
				}

				if(icon != mouseOverIcon)
					Render(drawArgs, icon, projectedPoint);
			}

			labelRectangles.Clear();

			// Render the mouse over icon last (on top)
			if(mouseOverIcon != null)
				Render(drawArgs, mouseOverIcon, drawArgs.WorldCamera.Project(mouseOverIcon.Position - referenceCenter));

			mouseOverIcon = closestIcon;

			m_sprite.End();
		}
コード例 #2
0
ファイル: KMLImporter.cs プロジェクト: jpespartero/WorldWind
		/// <summary>
		/// Retrieve an icon's texture
		/// </summary>
		private IconTexture GetTexture(RIcon icon)
		{
			object key = icon.Image;
			if(key==null)
				return null;
			IconTexture res = (IconTexture)m_textures[key];
			return res;
		}
コード例 #3
0
ファイル: KMLImporter.cs プロジェクト: jpespartero/WorldWind
		/// <summary>
		/// Adds an icon to this layer. Deprecated.
		/// </summary>
		internal void AddIcon(RIcon icon)
		{
			icon.ParentList = this;
			Add(icon);
		}
コード例 #4
0
ファイル: KMLImporter.cs プロジェクト: jpespartero/WorldWind
		/// <summary>
		/// Draw the icon
		/// </summary>
		protected virtual void Render(DrawArgs drawArgs, RIcon icon, Vector3 projectedPoint)
		{
			if (!icon.isInitialized)
				icon.Initialize(drawArgs);

			if(!drawArgs.WorldCamera.ViewFrustum.ContainsPoint(icon.Position))
				return;

			Vector3 referenceCenter = new Vector3(
				(float)drawArgs.WorldCamera.ReferenceCenter.X,
				(float)drawArgs.WorldCamera.ReferenceCenter.Y,
				(float)drawArgs.WorldCamera.ReferenceCenter.Z);

			IconTexture iconTexture = GetTexture(icon);
			bool isMouseOver = icon == mouseOverIcon;
			if(isMouseOver)
			{
				// Mouse is over
				isMouseOver = true;

				if(icon.isSelectable)
					DrawArgs.MouseCursor = CursorType.Hand;

				string description = icon.Description;

                // Ashish Datta - Commented. Descriptions will appear in bubbles not on the bottom of the screen.

                /*
				if(description==null)
					description = icon.ClickableActionURL;
				if(description!=null)
				{
					// Render description field
					DrawTextFormat format = DrawTextFormat.NoClip | DrawTextFormat.WordBreak | DrawTextFormat.Bottom;
					int left = 10;
					if(World.Settings.ShowLayerManager)
						left += World.Settings.LayerManagerWidth;
					Rectangle rect = Rectangle.FromLTRB(left, 10, drawArgs.screenWidth - 10, drawArgs.screenHeight - 10 );

					// Draw outline
					drawArgs.defaultDrawingFont.DrawText(
						m_sprite, description,
						rect,
						format, 0xb0 << 24 );
					
					rect.Offset(2,0);
					drawArgs.defaultDrawingFont.DrawText(
						m_sprite, description,
						rect,
						format, 0xb0 << 24 );

					rect.Offset(0,2);
					drawArgs.defaultDrawingFont.DrawText(
						m_sprite, description,
						rect,
						format, 0xb0 << 24 );

					rect.Offset(-2,0);
					drawArgs.defaultDrawingFont.DrawText(
						m_sprite, description,
						rect,
						format, 0xb0 << 24 );

					// Draw description
					rect.Offset(1,-1);
					drawArgs.defaultDrawingFont.DrawText(
						m_sprite, description,
						rect, 
						format, descriptionColor );
				}*/
			}

			int color = isMouseOver ? hotColor : normalColor;
			if(iconTexture==null || isMouseOver || Settings.ShowAllLabels)
			{
				// Render label
				if(icon.Name != null)
				{
					// Render name field
					const int labelWidth = 1000; // Dummy value needed for centering the text
					if(iconTexture==null)
					{
						// Center over target as we have no bitmap
						Rectangle realrect = drawArgs.defaultDrawingFont.MeasureString(m_sprite, icon.Name, DrawTextFormat.WordBreak, color);
						realrect.X = (int)projectedPoint.X - (labelWidth>>1);
						realrect.Y = (int)(projectedPoint.Y - (drawArgs.defaultDrawingFont.Description.Height >> 1));

						bool bDraw = true;

						foreach (Rectangle drawnrect in labelRectangles)
						{
							if (realrect.IntersectsWith(drawnrect))
							{
								bDraw = false;
								break;
							}
						}

						if (bDraw)
						{
							labelRectangles.Add(realrect);
							drawArgs.defaultDrawingFont.DrawText(m_sprite, icon.Name, realrect, DrawTextFormat.Center, color);
						}
					}
					else
					{
						// Adjust text to make room for icon
						int spacing = (int)(icon.Width * 0.3f);
						if(spacing>10)
							spacing = 10;
						int offsetForIcon = (icon.Width>>1) + spacing;

						// Text to the right
						Rectangle rightrect = drawArgs.defaultDrawingFont.MeasureString(m_sprite, icon.Name, DrawTextFormat.WordBreak, color);
						rightrect.X = (int)projectedPoint.X + offsetForIcon;
						rightrect.Y = (int)(projectedPoint.Y - (drawArgs.defaultDrawingFont.Description.Height >> 1));

						// Text to the left
						Rectangle leftrect = drawArgs.defaultDrawingFont.MeasureString(m_sprite, icon.Name, DrawTextFormat.WordBreak, color);
						leftrect.X = (int)projectedPoint.X - offsetForIcon - rightrect.Width;
						leftrect.Y = (int)(projectedPoint.Y - (drawArgs.defaultDrawingFont.Description.Height >> 1));

						bool bDrawRight = true;
						bool bDrawLeft = true;

						foreach (Rectangle drawnrect in labelRectangles)
						{
							if (rightrect.IntersectsWith(drawnrect))
							{
								bDrawRight = false;
							}
							if (leftrect.IntersectsWith(drawnrect))
							{
								bDrawLeft = false;
							}
							if (!bDrawRight && !bDrawLeft)
							{
								break;
							}
						}

						if (bDrawRight)
						{
							labelRectangles.Add(rightrect);
							drawArgs.defaultDrawingFont.DrawText(m_sprite, icon.Name, rightrect, DrawTextFormat.WordBreak, color);
						}
						else if (bDrawLeft)
						{
							labelRectangles.Add(leftrect);
							drawArgs.defaultDrawingFont.DrawText(m_sprite, icon.Name, leftrect, DrawTextFormat.WordBreak, color);
						}
					}
				}
			}

			if (icon.m_drawGroundStick)
			{
				Vector3 projectedGroundPoint = drawArgs.WorldCamera.Project(icon.m_groundPoint - referenceCenter);

				m_groundStick.Begin();
				groundStick[0].X = projectedPoint.X;
				groundStick[0].Y = projectedPoint.Y;
				groundStick[1].X = projectedGroundPoint.X;
				groundStick[1].Y = projectedGroundPoint.Y;

				m_groundStick.Draw(groundStick, Color.Red.ToArgb());
				m_groundStick.End();
			}

			if(iconTexture!=null)
			{
				float factor = 1;
				if (drawArgs.WorldCamera.Altitude > minIconZoomAltitude)
					factor -= (float)((drawArgs.WorldCamera.Altitude - minIconZoomAltitude) / drawArgs.WorldCamera.Altitude);

				// Render icon
				float xscale = factor * ((float)icon.Width / iconTexture.Width);
				float yscale = factor * ((float)icon.Height / iconTexture.Height);
				m_sprite.Transform = Matrix.Scaling(xscale, yscale, 0);
				
				if (icon.IsRotated) m_sprite.Transform *= Matrix.RotationZ((float)icon.Rotation.Radians - (float) drawArgs.WorldCamera.Heading.Radians);

				m_sprite.Transform *= Matrix.Translation(projectedPoint.X, projectedPoint.Y, 0);
				m_sprite.Draw( iconTexture.Texture,
					new Vector3(iconTexture.Width>>1, iconTexture.Height>>1,0),
					Vector3.Empty,
					color);
				
				// Reset transform to prepare for text rendering later
				m_sprite.Transform = Matrix.Identity;
			}
		}
コード例 #5
0
ファイル: KMLImporter.cs プロジェクト: jpespartero/WorldWind
		/// <summary>
		/// Creates a scaled icon on the globe
		/// </summary>
		/// <param name="Name">The name of the item</param>
		/// <param name="Desc">The description</param>
		/// <param name="Lat">The latitude for the icon</param>
		/// <param name="Lon">The longitude for the icon</param>
		/// <param name="Alt">The altitude to draw the icon at</param>
		/// <param name="bitmapPath">The path to the bitmap to show</param>
		private void CreateIcon(RIcons layer, string Name, string Desc, string Uri, float Lat, float Lon, float Alt, 
			Style style, bool bRotated, float rotation, bool bExtrude)
		{
			// Create the icon and set initial settings
			RIcon ic = new RIcon(
				Name,									// name
				Lat,										// latitude
				Lon,										// longitude
				style.NormalIcon,							// helper
				Alt);									// altitude

			// Set optional icon settings
			if (Desc != null)
				ic.Description = Desc;
			if (Uri != null)
				ic.ClickableActionURL = Uri;
			if (bRotated)
			{
				ic.Rotation = Angle.FromDegrees(rotation);
				ic.IsRotated = true;
			}
			ic.m_drawGroundStick = bExtrude;
            if (style.NormalIcon != null && bitmapCache.Contains(style.NormalIcon))
            {
                ic.Image = (Bitmap)bitmapCache[style.NormalIcon];
                ic.Height = Double.IsNaN(style.NormalScale) ? IconSizeConstant : (int)(style.NormalScale * Math.Min(((Bitmap)bitmapCache[style.NormalIcon]).Height, IconSizeConstant));
                ic.Width = Double.IsNaN(style.NormalScale) ? IconSizeConstant : (int)(style.NormalScale * Math.Min(((Bitmap)bitmapCache[style.NormalIcon]).Width, IconSizeConstant));
            }

			// Add the icon to the layer
			layer.Add(ic);
		}