| @@ -1 +1 @@ | |||
| Subproject commit edf7cebc93c6172d45111deb7e52b5df44652ba5 | |||
| Subproject commit 7936e6f1d08165407c1e1c2a6560f5cb278c3b5e | |||
| @@ -18,7 +18,7 @@ WINDRES ?= windres | |||
| ifeq ($(WIN32),true) | |||
| TARGETS = app.exe color.exe demo.exe images.exe nanovg.exe rectangles.exe shapes.exe text.exe | |||
| else | |||
| TARGETS = app color demo images nanovg rectangles shapes text | |||
| TARGETS = app color demo images nanovg nanovg2 rectangles shapes text | |||
| endif | |||
| # -------------------------------------------------------------- | |||
| @@ -51,9 +51,12 @@ demo: demo.cpp widgets/* ../dpf/dgl/* | |||
| images: images.cpp widgets/ExampleImagesWidget.hpp images_res/* ../dpf/dgl/* | |||
| $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ | |||
| nanovg: nanovg.cpp nanovg_res/* ../dpf/dgl/* | |||
| nanovg: nanovg.cpp widgets/NanoPerfWidget.hpp nanovg_res/* ../dpf/dgl/* | |||
| $(CXX) $< $(BUILD_CXX_FLAGS) -I../dpf/dgl/src/nanovg $(LINK_FLAGS) -o $@ | |||
| nanovg2: nanovg2.cpp widgets/NanoPerfWidget.hpp ../dpf/dgl/* | |||
| $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ | |||
| rectangles: rectangles.cpp widgets/ExampleRectanglesWidget.hpp ../dpf/dgl/* | |||
| $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ | |||
| @@ -24,6 +24,7 @@ | |||
| #include "widgets/ExampleRectanglesWidget.hpp" | |||
| #include "widgets/ExampleShapesWidget.hpp" | |||
| #include "widgets/ExampleTextWidget.hpp" | |||
| #include "widgets/NanoPerfWidget.hpp" | |||
| // ------------------------------------------------------ | |||
| // Images | |||
| @@ -71,12 +72,12 @@ public: | |||
| protected: | |||
| void onDisplay() override | |||
| { | |||
| const int iconSize = getWidth(); | |||
| const int iconSize = bgIcon.getWidth(); | |||
| glColor3f(0.027f, 0.027f, 0.027f); | |||
| bg.draw(); | |||
| Rectangle<int>(0, 0, getSize()).draw(); | |||
| bgIcon.setY(curPage*iconSize + curPage + 1); | |||
| bgIcon.setY(curPage*iconSize + curPage*3); | |||
| glColor3f(0.129f, 0.129f, 0.129f); | |||
| bgIcon.draw(); | |||
| @@ -86,7 +87,7 @@ protected: | |||
| if (curHover != curPage && curHover != -1) | |||
| { | |||
| Rectangle<int> rHover(1, curHover*iconSize + curHover + 1, iconSize-2, iconSize-2); | |||
| Rectangle<int> rHover(1, curHover*iconSize + curHover*3, iconSize-2, iconSize-2); | |||
| glColor3f(0.071f, 0.071f, 0.071f); | |||
| rHover.draw(); | |||
| @@ -105,10 +106,10 @@ protected: | |||
| const int pad = iconSize/2 - DemoArtwork::ico1Width/2; | |||
| img1.drawAt(pad, pad); | |||
| img2.drawAt(pad, pad + 1 + iconSize); | |||
| img3.drawAt(pad, pad + 2 + iconSize*2); | |||
| img4.drawAt(pad, pad + 3 + iconSize*3); | |||
| //img5.drawAt(pad, pad + 3 + iconSize*3); | |||
| img2.drawAt(pad, pad + 3 + iconSize); | |||
| img3.drawAt(pad, pad + 6 + iconSize*2); | |||
| img4.drawAt(pad, pad + 9 + iconSize*3); | |||
| //img5.drawAt(pad, pad + 12 + iconSize*4); | |||
| } | |||
| bool onMouse(const MouseEvent& ev) override | |||
| @@ -118,11 +119,11 @@ protected: | |||
| if (! contains(ev.pos)) | |||
| return false; | |||
| const int iconSize = getWidth(); | |||
| const int iconSize = bgIcon.getWidth(); | |||
| for (int i=0; i<kPageCount; ++i) | |||
| { | |||
| bgIcon.setY(i*iconSize + i + 1); | |||
| bgIcon.setY(i*iconSize + i*3); | |||
| if (bgIcon.contains(ev.pos)) | |||
| { | |||
| @@ -140,11 +141,11 @@ protected: | |||
| { | |||
| if (contains(ev.pos)) | |||
| { | |||
| const int iconSize = getWidth(); | |||
| const int iconSize = bgIcon.getWidth(); | |||
| for (int i=0; i<kPageCount; ++i) | |||
| { | |||
| bgIcon.setY(i*iconSize + i + 1); | |||
| bgIcon.setY(i*iconSize + i*3); | |||
| if (bgIcon.contains(ev.pos)) | |||
| { | |||
| @@ -180,19 +181,17 @@ protected: | |||
| const int width = ev.size.getWidth(); | |||
| const int height = ev.size.getHeight(); | |||
| bg.setSize(ev.size); | |||
| bgIcon.setWidth(width-4); | |||
| bgIcon.setHeight(width-4); | |||
| bgIcon.setWidth(width-2); | |||
| bgIcon.setHeight(width-2); | |||
| lineSep.setStartX(width+2); | |||
| lineSep.setEndPos(width+2, height); | |||
| lineSep.setStartPos(width, 0); | |||
| lineSep.setEndPos(width, height); | |||
| } | |||
| private: | |||
| Callback* const callback; | |||
| int curPage, curHover; | |||
| Rectangle<int> bg, bgIcon; | |||
| Rectangle<int> bgIcon; | |||
| Line<int> lineSep; | |||
| Image img1, img2, img3, img4, img5; | |||
| }; | |||
| @@ -318,6 +317,7 @@ public: | |||
| wText(*this), | |||
| wLeft(*this, this), | |||
| //wRezHandle(*this), | |||
| wPerf(*this, NanoPerfWidget::RENDER_FPS, "TESTING!!"), | |||
| curWidget(nullptr) | |||
| { | |||
| wColor.hide(); | |||
| @@ -325,13 +325,15 @@ public: | |||
| wRects.hide(); | |||
| wShapes.hide(); | |||
| wText.hide(); | |||
| //wPerf.hide(); | |||
| wColor.setAbsoluteX(80); | |||
| wImages.setAbsoluteX(80); | |||
| wRects.setAbsoluteX(80); | |||
| wShapes.setAbsoluteX(80); | |||
| wText.setAbsoluteX(80); | |||
| wColor.setAbsoluteX(81); | |||
| wImages.setAbsoluteX(81); | |||
| wRects.setAbsoluteX(81); | |||
| wShapes.setAbsoluteX(81); | |||
| wText.setAbsoluteX(81); | |||
| wLeft.setAbsolutePos(2, 2); | |||
| wPerf.setAbsoluteY(5); | |||
| setSize(600, 500); | |||
| setTitle("DGL Demo"); | |||
| @@ -341,17 +343,19 @@ public: | |||
| void onReshape(int width, int height) override | |||
| { | |||
| Size<int> size(width-80, height); | |||
| Size<int> size(width-81, height); | |||
| wColor.setSize(size); | |||
| wImages.setSize(size); | |||
| wRects.setSize(size); | |||
| wShapes.setSize(size); | |||
| wText.setSize(size); | |||
| wLeft.setSize(73, height-4); | |||
| wLeft.setSize(80-4, height-4); | |||
| //wRezHandle.setAbsoluteX(width-wRezHandle.getWidth()); | |||
| //wRezHandle.setAbsoluteY(height-wRezHandle.getHeight()); | |||
| wPerf.setAbsoluteX(width-wPerf.getWidth()-5); | |||
| Window::onReshape(width, height); | |||
| } | |||
| @@ -378,7 +382,6 @@ protected: | |||
| case 3: | |||
| curWidget = &wShapes; | |||
| break; | |||
| break; | |||
| case 4: | |||
| curWidget = &wText; | |||
| break; | |||
| @@ -396,6 +399,7 @@ private: | |||
| ExampleTextWidget wText; | |||
| LeftSideWidget wLeft; | |||
| //ResizeHandle wRezHandle; | |||
| NanoPerfWidget wPerf; | |||
| Widget* curWidget; | |||
| }; | |||
| @@ -22,70 +22,8 @@ | |||
| // ------------------------------------------------------ | |||
| // NanoVG Stuff | |||
| #include "NanoVG.hpp" | |||
| #include "widgets/NanoPerfWidget.hpp" | |||
| #include "nanovg_res/demo.h" | |||
| #include "nanovg_res/perf.h" | |||
| // ------------------------------------------------------ | |||
| // get time | |||
| #include <sys/time.h> | |||
| #include <time.h> | |||
| #ifdef DISTRHO_OS_WINDOWS | |||
| #else | |||
| struct TimePOSIX { | |||
| bool monotonic; | |||
| double resolution; | |||
| uint64_t base; | |||
| TimePOSIX() | |||
| : monotonic(false), | |||
| resolution(1e-6), | |||
| base(0) | |||
| { | |||
| #if defined(CLOCK_MONOTONIC) | |||
| struct timespec ts; | |||
| if (::clock_gettime(CLOCK_MONOTONIC, &ts) == 0) | |||
| { | |||
| monotonic = true; | |||
| resolution = 1e-9; | |||
| } | |||
| #endif | |||
| base = getRawTime(); | |||
| } | |||
| uint64_t getRawTime() | |||
| { | |||
| #if defined(CLOCK_MONOTONIC) | |||
| if (monotonic) | |||
| { | |||
| struct timespec ts; | |||
| ::clock_gettime(CLOCK_MONOTONIC, &ts); | |||
| return (uint64_t) ts.tv_sec * (uint64_t) 1000000000 + (uint64_t) ts.tv_nsec; | |||
| } | |||
| else | |||
| #endif | |||
| { | |||
| struct timeval tv; | |||
| ::gettimeofday(&tv, NULL); | |||
| return (uint64_t) tv.tv_sec * (uint64_t) 1000000 + (uint64_t) tv.tv_usec; | |||
| } | |||
| } | |||
| double getTime() | |||
| { | |||
| return (double)(getRawTime() - base) * resolution; | |||
| } | |||
| }; | |||
| static TimePOSIX gTime; | |||
| #endif | |||
| // ------------------------------------------------------ | |||
| // use namespace | |||
| @@ -102,8 +40,6 @@ int premult = 0; | |||
| int mx = 0; | |||
| int my = 0; | |||
| double prevt = 0; | |||
| class NanoExampleWidget : public NanoWidget, | |||
| public IdleCallback | |||
| { | |||
| @@ -114,11 +50,7 @@ public: | |||
| { | |||
| parent.addIdleCallback(this); | |||
| initGraph(&fPerf, GRAPH_RENDER_FPS, "Frame Time"); | |||
| loadDemoData(fContext, &fData); | |||
| prevt = gTime.getTime(); | |||
| } | |||
| ~NanoExampleWidget() override | |||
| @@ -143,13 +75,6 @@ protected: | |||
| const int winWidth = getWidth(); | |||
| const int winHeight = getHeight(); | |||
| double t, dt; | |||
| t = gTime.getTime(); | |||
| dt = t - prevt; | |||
| prevt = t; | |||
| updateGraph(&fPerf, dt); | |||
| if (premult) | |||
| glClearColor(0, 0, 0, 0); | |||
| else | |||
| @@ -157,8 +82,7 @@ protected: | |||
| glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); | |||
| renderDemo(fContext, mx, my, winWidth, winHeight, t, blowup, &fData); | |||
| renderGraph(fContext, 5, 5, &fPerf); | |||
| renderDemo(fContext, mx, my, winWidth, winHeight, gTime.getTime(), blowup, &fData); | |||
| if (screenshot) | |||
| { | |||
| @@ -204,7 +128,39 @@ protected: | |||
| private: | |||
| NVGcontext* fContext; | |||
| DemoData fData; | |||
| PerfGraph fPerf; | |||
| }; | |||
| // ----------------------------------------------------------------------- | |||
| // We need a custom window for multiple widgets | |||
| class NanoExampleWindow : public Window | |||
| { | |||
| public: | |||
| NanoExampleWindow(App& app) | |||
| : Window(app), | |||
| fDemo(*this), | |||
| fPerf(*this, NanoPerfWidget::RENDER_FPS, "Frame Time") | |||
| { | |||
| fPerf.setAbsolutePos(5, 5); | |||
| //fPerf.hide(); | |||
| setSize(1000, 600); | |||
| setTitle("NanoVG"); | |||
| } | |||
| protected: | |||
| void onReshape(int width, int height) | |||
| { | |||
| fDemo.setSize(width, height); | |||
| //fDemo.setAbsolutePos(10, height-fDemo.getHeight()-50); | |||
| Window::onReshape(width, height); | |||
| } | |||
| private: | |||
| NanoExampleWidget fDemo; | |||
| NanoPerfWidget fPerf; | |||
| }; | |||
| // ------------------------------------------------------ | |||
| @@ -212,12 +168,11 @@ private: | |||
| int main() | |||
| { | |||
| StandaloneWindow swin; | |||
| NanoExampleWidget widget(swin); | |||
| App app; | |||
| NanoExampleWindow win(app); | |||
| swin.setSize(1000, 600); | |||
| swin.setTitle("NanoVG"); | |||
| swin.exec(); | |||
| win.show(); | |||
| app.exec(); | |||
| return 0; | |||
| } | |||
| @@ -226,7 +181,6 @@ int main() | |||
| extern "C" { | |||
| #include "nanovg_res/demo.c" | |||
| #include "nanovg_res/perf.c" | |||
| } | |||
| // ------------------------------------------------------ | |||