private List <string> GetFormattedDescription(string rawDescription)
        {
            string[]       lines            = rawDescription.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
            List <string>  descriptionLines = new List <string>();
            string         text             = "WWWWWWWWWWWWWWWWWWWWWWWW ";
            Font           font             = FontManager.GetFont("Main 10");
            DrawTextFormat dtf   = DrawTextFormat.ExpandTabs | DrawTextFormat.WordBreak | DrawTextFormat.Left | DrawTextFormat.Top;
            Rectangle      area  = font.MeasureString(UI.CurrentHud.SpriteManager, text, dtf, Color.White);
            int            width = area.Width;

            foreach (string line in lines)
            {
                string[] words    = line.Split(' ');
                string   linetext = "";
                for (int i = 0; i < words.Length; i++)
                {
                    string addword = words[i] + (i == words.Length - 1 ? "" : " ");
                    if ((linetext + addword).Length > 25)
                    {
                        Rectangle a = font.MeasureString(UI.CurrentHud.SpriteManager, linetext + addword, dtf, Color.White);
                        if (a.Width > width)
                        {   //Wrap
                            descriptionLines.Add(linetext);
                            linetext = "";
                        }
                    }
                    linetext += addword;
                }
                descriptionLines.Add(linetext);
            }

            return(descriptionLines);
        }
示例#2
0
        void Render()
        {
            m_d3DDevice.BeginScene();

            // Render target needs to be set to 640x360 for optimal scaling. However the pixel coordinates for
            // Direct3D 9 render target is actually (-0.5,-0.5) to (639.5,359.5).  As such the Viewport is set
            // to 639x359 to account for the pixel coordinate offset of render target
            tagRECT rect;

            rect.top    = m_d3DDevice.Viewport.Y;
            rect.left   = m_d3DDevice.Viewport.X;
            rect.bottom = m_d3DDevice.Viewport.Y + m_d3DDevice.Viewport.Height;
            rect.right  = m_d3DDevice.Viewport.X + m_d3DDevice.Viewport.Width;

            m_previewHelper.Render(rect);

            // Draw the timecode top-center with a slight drop-shadow
            Rectangle rc = m_d3DFont.MeasureString(null, m_timeCodeString, Direct3D.DrawTextFormat.Center, Color.Black);
            int       x  = (m_d3DDevice.Viewport.Width / 2) - (rc.Width / 2);
            int       y  = 10;

            m_d3DFont.DrawText(null, m_timeCodeString, x + 1, y + 1, Color.Black);
            m_d3DFont.DrawText(null, m_timeCodeString, x, y, Color.White);

            m_d3DDevice.EndScene();
            m_d3DDevice.Present();
        }
示例#3
0
        public override void OnInitializeScene(GameFramework g)
        {
            BindGameController();

            _background.X      = 0;
            _background.Y      = 0;
            _background.Width  = g.CANVAS.Size.Width;
            _background.Height = g.CANVAS.Size.Height;

            //string path = System.Environment.CurrentDirectory + @"\ImageLib.dll";
            string path = string.Format(@"\\{0}\DDDClient\ImageLib.dll", DDD_Global.Instance.HostName);

            ImageLib = Assembly.LoadFile(path);

            //font_small = g.CANVAS.CreateFont(new System.Drawing.Font("Arial", 12));
            font_small = g.CANVAS.CreateFont(new System.Drawing.Font("MS Sans Serif", 14));

            font_large = g.CANVAS.CreateFont(new System.Drawing.Font("Arial", 28));

            bounding_rect   = font_large.MeasureString(null, Message, DrawTextFormat.NoClip, Color.Yellow);
            bounding_rect.X = (_background.Width - bounding_rect.Width) / 2;
            bounding_rect.Y = (int)(_background.Height - (2 * bounding_rect.Height));

            player_rect.X      = (int)((_background.Width - (_background.Width / 4)) / 2);
            player_rect.Y      = (int)((_background.Height - (_background.Height / 3)) / 2);
            player_rect.Width  = (int)(_background.Width / 4);
            player_rect.Height = (int)(_background.Height / 3);

            _player_window = CreateWindow(g.CANVAS.CreateFont(new System.Drawing.Font("MS Sans Serif", 12)), "Available Players",
                                          player_rect.X,
                                          player_rect.Y,
                                          player_rect.Right,
                                          player_rect.Bottom);

            _player_window.AllowMove     = false;
            _player_window.AllowShade    = false;
            _player_window.AllowResize   = false;
            _player_window.HasScrollBars = false;


            _player_menu = new PanelMenu(
                g.CANVAS.CreateFont(new System.Drawing.Font("MS Sans Serif", 14)),
                new PanelMenuSelectHandler(PlayerSelection)
                );
            _player_menu.BackgroundColor = Color.Black;
            _player_window.BindPanelControl(_player_menu);
            _player_window.Show();
            _player_menu.LayoutMenuOptions(new string[] { "Populating ..." }, PanelLayout.Vertical);


            _continue_btn = (PanelStaticButton) new PanelStaticButton(_player_window.ClientArea.Left,
                                                                      _player_window.ClientArea.Bottom + 2,
                                                                      _player_window.ClientArea.Right,
                                                                      _player_window.ClientArea.Bottom + 27);
            _continue_btn.Text            = "Continue";
            _continue_btn.BackgroundColor = Color.FromArgb(204, 63, 63, 63);
            _continue_btn.BorderColor     = Color.White;
            _continue_btn.Font            = font_small;
            _continue_btn.MouseClick      = new System.Windows.Forms.MouseEventHandler(this.Btn_Continue);
        }
示例#4
0
        public int LayoutMenuOptions(string[] options, PanelLayout type)
        {
            _panel_area = _client_area;

            lock (this)
            {
                MenuOptions = options;

                if (MenuOptions != null)
                {
                    // Step1; if no MenuLocations or MenuLocations Length not the same as MenuOptions Length
                    //   then create/recreate MenuLocations with the right size.
                    if (MenuLocations == null)
                    {
                        MenuLocations = new Rectangle[MenuOptions.Length];
                    }
                    else
                    if (MenuLocations.Length != MenuOptions.Length)
                    {
                        MenuLocations = new Rectangle[MenuOptions.Length];
                    }

                    //Step2; Initialize all MenuLocations to the empty rectangle.
                    //Step3; Set the layout type and return the total height of the MenuOptions, (useful for resizing)
                    _layout           = type;
                    _menu_item_height = 0;
                    for (int i = 0; i < MenuOptions.Length; i++)
                    {
                        MenuLocations[i] = _font.MeasureString(null, MenuOptions[i], DrawTextFormat.None, Color.Yellow);

                        switch (type)
                        {
                        case PanelLayout.Vertical:
                            goto case PanelLayout.VerticalFree;

                        case PanelLayout.VerticalFree:
                            MenuLocations[i].Height = (int)(MenuLocations[i].Height * 1.5);
                            _menu_item_height      += MenuLocations[i].Height;
                            break;

                        case PanelLayout.Horizontal:
                            goto case PanelLayout.HorizontalFree;

                        case PanelLayout.HorizontalFree:
                            MenuLocations[i].Width  = (int)(MenuLocations[i].Width * 1.5);
                            MenuLocations[i].Height = _panel_area.Height;
                            _menu_item_height      += MenuLocations[i].Width;
                            break;

                        default:
                            throw new ArgumentException("LayoutMenuOptions: Unsupported Layout type.");
                        }
                    }

                    LayoutButtons(type);
                    return(_menu_item_height);
                }
            }
            return(0);
        }
        public static void MeasureText(Font fnt, string text, ref float textwidth, ref float textheight, int fontSize)
        {
            if (text[0] == ' ') // anti-trim
            {
                text = "_" + text.Substring(1);
            }
            if (text[text.Length - 1] == ' ')
            {
                text = text.Substring(0, text.Length - 1) + '_';
            }

            // Text drawing doesnt work with DX9Ex & sprite
            if (GUIGraphicsContext.IsDirectX9ExUsed())
            {
                MeasureText(text, ref textwidth, ref textheight, fontSize);
            }
            else
            {
                if (_sprite == null)
                {
                    _sprite = new Sprite(GUIGraphicsContext.DX9Device);
                }
                Rectangle rect = fnt.MeasureString(_sprite, text, DrawTextFormat.NoClip, Color.Black);
                textwidth  = rect.Width;
                textheight = rect.Height;
            }
        }
示例#6
0
        private static void RenderFrame()
        {
            //Update camera
            camera.Update();
            if (camera.update)
            {
                renderer.Device.Transform.View = camera.View;
                camera.update = false;
            }

            //Being the scene
            renderer.BeginScene(Color.CornflowerBlue);

            //Only if our bsp is set lets render it
            int objectsRendered = 0;

            if (mi != null)
            {
                renderer.Device.Transform.World = Matrix.Identity;
                mi.RenderModel();

                objectsRendered++;
            }

            //See if we sent a request to capture a screenshot
            //This helps not only that we wont take it when its still drawing(because of threading)
            //And it makes sure we dont have the fps and console messages drawn
            if (capScreenshot)
            {
                capScreenshot = false;
                DumpScreenShot();
            }

            //Update and Render the messages
            messageConsole.Update();
            messageConsole.Render();

            //Render debug info
            if (renderDebug)
            {
                string debugString = "Debug Info\n" +
                                     "----------\n" +
                                     "rendering " + objectsRendered.ToString() + " object(s)\n" +
                                     "camera pos:\n" +
                                     "x=" + camera.Position.X.ToString() + "\n" +
                                     "y=" + camera.Position.Y.ToString() + "\n" +
                                     "z=" + camera.Position.Z.ToString();
                Rectangle rec = debugFont.MeasureString(null, debugString, DrawTextFormat.None, Color.Gold);
                debugFont.DrawText(null, debugString, renderScene.Width - rec.Width - 10, 10, Color.Gold);
            }

            //Render our FPS
            fpsFont.DrawText(null, totalFPS.ToString() + " FPS", 10, 10, Color.Gold);

            //End the scene
            renderer.EndScene();
        }
示例#7
0
        void PrintMessageOnScene()
        {
            int height = d3dfont.MeasureString(null, "0", DrawTextFormat.Left, Color.White).Height + 2;
            int x = 10, y = 7;

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("< {0} >\n\n", abi.filename);
            sb.AppendFormat("文件版本(file version)      : {0}\n", abi.version);
            sb.AppendFormat("材质数量(number of textures): {0}\n", abi.num_texture);
            sb.AppendFormat("骨骼数量(number of bones)   : {0}\n", abi.num_bone);
            sb.AppendFormat("模型编号(model index)       : {0}/{1}\n", model + 1, abi.num_model);
            sb.AppendFormat("-顶点数量(number of vertices) {0}\n", abi.models[model].num_vertice);
            sb.AppendFormat("-多边形量(number of polygons) {0}\n", abi.models[model].num_polygon);
            sb.AppendFormat("动作编号(animation index)   : {0}/{1}\n", animation + 1, abi.num_animation);
            sb.AppendFormat("动作速率(animation speed)   : {0:F1}\n", delta_time);
            sb.AppendFormat("动作名称(animation name)    : {0}\n", abi.animations[animation].name);

            d3dfont.DrawText(null, sb.ToString(), x, y, Color.White);
        }
示例#8
0
 public AGT_Text(string message, Microsoft.DirectX.Direct3D.Font label_font)
 {
     _font              = label_font;
     _label_message     = message;
     _message_rect      = label_font.MeasureString(null, message, DrawTextFormat.Center | DrawTextFormat.VerticalCenter, Color.White);
     _message_rect.X    = 0;
     _message_rect.Y    = 0;
     _label_rect.X      = 0;
     _label_rect.Y      = 0;
     _label_rect.Height = _message_rect.Height;
     _label_rect.Width  = (int)(_message_rect.Width + (_message_rect.Width * .2));
 }
示例#9
0
 /*-------------------------------------------------------------------------
  * 문자열の그리기時の사이즈を得る
  * ---------------------------------------------------------------------------*/
 public Rectangle MeasureText(string str, Color color)
 {
     if (is_created_textured_font(str))
     {
         // 캐시されていればそのまま사이즈を返す
         textured_font font = get_textured_font(str);
         Rectangle     rect = new Rectangle(0, 0, (int)font.size.X, (int)font.size.Y);
         return(rect);
     }
     // 캐시されてなければ調べる
     return(m_font.MeasureString(null, str, DrawTextFormat.None, color));
 }
示例#10
0
        public void DrawObjectID(Canvas canvas, Microsoft.DirectX.Direct3D.Font font)
        {
            if (ID != string.Empty)
            {
                _text_rect        = font.MeasureString(null, ID, DrawTextFormat.Center, TextColor);
                _text_rect.X      = (SpriteArea.X + ((SpriteArea.Width - _text_rect.Width) / 2)) - 5;
                _text_rect.Y      = SpriteArea.Bottom;
                _text_rect.Width += 10;
                canvas.DrawFillRect(_text_rect, _textbox_color_material);

                font.DrawText(null, ID, _text_rect, DrawTextFormat.Center, TextColor);
            }
        }
示例#11
0
        public Label(string id,
                     string text,
                     Vector2 position,
                     TextStyle textStyle) : base(id, position, Size.Empty)
        {
            style       = textStyle;
            textManager = new TextManager(Style.Font, lineHeight);
            Font        = Style.Font;
            area        = Font.MeasureString(UI.CurrentHud.SpriteManager, text, style.Flags, normal);
            size        = area.Size;
            this.text   = text;

            color = Style.StandardColor;
        }
示例#12
0
        public void AddTab(string tabLabel)
        {
            Panel tabPage = new Panel(string.Format("{0}_TabPage{1}", id, tabButtons.Count), Vector2.Empty, size);

            Rectangle tabRectangle = tabButtonFont.MeasureString(UI.CurrentHud.SpriteManager, tabLabel,
                                                                 DrawTextFormat.Left, Label.DefaultColor);

            int tabBaseWidth = DefaultTabBaseWidth;

            if (tabRectangle.Width > DefaultTabBaseWidth)
            {
                tabBaseWidth = tabRectangle.Width;
            }

            Button tabButton = new Button(string.Format("{0}_TabButton{1}", id, tabButtons.Count),
                                          tabLabel,
                                          new Vector2(totalWidth,
                                                      -DefaultTabHeight),
                                          new Size(tabBaseWidth, DefaultTabHeight),
                                          Shape.RightTrapezoidUpside,
                                          Shapes.ShadeTopToBottom,
                                          tabButtonColorArray
                                          );

            totalWidth += tabBaseWidth + DefaultTabTriangleWidth;

            tabButton.MouseClick += new MouseEventHandler(tabButton_MouseClick);

            currentTab = tabPage;

            foreach (Button button in tabButtons)
            {
                button.IsSelected = false;
            }
            foreach (Panel panel in tabPanels)
            {
                panel.IsVisible = false;
            }

            tabButtons.Add(tabButton);
            tabPanels.Add(tabPage);

            tabButton.IsSelected = true;

            Add(currentTab);
            Add(tabButton);
        }
示例#13
0
        public override void OnRender(Canvas canvas)
        {
            _background.X      = 0;
            _background.Y      = 0;
            _background.Width  = canvas.Size.Width;
            _background.Height = canvas.Size.Height;

            bounding_rect   = font_large.MeasureString(null, Message, DrawTextFormat.NoClip, Color.Yellow);
            bounding_rect.X = (_background.Width - bounding_rect.Width) / 2;
            bounding_rect.Y = (int)(_background.Height - (2 * bounding_rect.Height));

            canvas.DrawFillRect(_background, _background_color_material);
            canvas.DrawRect(_background, Color.White);

            font_large.DrawText(null, Message, bounding_rect, DrawTextFormat.None, MsgColor);

            base.OnRender(canvas);
        }
示例#14
0
            public textured_font(d3d_device device, string str, Microsoft.DirectX.Direct3D.Font font, Format format)
            {
                m_ref_count = 0;
                m_str       = str;
                try {
                    Rectangle rect = font.MeasureString(null, str, DrawTextFormat.None, Color.White);
                    m_size = new Vector2(rect.Right, rect.Bottom);

                    // 텍스쳐を작성
                    // 사이즈は4の배수とする
                    int width  = (((int)m_size.X) + 3) & ~3;
                    int height = (((int)m_size.Y) + 3) & ~3;
                    m_texture_size = new Vector2(width, height);
                    m_texture      = new Texture(device.device, width, height, 1,
                                                 Usage.RenderTarget, format, Pool.Default);
                } catch {
                    // 텍스쳐작성실패
                    m_size         = new Vector2(0, 0);
                    m_texture_size = new Vector2(0, 0);
                    m_texture      = null;
                    return;
                }

                // 렌더링 타겟を지정
                Surface depth      = device.device.DepthStencilSurface;
                Surface backbuffer = device.device.GetBackBuffer(0, 0, BackBufferType.Mono);

                device.device.DepthStencilSurface = null;                          // zバッファ없음
                device.device.SetRenderTarget(0, m_texture.GetSurfaceLevel(0));

                // 화면のクリア
                device.Clear(ClearFlags.Target, Color.FromArgb(0, 0, 0, 0));
                // 렌더링
                device.device.RenderState.ZBufferEnable = false;
                font.DrawText(null, str, new Point(0, 0), Color.White);
                device.device.RenderState.ZBufferEnable = true;

                // 렌더링 타겟を元に戻す
                device.device.DepthStencilSurface = depth;
                device.device.SetRenderTarget(0, backbuffer);

                backbuffer.Dispose();
                depth.Dispose();
            }
示例#15
0
        // Adds a token to text result.
        private static String AddToken(Direct3D.Font font, Sprite sprite, int width, String text, ref String currLine, String token, Color color)
        {
            Rectangle r = font.MeasureString(sprite, currLine + token, DrawTextFormat.None, color);

            if (r.Width <= width || currLine == "")
            {
                text     += token;
                currLine += token;
            }
            else
            {
                if (token == " ")
                {
                    token = "";
                }
                text    += ("\n" + token);
                currLine = token;
            }
            return(text);
        }
示例#16
0
        private static Size CalcSize(string message, Microsoft.DirectX.Direct3D.Font font)
        {
            Size size     = font.MeasureString(null, message, DrawStringFormat.Left, Color.White).Size;
            int  maxWidth = 500;

            if (size.Width <= maxWidth)
            {
                return(new Size(500, 200));
            }
            else
            {
                int height = size.Height;
                int rem;
                int lines = Math.DivRem(size.Width, maxWidth, out rem);
                if (rem > 0)
                {
                    lines++;
                }
                height *= lines;
                return(new Size(500, height + 50));
            }
        }
示例#17
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;
            }
        }
示例#18
0
        /// <summary>
        /// The render method to draw this widget on the screen.
        ///
        /// Called on the GUI thread.
        /// </summary>
        /// <param name="drawArgs">The drawing arguments passed from the WW GUI thread.</param>
        public void Render(DrawArgs drawArgs)
        {
            if ((!m_visible) || (!m_enabled))
            {
                return;
            }

            if (!m_isInitialized)
            {
                Initialize(drawArgs);
            }

            int widgetTop    = this.Top;
            int widgetBottom = this.Bottom;
            int widgetLeft   = this.Left;
            int widgetRight  = this.Right;

            m_currHeaderHeight = 0;

            #region Header Rendering

            // If we should render the header
            if (HeaderEnabled)
            {
                m_currHeaderHeight = m_headerHeight;

                JHU_Utilities.DrawBox(
                    this.AbsoluteLocation.X,
                    this.AbsoluteLocation.Y,
                    m_size.Width,
                    m_currHeaderHeight,
                    0.0f,
                    m_HeaderColor.ToArgb(),
                    drawArgs.device);

                Rectangle nameBounds = m_TitleFont.MeasureString(
                    null,
                    m_name,
                    DrawTextFormat.None,
                    0);

                int widthLeft = m_size.Width;

                m_TitleFont.DrawText(
                    null,
                    m_name,
                    new System.Drawing.Rectangle(this.AbsoluteLocation.X + 2, this.AbsoluteLocation.Y + 2, widthLeft, m_currHeaderHeight),
                    DrawTextFormat.None,
                    m_TextColor.ToArgb());


                // if we don't render the body add whatever is in the text field as annotation
                if (!m_renderBody)
                {
                    widthLeft -= nameBounds.Width + 10;
                    if (widthLeft > 20)
                    {
                        m_TextFont.DrawText(
                            null,
                            Text,
                            new System.Drawing.Rectangle(this.AbsoluteLocation.X + 10 + nameBounds.Width, this.AbsoluteLocation.Y + 3, widthLeft, m_currHeaderHeight),
                            DrawTextFormat.None,
                            m_TextColor.ToArgb());
                    }
                }

                // Render border
                m_OutlineVertsHeader[0].X = AbsoluteLocation.X;
                m_OutlineVertsHeader[0].Y = AbsoluteLocation.Y;

                m_OutlineVertsHeader[1].X = AbsoluteLocation.X + m_size.Width;
                m_OutlineVertsHeader[1].Y = AbsoluteLocation.Y;

                m_OutlineVertsHeader[2].X = AbsoluteLocation.X + m_size.Width;
                m_OutlineVertsHeader[2].Y = AbsoluteLocation.Y + m_currHeaderHeight;

                m_OutlineVertsHeader[3].X = AbsoluteLocation.X;
                m_OutlineVertsHeader[3].Y = AbsoluteLocation.Y + m_currHeaderHeight;

                m_OutlineVertsHeader[4].X = AbsoluteLocation.X;
                m_OutlineVertsHeader[4].Y = AbsoluteLocation.Y;

                JHU_Utilities.DrawLine(m_OutlineVertsHeader, m_BorderColor.ToArgb(), drawArgs.device);
            }

            #endregion

            #region Body Rendering

            if (m_renderBody)
            {
                // Draw the interior background
                JHU_Utilities.DrawBox(
                    this.AbsoluteLocation.X,
                    this.AbsoluteLocation.Y + m_currHeaderHeight,
                    m_size.Width,
                    m_size.Height - m_currHeaderHeight,
                    0.0f,
                    m_BackgroundColor.ToArgb(),
                    drawArgs.device);

                int childrenHeight = 0;
                int childrenWidth  = 0;

                int bodyHeight = m_size.Height - m_currHeaderHeight;
                int bodyWidth  = m_size.Width;

                getChildrenSize(out childrenHeight, out childrenWidth);

                // Render each child widget

                int bodyLeft    = this.BodyLocation.X;
                int bodyRight   = this.BodyLocation.X + this.ClientSize.Width;
                int bodyTop     = this.BodyLocation.Y;
                int bodyBottom  = this.BodyLocation.Y + this.ClientSize.Height;
                int childLeft   = 0;
                int childRight  = 0;
                int childTop    = 0;
                int childBottom = 0;

                for (int index = m_ChildWidgets.Count - 1; index >= 0; index--)
                {
                    jhuapl.util.IWidget currentChildWidget = m_ChildWidgets[index] as jhuapl.util.IWidget;
                    if (currentChildWidget != null)
                    {
                        if (currentChildWidget.ParentWidget == null || currentChildWidget.ParentWidget != this)
                        {
                            currentChildWidget.ParentWidget = this;
                        }
                        System.Drawing.Point childLocation = currentChildWidget.AbsoluteLocation;

                        // if any portion is visible try to render
                        childLeft   = childLocation.X;
                        childRight  = childLocation.X + currentChildWidget.WidgetSize.Width;
                        childTop    = childLocation.Y;
                        childBottom = childLocation.Y + currentChildWidget.WidgetSize.Height;

                        if ((((childLeft >= bodyLeft) && (childLeft <= bodyRight)) ||
                             ((childRight >= bodyLeft) && (childRight <= bodyRight)) ||
                             ((childLeft <= bodyLeft) && (childRight >= bodyRight)))
                            &&
                            (((childTop >= bodyTop) && (childTop <= bodyBottom)) ||
                             ((childBottom >= bodyTop) && (childBottom <= bodyBottom)) ||
                             ((childTop <= bodyTop) && (childBottom >= bodyBottom)))
                            )
                        {
                            currentChildWidget.Visible = true;
                            currentChildWidget.Render(drawArgs);
                        }
                        else
                        {
                            currentChildWidget.Visible = false;
                        }
                    }
                }

                m_OutlineVerts[0].X = AbsoluteLocation.X;
                m_OutlineVerts[0].Y = AbsoluteLocation.Y + m_currHeaderHeight;

                m_OutlineVerts[1].X = AbsoluteLocation.X + m_size.Width;
                m_OutlineVerts[1].Y = AbsoluteLocation.Y + m_currHeaderHeight;

                m_OutlineVerts[2].X = AbsoluteLocation.X + m_size.Width;
                m_OutlineVerts[2].Y = AbsoluteLocation.Y + m_size.Height;

                m_OutlineVerts[3].X = AbsoluteLocation.X;
                m_OutlineVerts[3].Y = AbsoluteLocation.Y + m_size.Height;

                m_OutlineVerts[4].X = AbsoluteLocation.X;
                m_OutlineVerts[4].Y = AbsoluteLocation.Y + m_currHeaderHeight;

                JHU_Utilities.DrawLine(m_OutlineVerts, m_BorderColor.ToArgb(), drawArgs.device);
            }

            #endregion
        }
示例#19
0
        protected override void RenderSynchronized(int width, int height)
        {
            base.RenderSynchronized(width, height);
            var wndSize     = new SizeF(width, height);
            var frameRate   = Allocator.Device.DisplayMode.RefreshRate;
            var graphRender = _graphRender.Get();
            var graphLoad   = _graphLoad.Get();

#if SHOW_LATENCY
            var graphLatency = _graphLatency.Get();
            //var graphCopy = _copyGraph.Get();
#endif
            var graphUpdate  = _graphUpdate.Get();
            var frequency    = GraphMonitor.Frequency;
            var limitDisplay = frequency / frameRate;
            var limit50      = frequency / 50D;
            var limit1ms     = frequency / 1000D;
            var maxRender    = graphRender.Max();
            var maxLoad      = graphLoad.Max();
            var minT         = graphRender.Min() * 1000D / frequency;
            var avgT         = graphRender.Average() * 1000D / frequency;
            var maxT         = maxRender * 1000D / frequency;
#if SHOW_LATENCY
            var minL = _graphLatency.IsDataAvailable ? graphLatency.Min() * 1000D / frequency : 0D;
            var avgL = _graphLatency.IsDataAvailable ? graphLatency.Average() * 1000D / frequency : 0D;
            var maxL = _graphLatency.IsDataAvailable ? graphLatency.Max() * 1000D / frequency : 0D;
#endif
            var avgE     = graphLoad.Average() * 1000D / frequency;
            var avgU     = graphUpdate.Average() * 1000D / frequency;
            var maxScale = Math.Max(maxRender, maxLoad);
            maxScale = Math.Max(maxScale, limit50);
            maxScale = Math.Max(maxScale, limitDisplay);
            var fpsRender = 1000D / avgT;
            var fpsUpdate = 1000D / avgU;
            var textValue = string.Format(
                "Render FPS: {0:F3}\n" +
                "Update FPS: {1:F3}\n" +
                "Device FPS: {2}\n" +
                "Back: [{3}, {4}]\n" +
                "Frame: [{5}, {6}]\n" +
                "Sound: {7:F3} kHz\n" +
                "FrameStart: {8}T",
                fpsRender,
                IsRunning ? fpsUpdate : (double?)null,
                frameRate,
                wndSize.Width,
                wndSize.Height,
                FrameSize.Width,
                FrameSize.Height,
                SampleRate / 1000D,
                FrameStartTact);
            var textRect = _font.MeasureString(
                null,
                textValue,
                DrawTextFormat.NoClip,
                Color.Yellow);
            textRect = new Rectangle(
                textRect.Left,
                textRect.Top,
                Math.Max(textRect.Width + 10, GraphLength),
                textRect.Height);
            FillRect(textRect, Color.FromArgb(192, Color.Green));
            _font.DrawText(
                null,
                textValue,
                textRect,
                DrawTextFormat.NoClip,
                Color.Yellow);
            // Draw graphs
            var graphRect = new Rectangle(
                textRect.Left,
                textRect.Top + textRect.Height,
                GraphLength,
                (int)(wndSize.Height - textRect.Top - textRect.Height));
            FillRect(graphRect, Color.FromArgb(192, Color.Black));
            RenderGraph(graphRender, maxScale, graphRect, Color.FromArgb(196, Color.Lime));
            RenderGraph(graphLoad, maxScale, graphRect, Color.FromArgb(196, Color.Red));
            //RenderGraph(graphCopy, maxTime, graphRect, Color.FromArgb(196, Color.Yellow));
            RenderLimit(limitDisplay, maxScale, graphRect, Color.FromArgb(196, Color.Yellow));
            RenderLimit(limit50, maxScale, graphRect, Color.FromArgb(196, Color.Magenta));
            DrawGraphGrid(maxScale, limit1ms, graphRect, _graphRender.GetIndex(), Color.FromArgb(64, Color.White));

            var msgTime = string.Format(
                "MinT: {0:F3} [ms]\nAvgT: {1:F3} [ms]\nMaxT: {2:F3} [ms]\nAvgE: {3:F3} [ms]",
                minT,
                avgT,
                maxT,
                avgE);
#if SHOW_LATENCY
            if (_graphLatency.IsDataAvailable)
            {
                msgTime = string.Format(
                    "{0}\nMinL: {1:F3} [ms]\nAvgL: {2:F3} [ms]\nMaxL: {3:F3} [ms]",
                    msgTime,
                    minL,
                    avgL,
                    maxL);
            }
#endif
            _font.DrawText(
                null,
                msgTime,
                graphRect,
                DrawTextFormat.NoClip,
                Color.FromArgb(156, Color.Yellow));
        }
示例#20
0
        public void Render()
        {
            device.VertexShader = null;
            device.PixelShader  = null;

            Camera cam = Camera.GetCameraInstance();

            device.Transform.View       = cam.GetMatrixView();
            device.Transform.Projection = cam.GetMatrixProjection();

            sprite.Begin(SpriteFlags.AlphaBlend);

            sprite.Draw2D(empty, srcRectangle, size, liveEmpty, Color.FromArgb(255, 255, 255, 255));
            sprite.Draw2D(live, liveRectangle, liveSize, livePoint, Color.FromArgb(255, 255, 255, 255));

            sprite.Draw2D(empty, srcRectangle, size, manaEmpty, Color.FromArgb(255, 255, 255, 255));
            sprite.Draw2D(mana, manaRectangle, manaSize, manaPoint, Color.FromArgb(255, 255, 255, 255));

            sprite.Draw2D(empty, srcRectangle, size, energyEmpty, Color.FromArgb(255, 255, 255, 255));
            sprite.Draw2D(energy, energyRectangle, energySize, energyPoint, Color.FromArgb(255, 255, 255, 255));

            sprite.End();

            RenderText();


            //for (int t = 0; t < sentences.Count; t++)
            //{
            //    Matrix m = Matrix.Identity;
            //    m *= Matrix.RotationX((float)Math.PI);
            //    m *= Matrix.Translation(sentences[t].position) * Matrix.Translation(0, 40, 0);
            //    sprite3d.SetWorldViewLH(m, device.Transform.View);
            //    sprite3d.Begin(SpriteFlags.ObjectSpace | SpriteFlags.Billboard | SpriteFlags.AlphaBlend);
            //    sprite3d.Draw2D(sentences[t].texture, new PointF(0,2),
            //        (float)Math.PI, new PointF(-sentences[t].rect.Width / 2, -16), Color.FromArgb(255, 255, 255, 255));
            //    sprite3d.End();
            //}

            device.Transform.Projection = cam.GetMatrixProjection();
            sprite3d.Transform          = Matrix.Identity;

            if (canRenderNpcInfo)
            {
                NpcInfo = form.Game.GetAllNpcInfo();

                for (int i = 0; i < NpcInfo.Count; i++)
                {
                    if (NpcInfo[i].Character.name == "Player")
                    {
                        setEnergy((int)NpcInfo[i].Status.energy);
                        setLive((int)(100 * NpcInfo[i].Status.hp / (float)(NpcInfo[i].Character.hp)));
                        setMana((int)(100 * NpcInfo[i].Status.mana / (float)(NpcInfo[i].Character.mana)));
                        continue;
                    }

                    StringFormat stringFormat = new StringFormat();
                    stringFormat.FormatFlags = StringFormatFlags.NoClip;

                    double percents = (1 - ((double)NpcInfo[i].Status.hp / (double)NpcInfo[i].Character.hp)) * 64;

                    npcRectange.X = (int)percents;

                    GeneralObject npcGeneral = getNpcGeneralObjectByName(NpcInfo[i].Character.name);
                    Matrix        world      = npcGeneral.GetMatrixWorld();

                    Vector3 min = npcGeneral.GetBoundingBoxRelativeMinimum();
                    Vector3 max = npcGeneral.GetBoundingBoxRelativeMaximum();
                    min = Vector3.TransformCoordinate(min, npcGeneral.GetMatrixWorldBoundingBoxMesh());
                    max = Vector3.TransformCoordinate(max, npcGeneral.GetMatrixWorldBoundingBoxMesh());
                    Vector3 delta = max - min;


                    world *= Matrix.Translation(0, delta.Y, 0);

                    device.Transform.World = world;

                    sprite3d.SetWorldViewLH(device.Transform.World, device.Transform.View);

                    sprite3d.Begin(SpriteFlags.ObjectSpace | SpriteFlags.Billboard | SpriteFlags.AlphaBlend);

                    sprite3d.Draw(empty2, npcScrRectange, center, new Vector3(0, 0, 0), Color.White);
                    sprite3d.Draw(live2, npcRectange, center, new Vector3(0, 0, 0), Color.White);
                    sprite3d.End();

                    Matrix current = Matrix.Identity;
                    Matrix hh      = cam.GetMatrixView();

                    Vector3 vect1 = new Vector3(world.M41 / world.M44, 0, world.M43 / world.M44);
                    Vector3 vect2 = new Vector3(hh.M41 / hh.M44, 0, hh.M43 / hh.M44);

                    Vector3 direction = vect2 - vect1;
                    vect1.Normalize();
                    vect2.Normalize();

                    float  vect3  = Vector3.Dot(vect1, vect2);
                    double number = vect3;
                    double angle  = Math.Acos(number);


                    if (direction.X > 0 && direction.Z > 0)
                    {
                        angle *= -1;
                    }
                    if (direction.X < 0 && direction.Z > 0)
                    {
                        angle *= -1;
                    }
                    current *= Matrix.Scaling(0.5f, 0.5f, 0.5f);
                    current *= Matrix.RotationZ((float)Math.PI);
                    current *= Matrix.RotationY((float)angle);

                    current.M41 = world.M41;
                    current.M42 = world.M42;
                    current.M43 = world.M43;
                    current.M44 = world.M44;

                    current *= Matrix.Translation(0, 15f, 0);

                    sprite3d.SetWorldViewLH(current, device.Transform.View);
                    device.Transform.World = current;

                    sprite3d.Begin(SpriteFlags.ObjectSpace | SpriteFlags.AlphaBlend);
                    Rectangle textRect = f.MeasureString(s, NpcInfo[i].Character.name, DrawTextFormat.Left, Color.DarkRed);
                    textRect.X -= (int)((float)textRect.Width * 0.5f);

                    Color textColor = Color.DarkRed;

                    if (NpcInfo[i].Character.type == WiccanRede.AI.NPCType.villager)
                    {
                        textColor = Color.DarkGreen;
                    }

                    f.DrawText(sprite3d, NpcInfo[i].Character.name, textRect, DrawTextFormat.Left, textColor);

                    sprite3d.End();
                }
            }
        }
示例#21
0
        public Rectangle MeasureString(string value)
        {
            var measure = _font.MeasureString(null, value, DrawTextFormat.None, Color.White);

            return(new Rectangle(measure.X, measure.Y, measure.Width, measure.Height));
        }
示例#22
0
        public override void DrawSpecial(Microsoft.DirectX.Direct3D.Font font, RectangleF overlay_rect, Rectangle text_rect, Canvas canvas)
        {
            _overlay_rect     = overlay_rect;
            _text_rect        = text_rect;
            _progressbar_rect = text_rect;
            _border_rect      = text_rect;



            if ((OwnerID == DDD_Global.Instance.PlayerID) && (DrawProgressBar))
            {
                _progressbar_rect.Y     += text_rect.Height;
                _progressbar_rect.Height = _ProgressBarHeight_;
                _progressbar_rect.Width  = _ProgressBarWidth_;
                _progressbar_rect.X     += ((text_rect.Width - _progressbar_rect.Width) / 2);

                _border_rect.Height = _ProgressBarHeight_ + _text_rect.Height + 2;

                canvas.DrawFillRect(_border_rect, _textbox_color_material);

                DrawObjectID(canvas, font);
                canvas.DrawRect(_border_rect, BorderColor);

                if (FuelCapacity > 0)
                {
                    canvas.DrawProgressBar(_progressbar_rect,
                                           progress_bar_background_material,
                                           progress_bar_foreground_material,
                                           FuelAmount / FuelCapacity);
                }
                else
                {
                    canvas.DrawProgressBar(_progressbar_rect,
                                           progress_bar_background_material,
                                           progress_bar_foreground_material,
                                           0);
                }
            }
            else
            {
                if (DrawUnmanagedAssetLabel)
                {
                    DrawObjectID(canvas, font);
                    canvas.DrawRect(_border_rect, BorderColor);
                }
            }



            foreach (DDDObjects attacker in Attackers)
            {
                float _destinationX = attacker.SpriteArea.X + (attacker.SpriteArea.Width / 2);
                float _destinationY = attacker.SpriteArea.Y + (attacker.SpriteArea.Height / 2);
                canvas.DrawLine(Color.Red, 1,
                                SpriteArea.X + (SpriteArea.Width / 2),
                                SpriteArea.Y + (SpriteArea.Height / 2),
                                _destinationX,
                                _destinationY
                                );
                //engagment_rect.X = (int)(_destinationX - 3);
                //engagment_rect.Y = (int)(_destinationY - 3);
                //engagment_rect.Height = 6;
                //engagment_rect.Width = 6;
                //canvas.DrawFillRect(engagment_rect, red_material);
            }

            if (IsBeingAttacked)
            {
                engagment_rect        = font.MeasureString(null, _engagementTimeStr, DrawTextFormat.Center | DrawTextFormat.VerticalCenter, Color.Red);
                engagment_rect.Width += 10;
                engagment_rect.X      = (int)(_overlay_rect.X + (_overlay_rect.Width - engagment_rect.Width) / 2);
                engagment_rect.Y      = (int)(_overlay_rect.Y + (_overlay_rect.Height - engagment_rect.Height) / 2);
                canvas.DrawFillRect(engagment_rect, black_material);
                canvas.DrawRect(engagment_rect, Color.Red);
                font.DrawText(null, _engagementTimeStr, engagment_rect, DrawTextFormat.Center | DrawTextFormat.VerticalCenter, Color.Red);
            }


            // Draw object "Tags"
            if (Tag != string.Empty && (DDD_Global.Instance.TagPosition != TagPositionEnum.INVISIBLE))
            {
                Rectangle tag_rect = font.MeasureString(null, Tag, DrawTextFormat.Center, Color.Black);

                switch (DDD_Global.Instance.TagPosition)
                {
                case TagPositionEnum.ABOVE:
                    tag_rect.Y = (int)(overlay_rect.Y - tag_rect.Height);
                    tag_rect.X = (int)(overlay_rect.X + ((overlay_rect.Width - tag_rect.Width) * .5f));
                    break;

                case TagPositionEnum.BELOW:
                    if (!DrawUnmanagedAssetLabel && (OwnerID != DDD_Global.Instance.PlayerID))
                    {
                        tag_rect.Y = (int)(overlay_rect.Bottom + 1);
                        tag_rect.X = (int)(overlay_rect.X + ((overlay_rect.Width - tag_rect.Width) * .5f));
                    }
                    else
                    {
                        tag_rect.Y = (int)(_border_rect.Bottom + 2);
                        tag_rect.X = (int)(overlay_rect.X + ((overlay_rect.Width - tag_rect.Width) * .5f));
                    }
                    break;

                case TagPositionEnum.CENTER:
                    //tag_rect.Y = (int)(overlay_rect.Y + ((overlay_rect.Height - tag_rect.Height) * .5f));
                    tag_rect.Y = (int)(overlay_rect.Bottom - tag_rect.Height - 2);
                    tag_rect.X = (int)(overlay_rect.X + ((overlay_rect.Width - tag_rect.Width) * .5f));
                    break;
                }

                canvas.DrawFillRect(tag_rect, tag_material);
                font.DrawText(null, Tag, tag_rect, DrawTextFormat.VerticalCenter | DrawTextFormat.Center, Color.Black);
            }
        }
示例#23
0
 void MeasureText()
 {
     textRect   = font.MeasureString(null, text, DrawTextFormat.None, Color.White);
     textCentre = new Size(textRect.Width / 2, textRect.Height / 2);
 }
示例#24
0
 public Rectangle MeasureStringIfIncreasedBy(string addition)
 {
     return(Font.MeasureString(UI.CurrentHud.SpriteManager, text + addition, style.Flags, normal));
 }
示例#25
0
        public override void OnInitializeScene(GameFramework g)
        {
            BindGameController();

            _background.X = 0;
            _background.Y = 0;
            _background.Width = g.CANVAS.Size.Width;
            _background.Height = g.CANVAS.Size.Height;
            
            //string path = System.Environment.CurrentDirectory + @"\ImageLib.dll";
            string path = string.Format(@"\\{0}\DDDClient\ImageLib.dll", DDD_Global.Instance.HostName);
            ImageLib = Assembly.LoadFile(path);
           
            //font_small = g.CANVAS.CreateFont(new System.Drawing.Font("Arial", 12));
            font_small = g.CANVAS.CreateFont(new System.Drawing.Font("MS Sans Serif", 14));

            font_large = g.CANVAS.CreateFont(new System.Drawing.Font("Arial", 28));

            bounding_rect = font_large.MeasureString(null, Message, DrawTextFormat.NoClip, Color.Yellow);
            bounding_rect.X = (_background.Width - bounding_rect.Width) / 2;
            bounding_rect.Y = (int)(_background.Height - (2*bounding_rect.Height));

            player_rect.X = (int)((_background.Width - (_background.Width / 4)) / 2);
            player_rect.Y = (int)((_background.Height - (_background.Height / 3)) / 2);
            player_rect.Width = (int)(_background.Width / 4);
            player_rect.Height = (int)( _background.Height / 3);

            _player_window = CreateWindow(g.CANVAS.CreateFont(new System.Drawing.Font("MS Sans Serif", 12)), "Available Players",
                 player_rect.X,
                 player_rect.Y,
                 player_rect.Right ,
                 player_rect.Bottom);

            _player_window.AllowMove = false;
            _player_window.AllowShade = false;
            _player_window.AllowResize = false;
            _player_window.HasScrollBars = false;
           

            _player_menu = new PanelMenu(
                                                     g.CANVAS.CreateFont(new System.Drawing.Font("MS Sans Serif", 14)),
                                                    new PanelMenuSelectHandler(PlayerSelection)
                                                    );
            _player_menu.BackgroundColor = Color.Black;
             _player_window.BindPanelControl(_player_menu);
           _player_window.Show();
            _player_menu.LayoutMenuOptions(new string[] { "Populating ..." }, PanelLayout.Vertical);

           
           _continue_btn = (PanelStaticButton)new PanelStaticButton(_player_window.ClientArea.Left,
               _player_window.ClientArea.Bottom + 2,
               _player_window.ClientArea.Right,
               _player_window.ClientArea.Bottom + 27);
            _continue_btn.Text = "Continue";
            _continue_btn.BackgroundColor = Color.FromArgb(204, 63, 63, 63);
            _continue_btn.BorderColor = Color.White;
            _continue_btn.Font = font_small;
            _continue_btn.MouseClick = new System.Windows.Forms.MouseEventHandler(this.Btn_Continue);



        }
示例#26
0
 /// <summary>
 /// Measures the rectangle dimensions of the specified text string when
 /// drawn with the specified <see cref="Microsoft.DirectX.Direct3D.Sprite">
 /// Microsoft.DirectX.Direct3D.Sprite</see> object.
 /// </summary>
 /// <param name="font">
 /// The Direct3D font for which to measure the specified text.
 /// </param>
 /// <param name="sprite">
 /// A <see cref="Microsoft.DirectX.Direct3D.Sprite">Sprite</see> object that
 /// contains the string.
 /// </param>
 /// <param name="text">String to measure.</param>
 /// <param name="width">Maximum width of the string.</param>
 /// <param name="color">Color of the text.</param>
 /// <returns>
 /// A Rectangle structure that contains the rectangle, in logical coordinates, that
 /// encompasses the formatted text string.
 /// </returns>
 public static Rectangle MeasureString(Direct3D.Font font, Sprite sprite, String text, int width, Color color)
 {
     return(font.MeasureString(sprite, WrapString(sprite, font, text, width, color), DrawTextFormat.None, color));
 }
示例#27
0
        /// <summary>
        /// 渲染当前菜单项
        /// </summary>
        /// <param name="drawArgs">绘制参数</param>
        /// <param name="x">菜单项X位置</param>
        /// <param name="y">菜单项Y位置</param>
        /// <param name="yOffset">菜单项Y偏移</param>
        /// <param name="width">菜单项宽度</param>
        /// <param name="height">菜单项高度</param>
        /// <param name="drawingFont">绘制字体</param>
        /// <param name="wingdingsFont"></param>
        /// <param name="worldwinddingsFont"></param>
        /// <param name="mouseOverItem">鼠标覆盖的菜单项</param>
        /// <returns>返回本次渲染消耗的高度</returns>
        public int Render(DrawArgs drawArgs, int x, int y, int yOffset, int width, int height,
                          Microsoft.DirectX.Direct3D.Font drawingFont,
                          Microsoft.DirectX.Direct3D.Font wingdingsFont,
                          Microsoft.DirectX.Direct3D.Font worldwinddingsFont,
                          LayerMenuItem mouseOverItem)
        {
            if (ParentControl == null)
            {
                ParentControl = drawArgs.parentControl;
            }

            this._x     = x;
            this._y     = y + yOffset;
            this._width = width;

            int consumedHeight = 20;

            System.Drawing.Rectangle textRect = drawingFont.MeasureString(null,
                                                                          m_renderableObject.Name,
                                                                          DrawTextFormat.None,
                                                                          System.Drawing.Color.White.ToArgb());

            consumedHeight = textRect.Height;

            if (m_renderableObject.Description != null && m_renderableObject.Description.Length > 0 && !(m_renderableObject is QRST.WorldGlobeTool.Renderable.Icon))
            {
                System.Drawing.SizeF rectF = DrawArgs.Graphics.MeasureString(
                    m_renderableObject.Description,
                    drawArgs.DefaultSubTitleFont,
                    width - (this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset)
                    );

                consumedHeight += (int)rectF.Height + 15;
            }

            lastConsumedHeight = consumedHeight;
            // Layer manager client area height
            int totalHeight = height - y;

            updateList();

            if (yOffset >= -consumedHeight)
            {
                // Part of item or whole item visible
                int color = m_renderableObject.IsOn ? itemOnColor : itemOffColor;
                if (mouseOverItem == this)
                {
                    if (!m_renderableObject.IsOn)
                    {
                        // mouseover + inactive color (black)
                        color = 0xff << 24;
                    }
                    MenuUtils.DrawBox(m_parent.ClientLeft, _y, m_parent.ClientWidth, consumedHeight, 0,
                                      World.Settings.menuOutlineColor, drawArgs.device);
                }

                if (m_renderableObject is RenderableObjectList)
                {
                    RenderableObjectList rol = (RenderableObjectList)m_renderableObject;
                    if (!rol.DisableExpansion)
                    {
                        worldwinddingsFont.DrawText(
                            null,
                            (this.isExpanded ? "L" : "A"),
                            new System.Drawing.Rectangle(x + this._itemXOffset, _y, this._expandArrowXSize, height),
                            DrawTextFormat.None,
                            color);
                    }
                }

                string checkSymbol = null;
                if (m_renderableObject.ParentList != null && m_renderableObject.ParentList.IsShowOnlyOneLayer)
                {
                    // Radio check
                    checkSymbol = m_renderableObject.IsOn ? "O" : "P";
                }
                else
                {
                    // Normal check
                    checkSymbol = m_renderableObject.IsOn ? "N" : "F";
                }

                worldwinddingsFont.DrawText(
                    null,
                    checkSymbol,
                    new System.Drawing.Rectangle(
                        x + this._itemXOffset + this._expandArrowXSize,
                        _y,
                        this._checkBoxXOffset,
                        height),
                    DrawTextFormat.NoClip,
                    color);


                drawingFont.DrawText(
                    null,
                    m_renderableObject.Name,
                    new System.Drawing.Rectangle(
                        x + this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset,
                        _y,
                        width - (this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset),
                        height),
                    DrawTextFormat.None,
                    color);

                if (m_renderableObject.Description != null && m_renderableObject.Description.Length > 0 && !(m_renderableObject is QRST.WorldGlobeTool.Renderable.Icon))
                {
                    drawArgs.DefaultSubTitleDrawingFont.DrawText(
                        null,
                        m_renderableObject.Description,
                        new System.Drawing.Rectangle(
                            x + this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset,
                            _y + textRect.Height,
                            width - (_itemXOffset + _expandArrowXSize + _checkBoxXOffset),
                            height),
                        DrawTextFormat.WordBreak,
                        System.Drawing.Color.Gray.ToArgb());
                }

                if (m_renderableObject.MetaData.Contains("InfoUri"))
                {
                    Vector2[] underlineVerts = new Vector2[2];
                    underlineVerts[0].X = x + this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset;
                    underlineVerts[0].Y = _y + textRect.Height;
                    underlineVerts[1].X = underlineVerts[0].X + textRect.Width;
                    underlineVerts[1].Y = _y + textRect.Height;

                    MenuUtils.DrawLine(underlineVerts, color, drawArgs.device);
                }
            }

            if (isExpanded)
            {
                for (int i = 0; i < m_subItems.Count; i++)
                {
                    int yRealOffset = yOffset + consumedHeight;
                    if (yRealOffset > totalHeight)
                    {
                        // No more space for items
                        break;
                    }
                    LayerMenuItem lmi = (LayerMenuItem)m_subItems[i];
                    consumedHeight += lmi.Render(
                        drawArgs,
                        x + _subItemXIndent,
                        y,
                        yRealOffset,
                        width - _subItemXIndent,
                        height,
                        drawingFont,
                        wingdingsFont,
                        worldwinddingsFont,
                        mouseOverItem);
                }
            }

            return(consumedHeight);
        }
示例#28
0
文件: Game.cs 项目: IanusInferus/cmdt
        ////////////////////////////////////////////////////////////////////////////////////
        public void RenderFrame()
        {
            device.BeginScene();
            if ((!DisplayHorizonalMesh && !DisplayVerticalMesh))
            {
                device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, 0x0, 1.0f, 0);
            }
            else
            {
                device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, 0x353535, 1.0f, 0);
            }

            ////////////////////////////////////////////////////////////////////////////////////
            //设置变换矩阵和灯光
            SetupMatrices();
            SetupLights();

            ////////////////////////////////////////////////////////////////////////////////////
            //device.RenderState.UseWBuffer = true;
            //device.RenderState.CullMode = Cull.None;
            //device.RenderState.FillMode = FillMode.WireFrame;

            ////////////////////////////////////////////////////////////////////////////////////
            //两个mesh由面构成,因此顶点需要提供法线信息
            device.VertexFormat = CustomVertex.PositionNormalColored.Format;
            device.RenderState.SlopeScaleDepthBias = 1F;                //最重要的参数设置,消除线与面的Z-Fightingd
            //device.RenderState.DepthBias = 0F;			//重要参数 about Hidden Lines Removal

            int numSubSets;

            if (DisplayHorizonalMesh)
            {
                numSubSets = ms.mesh.GetAttributeTable().Length;
                for (int i = 0; i < numSubSets; i++)
                {
                    ms.mesh.DrawSubset(i);
                }
            }
            if (DisplayVerticalMesh && ws.mesh != null)
            {
                numSubSets = ws.mesh.GetAttributeTable().Length;
                for (int i = 0; i < numSubSets; i++)
                {
                    ws.mesh.DrawSubset(i);
                }
            }

            ////////////////////////////////////////////////////////////////////////////////////
            //线框是目前存在性能问题最大的部分之一
            if (DisplayWireFrame)
            {
                //区域网格由直线构成,因此顶点不需要法线信息
                device.VertexFormat         = CustomVertex.PositionColored.Format;
                device.RenderState.Lighting = false;                    //区域网格无需灯光效果

                DrawBatchLinelist(pl.vertexbuf, pl.NumberOfLines);

                if (wpl.vertexbuf != null)
                {
                    DrawBatchLinelist(wpl.vertexbuf, wpl.NumberOfLines);
                }
            }

            ////////////////////////////////////////////////////////////////////////////////////
            //在当前选中的多边形质心处显示其编号
            Point     p = CaculateScreenXYofWorldPoint(curr_centroid);
            string    s = curr_district.ToString();
            Rectangle r = d3dfont_selected.MeasureString(null, s, DrawTextFormat.Center, Color.White);             //居中

            p.X -= r.Width / 2;
            p.Y -= r.Height / 2;
            if (!EnableLights && !EnableColoring && DisplayHorizonalMesh)
            {
                d3dfont_selected.DrawText(null, curr_district.ToString(), p, Color.Black);
            }
            else if (sec.districts[curr_district].attributes[0] == 1 && EnableColoring)
            {
                d3dfont_selected.DrawText(null, curr_district.ToString(), p, Color.Black);
            }
            else
            {
                d3dfont_selected.DrawText(null, curr_district.ToString(), p, Color.White);
            }

            ////////////////////////////////////////////////////////////////////////////////////
            //绘制信息框及其其中的文字,关键是:写在这里会不会打断CPU和AGP的pipeline?
            if (DisplayInfoHUD)
            {
                Vector3 center = new Vector3();                 //是struct,没有关系
                Vector3 pos    = new Vector3();

                //绘制半透明的信息框
                sprite.Begin(SpriteFlags.AlphaBlend);
                sprite.Draw(bkground_hud, Rectangle.Empty, center, pos, Color.FromArgb(80, 0, 0, 0));
                sprite.End();

                //绘制信息字符串
                d3dfont_hud.DrawText(null, message, 10, 7, Color.White);
            }

            ////////////////////////////////////////////////////////////////////////////////////
            //显示多边形选择框(高亮度青色)
            device.RenderState.Lighting = false;
            device.VertexFormat         = CustomVertex.PositionColored.Format;
            device.RenderState.AntiAliasedLineEnable = true;             //BUG? 会影响后面的Render
            DrawBatchLinelist(sl.vertexbuf, sl.NumberOfLines);
            device.RenderState.AntiAliasedLineEnable = false;            //MDX BUG? 无法取消前面的true,WHY?

            ////////////////////////////////////////////////////////////////////////////////////
            device.EndScene();

            try
            {
                device.Present();
            }
            catch (DeviceLostException)
            {
                device_lost = true;
                Debug.WriteLine("Device was lost");
            }
        }
示例#29
0
    public static void MeasureText(Font fnt, string text, ref float textwidth, ref float textheight, int fontSize)
    {
      if (text[0] == ' ') // anti-trim
      {
        text = "_" + text.Substring(1);
      }
      if (text[text.Length - 1] == ' ')
      {
        text = text.Substring(0, text.Length - 1) + '_';
      }

      // Text drawing doesnt work with DX9Ex & sprite
      if (GUIGraphicsContext.IsDirectX9ExUsed())
      {
        MeasureText(text, ref textwidth, ref textheight, fontSize);
      }
      else
      {
        if (_d3dxSprite == null)
        {
          _d3dxSprite = new Sprite(GUIGraphicsContext.DX9Device);
        }
        Rectangle rect = fnt.MeasureString(_d3dxSprite, text, DrawTextFormat.NoClip, Color.Black);
        textwidth = rect.Width;
        textheight = rect.Height;
      }
      return;
    }
示例#30
0
        /// <summary>
        /// 渲染三维球体
        /// </summary>
        /// <param name="drawArgs"></param>
        public override void Render(DrawArgs drawArgs)
        {
            if (!isOn)
            {
                return;
            }

            if (!IsInitialized)
            {
                Initialize(drawArgs);
            }


            #region 绘制色带

            CustomVertex.TransformedColored[] lineVerts;  //线段顶点列表
            switch (m_Anchor)
            {
            case ColorBarAnchor.Left:
            case ColorBarAnchor.LeftTop:
            case ColorBarAnchor.LeftBottom:
            case ColorBarAnchor.Right:
            case ColorBarAnchor.RightTop:
            case ColorBarAnchor.RightBottom:
                for (int i = 1; i < m_Height; i++)
                {
                    lineVerts          = new CustomVertex.TransformedColored[2];
                    lineVerts[0].X     = m_Location.X;
                    lineVerts[0].Y     = m_Location.Y + m_Height - i;
                    lineVerts[0].Z     = 0.0f;
                    lineVerts[0].Color = m_ColorBarColorBlend.GetColor(i / (float)m_Height).ToArgb();

                    lineVerts[1].X     = m_Location.X + m_Width;
                    lineVerts[1].Y     = lineVerts[0].Y;
                    lineVerts[1].Z     = 0.0f;
                    lineVerts[1].Color = lineVerts[0].Color;
                    drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Disable;
                    drawArgs.device.VertexFormat = CustomVertex.TransformedColored.Format;
                    drawArgs.device.DrawUserPrimitives(PrimitiveType.LineStrip, lineVerts.Length - 1, lineVerts);
                }
                break;

            case ColorBarAnchor.Top:
            case ColorBarAnchor.TopLeft:
            case ColorBarAnchor.TopRight:
            case ColorBarAnchor.Bottom:
            case ColorBarAnchor.BottomLeft:
            case ColorBarAnchor.BottomRight:
                for (int i = 1; i < m_Width; i++)
                {
                    lineVerts          = new CustomVertex.TransformedColored[2];
                    lineVerts[0].X     = m_Location.X + i;
                    lineVerts[0].Y     = m_Location.Y;
                    lineVerts[0].Z     = 0.0f;
                    lineVerts[0].Color = m_ColorBarColorBlend.GetColor(i / (float)m_Width).ToArgb();

                    lineVerts[1].X     = lineVerts[0].X;
                    lineVerts[1].Y     = m_Location.Y + m_Height;
                    lineVerts[1].Z     = 0.0f;
                    lineVerts[1].Color = lineVerts[0].Color;
                    drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Disable;
                    drawArgs.device.VertexFormat = CustomVertex.TransformedColored.Format;
                    drawArgs.device.DrawUserPrimitives(PrimitiveType.LineStrip, lineVerts.Length - 1, lineVerts);
                }
                break;
            }

            #endregion

            #region 绘制文字

            Rectangle      colorTextRectangle;
            DrawTextFormat minValueFormat, midValueFormat, maxValueFormat;
            switch (m_Anchor)
            {
            case ColorBarAnchor.Left:
            case ColorBarAnchor.LeftTop:
            case ColorBarAnchor.LeftBottom:
            default:
                colorTextRectangle = new Rectangle(m_Location.X + m_Width + 2, m_Location.Y,
                                                   drawArgs.ScreenWidth, m_Height);
                minValueFormat = DrawTextFormat.Left | DrawTextFormat.Bottom;
                midValueFormat = DrawTextFormat.Left | DrawTextFormat.VerticalCenter;
                maxValueFormat = DrawTextFormat.Left | DrawTextFormat.Top;
                break;

            case ColorBarAnchor.Right:
            case ColorBarAnchor.RightTop:
            case ColorBarAnchor.RightBottom:
                colorTextRectangle = new Rectangle(0, m_Location.Y,
                                                   drawArgs.ScreenWidth - m_Width - 3, m_Height);
                minValueFormat = DrawTextFormat.Right | DrawTextFormat.Bottom;
                midValueFormat = DrawTextFormat.Right | DrawTextFormat.VerticalCenter;
                maxValueFormat = DrawTextFormat.Right | DrawTextFormat.Top;
                break;

            case ColorBarAnchor.Top:
            case ColorBarAnchor.TopLeft:
            case ColorBarAnchor.TopRight:
                colorTextRectangle = new Rectangle(m_Location.X, m_Location.Y + m_Height + 2,
                                                   m_Width, drawArgs.ScreenHeight);
                minValueFormat = DrawTextFormat.Left | DrawTextFormat.Top;
                midValueFormat = DrawTextFormat.Center | DrawTextFormat.Top;
                maxValueFormat = DrawTextFormat.Right | DrawTextFormat.Top;
                break;

            case ColorBarAnchor.Bottom:
            case ColorBarAnchor.BottomLeft:
            case ColorBarAnchor.BottomRight:
                colorTextRectangle = new Rectangle(m_Location.X, 0,
                                                   m_Width, drawArgs.ScreenHeight - m_Height - 3);
                minValueFormat = DrawTextFormat.Left | DrawTextFormat.Bottom;
                midValueFormat = DrawTextFormat.Center | DrawTextFormat.Bottom;
                maxValueFormat = DrawTextFormat.Right | DrawTextFormat.Bottom;
                break;
            }
            m_ColorTextFont.DrawText(null, m_MaxValue.ToString(), colorTextRectangle, maxValueFormat, m_ColorBarColorBlend.GetColor(1.0f).ToArgb());
            m_ColorTextFont.DrawText(null, m_MinValue.ToString(), colorTextRectangle, minValueFormat, m_ColorBarColorBlend.GetColor(0.0f).ToArgb());
            if (m_IsShowMiddleValue)
            {
                string midText = m_ValueType == ColorBarValueType.整型 ? (((long)m_MaxValue + (long)m_MinValue) / 2).ToString() : (((double)m_MaxValue + (double)m_MinValue) / 2.0).ToString("0.00");
                m_ColorTextFont.DrawText(null, midText, colorTextRectangle, midValueFormat, m_ColorBarColorBlend.GetColor(0.5f).ToArgb());
            }

            //绘制标题
            if (m_ColorBarTitle != "")
            {
                Rectangle titleRectangle = m_TitleFont.MeasureString(null, m_ColorBarTitle, DrawTextFormat.Right, Color.White);
                titleRectangle.X     = 0;
                titleRectangle.Y     = m_Location.Y;
                titleRectangle.Width = drawArgs.ScreenWidth;
                m_TitleFont.DrawText(null, m_ColorBarTitle, titleRectangle, DrawTextFormat.Right, is3DMapMode ? Color.DeepSkyBlue : Color.FloralWhite);
            }

            #endregion
        }
示例#31
0
        public override void Render(DrawArgs drawArgs)
        {
            try {
                lock (this) {
                    Vector3 cameraPosition = drawArgs.WorldCamera.Position;
                    if (m_placeNames == null)
                    {
                        return;
                    }

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

                    if (m_sprite != null)
                    {
                        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 < m_placeNames.Length; index++)
                    {
                        Vector3 v = m_placeNames[index].cartesianPoint;
                        float   distanceSquared = Vector3.LengthSq(v - cameraPosition);
                        if (distanceSquared > m_maximumDistanceSq)
                        {
                            continue;
                        }

                        if (distanceSquared < m_minimumDistanceSq)
                        {
                            continue;
                        }

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

                        Vector3 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;
                         * }
                         */

                        Rectangle rect = m_drawingFont.MeasureString(null, label, m_textFormat, m_color);

                        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);

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

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

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

                    if (m_sprite != null)
                    {
                        m_sprite.End();
                    }
                }
            }
            catch (Exception caught) {
                Log.Write(caught);
            }
        }
示例#32
0
        private void drawWorlds(ref int index, ref int xIndex, ref int yIndex, ref int xPos, ref int yPos, hittest_list list)
        {
            foreach (GvoWorldInfo.Info i in list)
            {
                String name = i.Name;
                if (i.InfoType == GvoWorldInfo.InfoType.GuildCity && i.CityInfo != null && i.CityInfo.HasNameImage == false)
                {
                    continue;
                }
                else if (i.InfoType == GvoWorldInfo.InfoType.GuildCity && i.CityInfo != null)
                {
                    name = i.Name.Substring(0, i.Name.Length - 1);
                }

                Rectangle rect = m_font.MeasureString(m_sprite, name, DrawTextFormat.Left, Color.White);

                xPos = (xIndex) * MAX_NAME_WIDTH + 1;
                yPos = (yIndex) * 16 + 1;

                Color color = Color.Black;
                if (i.InfoType == GvoWorldInfo.InfoType.Sea)
                {
                    color = Color.RoyalBlue;
                }
                else if (i.InfoType == GvoWorldInfo.InfoType.Shore)
                {
                    color = Color.SeaGreen;
                }
                else if (i.InfoType == GvoWorldInfo.InfoType.Shore2)
                {
                    color = Color.Navy;
                }
                else if (i.InfoType == GvoWorldInfo.InfoType.OutsideCity)
                {
                    color = Color.Chocolate;
                }
                else if (i.InfoType == GvoWorldInfo.InfoType.PF)
                {
                    color = Color.SaddleBrown;
                }

                m_font.DrawText(null, name, xPos - 1, yPos - 1, Color.FromArgb(190, Color.White));
                m_font.DrawText(null, name, xPos - 1, yPos + 1, Color.FromArgb(190, Color.White));
                m_font.DrawText(null, name, xPos + 1, yPos - 1, Color.FromArgb(190, Color.White));
                m_font.DrawText(null, name, xPos + 1, yPos + 1, Color.FromArgb(190, Color.White));
                m_font.DrawText(null, name, xPos - 1, yPos, Color.FromArgb(230, Color.White));
                m_font.DrawText(null, name, xPos + 1, yPos, Color.FromArgb(230, Color.White));
                m_font.DrawText(null, name, xPos, yPos - 1, Color.FromArgb(230, Color.White));
                m_font.DrawText(null, name, xPos, yPos + 1, Color.FromArgb(230, Color.White));
                m_font.DrawText(null, name, xPos + 0, yPos + 0, color);

                rect.X = xPos - 1;
                rect.Y = yPos - 1;

                rect.Width  += 3;
                rect.Height += 2;

                Vector2 leftTop = new Vector2(rect.X, rect.Y);
                Vector2 size    = new Vector2(rect.Width, rect.Height);

                if (i.NameRect != null)
                {
                    if (m_nameRect.ContainsKey(i.Name))
                    {
                        //i.NameRect = new d3d_sprite_rects.rect(m_textureSize, m_offset, rect);
                        //m_nameRect.Remove(i.Name);
                        //m_nameRect.Add(i.Name, i.NameRect);
                    }
                    else
                    {
                        i.NameRect = new d3d_sprite_rects.rect(m_textureSize, m_offset, rect);
                        m_nameRect.Add(i.Name, i.NameRect);
                    }
                }
                else
                {
                    i.NameRect = new d3d_sprite_rects.rect(m_textureSize, m_offset, rect);
                    m_nameRect.Add(i.Name, i.NameRect);
                }

                yIndex++;
                if (yIndex >= MAX_NAME_LINE)
                {
                    xIndex++;
                    yIndex = 0;
                }
                index++;
            }
        }