Example #1
0
        /// <summary>
        /// Renders the flattened path to the device using the specified color.
        /// </summary>
        /// <param name="device">The device to use for rendering the path.</param>
        /// <param name="color">The color to use for the vertices.</param>
        /// <param name="flattenedPath">The path to render.</param>
        protected virtual void Render(Device device, int color, GraphicsPath flattenedPath)
        {
            PointF[] points = flattenedPath.PathPoints;
            device.VertexFormat = CustomVertex.PositionColored.Format;

            bool isClosed;
            GraphicsPathIterator pi = new GraphicsPathIterator(flattenedPath);

            while (pi.NextSubpath(flattenedPath, out isClosed) != 0)
            {
                byte type;
                int  start, end;

                while (pi.NextPathType(out type, out start, out end) != 0)
                {
                    int numDistinctPoints = end - start + 1;
                    int totNumPoints      = numDistinctPoints;
                    if (isClosed)
                    {
                        totNumPoints++;
                    }

                    CustomVertex.PositionColored[] colVerts = new CustomVertex.PositionColored[totNumPoints];
                    P3Util.CreateColoredVertexList(colVerts, points, start, 0, numDistinctPoints, color);

                    if (isClosed)
                    {
                        colVerts[numDistinctPoints] = colVerts[0];
                    }

                    device.DrawUserPrimitives(PrimitiveType.LineStrip, totNumPoints - 1, colVerts);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Renders the list of primitives to the device.
        /// </summary>
        /// <param name="device">The device to use for rendering the primitives.</param>
        /// <param name="renderList">The list of primitives to render.</param>
        protected virtual void Render(Device device, ArrayList renderList)
        {
            PointF[] points = (PointF[])renderList.ToArray(typeof(PointF));
            device.VertexFormat = CustomVertex.PositionColored.Format;

            for (int i = 0; i < renderListTypes.Count; i++)
            {
                PrimitiveTypeInfo pti = (PrimitiveTypeInfo)renderListTypes[i];
                int numVerts          = (pti.End - pti.Start + 1);

                CustomVertex.PositionColored[] colVerts = new CustomVertex.PositionColored[numVerts];
                P3Util.CreateColoredVertexList(colVerts, points, pti.Start, 0, numVerts, pti.Color);

                switch (pti.Type)
                {
                case PrimitiveType.TriangleFan:
                    device.DrawUserPrimitives(PrimitiveType.TriangleFan, colVerts.Length - 2, colVerts);
                    break;

                case PrimitiveType.TriangleList:
                    device.DrawUserPrimitives(PrimitiveType.TriangleList, colVerts.Length / 3, colVerts);
                    break;

                case PrimitiveType.TriangleStrip:
                    device.DrawUserPrimitives(PrimitiveType.TriangleStrip, colVerts.Length - 2, colVerts);
                    break;
                }
            }
        }
Example #3
0
        /// <summary>
        /// Overridden.  See <see cref="PCamera.PaintDebugFullBounds">PaintDebugFullBounds</see>.
        /// </summary>
        protected override void PaintDebugFullBounds(PPaintContext paintContext, Brush fullBoundsBrush, RectangleF nodeBounds)
        {
            Device device = (paintContext as P3PaintContext).Device;

            CustomVertex.PositionColored[] colVerts = new CustomVertex.PositionColored[VERTEX_COUNT];
            P3Util.CreateColoredRectangle(colVerts, 0, nodeBounds, (fullBoundsBrush as SolidBrush).Color.ToArgb());
            device.VertexFormat = CustomVertex.PositionColored.Format;
            device.DrawUserPrimitives(PrimitiveType.TriangleList, 2, colVerts);
        }
Example #4
0
        /// <summary>
        /// Overridden.  See <see cref="PCamera.PaintDebugBounds">PCamera.PaintDebugBounds</see>.
        /// </summary>
        protected override void PaintDebugBounds(PPaintContext paintContext, Pen boundsPen, RectangleF nodeBounds)
        {
            Device device = (paintContext as P3PaintContext).Device;

            CustomVertex.PositionColored[] colVerts = new CustomVertex.PositionColored[VERTEX_COUNT];
            P3Util.CreateColoredRectangleOutline(colVerts, 0, nodeBounds, boundsPen.Color.ToArgb());
            device.VertexFormat = CustomVertex.PositionColored.Format;
            device.DrawUserPrimitives(PrimitiveType.LineStrip, 4, colVerts);
        }
Example #5
0
        /// <summary>
        /// Overridden.  See <see cref="P3Node.FillVertexBuffer">P3Node.FillVertexBuffer</see>.
        /// </summary>
        protected override void FillVertexBuffer(VertexBuffer vb)
        {
            GraphicsStream stm = vb.Lock(0, 0, 0);

            CustomVertex.PositionNormalTextured[] texVerts = new CustomVertex.PositionNormalTextured[VERTEX_COUNT];
            P3Util.CreateTexturedRectangle(texVerts, 0, Bounds);
            stm.Write(texVerts);
            vb.Unlock();
        }
Example #6
0
 /// <summary>
 /// Override this method to fill the vertex buffer with the appropriate data.  Most nodes
 /// that extend P3Node will need to override this method since their number and type of
 /// vertices will vary.
 /// </summary>
 /// <remarks>
 /// It is not safe to call GetValidVertexBuffer() here, since that method may call
 /// FillVertexBuffer().
 /// </remarks>
 /// <param name="vb">The vertex buffer to fill.</param>
 protected virtual void FillVertexBuffer(VertexBuffer vb)
 {
     if (Brush != null)
     {
         GraphicsStream stm = vb.Lock(0, 0, 0);
         CustomVertex.PositionColored[] colVerts = new CustomVertex.PositionColored[VERTEX_COUNT];
         P3Util.CreateColoredRectangle(colVerts, 0, Bounds, (Brush as SolidBrush).Color.ToArgb());
         stm.Write(colVerts);
         vb.Unlock();
     }
 }
Example #7
0
        /// <summary>
        /// Overridden.  See <see cref="P3Node.FillVertexBuffer">P3Node.FillVertexBuffer</see>.
        /// </summary>
        protected override void FillVertexBuffer(VertexBuffer vb)
        {
            GraphicsStream stm = vb.Lock(0, 0, 0);

            CustomVertex.PositionColored[] colVerts = new CustomVertex.PositionColored[renderList.Count];

            PointF[] points = (PointF[])renderList.ToArray(typeof(PointF));
            foreach (PrimitiveTypeInfo pti in renderListTypes)
            {
                P3Util.CreateColoredVertexList(colVerts, points, pti.Start, pti.Start, pti.End - pti.Start + 1, pti.Color);
            }

            stm.Write(colVerts);
            vb.Unlock();
        }
Example #8
0
        /// <summary>
        /// Override this method to change the way bounds are computed. For example
        /// this is where you can control how lines are wrapped.
        /// </summary>
        public virtual void RecomputeBounds()
        {
            if (text != null && (ConstrainWidthToTextWidth || ConstrainHeightToTextHeight))
            {
                currLeftPadding = currRightPadding = currTopPadding = currBottomPadding = 0;

                // Calculate the padding values in display units
                float scaleFactor = displayFontSize / DEFAULT_FONT_SIZE;
                currLeftPadding   = (int)(scaleFactor * LEFT_PADDING);
                currRightPadding  = (int)(scaleFactor * RIGHT_PADDING);
                currTopPadding    = (int)(scaleFactor * TOP_PADDING);
                currBottomPadding = (int)(scaleFactor * BOTTOM_PADDING);

                // Set the scale factor relative to the current font size
                scaleFactor = displayFontSize / Font.Size;

                float textWidth;
                float textHeight;
                if (ConstrainWidthToTextWidth)
                {
                    Rectangle rect = measureFont.MeasureString(null, Text, DrawTextFormat.None, (textBrush as SolidBrush).Color);
                    textWidth  = rect.Width * scaleFactor + currLeftPadding + currRightPadding;
                    textHeight = rect.Height * scaleFactor + currTopPadding + currBottomPadding;
                }
                else
                {
                    textWidth = Width;
                    int   scaledWidth  = (int)((textWidth - (currLeftPadding + currRightPadding)) * (1 / scaleFactor));
                    float scaledHeight = P3Util.MeasureString(measureFont, null, Text, scaledWidth, (textBrush as SolidBrush).Color).Height;
                    textHeight = scaledHeight * scaleFactor + currTopPadding + currBottomPadding;;
                }

                float newWidth  = Width;
                float newHeight = Height;
                if (ConstrainWidthToTextWidth)
                {
                    newWidth = textWidth;
                }
                if (ConstrainHeightToTextHeight)
                {
                    newHeight = textHeight;
                }

                base.SetBounds(X, Y, newWidth, newHeight);
            }
        }
Example #9
0
        //****************************************************************
        // Painting - Methods for painting a PText.
        //****************************************************************

        /// <summary>
        /// Overridden.  See <see cref="PNode.Paint">PNode.Paint</see>.
        /// </summary>
        protected override void Paint(UMD.HCIL.Piccolo.Util.PPaintContext paintContext)
        {
            base.Paint(paintContext);
            Device device = (paintContext as P3PaintContext).Device;

            PMatrix currMatrix = (paintContext as P3PaintContext).Transform;

            // Scale the matrix down to display font units
            float scale = displayFontSize / font.Size;

            currMatrix.ScaleBy(scale, X, Y);

            float[] piccoloMatrixElements = currMatrix.Elements;
            if (!currMatrix.IsIdentity)
            {
                Matrix m = new Matrix();
                m.M11 = piccoloMatrixElements[0];
                m.M12 = piccoloMatrixElements[1];
                m.M21 = piccoloMatrixElements[2];
                m.M22 = piccoloMatrixElements[3];
                m.M41 = piccoloMatrixElements[4];
                m.M42 = piccoloMatrixElements[5];
                m.M33 = 1;
                m.M44 = 1;
                textSprite.Transform = m;
            }

            textSprite.Begin(SpriteFlags.None);
            DrawTextFormat D3DAlignment = P3Util.GetD3DAlignment(stringFormat.Alignment);

            // Calculate the rectangle with no padding, in actual font units
            scale = 1 / scale;
            int totHzPadding = currLeftPadding + currRightPadding;
            int totVtPadding = currTopPadding + currBottomPadding;

            Rectangle dstRect = new Rectangle((int)(Bounds.X + currLeftPadding * scale), (int)(Bounds.Y + currTopPadding * scale),
                                              (int)((Bounds.Width - totHzPadding) * scale), (int)((Bounds.Height - totVtPadding) * scale));

            // Wrap the string ourselves, instead of letting the draw method do it, since we want to make
            // sure it's consistent with our own MeasureString method.
            String str = P3Util.WrapString(textSprite, D3Dfont, Text, dstRect.Width, (TextBrush as SolidBrush).Color);

            D3Dfont.DrawText(textSprite, str, dstRect, D3DAlignment, (TextBrush as SolidBrush).Color);
            textSprite.End();
        }
Example #10
0
        /// <summary>
        /// Implements <see cref="UMD.HCIL.PiccoloDirect3D.Util.TesselationVisitor.TessBegin">
        /// TesselationVisitor.TessBegin</see>.
        /// </summary>
        public virtual void TessBegin(P3Util.GlPrimitiveType which)
        {
            PrimitiveType type = P3Util.GetD3DPrimitiveType(which);

            this.renderListTypes.Add(new PrimitiveTypeInfo(renderList.Count, renderList.Count - 1, currentTesselationColor, type));
        }
Example #11
0
 /// <summary>
 /// Overridden.  Creates a PiccoloDirect3D scene graph.
 /// </summary>
 /// <returns>The main camera node in the new scene graph.</returns>
 protected override PCamera CreateBasicScenegraph()
 {
     return(P3Util.CreateBasicScenegraph());
 }