UILabel.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. #include "StdAfx.h"
  2. #include "UILabel.h"
  3. // UMU: DO NOT use "using namespace" in .h file
  4. #ifdef _USE_GDIPLUS
  5. using namespace Gdiplus;
  6. #endif
  7. namespace DuiLib
  8. {
  9. Color ARGB2Color(DWORD dwColor)
  10. {
  11. return Color(HIBYTE((dwColor)>>16), GetBValue(dwColor), GetGValue(dwColor), GetRValue(dwColor));
  12. }
  13. CLabelUI::CLabelUI() :
  14. m_pWideText(0),
  15. m_uTextStyle(DT_VCENTER|DT_SINGLELINE),
  16. m_dwTextColor(0),
  17. m_dwDisabledTextColor(0),
  18. m_iFont(-1),
  19. m_bShowHtml(false),
  20. m_bNeedEstimateSize(true),
  21. m_EnableEffect(false),
  22. m_bEnableLuminous(false),
  23. m_fLuminousFuzzy(3),
  24. m_gdiplusToken(0),
  25. m_dwTextColor1(-1),
  26. m_dwTextShadowColorA(0xff000000),
  27. m_dwTextShadowColorB(-1),
  28. m_GradientAngle(0),
  29. m_EnabledStroke(false),
  30. m_dwStrokeColor(0),
  31. m_EnabledShadow(false),
  32. m_GradientLength(0)
  33. {
  34. m_ShadowOffset.X = 0.0f;
  35. m_ShadowOffset.Y = 0.0f;
  36. m_ShadowOffset.Width = 0.0f;
  37. m_ShadowOffset.Height = 0.0f;
  38. m_cxyFixedLast.cx = m_cxyFixedLast.cy = 0;
  39. m_szAvailableLast.cx = m_szAvailableLast.cy = 0;
  40. ::ZeroMemory(&m_rcTextPadding, sizeof(m_rcTextPadding));
  41. #ifdef _USE_GDIPLUS
  42. GdiplusStartup( &m_gdiplusToken,&m_gdiplusStartupInput, NULL);
  43. #endif
  44. }
  45. CLabelUI::~CLabelUI()
  46. {
  47. #ifdef _UNICODE
  48. if( m_pWideText && m_pWideText != m_sText.GetData()) delete[] m_pWideText;
  49. #else
  50. if( m_pWideText ) delete[] m_pWideText;
  51. #endif
  52. #ifdef _USE_GDIPLUS
  53. GdiplusShutdown( m_gdiplusToken );
  54. #endif
  55. }
  56. LPCTSTR CLabelUI::GetClass() const
  57. {
  58. return DUI_CTR_LABEL;
  59. }
  60. LPVOID CLabelUI::GetInterface(LPCTSTR pstrName)
  61. {
  62. if( _tcscmp(pstrName, DUI_CTR_LABEL) == 0 ) return static_cast<CLabelUI*>(this);
  63. return CControlUI::GetInterface(pstrName);
  64. }
  65. void CLabelUI::SetFixedWidth(int cx)
  66. {
  67. m_bNeedEstimateSize = true;
  68. CControlUI::SetFixedWidth(cx);
  69. }
  70. void CLabelUI::SetFixedHeight(int cy)
  71. {
  72. m_bNeedEstimateSize = true;
  73. CControlUI::SetFixedHeight(cy);
  74. }
  75. void CLabelUI::SetText(LPCTSTR pstrText)
  76. {
  77. CControlUI::SetText(pstrText);
  78. m_bNeedEstimateSize = true;
  79. if( m_EnableEffect) {
  80. #ifdef _UNICODE
  81. m_pWideText = (LPWSTR)m_sText.GetData();
  82. #else
  83. int iLen = _tcslen(pstrText);
  84. if (m_pWideText) delete[] m_pWideText;
  85. m_pWideText = new WCHAR[iLen + 1];
  86. ::ZeroMemory(m_pWideText, (iLen + 1) * sizeof(WCHAR));
  87. ::MultiByteToWideChar(CP_ACP, 0, pstrText, -1, (LPWSTR)m_pWideText, iLen);
  88. #endif
  89. }
  90. }
  91. void CLabelUI::SetTextStyle(UINT uStyle)
  92. {
  93. m_uTextStyle = uStyle;
  94. m_bNeedEstimateSize = true;
  95. Invalidate();
  96. }
  97. UINT CLabelUI::GetTextStyle() const
  98. {
  99. return m_uTextStyle;
  100. }
  101. bool CLabelUI::IsMultiLine()
  102. {
  103. return (m_uTextStyle & DT_SINGLELINE) == 0;
  104. }
  105. void CLabelUI::SetMultiLine(bool bMultiLine)
  106. {
  107. if (bMultiLine) {
  108. m_uTextStyle &= ~DT_SINGLELINE;
  109. m_uTextStyle |= DT_WORDBREAK;
  110. }
  111. else m_uTextStyle |= DT_SINGLELINE;
  112. m_bNeedEstimateSize = true;
  113. }
  114. void CLabelUI::SetTextColor(DWORD dwTextColor)
  115. {
  116. m_dwTextColor = dwTextColor;
  117. Invalidate();
  118. }
  119. DWORD CLabelUI::GetTextColor() const
  120. {
  121. return m_dwTextColor;
  122. }
  123. void CLabelUI::SetDisabledTextColor(DWORD dwTextColor)
  124. {
  125. m_dwDisabledTextColor = dwTextColor;
  126. Invalidate();
  127. }
  128. DWORD CLabelUI::GetDisabledTextColor() const
  129. {
  130. return m_dwDisabledTextColor;
  131. }
  132. void CLabelUI::SetFont(int index)
  133. {
  134. m_iFont = index;
  135. m_bNeedEstimateSize = true;
  136. Invalidate();
  137. }
  138. int CLabelUI::GetFont() const
  139. {
  140. return m_iFont;
  141. }
  142. RECT CLabelUI::GetTextPadding() const
  143. {
  144. return m_rcTextPadding;
  145. }
  146. void CLabelUI::SetTextPadding(RECT rc)
  147. {
  148. m_rcTextPadding = rc;
  149. m_bNeedEstimateSize = true;
  150. Invalidate();
  151. }
  152. bool CLabelUI::IsShowHtml()
  153. {
  154. return m_bShowHtml;
  155. }
  156. void CLabelUI::SetShowHtml(bool bShowHtml)
  157. {
  158. if( m_bShowHtml == bShowHtml ) return;
  159. m_bShowHtml = bShowHtml;
  160. m_bNeedEstimateSize = true;
  161. Invalidate();
  162. }
  163. SIZE CLabelUI::EstimateSize(SIZE szAvailable)
  164. {
  165. if (m_cxyFixed.cx > 0 && m_cxyFixed.cy > 0) return m_cxyFixed;
  166. if ((m_uTextStyle & DT_SINGLELINE) == 0 &&
  167. (szAvailable.cx != m_szAvailableLast.cx || szAvailable.cy != m_szAvailableLast.cy)) {
  168. m_bNeedEstimateSize = true;
  169. }
  170. if (m_bNeedEstimateSize) {
  171. m_bNeedEstimateSize = false;
  172. m_szAvailableLast = szAvailable;
  173. m_cxyFixedLast = m_cxyFixed;
  174. if ((m_uTextStyle & DT_SINGLELINE) != 0) {
  175. if (m_cxyFixedLast.cy == 0) {
  176. m_cxyFixedLast.cy = m_pManager->GetFontInfo(m_iFont)->tm.tmHeight + 8;
  177. m_cxyFixedLast.cy += m_rcTextPadding.top + m_rcTextPadding.bottom;
  178. }
  179. if (m_cxyFixedLast.cx == 0) {
  180. RECT rcText = { 0, 0, 9999, m_cxyFixedLast.cy };
  181. if( m_bShowHtml ) {
  182. int nLinks = 0;
  183. CRenderEngine::DrawHtmlText(m_pManager->GetPaintDC(), m_pManager, rcText, m_sText, 0, NULL, NULL, nLinks, m_iFont, DT_CALCRECT | m_uTextStyle & ~DT_RIGHT & ~DT_CENTER);
  184. }
  185. else {
  186. CRenderEngine::DrawText(m_pManager->GetPaintDC(), m_pManager, rcText, m_sText, 0, m_iFont, DT_CALCRECT | m_uTextStyle & ~DT_RIGHT & ~DT_CENTER);
  187. }
  188. m_cxyFixedLast.cx = rcText.right - rcText.left + m_rcTextPadding.left + m_rcTextPadding.right;
  189. }
  190. }
  191. else {
  192. if( m_cxyFixedLast.cx == 0 ) {
  193. m_cxyFixedLast.cx = szAvailable.cx;
  194. }
  195. RECT rcText = { 0, 0, m_cxyFixedLast.cx, 9999 };
  196. rcText.left += m_rcTextPadding.left;
  197. rcText.right -= m_rcTextPadding.right;
  198. if( m_bShowHtml ) {
  199. int nLinks = 0;
  200. CRenderEngine::DrawHtmlText(m_pManager->GetPaintDC(), m_pManager, rcText, m_sText, 0, NULL, NULL, nLinks, m_iFont, DT_CALCRECT | m_uTextStyle & ~DT_RIGHT & ~DT_CENTER);
  201. }
  202. else {
  203. CRenderEngine::DrawText(m_pManager->GetPaintDC(), m_pManager, rcText, m_sText, 0, m_iFont, DT_CALCRECT | m_uTextStyle & ~DT_RIGHT & ~DT_CENTER);
  204. }
  205. m_cxyFixedLast.cy = rcText.bottom - rcText.top + m_rcTextPadding.top + m_rcTextPadding.bottom;
  206. }
  207. }
  208. return m_cxyFixedLast;
  209. }
  210. void CLabelUI::DoEvent(TEventUI& event)
  211. {
  212. if( event.Type == UIEVENT_SETFOCUS )
  213. {
  214. m_bFocused = true;
  215. return;
  216. }
  217. if( event.Type == UIEVENT_KILLFOCUS )
  218. {
  219. m_bFocused = false;
  220. return;
  221. }
  222. CControlUI::DoEvent(event);
  223. }
  224. void CLabelUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
  225. {
  226. if( _tcscmp(pstrName, _T("align")) == 0 ) {
  227. if( _tcsstr(pstrValue, _T("left")) != NULL ) {
  228. m_uTextStyle &= ~(DT_CENTER | DT_RIGHT);
  229. m_uTextStyle |= DT_LEFT;
  230. }
  231. if( _tcsstr(pstrValue, _T("center")) != NULL ) {
  232. m_uTextStyle &= ~(DT_LEFT | DT_RIGHT);
  233. m_uTextStyle |= DT_CENTER;
  234. }
  235. if( _tcsstr(pstrValue, _T("right")) != NULL ) {
  236. m_uTextStyle &= ~(DT_LEFT | DT_CENTER);
  237. m_uTextStyle |= DT_RIGHT;
  238. }
  239. }
  240. else if (_tcscmp(pstrName, _T("valign")) == 0)
  241. {
  242. if (_tcsstr(pstrValue, _T("top")) != NULL) {
  243. m_uTextStyle &= ~(DT_BOTTOM | DT_VCENTER);
  244. m_uTextStyle |= DT_TOP;
  245. }
  246. if (_tcsstr(pstrValue, _T("vcenter")) != NULL) {
  247. m_uTextStyle &= ~(DT_TOP | DT_BOTTOM);
  248. m_uTextStyle |= DT_VCENTER;
  249. }
  250. if (_tcsstr(pstrValue, _T("bottom")) != NULL) {
  251. m_uTextStyle &= ~(DT_TOP | DT_VCENTER);
  252. m_uTextStyle |= DT_BOTTOM;
  253. }
  254. }
  255. else if( _tcscmp(pstrName, _T("endellipsis")) == 0 ) {
  256. if( _tcscmp(pstrValue, _T("true")) == 0 ) m_uTextStyle |= DT_END_ELLIPSIS;
  257. else m_uTextStyle &= ~DT_END_ELLIPSIS;
  258. }
  259. else if( _tcscmp(pstrName, _T("font")) == 0 ) SetFont(_ttoi(pstrValue));
  260. else if( _tcscmp(pstrName, _T("textcolor")) == 0 ) {
  261. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  262. LPTSTR pstr = NULL;
  263. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  264. SetTextColor(clrColor);
  265. }
  266. else if( _tcscmp(pstrName, _T("disabledtextcolor")) == 0 ) {
  267. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  268. LPTSTR pstr = NULL;
  269. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  270. SetDisabledTextColor(clrColor);
  271. }
  272. else if( _tcscmp(pstrName, _T("textpadding")) == 0 ) {
  273. RECT rcTextPadding = { 0 };
  274. LPTSTR pstr = NULL;
  275. rcTextPadding.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  276. rcTextPadding.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  277. rcTextPadding.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  278. rcTextPadding.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  279. SetTextPadding(rcTextPadding);
  280. }
  281. else if( _tcscmp(pstrName, _T("multiline")) == 0 ) SetMultiLine(_tcscmp(pstrValue, _T("true")) == 0);
  282. else if( _tcscmp(pstrName, _T("showhtml")) == 0 ) SetShowHtml(_tcscmp(pstrValue, _T("true")) == 0);
  283. else if( _tcscmp(pstrName, _T("enabledeffect")) == 0 ) SetEnabledEffect(_tcscmp(pstrValue, _T("true")) == 0);
  284. else if( _tcscmp(pstrName, _T("enabledluminous")) == 0 ) SetEnabledLuminous(_tcscmp(pstrValue, _T("true")) == 0);
  285. else if( _tcscmp(pstrName, _T("luminousfuzzy")) == 0 ) SetLuminousFuzzy((float)_tstof(pstrValue));
  286. else if( _tcscmp(pstrName, _T("gradientangle")) == 0 ) SetGradientAngle(_ttoi(pstrValue));
  287. else if( _tcscmp(pstrName, _T("enabledstroke")) == 0 ) SetEnabledStroke(_tcscmp(pstrValue, _T("true")) == 0);
  288. else if( _tcscmp(pstrName, _T("enabledshadow")) == 0 ) SetEnabledShadow(_tcscmp(pstrValue, _T("true")) == 0);
  289. else if( _tcscmp(pstrName, _T("gradientlength")) == 0 ) SetGradientLength(_ttoi(pstrValue));
  290. else if( _tcscmp(pstrName, _T("shadowoffset")) == 0 ){
  291. LPTSTR pstr = NULL;
  292. int offsetx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  293. int offsety = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  294. SetShadowOffset(offsetx,offsety);
  295. }
  296. else if( _tcscmp(pstrName, _T("textcolor1")) == 0 ) {
  297. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  298. LPTSTR pstr = NULL;
  299. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  300. SetTextColor1(clrColor);
  301. }
  302. else if( _tcscmp(pstrName, _T("textshadowcolora")) == 0 ) {
  303. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  304. LPTSTR pstr = NULL;
  305. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  306. SetTextShadowColorA(clrColor);
  307. }
  308. else if( _tcscmp(pstrName, _T("textshadowcolorb")) == 0 ) {
  309. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  310. LPTSTR pstr = NULL;
  311. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  312. SetTextShadowColorB(clrColor);
  313. }
  314. else if( _tcscmp(pstrName, _T("strokecolor")) == 0 ) {
  315. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  316. LPTSTR pstr = NULL;
  317. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  318. SetStrokeColor(clrColor);
  319. }
  320. else CControlUI::SetAttribute(pstrName, pstrValue);
  321. }
  322. void CLabelUI::PaintText(HDC hDC)
  323. {
  324. if( m_dwTextColor == 0 ) m_dwTextColor = m_pManager->GetDefaultFontColor();
  325. if( m_dwDisabledTextColor == 0 ) m_dwDisabledTextColor = m_pManager->GetDefaultDisabledColor();
  326. RECT rc = m_rcItem;
  327. rc.left += m_rcTextPadding.left;
  328. rc.right -= m_rcTextPadding.right;
  329. rc.top += m_rcTextPadding.top;
  330. rc.bottom -= m_rcTextPadding.bottom;
  331. if(!GetEnabledEffect())
  332. {
  333. if( m_sText.IsEmpty() ) return;
  334. int nLinks = 0;
  335. if( IsEnabled() ) {
  336. if( m_bShowHtml )
  337. CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, m_sText, m_dwTextColor, \
  338. NULL, NULL, nLinks, m_iFont, m_uTextStyle);
  339. else
  340. CRenderEngine::DrawText(hDC, m_pManager, rc, m_sText, m_dwTextColor, \
  341. m_iFont, m_uTextStyle);
  342. }
  343. else {
  344. if( m_bShowHtml )
  345. CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor, \
  346. NULL, NULL, nLinks, m_iFont, m_uTextStyle);
  347. else
  348. CRenderEngine::DrawText(hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor, \
  349. m_iFont, m_uTextStyle);
  350. }
  351. }
  352. else
  353. {
  354. #ifdef _USE_GDIPLUS
  355. Font nFont(hDC,m_pManager->GetFont(GetFont()));
  356. Graphics nGraphics(hDC);
  357. nGraphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
  358. StringFormat format;
  359. StringAlignment sa = StringAlignment::StringAlignmentNear;
  360. if ((m_uTextStyle & DT_VCENTER) != 0) sa = StringAlignment::StringAlignmentCenter;
  361. else if( (m_uTextStyle & DT_BOTTOM) != 0) sa = StringAlignment::StringAlignmentFar;
  362. format.SetLineAlignment((StringAlignment)sa);
  363. sa = StringAlignment::StringAlignmentNear;
  364. if ((m_uTextStyle & DT_CENTER) != 0) sa = StringAlignment::StringAlignmentCenter;
  365. else if( (m_uTextStyle & DT_RIGHT) != 0) sa = StringAlignment::StringAlignmentFar;
  366. format.SetAlignment((StringAlignment)sa);
  367. RectF nRc((float)rc.left,(float)rc.top,(float)rc.right-rc.left,(float)rc.bottom-rc.top);
  368. RectF nShadowRc = nRc;
  369. nShadowRc.X += m_ShadowOffset.X;
  370. nShadowRc.Y += m_ShadowOffset.Y;
  371. int nGradientLength = GetGradientLength();
  372. if(nGradientLength == 0)
  373. nGradientLength = (rc.bottom-rc.top);
  374. LinearGradientBrush nLineGrBrushA(Point(GetGradientAngle(), 0),Point(0,nGradientLength),ARGB2Color(GetTextShadowColorA()),ARGB2Color(GetTextShadowColorB() == -1?GetTextShadowColorA():GetTextShadowColorB()));
  375. LinearGradientBrush nLineGrBrushB(Point(GetGradientAngle(), 0),Point(0,nGradientLength),ARGB2Color(GetTextColor()),ARGB2Color(GetTextColor1() == -1?GetTextColor():GetTextColor1()));
  376. if (GetEnabledLuminous())
  377. {
  378. // from http://bbs.csdn.net/topics/390346428
  379. int iFuzzyWidth = (int)(nRc.Width/GetLuminousFuzzy());
  380. if (iFuzzyWidth < 1) iFuzzyWidth = 1;
  381. int iFuzzyHeight = (int)(nRc.Height/GetLuminousFuzzy());
  382. if (iFuzzyHeight < 1) iFuzzyHeight = 1;
  383. RectF nTextRc(0.0f, 0.0f, nRc.Width, nRc.Height);
  384. Bitmap Bit1((INT)nRc.Width, (INT)nRc.Height);
  385. Graphics g1(&Bit1);
  386. g1.SetSmoothingMode(SmoothingModeAntiAlias);
  387. g1.SetTextRenderingHint(TextRenderingHintAntiAlias);
  388. g1.SetCompositingQuality(CompositingQualityAssumeLinear);
  389. Bitmap Bit2(iFuzzyWidth, iFuzzyHeight);
  390. Graphics g2(&Bit2);
  391. g2.SetInterpolationMode(InterpolationModeHighQualityBicubic);
  392. g2.SetPixelOffsetMode(PixelOffsetModeNone);
  393. FontFamily ftFamily;
  394. nFont.GetFamily(&ftFamily);
  395. int iLen = wcslen(m_pWideText);
  396. g1.DrawString(m_pWideText,iLen,&nFont,nRc,&format,&nLineGrBrushB);
  397. g2.DrawImage(&Bit1, 0, 0, (int)iFuzzyWidth, (int)iFuzzyHeight);
  398. g1.Clear(Color(0));
  399. g1.DrawImage(&Bit2, (int)m_ShadowOffset.X, (int)m_ShadowOffset.Y, (int)nRc.Width, (int)nRc.Height);
  400. g1.SetTextRenderingHint(TextRenderingHintAntiAlias);
  401. nGraphics.DrawImage(&Bit1, nRc.X, nRc.Y);
  402. }
  403. if(GetEnabledStroke() && GetStrokeColor() > 0)
  404. {
  405. LinearGradientBrush nLineGrBrushStroke(Point(GetGradientAngle(),0),Point(0,rc.bottom-rc.top+2),ARGB2Color(GetStrokeColor()),ARGB2Color(GetStrokeColor()));
  406. #ifdef _UNICODE
  407. nRc.Offset(-1,0);
  408. nGraphics.DrawString(m_sText,m_sText.GetLength(),&nFont,nRc,&format,&nLineGrBrushStroke);
  409. nRc.Offset(2,0);
  410. nGraphics.DrawString(m_sText,m_sText.GetLength(),&nFont,nRc,&format,&nLineGrBrushStroke);
  411. nRc.Offset(-1,-1);
  412. nGraphics.DrawString(m_sText,m_sText.GetLength(),&nFont,nRc,&format,&nLineGrBrushStroke);
  413. nRc.Offset(0,2);
  414. nGraphics.DrawString(m_sText,m_sText.GetLength(),&nFont,nRc,&format,&nLineGrBrushStroke);
  415. nRc.Offset(0,-1);
  416. #else
  417. int iLen = wcslen(m_pWideText);
  418. nRc.Offset(-1,0);
  419. nGraphics.DrawString(m_pWideText,iLen,&nFont,nRc,&format,&nLineGrBrushStroke);
  420. nRc.Offset(2,0);
  421. nGraphics.DrawString(m_pWideText,iLen,&nFont,nRc,&format,&nLineGrBrushStroke);
  422. nRc.Offset(-1,-1);
  423. nGraphics.DrawString(m_pWideText,iLen,&nFont,nRc,&format,&nLineGrBrushStroke);
  424. nRc.Offset(0,2);
  425. nGraphics.DrawString(m_pWideText,iLen,&nFont,nRc,&format,&nLineGrBrushStroke);
  426. nRc.Offset(0,-1);
  427. #endif
  428. }
  429. #ifdef _UNICODE
  430. if(GetEnabledShadow() && (GetTextShadowColorA() > 0 || GetTextShadowColorB() > 0))
  431. nGraphics.DrawString(m_sText,m_sText.GetLength(),&nFont,nShadowRc,&format,&nLineGrBrushA);
  432. nGraphics.DrawString(m_sText,m_sText.GetLength(),&nFont,nRc,&format,&nLineGrBrushB);
  433. #else
  434. int iLen = wcslen(m_pWideText);
  435. if(GetEnabledShadow() && (GetTextShadowColorA() > 0 || GetTextShadowColorB() > 0))
  436. nGraphics.DrawString(m_pWideText,iLen,&nFont,nShadowRc,&format,&nLineGrBrushA);
  437. nGraphics.DrawString(m_pWideText,iLen,&nFont,nRc,&format,&nLineGrBrushB);
  438. #endif
  439. #endif
  440. }
  441. }
  442. void CLabelUI::SetShadowOffset( int _offset,int _angle )
  443. {
  444. if(_angle > 180 || _angle < -180) return;
  445. RECT rc = m_rcItem;
  446. if(_angle >= 0 && _angle <= 180) rc.top -= _offset;
  447. else if(_angle > -180 && _angle < 0) rc.top += _offset;
  448. if(_angle > -90 && _angle <= 90) rc.left -= _offset;
  449. else if( _angle > 90 || _angle < -90) rc.left += _offset;
  450. m_ShadowOffset.X = (float)rc.top;
  451. m_ShadowOffset.Y = (float)rc.left;
  452. Invalidate();
  453. }
  454. RectF CLabelUI::GetShadowOffset()
  455. {
  456. return m_ShadowOffset;
  457. }
  458. void CLabelUI::SetEnabledEffect( bool _EnabledEffect )
  459. {
  460. m_EnableEffect = _EnabledEffect;
  461. if (m_EnableEffect) {
  462. #ifdef _UNICODE
  463. m_pWideText = (LPWSTR)m_sText.GetData();
  464. #else
  465. int iLen = m_sText.GetLength();
  466. if (m_pWideText) delete[] m_pWideText;
  467. m_pWideText = new WCHAR[iLen + 1];
  468. ::ZeroMemory(m_pWideText, (iLen + 1) * sizeof(WCHAR));
  469. ::MultiByteToWideChar(CP_ACP, 0, m_sText.GetData(), -1, (LPWSTR)m_pWideText, iLen);
  470. #endif
  471. }
  472. Invalidate();
  473. }
  474. bool CLabelUI::GetEnabledEffect()
  475. {
  476. return m_EnableEffect;
  477. }
  478. void CLabelUI::SetEnabledLuminous(bool bEnableLuminous)
  479. {
  480. m_bEnableLuminous = bEnableLuminous;
  481. Invalidate();
  482. }
  483. bool CLabelUI::GetEnabledLuminous()
  484. {
  485. return m_bEnableLuminous;
  486. }
  487. void CLabelUI::SetLuminousFuzzy(float fFuzzy)
  488. {
  489. if (fFuzzy < 0.0001f) return;
  490. m_fLuminousFuzzy = fFuzzy;
  491. Invalidate();
  492. }
  493. float CLabelUI::GetLuminousFuzzy()
  494. {
  495. return m_fLuminousFuzzy;
  496. }
  497. void CLabelUI::SetTextColor1( DWORD _TextColor1 )
  498. {
  499. m_dwTextColor1 = _TextColor1;
  500. Invalidate();
  501. }
  502. DWORD CLabelUI::GetTextColor1()
  503. {
  504. return m_dwTextColor1;
  505. }
  506. void CLabelUI::SetTextShadowColorA( DWORD _TextShadowColorA )
  507. {
  508. m_dwTextShadowColorA = _TextShadowColorA;
  509. Invalidate();
  510. }
  511. DWORD CLabelUI::GetTextShadowColorA()
  512. {
  513. return m_dwTextShadowColorA;
  514. }
  515. void CLabelUI::SetTextShadowColorB( DWORD _TextShadowColorB )
  516. {
  517. m_dwTextShadowColorB = _TextShadowColorB;
  518. Invalidate();
  519. }
  520. DWORD CLabelUI::GetTextShadowColorB()
  521. {
  522. return m_dwTextShadowColorB;
  523. }
  524. void CLabelUI::SetGradientAngle( int _SetGradientAngle )
  525. {
  526. m_GradientAngle = _SetGradientAngle;
  527. Invalidate();
  528. }
  529. int CLabelUI::GetGradientAngle()
  530. {
  531. return m_GradientAngle;
  532. }
  533. void CLabelUI::SetEnabledStroke( bool _EnabledStroke )
  534. {
  535. m_EnabledStroke = _EnabledStroke;
  536. Invalidate();
  537. }
  538. bool CLabelUI::GetEnabledStroke()
  539. {
  540. return m_EnabledStroke;
  541. }
  542. void CLabelUI::SetStrokeColor( DWORD _StrokeColor )
  543. {
  544. m_dwStrokeColor = _StrokeColor;
  545. Invalidate();
  546. }
  547. DWORD CLabelUI::GetStrokeColor()
  548. {
  549. return m_dwStrokeColor;
  550. }
  551. void CLabelUI::SetEnabledShadow( bool _EnabledShadowe )
  552. {
  553. m_EnabledShadow = _EnabledShadowe;
  554. Invalidate();
  555. }
  556. bool CLabelUI::GetEnabledShadow()
  557. {
  558. return m_EnabledShadow;
  559. }
  560. void CLabelUI::SetGradientLength( int _GradientLength )
  561. {
  562. m_GradientLength = _GradientLength;
  563. Invalidate();
  564. }
  565. int CLabelUI::GetGradientLength()
  566. {
  567. return m_GradientLength;
  568. }
  569. }