示例#1
0
static void sdl_update(DisplayState *ds, int x, int y, int w, int h)
{
//        printf("updating x=%d y=%d w=%d h=%d\n", x, y, w, h);
//        printf("scaling_active=%d\n", scaling_active);
    SDL_Rect rec;
    rec.x = x;
    rec.y = y;
    rec.w = w;
    rec.h = h;

    if (guest_screen) {
        if (!scaling_active) {
            SDL_BlitSurface(guest_screen, &rec, real_screen, &rec);
        } else {
            if (sdl_zoom_blit(guest_screen, real_screen, SMOOTHING_ON, &rec) < 0) {
                fprintf(stderr, "Zoom blit failed\n");
                exit(1);
            }
        }
    } 
    SDL_UpdateRect(real_screen, rec.x, rec.y, rec.w, rec.h);
}
示例#2
0
void ezioEmulator::ClearDisplay(void)
{
	SDL_Rect rect;
	Uint8 *chr = display;
	memset(display, ' ',
		device->GetCharactersPerLine() * device->GetPanelHeight());

	for (rect.y = 0;
		rect.y < px_lcd_height; rect.y += (px_chr_height + 1)) {
		for (rect.x = 0;
			rect.x < px_lcd_width; rect.x += (px_chr_width + 1)) {
			rect.w = px_chr_width;
			rect.h = px_chr_height;
			SDL_BlitSurface(chr_off, NULL, lcd_panel, &rect);
			rect.x += (px_chr_space - 1);
		}
		rect.y += (px_chr_space - 1);
	}

	SDL_BlitSurface(lcd_panel, NULL, view, NULL);
	SDL_UpdateRect(view, 0, 0, 0, 0);
}
示例#3
0
void factoroids_show_message(char* str)
{
    SDL_Surface* s1 = NULL;
    SDL_Rect loc;
    char wrapped_str[1024];
    int char_width;

    if(str == NULL)
        return;

    char_width = T4K_CharsForWidth(DEFAULT_MENU_FONT_SIZE, screen->w * 0.75);
    T4K_LineWrapInsBreaks(str, wrapped_str, char_width, 64, 64);
    s1 = T4K_BlackOutline(wrapped_str, DEFAULT_MENU_FONT_SIZE, &yellow);
    if (s1)
    {
        loc.x = screen->w/2 - s1->w/2;
        loc.y = screen->h/4;
        SDL_BlitSurface(s1, NULL, screen, &loc);
        SDL_FreeSurface(s1);
    }
    SDL_UpdateRect(screen, 0, 0, 0, 0);
}
示例#4
0
static DFBResult
dfb_sdl_update_screen_handler( const DFBRegion *region )
{
     DFBRegion    update;
     CoreSurface *surface = dfb_sdl->primary;

     DFB_REGION_ASSERT_IF( region );

     if (region)
          update = *region;
     else {
          update.x1 = 0;
          update.y1 = 0;
          update.x2 = surface->config.size.w - 1;
          update.y2 = surface->config.size.h - 1;
     }

#if 0
     pthread_mutex_lock( &dfb_sdl->update.lock );

     if (dfb_sdl->update.pending)
          dfb_region_region_union( &dfb_sdl->update.region, &update );
     else {
          dfb_sdl->update.region  = update;
          dfb_sdl->update.pending = true;
     }

     pthread_cond_signal( &dfb_sdl->update.cond );

     pthread_mutex_unlock( &dfb_sdl->update.lock );
#else
     if (surface->config.caps & DSCAPS_FLIPPING)
          SDL_Flip( dfb_sdl->screen );
     else
          SDL_UpdateRect( dfb_sdl->screen, DFB_RECTANGLE_VALS_FROM_REGION(&update) );
#endif

     return DFB_OK;
}
示例#5
0
void lcd_cs(uint8_t on)
{
    if (!on)
    {
        SDL_Surface *scaled;
        scaled = zoomSurface(offscreen, SCALEX, SCALEY, 0);
        SDL_BlitSurface(scaled, NULL, screen, NULL);
        SDL_FreeSurface(scaled);
        SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);

        if (NULL != cmdline_saveframes())
        {
            char fname[1024];
            snprintf(fname, sizeof(fname), "%s-%08d.bmp", cmdline_saveframes(), frameIndex++);
            if (0 != SDL_SaveBMP(screen, fname))
            {
                fprintf(stderr, "Failed to save %s\n", fname);
                exit(1);
            }
        }
    }
}
示例#6
0
void SkOSWindow::doDraw() {
    if (fGLCanvas) {
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
        glEnable(GL_TEXTURE_2D);
        glClearColor(0, 0, 0, 0);
        glClear(GL_COLOR_BUFFER_BIT);

        int count = fGLCanvas->save();
        this->draw(fGLCanvas);
        fGLCanvas->restoreToCount(count);
        SDL_GL_SwapBuffers( );
    } else {
        if ( SDL_MUSTLOCK(fSurface) ) {
            if ( SDL_LockSurface(fSurface) < 0 ) {
                return;
            }
        }

        SkBitmap bitmap;

        if (skia_setBitmapFromSurface(&bitmap, fSurface)) {
            SkCanvas canvas(bitmap);
            this->draw(&canvas);
        }

        if ( SDL_MUSTLOCK(fSurface) ) {
            SDL_UnlockSurface(fSurface);
        }

        int result = SDL_BlitSurface(fSurface, NULL, fScreen, NULL);
        if (result) {
            SkDebugf("------- SDL_BlitSurface returned %d\n", result);
        }
        SDL_UpdateRect(fScreen, 0, 0, fScreen->w, fScreen->h);
    }
}
示例#7
0
void drawBackground(SDL_Surface *screen)
{
   int      i;
   Uint32   color;
   Uint8    gradient;
   SDL_Rect rect;
   
   rect.w = screen->w;
   rect.h = 1;
   rect.x = 0;
   
   for (i=0; i<screen->h; i++)
   {
      rect.y = i;
      
      if (i < (screen->h/2))
      {
         gradient = 127 + (i*127/((screen->h)/2) - 1);
      }
      else
      {
         gradient = 127 + ((screen->h - i)*127/((screen->h)/2) - 1);
      }
      
      color = SDL_MapRGB(screen->format, gradient, gradient, gradient);
      
      SDL_FillRect(screen, &rect, color);
   }
   
   if (screen->flags & SDL_DOUBLEBUF)
   {
      SDL_Flip(screen);
   }
   else
   {
      SDL_UpdateRect(screen, 0, 0, 0, 0);
   }
}
示例#8
0
/***************************************************************\
*                         Menu                                  *
*  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  *
*                                                               *
*  Muestra y controla el men˙ del juego.                        *
*  Devuelve 	0 si hay que arrancar el juego			*
*  		1 si hay que cargar partida			*
*  		2 si hay que salir
\***************************************************************/
void mostrarMenu ( const char* imagenFondo )
{
    bool salir = false;
    SDL_Event evento;

    SDL_Surface * fondoMenu = IMG_Load(imagenFondo);

    SDL_Rect *rectFondoMenu = new SDL_Rect;

    rectFondoMenu->x = 0;
    rectFondoMenu->y = ConfigManager::V_RES - fondoMenu->h;
    rectFondoMenu->w = fondoMenu->w;
    rectFondoMenu->h = fondoMenu->h;

    while ( !salir )
    {
        // Hacemos el control del teclado
        while ( SDL_PollEvent ( &evento ) )
        {
            switch ( evento.type )
            {
            case SDL_KEYDOWN:
		if (evento.key.keysym.sym == SDLK_RETURN) salir = true;
                break;
            default:
                break;
            }
        }
        SDL_FillRect ( screen, NULL, ConfigManager::GetIntProperty("menuBackground") );  
	//SDL_MapRGB(screen->format, 0,0,int(50*sin(cuentaCiclos/40.0)+100)));
        SDL_BlitSurface ( fondoMenu, NULL, screen, rectFondoMenu );
        SDL_UpdateRect ( screen, 0, 0, 0, 0 );

    }
    SDL_FreeSurface ( fondoMenu );
    SDL_ShowCursor ( SDL_ENABLE );

}
示例#9
0
void ZoomPicture (SDL_Surface *screen, SDL_Surface *picture, int smooth) 
{
	SDL_Surface *rotozoom_picture;
	SDL_Rect dest;
	int framecount, framemax, frameinc;
	float zoomxf,zoomyf;

	/* Zoom and display the picture */
	framemax=4*360; frameinc=1;
	for (framecount=360; framecount<framemax; framecount += frameinc) {
		if ((framecount % 360)==0) frameinc++;
		HandleEvent();
		ClearScreen(screen);
                zoomxf=(float)framecount/(float)framemax;
                zoomxf=1.5*zoomxf*zoomxf;
                zoomyf=0.5+fabs(1.0*sin((double)framecount/80.0));
                if ((framecount % 120)==0) {
                 printf ("  Frame: %i   Zoom: x=%.2f y=%.2f\n",framecount,zoomxf,zoomyf);
                }
		if ((rotozoom_picture=zoomSurface (picture, zoomxf, zoomyf, smooth))!=NULL) {
			dest.x = (screen->w - rotozoom_picture->w)/2;;
			dest.y = (screen->h - rotozoom_picture->h)/2;
			dest.w = rotozoom_picture->w;
			dest.h = rotozoom_picture->h;
			if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) {
				fprintf(stderr, "Blit failed: %s\n", SDL_GetError());
				break;
			}
			SDL_FreeSurface(rotozoom_picture);
		}

		/* Display by flipping screens */
		SDL_UpdateRect(screen,0,0,0,0);
	}
	
	/* Pause for a sec */
	SDL_Delay(1000);
}
示例#10
0
/* Fill the screen with a gradient */
static void FillBackground(SDL_Surface *screen)
{
	Uint8 *buffer;
	Uint16 *buffer16;
        Uint16 color;
        Uint8  gradient;
	int    i, k;

	/* Set the surface pixels and refresh! */
	if ( SDL_LockSurface(screen) < 0 ) {
		fprintf(stderr, "Couldn't lock the display surface: %s\n",
							SDL_GetError());
		quit(2);
	}
	buffer=(Uint8 *)screen->pixels;
	if (screen->format->BytesPerPixel!=2) {
		for ( i=0; i<screen->h; ++i ) {
			memset(buffer,(i*255)/screen->h, screen->w*screen->format->BytesPerPixel);
			buffer += screen->pitch;
		}
	}
        else
        {
		for ( i=0; i<screen->h; ++i ) {
			gradient=((i*255)/screen->h);
                        color = (Uint16)SDL_MapRGB(screen->format, gradient, gradient, gradient);
                        buffer16=(Uint16*)buffer;
                        for (k=0; k<screen->w; k++)
                        {
                            *(buffer16+k)=color;
                        }
			buffer += screen->pitch;
		}
        }

	SDL_UnlockSurface(screen);
	SDL_UpdateRect(screen, 0, 0, 0, 0);
}
示例#11
0
文件: video.c 项目: alanbu/PCPinball
/*procedure flip_led_1;
var z:byte;
    z1,z2:word;
begin
  for z:=0 to 22 do
  begin
    z1:=z*80;
    z2:=z*160;
    asm
      push si
      push di
      push ds
      push es
      push cx
      push dx

      mov dx,03c4h
      mov ax,258
      out dx,ax
      mov es,[vseg]   {ES:DI}
      mov ds,[ledseg] {DS:SI}
      mov si,z1
      mov di,z2
      mov cx,40
      rep movsw {}

      pop dx
      pop cx
      pop es
      pop ds
      pop di
      pop si
    end;
  end;
end;

procedure flip_led_2;
var z:byte;
    z1,z2:word;
begin
  for z:=0 to 22 do
  begin
    z1:=z*80+1920;
    z2:=z*160;
    asm
      push si
      push di
      push ds
      push es
      push cx
      push dx

      mov dx,03c4h
      mov ax,1026
      out dx,ax
      mov es,[vseg]   {ES:DI}
      mov ds,[ledseg] {DS:SI}
      mov si,z1
      mov di,z2
      mov cx,40
      rep movsw {}

      pop dx
      pop cx
      pop es
      pop ds
      pop di
      pop si
    end;
  end;
end;
*/
void flip_led(boolean pause)
{
  int x,y;
  pointer line = ((byte *)screen->pixels);
  pointer led_line = led_display;

  for (y = 0; y <= 22; y++)
  {
	for (x = 0; x < 160; x++)
	{
	  line[x*2] = led_line[x];
	}
    line += 640;
    led_line += 160;
  }
  led_status =0;

  // Blit led
  SDL_BlitSurface(screen, &visible_led, real_screen, &led_rect);
  SDL_UpdateRect(real_screen, led_rect.x, led_rect.y, led_rect.w, led_rect.h);

  if (pause) end_of_frame_pause();
}
示例#12
0
void DealHelp::UpdateDisplay()
{
	SDL_FillRect(m_pScreen, NULL, SDL_MapRGB(m_pScreen->format, 153, 153, 255));

	nSDL_DrawString(m_pScreen, m_pFont, 15, 20, 
"Deal or No Deal is a game.\n\
There are 26 cases each containing\n\
money from a lot ($1,000,000) to\n\
very little ($0.01).\n\
\n\
You want the high value case; however\n\
the banker wants you to take a deal\n\
for the lesser value.\n\
\n\
Your object is to get the highest\n\
amount you can!\n\
\n\
Good luck!\n\
\n\
Also have fun!");		
	
	SDL_UpdateRect(m_pScreen, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
}
示例#13
0
inline void drawScreen() { 
  static const  Uint32 white = SDL_MapRGB(screen->format, 0xff, 0xff, 0xff); 
  static const Uint32 black = SDL_MapRGB(screen->format, 0, 0, 0); 
  if(SDL_MUSTLOCK(screen)) {
    if(SDL_LockSurface(screen) < 0) { 
      fprintf(stderr, "Can't lock screen: %s\n", SDL_GetError()); 
      return;
    }
  }
  for(int y =0; y < 32; ++y) { 
    for(int x=0; x < 64; ++x) { 
      if(disp[x][y]) { 
        putpixel(screen,x,y,white); 
      }
      else { 
        putpixel(screen,x,y,black); 
      }
    }
  }

  if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); 
  SDL_UpdateRect(screen,0,0,0,0);  
}
示例#14
0
/**
 * Paint the secure label if required
 *
 * @param   fForce Force the repaint
 * @remarks must be called from the SDL thread!
 */
void SDLFramebuffer::paintSecureLabel(int x, int y, int w, int h, bool fForce)
{
    AssertMsg(mSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));
    /* check if we can skip the paint */
    if (!fForce && ((uint32_t)y > mLabelHeight))
    {
        return;
    }
    /* first fill the background */
    SDL_Rect rect = {0, 0, mWidth, mLabelHeight};
    SDL_FillRect(mScreen, &rect, SDL_MapRGB(mScreen->format, 255, 255, 0));
    /* now the text */
    if (mLabelFont && mSecureLabelText)
    {
        SDL_Color clrFg = {0, 0, 255, 0};
        SDL_Surface *sText = TTF_RenderUTF8_Solid(mLabelFont, mSecureLabelText, clrFg);
        rect.x = 10;
        SDL_BlitSurface(sText, NULL, mScreen, &rect);
        SDL_FreeSurface(sText);
    }
    /* make sure to update the screen */
    SDL_UpdateRect(mScreen, 0, 0, mWidth, mLabelHeight);
}
/**
 * Method used to display text on the screen.
 * @param font - font which will be used to write text.
 * @param screen - pointer to screen on which we will display everything.
 */
void BattleOfMindorMenuState::printMenuText(TTF_Font* font, SDL_Surface* screen)
{
	SDL_Color activeForeground, foregroundColor;
	int x = 370;
	int y = 320;

	activeForeground.r = foregroundColor.r = 255;
	foregroundColor.g = 255;
	foregroundColor.b = 51;
	activeForeground.g = 0;
	activeForeground.b = 0;
	
	Configuration* conf = Configuration::getInstance();
	displayOneText(font, screen, "Intro", foregroundColor, x, y);
	y += 50;
	x -= 45;
	displayOneText(font, screen, "Battle of Mindor", activeForeground, x, y);
	y += 50;
	x += 10;
	displayOneText(font, screen, "Battle of Hoth", foregroundColor, x, y);

	SDL_UpdateRect( screen, NULL, NULL, NULL, NULL );
};
示例#16
0
static void
blit_to_screen (void)
{
  int j;

  SDL_LockSurface (screen);

  /* FIXME: add scaling support */

  SDL_SetPalette (screen, SDL_LOGPAL|SDL_PHYSPAL,
		  (SDL_Color*)pn_image_data->cmap, 0, 256);
  SDL_SetAlpha (screen, 0, 255);

  for (j=0; j<pn_image_data->height; j++)
      memcpy (screen->pixels + j*screen->pitch,
	      pn_image_data->surface[0] + j*pn_image_data->width,
	      pn_image_data->width);


  SDL_UnlockSurface (screen);

  SDL_UpdateRect (screen, 0, 0, 0, 0);
}
示例#17
0
文件: board.c 项目: Zirias/stoneage
static void
m_redraw(THIS, int refresh)
{
    METHOD(Board);
    int x, y;
    SDL_Rect drawArea;
    Screen s;

    struct Board_impl *b = this->pimpl;
    SDL_Surface *sf = SDL_GetVideoSurface();

    if (b->level < 0) return;

    for (y = 0; y < LVL_ROWS; ++y)
	for (x = 0; x < LVL_COLS; ++x)
	    this->draw(this, x, y, 0);

    if (!refresh) return;

    s = getScreen();
    s->coordinatesToRect(s, 0, 0, LVL_COLS, LVL_ROWS, &drawArea);
    SDL_UpdateRect(sf, drawArea.x, drawArea.y, drawArea.w, drawArea.h);
}
示例#18
0
void DisplayDrawCircle(int x0, int y0, int radius)
{
    int f = 1 - radius;
    int ddF_x = 0;
    int ddF_y = -2 * radius;
    int x = 0;
    int y = radius;
 
    DisplaySetPoint(x0, y0 + radius);
    DisplaySetPoint(x0, y0 - radius);
    DisplaySetPoint(x0 + radius, y0);
    DisplaySetPoint(x0 - radius, y0);
 
    while(x < y) 
    {
       if(f >= 0) 
       {
          y--;
          ddF_y += 2;
          f += ddF_y;
       }
      
       x++;
       ddF_x += 2;
       f += ddF_x + 1;
 
       DisplaySetPoint(x0 + x, y0 + y);
       DisplaySetPoint(x0 - x, y0 + y);
       DisplaySetPoint(x0 + x, y0 - y);
       DisplaySetPoint(x0 - x, y0 - y);
       DisplaySetPoint(x0 + y, y0 + x);
       DisplaySetPoint(x0 - y, y0 + x);
       DisplaySetPoint(x0 + y, y0 - x);
       DisplaySetPoint(x0 - y, y0 - x);
    }
	SDL_UpdateRect(screen, 0, 0, 160*2, 80*2);
}
示例#19
0
void
av_sync(void)
{
    SDL_Rect r;

#ifdef PROFILE_GRAPHICS
    float tot_area = 0;
    int i = 0;
    Uint32 ticks = SDL_GetTicks();
#endif

    SDL_Scale2x(display::graphics.screen()->surface(), display::graphics.scaledScreenSurface());
    /* copy palette and handle fading! */
    transform_palette();
    SDL_SetColors(display::graphics.scaledScreenSurface(), pal_colors, 0, 256);
    SDL_BlitSurface(display::graphics.scaledScreenSurface(), NULL, display::graphics.displaySurface(), NULL);

    if (display::graphics.videoRect().h && display::graphics.videoRect().w) {
        r.h = 2 * display::graphics.videoRect().h;
        r.w = 2 * display::graphics.videoRect().w;
        r.x = 2 * display::graphics.videoRect().x;
        r.y = 2 * display::graphics.videoRect().y;
        SDL_DisplayYUVOverlay(display::graphics.videoOverlay(), &r);
    }

    if (display::graphics.newsRect().h && display::graphics.newsRect().w) {
        r.h = 2 * display::graphics.newsRect().h;
        r.w = 2 * display::graphics.newsRect().w;
        r.x = 2 * display::graphics.newsRect().x;
        r.y = 2 * display::graphics.newsRect().y;
        SDL_DisplayYUVOverlay(display::graphics.newsOverlay(), &r);
    }

    //TODO: Since we're not always tracking the right dirty area (due to the graphics refactoring)
    // for now we update the entire display every time.
    SDL_UpdateRect(display::graphics.displaySurface(), 0, 0, 640, 400);
}
示例#20
0
文件: XEditBox.cpp 项目: dulton/XGUI
void BCursor::resume()
{
	Uint16 current_height;
	int  i;
	void *p_screen;
	void *p_clone = clone_creen;
	
	if(!clone_creen)
		return ;
	
	current_height=y+height; //计算y2坐标,以免在循环的时候重复计算
	
	switch(screen->format->BytesPerPixel)
	{
	 	case 2:
	 	for(i=y;i<current_height; ++i)
	 	{
	 		p_screen=((Uint16 *)screen->pixels) + (i * screen->w +x);
	 		memcpy(p_screen,p_clone,COURSOR_WIDTH*2);	
	 		
	 		p_clone =(Uint16 *)p_clone+COURSOR_WIDTH;
	 	} 		
	 	break;
	 	case 4:
	 	for(i=y;i<current_height; ++i)
	 	{
	 		p_screen=((Uint32 *)screen->pixels) + (i* screen->w +x);
	 		memcpy(p_screen,p_clone,COURSOR_WIDTH*4);	
	 		
	 		p_clone =(Uint32 *)p_clone+COURSOR_WIDTH;

	 	}
	 	
	 	break;
	}
	SDL_UpdateRect(screen,x,y,COURSOR_WIDTH,height);
}
示例#21
0
void u8g_sdl_init(void)
{
    if (SDL_Init(SDL_INIT_VIDEO) != 0)
    {
        printf("Unable to initialize SDL:  %s\n", SDL_GetError());
        exit(1);
    }

    /* http://www.libsdl.org/cgi/docwiki.cgi/SDL_SetVideoMode */
    u8g_sdl_screen = SDL_SetVideoMode(WIDTH*u8g_sdl_multiple,HEIGHT*u8g_sdl_multiple,32,SDL_SWSURFACE|SDL_ANYFORMAT);
    if ( u8g_sdl_screen == NULL )
    {
        printf("Couldn't set video mode: %s\n", SDL_GetError());
        exit(1);
    }
    //printf("%d bits-per-pixel mode\n", u8g_sdl_screen->format->BitsPerPixel);
    //printf("%d bytes-per-pixel mode\n", u8g_sdl_screen->format->BytesPerPixel);

    u8g_sdl_color[0] = SDL_MapRGB( u8g_sdl_screen->format, 0, 0, 0 );
    u8g_sdl_color[1] = SDL_MapRGB( u8g_sdl_screen->format, W(100, 50), W(255,50), 0 );
    u8g_sdl_color[2] = SDL_MapRGB( u8g_sdl_screen->format, W(100, 80), W(255,80), 0 );
    u8g_sdl_color[3] = SDL_MapRGB( u8g_sdl_screen->format, 100, 255, 0 );

    /*
    u8g_sdl_set_pixel(0,0);
    u8g_sdl_set_pixel(1,1);
    u8g_sdl_set_pixel(2,2);
    */

    /* update all */
    /* http://www.libsdl.org/cgi/docwiki.cgi/SDL_UpdateRect */
    SDL_UpdateRect(u8g_sdl_screen, 0,0,0,0);

    atexit(SDL_Quit);
    return;
}
示例#22
0
文件: gl.cpp 项目: Vogtinator/nGL
void nglDisplay()
{
    #ifdef _TINSPIRE
        if(is_monochrome)
        {
            //Flip everything, as 0xFFFF is white on CX, but black on classic
            COLOR *ptr = screen + SCREEN_HEIGHT*SCREEN_WIDTH, *ptr_inv = screen_inverted + SCREEN_HEIGHT*SCREEN_WIDTH;
            while(--ptr >= screen)
                *--ptr_inv = ~*ptr;

            lcd_blit(screen_inverted, SCR_320x240_16);
        }
        else
            lcd_blit(screen, SCR_320x240_565);
    #else
        SDL_LockSurface(scr);
        std::copy(screen, screen + SCREEN_HEIGHT*SCREEN_WIDTH, reinterpret_cast<COLOR*>(scr->pixels));
        SDL_UnlockSurface(scr);
        SDL_UpdateRect(scr, 0, 0, 0, 0);
    #endif

    #ifdef FPS_COUNTER
        static unsigned int frames = 0;
        ++frames;

        static time_t last = 0;
        time_t now = time(nullptr);
        if(now != last)
        {
            fps = frames;
            printf("FPS: %u\n", frames);
            last = now;
            frames = 0;
        }
    #endif
}
示例#23
0
int Menu()
{
	int i,j,value=0;

	SDL_BlitSurface(GfxData[MENU],NULL,GfxData[SCREEN],NULL);
	for (i=0;i<buttonNum;i++)
		DrawMenuItem(i,0);
	
	UpdateScreen();

	while (!value)
	{
		SDL_PollEvent(&event);
		switch (event.type)
		{
		case SDL_QUIT:
			value=5;
			break;
		case SDL_MOUSEMOTION:
			j=(event.motion.y-buttonDistanceY)/buttonHeight;
			for (i=0;i<buttonNum;i++)
				DrawMenuItem(i,(i==j)&&(event.motion.x>=buttonDistanceX) && (event.motion.x<=buttonDistanceX+buttonWidth) && (event.motion.y>=buttonDistanceY) && (event.motion.y<=buttonDistanceY+buttonHeight*buttonNum));
			SDL_UpdateRect(GfxData[SCREEN],buttonDistanceX,buttonDistanceY,buttonDistanceX+buttonWidth,buttonDistanceY+buttonHeight*buttonNum);
			break;
		case SDL_MOUSEBUTTONDOWN:
			if ((event.button.button==SDL_BUTTON_LEFT) && InRect(event.button,buttonDistanceX,buttonDistanceY,buttonDistanceX+buttonWidth,buttonDistanceY+buttonHeight*buttonNum))
			{	// menuitem
				j=(event.button.y-buttonDistanceY)/buttonHeight;
				value=j+1;
			}
			break;
		}
		SDL_Delay(CPUWAIT);
	}
	return value;
}
示例#24
0
int main() {
	SDL_Surface* screen, *image;
	SDL_Rect dest,src;
	SDL_Event event;
	SDL_Init(SDL_INIT_EVERYTHING);
	atexit(SDL_Quit);
	screen = SDL_SetVideoMode(640,480,0,0);
	image = SDL_LoadBMP( IMAGE );

	SDL_SetColorKey(image,SDL_SRCCOLORKEY,SDL_MapRGB(screen->format,255,255,255));

	src.x=32;
	src.y=32;
	src.w = 640 - 64;
	src.h = 480 - 64;
	SDL_SetClipRect(screen,&src);

	for (;;) {
		if (SDL_PollEvent(&event)==0) {

			dest.w = image->w;
			dest.h = image->h;

			dest.x = rand() % (640 - image->w);
			dest.y = rand() % (480 - image->h);

			SDL_BlitSurface(image,NULL,screen,&dest);

			SDL_UpdateRect(screen,0,0,0,0);
		} else if (event.type==SDL_QUIT) 
			break;
	
	}

	return 0;
}
示例#25
0
void SDL_UpdateRects(SDL_Surface* pSurface, const CRectArray& raRectsToUpdate_c)
{
   if (raRectsToUpdate_c.size() == 0)
      return;

   for (int iRect = 0; iRect < raRectsToUpdate_c.size(); iRect++)
   {
      // Limit update calls to screen (Updates either crash or quiety fail on offscreen coordinates)
      int x = max(0, (int)raRectsToUpdate_c[iRect].x);
      int y = max(0, (int)raRectsToUpdate_c[iRect].y);
      int w = min((int)raRectsToUpdate_c[iRect].w, pSurface->w-(int)raRectsToUpdate_c[iRect].x);
      int h = min((int)raRectsToUpdate_c[iRect].h, pSurface->h-(int)raRectsToUpdate_c[iRect].y);
      SDL_UpdateRect(pSurface, x, y, w, h);
   }


/*   SDL_Rect* paRects = new SDL_Rect[raRectsToUpdate_c.size()];

   for (int iRect = 0; iRect < raRectsToUpdate_c.size(); iRect++)
   {
      paRects[iRect] = raRectsToUpdate_c[iRect];
   }i
   delete [] paRects;*/
}
示例#26
0
void factoroids_level_objs_hints(char *label, char *contents, int x, int y )
{
    SDL_Surface *s1 = NULL, *s2 = NULL;
    SDL_Rect loc;
    char wrapped_label[256];
    char wrapped_contents[256];
    int char_width;

    if(label == NULL || contents == NULL)
        return;

    char_width = T4K_CharsForWidth(DEFAULT_MENU_FONT_SIZE, LVL_WIDTH_MSG);
    T4K_LineWrapInsBreaks(label, wrapped_label, char_width, 64, 64);
    T4K_LineWrapInsBreaks(contents, wrapped_contents, char_width, 64, 64);

    s1 = T4K_BlackOutline(wrapped_label, DEFAULT_MENU_FONT_SIZE, &white);
    s2 = T4K_BlackOutline(wrapped_contents, DEFAULT_MENU_FONT_SIZE, &white);

    if(s1)
    {
        loc.x = x;
        loc.y = y;
        SDL_BlitSurface(s1, NULL, screen, &loc);
    }
    if(s2)
    {
        loc.x = x;
        loc.y = s1->h + loc.y ;
        SDL_BlitSurface(s2, NULL, screen, &loc);
    }

    SDL_UpdateRect(screen, 0, 0, 0, 0);

    SDL_FreeSurface(s1);
    SDL_FreeSurface(s2);
}
示例#27
0
void DrawMenu(T_E_Sel Mnu){
int I;
	boxRGBA(screen,Mnu.X,0,Mnu.X+19,399,64,64,64,0xFF);
	boxRGBA(screen,Mnu.X+19,0,Mnu.X+19,399,32,32,32,0xFF);

	rectangleRGBA(screen,Mnu.X,0,Mnu.X+19,19,32,32,32,0xFF);
	lineRGBA(screen,Mnu.X+5,5,Mnu.X+10,0,200,200,200,0xFF);
	lineRGBA(screen,Mnu.X+10,0,Mnu.X+15,5,200,200,200,0xFF);
	stringRGBA(screen,Mnu.X+1,10,Mnu.Name,200,200,200,0xFF);

	rectangleRGBA(screen,Mnu.X,380,Mnu.X+19,399,32,32,32,0xFF);
	lineRGBA(screen,Mnu.X+5,395,Mnu.X+10,399,200,200,200,0xFF);
	lineRGBA(screen,Mnu.X+10,399,Mnu.X+15,395,200,200,200,0xFF);
	
	for (I=0;(I<18)&&(Mnu.Top+I<Mnu.L);I++)
		DrawSpr(Spr[Mnu.E[Mnu.Top+I].Spr].img,screen,Mnu.X,20+I*20);

	if ((Mnu.Akt>=Mnu.Top)&&(Mnu.Akt<Mnu.Top+18)){
		rectangleRGBA(screen,Mnu.X+1,21+(Mnu.Akt-Mnu.Top)*20,Mnu.X+18,19+(Mnu.Akt-Mnu.Top)*20+19,0,0,0,128);
		rectangleRGBA(screen,Mnu.X,20+(Mnu.Akt-Mnu.Top)*20,Mnu.X+19,20+(Mnu.Akt-Mnu.Top)*20+19,255,255,255,128);
	}

	SDL_UpdateRect(screen,Mnu.X,0,20,400);
}
示例#28
0
文件: GUI.cpp 项目: TomHarte/ElectrEm
/*
	pretty much as SDL_BlitSurface, but blits everywhere except dstrect
*/
void SDL_BlitSurfaceNOT(SDL_Surface *src, SDL_Surface *dst, SDL_Rect *dstrect)
{
	SDL_Rect Target;

	/* left strip */
	Target.x = 0;
	if(Target.w = dstrect->x)
	{
		Target.y = 0;
		Target.h = src->h;
		SDL_BlitSurface(src, &Target, dst, &Target);
	}

	/* right strip */
	Target.x = dstrect->x+dstrect->w;
	if(Target.w = src->w-Target.x)
	{
		Target.y = 0;
		Target.h = src->h;
		SDL_BlitSurface(src, &Target, dst, &Target);
	}

	/* top strip */
	Target.x = dstrect->x;
	Target.w = dstrect->w;
	Target.y = 0;
	if(Target.h = dstrect->y)
		SDL_BlitSurface(src, &Target, dst, &Target);

	/* bottom strip */
	Target.y = dstrect->y+dstrect->h;
	if(Target.h = src->h-Target.y)
		SDL_BlitSurface(src, &Target, dst, &Target);

	SDL_UpdateRect(dst, 0, 0, 0, 0);
}
示例#29
0
文件: sdl.c 项目: sbp/cadr
void
sdl_set_bow_mode(char new_mode)
{
  unsigned char *p = screen->pixels;
  int i, j;

#if 0
  printf("Setting Black-on-White mode: was %d, setting %d\n",
	 video_bow_mode, new_mode);
#endif
  if (video_bow_mode == new_mode)
    return;

  /* Need to complement it */
  video_bow_mode = new_mode;

  for (i = 0; i < video_width; i++)
    for (j = 0; j < video_height; j++) {
      *p = ~*p;
      p++;
    }

  SDL_UpdateRect(screen, 0, 0, video_width, video_height);
}
void ContinueHere()
{
bool GotoIntro = false;
bool ContinueWithThisLevel = false;
LevelHeight=1; SetLevelHeight(LevelHeight);
ClearLevel();
ReDrawScreen();
{Print (120,80,   " PLUS:      ");}
{Print (120,90,   "   Exit     ");}
{Print (120,108,  " OK:        ");}
{Print (120,118,  "   Continue ");}
SDL_UpdateRect(DisplaySurface,0,0,0,0);


    getInput();
    while(Key_ESCAPE_pressed == false && Key_ENTER_pressed == false)
	{
     getInput();
     if(Key_ESCAPE_pressed == true){GotoIntro = true;}
     if(Key_ENTER_pressed == true) {DrawGuidepoints=true;ContinueWithThisLevel = true;}
     }
if(GotoIntro == true)             {ClearLevel();intro();}
if(ContinueWithThisLevel == true) {LoadLevel(LevelNumber); game_singleplayer();}
}