TNB Library
TnbIconDrawer.h
[詳解]
1#pragma once
11#include "TnbDrawable.h"
12
13
14
15//TNB Library
16namespace TNB
17{
18
19
20
21
38class CIconDrawer : public IDrawable
39{
40 DEFSUPER(IDrawable);
41protected:
42 HICON m_icon;
44 mutable SIZE m_size;
45public:
46
52 CIconDrawer(HICON icon, bool canResize = true) : m_icon(icon), m_canResize(canResize)
53 {
54 m_size.cx = 0;
55 m_size.cy = 0;
56 }
57
63 virtual IDrawable* Clone(void) const
64 {
66 p->m_size = m_size;
67 return p;
68 }
69
77 virtual bool GetSize(SIZE& _size) const
78 {
79 if ( m_size.cx == 0 )
80 {
81 ICONINFO ii;
82 if ( ::GetIconInfo(m_icon, &ii) )
83 {
84 HBITMAP h = ii.hbmColor;
85 if ( h == NULL )
86 {
87 h = ii.hbmMask;
88 }
89 BITMAP bm;
90 if ( ::GetObject(h, sizeof(BITMAP), &bm) > 0 )
91 {
92 m_size.cx = bm.bmWidth;
93 m_size.cy = bm.bmHeight;
94 }
95 ::DeleteObject(ii.hbmColor);
96 ::DeleteObject(ii.hbmMask);
97 }
98 }
99 _size = m_size;
100 return m_size.cx != 0;
101 }
102
110 virtual bool Resize(const SIZE& size)
111 {
112 if ( m_canResize )
113 {
114 m_size = size;
115 return true;
116 }
117 return false;
118 }
119
127 virtual void Draw(HDC dc, int x = 0, int y = 0) const
128 {
129 SIZE sz;
130 GetSize(sz);
131 if ( m_canResize )
132 {
133 ::DrawIconEx(dc, x, y, m_icon, sz.cx, sz.cy, 0, NULL, DI_NORMAL);
134 }
135 else
136 {
137 ::DrawIconEx(dc, x, y, m_icon, 0, 0, 0, NULL, DI_NORMAL);
138 }
139 }
140};
141
142
143
144};
描画情報関係のヘッダ
アイコン描画クラス
Definition: TnbIconDrawer.h:39
SIZE m_size
サイズ
Definition: TnbIconDrawer.h:44
virtual void Draw(HDC dc, int x=0, int y=0) const
[描画] 描画.
bool m_canResize
リサイズ可能?
Definition: TnbIconDrawer.h:43
virtual bool Resize(const SIZE &size)
[設定] サイズ設定.
HICON m_icon
アイコン
Definition: TnbIconDrawer.h:42
CIconDrawer(HICON icon, bool canResize=true)
コンストラクタ
Definition: TnbIconDrawer.h:52
virtual bool GetSize(SIZE &_size) const
[取得] サイズ取得.
Definition: TnbIconDrawer.h:77
virtual IDrawable * Clone(void) const
[作成] クローン作成.
Definition: TnbIconDrawer.h:63
TNB Library
Definition: TnbDoxyTitle.txt:2
描画情報インターフェース
Definition: TnbDrawable.h:37