Пример #1
0
        private void RenderInternal(GwenRenderContext ctx)
        {
            if (m_resizeCtrl != null && m_resizeCtrl.IsVisible)
            {
                if (GwenUtil.GetWorldBound(m_resizeCtrl).Contains(ctx.CurrentMousePos))
                {
                    m_resizeCtrl.RenderBound(ctx.Renderer);
                }
            }

            foreach (Node n in m_selection)
            {
                Rectangle rect = n.GetWorldBounds();
                Color     c    = ctx.Renderer.DrawColor;
                RenderSelectionBox(ctx.Renderer, rect);

                Point textSize = ctx.Renderer.MeasureText(ctx.Font, BaseUtil.PointToString(n.Position));

                ctx.Renderer.DrawColor = SceneEdConstants.SelectionCoordBgColor;
                ctx.Renderer.DrawFilledRect(new Rectangle(rect.X, rect.Y - textSize.Y - 10, textSize.X, textSize.Y));
                ctx.Renderer.DrawColor = SceneEdConstants.SelectionCoordTextColor;
                ctx.Renderer.RenderText(ctx.Font, new Point(rect.X, rect.Y - textSize.Y - 10), BaseUtil.PointToString(n.Position));

                if (rect.Contains(ctx.CurrentMousePos) || IsScrolling)
                {
                    RenderHoveringSelectedNode(ctx.Renderer, ctx, n);
                }

                ctx.Renderer.DrawColor = c;
            }
        }
Пример #2
0
        private void RenderTextNode(TextNode textNode, GwenRenderContext grc)
        {
            if (string.IsNullOrEmpty(textNode.Text))
            {
                return;
            }

            // 当需要的时候,先更新 TextNode 的尺寸
            Point textSize = grc.Renderer.MeasureText(grc.Font, textNode.Text);

            if (textNode.RequestedSizeRefreshing)
            {
                textNode.Size = new Size(
                    Math.Max(textNode.Size.Width, textSize.X),
                    Math.Max(textNode.Size.Height, textSize.Y));
                NodeSGUtil.ClampBounds(textNode);
                textNode.RequestedSizeRefreshing = false;
            }

            Point loc = grc.GetAccumulatedDockedScrolledTranslate();

            // 理论上这里我们不应当每帧对每段 Text 都调用 MeasureText()
            // 不过考察 Gwen.Renderer.Tao.MeasureText() 后我们发现
            // 其内部已经 Cache 了一份,把尺寸再缓存一份意义不大
            Point internalOffset = TextNodeUtil.CalculateInternalTextOffset(textNode, textSize);

            loc.Offset(internalOffset);

            Color c = grc.Renderer.DrawColor;

            grc.Renderer.DrawColor = textNode.TextColor;
            grc.Renderer.RenderText(grc.Font, loc, textNode.Text);
            grc.Renderer.DrawColor = c;
        }
Пример #3
0
        private void RenderCheckBox(CheckBox cb, GwenRenderContext grc)
        {
            Rectangle rect = new Rectangle(grc.GetAccumulatedDockedScrolledTranslate(), cb.MarkSize);

            DrawImage(grc, rect, cb.Res_Background);
            DrawImage(grc, rect, cb.Res_Mark);
        }
Пример #4
0
        public void Render(GwenRenderContext ctx)
        {
            // 把当前的设计时分辨率画下来
            Color c = ctx.Renderer.DrawColor;

            {
                // draw the coordinate
                ctx.Renderer.DrawColor = Color.LightGray;
                ctx.Renderer.DrawLinedRect(new Rectangle(-1000, 0, 5000, 1));
                ctx.Renderer.DrawLinedRect(new Rectangle(0, -1000, 1, 5000));
                ctx.Renderer.DrawColor = Color.White;
                ctx.Renderer.RenderText(ctx.Font, new Point(-35, -20), "(0, 0)");

                // draw the boundary
                int w = Scene.Instance.DesignTimeResolution.width;
                int h = Scene.Instance.DesignTimeResolution.height;
                ctx.Renderer.DrawColor = Color.DarkGreen;
                ctx.Renderer.DrawLinedRect(new Rectangle(0, 0, w, h));
                ctx.Renderer.RenderText(ctx.Font, new Point(w + 10, h / 2), h.ToString());
                ctx.Renderer.RenderText(ctx.Font, new Point(w / 2 - 30, h), w.ToString());
            }
            ctx.Renderer.DrawColor = c;

            m_dragAndDropReceiver.Render(ctx);
            m_selectionList.Render(ctx);
        }
Пример #5
0
        void RenderHoveringSelectedNode(Gwen.Renderer.Tao renderer, GwenRenderContext ctx, Node hoveringNode)
        {
            renderer.DrawColor = SceneEdConstants.SelectionDescTextColor;
            Rectangle rect     = hoveringNode.GetWorldBounds();
            int       interval = SceneEdConstants.TextLineInterval;

            {
                string title         = string.Format("{0} [{1}]", hoveringNode.Name, hoveringNode.GetType().Name);
                Point  titleSize     = renderer.MeasureText(ctx.Font, title);
                Point  widthTextSize = renderer.MeasureText(ctx.Font, rect.Width.ToString());

                int occupiedHeight = titleSize.Y + widthTextSize.Y + interval * 2;
                int titleX         = rect.X + rect.Width / 2 - titleSize.X / 2;
                int titleY         = rect.Top < occupiedHeight ? rect.Top + occupiedHeight - widthTextSize.Y : rect.Top - occupiedHeight;
                int widthTextX     = rect.X + rect.Width / 2 - widthTextSize.X / 2;
                int widthTextY     = rect.Top < occupiedHeight ? rect.Top + interval : rect.Top - interval - widthTextSize.Y;

                renderer.RenderText(ctx.Font, new Point(titleX, titleY), title);
                renderer.RenderText(ctx.Font, new Point(widthTextX, widthTextY), rect.Width.ToString());
                renderer.DrawFilledRect(new Rectangle(rect.X, widthTextY + widthTextSize.Y / 2, widthTextX - rect.X, 1));
                renderer.DrawFilledRect(new Rectangle(widthTextX + widthTextSize.X, widthTextY + widthTextSize.Y / 2, widthTextX - rect.X, 1));
            }

            {
                Point heightTextSize = renderer.MeasureText(ctx.Font, rect.Height.ToString());
                int   heightTextX    = rect.Left < heightTextSize.X ? rect.Left : rect.Left - heightTextSize.X;
                int   heightTextY    = rect.Top + rect.Height / 2 - heightTextSize.Y / 2;

                renderer.RenderText(ctx.Font, new Point(heightTextX, heightTextY), rect.Height.ToString());
                renderer.DrawFilledRect(new Rectangle(rect.X - heightTextSize.X / 2, rect.Top, 1, rect.Height / 2 - heightTextSize.Y / 2));
                renderer.DrawFilledRect(new Rectangle(rect.X - heightTextSize.X / 2, heightTextY + heightTextSize.Y, 1, rect.Height / 2 - heightTextSize.Y / 2));
            }

            int thickness = SceneEdConstants.SlideBarThickness;

            if (hoveringNode.IsScrollableH())
            {
                float range       = (float)(hoveringNode.LogicalSize.Width - hoveringNode.Size.Width);
                int   slideWidth  = (int)((float)rect.Width * (float)(hoveringNode.Size.Width) / (float)(hoveringNode.LogicalSize.Width));
                int   slideOffset = (int)((float)(rect.Width - slideWidth) * (float)hoveringNode.CurrentScrollOffset.X / range);

                renderer.DrawColor = SceneEdConstants.SlideBarBackground;
                renderer.DrawFilledRect(new Rectangle(rect.X, rect.Bottom, rect.Width, thickness));
                renderer.DrawColor = IsScrolling ? SceneEdConstants.SelectionHighlightColor : SceneEdConstants.SlideBarForeground;
                renderer.DrawFilledRect(new Rectangle(rect.X + slideOffset, rect.Bottom, slideWidth, thickness));
            }
            if (hoveringNode.IsScrollableV())
            {
                float range       = (float)(hoveringNode.LogicalSize.Height - hoveringNode.Size.Height);
                int   slideHeight = (int)((float)rect.Height * (float)(hoveringNode.Size.Height) / (float)(hoveringNode.LogicalSize.Height));
                int   slideOffset = (int)((float)(rect.Height - slideHeight) * (float)hoveringNode.CurrentScrollOffset.Y / range);

                renderer.DrawColor = SceneEdConstants.SlideBarBackground;
                renderer.DrawFilledRect(new Rectangle(rect.Right, rect.Top, thickness, rect.Height));
                renderer.DrawColor = IsScrolling ? SceneEdConstants.SelectionHighlightColor : SceneEdConstants.SlideBarForeground;
                renderer.DrawFilledRect(new Rectangle(rect.Right, rect.Top + slideOffset, thickness, slideHeight));
            }
        }
Пример #6
0
        public Rectangle GetCurrentClip(RenderContext rc)
        {
            GwenRenderContext grc = rc as GwenRenderContext;

            if (grc == null)
            {
                return(ucore.Const.INVALID_RECT);
            }

            return(grc.CurrentOrthoTransform.UntransformClipRegion(grc.Renderer.ClipRegion));
        }
Пример #7
0
        public void Render(GwenRenderContext ctx)
        {
            if (m_targetNode != null)
            {
                Rectangle rect = m_targetNode.GetWorldBounds();
                rect.Inflate(5, 5);

                Color c = ctx.Renderer.DrawColor;
                ctx.Renderer.DrawColor = Color.HotPink;
                ctx.Renderer.DrawLinedRect(rect);
                ctx.Renderer.RenderText(ctx.Font, new Point(rect.Left, rect.Top - 18), "[目标节点] " + m_targetNode.Name);
                ctx.Renderer.DrawColor = c;
            }
        }
Пример #8
0
        public void SetCurrentClip(RenderContext rc, Rectangle clip)
        {
            GwenRenderContext grc = rc as GwenRenderContext;

            if (grc == null)
            {
                return;
            }

            if (clip != ucore.Const.INVALID_RECT)
            {
                grc.Renderer.ClipRegion = grc.CurrentOrthoTransform.TransformClipRegion(clip);
                grc.Renderer.StartClip();
            }
            else
            {
                grc.Renderer.EndClip();
            }
        }
Пример #9
0
        public void RenderNode(Node node, RenderContext rc)
        {
            GwenRenderContext grc = rc as GwenRenderContext;

            if (grc == null)
            {
                return;
            }

            Rectangle worldBounds = node.GetWorldBounds();

            if (node is ImageNode)
            {
                RenderImageNode(node as ImageNode, grc);
            }
            else if (node is TextNode)
            {
                RenderTextNode(node as TextNode, grc);
            }
            else if (node is Button)
            {
                RenderButton(node as Button, grc);
            }
            else if (node is CheckBox)
            {
                RenderCheckBox(node as CheckBox, grc);
            }
            else if (node is ProgressBar)
            {
                RenderProgressBar(node as ProgressBar, grc);
            }
            else if (node is Grid)
            {
                RenderGrid(node as Grid, grc);
            }
            else
            {
                // default method for rendering an unknown node
                grc.Renderer.DrawLinedRect(worldBounds);
            }
        }
Пример #10
0
        private void RenderGrid(Grid g, GwenRenderContext grc)
        {
            Rectangle rect = new Rectangle(grc.GetAccumulatedDockedTranslate(), g.Size);

            grc.Renderer.DrawLinedRect(rect);

            Point loc = grc.GetAccumulatedDockedScrolledTranslate();

            for (int i = 0; i < g.RowCount; i++)
            {
                for (int k = 0; k < g.ColumnCount; k++)
                {
                    Rectangle cellRect = new Rectangle();
                    cellRect.X      = loc.X + i * (g.CellSize.Width + g.CellPadding.Width);
                    cellRect.Y      = loc.Y + k * (g.CellSize.Height + g.CellPadding.Height);
                    cellRect.Width  = g.CellSize.Width;
                    cellRect.Height = g.CellSize.Height;
                    grc.Renderer.DrawLinedRect(cellRect);
                }
            }
        }
Пример #11
0
 private void RenderImageNode(ImageNode imageNode, GwenRenderContext grc)
 {
     DrawImage(grc, new Rectangle(grc.GetAccumulatedDockedScrolledTranslate(), imageNode.Size), imageNode.Res);
 }
Пример #12
0
        private void DrawImage(GwenRenderContext grc, Rectangle rect, string url)
        {
            TextureRenderInfo tri = GwenTextureProvider.Instance.GetTextureRenderInfo(grc.Renderer, url);

            if (tri == null) // 找不到贴图的话,正常的处理应该用一个显眼的错误图案,这里暂时先忽略,待补充
            {
                return;
            }

            // 处理非九宫格图像渲染
            if (tri.uv9Grid == null)
            {
                grc.Renderer.DrawTexturedRect(tri.texture, rect, tri.u1, tri.v1, tri.u2, tri.v2);
                return;
            }

            // 九宫格渲染
            bool hori = tri.uv9Grid.IsHoriStreched();
            bool vert = tri.uv9Grid.IsVertStreched();

            if (hori && vert)
            {
                // ========== 完全九宫格 ===========

                // 先画四个角
                Rectangle upperLeft = rect;
                upperLeft.Width  = tri.uv9Grid.GetLeft(rect.Width);
                upperLeft.Height = tri.uv9Grid.GetTop(rect.Height);
                grc.Renderer.DrawTexturedRect(tri.texture, upperLeft, tri.u1, tri.v1, tri.uv9Grid.uLeft, tri.uv9Grid.vTop);
                Rectangle upperRight = rect;
                upperRight.Width  = tri.uv9Grid.GetRight(rect.Width);
                upperRight.Height = tri.uv9Grid.GetTop(rect.Height);
                upperRight.X      = rect.Right - upperRight.Width;
                grc.Renderer.DrawTexturedRect(tri.texture, upperRight, tri.uv9Grid.uRight, tri.v1, tri.u2, tri.uv9Grid.vTop);

                Rectangle lowerLeft = rect;
                lowerLeft.Width  = tri.uv9Grid.GetLeft(rect.Width);
                lowerLeft.Height = tri.uv9Grid.GetBottom(rect.Height);
                lowerLeft.Y      = rect.Bottom - lowerLeft.Height;
                grc.Renderer.DrawTexturedRect(tri.texture, lowerLeft, tri.u1, tri.uv9Grid.vBottom, tri.uv9Grid.uLeft, tri.v2);
                Rectangle lowerRight = rect;
                lowerRight.Width  = tri.uv9Grid.GetRight(rect.Width);
                lowerRight.Height = tri.uv9Grid.GetBottom(rect.Height);
                lowerRight.X      = rect.Right - lowerRight.Width;
                lowerRight.Y      = rect.Bottom - lowerRight.Height;
                grc.Renderer.DrawTexturedRect(tri.texture, lowerRight, tri.uv9Grid.uRight, tri.uv9Grid.vBottom, tri.u2, tri.v2);

                // 再画四个方向上的拉伸部分
                if (tri.uv9Grid.HasHoriStrechArea(rect.Width))
                {
                    grc.Renderer.DrawTexturedRect(tri.texture,
                                                  new Rectangle(rect.X + upperLeft.Width, rect.Y, rect.Width - upperLeft.Width - upperRight.Width, tri.uv9Grid.GetTop(rect.Height)),
                                                  tri.uv9Grid.uLeft, tri.v1, tri.uv9Grid.uRight, tri.uv9Grid.vTop);
                    grc.Renderer.DrawTexturedRect(tri.texture,
                                                  new Rectangle(rect.X + upperLeft.Width, rect.Bottom - lowerRight.Height, rect.Width - upperLeft.Width - upperRight.Width, lowerRight.Height),
                                                  tri.uv9Grid.uLeft, tri.uv9Grid.vBottom, tri.uv9Grid.uRight, tri.v2);
                }

                if (tri.uv9Grid.HasVertStrechArea(rect.Height))
                {
                    grc.Renderer.DrawTexturedRect(tri.texture,
                                                  new Rectangle(rect.X, rect.Y + upperLeft.Height, upperLeft.Width, rect.Height - upperLeft.Height - lowerLeft.Height),
                                                  tri.u1, tri.uv9Grid.vTop, tri.uv9Grid.uLeft, tri.uv9Grid.vBottom);
                    grc.Renderer.DrawTexturedRect(tri.texture,
                                                  new Rectangle(rect.Right - lowerRight.Width, rect.Y + upperLeft.Height, lowerRight.Width, rect.Height - upperRight.Height - lowerRight.Height),
                                                  tri.uv9Grid.uRight, tri.uv9Grid.vTop, tri.u2, tri.uv9Grid.vBottom);
                }

                // 最后画中央区域拉伸部分
                if (tri.uv9Grid.HasHoriStrechArea(rect.Width) && tri.uv9Grid.HasVertStrechArea(rect.Height))
                {
                    grc.Renderer.DrawTexturedRect(tri.texture,
                                                  new Rectangle(rect.X + upperLeft.Width,
                                                                rect.Y + upperLeft.Height,
                                                                rect.Width - upperLeft.Width - upperRight.Width,
                                                                rect.Height - upperRight.Height - lowerRight.Height),
                                                  tri.uv9Grid.uLeft, tri.uv9Grid.vTop, tri.uv9Grid.uRight, tri.uv9Grid.vBottom);
                }
            }
            else if (hori)
            {
                // ========== 横向九宫格 ===========

                // 先画左右两端
                Rectangle leftPart = rect;
                leftPart.Width = tri.uv9Grid.GetLeft(rect.Width);
                grc.Renderer.DrawTexturedRect(tri.texture, leftPart, tri.u1, tri.v1, tri.uv9Grid.uLeft, tri.v2);
                Rectangle rightPart = rect;
                rightPart.Width = tri.uv9Grid.GetRight(rect.Width);
                rightPart.X     = rect.Right - rightPart.Width;
                grc.Renderer.DrawTexturedRect(tri.texture, rightPart, tri.uv9Grid.uRight, tri.v1, tri.u2, tri.v2);

                // 再画中间拉伸部分
                if (tri.uv9Grid.HasHoriStrechArea(rect.Width))
                {
                    Rectangle middlePart = rect;
                    middlePart.Width = rect.Width - leftPart.Width - rightPart.Width;
                    middlePart.X     = rect.X + leftPart.Width;
                    grc.Renderer.DrawTexturedRect(tri.texture, middlePart, tri.uv9Grid.uLeft, tri.v1, tri.uv9Grid.uRight, tri.v2);
                }
            }
            else if (vert)
            {
                // ========== 纵向九宫格 ===========

                // 先画上下两端
                Rectangle topPart = rect;
                topPart.Height = tri.uv9Grid.GetTop(rect.Height);
                grc.Renderer.DrawTexturedRect(tri.texture, topPart, tri.u1, tri.v1, tri.u2, tri.uv9Grid.vTop);
                Rectangle bottomPart = rect;
                bottomPart.Height = tri.uv9Grid.GetBottom(rect.Height);
                bottomPart.Y      = rect.Bottom - bottomPart.Height;
                grc.Renderer.DrawTexturedRect(tri.texture, bottomPart, tri.u1, tri.uv9Grid.vBottom, tri.u2, tri.v2);

                // 再画中间拉伸部分
                if (tri.uv9Grid.HasVertStrechArea(rect.Height))
                {
                    Rectangle middlePart = rect;
                    middlePart.Height = rect.Height - topPart.Height - bottomPart.Height;
                    middlePart.Y      = rect.Y + topPart.Height;
                    grc.Renderer.DrawTexturedRect(tri.texture, middlePart, tri.u1, tri.uv9Grid.vTop, tri.u2, tri.uv9Grid.vBottom);
                }
            }
        }
Пример #13
0
        private void RenderProgressBar(ProgressBar pb, GwenRenderContext grc)
        {
            Rectangle rect = new Rectangle(grc.GetAccumulatedDockedScrolledTranslate(), pb.Size);

            DrawImage(grc, rect, pb.Res_Progress);
        }
Пример #14
0
 private void RenderButton(Button bt, GwenRenderContext grc)
 {
     DrawImage(grc, new Rectangle(grc.GetAccumulatedDockedScrolledTranslate(), bt.Size), bt.Res_Current);
 }
Пример #15
0
 public void Render(GwenRenderContext ctx)
 {
     // 把渲染细节移动到以 _Render 为后缀的一份单独的代码文件
     RenderInternal(ctx);
 }