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.

67 lines
1.6KB

  1. #include "../LRComponents.hpp"
  2. namespace lrt {
  3. LRKnob::LRKnob() {
  4. minAngle = -ANGLE * (float) M_PI;
  5. maxAngle = ANGLE * (float) M_PI;
  6. shader = new LRShadow();
  7. removeChild(shadow); // uninstall default
  8. font = Font::load(assetGlobal("res/fonts/ShareTechMono-Regular.ttf"));
  9. indicator = new LRCVIndicator(15.f, ANGLE);
  10. addChild(indicator);
  11. }
  12. void LRKnob::setSVG(std::shared_ptr<SVG> svg) {
  13. SVGKnob::setSVG(svg);
  14. /** inherit dimensions after loaded svg */
  15. indicator->box.size = sw->box.size;
  16. indicator->middle = Vec(box.size.x / 2, box.size.y / 2);
  17. shader->setBox(box);
  18. }
  19. void LRKnob::draw(NVGcontext *vg) {
  20. /** shadow */
  21. shader->draw(vg);
  22. /** component */
  23. FramebufferWidget::draw(vg);
  24. /** debug numerical values */
  25. if (debug) {
  26. auto text = stringf("%4.2f", value);
  27. nvgFontSize(vg, 15);
  28. nvgFontFaceId(vg, font->handle);
  29. nvgFillColor(vg, nvgRGBAf(1.f, 1.f, 1.0f, 1.0f));
  30. nvgText(vg, box.size.x - 5, box.size.y + 10, text.c_str(), NULL);
  31. }
  32. }
  33. void LRKnob::setSnap(float position, float sensitivity) {
  34. snap = true;
  35. snapSens = sensitivity;
  36. snapAt = position;
  37. }
  38. void LRKnob::unsetSnap() {
  39. snap = false;
  40. }
  41. void LRKnob::onChange(EventChange &e) {
  42. // if the value still inside snap-tolerance keep the value zero
  43. if (snap && value > -snapSens + snapAt && value < snapSens + snapAt) value = 0;
  44. SVGKnob::onChange(e);
  45. }
  46. }