Simulant  21.12-194
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
panel.h
1 /* * Copyright (c) 2011-2017 Luke Benstead https://simulant-engine.appspot.com
2  *
3  * This file is part of Simulant.
4  *
5  * Simulant is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Simulant is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with Simulant. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #include "../event_listener.h"
22 #include "../nodes/stage_node_pool.h"
23 
24 namespace smlt {
25 
26 class Stage;
27 
28 class Panel:
29  public EventListener {
30 public:
31  virtual ~Panel() {}
32 
33  bool init();
34  void clean_up();
35 
36  bool is_active() const { return is_active_; }
37 
38  void activate() {
39  if(is_active_) return;
40 
41  do_activate();
42  is_active_ = true;
43  }
44 
45  void deactivate() {
46  if(!is_active_) return;
47 
48  do_deactivate();
49  is_active_ = false;
50  }
51 
52  void on_key_down(const KeyEvent& evt) override;
53 
54  void set_activation_key(KeyboardCode code) {
55  activation_key_ = code;
56  }
57 
58 protected:
59  std::shared_ptr<Stage> stage_;
60 
61 private:
62  KeyboardCode activation_key_ = KEYBOARD_CODE_NONE;
63  bool is_active_ = false;
64 
65  virtual void do_activate() = 0;
66  virtual void do_deactivate() = 0;
67 };
68 
69 
70 }
smlt::EventListener
Definition: event_listener.h:64
smlt
Definition: animation.cpp:25
smlt::Panel
Definition: panel.h:29
smlt::KeyEvent
Definition: event_listener.h:58