TNB Library
TnbDrawable.h
[詳解]
1#pragma once
11#include "TnbPointerHandle.h"
13
14
15
16//TNB Library
17namespace TNB
18{
19
20
21
37{
39 virtual ~IDrawable(void) { }
40
46 virtual IDrawable* Clone(void) const = 0;
47
55 virtual bool GetSize(SIZE& _size) const = 0;
56
64 virtual bool Resize(const SIZE& size) = 0;
65
73 virtual void Draw(HDC dc, int x = 0, int y = 0) const = 0;
74
83 virtual void DrawEx(HDC dc, int x, int y, LPARAM lParam) const
84 {
85 Draw(dc, x, y);
86 }
87
90};
91
92
93
105class CNullDrawer : public IDrawable
106{
107 DEFSUPER(IDrawable);
108protected:
109 SIZE m_size;
110public:
111
116 CNullDrawer(const SIZE& size) : m_size(size)
117 {
118 }
119
125 {
126 m_size.cx = 0;
127 m_size.cy = 0;
128 }
129
135 virtual IDrawable* Clone(void) const
136 {
137 return new CNullDrawer(m_size);
138 }
139
147 virtual bool GetSize(SIZE& _size) const
148 {
149 _size = m_size;
150 return true;
151 }
152
160 virtual bool Resize(const SIZE& size)
161 {
162 m_size = size;
163 return true;
164 }
165
174 virtual void Draw(HDC dc, int x = 0, int y = 0) const
175 {
176 }
177};
178
179
180
194class CPairDrawer : public IDrawable
195{
196 DEFSUPER(IDrawable);
197 IDrawable::Ptr m_pDrawLeft;
198 IDrawable::Ptr m_pDrawRight;
199 size_t m_orgLeftWidth;
200 SIZE m_size;
201
202public:
203
209 CPairDrawer(const IDrawable& drawLeft, const IDrawable& drawRight)
210 {
211 m_pDrawLeft = drawLeft.Clone();
212 m_pDrawRight = drawRight.Clone();
213 SIZE orgSize;
214 m_pDrawLeft->GetSize(orgSize);
215 m_orgLeftWidth = orgSize.cx;
216 m_size.cx = 0;
217 m_size.cy = 0;
218 }
219
225 virtual IDrawable* Clone(void) const
226 {
227 CPairDrawer* P = new CPairDrawer(*this);
228 return P;
229 }
230
238 virtual bool GetSize(SIZE& _size) const
239 {
240 _size = m_size;
241 return true;
242 }
243
252 virtual bool Resize(const SIZE& size)
253 {
254 m_size = size;
255 SIZE s1 = { min(ToInt(m_orgLeftWidth), size.cx), size.cy };
256 SIZE s2 = { max(down_cast<LONG>(size.cx - m_orgLeftWidth), 0), size.cy };
257 m_pDrawLeft->Resize(s1);
258 m_pDrawRight->Resize(s2);
259 return true;
260 }
261
269 virtual void Draw(HDC dc, int x = 0, int y = 0) const
270 {
271 DrawEx(dc, x, y, 0);
272 }
273
282 virtual void DrawEx(HDC dc, int x, int y, LPARAM lParam) const
283 {
284 SIZE s1;
285 m_pDrawLeft->GetSize(s1);
286 m_pDrawLeft->DrawEx(dc, x, y + (m_size.cy - s1.cy) / 2, lParam);
287 SIZE s2;
288 m_pDrawRight->GetSize(s2);
289 m_pDrawRight->DrawEx(dc, x + s1.cx, y + (m_size.cy - s2.cy) / 2, lParam);
290 }
291};
292
293
294
309{
310 DEFSUPER(IDrawable);
311 IDrawable::Ptr m_pDrawBase;
312 POINT m_offsetOver;
313 IDrawable::Ptr m_pDrawOver;
314 SIZE m_size;
315 void m_CalcSize(void)
316 {
317 m_size.cx = 0;
318 m_size.cy = 0;
319 SIZE s1;
320 SIZE s2;
321 if ( m_pDrawBase->GetSize(s1) && m_pDrawOver->GetSize(s2) )
322 {
323 RECT r1 = { 0, 0, s1.cx, s1.cy };
324 RECT r2 = { m_offsetOver.x, m_offsetOver.y, m_offsetOver.x + s2.cx, m_offsetOver.y + s2.cy };
325 if ( ::UnionRect(&r1, &r1, &r2) )
326 {
327 m_size.cx = r1.right - r1.left;
328 m_size.cy = r1.bottom - r1.top;
329 }
330 }
331 }
332
333public:
334
341 COffsetDrawer(const IDrawable& drawBase, const POINT& off, const IDrawable& drawOver)
342 : m_offsetOver(off)
343 {
344 m_pDrawBase = drawBase.Clone();
345 m_pDrawOver = drawOver.Clone();
346 m_CalcSize();
347 }
348
356 COffsetDrawer(const SIZE& size, const POINT& off, const IDrawable& draw)
357 : m_offsetOver(off)
358 {
359 m_pDrawBase = new CNullDrawer(size);
360 m_pDrawOver = draw.Clone();
361 m_CalcSize();
362 }
363
369 virtual IDrawable* Clone(void) const
370 {
371 return new COffsetDrawer(*m_pDrawBase, m_offsetOver, *m_pDrawOver);
372 }
373
381 virtual bool GetSize(SIZE& _size) const
382 {
383 _size = m_size;
384 return true;
385 }
386
395 virtual bool Resize(const SIZE& size)
396 {
397 return false;
398 }
399
407 virtual void Draw(HDC dc, int x = 0, int y = 0) const
408 {
409 DrawEx(dc, x, y, 0);
410 }
411
420 virtual void DrawEx(HDC dc, int x, int y, LPARAM lParam) const
421 {
422 if ( ! m_pDrawBase.IsNull() )
423 {
424 m_pDrawBase->DrawEx(dc, x, y, lParam);
425 }
426 if ( ! m_pDrawOver.IsNull() )
427 {
428 m_pDrawOver->DrawEx(dc, x + m_offsetOver.x, y + m_offsetOver.y, lParam);
429 }
430 }
431};
432
433
434
449{
450 DEFSUPER(CNullDrawer);
451 COLORREF m_color;
452 int m_width;
453public:
454
461 CBoxDrawer(const SIZE& size, COLORREF color, int width = 1)
462 : _super(size), m_color(color), m_width(width)
463 {
464 }
465
472 CBoxDrawer(COLORREF color, int width = 1)
473 : _super(), m_color(color), m_width(width)
474 {
475 }
476
482 virtual IDrawable* Clone(void) const
483 {
484 return new CBoxDrawer(m_size, m_color, m_width);
485 }
486
494 virtual void Draw(HDC dc, int x = 0, int y = 0) const
495 {
496 int z1 = m_width / 2;
497 int z2 = (m_width + 1) / 2 - 1;
498 HPEN pen = ::CreatePen(PS_SOLID, m_width, m_color);
499 CDcSelectAssistant dca(dc);
500// HGDIOBJ oldPen = ::SelectObject(dc, pen);
501// HGDIOBJ oldBrush = ::SelectObject(dc, ::GetStockObject(NULL_BRUSH));
502 dca.SelectPen(pen);
503 dca.SelectBrush(static_cast<HBRUSH>(::GetStockObject(NULL_BRUSH)));
504 ::RoundRect(dc, x + z1, y + z1, m_size.cx + x - z2, m_size.cy + y - z2, 0, 0);
505// ::SelectObject(dc, oldBrush);
506// ::SelectObject(dc, oldPen);
507 dca.Restore();
508 _DeleteObject(pen);
509 }
510};
511
512
513
528{
529 DEFSUPER(CNullDrawer);
530 COLORREF m_color;
531public:
532
538 CBoxFillDrawer(const SIZE& size, COLORREF color) : _super(size), m_color(color)
539 {
540 }
541
547 CBoxFillDrawer(COLORREF color) : _super(), m_color(color)
548 {
549 }
550
556 virtual IDrawable* Clone(void) const
557 {
558 return new CBoxFillDrawer(m_size, m_color);
559 }
560
568 virtual void Draw(HDC dc, int x = 0, int y = 0) const
569 {
570 RECT rc = { x, y, x + m_size.cx, y + m_size.cy };
571 COLORREF c = ::GetBkColor(dc);
572 ::SetBkColor(dc, m_color);
573 ::ExtTextOut(dc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
574 ::SetBkColor(dc, c);
575 }
576};
577
578
579
594{
595 DEFSUPER(CNullDrawer);
596public:
597
602 CBoxInverter(const SIZE& size) : _super(size)
603 {
604 }
605
610 CBoxInverter(void) : _super()
611 {
612 }
613
619 virtual IDrawable* Clone(void) const
620 {
621 return new CBoxInverter(m_size);
622 }
623
631 virtual void Draw(HDC dc, int x = 0, int y = 0) const
632 {
633 RECT rc = { x, y, x + m_size.cx, y + m_size.cy };
634 ::InvertRect(dc, &rc);
635 }
636};
637
638
639
653{
654 DEFSUPER(CNullDrawer);
655 bool m_isFrameMode;
656 UINT m_param1;
657 UINT m_param2;
658public:
659
667 CFrameDrawer(const SIZE& size, bool isFrameMode, UINT p1, UINT p2)
668 : _super(size), m_isFrameMode(isFrameMode), m_param1(p1), m_param2(p2)
669 {
670 }
671
679 CFrameDrawer(bool isFrameMode, UINT p1, UINT p2)
680 : _super(), m_isFrameMode(isFrameMode), m_param1(p1), m_param2(p2)
681 {
682 }
683
689 virtual IDrawable* Clone(void) const
690 {
691 return new CFrameDrawer(*this);
692 }
693
701 virtual void Draw(HDC dc, int x = 0, int y = 0) const
702 {
703 RECT rc = { x, y, x + m_size.cx, y + m_size.cy };
704 m_isFrameMode ? ::DrawFrameControl(dc, &rc, m_param1, m_param2) : ::DrawEdge(dc, &rc, m_param1, m_param2);
705 }
706};
707
708
709
724{
725 DEFSUPER(CNullDrawer);
726public:
727
732 CFocusFrameDrawer(const SIZE& size) : _super(size)
733 {
734 }
735
740 CFocusFrameDrawer(void) : _super()
741 {
742 }
743
749 virtual IDrawable* Clone(void) const
750 {
751 return new CFocusFrameDrawer(m_size);
752 }
753
761 virtual void Draw(HDC dc, int x = 0, int y = 0) const
762 {
763 RECT rc = { x, y, x + m_size.cx, y + m_size.cy };
764 ::DrawFocusRect(dc, &rc);
765 }
766};
767
768
769
770};
771
デバイステキストセレクトアシスタント関係のヘッダ
ポインタハンドル関係のヘッダ
四角描画クラス
Definition: TnbDrawable.h:449
CBoxDrawer(const SIZE &size, COLORREF color, int width=1)
コンストラクタ
Definition: TnbDrawable.h:461
virtual void Draw(HDC dc, int x=0, int y=0) const
[描画] 描画.
Definition: TnbDrawable.h:494
CBoxDrawer(COLORREF color, int width=1)
コンストラクタ
Definition: TnbDrawable.h:472
virtual IDrawable * Clone(void) const
[作成] クローン作成.
Definition: TnbDrawable.h:482
四角塗りつぶし描画クラス
Definition: TnbDrawable.h:528
CBoxFillDrawer(COLORREF color)
コンストラクタ
Definition: TnbDrawable.h:547
virtual void Draw(HDC dc, int x=0, int y=0) const
[描画] 描画.
Definition: TnbDrawable.h:568
CBoxFillDrawer(const SIZE &size, COLORREF color)
コンストラクタ
Definition: TnbDrawable.h:538
virtual IDrawable * Clone(void) const
[作成] クローン作成.
Definition: TnbDrawable.h:556
反転描画クラス
Definition: TnbDrawable.h:594
virtual void Draw(HDC dc, int x=0, int y=0) const
[描画] 描画.
Definition: TnbDrawable.h:631
CBoxInverter(const SIZE &size)
コンストラクタ
Definition: TnbDrawable.h:602
CBoxInverter(void)
コンストラクタ
Definition: TnbDrawable.h:610
virtual IDrawable * Clone(void) const
[作成] クローン作成.
Definition: TnbDrawable.h:619
デバイステキストセレクトアシスタント
void SelectBrush(HBRUSH brush)
[選択] ブラシ選択.
void Restore(void)
[設定] リストア.
void SelectPen(HPEN pen)
[選択] ペン選択.
フォーカスフレーム描画クラス
Definition: TnbDrawable.h:724
virtual void Draw(HDC dc, int x=0, int y=0) const
[描画] 描画.
Definition: TnbDrawable.h:761
CFocusFrameDrawer(void)
コンストラクタ
Definition: TnbDrawable.h:740
CFocusFrameDrawer(const SIZE &size)
コンストラクタ
Definition: TnbDrawable.h:732
virtual IDrawable * Clone(void) const
[作成] クローン作成.
Definition: TnbDrawable.h:749
フレーム描画クラス
Definition: TnbDrawable.h:653
CFrameDrawer(bool isFrameMode, UINT p1, UINT p2)
コンストラクタ
Definition: TnbDrawable.h:679
virtual void Draw(HDC dc, int x=0, int y=0) const
[描画] 描画.
Definition: TnbDrawable.h:701
virtual IDrawable * Clone(void) const
[作成] クローン作成.
Definition: TnbDrawable.h:689
CFrameDrawer(const SIZE &size, bool isFrameMode, UINT p1, UINT p2)
コンストラクタ
Definition: TnbDrawable.h:667
NULL描画クラス
Definition: TnbDrawable.h:106
CNullDrawer(void)
コンストラクタ.
Definition: TnbDrawable.h:124
SIZE m_size
サイズ
Definition: TnbDrawable.h:109
virtual void Draw(HDC dc, int x=0, int y=0) const
[描画] 描画.
Definition: TnbDrawable.h:174
CNullDrawer(const SIZE &size)
コンストラクタ
Definition: TnbDrawable.h:116
virtual bool Resize(const SIZE &size)
[設定] サイズ設定.
Definition: TnbDrawable.h:160
virtual bool GetSize(SIZE &_size) const
[取得] サイズ取得.
Definition: TnbDrawable.h:147
virtual IDrawable * Clone(void) const
[作成] クローン作成.
Definition: TnbDrawable.h:135
描画情報保持描画クラス
Definition: TnbDrawable.h:309
virtual void Draw(HDC dc, int x=0, int y=0) const
[描画] 描画.
Definition: TnbDrawable.h:407
COffsetDrawer(const IDrawable &drawBase, const POINT &off, const IDrawable &drawOver)
コンストラクタ
Definition: TnbDrawable.h:341
virtual bool Resize(const SIZE &size)
[設定] サイズ設定.
Definition: TnbDrawable.h:395
COffsetDrawer(const SIZE &size, const POINT &off, const IDrawable &draw)
コンストラクタ.
Definition: TnbDrawable.h:356
virtual bool GetSize(SIZE &_size) const
[取得] サイズ取得.
Definition: TnbDrawable.h:381
virtual IDrawable * Clone(void) const
[作成] クローン作成.
Definition: TnbDrawable.h:369
virtual void DrawEx(HDC dc, int x, int y, LPARAM lParam) const
[描画] 描画.
Definition: TnbDrawable.h:420
描画情報保持描画クラス
Definition: TnbDrawable.h:195
virtual void Draw(HDC dc, int x=0, int y=0) const
[描画] 描画.
Definition: TnbDrawable.h:269
CPairDrawer(const IDrawable &drawLeft, const IDrawable &drawRight)
コンストラクタ
Definition: TnbDrawable.h:209
virtual bool Resize(const SIZE &size)
[設定] サイズ設定.
Definition: TnbDrawable.h:252
virtual bool GetSize(SIZE &_size) const
[取得] サイズ取得.
Definition: TnbDrawable.h:238
virtual IDrawable * Clone(void) const
[作成] クローン作成.
Definition: TnbDrawable.h:225
virtual void DrawEx(HDC dc, int x, int y, LPARAM lParam) const
[描画] 描画.
Definition: TnbDrawable.h:282
bool IsNull(void) const
[確認] NULLチェック
int ToInt(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).
Definition: TnbStrLib.h:367
TNB Library
Definition: TnbDoxyTitle.txt:2
描画情報インターフェース
Definition: TnbDrawable.h:37
virtual bool Resize(const SIZE &size)=0
[設定] サイズ設定.
CPointerHandleT< IDrawable > Ptr
ポインタハンドル型宣言
Definition: TnbDrawable.h:89
virtual bool GetSize(SIZE &_size) const =0
[取得] サイズ取得.
virtual ~IDrawable(void)
デストラクタ
Definition: TnbDrawable.h:39
virtual IDrawable * Clone(void) const =0
[作成] クローン作成.
virtual void Draw(HDC dc, int x=0, int y=0) const =0
[描画] 描画.
virtual void DrawEx(HDC dc, int x, int y, LPARAM lParam) const
[描画] 描画.
Definition: TnbDrawable.h:83