java - Custom collision shape for Buttons in JavaFX -


creating custom button shape done, how possible make sure new shape "collision box" of button itself?

in case created 2 hexagnol shaped buttons , aligned them properly. problem collision box of buttons still rectangular , when move mouse upper button lower 1 notice collision box strictly rectangular , makes custom shapes kind of useless.

any way create custom collision shapes or collision checks?

full working example:

import javafx.application.application; import javafx.scene.scene; import javafx.scene.control.button; import javafx.scene.layout.pane; import javafx.scene.shape.polygon; import javafx.stage.stage;  public class test extends application {     public static void main(string[] args) {         launch(args);     }      @override     public void start(stage primarystage) throws exception {         pane apane = new pane();         apane.setprefwidth(100);         apane.setprefheight(100);          apane.getchildren().add(createhexat(10, 10));         apane.getchildren().add(createhexat(35, 45));          scene ascene = new scene(apane);          primarystage.setscene(ascene);         primarystage.show();     }      private button createhexat(double xpos, double ypos) {         button abutton = new button();         abutton.setlayoutx(xpos);         abutton.setlayouty(ypos);         abutton.setprefwidth(50);         abutton.setprefheight(50);         double[] path = new double[12];         (int q = 0; q < 6; q++) {             double x = math.cos(math.pi / 3.0 * q + math.pi / 2.0);             double y = math.sin(math.pi / 3.0 * q + math.pi / 2.0);             path[q * 2] = x;             path[q * 2 + 1] = y;         }         polygon apoly = new polygon(path);         abutton.setshape(apoly);         return abutton;     } } 

call

abutton.setpickonbounds(false); 

this instructs javafx consider mouse being on button if on non-transparent pixel, instead of default (which mouse coordinates intersect rectangular bounds of button).


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -