bool Console::cmdShowSprite(int argc, const char **argv) { View *view = _vm->_viewManager->getView(VIEWID_SCENE); if (view == NULL) DebugPrintf("The scene view isn't currently active\n"); else if (argc < 2) DebugPrintf("Usage: %s resource_name\n", argv[0]); else { char resourceName[20]; strncpy(resourceName, argv[1], 15); resourceName[15] = '\0'; if (!strchr(resourceName, '.')) strcat(resourceName, ".SS"); _vm->_viewManager->moveToFront(view); Common::SeekableReadStream *data = _vm->res()->get(resourceName); SpriteAsset *asset = new SpriteAsset(_vm, data, data->size(), resourceName); _vm->res()->toss(resourceName); RGBList *palData = new RGBList(asset->getColorCount(), asset->getPalette(), true); _vm->_palette->addRange(palData); // Get the scene background surface M4Surface *bg = _vm->_scene->getBackgroundSurface(); // Write the sprite onto the screen int x = 0, y = 0, yMax = 0; for (int index = 0; index < asset->getCount(); index++) { M4Sprite *spr = asset->getFrame(index); spr->translate(palData); // sprite pixel translation if ((x + spr->width() >= bg->width()) && (yMax != 0)) { x = 0; y += yMax; yMax = 0; } if (y >= bg->height()) break; // FIXME: We assume that the transparent color is the color of the top left pixel byte *transparentColor = (byte *)spr->pixels; spr->copyTo(bg, x, y, (int)*transparentColor); x += spr->width(); yMax = MAX(yMax, spr->height()); } view->restore(0, 0, view->width(), view->height()); return false; } return true; }
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; }
bool OrionMenuView::loadSprites(const char *seriesName) { Common::SeekableReadStream *data = _vm->res()->get(seriesName); RGB8 *palette; _sprites = new SpriteAsset(_vm, data, data->size(), seriesName); palette = _sprites->getPalette(); _vm->_palette->setPalette(palette, 0, _sprites->getColorCount()); _vm->res()->toss(seriesName); // Update the palette //_vm->setPalette((byte *) _menuPalette, 59, 197); // The first sprite is the menu background M4Sprite *bg = _sprites->getFrame(0); this->setSize(bg->width(), bg->height()); _coords.setWidth(bg->width()); _coords.setHeight(bg->height()); bg->copyTo(this); return true; }
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; } }