You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://sam.zoy.org/projects/COPYING.WTFPL for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <cstring>
  14. #include <cstdio>
  15. #include "core.h"
  16. using namespace std;
  17. namespace lol
  18. {
  19. /*
  20. * Font implementation class
  21. */
  22. class FontData
  23. {
  24. friend class Font;
  25. private:
  26. char *name;
  27. TileSet *tileset;
  28. ivec2 size;
  29. };
  30. /*
  31. * Public Font class
  32. */
  33. Font::Font(char const *path)
  34. : data(new FontData())
  35. {
  36. data->name = (char *)malloc(7 + strlen(path) + 1);
  37. sprintf(data->name, "<font> %s", path);
  38. data->tileset = Tiler::Register(path, ivec2(0), ivec2(16));
  39. data->size = data->tileset->GetSize(0);
  40. m_drawgroup = DRAWGROUP_BEFORE;
  41. }
  42. Font::~Font()
  43. {
  44. Tiler::Deregister(data->tileset);
  45. free(data->name);
  46. delete data;
  47. }
  48. void Font::TickDraw(float seconds)
  49. {
  50. Entity::TickDraw(seconds);
  51. }
  52. char const *Font::GetName()
  53. {
  54. return data->name;
  55. }
  56. void Font::Print(vec3 pos, char const *str, vec2 scale)
  57. {
  58. Scene *scene = Scene::GetDefault();
  59. while (*str)
  60. {
  61. uint32_t ch = (uint8_t)*str++;
  62. if (ch != ' ')
  63. scene->AddTile(data->tileset, ch & 255, pos, 0, scale);
  64. pos.x += data->size.x * scale.x;
  65. }
  66. }
  67. ivec2 Font::GetSize() const
  68. {
  69. return data->size;
  70. }
  71. } /* namespace lol */