class DrawingAdapter(object): def __init__(self): self.drawing = GDrawing(scale=settings.SCALE, width=settings.WIDTH, height=settings.HEIGHT) def _elements_for_glyph(self, glyph): return [GLine(line.x, line.y, line.l, glyph.orientation) for line in glyph.lines] def _elements_for_point(self, point): return [GPoint(point.x, point.y)] def _elements_for_circle(self, circle): return [GCircle(circle.x, circle.y, circle.r)] def _elements_for_list(self, lst): elements = [] for item in lst: elements.extend(self._elements_for(item)) return elements def _elements_for(self, item): mapping = { Glyph: self._elements_for_glyph, Point: self._elements_for_point, Circle: self._elements_for_circle, list: self._elements_for_list} return mapping[type(item)](item) def add_zone(self, *items): elements = [] for item in items: elements.extend(self._elements_for(item)) self.drawing.add_zone(GZone(elements=elements))
def __init__(self): self.drawing = GDrawing(scale=settings.SCALE, width=settings.WIDTH, height=settings.HEIGHT)
def _init_glut(self): glutInit() glutInitWindowSize(self.width, self.height) glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE) glutCreateWindow(self.caption) glutDisplayFunc(self.on_draw) def on_draw(self): glClear(GL_COLOR_BUFFER_BIT) if self.drawing: self.drawing.draw() glFlush() def run_gui(drawing): window = MainWindow(drawing) if __name__ == "__main__": drawing = GDrawing(scale=SCALE, width=WIDTH, height=HEIGHT) drawing.add_zone(GZone(elements=[GPoint(0, 0), GLine(2, 0, 5, VERTICAL), GLine(4, 0, 5, HORIZONTAL)])) drawing.add_zone(GZone(elements=[GPoint(0, 0), GLine(2, 0, 5, VERTICAL), GLine(4, 0, 5, HORIZONTAL)])) drawing.add_zone(GZone(elements=[GCircle(10, 10, 6)])) run_gui(drawing)