Esempio n. 1
0
void MadsSpriteSlots::drawBackground() {
	// Draw all active sprites onto the background surface
	for (int i = 0; i < startIndex; ++i) {
		MadsSpriteSlot &slot = _entries[i];

		if (slot.spriteType >= 0) {
			_owner._dirtyAreas[i].active = false;
		} else {
			_owner._dirtyAreas[i].textActive = true;
			_owner._dirtyAreas.setSpriteSlot(i, slot);

			if (slot.spriteType == BACKGROUND_SPRITE) {
				SpriteAsset &spriteSet = getSprite(slot.spriteListIndex);
				M4Sprite *frame = spriteSet.getFrame((slot.frameNumber & 0x7fff) - 1);
				int xp = slot.xp;
				int yp = slot.yp;

				if (_entries[i].scale != -1) {
					// Adjust position based on frame size
					xp -= frame->width() / 2;
					yp -= frame->height() / 2;
				}

				if (slot.depth > 1) {
					// Draw the frame with depth processing
					_owner._bgSurface->copyFrom(frame, xp, yp, slot.depth, _owner._depthSurface, 100, 
						frame->getTransparencyIndex());
				} else {
					// No depth, so simply draw the image
					frame->copyTo(_owner._bgSurface, xp, yp, frame->getTransparencyIndex());
				}
			}
		}
	}

	// Flag any remaining dirty areas as inactive
	for (uint i = startIndex; i < DIRTY_AREAS_TEXT_DISPLAY_IDX; ++i)
		_owner._dirtyAreas[i].active = false;
}
Esempio n. 2
0
void MadsSpriteSlots::drawForeground(M4Surface *viewport) {
	DepthList depthList;

	// Get a list of sprite object depths for active objects
	for (int i = 0; i < startIndex; ++i) {
		if (_entries[i].spriteType >= SPRITE_ZERO) {
			DepthEntry rec(16 - _entries[i].depth, i);
			depthList.push_back(rec);
		}
	}

	// Sort the list in order of the depth
	Common::sort(depthList.begin(), depthList.end(), sortHelper);

	// Loop through each of the objects
	DepthList::iterator i;
	for (i = depthList.begin(); i != depthList.end(); ++i) {
		DepthEntry &de = *i;
		MadsSpriteSlot &slot = _entries[de.index];
		assert(slot.spriteListIndex < (int)_sprites.size());
		SpriteAsset &spriteSet = *_sprites[slot.spriteListIndex];

		// Get the sprite frame
		int frameNumber = slot.frameNumber & 0x7fff;
		bool flipped = (slot.frameNumber & 0x8000) != 0;
		M4Sprite *sprite = spriteSet.getFrame(frameNumber - 1);

		M4Surface *spr = sprite;
		if (flipped) {
			// Create a flipped copy of the sprite temporarily
			spr = sprite->flipHorizontal();
		}

		if ((slot.scale < 100) && (slot.scale != -1)) {
			// Minimalised drawing
			viewport->copyFrom(spr, slot.xp, slot.yp, slot.depth, _owner._depthSurface, slot.scale, 
				sprite->getTransparencyIndex());
		} else {
			int xp, yp;

			if (slot.scale == -1) {
				xp = slot.xp - _owner._posAdjust.x;
				yp = slot.yp - _owner._posAdjust.y;
			} else {
				xp = slot.xp - (spr->width() / 2) - _owner._posAdjust.x;
				yp = slot.yp - spr->height() - _owner._posAdjust.y + 1;
			}

			if (slot.depth > 1) {
				// Draw the frame with depth processing
				viewport->copyFrom(spr, xp, yp, slot.depth, _owner._depthSurface, 100, sprite->getTransparencyIndex());
			} else {
				// No depth, so simply draw the image
				spr->copyTo(viewport, xp, yp, sprite->getTransparencyIndex());
			}
		}

		// Free sprite if it was a flipped one
		if (flipped)
			delete spr;
	}
}