Exemplo n.º 1
0
void TitleState::Draw(Renderer &renderer) const {

  const bool compress_height = (GetStateHeight() < 750);
  const bool compress_width = (GetStateWidth() < 850);

  const static int TitleWidth = 507;
  const static int TitleY = (compress_height ? 20 : 100);

  int left = GetStateWidth() / 2 - TitleWidth / 2;

  renderer.SetColor(White);
  renderer.DrawTga(GetTexture(TitleLogo), left, TitleY);
  renderer.DrawTga(GetTexture(GameMusicThemes), left+3, TitleY + (compress_height ? 120 : 150) );

  TextWriter version(Layout::ScreenMarginX,
                     GetStateHeight() - Layout::ScreenMarginY - Layout::SmallFontSize * 2,
                     renderer, false, Layout::SmallFontSize);

  version << Text("version " + LinthesiaVersionString, Gray);

  Layout::DrawHorizontalRule(renderer,
                             GetStateWidth(),
                             GetStateHeight() - Layout::ScreenMarginY);

  Layout::DrawButton(renderer, m_continue_button, GetTexture(ButtonChooseTracks));
  Layout::DrawButton(renderer, m_back_button, GetTexture(ButtonExit));

  m_output_tile->Draw(renderer);
  m_input_tile->Draw(renderer);
  m_file_tile->Draw(renderer);

  if (m_input_tile->IsPreviewOn()) {

    const static int PreviewWidth = 60;
    const static int PreviewHeight = 40;

    const int x = m_input_tile->GetX() + DeviceTileWidth + 12;
    const int y = m_input_tile->GetY() + 38;

    renderer.SetColor(0xFF, 0xFF, 0xFF);
    renderer.DrawQuad(x, y, PreviewWidth, PreviewHeight);

    renderer.SetColor(0, 0, 0);
    renderer.DrawQuad(x+1, y+1, PreviewWidth-2, PreviewHeight-2);

    TextWriter last_note(x + PreviewWidth/2 - 1,
                         m_input_tile->GetY() + 44,
                         renderer, true, Layout::TitleFontSize);

    Widen<char> w;
    last_note << w(m_last_input_note_name);
  }

  const int tooltip_font_size = (compress_width ? Layout::ButtonFontSize : Layout::TitleFontSize);
  TextWriter tooltip(GetStateWidth() / 2,
                     GetStateHeight() - Layout::ScreenMarginY/2 - tooltip_font_size/2,
                     renderer, true, tooltip_font_size);

  tooltip << m_tooltip;
}
Exemplo n.º 2
0
void PlayingState::Draw(Renderer &renderer) const {

  const Tga *key_tex[3] = { GetTexture(PlayKeyRail),
                            GetTexture(PlayKeyShadow),
                            GetTexture(PlayKeysBlack, true) };

  const Tga *note_tex[4] = { GetTexture(PlayNotesWhiteShadow, true),
                             GetTexture(PlayNotesBlackShadow, true),
                             GetTexture(PlayNotesWhiteColor, true),
                             GetTexture(PlayNotesBlackColor, true) };
  renderer.ForceTexture(0);

  // Draw a keyboard, fallen keys and background for them
  m_keyboard->Draw(renderer, key_tex, note_tex, Layout::ScreenMarginX, 0, m_notes, m_show_duration,
                   m_state.midi->GetSongPositionInMicroseconds(), m_state.track_properties,
                   m_state.midi->GetBarLines());

  string title_text = m_state.song_title;

  double alpha = m_title_alpha;
  if (m_paused) {
    alpha = 1.0;
    title_text = "Game Paused";
  }

  if (alpha > 0.001) {
    renderer.SetColor(0, 0, 0, int(alpha * 160));
    renderer.DrawQuad(0, GetStateHeight() / 3, GetStateWidth(), 80);
    const Color c = Renderer::ToColor(255, 255, 255, int(alpha * 0xFF));
    TextWriter title(GetStateWidth()/2, GetStateHeight()/3 + 25, renderer, true, 24);
    title << Text(title_text, c);

    // While we're at it, show the key legend
    renderer.SetColor(c);
    const Tga *keys = GetTexture(PlayKeys);
    renderer.DrawTga(keys, GetStateWidth() / 2 - 250, GetStateHeight() / 2);
  }

  int text_y = CalcKeyboardHeight() + 42;

  renderer.SetColor(White);
  renderer.DrawTga(GetTexture(PlayStatus),  Layout::ScreenMarginX - 1,   text_y);
  renderer.DrawTga(GetTexture(PlayStatus2), Layout::ScreenMarginX + 273, text_y);

  string multiplier_text = STRING(fixed << setprecision(1) << CalculateScoreMultiplier() <<
                                  " Multiplier");
  string speed_text = STRING(m_state.song_speed << "% Speed");

  TextWriter score(Layout::ScreenMarginX + 92, text_y + 5, renderer,
                   false, Layout::ScoreFontSize);
  score << static_cast<int>(m_state.stats.score);

  TextWriter multipliers(Layout::ScreenMarginX + 232, text_y + 12, renderer,
                         false, Layout::TitleFontSize+2);
  multipliers << Text(multiplier_text, Renderer::ToColor(138, 226, 52));

  int speed_x_offset = (m_state.song_speed >= 100 ? 0 : 11);
  TextWriter speed(Layout::ScreenMarginX + 412 + speed_x_offset, text_y + 12,
                   renderer, false, Layout::TitleFontSize+2);
  speed << Text(speed_text, Renderer::ToColor(114, 159, 207));

  string retry_text = m_should_retry ? "R" : "";

  TextWriter retry(Layout::ScreenMarginX + 600, text_y + 12,
                   renderer, false, Layout::TitleFontSize+2);
  retry << Text(retry_text, Renderer::ToColor(114, 159, 207));

  double non_zero_playback_speed = ( (m_state.song_speed == 0) ? 0.1 : (m_state.song_speed/100.0) );
  microseconds_t tot_seconds = static_cast<microseconds_t>((m_state.midi->GetSongLengthInMicroseconds() /
                                                            100000.0) / non_zero_playback_speed);
  microseconds_t cur_seconds = static_cast<microseconds_t>((m_state.midi->GetSongPositionInMicroseconds() /
                                                            100000.0) / non_zero_playback_speed);

  if (cur_seconds < 0)
    cur_seconds = 0;

  if (cur_seconds > tot_seconds)
    cur_seconds = tot_seconds;

  int completion = static_cast<int>(m_state.midi->GetSongPercentageComplete() * 100.0);

  unsigned int tot_min = static_cast<unsigned int>((tot_seconds/10) / 60);
  unsigned int tot_sec = static_cast<unsigned int>((tot_seconds/10) % 60);
  unsigned int tot_ten = static_cast<unsigned int>( tot_seconds%10);
  const string total_time = STRING(tot_min << ":" << setfill('0') << setw(2) << tot_sec << "." << tot_ten);

  unsigned int cur_min = static_cast<unsigned int>((cur_seconds/10) / 60);
  unsigned int cur_sec = static_cast<unsigned int>((cur_seconds/10) % 60);
  unsigned int cur_ten = static_cast<unsigned int>( cur_seconds%10      );
  const string current_time = STRING(cur_min << ":" << setfill('0') << setw(2) << cur_sec << "." << cur_ten);
  const string percent_complete = STRING(" (" << completion << "%)");

  text_y += 30 + Layout::SmallFontSize;
  TextWriter time_text(Layout::ScreenMarginX + 39, text_y+2, renderer, false, Layout::SmallFontSize);
  time_text << STRING(current_time << " / " << total_time << percent_complete);

  // Draw a song progress bar along the top of the screen
  const int time_pb_width = static_cast<int>(m_state.midi->GetSongPercentageComplete() * (GetStateWidth() -
                                                                                          Layout::ScreenMarginX*2));
  const int pb_x = Layout::ScreenMarginX;
  const int pb_y = CalcKeyboardHeight() + 25;

  renderer.SetColor(0x50, 0x50, 0x50);
  renderer.DrawQuad(pb_x, pb_y, time_pb_width, 16);

  if (m_look_ahead_you_play_note_count > 0) {

    const double note_count = 1.0 * m_look_ahead_you_play_note_count;

    const int note_miss_pb_width = static_cast<int>(m_state.stats.notes_user_could_have_played /
                                                    note_count * (GetStateWidth() - Layout::ScreenMarginX*2));

    const int note_hit_pb_width = static_cast<int>(m_state.stats.notes_user_actually_played /
                                                   note_count * (GetStateWidth() - Layout::ScreenMarginX*2));

    renderer.SetColor(0xCE,0x5C,0x00);
    renderer.DrawQuad(pb_x, pb_y - 20, note_miss_pb_width, 16);

    renderer.SetColor(0xFC,0xAF,0x3E);
    renderer.DrawQuad(pb_x, pb_y - 20, note_hit_pb_width, 16);
  }

  // Show the combo
  if (m_current_combo > 5) {
    int combo_font_size = 20;
    combo_font_size += (m_current_combo / 10);

    int combo_x = GetStateWidth() / 2;
    int combo_y = GetStateHeight() - CalcKeyboardHeight() + 30 - (combo_font_size/2);

    TextWriter combo_text(combo_x, combo_y, renderer, true, combo_font_size);
    combo_text << STRING(m_current_combo << " Combo!");
  }
}
Exemplo n.º 3
0
void World::Render()
{
    if( !mWorldInitialized )
        return;

    Renderer* renderer = GraphicSubsystem::Instance()->GetRenderer();
    GD_ASSERT(renderer);

    UInt32 viewWidth = renderer->GetRenderTarget()->GetWidth();
    UInt32 viewHeight = renderer->GetRenderTarget()->GetHeight();

    // Init.
    //renderer->BeginScene( Renderer::PointList );

    renderer->SetViewport( 0, 0, viewWidth, viewHeight );
    renderer->SetClearColor(Color4f(0.0f, 0.0f, 0.0f, 1.0f));
    renderer->SetRenderState( Renderer::Texture2D, false );
    renderer->SetRenderState( Renderer::DepthTest, true );
    //renderer->SetRenderState( Renderer::Lighting, true );
    //renderer->SetCulling( Renderer::CullBackFace );

    // Render.
    renderer->Clear( Renderer::ColorBuffer | Renderer::DepthBuffer );

    renderer->SetMatrixMode(Renderer::ProjectionMatrix);
    renderer->LoadIdentity();

    Camera* currentCamera = GetCurrentCamera();
    renderer->Perspective(currentCamera->GetFovAngle(),
                          viewWidth / static_cast<Float>(viewHeight),
                          currentCamera->GetNearView(), currentCamera->GetFarView());

    renderer->SetMatrixMode(Renderer::ModelViewMatrix);
    renderer->LoadIdentity();
    currentCamera->ApplyViewMatrix();
    /*
    Light light;
    light.mPosition = Vector3f( 4.32f, -3.0f, -3.4f ).Normalize();
    light.mAmbient  = Color4f(1.0f,1.0f, 1.0f,1.0f);
    light.mDiffuse  = Color4f(1.0f,1.0f, 1.0f,1.0f);
    light.mSpecular = Color4f(1.0f,1.0f, 1.0f,1.0f);
    light.mType = Renderer::LightDirectional;
    renderer->SetRenderState( Renderer::Light_i, true, 0 );
    renderer->SetLight( 0, light );*/

#if 0
    Matrix4d modelView;
    renderer->GetModelViewMatrix( modelView );

    Vector3f vRight( modelView[0], modelView[4], modelView[8] );
    Vector3f vUp( modelView[1], modelView[5], modelView[9] );

    Vector3f vBottomLeft  = light.mPosition + (-vRight - vUp).Normalize() * 2;
    Vector3f vBottomRight = light.mPosition + ( vRight - vUp).Normalize() * 2;
    Vector3f vTopRight    = light.mPosition + ( vRight + vUp).Normalize() * 2;
    Vector3f vTopLeft     = light.mPosition + (-vRight + vUp).Normalize() * 2;

    /*renderer->SetRenderState( Renderer::DepthMask, false );
    renderer->SetRenderState( Renderer::Lighting, false );
    renderer->SetRenderState( Renderer::Blend, true );
    renderer->SetBlendFunc( Renderer::BlendSrcAlpha, Renderer::BlendOne );*/
    renderer->SetRenderState( Renderer::Lighting, false );
    renderer->DrawQuad( vBottomLeft, vBottomRight, vTopRight, vTopLeft, false );
    renderer->SetRenderState( Renderer::Lighting, true );
#endif


    renderer->SetAmbiantColor( Color4f(1.0f, 1.0f, 1.0f, 1.0f) );

      /*Light lightPoint;
    lightPoint.mPosition = currentCamera->GetPosition();
    lightPoint.mAmbient  = Color4f(0.00f,0.00f, 0.00f,1.0f);
    lightPoint.mDiffuse  = Color4f(1.0f,1.0f, 1.0f,1.0f);
    lightPoint.mSpecular = Color4f(1.0f,1.0f, 1.0f,1.0f);
    lightPoint.mType = Renderer::LightPoint;
    lightPoint.mAttenuationConstant  = 0;
    lightPoint.mAttenuationLinear    = 0;
    lightPoint.mAttenuationQuadratic = 0.01f;
    renderer->SetRenderState( Renderer::Light_i, true, 0 );
    renderer->SetLight( 0, lightPoint );*/

	// Get the frustum.
	Matrix4f modelViewMatrix;
    Matrix4f projectionMatrix;
    Frustum  frustum;

	renderer->GetModelViewMatrix(modelViewMatrix);
	renderer->GetProjectionMatrix(projectionMatrix);
	frustum.CalculateFrustum(projectionMatrix, modelViewMatrix);

	mNbRenderedEntities = 0;

    // Render the objects in the world.
    /*
    List<Entity*> visibleEntities;
	mSpacePartition->Query(frustum, visibleEntities);
    */
    List<Entity*>::const_iterator itEntity;
    for( itEntity = mEntities.begin(); itEntity != mEntities.end(); ++itEntity )
    {
        if( *itEntity != currentCamera )
        {
			// Do frustum culling.
			if((*itEntity)->GetClass() != Terrain::StaticClass() &&
               (*itEntity)->GetClass() != SkyDome::StaticClass())
			{
				BoundingBox boundingBox = (*itEntity)->GetBoundingBox();

                if( (*itEntity)->GetClass() != ParticleEmitter::StaticClass() )
                {
                    Matrix4f translation = Matrix4f::Translation((*itEntity)->GetPosition());
				    Matrix4f rotation;
				    (*itEntity)->GetOrientation().ToMatrix(rotation);

				    Matrix4f trsMatrix = rotation * translation;
				    boundingBox.SetMin( boundingBox.Min() * trsMatrix );
				    boundingBox.SetMax( boundingBox.Max() * trsMatrix );
                }

				if( frustum.BoxInFrustum(boundingBox) )
				{
					mNbRenderedEntities++;
				}
				else
				{
					continue;
				}
			}

            renderer->PushMatrix();

            if( String((*itEntity)->GetClass()->GetName()) == "SkyDome" )
                renderer->Translate(currentCamera->GetPosition()-Vector3f(0,100,0) );
            else
                renderer->Translate((*itEntity)->GetPosition());

            renderer->Rotate((*itEntity)->GetOrientation());

            if( (*itEntity)->IsSelected() )
                (*itEntity)->RenderSelected();

            (*itEntity)->Render();

            renderer->PopMatrix();
        }
    }

    renderer->SetMatrixMode(Renderer::ModelViewMatrix);
    renderer->LoadIdentity();
    currentCamera->ApplyViewMatrix();

    //renderer->EndScene();
}