Beispiel #1
0
 public QFontDrawingPrimitive this[PrintedTextKey key]
 {
     get
     {
         CacheValueContainer value;
         if (_levelTwoCache.ContainsKey(key))
         {
             value = _levelTwoCache[key];
         }
         else
         {
             value         = _levelOneCache[key];
             value.Health += LevelOneHealthIncrease;
         }
         return(value.DrawingPrimitive);
     }
     set
     {
         if (_levelTwoCache.ContainsKey(key))
         {
             _levelTwoCache[key].DrawingPrimitive = value;
         }
         else if (_levelOneCache.ContainsKey(key))
         {
             _levelOneCache[key].DrawingPrimitive = value;
         }
         else
         {
             _levelOneCache.Add(key, new CacheValueContainer {
                 DrawingPrimitive = value, Health = LevelOneStartHealth
             });
         }
     }
 }
        public override void InvalidateCachedText(PrintedTextKey key)
        {
            var tp = Translate(key.Position);

            // flip y coordinate for QuickFont
            tp.Y         = -tp.Y;
            key.Position = tp;

            m_StringCache.Remove(key);
        }
        public override void RenderText(Font font, Point position, TextContainer textContainer)
        {
            //Debug.Print(String.Format("RenderText {0}", font.FaceName));

            // The DrawString(...) below will bind a new texture
            // so make sure everything is rendered!

            var tp = Translate(position);

            //perform broad phase clipping
            if (tp.Y > ClipRegion.Y + ClipRegion.Height || (tp.Y + font.RealSize * (textContainer.LineCount + 1) < ClipRegion.Y))
            {
                return;
            }


            //All text currently drawn in separate call, don't need to flush atm
            Flush();
            m_FontDrawing.DrawingPrimitives.Clear();

            QFont sysQFont = font.RendererData as QFont;

            if (sysQFont == null || Math.Abs(font.RealSize - font.Size * Scale) > 2)
            {
                FreeFont(font);
                LoadFont(font);
                sysQFont = font.RendererData as QFont;
            }

            // flip y coordinate for QuickFont
            tp.Y = -tp.Y;

            var key = new PrintedTextKey {
                Color = this.DrawColor, Text = textContainer.Text, Font = font, Position = tp
            };

            if (!m_StringCache.Contains(key))
            {
                // not cached - create text renderer
                Debug.Print(String.Format("RenderText: caching \"{0}\", {1}", textContainer.Text, font.FaceName));
                Rectangle cRect;
                cRect = m_ClipEnabled ? new Rectangle(ClipRegion.X, -ClipRegion.Y - ClipRegion.Height, ClipRegion.Width, ClipRegion.Height) : default(Rectangle);

                m_StringCache[key] = new QFontDrawingPrimitive(sysQFont);
                m_StringCache[key].Print(textContainer.Text, new Vector3(tp.X, tp.Y, 0), QFontAlignment.Left, this.DrawColor, cRect);
            }

            m_FontDrawing.DrawingPrimitives.Add(m_StringCache[key]);

            DrawText();
        }
Beispiel #4
0
 /// <summary>
 /// Invalidates the cached value for the specified text.
 /// Only used if the renderer uses a string caching mechanism
 /// </summary>
 /// <param name="key">The key to use for the cache dictionary</param>
 public virtual void InvalidateCachedText(PrintedTextKey key)
 {
 }
Beispiel #5
0
 public void Remove(PrintedTextKey key)
 {
     _levelOneCache.Remove(key);
     _levelTwoCache.Remove(key);
 }
Beispiel #6
0
 private bool LevelTwoContains(PrintedTextKey key)
 {
     return(_levelTwoCache.ContainsKey(key));
 }
Beispiel #7
0
 public bool Contains(PrintedTextKey key)
 {
     return(LevelTwoContains(key) || LevelOneContains(key));
 }