SketchWidget: refactor drawing of shapes/constraints

This commit is contained in:
Josh Holtrop 2011-04-03 20:09:56 -04:00
parent 15f020e93a
commit f2fdf19079

View File

@ -6,6 +6,7 @@ import gtk.gtkgl
from OpenGL.GL import * from OpenGL.GL import *
from shapes import * from shapes import *
from constraints import *
class SketchWidget: class SketchWidget:
def __init__(self, sketch): def __init__(self, sketch):
@ -25,6 +26,7 @@ class SketchWidget:
self.background_color = (0.6, 0.9, 1.0, 1.0) self.background_color = (0.6, 0.9, 1.0, 1.0)
self.line_color = (0.1, 0.4, 1.0, 1.0) self.line_color = (0.1, 0.4, 1.0, 1.0)
self.axis_color = (1.0, 0.0, 0.0, 1.0) self.axis_color = (1.0, 0.0, 0.0, 1.0)
self.constraint_color = (0.5, 1.0, 0.0, 1.0)
try: try:
# try double-buffered # try double-buffered
@ -103,12 +105,8 @@ class SketchWidget:
self.drawAxes() self.drawAxes()
glColor(*self.line_color) self.drawShapes()
for shape in self.sketch: self.drawConstraints()
if isinstance(shape, Line):
self.drawLine(shape, self.line_width)
elif isinstance(shape, Circle):
self.drawCircle(shape, self.line_width)
if self.drawingLine is not None: if self.drawingLine is not None:
self.drawLine(self.drawingLine, self.line_width) self.drawLine(self.drawingLine, self.line_width)
@ -263,3 +261,18 @@ class SketchWidget:
def queue_redraw(self): def queue_redraw(self):
self.widget.queue_draw_area(0, 0, self.widget.queue_draw_area(0, 0,
int(self.size[0]), int(self.size[1])) int(self.size[0]), int(self.size[1]))
def drawShapes(self):
glColor(*self.line_color)
for shape in self.sketch:
if isinstance(shape, Line):
self.drawLine(shape, self.line_width)
elif isinstance(shape, Circle):
self.drawCircle(shape, self.line_width)
def drawConstraints(self):
glColor(*self.constraint_color)
for c in self.sketch.constraints:
if isinstance(c, Connect):
# self.drawConnect(c)
pass