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

📄 wg__painter_8cpp-source.html

📁 一个小巧的嵌入式图形系统wGUI, 可以用VC编译
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!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_painter.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_painter.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// wg_painter.cpp</span>00002 <span class="comment">//</span>00003 <span class="comment">// CPainter class</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_painter.h"</span>00027 <span class="preprocessor">#include "wg_error.h"</span>00028 <span class="preprocessor">#include &lt;algorithm&gt;</span>00029 <span class="preprocessor">#ifdef WIN32</span>00030 <span class="preprocessor"></span><span class="preprocessor">#include &lt;limits&gt;</span>00031 <span class="preprocessor">#endif // WIN32</span>00032 <span class="preprocessor"></span>00033 00034 <span class="keyword">namespace </span>wGui00035 {00036 <a name="l00037"></a><a class="code" href="classwGui_1_1CPainter.html#a0">00037</a> CPainter::CPainter(SDL_Surface* pSurface, EPaintMode ePaintMode) :00038      m_pSurface(pSurface),00039      m_pWindow(0),00040      m_PaintMode(ePaintMode)00041 {00042      <span class="keywordflow">if</span> (!<a class="code" href="classwGui_1_1CPainter.html#n0">m_pSurface</a>)00043      {00044           <span class="keywordflow">throw</span> <a class="code" href="classwGui_1_1Wg__Ex__App.html">Wg_Ex_App</a>(<span class="stringliteral">"CPainter::CPainter : Invalid pointer to surface."</span>);00045      }00046 }00047 00048 <a name="l00049"></a><a class="code" href="classwGui_1_1CPainter.html#a1">00049</a> CPainter::CPainter(<a class="code" href="classwGui_1_1CWindow.html">CWindow</a>* pWindow, EPaintMode ePaintMode) :00050      m_pSurface(0),00051      m_pWindow(pWindow),00052      m_PaintMode(ePaintMode)00053 {00054      <span class="keywordflow">if</span> (!<a class="code" href="classwGui_1_1CPainter.html#n1">m_pWindow</a>)00055      {00056           <span class="keywordflow">throw</span> <a class="code" href="classwGui_1_1Wg__Ex__App.html">Wg_Ex_App</a>(<span class="stringliteral">"CPainter::CPainter : Invalid pointer to window."</span>);00057      }00058      <a class="code" href="classwGui_1_1CPainter.html#n0">m_pSurface</a> = pWindow-&gt;<a class="code" href="classwGui_1_1CWindow.html#a12">GetSDLSurface</a>();00059      <span class="keywordflow">if</span> (!<a class="code" href="classwGui_1_1CPainter.html#n0">m_pSurface</a>)00060      {00061           <span class="keywordflow">throw</span> <a class="code" href="classwGui_1_1Wg__Ex__App.html">Wg_Ex_App</a>(<span class="stringliteral">"CPainter::CPainter : Invalid pointer to surface."</span>);00062      }00063 }00064 00065 <a name="l00066"></a><a class="code" href="classwGui_1_1CPainter.html#a3">00066</a> <span class="keywordtype">void</span> CPainter::DrawHLine(<span class="keywordtype">int</span> xStart, <span class="keywordtype">int</span> xEnd, <span class="keywordtype">int</span> y, <span class="keyword">const</span> <a class="code" href="classwGui_1_1CRGBColor.html">CRGBColor</a>&amp; LineColor)00067 {00068      <span class="keywordflow">if</span> (m_pWindow)00069      {00070           <a class="code" href="classwGui_1_1CPoint.html">CPoint</a> Offset = <a class="code" href="classwGui_1_1CPainter.html#n1">m_pWindow</a>-&gt;<a class="code" href="classwGui_1_1CWindow.html#a5">GetClientRect</a>().<a class="code" href="classwGui_1_1CRect.html#a13">TopLeft</a>();00071           xStart += Offset.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>();00072           xEnd += Offset.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>();00073           y += Offset.<a class="code" href="classwGui_1_1CPoint.html#a7">YPos</a>();00074      }00075 <span class="preprocessor">#ifdef WIN32</span>00076 <span class="preprocessor"></span><span class="preprocessor">#ifndef MSVC6  // There are problems with VC6 and these std lib template classes</span>00077 <span class="preprocessor"></span>     <span class="keywordflow">if</span> (xStart &lt; std::numeric_limits&lt;short int&gt;::min() ||xStart &gt; std::numeric_limits&lt;short int&gt;::max()00078           || xEnd &lt; std::numeric_limits&lt;short int&gt;::min() ||xEnd &gt; std::numeric_limits&lt;short int&gt;::max()00079           || y &lt; std::numeric_limits&lt;short int&gt;::min() ||y &gt; std::numeric_limits&lt;short int&gt;::max())00080      {00081           <span class="keywordflow">throw</span>(<a class="code" href="classwGui_1_1Wg__Ex__Range.html">Wg_Ex_Range</a>(<span class="stringliteral">"CPainter::DrawHLine : Out of range - converting int to short int!"</span>));00082      }00083 <span class="preprocessor">#endif // MSVC6</span>00084 <span class="preprocessor"></span><span class="preprocessor">#endif // WIN32</span>00085 <span class="preprocessor"></span>     SDL_Rect Rect;00086      Rect.x = static_cast&lt;short int&gt;(std::min(xStart, xEnd));00087      Rect.y = static_cast&lt;short int&gt;(y);00088      Rect.w = static_cast&lt;short int&gt;(std::max(xEnd - xStart + 1, xStart - xEnd + 1));00089      Rect.h = 1;00090      SDL_FillRect(<a class="code" href="classwGui_1_1CPainter.html#n0">m_pSurface</a>, &amp;Rect, LineColor.<a class="code" href="classwGui_1_1CRGBColor.html#a2">SDLColor</a>(<a class="code" href="classwGui_1_1CPainter.html#n0">m_pSurface</a>-&gt;format));00091 }00092 00093 <a name="l00094"></a><a class="code" href="classwGui_1_1CPainter.html#a4">00094</a> <span class="keywordtype">void</span> CPainter::DrawVLine(<span class="keywordtype">int</span> yStart, <span class="keywordtype">int</span> yEnd, <span class="keywordtype">int</span> x, <span class="keyword">const</span> <a class="code" href="classwGui_1_1CRGBColor.html">CRGBColor</a>&amp; LineColor)00095 {00096      <span class="keywordflow">if</span> (m_pWindow)00097      {00098           <a class="code" href="classwGui_1_1CPoint.html">CPoint</a> Offset = <a class="code" href="classwGui_1_1CPainter.html#n1">m_pWindow</a>-&gt;<a class="code" href="classwGui_1_1CWindow.html#a5">GetClientRect</a>().<a class="code" href="classwGui_1_1CRect.html#a13">TopLeft</a>();00099           yStart += Offset.<a class="code" href="classwGui_1_1CPoint.html#a7">YPos</a>();00100           yEnd += Offset.<a class="code" href="classwGui_1_1CPoint.html#a7">YPos</a>();00101           x += Offset.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>();00102      }00103 <span class="preprocessor">#ifdef WIN32</span>00104 <span class="preprocessor"></span><span class="preprocessor">#ifndef MSVC6  // There are problems with VC6 and these std lib template classes</span>00105 <span class="preprocessor"></span>     <span class="keywordflow">if</span> (yStart &lt; std::numeric_limits&lt;short int&gt;::min() ||yStart &gt; std::numeric_limits&lt;short int&gt;::max()00106           || yEnd &lt; std::numeric_limits&lt;short int&gt;::min() ||yEnd &gt; std::numeric_limits&lt;short int&gt;::max()00107           || x &lt; std::numeric_limits&lt;short int&gt;::min() ||x &gt; std::numeric_limits&lt;short int&gt;::max())

⌨️ 快捷键说明

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