Esempio n. 1
0
void Window::setFullscreen(Fullscreen var)
{
    switch (var) {
        case Fullscreen::off :
            SDL_SetWindowFullscreen(pointer, 0);
            SDL_SetWindowBordered(pointer, SDL_TRUE);
            setPosition(m_defaultPosSize.x, m_defaultPosSize.y);
            setSize(m_defaultPosSize.w, m_defaultPosSize.h);
			updateAll();
            break;
        case Fullscreen::normal :
        case Fullscreen::fake :
            if (SDL_SetWindowFullscreen(pointer, var) != 0)
                Log(SDL_GetError());
			updateAll();
            break;
        case Fullscreen::window :
            SDL_SetWindowFullscreen(pointer, 0);
            SDL_SetWindowBordered(pointer, SDL_FALSE);
            setPosition(0,0);
            setSize(game.hardware.displays[0].bounds.w, game.hardware.displays[0].bounds.h);
			updateAll();
            break;
    }
    
	updateAll();
}
Esempio n. 2
0
void GameManager::init()
{
	running = true;
	//INITIATE SDL
	SDL_Init(SDL_INIT_EVERYTHING);
	//WINDOW PROPERTIES
	window = SDL_CreateWindow(
		"BREAKOUT",
		SDL_WINDOWPOS_UNDEFINED,
		SDL_WINDOWPOS_UNDEFINED,
		SCREEN_WIDTH,
		SCREEN_HEIGHT,
		SDL_WINDOW_RESIZABLE
		);

	//ERROR HANDLING
	if (window == NULL) {
		cout << "There was an error initializing the window!" << endl
			<< SDL_GetError() << endl;
	}

	//ADD SCREEN TO WINDOW
	screen = SDL_GetWindowSurface(window);

	//TURN ON/OFF BORDERS TRUE = BORDERS
	SDL_SetWindowBordered(window, SDL_TRUE);

}
Esempio n. 3
0
/*
* Initialiser SDL : renvoie la surface principale
**/
SDLWrapper::SDLWrapper(size_t width, size_t height): m_width(width), m_height(height) {
	if (TTF_Init() == -1) {
		throw std::runtime_error(TTF_GetError());
	}

	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)< 0) {
		throw std::runtime_error(SDL_GetError());
	}
	else {
		std::clog << "Audio & Video modules initialized correctly" << std::endl;
	}

	m_window = SDL_CreateWindow("Vector Fractal generation", 100, 100, static_cast<int>(width), static_cast<int>(height), 0);
	SDL_SetWindowBordered(m_window, SDL_TRUE);
	m_renderer = SDL_CreateRenderer(m_window, -1, SDL_RENDERER_SOFTWARE | SDL_RENDERER_TARGETTEXTURE);
	Uint32 format = SDL_GetWindowPixelFormat(m_window);
	if (format != SDL_PIXELFORMAT_RGB888)
	{
		std::cerr << "Window pixel format unsupported, will be slower !" << std::endl;
	}

	m_screen = SDL_CreateTexture(m_renderer,
		SDL_PIXELFORMAT_RGB888,
		SDL_TEXTUREACCESS_STREAMING,
		static_cast<int>(width), static_cast<int>(height)
		);

	std::atexit(SDL_Quit);

	std::clog << "SDL initialization OK" << std::endl;
}
bool GraphicsWindowSDL2::setWindowDecorationImplementation(bool flag)
{
    if(!mWindow) return false;

    SDL_SetWindowBordered(mWindow, flag ? SDL_TRUE : SDL_FALSE);
    return true;
}
Esempio n. 5
0
        void WindowSDL2::bordered(bool enable) {

            if(closed) {
                return;
            }

            SDL_SetWindowBordered( window, enable ? SDL_TRUE : SDL_FALSE );

        } //bordered
Esempio n. 6
0
    void set_style(Window& _window, WindowStyle _style)
    {
        ASSERT(_window._sdlWindow != nullptr, "");

        switch (_style) {
        case WindowStyle::cWindowed:
            SDL_SetWindowBordered(_window._sdlWindow, SDL_TRUE);
            SDL_SetWindowFullscreen(_window._sdlWindow, 0);
            break;

        case WindowStyle::cFullscreen:
            SDL_SetWindowFullscreen(_window._sdlWindow, SDL_WINDOW_FULLSCREEN);
            break;

        case WindowStyle::cBorderlessWindow:
            SDL_SetWindowBordered(_window._sdlWindow, SDL_FALSE);
            SDL_SetWindowFullscreen(_window._sdlWindow, SDL_WINDOW_FULLSCREEN_DESKTOP);
            break;
        }
    }
Esempio n. 7
0
/** Toggle native window between fullscreen and normal mode */
void FLinuxWindow::SetWindowMode( EWindowMode::Type NewWindowMode )
{
	if( NewWindowMode != WindowMode )
	{
		switch( NewWindowMode )
		{
			// Fullscreen and WindowedFullscreen both use SDL_WINDOW_FULLSCREEN_DESKTOP now
			//  and code elsewhere handles the backbufer blit properly. This solves several
			//  problems that actual mode switches cause, and a GPU scales better than your
			//  cheap LCD display anyhow.
			case EWindowMode::Fullscreen:
			case EWindowMode::WindowedFullscreen:
			{
				if ( bWasFullscreen != true )
				{
					SDL_SetWindowSize( HWnd, VirtualWidth, VirtualHeight );
					SDL_SetWindowFullscreen( HWnd, SDL_WINDOW_FULLSCREEN_DESKTOP );
					bWasFullscreen = true;
				}
			}	break;

			case EWindowMode::Windowed:
			{
				// when going back to windowed from desktop, make window smaller (but not too small),
				// since some too smart window managers (Compiz) will maximize the window if it's set to desktop size.
				// @FIXME: [RCL] 2015-02-10: this is a hack.
				int SmallerWidth = FMath::Max(100, VirtualWidth - 100);
				int SmallerHeight = FMath::Max(100, VirtualHeight - 100);
				SDL_SetWindowSize(HWnd, SmallerWidth, SmallerHeight);

				SDL_SetWindowFullscreen( HWnd, 0 );
				SDL_SetWindowBordered( HWnd, SDL_TRUE );

				SDL_SetWindowGrab( HWnd, SDL_FALSE );

				bWasFullscreen = false;
			}	break;
		}


		WindowMode = NewWindowMode;
	}
}
Esempio n. 8
0
    void VideoWrapper::setVideoMode(int width, int height, bool fullscreen, bool windowBorder)
    {
        SDL_SetWindowFullscreen(mWindow, 0);

        if (SDL_GetWindowFlags(mWindow) & SDL_WINDOW_MAXIMIZED)
            SDL_RestoreWindow(mWindow);

        if (fullscreen)
        {
            SDL_DisplayMode mode;
            SDL_GetWindowDisplayMode(mWindow, &mode);
            mode.w = width;
            mode.h = height;
            SDL_SetWindowDisplayMode(mWindow, &mode);
            SDL_SetWindowFullscreen(mWindow, fullscreen);
        }
        else
        {
            SDL_SetWindowSize(mWindow, width, height);
            SDL_SetWindowBordered(mWindow, windowBorder ? SDL_TRUE : SDL_FALSE);
        }
    }
Esempio n. 9
0
bool ZWindow::CreateWindow(const char *title,int x, int y, int w, int h, uint32_t flags)
{
	if (m_win)
		return false;
	m_win= SDL_CreateWindow(title, x,y,w,h,flags);
	
	if (m_win ){
		SDL_SetWindowBordered(m_win,SDL_FALSE);
		//SDL_SetWindowTransparent(m_win,SDL_TRUE);
		SDL_SetWindowData(m_win,WND_USER_DATA,this);

#ifdef WIN32
		SDL_SetWindowData(m_win,"EV_HitTest",WindowHitTestHandle);
		SDL_SetWindowData(m_win,"EV_Render",WindowRenderHandle);
#endif

		m_render=new ZRenerder(m_win);
		m_mgr.Init(this);
		Init();
		return true;
	}
	else
		return false;
}
Esempio n. 10
0
static int display(struct vidisp_st *st, const char *title,
		   const struct vidframe *frame)
{
	void *pixels;
	uint8_t *d;
	int dpitch, ret;
	unsigned i, h;
	uint32_t format;

	if (!st || !frame)
		return EINVAL;

	format = match_fmt(frame->fmt);
	if (format == SDL_PIXELFORMAT_UNKNOWN) {
		warning("sdl2: pixel format not supported (%s)\n",
			vidfmt_name(frame->fmt));
		return ENOTSUP;
	}

	if (!vidsz_cmp(&st->size, &frame->size) || frame->fmt != st->fmt) {
		if (st->size.w && st->size.h) {
			info("sdl: reset size:"
			     " %s %u x %u ---> %s %u x %u\n",
			     vidfmt_name(st->fmt), st->size.w, st->size.h,
			     vidfmt_name(frame->fmt),
			     frame->size.w, frame->size.h);
		}
		sdl_reset(st);
	}

	if (!st->window) {
		char capt[256];

		st->flags = SDL_WINDOW_SHOWN | SDL_WINDOW_INPUT_FOCUS;

		if (st->fullscreen)
			st->flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;

		if (title) {
			re_snprintf(capt, sizeof(capt), "%s - %u x %u",
				    title, frame->size.w, frame->size.h);
		}
		else {
			re_snprintf(capt, sizeof(capt), "%u x %u",
				    frame->size.w, frame->size.h);
		}

		st->window = SDL_CreateWindow(capt,
					      SDL_WINDOWPOS_CENTERED,
					      SDL_WINDOWPOS_CENTERED,
					      frame->size.w, frame->size.h,
					      st->flags);
		if (!st->window) {
			warning("sdl: unable to create sdl window: %s\n",
				SDL_GetError());
			return ENODEV;
		}

		st->size = frame->size;
		st->fmt = frame->fmt;

		SDL_RaiseWindow(st->window);
		SDL_SetWindowBordered(st->window, true);
		SDL_ShowWindow(st->window);
	}

	if (!st->renderer) {

		Uint32 flags = 0;

		flags |= SDL_RENDERER_ACCELERATED;
		flags |= SDL_RENDERER_PRESENTVSYNC;

		st->renderer = SDL_CreateRenderer(st->window, -1, flags);
		if (!st->renderer) {
			warning("sdl: unable to create renderer: %s\n",
				SDL_GetError());
			return ENOMEM;
		}
	}

	if (!st->texture) {

		st->texture = SDL_CreateTexture(st->renderer,
						format,
						SDL_TEXTUREACCESS_STREAMING,
						frame->size.w, frame->size.h);
		if (!st->texture) {
			warning("sdl: unable to create texture: %s\n",
				SDL_GetError());
			return ENODEV;
		}
	}

	ret = SDL_LockTexture(st->texture, NULL, &pixels, &dpitch);
	if (ret != 0) {
		warning("sdl: unable to lock texture (ret=%d)\n", ret);
		return ENODEV;
	}

	d = pixels;
	for (i=0; i<3; i++) {

		const uint8_t *s = frame->data[i];
		unsigned sz, dsz, hstep, wstep;

		if (!frame->data[i] || !frame->linesize[i])
			break;

		hstep = i==0 ? 1 : 2;
		wstep = i==0 ? 1 : chroma_step(frame->fmt);

		dsz = dpitch / wstep;
		sz  = min(frame->linesize[i], dsz);

		for (h = 0; h < frame->size.h; h += hstep) {

			memcpy(d, s, sz);

			s += frame->linesize[i];
			d += dsz;
		}
	}

	SDL_UnlockTexture(st->texture);

	/* Blit the sprite onto the screen */
	SDL_RenderCopy(st->renderer, st->texture, NULL, NULL);

	/* Update the screen! */
	SDL_RenderPresent(st->renderer);

	return 0;
}
Esempio n. 11
0
/**
 * @brief Initializes Game Window.
 * @param TITLE Set the title of the Window.
 * @param Background Set the background of the window.
 * @param SDL_SCREEN_FLAGS Start the window with given flags.
 * @return Returns 0 on success.
 */
int GameWindow::init( const char* TITLE , SDL_Color Background , int SDL_SCREEN_FLAGS )
{
	//If it already was inited, do not bother with it again
	if ( this->inited )
		return 0;

	//Support for Resizeable windows
	//Check if the settings contain the option
	bool resizable;
	if ( this->content->Settings()->getBool ( "window" , "resizeable" , &resizable ) == true )
	{
		//Evaluate if the option is set on
		if ( resizable )
		{
			SDL_SCREEN_FLAGS |= SDL_WINDOW_RESIZABLE;

		}
	}

	//Support for fullscreen windows
	//Check if the settings contain the option
	bool fullscreen;
	if ( this->content->Settings()->getBool ( "window" , "fullscreen", &fullscreen ) == true )
	{
		//Evaluate if the option is set on
		if ( fullscreen )
		{
			SDL_SCREEN_FLAGS |=
//Build option to use SDL_WINDOW_FULLSCREEN instead of DESKTOP
#ifdef GAME_WINDOW_USE_WINDOW_FULLSCREEN
				SDL_WINDOW_FULLSCREEN;
#else
				SDL_WINDOW_FULLSCREEN_DESKTOP;
#endif
		}
	}

	int display = 0;
	this->content->Settings()->getInt ( "window" , "display" , &display );


	//Set display to be rendered to
	SDL_DisplayMode display_mode;
	if ( SDL_GetDisplayMode( display , 0 , &display_mode ) != 0 )
	{
		display = 0;
		std::cout << "An error has occurred" << std::endl << SDL_GetError() << std::endl;
		std::cout << "Defaulting to display index : " << display << std::endl;
	}

	int WIDTH = 800;
	if ( this->content->Settings()->getInt( "window" , "width" , &WIDTH ) == false )
	{
		std::string native;
		if ( this->content->Settings()->get ( "window" , "width" , &native ) == true )
		{
			if ( native == "native" )
			{
				//Set height as native screen width
				SDL_DisplayMode dm;
				if ( SDL_GetDesktopDisplayMode( display , &dm ) == 0 )
				{
					WIDTH = dm.w;
				}
			}
		}
		if ( WIDTH == 800 )
		{
			std::cout << "Warning! Window width is set to default, 800px" << std::endl;
		}
	}

	int HIEGHT = 600;
	if ( this->content->Settings()->getInt( "window" , "height" , &HIEGHT ) == false )
	{
		std::string native;
		if ( this->content->Settings()->get ( "window" , "height" , &native ) == true )
		{
			if ( native == "native" )
			{
				//Set height as native screen height
				SDL_DisplayMode dm;
				if ( SDL_GetDesktopDisplayMode( display , &dm ) == 0 )
				{
					HIEGHT = dm.h;
				}
			}
		}
		if ( HIEGHT == 600 )
		{
			std::cout << "Warning! Window height is set to default, 600px" << std::endl;
		}
	}


	//Create the window
	this->window = SDL_CreateWindow (  TITLE
									   , SDL_WINDOWPOS_CENTERED_DISPLAY( display )
									   , SDL_WINDOWPOS_CENTERED_DISPLAY( display )
									   , WIDTH
									   , HIEGHT
									   , SDL_SCREEN_FLAGS );

	//Set minimum size of window (640x480)
	SDL_SetWindowMinimumSize( this->window , 640, 480 );
	SDL_SetWindowDisplayMode( this->window , &display_mode );

	//Check if the window was created
	if ( this->window == nullptr )
	{
		std::cout << "An error has occurred" << std::endl << SDL_GetError() << std::endl;
		std::cerr << SDL_GetError() << std::endl;
		return 1;
	}

	int render_flags = SDL_RENDERER_ACCELERATED;
	//Support for SDL_Render VSync
	//Check if the settings contain the option
	bool vsync;
	if ( this->content->Settings()->getBool ( "window" , "vsync" , &vsync ) )
	{
		//Evaluate if the option is set on
		if ( vsync )
		{
			//render_flags |= SDL_RENDERER_PRESENTVSYNC;
			this->CAP_FRAMES = true;
		}
	}

	int FRAME_LIMIT = display_mode.refresh_rate;
	if ( this->content->Settings()->getInt ( "window" , "framelimit" , &FRAME_LIMIT ) )
	{
		std::cout << FRAME_LIMIT << std::endl;
		if ( FRAME_LIMIT > 0 )
		{
			this->FRAME_LIMIT = FRAME_LIMIT;
		}
		else
		{
			std::cout << "Cannot set negative Frame Limit " << FRAME_LIMIT << std::endl;
		}
	}
	else
	{
		this->FRAME_LIMIT = FRAME_LIMIT;
	}


	bool windowborder = false;
	if ( this->content->Settings()->getBool ( "window" , "borderless" , &windowborder ) )
	{
		if ( windowborder )
		{
			SDL_SetWindowBordered( this->window ,  SDL_FALSE );
		}
	}

	//Create Renderer
	this->renderer = SDL_CreateRenderer ( this->window , -1 , render_flags );

	//Make sure it was created correctly
	if ( this->renderer == nullptr )
	{
		std::cout << "An error has occurred" << std::endl << SDL_GetError() << std::endl;
		std::cerr << SDL_GetError() << std::endl;
		return 1;
	}

	//Set background colour
	this->background = Background;

	//Check if the System has a battery
	this->has_battery = etc::has_battery();

	//Camera bnounds
	this->camera.setBounds( WIDTH , HIEGHT );
	this->camera.setPosition( 0, 0 );

	this->textures = graphics::TextureManager(this->renderer);
	this->content->Maps()->init(&(this->textures) , this->content->TileTypes());
	this->content->load();

	this->inited = true;
	//All done correctly

	return 0;
}
Esempio n. 12
0
void
SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
{
    int i;

    if (state->verbose & VERBOSE_EVENT) {
        SDLTest_PrintEvent(event);
    }

    switch (event->type) {
    case SDL_WINDOWEVENT:
        switch (event->window.event) {
        case SDL_WINDOWEVENT_SIZE_CHANGED:
            {
                SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
                if (window) {
                    for (i = 0; i < state->num_windows; ++i) {
                        if (window == state->windows[i] &&
                            (state->window_flags & SDL_WINDOW_RESIZABLE)) {
                            SDL_Rect viewport;

                            viewport.x = 0;
                            viewport.y = 0;
                            SDL_GetWindowSize(window, &viewport.w, &viewport.h);
                            SDL_RenderSetViewport(state->renderers[i], &viewport);
                        }
                    }
                }
            }
            break;
        case SDL_WINDOWEVENT_CLOSE:
			{
                SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
                if (window) {
					SDL_DestroyWindow(window);
				}
			}
            break;
        }
        break;
    case SDL_KEYDOWN:
        switch (event->key.keysym.sym) {
            /* Add hotkeys here */
        case SDLK_PRINTSCREEN: {
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    for (i = 0; i < state->num_windows; ++i) {
                        if (window == state->windows[i]) {
                            SDLTest_ScreenShot(state->renderers[i]);
                        }
                    }
                }
            }
            break;
        case SDLK_EQUALS:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrt-+ double the size of the window */
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    int w, h;
                    SDL_GetWindowSize(window, &w, &h);
                    SDL_SetWindowSize(window, w*2, h*2);
                }
            }
            break;
        case SDLK_MINUS:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrt-- double the size of the window */
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    int w, h;
                    SDL_GetWindowSize(window, &w, &h);
                    SDL_SetWindowSize(window, w/2, h/2);
                }
            }
            break;
        case SDLK_c:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-C copy awesome text! */
                SDL_SetClipboardText("SDL rocks!\nYou know it!");
                printf("Copied text to clipboard\n");
            }
            break;
        case SDLK_v:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-V paste awesome text! */
                char *text = SDL_GetClipboardText();
                if (*text) {
                    printf("Clipboard: %s\n", text);
                } else {
                    printf("Clipboard is empty\n");
                }
                SDL_free(text);
            }
            break;
        case SDLK_g:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-G toggle grab */
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    SDL_SetWindowGrab(window, !SDL_GetWindowGrab(window));
                }
            }
            break;
        case SDLK_m:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-M maximize */
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    Uint32 flags = SDL_GetWindowFlags(window);
                    if (flags & SDL_WINDOW_MAXIMIZED) {
                        SDL_RestoreWindow(window);
                    } else {
                        SDL_MaximizeWindow(window);
                    }
                }
            }
            break;
        case SDLK_r:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-R toggle mouse relative mode */
                SDL_SetRelativeMouseMode(!SDL_GetRelativeMouseMode());
            }
            break;
        case SDLK_z:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-Z minimize */
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    SDL_MinimizeWindow(window);
                }
            }
            break;
        case SDLK_RETURN:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-Enter toggle fullscreen */
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    Uint32 flags = SDL_GetWindowFlags(window);
                    if (flags & SDL_WINDOW_FULLSCREEN) {
                        SDL_SetWindowFullscreen(window, SDL_FALSE);
                    } else {
                        SDL_SetWindowFullscreen(window, SDL_TRUE);
                    }
                }
            }
            break;
        case SDLK_b:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-B toggle window border */
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    const Uint32 flags = SDL_GetWindowFlags(window);
                    const SDL_bool b = ((flags & SDL_WINDOW_BORDERLESS) != 0);
                    SDL_SetWindowBordered(window, b);
                }
            }
            break;
        case SDLK_1:
            if (event->key.keysym.mod & KMOD_CTRL) {
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Test Message", "You're awesome!", window);
            }
            break;
        case SDLK_ESCAPE:
            *done = 1;
            break;
        default:
            break;
        }
        break;
    case SDL_QUIT:
        *done = 1;
        break;
    }
}
Esempio n. 13
0
static int display(struct vidisp_st *st, const char *title,
		   const struct vidframe *frame)
{
	void *pixels;
	uint8_t *p;
	int pitch, ret;
	unsigned i, h;

	if (!vidsz_cmp(&st->size, &frame->size)) {
		if (st->size.w && st->size.h) {
			info("sdl: reset size: %u x %u ---> %u x %u\n",
			     st->size.w, st->size.h,
			     frame->size.w, frame->size.h);
		}
		sdl_reset(st);
	}

	if (!st->window) {
		Uint32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_INPUT_FOCUS;
		char capt[256];

		if (st->fullscreen)
			flags |= SDL_WINDOW_FULLSCREEN;

		if (title) {
			re_snprintf(capt, sizeof(capt), "%s - %u x %u",
				    title, frame->size.w, frame->size.h);
		}
		else {
			re_snprintf(capt, sizeof(capt), "%u x %u",
				    frame->size.w, frame->size.h);
		}

		st->window = SDL_CreateWindow(capt,
					      SDL_WINDOWPOS_CENTERED,
					      SDL_WINDOWPOS_CENTERED,
					      frame->size.w, frame->size.h,
					      flags);
		if (!st->window) {
			warning("sdl: unable to create sdl window: %s\n",
				SDL_GetError());
			return ENODEV;
		}

		st->size = frame->size;

		SDL_RaiseWindow(st->window);
		SDL_SetWindowBordered(st->window, true);
		SDL_ShowWindow(st->window);
	}

	if (!st->renderer) {

		Uint32 flags = 0;

		flags |= SDL_RENDERER_ACCELERATED;
		flags |= SDL_RENDERER_PRESENTVSYNC;

		st->renderer = SDL_CreateRenderer(st->window, -1, flags);
		if (!st->renderer) {
			warning("sdl: unable to create renderer: %s\n",
				SDL_GetError());
			return ENOMEM;
		}
	}

	if (!st->texture) {

		st->texture = SDL_CreateTexture(st->renderer,
						SDL_PIXELFORMAT_IYUV,
						SDL_TEXTUREACCESS_STREAMING,
						frame->size.w, frame->size.h);
		if (!st->texture) {
			warning("sdl: unable to create texture: %s\n",
				SDL_GetError());
			return ENODEV;
		}
	}

	ret = SDL_LockTexture(st->texture, NULL, &pixels, &pitch);
	if (ret != 0) {
		warning("sdl: unable to lock texture (ret=%d)\n", ret);
		return ENODEV;
	}

	p = pixels;
	for (i=0; i<3; i++) {

		const uint8_t *s   = frame->data[i];
		const unsigned stp = frame->linesize[0] / frame->linesize[i];
		const unsigned sz  = frame->size.w / stp;

		for (h = 0; h < frame->size.h; h += stp) {

			memcpy(p, s, sz);

			s += frame->linesize[i];
			p += (pitch / stp);
		}
	}

	SDL_UnlockTexture(st->texture);

	/* Blit the sprite onto the screen */
	SDL_RenderCopy(st->renderer, st->texture, NULL, NULL);

	/* Update the screen! */
	SDL_RenderPresent(st->renderer);

	return 0;
}
Esempio n. 14
0
 void Window::setBorder(bool use_border) const {
     SDL_SetWindowBordered(_wnd, use_border ? SDL_TRUE : SDL_FALSE);
 }
Esempio n. 15
0
 void bordered(bool b = true) noexcept {
     SDL_SetWindowBordered(ptr.get(), b ? SDL_TRUE : SDL_FALSE);
 }
Esempio n. 16
0
void Window::setBorderless(SDL_Window* window, SDL_bool bordered)
{
	SDL_SetWindowBordered(window, bordered);
}
Esempio n. 17
0
void openvox::Window::setBorderless(bool useBorderless, bool overrideCheck /*= false*/) {
    if ((overrideCheck || m_displayMode.isBorderless != useBorderless) && !m_displayMode.isFullscreen) {
        m_displayMode.isBorderless = useBorderless;
        SDL_SetWindowBordered((SDL_Window*)m_window, m_displayMode.isBorderless ? SDL_FALSE : SDL_TRUE);
    }
}
Esempio n. 18
0
void
SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
{
    int i;
    static SDL_MouseMotionEvent lastEvent;

    if (state->verbose & VERBOSE_EVENT) {
        SDLTest_PrintEvent(event);
    }

    switch (event->type) {
    case SDL_WINDOWEVENT:
        switch (event->window.event) {
        case SDL_WINDOWEVENT_CLOSE:
            {
                SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
                if (window) {
                    SDL_DestroyWindow(window);
                }
            }
            break;
        }
        break;
    case SDL_KEYDOWN:
        switch (event->key.keysym.sym) {
            /* Add hotkeys here */
        case SDLK_PRINTSCREEN: {
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    for (i = 0; i < state->num_windows; ++i) {
                        if (window == state->windows[i]) {
                            SDLTest_ScreenShot(state->renderers[i]);
                        }
                    }
                }
            }
            break;
        case SDLK_EQUALS:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-+ double the size of the window */
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    int w, h;
                    SDL_GetWindowSize(window, &w, &h);
                    SDL_SetWindowSize(window, w*2, h*2);
                }
            }
            break;
        case SDLK_MINUS:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-- half the size of the window */
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    int w, h;
                    SDL_GetWindowSize(window, &w, &h);
                    SDL_SetWindowSize(window, w/2, h/2);
                }
            }
            break;
        case SDLK_c:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-C copy awesome text! */
                SDL_SetClipboardText("SDL rocks!\nYou know it!");
                printf("Copied text to clipboard\n");
            }
            if (event->key.keysym.mod & KMOD_ALT) {
                /* Alt-C toggle a render clip rectangle */
                for (i = 0; i < state->num_windows; ++i) {
                    int w, h;
                    if (state->renderers[i]) {
                        SDL_Rect clip;
                        SDL_GetWindowSize(state->windows[i], &w, &h);
                        SDL_RenderGetClipRect(state->renderers[i], &clip);
                        if (SDL_RectEmpty(&clip)) {
                            clip.x = w/4;
                            clip.y = h/4;
                            clip.w = w/2;
                            clip.h = h/2;
                            SDL_RenderSetClipRect(state->renderers[i], &clip);
                        } else {
                            SDL_RenderSetClipRect(state->renderers[i], NULL);
                        }
                    }
                }
            }
            break;
        case SDLK_v:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-V paste awesome text! */
                char *text = SDL_GetClipboardText();
                if (*text) {
                    printf("Clipboard: %s\n", text);
                } else {
                    printf("Clipboard is empty\n");
                }
                SDL_free(text);
            }
            break;
        case SDLK_g:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-G toggle grab */
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    SDL_SetWindowGrab(window, !SDL_GetWindowGrab(window) ? SDL_TRUE : SDL_FALSE);
                }
            }
            break;
        case SDLK_m:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-M maximize */
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    Uint32 flags = SDL_GetWindowFlags(window);
                    if (flags & SDL_WINDOW_MAXIMIZED) {
                        SDL_RestoreWindow(window);
                    } else {
                        SDL_MaximizeWindow(window);
                    }
                }
            }
            break;
        case SDLK_r:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-R toggle mouse relative mode */
                SDL_SetRelativeMouseMode(!SDL_GetRelativeMouseMode() ? SDL_TRUE : SDL_FALSE);
            }
            break;
        case SDLK_z:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-Z minimize */
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    SDL_MinimizeWindow(window);
                }
            }
            break;
        case SDLK_RETURN:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-Enter toggle fullscreen */
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    Uint32 flags = SDL_GetWindowFlags(window);
                    if (flags & SDL_WINDOW_FULLSCREEN) {
                        SDL_SetWindowFullscreen(window, SDL_FALSE);
                    } else {
                        SDL_SetWindowFullscreen(window, SDL_TRUE);
                    }
                }
            } else if (event->key.keysym.mod & KMOD_ALT) {
                /* Alt-Enter toggle fullscreen desktop */
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    Uint32 flags = SDL_GetWindowFlags(window);
                    if (flags & SDL_WINDOW_FULLSCREEN) {
                        SDL_SetWindowFullscreen(window, SDL_FALSE);
                    } else {
                        SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
                    }
                }
            }
            break;
        case SDLK_b:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-B toggle window border */
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    const Uint32 flags = SDL_GetWindowFlags(window);
                    const SDL_bool b = ((flags & SDL_WINDOW_BORDERLESS) != 0) ? SDL_TRUE : SDL_FALSE;
                    SDL_SetWindowBordered(window, b);
                }
            }
            break;
        case SDLK_0:
            if (event->key.keysym.mod & KMOD_CTRL) {
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Test Message", "You're awesome!", window);
            }
            break;
        case SDLK_1:
            if (event->key.keysym.mod & KMOD_CTRL) {
                FullscreenTo(0, event->key.windowID);
            }
            break;
        case SDLK_2:
            if (event->key.keysym.mod & KMOD_CTRL) {
                FullscreenTo(1, event->key.windowID);
            }
            break;
        case SDLK_ESCAPE:
            *done = 1;
            break;
        case SDLK_SPACE:
        {
            char message[256];
            SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);

            SDL_snprintf(message, sizeof(message), "(%i, %i), rel (%i, %i)\n", lastEvent.x, lastEvent.y, lastEvent.xrel, lastEvent.yrel);
            SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Last mouse position", message, window);
            break;
        }
        default:
            break;
        }
        break;
    case SDL_QUIT:
        *done = 1;
        break;
    case SDL_MOUSEMOTION:
        lastEvent = event->motion;
        break;
    }
}
Esempio n. 19
0
	int inline Window::setWindowBordered(State & state, SDL_Window  * window){
		Stack * stack = state.stack;
		SDL_SetWindowBordered(window, static_cast<SDL_bool>(stack->to<bool>(1)));
		return 0;
	}