Skip to content

Commit

Permalink
Client|ClientWindow: FPS counter as a notification
Browse files Browse the repository at this point in the history
This commit brings back the FPS counter as a notification widget owned
by ClientWindow. When "Show FPS" is selected in the DE menu, the
window sets Config.window.main.showFps to True and the FPS counter
widget is shown in the main window's notification area.

The counter notification is dismissed by selecting "Hide FPS" in the
DE menu.
  • Loading branch information
skyjake committed Jul 9, 2013
1 parent a334512 commit 95e7ac3
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 8 deletions.
8 changes: 8 additions & 0 deletions doomsday/client/include/ui/clientwindow.h
Expand Up @@ -40,6 +40,7 @@

class ConsoleWidget;
class TaskBarWidget;
class NotificationWidget;

/**
* Top-level window that contains a libdeng2 UI widgets. @ingroup gui
Expand All @@ -63,6 +64,7 @@ class ClientWindow : public de::PersistentCanvasWindow,
GuiRootWidget &root();
TaskBarWidget &taskBar();
ConsoleWidget &console();
NotificationWidget &notifications();

/**
* Sets the operating mode of the window. In Busy mode, the normal
Expand Down Expand Up @@ -104,6 +106,9 @@ class ClientWindow : public de::PersistentCanvasWindow,

void updateCanvasFormat();

// Notifications.
bool isFPSCounterVisible() const;

// Events.
void closeEvent(QCloseEvent *);
void canvasGLReady(de::Canvas &);
Expand All @@ -113,6 +118,9 @@ class ClientWindow : public de::PersistentCanvasWindow,

static ClientWindow &main();

public slots:
void toggleFPSCounter();

private:
DENG2_PRIVATE(d)
};
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/include/ui/widgets/taskbarwidget.h
Expand Up @@ -50,13 +50,15 @@ class TaskBarWidget : public GuiWidget

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

public slots:
void open(bool doAction = true);
void close();
void openMainMenu();
void toggleFPS();

signals:
void opened();
Expand Down
42 changes: 40 additions & 2 deletions doomsday/client/src/ui/clientwindow.cpp
Expand Up @@ -72,6 +72,10 @@ public IGameChangeObserver

GuiRootWidget busyRoot;

// FPS notifications.
LabelWidget *fpsCounter;
float oldFps;

Instance(Public *i)
: Base(i),
needMainInit(true),
Expand All @@ -83,7 +87,9 @@ public IGameChangeObserver
notifications(0),
background(0),
games(0),
busyRoot(thisPublic)
busyRoot(thisPublic),
fpsCounter(0),
oldFps(0)
{
/// @todo The decision whether to receive input notifications from the
/// canvas is really a concern for the input drivers.
Expand Down Expand Up @@ -140,10 +146,15 @@ public IGameChangeObserver
// Common notification area.
notifications = new NotificationWidget;
notifications->rule()
.setInput(Rule::Top, root.viewTop() + style.rules().rule("gap"))
.setInput(Rule::Top, root.viewTop() + style.rules().rule("gap") - notifications->shift())
.setInput(Rule::Right, root.viewRight() - style.rules().rule("gap"));
root.add(notifications);

// FPS counter for the notification area.
fpsCounter = new LabelWidget;
fpsCounter->setSizePolicy(ui::Expand, ui::Expand);
fpsCounter->setAlignment(ui::AlignRight);

// Taskbar is over almost everything else.
taskBar = new TaskBarWidget;
taskBar->rule()
Expand Down Expand Up @@ -307,6 +318,17 @@ public IGameChangeObserver
ev.focus.inWindow = 1; /// @todo Ask WindowSystem for an identifier number.
DD_PostEvent(&ev);
}

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

if(!fequal(oldFps, fps))
{
fpsCounter->setText(QString("%1 "_E(l)"FPS").arg(fps, 0, 'f', 1));
oldFps = fps;
}
}
};

ClientWindow::ClientWindow(String const &id)
Expand Down Expand Up @@ -340,6 +362,16 @@ ConsoleWidget &ClientWindow::console()
return d->taskBar->console();
}

NotificationWidget &ClientWindow::notifications()
{
return *d->notifications;
}

bool ClientWindow::isFPSCounterVisible() const
{
return d->notifications->isChildShown(*d->fpsCounter);
}

void ClientWindow::setMode(Mode const &mode)
{
LOG_AS("ClientWindow");
Expand Down Expand Up @@ -403,6 +435,7 @@ void ClientWindow::canvasGLDraw(Canvas &canvas)
ClientApp::app().postFrame(); /// @todo what about multiwindow?

PersistentCanvasWindow::canvasGLDraw(canvas);
d->updateFpsNotification(frameRate());
}

void ClientWindow::canvasGLResized(Canvas &canvas)
Expand Down Expand Up @@ -549,3 +582,8 @@ void GL_AssertContextActive()
DENG_ASSERT(QGLContext::currentContext() != 0);
}
#endif

void ClientWindow::toggleFPSCounter()
{
App::config().set(configName("showFps"), !isFPSCounterVisible());
}
7 changes: 5 additions & 2 deletions doomsday/client/src/ui/widgets/labelwidget.cpp
Expand Up @@ -410,8 +410,11 @@ LabelWidget::LabelWidget(String const &name) : GuiWidget(name), d(new Instance(t

void LabelWidget::setText(String const &text)
{
d->styledText = text;
d->wrapWidth = 0; // force rewrap
if(text != d->styledText)
{
d->styledText = text;
d->wrapWidth = 0; // force rewrap
}
}

void LabelWidget::setImage(Image const &image)
Expand Down
21 changes: 20 additions & 1 deletion doomsday/client/src/ui/widgets/taskbarwidget.cpp
Expand Up @@ -51,6 +51,7 @@ public IGameChangeObserver
LabelWidget *status;
PopupMenuWidget *mainMenu;
ButtonWidget *panelItem;
ButtonWidget *fpsItem;
ButtonWidget *unloadItem;
ScalarRule *vertShift;

Expand Down Expand Up @@ -150,6 +151,11 @@ public IGameChangeObserver
status->setText("No game loaded");
}
}

void updateFpsMenuItem()
{
fpsItem->setText(ClientWindow::main().isFPSCounterVisible()? "Hide FPS" : "Show FPS");
}
};

TaskBarWidget::TaskBarWidget() : GuiWidget("taskbar"), d(new Instance(this))
Expand Down Expand Up @@ -231,7 +237,8 @@ TaskBarWidget::TaskBarWidget() : GuiWidget("taskbar"), d(new Instance(this))
d->mainMenu = new PopupMenuWidget("de-menu");
d->mainMenu->setAnchor(d->logo->rule().left() + d->logo->rule().width() / 2,
d->logo->rule().top());
d->panelItem = d->mainMenu->addItem(_E(b) "Open Control Panel", new CommandAction("panel"));
d->fpsItem = d->mainMenu->addItem("", new SignalAction(this, SLOT(toggleFPS())));
d->panelItem = d->mainMenu->addItem(_E(b) "Open Control Panel", new CommandAction("panel"));
d->mainMenu->addItem("Check for updates...", new CommandAction("updateandnotify"));
d->unloadItem = d->mainMenu->addItem("Unload game", new CommandAction("unload"));
d->mainMenu->addItem("Quit Doomsday", new CommandAction("quit"));
Expand Down Expand Up @@ -294,6 +301,13 @@ void TaskBarWidget::viewResized()
d->updateProjection();
}

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

d->updateFpsMenuItem();
}

void TaskBarWidget::drawContent()
{
d->updateGeometry();
Expand Down Expand Up @@ -462,3 +476,8 @@ void TaskBarWidget::openMainMenu()
{
d->mainMenu->open();
}

void TaskBarWidget::toggleFPS()
{
ClientWindow::main().toggleFPSCounter();
}
8 changes: 5 additions & 3 deletions doomsday/libdeng2/modules/Config.de
Expand Up @@ -50,10 +50,12 @@ def setDefaults(d = None)
d.window.fsaa = True # Remove this (should be window-specific).

# Configure the main window.
# TODO: The client should have its own config script for setting these
record d.window.main
d.window.main.center = True
d.window.main.fsaa = True
d.window.main.vsync = True
d.window.main.showFps = False
d.window.main.center = True
d.window.main.fsaa = True
d.window.main.vsync = True

try
# The default window parameters depend on the original display mode.
Expand Down

0 comments on commit 95e7ac3

Please sign in to comment.