I am currently exploring my options for drawing (javafx) limited 2D (N x N) grid where crossing are clickable elements.
Example: (red rectangles are example of clickable areas - meaning area is bound to particular intersection, all crossings should be such rectangle).
Requirements:
Grid is resizable (x/y scale is preserved).
"Crossings" can receive mouse events.
As of now it's either make GridPane that will hold rectangles that receive events. Each rectangle would have background drawing corresponding to its position in grid (so rectangles on border have different background).
Other things I've considered is making transparent rectangles placed on GridPane that itself draws background.
Now my question here is - what would be best/proper way of doing such thing. What tools can be useful to me?
Related
Double pytha = (Math.pow(e.getX() - circ.getCenterX(),2) + Math.pow(e.getY() - circ.getCenterY(),2));
Double pythaSqr = Math.sqrt(pytha);
circ.setRadius(pythaSqr);
gc.strokeOval(circ.getCenterX()-circ.getRadius(), circ.getCenterY()-circ.getRadius(), circ.getRadius(), circ.getRadius());
This is part of my paint program code and I can not get the oval to draw from the circle center, it alway uses my mouse click as its borders. I am trying to click on the screen and from the should the circle borders grow accoring to the radius in all directins equally. Hope you understand my questin (here I have done strokeOval(X-r,Y-r,r,r) but the it just grows in -x,y direction and if strokeOval(X,Y,r,r) then it grows in X,-Y dircetion in stead of growin equally to all directions using X,Y as center).
I draw lots of dots on the Swing(Jpanel).
I make that panel zoomable, zoom-in works fine, but I have a problem at zoom-out when it was zoomed-out to the limit, I draw dots per pixel.
I want to zoom-out it more, how can I draw it on Graphics2D
And those dots on the panel are editable(by using a mouse). Since they are drawn less than one pixel, how can I get their actually drawn position?
I can't seem to move a rectangle object in JavaFX. I've placed the rectangle inside of a stackpane, but whenever I change the coordinates of the rectangle, it won't move (even if I change the coordinates of initialization). So,
Rectangle rect = new Rectangle(150,150,75,75);
will be in the center of the stackpane, as well as
Rectangle rect = new Rectangle(2043,136,75,75);
Whenever I use
rect.setX();
The rectangle doesn't move at all. I know I'm missing something really simple, I just can't figure it out. I don't want to use a transition, because my goal is to simply move the rectangle a few pixels in the direction of an arrow key press. So what exactly am I doing wrong?
Solution
Use a different container type (e.g. a Pane) if you want to manually specify layout co-ordinates (e.g. the x,y co-ordinates of a Rectangle).
Background
A StackPane is a managed layout pane - it controls the layout of the items you place in it (by default centering items in the stack). So it doesn't matter what co-ordinates you give the Rectangle, when you place it in the StackPane, the layout manager will move your rectangle so that it is in the center of the stack.
JavaFX has two concepts for positioning, one is layout co-ordinates, the other is translation deltas, which are added to the layout co-ordinates. TranslateTransitions work by modifying translation deltas. Translation is meant for animations and temporarily moving things around. Translation is independent of and does not effect layout values, so you could place something in a StackPane and apply a TranslateTransition to it and it would still move, but it would move from the center of the stack, as that is the initial layout position.
I'm working in a simple game for desktop and Android using LibGDX framework. The game spawn some balls that move from one side of the screen to the opposite one. I want to show white circles over a black background but I also want to draw some white texts. My problem with this is that I want to draw the intersection between balls and between balls and text in black. I want something like this:
Other of my problems is that I'm using ShapeRenderer to draw the circles and they are too pixelated.
What is the best way to render circles in libGDX (Ill have to render between 1 and 100). Is it possible to get the effect shown in the image?
Let's say that I have drawn a square on the screen using the following code:
I want that if the user clicks on the shape, a border with four small boxes (north, south, east and west) is drawn on the shape. Hovering on any of the small boxes changes the cursor to the resize cursor and, if the user drags the small box to a new location, the shape is resized.
How can this be done please?
Instead of using drawRect() method create Shape object for the rectangle and draw the Shape. For Shape you can use getBounds() to get main rectangle. Use the bounds to find the small boxes rectangles (also Shapes).
When mouse is moved (or dragged) check whether one of the boxes shapes contains the mouse event coordinates.
On drag you can change original Shape using AffineTransfrorm.