BsScriptFontBitmap.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsScriptEnginePrerequisites.h"
  5. #include "BsScriptResource.h"
  6. #include "BsScriptObject.h"
  7. #include "BsFont.h"
  8. namespace bs
  9. {
  10. /** @addtogroup ScriptInteropEngine
  11. * @{
  12. */
  13. /** Describes a single character in a font of a specific size. */
  14. struct ScriptCharDesc // Note: Must match C# struct CharDesc
  15. {
  16. UINT32 charId; /**< Character ID, corresponding to a Unicode key. */
  17. UINT32 page; /**< Index of the texture the character is located on. */
  18. float uvX, uvY; /**< Texture coordinates of the character in the page texture. */
  19. float uvWidth, uvHeight; /**< Width/height of the character in texture coordinates. */
  20. UINT32 width, height; /**< Width/height of the character in pixels. */
  21. INT32 xOffset, yOffset; /**< Offset for the visible portion of the character in pixels. */
  22. INT32 xAdvance, yAdvance; /**< Determines how much to advance the pen after writing this character, in pixels. */
  23. };
  24. /** Interop class between C++ & CLR for FontBitmap. */
  25. class BS_SCR_BE_EXPORT ScriptFontBitmap : public ScriptObject<ScriptFontBitmap>
  26. {
  27. public:
  28. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "FontBitmap")
  29. /**
  30. * Creates a new managed instance of a font bitmap.
  31. *
  32. * @param[in] bitmap Native font bitmap to initialize the managed instance with.
  33. */
  34. static MonoObject* create(SPtr<const FontBitmap> bitmap);
  35. private:
  36. friend class ScriptResourceManager;
  37. ScriptFontBitmap(MonoObject* instance, SPtr<const FontBitmap> bitmap);
  38. /** Converts the native character description into a script character description. */
  39. static ScriptCharDesc convertCharDesc(const CHAR_DESC& desc);
  40. SPtr<const FontBitmap> mBitmap;
  41. /************************************************************************/
  42. /* CLR HOOKS */
  43. /************************************************************************/
  44. static UINT32 internal_GetSize(ScriptFontBitmap* instance);
  45. static INT32 internal_GetBaselineOffset(ScriptFontBitmap* instance);
  46. static UINT32 internal_GetLineHeight(ScriptFontBitmap* instance);
  47. static UINT32 internal_GetSpaceWidth(ScriptFontBitmap* instance);
  48. static void internal_GetMissingChar(ScriptFontBitmap* instance, ScriptCharDesc* output);
  49. static MonoArray* internal_GetPages(ScriptFontBitmap* instance);
  50. static void internal_GetChar(ScriptFontBitmap* instance, UINT32 id, ScriptCharDesc* output);
  51. static MonoArray* internal_GetKerning(ScriptFontBitmap* instance, UINT32 id);
  52. };
  53. /** Interop class between C++ & CLR for KerningPair. */
  54. class BS_SCR_BE_EXPORT ScriptKerningPair : public ScriptObject <ScriptKerningPair>
  55. {
  56. public:
  57. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "KerningPair")
  58. private:
  59. ScriptKerningPair(MonoObject* instance);
  60. };
  61. /** @} */
  62. }