Go to the documentation of this file.
39 m_rootWidget->
setId(
"root");
40 m_mouseReceiver = m_rootWidget;
41 m_keyboardReceiver = m_rootWidget;
48 m_mouseReceiver =
nullptr;
49 m_keyboardReceiver =
nullptr;
50 m_rootWidget =
nullptr;
51 m_draggingWidget =
nullptr;
52 m_hoveredWidget =
nullptr;
53 m_pressedWidget =
nullptr;
55 m_destroyedWidgets.clear();
56 m_checkEvent =
nullptr;
61 m_rootWidget->
draw(m_rootWidget->
getRect(), drawPane);
88 if (pressedWidget && !pressedWidget->
isEnabled())
89 pressedWidget =
nullptr;
104 bool accepted =
false;
112 if (m_pressedWidget) {
113 auto it = std::find(widgetList.begin(), widgetList.end(), m_pressedWidget);
114 if (it != widgetList.end())
115 widgetList.erase(it);
116 widgetList.push_front(m_pressedWidget);
132 if (m_pressedWidget && m_pressedWidget->
isDraggable() && m_draggingWidget != m_pressedWidget) {
142 if (m_draggingWidget) {
147 if (m_pressedWidget) {
175 m_pressedWidget = newPressedWidget;
178 if (fireClicks && oldPressedWidget && oldPressedWidget->
isEnabled() && oldPressedWidget->
containsPoint(clickedPos))
179 oldPressedWidget->
onClick(clickedPos);
181 if (newPressedWidget)
184 if (oldPressedWidget)
190 bool accepted =
false;
193 m_draggingWidget =
nullptr;
194 if (oldDraggingWidget) {
196 if (!clickedPos.
isNull()) {
199 if (child->onDrop(oldDraggingWidget, clickedPos)) {
200 droppedWidget = child;
206 accepted = oldDraggingWidget->
onDragLeave(droppedWidget, clickedPos);
210 if (draggingWidget) {
212 m_draggingWidget = draggingWidget;
223 if (m_hoverUpdateScheduled && !now)
230 m_hoverUpdateScheduled =
false;
234 if (hoveredWidget && !hoveredWidget->
isEnabled())
235 hoveredWidget =
nullptr;
238 if (hoveredWidget != m_hoveredWidget) {
240 m_hoveredWidget = hoveredWidget;
255 m_hoverUpdateScheduled =
true;
275 if (m_keyboardReceiver == widget)
278 if (m_mouseReceiver == widget)
281 if (m_hoveredWidget == widget)
284 if (m_pressedWidget == widget)
287 if (m_draggingWidget == widget)
291 if (widget == m_rootWidget || !m_rootWidget)
294 m_destroyedWidgets.push_back(widget);
296 if (m_checkEvent && !m_checkEvent->
isExecuted())
302 m_destroyedWidgets.clear();
338 std::string tag = styleNode->
tag();
340 if (
split.size() != 2)
341 throw OTMLException(styleNode,
"not a valid style declaration");
343 std::string name =
split[0];
344 std::string base =
split[1];
350 if (name[0] ==
'#') {
351 name = name.substr(1);
355 styleNode->
writeAt(
"__unique",
true);
369 if (!oldStyle || !oldStyle->
valueAt(
"__unique",
false) || unique) {
374 style->
merge(styleNode);
376 m_styles[name] = style;
382 auto it = m_styles.find(styleName);
383 if (it != m_styles.end())
384 return m_styles[styleName];
389 node->
writeAt(
"__class", styleName);
390 m_styles[styleName] = node;
400 if (style && style->
get(
"__class"))
401 return style->
valueAt(
"__class");
413 std::string tag = node->tag();
416 if (tag.find(
"<") != std::string::npos)
448 if (!originalStyleNode)
452 styleNode->
merge(widgetNode);
454 std::string widgetType = styleNode->
valueAt(
"__class");
467 if (!childNode->isUnique()) {
void setTag(const std::string &tag)
void onWidgetAppear(const UIWidgetPtr &widget)
void onWidgetDisappear(const UIWidgetPtr &widget)
OTMLNodePtr getStyle(const std::string &styleName)
void writeAt(const std::string &childTag, const T &v)
void resize(const Size &size)
All OTML errors throw this exception.
EventDispatcher g_dispatcher
static OTMLDocumentPtr parse(const std::string &fileName)
Parse OTML from a file.
void callGlobalField(const std::string &global, const std::string &field, const T &... args)
bool removeChild(const OTMLNodePtr &oldChild)
void updateHoveredWidget(bool now=false)
stdext::shared_object_ptr< UIWidget > UIWidgetPtr
void error(const std::string &what)
std::string getStyleClass(const std::string &styleName)
bool starts_with(const std::string &str, const std::string &test)
ResourceManager g_resources
T valueAt(const std::string &childTag)
R callLuaField(const std::string &field, const T &... args)
EventPtr addEvent(const std::function< void()> &callback, bool pushFront=false)
UIWidgetPtr createWidgetFromOTML(const OTMLNodePtr &widgetNode, const UIWidgetPtr &parent)
void importStyleFromOTML(const OTMLNodePtr &styleNode)
void resetMouseReceiver()
OTMLNodePtr get(const std::string &childTag)
void resetKeyboardReceiver()
void trim(std::string &str)
void render(Fw::DrawPane drawPane)
void throw_exception(const std::string &what)
Throws a generic exception.
UIWidgetPtr loadUI(std::string file, const UIWidgetPtr &parent)
std::vector< std::string > split(const std::string &str, const std::string &separators)
virtual const char * what() const
void updatePressedWidget(const UIWidgetPtr &newPressedWidget, const Point &clickedPos=Point(), bool fireClicks=true)
void merge(const OTMLNodePtr &node)
void onWidgetDestroy(const UIWidgetPtr &widget)
void inputEvent(const InputEvent &event)
bool updateDraggingWidget(const UIWidgetPtr &draggingWidget, const Point &clickedPos=Point())
bool importStyle(std::string file)
ScheduledEventPtr scheduleEvent(const std::function< void()> &callback, int delay)
std::deque< UIWidgetPtr > UIWidgetList
UIWidgetPtr createWidget(const std::string &styleName, const UIWidgetPtr &parent)
std::string guessFilePath(const std::string &filename, const std::string &type)
void warning(const std::string &what)
static OTMLNodePtr create(std::string tag="", bool unique=false)