1 #pragma once 2 3 #include <memory> 4 5 #include "Common/GPU/thin3d.h" 6 #include "Common/UI/View.h" 7 #include "Common/File/Path.h" 8 9 enum ImageFileType { 10 PNG, 11 JPEG, 12 ZIM, 13 DETECT, 14 TYPE_UNKNOWN, 15 }; 16 17 class ManagedTexture { 18 public: ManagedTexture(Draw::DrawContext * draw)19 ManagedTexture(Draw::DrawContext *draw) : draw_(draw) { 20 } ~ManagedTexture()21 ~ManagedTexture() { 22 if (texture_) 23 texture_->Release(); 24 } 25 26 bool LoadFromFile(const std::string &filename, ImageFileType type = ImageFileType::DETECT, bool generateMips = false); 27 bool LoadFromFileData(const uint8_t *data, size_t dataSize, ImageFileType type, bool generateMips, const char *name); 28 Draw::Texture *GetTexture(); // For immediate use, don't store. Width()29 int Width() const { return texture_->Width(); } Height()30 int Height() const { return texture_->Height(); } 31 32 void DeviceLost(); 33 void DeviceRestored(Draw::DrawContext *draw); 34 35 private: 36 Draw::Texture *texture_ = nullptr; 37 Draw::DrawContext *draw_; 38 std::string filename_; // Textures that are loaded from files can reload themselves automatically. 39 bool generateMips_ = false; 40 bool loadPending_ = false; 41 }; 42 43 std::unique_ptr<ManagedTexture> CreateTextureFromFile(Draw::DrawContext *draw, const char *filename, ImageFileType fileType, bool generateMips); 44 std::unique_ptr<ManagedTexture> CreateTextureFromFileData(Draw::DrawContext *draw, const uint8_t *data, int size, ImageFileType fileType, bool generateMips, const char *name); 45 46 class GameIconView : public UI::InertView { 47 public: 48 GameIconView(const Path &gamePath, float scale, UI::LayoutParams *layoutParams = 0) InertView(layoutParams)49 : InertView(layoutParams), gamePath_(gamePath), scale_(scale) {} 50 51 void GetContentDimensions(const UIContext &dc, float &w, float &h) const override; 52 void Draw(UIContext &dc) override; DescribeText()53 std::string DescribeText() const override { return ""; } 54 55 private: 56 Path gamePath_; 57 float scale_ = 1.0f; 58 int textureWidth_ = 0; 59 int textureHeight_ = 0; 60 }; 61