Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
On 14/01/2014 at 08:34, xxxxxxxx wrote:
User Information: Cinema 4D Version: 13 Platform: Windows ; Language(s) : C++ ;
--------- Hi, I'm trying to get the width of the UI border around the editor window so I can subtract it from the mouse cursor position. So that I can get the mouse coordinates for just the editor window. BFM_INPUT_X & BFM_INPUT_Y include the border areas in their calculations. And GetCursorInfo() is not available in tag plugins.
It works fine for me in python. But I can't get it to work in C++.
Python
mx = msg[c4d.BFM_INPUT_X] my = msg[c4d.BFM_INPUT_Y] bd = doc.GetActiveBaseDraw() win = bd.GetEditorWindow() wx, wy = win.Local2Screen() print mx-wx #<---- prints 41 print my-wy #<---- prints 109
C++
Bool DrawTool::MouseInput(BaseDocument *doc, BaseContainer &data, BaseDraw *bd, EditorWindow *win, const BaseContainer &msg) { BaseContainer state; while (GetInputState(BFM_INPUT_MOUSE, BFM_INPUT_MOUSELEFT, state)) //While the left mouse button is pressed { if (state.GetLong(BFM_INPUT_VALUE) == 0) break; // Break out of the loop when left mouse button is NOT pressed LONG mx = state.GetLong(BFM_INPUT_X); LONG my = state.GetLong(BFM_INPUT_Y); LONG wx, wy; bd->GetEditorWindow()->Screen2Local(&wx, &wy); mx = mx-wx; //<----Gibberish...memory addresses? 858991498 my = my-wy; //<----Gibberish...memory addresses? 858991498 GePrint(LongToString(mx)); } return TRUE; }
What am I doing wrong? Is there another way to get the mouse coordinates for just the editor window? Something that I can use in things like tag plugins that doesn't support GetCursorInfo().
-ScottA
On 17/01/2014 at 18:56, xxxxxxxx wrote:
Figured it out. The SDK has lots of functions that fill variables with data. But once in a while you run into one like this that doesn't fill the variables... It converts them. So asking the Screen2Local() function to convert unassigned variables is why I was getting gibberish values from it.
Here's the C++ code that produces the correct values
Bool DrawTool::MouseInput(BaseDocument *doc, BaseContainer &data, BaseDraw *bd, EditorWindow *win, const BaseContainer &msg) { BaseContainer state; while (GetInputState(BFM_INPUT_MOUSE, BFM_INPUT_MOUSELEFT, state)) //While the left mouse button is pressed { if (state.GetLong(BFM_INPUT_VALUE) == 0) break; // Break out of the loop when left mouse button is NOT pressed LONG mx = state.GetLong(BFM_INPUT_X); LONG my = state.GetLong(BFM_INPUT_Y); //This code gets the editor window's mouse coordinates(not including the UI border area around it) LONG wx = mx; LONG wy = my; bd->GetEditorWindow()->Screen2Local(&wx, &wy); GePrint(LongToString(wx) + " " +LongToString(wy)); } return TRUE; }