Browse Source

blendish example now draws 2 subwidgets; Add demo-subwidgets

pull/1/head
falkTX 10 years ago
parent
commit
eb72a8f370
12 changed files with 1589 additions and 8 deletions
  1. +4
    -0
      .gitignore
  2. +1
    -1
      dpf
  3. +7
    -3
      examples/Makefile
  4. +140
    -4
      examples/blendish.cpp
  5. BIN
      examples/blendish_res/DejaVuSans.ttf
  6. BIN
      examples/blendish_res/blender_icons16.png
  7. +1310
    -0
      examples/blendish_res/example.c
  8. +94
    -0
      examples/demo-subwidgets.cpp
  9. +11
    -0
      examples/widgets/ExampleColorWidget.hpp
  10. +9
    -0
      examples/widgets/ExampleRectanglesWidget.hpp
  11. +6
    -0
      examples/widgets/ExampleShapesWidget.hpp
  12. +7
    -0
      examples/widgets/ExampleTextWidget.hpp

+ 4
- 0
.gitignore View File

@@ -1,18 +1,22 @@
*.a
*.d
*.o

*.exe
*.dll
*.dylib
*.so
*.zip

.kdev_include_paths
*.kdev4

examples/app
examples/blendish
examples/color
examples/demo
examples/demo-multi
examples/demo-subwidgets
examples/file-browser
examples/images
examples/nanovg


+ 1
- 1
dpf

@@ -1 +1 @@
Subproject commit 3a77a1144f4cb53ded4fb9194eded380bdfa9316
Subproject commit c6789d1889cfdb9fef784f19ab452ff70723ffc2

+ 7
- 3
examples/Makefile View File

@@ -8,7 +8,7 @@ include ../dpf/dgl/Makefile.mk

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

BUILD_CXX_FLAGS += -I../dpf/dgl
BUILD_CXX_FLAGS += -I../dpf/distrho -I../dpf/dgl
LINK_FLAGS += -L../dpf -ldgl $(DGL_LIBS)

WINDRES ?= windres
@@ -16,9 +16,10 @@ WINDRES ?= windres
# --------------------------------------------------------------

ifeq ($(WIN32),true)
TARGETS = app.exe color.exe demo.exe demo-multi images.exe nanovg.exe rectangles.exe shapes.exe text.exe
TARGETS = app.exe color.exe demo.exe demo-multi demo-subwidgets,exe images.exe nanovg.exe rectangles.exe shapes.exe text.exe
else
TARGETS = app blendish color demo demo-multi images nanovg nanovg2 rectangles shapes text
TARGETS = app blendish color demo demo-multi demo-subwidgets images nanovg nanovg2 rectangles shapes text
# TARGETS = blendish demo-subwidgets
endif

# --------------------------------------------------------------
@@ -54,6 +55,9 @@ demo: demo.cpp widgets/* ../dpf/dgl/*
demo-multi: demo-multi.cpp widgets/* ../dpf/dgl/*
$(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@

demo-subwidgets: demo-subwidgets.cpp widgets/* ../dpf/dgl/*
$(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@

images: images.cpp widgets/ExampleImagesWidget.hpp images_res/* ../dpf/dgl/*
$(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@



+ 140
- 4
examples/blendish.cpp View File

@@ -18,14 +18,138 @@
// DGL Stuff

#include "NanoVG.hpp"
#include "Widget.hpp"
#include "StandaloneWindow.hpp"

#include "extra/ScopedPointer.hpp"

#include "src/nanovg/nanovg.h"
#include "src/oui-blendish/blendish.h"

// ------------------------------------------------------
// use namespace

using DGL::NanoWidget;
using DGL::StandaloneWindow;
using DGL::Window;
USE_NAMESPACE_DISTRHO;
USE_NAMESPACE_DGL;

// ------------------------------------------------------
// Test

class BlenderOption : public NanoWidget
{
public:
BlenderOption(NanoWidget* groupWidget)
: NanoWidget(groupWidget),
state(BND_DEFAULT),
area(10, 10, 200, BND_WIDGET_HEIGHT) {}

protected:
bool onMouse(const MouseEvent& e)
{
if (! e.press)
return false;
if (! area.contains(e.pos))
return false;

if (state == BND_ACTIVE)
state = BND_HOVER;
else
state = BND_ACTIVE;

repaint();
return true;
}

bool onMotion(const MotionEvent& e)
{
if (! area.contains(e.pos))
{
if (state == BND_HOVER)
{
state = BND_DEFAULT;
repaint();
return true;
}

return false;
}

if (state == BND_DEFAULT)
{
state = BND_HOVER;
repaint();
}

return true;
}

void onNanoDisplay() override
{
bndOptionButton(getContext(), 10, 10, 200, BND_WIDGET_HEIGHT, state, "checkbox whoohoo!");
}

private:
BNDwidgetState state;
Rectangle<int> area;
};

class BlenderRadioBox : public NanoWidget
{
public:
BlenderRadioBox(NanoWidget* groupWidget)
: NanoWidget(groupWidget),
state(BND_DEFAULT),
area(10, 40, 200, BND_WIDGET_HEIGHT) {}

protected:
bool onMouse(const MouseEvent& e)
{
if (! e.press)
return false;
if (! area.contains(e.pos))
return false;

if (state == BND_ACTIVE)
state = BND_HOVER;
else
state = BND_ACTIVE;

repaint();
return true;
}

bool onMotion(const MotionEvent& e)
{
if (! area.contains(e.pos))
{
if (state == BND_HOVER)
{
state = BND_DEFAULT;
repaint();
return true;
}

return false;
}

if (state == BND_DEFAULT)
{
state = BND_HOVER;
repaint();
}

return true;
}

void onNanoDisplay() override
{
bndRadioButton(getContext(), 10, 40, 200, BND_WIDGET_HEIGHT, 0, state, BND_ICON_NONE, "radio blender style yeah");
}

private:
BNDwidgetState state;
Rectangle<int> area;
};

// ------------------------------------------------------
// Test
@@ -34,14 +158,26 @@ class TestWidget : public NanoWidget
{
public:
TestWidget(Window& parent)
: NanoWidget(parent)
: NanoWidget(parent, NanoVG::CREATE_ANTIALIAS|NanoVG::CREATE_STENCIL_STROKES),
opt(this),
rb(this)
{
NVGcontext* const context(getContext());

bndSetFont(nvgCreateFont(context, "system", "./blendish_res/DejaVuSans.ttf"));
bndSetIconImage(nvgCreateImage(context, "./blendish_res/blender_icons16.png", 0));
}

protected:
void onNanoDisplay() override
{
glClearColor(0.3f, 0.3f, 0.32f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
}

private:
BlenderOption opt;
BlenderRadioBox rb;
};

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


BIN
examples/blendish_res/DejaVuSans.ttf View File


BIN
examples/blendish_res/blender_icons16.png View File

Before After
Width: 602  |  Height: 640  |  Size: 245KB

+ 1310
- 0
examples/blendish_res/example.c
File diff suppressed because it is too large
View File


+ 94
- 0
examples/demo-subwidgets.cpp View File

@@ -0,0 +1,94 @@
/*
* 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/ExampleColorWidget.hpp"
#include "widgets/ExampleRectanglesWidget.hpp"
#include "widgets/ExampleShapesWidget.hpp"
#include "widgets/ExampleTextWidget.hpp"

// ------------------------------------------------------
// use namespace

using DGL::Size;
using DGL::StandaloneWindow;
using DGL::Widget;
using DGL::Window;

// ------------------------------------------------------
// SubWidgets

class SubWidgets : public Widget
{
public:
SubWidgets(Window& parent)
: Widget(parent),
wColor(this),
wRects(this),
wShapes(this),
wText(this)
{
}

protected:
void onDisplay() override
{
}

void onResize(const ResizeEvent& e) override
{
const uint w = e.size.getWidth()/2;
const uint h = e.size.getHeight()/2;

wColor.setAbsolutePos(0, 0);
wColor.setSize(w, h);

wRects.setAbsolutePos(w, 0);
wRects.setSize(w, h);

wShapes.setAbsolutePos(0, h);
wShapes.setSize(w, h);

wText.setAbsolutePos(w, h);
wText.setSize(w, h);
}

private:
ExampleColorWidget wColor;
ExampleRectanglesWidget wRects;
ExampleShapesWidget wShapes;
ExampleTextWidget wText;
};

// ------------------------------------------------------
// main entry point

int main()
{
StandaloneWindow swin;
SubWidgets swid(swin);

swin.setSize(600, 600);
swin.setTitle("SubWidgets");
swin.exec();

return 0;
}

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

+ 11
- 0
examples/widgets/ExampleColorWidget.hpp View File

@@ -49,6 +49,17 @@ public:
parent.addIdleCallback(this);
}

ExampleColorWidget(Widget* groupWidget)
: Widget(groupWidget),
cur('r'),
reverse(false),
r(0), g(0), b(0)
{
setSize(300, 300);

groupWidget->getParentWindow().addIdleCallback(this);
}

protected:
void idleCallback() noexcept override
{


+ 9
- 0
examples/widgets/ExampleRectanglesWidget.hpp View File

@@ -45,6 +45,15 @@ public:
fClicked[i] = false;
}

ExampleRectanglesWidget(Widget* groupWidget)
: Widget(groupWidget)
{
setSize(300, 300);

for (int i=0; i<9; ++i)
fClicked[i] = false;
}

protected:
void onDisplay() override
{


+ 6
- 0
examples/widgets/ExampleShapesWidget.hpp View File

@@ -44,6 +44,12 @@ public:
setSize(300, 300);
}

ExampleShapesWidget(Widget* groupWidget)
: Widget(groupWidget)
{
setSize(300, 300);
}

protected:
void onDisplay() override
{


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

@@ -41,6 +41,13 @@ public:
setSize(500, 300);
}

ExampleTextWidget(Widget* groupWidget)
: NanoWidget(groupWidget),
fFont(createFontFromFile("sans", "./nanovg_res/Roboto-Regular.ttf"))
{
setSize(500, 300);
}

protected:
void onNanoDisplay() override
{


Loading…
Cancel
Save