Skip to content

Commit

Permalink
Refactor: Moved IdTech1Image to libdoomsday
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent fc616ec commit 1f46e3c
Show file tree
Hide file tree
Showing 16 changed files with 256 additions and 248 deletions.
30 changes: 30 additions & 0 deletions doomsday/apps/client/include/ui/clientstyle.h
Expand Up @@ -19,12 +19,27 @@
#ifndef DENG_CLIENT_UI_CLIENTSTYLE_H
#define DENG_CLIENT_UI_CLIENTSTYLE_H

#include <de/Image>
#include <de/Style>
#include <de/GuiWidget>
#include <de/ui/Stylist>
#include <doomsday/Game>
#include <doomsday/LumpCatalog>

class ClientStyle : public de::Style
{
public:
enum LogoFlag
{
UnmodifiedAppearance = 0,
ColorizedByFamily = 0x1,
Downscale50Percent = 0x2,
NullImageIfFails = 0x4, // by default returns a small fallback image

DefaultLogoFlags = ColorizedByFamily | Downscale50Percent,
};
Q_DECLARE_FLAGS(LogoFlags, LogoFlag)

public:
ClientStyle();

Expand All @@ -33,8 +48,23 @@ class ClientStyle : public de::Style

void performUpdate() override;

/**
* Prepares a game logo image to be used in items. The image is based on the
* game's title screen image in its WAD file(s).
*
* @param game Game.
* @param catalog Catalog of selected lumps.
*
* @return Lgoo image.
*/
static de::Image makeGameLogo(Game const & game,
res::LumpCatalog const &catalog,
LogoFlags flags = DefaultLogoFlags);

private:
DENG2_PRIVATE(d)
};

Q_DECLARE_OPERATORS_FOR_FLAGS(ClientStyle::LogoFlags)

#endif // DENG_CLIENT_UI_CLIENTSTYLE_H
127 changes: 0 additions & 127 deletions doomsday/apps/client/src/resource/idtech1image.cpp

This file was deleted.

6 changes: 3 additions & 3 deletions doomsday/apps/client/src/resource/image.cpp
Expand Up @@ -570,7 +570,7 @@ static Block loadAndTranslatePatch(IByteArray const &data, colorpaletteid_t palI
}
else
{
return res::Patch::load(data, res::Patch::ClipToLogicalDimensions);
return res::Patch::load(data, nullptr, res::Patch::ClipToLogicalDimensions);
}
}

Expand Down Expand Up @@ -653,8 +653,8 @@ static Source loadPatchComposite(image_t &image, Texture const &tex,
Patch::Flags loadFlags;
if (maskZero) loadFlags |= Patch::MaskZero;

Block patchImg = Patch::load(fileData, loadFlags);
PatchMetadata info = Patch::loadMetadata(fileData);
PatchMetadata info;
Block patchImg = Patch::load(fileData, &info, loadFlags);

Vec2i origin = i->origin();
if (useZeroOriginIfOneComponent && texDef.componentCount() == 1)
Expand Down
51 changes: 51 additions & 0 deletions doomsday/apps/client/src/ui/clientstyle.cpp
Expand Up @@ -19,6 +19,7 @@
#include "ui/clientstyle.h"
#include "ui/clientwindow.h"

#include <doomsday/res/IdTech1Image>
#include <de/Async>

using namespace de;
Expand Down Expand Up @@ -51,6 +52,56 @@ ui::Stylist &ClientStyle::emptyMenuLabelStylist() const
return d->emptyMenuLabelStylist;
}

Image ClientStyle::makeGameLogo(Game const &game, res::LumpCatalog const &catalog, LogoFlags flags)
{
try
{
if (game.isPlayableWithDefaultPackages())
{
Block const playPal = catalog.read("PLAYPAL");
Block const title = catalog.read("TITLE");
Block const titlePic = catalog.read("TITLEPIC");
Block const interPic = catalog.read("INTERPIC");

res::IdTech1Image img(title? title : (titlePic? titlePic : interPic), playPal);

int const sizeDiv = flags.testFlag(Downscale50Percent)? 2 : 1;
Image::Size const finalSize( img.pixelSize().x / sizeDiv,
int(img.pixelSize().y * 1.2f / sizeDiv)); // VGA aspect

Image logoImage(
Image::fromRgbaData(img.pixelSize(), img.pixels())
.toQImage()
.scaled(
finalSize.x, finalSize.y, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));

if (flags & ColorizedByFamily)
{
String const colorId = "home.icon." +
(game.family().isEmpty()? "other" : game.family());
return logoImage.colorized(Style::get().colors().color(colorId));
}
return logoImage;
}
}
catch (Error const &er)
{
if (flags & NullImageIfFails) return Image();

LOG_RES_WARNING("Failed to load title picture for game \"%s\": %s")
<< game.title()
<< er.asText();
}
if (flags & NullImageIfFails)
{
return Image();
}
// Use a generic logo, some files are missing.
QImage img(64, 64, QImage::Format_ARGB32);
img.fill(Qt::black);
return img;
}

void ClientStyle::performUpdate()
{
async([]() {
Expand Down
6 changes: 3 additions & 3 deletions doomsday/apps/client/src/ui/dialogs/packageinfodialog.cpp
Expand Up @@ -18,7 +18,7 @@

#include "ui/dialogs/packageinfodialog.h"
#include "ui/widgets/packagecontentoptionswidget.h"
#include "resource/idtech1image.h"
#include "ui/clientstyle.h"
#include "dd_main.h"

#include <doomsday/DataBundle>
Expand Down Expand Up @@ -178,8 +178,8 @@ DENG_GUI_PIMPL(PackageInfoDialog)

res::LumpCatalog catalog;
catalog.setPackages(game.requiredPackages() + StringList({packageId}));
Image img = IdTech1Image::makeGameLogo(
game, catalog, IdTech1Image::NullImageIfFails | IdTech1Image::UnmodifiedAppearance);
Image img = ClientStyle::makeGameLogo(
game, catalog, ClientStyle::NullImageIfFails | ClientStyle::UnmodifiedAppearance);
if (!img.isNull())
{
setPackageIcon(img);
Expand Down
8 changes: 3 additions & 5 deletions doomsday/apps/client/src/ui/dialogs/packagesdialog.cpp
Expand Up @@ -21,8 +21,6 @@
#include "ui/widgets/homeitemwidget.h"
#include "ui/widgets/homemenuwidget.h"
#include "ui/dialogs/packageinfodialog.h"
#include "ui/dialogs/datafilesettingsdialog.h"
#include "resource/idtech1image.h"
#include "ui/clientwindow.h"
#include "ui/clientstyle.h"
#include "clientapp.h"
Expand Down Expand Up @@ -301,9 +299,9 @@ DENG_GUI_PIMPL(PackagesDialog)
{
if (gameProfile && catalog.setPackages(gameProfile->allRequiredPackages() + selectedPackages))
{
gameTitle->setImage(IdTech1Image::makeGameLogo(gameProfile->game(), catalog,
IdTech1Image::UnmodifiedAppearance |
IdTech1Image::AlwaysTryLoad));
gameTitle->setImage(ClientStyle::makeGameLogo(gameProfile->game(), catalog,
ClientStyle::UnmodifiedAppearance |
ClientStyle::AlwaysTryLoad));
// List of the native required files.
StringList dataFiles;
// if (gameProfile->customDataFile())
Expand Down
8 changes: 4 additions & 4 deletions doomsday/apps/client/src/ui/home/gamepanelbuttonwidget.cpp
Expand Up @@ -17,13 +17,13 @@
*/

#include "ui/home/gamepanelbuttonwidget.h"
#include "ui/widgets/homemenuwidget.h"
#include "ui/clientstyle.h"
#include "ui/dialogs/packagesdialog.h"
#include "ui/home/savelistwidget.h"
#include "ui/home/gamecolumnwidget.h"
#include "ui/savelistdata.h"
#include "ui/dialogs/packagesdialog.h"
#include "ui/widgets/homemenuwidget.h"
#include "ui/widgets/packagesbuttonwidget.h"
#include "resource/idtech1image.h"
#include "dd_main.h"

#include <doomsday/console/exec.h>
Expand Down Expand Up @@ -264,7 +264,7 @@ DENG_GUI_PIMPL(GamePanelButtonWidget)

void updateGameTitleImage()
{
*this += async([this]() { return IdTech1Image::makeGameLogo(game(), catalog); },
*this += async([this]() { return ClientStyle::makeGameLogo(game(), catalog); },
[this](const Image &gameLogo) { self().icon().setImage(gameLogo); });
}

Expand Down
Expand Up @@ -18,10 +18,10 @@

#include "ui/home/multiplayerpanelbuttonwidget.h"
#include "ui/dialogs/serverinfodialog.h"
#include "ui/clientstyle.h"
#include "ui/clientwindow.h"
#include "network/net_main.h"
#include "network/serverlink.h"
#include "resource/idtech1image.h"
#include "clientapp.h"
#include "dd_main.h"

Expand Down Expand Up @@ -185,7 +185,7 @@ void MultiplayerPanelButtonWidget::updateContent(shell::ServerInfo const &info)
if (d->catalog.setPackages(game.requiredPackages()))
{
res::LumpCatalog catalog{d->catalog};
*d += async([&game, catalog]() { return IdTech1Image::makeGameLogo(game, catalog); },
*d += async([&game, catalog]() { return ClientStyle::makeGameLogo(game, catalog); },
[this](const Image &logo) { icon().setImage(logo); });
}
}
Expand Down
1 change: 0 additions & 1 deletion doomsday/apps/client/src/ui/widgets/homeitemwidget.cpp
Expand Up @@ -19,7 +19,6 @@
#include "ui/widgets/homeitemwidget.h"
#include "ui/widgets/homemenuwidget.h"
#include "ui/home/columnwidget.h"
#include "resource/idtech1image.h"

#include <doomsday/LumpCatalog>
#include <doomsday/Game>
Expand Down
@@ -0,0 +1 @@
#include "../resource/idtech1image.h"

0 comments on commit 1f46e3c

Please sign in to comment.