/*---------------------------------------------------------------------------* 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. *---------------------------------------------------------------------------*/ //////////////////////////////////////////////////// // // Scroll Bar functions // //////////////////////////////////////////////////// ScrollBar* ScrollBar::Add(const ScrollBar& item) { ScrollBar* pItem = new ScrollBar(item); item.window->menuItems.push_back(pItem); return pItem; } // Updates the scroll bar bool ScrollBar::Update() { // A draggable bar if (this->count <= this->max) return true; float sizeY = this->count - this->max; float offY = *this->pPos / sizeY; offY = (0.5 - offY) * (this->height - this->subHeight); // No longer selecting the bar! if (!PositivePressed()) this->status = 0; if (this->status == 2) { offY = CursorY() - this->oldY; offY = 0.5 - offY / (this->height - this->subHeight); *this->pPos = offY * sizeY; // Clamp the values! if (*this->pPos >= this->count - this->max) { this->wasMax = true; *this->pPos = this->count - this->max; } if (*this->pPos <= 0) *this->pPos = 0; return false; } int status; // We don't care as much if the cursor isn't being triggered if (!PositiveTriggered()) status = 1; else status = 2; // See if we just hit something if (CursorColliding(this->x, this->y + offY, this->width, this->subHeight)) { this->status = status; if (status == 2) this->oldY = CursorY() - offY; } else this->status = 0; return (this->status == 0); } // Draws the scroll bar void ScrollBar::Draw() { // If we WERE at the bottom, STAY at the bottom if (wasMax && oldPos == *pPos) *pPos = count - max; wasMax = false; // Clamp the values! if (*pPos >= count - max) { wasMax = true; *pPos = count - max; } if (*pPos <= 0) *pPos = 0; // A draggable bar if (count > max) { float sizeY = count - max; float offY = *pPos / sizeY; subHeight = height * (1.0 - (float)sizeY / count); if (subHeight < width) subHeight = width; offY = (0.5 - offY) * (height - subHeight); CVec4 color = WhiteDarker(status); DrawQuad(position, size, CVec4(1.0, 1.0, 1.0, 0.2)); DrawQuad(CVec3(x, y + offY, z + 0.0001), CVec2(width, subHeight), color); DrawLine(CVec3(x - width / 2, y - height / 2, z + 0.0002), CVec2(0, height), CVec4(0, 0, 0)); } oldPos = *pPos; } // Resets the scroll bar's status void ScrollBar::Reset() { if (this->status > 0) this->status = 0; }