private void OnNodeClick(TreeViewEx sender, MouseClickArgs args)
 {
   switch((NodeLevel)args.Node.Level)
   {
     case NodeLevel.PROJECT:
     {
       if(args.Button == MouseButtons.Right)
       {
         LightContextMenu contextMenu = new LightContextMenu();
         ItemClickHandler addSceneHandler = delegate()
         {
           CheckValueCorrectnessDelegate checker = Solution.Instance.CreateSceneNameChecker();
           string sceneName = NameGenerator.GenerateName("Scene", checker);
           Scene.Scene scene = m_Scenes.CreateScene(sceneName);
           this.SelectedScene = scene;
         };
         contextMenu.AddItem("Add scene", addSceneHandler);
         contextMenu.Show(this, args.Location);
       }
       
       break;
     }
     
     case NodeLevel.SCENE:
     {
       Scene.Scene scene = (Scene.Scene)args.Node.Tag;
       this.SelectedScene = scene;
       if(args.Button == MouseButtons.Right)
       {
         LightContextMenu contextMenu = new LightContextMenu();
         if(Settings.SceneTranslator != null)
         {
           ItemClickHandler codeToClipboardHandler = delegate()
           {
             try
             {
               string code = Settings.SceneTranslator.Translate(m_Scenes, scene);
               System.Windows.Forms.Clipboard.SetText(code);
             }
             catch(Exception e)
             {
               MessageBox.Show("Translation error: " + e.Message, "Translation error",
                 MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
           };
           contextMenu.AddItem("Copy code to clipboard", codeToClipboardHandler);
         }
         
         ItemClickHandler cloneSceneHandler = delegate()
         {
           CheckValueCorrectnessDelegate checker = Solution.Instance.CreateSceneNameChecker();
           string cloneName = NameGenerator.GenerateName(scene.Name, checker);
           Scene.Scene clone = m_Scenes.CloneScene(scene, cloneName);
           this.SelectedScene = clone;
         };
         ItemClickHandler removeSceneHandler = delegate()
         {
           m_Scenes.RemoveScene(scene);
           this.SelectedScene = null;
         };
         contextMenu.AddItem("Clone scene", cloneSceneHandler);
         contextMenu.AddItem("Remove scene", removeSceneHandler);
         contextMenu.Show(this, args.Location);
       }
       
       break;
     }
     
     case NodeLevel.SHAPE:
     {
       Shape shape = (Shape)args.Node.Tag;
       if(shape != null && m_ShapeSelectedHandler != null)
       {
         m_ShapeSelectedHandler(this, shape);
         m_ShapeSelectedHandler = null;
       }
       else
       {
         this.SelectedShape = shape;
         if(args.Button == MouseButtons.Right)
         {
           LightContextMenu contextMenu = new LightContextMenu();
           ItemClickHandler removeObjectHandler = delegate()
           {
             this.SelectedScene.RemoveShape(shape);
             this.SelectedShape = null;
           };
           contextMenu.AddItem("Remove object", removeObjectHandler);
           contextMenu.Show(this, args.Location);
         }
       }
       
       break;
     }
   }
 }
Exemple #2
0
 private SpatialManip SelectSpatialManip(Vector2f position)
 {
   if(this.SelectedShape != null)
   {
     List<SpatialManip> candidates = new List<SpatialManip>();
     foreach(SpatialManip manip in this.SelectedShape.Manips)
     {
       if(manip.TryTouch(position, this.SelectedManip == manip))
       {
         if(this.SelectedManip == manip)
         {
           return this.SelectedManip;
         }
         
         candidates.Add(manip);
       }
     }
     
     if(candidates.Count != 0)
     {
       if(candidates.Count == 1)
       {
         return candidates[0];
       }
       else
       {
         LightContextMenu contextMenu = new LightContextMenu();
         for(int index = 0; index < candidates.Count; ++index)
         {
           SpatialManip manip = candidates[index];
           ItemClickHandler activateKey = delegate()
           {
             this.SelectedManip = manip;
           };
           contextMenu.AddItem(manip.Name, activateKey);
         }
         
         contextMenu.Show(this, GLToControlPosition(position));
         return null;
       }
     }
     else
     {
       return this.SelectedShape.SelectionManip;
     }
   }
   
   return null;
 }
 private void OnNodeClick(TreeViewEx sender, MouseClickArgs args)
 {
   if(args.Node.Level == 0)
   {
     if(args.Button == MouseButtons.Right)
     {
       LightContextMenu contextMenu = new LightContextMenu();
       contextMenu.AddItem("Edit templates...", this.OnEditTemplatesClick);
       contextMenu.Show(this, args.Location);
       this.ActiveTemplate = null;
     }
   }
   else if(args.Node.Level == 1)
   {
     if(args.Button == MouseButtons.Left)
     {
       this.ActiveTemplate = (ShapeTemplate)args.Node.Tag;
     }
   }
 }
Exemple #4
0
 private Shape FindShape(Vector2f position, bool backgroudCollect, out bool delayed)
 {
   delayed = false;
   List<Shape> candidates = new List<Shape>();
   foreach(Shape shape in this.Shapes)
   {
     bool selected = (this.SelectedShape == shape);
     if(shape.TryTouch(position, selected))
     {
       if(selected)
       {
         return this.SelectedShape;
       }
       
       candidates.Add(shape);
     }
   }
   
   if(candidates.Count != 0)
   {
     if(candidates.Count == 1)
     {
       return candidates[0];
     }
     else
     {
       List<Shape> filteredCandidates = new List<Shape>();
       if(backgroudCollect)
       {
         filteredCandidates.AddRange(candidates);
       }
       else
       {
         foreach(Shape shape in candidates)
         {
           if(!shape.Template.Backgroud)
           {
             filteredCandidates.Add(shape);
           }
         }
       }
       
       if(filteredCandidates.Count == 0)
       {
         return null;
       }
       else if(filteredCandidates.Count == 1)
       {
         return filteredCandidates[0];
       }
       else
       {
         LightContextMenu contextMenu = new LightContextMenu();
         for(int index = 0; index < filteredCandidates.Count; ++index)
         {
           Shape shape = filteredCandidates[index];
           if(!shape.Template.Backgroud || backgroudCollect)
           {
             ItemClickHandler activateKey = delegate()
             {
               this.SelectedShape = shape;
             };
             contextMenu.AddItem(shape.Name, activateKey);
             delayed = true;
           }
         }
         
         contextMenu.Show(this, GLToControlPosition(position));
         return null;
       }
     }
   }
   
   return null;
 }