TestSignedDistanceFont.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #include "test.h"
  3. class TestSignedDistanceFont : public Test
  4. {
  5. public:
  6. spTextField _txt;
  7. ResFontBM font;
  8. spTween t;
  9. TestSignedDistanceFont()
  10. {
  11. font.initSD("sdf/font.fnt", 8);
  12. font.load();
  13. /*how to make SD font
  14. based on article: https://habrahabr.ru/post/282191/
  15. 1. install ImageMagick
  16. 2. generate huge font with size 400pt, set padding 40x40x40x40
  17. 3. convert font image to SD font image using command below:
  18. convert font.png -filter Jinc ( +clone -negate -morphology Distance Euclidean -level 50%,-50% ) -morphology Distance Euclidean -compose Plus -composite -level 43%,57% -resize 12.5% font.png
  19. font image will be downscaled 8 times from 4096 to 512
  20. declare your font in resources.xml:
  21. <sdfont font="font.fnt" downsample="8" />
  22. or load it directly from file as I did above
  23. */
  24. spTextField txt = new TextField;
  25. txt->attachTo(content);
  26. _txt = txt;
  27. TextStyle st;
  28. st.font = &font;
  29. st.vAlign = TextStyle::VALIGN_MIDDLE;
  30. st.hAlign = TextStyle::HALIGN_MIDDLE;
  31. st.color = Color::CornflowerBlue;
  32. st.multiline = true;
  33. st.outlineColor = Color::White;
  34. st.outline = 0.1f;
  35. txt->setStyle(st);
  36. txt->setColor(Color::CornflowerBlue);
  37. txt->setText("The quick brown fox jumps over the lazy dog. 1234567890.");
  38. txt->setPosition(getStage()->getSize() / 2);
  39. txt->setWidth(getStage()->getWidth() / 2);
  40. txt->setAnchor(0.5f, 0.5f);
  41. addButton("scale+", "scale+");
  42. addButton("scale-", "scale-");
  43. addButton("weight+", "weight+");
  44. addButton("weight-", "weight-");
  45. addButton("outline+", "outline+");
  46. addButton("outline-", "outline-");
  47. }
  48. ~TestSignedDistanceFont()
  49. {
  50. }
  51. void clicked(string id)
  52. {
  53. if (id == "outline+")
  54. _txt->setOutline(_txt->getOutline() + 0.01f);
  55. if (id == "outline-")
  56. _txt->setOutline(_txt->getOutline() - 0.01f);
  57. if (id == "scale+")
  58. _txt->addTween(TweenScale(_txt->getScale() * 1.5f), 300);
  59. if (id == "scale-")
  60. _txt->addTween(TweenScale(_txt->getScale() / 1.5f), 300);
  61. if (id == "weight+")
  62. _txt->setWeight(_txt->getWeight() - 0.01f);
  63. if (id == "weight-")
  64. _txt->setWeight(_txt->getWeight() + 0.01f);
  65. }
  66. void toggleClicked(string id, const toggle* data)
  67. {
  68. }
  69. };