| 573 | |
| 574 | |
| 575 | void Window::screenshotModules(const std::string& screenshotsDir, float zoom) { |
| 576 | // Disable preferDarkPanels |
| 577 | bool preferDarkPanels = settings::preferDarkPanels; |
| 578 | settings::preferDarkPanels = false; |
| 579 | DEFER({settings::preferDarkPanels = preferDarkPanels;}); |
| 580 | |
| 581 | // Iterate plugins and create directories |
| 582 | system::createDirectories(screenshotsDir); |
| 583 | for (plugin::Plugin* p : plugin::plugins) { |
| 584 | std::string dir = system::join(screenshotsDir, p->slug); |
| 585 | system::createDirectory(dir); |
| 586 | for (plugin::Model* model : p->models) { |
| 587 | std::string filename = system::join(dir, model->slug + ".png"); |
| 588 | |
| 589 | // Skip model if screenshot already exists |
| 590 | if (system::isFile(filename)) |
| 591 | continue; |
| 592 | |
| 593 | INFO("Screenshotting %s %s to %s", p->slug.c_str(), model->slug.c_str(), filename.c_str()); |
| 594 | |
| 595 | // Create widgets |
| 596 | widget::FramebufferWidget* fbw = new widget::FramebufferWidget; |
| 597 | fbw->oversample = 2; |
| 598 | |
| 599 | struct ModuleWidgetContainer : widget::Widget { |
| 600 | void draw(const DrawArgs& args) override { |
| 601 | Widget::draw(args); |
| 602 | Widget::drawLayer(args, 1); |
| 603 | } |
| 604 | }; |
| 605 | ModuleWidgetContainer* mwc = new ModuleWidgetContainer; |
| 606 | fbw->addChild(mwc); |
| 607 | |
| 608 | app::ModuleWidget* mw = model->createModuleWidget(NULL); |
| 609 | mwc->box.size = mw->box.size; |
| 610 | fbw->box.size = mw->box.size; |
| 611 | mwc->addChild(mw); |
| 612 | |
| 613 | // Step to allow the ModuleWidget state to set its default appearance. |
| 614 | fbw->step(); |
| 615 | |
| 616 | // Draw to framebuffer |
| 617 | fbw->render(math::Vec(zoom, zoom)); |
| 618 | |
| 619 | // Read pixels |
| 620 | nvgluBindFramebuffer(fbw->getFramebuffer()); |
| 621 | int width, height; |
| 622 | nvgImageSize(vg, fbw->getImageHandle(), &width, &height); |
| 623 | uint8_t* pixels = new uint8_t[height * width * 4]; |
| 624 | glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 625 | |
| 626 | // Write pixels to PNG |
| 627 | flipBitmap(pixels, width, height, 4); |
| 628 | stbi_write_png(filename.c_str(), width, height, 4, pixels, width * 4); |
| 629 | |
| 630 | // Cleanup |
| 631 | delete[] pixels; |
| 632 | nvgluBindFramebuffer(NULL); |
no test coverage detected