📄 wg__scrollbar_8cpp-source.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_scrollbar.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> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Data Structures</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Data Fields</a> </center><hr><h1>wg_scrollbar.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// wg_scrollbar.cpp</span>00002 <span class="comment">//</span>00003 <span class="comment">// CScrollBar 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_scrollbar.h"</span>00027 <span class="preprocessor">#include "wg_message_server.h"</span>00028 <span class="preprocessor">#include "wg_error.h"</span>00029 <span class="preprocessor">#include "wg_resources.h"</span>00030 00031 00032 <span class="keyword">namespace </span>wGui00033 {00034 <a name="l00035"></a><a class="code" href="classwGui_1_1CScrollBar.html#a0">00035</a> CScrollBar::CScrollBar(<span class="keyword">const</span> <a class="code" href="classwGui_1_1CRect.html">CRect</a>& WindowRect, <a class="code" href="classwGui_1_1CWindow.html">CWindow</a>* pParent, EScrollBarType ScrollBarType) :00036 <a class="code" href="classwGui_1_1CWindow.html">CWindow</a>(WindowRect, pParent),00037 m_ScrollBarType(ScrollBarType),00038 m_iMin(0),00039 m_iMax(100),00040 m_iPosition(0),00041 m_bDragging(false)00042 {00043 <a class="code" href="classwGui_1_1CWindow.html#n8">m_sClassName</a> = <span class="stringliteral">"CScrollBar"</span>;00044 <a class="code" href="classwGui_1_1CWindow.html#n2">m_BGColor</a> = DEFAULT_FG_COLOR;00045 <span class="keywordflow">switch</span> (m_ScrollBarType)00046 {00047 <span class="keywordflow">case</span> <a class="code" href="classwGui_1_1CScrollBar.html#s2s0">VERTICAL</a>:00048 m_pBtnUpLeft = <span class="keyword">new</span> <a class="code" href="classwGui_1_1CPictureButton.html">CPictureButton</a>(00049 <a class="code" href="classwGui_1_1CRect.html">CRect</a>(WindowRect.<a class="code" href="classwGui_1_1CRect.html#a13">TopLeft</a>(), <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(WindowRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>(), WindowRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>() + WindowRect.<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>())),00050 <span class="keyword">this</span>, <a class="code" href="classwGui_1_1CwgBitmapResourceHandle.html">CwgBitmapResourceHandle</a>(WGRES_UP_ARROW_BITMAP));00051 m_pBtnDownRight = <span class="keyword">new</span> <a class="code" href="classwGui_1_1CPictureButton.html">CPictureButton</a>(00052 <a class="code" href="classwGui_1_1CRect.html">CRect</a>(<a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(WindowRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>(), WindowRect.<a class="code" href="classwGui_1_1CRect.html#a12">Bottom</a>() - WindowRect.<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>()), WindowRect.<a class="code" href="classwGui_1_1CRect.html#a16">BottomRight</a>()),00053 <span class="keyword">this</span>, <a class="code" href="classwGui_1_1CwgBitmapResourceHandle.html">CwgBitmapResourceHandle</a>(WGRES_DOWN_ARROW_BITMAP));00054 <a class="code" href="classwGui_1_1CWindow.html#n3">m_ClientRect</a> = <a class="code" href="classwGui_1_1CRect.html">CRect</a>(0, m_pBtnUpLeft-><a class="code" href="classwGui_1_1CWindow.html#a3">GetWindowRect</a>().<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>() + 1,00055 <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_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>() - m_pBtnUpLeft-><a class="code" href="classwGui_1_1CWindow.html#a3">GetWindowRect</a>().<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>() - 1);00056 <span class="keywordflow">break</span>;00057 <span class="keywordflow">case</span> <a class="code" href="classwGui_1_1CScrollBar.html#s2s1">HORIZONTAL</a>:00058 m_pBtnUpLeft = <span class="keyword">new</span> <a class="code" href="classwGui_1_1CPictureButton.html">CPictureButton</a>(00059 <a class="code" href="classwGui_1_1CRect.html">CRect</a>(WindowRect.<a class="code" href="classwGui_1_1CRect.html#a13">TopLeft</a>(), <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(WindowRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>() + WindowRect.<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>(), WindowRect.<a class="code" href="classwGui_1_1CRect.html#a12">Bottom</a>())),00060 <span class="keyword">this</span>, <a class="code" href="classwGui_1_1CwgBitmapResourceHandle.html">CwgBitmapResourceHandle</a>(WGRES_LEFT_ARROW_BITMAP));00061 m_pBtnDownRight = <span class="keyword">new</span> <a class="code" href="classwGui_1_1CPictureButton.html">CPictureButton</a>(00062 <a class="code" href="classwGui_1_1CRect.html">CRect</a>(<a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(WindowRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>() - WindowRect.<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>(), WindowRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>()), WindowRect.<a class="code" href="classwGui_1_1CRect.html#a16">BottomRight</a>()),00063 <span class="keyword">this</span>, <a class="code" href="classwGui_1_1CwgBitmapResourceHandle.html">CwgBitmapResourceHandle</a>(WGRES_RIGHT_ARROW_BITMAP));00064 <a class="code" href="classwGui_1_1CWindow.html#n3">m_ClientRect</a> = <a class="code" href="classwGui_1_1CRect.html">CRect</a>(m_pBtnUpLeft-><a class="code" href="classwGui_1_1CWindow.html#a3">GetWindowRect</a>().<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>() + 1, 0,00065 <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>() - m_pBtnUpLeft-><a class="code" href="classwGui_1_1CWindow.html#a3">GetWindowRect</a>().<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>() - 1, <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>() - 1);00066 <span class="keywordflow">break</span>;00067 <span class="keywordflow">default</span>:00068 <span class="keywordflow">throw</span>(<a class="code" href="classwGui_1_1Wg__Ex__App.html">Wg_Ex_App</a>(<span class="stringliteral">"CScrollBar::CScrollBar: Unrecognized ScrollBar Type."</span>));00069 <span class="keywordflow">break</span>;00070 }00071 m_ThumbRect = <a class="code" href="classwGui_1_1CWindow.html#a5">GetClientRect</a>();00072 <a class="code" href="classwGui_1_1CScrollBar.html#a5">SetPosition</a>(0);00073 CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::MOUSE_BUTTONUP);00074 CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::MOUSE_MOVE);00075 CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::CTRL_LCLICK);00076 }00077 00078 <a name="l00079"></a><a class="code" href="classwGui_1_1CScrollBar.html#a1">00079</a> CScrollBar::~CScrollBar(<span class="keywordtype">void</span>)00080 {00081 00082 }00083 00084 <a name="l00085"></a><a class="code" href="classwGui_1_1CScrollBar.html#a2">00085</a> <span class="keywordtype">void</span> CScrollBar::SetLimits(<span class="keywordtype">int</span> iMin, <span class="keywordtype">int</span> iMax)00086 {00087 m_iMin = iMin;00088 m_iMax = iMax;00089 <a class="code" href="classwGui_1_1CWindow.html#a23">StartDrawProc</a>();00090 }00091 00092 <a name="l00093"></a><a class="code" href="classwGui_1_1CScrollBar.html#a5">00093</a> <span class="keywordtype">void</span> CScrollBar::SetPosition(<span class="keywordtype">int</span> iPosition)00094 {00095 m_iPosition = iPosition;00096 <span class="keywordflow">if</span> (m_iPosition < m_iMin)00097 {00098 m_iPosition = m_iMin;00099 }00100 <span class="keywordflow">if</span> (m_iPosition > m_iMax)00101 {00102 m_iPosition = m_iMax;00103 }00104 <span class="keywordflow">switch</span> (m_ScrollBarType)00105 {00106 <span class="keywordflow">case</span> <a class="code" href="classwGui_1_1CScrollBar.html#s2s0">VERTICAL</a>:00107 {00108 <span class="keywordtype">int</span> yPos = static_cast<int>(<a class="code" href="classwGui_1_1CWindow.html#a5">GetClientRect</a>().<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>() + (<a class="code" href="classwGui_1_1CWindow.html#a5">GetClientRect</a>().<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>() - 16) * (static_cast<double>(m_iPosition - m_iMin) / (m_iMax - m_iMin)) - 1);00109 m_ThumbRect.<a class="code" href="classwGui_1_1CRect.html#a5">SetTop</a>(yPos);00110 m_ThumbRect.<a class="code" href="classwGui_1_1CRect.html#a8">SetBottom</a>(yPos + 16);00111 <span class="keywordflow">break</span>;00112 }00113 <span class="keywordflow">case</span> <a class="code" href="classwGui_1_1CScrollBar.html#s2s1">HORIZONTAL</a>:00114 {00115 <span class="keywordtype">int</span> xPos = static_cast<int>(<a class="code" href="classwGui_1_1CWindow.html#a5">GetClientRect</a>().<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>() + (<a class="code" href="classwGui_1_1CWindow.html#a5">GetClientRect</a>().<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>() - 16) * (static_cast<double>(m_iPosition - m_iMin) / (m_iMax - m_iMin)) - 1);00116 m_ThumbRect.<a class="code" href="classwGui_1_1CRect.html#a6">SetLeft</a>(xPos);00117 m_ThumbRect.<a class="code" href="classwGui_1_1CRect.html#a7">SetRight</a>(xPos + 16);00118 <span class="keywordflow">break</span>;00119 }00120 <span class="keywordflow">default</span>:00121 <span class="keywordflow">throw</span>(<a class="code" href="classwGui_1_1Wg__Ex__App.html">Wg_Ex_App</a>(<span class="stringliteral">"CScrollBar::SetPosition: Unrecognized ScrollBar Type."</span>));00122 <span class="keywordflow">break</span>;00123 }00124 <a class="code" href="classwGui_1_1CWindow.html#a23">StartDrawProc</a>();00125 }00126 00127 <a name="l00128"></a><a class="code" href="classwGui_1_1CScrollBar.html#a7">00128</a> <span class="keywordtype">void</span> CScrollBar::Draw(<span class="keywordtype">void</span>)<span class="keyword"> const</span>00129 <span class="keyword"></span>{00130 CWindow::Draw();00131 00132 <a class="code" href="classwGui_1_1CPainter.html">CPainter</a> Painter(<a class="code" href="classwGui_1_1CWindow.html#n6">m_pSDLSurface</a>);00133 Painter.<a class="code" href="classwGui_1_1CPainter.html#a5">DrawRect</a>(m_ThumbRect, <span class="keyword">false</span>, COLOR_BLACK);00134 <a class="code" href="classwGui_1_1CRect.html">CRect</a> SubRect(m_ThumbRect);00135 SubRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-1);00136 Painter.<a class="code" href="classwGui_1_1CPainter.html#a5">DrawRect</a>(SubRect, <span class="keyword">true</span>, COLOR_LIGHTGRAY, DEFAULT_FG_COLOR);00137 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -