📄 icons.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Drawing;
using Microsoft.WindowsMobile.DirectX;
using Microsoft.WindowsMobile.DirectX.Direct3D;
using WorldWindow;
namespace cfWorldWind
{
public class Icons
{
public Icons()
{
}
public LayerSet GetLayerSetXs(string filePath)
{
XmlSerializer xs = new XmlSerializer(typeof(LayerSet));
//string filePath = Settings.DirectoryLandmark + @"Landmark.xml";
FileStream fs = new FileStream(filePath, FileMode.Open);
LayerSet ls = (LayerSet)xs.Deserialize(fs);
fs.Close();
xs = null;
return ls;
}
List<IconClass> alIcons;
//Rectangle spriteSize = new Rectangle(0, 0, 128, 128);
Sprite sprite;
public class IconClass
{
public string name;
public float lat;
public float lon;
public Vector3 point;
public Texture texture;
public string url;
}
public void InitializeVertex(Device device, string filePath)
{
LayerSet ls = GetLayerSetXs(filePath);
InitializeVertex(device, ls);
}
public void InitializeVertex(Device device, LayerSet ls)
{
alIcons = new List<IconClass>();
sprite = new Sprite(device);
float heightAboveSurface = Settings.Radius + 100;
//LayerSet ls = GetLayerSetXs(filePath);
foreach (Icon icon in ls.Icon)
{
IconClass ic = new IconClass();
ic.name = icon.Name;
ic.lat = (float)icon.Latitude.Value;
ic.lon = (float)icon.Longitude.Value;
ic.url = icon.ClickableUrl;
ic.point = MathEngine.SphericalToCartesian(ic.lat, ic.lon, heightAboveSurface);
//make it easy for hit testing
ic.lat = ic.lat + 90;
ic.lon = ic.lon + 180;
string path = Settings.StorageCard + icon.TextureFilePath.Replace("Add-ons", "Data");
path = path.Replace("Flags Of The World", "FlagsOfTheWorld"); //lazy
path = path.Replace(".png", "Small.png"); //size issue
ic.texture = TextureLoader.FromFile(device, path, 0, 0, 1, 0, Format.Unknown, Pool.Managed, Filter.Box, Filter.Box, 0);
alIcons.Add(ic);
}
ls.Icon = null;
ls = null;
}
//TODO selection to spawn a URL?
public void RenderVertex(Device device, Camera camera, Rectangle spriteSize)
{
float decViewRange = (float)MathEngine.RadiansToDegrees(camera.ViewRange) / 4f; //not quire 1/2
float north = (camera.Latitude + 90) + decViewRange;
float east = (camera.Longitude + 180) + decViewRange;
float south = (camera.Latitude + 90) - decViewRange;
float west = (camera.Longitude + 180) - decViewRange;
float scaleWidth = .25f;
float scaleHeight = .25f;
uint iconWidth = 16;
uint iconHeight = 8;
foreach (IconClass ic in alIcons)
{
if (ic.lat <= north && ic.lat >= south && ic.lon <= east && ic.lon >= west)
{
Vector3 projectedPoint = ic.point;
projectedPoint.Project(device.Viewport, camera.Projection, camera.View, camera.World);
sprite.Begin(SpriteFlags.AlphaBlend);
sprite.Transform = Matrix.Transformation2D(new Vector2(0.0f, 0.0f),
0.0f, new Vector2(scaleWidth, scaleHeight),
new Vector2(0, 0), 0.0f, new Vector2(projectedPoint.X, projectedPoint.Y));
sprite.Draw(ic.texture, spriteSize, new Vector3(1.3f * iconWidth, 1.3f * iconHeight, 0), new Vector3(0, 0, 0), System.Drawing.Color.White);
sprite.End();
}
}
}
public void Dispose()
{
if (sprite != null)
{
sprite.Dispose();
sprite = null;
}
if (alIcons != null)
{
foreach (IconClass ic in alIcons)
{
if (ic.texture != null)
{
ic.texture.Dispose();
ic.texture = null;
}
}
alIcons.Clear();
alIcons = null;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -