clear some code

This commit is contained in:
gazer 2016-01-04 21:03:35 +03:00
parent 57002757b7
commit 936838bf2d
2 changed files with 17 additions and 40 deletions

View File

@ -47,7 +47,7 @@ static if (ENABLE_OPENGL) {
import dlangui.graphics.gldrawbuf; import dlangui.graphics.gldrawbuf;
import dlangui.graphics.glsupport; import dlangui.graphics.glsupport;
} }
private derelict.util.exception.ShouldThrow missingSymFunc( string symName ) { private derelict.util.exception.ShouldThrow missingSymFunc( string symName ) {
import std.algorithm : equal; import std.algorithm : equal;
foreach(s; ["SDL_DestroyRenderer", "SDL_GL_DeleteContext", "SDL_DestroyWindow", "SDL_PushEvent", foreach(s; ["SDL_DestroyRenderer", "SDL_GL_DeleteContext", "SDL_DestroyWindow", "SDL_PushEvent",
@ -114,16 +114,16 @@ class SDLWindow : Window {
} }
static if (ENABLE_OPENGL) { static if (ENABLE_OPENGL)
{
static private bool _gl3Reloaded = false; static private bool _gl3Reloaded = false;
private SDL_GLContext _context; private SDL_GLContext _context;
}
static if (ENABLE_OPENGL) {
protected bool createContext(int versionMajor, int versionMinor) { protected bool createContext(int versionMajor, int versionMinor) {
Log.i("Trying to create OpenGL ", versionMajor, ".", versionMinor, " context"); Log.i("Trying to create OpenGL ", versionMajor, ".", versionMinor, " context");
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, versionMajor); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, versionMajor);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, versionMinor); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, versionMinor);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
_context = SDL_GL_CreateContext(_win); // Create the actual context and make it current _context = SDL_GL_CreateContext(_win); // Create the actual context and make it current
if (!_context) if (!_context)
Log.e("SDL_GL_CreateContext failed: ", fromStringz(SDL_GetError())); Log.e("SDL_GL_CreateContext failed: ", fromStringz(SDL_GetError()));
@ -176,9 +176,7 @@ class SDLWindow : Window {
static if (ENABLE_OPENGL) { static if (ENABLE_OPENGL) {
if (_enableOpengl) { if (_enableOpengl) {
Log.i("Trying to create OpenGL 3.2 context");
createContext(3, 2); createContext(3, 2);
//_context = SDL_GL_CreateContext(_win); // Create the actual context and make it current
if (!_context) { if (!_context) {
Log.e("SDL_GL_CreateContext failed: ", fromStringz(SDL_GetError())); Log.e("SDL_GL_CreateContext failed: ", fromStringz(SDL_GetError()));
Log.w("trying other versions of OpenGL"); Log.w("trying other versions of OpenGL");
@ -237,7 +235,7 @@ class SDLWindow : Window {
return SDL_GetWindowID(_win); return SDL_GetWindowID(_win);
return 0; return 0;
} }
override void show() { override void show() {
Log.d("SDLWindow.show()"); Log.d("SDLWindow.show()");
if (_mainWidget && !(_flags & WindowFlag.Resizable)) { if (_mainWidget && !(_flags & WindowFlag.Resizable)) {
@ -453,7 +451,7 @@ class SDLWindow : Window {
SDL_RenderPresent(_renderer); SDL_RenderPresent(_renderer);
} }
} }
ColorDrawBuf _drawbuf; ColorDrawBuf _drawbuf;
//bool _exposeSent; //bool _exposeSent;
@ -743,7 +741,7 @@ class SDLWindow : Window {
return 0x10000 | keyCode; return 0x10000 | keyCode;
} }
} }
uint convertKeyFlags(uint flags) { uint convertKeyFlags(uint flags) {
uint res; uint res;
if (flags & KMOD_CTRL) if (flags & KMOD_CTRL)
@ -766,7 +764,7 @@ class SDLWindow : Window {
res |= KeyFlag.LAlt | KeyFlag.Alt; res |= KeyFlag.LAlt | KeyFlag.Alt;
return res; return res;
} }
bool processTextInput(const char * s) { bool processTextInput(const char * s) {
string str = fromStringz(s).dup; string str = fromStringz(s).dup;
dstring ds = toUTF32(str); dstring ds = toUTF32(str);
@ -838,7 +836,7 @@ class SDLWindow : Window {
override void invalidate() { override void invalidate() {
_platform.sendRedrawEvent(windowId, ++_lastRedrawEventCode); _platform.sendRedrawEvent(windowId, ++_lastRedrawEventCode);
} }
void processRedrawEvent(uint code) { void processRedrawEvent(uint code) {
if (code == _lastRedrawEventCode) if (code == _lastRedrawEventCode)
redraw(); redraw();
@ -887,23 +885,16 @@ private __gshared bool _enableOpengl;
class SDLPlatform : Platform { class SDLPlatform : Platform {
this() { this() {
} }
private SDLWindow[uint] _windowMap;
~this() { ~this() {
foreach(ref SDLWindow wnd; _windowMap) { foreach(ref SDLWindow wnd; _windowMap) {
destroy(wnd); destroy(wnd);
wnd = null; wnd = null;
} }
destroy(_windowMap); destroy(_windowMap);
disconnect();
}
void disconnect() {
/* Cleanup */
}
bool connect() {
return true;
} }
SDLWindow getWindow(uint id) { SDLWindow getWindow(uint id) {
@ -944,7 +935,6 @@ class SDLPlatform : Platform {
event.user.windowID = windowId; event.user.windowID = windowId;
event.user.code = code; event.user.code = code;
SDL_PushEvent(&event); SDL_PushEvent(&event);
} }
override Window createWindow(dstring windowCaption, Window parent, uint flags = WindowFlag.Resizable, uint width = 0, uint height = 0) { override Window createWindow(dstring windowCaption, Window parent, uint flags = WindowFlag.Resizable, uint width = 0, uint height = 0) {
@ -982,8 +972,6 @@ class SDLPlatform : Platform {
bool skipNextQuit = false; bool skipNextQuit = false;
while(!quit) { while(!quit) {
//redrawWindows(); //redrawWindows();
//if (SDL_PollEvent(&event)) {
if (SDL_WaitEvent(&event)) { if (SDL_WaitEvent(&event)) {
//Log.d("Event.type = ", event.type); //Log.d("Event.type = ", event.type);
@ -1150,9 +1138,7 @@ class SDLPlatform : Platform {
} }
_windowToClose = null; _windowToClose = null;
} }
//
if (_windowMap.length == 0) { if (_windowMap.length == 0) {
//quit = true;
SDL_Quit(); SDL_Quit();
quit = true; quit = true;
} }
@ -1161,7 +1147,7 @@ class SDLPlatform : Platform {
Log.i("exiting message loop"); Log.i("exiting message loop");
return 0; return 0;
} }
/// retrieves text from clipboard (when mouseBuffer == true, use mouse selection clipboard - under linux) /// retrieves text from clipboard (when mouseBuffer == true, use mouse selection clipboard - under linux)
override dstring getClipboardText(bool mouseBuffer = false) { override dstring getClipboardText(bool mouseBuffer = false) {
if (!SDL_HasClipboardText()) if (!SDL_HasClipboardText())
@ -1173,14 +1159,12 @@ class SDLPlatform : Platform {
SDL_free(txt); SDL_free(txt);
return toUTF32(s); return toUTF32(s);
} }
/// sets text to clipboard (when mouseBuffer == true, use mouse selection clipboard - under linux) /// sets text to clipboard (when mouseBuffer == true, use mouse selection clipboard - under linux)
override void setClipboardText(dstring text, bool mouseBuffer = false) { override void setClipboardText(dstring text, bool mouseBuffer = false) {
string s = toUTF8(text); string s = toUTF8(text);
SDL_SetClipboardText(s.toStringz); SDL_SetClipboardText(s.toStringz);
} }
protected SDLWindow[uint] _windowMap;
} }
version (Windows) { version (Windows) {
@ -1321,13 +1305,9 @@ int sdlmain(string[] args) {
USER_EVENT_ID = SDL_RegisterEvents(1); USER_EVENT_ID = SDL_RegisterEvents(1);
TIMER_EVENT_ID = SDL_RegisterEvents(1); TIMER_EVENT_ID = SDL_RegisterEvents(1);
int request = SDL_GetDesktopDisplayMode(0,&displayMode); int request = SDL_GetDesktopDisplayMode(0, &displayMode);
static if (ENABLE_OPENGL) { static if (ENABLE_OPENGL) {
// we want OpenGL 3.2
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
// Set OpenGL attributes // Set OpenGL attributes
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
@ -1335,10 +1315,7 @@ int sdlmain(string[] args) {
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
} }
SDLPlatform sdl = new SDLPlatform(); auto sdl = new SDLPlatform;
if (!sdl.connect()) {
return 1;
}
Platform.setInstance(sdl); Platform.setInstance(sdl);

View File

@ -966,7 +966,7 @@ class X11Platform : Platform {
this() { this() {
} }
X11Window[XWindow] _windowMap; private X11Window[XWindow] _windowMap;
/** /**
* create window * create window