Reset Line position after window resize - kivy

I'm developing an App where I want to draw lines on an Image. The Image can be zoomed in and out, and dragged. I used self.to_widget() method of the Scatter class, so that the coordinates with respect to the Image will remain the same after zooming and dragging.
I wanted to implement a reset button, that would allow to reset the position and size of the image with respect to the the Window size. Here I'm facing the problem that the coordinates of the lines are changing with respect to the Image.
Knowing that the Image is a Child of a Scatter class with id: scatter_class, here is the code for the reset button:
def reset_position(self):
self.initial_width = Window.size[0]
self.initial_height = Window.size[1]
self.ids.scatter_class.pos = (
self.initial_width * 0.25,
self.initial_height * 0.5 - self.ids.main_image.height * 0.5,
)
I read that making changes in a Scatter class, won't affect its children, that's why probably the Line position are not updating with respect to the Image. I tried updating the position of the Lines using the to_widget() Method, to recalculate the coordinates with respect to the new position and size of the image, but it seems like I'm missing something.
Any Ideas?
Thanks in Advance!

Related

Curved Path2D becomes straight when increasing stroke size

I have this strange problem with Java2D. I have a Path2D.Double that I want to draw, but depending on the stroke size, all segments are drawn correctly (curved) but when the stroke size is greater or equal than 0.00005d the segments are drawn straight. As you can see, the only parameter I'm changing is the stroke size. What am I doing wrong?
BasicStroke basicStroke1 = new BasicStroke(.00004f, CAP_ROUND, JOIN_ROUND);
g2draw.setStroke(basicStroke1);
g2draw.draw(path);
BasicStroke basicStroke2 = new BasicStroke(.00006f, CAP_ROUND, JOIN_ROUND);
g2draw.setStroke(basicStroke2);
g2draw.draw(path);
And here a picture with the result of this code:
Turns out the error seems to be rounding errors when transforming user coordinates to screen coordinates, when the scale difference is big (or not so big...). It's an odd behaviour of Java2D. Switched to JavaFX and the problem disappeared.

How to draw multiple circles within circle like target and get touch event of particular circle?

I want to draw target view like this-
And get touch event of a particular circle.
e.g If user touch between circle 7 then fill black color of circles up to circles 7.
Currently I have two ways to implement this functionality:
1) Take 10 UIImageView and put on each other and touch of an image view change the colors of image view's according to conditions.
2) Take UIView and draw 20 color gradient (10 for black border line and 10 for white spaces) and save frame of each gradient. After that get user's touch area then change color according to that.
I am looking for a better solution.
why not have a single image, and calculate the radius based on the touch point - all you need to know is the centre position.
Instead of radius, what you really need is an index from 0 to 11 for your bands - if they are equal thickness, you can do that in a single calculation - take the integer part of (11 * radius / radiusFull)
If the bulls-eye is a different size, you may need to add some more code.
Either way, you should be able to do it all with a single image - generated on the fly, or simply loaded - and a bit of simple maths.

Is there any way to do change the look of slider ? move slider at different positions with image change

hi this is an image i attached. Actually i want to build a system in which i want to move the car button (showing in image) to different specified positions(showing on the right) and at each position i want to replace the car image with different one(like truck, train). is there any way to do this ?
Link to the image:-
https://drive.google.com/file/d/0B-TGzvOW0sr9Wlk3T25DYWZlOGs/view
yes there is always a way to do it :-)
so create a UIView subclass which has two UIImageViews. 1st UIImageView can be the horizontal line. and the second UIImageView can be the with the car. you then move the UIImageView horizontally as you wish and set different images while changing the position.
edit:
1. moving an UI element can be done with resetting the frame of UI element.
for example if an image was at position (x,y, width, height) and you want to move 20 points to the right then it will be (x + 20, y, width, height)
if you use auto layout then you can just change the constant of your x-constraint in this case.
edit 2 :
you can use (Tap/Pan) Gesture recogniser. you will get the exact position and as well as the velocity with different state (gesture started/ended/changed).

How to detect the coordinates of a custom UIView on CPTPlotspace?

In my App, I am using Coreplot to draw a CPTScatterPlot. Now i want to do a scanner on the chart and this animation of UIView (a line) should be like a Line aligned with Y-axis and travels through x=0 to whatever the last value of x is.
I want to perform an action based on the y value while this custom UIView (scanner) travels.
Any help would be appreciated.
Thanks,
i have something similar in an app of mine, the way i went about it was to add a bar graph on top of the scatter plot, i used that bar graph to represent the line that tracks the user's touch.
then i have a UIView that is overlaid on the plot and tracks the scatter plot touches and displays details of the point being touched.
if you just want to display a line, adding a bar graph is probably the easiest, then you don't have to worry about plot space coordinates vs superview coordinates.
the bar graph data source is only returning a value for the location the user is touching, with a height to match the size of the scatter plot.
the quick version is you can use handlePlotTouchEventInSpace:atPoint:isNewEvent to track the user's touches on the graph.
from there you can use the plotPoint:forPlotAreaViewPoint method on the plot space to get the coordinates of the touch.
something like this is a good starting point. it's a bit of a journey to get it all working, but its not too bad once you get the puzzle started.
-(void)handlePlotTouchEventInSpace:(CPTPlotSpace *)space atPoint:(CGPoint)point isNewEvent:(BOOL)newEvent {
NSDecimal plotPoint[2];
CPTXYPlotSpace *xySpace = (CPTXYPlotSpace *)space;
[xySpace plotPoint:plotPoint forPlotAreaViewPoint:point];
after that plotPoint will contain the x and y location of the touch inside the plot space.

How can I draw a point at my ImagevView's anchorpoint?

I am trying to achieve some effect using imageViews and I need to set the anchorpoint correctly. It is very hard without it being visible.
How would you go about showing it up on the imageview ?
The anchor point is a property specified on the layer (you will need QuartCore to access it). It is specified in the unit coordinate space of the device (both x and y goes from 0 to 1 within the bounds of the layer. You can know the coordinate of the actor point by multiplying the x value with the width and the y value with the height. To draw a point at that location you could just add a new, small layer (bounds 4x4 and corner radius 4 (to get a circle))
Be aware that changing the anchor point will change where the layer (and the view) appears on screen as the frame is calculated relative to the anchor point. To have the frame appear in the same place after the anchor point has been set you could re-set the frame (this will update the layers position so that the frame is what you expect it to be)

Resources