XYWnd.cpp 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. // XYWnd.cpp : implementation file
  19. //
  20. // QERadiant
  21. //
  22. //
  23. #include "stdafx.h"
  24. #include "Radiant.h"
  25. #include "XYWnd.h"
  26. #include "qe3.h"
  27. #include "PrefsDlg.h"
  28. #include "DialogInfo.h"
  29. #include "splines/splines.h"
  30. #ifdef _DEBUG
  31. #define new DEBUG_NEW
  32. #undef THIS_FILE
  33. static char THIS_FILE[] = __FILE__;
  34. #endif
  35. #define PAGEFLIPS 2
  36. const char* g_pDimStrings[] = {"x:%.f", "y:%.f", "z:%.f"};
  37. const char* g_pOrgStrings[] = {"(x:%.f y:%.f)", "(x:%.f z:%.f)", "(y:%.f z:%.f)"};
  38. CString g_strDim;
  39. CString g_strStatus;
  40. bool g_bCrossHairs = false;
  41. bool g_bScaleMode;
  42. int g_nScaleHow;
  43. bool g_bRotateMode;
  44. bool g_bClipMode;
  45. bool g_bRogueClipMode;
  46. bool g_bSwitch;
  47. CClipPoint g_Clip1;
  48. CClipPoint g_Clip2;
  49. CClipPoint g_Clip3;
  50. CClipPoint* g_pMovingClip;
  51. brush_t g_brFrontSplits;
  52. brush_t g_brBackSplits;
  53. brush_t g_brClipboard;
  54. brush_t g_brUndo;
  55. entity_t g_enClipboard;
  56. vec3_t g_vRotateOrigin;
  57. vec3_t g_vRotation;
  58. bool g_bPathMode;
  59. CClipPoint g_PathPoints[256];
  60. CClipPoint* g_pMovingPath;
  61. int g_nPathCount;
  62. int g_nPathLimit;
  63. bool g_bSmartGo;
  64. bool g_bPointMode;
  65. CClipPoint g_PointPoints[512];
  66. CClipPoint* g_pMovingPoint;
  67. int g_nPointCount;
  68. int g_nPointLimit;
  69. const int XY_LEFT = 0x01;
  70. const int XY_RIGHT = 0x02;
  71. const int XY_UP = 0x04;
  72. const int XY_DOWN = 0x08;
  73. PFNPathCallback* g_pPathFunc = NULL;
  74. void AcquirePath(int nCount, PFNPathCallback* pFunc)
  75. {
  76. g_nPathCount = 0;
  77. g_nPathLimit = nCount;
  78. g_pPathFunc = pFunc;
  79. g_bPathMode = true;
  80. }
  81. CPtrArray g_ptrMenus;
  82. CMemFile g_Clipboard(4096);
  83. CMemFile g_PatchClipboard(4096);
  84. extern int pressx;
  85. extern int pressy;
  86. /////////////////////////////////////////////////////////////////////////////
  87. // CXYWnd
  88. IMPLEMENT_DYNCREATE(CXYWnd, CWnd);
  89. CXYWnd::CXYWnd()
  90. {
  91. g_brClipboard.next = &g_brClipboard;
  92. g_brUndo.next = &g_brUndo;
  93. g_nScaleHow = 0;
  94. g_bRotateMode = false;
  95. g_bClipMode = false;
  96. g_bRogueClipMode = false;
  97. g_bSwitch = true;
  98. g_pMovingClip = NULL;
  99. g_pMovingPath = NULL;
  100. g_brFrontSplits.next = &g_brFrontSplits;
  101. g_brBackSplits.next = &g_brBackSplits;
  102. m_bActive = false;
  103. //m_bTiming = true;
  104. m_bTiming = false;
  105. m_bRButtonDown = false;
  106. m_nUpdateBits = W_XY;
  107. g_bPathMode = false;
  108. g_nPathCount = 0;
  109. g_nPathLimit = 0;
  110. m_nTimerID = -1;
  111. XY_Init();
  112. }
  113. CXYWnd::~CXYWnd()
  114. {
  115. int nSize = g_ptrMenus.GetSize();
  116. while (nSize > 0)
  117. {
  118. CMenu* pMenu = reinterpret_cast<CMenu*>(g_ptrMenus.GetAt(nSize-1));
  119. ASSERT(pMenu);
  120. pMenu->DestroyMenu();
  121. delete pMenu;
  122. nSize--;
  123. }
  124. g_ptrMenus.RemoveAll();
  125. m_mnuDrop.DestroyMenu();
  126. }
  127. BEGIN_MESSAGE_MAP(CXYWnd, CWnd)
  128. //{{AFX_MSG_MAP(CXYWnd)
  129. ON_WM_CREATE()
  130. ON_WM_LBUTTONDOWN()
  131. ON_WM_MBUTTONDOWN()
  132. ON_WM_RBUTTONDOWN()
  133. ON_WM_LBUTTONUP()
  134. ON_WM_MBUTTONUP()
  135. ON_WM_RBUTTONUP()
  136. ON_WM_MOUSEMOVE()
  137. ON_WM_PAINT()
  138. ON_WM_KEYDOWN()
  139. ON_WM_SIZE()
  140. ON_WM_DESTROY()
  141. ON_COMMAND(ID_SELECT_MOUSEROTATE, OnSelectMouserotate)
  142. ON_WM_TIMER()
  143. ON_WM_KEYUP()
  144. ON_WM_NCCALCSIZE()
  145. ON_WM_KILLFOCUS()
  146. ON_WM_SETFOCUS()
  147. ON_WM_CLOSE()
  148. ON_COMMAND(ID_SELECTION_MAKE_DETAIL, CMainFrame::OnSelectionMakeDetail)
  149. ON_COMMAND(ID_SELECTION_MAKE_STRUCTURAL, CMainFrame::OnSelectionMakeStructural)
  150. ON_COMMAND(ID_SELECTION_SELECTCOMPLETETALL, CMainFrame::OnSelectionSelectcompletetall)
  151. ON_COMMAND(ID_SELECTION_SELECTINSIDE, CMainFrame::OnSelectionSelectinside)
  152. ON_COMMAND(ID_SELECTION_SELECTPARTIALTALL, CMainFrame::OnSelectionSelectpartialtall)
  153. ON_COMMAND(ID_SELECTION_SELECTTOUCHING, CMainFrame::OnSelectionSelecttouching)
  154. ON_COMMAND(ID_SELECTION_UNGROUPENTITY, CMainFrame::OnSelectionUngroupentity)
  155. //}}AFX_MSG_MAP
  156. ON_COMMAND_RANGE(ID_ENTITY_START, ID_ENTITY_END, OnEntityCreate)
  157. END_MESSAGE_MAP()
  158. /////////////////////////////////////////////////////////////////////////////
  159. // CXYWnd message handlers
  160. LONG WINAPI XYWndProc(HWND, UINT, WPARAM, LPARAM);
  161. BOOL CXYWnd::PreCreateWindow(CREATESTRUCT& cs)
  162. {
  163. WNDCLASS wc;
  164. HINSTANCE hInstance = AfxGetInstanceHandle();
  165. if (::GetClassInfo(hInstance, XY_WINDOW_CLASS, &wc) == FALSE)
  166. {
  167. // Register a new class
  168. memset (&wc, 0, sizeof(wc));
  169. wc.style = CS_NOCLOSE | CS_OWNDC;
  170. wc.lpszClassName = XY_WINDOW_CLASS;
  171. wc.hCursor = NULL; //LoadCursor (NULL,IDC_ARROW);
  172. wc.lpfnWndProc = ::DefWindowProc;
  173. if (AfxRegisterClass(&wc) == FALSE)
  174. Error ("CCamWnd RegisterClass: failed");
  175. }
  176. cs.lpszClass = XY_WINDOW_CLASS;
  177. cs.lpszName = "VIEW";
  178. if (cs.style != QE3_CHILDSTYLE)
  179. cs.style = QE3_SPLITTER_STYLE;
  180. return CWnd::PreCreateWindow(cs);
  181. }
  182. HDC s_hdcXY;
  183. HGLRC s_hglrcXY;
  184. static unsigned s_stipple[32] =
  185. {
  186. 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  187. 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  188. 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  189. 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  190. 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  191. 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  192. 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  193. 0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  194. };
  195. /*
  196. ============
  197. WXY_WndProc
  198. ============
  199. */
  200. LONG WINAPI XYWndProc (
  201. HWND hWnd,
  202. UINT uMsg,
  203. WPARAM wParam,
  204. LPARAM lParam)
  205. {
  206. switch (uMsg)
  207. {
  208. case WM_DESTROY:
  209. QEW_StopGL( hWnd, s_hglrcXY, s_hdcXY );
  210. return 0;
  211. case WM_NCCALCSIZE:// don't let windows copy pixels
  212. DefWindowProc (hWnd, uMsg, wParam, lParam);
  213. return WVR_REDRAW;
  214. case WM_KILLFOCUS:
  215. case WM_SETFOCUS:
  216. SendMessage( hWnd, WM_NCACTIVATE, uMsg == WM_SETFOCUS, 0 );
  217. return 0;
  218. case WM_CLOSE:
  219. DestroyWindow (hWnd);
  220. return 0;
  221. }
  222. return DefWindowProc (hWnd, uMsg, wParam, lParam);
  223. }
  224. static void WXY_InitPixelFormat( PIXELFORMATDESCRIPTOR *pPFD )
  225. {
  226. memset( pPFD, 0, sizeof( *pPFD ) );
  227. pPFD->nSize = sizeof( PIXELFORMATDESCRIPTOR );
  228. pPFD->nVersion = 1;
  229. pPFD->dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
  230. pPFD->iPixelType = PFD_TYPE_RGBA;
  231. pPFD->cColorBits = 24;
  232. pPFD->cDepthBits = 32;
  233. pPFD->iLayerType = PFD_MAIN_PLANE;
  234. }
  235. void WXY_Print( void )
  236. {
  237. DOCINFO di;
  238. PRINTDLG pd;
  239. /*
  240. ** initialize the PRINTDLG struct and execute it
  241. */
  242. memset( &pd, 0, sizeof( pd ) );
  243. pd.lStructSize = sizeof( pd );
  244. pd.hwndOwner = g_qeglobals.d_hwndXY;
  245. pd.Flags = PD_RETURNDC;
  246. pd.hInstance = 0;
  247. if ( !PrintDlg( &pd ) || !pd.hDC )
  248. {
  249. MessageBox( g_qeglobals.d_hwndMain, "Could not PrintDlg()", "QE4 Print Error", MB_OK | MB_ICONERROR );
  250. return;
  251. }
  252. /*
  253. ** StartDoc
  254. */
  255. memset( &di, 0, sizeof( di ) );
  256. di.cbSize = sizeof( di );
  257. di.lpszDocName = "QE4";
  258. if ( StartDoc( pd.hDC, &di ) <= 0 )
  259. {
  260. MessageBox( g_qeglobals.d_hwndMain, "Could not StartDoc()", "QE4 Print Error", MB_OK | MB_ICONERROR );
  261. return;
  262. }
  263. /*
  264. ** StartPage
  265. */
  266. if ( StartPage( pd.hDC ) <= 0 )
  267. {
  268. MessageBox( g_qeglobals.d_hwndMain, "Could not StartPage()", "QE4 Print Error", MB_OK | MB_ICONERROR );
  269. return;
  270. }
  271. /*
  272. ** read pixels from the XY window
  273. */
  274. {
  275. int bmwidth = 320, bmheight = 320;
  276. int pwidth, pheight;
  277. RECT r;
  278. GetWindowRect( g_qeglobals.d_hwndXY, &r );
  279. bmwidth = r.right - r.left;
  280. bmheight = r.bottom - r.top;
  281. pwidth = GetDeviceCaps( pd.hDC, PHYSICALWIDTH ) - GetDeviceCaps( pd.hDC, PHYSICALOFFSETX );
  282. pheight = GetDeviceCaps( pd.hDC, PHYSICALHEIGHT ) - GetDeviceCaps( pd.hDC, PHYSICALOFFSETY );
  283. StretchBlt( pd.hDC,
  284. 0, 0,
  285. pwidth, pheight,
  286. s_hdcXY,
  287. 0, 0,
  288. bmwidth, bmheight,
  289. SRCCOPY );
  290. }
  291. /*
  292. ** EndPage and EndDoc
  293. */
  294. if ( EndPage( pd.hDC ) <= 0 )
  295. {
  296. MessageBox( g_qeglobals.d_hwndMain, "QE4 Print Error", "Could not EndPage()", MB_OK | MB_ICONERROR );
  297. return;
  298. }
  299. if ( EndDoc( pd.hDC ) <= 0 )
  300. {
  301. MessageBox( g_qeglobals.d_hwndMain, "QE4 Print Error", "Could not EndDoc()", MB_OK | MB_ICONERROR );
  302. return;
  303. }
  304. }
  305. int CXYWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
  306. {
  307. if (CWnd::OnCreate(lpCreateStruct) == -1)
  308. return -1;
  309. s_hdcXY = ::GetDC(GetSafeHwnd());
  310. QEW_SetupPixelFormat(s_hdcXY, false);
  311. if ( ( s_hglrcXY = qwglCreateContext( s_hdcXY ) ) == 0 )
  312. Error( "wglCreateContext in WXY_WndProc failed" );
  313. if (!qwglShareLists( g_qeglobals.d_hglrcBase, s_hglrcXY ) )
  314. Error( "wglShareLists in WXY_WndProc failed" );
  315. if (!qwglMakeCurrent( s_hdcXY, s_hglrcXY ))
  316. Error ("wglMakeCurrent failed");
  317. qglPolygonStipple ((unsigned char *)s_stipple);
  318. qglLineStipple (3, 0xaaaa);
  319. g_qeglobals.d_hwndXY = GetSafeHwnd();
  320. return 0;
  321. }
  322. float ptSum(vec3_t pt)
  323. {
  324. return pt[0] + pt[1] + pt[2];
  325. }
  326. void CXYWnd::DropClipPoint(UINT nFlags, CPoint point)
  327. {
  328. CRect rctZ;
  329. GetClientRect(rctZ);
  330. if (g_pMovingClip)
  331. {
  332. SetCapture();
  333. SnapToPoint (point.x, rctZ.Height() - 1 - point.y , *g_pMovingClip);
  334. }
  335. else
  336. {
  337. vec3_t* pPt = NULL;
  338. if (g_Clip1.Set() == false)
  339. {
  340. pPt = g_Clip1;
  341. g_Clip1.Set(true);
  342. g_Clip1.m_ptScreen = point;
  343. }
  344. else
  345. if (g_Clip2.Set() == false)
  346. {
  347. pPt = g_Clip2;
  348. g_Clip2.Set(true);
  349. g_Clip2.m_ptScreen = point;
  350. }
  351. else
  352. if (g_Clip3.Set() == false)
  353. {
  354. pPt = g_Clip3;
  355. g_Clip3.Set(true);
  356. g_Clip3.m_ptScreen = point;
  357. }
  358. else
  359. {
  360. RetainClipMode(true);
  361. pPt = g_Clip1;
  362. g_Clip1.Set(true);
  363. g_Clip1.m_ptScreen = point;
  364. }
  365. SnapToPoint (point.x, rctZ.Height() - 1 - point.y , *pPt);
  366. }
  367. Sys_UpdateWindows(XY | W_CAMERA_IFON);
  368. }
  369. void CXYWnd::DropPathPoint(UINT nFlags, CPoint point)
  370. {
  371. CRect rctZ;
  372. GetClientRect(rctZ);
  373. if (g_pMovingPath)
  374. {
  375. SetCapture();
  376. SnapToPoint (point.x, rctZ.Height() - 1 - point.y , *g_pMovingPath);
  377. }
  378. else
  379. {
  380. g_PathPoints[g_nPathCount].Set(true);
  381. g_PathPoints[g_nPathCount].m_ptScreen = point;
  382. SnapToPoint(point.x, rctZ.Height() - 1 - point.y, g_PathPoints[g_nPathCount]);
  383. g_nPathCount++;
  384. if (g_nPathCount == g_nPathLimit)
  385. {
  386. if (g_pPathFunc)
  387. g_pPathFunc(true, g_nPathCount);
  388. g_nPathCount = 0;
  389. g_bPathMode = false;
  390. g_pPathFunc = NULL;
  391. }
  392. }
  393. Sys_UpdateWindows(XY | W_CAMERA_IFON);
  394. }
  395. void CXYWnd::AddPointPoint(UINT nFlags, vec3_t* pVec)
  396. {
  397. g_PointPoints[g_nPointCount].Set(true);
  398. //g_PointPoints[g_nPointCount].m_ptScreen = point;
  399. _VectorCopy(*pVec, g_PointPoints[g_nPointCount]);
  400. g_PointPoints[g_nPointCount].SetPointPtr(pVec);
  401. g_nPointCount++;
  402. Sys_UpdateWindows(XY | W_CAMERA_IFON);
  403. }
  404. void CXYWnd::OnLButtonDown(UINT nFlags, CPoint point)
  405. {
  406. g_pParentWnd->SetActiveXY(this);
  407. UndoCopy();
  408. // plugin entities
  409. if (DispatchOnLButtonDown(nFlags, point.x, point.y ))
  410. return;
  411. if (ClipMode() && !RogueClipMode())
  412. {
  413. DropClipPoint(nFlags, point);
  414. }
  415. else if (PathMode())
  416. {
  417. DropPathPoint(nFlags, point);
  418. }
  419. else OriginalButtonDown(nFlags, point);
  420. }
  421. void CXYWnd::OnMButtonDown(UINT nFlags, CPoint point)
  422. {
  423. OriginalButtonDown(nFlags, point);
  424. }
  425. float Betwixt(float f1, float f2)
  426. {
  427. if (f1 > f2)
  428. return f2 + ((f1 - f2) / 2);
  429. else
  430. return f1 + ((f2 - f1) / 2);
  431. }
  432. void CXYWnd::ProduceSplits(brush_t** pFront, brush_t** pBack)
  433. {
  434. *pFront = NULL;
  435. *pBack = NULL;
  436. if (ClipMode())
  437. {
  438. if (g_Clip1.Set() && g_Clip2.Set())
  439. {
  440. face_t face;
  441. VectorCopy(g_Clip1.m_ptClip,face.planepts[0]);
  442. VectorCopy(g_Clip2.m_ptClip,face.planepts[1]);
  443. VectorCopy(g_Clip3.m_ptClip,face.planepts[2]);
  444. if (selected_brushes.next && (selected_brushes.next->next == &selected_brushes))
  445. {
  446. if (g_Clip3.Set() == false)
  447. {
  448. if (m_nViewType == XY)
  449. {
  450. face.planepts[0][2] = selected_brushes.next->mins[2];
  451. face.planepts[1][2] = selected_brushes.next->mins[2];
  452. face.planepts[2][0] = Betwixt(g_Clip1.m_ptClip[0], g_Clip2.m_ptClip[0]);
  453. face.planepts[2][1] = Betwixt(g_Clip1.m_ptClip[1], g_Clip2.m_ptClip[1]);
  454. face.planepts[2][2] = selected_brushes.next->maxs[2];
  455. }
  456. else if (m_nViewType == YZ)
  457. {
  458. face.planepts[0][0] = selected_brushes.next->mins[0];
  459. face.planepts[1][0] = selected_brushes.next->mins[0];
  460. face.planepts[2][1] = Betwixt(g_Clip1.m_ptClip[1], g_Clip2.m_ptClip[1]);
  461. face.planepts[2][2] = Betwixt(g_Clip1.m_ptClip[2], g_Clip2.m_ptClip[2]);
  462. face.planepts[2][0] = selected_brushes.next->maxs[0];
  463. }
  464. else
  465. {
  466. face.planepts[0][1] = selected_brushes.next->mins[1];
  467. face.planepts[1][1] = selected_brushes.next->mins[1];
  468. face.planepts[2][0] = Betwixt(g_Clip1.m_ptClip[0], g_Clip2.m_ptClip[0]);
  469. face.planepts[2][2] = Betwixt(g_Clip1.m_ptClip[2], g_Clip2.m_ptClip[2]);
  470. face.planepts[2][1] = selected_brushes.next->maxs[1];
  471. }
  472. }
  473. Brush_SplitBrushByFace (selected_brushes.next, &face, pFront, pBack);
  474. }
  475. }
  476. }
  477. }
  478. void CleanList(brush_t* pList)
  479. {
  480. brush_t* pBrush = pList->next;
  481. while (pBrush != NULL && pBrush != pList)
  482. {
  483. brush_t* pNext = pBrush->next;
  484. Brush_Free(pBrush);
  485. pBrush = pNext;
  486. }
  487. }
  488. void CXYWnd::ProduceSplitLists()
  489. {
  490. if (AnyPatchesSelected())
  491. {
  492. Sys_Printf("Deslecting patches for clip operation.\n");
  493. brush_t *next;
  494. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = next)
  495. {
  496. next = pb->next;
  497. if (pb->patchBrush)
  498. {
  499. Brush_RemoveFromList (pb);
  500. Brush_AddToList (pb, &active_brushes);
  501. UpdatePatchInspector();
  502. }
  503. if (pb->terrainBrush)
  504. {
  505. Brush_RemoveFromList (pb);
  506. Brush_AddToList (pb, &active_brushes);
  507. UpdateTerrainInspector();
  508. }
  509. }
  510. }
  511. CleanList(&g_brFrontSplits);
  512. CleanList(&g_brBackSplits);
  513. g_brFrontSplits.next = &g_brFrontSplits;
  514. g_brBackSplits.next = &g_brBackSplits;
  515. brush_t* pBrush;
  516. for (pBrush = selected_brushes.next ; pBrush != NULL && pBrush != &selected_brushes ; pBrush=pBrush->next)
  517. {
  518. brush_t* pFront = NULL;
  519. brush_t* pBack = NULL;
  520. if (ClipMode())
  521. {
  522. if (g_Clip1.Set() && g_Clip2.Set())
  523. {
  524. face_t face;
  525. VectorCopy(g_Clip1.m_ptClip,face.planepts[0]);
  526. VectorCopy(g_Clip2.m_ptClip,face.planepts[1]);
  527. VectorCopy(g_Clip3.m_ptClip,face.planepts[2]);
  528. if (g_Clip3.Set() == false)
  529. {
  530. if (g_pParentWnd->ActiveXY()->GetViewType() == XY)
  531. {
  532. face.planepts[0][2] = pBrush->mins[2];
  533. face.planepts[1][2] = pBrush->mins[2];
  534. face.planepts[2][0] = Betwixt(g_Clip1.m_ptClip[0], g_Clip2.m_ptClip[0]);
  535. face.planepts[2][1] = Betwixt(g_Clip1.m_ptClip[1], g_Clip2.m_ptClip[1]);
  536. face.planepts[2][2] = pBrush->maxs[2];
  537. }
  538. else if (g_pParentWnd->ActiveXY()->GetViewType() == YZ)
  539. {
  540. face.planepts[0][0] = pBrush->mins[0];
  541. face.planepts[1][0] = pBrush->mins[0];
  542. face.planepts[2][1] = Betwixt(g_Clip1.m_ptClip[1], g_Clip2.m_ptClip[1]);
  543. face.planepts[2][2] = Betwixt(g_Clip1.m_ptClip[2], g_Clip2.m_ptClip[2]);
  544. face.planepts[2][0] = pBrush->maxs[0];
  545. }
  546. else
  547. {
  548. face.planepts[0][1] = pBrush->mins[1];
  549. face.planepts[1][1] = pBrush->mins[1];
  550. face.planepts[2][0] = Betwixt(g_Clip1.m_ptClip[0], g_Clip2.m_ptClip[0]);
  551. face.planepts[2][2] = Betwixt(g_Clip1.m_ptClip[2], g_Clip2.m_ptClip[2]);
  552. face.planepts[2][1] = pBrush->maxs[1];
  553. }
  554. }
  555. Brush_SplitBrushByFace (pBrush, &face, &pFront, &pBack);
  556. if (pBack)
  557. Brush_AddToList(pBack, &g_brBackSplits);
  558. if (pFront)
  559. Brush_AddToList(pFront, &g_brFrontSplits);
  560. }
  561. }
  562. }
  563. }
  564. void Brush_CopyList (brush_t* pFrom, brush_t* pTo)
  565. {
  566. brush_t* pBrush = pFrom->next;
  567. while (pBrush != NULL && pBrush != pFrom)
  568. {
  569. brush_t* pNext = pBrush->next;
  570. Brush_RemoveFromList(pBrush);
  571. Brush_AddToList(pBrush, pTo);
  572. pBrush = pNext;
  573. }
  574. }
  575. void CXYWnd::OnRButtonDown(UINT nFlags, CPoint point)
  576. {
  577. g_pParentWnd->SetActiveXY(this);
  578. m_ptDown = point;
  579. m_bRButtonDown = true;
  580. if (g_PrefsDlg.m_nMouseButtons == 3) // 3 button mouse
  581. {
  582. if ((GetKeyState(VK_CONTROL) & 0x8000))
  583. {
  584. if (ClipMode()) // already there?
  585. DropClipPoint(nFlags, point);
  586. else
  587. {
  588. SetClipMode(true);
  589. g_bRogueClipMode = true;
  590. DropClipPoint(nFlags, point);
  591. }
  592. return;
  593. }
  594. }
  595. OriginalButtonDown(nFlags, point);
  596. }
  597. void CXYWnd::OnLButtonUp(UINT nFlags, CPoint point)
  598. {
  599. // plugin entities
  600. if (DispatchOnLButtonUp(nFlags, point.x, point.y ))
  601. return;
  602. if (ClipMode())
  603. {
  604. if (g_pMovingClip)
  605. {
  606. ReleaseCapture();
  607. g_pMovingClip = NULL;
  608. }
  609. }
  610. OriginalButtonUp(nFlags, point);
  611. }
  612. void CXYWnd::OnMButtonUp(UINT nFlags, CPoint point)
  613. {
  614. OriginalButtonUp(nFlags, point);
  615. }
  616. void CXYWnd::OnRButtonUp(UINT nFlags, CPoint point)
  617. {
  618. m_bRButtonDown = false;
  619. if (point == m_ptDown) // mouse didn't move
  620. {
  621. bool bGo = true;
  622. if ((GetKeyState(VK_MENU) & 0x8000))
  623. bGo = false;
  624. if ((GetKeyState(VK_CONTROL) & 0x8000))
  625. bGo = false;
  626. if ((GetKeyState(VK_SHIFT) & 0x8000))
  627. bGo = false;
  628. if (bGo)
  629. HandleDrop();
  630. }
  631. OriginalButtonUp(nFlags, point);
  632. }
  633. void CXYWnd::OriginalButtonDown(UINT nFlags, CPoint point)
  634. {
  635. CRect rctZ;
  636. GetClientRect(rctZ);
  637. SetWindowPos(&wndTop, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
  638. if (::GetTopWindow( g_qeglobals.d_hwndMain ) != GetSafeHwnd())
  639. ::BringWindowToTop(GetSafeHwnd());
  640. SetFocus();
  641. SetCapture();
  642. XY_MouseDown (point.x, rctZ.Height() - 1 - point.y , nFlags);
  643. m_nScrollFlags = nFlags;
  644. }
  645. void CXYWnd::OriginalButtonUp(UINT nFlags, CPoint point)
  646. {
  647. CRect rctZ;
  648. GetClientRect(rctZ);
  649. XY_MouseUp (point.x, rctZ.Height() - 1 - point.y , nFlags);
  650. if (! (nFlags & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
  651. ReleaseCapture ();
  652. }
  653. float fDiff(float f1, float f2)
  654. {
  655. if (f1 > f2)
  656. return f1 - f2;
  657. else
  658. return f2 - f1;
  659. }
  660. vec3_t tdp;
  661. void CXYWnd::OnMouseMove(UINT nFlags, CPoint point)
  662. {
  663. // plugin entities
  664. //++timo TODO: handle return code
  665. DispatchOnMouseMove( nFlags, point.x, point.y );
  666. m_ptDown.x = 0;
  667. m_ptDown.y = 0;
  668. if ( g_PrefsDlg.m_bChaseMouse == TRUE &&
  669. (point.x < 0 || point.y < 0 ||
  670. point.x > m_nWidth || point.y > m_nHeight) &&
  671. GetCapture() == this)
  672. {
  673. float fAdjustment = (g_qeglobals.d_gridsize / 8 * 64) / m_fScale;
  674. //m_ptDrag = point;
  675. m_ptDragAdj.x = 0;
  676. m_ptDragAdj.y = 0;
  677. if (point.x < 0)
  678. {
  679. m_ptDragAdj.x = -fAdjustment;
  680. }
  681. else
  682. if (point.x > m_nWidth)
  683. {
  684. m_ptDragAdj.x = fAdjustment;
  685. }
  686. if (point.y < 0)
  687. {
  688. m_ptDragAdj.y = -fAdjustment;
  689. }
  690. else
  691. if (point.y > m_nHeight)
  692. {
  693. m_ptDragAdj.y = fAdjustment;
  694. }
  695. if (m_nTimerID == -1)
  696. {
  697. m_nTimerID = SetTimer(100, 50, NULL);
  698. m_ptDrag = point;
  699. m_ptDragTotal = 0;
  700. }
  701. return;
  702. }
  703. //else if (m_nTimerID != -1)
  704. if (m_nTimerID != -1)
  705. {
  706. KillTimer(m_nTimerID);
  707. pressx -= m_ptDragTotal.x;
  708. pressy += m_ptDragTotal.y;
  709. m_nTimerID = -1;
  710. //return;
  711. }
  712. bool bCrossHair = false;
  713. if (!m_bRButtonDown)
  714. {
  715. tdp[0] = tdp[1] = tdp[2] = 0.0;
  716. SnapToPoint (point.x, m_nHeight - 1 - point.y , tdp);
  717. g_strStatus.Format("x:: %.1f y:: %.1f z:: %.1f", tdp[0], tdp[1], tdp[2]);
  718. g_pParentWnd->SetStatusText(1, g_strStatus);
  719. // i need to generalize the point code.. having 3 flavors pretty much sucks..
  720. // once the new curve stuff looks like it is going to stick i will
  721. // rationalize this down to a single interface..
  722. if (PointMode())
  723. {
  724. if (g_pMovingPoint && GetCapture() == this)
  725. {
  726. bCrossHair = true;
  727. SnapToPoint (point.x, m_nHeight - 1 - point.y , g_pMovingPoint->m_ptClip);
  728. g_pMovingPoint->UpdatePointPtr();
  729. Sys_UpdateWindows(XY | W_CAMERA_IFON);
  730. }
  731. else
  732. {
  733. g_pMovingPoint = NULL;
  734. int nDim1 = (m_nViewType == YZ) ? 1 : 0;
  735. int nDim2 = (m_nViewType == XY) ? 1 : 2;
  736. for (int n = 0; n < g_nPointCount; n++)
  737. {
  738. if ( fDiff(g_PointPoints[n].m_ptClip[nDim1], tdp[nDim1]) < 3 &&
  739. fDiff(g_PointPoints[n].m_ptClip[nDim2], tdp[nDim2]) < 3 )
  740. {
  741. bCrossHair = true;
  742. g_pMovingPoint = &g_PointPoints[n];
  743. }
  744. }
  745. }
  746. }
  747. else if (ClipMode())
  748. {
  749. if (g_pMovingClip && GetCapture() == this)
  750. {
  751. bCrossHair = true;
  752. SnapToPoint (point.x, m_nHeight - 1 - point.y , g_pMovingClip->m_ptClip);
  753. Sys_UpdateWindows(XY | W_CAMERA_IFON);
  754. }
  755. else
  756. {
  757. g_pMovingClip = NULL;
  758. int nDim1 = (m_nViewType == YZ) ? 1 : 0;
  759. int nDim2 = (m_nViewType == XY) ? 1 : 2;
  760. if (g_Clip1.Set())
  761. {
  762. if ( fDiff(g_Clip1.m_ptClip[nDim1], tdp[nDim1]) < 3 &&
  763. fDiff(g_Clip1.m_ptClip[nDim2], tdp[nDim2]) < 3 )
  764. {
  765. bCrossHair = true;
  766. g_pMovingClip = &g_Clip1;
  767. }
  768. }
  769. if (g_Clip2.Set())
  770. {
  771. if ( fDiff(g_Clip2.m_ptClip[nDim1], tdp[nDim1]) < 3 &&
  772. fDiff(g_Clip2.m_ptClip[nDim2], tdp[nDim2]) < 3 )
  773. {
  774. bCrossHair = true;
  775. g_pMovingClip = &g_Clip2;
  776. }
  777. }
  778. if (g_Clip3.Set())
  779. {
  780. if ( fDiff(g_Clip3.m_ptClip[nDim1], tdp[nDim1]) < 3 &&
  781. fDiff(g_Clip3.m_ptClip[nDim2], tdp[nDim2]) < 3 )
  782. {
  783. bCrossHair = true;
  784. g_pMovingClip = &g_Clip3;
  785. }
  786. }
  787. }
  788. if (bCrossHair == false)
  789. XY_MouseMoved (point.x, m_nHeight - 1 - point.y , nFlags);
  790. }
  791. else if (PathMode())
  792. {
  793. if (g_pMovingPath && GetCapture() == this)
  794. {
  795. bCrossHair = true;
  796. SnapToPoint (point.x, m_nHeight - 1 - point.y , g_pMovingPath->m_ptClip);
  797. Sys_UpdateWindows(XY | W_CAMERA_IFON);
  798. }
  799. else
  800. {
  801. g_pMovingPath = NULL;
  802. int nDim1 = (m_nViewType == YZ) ? 1 : 0;
  803. int nDim2 = (m_nViewType == XY) ? 1 : 2;
  804. for (int n = 0; n < g_nPathCount; n++)
  805. {
  806. if ( fDiff(g_PathPoints[n].m_ptClip[nDim1], tdp[nDim1]) < 3 &&
  807. fDiff(g_PathPoints[n].m_ptClip[nDim2], tdp[nDim2]) < 3 )
  808. {
  809. bCrossHair = true;
  810. g_pMovingPath = &g_PathPoints[n];
  811. }
  812. }
  813. }
  814. }
  815. else
  816. {
  817. XY_MouseMoved (point.x, m_nHeight - 1 - point.y , nFlags);
  818. }
  819. }
  820. else
  821. {
  822. XY_MouseMoved (point.x, m_nHeight - 1 - point.y , nFlags);
  823. }
  824. if (bCrossHair)
  825. SetCursor(::LoadCursor(NULL, IDC_CROSS));
  826. else
  827. SetCursor(::LoadCursor(NULL, IDC_ARROW));
  828. }
  829. void CXYWnd::RetainClipMode(bool bMode)
  830. {
  831. bool bSave = g_bRogueClipMode;
  832. SetClipMode(bMode);
  833. if (bMode == true)
  834. g_bRogueClipMode = bSave;
  835. else
  836. g_bRogueClipMode = false;
  837. }
  838. void CXYWnd::SetClipMode(bool bMode)
  839. {
  840. g_bClipMode = bMode;
  841. g_bRogueClipMode = false;
  842. if (bMode)
  843. {
  844. g_Clip1.Reset();
  845. g_Clip2.Reset();
  846. g_Clip3.Reset();
  847. CleanList(&g_brFrontSplits);
  848. CleanList(&g_brBackSplits);
  849. g_brFrontSplits.next = &g_brFrontSplits;
  850. g_brBackSplits.next = &g_brBackSplits;
  851. }
  852. else
  853. {
  854. if (g_pMovingClip)
  855. {
  856. ReleaseCapture();
  857. g_pMovingClip = NULL;
  858. }
  859. CleanList(&g_brFrontSplits);
  860. CleanList(&g_brBackSplits);
  861. g_brFrontSplits.next = &g_brFrontSplits;
  862. g_brBackSplits.next = &g_brBackSplits;
  863. Sys_UpdateWindows(XY | W_CAMERA_IFON);
  864. }
  865. }
  866. bool CXYWnd::ClipMode()
  867. {
  868. return g_bClipMode;
  869. }
  870. bool CXYWnd::RogueClipMode()
  871. {
  872. return g_bRogueClipMode;
  873. }
  874. bool CXYWnd::PathMode()
  875. {
  876. return g_bPathMode;
  877. }
  878. bool CXYWnd::PointMode()
  879. {
  880. return g_bPointMode;
  881. }
  882. void CXYWnd::SetPointMode(bool b)
  883. {
  884. g_bPointMode = b;
  885. if (!b)
  886. g_nPointCount = 0;
  887. }
  888. void CXYWnd::OnPaint()
  889. {
  890. CPaintDC dc(this); // device context for painting
  891. bool bPaint = true;
  892. if (!qwglMakeCurrent(dc.m_hDC, s_hglrcXY))
  893. {
  894. Sys_Printf("ERROR: wglMakeCurrent failed.. Error:%i\n",qglGetError());
  895. Sys_Printf("Please restart Q3Radiant if the Map view is not working\n");
  896. bPaint = false;
  897. }
  898. if (bPaint)
  899. {
  900. QE_CheckOpenGLForErrors();
  901. XY_Draw ();
  902. QE_CheckOpenGLForErrors();
  903. if (m_nViewType != XY)
  904. {
  905. qglPushMatrix();
  906. if (m_nViewType == YZ)
  907. qglRotatef (-90, 0, 1, 0); // put Z going up
  908. qglRotatef (-90, 1, 0, 0); // put Z going up
  909. }
  910. if (g_bCrossHairs)
  911. {
  912. qglColor4f(0.2, 0.9, 0.2, 0.8);
  913. qglBegin (GL_LINES);
  914. if (m_nViewType == XY)
  915. {
  916. qglVertex2f(-16384, tdp[1]);
  917. qglVertex2f(16384, tdp[1]);
  918. qglVertex2f(tdp[0], -16384);
  919. qglVertex2f(tdp[0], 16384);
  920. }
  921. else if (m_nViewType == YZ)
  922. {
  923. qglVertex3f(tdp[0], -16384, tdp[2]);
  924. qglVertex3f(tdp[0], 16384, tdp[2]);
  925. qglVertex3f(tdp[0], tdp[1], -16384);
  926. qglVertex3f(tdp[0], tdp[1], 16384);
  927. }
  928. else
  929. {
  930. qglVertex3f(-16384, tdp[1], tdp[2]);
  931. qglVertex3f( 16384, tdp[1], tdp[2]);
  932. qglVertex3f(tdp[0], tdp[1], -16384);
  933. qglVertex3f(tdp[0], tdp[1], 16384);
  934. }
  935. qglEnd();
  936. }
  937. if (ClipMode())
  938. {
  939. qglPointSize (4);
  940. qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_CLIPPER]);
  941. qglBegin (GL_POINTS);
  942. if (g_Clip1.Set())
  943. qglVertex3fv (g_Clip1);
  944. if (g_Clip2.Set())
  945. qglVertex3fv (g_Clip2);
  946. if (g_Clip3.Set())
  947. qglVertex3fv (g_Clip3);
  948. qglEnd ();
  949. qglPointSize (1);
  950. CString strMsg;
  951. if (g_Clip1.Set())
  952. {
  953. qglRasterPos3f (g_Clip1.m_ptClip[0]+2, g_Clip1.m_ptClip[1]+2, g_Clip1.m_ptClip[2]+2);
  954. strMsg = "1";
  955. //strMsg.Format("1 (%f, %f, %f)", g_Clip1[0], g_Clip1[1], g_Clip1[2]);
  956. qglCallLists (strMsg.GetLength(), GL_UNSIGNED_BYTE, strMsg);
  957. }
  958. if (g_Clip2.Set())
  959. {
  960. qglRasterPos3f (g_Clip2.m_ptClip[0]+2, g_Clip2.m_ptClip[1]+2, g_Clip2.m_ptClip[2]+2);
  961. strMsg = "2";
  962. //strMsg.Format("2 (%f, %f, %f)", g_Clip2[0], g_Clip2[1], g_Clip2[2]);
  963. qglCallLists (strMsg.GetLength(), GL_UNSIGNED_BYTE, strMsg);
  964. }
  965. if (g_Clip3.Set())
  966. {
  967. qglRasterPos3f (g_Clip3.m_ptClip[0]+2, g_Clip3.m_ptClip[1]+2, g_Clip3.m_ptClip[2]+2);
  968. strMsg = "3";
  969. //strMsg.Format("3 (%f, %f, %f)", g_Clip3[0], g_Clip3[1], g_Clip3[2]);
  970. qglCallLists (strMsg.GetLength(), GL_UNSIGNED_BYTE, strMsg);
  971. }
  972. if (g_Clip1.Set() && g_Clip2.Set())
  973. {
  974. ProduceSplitLists();
  975. brush_t* pBrush;
  976. brush_t* pList = ( (m_nViewType == XZ) ? !g_bSwitch : g_bSwitch) ? &g_brBackSplits : &g_brFrontSplits;
  977. for (pBrush = pList->next ; pBrush != NULL && pBrush != pList ; pBrush=pBrush->next)
  978. {
  979. qglColor3f (1,1,0);
  980. face_t *face;
  981. int order;
  982. for (face = pBrush->brush_faces,order = 0 ; face ; face=face->next, order++)
  983. {
  984. winding_t* w = face->face_winding;
  985. if (!w)
  986. continue;
  987. // draw the polygon
  988. qglBegin(GL_LINE_LOOP);
  989. for (int i=0 ; i<w->numpoints ; i++)
  990. qglVertex3fv(w->points[i]);
  991. qglEnd();
  992. }
  993. }
  994. }
  995. }
  996. if (PathMode())
  997. {
  998. qglPointSize (4);
  999. qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_CLIPPER]);
  1000. qglBegin (GL_POINTS);
  1001. for (int n = 0; n < g_nPathCount; n++)
  1002. qglVertex3fv(g_PathPoints[n]);
  1003. qglEnd ();
  1004. qglPointSize (1);
  1005. CString strMsg;
  1006. for (n = 0; n < g_nPathCount; n++)
  1007. {
  1008. qglRasterPos3f (g_PathPoints[n].m_ptClip[0]+2, g_PathPoints[n].m_ptClip[1]+2, g_PathPoints[n].m_ptClip[2]+2);
  1009. strMsg.Format("%i", n+1);
  1010. qglCallLists (strMsg.GetLength(), GL_UNSIGNED_BYTE, strMsg);
  1011. }
  1012. }
  1013. if (m_nViewType != XY)
  1014. qglPopMatrix();
  1015. qwglSwapBuffers(dc.m_hDC);
  1016. TRACE("XY Paint\n");
  1017. }
  1018. }
  1019. void CXYWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  1020. {
  1021. g_pParentWnd->HandleKey(nChar, nRepCnt, nFlags);
  1022. }
  1023. // FIXME: the brush_t *pBrush is never used. ( Entity_Create uses selected_brushes )
  1024. void CreateEntityFromName(char* pName, brush_t* pBrush)
  1025. {
  1026. eclass_t *pecNew;
  1027. entity_t *petNew;
  1028. if (stricmp(pName, "worldspawn") == 0)
  1029. {
  1030. MessageBox(g_qeglobals.d_hwndMain, "Can't create an entity with worldspawn.", "info", 0);
  1031. return;
  1032. }
  1033. pecNew = Eclass_ForName(pName, false);
  1034. // create it
  1035. petNew = Entity_Create(pecNew);
  1036. if (petNew == NULL)
  1037. {
  1038. if (!((selected_brushes.next == &selected_brushes)||(selected_brushes.next->next != &selected_brushes)))
  1039. {
  1040. brush_t* b = selected_brushes.next;
  1041. if (b->owner != world_entity && b->owner->eclass->fixedsize && pecNew->fixedsize)
  1042. {
  1043. vec3_t mins, maxs;
  1044. vec3_t origin;
  1045. for (int i=0 ; i<3 ; i++)
  1046. origin[i] = b->mins[i] - pecNew->mins[i];
  1047. VectorAdd (pecNew->mins, origin, mins);
  1048. VectorAdd (pecNew->maxs, origin, maxs);
  1049. brush_t* nb = Brush_Create (mins, maxs, &pecNew->texdef);
  1050. Entity_LinkBrush (b->owner, nb);
  1051. nb->owner->eclass = pecNew;
  1052. SetKeyValue (nb->owner, "classname", pName);
  1053. Brush_Free(b);
  1054. Brush_Build(nb);
  1055. Brush_AddToList (nb, &active_brushes);
  1056. Select_Brush(nb);
  1057. return;
  1058. }
  1059. }
  1060. MessageBox(g_qeglobals.d_hwndMain, "Failed to create entity.", "info", 0);
  1061. return;
  1062. }
  1063. Select_Deselect ();
  1064. //entity_t* pEntity = world_entity;
  1065. //if (selected_brushes.next != &selected_brushes)
  1066. // pEntity = selected_brushes.next->owner;
  1067. Select_Brush (petNew->brushes.onext);
  1068. if (stricmp(pName, "misc_model") == 0)
  1069. {
  1070. SetInspectorMode(W_ENTITY);
  1071. PostMessage(g_qeglobals.d_hwndEntity, WM_COMMAND, IDC_BTN_ASSIGNMODEL, 0);
  1072. }
  1073. }
  1074. brush_t* CreateEntityBrush(int x, int y, CXYWnd* pWnd)
  1075. {
  1076. vec3_t mins, maxs;
  1077. int i;
  1078. float temp;
  1079. brush_t *n;
  1080. pWnd->SnapToPoint (x, y, mins);
  1081. x += 32;
  1082. y += 32;
  1083. pWnd->SnapToPoint (x, y, maxs);
  1084. int nDim = (pWnd->GetViewType() == XY) ? 2 : (pWnd->GetViewType() == YZ) ? 0 : 1;
  1085. mins[nDim] = g_qeglobals.d_gridsize * ((int)(g_qeglobals.d_new_brush_bottom_z/g_qeglobals.d_gridsize));
  1086. maxs[nDim] = g_qeglobals.d_gridsize * ((int)(g_qeglobals.d_new_brush_top_z/g_qeglobals.d_gridsize));
  1087. if (maxs[nDim] <= mins[nDim])
  1088. maxs[nDim] = mins[nDim] + g_qeglobals.d_gridsize;
  1089. for (i=0 ; i<3 ; i++)
  1090. {
  1091. if (mins[i] == maxs[i])
  1092. maxs[i] += 16; // don't create a degenerate brush
  1093. if (mins[i] > maxs[i])
  1094. {
  1095. temp = mins[i];
  1096. mins[i] = maxs[i];
  1097. maxs[i] = temp;
  1098. }
  1099. }
  1100. n = Brush_Create (mins, maxs, &g_qeglobals.d_texturewin.texdef);
  1101. if (!n)
  1102. return NULL;
  1103. Brush_AddToList (n, &selected_brushes);
  1104. Entity_LinkBrush (world_entity, n);
  1105. Brush_Build( n );
  1106. return n;
  1107. }
  1108. void CreateRightClickEntity(CXYWnd* pWnd, int x, int y, char* pName)
  1109. {
  1110. CRect rctZ;
  1111. pWnd->GetClientRect(rctZ);
  1112. brush_t* pBrush = (selected_brushes.next == &selected_brushes) ? CreateEntityBrush(x, rctZ.Height() - 1 - y, pWnd) : selected_brushes.next;
  1113. CreateEntityFromName(pName, pBrush);
  1114. //Select_Brush(pBrush);
  1115. }
  1116. brush_t* CreateSmartBrush(vec3_t v)
  1117. {
  1118. vec3_t mins, maxs;
  1119. int i;
  1120. brush_t *n;
  1121. for (i=0 ; i<3 ; i++)
  1122. {
  1123. mins[i] = v[i] - 16;
  1124. maxs[i] = v[i] + 16;
  1125. }
  1126. n = Brush_Create (mins, maxs, &g_qeglobals.d_texturewin.texdef);
  1127. if (!n)
  1128. return NULL;
  1129. Brush_AddToList(n, &selected_brushes);
  1130. //Entity_LinkBrush(world_entity, n);
  1131. Brush_Build(n);
  1132. return n;
  1133. }
  1134. CString g_strSmartEntity;
  1135. int g_nSmartX;
  1136. int g_nSmartY;
  1137. bool g_bSmartWaiting;
  1138. void _SmartPointDone(bool b, int n)
  1139. {
  1140. g_bSmartWaiting = false;
  1141. }
  1142. void CreateSmartEntity(CXYWnd* pWnd, int x, int y, const char* pName)
  1143. {
  1144. g_nSmartX = x;
  1145. g_nSmartY = y;
  1146. g_strSmartEntity = pName;
  1147. if (g_strSmartEntity.Find("Smart_Train") >= 0)
  1148. {
  1149. ShowInfoDialog("Select the path of the train by left clicking in XY, YZ and/or XZ views. You can move an already dropped point by grabbing and moving it. When you are finished, press ENTER to accept and create the entity and path(s), press ESC to abandon the creation");
  1150. g_bPathMode = true;
  1151. g_nPathLimit = 0;
  1152. g_nPathCount = 0;
  1153. g_bSmartGo = true;
  1154. }
  1155. else
  1156. if (g_strSmartEntity.Find("Smart_Monster...") >= 0)
  1157. {
  1158. g_bPathMode = true;
  1159. g_nPathLimit = 0;
  1160. g_nPathCount = 0;
  1161. }
  1162. else
  1163. if (g_strSmartEntity.Find("Smart_Rotating") >= 0)
  1164. {
  1165. g_bSmartWaiting = true;
  1166. ShowInfoDialog("Left click to specify the rotation origin");
  1167. AcquirePath(1, &_SmartPointDone);
  1168. while (g_bSmartWaiting)
  1169. {
  1170. MSG msg;
  1171. if (::PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ))
  1172. {
  1173. TranslateMessage(&msg);
  1174. DispatchMessage(&msg);
  1175. }
  1176. }
  1177. HideInfoDialog();
  1178. CPtrArray array;
  1179. g_bScreenUpdates = false;
  1180. CreateRightClickEntity(g_pParentWnd->ActiveXY(), g_nSmartX, g_nSmartY, "func_rotating");
  1181. array.Add(reinterpret_cast<void*>(selected_brushes.next));
  1182. Select_Deselect();
  1183. brush_t* pBrush = CreateSmartBrush(g_PathPoints[0]);
  1184. array.Add(pBrush);
  1185. Select_Deselect();
  1186. Select_Brush(reinterpret_cast<brush_t*>(array.GetAt(0)));
  1187. Select_Brush(reinterpret_cast<brush_t*>(array.GetAt(1)));
  1188. ConnectEntities();
  1189. g_bScreenUpdates = true;
  1190. }
  1191. }
  1192. void FinishSmartCreation()
  1193. {
  1194. CPtrArray array;
  1195. HideInfoDialog();
  1196. brush_t* pEntities = NULL;
  1197. if (g_strSmartEntity.Find("Smart_Train") >= 0)
  1198. {
  1199. g_bScreenUpdates = false;
  1200. CreateRightClickEntity(g_pParentWnd->ActiveXY(), g_nSmartX, g_nSmartY, "func_train");
  1201. array.Add(reinterpret_cast<void*>(selected_brushes.next));
  1202. for (int n = 0; n < g_nPathCount; n++)
  1203. {
  1204. Select_Deselect();
  1205. CreateRightClickEntity(g_pParentWnd->ActiveXY(), g_PathPoints[n].m_ptScreen.x,g_PathPoints[n].m_ptScreen.y, "path_corner");
  1206. array.Add(reinterpret_cast<void*>(selected_brushes.next));
  1207. }
  1208. for (n = 0; n < g_nPathCount; n++)
  1209. {
  1210. Select_Deselect();
  1211. Select_Brush(reinterpret_cast<brush_t*>(array.GetAt(n)));
  1212. Select_Brush(reinterpret_cast<brush_t*>(array.GetAt(n+1)));
  1213. ConnectEntities();
  1214. }
  1215. g_bScreenUpdates = true;
  1216. }
  1217. g_nPathCount = 0;
  1218. g_bPathMode = false;
  1219. Sys_UpdateWindows(W_ALL);
  1220. }
  1221. void CXYWnd::KillPathMode()
  1222. {
  1223. g_bSmartGo = false;
  1224. g_bPathMode = false;
  1225. if (g_pPathFunc)
  1226. g_pPathFunc(false, g_nPathCount);
  1227. g_nPathCount = 0;
  1228. g_pPathFunc = NULL;
  1229. Sys_UpdateWindows(W_ALL);
  1230. }
  1231. // gets called for drop down menu messages
  1232. // TIP: it's not always about EntityCreate
  1233. void CXYWnd::OnEntityCreate(unsigned int nID)
  1234. {
  1235. if (m_mnuDrop.GetSafeHmenu())
  1236. {
  1237. CString strItem;
  1238. m_mnuDrop.GetMenuString(nID, strItem, MF_BYCOMMAND);
  1239. if (strItem.CompareNoCase("Add to...") == 0)
  1240. {
  1241. //++timo TODO: fill the menu with current groups?
  1242. // this one is for adding to existing groups only
  1243. Sys_Printf("TODO: Add to... in CXYWnd::OnEntityCreate\n");
  1244. }
  1245. else if (strItem.CompareNoCase("Remove") == 0)
  1246. {
  1247. // remove selected brushes from their current group
  1248. brush_t *b;
  1249. for( b = selected_brushes.next; b != &selected_brushes; b = b->next )
  1250. {
  1251. }
  1252. }
  1253. //++timo FIXME: remove when all hooks are in
  1254. if (strItem.CompareNoCase("Add to...") == 0
  1255. || strItem.CompareNoCase("Remove") == 0
  1256. || strItem.CompareNoCase("Name...") == 0
  1257. || strItem.CompareNoCase("New group...") == 0)
  1258. {
  1259. Sys_Printf("TODO: hook drop down group menu\n");
  1260. return;
  1261. }
  1262. if (strItem.Find("Smart_") >= 0)
  1263. {
  1264. CreateSmartEntity(this, m_ptDown.x, m_ptDown.y, strItem);
  1265. }
  1266. else
  1267. {
  1268. CreateRightClickEntity(this, m_ptDown.x, m_ptDown.y, strItem.GetBuffer(0));
  1269. }
  1270. Sys_UpdateWindows(W_ALL);
  1271. //OnLButtonDown((MK_LBUTTON | MK_SHIFT), CPoint(m_ptDown.x+2, m_ptDown.y+2));
  1272. }
  1273. }
  1274. void CXYWnd::HandleDrop()
  1275. {
  1276. if (g_PrefsDlg.m_bRightClick == false)
  1277. return;
  1278. if (!m_mnuDrop.GetSafeHmenu()) // first time, load it up
  1279. {
  1280. m_mnuDrop.CreatePopupMenu();
  1281. int nID = ID_ENTITY_START;
  1282. CMenu* pChild2 = new CMenu;
  1283. pChild2->CreateMenu();
  1284. pChild2->AppendMenu(MF_STRING, ID_SELECTION_SELECTCOMPLETETALL, "Select Complete Tall");
  1285. pChild2->AppendMenu(MF_STRING, ID_SELECTION_SELECTTOUCHING, "Select Touching");
  1286. pChild2->AppendMenu(MF_STRING, ID_SELECTION_SELECTPARTIALTALL, "Select Partial Tall");
  1287. pChild2->AppendMenu(MF_STRING, ID_SELECTION_SELECTINSIDE, "Select Inside");
  1288. m_mnuDrop.AppendMenu(MF_POPUP, reinterpret_cast<unsigned int>(pChild2->GetSafeHmenu()), "Select");
  1289. m_mnuDrop.AppendMenu(MF_SEPARATOR, nID++, "");
  1290. CMenu* pChild3 = new CMenu;
  1291. pChild3->CreateMenu();
  1292. pChild3->AppendMenu(MF_STRING, ID_DROP_GROUP_ADDTO, "Add to...");
  1293. pChild3->AppendMenu(MF_STRING, ID_DROP_GROUP_REMOVE, "Remove");
  1294. pChild3->AppendMenu(MF_STRING, ID_DROP_GROUP_NAME, "Name...");
  1295. pChild3->AppendMenu(MF_SEPARATOR, nID++, "");
  1296. pChild3->AppendMenu(MF_STRING, ID_DROP_GROUP_NEWGROUP, "New Group...");
  1297. m_mnuDrop.AppendMenu(MF_POPUP, reinterpret_cast<unsigned int>(pChild3->GetSafeHmenu()), "Group");
  1298. m_mnuDrop.AppendMenu(MF_SEPARATOR, nID++, "");
  1299. m_mnuDrop.AppendMenu(MF_STRING, ID_SELECTION_UNGROUPENTITY, "Ungroup Entity");
  1300. m_mnuDrop.AppendMenu(MF_STRING, ID_SELECTION_MAKE_DETAIL, "Make Detail");
  1301. m_mnuDrop.AppendMenu(MF_STRING, ID_SELECTION_MAKE_STRUCTURAL, "Make Structural");
  1302. m_mnuDrop.AppendMenu(MF_SEPARATOR, nID++, "");
  1303. CMenu* pChild = new CMenu;
  1304. pChild->CreateMenu();
  1305. pChild->AppendMenu(MF_STRING, nID++, "Smart_Train");
  1306. //pChild->AppendMenu(MF_STRING, nID++, "Smart_Rotating");
  1307. m_mnuDrop.AppendMenu(MF_POPUP, reinterpret_cast<unsigned int>(pChild->GetSafeHmenu()), "Smart Entities");
  1308. m_mnuDrop.AppendMenu(MF_SEPARATOR, nID++, "");
  1309. pChild = NULL;
  1310. eclass_t *e;
  1311. CString strActive;
  1312. CString strLast;
  1313. CString strName;
  1314. for (e=eclass ; e ; e=e->next)
  1315. {
  1316. strLast = strName;
  1317. strName = e->name;
  1318. int n_ = strName.Find("_");
  1319. if (n_ > 0)
  1320. {
  1321. CString strLeft = strName.Left(n_);
  1322. CString strRight = strName.Right(strName.GetLength() - n_ - 1);
  1323. if (strLeft == strActive) // this is a child
  1324. {
  1325. ASSERT(pChild);
  1326. pChild->AppendMenu(MF_STRING, nID++, strName);
  1327. }
  1328. else
  1329. {
  1330. if (pChild)
  1331. {
  1332. m_mnuDrop.AppendMenu(MF_POPUP, reinterpret_cast<unsigned int>(pChild->GetSafeHmenu()), strActive);
  1333. g_ptrMenus.Add(pChild);
  1334. //pChild->DestroyMenu();
  1335. //delete pChild;
  1336. pChild = NULL;
  1337. }
  1338. strActive = strLeft;
  1339. pChild = new CMenu;
  1340. pChild->CreateMenu();
  1341. pChild->AppendMenu(MF_STRING, nID++, strName);
  1342. }
  1343. }
  1344. else
  1345. {
  1346. if (pChild)
  1347. {
  1348. m_mnuDrop.AppendMenu(MF_POPUP, reinterpret_cast<unsigned int>(pChild->GetSafeHmenu()), strActive);
  1349. g_ptrMenus.Add(pChild);
  1350. //pChild->DestroyMenu();
  1351. //delete pChild;
  1352. pChild = NULL;
  1353. }
  1354. strActive = "";
  1355. m_mnuDrop.AppendMenu(MF_STRING, nID++, strName);
  1356. }
  1357. }
  1358. }
  1359. CPoint ptMouse;
  1360. GetCursorPos(&ptMouse);
  1361. m_mnuDrop.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, ptMouse.x, ptMouse.y, this);
  1362. }
  1363. void CXYWnd::XY_Init()
  1364. {
  1365. m_vOrigin[0] = 0;
  1366. m_vOrigin[1] = 20;
  1367. m_vOrigin[2] = 46;
  1368. m_fScale = 1;
  1369. }
  1370. void CXYWnd::SnapToPoint (int x, int y, vec3_t point)
  1371. {
  1372. if (g_PrefsDlg.m_bNoClamp)
  1373. {
  1374. XY_ToPoint(x, y, point);
  1375. }
  1376. else
  1377. {
  1378. XY_ToGridPoint(x, y, point);
  1379. }
  1380. //-- else
  1381. //-- XY_ToPoint(x, y, point);
  1382. //-- //XY_ToPoint(x, y, point);
  1383. }
  1384. void CXYWnd::XY_ToPoint (int x, int y, vec3_t point)
  1385. {
  1386. float fx = x;
  1387. float fy = y;
  1388. float fw = m_nWidth;
  1389. float fh = m_nHeight;
  1390. if (m_nViewType == XY)
  1391. {
  1392. point[0] = m_vOrigin[0] + (fx - fw / 2) / m_fScale;
  1393. point[1] = m_vOrigin[1] + (fy - fh / 2) / m_fScale;
  1394. //point[2] = 0;
  1395. }
  1396. else if (m_nViewType == YZ)
  1397. {
  1398. ////point[0] = 0;
  1399. //point[1] = m_vOrigin[0] + (fx - fw / 2) / m_fScale;
  1400. //point[2] = m_vOrigin[1] + (fy - fh / 2 ) / m_fScale;
  1401. point[1] = m_vOrigin[1] + (fx - fw / 2) / m_fScale;
  1402. point[2] = m_vOrigin[2] + (fy - fh / 2 ) / m_fScale;
  1403. }
  1404. else
  1405. {
  1406. //point[0] = m_vOrigin[0] + (fx - fw / 2) / m_fScale;
  1407. ////point[1] = 0;
  1408. //point[2] = m_vOrigin[1] + (fy - fh / 2) / m_fScale;
  1409. point[0] = m_vOrigin[0] + (fx - fw / 2) / m_fScale;
  1410. //point[1] = 0;
  1411. point[2] = m_vOrigin[2] + (fy - fh / 2) / m_fScale;
  1412. }
  1413. }
  1414. void CXYWnd::XY_ToGridPoint (int x, int y, vec3_t point)
  1415. {
  1416. if (m_nViewType == XY)
  1417. {
  1418. point[0] = m_vOrigin[0] + (x - m_nWidth / 2) / m_fScale;
  1419. point[1] = m_vOrigin[1] + (y - m_nHeight / 2) / m_fScale;
  1420. //point[2] = 0;
  1421. point[0] = floor(point[0] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
  1422. point[1] = floor(point[1] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
  1423. }
  1424. else if (m_nViewType == YZ)
  1425. {
  1426. //point[0] = 0;
  1427. //point[1] = m_vOrigin[0] + (x - m_nWidth / 2) / m_fScale;
  1428. //point[2] = m_vOrigin[1] + (y - m_nHeight / 2) / m_fScale;
  1429. point[1] = m_vOrigin[1] + (x - m_nWidth / 2) / m_fScale;
  1430. point[2] = m_vOrigin[2] + (y - m_nHeight / 2) / m_fScale;
  1431. point[1] = floor(point[1] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
  1432. point[2] = floor(point[2] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
  1433. }
  1434. else
  1435. {
  1436. //point[1] = 0;
  1437. //point[0] = m_vOrigin[0] + (x - m_nWidth / 2) / m_fScale;
  1438. //point[2] = m_vOrigin[1] + (y - m_nHeight / 2) / m_fScale;
  1439. point[0] = m_vOrigin[0] + (x - m_nWidth / 2) / m_fScale;
  1440. point[2] = m_vOrigin[2] + (y - m_nHeight / 2) / m_fScale;
  1441. point[0] = floor(point[0] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
  1442. point[2] = floor(point[2] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
  1443. }
  1444. }
  1445. void CXYWnd::XY_MouseDown (int x, int y, int buttons)
  1446. {
  1447. vec3_t point;
  1448. vec3_t origin, dir, right, up;
  1449. m_nButtonstate = buttons;
  1450. m_nPressx = x;
  1451. m_nPressy = y;
  1452. VectorCopy (vec3_origin, m_vPressdelta);
  1453. XY_ToPoint (x, y, point);
  1454. VectorCopy (point, origin);
  1455. dir[0] = 0; dir[1] = 0; dir[2] = 0;
  1456. if (m_nViewType == XY)
  1457. {
  1458. origin[2] = 8192;
  1459. dir[2] = -1;
  1460. right[0] = 1 / m_fScale;
  1461. right[1] = 0;
  1462. right[2] = 0;
  1463. up[0] = 0;
  1464. up[1] = 1 / m_fScale;
  1465. up[2] = 0;
  1466. }
  1467. else if (m_nViewType == YZ)
  1468. {
  1469. origin[0] = 8192;
  1470. dir[0] = -1;
  1471. right[1] = 1 / m_fScale;
  1472. right[2] = 0;
  1473. right[0] = 0;
  1474. up[0] = 0;
  1475. up[2] = 1 / m_fScale;
  1476. up[1] = 0;
  1477. }
  1478. else
  1479. {
  1480. origin[1] = 8192;
  1481. dir[1] = -1;
  1482. right[0] = 1 / m_fScale;
  1483. right[2] = 0;
  1484. right[1] = 0;
  1485. up[0] = 0;
  1486. up[2] = 1 / m_fScale;
  1487. up[1] = 0;
  1488. }
  1489. m_bPress_selection = (selected_brushes.next != &selected_brushes);
  1490. GetCursorPos(&m_ptCursor);
  1491. //Sys_GetCursorPos (&m_ptCursor.x, &m_ptCursor.y);
  1492. // lbutton = manipulate selection
  1493. // shift-LBUTTON = select
  1494. if ( (buttons == MK_LBUTTON)
  1495. || (buttons == (MK_LBUTTON | MK_SHIFT))
  1496. || (buttons == (MK_LBUTTON | MK_CONTROL))
  1497. || (buttons == (MK_LBUTTON | MK_CONTROL | MK_SHIFT)) )
  1498. {
  1499. if (g_qeglobals.d_select_mode == sel_addpoint) {
  1500. XY_ToGridPoint(x, y, point);
  1501. if (g_qeglobals.selectObject) {
  1502. g_qeglobals.selectObject->addPoint(point[0], point[1], point[2]);
  1503. }
  1504. return;
  1505. }
  1506. Patch_SetView( (m_nViewType == XY) ? W_XY : (m_nViewType == YZ) ? W_YZ : W_XZ);
  1507. Drag_Begin (x, y, buttons, right, up, origin, dir);
  1508. return;
  1509. }
  1510. int nMouseButton = g_PrefsDlg.m_nMouseButtons == 2 ? MK_RBUTTON : MK_MBUTTON;
  1511. // control mbutton = move camera
  1512. if (m_nButtonstate == (MK_CONTROL|nMouseButton) )
  1513. {
  1514. VectorCopyXY(point, g_pParentWnd->GetCamera()->Camera().origin);
  1515. Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY);
  1516. }
  1517. // mbutton = angle camera
  1518. if ((g_PrefsDlg.m_nMouseButtons == 3 && m_nButtonstate == MK_MBUTTON) ||
  1519. (g_PrefsDlg.m_nMouseButtons == 2 && m_nButtonstate == (MK_SHIFT|MK_CONTROL|MK_RBUTTON)))
  1520. {
  1521. VectorSubtract (point, g_pParentWnd->GetCamera()->Camera().origin, point);
  1522. int n1 = (m_nViewType == XY) ? 1 : 2;
  1523. int n2 = (m_nViewType == YZ) ? 1 : 0;
  1524. int nAngle = (m_nViewType == XY) ? YAW : PITCH;
  1525. if (point[n1] || point[n2])
  1526. {
  1527. g_pParentWnd->GetCamera()->Camera().angles[nAngle] = 180/Q_PI*atan2 (point[n1], point[n2]);
  1528. Sys_UpdateWindows (W_CAMERA_IFON|W_XY_OVERLAY);
  1529. }
  1530. }
  1531. // shift mbutton = move z checker
  1532. if (m_nButtonstate == (MK_SHIFT | nMouseButton))
  1533. {
  1534. if (RotateMode() || g_bPatchBendMode)
  1535. {
  1536. SnapToPoint (x, y, point);
  1537. VectorCopyXY(point, g_vRotateOrigin);
  1538. if (g_bPatchBendMode)
  1539. {
  1540. VectorCopy(point, g_vBendOrigin);
  1541. }
  1542. Sys_UpdateWindows (W_XY);
  1543. return;
  1544. }
  1545. else
  1546. {
  1547. SnapToPoint (x, y, point);
  1548. if (m_nViewType == XY)
  1549. {
  1550. z.origin[0] = point[0];
  1551. z.origin[1] = point[1];
  1552. }
  1553. else if (m_nViewType == YZ)
  1554. {
  1555. z.origin[0] = point[1];
  1556. z.origin[1] = point[2];
  1557. }
  1558. else
  1559. {
  1560. z.origin[0] = point[0];
  1561. z.origin[1] = point[2];
  1562. }
  1563. Sys_UpdateWindows (W_XY_OVERLAY|W_Z);
  1564. return;
  1565. }
  1566. }
  1567. }
  1568. void CXYWnd::XY_MouseUp(int x, int y, int buttons)
  1569. {
  1570. Drag_MouseUp (buttons);
  1571. if (!m_bPress_selection)
  1572. Sys_UpdateWindows (W_ALL);
  1573. m_nButtonstate = 0;
  1574. while (::ShowCursor(TRUE) < 0)
  1575. ;
  1576. }
  1577. qboolean CXYWnd::DragDelta (int x, int y, vec3_t move)
  1578. {
  1579. vec3_t xvec, yvec, delta;
  1580. int i;
  1581. xvec[0] = 1 / m_fScale;
  1582. xvec[1] = xvec[2] = 0;
  1583. yvec[1] = 1 / m_fScale;
  1584. yvec[0] = yvec[2] = 0;
  1585. for (i=0 ; i<3 ; i++)
  1586. {
  1587. delta[i] = xvec[i] * (x - m_nPressx) + yvec[i] * (y - m_nPressy);
  1588. if (!g_PrefsDlg.m_bNoClamp)
  1589. {
  1590. delta[i] = floor(delta[i] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
  1591. }
  1592. }
  1593. VectorSubtract (delta, m_vPressdelta, move);
  1594. VectorCopy (delta, m_vPressdelta);
  1595. if (move[0] || move[1] || move[2])
  1596. return true;
  1597. return false;
  1598. }
  1599. /*
  1600. ==============
  1601. NewBrushDrag
  1602. ==============
  1603. */
  1604. void CXYWnd::NewBrushDrag (int x, int y)
  1605. {
  1606. vec3_t mins, maxs, junk;
  1607. int i;
  1608. float temp;
  1609. brush_t *n;
  1610. if (!DragDelta (x,y, junk))
  1611. return;
  1612. // delete the current selection
  1613. if (selected_brushes.next != &selected_brushes)
  1614. Brush_Free (selected_brushes.next);
  1615. SnapToPoint (m_nPressx, m_nPressy, mins);
  1616. int nDim = (m_nViewType == XY) ? 2 : (m_nViewType == YZ) ? 0 : 1;
  1617. mins[nDim] = g_qeglobals.d_gridsize * ((int)(g_qeglobals.d_new_brush_bottom_z / g_qeglobals.d_gridsize));
  1618. SnapToPoint (x, y, maxs);
  1619. maxs[nDim] = g_qeglobals.d_gridsize * ((int)(g_qeglobals.d_new_brush_top_z / g_qeglobals.d_gridsize));
  1620. if (maxs[nDim] <= mins[nDim])
  1621. maxs[nDim] = mins[nDim] + g_qeglobals.d_gridsize;
  1622. for (i=0 ; i<3 ; i++)
  1623. {
  1624. if (mins[i] == maxs[i])
  1625. return; // don't create a degenerate brush
  1626. if (mins[i] > maxs[i])
  1627. {
  1628. temp = mins[i];
  1629. mins[i] = maxs[i];
  1630. maxs[i] = temp;
  1631. }
  1632. }
  1633. n = Brush_Create (mins, maxs, &g_qeglobals.d_texturewin.texdef);
  1634. if (!n)
  1635. return;
  1636. vec3_t vSize;
  1637. VectorSubtract(maxs, mins, vSize);
  1638. g_strStatus.Format("Size X:: %.1f Y:: %.1f Z:: %.1f", vSize[0], vSize[1], vSize[2]);
  1639. g_pParentWnd->SetStatusText(2, g_strStatus);
  1640. Brush_AddToList (n, &selected_brushes);
  1641. Entity_LinkBrush (world_entity, n);
  1642. Brush_Build( n );
  1643. // Sys_UpdateWindows (W_ALL);
  1644. Sys_UpdateWindows (W_XY| W_CAMERA);
  1645. }
  1646. /*
  1647. ==============
  1648. XY_MouseMoved
  1649. ==============
  1650. */
  1651. void CXYWnd::XY_MouseMoved (int x, int y, int buttons)
  1652. {
  1653. vec3_t point;
  1654. if (!m_nButtonstate)
  1655. {
  1656. if (g_bCrossHairs)
  1657. {
  1658. ::ShowCursor(FALSE);
  1659. Sys_UpdateWindows (W_XY | W_XY_OVERLAY);
  1660. ::ShowCursor(TRUE);
  1661. }
  1662. return;
  1663. }
  1664. // lbutton without selection = drag new brush
  1665. //if (m_nButtonstate == MK_LBUTTON && !m_bPress_selection && g_qeglobals.d_select_mode != sel_curvepoint && g_qeglobals.d_select_mode != sel_splineedit)
  1666. if (m_nButtonstate == MK_LBUTTON && !m_bPress_selection && g_qeglobals.d_select_mode == sel_brush)
  1667. {
  1668. NewBrushDrag (x, y);
  1669. return;
  1670. }
  1671. // lbutton (possibly with control and or shift)
  1672. // with selection = drag selection
  1673. if (m_nButtonstate & MK_LBUTTON)
  1674. {
  1675. Drag_MouseMoved (x, y, buttons);
  1676. Sys_UpdateWindows (W_XY_OVERLAY | W_CAMERA_IFON | W_Z);
  1677. return;
  1678. }
  1679. int nMouseButton = g_PrefsDlg.m_nMouseButtons == 2 ? MK_RBUTTON : MK_MBUTTON;
  1680. // control mbutton = move camera
  1681. if (m_nButtonstate == (MK_CONTROL|nMouseButton) )
  1682. {
  1683. SnapToPoint (x, y, point);
  1684. VectorCopyXY(point, g_pParentWnd->GetCamera()->Camera().origin);
  1685. Sys_UpdateWindows (W_XY_OVERLAY | W_CAMERA);
  1686. return;
  1687. }
  1688. // shift mbutton = move z checker
  1689. if (m_nButtonstate == (MK_SHIFT|nMouseButton) )
  1690. {
  1691. if (RotateMode() || g_bPatchBendMode)
  1692. {
  1693. SnapToPoint (x, y, point);
  1694. VectorCopyXY(point, g_vRotateOrigin);
  1695. if (g_bPatchBendMode)
  1696. {
  1697. VectorCopy(point, g_vBendOrigin);
  1698. }
  1699. Sys_UpdateWindows (W_XY);
  1700. return;
  1701. }
  1702. else
  1703. {
  1704. SnapToPoint (x, y, point);
  1705. if (m_nViewType == XY)
  1706. {
  1707. z.origin[0] = point[0];
  1708. z.origin[1] = point[1];
  1709. }
  1710. else if (m_nViewType == YZ)
  1711. {
  1712. z.origin[0] = point[1];
  1713. z.origin[1] = point[2];
  1714. }
  1715. else
  1716. {
  1717. z.origin[0] = point[0];
  1718. z.origin[1] = point[2];
  1719. }
  1720. }
  1721. Sys_UpdateWindows (W_XY_OVERLAY|W_Z);
  1722. return;
  1723. }
  1724. // mbutton = angle camera
  1725. if ((g_PrefsDlg.m_nMouseButtons == 3 && m_nButtonstate == MK_MBUTTON) ||
  1726. (g_PrefsDlg.m_nMouseButtons == 2 && m_nButtonstate == (MK_SHIFT|MK_CONTROL|MK_RBUTTON)))
  1727. {
  1728. SnapToPoint (x, y, point);
  1729. VectorSubtract (point, g_pParentWnd->GetCamera()->Camera().origin, point);
  1730. int n1 = (m_nViewType == XY) ? 1 : 2;
  1731. int n2 = (m_nViewType == YZ) ? 1 : 0;
  1732. int nAngle = (m_nViewType == XY) ? YAW : PITCH;
  1733. if (point[n1] || point[n2])
  1734. {
  1735. g_pParentWnd->GetCamera()->Camera().angles[nAngle] = 180/Q_PI*atan2 (point[n1], point[n2]);
  1736. Sys_UpdateWindows (W_CAMERA_IFON|W_XY_OVERLAY);
  1737. }
  1738. return;
  1739. }
  1740. // rbutton = drag xy origin
  1741. if (m_nButtonstate == MK_RBUTTON)
  1742. {
  1743. Sys_GetCursorPos (&x, &y);
  1744. if (x != m_ptCursor.x || y != m_ptCursor.y)
  1745. {
  1746. int nDim1 = (m_nViewType == YZ) ? 1 : 0;
  1747. int nDim2 = (m_nViewType == XY) ? 1 : 2;
  1748. m_vOrigin[nDim1] -= (x - m_ptCursor.x) / m_fScale;
  1749. m_vOrigin[nDim2] += (y - m_ptCursor.y) / m_fScale;
  1750. SetCursorPos (m_ptCursor.x, m_ptCursor.y);
  1751. ::ShowCursor(FALSE);
  1752. //XY_Draw();
  1753. //RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  1754. Sys_UpdateWindows (W_XY | W_XY_OVERLAY);
  1755. //::ShowCursor(TRUE);
  1756. }
  1757. return;
  1758. }
  1759. }
  1760. /*
  1761. ============================================================================
  1762. DRAWING
  1763. ============================================================================
  1764. */
  1765. /*
  1766. ==============
  1767. XY_DrawGrid
  1768. ==============
  1769. */
  1770. void CXYWnd::XY_DrawGrid()
  1771. {
  1772. float x, y, xb, xe, yb, ye;
  1773. int w, h;
  1774. char text[32];
  1775. qglDisable(GL_TEXTURE_2D);
  1776. qglDisable(GL_TEXTURE_1D);
  1777. qglDisable(GL_DEPTH_TEST);
  1778. qglDisable(GL_BLEND);
  1779. w = m_nWidth / 2 / m_fScale;
  1780. h = m_nHeight / 2 / m_fScale;
  1781. int nDim1 = (m_nViewType == YZ) ? 1 : 0;
  1782. int nDim2 = (m_nViewType == XY) ? 1 : 2;
  1783. //int nDim1 = 0;
  1784. //int nDim2 = 1;
  1785. xb = m_vOrigin[nDim1] - w;
  1786. if (xb < region_mins[nDim1])
  1787. xb = region_mins[nDim1];
  1788. xb = 64 * floor (xb/64);
  1789. xe = m_vOrigin[nDim1] + w;
  1790. if (xe > region_maxs[nDim1])
  1791. xe = region_maxs[nDim1];
  1792. xe = 64 * ceil (xe/64);
  1793. yb = m_vOrigin[nDim2] - h;
  1794. if (yb < region_mins[nDim2])
  1795. yb = region_mins[nDim2];
  1796. yb = 64 * floor (yb/64);
  1797. ye = m_vOrigin[nDim2] + h;
  1798. if (ye > region_maxs[nDim2])
  1799. ye = region_maxs[nDim2];
  1800. ye = 64 * ceil (ye/64);
  1801. // draw major blocks
  1802. qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDMAJOR]);
  1803. int stepSize = 64 * 0.1 / m_fScale;
  1804. if (stepSize < 64) {
  1805. stepSize = 64;
  1806. } else {
  1807. int i;
  1808. for (i = 1; i < stepSize; i <<= 1) {
  1809. }
  1810. stepSize = i;
  1811. }
  1812. if ( g_qeglobals.d_showgrid )
  1813. {
  1814. qglBegin (GL_LINES);
  1815. for (x=xb ; x<=xe ; x+=stepSize)
  1816. {
  1817. qglVertex2f (x, yb);
  1818. qglVertex2f (x, ye);
  1819. }
  1820. for (y=yb ; y<=ye ; y+=stepSize)
  1821. {
  1822. qglVertex2f (xb, y);
  1823. qglVertex2f (xe, y);
  1824. }
  1825. qglEnd ();
  1826. }
  1827. // draw minor blocks
  1828. if ( m_fScale > .1 && g_qeglobals.d_showgrid && g_qeglobals.d_gridsize * m_fScale >= 4 &&
  1829. g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR] != g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK])
  1830. {
  1831. qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR]);
  1832. qglBegin (GL_LINES);
  1833. for (x=xb ; x<xe ; x += g_qeglobals.d_gridsize)
  1834. {
  1835. if ( ! ((int)x & 63) )
  1836. continue;
  1837. qglVertex2f (x, yb);
  1838. qglVertex2f (x, ye);
  1839. }
  1840. for (y=yb ; y<ye ; y+=g_qeglobals.d_gridsize)
  1841. {
  1842. if ( ! ((int)y & 63) )
  1843. continue;
  1844. qglVertex2f (xb, y);
  1845. qglVertex2f (xe, y);
  1846. }
  1847. qglEnd ();
  1848. }
  1849. // draw coordinate text if needed
  1850. if ( g_qeglobals.d_savedinfo.show_coordinates)
  1851. {
  1852. //glColor4f(0, 0, 0, 0);
  1853. qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDTEXT]);
  1854. for (x=xb ; x<xe ; x+=stepSize)
  1855. {
  1856. qglRasterPos2f (x, m_vOrigin[nDim2] + h - 6 / m_fScale);
  1857. sprintf (text, "%i",(int)x);
  1858. qglCallLists (strlen(text), GL_UNSIGNED_BYTE, text);
  1859. }
  1860. for (y=yb ; y<ye ; y+=stepSize)
  1861. {
  1862. qglRasterPos2f (m_vOrigin[nDim1] - w + 1, y);
  1863. sprintf (text, "%i",(int)y);
  1864. qglCallLists (strlen(text), GL_UNSIGNED_BYTE, text);
  1865. }
  1866. if (Active())
  1867. qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_VIEWNAME]);
  1868. qglRasterPos2f ( m_vOrigin[nDim1] - w + 35 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
  1869. char cView[20];
  1870. if (m_nViewType == XY)
  1871. strcpy(cView, "XY Top");
  1872. else
  1873. if (m_nViewType == XZ)
  1874. strcpy(cView, "XZ Front");
  1875. else
  1876. strcpy(cView, "YZ Side");
  1877. qglCallLists (strlen(cView), GL_UNSIGNED_BYTE, cView);
  1878. }
  1879. /*
  1880. if (true)
  1881. {
  1882. qglColor3f(g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR]);
  1883. qglBegin (GL_LINES);
  1884. qglVertex2f (x, yb);
  1885. qglVertex2f (x, ye);
  1886. qglEnd();
  1887. }
  1888. */
  1889. }
  1890. /*
  1891. ==============
  1892. XY_DrawBlockGrid
  1893. ==============
  1894. */
  1895. void CXYWnd::XY_DrawBlockGrid()
  1896. {
  1897. float x, y, xb, xe, yb, ye;
  1898. int w, h;
  1899. char text[32];
  1900. qglDisable(GL_TEXTURE_2D);
  1901. qglDisable(GL_TEXTURE_1D);
  1902. qglDisable(GL_DEPTH_TEST);
  1903. qglDisable(GL_BLEND);
  1904. w = m_nWidth / 2 / m_fScale;
  1905. h = m_nHeight / 2 / m_fScale;
  1906. int nDim1 = (m_nViewType == YZ) ? 1 : 0;
  1907. int nDim2 = (m_nViewType == XY) ? 1 : 2;
  1908. xb = m_vOrigin[nDim1] - w;
  1909. if (xb < region_mins[nDim1])
  1910. xb = region_mins[nDim1];
  1911. xb = 1024 * floor (xb/1024);
  1912. xe = m_vOrigin[nDim1] + w;
  1913. if (xe > region_maxs[nDim1])
  1914. xe = region_maxs[nDim1];
  1915. xe = 1024 * ceil (xe/1024);
  1916. yb = m_vOrigin[nDim2] - h;
  1917. if (yb < region_mins[nDim2])
  1918. yb = region_mins[nDim2];
  1919. yb = 1024 * floor (yb/1024);
  1920. ye = m_vOrigin[nDim2] + h;
  1921. if (ye > region_maxs[nDim2])
  1922. ye = region_maxs[nDim2];
  1923. ye = 1024 * ceil (ye/1024);
  1924. // draw major blocks
  1925. qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDBLOCK]);
  1926. qglLineWidth (2);
  1927. qglBegin (GL_LINES);
  1928. for (x=xb ; x<=xe ; x+=1024)
  1929. {
  1930. qglVertex2f (x, yb);
  1931. qglVertex2f (x, ye);
  1932. }
  1933. for (y=yb ; y<=ye ; y+=1024)
  1934. {
  1935. qglVertex2f (xb, y);
  1936. qglVertex2f (xe, y);
  1937. }
  1938. qglEnd ();
  1939. qglLineWidth (1);
  1940. // draw coordinate text if needed
  1941. for (x=xb ; x<xe ; x+=1024)
  1942. for (y=yb ; y<ye ; y+=1024)
  1943. {
  1944. qglRasterPos2f (x+512, y+512);
  1945. sprintf (text, "%i,%i",(int)floor(x/1024), (int)floor(y/1024) );
  1946. qglCallLists (strlen(text), GL_UNSIGNED_BYTE, text);
  1947. }
  1948. qglColor4f(0, 0, 0, 0);
  1949. }
  1950. void CXYWnd::DrawRotateIcon()
  1951. {
  1952. float x, y;
  1953. if (m_nViewType == XY)
  1954. {
  1955. x = g_vRotateOrigin[0];
  1956. y = g_vRotateOrigin[1];
  1957. }
  1958. else if (m_nViewType == YZ)
  1959. {
  1960. x = g_vRotateOrigin[1];
  1961. y = g_vRotateOrigin[2];
  1962. }
  1963. else
  1964. {
  1965. x = g_vRotateOrigin[0];
  1966. y = g_vRotateOrigin[2];
  1967. }
  1968. qglEnable (GL_BLEND);
  1969. qglDisable (GL_TEXTURE_2D);
  1970. qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
  1971. qglDisable (GL_CULL_FACE);
  1972. qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1973. qglColor4f (0.8, 0.1, 0.9, 0.25);
  1974. qglBegin(GL_QUADS);
  1975. qglVertex3f (x-4,y-4,0);
  1976. qglVertex3f (x+4,y-4,0);
  1977. qglVertex3f (x+4,y+4,0);
  1978. qglVertex3f (x-4,y+4,0);
  1979. qglEnd ();
  1980. qglDisable (GL_BLEND);
  1981. qglColor4f (1.0, 0.2, 1.0, 1);
  1982. qglBegin(GL_POINTS);
  1983. qglVertex3f (x,y,0);
  1984. qglEnd ();
  1985. #if 0
  1986. qglBegin(GL_LINES);
  1987. qglVertex3f (x-6,y+6,0);
  1988. qglVertex3f (x+6,y+6,0);
  1989. qglVertex3f (x-6,y-6,0);
  1990. qglVertex3f (x+6,y-6,0);
  1991. qglEnd ();
  1992. #endif
  1993. }
  1994. void CXYWnd::DrawCameraIcon()
  1995. {
  1996. float x, y, a;
  1997. if (m_nViewType == XY)
  1998. {
  1999. x = g_pParentWnd->GetCamera()->Camera().origin[0];
  2000. y = g_pParentWnd->GetCamera()->Camera().origin[1];
  2001. a = g_pParentWnd->GetCamera()->Camera().angles[YAW]/180*Q_PI;
  2002. }
  2003. else if (m_nViewType == YZ)
  2004. {
  2005. x = g_pParentWnd->GetCamera()->Camera().origin[1];
  2006. y = g_pParentWnd->GetCamera()->Camera().origin[2];
  2007. a = g_pParentWnd->GetCamera()->Camera().angles[PITCH]/180*Q_PI;
  2008. }
  2009. else
  2010. {
  2011. x = g_pParentWnd->GetCamera()->Camera().origin[0];
  2012. y = g_pParentWnd->GetCamera()->Camera().origin[2];
  2013. a = g_pParentWnd->GetCamera()->Camera().angles[PITCH]/180*Q_PI;
  2014. }
  2015. qglColor3f (0.0, 0.0, 1.0);
  2016. qglBegin(GL_LINE_STRIP);
  2017. qglVertex3f (x-16,y,0);
  2018. qglVertex3f (x,y+8,0);
  2019. qglVertex3f (x+16,y,0);
  2020. qglVertex3f (x,y-8,0);
  2021. qglVertex3f (x-16,y,0);
  2022. qglVertex3f (x+16,y,0);
  2023. qglEnd ();
  2024. qglBegin(GL_LINE_STRIP);
  2025. qglVertex3f (x+48*cos(a+Q_PI/4), y+48*sin(a+Q_PI/4), 0);
  2026. qglVertex3f (x, y, 0);
  2027. qglVertex3f (x+48*cos(a-Q_PI/4), y+48*sin(a-Q_PI/4), 0);
  2028. qglEnd ();
  2029. #if 0
  2030. char text[128];
  2031. qglRasterPos2f (x+64, y+64);
  2032. sprintf (text, "%f",g_pParentWnd->GetCamera()->Camera().angles[YAW]);
  2033. qglCallLists (strlen(text), GL_UNSIGNED_BYTE, text);
  2034. #endif
  2035. }
  2036. void CXYWnd::DrawZIcon (void)
  2037. {
  2038. if (m_nViewType == XY)
  2039. {
  2040. float x = z.origin[0];
  2041. float y = z.origin[1];
  2042. qglEnable (GL_BLEND);
  2043. qglDisable (GL_TEXTURE_2D);
  2044. qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
  2045. qglDisable (GL_CULL_FACE);
  2046. qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  2047. qglColor4f (0.0, 0.0, 1.0, 0.25);
  2048. qglBegin(GL_QUADS);
  2049. qglVertex3f (x-8,y-8,0);
  2050. qglVertex3f (x+8,y-8,0);
  2051. qglVertex3f (x+8,y+8,0);
  2052. qglVertex3f (x-8,y+8,0);
  2053. qglEnd ();
  2054. qglDisable (GL_BLEND);
  2055. qglColor4f (0.0, 0.0, 1.0, 1);
  2056. qglBegin(GL_LINE_LOOP);
  2057. qglVertex3f (x-8,y-8,0);
  2058. qglVertex3f (x+8,y-8,0);
  2059. qglVertex3f (x+8,y+8,0);
  2060. qglVertex3f (x-8,y+8,0);
  2061. qglEnd ();
  2062. qglBegin(GL_LINE_STRIP);
  2063. qglVertex3f (x-4,y+4,0);
  2064. qglVertex3f (x+4,y+4,0);
  2065. qglVertex3f (x-4,y-4,0);
  2066. qglVertex3f (x+4,y-4,0);
  2067. qglEnd ();
  2068. }
  2069. }
  2070. /*
  2071. ==================
  2072. FilterBrush
  2073. ==================
  2074. */
  2075. BOOL FilterBrush(brush_t *pb)
  2076. {
  2077. if (!pb->owner)
  2078. return FALSE; // during construction
  2079. if (pb->hiddenBrush)
  2080. {
  2081. return TRUE;
  2082. }
  2083. if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_CAULK)
  2084. {
  2085. // filter out the brush only if all faces are caulk
  2086. // if not don't hide the whole brush, proceed on a per-face basis (Cam_Draw)
  2087. //++timo TODO: set this as a preference .. show caulk: hide any brush with caulk // don't draw caulk faces
  2088. face_t *f;
  2089. f=pb->brush_faces;
  2090. while (f)
  2091. {
  2092. if (!strstr(f->texdef.name, "caulk"))
  2093. break;
  2094. f = f->next;
  2095. }
  2096. if (!f)
  2097. return TRUE;
  2098. #if 0
  2099. if (strstr(pb->brush_faces->texdef.name, "caulk"))
  2100. return TRUE;
  2101. #endif
  2102. //++timo FIXME: .. same deal here?
  2103. if (strstr(pb->brush_faces->texdef.name, "donotenter"))
  2104. return TRUE;
  2105. }
  2106. if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_HINT)
  2107. {
  2108. if (strstr(pb->brush_faces->texdef.name, "hint"))
  2109. return TRUE;
  2110. }
  2111. if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_CLIP)
  2112. {
  2113. if (strstr(pb->brush_faces->texdef.name, "clip"))
  2114. return TRUE;
  2115. if (strstr(pb->brush_faces->texdef.name, "skip"))
  2116. return TRUE;
  2117. //if (!strncmp(pb->brush_faces->texdef.name, "clip", 4))
  2118. // return TRUE;
  2119. }
  2120. if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_WATER)
  2121. {
  2122. for (face_t* f = pb->brush_faces ; f ; f=f->next)
  2123. {
  2124. if (f->texdef.contents & (CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA))
  2125. return TRUE;
  2126. }
  2127. }
  2128. if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_DETAIL)
  2129. {
  2130. if (pb->brush_faces->texdef.contents & CONTENTS_DETAIL)
  2131. return TRUE;
  2132. }
  2133. if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_CURVES)
  2134. {
  2135. if (pb->patchBrush)
  2136. return TRUE;
  2137. }
  2138. if( g_qeglobals.d_savedinfo.exclude & EXCLUDE_TERRAIN )
  2139. {
  2140. if( pb->terrainBrush )
  2141. {
  2142. return TRUE;
  2143. }
  2144. }
  2145. if (pb->owner == world_entity)
  2146. {
  2147. if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_WORLD)
  2148. return TRUE;
  2149. return FALSE;
  2150. }
  2151. else
  2152. {
  2153. if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_ENT)
  2154. {
  2155. return (strncmp(pb->owner->eclass->name, "func_group", 10));
  2156. }
  2157. }
  2158. if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_LIGHTS)
  2159. {
  2160. return (pb->owner->eclass->nShowFlags & ECLASS_LIGHT);
  2161. //if (!strncmp(pb->owner->eclass->name, "light", 5))
  2162. // return TRUE;
  2163. }
  2164. if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_PATHS)
  2165. {
  2166. return (pb->owner->eclass->nShowFlags & ECLASS_PATH);
  2167. //if (!strncmp(pb->owner->eclass->name, "path", 4))
  2168. // return TRUE;
  2169. }
  2170. return FALSE;
  2171. }
  2172. /*
  2173. =============================================================
  2174. PATH LINES
  2175. =============================================================
  2176. */
  2177. /*
  2178. ==================
  2179. DrawPathLines
  2180. Draws connections between entities.
  2181. Needs to consider all entities, not just ones on screen,
  2182. because the lines can be visible when neither end is.
  2183. Called for both camera view and xy view.
  2184. ==================
  2185. */
  2186. void DrawPathLines (void)
  2187. {
  2188. int i, j, k;
  2189. vec3_t mid, mid1;
  2190. entity_t *se, *te;
  2191. brush_t *sb, *tb;
  2192. char *psz;
  2193. vec3_t dir, s1, s2;
  2194. vec_t len, f;
  2195. int arrows;
  2196. int num_entities;
  2197. char *ent_target[MAX_MAP_ENTITIES];
  2198. entity_t *ent_entity[MAX_MAP_ENTITIES];
  2199. if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_PATHS)
  2200. return;
  2201. num_entities = 0;
  2202. for (te = entities.next ; te != &entities && num_entities != MAX_MAP_ENTITIES ; te = te->next)
  2203. {
  2204. ent_target[num_entities] = ValueForKey (te, "target");
  2205. if (ent_target[num_entities][0])
  2206. {
  2207. ent_entity[num_entities] = te;
  2208. num_entities++;
  2209. }
  2210. }
  2211. for (se = entities.next ; se != &entities ; se = se->next)
  2212. {
  2213. psz = ValueForKey(se, "targetname");
  2214. if (psz == NULL || psz[0] == '\0')
  2215. continue;
  2216. sb = se->brushes.onext;
  2217. if (sb == &se->brushes)
  2218. continue;
  2219. for (k=0 ; k<num_entities ; k++)
  2220. {
  2221. if (strcmp (ent_target[k], psz))
  2222. continue;
  2223. te = ent_entity[k];
  2224. tb = te->brushes.onext;
  2225. if (tb == &te->brushes)
  2226. continue;
  2227. for (i=0 ; i<3 ; i++)
  2228. mid[i] = (sb->mins[i] + sb->maxs[i])*0.5;
  2229. for (i=0 ; i<3 ; i++)
  2230. mid1[i] = (tb->mins[i] + tb->maxs[i])*0.5;
  2231. VectorSubtract (mid1, mid, dir);
  2232. len = VectorNormalize (dir);
  2233. s1[0] = -dir[1]*8 + dir[0]*8;
  2234. s2[0] = dir[1]*8 + dir[0]*8;
  2235. s1[1] = dir[0]*8 + dir[1]*8;
  2236. s2[1] = -dir[0]*8 + dir[1]*8;
  2237. qglColor3f (se->eclass->color[0], se->eclass->color[1], se->eclass->color[2]);
  2238. qglBegin(GL_LINES);
  2239. qglVertex3fv(mid);
  2240. qglVertex3fv(mid1);
  2241. arrows = (int)(len / 256) + 1;
  2242. for (i=0 ; i<arrows ; i++)
  2243. {
  2244. f = len * (i + 0.5) / arrows;
  2245. for (j=0 ; j<3 ; j++)
  2246. mid1[j] = mid[j] + f*dir[j];
  2247. qglVertex3fv (mid1);
  2248. qglVertex3f (mid1[0] + s1[0], mid1[1] + s1[1], mid1[2]);
  2249. qglVertex3fv (mid1);
  2250. qglVertex3f (mid1[0] + s2[0], mid1[1] + s2[1], mid1[2]);
  2251. }
  2252. qglEnd();
  2253. }
  2254. }
  2255. return;
  2256. }
  2257. //=============================================================
  2258. // can be greatly simplified but per usual i am in a hurry
  2259. // which is not an excuse, just a fact
  2260. void CXYWnd::PaintSizeInfo(int nDim1, int nDim2, vec3_t vMinBounds, vec3_t vMaxBounds)
  2261. {
  2262. vec3_t vSize;
  2263. VectorSubtract(vMaxBounds, vMinBounds, vSize);
  2264. qglColor3f(g_qeglobals.d_savedinfo.colors[COLOR_SELBRUSHES][0] * .65,
  2265. g_qeglobals.d_savedinfo.colors[COLOR_SELBRUSHES][1] * .65,
  2266. g_qeglobals.d_savedinfo.colors[COLOR_SELBRUSHES][2] * .65);
  2267. if (m_nViewType == XY)
  2268. {
  2269. qglBegin (GL_LINES);
  2270. qglVertex3f(vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f);
  2271. qglVertex3f(vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
  2272. qglVertex3f(vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
  2273. qglVertex3f(vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
  2274. qglVertex3f(vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f);
  2275. qglVertex3f(vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
  2276. qglVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2], 0.0f);
  2277. qglVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f);
  2278. qglVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f);
  2279. qglVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f);
  2280. qglVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2], 0.0f);
  2281. qglVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f);
  2282. qglEnd();
  2283. qglRasterPos3f (Betwixt(vMinBounds[nDim1], vMaxBounds[nDim1]), vMinBounds[nDim2] - 20.0 / m_fScale, 0.0f);
  2284. g_strDim.Format(g_pDimStrings[nDim1], vSize[nDim1]);
  2285. qglCallLists (g_strDim.GetLength(), GL_UNSIGNED_BYTE, g_strDim);
  2286. qglRasterPos3f (vMaxBounds[nDim1] + 16.0 / m_fScale, Betwixt(vMinBounds[nDim2], vMaxBounds[nDim2]), 0.0f);
  2287. g_strDim.Format(g_pDimStrings[nDim2], vSize[nDim2]);
  2288. qglCallLists (g_strDim.GetLength(), GL_UNSIGNED_BYTE, g_strDim);
  2289. qglRasterPos3f (vMinBounds[nDim1] + 4, vMaxBounds[nDim2] + 8 / m_fScale, 0.0f);
  2290. g_strDim.Format(g_pOrgStrings[0], vMinBounds[nDim1], vMaxBounds[nDim2]);
  2291. qglCallLists (g_strDim.GetLength(), GL_UNSIGNED_BYTE, g_strDim);
  2292. }
  2293. else
  2294. if (m_nViewType == XZ)
  2295. {
  2296. qglBegin (GL_LINES);
  2297. qglVertex3f(vMinBounds[nDim1], 0, vMinBounds[nDim2] - 6.0f / m_fScale);
  2298. qglVertex3f(vMinBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale);
  2299. qglVertex3f(vMinBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale);
  2300. qglVertex3f(vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale);
  2301. qglVertex3f(vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 6.0f / m_fScale);
  2302. qglVertex3f(vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale);
  2303. qglVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMinBounds[nDim2]);
  2304. qglVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2]);
  2305. qglVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2]);
  2306. qglVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2]);
  2307. qglVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMaxBounds[nDim2]);
  2308. qglVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2]);
  2309. qglEnd();
  2310. qglRasterPos3f (Betwixt(vMinBounds[nDim1], vMaxBounds[nDim1]), 0, vMinBounds[nDim2] - 20.0 / m_fScale);
  2311. g_strDim.Format(g_pDimStrings[nDim1], vSize[nDim1]);
  2312. qglCallLists (g_strDim.GetLength(), GL_UNSIGNED_BYTE, g_strDim);
  2313. qglRasterPos3f (vMaxBounds[nDim1] + 16.0 / m_fScale, 0, Betwixt(vMinBounds[nDim2], vMaxBounds[nDim2]));
  2314. g_strDim.Format(g_pDimStrings[nDim2], vSize[nDim2]);
  2315. qglCallLists (g_strDim.GetLength(), GL_UNSIGNED_BYTE, g_strDim);
  2316. qglRasterPos3f (vMinBounds[nDim1] + 4, 0, vMaxBounds[nDim2] + 8 / m_fScale);
  2317. g_strDim.Format(g_pOrgStrings[1], vMinBounds[nDim1], vMaxBounds[nDim2]);
  2318. qglCallLists (g_strDim.GetLength(), GL_UNSIGNED_BYTE, g_strDim);
  2319. }
  2320. else
  2321. {
  2322. qglBegin (GL_LINES);
  2323. qglVertex3f(0, vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale);
  2324. qglVertex3f(0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
  2325. qglVertex3f(0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
  2326. qglVertex3f(0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
  2327. qglVertex3f(0, vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale);
  2328. qglVertex3f(0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
  2329. qglVertex3f(0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2]);
  2330. qglVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2]);
  2331. qglVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2]);
  2332. qglVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2]);
  2333. qglVertex3f(0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2]);
  2334. qglVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2]);
  2335. qglEnd();
  2336. qglRasterPos3f (0, Betwixt(vMinBounds[nDim1], vMaxBounds[nDim1]), vMinBounds[nDim2] - 20.0 / m_fScale);
  2337. g_strDim.Format(g_pDimStrings[nDim1], vSize[nDim1]);
  2338. qglCallLists (g_strDim.GetLength(), GL_UNSIGNED_BYTE, g_strDim);
  2339. qglRasterPos3f (0, vMaxBounds[nDim1] + 16.0 / m_fScale, Betwixt(vMinBounds[nDim2], vMaxBounds[nDim2]));
  2340. g_strDim.Format(g_pDimStrings[nDim2], vSize[nDim2]);
  2341. qglCallLists (g_strDim.GetLength(), GL_UNSIGNED_BYTE, g_strDim);
  2342. qglRasterPos3f (0, vMinBounds[nDim1] + 4.0, vMaxBounds[nDim2] + 8 / m_fScale);
  2343. g_strDim.Format(g_pOrgStrings[2], vMinBounds[nDim1], vMaxBounds[nDim2]);
  2344. qglCallLists (g_strDim.GetLength(), GL_UNSIGNED_BYTE, g_strDim);
  2345. }
  2346. }
  2347. /*
  2348. ==============
  2349. XY_Draw
  2350. ==============
  2351. */
  2352. long g_lCount = 0;
  2353. long g_lTotal = 0;
  2354. extern void DrawBrushEntityName (brush_t *b);
  2355. void CXYWnd::XY_Draw()
  2356. {
  2357. brush_t *brush;
  2358. float w, h;
  2359. entity_t *e;
  2360. double start, end;
  2361. double start2, end2;
  2362. vec3_t mins, maxs;
  2363. int drawn, culled;
  2364. int i;
  2365. if (!active_brushes.next)
  2366. return; // not valid yet
  2367. if (m_bTiming)
  2368. start = Sys_DoubleTime();
  2369. //
  2370. // clear
  2371. //
  2372. m_bDirty = false;
  2373. qglViewport(0, 0, m_nWidth, m_nHeight);
  2374. qglClearColor (g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][0],
  2375. g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][1],
  2376. g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][2],0);
  2377. qglClear(GL_COLOR_BUFFER_BIT);
  2378. //
  2379. // set up viewpoint
  2380. //
  2381. qglMatrixMode(GL_PROJECTION);
  2382. qglLoadIdentity ();
  2383. w = m_nWidth / 2 / m_fScale;
  2384. h = m_nHeight / 2/ m_fScale;
  2385. int nDim1 = (m_nViewType == YZ) ? 1 : 0;
  2386. int nDim2 = (m_nViewType == XY) ? 1 : 2;
  2387. mins[0] = m_vOrigin[nDim1] - w;
  2388. maxs[0] = m_vOrigin[nDim1] + w;
  2389. mins[1] = m_vOrigin[nDim2] - h;
  2390. maxs[1] = m_vOrigin[nDim2] + h;
  2391. qglOrtho (mins[0], maxs[0], mins[1], maxs[1], -8192, 8192);
  2392. //glRotatef
  2393. //
  2394. // now draw the grid
  2395. //
  2396. XY_DrawGrid ();
  2397. //
  2398. // draw stuff
  2399. //
  2400. qglShadeModel (GL_FLAT);
  2401. qglDisable(GL_TEXTURE_2D);
  2402. qglDisable(GL_TEXTURE_1D);
  2403. qglDisable(GL_DEPTH_TEST);
  2404. qglDisable(GL_BLEND);
  2405. qglColor3f(0, 0, 0);
  2406. //glEnable (GL_LINE_SMOOTH);
  2407. drawn = culled = 0;
  2408. if (m_nViewType != XY)
  2409. {
  2410. qglPushMatrix();
  2411. if (m_nViewType == YZ)
  2412. qglRotatef (-90, 0, 1, 0); // put Z going up
  2413. //else
  2414. qglRotatef (-90, 1, 0, 0); // put Z going up
  2415. }
  2416. e = world_entity;
  2417. if (m_bTiming)
  2418. start2 = Sys_DoubleTime();
  2419. for (brush = active_brushes.next ; brush != &active_brushes ; brush=brush->next)
  2420. {
  2421. if (brush->mins[nDim1] > maxs[0] ||
  2422. brush->mins[nDim2] > maxs[1] ||
  2423. brush->maxs[nDim1] < mins[0] ||
  2424. brush->maxs[nDim2] < mins[1])
  2425. {
  2426. culled++;
  2427. continue; // off screen
  2428. }
  2429. if (FilterBrush (brush))
  2430. continue;
  2431. drawn++;
  2432. if (brush->owner != e && brush->owner)
  2433. {
  2434. qglColor3fv(brush->owner->eclass->color);
  2435. }
  2436. else
  2437. {
  2438. qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_BRUSHES]);
  2439. }
  2440. Brush_DrawXY(brush, m_nViewType);
  2441. }
  2442. if (m_bTiming)
  2443. end2 = Sys_DoubleTime();
  2444. DrawPathLines ();
  2445. //
  2446. // draw pointfile
  2447. //
  2448. if ( g_qeglobals.d_pointfile_display_list)
  2449. qglCallList (g_qeglobals.d_pointfile_display_list);
  2450. if (!(m_nViewType == XY))
  2451. qglPopMatrix();
  2452. //
  2453. // draw block grid
  2454. //
  2455. if ( g_qeglobals.show_blocks)
  2456. XY_DrawBlockGrid ();
  2457. //
  2458. // now draw selected brushes
  2459. //
  2460. if (m_nViewType != XY)
  2461. {
  2462. qglPushMatrix();
  2463. if (m_nViewType == YZ)
  2464. qglRotatef (-90, 0, 1, 0); // put Z going up
  2465. //else
  2466. qglRotatef (-90, 1, 0, 0); // put Z going up
  2467. }
  2468. qglPushMatrix();
  2469. qglTranslatef( g_qeglobals.d_select_translate[0], g_qeglobals.d_select_translate[1], g_qeglobals.d_select_translate[2]);
  2470. if (RotateMode())
  2471. qglColor3f(0.8, 0.1, 0.9);
  2472. else
  2473. if (ScaleMode())
  2474. qglColor3f(0.1, 0.8, 0.1);
  2475. else
  2476. qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_SELBRUSHES]);
  2477. if (g_PrefsDlg.m_bNoStipple == FALSE)
  2478. {
  2479. qglEnable (GL_LINE_STIPPLE);
  2480. qglLineStipple (3, 0xaaaa);
  2481. }
  2482. qglLineWidth (2);
  2483. vec3_t vMinBounds;
  2484. vec3_t vMaxBounds;
  2485. vMinBounds[0] = vMinBounds[1] = vMinBounds[2] = 9999.9f;
  2486. vMaxBounds[0] = vMaxBounds[1] = vMaxBounds[2] = -9999.9f;
  2487. int nSaveDrawn = drawn;
  2488. bool bFixedSize = false;
  2489. for (brush = selected_brushes.next ; brush != &selected_brushes ; brush=brush->next)
  2490. {
  2491. drawn++;
  2492. Brush_DrawXY(brush, m_nViewType);
  2493. if (!bFixedSize)
  2494. {
  2495. if (brush->owner->eclass->fixedsize)
  2496. bFixedSize = true;
  2497. if (g_PrefsDlg.m_bSizePaint)
  2498. {
  2499. for (i = 0; i < 3; i ++)
  2500. {
  2501. if (brush->mins[i] < vMinBounds[i])
  2502. vMinBounds[i] = brush->mins[i];
  2503. if (brush->maxs[i] > vMaxBounds[i])
  2504. vMaxBounds[i] = brush->maxs[i];
  2505. }
  2506. }
  2507. }
  2508. }
  2509. if (g_PrefsDlg.m_bNoStipple == FALSE)
  2510. {
  2511. qglDisable (GL_LINE_STIPPLE);
  2512. }
  2513. qglLineWidth (1);
  2514. if (!bFixedSize && !RotateMode() && !ScaleMode() && drawn - nSaveDrawn > 0 && g_PrefsDlg.m_bSizePaint)
  2515. PaintSizeInfo(nDim1, nDim2, vMinBounds, vMaxBounds);
  2516. // edge / vertex flags
  2517. if (g_qeglobals.d_select_mode == sel_vertex)
  2518. {
  2519. qglPointSize (4);
  2520. qglColor3f (0,1,0);
  2521. qglBegin (GL_POINTS);
  2522. for (i=0 ; i<g_qeglobals.d_numpoints ; i++)
  2523. qglVertex3fv (g_qeglobals.d_points[i]);
  2524. qglEnd ();
  2525. qglPointSize (1);
  2526. }
  2527. else if (g_qeglobals.d_select_mode == sel_edge)
  2528. {
  2529. float *v1, *v2;
  2530. qglPointSize (4);
  2531. qglColor3f (0,0,1);
  2532. qglBegin (GL_POINTS);
  2533. for (i=0 ; i<g_qeglobals.d_numedges ; i++)
  2534. {
  2535. v1 = g_qeglobals.d_points[g_qeglobals.d_edges[i].p1];
  2536. v2 = g_qeglobals.d_points[g_qeglobals.d_edges[i].p2];
  2537. qglVertex3f ( (v1[0]+v2[0])*0.5,(v1[1]+v2[1])*0.5,(v1[2]+v2[2])*0.5);
  2538. }
  2539. qglEnd ();
  2540. qglPointSize (1);
  2541. }
  2542. g_splineList->draw(static_cast<qboolean>(g_qeglobals.d_select_mode == sel_editpoint || g_qeglobals.d_select_mode == sel_addpoint));
  2543. qglPopMatrix();
  2544. qglTranslatef (-g_qeglobals.d_select_translate[0], -g_qeglobals.d_select_translate[1], -g_qeglobals.d_select_translate[2]);
  2545. if (!(m_nViewType == XY))
  2546. qglPopMatrix();
  2547. // area selection hack
  2548. if (g_qeglobals.d_select_mode == sel_area)
  2549. {
  2550. qglEnable (GL_BLEND);
  2551. qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  2552. qglColor4f(0.0, 0.0, 1.0, 0.25);
  2553. qglRectf(g_qeglobals.d_vAreaTL[nDim1], g_qeglobals.d_vAreaTL[nDim2], g_qeglobals.d_vAreaBR[nDim1], g_qeglobals.d_vAreaBR[nDim2]);
  2554. qglDisable (GL_BLEND);
  2555. }
  2556. //
  2557. // now draw camera point
  2558. //
  2559. DrawCameraIcon ();
  2560. DrawZIcon ();
  2561. if (RotateMode())
  2562. {
  2563. DrawRotateIcon();
  2564. }
  2565. // plugin entities
  2566. //++timo TODO: use an object for the 2D view
  2567. DrawPluginEntities( (VIEWTYPE)m_nViewType );
  2568. qglFinish();
  2569. //QE_CheckOpenGLForErrors();
  2570. if (m_bTiming)
  2571. {
  2572. end = Sys_DoubleTime ();
  2573. i = (int)(1000*(end-start));
  2574. int i3 = (int)(1000*(end2-start2));
  2575. g_lCount++;
  2576. g_lTotal += i;
  2577. int i2 = g_lTotal / g_lCount;
  2578. Sys_Printf ("xy: %i ab: %i avg: %i\n", i, i3, i2);
  2579. }
  2580. }
  2581. /*
  2582. ==============
  2583. XY_Overlay
  2584. ==============
  2585. */
  2586. void CXYWnd::XY_Overlay()
  2587. {
  2588. int w, h;
  2589. int r[4];
  2590. static vec3_t lastz;
  2591. static vec3_t lastcamera;
  2592. qglViewport(0, 0, m_nWidth, m_nHeight);
  2593. //
  2594. // set up viewpoint
  2595. //
  2596. qglMatrixMode(GL_PROJECTION);
  2597. qglLoadIdentity ();
  2598. w = m_nWidth / 2 / m_fScale;
  2599. h = m_nHeight / 2 / m_fScale;
  2600. qglOrtho (m_vOrigin[0] - w, m_vOrigin[0] + w , m_vOrigin[1] - h, m_vOrigin[1] + h, -8000, 8000);
  2601. //
  2602. // erase the old camera and z checker positions
  2603. // if the entire xy hasn't been redrawn
  2604. //
  2605. if (m_bDirty)
  2606. {
  2607. qglReadBuffer (GL_BACK);
  2608. qglDrawBuffer (GL_FRONT);
  2609. qglRasterPos2f (lastz[0]-9, lastz[1]-9);
  2610. qglGetIntegerv (GL_CURRENT_RASTER_POSITION,r);
  2611. qglCopyPixels(r[0], r[1], 18,18, GL_COLOR);
  2612. qglRasterPos2f (lastcamera[0]-50, lastcamera[1]-50);
  2613. qglGetIntegerv (GL_CURRENT_RASTER_POSITION,r);
  2614. qglCopyPixels(r[0], r[1], 100,100, GL_COLOR);
  2615. }
  2616. m_bDirty = true;
  2617. //
  2618. // save off underneath where we are about to draw
  2619. //
  2620. VectorCopy (z.origin, lastz);
  2621. VectorCopy (g_pParentWnd->GetCamera()->Camera().origin, lastcamera);
  2622. qglReadBuffer (GL_FRONT);
  2623. qglDrawBuffer (GL_BACK);
  2624. qglRasterPos2f (lastz[0]-9, lastz[1]-9);
  2625. qglGetIntegerv (GL_CURRENT_RASTER_POSITION,r);
  2626. qglCopyPixels(r[0], r[1], 18,18, GL_COLOR);
  2627. qglRasterPos2f (lastcamera[0]-50, lastcamera[1]-50);
  2628. qglGetIntegerv (GL_CURRENT_RASTER_POSITION,r);
  2629. qglCopyPixels(r[0], r[1], 100,100, GL_COLOR);
  2630. //
  2631. // draw the new icons
  2632. //
  2633. qglDrawBuffer (GL_FRONT);
  2634. qglShadeModel (GL_FLAT);
  2635. qglDisable(GL_TEXTURE_2D);
  2636. qglDisable(GL_TEXTURE_1D);
  2637. qglDisable(GL_DEPTH_TEST);
  2638. qglDisable(GL_BLEND);
  2639. qglColor3f(0, 0, 0);
  2640. DrawCameraIcon ();
  2641. DrawZIcon ();
  2642. qglDrawBuffer (GL_BACK);
  2643. qglFinish();
  2644. }
  2645. vec3_t& CXYWnd::GetOrigin()
  2646. {
  2647. return m_vOrigin;
  2648. }
  2649. void CXYWnd::SetOrigin(vec3_t org)
  2650. {
  2651. m_vOrigin[0] = org[0];
  2652. m_vOrigin[1] = org[1];
  2653. m_vOrigin[2] = org[2];
  2654. }
  2655. void CXYWnd::OnSize(UINT nType, int cx, int cy)
  2656. {
  2657. CWnd::OnSize(nType, cx, cy);
  2658. CRect rect;
  2659. GetClientRect(rect);
  2660. m_nWidth = rect.Width();
  2661. m_nHeight = rect.Height();
  2662. }
  2663. brush_t hold_brushes;
  2664. void CXYWnd::Clip()
  2665. {
  2666. if (ClipMode())
  2667. {
  2668. hold_brushes.next = &hold_brushes;
  2669. ProduceSplitLists();
  2670. //brush_t* pList = (g_bSwitch) ? &g_brFrontSplits : &g_brBackSplits;
  2671. brush_t* pList;
  2672. if (g_PrefsDlg.m_bSwitchClip)
  2673. pList = ( (m_nViewType == XZ) ? g_bSwitch: !g_bSwitch) ? &g_brFrontSplits : &g_brBackSplits;
  2674. else
  2675. pList = ( (m_nViewType == XZ) ? !g_bSwitch: g_bSwitch) ? &g_brFrontSplits : &g_brBackSplits;
  2676. if (pList->next != pList)
  2677. {
  2678. Brush_CopyList(pList, &hold_brushes);
  2679. CleanList(&g_brFrontSplits);
  2680. CleanList(&g_brBackSplits);
  2681. Select_Delete();
  2682. Brush_CopyList(&hold_brushes, &selected_brushes);
  2683. if (RogueClipMode())
  2684. RetainClipMode(false);
  2685. else
  2686. RetainClipMode(true);
  2687. Sys_UpdateWindows(W_ALL);
  2688. }
  2689. }
  2690. else if (PathMode())
  2691. {
  2692. FinishSmartCreation();
  2693. if (g_pPathFunc)
  2694. g_pPathFunc(true, g_nPathCount);
  2695. g_pPathFunc = NULL;
  2696. g_nPathCount = 0;
  2697. g_bPathMode = false;
  2698. }
  2699. }
  2700. void CXYWnd::SplitClip()
  2701. {
  2702. ProduceSplitLists();
  2703. if ((g_brFrontSplits.next != &g_brFrontSplits) &&
  2704. (g_brBackSplits.next != &g_brBackSplits))
  2705. {
  2706. Select_Delete();
  2707. Brush_CopyList(&g_brFrontSplits, &selected_brushes);
  2708. Brush_CopyList(&g_brBackSplits, &selected_brushes);
  2709. CleanList(&g_brFrontSplits);
  2710. CleanList(&g_brBackSplits);
  2711. if (RogueClipMode())
  2712. RetainClipMode(false);
  2713. else
  2714. RetainClipMode(true);
  2715. }
  2716. }
  2717. void CXYWnd::FlipClip()
  2718. {
  2719. g_bSwitch = !g_bSwitch;
  2720. Sys_UpdateWindows(XY | W_CAMERA_IFON);
  2721. }
  2722. // makes sure the selected brush or camera is in view
  2723. void CXYWnd::PositionView()
  2724. {
  2725. int nDim1 = (m_nViewType == YZ) ? 1 : 0;
  2726. int nDim2 = (m_nViewType == XY) ? 1 : 2;
  2727. brush_t* b = selected_brushes.next;
  2728. if (b && b->next != b)
  2729. {
  2730. m_vOrigin[nDim1] = b->mins[nDim1];
  2731. m_vOrigin[nDim2] = b->mins[nDim2];
  2732. }
  2733. else
  2734. {
  2735. m_vOrigin[nDim1] = g_pParentWnd->GetCamera()->Camera().origin[nDim1];
  2736. m_vOrigin[nDim2] = g_pParentWnd->GetCamera()->Camera().origin[nDim2];
  2737. }
  2738. }
  2739. void CXYWnd::VectorCopyXY(vec3_t in, vec3_t out)
  2740. {
  2741. if (m_nViewType == XY)
  2742. {
  2743. out[0] = in[0];
  2744. out[1] = in[1];
  2745. }
  2746. else
  2747. if (m_nViewType == XZ)
  2748. {
  2749. out[0] = in[0];
  2750. out[2] = in[2];
  2751. }
  2752. else
  2753. {
  2754. out[1] = in[1];
  2755. out[2] = in[2];
  2756. }
  2757. }
  2758. void CXYWnd::OnDestroy()
  2759. {
  2760. QEW_StopGL( GetSafeHwnd(), s_hglrcXY, s_hdcXY );
  2761. CWnd::OnDestroy();
  2762. // delete this;
  2763. }
  2764. void CXYWnd::SetViewType(int n)
  2765. {
  2766. m_nViewType = n;
  2767. if (g_pParentWnd->CurrentStyle() == QR_QE4)
  2768. {
  2769. CString str = "YZ Side";
  2770. if (m_nViewType == XY)
  2771. str = "XY Top";
  2772. else if (m_nViewType == XZ)
  2773. str = "XZ Front";
  2774. SetWindowText(str);
  2775. }
  2776. };
  2777. void CXYWnd::Redraw(unsigned int nBits)
  2778. {
  2779. m_nUpdateBits = nBits;
  2780. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  2781. m_nUpdateBits = W_XY;
  2782. }
  2783. bool CXYWnd::RotateMode()
  2784. {
  2785. return g_bRotateMode;
  2786. }
  2787. bool CXYWnd::ScaleMode()
  2788. {
  2789. return g_bScaleMode;
  2790. }
  2791. bool CXYWnd::SetRotateMode(bool bMode)
  2792. {
  2793. if (bMode && selected_brushes.next != &selected_brushes)
  2794. {
  2795. g_bRotateMode = true;
  2796. Select_GetTrueMid(g_vRotateOrigin);
  2797. g_vRotation[0] = g_vRotation[1] = g_vRotation[2] = 0.0;
  2798. }
  2799. else
  2800. {
  2801. if (bMode)
  2802. Sys_Printf("Need a brush selected to turn on Mouse Rotation mode\n");
  2803. g_bRotateMode = false;
  2804. }
  2805. RedrawWindow();
  2806. return g_bRotateMode;
  2807. }
  2808. void CXYWnd::SetScaleMode(bool bMode)
  2809. {
  2810. g_bScaleMode = bMode;
  2811. RedrawWindow();
  2812. }
  2813. // xy - z
  2814. // xz - y
  2815. // yz - x
  2816. void CXYWnd::OnSelectMouserotate()
  2817. {
  2818. // TODO: Add your command handler code here
  2819. }
  2820. void CleanCopyEntities()
  2821. {
  2822. entity_t* pe = g_enClipboard.next;
  2823. while (pe != NULL && pe != &g_enClipboard)
  2824. {
  2825. entity_t* next = pe->next;
  2826. epair_t* enext = NULL;
  2827. for (epair_t* ep = pe->epairs ; ep ; ep=enext)
  2828. {
  2829. enext = ep->next;
  2830. free (ep->key);
  2831. free (ep->value);
  2832. free (ep);
  2833. }
  2834. free (pe);
  2835. pe = next;
  2836. }
  2837. g_enClipboard.next = g_enClipboard.prev = &g_enClipboard;
  2838. }
  2839. entity_t *Entity_CopyClone (entity_t *e)
  2840. {
  2841. entity_t *n;
  2842. epair_t *ep, *np;
  2843. n = (entity_t*)qmalloc(sizeof(*n));
  2844. n->brushes.onext = n->brushes.oprev = &n->brushes;
  2845. n->eclass = e->eclass;
  2846. // add the entity to the entity list
  2847. n->next = g_enClipboard.next;
  2848. g_enClipboard.next = n;
  2849. n->next->prev = n;
  2850. n->prev = &g_enClipboard;
  2851. for (ep = e->epairs ; ep ; ep=ep->next)
  2852. {
  2853. np = (epair_t*)qmalloc(sizeof(*np));
  2854. np->key = copystring(ep->key);
  2855. np->value = copystring(ep->value);
  2856. np->next = n->epairs;
  2857. n->epairs = np;
  2858. }
  2859. return n;
  2860. }
  2861. bool OnList(entity_t* pFind, CPtrArray* pList)
  2862. {
  2863. int nSize = pList->GetSize();
  2864. while (nSize-- > 0)
  2865. {
  2866. entity_t* pEntity = reinterpret_cast<entity_t*>(pList->GetAt(nSize));
  2867. if (pEntity == pFind)
  2868. return true;
  2869. }
  2870. return false;
  2871. }
  2872. void CXYWnd::Copy()
  2873. {
  2874. #if 1
  2875. CWaitCursor WaitCursor;
  2876. g_Clipboard.SetLength(0);
  2877. g_PatchClipboard.SetLength(0);
  2878. Map_SaveSelected(&g_Clipboard, &g_PatchClipboard);
  2879. bool bClipped = false;
  2880. UINT nClipboard = ::RegisterClipboardFormat("RadiantClippings");
  2881. if (nClipboard > 0)
  2882. {
  2883. if (OpenClipboard())
  2884. {
  2885. ::EmptyClipboard();
  2886. long lSize = g_Clipboard.GetLength();
  2887. HANDLE h = ::GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE | GMEM_DDESHARE, lSize + sizeof(long));
  2888. if (h != NULL)
  2889. {
  2890. unsigned char *cp = reinterpret_cast<unsigned char*>(::GlobalLock(h));
  2891. memcpy(cp, &lSize, sizeof(long));
  2892. cp += sizeof(long);
  2893. g_Clipboard.SeekToBegin();
  2894. g_Clipboard.Read(cp, lSize);
  2895. ::GlobalUnlock(h);
  2896. ::SetClipboardData(nClipboard, h);
  2897. ::CloseClipboard();
  2898. bClipped = true;
  2899. }
  2900. }
  2901. }
  2902. if (!bClipped)
  2903. {
  2904. Sys_Printf("Unable to register Windows clipboard formats, copy/paste between editors will not be possible");
  2905. }
  2906. /*
  2907. CString strOut;
  2908. ::GetTempPath(1024, strOut.GetBuffer(1024));
  2909. strOut.ReleaseBuffer();
  2910. AddSlash(strOut);
  2911. strOut += "RadiantClipboard.$$$";
  2912. Map_SaveSelected(strOut.GetBuffer(0));
  2913. */
  2914. #else
  2915. CPtrArray holdArray;
  2916. CleanList(&g_brClipboard);
  2917. CleanCopyEntities();
  2918. for (brush_t* pBrush = selected_brushes.next ; pBrush != NULL && pBrush != &selected_brushes ; pBrush=pBrush->next)
  2919. {
  2920. if (pBrush->owner == world_entity)
  2921. {
  2922. brush_t* pClone = Brush_Clone(pBrush);
  2923. pClone->owner = NULL;
  2924. Brush_AddToList (pClone, &g_brClipboard);
  2925. }
  2926. else
  2927. {
  2928. if (!OnList(pBrush->owner, &holdArray))
  2929. {
  2930. entity_t* e = pBrush->owner;
  2931. holdArray.Add(reinterpret_cast<void*>(e));
  2932. entity_t* pEClone = Entity_CopyClone(e);
  2933. for (brush_t* pEB = e->brushes.onext ; pEB != &e->brushes ; pEB=pEB->onext)
  2934. {
  2935. brush_t* pClone = Brush_Clone(pEB);
  2936. //Brush_AddToList (pClone, &g_brClipboard);
  2937. Entity_LinkBrush(pEClone, pClone);
  2938. Brush_Build(pClone);
  2939. }
  2940. }
  2941. }
  2942. }
  2943. #endif
  2944. }
  2945. void CXYWnd::Undo()
  2946. {
  2947. /*
  2948. if (g_brUndo.next != &g_brUndo)
  2949. {
  2950. g_bScreenUpdates = false;
  2951. Select_Delete();
  2952. for (brush_t* pBrush = g_brUndo.next ; pBrush != NULL && pBrush != &g_brUndo ; pBrush=pBrush->next)
  2953. {
  2954. brush_t* pClone = Brush_Clone(pBrush);
  2955. Brush_AddToList (pClone, &active_brushes);
  2956. Entity_LinkBrush (pBrush->pUndoOwner, pClone);
  2957. Brush_Build(pClone);
  2958. Select_Brush(pClone);
  2959. }
  2960. CleanList(&g_brUndo);
  2961. g_bScreenUpdates = true;
  2962. Sys_UpdateWindows(W_ALL);
  2963. }
  2964. else Sys_Printf("Nothing to undo.../n");
  2965. */
  2966. }
  2967. void CXYWnd::UndoClear()
  2968. {
  2969. /*
  2970. CleanList(&g_brUndo);
  2971. */
  2972. }
  2973. void CXYWnd::UndoCopy()
  2974. {
  2975. /*
  2976. CleanList(&g_brUndo);
  2977. for (brush_t* pBrush = selected_brushes.next ; pBrush != NULL && pBrush != &selected_brushes ; pBrush=pBrush->next)
  2978. {
  2979. brush_t* pClone = Brush_Clone(pBrush);
  2980. pClone->pUndoOwner = pBrush->owner;
  2981. Brush_AddToList (pClone, &g_brUndo);
  2982. }
  2983. */
  2984. }
  2985. bool CXYWnd::UndoAvailable()
  2986. {
  2987. return (g_brUndo.next != &g_brUndo);
  2988. }
  2989. void CXYWnd::Paste()
  2990. {
  2991. #if 1
  2992. CWaitCursor WaitCursor;
  2993. bool bPasted = false;
  2994. UINT nClipboard = ::RegisterClipboardFormat("RadiantClippings");
  2995. if (nClipboard > 0 && OpenClipboard() && ::IsClipboardFormatAvailable(nClipboard))
  2996. {
  2997. HANDLE h = ::GetClipboardData(nClipboard);
  2998. if (h)
  2999. {
  3000. g_Clipboard.SetLength(0);
  3001. unsigned char *cp = reinterpret_cast<unsigned char*>(::GlobalLock(h));
  3002. long lSize = 0;
  3003. memcpy(&lSize, cp, sizeof(long));
  3004. cp += sizeof(long);
  3005. g_Clipboard.Write(cp, lSize);
  3006. }
  3007. ::GlobalUnlock(h);
  3008. ::CloseClipboard();
  3009. }
  3010. if (g_Clipboard.GetLength() > 0)
  3011. {
  3012. g_Clipboard.SeekToBegin();
  3013. int nLen = g_Clipboard.GetLength();
  3014. char* pBuffer = new char[nLen+1];
  3015. memset( pBuffer, 0, sizeof(pBuffer) );
  3016. g_Clipboard.Read(pBuffer, nLen);
  3017. pBuffer[nLen] = '\0';
  3018. Map_ImportBuffer(pBuffer);
  3019. delete []pBuffer;
  3020. }
  3021. #if 0
  3022. if (g_PatchClipboard.GetLength() > 0)
  3023. {
  3024. g_PatchClipboard.SeekToBegin();
  3025. int nLen = g_PatchClipboard.GetLength();
  3026. char* pBuffer = new char[nLen+1];
  3027. g_PatchClipboard.Read(pBuffer, nLen);
  3028. pBuffer[nLen] = '\0';
  3029. Patch_ReadBuffer(pBuffer, true);
  3030. delete []pBuffer;
  3031. }
  3032. #endif
  3033. #else
  3034. if (g_brClipboard.next != &g_brClipboard || g_enClipboard.next != &g_enClipboard)
  3035. {
  3036. Select_Deselect();
  3037. for (brush_t* pBrush = g_brClipboard.next ; pBrush != NULL && pBrush != &g_brClipboard ; pBrush=pBrush->next)
  3038. {
  3039. brush_t* pClone = Brush_Clone(pBrush);
  3040. //pClone->owner = pBrush->owner;
  3041. if (pClone->owner == NULL)
  3042. Entity_LinkBrush (world_entity, pClone);
  3043. Brush_AddToList (pClone, &selected_brushes);
  3044. Brush_Build(pClone);
  3045. }
  3046. for (entity_t* pEntity = g_enClipboard.next; pEntity != NULL && pEntity != &g_enClipboard; pEntity = pEntity->next)
  3047. {
  3048. entity_t* pEClone = Entity_Clone(pEntity);
  3049. for (brush_t* pEB = pEntity->brushes.onext ; pEB != &pEntity->brushes ; pEB=pEB->onext)
  3050. {
  3051. brush_t* pClone = Brush_Clone(pEB);
  3052. Brush_AddToList (pClone, &selected_brushes);
  3053. Entity_LinkBrush(pEClone, pClone);
  3054. Brush_Build(pClone);
  3055. if (pClone->owner && pClone->owner != world_entity)
  3056. {
  3057. UpdateEntitySel(pClone->owner->eclass);
  3058. }
  3059. }
  3060. }
  3061. Sys_UpdateWindows(W_ALL);
  3062. }
  3063. else Sys_Printf("Nothing to paste.../n");
  3064. #endif
  3065. }
  3066. vec3_t& CXYWnd::Rotation()
  3067. {
  3068. return g_vRotation;
  3069. }
  3070. vec3_t& CXYWnd::RotateOrigin()
  3071. {
  3072. return g_vRotateOrigin;
  3073. }
  3074. void CXYWnd::OnTimer(UINT nIDEvent)
  3075. {
  3076. int nDim1 = (m_nViewType == YZ) ? 1 : 0;
  3077. int nDim2 = (m_nViewType == XY) ? 1 : 2;
  3078. m_vOrigin[nDim1] += m_ptDragAdj.x / m_fScale;
  3079. m_vOrigin[nDim2] -= m_ptDragAdj.y / m_fScale;
  3080. Sys_UpdateWindows(W_XY | W_CAMERA);
  3081. //int nH = (m_ptDrag.y == 0) ? -1 : m_ptDrag.y;
  3082. m_ptDrag += m_ptDragAdj;
  3083. m_ptDragTotal += m_ptDragAdj;
  3084. XY_MouseMoved (m_ptDrag.x, m_nHeight - 1 - m_ptDrag.y , m_nScrollFlags);
  3085. //m_vOrigin[nDim1] -= m_ptDrag.x / m_fScale;
  3086. //m_vOrigin[nDim1] -= m_ptDrag.x / m_fScale;
  3087. }
  3088. void CXYWnd::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
  3089. {
  3090. g_pParentWnd->HandleKey(nChar, nRepCnt, nFlags, false);
  3091. //CWnd::OnKeyUp(nChar, nRepCnt, nFlags);
  3092. }
  3093. void CXYWnd::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
  3094. {
  3095. CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
  3096. }
  3097. void CXYWnd::OnKillFocus(CWnd* pNewWnd)
  3098. {
  3099. CWnd::OnKillFocus(pNewWnd);
  3100. SendMessage(WM_NCACTIVATE, FALSE , 0 );
  3101. }
  3102. void CXYWnd::OnSetFocus(CWnd* pOldWnd)
  3103. {
  3104. CWnd::OnSetFocus(pOldWnd);
  3105. SendMessage(WM_NCACTIVATE, TRUE , 0 );
  3106. }
  3107. void CXYWnd::OnClose()
  3108. {
  3109. CWnd::OnClose();
  3110. }
  3111. // should be static as should be the rotate scale stuff
  3112. bool CXYWnd::AreaSelectOK()
  3113. {
  3114. return RotateMode() ? false : ScaleMode() ? false : true;
  3115. }