/*---------------------------------------------------------------------------* Copyright (C) Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. *---------------------------------------------------------------------------*/ // Creates a window with tabs TabWindow::TabWindow(WindowManager* manager, const char* name, CVec2 position, float width, bool canKill) : Window(manager, name, position, CVec2(width, WINDOW_HANDLE_HEIGHT), CVec2(0, 0), canKill), tabWindowSelected(0), tabWindowOver(-1) { } // Draws the tab window void TabWindow::Draw() { // At this point, we better have some tabs! ASSERT(tabWindowList.size() && "Must have at least one tab!"); float temp = this->offY; this->offY = 0; // We can't be over the one that's selected! if (tabWindowSelected == tabWindowOver) tabWindowOver = -1; float x = -GetWidth() / 2 + GetWidth() / tabWindowList.size() / 2; float y = -height / 2; float spacing = GetWidth() / tabWindowList.size(); float buttonWidth = GetWidth() / tabWindowList.size(); float buttonHeight = height; float textHeight = buttonHeight * 0.8; for (int i = 0; i < tabWindowList.size(); ++i) { if (tabWindowSelected != i) menu->DrawBox(CVec3(x, y, 0.99), CVec2(buttonWidth, buttonHeight), CVec4(0.2, 0.2, 0.2)); else menu->DrawQuad(CVec3(x, y, 0.99), CVec2(buttonWidth, buttonHeight), CVec4(0, 0, 0, 0)); if (tabWindowOver == i) menu->DrawBox(CVec3(x, y, 0.9901), CVec2(buttonWidth, buttonHeight), CVec4(0.3, 0.3, 0.3)); menu->DrawTextCenter(tabWindowList[i]->name, CVec3(x, y, 0.9902), CVec2(buttonWidth, textHeight), CVec4(1.0, 1.0, 1.0)); x += spacing; } AttachWindow(tabWindowList[tabWindowSelected]); this->offY = temp; } // Anything special the window updates beforehand bool TabWindow::PreUpdate(bool canUpdate) { this->offY = 0; if (canUpdate) { float height = this->GetHeight() - this->height; scrollBar->count = this->GetMaxHeight() - this->height; scrollBar->max = height; scrollBar->x = (this->GetWidth() - SCROLLBAR_WIDTH) / 2; scrollBar->y = -height / 2 - this->height; scrollBar->height = height; canUpdate = scrollBar->Update(); } else scrollBar->Reset(); // At this point, we better have some tabs! ASSERT(tabWindowList.size() && "Must have at least one tab!"); tabWindowOver = -1; // The cursor is over one of the buttons if (canUpdate && menu->CursorColliding(0, -height / 2, GetWidth(), height)) { // Figure out which one! tabWindowOver = (menu->CursorX() - this->GetLeft()) / this->GetWidth() * tabWindowList.size(); canUpdate = false; if (menu->PositiveTriggered()) { tabWindowSelected = tabWindowOver; scrollBar->pos = 0; scrollBar->wasMax = false; } } AttachWindow(tabWindowList[tabWindowSelected]); this->offY = scrollBar->pos; return canUpdate; } // Anything special the window draws beforehand void TabWindow::PreDraw() { float temp = this->offY; this->offY = 0; float height = this->GetHeight() - this->height; scrollBar->count = this->GetMaxHeight() - this->height; scrollBar->max = height; scrollBar->x = (this->GetWidth() - SCROLLBAR_WIDTH) / 2; scrollBar->y = -height / 2 - this->height; scrollBar->height = height; scrollBar->Draw(); this->offY = temp; } // Adds a window to the list of tabs void TabWindow::AddWindow(Window* window) { tabWindowList.push_back(window); } // Removes a window from the list of tabs void TabWindow::RemoveWindow(Window* window) { int remove = 0; for (std::vector::iterator iter = tabWindowList.begin(); iter != tabWindowList.end(); ++iter, ++remove) { if (*iter == window) { // Make sure the selected number is updated if (remove < tabWindowSelected || (tabWindowSelected == tabWindowList.size() - 1 && tabWindowSelected > 0)) tabWindowSelected --; // Just in case, remove ALL instances of the window in the tab list tabWindowList.erase(iter); RemoveWindow(window); return; } } }