Ejemplo n.º 1
0
void EC_ChatBubble::Refresh()
{
    if (renderer_.expired() || !billboardSet_ || !billboard_)
        return;

    // If no messages in the log, hide the chat bubble.
    if (messages_.isEmpty())
    {
        billboardSet_->setVisible(false);
        return;
    }
    else
        billboardSet_->setVisible(true);

    // Get image buffer and texture
    QImage buffer = GetChatBubblePixmap().toImage();
    Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName(texture_name_);
    if (buffer.isNull() || texture.isNull())
        return;

    // Check texture size
    if ((int)texture->getWidth() != buffer.width() || (int)texture->getHeight() != buffer.height())
    {
        texture->freeInternalResources();
        texture->setWidth(buffer.width());
        texture->setHeight(buffer.height());
        texture->createInternalResources();
    }

    // Update texture buffer
    Ogre::Box update_box(0,0, buffer.width(), buffer.height());
    Ogre::PixelBox pixel_box(update_box, Ogre::PF_A8R8G8B8, (void*)buffer.bits());
    if (!texture->getBuffer().isNull())
        texture->getBuffer()->blitFromMemory(pixel_box, update_box);
}
Ejemplo n.º 2
0
void RenderWindow::Resize(int width, int height)
{
    renderWindow->resize(width, height);
    renderWindow->windowMovedOrResized();

    if (Ogre::TextureManager::getSingletonPtr() && Ogre::OverlayManager::getSingletonPtr())
    {
        PROFILE(RenderWindow_Resize);

        // recenter the overlay
//        int left = (renderWindow->getWidth() - width) / 2;
//        int top = (renderWindow->getHeight() - height) / 2;

        // resize the container
 //       overlayContainer->setDimensions(width, height);
  //      overlayContainer->setPosition(left, top);
        overlayContainer->setDimensions((Ogre::Real)width, (Ogre::Real)height);
        overlayContainer->setPosition(0,0);

        // resize the backing texture
        Ogre::TextureManager &mgr = Ogre::TextureManager::getSingleton();
        Ogre::TexturePtr texture = mgr.getByName(rttTextureName);
        assert(texture.get());

        texture->freeInternalResources();
        texture->setWidth(width);
        texture->setHeight(height);
        texture->createInternalResources();
    }
}
Ejemplo n.º 3
0
    void QOgreWorldView::ResizeOverlay(int width, int height)
    {
        if (Ogre::TextureManager::getSingletonPtr() && Ogre::OverlayManager::getSingletonPtr())
        {
            PROFILE(QOgreWorldView_ResizeOverlay);
            
            // recenter the overlay
            int left = (win_->getWidth() - width) / 2;
            int top = (win_->getHeight() - height) / 2;

            // resize the container
            ui_overlay_container_->setDimensions(width, height);
            ui_overlay_container_->setPosition(left, top);

            // resize the backing texture
            Ogre::TextureManager &mgr = Ogre::TextureManager::getSingleton();
            Ogre::TexturePtr texture = mgr.getByName(texture_name_);
            assert(texture.get());

            texture->freeInternalResources();
            texture->setWidth(width);
            texture->setHeight(height);
            texture->createInternalResources();
        }
    }
Ejemplo n.º 4
0
void EC_WidgetCanvas::Update()
{
    if (framework->IsHeadless())
        return;

    if (!widget_.data() || texture_name_.empty())
        return;
    if (widget_->width() <= 0 || widget_->height() <= 0)
        return;

    try
    {
        Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName(texture_name_);
        if (texture.isNull())
            return;

        if (buffer_.size() != widget_->size())
            buffer_ = QImage(widget_->size(), QImage::Format_ARGB32_Premultiplied);
        if (buffer_.width() <= 0 || buffer_.height() <= 0)
            return;

        QPainter painter(&buffer_);
        widget_->render(&painter);

        // Set texture to material
        if (update_internals_ && !material_name_.empty())
        {
            Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(material_name_);
            if (material.isNull())
                return;
            // Just for good measure, this is done once in the ctor already if everything went well.
            OgreRenderer::SetTextureUnitOnMaterial(material, texture_name_);
            UpdateSubmeshes();
            update_internals_ = false;
        }

        if ((int)texture->getWidth() != buffer_.width() || (int)texture->getHeight() != buffer_.height())
        {
            texture->freeInternalResources();
            texture->setWidth(buffer_.width());
            texture->setHeight(buffer_.height());
            texture->createInternalResources();
        }

        Blit(buffer_, texture);
    }
    catch (Ogre::Exception &e) // inherits std::exception
    {
        LogError("Exception occurred while blitting texture data from memory: " + std::string(e.what()));
    }
    catch (...)
    {
        LogError("Unknown exception occurred while blitting texture data from memory.");
    }
}
Ejemplo n.º 5
0
void EC_WidgetCanvas::Update(QImage buffer)
{
    if (framework->IsHeadless())
        return;
    if (buffer.width() <= 0 || buffer.height() <= 0)
        return;

    if (buffer.format() != QImage::Format_ARGB32 && buffer.format() != QImage::Format_ARGB32_Premultiplied)
    {
        LogWarning("EC_WidgetCanvas::Update(QImage buffer): Input format needs to be Format_ARGB32 or Format_ARGB32_Premultiplied, preforming auto conversion!");
        buffer = buffer.convertToFormat(QImage::Format_ARGB32);
        if (buffer.isNull())
        {
            LogError("-- Auto conversion failed, not updating!");
            return;
        }
    }

    try
    {
        Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName(texture_name_);
        if (texture.isNull())
            return;

        // Set texture to material if need be
        if (update_internals_ && !material_name_.empty())
        {
            Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(material_name_);
            if (material.isNull())
                return;
            // Just for good measure, this is done once in the ctor already if everything went well.
            OgreRenderer::SetTextureUnitOnMaterial(material, texture_name_);
            UpdateSubmeshes();
            update_internals_ = false;
        }

        if ((int)texture->getWidth() != buffer.width() || (int)texture->getHeight() != buffer.height())
        {
            texture->freeInternalResources();
            texture->setWidth(buffer.width());
            texture->setHeight(buffer.height());
            texture->createInternalResources();
        }

        Blit(buffer, texture);
    }
    catch (Ogre::Exception &e) // inherits std::exception
    {
        LogError("Exception occurred while blitting texture data from memory: " + std::string(e.what()));
    }
    catch (...)
    {
        LogError("Unknown exception occurred while blitting texture data from memory.");
    }
}
Ejemplo n.º 6
0
void SaveGameDialog::onSlotSelected(MyGUI::ListBox *sender, size_t pos)
{
    if (pos == MyGUI::ITEM_NONE)
    {
        mCurrentSlot = NULL;
        mInfoText->setCaption("");
        mScreenshot->setImageTexture("");
        return;
    }

    if (mSaving)
        mSaveNameEdit->setCaption(sender->getItemNameAt(pos));

    mCurrentSlot = NULL;
    unsigned int i=0;
    for (MWState::Character::SlotIterator it = mCurrentCharacter->begin(); it != mCurrentCharacter->end(); ++it, ++i)
    {
        if (i == pos)
            mCurrentSlot = &*it;
    }
    assert(mCurrentSlot && "Can't find selected slot");

    std::stringstream text;
    time_t time = mCurrentSlot->mTimeStamp;
    struct tm* timeinfo;
    timeinfo = localtime(&time);

    // Use system/environment locale settings for datetime formatting
    setlocale(LC_TIME, "");

    const int size=1024;
    char buffer[size];
    if (std::strftime(buffer, size, "%x %X", timeinfo) > 0)
        text << buffer << "\n";
    text << "Level " << mCurrentSlot->mProfile.mPlayerLevel << "\n";
    text << mCurrentSlot->mProfile.mPlayerCell << "\n";
    // text << "Time played: " << slot->mProfile.mTimePlayed << "\n";

    int hour = int(mCurrentSlot->mProfile.mInGameTime.mGameHour);
    bool pm = hour >= 12;
    if (hour >= 13) hour -= 12;
    if (hour == 0) hour = 12;

    text
            << mCurrentSlot->mProfile.mInGameTime.mDay << " "
            << MWBase::Environment::get().getWorld()->getMonthName(mCurrentSlot->mProfile.mInGameTime.mMonth)
            <<  " " << hour << " " << (pm ? "#{sSaveMenuHelp05}" : "#{sSaveMenuHelp04}");

    mInfoText->setCaptionWithReplacing(text.str());

    // Decode screenshot
    std::vector<char> data = mCurrentSlot->mProfile.mScreenshot; // MemoryDataStream doesn't work with const data :(
    Ogre::DataStreamPtr stream(new Ogre::MemoryDataStream(&data[0], data.size()));
    Ogre::Image image;
    image.load(stream, "jpg");

    const std::string textureName = "@savegame_screenshot";
    Ogre::TexturePtr texture;
    texture = Ogre::TextureManager::getSingleton().getByName(textureName);
    mScreenshot->setImageTexture("");
    if (texture.isNull())
    {
        texture = Ogre::TextureManager::getSingleton().createManual(textureName,
                  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                  Ogre::TEX_TYPE_2D,
                  image.getWidth(), image.getHeight(), 0, Ogre::PF_BYTE_RGBA, Ogre::TU_DYNAMIC_WRITE_ONLY);
    }
    texture->unload();
    texture->setWidth(image.getWidth());
    texture->setHeight(image.getHeight());
    texture->loadImage(image);

    mScreenshot->setImageTexture(textureName);
}