Exemplo n.º 1
0
Arquivo: anim.c Projeto: doremi/sdl
void draw()
{
    Uint32 halfHeight;
    Uint32 color;
    Uint32 target_color;

    Uint32 sBaseColor = 0xff000000;
    Uint32 sColors[] = {0x0000ff, 0x00ff00, 0xff0000};
    Uint32 sIntervals[] = {0x000001, 0x000100, 0x010000};

    static Uint32 mCount = HEIGHT / 2;
    static Uint32 mColorSelect = 0;

    Uint32 i;

//    color = SDL_MapRGB(screen->format, 255, 0, 0);
    color = sColors[mColorSelect];
    Uint32 interval = sIntervals[mColorSelect];

    halfHeight = HEIGHT / 2;

    SDL_Rect rect;
    rect.x = rect.y = 0;
    rect.w = WIDTH;
    rect.h = HEIGHT;
//    SDL_FillRect(screen, &rect, 0);

    for (i = 0; i < halfHeight; ++i) {
        Uint32 diff = (((mCount - i) * 4) * interval) % color;

        Uint32 mycolor = sBaseColor+diff;
        target_color = SDL_MapRGBA(screen->format,
            (mycolor >> 16) & 0xff,
            (mycolor >> 8)  & 0xff,
            (mycolor)       & 0xff,
            (mycolor >> 24) & 0xff);

        sge_Rect(screen, halfHeight - i, (halfHeight - 1) - i,
             (WIDTH - halfHeight) + i, halfHeight + i, target_color);

//        SDL_FillRect(screen, NULL, target_color);

//        printf("%d, %d, %d, %d, %u\n", halfHeight - i, (halfHeight - 1) - i,
//             (WIDTH - halfHeight) + i, halfHeight + i, sBaseColor + diff);
//        SDL_Flip(screen);
//        SDL_Delay(100);
    }

    SDL_Flip(screen);

    ++mCount;
    mCount = mCount % 0xff;
    if (mCount < halfHeight) {
        mCount = halfHeight;

        mColorSelect++;
        if (mColorSelect > 2) {
            mColorSelect = 0;
        }
    }
}
Exemplo n.º 2
0
int main(int argc, char** argv)
{	
	/* Init SDL */
	if ( SDL_Init(SDL_INIT_TIMER|SDL_INIT_VIDEO) < 0 ) {
		fprintf(stderr, "Couldn't load SDL: %s\n", SDL_GetError());
		exit(1);
	}

	/* Clean up on exit */
	atexit(SDL_Quit);

	/* Set window title */
	SDL_WM_SetCaption("Input Deluxe", "input deluxe");
	
	/* Initialize the display */
	SDL_Surface *screen;
	screen = SDL_SetVideoMode(600, 400, 0, SDL_SWSURFACE);
	if ( screen == NULL ) {
		fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError());
		exit(1);
	}
	
	sge_Update_OFF();
	SDL_EnableUNICODE(1); //This is VERY important!!
	
	//Init our text sprites
	sge_TextSprite text(screen,"Edit Me!",20,90);
	text.show_cursor(true);
	sge_TextSprite text2(screen,"Hello World!",100,25);
	text.show_cursor(true);
	
	//Set and draw the border box
	SDL_Rect r; r.x=1; r.y=81; r.w=598; r.h=318; 
	text.set_border(r);
	sge_Rect(screen,0,80, 599,399, 255,0,0);   
	
	//Open a TT font
	if(sge_TTF_Init()!=0){fprintf(stderr,"TT error: %s\n",SDL_GetError());exit(1);} 	
	sge_TTFont *font;
	font=sge_TTF_OpenFont("/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf", 25);
	if(font==NULL){fprintf(stderr,"TT error: %s\n",SDL_GetError());exit(1);}

	text.set_ttFont(font,0,255,0);    //Use our font
	text2.set_ttFont(font,50,50,200);
	text.set_pps(60,60);              //set speed (pixels/second)
	text2.set_pps(-170,0);
	text.border_warp(true);           //WARP!
	text2.border_warp(true);
	
	
	SDL_UpdateRect(screen, 0,0,0,0); //Update whole screen
	
	//Keyrepeat
	SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL+50);
	
	SDL_Event event;
	do{
		//SDL_Delay(1);
	
		/* Check events */
		if(SDL_PollEvent(&event)==1){
			if(event.type==SDL_QUIT){break;}
			if(event.type==SDL_KEYDOWN && event.key.keysym.sym==SDLK_ESCAPE){break;}
			
			text.check(&event);  //Let our text sprite handle the event (editing the text)
		}
		
		if(text.update()){       //update() calculates the new pos and returns true if we need to redraw
			text.clear(0);       //clear text area
			text.draw();         //draw text at new pos
			sge_Update_ON();     
			text.UpdateRects();  //Update screen (old pos + new pos)
			sge_Update_OFF();
		}	
		if(text2.update()){      //Same thing for the other sprite
			text2.clear(0);
			text2.draw();
			sge_Update_ON();     
			text2.UpdateRects();
			sge_Update_OFF();
		}
		
	}while(true);
	
	
	sge_TTF_CloseFont(font);
	return 0;
}