Browse Source

Add very small text example

pull/1/head
falkTX 11 years ago
parent
commit
7a60520050
5 changed files with 127 additions and 5 deletions
  1. +1
    -0
      .gitignore
  2. +1
    -1
      dpf
  3. +7
    -4
      examples/Makefile
  4. +43
    -0
      examples/text.cpp
  5. +75
    -0
      examples/widgets/ExampleTextWidget.hpp

+ 1
- 0
.gitignore View File

@@ -17,3 +17,4 @@ examples/nanovg
examples/qt-embed examples/qt-embed
examples/rectangles examples/rectangles
examples/shapes examples/shapes
examples/text

+ 1
- 1
dpf

@@ -1 +1 @@
Subproject commit 8b29f3f3982ea931c65be1ad6a90c7fcea9d634d
Subproject commit af09cb0a1284337a2592d237caa9ac5a274ce059

+ 7
- 4
examples/Makefile View File

@@ -42,22 +42,25 @@ debug:
app: app.cpp ../dpf/dgl/* app: app.cpp ../dpf/dgl/*
$(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ $(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 $@ $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@


demo: demo.cpp widgets/* ../dpf/dgl/* demo: demo.cpp widgets/* ../dpf/dgl/*
$(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ $(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 $@ $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@


nanovg: nanovg.cpp nanovg_res/* ../dpf/dgl/* nanovg: nanovg.cpp nanovg_res/* ../dpf/dgl/*
$(CXX) $< $(BUILD_CXX_FLAGS) -I../dpf/dgl/src/nanovg $(LINK_FLAGS) -o $@ $(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 $@ $(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 $@ $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@


# -------------------------------------------------------------- # --------------------------------------------------------------


+ 43
- 0
examples/text.cpp View File

@@ -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 "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;
}

// ------------------------------------------------------

+ 75
- 0
examples/widgets/ExampleTextWidget.hpp View File

@@ -0,0 +1,75 @@
/*
* 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.
*/

#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

Loading…
Cancel
Save