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

📄 wg__button_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_button.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_button.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// wg_button.cpp</span>00002 <span class="comment">//</span>00003 <span class="comment">// CButton class 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_button.h"</span>00027 <span class="preprocessor">#include "wg_application.h"</span>00028 <span class="preprocessor">#include "wg_message_server.h"</span>00029 <span class="preprocessor">#include &lt;algorithm&gt;</span>00030 00031 00032 <span class="keyword">namespace </span>wGui00033 {00034 <a name="l00035"></a><a class="code" href="classwGui_1_1CButton.html#a0">00035</a> CButton::CButton(<span class="keyword">const</span> <a class="code" href="classwGui_1_1CRect.html">CRect</a>&amp; WindowRect, <a class="code" href="classwGui_1_1CWindow.html">CWindow</a>* pParent, std::string sText, <a class="code" href="classwGui_1_1CFontEngine.html">CFontEngine</a>* pFontEngine) :00036      <a class="code" href="classwGui_1_1CWindow.html">CWindow</a>(WindowRect, pParent),00037      m_eButtonState(UP),00038      m_MouseButton(0)00039 {00040   <a class="code" href="classwGui_1_1CWindow.html#n8">m_sClassName</a> = <span class="stringliteral">"CButton"</span>;00041      <a class="code" href="classwGui_1_1CWindow.html#n0">m_sWindowText</a> = sText;00042      <span class="keywordflow">if</span> (pFontEngine)00043      {00044           <a class="code" href="classwGui_1_1CButton.html#n0">m_pFontEngine</a> = pFontEngine;00045      }00046      <span class="keywordflow">else</span>00047      {00048           <a class="code" href="classwGui_1_1CButton.html#n0">m_pFontEngine</a> = CApplication::Instance()-&gt;GetDefaultFontEngine();00049      }00050      std::auto_ptr&lt;CRenderedString&gt; pRenderedString(<span class="keyword">new</span> <a class="code" href="classwGui_1_1CRenderedString.html">CRenderedString</a>(00051           <a class="code" href="classwGui_1_1CButton.html#n0">m_pFontEngine</a>, sText, CRenderedString::VALIGN_CENTER, CRenderedString::HALIGN_CENTER));00052      <a class="code" href="classwGui_1_1CButton.html#n1">m_pRenderedString</a> = pRenderedString;00053      <a class="code" href="classwGui_1_1CWindow.html#n2">m_BGColor</a> = DEFAULT_FG_COLOR;00054      CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::MOUSE_BUTTONUP);00055 }00056 00057 <a name="l00058"></a><a class="code" href="classwGui_1_1CButton.html#a1">00058</a> CButton::~CButton(<span class="keywordtype">void</span>)00059 {00060 00061 }00062 00063 <a name="l00064"></a><a class="code" href="classwGui_1_1CButton.html#a3">00064</a> <span class="keywordtype">void</span> CButton::SetButtonState(EState eState)00065 {00066      <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CButton.html#n2">m_eButtonState</a> != eState)00067      {00068           <a class="code" href="classwGui_1_1CButton.html#n2">m_eButtonState</a> = eState;00069           <a class="code" href="classwGui_1_1CWindow.html#a23">StartDrawProc</a>();00070      }00071 }00072 00073 <a name="l00074"></a><a class="code" href="classwGui_1_1CButton.html#a4">00074</a> <span class="keywordtype">void</span> CButton::Draw(<span class="keywordtype">void</span>)<span class="keyword"> const</span>00075 <span class="keyword"></span>{00076      CWindow::Draw();00077 00078      <a class="code" href="classwGui_1_1CPoint.html">CPoint</a> FontCenterPoint = <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a17">Center</a>();00079      <a class="code" href="classwGui_1_1CRect.html">CRect</a> SubRect(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>);00080      SubRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-1);00081      <a class="code" href="classwGui_1_1CPainter.html">CPainter</a> Painter(<a class="code" href="classwGui_1_1CWindow.html#n6">m_pSDLSurface</a>);00082      Painter.<a class="code" href="classwGui_1_1CPainter.html#a5">DrawRect</a>(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>, <span class="keyword">false</span>, COLOR_BLACK);00083      <a class="code" href="classwGui_1_1CRGBColor.html">CRGBColor</a> FontColor = DEFAULT_LINE_COLOR;00084      <span class="keywordflow">switch</span> (m_eButtonState)00085      {00086      <span class="keywordflow">case</span> <a class="code" href="classwGui_1_1CButton.html#s3s0">UP</a>:00087           Painter.<a class="code" href="classwGui_1_1CPainter.html#a5">DrawRect</a>(SubRect, <span class="keyword">false</span>, COLOR_LIGHTGRAY);00088           Painter.<a class="code" href="classwGui_1_1CPainter.html#a3">DrawHLine</a>(SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>(), SubRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>(), SubRect.<a class="code" href="classwGui_1_1CRect.html#a12">Bottom</a>(), COLOR_DARKGRAY);00089           Painter.<a class="code" href="classwGui_1_1CPainter.html#a4">DrawVLine</a>(SubRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>(), SubRect.<a class="code" href="classwGui_1_1CRect.html#a12">Bottom</a>(), SubRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>(), COLOR_DARKGRAY);00090           <span class="keywordflow">break</span>;00091      <span class="keywordflow">case</span> <a class="code" href="classwGui_1_1CButton.html#s3s1">DOWN</a>:00092           Painter.<a class="code" href="classwGui_1_1CPainter.html#a5">DrawRect</a>(SubRect, <span class="keyword">false</span>, COLOR_LIGHTGRAY);00093           Painter.<a class="code" href="classwGui_1_1CPainter.html#a3">DrawHLine</a>(SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>(), SubRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>(), SubRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>(), COLOR_DARKGRAY);00094           Painter.<a class="code" href="classwGui_1_1CPainter.html#a4">DrawVLine</a>(SubRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>(), SubRect.<a class="code" href="classwGui_1_1CRect.html#a12">Bottom</a>(), SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>(), COLOR_DARKGRAY);00095           FontCenterPoint = FontCenterPoint + <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(1, 1);00096           <span class="keywordflow">break</span>;00097      <span class="keywordflow">case</span> <a class="code" href="classwGui_1_1CButton.html#s3s2">DISABLED</a>:00098           FontColor = DEFAULT_DISABLED_LINE_COLOR;00099           <span class="keywordflow">break</span>;00100      <span class="keywordflow">default</span>:00101           <span class="keywordflow">break</span>;00102      }00103      SubRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-2);00104      <a class="code" href="classwGui_1_1CButton.html#n1">m_pRenderedString</a>-&gt;Draw(<a class="code" href="classwGui_1_1CWindow.html#n6">m_pSDLSurface</a>, SubRect, FontCenterPoint, FontColor);00105 }00106 00107 <a name="l00108"></a><a class="code" href="classwGui_1_1CButton.html#a5">00108</a> <span class="keywordtype">void</span> CButton::SetWindowText(<span class="keyword">const</span> std::string&amp; sWindowText)00109 {00110      CWindow::SetWindowText(sWindowText);00111      std::auto_ptr&lt;CRenderedString&gt; pRenderedString(<span class="keyword">new</span> <a class="code" href="classwGui_1_1CRenderedString.html">CRenderedString</a>(00112           <a class="code" href="classwGui_1_1CButton.html#n0">m_pFontEngine</a>, sWindowText, CRenderedString::VALIGN_CENTER, CRenderedString::HALIGN_CENTER));00113      <a class="code" href="classwGui_1_1CButton.html#n1">m_pRenderedString</a> = pRenderedString;00114      <a class="code" href="classwGui_1_1CWindow.html#a23">StartDrawProc</a>();00115 }00116 00117 <a name="l00118"></a><a class="code" href="classwGui_1_1CButton.html#a6">00118</a> <span class="keywordtype">bool</span> CButton::OnMouseButtonDown(<a class="code" href="classwGui_1_1CPoint.html">CPoint</a> Point, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Button)00119 {00120      <span class="keywordtype">bool</span> bResult = <span class="keyword">false</span>;00121 00122      <span class="keywordflow">if</span> (! CWindow::OnMouseButtonDown(Point, Button) &amp;&amp; <a class="code" href="classwGui_1_1CWindow.html#n7">m_bVisible</a> &amp;&amp; (<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a32">HitTest</a>(Point) == CRect::RELPOS_INSIDE) &amp;&amp;00123           (<a class="code" href="classwGui_1_1CButton.html#n2">m_eButtonState</a> == <a class="code" href="classwGui_1_1CButton.html#s3s0">UP</a>))00124      {00125           <a class="code" href="classwGui_1_1CButton.html#a3">SetButtonState</a>(<a class="code" href="classwGui_1_1CButton.html#s3s1">DOWN</a>);00126           <a class="code" href="classwGui_1_1CButton.html#n3">m_MouseButton</a> = Button;00127           bResult = <span class="keyword">true</span>;00128      }00129 00130      <span class="keywordflow">return</span> bResult;00131 }00132 00133 <a name="l00134"></a><a class="code" href="classwGui_1_1CButton.html#a7">00134</a> <span class="keywordtype">bool</span> CButton::OnMouseButtonUp(<a class="code" href="classwGui_1_1CPoint.html">CPoint</a> Point, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Button)00135 {

⌨️ 快捷键说明

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