Merge branch 'master' of github.com:buggins/dlangui

This commit is contained in:
Vadim Lopatin 2015-11-11 18:51:16 +03:00
commit 3980210b6f
11 changed files with 179 additions and 55 deletions

View File

@ -40,7 +40,7 @@
"configurations": [ "configurations": [
{ {
"name": "default", "name": "default",
"versions": ["USE_OPENGL", "EmbedStandardResources", "USE_FREETYPE"], "versions": ["USE_OPENGL", "EmbedStandardResources", "USE_FREETYPE", "ForceLogs"],
"versions-posix": ["USE_SDL"], "versions-posix": ["USE_SDL"],
"versions-windows": ["Unicode"], "versions-windows": ["Unicode"],
"dependencies": { "dependencies": {
@ -50,7 +50,7 @@
"gl3n": "~>1.2.0" "gl3n": "~>1.2.0"
}, },
"dependencies-posix": { "dependencies-posix": {
"derelict-sdl2": "~>1.9.1" "derelict-sdl2": "~>1.9.7"
}, },
"copyFiles-windows-x86_64": [ "copyFiles-windows-x86_64": [
"libs/windows/x86_64/libfreetype-6.dll" "libs/windows/x86_64/libfreetype-6.dll"
@ -59,6 +59,19 @@
"libs/windows/x86/libfreetype-6.dll" "libs/windows/x86/libfreetype-6.dll"
] ]
}, },
{
"name": "minimal",
"versions": ["EmbedStandardResources", "ForceLogs"],
"versions-posix": ["USE_SDL", "USE_FREETYPE"],
"versions-windows": ["Unicode"],
"dependencies": {
"dlib": "~>0.7.0",
"gl3n": "~>1.2.0"
},
"dependencies-posix": {
"derelict-sdl2": "~>1.9.7"
}
},
{ {
"name": "sdl", "name": "sdl",
"versions": ["USE_SDL", "USE_OPENGL", "USE_FREETYPE", "EmbedStandardResources"], "versions": ["USE_SDL", "USE_OPENGL", "USE_FREETYPE", "EmbedStandardResources"],
@ -88,7 +101,7 @@
"derelict-gl3": "~>1.0.16", "derelict-gl3": "~>1.0.16",
"derelict-ft": "~>1.0.2", "derelict-ft": "~>1.0.2",
"gl3n": "~>1.2.0", "gl3n": "~>1.2.0",
"dsfml": "~master" "dsfml": "~>2.1.0"
}, },
"copyFiles-windows-x86_64": [ "copyFiles-windows-x86_64": [
"libs/windows/x86_64/libfreetype-6.dll" "libs/windows/x86_64/libfreetype-6.dll"

View File

@ -13,7 +13,13 @@
"sourceFiles-windows": ["$PACKAGE_DIR/src/win_app.def"], "sourceFiles-windows": ["$PACKAGE_DIR/src/win_app.def"],
"versions": ["EmbedStandardResources"],
"dependencies": { "dependencies": {
"dlangui": "*", "dlangui": {"path": "../../"}
},
"subConfigurations": {
"dlangui": "minimal"
} }
} }

View File

@ -13,7 +13,13 @@
"sourceFiles-windows": ["$PACKAGE_DIR/src/win_app.def"], "sourceFiles-windows": ["$PACKAGE_DIR/src/win_app.def"],
"versions": ["EmbedStandardResources", "ForceLogs"],
"dependencies": { "dependencies": {
"dlangui": "*" "dlangui": {"path": "../../"}
},
"subConfigurations": {
"dlangui": "minimal"
} }
} }

View File

@ -189,8 +189,8 @@ enum : int {
extern (C) int UIAppMain(string[] args) { extern (C) int UIAppMain(string[] args) {
// always use trace, even for release builds // always use trace, even for release builds
Log.setLogLevel(LogLevel.Trace); //Log.setLogLevel(LogLevel.Trace);
Log.setFileLogger(std.stdio.File("ui.log", "w")); //Log.setFileLogger(new std.stdio.File("ui.log", "w"));
// resource directory search paths // resource directory search paths
// not required if only embedded resources are used // not required if only embedded resources are used

View File

@ -11,7 +11,13 @@
"sourceFiles-windows": ["$PACKAGE_DIR/src/win_app.def"], "sourceFiles-windows": ["$PACKAGE_DIR/src/win_app.def"],
"versions": ["EmbedStandardResources"],
"dependencies": { "dependencies": {
"dlangui": "*", "dlangui": {"path": "../../"}
},
"subConfigurations": {
"dlangui": "minimal"
} }
} }

View File

@ -13,7 +13,13 @@
"sourceFiles-windows": ["$PACKAGE_DIR/src/win_app.def"], "sourceFiles-windows": ["$PACKAGE_DIR/src/win_app.def"],
"versions": ["EmbedStandardResources", "ForceLogs"],
"dependencies": { "dependencies": {
"dlangui": "*" "dlangui": {"path": "../../"}
},
"subConfigurations": {
"dlangui": "minimal"
} }
} }

View File

@ -76,33 +76,56 @@ Log.e("exception while reading file", e);
---- ----
*/ */
synchronized class Log {
static: import core.sync.mutex;
__gshared private LogLevel logLevel = LogLevel.Info;
__gshared private std.stdio.File logFile; class Log {
static __gshared private LogLevel logLevel = LogLevel.Info;
static __gshared private std.stdio.File * logFile = null;
static __gshared private Mutex mutex = null;
static this() {
Log.mutex = new Mutex();
}
/// Redirects output to stdout /// Redirects output to stdout
void setStdoutLogger() { static public void setStdoutLogger() {
logFile = stdout; synchronized(mutex) {
logFile = &stdout;
}
} }
/// Redirects output to stderr /// Redirects output to stderr
void setStderrLogger() { static public void setStderrLogger() {
logFile = stderr; synchronized(mutex) {
logFile = &stderr;
}
} }
/// Redirects output to file /// Redirects output to file
void setFileLogger(File file) { static public void setFileLogger(File * file) {
logFile = file; synchronized(mutex) {
if (logFile !is null && logFile != &stdout && logFile != &stderr) {
logFile.close();
destroy(logFile);
logFile = null;
}
logFile = file;
if (logFile !is null)
logFile.writeln("DlangUI log file");
}
} }
/// Sets log level (one of LogLevel) /// Sets log level (one of LogLevel)
void setLogLevel(LogLevel level) { static public void setLogLevel(LogLevel level) {
logLevel = level; synchronized(mutex) {
logLevel = level;
i("Log level changed to ", level);
}
} }
/// Log level to name helper function /// Log level to name helper function
string logLevelName(LogLevel level) { static public string logLevelName(LogLevel level) {
switch (level) { switch (level) {
case LogLevel.Fatal: return "F"; case LogLevel.Fatal: return "F";
case LogLevel.Error: return "E"; case LogLevel.Error: return "E";
@ -114,8 +137,8 @@ synchronized class Log {
} }
} }
/// Log message with arbitrary log level /// Log message with arbitrary log level
void log(S...)(LogLevel level, S args) { static public void log(S...)(LogLevel level, S args) {
if (logLevel >= level && logFile.isOpen) { if (logLevel >= level && logFile !is null && logFile.isOpen) {
SysTime ts = Clock.currTime(); SysTime ts = Clock.currTime();
logFile.writef("%04d-%02d-%02d %02d:%02d:%02d.%03d %s ", ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fracSecs.split!("msecs").msecs, logLevelName(level)); logFile.writef("%04d-%02d-%02d %02d:%02d:%02d.%03d %s ", ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fracSecs.split!("msecs").msecs, logLevelName(level));
logFile.writeln(args); logFile.writeln(args);
@ -123,34 +146,46 @@ synchronized class Log {
} }
} }
/// Log verbose / trace message /// Log verbose / trace message
void v(S...)(S args) { static public void v(S...)(S args) {
if (logLevel >= LogLevel.Trace && logFile.isOpen) synchronized(mutex) {
log(LogLevel.Trace, args); if (logLevel >= LogLevel.Trace && logFile !is null && logFile.isOpen)
log(LogLevel.Trace, args);
}
} }
/// Log debug message /// Log debug message
void d(S...)(S args) { static public void d(S...)(S args) {
if (logLevel >= LogLevel.Debug && logFile.isOpen) synchronized(mutex) {
log(LogLevel.Debug, args); if (logLevel >= LogLevel.Debug && logFile !is null && logFile.isOpen)
log(LogLevel.Debug, args);
}
} }
/// Log info message /// Log info message
void i(S...)(S args) { static public void i(S...)(S args) {
if (logLevel >= LogLevel.Info && logFile.isOpen) synchronized(mutex) {
log(LogLevel.Info, args); if (logLevel >= LogLevel.Info && logFile !is null && logFile.isOpen)
log(LogLevel.Info, args);
}
} }
/// Log warn message /// Log warn message
void w(S...)(S args) { static public void w(S...)(S args) {
if (logLevel >= LogLevel.Warn && logFile.isOpen) synchronized(mutex) {
log(LogLevel.Warn, args); if (logLevel >= LogLevel.Warn && logFile !is null && logFile.isOpen)
log(LogLevel.Warn, args);
}
} }
/// Log error message /// Log error message
void e(S...)(S args) { static public void e(S...)(S args) {
if (logLevel >= LogLevel.Error && logFile.isOpen) synchronized(mutex) {
log(LogLevel.Error, args); if (logLevel >= LogLevel.Error && logFile !is null && logFile.isOpen)
log(LogLevel.Error, args);
}
} }
/// Log fatal error message /// Log fatal error message
void f(S...)(S args) { static public void f(S...)(S args) {
if (logLevel >= LogLevel.Fatal && logFile.isOpen) synchronized(mutex) {
log(LogLevel.Fatal, args); if (logLevel >= LogLevel.Fatal && logFile !is null && logFile.isOpen)
log(LogLevel.Fatal, args);
}
} }
} }
@ -168,3 +203,4 @@ debug {
void onResourceDestroyWhileShutdown(string resourceName, string objname = null) { void onResourceDestroyWhileShutdown(string resourceName, string objname = null) {
Log.e("Resource leak: destroying resource while shutdown! ", resourceName, " ", objname); Log.e("Resource leak: destroying resource while shutdown! ", resourceName, " ", objname);
} }

View File

@ -9,6 +9,8 @@ Authors: Vadim Lopatin, coolreader.org@gmail.com
*/ */
module dlangui.graphics.ftfonts; module dlangui.graphics.ftfonts;
version(USE_FREETYPE):
import dlangui.graphics.fonts; import dlangui.graphics.fonts;
import derelict.freetype.ft; import derelict.freetype.ft;
@ -461,6 +463,17 @@ class FreeTypeFont : Font {
@property override bool isNull() { return _files.length == 0; } @property override bool isNull() { return _files.length == 0; }
} }
private derelict.util.exception.ShouldThrow missingSymFunc( string symName ) {
import std.algorithm : equal;
foreach(s; ["FT_New_Face", "FT_Attach_File", "FT_Set_Pixel_Sizes",
"FT_Get_Char_Index", "FT_Load_Glyph", "FT_Done_Face",
"FT_Init_FreeType", "FT_Done_FreeType"]) {
if (symName.equal(s)) // Symbol is used
return derelict.util.exception.ShouldThrow.Yes;
}
// Don't throw for unused symbol
return derelict.util.exception.ShouldThrow.No;
}
/// FreeType based font manager. /// FreeType based font manager.
class FreeTypeFontManager : FontManager { class FreeTypeFontManager : FontManager {
@ -513,11 +526,16 @@ class FreeTypeFontManager : FontManager {
this() { this() {
// load dynaic library // load dynaic library
try { try {
Log.v("DerelictFT: Loading FreeType library");
DerelictFT.missingSymbolCallback = &missingSymFunc;
Log.v("DerelictFT: Missing symbols callback is registered");
DerelictFT.load(); DerelictFT.load();
} catch (Exception e) { Log.v("DerelictFT: Loaded");
} catch (Throwable e) {
Log.e("Derelict: cannot load freetype shared library: ", e.msg); Log.e("Derelict: cannot load freetype shared library: ", e.msg);
throw new Exception("Cannot load freetype library"); throw new Exception("Cannot load freetype library");
} }
Log.v("Initializing FreeType library");
// init library // init library
int error = FT_Init_FreeType(&_library); int error = FT_Init_FreeType(&_library);
if (error) { if (error) {

View File

@ -1416,8 +1416,11 @@ version (Windows) {
try { try {
/// testing freetype font manager /// testing freetype font manager
version(USE_FREETYPE) { version(USE_FREETYPE) {
Log.v("Trying to init FreeType font manager");
import dlangui.graphics.ftfonts; import dlangui.graphics.ftfonts;
// trying to create font manager // trying to create font manager
Log.v("Creating FreeTypeFontManager");
FreeTypeFontManager ftfontMan = new FreeTypeFontManager(); FreeTypeFontManager ftfontMan = new FreeTypeFontManager();
import win32.shlobj; import win32.shlobj;
@ -1444,6 +1447,7 @@ version (Windows) {
} }
} }
} }
Log.v("Registering fonts");
ftfontMan.registerFont(fontsPath ~ "arial.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Normal); ftfontMan.registerFont(fontsPath ~ "arial.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "arialbd.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Bold); ftfontMan.registerFont(fontsPath ~ "arialbd.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "arialbi.ttf", FontFamily.SansSerif, "Arial", true, FontWeight.Bold); ftfontMan.registerFont(fontsPath ~ "arialbi.ttf", FontFamily.SansSerif, "Arial", true, FontWeight.Bold);
@ -1590,9 +1594,13 @@ void releaseResourcesOnAppExit() {
void initLogs() { void initLogs() {
version (Windows) { version (Windows) {
debug { debug {
Log.setFileLogger(std.stdio.File("ui.log", "w")); Log.setFileLogger(new std.stdio.File("ui.log", "w"));
} else { } else {
// no logging // no logging unless version ForceLogs is set
version(ForceLogs) {
Log.setFileLogger(new std.stdio.File("ui.log", "w"));
Log.i("Logging to file ui.log");
}
} }
} else { } else {
Log.setStderrLogger(); Log.setStderrLogger();
@ -1600,6 +1608,13 @@ void initLogs() {
debug { debug {
Log.setLogLevel(LogLevel.Trace); Log.setLogLevel(LogLevel.Trace);
} else { } else {
Log.setLogLevel(LogLevel.Warn); version(ForceLogs) {
Log.setLogLevel(LogLevel.Trace);
Log.i("Log level: trace");
} else {
Log.setLogLevel(LogLevel.Warn);
Log.i("Log level: warn");
}
} }
Log.i("Logger is initialized");
} }

View File

@ -45,13 +45,28 @@ version (USE_OPENGL) {
import dlangui.graphics.glsupport; import dlangui.graphics.glsupport;
} }
private derelict.util.exception.ShouldThrow missingSymFunc( string symName ) {
// pragma(lib, "xcb"); import std.algorithm : equal;
// pragma(lib, "xcb-shm"); foreach(s; ["SDL_DestroyRenderer", "SDL_GL_DeleteContext", "SDL_DestroyWindow", "SDL_PushEvent",
// pragma(lib, "xcb-image"); "SDL_GL_SetAttribute", "SDL_GL_CreateContext", "SDL_GetError",
// pragma(lib, "X11-xcb"); "SDL_CreateWindow", "SDL_CreateRenderer", "SDL_GetWindowSize",
// pragma(lib, "X11"); "SDL_GL_GetDrawableSize", "SDL_GetWindowID", "SDL_SetWindowSize",
// pragma(lib, "dl"); "SDL_ShowWindow", "SDL_SetWindowTitle", "SDL_CreateRGBSurfaceFrom",
"SDL_SetWindowIcon", "SDL_FreeSurface", "SDL_ShowCursor",
"SDL_SetCursor", "SDL_CreateSystemCursor", "SDL_DestroyTexture",
"SDL_CreateTexture", "SDL_UpdateTexture", "SDL_RenderCopy",
"SDL_GL_SwapWindow", "SDL_GL_MakeCurrent", "SDL_SetRenderDrawColor",
"SDL_RenderClear", "SDL_RenderPresent", "SDL_GetModState",
"SDL_RemoveTimer", "SDL_RemoveTimer", "SDL_PushEvent",
"SDL_RegisterEvents", "SDL_WaitEvent", "SDL_StartTextInput",
"SDL_Quit", "SDL_HasClipboardText", "SDL_GetClipboardText",
"SDL_free", "SDL_SetClipboardText", "SDL_Init"]) {
if (symName.equal(s)) // Symbol is used
return derelict.util.exception.ShouldThrow.Yes;
}
// Don't throw for unused symbol
return derelict.util.exception.ShouldThrow.No;
}
private __gshared uint USER_EVENT_ID; private __gshared uint USER_EVENT_ID;
private __gshared uint TIMER_EVENT_ID; private __gshared uint TIMER_EVENT_ID;
@ -1276,6 +1291,7 @@ int sdlmain(string[] args) {
currentTheme = createDefaultTheme(); currentTheme = createDefaultTheme();
try { try {
DerelictSDL2.missingSymbolCallback = &missingSymFunc;
// Load the SDL 2 library. // Load the SDL 2 library.
DerelictSDL2.load(); DerelictSDL2.load();
} catch (Exception e) { } catch (Exception e) {

View File

@ -905,8 +905,7 @@ int DLANGUIWinMain(void* hInstance, void* hPrevInstance,
char* lpCmdLine, int nCmdShow) { char* lpCmdLine, int nCmdShow) {
int result; int result;
try try {
{
Runtime.initialize(); Runtime.initialize();
// call SetProcessDPIAware to support HI DPI - fix by Kapps // call SetProcessDPIAware to support HI DPI - fix by Kapps
@ -973,7 +972,9 @@ int myWinMain(void* hInstance, void* hPrevInstance, char* lpCmdLine, int iCmdSho
_cmdShow = iCmdShow; _cmdShow = iCmdShow;
_hInstance = hInstance; _hInstance = hInstance;
Log.v("Creating platform");
w32platform = new Win32Platform(); w32platform = new Win32Platform();
Log.v("Registering window class");
if (!w32platform.registerWndClass()) { if (!w32platform.registerWndClass()) {
MessageBoxA(null, "This program requires Windows NT!", "DLANGUI App".toStringz, MB_ICONERROR); MessageBoxA(null, "This program requires Windows NT!", "DLANGUI App".toStringz, MB_ICONERROR);
return 0; return 0;
@ -981,6 +982,7 @@ int myWinMain(void* hInstance, void* hPrevInstance, char* lpCmdLine, int iCmdSho
Platform.setInstance(w32platform); Platform.setInstance(w32platform);
Log.v("Initializing font manager");
if (!initFontManager()) { if (!initFontManager()) {
Log.e("******************************************************************"); Log.e("******************************************************************");
Log.e("No font files found!!!"); Log.e("No font files found!!!");