Pie Noon
An open source project by FPL.
 All Classes Pages
gui_menu.h
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GUI_MENU_H
16 #define GUI_MENU_H
17 
18 #include <queue>
19 #include "common.h"
20 #include "config_generated.h"
21 #include "controller.h"
22 #include "precompiled.h"
23 #include "touchscreen_button.h"
24 
25 namespace fpl {
26 namespace pie_noon {
27 
28 class StaticImage;
29 
30 // Simple struct for transporting a menu selection, and the controller that
31 // triggered it.
32 struct MenuSelection {
33  MenuSelection(ButtonId buttonId, ControllerId controllerId)
34  : button_id(buttonId), controller_id(controllerId) {}
35 
36  ButtonId button_id;
37  ControllerId controller_id;
38 };
39 
40 class GuiMenu {
41  public:
42  GuiMenu();
43 
44  void AdvanceFrame(WorldTime delta_time, fplbase::InputSystem* input,
45  const vec2& window_size);
46  void Setup(const UiGroup* menudef, fplbase::AssetManager* matman);
47  void LoadAssets(const UiGroup* menu_def, fplbase::AssetManager* matman);
48  void Render(fplbase::Renderer* renderer);
49  void AdvanceFrame(WorldTime delta_time);
50  MenuSelection GetRecentSelection();
51  void HandleControllerInput(uint32_t logical_input,
52  ControllerId controller_id);
53  ButtonId GetFocus() const;
54  void SetFocus(ButtonId new_focus);
55  TouchscreenButton* FindButtonById(ButtonId id);
56  StaticImage* FindImageById(ButtonId id);
57  const UiGroup* menu_def() const { return menu_def_; }
58  void LoadDebugShaderAndOptions(const Config* config,
59  fplbase::AssetManager* matman);
60 
61  private:
62  void ClearRecentSelections();
63  void UpdateFocus(const flatbuffers::Vector<uint16_t>* destination_list);
64 
65  // imgui custom button definition.
66  flatui::Event ImguiButton(const ImguiButtonDef& data);
67  void RenderTexture(const fplbase::Texture& tex, const vec2& pos,
68  const vec2& size, const vec2& scale);
69 
70  const UiGroup* menu_def_;
71  fplbase::InputSystem* input_;
72  fplbase::AssetManager* matman_;
73  flatui::FontManager* fontman_;
74 
75  const char* debug_shader;
76  bool draw_debug_bounds;
77  ButtonId current_focus_;
78  std::queue<MenuSelection> unhandled_selections_;
79  std::vector<TouchscreenButton> button_list_;
80  std::vector<StaticImage> image_list_;
81 
82  // Total Worldtime since the menu was initialized.
83  // Used for animating selections and such.
84  WorldTime time_elapsed_;
85 };
86 
87 } // pie_noon
88 } // fpl
89 #endif // GUI_MENU_H
Definition: touchscreen_button.h:26
Definition: touchscreen_button.h:133
Definition: gui_menu.h:40
Definition: gui_menu.h:32