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.

139 lines
3.1KB

  1. #include "app.hpp"
  2. #include "gui.hpp"
  3. #include "util/request.hpp"
  4. #include "../ext/osdialog/osdialog.h"
  5. #include <string.h>
  6. #include <thread>
  7. namespace rack {
  8. static std::string newVersion = "";
  9. static void checkVersion() {
  10. json_t *resJ = requestJson(METHOD_GET, gApiHost + "/version", NULL);
  11. if (resJ) {
  12. json_t *versionJ = json_object_get(resJ, "version");
  13. if (versionJ) {
  14. const char *version = json_string_value(versionJ);
  15. if (version && strlen(version) > 0 && version != gApplicationVersion) {
  16. newVersion = version;
  17. }
  18. }
  19. json_decref(resJ);
  20. }
  21. }
  22. RackScene::RackScene() {
  23. scrollWidget = new RackScrollWidget();
  24. {
  25. zoomWidget = new ZoomWidget();
  26. {
  27. assert(!gRackWidget);
  28. gRackWidget = new RackWidget();
  29. zoomWidget->addChild(gRackWidget);
  30. }
  31. scrollWidget->container->addChild(zoomWidget);
  32. }
  33. addChild(scrollWidget);
  34. gToolbar = new Toolbar();
  35. addChild(gToolbar);
  36. scrollWidget->box.pos.y = gToolbar->box.size.y;
  37. // Check for new version
  38. if (!gApplicationVersion.empty()) {
  39. std::thread versionThread(checkVersion);
  40. versionThread.detach();
  41. }
  42. }
  43. void RackScene::step() {
  44. // Resize owned descendants
  45. gToolbar->box.size.x = box.size.x;
  46. scrollWidget->box.size = box.size.minus(scrollWidget->box.pos);
  47. // Resize to be a bit larger than the ScrollWidget viewport
  48. gRackWidget->box.size = scrollWidget->box.size
  49. .minus(scrollWidget->container->box.pos)
  50. .plus(Vec(500, 500))
  51. .div(zoomWidget->zoom);
  52. Scene::step();
  53. zoomWidget->box.size = gRackWidget->box.size.mult(zoomWidget->zoom);
  54. // Version popup message
  55. if (!newVersion.empty()) {
  56. std::string versionMessage = stringf("Rack %s is available.\n\nYou have Rack %s.\n\nWould you like to download the new version on the website?", newVersion.c_str(), gApplicationVersion.c_str());
  57. if (osdialog_message(OSDIALOG_INFO, OSDIALOG_YES_NO, versionMessage.c_str())) {
  58. std::thread t(openBrowser, "https://vcvrack.com/");
  59. t.detach();
  60. guiClose();
  61. }
  62. newVersion = "";
  63. }
  64. }
  65. void RackScene::draw(NVGcontext *vg) {
  66. Scene::draw(vg);
  67. }
  68. void RackScene::onHoverKey(EventHoverKey &e) {
  69. switch (e.key) {
  70. case GLFW_KEY_N:
  71. if (guiIsModPressed() && !guiIsShiftPressed()) {
  72. gRackWidget->reset();
  73. e.consumed = true;
  74. return;
  75. }
  76. break;
  77. case GLFW_KEY_Q:
  78. if (guiIsModPressed() && !guiIsShiftPressed()) {
  79. guiClose();
  80. e.consumed = true;
  81. return;
  82. }
  83. break;
  84. case GLFW_KEY_O:
  85. if (guiIsModPressed() && !guiIsShiftPressed()) {
  86. gRackWidget->openDialog();
  87. e.consumed = true;
  88. return;
  89. }
  90. break;
  91. case GLFW_KEY_S:
  92. if (guiIsModPressed() && !guiIsShiftPressed()) {
  93. gRackWidget->saveDialog();
  94. e.consumed = true;
  95. return;
  96. }
  97. if (guiIsModPressed() && guiIsShiftPressed()) {
  98. gRackWidget->saveAsDialog();
  99. e.consumed = true;
  100. return;
  101. }
  102. break;
  103. }
  104. Widget::onHoverKey(e);
  105. }
  106. void RackScene::onPathDrop(EventPathDrop &e) {
  107. if (e.paths.size() >= 1) {
  108. const std::string& firstPath = e.paths.front();
  109. if (extractExtension(firstPath) == "vcv") {
  110. gRackWidget->loadPatch(firstPath);
  111. e.consumed = true;
  112. }
  113. }
  114. }
  115. } // namespace rack