I am making a painter and when I am detect the point I want to draw in zooming mode in the interactive viewer it gets the wrong offset so I need the panning in the x-coordinate and the y-coordinate to have the correct offset
Use GestureDetector onPanUpdate Method to get change of finger-swipe and current finger coordinates
onPanUpdate: (pan){
print('Change In X:${pan.delta.dx}');
print('Change In Y:${pan.delta.dy}');
print('Global X Coordinate:${pan.globalPosition.dx}');
print('Global Y Coordinate:${pan.globalPosition.dy}');
print('Local x Coordinate:${pan.localPosition.dx}');
print('Local Y Coordinate:${pan.localPosition.dy}');}
Related
Am new to flutter and i need to get x axis y axis value of particular place of the image.i have put the image in container and i need to mark one corner of the container image position as (0,0) when I click the any part or place of the image I need to get x axis and y axis value of the clicked position. I don't know how to do it. Please any one help me to do that. Thanks in advance
Use GestureDetector to track mouse position.
// variables (or states based on your needs) to store positions
double x = 0.0;
double y = 0.0;
// a function to update mouse pointer position (location)
void updatePosition(TapDownDetails details) {
setState(() {
x = details.globalPosition.dx;
y = details.globalPosition.dy;
});
}
// image widget
GestureDetector(
onTapDown: updatePosition,
child: Image.asset(yourImagePathHere)), <-- change it to your image path
),
I'm struggling with this sort of
Screen disposition.
I want to position my Camera so that the world is positionned like in the image with the origin at bottom left. It's easy to set the orthographicSize of the camera as I know how many unit I want vertically. It is also easy to calculate the Y position of the camera as I just want it to be centered vertically. But I cannot find how to compute the X position of the camera to put the origin of the world in this position, no matter what the aspectRatio of the screen is.
It brings me two questions :
How can I calculate the X position of the camera so that the origin of the world is always as the same distance from the screen left and bottom borders ?
Instead of positioning the camera regarding the UI, should I use RenderMode Worldspace for the UI canvas. And if so, how could I manage responsiveness ?
I don't understand the second question, but regarding positioning the Camera on the X axis so that the lower left corner is always at world 0 you could do the following:
var lowerLeftScreen = new Vector3(0, 0, 10);
var pos = transform.position;
var lowerLeftScreenPoint = Camera.main.ScreenToWorldPoint(lowerLeftScreen).x;
if (lowerLeftScreenPoint > 0)
{
pos.x -= lowerLeftScreenPoint;
}
else
{
pos.x += Mathf.Abs(lowerLeftScreenPoint);
}
transform.position = pos;
Debug.Log(Camera.main.ScreenToWorldPoint(lowerLeftScreen));
Not the nicest code, but gets the job done.
Also the Z component in the Vector does not really matter for our orthographic camera.
GestureDetector(
onVerticalDragUpdate: (details) {
var dy = details.delta.dy;
var primaryDy = details.primaryDelta;
},
)
I couldn't find out the difference between a regular delta and a primary, both seems to do the same job. Can anyone explain the difference between these two deltas? (As usual Docs are not very clear, at least to me)
DragUpdateDetailsclass:
delta → Offset The amount the pointer has moved in the coordinate
space of the event receiver since the previous update
Meaning, The distance covered by dragging since the last pointer contact. Delta gives dx for horizontal distance and dy for vertical distance.
primaryDelta → double The amount the pointer has moved along the
primary axis in the coordinate space of the event receiver since the
previous update
primaryDelta gives the absolute distance in only one primary direction of dragging, meaning if the drag is primarily in horizontal axis(GestureDragUpdateCallback + Horizontal only) then this value represents the drag distance in the horizontal axis. If the drag in is vertical axis (GestureDragUpdateCallback + Vertical only) then this value represents the drag amount in the vertical axis.
Note: if the GestureDragUpdateCallback is for a two-dimensional drag (e.g., a pan), then this value is null.
I am working on Unity 4.7 project and need to create shooting on the target. I simulated gunpoint using horizontal and vertical slider moving on the time. When I click the button I need to memorize x and y coordinates of handles and instantiate bullet hole at this point but don't know how to get cords of sliders handle. It is possible to get values but it seems that it doesn't correspond to coordinates. If horizontal slider changes its value for 1, would its handle change x position for 1?
Use this then:
public static Vector3 GetScreenPositionFromWorldPosition(Vector3 targetPosition)
{
Vector3 screenPos = Camera.main.WorldToScreenPoint(targetPosition);
return screenPos;
}
Have the reference to Handles of the horizontal and vertical sliders, and use them like:
Vector3 pos = GetScreenPositionFromWorldPosition(horizontalHandle.transform.position);
I have a scrolled window with a viewport, which is some 4000 pixels tall. Is there a way to figure out the mouse position in viewport coordinates? At the moment, what I get for the position is the position in the segment that I actually see, and if I scroll down to the bottom, I still get something like 600 pixels for the vertical position (that is the size of my window), instead of the 4000 that I expect. If there is no easy way, how can one determine by how much the scrolled window is scrolled? I believe, I could then put the pieces together.
Thanks,
v923z
You are looking for the get_vadjustment method of the scrolled_window.
For instance if you bind the button_press_event to the scrolled window:
def button_press_event(self, widget, event):
v_scroll_pos = widget.get_vadjustment().get_value()
print "y pos + scroll pos = %f" % (event.y + v_scroll_pos,)
return gtk.TRUE
Would print the y position + the amount it is scrolled in the y direction.