Esempio n. 1
0
    def paint(self, surface=None):
        if not surface:
            surface = self.surface
            if not self.bg:
                self.surface.fill(COLORKEY)

        offset = self.offset
        viewrect = self.viewport.move(offset)
        offset = -array((offset[0], offset[1]))
        if self.bg:
            surface.blit(self.bg, offset)
        relzoom = 1.0
        reloffset = 0.0
        w, h = surface.get_rect().size
        for c in self.children:
            if hasattr(c, "paint"):
                c.paint(surface)
        # if hasattr(self,'veil') and self.veil:
        # surface.blit(self.veil,(0,0),None,pg.BLEND_RGBA_MULT )
        self.group.draw(surface)
        return
        tmp = surface.convert_alpha()
        for l in self.data.layers[::-1]:
            tmp.fill((0, 0, 0, 0))
            # self.group.draw(tmp)
            grp = pgsprite.Group([g for g in self.group if self.data.get_info(g.item, "layer") == l.trueID])
            grp.draw(tmp)

            d = self.data.get_info(l, "distance")
            if d > 0:
                gv_effects.blur(tmp, sigma=int(4 * d / 1.0))
            surface.blit(tmp, (0, 0))

        return
Esempio n. 2
0
    def set_image(self,state,**kwargs):
        #print 'set image',self,state
        ## Comments with ## = potential breaking change, 2013-08-05
        if not self.images:
            return False
        if state in self.images:
            self.base_image=self.images[state]
            ##return self.image
        else:
            state,prior =  sorted([(i,self.priority.get(i,0))
                for i in self.images if i =='idle' or self.states.get(i,0)],
                key=itemgetter(1),reverse=1)[0]
            self.base_image=self.images[state]


        mod=array((1.,1.,1.,1.))
        grayed=False
        for i in self.modimg:
            if self.states[i]:
                j=self.color_mod(i)
                if isinstance(j,basestring) and j=='grayed':
                    grayed=True
                else:
                    mod *= array(j)

        #Create a new surface only if something has changed
        if grayed or not (mod==tuple(1. for i in mod ) ).all():
            if self.per_pixel_alpha:
                try:
                    image=self.base_image.convert_alpha()
                except:
                    image=self.images['idle'].convert_alpha()
            else:
                try:
                    surf=self.base_image
                except:
                    surf=self.images['idle']
                image=pgsurface.Surface(surf.get_rect().size,pg.SRCALPHA)
                image.blit(surf,(0,0))
            if grayed:
                image=gv_effects.convert_to_greyscale(image)

            #Separate the mod into alpha and color if necessary
            if not self.per_pixel_alpha:
                useflag=pg.BLEND_MULT
                modalp=mod[3]
                mod=mod[:3]
            else:
                useflag=pg.BLEND_RGBA_MULT

            #RGB/RGBA component
            if not (mod==tuple(1. for i in mod ) ).all():
                excess=tuple(max(0.,i-1.) for i in mod)
                if excess!=(0,0,0,0):
                    img=image.copy()
                    img.fill(tuple(min(255,int(i*255)) for i in excess),None,useflag)
                else :
                    img = None
                image.fill(tuple(min(255,int(i*255)) for i in mod),None,useflag)
                if img:
                    image.blit(img,(0,0),None,pg.BLEND_RGB_ADD)

            #Surface alpha
            if not self.per_pixel_alpha and modalp!=1:
                surf=surf.convert()
                surf.fill(COLORKEY)
                surf.blit(image,(0,0))
                image=surf
                image.set_colorkey(COLORKEY)
                if self.alpha:
                    basalp=self.alpha
                else:
                    basalp=255
                image.set_alpha(rint(modalp*basalp),pg.RLEACCEL)
        else:
            try:
                image=self.base_image.copy()
            except:
                image=self.images['idle'].copy()
            if  not self.per_pixel_alpha and self.alpha:
                image.set_alpha(self.alpha,pg.RLEACCEL)
        if self.states.get('blur',None):
            blimg=image.copy()
            gv_effects.blur(blimg,**self.blur_mode)
            self.images['blur']=self.image=blimg
        self.image=image
        if self.maskable:
            self.mask=pgmask.from_surface(image,1)
        if kwargs.get('mutate',True):
            self.mutate()
        return self.image