Hi,
I am looking to develop a few plugins and was playing with the mouse position and screen dimensions, as seen in code snippet below.
I have assigned a shortcut to the plugin, which I then use to activate the plugin with different positions of the mouse to trigger the CommandData::Execute
.
class MyCommand : public CommandData
{
public:
// R20
// virtual Bool Execute(BaseDocument* doc)
// R21
virtual Bool Execute(BaseDocument* doc, GeDialog* parentManager)
{
BaseContainer bc;
if (GetInputState(BFM_INPUT_MOUSE, BFM_INPUT_MOUSELEFT, bc))
{
const Int32 mx = bc.GetInt32(BFM_INPUT_X);
const Int32 my = bc.GetInt32(BFM_INPUT_Y);
ApplicationOutput("Mouse coordinates @, @", mx, my);
Int32 sx1, sx2, sy1, sy2;
GeGetScreenDimensions(mx, my, true, &sx1, &sy1, &sx2, &sy2);
ApplicationOutput("Screen has coordinates @, @ -> @, @", sx1, sy1, sx2, sy2);
}
return true;
}
};
I am using a multiple monitor setup for testing purposes, as can be seen in following picture:
The picture isn't that important, but it can help in understanding the next screenshots taken from testing with the above setup.
I have been running R20 and R21 positioned identically relative to the two monitor setup, and have triggered the plugin with specific mouse positions. Notice that the accuracy of the mouse positions between the two tests isn't that important.
[ EDIT 1:
Note that the actual locations used for testing out the mouse position aren't important. I had chosen a few locations as references which could be easily reproduced both with R0 and R21.
Therefore, I created two dummy folders on the desktop, which I could use outside of the main window next to some easily recognizable locations on the main window itself.
I have indicated the locations with a red dot as I couldn't capture the mouse cursor.
EDIT 1]
R20: (had to upload a low quality jpg, better quality png is available on request)
R21: (same as for R20, a low quality jpg is uploaded for reason of allowed upload size)
Summary of the test.
While R20 seems to have appropriate coordinates for mouse positions outside of the main window, the values for R21 do not make any sense.
However, both version of Cinema4D seem to provide coordinates relative to some reference point of the main window itself. Move the window onto one screen or another, one would expect coordinates to be different, since with GetScreenDimensions
the provided coordinates are used to detect the screen dimensions.
In R20, when the main window of Cinema4D is entirely positioned inside the right side monitor, and the mouse cursor is positioned in the left side monitor area, executing the provided code results in:
"Screen has coordinates -1080, -650 -> 0, 1270". Which is exactly what one would expect, if the right side monitor is the main monitor with reference corner 0, 0.
However, move the main Cinema4D window into the left monitor area (entirely or only partially), then with the same mouse position as before one will get:
"Screen has coordinates 0, 0 -> 1920, 1080". Which definitely does not make any sense.
So, while the implementation for R20 is "slightly" better than R21, both are useless when it comes to multi monitor setups. I have not tested single monitor setup in details as, to me, it is not an option to have this working with single monitor and not working with multi monitors.
[ EDIT 2:
The original purpose for testing out was to find out if I could use some global mouse positioning, and be able to detect if the mouse position was close to the edge of a monitor.
I actually got side-tracked by trying to figure out the resulting mouse coordinates when the main window was on the right and left window. From this side-tracking I got even more confused about mouse coordinates "outside" of the main window. And then got totally off track finding out differences between R20 and R21. So, the whole thread just seems as a one big brain fart. Feel free to request to explain in smaller steps if the above brain dump doesn't make any sense.
EDIT 2 ]
Apologies for the lenghty post.