rendered paste bodyclass GSCShow{public: static GSCShow* GetInstance(); ~GSCShow(); bool Initialize(const char* sdfName); void Execute(); private: GSCShow(); GSCShow(const GSCShow& rhs); const GSCShow& operator=(const GSCShow& rhs); Sprite* spriteDef_; ImageList* spriteFrames_; unsigned int startFrame_; unsigned int currentFrame_; unsigned int lastFrame_; unsigned int currentAnimation_; ImageResource* spriteInfoPanel_; ImageResource* spriteAnimPanel_;};/******************************************************************************/GSCShow* GSCShow::GetInstance(){ static GSCShow instance; return &instance;}bool GSCShow::Initialize(const char* sdfName){ spriteDef_ = new Sprite(); if (!spriteDef_->Load(sdfName)) { LogFatal("Could not load the sprite definition file %s!", sdfName); } // initialize Allegro if (0 != allegro_init()) { LogFatal("Could not initialize Allegro!"); } // install the Allegro timer driver if (0 != install_timer()) { LogFatal("Could not install Allegro Timer driver!"); } // setup the graphics device GraphicsDevice->SetDisplay( 800, 600, GraphicsDevice_24bit, GraphicsDevice_Windowed); // setup the input device InputDevice->Initialize(INIT_KEYBOARD | INIT_MOUSE); // load the sprite sheet ImageResource spriteSheet(spriteDef_->GetSourceImageName().c_str()); // rip the actual sprite frames spriteFrames_ = new ImageList(); int spriteWidth = spriteDef_->GetWidth(); int spriteHeight = spriteDef_->GetHeight(); int ripColCount = spriteSheet.GetWidth() / (spriteWidth + 1); int ripRowCount = spriteSheet.GetHeight() / (spriteHeight + 1); for (int row = 0; row < ripRowCount; row++) { for (int col = 0; col < ripColCount; col++) { int ripFrom[4] = { 1 + col * (spriteWidth + 1), 1 + row * (spriteHeight + 1), spriteWidth, spriteHeight }; ImageResource* frame = new ImageResource(spriteWidth, spriteHeight, makecol(255, 0, 255)); spriteSheet.Blit(frame, ripFrom[0], ripFrom[1], 0, 0, ripFrom[2], ripFrom[3]); //fprintf(stderr, "Rip From: %4d, %4d - %4d, %4d\n", ripFrom[0], ripFrom[1], ripFrom[0] + ripFrom[2], ripFrom[1] + ripFrom[3]); spriteFrames_->Add(frame); } } // create the panels spriteInfoPanel_ = new ImageResource(800, 600, makecol(0, 0, 255)); spriteAnimPanel_ = new ImageResource(512, 511); // write the sprite information on the info panel // this never changes, so we write it once BitmapFont debugFont; int cursorX = 4, cursorY = 4; debugFont.Print(spriteInfoPanel_, cursorX, cursorY, "Sprite: %s", sdfName); cursorY += 10; debugFont.Print(spriteInfoPanel_, cursorX, cursorY, "Source Image: %s", spriteDef_->GetSourceImageName().c_str()); cursorY += 10; debugFont.Print(spriteInfoPanel_, cursorX, cursorY, "Frame Size: %d x %d", spriteDef_->GetWidth(), spriteDef_->GetHeight()); cursorY += 10; std::vector<SpriteAnimation*> animations = spriteDef_->GetAnimationList(); unsigned int animCount = animations.size(); debugFont.Print(spriteInfoPanel_, cursorX, cursorY, "Animations:"); cursorY += 10; debugFont.Print(spriteInfoPanel_, cursorX, cursorY, "START FRAME | END FRAME | SEQUENCE NAME"); cursorY += 10; debugFont.Print(spriteInfoPanel_, cursorX, cursorY, "----------------------------------------------------------------------"); cursorY += 10; for (unsigned int index = 0; index < animCount; index++) { debugFont.Print( spriteInfoPanel_, cursorX, cursorY, "%11d | %9d | %s", animations.at(index)->GetFirstFrameIndex(), animations.at(index)->GetFirstFrameIndex() + animations.at(index)->GetFrameCount() - 1, animations.at(index)->GetName().c_str()); cursorY += 10; } spriteSheet.BlitSprite(spriteInfoPanel_, 0, cursorY); return true;}void GSCShow::Execute(){ ImageResource* display = GraphicsDevice->GetSecondaryDisplayBuffer(); int dw = display->GetWidth(); int dh = display->GetHeight(); BitmapFont debugFont; bool showInfoPanel = false; bool running = true; while(running) { InputDevice->Update(UPDATE_KEYBOARD | UPDATE_MOUSE); if (InputDevice->KeyPressed(KEY::Key_Escape)) { running = false; } if (InputDevice->KeyPressed(KEY::Key_Tab)) { showInfoPanel = !showInfoPanel; } GraphicsDevice->BeginScene(); if (showInfoPanel) { spriteInfoPanel_->Blit(display, 0, 0, 0, 0, spriteInfoPanel_->GetWidth(), spriteInfoPanel_->GetHeight()); } else { // draw the sprite #if 0 std::vector<SpriteAnimation*> animations = spriteDef_->GetAnimationList(); ImageResource* currentFrame = spriteFrames_->Get(animations.at(currentAnimation_)->GetFirstFrameIndex()); currentFrame->BlitSprite(display, 400 - currentFrame->GetWidth() / 2, 300 - currentFrame->GetHeight() / 2); #endif // draw the sprite anim panel std::vector<SpriteAnimation*> animations = spriteDef_->GetAnimationList(); unsigned int animCount = animations.size(); unsigned int y = 1, x = 1; for (unsigned int animIndex = 0; animIndex < animCount; animIndex++) { unsigned int id = animations.at(animIndex)->GetFirstFrameIndex(); ImageResource* animFrame = spriteFrames_->Get(id); if (animFrame) { int scaleWidth = animFrame->GetWidth() * 3; int scaleHeight = animFrame->GetHeight() * 3; // animFrame->BlitSprite(spriteAnimPanel_, 8, y); animFrame->Blit(spriteAnimPanel_, 0, 0, animFrame->GetWidth(), animFrame->GetHeight(), x, y, scaleWidth, scaleHeight); x += scaleWidth + 1; int xLimit = spriteAnimPanel_->GetWidth() / scaleWidth; if (0 == (animIndex % xLimit) && animIndex != 0) { y += scaleHeight + 1; } } } spriteAnimPanel_->Blit(display, 0, 0, 1, 11, spriteAnimPanel_->GetWidth(), spriteAnimPanel_->GetHeight()); display->Rect(0, 0, dw - 1, dh - 1, makecol(192, 192, 192)); display->Line(dw / 2, 10, dw / 2, dh - 1, makecol(192, 192, 192)); display->Line(0, 10, dw - 1, 10, makecol(192, 192, 192)); debugFont.Print(display, 2, 2, "Cursor: %d, %d", InputDevice->MouseX(), InputDevice->MouseY()); show_mouse(display->GetBitmap()); } GraphicsDevice->EndScene(); rest(10); } show_mouse(0);}GSCShow::GSCShow() : spriteDef_(0), spriteFrames_(0), spriteInfoPanel_(0), spriteAnimPanel_(0){ currentAnimation_ = 0; currentFrame_ = 0;}GSCShow::~GSCShow(){ if (spriteAnimPanel_) { delete spriteAnimPanel_; } if (spriteInfoPanel_) { delete spriteInfoPanel_; } if (spriteDef_) { delete spriteDef_; } if (spriteFrames_) { delete spriteFrames_; }}