Skip to content

Commit

Permalink
InFine|FinalePageWidget: FinalePageWidget has ownership of child Fina…
Browse files Browse the repository at this point in the history
…leWidgets
  • Loading branch information
danij-deng committed Oct 15, 2014
1 parent d1b83d9 commit 1326724
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 246 deletions.
2 changes: 0 additions & 2 deletions doomsday/client/client.pro
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ DENG_HEADERS += \
include/ui/infine/finaletextwidget.h \
include/ui/infine/finalewidget.h \
include/ui/infine/infinesystem.h \
include/ui/infine/ui2_main.h \
include/ui/progress.h \
include/ui/widgetactions.h \
include/ui/widgets/busywidget.h \
Expand Down Expand Up @@ -700,7 +699,6 @@ SOURCES += \
src/ui/infine/finaletextwidget.cpp \
src/ui/infine/finalewidget.cpp \
src/ui/infine/infinesystem.cpp \
src/ui/infine/ui2_main.cpp \
src/ui/inputsystem.cpp \
src/ui/mouse_qt.cpp \
src/ui/nativeui.cpp \
Expand Down
3 changes: 1 addition & 2 deletions doomsday/client/include/de_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
#ifndef LIBDENG_USER_INTERFACE_H
#define LIBDENG_USER_INTERFACE_H

#include "ui/infine/finale.h"
#include "ui/infine/ui2_main.h"
#include "ui/infine/infinesystem.h"

#ifdef __CLIENT__
# include <de/input/ddkey.h>
Expand Down
2 changes: 0 additions & 2 deletions doomsday/client/include/ui/infine/finaleinterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ class FinaleInterpreter
*/
FinaleWidget &findOrCreateWidget(fi_obtype_e type, de::String const &name);

void removeWidget(FinaleWidget *widgetToRemove);

public: /// Script-level flow/state control (@todo make private): --------------------

void beginDoSkipMode();
Expand Down
18 changes: 12 additions & 6 deletions doomsday/client/include/ui/infine/finalepagewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class FinalePageWidget
/// An invalid font index was specified. @ingroup errors
DENG2_ERROR(InvalidFontError);

/// @note Unlike de::Visual the children are not owned by the page.
typedef QList<FinaleWidget *> Widgets;
typedef QList<FinaleWidget *> Children;

public:
FinalePageWidget();
Expand All @@ -62,22 +61,29 @@ class FinalePageWidget
bool hasWidget(FinaleWidget *widget);

/**
* Adds a widget to the page if not already present.
* Add a child widget to the page, transferring ownership. If the widget is
* already contained by the page then nothing happens.
*
* @param widgetToAdd Widget to be added.
*
* @return Same as @a widgetToAdd, for convenience.
*/
FinaleWidget *addWidget(FinaleWidget *widgetToAdd);
FinaleWidget *addChild(FinaleWidget *widgetToAdd);

/**
* Removes a widget from the page if present.
* Remove a child widget from the page, transferring ownership to the caller
* if owned by the page.
*
* @param widgetToRemove Widget to be removed.
*
* @return Same as @a widgetToRemove, for convenience.
*/
FinaleWidget *removeWidget(FinaleWidget *widgetToRemove);
FinaleWidget *removeChild(FinaleWidget *widgetToRemove);

/**
* Provides a list of all child widgets of the page, in addition order.
*/
Children const &children() const;

FinalePageWidget &setOffset(de::Vector3f const &newOffset, int steps = 0);
FinalePageWidget &setOffsetX(float newOffsetX, int steps = 0);
Expand Down
38 changes: 0 additions & 38 deletions doomsday/client/include/ui/infine/ui2_main.h

This file was deleted.

4 changes: 0 additions & 4 deletions doomsday/client/src/dd_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
#include "world/worldsystem.h"
#include "world/map.h"
#include "ui/infine/infinesystem.h"
#include "ui/infine/ui2_main.h"
#include "ui/p_control.h"
#include "ui/progress.h"
#include "ui/nativeui.h"
Expand Down Expand Up @@ -2204,9 +2203,6 @@ static int DD_StartupWorker(void * /*context*/)
Net_InitGame();
#ifdef __CLIENT__
Demo_Init();

LOG_VERBOSE("Initializing UI subsystem...");
UI_Init();
#endif
Con_SetProgress(190);

Expand Down
2 changes: 0 additions & 2 deletions doomsday/client/src/dd_pinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

#include "def_main.h"
#include "gl/svg.h"
#include "ui/infine/ui2_main.h" /// @todo Remove me

#ifdef __CLIENT__
# include "render/r_draw.h"
Expand Down Expand Up @@ -148,7 +147,6 @@ void DD_ShutdownAll()
#ifdef __CLIENT__
App_InFineSystem().deinitBindingContext();
#endif
UI_Shutdown();
Con_Shutdown();
DD_ShutdownHelp();

Expand Down
127 changes: 23 additions & 104 deletions doomsday/client/src/ui/infine/finaleinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,78 +409,6 @@ DENG2_PIMPL(FinaleInterpreter)
EventHandlers eventHandlers;
#endif // __CLIENT__

struct KnownObjects
{
struct Item
{
String name; ///< Unique among objects of the same type.
Id id = { Id::None };
};
typedef QList<Item> AllItems;
AllItems items;

void clear()
{
items.clear();
}

template <typename WidgetType>
fi_objectid_t toId(String const &name)
{
if(!name.isEmpty())
{
for(Item const &item : items)
{
if(item.name.compareWithoutCase(name)) continue;

FinaleWidget *widget = FI_Widget(item.id);
if(widget && widget->is<WidgetType>())
{
return item.id;
}
}
}
return 0;
}

int indexOf(FinaleWidget *widget)
{
if(widget)
{
for(int i = 0; i < items.count(); ++i)
{
if(items.at(i).id == widget->id()) return i + 1; // 1-based
}
}
return 0;
}

/**
* @note Does not check if the object already exists in this scope.
*/
FinaleWidget *add(FinaleWidget *widget)
{
DENG2_ASSERT(widget);
items.append(Item());
Item &item = items.last();
item.id = widget->id();
item.name = widget->name();
return widget;
}

/**
* @pre There is at most one reference to the object in this scope.
*/
FinaleWidget *remove(FinaleWidget *widget)
{
if(int index = indexOf(widget))
{
items.removeAt(index - 1 /*make zero-based*/);
}
return widget;
}
} names;

/// Pages on which objects created by this interpeter are visible.
FinalePageWidget *pages[2];

Expand Down Expand Up @@ -893,33 +821,34 @@ DENG2_PIMPL(FinaleInterpreter)

static inline PageIndex choosePageFor(FinaleWidget &widget)
{
return (widget.is<FinaleAnimWidget>()? Anims : Texts);
return widget.is<FinaleAnimWidget>()? Anims : Texts;
}

void clearAllWidgets()
static inline PageIndex choosePageFor(fi_obtype_e type)
{
while(!names.items.isEmpty())
{
FinaleWidget *widget = FI_Widget(names.items.first().id);
DENG2_ASSERT(widget);
self.removeWidget(widget);
}
return type == FI_ANIM? Anims : Texts;
}

void clearAllWidgets()
{
delete pages[Anims]; pages[Anims] = nullptr;
delete pages[Texts]; pages[Texts] = nullptr;
}

/// @todo Refactor away.
FinaleWidget *locateWidget(fi_obtype_e type, String const &name)
{
DENG2_ASSERT(!name.isEmpty());
// An existing widget?
if(fi_objectid_t found = (type == FI_ANIM? names.toId<FinaleAnimWidget>(name)
: names.toId<FinaleTextWidget>(name)))
if(!name.isEmpty())
{
return FI_Widget(found);
FinalePageWidget::Children const &children = pages[choosePageFor(type)]->children();
for(FinaleWidget *widget : children)
{
if(!widget->name().compareWithoutCase(name))
{
return widget;
}
}
}
return nullptr;
return nullptr; // Not found.
}

FinaleWidget *makeWidget(fi_obtype_e type, String const &name)
Expand Down Expand Up @@ -1318,21 +1247,20 @@ FinalePageWidget const &FinaleInterpreter::page(PageIndex index) const
FinaleWidget *FinaleInterpreter::tryFindWidget(String const &name)
{
// Perhaps an Anim?
if(fi_objectid_t found = d->names.toId<FinaleAnimWidget>(name))
if(FinaleWidget *found = d->locateWidget(FI_ANIM, name))
{
return FI_Widget(found);
return found;
}
// Perhaps a Text?
if(fi_objectid_t found = d->names.toId<FinaleTextWidget>(name))
if(FinaleWidget *found = d->locateWidget(FI_TEXT, name))
{
return FI_Widget(found);
return found;
}
return nullptr;
}

FinaleWidget &FinaleInterpreter::findWidget(fi_obtype_e type, String const &name)
{
DENG2_ASSERT(!name.isEmpty());
if(FinaleWidget *foundWidget = d->locateWidget(type, name))
{
return *foundWidget;
Expand All @@ -1352,16 +1280,7 @@ FinaleWidget &FinaleInterpreter::findOrCreateWidget(fi_obtype_e type, String con
FinaleWidget *newWidget = d->makeWidget(type, name);
if(!newWidget) throw Error("FinaleInterpreter::findOrCreateWidget", "Failed making widget for type:" + String::number(int(type)));

FI_Link(newWidget); // Link in the global store.
d->names.add(newWidget); // Link in the local namespace.
return *page(d->choosePageFor(*newWidget)).addWidget(newWidget);
}

void FinaleInterpreter::removeWidget(FinaleWidget *widgetToRemove)
{
if(!widgetToRemove) return;
FI_Unlink(widgetToRemove);
delete d->names.remove(widgetToRemove);
return *page(d->choosePageFor(*newWidget)).addChild(newWidget);
}

void FinaleInterpreter::beginDoSkipMode()
Expand Down Expand Up @@ -1690,7 +1609,7 @@ DEFFC(Marker)
DEFFC(Delete)
{
DENG2_UNUSED(cmd);
fi.removeWidget(fi.tryFindWidget(OP_CSTRING(0)));
delete fi.tryFindWidget(OP_CSTRING(0));
}

DEFFC(Image)
Expand Down Expand Up @@ -2280,7 +2199,7 @@ DEFFC(SetTextDef)
DEFFC(DeleteText)
{
DENG2_UNUSED(cmd);
fi.removeWidget(fi.tryFindWidget(OP_CSTRING(0)));
delete fi.tryFindWidget(OP_CSTRING(0));
}

DEFFC(PredefinedColor)
Expand Down
Loading

0 comments on commit 1326724

Please sign in to comment.