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

📄 wg__tooltip_8cpp-source.html

📁 一个小巧的嵌入式图形系统wGUI, 可以用VC编译
💻 HTML
字号:
<!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_tooltip.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_tooltip.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// wg_tooltip.cpp</span>00002 <span class="comment">//</span>00003 <span class="comment">// CToolTip interface</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 <span class="preprocessor">#include "wgui_include_config.h"</span>00025 <span class="preprocessor">#include "wg_tooltip.h"</span>00026 00027 <span class="keyword">namespace </span>wGui00028 {00029 <a name="l00030"></a><a class="code" href="classwGui_1_1CToolTip.html#a0">00030</a> CToolTip::CToolTip(<a class="code" href="classwGui_1_1CWindow.html">CWindow</a>* pToolWindow, std::string sText, <a class="code" href="classwGui_1_1CRGBColor.html">CRGBColor</a>&amp; FontColor, <a class="code" href="classwGui_1_1CRGBColor.html">CRGBColor</a>&amp; BGColor, <a class="code" href="classwGui_1_1CFontEngine.html">CFontEngine</a>* pFontEngine) :00031      <a class="code" href="classwGui_1_1CWindow.html">CWindow</a>(<a class="code" href="classwGui_1_1CRect.html">CRect</a>(), pToolWindow),00032      m_FontColor(FontColor)00033 {00034   <a class="code" href="classwGui_1_1CWindow.html#n8">m_sClassName</a> = <span class="stringliteral">"CToolTip"</span>;00035      <a class="code" href="classwGui_1_1CWindow.html#n0">m_sWindowText</a> = sText;00036      <span class="keywordflow">if</span> (pFontEngine)00037      {00038           <a class="code" href="classwGui_1_1CToolTip.html#n0">m_pFontEngine</a> = pFontEngine;00039      }00040      <span class="keywordflow">else</span>00041      {00042           <a class="code" href="classwGui_1_1CToolTip.html#n0">m_pFontEngine</a> = CApplication::Instance()-&gt;GetDefaultFontEngine();00043      }00044      std::auto_ptr&lt;CRenderedString&gt; pRenderedString(<span class="keyword">new</span> <a class="code" href="classwGui_1_1CRenderedString.html">CRenderedString</a>(00045           <a class="code" href="classwGui_1_1CToolTip.html#n0">m_pFontEngine</a>, sText, CRenderedString::VALIGN_TOP, CRenderedString::HALIGN_LEFT));00046      <a class="code" href="classwGui_1_1CToolTip.html#n1">m_pRenderedString</a> = pRenderedString;00047 00048      <a class="code" href="classwGui_1_1CToolTip.html#n4">m_pTimer</a> = <span class="keyword">new</span> <a class="code" href="classwGui_1_1CTimer.html">CTimer</a>(<span class="keyword">this</span>);00049 00050      <span class="comment">//Now resize the window so that it fits the Tooltip text</span>00051      <a class="code" href="classwGui_1_1CPoint.html">CPoint</a> Dims;00052      <a class="code" href="classwGui_1_1CToolTip.html#n1">m_pRenderedString</a>-&gt;GetMetrics(&amp;Dims, 0, 0);00053      <a class="code" href="classwGui_1_1CToolTip.html#n6">m_BoundingRect</a> = <a class="code" href="classwGui_1_1CRect.html">CRect</a>(<a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(0, 0), Dims + <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(4, 4));00054 00055      <a class="code" href="classwGui_1_1CWindow.html#n2">m_BGColor</a> = BGColor;00056      CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::MOUSE_MOVE);00057      CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::CTRL_TIMER);00058 }00059 00060 <a name="l00061"></a><a class="code" href="classwGui_1_1CToolTip.html#a1">00061</a> CToolTip::~CToolTip(<span class="keywordtype">void</span>)00062 {00063 00064 }00065 00066 <a name="l00067"></a><a class="code" href="classwGui_1_1CToolTip.html#a2">00067</a> <span class="keywordtype">void</span> CToolTip::ShowTip(<span class="keyword">const</span> <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>&amp; DrawPoint)00068 {00069      <a class="code" href="classwGui_1_1CWindow.html#a2">SetWindowRect</a>(<a class="code" href="classwGui_1_1CToolTip.html#n6">m_BoundingRect</a> + DrawPoint);00070      <a class="code" href="classwGui_1_1CWindow.html#a11">SetVisible</a>(<span class="keyword">true</span>);00071      <a class="code" href="classwGui_1_1CWindow.html#a23">StartDrawProc</a>();00072 }00073 00074 <a name="l00075"></a><a class="code" href="classwGui_1_1CToolTip.html#a3">00075</a> <span class="keywordtype">void</span> CToolTip::HideTip(<span class="keywordtype">void</span>)00076 {00077      <a class="code" href="classwGui_1_1CWindow.html#a11">SetVisible</a>(<span class="keyword">false</span>);00078      CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> <a class="code" href="classwGui_1_1CMessage.html">CMessage</a>(CMessage::APP_PAINT, 0, <span class="keyword">this</span>));00079 }00080 00081 <a name="l00082"></a><a class="code" href="classwGui_1_1CToolTip.html#a4">00082</a> <span class="keywordtype">void</span> CToolTip::Draw(<span class="keywordtype">void</span>)<span class="keyword"> const</span>00083 <span class="keyword"></span>{00084      CWindow::Draw();00085 00086      <a class="code" href="classwGui_1_1CPainter.html">CPainter</a> Painter(<a class="code" href="classwGui_1_1CWindow.html#n6">m_pSDLSurface</a>);00087      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>);00088      <a class="code" href="classwGui_1_1CRect.html">CRect</a> SubRect(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>);00089      SubRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-2);00090      <a class="code" href="classwGui_1_1CToolTip.html#n1">m_pRenderedString</a>-&gt;Draw(<a class="code" href="classwGui_1_1CWindow.html#n6">m_pSDLSurface</a>, SubRect, SubRect.<a class="code" href="classwGui_1_1CRect.html#a13">TopLeft</a>(), <a class="code" href="classwGui_1_1CToolTip.html#n2">m_FontColor</a>);00091 }00092 00093 <a name="l00094"></a><a class="code" href="classwGui_1_1CToolTip.html#a5">00094</a> <span class="keywordtype">void</span> CToolTip::MoveWindow(<span class="keyword">const</span> <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>&amp; MoveDistance)00095 {00096      CWindow::MoveWindow(MoveDistance);00097      <a class="code" href="classwGui_1_1CToolTip.html#n6">m_BoundingRect</a> = <a class="code" href="classwGui_1_1CToolTip.html#n6">m_BoundingRect</a> + MoveDistance;00098 }00099 00100 <a name="l00101"></a><a class="code" href="classwGui_1_1CToolTip.html#a6">00101</a> <span class="keywordtype">bool</span> CToolTip::HandleMessage(<a class="code" href="classwGui_1_1CMessage.html">CMessage</a>* pMessage)00102 {00103      <span class="keywordtype">bool</span> bHandled = <span class="keyword">false</span>;00104 00105      <span class="keywordflow">if</span> (pMessage)00106      {00107           <span class="keywordflow">switch</span>(pMessage-&gt;<a class="code" href="classwGui_1_1CMessage.html#a2">MessageType</a>())00108           {00109                <span class="keywordflow">case</span> CMessage::CTRL_TIMER:00110                {00111                     wGui::TIntMessage* pTimerMessage = dynamic_cast&lt;wGui::TIntMessage*&gt;(pMessage);00112                     <span class="keywordflow">if</span> (pTimerMessage &amp;&amp; pMessage-&gt;<a class="code" href="classwGui_1_1CMessage.html#a3">Destination</a>() == <span class="keyword">this</span>)00113                     {00114                          <span class="comment">// Timer has expired, so it's time to show the tooltip</span>00115                          <a class="code" href="classwGui_1_1CToolTip.html#a2">ShowTip</a>(<a class="code" href="classwGui_1_1CToolTip.html#n5">m_LastMousePosition</a> + <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(-6, 18));00116                          bHandled = <span class="keyword">true</span>;00117                     }00118                     <span class="keywordflow">break</span>;00119                }00120           <span class="keywordflow">case</span> CMessage::MOUSE_MOVE:00121           {00122                <span class="comment">// We don't want to mess with the underlying control, so don't trap any MOUSE_MOVE messages</span>00123                <a class="code" href="classwGui_1_1CMouseMessage.html">CMouseMessage</a>* pMouseMessage = dynamic_cast&lt;CMouseMessage*&gt;(pMessage);00124                <span class="keywordflow">if</span> (pMouseMessage)00125                {00126                     <a class="code" href="classwGui_1_1CToolTip.html#n5">m_LastMousePosition</a> = pMouseMessage-&gt;<a class="code" href="classwGui_1_1CMouseMessage.html#m0">Point</a>;00127                     <a class="code" href="classwGui_1_1CToolTip.html#n4">m_pTimer</a>-&gt;<a class="code" href="classwGui_1_1CTimer.html#a3">StopTimer</a>();00128                     <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CWindow.html#a10">IsVisible</a>())00129                     {00130                          <a class="code" href="classwGui_1_1CToolTip.html#a3">HideTip</a>();00131                     }00132                     <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CWindow.html#n4">m_pParentWindow</a>-&gt;<a class="code" href="classwGui_1_1CWindow.html#a3">GetWindowRect</a>().<a class="code" href="classwGui_1_1CRect.html#a32">HitTest</a>(<a class="code" href="classwGui_1_1CToolTip.html#n5">m_LastMousePosition</a>) == CRect::RELPOS_INSIDE)00133                     {00134                          <a class="code" href="classwGui_1_1CToolTip.html#n4">m_pTimer</a>-&gt;<a class="code" href="classwGui_1_1CTimer.html#a2">StartTimer</a>(1000);00135                     }00136                }00137           }00138           <span class="keywordflow">default</span> :00139                bHandled = CWindow::HandleMessage(pMessage);00140                <span class="keywordflow">break</span>;00141           }00142      }00143 00144      <span class="keywordflow">return</span> bHandled;00145 }00146 00147 }00148 </pre></div><hr><address style="align: right;"><small>Generated on Sat Oct 25 12:43:25 2003 for wGui by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.18 </small></address></body></html>

⌨️ 快捷键说明

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