How to make menus pop up in a certain distance of the mouse？
milkliu last edited by milkliu
I know how to use the method below to create a popup menu:
c4d.gui.ShowPopupDialog(cd, bc, x, y, flags=POPUP_RIGHT|POPUP_EXECUTECOMMANDS)
(x (int) – Popup X position in screen pixels, or c4d.MOUSEPOS to popup where the cursor is.
y (int) – Popup Y position in screen pixels, or c4d.MOUSEPOS to popup where the cursor is.)
I want the menu to popup at a position like this:x=c4d.mousepos+200,y=c4d.mousepos+200
but it do not work. is there a way?
thank you very much!
Hi @milkliu first of all welcome in the plugincafe.
I would like to point you to Q&A New Functionality.
While your idea is correct to add 200, c4d.mousepos is actually a constant and not a real value. So if you want to offset the position you have to first, retrieve the position with GetInputState.
import c4d def main(): IDM_MENU1 = c4d.FIRST_POPUP_ID IDM_MENU2 = c4d.FIRST_POPUP_ID+1 menu = c4d.BaseContainer() menu.InsData(IDM_MENU1, 'Item 1') menu.InsData(IDM_MENU2, 'Item 2') state = c4d.BaseContainer() c4d.gui.GetInputState(c4d.BFM_INPUT_MOUSE, c4d.BFM_INPUT_MOUSELEFT, state) x = state.GetInt32(c4d.BFM_INPUT_X) + 200 y = state.GetInt32(c4d.BFM_INPUT_Y) + 200 result = c4d.gui.ShowPopupDialog(cd=None, bc=menu, x=x, y=y) # Execute main() if __name__=='__main__': main()
If you have any question, please let me know.
milkliu last edited by
I did what you say,it works!!
you are so cool!!
thank you very much!!!