X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=blobdiff_plain;f=contrib%2Fbobtoolz%2FDTreePlanter.cpp;h=958bcf8b17fc61fa99356d971e2d827f5916af84;hp=237c9ccf75101da8eeeb4ad57d4049a19ae2d79d;hb=68159d9ed443f990fecf207847408a673eb641f7;hpb=12b372f89ce109a4db9d510884fbe7d05af79870 diff --git a/contrib/bobtoolz/DTreePlanter.cpp b/contrib/bobtoolz/DTreePlanter.cpp index 237c9ccf..958bcf8b 100644 --- a/contrib/bobtoolz/DTreePlanter.cpp +++ b/contrib/bobtoolz/DTreePlanter.cpp @@ -17,9 +17,9 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "StdAfx.h" +#include "DTreePlanter.h" -#include "gtkr_list.h" +#include #include "str.h" #include "DPoint.h" @@ -31,18 +31,19 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "ScriptParser.h" #include "misc.h" +#include "scenelib.h" -#include "DTreePlanter.h" #include "funchandlers.h" -bool DTreePlanter::OnMouseMove(guint32 nFlags, gdouble x, gdouble y) { - return false; -} - -bool DTreePlanter::OnLButtonDown(guint32 nFlags, gdouble x, gdouble y) { - VIEWTYPE vt = m_XYWrapper->GetViewType(); +SignalHandlerResult DTreePlanter::mouseDown(const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers) +{ + if(button != c_buttonLeft) + { + return SIGNAL_CONTINUE_EMISSION; + } + VIEWTYPE vt = GlobalRadiant().XYWindow_getViewType(); switch(vt) { case XY: @@ -50,14 +51,14 @@ bool DTreePlanter::OnLButtonDown(guint32 nFlags, gdouble x, gdouble y) { case YZ: case XZ: default: - return false; + return SIGNAL_CONTINUE_EMISSION; } - vec3_t pt, vhit; + Vector3 pt, vhit; - m_XYWrapper->SnapToGrid( static_cast(x), static_cast(y), pt ); + pt = vector3_snapped(GlobalRadiant().XYWindow_windowToWorld(position), GlobalRadiant().getGridSize()); - if(FindDropPoint(pt, vhit)) { + if(FindDropPoint(vector3_to_array(pt), vector3_to_array(vhit))) { vhit[2] += m_offset; char buffer[128]; @@ -67,18 +68,17 @@ bool DTreePlanter::OnLButtonDown(guint32 nFlags, gdouble x, gdouble y) { e.AddEPair("origin", buffer); if(m_autoLink) { -#if 0 - entity_t* pLastEntity = NULL; - entity_t* pThisEntity = NULL; - int entNum = -1, lastEntNum = -1, entpos; + const scene::Path* pLastEntity = NULL; + const scene::Path* pThisEntity = NULL; + + int entpos; for(int i = 0; i < 256; i++) { sprintf(buffer, m_linkName, i); - pThisEntity = FindEntityFromTargetname( buffer, &entNum ); + pThisEntity = FindEntityFromTargetname( buffer ); if(pThisEntity) { entpos = i; - lastEntNum = entNum; pLastEntity = pThisEntity; } } @@ -93,12 +93,12 @@ bool DTreePlanter::OnLButtonDown(guint32 nFlags, gdouble x, gdouble y) { if(pLastEntity) { DEntity e2; - e2.LoadFromEntity(lastEntNum, TRUE); + e2.LoadFromEntity(pLastEntity->top(), true); e2.AddEPair("target", buffer); e2.RemoveFromRadiant(); - e2.BuildInRadiant(FALSE); + e2.BuildInRadiant(false); } -#endif + } if(m_setAngles) { @@ -121,34 +121,14 @@ bool DTreePlanter::OnLButtonDown(guint32 nFlags, gdouble x, gdouble y) { e.AddEPair("modelscale", buffer); } - e.BuildInRadiant( FALSE ); + e.BuildInRadiant( false ); } if(m_autoLink) { DoTrainPathPlot(); } - return true; -} - -bool DTreePlanter::OnLButtonUp(guint32 nFlags, gdouble x, gdouble y) { - return false; -} - -bool DTreePlanter::OnRButtonDown(guint32 nFlags, gdouble x, gdouble y) { - return false; -} - -bool DTreePlanter::OnRButtonUp(guint32 nFlags, gdouble x, gdouble y) { - return false; -} - -bool DTreePlanter::OnMButtonDown(guint32 nFlags, gdouble x, gdouble y) { - return false; -} - -bool DTreePlanter::OnMButtonUp(guint32 nFlags, gdouble x, gdouble y) { - return false; + return SIGNAL_STOP_EMISSION; } bool DTreePlanter::FindDropPoint(vec3_t in, vec3_t out) { @@ -199,38 +179,42 @@ bool DTreePlanter::FindDropPoint(vec3_t in, vec3_t out) { return found; } -void DTreePlanter::DropEntsToGround( void ) { -#if 0 - // tell Radiant we want to access the selected brushes - g_FuncTable.m_pfnAllocateSelectedBrushHandles(); - - DEntity ent; - - int cnt = g_FuncTable.m_pfnSelectedBrushCount(); - for(int i = 0; i < cnt; i++) { - brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle(i); - - ent.LoadFromEntity(brush->owner, TRUE); +class TreePlanterDropEntityIfSelected +{ + mutable DEntity ent; + DTreePlanter& planter; +public: + TreePlanterDropEntityIfSelected(DTreePlanter& planter) : planter(planter) + { + } + void operator()(scene::Instance& instance) const + { + if(!instance.isSelected()) + { + return; + } + ent.LoadFromEntity(instance.path().top()); DEPair* pEpair = ent.FindEPairByKey("origin"); if(!pEpair) { - continue; + return; } vec3_t vec, out; sscanf( pEpair->value.GetBuffer(), "%f %f %f", &vec[0], &vec[1], &vec[2]); - FindDropPoint( vec, out ); + planter.FindDropPoint( vec, out ); char buffer[256]; sprintf( buffer, "%f %f %f", out[0], out[1], out[2] ); ent.AddEPair( "origin", buffer ); ent.RemoveFromRadiant(); - ent.BuildInRadiant(FALSE); - } + ent.BuildInRadiant(false); + } +}; - g_FuncTable.m_pfnReleaseSelectedBrushHandles(); -#endif +void DTreePlanter::DropEntsToGround( void ) { + Scene_forEachEntity(TreePlanterDropEntityIfSelected(*this)); } void DTreePlanter::MakeChain( void ) { @@ -254,7 +238,7 @@ void DTreePlanter::MakeChain( void ) { e.AddEPair( "control", buffer ); } - e.BuildInRadiant( FALSE ); + e.BuildInRadiant( false ); } for(i = 0; i < m_linkNum-1; i++) { @@ -266,7 +250,7 @@ void DTreePlanter::MakeChain( void ) { sprintf( buffer, "0 %i 0", (i * 64) + 32); e.AddEPair( "origin", buffer ); - e.BuildInRadiant( FALSE ); + e.BuildInRadiant( false ); } } @@ -290,7 +274,7 @@ void DTreePlanter::SelectChain( void ) { e.AddEPair( "control", buffer ); } - e.BuildInRadiant( FALSE ); + e.BuildInRadiant( false ); } for(int i = 0; i < m_linkNum-1; i++) { @@ -302,6 +286,6 @@ void DTreePlanter::SelectChain( void ) { sprintf( buffer, "0 %i 0", (i * 64) + 32); e.AddEPair( "origin", buffer ); - e.BuildInRadiant( FALSE ); + e.BuildInRadiant( false ); }*/ }