void JuiTabBook::OnRender( JPoint2I offset, const JRectI& rcPaint ) { int nWidth; int nLeaveCount; JRectI tabRect; tabRect.position = offset; tabRect.extent.x = nWidth = GetWidth() / m_lsPages.GetCount(); tabRect.extent.y = m_pNormalImage->GetHeight(); nLeaveCount = GetWidth() % m_lsPages.GetCount(); JuiTabPage* pTab = (JuiTabPage*)m_lsPages.First(); while(pTab) { if(nLeaveCount > 0) tabRect.extent.x = nWidth + 1; else tabRect.extent.x = nWidth; JRectI clip = tabRect; if(clip.Intersect(rcPaint)) RenderTab(clip, pTab); nLeaveCount -= 1; tabRect.position.x += tabRect.extent.x; pTab = (JuiTabPage*)m_lsPages.Next(); } }
/// Renders the inventory GUI to the provided screen. /// @param[in,out] renderer - The renderer to use for rendering. void InventoryGui::Render(GRAPHICS::Renderer& renderer) const { // RENDER A RECTANGLE FOR THE BACKGROUND. // It is offset from the top of the screen by the amount of the // top row of the HUD that is always displayed. Otherwise, // it should cover the remainder of the screen. const float TOP_SCREEN_OFFSET_IN_PIXELS = static_cast<float>(GRAPHICS::GUI::Glyph::HEIGHT_IN_PIXELS); const float SCREEN_LEFT_POSITION_IN_PIXELS = 0.0f; const float BACKGROUND_HEIGHT_IN_PIXELS = renderer.Screen.HeightInPixels<float>() - TOP_SCREEN_OFFSET_IN_PIXELS; MATH::FloatRectangle background_rectangle = MATH::FloatRectangle::FromLeftTopAndDimensions( SCREEN_LEFT_POSITION_IN_PIXELS, TOP_SCREEN_OFFSET_IN_PIXELS, renderer.Screen.WidthInPixels<float>(), BACKGROUND_HEIGHT_IN_PIXELS); // The background color is currently arbitrary. GRAPHICS::Color background_color; background_color.Red = GRAPHICS::Color::MAX_COLOR_COMPONENT; background_color.Green = GRAPHICS::Color::MAX_COLOR_COMPONENT; background_color.Blue = GRAPHICS::Color::MAX_COLOR_COMPONENT; renderer.RenderScreenRectangle( background_rectangle, background_color); // RENDER A TAB FOR THE BIBLE PORTION OF THE GUI. // It should be positioned near the top-left of the GUI. float bible_tab_left_screen_position_in_pixels = background_rectangle.GetLeftXPosition(); float bible_tab_top_screen_position_in_pixels = background_rectangle.GetTopYPosition(); MATH::Vector2f bible_tab_left_top_screen_position_in_pixels( bible_tab_left_screen_position_in_pixels, bible_tab_top_screen_position_in_pixels); RenderTab( "Bible", bible_tab_left_top_screen_position_in_pixels, InventoryBiblePage::BACKGROUND_COLOR, renderer); // RENDER A TAB FOR THE ANIMAL PORTION OF THE GUI. const std::string ANIMALS_TAB_STRING = "Animals"; unsigned int animals_tab_text_width_in_pixels = GRAPHICS::GUI::Glyph::WIDTH_IN_PIXELS * ANIMALS_TAB_STRING.length(); unsigned int animals_tab_text_half_width_in_pixels = animals_tab_text_width_in_pixels / 2; float animals_tab_left_screen_position_in_pixels = background_rectangle.GetCenterXPosition() - animals_tab_text_half_width_in_pixels; float animals_tab_top_screen_position_in_pixels = background_rectangle.GetTopYPosition(); MATH::Vector2f animals_tab_left_top_screen_position_in_pixels( animals_tab_left_screen_position_in_pixels, animals_tab_top_screen_position_in_pixels); RenderTab( ANIMALS_TAB_STRING, animals_tab_left_top_screen_position_in_pixels, ANIMALS_TAB_COLOR, renderer); // RENDER A TAB FOR THE FOOD PORTION OF THE GUI. const std::string FOOD_TAB_STRING = "Food"; unsigned int food_tab_text_width_in_pixels = GRAPHICS::GUI::Glyph::WIDTH_IN_PIXELS * FOOD_TAB_STRING.length(); float food_tab_left_screen_position_in_pixels = background_rectangle.GetRightXPosition() - food_tab_text_width_in_pixels; float food_tab_top_screen_position_in_pixels = background_rectangle.GetTopYPosition(); MATH::Vector2f food_tab_left_top_screen_position_in_pixels( food_tab_left_screen_position_in_pixels, food_tab_top_screen_position_in_pixels); RenderTab( FOOD_TAB_STRING, food_tab_left_top_screen_position_in_pixels, FOOD_TAB_COLOR, renderer); // RENDER THE CURRENTLY DISPLAYED PAGE. switch (CurrentTab) { case TabType::BIBLE: BiblePage.Render(renderer); break; case TabType::ANIMALS: RenderAnimalsPage(renderer); break; case TabType::FOOD: RenderFoodPage(renderer); break; } }