Exemplo n.º 1
0
  def draw(self, context):
    Thing.draw(self, context)

    # draw a bounding box
    #Primitives.bounding_box(context, -0.5, -0.5, 1.0, 1.0)
    
    # set origin to top left
    #context.translate(-0.5 + (self.root_node.width / 2.0), -0.5 + (self.root_node.height / 2.0)) 
    context.translate(-0.5, -0.5) 
    
    if self.cache_drawing_operations:
      # check if rendering cache needs to be refreshed
      if (self.cached_render is None) or (self.cached_scale is not TheWorld.scale):
        self.cached_render = self.__render_cache(context)
        self.cached_scale = TheWorld.scale
  
      # blast cached rendering to screen
      context.save()
      pixel_width, pixel_height = context.user_to_device_distance(self.width, self.height)
      context.scale(1.0 / pixel_width, 1.0 / pixel_height)
      context.set_source_surface(self.cached_render)
      context.paint()
      context.restore()
    
    else:
      # draw connectors first for z-order 
      context.save()
      self.x_offset = 0
      self.y_offset = 0
      self.draw_connectors(context, self.root_node)
      self.x_offset = 0
      self.y_offset = 0
      self.draw_nodes(context, self.root_node)
      context.restore()
Exemplo n.º 2
0
 def draw(self, context):
   Thing.draw(self, context)
   context.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
   context.set_font_size(0.1)
   context.set_source_rgb(0.0, 0.0, 0.0)
   context.move_to(-0.3, 0.02)
   context.show_text(self.target.__name__)
Exemplo n.º 3
0
 def draw(self, context):
   Thing.draw(self, context)
   
   x1 = -TheWorld.unit_range
   y1 = -TheWorld.unit_range
   x2 = TheWorld.unit_range
   y2 = TheWorld.unit_range
   
   # draw button
   context.rectangle(x1, y1, x2 * 2.0, y2 * 2.0)
   self.color(context)
   context.fill()
   
   cx1 = -TheWorld.unit_range / 4.0
   cy1 = y1
   cx2 = TheWorld.unit_range / 4.0
   cy2 = y2 
   
   #context.set_source_rgba(0.9, 0.9, 0.9, 0.5)
   #context.move_to(x1, 0)
   #context.curve_to(cx1, y1, cx2, cy2, TheWorld.unit_range, 0);
   #context.line_to(x2, y1)
   #context.line_to(x1, y1)
   #context.close_path()
   #context.fill()
   
   #context.set_source_rgba(0.7, 0.7, 0.7, 0.5)
   #context.move_to(x1, 0)
   #context.curve_to(cx1, y1, cx2, cy2, TheWorld.unit_range, 0);
   #context.line_to(x2, y2)
   #context.line_to(x1, y2)
   #context.close_path()
   #context.fill()
   
   # border
   context.set_line_width(1.0)
   context.set_source_rgb(0, 0, 0)
   context.rectangle(x1, y1, x2 * 2.0, y2 * 2.0)
   context.stroke()
   
   # draw label
   context.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
   context.set_font_size(70)
   context.set_source_rgb(0.0, 0.0, 0.0)
   context.move_to(-TheWorld.unit_range + 5, TheWorld.unit_range/4)
   context.show_text(self.label)
   
   # reset color
   self.color = lambda context : context.set_source_rgb(1.0, 1.0, 1.0)
Exemplo n.º 4
0
  def draw(self, context):
    Thing.draw(self, context)

    # draw a bounding box
    context.set_line_width(0.005)
    context.set_source_rgba(0.8, 0.8, 0.8, 1.0)
    context.rectangle(-0.5, -0.5, 1.0, 1.0)
    context.fill()
    
    # render label
    context.save()
    context.move_to(-0.5, -0.5)
    context.scale(self.scale_x, self.scale_y)
    context.set_source_rgb(0.0, 0.0, 0.0)
    context.show_layout(self.layout)    
    context.restore()
Exemplo n.º 5
0
  def draw(self, context):
    Thing.draw(self, context)
    
    self.text = self.target.__class__.__name__ # + "\n" + self.target.code
    
    # figure out scale factor to fit text to thing size
    scale = min(1.0 / self.pixel_width, 1.0 / self.pixel_height) / 2.0
    
    # draw connectors
    self.draw_inputs(context)
    #self.draw_outputs(context)

    # render the text
    context.save()
    context.move_to(-0.3, -0.5)
    context.scale(scale, scale)
    context.set_source_rgba(0.0, 0.0, 0.0, 1.0)
    context.show_layout(self.layout)        
    context.restore()
 
    # render box
    Primitives.panel(context, -0.5, -0.5, 1.0, 1.0, 0.05)
Exemplo n.º 6
0
    def draw(self, context):
        Thing.draw(self, context)

        context.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
        context.set_font_size(10.0)

        # # Decorations ###################################
        if self.mouse_over:
            # highlight
            # context.set_source_rgb(1.0, 1.0, 0.7)
            # context.rectangle(self.left - self.decorator_size,
            #                  self.top - self.decorator_size,
            #                  self.width + self.decorator_size * 2.0,
            #                  self.height + self.decorator_size * 2.0)
            # context.fill()

            # scaler
            if self.mouse_over_scaler:
                context.set_source_rgb(1.0, 0.0, 0.0)
                context.move_to(self.left - self.decorator_size * 2.0, self.bottom + self.decorator_size * 2.0)
                context.show_text(str((int(self.world_width), int(self.world_height))))
            else:
                context.set_source_rgb(0.0, 0.0, 0.0)
            context.set_line_width(4.0)
            context.move_to(self.left - self.decorator_size, self.bottom - self.decorator_size)
            context.line_to(self.left - self.decorator_size, self.bottom + self.decorator_size)
            context.line_to(self.left + self.decorator_size, self.bottom + self.decorator_size)
            context.stroke()

            # sizer
            if self.mouse_over_sizer:
                context.set_source_rgb(1.0, 0.0, 0.0)
                context.move_to(self.right + self.decorator_size * 2.0, self.bottom + self.decorator_size * 2.0)
                context.show_text(str((int(self.width), int(self.height))))
            else:
                context.set_source_rgb(0.0, 0.0, 0.0)
            context.set_line_width(4.0)
            context.move_to(self.right + self.decorator_size, self.bottom - self.decorator_size)
            context.line_to(self.right + self.decorator_size, self.bottom + self.decorator_size)
            context.line_to(self.right - self.decorator_size, self.bottom + self.decorator_size)
            context.stroke()

            # rotater
            if self.mouse_over_rotater:
                context.set_source_rgb(1.0, 0.0, 0.0)
                context.move_to(self.right + self.decorator_size * 2.0, self.top - self.decorator_size * 2.0)
                context.show_text(str(int(self.rotation)))
                context.stroke()
            else:
                context.set_source_rgb(0.0, 0.0, 0.0)
            context.set_line_width(4.0)
            context.arc(
                self.right - self.decorator_size / 2.0,
                self.top + self.decorator_size / 2.0,
                self.decorator_size * 2.0,
                math.pi + math.pi / 2.0,
                0.0,
            )
            context.stroke()

            # input
            if self.mouse_over_input:
                context.set_source_rgb(1.0, 0.0, 0.0)
            else:
                context.set_source_rgb(0.0, 0.0, 0.0)
            context.set_line_width(1.0)
            context.move_to(self.left - self.decorator_size * 2.0, -self.decorator_size)
            context.line_to(self.left - self.decorator_size, 0.0)
            context.line_to(self.left - self.decorator_size * 2.0, self.decorator_size)
            context.close_path()
            context.fill()

            # output
            if self.mouse_over_output:
                context.set_source_rgb(1.0, 0.0, 0.0)
            else:
                context.set_source_rgb(0.0, 0.0, 0.0)
            context.set_line_width(1.0)
            context.move_to(self.right + self.decorator_size, -self.decorator_size)
            context.line_to(self.right + self.decorator_size * 2.0, 0.0)
            context.line_to(self.right + self.decorator_size, self.decorator_size)
            context.close_path()
            context.fill()

        # # End Decorations ###############################

        # render any encapsulated objects
        if self.render_children:
            self.draw_children(context, self.children())