void AmmoBeltDialog::draw() { Rect bounds = _bounds; if (!_savedArea) { // Save the covered background area _savedArea = surfaceGetArea(g_globals->_gfxManagerInstance.getSurface(), _bounds); } else { bounds.moveTo(0, 0); } // Draw the dialog image g_globals->gfxManager().copyFrom(_surface, bounds.left, bounds.top); // Setup clip flags bool clip1 = true, clip2 = true; bool gunLoaded = BF_GLOBALS.getFlag(fGunLoaded); if (gunLoaded) { // A clip is currently loaded. Hide the appropriate clip if (BF_GLOBALS.getFlag(fLoadedSpare)) clip2 = false; else clip1 = false; } // Draw the first clip if necessary if (clip1) { GfxSurface clipSurface = surfaceFromRes(9, 6, BF_GLOBALS._clip1Bullets + 1); _clip1Rect.resize(clipSurface, _clip1Rect.left, _clip1Rect.top, 100); g_globals->gfxManager().copyFrom(clipSurface, bounds.left + _clip1Rect.left, bounds.top + _clip1Rect.top); } // Draw the second clip if necessary if (clip2) { GfxSurface clipSurface = surfaceFromRes(9, 6, BF_GLOBALS._clip2Bullets + 1); _clip2Rect.resize(clipSurface, _clip2Rect.left, _clip2Rect.top, 100); g_globals->gfxManager().copyFrom(clipSurface, bounds.left + _clip2Rect.left, bounds.top + _clip2Rect.top); } // If a clip is loaded, draw the 'loaded' portion of the gun if (gunLoaded) { GfxSurface loadedSurface = surfaceFromRes(9, 7, 1); _loadedRect.resize(loadedSurface, _loadedRect.left, _loadedRect.top, 100); g_globals->gfxManager().copyFrom(loadedSurface, bounds.left + _loadedRect.left, bounds.top + _loadedRect.top); } }
/** * This dialog implements the right-click dialog */ RightClickDialog::RightClickDialog() : GfxDialog(), _walkButton(1, 48, 12), _lookButton(2, 31, 29), _useButton(3, 65, 29), _talkButton(4, 14, 47), _inventoryButton(5, 48, 47), _optionsButton(6, 83, 47) { Rect rectArea, dialogRect; // Set the palette and change the cursor _gfxManager.setDialogPalette(); g_globals->_events.setCursor(CURSOR_ARROW); // Get the dialog image _surface = surfaceFromRes(7, 1, 1); // Set the dialog position dialogRect.resize(_surface, 0, 0, 100); dialogRect.center(g_globals->_events._mousePos.x, g_globals->_events._mousePos.y); // Ensure the dialog will be entirely on-screen Rect screenRect = g_globals->gfxManager()._bounds; screenRect.collapse(4, 4); dialogRect.contain(screenRect); _bounds = dialogRect; _gfxManager._bounds = _bounds; _highlightedButton = NULL; _selectedAction = -1; }
InventoryDialog::InventoryDialog() { // Determine the maximum size of the image of any item in the player's inventory int imgWidth = 0, imgHeight = 0; SynchronizedList<InvObject *>::iterator i; for (i = RING_INVENTORY._itemList.begin(); i != RING_INVENTORY._itemList.end(); ++i) { InvObject *invObject = *i; if (invObject->inInventory()) { // Get the image for the item GfxSurface itemSurface = surfaceFromRes(invObject->_displayResNum, invObject->_rlbNum, invObject->_cursorNum); // Maintain the dimensions of the largest item image imgWidth = MAX(imgWidth, (int)itemSurface.getBounds().width()); imgHeight = MAX(imgHeight, (int)itemSurface.getBounds().height()); // Add the item to the display list GfxInvImage *img = new GfxInvImage(); _images.push_back(img); img->setDetails(invObject->_displayResNum, invObject->_rlbNum, invObject->_cursorNum); img->_invObject = invObject; add(img); } } assert(_images.size() > 0); // Figure out the number of columns/rows to show all the items int cellsSize = 3; while ((cellsSize * cellsSize) < (int)_images.size()) ++cellsSize; // Set the position of each inventory item to be displayed int cellX = 0; Common::Point pt(0, 0); for (uint idx = 0; idx < _images.size(); ++idx) { if (cellX == cellsSize) { // Move to the start of the next line pt.x = 0; pt.y += imgHeight + 2; cellX = 0; } _images[idx]->_bounds.moveTo(pt.x, pt.y); pt.x += imgWidth + 2; ++cellX; } // Set up the buttons pt.y += imgHeight + 2; _btnOk.setText(OK_BTN_STRING); _btnOk._bounds.moveTo((imgWidth + 2) * cellsSize - _btnOk._bounds.width(), pt.y); _btnLook.setText(LOOK_BTN_STRING); _btnLook._bounds.moveTo(_btnOk._bounds.left - _btnLook._bounds.width() - 2, _btnOk._bounds.top); addElements(&_btnLook, &_btnOk, NULL); frame(); setCenter(SCREEN_CENTER_X, SCREEN_CENTER_Y); }
GfxSurface surfaceFromRes(int resNum, int rlbNum, int subNum) { uint size; byte *imgData = _resourceManager->getSubResource(resNum, rlbNum, subNum, &size); GfxSurface surface = surfaceFromRes(imgData); DEALLOCATE(imgData); return surface; }
void SceneArea::setup(int resNum, int rlbNum, int subNum, int actionId) { _resNum = resNum; _rlbNum = rlbNum; _subNum = subNum; _actionId = actionId; _surface = surfaceFromRes(resNum, rlbNum, subNum); }
/** * This dialog implements the right-click dialog */ RightClickDialog::RightClickDialog() : GfxDialog() { // Setup button areas _rectList1[0] = Rect(7, 50, 41, 67); _rectList1[1] = Rect(13, 27, 50, 50); _rectList1[2] = Rect(49, 27, 84, 50); _rectList1[3] = Rect(56, 50, 90, 67); _rectList1[4] = Rect(26, 68, 69, 99); _rectList3[0] = Rect(12, 49, 27, 64); _rectList3[1] = Rect(27, 31, 42, 46); _rectList3[2] = Rect(56, 31, 71, 46); _rectList3[3] = Rect(72, 50, 87, 65); _rectList3[4] = Rect(41, 81, 56, 96); // Set the palette and change the cursor GfxSurface cursor = surfaceFromRes(1, 5, 9); BF_GLOBALS._events.setCursor(cursor); setPalette(); // Get the dialog image _surface = surfaceFromRes(1, 1, 1); // Set the dialog position Rect dialogRect; dialogRect.resize(_surface, 0, 0, 100); dialogRect.center(g_globals->_events._mousePos.x, g_globals->_events._mousePos.y); // Ensure the dialog will be entirely on-screen Rect screenRect = g_globals->gfxManager()._bounds; screenRect.collapse(4, 4); dialogRect.contain(screenRect); // Load selected button images _btnImages.setVisage(1, 2); _bounds = dialogRect; _gfxManager._bounds = _bounds; _highlightedAction = -1; _selectedAction = -1; }
/** * This dialog implements the right-click dialog */ RightClickDialog::RightClickDialog() : GfxDialog() { // Setup button positions _btnList[0] = Common::Point(48, 12); _btnList[1] = Common::Point(31, 29); _btnList[2] = Common::Point(65, 29); _btnList[3] = Common::Point(14, 47); _btnList[4] = Common::Point(48, 47); _btnList[5] = Common::Point(83, 47); // Set the palette and change the cursor _previousCursor = R2_GLOBALS._events.getCursor(); R2_GLOBALS._events.setCursor(CURSOR_ARROW); setPalette(); // Get the dialog image and selected button images if (R2_GLOBALS._sceneManager._sceneNumber == 2900) { _surface = surfaceFromRes(2902, 1, 1); _btnImages.setVisage(2902, 2); } else { _surface = surfaceFromRes(1, 1, 1); _btnImages.setVisage(1, 2); } // Set the dialog position Rect dialogRect; dialogRect.resize(_surface, 0, 0, 100); dialogRect.center(g_globals->_events._mousePos.x, g_globals->_events._mousePos.y); // Ensure the dialog will be entirely on-screen Rect screenRect = g_globals->gfxManager()._bounds; screenRect.collapse(4, 4); dialogRect.contain(screenRect); _bounds = dialogRect; _gfxManager._bounds = _bounds; _highlightedAction = -1; _selectedAction = -1; }
void ModalDialog::drawFrame() { Rect origRect = _bounds; _bounds.collapse(-10, -10); if (g_vm->getGameID() == GType_Ringworld2) { GfxElement::drawFrame(); } else { // Fill the dialog area g_globals->gfxManager().fillRect(origRect, 54); // Draw top line GfxSurface surface = surfaceFromRes(8, 1, 7); for (int xp = _bounds.left + 10; xp < (_bounds.right - 20); xp += 10) surface.draw(Common::Point(xp, _bounds.top)); surface.draw(Common::Point(_bounds.right - 20, _bounds.top)); surface = surfaceFromRes(8, 1, 1); surface.draw(Common::Point(_bounds.left, _bounds.top)); surface = surfaceFromRes(8, 1, 4); surface.draw(Common::Point(_bounds.right - 10, _bounds.top)); // Draw vertical edges surface = surfaceFromRes(8, 1, 2); for (int yp = _bounds.top + 10; yp < (_bounds.bottom - 20); yp += 10) surface.draw(Common::Point(_bounds.left, yp)); surface.draw(Common::Point(_bounds.left, _bounds.bottom - 20)); surface = surfaceFromRes(8, 1, 5); for (int yp = _bounds.top + 10; yp < (_bounds.bottom - 20); yp += 10) surface.draw(Common::Point(_bounds.right - 10, yp)); surface.draw(Common::Point(_bounds.right - 10, _bounds.bottom - 20)); // Draw bottom line surface = surfaceFromRes(8, 1, 8); for (int xp = _bounds.left + 10; xp < (_bounds.right - 20); xp += 10) surface.draw(Common::Point(xp, _bounds.bottom - 10)); surface.draw(Common::Point(_bounds.right - 20, _bounds.bottom - 10)); surface = surfaceFromRes(8, 1, 3); surface.draw(Common::Point(_bounds.left, _bounds.bottom - 10)); surface = surfaceFromRes(8, 1, 6); surface.draw(Common::Point(_bounds.right - 10, _bounds.bottom - 10)); } // Set the dialog's manager bounds _gfxManager._bounds = origRect; }
void EventsClass::pushCursor(CursorType cursorType) { const byte *cursor; bool delFlag = true; uint size; switch (cursorType) { case CURSOR_NONE: // No cursor cursor = _resourceManager->getSubResource(4, 1, 6, &size); break; case CURSOR_LOOK: // Look cursor cursor = _resourceManager->getSubResource(4, 1, 5, &size); break; case CURSOR_USE: // Use cursor cursor = _resourceManager->getSubResource(4, 1, 4, &size); break; case CURSOR_TALK: // Talk cursor cursor = _resourceManager->getSubResource(4, 1, 3, &size); break; case CURSOR_ARROW: // Arrow cursor cursor = CURSOR_ARROW_DATA; delFlag = false; break; case CURSOR_WALK: default: // Walk cursor cursor = CURSOR_WALK_DATA; delFlag = false; break; } // Decode the cursor GfxSurface s = surfaceFromRes(cursor); Graphics::Surface surface = s.lockSurface(); const byte *cursorData = (const byte *)surface.getBasePtr(0, 0); CursorMan.pushCursor(cursorData, surface.w, surface.h, s._centroid.x, s._centroid.y, s._transColor); s.unlockSurface(); if (delFlag) DEALLOCATE(cursor); }
void GfxImage::setDefaults() { GfxElement::setDefaults(); // Decode the image uint size; byte *imgData = _resourceManager->getSubResource(_resNum, _rlbNum, _cursorNum, &size); _surface = surfaceFromRes(imgData); DEALLOCATE(imgData); // Set up the display bounds Rect imgBounds = _surface.getBounds(); imgBounds.moveTo(_bounds.left, _bounds.top); _bounds = imgBounds; }
void RightClickButton::highlight() { if (_savedButton) { // Button was previously highlighted, so de-highlight by restoring saved area g_globals->gfxManager().copyFrom(*_savedButton, _bounds.left, _bounds.top); delete _savedButton; _savedButton = NULL; } else { // Highlight button by getting the needed highlighted image resource _savedButton = Surface_getArea(g_globals->gfxManager().getSurface(), _bounds); uint size; byte *imgData = g_resourceManager->getSubResource(7, 2, _buttonIndex, &size); GfxSurface btnSelected = surfaceFromRes(imgData); g_globals->gfxManager().copyFrom(btnSelected, _bounds.left, _bounds.top); DEALLOCATE(imgData); } }
void UIQuestion::showItem(int resNum, int rlbNum, int frameNum) { GfxDialog::setPalette(); // Get the item to display GfxSurface objImage = surfaceFromRes(resNum, rlbNum, frameNum); Rect imgRect; imgRect.resize(objImage, 0, 0, 100); imgRect.center(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2); // Save the area behind where the image will be displayed GfxSurface *savedArea = surfaceGetArea(GLOBALS.gfxManager().getSurface(), imgRect); // Draw the image GLOBALS.gfxManager().copyFrom(objImage, imgRect); // Wait for a press GLOBALS._events.waitForPress(); // Restore the old area GLOBALS.gfxManager().copyFrom(*savedArea, imgRect); delete savedArea; }
AmmoBeltDialog::AmmoBeltDialog() : GfxDialog() { _cursorNum = BF_GLOBALS._events.getCursor(); _inDialog = -1; _closeFlag = false; // Get the dialog image _surface = surfaceFromRes(9, 5, 2); // Set the dialog position _dialogRect.resize(_surface, 0, 0, 100); _dialogRect.center(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2); _bounds = _dialogRect; _gfxManager._bounds = _bounds; _savedArea = NULL; // Set up area rects _gunRect.set(0, 0, 82, 48); _clip1Rect.set(90, 6, _bounds.width(), 39); _clip2Rect.set(90, 40, _bounds.width(), _bounds.height()); _loadedRect.set(50, 40, 60, 50); }
/** * Sets the specified cursor * * @cursorType Specified cursor number */ void EventsClass::setCursor(CursorType cursorType) { if (cursorType == _lastCursor) return; _lastCursor = cursorType; _globals->clearFlag(122); CursorMan.showMouse(true); const byte *cursor; bool delFlag = true; uint size; switch (cursorType) { case CURSOR_NONE: // No cursor _globals->setFlag(122); if (_vm->getFeatures() & GF_DEMO) { CursorMan.showMouse(false); return; } cursor = _resourceManager->getSubResource(4, 1, 6, &size); break; case CURSOR_LOOK: // Look cursor cursor = _resourceManager->getSubResource(4, 1, 5, &size); _currentCursor = CURSOR_LOOK; break; case CURSOR_USE: // Use cursor cursor = _resourceManager->getSubResource(4, 1, 4, &size); _currentCursor = CURSOR_USE; break; case CURSOR_TALK: // Talk cursor cursor = _resourceManager->getSubResource(4, 1, 3, &size); _currentCursor = CURSOR_TALK; break; case CURSOR_ARROW: // Arrow cursor cursor = CURSOR_ARROW_DATA; delFlag = false; break; case CURSOR_WALK: default: // Walk cursor cursor = CURSOR_WALK_DATA; _currentCursor = CURSOR_WALK; delFlag = false; break; } // Decode the cursor GfxSurface s = surfaceFromRes(cursor); Graphics::Surface surface = s.lockSurface(); const byte *cursorData = (const byte *)surface.getBasePtr(0, 0); CursorMan.replaceCursor(cursorData, surface.w, surface.h, s._centroid.x, s._centroid.y, s._transColor); s.unlockSurface(); if (delFlag) DEALLOCATE(cursor); }
void SceneArea::draw(bool flag) { _surface = surfaceFromRes(_resNum, _rlbNum, flag ? _subNum + 1 : _subNum); _surface.draw(Common::Point(_bounds.left, _bounds.top)); }
/** * Sets the specified cursor * * @cursorType Specified cursor number */ void EventsClass::setCursor(CursorType cursorType) { if (cursorType == _lastCursor) return; _lastCursor = cursorType; g_globals->clearFlag(122); CursorMan.showMouse(true); const byte *cursor; bool delFlag = true; uint size; bool questionEnabled = false; switch (cursorType) { case CURSOR_NONE: // No cursor g_globals->setFlag(122); if ((g_vm->getGameID() != GType_Ringworld) || ((g_vm->getGameID() == GType_Ringworld) && (g_vm->getFeatures() & GF_DEMO))) { CursorMan.showMouse(false); return; } cursor = g_resourceManager->getSubResource(4, 1, 6, &size); break; case CURSOR_LOOK: // Look cursor if (g_vm->getGameID() == GType_BlueForce) { cursor = g_resourceManager->getSubResource(1, 5, 3, &size); } else if (g_vm->getGameID() == GType_Ringworld2) { cursor = g_resourceManager->getSubResource(5, 1, 5, &size); } else { cursor = g_resourceManager->getSubResource(4, 1, 5, &size); } _currentCursor = CURSOR_LOOK; break; case CURSOR_USE: // Use cursor if (g_vm->getGameID() == GType_BlueForce) { cursor = g_resourceManager->getSubResource(1, 5, 2, &size); } else if (g_vm->getGameID() == GType_Ringworld2) { cursor = g_resourceManager->getSubResource(5, 1, 4, &size); } else { cursor = g_resourceManager->getSubResource(4, 1, 4, &size); } _currentCursor = CURSOR_USE; break; case CURSOR_TALK: // Talk cursor if (g_vm->getGameID() == GType_BlueForce) { cursor = g_resourceManager->getSubResource(1, 5, 4, &size); } else if (g_vm->getGameID() == GType_Ringworld2) { cursor = g_resourceManager->getSubResource(5, 1, 6, &size); } else { cursor = g_resourceManager->getSubResource(4, 1, 3, &size); } _currentCursor = CURSOR_TALK; break; case CURSOR_EXIT: // Exit cursor (Blue Force) assert(g_vm->getGameID() == GType_BlueForce); cursor = g_resourceManager->getSubResource(1, 5, 7, &size); _currentCursor = CURSOR_EXIT; break; case CURSOR_PRINTER: // Printer cursor (Blue Force) assert(g_vm->getGameID() == GType_BlueForce); cursor = g_resourceManager->getSubResource(1, 7, 6, &size); _currentCursor = CURSOR_PRINTER; break; case CURSOR_ARROW: // Arrow cursor cursor = CURSOR_ARROW_DATA; delFlag = false; break; case CURSOR_WALK: default: switch (g_vm->getGameID()) { case GType_BlueForce: if (cursorType == CURSOR_WALK) { cursor = g_resourceManager->getSubResource(1, 5, 1, &size); } else { // Inventory icon cursor = g_resourceManager->getSubResource(10, ((int)cursorType - 1) / 20 + 1, ((int)cursorType - 1) % 20 + 1, &size); questionEnabled = true; } _currentCursor = cursorType; break; case GType_Ringworld2: if (cursorType == CURSOR_WALK) { cursor = CURSOR_WALK_DATA; delFlag = false; } else { // Inventory icon InvObject *invObject = g_globals->_inventory->getItem((int)cursorType); cursor = g_resourceManager->getSubResource(6, invObject->_strip, invObject->_frame, &size); questionEnabled = true; } _currentCursor = cursorType; break; default: // For Ringworld, always treat as the walk cursor cursor = CURSOR_WALK_DATA; _currentCursor = CURSOR_WALK; delFlag = false; break; } break; // Ringworld 2 specific cursors case EXITCURSOR_N: case EXITCURSOR_S: case EXITCURSOR_W: case EXITCURSOR_E: case EXITCURSOR_LEFT_HAND: case CURSOR_INVALID: case EXITCURSOR_NE: case EXITCURSOR_SE: case EXITCURSOR_SW: case EXITCURSOR_NW: case SHADECURSOR_UP: case SHADECURSOR_DOWN: case SHADECURSOR_HAND: _currentCursor = cursorType; cursor = g_resourceManager->getSubResource(5, 1, cursorType - R2CURSORS_START, &size); break; case R2_CURSOR_ROPE: _currentCursor = cursorType; cursor = g_resourceManager->getSubResource(5, 4, 1, &size); break; } // Decode the cursor GfxSurface s = surfaceFromRes(cursor); Graphics::Surface surface = s.lockSurface(); const byte *cursorData = (const byte *)surface.getPixels(); CursorMan.replaceCursor(cursorData, surface.w, surface.h, s._centroid.x, s._centroid.y, s._transColor); s.unlockSurface(); if (delFlag) DEALLOCATE(cursor); // For Blue Force and Return to Ringworld, enable the question button when an inventory icon is selected if (g_vm->getGameID() != GType_Ringworld) T2_GLOBALS._uiElements._question.setEnabled(questionEnabled); }