⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wg__renderedstring_8cpp-source.html

📁 一个小巧的嵌入式图形系统wGUI, 可以用VC编译
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>wg_renderedstring.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.2.18 --><center><a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Data Structures</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Data Fields</a> &nbsp; </center><hr><h1>wg_renderedstring.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// wg_renderedstring.cpp</span>00002 <span class="comment">//</span>00003 <span class="comment">// CRenderedString implementation</span>00004 <span class="comment">//</span>00005 <span class="comment">//</span>00006 <span class="comment">// Copyright (c) 2002 Rob Wiskow</span>00007 <span class="comment">// rob-dev@boxedchaos.com</span>00008 <span class="comment">//</span>00009 <span class="comment">// This library is free software; you can redistribute it and/or</span>00010 <span class="comment">// modify it under the terms of the GNU Lesser General Public</span>00011 <span class="comment">// License as published by the Free Software Foundation; either</span>00012 <span class="comment">// version 2.1 of the License, or (at your option) any later version.</span>00013 <span class="comment">//</span>00014 <span class="comment">// This library is distributed in the hope that it will be useful,</span>00015 <span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span>00016 <span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>00017 <span class="comment">// Lesser General Public License for more details.</span>00018 <span class="comment">//</span>00019 <span class="comment">// You should have received a copy of the GNU Lesser General Public</span>00020 <span class="comment">// License along with this library; if not, write to the Free Software</span>00021 <span class="comment">// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span>00022 <span class="comment">//</span>00023 00024 00025 <span class="preprocessor">#include "wgui_include_config.h"</span>00026 <span class="preprocessor">#include "wg_renderedstring.h"</span>00027 <span class="preprocessor">#include "wg_painter.h"</span>00028 <span class="preprocessor">#include "wg_error.h"</span>00029 <span class="preprocessor">#include &lt;algorithm&gt;</span>00030 00031 <span class="keyword">namespace </span>wGui00032 {00033 <a name="l00034"></a><a class="code" href="classwGui_1_1CRenderedString.html#a0">00034</a> CRenderedString::CRenderedString(<a class="code" href="classwGui_1_1CFontEngine.html">CFontEngine</a>* pFontEngine, <span class="keyword">const</span> std::string&amp; sString, EVAlign eVertAlign, EHAlign eHorzAlign) :00035      m_pFontEngine(pFontEngine),00036      m_sString(sString),00037      m_eVertAlign(eVertAlign),00038      m_eHorzAlign(eHorzAlign),00039      m_bCachedMetricsValid(false),00040      m_MaskChar(' '),00041      m_MaxFontHeight(-1)00042 {00043      <span class="keywordflow">if</span> (! <a class="code" href="classwGui_1_1CRenderedString.html#n0">m_pFontEngine</a>)00044      {00045           <span class="keywordflow">throw</span>(<a class="code" href="classwGui_1_1Wg__Ex__App.html">Wg_Ex_App</a>(<span class="stringliteral">"CRenderedString::CRenderedString : Bad pFontEngine pointer!"</span>));00046      }00047 }00048 00049 <a name="l00050"></a><a class="code" href="classwGui_1_1CRenderedString.html#a1">00050</a> <span class="keywordtype">void</span> CRenderedString::Draw(SDL_Surface* pSurface, <span class="keyword">const</span> <a class="code" href="classwGui_1_1CRect.html">CRect</a>&amp; BoundingRect, <span class="keyword">const</span> <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>&amp; OriginPoint, <span class="keyword">const</span> <a class="code" href="classwGui_1_1CRGBColor.html">CRGBColor</a>&amp; FontColor)<span class="keyword"> const</span>00051 <span class="keyword"></span>{00052      <a class="code" href="classwGui_1_1CPoint.html">CPoint</a> OriginOffset;00053      std::vector&lt;CRect&gt; CharacterRects;00054      <a class="code" href="classwGui_1_1CRenderedString.html#a2">GetMetrics</a>(0, &amp;OriginOffset, &amp;CharacterRects);00055      <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i &lt; <a class="code" href="classwGui_1_1CRenderedString.html#n1">m_sString</a>.size(); ++i)00056      {00057           FT_BitmapGlyphRec* pGlyph;00058           <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CRenderedString.html#n2">m_MaskChar</a> == <span class="charliteral">' '</span>)00059           {00060                pGlyph = <a class="code" href="classwGui_1_1CRenderedString.html#n0">m_pFontEngine</a>-&gt;<a class="code" href="classwGui_1_1CFontEngine.html#a2">RenderGlyph</a>(<a class="code" href="classwGui_1_1CRenderedString.html#n1">m_sString</a>[i]);00061           }00062           <span class="keywordflow">else</span>00063           {00064                pGlyph = <a class="code" href="classwGui_1_1CRenderedString.html#n0">m_pFontEngine</a>-&gt;<a class="code" href="classwGui_1_1CFontEngine.html#a2">RenderGlyph</a>(<a class="code" href="classwGui_1_1CRenderedString.html#n2">m_MaskChar</a>);00065           }00066           <a class="code" href="classwGui_1_1CPainter.html">CPainter</a> Painter(pSurface, CPainter::PAINT_NORMAL);00067           <span class="keywordflow">for</span> (<span class="keywordtype">int</span> y = 0; y &lt; pGlyph-&gt;bitmap.rows; ++y)00068           {00069                <span class="keywordflow">for</span> (<span class="keywordtype">int</span> x = 0; x &lt; pGlyph-&gt;bitmap.width; ++x)00070                {00071                     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* PixelOffset = pGlyph-&gt;bitmap.buffer + y * pGlyph-&gt;bitmap.width + x;00072                     <span class="keywordflow">if</span> (*PixelOffset != 0x00)00073                     {00074                          <a class="code" href="classwGui_1_1CRGBColor.html">CRGBColor</a> PixelColor(FontColor.<a class="code" href="classwGui_1_1CRGBColor.html#m0">red</a>, FontColor.<a class="code" href="classwGui_1_1CRGBColor.html#m1">green</a>, FontColor.<a class="code" href="classwGui_1_1CRGBColor.html#m2">blue</a>, *PixelOffset);00075                          <a class="code" href="classwGui_1_1CPoint.html">CPoint</a> PixelPoint(<a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(x + pGlyph-&gt;left, y) + OriginPoint + OriginOffset + CharacterRects[i].TopLeft());00076                          <span class="keywordflow">if</span> (BoundingRect.<a class="code" href="classwGui_1_1CRect.html#a32">HitTest</a>(PixelPoint) == CRect::RELPOS_INSIDE)00077                          {00078                               Painter.<a class="code" href="classwGui_1_1CPainter.html#a7">DrawPoint</a>(PixelPoint, PixelColor);00079                          }00080                     }00081                }00082           }00083      }00084 }00085 <a name="l00086"></a><a class="code" href="classwGui_1_1CRenderedString.html#a4">00086</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> CRenderedString::GetMaxFontHeight()00087 {00088      <span class="keywordflow">if</span> (m_MaxFontHeight &lt; 0)00089      {00090           <span class="keywordtype">int</span> maxHeight=0;00091           FT_Glyph_Metrics* pMetrics;00092           <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0; i &lt; 256; i++)00093           {00094                pMetrics = <a class="code" href="classwGui_1_1CRenderedString.html#n0">m_pFontEngine</a>-&gt;<a class="code" href="classwGui_1_1CFontEngine.html#a3">GetMetrics</a>((<span class="keywordtype">char</span>)i);00095                <span class="keywordflow">if</span> ((pMetrics-&gt;height &gt;&gt; 6) &gt; maxHeight)00096                {00097                     maxHeight = (pMetrics-&gt;height &gt;&gt; 6);00098                }00099                <span class="comment">//maxHeight = std::max(maxHeight, pMetrics-&gt;height);</span>00100           }00101           m_MaxFontHeight = maxHeight;00102      }00103      <span class="keywordflow">return</span> m_MaxFontHeight;00104 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -