From 025e9a510da5fcce535cdfea387f69e06f23d894 Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Mon, 20 May 2024 23:55:28 +0200 Subject: [PATCH] Use `#if USING_TOLUAPP` in widgets.h/cpp --- src/include/widgets.h | 5 +++-- src/ui/widgets.cpp | 44 +++++++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/include/widgets.h b/src/include/widgets.h index ff7179a7b0..5e83d27394 100644 --- a/src/include/widgets.h +++ b/src/include/widgets.h @@ -45,7 +45,7 @@ void initGuichan(); void freeGuichan(); void handleInput(const SDL_Event *event); -#if 1 // ToLua++ +#if USING_TOLUAPP void addActionListener(gcn::Widget *, gcn::ActionListener *); void setBackgroundColor(gcn::Widget *, const gcn::Color &); void setBaseColor(gcn::Widget *, const gcn::Color &color); @@ -102,7 +102,8 @@ class ButtonWidget : public gcn::Button public: explicit ButtonWidget(const std::string &caption) : Button(caption) { - ::setHotKey(this, caption.c_str()); + gcn::Key key = GetHotKey(caption); + setHotKey(key.getValue()); } }; diff --git a/src/ui/widgets.cpp b/src/ui/widgets.cpp index 818e3b880a..5408fb06f1 100644 --- a/src/ui/widgets.cpp +++ b/src/ui/widgets.cpp @@ -63,6 +63,8 @@ static std::stack MenuStack; -- Functions ----------------------------------------------------------------------------*/ +#if USING_TOLUAPP + void addActionListener(gcn::Widget *widget, gcn::ActionListener *actionListener) { // gcn::Widget::addActionListener is no longer virtual @@ -129,6 +131,28 @@ void setFont(gcn::Widget *widget, gcn::Font *font) } } +void setHotKey(gcn::Widget* widget, const char *keyStr) +{ + if (widget && keyStr) { + gcn::Key key = GetHotKey(keyStr); + widget->setHotKey(key.getValue()); + } +} + +void scrollToBottom(gcn::ScrollArea *scrollArea) +{ + Assert(scrollArea); + scrollArea->setVerticalScrollAmount(scrollArea->getVerticalMaxScroll()); +} + +void scrollToTop(gcn::ScrollArea *scrollArea) +{ + Assert(scrollArea); + scrollArea->setVerticalScrollAmount(0); +} + +#endif + static void MenuHandleMouseMove(const PixelPos &screenPos) { PixelPos pos(screenPos); @@ -224,26 +248,6 @@ void DrawGuichanWidgets() } } -void setHotKey(gcn::Widget* widget, const char *keyStr) -{ - if (widget && keyStr) { - gcn::Key key = GetHotKey(keyStr); - widget->setHotKey(key.getValue()); - } -} - -void scrollToBottom(gcn::ScrollArea *scrollArea) -{ - Assert(scrollArea); - scrollArea->setVerticalScrollAmount(scrollArea->getVerticalMaxScroll()); -} - -void scrollToTop(gcn::ScrollArea *scrollArea) -{ - Assert(scrollArea); - scrollArea->setVerticalScrollAmount(0); -} - /*---------------------------------------------------------------------------- -- LuaActionListener ----------------------------------------------------------------------------*/