XYWnd.cpp 131 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "../../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "qe3.h"
  23. #include "Radiant.h"
  24. #include "XYWnd.h"
  25. #include "DialogInfo.h"
  26. #include "splines.h"
  27. #include "../../renderer/tr_local.h"
  28. #include "../../renderer/model_local.h" // for idRenderModelLiquid
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. const char *g_pDimStrings[] = { "x:%.f", "y:%.f", "z:%.f" };
  35. const char *g_pOrgStrings[] = { "(x:%.f y:%.f)", "(x:%.f z:%.f)", "(y:%.f z:%.f)" };
  36. CString g_strDim;
  37. CString g_strStatus;
  38. bool g_bCrossHairs = false;
  39. bool g_bScaleMode;
  40. int g_nScaleHow;
  41. bool g_bRotateMode;
  42. bool g_bClipMode;
  43. bool g_bRogueClipMode;
  44. bool g_bSwitch;
  45. CClipPoint g_Clip1;
  46. CClipPoint g_Clip2;
  47. CClipPoint g_Clip3;
  48. CClipPoint *g_pMovingClip;
  49. brush_t g_brFrontSplits;
  50. brush_t g_brBackSplits;
  51. brush_t g_brClipboard;
  52. brush_t g_brUndo;
  53. entity_t g_enClipboard;
  54. idVec3 g_vRotateOrigin;
  55. idVec3 g_vRotation;
  56. bool g_bPathMode;
  57. CClipPoint g_PathPoints[256];
  58. CClipPoint *g_pMovingPath;
  59. int g_nPathCount;
  60. int g_nPathLimit;
  61. bool g_bSmartGo;
  62. bool g_bPointMode;
  63. CClipPoint g_PointPoints[512];
  64. CClipPoint *g_pMovingPoint;
  65. int g_nPointCount;
  66. int g_nPointLimit;
  67. const int XY_LEFT = 0x01;
  68. const int XY_RIGHT = 0x02;
  69. const int XY_UP = 0x04;
  70. const int XY_DOWN = 0x08;
  71. PFNPathCallback *g_pPathFunc = NULL;
  72. void Select_Ungroup();
  73. /*
  74. =======================================================================================================================
  75. =======================================================================================================================
  76. */
  77. void AcquirePath(int nCount, PFNPathCallback *pFunc) {
  78. g_nPathCount = 0;
  79. g_nPathLimit = nCount;
  80. g_pPathFunc = pFunc;
  81. g_bPathMode = true;
  82. }
  83. CPtrArray g_ptrMenus;
  84. CMemFile g_Clipboard(4096);
  85. CMemFile g_PatchClipboard(4096);
  86. extern int pressx;
  87. extern int pressy;
  88. /*
  89. =======================================================================================================================
  90. =======================================================================================================================
  91. */
  92. float fDiff(float f1, float f2) {
  93. if (f1 > f2) {
  94. return f1 - f2;
  95. }
  96. else {
  97. return f2 - f1;
  98. }
  99. }
  100. #define MAX_DRAG_POINTS 128
  101. CPtrArray dragPoints;
  102. static CDragPoint *activeDrag = NULL;
  103. static bool activeDragging = false;
  104. /*
  105. =======================================================================================================================
  106. =======================================================================================================================
  107. */
  108. bool CDragPoint::PointWithin(idVec3 p, int nView) {
  109. if (nView == -1) {
  110. if (fDiff(p[0], vec[0]) <= 3 && fDiff(p[1], vec[1]) <= 3 && fDiff(p[2], vec[2]) <= 3) {
  111. return true;
  112. }
  113. }
  114. else {
  115. int nDim1 = (nView == YZ) ? 1 : 0;
  116. int nDim2 = (nView == XY) ? 1 : 2;
  117. if (fDiff(p[nDim1], vec[nDim1]) <= 3 && fDiff(p[nDim2], vec[nDim2]) <= 3) {
  118. return true;
  119. }
  120. }
  121. return false;
  122. }
  123. /*
  124. =======================================================================================================================
  125. =======================================================================================================================
  126. */
  127. CDragPoint *PointRay(const idVec3 &org, const idVec3 &dir, float *dist) {
  128. int i, besti;
  129. float d, bestd;
  130. idVec3 temp;
  131. CDragPoint *drag = NULL;
  132. CDragPoint *priority = NULL;
  133. // find the point closest to the ray
  134. float scale = g_pParentWnd->ActiveXY()->Scale();
  135. besti = -1;
  136. bestd = 12 / scale / 2;
  137. int count = dragPoints.GetSize();
  138. for (i = 0; i < count; i++) {
  139. drag = reinterpret_cast < CDragPoint * > (dragPoints[i]);
  140. temp = drag->vec - org;
  141. d = temp * dir;
  142. temp = org + d * dir;
  143. temp = drag->vec - temp;
  144. d = temp.Length();
  145. if ( d < bestd ) {
  146. bestd = d;
  147. besti = i;
  148. if (priority == NULL) {
  149. priority = reinterpret_cast < CDragPoint * > (dragPoints[besti]);
  150. if (!priority->priority) {
  151. priority = NULL;
  152. }
  153. }
  154. }
  155. }
  156. if (besti == -1) {
  157. return NULL;
  158. }
  159. drag = reinterpret_cast < CDragPoint * > (dragPoints[besti]);
  160. if (priority && !drag->priority) {
  161. drag = priority;
  162. }
  163. return drag;
  164. }
  165. /*
  166. =======================================================================================================================
  167. =======================================================================================================================
  168. */
  169. void ClearSelectablePoints(brush_t *b) {
  170. if (b == NULL) {
  171. dragPoints.RemoveAll();
  172. }
  173. else {
  174. CPtrArray ptr;
  175. ptr.Copy(dragPoints);
  176. dragPoints.RemoveAll();
  177. int count = ptr.GetSize();
  178. for (int i = 0; i < count; i++) {
  179. if (b == reinterpret_cast < CDragPoint * > ( ptr.GetAt(i))->pBrush ) {
  180. continue;
  181. }
  182. else {
  183. dragPoints.Add(ptr.GetAt(i));
  184. }
  185. }
  186. }
  187. }
  188. /*
  189. =======================================================================================================================
  190. =======================================================================================================================
  191. */
  192. void AddSelectablePoint(brush_t *b, idVec3 v, int type, bool priority) {
  193. dragPoints.Add(new CDragPoint(b, v, type, priority));
  194. }
  195. /*
  196. =======================================================================================================================
  197. =======================================================================================================================
  198. */
  199. void UpdateSelectablePoint(brush_t *b, idVec3 v, int type) {
  200. int count = dragPoints.GetSize();
  201. for (int i = 0; i < count; i++) {
  202. CDragPoint *drag = reinterpret_cast < CDragPoint * > (dragPoints.GetAt(i));
  203. if (b == drag->pBrush && type == drag->nType) {
  204. VectorCopy(v, drag->vec);
  205. return;
  206. }
  207. }
  208. }
  209. /*
  210. =======================================================================================================================
  211. =======================================================================================================================
  212. */
  213. void VectorToAngles(idVec3 vec, idVec3 angles) {
  214. float forward;
  215. float yaw, pitch;
  216. if ((vec[0] == 0) && (vec[1] == 0)) {
  217. yaw = 0;
  218. if (vec[2] > 0) {
  219. pitch = 90;
  220. }
  221. else {
  222. pitch = 270;
  223. }
  224. }
  225. else {
  226. yaw = RAD2DEG( atan2(vec[1], vec[0]) );
  227. if (yaw < 0) {
  228. yaw += 360;
  229. }
  230. forward = (float)idMath::Sqrt(vec[0] * vec[0] + vec[1] * vec[1]);
  231. pitch = RAD2DEG( atan2(vec[2], forward) );
  232. if (pitch < 0) {
  233. pitch += 360;
  234. }
  235. }
  236. angles[0] = pitch;
  237. angles[1] = yaw;
  238. angles[2] = 0;
  239. }
  240. /*
  241. =======================================================================================================================
  242. RotateLight target is relative to the light origin up and right are relative to the target up and right are
  243. perpendicular and are on a plane through the target with the target vector as normal delta is the movement of the
  244. target relative to the light
  245. =======================================================================================================================
  246. */
  247. void VectorSnapGrid(idVec3 &v) {
  248. v.x = floor(v.x / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
  249. v.y = floor(v.y / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
  250. v.z = floor(v.z / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
  251. }
  252. /*
  253. =======================================================================================================================
  254. =======================================================================================================================
  255. */
  256. static void RotateLight(idVec3 &target, idVec3 &up, idVec3 &right, const idVec3 &delta) {
  257. idVec3 newtarget, cross, dst;
  258. idVec3 normal;
  259. double angle, dist, d, len;
  260. idMat3 rot;
  261. // calculate new target
  262. newtarget = target + delta;
  263. // get the up and right vector relative to the light origin
  264. up += target;
  265. right += target;
  266. len = target.Length() * newtarget.Length();
  267. if (len > 0.1) {
  268. // calculate the rotation angle between the vectors
  269. double dp = target * newtarget;
  270. double dv = dp / len;
  271. angle = RAD2DEG( idMath::ACos( dv ) );
  272. // get a vector orthogonal to the rotation plane
  273. cross = target.Cross( newtarget );
  274. cross.Normalize();
  275. if (cross[0] || cross[1] || cross[2]) {
  276. // build the rotation matrix
  277. rot = idRotation( vec3_origin, cross, angle ).ToMat3();
  278. rot.ProjectVector(target, dst);
  279. target = dst;
  280. rot.ProjectVector( up, dst );
  281. up = dst;
  282. rot.ProjectVector( right, dst);
  283. right = dst;
  284. }
  285. }
  286. //
  287. // project the up and right vectors onto a plane that goes through the target and
  288. // has normal vector target.Normalize()
  289. //
  290. normal = target;
  291. normal.Normalize();
  292. dist = normal * target;
  293. d = (normal * up) - dist;
  294. up -= d * normal;
  295. d = (normal * right) - dist;
  296. right -= d * normal;
  297. //
  298. // FIXME: maybe calculate the right vector with a cross product between the target
  299. // and up vector, just to make sure the up and right vectors are perpendicular
  300. // get the up and right vectors relative to the target
  301. //
  302. up -= target;
  303. right -= target;
  304. // move the target in the (target - light_origin) direction
  305. target = newtarget;
  306. VectorSnapGrid(target);
  307. VectorSnapGrid(up);
  308. VectorSnapGrid(right);
  309. }
  310. /*
  311. =======================================================================================================================
  312. =======================================================================================================================
  313. */
  314. extern idVec3 Brush_TransformedPoint(brush_t *b, const idVec3 &in);
  315. extern idMat3 Brush_RotationMatrix(brush_t *b);
  316. bool UpdateActiveDragPoint(const idVec3 &move) {
  317. if (activeDrag) {
  318. idMat3 mat = Brush_RotationMatrix(activeDrag->pBrush);
  319. idMat3 invmat = mat.Transpose();
  320. idVec3 target, up, right, start, end;
  321. CString str;
  322. if (activeDrag->nType == LIGHT_TARGET) {
  323. GetVectorForKey(activeDrag->pBrush->owner, "light_target", target);
  324. GetVectorForKey(activeDrag->pBrush->owner, "light_up", up);
  325. GetVectorForKey(activeDrag->pBrush->owner, "light_right", right);
  326. target *= mat;
  327. up *= mat;
  328. right *= mat;
  329. RotateLight(target, up, right, move);
  330. target *= invmat;
  331. up *= invmat;
  332. right *= invmat;
  333. SetKeyVec3(activeDrag->pBrush->owner, "light_target", target);
  334. SetKeyVec3(activeDrag->pBrush->owner, "light_up", up);
  335. SetKeyVec3(activeDrag->pBrush->owner, "light_right", right);
  336. target += (activeDrag->pBrush->trackLightOrigin) ? activeDrag->pBrush->owner->lightOrigin : activeDrag->pBrush->owner->origin;
  337. UpdateSelectablePoint(activeDrag->pBrush, Brush_TransformedPoint(activeDrag->pBrush, target), LIGHT_TARGET);
  338. up += target;
  339. UpdateSelectablePoint(activeDrag->pBrush, Brush_TransformedPoint(activeDrag->pBrush,up), LIGHT_UP);
  340. right += target;
  341. UpdateSelectablePoint(activeDrag->pBrush, Brush_TransformedPoint(activeDrag->pBrush,right), LIGHT_RIGHT);
  342. }
  343. else if (activeDrag->nType == LIGHT_UP) {
  344. GetVectorForKey(activeDrag->pBrush->owner, "light_up", up);
  345. up *= mat;
  346. up += move;
  347. up *= invmat;
  348. SetKeyVec3(activeDrag->pBrush->owner, "light_up", up);
  349. GetVectorForKey(activeDrag->pBrush->owner, "light_target", target);
  350. target += (activeDrag->pBrush->trackLightOrigin) ? activeDrag->pBrush->owner->lightOrigin : activeDrag->pBrush->owner->origin;
  351. up += target;
  352. UpdateSelectablePoint(activeDrag->pBrush, Brush_TransformedPoint(activeDrag->pBrush,up), LIGHT_UP);
  353. }
  354. else if (activeDrag->nType == LIGHT_RIGHT) {
  355. GetVectorForKey(activeDrag->pBrush->owner, "light_right", right);
  356. right *= mat;
  357. right += move;
  358. right *= invmat;
  359. SetKeyVec3(activeDrag->pBrush->owner, "light_right", right);
  360. GetVectorForKey(activeDrag->pBrush->owner, "light_target", target);
  361. target += (activeDrag->pBrush->trackLightOrigin) ? activeDrag->pBrush->owner->lightOrigin : activeDrag->pBrush->owner->origin;
  362. right += target;
  363. UpdateSelectablePoint(activeDrag->pBrush, Brush_TransformedPoint(activeDrag->pBrush,right), LIGHT_RIGHT);
  364. }
  365. else if (activeDrag->nType == LIGHT_START) {
  366. GetVectorForKey(activeDrag->pBrush->owner, "light_start", start);
  367. start *= mat;
  368. start += move;
  369. start *= invmat;
  370. SetKeyVec3(activeDrag->pBrush->owner, "light_start", start);
  371. start += (activeDrag->pBrush->trackLightOrigin) ? activeDrag->pBrush->owner->lightOrigin : activeDrag->pBrush->owner->origin;
  372. UpdateSelectablePoint(activeDrag->pBrush, Brush_TransformedPoint(activeDrag->pBrush,start), LIGHT_START);
  373. }
  374. else if (activeDrag->nType == LIGHT_END) {
  375. GetVectorForKey(activeDrag->pBrush->owner, "light_end", end);
  376. end *= mat;
  377. end += move;
  378. end *= invmat;
  379. SetKeyVec3(activeDrag->pBrush->owner, "light_end", end);
  380. end += (activeDrag->pBrush->trackLightOrigin) ? activeDrag->pBrush->owner->lightOrigin : activeDrag->pBrush->owner->origin;
  381. UpdateSelectablePoint(activeDrag->pBrush, Brush_TransformedPoint(activeDrag->pBrush,end), LIGHT_END);
  382. }
  383. else if (activeDrag->nType == LIGHT_CENTER) {
  384. GetVectorForKey(activeDrag->pBrush->owner, "light_center", end);
  385. end *= mat;
  386. end += move;
  387. end *= invmat;
  388. SetKeyVec3(activeDrag->pBrush->owner, "light_center", end);
  389. end += (activeDrag->pBrush->trackLightOrigin) ? activeDrag->pBrush->owner->lightOrigin : activeDrag->pBrush->owner->origin;
  390. UpdateSelectablePoint(activeDrag->pBrush, Brush_TransformedPoint(activeDrag->pBrush, end), LIGHT_CENTER);
  391. }
  392. // FIXME: just build the frustrum values
  393. Brush_Build(activeDrag->pBrush);
  394. return true;
  395. }
  396. return false;
  397. }
  398. /*
  399. =======================================================================================================================
  400. =======================================================================================================================
  401. */
  402. bool SetDragPointCursor(idVec3 p, int nView) {
  403. activeDrag = NULL;
  404. int numDragPoints = dragPoints.GetSize();
  405. for (int i = 0; i < numDragPoints; i++) {
  406. if (reinterpret_cast < CDragPoint * > (dragPoints[i])->PointWithin(p, nView)) {
  407. activeDrag = reinterpret_cast < CDragPoint * > (dragPoints[i]);
  408. return true;
  409. }
  410. }
  411. return false;
  412. }
  413. /*
  414. =======================================================================================================================
  415. =======================================================================================================================
  416. */
  417. void SetActiveDrag(CDragPoint *p) {
  418. activeDrag = p;
  419. }
  420. /*
  421. =======================================================================================================================
  422. =======================================================================================================================
  423. */
  424. void ClearActiveDrag() {
  425. activeDrag = NULL;
  426. }
  427. // CXYWnd
  428. IMPLEMENT_DYNCREATE(CXYWnd, CWnd);
  429. /*
  430. =======================================================================================================================
  431. =======================================================================================================================
  432. */
  433. CXYWnd::CXYWnd() {
  434. g_brClipboard.next = &g_brClipboard;
  435. g_brUndo.next = &g_brUndo;
  436. g_nScaleHow = 0;
  437. g_bRotateMode = false;
  438. g_bClipMode = false;
  439. g_bRogueClipMode = false;
  440. g_bSwitch = true;
  441. g_pMovingClip = NULL;
  442. g_pMovingPath = NULL;
  443. g_brFrontSplits.next = &g_brFrontSplits;
  444. g_brBackSplits.next = &g_brBackSplits;
  445. m_bActive = false;
  446. m_bRButtonDown = false;
  447. m_nUpdateBits = W_XY;
  448. g_bPathMode = false;
  449. g_nPathCount = 0;
  450. g_nPathLimit = 0;
  451. m_nTimerID = -1;
  452. m_nButtonstate = 0;
  453. XY_Init();
  454. }
  455. /*
  456. =======================================================================================================================
  457. =======================================================================================================================
  458. */
  459. CXYWnd::~CXYWnd() {
  460. int nSize = g_ptrMenus.GetSize();
  461. while (nSize > 0) {
  462. CMenu *pMenu = reinterpret_cast < CMenu * > (g_ptrMenus.GetAt(nSize - 1));
  463. ASSERT(pMenu);
  464. pMenu->DestroyMenu();
  465. delete pMenu;
  466. nSize--;
  467. }
  468. g_ptrMenus.RemoveAll();
  469. m_mnuDrop.DestroyMenu();
  470. }
  471. BEGIN_MESSAGE_MAP(CXYWnd, CWnd)
  472. //{{AFX_MSG_MAP(CXYWnd)
  473. ON_WM_CREATE()
  474. ON_WM_LBUTTONDOWN()
  475. ON_WM_MBUTTONDOWN()
  476. ON_WM_RBUTTONDOWN()
  477. ON_WM_LBUTTONUP()
  478. ON_WM_MBUTTONUP()
  479. ON_WM_RBUTTONUP()
  480. ON_WM_MOUSEMOVE()
  481. ON_WM_PAINT()
  482. ON_WM_KEYDOWN()
  483. ON_WM_SIZE()
  484. ON_WM_DESTROY()
  485. ON_COMMAND(ID_SELECT_MOUSEROTATE, OnSelectMouserotate)
  486. ON_WM_TIMER()
  487. ON_WM_KEYUP()
  488. ON_WM_NCCALCSIZE()
  489. ON_WM_KILLFOCUS()
  490. ON_WM_SETFOCUS()
  491. ON_WM_CLOSE()
  492. ON_WM_ERASEBKGND()
  493. ON_WM_MOUSEWHEEL()
  494. ON_COMMAND(ID_DROP_NEWMODEL, OnDropNewmodel)
  495. //}}AFX_MSG_MAP
  496. ON_COMMAND_RANGE(ID_ENTITY_START, ID_ENTITY_END, OnEntityCreate)
  497. END_MESSAGE_MAP()
  498. // CXYWnd message handlers
  499. LONG WINAPI XYWndProc(HWND, UINT, WPARAM, LPARAM);
  500. /*
  501. =======================================================================================================================
  502. =======================================================================================================================
  503. */
  504. BOOL CXYWnd::PreCreateWindow(CREATESTRUCT &cs) {
  505. WNDCLASS wc;
  506. HINSTANCE hInstance = AfxGetInstanceHandle();
  507. if (::GetClassInfo(hInstance, XY_WINDOW_CLASS, &wc) == FALSE) {
  508. // Register a new class
  509. memset(&wc, 0, sizeof(wc));
  510. wc.style = CS_NOCLOSE;
  511. wc.lpszClassName = XY_WINDOW_CLASS;
  512. wc.hCursor = NULL; // LoadCursor (NULL,IDC_ARROW);
  513. wc.lpfnWndProc = ::DefWindowProc;
  514. if (AfxRegisterClass(&wc) == FALSE) {
  515. Error("CCamWnd RegisterClass: failed");
  516. }
  517. }
  518. cs.lpszClass = XY_WINDOW_CLASS;
  519. cs.lpszName = "VIEW";
  520. if (cs.style != QE3_CHILDSTYLE) {
  521. cs.style = QE3_SPLITTER_STYLE;
  522. }
  523. return CWnd::PreCreateWindow(cs);
  524. }
  525. HDC s_hdcXY;
  526. HGLRC s_hglrcXY;
  527. static unsigned s_stipple[32] = {
  528. 0xaaaaaaaa,
  529. 0x55555555,
  530. 0xaaaaaaaa,
  531. 0x55555555,
  532. 0xaaaaaaaa,
  533. 0x55555555,
  534. 0xaaaaaaaa,
  535. 0x55555555,
  536. 0xaaaaaaaa,
  537. 0x55555555,
  538. 0xaaaaaaaa,
  539. 0x55555555,
  540. 0xaaaaaaaa,
  541. 0x55555555,
  542. 0xaaaaaaaa,
  543. 0x55555555,
  544. 0xaaaaaaaa,
  545. 0x55555555,
  546. 0xaaaaaaaa,
  547. 0x55555555,
  548. 0xaaaaaaaa,
  549. 0x55555555,
  550. 0xaaaaaaaa,
  551. 0x55555555,
  552. 0xaaaaaaaa,
  553. 0x55555555,
  554. 0xaaaaaaaa,
  555. 0x55555555,
  556. 0xaaaaaaaa,
  557. 0x55555555,
  558. 0xaaaaaaaa,
  559. 0x55555555,
  560. };
  561. /*
  562. =======================================================================================================================
  563. WXY_WndProc
  564. =======================================================================================================================
  565. */
  566. LONG WINAPI XYWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  567. switch (uMsg)
  568. {
  569. case WM_DESTROY:
  570. return 0;
  571. case WM_NCCALCSIZE: // don't let windows copy pixels
  572. DefWindowProc(hWnd, uMsg, wParam, lParam);
  573. return WVR_REDRAW;
  574. case WM_KILLFOCUS:
  575. case WM_SETFOCUS:
  576. SendMessage(hWnd, WM_NCACTIVATE, uMsg == WM_SETFOCUS, 0);
  577. return 0;
  578. case WM_CLOSE:
  579. DestroyWindow(hWnd);
  580. return 0;
  581. }
  582. return DefWindowProc(hWnd, uMsg, wParam, lParam);
  583. }
  584. /*
  585. =======================================================================================================================
  586. =======================================================================================================================
  587. */
  588. static void WXY_InitPixelFormat(PIXELFORMATDESCRIPTOR *pPFD) {
  589. memset(pPFD, 0, sizeof(*pPFD));
  590. pPFD->nSize = sizeof(PIXELFORMATDESCRIPTOR);
  591. pPFD->nVersion = 1;
  592. pPFD->dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
  593. pPFD->iPixelType = PFD_TYPE_RGBA;
  594. pPFD->cColorBits = 24;
  595. pPFD->cDepthBits = 32;
  596. pPFD->iLayerType = PFD_MAIN_PLANE;
  597. }
  598. /*
  599. =======================================================================================================================
  600. =======================================================================================================================
  601. */
  602. void WXY_Print(void) {
  603. DOCINFO di;
  604. PRINTDLG pd;
  605. /* initialize the PRINTDLG struct and execute it */
  606. memset(&pd, 0, sizeof(pd));
  607. pd.lStructSize = sizeof(pd);
  608. pd.hwndOwner = g_pParentWnd->GetXYWnd()->GetSafeHwnd();
  609. pd.Flags = PD_RETURNDC;
  610. pd.hInstance = 0;
  611. if (!PrintDlg(&pd) || !pd.hDC) {
  612. g_pParentWnd->MessageBox("Could not PrintDlg()", "QE4 Print Error", MB_OK | MB_ICONERROR);
  613. return;
  614. }
  615. /* StartDoc */
  616. memset(&di, 0, sizeof(di));
  617. di.cbSize = sizeof(di);
  618. di.lpszDocName = "QE4";
  619. if (StartDoc(pd.hDC, &di) <= 0) {
  620. g_pParentWnd->MessageBox("Could not StartDoc()", "QE4 Print Error", MB_OK | MB_ICONERROR);
  621. return;
  622. }
  623. /* StartPage */
  624. if (StartPage(pd.hDC) <= 0) {
  625. g_pParentWnd->MessageBox("Could not StartPage()", "QE4 Print Error", MB_OK | MB_ICONERROR);
  626. return;
  627. } { /* read pixels from the XY window */
  628. int bmwidth = 320, bmheight = 320;
  629. int pwidth, pheight;
  630. RECT r;
  631. GetWindowRect(g_pParentWnd->GetXYWnd()->GetSafeHwnd(), &r);
  632. bmwidth = r.right - r.left;
  633. bmheight = r.bottom - r.top;
  634. pwidth = GetDeviceCaps(pd.hDC, PHYSICALWIDTH) - GetDeviceCaps(pd.hDC, PHYSICALOFFSETX);
  635. pheight = GetDeviceCaps(pd.hDC, PHYSICALHEIGHT) - GetDeviceCaps(pd.hDC, PHYSICALOFFSETY);
  636. StretchBlt(pd.hDC, 0, 0, pwidth, pheight, s_hdcXY, 0, 0, bmwidth, bmheight, SRCCOPY);
  637. }
  638. /* EndPage and EndDoc */
  639. if (EndPage(pd.hDC) <= 0) {
  640. g_pParentWnd->MessageBox("QE4 Print Error", "Could not EndPage()", MB_OK | MB_ICONERROR);
  641. return;
  642. }
  643. if (EndDoc(pd.hDC) <= 0) {
  644. g_pParentWnd->MessageBox("QE4 Print Error", "Could not EndDoc()", MB_OK | MB_ICONERROR);
  645. return;
  646. }
  647. }
  648. /*
  649. =======================================================================================================================
  650. =======================================================================================================================
  651. */
  652. int CXYWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) {
  653. if (CWnd::OnCreate(lpCreateStruct) == -1) {
  654. return -1;
  655. }
  656. s_hdcXY = ::GetDC(GetSafeHwnd());
  657. QEW_SetupPixelFormat(s_hdcXY, false);
  658. qglPolygonStipple((unsigned char *)s_stipple);
  659. qglLineStipple(3, 0xaaaa);
  660. return 0;
  661. }
  662. /*
  663. =======================================================================================================================
  664. =======================================================================================================================
  665. */
  666. float ptSum(idVec3 pt) {
  667. return pt[0] + pt[1] + pt[2];
  668. }
  669. /*
  670. =======================================================================================================================
  671. =======================================================================================================================
  672. */
  673. void CXYWnd::DropClipPoint(UINT nFlags, CPoint point) {
  674. CRect rctZ;
  675. GetClientRect(rctZ);
  676. if (g_pMovingClip) {
  677. SetCapture();
  678. SnapToPoint(point.x, rctZ.Height() - 1 - point.y, *g_pMovingClip);
  679. }
  680. else {
  681. idVec3 *pPt = NULL;
  682. if (g_Clip1.Set() == false) {
  683. pPt = g_Clip1;
  684. g_Clip1.Set(true);
  685. g_Clip1.m_ptScreen = point;
  686. }
  687. else if (g_Clip2.Set() == false) {
  688. pPt = g_Clip2;
  689. g_Clip2.Set(true);
  690. g_Clip2.m_ptScreen = point;
  691. }
  692. else if (g_Clip3.Set() == false) {
  693. pPt = g_Clip3;
  694. g_Clip3.Set(true);
  695. g_Clip3.m_ptScreen = point;
  696. }
  697. else {
  698. RetainClipMode(true);
  699. pPt = g_Clip1;
  700. g_Clip1.Set(true);
  701. g_Clip1.m_ptScreen = point;
  702. }
  703. SnapToPoint(point.x, rctZ.Height() - 1 - point.y, *pPt);
  704. // Put the off-viewaxis coordinate at the top or bottom of selected brushes
  705. if ( GetAsyncKeyState(VK_CONTROL) & 0x8000 ) {
  706. if ( selected_brushes.next != &selected_brushes ) {
  707. idVec3 smins, smaxs;
  708. Select_GetBounds( smins, smaxs );
  709. if ( m_nViewType == XY ) {
  710. if ( GetAsyncKeyState(VK_SHIFT) & 0x8000 ) {
  711. pPt->z = smaxs.z;
  712. } else {
  713. pPt->z = smins.z;
  714. }
  715. } else if ( m_nViewType == YZ ) {
  716. if ( GetAsyncKeyState(VK_SHIFT) & 0x8000 ) {
  717. pPt->x = smaxs.x;
  718. } else {
  719. pPt->x = smins.x;
  720. }
  721. } else {
  722. if ( GetAsyncKeyState(VK_SHIFT) & 0x8000 ) {
  723. pPt->y = smaxs.y;
  724. } else {
  725. pPt->y = smins.y;
  726. }
  727. }
  728. }
  729. }
  730. }
  731. Sys_UpdateWindows(XY | W_CAMERA_IFON);
  732. }
  733. /*
  734. =======================================================================================================================
  735. =======================================================================================================================
  736. */
  737. void CXYWnd::DropPathPoint(UINT nFlags, CPoint point) {
  738. CRect rctZ;
  739. GetClientRect(rctZ);
  740. if (g_pMovingPath) {
  741. SetCapture();
  742. SnapToPoint(point.x, rctZ.Height() - 1 - point.y, *g_pMovingPath);
  743. }
  744. else {
  745. g_PathPoints[g_nPathCount].Set(true);
  746. g_PathPoints[g_nPathCount].m_ptScreen = point;
  747. SnapToPoint(point.x, rctZ.Height() - 1 - point.y, g_PathPoints[g_nPathCount]);
  748. g_nPathCount++;
  749. if (g_nPathCount == g_nPathLimit) {
  750. if (g_pPathFunc) {
  751. g_pPathFunc(true, g_nPathCount);
  752. }
  753. g_nPathCount = 0;
  754. g_bPathMode = false;
  755. g_pPathFunc = NULL;
  756. }
  757. }
  758. Sys_UpdateWindows(XY | W_CAMERA_IFON);
  759. }
  760. /*
  761. =======================================================================================================================
  762. =======================================================================================================================
  763. */
  764. void CXYWnd::AddPointPoint(UINT nFlags, idVec3 *pVec) {
  765. g_PointPoints[g_nPointCount].Set(true);
  766. // g_PointPoints[g_nPointCount].m_ptScreen = point;
  767. g_PointPoints[g_nPointCount].m_ptClip = *pVec;
  768. g_PointPoints[g_nPointCount].SetPointPtr(pVec);
  769. g_nPointCount++;
  770. Sys_UpdateWindows(XY | W_CAMERA_IFON);
  771. }
  772. /*
  773. =======================================================================================================================
  774. =======================================================================================================================
  775. */
  776. void CXYWnd::OnLButtonDown(UINT nFlags, CPoint point) {
  777. g_pParentWnd->SetActiveXY(this);
  778. UndoCopy();
  779. if (g_pParentWnd->GetNurbMode()) {
  780. int i, num = g_pParentWnd->GetNurb()->GetNumValues();
  781. idList<idVec2> temp;
  782. for (i = 0; i < num; i++) {
  783. temp.Append(g_pParentWnd->GetNurb()->GetValue(i));
  784. }
  785. CRect rctZ;
  786. GetClientRect(rctZ);
  787. idVec3 v3;
  788. SnapToPoint(point.x, rctZ.Height() - 1 - point.y, v3);
  789. temp.Append(idVec2(v3.x, v3.y));
  790. num++;
  791. g_pParentWnd->GetNurb()->Clear();
  792. for (i = 0; i < num; i++) {
  793. g_pParentWnd->GetNurb()->AddValue((1000 * i)/num, temp[i]);
  794. }
  795. }
  796. if (ClipMode() && !RogueClipMode()) {
  797. DropClipPoint(nFlags, point);
  798. }
  799. else if (PathMode()) {
  800. DropPathPoint(nFlags, point);
  801. }
  802. else {
  803. OriginalButtonDown(nFlags, point);
  804. }
  805. }
  806. /*
  807. =======================================================================================================================
  808. =======================================================================================================================
  809. */
  810. void CXYWnd::OnMButtonDown(UINT nFlags, CPoint point) {
  811. OriginalButtonDown(nFlags, point);
  812. }
  813. /*
  814. =======================================================================================================================
  815. =======================================================================================================================
  816. */
  817. float Betwixt(float f1, float f2) {
  818. if (f1 > f2) {
  819. return f2 + ((f1 - f2) / 2);
  820. }
  821. else {
  822. return f1 + ((f2 - f1) / 2);
  823. }
  824. }
  825. /*
  826. =======================================================================================================================
  827. =======================================================================================================================
  828. */
  829. void CXYWnd::ProduceSplits(brush_t **pFront, brush_t **pBack) {
  830. *pFront = NULL;
  831. *pBack = NULL;
  832. if (ClipMode()) {
  833. if (g_Clip1.Set() && g_Clip2.Set()) {
  834. face_t face;
  835. VectorCopy(g_Clip1.m_ptClip, face.planepts[0]);
  836. VectorCopy(g_Clip2.m_ptClip, face.planepts[1]);
  837. VectorCopy(g_Clip3.m_ptClip, face.planepts[2]);
  838. if (selected_brushes.next && (selected_brushes.next->next == &selected_brushes)) {
  839. if (g_Clip3.Set() == false) {
  840. if (m_nViewType == XY) {
  841. face.planepts[0][2] = selected_brushes.next->mins[2];
  842. face.planepts[1][2] = selected_brushes.next->mins[2];
  843. face.planepts[2][0] = Betwixt(g_Clip1.m_ptClip[0], g_Clip2.m_ptClip[0]);
  844. face.planepts[2][1] = Betwixt(g_Clip1.m_ptClip[1], g_Clip2.m_ptClip[1]);
  845. face.planepts[2][2] = selected_brushes.next->maxs[2];
  846. }
  847. else if (m_nViewType == YZ) {
  848. face.planepts[0][0] = selected_brushes.next->mins[0];
  849. face.planepts[1][0] = selected_brushes.next->mins[0];
  850. face.planepts[2][1] = Betwixt(g_Clip1.m_ptClip[1], g_Clip2.m_ptClip[1]);
  851. face.planepts[2][2] = Betwixt(g_Clip1.m_ptClip[2], g_Clip2.m_ptClip[2]);
  852. face.planepts[2][0] = selected_brushes.next->maxs[0];
  853. }
  854. else {
  855. face.planepts[0][1] = selected_brushes.next->mins[1];
  856. face.planepts[1][1] = selected_brushes.next->mins[1];
  857. face.planepts[2][0] = Betwixt(g_Clip1.m_ptClip[0], g_Clip2.m_ptClip[0]);
  858. face.planepts[2][2] = Betwixt(g_Clip1.m_ptClip[2], g_Clip2.m_ptClip[2]);
  859. face.planepts[2][1] = selected_brushes.next->maxs[1];
  860. }
  861. }
  862. Brush_SplitBrushByFace(selected_brushes.next, &face, pFront, pBack);
  863. }
  864. }
  865. }
  866. }
  867. /*
  868. =======================================================================================================================
  869. =======================================================================================================================
  870. */
  871. void CleanList(brush_t *pList) {
  872. brush_t *pBrush = pList->next;
  873. while (pBrush != NULL && pBrush != pList) {
  874. brush_t *pNext = pBrush->next;
  875. Brush_Free(pBrush);
  876. pBrush = pNext;
  877. }
  878. }
  879. /*
  880. =======================================================================================================================
  881. =======================================================================================================================
  882. */
  883. void CXYWnd::ProduceSplitLists() {
  884. if (AnyPatchesSelected()) {
  885. Sys_Status("Deslecting patches for clip operation.\n");
  886. brush_t *next;
  887. for (brush_t * pb = selected_brushes.next; pb != &selected_brushes; pb = next) {
  888. next = pb->next;
  889. if (pb->pPatch) {
  890. Brush_RemoveFromList(pb);
  891. Brush_AddToList(pb, &active_brushes);
  892. UpdatePatchInspector();
  893. }
  894. }
  895. }
  896. CleanList(&g_brFrontSplits);
  897. CleanList(&g_brBackSplits);
  898. g_brFrontSplits.next = &g_brFrontSplits;
  899. g_brBackSplits.next = &g_brBackSplits;
  900. brush_t *pBrush;
  901. for (pBrush = selected_brushes.next; pBrush != NULL && pBrush != &selected_brushes; pBrush = pBrush->next) {
  902. brush_t *pFront = NULL;
  903. brush_t *pBack = NULL;
  904. if (ClipMode()) {
  905. if (g_Clip1.Set() && g_Clip2.Set()) {
  906. face_t face;
  907. VectorCopy(g_Clip1.m_ptClip, face.planepts[0]);
  908. VectorCopy(g_Clip2.m_ptClip, face.planepts[1]);
  909. VectorCopy(g_Clip3.m_ptClip, face.planepts[2]);
  910. if (g_Clip3.Set() == false) {
  911. if (g_pParentWnd->ActiveXY()->GetViewType() == XY) {
  912. face.planepts[0][2] = pBrush->mins[2];
  913. face.planepts[1][2] = pBrush->mins[2];
  914. face.planepts[2][0] = Betwixt(g_Clip1.m_ptClip[0], g_Clip2.m_ptClip[0]);
  915. face.planepts[2][1] = Betwixt(g_Clip1.m_ptClip[1], g_Clip2.m_ptClip[1]);
  916. face.planepts[2][2] = pBrush->maxs[2];
  917. }
  918. else if (g_pParentWnd->ActiveXY()->GetViewType() == YZ) {
  919. face.planepts[0][0] = pBrush->mins[0];
  920. face.planepts[1][0] = pBrush->mins[0];
  921. face.planepts[2][1] = Betwixt(g_Clip1.m_ptClip[1], g_Clip2.m_ptClip[1]);
  922. face.planepts[2][2] = Betwixt(g_Clip1.m_ptClip[2], g_Clip2.m_ptClip[2]);
  923. face.planepts[2][0] = pBrush->maxs[0];
  924. }
  925. else {
  926. face.planepts[0][1] = pBrush->mins[1];
  927. face.planepts[1][1] = pBrush->mins[1];
  928. face.planepts[2][0] = Betwixt(g_Clip1.m_ptClip[0], g_Clip2.m_ptClip[0]);
  929. face.planepts[2][2] = Betwixt(g_Clip1.m_ptClip[2], g_Clip2.m_ptClip[2]);
  930. face.planepts[2][1] = pBrush->maxs[1];
  931. }
  932. }
  933. Brush_SplitBrushByFace(pBrush, &face, &pFront, &pBack);
  934. if (pBack) {
  935. Brush_AddToList(pBack, &g_brBackSplits);
  936. }
  937. if (pFront) {
  938. Brush_AddToList(pFront, &g_brFrontSplits);
  939. }
  940. }
  941. }
  942. }
  943. }
  944. /*
  945. =======================================================================================================================
  946. =======================================================================================================================
  947. */
  948. void Brush_CopyList(brush_t *pFrom, brush_t *pTo) {
  949. brush_t *pBrush = pFrom->next;
  950. while (pBrush != NULL && pBrush != pFrom) {
  951. brush_t *pNext = pBrush->next;
  952. Brush_RemoveFromList(pBrush);
  953. Brush_AddToList(pBrush, pTo);
  954. pBrush = pNext;
  955. }
  956. }
  957. /*
  958. =======================================================================================================================
  959. =======================================================================================================================
  960. */
  961. void CXYWnd::OnRButtonDown(UINT nFlags, CPoint point) {
  962. g_pParentWnd->SetActiveXY(this);
  963. m_ptDown = point;
  964. m_bRButtonDown = true;
  965. if (g_PrefsDlg.m_nMouseButtons == 3) { // 3 button mouse
  966. if ((GetAsyncKeyState(VK_CONTROL) & 0x8000)) {
  967. if (ClipMode()) { // already there?
  968. DropClipPoint(nFlags, point);
  969. }
  970. else {
  971. SetClipMode(true);
  972. g_bRogueClipMode = true;
  973. DropClipPoint(nFlags, point);
  974. }
  975. return;
  976. }
  977. }
  978. OriginalButtonDown(nFlags, point);
  979. }
  980. /*
  981. =======================================================================================================================
  982. =======================================================================================================================
  983. */
  984. void CXYWnd::OnLButtonUp(UINT nFlags, CPoint point) {
  985. if (ClipMode()) {
  986. if (g_pMovingClip) {
  987. ReleaseCapture();
  988. g_pMovingClip = NULL;
  989. }
  990. }
  991. OriginalButtonUp(nFlags, point);
  992. }
  993. /*
  994. =======================================================================================================================
  995. =======================================================================================================================
  996. */
  997. void CXYWnd::OnMButtonUp(UINT nFlags, CPoint point) {
  998. OriginalButtonUp(nFlags, point);
  999. }
  1000. /*
  1001. =======================================================================================================================
  1002. =======================================================================================================================
  1003. */
  1004. void CXYWnd::OnRButtonUp(UINT nFlags, CPoint point) {
  1005. m_bRButtonDown = false;
  1006. if (point == m_ptDown) { // mouse didn't move
  1007. bool bGo = true;
  1008. if ((GetAsyncKeyState(VK_MENU) & 0x8000)) {
  1009. bGo = false;
  1010. }
  1011. if ((GetAsyncKeyState(VK_CONTROL) & 0x8000)) {
  1012. bGo = false;
  1013. }
  1014. if ((GetAsyncKeyState(VK_SHIFT) & 0x8000)) {
  1015. bGo = false;
  1016. }
  1017. if (bGo) {
  1018. HandleDrop();
  1019. }
  1020. }
  1021. OriginalButtonUp(nFlags, point);
  1022. }
  1023. /*
  1024. =======================================================================================================================
  1025. =======================================================================================================================
  1026. */
  1027. void CXYWnd::OriginalButtonDown(UINT nFlags, CPoint point) {
  1028. CRect rctZ;
  1029. GetClientRect(rctZ);
  1030. SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  1031. if (g_pParentWnd->GetTopWindow() != this) {
  1032. BringWindowToTop();
  1033. }
  1034. SetFocus();
  1035. SetCapture();
  1036. XY_MouseDown(point.x, rctZ.Height() - 1 - point.y, nFlags);
  1037. m_nScrollFlags = nFlags;
  1038. }
  1039. /*
  1040. =======================================================================================================================
  1041. =======================================================================================================================
  1042. */
  1043. void CXYWnd::OriginalButtonUp(UINT nFlags, CPoint point) {
  1044. CRect rctZ;
  1045. GetClientRect(rctZ);
  1046. XY_MouseUp(point.x, rctZ.Height() - 1 - point.y, nFlags);
  1047. if (!(nFlags & (MK_LBUTTON | MK_RBUTTON | MK_MBUTTON))) {
  1048. ReleaseCapture();
  1049. }
  1050. }
  1051. idVec3 tdp;
  1052. /*
  1053. =======================================================================================================================
  1054. =======================================================================================================================
  1055. */
  1056. void CXYWnd::OnMouseMove(UINT nFlags, CPoint point) {
  1057. m_ptDown.x = 0;
  1058. m_ptDown.y = 0;
  1059. if
  1060. (
  1061. g_PrefsDlg.m_bChaseMouse == TRUE &&
  1062. (point.x < 0 || point.y < 0 || point.x > m_nWidth || point.y > m_nHeight) &&
  1063. GetCapture() == this
  1064. ) {
  1065. float fAdjustment = (g_qeglobals.d_gridsize / 8 * 64) / m_fScale;
  1066. // m_ptDrag = point;
  1067. m_ptDragAdj.x = 0;
  1068. m_ptDragAdj.y = 0;
  1069. if (point.x < 0) {
  1070. m_ptDragAdj.x = -fAdjustment;
  1071. }
  1072. else if (point.x > m_nWidth) {
  1073. m_ptDragAdj.x = fAdjustment;
  1074. }
  1075. if (point.y < 0) {
  1076. m_ptDragAdj.y = -fAdjustment;
  1077. }
  1078. else if (point.y > m_nHeight) {
  1079. m_ptDragAdj.y = fAdjustment;
  1080. }
  1081. if (m_nTimerID == -1) {
  1082. m_nTimerID = SetTimer(100, 50, NULL);
  1083. m_ptDrag = point;
  1084. m_ptDragTotal = 0;
  1085. }
  1086. return;
  1087. }
  1088. // else if (m_nTimerID != -1)
  1089. if (m_nTimerID != -1) {
  1090. KillTimer(m_nTimerID);
  1091. pressx -= m_ptDragTotal.x;
  1092. pressy += m_ptDragTotal.y;
  1093. m_nTimerID = -1;
  1094. // return;
  1095. }
  1096. bool bCrossHair = false;
  1097. if (!m_bRButtonDown) {
  1098. tdp[0] = tdp[1] = tdp[2] = 0.0;
  1099. SnapToPoint(point.x, m_nHeight - 1 - point.y, tdp);
  1100. g_strStatus.Format("x:: %.1f y:: %.1f z:: %.1f", tdp[0], tdp[1], tdp[2]);
  1101. g_pParentWnd->SetStatusText(1, g_strStatus);
  1102. //
  1103. // i need to generalize the point code.. having 3 flavors pretty much sucks.. once
  1104. // the new curve stuff looks like it is going to stick i will rationalize this
  1105. // down to a single interface..
  1106. //
  1107. if (PointMode()) {
  1108. if (g_pMovingPoint && GetCapture() == this) {
  1109. bCrossHair = true;
  1110. SnapToPoint(point.x, m_nHeight - 1 - point.y, g_pMovingPoint->m_ptClip);
  1111. g_pMovingPoint->UpdatePointPtr();
  1112. Sys_UpdateWindows(XY | W_CAMERA_IFON);
  1113. }
  1114. else {
  1115. g_pMovingPoint = NULL;
  1116. int nDim1 = (m_nViewType == YZ) ? 1 : 0;
  1117. int nDim2 = (m_nViewType == XY) ? 1 : 2;
  1118. for (int n = 0; n < g_nPointCount; n++) {
  1119. if
  1120. (
  1121. fDiff(g_PointPoints[n].m_ptClip[nDim1], tdp[nDim1]) < 3 &&
  1122. fDiff(g_PointPoints[n].m_ptClip[nDim2], tdp[nDim2]) < 3
  1123. ) {
  1124. bCrossHair = true;
  1125. g_pMovingPoint = &g_PointPoints[n];
  1126. }
  1127. }
  1128. }
  1129. }
  1130. else if (ClipMode()) {
  1131. if (g_pMovingClip && GetCapture() == this) {
  1132. bCrossHair = true;
  1133. SnapToPoint(point.x, m_nHeight - 1 - point.y, g_pMovingClip->m_ptClip);
  1134. Sys_UpdateWindows(XY | W_CAMERA_IFON);
  1135. }
  1136. else {
  1137. g_pMovingClip = NULL;
  1138. int nDim1 = (m_nViewType == YZ) ? 1 : 0;
  1139. int nDim2 = (m_nViewType == XY) ? 1 : 2;
  1140. if (g_Clip1.Set()) {
  1141. if
  1142. (
  1143. fDiff(g_Clip1.m_ptClip[nDim1], tdp[nDim1]) < 3 &&
  1144. fDiff(g_Clip1.m_ptClip[nDim2], tdp[nDim2]) < 3
  1145. ) {
  1146. bCrossHair = true;
  1147. g_pMovingClip = &g_Clip1;
  1148. }
  1149. }
  1150. if (g_Clip2.Set()) {
  1151. if
  1152. (
  1153. fDiff(g_Clip2.m_ptClip[nDim1], tdp[nDim1]) < 3 &&
  1154. fDiff(g_Clip2.m_ptClip[nDim2], tdp[nDim2]) < 3
  1155. ) {
  1156. bCrossHair = true;
  1157. g_pMovingClip = &g_Clip2;
  1158. }
  1159. }
  1160. if (g_Clip3.Set()) {
  1161. if
  1162. (
  1163. fDiff(g_Clip3.m_ptClip[nDim1], tdp[nDim1]) < 3 &&
  1164. fDiff(g_Clip3.m_ptClip[nDim2], tdp[nDim2]) < 3
  1165. ) {
  1166. bCrossHair = true;
  1167. g_pMovingClip = &g_Clip3;
  1168. }
  1169. }
  1170. }
  1171. if (bCrossHair == false) {
  1172. XY_MouseMoved(point.x, m_nHeight - 1 - point.y, nFlags);
  1173. }
  1174. }
  1175. else if (PathMode()) {
  1176. if (g_pMovingPath && GetCapture() == this) {
  1177. bCrossHair = true;
  1178. SnapToPoint(point.x, m_nHeight - 1 - point.y, g_pMovingPath->m_ptClip);
  1179. Sys_UpdateWindows(XY | W_CAMERA_IFON);
  1180. }
  1181. else {
  1182. g_pMovingPath = NULL;
  1183. int nDim1 = (m_nViewType == YZ) ? 1 : 0;
  1184. int nDim2 = (m_nViewType == XY) ? 1 : 2;
  1185. for (int n = 0; n < g_nPathCount; n++) {
  1186. if
  1187. (
  1188. fDiff(g_PathPoints[n].m_ptClip[nDim1], tdp[nDim1]) < 3 &&
  1189. fDiff(g_PathPoints[n].m_ptClip[nDim2], tdp[nDim2]) < 3
  1190. ) {
  1191. bCrossHair = true;
  1192. g_pMovingPath = &g_PathPoints[n];
  1193. }
  1194. }
  1195. }
  1196. }
  1197. else {
  1198. bCrossHair = XY_MouseMoved(point.x, m_nHeight - 1 - point.y, nFlags);
  1199. }
  1200. }
  1201. else {
  1202. bCrossHair = XY_MouseMoved(point.x, m_nHeight - 1 - point.y, nFlags);
  1203. }
  1204. if (bCrossHair) {
  1205. SetCursor(::LoadCursor(NULL, IDC_CROSS));
  1206. }
  1207. else {
  1208. SetCursor(::LoadCursor(NULL, IDC_ARROW));
  1209. }
  1210. /// If precision crosshair is active, force redraw of the 2d view on mouse move
  1211. if( m_precisionCrosshairMode != PRECISION_CROSSHAIR_NONE )
  1212. {
  1213. /// Force 2d view redraw (so that the precision cursor moves with the mouse)
  1214. Sys_UpdateWindows( W_XY );
  1215. }
  1216. }
  1217. /*
  1218. =======================================================================================================================
  1219. =======================================================================================================================
  1220. */
  1221. void CXYWnd::RetainClipMode(bool bMode) {
  1222. bool bSave = g_bRogueClipMode;
  1223. SetClipMode(bMode);
  1224. if (bMode == true) {
  1225. g_bRogueClipMode = bSave;
  1226. }
  1227. else {
  1228. g_bRogueClipMode = false;
  1229. }
  1230. }
  1231. /*
  1232. =======================================================================================================================
  1233. =======================================================================================================================
  1234. */
  1235. void CXYWnd::SetClipMode(bool bMode) {
  1236. g_bClipMode = bMode;
  1237. g_bRogueClipMode = false;
  1238. if (bMode) {
  1239. g_Clip1.Reset();
  1240. g_Clip2.Reset();
  1241. g_Clip3.Reset();
  1242. CleanList(&g_brFrontSplits);
  1243. CleanList(&g_brBackSplits);
  1244. g_brFrontSplits.next = &g_brFrontSplits;
  1245. g_brBackSplits.next = &g_brBackSplits;
  1246. }
  1247. else {
  1248. if (g_pMovingClip) {
  1249. ReleaseCapture();
  1250. g_pMovingClip = NULL;
  1251. }
  1252. CleanList(&g_brFrontSplits);
  1253. CleanList(&g_brBackSplits);
  1254. g_brFrontSplits.next = &g_brFrontSplits;
  1255. g_brBackSplits.next = &g_brBackSplits;
  1256. Sys_UpdateWindows(XY | W_CAMERA_IFON);
  1257. }
  1258. }
  1259. /*
  1260. =======================================================================================================================
  1261. =======================================================================================================================
  1262. */
  1263. bool CXYWnd::ClipMode() {
  1264. return g_bClipMode;
  1265. }
  1266. /*
  1267. =======================================================================================================================
  1268. =======================================================================================================================
  1269. */
  1270. bool CXYWnd::RogueClipMode() {
  1271. return g_bRogueClipMode;
  1272. }
  1273. /*
  1274. =======================================================================================================================
  1275. =======================================================================================================================
  1276. */
  1277. bool CXYWnd::PathMode() {
  1278. return g_bPathMode;
  1279. }
  1280. /*
  1281. =======================================================================================================================
  1282. =======================================================================================================================
  1283. */
  1284. bool CXYWnd::PointMode() {
  1285. return g_bPointMode;
  1286. }
  1287. /*
  1288. =======================================================================================================================
  1289. =======================================================================================================================
  1290. */
  1291. void CXYWnd::SetPointMode(bool b) {
  1292. g_bPointMode = b;
  1293. if (!b) {
  1294. g_nPointCount = 0;
  1295. }
  1296. }
  1297. /*
  1298. =======================================================================================================================
  1299. =======================================================================================================================
  1300. */
  1301. void CXYWnd::OnPaint() {
  1302. CPaintDC dc(this); // device context for painting
  1303. bool bPaint = true;
  1304. if (!qwglMakeCurrent(dc.m_hDC, win32.hGLRC)) {
  1305. common->Printf("ERROR: wglMakeCurrent failed.. Error:%i\n", qglGetError());
  1306. common->Printf("Please restart Q3Radiant if the Map view is not working\n");
  1307. bPaint = false;
  1308. }
  1309. if (bPaint) {
  1310. QE_CheckOpenGLForErrors();
  1311. XY_Draw();
  1312. QE_CheckOpenGLForErrors();
  1313. if (m_nViewType != XY) {
  1314. qglPushMatrix();
  1315. if (m_nViewType == YZ) {
  1316. qglRotatef(-90, 0, 1, 0); // put Z going up
  1317. }
  1318. qglRotatef(-90, 1, 0, 0); // put Z going up
  1319. }
  1320. if ( g_bCrossHairs ) {
  1321. qglColor4f( 0.2f, 0.9f, 0.2f, 0.8f );
  1322. qglBegin(GL_LINES);
  1323. if (m_nViewType == XY) {
  1324. qglVertex2f(-16384, tdp[1]);
  1325. qglVertex2f(16384, tdp[1]);
  1326. qglVertex2f(tdp[0], -16384);
  1327. qglVertex2f(tdp[0], 16384);
  1328. }
  1329. else if (m_nViewType == YZ) {
  1330. qglVertex3f(tdp[0], -16384, tdp[2]);
  1331. qglVertex3f(tdp[0], 16384, tdp[2]);
  1332. qglVertex3f(tdp[0], tdp[1], -16384);
  1333. qglVertex3f(tdp[0], tdp[1], 16384);
  1334. }
  1335. else {
  1336. qglVertex3f(-16384, tdp[1], tdp[2]);
  1337. qglVertex3f(16384, tdp[1], tdp[2]);
  1338. qglVertex3f(tdp[0], tdp[1], -16384);
  1339. qglVertex3f(tdp[0], tdp[1], 16384);
  1340. }
  1341. qglEnd();
  1342. }
  1343. if (ClipMode()) {
  1344. qglPointSize(4);
  1345. qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_CLIPPER].ToFloatPtr());
  1346. qglBegin(GL_POINTS);
  1347. if (g_Clip1.Set()) {
  1348. qglVertex3fv(g_Clip1);
  1349. }
  1350. if (g_Clip2.Set()) {
  1351. qglVertex3fv(g_Clip2);
  1352. }
  1353. if (g_Clip3.Set()) {
  1354. qglVertex3fv(g_Clip3);
  1355. }
  1356. qglEnd();
  1357. qglPointSize(1);
  1358. CString strMsg;
  1359. if (g_Clip1.Set()) {
  1360. qglRasterPos3f(g_Clip1.m_ptClip[0] + 2, g_Clip1.m_ptClip[1] + 2, g_Clip1.m_ptClip[2] + 2);
  1361. strMsg = "1";
  1362. // strMsg.Format("1 (%f, %f, %f)", g_Clip1[0], g_Clip1[1], g_Clip1[2]);
  1363. qglCallLists(strMsg.GetLength(), GL_UNSIGNED_BYTE, strMsg);
  1364. }
  1365. if (g_Clip2.Set()) {
  1366. qglRasterPos3f(g_Clip2.m_ptClip[0] + 2, g_Clip2.m_ptClip[1] + 2, g_Clip2.m_ptClip[2] + 2);
  1367. strMsg = "2";
  1368. // strMsg.Format("2 (%f, %f, %f)", g_Clip2[0], g_Clip2[1], g_Clip2[2]);
  1369. qglCallLists(strMsg.GetLength(), GL_UNSIGNED_BYTE, strMsg);
  1370. }
  1371. if (g_Clip3.Set()) {
  1372. qglRasterPos3f(g_Clip3.m_ptClip[0] + 2, g_Clip3.m_ptClip[1] + 2, g_Clip3.m_ptClip[2] + 2);
  1373. strMsg = "3";
  1374. // strMsg.Format("3 (%f, %f, %f)", g_Clip3[0], g_Clip3[1], g_Clip3[2]);
  1375. qglCallLists(strMsg.GetLength(), GL_UNSIGNED_BYTE, strMsg);
  1376. }
  1377. if (g_Clip1.Set() && g_Clip2.Set() && selected_brushes.next != &selected_brushes) {
  1378. ProduceSplitLists();
  1379. brush_t *pBrush;
  1380. brush_t *pList = ((m_nViewType == XZ) ? !g_bSwitch : g_bSwitch) ? &g_brBackSplits : &g_brFrontSplits;
  1381. for (pBrush = pList->next; pBrush != NULL && pBrush != pList; pBrush = pBrush->next) {
  1382. qglColor3f(1, 1, 0);
  1383. face_t *face;
  1384. int order;
  1385. for (face = pBrush->brush_faces, order = 0; face; face = face->next, order++) {
  1386. idWinding *w = face->face_winding;
  1387. if (!w) {
  1388. continue;
  1389. }
  1390. // draw the polygon
  1391. qglBegin(GL_LINE_LOOP);
  1392. for (int i = 0; i < w->GetNumPoints(); i++) {
  1393. qglVertex3fv( (*w)[i].ToFloatPtr() );
  1394. }
  1395. qglEnd();
  1396. }
  1397. }
  1398. }
  1399. }
  1400. if (PathMode()) {
  1401. qglPointSize(4);
  1402. qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_CLIPPER].ToFloatPtr());
  1403. qglBegin(GL_POINTS);
  1404. int n;
  1405. for ( n = 0; n < g_nPathCount; n++) {
  1406. qglVertex3fv(g_PathPoints[n]);
  1407. }
  1408. qglEnd();
  1409. qglPointSize(1);
  1410. CString strMsg;
  1411. for (n = 0; n < g_nPathCount; n++) {
  1412. qglRasterPos3f
  1413. (
  1414. g_PathPoints[n].m_ptClip[0] + 2,
  1415. g_PathPoints[n].m_ptClip[1] + 2,
  1416. g_PathPoints[n].m_ptClip[2] + 2
  1417. );
  1418. strMsg.Format("%i", n + 1);
  1419. qglCallLists(strMsg.GetLength(), GL_UNSIGNED_BYTE, strMsg);
  1420. }
  1421. }
  1422. if (m_nViewType != XY) {
  1423. qglPopMatrix();
  1424. }
  1425. qwglSwapBuffers(dc.m_hDC);
  1426. TRACE("XY Paint\n");
  1427. }
  1428. }
  1429. /*
  1430. =======================================================================================================================
  1431. =======================================================================================================================
  1432. */
  1433. void CXYWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) {
  1434. g_pParentWnd->HandleKey(nChar, nRepCnt, nFlags);
  1435. }
  1436. //
  1437. // =======================================================================================================================
  1438. // FIXME: the brush_t *pBrush is never used. ( Entity_Create uses selected_brushes )
  1439. // =======================================================================================================================
  1440. //
  1441. void CreateEntityFromName(char *pName, brush_t *pBrush, bool forceFixed, idVec3 min, idVec3 max, idVec3 org) {
  1442. eclass_t *pecNew;
  1443. entity_t *petNew;
  1444. if (stricmp(pName, "worldspawn") == 0) {
  1445. g_pParentWnd->MessageBox("Can't create an entity with worldspawn.", "info", 0);
  1446. return;
  1447. }
  1448. pecNew = Eclass_ForName(pName, false);
  1449. if ((GetAsyncKeyState(VK_SHIFT) & 0x8000)) {
  1450. Select_Ungroup();
  1451. }
  1452. // create it
  1453. petNew = Entity_Create(pecNew, forceFixed);
  1454. if (petNew && idStr::Icmp(pName, "light") == 0 ) {
  1455. idVec3 rad = max - min;
  1456. rad *= 0.5;
  1457. if (rad.x != 0 && rad.y != 0 && rad.z != 0) {
  1458. SetKeyValue(petNew, "light_radius", va("%g %g %g", idMath::Fabs(rad.x), idMath::Fabs(rad.y), idMath::Fabs(rad.z)));
  1459. DeleteKey(petNew, "light");
  1460. }
  1461. }
  1462. if (petNew == NULL) {
  1463. if (!((selected_brushes.next == &selected_brushes) || (selected_brushes.next->next != &selected_brushes))) {
  1464. brush_t *b = selected_brushes.next;
  1465. if (b->owner != world_entity && ((b->owner->eclass->fixedsize && pecNew->fixedsize) || forceFixed)) {
  1466. idVec3 mins, maxs;
  1467. idVec3 origin;
  1468. for (int i = 0; i < 3; i++) {
  1469. origin[i] = b->mins[i] - pecNew->mins[i];
  1470. }
  1471. VectorAdd(pecNew->mins, origin, mins);
  1472. VectorAdd(pecNew->maxs, origin, maxs);
  1473. brush_t *nb = Brush_Create(mins, maxs, &pecNew->texdef);
  1474. Entity_LinkBrush(b->owner, nb);
  1475. nb->owner->eclass = pecNew;
  1476. SetKeyValue(nb->owner, "classname", pName);
  1477. Brush_Free(b);
  1478. Brush_Build(nb);
  1479. Brush_AddToList(nb, &active_brushes);
  1480. Select_Brush(nb);
  1481. return;
  1482. }
  1483. }
  1484. g_pParentWnd->MessageBox("Failed to create entity.", "info", 0);
  1485. return;
  1486. }
  1487. Select_Deselect();
  1488. //
  1489. // entity_t* pEntity = world_entity; if (selected_brushes.next !=
  1490. // &selected_brushes) pEntity = selected_brushes.next->owner;
  1491. //
  1492. Select_Brush(petNew->brushes.onext);
  1493. Brush_Build(petNew->brushes.onext);
  1494. }
  1495. /*
  1496. =======================================================================================================================
  1497. =======================================================================================================================
  1498. */
  1499. brush_t *CreateEntityBrush(int x, int y, CXYWnd *pWnd) {
  1500. idVec3 mins, maxs;
  1501. int i;
  1502. float temp;
  1503. brush_t *n;
  1504. pWnd->SnapToPoint(x, y, mins);
  1505. x += 32;
  1506. y += 32;
  1507. pWnd->SnapToPoint(x, y, maxs);
  1508. int nDim = (pWnd->GetViewType() == XY) ? 2 : (pWnd->GetViewType() == YZ) ? 0 : 1;
  1509. mins[nDim] = g_qeglobals.d_gridsize * ((int)(g_qeglobals.d_new_brush_bottom[nDim] / g_qeglobals.d_gridsize));
  1510. maxs[nDim] = g_qeglobals.d_gridsize * ((int)(g_qeglobals.d_new_brush_top[nDim] / g_qeglobals.d_gridsize));
  1511. if (maxs[nDim] <= mins[nDim]) {
  1512. maxs[nDim] = mins[nDim] + g_qeglobals.d_gridsize;
  1513. }
  1514. for (i = 0; i < 3; i++) {
  1515. if (mins[i] == maxs[i]) {
  1516. maxs[i] += 16; // don't create a degenerate brush
  1517. }
  1518. if (mins[i] > maxs[i]) {
  1519. temp = mins[i];
  1520. mins[i] = maxs[i];
  1521. maxs[i] = temp;
  1522. }
  1523. }
  1524. n = Brush_Create(mins, maxs, &g_qeglobals.d_texturewin.texdef);
  1525. if (!n) {
  1526. return NULL;
  1527. }
  1528. Brush_AddToList(n, &selected_brushes);
  1529. Entity_LinkBrush(world_entity, n);
  1530. Brush_Build(n);
  1531. return n;
  1532. }
  1533. /*
  1534. =======================================================================================================================
  1535. =======================================================================================================================
  1536. */
  1537. void CreateRightClickEntity(CXYWnd *pWnd, int x, int y, char *pName) {
  1538. idVec3 min, max, org;
  1539. Select_GetBounds(min, max);
  1540. Select_GetMid(org);
  1541. CRect rctZ;
  1542. pWnd->GetClientRect(rctZ);
  1543. brush_t *pBrush;
  1544. if (selected_brushes.next == &selected_brushes) {
  1545. pBrush = CreateEntityBrush(x, rctZ.Height() - 1 - y, pWnd);
  1546. min.Zero();
  1547. max.Zero();
  1548. CreateEntityFromName(pName, pBrush, true, min, max, org);
  1549. }
  1550. else {
  1551. pBrush = selected_brushes.next;
  1552. CreateEntityFromName(pName, pBrush, false, min, max, org);
  1553. }
  1554. }
  1555. /*
  1556. =======================================================================================================================
  1557. =======================================================================================================================
  1558. */
  1559. brush_t *CreateSmartBrush(idVec3 v) {
  1560. idVec3 mins, maxs;
  1561. int i;
  1562. brush_t *n;
  1563. for (i = 0; i < 3; i++) {
  1564. mins[i] = v[i] - 16;
  1565. maxs[i] = v[i] + 16;
  1566. }
  1567. n = Brush_Create(mins, maxs, &g_qeglobals.d_texturewin.texdef);
  1568. if (!n) {
  1569. return NULL;
  1570. }
  1571. Brush_AddToList(n, &selected_brushes);
  1572. // Entity_LinkBrush(world_entity, n);
  1573. Brush_Build(n);
  1574. return n;
  1575. }
  1576. CString g_strSmartEntity;
  1577. int g_nSmartX;
  1578. int g_nSmartY;
  1579. bool g_bSmartWaiting;
  1580. /*
  1581. =======================================================================================================================
  1582. =======================================================================================================================
  1583. */
  1584. void _SmartPointDone(bool b, int n) {
  1585. g_bSmartWaiting = false;
  1586. }
  1587. /*
  1588. =======================================================================================================================
  1589. =======================================================================================================================
  1590. */
  1591. void CreateSmartEntity(CXYWnd *pWnd, int x, int y, const char *pName) {
  1592. g_nSmartX = x;
  1593. g_nSmartY = y;
  1594. g_strSmartEntity = pName;
  1595. if (g_strSmartEntity.Find("Smart_Train") >= 0) {
  1596. 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");
  1597. g_bPathMode = true;
  1598. g_nPathLimit = 0;
  1599. g_nPathCount = 0;
  1600. g_bSmartGo = true;
  1601. }
  1602. else if (g_strSmartEntity.Find("Smart_Monster...") >= 0) {
  1603. g_bPathMode = true;
  1604. g_nPathLimit = 0;
  1605. g_nPathCount = 0;
  1606. }
  1607. else if (g_strSmartEntity.Find("Smart_Rotating") >= 0) {
  1608. g_bSmartWaiting = true;
  1609. ShowInfoDialog("Left click to specify the rotation origin");
  1610. AcquirePath(1, &_SmartPointDone);
  1611. while (g_bSmartWaiting) {
  1612. MSG msg;
  1613. if (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
  1614. TranslateMessage(&msg);
  1615. DispatchMessage(&msg);
  1616. }
  1617. }
  1618. HideInfoDialog();
  1619. CPtrArray array;
  1620. g_bScreenUpdates = false;
  1621. CreateRightClickEntity(g_pParentWnd->ActiveXY(), g_nSmartX, g_nSmartY, "func_rotating");
  1622. array.Add(reinterpret_cast < void * > (selected_brushes.next));
  1623. Select_Deselect();
  1624. brush_t *pBrush = CreateSmartBrush(g_PathPoints[0]);
  1625. array.Add(pBrush);
  1626. Select_Deselect();
  1627. Select_Brush(reinterpret_cast < brush_t * > (array.GetAt(0)));
  1628. Select_Brush(reinterpret_cast < brush_t * > (array.GetAt(1)));
  1629. ConnectEntities();
  1630. g_bScreenUpdates = true;
  1631. }
  1632. }
  1633. /*
  1634. =======================================================================================================================
  1635. =======================================================================================================================
  1636. */
  1637. void FinishSmartCreation() {
  1638. CPtrArray array;
  1639. HideInfoDialog();
  1640. brush_t *pEntities = NULL;
  1641. if (g_strSmartEntity.Find("Smart_Train") >= 0) {
  1642. g_bScreenUpdates = false;
  1643. CreateRightClickEntity(g_pParentWnd->ActiveXY(), g_nSmartX, g_nSmartY, "func_train");
  1644. array.Add(reinterpret_cast < void * > (selected_brushes.next));
  1645. int n;
  1646. for (n = 0; n < g_nPathCount; n++) {
  1647. Select_Deselect();
  1648. CreateRightClickEntity
  1649. (
  1650. g_pParentWnd->ActiveXY(),
  1651. g_PathPoints[n].m_ptScreen.x,
  1652. g_PathPoints[n].m_ptScreen.y,
  1653. "path_corner"
  1654. );
  1655. array.Add(reinterpret_cast < void * > (selected_brushes.next));
  1656. }
  1657. for (n = 0; n < g_nPathCount; n++) {
  1658. Select_Deselect();
  1659. Select_Brush(reinterpret_cast < brush_t * > (array.GetAt(n)));
  1660. Select_Brush(reinterpret_cast < brush_t * > (array.GetAt(n + 1)));
  1661. ConnectEntities();
  1662. }
  1663. g_bScreenUpdates = true;
  1664. }
  1665. g_nPathCount = 0;
  1666. g_bPathMode = false;
  1667. Sys_UpdateWindows(W_ALL);
  1668. }
  1669. /*
  1670. =======================================================================================================================
  1671. =======================================================================================================================
  1672. */
  1673. void CXYWnd::KillPathMode() {
  1674. g_bSmartGo = false;
  1675. g_bPathMode = false;
  1676. if (g_pPathFunc) {
  1677. g_pPathFunc(false, g_nPathCount);
  1678. }
  1679. g_nPathCount = 0;
  1680. g_pPathFunc = NULL;
  1681. Sys_UpdateWindows(W_ALL);
  1682. }
  1683. //
  1684. // =======================================================================================================================
  1685. // gets called for drop down menu messages TIP: it's not always about EntityCreate
  1686. // =======================================================================================================================
  1687. //
  1688. void CXYWnd::OnEntityCreate(unsigned int nID) {
  1689. if (m_mnuDrop.GetSafeHmenu()) {
  1690. CString strItem;
  1691. m_mnuDrop.GetMenuString(nID, strItem, MF_BYCOMMAND);
  1692. if (strItem.CompareNoCase("Add to...") == 0) {
  1693. //
  1694. // ++timo TODO: fill the menu with current groups? this one is for adding to
  1695. // existing groups only
  1696. //
  1697. common->Printf("TODO: Add to... in CXYWnd::OnEntityCreate\n");
  1698. }
  1699. else if (strItem.CompareNoCase("Remove") == 0) {
  1700. // remove selected brushes from their current group
  1701. brush_t *b;
  1702. for (b = selected_brushes.next; b != &selected_brushes; b = b->next) {
  1703. }
  1704. }
  1705. // ++timo FIXME: remove when all hooks are in
  1706. if
  1707. (
  1708. strItem.CompareNoCase("Add to...") == 0 ||
  1709. strItem.CompareNoCase("Remove") == 0 ||
  1710. strItem.CompareNoCase("Name...") == 0 ||
  1711. strItem.CompareNoCase("New group...") == 0
  1712. ) {
  1713. common->Printf("TODO: hook drop down group menu\n");
  1714. return;
  1715. }
  1716. if (strItem.Find("Smart_") >= 0) {
  1717. CreateSmartEntity(this, m_ptDown.x, m_ptDown.y, strItem);
  1718. }
  1719. else {
  1720. CreateRightClickEntity(this, m_ptDown.x, m_ptDown.y, strItem.GetBuffer(0));
  1721. }
  1722. Sys_UpdateWindows(W_ALL);
  1723. // OnLButtonDown((MK_LBUTTON | MK_SHIFT), CPoint(m_ptDown.x+2, m_ptDown.y+2));
  1724. }
  1725. }
  1726. BOOL CXYWnd::OnCmdMsg( UINT nID, int nCode, void *pExtra, AFX_CMDHANDLERINFO *pHandlerInfo )
  1727. {
  1728. if ( CWnd::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) {
  1729. return TRUE;
  1730. }
  1731. return AfxGetMainWnd()->OnCmdMsg( nID, nCode, pExtra, pHandlerInfo );
  1732. }
  1733. bool MergeMenu(CMenu * pMenuDestination, const CMenu * pMenuAdd, bool bTopLevel /*=false*/)
  1734. {
  1735. // get the number menu items in the menus
  1736. int iMenuAddItemCount = pMenuAdd->GetMenuItemCount();
  1737. int iMenuDestItemCount = pMenuDestination->GetMenuItemCount();
  1738. // if there are no items return
  1739. if (iMenuAddItemCount == 0)
  1740. return true;
  1741. // if we are not at top level and the destination menu is not empty
  1742. // -> we append a seperator
  1743. if (!bTopLevel && iMenuDestItemCount > 0)
  1744. pMenuDestination->AppendMenu(MF_SEPARATOR);
  1745. // iterate through the top level of <pMenuAdd>
  1746. for(int iLoop = 0; iLoop < iMenuAddItemCount; iLoop++)
  1747. {
  1748. // get the menu string from the add menu
  1749. CString sMenuAddString;
  1750. pMenuAdd->GetMenuString(iLoop, sMenuAddString, MF_BYPOSITION);
  1751. // try to get the submenu of the current menu item
  1752. CMenu* pSubMenu = pMenuAdd->GetSubMenu(iLoop);
  1753. // check if we have a sub menu
  1754. if (!pSubMenu)
  1755. {
  1756. // normal menu item
  1757. // read the source and append at the destination
  1758. UINT nState = pMenuAdd->GetMenuState(iLoop, MF_BYPOSITION);
  1759. UINT nItemID = pMenuAdd->GetMenuItemID(iLoop);
  1760. if (pMenuDestination->AppendMenu(nState, nItemID, sMenuAddString))
  1761. {
  1762. // menu item added, don't forget to correct the item count
  1763. iMenuDestItemCount++;
  1764. }
  1765. else
  1766. {
  1767. TRACE("MergeMenu: AppendMenu failed!\n");
  1768. return false;
  1769. }
  1770. }
  1771. else
  1772. {
  1773. // create or insert a new popup menu item
  1774. // default insert pos is like ap
  1775. int iInsertPosDefault = -1;
  1776. // if we are at top level merge into existing popups rather than
  1777. // creating new ones
  1778. if(bTopLevel)
  1779. {
  1780. ASSERT(sMenuAddString != "&?" && sMenuAddString !=
  1781. "?");
  1782. CString csAdd(sMenuAddString);
  1783. csAdd.Remove('&'); // for comparison of menu items supress '&'
  1784. bool bAdded = false;
  1785. // try to find existing popup
  1786. for( int iLoop1 = 0; iLoop1 < iMenuDestItemCount; iLoop1++ )
  1787. {
  1788. // get the menu string from the destination menu
  1789. CString sDest;
  1790. pMenuDestination->GetMenuString(iLoop1, sDest, MF_BYPOSITION);
  1791. sDest.Remove('&'); // for a better compare (s.a.)
  1792. if (csAdd == sDest)
  1793. {
  1794. // we got a hit -> merge the two popups
  1795. // try to get the submenu of the desired destination menu item
  1796. CMenu* pSubMenuDest =
  1797. pMenuDestination->GetSubMenu(iLoop1);
  1798. if (pSubMenuDest)
  1799. {
  1800. // merge the popup recursivly and continue with outer for loop
  1801. if (!MergeMenu(pSubMenuDest, pSubMenu, false))
  1802. return false;
  1803. bAdded = true;
  1804. break;
  1805. }
  1806. }
  1807. // alternativ insert before <Window> or <Help>
  1808. if (iInsertPosDefault == -1 && (sDest == "Window"
  1809. || sDest == "?" || sDest == "Help"))
  1810. {
  1811. iInsertPosDefault = iLoop1;
  1812. }
  1813. } // for (iLoop1)
  1814. if (bAdded)
  1815. {
  1816. // menu added, so go on with loop over pMenuAdd's top level
  1817. continue;
  1818. }
  1819. } // if (bTopLevel)
  1820. // if the top level search did not find a position append the menu
  1821. if( iInsertPosDefault == -1 )
  1822. {
  1823. iInsertPosDefault = pMenuDestination->GetMenuItemCount();
  1824. }
  1825. // create a new popup and insert before <Window> or <Help>
  1826. CMenu NewPopupMenu;
  1827. if (!NewPopupMenu.CreatePopupMenu())
  1828. {
  1829. TRACE("MergeMenu: CreatePopupMenu failed!\n");
  1830. return false;
  1831. }
  1832. // merge the new popup recursivly
  1833. if (!MergeMenu(&NewPopupMenu, pSubMenu, false))
  1834. return false;
  1835. // insert the new popup menu into the destination menu
  1836. HMENU hNewMenu = NewPopupMenu.GetSafeHmenu();
  1837. if (pMenuDestination->InsertMenu(iInsertPosDefault,
  1838. MF_BYPOSITION | MF_POPUP | MF_ENABLED,
  1839. (UINT)hNewMenu, sMenuAddString ))
  1840. {
  1841. // don't forget to correct the item count
  1842. iMenuDestItemCount++;
  1843. }
  1844. else
  1845. {
  1846. TRACE("MergeMenu: InsertMenu failed!\n");
  1847. return false;
  1848. }
  1849. // don't destroy the new menu
  1850. NewPopupMenu.Detach();
  1851. } // if (pSubMenu)
  1852. } // for (iLoop)
  1853. return true;
  1854. }
  1855. /*
  1856. =======================================================================================================================
  1857. =======================================================================================================================
  1858. */
  1859. void CXYWnd::HandleDrop() {
  1860. if (g_PrefsDlg.m_bRightClick == false) {
  1861. return;
  1862. }
  1863. if (!m_mnuDrop.GetSafeHmenu()) { // first time, load it up
  1864. m_mnuDrop.CreatePopupMenu();
  1865. CMenu *drop = new CMenu;
  1866. drop->LoadMenu( IDR_MENU_DROP );
  1867. MergeMenu( &m_mnuDrop, drop, false );
  1868. int nID = ID_ENTITY_START;
  1869. CMenu *pMakeEntityPop = &m_mnuDrop;
  1870. // Todo: Make this a config option maybe?
  1871. const int entitiesOnSubMenu = false;
  1872. if ( entitiesOnSubMenu ) {
  1873. pMakeEntityPop = new CMenu;
  1874. pMakeEntityPop->CreateMenu();
  1875. }
  1876. CMenu *pChild = NULL;
  1877. eclass_t *e;
  1878. CString strActive;
  1879. CString strLast;
  1880. CString strName;
  1881. for (e = eclass; e; e = e->next) {
  1882. strLast = strName;
  1883. strName = e->name;
  1884. int n_ = strName.Find("_");
  1885. if (n_ > 0) {
  1886. CString strLeft = strName.Left(n_);
  1887. CString strRight = strName.Right(strName.GetLength() - n_ - 1);
  1888. if (strLeft == strActive) { // this is a child
  1889. ASSERT(pChild);
  1890. pChild->AppendMenu(MF_STRING, nID++, strName);
  1891. }
  1892. else {
  1893. if (pChild) {
  1894. pMakeEntityPop->AppendMenu (
  1895. MF_POPUP,
  1896. reinterpret_cast < unsigned int > (pChild->GetSafeHmenu()),
  1897. strActive
  1898. );
  1899. g_ptrMenus.Add(pChild);
  1900. // pChild->DestroyMenu(); delete pChild;
  1901. pChild = NULL;
  1902. }
  1903. strActive = strLeft;
  1904. pChild = new CMenu;
  1905. pChild->CreateMenu();
  1906. pChild->AppendMenu(MF_STRING, nID++, strName);
  1907. }
  1908. }
  1909. else {
  1910. if (pChild) {
  1911. pMakeEntityPop->AppendMenu (
  1912. MF_POPUP,
  1913. reinterpret_cast < unsigned int > (pChild->GetSafeHmenu()),
  1914. strActive
  1915. );
  1916. g_ptrMenus.Add(pChild);
  1917. // pChild->DestroyMenu(); delete pChild;
  1918. pChild = NULL;
  1919. }
  1920. strActive = "";
  1921. pMakeEntityPop->AppendMenu(MF_STRING, nID++, strName);
  1922. }
  1923. }
  1924. if ( pMakeEntityPop != &m_mnuDrop ) {
  1925. m_mnuDrop.AppendMenu (
  1926. MF_POPUP,
  1927. reinterpret_cast < unsigned int > (pMakeEntityPop->GetSafeHmenu()),
  1928. "Make Entity"
  1929. );
  1930. }
  1931. }
  1932. CPoint ptMouse;
  1933. GetCursorPos(&ptMouse);
  1934. m_mnuDrop.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, ptMouse.x, ptMouse.y, this);
  1935. }
  1936. /*
  1937. =======================================================================================================================
  1938. =======================================================================================================================
  1939. */
  1940. void CXYWnd::XY_Init() {
  1941. m_vOrigin[0] = 0;
  1942. m_vOrigin[1] = 20;
  1943. m_vOrigin[2] = 46;
  1944. m_fScale = 1;
  1945. m_precisionCrosshairMode = PRECISION_CROSSHAIR_NONE;
  1946. }
  1947. /*
  1948. =======================================================================================================================
  1949. =======================================================================================================================
  1950. */
  1951. void CXYWnd::SnapToPoint(int x, int y, idVec3 &point) {
  1952. if (g_PrefsDlg.m_bNoClamp) {
  1953. XY_ToPoint(x, y, point);
  1954. }
  1955. else {
  1956. XY_ToGridPoint(x, y, point);
  1957. }
  1958. // -- else -- XY_ToPoint(x, y, point); -- //XY_ToPoint(x, y, point);
  1959. }
  1960. /*
  1961. =======================================================================================================================
  1962. =======================================================================================================================
  1963. */
  1964. void CXYWnd::XY_ToPoint(int x, int y, idVec3 &point) {
  1965. float fx = x;
  1966. float fy = y;
  1967. float fw = m_nWidth;
  1968. float fh = m_nHeight;
  1969. if (m_nViewType == XY) {
  1970. point[0] = m_vOrigin[0] + (fx - fw / 2) / m_fScale;
  1971. point[1] = m_vOrigin[1] + (fy - fh / 2) / m_fScale;
  1972. // point[2] = 0;
  1973. }
  1974. else if (m_nViewType == YZ) {
  1975. //
  1976. // //point[0] = 0; point[1] = m_vOrigin[0] + (fx - fw / 2) / m_fScale; point[2] =
  1977. // m_vOrigin[1] + (fy - fh / 2 ) / m_fScale;
  1978. //
  1979. point[1] = m_vOrigin[1] + (fx - fw / 2) / m_fScale;
  1980. point[2] = m_vOrigin[2] + (fy - fh / 2) / m_fScale;
  1981. }
  1982. else {
  1983. //
  1984. // point[0] = m_vOrigin[0] + (fx - fw / 2) / m_fScale; /point[1] = 0; point[2] =
  1985. // m_vOrigin[1] + (fy - fh / 2) / m_fScale;
  1986. //
  1987. point[0] = m_vOrigin[0] + (fx - fw / 2) / m_fScale;
  1988. // point[1] = 0;
  1989. point[2] = m_vOrigin[2] + (fy - fh / 2) / m_fScale;
  1990. }
  1991. }
  1992. /*
  1993. =======================================================================================================================
  1994. =======================================================================================================================
  1995. */
  1996. void CXYWnd::XY_ToGridPoint(int x, int y, idVec3 &point) {
  1997. if (m_nViewType == XY) {
  1998. point[0] = m_vOrigin[0] + (x - m_nWidth / 2) / m_fScale;
  1999. point[1] = m_vOrigin[1] + (y - m_nHeight / 2) / m_fScale;
  2000. // point[2] = 0;
  2001. point[0] = floor(point[0] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
  2002. point[1] = floor(point[1] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
  2003. }
  2004. else if (m_nViewType == YZ) {
  2005. //
  2006. // point[0] = 0; point[1] = m_vOrigin[0] + (x - m_nWidth / 2) / m_fScale; point[2]
  2007. // = m_vOrigin[1] + (y - m_nHeight / 2) / m_fScale;
  2008. //
  2009. point[1] = m_vOrigin[1] + (x - m_nWidth / 2) / m_fScale;
  2010. point[2] = m_vOrigin[2] + (y - m_nHeight / 2) / m_fScale;
  2011. point[1] = floor(point[1] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
  2012. point[2] = floor(point[2] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
  2013. }
  2014. else {
  2015. //
  2016. // point[1] = 0; point[0] = m_vOrigin[0] + (x - m_nWidth / 2) / m_fScale; point[2]
  2017. // = m_vOrigin[1] + (y - m_nHeight / 2) / m_fScale;
  2018. //
  2019. point[0] = m_vOrigin[0] + (x - m_nWidth / 2) / m_fScale;
  2020. point[2] = m_vOrigin[2] + (y - m_nHeight / 2) / m_fScale;
  2021. point[0] = floor(point[0] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
  2022. point[2] = floor(point[2] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
  2023. }
  2024. }
  2025. /*
  2026. =======================================================================================================================
  2027. =======================================================================================================================
  2028. */
  2029. idVec3 dragOrigin;
  2030. idVec3 dragDir;
  2031. idVec3 dragX;
  2032. idVec3 dragY;
  2033. void CXYWnd::XY_MouseDown(int x, int y, int buttons) {
  2034. idVec3 point,center;
  2035. idVec3 origin, dir, right, up;
  2036. m_nButtonstate = buttons;
  2037. m_nPressx = x;
  2038. m_nPressy = y;
  2039. VectorCopy(vec3_origin, m_vPressdelta);
  2040. point.Zero();
  2041. XY_ToPoint(x, y, point);
  2042. VectorCopy(point, origin);
  2043. dir.Zero();
  2044. if (m_nViewType == XY) {
  2045. origin[2] = HUGE_DISTANCE;
  2046. dir[2] = -1;
  2047. right[0] = 1 / m_fScale;
  2048. right[1] = 0;
  2049. right[2] = 0;
  2050. up[0] = 0;
  2051. up[1] = 1 / m_fScale;
  2052. up[2] = 0;
  2053. point[2] = g_pParentWnd->GetCamera()->Camera().origin[2];
  2054. }
  2055. else if (m_nViewType == YZ) {
  2056. origin[0] = HUGE_DISTANCE;
  2057. dir[0] = -1;
  2058. right[1] = 1 / m_fScale;
  2059. right[2] = 0;
  2060. right[0] = 0;
  2061. up[0] = 0;
  2062. up[2] = 1 / m_fScale;
  2063. up[1] = 0;
  2064. point[0] = g_pParentWnd->GetCamera()->Camera().origin[0];
  2065. }
  2066. else {
  2067. origin[1] = HUGE_DISTANCE;
  2068. dir[1] = -1;
  2069. right[0] = 1 / m_fScale;
  2070. right[2] = 0;
  2071. right[1] = 0;
  2072. up[0] = 0;
  2073. up[2] = 1 / m_fScale;
  2074. up[1] = 0;
  2075. point[1] = g_pParentWnd->GetCamera()->Camera().origin[1];
  2076. }
  2077. dragOrigin = m_vOrigin;
  2078. dragDir = dir;
  2079. dragX = right;
  2080. dragY = up;
  2081. m_bPress_selection = (selected_brushes.next != &selected_brushes);
  2082. GetCursorPos(&m_ptCursor);
  2083. // Sys_GetCursorPos (&m_ptCursor.x, &m_ptCursor.y);
  2084. if (buttons == MK_LBUTTON && activeDrag) {
  2085. activeDragging = true;
  2086. }
  2087. else {
  2088. activeDragging = false;
  2089. }
  2090. // lbutton = manipulate selection shift-LBUTTON = select
  2091. if
  2092. (
  2093. (buttons == MK_LBUTTON) ||
  2094. (buttons == (MK_LBUTTON | MK_SHIFT)) ||
  2095. (buttons == (MK_LBUTTON | MK_CONTROL)) ||
  2096. (buttons == (MK_LBUTTON | MK_CONTROL | MK_SHIFT))
  2097. ) {
  2098. if (g_qeglobals.d_select_mode == sel_addpoint) {
  2099. XY_ToGridPoint(x, y, point);
  2100. if (g_qeglobals.selectObject) {
  2101. g_qeglobals.selectObject->addPoint(point);
  2102. }
  2103. return;
  2104. }
  2105. Patch_SetView((m_nViewType == XY) ? W_XY : (m_nViewType == YZ) ? W_YZ : W_XZ);
  2106. Drag_Begin(x, y, buttons, right, up, origin, dir);
  2107. return;
  2108. }
  2109. int nMouseButton = g_PrefsDlg.m_nMouseButtons == 2 ? MK_RBUTTON : MK_MBUTTON;
  2110. // control mbutton = move camera
  2111. if (m_nButtonstate == (MK_CONTROL | nMouseButton)) {
  2112. VectorCopyXY(point, g_pParentWnd->GetCamera()->Camera().origin);
  2113. Sys_UpdateWindows(W_CAMERA | W_XY_OVERLAY);
  2114. }
  2115. // mbutton = angle camera
  2116. if
  2117. (
  2118. (g_PrefsDlg.m_nMouseButtons == 3 && m_nButtonstate == MK_MBUTTON) ||
  2119. (g_PrefsDlg.m_nMouseButtons == 2 && m_nButtonstate == (MK_SHIFT | MK_CONTROL | MK_RBUTTON))
  2120. ) {
  2121. VectorSubtract(point, g_pParentWnd->GetCamera()->Camera().origin, point);
  2122. int n1 = (m_nViewType == XY) ? 1 : 2;
  2123. int n2 = (m_nViewType == YZ) ? 1 : 0;
  2124. int nAngle = (m_nViewType == XY) ? YAW : PITCH;
  2125. if (point[n1] || point[n2]) {
  2126. g_pParentWnd->GetCamera()->Camera().angles[nAngle] = RAD2DEG( atan2(point[n1], point[n2]) );
  2127. Sys_UpdateWindows(W_CAMERA_IFON | W_XY_OVERLAY);
  2128. }
  2129. }
  2130. // shift mbutton = move z checker
  2131. if (m_nButtonstate == (MK_SHIFT | nMouseButton)) {
  2132. if (RotateMode() || g_bPatchBendMode) {
  2133. SnapToPoint(x, y, point);
  2134. VectorCopyXY(point, g_vRotateOrigin);
  2135. if (g_bPatchBendMode) {
  2136. VectorCopy(point, g_vBendOrigin);
  2137. }
  2138. Sys_UpdateWindows(W_XY);
  2139. return;
  2140. }
  2141. else {
  2142. SnapToPoint(x, y, point);
  2143. if (m_nViewType == XY) {
  2144. z.origin[0] = point[0];
  2145. z.origin[1] = point[1];
  2146. }
  2147. else if (m_nViewType == YZ) {
  2148. z.origin[0] = point[1];
  2149. z.origin[1] = point[2];
  2150. }
  2151. else {
  2152. z.origin[0] = point[0];
  2153. z.origin[1] = point[2];
  2154. }
  2155. Sys_UpdateWindows(W_XY_OVERLAY | W_Z);
  2156. return;
  2157. }
  2158. }
  2159. }
  2160. /*
  2161. =======================================================================================================================
  2162. =======================================================================================================================
  2163. */
  2164. void CXYWnd::XY_MouseUp(int x, int y, int buttons) {
  2165. activeDragging = false;
  2166. Drag_MouseUp(buttons);
  2167. if (!m_bPress_selection) {
  2168. Sys_UpdateWindows(W_ALL);
  2169. }
  2170. m_nButtonstate = 0;
  2171. while (::ShowCursor(TRUE) < 0)
  2172. ;
  2173. }
  2174. /*
  2175. =======================================================================================================================
  2176. =======================================================================================================================
  2177. */
  2178. bool CXYWnd::DragDelta(int x, int y, idVec3 &move) {
  2179. idVec3 xvec, yvec, delta;
  2180. int i;
  2181. xvec[0] = 1 / m_fScale;
  2182. xvec[1] = xvec[2] = 0;
  2183. yvec[1] = 1 / m_fScale;
  2184. yvec[0] = yvec[2] = 0;
  2185. for (i = 0; i < 3; i++) {
  2186. delta[i] = xvec[i] * (x - m_nPressx) + yvec[i] * (y - m_nPressy);
  2187. if (!g_PrefsDlg.m_bNoClamp) {
  2188. delta[i] = floor(delta[i] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
  2189. }
  2190. }
  2191. VectorSubtract(delta, m_vPressdelta, move);
  2192. VectorCopy(delta, m_vPressdelta);
  2193. if (move[0] || move[1] || move[2]) {
  2194. return true;
  2195. }
  2196. return false;
  2197. }
  2198. /*
  2199. =======================================================================================================================
  2200. NewBrushDrag
  2201. =======================================================================================================================
  2202. */
  2203. void CXYWnd::NewBrushDrag(int x, int y) {
  2204. idVec3 mins, maxs, junk;
  2205. int i;
  2206. float temp;
  2207. brush_t *n;
  2208. if ( radiant_entityMode.GetBool() ) {
  2209. return;
  2210. }
  2211. if (!DragDelta(x, y, junk)) {
  2212. return;
  2213. }
  2214. // delete the current selection
  2215. if (selected_brushes.next != &selected_brushes) {
  2216. Brush_Free(selected_brushes.next);
  2217. }
  2218. SnapToPoint(m_nPressx, m_nPressy, mins);
  2219. int nDim = (m_nViewType == XY) ? 2 : (m_nViewType == YZ) ? 0 : 1;
  2220. mins[nDim] = g_qeglobals.d_gridsize * ((int)(g_qeglobals.d_new_brush_bottom[nDim] / g_qeglobals.d_gridsize));
  2221. SnapToPoint(x, y, maxs);
  2222. maxs[nDim] = g_qeglobals.d_gridsize * ((int)(g_qeglobals.d_new_brush_top[nDim] / g_qeglobals.d_gridsize));
  2223. if (maxs[nDim] <= mins[nDim]) {
  2224. maxs[nDim] = mins[nDim] + g_qeglobals.d_gridsize;
  2225. }
  2226. for (i = 0; i < 3; i++) {
  2227. if (mins[i] == maxs[i]) {
  2228. return; // don't create a degenerate brush
  2229. }
  2230. if (mins[i] > maxs[i]) {
  2231. temp = mins[i];
  2232. mins[i] = maxs[i];
  2233. maxs[i] = temp;
  2234. }
  2235. }
  2236. n = Brush_Create(mins, maxs, &g_qeglobals.d_texturewin.texdef);
  2237. if (!n) {
  2238. return;
  2239. }
  2240. idVec3 vSize;
  2241. VectorSubtract(maxs, mins, vSize);
  2242. g_strStatus.Format("Size X:: %.1f Y:: %.1f Z:: %.1f", vSize[0], vSize[1], vSize[2]);
  2243. g_pParentWnd->SetStatusText(2, g_strStatus);
  2244. Brush_AddToList(n, &selected_brushes);
  2245. Entity_LinkBrush(world_entity, n);
  2246. Brush_Build(n);
  2247. // Sys_UpdateWindows (W_ALL);
  2248. Sys_UpdateWindows(W_XY | W_CAMERA);
  2249. }
  2250. /*
  2251. =======================================================================================================================
  2252. XY_MouseMoved
  2253. =======================================================================================================================
  2254. */
  2255. bool CXYWnd::XY_MouseMoved(int x, int y, int buttons) {
  2256. idVec3 point;
  2257. if (!m_nButtonstate) {
  2258. if (g_bCrossHairs) {
  2259. ::ShowCursor(FALSE);
  2260. Sys_UpdateWindows(W_XY | W_XY_OVERLAY);
  2261. ::ShowCursor(TRUE);
  2262. }
  2263. return false;
  2264. }
  2265. //
  2266. // lbutton without selection = drag new brush if (m_nButtonstate == MK_LBUTTON &&
  2267. // !m_bPress_selection && g_qeglobals.d_select_mode != sel_curvepoint &&
  2268. // g_qeglobals.d_select_mode != sel_splineedit)
  2269. //
  2270. if (m_nButtonstate == MK_LBUTTON && !m_bPress_selection && g_qeglobals.d_select_mode == sel_brush) {
  2271. NewBrushDrag(x, y);
  2272. return false;
  2273. }
  2274. // lbutton (possibly with control and or shift) with selection = drag selection
  2275. if (m_nButtonstate & MK_LBUTTON) {
  2276. Drag_MouseMoved(x, y, buttons);
  2277. Sys_UpdateWindows(W_XY_OVERLAY | W_CAMERA_IFON | W_Z);
  2278. return false;
  2279. }
  2280. int nMouseButton = g_PrefsDlg.m_nMouseButtons == 2 ? MK_RBUTTON : MK_MBUTTON;
  2281. // control mbutton = move camera
  2282. if (m_nButtonstate == (MK_CONTROL | nMouseButton)) {
  2283. SnapToPoint(x, y, point);
  2284. VectorCopyXY(point, g_pParentWnd->GetCamera()->Camera().origin);
  2285. Sys_UpdateWindows(W_XY_OVERLAY | W_CAMERA);
  2286. return false;
  2287. }
  2288. // shift mbutton = move z checker
  2289. if (m_nButtonstate == (MK_SHIFT | nMouseButton)) {
  2290. if (RotateMode() || g_bPatchBendMode) {
  2291. SnapToPoint(x, y, point);
  2292. VectorCopyXY(point, g_vRotateOrigin);
  2293. if (g_bPatchBendMode) {
  2294. VectorCopy(point, g_vBendOrigin);
  2295. }
  2296. Sys_UpdateWindows(W_XY);
  2297. return false;
  2298. }
  2299. else {
  2300. SnapToPoint(x, y, point);
  2301. if (m_nViewType == XY) {
  2302. z.origin[0] = point[0];
  2303. z.origin[1] = point[1];
  2304. }
  2305. else if (m_nViewType == YZ) {
  2306. z.origin[0] = point[1];
  2307. z.origin[1] = point[2];
  2308. }
  2309. else {
  2310. z.origin[0] = point[0];
  2311. z.origin[1] = point[2];
  2312. }
  2313. }
  2314. Sys_UpdateWindows(W_XY_OVERLAY | W_Z);
  2315. return false;
  2316. }
  2317. // mbutton = angle camera
  2318. if
  2319. (
  2320. (g_PrefsDlg.m_nMouseButtons == 3 && m_nButtonstate == MK_MBUTTON) ||
  2321. (g_PrefsDlg.m_nMouseButtons == 2 && m_nButtonstate == (MK_SHIFT | MK_CONTROL | MK_RBUTTON))
  2322. ) {
  2323. SnapToPoint(x, y, point);
  2324. VectorSubtract(point, g_pParentWnd->GetCamera()->Camera().origin, point);
  2325. int n1 = (m_nViewType == XY) ? 1 : 2;
  2326. int n2 = (m_nViewType == YZ) ? 1 : 0;
  2327. int nAngle = (m_nViewType == XY) ? YAW : PITCH;
  2328. if (point[n1] || point[n2]) {
  2329. g_pParentWnd->GetCamera()->Camera().angles[nAngle] = RAD2DEG( atan2(point[n1], point[n2]) );
  2330. Sys_UpdateWindows(W_CAMERA_IFON | W_XY_OVERLAY);
  2331. }
  2332. return false;
  2333. }
  2334. // rbutton = drag xy origin
  2335. if (m_nButtonstate == MK_RBUTTON) {
  2336. Sys_GetCursorPos(&x, &y);
  2337. if (x != m_ptCursor.x || y != m_ptCursor.y) {
  2338. if ((GetAsyncKeyState(VK_MENU) & 0x8000)) {
  2339. int *px = &x;
  2340. long *px2 = &m_ptCursor.x;
  2341. if (fDiff(y, m_ptCursor.y) > fDiff(x, m_ptCursor.x)) {
  2342. px = &y;
  2343. px2 = &m_ptCursor.y;
  2344. }
  2345. if (*px > *px2) {
  2346. // zoom in
  2347. SetScale( Scale() * 1.1f );
  2348. if ( Scale() < 0.1f ) {
  2349. SetScale( 0.1f );
  2350. }
  2351. }
  2352. else if (*px < *px2) {
  2353. // zoom out
  2354. SetScale( Scale() * 0.9f );
  2355. if ( Scale() > 16.0f ) {
  2356. SetScale( 16.0f );
  2357. }
  2358. }
  2359. *px2 = *px;
  2360. Sys_UpdateWindows(W_XY | W_XY_OVERLAY);
  2361. }
  2362. else {
  2363. int nDim1 = (m_nViewType == YZ) ? 1 : 0;
  2364. int nDim2 = (m_nViewType == XY) ? 1 : 2;
  2365. m_vOrigin[nDim1] -= (x - m_ptCursor.x) / m_fScale;
  2366. m_vOrigin[nDim2] += (y - m_ptCursor.y) / m_fScale;
  2367. SetCursorPos(m_ptCursor.x, m_ptCursor.y);
  2368. ::ShowCursor(FALSE);
  2369. // XY_Draw(); RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  2370. Sys_UpdateWindows(W_XY | W_XY_OVERLAY);
  2371. // ::ShowCursor(TRUE);
  2372. }
  2373. }
  2374. return false;
  2375. }
  2376. return false;
  2377. }
  2378. /*
  2379. =======================================================================================================================
  2380. DRAWING £
  2381. XY_DrawGrid
  2382. =======================================================================================================================
  2383. */
  2384. void CXYWnd::XY_DrawGrid() {
  2385. float x, y, xb, xe, yb, ye;
  2386. int w, h;
  2387. char text[32];
  2388. int startPos = max ( 64 , g_qeglobals.d_gridsize );
  2389. w = m_nWidth / 2 / m_fScale;
  2390. h = m_nHeight / 2 / m_fScale;
  2391. int nDim1 = (m_nViewType == YZ) ? 1 : 0;
  2392. int nDim2 = (m_nViewType == XY) ? 1 : 2;
  2393. // int nDim1 = 0; int nDim2 = 1;
  2394. xb = m_vOrigin[nDim1] - w;
  2395. if (xb < region_mins[nDim1]) {
  2396. xb = region_mins[nDim1];
  2397. }
  2398. xb = startPos * floor(xb / startPos);
  2399. xe = m_vOrigin[nDim1] + w;
  2400. if (xe > region_maxs[nDim1]) {
  2401. xe = region_maxs[nDim1];
  2402. }
  2403. xe = startPos * ceil(xe / startPos);
  2404. yb = m_vOrigin[nDim2] - h;
  2405. if (yb < region_mins[nDim2]) {
  2406. yb = region_mins[nDim2];
  2407. }
  2408. yb = startPos * floor(yb / startPos);
  2409. ye = m_vOrigin[nDim2] + h;
  2410. if (ye > region_maxs[nDim2]) {
  2411. ye = region_maxs[nDim2];
  2412. }
  2413. ye = startPos * ceil(ye / startPos);
  2414. // draw major blocks
  2415. qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDMAJOR].ToFloatPtr());
  2416. int stepSize = 64 * 0.1 / m_fScale;
  2417. if (stepSize < 64) {
  2418. stepSize = max ( 64 , g_qeglobals.d_gridsize );
  2419. }
  2420. else {
  2421. int i;
  2422. for (i = 1; i < stepSize; i <<= 1) {
  2423. }
  2424. stepSize = i;
  2425. }
  2426. if (g_qeglobals.d_showgrid) {
  2427. qglBegin(GL_LINES);
  2428. for (x = xb; x <= xe; x += stepSize) {
  2429. qglVertex2f(x, yb);
  2430. qglVertex2f(x, ye);
  2431. }
  2432. for (y = yb; y <= ye; y += stepSize) {
  2433. qglVertex2f(xb, y);
  2434. qglVertex2f(xe, y);
  2435. }
  2436. qglEnd();
  2437. }
  2438. // draw minor blocks
  2439. if ( m_fScale > .1 &&
  2440. g_qeglobals.d_showgrid &&
  2441. g_qeglobals.d_gridsize * m_fScale >= 4 &&
  2442. !g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR].Compare( g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK] ) ) {
  2443. qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR].ToFloatPtr());
  2444. qglBegin(GL_LINES);
  2445. for (x = xb; x < xe; x += g_qeglobals.d_gridsize) {
  2446. if (!((int)x & (startPos - 1))) {
  2447. continue;
  2448. }
  2449. qglVertex2f(x, yb);
  2450. qglVertex2f(x, ye);
  2451. }
  2452. for (y = yb; y < ye; y += g_qeglobals.d_gridsize) {
  2453. if (!((int)y & (startPos - 1))) {
  2454. continue;
  2455. }
  2456. qglVertex2f(xb, y);
  2457. qglVertex2f(xe, y);
  2458. }
  2459. qglEnd();
  2460. }
  2461. // draw ZClip boundaries (if applicable)...
  2462. //
  2463. if (m_nViewType == XZ || m_nViewType == YZ)
  2464. {
  2465. if (g_pParentWnd->GetZWnd()->m_pZClip) // should always be the case at this point I think, but this is safer
  2466. {
  2467. if (g_pParentWnd->GetZWnd()->m_pZClip->IsEnabled())
  2468. {
  2469. qglColor3f(ZCLIP_COLOUR);
  2470. qglLineWidth(2);
  2471. qglBegin (GL_LINES);
  2472. qglVertex2f (xb, g_pParentWnd->GetZWnd()->m_pZClip->GetTop());
  2473. qglVertex2f (xe, g_pParentWnd->GetZWnd()->m_pZClip->GetTop());
  2474. qglVertex2f (xb, g_pParentWnd->GetZWnd()->m_pZClip->GetBottom());
  2475. qglVertex2f (xe, g_pParentWnd->GetZWnd()->m_pZClip->GetBottom());
  2476. qglEnd ();
  2477. qglLineWidth(1);
  2478. }
  2479. }
  2480. }
  2481. // draw coordinate text if needed
  2482. if (g_qeglobals.d_savedinfo.show_coordinates) {
  2483. // glColor4f(0, 0, 0, 0);
  2484. qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDTEXT].ToFloatPtr());
  2485. float lastRaster = xb;
  2486. for (x = xb; x < xe; x += stepSize) {
  2487. qglRasterPos2f(x, m_vOrigin[nDim2] + h - 10 / m_fScale);
  2488. sprintf(text, "%i", (int)x);
  2489. qglCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
  2490. }
  2491. for (y = yb; y < ye; y += stepSize) {
  2492. qglRasterPos2f(m_vOrigin[nDim1] - w + 1, y);
  2493. sprintf(text, "%i", (int)y);
  2494. qglCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
  2495. }
  2496. if (Active()) {
  2497. qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_VIEWNAME].ToFloatPtr());
  2498. }
  2499. qglRasterPos2f(m_vOrigin[nDim1] - w + 35 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale);
  2500. char cView[20];
  2501. if (m_nViewType == XY) {
  2502. strcpy(cView, "XY Top");
  2503. }
  2504. else if (m_nViewType == XZ) {
  2505. strcpy(cView, "XZ Front");
  2506. }
  2507. else {
  2508. strcpy(cView, "YZ Side");
  2509. }
  2510. qglCallLists(strlen(cView), GL_UNSIGNED_BYTE, cView);
  2511. }
  2512. /*
  2513. * if (true) { qglColor3f(g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR]);
  2514. * qglBegin (GL_LINES); qglVertex2f (x, yb); qglVertex2f (x, ye); qglEnd(); }
  2515. */
  2516. }
  2517. /*
  2518. =======================================================================================================================
  2519. XY_DrawBlockGrid
  2520. =======================================================================================================================
  2521. */
  2522. void CXYWnd::XY_DrawBlockGrid() {
  2523. float x, y, xb, xe, yb, ye;
  2524. int w, h;
  2525. char text[32];
  2526. w = m_nWidth / 2 / m_fScale;
  2527. h = m_nHeight / 2 / m_fScale;
  2528. int nDim1 = (m_nViewType == YZ) ? 1 : 0;
  2529. int nDim2 = (m_nViewType == XY) ? 1 : 2;
  2530. xb = m_vOrigin[nDim1] - w;
  2531. if (xb < region_mins[nDim1]) {
  2532. xb = region_mins[nDim1];
  2533. }
  2534. xb = 1024 * floor(xb / 1024);
  2535. xe = m_vOrigin[nDim1] + w;
  2536. if (xe > region_maxs[nDim1]) {
  2537. xe = region_maxs[nDim1];
  2538. }
  2539. xe = 1024 * ceil(xe / 1024);
  2540. yb = m_vOrigin[nDim2] - h;
  2541. if (yb < region_mins[nDim2]) {
  2542. yb = region_mins[nDim2];
  2543. }
  2544. yb = 1024 * floor(yb / 1024);
  2545. ye = m_vOrigin[nDim2] + h;
  2546. if (ye > region_maxs[nDim2]) {
  2547. ye = region_maxs[nDim2];
  2548. }
  2549. ye = 1024 * ceil(ye / 1024);
  2550. // draw major blocks
  2551. qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDBLOCK].ToFloatPtr());
  2552. qglLineWidth(0.5);
  2553. qglBegin(GL_LINES);
  2554. for (x = xb; x <= xe; x += 1024) {
  2555. qglVertex2f(x, yb);
  2556. qglVertex2f(x, ye);
  2557. }
  2558. for (y = yb; y <= ye; y += 1024) {
  2559. qglVertex2f(xb, y);
  2560. qglVertex2f(xe, y);
  2561. }
  2562. qglEnd();
  2563. qglLineWidth(0.25);
  2564. // draw coordinate text if needed
  2565. for (x = xb; x < xe; x += 1024) {
  2566. for (y = yb; y < ye; y += 1024) {
  2567. qglRasterPos2f(x + 512, y + 512);
  2568. sprintf(text, "%i,%i", (int)floor(x / 1024), (int)floor(y / 1024));
  2569. qglCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
  2570. }
  2571. }
  2572. qglColor4f(0, 0, 0, 0);
  2573. }
  2574. void GLColoredBoxWithLabel(float x, float y, float size, idVec4 color, const char *text, idVec4 textColor, float xofs, float yofs, float lineSize) {
  2575. globalImages->BindNull();
  2576. qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  2577. qglDisable(GL_CULL_FACE);
  2578. qglDisable(GL_BLEND);
  2579. qglColor4f(color[0], color[1], color[2], color[3]);
  2580. qglBegin(GL_QUADS);
  2581. qglVertex3f(x - size, y - size, 0);
  2582. qglVertex3f(x + size, y - size, 0);
  2583. qglVertex3f(x + size, y + size, 0);
  2584. qglVertex3f(x - size, y + size, 0);
  2585. qglEnd();
  2586. qglColor4f(textColor[0], textColor[1], textColor[2], textColor[3]);
  2587. qglLineWidth(lineSize);
  2588. qglRasterPos2f(x + xofs, y + yofs);
  2589. qglCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
  2590. }
  2591. /*
  2592. =======================================================================================================================
  2593. =======================================================================================================================
  2594. */
  2595. void CXYWnd::DrawRotateIcon() {
  2596. float x, y;
  2597. if (m_nViewType == XY) {
  2598. x = g_vRotateOrigin[0];
  2599. y = g_vRotateOrigin[1];
  2600. }
  2601. else if (m_nViewType == YZ) {
  2602. x = g_vRotateOrigin[1];
  2603. y = g_vRotateOrigin[2];
  2604. }
  2605. else {
  2606. x = g_vRotateOrigin[0];
  2607. y = g_vRotateOrigin[2];
  2608. }
  2609. qglEnable(GL_BLEND);
  2610. globalImages->BindNull();
  2611. qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  2612. qglDisable(GL_CULL_FACE);
  2613. qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  2614. qglColor4f( 0.8f, 0.1f, 0.9f, 0.25f );
  2615. qglBegin(GL_QUADS);
  2616. qglVertex3f(x - 4, y - 4, 0);
  2617. qglVertex3f(x + 4, y - 4, 0);
  2618. qglVertex3f(x + 4, y + 4, 0);
  2619. qglVertex3f(x - 4, y + 4, 0);
  2620. qglEnd();
  2621. qglDisable(GL_BLEND);
  2622. qglColor4f( 1.0f, 0.2f, 1.0f, 1.0f );
  2623. qglBegin(GL_POINTS);
  2624. qglVertex3f(x, y, 0);
  2625. qglEnd();
  2626. int w = m_nWidth / 2 / m_fScale;
  2627. int h = m_nHeight / 2 / m_fScale;
  2628. int nDim1 = (m_nViewType == YZ) ? 1 : 0;
  2629. int nDim2 = (m_nViewType == XY) ? 1 : 2;
  2630. x = m_vOrigin[nDim1] - w + 35 / m_fScale;
  2631. y = m_vOrigin[nDim2] + h - 40 / m_fScale;
  2632. const char *p = "Rotate Z Axis";
  2633. if (g_qeglobals.rotateAxis == 1) {
  2634. p = "Rotate Y Axis";
  2635. } else if (g_qeglobals.rotateAxis == 0) {
  2636. p = "Rotate X Axis";
  2637. }
  2638. idStr str = p;
  2639. if (g_qeglobals.flatRotation) {
  2640. str += g_qeglobals.flatRotation == 2 ? " Flat [center] " : " Flat [ rot origin ] ";
  2641. }
  2642. qglRasterPos2f(x, y);
  2643. qglCallLists(str.Length(), GL_UNSIGNED_BYTE, str.c_str());
  2644. }
  2645. /*
  2646. =======================================================================================================================
  2647. =======================================================================================================================
  2648. */
  2649. void CXYWnd::DrawCameraIcon() {
  2650. float x, y, a;
  2651. if (m_nViewType == XY) {
  2652. x = g_pParentWnd->GetCamera()->Camera().origin[0];
  2653. y = g_pParentWnd->GetCamera()->Camera().origin[1];
  2654. a = g_pParentWnd->GetCamera()->Camera().angles[YAW] * idMath::M_DEG2RAD;
  2655. }
  2656. else if (m_nViewType == YZ) {
  2657. x = g_pParentWnd->GetCamera()->Camera().origin[1];
  2658. y = g_pParentWnd->GetCamera()->Camera().origin[2];
  2659. a = g_pParentWnd->GetCamera()->Camera().angles[PITCH] * idMath::M_DEG2RAD;
  2660. }
  2661. else {
  2662. x = g_pParentWnd->GetCamera()->Camera().origin[0];
  2663. y = g_pParentWnd->GetCamera()->Camera().origin[2];
  2664. a = g_pParentWnd->GetCamera()->Camera().angles[PITCH] * idMath::M_DEG2RAD;
  2665. }
  2666. float scale = 1.0/m_fScale; //jhefty - keep the camera icon proportionally the same size
  2667. qglColor3f(0.0, 0.0, 1.0);
  2668. qglBegin(GL_LINE_STRIP);
  2669. qglVertex3f(x - 16*scale, y, 0);
  2670. qglVertex3f(x, y + 8*scale, 0);
  2671. qglVertex3f(x + 16*scale, y, 0);
  2672. qglVertex3f(x, y - 8*scale, 0);
  2673. qglVertex3f(x - 16*scale, y, 0);
  2674. qglVertex3f(x + 16*scale, y, 0);
  2675. qglEnd();
  2676. qglBegin(GL_LINE_STRIP);
  2677. qglVertex3f(x + (48 * cos( a + idMath::PI * 0.25f )*scale), y + (48 * sin( a + idMath::PI * 0.25f )*scale), 0);
  2678. qglVertex3f(x, y, 0);
  2679. qglVertex3f(x + (48 * cos( a - idMath::PI * 0.25f )*scale), y + (48 * sin( a - idMath::PI * 0.25f )*scale), 0);
  2680. qglEnd();
  2681. #if 0
  2682. char text[128];
  2683. qglRasterPos2f(x + 64, y + 64);
  2684. sprintf(text, "%f", g_pParentWnd->GetCamera()->Camera().angles[YAW]);
  2685. qglCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
  2686. #endif
  2687. }
  2688. /*
  2689. =======================================================================================================================
  2690. =======================================================================================================================
  2691. */
  2692. void CXYWnd::DrawZIcon(void) {
  2693. if (m_nViewType == XY) {
  2694. float x = z.origin[0];
  2695. float y = z.origin[1];
  2696. qglEnable(GL_BLEND);
  2697. globalImages->BindNull();
  2698. qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  2699. qglDisable(GL_CULL_FACE);
  2700. qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  2701. qglColor4f(0.0, 0.0, 1.0, 0.25);
  2702. qglBegin(GL_QUADS);
  2703. qglVertex3f(x - 8, y - 8, 0);
  2704. qglVertex3f(x + 8, y - 8, 0);
  2705. qglVertex3f(x + 8, y + 8, 0);
  2706. qglVertex3f(x - 8, y + 8, 0);
  2707. qglEnd();
  2708. qglDisable(GL_BLEND);
  2709. qglColor4f(0.0, 0.0, 1.0, 1);
  2710. qglBegin(GL_LINE_LOOP);
  2711. qglVertex3f(x - 8, y - 8, 0);
  2712. qglVertex3f(x + 8, y - 8, 0);
  2713. qglVertex3f(x + 8, y + 8, 0);
  2714. qglVertex3f(x - 8, y + 8, 0);
  2715. qglEnd();
  2716. qglBegin(GL_LINE_STRIP);
  2717. qglVertex3f(x - 4, y + 4, 0);
  2718. qglVertex3f(x + 4, y + 4, 0);
  2719. qglVertex3f(x - 4, y - 4, 0);
  2720. qglVertex3f(x + 4, y - 4, 0);
  2721. qglEnd();
  2722. }
  2723. }
  2724. /*
  2725. =======================================================================================================================
  2726. FilterBrush
  2727. =======================================================================================================================
  2728. */
  2729. bool FilterBrush(brush_t *pb) {
  2730. if (!pb->owner) {
  2731. return false; // during construction
  2732. }
  2733. if (pb->hiddenBrush) {
  2734. return true;
  2735. }
  2736. if ( pb->forceVisibile ) {
  2737. return false;
  2738. }
  2739. if (g_pParentWnd->GetZWnd()->m_pZClip) // ZClip class up and running? (and hence Z window built)
  2740. {
  2741. if (g_pParentWnd->GetZWnd()->m_pZClip->IsEnabled())
  2742. {
  2743. // ZClipping active...
  2744. //
  2745. if (pb->mins[2] > g_pParentWnd->GetZWnd()->m_pZClip->GetTop() // brush bottom edge is above clip top
  2746. ||
  2747. pb->maxs[2] < g_pParentWnd->GetZWnd()->m_pZClip->GetBottom()// brush top edge is below clip bottom
  2748. )
  2749. {
  2750. return TRUE;
  2751. }
  2752. }
  2753. }
  2754. if (g_qeglobals.d_savedinfo.exclude & (EXCLUDE_CAULK | EXCLUDE_VISPORTALS)) {
  2755. //
  2756. // filter out the brush only if all faces are caulk if not don't hide the whole
  2757. // brush, proceed on a per-face basis (Cam_Draw) ++timo TODO: set this as a
  2758. // preference .. show caulk: hide any brush with caulk // don't draw caulk faces
  2759. //
  2760. face_t *f;
  2761. f = pb->brush_faces;
  2762. while (f) {
  2763. if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_CAULK) {
  2764. if (!strstr(f->texdef.name, "caulk")) {
  2765. break;
  2766. }
  2767. } else {
  2768. if (strstr(f->texdef.name, "visportal")) {
  2769. return true;
  2770. }
  2771. }
  2772. f = f->next;
  2773. }
  2774. if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_CAULK) {
  2775. if (!f) {
  2776. return true;
  2777. }
  2778. }
  2779. // ++timo FIXME: .. same deal here?
  2780. if (strstr(pb->brush_faces->texdef.name, "donotenter")) {
  2781. return true;
  2782. }
  2783. }
  2784. if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_HINT) {
  2785. if (strstr(pb->brush_faces->texdef.name, "hint")) {
  2786. return true;
  2787. }
  2788. }
  2789. if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_CLIP) {
  2790. if (strstr(pb->brush_faces->texdef.name, "clip")) {
  2791. return true;
  2792. }
  2793. }
  2794. if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_TRIGGERS) {
  2795. if (strstr(pb->brush_faces->texdef.name, "trig")) {
  2796. return true;
  2797. }
  2798. }
  2799. if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_NODRAW) {
  2800. if (strstr(pb->brush_faces->texdef.name, "nodraw")) {
  2801. return true;
  2802. }
  2803. }
  2804. if (strstr(pb->brush_faces->texdef.name, "skip")) {
  2805. return true;
  2806. }
  2807. if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_DYNAMICS) {
  2808. if (pb->modelHandle > 0) {
  2809. idRenderModel *model = pb->modelHandle;
  2810. if ( dynamic_cast<idRenderModelLiquid*>(model) ) {
  2811. return true;
  2812. }
  2813. }
  2814. }
  2815. if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_CURVES) {
  2816. if (pb->pPatch) {
  2817. return true;
  2818. }
  2819. }
  2820. if (pb->owner == world_entity) {
  2821. if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_WORLD) {
  2822. return true;
  2823. }
  2824. return false;
  2825. }
  2826. else {
  2827. if ( g_qeglobals.d_savedinfo.exclude & EXCLUDE_ENT ) {
  2828. return ( idStr::Cmpn( pb->owner->eclass->name, "func_static", 10 ) != 0 );
  2829. }
  2830. }
  2831. if ( g_qeglobals.d_savedinfo.exclude & EXCLUDE_LIGHTS && pb->owner->eclass->nShowFlags & ECLASS_LIGHT ) {
  2832. return true;
  2833. }
  2834. if ( g_qeglobals.d_savedinfo.exclude & EXCLUDE_COMBATNODES && pb->owner->eclass->nShowFlags & ECLASS_COMBATNODE ) {
  2835. return true;
  2836. }
  2837. if ( g_qeglobals.d_savedinfo.exclude & EXCLUDE_PATHS && pb->owner->eclass->nShowFlags & ECLASS_PATH) {
  2838. return true;
  2839. }
  2840. if ( g_qeglobals.d_savedinfo.exclude & EXCLUDE_MODELS && ( pb->owner->eclass->entityModel != NULL || pb->modelHandle > 0 ) ) {
  2841. return true;
  2842. }
  2843. return false;
  2844. }
  2845. /*
  2846. =======================================================================================================================
  2847. PATH LINES £
  2848. DrawPathLines Draws connections between entities. Needs to consider all entities, not just ones on screen, because
  2849. the lines can be visible when neither end is. Called for both camera view and xy view.
  2850. =======================================================================================================================
  2851. */
  2852. void DrawPathLines(void) {
  2853. int i, k;
  2854. idVec3 mid, mid1;
  2855. entity_t *se, *te;
  2856. brush_t *sb, *tb;
  2857. const char *psz;
  2858. idVec3 dir, s1, s2;
  2859. float len, f;
  2860. int arrows;
  2861. int num_entities;
  2862. const char *ent_target[MAX_MAP_ENTITIES];
  2863. entity_t *ent_entity[MAX_MAP_ENTITIES];
  2864. if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_PATHS) {
  2865. return;
  2866. }
  2867. num_entities = 0;
  2868. for (te = entities.next; te != &entities && num_entities != MAX_MAP_ENTITIES; te = te->next) {
  2869. for (int i = 0; i < 2048; i++) {
  2870. if (i == 0) {
  2871. ent_target[num_entities] = ValueForKey(te, "target");
  2872. } else {
  2873. ent_target[num_entities] = ValueForKey(te, va("target%i", i));
  2874. }
  2875. if (ent_target[num_entities][0]) {
  2876. ent_entity[num_entities] = te;
  2877. num_entities++;
  2878. } else if (i > 16) {
  2879. break;
  2880. }
  2881. }
  2882. }
  2883. for (se = entities.next; se != &entities; se = se->next) {
  2884. psz = ValueForKey(se, "name");
  2885. if (psz == NULL || psz[0] == '\0') {
  2886. continue;
  2887. }
  2888. sb = se->brushes.onext;
  2889. if (sb == &se->brushes) {
  2890. continue;
  2891. }
  2892. for (k = 0; k < num_entities; k++) {
  2893. if (strcmp(ent_target[k], psz)) {
  2894. continue;
  2895. }
  2896. te = ent_entity[k];
  2897. tb = te->brushes.onext;
  2898. if (tb == &te->brushes) {
  2899. continue;
  2900. }
  2901. mid = sb->owner->origin;
  2902. mid1 = tb->owner->origin;
  2903. VectorSubtract(mid1, mid, dir);
  2904. len = dir.Normalize();
  2905. s1[0] = -dir[1] * 8 + dir[0] * 8;
  2906. s2[0] = dir[1] * 8 + dir[0] * 8;
  2907. s1[1] = dir[0] * 8 + dir[1] * 8;
  2908. s2[1] = -dir[0] * 8 + dir[1] * 8;
  2909. qglColor3f(se->eclass->color[0], se->eclass->color[1], se->eclass->color[2]);
  2910. qglBegin(GL_LINES);
  2911. qglVertex3fv(mid.ToFloatPtr());
  2912. qglVertex3fv(mid1.ToFloatPtr());
  2913. arrows = (int)(len / 256) + 1;
  2914. for (i = 0; i < arrows; i++) {
  2915. f = len * (i + 0.5) / arrows;
  2916. mid1 = mid + (f * dir);
  2917. qglVertex3fv(mid1.ToFloatPtr());
  2918. qglVertex3f(mid1[0] + s1[0], mid1[1] + s1[1], mid1[2]);
  2919. qglVertex3fv(mid1.ToFloatPtr());
  2920. qglVertex3f(mid1[0] + s2[0], mid1[1] + s2[1], mid1[2]);
  2921. }
  2922. qglEnd();
  2923. }
  2924. }
  2925. return;
  2926. }
  2927. //
  2928. // =======================================================================================================================
  2929. // can be greatly simplified but per usual i am in a hurry which is not an excuse, just a fact
  2930. // =======================================================================================================================
  2931. //
  2932. void CXYWnd::PaintSizeInfo(int nDim1, int nDim2, idVec3 vMinBounds, idVec3 vMaxBounds) {
  2933. idVec3 vSize;
  2934. VectorSubtract(vMaxBounds, vMinBounds, vSize);
  2935. qglColor3f
  2936. (
  2937. g_qeglobals.d_savedinfo.colors[COLOR_SELBRUSHES][0] * .65,
  2938. g_qeglobals.d_savedinfo.colors[COLOR_SELBRUSHES][1] * .65,
  2939. g_qeglobals.d_savedinfo.colors[COLOR_SELBRUSHES][2] * .65
  2940. );
  2941. if (m_nViewType == XY) {
  2942. qglBegin(GL_LINES);
  2943. qglVertex3f(vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f);
  2944. qglVertex3f(vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
  2945. qglVertex3f(vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
  2946. qglVertex3f(vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
  2947. qglVertex3f(vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f);
  2948. qglVertex3f(vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f);
  2949. qglVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2], 0.0f);
  2950. qglVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f);
  2951. qglVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f);
  2952. qglVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f);
  2953. qglVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2], 0.0f);
  2954. qglVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f);
  2955. qglEnd();
  2956. qglRasterPos3f(Betwixt(vMinBounds[nDim1], vMaxBounds[nDim1]), vMinBounds[nDim2] - 20.0 / m_fScale, 0.0f);
  2957. g_strDim.Format(g_pDimStrings[nDim1], vSize[nDim1]);
  2958. qglCallLists(g_strDim.GetLength(), GL_UNSIGNED_BYTE, g_strDim);
  2959. qglRasterPos3f(vMaxBounds[nDim1] + 16.0 / m_fScale, Betwixt(vMinBounds[nDim2], vMaxBounds[nDim2]), 0.0f);
  2960. g_strDim.Format(g_pDimStrings[nDim2], vSize[nDim2]);
  2961. qglCallLists(g_strDim.GetLength(), GL_UNSIGNED_BYTE, g_strDim);
  2962. qglRasterPos3f(vMinBounds[nDim1] + 4, vMaxBounds[nDim2] + 8 / m_fScale, 0.0f);
  2963. g_strDim.Format(g_pOrgStrings[0], vMinBounds[nDim1], vMaxBounds[nDim2]);
  2964. qglCallLists(g_strDim.GetLength(), GL_UNSIGNED_BYTE, g_strDim);
  2965. }
  2966. else if (m_nViewType == XZ) {
  2967. qglBegin(GL_LINES);
  2968. qglVertex3f(vMinBounds[nDim1], 0, vMinBounds[nDim2] - 6.0f / m_fScale);
  2969. qglVertex3f(vMinBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale);
  2970. qglVertex3f(vMinBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale);
  2971. qglVertex3f(vMaxBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale);
  2972. qglVertex3f(vMaxBounds[nDim1], 0, vMinBounds[nDim2] - 6.0f / m_fScale);
  2973. qglVertex3f(vMaxBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale);
  2974. qglVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, 0, vMinBounds[nDim2]);
  2975. qglVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0, vMinBounds[nDim2]);
  2976. qglVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0, vMinBounds[nDim2]);
  2977. qglVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0, vMaxBounds[nDim2]);
  2978. qglVertex3f(vMaxBounds[nDim1] + 6.0f / m_fScale, 0, vMaxBounds[nDim2]);
  2979. qglVertex3f(vMaxBounds[nDim1] + 10.0f / m_fScale, 0, vMaxBounds[nDim2]);
  2980. qglEnd();
  2981. qglRasterPos3f(Betwixt(vMinBounds[nDim1], vMaxBounds[nDim1]), 0, vMinBounds[nDim2] - 20.0 / m_fScale);
  2982. g_strDim.Format(g_pDimStrings[nDim1], vSize[nDim1]);
  2983. qglCallLists(g_strDim.GetLength(), GL_UNSIGNED_BYTE, g_strDim);
  2984. qglRasterPos3f(vMaxBounds[nDim1] + 16.0 / m_fScale, 0, Betwixt(vMinBounds[nDim2], vMaxBounds[nDim2]));
  2985. g_strDim.Format(g_pDimStrings[nDim2], vSize[nDim2]);
  2986. qglCallLists(g_strDim.GetLength(), GL_UNSIGNED_BYTE, g_strDim);
  2987. qglRasterPos3f(vMinBounds[nDim1] + 4, 0, vMaxBounds[nDim2] + 8 / m_fScale);
  2988. g_strDim.Format(g_pOrgStrings[1], vMinBounds[nDim1], vMaxBounds[nDim2]);
  2989. qglCallLists(g_strDim.GetLength(), GL_UNSIGNED_BYTE, g_strDim);
  2990. }
  2991. else {
  2992. qglBegin(GL_LINES);
  2993. qglVertex3f(0, vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale);
  2994. qglVertex3f(0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
  2995. qglVertex3f(0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
  2996. qglVertex3f(0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
  2997. qglVertex3f(0, vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale);
  2998. qglVertex3f(0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale);
  2999. qglVertex3f(0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2]);
  3000. qglVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2]);
  3001. qglVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2]);
  3002. qglVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2]);
  3003. qglVertex3f(0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2]);
  3004. qglVertex3f(0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2]);
  3005. qglEnd();
  3006. qglRasterPos3f(0, Betwixt(vMinBounds[nDim1], vMaxBounds[nDim1]), vMinBounds[nDim2] - 20.0 / m_fScale);
  3007. g_strDim.Format(g_pDimStrings[nDim1], vSize[nDim1]);
  3008. qglCallLists(g_strDim.GetLength(), GL_UNSIGNED_BYTE, g_strDim);
  3009. qglRasterPos3f(0, vMaxBounds[nDim1] + 16.0 / m_fScale, Betwixt(vMinBounds[nDim2], vMaxBounds[nDim2]));
  3010. g_strDim.Format(g_pDimStrings[nDim2], vSize[nDim2]);
  3011. qglCallLists(g_strDim.GetLength(), GL_UNSIGNED_BYTE, g_strDim);
  3012. qglRasterPos3f(0, vMinBounds[nDim1] + 4.0, vMaxBounds[nDim2] + 8 / m_fScale);
  3013. g_strDim.Format(g_pOrgStrings[2], vMinBounds[nDim1], vMaxBounds[nDim2]);
  3014. qglCallLists(g_strDim.GetLength(), GL_UNSIGNED_BYTE, g_strDim);
  3015. }
  3016. }
  3017. /* XY_Draw */
  3018. long g_lCount = 0;
  3019. long g_lTotal = 0;
  3020. extern void DrawBrushEntityName(brush_t *b);
  3021. /*
  3022. =======================================================================================================================
  3023. =======================================================================================================================
  3024. */
  3025. void CXYWnd::XY_Draw() {
  3026. brush_t *brush;
  3027. float w, h;
  3028. entity_t *e;
  3029. idVec3 mins, maxs;
  3030. int drawn, culled;
  3031. int i;
  3032. if (!active_brushes.next) {
  3033. return; // not valid yet
  3034. }
  3035. // clear
  3036. m_bDirty = false;
  3037. GL_State( GLS_DEFAULT );
  3038. qglViewport(0, 0, m_nWidth, m_nHeight);
  3039. qglScissor(0, 0, m_nWidth, m_nHeight);
  3040. qglClearColor
  3041. (
  3042. g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][0],
  3043. g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][1],
  3044. g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][2],
  3045. 0
  3046. );
  3047. qglDisable(GL_DEPTH_TEST);
  3048. qglDisable(GL_CULL_FACE);
  3049. qglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  3050. // set up viewpoint
  3051. qglMatrixMode(GL_PROJECTION);
  3052. qglLoadIdentity();
  3053. w = m_nWidth / 2 / m_fScale;
  3054. h = m_nHeight / 2 / m_fScale;
  3055. int nDim1 = (m_nViewType == YZ) ? 1 : 0;
  3056. int nDim2 = (m_nViewType == XY) ? 1 : 2;
  3057. mins[0] = m_vOrigin[nDim1] - w;
  3058. maxs[0] = m_vOrigin[nDim1] + w;
  3059. mins[1] = m_vOrigin[nDim2] - h;
  3060. maxs[1] = m_vOrigin[nDim2] + h;
  3061. idBounds viewBounds( mins, maxs );
  3062. viewBounds[0].z = -99999;
  3063. viewBounds[1].z = 99999;
  3064. qglOrtho(mins[0], maxs[0], mins[1], maxs[1], MIN_WORLD_COORD, MAX_WORLD_COORD);
  3065. // draw stuff
  3066. globalImages->BindNull();
  3067. // now draw the grid
  3068. qglLineWidth(0.25);
  3069. XY_DrawGrid();
  3070. qglLineWidth(0.5);
  3071. drawn = culled = 0;
  3072. if (m_nViewType != XY) {
  3073. qglPushMatrix();
  3074. if (m_nViewType == YZ) {
  3075. qglRotatef(-90, 0, 1, 0); // put Z going up
  3076. }
  3077. // else
  3078. qglRotatef(-90, 1, 0, 0); // put Z going up
  3079. }
  3080. e = world_entity;
  3081. for ( brush = active_brushes.next; brush != &active_brushes; brush = brush->next ) {
  3082. if ( brush->forceVisibile || ( brush->owner->eclass->nShowFlags & ( ECLASS_LIGHT | ECLASS_PROJECTEDLIGHT ) ) ) {
  3083. } else if ( brush->mins[nDim1] > maxs[0] || brush->mins[nDim2] > maxs[1] || brush->maxs[nDim1] < mins[0] || brush->maxs[nDim2] < mins[1] ) {
  3084. culled++;
  3085. continue; // off screen
  3086. }
  3087. if ( FilterBrush(brush) ) {
  3088. continue;
  3089. }
  3090. drawn++;
  3091. if (brush->owner != e && brush->owner) {
  3092. qglColor3fv(brush->owner->eclass->color.ToFloatPtr());
  3093. }
  3094. else {
  3095. qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_BRUSHES].ToFloatPtr());
  3096. }
  3097. Brush_DrawXY( brush, m_nViewType );
  3098. }
  3099. DrawPathLines();
  3100. // draw pointfile
  3101. if (g_qeglobals.d_pointfile_display_list) {
  3102. qglCallList(g_qeglobals.d_pointfile_display_list);
  3103. }
  3104. if (!(m_nViewType == XY)) {
  3105. qglPopMatrix();
  3106. }
  3107. // draw block grid
  3108. if (g_qeglobals.show_blocks) {
  3109. XY_DrawBlockGrid();
  3110. }
  3111. // now draw selected brushes
  3112. if (m_nViewType != XY) {
  3113. qglPushMatrix();
  3114. if (m_nViewType == YZ) {
  3115. qglRotatef(-90, 0, 1, 0); // put Z going up
  3116. }
  3117. // else
  3118. qglRotatef(-90, 1, 0, 0); // put Z going up
  3119. }
  3120. qglPushMatrix();
  3121. qglTranslatef
  3122. (
  3123. g_qeglobals.d_select_translate[0],
  3124. g_qeglobals.d_select_translate[1],
  3125. g_qeglobals.d_select_translate[2]
  3126. );
  3127. if (RotateMode()) {
  3128. qglColor3f( 0.8f, 0.1f, 0.9f );
  3129. }
  3130. else if (ScaleMode()) {
  3131. qglColor3f( 0.1f, 0.8f, 0.1f );
  3132. }
  3133. else {
  3134. qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_SELBRUSHES].ToFloatPtr());
  3135. }
  3136. if (g_PrefsDlg.m_bNoStipple == FALSE) {
  3137. qglEnable(GL_LINE_STIPPLE);
  3138. qglLineStipple(3, 0xaaaa);
  3139. }
  3140. qglLineWidth(1);
  3141. idVec3 vMinBounds;
  3142. idVec3 vMaxBounds;
  3143. vMinBounds[0] = vMinBounds[1] = vMinBounds[2] = 999999.9f;
  3144. vMaxBounds[0] = vMaxBounds[1] = vMaxBounds[2] = -999999.9f;
  3145. int nSaveDrawn = drawn;
  3146. bool bFixedSize = false;
  3147. for (brush = selected_brushes.next; brush != &selected_brushes; brush = brush->next) {
  3148. drawn++;
  3149. Brush_DrawXY(brush, m_nViewType, true);
  3150. if (!bFixedSize) {
  3151. if (brush->owner->eclass->fixedsize) {
  3152. bFixedSize = true;
  3153. }
  3154. if (g_PrefsDlg.m_bSizePaint) {
  3155. for (i = 0; i < 3; i++) {
  3156. if (brush->mins[i] < vMinBounds[i]) {
  3157. vMinBounds[i] = brush->mins[i];
  3158. }
  3159. if (brush->maxs[i] > vMaxBounds[i]) {
  3160. vMaxBounds[i] = brush->maxs[i];
  3161. }
  3162. }
  3163. }
  3164. }
  3165. }
  3166. if (g_PrefsDlg.m_bNoStipple == FALSE) {
  3167. qglDisable(GL_LINE_STIPPLE);
  3168. }
  3169. qglLineWidth(0.5);
  3170. if (!bFixedSize && !RotateMode() && !ScaleMode() && drawn - nSaveDrawn > 0 && g_PrefsDlg.m_bSizePaint) {
  3171. PaintSizeInfo(nDim1, nDim2, vMinBounds, vMaxBounds);
  3172. }
  3173. // edge / vertex flags
  3174. if (g_qeglobals.d_select_mode == sel_vertex) {
  3175. qglPointSize(4);
  3176. qglColor3f(0, 1, 0);
  3177. qglBegin(GL_POINTS);
  3178. for (i = 0; i < g_qeglobals.d_numpoints; i++) {
  3179. qglVertex3fv(g_qeglobals.d_points[i].ToFloatPtr());
  3180. }
  3181. qglEnd();
  3182. qglPointSize(1);
  3183. }
  3184. else if (g_qeglobals.d_select_mode == sel_edge) {
  3185. float *v1, *v2;
  3186. qglPointSize(4);
  3187. qglColor3f(0, 0, 1);
  3188. qglBegin(GL_POINTS);
  3189. for (i = 0; i < g_qeglobals.d_numedges; i++) {
  3190. v1 = g_qeglobals.d_points[g_qeglobals.d_edges[i].p1].ToFloatPtr();
  3191. v2 = g_qeglobals.d_points[g_qeglobals.d_edges[i].p2].ToFloatPtr();
  3192. qglVertex3f((v1[0] + v2[0]) * 0.5, (v1[1] + v2[1]) * 0.5, (v1[2] + v2[2]) * 0.5);
  3193. }
  3194. qglEnd();
  3195. qglPointSize(1);
  3196. }
  3197. g_splineList->draw (static_cast<bool>(g_qeglobals.d_select_mode == sel_editpoint || g_qeglobals.d_select_mode == sel_addpoint));
  3198. if (g_pParentWnd->GetNurbMode() && g_pParentWnd->GetNurb()->GetNumValues()) {
  3199. int maxage = g_pParentWnd->GetNurb()->GetNumValues();
  3200. int time = 0;
  3201. qglColor3f(0, 0, 1);
  3202. qglPointSize(1);
  3203. qglBegin(GL_POINTS);
  3204. g_pParentWnd->GetNurb()->SetOrder(3);
  3205. for (i = 0; i < 100; i++) {
  3206. idVec2 v = g_pParentWnd->GetNurb()->GetCurrentValue(time);
  3207. qglVertex3f(v.x, v.y, 0.0f);
  3208. time += 10;
  3209. }
  3210. qglEnd();
  3211. qglPointSize(4);
  3212. qglColor3f(0, 0, 1);
  3213. qglBegin(GL_POINTS);
  3214. for (i = 0; i < maxage; i++) {
  3215. idVec2 v = g_pParentWnd->GetNurb()->GetValue(i);
  3216. qglVertex3f(v.x, v.y, 0.0f);
  3217. }
  3218. qglEnd();
  3219. qglPointSize(1);
  3220. }
  3221. qglPopMatrix();
  3222. qglTranslatef
  3223. (
  3224. -g_qeglobals.d_select_translate[0],
  3225. -g_qeglobals.d_select_translate[1],
  3226. -g_qeglobals.d_select_translate[2]
  3227. );
  3228. if (!(m_nViewType == XY)) {
  3229. qglPopMatrix();
  3230. }
  3231. // area selection hack
  3232. if (g_qeglobals.d_select_mode == sel_area) {
  3233. qglEnable(GL_BLEND);
  3234. qglPolygonMode ( GL_FRONT_AND_BACK , GL_FILL );
  3235. qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  3236. qglColor4f(0.0, 0.0, 1.0, 0.25);
  3237. qglRectf
  3238. (
  3239. g_qeglobals.d_vAreaTL[nDim1],
  3240. g_qeglobals.d_vAreaTL[nDim2],
  3241. g_qeglobals.d_vAreaBR[nDim1],
  3242. g_qeglobals.d_vAreaBR[nDim2]
  3243. );
  3244. qglDisable(GL_BLEND);
  3245. qglPolygonMode ( GL_FRONT_AND_BACK , GL_LINE );
  3246. qglColor3f(1.0f, 1.0f, 1.0f);
  3247. qglRectf
  3248. (
  3249. g_qeglobals.d_vAreaTL[nDim1],
  3250. g_qeglobals.d_vAreaTL[nDim2],
  3251. g_qeglobals.d_vAreaBR[nDim1],
  3252. g_qeglobals.d_vAreaBR[nDim2]
  3253. );
  3254. }
  3255. // now draw camera point
  3256. DrawCameraIcon();
  3257. DrawZIcon();
  3258. if (RotateMode()) {
  3259. DrawRotateIcon();
  3260. }
  3261. /// Draw a "precision crosshair" if enabled
  3262. if( m_precisionCrosshairMode != PRECISION_CROSSHAIR_NONE )
  3263. DrawPrecisionCrosshair();
  3264. qglFlush();
  3265. // QE_CheckOpenGLForErrors();
  3266. }
  3267. /*
  3268. =======================================================================================================================
  3269. =======================================================================================================================
  3270. */
  3271. idVec3 &CXYWnd::GetOrigin() {
  3272. return m_vOrigin;
  3273. }
  3274. /*
  3275. =======================================================================================================================
  3276. =======================================================================================================================
  3277. */
  3278. void CXYWnd::SetOrigin(idVec3 org) {
  3279. m_vOrigin[0] = org[0];
  3280. m_vOrigin[1] = org[1];
  3281. m_vOrigin[2] = org[2];
  3282. }
  3283. /*
  3284. =======================================================================================================================
  3285. =======================================================================================================================
  3286. */
  3287. void CXYWnd::OnSize(UINT nType, int cx, int cy) {
  3288. CWnd::OnSize(nType, cx, cy);
  3289. CRect rect;
  3290. GetClientRect(rect);
  3291. m_nWidth = rect.Width();
  3292. m_nHeight = rect.Height();
  3293. InvalidateRect(NULL, false);
  3294. }
  3295. brush_t hold_brushes;
  3296. /*
  3297. =======================================================================================================================
  3298. =======================================================================================================================
  3299. */
  3300. void CXYWnd::Clip() {
  3301. if (ClipMode()) {
  3302. hold_brushes.next = &hold_brushes;
  3303. ProduceSplitLists();
  3304. // brush_t* pList = (g_bSwitch) ? &g_brFrontSplits : &g_brBackSplits;
  3305. brush_t *pList;
  3306. if (g_PrefsDlg.m_bSwitchClip) {
  3307. pList = ((m_nViewType == XZ) ? g_bSwitch : !g_bSwitch) ? &g_brFrontSplits : &g_brBackSplits;
  3308. }
  3309. else {
  3310. pList = ((m_nViewType == XZ) ? !g_bSwitch : g_bSwitch) ? &g_brFrontSplits : &g_brBackSplits;
  3311. }
  3312. if (pList->next != pList) {
  3313. Brush_CopyList(pList, &hold_brushes);
  3314. CleanList(&g_brFrontSplits);
  3315. CleanList(&g_brBackSplits);
  3316. Select_Delete();
  3317. Brush_CopyList(&hold_brushes, &selected_brushes);
  3318. if (RogueClipMode()) {
  3319. RetainClipMode(false);
  3320. }
  3321. else {
  3322. RetainClipMode(true);
  3323. }
  3324. Sys_UpdateWindows(W_ALL);
  3325. }
  3326. }
  3327. else if (PathMode()) {
  3328. FinishSmartCreation();
  3329. if (g_pPathFunc) {
  3330. g_pPathFunc(true, g_nPathCount);
  3331. }
  3332. g_pPathFunc = NULL;
  3333. g_nPathCount = 0;
  3334. g_bPathMode = false;
  3335. }
  3336. }
  3337. /*
  3338. =======================================================================================================================
  3339. =======================================================================================================================
  3340. */
  3341. void CXYWnd::SplitClip() {
  3342. ProduceSplitLists();
  3343. if ((g_brFrontSplits.next != &g_brFrontSplits) && (g_brBackSplits.next != &g_brBackSplits)) {
  3344. Select_Delete();
  3345. Brush_CopyList(&g_brFrontSplits, &selected_brushes);
  3346. Brush_CopyList(&g_brBackSplits, &selected_brushes);
  3347. CleanList(&g_brFrontSplits);
  3348. CleanList(&g_brBackSplits);
  3349. if (RogueClipMode()) {
  3350. RetainClipMode(false);
  3351. }
  3352. else {
  3353. RetainClipMode(true);
  3354. }
  3355. }
  3356. }
  3357. /*
  3358. =======================================================================================================================
  3359. =======================================================================================================================
  3360. */
  3361. void CXYWnd::FlipClip() {
  3362. g_bSwitch = !g_bSwitch;
  3363. Sys_UpdateWindows(XY | W_CAMERA_IFON);
  3364. }
  3365. //
  3366. // =======================================================================================================================
  3367. // makes sure the selected brush or camera is in view
  3368. // =======================================================================================================================
  3369. //
  3370. void CXYWnd::PositionView() {
  3371. int nDim1 = (m_nViewType == YZ) ? 1 : 0;
  3372. int nDim2 = (m_nViewType == XY) ? 1 : 2;
  3373. brush_t *b = selected_brushes.next;
  3374. if (b && b->next != b) {
  3375. m_vOrigin[nDim1] = b->mins[nDim1];
  3376. m_vOrigin[nDim2] = b->mins[nDim2];
  3377. }
  3378. else {
  3379. m_vOrigin[nDim1] = g_pParentWnd->GetCamera()->Camera().origin[nDim1];
  3380. m_vOrigin[nDim2] = g_pParentWnd->GetCamera()->Camera().origin[nDim2];
  3381. }
  3382. }
  3383. /*
  3384. =======================================================================================================================
  3385. =======================================================================================================================
  3386. */
  3387. void CXYWnd::VectorCopyXY(const idVec3 &in, idVec3 &out) {
  3388. if (m_nViewType == XY) {
  3389. out[0] = in[0];
  3390. out[1] = in[1];
  3391. }
  3392. else if (m_nViewType == XZ) {
  3393. out[0] = in[0];
  3394. out[2] = in[2];
  3395. }
  3396. else {
  3397. out[1] = in[1];
  3398. out[2] = in[2];
  3399. }
  3400. }
  3401. /*
  3402. =======================================================================================================================
  3403. =======================================================================================================================
  3404. */
  3405. void CXYWnd::OnDestroy() {
  3406. CWnd::OnDestroy();
  3407. // delete this;
  3408. }
  3409. /*
  3410. =======================================================================================================================
  3411. =======================================================================================================================
  3412. */
  3413. void CXYWnd::SetViewType(int n) {
  3414. m_nViewType = n;
  3415. char *p = "YZ Side";
  3416. if (m_nViewType == XY) {
  3417. p = "XY Top";
  3418. } else if (m_nViewType == XZ) {
  3419. p = "XZ Front";
  3420. }
  3421. SetWindowText(p);
  3422. };
  3423. /*
  3424. =======================================================================================================================
  3425. =======================================================================================================================
  3426. */
  3427. void CXYWnd::Redraw(unsigned int nBits) {
  3428. m_nUpdateBits = nBits;
  3429. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  3430. m_nUpdateBits = W_XY;
  3431. }
  3432. /*
  3433. =======================================================================================================================
  3434. =======================================================================================================================
  3435. */
  3436. bool CXYWnd::RotateMode() {
  3437. return g_bRotateMode;
  3438. }
  3439. /*
  3440. =======================================================================================================================
  3441. =======================================================================================================================
  3442. */
  3443. bool CXYWnd::ScaleMode() {
  3444. return g_bScaleMode;
  3445. }
  3446. /*
  3447. =======================================================================================================================
  3448. =======================================================================================================================
  3449. */
  3450. extern bool Select_OnlyModelsSelected();
  3451. bool CXYWnd::SetRotateMode(bool bMode) {
  3452. if (bMode && selected_brushes.next != &selected_brushes) {
  3453. g_bRotateMode = true;
  3454. if (Select_OnlyModelsSelected()) {
  3455. Select_GetTrueMid(g_vRotateOrigin);
  3456. } else {
  3457. Select_GetMid(g_vRotateOrigin);
  3458. }
  3459. g_vRotation.Zero();
  3460. Select_InitializeRotation();
  3461. }
  3462. else {
  3463. if (bMode) {
  3464. Sys_Status("Need a brush selected to turn on Mouse Rotation mode\n");
  3465. }
  3466. g_bRotateMode = false;
  3467. Select_FinalizeRotation();
  3468. }
  3469. RedrawWindow();
  3470. return g_bRotateMode;
  3471. }
  3472. /*
  3473. =======================================================================================================================
  3474. =======================================================================================================================
  3475. */
  3476. void CXYWnd::SetScaleMode(bool bMode) {
  3477. g_bScaleMode = bMode;
  3478. RedrawWindow();
  3479. }
  3480. //
  3481. // =======================================================================================================================
  3482. // xy - z xz - y yz - x
  3483. // =======================================================================================================================
  3484. //
  3485. void CXYWnd::OnSelectMouserotate() {
  3486. // TODO: Add your command handler code here
  3487. }
  3488. /*
  3489. =======================================================================================================================
  3490. =======================================================================================================================
  3491. */
  3492. void CleanCopyEntities() {
  3493. entity_t *pe = g_enClipboard.next;
  3494. while (pe != NULL && pe != &g_enClipboard) {
  3495. entity_t *next = pe->next;
  3496. pe->epairs.Clear();
  3497. Entity_Free(pe);
  3498. pe = next;
  3499. }
  3500. g_enClipboard.next = g_enClipboard.prev = &g_enClipboard;
  3501. }
  3502. /*
  3503. =======================================================================================================================
  3504. =======================================================================================================================
  3505. */
  3506. entity_t *Entity_CopyClone(entity_t *e) {
  3507. entity_t *n;
  3508. n = Entity_New();
  3509. n->brushes.onext = n->brushes.oprev = &n->brushes;
  3510. n->eclass = e->eclass;
  3511. n->rotation = e->rotation;
  3512. // add the entity to the entity list
  3513. n->next = g_enClipboard.next;
  3514. g_enClipboard.next = n;
  3515. n->next->prev = n;
  3516. n->prev = &g_enClipboard;
  3517. n->epairs = e->epairs;
  3518. return n;
  3519. }
  3520. /*
  3521. =======================================================================================================================
  3522. =======================================================================================================================
  3523. */
  3524. bool OnList(entity_t *pFind, CPtrArray *pList) {
  3525. int nSize = pList->GetSize();
  3526. while (nSize-- > 0) {
  3527. entity_t *pEntity = reinterpret_cast < entity_t * > (pList->GetAt(nSize));
  3528. if (pEntity == pFind) {
  3529. return true;
  3530. }
  3531. }
  3532. return false;
  3533. }
  3534. /*
  3535. =======================================================================================================================
  3536. =======================================================================================================================
  3537. */
  3538. void CXYWnd::Copy()
  3539. {
  3540. #if 1
  3541. CWaitCursor WaitCursor;
  3542. g_Clipboard.SetLength(0);
  3543. g_PatchClipboard.SetLength(0);
  3544. Map_SaveSelected(&g_Clipboard, &g_PatchClipboard);
  3545. bool bClipped = false;
  3546. UINT nClipboard = ::RegisterClipboardFormat("RadiantClippings");
  3547. if (nClipboard > 0) {
  3548. if (OpenClipboard()) {
  3549. ::EmptyClipboard();
  3550. long lSize = g_Clipboard.GetLength();
  3551. HANDLE h = ::GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE | GMEM_DDESHARE, lSize + sizeof (long));
  3552. if (h != NULL) {
  3553. unsigned char *cp = reinterpret_cast < unsigned char * > (::GlobalLock(h));
  3554. memcpy(cp, &lSize, sizeof (long));
  3555. cp += sizeof (long);
  3556. g_Clipboard.SeekToBegin();
  3557. g_Clipboard.Read(cp, lSize);
  3558. ::GlobalUnlock(h);
  3559. ::SetClipboardData(nClipboard, h);
  3560. ::CloseClipboard();
  3561. bClipped = true;
  3562. }
  3563. }
  3564. }
  3565. if (!bClipped) {
  3566. common->Printf("Unable to register Windows clipboard formats, copy/paste between editors will not be possible");
  3567. }
  3568. /*
  3569. * CString strOut; ::GetTempPath(1024, strOut.GetBuffer(1024));
  3570. * strOut.ReleaseBuffer(); AddSlash(strOut); strOut += "RadiantClipboard.$$$";
  3571. * Map_SaveSelected(strOut.GetBuffer(0));
  3572. */
  3573. #else
  3574. CPtrArray holdArray;
  3575. CleanList(&g_brClipboard);
  3576. CleanCopyEntities();
  3577. for (brush_t * pBrush = selected_brushes.next; pBrush != NULL && pBrush != &selected_brushes; pBrush = pBrush->next) {
  3578. if (pBrush->owner == world_entity) {
  3579. brush_t *pClone = Brush_Clone(pBrush);
  3580. pClone->owner = NULL;
  3581. Brush_AddToList(pClone, &g_brClipboard);
  3582. }
  3583. else {
  3584. if (!OnList(pBrush->owner, &holdArray)) {
  3585. entity_t *e = pBrush->owner;
  3586. holdArray.Add(reinterpret_cast < void * > (e));
  3587. entity_t *pEClone = Entity_CopyClone(e);
  3588. for (brush_t * pEB = e->brushes.onext; pEB != &e->brushes; pEB = pEB->onext) {
  3589. brush_t *pClone = Brush_Clone(pEB);
  3590. // Brush_AddToList (pClone, &g_brClipboard);
  3591. Entity_LinkBrush(pEClone, pClone);
  3592. Brush_Build(pClone);
  3593. }
  3594. }
  3595. }
  3596. }
  3597. #endif
  3598. }
  3599. /*
  3600. =======================================================================================================================
  3601. =======================================================================================================================
  3602. */
  3603. void CXYWnd::Undo() {
  3604. /*
  3605. * if (g_brUndo.next != &g_brUndo) { g_bScreenUpdates = false; Select_Delete();
  3606. * for (brush_t* pBrush = g_brUndo.next ; pBrush != NULL && pBrush != &g_brUndo ;
  3607. * pBrush=pBrush->next) { brush_t* pClone = Brush_Clone(pBrush); Brush_AddToList
  3608. * (pClone, &active_brushes); Entity_LinkBrush (pBrush->pUndoOwner, pClone);
  3609. * Brush_Build(pClone); Select_Brush(pClone); } CleanList(&g_brUndo);
  3610. * g_bScreenUpdates = true; Sys_UpdateWindows(W_ALL); } else common->Printf("Nothing
  3611. * to undo.../n");
  3612. */
  3613. }
  3614. /*
  3615. =======================================================================================================================
  3616. =======================================================================================================================
  3617. */
  3618. void CXYWnd::UndoClear() {
  3619. /* CleanList(&g_brUndo); */
  3620. }
  3621. /*
  3622. =======================================================================================================================
  3623. =======================================================================================================================
  3624. */
  3625. void CXYWnd::UndoCopy() {
  3626. /*
  3627. * CleanList(&g_brUndo); for (brush_t* pBrush = selected_brushes.next ; pBrush !=
  3628. * NULL && pBrush != &selected_brushes ; pBrush=pBrush->next) { brush_t* pClone =
  3629. * Brush_Clone(pBrush); pClone->pUndoOwner = pBrush->owner; Brush_AddToList
  3630. * (pClone, &g_brUndo); }
  3631. */
  3632. }
  3633. /*
  3634. =======================================================================================================================
  3635. =======================================================================================================================
  3636. */
  3637. bool CXYWnd::UndoAvailable() {
  3638. return(g_brUndo.next != &g_brUndo);
  3639. }
  3640. /*
  3641. =======================================================================================================================
  3642. =======================================================================================================================
  3643. */
  3644. void CXYWnd::Paste()
  3645. {
  3646. #if 1
  3647. CWaitCursor WaitCursor;
  3648. bool bPasted = false;
  3649. UINT nClipboard = ::RegisterClipboardFormat("RadiantClippings");
  3650. if (nClipboard > 0 && OpenClipboard() && ::IsClipboardFormatAvailable(nClipboard)) {
  3651. HANDLE h = ::GetClipboardData(nClipboard);
  3652. if (h) {
  3653. g_Clipboard.SetLength(0);
  3654. unsigned char *cp = reinterpret_cast < unsigned char * > (::GlobalLock(h));
  3655. long lSize = 0;
  3656. memcpy(&lSize, cp, sizeof (long));
  3657. cp += sizeof (long);
  3658. g_Clipboard.Write(cp, lSize);
  3659. }
  3660. ::GlobalUnlock(h);
  3661. ::CloseClipboard();
  3662. }
  3663. if (g_Clipboard.GetLength() > 0) {
  3664. g_Clipboard.SeekToBegin();
  3665. int nLen = g_Clipboard.GetLength();
  3666. char *pBuffer = new char[nLen + 1];
  3667. memset(pBuffer, 0, sizeof(pBuffer));
  3668. g_Clipboard.Read(pBuffer, nLen);
  3669. pBuffer[nLen] = '\0';
  3670. Map_ImportBuffer(pBuffer, !(GetAsyncKeyState(VK_SHIFT) & 0x8000));
  3671. delete[] pBuffer;
  3672. }
  3673. #if 0
  3674. if (g_PatchClipboard.GetLength() > 0) {
  3675. g_PatchClipboard.SeekToBegin();
  3676. int nLen = g_PatchClipboard.GetLength();
  3677. char *pBuffer = new char[nLen + 1];
  3678. g_PatchClipboard.Read(pBuffer, nLen);
  3679. pBuffer[nLen] = '\0';
  3680. Patch_ReadBuffer(pBuffer, true);
  3681. delete[] pBuffer;
  3682. }
  3683. #endif
  3684. #else
  3685. if (g_brClipboard.next != &g_brClipboard || g_enClipboard.next != &g_enClipboard) {
  3686. Select_Deselect();
  3687. for (brush_t * pBrush = g_brClipboard.next; pBrush != NULL && pBrush != &g_brClipboard; pBrush = pBrush->next) {
  3688. brush_t *pClone = Brush_Clone(pBrush);
  3689. // pClone->owner = pBrush->owner;
  3690. if (pClone->owner == NULL) {
  3691. Entity_LinkBrush(world_entity, pClone);
  3692. }
  3693. Brush_AddToList(pClone, &selected_brushes);
  3694. Brush_Build(pClone);
  3695. }
  3696. for
  3697. (
  3698. entity_t * pEntity = g_enClipboard.next;
  3699. pEntity != NULL && pEntity != &g_enClipboard;
  3700. pEntity = pEntity->next
  3701. ) {
  3702. entity_t *pEClone = Entity_Clone(pEntity);
  3703. for (brush_t * pEB = pEntity->brushes.onext; pEB != &pEntity->brushes; pEB = pEB->onext) {
  3704. brush_t *pClone = Brush_Clone(pEB);
  3705. Brush_AddToList(pClone, &selected_brushes);
  3706. Entity_LinkBrush(pEClone, pClone);
  3707. Brush_Build(pClone);
  3708. if (pClone->owner && pClone->owner != world_entity) {
  3709. g_Inspectors->UpdateEntitySel(pClone->owner->eclass);
  3710. }
  3711. }
  3712. }
  3713. Sys_UpdateWindows(W_ALL);
  3714. }
  3715. else {
  3716. common->Printf("Nothing to paste.../n");
  3717. }
  3718. #endif
  3719. }
  3720. /*
  3721. =======================================================================================================================
  3722. =======================================================================================================================
  3723. */
  3724. idVec3 &CXYWnd::Rotation() {
  3725. return g_vRotation;
  3726. }
  3727. /*
  3728. =======================================================================================================================
  3729. =======================================================================================================================
  3730. */
  3731. idVec3 &CXYWnd::RotateOrigin() {
  3732. return g_vRotateOrigin;
  3733. }
  3734. /*
  3735. =======================================================================================================================
  3736. =======================================================================================================================
  3737. */
  3738. void CXYWnd::OnTimer(UINT nIDEvent) {
  3739. if (nIDEvent == 100) {
  3740. int nDim1 = (m_nViewType == YZ) ? 1 : 0;
  3741. int nDim2 = (m_nViewType == XY) ? 1 : 2;
  3742. m_vOrigin[nDim1] += m_ptDragAdj.x / m_fScale;
  3743. m_vOrigin[nDim2] -= m_ptDragAdj.y / m_fScale;
  3744. Sys_UpdateWindows(W_XY | W_CAMERA);
  3745. // int nH = (m_ptDrag.y == 0) ? -1 : m_ptDrag.y;
  3746. m_ptDrag += m_ptDragAdj;
  3747. m_ptDragTotal += m_ptDragAdj;
  3748. XY_MouseMoved(m_ptDrag.x, m_nHeight - 1 - m_ptDrag.y, m_nScrollFlags);
  3749. //
  3750. // m_vOrigin[nDim1] -= m_ptDrag.x / m_fScale; m_vOrigin[nDim1] -= m_ptDrag.x /
  3751. // m_fScale;
  3752. //
  3753. }
  3754. }
  3755. /*
  3756. =======================================================================================================================
  3757. =======================================================================================================================
  3758. */
  3759. void CXYWnd::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) {
  3760. g_pParentWnd->HandleKey(nChar, nRepCnt, nFlags, false);
  3761. // CWnd::OnKeyUp(nChar, nRepCnt, nFlags);
  3762. }
  3763. /*
  3764. =======================================================================================================================
  3765. =======================================================================================================================
  3766. */
  3767. void CXYWnd::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR *lpncsp) {
  3768. CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
  3769. }
  3770. /*
  3771. =======================================================================================================================
  3772. =======================================================================================================================
  3773. */
  3774. void CXYWnd::OnKillFocus(CWnd *pNewWnd) {
  3775. CWnd::OnKillFocus(pNewWnd);
  3776. SendMessage(WM_NCACTIVATE, FALSE, 0);
  3777. }
  3778. /*
  3779. =======================================================================================================================
  3780. =======================================================================================================================
  3781. */
  3782. void CXYWnd::OnSetFocus(CWnd *pOldWnd) {
  3783. CWnd::OnSetFocus(pOldWnd);
  3784. SendMessage(WM_NCACTIVATE, TRUE, 0);
  3785. }
  3786. /*
  3787. =======================================================================================================================
  3788. =======================================================================================================================
  3789. */
  3790. void CXYWnd::OnClose() {
  3791. CWnd::OnClose();
  3792. }
  3793. //
  3794. // =======================================================================================================================
  3795. // should be static as should be the rotate scale stuff
  3796. // =======================================================================================================================
  3797. //
  3798. bool CXYWnd::AreaSelectOK() {
  3799. return RotateMode() ? false : ScaleMode() ? false : true;
  3800. }
  3801. /*
  3802. =======================================================================================================================
  3803. =======================================================================================================================
  3804. */
  3805. BOOL CXYWnd::OnEraseBkgnd(CDC *pDC) {
  3806. return TRUE;
  3807. // return CWnd::OnEraseBkgnd(pDC);
  3808. }
  3809. extern void AssignModel();
  3810. void CXYWnd::OnDropNewmodel()
  3811. {
  3812. CPoint point;
  3813. GetCursorPos(&point);
  3814. CreateRightClickEntity(this, m_ptDown.x, m_ptDown.y, "func_static");
  3815. g_Inspectors->SetMode(W_ENTITY);
  3816. g_Inspectors->AssignModel();
  3817. }
  3818. BOOL CXYWnd::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
  3819. {
  3820. if (zDelta > 0) {
  3821. g_pParentWnd->OnViewZoomin();
  3822. } else {
  3823. g_pParentWnd->OnViewZoomout();
  3824. }
  3825. return TRUE;
  3826. }
  3827. //---------------------------------------------------------------------------
  3828. // CyclePrecisionCrosshairMode
  3829. //
  3830. // Called when the user presses the "cycle precision cursor mode" key.
  3831. // Cycles the precision cursor among the following three modes:
  3832. // PRECISION_CURSOR_NONE
  3833. // PRECISION_CURSOR_SNAP
  3834. // PRECISION_CURSOR_FREE
  3835. //---------------------------------------------------------------------------
  3836. void CXYWnd::CyclePrecisionCrosshairMode( void )
  3837. {
  3838. common->Printf("TODO: Make DrawPrecisionCrosshair work..." );
  3839. /// Cycle to next mode, wrap if necessary
  3840. m_precisionCrosshairMode ++;
  3841. if( m_precisionCrosshairMode >= PRECISION_CROSSHAIR_MAX )
  3842. m_precisionCrosshairMode = PRECISION_CROSSHAIR_NONE;
  3843. Sys_UpdateWindows( W_XY );
  3844. }
  3845. //---------------------------------------------------------------------------
  3846. // DrawPrecisionCrosshair
  3847. //
  3848. // Draws a precision crosshair beneath the cursor in the 2d (XY) view,
  3849. // depending on one of the following values for m_precisionCrosshairMode:
  3850. //
  3851. // PRECISION_CROSSHAIR_NONE No crosshair is drawn. Do not force refresh of XY view.
  3852. // PRECISION_CROSSHAIR_SNAP Crosshair snaps to grid size. Force refresh of XY view.
  3853. // PRECISION_CROSSHAIR_FREE Crosshair does not snap to grid. Force refresh of XY view.
  3854. //---------------------------------------------------------------------------
  3855. void CXYWnd::DrawPrecisionCrosshair( void )
  3856. {
  3857. // FIXME: m_mouseX, m_mouseY, m_axisHoriz, m_axisVert, etc... are never set
  3858. return;
  3859. idVec3 mouse3dPos (0.0f, 0.0f, 0.0f);
  3860. float x, y;
  3861. idVec4 crossEndColor (1.0f, 0.0f, 1.0f, 1.0f); // the RGBA color of the precision crosshair at its ends
  3862. idVec4 crossMidColor; // the RGBA color of the precision crosshair at the crossing point
  3863. /// Transform the mouse coordinates into axis-correct map-coordinates
  3864. if( m_precisionCrosshairMode == PRECISION_CROSSHAIR_SNAP )
  3865. SnapToPoint( m_mouseX, m_mouseY, mouse3dPos );
  3866. else
  3867. XY_ToPoint( m_mouseX, m_mouseY, mouse3dPos );
  3868. x = mouse3dPos[ m_axisHoriz ];
  3869. y = mouse3dPos[ m_axisVert ];
  3870. /// Use the color specified by the user
  3871. crossEndColor[0] = g_qeglobals.d_savedinfo.colors[ COLOR_PRECISION_CROSSHAIR ][0];
  3872. crossEndColor[1] = g_qeglobals.d_savedinfo.colors[ COLOR_PRECISION_CROSSHAIR ][1];
  3873. crossEndColor[2] = g_qeglobals.d_savedinfo.colors[ COLOR_PRECISION_CROSSHAIR ][2];
  3874. crossEndColor[3] = 1.0f;
  3875. crossMidColor = crossEndColor;
  3876. if( m_precisionCrosshairMode == PRECISION_CROSSHAIR_FREE )
  3877. crossMidColor[ 3 ] = 0.0f; // intersection-color is 100% transparent (alpha = 0.0f)
  3878. /// Set up OpenGL states (for drawing smooth-shaded plain-colored lines)
  3879. qglEnable( GL_BLEND );
  3880. qglDisable( GL_TEXTURE_2D );
  3881. qglShadeModel( GL_SMOOTH );
  3882. qglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
  3883. /// Draw a fullscreen-sized crosshair over the cursor
  3884. qglBegin( GL_LINES );
  3885. {
  3886. /// Draw the horizontal precision line (in two pieces)
  3887. qglColor4fv( crossEndColor.ToFloatPtr() );
  3888. qglVertex2f( m_mcLeft, y );
  3889. qglColor4fv( crossMidColor.ToFloatPtr() );
  3890. qglVertex2f( x, y );
  3891. qglColor4fv( crossMidColor.ToFloatPtr() );
  3892. qglVertex2f( x, y );
  3893. qglColor4fv( crossEndColor.ToFloatPtr() );
  3894. qglVertex2f( m_mcRight, y );
  3895. /// Draw the vertical precision line (in two pieces)
  3896. qglColor4fv( crossEndColor.ToFloatPtr() );
  3897. qglVertex2f( x, m_mcTop );
  3898. qglColor4fv( crossMidColor.ToFloatPtr() );
  3899. qglVertex2f( x, y );
  3900. qglColor4fv( crossMidColor.ToFloatPtr() );
  3901. qglVertex2f( x, y );
  3902. qglColor4fv( crossEndColor.ToFloatPtr() );
  3903. qglVertex2f( x, m_mcBottom );
  3904. }
  3905. qglEnd(); // GL_LINES
  3906. // Radiant was in opaque, flat-shaded mode by default; restore this to prevent possible slowdown
  3907. qglShadeModel( GL_FLAT );
  3908. qglDisable( GL_BLEND );
  3909. }