Hey @m_adam ,
Yes , I had a look at this example, but I'm confusing to understand how it can apply to my case, sorry for my foolish brain.
If I keep InputEvent
as @ferdinand did in the example, HandleMouseDrag
will return True if I have a little move, I try to stop this,
so I want to execute HandleDragEvent
only when mouse "obvious interaction outside the ua",to avoid the accompanying effect of dragging when lightly clicked (download) .
def InputEvent(self, msg: c4d.BaseContainer) -> bool:
"""Called by Cinema 4D when the user area receives input events.
Here we implement creating drag events when the user drags from this user area. The type of
drag event which is initiated is determined by the drag type selected in the combo box
of the dialog.
"""
# When this is not a left mouse button event on this user area, we just get out without
# consuming the event (by returning False).
if (msg.GetInt32(c4d.BFM_INPUT_DEVICE) != c4d.BFM_INPUT_MOUSE or
msg.GetInt32(c4d.BFM_INPUT_CHANNEL) != c4d.BFM_INPUT_MOUSELEFT):
return False
# Get the type of drag event that should be generated, and handle it.
dragType: int = self._host.GetInt32(self._host.ID_DRAG_TYPE)
return self.HandleDragEvent(msg, dragType)
my code did stop the HandleDragEvent
execute if I didn't want to.
but in this situation, even if I print and execute HandleDragEvent
successfully, C4D does not accept drag events, which means the material cannot be assigned to the object. I don't know what is preventing this.
def InputEvent(self, msg: c4d.BaseContainer) -> bool:
"""Called by Cinema 4D when the user area receives input events.
Here we implement creating drag events when the user drags from this user area. The type of
drag event which is initiated is determined by the drag type selected in the combo box
of the dialog.
"""
# When this is not a left mouse button event on this user area, we just get out without
# consuming the event (by returning False).
if msg[c4d.BFM_INPUT_DEVICE] != c4d.BFM_INPUT_MOUSE and msg[c4d.BFM_INPUT_CHANNEL] != c4d.BFM_INPUT_MOUSELEFT:
return False
dragType: int = self._host.GetInt32(self._host.ID_DRAG_TYPE)
if msg.GetBool(c4d.BFM_INPUT_DOUBLECLICK):
print("Double click detected, generating drag event")
return True
mx = int(msg[c4d.BFM_INPUT_X])
my = int(msg[c4d.BFM_INPUT_Y])
mx -= self.Local2Global()["x"]
my -= self.Local2Global()["y"]
# print(f"Start mouse: {mx}, {my}")
state = c4d.BaseContainer()
self.MouseDragStart(c4d.BFM_INPUT_MOUSELEFT,mx,my,c4d.MOUSEDRAGFLAGS_DONTHIDEMOUSE|c4d.MOUSEDRAGFLAGS_NOMOVE)
isFirstTick = True
s = 0
dua = 0
while True:
res, dx, dy, channels = self.MouseDrag()
if res != c4d.MOUSEDRAGRESULT_CONTINUE:
break
mx -= dx
my -= dy
self.GetInputState(c4d.BFM_INPUT_MOUSE, c4d.BFM_INPUT_MOUSELEFT, state)
# mouse released, this can triggered by a click or a drag end
if state[c4d.BFM_INPUT_VALUE] == 0:
dua = time.perf_counter() - s
print (f"Released Mouse in {dua:.4f} seconds")
# drag too short, not starting drag event
if dua < 0.15:
return False
break
if isFirstTick:
isFirstTick = False
s = time.perf_counter()
print(f"\t-- first click : {mx}, {my}")
continue
endState = self.MouseDragEnd()
if endState == c4d.MOUSEDRAGRESULT_FINISHED:
print(f"\t-- drag finished : {mx}, {my}")
# drag end inside ua, not generating drag event
if (0 <= mx <= 0 + self.width and 0 <= my <= 0 + self.height):
return False
print('Now ,try to start drag event')
return self.HandleDragEvent(msg, dragType)
Cheers~
DunHou