I have a window with an image as my user interface and I'm trying to see between what coordinates the buttons that I drew on that image are defined. I need those for the following condition:
if (mouseX0>a && mouseX0<b && mouseY0>c && mouseY0<d
&& event.window.windowID == user_interface)
I do not know at the moment between which coordinates are the buttons. I found out there is a function that could get the coordinates of a pixel I would click in my window and I could print that then use it in my code. I want to click on each corners of the buttons so I could have the a, b, c, d values.
The information you need is stored in SDL_MouseButtonEvent event structure (the x and y values obviously) . Just check the mouse events in your event loop as you click. See SDL_Event for example code on event processing and filtering.
Also if you have a static image for your UI, you just can measure that info in any graphics editor, just lookup coordinates under your cursor, which is basic functionality in most apps.
Related
I have a single image that is displayed inside a scrollRect.. pivot is centered and the user is able to scale the image up and down using a slider.. then he/she is able to scroll drag the image around (with the scrollRect functionality) like for example a page in a book-app.. but when the user scales the image up and drags it around and then scales it back down again, the page shrinks at its own pivot point and sometimes gaps are visible on the sides depending on where the user has dragged the image.. When you start to drag the image again it snaps to the correct location but it doesn't look very polished when you force a user to "nudge" something before it snaps into place..
does anybody know of a way to invoke the "nudge" after scaling? Or force the ScrollRect to calculate the position of the image after scaling? I tried using math and pivot points but since the position alters with both scaling and dragging I can't hardcode a value to change pivot points (like f.e. if x < -50 and y < -50 then the pivot point should be top right) ..
The simplest solution would be to invoke that little nudge the user has to do now but I don't know how I have to go about doing it (just changing the transform.positon.x in code doesn't work, the scrollRect needs to update its content) or maybe I could reset the position of the anchor so it stays at the center of the parent..
I tried to clarify with some images:
https://ibb.co/f7Oxk6
I have an issue on triggering mouse event on a svg.
I am using the library d3.js to handle some graphic tasks. Specifically, when I manually click on a position on the svg, d3 draws a red or blue (depending on the path I am clicking on) circle on it and then returns the d3.mouse coordinates of the click.
Now, suppose I have a set of coordinates and want to trigger programmatically click on the corresponding point on the svg, so that it draws a red or blue circle automatically. How can I achieve that?
I read many solutions here but none allows to click on specific coordinates (while I can easily click on a specific path, for example).
My ideal function would be:
var svgd3 = d3.select('svg#id_svg')
function d3click(x,y,svgd3){
//does the click on [x,y, x,y are relative coord. depending only svg viewBox
...
}
Any idea?
Thanks a lot!
I want to position a button at place having certain pixels distance from left and top. I have the exact position in pixels of where to place the button. But, how can I do so?
Try Absolute layout
https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/absolute-layout/
Another option is create view renderer which implement this funcionality in native part.
I was able to get the information about the image first(width and height), and next, I want to get the coordinate about certain point on the image and record the information by a mouse click. How can I do that? I am using Qt.
Thanks !
1 - map the click coordinates to the image coordinates, that will give you the position you clicked on the image.
2 - after that you can use QImage::pixel(x,y) to get the RGB value for the pixel at that coordinate.
Here is what exactly I am trying to do.
I have an image with square elements inside it. When i click on top left and bottom right corners of those elements they are surrounded with divs with border. I then have functions to drag and resize those divs(once they are created by two clicks). I want to be able to record the resized coordinates of those divs in text boxes. For example if the image is with height=700 and width=500. Then if i create a square div inside it with coordinates top left(x=190,y=150) and bottom right(x=290,y=250). Then if i drag this div around the image i want those coordinates to change accordingly. Same thing to happen if i resize it.
Here i have added the code in a web site. laughter.free.bg/imagemapping/Img1.html What you need to do is click on top left and bottom right corners of one of the snack packs. Then you`ll see a box on the right with the coordinates of this Green bordered div. I want those coordinates to change when i drag or resize this div. You can see the code in the source of the page.
Thanks a lot in advance.
It is possible to bind functions to the resize event through jQuery.
For example, ur kiroid has a class of ui-resizable. You could use something like:
$('.ui-resizable').resize(function() {
// refresh your coords here from $('kiroid').css maby?
})