.comment-link {margin-left:.6em;}

Wednesday, April 15, 2009

 

a button class for pycap

#this isn't perfect button class for pycap yet but it works (it knows where it is at)

class button:

  #a somewhat working version of button...

  #graphics not quite working yet

  #defined time as t up at the top of the program

  #test = squaret.hittest( x, y)    define in mousedown

  #..................................

  #define in init like the following example

  #global squaret

  #squaret = square(20, 20)

  #..............................

  #define in draw

  #squaret.draw()



  image = None

#   

  def __init__( self, x, y ):

          #import time as t

          self.state = '0' #intitial state

          self.click = '0'

          self.x = x

          self.y = y

          self.maxx = x + 25

          self.maxy = y + 25

  def update( self, delta ):

     pass

  def draw( self ):

      pass

      if self.state == '0':

        PC.setColour(20,40,0, 105)     

        PC.fillRect(self.x, self.y, self.maxx, self.maxy)

        PC.setColour(80,90,50,10)

        PC.fillRect(self.x + 3, self.y + 3, 19, 19)

        self.state = '1'

      else:

        PC.setColour(0,0,0, 105)       

        PC.fillRect(self.x, self.y, self.maxx, self.maxy)

        t.sleep(.02)

        PC.setColour(0,90,90,190)

        PC.fillRect(self.x + 3, self.y + 3, 19, 19)

        t.sleep(.2)

        PC.setColour(50,50,50,50)

        PC.fillRect(self.x + 3, self.y + 3, 19, 19)

      PC.markDirty()

        

        

        

      #I need a timer here

         

  def hittest( self, x, y ):

          pass

          hit = 0   

          if x > self.x:

              if x < self.maxx:

                 if y > self.y:

                   if y < self.maxy:

                      PC.markDirty()

                      self.click = '1'

                      

          #return hit

Labels: , ,


Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?