QGearsPaletteFile.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include <OgreColourValue.h>
  17. #include <OgreResource.h>
  18. #include "common/TypeDefine.h"
  19. namespace QGears{
  20. /**
  21. * Handles colour palette files.
  22. */
  23. class PaletteFile : public Ogre::Resource{
  24. public:
  25. /**
  26. * Constructor.
  27. *
  28. * @param creator[in] Pointer to the ResourceManager that is
  29. * creating this resource.
  30. * @param name[in] The unique name of the resource.
  31. * @param handle[in] @todo Understand and document.
  32. * @param group[in] The name of the resource group to which this
  33. * resource belong.
  34. * @param is_manual[in] True if the resource is manually loaded,
  35. * false otherwise.
  36. * @param loader[in] Pointer to a ManualResourceLoader
  37. * implementation which will be called when the Resource wishes to
  38. * load (should be supplied if is_manual is set to true). It can be
  39. * null, but the Resource will never be able to reload if anything
  40. * ever causes it to unload. Therefore provision of a proper
  41. * ManualResourceLoader instance is strongly recommended.
  42. */
  43. PaletteFile(
  44. Ogre::ResourceManager* creator, const String &name,
  45. Ogre::ResourceHandle handle, const String& group,
  46. bool is_manual = false,
  47. Ogre::ManualResourceLoader* loader = nullptr
  48. );
  49. /**
  50. * Destructor.
  51. */
  52. virtual ~PaletteFile();
  53. /**
  54. * The type of resource.
  55. */
  56. static const String RESOURCE_TYPE;
  57. typedef Ogre::ColourValue Color;
  58. typedef std::vector<Color> Page;
  59. typedef std::vector<Page> PageList;
  60. /**
  61. * Retrieevs the list of pages.
  62. *
  63. * @return The list of pages.
  64. */
  65. virtual PageList& GetPages(){return pages_;}
  66. /**
  67. * Retrieves a page.
  68. *
  69. * @param index[in] Page index.
  70. * @return The page at the specified index.
  71. */
  72. virtual const Page& GetPage(size_t index) const{
  73. return pages_.at(index);
  74. }
  75. protected:
  76. /**
  77. * Loads the file.
  78. */
  79. virtual void loadImpl() override;
  80. /**
  81. * Unloads the file.
  82. */
  83. virtual void unloadImpl() override;
  84. /**
  85. * Calculates the size of the palette.
  86. *
  87. * @return The size of the palette.
  88. * @todo Units?
  89. */
  90. virtual size_t calculateSize() const override;
  91. private:
  92. /**
  93. * The list of palette pages.
  94. */
  95. PageList pages_;
  96. };
  97. typedef Ogre::SharedPtr<PaletteFile> PaletteFilePtr;
  98. }