How do i move the mouse with processing? - processing

I was testing processing features and wondered if I could move the mouse with code with/without libraries. So can anyone write me a code / give me a library so that it works?
I tried reading half the 284 questions and found nothing, I tried reading through github trying to find a code / a library that works.

Not an answer, but a potential workaround:
Using noCursor(); you can get rid of the default cursor, and then develop your own custom cursor using something like shapes.
E.g. circle(mouseX + 20, mouseY, 20); would always draw a "cursor" 20 pixels to the right of where your mouse position actually is.
This is how I made a custom and dynamic cursor for a little game, where it changed color and sometimes position depending on activities on the screen.

Related

Problem when assigning Input.mousePosition to transform.position in Unity2D

I have been following the Inventory tutorials for Unity by Kryzarel and have encountered a weird issue that I think may be from something unrelated.
Tons of googling has yielded no results. It seems like an obscure issue.
https://www.youtube.com/channel/UCOM0GGMEcu-gyf4F1mT7A8Q/videos for reference of the channel.
But the issue I'm running into is I do the following:
draggableItem.transform.position = Input.mousePosition;
So basically draggable Item is a reference to an Image component on a GameObject. I log Input.mousePosition before hand and the values make sense (within the hundreds e.g. (563,262,0)). However, the transform position is nowhere near the number logged. For the example, I'm seeing (48660.31, 23917.95, -7889.887). There is no logic between the debug.log statement giving Input.mousePosition and the code assigning it to the transform. Anyone have any idea what I could possibly have configured wrong, or could be wrong?
I would expect the position to be (563,262,0) not the ridiculous number that it ends up being. I've tried localPosition instead of transform.position, and it sort of works. In that it's off by about 500 or 700 to the top-right of what I'm moving relative to the mouse, I want to avoid hacky solutions like subtracting some magic number if possible.
Edit: Some further background, other mouse clicks and mouse related things appear to work correctly. It's an orthographic camera, or the default for a unity2D project
Solution: IN my case I was able to set it per the accepted answer, I then had to modify position not localPosition and also had to zero out the z-value of the world point.
The mouse position is relative to your screen, not your world. You need to convert the screen space to world space with:
var pos = Camera.ScreenToWorldPoint(Input.mousePosition);

wxToolBar changing device coordinates

Using the mouse I am drawing 2D shapes on the client area of a MDIChildFrame. Recently I have added a wxToolBar to the frame and when I now draw a shape on the client area it seems that the points have shifted by the size the toolbar. Imagine that with mouse I am clicking on (100,100) and drawing a line to (150,150); however, the line appears somewhere (75,75) to (125,125). By the way, wxMouseEvent GetPosition(); reports (100,100) to me.
Removing the toolbar fixes the problem however, I want to keep the toolbar for ease of tool selection.
I use the code:
m_ToolBar=new wxToolBar(this, wxID_ANY);
m_ToolBar->AddTool() //
m_ToolBar->Realize();
this->SetToolBar(m_ToolBar);
Any ideas will be appreciated.
You can always use wxWindow::GetClientAreaOrigin() to manually offset the coordinates by the toolbar height but normally this shouldn't be necessary, and if this doesn't happen with a "normal" frame but only happens with wxMDIChildFrame it would be a bug in wxWidgets that should be reported as usual.
It's also recommended to not draw over wxFrame itself but rather put a wxWindow into it and draw on it. This should also take care of your problem.

Vertical NSLevelIndicator OSX

I wonder if there is a way of creating/modifying a NSLevelIndicator object so it can be positioned vertically, i.e. display discrete levels from bottom up, not from left to right, so it can be also used as element of interface-building library in Xcode?
There are lots of examples of such level displays in Apple and non-Apple OSX applications, and quite a few reasons why such an object should exist, yet how to create such an object for some reason (from what I can see in developer forums) seems either not worth asking or a "best kept secret".
Is there a template code which can be modified to into an object of such properties?
I haven't even faintest idea if such an object should really be written from scratch? Mission impossible?
Thanks in advance!
Try using
[NSView setFrameRotation:90];
it's sketchy but easier than a custom view
Edit: Alternatively try
[levelView setFrameCenterRotation:90];
SetFrameRotation:90 rotated it around the bottom left axis for me so it ended up being clipped. This one rotates it around the centre so you should be able to see it. I just made a quick swift playground showcasing it: http://cl.ly/WsL8/Vertical%20LevelIndicatorView.playground.zip
Edit again: If you're still stuck, I made a sample project with a vertical level indicator in objective-c: http://cl.ly/WrdH/levelindicator.zip
Swift 5.5.1 on macOS 11.6
myLevelIndicator.frameRotation = 90
If you need to reposition the indicator to fit within the view, realize the center of rotation is the origin of the level indicator.
So, to set the rotated level indicator 20px in from the left of the view, compute that for the new frame origin of the level indicator, not forgetting to adjust for the indicators height when it is horizontal because the original height will affect the final position when rotated.
myLevelIndicator.frame.origin = CGPoint(x: self.view.frame.minX+20+myLevelIndicator.frame.height, y: myLevelIndicator.frame.minY)
Of course, this can be avoided by placing the control in the correct position to allow for rotation within IB if that works for you. Some may not be using IB and creating these controls programmatically.

Changing the background of an edit control on getting focus

I want to change the background color of an edit control (i.e. regular EDIT window class) in that control's EN_SETFOCUS. I know that I should handle WM_CTLCOLOR, do SetBkColor() on the DC I get, and return a handle to a brush with the background color. HOWEVER, when I do that from EN_SETFOCUS, my control isn't invalidated or redrawn properly. Basically I get a 1-pixel border in the wrong color around my text; so a rectangle within the black border that is already around the control itself. If I move my mouse cursor over the control, some parts of that wrong border are redrawn correctly, and sometimes the whole artifact disappears after a small amount of time, as if some timer is causing a complete redraw.
I have tried invalidating the control in various places, RedrawWindow, SelectRgn(NULL) on the DC, playing with wS_CLIPCHILDREN and -SIBLINGS of the dialog, invalidating the dialog on the rect the control is at, but none of this works. I have also found a vague reference to a similar problem online in a post from 2001 (!) but no solution. Has anyone ever encountered this? Any ideas on other things I could try?
FWIW, this is using VS9 on WinXP, and using MFC, but I've also send messages 'by hand' and that didn't change anything, I don't think MFC in this case is the culprit. Of course I could be wrong :)
Edit:
Code of the dialog of the screenshots below (minimal sample) is here: http://pastebin.com/zepdhdp5 . This is a small wizard-generated app - nothing special, the full source code can be downloaded from https://www.dropbox.com/s/d8nxaryoo0vclue/edit_control_redrawing_sample.zip .
The control looks like this after it gets focus:
and like this when it loses focus:
As you can see, it looks like there a border around the text area that doesn't get invalidated.
I have tried to reproduce this with pure win32, but when I don't use commonctrl6, it doesn't exhibit the problem. I can't manage to get commonctrl6 to work in win32 though, so I'm suspecting now that it's got something to do with that.
Well what do you know - after another day of intermittently attempting various things and trying different angles in google searches, I found the magic keyword: non-client area invalidation. Which led me to http://forums.codeguru.com/showthread.php?307470-Invalidate-NC-area , which contains the solution:
SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_DRAWFRAME);
(in the SetFocus/KillFocus handlers)
My theory of what's going on is that the commonctrl6 visual styles manager treats the border around the edit control as non-client area, and miscalculates the area to be invalidated by one pixel when the control gets the focus. SWP_DRAWFRAME seems to be the only thing that forces a complete update of the control, RedrawWindow() with RDW_FRAME didn't cut it.
Ah well, hopefully my question here at least saves someone down the line from wasting his time like I have...

camera.lookAt not called when THREE controls are being used

I am working on a program, that uses THREE.RollControls, when the user goes too far away from the center of the screen, they tend to get lost, so I am working on creating a function that reorients them, facing the center of the scene.
What I had intened to do was simply call the following:
camera.lookAt(scene.position)
However, this has no affect. From what I was reading on different stack overflow questions specifically this:
ThreeJS camera.lookAt() has no effect, is there something I'm doing wrong?
It seems like their solution was to do the camera position change using the controls, rather then changing the camera itself.
I do not believe there is any 'Target' in the Roll Controls, so I don't know how I can reset where the camera is looking at based on a THREE.Vector3() Is there a simple way to do this, or will I basically have to:
So far I have 'attempted' to do the follow:
- Calculate the difference of position of the camera with the position of the scene.
- Normalize this vector
- Subtract it from the direction forward of the camera
- use this vector in controls.forward.add(thisVector)
but this doesn't do at all what I want (probably because I have no idea what I'm doing)
Thank you in advance for your time!
Isaac
The same thing bugged me too about the RollControls but I took a different approach in solving the problem. Since the controls are in the example code (in r55) you can modify the controls, as they are not part of the core library. You can see my modifications at http://www.virtuality.gr/AGG/EaZD-WebGL/js/three.js/examples/js/controls/RollControls.js
I introduced a local variable called mouseLook because I could not use the this.mouseLook. I initialized it to false and I only make it true when there is a button press i.e. when navigating in the scene. That solved my problem.

Resources