Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

背景塗りつぶしにPatBltを使う Part2 #766

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 70 additions & 60 deletions sakura_core/uiparts/CGraphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,78 @@
*/

#include <Windows.h>
#include <cassert>
#include <vector>

/*!
* @brief API関数FillRectの高速版(ブラシ用)
*
* @param [in] hDC デバイスコンテキスト
* @param [in] rc 塗りつぶし対象の矩形
* @param [in] hBrush 塗りつぶしに使うブラシハンドル
*/
inline bool MyFillRect( const HDC hDC, const RECT &rc, const HBRUSH hBrush ) noexcept
{
assert( hDC );
assert( hBrush );
assert( !IS_INTRESOURCE( hBrush ) );

if ( !hDC || IS_INTRESOURCE( hBrush ) ) return false;
beru marked this conversation as resolved.
Show resolved Hide resolved

HGDIOBJ hBrushOld = ::SelectObject( hDC, hBrush );
if ( hBrushOld == HGDI_ERROR ) return false;
beru marked this conversation as resolved.
Show resolved Hide resolved

int retPatBlt = ::PatBlt( hDC, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, PATCOPY );
beru marked this conversation as resolved.
Show resolved Hide resolved
::SelectObject( hDC, hBrushOld );

return retPatBlt != 0;
}

/*!
* @brief API関数FillRectの高速版(カラーインデックス用)
*
* @param [in] hDC デバイスコンテキスト
* @param [in] rc 塗りつぶし対象の矩形
* @param [in] sysColor システムカラーのインデックス
*/
inline bool MyFillRect( const HDC hDC, const RECT &rc, const int sysColor ) noexcept
{
assert( hDC );
assert( sysColor );
assert( IS_INTRESOURCE( sysColor ) );
beru marked this conversation as resolved.
Show resolved Hide resolved

if ( !hDC || !IS_INTRESOURCE( sysColor ) ) return false;

HBRUSH hBrush = ::GetSysColorBrush( sysColor );
if ( hBrush == NULL ) return false;

bool retMyFillRect = MyFillRect( hDC, rc, hBrush );

return retMyFillRect;
}

/*!
* @brief API関数FillRectの高速版(色指定用)
*
* @param [in] hDC デバイスコンテキスト
* @param [in] rc 塗りつぶし対象の矩形
* @param [in] color 塗りつぶし色
*/
inline bool MyFillRect( const HDC hDC, const RECT &rc, const COLORREF color ) noexcept
{
assert( hDC );

if ( !hDC ) return false;

HBRUSH hBrush = ::CreateSolidBrush( color );
if ( hBrush == NULL ) return false;

bool retMyFillRect = MyFillRect( hDC, rc, hBrush );
::DeleteObject( hBrush );

return retMyFillRect;
}

//! オリジナル値保存クラス
template <class T>
class TOriginalHolder{
Expand Down Expand Up @@ -72,9 +142,6 @@ struct SFONT {
HFONT m_hFont; //!< フォントハンドル
};

// 先行定義
inline bool MyFillRect( const HDC hDC, const RECT &rc, const HBRUSH hBrush ) noexcept;

//! 描画管理
//最新実装:ブラシ
class CGraphics{
Expand Down Expand Up @@ -265,62 +332,5 @@ class CGraphics{
bool m_bDynamicBrush; //m_hbrCurrentを動的に作成した場合はtrue
};

/*!
* @brief API関数FillRectの高速版(ブラシ用)
*
* @param [in] hDC デバイスコンテキスト
* @param [in] rc 塗りつぶし対象の矩形
* @param [in] hBrush 塗りつぶしに使うブラシハンドル
*/
inline bool MyFillRect( const HDC hDC, const RECT &rc, const HBRUSH hBrush ) noexcept
{
assert( hDC );
assert( hBrush );
assert( !IS_INTRESOURCE( hBrush ) );

HGDIOBJ hBrushOld = ::SelectObject( hDC, hBrush );
int retPatBlt = ::PatBlt( hDC, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, PATCOPY );
::SelectObject( hDC, hBrushOld );

return retPatBlt != 0;
}

/*!
* @brief API関数FillRectの高速版(カラーインデックス用)
*
* @param [in] hDC デバイスコンテキスト
* @param [in] rc 塗りつぶし対象の矩形
* @param [in] sysColor システムカラーのインデックス
*/
inline bool MyFillRect( const HDC hDC, const RECT &rc, const int sysColor ) noexcept
{
assert( hDC );
assert( sysColor );
assert( IS_INTRESOURCE( sysColor ) );

HBRUSH hBrush = ::GetSysColorBrush( sysColor );
bool retMyFillRect = MyFillRect( hDC, rc, hBrush );

return retMyFillRect;
}

/*!
* @brief API関数FillRectの高速版(色指定用)
*
* @param [in] hDC デバイスコンテキスト
* @param [in] rc 塗りつぶし対象の矩形
* @param [in] color 塗りつぶし色
*/
inline bool MyFillRect( const HDC hDC, const RECT &rc, const COLORREF color ) noexcept
{
assert( hDC );

HBRUSH hBrush = ::CreateSolidBrush( color );
bool retMyFillRect = MyFillRect( hDC, rc, hBrush );
::DeleteObject( hBrush );

return retMyFillRect;
}

#endif /* SAKURA_CGRAPHICS_BA5156BF_99C6_4854_8131_CE8B091A5EFF9_H_ */
/*[EOF]*/