Browse Source

Complete images example

gh-pages
falkTX 10 years ago
parent
commit
76a60bca84
10 changed files with 7329 additions and 77 deletions
  1. +3
    -3
      examples/Makefile
  2. +1
    -1
      examples/color.cpp
  3. +0
    -73
      examples/image.cpp
  4. +214
    -0
      examples/images.cpp
  5. +3
    -0
      examples/images_src/CREDITS.txt
  6. +7083
    -0
      examples/images_src/CatPics.cpp
  7. +25
    -0
      examples/images_src/CatPics.hpp
  8. BIN
      examples/images_src/cat1.png
  9. BIN
      examples/images_src/cat2.png
  10. BIN
      examples/images_src/cat3.png

+ 3
- 3
examples/Makefile View File

@@ -14,9 +14,9 @@ LINK_FLAGS += -L.. -ldgl $(DGL_LIBS)
# --------------------------------------------------------------

ifeq ($(WIN32),true)
TARGETS = app.exe image.exe nekobi-ui.exe
TARGETS = app.exe color images.exe nekobi-ui.exe
else
TARGETS = app image nekobi-ui
TARGETS = app color images nekobi-ui
endif

# --------------------------------------------------------------
@@ -38,7 +38,7 @@ app: app.cpp ../dgl/*
color: color.cpp ../dgl/*
$(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@

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

nekobi-ui: nekobi-ui.cpp nekobi-ui_src/* ../dgl/*


+ 1
- 1
examples/color.cpp View File

@@ -127,7 +127,7 @@ private:
width = width*2/3;
height = height*2/3;

// paint invert color (in 2/3 size)
// paint inverted color (in 2/3 size)
glColor3b(100-r, 100-g, 100-b);

glBegin(GL_QUADS);


+ 0
- 73
examples/image.cpp View File

@@ -1,73 +0,0 @@
/*
* DISTRHO Plugin Toolkit (DPT)
* Copyright (C) 2012-2013 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 Image

#include "Image.hpp"

// ------------------------------------------------------
// DGL Widget and StandaloneWindow

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

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

using namespace DGL;

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

class ExampleImageWidget : public Widget
{
public:
ExampleImageWidget(Window& win)
: Widget(win)
{
// TODO: load image
}

private:
void onDisplay() override
{
fImage.draw();
}

Image fImage;
};

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

int main()
{
StandaloneWindow appWin;
Window& win(appWin.getWindow());

ExampleImageWidget gui(win);
win.setResizable(false);
win.setSize(200, 200);
win.setTitle("Image");
win.show();

appWin.exec();

return 0;
}

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

+ 214
- 0
examples/images.cpp View File

@@ -0,0 +1,214 @@
/*
* DISTRHO Plugin Toolkit (DPT)
* Copyright (C) 2012-2013 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 "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 App::IdleCallback,
Widget
{
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)
{
}

private:
void idleCallback() override
{
if (fImg1rev)
{
fImg1x -= 2;
if (fImg1x <= 0)
{
fImg1rev = false;
setNewTopImg(1);
}
}
else
{
fImg1x += 2;
if (fImg1x >= kImg1max)
{
fImg1rev = true;
setNewTopImg(1);
}
}

if (fImg2rev)
{
fImg2x -= 1;
if (fImg2x <= 0)
{
fImg2rev = false;
setNewTopImg(2);
}
}
else
{
fImg2x += 4;
if (fImg2x >= kImg2max)
{
fImg2rev = true;
setNewTopImg(2);
}
}

if (fImg3rev)
{
fImg3y -= 3;
if (fImg3y <= 0)
{
fImg3rev = false;
setNewTopImg(3);
}
}
else
{
fImg3y += 3;
if (fImg3y >= kImg3max)
{
fImg3rev = true;
setNewTopImg(3);
}
}

repaint();
}

void setNewTopImg(const int imgId)
{
if (fImgTop1st == imgId)
return;

if (fImgTop2nd == imgId)
{
fImgTop2nd = fImgTop1st;
fImgTop1st = imgId;
return;
}

fImgTop3rd = fImgTop2nd;
fImgTop2nd = fImgTop1st;
fImgTop1st = imgId;
}

void onDisplay() override
{
switch (fImgTop3rd)
{
case 1:
fImg1.draw(fImg1x, kImg1y);
break;
case 2:
fImg2.draw(fImg2x, kImg2y);
break;
case 3:
fImg3.draw(kImg3x, fImg3y);
break;
};

switch (fImgTop2nd)
{
case 1:
fImg1.draw(fImg1x, kImg1y);
break;
case 2:
fImg2.draw(fImg2x, kImg2y);
break;
case 3:
fImg3.draw(kImg3x, fImg3y);
break;
};

switch (fImgTop1st)
{
case 1:
fImg1.draw(fImg1x, kImg1y);
break;
case 2:
fImg2.draw(fImg2x, kImg2y);
break;
case 3:
fImg3.draw(kImg3x, fImg3y);
break;
};
}

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);

app.addIdleCallback(&images);

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

return 0;
}

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

+ 3
- 0
examples/images_src/CREDITS.txt View File

@@ -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/

+ 7083
- 0
examples/images_src/CatPics.cpp
File diff suppressed because it is too large
View File


+ 25
- 0
examples/images_src/CatPics.hpp View File

@@ -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


BIN
examples/images_src/cat1.png View File

Before After
Width: 294  |  Height: 245  |  Size: 119KB

BIN
examples/images_src/cat2.png View File

Before After
Width: 245  |  Height: 160  |  Size: 69KB

BIN
examples/images_src/cat3.png View File

Before After
Width: 248  |  Height: 150  |  Size: 63KB

Loading…
Cancel
Save