def __init__(self): Object.__init__(self) self.handler.is_line = True self.start_point = Point() self.end_point = Point() self.line_width = 2
def __init__(self): Rectangle.__init__(self) self.handler = Handler() self.pivot = Point() self.offset = Point() self.is_selected = False self.is_resizing = False self.direction = NONE self.z_index = 0 self.fill_color = Color(0.25, 0.25, 0.25, 1.0) self.stroke_color = Color(1, 1, 1, 1) self.stroke_width = 0
def initialize_controls(self): self.handler.set_controls(north_west=Point(self.x, self.y), north_east=Point(self.x + self.width, self.y), south_west=Point(self.x, self.y + self.height), south_east=Point(self.x + self.width, self.y + self.height), north=Point(self.x + abs(self.width / 2), self.y), south=Point(self.x + abs(self.width / 2), self.y + self.height), west=Point(self.x, self.y + abs(self.height / 2)), east=Point(self.x + self.width, self.y + abs(self.height / 2)))
def motion(self, widget, event): self.disconnect(self.motion_id) x = event.x / self.zoom y = event.y / self.zoom direction = self.document.get_direction_for_child_at_post(x, y) # Selection rectangle properties based on mouse motion if self.selection.is_active: self.selection.width = x - self.selection.x self.selection.height = y - self.selection.y self.should_update = False self.update_canvas() # Handle selected children elif event.state & Gdk.ModifierType.BUTTON1_MASK: for selected_children in self.document.get_current_page( ).get_children(): if selected_children.is_selected: # New position to perform operation on target = Point() if selected_children.is_resizing: # Get nearest point to resize target.x = self.grid.get_nearest_axis(x) target.y = self.grid.get_nearest_axis(y) # If has control direction, resize otherwise transform if direction < ANONYMOUS: # Resize child selected_children.resize(target.x, target.y) else: selected_children.transform(target.x, target.y) else: # Get nearest point to move target.x = self.grid.get_nearest_axis( x - selected_children.offset.x) target.y = self.grid.get_nearest_axis( y - selected_children.offset.y) # Move child selected_children.move_position(target.x, target.y) # Update on every resize self.update_canvas() self.motion_id = self.connect("motion-notify-event", self.motion) return True
def resize(self, new_x, new_y): # Deselect all control selection self.handler.deselect_all_controls() point = Point() point.x = self.x point.y = self.y size = Size() size.width = self.width size.height = self.height # Get current vertical or horizontal direction direction = get_direction(self.direction) if direction is not VERTICAL: size.width = new_x - self.pivot.x if size.width < 0: point.x = new_x else: point.x = self.pivot.x if direction is not HORIZONTAL: size.height = new_y - self.pivot.y if size.height < 0: point.y = new_y else: point.y = self.pivot.y # Active control. control = self.handler.controls[self.direction] control.is_active = True self.set_point(point) self.set_size(size)
def initialize_controls(self): self.handler.set_controls(north_west=Point(self.start_point.x, self.start_point.y), south_east=Point(self.end_point.x, self.end_point.y))
def __init__(self): Point.__init__(self)