本文整理汇总了C#中Icon.Initialize方法的典型用法代码示例。如果您正苦于以下问题:C# Icon.Initialize方法的具体用法?C# Icon.Initialize怎么用?C# Icon.Initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Icon
的用法示例。
在下文中一共展示了Icon.Initialize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Render
/// <summary>
/// Draw the icon
/// </summary>
protected virtual void Render(DrawArgs drawArgs, Icon icon, Vector3 projectedPoint)
{
if (!icon.isInitialized)
icon.Initialize(drawArgs);
if(!drawArgs.WorldCamera.ViewFrustum.ContainsPoint(icon.Position))
return;
// Check icons for within "visual" range
double distanceToIcon = Vector3.Length(icon.Position - drawArgs.WorldCamera.Position);
if(distanceToIcon > icon.MaximumDisplayDistance)
return;
if(distanceToIcon < icon.MinimumDisplayDistance)
return;
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;
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 || icon.NameAlwaysVisible)
{
// 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 rect = new Rectangle(
(int)projectedPoint.X - (labelWidth>>1),
(int)(projectedPoint.Y - (drawArgs.defaultDrawingFont.Description.Height >> 1)),
labelWidth,
drawArgs.screenHeight );
drawArgs.defaultDrawingFont.DrawText(m_sprite, icon.Name, rect, 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;
//.........这里部分代码省略.........
示例2: Render
protected override void Render(DrawArgs drawArgs, Icon icon, Vector3 projectedPoint)
{
if (!icon.Initialized) {
icon.Initialize(drawArgs);
return;
}
if (!drawArgs.WorldCamera.ViewFrustum.ContainsPoint(icon.Position)) {
return;
}
// check whether in icon's visual range.
float distanceToIcon = Vector3.Length(icon.Position - drawArgs.WorldCamera.Position);
if (distanceToIcon > icon.MaximumDisplayDistance) {
return;
}
if (distanceToIcon < icon.MinimumDisplayDistance) {
return;
}
IconTexture iconTexture = this.GetTexture(icon);
// check is mouse over.
bool isMouseOver = (icon == this.mouseOverIcon);
if (isMouseOver) {
if (icon.IsSelectable) {
DrawArgs.MouseCursor = CursorType.Hand;
}
// get icon's description.
string description = icon.Description;
if (description == null) {
description = icon.ClickableActionURL;
}
if (description != null) {
// Render the description field.
DrawTextFormat descTextFormat = DrawTextFormat.NoClip;
descTextFormat |= DrawTextFormat.WordBreak;
descTextFormat |= DrawTextFormat.Bottom;
int left = 10;
//if (World.Settings.ShowLayerManager) {
// left += World.Settings.LayerManagerWidth;
//}
Rectangle descRectangle = Rectangle.FromLTRB(left, 10, drawArgs.ScreenWidth - 10, drawArgs.ScreenHeight - 10);
// Draw outline
this.DrawOutline(drawArgs.DefaultDrawingFont, this.m_sprite, description, ref descRectangle, descTextFormat);
// Draw description
drawArgs.DefaultDrawingFont.DrawText(this.m_sprite, description, descRectangle, descTextFormat, descriptionColor);
}
}
int color = isMouseOver ? hotColor : normalColor;
// calculate scale
double scale = (drawArgs.WorldCamera.WorldRadius + icon.Altitude)/(drawArgs.WorldCamera.WorldRadius + distanceToIcon);
scale *= drawArgs.WorldCamera.TargetDistance/distanceToIcon;
//
// render name field.
if (icon.Name != null) {
Rectangle nameRectangle = drawArgs.DefaultDrawingFont.MeasureString(this.m_sprite, icon.Name, DrawTextFormat.Center, color);
nameRectangle.X = (int) projectedPoint.X - (nameRectangle.Width >> 1);
if (iconTexture == null) {
// by zzm start
nameRectangle.Y = (int) projectedPoint.Y - (drawArgs.DefaultDrawingFont.Description.Height >> 1);
// by zzm end
this.DrawOutline(drawArgs.DefaultDrawingFont, this.m_sprite, icon.Name, ref nameRectangle, DrawTextFormat.Center);
drawArgs.DefaultDrawingFont.DrawText(this.m_sprite, icon.Name, nameRectangle, DrawTextFormat.Center, color);
}
else {
// adjust text to make room for icon.
int spacing = 10;
int offsetForIcon = (int) (icon.Height*scale) + spacing;
nameRectangle.Y = (int) projectedPoint.Y - offsetForIcon - (drawArgs.DefaultDrawingFont.Description.Height >> 1);
this.DrawOutline(drawArgs.DefaultDrawingFont, this.m_sprite, icon.Name, ref nameRectangle, DrawTextFormat.Center);
drawArgs.DefaultDrawingFont.DrawText(this.m_sprite, icon.Name, nameRectangle, DrawTextFormat.Center, color);
}
}
if (iconTexture != null) {
// render icon
// get icon's current scale
float xScale = (float) scale; //icon.Width / iconTexture.Width;
float yScale = (float) scale; //icon.Height / iconTexture.Height;
this.m_sprite.Transform = Matrix.Scaling(xScale, yScale, 0);
this.m_sprite.Transform *= Matrix.Translation(projectedPoint.X, projectedPoint.Y, 0);
this.m_sprite.Draw(iconTexture.Texture, new Vector3(iconTexture.Width, iconTexture.Height, 0), Vector3.Empty, color);
this.m_sprite.Transform = Matrix.Identity;
}
}