From 7a60520050a63f3a62569c5ab3463ff562577d5d Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 24 May 2014 01:49:24 +0100 Subject: [PATCH] Add very small text example --- .gitignore | 1 + dpf | 2 +- examples/Makefile | 11 ++-- examples/text.cpp | 43 +++++++++++++++ examples/widgets/ExampleTextWidget.hpp | 75 ++++++++++++++++++++++++++ 5 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 examples/text.cpp create mode 100644 examples/widgets/ExampleTextWidget.hpp diff --git a/.gitignore b/.gitignore index 961698e..5b964a7 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ examples/nanovg examples/qt-embed examples/rectangles examples/shapes +examples/text diff --git a/dpf b/dpf index 8b29f3f..af09cb0 160000 --- a/dpf +++ b/dpf @@ -1 +1 @@ -Subproject commit 8b29f3f3982ea931c65be1ad6a90c7fcea9d634d +Subproject commit af09cb0a1284337a2592d237caa9ac5a274ce059 diff --git a/examples/Makefile b/examples/Makefile index 24ab3fc..dd0fabf 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -42,22 +42,25 @@ debug: app: app.cpp ../dpf/dgl/* $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ -color: color.cpp ../dpf/dgl/* +color: color.cpp widgets/ExampleColorWidget.hpp ../dpf/dgl/* $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ demo: demo.cpp widgets/* ../dpf/dgl/* $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ -images: images.cpp images_res/* ../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/* $(CXX) $< $(BUILD_CXX_FLAGS) -I../dpf/dgl/src/nanovg $(LINK_FLAGS) -o $@ -rectangles: rectangles.cpp ../dpf/dgl/* +rectangles: rectangles.cpp widgets/ExampleRectanglesWidget.hpp ../dpf/dgl/* $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ -shapes: shapes.cpp ../dpf/dgl/* +shapes: shapes.cpp widgets/ExampleShapesWidget.hpp ../dpf/dgl/* + $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ + +text: text.cpp widgets/ExampleTextWidget.hpp ../dpf/dgl/* $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ # -------------------------------------------------------------- diff --git a/examples/text.cpp b/examples/text.cpp new file mode 100644 index 0000000..14096df --- /dev/null +++ b/examples/text.cpp @@ -0,0 +1,43 @@ +/* + * DISTRHO Plugin Framework (DPF) + * Copyright (C) 2012-2014 Filipe Coelho + * + * 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 "StandaloneWindow.hpp" +#include "widgets/ExampleTextWidget.hpp" + +// ------------------------------------------------------ +// use namespace + +using DGL::StandaloneWindow; + +// ------------------------------------------------------ +// main entry point + +int main() +{ + StandaloneWindow swin; + ExampleTextWidget widget(swin); + + swin.setSize(500, 300); + swin.setTitle("Text"); + swin.exec(); + + return 0; +} + +// ------------------------------------------------------ diff --git a/examples/widgets/ExampleTextWidget.hpp b/examples/widgets/ExampleTextWidget.hpp new file mode 100644 index 0000000..79f3b64 --- /dev/null +++ b/examples/widgets/ExampleTextWidget.hpp @@ -0,0 +1,75 @@ +/* + * DISTRHO Plugin Framework (DPF) + * Copyright (C) 2012-2014 Filipe Coelho + * + * 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. + */ + +#ifndef EXAMPLE_TEXT_WIDGET_HPP_INCLUDED +#define EXAMPLE_TEXT_WIDGET_HPP_INCLUDED + +// ------------------------------------------------------ +// DGL Stuff + +#include "NanoWidget.hpp" + +// ------------------------------------------------------ +// use namespace + +using DGL::NanoWidget; +using DGL::Window; + +// ------------------------------------------------------ +// our widget + +class ExampleTextWidget : public NanoWidget +{ +public: + ExampleTextWidget(Window& parent) + : NanoWidget(parent), + fFont(createFont("sans", "./nanovg_res/Roboto-Regular.ttf")) + { + setSize(500, 300); + } + +protected: + void onDisplay() override + { + const int width = getWidth(); + const int height = getHeight(); + + beginFrame(); + save(); + + fontSize(40.0f); + textAlign(Align(ALIGN_CENTER|ALIGN_MIDDLE)); + textLineHeight(20.0f); + + beginPath(); + fillColor(RGBA(220,220,220,255)); + roundedRect(10, height/4+10, width-20, height/2-20, 3); + fill(); + + fillColor(RGBA(0,0,0,220)); + textBox(10, height/2, width-20, "Hello World!", nullptr); + + restore(); + endFrame(); + } + +private: + FontId fFont; +}; + +// ------------------------------------------------------ + +#endif // EXAMPLE_TEXT_WIDGET_HPP_INCLUDED