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

📄 wg__frame_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_frame.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_frame.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// wg_frame.cpp</span>00002 <span class="comment">//</span>00003 <span class="comment">// CFrame 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_frame.h"</span>00027 <span class="preprocessor">#include "wg_application.h"</span>00028 00029 <span class="keyword">namespace </span>wGui00030 {00031 <a name="l00032"></a><a class="code" href="classwGui_1_1CFrame.html#a0">00032</a> CFrame::CFrame(<span class="keyword">const</span> <a class="code" href="classwGui_1_1CRect.html">CRect</a>&amp; WindowRect, <a class="code" href="classwGui_1_1CView.html">CView</a>* pParent, <a class="code" href="classwGui_1_1CFontEngine.html">CFontEngine</a>* pFontEngine, std::string sTitle, <span class="keywordtype">bool</span> bResizable) :00033      <a class="code" href="classwGui_1_1CWindow.html">CWindow</a>(WindowRect, pParent),00034      m_TitleBarColor(COLOR_BLUE),00035      m_TitleBarTextColor(DEFAULT_LINE_COLOR),00036      m_iTitleBarHeight(16),00037      m_bResizable(bResizable),00038      m_pMenu(0),00039      m_bDragMode(false),00040      m_pSavedSurface(0)00041 {00042   <a class="code" href="classwGui_1_1CWindow.html#n8">m_sClassName</a> = <span class="stringliteral">"CFrame"</span>;00043      <a class="code" href="classwGui_1_1CWindow.html#n0">m_sWindowText</a> = sTitle;00044      <a class="code" href="classwGui_1_1CFrame.html#n0">m_pFrameCloseButton</a> = <span class="keyword">new</span> <a class="code" href="classwGui_1_1CPictureButton.html">CPictureButton</a>(<a class="code" href="classwGui_1_1CRect.html">CRect</a>(0, 0, 12, 12),00045                <span class="keyword">this</span>, <a class="code" href="classwGui_1_1CwgBitmapResourceHandle.html">CwgBitmapResourceHandle</a>(WGRES_X_BITMAP));00046 00047      <a class="code" href="classwGui_1_1CFrame.html#a9">SetWindowRect</a>(WindowRect);  <span class="comment">// must be done after the buttons are created</span>00048 00049      <span class="keywordflow">if</span> (pFontEngine)00050      {00051           <a class="code" href="classwGui_1_1CFrame.html#n4">m_pFontEngine</a> = pFontEngine;00052      }00053      <span class="keywordflow">else</span>00054      {00055           <a class="code" href="classwGui_1_1CFrame.html#n4">m_pFontEngine</a> = CApplication::Instance()-&gt;GetDefaultFontEngine();00056      }00057      std::auto_ptr&lt;CRenderedString&gt; pRenderedString(<span class="keyword">new</span> <a class="code" href="classwGui_1_1CRenderedString.html">CRenderedString</a>(<a class="code" href="classwGui_1_1CFrame.html#n4">m_pFontEngine</a>, <a class="code" href="classwGui_1_1CWindow.html#n0">m_sWindowText</a>, CRenderedString::VALIGN_CENTER));00058      <a class="code" href="classwGui_1_1CFrame.html#n5">m_pRenderedString</a> = pRenderedString;00059 00060      CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::MOUSE_BUTTONUP);00061      CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::MOUSE_MOVE);00062      CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::CTRL_LCLICK);00063 }00064 00065 <a name="l00066"></a><a class="code" href="classwGui_1_1CFrame.html#a1">00066</a> CFrame::~CFrame(<span class="keywordtype">void</span>)00067 {00068      <span class="keywordflow">if</span> (m_pSavedSurface)00069      {00070           SDL_FreeSurface(m_pSavedSurface);00071      }00072 }00073 00074 <a name="l00075"></a><a class="code" href="classwGui_1_1CFrame.html#a8">00075</a> <span class="keywordtype">void</span> CFrame::Draw(<span class="keywordtype">void</span>)<span class="keyword"> const</span>00076 <span class="keyword"></span>{00077      CWindow::Draw();00078 00079      <a class="code" href="classwGui_1_1CPainter.html">CPainter</a> Painter(<a class="code" href="classwGui_1_1CWindow.html#n6">m_pSDLSurface</a>);00080      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_LIGHTGRAY);00081      Painter.<a class="code" href="classwGui_1_1CPainter.html#a3">DrawHLine</a>(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>(), <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>(), <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a12">Bottom</a>(), COLOR_DARKGRAY);00082      Painter.<a class="code" href="classwGui_1_1CPainter.html#a4">DrawVLine</a>(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>(), <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a12">Bottom</a>(), <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>(), COLOR_DARKGRAY);00083      <a class="code" href="classwGui_1_1CRect.html">CRect</a> SubRect(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>);00084      SubRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-1);00085      Painter.<a class="code" href="classwGui_1_1CPainter.html#a5">DrawRect</a>(SubRect, <span class="keyword">false</span>, COLOR_BLACK);00086      Painter.<a class="code" href="classwGui_1_1CPainter.html#a5">DrawRect</a>(m_TitleBarRect, <span class="keyword">true</span>, <a class="code" href="classwGui_1_1CFrame.html#n1">m_TitleBarColor</a>, <a class="code" href="classwGui_1_1CFrame.html#n1">m_TitleBarColor</a>);00087 00088      <a class="code" href="classwGui_1_1CRect.html">CRect</a> TextClipRect(m_TitleBarRect);00089      TextClipRect.<a class="code" href="classwGui_1_1CRect.html#a7">SetRight</a>(TextClipRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>() - 16);00090      TextClipRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-1);00091      <a class="code" href="classwGui_1_1CFrame.html#n5">m_pRenderedString</a>-&gt;Draw(<a class="code" href="classwGui_1_1CWindow.html#n6">m_pSDLSurface</a>, TextClipRect, m_TitleBarRect.<a class="code" href="classwGui_1_1CRect.html#a13">TopLeft</a>() + <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(6, <a class="code" href="classwGui_1_1CFrame.html#n3">m_iTitleBarHeight</a> / 2), <a class="code" href="classwGui_1_1CFrame.html#n2">m_TitleBarTextColor</a>);00092 }00093 00094 <a name="l00095"></a><a class="code" href="classwGui_1_1CFrame.html#a4">00095</a> <span class="keywordtype">void</span> CFrame::SetTitleBarHeight(<span class="keywordtype">int</span> iTitleBarHeight)00096 {00097      <a class="code" href="classwGui_1_1CFrame.html#n3">m_iTitleBarHeight</a> = iTitleBarHeight;00098      <a class="code" href="classwGui_1_1CFrame.html#a9">SetWindowRect</a>(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>);00099 }00100 00101 <a name="l00102"></a><a class="code" href="classwGui_1_1CFrame.html#a6">00102</a> <span class="keywordtype">void</span> CFrame::AttachMenu(<a class="code" href="classwGui_1_1CMenu.html">CMenu</a>* pMenu)00103 {00104      <span class="keyword">delete</span> <a class="code" href="classwGui_1_1CFrame.html#n7">m_pMenu</a>;00105      <a class="code" href="classwGui_1_1CFrame.html#n7">m_pMenu</a> = pMenu;00106      <span class="keywordflow">if</span> (m_pMenu)00107      {00108           <a class="code" href="classwGui_1_1CFrame.html#n7">m_pMenu</a>-&gt;<a class="code" href="classwGui_1_1CWindow.html#a2">SetWindowRect</a>(<a class="code" href="classwGui_1_1CRect.html">CRect</a>(0, 0, <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>() - 1, <a class="code" href="classwGui_1_1CFrame.html#n7">m_pMenu</a>-&gt;<a class="code" href="classwGui_1_1CWindow.html#a3">GetWindowRect</a>().<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>()));00109           <a class="code" href="classwGui_1_1CWindow.html#n3">m_ClientRect</a>.<a class="code" href="classwGui_1_1CRect.html#a5">SetTop</a>(<a class="code" href="classwGui_1_1CFrame.html#n7">m_pMenu</a>-&gt;<a class="code" href="classwGui_1_1CWindow.html#a3">GetWindowRect</a>().<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>() + 1);00110           <a class="code" href="classwGui_1_1CWindow.html#n3">m_ClientRect</a>.<a class="code" href="classwGui_1_1CRect.html#a31">ClipTo</a>(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>);00111      }00112      <span class="keywordflow">else</span>00113      {00114           <a class="code" href="classwGui_1_1CWindow.html#n3">m_ClientRect</a> = <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>;00115      }00116 }00117 00118 <a name="l00119"></a><a class="code" href="classwGui_1_1CFrame.html#a9">00119</a> <span class="keywordtype">void</span> CFrame::SetWindowRect(<span class="keyword">const</span> <a class="code" href="classwGui_1_1CRect.html">CRect</a>&amp; WindowRect)00120 {00121      CWindow::SetWindowRect(WindowRect);00122      m_TitleBarRect = <a class="code" href="classwGui_1_1CRect.html">CRect</a>(2, 2, WindowRect.<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>() - 3, <a class="code" href="classwGui_1_1CFrame.html#n3">m_iTitleBarHeight</a>) + WindowRect.<a class="code" href="classwGui_1_1CRect.html#a13">TopLeft</a>();00123      <a class="code" href="classwGui_1_1CFrame.html#n0">m_pFrameCloseButton</a>-&gt;<a class="code" href="classwGui_1_1CWindow.html#a2">SetWindowRect</a>(<a class="code" href="classwGui_1_1CRect.html">CRect</a>(WindowRect.<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>() - 16, <a class="code" href="classwGui_1_1CFrame.html#n3">m_iTitleBarHeight</a> / 2 - 5, WindowRect.<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>() - 4, <a class="code" href="classwGui_1_1CFrame.html#n3">m_iTitleBarHeight</a> / 2 + 7) + WindowRect.<a class="code" href="classwGui_1_1CRect.html#a13">TopLeft</a>());00124      <a class="code" href="classwGui_1_1CWindow.html#n3">m_ClientRect</a> = <a class="code" href="classwGui_1_1CRect.html">CRect</a>(2, <a class="code" href="classwGui_1_1CFrame.html#n3">m_iTitleBarHeight</a> + 2, WindowRect.<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>() - <a class="code" href="classwGui_1_1CFrame.html#n3">m_iTitleBarHeight</a> - 1, WindowRect.<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>() - 1);00125 }00126 00127 <a name="l00128"></a><a class="code" href="classwGui_1_1CFrame.html#a10">00128</a> <span class="keywordtype">void</span> CFrame::MoveWindow(<span class="keyword">const</span> <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>&amp; MoveDistance)00129 {00130      CWindow::MoveWindow(MoveDistance);00131      m_TitleBarRect = m_TitleBarRect + MoveDistance;00132 }00133 00134 

⌨️ 快捷键说明

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