1 /*---------------------------------------------------------------------------*
2 
3   Copyright (C) Nintendo.  All rights reserved.
4 
5   These coded instructions, statements, and computer programs contain
6   proprietary information of Nintendo of America Inc. and/or Nintendo
7   Company Ltd., and are protected by Federal copyright law.  They may
8   not be disclosed to third parties or copied or duplicated in any form,
9   in whole or in part, without the prior written consent of Nintendo.
10 
11  *---------------------------------------------------------------------------*/
12 
13 ////////////////////////////////////////////////////
14 //
15 // Button functions
16 //
17 ////////////////////////////////////////////////////
18 
Add(const HeldButton & item)19 HeldButton* HeldButton::Add(const HeldButton& item)
20 {
21     HeldButton* pItem = new HeldButton(item);
22     item.window->menuItems.push_back(pItem);
23     item.window->AddTabbing(pItem);
24     return pItem;
25 }
26 
27 	// Updates the button
Update()28 bool HeldButton::Update()
29 {
30 	if (!PositivePressed())
31 		this->status = 0;
32 
33 	int status;
34 
35 		// We don't care as much if the cursor isn't being pressed
36 	if (PositiveTriggered())
37 		status = 2;
38 	else
39 		status = 1;
40 
41 		// See if we just hit something
42 	if (CursorColliding(this->x, this->y, this->width, this->height))
43 	{
44 		if (status > this->status)
45 			this->status = status;
46 
47             // Held buttons behave slightly differently!
48         if (this->status == 2 && (CursorTime() == 0 || (CursorTime() >= 30 && (CursorTime() - 30) % 5 == 0)))
49             this->func(this->funcExtra);
50 	}
51 	else if (this->status == 1)
52 		this->status = 0;
53 
54 	return (this->status == 0);
55 }
56 
57 	// Draws the button
Draw()58 void HeldButton::Draw()
59 {
60 	CVec4 color = colorFunc(status);
61 
62 	if (tex)
63 		DrawTexQuad(*tex, position, size, color);
64 	else
65 		DrawBox(position, size, color);
66 
67     if (text.text[0])
68         DrawTextCenter(text.text, CVec3(x, y, z + 0.0001), CVec2(width, height * 0.8), CVec4(1.0 - color.r, 1.0 - color.g, 1.0 - color.b));
69 }
70 
71     // Resets the button's status
Reset()72 void HeldButton::Reset()
73 {
74     if (this->status > 0)
75         this->status = 0;
76 }
77