// Callback for Link Browser
void ManageBackgroundScreen::CallBack( Fl_Widget* w )
{
    assert( m_ScreenMgr );

    MainVSPScreen* main = dynamic_cast<MainVSPScreen*>( m_ScreenMgr->GetScreen( m_ScreenMgr->VSP_MAIN_SCREEN ) );
    if( !main )
    {
        return;
    }

    VSPGUI::VspGlWindow * glwin = main->GetGLWindow();

    VSPGraphic::Viewport * viewport = glwin->getGraphicEngine()->getDisplay()->getViewport();
    if( !viewport )
    {
        return;
    }

    if ( w == colorChooser )
    {
        viewport->getBackground()->setRed( ( float )( colorChooser->r() ) );
        viewport->getBackground()->setGreen( ( float )( colorChooser->g() ) );
        viewport->getBackground()->setBlue( ( float )( colorChooser->b() ) );
    }

    m_ScreenMgr->SetUpdateFlag( true );
}
bool ManageBackgroundScreen::Update()
{
    MainVSPScreen* main = dynamic_cast<MainVSPScreen*>( m_ScreenMgr->GetScreen( m_ScreenMgr->VSP_MAIN_SCREEN ) );
    if( !main )
    {
        return false;
    }

    VSPGUI::VspGlWindow * glwin = main->GetGLWindow();

    VSPGraphic::Viewport * viewport = glwin->getGraphicEngine()->getDisplay()->getViewport();
    if( !viewport )
    {
        return false;
    }

    VSPGraphic::Common::VSPenum mode = viewport->getBackground()->getBackgroundMode();
    if ( mode == VSPGraphic::Common::VSP_BACKGROUND_COLOR )
    {
        m_ColorLayout.GetGroup()->activate();
        m_ImageLayout.GetGroup()->deactivate();
    }
    else
    {
        m_ColorLayout.GetGroup()->deactivate();
        m_ImageLayout.GetGroup()->activate();
    }

    if ( m_PreserveAspect.GetFlButton()->value() )
    {
        m_PreserveAspectLayout.GetGroup()->deactivate();
    }
    else
    {
        m_PreserveAspectLayout.GetGroup()->activate();
    }

    //Update Scale and Offset in Background
    m_WScale.Update( m_WidthScaleValue.GetID() );
    m_HScale.Update( m_HeightScaleValue.GetID() );

    viewport->getBackground()->scaleW( (float) m_WidthScaleValue.Get() );
    if (m_PreserveAspect.GetFlButton()->value())
    {
        m_HeightScaleValue.Set( viewport->getBackground()->getScaleH() );
    }
    else
    {
        viewport->getBackground()->scaleH( (float) m_HeightScaleValue.Get() );
    }

    m_XOffset.Update( m_XOffsetValue.GetID() );
    m_YOffset.Update( m_YOffsetValue.GetID() );

    viewport->getBackground()->offsetX( (float) m_XOffsetValue.Get() );
    viewport->getBackground()->offsetY( (float) m_YOffsetValue.Get() );

    m_FLTK_Window->redraw();
    return false;
}
// Callback for all other GUI Devices
void ManageBackgroundScreen::GuiDeviceCallBack( GuiDevice* device )
{
    assert( m_ScreenMgr );

    MainVSPScreen* main = dynamic_cast<MainVSPScreen*>( m_ScreenMgr->GetScreen( m_ScreenMgr->VSP_MAIN_SCREEN ) );
    if( !main )
    {
        return;
    }

    VSPGUI::VspGlWindow * glwin = main->GetGLWindow();

    VSPGraphic::Viewport * viewport = glwin->getGraphicEngine()->getDisplay()->getViewport();
    if( !viewport )
    {
        return;
    }

    if ( device == &m_Color )
    {
        m_Color.GetFlButton()->value( 1 );
        m_Image.GetFlButton()->value( 0 );
        viewport->getBackground()->removeImage();
        viewport->getBackground()->setBackgroundMode( VSPGraphic::Common::VSP_BACKGROUND_COLOR );
    }
    else if ( device == &m_Image )
    {
        m_Color.GetFlButton()->value( 0 );
        m_Image.GetFlButton()->value( 1 );
        viewport->getBackground()->setBackgroundMode( VSPGraphic::Common::VSP_BACKGROUND_IMAGE );

        if ( m_ImageFile.compare( "" ) != 0 )
        {
            viewport->getBackground()->attachImage( VSPGraphic::GlobalTextureRepo()->get2DTexture( m_ImageFile.c_str() ) );
        }
    }
    else if ( device == &m_FileSelect )
    {
        std::string fileName = m_ScreenMgr->GetSelectFileScreen()->FileChooser(
                "Select Image File", "*.{jpg,png,tga,bmp,gif}", false );

        if( !fileName.empty() )
        {
            viewport->getBackground()->removeImage();
            viewport->getBackground()->attachImage( VSPGraphic::GlobalTextureRepo()->get2DTexture( fileName.c_str() ) );
            m_ImageFile = fileName;
            m_FileOutput.Update( truncateFileName( fileName, 40 ).c_str() );
        }
    }
    else if ( device == &m_PreserveAspect )
    {
        if ( m_PreserveAspect.GetFlButton()->value() == 1 )
        {
            viewport->getBackground()->preserveAR( true );
        }
        else
        {
            viewport->getBackground()->preserveAR( false );
        }
    }
    else if ( device == &m_ResetDefaults )
    {
        viewport->getBackground()->reset();
        colorChooser->rgb( viewport->getBackground()->getRed(), viewport->getBackground()->getGreen(),
                           viewport->getBackground()->getBlue() );
        m_FileOutput.Update("");
        m_ImageFile = "";

        //Reset Scale & Offset
        m_WidthScaleValue.Set( viewport->getBackground()->getScaleW() );
        m_HeightScaleValue.Set( viewport->getBackground()->getScaleH() );

        m_XOffsetValue.Set( viewport->getBackground()->getOffsetX() );
        m_YOffsetValue.Set( viewport->getBackground()->getOffsetY() );
    }

    m_ScreenMgr->SetUpdateFlag( true );
}
Пример #4
0
bool ManageTextureScreen::Update()
{
    assert( m_ScreenMgr );

    Vehicle* veh = m_ScreenMgr->GetVehiclePtr();
    vector< Geom* > select_vec = veh->GetActiveGeomPtrVec();

    if ( select_vec.size() != 1 )
    {
        Hide();
        return false;
    }

    // Redo list on each update.
    m_TextureMgrUI->compChoice->clear();
    m_CompDropDownList.clear();

    std::vector<Geom *> geomVec = veh->FindGeomVec( veh->GetGeomVec() );
    for( int i = 0; i < ( int )geomVec.size(); i++ )
    {
        CompDropDownItem item;
        item.GeomName = geomVec[i]->GetName();
        item.GeomID = geomVec[i]->GetID();

        // Hack to add duplicate names
        char str[256];
        sprintf( str, "%d", i );
        item.GUIIndex = m_TextureMgrUI->compChoice->add( str );

        m_CompDropDownList.push_back( item );
    }
    // Fill Hacked char array with correct names.
    for( int i = 0; i < ( int )m_CompDropDownList.size(); i++ )
    {
        m_TextureMgrUI->compChoice->replace( m_CompDropDownList[i].GUIIndex, m_CompDropDownList[i].GeomName.c_str() );
    }

    // Set compChoice to current selected and update texture dropdown list.
    for( int i = 0; i < ( int )m_CompDropDownList.size(); i++ )
    {
        if( m_CompDropDownList[i].GeomID == select_vec[0]->GetID() )
        {
            m_TextureMgrUI->compChoice->value( m_CompDropDownList[i].GUIIndex );

            // Update Texture Dropdown List. //

            // Redo texture list on each update.
            m_TextureMgrUI->textureChoice->clear();
            m_TexDropDownList.clear();

            // Clear preview window.
            VSPGraphic::Viewport * viewport = m_GlWin->getGraphicEngine()->getDisplay()->getViewport();
            assert( viewport );
            viewport->getBackground()->removeImage();

            // Load Textures...
            TextureMgr * texMgr = select_vec[0]->m_GuiDraw.getTextureMgr();
            std::vector<Texture*> texInfos = texMgr->FindTextureVec( texMgr->GetTextureVec() );
            for( int j = 0; j < ( int )texInfos.size(); j++ )
            {
                TexDropDownItem item;
                item.TexInfo = texInfos[j];

                // Hack to add duplicate names
                char str[256];
                sprintf( str, "%d", j );
                item.GUIIndex = m_TextureMgrUI->textureChoice->add( str );

                m_TexDropDownList.push_back( item );
            }
            // Fill Hacked char array with correct names.
            for( int j = 0; j < ( int )m_TexDropDownList.size(); j++ )
            {
                m_TextureMgrUI->textureChoice->replace( m_TexDropDownList[j].GUIIndex, m_TexDropDownList[j].TexInfo->GetName().c_str() );
            }
            if( !m_TexDropDownList.empty() )
            {
                if( m_SelectedTexItem )
                {
                    m_TextureMgrUI->textureChoice->value( m_SelectedTexItem->GUIIndex );
                }
                else
                {
                    // On refresh list, if nothing is selected, pick last item on list.
                    m_TextureMgrUI->textureChoice->value( m_TexDropDownList[m_TexDropDownList.size() - 1].GUIIndex );
                }
                UpdateCurrentSelected();

                assert( m_SelectedTexItem );

                viewport->getBackground()->attachImage( VSPGraphic::GlobalTextureRepo()->
                    get2DTexture( m_SelectedTexItem->TexInfo->m_FileName.c_str() ) );
            }
            else
            {
                ResetCurrentSelected();

                // Force redraw empty list.
                m_TextureMgrUI->textureChoice->redraw();
            }

            // Update Sliders and Buttons.
            if( m_SelectedTexItem )
            {
                Texture * info = select_vec[0]->m_GuiDraw.getTextureMgr()->FindTexture( m_SelectedTexItem->TexInfo->GetID() );

                m_TextureMgrUI->textureNameInput->value( info->GetName().c_str() );

                m_UScaleSlider.Update( info->m_UScale.GetID() );
                m_WScaleSlider.Update( info->m_WScale.GetID() );

                m_UPosSlider.Update( info->m_U.GetID() );
                m_WPosSlider.Update( info->m_W.GetID() );

                m_TransparencySlider.Update( info->m_Transparency.GetID() );

                m_FlipUButton.Update( info->m_FlipU.GetID() );
                m_FlipWButton.Update( info->m_FlipW.GetID() );
            }
            break;
        }
    }
    m_GlWin->redraw();
    return true;
}