mirror of https://github.com/fltk/fltk
Replace an enum with 'const' variables in test/animated.cxx
- replace enum value 'FRAMES' with 'const unsigned int frames' - replace enum value 'DIM' with 'const unsigned int dim' - remove commented statements that have never been used. Note: this also changes uppercase enum values to lowercase constants.
This commit is contained in:
parent
72b8054ecc
commit
03389d1931
|
@ -1,7 +1,7 @@
|
|||
//
|
||||
// Alpha rendering benchmark program for the Fast Light Tool Kit (FLTK).
|
||||
//
|
||||
// Copyright 1998-2018 by Bill Spitzak and others.
|
||||
// Copyright 1998-2022 by Bill Spitzak and others.
|
||||
//
|
||||
// This library is free software. Distribution and use rights are outlined in
|
||||
// the file "COPYING" which should have been included with this file. If this
|
||||
|
@ -25,19 +25,19 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
enum {
|
||||
FRAMES = 48,
|
||||
DIM = 256
|
||||
};
|
||||
// These constants define the image dimensions and
|
||||
// the number of frames of the animation
|
||||
const unsigned int dim = 256;
|
||||
const unsigned int frames = 48;
|
||||
|
||||
static Fl_RGB_Image *img[FRAMES];
|
||||
static Fl_RGB_Image *img[frames];
|
||||
static uchar curframe;
|
||||
|
||||
static void make_images() {
|
||||
|
||||
unsigned i;
|
||||
for (i = 0; i < FRAMES; i++) {
|
||||
const unsigned size = DIM * DIM * 4;
|
||||
for (i = 0; i < frames; i++) {
|
||||
const unsigned size = dim * dim * 4;
|
||||
uchar *data = new uchar[size];
|
||||
|
||||
memset(data, 0, size);
|
||||
|
@ -46,19 +46,19 @@ static void make_images() {
|
|||
int x, y;
|
||||
for (x = 0; x < 10; x++) {
|
||||
for (y = 0; y < 10; y++) {
|
||||
data[y * DIM * 4 + x * 4 + 3] = 255;
|
||||
data[y * dim * 4 + x * 4 + 3] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
// A fading sphere
|
||||
uchar alpha = 255;
|
||||
if (i < FRAMES / 2)
|
||||
alpha = uchar(255 * (i / ((float) FRAMES / 2)));
|
||||
if (i < frames / 2)
|
||||
alpha = uchar(255 * (i / ((float) frames / 2)));
|
||||
else
|
||||
alpha = uchar(255 * (((FRAMES / 2) - (i - FRAMES / 2)) / ((float) FRAMES / 2)));
|
||||
alpha = uchar(255 * (((frames / 2) - (i - frames / 2)) / ((float) frames / 2)));
|
||||
|
||||
const int spherew = 60;
|
||||
const int spherex = (DIM - spherew) / 2;
|
||||
const int spherex = (dim - spherew) / 2;
|
||||
const int maxdist = (spherew / 2) * (spherew / 2);
|
||||
for (x = spherex; x < spherex + spherew; x++) {
|
||||
for (y = 20; y < 20 + spherew; y++) {
|
||||
|
@ -77,33 +77,31 @@ static void make_images() {
|
|||
if (fill > 0.9)
|
||||
myalpha *= uchar((1.0f - fill) * 10);
|
||||
|
||||
data[y * DIM * 4 + x * 4 + 0] = grey;
|
||||
data[y * DIM * 4 + x * 4 + 1] = grey;
|
||||
data[y * DIM * 4 + x * 4 + 2] = grey;
|
||||
data[y * DIM * 4 + x * 4 + 3] = myalpha;
|
||||
data[y * dim * 4 + x * 4 + 0] = grey;
|
||||
data[y * dim * 4 + x * 4 + 1] = grey;
|
||||
data[y * dim * 4 + x * 4 + 2] = grey;
|
||||
data[y * dim * 4 + x * 4 + 3] = myalpha;
|
||||
}
|
||||
}
|
||||
|
||||
// A moving blob
|
||||
const float pos = (i / (float) FRAMES) * 2 - 0.5f;
|
||||
const float pos = (i / (float) frames) * 2 - 0.5f;
|
||||
|
||||
const int xoffset = int(pos * (int)DIM);
|
||||
const int xoffset = int(pos * DIM);
|
||||
const int yoffset = 2 * DIM / 3;
|
||||
const int w = DIM / 4;
|
||||
|
||||
for (x = -w; x < w; x++) {
|
||||
if (x + xoffset < 0 || x + xoffset >= DIM)
|
||||
if (x + xoffset < 0 || x + xoffset >= (int)dim)
|
||||
continue;
|
||||
for (y = yoffset - w; y < yoffset + w; y++) {
|
||||
const uchar grey = abs(y - yoffset);
|
||||
// data[y * DIM * 4 + (x + xoffset) * 4 + 0] = grey;
|
||||
// data[y * DIM * 4 + (x + xoffset) * 4 + 1] = grey;
|
||||
data[y * DIM * 4 + (x + xoffset) * 4 + 2] = grey;
|
||||
data[y * DIM * 4 + (x + xoffset) * 4 + 3] = 127;
|
||||
data[y * dim * 4 + (x + xoffset) * 4 + 2] = grey;
|
||||
data[y * dim * 4 + (x + xoffset) * 4 + 3] = 127;
|
||||
}
|
||||
}
|
||||
|
||||
img[i] = new Fl_RGB_Image(data, DIM, DIM, 4);
|
||||
img[i] = new Fl_RGB_Image(data, dim, dim, 4);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,7 +115,7 @@ public:
|
|||
// Test both cx/cy offset and clipping. Both borders should have a 5-pixel edge,
|
||||
// and the upper-left black box should not be visible.
|
||||
fl_push_clip(5, 5, w() - 5, h() - 5);
|
||||
img[curframe]->draw(0, 0, DIM, DIM, 5, 5);
|
||||
img[curframe]->draw(0, 0, dim, dim, 5, 5);
|
||||
fl_pop_clip();
|
||||
}
|
||||
};
|
||||
|
@ -131,7 +129,7 @@ static void cb(void *) {
|
|||
Fl::repeat_timeout(1.0f / 24, cb);
|
||||
|
||||
curframe++;
|
||||
curframe %= FRAMES;
|
||||
curframe %= frames;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
|
Loading…
Reference in New Issue