private void PaintInternal()
        {
            try
            {
                mNeedsRepaint = false;

                if (mHud == null || mHud.Lost)
                {
                    if (mHud != null)
                    {
                        mHud.Dispose();
                    }
                    mHud = Manager.Host.Render.CreateHud(
                        new Rectangle(Location.X, Location.Y, CanvasWidth, CanvasHeight));
                    mHud.Alpha   = Alpha;
                    mHud.Enabled = Visible;
                }

                if (!IsHudVisible())
                {
                    mHud.Enabled = false;
                    return;
                }

                double arrowAngleRadians = PlayerCoords.AngleTo(DestinationCoords) - PlayerHeadingRadians;
                while (arrowAngleRadians < 0)
                {
                    arrowAngleRadians += 2 * Math.PI;
                }

                int imageFrame;
                if (mNeedToCalculateImageRotations)
                {
                    imageFrame = 1;
                    Graphics g = Graphics.FromImage(mArrowImages[1]);
                    g.Clear(Clear);
                    g.TranslateTransform(mArrowImages[0].Width / 2, mArrowImages[0].Height / 2);
                    g.RotateTransform((float)(arrowAngleRadians * 180.0 / Math.PI));
                    g.TranslateTransform(-mArrowImages[0].Width / 2, -mArrowImages[0].Height / 2);
                    g.DrawImage(mArrowImages[0], 0, 0, mArrowImages[0].Width, mArrowImages[0].Height);
                }
                else
                {
                    imageFrame = ((int)(arrowAngleRadians / (2 * Math.PI) * mArrowImages.Length))
                                 % mArrowImages.Length;
                }

                mArrowRect.Y = 1;
                mArrowRect.X = (CanvasWidth - mArrowRect.Width) / 2;
                Rectangle distRect = new Rectangle(1, mArrowRect.Height, CanvasWidth - 2, TextSize + 2);
                if (ShowDestinationOver)
                {
                    mArrowRect.Y += 2 * TextSize;
                    distRect.Y   += 2 * TextSize;
                }

                //mImageFrame = newImageFrame;
                mHud.Clear();
                // Draw move border
                if (mMouseHovering)
                {
                    Rectangle r = new Rectangle(mArrowRect.Location, mArrowRect.Size);
                    mHud.Fill(r, Color.Gold);
                    r = new Rectangle(r.X + 1, r.Y + 1, r.Width - 2, r.Height - 2);
                    mHud.Clear(r);
                }
                mHud.BeginRender();
                // Draw close button
                if (mMouseHovering && ShowCloseButton)
                {
                    Bitmap closeBox = Icons.Window.CloseBox;
                    mCloseBoxRect = new Rectangle(mArrowRect.Right - closeBox.Width - 2,
                                                  mArrowRect.Top + 2, closeBox.Width, closeBox.Height);
                    mHud.DrawImage(Icons.Window.CloseBox, mCloseBoxRect);
                }
                else
                {
                    mCloseBoxRect = Rectangle.Empty;
                }
                mRoutePrevRect = mRouteNextRect = new Rectangle(-1, -1, 0, 0);

                if (ShowDestinationOver || ShowDistanceUnder)
                {
                    mHud.BeginText(HudFont, TextSize, TextBold ? FontWeight.Bold : FontWeight.Normal, false);
                    if (ShowDestinationOver)
                    {
                        if (HasDestinationLocation)
                        {
                            string locationName = DestinationLocation.Name;
                            if (HasRoute)
                            {
                                // Left and Right arrows on each end
                                if (RouteIndex > 0)
                                {
                                    locationName = "\u25C4  " + locationName;
                                }
                                if (RouteIndex < Route.Count - 1)
                                {
                                    locationName += "  \u25BA";
                                }
                                SizeF sz = mFontMeasure.MeasureString(locationName, mFont);
                                mRoutePrevRect = mRouteNextRect = new Rectangle(-1, -1, 0, 0);
                                float width = 0.2f * sz.Width;
                                if (RouteIndex > 0)
                                {
                                    mRoutePrevRect = Rectangle.Round(new RectangleF(
                                                                         Location.X + (CanvasWidth - 0.9f * sz.Width) / 2.0f,
                                                                         Location.Y - 1, width, TextSize + 2));
                                }
                                if (RouteIndex < Route.Count - 1)
                                {
                                    mRouteNextRect = Rectangle.Round(new RectangleF(
                                                                         Location.X + (CanvasWidth + 0.9f * sz.Width) / 2.0f - width,
                                                                         Location.Y - 1, width, TextSize + 2));
                                }
                            }

                            WriteText(locationName, WriteTextFormats.Center,
                                      new Rectangle(1, 1, CanvasWidth - 2, TextSize + 2));
                        }
                        else if (HasDestinationObject)
                        {
                            WriteText(DestinationObject.Name + (DestinationObject.IsValid ? "" : " (out of range)"), WriteTextFormats.Center,
                                      new Rectangle(1, 1, CanvasWidth - 2, TextSize + 2));
                        }
                        WriteText(DestinationCoords.ToString(), WriteTextFormats.Center,
                                  new Rectangle(1, TextSize, CanvasWidth - 2, TextSize + 2));
                    }
                    if (ShowDistanceUnder)
                    {
                        double dist = PlayerCoords.DistanceTo(DestinationCoords);
                        WriteText(dist.ToString("0.00"), WriteTextFormats.Center, distRect);
                    }
                    mHud.EndText();
                }
                mHud.DrawImage(mArrowImages[imageFrame], mArrowRect);
                mHud.EndRender();
                mHud.Enabled = true;

                mLastDisplayedDestinationCoords = DestinationCoords;
            }
            catch (Exception ex) { Util.HandleException(ex); }
        }
Exemple #2
0
        private void PaintInternal()
        {
            mNeedsRepaint = false;

            mHud.Clear();

            // Draw the background
            mHud.Fill(Colors.Background);

            Point pt;

            if (PositionLocked)
            {
                pt = new Point(EdgeWidth, EdgeWidth);
            }
            else if (Orientation == ToolbarOrientation.Horizontal)
            {
                pt = new Point(EdgeWidth + GrabberWidth, EdgeWidth);
                // Draw the grabber
                Rectangle r = new Rectangle(EdgeWidth + 1, EdgeWidth, 1, mSize.Height - 2 * EdgeWidth);
                mHud.Fill(r, Colors.GrabberA);
                r.X++;
                mHud.Fill(r, Colors.GrabberB);
                r = new Rectangle(r.X + 2, r.Y + 2, 1, r.Height - 4);
                mHud.Fill(r, Colors.GrabberA);
                r.X++;
                mHud.Fill(r, Colors.GrabberB);
            }
            else if (Orientation == ToolbarOrientation.Vertical)
            {
                pt = new Point(EdgeWidth, EdgeWidth + GrabberWidth);
                // Draw the grabber
                Rectangle r = new Rectangle(EdgeWidth, EdgeWidth + 1, mSize.Width - 2 * EdgeWidth, 1);
                mHud.Fill(r, Colors.GrabberA);
                r.Y++;
                mHud.Fill(r, Colors.GrabberB);
                r = new Rectangle(r.X + 2, r.Y + 2, r.Width - 4, 1);
                mHud.Fill(r, Colors.GrabberA);
                r.Y++;
                mHud.Fill(r, Colors.GrabberB);
            }

            // Paint the buttons
            foreach (ToolbarButton button in mButtons)
            {
                if (button.Visible)
                {
                    button.PaintBackground(mHud);
                }
            }
            mHud.BeginRender();
            mHud.BeginText(ToolbarButton.FontName, ToolbarButton.FontSize);
            foreach (ToolbarButton button in mButtons)
            {
                if (button.Visible)
                {
                    button.PaintForeground(mHud);
                }
            }
            mHud.EndText();
            mHud.EndRender();
        }