move glColor() out of individual draw routines

This commit is contained in:
Josh Holtrop 2011-07-27 23:17:35 -04:00
parent 03754f3cec
commit a0fe5aa6aa

View File

@ -24,6 +24,7 @@ class SketchWidget:
'arrow': gtk.gdk.Cursor(gtk.gdk.ARROW), 'arrow': gtk.gdk.Cursor(gtk.gdk.ARROW),
'crosshair': gtk.gdk.Cursor(gtk.gdk.CROSSHAIR), 'crosshair': gtk.gdk.Cursor(gtk.gdk.CROSSHAIR),
} }
self.current_snap_point = None
# Configuration parameters # Configuration parameters
self.line_width = 1.5 self.line_width = 1.5
@ -125,7 +126,9 @@ class SketchWidget:
self.drawConstraints() self.drawConstraints()
if self.drawingShape is not None: if self.drawingShape is not None:
glColor(*self.line_color)
self.drawShape(self.drawingShape) self.drawShape(self.drawingShape)
glColor(*self.constraint_color)
for c in self.drawingConstraints: for c in self.drawingConstraints:
self.drawConstraint(c) self.drawConstraint(c)
@ -157,13 +160,11 @@ class SketchWidget:
return dist / self.size[0] * self.view_width return dist / self.size[0] * self.view_width
def drawLine(self, shape): def drawLine(self, shape):
glColor(*self.line_color)
pt0 = self.ptToScreenPt(shape.getPt(0)) pt0 = self.ptToScreenPt(shape.getPt(0))
pt1 = self.ptToScreenPt(shape.getPt(1)) pt1 = self.ptToScreenPt(shape.getPt(1))
self.drawFilledLine(pt0[0], pt0[1], pt1[0], pt1[1], self.line_width) self.drawFilledLine(pt0[0], pt0[1], pt1[0], pt1[1], self.line_width)
def drawCircle(self, shape): def drawCircle(self, shape):
glColor(*self.line_color)
center = self.ptToScreenPt(shape.getCenter()) center = self.ptToScreenPt(shape.getCenter())
rad = self.distToScreenDist(shape.getRadius()) rad = self.distToScreenDist(shape.getRadius())
if rad < 30: if rad < 30:
@ -284,6 +285,7 @@ class SketchWidget:
self.widget.queue_draw_area(0, 0, *map(int, self.size)) self.widget.queue_draw_area(0, 0, *map(int, self.size))
def drawShapes(self): def drawShapes(self):
glColor(*self.line_color)
for shape in self.sketch: for shape in self.sketch:
self.drawShape(shape) self.drawShape(shape)
@ -294,6 +296,7 @@ class SketchWidget:
self.drawCircle(shape) self.drawCircle(shape)
def drawConstraints(self): def drawConstraints(self):
glColor(*self.constraint_color)
for c in self.sketch.constraints: for c in self.sketch.constraints:
self.drawConstraint(c) self.drawConstraint(c)
@ -306,12 +309,10 @@ class SketchWidget:
self.drawVertical(c) self.drawVertical(c)
def drawConnect(self, con): def drawConnect(self, con):
glColor(*self.constraint_color)
pt = self.ptToScreenPt(con.shape1.getPt(con.pt1)) pt = self.ptToScreenPt(con.shape1.getPt(con.pt1))
self.drawHandle(pt[0], pt[1]) self.drawHandle(pt[0], pt[1])
def drawHandle(self, x, y): def drawHandle(self, x, y):
glColor(*self.constraint_color)
self.drawFilledCircle(x, y, self.line_width, 4) self.drawFilledCircle(x, y, self.line_width, 4)
s = self.line_width * 2 s = self.line_width * 2
glBegin(GL_LINE_LOOP) glBegin(GL_LINE_LOOP)
@ -322,7 +323,6 @@ class SketchWidget:
glEnd() glEnd()
def drawHorizontal(self, con): def drawHorizontal(self, con):
glColor(*self.constraint_color)
l = 15.0 l = 15.0
glPushAttrib(GL_LINE_BIT) glPushAttrib(GL_LINE_BIT)
glEnable(GL_LINE_STIPPLE) glEnable(GL_LINE_STIPPLE)
@ -338,7 +338,6 @@ class SketchWidget:
glPopAttrib() glPopAttrib()
def drawVertical(self, con): def drawVertical(self, con):
glColor(*self.constraint_color)
l = 15.0 l = 15.0
glPushAttrib(GL_LINE_BIT) glPushAttrib(GL_LINE_BIT)
glEnable(GL_LINE_STIPPLE) glEnable(GL_LINE_STIPPLE)