Skip to content

Commit

Permalink
调整由008提供的dpi处理的实现。
Browse files Browse the repository at this point in the history
  • Loading branch information
setoutsoft committed Jan 3, 2019
1 parent 8aeac10 commit e32886f
Show file tree
Hide file tree
Showing 8 changed files with 854 additions and 588 deletions.
3 changes: 3 additions & 0 deletions SOUI/SOUI.pro
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ HEADERS += include/SApp.h \
include/helper/sdibhelper.h \
include/helper/unknown.h \
include/helper/SFunctor.hpp \
include/helper/sdpiscale.h \
include/helper/sdpihelper.hpp \
include/interface/imgdecoder-i.h \
include/interface/render-i.h \
include/interface/SResProvider-i.h \
Expand Down Expand Up @@ -238,6 +240,7 @@ SOURCES += src/SApp.cpp \
src/helper/smenuex.cpp \
src/helper/smatrix.cpp \
src/helper/sdibhelper.cpp \
src/helper/sdpiscale.cpp \
src/res.mgr/SUiDef.cpp \
src/res.mgr/SFontPool.cpp \
src/res.mgr/SObjDefAttr.cpp \
Expand Down
2 changes: 1 addition & 1 deletion SOUI/include/control/SCmnCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ class SOUI_EXP SToggle : public SWindow
virtual CSize GetDesiredSize(LPCRECT pRcContainer);
virtual BOOL NeedRedrawWhenStateChange(){return TRUE;}
virtual void OnColorize(COLORREF cr);
virtual void SToggle::OnScaleChanged(int nScale);
virtual void OnScaleChanged(int nScale);

SOUI_ATTRS_BEGIN()
ATTR_INT(L"toggled", m_bToggled, TRUE)
Expand Down
8 changes: 0 additions & 8 deletions SOUI/include/core/SHostDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,4 @@ namespace SOUI

SMessageLoop * m_MsgLoop;
};

class SOUI_EXP SDpiHostDialog :public SDpiHeler<SDpiHostDialog>,public SHostDialog
{
BEGIN_MSG_MAP_EX(SDpiHostDialog)
CHAIN_MSG_MAP(SHostDialog)
CHAIN_MSG_MAP(SDpiHeler<SDpiHostDialog>)
END_MSG_MAP()
};
}
76 changes: 1 addition & 75 deletions SOUI/include/core/SHostWnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ class SOUI_EXP SHostWnd
IToolTip * GetToolTip() const {
return m_pTipCtrl;
}
virtual int GetScale() const;
protected://辅助函数
BOOL _InitFromXml(pugi::xml_node xmlNode,int nWidth,int nHeight);
void _Redraw();
Expand Down Expand Up @@ -320,7 +319,7 @@ class SOUI_EXP SHostWnd

virtual IScriptModule * GetScriptModule();


virtual int GetScale() const;
protected://Swindow 虚方法
virtual void BeforePaint(IRenderTarget *pRT, SPainter &painter);
virtual void AfterPaint(IRenderTarget *pRT, SPainter &painter);
Expand Down Expand Up @@ -379,78 +378,5 @@ class SOUI_EXP SHostWnd


};
const int SKBuiltinScales[] =
{
100,125,150,200,250,300
};
template <class T>
class SOUI_EXP SDpiHeler
{
/*标准化放大比例, 选择比自己指定比例小一号的比例*/
int NormalizeScale(int nScale)
{
for (int i = 1; i < ARRAYSIZE(SKBuiltinScales); i++)
{
if (nScale < SKBuiltinScales[i])
{
return SKBuiltinScales[i - 1];
}
}
return SKBuiltinScales[ARRAYSIZE(SKBuiltinScales) - 1];
}

protected:
void OnDipChanged(WORD dpi, const RECT* desRect)
{
T *pT = static_cast<T*>(this);

int nScale = dpi * 100 / 96;
nScale = NormalizeScale(nScale);
OnScaleChanged(nScale, desRect);
}
//能过重写些函数来屏蔽一些不处理的DPI。。比如只支持 100 150 200。。。所有都支持基本不现实
virtual void OnScaleChanged(WORD nScale, const RECT *desRect)
{
T *pT = static_cast<T*>(this);

if (nScale != pT->GetScale())
{
//pT->OnScaleChanged(nScale);
pT->SDispatchMessage(UM_SETSCALE, nScale, 0);
pT->SetWindowPos(
NULL,
desRect->left,
desRect->top,
desRect->right - desRect->left,
desRect->bottom - desRect->top,
SWP_NOZORDER | SWP_NOACTIVATE);
}
}
public:
BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lResult, DWORD dwMsgMapID = 0)
{
BOOL bHandled = TRUE;

switch (dwMsgMapID)
{
case 0:
if (uMsg == WM_DPICHANGED)
{
OnDipChanged((WORD)HIWORD(wParam), (RECT* const)lParam);
lResult = 0;
}
break;
}
return FALSE;
}
};

class SOUI_EXP SDpiHostWnd :public SDpiHeler<SDpiHostWnd>, public SHostWnd
{
BEGIN_MSG_MAP_EX(SDpiHostWnd)
CHAIN_MSG_MAP(SHostWnd)
CHAIN_MSG_MAP(SDpiHeler<SDpiHostWnd>)
END_MSG_MAP()
};

}//namespace SOUI
Loading

0 comments on commit e32886f

Please sign in to comment.