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.

пре 12 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
пре 14 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2013 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://www.wtfpl.net/ 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. String m_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->m_name = String("<font> ") + path;
  37. data->tileset = Tiler::Register(path, ivec2(0), ivec2(16));
  38. data->size = data->tileset->GetTileSize(0);
  39. m_drawgroup = DRAWGROUP_BEFORE;
  40. }
  41. Font::~Font()
  42. {
  43. Tiler::Deregister(data->tileset);
  44. delete data;
  45. }
  46. void Font::TickDraw(float seconds)
  47. {
  48. Entity::TickDraw(seconds);
  49. }
  50. char const *Font::GetName()
  51. {
  52. return data->m_name.C();
  53. }
  54. void Font::Print(vec3 pos, char const *str, vec2 scale)
  55. {
  56. while (*str)
  57. {
  58. uint32_t ch = (uint8_t)*str++;
  59. if (ch != ' ')
  60. g_scene->AddTile(data->tileset, ch & 255, pos, 0, scale);
  61. pos.x += data->size.x * scale.x;
  62. }
  63. }
  64. ivec2 Font::GetSize() const
  65. {
  66. return data->size;
  67. }
  68. } /* namespace lol */