javafx 8 - Add a decorative area around a node, that behaves like an Effect -
for card game, i'm writing, created custom "control" represents card. can flipped, dragged around, selected, , scaled, translated , forth during course of game.
one core feature of card is can "highlighted" in different ways. basic form of highlighting showing glowing border (animated) around card.
i started javafx effects here (dropshadow animated spread/radius) turned away this, because performance turned out bad.
so, replaced effect animated imageview "behind" card (basic sprite animation sprite sheet pre-rendered glow animation). solves performance issue, introduced numerous other problems i'm trying tackle...
since, don't want "anchor point" top-left corner of glow around card top-left corner of card itself, tried offset imageview within card node -x/-y.
(different highlights can "expand" node different amounts, should not affect location of node, , when setting location of node should not have care potentially differing highlight offsets or highlights @ all.)
at first looked good, still affects bounds of whole node. instance, if add mouse event listener node, fires when clicking in "glow" area, though set imageview mouse transparent. have create "proxy" methods event methods on custom node , forward them "inner" card node. of course possible - frankly not solution hope find.
the current card node has following structure:
public class card extends pane { // view contain border glow (blue area in image below) private imageview effectview; // stand-in rest of card stuff (image etc) private rectangle placeholderforcardcontent; public card() { effectview = new imageview(); effectview.setmousetransparent(true); placeholderforcardcontent = new rectangle(); getchildren().addall(effectview, placeholderforcardcontent); } @override protected void layoutchildren() { // offsets defined current highlight effectview.setlayoutx(-50); effectview.setlayouty(-50); effectview.setfitwidth(getwidth() + 100); effectview.setfitheight(getheight() + 100); placeholderforcardcontent.setlayoutx(0); placeholderforcardcontent.setlayouty(0); placeholderforcardcontent.setwidth(getwidth()); placeholderforcardcontent.setheight(getheight()); } }
example: new card().setonmouseclick() , should affect area equal placeholderforcardcontent, not extend effectview. simply, should behave effect of node...
the following image shows try build:
how done in javafx? can done?
setmousetransparent(true)
works effectview
.
however, parent's bounds (pane
) still include effectview
, generate mouse event. , since pickonbounds
regions
set true
default (which thing missed, since general default, according java doc, false
) need set false
.
then works.
Comments
Post a Comment