فهرست منبع

Merge pull request #122 from mcclure/screeninfo

getScreeninfo() method / ability to set "full screen + current resolution"
Ivan Safrin 13 سال پیش
والد
کامیت
c8c249b915

+ 9 - 0
Core/Contents/Include/PolyCoreServices.h

@@ -146,6 +146,15 @@ namespace Polycode {
 			* @see Config
 			*/																													
 			Config *getConfig();
+		
+			/**
+			 * Provides the current width, height, and refresh rate of the screen.
+			 * @param width If non-NULL, current screen width will be written here (or 0 if unknown).
+			 * @param hight If non-NULL, current screen height will be written here (or 0 if unknown).
+			 * @param hz If non-NULL, current screen refresh rate will be written here (or 0 if unknown).
+			 */
+			void getScreenInfo(int *width, int *height, int *hz);
+		
 			
 			bool drawScreensFirst;
 					

+ 1 - 1
Core/Contents/Source/PolyAGLCore.cpp

@@ -29,7 +29,7 @@ long getThreadID() {
 	return (long)pthread_self();
 }
 
-AGLCore::AGLCore(WindowRef window, Polycode::Rectangle *clippingArea, int xRes, int yRes, bool fullScreen,int aaLevel, int frameRate) : Core(xRes, yRes, fullScreen,aaLevel, frameRate) {
+AGLCore::AGLCore(WindowRef window, Polycode::Rectangle *clippingArea, int _xRes, int _yRes, bool fullScreen, int aaLevel, int frameRate) : Core(_xRes, _yRes, fullScreen,aaLevel, frameRate) {
 
 	eventMutex = createMutex();
 	

+ 1 - 1
Core/Contents/Source/PolyCocoaCore.mm

@@ -30,7 +30,7 @@ long getThreadID() {
 	return (long)pthread_self();
 }
 
-CocoaCore::CocoaCore(PolycodeView *view, int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, int frameRate, int monitorIndex) : Core(xRes, yRes, fullScreen, vSync, aaLevel, anisotropyLevel, frameRate, monitorIndex) {	
+CocoaCore::CocoaCore(PolycodeView *view, int _xRes, int _yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, int frameRate, int monitorIndex) : Core(_xRes, _yRes, fullScreen, vSync, aaLevel, anisotropyLevel, frameRate, monitorIndex) {	
 
 	hidManager = NULL;
 	initGamepad();

+ 6 - 3
Core/Contents/Source/PolyCore.cpp

@@ -50,7 +50,7 @@ namespace Polycode {
 		yearDay = timeinfo->tm_yday;
 	}
 	
-	Core::Core(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, int frameRate, int monitorIndex) : EventDispatcher() {
+	Core::Core(int _xRes, int _yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, int frameRate, int monitorIndex) : EventDispatcher() {
 		services = CoreServices::getInstance();
 		input = new CoreInput();
 		services->setCore(this);
@@ -60,8 +60,11 @@ namespace Polycode {
 		lastFrameTicks=0;
 		lastFPSTicks=0;
 		elapsed = 0;
-		this->xRes = xRes;
-		this->yRes = yRes;
+		xRes = _xRes;
+		yRes = _yRes;
+		if (fullScreen && !xRes && !yRes) {
+			CoreServices::getInstance()->getScreenInfo(&xRes, &yRes, NULL);
+		}
 		mouseEnabled = true;
 		lastSleepFrameTicks = 0;
 		

+ 50 - 0
Core/Contents/Source/PolyCoreServices.cpp

@@ -37,6 +37,15 @@
 #include "PolyTweenManager.h"
 #include "PolySoundManager.h"
 
+// For use by getScreenInfo
+#if defined(_WINDOWS)
+#include <windows.h>
+#elif defined(__APPLE__) && defined(__MACH__)
+#include <ApplicationServices/ApplicationServices.h>
+#elif defined(__linux) || defined(__linux__) || defined(linux)
+#include <SDL/SDL.h>
+#endif
+
 using namespace Polycode;
 
 std::map<long, CoreServices*> CoreServices::instanceMap;
@@ -249,3 +258,44 @@ TweenManager *CoreServices::getTweenManager() {
 ResourceManager *CoreServices::getResourceManager() {
 	return resourceManager;
 }
+
+void CoreServices::getScreenInfo(int *width, int *height, int *hz) {
+#if defined(_WINDOWS)
+	
+	DEVMODE mode = {}; // Zero initialize
+	mode.dmSize = sizeof(DEVMODE);
+	
+    EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &mode);
+	
+    // Store the current display settings.
+    if (width) *width = mode.dmPelsWidth;
+    if (height) *height = mode.dmPelsHeight;
+    if (hz) *hz = mode.dmDisplayFrequency;
+	
+#elif defined(__APPLE__) && defined(__MACH__)
+	
+	CGDisplayModeRef mode = CGDisplayCopyDisplayMode(CGMainDisplayID());
+    
+    // Copy the relevant data.
+    if (width) *width = CGDisplayModeGetWidth(mode);
+    if (height) *height = CGDisplayModeGetHeight(mode);
+    if (hz) *hz = CGDisplayModeGetRefreshRate(mode);
+    
+    CGDisplayModeRelease(mode);
+	
+#elif defined(__linux) || defined(__linux__) || defined(linux)
+	
+	SDL_Init(SDL_INIT_VIDEO); // Or GetVideoInfo will not work
+	const SDL_VideoInfo *video = SDL_GetVideoInfo();
+	if (width) *width = video->current_w;
+	if (height) *height = video->current_h;
+	if (hz) *hz = 0;
+	
+#else
+	
+	if (width) *width = 0;
+	if (height) *height = 0;
+	if (hz) *hz = 0;
+	
+#endif
+}

+ 1 - 1
Core/Contents/Source/PolySDLCore.cpp

@@ -41,7 +41,7 @@ long getThreadID() {
 	return (long)pthread_self();
 }
 
-SDLCore::SDLCore(PolycodeView *view, int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, int frameRate, int monitorIndex) : Core(xRes, yRes, fullScreen, vSync, aaLevel, anisotropyLevel, frameRate, monitorIndex) {
+SDLCore::SDLCore(PolycodeView *view, int _xRes, int _yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, int frameRate) : Core(_xRes, _yRes, fullScreen, vSync, aaLevel, anisotropyLevel, frameRate) {
 
 	String *windowTitle = (String*)view->windowData;
 

+ 2 - 2
Core/Contents/Source/PolyWinCore.cpp

@@ -55,8 +55,8 @@ void ClientResize(HWND hWnd, int nWidth, int nHeight)
   MoveWindow(hWnd,rcWindow.left, rcWindow.top, nWidth + ptDiff.x, nHeight + ptDiff.y, TRUE);
 }
 
-Win32Core::Win32Core(PolycodeViewBase *view, int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, int frameRate,  int monitorIndex) 
-	: Core(xRes, yRes, fullScreen, vSync, aaLevel, anisotropyLevel, frameRate, monitorIndex) {
+Win32Core::Win32Core(PolycodeViewBase *view, int _xRes, int _yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, int frameRate,  int monitorIndex) 
+	: Core(_xRes, _yRes, fullScreen, vSync, aaLevel, anisotropyLevel, frameRate, monitorIndex) {
 
 	hWnd = *((HWND*)view->windowData);
 	core = this;