I was trying to make a radio button on pudding and to draw it i use this:
def
draw_bordered_circle(self,radius,background=None,border=None,border_width=No
ne):
glEnable(GL_BLEND)
if background != STYLE_NONE:
glColor4f( *( background or self.box_background) )
glBegin(GL_TRIANGLES)
for i in range(360):
rad1=i*math.pi/180
rad2=(i+1)*math.pi/180
glVertex2f(0.0,0.0)
glVertex2f(math.cos(rad1)*radius,math.sin(rad1)*radius)
glVertex2f(math.cos(rad2)*radius,math.sin(rad2)*radius)
glEnd()
glColor4f( *( border or self.box_border) )
# glHint(GL_LINE_SMOOTH_HINT,GL_NICEST)
# glEnable(GL_LINE_SMOOTH)
if border != STYLE_NONE and border_width != 0:
glLineWidth( border_width or self.box_border_width)
glBegin(GL_LINE_STRIP)
for i in range(360):
rad=i*math.pi/180
glVertex2f(math.cos(rad)*radius,math.sin(rad)*radius)
glEnd()
# glDisable(GL_LINE_SMOOTH)
glDisable(GL_BLEND)
The trouble is that the solid circle isn't draw is there are other widget's
draw on the screen, but if the circle is the only thing to be drawed it has
no trouble.
This is my radio button right now:
class RadioButton(Control, InputControl):
def __get_background_color__(self):
return self._background_color
def __set_background_color__(self, color):
self._background_color = color
def __get_border_color__(self):
return self._border_color
def __set_border_color__(self, color):
self._border_color = color
def __get_border_width__(self):
return self._border_width
def __set_border_width__(self, width):
self._border_width = width
background_color = property(__get_background_color__,
__set_background_color__,
doc = "background color of the box")
border_color = property(__get_border_color__,
__set_border_color__,
doc = "border color of the box")
border_width = property(__get_border_width__,
__set_border_width__,
doc = "border width")
def __init__(self, parent = None, left=0, top=0, radius=0.0,
indicator_radius=0):
Control.__init__(self, parent, left, top, 2*radius, 2*radius)
InputControl.__init__(self)
self._background_color = pudding.STYLE.box_background
self._border_color = pudding.STYLE.box_border
self._border_width = 1
self.radius=radius
self.indicator=indicator_radius
self.angle=0
self.moving=None
self.old_x=None
self.old_y=None
def process_event(self, event):
""" use the InputControl class to process events """
return InputControl.process_event(self, event)
def render_self(self):
""" render the box with current settings """
glPushMatrix()
glTranslatef(self.radius,self.radius,0.0)
glRotatef(self.angle,0,0,1)
pudding.STYLE.draw_bordered_circle(self.radius,
background = self.background_color, border = self.border_color,
border_width = self.border_width)
glTranslatef(0.0,1+self.indicator-self.radius,0.0)
pudding.STYLE.draw_bordered_circle(self.indicator,
background = (0.0,0.0,1.0,1.0), border = self.border_color,
border_width = self.border_width)
glPopMatrix()
def on_mouse_down(self,x,y,ev):
if self.focus:
self.moving=True
self.old_x=x
self.old_y=y
return True
return False
def on_mouse_up(self,x,y,ev):
if self.moving:
self.moving=None
return True
return False
def on_mouse_over(self,x,y,ev):
if self.moving:
if not self.old_x:
self.old_x=x
else:
self.angle+=x-self.old_x
self.old_x=x
return True
return False
Javier Correa