Skip to content

Commit

Permalink
Merge pull request #1411 from beru/CGraphics_SaveDC_RestoreDC
Browse files Browse the repository at this point in the history
CGraphics 関連の最適化
  • Loading branch information
beru authored Sep 27, 2020
2 parents 120a20c + ad4537a commit 470a1ff
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 21 deletions.
3 changes: 1 addition & 2 deletions sakura_core/view/CEditView.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ class CEditView
protected:
//! ロジック行を1行描画
bool DrawLogicLine(
HDC hdc, //!< [in] 作画対象
DispPos* pDispPos, //!< [in,out] 描画する箇所、描画元ソース
SColorStrategyInfo* pInfo, //!< [in,out] 作画情報
CLayoutInt nLineTo //!< [in] 作画終了するレイアウト行番号
);

Expand Down
14 changes: 5 additions & 9 deletions sakura_core/view/CEditView_Paint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,15 +779,17 @@ void CEditView::OnPaint2( HDC _hdc, PAINTSTRUCT *pPs, BOOL bDrawFromComptibleBmp
sPos.ForwardLayoutLineRef(1); //レイアウト行++
}
}else{
SColorStrategyInfo sInfo(gr);
sInfo.m_pDispPos = &sPos;
sInfo.m_pcView = this;
while(sPos.GetLayoutLineRef() <= nLayoutLineTo)
{
//描画X位置リセット
sPos.ResetDrawCol();

//1行描画
bool bDispResult = DrawLogicLine(
gr,
&sPos,
&sInfo,
nLayoutLineTo
);

Expand Down Expand Up @@ -871,18 +873,12 @@ void CEditView::OnPaint2( HDC _hdc, PAINTSTRUCT *pPs, BOOL bDrawFromComptibleBmp
@date 2007.08.31 kobake 引数 bDispBkBitmap を削除
*/
bool CEditView::DrawLogicLine(
HDC _hdc, //!< [in] 作画対象
DispPos* _pDispPos, //!< [in,out] 描画する箇所、描画元ソース
SColorStrategyInfo* pInfo, //!< [in,out] 作画情報
CLayoutInt nLineTo //!< [in] 作画終了するレイアウト行番号
)
{
// MY_RUNNINGTIMER( cRunningTimer, "CEditView::DrawLogicLine" );
bool bDispEOF = false;
SColorStrategyInfo _sInfo;
SColorStrategyInfo* pInfo = &_sInfo;
pInfo->m_gr.Init(_hdc);
pInfo->m_pDispPos = _pDispPos;
pInfo->m_pcView = this;

//CColorStrategyPool初期化
CColorStrategyPool* pool = CColorStrategyPool::getInstance();
Expand Down
3 changes: 1 addition & 2 deletions sakura_core/view/CEditView_Paint_Bracket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ void CEditView::DrawBracketPair( bool bDraw )
return;
}

CGraphics gr;
gr.Init(::GetDC(GetHwnd()));
CGraphics gr(::GetDC(GetHwnd()));
bool bCaretChange = false;
gr.SetTextBackTransparent(true);

Expand Down
9 changes: 8 additions & 1 deletion sakura_core/view/colors/CColorStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ struct CColor3Setting {
};

struct SColorStrategyInfo{
SColorStrategyInfo() : m_sDispPosBegin(0,0), m_pStrategy(NULL), m_pStrategyFound(NULL), m_pStrategySelect(NULL), m_colorIdxBackLine(COLORIDX_TEXT) {
SColorStrategyInfo(HDC hDC = NULL)
: m_sDispPosBegin(0,0)
, m_pStrategy(NULL)
, m_pStrategyFound(NULL)
, m_pStrategySelect(NULL)
, m_colorIdxBackLine(COLORIDX_TEXT)
, m_gr(hDC)
{
m_cIndex.eColorIndex = COLORIDX_TEXT;
m_cIndex.eColorIndex2 = COLORIDX_TEXT;
m_cIndex.eColorIndexBg = COLORIDX_TEXT;
Expand Down
25 changes: 18 additions & 7 deletions sakura_core/view/figures/CFigure_Eol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void _DispWrap(CGraphics& gr, DispPos* pDispPos, const CEditView* pcView);

//改行記号描画
//2007.08.30 kobake 追加
void _DispEOL(CGraphics& gr, DispPos* pDispPos, CEol cEol, const CEditView* pcView, bool bTrans);
void _DispEOL(CGraphics& gr, DispPos* pDispPos, CEol cEol, const CEditView* pcView, bool bTrans, HPEN hPen);

// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- //
// CFigure_Eol //
Expand Down Expand Up @@ -113,7 +113,16 @@ bool CFigure_Eol::DrawImp(SColorStrategyInfo* pInfo)
pInfo->m_gr.PushMyFont(sFont);

DispPos sPos(*pInfo->m_pDispPos); // 現在位置を覚えておく
_DispEOL(pInfo->m_gr, pInfo->m_pDispPos, cEol, pcView, bTrans);

if (crText != m_clrPen || m_hPen == NULL) {
if (m_hPen != NULL) {
::DeleteObject(m_hPen);
}
m_hPen = CreatePen(PS_SOLID, 1, crText);
m_clrPen = crText;
}

_DispEOL(pInfo->m_gr, pInfo->m_pDispPos, cEol, pcView, bTrans, m_hPen);
DrawImp_StylePop(pInfo);
DrawImp_DrawUnderline(pInfo, sPos);

Expand Down Expand Up @@ -252,11 +261,11 @@ void _DrawEOL(
const CMyRect& rcEol,
CEol cEol,
bool bBold,
COLORREF pColor
HPEN hPen
);

//2007.08.30 kobake 追加
void _DispEOL(CGraphics& gr, DispPos* pDispPos, CEol cEol, const CEditView* pcView, bool bTrans)
void _DispEOL(CGraphics& gr, DispPos* pDispPos, CEol cEol, const CEditView* pcView, bool bTrans, HPEN hPen)
{
const CLayoutXInt nCol = CTypeSupport(pcView,COLORIDX_EOL).IsDisp()
? pcView->GetTextMetrics().GetLayoutXDefault(CKetaXInt(1)) + CLayoutXInt(4) // ONのときは1幅+4px
Expand Down Expand Up @@ -293,7 +302,7 @@ void _DispEOL(CGraphics& gr, DispPos* pDispPos, CEol cEol, const CEditView* pcVi
// 文字色や太字かどうかを現在の DC から調べる // 2009.05.29 ryoji
// (検索マッチ等の状況に柔軟に対応するため、ここは記号の色指定には決め打ちしない)
// 2013.06.21 novice 文字色、太字をCGraphicsから取得
_DrawEOL(gr, rcEol, cEol, gr.GetCurrentMyFontBold(), gr.GetCurrentTextForeColor());
_DrawEOL(gr, rcEol, cEol, gr.GetCurrentMyFontBold(), hPen);

// リージョン破棄
gr.PopClipping();
Expand Down Expand Up @@ -322,11 +331,11 @@ void _DrawEOL(
const CMyRect& rcEol, //!< 描画領域
CEol cEol, //!< 行末コード種別
bool bBold, //!< TRUE: 太字
COLORREF pColor //!<
HPEN hPen //!< ペン
)
{
int sx, sy; // 矢印の先頭
gr.SetPen( pColor );
HPEN hPenOld = (HPEN)SelectObject(gr, hPen);

switch( cEol.GetType() ){
case EOL_CRLF: // 下左矢印
Expand Down Expand Up @@ -471,4 +480,6 @@ void _DrawEOL(
}
break;
}

SelectObject(gr, hPenOld);
}
9 changes: 9 additions & 0 deletions sakura_core/view/figures/CFigure_Eol.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
//! 改行描画
class CFigure_Eol : public CFigureSpace{
public:
~CFigure_Eol()
{
if (m_hPen) {
::DeleteObject(m_hPen);
}
}
//traits
bool Match(const wchar_t* pText, int nTextLen) const;
bool Disp(void) const
Expand All @@ -42,5 +48,8 @@ class CFigure_Eol : public CFigureSpace{
bool DrawImp(SColorStrategyInfo* pInfo);
void DispSpace(CGraphics& gr, DispPos* pDispPos, CEditView* pcView, bool bTrans) const {};
EColorIndexType GetColorIdx(void) const{ return COLORIDX_EOL; }
private:
HPEN m_hPen = NULL;
COLORREF m_clrPen;
};
#endif /* SAKURA_CFIGURE_EOL_C51A4502_29AE_4D38_8056_5B0CFCC3686B_H_ */

0 comments on commit 470a1ff

Please sign in to comment.