diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /utils/hlfaceposer/mxbitmapbutton.cpp | |
| download | archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.tar.xz archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.zip | |
Diffstat (limited to 'utils/hlfaceposer/mxbitmapbutton.cpp')
| -rw-r--r-- | utils/hlfaceposer/mxbitmapbutton.cpp | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/utils/hlfaceposer/mxbitmapbutton.cpp b/utils/hlfaceposer/mxbitmapbutton.cpp new file mode 100644 index 0000000..4f088b7 --- /dev/null +++ b/utils/hlfaceposer/mxbitmapbutton.cpp @@ -0,0 +1,96 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// +#include "mxBitmapButton.h" +#include "hlfaceposer.h" + + +mxBitmapButton::mxBitmapButton( mxWindow *parent, int x, int y, int w, int h, int id /*= 0*/, const char *bitmap /* = 0 */ ) +: mxWindow( parent, x, y, w, h, "" ) +{ + setId( id ); + + m_bmImage.valid = false; + + SetImage( bitmap ); + + HWND wnd = (HWND)getHandle(); + + DWORD style = GetWindowLong( wnd, GWL_STYLE ); + style |= WS_CLIPSIBLINGS; + SetWindowLong( wnd, GWL_STYLE, style ); +} + +mxBitmapButton::~mxBitmapButton( void ) +{ + DeleteImage(); +} + +void mxBitmapButton::redraw() +{ + HWND wnd = (HWND)getHandle(); + if ( !wnd ) + return; + + if ( !m_bmImage.valid ) + return; + + RECT rc; + GetClientRect( wnd, &rc ); + + HDC dc = GetDC( wnd ); + + DrawBitmapToDC( dc, 0, 0, w(), h(), m_bmImage ); + + ReleaseDC( wnd, dc ); + + ValidateRect( wnd, &rc ); +} + +int mxBitmapButton::handleEvent( mxEvent * event ) +{ + int iret = 0; + + switch (event->event) + { + case mxEvent::MouseUp: + // Send message to parent + HWND parent = (HWND)( getParent() ? getParent()->getHandle() : NULL ); + if ( parent ) + { + LPARAM lp; + WPARAM wp; + + wp = MAKEWPARAM( getId(), BN_CLICKED ); + lp = (long)getHandle(); + + SendMessage( parent, WM_COMMAND, wp, lp ); + iret = 1; + } + break; + } + + return iret; +} + +void mxBitmapButton::SetImage( const char *bitmapname ) +{ + if ( m_bmImage.valid ) + { + DeleteImage(); + } + + LoadBitmapFromFile( bitmapname, m_bmImage ); +} + +void mxBitmapButton::DeleteImage( void ) +{ + if ( m_bmImage.valid ) + { + DeleteObject( m_bmImage.image ); + m_bmImage.valid = false; + } +} |