mirror of https://github.com/buggins/dlangui.git
support SDL2 under Windows
This commit is contained in:
parent
7c0e3006bf
commit
ce71e7dc1a
|
@ -66,7 +66,7 @@
|
|||
<debuglevel>0</debuglevel>
|
||||
<debugids />
|
||||
<versionlevel>0</versionlevel>
|
||||
<versionids>Unicode USE_OPENGL</versionids>
|
||||
<versionids>Unicode USE_OPENGL USE_SDL</versionids>
|
||||
<dump_source>0</dump_source>
|
||||
<mapverbosity>0</mapverbosity>
|
||||
<createImplib>1</createImplib>
|
||||
|
@ -225,6 +225,15 @@
|
|||
<File path="..\DerelictUtil\source\derelict\util\wintypes.d" />
|
||||
<File path="..\DerelictUtil\source\derelict\util\xtypes.d" />
|
||||
</Folder>
|
||||
<Folder name="DerelictSDL2">
|
||||
<File path="..\DerelictSDL2\source\derelict\sdl2\functions.d" />
|
||||
<File path="..\DerelictSDL2\source\derelict\sdl2\image.d" />
|
||||
<File path="..\DerelictSDL2\source\derelict\sdl2\mixer.d" />
|
||||
<File path="..\DerelictSDL2\source\derelict\sdl2\net.d" />
|
||||
<File path="..\DerelictSDL2\source\derelict\sdl2\sdl.d" />
|
||||
<File path="..\DerelictSDL2\source\derelict\sdl2\ttf.d" />
|
||||
<File path="..\DerelictSDL2\source\derelict\sdl2\types.d" />
|
||||
</Folder>
|
||||
<Folder name="gl3n">
|
||||
<File path="..\gl3n\gl3n\aabb.d" />
|
||||
<File path="..\gl3n\gl3n\frustum.d" />
|
||||
|
@ -320,12 +329,14 @@
|
|||
<Folder name="common">
|
||||
<File path="src\dlangui\platforms\common\platform.d" />
|
||||
</Folder>
|
||||
<Folder name="sdl">
|
||||
<File path="src\dlangui\platforms\sdl\sdlapp.d" />
|
||||
</Folder>
|
||||
<Folder name="windows">
|
||||
<File path="src\dlangui\platforms\windows\win32drawbuf.d" />
|
||||
<File path="src\dlangui\platforms\windows\win32fonts.d" />
|
||||
<File path="src\dlangui\platforms\windows\winapp.d" />
|
||||
</Folder>
|
||||
<File path="src\dlangui\platforms\sdl\sdlapp.d" />
|
||||
</Folder>
|
||||
<Folder name="widgets">
|
||||
<File path="src\dlangui\widgets\controls.d" />
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
<compiler>0</compiler>
|
||||
<otherDMD>0</otherDMD>
|
||||
<program>$(DMDInstallDir)windows\bin\dmd.exe</program>
|
||||
<imppath>$(SolutionDir)/src $(SolutionDir)/3rdparty $(SolutionDir)/3rdparty/libpng/source $(SolutionDir)/../DerelictGL3/source $(SolutionDir)/../DerelictUtil/source $(SolutionDir)/../gl3n</imppath>
|
||||
<imppath>$(SolutionDir)/src $(SolutionDir)/3rdparty $(SolutionDir)/3rdparty/libpng/source $(SolutionDir)/../DerelictGL3/source $(SolutionDir)/../DerelictUtil/source $(SolutionDir)/../DerelictFT/source $(SolutionDir)/../DerelictSDL2/source </imppath>
|
||||
<fileImppath />
|
||||
<outdir>$(ConfigurationName)</outdir>
|
||||
<objdir>$(OutDir)</objdir>
|
||||
|
@ -66,7 +66,7 @@
|
|||
<debuglevel>0</debuglevel>
|
||||
<debugids />
|
||||
<versionlevel>0</versionlevel>
|
||||
<versionids>Unicode USE_OPENGL</versionids>
|
||||
<versionids>Unicode USE_OPENGL USE_SDL</versionids>
|
||||
<dump_source>0</dump_source>
|
||||
<mapverbosity>3</mapverbosity>
|
||||
<createImplib>0</createImplib>
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
<compiler>0</compiler>
|
||||
<otherDMD>0</otherDMD>
|
||||
<program>$(DMDInstallDir)windows\bin\dmd.exe</program>
|
||||
<imppath>$(SolutionDir)/src $(SolutionDir)/3rdparty $(SolutionDir)/3rdparty/libpng/source $(SolutionDir)/../DerelictGL3/source $(SolutionDir)/../DerelictUtil/source $(SolutionDir)/../gl3n</imppath>
|
||||
<imppath>$(SolutionDir)/src $(SolutionDir)/3rdparty $(SolutionDir)/3rdparty/libpng/source $(SolutionDir)/../DerelictGL3/source $(SolutionDir)/../DerelictUtil/source $(SolutionDir)/../DerelictFT/source $(SolutionDir)/../DerelictSDL2/source</imppath>
|
||||
<fileImppath />
|
||||
<outdir>$(ConfigurationName)</outdir>
|
||||
<objdir>$(OutDir)</objdir>
|
||||
|
@ -66,7 +66,7 @@
|
|||
<debuglevel>0</debuglevel>
|
||||
<debugids />
|
||||
<versionlevel>0</versionlevel>
|
||||
<versionids>Unicode USE_OPENGL</versionids>
|
||||
<versionids>Unicode USE_OPENGL USE_SDL</versionids>
|
||||
<dump_source>0</dump_source>
|
||||
<mapverbosity>3</mapverbosity>
|
||||
<createImplib>0</createImplib>
|
||||
|
|
|
@ -525,13 +525,15 @@ mixin template APP_ENTRY_POINT() {
|
|||
/// workaround for link issue when WinMain is located in library
|
||||
version(Windows) {
|
||||
private import win32.windows;
|
||||
private import dlangui.platforms.sdl.sdlapp;
|
||||
private import dlangui.platforms.windows.winapp;
|
||||
|
||||
extern (Windows)
|
||||
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
LPSTR lpCmdLine, int nCmdShow)
|
||||
{
|
||||
return DLANGUIWinMain(hInstance, hPrevInstance,
|
||||
lpCmdLine, nCmdShow);
|
||||
}
|
||||
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
LPSTR lpCmdLine, int nCmdShow)
|
||||
{
|
||||
return DLANGUIWinMain(hInstance, hPrevInstance,
|
||||
lpCmdLine, nCmdShow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
module src.dlangui.platforms.sdl.sdlapp;
|
||||
|
||||
version(USE_SDL) {
|
||||
import core.runtime;
|
||||
import std.string;
|
||||
import std.conv;
|
||||
import std.string;
|
||||
import std.utf;
|
||||
import std.stdio;
|
||||
import std.algorithm;
|
||||
import std.file;
|
||||
|
||||
import dlangui.core.logger;
|
||||
import dlangui.core.events;
|
||||
|
@ -243,59 +249,145 @@ version(USE_SDL) {
|
|||
|
||||
// entry point
|
||||
extern(C) int UIAppMain(string[] args);
|
||||
|
||||
version (Windows) {
|
||||
import win32.windows;
|
||||
import dlangui.platforms.windows.win32fonts;
|
||||
pragma(lib, "gdi32.lib");
|
||||
pragma(lib, "user32.lib");
|
||||
extern(Windows)
|
||||
int DLANGUIWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
LPSTR lpCmdLine, int nCmdShow) {
|
||||
int result;
|
||||
|
||||
try
|
||||
{
|
||||
Runtime.initialize();
|
||||
result = myWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
|
||||
Runtime.terminate();
|
||||
}
|
||||
catch (Throwable e) // catch any uncaught exceptions
|
||||
{
|
||||
MessageBox(null, toUTF16z(e.toString()), "Error",
|
||||
MB_OK | MB_ICONEXCLAMATION);
|
||||
result = 0; // failed
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
string[] splitCmdLine(string line) {
|
||||
string[] res;
|
||||
int start = 0;
|
||||
bool insideQuotes = false;
|
||||
for (int i = 0; i <= line.length; i++) {
|
||||
char ch = i < line.length ? line[i] : 0;
|
||||
if (ch == '\"') {
|
||||
if (insideQuotes) {
|
||||
if (i > start)
|
||||
res ~= line[start .. i];
|
||||
start = i + 1;
|
||||
insideQuotes = false;
|
||||
} else {
|
||||
insideQuotes = true;
|
||||
start = i + 1;
|
||||
}
|
||||
} else if (!insideQuotes && (ch == ' ' || ch == '\t' || ch == 0)) {
|
||||
if (i > start) {
|
||||
res ~= line[start .. i];
|
||||
}
|
||||
start = i + 1;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int myWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
|
||||
{
|
||||
setFileLogger(std.stdio.File("ui.log", "w"));
|
||||
setLogLevel(LogLevel.Trace);
|
||||
Log.d("myWinMain()");
|
||||
string basePath = exePath();
|
||||
Log.i("Current executable: ", exePath());
|
||||
string cmdline = fromStringz(lpCmdLine);
|
||||
Log.i("Command line: ", cmdline);
|
||||
string[] args = splitCmdLine(cmdline);
|
||||
Log.i("Command line params: ", args);
|
||||
|
||||
try {
|
||||
// Load the SDL 2 library.
|
||||
DerelictSDL2.load();
|
||||
} catch (Exception e) {
|
||||
Log.e("Cannot load SDL2 library", e);
|
||||
return 1;
|
||||
}
|
||||
|
||||
//_cmdShow = iCmdShow;
|
||||
//_hInstance = hInstance;
|
||||
|
||||
FontManager.instance = new Win32FontManager();
|
||||
|
||||
return sdlmain(args);
|
||||
}
|
||||
} else {
|
||||
|
||||
int main(string[] args)
|
||||
{
|
||||
|
||||
int main(string[] args)
|
||||
{
|
||||
|
||||
setStderrLogger();
|
||||
setLogLevel(LogLevel.Trace);
|
||||
setStderrLogger();
|
||||
setLogLevel(LogLevel.Trace);
|
||||
|
||||
try {
|
||||
// Load the SDL 2 library.
|
||||
DerelictSDL2.load();
|
||||
} catch (Exception e) {
|
||||
Log.e("Cannot load SDL2 library", e);
|
||||
return 1;
|
||||
}
|
||||
try {
|
||||
// Load the SDL 2 library.
|
||||
DerelictSDL2.load();
|
||||
} catch (Exception e) {
|
||||
Log.e("Cannot load SDL2 library", e);
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_DisplayMode displayMode;
|
||||
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_EVENTS) != 0) {
|
||||
Log.e("Cannot init SDL2");
|
||||
return 2;
|
||||
}
|
||||
scope(exit)SDL_Quit();
|
||||
int request = SDL_GetDesktopDisplayMode(0,&displayMode);
|
||||
SDL_DisplayMode displayMode;
|
||||
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_EVENTS) != 0) {
|
||||
Log.e("Cannot init SDL2");
|
||||
return 2;
|
||||
}
|
||||
scope(exit)SDL_Quit();
|
||||
int request = SDL_GetDesktopDisplayMode(0,&displayMode);
|
||||
|
||||
|
||||
FreeTypeFontManager ft = new FreeTypeFontManager();
|
||||
// TODO: use FontConfig
|
||||
ft.registerFont("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", FontFamily.SansSerif, "DejaVu", false, FontWeight.Normal);
|
||||
FontManager.instance = ft;
|
||||
FreeTypeFontManager ft = new FreeTypeFontManager();
|
||||
// TODO: use FontConfig
|
||||
ft.registerFont("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", FontFamily.SansSerif, "DejaVu", false, FontWeight.Normal);
|
||||
FontManager.instance = ft;
|
||||
|
||||
currentTheme = createDefaultTheme();
|
||||
|
||||
SDLPlatform sdl = new SDLPlatform();
|
||||
if (!sdl.connect()) {
|
||||
return 1;
|
||||
}
|
||||
Platform.setInstance(sdl);
|
||||
return sdlmain(args);
|
||||
}
|
||||
}
|
||||
|
||||
int res = 0;
|
||||
|
||||
res = UIAppMain(args);
|
||||
int sdlmain(string[] args) {
|
||||
currentTheme = createDefaultTheme();
|
||||
|
||||
Platform.setInstance(null);
|
||||
Log.d("Destroying SDL platform");
|
||||
destroy(sdl);
|
||||
|
||||
currentTheme = null;
|
||||
drawableCache = null;
|
||||
imageCache = null;
|
||||
FontManager.instance = null;
|
||||
|
||||
Log.d("Exiting main");
|
||||
SDLPlatform sdl = new SDLPlatform();
|
||||
if (!sdl.connect()) {
|
||||
return 1;
|
||||
}
|
||||
Platform.setInstance(sdl);
|
||||
|
||||
return res;
|
||||
}
|
||||
int res = 0;
|
||||
|
||||
res = UIAppMain(args);
|
||||
|
||||
Platform.setInstance(null);
|
||||
Log.d("Destroying SDL platform");
|
||||
destroy(sdl);
|
||||
|
||||
currentTheme = null;
|
||||
drawableCache = null;
|
||||
imageCache = null;
|
||||
FontManager.instance = null;
|
||||
|
||||
Log.d("Exiting main");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
module dlangui.platforms.windows.win32drawbuf;
|
||||
|
||||
version (USE_SDL) { }
|
||||
else version (Windows) {
|
||||
version (Windows) {
|
||||
|
||||
import win32.windows;
|
||||
import dlangui.core.logger;
|
||||
|
|
Loading…
Reference in New Issue