Skip to content

Commit

Permalink
Client|TaskBarWidget: Cleanup, observe showFps change notification
Browse files Browse the repository at this point in the history
Rather than checking every frame whether the FPS counter is visible
or not, now the task bar only observes when the window's showFps
variable changes.
  • Loading branch information
skyjake committed Jul 9, 2013
1 parent 9d2b41d commit 16adb58
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
1 change: 0 additions & 1 deletion doomsday/client/include/ui/widgets/taskbarwidget.h
Expand Up @@ -50,7 +50,6 @@ class TaskBarWidget : public GuiWidget

// Events.
void viewResized();
void update();
void drawContent();
bool handleEvent(de::Event const &event);

Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/ui/clientwindow.cpp
Expand Up @@ -321,7 +321,7 @@ public IGameChangeObserver

void updateFpsNotification(float fps)
{
notifications->showOrHide(fpsCounter, App::config().getb(self.configName("showFps")));
notifications->showOrHide(fpsCounter, self.isFPSCounterVisible());

if(!fequal(oldFps, fps))
{
Expand Down Expand Up @@ -369,7 +369,7 @@ NotificationWidget &ClientWindow::notifications()

bool ClientWindow::isFPSCounterVisible() const
{
return d->notifications->isChildShown(*d->fpsCounter);
return App::config().getb(configName("showFps"));
}

void ClientWindow::setMode(Mode const &mode)
Expand Down
21 changes: 13 additions & 8 deletions doomsday/client/src/ui/widgets/taskbarwidget.cpp
Expand Up @@ -29,6 +29,7 @@

#include "ui/ui_main.h"

#include <de/App>
#include <de/KeyEvent>
#include <de/Drawable>
#include <de/GLBuffer>
Expand All @@ -41,6 +42,7 @@ using namespace de;
using namespace ui;

DENG2_PIMPL(TaskBarWidget),
DENG2_OBSERVES(Variable, Change),
public IGameChangeObserver
{
typedef DefaultVertexBuf VertexBuf;
Expand Down Expand Up @@ -152,6 +154,12 @@ public IGameChangeObserver
}
}

void variableValueChanged(Variable &, Value const &val)
{
// We are observing the value of the window's showFps variable.
updateFpsMenuItem();
}

void updateFpsMenuItem()
{
fpsItem->setText(ClientWindow::main().isFPSCounterVisible()? "Hide FPS" : "Show FPS");
Expand Down Expand Up @@ -246,6 +254,10 @@ TaskBarWidget::TaskBarWidget() : GuiWidget("taskbar"), d(new Instance(this))

d->panelItem->hide();
d->unloadItem->hide();
d->updateFpsMenuItem();

// Observe when the showFps variable changes.
App::config()["window.main.showFps"].audienceForChange += d;

d->logo->setAction(new SignalAction(this, SLOT(openMainMenu())));
}
Expand Down Expand Up @@ -301,13 +313,6 @@ void TaskBarWidget::viewResized()
d->updateProjection();
}

void TaskBarWidget::update()
{
GuiWidget::update();

d->updateFpsMenuItem();
}

void TaskBarWidget::drawContent()
{
d->updateGeometry();
Expand Down Expand Up @@ -479,5 +484,5 @@ void TaskBarWidget::openMainMenu()

void TaskBarWidget::toggleFPS()
{
ClientWindow::main().toggleFPSCounter();
root().window().toggleFPSCounter();
}

0 comments on commit 16adb58

Please sign in to comment.