From 98987a2ef9d0ae356017ffe8056d217e68887fc2 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 16 Sep 2017 17:10:41 -0400 Subject: [PATCH] Add error message if window doesn't open, refactor SVGPanel --- ext/osdialog | 2 +- include/app.hpp | 6 +----- src/app/PanelBorder.cpp | 20 -------------------- src/app/SVGPanel.cpp | 20 ++++++++++++++++++-- src/gui.cpp | 7 ++++++- src/widgets/FramebufferWidget.cpp | 1 + 6 files changed, 27 insertions(+), 29 deletions(-) delete mode 100644 src/app/PanelBorder.cpp diff --git a/ext/osdialog b/ext/osdialog index e66caf0f..952d72f9 160000 --- a/ext/osdialog +++ b/ext/osdialog @@ -1 +1 @@ -Subproject commit e66caf0f9d3266a79c513dcc73b57b6b3eb38120 +Subproject commit 952d72f925ea5e9086067d47a9d31516878fcaac diff --git a/include/app.hpp b/include/app.hpp index a6cf7616..07862c9c 100644 --- a/include/app.hpp +++ b/include/app.hpp @@ -121,12 +121,8 @@ struct Panel : TransparentWidget { void draw(NVGcontext *vg); }; -struct PanelBorder : TransparentWidget { - void draw(NVGcontext *vg); -}; - struct SVGPanel : FramebufferWidget { - void addBackground(std::shared_ptr svg); + void setBackground(std::shared_ptr svg); }; //////////////////// diff --git a/src/app/PanelBorder.cpp b/src/app/PanelBorder.cpp deleted file mode 100644 index aea68159..00000000 --- a/src/app/PanelBorder.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "app.hpp" - - -namespace rack { - -void PanelBorder::draw(NVGcontext *vg) { - nvgBeginPath(vg); - nvgRect(vg, 0.0, 0.0, box.size.x, box.size.y); - - NVGcolor borderColor = nvgRGB(0xac, 0xac, 0xac); - - // Border - nvgBeginPath(vg); - nvgRect(vg, 0.5, 0.5, box.size.x - 1, box.size.y - 1); - nvgStrokeColor(vg, borderColor); - nvgStrokeWidth(vg, 1.0); - nvgStroke(vg); -} - -} // namespace rack diff --git a/src/app/SVGPanel.cpp b/src/app/SVGPanel.cpp index b77760c0..73958c81 100644 --- a/src/app/SVGPanel.cpp +++ b/src/app/SVGPanel.cpp @@ -4,14 +4,30 @@ namespace rack { -void SVGPanel::addBackground(std::shared_ptr svg) { +struct PanelBorder : TransparentWidget { + void draw(NVGcontext *vg) { + nvgBeginPath(vg); + nvgRect(vg, 0.0, 0.0, box.size.x, box.size.y); + + NVGcolor borderColor = nvgRGBAf(0.5, 0.5, 0.5, 0.5); + + nvgBeginPath(vg); + nvgRect(vg, 0.5, 0.5, box.size.x - 1.0, box.size.y - 1.0); + nvgStrokeColor(vg, borderColor); + nvgStrokeWidth(vg, 1.0); + nvgStroke(vg); + } +}; + + +void SVGPanel::setBackground(std::shared_ptr svg) { SVGWidget *sw = new SVGWidget(); sw->wrap(); sw->svg = svg; addChild(sw); PanelBorder *pb = new PanelBorder(); - sw->box.size = box.size; + pb->box.size = box.size; addChild(pb); } diff --git a/src/gui.cpp b/src/gui.cpp index d575019d..dbb25433 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -3,6 +3,7 @@ #include "gui.hpp" #include "app.hpp" #include "settings.hpp" +#include "../ext/osdialog/osdialog.h" #define NANOVG_GL2_IMPLEMENTATION // #define NANOVG_GL3_IMPLEMENTATION @@ -216,7 +217,11 @@ void guiInit() { glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); std::string title = gApplicationName + " " + gApplicationVersion; gWindow = glfwCreateWindow(1000, 750, title.c_str(), NULL, NULL); - assert(gWindow); + if (!gWindow) { + osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, "Cannot open window with OpenGL 2.0 renderer. Does your graphics card support OpenGL 2.0? If so, are the latest drivers installed?"); + exit(1); + } + glfwMakeContextCurrent(gWindow); glfwSwapInterval(1); diff --git a/src/widgets/FramebufferWidget.cpp b/src/widgets/FramebufferWidget.cpp index 1fa13656..9b5b0d9e 100644 --- a/src/widgets/FramebufferWidget.cpp +++ b/src/widgets/FramebufferWidget.cpp @@ -42,6 +42,7 @@ void FramebufferWidget::step() { Vec fbSize = internal->box.size.mult(gPixelRatio * oversample); // assert(fbSize.isFinite()); + // Delete old one first to free up GPU memory internal->setFramebuffer(NULL); NVGLUframebuffer *fb = nvgluCreateFramebuffer(gVg, fbSize.x, fbSize.y, NVG_IMAGE_REPEATX | NVG_IMAGE_REPEATY); if (!fb)