Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / tools / 3d / tile_edit / Browse.cpp
blobfee54410f33ba7c1e13b567effe88a1efe8f3a23
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "stdafx.h"
22 //#include "tile_edit_dll.h"
23 #include "resource.h"
24 #include "Browse.h"
25 #include "custom.h"
26 #include "getval.h"
28 using namespace NL3D;
29 using namespace NLMISC;
31 extern CTileBank tileBank2;
33 /////////////////////////////////////////////////////////////////////////////
34 // Browse dialog
36 Browse::Browse(int nland, CWnd* pParent /*=NULL*/)
37 : CDialog(Browse::IDD, pParent)
39 //{{AFX_DATA_INIT(Browse)
40 SubGroup0 = FALSE;
41 SubGroup1 = FALSE;
42 SubGroup2 = FALSE;
43 SubGroup3 = FALSE;
44 SubGroup4 = FALSE;
45 SubGroup5 = FALSE;
46 SubGroup6 = FALSE;
47 SubGroup7 = FALSE;
48 SubGroup10 = FALSE;
49 SubGroup11 = FALSE;
50 SubGroup8 = FALSE;
51 SubGroup9 = FALSE;
52 Oriented = FALSE;
53 //}}AFX_DATA_INIT
54 land=nland;
55 m_128x128=0;
59 void Browse::DoDataExchange(CDataExchange* pDX)
61 CDialog::DoDataExchange(pDX);
62 //{{AFX_DATA_MAP(Browse)
63 DDX_Radio(pDX, IDC_128X128, m_128x128);
64 DDX_Control(pDX, IDC_VIEW, m_ctrl);
65 DDX_Control(pDX, IDC_INFONUM, m_infotexte);
66 DDX_Control(pDX, IDC_JOUR, m_rb_jour);
67 DDX_Check(pDX, IDC_SUBGROUP0, SubGroup0);
68 DDX_Check(pDX, IDC_SUBGROUP1, SubGroup1);
69 DDX_Check(pDX, IDC_SUBGROUP2, SubGroup2);
70 DDX_Check(pDX, IDC_SUBGROUP3, SubGroup3);
71 DDX_Check(pDX, IDC_SUBGROUP4, SubGroup4);
72 DDX_Check(pDX, IDC_SUBGROUP5, SubGroup5);
73 DDX_Check(pDX, IDC_SUBGROUP6, SubGroup6);
74 DDX_Check(pDX, IDC_SUBGROUP7, SubGroup7);
75 DDX_Check(pDX, IDC_SUBGROUP10, SubGroup10);
76 DDX_Check(pDX, IDC_SUBGROUP11, SubGroup11);
77 DDX_Check(pDX, IDC_SUBGROUP8, SubGroup8);
78 DDX_Check(pDX, IDC_SUBGROUP9, SubGroup9);
79 DDX_Check(pDX, IDC_ORIENTED, Oriented);
80 //}}AFX_DATA_MAP
84 BEGIN_MESSAGE_MAP(Browse, CDialog)
85 //{{AFX_MSG_MAP(Browse)
86 ON_WM_SIZE()
87 ON_BN_CLICKED(IDC_ALPHA, OnAlpha)
88 ON_BN_CLICKED(IDC_128X128, OnChangeVariety)
89 ON_BN_CLICKED(IDC_JOUR, OnJour)
90 ON_BN_CLICKED(IDC_NUIT, OnNuit)
91 ON_BN_CLICKED(IDC_OK, OnOk)
92 ON_WM_RBUTTONDOWN()
93 ON_BN_CLICKED(IDC_OK2, OnUpdateTiles)
94 ON_BN_CLICKED(IDC_BATCH_LOAD, OnBatchLoad)
95 ON_BN_CLICKED(IDC_SUBGROUP0, OnSubgroup0)
96 ON_BN_CLICKED(IDC_SUBGROUP1, OnSubgroup1)
97 ON_BN_CLICKED(IDC_SUBGROUP2, OnSubgroup2)
98 ON_BN_CLICKED(IDC_SUBGROUP3, OnSubgroup3)
99 ON_BN_CLICKED(IDC_SUBGROUP4, OnSubgroup4)
100 ON_BN_CLICKED(IDC_SUBGROUP5, OnSubgroup5)
101 ON_BN_CLICKED(IDC_SUBGROUP6, OnSubgroup6)
102 ON_BN_CLICKED(IDC_SUBGROUP7, OnSubgroup7)
103 ON_BN_CLICKED(IDC_SUBGROUP8, OnSubgroup8)
104 ON_BN_CLICKED(IDC_SUBGROUP9, OnSubgroup9)
105 ON_BN_CLICKED(IDC_SUBGROUP10, OnSubgroup10)
106 ON_BN_CLICKED(IDC_SUBGROUP11, OnSubgroup11)
107 ON_BN_CLICKED(IDC_EXPORT_BORDER, OnExportBorder)
108 ON_BN_CLICKED(IDC_ZOOM5, OnChangeVariety)
109 ON_BN_CLICKED(IDC_ZOOM6, OnChangeVariety)
110 ON_BN_CLICKED(IDCANCEL, OnCancel)
111 ON_BN_CLICKED(IDC_CANCEL, OnCancel)
112 ON_BN_CLICKED(IDC_DISPLACE, OnChangeVariety)
113 ON_BN_CLICKED(IDC_IMPORT_BORDER2, OnImportBorder)
114 //}}AFX_MSG_MAP
115 END_MESSAGE_MAP()
117 /////////////////////////////////////////////////////////////////////////////
118 // Browse message handlers
120 BOOL Browse::PreCreateWindow(CREATESTRUCT& cs)
122 // TODO: Add your specialized code here and/or call the base class
124 return CDialog::PreCreateWindow(cs);
127 DWORD thread_id;
128 int thread_actif = 0;
129 Browse *pDialog;
130 int ccount=0;
132 LRESULT Browse::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
135 // TODO: Add your specialized code here and/or call the base class
136 if (ccount==0 && message==WM_PAINT)
138 Init();
140 if (message==WM_KEYUP || message==WM_KEYDOWN)
142 RECT parent,client;
143 GetWindowRect(&parent); m_ctrl.GetWindowRect(&client);
144 if (m_ctrl.MousePos.x<(client.right - parent.left) &&
145 m_ctrl.MousePos.x>0 &&
146 m_ctrl.MousePos.y<(client.bottom - client.top) &&
147 m_ctrl.MousePos.y>0)
149 m_ctrl.SendMessage(message,wParam,lParam);
153 if (message==WM_MOUSEMOVE)
155 m_ctrl.MousePos.x = LOWORD(lParam);
156 m_ctrl.MousePos.y = HIWORD(lParam);
158 RECT client, parent;
160 ClientToScreen (&m_ctrl.MousePos);
161 m_ctrl.ScreenToClient (&m_ctrl.MousePos);
163 m_ctrl.GetWindowRect(&client);
164 GetWindowRect(&parent);
165 if (m_ctrl.MousePos.x<0)
166 m_ctrl.MousePos.x=0;
167 if (m_ctrl.MousePos.x>client.right-client.left)
168 m_ctrl.MousePos.x=client.right-client.left;
169 if (m_ctrl.MousePos.y<0)
170 m_ctrl.MousePos.y=0;
171 if (m_ctrl.MousePos.y>client.bottom-client.top)
172 m_ctrl.MousePos.y=client.bottom-client.top;
174 m_ctrl.ClientToScreen (&m_ctrl.MousePos);
175 ScreenToClient (&m_ctrl.MousePos);
177 if (lbutton) //on dessine le carre de selection
179 selection = 1;
180 RECT current;
181 SIZE size; size.cx = size.cy = 1;
182 current.left = OriginalPos.x;
183 current.top = OriginalPos.y;
184 current.right = m_ctrl.MousePos.x;
185 current.bottom = m_ctrl.MousePos.y;
186 if (current.left>current.right) {int temp = current.left; current.left = current.right; current.right = temp;}
187 if (current.top>current.bottom) {int temp = current.bottom; current.bottom = current.top; current.top = temp;}
189 CDC *pDC = GetDC();
190 m_ctrl.DrawDragRect(pDC,NULL,size,&last_sel,size); //on efface l'ancien carre
192 m_ctrl.UpdateSelection(&current, (int)wParam, m_128x128); //on affiche les modifes
194 m_ctrl.DrawDragRect(pDC,&current,size,NULL,size); //on affiche le nouveau carre
195 ::ReleaseDC(*this,*pDC);
197 last_sel = current;
200 if (message==WM_DROPFILES)
202 m_ctrl.PostMessage(WM_DROPFILES,wParam,lParam);
204 if (message==WM_COMMAND && !thread_actif)
206 int button = LOWORD(wParam);
207 if (button==IDC_ZOOM1 || button==IDC_ZOOM2 || button==IDC_ZOOM3)
209 m_ctrl.Zoom = button - IDC_ZOOM1 +1;
210 m_ctrl.UpdateSize(m_128x128);
211 m_ctrl.scrollpos = 0;
212 SetScrollPos(SB_VERT,0,true);
213 m_ctrl.RedrawWindow();
215 else if (button==IDC_INFONUM)
217 m_ctrl.InfoTexte = 1;
218 m_ctrl.RedrawWindow();
220 else if (button==IDC_FILENAME)
222 m_ctrl.InfoTexte =2;
223 m_ctrl.RedrawWindow();
225 else if (button==IDC_GROUP)
227 m_ctrl.InfoTexte = 3;
228 m_ctrl.RedrawWindow();
230 else if (button>=10 && button<=15)
231 m_ctrl.PostMessage(WM_COMMAND,wParam,lParam);
233 if (message==WM_LBUTTONDOWN)
235 int xPos = LOWORD(lParam); // horizontal position of cursor
236 int yPos = HIWORD(lParam); // vertical position of cursor
238 if (lbutton) //on dessine le carre de selection
240 selection = 1;
241 RECT current;
242 SIZE size; size.cx = size.cy = 1;
243 current.left = OriginalPos.x;
244 current.top = OriginalPos.y;
245 current.right = m_ctrl.MousePos.x;
246 current.bottom = m_ctrl.MousePos.y;
247 if (current.left>current.right) {int temp = current.left; current.left = current.right; current.right = temp;}
248 if (current.top>current.bottom) {int temp = current.bottom; current.bottom = current.top; current.top = temp;}
250 CDC *pDC = GetDC();
251 m_ctrl.DrawDragRect(pDC,NULL,size,&last_sel,size); //on efface l'ancien carre
253 m_ctrl.UpdateSelection(&current,(int)wParam, m_128x128); //on affiche les modifes
255 ::ReleaseDC(*this,*pDC);
257 last_sel = current;
260 RECT p,rect; p.left = m_ctrl.MousePos.x; p.top = m_ctrl.MousePos.y;
261 ClientToScreen(&p);
262 m_ctrl.GetClientRect(&rect);
263 POINT pt; pt.x = p.left; pt.y = p.top;
264 m_ctrl.ScreenToClient(&pt);
265 if (pt.x>=rect.left && pt.x<rect.right && pt.y>=rect.top && pt.y<rect.bottom)
267 m_ctrl.SetFocus();
268 int index = m_ctrl.GetIndex(&pt, m_128x128);
269 if (index!=-1 && !(wParam&MK_SHIFT)/* && !(wParam&MK_CONTROL)*/)
271 tilelist::iterator p = m_ctrl.InfoList.Get(index, m_128x128);
272 if (p!=m_ctrl.InfoList.GetLast(m_128x128))
274 tilelist::iterator pp = p;
275 if (wParam&MK_CONTROL)
276 p->Selected = p->Selected?0:7;
277 else
278 p->Selected = 1;
279 CDC *pDC = NULL;
280 int indexx=0;
281 for (p=m_ctrl.InfoList.GetFirst(m_128x128);p!=m_ctrl.InfoList.GetLast(m_128x128);++p, indexx++)
283 if (p!=pp && p->Selected)
285 if (!(wParam&MK_CONTROL))
287 p->Selected = 0;
288 if (pDC==NULL) pDC = m_ctrl.GetDC();
289 m_ctrl.DrawTile(p,pDC,1,m_128x128);
292 else
294 if (p==pp)
296 if (pDC==NULL) pDC = m_ctrl.GetDC();
297 m_ctrl.DrawTile(p,pDC,1,m_128x128);
301 if (pDC) ::ReleaseDC(*this,*pDC);
304 else
306 if (!(wParam&MK_CONTROL) && !(wParam&MK_SHIFT))
308 tilelist::iterator p = m_ctrl.InfoList.GetFirst(m_128x128);
309 CDC *pDC = NULL;
310 for (int i = 0; i<m_ctrl.InfoList.GetSize(m_128x128); i++)
312 if (p->Selected)
314 if (pDC==NULL) pDC = m_ctrl.GetDC();
315 //m_ctrl.InfoList.setSelection (i, 0);
316 p->Selected = 0;
317 m_ctrl.DrawTile(p,pDC,1,m_128x128);
319 p++;
321 if (pDC) ::ReleaseDC(*this,*pDC);
324 lbutton = 1;
326 SIZE size; size.cx = size.cy = 1;
328 last_sel.top = xPos;
329 last_sel.left = yPos;
330 last_sel.bottom = xPos;
331 last_sel.right = yPos;
332 OriginalPos.x=xPos;
333 OriginalPos.y=yPos;
336 if (message==WM_LBUTTONUP || message==WM_NCLBUTTONUP)
338 RECT p; p.left = m_ctrl.MousePos.x; p.top = m_ctrl.MousePos.y;
339 ClientToScreen(&p);
340 POINT pt; pt.x = p.left; pt.y = p.top;
341 m_ctrl.ScreenToClient(&pt);
342 int index = m_ctrl.GetIndex(&pt, m_128x128);
343 if (!selection && index!=-1)
345 int i = 0;
347 else if (selection)
349 CDC *pDC = GetDC();
350 CSize size; size.cx = size.cy = 1;
351 m_ctrl.DrawDragRect(pDC,NULL,size,&last_sel,size);
352 ::ReleaseDC(*this,*pDC);
353 int index=0;
354 for (tilelist::iterator p = m_ctrl.InfoList.GetFirst(m_128x128);p!=m_ctrl.InfoList.GetLast(m_128x128);++p, index++)
356 if (p->Selected&3)
358 p->Selected=2;
360 else
361 p->Selected = 0;
364 selection =0;
365 lbutton = 0;
367 if (message==WM_KEYDOWN)
369 int toto = 0;
371 if (message==WM_SIZE && m_ctrl.count_ )
373 int x = LOWORD(lParam);
374 int y = HIWORD(lParam);
376 int i = std::max (1, m_ctrl.GetNbTileLine());
377 int j = std::max (1, m_ctrl.GetNbTileColumn());
378 int pos = m_ctrl.GetScrollPos(SB_VERT);
379 int hview = (m_ctrl.InfoList.GetSize(m_128x128)/i + 1)*(m_ctrl.sizeicon_y + m_ctrl.spacing_y) + m_ctrl.spacing_y;
380 m_ctrl.scrollpos = (pos*hview)/SCROLL_MAX;
382 RECT clientrect,rect;
383 m_ctrl.GetWindowRect(&clientrect);
384 InvalidateRect(NULL,false);
385 GetWindowRect(&rect);
386 m_ctrl.SetWindowPos(NULL, 0, 0, std::max (100, x - 120), y - 20, SWP_NOMOVE);
387 int iFirst,iLast;
388 m_ctrl.GetVisibility(iFirst, iLast, m_128x128);
389 m_ctrl.UpdateBar(iFirst, iLast, m_128x128);
390 return 0;
392 if (message==WM_VSCROLL || message==WM_MOUSEWHEEL)
394 SCROLLINFO inf;
395 RECT rect_scroll,rect_clip;
396 int scrollcode,pos;
397 inf.fMask = SIF_ALL;
398 GetScrollInfo(SB_VERT,&inf);
399 m_ctrl.GetClientRect(&rect_scroll);
400 int i = m_ctrl.GetNbTileLine();
401 int hview = (m_ctrl.InfoList.GetSize(m_128x128)/i + 2)*(m_ctrl.sizeicon_y + m_ctrl.spacing_y) + m_ctrl.spacing_y;
403 if (message==WM_MOUSEWHEEL)
405 int inc = ((int)(short)HIWORD(wParam))/WHEEL_DELTA;
406 pos = inf.nPos - inc*(((m_ctrl.sizeicon_y+m_ctrl.spacing_y)*SCROLL_MAX)/(hview - m_ctrl.spacing_y));
408 else
410 scrollcode = LOWORD(wParam);
411 pos = inf.nTrackPos;
412 switch (scrollcode)
414 case SB_BOTTOM:
415 pos = SCROLL_MAX - inf.nPage;
416 break;
417 case SB_PAGEDOWN:
418 pos = inf.nPos + inf.nPage;
419 break;
420 case SB_PAGEUP:
421 pos = inf.nPos - inf.nPage;
422 break;
423 case SB_LINEUP:
424 pos = inf.nPos - (((m_ctrl.sizeicon_y+m_ctrl.spacing_y)*SCROLL_MAX)/(hview - m_ctrl.spacing_y));
425 break;
426 case SB_LINEDOWN:
427 pos = inf.nPos + (((m_ctrl.sizeicon_y+m_ctrl.spacing_y)*SCROLL_MAX)/(hview - m_ctrl.spacing_y));
428 break;
429 case SB_TOP:
430 pos = 0;
431 break;
432 case SB_THUMBPOSITION:
433 case SB_ENDSCROLL:
434 pos = inf.nPos;
435 break;
439 if (pos<0) pos = 0;
440 if (pos>(SCROLL_MAX - (int)inf.nPage))
441 pos = SCROLL_MAX - inf.nPage;
443 SetScrollPos(SB_VERT,pos,1);
444 rect_scroll.bottom -= rect_scroll.top;
445 rect_scroll.top = 0;
446 rect_clip = rect_scroll;
447 int scroll_pixel = m_ctrl.scrollpos;
448 int old_iFV,old_iLV;
449 m_ctrl.GetVisibility(old_iFV, old_iLV, m_128x128);
450 m_ctrl.scrollpos = (pos*hview)/(SCROLL_MAX);
451 int iFV,iLV;
452 m_ctrl.GetVisibility(iFV, iLV, m_128x128);
454 if (iFV>old_iLV || iLV<old_iFV || scrollcode==SB_PAGEDOWN || scrollcode==SB_PAGEUP)
456 m_ctrl.RedrawWindow();
458 else
460 scroll_pixel -= m_ctrl.scrollpos;
461 if (scroll_pixel)
463 CDC *pDC = m_ctrl.GetDC();
464 if (abs(scroll_pixel)>(rect_clip.bottom - rect_clip.top)) scroll_pixel = 0;
465 else pDC->ScrollDC(0,scroll_pixel,&rect_scroll,&rect_clip,NULL,NULL);
467 tilelist::iterator p = m_ctrl.InfoList.GetFirst(m_128x128);
468 CBrush brush (GetSysColor(COLOR_3DFACE));
469 if (scroll_pixel<0)
471 rect_scroll.top = rect_scroll.bottom + scroll_pixel;
472 pDC->FillRect(&rect_scroll,&brush);
473 if ((iLV-i)<iFV) i = iLV - iFV;
474 int k;
475 for (k = 0;k<old_iLV-i;k++) p++;
476 for (k=old_iLV - i;k<=iLV;k++)
478 m_ctrl.DrawTile(p,pDC,0,m_128x128);
479 p++;
482 else
484 rect_scroll.bottom = rect_scroll.top + scroll_pixel;
485 pDC->FillRect(&rect_scroll,&brush);
486 int k;
487 for (k = 0;k<iFV;k++) p++;
488 for (k = iFV;k<(old_iFV+i);k++)
490 m_ctrl.DrawTile(p,pDC,0,m_128x128);
491 p++;
494 ::ReleaseDC(m_ctrl,*pDC);
497 m_ctrl.lastVBarPos = pos;
499 if (message==WM_CLOSE)
501 ccount=0;
502 this->m_ctrl.count_=0;
503 OnDestroy();
505 if (message==WM_LBUTTONDBLCLK)
507 m_ctrl.SendMessage(WM_LBUTTONDBLCLK,wParam,lParam);
509 pDialog=this;
510 return CDialog::WindowProc(message, wParam, lParam);
514 unsigned long Browse::MyControllingFunction( void* pParam )
516 thread_actif = 1;
517 Browse *br = (Browse*)pParam;
518 br->m_ctrl.lockInsertion = 1;
519 int iFV,iLV;
520 br->m_ctrl.GetVisibility(iFV, iLV, br->m_128x128);
521 br->m_ctrl.UpdateBar(iFV, iLV, br->m_128x128);
522 tilelist::iterator p = br->m_ctrl.InfoList.GetFirst(br->m_128x128);
523 tilelist::iterator plast = p;
524 for (int i=0;i<br->m_ctrl.InfoList.GetSize(br->m_128x128);i++)
526 int *ld;
527 int rot=0;
528 std::string path;
529 LPBITMAPINFO pBmp;
530 std::vector<NLMISC::CBGRA>* bits;
532 switch (br->m_128x128)
534 case 0:
535 path = tileBank2.getTile (tileBank2.getTileSet (br->m_ctrl.InfoList._tileSet)->getTile128 (i))->
536 getRelativeFileName ((CTile::TBitmap)(br->m_ctrl.Texture-1));
537 break;
538 case 1:
539 path = tileBank2.getTile (tileBank2.getTileSet (br->m_ctrl.InfoList._tileSet)->getTile256 (i))->
540 getRelativeFileName ((CTile::TBitmap)(br->m_ctrl.Texture-1));
541 break;
542 case 2:
544 int index=tileBank2.getTileSet (br->m_ctrl.InfoList._tileSet)->getTransition (i)->getTile();
545 if (index!=-1)
547 path = tileBank2.getTile (index)->getRelativeFileName ((CTile::TBitmap)(br->m_ctrl.Texture-1));
548 if (br->m_ctrl.Texture==3)
549 rot = tileBank2.getTile (index)->getRotAlpha ();
551 else
552 path.clear();
554 break;
555 case 3:
556 // Get diplacement filename
557 path = tileBank2.getDisplacementMap (tileBank2.getTileSet (br->m_ctrl.InfoList._tileSet)->getDisplacementTile ((CTileSet::TDisplacement)i));
558 break;
560 std::vector<NLMISC::CBGRA>* pAlpha=NULL;
561 switch (br->m_ctrl.Texture)
563 case 1:
564 ld = &p->loaded;
565 pBmp = &p->BmpInfo;
566 bits = &p->Bits;
567 pAlpha = &p->alphaBits;
568 break;
569 case 2:
570 ld = &p->nightLoaded;
571 pBmp = &p->nightBmpInfo;
572 bits = &p->nightBits;
573 pAlpha = &p->alphaBits;
574 break;
575 case 3:
576 ld = &p->alphaLoaded;
577 pBmp = &p->alphaBmpInfo;
578 bits = &p->alphaBits;
579 break;
582 if (!path.empty() && _LoadBitmap(tileBank2.getAbsPath() + path, pBmp, *bits, pAlpha, rot))
584 *ld=1;
585 int iFV,iLV; br->m_ctrl.GetVisibility(iFV, iLV, br->m_128x128);
586 if (i<=iLV && i>=iFV)
588 CDC *pDC = br->m_ctrl.GetDC();
589 br->m_ctrl.DrawTile(p,pDC,1,br->m_128x128);
590 ::ReleaseDC(*br,*pDC);
593 p++;
595 br->m_ctrl.lockInsertion = 0;
596 thread_actif = 0;
597 return 1;
600 void Browse::LoadInThread(void)
602 if (!thread_actif)
603 MyControllingFunction (this);
607 void Browse::Init()
609 UpdateData ();
610 lbutton = 0;
611 selection = 0;
612 control = 0;
613 m_ctrl.lockInsertion = 0; oldsel = -1;
614 HKEY regkey;
615 unsigned long value;
616 unsigned long type;
617 int cx=-1,cy=-1,x=-1,y=-1;
618 TCHAR sWindowpl[256];
620 if (RegOpenKey(HKEY_CURRENT_USER,REGKEY_TILEDIT,&regkey)==ERROR_SUCCESS)
622 value=256;
623 type=REG_SZ;
624 if (RegQueryValueEx(regkey,REGKEY_WNDPL,0,&type,(unsigned char *)&sWindowpl,&value)==ERROR_SUCCESS)
626 WINDOWPLACEMENT wndpl;
627 _stscanf(sWindowpl,_T("%d %d %d %d %d %d %d %d %d %d"),
628 &wndpl.flags,
629 &wndpl.ptMaxPosition.x,&wndpl.ptMaxPosition.y,
630 &wndpl.ptMinPosition.x,&wndpl.ptMinPosition.y,
631 &wndpl.rcNormalPosition.bottom,&wndpl.rcNormalPosition.left,&wndpl.rcNormalPosition.right,&wndpl.rcNormalPosition.top,
632 &wndpl.showCmd);
633 wndpl.length = sizeof(WINDOWPLACEMENT);
634 this->SetWindowPlacement(&wndpl);
636 value=256;
637 type=REG_SZ;
638 if (RegQueryValueEx(regkey, REGKEY_LASTPATH, 0, &type, (unsigned char *)&sWindowpl, &value) != ERROR_SUCCESS)
639 m_ctrl.LastPath.clear();
640 else
641 m_ctrl.LastPath = tStrToUtf8(sWindowpl);
642 value=4;
643 type=REG_DWORD;
644 if (RegQueryValueEx(regkey,REGKEY_BUTTONZOOM,0,&type,(unsigned char *)&m_ctrl.Zoom,&value)!=ERROR_SUCCESS)
645 m_ctrl.Zoom = 3;
646 value=4;
647 type=REG_DWORD;
648 if (RegQueryValueEx(regkey,REGKEY_BUTTONVARIETY,0,&type,(unsigned char *)&m_128x128,&value)!=ERROR_SUCCESS)
649 m_128x128 = 0;
650 value=4;
651 type=REG_DWORD;
652 if (RegQueryValueEx(regkey,REGKEY_BUTTONTEXTURE,0,&type,(unsigned char *)&m_ctrl.Texture,&value)!=ERROR_SUCCESS)
653 m_ctrl.Texture = 1;
654 value=4;
655 type=REG_DWORD;
656 if (RegQueryValueEx(regkey,REGKEY_BUTTONTEXTINFO,0,&type,(unsigned char *)&m_ctrl.InfoTexte,&value)!=ERROR_SUCCESS)
657 m_ctrl.InfoTexte = 1;
658 RegCloseKey(regkey);
660 CButton *button = (CButton*)GetDlgItem(IDC_ZOOM1 + m_ctrl.Zoom -1);
661 button->SetCheck(1);
662 button = (CButton*)GetDlgItem(IDC_JOUR + m_ctrl.Texture -1);
663 button->SetCheck(1);
664 button = (CButton*)GetDlgItem(IDC_INFONUM + m_ctrl.InfoTexte -1);
665 button->SetCheck(1);
666 if (cx!=-1 && cy!=-1 && x!=-1 && y!=-1) SetWindowPos(0,x,y,cx,cy,0);
668 m_ctrl.Init(land, m_128x128);
669 SelectionTerritoire *slt = (SelectionTerritoire*)GetParent();
670 ccount=1;
672 RECT rect;
673 this->GetWindowRect(&rect);
674 SendMessage(WM_SIZE,rect.right - rect.left,rect.bottom - rect.top); //force resize
676 SelectionTerritoire *parent = (SelectionTerritoire*)GetParent();
678 // The land
679 CTileSet *tileSet=tileBank2.getTileSet (land);
681 if (tileSet->getOriented())
682 Oriented = 1;
683 else
684 Oriented = 0;
686 // 128
687 m_ctrl.InfoList.theList128.resize (tileSet->getNumTile128 ());
688 int i;
689 for (i=0; i<tileSet->getNumTile128 (); i++)
691 m_ctrl.InfoList.theList128[i].id=i;
692 m_ctrl.InfoList.theList128[i].Selected=0;
693 m_ctrl.InfoList.theList128[i].loaded=0;
694 m_ctrl.InfoList.theList128[i].nightLoaded=0;
695 m_ctrl.InfoList.theList128[i].alphaLoaded=0;
697 m_ctrl.InfoList.Reload (0, tileSet->getNumTile128 (), 0);
699 // 256
700 m_ctrl.InfoList.theList256.resize (tileSet->getNumTile256 ());
701 for (i=0; i<tileSet->getNumTile256 (); i++)
703 m_ctrl.InfoList.theList256[i].id=i;
704 m_ctrl.InfoList.theList256[i].Selected=0;
705 m_ctrl.InfoList.theList256[i].loaded=0;
706 m_ctrl.InfoList.theList256[i].nightLoaded=0;
707 m_ctrl.InfoList.theList256[i].alphaLoaded=0;
709 m_ctrl.InfoList.Reload (0, tileSet->getNumTile256 (), 1);
711 // Transition
712 for (i=0; i<CTileSet::count; i++)
714 m_ctrl.InfoList.theListTransition[i].id=i;
715 m_ctrl.InfoList.theListTransition[i].Selected=0;
716 m_ctrl.InfoList.theListTransition[i].loaded=0;
717 m_ctrl.InfoList.theListTransition[i].nightLoaded=0;
718 m_ctrl.InfoList.theListTransition[i].alphaLoaded=0;
720 m_ctrl.InfoList.Reload (0, CTileSet::count, 2);
722 // Displacement
723 for (i=0; i<CTileSet::CountDisplace; i++)
725 m_ctrl.InfoList.theListDisplacement[i].id=i;
726 m_ctrl.InfoList.theListDisplacement[i].Selected=0;
727 m_ctrl.InfoList.theListDisplacement[i].loaded=0;
728 m_ctrl.InfoList.theListDisplacement[i].nightLoaded=0;
729 m_ctrl.InfoList.theListDisplacement[i].alphaLoaded=0;
731 m_ctrl.InfoList.Reload (0, CTileSet::CountDisplace, 3);
733 CString fullpath = parent->DefautPath + parent->CurrentTerritory;
735 LoadInThread();
736 UpdateData (FALSE);
738 OnChangeVariety();
743 void Browse::OnSize(UINT nType, int cx, int cy)
745 CDialog::OnSize(nType, cx, cy);
748 void Browse::OnAlpha ()
750 // TODO: Add your control notification handler code here
751 m_ctrl.Texture = 3;
752 LoadInThread();
753 m_ctrl.RedrawWindow();
756 void Browse::OnJour ()
758 // TODO: Add your control notification handler code here
759 m_ctrl.Texture = 1;
760 LoadInThread();
761 m_ctrl.RedrawWindow();
764 void Browse::OnNuit ()
766 // TODO: Add your control notification handler code here
767 m_ctrl.Texture = 2;
768 LoadInThread();
769 m_ctrl.RedrawWindow();
772 void Browse::OnNum()
774 // TODO: Add your control notification handler code here
775 m_ctrl.Sort = 1;
776 m_ctrl.SendMessage(WM_PAINT);
779 void Browse::OnCancel()
781 // TODO: Add your control notification handler code here
782 if (thread_actif) return;
784 if (::MessageBox (NULL, _T("Are you sure you want to cancel?"), _T("Cancel"), MB_OK|MB_ICONQUESTION|MB_YESNO)==IDYES)
786 this->SendMessage(WM_CLOSE);
787 CDialog::OnCancel();
789 EndDialog(0);*/
793 void Browse::UpdateAll(void)
798 void Browse::OnDestroy()
800 // TODO: Add your control notification handler code here
801 HKEY regkey;
802 WINDOWPLACEMENT wndpl;
803 this->GetWindowPlacement(&wndpl);
804 char sWindowpl[256];
805 sprintf(sWindowpl,"%d %d %d %d %d %d %d %d %d %d",
806 wndpl.flags,
807 wndpl.ptMaxPosition.x,wndpl.ptMaxPosition.y,
808 wndpl.ptMinPosition.x,wndpl.ptMinPosition.y,
809 wndpl.rcNormalPosition.bottom,wndpl.rcNormalPosition.left,wndpl.rcNormalPosition.right,wndpl.rcNormalPosition.top,
810 wndpl.showCmd);
811 if (RegCreateKey(HKEY_CURRENT_USER,REGKEY_TILEDIT,&regkey)==ERROR_SUCCESS)
813 //int sel = ((CComboBox*)GetDlgItem(IDC_LISTTYPE))->GetCurSel();
814 tstring tWindowpl = utf8ToTStr(sWindowpl);
815 tstring tLastPath = utf8ToTStr(m_ctrl.LastPath);
816 RegSetValueEx(regkey, REGKEY_WNDPL, 0, REG_SZ, (const BYTE *)tWindowpl.c_str(), (tWindowpl.size() + 1) * sizeof(TCHAR));
817 RegSetValueEx(regkey, REGKEY_LASTPATH, 0, REG_SZ, (const BYTE *)tLastPath.c_str(), (tLastPath.size() + 1) * sizeof(TCHAR));
818 RegSetValueEx(regkey,REGKEY_BUTTONZOOM,0,REG_DWORD,(const unsigned char*)&m_ctrl.Zoom,4);
819 RegSetValueEx(regkey,REGKEY_BUTTONVARIETY,0,REG_DWORD,(const unsigned char*)&m_128x128,4);
820 RegSetValueEx(regkey,REGKEY_BUTTONTEXTURE,0,REG_DWORD,(const unsigned char*)&m_ctrl.Texture,4);
821 RegSetValueEx(regkey,REGKEY_BUTTONSORT,0,REG_DWORD,(const unsigned char*)&m_ctrl.Sort,4);
822 RegSetValueEx(regkey,REGKEY_BUTTONTEXTINFO,0,REG_DWORD,(const unsigned char*)&m_ctrl.InfoTexte,4);
823 RegCloseKey(regkey);
827 void Browse::OnOk()
829 // TODO: Add your control notification handler code here
830 if (thread_actif) return;
832 // trap - Don't know if this is the right place to do this
833 UpdateData ();
834 CTileSet *tileSet=tileBank2.getTileSet (land);
835 tileSet->setOriented(Oriented?true:false);
838 this->SendMessage(WM_CLOSE);
839 EndDialog(1);
842 void Browse::OnRButtonDown(UINT nFlags, CPoint point)
844 // TODO: Add your message handler code here and/or call default
845 m_ctrl.PostMessage(WM_RBUTTONDOWN,point.x,point.y);
846 CDialog::OnRButtonDown(nFlags, point);
849 void Browse::OnSelchangeListtype()
853 void Browse::OnUpdateTiles()
855 // TODO: Add your control notification handler code here
856 LoadInThread();
860 void Browse::OnChangeVariety()
862 UpdateData();
863 m_ctrl.UpdateSize (m_128x128);
865 // Enable window
866 GetDlgItem (IDC_JOUR)->EnableWindow (m_128x128!=3);
867 GetDlgItem (IDC_NUIT)->EnableWindow (m_128x128!=3);
868 GetDlgItem (IDC_ALPHA)->EnableWindow (m_128x128==2);
869 GetDlgItem (IDC_BATCH_LOAD)->EnableWindow (m_128x128==2);
871 if ((m_ctrl.Texture==3)&&(m_128x128!=2))
873 m_ctrl.Texture=2;
874 ((CButton*)GetDlgItem (IDC_ALPHA))->SetCheck (0);
875 ((CButton*)GetDlgItem (IDC_NUIT))->SetCheck (1);
878 if ((m_ctrl.Texture!=1)&&(m_128x128==3))
880 m_ctrl.Texture=1;
881 ((CButton*)GetDlgItem (IDC_ALPHA))->SetCheck (0);
882 ((CButton*)GetDlgItem (IDC_NUIT))->SetCheck (0);
883 ((CButton*)GetDlgItem (IDC_JOUR))->SetCheck (1);
886 m_ctrl.Invalidate ();
887 UpdateData(FALSE);
890 void Browse::OnBatchLoad ()
892 CFileDialog sFile (true, NULL, NULL, OFN_ENABLESIZING, _T("PNG Bitmap (*.png)|*.png|Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||"), NULL);
894 if (sFile.DoModal()==IDOK)
896 std::string fullPath = tStrToUtf8(sFile.GetPathName());
898 std::string path = NLMISC::CFile::getPath(fullPath);
899 std::string filename = NLMISC::CFile::getFilenameWithoutExtension(fullPath);
900 std::string ext = NLMISC::CFile::getExtension(fullPath);
902 // look for some numbers..
903 std::string::size_type pos = filename.find_last_not_of("0123456789");
905 if (pos != std::string::npos)
907 filename = filename.substr(0, pos + 1);
910 bool rotate=false;
912 if (::MessageBox (NULL, _T("Do you want to use rotation to reuse alpha tiles ?"), _T("Import rotated tiles"), MB_OK|MB_ICONQUESTION|MB_YESNO)==IDYES)
913 rotate=true;
915 for (int i=0; i<CTileSet::count; i++)
917 if (m_ctrl.Texture==3)
919 // Current transition
920 CTileSet::TTransition transition=(CTileSet::TTransition)i;
922 // Transition to patch
923 CTileSetTransition* trans=tileBank2.getTileSet (land)->getTransition (transition);
924 if (tileBank2.getTile (trans->getTile())->getRelativeFileName (CTile::alpha).empty())
926 // Continue ?
927 int ok;
929 // Try to load transition with rotation
930 for (int rot=0; rot<4; rot++)
932 // Try to load a tile with a file name like /tiletransition0.tga
933 std::string sFinal = path + toString("%s%02d.%s", filename.c_str(), (int)transition, ext.c_str());
935 FILE *pFile = nlfopen (sFinal, "rb");
937 // Close the file and add the tile if opened
938 if (pFile)
940 fclose (pFile);
941 ok=m_ctrl.InfoList.setTileTransitionAlpha (i, sFinal, (4-rot)%4);
943 // End
944 break;
947 // Rotate the transition
948 transition=CTileSet::rotateTransition (transition);
950 if (!rotate)
951 break;
953 if (!ok)
954 break;
957 else
959 // Current transition
960 CTileSet::TTransition transition=(CTileSet::TTransition)i;
962 // Transition to patch
963 CTileSetTransition* trans=tileBank2.getTileSet (land)->getTransition (transition);
964 if (tileBank2.getTile (trans->getTile())->getRelativeFileName (m_ctrl.Texture==1?CTile::diffuse:CTile::additive).empty())
966 // Try to load a tile with a file name like /tiletransition0.tga
967 std::string sFinal = path + toString("%s%02d.%s", filename.c_str(), (int)transition, ext.c_str());
969 FILE *pFile = nlfopen (sFinal, "rb");
971 // Close the file and add the tile if opened
972 if (pFile)
974 fclose (pFile);
975 if (!m_ctrl.InfoList.setTileTransition (i, sFinal, m_ctrl.Texture==1?CTile::diffuse:CTile::additive))
976 break;
981 m_ctrl.Invalidate ();
986 void Browse::UpdateFlags ()
988 SubGroup0=0;
989 SubGroup1=0;
990 SubGroup2=0;
991 SubGroup3=0;
992 SubGroup4=0;
993 SubGroup5=0;
994 SubGroup6=0;
995 SubGroup7=0;
996 SubGroup8=0;
997 SubGroup9=0;
998 SubGroup10=0;
999 SubGroup11=0;
1001 // Flags
1002 uint or=0, and=0xffffffff;
1003 bool find=false;
1005 // For each
1006 for (int i=0;i<m_ctrl.InfoList.GetSize(m_128x128);i++)
1008 // Selected ?
1009 if (m_ctrl.InfoList.theList[m_128x128][i].Selected)
1011 // Tile index
1012 sint index;
1014 // get flags
1015 switch (m_128x128)
1017 case 0:
1018 // Tile index
1019 index=tileBank2.getTileSet (land)->getTile128 (i);
1020 break;
1021 case 1:
1022 // Tile index
1023 index=tileBank2.getTileSet (land)->getTile256 (i);
1024 break;
1025 case 2:
1026 // Tile index
1027 index=tileBank2.getTileSet (land)->getTransition (i)->getTile ();
1028 break;
1029 case 3:
1030 // not found
1031 index=-1;
1032 break;
1033 default:
1034 nlassert (0); // no!
1037 // valid flags
1038 if (index!=-1)
1040 // Get flags
1041 or|=tileBank2.getTile (index)->getGroupFlags ();
1042 and&=tileBank2.getTile (index)->getGroupFlags ();
1044 // Find one
1045 find=true;
1050 // Valid ctrl
1051 GetDlgItem (IDC_SUBGROUP0)->EnableWindow (find?TRUE:FALSE);
1052 GetDlgItem (IDC_SUBGROUP1)->EnableWindow (find?TRUE:FALSE);
1053 GetDlgItem (IDC_SUBGROUP2)->EnableWindow (find?TRUE:FALSE);
1054 GetDlgItem (IDC_SUBGROUP3)->EnableWindow (find?TRUE:FALSE);
1055 GetDlgItem (IDC_SUBGROUP4)->EnableWindow (find?TRUE:FALSE);
1056 GetDlgItem (IDC_SUBGROUP5)->EnableWindow (find?TRUE:FALSE);
1057 GetDlgItem (IDC_SUBGROUP6)->EnableWindow (find?TRUE:FALSE);
1058 GetDlgItem (IDC_SUBGROUP7)->EnableWindow (find?TRUE:FALSE);
1059 GetDlgItem (IDC_SUBGROUP8)->EnableWindow (find?TRUE:FALSE);
1060 GetDlgItem (IDC_SUBGROUP9)->EnableWindow (find?TRUE:FALSE);
1061 GetDlgItem (IDC_SUBGROUP10)->EnableWindow (find?TRUE:FALSE);
1062 GetDlgItem (IDC_SUBGROUP11)->EnableWindow (find?TRUE:FALSE);
1064 // Find at least one tile ?
1065 if (find)
1067 // Set UI
1068 SubGroup0=(and&0x1)?1:(or&0x1)?2:0;
1069 SubGroup1=(and&0x2)?1:(or&0x2)?2:0;
1070 SubGroup2=(and&0x4)?1:(or&0x4)?2:0;
1071 SubGroup3=(and&0x8)?1:(or&0x8)?2:0;
1072 SubGroup4=(and&0x10)?1:(or&0x10)?2:0;
1073 SubGroup5=(and&0x20)?1:(or&0x20)?2:0;
1074 SubGroup6=(and&0x40)?1:(or&0x40)?2:0;
1075 SubGroup7=(and&0x80)?1:(or&0x80)?2:0;
1076 SubGroup8=(and&0x100)?1:(or&0x100)?2:0;
1077 SubGroup9=(and&0x200)?1:(or&0x200)?2:0;
1078 SubGroup10=(and&0x400)?1:(or&0x400)?2:0;
1079 SubGroup11=(and&0x800)?1:(or&0x800)?2:0;
1082 // Update UI data
1083 UpdateData (FALSE);
1086 void Browse::Flags (int flagNumber, bool go)
1088 // For each
1089 for (int i=0;i<m_ctrl.InfoList.GetSize(m_128x128);i++)
1091 // Selected ?
1092 if (m_ctrl.InfoList.theList[m_128x128][i].Selected)
1094 // Tile index
1095 sint index;
1097 // get flags
1098 switch (m_128x128)
1100 case 0:
1101 // Tile index
1102 index=tileBank2.getTileSet (land)->getTile128 (i);
1103 break;
1104 case 1:
1105 // Tile index
1106 index=tileBank2.getTileSet (land)->getTile256 (i);
1107 break;
1108 case 2:
1109 // Tile index
1110 index=tileBank2.getTileSet (land)->getTransition (i)->getTile ();
1111 break;
1112 default:
1113 nlassert (0); // no!
1116 // valid flags
1117 if (index!=-1)
1119 // Get flags
1120 uint value=tileBank2.getTile (index)->getGroupFlags ();
1122 // Clear flag
1123 value&=~(1<<flagNumber);
1125 // Set the flag
1126 if (go)
1127 value|=(1<<flagNumber);
1129 // Setup
1130 tileBank2.getTile (index)->setGroupFlags (value);
1137 void Browse::OnSubgroup0()
1139 // TODO: Add your control notification handler code here
1141 // Check if clicked
1142 UpdateData ();
1143 if (SubGroup0==2)
1145 SubGroup0=0;
1146 UpdateData (FALSE);
1149 nlassert (SubGroup0!=2);
1150 if (SubGroup0==0)
1151 Flags (0, false);
1152 if (SubGroup0==1)
1153 Flags (0, true);
1156 void Browse::OnSubgroup1()
1158 // TODO: Add your control notification handler code here
1160 // Check if clicked
1161 UpdateData ();
1162 if (SubGroup1==2)
1164 SubGroup1=0;
1165 UpdateData (FALSE);
1168 nlassert (SubGroup1!=2);
1169 if (SubGroup1==0)
1170 Flags (1, false);
1171 if (SubGroup1==1)
1172 Flags (1, true);
1175 void Browse::OnSubgroup2()
1177 // TODO: Add your control notification handler code here
1179 // Check if clicked
1180 UpdateData ();
1181 if (SubGroup2==2)
1183 SubGroup2=0;
1184 UpdateData (FALSE);
1187 nlassert (SubGroup2!=2);
1188 if (SubGroup2==0)
1189 Flags (2, false);
1190 if (SubGroup2==1)
1191 Flags (2, true);
1194 void Browse::OnSubgroup3()
1196 // TODO: Add your control notification handler code here
1198 // Check if clicked
1199 UpdateData ();
1200 if (SubGroup3==2)
1202 SubGroup3=0;
1203 UpdateData (FALSE);
1206 nlassert (SubGroup3!=2);
1207 if (SubGroup3==0)
1208 Flags (3, false);
1209 if (SubGroup3==1)
1210 Flags (3, true);
1213 void Browse::OnSubgroup4()
1215 // TODO: Add your control notification handler code here
1217 // Check if clicked
1218 UpdateData ();
1219 if (SubGroup4==2)
1221 SubGroup4=0;
1222 UpdateData (FALSE);
1225 nlassert (SubGroup4!=2);
1226 if (SubGroup4==0)
1227 Flags (4, false);
1228 if (SubGroup4==1)
1229 Flags (4, true);
1232 void Browse::OnSubgroup5()
1234 // TODO: Add your control notification handler code here
1236 // Check if clicked
1237 UpdateData ();
1238 if (SubGroup5==2)
1240 SubGroup5=0;
1241 UpdateData (FALSE);
1244 nlassert (SubGroup5!=2);
1245 if (SubGroup5==0)
1246 Flags (5, false);
1247 if (SubGroup5==1)
1248 Flags (5, true);
1251 void Browse::OnSubgroup6()
1253 // TODO: Add your control notification handler code here
1255 // Check if clicked
1256 UpdateData ();
1257 if (SubGroup6==2)
1259 SubGroup6=0;
1260 UpdateData (FALSE);
1263 nlassert (SubGroup6!=2);
1264 if (SubGroup6==0)
1265 Flags (6, false);
1266 if (SubGroup6==1)
1267 Flags (6, true);
1270 void Browse::OnSubgroup7()
1272 // TODO: Add your control notification handler code here
1274 // Check if clicked
1275 UpdateData ();
1276 if (SubGroup7==2)
1278 SubGroup7=0;
1279 UpdateData (FALSE);
1282 nlassert (SubGroup7!=2);
1283 if (SubGroup7==0)
1284 Flags (7, false);
1285 if (SubGroup7==1)
1286 Flags (7, true);
1289 void Browse::OnSubgroup8()
1291 // TODO: Add your control notification handler code here
1293 // Check if clicked
1294 UpdateData ();
1295 if (SubGroup8==2)
1297 SubGroup8=0;
1298 UpdateData (FALSE);
1301 nlassert (SubGroup8!=2);
1302 if (SubGroup8==0)
1303 Flags (8, false);
1304 if (SubGroup8==1)
1305 Flags (8, true);
1308 void Browse::OnSubgroup9()
1310 // TODO: Add your control notification handler code here
1312 // Check if clicked
1313 UpdateData ();
1314 if (SubGroup9==2)
1316 SubGroup9=0;
1317 UpdateData (FALSE);
1320 nlassert (SubGroup9!=2);
1321 if (SubGroup9==0)
1322 Flags (9, false);
1323 if (SubGroup9==1)
1324 Flags (9, true);
1327 void Browse::OnSubgroup10()
1329 // TODO: Add your control notification handler code here
1331 // Check if clicked
1332 UpdateData ();
1333 if (SubGroup10==2)
1335 SubGroup10=0;
1336 UpdateData (FALSE);
1339 nlassert (SubGroup10!=2);
1340 if (SubGroup10==0)
1341 Flags (10, false);
1342 if (SubGroup10==1)
1343 Flags (10, true);
1346 void Browse::OnSubgroup11()
1348 // TODO: Add your control notification handler code here
1350 // Check if clicked
1351 UpdateData ();
1352 if (SubGroup11==2)
1354 SubGroup11=0;
1355 UpdateData (FALSE);
1358 nlassert (SubGroup11!=2);
1359 if (SubGroup11==0)
1360 Flags (11, false);
1361 if (SubGroup11==1)
1362 Flags (11, true);
1365 void Browse::OnExportBorder()
1367 // Select a file
1368 CFileDialog sFile (false, NULL, NULL, OFN_ENABLESIZING, _T("PNG Bitmap (*.png)|*.png|Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||"), NULL);
1369 if (sFile.DoModal()==IDOK)
1371 // Get the border of the bank
1372 std::vector<NLMISC::CBGRA> array;
1374 // 256 or 128 ?
1375 int width, height;
1376 tileBank2.getTileSet (land)->getBorder128 (m_ctrl.Texture==1?CTile::diffuse:CTile::additive)->get (width, height, array);
1378 // Make a bitmap
1379 if (width&&height)
1381 NLMISC::CBitmap bitmap;
1382 bitmap.resize (width, height, NLMISC::CBitmap::RGBA);
1384 // Get pixel
1385 CRGBA *pPixel=(CRGBA*)&bitmap.getPixels()[0];
1387 // Make a copy
1388 for (int i=0; i<width*height; i++)
1390 // Copy the pixel
1391 pPixel->R=array[i].R;
1392 pPixel->G=array[i].G;
1393 pPixel->B=array[i].B;
1394 pPixel->A=array[i].A;
1395 pPixel++;
1398 // Write the bitmap
1399 bool error=false;
1400 CString pathName=sFile.GetPathName();
1403 COFile file;
1404 if (file.open (tStrToUtf8(pathName)))
1406 // Export
1407 bitmap.writeTGA (file, 32);
1409 else
1410 error=true;
1412 catch (const Exception& e)
1414 const char *toto=e.what ();
1415 error=true;
1418 // Error during export ?
1419 if (error)
1421 // Error message
1422 std::string tmp = toString("Can't write bitmap %s", tStrToUtf8(pathName).c_str());
1423 MessageBox(nlUtf8ToTStr(tmp), _T("Export border"), MB_OK | MB_ICONEXCLAMATION);
1429 void Browse::OnImportBorder()
1431 // Select a file
1432 CFileDialog sFile (true, NULL, NULL, OFN_ENABLESIZING,_T("PNG Bitmap (*.png)|*.png|Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||"), NULL);
1433 if (sFile.DoModal()==IDOK)
1435 // Get the border of the bank
1436 std::vector<NLMISC::CBGRA> array(128*128);
1438 // The bitmap
1439 NLMISC::CBitmap bitmap;
1441 // Read the bitmap
1442 bool error=false;
1443 CString pathName=sFile.GetPathName();
1446 CIFile file;
1447 if (file.open (tStrToUtf8(pathName)))
1449 // Export
1450 bitmap.load (file);
1452 else
1453 error=true;
1455 catch (const Exception& e)
1457 const char *toto=e.what ();
1458 error=true;
1461 // Error during import ?
1462 if (error)
1464 // Error message
1465 std::string tmp = toString("Can't read bitmap %s", tStrToUtf8(pathName).c_str());
1466 MessageBox(nlUtf8ToTStr(tmp), _T("Import border"), MB_OK | MB_ICONEXCLAMATION);
1469 // Get pixel
1470 CRGBA *pPixel=(CRGBA*)&bitmap.getPixels()[0];
1472 // Good size
1473 if ((bitmap.getWidth()==128)&&(bitmap.getHeight()==128))
1475 // Make a copy
1476 for (int i=0; i<128*128; i++)
1478 // Copy the pixel
1479 array[i].R=pPixel->R;
1480 array[i].G=pPixel->G;
1481 array[i].B=pPixel->B;
1482 array[i].A=pPixel->A;
1483 pPixel++;
1486 else
1488 // Error message
1489 std::string tmp = toString("The bitmap must have a size of 128x128 (%s)", tStrToUtf8(pathName).c_str());
1490 MessageBox(nlUtf8ToTStr(tmp), _T("Import border"), MB_OK | MB_ICONEXCLAMATION);
1493 // 256 or 128 ?
1494 CTileBorder border;
1495 border.set (128, 128, array);
1496 tileBank2.getTileSet (land)->setBorder (m_ctrl.Texture==1?CTile::diffuse:CTile::additive, border);
1498 // Message
1499 MessageBox (_T("The border has been changed."), _T("Import border"), MB_OK|MB_ICONINFORMATION);