GUI shapes border checking (FLOWCHART CONNECTOR) - user-interface

So I'm working on a Flowchart (OOP) Program, and I have to implement a code for Connector, which has the condition that it must be between 2 other shapes.
So the question here is how to check if the user click is within a "shape" area ?
Like I can "GetMouseClick" as a function, but I need to check if this point lies in a shape from the shapes drawn.
NOTE : Each shape has a class !

For each class (shape) define a getBounds(...) method that will return the rectangle (or a polygon) and when you click you can iterate over all shapes and see within what bounds the click was.
Another idea is to add mouse listener for each shape and rely on event handler to tell you what shape was clicked.

Related

How to webgl detach transform control when click another range not transform control

I'm developing webgl graphics with three.js
While I developing, I'm facing something stuck.
I'm trying to detach transform control when I click another range(ex, grid or another objects) not transform control.
I implemented it by checking clicked position.
For example, I set event handler with mouse down and in there, I store that mouse position. Also I set event handler with mouse up and in there, I compare mouse positions both mouse down and mouse up. If two positions are same, I detach the transform controller. However with this implementation, transform controller was disappeared though I clicked transform controller.
I just wanna detach transform control when I click another position not transform control
Does anyone help me please with this issue?
Thank you in advance.

How to select a shape in a subscene to allow me to make transformations

I currently am working on a program in javafx that asks the user for radius and height of a cylinder and once the user hits add, it creates a cylinder in the subscene. I was wondering how I can combine the setonmouseclicked event handler with the cylinder so that way I can choose that one cylinder and make edits like scaling it, rotating it, etc. and then i can go to the next shape and click on that one and then i can do stuff like scale, rotate, etc to the next one. Currently this is what happens when i ask a user and they add the cylinder.
Button addCyl=new Button("Add Cylinder");
addCyl.setOnAction(event -> {
String cylRadius=cylRadiusInput.getText();
String cylHeight=cylHeightInput.getText();
Double Radius=Double.parseDouble(cylRadius);
Double Height=Double.parseDouble(cylHeight);
Cylinder cylinder=new Cylinder(Radius, Height);
shapeGroup.getChildren().add(cylinder);
});
How to pick a node
"how do i differentiate between which cylinder im clicking on so i can make changes to that specific one?"
You don't, the JavaFX node picking implementation will do that for you. When you set a click handler on an object, it will be invoked when the object is clicked on, so when it is invoked, you know that the user has clicked on the object.
How to save a selection
When you create the shape, create a click handler for it, and, when the node is clicked, set a field for the selected node.
private Group shapeGroup = new Group():
private Cylinder selectedNode;
// omitted ... add shapeGroup to sub-scene
private void addNode() {
Cylinder cylinder = new Cylinder(radius, height);
cylinder.setOnMouseClicked(e -> {
selectedNode = cylinder;
});
shapeGroup.getChildren().add(cylinder);
}
How to modify a selected item
To define what happens you want to take an action on the selected node, say change the radius, then you can do something like below:
private Slider radius = new Slider(10, 100, 20);
// omitted ... add radius control to scene
radius.valueProperty().addListener(
(observable, oldValue, newValue) -> {
if (selectedNode != null) {
selectedNode.setRadius(newValue);
}
}
);
How to set values from a selected node to your controls
If you wish, when a node is selected, you can set the value of your controls to the current value for the selected node, e.g.
cylinder.setOnMouseClicked(e -> {
selectedNode = cylinder;
radius.setValue(selectedNode.getRadius());
});
Sample node selection app
An example of the concepts discussed here is demoed in the following sample app:
JavaFX application demoing placing text in adjustable boxes.
Even though the demo example is in 2D, the concepts for node selection and subsequent modification of item properties by controls are no different for 2D and 3D.
How to handle multiple selections
If you wish to add multiple selection where multiple nodes may be selected at once, then it is a bit more complex. You can use some of the concepts defined in the answers below (linked question is for 2D, but 3D isn't really different in this regards).
How to implement selection of Nodes in JavaFX
What to do about depth sorting and obscured nodes
Because it is 3D, the objects can have z-depth, and are subject to depth sorting. If one object is behind another object, to allow the obscured object to be selected by mouse, you will need to have a mechanism to allow the user to move the obscuring objects out of the way (e.g. by selecting and dragging them to move them), or to rotate the scene to another viewpoint where the object the user wishes to click is no longer obscured (info on how to accomplish these kind of things is out of scope for this answer).
Getting detailed pick info
If you needed more info about the thing being picked, e.g. the point (in 3D space) on the node which was picked, or what face or texture co-ordinate of the node was picked then you can use the pickResult API. A tutorial for this is provided:
https://docs.oracle.com/javase/8/javafx/graphics-tutorial/picking.htm
However, for your purposes, a simple click handler for the node which does not query the pick result is all that is really needed.

How to hide outer bounded parent rectangle in GEF figure

I am trying to create a circle or an ellipse in GEF framework. We are setting constraints/bounds as a rectangle within which the circle/ellipse sits.
My problem is that I am not able to hide/suppress outer Rectangle when I do drag drop or I just click on the circle. Is there any way we can remove this outer Rectangle ? any tip idea would help. thanks
This rectangle is created by the NonResizableEditPolicy (or ResizableEditPolicy if your figure is resizable). This policy is added automatically to children of some layout policies, for example children of ConstrainedLayoutEditPolicy. What you need to do is find which layout policy you are using in your container, and override it to use a different edit policy to decorate the children of the container. This can be done by overriding the NonResizableEditPolicy (or ResizableEditPolicy) and then modify how this policy provides feedback when the Figure is selected, clicked on, etc.

Allow clicks to pass through transparent parts of NSButton

I have an NSButton that contains a triangular image. I don't want a click on the button to be detected unless the user clicks on the triangle itself. Clicks on the transparent outside area should be passed through to the view underneath.
Is this possible?
It's easier if the triangle is an NSBezierPath or CGPath.
There are methods and functions to test if a point is inside a path.

Invalidate() command is not repainting the control

I am trying to develop a custom control which needs to have some rectangles to be drawn. Now, 1 rectangle needs to be moved so I used overrided mousemove method to get the new location and change the location part of that rectangle and then used Invalidate() command. But problem is, that whole control is painted instead of that rectangle. It is disaapearing. If someone can point out where I am doing wrong, that would be a great help. Thanks.
You can use partial invalidate using Invallidate() overloads. pass a rectangle as a parameter to Invalidate() or you can pass 4 number to do it.
Invalidate(new Rectangle(left, top, width, height));
of course you must invalidate rectangle's old place and new place.

Resources