Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/CWindowCtrl.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Sun Aug 15 01:53:13 2010 UTC (13 years, 9 months ago) by okadu
File MIME type: text/x-c++src
File size: 9919 byte(s)


1 #include "stdafx.h"
2 #include "CWindowCtrl.h"
3 #include "CSkinPlugin.h"
4 #include "CConfigMode.h"
5
6 // 内部定数
7 const int WND_RESIZE_GRAB = 4; // 窓リサイズつまみ幅
8
9 /*
10 * コンストラクタ
11 */
12 CWindowCtrl::CWindowCtrl(){
13 m_CloseButton = NULL;
14 }
15
16 /*
17 * デストラクタ
18 */
19 CWindowCtrl::~CWindowCtrl(){
20 DELETE_V(m_CloseButton);
21 }
22
23 /*
24 * 初期化
25 */
26 void CWindowCtrl::Init(
27 int x, int y, // 座標
28 int w, int h, // サイズ
29 char *t, // テキスト
30 CInterface *p, // 親
31 bool close // クローズ有効
32 ){
33 CInterface::Init(x, y, w, h, t, p);
34 m_State = 0;
35 m_MinWidth = m_MinHeight = m_MaxWidth = m_MaxHeight = 0;
36 m_Color = 0xffffffff;
37 if(close){
38 m_CloseButton = new CMiniButton;
39 m_CloseButton->Init(w-TILE_UNIT, 0,
40 TILE_UNIT, TILE_UNIT, this, 0.25f, 0.75f, false);
41 }
42 }
43
44 /*
45 * サイズ設定
46 */
47 void CWindowCtrl::SetSize(
48 int w, int h // サイズ
49 ){
50 m_Width = w;
51 m_Height = h;
52 if(m_CloseButton) m_CloseButton->SetPos(m_Width-TILE_UNIT, 0);
53 if(m_Resizer) m_Resizer->WindowResized(m_Width, m_Height, this);
54 }
55
56 /*
57 * リサイズ設定
58 */
59 void CWindowCtrl::SetResize(
60 int minw, int minh, // 最小サイズ
61 int maxw, int maxh, // 最大サイズ
62 CWindowResizer *res // リサイザ
63 ){
64 m_MinWidth = minw; m_MinHeight = minh;
65 m_MaxWidth = maxw; m_MaxHeight = maxh;
66 m_Resizer = res;
67 }
68
69 /*
70 * カーソルがウィンドウ外なら自動的に不透明にする
71 */
72 void CWindowCtrl::SetAutoTransparent(){
73 POINT pos = g_Cursor.GetPos();
74 SetColor(IsInside(pos.x, pos.y) ? 0xffffffff : 0x80ffffff);
75 }
76
77 /*
78 * 指定座標がタイトルバー内か調べる
79 */
80 bool CWindowCtrl::IsInsideTitleBar(
81 int x, int y // 座標
82 ){
83 int px, py;
84 GetAbsPos(&px, &py);
85 return px<=x && x<px+m_Width && py<=y && y<py+TILE_UNIT;
86 }
87
88 /*
89 * 指定座標が左リサイズつまみ内か調べる
90 */
91 bool CWindowCtrl::IsInsideLeftGrab(
92 int x, int y // 座標
93 ){
94 int px, py;
95 GetAbsPos(&px, &py);
96 return px<=x && x<px+WND_RESIZE_GRAB && py<=y && y<py+m_Height;
97 }
98
99 /*
100 * 指定座標が上リサイズつまみ内か調べる
101 */
102 bool CWindowCtrl::IsInsideTopGrab(
103 int x, int y // 座標
104 ){
105 int px, py;
106 GetAbsPos(&px, &py);
107 return px<=x && x<px+m_Width && py<=y && y<py+WND_RESIZE_GRAB;
108 }
109
110 /*
111 * 指定座標が右リサイズつまみ内か調べる
112 */
113 bool CWindowCtrl::IsInsideRightGrab(
114 int x, int y // 座標
115 ){
116 int px, py;
117 GetAbsPos(&px, &py);
118 return px+m_Width-WND_RESIZE_GRAB<=x && x<px+m_Width && py<=y && y<py+m_Height;
119 }
120
121 /*
122 * 指定座標が下リサイズつまみ内か調べる
123 */
124 bool CWindowCtrl::IsInsideBottomGrab(
125 int x, int y // 座標
126 ){
127 int px, py;
128 GetAbsPos(&px, &py);
129 return px<=x && x<px+m_Width && py+m_Height-WND_RESIZE_GRAB<=y && y<py+m_Height;
130 }
131
132 /*
133 * ドラッグ開始
134 */
135 void CWindowCtrl::BeginDrag(
136 int state, // 状態
137 int ox, int oy // 旧数値
138 ){
139 POINT pos = g_Cursor.GetPos();
140 m_State = state;
141 m_OldX = ox; m_OldY = oy;
142 m_DragX = pos.x; m_DragY = pos.y;
143 CInterface *ti = FindTabItem();
144 if(ti) ti->GiveFocus();
145 }
146
147 /*
148 * 入力チェック
149 */
150 bool CWindowCtrl::ScanInput(){
151 if(!m_Visible){
152 if(m_CloseButton) m_CloseButton->SetPush(false);
153 return ScanInputBrother();
154 }
155 if(m_CloseButton) m_CloseButton->Show(false);
156 bool childret = CInterface::ScanInputChild();
157 if(m_CloseButton) m_CloseButton->Show(true);
158 if(childret) return true;
159 if(ScanInputWindow()) return true;
160 POINT pos = g_Cursor.GetPos();
161 if(m_State){
162 switch(GetButton(DIM_LEFT)){
163 case S_HOLD:
164 if(m_State&16){
165 int oh = m_Height;
166 m_Height = m_OldY-pos.y+m_DragY;
167 ValueArea(&m_Height, m_MinHeight, m_MaxHeight);
168 m_PosY += oh-m_Height;
169 }
170 if(m_State&32){
171 m_Height = m_OldY+pos.y-m_DragY;
172 ValueArea(&m_Height, m_MinHeight, m_MaxHeight);
173 }
174 if(m_State&64){
175 int ow = m_Width;
176 m_Width = m_OldX-pos.x+m_DragX;
177 ValueArea(&m_Width, m_MinWidth, m_MaxWidth);
178 m_PosX += ow-m_Width;
179 }
180 if(m_State&128){
181 m_Width = m_OldX+pos.x-m_DragX;
182 ValueArea(&m_Width, m_MinWidth, m_MaxWidth);
183 }
184 if(m_State&240){
185 if(m_CloseButton) m_CloseButton->SetPos(m_Width-TILE_UNIT, 0);
186 if(m_Resizer) m_Resizer->WindowResized(m_Width, m_Height, this);
187 }
188 switch(m_State){
189 case 16: case 32: g_Cursor.SetResize(0); break;
190 case 144: case 96: g_Cursor.SetResize(1); break;
191 case 64: case 128: g_Cursor.SetResize(2); break;
192 case 80: case 160: g_Cursor.SetResize(3); break;
193 }
194 g_Cursor.SetResize(-1);
195 if(m_State==1){
196 m_PosX = m_OldX+pos.x-m_DragX;
197 m_PosY = m_OldY+pos.y-m_DragY;
198 }
199 return true;
200 default:
201 m_State = 0;
202 break;
203 }
204 }else if(GetButton(DIM_LEFT)==S_PUSH){
205 if(m_MaxHeight && IsInsideTopGrab(pos.x, pos.y)){
206 if(m_MaxWidth && IsInsideLeftGrab(pos.x, pos.y)){
207 g_Cursor.SetResize(3);
208 BeginDrag(16|64, m_Width, m_Height);
209 return true;
210 }else if(m_MaxWidth && IsInsideRightGrab(pos.x, pos.y)){
211 g_Cursor.SetResize(1);
212 BeginDrag(16|128, m_Width, m_Height);
213 return true;
214 }else{
215 g_Cursor.SetResize(0);
216 BeginDrag(16, m_Width, m_Height);
217 return true;
218 }
219 }else if(m_MaxHeight && IsInsideBottomGrab(pos.x, pos.y)){
220 if(m_MaxWidth && IsInsideLeftGrab(pos.x, pos.y)){
221 g_Cursor.SetResize(1);
222 BeginDrag(32|64, m_Width, m_Height);
223 return true;
224 }else if(m_MaxWidth && IsInsideRightGrab(pos.x, pos.y)){
225 g_Cursor.SetResize(3);
226 BeginDrag(32|128, m_Width, m_Height);
227 return true;
228 }else{
229 g_Cursor.SetResize(0);
230 BeginDrag(32, m_Width, m_Height);
231 return true;
232 }
233 }else if(m_MaxWidth && IsInsideLeftGrab(pos.x, pos.y)){
234 g_Cursor.SetResize(2);
235 BeginDrag(64, m_Width, m_Height);
236 return true;
237 }else if(m_MaxWidth && IsInsideRightGrab(pos.x, pos.y)){
238 g_Cursor.SetResize(2);
239 BeginDrag(128, m_Width, m_Height);
240 return true;
241 }else if(IsInsideTitleBar(pos.x, pos.y)){
242 g_Cursor.SetResize(-1);
243 if(m_CloseButton && m_CloseButton->ScanInput()) return true;
244 BeginDrag(1, m_PosX, m_PosY);
245 return true;
246 }else{
247 CLICKFOCUS:
248 if(IsInside(pos.x, pos.y)){
249 g_Cursor.SetResize(-1);
250 CInterface *ti = FindTabItem();
251 if(ti) ti->GiveFocus();
252 return true;
253 }
254 }
255 }else if(GetButton(DIM_RIGHT)==S_PUSH){
256 goto CLICKFOCUS;
257 }else{
258 if(m_MaxHeight && IsInsideTopGrab(pos.x, pos.y)){
259 if(m_MaxWidth && IsInsideLeftGrab(pos.x, pos.y)) g_Cursor.SetResize(3);
260 else if(m_MaxWidth && IsInsideRightGrab(pos.x, pos.y)) g_Cursor.SetResize(1);
261 else g_Cursor.SetResize(0);
262 }else if(m_MaxHeight && IsInsideBottomGrab(pos.x, pos.y)){
263 if(m_MaxWidth && IsInsideLeftGrab(pos.x, pos.y)) g_Cursor.SetResize(1);
264 else if(m_MaxWidth && IsInsideRightGrab(pos.x, pos.y)) g_Cursor.SetResize(3);
265 else g_Cursor.SetResize(0);
266 }else if(m_MaxWidth && IsInsideLeftGrab(pos.x, pos.y)){
267 g_Cursor.SetResize(2);
268 }else if(m_MaxWidth && IsInsideRightGrab(pos.x, pos.y)){
269 g_Cursor.SetResize(2);
270 }else if(IsInside(pos.x, pos.y)){
271 g_Cursor.SetResize(-1);
272 }
273 }
274 if(m_CloseButton && m_CloseButton->ScanInput()) return true;
275 return ScanInputBrother();
276 }
277
278 /*
279 * レンダリング
280 */
281 void CWindowCtrl::Render(){
282 CInterface::RenderBrother();
283 if(!m_Visible) return;
284 int px, py;
285 GetAbsPos(&px, &py);
286 g_Skin->SetInterfaceTexture();
287 if(g_ConfigMode->GetWindowShadow()){
288 const int SO = TILE_QUAD;
289 D3DCOLOR sc = (m_Color>>1)&0xff000000;
290 SetUVMap(0.0f, 0.0f, 0.125f, 0.125f);
291 TexMap2DRect(px+SO, py+SO, px+TILE_UNIT+SO, py+TILE_UNIT+SO, sc);
292 SetUVMap(0.125f, 0.0f, 0.25f, 0.125f);
293 TexMap2DRect(px+TILE_UNIT+SO, py+SO, px+m_Width-TILE_UNIT+SO, py+TILE_UNIT+SO, sc);
294 SetUVMap(0.25f, 0.0f, 0.375f, 0.125f);
295 TexMap2DRect(px+m_Width-TILE_UNIT+SO, py+SO, px+m_Width+SO, py+TILE_UNIT+SO, sc);
296 SetUVMap(0.0f, 0.125f, 0.125f, 0.25f);
297 TexMap2DRect(px+SO, py+TILE_UNIT+SO, px+TILE_UNIT+SO, py+m_Height-TILE_UNIT+SO, sc);
298 SetUVMap(0.125f, 0.125f, 0.25f, 0.25f);
299 TexMap2DRect(px+TILE_UNIT+SO, py+TILE_UNIT+SO, px+m_Width-TILE_UNIT+SO, py+m_Height-TILE_UNIT+SO, sc);
300 SetUVMap(0.25f, 0.125f, 0.375f, 0.25f);
301 TexMap2DRect(px+m_Width-TILE_UNIT+SO, py+TILE_UNIT+SO, px+m_Width+SO, py+m_Height-TILE_UNIT+SO, sc);
302 SetUVMap(0.0f, 0.25f, 0.125f, 0.375f);
303 TexMap2DRect(px+SO, py+m_Height-TILE_UNIT+SO, px+TILE_UNIT+SO, py+m_Height+SO, sc);
304 SetUVMap(0.125f, 0.25f, 0.25f, 0.375f);
305 TexMap2DRect(px+TILE_UNIT+SO, py+m_Height-TILE_UNIT+SO, px+m_Width-TILE_UNIT+SO, py+m_Height+SO, sc);
306 SetUVMap(0.25f, 0.25f, 0.375f, 0.375f);
307 TexMap2DRect(px+m_Width-TILE_UNIT+SO, py+m_Height-TILE_UNIT+SO, px+m_Width+SO, py+m_Height+SO, sc);
308 }
309 SetUVMap(0.0f, 0.0f, 0.125f, 0.125f);
310 TexMap2DRect(px, py, px+TILE_UNIT, py+TILE_UNIT, m_Color);
311 SetUVMap(0.125f, 0.0f, 0.25f, 0.125f);
312 TexMap2DRect(px+TILE_UNIT, py, px+m_Width-TILE_UNIT, py+TILE_UNIT, m_Color);
313 SetUVMap(0.25f, 0.0f, 0.375f, 0.125f);
314 TexMap2DRect(px+m_Width-TILE_UNIT, py, px+m_Width, py+TILE_UNIT, m_Color);
315 SetUVMap(0.0f, 0.125f, 0.125f, 0.25f);
316 TexMap2DRect(px, py+TILE_UNIT, px+TILE_UNIT, py+m_Height-TILE_UNIT, m_Color);
317 SetUVMap(0.125f, 0.125f, 0.25f, 0.25f);
318 TexMap2DRect(px+TILE_UNIT, py+TILE_UNIT, px+m_Width-TILE_UNIT, py+m_Height-TILE_UNIT, m_Color);
319 SetUVMap(0.25f, 0.125f, 0.375f, 0.25f);
320 TexMap2DRect(px+m_Width-TILE_UNIT, py+TILE_UNIT, px+m_Width, py+m_Height-TILE_UNIT, m_Color);
321 SetUVMap(0.0f, 0.25f, 0.125f, 0.375f);
322 TexMap2DRect(px, py+m_Height-TILE_UNIT, px+TILE_UNIT, py+m_Height, m_Color);
323 SetUVMap(0.125f, 0.25f, 0.25f, 0.375f);
324 TexMap2DRect(px+TILE_UNIT, py+m_Height-TILE_UNIT, px+m_Width-TILE_UNIT, py+m_Height, m_Color);
325 SetUVMap(0.25f, 0.25f, 0.375f, 0.375f);
326 TexMap2DRect(px+m_Width-TILE_UNIT, py+m_Height-TILE_UNIT, px+m_Width, py+m_Height, m_Color);
327 g_StrTex->RenderCenter(px+m_Width/2, py+FontY(TILE_UNIT),
328 g_Skin->m_InterfaceData.m_TitleBarFontColor, 0, m_Text.c_str(), m_Width-TILE_UNIT);
329 CInterface::RenderChild();
330 RenderWindow();
331 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26