コード例 #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (m_Words == null || !m_Words.Any())
            {
                return;
            }
            if (m_Layout == null)
            {
                return;
            }

            IEnumerable <LayoutItem> wordsToRedraw = m_Layout.GetWordsInArea(e.ClipRectangle);

            using (IGraphicEngine graphicEngine =
                       NewGraphicEngine(e.Graphics, this.Font.FontFamily, FontStyle.Regular, m_Palette, MinFontSize, MaxFontSize, m_MinWordWeight, m_MaxWordWeight))
            {
                foreach (LayoutItem currentItem in wordsToRedraw)
                {
                    if (m_ItemUnderMouse == currentItem)
                    {
                        graphicEngine.DrawEmphasized(currentItem);
                    }
                    else
                    {
                        graphicEngine.Draw(currentItem);
                    }
                }
            }
        }
コード例 #2
0
    /// <inheritdoc cref="ILayout"/>
    /// <summary>
    /// Arranges the words on the graphics engine.
    /// </summary>
    /// <param name="words">The words.</param>
    /// <param name="graphicEngine">The graphics engine.</param>
    /// <returns>The word count.</returns>
    /// <seealso cref="ILayout"/>
    public int Arrange(IEnumerable <IWord> words, IGraphicEngine graphicEngine)
    {
        if (words == null)
        {
            throw new ArgumentNullException(nameof(words));
        }

        var enumerable = words as IWord[] ?? words.ToArray();

        if (enumerable.First() == null)
        {
            return(0);
        }

        foreach (var word in enumerable)
        {
            var size = graphicEngine.Measure(word.Text, word.Occurrences);

            if (!this.TryFindFreeRectangle(size, out var freeRectangle))
            {
                break;
            }

            var item = new LayoutItem(freeRectangle, word);
            this.QuadTree.Insert(item);
            graphicEngine.Draw(item);
        }

        return(this.QuadTree.Count);
    }
コード例 #3
0
 /// <summary>
 /// Draws the word cloud into <see
 /// cref="IGraphicEngine{TBitmap}.Bitmap"/>.
 /// </summary>
 public TBitmap Draw()
 {
     return(Process((engine, items) =>
     {
         // Draw words.
         foreach (var item in items)
         {
             engine.Draw(item.Location, item.Measured, item.Entry.Word, item.Entry.Count);
         }
         return engine.Bitmap;
     }));
 }