Browse Source

Move widget code into separate classes; Add shapes example

pull/1/head
falkTX 11 years ago
parent
commit
7954ba9266
12 changed files with 707 additions and 508 deletions
  1. +3
    -1
      .gitignore
  2. +1
    -1
      dpf
  3. +5
    -2
      examples/Makefile
  4. +8
    -114
      examples/color.cpp
  5. +12
    -82
      examples/demo.cpp
  6. +9
    -175
      examples/images.cpp
  7. +8
    -133
      examples/rectangles.cpp
  8. +43
    -0
      examples/shapes.cpp
  9. +140
    -0
      examples/widgets/ExampleColorWidget.hpp
  10. +212
    -0
      examples/widgets/ExampleImagesWidget.hpp
  11. +155
    -0
      examples/widgets/ExampleRectanglesWidget.hpp
  12. +111
    -0
      examples/widgets/ExampleShapesWidget.hpp

+ 3
- 1
.gitignore View File

@@ -7,9 +7,11 @@
*.so

.kdev_include_paths
.kdev4/
*.kdev4

examples/app
examples/color
examples/demo
examples/images
examples/rectangles
examples/shapes

+ 1
- 1
dpf

@@ -1 +1 @@
Subproject commit 9e618371d7ac1f3d6984b0b96102d3bfe56c68d5
Subproject commit 142af3edcb598e0293f3637b0bad8f4af4158f24

+ 5
- 2
examples/Makefile View File

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

ifeq ($(WIN32),true)
TARGETS = app.exe color.exe demo.exe images.exe rectangles.exe
TARGETS = app.exe color.exe demo.exe images.exe rectangles.exe shapes.exe
else
TARGETS = app color demo images rectangles
TARGETS = app color demo images rectangles shapes
endif

# --------------------------------------------------------------
@@ -54,6 +54,9 @@ images: images.cpp images_src/* ../dpf/dgl/*
rectangles: rectangles.cpp ../dpf/dgl/*
$(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@

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

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

cairo: cairo.cpp ../dgl/*


+ 8
- 114
examples/color.cpp View File

@@ -17,131 +17,25 @@
// ------------------------------------------------------
// DGL Stuff

#include "App.hpp"
#include "Window.hpp"
#include "Widget.hpp"
#include "StandaloneWindow.hpp"
#include "widgets/ExampleColorWidget.hpp"

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

using namespace DGL;

// ------------------------------------------------------
// our 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;
};
using DGL::StandaloneWindow;

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

int main()
{
App app;
Window win(app);
ColorWidget color(win);
StandaloneWindow swin;
ExampleColorWidget widget(swin.getWindow());

win.setSize(300, 300);
win.setTitle("Color");
win.show();
app.exec();
swin.setSize(300, 300);
swin.setTitle("Color");
swin.exec();

return 0;
}


+ 12
- 82
examples/demo.cpp View File

@@ -17,91 +17,21 @@
// ------------------------------------------------------
// DGL Stuff

#include "App.hpp"
#include "Window.hpp"
#include "Widget.hpp"
#include <cmath>
#include "StandaloneWindow.hpp"
#include "widgets/ExampleColorWidget.hpp"
#include "widgets/ExampleImagesWidget.hpp"
#include "widgets/ExampleRectanglesWidget.hpp"
#include "widgets/ExampleShapesWidget.hpp"

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

using namespace DGL;
#include "images_src/CatPics.cpp"

// ------------------------------------------------------
// our widget

class DummyWidget : public Widget
{
public:
DummyWidget(Window& win)
: Widget(win)
{
}

protected:
void onDisplay() override
{
#if 0
glEnable(GL_MULTISAMPLE);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_SRC_ALPHA);
glEnable(GL_ONE_MINUS_SRC_ALPHA);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
#endif

glLineWidth(1.0f);
glColor3f(0.302f, 0.337f, 0.361f);
bgFull.draw();

glColor3f(0.235f, 0.271f, 0.294f);
bgSmall.draw();

glColor3f(0.176f, 0.212f, 0.235f);
bgSmall.drawOutline();

glColor3f(0.302f*2, 0.337f*2, 0.361f*2);
tri.draw();

glLineWidth(3.0f);
glColor3f(0.302f/2.0f, 0.337f/2.0f, 0.361f/2.0f);
tri.drawOutline();

glColor3f(0.235f, 0.271f, 0.294f);
cir.draw();

glLineWidth(2.0f);
glColor3f(0.176f/4, 0.212f/4, 0.235f/4);
cir.drawOutline();
}

void onReshape(int width, int height) override
{
// full bg
bgFull = Rectangle<int>(0, 0, width, height);

// small bg
bgSmall = Rectangle<int>(20, 10, width-40, height-20);

// center triangle
tri = Triangle<int>(width*0.5, height*0.1, width*0.1, height*0.9, width*0.9, height*0.9);

// circle
cir = Circle<int>(width/2, height*2/3, height/6, 300);

// make widget same size as window
setSize(width, height);

// default reshape implementation
Widget::onReshape(width, height);
}
// use namespace

private:
Rectangle<int> bgFull, bgSmall;
Triangle<int> tri;
Circle<int> cir;
};
using DGL::App;

// ------------------------------------------------------
// Our Demo Window
@@ -110,15 +40,15 @@ class DemoWindow : public Window
{
public:
DemoWindow(App& app)
: Window(app),
w1(*this)
: Window(app)//,
//w1(*this)
{
setSize(300, 300);
setTitle("DGL Demo");
}

private:
DummyWidget w1;
//DummyWidget w1;
};

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


+ 9
- 175
examples/images.cpp View File

@@ -14,198 +14,32 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

// ------------------------------------------------------
// Pics

#include "images_src/CatPics.cpp"

// ------------------------------------------------------
// DGL Stuff

#include "Image.hpp"
#include "Widget.hpp"
#include "StandaloneWindow.hpp"
#include "widgets/ExampleImagesWidget.hpp"

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

using namespace DGL;
#include "images_src/CatPics.cpp"

// ------------------------------------------------------
// 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;
}
// use namespace

int fImgTop1st, fImgTop2nd, fImgTop3rd;
int fImg1x, fImg2x, fImg3y;
bool fImg1rev, fImg2rev, fImg3rev;
Image fImg1, fImg2, fImg3;
};
using DGL::StandaloneWindow;

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

int main()
{
App app;
Window win(app);
ExampleImagesWidget images(win);
StandaloneWindow swin;
ExampleImagesWidget widget(swin.getWindow(), true);

win.setResizable(false);
win.setSize(500, 400);
win.setTitle("Images");
win.show();
app.exec();
swin.setTitle("Images");
swin.exec();

return 0;
}


+ 8
- 133
examples/rectangles.cpp View File

@@ -17,150 +17,25 @@
// ------------------------------------------------------
// DGL Stuff

#include "App.hpp"
#include "Window.hpp"
#include "Widget.hpp"
#include "StandaloneWindow.hpp"
#include "widgets/ExampleRectanglesWidget.hpp"

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

using namespace DGL;

// ------------------------------------------------------
// our widget

class RectanglesWidget : public Widget
{
public:
RectanglesWidget(Window& parent)
: Widget(parent)
{
for (int i=0; i<9; ++i)
fClicked[i] = false;
}

protected:
void onDisplay() override
{
const int width = getWidth();
const int height = getHeight();

Rectangle<int> r;

r.setWidth(width/3 - 6);
r.setHeight(height/3 - 6);

// draw a 3x3 grid
for (int i=0; i<3; ++i)
{
r.setX(3 + i*width/3);

// 1st
r.setY(3);

if (fClicked[0+i])
glColor3f(0.8f, 0.5f, 0.3f);
else
glColor3f(0.3f, 0.5f, 0.8f);

r.draw();

// 2nd
r.setY(3 + height/3);

if (fClicked[3+i])
glColor3f(0.8f, 0.5f, 0.3f);
else
glColor3f(0.3f, 0.5f, 0.8f);

r.draw();

// 3rd
r.setY(3 + height*2/3);

if (fClicked[6+i])
glColor3f(0.8f, 0.5f, 0.3f);
else
glColor3f(0.3f, 0.5f, 0.8f);

r.draw();
}
}

void onReshape(int width, int height) override
{
// make this widget same size as window
setSize(width, height);
Widget::onReshape(width, height);
}

bool onMouse(int button, bool press, int x, int y) override
{
if (button != 1 || ! press)
return false;

const Point<int> pos(x, y);

const int width = getWidth();
const int height = getHeight();

Rectangle<int> r;

r.setWidth(width/3 - 6);
r.setHeight(height/3 - 6);

// draw a 3x3 grid
for (int i=0; i<3; ++i)
{
r.setX(3 + i*width/3);
r.setY(3);

if (r.contains(pos))
{
fClicked[0+i] = !fClicked[0+i];
repaint();
break;
}

r.setY(3 + height/3);

if (r.contains(pos))
{
fClicked[3+i] = !fClicked[3+i];
repaint();
break;
}

r.setY(3 + height*2/3);

if (r.contains(pos))
{
fClicked[6+i] = !fClicked[6+i];
repaint();
break;
}
}

return true;
}

private:
bool fClicked[9];
};
using DGL::StandaloneWindow;

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

int main()
{
App app;
Window win(app);
RectanglesWidget rects(win);
StandaloneWindow swin;
ExampleRectanglesWidget widget(swin.getWindow());

win.setSize(300, 300);
win.setTitle("Rectangles");
win.show();
app.exec();
swin.setSize(300, 300);
swin.setTitle("Rectangles");
swin.exec();

return 0;
}


+ 43
- 0
examples/shapes.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/ExampleShapesWidget.hpp"

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

using DGL::StandaloneWindow;

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

int main()
{
StandaloneWindow swin;
ExampleShapesWidget widget(swin.getWindow());

swin.setSize(300, 300);
swin.setTitle("Shapes");
swin.exec();

return 0;
}

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

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

@@ -0,0 +1,140 @@
/*
* 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_COLOR_WIDGET_HPP_INCLUDED
#define EXAMPLE_COLOR_WIDGET_HPP_INCLUDED

// ------------------------------------------------------
// DGL Stuff

#include "Widget.hpp"
#include "Window.hpp"

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

using DGL::IdleCallback;
using DGL::Rectangle;
using DGL::Widget;
using DGL::Window;

// ------------------------------------------------------
// our widget

class ExampleColorWidget : public Widget,
public IdleCallback
{
public:
ExampleColorWidget(Window& parent)
: Widget(parent),
cur('r'),
reverse(false),
r(0), g(0), b(0)
{
parent.addIdleCallback(this);
}

protected:
void idleCallback() noexcept 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;
};


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

#endif // EXAMPLE_COLOR_WIDGET_HPP_INCLUDED

+ 212
- 0
examples/widgets/ExampleImagesWidget.hpp View File

@@ -0,0 +1,212 @@
/*
* 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_IMAGES_WIDGET_HPP_INCLUDED
#define EXAMPLE_IMAGES_WIDGET_HPP_INCLUDED

// ------------------------------------------------------
// DGL Stuff

#include "Image.hpp"
#include "Widget.hpp"
#include "Window.hpp"

// ------------------------------------------------------
// Images

#include "../images_src/CatPics.hpp"

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

using DGL::IdleCallback;
using DGL::Image;
using DGL::Rectangle;
using DGL::Widget;
using DGL::Window;

// ------------------------------------------------------
// 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& parent, const bool setParentSize = false)
: Widget(parent),
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)
{
setSize(500, 400);

parent.addIdleCallback(this);

if (setParentSize)
{
parent.setSize(500, 400);
parent.setResizable(false);
}
}

private:
void idleCallback() noexcept 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) noexcept
{
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;
};

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

#endif // EXAMPLE_IMAGES_WIDGET_HPP_INCLUDED

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

@@ -0,0 +1,155 @@
/*
* 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_RECTANGLES_WIDGET_HPP_INCLUDED
#define EXAMPLE_RECTANGLES_WIDGET_HPP_INCLUDED

// ------------------------------------------------------
// DGL Stuff

#include "Widget.hpp"
#include "Window.hpp"

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

using DGL::Rectangle;
using DGL::Widget;
using DGL::Window;

// ------------------------------------------------------
// our widget

class ExampleRectanglesWidget : public Widget
{
public:
ExampleRectanglesWidget(Window& parent)
: Widget(parent)
{
for (int i=0; i<9; ++i)
fClicked[i] = false;
}

protected:
void onDisplay() override
{
const int width = getWidth();
const int height = getHeight();

Rectangle<int> r;

r.setWidth(width/3 - 6);
r.setHeight(height/3 - 6);

// draw a 3x3 grid
for (int i=0; i<3; ++i)
{
r.setX(3 + i*width/3);

// 1st
r.setY(3);

if (fClicked[0+i])
glColor3f(0.8f, 0.5f, 0.3f);
else
glColor3f(0.3f, 0.5f, 0.8f);

r.draw();

// 2nd
r.setY(3 + height/3);

if (fClicked[3+i])
glColor3f(0.8f, 0.5f, 0.3f);
else
glColor3f(0.3f, 0.5f, 0.8f);

r.draw();

// 3rd
r.setY(3 + height*2/3);

if (fClicked[6+i])
glColor3f(0.8f, 0.5f, 0.3f);
else
glColor3f(0.3f, 0.5f, 0.8f);

r.draw();
}
}

void onReshape(int width, int height) override
{
// make this widget same size as window
setSize(width, height);
Widget::onReshape(width, height);
}

bool onMouse(int button, bool press, int x, int y) override
{
if (button != 1 || ! press)
return false;

const int width = getWidth();
const int height = getHeight();

Rectangle<int> r;

r.setWidth(width/3 - 6);
r.setHeight(height/3 - 6);

// draw a 3x3 grid
for (int i=0; i<3; ++i)
{
r.setX(3 + i*width/3);
r.setY(3);

if (r.contains(x, y))
{
fClicked[0+i] = !fClicked[0+i];
repaint();
break;
}

r.setY(3 + height/3);

if (r.contains(x, y))
{
fClicked[3+i] = !fClicked[3+i];
repaint();
break;
}

r.setY(3 + height*2/3);

if (r.contains(x, y))
{
fClicked[6+i] = !fClicked[6+i];
repaint();
break;
}
}

return true;
}

private:
bool fClicked[9];
};

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

#endif // EXAMPLE_RECTANGLES_WIDGET_HPP_INCLUDED

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

@@ -0,0 +1,111 @@
/*
* 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_SHAPES_WIDGET_HPP_INCLUDED
#define EXAMPLE_SHAPES_WIDGET_HPP_INCLUDED

// ------------------------------------------------------
// DGL Stuff

#include "Widget.hpp"
#include "Window.hpp"

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

using DGL::Circle;
using DGL::Triangle;
using DGL::Rectangle;
using DGL::Widget;
using DGL::Window;

// ------------------------------------------------------
// our widget

class ExampleShapesWidget : public Widget
{
public:
ExampleShapesWidget(Window& parent)
: Widget(parent) {}

protected:
void onDisplay() override
{
#if 0
glEnable(GL_MULTISAMPLE);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_SRC_ALPHA);
glEnable(GL_ONE_MINUS_SRC_ALPHA);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
#endif

glLineWidth(1.0f);
glColor3f(0.302f, 0.337f, 0.361f);
bg.draw();

glColor3f(0.235f, 0.271f, 0.294f);
rect.draw();

glColor3f(0.176f, 0.212f, 0.235f);
rect.drawOutline();

glColor3f(0.302f*2, 0.337f*2, 0.361f*2);
tri.draw();

glLineWidth(3.0f);
glColor3f(0.302f/2.0f, 0.337f/2.0f, 0.361f/2.0f);
tri.drawOutline();

glColor3f(0.235f, 0.271f, 0.294f);
cir.draw();

glLineWidth(2.0f);
glColor3f(0.176f/4, 0.212f/4, 0.235f/4);
cir.drawOutline();
}

void onReshape(int width, int height) override
{
// background
bg = Rectangle<int>(0, 0, width, height);

// rectangle
rect = Rectangle<int>(20, 10, width-40, height-20);

// center triangle
tri = Triangle<int>(width*0.5, height*0.1, width*0.1, height*0.9, width*0.9, height*0.9);

// circle
cir = Circle<int>(width/2, height*2/3, height/6, 300);

// make widget same size as window
setSize(width, height);

// default reshape implementation
Widget::onReshape(width, height);
}

private:
Rectangle<int> bg;
Rectangle<int> rect;
Triangle<int> tri;
Circle<int> cir;
};

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

#endif // EXAMPLE_SHAPES_WIDGET_HPP_INCLUDED

Loading…
Cancel
Save