diff --git a/doomsday/sdk/libappfw/include/de/FadeToBlackWidget b/doomsday/sdk/libappfw/include/de/FadeToBlackWidget new file mode 100644 index 0000000000..906d4fbbc2 --- /dev/null +++ b/doomsday/sdk/libappfw/include/de/FadeToBlackWidget @@ -0,0 +1 @@ +#include "widgets/fadetoblackwidget.h" diff --git a/doomsday/sdk/libappfw/include/de/GuiWidgetRef b/doomsday/sdk/libappfw/include/de/GuiWidgetRef new file mode 100644 index 0000000000..f500fea646 --- /dev/null +++ b/doomsday/sdk/libappfw/include/de/GuiWidgetRef @@ -0,0 +1 @@ +#include "framework/guiwidgetref.h" diff --git a/doomsday/sdk/libappfw/include/de/framework/guiwidgetref.h b/doomsday/sdk/libappfw/include/de/framework/guiwidgetref.h new file mode 100644 index 0000000000..62419d897f --- /dev/null +++ b/doomsday/sdk/libappfw/include/de/framework/guiwidgetref.h @@ -0,0 +1,69 @@ +/** @file guiwidgetref.h Smart pointer to a GuiWidget. + * + * @authors Copyright (c) 2015 Jaakko Keränen + * + * @par License + * LGPL: http://www.gnu.org/licenses/lgpl.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at your + * option) any later version. This program is distributed in the hope that it + * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this program; if not, see: + * http://www.gnu.org/licenses + */ + +#ifndef LIBAPPFW_GUIWIDGETREF_H +#define LIBAPPFW_GUIWIDGETREF_H + +#include "../GuiWidget" + +namespace de { + +/** + * Smart pointer to a GuiWidget. Does not own the target widget. + */ +template +class GuiWidgetRef : DENG2_OBSERVES(Widget, Deletion) +{ +public: + GuiWidgetRef(WidgetType *ptr = nullptr) { + reset(ptr); + } + ~GuiWidgetRef() { + reset(nullptr); + } + void reset(WidgetType *ptr) { + if(_ptr) _ptr->Widget::audienceForDeletion() -= this; + _ptr = ptr; + if(_ptr) _ptr->Widget::audienceForDeletion() += this; + } + WidgetType *operator -> () const { + return _ptr; + } + operator WidgetType const * () const { + return _ptr; + } + operator WidgetType * () { + return _ptr; + } + explicit operator bool() const { + return _ptr != nullptr; + } + void widgetBeingDeleted(Widget &widget) { + if(&widget == _ptr) { + _ptr = nullptr; + } + } + +private: + WidgetType *_ptr = nullptr; +}; + +} // namespace de + +#endif // LIBAPPFW_GUIWIDGETREF_H + diff --git a/doomsday/sdk/libappfw/include/de/widgets/fadetoblackwidget.h b/doomsday/sdk/libappfw/include/de/widgets/fadetoblackwidget.h new file mode 100644 index 0000000000..0cb4c6b977 --- /dev/null +++ b/doomsday/sdk/libappfw/include/de/widgets/fadetoblackwidget.h @@ -0,0 +1,52 @@ +/** @file fadetoblackwidget.h Fade to/from black. + * + * @authors Copyright (c) 2015 Jaakko Keränen + * + * @par License + * LGPL: http://www.gnu.org/licenses/lgpl.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at your + * option) any later version. This program is distributed in the hope that it + * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this program; if not, see: + * http://www.gnu.org/licenses + */ + +#ifndef LIBAPPFW_FADETOBLACKWIDGET +#define LIBAPPFW_FADETOBLACKWIDGET + +#include "../LabelWidget" +#include + +namespace de { + +/** + * Fade to/from black. + */ +class FadeToBlackWidget : public LabelWidget +{ +public: + FadeToBlackWidget(); + + void initFadeFromBlack(TimeDelta const &span); + + void start(); + + void cancel(); + + bool isDone() const; + + void disposeIfDone(); + +private: + DENG2_PRIVATE(d) +}; + +} // namespace de + +#endif // LIBAPPFW_FADETOBLACKWIDGET + diff --git a/doomsday/sdk/libappfw/src/widgets/fadetoblackwidget.cpp b/doomsday/sdk/libappfw/src/widgets/fadetoblackwidget.cpp new file mode 100644 index 0000000000..addc4ff827 --- /dev/null +++ b/doomsday/sdk/libappfw/src/widgets/fadetoblackwidget.cpp @@ -0,0 +1,62 @@ +/** @file fadetoblackwidget.cpp Fade to/from black. + * + * @authors Copyright (c) 2015 Jaakko Keränen + * + * @par License + * LGPL: http://www.gnu.org/licenses/lgpl.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at your + * option) any later version. This program is distributed in the hope that it + * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this program; if not, see: + * http://www.gnu.org/licenses + */ + +#include "de/FadeToBlackWidget" + +namespace de { + +DENG2_PIMPL_NOREF(FadeToBlackWidget) +{ + TimeDelta span = 1; +}; + +FadeToBlackWidget::FadeToBlackWidget() : d(new Instance) +{ + set(Background(Vector4f(0, 0, 0, 1))); +} + +void FadeToBlackWidget::initFadeFromBlack(TimeDelta const &span) +{ + setOpacity(1); + d->span = span; +} + +void FadeToBlackWidget::start() +{ + setOpacity(0, d->span); +} + +void FadeToBlackWidget::cancel() +{ + setOpacity(0); +} + +bool FadeToBlackWidget::isDone() const +{ + return opacity().done(); +} + +void FadeToBlackWidget::disposeIfDone() +{ + if(isDone()) + { + destroyLater(this); + } +} + +} // namespace de