@@ -412,6 +412,12 @@ def compute_node_position(self, node, scaler: Scaler, offset_x: int, offset_y: i
412412 else :
413413 raise RuntimeError ("unknown type:" , type (node ))
414414
415+ def move_root (self , node , scaler : Scaler , d_x : int , d_y : int ) -> None :
416+ offset_x = self .graphics_info [node ].pos_x + d_x
417+ offset_y = self .graphics_info [node ].pos_y + d_y
418+
419+ self .compute_node_position (node , scaler , offset_x , offset_y )
420+
415421 def on_draw (self ):
416422 if self .should_redraw :
417423 start_time = time .time ()
@@ -431,6 +437,8 @@ def on_draw(self):
431437
432438 def function_call_draw (self , node ):
433439 if node .target is not None :
440+ # FIXME: do this properly
441+ self .compute_function_call_graphics_info (node )
434442 def quad_bezier (t , p0 , p1 , p2 ):
435443 return (1 - t ) ** 2 * p0 + 2 * (1 - t ) * t * p1 + t ** 2 * p2
436444
@@ -530,28 +538,38 @@ def update(self, delta_time):
530538 pass
531539
532540 def on_key_press (self , symbol , modifier ):
533- should_recalculate = False
534541 if symbol == arcade .key .UP :
535- self .global_offset_y -= 50
536- should_recalculate = True
542+ if self .current_selected_node is None :
543+ for i in self .parser .code_tree .roots :
544+ self .move_root (i , self .scaler , 0 , - 50 )
545+ elif self .current_selected_node in self .parser .code_tree .roots :
546+ self .move_root (self .current_selected_node , self .scaler , 0 , 50 )
547+ self .should_redraw = True
537548 elif symbol == arcade .key .DOWN :
538- self .global_offset_y += 50
539- should_recalculate = True
549+ if self .current_selected_node is None :
550+ for i in self .parser .code_tree .roots :
551+ self .move_root (i , self .scaler , 0 , 50 )
552+ elif self .current_selected_node in self .parser .code_tree .roots :
553+ self .move_root (self .current_selected_node , self .scaler , 0 , - 50 )
554+ self .should_redraw = True
540555 elif symbol == arcade .key .RIGHT :
541- self .global_offset_x -= 50
542- should_recalculate = True
556+ if self .current_selected_node is None :
557+ for i in self .parser .code_tree .roots :
558+ self .move_root (i , self .scaler , - 50 , 0 )
559+ elif self .current_selected_node in self .parser .code_tree .roots :
560+ self .move_root (self .current_selected_node , self .scaler , 50 , 0 )
561+ self .should_redraw = True
543562 elif symbol == arcade .key .LEFT :
544- self .global_offset_x += 50
545- should_recalculate = True
563+ if self .current_selected_node is None :
564+ for i in self .parser .code_tree .roots :
565+ self .move_root (i , self .scaler , 50 , 0 )
566+ elif self .current_selected_node in self .parser .code_tree .roots :
567+ self .move_root (self .current_selected_node , self .scaler , - 50 , 0 )
568+ self .should_redraw = True
546569 elif symbol == arcade .key .KEY_0 :
547570 self .scaler .rescale (self .scaler .current_scale * 1.05 )
548- should_recalculate = True
549571 elif symbol == arcade .key .KEY_9 :
550572 self .scaler .rescale (self .scaler .current_scale * 0.95 )
551- should_recalculate = True
552-
553- if should_recalculate :
554- self .on_resize (self .width , self .height )
555573
556574 def on_mouse_press (self , x : float , y : float , button : int , modifiers : int ):
557575 if button == 1 :
0 commit comments