Ejemplo 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()
Ejemplo 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__)
Ejemplo n.º 3
0
  def __init__(self, start_particles, x, y):
    Thing.__init__(self)
    self.width = SIZE
    self.height = SIZE 
    
    self.x = x
    self.y = y
    
    self.output_buffer = []
    self.output_buffer_count = 0
    self.particle_life = 50000.0
    
    
    # set up physics engine
    self.ode = ode.World()
    #self.ode.setGravity( (0,0.1,0) )    
    #self.ode.setERP(0.8)  
    #self.ode.setCFM(10E-10) 
    #self.ode.setContactMaxCorrectingVel(10.0)
    self.ode_space = ode.Space(type=1) # hashspace
    #self.ode_space = ode.QuadTreeSpace((0,0,0),(1,1,1),4)
    
    # create walls
    self.ode_floor = ode.GeomPlane(self.ode_space, (0, -1, 0), -TheWorld.unit_range)
    self.ode_wall_right = ode.GeomPlane(self.ode_space, (-1, 0, 0), -TheWorld.unit_range)
    self.ode_wall_left = ode.GeomPlane(self.ode_space, (1, 0, 0), -TheWorld.unit_range)
    self.ode_celing = ode.GeomPlane(self.ode_space, (0, 1, 0), -TheWorld.unit_range)
    
    # contact group for collision detection
    self.ode_contactgroup = ode.JointGroup()
    
    # jointgroup for constraining movement to 2d
    self.ode_2dgroup = ode.JointGroup()
    
    # motor group ?
    self.ode_motorgroup = ode.JointGroup()
    
    # jointgroup for fixed objects
    self.ode_anchorgroup = ode.JointGroup()

    # create some bodies
    self.ode_bodies = []
    self.start_particles = start_particles
    #for i in range(start_particles):
    #  self.ode_bodies.append(self.create_body())
    
    # a wall
    #thick = 5.0
    self.ode_walls = []
    #self.ode_walls.append(self.create_wall(0.0, -TheWorld.unit_range, TheWorld.unit_range*2 - thick, thick)) # top
    #self.ode_walls.append(self.create_wall(-TheWorld.unit_range, 0.0, thick, TheWorld.unit_range*2 - thick)) # left
    #self.ode_walls.append(self.create_wall(0.0,  TheWorld.unit_range, TheWorld.unit_range*2 - thick, thick)) # bottom
    #self.ode_walls.append(self.create_wall(TheWorld.unit_range,  0.0, thick, TheWorld.unit_range*2 - thick)) # right
    
    # create a rotor
    self.rotor = None

    self.skip = 10
    self.skipcount = 0
Ejemplo n.º 4
0
  def __init__(self, x, y, label, target):
    Thing.__init__(self, x, y, Button.size, Button.size)

    self.label = label
    self.target = target

    # lock position
    #self.can_drag = False
    
    self.color = lambda context : context.set_source_rgb(1.0, 1.0, 1.0)
Ejemplo n.º 5
0
 def __init__(self, root_node):
   Thing.__init__(self)
   
   self.root_node = root_node
   
   self.x_offset = 0.0
   self.y_offset = 0.0
   self.width = 1.5
   self.height = 1.5
   
   self.cache_drawing_operations = False
   self.cached_render = None
   self.cached_scale  = TheWorld.scale
Ejemplo n.º 6
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)
Ejemplo n.º 7
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()
Ejemplo n.º 8
0
 def __init__(self):
   Thing.__init__(self)
   TextEditor.__init__(self, "> ")
   self.cursorindex = 2
   
   self.x = 0.0
   self.y = 0.0
   self.width = 0.2
   self.height = 0.2
   
   fontDescription = pango.FontDescription("Monospace 10")
   self.layout.set_font_description(fontDescription)
   
   self.lock_scale = False
   self.lock_position = True
   
   self.first = True
Ejemplo n.º 9
0
    def __init__(self, x, y, w, h):
        Thing.__init__(self, x, y, w, h)

        self.render_children = True

        self.decorator_size = 10.0
        self.mouse_over = False
        self.mouse_over_sizer = False
        self.mouse_over_scaler = False
        self.mouse_over_input = False
        self.mouse_over_output = False
        self.mouse_over_rotater = False

        self.scale_to_container = True

        self.is_toolbox = (
            False
        )  # TODO We need another way to associate these kind of aspects with objects than base classes as they swell base classes unneccesarily
Ejemplo n.º 10
0
 def __init__(self, label, points = 6.0, font = "Comic Sans MS"):
   Thing.__init__(self)
   
   self.width = 1.0
   self.height = 1.0
   self.pixel_width  = 0.0
   self.pixel_height = 0.0
   self.scale_x = 1.0
   self.scale_y = 1.0
   
   self.size_thing_to_content = True
   self.size_content_to_thing = not self.size_thing_to_content
   
   # pango
   font_description = pango.FontDescription(font + " " + str(points))
   self.layout = TheWorld.text_layout
   self.layout.set_font_description(font_description)
   
   self.label = label    
Ejemplo n.º 11
0
  def __init__(self, target):
    Thing.__init__(self)

    self.target = target

    # TODO Need a way of making world objects exempt from scaling, rotation and/or translation transforms
    size = 0.25
    self.width = size
    self.height = size
    
    # set & lock position
    self.x = -1.0 + (ClassEditor.num_editors * (size * 1.5)) + (size / 2.0)
    self.y = -1.0 - (size / 2.0)
    self.can_drag = False
    
    # image
    self.svg = rsvg.Handle('resources/classeditor.svg')    

    ClassEditor.num_editors += 1    
Ejemplo n.º 12
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)
Ejemplo n.º 13
0
  def __init__(self, target):
    Thing.__init__(self)

    self.target = target
    
    # set & lock position
    self.x = (random() * 2.0) - 1
    self.y = (random() * 2.0) - 1
    
    self.width  = 0.1
    self.height = 0.1
    self.pixel_width  = 0.0
    self.pixel_height = 0.0
    

    # pango
    self.layout = pango.Layout(TheWorld.pango_context)
    fontDescription = pango.FontDescription("Sans 8")
    self.layout.set_font_description(fontDescription)
    self.text = self.target.__class__.__name__ + "\n" + self.target.code
    
    # calc text metrics
    self.recalc_text_size()
Ejemplo n.º 14
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())
Ejemplo n.º 15
0
 def tick(self):
     Thing.tick(self)
Ejemplo n.º 16
0
 def hit_test(self, x, y):
   b = Thing.hit_test(self, x * TheWorld.scale, y * TheWorld.scale)
   if b:
     print "BOING"
   return b