Beispiel #1
0
    def render(self, renderer, rect, alpha=255, scale=1.0):
        def _scale(v):
            return int(math.ceil(v / (self.scale / scale)))

        texture = self.get_texture(renderer)
        s = self.slice_rects
        mid_w = rect.width - _scale(s[0].width) - _scale(s[2].width)
        mid_h = rect.height - _scale(s[0].height) - _scale(s[6].height)
        x1 = rect.left + _scale(s[0].width)
        x2 = rect.right - _scale(s[2].width)
        y1 = rect.top + _scale(s[0].height)
        y2 = rect.bottom - _scale(s[6].height)
        rects = [
            Rect([rect.left, rect.top],
                 [_scale(s[0].width), _scale(s[0].height)]),
            Rect([x1, rect.top], [mid_w, _scale(s[1].height)]),
            Rect([x2, rect.top],
                 [_scale(s[2].width), _scale(s[2].height)]),
            Rect([rect.left, y1], [_scale(s[3].width), mid_h]),
            Rect([x1, y1], [mid_w, mid_h]),
            Rect([x2, y1], [_scale(s[5].width), mid_h]),
            Rect([rect.left, y2],
                 [_scale(s[6].width), _scale(s[6].height)]),
            Rect([x1, y2], [mid_w, _scale(s[7].height)]),
            Rect([x2, y2],
                 [_scale(s[8].width), _scale(s[8].height)]),
        ]
        sdl2.SDL_SetTextureAlphaMod(texture, alpha)
        for idx in range(len(s)):
            src = s[idx]
            dst = rects[idx]
            sdl2.SDL_RenderCopy(renderer, texture, ctypes.byref(src.sdl),
                                ctypes.byref(dst.sdl))
    def draw(self, destination_texture = None):
        # for p in self.particles:
        for x in xrange(0,len(self.particles)): #xrange(len(self.particles)-1,0,-1):
            p = self.particles[x]
            tx = None
            if(p.life > self.max_life * 0.55):
                tx = self.txImg16
                (self.p_w, self.p_h) = (self.p16_w,self.p16_h)
            else:
                tx = self.txImg8
                (self.p_w, self.p_h) = (self.p8_w,self.p8_h)

            if(p.color_changed):
                sdl2.SDL_SetTextureColorMod(tx.texture, p.r,p.g,p.b)
                p.color_changed = False

            # sdl2.SDL_SetTextureAlphaMod(tx.texture, 192) #int(p.a))
            if(p.alpha_changed):
                sdl2.SDL_SetTextureAlphaMod(tx.texture, int(p.a))
                p.alpha_changed = False

            if(destination_texture is None):
                sdl2_DisplayManager.inst().screen_blit(tx, x=p.x, y=p.y, expand_to_fill=False)
            else:
                sdl2_DisplayManager.inst().blit(source_tx = tx, dest_tx=destination_texture, dest=(p.x,p.y,self.p_w, self.p_h))                
Beispiel #3
0
 def draw(self,
          renderer,
          text,
          rect,
          color,
          selected=None,
          kerning=True,
          wrap=True,
          lines=None):
     """
     Renders text in the specified rect, using the specified color. If specified, selected is a set of indexes in
     text that should be highlighted.
     """
     y = rect.top
     if lines is None:
         lines = list(
             self.layout(text, rect.width, kerning=kerning, wrap=wrap))
     for line in lines:
         for idx, code, x, kern, extent in line:
             tex, size = self.glyph(renderer, code)
             sdl2.SDL_SetTextureColorMod(tex, color.r, color.g, color.b)
             sdl2.SDL_SetTextureAlphaMod(tex, color.a)
             dst = sdl2.SDL_Rect(rect.left + x + kern, y, size.w, size.h)
             sdl2.SDL_RenderCopy(renderer, tex, None, ctypes.byref(dst))
             if selected and idx in selected:
                 sdl2.SDL_SetRenderDrawColor(renderer, 20, 60, 120, 255)
                 sdl2.SDL_SetRenderDrawBlendMode(renderer,
                                                 sdl2.SDL_BLENDMODE_ADD)
                 sdl2.SDL_RenderFillRect(
                     renderer,
                     sdl2.SDL_Rect(rect.left + x, y, size.w + kern, size.h))
         y += self.line_height
     return lines
Beispiel #4
0
 def __init__(self, **kwargs):
     super(Image_Entry, self).__init__(**kwargs)
     image_field = self.parent_field
     resource_alias = image_field.value
     resource_id = image_field.parent_form.manifest[resource_alias]
     file_name = os.path.join(pride.site_config.RESOURCE_DIRECTORY,
                              resource_id)
     image_surface = sdl2.ext.load_image(file_name,
                                         enforce=self._enforce_flag)
     sprite_factory = self.sdl_window.renderer.sprite_factory
     image_texture = sprite_factory.from_surface(image_surface)
     sdl2.SDL_SetTextureAlphaMod(image_texture.texture, self.color[-1])
     self.image_texture = image_texture
Beispiel #5
0
    def set_alpha_mod(self, alpha=None):
        """Set a alpha value multiplier for render copy operations.

        When this texture is rendered, during the copy operation the source
        alpha value is modulated by this alpha value according to the
        following formula:
            srcA = srcA * (alpha / 255)

        Args:
            alpha (int): integer between 0 and 255

        Returns:
            None
        """
        alpha = alpha or 255
        sdl2.SDL_SetTextureAlphaMod(self.texture, alpha)
Beispiel #6
0
    def draw(self, destination_texture = None):
        # for p in self.particles:
        for x in xrange(0,len(self.particles)): #xrange(len(self.particles)-1,0,-1):
            p = self.particles[x]
            tx = None
            # if(p.life > self.max_life * 0.55):
            #     tx = self.txYellow
            # elif(p.life > self.max_life * 0.25):
            #     tx = self.txFire
            # else:
            #     tx = self.txWhite
            tx = self.txSmoke

            sdl2.SDL_SetTextureColorMod(tx.texture, p.r,p.g,p.b)

            # sdl2.SDL_SetTextureAlphaMod(tx.texture, 192) #int(p.alpha_value))
            sdl2.SDL_SetTextureAlphaMod(tx.texture, int(p.alpha_value))
            if(destination_texture is None):
                sdl2_DisplayManager.inst().screen_blit(tx, x=p.x, y=p.y, expand_to_fill=False)
            else:
                sdl2_DisplayManager.inst().blit(source_tx = tx, dest_tx=destination_texture, dest=(p.x,p.y,self.p_w, self.p_h))                
Beispiel #7
0
    def render(self, renderer):
        if self.currentSystem != self.currentState.getCurrentSystem().name:
            image = sdl2.sdlimage.IMG_Load(
                b"images/backdrops/" +
                self.currentState.getCurrentSystem().name.encode('utf-8') +
                b".jpg")
            self.text = sdl2.SDL_CreateTextureFromSurface(renderer, image)
            sdl2.SDL_FreeSurface(image)

            sdl2.SDL_SetTextureBlendMode(self.text, sdl2.SDL_BLENDMODE_BLEND)
            sdl2.SDL_SetTextureAlphaMod(self.text, c_uint8(48))
            sdl2.SDL_QueryTexture(self.text, None, None,
                                  byref(self.imageWidth),
                                  byref(self.imageHeight))

            self.currentSystem = self.currentState.getCurrentSystem().name

        percent = 720 / self.imageHeight.value
        sdl2.SDL_RenderCopy(
            renderer, self.text, None,
            sdl2.SDL_Rect(0, 0, int(self.imageWidth.value * percent),
                          int(self.imageHeight.value * percent)))
Beispiel #8
0
	def load(self, renderer):
		# Player
		self.textures[TextureType.PLAYER] = self.create(
			renderer, b'textures/player.png')

		# Characters
		self.textures[TextureType.CIVILIAN] = self.create(
			renderer, b'textures/civilian.png')
		self.textures[TextureType.STOCKER] = self.create(
			renderer, b'textures/stocker.png')

		# Locations
		self.textures[TextureType.HOUSE_INTERIOR] = self.create(
			renderer, b'textures/house_interior.png')
		self.textures[TextureType.GROCERY_STORE_INTERIOR] = self.create(
			renderer, b'textures/grocery_store_interior.png')
		self.textures[TextureType.GAS_STATION_INTERIOR] = self.create(
			renderer, b'textures/gas_station_interior.png')
		self.textures[TextureType.HOUSE_EXTERIOR] = self.create(
			renderer, b'textures/house_exterior.png')
		self.textures[TextureType.HOUSE_EXTERIOR_REAR] = self.create(
			renderer, b'textures/house_exterior_rear.png')
		self.textures[TextureType.GROCERY_STORE_EXTERIOR] = self.create(
			renderer, b'textures/grocery_store_exterior.png')
		self.textures[TextureType.GAS_STATION_EXTERIOR] = self.create(
			renderer, b'textures/gas_station_exterior.png')

		# Supplies
		self.textures[TextureType.FOOD] = self.create(
			renderer, b'textures/food.png')
		self.textures[TextureType.SOAP] = self.create(
			renderer, b'textures/soap.png')
		self.textures[TextureType.HAND_SANITIZER] = self.create(
			renderer, b'textures/hand_sanitizer.png')
		self.textures[TextureType.TOILET_PAPER] = self.create(
			renderer, b'textures/toilet_paper.png')
		self.textures[TextureType.MASK] = self.create(
			renderer, b'textures/mask.png')
		self.textures[TextureType.PET_SUPPLIES] = self.create(
			renderer, b'textures/pet_supplies.png')

		# Items
		self.textures[TextureType.VEHICLE] = self.create(
			renderer, b'textures/vehicle.png')
		self.textures[TextureType.SINK] = self.create(
			renderer, b'textures/sink.png')
		self.textures[TextureType.KITCHEN] = self.create(
			renderer, b'textures/kitchen.png')
		self.textures[TextureType.BED] = self.create(
			renderer, b'textures/bed.png')
		self.textures[TextureType.COMPUTER] = self.create(
			renderer, b'textures/computer.png')
		self.textures[TextureType.SHOPPING_CART] = self.create(
			renderer, b'textures/cart.png')
		self.textures[TextureType.DOOR] = self.create(
			renderer, b'textures/door.png')
		self.textures[TextureType.SELF_CHECKOUT] = self.create(
			renderer, b'textures/self_checkout.png')
		self.textures[TextureType.CLOSET] = self.create(
			renderer, b'textures/closet.png')
		self.textures[TextureType.FUEL_DISPENSER] = self.create(
			renderer, b'textures/fuel_dispenser.png')

		# Pets
		self.textures[TextureType.DOG] = self.create(
			renderer, b'textures/dog.png')

		# Map Elements
		self.textures[TextureType.AISLE] = self.create(
			renderer, b'textures/aisle.png')
		self.textures[TextureType.ROAD] = self.create(
			renderer, b'textures/road.png')
		self.textures[TextureType.SIDEWALK] = self.create(
			renderer, b'textures/sidewalk.png')
		self.textures[TextureType.DRIVEWAY] = self.create(
			renderer, b'textures/driveway.png')
		self.textures[TextureType.PARKING_LOT] = self.create(
			renderer, b'textures/parking_lot.png')
		self.textures[TextureType.COUNTER] = self.create(
			renderer, b'textures/counter.png')
		self.textures[TextureType.DESK] = self.create(
			renderer, b'textures/desk.png')

		# World
		self.textures[TextureType.GRASS] = self.create(
			renderer, b'textures/grass.png')

		# User Interface
		self.textures[TextureType.SPLASH_SCREEN] = self.create(
			renderer, b'textures/splash_screen.jpg')
		self.textures[TextureType.LOSE_SCREEN] = self.create(
			renderer, b'textures/lose_screen.jpg')
		self.textures[TextureType.MINI_MAP] = self.create(
			renderer, b'textures/mini_map.png')
		
		# Increase transparency on mini-map texture
		sdl2.SDL_SetTextureBlendMode(self.textures[TextureType.MINI_MAP],
			sdl2.SDL_BLENDMODE_BLEND)
		sdl2.SDL_SetTextureAlphaMod(self.textures[TextureType.MINI_MAP], 75)