Skip to content

Commit

Permalink
Merge pull request #766 from berryzplus/refactoring/fillrect_to_patblt
Browse files Browse the repository at this point in the history
背景塗りつぶしにPatBltを使う Part2
  • Loading branch information
berryzplus authored Jan 21, 2019
2 parents c670c2d + 226af59 commit fde6480
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 133 deletions.
9 changes: 3 additions & 6 deletions sakura_core/outline/CDlgFuncList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3223,9 +3223,6 @@ INT_PTR CDlgFuncList::OnNcPaint( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa
rc = rcScr;
::OffsetRect( &rc, -rcScr.left, -rcScr.top );

// 背景を描画する
//::FillRect( gr, &rc, (HBRUSH)(COLOR_3DFACE + 1) );

// 分割線を描画する
rcWk = rc;
switch( eDockSide ){
Expand All @@ -3234,7 +3231,7 @@ INT_PTR CDlgFuncList::OnNcPaint( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa
case DOCKSIDE_RIGHT: rcWk.right = rcWk.left + DOCK_SPLITTER_WIDTH; break;
case DOCKSIDE_BOTTOM: rcWk.bottom = rcWk.top + DOCK_SPLITTER_WIDTH; break;
}
::FillRect( gr, &rcWk, (HBRUSH)(COLOR_3DFACE + 1) );
::MyFillRect( gr, rcWk, COLOR_3DFACE );
::DrawEdge( gr, &rcWk, EDGE_ETCHED, BF_TOPLEFT );

// タイトルを描画する
Expand All @@ -3259,7 +3256,7 @@ INT_PTR CDlgFuncList::OnNcPaint( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa
nClrCaption = ( bActive? COLOR_GRADIENTACTIVECAPTION: COLOR_GRADIENTINACTIVECAPTION );
else
nClrCaption = ( bActive? COLOR_ACTIVECAPTION: COLOR_INACTIVECAPTION );
::FillRect( gr, &rcWk, ::GetSysColorBrush( nClrCaption ) );
::MyFillRect( gr, rcWk, nClrCaption );
::DrawEdge( gr, &rcCaption, BDR_SUNKENOUTER, BF_TOP );

// タイトル上のボタンを描画する
Expand Down Expand Up @@ -3290,7 +3287,7 @@ INT_PTR CDlgFuncList::OnNcPaint( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa
int nClrCaptionText;
// マウスカーソルがボタン上にあればハイライト
if( ::PtInRect( &rcBtn, pt ) ){
::FillRect( gr, &rcBtn, ::GetSysColorBrush( (bGradient && !bActive)? COLOR_INACTIVECAPTION: COLOR_ACTIVECAPTION ) );
::MyFillRect( gr, rcBtn, (bGradient && !bActive)? COLOR_INACTIVECAPTION: COLOR_ACTIVECAPTION );
nClrCaptionText = ( (bGradient && !bActive)? COLOR_INACTIVECAPTIONTEXT: COLOR_CAPTIONTEXT );
}else{
nClrCaptionText = ( bActive? COLOR_CAPTIONTEXT: COLOR_INACTIVECAPTIONTEXT );
Expand Down
3 changes: 2 additions & 1 deletion sakura_core/print/CPrintPreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "dlg/CDlgCancel.h" /// 2002/2/3 aroka from here
#include "dlg/CDlgInput1.h" /// 2007.02.11 Moca
#include "CEditApp.h"
#include "uiparts/CGraphics.h"
#include "util/window.h"
#include "util/shell.h"
#include "env/CSakuraEnvironment.h"
Expand Down Expand Up @@ -145,7 +146,7 @@ LRESULT CPrintPreview::OnPaint(
::GetClientRect( hwnd, &bmpRc );
bmpRc.right = (bmpRc.right * m_nbmpCompatScale) / COMPAT_BMP_BASE;
bmpRc.bottom = (bmpRc.bottom * m_nbmpCompatScale) / COMPAT_BMP_BASE;
::FillRect( hdc, &bmpRc, (HBRUSH)::GetStockObject( GRAY_BRUSH ) );
::MyFillRect( hdc, bmpRc, (HBRUSH)::GetStockObject( GRAY_BRUSH ) );
}

// ツールバー高さ -> nToolBarHeight
Expand Down
156 changes: 76 additions & 80 deletions sakura_core/prop/CPropComToolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@

#include "StdAfx.h"
#include "prop/CPropCommon.h"
#include "uiparts/CMenuDrawer.h" // 2002/2/10 aroka
#include "uiparts/CGraphics.h"
#include "uiparts/CImageListMgr.h" // 2005/8/9 aroka
#include "uiparts/CMenuDrawer.h" // 2002/2/10 aroka
#include "util/shell.h"
#include "util/window.h"
#include "sakura_rc.h"
Expand Down Expand Up @@ -553,98 +554,93 @@ void CPropToolbar::DrawToolBarItemList( DRAWITEMSTRUCT* pDis )
const int cxSmIcon = ::GetSystemMetrics(SM_CXSMICON);
const int cySmIcon = ::GetSystemMetrics(SM_CYSMICON);

TBBUTTON tbb;
HBRUSH hBrush;
RECT rc;
RECT rc0;
RECT rc1;
RECT rc2;

// hBrush = ::CreateSolidBrush( ::GetSysColor( COLOR_WINDOW ) );
hBrush = ::GetSysColorBrush( COLOR_WINDOW );
::FillRect( pDis->hDC, &pDis->rcItem, hBrush );
// ::DeleteObject( hBrush );

rc = pDis->rcItem;
rc0 = pDis->rcItem;
rc0.left += GetSystemMetrics(SM_CXSMICON) + DpiScaleX(2);
rc1 = rc0;
rc2 = rc0;

if( (int)pDis->itemID < 0 ){
RECT rcItem = pDis->rcItem;
RECT rcText = rcItem;
rcText.left += GetSystemMetrics( SM_CXSMICON ) + DpiScaleX( 2 );
RECT rcFrame = rcText;

// アイテム背景をウインドウ背景色で塗りつぶす
::MyFillRect( pDis->hDC, rcItem, COLOR_WINDOW );

// 背景色と前景色
int bkColor;
int textColor;

/* アイテムが選択されている */
if( pDis->itemState & ODS_SELECTED ){
bkColor = COLOR_HIGHLIGHT;
textColor = COLOR_HIGHLIGHTTEXT;
}else{
bkColor = COLOR_WINDOW;
textColor = COLOR_WINDOWTEXT;
}

//@@@ 2002.01.03 YAZAKI m_tbMyButtonなどをCShareDataからCMenuDrawerへ移動したことによる修正。
// tbb = m_cShareData.m_tbMyButton[pDis->itemData];
// tbb = m_pcMenuDrawer->m_tbMyButton[pDis->itemData];
tbb = m_pcMenuDrawer->getButton(pDis->itemData);

// ボタンとセパレータとで処理を分ける 2007.11.02 ryoji
WCHAR szLabel[256];
if( tbb.fsStyle & TBSTYLE_SEP ){
// テキストだけ表示する
if( tbb.idCommand == F_SEPARATOR ){
auto_strncpy( szLabel, LSW(STR_PROPCOMTOOL_ITEM1), _countof(szLabel) - 1 ); // nLength 未使用 2003/01/09 Moca
szLabel[_countof(szLabel) - 1] = L'\0';
}else if( tbb.idCommand == F_MENU_NOT_USED_FIRST ){
// ツールバー折返
auto_strncpy( szLabel, LSW(STR_PROPCOMTOOL_ITEM2), _countof(szLabel) - 1 );
szLabel[_countof(szLabel) - 1] = L'\0';
}else{
auto_strncpy( szLabel, LSW(STR_PROPCOMTOOL_ITEM3), _countof(szLabel) - 1 );
szLabel[_countof(szLabel) - 1] = L'\0';
}
// From Here Oct. 15, 2001 genta
// デバイスコンテキストのオプションを設定する
int bkModeOld = ::SetBkMode( pDis->hDC, TRANSPARENT );
COLORREF bkColorOld = ::SetBkColor( pDis->hDC, ::GetSysColor( bkColor ) );
COLORREF textColorOld = ::SetTextColor( pDis->hDC, ::GetSysColor( textColor ) );

// itemDataに紐づくボタン情報を取得する
TBBUTTON tbb = m_pcMenuDrawer->getButton(pDis->itemData);

// ボタンとセパレータとで処理を分ける 2007.11.02 ryoji
WCHAR szLabel[256];
if( tbb.fsStyle & TBSTYLE_SEP ){
// テキストだけ表示する
if( tbb.idCommand == F_SEPARATOR ){
auto_strncpy( szLabel, LSW(STR_PROPCOMTOOL_ITEM1), _countof(szLabel) - 1 ); // nLength 未使用 2003/01/09 Moca
szLabel[_countof(szLabel) - 1] = L'\0';
}else if( tbb.idCommand == F_MENU_NOT_USED_FIRST ){
// ツールバー折返
auto_strncpy( szLabel, LSW(STR_PROPCOMTOOL_ITEM2), _countof(szLabel) - 1 );
szLabel[_countof(szLabel) - 1] = L'\0';
}else{
// アイコンとテキストを表示する
m_pcIcons->DrawToolIcon(
pDis->hDC,
rc.left + cxEdge,
rc.top + cyEdge + (rc.bottom - rc.top - cySmIcon) / 2,
tbb.iBitmap,
ILD_NORMAL,
cxSmIcon,
cySmIcon
);
m_cLookup.Funccode2Name( tbb.idCommand, szLabel, _countof( szLabel ) );
auto_strncpy( szLabel, LSW(STR_PROPCOMTOOL_ITEM3), _countof(szLabel) - 1 );
szLabel[_countof(szLabel) - 1] = L'\0';
}
// To Here Oct. 15, 2001 genta
}else{
// アイコンとテキストを表示する
m_pcIcons->DrawToolIcon(
pDis->hDC,
rcItem.left + cxEdge,
rcItem.top + cyEdge + (rcItem.bottom - rcItem.top - cySmIcon) / 2,
tbb.iBitmap,
ILD_NORMAL,
cxSmIcon,
cySmIcon
);
m_cLookup.Funccode2Name( tbb.idCommand, szLabel, _countof( szLabel ) );
}

/* アイテムが選択されている */
if( pDis->itemState & ODS_SELECTED ){
// hBrush = ::CreateSolidBrush( ::GetSysColor( COLOR_HIGHLIGHT ) );
hBrush = ::GetSysColorBrush( COLOR_HIGHLIGHT );
::SetTextColor( pDis->hDC, ::GetSysColor( COLOR_HIGHLIGHTTEXT ) );
}else{
// hBrush = ::CreateSolidBrush( ::GetSysColor( COLOR_WINDOW ) );
hBrush = ::GetSysColorBrush( COLOR_WINDOW );
::SetTextColor( pDis->hDC, ::GetSysColor( COLOR_WINDOWTEXT ) );
}
// 微調整 フォーカス枠の分へこませる
::InflateRect( &rcText, -cxBorder, -cyBorder );

::InflateRect( &rc1, -cxBorder, -cyBorder );
::FillRect( pDis->hDC, &rc1, hBrush );
// ::DeleteObject( hBrush );
// 選択アイテムの背景を描画
::ExtTextOut( pDis->hDC, 0, 0, ETO_OPAQUE, &rcText, (LPCTSTR) NULL, 0, NULL );

::SetBkMode( pDis->hDC, TRANSPARENT );
// 微調整 インデントと上余白
rcText.left += cxFrame;
rcText.top += cyBorder;

// 微調整 インデントと上余白
rc1.left += cxFrame;
rc1.top += cyBorder;
// 指定された矩形に左寄せ上下中央揃えで出力する
::DrawText(
pDis->hDC,
szLabel,
-1,
&rcText,
DT_LEFT | DT_VCENTER | DT_SINGLELINE
);

// 指定された矩形に左寄せ上下中央揃えで出力する
::DrawText(
pDis->hDC,
szLabel,
-1,
&rc1,
DT_LEFT | DT_VCENTER | DT_SINGLELINE
);
}
// デバイスコンテキストのオプションを元に戻す
::SetTextColor( pDis->hDC, textColorOld );
::SetBkColor( pDis->hDC, bkColorOld );
::SetBkMode( pDis->hDC, bkModeOld );

/* アイテムにフォーカスがある */
if( pDis->itemState & ODS_FOCUS ){
::DrawFocusRect( pDis->hDC, &rc2 );
::DrawFocusRect( pDis->hDC, &rcFrame );
}

return;
}

8 changes: 3 additions & 5 deletions sakura_core/typeprop/CDlgSameColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,13 @@ BOOL CDlgSameColor::OnDrawItem( WPARAM wParam, LPARAM lParam )
rc = pDis->rcItem;

// アイテム矩形塗りつぶし
::FillRect( gr, &pDis->rcItem, ::GetSysColorBrush( COLOR_WINDOW ) );
::MyFillRect( gr, pDis->rcItem, COLOR_WINDOW );

// アイテムが選択状態
if( pDis->itemState & ODS_SELECTED ){
rc = pDis->rcItem;
rc.left += (rc.bottom - rc.top);
::FillRect( gr, &rc, ::GetSysColorBrush( COLOR_HIGHLIGHT ) );
::MyFillRect( gr, rc, COLOR_HIGHLIGHT );
}

// アイテムにフォーカスがある
Expand Down Expand Up @@ -415,9 +415,7 @@ LRESULT CALLBACK CDlgSameColor::ColorStatic_SubclassProc( HWND hwnd, UINT uMsg,
// 親にWM_CTLCOLORSTATICを送って背景ブラシを取得し、背景描画する
{
HBRUSH hBrush = (HBRUSH)::SendMessageAny( GetParent( hwnd ), WM_CTLCOLORSTATIC, wParam, (LPARAM)hwnd );
HBRUSH hBrushOld = (HBRUSH)::SelectObject( hDC, hBrush );
::FillRect( hDC, &rc, hBrush );
::SelectObject( hDC, hBrushOld );
::MyFillRect( hDC, rc, hBrush );
}
return (LRESULT)1;

Expand Down
69 changes: 68 additions & 1 deletion sakura_core/uiparts/CGraphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,75 @@
*/

#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 );

if ( !hDC || !hBrush ) return false;

HGDIOBJ hBrushOld = ::SelectObject( hDC, hBrush );
if ( !hBrushOld || hBrushOld == HGDI_ERROR ) return false;

auto 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 );

if ( !hDC ) 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 @@ -211,7 +278,7 @@ class CGraphics{
//! 矩形塗り潰し
void FillMyRect(const RECT& rc)
{
::FillRect(m_hdc,&rc,GetCurrentBrush());
::MyFillRect( m_hdc, rc, GetCurrentBrush() );
#ifdef _DEBUG
::SetPixel(m_hdc,-1,-1,0); //###########実験
#endif
Expand Down
Loading

0 comments on commit fde6480

Please sign in to comment.