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 #ifndef __DEMOWIN_H_ 14 #define __DEMOWIN_H_ 15 16 #include <stdio.h> 17 #include <stdlib.h> 18 #include <string.h> 19 #include <math.h> 20 #include <vector> 21 #include <list> 22 #include <hash_map> 23 24 #include <cafe/os.h> 25 26 #include <cafe/gx2.h> 27 28 namespace DEMOWin 29 { 30 31 #include "demowin/demowin_assets.h" 32 #include "demowin/demowin_helpers.h" 33 34 /////////////////////////////////////////////////////////////////////////////////////////////////// 35 36 struct WindowManager; 37 struct ScrollBar; 38 39 // This window is more generic, and can scroll vertically 40 struct Window 41 { 42 Window(WindowManager* manager, const char* _name, CVec2 _position, CVec2 _size, CVec2 _maxSize = CVec2(0, 0), bool _canKill = true); 43 ~Window(); 44 DeleteWindow45 void Delete() {this->deleteFlag = true; this->visible = false;} DeletedWindow46 bool Deleted() {return this->deleteFlag;} 47 GetNameWindow48 const char* GetName() {return name.text;} SetNameWindow49 void SetName(const char* name) {this->name = name;} 50 GetXWindow51 float GetX() {return this->x;} GetYWindow52 float GetY() {return this->y + this->offY;} 53 float& GetOffY(); 54 55 float GetWidth(); 56 float GetHeight(); 57 float GetMaxHeight(); 58 GetLeftWindow59 float GetLeft() {return this->x - GetWidth() / 2;} GetRightWindow60 float GetRight() {return this->x + GetWidth() / 2;} 61 float GetTop(); GetBottomWindow62 float GetBottom(){return this->GetTop() - GetHeight();} 63 64 Window* GetMaster(); 65 GetDataWindow66 virtual void GetData(void*& data, int& size) {data = NULL; size = 0;} 67 virtual bool CursorOver(); UpdateWindow68 virtual bool Update(bool canUpdate) {return canUpdate;} DrawWindow69 virtual void Draw() {} 70 virtual void Reset(); 71 72 virtual bool PreUpdate(bool canUpdate); 73 virtual void PreDraw(); 74 75 virtual void Hide(); 76 virtual void Show(); 77 78 bool Visible(); 79 bool Enabled(); 80 EnableWindow81 void Enable() {this->enabled = true;} DisableWindow82 void Disable() {this->enabled = false;} 83 ActiveWindow84 bool Active() {return this->Visible() && this->Enabled();} 85 bool InFront(); 86 87 void BringToFront(); 88 89 virtual void ClearItems(); 90 MenuWindow91 MenuItem* Menu() {return menu;} 92 93 void AddTabbing(MenuItem* item); DummyTabWindow94 TabObject* DummyTab() {return &dummyTab;} 95 96 void AttachWindow(Window* window); 97 void DetachWindow(); 98 99 String<MAX_NAME_LENGTH> name; 100 101 int number; 102 103 CVec2 position; 104 CVec2 size; 105 CVec2 maxSize; 106 107 float& x; 108 float& y; 109 110 float offY; 111 112 float& width; 113 float& height; 114 115 float& maxWidth; 116 float& maxHeight; 117 118 bool canKill; 119 120 int closeStatus; 121 122 std::list<MenuItem*> menuItems; 123 124 WindowManager* manager; 125 126 Window* master; 127 Window* child; 128 129 protected: 130 131 bool deleteFlag; 132 133 ScrollBar* scrollBar; 134 135 TabObject dummyTab; 136 MenuItem* menu; 137 138 bool visible; 139 bool enabled; 140 141 std::list<MenuItem*> sortedItems; 142 std::list<MenuItem*> sortedDrawItems; 143 std::list<TabObject> tabItems; 144 145 friend TabObject; 146 friend WindowManager; 147 }; 148 149 // Has a single combo box, no core (max 10 options) 150 struct ComboCustom : public Window 151 { 152 ComboCustom(WindowManager* manager, const char* name, const AutoList<int>& start, const AutoList<const char*>& names, const AutoList<AutoList<const char*> >& option); 153 ComboCustom(WindowManager* manager, const char* name, const AutoList<int>& start, const AutoList<const char*>& names, const AutoList<std::vector<const char*> >& option); 154 ComboCustom(WindowManager* manager, const char* name, const std::vector<int>& start, const std::vector<const char*>& names, const std::vector<std::vector<const char*> >& option); 155 156 void Init(int num, const int* counts, const int* start, const char* const* names, const char* const* const* option); 157 158 std::vector<SubComboBasic<MAX_NAME_LENGTH> > options[10]; 159 std::vector<SubCombo*> optionsList[10]; 160 int choice[10]; 161 }; 162 163 #include "demowin/demowin_manager.h" 164 165 struct MenuItem 166 { 167 MenuItem(Window* _window, const CVec3& _position = CVec3(0, 0, 0), const CVec2& _size = CVec2(0, 0)) windowMenuItem168 : window(_window), visible(true), position(_position), size(_size), x(position.x), y(position.y), z(position.z), width(size.x), height(size.y), status(0) {} 169 MenuItemMenuItem170 MenuItem(const MenuItem& copy) 171 : window(copy.window), visible(copy.visible), position(copy.position), size(copy.size), x(position.x), y(position.y), z(position.z), width(size.x), height(size.y), status(copy.status) {} 172 CursorOverMenuItem173 virtual bool CursorOver() {return false;} UpdateMenuItem174 virtual bool Update() {return true;} DrawMenuItem175 virtual void Draw() {} ResetMenuItem176 virtual void Reset() {} 177 ActiveMenuItem178 virtual bool Active() {return this->visible && this->status >= 0;} 179 180 // Draw calls DrawTextMenuItem181 void DrawText(const char* text, CVec3 position, CVec2 size, CVec4 color) 182 {window->manager->peripheral->DrawText(text, CVec3(window->GetX() + position.x, window->GetY() + position.y, position.z), size, color);} DrawTextCenterMenuItem183 void DrawTextCenter(const char* text, CVec3 position, CVec2 size, CVec4 color) 184 {window->manager->peripheral->DrawTextCenter(text, CVec3(window->GetX() + position.x, window->GetY() + position.y, position.z), size, color);} DrawTextRightMenuItem185 void DrawTextRight(const char* text, CVec3 position, CVec2 size, CVec4 color) 186 {window->manager->peripheral->DrawTextRight(text, CVec3(window->GetX() + position.x, window->GetY() + position.y, position.z), size, color);} DrawMultiLineTextMenuItem187 void DrawMultiLineText(const char* text, CVec3 position, CVec2 size, CVec4 color) 188 {window->manager->peripheral->DrawMultiLineText(text, CVec3(window->GetX() + position.x, window->GetY() + position.y, position.z), size, color);} 189 void DrawBox(CVec3 position, CVec2 size, CVec4 color, CVec4 color1 = CVec4(0, 0, 0, 1.0)) 190 {window->manager->peripheral->DrawBox(CVec3(window->GetX() + position.x, window->GetY() + position.y, position.z), size, color, color1);} DrawLineMenuItem191 void DrawLine(CVec3 position, CVec2 size, CVec4 color) 192 {window->manager->peripheral->DrawLine(CVec3(window->GetX() + position.x, window->GetY() + position.y, position.z), size, color);} DrawFastLineMenuItem193 void DrawFastLine(CVec3 position, CVec2 size, CVec4 color) 194 {window->manager->peripheral->DrawFastLine(CVec3(window->GetX() + position.x, window->GetY() + position.y, position.z), size, color);} DrawQuadMenuItem195 void DrawQuad(CVec3 position, CVec2 size, CVec4 color) 196 {window->manager->peripheral->DrawQuad(CVec3(window->GetX() + position.x, window->GetY() + position.y, position.z), size, color);} DrawTexQuadMenuItem197 void DrawTexQuad(GX2Texture* tex, CVec3 position, CVec2 size, CVec4 color) 198 {window->manager->peripheral->DrawTexQuad(tex, CVec3(window->GetX() + position.x, window->GetY() + position.y, position.z), size, color);} DrawBoxQuadMenuItem199 void DrawBoxQuad(CVec3 position, CVec2 size, CVec4 color) 200 {window->manager->peripheral->DrawBoxQuad(CVec3(window->GetX() + position.x, window->GetY() + position.y, position.z), size, color);} 201 GetTextureMenuItem202 GX2Texture** GetTexture(CWTextures num) 203 {return window->manager->GetTexture(num);} 204 205 // Input checks AnyPressedMenuItem206 bool AnyPressed() {return window->manager->peripheral->AnyPressed();} 207 LeftPressedMenuItem208 bool LeftPressed() {return window->manager->peripheral->LeftPressed();} RightPressedMenuItem209 bool RightPressed() {return window->manager->peripheral->RightPressed();} UpPressedMenuItem210 bool UpPressed() {return window->manager->peripheral->UpPressed();} DownPressedMenuItem211 bool DownPressed() {return window->manager->peripheral->DownPressed();} PositivePressedMenuItem212 bool PositivePressed() {return window->manager->peripheral->PositivePressed();} NegativePressedMenuItem213 bool NegativePressed() {return window->manager->peripheral->NegativePressed();} 214 LeftTriggeredMenuItem215 bool LeftTriggered() {return window->manager->peripheral->LeftTriggered();} RightTriggeredMenuItem216 bool RightTriggered() {return window->manager->peripheral->RightTriggered();} UpTriggeredMenuItem217 bool UpTriggered() {return window->manager->peripheral->UpTriggered();} DownTriggeredMenuItem218 bool DownTriggered() {return window->manager->peripheral->DownTriggered();} PositiveTriggeredMenuItem219 bool PositiveTriggered() {return window->manager->peripheral->PositiveTriggered();} NegativeTriggeredMenuItem220 bool NegativeTriggered() {return window->manager->peripheral->NegativeTriggered();} 221 TabLeftTriggeredMenuItem222 bool TabLeftTriggered() {return window->manager->peripheral->TabLeftTriggered();} TabRightTriggeredMenuItem223 bool TabRightTriggered() {return window->manager->peripheral->TabRightTriggered();} PauseTriggeredMenuItem224 bool PauseTriggered() {return window->manager->peripheral->PauseTriggered();} HomeTriggeredMenuItem225 bool HomeTriggered() {return window->manager->peripheral->HomeTriggered();} 226 227 bool CursorColliding(float x, float y, float width, float height, bool ignoreBounds = false) 228 {return window->manager->peripheral->CursorColliding(window, x, y, width, height, ignoreBounds);} 229 UsingPadMenuItem230 bool UsingPad() {return window->manager->peripheral->UsingPad();} UsingWiimoteMenuItem231 bool UsingWiimote() {return window->manager->peripheral->UsingWiimote();} 232 CursorXMenuItem233 float& CursorX() {return window->manager->peripheral->CursorX();} CursorYMenuItem234 float& CursorY() {return window->manager->peripheral->CursorY();} 235 TabIndexMenuItem236 TabObject*& TabIndex() {return (window->manager->tabIndex);} TabSubIndexMenuItem237 int& TabSubIndex() {return (window->manager->tabSubIndex);} CursorTimeMenuItem238 int& CursorTime() {return (window->manager->cursorTime);} 239 240 Window* window; 241 242 CVec3 position; 243 CVec2 size; 244 245 float& x; 246 float& y; 247 float& z; 248 249 float& width; 250 float& height; 251 252 bool visible; 253 254 int status; 255 }; 256 257 #include "demowin/demowin_object_list.h" 258 #include "demowin/demowin_tab_window.h" 259 260 } 261 262 #endif 263