2016-12-27 21:26:49 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-05-18 10:52:03 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2016-12-27 21:26:49 +00:00
|
|
|
#include "thin3d/thin3d.h"
|
2019-10-11 15:34:38 +00:00
|
|
|
#include "ui/view.h"
|
2016-12-27 21:26:49 +00:00
|
|
|
|
|
|
|
enum ImageFileType {
|
|
|
|
PNG,
|
|
|
|
JPEG,
|
|
|
|
ZIM,
|
|
|
|
DETECT,
|
|
|
|
TYPE_UNKNOWN,
|
|
|
|
};
|
|
|
|
|
2017-12-07 13:56:19 +00:00
|
|
|
class ManagedTexture {
|
2016-12-27 21:26:49 +00:00
|
|
|
public:
|
2017-04-02 21:58:27 +00:00
|
|
|
ManagedTexture(Draw::DrawContext *draw) : draw_(draw) {
|
2016-12-27 21:26:49 +00:00
|
|
|
}
|
|
|
|
~ManagedTexture() {
|
2017-05-18 11:17:10 +00:00
|
|
|
if (texture_)
|
|
|
|
texture_->Release();
|
2016-12-27 21:26:49 +00:00
|
|
|
}
|
|
|
|
|
2017-03-11 13:43:42 +00:00
|
|
|
bool LoadFromFile(const std::string &filename, ImageFileType type = ImageFileType::DETECT, bool generateMips = false);
|
|
|
|
bool LoadFromFileData(const uint8_t *data, size_t dataSize, ImageFileType type = ImageFileType::DETECT, bool generateMips = false);
|
2018-03-27 21:10:33 +00:00
|
|
|
Draw::Texture *GetTexture(); // For immediate use, don't store.
|
2016-12-27 21:26:49 +00:00
|
|
|
int Width() const { return texture_->Width(); }
|
|
|
|
int Height() const { return texture_->Height(); }
|
|
|
|
|
2018-03-27 21:10:33 +00:00
|
|
|
void DeviceLost();
|
|
|
|
void DeviceRestored(Draw::DrawContext *draw);
|
|
|
|
|
2016-12-27 21:26:49 +00:00
|
|
|
private:
|
2017-04-02 21:58:27 +00:00
|
|
|
Draw::Texture *texture_ = nullptr;
|
2016-12-27 21:26:49 +00:00
|
|
|
Draw::DrawContext *draw_;
|
|
|
|
std::string filename_; // Textures that are loaded from files can reload themselves automatically.
|
2018-03-27 21:10:33 +00:00
|
|
|
bool generateMips_ = false;
|
|
|
|
bool loadPending_ = false;
|
2016-12-27 21:26:49 +00:00
|
|
|
};
|
|
|
|
|
2017-05-18 10:52:03 +00:00
|
|
|
std::unique_ptr<ManagedTexture> CreateTextureFromFile(Draw::DrawContext *draw, const char *filename, ImageFileType fileType, bool generateMips = false);
|
2019-10-11 15:34:38 +00:00
|
|
|
std::unique_ptr<ManagedTexture> CreateTextureFromFileData(Draw::DrawContext *draw, const uint8_t *data, int size, ImageFileType fileType, bool generateMips = false);
|
|
|
|
|
|
|
|
class GameIconView : public UI::InertView {
|
|
|
|
public:
|
|
|
|
GameIconView(std::string gamePath, UI::LayoutParams *layoutParams = 0)
|
|
|
|
: InertView(layoutParams), gamePath_(gamePath) {}
|
|
|
|
|
|
|
|
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override;
|
|
|
|
void Draw(UIContext &dc) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string gamePath_;
|
|
|
|
int textureWidth_ = 0;
|
|
|
|
int textureHeight_ = 0;
|
|
|
|
};
|