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.

127 lines
3.3KB

  1. #include "global_pre.hpp"
  2. #include "app.hpp"
  3. #include "window.hpp"
  4. #include "util/request.hpp"
  5. #include "osdialog.h"
  6. #include <string.h>
  7. #include <thread>
  8. #include "global_ui.hpp"
  9. namespace rack {
  10. RackScene::RackScene() {
  11. scrollWidget = new RackScrollWidget();
  12. {
  13. zoomWidget = new ZoomWidget();
  14. {
  15. assert(!global_ui->app.gRackWidget);
  16. global_ui->app.gRackWidget = new RackWidget();
  17. zoomWidget->addChild(global_ui->app.gRackWidget);
  18. }
  19. scrollWidget->container->addChild(zoomWidget);
  20. }
  21. addChild(scrollWidget);
  22. global_ui->app.gToolbar = new Toolbar();
  23. addChild(global_ui->app.gToolbar);
  24. scrollWidget->box.pos.y = global_ui->app.gToolbar->box.size.y;
  25. }
  26. void RackScene::step() {
  27. // Resize owned descendants
  28. global_ui->app.gToolbar->box.size.x = box.size.x;
  29. scrollWidget->box.size = box.size.minus(scrollWidget->box.pos);
  30. // Resize to be a bit larger than the ScrollWidget viewport
  31. global_ui->app.gRackWidget->box.size = scrollWidget->box.size
  32. .minus(scrollWidget->container->box.pos)
  33. .plus(Vec(500, 500))
  34. .div(zoomWidget->zoom);
  35. Scene::step();
  36. zoomWidget->box.size = global_ui->app.gRackWidget->box.size.mult(zoomWidget->zoom);
  37. // Version popup message
  38. if (!global_ui->app.gLatestVersion.empty()) {
  39. std::string versionMessage = stringf("Rack %s is available.\n\nYou have Rack %s.\n\nClose Rack and download new version on the website?", global_ui->app.gLatestVersion.c_str(), global_ui->app.gApplicationVersion.c_str());
  40. if (osdialog_message(OSDIALOG_INFO, OSDIALOG_OK_CANCEL, versionMessage.c_str())) {
  41. std::thread t(systemOpenBrowser, "https://vcvrack.com/");
  42. t.detach();
  43. windowClose();
  44. }
  45. global_ui->app.gLatestVersion = "";
  46. }
  47. }
  48. void RackScene::draw(NVGcontext *vg) {
  49. Scene::draw(vg);
  50. }
  51. void RackScene::onHoverKey(EventHoverKey &e) {
  52. Widget::onHoverKey(e);
  53. if (!e.consumed) {
  54. switch (e.key) {
  55. case 'n'/*GLFW_KEY_N*/:
  56. if (windowIsModPressed() && !windowIsShiftPressed()) {
  57. global_ui->app.gRackWidget->reset();
  58. e.consumed = true;
  59. }
  60. break;
  61. case 'q'/*GLFW_KEY_Q*/:
  62. if (windowIsModPressed() && !windowIsShiftPressed()) {
  63. windowClose();
  64. e.consumed = true;
  65. }
  66. break;
  67. case 'o'/*GLFW_KEY_O*/:
  68. if (windowIsModPressed() && !windowIsShiftPressed()) {
  69. global_ui->app.gRackWidget->openDialog();
  70. e.consumed = true;
  71. }
  72. if (windowIsModPressed() && windowIsShiftPressed()) {
  73. global_ui->app.gRackWidget->revert();
  74. e.consumed = true;
  75. }
  76. break;
  77. case 's'/*GLFW_KEY_S*/:
  78. if (windowIsModPressed() && !windowIsShiftPressed()) {
  79. global_ui->app.gRackWidget->saveDialog();
  80. e.consumed = true;
  81. }
  82. if (windowIsModPressed() && windowIsShiftPressed()) {
  83. global_ui->app.gRackWidget->saveAsDialog();
  84. e.consumed = true;
  85. }
  86. break;
  87. case LGLW_VKEY_RETURN/*GLFW_KEY_ENTER*/:
  88. // case GLFW_KEY_KP_ENTER:
  89. appModuleBrowserCreate();
  90. e.consumed = true;
  91. break;
  92. case LGLW_VKEY_F11/*GLFW_KEY_F11*/:
  93. windowSetFullScreen(!windowGetFullScreen());
  94. break;
  95. }
  96. }
  97. }
  98. void RackScene::onPathDrop(EventPathDrop &e) {
  99. if (e.paths.size() >= 1) {
  100. const std::string& firstPath = e.paths.front();
  101. if (stringExtension(firstPath) == "vcv") {
  102. global_ui->app.gRackWidget->loadPatch(firstPath);
  103. e.consumed = true;
  104. }
  105. }
  106. if (!e.consumed)
  107. Scene::onPathDrop(e);
  108. }
  109. } // namespace rack