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.

124 lines
2.8KB

  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. zoomWidget->zoom = 1.0;
  27. {
  28. assert(!gRackWidget);
  29. gRackWidget = new RackWidget();
  30. zoomWidget->addChild(gRackWidget);
  31. }
  32. scrollWidget->container->addChild(zoomWidget);
  33. }
  34. addChild(scrollWidget);
  35. gToolbar = new Toolbar();
  36. addChild(gToolbar);
  37. scrollWidget->box.pos.y = gToolbar->box.size.y;
  38. // Check for new version
  39. if (!gApplicationVersion.empty()) {
  40. std::thread versionThread(checkVersion);
  41. versionThread.detach();
  42. }
  43. }
  44. void RackScene::step() {
  45. // Resize owned descendants
  46. gToolbar->box.size.x = box.size.x;
  47. scrollWidget->box.size = box.size.minus(scrollWidget->box.pos);
  48. // Resize to be a bit larger than the ScrollWidget viewport
  49. gRackWidget->box.size = scrollWidget->box.size
  50. .minus(scrollWidget->container->box.pos)
  51. .plus(Vec(500, 500))
  52. .div(zoomWidget->zoom);
  53. Scene::step();
  54. zoomWidget->box.size = gRackWidget->box.size.mult(zoomWidget->zoom);
  55. // Version popup message
  56. if (!newVersion.empty()) {
  57. 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());
  58. if (osdialog_message(OSDIALOG_INFO, OSDIALOG_YES_NO, versionMessage.c_str())) {
  59. std::thread t(openBrowser, "https://vcvrack.com/");
  60. t.detach();
  61. guiClose();
  62. }
  63. newVersion = "";
  64. }
  65. }
  66. void RackScene::draw(NVGcontext *vg) {
  67. Scene::draw(vg);
  68. }
  69. Widget *RackScene::onHoverKey(Vec pos, int key) {
  70. switch (key) {
  71. case GLFW_KEY_N:
  72. if (guiIsModPressed() && !guiIsShiftPressed()) {
  73. gRackWidget->reset();
  74. return this;
  75. }
  76. break;
  77. case GLFW_KEY_Q:
  78. if (guiIsModPressed() && !guiIsShiftPressed()) {
  79. guiClose();
  80. return this;
  81. }
  82. break;
  83. case GLFW_KEY_O:
  84. if (guiIsModPressed() && !guiIsShiftPressed()) {
  85. gRackWidget->openDialog();
  86. return this;
  87. }
  88. break;
  89. case GLFW_KEY_S:
  90. if (guiIsModPressed() && !guiIsShiftPressed()) {
  91. gRackWidget->saveDialog();
  92. return this;
  93. }
  94. if (guiIsModPressed() && guiIsShiftPressed()) {
  95. gRackWidget->saveAsDialog();
  96. return this;
  97. }
  98. break;
  99. }
  100. return Widget::onHoverKey(pos, key);
  101. }
  102. } // namespace rack