https://kotlinlang.org logo
#korge
Title
# korge
r

Rachid

07/03/2020, 8:46 AM
Related to my previous question. Any idea why when I draw a circle with filling the
onClick
and
onOver
doesn't work?
Copy code
// clicking DOES work
	val cicleStroke = graphics {
		stroke(
			ColorPaint(Colors.RED),
			Context2d.StrokeInfo(thickness = 1.0)
		) {
			circle(0.0, 0.0, 40.0)
		}
	}.xy(100.0, 100.0)
	cicleStroke.onClick {
		println("Clicked cicleStroke")
	}
Copy code
// clicking does NOT work
	val circleFilled = graphics {
		fillStroke(
			ColorPaint(Colors.LAWNGREEN),
			ColorPaint(Colors.BLACK),
			Context2d.StrokeInfo(thickness = 1.0 )
		) {
			circle(0.0, 0.0, 30.0)
		}
	}.xy(200.0, 100.0)
	circleFilled.onClick {
		println("Clicked circleFilled")
	}
n

Nico

07/03/2020, 9:14 AM
Might be a bug .
beginFillStroke
does not return
Graphics
.
😱 1
d

Deactivated User

07/03/2020, 9:19 AM
Maybe we should inject the Graphics instance in the lambda, right?
n

Nico

07/03/2020, 9:20 AM
I dont know what the
dirty
flag is doing but the
dirty
function returns
Graphics
on all the other drawing calls. Its only missing here
r

Rachid

07/03/2020, 9:21 AM
Do you know if/how I can workaround this by forexample something like overriding the
beginFillStroke
in my example?
Also for a first quick test if that will fix it
d

Deactivated User

07/03/2020, 9:22 AM
Maybe it is a 🪲 (the dirty part)
n

Nico

07/03/2020, 9:23 AM
I dont know if there is a quick workaround with extension functions because there are private properties involved.
d

Deactivated User

07/03/2020, 9:23 AM
looks like it, but it is initially dirty, it shouldn't be a problem. BTW dirty is just to let the rendering to know that something has changed and needs to be recomputed
r

Rachid

07/03/2020, 9:32 AM
Any other tip how I can draw a circle and adding onClick functionality for now?
n

Nico

07/03/2020, 9:33 AM
a regular circle?
Copy code
val circle = circle().onClick { println("I am a circle") }
r

Rachid

07/03/2020, 9:48 AM
Check, that's how I started by I moved to the graphics/VectorBuilder because I wanted a circle with a border.
Maybe more common to create sprites for this, instead of drawing it in code...
4 Views