CCTTFLabelRenderer.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /****************************************************************************
  2. Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
  3. http://www.cocos.com
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #pragma once
  21. #include "base/ccMacros.h"
  22. #include "2d/CCTTFTypes.h"
  23. #include "base/ccConfig.h"
  24. #include <memory>
  25. #if CC_ENABLE_TTF_LABEL_RENDERER
  26. namespace se {
  27. class Object;
  28. }
  29. namespace cocos2d {
  30. namespace renderer {
  31. class Texture2D;
  32. class Effect;
  33. class EffectVariant;
  34. class NodeProxy;
  35. }
  36. class LabelLayout;
  37. class LabelRenderer : public cocos2d::Ref {
  38. private:
  39. enum UpdateFlags {
  40. UPDATE_CONTENT = 1 << 0,
  41. UPDATE_FONT = 1 << 1,
  42. UPDATE_EFFECT = 1 << 2
  43. };
  44. public:
  45. struct LabelRendererConfig {
  46. uint32_t updateFlags = 0xFFFFFFFF;
  47. float fontSize = 20.0f;
  48. float fontSizeRetina = 0.0f;
  49. };
  50. LabelRenderer();
  51. virtual ~LabelRenderer();
  52. void bindNodeProxy(cocos2d::renderer::NodeProxy* node);
  53. void setEffect(cocos2d::renderer::EffectVariant* effect);
  54. void render();
  55. void bindSharedBlock(se::Object *selfObj, void *cfg, void *layout);
  56. private:
  57. void genStringLayout();
  58. void renderIfChange();
  59. void doRender();
  60. std::string getString();
  61. std::string getFontPath();
  62. std::unique_ptr<LabelLayout> _stringLayout;
  63. se::Object *_selfObj = nullptr;
  64. //export arraybuffer to js
  65. LabelRendererConfig *_cfg = nullptr;
  66. LabelLayoutInfo *_layoutInfo = nullptr;
  67. cocos2d::renderer::NodeProxy* _nodeProxy = nullptr;
  68. cocos2d::renderer::EffectVariant * _effect = nullptr;
  69. };
  70. }
  71. #endif