123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565 |
- /* Copyright (c) 2002-2012 Croteam Ltd.
- This program is free software; you can redistribute it and/or modify
- it under the terms of version 2 of the GNU General Public License as published by
- the Free Software Foundation
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
- // TerrainInterface.cpp : implementation file
- //
- #include "stdafx.h"
- #include "WorldEditor.h"
- #include "TerrainInterface.h"
- #include <Engine/Templates/Stock_CTextureData.h>
- #ifdef _DEBUG
- #undef new
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define RENDERED_BRUSH_SIZE_IN_METERS 32.0f
- #define CHANGE_ANGLE_SENSITIVITY (1.0f/1.0f)
- #define CHANGE_INDEX_SENSITIVITY (1.0f/16.0f)
- #define CHANGE_NORMALIZED_SENSITIVITY (1.0f/100.0f)
- #define CHANGE_PREASSURE_SENSITIVITY (1.0f)
- #define CHANGE_OFFSET_SENSITIVITY 0.1f
- #define CHANGE_STRETCH_SENSITIVITY 1.0f
- #define LAYER_START_X 48
- #define LAYER_HEIGHT 48
- #define LAYER_SPACING_V PIX(4)
- #define COL_ODD_LAYERS (RGBToColor(25,25,30)|CT_OPAQUE)
- #define COL_EVEN_LAYERS (RGBToColor(40,40,50)|CT_OPAQUE)
- COLOR _colSelectedLayerBcg=0x500000FF;
- #define COL_SELECTED_LAYER _colSelectedLayerBcg
- #define SLIDER_WIDTH 12
- #define SLIDER_HOLDER_HEIGHT 32
- #define COL_DEFAULT_ITEM (C_YELLOW|CT_OPAQUE)
- #define COL_SETTINGS (C_vlBLUE|CT_OPAQUE)
- #define COL_SEPARATOR (C_WHITE|CT_OPAQUE)
- static FLOAT _fScrollLayers=0;
- INDEX _iGenerateForLayer;
- Rect _rectInvalid;
- CUpdateableRT _udAutoGenerateDistribution;
- CChangeableRT _chAutoGenerateDistribution;
- CTerrain *_ptrLastEditedTerrain=NULL;
- CTerrainEditBrush atebDefaultEditBrushValues[]=
- {
- {0,1}, {0,2}, {0,4}, {0,6},
- {0,8}, {0,12}, {0,16}, {0,24},
- {0,32}, {0,40}, {0,52}, {0,63},
-
- {1,1}, {2,2}, {4,4}, {6,6},
- {8,8}, {12,12}, {16,16}, {24,24},
- {32,32}, {40,40}, {52,52}, {63,63},
-
- {2,4}, {3,6}, {4,8}, {6,12},
- {8,16}, {12,24}, {16,32}, {32,63},
- };
- CTerrainEditBrush atebCustomEditBrushes[CT_BRUSHES];
- static CTextureObject _toIcons;
- static CDynamicContainer<CTIButton> dcButtons;
- void GenerateTerrainBrushTexture( INDEX iBrush, FLOAT fHotSpot, FLOAT fFallOff);
- /////////////////////////////////////////////////////////////////////////////
- // CTerrainInterface
- static CTString _strToolTip;
- static void GetToolTipText(void *pTerrainInterface, char *pToolTipText)
- {
- pToolTipText+= sprintf(pToolTipText, "%s", _strToolTip);
- }
- CTFileName GetBrushTextureName(INDEX iBrush)
- {
- CTString strBrushFile;
- strBrushFile.PrintF("Textures\\Editor\\TerrainBrush%02d.tex", iBrush);
- return strBrushFile;
- }
- void CTerrainInterface::HideCursor(void)
- {
- RECT rect;
- GetClientRect( &rect);
- ClientToScreen( &rect);
- ClipCursor(&rect);
- while (ShowCursor(FALSE)>=0);
- }
- void CTerrainInterface::UnhideCursor(void)
- {
- ClipCursor(NULL);
- while (ShowCursor(TRUE)<0);
- }
- void GetButtonOffset(CTIButton &tib, PIX &pixOffsetX, PIX &pixOffsetY)
- {
- if(tib.tib_iLayer!=-1)
- {
- CTerrain *ptrTerrain=GetTerrain();
- if( ptrTerrain==NULL) return;
- pixOffsetX=LAYER_START_X;
- pixOffsetY=(ptrTerrain->tr_atlLayers.Count()-1-tib.tib_iLayer)*LAYER_HEIGHT-_fScrollLayers;
- }
- }
- #define TERRAIN_SURFACE_VER "V002"
- void LoadSurface(CTFileName fnSurface)
- {
- CTerrain *ptrTerrain=GetTerrain();
- if( ptrTerrain==NULL) return;
- try
- {
- CTFileStream strmFile;
- strmFile.Open_t( fnSurface);
- strmFile.ExpectID_t( CChunkID( "TRSF")); // terrain surface
- // check version number
- if( !( CChunkID(TERRAIN_SURFACE_VER) == strmFile.GetID_t()) )
- {
- throw( "Invalid version of terrain surface file. Unable to load");
- }
- INDEX ctLayers=ptrTerrain->tr_atlLayers.Count();
- for(INDEX iDelLayer=0; iDelLayer<ctLayers-1; iDelLayer++)
- {
- ptrTerrain->RemoveLayer(0, FALSE);
- }
- ptrTerrain->tr_atlLayers[0].ResetLayerMask(0xFF);
- ctLayers=0;
- strmFile>>ctLayers;
- for( INDEX iLayer=0; iLayer<ctLayers; iLayer++)
- {
- CTFileName fnTexture;
- strmFile>>fnTexture;
- // check if texture exists
- if(!FileExists( fnTexture))
- {
- fnTexture=CTFILENAME("Textures\\Editor\\Default.tex");
- }
- CTerrainLayer *ptlLayer=&ptrTerrain->tr_atlLayers[0];
- if( iLayer!=0)
- {
- ptlLayer=&ptrTerrain->AddLayer_t(fnTexture, LT_NORMAL, FALSE);
- }
- else
- {
- ptlLayer->SetLayerTexture_t(fnTexture);
- }
- // load surface
- strmFile>>ptlLayer->tl_fRotateX;
- strmFile>>ptlLayer->tl_fRotateY;
- strmFile>>ptlLayer->tl_fStretchX;
- strmFile>>ptlLayer->tl_fStretchY;
- strmFile>>ptlLayer->tl_fOffsetX;
- strmFile>>ptlLayer->tl_fOffsetY;
- strmFile>>ptlLayer->tl_bAutoRegenerated;
- strmFile>>ptlLayer->tl_fCoverage;
- strmFile>>ptlLayer->tl_fCoverageNoise;
- strmFile>>ptlLayer->tl_fCoverageRandom;
- strmFile>>ptlLayer->tl_bApplyMinAltitude;
- strmFile>>ptlLayer->tl_fMinAltitude;
- strmFile>>ptlLayer->tl_fMinAltitudeFade;
- strmFile>>ptlLayer->tl_fMinAltitudeNoise;
- strmFile>>ptlLayer->tl_fMinAltitudeRandom;
- strmFile>>ptlLayer->tl_bApplyMaxAltitude;
- strmFile>>ptlLayer->tl_fMaxAltitude;
- strmFile>>ptlLayer->tl_fMaxAltitudeFade;
- strmFile>>ptlLayer->tl_fMaxAltitudeNoise;
- strmFile>>ptlLayer->tl_fMaxAltitudeRandom;
- strmFile>>ptlLayer->tl_bApplyMinSlope;
- strmFile>>ptlLayer->tl_fMinSlope;
- strmFile>>ptlLayer->tl_fMinSlopeFade;
- strmFile>>ptlLayer->tl_fMinSlopeNoise;
- strmFile>>ptlLayer->tl_fMinSlopeRandom;
- strmFile>>ptlLayer->tl_bApplyMaxSlope;
- strmFile>>ptlLayer->tl_fMaxSlope;
- strmFile>>ptlLayer->tl_fMaxSlopeFade;
- strmFile>>ptlLayer->tl_fMaxSlopeNoise;
- strmFile>>ptlLayer->tl_fMaxSlopeRandom;
-
- strmFile>>ptlLayer->tl_colMultiply;
- }
- strmFile.Close();
- }
- catch( char *strError)
- {
- WarningMessage(strError);
- return;
- }
- GenerateLayerDistribution(-1);
- theApp.m_ctTerrainPage.MarkChanged();
- ptrTerrain->RefreshTerrain();
- }
- void SaveSurface(CTFileName fnSurface)
- {
- CTerrain *ptrTerrain=GetTerrain();
- if( ptrTerrain==NULL) return;
- try
- {
- CTFileStream strmFile;
- strmFile.Create_t( fnSurface);
- strmFile.WriteID_t( CChunkID( "TRSF")); // terrain surface
- // write version number
- strmFile.WriteID_t(TERRAIN_SURFACE_VER);
- INDEX ctLayers=ptrTerrain->tr_atlLayers.Count();
- strmFile<<ctLayers;
- for( INDEX iLayer=0; iLayer<ctLayers; iLayer++)
- {
- CTerrainLayer *ptlLayer=&ptrTerrain->tr_atlLayers[iLayer];
- if(ptlLayer->tl_ptdTexture==NULL) continue;
- CTFileName fnTexture=ptlLayer->tl_ptdTexture->GetName();
- strmFile<<fnTexture;
- // save surface
- strmFile<<ptlLayer->tl_fRotateX;
- strmFile<<ptlLayer->tl_fRotateY;
- strmFile<<ptlLayer->tl_fStretchX;
- strmFile<<ptlLayer->tl_fStretchY;
- strmFile<<ptlLayer->tl_fOffsetX;
- strmFile<<ptlLayer->tl_fOffsetY;
- strmFile<<ptlLayer->tl_bAutoRegenerated;
- strmFile<<ptlLayer->tl_fCoverage;
- strmFile<<ptlLayer->tl_fCoverageNoise;
- strmFile<<ptlLayer->tl_fCoverageRandom;
- strmFile<<ptlLayer->tl_bApplyMinAltitude;
- strmFile<<ptlLayer->tl_fMinAltitude;
- strmFile<<ptlLayer->tl_fMinAltitudeFade;
- strmFile<<ptlLayer->tl_fMinAltitudeNoise;
- strmFile<<ptlLayer->tl_fMinAltitudeRandom;
- strmFile<<ptlLayer->tl_bApplyMaxAltitude;
- strmFile<<ptlLayer->tl_fMaxAltitude;
- strmFile<<ptlLayer->tl_fMaxAltitudeFade;
- strmFile<<ptlLayer->tl_fMaxAltitudeNoise;
- strmFile<<ptlLayer->tl_fMaxAltitudeRandom;
- strmFile<<ptlLayer->tl_bApplyMinSlope;
- strmFile<<ptlLayer->tl_fMinSlope;
- strmFile<<ptlLayer->tl_fMinSlopeFade;
- strmFile<<ptlLayer->tl_fMinSlopeNoise;
- strmFile<<ptlLayer->tl_fMinSlopeRandom;
- strmFile<<ptlLayer->tl_bApplyMaxSlope;
- strmFile<<ptlLayer->tl_fMaxSlope;
- strmFile<<ptlLayer->tl_fMaxSlopeFade;
- strmFile<<ptlLayer->tl_fMaxSlopeNoise;
- strmFile<<ptlLayer->tl_fMaxSlopeRandom;
- strmFile<<ptlLayer->tl_colMultiply;
- }
- strmFile.Close();
- }
- catch( char *strError)
- {
- WarningMessage(strError);
- return;
- }
- }
- void PointToIconSpace(CPoint &pt, CTIButton *ptib)
- {
- PIX pixOffsetX=0;
- PIX pixOffsetY=0;
- GetButtonOffset(*ptib, pixOffsetX, pixOffsetY);
- PIX x=ptib->tib_fx+pixOffsetX;
- PIX y=ptib->tib_fy+pixOffsetY;
- pt.x=Clamp(pt.x-x, INDEX(0), INDEX(ptib->tib_fdx));
- pt.y=Clamp(pt.y-y, INDEX(0), INDEX(ptib->tib_fdy));
- }
- void PointToScreenSpace(CPoint &pt, CDrawPort *pdp)
- {
- HWND hWnd=pdp->dp_Raster->ra_pvpViewPort->vp_hWnd;
- ClientToScreen(hWnd, &pt);
- }
- PIXaabbox2D GetButtonScreenBox(CTIButton &tib)
- {
- PIX pixOffsetX=0;
- PIX pixOffsetY=0;
- GetButtonOffset(tib, pixOffsetX, pixOffsetY);
- PIX x=tib.tib_fx+pixOffsetX;
- PIX y=tib.tib_fy+pixOffsetY;
- PIX dx=tib.tib_fdx;
- PIX dy=tib.tib_fdy;
- PIXaabbox2D boxScreen=PIXaabbox2D( PIX2D(x,y), PIX2D(x+dx, y+dy));
- return boxScreen;
- }
- void GenerateDefaultBrush(INDEX iBrush)
- {
- atebCustomEditBrushes[iBrush].teb_fHotSpot=atebDefaultEditBrushValues[iBrush].teb_fHotSpot;
- atebCustomEditBrushes[iBrush].teb_fFallOff=atebDefaultEditBrushValues[iBrush].teb_fFallOff;
- GenerateTerrainBrushTexture( iBrush,
- atebCustomEditBrushes[iBrush].teb_fHotSpot-0.1f, atebCustomEditBrushes[iBrush].teb_fFallOff-0.1f);
- }
- void SetDefaultEditBrushes(void)
- {
- for(INDEX iBrush=0; iBrush<CT_BRUSHES; iBrush++)
- {
- GenerateDefaultBrush(iBrush);
- }
- }
- void GenerateNonExistingTerrainEditBrushes(void)
- {
- for(INDEX iBrush=0; iBrush<CT_BRUSHES; iBrush++)
- {
- // copy default values as custom ones
- atebCustomEditBrushes[iBrush].teb_fHotSpot=atebDefaultEditBrushValues[iBrush].teb_fHotSpot;
- atebCustomEditBrushes[iBrush].teb_fFallOff=atebDefaultEditBrushValues[iBrush].teb_fFallOff;
- CTFileName fnBrush=GetBrushTextureName(iBrush);
- if(!FileExists(fnBrush))
- {
- GenerateDefaultBrush(iBrush);
- }
- else
- {
- // precache existing brushes
- try
- {
- _pTextureStock->Obtain_t(fnBrush);
- }
- catch(char *strError)
- {
- (void) strError;
- }
- }
- }
- }
- CTerrainInterface::CTerrainInterface()
- {
- m_pDrawPort = NULL;
- m_pViewPort = NULL;
- _fScrollLayers=0;
- _udAutoGenerateDistribution.MarkUpdated();
- }
- CTerrainInterface::~CTerrainInterface()
- {
- }
- BEGIN_MESSAGE_MAP(CTerrainInterface, CWnd)
- //{{AFX_MSG_MAP(CTerrainInterface)
- ON_WM_PAINT()
- ON_WM_DESTROY()
- ON_WM_LBUTTONDOWN()
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONUP()
- ON_WM_RBUTTONDOWN()
- ON_WM_RBUTTONUP()
- ON_WM_LBUTTONDBLCLK()
- ON_WM_DROPFILES()
- ON_WM_CREATE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CTerrainInterface message handlers
- void CTerrainInterface::OnPaint()
- {
- #if ALLOW_TERRAINS
- {
- CPaintDC dc(this);
- }
- if( (m_pViewPort == NULL) && (m_pDrawPort == NULL) )
- {
- // initialize canvas for active texture button
- _pGfx->CreateWindowCanvas( m_hWnd, &m_pViewPort, &m_pDrawPort);
- }
- // if there is a valid drawport, and the drawport can be locked
- if( (m_pDrawPort != NULL) && (m_pDrawPort->Lock()) )
- {
- if(dcButtons.Count()==0 || GetTerrain()!=_ptrLastEditedTerrain)
- {
- InitializeInterface(m_pDrawPort);
- _ptrLastEditedTerrain=GetTerrain();
- }
- PIXaabbox2D rectPict;
- rectPict = PIXaabbox2D( PIX2D(0, 0),
- PIX2D(m_pDrawPort->GetWidth(), m_pDrawPort->GetHeight()));
- // clear texture area to black
- m_pDrawPort->Fill( C_BLACK | CT_OPAQUE);
- // erase z-buffer
- m_pDrawPort->FillZBuffer(ZBUF_BACK);
- RenderInterface(m_pDrawPort);
-
- // unlock the drawport
- m_pDrawPort->Unlock();
- if (m_pViewPort!=NULL)
- {
- m_pViewPort->SwapBuffers();
- }
- }
- #endif
- }
- void CTerrainInterface::RenderInterface(CDrawPort *pdp)
- {
- #if ALLOW_TERRAINS
- // render terrain interface buttons
- FOREACHINDYNAMICCONTAINER( dcButtons, CTIButton, ittib)
- {
- CTIButton &tib=*ittib;
- PIX pixOffsetX=0;
- PIX pixOffsetY=0;
- GetButtonOffset(tib, pixOffsetX, pixOffsetY);
- if( tib.tib_pPreRender!=NULL) tib.tib_pPreRender(&tib, pdp);
- PIX x=tib.tib_fx+pixOffsetX;
- PIX y=tib.tib_fy+pixOffsetY;
- PIX dx=tib.tib_fdx;
- PIX dy=tib.tib_fdy;
- // bcg icon fill
- if( tib.tib_colFill&0xFF)
- {
- if(pdp->Lock())
- {
- pdp->Fill(x,y,dx,dy, tib.tib_colFill);
- pdp->Unlock();
- }
- }
-
- // icon texture
- if( tib.tib_iIcon!=-1)
- {
- PIXaabbox2D boxScreen=PIXaabbox2D( PIX2D(x,y), PIX2D(x+dx, y+dy));
- MEXaabbox2D boxTexture=MEXaabbox2D( MEX2D(16*tib.tib_iIcon,0), MEX2D(16*tib.tib_iIcon+16,16));
- COLOR colMultiply=C_WHITE|CT_OPAQUE;
- if(tib.tib_pIsEnabled!=NULL && !tib.tib_pIsEnabled(&tib))
- {
- colMultiply=C_dGRAY|CT_OPAQUE;
- }
- pdp->PutTexture( &_toIcons, boxScreen, boxTexture, colMultiply);
- }
-
- // custom render
- if(tib.tib_pOnRender!=NULL) tib.tib_pOnRender(&tib, pdp);
-
- // icon border
- if( tib.tib_colBorderColor&0xFF)
- {
- if(pdp->Lock())
- {
- pdp->DrawBorder(x,y,dx,dy, tib.tib_colBorderColor);
- pdp->Unlock();
- }
- }
- }
- #endif
- }
- PIXaabbox2D GetLayersBox(CDrawPort *pdp)
- {
- return PIXaabbox2D( PIX2D(LAYER_START_X,0), PIX2D(pdp->GetWidth()-LAYER_START_X, pdp->GetHeight()));
- }
- PIX2D GetLayerSize(CDrawPort *pdp)
- {
- return PIX2D(pdp->GetWidth()-LAYER_START_X, LAYER_HEIGHT);
- }
- void CTerrainInterface::OnDestroy()
- {
- CWnd::OnDestroy();
- if( m_pViewPort != NULL)
- {
- _pGfx->DestroyWindowCanvas( m_pViewPort);
- m_pViewPort = NULL;
- }
- m_pViewPort = NULL;
- m_pDrawPort = NULL;
- }
- void GenerateTerrainBrushTexture( INDEX iBrush, FLOAT fHotSpot, FLOAT fFallOff)
- {
- #if ALLOW_TERRAINS
- INDEX iLog2=INDEX(ceil(Log2(fFallOff*2+2)));
- PIX pixSize=1UL<<(iLog2+1);
- FLOAT fcx=pixSize/2.0f;
- FLOAT fcy=pixSize/2.0f;
- CImageInfo ii;
- ii.ii_Width=pixSize;
- ii.ii_Height=pixSize;
- ii.ii_BitsPerPixel=32;
- ii.ii_Picture=(UBYTE*) AllocMemory(ii.ii_Width*ii.ii_Height*ii.ii_BitsPerPixel/8);
- COLOR *pcol=(COLOR *)ii.ii_Picture;
- for(INDEX iy=0; iy<ii.ii_Height; iy++)
- {
- for(INDEX ix=0; ix<ii.ii_Width; ix++)
- {
- FLOAT fDist=sqrt((fcx-ix)*(fcx-ix)+(fcy-iy)*(fcy-iy));
- FLOAT fcolPower=1.0f;
- if(fDist>fFallOff) fcolPower=0.0f;
- else if(fDist>fHotSpot)
- {
- fcolPower=CalculateRatio(fDist, fHotSpot, fFallOff, 0.0f, 1.0f);
- fcolPower=1.0f-(1.0f-fcolPower)*(1.0f-fcolPower);
- }
- UBYTE ubCol=fcolPower*255.0f;
- COLOR col=RGBToColor(ubCol,ubCol,ubCol)|CT_OPAQUE;
- *pcol=ByteSwap(col);
- pcol++;
- }
- }
- CTextureData tdBrush;
- try
- {
- tdBrush.Create_t( &ii, pixSize, 16, TRUE);
- CTString strBrushFile;
- strBrushFile.PrintF("Textures\\Editor\\TerrainBrush%02d.tex", iBrush);
- tdBrush.Save_t( strBrushFile);
- tdBrush.Reload();
- }
- catch( char *strError)
- {
- (void) strError;
- WarningMessage("Unable to create terrain brush texture!");
- }
- #endif
- }
- CTIButton::CTIButton()
- {
- tib_fx=0.0f;
- tib_fy=0.0f;
- tib_fdx=0.0f;
- tib_fdy=0.0f;
- tib_iIcon=-1;
- tib_colBorderColor=0;
- tib_fDataMin=0.0f;
- tib_fDataMax=0.0f;
- tib_bWrapData=TRUE;
- tib_fDataDelta=0.0f;
- tib_pfData1=NULL;
- tib_pfData2=NULL;
- tib_iLayer=-1;
- tib_strToolTip="Unknown tool tip";
- tib_pPreRender=NULL;
- tib_pOnRender=NULL;
- tib_pOnLeftClick=NULL;
- tib_pOnLeftClickMove=NULL;
- tib_pOnRightClick=NULL;
- tib_pOnRightClickMove=NULL;
- tib_pOnDropFiles=NULL;
- tib_pGetClickMoveData=NULL;
- tib_pIsEnabled=NULL;
-
- tib_bMouseTrapForMove=TRUE;
- tib_bContinueTesting=FALSE;
- }
- CTIButton *AddButton(CDynamicContainer<CTIButton> &dc, FLOAT x, FLOAT y, FLOAT dx, FLOAT dy, INDEX iLayer, INDEX iIcon,
- CTString strToolTip, COLOR colBorder=C_RED|CT_TRANSPARENT, COLOR colFill=C_BLACK|CT_TRANSPARENT)
- {
- CTIButton &tib=*(new CTIButton);
- tib.tib_fx=x;
- tib.tib_fy=y;
- tib.tib_fdx=dx;
- tib.tib_fdy=dy;
- tib.tib_iLayer=iLayer;
- tib.tib_iIcon=iIcon;
- tib.tib_strToolTip=strToolTip;
- tib.tib_colBorderColor=colBorder;
- tib.tib_colFill=colFill;
- dc.Add(&tib);
- return &tib;
- }
- void CTIButton::SetData( FLOAT fDataMin, FLOAT fDataMax, FLOAT fDataDelta, BOOL bWrap/*=FALSE*/, FLOAT *pfData1/*=NULL*/, FLOAT *pfData2/*=NULL*/)
- {
- tib_fDataMin=fDataMin;
- tib_fDataMax=fDataMax;
- tib_fDataDelta=fDataDelta;
- tib_bWrapData=bWrap;
- tib_pfData1=pfData1;
- tib_pfData2=pfData2;
- }
- void CTIButton::SetFunctions(
- void (*pOnRender)(CTIButton *ptib, CDrawPort *pdp)/*=NULL*/,
- void (*pOnLeftClick)(CTIButton *ptib, CPoint pt, CDrawPort *pdp)/*=NULL*/,
- void (*pOnLeftClickMove)(CTIButton *ptib, FLOAT fdx, FLOAT fdy, CDrawPort *pdp)/*=NULL*/,
- void (*pOnRightClick)(CTIButton *ptib, CPoint pt, CDrawPort *pdp)/*=NULL*/,
- void (*pOnRightClickMove)(CTIButton *ptib, FLOAT fdx, FLOAT fdy, CDrawPort *pdp)/*=NULL*/,
- void (*pPreRender)(CTIButton *ptib, CDrawPort *pdp)/*=NULL*/)
- {
- tib_pOnRender=pOnRender;
- tib_pOnLeftClick=pOnLeftClick;
- tib_pOnLeftClickMove=pOnLeftClickMove;
- tib_pOnRightClick=pOnRightClick;
- tib_pOnRightClickMove=pOnRightClickMove;
- tib_pPreRender=pPreRender;
- }
- void RenderBrushNo(CTIButton *ptib, CDrawPort *pdp)
- {
- pdp->SetFont( _pfdConsoleFont);
- pdp->SetTextAspect( 1.0f);
- pdp->SetTextScaling( 1.0f);
- CTString strText;
- strText.PrintF("%d", INDEX(theApp.m_fCurrentTerrainBrush));
- pdp->PutTextC( strText, ptib->tib_fx+ptib->tib_fdx/2, ptib->tib_fy+4, C_YELLOW|CT_OPAQUE);
- }
- void RenderBrushShape( INDEX iBrush, PIXaabbox2D rect, CDrawPort *pdp)
- {
- CDrawPort dpBrush=CDrawPort(pdp, rect);
- CTextureObject to;
- CTString strBrushFile;
- strBrushFile.PrintF("Textures\\Editor\\TerrainBrush%02d.tex", iBrush);
- try
- {
- to.SetData_t(strBrushFile);
- CTextureData *ptd=(CTextureData *)to.GetData();
- if( dpBrush.Lock())
- {
- dpBrush.Fill(C_BLACK|CT_OPAQUE);
- PIX pixTexW=ptd->GetPixWidth();
- PIX pixTexH=ptd->GetPixHeight();
- FLOAT fScreenW=dpBrush.GetWidth()*pixTexW/RENDERED_BRUSH_SIZE_IN_METERS;
- FLOAT fScreenH=dpBrush.GetHeight()*pixTexH/RENDERED_BRUSH_SIZE_IN_METERS;
- PIXaabbox2D rectPic;
- rectPic = PIXaabbox2D(
- PIX2D(dpBrush.GetWidth()/2.0f-fScreenW/2.0f, dpBrush.GetHeight()/2.0f-fScreenH/2.0f),
- PIX2D(dpBrush.GetWidth()/2.0f-fScreenW/2.0f+fScreenW, dpBrush.GetHeight()/2.0f-fScreenH/2.0f+fScreenH));
- dpBrush.PutTexture( &to, rectPic);
- dpBrush.Unlock();
- }
- }
- catch( char *strError)
- {
- (void) strError;
- }
- }
- void RenderBrushShape(CTIButton *ptib, CDrawPort *pdp)
- {
- INDEX iBrush=INDEX(theApp.m_fCurrentTerrainBrush);
- CTerrainEditBrush &teb=atebCustomEditBrushes[iBrush];
- PIXaabbox2D rectButton = PIXaabbox2D(
- PIX2D(ptib->tib_fx, ptib->tib_fy),
- PIX2D(ptib->tib_fx+ptib->tib_fdx, ptib->tib_fy+ptib->tib_fdy));
- RenderBrushShape(iBrush,rectButton,pdp);
- }
- void RenderBrushPressure(CTIButton *ptib, CDrawPort *pdp)
- {
- pdp->SetFont( _pfdConsoleFont);
- pdp->SetTextAspect( 1.0f);
- pdp->SetTextScaling( 1.0f);
- CTString strText;
- strText.PrintF("%d%%", INDEX(theApp.m_fTerrainBrushPressure/1024.0f*100.0f));
- pdp->PutTextC( strText, ptib->tib_fx+ptib->tib_fdx/2, ptib->tib_fy, C_YELLOW|CT_OPAQUE);
- }
- void RenderLayerTexture(CTIButton *ptib, CDrawPort *pdp)
- {
- INDEX iLayer=ptib->tib_iLayer;
- CTerrainLayer *ptlLayer=GetLayer(iLayer);
- if(ptlLayer!=NULL && ptlLayer->tl_ptdTexture!=NULL)
- {
- CTextureObject to;
- to.SetData(ptlLayer->tl_ptdTexture);
- PIXaabbox2D boxScreen=GetButtonScreenBox(*ptib);
- pdp->PutTexture( &to, boxScreen);
- }
- }
- void RenderLayerBcg(CTIButton *ptib, CDrawPort *pdp)
- {
- INDEX iLayer=ptib->tib_iLayer;
-
- CTIButton &tib=*ptib;
- PIX pixOffsetX=0;
- PIX pixOffsetY=0;
- GetButtonOffset(tib, pixOffsetX, pixOffsetY);
- if( tib.tib_pPreRender!=NULL) tib.tib_pPreRender(&tib, pdp);
- PIX x=tib.tib_fx+pixOffsetX;
- PIX y=tib.tib_fy+pixOffsetY;
- PIX dx=tib.tib_fdx;
- PIX dy=tib.tib_fdy;
- COLOR colBcg=C_WHITE|CT_OPAQUE;
- if( tib.tib_iLayer==GetLayerIndex()) colBcg=COL_SELECTED_LAYER;
- else if( iLayer&1) colBcg=COL_ODD_LAYERS;
- else colBcg=COL_EVEN_LAYERS;
- if(pdp->Lock())
- {
- pdp->Fill(x,y,dx,dy, colBcg);
- pdp->Unlock();
- }
- }
- void RenderLayerMask(CTIButton *ptib, CDrawPort *pdp)
- {
- INDEX iLayer=ptib->tib_iLayer;
- CTerrainLayer *ptlLayer=GetLayer(iLayer);
- if(ptlLayer!=NULL && ptlLayer->tl_ptdTexture!=NULL)
- {
- CTextureObject to;
- CTextureData *ptd=ptlLayer->GetThumbnail(64,64);
- to.SetData(ptd);
- PIXaabbox2D boxScreen=GetButtonScreenBox(*ptib);
- pdp->PutTexture( &to, boxScreen);
- }
- }
- void GetBrushModeInfo(INDEX iMode, INDEX &iIcon, CTString &strText)
- {
- strText="Unknown";
- iIcon=0;
- switch(INDEX (iMode))
- {
- case TBM_PAINT:
- {
- strText="Paint (J)";
- if(INDEX(theApp.m_iTerrainEditMode)==TEM_HEIGHTMAP) iIcon=12;
- else iIcon=8;
- break;
- }
- case TBM_SMOOTH: strText="Smooth tool (O)"; iIcon=10; break;
- case TBM_FILTER: strText="Filter tool (F)"; iIcon=30; break;
- case TBM_MINIMUM: strText="Limit down (M)"; iIcon=27; break;
- case TBM_MAXIMUM: strText="Limit up (X)"; iIcon=11; break;
- case TBM_FLATTEN: strText="Flatten (=)"; iIcon=18; break;
- case TBM_POSTERIZE: strText="Posterize (;)"; iIcon=28; break;
- case TBM_RND_NOISE: strText="Random noise (K)"; iIcon=21; break;
- case TBM_CONTINOUS_NOISE: strText="Texture noise (Y)"; iIcon=31; break;
- case TBM_ERASE: strText="Erase (D)"; iIcon=9; break;
- }
- }
- void UpdateEditModeIcon(CTIButton *ptib, CDrawPort *pdp)
- {
- if(INDEX(theApp.m_iTerrainEditMode)==TEM_HEIGHTMAP) ptib->tib_iIcon=20;
- else ptib->tib_iIcon=19;
- }
- void UpdateBrushModeIcon(CTIButton *ptib, CDrawPort *pdp)
- {
- INDEX iIcon;
- CTString strText;
- GetBrushModeInfo(INDEX(theApp.m_iTerrainBrushMode), iIcon, strText);
- ptib->tib_iIcon=iIcon;
- }
- void UpdateLayerVisibleFlag(CTIButton *ptib, CDrawPort *pdp)
- {
- INDEX iLayer=ptib->tib_iLayer;
- CTerrainLayer *ptlLayer=GetLayer(iLayer);
- if(ptlLayer!=NULL)
- {
- if( ptlLayer->tl_bVisible) ptib->tib_iIcon=3;
- else ptib->tib_iIcon=4;
- }
- }
- void UpdatePressure(CTIButton *ptib, CDrawPort *pdp)
- {
- if(theApp.m_fTerrainBrushPressureEnum>=0)
- {
- theApp.m_fTerrainBrushPressure=(theApp.m_fTerrainBrushPressureEnum+1)/10.0f*1024.0f+1;
- theApp.m_fTerrainBrushPressureEnum=-1;
- }
- }
- void SetAsActiveLayer(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- SelectLayer(ptib->tib_iLayer);
- CWorldEditorDoc* pDoc = theApp.GetActiveDocument();
- if(pDoc!=NULL)
- {
- pDoc->m_chSelections.MarkChanged();
- }
- }
- void ApplyLayerCommand(INDEX iSelectedItem)
- {
- CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
- CTerrain *ptrTerrain=GetTerrain();
- if( ptrTerrain==NULL) return;
- CTerrainLayer *ptlLayer=GetLayer();
- INDEX iLayer=GetLayerIndex();
- if(ptlLayer!=NULL)
- {
- switch( iSelectedItem)
- {
- case 0: // "Delete layer"
- {
- if(ptrTerrain->tr_atlLayers.Count()>1)
- {
- if( ::MessageBoxA( pMainFrame->m_hWnd, "Are you sure that you want to delete this layer?",
- "Warning !", MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON1| MB_SYSTEMMODAL | MB_TOPMOST) == IDYES)
- {
- ptrTerrain->RemoveLayer(iLayer);
- if(GetLayerIndex()>=ptrTerrain->tr_atlLayers.Count())
- {
- SelectLayer(ptrTerrain->tr_atlLayers.Count()-1);
- }
- }
- }
- break;
- }
- case 1: // "Insert texture layer"
- {
- try
- {
- ptrTerrain->AddLayer_t( CTFILENAME("Textures\\Editor\\Default.tex"));
- SelectLayer( ptrTerrain->tr_atlLayers.Count()-1);
- }
- catch(char *strError)
- {
- WarningMessage("Unable to obtain default texture for new texture layer!\nError: %s", strError);
- }
- break;
- }
- case 4: // "Insert tile layer"
- {
- try
- {
- ptrTerrain->AddLayer_t( CTFILENAME("Textures\\Editor\\Default.tex"), LT_TILE);
- SelectLayer( ptrTerrain->tr_atlLayers.Count()-1);
- }
- catch(char *strError)
- {
- WarningMessage("Unable to obtain default texture for new tile layer!\nError: %s", strError);
- }
- break;
- }
- case 2: // "Move up"
- {
- if(iLayer<ptrTerrain->tr_atlLayers.Count()-1)
- {
- ptrTerrain->SetLayerIndex( iLayer, iLayer+1);
- SelectLayer(iLayer+1);
- }
- break;
- }
- case 3: // "Move down"
- {
- if(iLayer>0)
- {
- ptrTerrain->SetLayerIndex( iLayer, iLayer-1);
- SelectLayer(iLayer-1);
- }
- break;
- }
- }
- }
- theApp.m_ctTerrainPage.MarkChanged();
- }
- void DisplayLayerTexture(INDEX iLayer)
- {
- CWndDisplayTexture *pDisplay=new CWndDisplayTexture;
- CTerrainLayer *ptlLayer=GetLayer(iLayer);
- if(ptlLayer!=NULL && ptlLayer->tl_ptdTexture!=NULL)
- {
- POINT pt;
- GetCursorPos(&pt);
- CTString strText1=ptlLayer->tl_ptdTexture->GetName();
- CTString strText2=ptlLayer->tl_ptdTexture->GetDescription();
- pDisplay->Initialize(pt.x, pt.y, ptlLayer->tl_ptdTexture, strText1, strText2);
- }
- }
- void ApplyLayerTextureCommand(INDEX iSelectedItem)
- {
- CTerrain *ptrTerrain=GetTerrain();
- if( ptrTerrain==NULL) return;
- CTerrainLayer *ptlLayer=GetLayer();
- INDEX iLayer=GetLayerIndex();
- if(ptlLayer!=NULL)
- {
- switch( iSelectedItem)
- {
- case 0: // "Create izohipse textutre"
- {
- CTFileName fnGradient=_EngineGUI.FileRequester(
- "Select izohipse gradient", FILTER_TEX FILTER_ALL FILTER_END,
- "Texture directory", "Textures\\");
- if( fnGradient=="") return;
- CTextureData *ptdGradient;
- try
- {
- ptdGradient=_pTextureStock->Obtain_t( fnGradient);
- ptdGradient->Force(TEX_STATIC|TEX_CONSTANT);
- }
- catch( char *strError)
- {
- (void) strError;
- WarningMessage("Unable to obtain izohipse gradient texture!");
- return;
- }
- CTFileName fnIzohipseTexture=_EngineGUI.FileRequester(
- "Choose name for izohipse texture", FILTER_TEX FILTER_ALL FILTER_END,
- "Texture directory", "Textures\\");
- if( fnIzohipseTexture=="") return;
- INDEX iHMWidth=ptrTerrain->tr_pixHeightMapWidth;
- INDEX iHMHeight=ptrTerrain->tr_pixHeightMapHeight;
- CImageInfo ii;
- ii.ii_Width=iHMWidth-1;
- ii.ii_Height=iHMHeight-1;
- ii.ii_BitsPerPixel=32;
- ii.ii_Picture=(UBYTE*) AllocMemory(ii.ii_Width*ii.ii_Height*ii.ii_BitsPerPixel/8);
- COLOR *pcol=(COLOR *)ii.ii_Picture;
- INDEX iGradientHeight=ptdGradient->GetPixHeight();
- UWORD *puw=ptrTerrain->tr_auwHeightMap;
- if(puw==NULL) return;
- for( INDEX iy=0; iy<ii.ii_Height; iy++)
- {
- for( INDEX ix=0; ix<ii.ii_Width; ix++)
- {
- UWORD uwHeight=*(puw+iy*iHMWidth+ix);
- FLOAT fHeightRatio=uwHeight/65535.0f;
- INDEX iGradPix1=iGradientHeight*fHeightRatio;
- INDEX iGradPix2=ClampUp(iGradPix1+1,iGradientHeight-1);
- COLOR colPix1=ptdGradient->GetTexel(0,iGradPix1);
- COLOR colPix2=ptdGradient->GetTexel(0,iGradPix2);
- FLOAT fLerpFactor=iGradientHeight*fHeightRatio-INDEX(iGradientHeight*fHeightRatio);
- COLOR colResult=LerpColor(colPix1,colPix2,fLerpFactor);
- *(pcol+iy*ii.ii_Width+ix)=ByteSwap(colResult);
- }
- }
- _pTextureStock->Release(ptdGradient);
- CTextureData tdIzohipse;
- try
- {
- tdIzohipse.Create_t( &ii, 1024, 16, TRUE);
- tdIzohipse.Save_t( fnIzohipseTexture);
- ptlLayer->SetLayerTexture_t(fnIzohipseTexture);
- ptlLayer->tl_fStretchX=1.0f/ptrTerrain->tr_vTerrainSize(1);
- ptlLayer->tl_fStretchY=1.0f/ptrTerrain->tr_vTerrainSize(2);
- }
- catch( char *strError)
- {
- (void) strError;
- WarningMessage("Unable to save izohipse texture!");
- return;
- }
- ptrTerrain->RefreshTerrain();
- theApp.m_ctTerrainPage.MarkChanged();
- break;
- }
- case 1: // "Browse texture"
- {
- CTFileName fnTexture=_EngineGUI.FileRequester(
- "Browse texture", FILTER_TEX FILTER_ALL FILTER_END,
- "Texture directory", "Textures\\");
- if( fnTexture=="") return;
- try
- {
- ptlLayer->SetLayerTexture_t(fnTexture);
- theApp.m_ctTerrainPageCanvas.MarkChanged();
- ptrTerrain->RefreshTerrain();
- }
- catch(char *strError)
- {
- (void) strError;
- }
- break;
- }
- case 2: // "View layer texture"
- {
- DisplayLayerTexture(iLayer);
- }
- }
- }
- }
- void DisplayLayerMask(INDEX iLayer)
- {
- CWndDisplayTexture *pDisplay=new CWndDisplayTexture;
- CTerrainLayer *ptlLayer=GetLayer(iLayer);
- if(ptlLayer!=NULL && ptlLayer->tl_ptdTexture!=NULL)
- {
- CTextureData *ptd=ptlLayer->GetThumbnail(ptlLayer->tl_iMaskWidth-1,ptlLayer->tl_iMaskHeight-1);
- POINT pt;
- GetCursorPos(&pt);
- CTString strText1;
- strText1.PrintF("%dx%d",ptlLayer->tl_iMaskWidth-1, ptlLayer->tl_iMaskHeight-1);
- pDisplay->Initialize(pt.x, pt.y, ptd, strText1);
- }
- }
- void ApplyLayerMaskCommand(INDEX iSelectedItem)
- {
- CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
- CTerrain *ptrTerrain=GetTerrain();
- if( ptrTerrain==NULL) return;
- CTerrainLayer *ptlLayer=GetLayer();
- INDEX iLayer=GetLayerIndex();
- if(ptlLayer!=NULL)
- {
- switch( iSelectedItem)
- {
- case 0: // "Fill mask"
- {
- if( ::MessageBoxA( pMainFrame->m_hWnd, "Are you sure that you want to fill this layer's mask?",
- "Warning !", MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON1| MB_SYSTEMMODAL | MB_TOPMOST) == IDYES)
- {
- EditTerrain(NULL, FLOAT3D(0,0,0), 1.0f, TE_FILL_LAYER_MASK);
- }
- break;
- }
- case 1: // "Clear mask"
- {
- if( ::MessageBoxA( pMainFrame->m_hWnd, "Are you sure that you want to clear this layer's mask?",
- "Warning !", MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON1| MB_SYSTEMMODAL | MB_TOPMOST) == IDYES)
- {
- EditTerrain(NULL, FLOAT3D(0,0,0), 1.0f, TE_CLEAR_LAYER_MASK);
- }
- break;
- }
- case 2: // "Import mask"
- {
- CTFileName fnMaskMap=_EngineGUI.FileRequester(
- "Import layer mask", FILTER_TGA FILTER_PCX FILTER_ALL FILTER_END,
- "Layer mask directory", "Textures\\");
- if( fnMaskMap=="") return;
- try
- {
- ptlLayer->ImportLayerMask_t(fnMaskMap);
- ptrTerrain->RefreshTerrain();
- pMainFrame->Invalidate(FALSE);
- theApp.GetActiveDocument()->SetModifiedFlag( TRUE);
- }
- catch(char *strError)
- {
- AfxMessageBox( CString(strError));
- }
- break;
- }
- case 3: // "Export mask"
- {
- CTFileName fnMaskMap=_EngineGUI.FileRequester(
- "Export layer mask", FILTER_TGA FILTER_PCX FILTER_ALL FILTER_END,
- "Layer mask directory", "Textures\\");
- if( fnMaskMap=="") return;
- try
- {
- ptlLayer->ExportLayerMask_t(fnMaskMap);
- ptrTerrain->RefreshTerrain();
- pMainFrame->Invalidate(FALSE);
- }
- catch(char *strError)
- {
- AfxMessageBox( CString(strError));
- }
- break;
- }
- case 4: // noise
- {
- EditTerrain(NULL, FLOAT3D(0,0,0), 1.0f, TE_LAYER_RND_NOISE);
- break;
- }
- case 5: // "View mask"
- {
- DisplayLayerMask(iLayer);
- }
- }
- theApp.m_ctTerrainPageCanvas.MarkChanged();
- }
- }
- void PickLayerColor(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- INDEX iLayer=ptib->tib_iLayer;
- CTerrainLayer *ptlLayer=GetLayer(iLayer);
- if(ptlLayer==NULL) return;
- CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
- COLORREF colMfc=CLRF_CLR( ptlLayer->tl_colMultiply);
- if( MyChooseColor( colMfc, *pMainFrame))
- {
- ptlLayer->tl_colMultiply=CLR_CLRF( colMfc) | ptlLayer->tl_colMultiply&0x000000FF;
- }
- }
- void NumericAlpha(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- INDEX iLayer=ptib->tib_iLayer;
- CTerrainLayer *ptlLayer=GetLayer(iLayer);
- if(ptlLayer==NULL) return;
- CDlgNumericAlpha dlgNumericAlpha( ptlLayer->tl_colMultiply&0xFF);
- if( dlgNumericAlpha.DoModal() == IDOK)
- {
- ptlLayer->tl_colMultiply&=0xFFFFFF00;
- ptlLayer->tl_colMultiply|=(dlgNumericAlpha.m_iAlpha&0xFF);
- }
- }
- void InvokeLayerOptions(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- INDEX iLayer=ptib->tib_iLayer;
- if(iLayer==-1) return;
- CDlgEditTerrainLayer dlg;
- if( dlg.DoModal()==IDOK)
- {
- GenerateLayerDistribution(iLayer);
- }
- }
- void PickSelectedLayerBcgColor(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- PointToScreenSpace(pt, pdp);
- CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
- pMainFrame->CustomColorPicker( pt.x-50, pt.y);
- COLORREF TmpColor = CLRF_CLR( _colSelectedLayerBcg);
- if( MyChooseColor( TmpColor, *pMainFrame))
- {
- _colSelectedLayerBcg = CLR_CLRF( TmpColor)|CT_OPAQUE;
- }
- theApp.m_ctTerrainPageCanvas.MarkChanged();
- }
- INDEX InsertItemMacro( CCustomComboWnd *pCC, CTString strText, INDEX iIcon=-1, INDEX iValue=-1, COLOR col=COL_DEFAULT_ITEM)
- {
- INDEX iItem;
- if(iIcon!=-1)
- {
- MEXaabbox2D boxIcon=MEXaabbox2D( MEX2D(16*iIcon,0), MEX2D(16*iIcon+16,16));
- DECLARE_CTFILENAME( fnTerrainEditIcons, "Textures\\Editor\\TerrainEditingIcons.tex");
- iItem=pCC->InsertItem( strText, fnTerrainEditIcons, boxIcon);
- }
- else
- {
- iItem=pCC->InsertItem( strText);
- }
- if(iValue!=-1)
- {
- pCC->SetItemValue(iItem, iValue);
- }
- pCC->SetItemColor( iItem, col);
- return iItem;
- }
- void InvokeLayerPopup(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- CTerrain *ptrTerrain=GetTerrain();
- if( ptrTerrain==NULL) return;
- CCustomComboWnd *pCombo=new CCustomComboWnd;
- InsertItemMacro( pCombo, "Delete layer", -1, 0);
- InsertItemMacro( pCombo, "Insert texture layer", -1, 1);
- InsertItemMacro( pCombo, "Insert tile layer", -1, 4);
- InsertItemMacro( pCombo, "Move up", -1, 2);
- InsertItemMacro( pCombo, "Move down", -1, 3);
- PointToScreenSpace(pt, pdp);
- pCombo->Initialize(NULL, ApplyLayerCommand, pt.x, pt.y);
- }
- void InvokeLayerTexturePopup(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- CTerrain *ptrTerrain=GetTerrain();
- if( ptrTerrain==NULL) return;
- CCustomComboWnd *pCombo=new CCustomComboWnd;
- InsertItemMacro( pCombo, "Create izohipse texture", 22, 0);
- InsertItemMacro( pCombo, "Browse texture", 22, 1);
- InsertItemMacro( pCombo, "View layer texture", 3, 2);
- PointToScreenSpace(pt, pdp);
- pCombo->Initialize(NULL, ApplyLayerTextureCommand, pt.x, pt.y);
- }
- void InvokeLayerMaskPopup(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- CTerrain *ptrTerrain=GetTerrain();
- if( ptrTerrain==NULL) return;
- CCustomComboWnd *pCombo=new CCustomComboWnd;
- InsertItemMacro( pCombo, "Fill mask", 17, 0);
- InsertItemMacro( pCombo, "Clear mask", 9, 1);
- InsertItemMacro( pCombo, "Noise", 12, 4);
- InsertItemMacro( pCombo, "--------------",-1,-1);
- InsertItemMacro( pCombo, "Import mask", 22, 2);
- InsertItemMacro( pCombo, "Export mask", 22, 3);
- InsertItemMacro( pCombo, "--------------",-1,-1);
- InsertItemMacro( pCombo, "View mask", 3, 5);
- PointToScreenSpace(pt, pdp);
- pCombo->Initialize(NULL, ApplyLayerMaskCommand, pt.x, pt.y);
- }
- CTString GetStretchInfo(CTIButton *ptib, CPoint pt, CDrawPort *pdp, BOOL bLmb)
- {
- CTString strInfo;
- INDEX iLayer=ptib->tib_iLayer;
- if( iLayer!=-1)
- {
- CTerrainLayer *ptlLayer=GetLayer(iLayer);
- CTerrain *ptrTerrain=GetTerrain();
- if(ptlLayer!=NULL && ptrTerrain!=NULL)
- {
- strInfo.PrintF("Texture stretch: %g", ptlLayer->tl_fStretchX);
- return strInfo;
- }
- }
- return strInfo;
- }
- CTString GetEditedData(CTIButton *ptib, CPoint pt, CDrawPort *pdp, BOOL bLmb)
- {
- CTString strInfo;
- if(ptib->tib_pfData1!=NULL) strInfo.PrintF("%f", ptib->tib_pfData1);
- return strInfo;
- }
- void OnDropIntoLayerTexture(CTIButton *ptib, CPoint pt, CDrawPort *pdp, CTFileName fnDropped)
- {
- // if it is not texture, report error
- if( fnDropped.FileExt() != ".tex" )
- {
- AfxMessageBox( L"You can only drop textures here.");
- return;
- }
-
- INDEX iLayer=ptib->tib_iLayer;
- CTerrainLayer *ptlLayer=GetLayer(iLayer);
- CTerrain *ptrTerrain=GetTerrain();
- if(ptlLayer!=NULL && ptrTerrain!=NULL)
- {
- ASSERT(ptlLayer->tl_ptdTexture!=NULL);
- CTFileName fnOldTexture=CTFILENAME("Textures\\Editor\\Default.tex");
- if(ptlLayer->tl_ptdTexture!=NULL)
- {
- fnOldTexture=ptlLayer->tl_ptdTexture->GetName();
- }
- BOOL bSetOldTexture=TRUE;
- try
- {
- fnDropped.RemoveApplicationPath_t();
- ptlLayer->SetLayerTexture_t(fnDropped);
- bSetOldTexture=FALSE;
- theApp.m_ctTerrainPageCanvas.MarkChanged();
- ptrTerrain->RefreshTerrain();
- }
- catch(char *strError)
- {
- (void) strError;
- }
-
- // if should restore old texture
- if(bSetOldTexture)
- {
- try
- {
- ptlLayer->SetLayerTexture_t(fnOldTexture);
- }
- catch(char *strError)
- {
- (void) strError;
- }
- }
- }
- }
- void ToggleLayerVisibleFlag(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- INDEX iLayer=ptib->tib_iLayer;
- if( iLayer!=-1)
- {
- CTerrainLayer *ptlLayer=GetLayer(iLayer);
- if(ptlLayer!=NULL)
- {
- ptlLayer->tl_bVisible=!ptlLayer->tl_bVisible;
- CTerrain *ptrTerrain=GetTerrain();
- ptrTerrain->RefreshTerrain();
- }
- }
- }
- void ToggleFlag(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- INDEX iLayer=ptib->tib_iLayer;
- if( iLayer!=-1)
- {
- CTerrainLayer *ptlLayer=GetLayer(iLayer);
- if(ptlLayer!=NULL)
- {
- BOOL bOldValue=*(BOOL*)((UBYTE*)ptlLayer+(ULONG)ptib->tib_pfData1);
- bOldValue=!bOldValue;
- *(BOOL*)((UBYTE*)ptlLayer+(ULONG)ptib->tib_pfData1)=bOldValue;
- }
- }
- }
- BOOL DisableIfNoTerrainSelected(CTIButton *ptib)
- {
- CTerrain *ptrTerrain=GetTerrain();
- return ptrTerrain!=NULL;
- }
- CTString GetNormalizedPercentageInfo(CTIButton *ptib, CPoint pt, CDrawPort *pdp, BOOL bLmb)
- {
- CTString strInfo;
- INDEX iLayer=ptib->tib_iLayer;
- if( iLayer!=-1)
- {
- CTerrainLayer *ptlLayer=GetLayer(iLayer);
- if(ptlLayer!=NULL)
- {
- FLOAT *pfNormalized=(FLOAT *)((UBYTE*)ptlLayer+(ULONG)ptib->tib_pfData1);
- FLOAT fValue=*pfNormalized;
- strInfo.PrintF("%s: %d%%", ptib->tib_strToolTip, INDEX(floor(fValue*100.0f+0.5f)));
- return strInfo;
- }
- }
- return strInfo;
- }
- void ChangeLayerDistributionData(CTIButton *ptib, FLOAT fdx, FLOAT fdy, CDrawPort *pdp)
- {
- if( ptib->tib_pfData1==NULL) return;
- INDEX iLayer=ptib->tib_iLayer;
- if( iLayer==-1) return;
- CTerrainLayer *ptlLayer=GetLayer(iLayer);
- if(ptlLayer==NULL) return;
-
- FLOAT *pfNormalized=(FLOAT *)((UBYTE*)ptlLayer+(ULONG)ptib->tib_pfData1);
- FLOAT fOldValue=*pfNormalized;
- FLOAT fAddX=ptib->tib_fDataDelta*fdx;
- FLOAT fNewValue=Clamp( fOldValue+fAddX, 0.0f, 1.0f);
- *pfNormalized=fNewValue;
- _iGenerateForLayer=iLayer;
- _chAutoGenerateDistribution.MarkChanged();
- }
- void ChangeData(CTIButton *ptib, FLOAT fdx, FLOAT fdy, CDrawPort *pdp)
- {
- if( ptib->tib_pfData1!=NULL)
- {
- FLOAT fData=*ptib->tib_pfData1;
- FLOAT fAdd=ptib->tib_fDataDelta*fdx;
- if((fData+fAdd)>=ptib->tib_fDataMax)
- {
- if(ptib->tib_bWrapData)
- {
- fData=ptib->tib_fDataMin+((fData+fAdd)-ptib->tib_fDataMax);
- }
- else
- {
- fData=ptib->tib_fDataMax;
- }
- }
- else if((fData+fAdd)<=ptib->tib_fDataMin)
- {
- if(ptib->tib_bWrapData)
- {
- fData=ptib->tib_fDataMax+(fData+fAdd);
- }
- else
- {
- fData=ptib->tib_fDataMin;
- }
- }
- else
- {
- fData=fData+fAdd;
- }
- *ptib->tib_pfData1=fData;
- }
- }
- void ChangeTextureRotation(CTIButton *ptib, FLOAT fdx, FLOAT fdy, CDrawPort *pdp)
- {
- INDEX iLayer=ptib->tib_iLayer;
- if( iLayer!=-1)
- {
- CTerrainLayer *ptlLayer=GetLayer(iLayer);
- if(ptlLayer!=NULL)
- {
- FLOAT fAdd=CHANGE_ANGLE_SENSITIVITY*fdx;
- ptlLayer->tl_fRotateX+=fAdd;
- ptlLayer->tl_fRotateY+=fAdd;
- }
- }
- }
- void ChangeTextureOffset(CTIButton *ptib, FLOAT fdx, FLOAT fdy, CDrawPort *pdp)
- {
- INDEX iLayer=ptib->tib_iLayer;
- if( iLayer!=-1)
- {
- CTerrainLayer *ptlLayer=GetLayer(iLayer);
- if(ptlLayer!=NULL)
- {
- FLOAT fAddX=CHANGE_OFFSET_SENSITIVITY*fdx;
- FLOAT fAddY=CHANGE_OFFSET_SENSITIVITY*fdy;
- ptlLayer->tl_fOffsetX+=fAddX;
- ptlLayer->tl_fOffsetY+=fAddY;
- }
- }
- }
- void ChangeTextureStretch(CTIButton *ptib, FLOAT fdx, FLOAT fdy, CDrawPort *pdp)
- {
- INDEX iLayer=ptib->tib_iLayer;
- if( iLayer!=-1)
- {
- CTerrainLayer *ptlLayer=GetLayer(iLayer);
- CTerrain *ptrTerrain=GetTerrain();
- if(ptlLayer!=NULL && ptrTerrain!=NULL)
- {
- if(fdx>=CHANGE_STRETCH_SENSITIVITY)
- {
- ptlLayer->tl_fStretchX/=2;
- ptlLayer->tl_fStretchY/=2;
- ptrTerrain->RefreshTerrain();
- }
- else if(fdx<=-CHANGE_STRETCH_SENSITIVITY)
- {
- ptlLayer->tl_fStretchX*=2;
- ptlLayer->tl_fStretchY*=2;
- ptrTerrain->RefreshTerrain();
- }
- }
- }
- }
- void OnSelectBrush(INDEX iSelectedItem)
- {
- if( iSelectedItem>=0 && iSelectedItem<CT_BRUSH_MODES)
- {
- theApp.m_iTerrainBrushMode=iSelectedItem;
- theApp.m_ctTerrainPageCanvas.MarkChanged();
- theApp.GetDocument()->SetStatusLineModeInfoMessage();
- }
- else if(iSelectedItem==-1)
- {
- CTerrain *ptrTerrain=GetTerrain();
- if( ptrTerrain==NULL) return;
- CDlgEditFloat dlg;
- dlg.m_fEditFloat=theApp.m_fPosterizeStep;
- dlg.m_strVarName = "Posterize step (m)";
- dlg.m_strTitle = "Enter posterize step";
- if(dlg.DoModal()!=IDOK) return;
- theApp.m_fPosterizeStep=dlg.m_fEditFloat;
- }
- // auto update terrain distribution flag
- else if(iSelectedItem==50)
- {
- theApp.m_Preferences.ap_bAutoUpdateTerrainDistribution=!theApp.m_Preferences.ap_bAutoUpdateTerrainDistribution;
- }
- // settings
- else if(iSelectedItem==100)
- {
- CDlgTEOperationSettings dlg;
- dlg.DoModal();
- }
- }
- void InvokeBrushModeCombo(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- PointToScreenSpace(pt, pdp);
- CCustomComboWnd *pCombo=new CCustomComboWnd;
- INDEX iFlag=6;
- if(theApp.m_Preferences.ap_bAutoUpdateTerrainDistribution)
- {
- iFlag=7;
- }
- InsertItemMacro( pCombo, "Auto update layer distribution", iFlag, 50, COL_SETTINGS);
- InsertItemMacro( pCombo, "---------------------------------", -1, -1, COL_SEPARATOR);
- for(INDEX iMode=0; iMode<CT_BRUSH_MODES; iMode++)
- {
- INDEX iIcon;
- CTString strText;
- GetBrushModeInfo(iMode, iIcon, strText);
- InsertItemMacro( pCombo, strText, iIcon, iMode);
- }
-
- InsertItemMacro( pCombo, "---------------------------------", -1, -1, COL_SEPARATOR);
- InsertItemMacro( pCombo, "Operation settings (Ctrl+Shift+P)", 26, 100, COL_SETTINGS);
- pCombo->Initialize(NULL, OnSelectBrush, pt.x, pt.y);
- }
- void InvokePercentageCombo(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- PointToScreenSpace(pt, pdp);
- CCustomComboWnd *pCombo=new CCustomComboWnd;
- for( INDEX i=1; i<11; i++)
- {
- CTString strText;
- strText.PrintF("%d", i*10);
- pCombo->InsertItem( strText);
- }
- pCombo->Initialize(&theApp.m_fTerrainBrushPressureEnum, NULL, pt.x, pt.y);
- }
- void InvokeEditModeCombo(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- PointToScreenSpace(pt, pdp);
- CCustomComboWnd *pCombo=new CCustomComboWnd;
- InsertItemMacro( pCombo, "Altitude (U)", 20);
- InsertItemMacro( pCombo, "Texture (L)", 19);
- pCombo->Initialize(&theApp.m_iTerrainEditMode, NULL, pt.x, pt.y);
- }
- void NextEnum(CTIButton *ptib, CPoint pt)
- {
- ChangeData(ptib, 1, 0, NULL);
- }
- FLOAT GetMaxSliderPos(CDrawPort *pdp)
- {
- CTerrain *ptrTerrain=GetTerrain();
- if( ptrTerrain==NULL) return 0;
- FLOAT fMaxPos=ClampDn(ptrTerrain->tr_atlLayers.Count()*LAYER_HEIGHT-pdp->GetHeight(),PIX(0));
- return fMaxPos;
- }
- void OnSliderArrowUp(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- _fScrollLayers=ClampDn(_fScrollLayers-PIX(LAYER_HEIGHT),0.0f);
- }
- void OnSliderArrowDown(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- _fScrollLayers=ClampUp(_fScrollLayers+PIX(LAYER_HEIGHT),GetMaxSliderPos(pdp));
- }
- void RenderLayerColor(CTIButton *ptib, CDrawPort *pdp)
- {
- INDEX iLayer=ptib->tib_iLayer;
- CTerrainLayer *ptlLayer=GetLayer(iLayer);
- if(ptlLayer==NULL) return;
- PIXaabbox2D box=GetButtonScreenBox(*ptib);
- pdp->Fill(box.Min()(1), box.Min()(2), box.Size()(1), box.Size()(2), ptlLayer->tl_colMultiply);
- }
- void RenderSlider(CTIButton *ptib, CDrawPort *pdp)
- {
- FLOAT fMaxPos=GetMaxSliderPos(pdp);
- PIX pixSliderY=FLOAT(ptib->tib_fdy-SLIDER_HOLDER_HEIGHT/2)/fMaxPos*_fScrollLayers;
- pixSliderY=ClampDn<PIX>(pixSliderY-SLIDER_HOLDER_HEIGHT/2, 0);
- pdp->Fill(ptib->tib_fx, ptib->tib_fy+pixSliderY, ptib->tib_fdx-2, SLIDER_HOLDER_HEIGHT, C_mlGRAY|CT_OPAQUE);
- }
- void OnSliderClick(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- FLOAT fMaxPos=GetMaxSliderPos(pdp);
- PointToIconSpace(pt, ptib);
- pt.y=ClampUp( pt.y, INDEX(ptib->tib_fdy-SLIDER_HOLDER_HEIGHT/2));
- if(pt.y<SLIDER_HOLDER_HEIGHT/2) pt.y=0;
- FLOAT fRemapFactor=fMaxPos/(ptib->tib_fdy-SLIDER_HOLDER_HEIGHT);
- FLOAT fSetPos=pt.y*fRemapFactor;
- _fScrollLayers=ClampUp(fSetPos,fMaxPos);
- }
- void DragSlider(CTIButton *ptib, FLOAT fdx, FLOAT fdy, CDrawPort *pdp/*=NULL*/)
- {
- FLOAT fMaxPos=GetMaxSliderPos(pdp);
- FLOAT fRemapFactor=FLOAT(fMaxPos)/(ptib->tib_fdy-SLIDER_HOLDER_HEIGHT);
- FLOAT fNewPos=_fScrollLayers+fdy*fRemapFactor;
- _fScrollLayers=Clamp( fNewPos, 0.0f, fMaxPos);
- }
- void RecalculateShadows(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- RecalculateShadows();
- }
- void DisplayHeightMap(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- PointToScreenSpace(pt, pdp);
- DisplayHeightMapWindow( pt);
- }
- void ApplyTerrainOptions(INDEX iSelectedItem)
- {
- CTerrain *ptrTerrain=GetTerrain();
- if( ptrTerrain==NULL) return;
- switch(iSelectedItem)
- {
- // invoke properties
- case 0:
- {
- CDlgTerrainProperties dlg;
- dlg.DoModal();
- break;
- }
- // generate terrain
- case 3:
- {
- ApplyGenerateTerrain();
- break;
- }
- // smooth
- case 4:
- {
- ApplySmoothOntoTerrain();
- break;
- }
- // filter
- case 5:
- {
- ApplyFilterOntoTerrain();
- break;
- }
- // add noise
- case 6:
- {
- ApplyRndNoiseOntoTerrain();
- break;
- }
- // equalize
- case 7:
- {
- ApplyEqualizeOntoTerrain();
- break;
- }
- // operation settings
- case 8:
- {
- // option settings
- CDlgTEOperationSettings dlg;
- dlg.DoModal();
- break;
- }
- // posterize
- case 9:
- {
- ApplyPosterizeOntoTerrain();
- break;
- }
- // add continous noise
- case 11:
- {
- ApplyContinousNoiseOntoTerrain();
- break;
- }
- // limit down
- case 12:
- {
- ApplyMinimumOntoTerrain();
- break;
- }
- // limit up
- case 13:
- {
- ApplyMaximumOntoTerrain();
- break;
- }
- // flatten
- case 14:
- {
- ApplyFlattenOntoTerrain();
- break;
- }
- // recalcualte shadows
- case 15:
- {
- ptrTerrain->UpdateShadowMap();
- }
- // generate layer distribution
- case 16:
- {
- GenerateLayerDistribution(-1);
- }
- // optimize layers
- case 17:
- {
- OptimizeLayers();
- }
- // view heightmap
- case 50:
- {
- CPoint pt;
- GetCursorPos( &pt);
- DisplayHeightMapWindow( pt);
- }
- }
- }
- void InvokeTerrainOptions(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- CTerrain *ptrTerrain=GetTerrain();
- if( ptrTerrain==NULL) return;
- CCustomComboWnd *pCombo=new CCustomComboWnd;
- INDEX iItem=0;
- InsertItemMacro( pCombo, "Terrain properties (Ctrl+Shift+T)",2,0);
- InsertItemMacro( pCombo, "------------------------------------", -1, -1, COL_SEPARATOR);
- InsertItemMacro( pCombo, "Generate terrain (Ctrl+Shift+G)",25, 3);
- InsertItemMacro( pCombo, "Equalize (Ctrl+Shift+E)",1,7);
- InsertItemMacro( pCombo, "------------------------------------", -1, -1, COL_SEPARATOR);
- InsertItemMacro( pCombo, "Recalculate shadows (Ctrl+Shift+R)",5, 15);
- InsertItemMacro( pCombo, "Generate layer distribution (Ctrl+G)",19, 16);
- InsertItemMacro( pCombo, "Optimize layers (Ctrl+Shift+Z)",25, 17);
- InsertItemMacro( pCombo, "------------------------------------", -1, -1, COL_SEPARATOR);
- InsertItemMacro( pCombo, "Smooth (Ctrl+Shift+O)",10,4);
- InsertItemMacro( pCombo, "Filter (Ctrl+Shift+F)",30,5);
- InsertItemMacro( pCombo, "Limit down (Ctrl+Shift+M)",27,12);
- InsertItemMacro( pCombo, "Limit up (Ctrl+Shift+X)",11,13);
- InsertItemMacro( pCombo, "Flatten (Ctrl+Shift+N)",18,14);
- InsertItemMacro( pCombo, "Posterize",28,9);
- InsertItemMacro( pCombo, "Random noise (Ctrl+Shift+K)",21,6);
- InsertItemMacro( pCombo, "Texture noise (Ctrl+Shift+Y)",31,11);
- InsertItemMacro( pCombo, "------------------------------------", -1, -1,COL_SEPARATOR);
- InsertItemMacro( pCombo, "View height map ", 26, 50);
- InsertItemMacro( pCombo, "Operation settings (Ctrl+Shift+P)", 26, 8, COL_SETTINGS);
- PointToScreenSpace(pt, pdp);
- pCombo->Initialize(NULL, ApplyTerrainOptions, pt.x, pt.y);
- }
- void DisplayHeightMapWindow(CPoint pt)
- {
- CTextureData tdHeightMap;
- CImageInfo ii;
- CTerrain *ptrTerrain=GetTerrain();
- if( ptrTerrain==NULL) return;
- PIX pixW=ptrTerrain->tr_pixHeightMapWidth;
- PIX pixH=ptrTerrain->tr_pixHeightMapHeight;
- if(ptrTerrain->tr_auwHeightMap==NULL) return;
- ii.ii_BitsPerPixel=32;
- ii.ii_Width=pixW-1;
- ii.ii_Height=pixH-1;
- ii.ii_Picture=(UBYTE*)AllocMemory((pixW-1)*(pixH-1)*sizeof(COLOR));
- COLOR *pcol=(COLOR *)ii.ii_Picture;
- for( INDEX iy=0; iy<pixH-1; iy++)
- {
- for( INDEX ix=0; ix<pixW-1; ix++)
- {
- UWORD *pdest=ptrTerrain->tr_auwHeightMap+iy*pixW+ix;
- UWORD uw=*pdest;
- FLOAT fPix=uw/256.0f;
- UBYTE ubR=UBYTE(fPix);
- COLOR col=RGBToColor(ubR,ubR,ubR)|CT_OPAQUE;
- col=RGBToColor(ubR,ubR,ubR)|CT_OPAQUE;
- *(pcol+iy*(pixW-1)+ix)=ByteSwap(col);
- }
- }
- try
- {
- tdHeightMap.Create_t( &ii, pixW-1, 16, TRUE);
- CTString strHeightMap="Temp\\ViewHeightMap.tex";
- tdHeightMap.Save_t( strHeightMap);
- CTextureData *ptd;
- ptd=_pTextureStock->Obtain_t( strHeightMap);
- ptd->Reload();
- CWndDisplayTexture *pDisplay=new CWndDisplayTexture;
- pDisplay->Initialize(pt.x, pt.y, ptd);
- }
- catch( char *strError)
- {
- (void) strError;
- WarningMessage("Unable to display height map!");
- }
- }
- void OnSelectLoadSave(INDEX iSelectedItem)
- {
- switch( iSelectedItem)
- {
- case 0:
- case 1:
- case 2:
- case 3:
- {
- ApplyImportExport(iSelectedItem);
- }
- case 4: // "Load surface"
- {
- CTFileName fnSurface=_EngineGUI.FileRequester(
- "Load surface", "Surfaces (*.sfc)\0*.sfc\0" FILTER_ALL FILTER_END,
- "Surface directory", "Surfaces\\");
- if( fnSurface=="") return;
- LoadSurface(fnSurface);
- break;
- }
- case 5: // "Save surface"
- {
- CTFileName fnSurface=_EngineGUI.FileRequester(
- "Save surface", "Surfaces (*.sfc)\0*.sfc\0" FILTER_ALL FILTER_END,
- "Surface directory", "Surfaces\\");
- if( fnSurface=="") return;
- SaveSurface(fnSurface);
- break;
- }
- }
- }
- void ApplyImportExport(INDEX iOperation)
- {
- CTerrain *ptrTerrain=GetTerrain();
- if( ptrTerrain==NULL) return;
- CTFileName fnHeightmap;
- if(iOperation<2)
- {
- fnHeightmap=_EngineGUI.FileRequester(
- "Import heightmap", FILTER_TGA FILTER_PCX FILTER_ALL FILTER_END,
- "Terrain heightmap directory", "Textures\\");
- if( fnHeightmap=="") return;
- }
- else
- {
- fnHeightmap=_EngineGUI.FileRequester(
- "Export heightmap", FILTER_TGA FILTER_PCX FILTER_ALL FILTER_END,
- "Terrain heightmap directory", "Textures\\");
- if( fnHeightmap=="") return;
- }
- try
- {
- switch( iOperation)
- {
- // import 8 bit
- case 0:
- {
- ptrTerrain->ImportHeightMap_t(fnHeightmap, FALSE);
- theApp.m_ctTerrainPage.MarkChanged();
- break;
- }
- // import 16 bit
- case 1:
- {
- ptrTerrain->ImportHeightMap_t(fnHeightmap, TRUE);
- theApp.m_ctTerrainPage.MarkChanged();
- break;
- }
- // export 8 bit
- case 2:
- {
- ptrTerrain->ExportHeightMap_t(fnHeightmap, FALSE);
- break;
- }
- // export 16 bit
- case 3:
- {
- ptrTerrain->ExportHeightMap_t(fnHeightmap, TRUE);
- break;
- }
- }
- }
- catch(char *strError)
- {
- AfxMessageBox( CString(strError));
- }
- }
- void GenerateLayerDistribution(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- GenerateLayerDistribution(-1);
- }
- void InvokeImportExportCombo(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- CTerrain *ptrTerrain=GetTerrain();
- if( ptrTerrain==NULL) return;
- CCustomComboWnd *pCombo=new CCustomComboWnd;
- InsertItemMacro( pCombo, "Import 8-bit", 22, 0);
- InsertItemMacro( pCombo, "Import 16-bit", 22, 1);
- InsertItemMacro( pCombo, "Export 8-bit", 22, 2);
- InsertItemMacro( pCombo, "Export 16-bit", 22, 3);
- InsertItemMacro( pCombo, "----------------", -1, -1, COL_SEPARATOR);
- InsertItemMacro( pCombo, "Load surface", 22, 4);
- InsertItemMacro( pCombo, "Save surface", 22, 5);
- PointToScreenSpace(pt, pdp);
- pCombo->Initialize(NULL, OnSelectLoadSave, pt.x, pt.y);
- }
- void InvokeTerrainTilePalette( PIX pixX, PIX pixY)
- {
- CWndTerrainTilePalette *pDisplay=new CWndTerrainTilePalette;
- CTerrainLayer *ptlLayer=GetLayer();
- if(ptlLayer!=NULL && ptlLayer->tl_ptdTexture!=NULL)
- {
- pDisplay->Initialize(pixX, pixY, ptlLayer->tl_ptdTexture, TRUE);
- }
- }
- CBrushPaletteWnd *_pBrushPalette=NULL;
- void InvokeTerrainBrushPalette( PIX pixX, PIX pixY)
- {
- // calculate palette window's rectangle
- CRect rectWindow;
- rectWindow.left = pixX;
- rectWindow.bottom = pixY;
- rectWindow.right = rectWindow.left + BRUSH_PALETTE_WIDTH;
- rectWindow.top = rectWindow.bottom - BRUSH_PALETTE_HEIGHT;
- if( _pBrushPalette == NULL)
- {
- // instantiate new choose color palette window
- _pBrushPalette = new CBrushPaletteWnd;
- // create window
- CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
- BOOL bResult = _pBrushPalette->CreateEx( WS_EX_TOOLWINDOW,
- NULL, L"Brush palette", WS_CHILD|WS_POPUP|WS_VISIBLE,
- rectWindow.left, rectWindow.top, rectWindow.Width(), rectWindow.Height(),
- pMainFrame->m_hWnd, NULL, NULL);
- _pBrushPalette->SetFocus();
- if( !bResult)
- {
- AfxMessageBox( L"Error: Failed to create brush palette");
- return;
- }
- // initialize canvas for active texture button
- _pGfx->CreateWindowCanvas( _pBrushPalette->m_hWnd, &_pBrushPalette->m_pViewPort,
- &_pBrushPalette->m_pDrawPort);
- }
- else
- {
- _pBrushPalette->ShowWindow(SW_SHOW);
- _pBrushPalette->SetFocus();
- }
- }
- void InvokeBrushPalette(CTIButton *ptib, CPoint pt, CDrawPort *pdp)
- {
- PointToScreenSpace(pt, pdp);
- InvokeTerrainBrushPalette( pt.x, pt.y);
- }
- BOOL CTerrainInterface::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
- {
- return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
- }
- BOOL CTerrainInterface::IsClicked(CTIButton &tib, CPoint pt) const
- {
- PIX pixOffsetX=0;
- PIX pixOffsetY=0;
- GetButtonOffset(tib, pixOffsetX, pixOffsetY);
- PIX x=tib.tib_fx+pixOffsetX;
- PIX y=tib.tib_fy+pixOffsetY;
- PIX dx=tib.tib_fdx;
- PIX dy=tib.tib_fdy;
- return( (pt.x>x) && (pt.x<x+dx) && (pt.y>y) && (pt.y<y+dy) );
- }
- BOOL _bDummyMouseMove=FALSE;
- BOOL _bMouseTrapInProgress=FALSE;
- void CTerrainInterface::OnLButtonDown(UINT nFlags, CPoint point)
- {
- CWnd::OnLButtonDown(nFlags, point);
- SetFocus();
- m_ptMouseDown=point;
- m_ptMouse=point;
- m_ptMouseDownScreen=point;
- ClientToScreen(&m_ptMouseDownScreen);
- FOREACHINDYNAMICCONTAINER( dcButtons, CTIButton, ittib)
- {
- CTIButton &tib=*ittib;
-
- if( IsClicked(tib, point))
- {
- if(tib.tib_pOnLeftClick!=NULL)
- {
- tib.tib_pOnLeftClick(&tib, m_ptMouse, m_pDrawPort);
- _bMouseTrapInProgress=FALSE;
- UnhideCursor();
- Invalidate(FALSE);
- if(!tib.tib_bContinueTesting) break;
- }
- if(tib.tib_pOnLeftClickMove!=NULL)
- {
- // display tool tip
- if( tib.tib_pGetClickMoveData!=NULL)
- {
- CTString strInfo=tib.tib_pGetClickMoveData(&tib, point, m_pDrawPort, TRUE);
- _strToolTip=strInfo;
- SetCapture();
- theApp.m_cttToolTips.ManualOn( m_ptMouseDownScreen.x, m_ptMouseDownScreen.y, &::GetToolTipText, this);
- }
- // if should trap the mouse
- if(tib.tib_bMouseTrapForMove)
- {
- m_ptMouseCenter.x=m_pDrawPort->GetWidth()/2;
- m_ptMouseCenter.y=m_pDrawPort->GetHeight()/2;
- m_ptMouseCenterScreen=m_ptMouseCenter;
- ClientToScreen(&m_ptMouseCenterScreen);
- _bDummyMouseMove=TRUE;
- SetCursorPos(m_ptMouseCenterScreen.x, m_ptMouseCenterScreen.y);
- HideCursor();
- _bMouseTrapInProgress=TRUE;
- }
- if(!tib.tib_bContinueTesting) break;
- }
- }
- }
- }
- void CTerrainInterface::OnLButtonDblClk(UINT nFlags, CPoint point)
- {
- OnLButtonDown(nFlags, point);
- }
- void CTerrainInterface::OnMouseMove(UINT nFlags, CPoint point)
- {
- theApp.m_cttToolTips.MouseMoveNotify( m_hWnd, 500, &::GetToolTipText, this);
- BOOL bLMB = nFlags & MK_LBUTTON;
- BOOL bRMB = nFlags & MK_RBUTTON;
- FLOAT fdx=point.x-m_ptMouseCenter.x;
- FLOAT fdy=point.y-m_ptMouseCenter.y;
- FLOAT fdxNotLocked=point.x-m_ptMouse.x;
- FLOAT fdyNotLocked=point.y-m_ptMouse.y;
- fdx=fdxNotLocked;
- fdy=fdyNotLocked;
- m_ptMouse=point;
- if( _bDummyMouseMove)
- {
- _bDummyMouseMove=FALSE;
- return;
- }
- if( bLMB)
- {
- FOREACHINDYNAMICCONTAINER( dcButtons, CTIButton, ittib)
- {
- CTIButton &tib=*ittib;
-
- if( IsClicked(tib, m_ptMouseDown) && tib.tib_pOnLeftClickMove!=NULL)
- {
- if(tib.tib_bMouseTrapForMove)
- {
- tib.tib_pOnLeftClickMove(&tib, fdx, fdy, m_pDrawPort);
- _bDummyMouseMove=TRUE;
- SetCursorPos(m_ptMouseCenterScreen.x, m_ptMouseCenterScreen.y);
- }
- else
- {
- tib.tib_pOnLeftClickMove(&tib, fdxNotLocked, fdyNotLocked, m_pDrawPort);
- }
- Invalidate(FALSE);
-
- // update tool tip
- if( tib.tib_pGetClickMoveData!=NULL)
- {
- _strToolTip=tib.tib_pGetClickMoveData(&tib, point, m_pDrawPort, TRUE);
- theApp.m_cttToolTips.ManualUpdate();
- }
- if(!tib.tib_bContinueTesting) break;
- }
- }
- }
- else if( bRMB)
- {
- FOREACHINDYNAMICCONTAINER( dcButtons, CTIButton, ittib)
- {
- CTIButton &tib=*ittib;
-
- if( IsClicked(tib, m_ptMouseDown) && tib.tib_pOnRightClickMove!=NULL)
- {
- if(tib.tib_bMouseTrapForMove)
- {
- tib.tib_pOnRightClickMove(&tib, fdx, fdy, m_pDrawPort);
- _bDummyMouseMove=TRUE;
- SetCursorPos(m_ptMouseCenterScreen.x, m_ptMouseCenterScreen.y);
- }
- else
- {
- tib.tib_pOnRightClickMove(&tib, fdxNotLocked, fdyNotLocked, m_pDrawPort);
- }
- Invalidate(FALSE);
-
- // update tool tip
- if( tib.tib_pGetClickMoveData!=NULL)
- {
- _strToolTip=tib.tib_pGetClickMoveData(&tib, point, m_pDrawPort, FALSE);
- theApp.m_cttToolTips.ManualUpdate();
- }
- if(!tib.tib_bContinueTesting) break;
- }
- }
- }
- CWnd::OnMouseMove(nFlags, point);
- }
- void CTerrainInterface::OnLButtonUp(UINT nFlags, CPoint point)
- {
- theApp.m_cttToolTips.ManualOff();
- ReleaseCapture();
- _bDummyMouseMove=TRUE;
- if( _bMouseTrapInProgress)
- {
- SetCursorPos(m_ptMouseDownScreen.x, m_ptMouseDownScreen.y);
- _bMouseTrapInProgress=FALSE;
- UnhideCursor();
- m_ptMouseDown.x=-1;
- m_ptMouseDown.y=-1;
- }
- CWnd::OnLButtonUp(nFlags, point);
- }
- BOOL CTerrainInterface::PreTranslateMessage(MSG* pMsg)
- {
- return CWnd::PreTranslateMessage(pMsg);
- }
- void CTerrainInterface::OnRButtonDown(UINT nFlags, CPoint point)
- {
- CWnd::OnRButtonDown(nFlags, point);
- SetFocus();
- m_ptMouseDown=point;
- m_ptMouse=point;
- m_ptMouseDownScreen=point;
- ClientToScreen(&m_ptMouseDownScreen);
- FOREACHINDYNAMICCONTAINER( dcButtons, CTIButton, ittib)
- {
- CTIButton &tib=*ittib;
-
- if( IsClicked(tib, point))
- {
- if(tib.tib_pOnRightClick!=NULL)
- {
- tib.tib_pOnRightClick(&tib, m_ptMouse, m_pDrawPort);
- _bMouseTrapInProgress=FALSE;
- UnhideCursor();
- Invalidate(FALSE);
- if(!tib.tib_bContinueTesting) break;
- }
- if(tib.tib_pOnRightClickMove!=NULL)
- {
- // display tool tip
- if( tib.tib_pGetClickMoveData!=NULL)
- {
- CTString strInfo=tib.tib_pGetClickMoveData(&tib, point, m_pDrawPort, TRUE);
- _strToolTip=strInfo;
- theApp.m_cttToolTips.ManualOn( m_ptMouseDownScreen.x, m_ptMouseDownScreen.y, &::GetToolTipText, this);
- SetCapture();
- }
- // if should trap the mouse
- if(tib.tib_bMouseTrapForMove)
- {
- m_ptMouseCenter.x=m_pDrawPort->GetWidth()/2;
- m_ptMouseCenter.y=m_pDrawPort->GetHeight()/2;
- m_ptMouseCenterScreen=m_ptMouseCenter;
- ClientToScreen(&m_ptMouseCenterScreen);
- _bDummyMouseMove=TRUE;
- SetCursorPos(m_ptMouseCenterScreen.x, m_ptMouseCenterScreen.y);
- HideCursor();
- _bMouseTrapInProgress=TRUE;
- }
- if(!tib.tib_bContinueTesting) break;
- }
- }
- }
- }
- void CTerrainInterface::OnRButtonUp(UINT nFlags, CPoint point)
- {
- theApp.m_cttToolTips.ManualOff();
- ReleaseCapture();
- _bDummyMouseMove=TRUE;
- if( _bMouseTrapInProgress)
- {
- SetCursorPos(m_ptMouseDownScreen.x, m_ptMouseDownScreen.y);
- _bMouseTrapInProgress=FALSE;
- UnhideCursor();
- m_ptMouseDown.x=-1;
- m_ptMouseDown.y=-1;
- }
- CWnd::OnRButtonUp(nFlags, point);
- }
- void CTerrainInterface::OnIdle(void)
- {
- CWorldEditorDoc *pDoc = theApp.GetDocument();
-
- if(!_chAutoGenerateDistribution.IsUpToDate( _udAutoGenerateDistribution))
- {
- GenerateLayerDistribution(_iGenerateForLayer);
- _udAutoGenerateDistribution.MarkUpdated();
- }
- CTerrain *ptrTerrain=GetTerrain();
- if(ptrTerrain!=NULL)
- {
- if(GetLayerIndex()>=ptrTerrain->tr_atlLayers.Count())
- {
- SelectLayer(0);
- }
- }
- BOOL bLMB = (GetKeyState( VK_LBUTTON)&0x8000) != 0;
- BOOL bRMB = (GetKeyState( VK_RBUTTON)&0x8000) != 0;
- if(!bLMB && !bRMB && _bMouseTrapInProgress)
- {
- _bMouseTrapInProgress=FALSE;
- UnhideCursor();
- theApp.m_cttToolTips.ManualOff();
- }
-
- // if should re-initialize interface
- if(pDoc!=NULL && !pDoc->m_chSelections.IsUpToDate( m_udTerrainPage) ||
- !theApp.m_ctTerrainPage.IsUpToDate( m_udTerrainPage) )
- {
- if(m_pDrawPort!=NULL)
- {
- InitializeInterface(m_pDrawPort);
- Invalidate(FALSE);
- m_udTerrainPage.MarkUpdated();
- }
- }
-
- // if should just redraw interface
- if(!theApp.m_ctTerrainPageCanvas.IsUpToDate( m_udTerrainPageCanvas) )
- {
- Invalidate(FALSE);
- m_udTerrainPageCanvas.MarkUpdated();
- }
- }
- void CTerrainInterface::OnDropFiles(HDROP hDropInfo)
- {
- INDEX iNoOfFiles = DragQueryFile( hDropInfo, 0xFFFFFFFF, NULL, 0);
-
- if( iNoOfFiles != 1)
- {
- AfxMessageBox( L"You can drop only one file at a time.");
- return;
- }
- // buffer for dropped file name
- wchar_t chrFile[ 256];
- // place dropped file name into buffer
- DragQueryFile( hDropInfo, 0, chrFile, 256);
- // create file name from buffer
- CTFileName fnDropped = CTString(CStringA(chrFile));
- CPoint ptMouse;
- GetCursorPos( &ptMouse);
- ScreenToClient(&ptMouse);
- FOREACHINDYNAMICCONTAINER( dcButtons, CTIButton, ittib)
- {
- CTIButton &tib=*ittib;
- if( IsClicked(tib, ptMouse) && tib.tib_pOnDropFiles!=NULL)
- {
- tib.tib_pOnDropFiles(&tib, ptMouse, m_pDrawPort, fnDropped);
- }
- }
- CWnd::OnDropFiles(hDropInfo);
- }
- int CTerrainInterface::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- DragAcceptFiles();
- EnableToolTips( TRUE);
- return 0;
- }
- int CTerrainInterface::OnToolHitTest( CPoint point, TOOLINFO* pTI ) const
- {
- FOREACHINDYNAMICCONTAINER( dcButtons, CTIButton, ittib)
- {
- CTIButton &tib=*ittib;
-
- _strToolTip="";
- if( IsClicked(tib, point))
- {
- if( tib.tib_strToolTip!="" && tib.tib_strToolTip[0]!='_')
- {
- _strToolTip=tib.tib_strToolTip;
- return 1;
- }
- }
- }
- return 0;
- }
- void CTerrainInterface::InitializeInterface(CDrawPort *pdp)
- {
- try
- {
- DECLARE_CTFILENAME( fnTerrainEditIcons, "Textures\\Editor\\TerrainEditingIcons.tex");
- _toIcons.SetData_t(fnTerrainEditIcons);
- }
- catch(char *strError)
- {
- (void)strError;
- return;
- }
-
- FOREACHINDYNAMICCONTAINER( dcButtons, CTIButton, ittib)
- {
- delete &*ittib;
- }
- dcButtons.Clear();
- CTIButton *ptib;
- COLOR colBcg=RGBToColor(45,45,60)|CT_OPAQUE;
- ptib=AddButton(dcButtons,0,0,LAYER_START_X,pdp->GetHeight(),-1,-1, "_Terrain options area fill", C_dGRAY|CT_TRANSPARENT, colBcg);
-
- ptib=AddButton(dcButtons,1,1,45,45,-1,-1, "Current brush (\\)", C_lGRAY|CT_OPAQUE);
- ptib->SetData(0, CT_BRUSHES, CHANGE_INDEX_SENSITIVITY, FALSE, &theApp.m_fCurrentTerrainBrush, NULL);
- ptib->SetFunctions( RenderBrushShape, NULL, ChangeData, InvokeBrushPalette);
- ptib=AddButton(dcButtons,0,52,LAYER_START_X,8,-1,-1, "Brush pressure (keys 0-10)");
- ptib->SetData(0, 1024.0f, CHANGE_PREASSURE_SENSITIVITY, FALSE, &theApp.m_fTerrainBrushPressure, NULL);
- ptib->SetFunctions( RenderBrushPressure, NULL, ChangeData, InvokePercentageCombo, NULL, UpdatePressure);
- ptib=AddButton(dcButtons,6,64,16,16,-1,19, "Edit mode");
- ptib->SetData(0, CT_EDIT_MODES, CHANGE_INDEX_SENSITIVITY, FALSE, &theApp.m_iTerrainEditMode, NULL);
- UpdateEditModeIcon(ptib, NULL);
- ptib->SetFunctions( NULL, NULL, ChangeData, InvokeEditModeCombo, NULL, UpdateEditModeIcon);
-
- ptib=AddButton(dcButtons,28,64,16,16,-1,-1, "Brush mode");
- ptib->SetData(0, CT_BRUSH_MODES-0.5f, CHANGE_INDEX_SENSITIVITY, FALSE, &theApp.m_iTerrainBrushMode, NULL);
- UpdateBrushModeIcon(ptib, NULL);
- ptib->SetFunctions( NULL, NULL, ChangeData, InvokeBrushModeCombo, NULL, UpdateBrushModeIcon);
- /*
- ptib=AddButton(dcButtons,6,84,16,16,-1,5, "Recalculate shadows (Ctrl+R)");
- ptib->SetFunctions( NULL, RecalculateShadows);
- ptib->tib_pIsEnabled=DisableIfNoTerrainSelected;
- */
- ptib=AddButton(dcButtons,28,84,16,16,-1,25, "Terrain options");
- ptib->SetFunctions( NULL, NULL, NULL, InvokeTerrainOptions);
- ptib->tib_pIsEnabled=DisableIfNoTerrainSelected;
- /*
- ptib=AddButton(dcButtons,6,104,16,16,-1,6, "Generate layer distribution (Ctrl+G)");
- ptib->SetFunctions( NULL, GenerateLayerDistribution);
- ptib->tib_pIsEnabled=DisableIfNoTerrainSelected;
- */
- ptib=AddButton(dcButtons,6,84,16,16,-1,22, "Import/Export");
- ptib->SetFunctions( NULL, NULL, NULL, InvokeImportExportCombo);
- ptib->tib_pIsEnabled=DisableIfNoTerrainSelected;
- CTerrain *ptrTerrain=GetTerrain();
- if( ptrTerrain!=NULL)
- {
- for(INDEX iLayer=0; iLayer<ptrTerrain->tr_atlLayers.Count(); iLayer++)
- {
- CTerrainLayer &tlLayer=ptrTerrain->tr_atlLayers[iLayer];
- ptib=AddButton(dcButtons,0,0,GetLayerSize(pdp)(1)-SLIDER_WIDTH,
- GetLayerSize(pdp)(2),iLayer,-1, "_Layer options area bcg");
- ptib->SetFunctions( RenderLayerBcg, SetAsActiveLayer, NULL, SetAsActiveLayer);
- ptib->tib_bContinueTesting=TRUE;
- ptib=AddButton(dcButtons,
- LAYER_SPACING_V/2, LAYER_SPACING_V/2,
- LAYER_HEIGHT-LAYER_SPACING_V/2-1, LAYER_HEIGHT-LAYER_SPACING_V/2-1, iLayer,-1, "Layer texture",
- C_BLACK|CT_OPAQUE);
- ptib->SetFunctions( RenderLayerTexture, NULL, NULL, InvokeLayerTexturePopup);
- ptib->tib_pOnDropFiles=OnDropIntoLayerTexture;
- ptib=AddButton(dcButtons, LAYER_SPACING_V/2, LAYER_SPACING_V/2, 16, 16, iLayer, -1, "Layer visibility");
- UpdateLayerVisibleFlag(ptib, NULL);
- ptib->tib_pfData1=(FLOAT*)offsetof(CTerrainLayer, tl_bVisible);
- ptib->SetFunctions( NULL, ToggleLayerVisibleFlag, NULL, NULL, NULL, UpdateLayerVisibleFlag);
- ptib=AddButton(dcButtons,
- LAYER_HEIGHT, LAYER_SPACING_V/2,
- LAYER_HEIGHT-LAYER_SPACING_V/2-1, LAYER_HEIGHT-LAYER_SPACING_V/2-1, iLayer,-1, "Layer mask",
- C_BLACK|CT_OPAQUE);
- ptib->SetFunctions( RenderLayerMask, NULL, NULL, InvokeLayerMaskPopup);
- if(tlLayer.tl_ltType==LT_NORMAL)
- {
- ptib=AddButton(dcButtons, LAYER_HEIGHT*2,2,16,16,iLayer,0, "Rotate texture");
- ptib->SetFunctions( NULL, NULL, ChangeTextureRotation);
-
- ptib=AddButton(dcButtons, LAYER_HEIGHT*2,16,16,16,iLayer,2, "Stretch texture");
- ptib->SetFunctions( NULL, NULL, ChangeTextureStretch);
- ptib->tib_pGetClickMoveData=GetStretchInfo;
-
- ptib=AddButton(dcButtons, LAYER_HEIGHT*2,30,16,16,iLayer,1, "Offset texture");
- ptib->SetFunctions( NULL, NULL, ChangeTextureOffset);
-
- #define ICON_COVERAGE_X (LAYER_HEIGHT*2+16)
- #define ICON_FILTER_X (LAYER_HEIGHT*2+40)
- #define ICON_FADE_X (ICON_FILTER_X+16)
- #define ICON_NOISE_X (ICON_FADE_X+16)
- #define ICON_SLOPE_OFFSET 56
- #define ICON_LINE1_Y 6
- #define ICON_LINE2_Y 26
- ptib=AddButton(dcButtons, ICON_COVERAGE_X,ICON_LINE1_Y,16,16,iLayer,17, "Layer coverage");
- ptib->SetData(0, 1, CHANGE_NORMALIZED_SENSITIVITY, FALSE, (FLOAT*)offsetof(CTerrainLayer, tl_fCoverage));
- ptib->SetFunctions( NULL, NULL, ChangeLayerDistributionData);
- ptib->tib_pGetClickMoveData=GetNormalizedPercentageInfo;
- ptib=AddButton(dcButtons, ICON_COVERAGE_X,ICON_LINE2_Y,16,16,iLayer,21, "Layer coverage noise");
- ptib->SetData(0, 1, CHANGE_NORMALIZED_SENSITIVITY, FALSE, (FLOAT*)offsetof(CTerrainLayer, tl_fCoverageNoise));
- ptib->SetFunctions( NULL, NULL, ChangeLayerDistributionData);
- ptib->tib_pGetClickMoveData=GetNormalizedPercentageInfo;
- ptib=AddButton(dcButtons, ICON_FILTER_X, ICON_LINE1_Y,16,16,iLayer,14, "Max altitude");
- ptib->SetData(0, 1, CHANGE_NORMALIZED_SENSITIVITY, FALSE, (FLOAT*)offsetof(CTerrainLayer, tl_fMaxAltitude));
- ptib->SetFunctions( NULL, NULL, ChangeLayerDistributionData);
- ptib->tib_pGetClickMoveData=GetNormalizedPercentageInfo;
- ptib=AddButton(dcButtons, ICON_FADE_X, ICON_LINE1_Y,16,16,iLayer,29, "Max altitude fade");
- ptib->SetFunctions( NULL, NULL, ChangeLayerDistributionData);
- ptib->tib_pGetClickMoveData=GetNormalizedPercentageInfo;
- ptib->SetData(0, 1, CHANGE_NORMALIZED_SENSITIVITY, FALSE, (FLOAT*)offsetof(CTerrainLayer, tl_fMaxAltitudeFade));
- ptib=AddButton(dcButtons, ICON_NOISE_X, ICON_LINE1_Y,16,16,iLayer,21, "Max altitude noise");
- ptib->SetData(0, 1, CHANGE_NORMALIZED_SENSITIVITY, FALSE, (FLOAT*)offsetof(CTerrainLayer, tl_fMaxAltitudeNoise));
- ptib->SetFunctions( NULL, NULL, ChangeLayerDistributionData);
- ptib->tib_pGetClickMoveData=GetNormalizedPercentageInfo;
-
- ptib=AddButton(dcButtons, ICON_FILTER_X, ICON_LINE2_Y,16,16,iLayer,13, "Min altitude");
- ptib->SetData(0, 1, CHANGE_NORMALIZED_SENSITIVITY, FALSE, (FLOAT*)offsetof(CTerrainLayer, tl_fMinAltitude));
- ptib->SetFunctions( NULL, NULL, ChangeLayerDistributionData);
- ptib->tib_pGetClickMoveData=GetNormalizedPercentageInfo;
- ptib=AddButton(dcButtons, ICON_FADE_X, ICON_LINE2_Y,16,16,iLayer,29, "Min altitude fade");
- ptib->SetData(0, 1, CHANGE_NORMALIZED_SENSITIVITY, FALSE, (FLOAT*)offsetof(CTerrainLayer, tl_fMinAltitudeFade));
- ptib->SetFunctions( NULL, NULL, ChangeLayerDistributionData);
- ptib->tib_pGetClickMoveData=GetNormalizedPercentageInfo;
- ptib=AddButton(dcButtons, ICON_NOISE_X, ICON_LINE2_Y,16,16,iLayer,21, "Min altitude noise");
- ptib->SetData(0, 1, CHANGE_NORMALIZED_SENSITIVITY, FALSE, (FLOAT*)offsetof(CTerrainLayer, tl_fMinAltitudeNoise));
- ptib->SetFunctions( NULL, NULL, ChangeLayerDistributionData);
- ptib->tib_pGetClickMoveData=GetNormalizedPercentageInfo;
-
- ptib=AddButton(dcButtons, ICON_FILTER_X+ICON_SLOPE_OFFSET, ICON_LINE1_Y,16,16,iLayer,16, "Max slope");
- ptib->SetData(0, 1, CHANGE_NORMALIZED_SENSITIVITY, FALSE, (FLOAT*)offsetof(CTerrainLayer, tl_fMaxSlope));
- ptib->SetFunctions( NULL, NULL, ChangeLayerDistributionData);
- ptib->tib_pGetClickMoveData=GetNormalizedPercentageInfo;
- ptib=AddButton(dcButtons, ICON_FADE_X+ICON_SLOPE_OFFSET, ICON_LINE1_Y,16,16,iLayer,29, "Max slope fade");
- ptib->SetData(0, 1, CHANGE_NORMALIZED_SENSITIVITY, FALSE, (FLOAT*)offsetof(CTerrainLayer, tl_fMaxSlopeFade));
- ptib->SetFunctions( NULL, NULL, ChangeLayerDistributionData);
- ptib->tib_pGetClickMoveData=GetNormalizedPercentageInfo;
- ptib=AddButton(dcButtons, ICON_NOISE_X+ICON_SLOPE_OFFSET, ICON_LINE1_Y,16,16,iLayer,21, "Max slope noise");
- ptib->SetData(0, 1, CHANGE_NORMALIZED_SENSITIVITY, FALSE, (FLOAT*)offsetof(CTerrainLayer, tl_fMaxSlopeNoise));
- ptib->SetFunctions( NULL, NULL, ChangeLayerDistributionData);
- ptib->tib_pGetClickMoveData=GetNormalizedPercentageInfo;
-
- ptib=AddButton(dcButtons, ICON_FILTER_X+ICON_SLOPE_OFFSET, ICON_LINE2_Y,16,16,iLayer,15, "Min slope");
- ptib->SetData(0, 1, CHANGE_NORMALIZED_SENSITIVITY, FALSE, (FLOAT*)offsetof(CTerrainLayer, tl_fMinSlope));
- ptib->SetFunctions( NULL, NULL, ChangeLayerDistributionData);
- ptib->tib_pGetClickMoveData=GetNormalizedPercentageInfo;
- ptib=AddButton(dcButtons, ICON_FADE_X+ICON_SLOPE_OFFSET, ICON_LINE2_Y,16,16,iLayer,29, "Min slope fade");
- ptib->SetData(0, 1, CHANGE_NORMALIZED_SENSITIVITY, FALSE, (FLOAT*)offsetof(CTerrainLayer, tl_fMinSlopeFade));
- ptib->SetFunctions( NULL, NULL, ChangeLayerDistributionData);
- ptib->tib_pGetClickMoveData=GetNormalizedPercentageInfo;
- ptib=AddButton(dcButtons, ICON_NOISE_X+ICON_SLOPE_OFFSET, ICON_LINE2_Y,16,16,iLayer,21, "Min slope noise");
- ptib->SetData(0, 1, CHANGE_NORMALIZED_SENSITIVITY, FALSE, (FLOAT*)offsetof(CTerrainLayer, tl_fMinSlopeFade));
- ptib->SetFunctions( NULL, NULL, ChangeLayerDistributionData);
- ptib->tib_pGetClickMoveData=GetNormalizedPercentageInfo;
- ptib=AddButton(dcButtons, GetLayerSize(pdp)(1)-12-SLIDER_WIDTH-1-2,2,12,12,iLayer,-1, "Multiply color", C_BLACK|CT_OPAQUE);
- ptib->SetFunctions( RenderLayerColor, PickLayerColor, NULL, NumericAlpha);
- ptib=AddButton(dcButtons, GetLayerSize(pdp)(1)-16-SLIDER_WIDTH-1,GetLayerSize(pdp)(2)-20,16,16,iLayer,26, "Layer options (Ctrl+Shift+L)");
- ptib->SetFunctions( NULL, InvokeLayerOptions);
- }
- else if(tlLayer.tl_ltType==LT_TILE)
- {
- }
- ptib=AddButton(dcButtons,0,0,GetLayerSize(pdp)(1)-SLIDER_WIDTH-1,GetLayerSize(pdp)(2),iLayer,-1, "_Layer options area border", C_GRAY|CT_OPAQUE);
- // _Layer click detector
- ptib=AddButton(dcButtons,0,0,GetLayerSize(pdp)(1)-SLIDER_WIDTH,
- GetLayerSize(pdp)(2),iLayer,-1, "_Layer click detector");
- ptib->SetFunctions( NULL, NULL, NULL, InvokeLayerPopup);
- }
- }
- //slider
- ptib=AddButton(dcButtons,pdp->GetWidth()-SLIDER_WIDTH, 0, SLIDER_WIDTH, SLIDER_WIDTH, -1, 23, "_Slider arrow up", C_GRAY|CT_OPAQUE, C_mdGRAY|CT_OPAQUE);
- ptib->SetFunctions(NULL,OnSliderArrowUp);
- ptib=AddButton(dcButtons,pdp->GetWidth()-SLIDER_WIDTH, pdp->GetHeight()-SLIDER_WIDTH, SLIDER_WIDTH, SLIDER_WIDTH, -1, 24, "_Slider arrow down", C_GRAY|CT_OPAQUE, C_mdGRAY|CT_OPAQUE);
- ptib->SetFunctions(NULL,OnSliderArrowDown);
- ptib=AddButton(dcButtons,pdp->GetWidth()-SLIDER_WIDTH, SLIDER_WIDTH, SLIDER_WIDTH, pdp->GetHeight()-SLIDER_WIDTH*2, -1,-1, "_Slider rect", C_dGRAY|CT_OPAQUE, colBcg);
- ptib->SetFunctions(RenderSlider,OnSliderClick, DragSlider);
- ptib->tib_bMouseTrapForMove=FALSE;
- }
|