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.

50 lines
1.2KB

  1. #include "widgets.hpp"
  2. namespace rack {
  3. TransformWidget::TransformWidget() {
  4. identity();
  5. }
  6. Rect TransformWidget::getChildrenBoundingBox() {
  7. Rect bound = Widget::getChildrenBoundingBox();
  8. Vec topLeft = bound.pos;
  9. Vec bottomRight = bound.getBottomRight();
  10. nvgTransformPoint(&topLeft.x, &topLeft.y, transform, topLeft.x, topLeft.y);
  11. nvgTransformPoint(&bottomRight.x, &bottomRight.y, transform, bottomRight.x, bottomRight.y);
  12. return Rect(topLeft, bottomRight.minus(topLeft));
  13. }
  14. void TransformWidget::identity() {
  15. nvgTransformIdentity(transform);
  16. }
  17. void TransformWidget::translate(Vec delta) {
  18. float t[6];
  19. nvgTransformTranslate(t, delta.x, delta.y);
  20. nvgTransformPremultiply(transform, t);
  21. }
  22. void TransformWidget::rotate(float angle) {
  23. float t[6];
  24. nvgTransformRotate(t, angle);
  25. nvgTransformPremultiply(transform, t);
  26. }
  27. void TransformWidget::scale(Vec s) {
  28. float t[6];
  29. nvgTransformScale(t, s.x, s.y);
  30. nvgTransformPremultiply(transform, t);
  31. }
  32. void TransformWidget::draw(NVGcontext *vg) {
  33. // No need to save the state because that is done in the parent
  34. nvgTransform(vg, transform[0], transform[1], transform[2], transform[3], transform[4], transform[5]);
  35. Widget::draw(vg);
  36. }
  37. } // namespace rack