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__)
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()
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
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()
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
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
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
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)
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()
def hit_test(self, x, y): b = Thing.hit_test(self, x * TheWorld.scale, y * TheWorld.scale) if b: print "BOING" return b
def __init__(self): Thing.__init__(self)