Harmonic Flow Framework (libhffwk)
Cross platform C++ 2D Game Engine Framework
WidgetManager.cpp
1 /*
2  Harmonic Flow Framework
3  Copyright (C) 2011-2018 Andreas Widen <andreas@harmonicflow.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "WidgetManager.h"
22 #include "Widget.h"
23 #include "platform/Graphics.h"
24 #include "platform/Image.h"
25 #include "platform/Environment.h"
26 #include <assert.h>
27 #include <algorithm>
28 
29 using namespace HFCore;
30 
31 #include "debug/CrtDbgNew.h"
32 
34 {
35  mMinDeferredOverlayPriority = 0x7FFFFFFF;
36  mWidgetManager = this;
37  mMouseIn = false;
41  mOverWidget = NULL;
44  mWidth = 0;
45  mHeight = 0;
46  mHasFocus = true;
49 
51 }
52 
54 {
55  // Remove and clean up DialogWidget Map
56  DialogMap::iterator dialogItr = mDialogMap.begin();
57  while (dialogItr != mDialogMap.end())
58  {
59  removeWidget(dialogItr->second);
60  HF_SAFE_DELETE(dialogItr->second);
61  ++dialogItr;
62  }
63  mDialogMap.clear();
64  mDialogList.clear();
65 
67 }
68 
69 int32_hf WidgetManager::getWidgetFlags()
70 {
71  return mHasFocus ? mWidgetFlags :
73 }
74 
76 {
77  if (!widget->getMouseListenerEnabled())
78  return;
79 
80  widget->mIsOver = true;
81 
82  widget->mouseEnter(mCurMouse);
83  if (widget->mDoFinger)
84  widget->showFinger(true);
85 }
86 
88 {
89  if (!widget->getMouseListenerEnabled())
90  return;
91 
92  widget->mIsOver = false;
93  widget->mouseLeave(mCurMouse);
94  if (widget->mDoFinger)
95  widget->showFinger(false);
96 }
97 
98 void WidgetManager::setBaseModal(Widget *widget, const FlagsMod &belowFlagsMod)
99 {
100  mBaseModalWidget = widget;
101  mBelowModalFlagsMod = belowFlagsMod;
102 
105  {
106  Widget *widget = mOverWidget;
107  mOverWidget = NULL;
108  mouseLeave(widget);
109  }
110 
113  {
114  Widget *widget = mLastDownWidget;
116  doMouseUps(widget);
117  }
118 
121  {
122  Widget *widget = mFocusWidget;
123  mFocusWidget = NULL;
124  widget->lostFocus();
125  }
126 }
127 
129 {
130  DialogMap::iterator itr = mDialogMap.find(dialogId);
131 
132  if (itr != mDialogMap.end())
133  return itr->second;
134 
135  return NULL;
136 }
137 
138 void WidgetManager::addDialog(int32_hf dialogId, DialogWidget *dialogWidget)
139 {
140  killDialog(dialogId);
141 
142  if (dialogWidget->mWidth == 0)
143  {
144  // Set the dialog position ourselves
145  fp32_hf width = mWidth / 2;
146  dialogWidget->resize((mWidth - width) / 2, (mHeight / 5),
147  (int32_hf)width, dialogWidget->getPreferredHeight((int32_hf)width));
148  }
149 
150  mDialogMap.insert(DialogMap::value_type(dialogId, dialogWidget));
151  mDialogList.push_back(dialogWidget);
152 
153  addWidget(dialogWidget);
154  if (dialogWidget->isModal())
155  {
156  addBaseModal(dialogWidget);
157  modalDialogOpen();
158  }
159 }
160 
162 {
163  addDialog(dialogWidget->mId, dialogWidget);
164 }
165 
166 bool WidgetManager::killDialog(int32_hf dialogId, bool removeDialog, bool deleteDialog)
167 {
168  DialogMap::iterator itr = mDialogMap.find(dialogId);
169 
170  if (itr != mDialogMap.end())
171  {
172  DialogWidget *dialogWidget = itr->second;
173 
174  // set the result to something else so DoMainLoop knows that the dialog is gone
175  // in case nobody else sets mResult
176  if (dialogWidget->mResult == -1)
177  dialogWidget->mResult = 0;
178 
179  DialogList::iterator listItr = std::find(mDialogList.begin(),
180  mDialogList.end(), dialogWidget);
181  if (listItr != mDialogList.end())
182  mDialogList.erase(listItr);
183 
184  mDialogMap.erase(itr);
185 
186  if (removeDialog || deleteDialog)
187  removeWidget(dialogWidget);
188 
189  if (dialogWidget->isModal())
190  {
192  removeBaseModal(dialogWidget);
193  }
194 
195  if (deleteDialog)
196  {
197  HF_SAFE_DELETE(dialogWidget);
198  }
199 
200  return true;
201  }
202 
203  return false;
204 }
205 
207 {
208  return killDialog(dialogId, true, true);
209 }
210 
212 {
213  return killDialog(dialogWidget->mId);
214 }
215 
217 {
218  return mDialogMap.size();
219 }
220 
221 void WidgetManager::addBaseModal(Widget *widget, const FlagsMod &belowFlagsMod)
222 {
223  PreModalInfo preModalInfo;
224  preModalInfo.mBaseModalWidget = widget;
225  preModalInfo.mPrevBaseModalWidget = mBaseModalWidget;
226  preModalInfo.mPrevFocusWidget = mFocusWidget;
228  mPreModalInfoList.push_back(preModalInfo);
229 
230  setBaseModal(widget, belowFlagsMod);
231 }
232 
234 {
236 }
237 
239 {
240  assert(mPreModalInfoList.size() > 0);
241 
242  bool first = true;
243 
244  while (mPreModalInfoList.size() > 0)
245  {
246  PreModalInfo *preModalInfo = &mPreModalInfoList.back();
247 
248  if ((first) && (preModalInfo->mBaseModalWidget != widget))
249  {
250  // We don't remove it yet, because we want to restore
251  // its keyboard focused widget and crap later
252  return;
253  }
254 
255  // If we removed a widget's self from pre-modal info before
256  // then that means the dialog got removed out-of-order but we
257  // deferred setting the state back until now
258  bool done = (preModalInfo->mPrevBaseModalWidget != NULL) ||
259  (mPreModalInfoList.size() == 1);
260 
261  setBaseModal(preModalInfo->mPrevBaseModalWidget,
262  preModalInfo->mPrevBelowModalFlagsMod);
263 
264  if (mFocusWidget == NULL)
265  {
266  mFocusWidget = preModalInfo->mPrevFocusWidget;
267  if (mFocusWidget != NULL)
269  }
270 
271  mPreModalInfoList.pop_back();
272 
273  if (done)
274  break;
275 
276  first = false;
277  }
278 }
279 
281 {
282  if (mOverWidget == widget)
283  {
284  Widget *overWidget = mOverWidget;
285  mOverWidget = NULL;
286  mouseLeave(overWidget);
287  }
288 
289  if (mLastDownWidget == widget)
290  {
291  Widget *lastDownWidget = mLastDownWidget;
293  doMouseUps(lastDownWidget);
294  }
295 
296  if (mFocusWidget == widget)
297  {
298  Widget *focusWidget = mFocusWidget;
299  mFocusWidget = NULL;
300  focusWidget->lostFocus();
301  }
302 
303  if (mBaseModalWidget == widget)
305 }
306 
308  fp32_hf *widgetX, fp32_hf *widgetY)
309 {
310  bool found;
311  return getWidgetAtHelper(x, y, getWidgetFlags(),
312  &found, widgetX, widgetY);
313 }
314 
316  fp32_hf *widgetX, fp32_hf *widgetY)
317 {
318  Widget *widget = getAnyWidgetAt(x, y, widgetX, widgetY);
319  if ((widget != NULL) && (widget->mDisabled))
320  widget = NULL;
321  return widget;
322 }
323 
325 {
326  if (widget == mFocusWidget)
327  return;
328 
329  if (mFocusWidget != NULL)
331 
332  if ((widget != NULL) && (widget->mWidgetManager == this))
333  {
334  mFocusWidget = widget;
335 
336  if ((mHasFocus) && (mFocusWidget != NULL))
338  }
339  else
340  mFocusWidget = NULL;
341 }
342 
344 {
345  if (!mHasFocus)
346  {
347  mHasFocus = true;
348 
349  if (mFocusWidget != NULL)
351  }
352 }
353 
355 {
356  if (mHasFocus)
357  {
358  mHasFocus = false;
359 
360  if (mFocusWidget != NULL)
362  }
363 }
364 
366 {
367  modalFlags->mIsOver = mBaseModalWidget == NULL;
368  modalFlags->mOverFlags = getWidgetFlags();
369  modalFlags->mUnderFlags = GetModFlags(modalFlags->mOverFlags, mBelowModalFlagsMod);
370 }
371 
373 {
375  {
376  widget->mIsDown = false;
377  widget->mouseButtonUp(mCurMouse);
378  }
379 }
380 
382 {
383  if (mLastDownWidget != NULL)
384  {
387  }
388 }
389 
391 {
392  mDeferredOverlayWidgets.push_back(std::pair<Widget *, int32_hf>(widget, priority));
393  if (priority < mMinDeferredOverlayPriority)
394  mMinDeferredOverlayPriority = priority;
395 }
396 
398 {
399  for (;;)
400  {
401  int32_hf nextMinPriority = 0x7FFFFFFF;
402 
403  for (int32_hf i = 0; i < (int32_hf) mDeferredOverlayWidgets.size(); i++)
404  {
405  Widget *widget = mDeferredOverlayWidgets[i].first;
406  if (widget != NULL)
407  {
408  int32_hf priority = mDeferredOverlayWidgets[i].second;
409 
410  if (priority == mMinDeferredOverlayPriority)
411  {
412  // Overlays don't get clipped
413  Graphics *g = HFCORE_ENV->getGraphics();
414  widget->drawOverlay(g);
415  }
416  else
417  {
418  if (priority < nextMinPriority)
419  nextMinPriority = priority;
420  }
421  }
422  }
423 
424  mMinDeferredOverlayPriority = nextMinPriority;
425 
426  // Lowest overlay priority is higher or equal to our current widget,
427  // so continue deferring
428  if (nextMinPriority >= maxPriority)
429  break;
430  }
431 }
432 
434 {
435  DeferredOverlayVector::iterator iter;
436  for (iter = mDeferredOverlayWidgets.begin(); iter != mDeferredOverlayWidgets.end(); iter++)
437  {
438  if (iter->first == widget)
439  {
440  mDeferredOverlayWidgets.erase(iter);
441  break;
442  }
443  }
444 }
445 
447 {
448  ModalFlags modalFlags;
449  initModalFlags(&modalFlags);
450 
451  mMinDeferredOverlayPriority = 0x7FFFFFFF;
452 
453  bool updateRenderTexture = false;
454  std::vector<Widget *> parentWidgetVector;
455  WidgetList::iterator itr = mWidgets.begin();
456  int i = 0;
457  while (itr != mWidgets.end())
458  {
459  Widget *widget = *itr;
460 
461  if (widget->mParentWidget)
462  {
463  parentWidgetVector.push_back(widget);
464  }
465 
466  if (widget == mWidgetManager->mBaseModalWidget)
467  modalFlags.mIsOver = true;
468 
469  if (widget->mVisible && widget->getIsDrawEnabled())
470  {
471  if (widget->getBatchUIUpdateNeeded())
472  {
473  updateRenderTexture = true;
474  }
475 
476  widget->drawAll(&modalFlags, g);
477 
478  // reset update:
479  widget->setBatchUIUpdateNeeded(false);
480  }
481  i++;
482 
483  ++itr;
484  }
485 
486  // overlay:
487  flushDeferredOverlayWidgets(0x7FFFFFFF);
488 
489  if (parentWidgetVector.size() > 0)
490  {
491  for (int32_hf i = 0; i < (int32_hf)parentWidgetVector.size(); i++)
492  {
493  Widget *parent = parentWidgetVector[i];
494 
495  parent->renderBatchCallback(g, updateRenderTexture);
496  }
497  }
498  else
499  {
500  g->renderBatchAll();
501  }
502  parentWidgetVector.clear();
503 }
504 
506 {
507  ModalFlags modalFlags;
508  initModalFlags(&modalFlags);
509 
510  updateAll(&modalFlags, dt);
511 }
512 
514 {
515  mPopupCommandWidget = list;
517 }
518 
520 {
521  if (mPopupCommandWidget != NULL)
522  {
523  Widget *widget = mPopupCommandWidget;
525  removeWidget(widget);
526  }
527 }
528 
530 {
531  if (mLastDownWidget != NULL)
532  {
533  if (mOverWidget != NULL)
534  {
536 
537  if (widgetOver != mLastDownWidget)
538  {
539  Widget *overWidget = mOverWidget;
540  mOverWidget = NULL;
541 
542  if (overWidget->getMouseListenerEnabled())
543  mouseLeave(overWidget);
544  }
545  }
546  }
547 }
548 
550 {
555 }
556 
558 {
559  if (mFocusWidget != NULL)
560  {
561  mFocusWidget->keyUp(kb);
562  }
563 }
564 
566 {
567  if (mFocusWidget != NULL)
568  {
569  mFocusWidget->keyDown(kb);
570  }
571 }
572 
574 {
575  fp32_hf x = touch.x;
576  fp32_hf y = touch.y;
577 
580 
581  fp32_hf widgetX;
582  fp32_hf widgetY;
583  Widget *widget = getWidgetAt(x, y, &widgetX, &widgetY);
584 
585  mLastDownWidget = widget;
586  if (widget != NULL)
587  {
588  if (widget->wantsFocus())
589  setFocus(widget);
590 
591  widget->mIsDown = true;
592 
593  if (widget->getTouchListenerEnabled())
594  {
595  widget->touchDown(touch);
596  }
597  }
598 }
599 
601 {
602  if ((mLastDownWidget != NULL))
603  {
604  Widget *lastDownWidget = mLastDownWidget;
606 
607  lastDownWidget->mIsDown = false;
608 
609  if (lastDownWidget->getTouchListenerEnabled())
610  {
611  lastDownWidget->touchUp(touch);
612  }
613  }
614 }
615 
617 {
618  if (mLastDownWidget != NULL)
619  {
621  mLastDownWidget->touchMove(touch);
622  }
623 }
624 
626 {
627  if (isLeftButtonDown() || isMiddleButtonDown() || isRightButtonDown())
628  return handleMouseDrag(mouse);
629 
630  mCurMouse = mouse;
631 
632  int32_hf lastMouseX = (int32_hf)mLastMouseX;
633  int32_hf lastMouseY = (int32_hf)mLastMouseY;
634 
635  mLastMouseX = mouse.x;
636  mLastMouseY = mouse.y;
637 
638  fp32_hf widgetX;
639  fp32_hf widgetY;
640  Widget *widget = getWidgetAt(mLastMouseX, mLastMouseY, &widgetX, &widgetY);
641 
642  if (widget != mOverWidget)
643  {
644  Widget *lastOverWidget = mOverWidget;
645  mOverWidget = NULL;
646 
647  if (lastOverWidget != NULL)
648  {
649  if (lastOverWidget->getMouseListenerEnabled())
650  mouseLeave(lastOverWidget);
651  }
652 
653  mOverWidget = widget;
654  if (widget != NULL)
655  {
656  if (widget->getMouseListenerEnabled())
657  {
658  mouseEnter(widget);
659  widget->mouseMove(mouse);
660  }
661  }
662  }
663  else if ((lastMouseX != mLastMouseX) || (lastMouseY != mLastMouseY))
664  {
665  if (widget != NULL)
666  {
667  if (widget->getMouseListenerEnabled())
668  widget->mouseMove(mouse);
669  }
670  }
671 }
672 
674 {
675  mCurMouseButton = mouse.button;
676 
677  fp32_hf x = mouse.x;
678  fp32_hf y = mouse.y;
679 
682 
683  fp32_hf widgetX;
684  fp32_hf widgetY;
685  Widget *widget = getWidgetAt(x, y, &widgetX, &widgetY);
686 
687  mLastDownWidget = widget;
688  if (widget != NULL)
689  {
690  if (widget->wantsFocus())
691  setFocus(widget);
692 
693  widget->mIsDown = true;
694 
695  if (widget->getMouseListenerEnabled())
696  widget->mouseButtonDown(mouse);
697  }
698 }
699 
701 {
703 
704  if ((mLastDownWidget != NULL))
705  {
706  Widget *lastDownWidget = mLastDownWidget;
708 
709  lastDownWidget->mIsDown = false;
710 
711  if (lastDownWidget->getMouseListenerEnabled())
712  lastDownWidget->mouseButtonUp(mouse);
713  }
714 }
715 
717 {
718  if (mFocusWidget != NULL)
719  {
721  mFocusWidget->mouseWheel(mouse);
722  }
723 }
724 
726 {
727  mMouseIn = true;
728 
729  if (mOverWidget != NULL)
730  {
732  mOverWidget->mouseEnter(mouse);
733  mOverWidget = NULL;
734  }
735 }
736 
738 {
739  mMouseIn = false;
740 
741  if (mOverWidget != NULL)
742  {
744  mOverWidget->mouseLeave(mouse);
745  mOverWidget = NULL;
746  }
747 }
748 
749 void WidgetManager::handleMouseDrag(Mouse::MouseInfo mouse)
750 {
751  mMouseIn = true;
752  mLastMouseX = mouse.x;
753  mLastMouseY = mouse.y;
754 
755  if ((mOverWidget != NULL) && (mOverWidget != mLastDownWidget))
756  {
757  Widget *overWidget = mOverWidget;
758  mOverWidget = NULL;
759  if (overWidget->getMouseListenerEnabled())
760  mouseLeave(overWidget);
761  }
762 
763  if (mLastDownWidget != NULL)
764  {
766  mLastDownWidget->mouseMove(mouse);
767 
769 
770  if ((widgetOver == mLastDownWidget) && (widgetOver != NULL))
771  {
772  if (mOverWidget == NULL)
773  {
777  }
778  }
779  else
780  {
781  if (mOverWidget != NULL)
782  {
783  Widget *overWidget = mOverWidget;
784  mOverWidget = NULL;
785  if (overWidget->getMouseListenerEnabled())
786  mouseLeave(overWidget);
787  }
788  }
789  }
790 }
791 
792 bool WidgetManager::isLeftButtonDown()
793 {
794  return (mCurMouseButton == Mouse::BUTTON_LEFT) ? true : false;
795 }
796 
797 bool WidgetManager::isMiddleButtonDown()
798 {
799  return (mCurMouseButton == Mouse::BUTTON_MIDDLE) ? true : false;
800 }
801 
802 bool WidgetManager::isRightButtonDown()
803 {
804  return (mCurMouseButton == Mouse::BUTTON_RIGHT) ? true : false;
805 }
806 
808 {
809  // inform all widgets:
810  WidgetList::iterator itrWidgets = mWidgets.begin();
811  while (itrWidgets != mWidgets.end())
812  {
813  Widget *widget = *itrWidgets;
814  widget->destroyRenderTextures();
815 
816  ++itrWidgets;
817  }
818 
819  // inform all dialogs:
820  DialogList::iterator itrDialogs = mDialogList.begin();
821  while (itrDialogs != mDialogList.end())
822  {
823  DialogWidget *widget = *itrDialogs;
824  widget->destroyRenderTextures();
825 
826  ++itrDialogs;
827  }
828 }
829 
831 {
832  // inform all widgets:
833  WidgetList::iterator itrWidgets = mWidgets.begin();
834  while (itrWidgets != mWidgets.end())
835  {
836  Widget *widget = *itrWidgets;
837  widget->createRenderTextures();
838 
839  ++itrWidgets;
840  }
841 
842  // inform all dialogs:
843  DialogList::iterator itrDialogs = mDialogList.begin();
844  while (itrDialogs != mDialogList.end())
845  {
846  DialogWidget *widget = *itrDialogs;
847  widget->createRenderTextures();
848 
849  ++itrDialogs;
850  }
851 }
virtual void keyUp(Keyboard::KeyboardInfo kb)
Called automatically when Keyboard keyUp event occurs.
Interface for all rendering related things.
virtual void mouseMove(Mouse::MouseInfo mouse)
Called automatically when Mouse motion event occurs.
Widget * mPopupCommandWidget
Holds pointer to popup command Widget.
virtual void drawAll(ModalFlags *flags, Graphics *g)
Calls draw() for all Widget&#39;s in internal list which have WIDGETFLAGS_DRAW set in flags...
No button pressed.
Definition: Mouse.h:57
fp32_hf x
X coordinate, relative to window.
Definition: Touch.h:55
void lostFocus()
Called when the Widget loses focus.
bool mParentWidget
Flag indicating if parent widget or not.
Definition: Widget.h:1030
void createRenderTextures()
Called by the framework when Render textures needs to be created/initialized.
void removePopupCommandWidget()
Remove popup command Widget.
virtual void keyDown(Keyboard::KeyboardInfo kb)
Called automatically when Keyboard keyDown event occurs.
Definition: Widget.cpp:243
virtual void setBatchUIUpdateNeeded(bool update)
Set BatchUI update needed flag.
Definition: Widget.cpp:503
Widget * mPrevFocusWidget
Pointer to previous focus Widget.
Definition: WidgetManager.h:60
Widget * mBaseModalWidget
Holds pointer to base modal Widget.
bool mIsOver
Flag indicating if over or not.
Definition: Flags.h:101
void updateFrame(fp32_hf dt)
Called by the framework once for every iteration of the game loop, immediately before rendering takes...
int32_hf getDialogCount()
Get DialogWidget count.
int32_hf GetModFlags(int32_hf flags, const FlagsMod &flagMod)
Get mod flags.
Definition: Flags.h:77
fp32_hf y
Y coordinate, relative to window.
Definition: Mouse.h:69
Widget * mLastDownWidget
Holds pointer to last down Widget.
Widget is a base class with core functionality for specialized Widget&#39;s to use / override / inherit f...
Definition: Widget.h:163
virtual void touchMove(Touch::TouchInfo touch)
Called automatically when Touch move/drag event occurs.
Definition: Widget.cpp:268
fp32_hf getWidth() const
Get Rect Width (or maxX).
Definition: Rect.h:168
#define HF_SAFE_DELETE(p)
Check if not NULL, delete and set to NULL.
Definition: HFDataTypes.h:49
void rehupMouse()
Rehup Mouse (calls Widget::mouseLeave()) if needed for over Widget.
int int32_hf
A type definition for int.
Definition: HFDataTypes.h:349
Rect mMouseDestRect
Holds Mouse destination Rect.
virtual void mouseButtonDown(Mouse::MouseInfo mouse)
Called automatically when Mouse button down event occurs.
Class for add / remove flags.
Definition: Flags.h:34
FlagsMod mBelowModalFlagsMod
Holds below modal FlagsMod.
virtual void mouseWheel(Mouse::MouseInfo mouse)
Called automatically when Mouse wheel event occurs.
FlagsMod mPrevBelowModalFlagsMod
Holds previous below modal FlagsMod.
Definition: WidgetManager.h:65
virtual void mouseLeave(Mouse::MouseInfo mouse)
Called automatically when Mouse leave event occurs.
Definition: Widget.cpp:292
void disableWidget(Widget *widget)
Disable widget.
virtual void touchUp(Touch::TouchInfo touch)
Called automatically when Touch up event occurs.
virtual bool getBatchUIUpdateNeeded()
Determine if BatchUI update is needed.
Definition: Widget.cpp:508
Widget * getWidgetAtHelper(fp32_hf x, fp32_hf y, int32_hf flags, bool *found, fp32_hf *widgetX, fp32_hf *widgetY)
Get Widget at x and y position which has flags set.
virtual void touchUp(Touch::TouchInfo touch)
Called automatically when Touch up event occurs.
Definition: Widget.cpp:264
DialogWidget * getDialog(int32_hf dialogId)
Get a pointer to DialogWidget for given dialogId.
void removeBaseModal(Widget *widget)
Remove base modal Widget.
Mouse::Button mCurMouseButton
Holds current Mouse button state.
virtual void showFinger(bool on)
Method for controlling if finger cursor should be shown.
Definition: Widget.cpp:157
bool mIsOver
Flag indicating if over or not.
Definition: Widget.h:1070
fp32_hf mLastMouseY
Holds last Mouse position Y.
fp32_hf x
X coordinate, relative to window.
Definition: Mouse.h:68
void removeOverlay(Widget *widget)
Remove widget from internal WidgetManager::DeferredOverlayVector.
FlagsMod mDefaultBelowModalFlagsMod
Holds default below modal FlagsMod.
virtual void modalDialogOpen()
Called for DialogWidget&#39;s which has mIsModal flag set to true during WidgetManager::addDialog() call...
bool mDoFinger
Flag indicating if we should show finger or not.
Definition: Widget.h:1091
A structure that contains Touch event information.
Definition: Touch.h:50
bool mHasFocus
Flag indicating if has focus or not.
virtual void mouseMove(Mouse::MouseInfo mouse)
Called automatically when Mouse motion event occurs.
Definition: Widget.cpp:272
virtual void keyUp(Keyboard::KeyboardInfo kb)
Called automatically when Keyboard keyUp event occurs.
Definition: Widget.cpp:239
virtual void updateAll(ModalFlags *flags, fp32_hf dt)
Calls update() for all Widget&#39;s in internal list which have WIDGETFLAGS_UPDATE set in flags...
virtual bool wantsFocus()
Determine whether Widget wants focus.
Definition: Widget.cpp:207
void gotFocus()
Called when the Widget gains focus.
fp32_hf getY() const
Get Rect Y (or minY).
Definition: Rect.h:159
Interface for Resource type Image.
void destroyRenderTextures()
Called by the framework when Render textures needs to be destroyed.
virtual void touchDown(Touch::TouchInfo touch)
Called automatically when Touch down event occurs.
#define NULL
Convenient define for 0.
Definition: HFDataTypes.h:42
virtual void keyDown(Keyboard::KeyboardInfo kb)
Called automatically when Keyboard keyDown event occurs.
void doMouseUps()
Call Widget::mouseButtonUp() for last down Widget.
void remapMouse(int32_hf &x, int32_hf &y)
Do some internal Mouse re-mapping.
Interface for UI DialogWidget.
Definition: DialogWidget.h:111
void flushDeferredOverlayWidgets(int32_hf maxPriority)
Calls Widget::drawOverlay() for all Widget&#39;s in internal WidgetManager::DeferredOverlayVector in prio...
virtual void mouseButtonUp(Mouse::MouseInfo mouse)
Called automatically when Mouse button up event occurs.
virtual void mouseEnter(Mouse::MouseInfo mouse)
Called automatically when Mouse enter event occurs.
Definition: Widget.cpp:288
void deferOverlay(Widget *widget, int32_hf priority)
Put widget in internal WidgetManager::DeferredOverlayVector.
virtual bool isModal()
Determine whether Dialog is modal.
Class for modal flags.
Definition: Flags.h:85
virtual void removeWidget(Widget *widget)
Remove a Widget and call removedFromManager().
A structure that contains Mouse event information.
Definition: Mouse.h:63
Widget * mPrevBaseModalWidget
Pointer to previous base modal Widget.
Definition: WidgetManager.h:55
Widget * getWidgetAt(fp32_hf x, fp32_hf y, fp32_hf *widgetX, fp32_hf *widgetY)
Get Widget at x and y position.
Widget * getAnyWidgetAt(fp32_hf x, fp32_hf y, fp32_hf *widgetX, fp32_hf *widgetY)
Get any Widget found at x and y position.
virtual void renderBatchCallback(Graphics *g, bool updateBatchUIRenderTexture)
Called by the framework when render batch should be performed.
Definition: Widget.cpp:525
A structure that contains Keyboard event information.
Definition: Keyboard.h:103
virtual void addWidget(Widget *widget)
Adds a new Widget and call addedToManager().
bool mMouseIn
Flag indicating if Mouse entered or not.
Right button.
Definition: Mouse.h:56
fp32_hf y
Y coordinate, relative to window.
Definition: Touch.h:56
FlagsMod mLostFocusFlagsMod
Holds lost focus FlagsMod.
fp32_hf mLastMouseX
Holds last Mouse position X.
virtual void modalDialogClose()
Called for DialogWidget&#39;s which has mIsModal flag set to true during WidgetManager::killDialog() call...
virtual void mouseLeave(Mouse::MouseInfo mouse)
Called automatically when Mouse leave event occurs.
fp32_hf getX() const
Get Rect X (or minX).
Definition: Rect.h:150
Button button
Mouse Button enum value.
Definition: Mouse.h:72
void setFocus(Widget *widget)
Set focus on widget.
virtual bool contains(int32_hf x, int32_hf y)
Determine whether a point specified by x and y is contained within Widget or not. ...
Definition: Widget.cpp:401
virtual ~WidgetManager()
Destructor.
void initModalFlags(ModalFlags *modalFlags)
Initialize ModalFlags to defaults.
void setPopupCommandWidget(Widget *list)
Set popup command Widget.
Left button.
Definition: Mouse.h:54
virtual bool isBelow(Widget *widget1, Widget *widget2)
Determine whether widget1 is below widget2.
void addDialog(int32_hf dialogId, DialogWidget *dialogWidget)
Add a DialogWidget.
bool killDialog(int32_hf dialogId, bool removeDialog, bool deleteDialog)
Kill DialogWidget with given dialogId.
virtual void gotFocus()
Called when the Widget gains focus.
Definition: Widget.cpp:229
virtual void mouseButtonUp(Mouse::MouseInfo mouse)
Called automatically when Mouse button up event occurs.
Definition: Widget.cpp:280
virtual void lostFocus()
Called when the Widget loses focus.
Definition: Widget.cpp:234
virtual bool getTouchListenerEnabled()
Determine whether TouchListener is enabled.
Definition: Widget.cpp:176
virtual void mouseWheel(Mouse::MouseInfo mouse)
Called automatically when Mouse wheel event occurs.
Definition: Widget.cpp:284
virtual void touchMove(Touch::TouchInfo touch)
Called automatically when Touch move/drag event occurs.
virtual void createRenderTextures()
Called by the framework when Render textures needs to be created/initialized.
Definition: Widget.cpp:521
Widget is a base class with core functionality for specialized Widget&#39;s to inherit from...
virtual bool getIsDrawEnabled()
Determine whether drawing is enabled.
Definition: Widget.cpp:498
int32_hf mId
Holds Dialog ID.
Definition: DialogWidget.h:521
Definition: Actor.h:34
virtual int32_hf getPreferredHeight(int32_hf width)
Calculate the preferred height of the Dialog.
int32_hf mUnderFlags
Holds under flags.
Definition: Flags.h:96
virtual void destroyRenderTextures()
Called by the framework when Render textures needs to be destroyed.
Definition: Widget.cpp:517
WidgetManager()
Constructor.
Singleton interface for platform specific things.
Mouse::MouseInfo mCurMouse
Holds current Mouse state.
int32_hf mRemoveFlags
Remove flags.
Definition: Flags.h:45
bool mVisible
Flag indicating if visible or not.
Definition: Widget.h:1045
Widget * mBaseModalWidget
Pointer to base modal Widget.
Definition: WidgetManager.h:50
virtual void drawOverlay(Graphics *g)
Called by the framework once for every iteration of the main loop.
Definition: Widget.cpp:216
Widget * mFocusWidget
Holds pointer to focus Widget.
Middle button.
Definition: Mouse.h:55
#define HFCORE_ENV
Get HFCore::Environment instance shortcut macro.
Definition: Environment.h:68
Interface for all rendering related things.
Definition: Graphics.h:120
virtual void mouseButtonDown(Mouse::MouseInfo mouse)
Called automatically when Mouse button down event occurs.
Definition: Widget.cpp:276
WidgetManager manages Widget&#39;s and interacts with Game interface.
Widget * mOverWidget
Holds pointer to over Widget.
bool mDisabled
Flag indicating if disabled or not.
Definition: Widget.h:1055
bool mIsDown
Flag indicating if down or not.
Definition: Widget.h:1065
virtual void mouseEnter(Mouse::MouseInfo mouse)
Called automatically when Mouse enter event occurs.
Rect mMouseSourceRect
Holds Mouse source Rect.
fp32_hf getHeight() const
Get Rect Height (or maxY).
Definition: Rect.h:177
virtual void renderBatchAll()=0
Render Batch. (each available Graphics::BatchMode)
void drawFrame(Graphics *g)
Called by the framework once for every iteration of the main loop.
int32_hf mOverFlags
Holds over flags.
Definition: Flags.h:91
int32_hf mWidgetFlags
Holds Widget flags.
virtual void resize(fp32_hf x, fp32_hf y, int32_hf w, int32_hf h)
Resize Widget.
DialogList mDialogList
Internal WidgetManager::DialogList.
PreModalInfoList mPreModalInfoList
Internal WidgetManager::PreModalInfoList.
WidgetManager * mWidgetManager
Pointer to WidgetManager.
int32_hf mResult
Holds result value.
Definition: DialogWidget.h:531
void addBaseModal(Widget *widget, const FlagsMod &belowFlagsMod)
Add a base modal Widget.
fp32_hf mWidth
Holds Widget width.
virtual void touchDown(Touch::TouchInfo touch)
Called automatically when Touch down event occurs.
Definition: Widget.cpp:260
DialogMap mDialogMap
Internal WidgetManager::DialogMap.
float fp32_hf
A type definition for float.
Definition: HFDataTypes.h:359
DeferredOverlayVector mDeferredOverlayWidgets
Internal WidgetManager::DeferredOverlayVector.
int32_hf mMinDeferredOverlayPriority
Holds minimum deferred overlay priority.
Class holding modal Widget info.
Definition: WidgetManager.h:44
fp32_hf mHeight
Holds Widget height.
WidgetList mWidgets
WidgetContainer::WidgetList holding child Widget&#39;s.
virtual bool getMouseListenerEnabled()
Determine whether MouseListener is enabled.
Definition: Widget.cpp:166