ide/Debugger: Rubber Ducking Support
authorJerome St-Louis <jerome@ecere.com>
Fri, 25 Apr 2014 10:21:42 +0000 (06:21 -0400)
committerJerome St-Louis <jerome@ecere.com>
Fri, 25 Apr 2014 10:32:09 +0000 (06:32 -0400)
ecere/src/gui/Window.ec
ide/src/documents/ModelView.ec
ide/src/ide.ec

index a0bb221..f9172a1 100644 (file)
@@ -4296,7 +4296,8 @@ private:
          }
          SelectMouseCursor();
 
-         if(window && !guiApp.windowMoving && !wasMoving && !wasScrolling)
+         if(window && ((!guiApp.windowMoving && !wasMoving) ||
+            (wasMoving && guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp)) && !wasScrolling)
          {
             int clientX = x - (window.absPosition.x + window.clientStart.x);
             int clientY = y - (window.absPosition.y + window.clientStart.y);
index d2259a2..495b8c8 100644 (file)
@@ -7,7 +7,7 @@ import "ecere"
 class ModelView : Window
 {
    isActiveClient = true;
-   background = blue;
+   background = lightBlue;
    anchor = { left = 0, top = 0, right = 0, bottom = 0 };
 
    FillModeValue fillMode;
@@ -53,6 +53,7 @@ class ModelView : Window
       {
          strcpy(fileName, value);
       }
+      get { return fileName; }
    }
 
    void OnUnloadGraphics()
@@ -85,11 +86,30 @@ class ModelView : Window
    {
       if(!moving && !lightMoving)
       {
-         startPosition.x = x;
-         startPosition.y = y;
-         startOrientation = camera.eulerOrientation;
-         Capture();
-         moving = true;
+         bool clicked = false;
+         OldList list {};
+
+         display.StartSelection(x,y, 0,0);
+         display.SetCamera(null, camera);
+         display.CollectHits();
+         display.DrawObject(model);
+         if(display.GetHits(list))
+         {
+            clicked = true;
+            list.Free(null);
+         }
+         display.SetCamera(null, null);
+         display.StopSelection();
+
+         if(clicked)
+         {
+            startPosition.x = x;
+            startPosition.y = y;
+            startOrientation = camera.eulerOrientation;
+            Capture();
+            moving = true;
+            return false;
+         }
       }
       return true;
    }
@@ -203,6 +223,8 @@ class ModelView : Window
          camera.zMax = 10000;
          camera.position = { 0, 0, -r * 2 };
          camera.eulerOrientation = Euler { 30, 0, 0 };
+         light.orientation = Euler { pitch = 50, yaw = 45 };
+
          if(r * 2 < camera.zMax / 10)
          {
             while(r * 2 < camera.zMax / 100)
@@ -229,14 +251,13 @@ class ModelView : Window
       //display.fogColor = blue;
       display.fogDensity = 0; //0.000001f;
 
-      surface.SetBackground(lightBlue);
-      surface.Clear(colorAndDepth);
-
+      surface.Clear(depthBuffer);
       camera.Update();
 
+      display.SetLight(0, light);
       display.SetCamera(surface, camera);
 
-      display.SetLight(0, light);
+      //display.SetLight(0, light);
 
       display.fillMode = fillMode;
       display.DrawObject(model);
index bb5ae24..68a310f 100644 (file)
@@ -1092,6 +1092,59 @@ class IDEWorkSpace : Window
             return true;
          }
       }
+      MenuDivider { debugMenu };
+      ModelView duck
+      {
+         this,
+         // nonClient = true,
+         autoCreate = false,
+         alphaBlend = true,
+         opacity = 0,
+         isRemote = true,
+         borderStyle = 0,
+         moveable = true,
+         anchor = { right = 0, top = 0 },
+         inactive = true,
+         isActiveClient = false,
+         stayOnTop = true,
+         clickThrough = true,
+         size = { 500, 500 };
+
+         bool OnLoadGraphics()
+         {
+            ModelView::OnLoadGraphics();
+            camera.position.z /= 1.3;
+            camera.orientation = Euler { yaw = 290, pitch = 20 };
+            camera.Update();
+            Update(null);
+            return true;
+         }
+
+         bool OnRightButtonDown(int x, int y, Modifiers mods)
+         {
+            MenuWindowMove(null, 0);
+            return false;
+         }
+
+         bool OnRightButtonUp(int x, int y, Modifiers mods)
+         {
+            position = position;
+            state = normal;
+            return true;
+         }
+      };
+      MenuItem debugRubberDuck
+      {
+         debugMenu, $"Rubber Duck", checkable = true, disabled = true;
+         bool NotifySelect(MenuItem selection, Modifiers mods)
+         {
+            if(selection.checked)
+               duck.Create();
+            else
+               duck.Destroy(0);
+            return true;
+         }
+      }
 #ifndef __WIN32__
       MenuDivider { debugMenu };
       MenuItem debugUseValgrindItem
@@ -1606,6 +1659,9 @@ class IDEWorkSpace : Window
       delete ideSettings.displayDriver;
       ideSettings.displayDriver = CopyString(selection.id ? "OpenGL" : "Default");
 
+      if(ide.duck.modelFile && !strcmpi(app.driver, "OpenGL"))
+         ide.debugRubberDuck.disabled = false;
+
       settingsContainer.Save();
       //SetDriverAndSkin();
       return true;
@@ -3472,146 +3528,126 @@ define sdkDirName = "Ecere SDK";
 define sdkDirName = "ecere";
 #endif
 
-void FindAndShellOpenInstalledFolder(char * name)
+bool GetInstalledFileOrFolder(char * subDir, char * name, char * path, FileAttribs attribs)
 {
-   char * p = new char[MAX_LOCATION];
+   bool found = false;
    char * v = new char[maxPathLen];
-   byte * tokens[256];
-   int c, numTokens;
-   Array<String> paths { };
-   p[0] = v[0] = '\0';
-   strncpy(p, settingsContainer.moduleLocation, MAX_LOCATION); p[MAX_LOCATION-1] = '\0';
-   StripLastDirectory(p, p);
-   PathCat(p, name);
-   paths.Add(CopyString(p));
-#if defined(__WIN32__)
-   GetEnvironment("ECERE_SDK_SRC", v, maxPathLen);
-   if(v[0])
+   v[0] = '\0';
+   if(found)
    {
-      strncpy(p, v, MAX_LOCATION); p[MAX_LOCATION-1] = '\0';
-      PathCat(p, name); paths.Add(CopyString(p));
+      strncpy(path, settingsContainer.moduleLocation, MAX_LOCATION); path[MAX_LOCATION-1] = '\0';
+      StripLastDirectory(path, path);
+      PathCat(path, subDir);
+      if(name) PathCat(path, name);
+      if(FileExists(path) & attribs) found = true;
    }
-   GetEnvironment("AppData", v, maxPathLen);
-   if(v[0])
+#if defined(__WIN32__)
+   if(!found)
    {
-      strncpy(p, v, MAX_LOCATION); p[MAX_LOCATION-1] = '\0';
-      PathCat(p, sdkDirName); PathCat(p, name); paths.Add(CopyString(p));
+      GetEnvironment("ECERE_SDK_SRC", v, maxPathLen);
+      if(v[0])
+      {
+         strncpy(path, v, MAX_LOCATION); path[MAX_LOCATION-1] = '\0';
+         PathCat(path, subDir);
+         if(name) PathCat(path, name);
+         if(FileExists(path) & attribs) found = true;
+      }
    }
-   GetEnvironment("ProgramData", v, maxPathLen);
-   if(v[0])
+   if(!found)
    {
-      strncpy(p, v, MAX_LOCATION); p[MAX_LOCATION-1] = '\0';
-      PathCat(p, sdkDirName); PathCat(p, name); paths.Add(CopyString(p));
+      GetEnvironment("AppData", v, maxPathLen);
+      if(v[0])
+      {
+         strncpy(path, v, MAX_LOCATION); path[MAX_LOCATION-1] = '\0';
+         PathCat(path, sdkDirName);
+         PathCat(path, subDir);
+         if(name) PathCat(path, name);
+         if(FileExists(path) & attribs) found = true;
+      }
    }
-   GetEnvironment("ProgramFiles", v, maxPathLen);
-   if(v[0])
+   if(!found)
    {
-      strncpy(p, v, MAX_LOCATION); p[MAX_LOCATION-1] = '\0';
-      PathCat(p, sdkDirName); PathCat(p, name); paths.Add(CopyString(p));
+      GetEnvironment("ProgramData", v, maxPathLen);
+      if(v[0])
+      {
+         strncpy(path, v, MAX_LOCATION); path[MAX_LOCATION-1] = '\0';
+         PathCat(path, sdkDirName);
+         PathCat(path, subDir);
+         if(name) PathCat(path, name);
+         if(FileExists(path) & attribs) found = true;
+      }
    }
-   GetEnvironment("ProgramFiles(x86)", v, maxPathLen);
-   if(v[0])
+   if(!found)
    {
-      strncpy(p, v, MAX_LOCATION); p[MAX_LOCATION-1] = '\0';
-      PathCat(p, sdkDirName); PathCat(p, name); paths.Add(CopyString(p));
+      GetEnvironment("ProgramFiles", v, maxPathLen);
+      if(v[0])
+      {
+         strncpy(path, v, MAX_LOCATION); path[MAX_LOCATION-1] = '\0';
+         PathCat(path, sdkDirName);
+         PathCat(path, subDir);
+         if(name) PathCat(path, name);
+         if(FileExists(path) & attribs) found = true;
+      }
    }
-   GetEnvironment("SystemDrive", v, maxPathLen);
-   if(v[0])
+   if(!found)
    {
-      strncpy(p, v, MAX_LOCATION); p[MAX_LOCATION-1] = '\0';
-      PathCat(p, "Program Files"); PathCat(p, sdkDirName); PathCat(p, name); paths.Add(CopyString(p));
+      GetEnvironment("ProgramFiles(x86)", v, maxPathLen);
+      if(v[0])
+      {
+         strncpy(path, v, MAX_LOCATION); path[MAX_LOCATION-1] = '\0';
+         PathCat(path, sdkDirName);
+         PathCat(path, subDir);
+         if(name) PathCat(path, name);
+         if(FileExists(path) & attribs) found = true;
+      }
    }
-#else
-   GetEnvironment("XDG_DATA_DIRS", v, maxPathLen);
-   numTokens = TokenizeWith(v, sizeof(tokens) / sizeof(byte *), tokens, ":", false);
-   for(c=0; c<numTokens; c++)
+   if(!found)
    {
-      strncpy(p, tokens[c], MAX_LOCATION); p[MAX_LOCATION-1] = '\0';
-      PathCat(p, sdkDirName); PathCat(p, name); paths.Add(CopyString(p));
+      GetEnvironment("SystemDrive", v, maxPathLen);
+      if(v[0])
+      {
+         strncpy(path, v, MAX_LOCATION); path[MAX_LOCATION-1] = '\0';
+         PathCat(path, "Program Files");
+         PathCat(path, sdkDirName);
+         PathCat(path, subDir);
+         if(name) PathCat(path, name);
+         if(FileExists(path) & attribs) found = true;
+      }
    }
-#endif
-   for(path : paths)
+#else
+   if(!found)
    {
-      strncpy(p, path, MAX_LOCATION); p[MAX_LOCATION-1] = '\0';
-      if(FileExists(p).isDirectory)
+      byte * tokens[256];
+      int c, numTokens;
+
+      GetEnvironment("XDG_DATA_DIRS", v, maxPathLen);
+      numTokens = TokenizeWith(v, sizeof(tokens) / sizeof(byte *), tokens, ":", false);
+      for(c=0; c<numTokens; c++)
       {
-         ShellOpen(p);
-         break;
+         strncpy(path, tokens[c], MAX_LOCATION); path[MAX_LOCATION-1] = '\0';
+         PathCat(path, sdkDirName);
+         PathCat(path, subDir);
+         if(name) PathCat(path, name);
+         if(FileExists(path) & attribs) found = true;
       }
    }
-   delete p;
+#endif
    delete v;
-   paths.Free();
-   delete paths;
+   return found;
+}
+
+void FindAndShellOpenInstalledFolder(char * name)
+{
+   char path[MAX_LOCATION];
+   if(GetInstalledFileOrFolder(name, null, path, { isDirectory = true }))
+      ShellOpen(path);
 }
 
 void FindAndShellOpenInstalledFile(char * subdir, char * name)
 {
-   char * p = new char[MAX_LOCATION];
-   char * v = new char[maxPathLen];
-   byte * tokens[256];
-   int c, numTokens;
-   Array<String> paths { };
-   p[0] = v[0] = '\0';
-   strncpy(p, settingsContainer.moduleLocation, MAX_LOCATION); p[MAX_LOCATION-1] = '\0';
-   paths.Add(CopyString(p));
-   StripLastDirectory(p, p);
-   PathCat(p, subdir);
-   paths.Add(CopyString(p));
-#if defined(__WIN32__)
-   GetEnvironment("ECERE_SDK_SRC", v, maxPathLen);
-   if(v[0])
-   {
-      strncpy(p, v, MAX_LOCATION); p[MAX_LOCATION-1] = '\0';
-      PathCat(p, sdkDirName); PathCat(p, subdir); paths.Add(CopyString(p));
-   }
-   GetEnvironment("AppData", v, maxPathLen);
-   if(v[0])
-   {
-      strncpy(p, v, MAX_LOCATION); p[MAX_LOCATION-1] = '\0';
-      PathCat(p, sdkDirName); PathCat(p, subdir); paths.Add(CopyString(p));
-   }
-   GetEnvironment("ProgramFiles", v, maxPathLen);
-   if(v[0])
-   {
-      strncpy(p, v, MAX_LOCATION); p[MAX_LOCATION-1] = '\0';
-      PathCat(p, sdkDirName); PathCat(p, subdir); paths.Add(CopyString(p));
-   }
-   GetEnvironment("ProgramFiles(x86)", v, maxPathLen);
-   if(v[0])
-   {
-      strncpy(p, v, MAX_LOCATION); p[MAX_LOCATION-1] = '\0';
-      PathCat(p, sdkDirName); PathCat(p, subdir); paths.Add(CopyString(p));
-   }
-   GetEnvironment("SystemDrive", v, maxPathLen);
-   if(v[0])
-   {
-      strncpy(p, v, MAX_LOCATION); p[MAX_LOCATION-1] = '\0';
-      PathCat(p, "Program Files"); PathCat(p, sdkDirName); PathCat(p, subdir); paths.Add(CopyString(p));
-   }
-#else
-   GetEnvironment("XDG_DATA_DIRS", v, maxPathLen);
-   numTokens = TokenizeWith(v, sizeof(tokens) / sizeof(byte *), tokens, ":", false);
-   for(c=0; c<numTokens; c++)
-   {
-      strncpy(p, tokens[c], MAX_LOCATION); p[MAX_LOCATION-1] = '\0';
-      PathCat(p, sdkDirName); PathCat(p, subdir); paths.Add(CopyString(p));
-   }
-#endif
-   for(path : paths)
-   {
-      strncpy(p, path, MAX_LOCATION); p[MAX_LOCATION-1] = '\0';
-      PathCat(p, name);
-      if(FileExists(p).isFile)
-      {
-         ShellOpen(p);
-         break;
-      }
-   }
-   delete p;
-   delete v;
-   paths.Free();
-   delete paths;
+   char path[MAX_LOCATION];
+   if(GetInstalledFileOrFolder(subdir, name, path, { isFile = true }))
+      ShellOpen(path);
 }
 
 class RecursiveDeleteFolderFSI : NormalFileSystemIterator
@@ -3696,6 +3732,17 @@ class IDEApp : GuiApplication
          ide.driverItems[ideSettings.displayDriver && !strcmp(ideSettings.displayDriver,"OpenGL")].checked = true;
       }
 
+      {
+         char model[MAX_LOCATION];
+         if(GetInstalledFileOrFolder("samples", "3D/ModelViewer/models/duck/duck.3DS", model, { isFile = true }))
+         {
+            ide.duck.modelFile = model;
+            ide.duck.parent = ideMainFrame;
+         }
+      }
+      if(ide.duck.modelFile && !strcmpi(app.driver, "OpenGL"))
+         ide.debugRubberDuck.disabled = false;
+
       SetInIDE(true);
 
       desktop.caption = titleECEREIDE;