Skip to content

Commit

Permalink
Refactor|libgui: Use pimpl-friendly audiences for libgui classes
Browse files Browse the repository at this point in the history
All usage of libgui classes updated accordingly.
  • Loading branch information
skyjake committed Mar 2, 2014
1 parent b92c4b3 commit c72e342
Show file tree
Hide file tree
Showing 25 changed files with 189 additions and 79 deletions.
12 changes: 6 additions & 6 deletions doomsday/client/src/ui/clientwindow.cpp
Expand Up @@ -130,16 +130,16 @@ DENG2_PIMPL(ClientWindow)
App::app().audienceForStartupComplete() += this;

// Listen to input.
self.canvas().audienceForMouseStateChange += this;
self.canvas().audienceForMouseStateChange() += this;
}

~Instance()
{
App::app().audienceForGameChange() -= this;
App::app().audienceForStartupComplete() -= this;

self.canvas().audienceForFocusChange -= this;
self.canvas().audienceForMouseStateChange -= this;
self.canvas().audienceForFocusChange() -= this;
self.canvas().audienceForMouseStateChange() -= this;

releaseRef(cursorX);
releaseRef(cursorY);
Expand Down Expand Up @@ -341,7 +341,7 @@ DENG2_PIMPL(ClientWindow)
}
*/

self.canvas().audienceForFocusChange += this;
self.canvas().audienceForFocusChange() += this;

#ifdef WIN32
if(self.isFullScreen())
Expand Down Expand Up @@ -651,8 +651,8 @@ ClientWindow::ClientWindow(String const &id)
: BaseWindow(id)
, d(new Instance(this))
{
canvas().audienceForGLResize += this;
canvas().audienceForGLInit += this;
canvas().audienceForGLResize() += this;
canvas().audienceForGLInit() += this;

#ifdef WIN32
// Set an icon for the window.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/ui/dialogs/videosettingsdialog.cpp
Expand Up @@ -70,12 +70,12 @@ DENG2_OBSERVES(PersistentCanvasWindow, AttributeChange)
#ifdef USE_COLOR_DEPTH_CHOICE
area.add(depths = new ChoiceWidget);
#endif
win.audienceForAttributeChange += this;
win.audienceForAttributeChange() += this;
}

~Instance()
{
win.audienceForAttributeChange -= this;
win.audienceForAttributeChange() -= this;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libappfw/include/de/framework/guiwidgetprivate.h
Expand Up @@ -60,7 +60,7 @@ class GuiWidgetPrivate : public Private<PublicType>,
{
if(_observingAtlas)
{
_observingAtlas->audienceForReposition -= this;
_observingAtlas->audienceForReposition() -= this;
}

/**
Expand All @@ -80,7 +80,7 @@ class GuiWidgetPrivate : public Private<PublicType>,
{
// Automatically start observing the root atlas.
_observingAtlas = &root().atlas();
_observingAtlas->audienceForReposition += this;
_observingAtlas->audienceForReposition() += this;
}
}

Expand Down
8 changes: 4 additions & 4 deletions doomsday/libappfw/src/basewindow.cpp
Expand Up @@ -37,14 +37,14 @@ DENG2_PIMPL(BaseWindow)
, xf(&defaultXf)
{
// Listen to input.
self.canvas().audienceForKeyEvent += this;
self.canvas().audienceForMouseEvent += this;
self.canvas().audienceForKeyEvent() += this;
self.canvas().audienceForMouseEvent() += this;
}

~Instance()
{
self.canvas().audienceForKeyEvent -= this;
self.canvas().audienceForMouseEvent -= this;
self.canvas().audienceForKeyEvent() -= this;
self.canvas().audienceForMouseEvent() -= this;
}

void keyEvent(KeyEvent const &ev)
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libappfw/src/widgets/documentwidget.cpp
Expand Up @@ -125,7 +125,7 @@ public Font::RichFormat::IStyle

void glInit()
{
atlas().audienceForReposition += this;
atlas().audienceForReposition() += this;

glText.init(atlas(), self.font(), this);

Expand All @@ -145,7 +145,7 @@ public Font::RichFormat::IStyle

void glDeinit()
{
atlas().audienceForReposition -= this;
atlas().audienceForReposition() -= this;
glText.deinit();
drawable.clear();
}
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libappfw/src/widgets/logwidget.cpp
Expand Up @@ -463,8 +463,8 @@ public Font::RichFormat::IStyle
Atlas::BackingStore | Atlas::AllowDefragment,
GLTexture::maximumSize().min(Atlas::Size(4096, 2048)));

entryAtlas->audienceForReposition += this;
entryAtlas->audienceForOutOfSpace += this;
entryAtlas->audienceForReposition() += this;
entryAtlas->audienceForOutOfSpace() += this;

// Simple texture for the scroll indicator.
Image solidWhitePixel = Image::solidColor(Image::Color(255, 255, 255, 255),
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libdeng2/include/de/data/observers.h
Expand Up @@ -141,7 +141,7 @@
DENG2_FOR_EACH_OBSERVER(Name##Audience, Var, self.audienceFor##Name)

#define DENG2_FOR_PUBLIC_AUDIENCE2(Name, Var) \
DENG2_FOR_EACH_OBSERVER(Name##Audience, Var, audienceFor##Name)
DENG2_FOR_EACH_OBSERVER(Name##Audience, Var, self.audienceFor##Name())

namespace de {

Expand Down
4 changes: 2 additions & 2 deletions doomsday/libgui/include/de/gui/atlas.h
Expand Up @@ -109,13 +109,13 @@ class LIBGUI_PUBLIC Atlas : public Lockable
* repositioned for some reasons (e.g., defragmentation). Normally once
* allocated, content will remain at its initial place.
*/
DENG2_DEFINE_AUDIENCE(Reposition, void atlasContentRepositioned(Atlas &))
DENG2_DEFINE_AUDIENCE2(Reposition, void atlasContentRepositioned(Atlas &))

/**
* Audience that will be notified when an allocation fails due to the atlas
* being so full that there is no room for the new image.
*/
DENG2_DEFINE_AUDIENCE(OutOfSpace, void atlasOutOfSpace(Atlas &))
DENG2_DEFINE_AUDIENCE2(OutOfSpace, void atlasOutOfSpace(Atlas &))

public:
/**
Expand Down
10 changes: 5 additions & 5 deletions doomsday/libgui/include/de/gui/canvas.h
Expand Up @@ -57,29 +57,29 @@ class LIBGUI_PUBLIC Canvas : public QGLWidget, public KeyEventSource, public Mou
* screen. Note that the notification comes straight from the event loop
* (timer signal) instead of during a paint event.
*/
DENG2_DEFINE_AUDIENCE(GLReady, void canvasGLReady(Canvas &))
DENG2_DEFINE_AUDIENCE2(GLReady, void canvasGLReady(Canvas &))

/**
* Notified when the canvas's GL state needs to be initialized. This is
* called immediately before drawing the contents of the canvas for the
* first time (during a paint event).
*/
DENG2_DEFINE_AUDIENCE(GLInit, void canvasGLInit(Canvas &))
DENG2_DEFINE_AUDIENCE2(GLInit, void canvasGLInit(Canvas &))

/**
* Notified when a canvas's size has changed.
*/
DENG2_DEFINE_AUDIENCE(GLResize, void canvasGLResized(Canvas &))
DENG2_DEFINE_AUDIENCE2(GLResize, void canvasGLResized(Canvas &))

/**
* Notified when drawing of the canvas contents has been requested.
*/
DENG2_DEFINE_AUDIENCE(GLDraw, void canvasGLDraw(Canvas &))
DENG2_DEFINE_AUDIENCE2(GLDraw, void canvasGLDraw(Canvas &))

/**
* Notified when the canvas gains or loses input focus.
*/
DENG2_DEFINE_AUDIENCE(FocusChange, void canvasFocusChanged(Canvas &, bool hasFocus))
DENG2_DEFINE_AUDIENCE2(FocusChange, void canvasFocusChanged(Canvas &, bool hasFocus))

public:
explicit Canvas(CanvasWindow *parent, QGLWidget* shared = 0);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libgui/include/de/gui/gluniform.h
Expand Up @@ -67,12 +67,12 @@ class LIBGUI_PUBLIC GLUniform
/**
* Notified when the value of the uniform changes.
*/
DENG2_DEFINE_AUDIENCE(ValueChange, void uniformValueChanged(GLUniform &))
DENG2_DEFINE_AUDIENCE2(ValueChange, void uniformValueChanged(GLUniform &))

/**
* Notified when the uniform instance is deleted.
*/
DENG2_DEFINE_AUDIENCE(Deletion, void uniformDeleted(GLUniform &))
DENG2_DEFINE_AUDIENCE2(Deletion, void uniformDeleted(GLUniform &))

public:
GLUniform(char const *nameInShader, Type uniformType);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libgui/include/de/gui/guiapp.h
Expand Up @@ -48,7 +48,7 @@ class LIBGUI_PUBLIC GuiApp : public QApplication, public App,
/**
* Notified when a Canvas is recreated.
*/
DENG2_DEFINE_AUDIENCE(GLContextChange, void appGLContextChanged())
DENG2_DEFINE_AUDIENCE2(GLContextChange, void appGLContextChanged())

public:
GuiApp(int &argc, char **argv);
Expand Down
6 changes: 5 additions & 1 deletion doomsday/libgui/include/de/gui/keyeventsource.h
Expand Up @@ -32,10 +32,14 @@ namespace de {
class LIBGUI_PUBLIC KeyEventSource
{
public:
DENG2_DEFINE_AUDIENCE(KeyEvent, void keyEvent(KeyEvent const &))
DENG2_DEFINE_AUDIENCE2(KeyEvent, void keyEvent(KeyEvent const &))

public:
KeyEventSource();
virtual ~KeyEventSource() {}

private:
DENG2_PRIVATE(d)
};

} // namespace de
Expand Down
9 changes: 6 additions & 3 deletions doomsday/libgui/include/de/gui/mouseeventsource.h
Expand Up @@ -38,12 +38,15 @@ class LIBGUI_PUBLIC MouseEventSource
Trapped
};

DENG2_DEFINE_AUDIENCE(MouseStateChange, void mouseStateChanged(State))

DENG2_DEFINE_AUDIENCE(MouseEvent, void mouseEvent(MouseEvent const &))
DENG2_DEFINE_AUDIENCE2(MouseStateChange, void mouseStateChanged(State))
DENG2_DEFINE_AUDIENCE2(MouseEvent, void mouseEvent(MouseEvent const &))

public:
MouseEventSource();
virtual ~MouseEventSource() {}

private:
DENG2_PRIVATE(d)
};

} // namespace de
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libgui/include/de/gui/persistentcanvaswindow.h
Expand Up @@ -78,7 +78,7 @@ class LIBGUI_PUBLIC PersistentCanvasWindow : public CanvasWindow
* changes are queued, the notification is made only after all the changes
* have been applied.
*/
DENG2_DEFINE_AUDIENCE(AttributeChange, void windowAttributesChanged(PersistentCanvasWindow &))
DENG2_DEFINE_AUDIENCE2(AttributeChange, void windowAttributesChanged(PersistentCanvasWindow &))

public:
/**
Expand Down
2 changes: 2 additions & 0 deletions doomsday/libgui/libgui.pro
Expand Up @@ -150,7 +150,9 @@ SOURCES += \
src/imagebank.cpp \
src/kdtreeatlasallocator.cpp \
src/keyevent.cpp \
src/keyeventsource.cpp \
src/mouseevent.cpp \
src/mouseeventsource.cpp \
src/nativefont.cpp \
src/qtnativefont.h \
src/persistentcanvaswindow.cpp \
Expand Down
10 changes: 8 additions & 2 deletions doomsday/libgui/src/atlas.cpp
Expand Up @@ -139,13 +139,19 @@ DENG2_PIMPL(Atlas)
markFullyChanged();
mayDefrag = false;

DENG2_FOR_PUBLIC_AUDIENCE(Reposition, i)
DENG2_FOR_PUBLIC_AUDIENCE2(Reposition, i)
{
i->atlasContentRepositioned(self);
}
}

DENG2_PIMPL_AUDIENCE(Reposition)
DENG2_PIMPL_AUDIENCE(OutOfSpace)
};

DENG2_AUDIENCE_METHOD(Atlas, Reposition)
DENG2_AUDIENCE_METHOD(Atlas, OutOfSpace)

Atlas::Atlas(Flags const &flags, Size const &totalSize)
: d(new Instance(this, flags, totalSize))
{}
Expand Down Expand Up @@ -252,7 +258,7 @@ Id Atlas::alloc(Image const &image)
{
LOG_GL_XVERBOSE("Atlas is full with %.1f%% usage") << d->usedPercentage()*100;

DENG2_FOR_AUDIENCE(OutOfSpace, i)
DENG2_FOR_AUDIENCE2(OutOfSpace, i)
{
i->atlasOutOfSpace(*this);
}
Expand Down

0 comments on commit c72e342

Please sign in to comment.