Draw and Drag



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 02/08/2011 at 08:35, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R12 
    Platform:   Windows  ; Mac  ;  
    Language(s) :     C++  ;

    ---------
    Okay this is a basic question that I thought I knew the answer to but can't seem to get it to work.

    How do you draw a 2D line while dragging the mouse?

    I tried using DrawLine2D while dragging in MouseInput() like so...

      
      
     win->MouseDragStart(button,mx,my,MOUSEDRAGFLAGS_DONTHIDEMOUSE|MOUSEDRAGFLAGS_NOMOVE);  
       while (win->MouseDrag(&dx,&dy,&device)==MOUSEDRAGRESULT_CONTINUE)  
       {  
            
          if(dx == 0 && dy == 0) continue;  
      
          mx += dx;  
          my += dy;  
             
          bline = TRUE;  
    GePrint("1");  
          bd = doc->GetActiveBaseDraw();  
          if(bd) return FALSE;  
            
    GePrint("2");  
          startpoint = Vector(cursorX, cursorY, 0);   
          newpoint =    Vector(mx, my, 0);  
      
          bd->SetMatrix_Screen();  
          bd->SetPen(Vector(1,1,1));  
          bd->DrawLine2D(startpoint, newpoint);  
      
          GeSyncMessage(EVMSG_ASYNCEDITORMOVE);  
          EventAdd();  
      
            
       }  
      
       if (win->MouseDragEnd()==MOUSEDRAGRESULT_ESCAPE)  
       {  
           bline = FALSE;  
      
       }  
      
       return TRUE;  
    

    but nothing happens..  the BaseDraw is not active and my second GePrint() never gets shown.  So I tried using bools which is what the bline == TRUE is and drawing the line in Draw()  but nothing works.  Do I need to use a SceneHook to accomplish this?

    Thanks,

    Shawn



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 02/08/2011 at 09:01, xxxxxxxx wrote:

    Hm don't have much time to take a look at it.

    But basically you should define the 'startpoint' vector before the while loop (actuall on the mouse down) and during the while loop you get the endpoint through the new cursor position and draw the line between those.

    Don't forget to make the gui sleep within the while loop. About 30 or 40 fps should be great.

    start = Vector(msg.GetReal(MOUSEX), msg.GetReal(MOUSEY), 0)  
      
    while (isDragging) {  
      end = Vector(msg.GetReal(MOUSEX), msg.GetReal(MOUSEY), 0)  
      DrawLine(start, end)  
      
      sleep(1.0 / 10.0)  
    }
    

    /edit: Oh I was talking about userareas .. but it shouldn be that different to the editor window.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/08/2011 at 06:03, xxxxxxxx wrote:

    Basically you need to store the start and end point of the line in own member variables of your tool class. Fill these variables from within the mouse loop. At the end of the loop call DrawViews, like DrawViews(DRAWFLAGS_ONLY_ACTIVE_VIEW|DRAWFLAGS_NO_THREAD|DRAWFLAGS_NO_ANIMATION) for instance. This will trigger a redraw and call the Draw method of your tool class. In the Draw method read out the variables and use them for your line drawing.

    cheers,
    Matthias


Log in to reply