JXBrowser - What is globalX, globalY, windowX, windowY in relation to x, y for forwarding mouse events? - jxbrowser

I can find no explanation on what these are actually supposed to do.
There are examples on:
https://jxbrowser.support.teamdev.com/support/solutions/articles/9000102480-forwarding-mouse-events
but 629 and 373 ? I can't figure out what those values are for. I can get the same behaviour with any value for those.
What if you one also sets windowX and windowY ?
What would they do to the result click?
I am looking to be able to click and move on a google map. Is that possible?

The x and y values define the mouse event coordinate inside the browser content area.
The globalX and globalY values define the screen coordinate of the mouse event.
The windowX and windowY are deprecated. If you set them, this doesn't affect anything.
For more detailed information about working with Google Maps, please take a look at the article.

Your browserView must be active/focused first!
Then, let's do this way:
public static void simulateMouseClickOnElement(Browser browser, BrowserView browserView, DOMElement element){
Rectangle rect = element.getBoundingClientRect();
Point ptOnScreen = new Point(rect.x , rect.y );
SwingUtilities.convertPointToScreen(ptOnScreen, browserView);
forwardMouseClickEvent(browser,MouseButtonType.PRIMARY,rect.x,rect.y, ptOnScreen.x, ptOnScreen.y);
}
JxBrowser is the BEST automation or crawling/hacking tool! Selenium is a best alternative choice due to the TCO.

Related

Javafx How to undo shape drawings on another shape

I am implement a screenshot app with javafx, like lightshot. I am done with almost all the functionalities, but I am now stuck at the undo operation. I am adding the free draw, line arrows, rectangles etc on a rectangle like this :
selection.setCursor(Cursor.CROSSHAIR);
Arrow arrow = new Arrow();
selection.setOnMousePressed((evt) -> {
rootPane.getChildren().remove(arrow);
arrow.setStartX(evt.getX());
arrow.setStartY(evt.getY());
arrow.setEndX(evt.getX());
arrow.setEndY(evt.getY());
arrow.setStyle("-fx-background-color:red");
rootPane.getChildren().add(arrow);
});
selection.setOnMouseDragged((evt) -> {
arrow.setEndX(evt.getX());
arrow.setEndY(evt.getY());
});
selection.setOnMouseReleased((evt) -> {
arrow.setEndX(evt.getX());
arrow.setEndY(evt.getY());
});
drawtype = "arrow";
});
Selection is the rectangle that I have drawn, this is an example of how I am adding the arrow. I have tried researching online but I cant seem to get something to point me in the right direction, anyone who can help out here please? Remember, I am not using Canvas or GraphicsContext.
If you want to be able to undo the actions, you need to store the state of your 'drawing'.
In your case undoing the creation of your Arrow element, would be simple rootPane.getChildren().remove(arrow);
You just need to create a Data Structure where you store all actions done by the user (or at least a few). And each action can get reversed.
Example:
ActionType.Add -> action: getChildren().add(xyz) -> reverse: getChildren().remove(xyz)
ActionType.Move -> arrow.setEndX(evt.getX()) -> arrow.setEndX(oldX)
Each action should contain all information needed to reverse it. (The node involved, what was done and how it was before)

Enemies Overlapping in Game Maker: Studio, How Do I Fix This?

The AI of my enemies that I made for my game is simple. They just follow the player (more precisely, they look in the direction of the player and go forward)
Step Event:
if (instance_exists(obj_player)){
direction = point_direction(x,y,obj_player.x,obj_player.y);
}
speed = spd;
But they keep on overlapping each other and go on top of the player. I've tried researching but all the forums said was to use place_free() and xprevious & yprevious, but I have no idea how to use them. How do I fix this?
Thanks :)
You can read about this on the gamemaker documentation : https://docs.yoyogames.com/source/dadiospice/002_reference/movement%20and%20collisions/collisions/place_free.html
basically, what you want to do is avoid moving your instance if that means causing a collision. x_previous and y_previous will be used to cancel the move by going back to the previous position.
But I think it's better to check the place before moving, so I would add at the end of you script :
if (place_free(x+hspeed, y+vspeed)) speed = spd;
else speed = 0;
that way, the ennemy will stop instead of stepping above an other instance.
A little upgrade would be the following : if there is a collision detected, check if you can move along a single axis instead (x or y) and do it.

Client doesn't have a name/class at startup

I'm trying to start an application (Spotify) on a particular tag. Rules aren't applied and now I'm inspecting the client class by printing the class in a notification in the "manage" signal. This results in an empty notification.
client.connect_signal("manage", function (c, startup)
naughty.notify({title=c.class})
end)
When I restart awesome, it does print the client class, so why isn't it working when the client is initially started?
Using xprop, it also prints the class:
WM_CLASS(STRING) = "spotify", "Spotify"
Sounds like a bug in Spotify (and I think I heard about this one before). I would guess that Spotify does not follow ICCCM and only sets its WM_CLASS property after it made its window visible and not before.
I fear that you cannot do much about this except for complaining to Spotify devs to fix their stuff.
You could work around this by starting a timer in the manage signal that checks if a window turns out to be spotify a short time later. Alternatively, you could do something like client.connect_signal("property::class", function(c) if c.class == "Spotify" then print("This is now a spotify window") end end) to react to change to a window's class (of course you'd want to do something more useful to Spotify's windows than printing them).
(Per the ICCCM, a window is not allowed to change its class while it is visible, but who cares about standards...)
I had a similar issue with the claws-mail client. Inspecting it via xprop, it shows
WM_CLASS(STRING) = "claws-mail", "Claws-mail"
but awesome just did’t apply the rules for it. The trick was giving awesome-wm both of these class names in the rules section by providing a set of characters to chose from:
rule = {class = "[Cc]laws%-mail"}
I hope this works for your spotify application, too.
For further reading about patterns in lua I suggest this:
https://www.lua.org/pil/20.2.html

Google map how to display a dragable marker based on coordinates and return new coordinates

I have to write a script for Google Maps V3 which will do the following:
Place a marker on a map based on a set of coordinates and possbibly change the address after the page has been loaded
Allow the user the drag the mark to replace it elsewhere
Collect the new coordinates once the marker has been moved.
The first part is basic enough and should be fine, changing the address after the page is loaded should only be a matter of calling back the same function?
I am not sure where to start on the draggable marker and collecting hew coordinates.
Would anyone know of scripts / API's or where in the doc should I start?
Have you checked the Google Maps Javascript API V3 Reference to see whether the google.maps.Marker class has :
a draggable option
an dragend event
a getPosition method
Hint: The answer might just be "yes" to all three, and you don't need much else to solve your problem.

audio playback in c4 framework (c4iOS

new user to c4iOS framework. Working my way thru the tutorials/examples - wondering how one goes about playing back audio (as opposed to video, which is covered in the example texts).
thanks in advance for answering my less-than-advance 'n00b' question
-jf
Audio samples are fairly similar to movie objects, albeit they don't have an option like shouldAutoplay that will get them running as soon as the application loads.
The easiest way to construct a sample is like this:
#implementation C4WorkSpace {
C4Sample *audioSample;
}
-(void)setup {
audioSample = [C4Sample sampleNamed:#"C4Loop.aif"];
}
Which builds the audio sample object as a variable that you can then reference in other methods. For instance, if you want to play a sound clip when you first touch the screen you would do the following:
-(void)touchesBegan {
[audioSample play];
}
To toggle the playback for each touch, you would do something like:
-(void)touchesBegan {
if(audioSample.isPlaying) {
[audioSample stop];
} else {
[audioSample play];
}
}
A working copy of a C4 app that toggles playback can be found HERE.
There are also a lot of properties for audio samples that let you control things like playback rate, volume, panning and so on.
An example of changing the volume is like this:
audioSample.volume = 0.5; //0 = mute, 1 = full volume
An example of skipping to a specific time in a sample would be like:
audioSample.currentTime = 1.0f; //this will put the "playhead" to 1.0 second
You can have a look at the C4Sample documentation to see more properties and other aspects of the class. The documentation is also available via the Xcode organizer.

Resources