]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - contrib/bobtoolz/funchandlers-GTK.cpp
* applied patch by StefanV (from mailinglist) that fixes an error in config.py (broke...
[xonotic/netradiant.git] / contrib / bobtoolz / funchandlers-GTK.cpp
index deb3ff829d5668e8eefe6907dba5f1d7ce6e9966..6f7ad44314998ffcd9ab1ed4a18106b7323e9e24 100644 (file)
@@ -19,46 +19,22 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 #include "StdAfx.h"
 
-#ifdef WIN32
+#ifdef _WIN32
 #pragma warning(disable : 4786)
 #endif
 
 #include "dialogs/dialogs-gtk.h"
 
-#include "gtkr_list.h"
-#include "str.h"
-
-#include "DPoint.h"
-#include "DPlane.h"
-#include "DBrush.h"
-#include "DEPair.h"
-#include "DPatch.h"
 #include "DEntity.h"
 #include "DShape.h"
-#include "DBobView.h"
-#include "DVisDrawer.h"
-#include "DTrainDrawer.h"
+#include "DPatch.h"
 
 #include "misc.h"
-#include "scriptparser.h"
-#include "DTreePlanter.h"
-
 #include "shapes.h"
 #include "lists.h"
 #include "funchandlers.h"
 #include "visfind.h"
 
-#include "iundo.h"
-
-#include "refcounted_ptr.h"
-
-#include <vector>
-#include <list>
-#include <map>
-#include <algorithm>
-
-#include "scenelib.h"
-
 // for autocaulk
 list<Str> exclusionList;               // whole brush exclusion
 list<Str> exclusionList_Face;  // single face exclusion
@@ -97,14 +73,14 @@ void DoIntersect()
 {
        IntersectRS rs;
 
-       if(DoIntersectBox(&rs) == eIDCANCEL)
+       if(DoIntersectBox(&rs) == IDCANCEL)
                return;
 
        if(rs.nBrushOptions == BRUSH_OPT_SELECTED)
        {
-               if( GlobalSelectionSystem().countSelected() < 2 )
+               if( g_FuncTable.m_pfnSelectedBrushCount() < 2 )
                {
-                       DoMessageBox("Invalid number of brushes selected, choose at least 2", "Error", eMB_OK);
+                       DoMessageBox("Invalid number of brushes selected, choose at least 2", "Error", MB_OK);
                        return; 
                }
        }
@@ -140,34 +116,38 @@ void DoIntersect()
 
 void DoPolygonsTB()
 {
-  DoPolygons();
+  vec3_t vMin, vMax;
+
+  // figure out vMin and vMax
+  g_FuncTable.m_pfnGetDispatchParams( vMin, vMax, NULL );
+
+  DoPolygons( vMin, vMax );
 }
 
-void DoPolygons()
+void DoPolygons(vec3_t vMin, vec3_t vMax)
 {
        // ensure we have something selected
-       if( GlobalSelectionSystem().countSelected() != 1 )
+       if( g_FuncTable.m_pfnSelectedBrushCount() != 1 )
        {
-               DoMessageBox("Invalid number of brushes selected, choose 1 only", "Error", eMB_OK);
+               DoMessageBox("Invalid number of brushes selected, choose 1 only", "Error", MB_OK);
                return; 
        }
 
+       // tell Radiant we want to access the selected brushes
+       g_FuncTable.m_pfnAllocateSelectedBrushHandles();
+                       
+       // get handle to size definition brush
+       brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle(0);
+       // cant release until we delete the brush, if we do...
+
        PolygonRS rs;
 
        // ask user for type, size, etc....
-       if(DoPolygonBox(&rs) == eIDOK)
+       if(DoPolygonBox(&rs) == IDOK)
        {
-               DShape poly;
+               g_FuncTable.m_pfnDeleteBrushHandle(brush);
 
-    vec3_t vMin, vMax;
-
-    {
-      scene::Instance& instance = GlobalSelectionSystem().ultimateSelected();
-      VectorSubtract(instance.aabb_world().origin, instance.aabb_world().extents, vMin);
-      VectorAdd(instance.aabb_world().origin, instance.aabb_world().extents, vMax);
-
-      instance.path().parent()->m_traverse->erase(instance.path().top());
-    }
+               DShape poly;
 
                if(rs.bInverse)
                        poly.BuildInversePrism(vMin, vMax, rs.nSides, rs.bAlignTop);
@@ -182,6 +162,9 @@ void DoPolygons()
 
                poly.Commit();
        }
+
+
+       g_FuncTable.m_pfnReleaseSelectedBrushHandles();
 }
 
 void DoFixBrushes()
@@ -189,7 +172,7 @@ void DoFixBrushes()
        DMap world;
        world.LoadAll();
 
-       int count = world.FixBrushes();
+       int count = world.FixBrushes(TRUE);
        
        Sys_Printf("%i invalid/duplicate planes removed\n", count);
 }
@@ -199,7 +182,7 @@ void DoResetTextures()
        static ResetTextureRS rs;
 
   const char* texName;
-       if(1/*g_SelectedFaceTable.m_pfnGetSelectedFaceCount() != 1*/)
+       if(g_SelectedFaceTable.m_pfnGetSelectedFaceCount() != 1)
   {
     texName = NULL;
   }
@@ -209,14 +192,14 @@ void DoResetTextures()
          strcpy(rs.textureName, GetCurrentTexture());
   }
 
-  EMessageBoxReturn ret;
-       if((ret = DoResetTextureBox(&rs)) == eIDCANCEL)
+  int ret;
+       if((ret = DoResetTextureBox(&rs)) == IDCANCEL)
                return;  
 
   if(rs.bResetTextureName)
     texName = rs.textureName;
 
-  if(ret == eIDOK)
+  if(ret == IDOK)
   {
          DEntity world;
          world.LoadSelectedBrushes();
@@ -232,30 +215,30 @@ void DoResetTextures()
   }
 }
 
-void DoBuildStairs()
+void DoBuildStairs(vec3_t vMin, vec3_t vMax)
 {
        BuildStairsRS rs;
 
        strcpy(rs.mainTexture, GetCurrentTexture());
 
        // ensure we have something selected
-       if( GlobalSelectionSystem().countSelected() != 1 )
+       if( g_FuncTable.m_pfnSelectedBrushCount() != 1 )
        {
-               DoMessageBox("Invalid number of brushes selected, choose 1 only", "Error", eMB_OK);
+               DoMessageBox("Invalid number of brushes selected, chose 1 only", "Error", MB_OK);
                return; 
        }
 
-       // ask user for type, size, etc....
-       if(DoBuildStairsBox(&rs) == eIDOK)
-       {
-    vec3_t vMin, vMax;
+       // tell Radiant we want to access the selected brushes
+       g_FuncTable.m_pfnAllocateSelectedBrushHandles();
+                       
+       // get handle to size definition brush
+       brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle(0);
+       // cant release until we delete the brush, if we do...
 
-    {
-      scene::Instance& instance = GlobalSelectionSystem().ultimateSelected();
-      VectorSubtract(instance.aabb_world().origin, instance.aabb_world().extents, vMin);
-      VectorAdd(instance.aabb_world().origin, instance.aabb_world().extents, vMax);
-    }
 
+       // ask user for type, size, etc....
+       if(DoBuildStairsBox(&rs) == IDOK)
+       {
                // calc brush size
                vec3_t size;
                VectorSubtract(vMax, vMin, size);
@@ -263,14 +246,14 @@ void DoBuildStairs()
                if(((int)size[2] % rs.stairHeight) != 0)
                {
                        // stairs must fit evenly into brush
-                       DoMessageBox("Invalid stair height\nHeight of block must be divisable by stair height", "Error", eMB_OK);
+                       DoMessageBox("Invalid stair height\nHeight of block must be divisable by stair height", "Error", MB_OK);
                }
                else
                {
-      {
-        scene::Instance& instance = GlobalSelectionSystem().ultimateSelected();
-        instance.path().parent()->m_traverse->erase(instance.path().top());
-      }
+                       
+                       // Remove Size Brush
+                       g_FuncTable.m_pfnDeleteBrushHandle(brush);
+
                                                
                        // Get Step Count
                        int numSteps = (int)size[2] / rs.stairHeight;
@@ -318,30 +301,32 @@ void DoBuildStairs()
                        }
                }
        }
+
+       g_FuncTable.m_pfnReleaseSelectedBrushHandles();
 }
 
-void DoBuildDoors()
+void DoBuildDoors(vec3_t vMin, vec3_t vMax)
 {
        // ensure we have something selected
-       if( GlobalSelectionSystem().countSelected() != 1 )
+       if( g_FuncTable.m_pfnSelectedBrushCount() != 1 )
        {
-               DoMessageBox("Invalid number of brushes selected, choose 1 only", "Error", eMB_OK);
+               DoMessageBox("Invalid number of brushes selected, chose 1 only", "Error", MB_OK);
                return; 
        }
 
-  DoorRS rs;
+       // tell Radiant we want to access the selected brushes
+       g_FuncTable.m_pfnAllocateSelectedBrushHandles();
+                       
+       // get handle to size definition brush
+       brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle(0);
+       // cant release until we delete the brush, if we do...
+
+       DoorRS rs;
        strcpy(rs.mainTexture, GetCurrentTexture());
 
-       if(DoDoorsBox(&rs) == eIDOK)
+       if(DoDoorsBox(&rs) == IDOK)
        {
-    vec3_t vMin, vMax;
-
-    {
-      scene::Instance& instance = GlobalSelectionSystem().ultimateSelected();
-      VectorSubtract(instance.aabb_world().origin, instance.aabb_world().extents, vMin);
-      VectorAdd(instance.aabb_world().origin, instance.aabb_world().extents, vMax);
-      instance.path().parent()->m_traverse->erase(instance.path().top());
-    }
+               g_FuncTable.m_pfnDeleteBrushHandle(brush);
 
                BuildDoorsX2(vMin, vMax, 
                        rs.bScaleMainH, rs.bScaleMainV,
@@ -349,32 +334,37 @@ void DoBuildDoors()
                        rs.mainTexture, rs.trimTexture,
                        rs.nOrientation);       // shapes.cpp
        }
+
+       g_FuncTable.m_pfnReleaseSelectedBrushHandles();
 }
 
 void DoPathPlotter()
 {
        PathPlotterRS rs;
-       EMessageBoxReturn ret = DoPathPlotterBox(&rs);
-       if(ret == eIDCANCEL)
+       int ret = DoPathPlotterBox(&rs);
+       if(ret == IDCANCEL)
                return;
-       if(ret == eIDNO)
+       if(ret == IDNO)
        {
                if(g_PathView)
                        delete g_PathView;
                return;
        }
 
-       // ensure we have something selected
-       if( GlobalSelectionSystem().countSelected() != 1 )
+       if( g_FuncTable.m_pfnSelectedBrushCount() != 1)
        {
-               DoMessageBox("Invalid number of brushes selected, choose 1 only", "Error", eMB_OK);
-               return; 
+               DoMessageBox("Invalid number of brushes selected, chose 1 only", "Error", MB_OK);
+               return;
        }
 
-  scene::Instance& instance = GlobalSelectionSystem().ultimateSelected();
+       // tell Radiant we want to access the selected brushes
+       g_FuncTable.m_pfnAllocateSelectedBrushHandles();
+                       
+       brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle(0);
+       // should be our trigger brush
 
        DEntity world;
-       world.LoadEPairList(instance.path().top()->m_entity);
+       world.LoadEPairList(*g_EntityTable.m_pfnGetEntityKeyValList(brush->owner));
 
        DEPair* trigger_ep = world.FindEPairByKey("targetname");
 
@@ -385,7 +375,7 @@ void DoPathPlotter()
                        DEPair* target_ep = world.FindEPairByKey("target");
                        if(target_ep)
                        {
-        scene::Path* entTarget = FindEntityFromTargetname(target_ep->value, NULL);
+                               entity_s* entTarget = FindEntityFromTargetname(target_ep->value, NULL);
                                if(entTarget)
                                {
                                        if(g_PathView)
@@ -395,32 +385,35 @@ void DoPathPlotter()
                                        g_PathView->Begin(trigger_ep->value, target_ep->value, rs.fMultiplier, rs.nPoints, rs.fGravity, rs.bNoUpdate, rs.bShowExtra);
                                }
                                else
-                                       DoMessageBox("trigger_push target could not be found.", "Error", eMB_OK);
+                                       DoMessageBox("trigger_push target could not be found.", "Error", MB_OK);
                        }
                        else
-                               DoMessageBox("trigger_push has no target.", "Error", eMB_OK);
+                               DoMessageBox("trigger_push has no target.", "Error", MB_OK);
                }
                else
-                       DoMessageBox("You must select a 'trigger_push' entity.", "Error", eMB_OK);
+                       DoMessageBox("You must select a 'trigger_push' entity.", "Error", MB_OK);
        }       
        else
-               DoMessageBox("Entity must have a targetname", "Error", eMB_OK);
+               DoMessageBox("Entity must have a targetname", "Error", MB_OK);
+
+       g_FuncTable.m_pfnReleaseSelectedBrushHandles();
 }
 
-void DoPitBuilder()
+void DoPitBuilder(vec3_t vMin, vec3_t vMax)
 {
        // ensure we have something selected
-       if( GlobalSelectionSystem().countSelected() != 1 )
+       if( g_FuncTable.m_pfnSelectedBrushCount() != 1 )
        {
-               DoMessageBox("Invalid number of brushes selected, choose 1 only", "Error", eMB_OK);
+               DoMessageBox("Invalid number of brushes selected, chose 1 only", "Error", MB_OK);
                return; 
        }
 
-  vec3_t vMin, vMax;
-
-  scene::Instance& instance = GlobalSelectionSystem().ultimateSelected();
-  VectorSubtract(instance.aabb_world().origin, instance.aabb_world().extents, vMin);
-  VectorAdd(instance.aabb_world().origin, instance.aabb_world().extents, vMax);
+       // tell Radiant we want to access the selected brushes
+       g_FuncTable.m_pfnAllocateSelectedBrushHandles();
+                       
+       // get handle to size definition brush
+       brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle(0);
+       // cant release until we delete the brush, if we do...
 
        DShape pit;
 
@@ -428,10 +421,12 @@ void DoPitBuilder()
        {
                pit.Commit();
 
-    instance.path().parent()->m_traverse->erase(instance.path().top());
+               g_FuncTable.m_pfnDeleteBrushHandle(brush);
        }
        else
-               DoMessageBox("Failed To Make Pit\nTry Making The Brush Bigger", "Error", eMB_OK);
+               DoMessageBox("Failed To Make Pit\nTry Making The Brush Bigger", "Error", MB_OK);
+
+       g_FuncTable.m_pfnReleaseSelectedBrushHandles();
 }
 
 void DoMergePatches()
@@ -440,26 +435,28 @@ void DoMergePatches()
   DPatch mrgPatches[2];
   int i;
 
-       // ensure we have something selected
-       if( GlobalSelectionSystem().countSelected() != 2 )
-       {
-               DoMessageBox("Invalid number of patches selected, choose 2 only", "Error", eMB_OK);
-               return; 
-       }
+  // ensure we have something selected
+  if ( g_FuncTable.m_pfnSelectedBrushCount() != 2 )
+  {
+    DoMessageBox("Invalid number of objects selected, chose 2 only", "Error", MB_OK);
+    return; 
+  }
+
 
-  scene::Node* patches[2];
-  patches[0] = GlobalSelectionSystem().ultimateSelected().path().top();
-  patches[1] = GlobalSelectionSystem().penultimateSelected().path().top();
+  g_FuncTable.m_pfnAllocateSelectedBrushHandles();
 
   for (i = 0; i < 2; i++)
   {
-    if (!patches[i]->m_patch)
+    brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle(i);
+
+    if (!brush->pPatch)
     {
-      DoMessageBox("You must select ONLY patches", "Error", eMB_OK);
+      g_FuncTable.m_pfnReleaseSelectedBrushHandles();
+      DoMessageBox("You must select ONLY patches", "Error", MB_OK);
       return; 
     }
 
-    mrgPatches[0].LoadFromBrush(patches[i]);
+    mrgPatches[i].LoadFromBrush_t(brush);
   }
 
   /*  mrgPatches[0].Transpose();
@@ -495,26 +492,30 @@ void DoMergePatches()
       delete newPatch;
     }
   }
+
+  g_FuncTable.m_pfnReleaseSelectedBrushHandles();
 }
 
 void DoSplitPatch() {
        DPatch patch;
 
        // ensure we have something selected
-       if( GlobalSelectionSystem().countSelected() != 1 )
-       {
-               DoMessageBox("Invalid number of patches selected, choose 1 only", "Error", eMB_OK);
+       if( g_FuncTable.m_pfnSelectedBrushCount() != 1 ) {
+               DoMessageBox("Invalid number of objects selected, select 1 patch only", "Error", MB_OK);
                return; 
        }
 
-  scene::Node* node = GlobalSelectionSystem().ultimateSelected().path().top();
+       g_FuncTable.m_pfnAllocateSelectedBrushHandles();
 
-       if( !node->m_patch ) {
-               DoMessageBox("You must select ONLY patches", "Error", eMB_OK);
+       brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle(0);
+
+       if( !brush->pPatch ) {
+               g_FuncTable.m_pfnReleaseSelectedBrushHandles();
+               DoMessageBox("You must select ONLY patches", "Error", MB_OK);
                return; 
        }
 
-       patch.LoadFromBrush(node);
+       patch.LoadFromBrush_t(brush);
 
        list<DPatch> patchList = patch.Split( true, true );
        for(list<DPatch>::iterator patches = patchList.begin(); patches != patchList.end(); patches++) {
@@ -522,13 +523,15 @@ void DoSplitPatch() {
        }
 
        patch.RemoveFromRadiant();
+
+       g_FuncTable.m_pfnReleaseSelectedBrushHandles();
 }
 
 void DoVisAnalyse()
 {
        char filename[1024];
 
-       if( GlobalSelectionSystem().countSelected() == 0 )
+       if( g_FuncTable.m_pfnSelectedBrushCount() == 0 )
        {
                if(g_VisView) 
                {
@@ -537,17 +540,20 @@ void DoVisAnalyse()
                }
        }
 
-       // ensure we have something selected
-       if( GlobalSelectionSystem().countSelected() != 1 )
+       if( g_FuncTable.m_pfnSelectedBrushCount() != 1 )
        {
-               DoMessageBox("Invalid number of objects selected, choose 1 only", "Error", eMB_OK);
+               DoMessageBox("Invalid number of objects selected, select 1 only", "Error", MB_OK);
                return; 
        }
 
-  scene::Node* brush = GlobalSelectionSystem().ultimateSelected().path().top();
+       g_FuncTable.m_pfnAllocateSelectedBrushHandles();
+
+       brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle(0);
 
        DBrush orgBrush;
-       orgBrush.LoadFromBrush(brush, false);
+       orgBrush.LoadFromBrush_t(brush, false);
+
+       g_FuncTable.m_pfnReleaseSelectedBrushHandles();
 
        orgBrush.BuildBounds();
        vec3_t origin;
@@ -556,10 +562,10 @@ void DoVisAnalyse()
        origin[2] = (orgBrush.bbox_max[2] + orgBrush.bbox_min[2])/2.f;
 
 
-  const char* rad_filename = g_FuncTable.m_pfnGetMapName();
+  char* rad_filename = g_FuncTable.m_pfnGetMapName();
        if(!rad_filename)
        {
-               DoMessageBox("An Error Occurred While Trying\n To Get The Map Filename", "Error", eMB_OK);
+               DoMessageBox("An Error Occurred While Trying\n To Get The Map Filename", "Error", MB_OK);
                return;
        }
 
@@ -588,7 +594,7 @@ void DoTrainPathPlot() {
        g_TrainView = new DTrainDrawer();
 }
 
-void DoCaulkSelection() {
+void DoCaulkSelection( void ) {
        DEntity world;
        
        float fScale[2] = { 0.5f, 0.5f };
@@ -602,7 +608,7 @@ void DoCaulkSelection() {
        world.ResetTextures( NULL, fScale, fShift, 0, "textures/common/caulk", true, bResetScale, bResetShift, false, true );
 }
 
-void DoTreePlanter() {
+void DoTreePlanter( void ) {
        if(g_TreePlanter) {
                delete g_TreePlanter;
                g_TreePlanter = NULL;
@@ -612,13 +618,13 @@ void DoTreePlanter() {
        g_TreePlanter = new DTreePlanter();
 }
 
-void DoDropEnts() {
+void DoDropEnts( void ) {
        if(g_TreePlanter) {
                g_TreePlanter->DropEntsToGround();
        }
 }
 
-void DoMakeChain() {
+void DoMakeChain( void ) {
        DTreePlanter pl;
        pl.MakeChain();
 }
@@ -627,28 +633,31 @@ typedef DPoint* pntTripple[3];
 
 bool bFacesNoTop[6] = {true, true, true, true, true, false};
 
-void DoFlipTerrain() {
+void DoFlipTerrain( void ) {
        vec3_t vUp = { 0.f, 0.f, 1.f };
   int i;
 
        // ensure we have something selected
-       if( GlobalSelectionSystem().countSelected() != 2 )
-       {
-               DoMessageBox("Invalid number of objects selected, choose 2 only", "Error", eMB_OK);
-               return; 
+       if( g_FuncTable.m_pfnSelectedBrushCount() != 2 ) {
+               DoMessageBox("Invalid number of objects selected, chose 2 only", "Error", MB_OK);
+               return;
        }
 
-  scene::Node* brushes[2];
-       brushes[0] = GlobalSelectionSystem().ultimateSelected().path().top();
-       brushes[1] = GlobalSelectionSystem().penultimateSelected().path().top();
+       g_FuncTable.m_pfnAllocateSelectedBrushHandles();
+
+       brush_t* brushes[2];
+       for( i = 0; i < 2; i++ ) {
+               brushes[i] = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle(i);
+       }
 
        DBrush Brushes[2];
        DPlane* Planes[2];
        pntTripple Points[2];
        for( i = 0; i < 2; i++ ) {
-               Brushes[i].LoadFromBrush( brushes[i], false );
+               Brushes[i].LoadFromBrush_t( brushes[i], false );
                if(!(Planes[i] = Brushes[i].FindPlaneWithClosestNormal( vUp )) || Brushes[i].FindPointsForPlane( Planes[i], Points[i], 3 ) != 3) {
-                       DoMessageBox("Error", "Error", eMB_OK);
+                       g_FuncTable.m_pfnReleaseSelectedBrushHandles();
+                       DoMessageBox("Error", "Error", MB_OK);
                        return;
                }
        }
@@ -657,14 +666,15 @@ void DoFlipTerrain() {
        Brushes[0].GetBounds( mins1, maxs1 );
        Brushes[1].GetBounds( mins2, maxs2 );
 
-  scene::Node* ents[2];
-       ents[0] = GlobalSelectionSystem().ultimateSelected().path().parent();
-       ents[1] = GlobalSelectionSystem().penultimateSelected().path().parent();
-
+       entity_t* ents[2];
        for( i = 0; i < 2; i++ ) {
+               ents[i] = brushes[i]->owner;
                Brushes[i].RemoveFromRadiant();
        }
 
+       g_FuncTable.m_pfnReleaseSelectedBrushHandles();
+
+
 
 
        int dontmatch[2] = { -1, -1 };
@@ -683,7 +693,7 @@ void DoFlipTerrain() {
                found = false;
        }
        if(dontmatch[0] == -1) {
-               DoMessageBox("Error", "Error", eMB_OK);
+               DoMessageBox("Error", "Error", MB_OK);
                return;
        }
 
@@ -701,7 +711,7 @@ void DoFlipTerrain() {
                found = false;
        }
        if(dontmatch[1] == -1) {
-               DoMessageBox("Error", "Error", eMB_OK);
+               DoMessageBox("Error", "Error", MB_OK);
                return;
        }