Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Login

    drag on userarea [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    8 Posts 0 Posters 784 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      On 11/06/2015 at 12:51, xxxxxxxx wrote:

      Hello,

      I use the Message of a Dialog to revive a drag - in the dialog are several userareas and i like to call a different function when the drag finished over a userarea than on the rest of the dialog - can i check if it over ?

      Thanks

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 12/06/2015 at 07:44, xxxxxxxx wrote:

        Hi,

        I'm not quite sure, what you mean with "revive a drag". Basically all you need to do, is to process the BFM_DRAGRECEIVE message in your GeUserArea. For example see this thread.

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 12/06/2015 at 11:08, xxxxxxxx wrote:

          Hi Andreas,

          I use the BFM_DRAGRECEIVE in the Message of a gui.GeDialog - to receive the drag on the dialog - but i need to know if the drag was on the free space in the dialog or on a special GeUserArea within the dialog

          i try to add the BFM_DRAGRECEIVE in the GeUserArea but the dialog take the message

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            On 16/06/2015 at 03:29, xxxxxxxx wrote:

            Hi conner,

            indeed, this was a bit tricky. I guess, that's why Drag&Drop for Python is not documented, yet.
            Here's what I did to make it work:
            Basically I implemented Message() only for the GeDialog and have a custom MyDragMessage() function on the GeUserArea.

            Note: I used the MemoryViewer example from the Python SDK examples. In there I duplicated the mem_info user area and added a static text in between in order to have some "dialog" area.

            In my GeUserArea:

                def MyDragMessage(self, msg, draginfo, result) :
                    # Don't discard here, if lost drag or if it has been escaped. Already done in parent dialog.
              
                    # Check drop area and discard if not on the user area
                    if not self.CheckDropArea(msg, True, True) :
                        self.SetDragDestination(c4d.MOUSE_FORBIDDEN)
                        return False
              
                    # Here: Mouse hovers over user area
              
                    # Check if drag is finished (=drop)
                    if msg.GetInt32(c4d.BFM_DRAG_FINISHED)==1:
                        print "Dropped on UserArea %s" % self.uaIdx
                        return True
              
                    # Return current mouse cursor for valid drag operation
                    self.SetDragDestination(c4d.MOUSE_MOVE)
                    return True
            

            In my GeDialog:

                def Message(self, msg, result) :
                    if msg.GetId()==c4d.BFM_DRAGRECEIVE:
                        # Get drag object type and data
                        draginfo = self.GetDragObject(msg)
              
                        # Discard if lost drag or if it has been escaped
                        if msg.GetInt32(c4d.BFM_DRAG_LOST) or msg.GetInt32(c4d.BFM_DRAG_ESC) :
                            # Not sure, why we need to test the UserArea here as well
                            if self.mem_info.MyDragMessage(msg, draginfo, result)==True:
                                return True
                            if self.mem_info_2.MyDragMessage(msg, draginfo, result)==True:
                                return True
                            return self.SetDragDestination(c4d.MOUSE_FORBIDDEN)
              
                        # if we are here, mouse hovers over dialog
              
                        if self.mem_info.MyDragMessage(msg, draginfo, result)==True:
                            return True
                        if self.mem_info_2.MyDragMessage(msg, draginfo, result)==True:
                            return True
              
                        # Check if drag is finished (=drop)
                        if msg.GetInt32(c4d.BFM_DRAG_FINISHED)==1:
                            print "Dropped on Dialog"
                            return True
              
                        # Return current mouse cursor for valid drag operation
                        return self.SetDragDestination(c4d.MOUSE_MOVE)
              
                    # Call GeDialog.Message() implementation so that it can handle all the other messages
                    return gui.GeDialog.Message(self, msg, result)
            
            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              On 19/06/2015 at 11:35, xxxxxxxx wrote:

              Hey Andreas,

              thanks for you help - In my case it`s a bit more tricky- I have a undefined  count of GeUserArea of two different types - is there a way to check that and return the id ?

              Many Thanks

              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

                On 19/06/2015 at 21:03, xxxxxxxx wrote:

                Hi conner,

                you need to add a "MyDragMessage" to both types. Then have a index member in your GeUserAreas. In my case it's uaIdx (my code already prints, on which area the user dropped) and I initialize it, when instancing the GeUserAreas. I simply used indeces beginning with 0, but of course you can use anything you like (e.g. DescIds). Sorry, I should have mentioned that. And you are free to change the "MyDragMessage" functions to  return the index (and for example -1 in false cases), if you need that information in the parent dialog.

                1 Reply Last reply Reply Quote 0
                • H Offline
                  Helper
                  last edited by

                  On 20/06/2015 at 04:40, xxxxxxxx wrote:

                  You probably have the user areas in a list somewhere. If you have mixed types of user areas
                  in the list, then you could use isinstance() to check the type or (even more portable) call the
                  method only on objects that support it via hasattr().

                  for ua in self.user_areas:  
                      if hasattr(ua, 'MyDragMessage') and ua.MyDragMessage(msg, draginfo, result) :
                          return True
                  
                  1 Reply Last reply Reply Quote 0
                  • H Offline
                    Helper
                    last edited by

                    On 21/06/2015 at 06:02, xxxxxxxx wrote:

                    great - that work

                    good help - thanks

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post