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.

81 lines
2.1KB

  1. #include "../include/ColourDragging.hpp"
  2. #include "../include/BaseWidget.hpp"
  3. #include "window.hpp"
  4. namespace rack_plugin_rcm {
  5. BaseWidget::BaseWidget(Module* module) : ModuleWidget(module) {}
  6. void BaseWidget::onDragStart(EventDragStart& e) {
  7. if (currentDragType == NULL) {
  8. Vec pos = RACK_PLUGIN_UI_RACKWIDGET->lastMousePos.minus(box.pos);
  9. bool inColourDragZone = colourHotZone.contains(pos);
  10. if (inColourDragZone && windowIsShiftPressed()) {
  11. currentDragType = new ColourDragging(this);
  12. }
  13. }
  14. ModuleWidget::onDragStart(e);
  15. }
  16. void BaseWidget::onDragMove(EventDragMove& e) {
  17. if (currentDragType != NULL) {
  18. currentDragType->onDragMove(e);
  19. } else {
  20. ModuleWidget::onDragMove(e);
  21. }
  22. }
  23. void BaseWidget::onDragEnd(EventDragEnd& e) {
  24. if (currentDragType != NULL) {
  25. delete currentDragType;
  26. currentDragType = NULL;
  27. }
  28. ModuleWidget::onDragEnd(e);
  29. }
  30. json_t *BaseWidget::toJson() {
  31. json_t *rootJ = ModuleWidget::toJson();
  32. if (rootJ == NULL) {
  33. rootJ = json_object();
  34. }
  35. json_object_set_new(rootJ, "backgroundHue", json_real(this->backgroundHue));
  36. json_object_set_new(rootJ, "backgroundSaturation", json_real(this->backgroundSaturation));
  37. json_object_set_new(rootJ, "backgroundLuminosity", json_real(this->backgroundLuminosity));
  38. return rootJ;
  39. }
  40. void BaseWidget::fromJson(json_t *rootJ) {
  41. ModuleWidget::fromJson(rootJ);
  42. json_t *backgroundHueJ = json_object_get(rootJ, "backgroundHue");
  43. if (backgroundHueJ) {
  44. backgroundHue = json_real_value(backgroundHueJ);
  45. }
  46. json_t *backgroundSaturationJ = json_object_get(rootJ, "backgroundSaturation");
  47. if (backgroundSaturationJ) {
  48. backgroundSaturation = json_real_value(backgroundSaturationJ);
  49. }
  50. json_t *backgroundLuminosityJ = json_object_get(rootJ, "backgroundLuminosity");
  51. if (backgroundLuminosityJ) {
  52. backgroundLuminosity = json_real_value(backgroundLuminosityJ);
  53. }
  54. }
  55. void BaseWidget::draw(NVGcontext* ctx) {
  56. nvgBeginPath(ctx);
  57. nvgFillColor(ctx, nvgHSL(backgroundHue, backgroundSaturation, backgroundLuminosity));
  58. nvgRect(ctx, 0, 0, box.size.x, box.size.y);
  59. nvgFill(ctx);
  60. ModuleWidget::draw(ctx);
  61. }
  62. } // namespace rack_plugin_rcm