Here is some code I'm using to create a rectangle on a control node to select its texture button children
func recy(event): # Rectangle draw test
if(event.type == InputEvent.MOUSE_BUTTON):
if(event.button_index==1):
if(event.is_pressed()):
from = event.pos
to = event.pos
multi_select=true
else:
multi_select=false # done remove rect
update() # draw call without rect
elif(event.type == InputEvent.MOUSE_MOTION):
if(multi_select):
to = event.pos # update position and
update() # draw
# draw and select here
func _draw():
if(multi_select):
var tl = Vector2(min(to.x,from.x),min(to.y,from.y))
var br = Vector2(max(to.x,from.x),max(to.y,from.y))
var tr = Vector2(br.x,tl.y)
var bl = Vector2(tl.x,br.y)
var my = Rect2(tl, br-tl )
draw_rect( my, Color(0,1,0,0.2))
draw_line( tl, tr, Color(0,1,0) )
draw_line( tl, bl, Color(0,1,0) )
draw_line( br, tr, Color(0,1,0) )
draw_line( br, bl, Color(0,1,0) )
my.pos=tl+get_global_pos() # the center container prevents me from getting an easy rect so i have to ask the button for its global rect and terfore make my mose rect global aswell
for i in get_node("radar").get_children():
if(i.button):
i.image.set_modulate(global.cl)
if(my.intersects(i.button.get_global_rect() )):
i.image.set_modulate(global.ch)
if(-1==selec_rect_items.find(i)):
selec_rect_items.append(i)
else:
if(-1!=selec_rect_items.find(i)):
selec_rect_items.erase( i )
else:
# for i in get_node("radar").get_children():
# if(i.button):
# pass
for i in selec_rect_items:
i.image.set_modulate(global.cl)
i.set_selected(true)
selec_rect_items.clear()