1 // -*- Mode: C++; tab-width:2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi:tw=80:et:ts=2:sts=2
3 //
4 // -----------------------------------------------------------------------
5 //
6 // This file is part of RLVM, a RealLive virtual machine clone.
7 //
8 // -----------------------------------------------------------------------
9 //
10 // Copyright (C) 2008 Elliot Glaysher
11 //
12 // This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 3 of the License, or
15 // (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 // -----------------------------------------------------------------------
26 
27 #ifndef SRC_PLATFORMS_GCN_GCN_PLATFORM_H_
28 #define SRC_PLATFORMS_GCN_GCN_PLATFORM_H_
29 
30 #include <guichan.hpp>
31 #include <guichan/opengl.hpp>
32 #include <guichan/sdl.hpp>
33 #include <guichan/opengl/openglsdlimageloader.hpp>
34 
35 #include <memory>
36 #include <string>
37 #include <vector>
38 
39 #include "systems/base/platform.h"
40 #include "systems/base/renderable.h"
41 #include "platforms/gcn/gcn_menu.h"
42 #include "platforms/gcn/gcn_window.h"
43 #include "platforms/gcn/gcn_save_load_window.h"
44 
45 class Gameexe;
46 class GCNPlatformBlocker;
47 class Rect;
48 class System;
49 struct MenuSpec;
50 
51 // -----------------------------------------------------------------------
52 
53 extern const char* EVENT_CANCEL;
54 
55 // -----------------------------------------------------------------------
56 
57 // Guichan GUI.
58 class GCNPlatform : public Platform,
59                     public gcn::MouseListener,
60                     public gcn::KeyListener,
61                     public std::enable_shared_from_this<GCNPlatform> {
62  public:
63   GCNPlatform(System& system, const Rect& screen_size);
64   ~GCNPlatform();
65 
66   void render();
67   void windowCanceled(GCNWindow* window);
68   void receiveGCNMenuEvent(GCNMenu* menu, const std::string& event);
69   void saveEvent(int slot);
70   void loadEvent(int slot);
71 
72   // Overridden from Platform:
73   virtual void Run(RLMachine& machine) override;
74   virtual void ShowNativeSyscomMenu(RLMachine& machine) override;
75   virtual void InvokeSyscomStandardUI(RLMachine& machine, int syscom) override;
76   virtual void ShowSystemInfo(RLMachine& machine,
77                               const RlvmInfo& info) override;
78 
79   // Overridden from gcn::MouseListener:
80   virtual void mouseClicked(gcn::MouseEvent& mouseEvent) override;
81 
82   // Overridden from gcn::KeyListener:
83   virtual void keyReleased(gcn::KeyEvent& keyEvent) override;
84 
85  private:
86   // Blocks the world until we're done.
87   void pushBlocker(RLMachine& machine);
88 
89   // Initializes all of the above.
90   void initializeGuichan(System& system, const Rect& screen_size);
91 
92   // Builds the current syscom menu, based on the currently visisble syscom
93   // items, erasing the old one if necessary.
94   void buildSyscomMenuFor(const std::string& label,
95                           const MenuSpec menu_items[],
96                           RLMachine& machine);
97 
98   // Clears the window stack (unblocking the RLMachine).
99   void clearWindowStack();
100 
101   // Deallocates the window on the top of the window stack.
102   void popWindowFromStack();
103 
104   // Displays a window.
105   void pushWindowOntoStack(GCNWindow* window);
106 
107   // Event Handling functions
108   void MenuSave(RLMachine& machine);
109   void DoSave(RLMachine& machine, int slot);
110   void MenuLoad(RLMachine& machine);
111   void DoLoad(RLMachine& machine, int slot);
112   void InvokeSyscom(RLMachine& machine, int syscom);
113 
114   // This is our LongOperation on the stack.
115   GCNPlatformBlocker* blocker_;
116 
117   // Used to center dialogs in the window.
118   Rect screen_size_;
119 
120   // GUIchan syscom implementation
121   //
122   // In addition to the SDL systems, SDLSystem also owns the guichan based
123   // GUI. The following gcn objects are the
124   std::unique_ptr<gcn::OpenGLSDLImageLoader> sdl_image_loader_;
125   std::unique_ptr<gcn::OpenGLGraphics> opengl_graphics_;
126   std::unique_ptr<gcn::SDLInput> sdl_input_;
127 
128   std::unique_ptr<gcn::Container> toplevel_container_;
129   std::unique_ptr<gcn::Gui> guichan_gui_;
130 
131   std::unique_ptr<gcn::Font> global_font_;
132 
133   // Stack of menus rendered on top of each other.
134   std::vector<GCNWindow*> window_stack_;
135 
136   friend class GCNPlatformBlocker;
137 };  // end of class GCNPlatform
138 
139 #endif  // SRC_PLATFORMS_GCN_GCN_PLATFORM_H_
140