Browse Source

Add metadata submenu to "Add module" menu, deprecate Menu::pushChild (use ::addChild)

tags/v0.5.0
Andrew Belt 7 years ago
parent
commit
47682af04c
6 changed files with 80 additions and 69 deletions
  1. +7
    -0
      include/plugin.hpp
  2. +3
    -0
      include/util.hpp
  3. +3
    -1
      include/widgets.hpp
  4. +50
    -57
      src/app/RackWidget.cpp
  5. +4
    -0
      src/core/core.cpp
  6. +13
    -11
      src/widgets/Menu.cpp

+ 7
- 0
include/plugin.hpp View File

@@ -68,11 +68,18 @@ struct Plugin {


/** Used when syncing plugins with the API */ /** Used when syncing plugins with the API */
std::string slug; std::string slug;

// Optional plugin metadata

/** The version of your plugin /** The version of your plugin
Plugins should follow the versioning scheme described at https://github.com/VCVRack/Rack/issues/266 Plugins should follow the versioning scheme described at https://github.com/VCVRack/Rack/issues/266
Do not include the "v" in "v1.0" for example. Do not include the "v" in "v1.0" for example.
*/ */
std::string version; std::string version;
/** URL for plugin homepage */
std::string website;
/** URL for plugin manual */
std::string manual;


virtual ~Plugin(); virtual ~Plugin();
void addModel(Model *model); void addModel(Model *model);


+ 3
- 0
include/util.hpp View File

@@ -30,6 +30,9 @@ will expand to


#define LENGTHOF(arr) (sizeof(arr) / sizeof((arr)[0])) #define LENGTHOF(arr) (sizeof(arr) / sizeof((arr)[0]))


/** Deprecation notice for GCC */
#define DEPRECATED __attribute__ ((deprecated))



namespace rack { namespace rack {




+ 3
- 1
include/widgets.hpp View File

@@ -312,7 +312,9 @@ struct Menu : OpaqueWidget {
} }
~Menu(); ~Menu();
// Resizes menu and calls addChild() // Resizes menu and calls addChild()
void pushChild(Widget *child);
void pushChild(Widget *child) DEPRECATED {
addChild(child);
}
void setChildMenu(Menu *menu); void setChildMenu(Menu *menu);
void step() override; void step() override;
void draw(NVGcontext *vg) override; void draw(NVGcontext *vg) override;


+ 50
- 57
src/app/RackWidget.cpp View File

@@ -247,8 +247,8 @@ void RackWidget::fromJson(json_t *rootJ) {
int outputModuleId, outputId; int outputModuleId, outputId;
int inputModuleId, inputId; int inputModuleId, inputId;
int err = json_unpack(wireJ, "{s:i, s:i, s:i, s:i}", int err = json_unpack(wireJ, "{s:i, s:i, s:i, s:i}",
"outputModuleId", &outputModuleId, "outputId", &outputId,
"inputModuleId", &inputModuleId, "inputId", &inputId);
"outputModuleId", &outputModuleId, "outputId", &outputId,
"inputModuleId", &inputModuleId, "inputId", &inputId);
if (err) continue; if (err) continue;
// Get ports // Get ports
ModuleWidget *outputModuleWidget = moduleWidgets[outputModuleId]; ModuleWidget *outputModuleWidget = moduleWidgets[outputModuleId];
@@ -354,7 +354,7 @@ void RackWidget::step() {
} }


// Autosave every 15 seconds // Autosave every 15 seconds
if (gGuiFrame % (60*15) == 0) {
if (gGuiFrame % (60 * 15) == 0) {
savePatch(assetLocal("autosave.vcv")); savePatch(assetLocal("autosave.vcv"));
settingsSave(assetLocal("settings.json")); settingsSave(assetLocal("settings.json"));
} }
@@ -366,6 +366,16 @@ void RackWidget::draw(NVGcontext *vg) {
Widget::draw(vg); Widget::draw(vg);
} }



struct UrlItem : MenuItem {
std::string url;
void onAction(EventAction &e) override {
std::thread t(openBrowser, url);
t.detach();
}
};


struct AddModuleMenuItem : MenuItem { struct AddModuleMenuItem : MenuItem {
Model *model; Model *model;
Vec modulePos; Vec modulePos;
@@ -378,19 +388,47 @@ struct AddModuleMenuItem : MenuItem {
box.pos = modulePos.minus(box.getCenter()); box.pos = modulePos.minus(box.getCenter());
gRackWidget->requestModuleBoxNearest(moduleWidget, box); gRackWidget->requestModuleBoxNearest(moduleWidget, box);
} }
};


struct UrlItem : MenuItem {
std::string url;
void onAction(EventAction &e) override {
std::thread t(openBrowser, url);
t.detach();
Menu *createChildMenu() override {
Menu *menu = new Menu();

// Tag list
if (!model->tags.empty()) {
for (ModelTag tag : model->tags) {
menu->addChild(construct<MenuLabel>(&MenuEntry::text, gTagNames[tag]));
}
menu->addChild(construct<MenuEntry>());
}

// Plugin name
std::string pluginName = model->plugin->slug;
if (!model->plugin->version.empty()) {
pluginName += " v";
pluginName += model->plugin->version;
}
menu->addChild(construct<MenuLabel>(&MenuEntry::text, pluginName));

// Plugin metadata
if (!model->plugin->website.empty()) {
menu->addChild(construct<UrlItem>(&MenuEntry::text, "Website", &UrlItem::url, model->plugin->path));
}
if (!model->plugin->manual.empty()) {
menu->addChild(construct<UrlItem>(&MenuEntry::text, "Manual", &UrlItem::url, model->plugin->manual));
}
if (!model->plugin->path.empty()) {
menu->addChild(construct<UrlItem>(&MenuEntry::text, "Browse directory", &UrlItem::url, model->plugin->path));
}

return menu;
} }
}; };


struct AddManufacturerMenuItem : MenuItem { struct AddManufacturerMenuItem : MenuItem {
std::string manufacturerName; std::string manufacturerName;
Vec modulePos; Vec modulePos;
void onAction(EventAction &e) override {
e.consumed = false;
}
Menu *createChildMenu() override { Menu *createChildMenu() override {
Menu *menu = new Menu(); Menu *menu = new Menu();


@@ -405,51 +443,11 @@ struct AddManufacturerMenuItem : MenuItem {
// item->rightText += " v" + model->plugin->version; // item->rightText += " v" + model->plugin->version;
item->model = model; item->model = model;
item->modulePos = modulePos; item->modulePos = modulePos;
menu->pushChild(item);
menu->addChild(item);
} }
} }
} }


// Metadata items
/*
{
MenuLabel *label = new MenuLabel();
menu->pushChild(label);
}
{
MenuLabel *label = new MenuLabel();
label->text = plugin->name;
menu->pushChild(label);
}

if (!plugin->homepageUrl.empty()) {
UrlItem *item = new UrlItem();
item->text = "Homepage";
item->url = plugin->homepageUrl;
menu->pushChild(item);
}

if (!plugin->manualUrl.empty()) {
UrlItem *item = new UrlItem();
item->text = "Manual";
item->url = plugin->manualUrl;
menu->pushChild(item);
}

if (!plugin->path.empty()) {
UrlItem *item = new UrlItem();
item->text = "Browse directory";
item->url = plugin->path;
menu->pushChild(item);
}

if (!plugin->version.empty()) {
MenuLabel *item = new MenuLabel();
item->text = "Version: v" + plugin->version;
menu->pushChild(item);
}
*/

return menu; return menu;
} }
}; };
@@ -486,16 +484,11 @@ void RackWidget::onMouseDown(EventMouseDown &e) {
if (e.button == 1) { if (e.button == 1) {
Menu *menu = gScene->createMenu(); Menu *menu = gScene->createMenu();


menu->pushChild(construct<MenuLabel>(&MenuLabel::text, "Add module"));

/*
// TODO make functional
TextField *searchField = construct<SearchModuleField>(); TextField *searchField = construct<SearchModuleField>();
searchField->box.size.x = 100.0; searchField->box.size.x = 100.0;
menu->pushChild(searchField);
menu->addChild(searchField);
// Focus search field // Focus search field
gFocusedWidget = searchField; gFocusedWidget = searchField;
*/


// Collect manufacturer names // Collect manufacturer names
std::set<std::string> manufacturerNames; std::set<std::string> manufacturerNames;
@@ -510,7 +503,7 @@ void RackWidget::onMouseDown(EventMouseDown &e) {
item->text = manufacturerName; item->text = manufacturerName;
item->manufacturerName = manufacturerName; item->manufacturerName = manufacturerName;
item->modulePos = e.pos; item->modulePos = e.pos;
menu->pushChild(item);
menu->addChild(item);
} }
} }
e.consumed = true; e.consumed = true;


+ 4
- 0
src/core/core.cpp View File

@@ -3,6 +3,10 @@


void init(rack::Plugin *p) { void init(rack::Plugin *p) {
p->slug = "Core"; p->slug = "Core";
#ifdef VERSION
p->version = TOSTRING(VERSION);
#endif

p->addModel(createModel<AudioInterfaceWidget>("Core", "Core", "AudioInterface", "Audio Interface", EXTERNAL_TAG)); p->addModel(createModel<AudioInterfaceWidget>("Core", "Core", "AudioInterface", "Audio Interface", EXTERNAL_TAG));
p->addModel(createModel<MidiToCVWidget>("Core", "Core", "MIDIToCVInterface", "MIDI-to-CV Interface", MIDI_TAG, EXTERNAL_TAG)); p->addModel(createModel<MidiToCVWidget>("Core", "Core", "MIDIToCVInterface", "MIDI-to-CV Interface", MIDI_TAG, EXTERNAL_TAG));




+ 13
- 11
src/widgets/Menu.cpp View File

@@ -7,12 +7,6 @@ Menu::~Menu() {
setChildMenu(NULL); setChildMenu(NULL);
} }


void Menu::pushChild(Widget *child) {
child->box.pos = Vec(0, box.size.y);
addChild(child);
box.size.y += child->box.size.y;
}

void Menu::setChildMenu(Menu *menu) { void Menu::setChildMenu(Menu *menu) {
if (childMenu) { if (childMenu) {
if (childMenu->parent) if (childMenu->parent)
@@ -28,22 +22,30 @@ void Menu::setChildMenu(Menu *menu) {
} }


void Menu::step() { void Menu::step() {
// Try to fit into the parent's box
if (parent)
box = box.nudge(Rect(Vec(0, 0), parent->box.size));

Widget::step(); Widget::step();


// Resize the width to the widest child
// Set positions of children
box.size = Vec(0, 0);
for (Widget *child : children) { for (Widget *child : children) {
if (!child->visible)
continue;
// Increase height, set position of child
child->box.pos = Vec(0, box.size.y);
box.size.y += child->box.size.y;
// Increase width based on maximum width of child
if (child->box.size.x > box.size.x) { if (child->box.size.x > box.size.x) {
box.size.x = child->box.size.x; box.size.x = child->box.size.x;
} }
} }

// Resize widths of children // Resize widths of children
for (Widget *child : children) { for (Widget *child : children) {
child->box.size.x = box.size.x; child->box.size.x = box.size.x;
} }

// Try to fit into the parent's box
if (parent)
box = box.nudge(Rect(Vec(0, 0), parent->box.size));
} }


void Menu::draw(NVGcontext *vg) { void Menu::draw(NVGcontext *vg) {


Loading…
Cancel
Save