| @@ -0,0 +1,14 @@ | |||
| *.a | |||
| *.o | |||
| *.exe | |||
| *.dll | |||
| *.dylib | |||
| *.so | |||
| .kdev_include_paths | |||
| .kdev4/ | |||
| examples/app | |||
| examples/color | |||
| examples/images | |||
| @@ -0,0 +1,3 @@ | |||
| [submodule "dpf"] | |||
| path = dpf | |||
| url = git://github.com/DISTRHO/DPF | |||
| @@ -0,0 +1,13 @@ | |||
| DISTRHO Plugin Framework (DPF) | |||
| Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com> | |||
| Permission to use, copy, modify, and/or distribute this software for any purpose with | |||
| or without fee is hereby granted, provided that the above copyright notice and this | |||
| permission notice appear in all copies. | |||
| THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD | |||
| TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN | |||
| NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | |||
| DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER | |||
| IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |||
| CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |||
| @@ -0,0 +1,25 @@ | |||
| #!/usr/bin/make -f | |||
| # Makefile for DPF examples # | |||
| # ------------------------- # | |||
| # Created by falkTX | |||
| # | |||
| all: libs examples | |||
| # -------------------------------------------------------------- | |||
| libs: | |||
| $(MAKE) -C dpf/dgl | |||
| examples: libs | |||
| $(MAKE) build -C examples | |||
| # -------------------------------------------------------------- | |||
| clean: | |||
| $(MAKE) clean -C dpf/dgl | |||
| $(MAKE) clean -C dpf/examples | |||
| # -------------------------------------------------------------- | |||
| .PHONY: examples | |||
| @@ -0,0 +1 @@ | |||
| Subproject commit d17a8706cc9d0c4540eb6bb09dd3357f9e3a8437 | |||
| @@ -0,0 +1,68 @@ | |||
| #!/usr/bin/make -f | |||
| # Makefile for DPF examples # | |||
| # ------------------------- # | |||
| # Created by falkTX | |||
| # | |||
| include ../dpf/dgl/Makefile.mk | |||
| # -------------------------------------------------------------- | |||
| BUILD_CXX_FLAGS += -I../dpf/dgl | |||
| LINK_FLAGS += -L../dpf -ldgl $(DGL_LIBS) | |||
| # -------------------------------------------------------------- | |||
| ifeq ($(WIN32),true) | |||
| TARGETS = app.exe color.exe images.exe | |||
| else | |||
| TARGETS = app color images | |||
| endif | |||
| # -------------------------------------------------------------- | |||
| all: ../libdgl.a $(TARGETS) | |||
| build: $(TARGETS) | |||
| clean: | |||
| $(MAKE) -C ../dgl clean | |||
| $(RM) $(TARGETS) | |||
| debug: | |||
| $(MAKE) DEBUG=true | |||
| # -------------------------------------------------------------- | |||
| %.exe: % | |||
| rm -f $*.exe | |||
| mv $* $*.exe | |||
| ln -sf $*.exe $* | |||
| ../libdgl.a: .FORCE | |||
| $(MAKE) -C ../dpf/dgl | |||
| # -------------------------------------------------------------- | |||
| app: app.cpp ../dpf/dgl/* | |||
| $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ | |||
| color: color.cpp ../dpf/dgl/* | |||
| $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ | |||
| images: images.cpp images_src/* ../dpf/dgl/* | |||
| $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ | |||
| # -------------------------------------------------------------- | |||
| cairo: cairo.cpp ../dgl/* | |||
| $(CXX) $< $(BUILD_CXX_FLAGS) $(shell pkg-config --cflags --libs cairo) $(LINK_FLAGS) -o $@ | |||
| text: text.cpp ../dgl/* | |||
| $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ | |||
| # -------------------------------------------------------------- | |||
| .FORCE: | |||
| .PHONY: .FORCE | |||
| # -------------------------------------------------------------- | |||
| @@ -0,0 +1,43 @@ | |||
| /* | |||
| * DISTRHO Plugin Framework (DPF) | |||
| * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com> | |||
| * | |||
| * Permission to use, copy, modify, and/or distribute this software for any purpose with | |||
| * or without fee is hereby granted, provided that the above copyright notice and this | |||
| * permission notice appear in all copies. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD | |||
| * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN | |||
| * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | |||
| * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER | |||
| * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |||
| * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |||
| */ | |||
| // ------------------------------------------------------ | |||
| // DGL Stuff | |||
| #include "App.hpp" | |||
| #include "Window.hpp" | |||
| // ------------------------------------------------------ | |||
| // use namespace | |||
| using namespace DGL; | |||
| // ------------------------------------------------------ | |||
| // main entry point | |||
| int main() | |||
| { | |||
| App app; | |||
| Window win(app); | |||
| win.setTitle("App"); | |||
| win.show(); | |||
| app.exec(); | |||
| return 0; | |||
| } | |||
| // ------------------------------------------------------ | |||
| @@ -0,0 +1,149 @@ | |||
| /* | |||
| * DISTRHO Plugin Framework (DPF) | |||
| * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com> | |||
| * | |||
| * Permission to use, copy, modify, and/or distribute this software for any purpose with | |||
| * or without fee is hereby granted, provided that the above copyright notice and this | |||
| * permission notice appear in all copies. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD | |||
| * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN | |||
| * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | |||
| * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER | |||
| * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |||
| * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |||
| */ | |||
| // ------------------------------------------------------ | |||
| // DGL Stuff | |||
| #include "App.hpp" | |||
| #include "Window.hpp" | |||
| #include "Widget.hpp" | |||
| // ------------------------------------------------------ | |||
| // use namespace | |||
| using namespace DGL; | |||
| // ------------------------------------------------------ | |||
| // Single color widget | |||
| class ColorWidget : public Widget, | |||
| public IdleCallback | |||
| { | |||
| public: | |||
| ColorWidget(Window& parent) | |||
| : Widget(parent), | |||
| cur('r'), | |||
| reverse(false), | |||
| r(0), g(0), b(0) | |||
| { | |||
| parent.addIdleCallback(this); | |||
| } | |||
| private: | |||
| void idleCallback() override | |||
| { | |||
| switch (cur) | |||
| { | |||
| case 'r': | |||
| if (reverse) | |||
| { | |||
| if (--r == 0) | |||
| cur = 'g'; | |||
| } | |||
| else | |||
| { | |||
| if (++r == 100) | |||
| cur = 'g'; | |||
| } | |||
| break; | |||
| case 'g': | |||
| if (reverse) | |||
| { | |||
| if (--g == 0) | |||
| cur = 'b'; | |||
| } | |||
| else | |||
| { | |||
| if (++g == 100) | |||
| cur = 'b'; | |||
| } | |||
| break; | |||
| case 'b': | |||
| if (reverse) | |||
| { | |||
| if (--b == 0) | |||
| { | |||
| cur = 'r'; | |||
| reverse = false; | |||
| } | |||
| } | |||
| else | |||
| { | |||
| if (++b == 100) | |||
| { | |||
| cur = 'r'; | |||
| reverse = true; | |||
| } | |||
| } | |||
| break; | |||
| } | |||
| repaint(); | |||
| } | |||
| void onDisplay() override | |||
| { | |||
| // paint bg color (in full size) | |||
| glColor3b(r, g, b); | |||
| bgFull.draw(); | |||
| // paint inverted color (in 2/3 size) | |||
| glColor3b(100-r, 100-g, 100-b); | |||
| bgSmall.draw(); | |||
| } | |||
| void onReshape(int width, int height) override | |||
| { | |||
| // full bg | |||
| bgFull = Rectangle<int>(0, 0, width, height); | |||
| // small bg, centered 2/3 size | |||
| bgSmall = Rectangle<int>(width/6, height/6, width*2/3, height*2/3); | |||
| // make widget same size as window | |||
| setSize(width, height); | |||
| // default reshape implementation | |||
| Widget::onReshape(width, height); | |||
| } | |||
| char cur; | |||
| bool reverse; | |||
| int r, g, b; | |||
| Rectangle<int> bgFull, bgSmall; | |||
| }; | |||
| // ------------------------------------------------------ | |||
| // main entry point | |||
| int main() | |||
| { | |||
| App app; | |||
| Window win(app); | |||
| ColorWidget color(win); | |||
| win.setSize(300, 300); | |||
| win.setTitle("Color"); | |||
| win.show(); | |||
| app.exec(); | |||
| return 0; | |||
| } | |||
| // ------------------------------------------------------ | |||
| @@ -0,0 +1,213 @@ | |||
| /* | |||
| * DISTRHO Plugin Framework (DPF) | |||
| * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com> | |||
| * | |||
| * Permission to use, copy, modify, and/or distribute this software for any purpose with | |||
| * or without fee is hereby granted, provided that the above copyright notice and this | |||
| * permission notice appear in all copies. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD | |||
| * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN | |||
| * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | |||
| * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER | |||
| * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |||
| * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |||
| */ | |||
| // ------------------------------------------------------ | |||
| // Pics | |||
| #include "dgl-images_src/CatPics.cpp" | |||
| // ------------------------------------------------------ | |||
| // DGL Stuff | |||
| #include "Image.hpp" | |||
| #include "Widget.hpp" | |||
| #include "StandaloneWindow.hpp" | |||
| // ------------------------------------------------------ | |||
| // use namespace | |||
| using namespace DGL; | |||
| // ------------------------------------------------------ | |||
| // our widget | |||
| class ExampleImagesWidget : public Widget, | |||
| public IdleCallback | |||
| { | |||
| public: | |||
| static const int kImg1y = 0; | |||
| static const int kImg2y = 500/2-CatPics::cat2Height/2; | |||
| static const int kImg3x = 400/3-CatPics::cat3Width/3; | |||
| static const int kImg1max = 500-CatPics::cat1Width; | |||
| static const int kImg2max = 500-CatPics::cat2Width; | |||
| static const int kImg3max = 400-CatPics::cat3Height; | |||
| ExampleImagesWidget(Window& win) | |||
| : Widget(win), | |||
| fImgTop1st(1), | |||
| fImgTop2nd(2), | |||
| fImgTop3rd(3), | |||
| fImg1x(0), | |||
| fImg2x(kImg2max), | |||
| fImg3y(kImg3max), | |||
| fImg1rev(false), | |||
| fImg2rev(true), | |||
| fImg3rev(true), | |||
| fImg1(CatPics::cat1Data, CatPics::cat1Width, CatPics::cat1Height, GL_BGR), | |||
| fImg2(CatPics::cat2Data, CatPics::cat2Width, CatPics::cat2Height, GL_BGR), | |||
| fImg3(CatPics::cat3Data, CatPics::cat3Width, CatPics::cat3Height, GL_BGR) | |||
| { | |||
| win.addIdleCallback(this); | |||
| } | |||
| private: | |||
| void idleCallback() override | |||
| { | |||
| if (fImg1rev) | |||
| { | |||
| fImg1x -= 2; | |||
| if (fImg1x <= -50) | |||
| { | |||
| fImg1rev = false; | |||
| setNewTopImg(1); | |||
| } | |||
| } | |||
| else | |||
| { | |||
| fImg1x += 2; | |||
| if (fImg1x >= kImg1max+50) | |||
| { | |||
| fImg1rev = true; | |||
| setNewTopImg(1); | |||
| } | |||
| } | |||
| if (fImg2rev) | |||
| { | |||
| fImg2x -= 1; | |||
| if (fImg2x <= -50) | |||
| { | |||
| fImg2rev = false; | |||
| setNewTopImg(2); | |||
| } | |||
| } | |||
| else | |||
| { | |||
| fImg2x += 4; | |||
| if (fImg2x >= kImg2max+50) | |||
| { | |||
| fImg2rev = true; | |||
| setNewTopImg(2); | |||
| } | |||
| } | |||
| if (fImg3rev) | |||
| { | |||
| fImg3y -= 3; | |||
| if (fImg3y <= -50) | |||
| { | |||
| fImg3rev = false; | |||
| setNewTopImg(3); | |||
| } | |||
| } | |||
| else | |||
| { | |||
| fImg3y += 3; | |||
| if (fImg3y >= kImg3max+50) | |||
| { | |||
| fImg3rev = true; | |||
| setNewTopImg(3); | |||
| } | |||
| } | |||
| repaint(); | |||
| } | |||
| void onDisplay() override | |||
| { | |||
| switch (fImgTop3rd) | |||
| { | |||
| case 1: | |||
| fImg1.drawAt(fImg1x, kImg1y); | |||
| break; | |||
| case 2: | |||
| fImg2.drawAt(fImg2x, kImg2y); | |||
| break; | |||
| case 3: | |||
| fImg3.drawAt(kImg3x, fImg3y); | |||
| break; | |||
| }; | |||
| switch (fImgTop2nd) | |||
| { | |||
| case 1: | |||
| fImg1.drawAt(fImg1x, kImg1y); | |||
| break; | |||
| case 2: | |||
| fImg2.drawAt(fImg2x, kImg2y); | |||
| break; | |||
| case 3: | |||
| fImg3.drawAt(kImg3x, fImg3y); | |||
| break; | |||
| }; | |||
| switch (fImgTop1st) | |||
| { | |||
| case 1: | |||
| fImg1.drawAt(fImg1x, kImg1y); | |||
| break; | |||
| case 2: | |||
| fImg2.drawAt(fImg2x, kImg2y); | |||
| break; | |||
| case 3: | |||
| fImg3.drawAt(kImg3x, fImg3y); | |||
| break; | |||
| }; | |||
| } | |||
| void setNewTopImg(const int imgId) | |||
| { | |||
| if (fImgTop1st == imgId) | |||
| return; | |||
| if (fImgTop2nd == imgId) | |||
| { | |||
| fImgTop2nd = fImgTop1st; | |||
| fImgTop1st = imgId; | |||
| return; | |||
| } | |||
| fImgTop3rd = fImgTop2nd; | |||
| fImgTop2nd = fImgTop1st; | |||
| fImgTop1st = imgId; | |||
| } | |||
| int fImgTop1st, fImgTop2nd, fImgTop3rd; | |||
| int fImg1x, fImg2x, fImg3y; | |||
| bool fImg1rev, fImg2rev, fImg3rev; | |||
| Image fImg1, fImg2, fImg3; | |||
| }; | |||
| // ------------------------------------------------------ | |||
| // main entry point | |||
| int main() | |||
| { | |||
| App app; | |||
| Window win(app); | |||
| ExampleImagesWidget images(win); | |||
| win.setResizable(false); | |||
| win.setSize(500, 400); | |||
| win.setTitle("Images"); | |||
| win.show(); | |||
| app.exec(); | |||
| return 0; | |||
| } | |||
| // ------------------------------------------------------ | |||
| @@ -0,0 +1,3 @@ | |||
| cat1.png: http://www.flickr.com/photos/tomitapio/4305303148/ | |||
| cat2.png: http://www.flickr.com/photos/aigle_dore/6672148713/ | |||
| cat3.png: http://www.flickr.com/photos/aigle_dore/5889008066/ | |||
| @@ -0,0 +1,25 @@ | |||
| /* (Auto-generated binary data file). */ | |||
| #ifndef BINARY_CATPICS_HPP | |||
| #define BINARY_CATPICS_HPP | |||
| namespace CatPics | |||
| { | |||
| extern const char* cat1Data; | |||
| const unsigned int cat1DataSize = 216090; | |||
| const unsigned int cat1Width = 294; | |||
| const unsigned int cat1Height = 245; | |||
| extern const char* cat2Data; | |||
| const unsigned int cat2DataSize = 117600; | |||
| const unsigned int cat2Width = 245; | |||
| const unsigned int cat2Height = 160; | |||
| extern const char* cat3Data; | |||
| const unsigned int cat3DataSize = 111600; | |||
| const unsigned int cat3Width = 248; | |||
| const unsigned int cat3Height = 150; | |||
| } | |||
| #endif // BINARY_CATPICS_HPP | |||
| @@ -0,0 +1,213 @@ | |||
| /* | |||
| * DISTRHO Plugin Framework (DPF) | |||
| * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com> | |||
| * | |||
| * Permission to use, copy, modify, and/or distribute this software for any purpose with | |||
| * or without fee is hereby granted, provided that the above copyright notice and this | |||
| * permission notice appear in all copies. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD | |||
| * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN | |||
| * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | |||
| * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER | |||
| * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |||
| * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |||
| */ | |||
| // ------------------------------------------------------ | |||
| // DGL Stuff | |||
| #include "App.hpp" | |||
| #include "CairoWidget.hpp" | |||
| #include "Window.hpp" | |||
| #include <cstdio> | |||
| // ------------------------------------------------------ | |||
| // use namespace | |||
| using namespace DGL; | |||
| // ------------------------------------------------------ | |||
| // Background widget (cairo will be painted on top) | |||
| class BackgroundWidget : public Widget | |||
| { | |||
| public: | |||
| BackgroundWidget(Window& parent) | |||
| : Widget(parent) | |||
| { | |||
| } | |||
| private: | |||
| void onDisplay() override | |||
| { | |||
| int x = 0; | |||
| int y = 0; | |||
| int width = getWidth(); | |||
| int height = getHeight(); | |||
| // paint bg color (in full size) | |||
| glColor3b(20, 80, 20); | |||
| glBegin(GL_QUADS); | |||
| glTexCoord2f(0.0f, 0.0f); | |||
| glVertex2i(x, y); | |||
| glTexCoord2f(1.0f, 0.0f); | |||
| glVertex2i(x+width, y); | |||
| glTexCoord2f(1.0f, 1.0f); | |||
| glVertex2i(x+width, y+height); | |||
| glTexCoord2f(0.0f, 1.0f); | |||
| glVertex2i(x, y+height); | |||
| glEnd(); | |||
| } | |||
| void onReshape(int width, int height) override | |||
| { | |||
| // make this widget same size as window | |||
| setSize(width, height); | |||
| Widget::onReshape(width, height); | |||
| } | |||
| }; | |||
| // ------------------------------------------------------ | |||
| // Custom Cairo Widget | |||
| class CustomCairoWidget : public CairoWidget, | |||
| public IdleCallback | |||
| { | |||
| public: | |||
| CustomCairoWidget(Window& parent) | |||
| : CairoWidget(parent), | |||
| value(0.0f), | |||
| pressed(false) | |||
| { | |||
| setSize(100, 100); | |||
| } | |||
| private: | |||
| void idleCallback() override | |||
| { | |||
| value += 0.001f; | |||
| if (value > 1.0f) | |||
| value = 0; | |||
| repaint(); | |||
| } | |||
| void cairoDisplay(cairo_t* const context) override | |||
| { | |||
| const int w = getWidth(); | |||
| const int h = getHeight(); | |||
| float radius = 40.0f; | |||
| // * 0.9 for line width to remain inside redraw area | |||
| if (w > h) | |||
| radius = (h / 2.0f)*0.9f; | |||
| else | |||
| radius = (w / 2.0f)*0.9f; | |||
| cairo_save(context); | |||
| cairo_rectangle(context, 0, 0, w, h ); | |||
| cairo_set_source_rgba(context, 1.1, 0.1, 0.1, 0 ); | |||
| cairo_fill(context); | |||
| cairo_set_line_join(context, CAIRO_LINE_JOIN_ROUND); | |||
| cairo_set_line_cap(context, CAIRO_LINE_CAP_ROUND); | |||
| cairo_set_line_width(context, 5-0.2); | |||
| cairo_move_to(context, w/2, h/2); | |||
| cairo_line_to(context, w/2, h/2); | |||
| cairo_set_source_rgba(context, 0.1, 0.1, 0.1, 0 ); | |||
| cairo_stroke(context); | |||
| cairo_arc(context, w/2, h/2, radius, 2.46, 0.75 ); | |||
| cairo_set_source_rgb(context, 0.1, 0.1, 0.1 ); | |||
| cairo_stroke(context); | |||
| float angle = 2.46 + ( 4.54 * value ); | |||
| cairo_set_line_width(context, 5); | |||
| cairo_arc(context, w/2, h/2, radius, 2.46, angle ); | |||
| cairo_line_to(context, w/2, h/2); | |||
| cairo_set_source_rgba(context, 1.0, 0.48, 0, 0.8); | |||
| cairo_stroke(context); | |||
| cairo_restore(context); | |||
| } | |||
| bool onMouse(int button, bool press, int x, int y) | |||
| { | |||
| if (button == 1) | |||
| { | |||
| pressed = press; | |||
| if (press) | |||
| { | |||
| setX(x-100/2); | |||
| setY(y-100/2); | |||
| } | |||
| return true; | |||
| } | |||
| return false; | |||
| } | |||
| bool onMotion(int x, int y) | |||
| { | |||
| if (pressed) | |||
| { | |||
| setX(x-100/2); | |||
| setY(y-100/2); | |||
| return true; | |||
| } | |||
| return false; | |||
| } | |||
| float value; | |||
| bool pressed; | |||
| }; | |||
| // ------------------------------------------------------ | |||
| // Custom window, with bg + cairo + image | |||
| class CustomWindow : public Window | |||
| { | |||
| public: | |||
| CustomWindow(App& app) | |||
| : Window(app), | |||
| bg(*this), | |||
| cairo(*this) | |||
| { | |||
| addIdleCallback(&cairo); | |||
| } | |||
| private: | |||
| BackgroundWidget bg; | |||
| CustomCairoWidget cairo; | |||
| }; | |||
| // ------------------------------------------------------ | |||
| // main entry point | |||
| int main() | |||
| { | |||
| App app; | |||
| CustomWindow win(app); | |||
| win.setSize(300, 300); | |||
| win.setTitle("Cairo"); | |||
| win.show(); | |||
| app.exec(); | |||
| return 0; | |||
| } | |||
| // ------------------------------------------------------ | |||
| @@ -0,0 +1,208 @@ | |||
| /* | |||
| * DISTRHO Plugin Framework (DPF) | |||
| * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com> | |||
| * | |||
| * Permission to use, copy, modify, and/or distribute this software for any purpose with | |||
| * or without fee is hereby granted, provided that the above copyright notice and this | |||
| * permission notice appear in all copies. | |||
| * | |||
| * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD | |||
| * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN | |||
| * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | |||
| * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER | |||
| * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |||
| * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |||
| */ | |||
| // ------------------------------------------------------ | |||
| // DGL Stuff | |||
| #define GL_GLEXT_PROTOTYPES | |||
| #include "App.hpp" | |||
| #include "Window.hpp" | |||
| #include "Widget.hpp" | |||
| #include "src/freetype-gl/text-buffer.h" | |||
| #include "src/freetype-gl/mat4.h" | |||
| #include <GL/glext.h> | |||
| #include <cstdio> | |||
| #include <cwchar> | |||
| // ------------------------------------------------------ | |||
| extern "C" { | |||
| int z_verbose = 0; | |||
| void z_error (char* message) | |||
| { | |||
| d_stderr2(message); | |||
| } | |||
| } | |||
| // ------------------------------------------------------ | |||
| // use namespace | |||
| using namespace DGL; | |||
| // ------------------------------------------------------ | |||
| // Single color widget | |||
| class TextWidget : public Widget | |||
| { | |||
| public: | |||
| TextWidget(Window& parent) | |||
| : Widget(parent), | |||
| #if 1 | |||
| atlas(nullptr), | |||
| fontmgr(nullptr), | |||
| font(nullptr), | |||
| #endif | |||
| textbuf(nullptr) | |||
| { | |||
| vec2 pen = {{20, 200}}; | |||
| vec4 black = {{0.0, 0.0, 0.0, 1.0}}; | |||
| vec4 white = {{1.0, 1.0, 1.0, 1.0}}; | |||
| vec4 none = {{1.0, 1.0, 1.0, 0.0}}; | |||
| markup_t markup = { | |||
| "normal", | |||
| 24.0f, 0, 0, | |||
| 0.0, 0.0, 2.0f, | |||
| white, none, | |||
| 0, white, | |||
| 0, white, | |||
| 0, white, | |||
| 0, white, | |||
| 0 | |||
| }; | |||
| wchar_t* text = L"A Quick Brown Fox Jumps Over The Lazy Dog 0123456789"; | |||
| #if 1 | |||
| atlas = texture_atlas_new(600, 300, 1); | |||
| DISTRHO_SAFE_ASSERT_RETURN(atlas != nullptr,); | |||
| //fontmgr = font_manager_new(600, 200, 2); | |||
| //DISTRHO_SAFE_ASSERT_RETURN(fontmgr != nullptr,); | |||
| //font = font_manager_get_from_filename(fontmgr, "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", 12.0f); | |||
| //DISTRHO_SAFE_ASSERT_RETURN(font != nullptr,); | |||
| font = texture_font_new_from_file(atlas, 12.0f, "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf"); | |||
| DISTRHO_SAFE_ASSERT_RETURN(font != nullptr,); | |||
| #endif | |||
| textbuf = text_buffer_new(LCD_FILTERING_OFF); | |||
| DISTRHO_SAFE_ASSERT_RETURN(textbuf != nullptr,); | |||
| textbuf->base_color = black; | |||
| //markup.family = "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf"; | |||
| markup.font = font; | |||
| text_buffer_printf(textbuf, &pen, | |||
| &markup, text, nullptr); | |||
| text_buffer_add_text(textbuf, &pen, &markup, text, std::wcslen(text)); | |||
| mat4_set_identity(&projection); | |||
| mat4_set_identity(&model); | |||
| mat4_set_identity(&view); | |||
| } | |||
| ~TextWidget() | |||
| { | |||
| if (textbuf != nullptr) | |||
| { | |||
| text_buffer_delete(textbuf); | |||
| textbuf = nullptr; | |||
| } | |||
| #if 1 | |||
| if (font != nullptr) | |||
| { | |||
| texture_font_delete(font); | |||
| font = nullptr; | |||
| } | |||
| if (fontmgr != nullptr) | |||
| { | |||
| font_manager_delete(fontmgr); | |||
| fontmgr = nullptr; | |||
| } | |||
| if (atlas != nullptr) | |||
| { | |||
| texture_atlas_delete(atlas); | |||
| atlas = nullptr; | |||
| } | |||
| #endif | |||
| } | |||
| private: | |||
| void onDisplay() override | |||
| { | |||
| DISTRHO_SAFE_ASSERT_RETURN(textbuf != nullptr,); | |||
| glClearColor(0.4f, 0.4f, 0.45f, 1.0f); | |||
| glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||
| glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | |||
| glUseProgram(textbuf->shader); | |||
| { | |||
| glUniformMatrix4fv(glGetUniformLocation(textbuf->shader, "model"), 1, 0, model.data); | |||
| glUniformMatrix4fv(glGetUniformLocation(textbuf->shader, "view"), 1, 0, view.data); | |||
| glUniformMatrix4fv(glGetUniformLocation(textbuf->shader, "projection"), 1, 0, projection.data); | |||
| text_buffer_render(textbuf); | |||
| } | |||
| } | |||
| void onReshape(int width, int height) override | |||
| { | |||
| // make widget same size as window | |||
| setSize(width, height); | |||
| //Widget::onReshape(width, height); | |||
| //mat4_set_identity(&projection); | |||
| //mat4_set_identity(&model); | |||
| //mat4_set_identity(&view); | |||
| glViewport(0, 0, width, height); | |||
| //mat4_set_orthographic(&projection, 0, width, 0, height, width, height); | |||
| mat4_set_orthographic(&projection, 0, width, 0, height, -1, 1); | |||
| } | |||
| texture_atlas_t* atlas; | |||
| font_manager_t* fontmgr; | |||
| texture_font_t* font; | |||
| text_buffer_t* textbuf; | |||
| mat4 model, view, projection; | |||
| }; | |||
| // ------------------------------------------------------ | |||
| // main entry point | |||
| int main() | |||
| { | |||
| App app; | |||
| Window win(app); | |||
| TextWidget color(win); | |||
| win.setSize(600, 300); | |||
| win.setTitle("Text"); | |||
| win.show(); | |||
| app.exec(); | |||
| return 0; | |||
| } | |||
| // ------------------------------------------------------ | |||