コード例 #1
0
void PPDisplayDevice::deLetterbox(pp_int32& mouseX, pp_int32& mouseY)
{
	if (needsDeLetterbox)
	{
		SDL_Renderer* theRenderer = SDL_GetRenderer(theWindow);
		
		int rendererW, rendererH;
		SDL_GetRendererOutputSize(theRenderer, &rendererW, &rendererH);

		int surfaceW = realWidth;
		int surfaceH = realHeight;

		float aspectRenderer, aspectSurface;

		aspectRenderer = (float)rendererW / rendererH;
		aspectSurface  = (float)surfaceW  / surfaceH;

		if (aspectSurface < aspectRenderer)
		{
			mouseX += (surfaceH * aspectRenderer - surfaceW) / 2;
		}
		else if (aspectSurface > aspectRenderer)
		{
			mouseY += (surfaceW / aspectRenderer - surfaceH) / 2;
		}
	}
}
コード例 #2
0
ファイル: sdl_main.cpp プロジェクト: DanB91/SDLHero
static void processWindowEvent(SDL_WindowEvent* we){
    switch (we->event) {
        case SDL_WINDOWEVENT_RESIZED:
            printf("SDL_WINDOWEVENT_RESIZED (%d, %d)\n", we->data1, we->data2);
            resizeTexture(&gTexture, &gOsb, we->data1, we->data2,
                    SDL_GetRenderer(SDL_GetWindowFromID(we->windowID)));
            break;
    }
}
コード例 #3
0
ファイル: renderer.cpp プロジェクト: juanAngel/Snake
SDL_Texture *renderer::screenshot(SDL_Window* w){
    SDL_Texture* img = nullptr;

    SDL_Surface* surface = SDL_GetWindowSurface(w);
    SDL_Renderer* renderer = SDL_GetRenderer(w);
    if(surface && renderer){
        SDL_RenderReadPixels(renderer,&surface->clip_rect,surface->format->format
                             ,surface->pixels,surface->pitch);
        img = SDL_CreateTextureFromSurface(renderer,surface);
    }

    return img;
}
コード例 #4
0
ファイル: window.cpp プロジェクト: soulik/LuaSDL-2.0
	int Window::getRenderer(State & state, SDL_Window  * window){
		Stack * stack = state.stack;
		Renderer * interfaceRenderer = state.getInterface<Renderer>("LuaSDL_Renderer");

		SDL_Renderer * renderer = SDL_GetRenderer(window);
		if (renderer){
			interfaceRenderer->push(renderer, false);
		}
		else{
			stack->push<bool>(false);
		}
		return 1;
	}
コード例 #5
0
bool HandleEvent(SDL_Event *Event) {
  bool ShouldQuit = false;

  switch(Event->type) {
    case SDL_QUIT:
    {
      printf("SDL_QUIT\n");
      ShouldQuit = true;
    } break;

    case SDL_WINDOWEVENT:
    {
      switch(Event->window.event) {
        case SDL_WINDOWEVENT_RESIZED:
        {
          printf("SDL_WINDOWEVENT_RESIZED (%d, %d)\n",
                 Event->window.data1,
                 Event->window.data2);
        } break;

        case SDL_WINDOWEVENT_FOCUS_GAINED:
        {
          printf("SDL_WINDOWEVENT_FOCUS_GAINED\n");
        } break;

        case SDL_WINDOWEVENT_EXPOSED:
        {
          printf("Window exposed");
          SDL_Window *Window     = SDL_GetWindowFromID(Event->window.windowID);
          SDL_Renderer *Renderer = SDL_GetRenderer(Window);
          static bool isWhite    = true;

          if (isWhite == true) {
            SDL_SetRenderDrawColor(Renderer, 255, 255, 255, 255);
            isWhite = false;
          }
          else {
            SDL_SetRenderDrawColor(Renderer, 0 , 0, 0, 255);
            isWhite = true;
          }

          SDL_RenderClear(Renderer);
          SDL_RenderPresent(Renderer);
        } break;
      }
    } break;
  }

  return(ShouldQuit);
}
コード例 #6
0
ファイル: sdl_main.cpp プロジェクト: DanB91/SDLHero
static void updateWindow(SDL_Window* window, Texture texture) {
    SDL_Renderer* renderer = SDL_GetRenderer(window);
    SDL_RenderClear(renderer);

    if(SDL_UpdateTexture(texture.sdlTexture, NULL, texture.pixels, 
                texture.width * sizeof(Pixel)) != 0) {
        printSDLErrorAndExit();
    }

    if(SDL_RenderCopy(renderer, texture.sdlTexture, NULL, NULL) != 0) {
        printSDLErrorAndExit();
    }

    SDL_RenderPresent(renderer);
}
コード例 #7
0
ファイル: sdl_echelon.cpp プロジェクト: redabs/Echelon
inline void
SDLHandleEvent(SDL_Event *Event, window_dimensions *WindowDimensions) {
    SDL_Renderer *Renderer;
    SDL_Window *Window;

    Window = SDL_GetWindowFromID(Event->window.windowID);
    Renderer = SDL_GetRenderer(Window);

    switch(Event->type) {

        case SDL_CONTROLLERDEVICEADDED:
            SDLOpenGameControllers();
            break;

        case SDL_CONTROLLERDEVICEREMOVED:
            SDLCloseGameControllers();
            printf("Controller device removed\n");
            break;

        case SDL_CONTROLLERDEVICEREMAPPED:
            printf("Controller device remapped\n");
            break;

        case SDL_QUIT:
            GlobalRunning = false;
            break;

        case SDL_WINDOWEVENT:
            switch(Event->window.event) {
                case SDL_WINDOWEVENT_SIZE_CHANGED:
                    
                    SDLCreateNewTexture(&GlobalBuffer,
                                        Renderer,
                                        Event->window.data1, Event->window.data2,
                                        4);

                    WindowDimensions->Width = Event->window.data1;
                    WindowDimensions->Height = Event->window.data2;
                    break;

                case SDL_WINDOWEVENT_EXPOSED:
                    SDLBlitFrameToWindow(&GlobalBuffer, Renderer);
                    break;
            }
            break;
    }

}
コード例 #8
0
ファイル: Window.cpp プロジェクト: Sackzement/Heroes
bool Renderer::create() {

	SDL_DestroyRenderer(m_renderer);

	m_renderer = SDL_GetRenderer(game.window.getPointer());
	SDL_DestroyRenderer(m_renderer);

	m_renderer = SDL_CreateRenderer(game.window.getPointer(), -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);

	if (!m_renderer) {
		Log(SDL_GetError());
		return false;
	}
	
	return true;
}
コード例 #9
0
// ctor requires just window width & height
SDL::SDL(const char* title, int windowWidth, int windowHeight):window(0), screenSurface(0), renderer(0),
size(windowWidth, windowHeight)
{
	Sprite::sdl = this;
	if( SDL_Init(SDL_INIT_EVERYTHING) < 0 )
	{
		error( "SDL init error: %s\n", SDL_GetError() );
		exit( 1 );
	}

	window = SDL_CreateWindow( title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
		windowWidth, windowHeight, SDL_WINDOW_SHOWN );
	if( !window )
	{
		error("Window could not be created! error: %s\n", SDL_GetError());
		exit( 1 );
	}
	
	// retrieve the surface (collection of pixels) of the window
	screenSurface = SDL_GetWindowSurface( window );
	if( !screenSurface )
    {
    	error( "Could not create screenSurface %s", SDL_GetError() );
    }
    
	// create a hardware accelerated renderer
	// that displays only once per refresh interval
	renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
	if( !renderer )
    {
		error( "Could not create renderer %s", SDL_GetError() );
	    renderer = SDL_GetRenderer( window );
        if( renderer )
        {
        	// delete default to get one with vsync on
        	SDL_DestroyRenderer( renderer );
    		renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
        }
    }
    
	// Turn on alpha blending
	SDL_SetRenderDrawBlendMode( renderer, SDL_BLENDMODE_BLEND );

}
コード例 #10
0
ファイル: window.cpp プロジェクト: Moopli/wesnoth
twindow::operator SDL_Renderer*()
{
	return SDL_GetRenderer(window_);
}
コード例 #11
0
SDL_Renderer* GraphicsSystem::getSystemRenderer()
{
	return SDL_GetRenderer(mpDisplay);
}
コード例 #12
0
ファイル: SDL_render.c プロジェクト: ryanzhao006/IOSAVDecode
SDL_Renderer *
SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
{
    SDL_Renderer *renderer = NULL;
    int n = SDL_GetNumRenderDrivers();
    const char *hint;

    if (!window) {
        SDL_SetError("Invalid window");
        return NULL;
    }

    if (SDL_GetRenderer(window)) {
        SDL_SetError("Renderer already associated with window");
        return NULL;
    }

    hint = SDL_GetHint(SDL_HINT_RENDER_VSYNC);
    if (hint) {
        if (*hint == '0') {
            flags &= ~SDL_RENDERER_PRESENTVSYNC;
        } else {
            flags |= SDL_RENDERER_PRESENTVSYNC;
        }
    }

    if (index < 0) {
        hint = SDL_GetHint(SDL_HINT_RENDER_DRIVER);
        if (hint) {
            for (index = 0; index < n; ++index) {
                const SDL_RenderDriver *driver = render_drivers[index];

                if (SDL_strcasecmp(hint, driver->info.name) == 0) {
                    /* Create a new renderer instance */
                    renderer = driver->CreateRenderer(window, flags);
                    break;
                }
            }
        }

        if (!renderer) {
            for (index = 0; index < n; ++index) {
                const SDL_RenderDriver *driver = render_drivers[index];

                if ((driver->info.flags & flags) == flags) {
                    /* Create a new renderer instance */
                    renderer = driver->CreateRenderer(window, flags);
                    if (renderer) {
                        /* Yay, we got one! */
                        break;
                    }
                }
            }
        }
        if (index == n) {
            SDL_SetError("Couldn't find matching render driver");
            return NULL;
        }
    } else {
        if (index >= SDL_GetNumRenderDrivers()) {
            SDL_SetError("index must be -1 or in the range of 0 - %d",
                         SDL_GetNumRenderDrivers() - 1);
            return NULL;
        }
        /* Create a new renderer instance */
        renderer = render_drivers[index]->CreateRenderer(window, flags);
    }

    if (renderer) {
        renderer->magic = &renderer_magic;
        renderer->window = window;

        if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED) {
            renderer->minimized = SDL_TRUE;
        } else {
            renderer->minimized = SDL_FALSE;
        }

        SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);

        SDL_RenderSetViewport(renderer, NULL);

        SDL_AddEventWatch(SDL_RendererEventWatch, renderer);

        SDL_LogInfo(SDL_LOG_CATEGORY_RENDER,
                    "Created renderer: %s", renderer->info.name);
    }
    return renderer;
}
コード例 #13
0
ファイル: window.cpp プロジェクト: Aishiko/wesnoth
ttexture twindow::create_texture(const int access, const int w, const int h)
{
	return ttexture(*SDL_GetRenderer(window_), pixel_format_, access, w, h);
}
コード例 #14
0
void loadscreen::draw_screen(const std::string &text)
{
	// Set progress bar parameters:
	//
	// RGB-values for finished piece.
	int fcr =  21, fcg =  53, fcb =  80;
	// Groove.
	int lcr =  21, lcg =  22, lcb =  24;
	// Border color.
	int bcr = 188, bcg = 176, bcb = 136;
	// Border width.
	int bw = 1;
	// Border inner spacing width.
	int bispw = 1;
	bw = 2*(bw+bispw) > screen_.getx() ? 0: 2*(bw+bispw) > screen_.gety() ? 0: bw;
	// Available width.
	int scrx = screen_.getx() - 2*(bw+bispw);
	// Available height.
	int scry = screen_.gety() - 2*(bw+bispw);
	// Used width.
	int pbw = scrx/2;
	// Used height.
	int pbh = scry/16;
	// Height of the lighting line.
	int	lightning_thickness = 2;

#if SDL_VERSION_ATLEAST(2,0,0)
	sdl::twindow *wnd = CVideo::get_window();
	SDL_Renderer *rnd = SDL_GetRenderer(*wnd);

	SDL_Rect area;

	// Pump events and make sure to redraw the logo if there's a chance that it's been obscured
	SDL_Event ev;
	while(SDL_PollEvent(&ev)) {
		if(ev.type == SDL_WINDOWEVENT
				&& (ev.window.event == SDL_WINDOWEVENT_RESIZED
					|| ev.window.event == SDL_WINDOWEVENT_EXPOSED))
		{
			logo_drawn_ = false;
		}
	}

	// Draw logo if it was successfully loaded.
	if (!logo_texture_.null() && !logo_drawn_) {
		int x = (screen_.getx () - logo_texture_.width()) / 2;
		int y = ((scry - logo_texture_.height()) / 2) - pbh;

		// Check if we have enough pixels to display it.
		if (x > 0 && y > 0) {
			pby_offset_ = (pbh + logo_texture_.height())/2;
			wnd->draw(logo_texture_, x, y);
		} else {
			if (!screen_.faked()) {  // Avoid error if --nogui is used.
				ERR_DP << "loadscreen: Logo image is too big." << std::endl;
			}
		}
		logo_drawn_ = true;
	}
	int pbx = (scrx - pbw)/2;					// Horizontal location.
	int pby = (scry - pbh)/2 + pby_offset_;		// Vertical location.

	// Draw top border.
	area.x = pbx; area.y = pby;
	area.w = pbw + 2*(bw+bispw); area.h = bw;
	sdl::fill_rect(rnd,&area,bcr,bcg,bcb,255);
	// Draw bottom border.
	area.x = pbx; area.y = pby + pbh + bw + 2*bispw;
	area.w = pbw + 2*(bw+bispw); area.h = bw;
	sdl::fill_rect(rnd,&area,bcr,bcg,bcb,255);
	// Draw left border.
	area.x = pbx; area.y = pby + bw;
	area.w = bw; area.h = pbh + 2*bispw;
	sdl::fill_rect(rnd,&area,bcr,bcg,bcb,255);
	// Draw right border.
	area.x = pbx + pbw + bw + 2*bispw; area.y = pby + bw;
	area.w = bw; area.h = pbh + 2*bispw;
	sdl::fill_rect(rnd,&area,bcr,bcg,bcb,255);
	// Draw the finished bar area.
	area.x = pbx + bw + bispw; area.y = pby + bw + bispw;
	area.w = (prcnt_ * pbw) / 100; area.h = pbh;
	sdl::fill_rect(rnd,&area,fcr,fcg,fcb,255);

	SDL_Rect lightning = area;
	lightning.h = lightning_thickness;
	//we add 25% of white to the color of the bar to simulate a light effect
	sdl::fill_rect(rnd,&lightning,(fcr*3+255)/4,(fcg*3+255)/4,(fcb*3+255)/4,255);
	lightning.y = area.y+area.h-lightning.h;
	//remove 50% of color to simulate a shadow effect
	sdl::fill_rect(rnd,&lightning,fcr/2,fcg/2,fcb/2,255);

	// Draw the leftover bar area.
	area.x = pbx + bw + bispw + (prcnt_ * pbw) / 100; area.y = pby + bw + bispw;
	area.w = ((100 - prcnt_) * pbw) / 100; area.h = pbh;
	sdl::fill_rect(rnd, &area, lcr, lcg, lcb, 255);

	// Clear the last text and draw new if text is provided.
	if (!text.empty())
	{
		sdl::fill_rect(rnd, &textarea_, 0, 0, 0, 255);

		font::ttext txt;
		txt.set_text(text, false);
		// A text-ure... haha, get it?
		sdl::ttexture texture = txt.render_as_texture();
		textarea_.h = texture.height();
		textarea_.w = texture.width();
		textarea_.x = scrx/2 + bw + bispw - textarea_.w / 2;
		textarea_.y = pby + pbh + 4*(bw + bispw);
		wnd->draw(texture, textarea_.x, textarea_.y);
	}
	CVideo::get_window()->render();
#else
	surface gdis = screen_.getSurface();
	SDL_Rect area;

	// Pump events and make sure to redraw the logo if there's a chance that it's been obscured
	SDL_Event ev;
	while(SDL_PollEvent(&ev)) {
		if(ev.type == SDL_VIDEORESIZE || ev.type == SDL_VIDEOEXPOSE)
		{
			logo_drawn_ = false;
		}
	}

	// Draw logo if it was successfully loaded.
	if (logo_surface_ && !logo_drawn_) {
		area.x = (screen_.getx () - logo_surface_->w) / 2;
		area.y = ((scry - logo_surface_->h) / 2) - pbh;
		area.w = logo_surface_->w;
		area.h = logo_surface_->h;
		// Check if we have enough pixels to display it.
		if (area.x > 0 && area.y > 0) {
			pby_offset_ = (pbh + area.h)/2;
			sdl_blit(logo_surface_, 0, gdis, &area);
		} else {
			if (!screen_.faked()) {  // Avoid error if --nogui is used.
				ERR_DP << "loadscreen: Logo image is too big." << std::endl;
			}
		}
		logo_drawn_ = true;
		update_rect(area.x, area.y, area.w, area.h);
	}
	int pbx = (scrx - pbw)/2;					// Horizontal location.
	int pby = (scry - pbh)/2 + pby_offset_;		// Vertical location.

	// Draw top border.
	area.x = pbx; area.y = pby;
	area.w = pbw + 2*(bw+bispw); area.h = bw;
	sdl::fill_rect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
	// Draw bottom border.
	area.x = pbx; area.y = pby + pbh + bw + 2*bispw;
	area.w = pbw + 2*(bw+bispw); area.h = bw;
	sdl::fill_rect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
	// Draw left border.
	area.x = pbx; area.y = pby + bw;
	area.w = bw; area.h = pbh + 2*bispw;
	sdl::fill_rect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
	// Draw right border.
	area.x = pbx + pbw + bw + 2*bispw; area.y = pby + bw;
	area.w = bw; area.h = pbh + 2*bispw;
	sdl::fill_rect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
	// Draw the finished bar area.
	area.x = pbx + bw + bispw; area.y = pby + bw + bispw;
	area.w = (prcnt_ * pbw) / 100; area.h = pbh;
	sdl::fill_rect(gdis,&area,SDL_MapRGB(gdis->format,fcr,fcg,fcb));

	SDL_Rect lightning = area;
	lightning.h = lightning_thickness;
	//we add 25% of white to the color of the bar to simulate a light effect
	sdl::fill_rect(gdis,&lightning,SDL_MapRGB(gdis->format,(fcr*3+255)/4,(fcg*3+255)/4,(fcb*3+255)/4));
	lightning.y = area.y+area.h-lightning.h;
	//remove 50% of color to simulate a shadow effect
	sdl::fill_rect(gdis,&lightning,SDL_MapRGB(gdis->format,fcr/2,fcg/2,fcb/2));

	// Draw the leftover bar area.
	area.x = pbx + bw + bispw + (prcnt_ * pbw) / 100; area.y = pby + bw + bispw;
	area.w = ((100 - prcnt_) * pbw) / 100; area.h = pbh;
	sdl::fill_rect(gdis,&area,SDL_MapRGB(gdis->format,lcr,lcg,lcb));

	// Clear the last text and draw new if text is provided.
	if (!text.empty())
	{
		SDL_Rect oldarea = textarea_;
		sdl::fill_rect(gdis,&textarea_,SDL_MapRGB(gdis->format,0,0,0));
		textarea_ = font::line_size(text, font::SIZE_NORMAL);
		textarea_.x = scrx/2 + bw + bispw - textarea_.w / 2;
		textarea_.y = pby + pbh + 4*(bw + bispw);
		textarea_ = font::draw_text(&screen_,textarea_,font::SIZE_NORMAL,font::NORMAL_COLOR,text,textarea_.x,textarea_.y);
		SDL_Rect refresh = sdl::union_rects(oldarea, textarea_);
		update_rect(refresh.x, refresh.y, refresh.w, refresh.h);
	}
	// Update the rectangle.
	update_rect(pbx, pby, pbw + 2*(bw + bispw), pbh + 2*(bw + bispw));
	screen_.flip();
#endif
}