Exemplo n.º 1
0
        public SizeF Print(QFont font, string text, Vector3 position, SizeF maxSize, QFontAlignment alignment, Rectangle clippingRectangle = default(Rectangle))
        {
            var dp = new QFontDrawingPimitive(font);

            _glFontDrawingPimitives.Add(dp);
            return(dp.Print(text, position, maxSize, alignment, clippingRectangle));
        }
Exemplo n.º 2
0
        public SizeF Print(QFont font, string text, Vector3 position, SizeF maxSize, QFontAlignment alignment, QFontRenderOptions opt)
        {
            var dp = new QFontDrawingPimitive(font, opt);

            _glFontDrawingPimitives.Add(dp);
            return(dp.Print(text, position, maxSize, alignment, opt.ClippingRectangle));
        }
Exemplo n.º 3
0
        public SizeF Print(QFont font, ProcessedText text, Vector3 position, QFontRenderOptions opt)
        {
            var dp = new QFontDrawingPimitive(font, opt);

            _glFontDrawingPimitives.Add(dp);
            return(dp.Print(text, position, opt.ClippingRectangle));
        }
Exemplo n.º 4
0
        public SizeF Print(QFont font, ProcessedText processedText, Vector3 position, Color?colour = null, Rectangle clippingRectangle = default(Rectangle))
        {
            var dp   = new QFontDrawingPimitive(font);
            var size = (colour.HasValue)
                    ? dp.Print(processedText, position, colour.Value)
                    : dp.Print(processedText, position);

            _glFontDrawingPimitives.Add(dp);
            return(size);
        }
Exemplo n.º 5
0
        public SizeF Print(QFont font, string text, Vector3 position, QFontAlignment alignment, Color?color = null, Rectangle clippingRectangle = default(Rectangle))
        {
            var dp = new QFontDrawingPimitive(font);

            _glFontDrawingPimitives.Add(dp);
            if (color.HasValue)
            {
                return(dp.Print(text, position, alignment, color.Value, clippingRectangle));
            }
            return(dp.Print(text, position, alignment, clippingRectangle));
        }
Exemplo n.º 6
0
        public SizeF Print(QFont font, ProcessedText processedText, Vector3 position, Color?colour = null, Rectangle clippingRectangle = default(Rectangle))
        {
            var dp = new QFontDrawingPimitive(font);

            DrawingPimitiveses.Add(dp);
            if (colour.HasValue)
            {
                return(dp.Print(processedText, position, colour.Value));
            }
            else
            {
                return(dp.Print(processedText, position));
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Measures the specified text. Helper method delegating functionality.
 /// </summary>
 /// <param name="text">The text.</param>
 /// <param name="alignment">The alignment.</param>
 /// <returns>
 /// Measured size.
 /// </returns>
 public SizeF Measure(string text, QFontAlignment alignment = QFontAlignment.Left)
 {
     var test = new QFontDrawingPimitive(this);
     return test.Measure(text, alignment);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Measures the specified text. Helper method delegating functionality.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="maxWidth">The maximum width.</param>
        /// <param name="alignment">The alignment.</param>
        /// <returns>
        /// Measured size.
        /// </returns>
        public SizeF Measure(string text, float maxWidth, QFontAlignment alignment)
        {
            var test = new QFontDrawingPimitive(this);

            return(test.Measure(text, maxWidth, alignment));
        }
Exemplo n.º 9
0
 /// <summary>
 /// Measures the specified text. Helper method delegating functionality.
 /// </summary>
 /// <param name="text">The text.</param>
 /// <param name="maxWidth">The maximum width.</param>
 /// <param name="alignment">The alignment.</param>
 /// <returns>
 /// Measured size.
 /// </returns>
 public SizeF Measure(string text, float maxWidth, QFontAlignment alignment)
 {
     var test = new QFontDrawingPimitive(this);
     return test.Measure(text, maxWidth, alignment);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Measures the specified text. Helper method delegating functionality.
 /// </summary>
 /// <param name="processedText">The processed text.</param>
 /// <returns>
 /// Measured size.
 /// </returns>
 public SizeF Measure(ProcessedText processedText)
 {
     var test = new QFontDrawingPimitive(this);
     return test.Measure(processedText);
 }
Exemplo n.º 11
0
        private void PrintWithBounds(QFont font, string text, RectangleF bounds, QFontAlignment alignment, ref float yOffset)
        {
            float maxWidth = bounds.Width;

            float height = font.Measure(text, new SizeF(maxWidth, -1), alignment).Height;

            //gl.begin(beginmode.lineloop);
            //gl.vertex3(bounds.x, bounds.y, 0f);
            //gl.vertex3(bounds.x + bounds.width, bounds.y, 0f);
            //gl.vertex3(bounds.x + bounds.width, bounds.y + height, 0f);
            //gl.vertex3(bounds.x, bounds.y + height, 0f);
            //gl.end();

            var dp = new QFontDrawingPimitive(font);
            dp.Print(text, new Vector3(bounds.X, Height - yOffset, 0), new SizeF(maxWidth, float.MaxValue), alignment);
            drawing.DrawingPimitiveses.Add(dp);

            yOffset += height;
        }
Exemplo n.º 12
0
        private void PrintCommentWithLine(QFont font, string comment, QFontAlignment alignment, float xOffset, ref float yOffset, QFontRenderOptions opts)
        {
            yOffset += 20;
            var dp = new QFontDrawingPimitive(font, opts);
            //if (doSpacing)
            //    dp.Options.CharacterSpacing = 0.05f;
            dp.Print(comment, new Vector3(xOffset, Height - yOffset, 0f), new SizeF(Width - 60, -1), alignment);
            drawing.DrawingPimitiveses.Add(dp);
            var bounds = font.Measure(comment, new SizeF(Width - 60, float.MaxValue), alignment);

            //GL.Disable(EnableCap.Texture2D);
            //GL.Begin(BeginMode.Lines);
            //GL.Color4(1.0f, 0f, 0f, 1f); GL.Vertex2(0f, 0f);
            //GL.Color4(1.0f, 0f, 0f, 1f); GL.Vertex2(0f, bounds.Height + 20f);
            //GL.End();

            yOffset += bounds.Height;
        }
Exemplo n.º 13
0
 public SizeF Print(QFont font, ProcessedText processedText, Vector3 position, Color? colour = null, Rectangle clippingRectangle = default(Rectangle))
 {
     var dp = new QFontDrawingPimitive(font);
     DrawingPimitiveses.Add(dp);
     if (colour.HasValue)
         return dp.Print(processedText, position, colour.Value);
     else
         return dp.Print(processedText, position);
 }
Exemplo n.º 14
0
 public SizeF Print(QFont font, ProcessedText text, Vector3 position, QFontRenderOptions opt)
 {
     var dp = new QFontDrawingPimitive(font, opt);
     DrawingPimitiveses.Add(dp);
     return dp.Print(text, position, opt.ClippingRectangle);
 }
Exemplo n.º 15
0
 private void PrintComment(QFont font, string comment, QFontAlignment alignment, ref float yOffset, QFontRenderOptions opts )
 {
     yOffset += 20;
     var pos = new Vector3(30f, Height - yOffset, 0f);
     var dp = new QFontDrawingPimitive(font, opts ?? new QFontRenderOptions());
     dp.Print(comment, pos, new SizeF(Width - 60, -1), alignment);
     yOffset += dp.Measure(comment, new SizeF(Width - 60, -1), alignment).Height;
     drawing.DrawingPimitiveses.Add(dp);
 }
Exemplo n.º 16
0
        /// <summary>
        /// Measures the specified text. Helper method delegating functionality.
        /// </summary>
        /// <param name="processedText">The processed text.</param>
        /// <returns>
        /// Measured size.
        /// </returns>
        public SizeF Measure(ProcessedText processedText)
        {
            var test = new QFontDrawingPimitive(this);

            return(test.Measure(processedText));
        }
Exemplo n.º 17
0
 public SizeF Print(QFont font, string text, Vector3 position, SizeF maxSize, QFontAlignment alignment, QFontRenderOptions opt )
 {
     var dp = new QFontDrawingPimitive(font, opt);
     DrawingPimitiveses.Add(dp);
     return dp.Print(text, position, maxSize, alignment, opt.ClippingRectangle);
 }
Exemplo n.º 18
0
 public SizeF Print(QFont font, string text, Vector3 position, SizeF maxSize, QFontAlignment alignment, Rectangle clippingRectangle = default(Rectangle))
 {
     var dp = new QFontDrawingPimitive(font);
     DrawingPimitiveses.Add(dp);
     return dp.Print(text, position, maxSize, alignment, clippingRectangle);
 }
Exemplo n.º 19
0
 public SizeF Print(QFont font, string text, Vector3 position, QFontAlignment alignment, Color? color = null, Rectangle clippingRectangle = default(Rectangle))
 {
     var dp = new QFontDrawingPimitive(font);
     DrawingPimitiveses.Add(dp);
     if( color.HasValue )
         return dp.Print(text, position, alignment, color.Value, clippingRectangle);
     return dp.Print(text, position, alignment, clippingRectangle);
 }
Exemplo n.º 20
0
        /// <summary>
        /// Measures the specified text. Helper method delegating functionality.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="alignment">The alignment.</param>
        /// <returns>
        /// Measured size.
        /// </returns>
        public SizeF Measure(string text, QFontAlignment alignment = QFontAlignment.Left)
        {
            var test = new QFontDrawingPimitive(this);

            return(test.Measure(text, alignment));
        }
Exemplo n.º 21
0
        /// <summary>
        /// Called when it is time to render the next frame. Add your rendering code here.
        /// </summary>
        /// <param name="e">Contains timing information.</param>
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            drawing.ProjectionMatrix = _projectionMatrix;

            frameCount++;

            float yOffset = 0;

            //mainText.Begin();
            //GL.Begin(BeginMode.Quads);

            //GL.Color3(1.0f, 1.0f, 1.0); GL.Vertex2(0, 0);
            //GL.Color3(0.9f, 0.9f, 0.9f); GL.Vertex2(0, Height);
            //GL.Color3(0.9f, 0.9f, 0.9f); GL.Vertex2(Width, Height);
            //GL.Color3(0.9f, 0.9f, 0.9f); GL.Vertex2(Width, 0);

            //GL.End();
            //mainText.End();
            if (currentDemoPage != _previousPage)
            {
                _previousPage = currentDemoPage;
                // we have to rebuild the stuff
                drawing.DrawingPimitiveses.Clear();

                switch (currentDemoPage)
                {
                    case 0:
                        {
                            yOffset += drawing.Print(heading1, "ModernQuickFont",
                                                                     new Vector3((float) Width/2, Height, 0),
                                                                     QFontAlignment.Centre, heading1Options).Height;

                            yOffset += drawing.Print(heading2, "Introduction #0",
                                                                     new Vector3(20, Height - yOffset, 0),
                                                                     QFontAlignment.Left, heading2Options)
                                        .Height;

                            yOffset += drawing.Print(mainText, modernQuickFontIntro, new Vector3(30, Height - yOffset, 0),
                                                                 new SizeF(Width - 60f, -1), QFontAlignment.Justify).Height;

                            PrintCode(modernIntroCode, ref yOffset);
                            break;
                        }

                    case 1:
                        {
                            yOffset += drawing.Print(heading1, "QuickFont",
                                                                     new Vector3((float) Width/2, Height, 0),
                                                                     QFontAlignment.Centre, heading1Options).Height;

                            yOffset += drawing.Print(heading2, "Introduction",
                                                                     new Vector3(20, Height - yOffset, 0),
                                                                     QFontAlignment.Left, heading2Options)
                                        .Height;

                            yOffset += 20f;
                            drawing.Print(mainText, introduction, new Vector3(30, Height - yOffset, 0),
                                                                 new SizeF(Width - 60f, -1), QFontAlignment.Justify);

                            break;
                        }

                    case 2:
                        {
                            yOffset += drawing.Print( heading2, "Easy as ABC!",
                                                                     new Vector3(20f, Height - yOffset, 0f),
                                                                     QFontAlignment.Left, heading2Options).Height;

                            PrintComment(usingQuickFontIsSuperEasy, ref yOffset);
                            PrintCode(loadingAFont1, ref yOffset);

                            PrintComment(andPrintWithIt, ref yOffset);
                            PrintCode(printWithFont1, ref yOffset);

                            PrintComment(itIsAlsoEasyToMeasure, ref yOffset);
                            PrintCode(measureText1, ref yOffset);

                            PrintComment(oneOfTheFirstGotchas, ref yOffset);
                            PrintCode(loadingAFont2, ref yOffset);

                            break;
                        }

                    case 3:
                        {
                            yOffset +=  drawing.Print(heading2 ,"Alignment", new Vector3(20f, Height - yOffset, 0f),
                                                                     QFontAlignment.Left, heading2Options).Height;

                            PrintCommentWithLine(whenPrintingText, QFontAlignment.Left, 20f, ref yOffset);
                            PrintCode(printWithFont2, ref yOffset);

                            PrintCommentWithLine(righAlignedText, QFontAlignment.Right, 20f, ref yOffset);
                            yOffset += 10f;

                            PrintCommentWithLine(centredTextAsYou, QFontAlignment.Centre, Width*0.5f, ref yOffset);

                            break;
                        }

                    case 4:
                        {
                            // in this stage force redraw and recreation of VBO every time: just divert last page
                            _previousPage = -1;
                            yOffset += drawing.Print(heading2, "Bounds and Justify",
                                                                     new Vector3(20f, Height - yOffset, 0f),
                                                                     QFontAlignment.Left, heading2Options).Height;

                            yOffset += 20;
                            yOffset +=  drawing.Print( controlsText, "Press [Up], [Down] or [Enter]!",
                                                                         new Vector3(Width*0.5f, Height - yOffset, 0f),
                                                                         QFontAlignment.Centre, controlsTextOpts).Height;

                            float boundShrink = (int) (350*(1 - Math.Cos(boundsAnimationCnt*Math.PI*2)));

                            yOffset += 15;
                            PrintWithBounds(mainText, ofCourseItsNot,
                                            new RectangleF(30f + boundShrink*0.5f, yOffset, Width - 60 - boundShrink,
                                                           350f), cycleAlignment, ref yOffset);

                            string printWithBounds = "myFont.Print(text, position, maxSize, QFontAlignment." +
                                                     cycleAlignment + ");";
                            yOffset += 15f;
                            PrintCode(printWithBounds, ref yOffset);

                            break;
                        }

                    case 5:
                        {
                            yOffset +=  drawing.Print(heading2, "Your own Texture Fonts",
                                                                     new Vector3(20f, Height - yOffset, 0f),
                                                                     QFontAlignment.Left, heading2Options).Height;

                            PrintComment(anotherCoolFeature, ref yOffset);
                            PrintCode(textureFontCode1, ref yOffset);
                            PrintComment(thisWillHaveCreated, ref yOffset);

                            break;
                        }

                    case 6:
                        {
                            yOffset +=  drawing.Print(heading2, "Your own Texture Fonts",
                                                                     new Vector3(20f, Height - yOffset, 0f),
                                                                     QFontAlignment.Left, heading2Options).Height;

                            PrintComment(ifYouDoIntend, ref yOffset);
                            PrintCode(textureFontCode2, ref yOffset);
                            PrintComment(actuallyTexturing, ref yOffset);
                            PrintCode(textureFontCode3, ref yOffset);

                            break;
                        }

                    case 7:
                        {
                            // in this stage force redraw and recreation of VBO every time: just divert last page
                            _previousPage = -1;

                            // store this primitive to remember
                            QFontDrawingPimitive dp = new QFontDrawingPimitive(heading2);
                            dp.Options.DropShadowActive = true;
                            dp.Options.DropShadowOffset = new Vector2(0.1f + 0.2f*(float) Math.Sin(cnt),
                                                                            0.1f + 0.2f*(float) Math.Cos(cnt));

                            yOffset += dp.Print("Drop Shadows",
                                                                     new Vector3(20f, Height - yOffset, 0f),
                                                                     QFontAlignment.Left).Height;
                            drawing.DrawingPimitiveses.Add(dp);

                            PrintComment(asIhaveleant, ref yOffset);
                            PrintCode(dropShadowCode1, ref yOffset);
                            PrintComment(thisWorksFine, ref yOffset);
                            PrintCode(dropShadowCode2, ref yOffset);
                            PrintComment(onceAFont, ref yOffset);

                            //mainText.Options.DropShadowActive = false;
                            break;
                        }

                    case 8:
                        {
                            yOffset += drawing.Print(heading2, "Monospaced Fonts",
                                                                     new Vector3(20f, Height - yOffset, 0f),
                                                                     QFontAlignment.Left, heading2Options).Height;

                            QFontRenderOptions monoSpaceCondensed = monoSpacedOptions.CreateClone();
                            monoSpaceCondensed.CharacterSpacing = 0.05f;
                            PrintComment(monoSpaced, hereIsSomeMono, QFontAlignment.Left, ref yOffset, monoSpaceCondensed);
                            PrintCode(monoCode1, ref yOffset);
                            PrintComment(monoSpaced, theDefaultMono, QFontAlignment.Left, ref yOffset, monoSpaceCondensed);

                            PrintCommentWithLine(monoSpaced, mono, QFontAlignment.Left, 20f, ref yOffset, monoSpaceCondensed);
                            yOffset += 2f;
                            PrintCommentWithLine(monoSpaced, mono, QFontAlignment.Right, 20f, ref yOffset, monoSpaceCondensed);
                            yOffset += 2f;
                            PrintCommentWithLine(monoSpaced, mono, QFontAlignment.Centre, Width * 0.5f, ref yOffset, monoSpaceCondensed);
                            yOffset += 2f;

                            PrintComment(monoSpaced,
                                         "As usual, you can adjust character spacing with myPrimitive.Options.CharacterSpacing.",
                                         QFontAlignment.Left, ref yOffset, monoSpaceCondensed);

                            break;
                        }

                    case 9:
                        {
                            // in this stage force redraw and recreation of VBO every time: just divert last page
                            _previousPage = -1;
                            yOffset += drawing.Print(heading2, "Preprocessed Text",
                                                                     new Vector3(20f, Height - yOffset, 0f),
                                                                     QFontAlignment.Left).Height;
                            yOffset += 20f;

                            _stopwatch = Stopwatch.StartNew();
                            yOffset +=  drawing.Print(mainText, _processedText,
                                                                     new Vector3(20, Height - yOffset, 0)).Height;
                            _stopwatch.Stop();
                            long preprocessed = _stopwatch.Elapsed.Ticks;

                            _stopwatch = Stopwatch.StartNew();
                            yOffset += drawing.Print( mainText,nonPreProcessed,
                                                                     new Vector3(20, Height - yOffset, 0),
                                                                     new SizeF(Width - 40f, -1), QFontAlignment.Justify)
                                        .Height;
                            _stopwatch.Stop();
                            long notpreprocessed = _stopwatch.Elapsed.Ticks;

                            if (frameCount > 60)
                            {
                                _benchResult = string.Format(("{0}       {1}\nPreprocessed was {2} ticks faster"),
                                                             preprocessed,
                                                             notpreprocessed, notpreprocessed - preprocessed);
                                frameCount = 0;
                            }

                            drawing.Print(_benchmarkResults, _benchResult,
                                                                          new Vector3(Width*0.5f, Height - yOffset, 0),
                                                                          QFontAlignment.Centre, Color.White);
                            break;
                        }

                    case 10:
                        {
                            yOffset += drawing.Print(heading2, "In Conclusion",
                                                                     new Vector3(20f, Height - yOffset, 0f),
                                                                     QFontAlignment.Left, heading2Options).Height;

                            PrintComment(thereAreActually, ref yOffset);

                            break;
                        }
                }

                drawing.RefreshBuffers();

            }

            // Create controlsDrawing every time.. would be also good to vary ProjectionMatrix with * Matrix4.CreateTranslation() !
            // this would save buffer work for OpenGL
            controlsDrawing.DrawingPimitiveses.Clear();
            controlsDrawing.ProjectionMatrix = _projectionMatrix;

            if (currentDemoPage != lastPage)
            {
                Vector3 pos = new Vector3(Width - 10 - 16 * (float)(1 + Math.Sin(cnt * 4)),
                    controlsText.Measure("P").Height + 10f, 0f);
                controlsDrawing.Print(controlsText, "Press [Right] ->", pos, QFontAlignment.Right, controlsTextOpts);
            }

            if (currentDemoPage != 0)
            {
                var pos = new Vector3(10 + 16*(float) (1 + Math.Sin(cnt*4)), controlsText.Measure("P").Height + 10f, 0f);
                controlsDrawing.Print(controlsText, "<- Press [Left]", pos, QFontAlignment.Left, controlsTextOpts);
            }
            controlsDrawing.RefreshBuffers();
            controlsDrawing.Draw();

            drawing.Draw();
            SwapBuffers();
        }