TNB Library
TnbMfcMarqueeStatic.h
[詳解]
1#pragma once
13#include "TnbMfcCommon.h"
14#include "TnbBitmapDrawer.h"
15#include "TnbTextDrawer.h"
16
17
18
19//TNB Library
20namespace TNB {
21namespace MFC {
22
23
24
40class CMarqueeStatic : public CWnd
41{
42 DEFSUPER(CWnd);
43public:
44
46 CMarqueeStatic(void) : _super(), m_margin(0, 0), m_mode(Mode_Scroll)
47 , m_direction(LEFT), m_amount(6), m_delay(85)
48 , m_backColor(RGB(0, 0, 0)), m_withBackDraw(true)
49 {
50 }
51
57 void SetMargin(size_t cx, size_t cy)
58 {
59 m_margin.cx = cx;
60 m_margin.cy = cy;
61 if ( ::IsWindow(_super::GetSafeHwnd()) )
62 {
63 CRect rc;
64 _super::GetClientRect(&rc);
65 m_clientSize = rc.Size() - m_margin - m_margin;
66 m_Reset();
67 }
68 }
69
71 enum EMode
72 {
75 };
76
81 void SetMode(EMode mode)
82 {
83 m_mode = mode;
84 m_Reset();
85 }
86
89 {
95 };
96
102 {
103 m_direction = d;
104 m_Reset();
105 }
106
112 void SetSpeed(DWORD amount, DWORD delay)
113 {
114 m_amount = amount;
115 m_delay = delay;
116 if ( ::IsWindow(GetSafeHwnd()) )
117 {
118 SetTimer(TIMERID_MARQUEE, m_delay, NULL);
119 }
120 }
121
126 void SetBackColor(COLORREF c)
127 {
128 m_backColor = c;
129 m_Reset();
130 }
131
137 void SetDrawingObject(const IDrawable& draw, bool withBackDraw = true)
138 {
139 m_withBackDraw = withBackDraw;
140 m_pDrawing = draw.Clone();
141 if ( ! m_pDrawing.IsNull() )
142 {
143 m_pDrawing->GetSize(m_drawingSize);
144 }
145 m_Reset();
146 }
147
153 {
155 }
156
166 void SetDrawingText(HFONT font, COLORREF textColor, LPCTSTR lpszText, DWORD style = DT_CENTER | DT_VCENTER, int margin = 0)
167 {
168 CTextBkDrawer d(font, textColor, m_backColor, lpszText, style, margin);
169 d.AdjustSize();
170 SetDrawingObject(d, true);
171 }
172
173protected:
174
184 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
185 {
186 switch ( message )
187 {
188 case WM_ERASEBKGND:
189 TTRACE0("WM_ERASEBKGND\n");
190 return 0;
191 case WM_PRINTCLIENT:
192 TTRACE0("WM_PRINTCLIENT\n");
193 {
194 CDC* pDC = CDC::FromHandle(reinterpret_cast<HDC>(wParam));
195 m_Draw(pDC);
196 }
197 return 0;
198 case WM_PAINT:
199 TTRACE0("WM_PAINT\n");
200 {
201 CPaintDC dc(this); // 描画用のデバイス コンテキスト
202 m_Draw(&dc);
203 }
204 return 0;
205 case WM_ENABLE:
206 TTRACE0("WM_ENABLE\n");
207 return 0;
208 case WM_TIMER:
209 if ( wParam == TIMERID_MARQUEE )
210 {
211 if ( _super::IsWindowVisible() )
212 {
213 m_Next();
214 _super::RedrawWindow();
215 }
216 }
217 break;
218 }
219 return _super::WindowProc(message, wParam, lParam);
220 }
221
227 virtual void PreSubclassWindow(void)
228 {
229 _super::ModifyStyle(0, SS_OWNERDRAW);
230 _super::PreSubclassWindow();
231 SetTimer(TIMERID_MARQUEE, m_delay, NULL);
232 CRect rc;
233 _super::GetClientRect(&rc);
234 m_clientSize = rc.Size() - m_margin - m_margin;
235 m_isStarted = false;
236 }
237
238private:
239
240 void m_Reset(void)
241 {
242 m_isStarted = false;
243 if ( ::IsWindow(GetSafeHwnd()) )
244 {
245 SetTimer(TIMERID_MARQUEE, m_delay, NULL);
246 }
247 }
248
250 void m_Draw(CDC* pDC)
251 {
252 if ( ! m_pDrawing.IsNull() )
253 {
254 CRect rc;
255 _super::GetClientRect(&rc);
256 pDC->IntersectClipRect(&rc);
257 CPoint po = m_drawPoint + m_margin;
258 if ( m_withBackDraw )
259 {
260 //背景も描画するDrawerだ
261 m_pDrawing->Draw(*pDC, po.x, po.y);
262 pDC->ExcludeClipRect(CRect(po, m_drawingSize));
263 pDC->FillSolidRect(&rc, m_backColor);
264 }
265 else
266 {
267 //背景は書いてくれないDrawerだ
268 pDC->FillSolidRect(&rc, m_backColor);
269 m_pDrawing->Draw(*pDC, po.x, po.y);
270 }
271 }
272 }
273
274 // メンバの状態から、 m_drawPoint を更新する。
275 void m_Next(void)
276 {
277 if ( ! m_isStarted )
278 {
279 // 開始!
280 switch ( m_direction )
281 {
282 case LEFT: //右から開始
283 m_drawPoint = CPoint(m_clientSize.cx + m_margin.cx, 0);
284 break;
285 case RIGHT: //左から開始
286 m_drawPoint = CPoint(-m_drawingSize.cx - m_margin.cx, 0);
287 break;
288 case UP: //下から開始
289 m_drawPoint = CPoint(0, m_clientSize.cy + m_margin.cy);
290 break;
291 case DOWN: //上から開始
292 m_drawPoint = CPoint(0, -m_drawingSize.cy - + m_margin.cy);
293 break;
294 case IMMOVALE: //不動
295 m_drawPoint = CPoint(0, 0);
296 KillTimer(TIMERID_MARQUEE);
297 break;
298 }
299 m_isStarted = true;
300 }
301 int w = (m_clientSize.cx - m_drawingSize.cx);
302 int h = (m_clientSize.cy - m_drawingSize.cy);
303 switch ( m_direction )
304 {
305 case LEFT: //左へ
306 m_drawPoint.x -= m_amount;
307 break;
308 case RIGHT: //右へ
309 m_drawPoint.x += m_amount;
310 break;
311 case UP: //上へ
312 m_drawPoint.y -= m_amount;
313 break;
314 case DOWN: //下へ
315 m_drawPoint.y += m_amount;
316 break;
317 }
318 if ( m_mode == Mode_Scroll )
319 {
320 switch ( m_direction )
321 {
322 case LEFT: //左を超えたら右から
323 if ( m_drawPoint.x < -m_drawingSize.cx )
324 {
325 m_drawPoint.x = m_clientSize.cx + m_margin.cx;
326 }
327 break;
328 case RIGHT: //右を超えたら左から
329 if ( m_drawPoint.x > m_clientSize.cx )
330 {
331 m_drawPoint.x = -m_drawingSize.cx - m_margin.cx;
332 }
333 break;
334 case UP: //上を超えたら下から
335 if ( m_drawPoint.y < -m_drawingSize.cy )
336 {
337 m_drawPoint.y = m_clientSize.cy + m_margin.cy;
338 }
339 break;
340 case DOWN: //下を超えたら上から
341 if ( m_drawPoint.y > m_clientSize.cy )
342 {
343 m_drawPoint.y = -m_drawingSize.cy - m_margin.cy;
344 }
345 break;
346 }
347 }
348 if ( m_mode == Mode_Slide )
349 {
350 bool isContinue = true;
351 switch ( m_direction )
352 {
353 case LEFT: //左で終わり
354 if ( m_drawPoint.x < 0 ) { m_drawPoint.x = 0; isContinue = false; }
355 break;
356 case RIGHT: //右で終わり
357 if ( m_drawPoint.x > w ) { m_drawPoint.x = w; isContinue = false; }
358 break;
359 case UP: //上で終わり
360 if ( m_drawPoint.y < 0 ) { m_drawPoint.y = 0; isContinue = false; }
361 break;
362 case DOWN: //下で終わり
363 if ( m_drawPoint.y > h ) { m_drawPoint.y = h; isContinue = false; }
364 break;
365 }
366 if ( ! isContinue )
367 {
368 KillTimer(TIMERID_MARQUEE);
369 }
370 }
371 }
372
373 enum
374 {
375 TIMERID_MARQUEE = 1,
376 };
377
378 IDrawable::Ptr m_pDrawing;
379 CSize m_margin;
380 EMode m_mode;
381 EDirection m_direction;
382 DWORD m_amount;
383 DWORD m_delay;
384 COLORREF m_backColor;
385 bool m_withBackDraw;
386 // -- work
387 CSize m_drawingSize;
388 CSize m_clientSize;
389 CPoint m_drawPoint;
390 bool m_isStarted;
391};
392
393
394
395}; //MFC
396}; //TNB
397
398
399
ビットマップ描画関係のヘッダ
MFCコントロール共通のヘッダ
テキスト描画関係のヘッダ
ウィンドウ管理.
HWND GetSafeHwnd(void) const
[取得] ウィンドウハンドル取得.
ビットマップ描画クラス
HBITMAP型ハンドルハンドル
bool IsNull(void) const
[確認] NULLチェック
テキスト描画クラス
bool AdjustSize(int margin=1, HWND hWnd=NULL)
[設定] サイズ調整.
描画情報マーキー表示コントロールクラス
void SetBackColor(COLORREF c)
[設定] 背景色設定.
void SetMode(EMode mode)
[設定] モード設定.
void SetDirection(EDirection d)
[設定] 方向設定.
void SetDrawingBitmap(CBitmapHandle bmp)
[設定] 描画情報設定.
void SetDrawingText(HFONT font, COLORREF textColor, LPCTSTR lpszText, DWORD style=DT_CENTER|DT_VCENTER, int margin=0)
[設定] 描画文字列設定.
void SetMargin(size_t cx, size_t cy)
[設定] マージン.
virtual void PreSubclassWindow(void)
[通知] subclassing/unsubclassing functions.
void SetSpeed(DWORD amount, DWORD delay)
[設定] 移動速度設定.
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
[通知] for processing Windows messages.
void SetDrawingObject(const IDrawable &draw, bool withBackDraw=true)
[設定] 描画情報設定.
CMarqueeStatic(void)
コンストラクタ
TNB Library
Definition: TnbDoxyTitle.txt:2
描画情報インターフェース
Definition: TnbDrawable.h:37
virtual bool GetSize(SIZE &_size) const =0
[取得] サイズ取得.
virtual IDrawable * Clone(void) const =0
[作成] クローン作成.
virtual void Draw(HDC dc, int x=0, int y=0) const =0
[描画] 描画.