|
|
@@ -34,6 +34,10 @@
|
|
|
#include <SDL/SDL.h>
|
|
|
#include <iostream>
|
|
|
|
|
|
+#include <unistd.h>
|
|
|
+#include <sys/types.h>
|
|
|
+#include <pwd.h>
|
|
|
+
|
|
|
using namespace Polycode;
|
|
|
using std::vector;
|
|
|
|
|
|
@@ -49,11 +53,25 @@ void Core::getScreenInfo(int *width, int *height, int *hz) {
|
|
|
if (hz) *hz = 0;
|
|
|
}
|
|
|
|
|
|
-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, int monitorIndex, bool resizableWindow) : Core(_xRes, _yRes, fullScreen, vSync, aaLevel, anisotropyLevel, frameRate, monitorIndex) {
|
|
|
+
|
|
|
+ this->resizableWindow = resizableWindow;
|
|
|
+
|
|
|
+ char *buffer = getcwd(NULL, 0);
|
|
|
+ defaultWorkingDirectory = String(buffer);
|
|
|
+ free(buffer);
|
|
|
+
|
|
|
+ struct passwd *pw = getpwuid(getuid());
|
|
|
+ const char *homedir = pw->pw_dir;
|
|
|
+ userHomeDirectory = String(homedir);
|
|
|
|
|
|
String *windowTitle = (String*)view->windowData;
|
|
|
|
|
|
- putenv("SDL_VIDEO_CENTERED=1");
|
|
|
+ if(resizableWindow) {
|
|
|
+ unsetenv("SDL_VIDEO_CENTERED");
|
|
|
+ } else {
|
|
|
+ setenv("SDL_VIDEO_CENTERED", "1", 1);
|
|
|
+ }
|
|
|
|
|
|
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
|
|
|
}
|
|
|
@@ -95,16 +113,20 @@ void SDLCore::setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, int
|
|
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0);
|
|
|
|
|
|
+ flags = SDL_OPENGL;
|
|
|
+
|
|
|
if(fullScreen) {
|
|
|
- if( SDL_SetVideoMode(xRes, yRes, 0, SDL_OPENGL|SDL_FULLSCREEN) == NULL ) {
|
|
|
- }
|
|
|
- } else {
|
|
|
- if( SDL_SetVideoMode(xRes, yRes, 0, SDL_OPENGL) == NULL ) {
|
|
|
- }
|
|
|
+ flags |= SDL_FULLSCREEN;
|
|
|
}
|
|
|
+
|
|
|
+ if(resizableWindow) {
|
|
|
+ flags |= SDL_RESIZABLE;
|
|
|
+ }
|
|
|
+ SDL_SetVideoMode(xRes, yRes, 0, flags);
|
|
|
|
|
|
renderer->Resize(xRes, yRes);
|
|
|
- CoreServices::getInstance()->getMaterialManager()->reloadProgramsAndTextures();
|
|
|
+ //CoreServices::getInstance()->getMaterialManager()->reloadProgramsAndTextures();
|
|
|
+ dispatchEvent(new Event(), EVENT_CORE_RESIZE);
|
|
|
}
|
|
|
|
|
|
vector<Polycode::Rectangle> SDLCore::getVideoModes() {
|
|
|
@@ -130,7 +152,22 @@ void SDLCore::openURL(String url) {
|
|
|
}
|
|
|
|
|
|
String SDLCore::executeExternalCommand(String command) {
|
|
|
-
|
|
|
+ FILE *fp = popen(command.c_str(), "r");
|
|
|
+ if(!fp) {
|
|
|
+ return "Unable to execute command";
|
|
|
+ }
|
|
|
+
|
|
|
+ int fd = fileno(fp);
|
|
|
+
|
|
|
+ char path[2048];
|
|
|
+ String retString;
|
|
|
+
|
|
|
+ while (fgets(path, sizeof(path), fp) != NULL) {
|
|
|
+ retString = retString + String(path);
|
|
|
+ }
|
|
|
+
|
|
|
+ pclose(fp);
|
|
|
+ return retString;
|
|
|
}
|
|
|
|
|
|
int SDLThreadFunc(void *data) {
|
|
|
@@ -157,7 +194,7 @@ void SDLCore::enableMouse(bool newval) {
|
|
|
}
|
|
|
Core::enableMouse(newval);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
bool SDLCore::Update() {
|
|
|
if(!running)
|
|
|
return false;
|
|
|
@@ -173,6 +210,18 @@ bool SDLCore::Update() {
|
|
|
case SDL_QUIT:
|
|
|
running = false;
|
|
|
break;
|
|
|
+ case SDL_VIDEORESIZE:
|
|
|
+ if(resizableWindow) {
|
|
|
+ unsetenv("SDL_VIDEO_CENTERED");
|
|
|
+ } else {
|
|
|
+ setenv("SDL_VIDEO_CENTERED", "1", 1);
|
|
|
+ }
|
|
|
+ this->xRes = event.resize.w;
|
|
|
+ this->yRes = event.resize.h;
|
|
|
+ SDL_SetVideoMode(xRes, yRes, 0, flags);
|
|
|
+ renderer->Resize(xRes, yRes);
|
|
|
+ dispatchEvent(new Event(), EVENT_CORE_RESIZE);
|
|
|
+ break;
|
|
|
case SDL_JOYBUTTONDOWN:
|
|
|
// input->setKeyState((PolyKEY)(event.key.keysym.sym), true);
|
|
|
break;
|