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.

85 lines
2.5KB

  1. #include <app/RackRail.hpp>
  2. #include <app.hpp>
  3. #include <asset.hpp>
  4. #include <svg.hpp>
  5. namespace rack {
  6. namespace app {
  7. RackRail::RackRail() {
  8. busBoardSvg = APP->window->loadSvg(asset::system("res/ComponentLibrary/RackBusboard.svg"));
  9. }
  10. void RackRail::draw(const DrawArgs& args) {
  11. const float railHeight = 15;
  12. // Background color
  13. nvgBeginPath(args.vg);
  14. nvgRect(args.vg, 0.0, 0.0, box.size.x, box.size.y);
  15. nvgFillColor(args.vg, nvgRGB(0x30, 0x30, 0x30));
  16. nvgFill(args.vg);
  17. // Rails
  18. float holeRadius = 4.0;
  19. for (float y = 0; y < box.size.y; y += RACK_GRID_HEIGHT) {
  20. nvgFillColor(args.vg, nvgRGB(0xc9, 0xc9, 0xc9));
  21. nvgStrokeWidth(args.vg, 1.0);
  22. nvgStrokeColor(args.vg, nvgRGB(0x9d, 0x9f, 0xa2));
  23. // Top rail
  24. nvgBeginPath(args.vg);
  25. nvgRect(args.vg, 0, y, box.size.x, railHeight);
  26. for (float x = 0; x < box.size.x; x += RACK_GRID_WIDTH) {
  27. nvgCircle(args.vg, x + RACK_GRID_WIDTH / 2, y + railHeight / 2, holeRadius);
  28. nvgPathWinding(args.vg, NVG_HOLE);
  29. }
  30. nvgFill(args.vg);
  31. nvgBeginPath(args.vg);
  32. nvgMoveTo(args.vg, 0, y + railHeight - 0.5);
  33. nvgLineTo(args.vg, box.size.x, y + railHeight - 0.5);
  34. nvgStroke(args.vg);
  35. // Bottom rail
  36. nvgBeginPath(args.vg);
  37. nvgRect(args.vg, 0, y + RACK_GRID_HEIGHT - railHeight, box.size.x, railHeight);
  38. for (float x = 0; x < box.size.x; x += RACK_GRID_WIDTH) {
  39. nvgCircle(args.vg, x + RACK_GRID_WIDTH / 2, y + RACK_GRID_HEIGHT - railHeight + railHeight / 2, holeRadius);
  40. nvgPathWinding(args.vg, NVG_HOLE);
  41. }
  42. nvgFill(args.vg);
  43. nvgBeginPath(args.vg);
  44. nvgMoveTo(args.vg, 0, y + RACK_GRID_HEIGHT - 0.5);
  45. nvgLineTo(args.vg, box.size.x, y + RACK_GRID_HEIGHT - 0.5);
  46. nvgStroke(args.vg);
  47. // Bus board
  48. const float busBoardWidth = busBoardSvg->handle->width;
  49. const float busBoardHeight = busBoardSvg->handle->height;
  50. const float busBoardY = y + (RACK_GRID_HEIGHT - busBoardHeight) / 2;
  51. for (float x = 0; x < box.size.x; x += busBoardWidth) {
  52. nvgSave(args.vg);
  53. nvgTranslate(args.vg, x, busBoardY);
  54. svgDraw(args.vg, busBoardSvg->handle);
  55. nvgRestore(args.vg);
  56. }
  57. // Bus board shadow
  58. nvgBeginPath(args.vg);
  59. const float shadowY = busBoardY + busBoardHeight;
  60. const float shadowHeight = 10;
  61. nvgRect(args.vg, 0, shadowY, box.size.x, shadowHeight);
  62. NVGcolor shadowColor = nvgRGBA(0, 0, 0, 0x20);
  63. NVGcolor transparentColor = nvgRGBAf(0, 0, 0, 0);
  64. nvgFillPaint(args.vg, nvgLinearGradient(args.vg, 0, shadowY, 0, shadowY + shadowHeight, shadowColor, transparentColor));
  65. nvgFill(args.vg);
  66. }
  67. }
  68. } // namespace app
  69. } // namespace rack