public void Init() { PresentParameters present_params = new PresentParameters(); present_params.Windowed = true; present_params.SwapEffect = SwapEffect.Discard; _device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, present_params); font = new Microsoft.DirectX.Direct3D.Font(_device, 20, 0, FontWeight.Bold, 0, false, CharacterSet.Default, Precision.Default, FontQuality.Default, PitchAndFamily.DefaultPitch, "Arial"); _video = new Video("clock.avi"); _video.TextureReadyToRender += new TextureRenderEventHandler(_video_TextureReadyToRender); _video.RenderToTexture(_device); vertices = new CustomVertex.PositionTextured[6]; vertices[0].Position = new Vector3(1f, 1f, 0f); vertices[0].Tu = 0; vertices[0].Tv = 1; vertices[1].Position = new Vector3(-1f, -1f, 0f); vertices[1].Tu = 1; vertices[1].Tv = 1; vertices[2].Position = new Vector3(1f, -1f, 0f); vertices[2].Tu = 0; vertices[2].Tv = 0; vertices[3].Position = new Vector3(-1.1f, -0.99f, 0f); vertices[3].Tu = 1; vertices[3].Tv = 0; vertices[4].Position = new Vector3(0.99f, 1.1f, 0f); vertices[4].Tu = 0; vertices[4].Tv = 0; vertices[5].Position = new Vector3(-1.1f, 1.1f, 0f); vertices[5].Tu = 1; vertices[5].Tv = 1; }
/// <summary> /// The initialize graphics. /// </summary> /// <returns>The initialize graphics.</returns> /// <remarks></remarks> public bool InitializeGraphics() { // try // { render.CreateDevice(this); pc = new PortalContainer(portals, ref render.device); BSPModel.BSPDisplayedInfo.CreateVertexBuffers(ref render.device, ref bsp); BSPModel.BSPDisplayedInfo.CreateIndexBuffers(ref render.device, ref bsp); BSPModel.BSPDisplayedInfo.LoadShaderTextures(ref render.device, ref bsp); System.Drawing.Font systemfont = new System.Drawing.Font("Arial", 12f, FontStyle.Regular); text = new Font(render.device, systemfont); cam = new Camera2(this); cam.speed = 0.05f; // cam.fixedrotation = true; return(true); // } // catch (DirectXException) // { // Catch any errors and return a failure // return false; // } }
private RenderableObject getRenderableObjectListFromLayerSet(World curWorld, LayerSet.Type_LayerSet curLayerSet, string layerSetFile)//ref TreeNode treeNode) { RenderableObjectList rol = null; // If the layer set has icons, use the icon list layer as parent if (curLayerSet.HasIcon()) { rol = new Icons(curLayerSet.Name.Value); rol.RenderPriority = RenderPriority.Icons; } else { rol = new RenderableObjectList(curLayerSet.Name.Value); } if (curLayerSet.HasShowOnlyOneLayer()) { rol.ShowOnlyOneLayer = curLayerSet.ShowOnlyOneLayer.Value; } // HACK: This should be part of the settings if (curLayerSet.Name.ToString().ToUpper() == "PLACENAMES") { rol.RenderPriority = RenderPriority.Placenames; } if (curLayerSet.HasExtendedInformation()) { if (curLayerSet.ExtendedInformation.HasToolBarImage()) { rol.MetaData.Add("ToolBarImagePath", curLayerSet.ExtendedInformation.ToolBarImage.Value); } } if (curLayerSet.HasImageLayer()) { for (int i = 0; i < curLayerSet.ImageLayerCount; i++) { LayerSet.Type_ImageLayer curImageLayerType = curLayerSet.GetImageLayerAt(i); // <TexturePath> could contain Url, relative path, or absolute path string imagePath = null; string imageUrl = null; if (curImageLayerType.TexturePath.Value.ToLower(System.Globalization.CultureInfo.InvariantCulture).StartsWith(("http://"))) { imageUrl = curImageLayerType.TexturePath.Value; } else { imagePath = curImageLayerType.TexturePath.Value; if (!Path.IsPathRooted(imagePath)) { imagePath = Path.Combine(PluginEngineGlobal.DirectoryPath, imagePath); } } int transparentColor = 0; if (curImageLayerType.HasTransparentColor()) { transparentColor = System.Drawing.Color.FromArgb( curImageLayerType.TransparentColor.Red.Value, curImageLayerType.TransparentColor.Green.Value, curImageLayerType.TransparentColor.Blue.Value).ToArgb(); } ImageLayer newImageLayer = new ImageLayer( curImageLayerType.Name.Value, curWorld, (float)curImageLayerType.DistanceAboveSurface.Value, imagePath, (float)curImageLayerType.BoundingBox.South.Value2.DoubleValue(), (float)curImageLayerType.BoundingBox.North.Value2.DoubleValue(), (float)curImageLayerType.BoundingBox.West.Value2.DoubleValue(), (float)curImageLayerType.BoundingBox.East.Value2.DoubleValue(), (byte)curImageLayerType.Opacity.Value, (curImageLayerType.TerrainMapped.Value ? curWorld.TerrainAccessor : null)); newImageLayer.ImageUrl = imageUrl; newImageLayer.TransparentColor = transparentColor; newImageLayer.IsOn = curImageLayerType.ShowAtStartup.Value; if (curImageLayerType.HasLegendImagePath()) { newImageLayer.LegendImagePath = curImageLayerType.LegendImagePath.Value; } if (curImageLayerType.HasExtendedInformation() && curImageLayerType.ExtendedInformation.HasToolBarImage()) { newImageLayer.MetaData.Add("ToolBarImagePath", Path.Combine(PluginEngineGlobal.DirectoryPath, curImageLayerType.ExtendedInformation.ToolBarImage.Value)); } rol.Add(newImageLayer); } } if (curLayerSet.HasQuadTileSet()) { for (int i = 0; i < curLayerSet.QuadTileSetCount; i++) { LayerSet.Type_QuadTileSet2 curQtsType = curLayerSet.GetQuadTileSetAt(i); } } if (curLayerSet.HasPathList()) { for (int i = 0; i < curLayerSet.PathListCount; i++) { LayerSet.Type_PathList2 newPathList = curLayerSet.GetPathListAt(i); PathList pl = new PathList( newPathList.Name.Value, curWorld, newPathList.MinDisplayAltitude.DoubleValue(), newPathList.MaxDisplayAltitude.DoubleValue(), PluginEngineGlobal.DirectoryPath + "//" + newPathList.PathsDirectory.Value, newPathList.DistanceAboveSurface.DoubleValue(), (newPathList.HasWinColorName() ? System.Drawing.Color.FromName(newPathList.WinColorName.Value) : System.Drawing.Color.FromArgb(newPathList.RGBColor.Red.Value, newPathList.RGBColor.Green.Value, newPathList.RGBColor.Blue.Value)), curWorld.TerrainAccessor); pl.IsOn = newPathList.ShowAtStartup.Value; if (newPathList.HasExtendedInformation() && newPathList.ExtendedInformation.HasToolBarImage()) { pl.MetaData.Add("ToolBarImagePath", Path.Combine(PluginEngineGlobal.DirectoryPath, newPathList.ExtendedInformation.ToolBarImage.Value)); } rol.Add(pl); } } if (curLayerSet.HasShapeFileLayer()) { for (int i = 0; i < curLayerSet.ShapeFileLayerCount; i++) { LayerSet.Type_ShapeFileLayer2 newShapefileLayer = curLayerSet.GetShapeFileLayerAt(i); Microsoft.DirectX.Direct3D.FontDescription fd = Global.GetLayerFontDescription(newShapefileLayer.DisplayFont); Microsoft.DirectX.Direct3D.Font font = worldWindow.DrawArgs.CreateFont(fd); ShapeLayer sp = new ShapeLayer( newShapefileLayer.Name.Value, curWorld, newShapefileLayer.DistanceAboveSurface.DoubleValue(), newShapefileLayer.MasterFilePath.Value, newShapefileLayer.MinimumViewAltitude.DoubleValue(), newShapefileLayer.MaximumViewAltitude.DoubleValue(), font, (newShapefileLayer.HasWinColorName() ? System.Drawing.Color.FromName(newShapefileLayer.WinColorName.Value) : System.Drawing.Color.FromArgb(newShapefileLayer.RGBColor.Red.Value, newShapefileLayer.RGBColor.Green.Value, newShapefileLayer.RGBColor.Blue.Value)), (newShapefileLayer.HasScalarKey() ? newShapefileLayer.ScalarKey.Value : null), (newShapefileLayer.HasShowBoundaries() ? newShapefileLayer.ShowBoundaries.Value : false), (newShapefileLayer.HasShowFilledRegions() ? newShapefileLayer.ShowFilledRegions.Value : false)); sp.IsOn = newShapefileLayer.ShowAtStartup.BoolValue(); if (newShapefileLayer.HasExtendedInformation() && newShapefileLayer.ExtendedInformation.HasToolBarImage()) { sp.MetaData.Add("ToolBarImagePath", Path.Combine(PluginEngineGlobal.DirectoryPath, newShapefileLayer.ExtendedInformation.ToolBarImage.Value)); } rol.Add(sp); } } if (curLayerSet.HasIcon()) { Icons icons = (Icons)rol; for (int i = 0; i < curLayerSet.IconCount; i++) { LayerSet.Type_Icon newIcon = curLayerSet.GetIconAt(i); string textureFullPath = newIcon.TextureFilePath.Value; if (textureFullPath.Length > 0 && !Path.IsPathRooted(textureFullPath)) { // Use absolute path to icon image textureFullPath = Path.Combine(PluginEngineGlobal.DirectoryPath, newIcon.TextureFilePath.Value); } WorldWind.Renderable.Icon ic = new WorldWind.Renderable.Icon( newIcon.Name.Value, (float)newIcon.Latitude.Value2.DoubleValue(), (float)newIcon.Longitude.Value2.DoubleValue(), (float)newIcon.DistanceAboveSurface.DoubleValue()); ic.TextureFileName = textureFullPath; ic.Width = newIcon.IconWidthPixels.Value; ic.Height = newIcon.IconHeightPixels.Value; ic.IsOn = newIcon.ShowAtStartup.Value; if (newIcon.HasDescription()) { ic.Description = newIcon.Description.Value; } if (newIcon.HasClickableUrl()) { ic.ClickableActionURL = newIcon.ClickableUrl.Value; } if (newIcon.HasMaximumDisplayAltitude()) { ic.MaximumDisplayDistance = (float)newIcon.MaximumDisplayAltitude.Value; } if (newIcon.HasMinimumDisplayAltitude()) { ic.MinimumDisplayDistance = (float)newIcon.MinimumDisplayAltitude.Value; } icons.Add(ic); } } if (curLayerSet.HasTiledPlacenameSet()) { for (int i = 0; i < curLayerSet.TiledPlacenameSetCount; i++) { LayerSet.Type_TiledPlacenameSet2 newPlacenames = curLayerSet.GetTiledPlacenameSetAt(i); string filePath = newPlacenames.PlacenameListFilePath.Value; if (!Path.IsPathRooted(filePath)) { filePath = Path.Combine(PluginEngineGlobal.DirectoryPath, filePath); } Microsoft.DirectX.Direct3D.FontDescription fd = Global.GetLayerFontDescription(newPlacenames.DisplayFont); TiledPlacenameSet tps = new TiledPlacenameSet( newPlacenames.Name.Value, curWorld, newPlacenames.DistanceAboveSurface.DoubleValue(), newPlacenames.MaximumDisplayAltitude.DoubleValue(), newPlacenames.MinimumDisplayAltitude.DoubleValue(), filePath, fd, (newPlacenames.HasWinColorName() ? System.Drawing.Color.FromName(newPlacenames.WinColorName.Value) : System.Drawing.Color.FromArgb(newPlacenames.RGBColor.Red.Value, newPlacenames.RGBColor.Green.Value, newPlacenames.RGBColor.Blue.Value)), (newPlacenames.HasIconFilePath() ? newPlacenames.IconFilePath.Value : null)); if (newPlacenames.HasExtendedInformation() && newPlacenames.ExtendedInformation.HasToolBarImage()) { tps.MetaData.Add("ToolBarImagePath", Path.Combine(PluginEngineGlobal.DirectoryPath, newPlacenames.ExtendedInformation.ToolBarImage.Value)); } tps.IsOn = newPlacenames.ShowAtStartup.Value; rol.Add(tps); } } if (curLayerSet.HasChildLayerSet()) { for (int i = 0; i < curLayerSet.ChildLayerSetCount; i++) { LayerSet.Type_LayerSet ls = curLayerSet.GetChildLayerSetAt(i); rol.Add(getRenderableObjectListFromLayerSet(curWorld, ls, layerSetFile)); } } rol.IsOn = curLayerSet.ShowAtStartup.Value; return(rol); }
/// <summary> /// The initialize graphics. /// </summary> /// <returns>The initialize graphics.</returns> /// <remarks></remarks> public bool InitializeGraphics() { // try // { render.CreateDevice(this); pc = new PortalContainer(portals, ref render.device); BSPModel.BSPDisplayedInfo.CreateVertexBuffers(ref render.device, ref bsp); BSPModel.BSPDisplayedInfo.CreateIndexBuffers(ref render.device, ref bsp); BSPModel.BSPDisplayedInfo.LoadShaderTextures(ref render.device, ref bsp); System.Drawing.Font systemfont = new System.Drawing.Font("Arial", 12f, FontStyle.Regular); text = new Font(render.device, systemfont); cam = new Camera2(this); cam.speed = 0.05f; // cam.fixedrotation = true; return true; // } // catch (DirectXException) // { // Catch any errors and return a failure // return false; // } }
public virtual void Render(DrawArgs drawArgs) { if (!Visible) { return; } if (m_TextFont == null) { System.Drawing.Font localHeaderFont = new System.Drawing.Font("Arial", 12.0f, System.Drawing.FontStyle.Italic | System.Drawing.FontStyle.Bold); m_TextFont = new Microsoft.DirectX.Direct3D.Font(drawArgs.device, localHeaderFont); } if (m_WorldWindDingsFont == null) { AddFontResource(Path.Combine(System.Windows.Forms.Application.StartupPath, "World Wind Dings 1.04.ttf")); System.Drawing.Text.PrivateFontCollection fpc = new System.Drawing.Text.PrivateFontCollection(); fpc.AddFontFile(Path.Combine(System.Windows.Forms.Application.StartupPath, "World Wind Dings 1.04.ttf")); System.Drawing.Font worldwinddings = new System.Drawing.Font(fpc.Families[0], 12.0f); m_WorldWindDingsFont = new Microsoft.DirectX.Direct3D.Font(drawArgs.device, worldwinddings); } if (DrawArgs.LastMousePosition.X > AbsoluteLocation.X - resizeBuffer && DrawArgs.LastMousePosition.X < AbsoluteLocation.X + resizeBuffer && DrawArgs.LastMousePosition.Y > AbsoluteLocation.Y - resizeBuffer && DrawArgs.LastMousePosition.Y < AbsoluteLocation.Y + resizeBuffer) { DrawArgs.MouseCursor = CursorType.SizeNWSE; } else if (DrawArgs.LastMousePosition.X > AbsoluteLocation.X - resizeBuffer + ClientSize.Width && DrawArgs.LastMousePosition.X < AbsoluteLocation.X + resizeBuffer + ClientSize.Width && DrawArgs.LastMousePosition.Y > AbsoluteLocation.Y - resizeBuffer && DrawArgs.LastMousePosition.Y < AbsoluteLocation.Y + resizeBuffer) { DrawArgs.MouseCursor = CursorType.SizeNESW; } else if (DrawArgs.LastMousePosition.X > AbsoluteLocation.X - resizeBuffer && DrawArgs.LastMousePosition.X < AbsoluteLocation.X + resizeBuffer && DrawArgs.LastMousePosition.Y > AbsoluteLocation.Y - resizeBuffer + ClientSize.Height && DrawArgs.LastMousePosition.Y < AbsoluteLocation.Y + resizeBuffer + ClientSize.Height) { DrawArgs.MouseCursor = CursorType.SizeNESW; } else if (DrawArgs.LastMousePosition.X > AbsoluteLocation.X - resizeBuffer + ClientSize.Width && DrawArgs.LastMousePosition.X < AbsoluteLocation.X + resizeBuffer + ClientSize.Width && DrawArgs.LastMousePosition.Y > AbsoluteLocation.Y - resizeBuffer + ClientSize.Height && DrawArgs.LastMousePosition.Y < AbsoluteLocation.Y + resizeBuffer + ClientSize.Height) { DrawArgs.MouseCursor = CursorType.SizeNWSE; } else if ( (DrawArgs.LastMousePosition.X > AbsoluteLocation.X - resizeBuffer && DrawArgs.LastMousePosition.X < AbsoluteLocation.X + resizeBuffer && DrawArgs.LastMousePosition.Y > AbsoluteLocation.Y - resizeBuffer && DrawArgs.LastMousePosition.Y < AbsoluteLocation.Y + resizeBuffer + ClientSize.Height) || (DrawArgs.LastMousePosition.X > AbsoluteLocation.X - resizeBuffer + ClientSize.Width && DrawArgs.LastMousePosition.X < AbsoluteLocation.X + resizeBuffer + ClientSize.Width && DrawArgs.LastMousePosition.Y > AbsoluteLocation.Y - resizeBuffer && DrawArgs.LastMousePosition.Y < AbsoluteLocation.Y + resizeBuffer + ClientSize.Height)) { DrawArgs.MouseCursor = CursorType.SizeWE; } else if ( (DrawArgs.LastMousePosition.X > AbsoluteLocation.X - resizeBuffer && DrawArgs.LastMousePosition.X < AbsoluteLocation.X + resizeBuffer + ClientSize.Width && DrawArgs.LastMousePosition.Y > AbsoluteLocation.Y - resizeBuffer && DrawArgs.LastMousePosition.Y < AbsoluteLocation.Y + resizeBuffer) || (DrawArgs.LastMousePosition.X > AbsoluteLocation.X - resizeBuffer && DrawArgs.LastMousePosition.X < AbsoluteLocation.X + resizeBuffer + ClientSize.Width && DrawArgs.LastMousePosition.Y > AbsoluteLocation.Y - resizeBuffer + ClientSize.Height && DrawArgs.LastMousePosition.Y < AbsoluteLocation.Y + resizeBuffer + ClientSize.Height)) { DrawArgs.MouseCursor = CursorType.SizeNS; } if (ClientSize.Height > drawArgs.parentControl.Height) { ClientSize = new System.Drawing.Size(ClientSize.Width, drawArgs.parentControl.Height); } if (ClientSize.Width > drawArgs.parentControl.Width) { ClientSize = new System.Drawing.Size(drawArgs.parentControl.Width, ClientSize.Height); } if (!m_HideHeader && (!m_AutoHideHeader || (DrawArgs.LastMousePosition.X >= ClientLocation.X && DrawArgs.LastMousePosition.X <= ClientLocation.X + m_Size.Width && DrawArgs.LastMousePosition.Y >= ClientLocation.Y && DrawArgs.LastMousePosition.Y <= ClientLocation.Y + m_Size.Height))) { Widgets.Utilities.DrawBox( ClientLocation.X, ClientLocation.Y, m_Size.Width, m_HeaderHeight, 0.0f, m_HeaderColor.ToArgb(), drawArgs.device); m_TextFont.DrawText( null, m_Text, new System.Drawing.Rectangle(ClientLocation.X + 2, ClientLocation.Y, m_Size.Width, m_HeaderHeight), DrawTextFormat.None, m_TextColor.ToArgb()); m_WorldWindDingsFont.DrawText( null, "E", new System.Drawing.Rectangle(ClientLocation.X + m_Size.Width - 15, ClientLocation.Y + 2, m_Size.Width, m_Size.Height), DrawTextFormat.NoClip, System.Drawing.Color.White.ToArgb()); m_OutlineVertsHeader[0].X = AbsoluteLocation.X; m_OutlineVertsHeader[0].Y = AbsoluteLocation.Y; m_OutlineVertsHeader[1].X = AbsoluteLocation.X + ClientSize.Width; m_OutlineVertsHeader[1].Y = AbsoluteLocation.Y; m_OutlineVertsHeader[2].X = AbsoluteLocation.X + ClientSize.Width; m_OutlineVertsHeader[2].Y = AbsoluteLocation.Y + m_HeaderHeight; m_OutlineVertsHeader[3].X = AbsoluteLocation.X; m_OutlineVertsHeader[3].Y = AbsoluteLocation.Y + m_HeaderHeight; m_OutlineVertsHeader[4].X = AbsoluteLocation.X; m_OutlineVertsHeader[4].Y = AbsoluteLocation.Y; if (!m_HideBorder) { Widgets.Utilities.DrawLine(m_OutlineVertsHeader, m_BorderColor.ToArgb(), drawArgs.device); } } Widgets.Utilities.DrawBox( ClientLocation.X, ClientLocation.Y + m_HeaderHeight, m_Size.Width, m_Size.Height - m_HeaderHeight, 0.0f, m_BackgroundColor.ToArgb(), drawArgs.device); for (int index = m_ChildWidgets.Count - 1; index >= 0; index--) { IWidget currentChildWidget = m_ChildWidgets[index] as IWidget; if (currentChildWidget != null) { if (currentChildWidget.ParentWidget == null || currentChildWidget.ParentWidget != this) { currentChildWidget.ParentWidget = this; } currentChildWidget.Render(drawArgs); } } m_OutlineVerts[0].X = AbsoluteLocation.X; m_OutlineVerts[0].Y = AbsoluteLocation.Y + m_HeaderHeight; m_OutlineVerts[1].X = AbsoluteLocation.X + ClientSize.Width; m_OutlineVerts[1].Y = AbsoluteLocation.Y + m_HeaderHeight; m_OutlineVerts[2].X = AbsoluteLocation.X + ClientSize.Width; m_OutlineVerts[2].Y = AbsoluteLocation.Y + ClientSize.Height; m_OutlineVerts[3].X = AbsoluteLocation.X; m_OutlineVerts[3].Y = AbsoluteLocation.Y + ClientSize.Height; m_OutlineVerts[4].X = AbsoluteLocation.X; m_OutlineVerts[4].Y = AbsoluteLocation.Y + m_HeaderHeight; if (!m_HideBorder) { Widgets.Utilities.DrawLine(m_OutlineVerts, m_BorderColor.ToArgb(), drawArgs.device); } }