def _draw_container_mainlayer(self, gc, view_bounds, mode="default"): with gc: gc.set_fill_color((1.0, 1.0, 1.0, 1.0)) gc.set_stroke_color((1.0, 1.0, 1.0, 1.0)) gc.rect(self.x, self.y, self.width, self.height) gc.fill_path() if view_bounds: v = view_bounds new_bounds = (v[0] - self.x, v[1] - self.y, v[2], v[3]) else: new_bounds = None with gc: gc.translate_ctm(*self.position) gc.set_stroke_color((0.0, 0.0, 0.0, 1.0)) for component in self._components: # See if the component is visible: tmp = intersect_bounds(component.position + component.bounds, new_bounds) if tmp == empty_rectangle: print("skipping component:", component.__class__.__name__, end=' ') print("\tbounds:", component.position, component.bounds) continue with gc: component.draw(gc, new_bounds, mode)
def _draw_container_mainlayer(self, gc, view_bounds, mode="default"): with gc: gc.set_fill_color((1.0, 1.0, 1.0, 1.0)) gc.set_stroke_color((1.0, 1.0, 1.0, 1.0)) gc.rect(self.x, self.y, self.width, self.height) gc.fill_path() if view_bounds: v = view_bounds new_bounds = (v[0]-self.x, v[1]-self.y, v[2], v[3]) else: new_bounds = None with gc: gc.translate_ctm(*self.position) gc.set_stroke_color((0.0, 0.0, 0.0, 1.0)) for component in self._components: # See if the component is visible: tmp = intersect_bounds(component.position + component.bounds, new_bounds) if tmp == empty_rectangle: print "skipping component:", component.__class__.__name__, print "\tbounds:", component.position, component.bounds continue with gc: component.draw(gc, new_bounds, mode)
def _draw_mainlayer(self, gc, view_bounds=None, mode="normal"): # For now, ViewPort ignores the view_bounds that are passed in... # Long term, it should be intersected with the view_position to # compute a new view_bounds to pass in to our component. if self.component is not None: x, y = self.position view_x, view_y = self.view_position with gc: # Clip in the viewport's space (screen space). This ensures # that the half-pixel offsets we us are actually screen pixels, # and it's easier/more accurate than transforming the clip # rectangle down into the component's space (especially if zoom # is involved). gc.clip_to_rect(x-0.5, y-0.5, self.width+1, self.height+1) # There is a two-step transformation from the viewport's # "outer" coordinates into the coordinates space of the viewed # component: scaling, followed by a translation. if self.enable_zoom: if self.zoom != 0: gc.scale_ctm(self.zoom, self.zoom) gc.translate_ctm(x/self.zoom - view_x, y/self.zoom - view_y) else: raise RuntimeError("Viewport zoomed out too far.") else: gc.translate_ctm(x - view_x, y - view_y) # Now transform the passed-in view_bounds; this is not the # same thing as self.view_bounds! if view_bounds: # Find the intersection rectangle of the viewport with the # view_bounds, and transform this into the component's # space. clipped_view = intersect_bounds( self.position + self.bounds, view_bounds) if clipped_view != empty_rectangle: # clipped_view and self.position are in the space of # our parent container. we know that # self.position -> view_x,view_y in the coordinate # space of our component. So, find the vector from # self.position to clipped_view, then add this to # view_x and view_y to generate the transformed # coordinates of clipped_view in our component's space. offset = array(clipped_view[:2]) - array(self.position) new_bounds = ((offset[0]/self.zoom + view_x), (offset[1]/self.zoom + view_y), clipped_view[2] / self.zoom, clipped_view[3] / self.zoom) # FIXME This is a bit hacky - i should pass in the # zoom level to the draw function self.component._zoom_level = self.zoom_level self.component.draw(gc, new_bounds, mode=mode) return
def _draw_mainlayer(self, gc, view_bounds=None, mode="normal"): # For now, ViewPort ignores the view_bounds that are passed in... # Long term, it should be intersected with the view_position to # compute a new view_bounds to pass in to our component. if self.component is not None: x, y = self.position view_x, view_y = self.view_position with gc: # Clip in the viewport's space (screen space). This ensures # that the half-pixel offsets we us are actually screen pixels, # and it's easier/more accurate than transforming the clip # rectangle down into the component's space (especially if zoom # is involved). gc.clip_to_rect(x-0.5, y-0.5, self.width+1, self.height+1) # There is a two-step transformation from the viewport's "outer" # coordinates into the coordinates space of the viewed component: # scaling, followed by a translation. if self.enable_zoom: if self.zoom != 0: gc.scale_ctm(self.zoom, self.zoom) gc.translate_ctm(x/self.zoom - view_x, y/self.zoom - view_y) else: raise RuntimeError("Viewport zoomed out too far.") else: gc.translate_ctm(x - view_x, y - view_y) # Now transform the passed-in view_bounds; this is not the same thing as # self.view_bounds! if view_bounds: # Find the intersection rectangle of the viewport with the view_bounds, # and transform this into the component's space. clipped_view = intersect_bounds(self.position + self.bounds, view_bounds) if clipped_view != empty_rectangle: # clipped_view and self.position are in the space of our parent # container. we know that self.position -> view_x,view_y # in the coordinate space of our component. So, find the # vector from self.position to clipped_view, then add this to # view_x and view_y to generate the transformed coordinates # of clipped_view in our component's space. offset = array(clipped_view[:2]) - array(self.position) new_bounds = ((offset[0]/self.zoom + view_x), (offset[1]/self.zoom + view_y), clipped_view[2] / self.zoom, clipped_view[3] / self.zoom) # FIXME This is a bit hacky - i should pass in the zoom level # to the draw function self.component._zoom_level = self.zoom_level self.component.draw(gc, new_bounds, mode=mode) return