Skip to content

Commit c74ff2a

Browse files
committed
first commit
1 parent 70f126b commit c74ff2a

File tree

119 files changed

+23397
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+23397
-0
lines changed

controls.extend/ExtendCtrls.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include "stdafx.h"
2+
#include "ExtendCtrls.h"

controls.extend/ExtendCtrls.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
#include "core/SWnd.h"
3+
4+
namespace SOUI
5+
{
6+
class SWindowEx : public SWindow
7+
{
8+
public:
9+
SOUI_CLASS_NAME(SWindowEx, L"windowex")
10+
11+
protected:
12+
SOUI_MSG_MAP_BEGIN()
13+
MSG_WM_LBUTTONDBLCLK(OnLButtonDown) //˝ŤËŤť÷ĎűϢ´ŚŔíÎŞľĽť÷
14+
SOUI_MSG_MAP_END()
15+
};
16+
17+
};

controls.extend/ExtendSkins.cpp

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#include "stdafx.h"
2+
#include "souistd.h"
3+
#include "core/Sskin.h"
4+
#include "ExtendSkins.h"
5+
6+
//////////////////////////////////////////////////////////////////////////
7+
// SColorMask
8+
SColorMask::SColorMask()
9+
{
10+
m_crStates[0]=(RGB(0xEE, 0xEE, 0xEE));
11+
m_crStates[1]=(RGB(0xD6, 0xD6, 0xD6));
12+
m_crStates[2]=(RGB(0xEE, 0xEE, 0xEE));
13+
m_crStates[3]=(RGB(0xE0, 0xE0, 0xE0));
14+
}
15+
16+
void SColorMask::_Draw(IRenderTarget *pRT, LPCRECT prcDraw, DWORD dwState, BYTE byAlpha)
17+
{
18+
CRect rcDraw = *prcDraw;
19+
20+
//STRACE(_T("skin btn state:%d"), dwState);
21+
if (dwState >= 0 && dwState < STATE_COUNT && m_bmpSkin)
22+
{
23+
SColor cr(m_crStates[dwState]);
24+
cr.updateAlpha(byAlpha);
25+
26+
int nWidthPerState = m_size.cx / STATE_COUNT;
27+
CRect rcSrc(CPoint(dwState * nWidthPerState, 0), CSize(nWidthPerState, m_size.cy));
28+
pRT->DrawBitmapEx(rcDraw, m_bmpSkin, &rcSrc, EM_STRETCH, byAlpha);
29+
}
30+
}
31+
32+
void SColorMask::SetColors(COLORREF cr[4])
33+
{
34+
memcpy(m_crStates, cr, 4*sizeof(COLORREF));
35+
}
36+
37+
HRESULT SColorMask::OnAttrMask(const SStringW & strValue, BOOL bLoading)
38+
{
39+
SStringW strChannel = strValue.Right(2);
40+
m_iMaskChannel = -1;
41+
if(strChannel == L".a")
42+
m_iMaskChannel = 3;
43+
else if(strChannel == L".r")
44+
m_iMaskChannel =0;
45+
else if(strChannel == L".g")
46+
m_iMaskChannel = 1;
47+
else if(strChannel == L".b")
48+
m_iMaskChannel = 2;
49+
50+
IBitmap *pImg = NULL;
51+
if(m_iMaskChannel==-1)
52+
{//use alpha channel as default
53+
m_iMaskChannel = 0;
54+
pImg = LOADIMAGE2(strValue);
55+
}else
56+
{
57+
pImg = LOADIMAGE2(strValue.Left(strValue.GetLength()-2));
58+
}
59+
if(!pImg)
60+
{
61+
return E_FAIL;
62+
}
63+
m_bmpMask = pImg;
64+
pImg->Release();
65+
66+
MakeCacheApha();
67+
68+
return S_OK;
69+
}
70+
71+
void SColorMask::MakeCacheApha()
72+
{
73+
int nWidthPerSize = m_size.cx / STATE_COUNT;
74+
75+
m_bmpSkin = NULL;
76+
GETRENDERFACTORY->CreateBitmap(&m_bmpSkin);
77+
m_bmpSkin->Init(m_size.cx, m_size.cy);
78+
79+
// 创建画布并把skin选进画布
80+
CAutoRefPtr<IRenderTarget> pRTDst;
81+
GETRENDERFACTORY->CreateRenderTarget(&pRTDst,0,0);
82+
CAutoRefPtr<IRenderObj> pOldBmp;
83+
pRTDst->SelectObject(m_bmpSkin,&pOldBmp);
84+
for (int i = 0; i < STATE_COUNT; ++i)
85+
{
86+
CRect rc(CPoint(i * nWidthPerSize, 0), m_size);
87+
SColor cr(m_crStates[i]);
88+
pRTDst->FillSolidRect(&rc, cr.toCOLORREF());
89+
}
90+
pRTDst->SelectObject(pOldBmp);
91+
92+
//从mask的指定channel中获得alpha通道,与cache按位运算
93+
LPBYTE pBitCache = (LPBYTE)m_bmpSkin->LockPixelBits();
94+
LPBYTE pBitMask = (LPBYTE)m_bmpMask->LockPixelBits();
95+
96+
int cx = m_bmpMask->Width() < m_bmpSkin->Width() ? m_bmpMask->Width() : m_bmpSkin->Width();
97+
int cy = m_bmpMask->Height() < m_bmpSkin->Height() ? m_bmpMask->Height() : m_bmpSkin->Height();
98+
99+
for (int i = 0; i < STATE_COUNT; ++i)
100+
{
101+
for (int y = 0; y < cy; ++y)
102+
{
103+
LPBYTE pDst = pBitCache + (y * m_bmpSkin->Width() + i * nWidthPerSize) * 4;
104+
LPBYTE pSrc = pBitMask + y * m_bmpMask->Width() * 4 + m_iMaskChannel;
105+
106+
for (int x = 0; x < cx; ++x)
107+
{
108+
BYTE byAlpha = *pSrc;
109+
pSrc += 4;
110+
111+
*pDst++ = ((*pDst) * byAlpha)>>8;//做premutiply
112+
*pDst++ = ((*pDst) * byAlpha)>>8;//做premutiply
113+
*pDst++ = ((*pDst) * byAlpha)>>8;//做premutiply
114+
*pDst++ = byAlpha;
115+
}
116+
}
117+
}
118+
119+
m_bmpSkin->UnlockPixelBits(pBitCache);
120+
m_bmpMask->UnlockPixelBits(pBitMask);
121+
}

controls.extend/ExtendSkins.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#pragma once
2+
3+
#include "core/SSkinObjBase.h"
4+
5+
namespace SOUI
6+
{
7+
8+
class SColorMask : public SSkinObjBase
9+
{
10+
#define STATE_COUNT 4
11+
SOUI_CLASS_NAME(SColorMask, L"colormask")
12+
13+
enum{
14+
ST_NORMAL=0,
15+
ST_HOVER,
16+
ST_PUSHDOWN,
17+
ST_DISABLE,
18+
};
19+
20+
public:
21+
SColorMask();
22+
virtual BOOL IgnoreState() { return FALSE; }
23+
virtual int GetStates() { return STATE_COUNT;}
24+
virtual SIZE GetSkinSize() { return m_size; }
25+
26+
void SetColors(COLORREF cr[4]);
27+
28+
protected:
29+
virtual void _Draw(IRenderTarget *pRT, LPCRECT rcDraw, DWORD dwState,BYTE byAlpha);
30+
HRESULT OnAttrMask(const SStringW & strValue,BOOL bLoading);
31+
void MakeCacheApha();
32+
33+
COLORREF m_crStates[STATE_COUNT];
34+
SIZE m_size;
35+
36+
SOUI_ATTRS_BEGIN()
37+
ATTR_COLOR(L"colorNormal", m_crStates[0], TRUE)
38+
ATTR_COLOR(L"colorHover", m_crStates[1], TRUE)
39+
ATTR_COLOR(L"colorDown", m_crStates[2], TRUE)
40+
ATTR_COLOR(L"colorDisable", m_crStates[3], TRUE)
41+
ATTR_INT(L"width", m_size.cx, 0)
42+
ATTR_INT(L"height", m_size.cy, 0)
43+
ATTR_CUSTOM(L"mask", OnAttrMask)
44+
ATTR_RECT(L"margin" ,m_rcMargin,FALSE) //¾Å¹¬¸ñ4ÖÜ
45+
SOUI_ATTRS_END()
46+
47+
//CAutoRefPtr<IBitmap> * m_pBmpCaches;
48+
49+
SStringW m_strSkin;
50+
CAutoRefPtr<IBitmap> m_bmpSkin;
51+
CAutoRefPtr<IBitmap> m_bmpMask;
52+
CRect m_rcMargin;
53+
int m_iMaskChannel;
54+
};
55+
56+
};

controls.extend/FileHelper.h

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* Copyright (C) 2014-2050
3+
* All rights reserved.
4+
*
5+
* @file FileHelper.h
6+
* @brief
7+
* @version v1.0
8+
* @author SOUI group
9+
* @date 2014/08/03
10+
*
11+
* Describe 实现两个文件相关的helper
12+
*/
13+
14+
#pragma once
15+
16+
#include <commdlg.h>
17+
/**
18+
* BuildFilePath
19+
* @brief 递归创建子目录
20+
* @param LPCTSTR pszCurPath -- 创建路径的起始位置
21+
* @param LPCTSTR pszNewPath -- 新路径
22+
* @param BOOL bPath -- pszNewPath是一个路径标识
23+
* @return BOOL -- true创建成功
24+
* Describe pszNewPath指向一个文件名时,只创建文件路径部分
25+
*/
26+
inline BOOL BuildFilePath(LPCTSTR pszCurPath,LPCTSTR pszNewPath,BOOL bPath=TRUE)
27+
{
28+
TCHAR szCurDir[MAX_PATH+1];
29+
GetCurrentDirectory(MAX_PATH,szCurDir);
30+
if(!SetCurrentDirectory(pszCurPath)) return FALSE;
31+
TCHAR szNewPath[MAX_PATH+1];
32+
_tcscpy_s(szNewPath,_countof(szNewPath),pszNewPath);
33+
if(bPath)
34+
{
35+
int nLen=_tcslen(szNewPath);
36+
if(szNewPath[nLen-1]!=_T('\\'))
37+
_tcscat(szNewPath,_T("\\"));
38+
}
39+
LPTSTR pszPath=_tcschr(szNewPath,_T('\\'));
40+
while(pszPath)
41+
{
42+
*pszPath=0;
43+
if(!CreateDirectory(szNewPath,NULL)) return FALSE;
44+
*pszPath=_T('\\');
45+
pszPath=_tcschr(pszPath+1,_T('\\'));
46+
}
47+
SetCurrentDirectory(szCurDir);
48+
return TRUE;
49+
}
50+
51+
class CFileDialogEx
52+
{
53+
public:
54+
55+
OPENFILENAME m_ofn;
56+
BOOL m_bOpenFileDialog; // TRUE for file open, FALSE for file save
57+
TCHAR m_szFileTitle[_MAX_FNAME]; // contains file title after return
58+
TCHAR m_szFileName[_MAX_PATH]; // contains full path name after return
59+
60+
CFileDialogEx(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
61+
LPCTSTR lpszDefExt = NULL,
62+
LPCTSTR lpszFileName = NULL,
63+
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT ,
64+
LPCTSTR lpszFilter = NULL,
65+
HWND hWndParent = NULL)
66+
{
67+
memset(&m_ofn, 0, sizeof(m_ofn)); // initialize structure to 0/NULL
68+
m_szFileName[0] = _T('\0');
69+
m_szFileTitle[0] = _T('\0');
70+
71+
m_bOpenFileDialog = bOpenFileDialog;
72+
m_ofn.lStructSize = sizeof(m_ofn);
73+
m_ofn.lpstrFile = m_szFileName;
74+
m_ofn.nMaxFile = _MAX_PATH;
75+
m_ofn.lpstrDefExt = lpszDefExt;
76+
m_ofn.lpstrFileTitle = (LPTSTR)m_szFileTitle;
77+
m_ofn.nMaxFileTitle = _MAX_FNAME;
78+
m_ofn.Flags = dwFlags | OFN_EXPLORER | OFN_ENABLEHOOK | OFN_ENABLESIZING| OFN_NOCHANGEDIR;
79+
m_ofn.lpstrFilter = lpszFilter;
80+
m_ofn.hwndOwner = hWndParent;
81+
82+
// setup initial file name
83+
if(lpszFileName != NULL)
84+
_tcscpy_s(m_szFileName, _countof(m_szFileName), lpszFileName);
85+
}
86+
87+
INT_PTR DoModal(HWND hWndParent = ::GetActiveWindow())
88+
{
89+
if(m_ofn.hwndOwner == NULL) // set only if not specified before
90+
m_ofn.hwndOwner = hWndParent;
91+
92+
if(m_bOpenFileDialog)
93+
return ::GetOpenFileName(&m_ofn);
94+
else
95+
return ::GetSaveFileName(&m_ofn);
96+
}
97+
};

controls.extend/SAnimImg.cpp

6.8 KB
Binary file not shown.

controls.extend/SAnimImg.h

3.36 KB
Binary file not shown.

controls.extend/SAnimator.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#pragma once
2+
3+
namespace SOUI
4+
{
5+
class SAnimator
6+
{
7+
public:
8+
enum {
9+
ABORT = -1,
10+
PER_START = 0,
11+
PER_END = 100,
12+
};
13+
14+
typedef void (*AnimatorStateHandler)(int percent,LPARAM lp);
15+
16+
SAnimator():m_uDuration(0),m_funAnimatorStateHandler(NULL),m_lpUserdata(0){}
17+
18+
virtual ~SAnimator(){}
19+
20+
void Start(UINT uDuration)
21+
{
22+
m_dwStart = GetTickCount();
23+
m_uDuration = uDuration;
24+
OnAnimatorState(PER_START);
25+
}
26+
27+
void Stop()
28+
{
29+
if(!IsBusy()) return;
30+
m_uDuration =0;
31+
OnAnimatorState(ABORT);
32+
}
33+
34+
void SetAnimatorHandler(AnimatorStateHandler funHandler,LPARAM lpUserData)
35+
{
36+
m_funAnimatorStateHandler = funHandler;
37+
m_lpUserdata =lpUserData;
38+
}
39+
40+
BOOL IsBusy(){return m_uDuration != 0;}
41+
42+
BOOL Update()
43+
{
44+
if(m_uDuration == 0) return FALSE;
45+
46+
DWORD dwElapse = GetTickCount() - m_dwStart;
47+
if(dwElapse >= m_uDuration)
48+
{
49+
OnAnimatorState(100);
50+
m_uDuration = 0;
51+
}else
52+
{
53+
OnAnimatorState(dwElapse*100/m_uDuration);
54+
}
55+
return TRUE;
56+
}
57+
58+
//¶¯»­×´Ì¬¸Ä±ä£¬percent in [0,100]
59+
virtual void OnAnimatorState(int percent)
60+
{
61+
if(m_funAnimatorStateHandler) m_funAnimatorStateHandler(percent,m_lpUserdata);
62+
}
63+
private:
64+
DWORD m_dwStart;
65+
DWORD m_uDuration;
66+
LPARAM m_lpUserdata;
67+
AnimatorStateHandler m_funAnimatorStateHandler;
68+
};
69+
}

0 commit comments

Comments
 (0)