4
#include "minorGems/graphics/ScreenGraphics.h"
5
#include "minorGems/graphics/GraphicBuffer.h"
6
#include "minorGems/graphics/Color.h"
8
#include "minorGems/ui/Mouse.h"
19
void catch_int(int sig_num) {
20
printf( "Quiting..." );
21
currentStep = numSteps;
22
signal( SIGINT, catch_int);
28
// let catch_int handle interrupt (^c)
29
signal( SIGINT, catch_int);
31
ScreenGraphics *graphics = new ScreenGraphics( 640, 480 );
32
Mouse *mouse = new Mouse(2);
35
unsigned long *pixelBuff = new unsigned long[ 640 * 480 ];
37
GraphicBuffer *buffer = new GraphicBuffer( pixelBuff, 640, 480 );
39
IconMap **maps = new IconMap*[numIcons];
43
IconMap *mouseMap1 = new IconMap( 10, 10 );
44
Color mouseColor1( 1.0, 0.0, 0.0, 1.0 );
45
for( int y=0; y<10; y++ ) {
46
for( int x=0; x<10; x++ ) {
47
mouseMap1->imageMap[ mouseMap1->yOffset[y] + x ] =
48
mouseColor1.composite;
51
IconMap *mouseMap2 = new IconMap( 10, 10 );
52
Color mouseColor2( 0.0, 1.0, 0.0, 1.0 );
53
for( int y=0; y<10; y++ ) {
54
for( int x=0; x<10; x++ ) {
55
mouseMap2->imageMap[ mouseMap2->yOffset[y] + x ] =
56
mouseColor2.composite;
60
IconMap *mouseMap3 = new IconMap( 10, 10 );
61
Color mouseColor3( 0.0, 0.0, 1.0, 1.0 );
62
for( int y=0; y<10; y++ ) {
63
for( int x=0; x<10; x++ ) {
64
mouseMap3->imageMap[ mouseMap3->yOffset[y] + x ] =
65
mouseColor3.composite;
71
Color c( 0.0f, 0.0f, 0.0f, 1.0f );
74
float *xPos = new float[numIcons];
75
float *yPos = new float[numIcons];
76
float *xDelta = new float[numIcons];
77
float *yDelta = new float[numIcons];
79
for( i=0; i<numIcons; i++ ) {
80
xPos[i] = (float)640 * rand() / RAND_MAX;
81
yPos[i] = (float)480 * rand() / RAND_MAX;
82
xDelta[i] = 10.0f * rand() / RAND_MAX;
83
yDelta[i] = 10.0f * rand() / RAND_MAX;
84
maps[i] = new IconMap( 10, 10 );
85
Color randColor( (float)rand() / RAND_MAX,
86
(float)rand() / RAND_MAX, (float)rand() / RAND_MAX, 1.0 );
87
for( int y=0; y<10; y++ ) {
88
for( int x=0; x<10; x++ ) {
89
maps[i]->imageMap[ maps[i]->yOffset[y] + x ] =
96
char buttonDown1 = false;
97
char buttonDown2 = false;
98
for( currentStep=0; currentStep<numSteps; currentStep++ ) {
99
buffer->eraseIconMap( mouseMap, mouseX, mouseY, c );
101
mouse->getLocation( &mouseX, &mouseY );
103
buffer->drawIconMap( mouseMap, mouseX, mouseY );
105
if( !buttonDown1 && mouse->isButtonDown(0) ) {
107
mouseMap = mouseMap2;
109
else if( buttonDown1 && !mouse->isButtonDown(0) ) {
111
mouseMap = mouseMap1;
114
else if( !buttonDown2 && mouse->isButtonDown(1) ) {
116
mouseMap = mouseMap3;
118
else if( buttonDown2 && !mouse->isButtonDown(1) ) {
120
mouseMap = mouseMap1;
125
for( i=0; i<numIcons; i++ ) {
126
buffer->eraseIconMap( maps[i], (int)( xPos[i] - 5 ),
127
(int)( yPos[i] - 5 ), c );
128
if( xPos[i] > 640 || xPos[i] < 0 ) {
129
xDelta[i] = -xDelta[i];
131
xPos[i] += xDelta[i];
132
if( yPos[i] > 480 || yPos[i] < 0 ) {
133
yDelta[i] = -yDelta[i];
135
yPos[i] += yDelta[i];
137
buffer->drawIconMap( maps[i], (int)( xPos[i] - 5 ),
138
(int)( yPos[i] - 5 ) );
141
graphics->swapBuffers( buffer );
146
for( int i=0; i<100; i++ ) {
148
Color c( 1.0f, 0.0f, 0.0f, 1.0f );
152
Color c( 0.0f, 1.0f, 0.0f, 1.0f );
155
graphics->swapBuffers( buffer );
161
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
162
printf( "Couldn't initialize SDL: %s\n", SDL_GetError() );
166
//atexit( SDL_Quit );
168
SDL_Surface *screen = SDL_SetVideoMode( 640, 480,
169
32, SDL_HWSURFACE | SDL_DOUBLEBUF );//| SDL_FULLSCREEN );
171
if ( screen == NULL ) {
172
printf( "Couldn't set 640x480x32 video mode: %s\n",
177
for( int i=0; i< 100; i++ ) {
178
if ( SDL_MUSTLOCK(screen) ) {
179
if ( SDL_LockSurface(screen) < 0 ) {
180
printf( "Couldn't lock screen: %s\n",
194
Uint32 *buffer = (Uint32 *)( screen->pixels );
195
for ( int y=0; y<screen->h; y++ ) {
196
for ( int x=0; x<screen->w; x++ ) {
198
int r = ( ( ( x * 255 ) / screen->w ) + i ) % 255;
199
int g = ( ( ( y * 255 ) / screen->h ) + i ) % 255;
203
//buffer[ y * screen->w + x ] = (a << 24) | (r << 16) | (g << 8) | b;
204
buffer[ y * screen->w + x ] = value;
208
if ( SDL_MUSTLOCK(screen) ) {
209
SDL_UnlockSurface(screen);
212
//SDL_UpdateRect( screen, 0, 0, screen->w, screen->h );