From d7c9a36faa41e0456e08ae55aa8634b28b898174 Mon Sep 17 00:00:00 2001 From: berryplus Date: Sun, 13 Jan 2019 14:13:13 +0900 Subject: [PATCH 1/8] =?UTF-8?q?MyFillRect=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FillRectの利用シーンに合うように、ブラシ・システムカラー・色指定の3オーバーロードを用意。 --- sakura_core/uiparts/CGraphics.h | 57 +++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/sakura_core/uiparts/CGraphics.h b/sakura_core/uiparts/CGraphics.h index a758a32436..5f0646cc6d 100644 --- a/sakura_core/uiparts/CGraphics.h +++ b/sakura_core/uiparts/CGraphics.h @@ -262,5 +262,62 @@ 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]*/ From 6b0e2cd99abf21845a607fae3e005c4c4849c05c Mon Sep 17 00:00:00 2001 From: berryplus Date: Sun, 13 Jan 2019 15:34:40 +0900 Subject: [PATCH 2/8] =?UTF-8?q?MyFillRect=E9=96=A2=E6=95=B0=E3=82=92?= =?UTF-8?q?=E5=B1=95=E9=96=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 周辺で宣言していたブラシの一時変数が要らなくなる。 CPropComToolbar.cppのFillRectは関連コンテキストでSetBkColorする必要があるので除外した。 --- sakura_core/outline/CDlgFuncList.cpp | 9 +++------ sakura_core/print/CPrintPreview.cpp | 3 ++- sakura_core/typeprop/CDlgSameColor.cpp | 8 +++----- sakura_core/uiparts/CGraphics.h | 5 ++++- sakura_core/uiparts/CMenuDrawer.cpp | 28 +++++++++----------------- sakura_core/window/CSplitBoxWnd.cpp | 14 +++++-------- sakura_core/window/CSplitterWnd.cpp | 8 +++----- sakura_core/window/CTabWnd.cpp | 10 ++++----- 8 files changed, 33 insertions(+), 52 deletions(-) diff --git a/sakura_core/outline/CDlgFuncList.cpp b/sakura_core/outline/CDlgFuncList.cpp index 7c59b94a0d..761a3c700c 100644 --- a/sakura_core/outline/CDlgFuncList.cpp +++ b/sakura_core/outline/CDlgFuncList.cpp @@ -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 ){ @@ -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 ); // タイトルを描画する @@ -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 ); // タイトル上のボタンを描画する @@ -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 ); diff --git a/sakura_core/print/CPrintPreview.cpp b/sakura_core/print/CPrintPreview.cpp index bc1ce41079..ee1414e992 100644 --- a/sakura_core/print/CPrintPreview.cpp +++ b/sakura_core/print/CPrintPreview.cpp @@ -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" @@ -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 diff --git a/sakura_core/typeprop/CDlgSameColor.cpp b/sakura_core/typeprop/CDlgSameColor.cpp index d652c4501b..a8cc96e755 100644 --- a/sakura_core/typeprop/CDlgSameColor.cpp +++ b/sakura_core/typeprop/CDlgSameColor.cpp @@ -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 ); } // アイテムにフォーカスがある @@ -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; diff --git a/sakura_core/uiparts/CGraphics.h b/sakura_core/uiparts/CGraphics.h index 5f0646cc6d..a909765478 100644 --- a/sakura_core/uiparts/CGraphics.h +++ b/sakura_core/uiparts/CGraphics.h @@ -72,6 +72,9 @@ struct SFONT { HFONT m_hFont; //!< フォントハンドル }; +// 先行定義 +inline bool MyFillRect( const HDC hDC, const RECT &rc, const HBRUSH hBrush ) noexcept; + //! 描画管理 //最新実装:ブラシ class CGraphics{ @@ -211,7 +214,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 diff --git a/sakura_core/uiparts/CMenuDrawer.cpp b/sakura_core/uiparts/CMenuDrawer.cpp index 774780ad27..a58a0396df 100644 --- a/sakura_core/uiparts/CMenuDrawer.cpp +++ b/sakura_core/uiparts/CMenuDrawer.cpp @@ -25,6 +25,7 @@ #include "window/CSplitBoxWnd.h" #include "CImageListMgr.h" #include "func/CKeyBind.h" +#include "uiparts/CGraphics.h" #include "util/window.h" // メニューアイコンの背景をボタンの色にする @@ -979,8 +980,6 @@ void CMenuDrawer::DrawItem( DRAWITEMSTRUCT* lpdis ) const int cxSmIcon = ::GetSystemMetrics(SM_CXSMICON); const int cySmIcon = ::GetSystemMetrics(SM_CYSMICON); - HBRUSH hBrush; - CMyRect rcItem( lpdis->rcItem ); const bool bMenuIconDraw = !!m_pShareData->m_Common.m_sWindow.m_bMenuIcon; @@ -1040,7 +1039,7 @@ void CMenuDrawer::DrawItem( DRAWITEMSTRUCT* lpdis ) BYTE valR = ((GetRValue(colHilight) * 4 + GetRValue(colMenu) * 6) / 10) | 0x18; BYTE valG = ((GetGValue(colHilight) * 4 + GetGValue(colMenu) * 6) / 10) | 0x18; BYTE valB = ((GetBValue(colHilight) * 4 + GetBValue(colMenu) * 6) / 10) | 0x18; - hBrush = ::CreateSolidBrush( RGB(valR, valG, valB) ); + HBRUSH hBrush = ::CreateSolidBrush( RGB(valR, valG, valB) ); HBRUSH hOldBrush = (HBRUSH)::SelectObject( hdc, hBrush ); ::Rectangle( hdc, rc1.left, rc1.top, rc1.right, rc1.bottom ); ::SelectObject( hdc, hOldPen ); @@ -1048,17 +1047,15 @@ void CMenuDrawer::DrawItem( DRAWITEMSTRUCT* lpdis ) ::DeleteObject( hPenBorder ); ::DeleteObject( hBrush ); #else - hBrush = ::GetSysColorBrush( COLOR_HIGHLIGHT ); /* 選択ハイライト矩形 */ - ::FillRect( hdc, &rc1, hBrush ); + ::MyFillRect( hdc, rc1, COLOR_HIGHLIGHT ); #endif #ifdef DRAW_MENU_ICON_BACKGROUND_3DFACE }else if( bMenuIconDraw ){ // アイコン部分の背景を灰色にする - hBrush = ::GetSysColorBrush( COLOR_MENU ); CMyRect rcFillMenuBack( rcItem ); rcFillMenuBack.left += nIndentLeft; - ::FillRect( hdc, &rcFillMenuBack, hBrush ); + ::MyFillRect( hdc, rcFillMenuBack, COLOR_MENU ); // hBrush = ::GetSysColorBrush( COLOR_3DFACE ); COLORREF colMenu = ::GetSysColor( COLOR_MENU ); @@ -1075,22 +1072,18 @@ void CMenuDrawer::DrawItem( DRAWITEMSTRUCT* lpdis ) BYTE valB = ((GetBValue(colFace) * 7 + GetBValue(colMenu) * 3) / 10); colIconBack = RGB(valR, valG, valB); } - HBRUSH hbr = ::CreateSolidBrush( colIconBack ); CMyRect rcIconBk( rcItem ); rcIconBk.right = rcItem.left + nIndentLeft; - ::FillRect( hdc, &rcIconBk, hbr ); - ::DeleteObject( hbr ); + ::MyFillRect( hdc, rcIconBk, colIconBack ); }else{ // アイテム矩形塗りつぶし - hBrush = ::GetSysColorBrush( COLOR_MENU ); - ::FillRect( hdc, &lpdis->rcItem, hBrush ); + ::MyFillRect( hdc, lpdis->rcItem, COLOR_MENU ); } #else }else{ - hBrush = ::GetSysColorBrush( COLOR_MENU ); - ::FillRect( hdc, &lpdis->rcItem, hBrush ); + ::MyFillRect( hdc, lpdis->rcItem, COLOR_MENU ); } #endif @@ -1212,8 +1205,7 @@ void CMenuDrawer::DrawItem( DRAWITEMSTRUCT* lpdis ) // フラットな枠 + 半透明の背景色 CMyRect rcFrame( rcIcon ); ::InflateRect( &rcFrame, cxEdge * 2, cyEdge * 2 ); - HBRUSH hBrush = ::GetSysColorBrush( COLOR_HIGHLIGHT ); - ::FillRect( hdc, &rcFrame, hBrush ); + ::MyFillRect( hdc, rcFrame, COLOR_HIGHLIGHT ); COLORREF colHilight = ::GetSysColor( COLOR_HIGHLIGHT ); COLORREF colMenu = ::GetSysColor( COLOR_MENU ); @@ -1232,9 +1224,7 @@ void CMenuDrawer::DrawItem( DRAWITEMSTRUCT* lpdis ) } CMyRect rcBkFrame( rcIcon ); ::InflateRect( &rcBkFrame, cxEdge , cyEdge ); - HBRUSH hbr = ::CreateSolidBrush( RGB(valR, valG, valB) ); - ::FillRect( hdc, &rcBkFrame, hbr ); - ::DeleteObject( hbr ); + ::MyFillRect( hdc, rcBkFrame, RGB( valR, valG, valB ) ); } } diff --git a/sakura_core/window/CSplitBoxWnd.cpp b/sakura_core/window/CSplitBoxWnd.cpp index 164d4fe34c..1e1794f651 100644 --- a/sakura_core/window/CSplitBoxWnd.cpp +++ b/sakura_core/window/CSplitBoxWnd.cpp @@ -14,6 +14,7 @@ */ #include "StdAfx.h" #include "window/CSplitBoxWnd.h" +#include "uiparts/CGraphics.h" CSplitBoxWnd::CSplitBoxWnd() : CWnd(_T("::CSplitBoxWnd")) @@ -80,21 +81,16 @@ HWND CSplitBoxWnd::Create( HINSTANCE hInstance, HWND hwndParent, int bVertical ) void CSplitBoxWnd::Draw3dRect( HDC hdc, int x, int y, int cx, int cy, COLORREF clrTopLeft, COLORREF clrBottomRight ) { - HBRUSH hBrush; RECT rc; - hBrush = ::CreateSolidBrush( clrTopLeft ); ::SetRect( &rc, x, y, x + cx - 1, y + 1 ); - ::FillRect( hdc, &rc, hBrush ); + ::MyFillRect( hdc, rc, clrTopLeft ); ::SetRect( &rc, x, y, x + 1, y + cy - 1 ); - ::FillRect( hdc, &rc, hBrush ); - ::DeleteObject( hBrush ); + ::MyFillRect( hdc, rc, clrTopLeft ); - hBrush = ::CreateSolidBrush( clrBottomRight ); ::SetRect( &rc, x + cx - 1, y, x + cx, y + cy ); - ::FillRect( hdc, &rc, hBrush ); + ::MyFillRect( hdc, rc, clrBottomRight ); ::SetRect( &rc, x, y + cy - 1, x + cx, y + cy ); - ::FillRect( hdc, &rc, hBrush ); - ::DeleteObject( hBrush ); + ::MyFillRect( hdc, rc, clrBottomRight ); return; } diff --git a/sakura_core/window/CSplitterWnd.cpp b/sakura_core/window/CSplitterWnd.cpp index 5ea507e500..0db3339cb8 100644 --- a/sakura_core/window/CSplitterWnd.cpp +++ b/sakura_core/window/CSplitterWnd.cpp @@ -21,6 +21,7 @@ #include "view/CEditView.h" #include "outline/CDlgFuncList.h" #include "env/DLLSHAREDATA.h" +#include "uiparts/CGraphics.h" constexpr auto SPLITTER_FRAME_WIDTH = 3; constexpr auto SPLITTER_MARGIN = 2; @@ -782,19 +783,16 @@ LRESULT CSplitterWnd::OnPaint( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPara RECT rc; RECT rcFrame; const int nFrameWidth = DpiScaleX(SPLITTER_FRAME_WIDTH); - HBRUSH hBrush; hdc = ::BeginPaint( hwnd, &ps ); ::GetClientRect( GetHwnd(), &rc ); - hBrush = ::CreateSolidBrush( ::GetSysColor( COLOR_3DFACE ) ); if( m_nAllSplitRows > 1 ){ ::SetRect( &rcFrame, rc.left, m_nVSplitPos, rc.right, m_nVSplitPos + nFrameWidth ); - ::FillRect( hdc, &rcFrame, hBrush ); + ::MyFillRect( hdc, rcFrame, COLOR_3DFACE ); } if( m_nAllSplitCols > 1 ){ ::SetRect( &rcFrame, m_nHSplitPos, rc.top, m_nHSplitPos + nFrameWidth, rc.bottom ); - ::FillRect( hdc, &rcFrame, hBrush ); + ::MyFillRect( hdc, rcFrame, COLOR_3DFACE ); } - ::DeleteObject( hBrush ); ::EndPaint(hwnd, &ps); return 0L; } diff --git a/sakura_core/window/CTabWnd.cpp b/sakura_core/window/CTabWnd.cpp index 17740b59af..ec6741c891 100644 --- a/sakura_core/window/CTabWnd.cpp +++ b/sakura_core/window/CTabWnd.cpp @@ -1279,7 +1279,7 @@ LRESULT CTabWnd::OnDrawItem( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam } // 背景描画 - ::FillRect( gr, &rcItem, (HBRUSH)(nSysClrBk + 1) ); + ::MyFillRect( gr, rcItem, nSysClrBk ); // アイコン描画 int cxIcon = CX_SMICON; @@ -1341,7 +1341,7 @@ LRESULT CTabWnd::OnDrawItem( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam // 背景描画 if( !IsVisualStyle() ) { - ::FillRect( gr, &rcItem, (HBRUSH)(COLOR_BTNFACE + 1) ); + ::MyFillRect( gr, rcItem, COLOR_BTNFACE ); }else{ CUxTheme& uxTheme = *CUxTheme::getInstance(); int iPartId = TABP_TABITEM; @@ -1587,7 +1587,7 @@ LRESULT CTabWnd::OnPaint( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) // 背景を描画する ::GetClientRect( hwnd, &rc ); - ::FillRect( gr, &rc, (HBRUSH)(COLOR_3DFACE + 1) ); + ::MyFillRect( gr, rc, COLOR_3DFACE ); // ボタンを描画する DrawListBtn( gr, &rc ); @@ -1634,9 +1634,7 @@ LRESULT CTabWnd::OnPaint( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) if( rcCurSel.left < rcCurSel.right ) { - HBRUSH hBr = ::CreateSolidBrush( RGB( 255, 128, 0 ) ); - ::FillRect( gr, &rcCurSel, hBr ); - ::DeleteObject( hBr ); + ::MyFillRect( gr, rcCurSel, RGB( 255, 128, 0 ) ); } } } From 16a7d55bfbe77e3d07f2323277649e995f649cac Mon Sep 17 00:00:00 2001 From: berryplus Date: Sun, 13 Jan 2019 15:37:47 +0900 Subject: [PATCH 3/8] =?UTF-8?q?CPropComToolbar=E3=83=AA=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=AF=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FillRect利用箇所周辺のコードをリファクタリング。 この関数は共通設定ツールバーのリストボックスを描画するためのもので、テキストとアイコンを描画する。 アイコン描画処理のためにSetBkColorする必要があるためFillRect⇒ExtTextOutの変更を行う。 --- sakura_core/prop/CPropComToolbar.cpp | 156 +++++++++++++-------------- 1 file changed, 76 insertions(+), 80 deletions(-) diff --git a/sakura_core/prop/CPropComToolbar.cpp b/sakura_core/prop/CPropComToolbar.cpp index 200d806f20..7219e7709b 100644 --- a/sakura_core/prop/CPropComToolbar.cpp +++ b/sakura_core/prop/CPropComToolbar.cpp @@ -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" @@ -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; } From 0ccf0b82f63987b4754237d92318d56759094f68 Mon Sep 17 00:00:00 2001 From: berryplus Date: Sun, 13 Jan 2019 19:45:38 +0900 Subject: [PATCH 4/8] =?UTF-8?q?=E5=9E=8B=E5=AE=9A=E7=BE=A9=E3=81=AE?= =?UTF-8?q?=E8=AA=A4=E3=82=8A=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 生APIを使う場合、sysColorはint型。 INT_PTR型で宣言するとx64ビルドで適切なオーバーロードを選択できずコンパイルエラーになってしまう。 他で必要があってINT_PTRとしているわけでもないのでintに変える。 --- sakura_core/window/CTabWnd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sakura_core/window/CTabWnd.cpp b/sakura_core/window/CTabWnd.cpp index ec6741c891..eb4ac36a02 100644 --- a/sakura_core/window/CTabWnd.cpp +++ b/sakura_core/window/CTabWnd.cpp @@ -1266,7 +1266,7 @@ LRESULT CTabWnd::OnDrawItem( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam // 状態に従ってテキストと背景色を決める COLORREF clrText; - INT_PTR nSysClrBk; + int nSysClrBk; if (lpdis->itemState & ODS_SELECTED) { clrText = ::GetSysColor( COLOR_HIGHLIGHTTEXT ); From 748604537a9e18f1e1287a762457320de62c932a Mon Sep 17 00:00:00 2001 From: berryplus Date: Sun, 20 Jan 2019 00:09:11 +0900 Subject: [PATCH 5/8] =?UTF-8?q?=E5=AE=9A=E7=BE=A9=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E7=A7=BB=E5=8B=95=E3=81=A8=E3=82=A8=E3=83=A9=E3=83=BC=E5=87=A6?= =?UTF-8?q?=E7=90=86=E6=8B=A1=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sakura_core/uiparts/CGraphics.h | 130 +++++++++++++++++--------------- 1 file changed, 70 insertions(+), 60 deletions(-) diff --git a/sakura_core/uiparts/CGraphics.h b/sakura_core/uiparts/CGraphics.h index a909765478..03c46da9de 100644 --- a/sakura_core/uiparts/CGraphics.h +++ b/sakura_core/uiparts/CGraphics.h @@ -30,8 +30,78 @@ */ #include +#include #include +/*! + * @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; + + HGDIOBJ hBrushOld = ::SelectObject( hDC, hBrush ); + if ( hBrushOld == HGDI_ERROR ) return false; + + 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 ) ); + + 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 TOriginalHolder{ @@ -72,9 +142,6 @@ struct SFONT { HFONT m_hFont; //!< フォントハンドル }; -// 先行定義 -inline bool MyFillRect( const HDC hDC, const RECT &rc, const HBRUSH hBrush ) noexcept; - //! 描画管理 //最新実装:ブラシ class CGraphics{ @@ -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]*/ From 4b9e524afca3c7397b6c41cdbf63003dbcef1c56 Mon Sep 17 00:00:00 2001 From: berryplus Date: Sun, 20 Jan 2019 15:10:57 +0900 Subject: [PATCH 6/8] =?UTF-8?q?assert=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sysColorは0から始まるので0を許容する必要がある。 --- sakura_core/uiparts/CGraphics.h | 1 - 1 file changed, 1 deletion(-) diff --git a/sakura_core/uiparts/CGraphics.h b/sakura_core/uiparts/CGraphics.h index 03c46da9de..6cbf09080c 100644 --- a/sakura_core/uiparts/CGraphics.h +++ b/sakura_core/uiparts/CGraphics.h @@ -67,7 +67,6 @@ inline bool MyFillRect( const HDC hDC, const RECT &rc, const HBRUSH hBrush ) noe inline bool MyFillRect( const HDC hDC, const RECT &rc, const int sysColor ) noexcept { assert( hDC ); - assert( sysColor ); assert( IS_INTRESOURCE( sysColor ) ); if ( !hDC || !IS_INTRESOURCE( sysColor ) ) return false; From 3956c024f44d6373b4dc1384b7852e629c976d58 Mon Sep 17 00:00:00 2001 From: berryplus Date: Sun, 20 Jan 2019 17:28:51 +0900 Subject: [PATCH 7/8] =?UTF-8?q?=E3=82=A8=E3=83=A9=E3=83=BC=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=81=AEIS=5FINTRESOURCE=E3=82=92=E3=82=84=E3=82=81?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sakura_core/uiparts/CGraphics.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sakura_core/uiparts/CGraphics.h b/sakura_core/uiparts/CGraphics.h index 6cbf09080c..b19d676df7 100644 --- a/sakura_core/uiparts/CGraphics.h +++ b/sakura_core/uiparts/CGraphics.h @@ -44,9 +44,8 @@ inline bool MyFillRect( const HDC hDC, const RECT &rc, const HBRUSH hBrush ) noe { assert( hDC ); assert( hBrush ); - assert( !IS_INTRESOURCE( hBrush ) ); - if ( !hDC || IS_INTRESOURCE( hBrush ) ) return false; + if ( !hDC || !hBrush ) return false; HGDIOBJ hBrushOld = ::SelectObject( hDC, hBrush ); if ( hBrushOld == HGDI_ERROR ) return false; @@ -67,9 +66,8 @@ inline bool MyFillRect( const HDC hDC, const RECT &rc, const HBRUSH hBrush ) noe inline bool MyFillRect( const HDC hDC, const RECT &rc, const int sysColor ) noexcept { assert( hDC ); - assert( IS_INTRESOURCE( sysColor ) ); - if ( !hDC || !IS_INTRESOURCE( sysColor ) ) return false; + if ( !hDC ) return false; HBRUSH hBrush = ::GetSysColorBrush( sysColor ); if ( hBrush == NULL ) return false; From 226af5991a7f6a84d8b53252bf8e9ceeca8165a3 Mon Sep 17 00:00:00 2001 From: berryplus Date: Sun, 20 Jan 2019 20:37:16 +0900 Subject: [PATCH 8/8] =?UTF-8?q?=E6=88=BB=E3=82=8A=E5=80=A4=E3=83=81?= =?UTF-8?q?=E3=82=A7=E3=83=83=E3=82=AF=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PatBltの戻り値をintからautoに変更。 --- sakura_core/uiparts/CGraphics.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sakura_core/uiparts/CGraphics.h b/sakura_core/uiparts/CGraphics.h index b19d676df7..a9f8acc7be 100644 --- a/sakura_core/uiparts/CGraphics.h +++ b/sakura_core/uiparts/CGraphics.h @@ -48,9 +48,9 @@ inline bool MyFillRect( const HDC hDC, const RECT &rc, const HBRUSH hBrush ) noe if ( !hDC || !hBrush ) return false; HGDIOBJ hBrushOld = ::SelectObject( hDC, hBrush ); - if ( hBrushOld == HGDI_ERROR ) return false; + if ( !hBrushOld || hBrushOld == HGDI_ERROR ) return false; - int retPatBlt = ::PatBlt( hDC, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, PATCOPY ); + auto retPatBlt = ::PatBlt( hDC, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, PATCOPY ); ::SelectObject( hDC, hBrushOld ); return retPatBlt != 0;