Пример #1
0
void Window::getPosition(int &x, int &y, int &displayindex)
{
	if (!window)
	{
		x = y =  0;
		displayindex = 0;
		return;
	}

	displayindex = std::max(SDL_GetWindowDisplayIndex(window), 0);

	SDL_GetWindowPosition(window, &x, &y);

	// In SDL <= 2.0.3, fullscreen windows are always reported as 0,0. In every
	// other case we need to convert the position from global coordinates to the
	// monitor's coordinate space.
	if (x != 0 || y != 0)
	{
		SDL_Rect displaybounds = {};
		SDL_GetDisplayBounds(displayindex, &displaybounds);

		x -= displaybounds.x;
		y -= displaybounds.y;
	}
}
Пример #2
0
SDL_Rect CVideo::bound() const
{
	SDL_Rect rc;
	int display = window? SDL_GetWindowDisplayIndex(window): 0;
	SDL_GetDisplayBounds(display, &rc);
	return rc;
}
Пример #3
0
void Window::SetMaxMinResolution( SDL_Window * window, int &min_width, int &min_height, int &max_width, int &max_height  ){
   if( window == NULL or window == nullptr ){
      return;
   }

   int DisplayIndex = SDL_GetWindowDisplayIndex( window );
   SDL_DisplayMode CurrentDisplayMode;

   if( SDL_GetDisplayMode( DisplayIndex, SDL_GetNumDisplayModes( DisplayIndex ) - 1, &CurrentDisplayMode ) == 0 ){
      min_width = CurrentDisplayMode.w;
      min_height = CurrentDisplayMode.h;
      logger << ( "[LOG] Minimal resolution: " + to_string( min_width ) + "x" + to_string( min_height ) );
   }
   else{
      logger << ( "[ERROR] SDL_GetDisplayMode: " + string( SDL_GetError() ) );
      return;
   }
   SDL_SetWindowMinimumSize( window, min_width, min_height );

   if( SDL_GetDisplayMode( DisplayIndex, 0, &CurrentDisplayMode ) == 0 ){
      max_width = CurrentDisplayMode.w;
      max_height = CurrentDisplayMode.h;
      logger << ( "[LOG] Maximal resolution: " + to_string( max_width ) + "x" + to_string( max_height ) );
   }
   else{
      logger << ( "[ERROR] SDL_GetDisplayMode: " + string( SDL_GetError() ) );
      return;
   }
   SDL_SetWindowMaximumSize( window, max_width, max_height );
}
Пример #4
0
/*
===============
GLimp_DetectAvailableModes
===============
*/
static bool GLimp_DetectAvailableModes(void)
{
	int i;
	char buf[ MAX_STRING_CHARS ] = { 0 };
	SDL_Rect modes[ 128 ];
	int numModes = 0;

	int display = SDL_GetWindowDisplayIndex( screen );
	SDL_DisplayMode windowMode;

	if( SDL_GetWindowDisplayMode( screen, &windowMode ) < 0 )
	{
		Com_Printf( "Couldn't get window display mode, no resolutions detected (%s).\n", SDL_GetError() );
		return false;
	}

	int numDisplayModes = SDL_GetNumDisplayModes( display );
	for( i = 0; i < numDisplayModes; i++ )
	{
		SDL_DisplayMode mode;

		if( SDL_GetDisplayMode( display, i, &mode ) < 0 )
			continue;

		if( !mode.w || !mode.h )
		{
			Com_Printf( "Display supports any resolution\n" );
			return true;
		}

		if( windowMode.format != mode.format )
			continue;

		modes[ numModes ].w = mode.w;
		modes[ numModes ].h = mode.h;
		numModes++;
	}

	if( numModes > 1 )
		qsort( modes, numModes, sizeof( SDL_Rect ), GLimp_CompareModes );

	for( i = 0; i < numModes; i++ )
	{
		const char *newModeString = va( "%ux%u ", modes[ i ].w, modes[ i ].h );

		if( strlen( newModeString ) < (int)sizeof( buf ) - strlen( buf ) )
			Q_strcat( buf, sizeof( buf ), newModeString );
		else
			Com_Printf( "Skipping mode %ux%x, buffer too small\n", modes[ i ].w, modes[ i ].h );
	}

	if( *buf )
	{
		buf[ strlen( buf ) - 1 ] = 0;
		Com_Printf( "Available modes: '%s'\n", buf );
		ri->Cvar_Set( "r_availableModes", buf );
	}

	return true;
}
Пример #5
0
bool KPSdl2UserInterface::IsWindowResolutionSupported(
    int width, int height) const
{
    int index;
    SDL_Rect rect;

    if (window == nullptr)
    {
        // If there is no window opened yet we just can make a guess.
        index = 0;
    }
    else
    {
        index = SDL_GetWindowDisplayIndex(window);
    }

    if (index < 0)
    {
        BLogger::Log("*** SDL_GetWindowDisplayIndex error: ", SDL_GetError());
        return false;
    }

    auto result = SDL_GetDisplayBounds(index, &rect);

    if (result < 0)
    {
        BLogger::Log("*** SDL_GetDisplayBounds error: ", SDL_GetError());
        return false;
    }

    return width <= rect.w && (height <= rect.h);
}
Пример #6
0
static void _GetBestFullscreenResolution( SDL_HWindow hWnd, int32 *pWidth, int32 *pHeight )
{
	uint32 InitializedMode = false;
	uint32 BestWidth = 0;
	uint32 BestHeight = 0;
	uint32 ModeIndex = 0;

	int32 dsp_idx = SDL_GetWindowDisplayIndex( hWnd );
	if ( dsp_idx < 0 )
	{	dsp_idx = 0;	}

	SDL_DisplayMode dsp_mode;
	FMemory::Memzero( &dsp_mode, sizeof(SDL_DisplayMode) );

	while ( !SDL_GetDisplayMode( dsp_idx, ModeIndex++, &dsp_mode ) )
	{
		bool IsEqualOrBetterWidth  = FMath::Abs((int32)dsp_mode.w - (int32)(*pWidth))  <= FMath::Abs((int32)BestWidth  - (int32)(*pWidth ));
		bool IsEqualOrBetterHeight = FMath::Abs((int32)dsp_mode.h - (int32)(*pHeight)) <= FMath::Abs((int32)BestHeight - (int32)(*pHeight));
		if	(!InitializedMode || (IsEqualOrBetterWidth && IsEqualOrBetterHeight))
		{
			BestWidth = dsp_mode.w;
			BestHeight = dsp_mode.h;
			InitializedMode = true;
		}
	}

	check(InitializedMode);

	*pWidth  = BestWidth;
	*pHeight = BestHeight;
}
Пример #7
0
int video_display(void)
{
    if (window)
        return SDL_GetWindowDisplayIndex(window);
    else
        return -1;
}
Пример #8
0
void SDL2Window::changeMode(DisplayMode mode, bool makeFullscreen) {
	
	if(!m_window) {
		m_size = mode.resolution;
		m_fullscreen = makeFullscreen;
		return;
	}
	
	if(m_fullscreen == makeFullscreen && m_size == mode.resolution) {
		return;
	}
	
	bool wasFullscreen = m_fullscreen;
	
	m_renderer->beforeResize(wasFullscreen || makeFullscreen);
	
	if(makeFullscreen) {
		if(mode.resolution != Vec2i_ZERO) {
			SDL_DisplayMode sdlmode;
			SDL_DisplayMode requested;
			requested.driverdata = NULL;
			requested.format = 0;
			requested.refresh_rate = 0;
			requested.w = mode.resolution.x;
			requested.h = mode.resolution.y;
			int display = SDL_GetWindowDisplayIndex(m_window);
			if(!SDL_GetClosestDisplayMode(display, &requested, &sdlmode)) {
				if(SDL_GetDesktopDisplayMode(display, &sdlmode)) {
					return;
				}
			}
			if(SDL_SetWindowDisplayMode(m_window, &sdlmode) < 0) {
				return;
			}
		}
	}
	
	Uint32 flags = getSDLFlagsForMode(mode.resolution, makeFullscreen);
	if(SDL_SetWindowFullscreen(m_window, flags) < 0) {
		return;
	}
	
	if(!makeFullscreen) {
		SDL_SetWindowSize(m_window, mode.resolution.x, mode.resolution.y);
	}
	
	if(wasFullscreen != makeFullscreen) {
		onToggleFullscreen(makeFullscreen);
	}
	
	if(makeFullscreen) {
		// SDL regrettably sends resize events when a fullscreen window is minimized.
		// Because of that we ignore all size change events when fullscreen.
		// Instead, handle the size change here.
		updateSize();
	}
	
	tick();
}
Пример #9
0
void
loop()
{
    SDL_Event event;
        /* Check for events */
        while (SDL_PollEvent(&event)) {
            SDLTest_CommonEvent(state, &event, &done);

            if (event.type == SDL_WINDOWEVENT) {
                if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
                    SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
                    if (window) {
                        SDL_Log("Window %d resized to %dx%d\n",
                            event.window.windowID,
                            event.window.data1,
                            event.window.data2);
                    }
                }
                if (event.window.event == SDL_WINDOWEVENT_MOVED) {
                    SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
                    if (window) {
                        SDL_Log("Window %d moved to %d,%d (display %s)\n",
                            event.window.windowID,
                            event.window.data1,
                            event.window.data2,
                            SDL_GetDisplayName(SDL_GetWindowDisplayIndex(window)));
                    }
                }
            }
            if (event.type == SDL_KEYUP) {
                SDL_bool updateCursor = SDL_FALSE;

                if (event.key.keysym.sym == SDLK_LEFT) {
                    --system_cursor;
                    if (system_cursor < 0) {
                        system_cursor = SDL_NUM_SYSTEM_CURSORS - 1;
                    }
                    updateCursor = SDL_TRUE;
                } else if (event.key.keysym.sym == SDLK_RIGHT) {
                    ++system_cursor;
                    if (system_cursor >= SDL_NUM_SYSTEM_CURSORS) {
                        system_cursor = 0;
                    }
                    updateCursor = SDL_TRUE;
                }
                if (updateCursor) {
                    SDL_Log("Changing cursor to \"%s\"", cursorNames[system_cursor]);
                    SDL_FreeCursor(cursor);
                    cursor = SDL_CreateSystemCursor((SDL_SystemCursor)system_cursor);
                    SDL_SetCursor(cursor);
                }
            }
        }
#ifdef __EMSCRIPTEN__
    if (done) {
        emscripten_cancel_main_loop();
    }
#endif
}
Пример #10
0
/* get desktop resolution */
static void get_current_resolution(int *w, int *h) {
	int displayidx;
	SDL_Rect rect = { 0, 0, 0, 0 };
	if (window) {
		TCOD_IFNOT(window) return;
		displayidx = SDL_GetWindowDisplayIndex(window);
		TCOD_IFNOT(displayidx >= 0) return;
	} else {
Пример #11
0
int GraphicsManager::getSystemHeight() const {
	int displayIndex = SDL_GetWindowDisplayIndex(_screen);
	SDL_DisplayMode maxHeight;
	// The display mode are sorted by, in this order, greater bpp, largest width, largest height and higher refresh rate.
	SDL_GetDisplayMode(displayIndex, 0, &maxHeight);

	return maxHeight.h;
}
Пример #12
0
bool gutGetDisplayIndex(unsigned *display) {
	chkwin;
	int i;
	i = SDL_GetWindowDisplayIndex(gut.core->window.handle);
	if (i < 0) return false;
	gut.core->window.display = (unsigned) i;
	*display = (unsigned) i;
	return true;
}
Пример #13
0
/*
===============
GLimp_DetectAvailableModes
===============
*/
static void GLimp_DetectAvailableModes() {
    char buf[MAX_STRING_CHARS] = {0};
    SDL_Rect modes[128];
    int numModes = 0;
    int i;
    SDL_DisplayMode windowMode;
    int display;

    display = SDL_GetWindowDisplayIndex(window);

    if (SDL_GetWindowDisplayMode(window, &windowMode) < 0) {
        ri.Printf(PRINT_WARNING, "Couldn't get window display mode: %s\n", SDL_GetError());
        return;
    }

    for (i = 0; i < SDL_GetNumDisplayModes(display); i++) {
        SDL_DisplayMode mode;

        if (SDL_GetDisplayMode(display, i, &mode) < 0) {
            continue;
        }

        if (!mode.w || !mode.h) {
            ri.Printf(PRINT_ALL, "Display supports any resolution\n");
            return;
        }

        if (windowMode.format != mode.format ||
            windowMode.refresh_rate != mode.refresh_rate) {
            continue;
        }

        modes[numModes].w = mode.w;
        modes[numModes].h = mode.h;
        numModes++;
    }

    if (numModes > 1) {
        qsort(modes, numModes, sizeof(SDL_Rect), GLimp_CompareModes);
    }

    for (i = 0; i < numModes; i++) {
        const char* newModeString = va("%ux%u ", modes[i].w, modes[i].h);

        if (strlen(newModeString) < (int) sizeof(buf) - strlen(buf)) {
            Q_strcat(buf, sizeof(buf), newModeString);
        } else {
            ri.Printf(PRINT_WARNING, "Skipping mode %ux%x, buffer too small\n", modes[i].w, modes[i].h);
        }
    }

    if (*buf) {
        ri.Printf(PRINT_ALL, "Available modes: '%s'\n", buf);
        ri.Cvar_Set("r_availableModes", buf);
    }
}
Пример #14
0
void UIInterface::getScreenSize(int *width, int *height)
{
    SDL_Rect bounds;
    int displayIndex = SDL_GetWindowDisplayIndex(this->m_Win);

    SDL_GetDisplayBounds(displayIndex, &bounds);

    if (width) *width = bounds.w;
    if (height) *height = bounds.h;
}
Пример #15
0
		WindowMode getDisplaySize() const override {
			SDL_DisplayMode new_mode;
			int display_index = 0;
			if(window_ != nullptr) {
				display_index = SDL_GetWindowDisplayIndex(window_.get());
			}
			SDL_GetDesktopDisplayMode(display_index, &new_mode);
			WindowMode mode = { new_mode.w, new_mode.h, std::make_shared<SDLPixelFormat>(new_mode.format), new_mode.refresh_rate };
			return mode;
		}
Пример #16
0
static int get_refresh_rate(SDL_Window * win) {

	SDL_DisplayMode mode;
	int displayIndex = SDL_GetWindowDisplayIndex(win);

	if (SDL_GetDesktopDisplayMode(displayIndex, &mode) != 0 ) {
        return 0;
    } else {
    	return mode.refresh_rate;
    }
}
Пример #17
0
static uint32_t getRefreshRate(SDL_Window* window) {
    int displayIndex = SDL_GetWindowDisplayIndex(window);
    SDL_DisplayMode displayMode; //stores refresh rate

    if(SDL_GetDesktopDisplayMode(displayIndex, &displayMode) != 0 
            && displayMode.refresh_rate != 0) {

        return displayMode.refresh_rate;
    }

    return DEFAULT_REFRESH_RATE;
}
Пример #18
0
static void get_closest_mode(int *w, int *h) {
	SDL_DisplayMode wantedmode, closestmode;
	wantedmode.w = *w;
	wantedmode.h = *h;
	wantedmode.format = 0;  /* don't care for rest. */
	wantedmode.refresh_rate = 0;
	wantedmode.driverdata = 0;
	if (SDL_GetClosestDisplayMode(window?SDL_GetWindowDisplayIndex(window):0, &wantedmode, &closestmode) == &closestmode) {
		*w=closestmode.w;
		*h=closestmode.h;
	}
}
Пример #19
0
	void ProcessEvent(OpenBlox::OBGame* gameInst, SDL_Event event){
		switch(event.type){
			case SDL_MOUSEMOTION: {
				SDL_MouseMotionEvent motion = event.motion;
				gameInst->mouseMove(QPoint(motion.x, motion.y));
				break;
			}
			case SDL_MOUSEBUTTONDOWN: {
				SDL_MouseButtonEvent btn = event.button;
				gameInst->mousePress(btn.button, QPoint(btn.x, btn.y));
				break;
			}
			case SDL_KEYDOWN: {
				SDL_KeyboardEvent keyEvt = event.key;
				SDL_Keysym key = keyEvt.keysym;

				#ifndef OPENBLOX_STUDIO
				if(key.sym == SDLK_F11){
					if((SDL_GetWindowFlags(OpenBlox::mw) & SDL_WINDOW_FULLSCREEN) == SDL_WINDOW_FULLSCREEN){
						SDL_SetWindowFullscreen(OpenBlox::mw, 0);
					}else{
						SDL_DisplayMode dm;
						if(SDL_GetDesktopDisplayMode(SDL_GetWindowDisplayIndex(OpenBlox::mw), &dm) == 0){
							SDL_SetWindowDisplayMode(OpenBlox::mw, &dm);
						}
						SDL_SetWindowFullscreen(OpenBlox::mw, SDL_WINDOW_FULLSCREEN);
					}
				}
				#endif
				break;
			}
			case SDL_KEYUP: {
				SDL_KeyboardEvent keyEvt = event.key;
				SDL_Keysym key = keyEvt.keysym;
				Q_UNUSED(key)
				break;
			}
			case SDL_WINDOWEVENT: {
				SDL_WindowEvent wevt = event.window;
				switch(wevt.event){
					case SDL_WINDOWEVENT_RESIZED: {
						gameInst->resized();
					}
				}
				break;
			}
			case SDL_QUIT: {
				shouldQuit = true;
				break;
			}
		}
	}
Пример #20
0
static void video_check_fullscreen_sanity(void) {
	SDL_DisplayMode mode;

	if(SDL_GetCurrentDisplayMode(SDL_GetWindowDisplayIndex(video.window), &mode)) {
		log_warn("SDL_GetCurrentDisplayMode failed: %s", SDL_GetError());
		return;
	}

	if(video.current.width != mode.w || video.current.height != mode.h) {
		log_warn("BUG: window is not actually fullscreen after modesetting. Video mode: %ix%i, window size: %ix%i",
			mode.w, mode.h, video.current.width, video.current.height);
	}
}
Пример #21
0
static int32_t sdl_get_refresh_rate(SDL_Window* window)
{
	int32_t result;
	int32_t index;
	SDL_DisplayMode mode;

	/* default refresh rate is 60 Hz */
	result = DEFAULT_REFRESH_RATE;
	index = SDL_GetWindowDisplayIndex(window);
	if ((SDL_GetDesktopDisplayMode(index, &mode) == 0) && (mode.refresh_rate != 0)) {
		result = mode.refresh_rate;
	}
	return (result);
}
Пример #22
0
//--------------------------------------------------------------------------------------------
bool SDLX_Get_Screen_Info( SDLX_screen_info_t& psi, bool make_report )
{
    Uint32 init_flags = 0;
    SDL_Window *window;

    init_flags = SDL_WasInit( SDL_INIT_EVERYTHING );
    if ( 0 == init_flags )
    {
        if ( make_report ) Log::get().message("ERROR: SDLX_Get_Screen_Info() called before initializing SDL\n");
        return false;
    }
    else if ( HAS_NO_BITS( init_flags, SDL_INIT_VIDEO ) )
    {
        if ( make_report ) Log::get().message("ERROR: SDLX_Get_Screen_Info() called before initializing SDL video driver\n");
        return false;
    }

    // store the screen info for everyone to use
    window = Ego::GraphicsSystem::window;
	psi.window = window;
    SDL_GetWindowSize(window, &(psi.x), &(psi.y));
    SDLX_GetDrawableSize(window, &(psi.drawWidth), &(psi.drawHeight));

    // Grab all the available video modes
    psi.video_mode_list.clear();
    
    int displayNum = SDL_GetWindowDisplayIndex(window);
    int numDisplayModes = SDL_GetNumDisplayModes(displayNum);
    
    for (int i = 0; i < numDisplayModes; i++) {
        SDL_DisplayMode mode;
        SDL_GetDisplayMode(displayNum, i, &mode);
        psi.video_mode_list.push_back(mode);
    }
    
    // log the video driver info
    psi.szDriver = SDL_GetCurrentVideoDriver();

    // grab all SDL_GL_* attributes
    SDLX_sdl_gl_attrib_t::download(psi.gl_att);

    // translate the surface flags into the bitfield
    SDLX_sdl_video_flags_t::download(psi.flags, SDL_GetWindowFlags(window));

    if (make_report)
    {
        SDLX_screen_info_t::report(psi);
    }
    return true;
}
Пример #23
0
void SetBrightness(float val)
{
	/* This function exists because SDL2 uses function for brightness which is not supported by opensource X11 drivers */
	/* val < 0.0f tries to restore the brightness, less than -1.0 doesn't affect SDL function */
#ifdef USE_X11_GAMMA
	static BOOL firstCall = true;
	SDL_SysWMinfo sysInfo;
	SDL_VERSION(&sysInfo.version);
	if (SDL_GetWindowWMInfo(sdlWin, &sysInfo) && sysInfo.subsystem == SDL_SYSWM_X11)
	{
		static XF86VidModeGamma gammaToRestore = {-1.0f, -1.0f, -1.0f};
		static _XF86VidModeGetGamma XF86VidModeGetGamma;
		static _XF86VidModeSetGamma XF86VidModeSetGamma;
		if (firstCall && (!XF86VidModeGetGamma || !XF86VidModeSetGamma))
		{
			void *Xxf86vm = SDL_LoadObject(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE);
			if (Xxf86vm)
			{
				XF86VidModeGetGamma = SDL_LoadFunction(Xxf86vm, "XF86VidModeGetGamma");
				XF86VidModeSetGamma = SDL_LoadFunction(Xxf86vm, "XF86VidModeSetGamma");
			}
		}
		firstCall = false;
		if (XF86VidModeGetGamma && XF86VidModeSetGamma)
		{
			int screen = SDL_GetWindowDisplayIndex(sdlWin);
			if (screen < 0)
				screen = 0;
			if (gammaToRestore.red == -1.0f && gammaToRestore.green == -1.0f && gammaToRestore.blue == -1.0f)
				XF86VidModeGetGamma(sysInfo.info.x11.display, screen, &gammaToRestore); //Get brightness at first attempt
			if (val < 0.0f)
			{
				if (gammaToRestore.red >= 0.0f && gammaToRestore.green >= 0.0f && gammaToRestore.blue >= 0.0f && XF86VidModeSetGamma(sysInfo.info.x11.display, screen, &gammaToRestore)) //Restore brightness
					return;
				else
					val = 1.0f;
			}
			if (val >= 0.0f)
			{
				XF86VidModeGamma gamma = {val, val, val};
				if (XF86VidModeSetGamma(sysInfo.info.x11.display, screen, &gamma)) //Set brightness
					return;
			}
		}
	}
#endif
	if (val >= -1.0f)
		SDL_SetWindowBrightness(sdlWin, val < 0.0f ? 1.0f : val);
}
Пример #24
0
bool Window::setFullscreen(bool fullscreen, Window::FullscreenType fstype)
{
	if (!window)
		return false;

	if (graphics.get() && graphics->isCanvasActive())
		throw love::Exception("love.window.setFullscreen cannot be called while a Canvas is active in love.graphics.");

	WindowSettings newsettings = settings;
	newsettings.fullscreen = fullscreen;
	newsettings.fstype = fstype;

	Uint32 sdlflags = 0;

	if (fullscreen)
	{
		if (fstype == FULLSCREEN_DESKTOP)
			sdlflags = SDL_WINDOW_FULLSCREEN_DESKTOP;
		else
		{
			sdlflags = SDL_WINDOW_FULLSCREEN;

			SDL_DisplayMode mode = {};
			mode.w = windowWidth;
			mode.h = windowHeight;

			SDL_GetClosestDisplayMode(SDL_GetWindowDisplayIndex(window), &mode, &mode);
			SDL_SetWindowDisplayMode(window, &mode);
		}
	}

#ifdef LOVE_ANDROID
	love::android::setImmersive(fullscreen);
#endif

	if (SDL_SetWindowFullscreen(window, sdlflags) == 0)
	{
		SDL_GL_MakeCurrent(window, context);
		updateSettings(newsettings, true);

		// Apparently this gets un-set when we exit fullscreen (at least in OS X).
		if (!fullscreen)
			SDL_SetWindowMinimumSize(window, settings.minwidth, settings.minheight);

		return true;
	}

	return false;
}
Пример #25
0
GHOST_TUns16
GHOST_WindowSDL::getDPIHint()
{
	int displayIndex = SDL_GetWindowDisplayIndex(m_sdl_win);
	if (displayIndex < 0) {
		return 96;
	}

	float ddpi;
	if (SDL_GetDisplayDPI(displayIndex, &ddpi, NULL, NULL) != 0) {
		return 96;
	}

	return (int)ddpi;
}
Пример #26
0
PPSize PPDisplayDevice::getDisplayResolution() const {
	// Find the monitor MilkyTracker is being displayed on
	int currentDisplay = SDL_GetWindowDisplayIndex(theWindow);

	// Structure to hold the display resolution
	SDL_DisplayMode* displayMode = new SDL_DisplayMode;

	// If this fails, return -1 dimensions (makes MilkyTracker display an error)
	if (SDL_GetDesktopDisplayMode(currentDisplay, displayMode) != 0)
	{
		return PPSize(-1, -1);
	}

	// Return the desktop size
	return PPSize(displayMode->w, displayMode->h);
}
Пример #27
0
bool FLinuxWindow::GetFullScreenInfo( int32& X, int32& Y, int32& Width, int32& Height ) const
{
	SDL_Rect DisplayRect;

	int DisplayIdx = SDL_GetWindowDisplayIndex(HWnd);
	if (DisplayIdx >= 0 && SDL_GetDisplayBounds(DisplayIdx, &DisplayRect) == 0)
	{
		X = DisplayRect.x;
		Y = DisplayRect.y;
		Width = DisplayRect.w;
		Height = DisplayRect.h;

		return true;
	}

	return false;
}
Пример #28
0
void Window::handle()
{
	this->_displayIndex = SDL_GetWindowDisplayIndex(this->_window);

	SDL_GetCurrentDisplayMode(this->_displayIndex, &this->_displayMode);

	SDL_GetWindowSize(this->_window, &this->_windowMode.w, &this->_windowMode.h);

	SDL_GetWindowPosition(this->_window, &this->_windowMode.x, &this->_windowMode.y);

	this->scaleRenderer();

	std::cout << "The window was updated in some form!\n" <<
		"It's currently sitting on the display with an index of " << this->_displayIndex << "\n" <<
		"A screen width and height of " << this->_displayMode.w << " and " << this->_displayMode.h << "\n" <<
		"And a refresh rate of " << this->_displayMode.refresh_rate << "\n" <<
		"Oh, and now the window itself has the dimensions of " << this->_windowMode.w << " by " << this->_windowMode.h << "\n" <<
		"At the position " << this->_windowMode.x << " and " << this->_windowMode.y << "\n";
}
Пример #29
0
		std::vector<WindowMode> getWindowModes(std::function<bool(const WindowMode&)> mode_filter) const override {
			std::vector<WindowMode> res;
			int display_index = 0;
			if(window_ != nullptr) {
				display_index = SDL_GetWindowDisplayIndex(window_.get());
			}
			const int nmodes = SDL_GetNumDisplayModes(display_index);
			for(int n = 0; n != nmodes; ++n) {
				SDL_DisplayMode new_mode;
				const int nvalue = SDL_GetDisplayMode(display_index, n, &new_mode);
				if(nvalue != 0) {
					LOG_ERROR("QUERYING DISPLAY INFO: " << SDL_GetError());
					continue;
				}
				WindowMode mode = { new_mode.w, new_mode.h, std::make_shared<SDLPixelFormat>(new_mode.format), new_mode.refresh_rate };
				// filter modes based on pixel format here
				if(mode_filter(mode)) {
					res.emplace_back(mode);
				}
			}
			return res;
		}
Пример #30
0
    bool LWindow::init()
    {
        //Create window
        mWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE );
        if( mWindow != NULL )
        {
            mMouseFocus = true;
            mKeyboardFocus = true;
            mWidth = SCREEN_WIDTH;
            mHeight = SCREEN_HEIGHT;

            //Create renderer for window
            mRenderer = SDL_CreateRenderer( mWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
            if( mRenderer == NULL )
            {
                printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() );
                SDL_DestroyWindow( mWindow );
                mWindow = NULL;
            }
            else
            {
                //Initialize renderer color
                SDL_SetRenderDrawColor( mRenderer, 0xFF, 0xFF, 0xFF, 0xFF );

                //Grab window identifiers
                mWindowID = SDL_GetWindowID( mWindow );
                mWindowDisplayID = SDL_GetWindowDisplayIndex( mWindow );

                //Flag as opened
                mShown = true;
            }
        }
        else
        {
            printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() );
        }

        return mWindow != NULL && mRenderer != NULL;
    }