当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_GetWindowDisplayIndex函数代码示例

本文整理汇总了C++中SDL_GetWindowDisplayIndex函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_GetWindowDisplayIndex函数的具体用法?C++ SDL_GetWindowDisplayIndex怎么用?C++ SDL_GetWindowDisplayIndex使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_GetWindowDisplayIndex函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getPosition

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;
	}
}
开发者ID:MikuAuahDark,项目名称:livesim4,代码行数:25,代码来源:Window.cpp

示例2: SDL_GetWindowDisplayIndex

SDL_Rect CVideo::bound() const
{
	SDL_Rect rc;
	int display = window? SDL_GetWindowDisplayIndex(window): 0;
	SDL_GetDisplayBounds(display, &rc);
	return rc;
}
开发者ID:freeors,项目名称:War-Of-Kingdom,代码行数:7,代码来源:video.cpp

示例3: SDL_GetWindowDisplayIndex

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 );
}
开发者ID:kaczla,项目名称:OpenGL,代码行数:30,代码来源:window.cpp

示例4: GLimp_DetectAvailableModes

/*
===============
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;
}
开发者ID:Wookiee-,项目名称:jaPRO,代码行数:65,代码来源:sdl_glimp.cpp

示例5: SDL_GetWindowDisplayIndex

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);
}
开发者ID:aladur,项目名称:khunphan,代码行数:32,代码来源:kpsdl2userinterface.cpp

示例6: _GetBestFullscreenResolution

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;
}
开发者ID:magetron,项目名称:UnrealEngine4-mod,代码行数:31,代码来源:LinuxWindow.cpp

示例7: video_display

int video_display(void)
{
    if (window)
        return SDL_GetWindowDisplayIndex(window);
    else
        return -1;
}
开发者ID:senquack,项目名称:neverball,代码行数:7,代码来源:video.c

示例8: SDL_GetWindowDisplayIndex

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();
}
开发者ID:HerculesCE,项目名称:ArxLibertatis,代码行数:59,代码来源:SDL2Window.cpp

示例9: loop

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
}
开发者ID:agangzz,项目名称:CorsixTH-Android,代码行数:59,代码来源:testwm2.c

示例10: get_current_resolution

/* 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 {
开发者ID:dev-riker,项目名称:roguelikes,代码行数:9,代码来源:sys_sdl2_c.c

示例11: SDL_GetWindowDisplayIndex

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;
}
开发者ID:strand,项目名称:xoreos,代码行数:8,代码来源:graphics.cpp

示例12: gutGetDisplayIndex

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;
}
开发者ID:FolkertVanVerseveld,项目名称:gut,代码行数:9,代码来源:gut.c

示例13: GLimp_DetectAvailableModes

/*
===============
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);
    }
}
开发者ID:Kangz,项目名称:Unvanquished,代码行数:61,代码来源:sdl_glimp.cpp

示例14: SDL_GetWindowDisplayIndex

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;
}
开发者ID:nidium,项目名称:Nidium,代码行数:10,代码来源:UIInterface.cpp

示例15: getDisplaySize

		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;
		}
开发者ID:sweetkristas,项目名称:render_engine,代码行数:10,代码来源:WindowManager.cpp


注:本文中的SDL_GetWindowDisplayIndex函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。