Added aqua_speed for rite geo 50 tryker
[ryzomcore.git] / nel / tools / 3d / tile_edit / ViewColumn.cpp
blobdb69b11dc73037508b67b1a173c441dc2a1c1c43
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "stdafx.h"
18 #include "resource.h"
19 #include "ViewColumn.h"
20 #include "Browse.h"
22 TCHAR *WndRegKeys[4][5] = {
24 _T("POPUP BOTTOM RX"),
25 _T("POPUP BOTTOM RY"),
26 _T("POPUP BOTTOM CX"),
27 _T("POPUP BOTTOM CY"),
28 _T("POPUP BOTTOM N")
31 _T("POPUP TOP RX"),
32 _T("POPUP TOP RY"),
33 _T("POPUP TOP CX"),
34 _T("POPUP TOP CY"),
35 _T("POPUP TOP N")
38 _T("POPUP LEFT RX"),
39 _T("POPUP LEFT RY"),
40 _T("POPUP LEFT CX"),
41 _T("POPUP LEFT CY"),
42 _T("POPUP LEFT N")
45 _T("POPUP RIGHT RX"),
46 _T("POPUP RIGHT RY"),
47 _T("POPUP RIGHT CX"),
48 _T("POPUP RIGHT CY"),
49 _T("POPUP RIGHT N")
53 /////////////////////////////////////////////////////////////////////////////
54 // ViewColumn dialog
57 ViewColumn::ViewColumn(CWnd* pParent /*=NULL*/)
58 : CDialog(ViewColumn::IDD, pParent)
60 //{{AFX_DATA_INIT(ViewColumn)
61 // NOTE: the ClassWizard will add member initialization here
62 //}}AFX_DATA_INIT
63 list = NULL;
64 nTiles = sizetile_y = 0;
65 nTileInWnd = 1;
66 parent = 0;
67 MousePos.x = MousePos.y = 0;
71 void ViewColumn::DoDataExchange(CDataExchange* pDX)
73 CDialog::DoDataExchange(pDX);
74 //{{AFX_DATA_MAP(ViewColumn)
75 // NOTE: the ClassWizard will add DDX and DDV calls here
76 //}}AFX_DATA_MAP
80 BEGIN_MESSAGE_MAP(ViewColumn, CDialog)
81 //{{AFX_MSG_MAP(ViewColumn)
82 ON_WM_PAINT()
83 ON_WM_VSCROLL()
84 ON_WM_CLOSE()
85 ON_WM_SIZE()
86 ON_WM_RBUTTONDOWN()
87 //}}AFX_MSG_MAP
88 END_MESSAGE_MAP()
90 /////////////////////////////////////////////////////////////////////////////
91 // ViewColumn message handlers
93 void ViewColumn::OnPaint()
95 CPaintDC dc(this); // device context for painting
97 // TODO: Add your message handler code here
98 RECT rect,wndrect; SCROLLINFO inf;
99 int first,scroll,nInWnd,cx,cy;
100 GetClientRect(&wndrect);
101 rect = wndrect;
102 inf.fMask = SIF_ALL;
103 GetScrollInfo(SB_VERT,&inf);
105 if ((nTiles==0)||(nTiles==1))
107 dc.FillSolidRect (&wndrect, 0xffffffff);
109 if (inf.nPos>(10000 - (int)inf.nPage)) inf.nPos = 10000 - inf.nPage - 1;
110 if (inf.nPage>=10000) inf.nPage = 10000 -1;
111 if (nTileInWnd==4)
113 nInWnd = (((rect.bottom - rect.top)/(sizetile_y>>1))<<1)+2;
114 if (nTiles>nInWnd) first = ((inf.nPos*((nTiles-nInWnd)>>1))/(10000 - inf.nPage))<<1;
115 else first = 0;
116 int n = (nTiles+1)>>1;
117 scroll = ((inf.nPos*((sizetile_y>>1)*n - (rect.bottom - rect.top)))/(10000 - inf.nPage));
118 if (scroll>=0) scroll-= (first>>1)*(sizetile_y>>1);
119 else scroll = 0;
120 rect.top -= scroll; rect.bottom -= scroll;
121 cy = sizetile_y>>1;
122 cx = (rect.right - rect.left)>>1;
124 else
126 if (nTiles==1)
128 first = 0;
129 cy = sizetile_y;
130 cx = (rect.right - rect.left);
132 else
134 nInWnd = ((rect.bottom - rect.top)/sizetile_y)+1;
135 if (nTiles>nInWnd) first = ((inf.nPos*(nTiles-nInWnd))/(10000 - inf.nPage));
136 else first = 0;
137 scroll = ((inf.nPos*(sizetile_y*nTiles - (rect.bottom - rect.top)))/(10000 - inf.nPage));
138 if (scroll<0) scroll = 0;
139 else scroll-=first*sizetile_y;
140 rect.top -= scroll; rect.bottom -= scroll;
141 cy = sizetile_y;
142 cx = (rect.right - rect.left);
145 int i = first;
146 while (rect.top<wndrect.bottom)
148 if (i<nTiles)
150 StretchDIBits(dc,rect.left,rect.top,cx,cy,
151 0,0,list[i]->BmpInfo.bmiHeader.biWidth,list[i]->BmpInfo.bmiHeader.biHeight,
152 &*list[i]->Bits.begin(),&list[i]->BmpInfo,DIB_RGB_COLORS,SRCCOPY);
154 else
156 StretchDIBits(dc,rect.left,rect.top,cx,cy,
157 0,0,0,0,
158 0,0,DIB_RGB_COLORS,WHITENESS);
160 if (nTileInWnd==1)
162 rect.top += sizetile_y;
163 rect.bottom += sizetile_y;
165 else if (nTileInWnd==4)
167 if ((i&1)==0)
169 rect.left += cx;
170 rect.right += cx;
172 else
174 rect.left -= cx;
175 rect.right -= cx;
176 rect.top += cy;
177 rect.bottom += cy;
180 i++;
182 // Do not call CDialog::OnPaint() for painting messages
185 BOOL ViewColumn::OnInitDialog()
187 CDialog::OnInitDialog();
189 HKEY regkey; int rx=-1,ry=-1,cx=-1,cy=-1;
190 if (RegOpenKey(HKEY_CURRENT_USER,REGKEY_TILEDIT,&regkey)==ERROR_SUCCESS)
192 unsigned long value;
193 RegQueryValueEx(regkey, WndRegKeys[pos&3][0], 0, &value, (LPBYTE)&rx, &value);
194 RegQueryValueEx(regkey, WndRegKeys[pos&3][1], 0, &value, (LPBYTE)&ry, &value);
195 RegQueryValueEx(regkey, WndRegKeys[pos&3][2], 0, &value, (LPBYTE)&cx, &value);
196 RegQueryValueEx(regkey, WndRegKeys[pos&3][3], 0, &value, (LPBYTE)&cy, &value);
197 RegQueryValueEx(regkey, WndRegKeys[pos&3][4], 0, &value, (LPBYTE)&nTileInWnd, &value);
198 RegCloseKey(regkey);
200 EnableScrollBar(SB_VERT);
201 RECT rect;
202 parent->GetWindowRect(&rect);
203 if (rx==-1 || ry==-1 || cx==-1 || cy==-1)
205 rx = rect.left;
206 ry = rect.top;
207 cx = rect.right - rect.left;
208 cy = rect.bottom - rect.top;
209 switch (pos)
211 case 0:
212 ry=rect.bottom;
213 break;
214 case 1:
215 ry-=rect.bottom - rect.top;
216 break;
217 case 2:
218 rx-=rect.right - rect.left;
219 break;
220 case 3:
221 rx+=rect.right - rect.left;
222 break;
225 else
227 rx += rect.left;
228 ry += rect.top;
230 SetWindowPos(0,rx,ry,cx,cy,0);
232 SendMessage(WM_VSCROLL,0,0);
233 // TODO: Add extra initialization here
234 return TRUE; // return TRUE unless you set the focus to a control
235 // EXCEPTION: OCX Property Pages should return FALSE
238 void ViewColumn::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
240 // TODO: Add your message handler code here and/or call default
241 SCROLLINFO scroll; RECT rect;
242 scroll.fMask = SIF_TRACKPOS | SIF_POS;
243 GetScrollInfo(SB_VERT,&scroll);
244 scroll.cbSize = sizeof(SCROLLINFO);
245 scroll.fMask = SIF_ALL;
246 //scroll.nPos = scroll.nTrackPos;
247 scroll.nMax = 10000;
248 scroll.nMin = 0;
249 GetClientRect(&rect);
250 if (nTiles)
252 if (nTileInWnd==4)
254 scroll.nPage = ((rect.bottom - rect.top)*10000)/(( (nTiles>>1)+(nTiles&1) )*(sizetile_y>>1));
256 else
258 scroll.nPage = ((rect.bottom - rect.top)*10000)/(nTiles*sizetile_y);
261 else scroll.nPage = 10000;
263 switch(nSBCode)
265 case SB_BOTTOM:
266 scroll.nPos = 10000 - scroll.nPage;
267 break;
268 case SB_LINEDOWN:
269 scroll.nPos += scroll.nPage/4;
270 break;
271 case SB_LINEUP:
272 scroll.nPos -= scroll.nPage/4;
273 break;
274 case SB_PAGEDOWN:
275 scroll.nPos += scroll.nPage;
276 break;
277 case SB_PAGEUP:
278 scroll.nPos -= scroll.nPage;
279 break;
280 case SB_THUMBPOSITION:
281 case SB_THUMBTRACK:
282 scroll.nPos = scroll.nTrackPos;
283 break;
284 case SB_TOP:
285 scroll.nPos = 0;
286 break;
287 default:
288 scroll.fMask^=SIF_POS;
289 break;
291 if (scroll.nPos<0)
292 scroll.nPos = 0;
293 else if (scroll.nPos > (10000 - (int)scroll.nPage))
294 scroll.nPos = 10000 - scroll.nPage - 1;
295 this->SetScrollInfo(SB_VERT,&scroll);
296 RedrawWindow();
297 CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
300 void ViewColumn::OnClose()
302 // TODO: Add your message handler code here and/or call default
304 CDialog::OnClose();
307 void ViewColumn::OnSize(UINT nType, int cx, int cy)
309 CDialog::OnSize(nType, cx, cy);
310 SendMessage(WM_VSCROLL,0,0);
313 LRESULT ViewColumn::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
315 // TODO: Add your specialized code here and/or call the base class
316 if (message==WM_CLOSE || message==WM_DESTROY)
318 HKEY regkey;
319 if (RegCreateKey(HKEY_CURRENT_USER,REGKEY_TILEDIT,&regkey)==ERROR_SUCCESS)
322 RECT rect; RECT rpopup;
323 GetWindowRect(&rect);
324 parent->GetWindowRect(&rpopup);
325 int rx,ry,cx,cy; //on sauvegarde les coordonnes de la wnd relativement a la fenetre popup principale
326 rx = rect.left - rpopup.left;
327 ry = rect.top - rpopup.top;
328 cx = rect.right - rect.left;
329 cy = rect.bottom - rect.top;
330 RegSetValueEx(regkey,WndRegKeys[pos][0],0,REG_DWORD,(unsigned char*)&rx,4);
331 RegSetValueEx(regkey,WndRegKeys[pos][1],0,REG_DWORD,(unsigned char*)&ry,4);
332 RegSetValueEx(regkey,WndRegKeys[pos][2],0,REG_DWORD,(unsigned char*)&cx,4);
333 RegSetValueEx(regkey,WndRegKeys[pos][3],0,REG_DWORD,(unsigned char*)&cy,4);
334 RegSetValueEx(regkey,WndRegKeys[pos][4],0,REG_DWORD,(unsigned char*)&nTileInWnd,4);
335 RegCloseKey(regkey);
338 else if (message==WM_MOUSEMOVE)
340 MousePos.x = LOWORD(lParam);
341 MousePos.y = HIWORD(lParam);
343 else if (message==WM_ERASEBKGND)
345 return 0;
347 else if (message==WM_MOUSEWHEEL)
349 if ((short)(HIWORD(wParam))<0)
350 SendMessage(WM_VSCROLL,SB_LINEDOWN,0);
351 else
352 SendMessage(WM_VSCROLL,SB_LINEUP,0);
354 else if (message==WM_COMMAND)
356 switch(LOWORD(wParam))
358 case 10:
359 if (nTileInWnd!=1)
361 nTileInWnd = 1;
362 SendMessage(WM_VSCROLL,0,0);
364 break;
365 case 12:
366 if (nTileInWnd!=4)
368 nTileInWnd = 4;
369 SendMessage(WM_VSCROLL,0,0);
371 break;
372 case 13:
373 RECT rect;
374 parent->GetWindowRect(&rect);
375 int rx,ry,cx,cy;
376 rx = rect.left;
377 ry = rect.top;
378 cx = rect.right - rect.left;
379 cy = rect.bottom - rect.top;
380 switch (pos)
382 case 0:
383 ry=rect.bottom;
384 break;
385 case 1:
386 ry-=rect.bottom - rect.top;
387 break;
388 case 2:
389 rx-=rect.right - rect.left;
390 break;
391 case 3:
392 rx+=rect.right - rect.left;
393 break;
395 SetWindowPos(0,rx,ry,cx,cy,0);
396 break;
399 return CDialog::WindowProc(message, wParam, lParam);
402 void ViewColumn::OnRButtonDown(UINT nFlags, CPoint point)
404 // TODO: Add your message handler code here and/or call default
405 CMenu popup;
406 popup.CreatePopupMenu();
407 popup.AppendMenu(MF_STRING | (nTileInWnd == 1 ? MF_CHECKED:0), 10, _T("*1"));
408 popup.AppendMenu(MF_STRING | (nTileInWnd == 4 ? MF_CHECKED:0), 12, _T("*4"));
409 popup.AppendMenu(MF_STRING, 13, _T("Replace window"));
411 RECT rect; GetWindowRect(&rect);
412 popup.TrackPopupMenu(TPM_LEFTALIGN,MousePos.x+rect.left,MousePos.y+rect.top,this,NULL);
413 CDialog::OnRButtonDown(nFlags, point);