| 1 | // Aseprite |
| 2 | // Copyright (C) 2001-2018 David Capello |
| 3 | // |
| 4 | // This program is distributed under the terms of |
| 5 | // the End-User License Agreement for Aseprite. |
| 6 | |
| 7 | #ifndef APP_UI_RESOURCES_LISTBOX_H_INCLUDED |
| 8 | #define APP_UI_RESOURCES_LISTBOX_H_INCLUDED |
| 9 | #pragma once |
| 10 | |
| 11 | #include "app/res/resources_loader.h" |
| 12 | #include "obs/signal.h" |
| 13 | #include "ui/listbox.h" |
| 14 | #include "ui/listitem.h" |
| 15 | #include "ui/timer.h" |
| 16 | |
| 17 | #include <memory> |
| 18 | |
| 19 | namespace app { |
| 20 | class ResourceListItem; |
| 21 | |
| 22 | class ResourceListItem : public ui::ListItem { |
| 23 | public: |
| 24 | ResourceListItem(Resource* resource); |
| 25 | |
| 26 | Resource* resource() const { return m_resource.get(); } |
| 27 | |
| 28 | protected: |
| 29 | bool onProcessMessage(ui::Message* msg) override; |
| 30 | void onPaint(ui::PaintEvent& ev) override; |
| 31 | void onSizeHint(ui::SizeHintEvent& ev) override; |
| 32 | |
| 33 | private: |
| 34 | std::unique_ptr<Resource> m_resource; |
| 35 | }; |
| 36 | |
| 37 | class ResourcesListBox : public ui::ListBox { |
| 38 | public: |
| 39 | friend class ResourceListItem; |
| 40 | |
| 41 | ResourcesListBox(ResourcesLoader* resourcesLoader); |
| 42 | |
| 43 | Resource* selectedResource(); |
| 44 | |
| 45 | void reload(); |
| 46 | |
| 47 | obs::signal<void()> FinishLoading; |
| 48 | |
| 49 | protected: |
| 50 | virtual bool onProcessMessage(ui::Message* msg) override; |
| 51 | virtual void onChange() override; |
| 52 | virtual ResourceListItem* onCreateResourceItem(Resource* resource); |
| 53 | |
| 54 | // abstract |
| 55 | virtual void onResourceChange(Resource* resource) = 0; |
| 56 | virtual void onPaintResource(ui::Graphics* g, gfx::Rect& bounds, Resource* resource) = 0; |
| 57 | virtual void onResourceSizeHint(Resource* resource, gfx::Size& size) = 0; |
| 58 | |
| 59 | private: |
| 60 | void paintResource(ui::Graphics* g, gfx::Rect& bounds, Resource* resource); |
| 61 | gfx::Size resourceSizeHint(Resource* resource); |
| 62 | |
| 63 | void onTick(); |
| 64 | void stop(); |
| 65 | |
| 66 | std::unique_ptr<ResourcesLoader> m_resourcesLoader; |
| 67 | ui::Timer m_resourcesTimer; |
| 68 | bool m_reload; |
| 69 | |
| 70 | class LoadingItem; |
| 71 | LoadingItem* m_loadingItem; |
| 72 | }; |
| 73 | |
| 74 | } // namespace app |
| 75 | |
| 76 | #endif |
| 77 | |