Beispiel #1
0
        public override void Initialize(DrawArgs drawArgs)
        {
            this.isInitialized = true;

            this.m_drawingFont = drawArgs.CreateFont(this.m_fontDescription);
            if (!File.Exists(this.m_placenameListFilePath))
            {
                this.isInitialized = true;
                Log.Write(Log.Levels.Error, "PLACE", this.m_placenameListFilePath + " not found.");
                return;
            }

            if (this.m_iconFilePath != null)
            {
                this.m_iconTexture = ImageHelper.LoadIconTexture(this.m_iconFilePath);

                using (Surface s = this.m_iconTexture.GetSurfaceLevel(0))
                {
                    SurfaceDescription desc = s.Description;
                    this.m_spriteSize = new System.Drawing.Rectangle(0, 0, desc.Width, desc.Height);
                }

                this.m_sprite = new Sprite(drawArgs.device);
            }

            using (BufferedStream placenameFileListStream = new BufferedStream(File.Open(this.m_placenameListFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
                using (BinaryReader placenameFileListReader = new BinaryReader(placenameFileListStream, System.Text.Encoding.ASCII))
                {
                    int count = placenameFileListReader.ReadInt32();
                    for (int i = 0; i < count; i++)
                    {
                        WorldWindPlacenameFile wwpf = new WorldWindPlacenameFile();
                        wwpf.dataFilename = placenameFileListReader.ReadString();
                        wwpf.west         = placenameFileListReader.ReadSingle();
                        wwpf.south        = placenameFileListReader.ReadSingle();
                        wwpf.east         = placenameFileListReader.ReadSingle();
                        wwpf.north        = placenameFileListReader.ReadSingle();
                        this.m_placenameFileList.Add(wwpf);
                    }
                }
        }
Beispiel #2
0
        public override void Initialize(DrawArgs drawArgs)
        {
            this.isInitialized = true;

            FontDescription scaledDescription = this.m_fontDescription;

            scaledDescription.Height = (int)(this.m_fontDescription.Height * this.m_fontScaling);

            this.m_drawingFont = drawArgs.CreateFont(scaledDescription);

            //Validate URL

            /*
             * if(System.Text.RegularExpressions.Regex.IsMatch(m_placenameBaseUrl, "(http|ftp|https)://([/w-]+/.)+(/[/w- ./?%&=]*)?"))
             * {
             *  this.isInitialized = true;
             * }
             */
            //Generate Initial File List
            //WorldWindWFSPlacenameFile root_file = new WorldWindWFSPlacenameFile(m_placenameBaseUrl, m_typename, m_labelfield);
            //m_placenameFileList = new ArrayList(root_file.SplitPlacenameFiles());

            //TODO:Download and validate capabitilities

            if (this.m_iconFilePath != null)
            {
                this.m_iconTexture = ImageHelper.LoadIconTexture(this.m_iconFilePath);

                using (Surface s = this.m_iconTexture.GetSurfaceLevel(0))
                {
                    SurfaceDescription desc = s.Description;
                    this.m_spriteSize = new System.Drawing.Rectangle(0, 0, desc.Width, desc.Height);
                }

                this.m_sprite = new Sprite(drawArgs.device);
            }
        }
Beispiel #3
0
		public void ComputeAutoSize (DrawArgs drawArgs)
		{
			Microsoft.DirectX.Direct3D.Font font = drawArgs.defaultDrawingFont;
			if(font==null)
				font = drawArgs.CreateFont( "", 10 );
			Rectangle bounds = font.MeasureString(null, m_Text, m_Format, 0);
			if(m_useParentWidth)
			{
				m_size.Width = this.WidgetSize.Width - m_location.X;
				m_size.Height = bounds.Height * ( (int)(bounds.Width/m_size.Width) + 1);
			}
			else
			{
				m_size.Width = bounds.Width + m_borderWidth;
				m_size.Height = bounds.Height + m_borderWidth;
			}

			if(m_useParentHeight)
				m_size.Height = this.WidgetSize.Height - m_location.Y;

			// This code is iffy - no idea why Y is offset by more than specified.
			if (m_location.X == 0)
			{
				m_location.X = m_borderWidth;
				m_size.Width += m_borderWidth;
			}
			if (m_location.Y == 0)
			{
				m_location.Y = m_borderWidth;
				m_size.Height += m_borderWidth;
			}
		}
		public override void Initialize(DrawArgs drawArgs)
		{
			this.isInitialized = true;

			m_drawingFont = drawArgs.CreateFont(m_fontDescription);

            //Validate URL
            /*
            if(System.Text.RegularExpressions.Regex.IsMatch(m_placenameBaseUrl, "(http|ftp|https)://([/w-]+/.)+(/[/w- ./?%&=]*)?"))
            {
                this.isInitialized = true;
            }
            */
            //Generate Initial File List
            //WorldWindWFSPlacenameFile root_file = new WorldWindWFSPlacenameFile(m_placenameBaseUrl, m_typename, m_labelfield);
            //m_placenameFileList = new ArrayList(root_file.SplitPlacenameFiles());

            //TODO:Download and validate capabitilities

			if(m_iconFilePath!=null)
			{
				m_iconTexture = ImageHelper.LoadIconTexture( m_iconFilePath );
			
				using(Surface s = m_iconTexture.GetSurfaceLevel(0))
				{
					SurfaceDescription desc = s.Description;
					m_spriteSize = new System.Drawing.Rectangle(0,0, desc.Width, desc.Height);
				}

				m_sprite = new Sprite(drawArgs.device);
			}
		}
Beispiel #5
0
        public override void Render(DrawArgs drawArgs)
        {
            try
            {
                lock (this)
                {
                    //override colors for visibility
                    switch (World.Settings.WFSNameColors)
                    {
                    case WFSNameColors.Black:
                        this.m_renderColor = System.Drawing.Color.Black.ToArgb();
                        break;

                    case WFSNameColors.White:
                        this.m_renderColor = System.Drawing.Color.White.ToArgb();
                        break;

                    case WFSNameColors.Gray:
                        this.m_renderColor = System.Drawing.Color.DarkGray.ToArgb();
                        break;

                    case WFSNameColors.Default:
                        this.m_renderColor = this.m_defaultColor;
                        break;
                    }

                    if (World.Settings.WFSNameSizeMultiplier != this.m_fontScaling)
                    {
                        this.m_fontScaling = World.Settings.WFSNameSizeMultiplier;
                        // scale font size based on settings
                        FontDescription scaledDescription = this.m_fontDescription;
                        scaledDescription.Height = (int)(this.m_fontDescription.Height * this.m_fontScaling);
                        this.m_drawingFont       = drawArgs.CreateFont(scaledDescription);
                    }

                    Vector3 cameraPosition = drawArgs.WorldCamera.Position;
                    if (this.m_placeNames == null)
                    {
                        return;
                    }

                    // Black outline for light text, white outline for dark text
                    int outlineColor = unchecked ((int)0x80ffffff);
                    int brightness   = (this.m_renderColor & 0xff) +
                                       ((this.m_renderColor >> 8) & 0xff) +
                                       ((this.m_renderColor >> 16) & 0xff);
                    if (brightness > 255 * 3 / 2)
                    {
                        outlineColor = unchecked ((int)0x80000000);
                    }

                    if (this.m_sprite != null)
                    {
                        this.m_sprite.Begin(SpriteFlags.AlphaBlend);
                    }
                    int     count           = 0;
                    Vector3 referenceCenter = new Vector3(
                        (float)drawArgs.WorldCamera.ReferenceCenter.X,
                        (float)drawArgs.WorldCamera.ReferenceCenter.Y,
                        (float)drawArgs.WorldCamera.ReferenceCenter.Z);

                    for (int index = 0; index < this.m_placeNames.Length; index++)
                    {
                        Vector3 v = this.m_placeNames[index].cartesianPoint;
                        float   distanceSquared = Vector3.LengthSq(v - cameraPosition);
                        if (distanceSquared > this.m_maximumDistanceSq)
                        {
                            continue;
                        }

                        if (distanceSquared < this.m_minimumDistanceSq)
                        {
                            continue;
                        }

                        if (!drawArgs.WorldCamera.ViewFrustum.ContainsPoint(v))
                        {
                            continue;
                        }

                        Vector3 pv = drawArgs.WorldCamera.Project(v - referenceCenter);

                        // Render text only
                        string label = this.m_placeNames[index].Name;


                        /*
                         * if(m_sprite != null && 1==0)
                         * {
                         *      m_sprite.Draw(m_iconTexture,
                         *              m_spriteSize,
                         *              new Vector3(m_spriteSize.Width/2,m_spriteSize.Height/2,0),
                         *              new Vector3(pv.X, pv.Y, 0),
                         *              System.Drawing.Color.White);
                         *      pv.X += m_spriteSize.Width/2 + 4;
                         * }
                         */

                        System.Drawing.Rectangle rect = this.m_drawingFont.MeasureString(null, label, this.m_textFormat, this.m_renderColor);

                        pv.Y -= rect.Height / 2;
                        if (this.m_sprite == null)
                        {
                            // Center horizontally
                            pv.X -= rect.Width / 2;
                        }

                        rect.Inflate(3, 1);
                        int x = (int)Math.Round(pv.X);
                        int y = (int)Math.Round(pv.Y);

                        rect.Offset(x, y);

                        if (World.Settings.WFSOutlineText)
                        {
                            this.m_drawingFont.DrawText(null, label, x - 1, y - 1, outlineColor);
                            this.m_drawingFont.DrawText(null, label, x - 1, y + 1, outlineColor);
                            this.m_drawingFont.DrawText(null, label, x + 1, y - 1, outlineColor);
                            this.m_drawingFont.DrawText(null, label, x + 1, y + 1, outlineColor);
                        }

                        this.m_drawingFont.DrawText(null, label, x, y, this.m_renderColor);

                        count++;
                        if (count > 30)
                        {
                            break;
                        }
                    }

                    if (this.m_sprite != null)
                    {
                        this.m_sprite.End();
                    }
                }
            }
            catch (Exception caught)
            {
                Log.Write(caught);
            }
        }
Beispiel #6
0
        public override void RenderContents(DrawArgs drawArgs)
        {
            this.m_DrawArgs = drawArgs;
            try
            {
                if (this.itemFont == null)
                {
                    this.itemFont = drawArgs.CreateFont(World.Settings.LayerManagerFontName,
                                                        World.Settings.LayerManagerFontSize, World.Settings.LayerManagerFontStyle);

                    // TODO: Fix wingdings menu problems
                    Font localHeaderFont = new Font("Arial", 12.0f, FontStyle.Italic | FontStyle.Bold);
                    this.headerFont = new SharpDX.Direct3D9.Font(drawArgs.device, localHeaderFont);

                    Font wingdings = new Font("Wingdings", 12.0f);
                    this.wingdingsFont = new SharpDX.Direct3D9.Font(drawArgs.device, wingdings);

                    AddFontResource(Path.Combine(Application.StartupPath, "World Wind Dings 1.04.ttf"));
                    System.Drawing.Text.PrivateFontCollection fpc = new System.Drawing.Text.PrivateFontCollection();
                    fpc.AddFontFile(Path.Combine(Application.StartupPath, "World Wind Dings 1.04.ttf"));
                    Font worldwinddings = new Font(fpc.Families[0], 12.0f);
                    this.worldwinddingsFont = new SharpDX.Direct3D9.Font(drawArgs.device, worldwinddings);
                }

                this.updateList();

                this.worldwinddingsFont.DrawText(
                    null,
                    "E",
                    new Rectangle(this.Right - 16, this.Top + 2, 20, this.topBorder),
                    FontDrawFlags.None, this.TextColor);

                int numItems    = this.GetNumberOfUncollapsedItems();
                int totalHeight = this.GetItemsHeight(drawArgs);                //numItems * ItemHeight;
                this.showScrollbar = totalHeight > this.ClientHeight;
                if (this.showScrollbar)
                {
                    double percentHeight   = (double)this.ClientHeight / totalHeight;
                    int    scrollbarHeight = (int)(this.ClientHeight * percentHeight);

                    int maxScroll = totalHeight - this.ClientHeight;

                    if (this.scrollBarPosition < 0)
                    {
                        this.scrollBarPosition = 0;
                    }
                    else if (this.scrollBarPosition > maxScroll)
                    {
                        this.scrollBarPosition = maxScroll;
                    }

                    // Smooth scroll
                    const float scrollSpeed       = 0.3f;
                    float       smoothScrollDelta = (this.scrollBarPosition - this.scrollSmoothPosition) * scrollSpeed;
                    float       absDelta          = Math.Abs(smoothScrollDelta);
                    if (absDelta > 100f || absDelta < 3f)
                    {
                        // Scroll > 100 pixels and < 1.5 pixels faster
                        smoothScrollDelta = (this.scrollBarPosition - this.scrollSmoothPosition) * (float)Math.Sqrt(scrollSpeed);
                    }

                    this.scrollSmoothPosition += smoothScrollDelta;

                    if (this.scrollSmoothPosition > maxScroll)
                    {
                        this.scrollSmoothPosition = maxScroll;
                    }

                    int scrollPos = (int)((float)percentHeight * this.scrollBarPosition);

                    int color = this.isScrolling ? World.Settings.scrollbarHotColor : World.Settings.scrollbarColor;
                    MenuUtils.DrawBox(this.Right - this.ScrollBarSize + 2, this.ClientTop + scrollPos, this.ScrollBarSize - 3,
                                      scrollbarHeight + 1,
                                      0.0f,
                                      color,
                                      drawArgs.device);

                    this.scrollbarLine[0].X = this.Right - this.ScrollBarSize;
                    this.scrollbarLine[0].Y = this.ClientTop;
                    this.scrollbarLine[1].X = this.Right - this.ScrollBarSize;
                    this.scrollbarLine[1].Y = this.Bottom;
                    MenuUtils.DrawLine(this.scrollbarLine, this.DialogColor,
                                       drawArgs.device);
                }

                this.headerFont.DrawText(
                    null, "Layer Manager",
                    new Rectangle(this.Left + 5, this.Top + 1, this.Width, this.topBorder - 2),
                    FontDrawFlags.VerticalCenter, this.TextColor);

                SharpDX.Vector2[] headerLinePoints = new SharpDX.Vector2[2];
                headerLinePoints[0].X = this.Left;
                headerLinePoints[0].Y = this.Top + this.topBorder - 1;

                headerLinePoints[1].X = this.Right;
                headerLinePoints[1].Y = this.Top + this.topBorder - 1;

                MenuUtils.DrawLine(headerLinePoints, this.DialogColor, drawArgs.device);

                int runningItemHeight = 0;
                if (this.showScrollbar)
                {
                    runningItemHeight = -(int)Math.Round(this.scrollSmoothPosition);
                }

                // Set the Direct3D viewport to match the layer manager client area
                // to clip the text to the window when scrolling
                Viewport lmClientAreaViewPort = new Viewport();
                lmClientAreaViewPort.X      = this.ClientLeft;
                lmClientAreaViewPort.Y      = this.ClientTop;
                lmClientAreaViewPort.Width  = this.ClientWidth;
                lmClientAreaViewPort.Height = this.ClientHeight;
                Viewport defaultViewPort = drawArgs.device.Viewport;
                drawArgs.device.Viewport = lmClientAreaViewPort;
                for (int i = 0; i < this._itemList.Count; i++)
                {
                    if (runningItemHeight > this.ClientHeight)
                    {
                        // No more space for items
                        break;
                    }
                    LayerMenuItem lmi = (LayerMenuItem)this._itemList[i];
                    runningItemHeight += lmi.Render(
                        drawArgs, this.ClientLeft, this.ClientTop,
                        runningItemHeight, this.ClientWidth, this.ClientBottom, this.itemFont, this.wingdingsFont, this.worldwinddingsFont, this.MouseOverItem);
                }
                drawArgs.device.Viewport = defaultViewPort;
            }
            catch (Exception caught)
            {
                Log.Write(caught);
            }
        }
        public override void Render(DrawArgs drawArgs)
        {
            try
            {
                lock (this)
                {
                    m_renderColor = m_defaultColor;

                    if (WFSNameSizeMultiplier != m_fontScaling)
                    {
                        m_fontScaling = WFSNameSizeMultiplier;
                        // scale font size based on settings
                        FontDescription scaledDescription = m_fontDescription;
                        scaledDescription.Height = (int)(m_fontDescription.Height * m_fontScaling);
                        m_drawingFont = drawArgs.CreateFont(scaledDescription);
                    }

                    Point3d cameraPosition = drawArgs.WorldCamera.Position;
                    if (m_placeNames == null)
                        return;

                    if (m_sprite != null)
                        m_sprite.Begin(SpriteFlags.AlphaBlend);
                    int count = 0;
                    Point3d referenceCenter = new Point3d(
                        drawArgs.WorldCamera.ReferenceCenter.X,
                        drawArgs.WorldCamera.ReferenceCenter.Y,
                        drawArgs.WorldCamera.ReferenceCenter.Z);

                    for (int index = 0; index < m_placeNames.Length; index++)
                    {
                        Point3d v = m_placeNames[index].cartesianPoint;
                        double distanceSquared = (v - cameraPosition).LengthSq;
                        if (distanceSquared > m_maximumDistanceSq)
                            continue;

                        if (distanceSquared < m_minimumDistanceSq)
                            continue;

                        if (!drawArgs.WorldCamera.ViewFrustum.ContainsPoint(v))
                            continue;

                        Point3d pv = drawArgs.WorldCamera.Project(v - referenceCenter);

                        // Render text only
                        string label = m_placeNames[index].Name;

                        /*
                        if(m_sprite != null && 1==0)
                        {
                            m_sprite.Draw(m_iconTexture,
                                m_spriteSize,
                                new Vector3(m_spriteSize.Width/2,m_spriteSize.Height/2,0),
                                new Vector3(pv.X, pv.Y, 0),
                                System.Drawing.Color.White);
                            pv.X += m_spriteSize.Width/2 + 4;
                        }
                        */

                        System.Drawing.Rectangle rect = m_drawingFont.MeasureString(null, label, m_textFormat, m_renderColor);

                        pv.Y -= rect.Height / 2;
                        if (m_sprite == null)
                            // Center horizontally
                            pv.X -= rect.Width / 2;

                        rect.Inflate(3, 1);
                        int x = (int)Math.Round(pv.X);
                        int y = (int)Math.Round(pv.Y);

                        rect.Offset(x, y);

                        m_drawingFont.DrawText(null, label, x, y, m_renderColor);

                        count++;
                        if (count > 30)
                            break;
                    }

                    if (m_sprite != null)
                        m_sprite.End();

                }
            }
            catch (Exception caught)
            {
                Log.Write(caught);
            }
        }
        public override void Initialize(DrawArgs drawArgs)
        {
            this.isInitialized = true;

            FontDescription scaledDescription = m_fontDescription;
            scaledDescription.Height = (int)(m_fontDescription.Height * m_fontScaling);

            m_drawingFont = drawArgs.CreateFont(scaledDescription);

            if (m_iconFilePath != null)
            {
                m_iconTexture = ImageHelper.LoadIconTexture(m_iconFilePath);

                using (Surface s = m_iconTexture.GetSurfaceLevel(0))
                {
                }

                m_sprite = new Sprite(drawArgs.device);
            }
        }
		public override void Initialize(DrawArgs drawArgs)
		{
			this.isInitialized = true;

			m_drawingFont = drawArgs.CreateFont(m_fontDescription);
			if(!File.Exists(m_placenameListFilePath))
			{
				this.isInitialized = true;
				Log.Write(Log.Levels.Error, "PLACE", m_placenameListFilePath + " not found.");
				return;
			}

			if(m_iconFilePath!=null)
			{
				m_iconTexture = ImageHelper.LoadIconTexture( m_iconFilePath );
			
				using(Surface s = m_iconTexture.GetSurfaceLevel(0))
				{
					SurfaceDescription desc = s.Description;
					m_spriteSize = new System.Drawing.Rectangle(0,0, desc.Width, desc.Height);
				}

				m_sprite = new Sprite(drawArgs.device);
			}

			using( BufferedStream placenameFileListStream = new BufferedStream(File.Open(m_placenameListFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
			using( BinaryReader placenameFileListReader = new BinaryReader(placenameFileListStream, System.Text.Encoding.ASCII))
			{
				int count = placenameFileListReader.ReadInt32();
				for (int i = 0; i < count; i++)
				{
					WorldWindPlacenameFile wwpf = new WorldWindPlacenameFile();
					wwpf.dataFilename = placenameFileListReader.ReadString();
					wwpf.west = placenameFileListReader.ReadSingle();
					wwpf.south = placenameFileListReader.ReadSingle();
					wwpf.east = placenameFileListReader.ReadSingle();
					wwpf.north = placenameFileListReader.ReadSingle();
					m_placenameFileList.Add(wwpf);
				}
			}
		}