Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/imgClick.py
blob: 707ab864ad4613c10950c44d6ce81b75bcea2571 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#imgClick.py
# eg click_img=ImgClickClass(img,(x,y)) (x,y)=top left
#   if click_img.mouse_on():
#   click_img.draw(gscreen)

import g,pygame

class ImgClick: # for clickable images
    def __init__(self,img,(x1,y1),centre=False):
        w=img.get_width();h=img.get_height();x=x1;y=y1
        if centre: x=x-w/2; y=y-h/2; self.cx=x1; self.cy=y1
        else: self.cx=x+w/2; self.cy=y+h/2
        self.rect=pygame.Rect(x,y,w,h)
        self.x=x; self.y=y; self.img=img
        self.w=w; self.h=h


    def mouse_on(self):
        return self.rect.collidepoint(g.pos)

    def draw(self,screen):
        screen.blit(self.img,(self.x,self.y))

    def mouse_set(self):
        pygame.mouse.set_pos((self.cx,self.cy))
        g.pos=(self.cx,self.cy)