71 #include "gui/viewport.h"
105 #include "utils/timer.h"
121 mLastMousePressTimeStamp(0U),
126 mWidgetWithMouseQueue(),
134 mMouseCursorAlpha(1.0F),
135 mMouseInactivityTimer(0),
146 mCustomCursor(false),
174 const bool isJapan = (!langs.empty() && langs[0].size() > 3
175 && langs[0].substr(0, 3) ==
"ja_");
176 const bool isChinese = (!langs.empty() && langs[0].size() > 3
177 && langs[0].substr(0, 3) ==
"zh_");
185 if (fontFile.empty())
191 if (fontFile.empty())
194 if (fontFile.empty())
197 mGuiFont =
new Font(fontFile, fontSize, TTF_STYLE_NORMAL);
204 if (fontFile.empty())
210 if (fontFile.empty())
213 if (fontFile.empty())
220 if (fontFile.empty())
223 boldFont =
new Font(fontFile, fontSize, TTF_STYLE_NORMAL);
227 if (fontFile.empty())
234 if (fontFile.empty())
245 if (fontFile.empty())
251 if (fontFile.empty())
254 if (fontFile.empty())
257 mNpcFont =
new Font(fontFile, npcFontSize, TTF_STYLE_NORMAL);
401 bool consumed(
false);
407 KeyEvent eventToGlobalKeyListeners(
nullptr,
412 if (!keyInput.getText().empty())
413 eventToGlobalKeyListeners.setText(keyInput.getText());
417 eventToGlobalKeyListeners);
429 bool eventConsumed =
false;
438 if (!keyInput.getText().empty())
439 event.setText(keyInput.getText());
447 eventConsumed =
event.isConsumed();
494 ((button & SDL_BUTTON(1)) != 0)) &&
507 const int posY = mouseY +
508 (image !=
nullptr ? image->mBounds.h / 2 : 0);
515 if (image !=
nullptr)
517 const int posX = mouseX - (image->mBounds.w / 2);
518 const int posY = mouseY - (image->mBounds.h / 2);
525 if (mouseCursor !=
nullptr)
542 const int oldWidth =
top->getWidth();
543 const int oldHeight =
top->getHeight();
546 top->adjustAfterResize(oldWidth, oldHeight);
576 logger->
log(
"Error: Unable to load mouse cursors.");
596 if (
mTop !=
nullptr &&
598 (mouseInput.
getX() < 0 ||
599 mouseInput.
getY() < 0 ||
627 const int mouseX = mouseInput.
getX();
628 const int mouseY = mouseInput.
getY();
634 while (!widgetWithMouseQueueCheckDone)
636 unsigned int iterations = 0;
637 for (std::deque<Widget*>::iterator
642 Widget *
const widget = *iter;
680 widgetWithMouseQueueCheckDone =
706 if (
x > mouseX ||
y > mouseY
714 while (parent !=
nullptr)
719 bool widgetIsPresentInQueue =
false;
720 FOR_EACH (std::deque<Widget*>::const_iterator,
725 widgetIsPresentInQueue =
true;
732 if (!widgetIsPresentInQueue
745 const Widget *
const swap = widget;
776 const int x = mouseInput.
getX();
777 const int y = mouseInput.
getY();
779 const unsigned int timeStamp = mouseInput.
getTimeStamp();
786 if (sourceWidget ==
nullptr)
828 if (fontFile.empty())
834 if (fontFile.empty())
840 if (fontFile.empty())
848 if (fontFile.empty())
857 const int x,
const int y,
859 const bool toSourceOnly)
885 while (parent !=
nullptr)
900 event.setX(
x - widgetX);
901 event.setY(
y - widgetY);
903 std::list<MouseListener*> mouseListeners
908 FOR_EACH (std::list<MouseListener*>::const_iterator,
914 (*it)->mouseEntered(event);
917 (*it)->mouseExited(event);
920 (*it)->mouseMoved(event);
923 (*it)->mousePressed(event);
927 (*it)->mouseReleased(event);
930 (*it)->mouseWheelMovedUp(event);
933 (*it)->mouseWheelMovedDown(event);
936 (*it)->mouseDragged(event);
939 (*it)->mouseClicked(event);
950 const Widget *
const swap = widget;
959 if ((widget ==
nullptr) || event.
isConsumed())
988 if ((
viewport ==
nullptr) || (widget ==
nullptr))
1011 if (widget ==
nullptr)
1015 while (widget->getParent() !=
nullptr)
1017 x += widget->getX();
1018 y += widget->getY();
1019 widget = widget->getParent();
1035 mLastMouseRealX, mLastMouseRealY);
1048 mLastMouseRealX = mouseInput.
getRealX();
1049 mLastMouseRealY = mouseInput.
getRealY();
1084 mouseInput.
getX(), mouseInput.
getY());
1093 Widget *
const oldWidget = sourceWidget;
1095 if ((oldWidget !=
nullptr) && oldWidget != sourceWidget)
1108 if (sourceWidget ==
nullptr)
1158 (*iter)->focusGained(focusEvent);
1182 if (
mTop !=
nullptr)
1223 mouseInput.
getX(), mouseInput.
getY());
1228 if (sourceWidget !=
nullptr)
1230 int sourceWidgetX = 0;
1231 int sourceWidgetY = 0;
1247 mouseInput.
getX(), mouseInput.
getY());
1252 if (sourceWidget !=
nullptr)
1275 while (child !=
nullptr)
1277 Widget *
const swap = child;
1284 selectable = parent;
1293 if (widget ==
nullptr)
1310 while (widget !=
nullptr &&
1322 Widget* parent =
event.getSource();
1325 if (parent ==
nullptr)
1338 while (parent !=
nullptr)
1349 std::list<KeyListener*> keyListeners
1354 FOR_EACH (std::list<KeyListener*>::const_iterator,
1360 (*it)->keyPressed(event);
1363 (*it)->keyReleased(event);
1371 const Widget *
const swap = widget;
1377 if ((widget !=
nullptr) &&
1388 BLOCK_START(
"Gui::distributeKeyEventToGlobalKeyListeners")
1395 (*it)->keyPressed(event);
1398 (*it)->keyReleased(event);
1407 BLOCK_END(
"Gui::distributeKeyEventToGlobalKeyListeners")
1413 Widget *
const lastModalWidget
1416 if (lastModalWidget != modalWidget)
1419 if (lastModalWidget ==
nullptr)
1431 BLOCK_END(
"Gui::handleModalMouseInputFocus")
1437 Widget *
const lastModalWidget
1441 if (lastModalWidget != modalWidget)
1444 if (lastModalWidget ==
nullptr)
1493 while (parent !=
nullptr &&
1499 bool widgetIsPresentInQueue =
false;
1500 FOR_EACH (std::deque<Widget*>::const_iterator,
1503 if (*iter == widget)
1505 widgetIsPresentInQueue =
true;
1524 const Widget *
const swap = widget;
1534 unsigned int ticks = SDL_GetTicks();
void setOpaque(Opaque opaque)
std::string getValue(const std::string &key, const std::string &deflt) const
bool getBoolValue(const std::string &key) const
std::string getStringValue(const std::string &key) const
void addListener(const std::string &key, ConfigListener *const listener)
void removeListeners(ConfigListener *const listener)
int getIntValue(const std::string &key) const
const std::string & getText() const
void setLastWidgetWithModalFocus(Widget *const widget)
Widget * getLastWidgetWithModalMouseInputFocus() const
Widget * getModalMouseInputFocused() const
Widget * getDraggedWidget() const
Widget * getFocused() const
Widget * getLastWidgetPressed() const
void setLastWidgetWithModalMouseInputFocus(Widget *const widget)
void setDraggedWidget(Widget *const draggedWidget)
Widget * getModalFocused() const
Widget * getLastWidgetWithModalFocus() const
void setLastWidgetPressed(Widget *const lastWidgetPressed)
void slowLogic(const int rnd)
void loadFont(std::string filename, const int size, const int style)
int getWidth(const std::string &text) const
void drawString(Graphics *const graphics, Color col, const Color &col2, const std::string &text, const int x, const int y)
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
virtual void popClipArea()
virtual void pushClipArea(const Rect &area)
std::deque< Widget * > mWidgetWithMouseQueue
void removeGlobalKeyListener(KeyListener *const keyListener)
void distributeGlobalFocusGainedEvent(const Event &focusEvent)
Widget * getMouseEventSource(const int x, const int y) const
int getMousePressLength() const
KeyListenerList::iterator KeyListenerListIterator
void handleMouseMoved(const MouseInput &mouseInput)
int mMouseInactivityTimer
MouseButtonT mLastMouseDragButton
SDLInput * getInput() const
void handleModalFocusGained()
static uint8_t getMouseState(int &x, int &y)
unsigned int mLastMousePressTimeStamp
void setInput(SDLInput *const input)
void setUseCustomCursor(const bool customCursor)
Widget * getWidgetAt(const int x, const int y) const
FocusListenerList::iterator FocusListenerIterator
void removeGlobalFocusListener(FocusListener *focusListener)
void distributeMouseEvent(Widget *const source, const MouseEventTypeT type, const MouseButtonT button, const int x, const int y, const bool force, const bool toSourceOnly)
Graphics * getGraphics() const
static void getAbsolutePosition(Widget *widget, int &x, int &y)
KeyListenerList mKeyListeners
void addGlobalKeyListener(KeyListener *const keyListener)
GuiConfigListener * mConfigListener
void handleModalFocusReleased()
FocusHandler * mFocusHandler
void videoResized() const
void handleMousePressed(const MouseInput &mouseInput)
void handleModalMouseInputFocus()
FocusListenerList mFocusListeners
void setDoubleClick(const bool b)
MouseEvent * createMouseEvent(Window *const widget)
void distributeKeyEventToGlobalKeyListeners(KeyEvent &event)
MouseButtonT mLastMousePressButton
void handleMouseWheelMovedUp(const MouseInput &mouseInput)
void distributeKeyEvent(KeyEvent &event) const
void removeDragged(const Widget *const widget)
void handleMouseReleased(const MouseInput &mouseInput)
void postInit(Graphics *const graphics)
void setGraphics(Graphics *const graphics)
void handleMouseWheelMovedDown(const MouseInput &mouseInput)
void addGlobalFocusListener(FocusListener *focusListener)
void setTop(Widget *const top)
Widget * getKeyEventSource() const
Image * get(const size_type i) const
static void finalCleanup()
void log(const char *const log_text,...)
void log1(const char *const log_text)
static void advanceGradients()
bool isPointInRect(const int x_, const int y_) const
static void finalCleanup()
static ImageSet * getImageSetFromTheme(const std::string &path, const int w, const int h)
bool processEvent(const MouseInput &mouseInput)
static void setWindowContainer(WindowContainer *const windowContainer)
#define FOR_EACH(type, iter, array)
const Image *restrict const top
KeyEventType ::T KeyEventTypeT
MouseEventType ::T MouseEventTypeT
const DyeColor * getColor(const std::string &name)
bool cleanOrphans(const bool always)
void showCursor(const bool show)
#define BLOCK_START(name)
#define isBatchDrawRenders(val)
std::vector< std::string > StringVect
TouchManager touchManager
WindowContainer * windowContainer