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 Button & item)19 Button* Button::Add(const Button& item)
20 {
21     Button* pItem = new Button(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 Button::Update()
29 {
30 	int status;
31 
32 		// We don't care as much if the cursor isn't being triggered
33 	if (PositiveTriggered())
34 		status = 2;
35 	else
36 		status = 1;
37 
38 		// See if we just hit something
39 	if (CursorColliding(this->x, this->y, this->width, this->height))
40 		this->status = status;
41 	else
42 		this->status = 0;
43 
44 	if (this->status == 2)
45         this->func(this->funcExtra);
46 
47 	return (this->status == 0);
48 }
49 
50 	// Draws the button
Draw()51 void Button::Draw()
52 {
53 	CVec4 color = colorFunc(status);
54 
55 	if (tex)
56 		DrawTexQuad(*tex, position, size, color);
57 	else
58 		DrawBox(position, size, color);
59 
60     if (text.text[0])
61         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));
62 }
63 
Reset()64 void Button::Reset()
65 {
66     if (this->status > 0)
67         this->status = 0;
68 }
69