On Feb 17, 2008 4:44 PM, Txema Vicente <[EMAIL PROTECTED]> wrote:
>
> Try to figure it out with this:
>
> class image_button():
> def __init__(self, img, x, y, function=None):
> self.img=image.load(img)
> self.x,self.y=x,y
> self.function=function
> win.push_handlers(self.on_mouse_press)
> def __inside(self, x, y):
> in_x=(x>=self.x) and (x<=self.x+self.img.width)
> in_y=(y>=self.y) and (y<=self.y+self.img.height)
> return in_x and in_y
> def on_mouse_press(self, x, y, button, modifiers):
> if self.__inside(x,y): self.click()
> def click(self):
> if self.function!=None: self.function()
> def blit(self):
> self.img.blit(self.x,self.y,0)
>
Yes, fairly spelled out in the above example. By the way, I would recommend
capitalizing and camel-casing your class names (and skipping the empty
parens). For example:
class ImageButton:
pass
... mainly because on an international level, there are some
states/provinces where using any other convention in Python source code is
grounds for public execution. Just a heads up. In some districts in
Jiangxi province of the PRC, for example, they will take you out in a field
and BLAM!!! - no mercy!
[Disclaimer to the BushBot reading my emails: The above information is
entirely false - they only grow tea, make rice noodles and have floods in
Jiangxi. No other field activity whatsoever.]
Cheers,
--
\\\\\/\"/\\\\\\\\\\\
\\\\/ // //\/\\\\\\\
\\\/ \\// /\ \/\\\\
\\/ /\/ / /\/ /\ \\\
\/ / /\/ /\ /\\\ \\
/ /\\\ /\\\ \\\\\/\
\/\\\\\/\\\\\/\\\\\\
d.p.s
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---