private void BotViewer_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (_bot == null)
                {
                    MessageBox.Show("Create a bot first", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                if (_viewer != null)
                {
                    _viewer.Close();
                    _viewer = null;
                }

                _viewer = new ShipViewerWindow(_bot)
                {
                    Owner = this,		// the other settings like topmost, showintaskbar, etc are already set in the window's xaml

                    PopupBorder = new SolidColorBrush(UtilityWPF.ColorFromHex("60000000")),
                    PopupBackground = new SolidColorBrush(UtilityWPF.ColorFromHex("30000000")),
                    ViewportBorder = new SolidColorBrush(UtilityWPF.ColorFromHex("E0000000")),
                    ViewportBackground = new SolidColorBrush(UtilityWPF.ColorFromHex("E0E0E0E0")),
                    PanelBorder = new SolidColorBrush(UtilityWPF.ColorFromHex("8068736B")),
                    PanelBackground = new SolidColorBrush(UtilityWPF.ColorFromHex("80424F45")),
                    Foreground = new SolidColorBrush(UtilityWPF.ColorFromHex("F0F0F0")),
                };

                _viewer.Show();      // it needs to be shown first to get the size
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private ShipViewerWindow ShowShipViewer(Swimbot bot, Point clickPoint)
        {
            // Make the camera follow this bean
            //TODO: Place a 2D graphic behind the selected ship
            //TODO: Zoom in on it
            #region Create Viewer

            ShipViewerWindow retVal = new ShipViewerWindow(bot);
            retVal.Owner = this;		// the other settings like topmost, showintaskbar, etc are already set in the window's xaml
            retVal.PopupBorder = new SolidColorBrush(UtilityWPF.ColorFromHex("60000000"));
            retVal.PopupBackground = new SolidColorBrush(UtilityWPF.ColorFromHex("30000000"));
            retVal.ViewportBorder = new SolidColorBrush(UtilityWPF.ColorFromHex("E0000000"));

            LinearGradientBrush brush = new LinearGradientBrush();
            brush.StartPoint = new Point(0, 0);
            brush.EndPoint = new Point(1, 1);

            GradientStopCollection gradients = new GradientStopCollection();
            gradients.Add(new GradientStop(UtilityWPF.ColorFromHex("E0EBEDE4"), 0d));
            gradients.Add(new GradientStop(UtilityWPF.ColorFromHex("E0DFE0DA"), .1d));
            gradients.Add(new GradientStop(UtilityWPF.ColorFromHex("E0E0E0E0"), .6d));
            gradients.Add(new GradientStop(UtilityWPF.ColorFromHex("E0DADBD5"), .9d));
            gradients.Add(new GradientStop(UtilityWPF.ColorFromHex("E0D7DBCC"), 1d));
            brush.GradientStops = gradients;

            retVal.ViewportBackground = brush;

            retVal.PanelBorder = new SolidColorBrush(UtilityWPF.ColorFromHex("8068736B"));
            retVal.PanelBackground = new SolidColorBrush(UtilityWPF.ColorFromHex("80424F45"));
            retVal.Foreground = new SolidColorBrush(UtilityWPF.ColorFromHex("F0F0F0"));

            #endregion

            // Place Viewer
            Point screenClickPoint = UtilityWPF.TransformToScreen(clickPoint, grdViewPort);
            ShipViewerWindow.PlaceViewerInCorner(retVal, screenClickPoint);

            // This places the viewer to the right of where they clicked - which is fine if they can't drag the item
            // around, but it's in the way if they try to move the object
            //Point popupPoint = new Point(windowClickPoint.X + 50, windowClickPoint.Y - (viewer.Height / 3d));
            //popupPoint = UtilityWPF.EnsureWindowIsOnScreen(popupPoint, new Size(viewer.Width, viewer.Height));		// don't let the popup straddle monitors
            //viewer.Left = popupPoint.X;
            //viewer.Top = popupPoint.Y;

            retVal.Show();      // it needs to be shown first to get the size

            return retVal;
        }
        private void grdViewPort_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (e.ChangedButton != MouseButton.Left)
                {
                    // All the special logic in this method is for the left button
                    return;
                }

                #region Tab Buttons

                if (_pressedButton != null)
                {
                    // Hide the currently showing options panel
                    pnlSettings.Children.Clear();
                    _pressedButton = null;
                    ColorPanelButtons();
                }

                #endregion
                #region Select Bean

                var clickedBean = GetMouseOverBean(e);

                if (_selectedBean != null && clickedBean != null && _selectedBean.Bean.Equals(clickedBean.Item1))
                {
                    // This is already selected, don't do anything
                }
                else
                {
                    // Close any existing viewer
                    if (_selectedBean != null && _selectedBean.Viewer != null)
                    {
                        _selectedBean.Viewer.Close();
                    }
                    _selectedBean = null;

                    // Make the camera follow this bean
                    //TODO: Place a 2D graphic behind the selected ship
                    //TODO: Zoom in on the bean
                    if (clickedBean != null)
                    {
                        #region Show Viewer

                        ShipViewerWindow viewer = new ShipViewerWindow(clickedBean.Item1);
                        viewer.Owner = this;		// the other settings like topmost, showintaskbar, etc are already set in the window's xaml
                        viewer.PopupBorder = new SolidColorBrush(UtilityWPF.ColorFromHex("60000000"));
                        viewer.PopupBackground = new SolidColorBrush(UtilityWPF.ColorFromHex("30000000"));
                        viewer.ViewportBorder = new SolidColorBrush(UtilityWPF.ColorFromHex("E0000000"));

                        LinearGradientBrush brush = new LinearGradientBrush();
                        brush.StartPoint = new Point(0, 0);
                        brush.EndPoint = new Point(1, 1);

                        GradientStopCollection gradients = new GradientStopCollection();
                        gradients.Add(new GradientStop(UtilityWPF.ColorFromHex("E0EBEDE4"), 0d));
                        gradients.Add(new GradientStop(UtilityWPF.ColorFromHex("E0DFE0DA"), .1d));
                        gradients.Add(new GradientStop(UtilityWPF.ColorFromHex("E0E0E0E0"), .6d));
                        gradients.Add(new GradientStop(UtilityWPF.ColorFromHex("E0DADBD5"), .9d));
                        gradients.Add(new GradientStop(UtilityWPF.ColorFromHex("E0D7DBCC"), 1d));
                        brush.GradientStops = gradients;

                        viewer.ViewportBackground = brush;

                        viewer.PanelBorder = new SolidColorBrush(UtilityWPF.ColorFromHex("8068736B"));
                        viewer.PanelBackground = new SolidColorBrush(UtilityWPF.ColorFromHex("80424F45"));
                        viewer.Foreground = new SolidColorBrush(UtilityWPF.ColorFromHex("F0F0F0"));

                        Point windowClickPoint = UtilityWPF.TransformToScreen(clickedBean.Item3, grdViewPort);
                        Point popupPoint = new Point(windowClickPoint.X + 50, windowClickPoint.Y - (viewer.Height / 3d));
                        popupPoint = UtilityWPF.EnsureWindowIsOnScreen(popupPoint, new Size(viewer.Width, viewer.Height));		// don't let the popup straddle monitors
                        viewer.Left = popupPoint.X;
                        viewer.Top = popupPoint.Y;

                        viewer.Show();

                        #endregion

                        _selectedBean = new SelectedBean(clickedBean.Item1, viewer, _camera.Position - clickedBean.Item1.PositionWorld);
                    }
                }

                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }