📄 wg__button_8cpp-source.html
字号:
00136 <span class="keywordtype">bool</span> bResult = <span class="keyword">false</span>;00137 00138 <span class="keywordflow">if</span> (! CWindow::OnMouseButtonUp(Point, Button) && <a class="code" href="classwGui_1_1CWindow.html#n7">m_bVisible</a> && (<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) &&00139 (<a class="code" href="classwGui_1_1CButton.html#n2">m_eButtonState</a> == <a class="code" href="classwGui_1_1CButton.html#s3s1">DOWN</a>) && (<a class="code" href="classwGui_1_1CButton.html#n3">m_MouseButton</a> == Button))00140 {00141 CMessage::EMessageType MessageType = CMessage::UNKNOWN;00142 <span class="keywordflow">switch</span> (m_MouseButton)00143 {00144 <span class="keywordflow">case</span> CMouseMessage::LEFT:00145 MessageType = CMessage::CTRL_LCLICK;00146 <span class="keywordflow">break</span>;00147 <span class="keywordflow">case</span> CMouseMessage::RIGHT:00148 MessageType = CMessage::CTRL_RCLICK;00149 <span class="keywordflow">break</span>;00150 <span class="keywordflow">case</span> CMouseMessage::MIDDLE:00151 MessageType = CMessage::CTRL_MCLICK;00152 <span class="keywordflow">break</span>;00153 }00154 CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> TIntMessage(MessageType, <a class="code" href="classwGui_1_1CWindow.html#n4">m_pParentWindow</a>, <span class="keyword">this</span>, 0));00155 bResult = <span class="keyword">true</span>;00156 }00157 00158 <span class="keywordflow">return</span> bResult;00159 }00160 00161 <a name="l00162"></a><a class="code" href="classwGui_1_1CButton.html#a8">00162</a> <span class="keywordtype">bool</span> CButton::HandleMessage(<a class="code" href="classwGui_1_1CMessage.html">CMessage</a>* pMessage)00163 {00164 <span class="keywordtype">bool</span> bHandled = <span class="keyword">false</span>;00165 00166 <span class="keywordflow">if</span> (pMessage)00167 {00168 <span class="keywordflow">switch</span>(pMessage-><a class="code" href="classwGui_1_1CMessage.html#a2">MessageType</a>())00169 {00170 <span class="keywordflow">case</span> CMessage::MOUSE_BUTTONUP:00171 {00172 <a class="code" href="classwGui_1_1CMouseMessage.html">CMouseMessage</a>* pMouseMessage = dynamic_cast<CMouseMessage*>(pMessage);00173 <span class="keywordflow">if</span> (pMouseMessage && <a class="code" href="classwGui_1_1CButton.html#n2">m_eButtonState</a> == <a class="code" href="classwGui_1_1CButton.html#s3s1">DOWN</a>)00174 {00175 <a class="code" href="classwGui_1_1CButton.html#a3">SetButtonState</a>(<a class="code" href="classwGui_1_1CButton.html#s3s0">UP</a>);00176 bHandled = <span class="keyword">true</span>;00177 }00178 <span class="keywordflow">break</span>;00179 }00180 <span class="keywordflow">default</span> :00181 bHandled = CWindow::HandleMessage(pMessage);00182 <span class="keywordflow">break</span>;00183 }00184 }00185 00186 <span class="keywordflow">return</span> bHandled;00187 }00188 00189 <a name="l00190"></a><a class="code" href="classwGui_1_1CPictureButton.html#a0">00190</a> CPictureButton::CPictureButton(<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, std::string sPictureFile) :00191 <a class="code" href="classwGui_1_1CButton.html">CButton</a>(WindowRect, pParent, sPictureFile, 0)00192 {00193 <a class="code" href="classwGui_1_1CWindow.html#n8">m_sClassName</a> = <span class="stringliteral">"CPictureButton"</span>;00194 std::auto_ptr<CBitmapResourceHandle> phBitmap(<span class="keyword">new</span> <a class="code" href="classwGui_1_1CBitmapFileResourceHandle.html">CBitmapFileResourceHandle</a>(sPictureFile));00195 m_phBitmap = phBitmap;00196 }00197 00198 <a name="l00199"></a><a class="code" href="classwGui_1_1CPictureButton.html#a1">00199</a> CPictureButton::CPictureButton(<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, <span class="keyword">const</span> <a class="code" href="classwGui_1_1CBitmapResourceHandle.html">CBitmapResourceHandle</a>& hBitmap) :00200 <a class="code" href="classwGui_1_1CButton.html">CButton</a>(WindowRect, pParent, "<bitmap>", 0)00201 {00202 <a class="code" href="classwGui_1_1CWindow.html#n8">m_sClassName</a> = <span class="stringliteral">"CPictureButton"</span>;00203 std::auto_ptr<CBitmapResourceHandle> phBitmap(<span class="keyword">new</span> <a class="code" href="classwGui_1_1CBitmapResourceHandle.html">CBitmapResourceHandle</a>(hBitmap));00204 m_phBitmap = phBitmap;00205 }00206 00207 <a name="l00208"></a><a class="code" href="classwGui_1_1CPictureButton.html#a2">00208</a> CPictureButton::~CPictureButton(<span class="keywordtype">void</span>)00209 {00210 00211 }00212 00213 <a name="l00214"></a><a class="code" href="classwGui_1_1CPictureButton.html#a3">00214</a> <span class="keywordtype">void</span> CPictureButton::SetPicture(std::string sPictureFile)00215 {00216 <a class="code" href="classwGui_1_1CPictureButton.html#a3">SetPicture</a>(<a class="code" href="classwGui_1_1CBitmapFileResourceHandle.html">CBitmapFileResourceHandle</a>(sPictureFile));00217 }00218 00219 <a name="l00220"></a><a class="code" href="classwGui_1_1CPictureButton.html#a4">00220</a> <span class="keywordtype">void</span> CPictureButton::SetPicture(<span class="keyword">const</span> <a class="code" href="classwGui_1_1CBitmapResourceHandle.html">CBitmapResourceHandle</a>& hBitmap)00221 {00222 std::auto_ptr<CBitmapResourceHandle> phBitmap(<span class="keyword">new</span> <a class="code" href="classwGui_1_1CBitmapResourceHandle.html">CBitmapResourceHandle</a>(hBitmap));00223 m_phBitmap = phBitmap;00224 <a class="code" href="classwGui_1_1CWindow.html#a23">StartDrawProc</a>();00225 }00226 00227 <a name="l00228"></a><a class="code" href="classwGui_1_1CPictureButton.html#a5">00228</a> <span class="keywordtype">void</span> CPictureButton::Draw(<span class="keywordtype">void</span>)<span class="keyword"> const</span>00229 <span class="keyword"></span>{00230 CWindow::Draw();00231 00232 <a class="code" href="classwGui_1_1CRect.html">CRect</a> SubRect(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>);00233 SubRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-1);00234 <a class="code" href="classwGui_1_1CPainter.html">CPainter</a> Painter(<a class="code" href="classwGui_1_1CWindow.html#n6">m_pSDLSurface</a>);00235 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);00236 <span class="keywordflow">switch</span> (m_eButtonState)00237 {00238 <span class="keywordflow">case</span> <a class="code" href="classwGui_1_1CButton.html#s3s0">UP</a>:00239 Painter.<a class="code" href="classwGui_1_1CPainter.html#a5">DrawRect</a>(SubRect, <span class="keyword">false</span>, COLOR_LIGHTGRAY);00240 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);00241 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);00242 <span class="keywordflow">break</span>;00243 <span class="keywordflow">case</span> <a class="code" href="classwGui_1_1CButton.html#s3s1">DOWN</a>:00244 Painter.<a class="code" href="classwGui_1_1CPainter.html#a5">DrawRect</a>(SubRect, <span class="keyword">false</span>, COLOR_LIGHTGRAY);00245 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);00246 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);00247 SubRect = SubRect + <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(1, 1);00248 <span class="keywordflow">break</span>;00249 <span class="keywordflow">case</span> <a class="code" href="classwGui_1_1CButton.html#s3s2">DISABLED</a>:00250 <span class="keywordflow">break</span>;00251 <span class="keywordflow">default</span>:00252 <span class="keywordflow">break</span>;00253 }00254 SubRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-1);00255 SDL_Rect SourceRect;00256 SourceRect.x = static_cast<short int>((m_phBitmap->Bitmap()->w - SubRect.<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>()) / 2 < 0 ? 0 : (m_phBitmap->Bitmap()->w - SubRect.<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>()) / 2);00257 SourceRect.y = static_cast<short int>((m_phBitmap->Bitmap()->h - SubRect.<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>()) / 2 < 0 ? 0 : (m_phBitmap->Bitmap()->w - SubRect.<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>()) / 2);00258 SourceRect.w = static_cast<short int>(std::min(SubRect.<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>(), m_phBitmap->Bitmap()->w));00259 SourceRect.h = static_cast<short int>(std::min(SubRect.<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>(), m_phBitmap->Bitmap()->h));00260 SDL_Rect DestRect;00261 DestRect.x = static_cast<short int>((SubRect.<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>() - m_phBitmap->Bitmap()->w) / 2 < 0 ? SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>() : SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>() + (SubRect.<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>() - m_phBitmap->Bitmap()->w) / 2);00262 DestRect.y = static_cast<short int>((SubRect.<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>() - m_phBitmap->Bitmap()->h) / 2 < 0 ? SubRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>() : SubRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>() + (SubRect.<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>() - m_phBitmap->Bitmap()->h) / 2);00263 DestRect.w = static_cast<short int>(std::min(SubRect.<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>(), m_phBitmap->Bitmap()->w));00264 DestRect.h = static_cast<short int>(std::min(SubRect.<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>(), m_phBitmap->Bitmap()->h));00265 SDL_BlitSurface(m_phBitmap->Bitmap(), &SourceRect, <a class="code" href="classwGui_1_1CWindow.html#n6">m_pSDLSurface</a>, &DestRect);00266 }00267 00268 }00269 00270 </pre></div><hr><address style="align: right;"><small>Generated on Sat Oct 25 12:43:21 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 + -