i6engine  1.0
GUIWidget.h
Go to the documentation of this file.
1 /*
2  * i6engine
3  * Copyright (2016) Daniel Bonrath, Michael Baer, All rights reserved.
4  *
5  * This file is part of i6engine; i6engine is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
25 #ifndef __I6ENGINE_API_GUIWIDGET_H__
26 #define __I6ENGINE_API_GUIWIDGET_H__
27 
28 #include <vector>
29 
31 
33 
34 #include "boost/function.hpp"
35 
36 namespace CEGUI {
37  class AnimationInstance;
38  class EventArgs;
39  class Window;
40 } /* namespace CEGUI */
41 
42 namespace i6e {
43 namespace api {
44 namespace gui {
46 } /* namespace gui */
47 
66  public:
67  explicit GUIWidget(const std::string & name);
68  virtual ~GUIWidget();
69 
73  virtual void update(uint16_t type, gui::GUIUpdateMessageStruct * message);
74 
78  virtual void tick();
79 
83  void loadWindowLayout(const std::string & name, const std::string & filename);
84 
89  void enableTicking(bool enabled);
90 
96  void subscribeClickEvent(const boost::function<void(void)> & callback) {
97  _clickCallback = callback;
98  }
99 
103  bool canDrop() const {
104  return _dropable;
105  }
106 
110  std::vector<GUIWidget *> getAllMouseoverWidgets() const {
111  return _mouseOverCallback();
112  }
113 
117  void setMouseOverCallback(const std::function<std::vector<GUIWidget *>(void)> & func) {
118  _mouseOverCallback = func;
119  }
120 
124  void setPosition(double x, double y);
125 
129  void setSize(double w, double h);
130 
131  bool isHit() const;
132 
134  bool renderingEndedHandler(const CEGUI::EventArgs & args);
135 
136  std::string _name;
137  CEGUI::Window * _window;
138 
140  std::vector<GUIWidget *> _childs;
141 
142  private:
143  bool _ticking;
144  std::function<std::vector<GUIWidget *>()> _mouseOverCallback;
145  bool _dropable;
146  std::function<bool(std::string)> _canDrop;
147  bool _dragable;
148  std::function<void(const std::string &, const std::string &)> _dropCallback;
149  Vec2f _originalPos;
150  bool _isDragged;
151  Vec2f _dragOffset;
152  boost::function<void(void)> _clickCallback;
153  std::string _tooltip;
154  bool _tooltipActive;
155  std::map<std::string, CEGUI::AnimationInstance *> _animations;
156 
158  uint32_t * _hitTestBuffer;
160  size_t _hitBufferCapacity;
162  Vec2f _hitBufferSize;
164  bool _hitBufferInverted;
165 
166  bool drag(const CEGUI::EventArgs & e);
167  bool drop(const CEGUI::EventArgs & e);
168  bool mouseMove(const CEGUI::EventArgs & e);
169  bool mouseEnter(const CEGUI::EventArgs & e);
170  bool mouseLeave(const CEGUI::EventArgs & e);
171 
172  // overridden from Window base class
173  //bool testClassName_impl(const CEGUI::String & class_name) const;
174 
178  GUIWidget(const GUIWidget &) = delete;
179 
183  GUIWidget & operator=(const GUIWidget &) = delete;
184  };
185 
186 } /* namespace api */
187 } /* namespace i6e */
188 
189 #endif /* __I6ENGINE_API_GUIWIDGET_H__ */
190 
CEGUI::Window * _window
Definition: GUIWidget.h:137
#define ISIXE_MODULES_API
std::vector< GUIWidget * > _childs
Definition: GUIWidget.h:140
Used to partially unwrap GUI messages.
Definition: GUIConfig.h:108
GUIWidget * _parent
Definition: GUIWidget.h:139
i6e::api::gui::GUIUpdateMessageStruct GUIUpdateMessageStruct
std::string _name
Definition: GUIWidget.h:136
void setMouseOverCallback(const std::function< std::vector< GUIWidget * >(void)> &func)
sets mouse over callback
Definition: GUIWidget.h:117
std::vector< GUIWidget * > getAllMouseoverWidgets() const
returns a vector containing all windows the mousecursor is currently over
Definition: GUIWidget.h:110
void subscribeClickEvent(const boost::function< void(void)> &callback)
Subscribes to a window event. This function can be used to handle event-subscription-messages.
Definition: GUIWidget.h:96
Superclass for all GUI widgets.
Definition: GUIWidget.h:65
bool canDrop() const
returns whether the widget accepts drops or not
Definition: GUIWidget.h:103