ecere,ecereCOM: support Emscriptem platform. add new Emscripten interface driver.
authorRejean Loyer <redj@ecere.com>
Sun, 14 Sep 2014 18:36:27 +0000 (14:36 -0400)
committerJerome St-Louis <jerome@ecere.com>
Thu, 15 Oct 2015 00:19:25 +0000 (20:19 -0400)
 - <NOTE> had to move GetDisplayDriver and GetDisplaySystem to end of Display.ec file due to compiler issue
 - #if !defined(__EMSCRIPTEN__) out:
    - dynamic loading
    - thread/mutex/semaphore and Condition class
    - file monitoring
    - png/jpeg/gif
    - X driver
    - NCurses driver
    - dcom
 - add emscripten_main_loop_callback in GuiApplication.ec
 - use of glfw and a bit of tweaking in the OpenGL driver

27 files changed:
ecere/ecere.epj
ecere/src/com/instance.c
ecere/src/com/instance.ec
ecere/src/gfx/Display.ec
ecere/src/gfx/DisplaySystem.ec
ecere/src/gfx/bitmaps/GIFFormat.ec
ecere/src/gfx/bitmaps/PNGFormat.ec
ecere/src/gfx/drivers/NCursesDisplayDriver.ec
ecere/src/gfx/drivers/OpenGLDisplayDriver.ec
ecere/src/gfx/drivers/XDisplayDriver.ec
ecere/src/gui/Desktop3D.ec
ecere/src/gui/GuiApplication.ec
ecere/src/gui/Window.ec
ecere/src/gui/drivers/EmscriptenInterface.ec [new file with mode: 0644]
ecere/src/gui/drivers/NCursesInterface.ec
ecere/src/gui/drivers/XInterface.ec
ecere/src/gui/skins/WindowsSkin.ec
ecere/src/net/dcom.ec
ecere/src/sys/Condition.ec
ecere/src/sys/EARArchive.ec
ecere/src/sys/FileMonitor.ec
ecere/src/sys/GlobalAppSettings.ec
ecere/src/sys/Mutex.ec
ecere/src/sys/Semaphore.ec
ecere/src/sys/System.ec
ecere/src/sys/Thread.ec
ecere/src/sys/i18n.ec

index d1e66f3..4757285 100644 (file)
@@ -1873,6 +1873,12 @@ from wherever you obtained them.
                                  }
                               }
                            ]
+                        },
+                        {
+                           "FileName" : "EmscriptenInterface.ec",
+                           "Options" : {
+                              "ExcludeFromBuild" : false
+                           }
                         }
                      ],
                      "Options" : {
index 5ad25c8..3539e8d 100644 (file)
@@ -248,7 +248,7 @@ bool Instance_LocateModule(const char * name, char * fileName)
    }
 #elif defined(__unix__)
    //File f = FileOpen("/proc/self/maps", read);
-   FILE * f;
+   FILE * f = null;
    char exeName[MAX_FILENAME];
    exeName[0] = 0;
 #if defined(__linux__)
@@ -325,7 +325,7 @@ bool Instance_LocateModule(const char * name, char * fileName)
       }
       fclose(f);
    }
-#if !defined(ECERE_NOFILE) && !defined(__linux__)
+#if !defined(ECERE_NOFILE) && !defined(__linux__) && !defined(__EMSCRIPTEN__)
    if(name && name[0])
    {
       // Couldn't locate libraries with /proc/curmap/map, attempt with ldd
@@ -404,7 +404,7 @@ bool Instance_LocateModule(const char * name, char * fileName)
 
 void Instance_COM_Initialize(int argc, char ** argv, char ** parsedCommand, int * argcPtr, const char *** argvPtr)
 {
-#if !defined(__WIN32__) && !defined(ECERE_BOOTSTRAP)
+#if !defined(__WIN32__) && !defined(__EMSCRIPTEN__) && !defined(ECERE_BOOTSTRAP)
    // Disable stdout buffering on Unix
    setvbuf(stdout, null, _IONBF, 0);
 #endif
@@ -476,7 +476,9 @@ void * Instance_Module_Load(const char * libLocation, const char * name, void **
       strcat(fileName, ".so");
 #endif
 
+#if !defined(__EMSCRIPTEN__)
    library = dlopen(fileName, RTLD_LAZY);
+#endif
    while(!library && attempts < sizeof(paths)/sizeof(paths[0]))
    {
       if(paths[attempts])
@@ -499,15 +501,19 @@ void * Instance_Module_Load(const char * libLocation, const char * name, void **
 #else
          strcat(fileName, ".so");
 #endif
+#if !defined(__EMSCRIPTEN__)
       library = dlopen(fileName, RTLD_LAZY);
+#endif
    }
 
    if(library)
    {
       *Load = dlsym(library, "__ecereDll_Load");
       *Unload = dlsym(library, "__ecereDll_Unload");
+#if !defined(__EMSCRIPTEN__)
       if(!*Load)
          dlclose(library);
+#endif
    }
 #elif defined(__APPLE__)
    if(libLocation || strchr(name, '/'))
@@ -553,7 +559,7 @@ void Instance_Module_Free(void * library)
 #if defined(__WIN32__) && !defined(__EMSCRIPTEN__)
    if(library)
       FreeLibrary(library);
-#elif defined(__unix__) || defined(__APPLE__)
+#elif (defined(__unix__) || defined(__APPLE__)) && !defined(__EMSCRIPTEN__)
    if(library)
       dlclose(library);
 #endif
index 438cd81..28aa627 100644 (file)
@@ -16,9 +16,11 @@ import "dataTypes"
 
 #undef __BLOCKS__
 
+#if !defined(__EMSCRIPTEN__)
 #if !defined(ECERE_BOOTSTRAP)
 import "Mutex"
 #endif
+#endif
 
 // #define MEMINFO
 /*
@@ -37,7 +39,9 @@ import "Mutex"
 #endif
 
 #ifdef MEMINFO
+#if !defined(__EMSCRIPTEN__)
 import "Thread"
+#endif
 static define MAX_MEMORY_LOC = 40;
 static define MAX_STACK_FRAMES = 1000;
 
@@ -183,7 +187,9 @@ public dllexport void MemoryGuard_PushLoc(const char * loc)
 {
 #ifdef MEMINFO
    MemStack stack;
+#if !defined(__EMSCRIPTEN__)
    memMutex.Wait();
+#endif
    stack = (MemStack)memStacks.Find(GetCurrentThreadID());
    if(!stack)
    {
@@ -193,22 +199,28 @@ public dllexport void MemoryGuard_PushLoc(const char * loc)
    }
    if(stack.pos < MAX_STACK_FRAMES)
       stack.frames[stack.pos++] = loc;
+#if !defined(__EMSCRIPTEN__)
    memMutex.Release();
 #endif
+#endif
 }
 
 public dllexport void MemoryGuard_PopLoc()
 {
 #ifdef MEMINFO
    MemStack stack;
+#if !defined(__EMSCRIPTEN__)
    memMutex.Wait();
+#endif
    stack = (MemStack)memStacks.Find(GetCurrentThreadID());
    if(stack && stack.pos > 0)
    {
       stack.pos--;
    }
+#if !defined(__EMSCRIPTEN__)
    memMutex.Release();
 #endif
+#endif
 }
 
 #ifdef ECERE_STATIC
@@ -707,9 +719,11 @@ static uint TOTAL_MEM = 0;
 static uint OUTSIDE_MEM = 0;
 #endif
 
+#if !defined(__EMSCRIPTEN__)
 #if !defined(ECERE_BOOTSTRAP)
 static Mutex memMutex { };
 #endif
+#endif
 
 private class MemBlock : struct
 {
@@ -5874,7 +5888,7 @@ static int64 GetEnumSize(Class _class)
 #define strnicmp strncasecmp
 #endif
 
-#if defined(ECERE_BOOTSTRAP) || (defined(__GNUC__) && !defined(__DJGPP__) && !defined(__WIN32__))
+#if defined(ECERE_BOOTSTRAP) || (defined(__GNUC__) && !defined(__DJGPP__) && !defined(__WIN32__) && !defined(__EMSCRIPTEN__))
 #undef strlwr
 #undef strupr
 default dllexport char * strlwr(char *string)
index 7013496..2f0b541 100644 (file)
@@ -48,7 +48,9 @@ public class FontFlags
 
 __attribute__((unused)) static void DummyFunction()
 {
+#if !defined(__EMSCRIPTEN__)
    Mutex { };
+#endif
 }
 
 public class DisplayDriver
@@ -179,27 +181,6 @@ public:
 public enum Alignment { left, right, center };
 public enum ClearType { colorBuffer, depthBuffer, colorAndDepth };
 
-subclass(DisplayDriver) GetDisplayDriver(const char * driverName)
-{
-   if(driverName)
-   {
-      OldLink link;
-      for(link = class(DisplayDriver).derivatives.first; link; link = link.next)
-      {
-         subclass(DisplayDriver) displayDriver = link.data;
-         if(displayDriver && displayDriver.name && !strcmp(displayDriver.name, driverName))
-            return displayDriver;
-      }
-   }
-   return null;
-}
-
-DisplaySystem GetDisplaySystem(const char * driverName)
-{
-   subclass(DisplayDriver) displayDriver = GetDisplayDriver(driverName);
-   return displayDriver ? displayDriver.displaySystem : null;
-}
-
 define textCellW = 8;
 define textCellH = 16;
 
@@ -549,7 +530,9 @@ public:
       result = displaySystem && displaySystem.Lock();
       if(result && render)
       {
+#if !defined(__EMSCRIPTEN__)
          mutex.Wait();
+#endif
 
          if(!current)
             result = displaySystem.driver.Lock(this);
@@ -575,7 +558,9 @@ public:
          */
          if(!current && displaySystem)
             displaySystem.driver.Unlock(this);
+#if !defined(__EMSCRIPTEN__)
          mutex.Release();
+#endif
       }
       if(displaySystem)
          displaySystem.Unlock();
@@ -1128,7 +1113,9 @@ private:
    DisplaySystem displaySystem;
    void * window;
 
+#if !defined(__EMSCRIPTEN__)
    Mutex mutex { };
+#endif
    int current;
 
 #if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D)
@@ -1909,3 +1896,25 @@ public int BestColorMatch(ColorAlpha * palette, int start, int end, Color rgb)
    }
    return best;
 }
+
+// had to move this here due to compiler ordering issue for "get property" symbol
+subclass(DisplayDriver) GetDisplayDriver(const char * driverName)
+{
+   if(driverName)
+   {
+      OldLink link;
+      for(link = class(DisplayDriver).derivatives.first; link; link = link.next)
+      {
+         subclass(DisplayDriver) displayDriver = link.data;
+         if(displayDriver && displayDriver.name && !strcmp(displayDriver.name, driverName))
+            return displayDriver;
+      }
+   }
+   return null;
+}
+
+DisplaySystem GetDisplaySystem(const char * driverName)
+{
+   subclass(DisplayDriver) displayDriver = GetDisplayDriver(driverName);
+   return displayDriver ? displayDriver.displaySystem : null;
+}
index 9506095..b584b82 100644 (file)
@@ -1,6 +1,8 @@
 namespace gfx;
 
+#if !defined(__EMSCRIPTEN__)
 import "Mutex"
+#endif
 import "Display"
 
 String printingDocumentName;
@@ -168,7 +170,9 @@ public:
    bool Lock()
    {
       bool result = false;
+#if !defined(__EMSCRIPTEN__)
       mutex.Wait();
+#endif
 
       if(!current)
          result = driver.LockSystem(this);
@@ -184,7 +188,9 @@ public:
       if(!current)
          driver.UnlockSystem(this);
 
+#if !defined(__EMSCRIPTEN__)
       mutex.Release();
+#endif
    }
 #if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D)
    // --- Materials List Management ---
@@ -329,5 +335,7 @@ private:
 
    void * driverData;
    int current;
+#if !defined(__EMSCRIPTEN__)
    Mutex mutex { };
+#endif
 };
index 9d81af9..681692d 100644 (file)
@@ -1,9 +1,11 @@
 namespace gfx::bitmaps;
 
-#include "gif_lib.h"
-
 import "Display"
 
+#if !defined(__EMSCRIPTEN__)
+
+#include "gif_lib.h"
+
 static int ReadData(GifFileType * gifFile, GifByteType * bytes, int size)
 {
    File f = gifFile->UserData;
@@ -129,3 +131,5 @@ class GIFFormat : BitmapFormat
       return result;
    }
 }
+
+#endif // !defined(__EMSCRIPTEN__)
index 22de51a..95e596e 100644 (file)
@@ -2,6 +2,8 @@ namespace gfx::bitmaps;
 
 import "Display"
 
+#if !defined(__EMSCRIPTEN__)
+
 #define uint _uint
 #include "png.h"
 #undef uint
@@ -307,3 +309,5 @@ class PNGFormat : BitmapFormat
       return result;
    }
 }
+
+#endif // !defined(__EMSCRIPTEN__)
index 2e7cd19..b15db41 100644 (file)
@@ -4,7 +4,7 @@ import "instance"
 
 #undef __BLOCKS__
 
-#if (defined(__unix__) || defined(__APPLE__)) && !defined(__DOS__)
+#if (defined(__unix__) || defined(__APPLE__)) && !defined(__DOS__) && !defined(__EMSCRIPTEN__)
 
 #include <curses.h>
 
index 0175a7b..af87f3d 100644 (file)
@@ -18,7 +18,7 @@ namespace gfx::drivers;
 
 #else
 
-   #if !defined(__ANDROID__)
+   #if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
 
       #define property _property
       #define new _new
@@ -80,6 +80,27 @@ namespace gfx::drivers;
    #include <GLES/gl.h>
    #include <EGL/egl.h>
 
+#elif defined(__EMSCRIPTEN__)
+
+   #define property _property
+   #define uint _uint
+
+   #include <GL/gl.h>
+   #include <GL/glut.h>
+
+   //#include <GLES/gl.h>
+   //#include <EGL/egl.h>
+
+   //#include <GLES2/gl.h>
+   //#include <EGL/egl.h>
+
+   //#include <GLES2/gl2.h>
+   #include <GL/glfw.h>
+   #include <emscripten/emscripten.h>
+
+   #undef property
+   #undef uint
+
 #else
 
    #include <GL/gl.h>
@@ -93,7 +114,7 @@ import "Display"
 
 #if defined(__unix__) || defined(__APPLE__)
 
-   #ifndef __ANDROID__
+   #if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
    import "XInterface"
    #endif
 
@@ -364,6 +385,38 @@ static double nearPlane = 1;
 
    static PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = NULL;
 
+#elif defined(__ANDROID__)
+
+   #define GL_FRAMEBUFFER           GL_FRAMEBUFFER_OES
+   #define GL_RENDERBUFFER          GL_RENDERBUFFER_OES
+   #define GL_COLOR_ATTACHMENT0     GL_COLOR_ATTACHMENT0_OES
+
+   #define GL_POLYGON_STIPPLE 0xFFFF
+   #define GL_LINE_STIPPLE 0xFFFF
+   #define GL_LINE 0xFFFF
+   #define GL_FILL 0xFFFF
+   #define GL_ALL_ATTRIB_BITS 0xFFFF
+   #define GL_LIGHT_MODEL_LOCAL_VIEWER 0xFFFF
+
+   #define GL_POLYGON      9
+   #define GL_QUADS        7
+
+   //#define GL_QUADS              0
+   #define GL_QUAD_STRIP         0
+   //#define GL_DOUBLE             0
+   //#define GL_UNSIGNED_INT       0
+   //#define GL_FILL               0
+   //#define GL_LINE               0
+   //#define GL_LINE_STIPPLE       0
+   #define GL_BGRA_EXT           0
+   #define GL_UNPACK_ROW_LENGTH  0
+   #define GL_UNPACK_SKIP_PIXELS 0
+   #define GL_UNPACK_SKIP_ROWS   0
+   #define GL_RGBA8              0
+   #define GL_PACK_ROW_LENGTH    0
+   #define GL_PACK_SKIP_ROWS     0
+   #define GL_PACK_SKIP_PIXELS   0
+
 #endif
 
 // Our own matrix stack
@@ -377,26 +430,15 @@ static int curStack = 0;
 #if defined(__ANDROID__)
    #define glBindFramebuffer        glBindFramebufferOES
    #define glBindRenderbuffer       glBindRenderbufferOES
-   #define GL_FRAMEBUFFER           GL_FRAMEBUFFER_OES
-   #define GL_RENDERBUFFER          GL_RENDERBUFFER_OES
    #define glFramebufferTexture2D   glFramebufferTexture2DOES
-   #define GL_COLOR_ATTACHMENT0     GL_COLOR_ATTACHMENT0_OES
    #define glGenFramebuffers        glGenFramebuffersOES
    #define glGenRenderbuffers       glGenRenderbuffersOES
    #define glDeleteFramebuffers     glDeleteFramebuffersOES
    #define glDeleteRenderbuffers    glDeleteRenderbuffersOES
 
-   #define GL_POLYGON_STIPPLE 0xFFFF
-   #define GL_LINE_STIPPLE 0xFFFF
-   #define GL_LINE 0xFFFF
-   #define GL_FILL 0xFFFF
-   #define GL_ALL_ATTRIB_BITS 0xFFFF
-   #define GL_LIGHT_MODEL_LOCAL_VIEWER 0xFFFF
    #define GL_INT                                  0x1404
    #define GL_UNSIGNED_INT                         0x1405
    #define GL_DOUBLE                               0x140A
-   #define GL_POLYGON      9
-   #define GL_QUADS        7
    #define APIENTRY
 #endif
 
@@ -437,24 +479,6 @@ static int curStack = 0;
    #define glVertex3fv           glesVertex3fv
    #define glLightModeli         glesLightModeli
 
-#if defined(__ANDROID__)
-   //#define GL_QUADS              0
-   #define GL_QUAD_STRIP         0
-   //#define GL_DOUBLE             0
-   //#define GL_UNSIGNED_INT       0
-   //#define GL_FILL               0
-   //#define GL_LINE               0
-   //#define GL_LINE_STIPPLE       0
-   #define GL_BGRA_EXT           0
-   #define GL_UNPACK_ROW_LENGTH  0
-   #define GL_UNPACK_SKIP_PIXELS 0
-   #define GL_UNPACK_SKIP_ROWS   0
-   #define GL_RGBA8              0
-   #define GL_PACK_ROW_LENGTH    0
-   #define GL_PACK_SKIP_ROWS     0
-   #define GL_PACK_SKIP_PIXELS   0
-#endif
-
 #else
 
 #define glVertexPointerd(nc, s, p, nv)       glVertexPointer(nc, GL_DOUBLE, s, p)
@@ -1266,7 +1290,7 @@ class OGLDisplay : struct
    int imageBuffers[2];
    byte * pboMemory1, * pboMemory2;
    */
-#elif !defined(__ANDROID__)
+#elif !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
    GLXContext glContext;
 
    Pixmap pixmap;
@@ -1300,7 +1324,7 @@ class OGLSystem : struct
    HDC hdc;
    HGLRC glrc;
    HWND hwnd;
-#elif !defined(__ANDROID__)
+#elif !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
    XVisualInfo * visualInfo;
    GLXContext glContext;
    GLXDrawable glxDrawable;
@@ -1343,7 +1367,7 @@ class OpenGLDisplayDriver : DisplayDriver
 
    bool LockSystem(DisplaySystem displaySystem)
    {
-#if !defined(__ANDROID__)
+#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
       OGLSystem oglSystem = displaySystem.driverData;
       if(useSingleGLContext) return true;
    #if defined(__WIN32__)
@@ -1365,7 +1389,7 @@ class OpenGLDisplayDriver : DisplayDriver
       wglMakeCurrent(null, null);
    #elif defined(__unix__) || defined(__APPLE__)
       // printf("Making NULL current\n");
-      #if defined(__ANDROID__)
+      #if defined(__ANDROID__) || defined(__EMSCRIPTEN__)
       #else
       glXMakeCurrent(xGlobalDisplay, None, null);
       #endif
@@ -1375,7 +1399,7 @@ class OpenGLDisplayDriver : DisplayDriver
 
    bool Lock(Display display)
    {
-#if !defined(__ANDROID__)
+#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
       OGLDisplay oglDisplay = display.driverData;
       if(useSingleGLContext) return true;
    #if defined(__WIN32__)
@@ -1423,7 +1447,7 @@ class OpenGLDisplayDriver : DisplayDriver
          if(oglDisplay.memBitmap) DeleteObject(oglDisplay.memBitmap);
 
    #elif defined(__unix__) || defined(__APPLE__)
-      #if defined(__ANDROID__)
+      #if defined(__ANDROID__) || defined(__EMSCRIPTEN__)
       #else
          if(oglDisplay.shapePixmap)
             XFreePixmap(xGlobalDisplay, oglDisplay.shapePixmap);
@@ -1605,6 +1629,20 @@ class OpenGLDisplayDriver : DisplayDriver
          egl_init_display(guiApp.desktop.windowHandle);
          CheckExtensions(oglSystem);
          result = true;
+      #elif defined(__EMSCRIPTEN__)
+         if(glfwInit() == GL_TRUE)
+         {
+            const int width = 640, height = 480;
+            if(glfwOpenWindow(width, height, 8, 8, 8, 8, 16, 0, GLFW_WINDOW) == GL_TRUE)
+            {
+               //glfwSwapBuffers();
+               result = true;
+            }
+            else
+               printf("glfwOpenWindow() failed\n"); //glfwTerminate();
+         }
+         else
+            printf("glfwInit() failed\n"); //glfwTerminate();
       #else
       {
          X11Window root = RootWindow( xGlobalDisplay, DefaultScreen( xGlobalDisplay ) );
@@ -1669,6 +1707,8 @@ class OpenGLDisplayDriver : DisplayDriver
    #elif defined(__unix__) || defined(__APPLE__)
       #if defined(__ANDROID__)
          egl_term_display();
+      #elif defined(__EMSCRIPTEN__)
+         glfwTerminate();
       #else
       if(oglSystem.visualInfo)
       {
@@ -1693,7 +1733,7 @@ class OpenGLDisplayDriver : DisplayDriver
    {
       bool result = false;
       OGLDisplay oglDisplay = display.driverData;
-#if !defined(__ANDROID__)
+#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
       OGLSystem oglSystem = display.displaySystem.driverData;
 #endif
       if(!oglDisplay)
@@ -1716,7 +1756,7 @@ class OpenGLDisplayDriver : DisplayDriver
          else
             ReleaseDC(display.window, oglDisplay.hdc);
    #elif defined(__unix__) || defined(__APPLE__)
-      #if defined(__ANDROID__)
+      #if defined(__ANDROID__) || defined(__EMSCRIPTEN__)
       #else
          XVisualInfo * visualInfo = ((XWindowData)display.windowDriverData).visual;
          /*
@@ -1799,7 +1839,7 @@ class OpenGLDisplayDriver : DisplayDriver
    #if defined(__WIN32__)
          wglMakeCurrent(null, null);
    #elif defined(__unix__) || defined(__APPLE__)
-      #if defined(__ANDROID__)
+      #if defined(__ANDROID__) || defined(__EMSCRIPTEN__)
          result = true;
       #else
          glXMakeCurrent(xGlobalDisplay, None, null);
@@ -1976,7 +2016,7 @@ class OpenGLDisplayDriver : DisplayDriver
             ReleaseDC(display.window, hdc);
          }
 #elif defined(__unix__) || defined(__APPLE__)
-      #if defined(__ANDROID__)
+      #if defined(__ANDROID__) || defined(__EMSCRIPTEN__)
          result = true;
       #else
        int attrib[] =
@@ -2140,7 +2180,7 @@ class OpenGLDisplayDriver : DisplayDriver
 #if defined(__WIN32__)
          wglMakeCurrent(oglDisplay.hdc, oglDisplay.glrc);
 #elif defined(__unix__) || defined(__APPLE__)
-      #if defined(__ANDROID__)
+      #if defined(__ANDROID__) || defined(__EMSCRIPTEN__)
          width = eglWidth;
          height = eglHeight;
       #else
@@ -2278,7 +2318,7 @@ class OpenGLDisplayDriver : DisplayDriver
 
             ReleaseDC(0, hdc);
 #elif defined(__unix__) || defined(__APPLE__)
-      #if defined(__ANDROID__)
+      #if defined(__ANDROID__) || defined(__EMSCRIPTEN__)
       #else
             XTransform transform =
             {
@@ -2310,6 +2350,8 @@ class OpenGLDisplayDriver : DisplayDriver
 #elif defined(__unix__) || defined(__APPLE__)
       #if defined(__ANDROID__)
          eglSwapBuffers(eglDisplay, eglSurface);
+      #elif defined(__EMSCRIPTEN__)
+         glfwSwapBuffers();
       #else
          glXSwapBuffers(xGlobalDisplay, (GLXDrawable)display.window);
       #endif
@@ -4075,11 +4117,12 @@ IS_GLGetContext(DisplaySystem displaySystem)
 #if defined(__WIN32__)
       OGLSystem system = displaySystem.driverData;
       return system.glrc;
-#elif !defined(__ANDROID__)
+#elif defined(__ANDROID__)
+      return eglContext;
+#elif defined(__EMSCRIPTEN__)
+#else
       OGLSystem system = displaySystem.driverData;
       return system.glContext;
-#else
-      return eglContext;
 #endif
    }
    return null;
index 01497c9..81a6d8f 100644 (file)
@@ -2,7 +2,7 @@ namespace gfx::drivers;
 
 import "instance"
 
-#if (defined(__unix__) || defined(__APPLE__)) && !defined(ECERE_MINIGLX)
+#if (defined(__unix__) || defined(__APPLE__)) && !defined(ECERE_MINIGLX) && !defined(__EMSCRIPTEN__)
 
 default:
 
@@ -21,8 +21,10 @@ default:
 
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
+#if !defined(__EMSCRIPTEN__)
 #include <X11/extensions/shape.h>
 #include <X11/extensions/Xrender.h>
+#endif
 #include <X11/extensions/XShm.h>
 #include <sys/ipc.h>
 #include <sys/shm.h>
index d9e273e..45085a8 100644 (file)
@@ -54,7 +54,9 @@ static bool Window3D_Setup(Window window, bool positionChildren)
          window.display.driverData = virtualDesktop.display.driverData;
          window.display.current = virtualDesktop.display.current;
 
+#if !defined(__EMSCRIPTEN__)
          window.display.mutex = null;
+#endif
          window.ComputeAnchors(window.stateAnchor, window.stateSizeAnchor, &x,&y,&w,&h);
          virtualDesktop.display.Lock(false);
          window.windowHandle = Setup3DWindow(window, w, h);
index 87fe462..bb7fd95 100644 (file)
@@ -1,6 +1,14 @@
 namespace gui;
 
-#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
+#ifdef __EMSCRIPTEN__
+#include <emscripten.h>
+#endif
+
+#ifdef __EMSCRIPTEN__
+#include <emscripten.h>
+#endif
+
+#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
 #define property _property
 #define new _new
 #define class _class
@@ -77,7 +85,7 @@ import "network"
 import "CocoaInterface"
 #endif
 
-#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
+#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
 import "XInterface"
 #endif
 
@@ -160,9 +168,13 @@ public class GuiApplication : Application
 
    bool processAll;
 
+#if !defined(__EMSCRIPTEN__)
    Mutex waitMutex {};
+#endif
    bool waiting;
+#if !defined(__EMSCRIPTEN__)
    Mutex lockMutex {};
+#endif
 
    Window interimWindow;
    bool caretEnabled;
@@ -179,7 +191,9 @@ public class GuiApplication : Application
    {
       SystemCursor c;
 
+#if !defined(__EMSCRIPTEN__)
       mainThread = GetCurrentThreadID();
+#endif
       if(!guiApp)
          guiApp = this;
 
@@ -194,9 +208,11 @@ public class GuiApplication : Application
       for(c = 0; c<SystemCursor::enumSize; c++)
          systemCursors[c] = Cursor { systemCursor = c; };
 
+#if !defined(__EMSCRIPTEN__)
       globalSystem.eventSemaphore = Semaphore { };
       globalSystem.fileMonitorMutex = Mutex { };
       globalSystem.fileMonitors.offset = (uint)(uintptr)&((FileMonitor)0).prev;
+#endif
       return true;
    }
 
@@ -209,12 +225,12 @@ public class GuiApplication : Application
       delete desktop;
       customCursors.Clear();
 
-#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
+#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
       if(xGlobalDisplay)
          XUnlockDisplay(xGlobalDisplay);
 #endif
 
-#if !defined(__ANDROID__)
+#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
       // Because destruction of app won't be from main thread
       if(guiApplicationInitialized)
          lockMutex.Release();
@@ -238,9 +254,11 @@ public class GuiApplication : Application
       Network_Terminate();
 #endif
 
+#if !defined(__EMSCRIPTEN__)
       delete globalSystem.eventSemaphore;
       delete globalSystem.fileMonitorMutex;
       delete globalSystem.fileMonitorThread;
+#endif
 
       UnapplySkin(class(Window));
 
@@ -552,7 +570,9 @@ public class GuiApplication : Application
 
          errorLevel = 2;
 
+#if !defined(__EMSCRIPTEN__)
          lockMutex.Wait();
+#endif
 /*#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
          if(xGlobalDisplay)
             XLockDisplay(xGlobalDisplay);
@@ -572,7 +592,9 @@ public class GuiApplication : Application
             desktop.caption = appName;
             *&desktop.visible = true;
             desktop.position = Point { };
+#if !defined(__EMSCRIPTEN__)
             desktop.mutex = Mutex { };
+#endif
             desktop.created = true;
          }
 
@@ -599,6 +621,13 @@ public class GuiApplication : Application
             else
                defaultDriver = "OpenGL";
          }
+   #elif defined(__EMSCRIPTEN__)
+         {
+            if(driver)
+               defaultDriver = driver;
+            else
+               defaultDriver = "OpenGL";
+         }
    #else
          if((this.isGUIApp & 1) && !textMode)
          {
@@ -677,6 +706,10 @@ public:
             }
          }
 
+#ifdef __EMSCRIPTEN__
+      emscripten_set_main_loop(emscripten_main_loop_callback, 1/*60*/, 1);
+#endif
+
          if(desktop)
          {
             int terminated = 0;
@@ -703,16 +736,22 @@ public:
                      break;
                if(!child) break;
 
+#if !defined(__EMSCRIPTEN__)
                for(window = desktop.children.first; window; window = window.next)
                   if(window.mutex) window.mutex.Wait();
+#endif
                UpdateDisplay();
+#if !defined(__EMSCRIPTEN__)
                for(window = desktop.children.first; window; window = window.next)
                   if(window.mutex) window.mutex.Release();
+#endif
                wait = !ProcessInput(true);
+#if !defined(__EMSCRIPTEN__)
 #ifdef _DEBUG
                if(lockMutex.owningThread != GetCurrentThreadID())
                   PrintLn("WARNING: ProcessInput returned unlocked GUI!");
 #endif
+#endif
                if(!Cycle(wait))
                   wait = false;
 
@@ -720,15 +759,17 @@ public:
                   Wait();
                else
                {
-#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
+#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
                   if(xGlobalDisplay)
                      XUnlockDisplay(xGlobalDisplay);
 #endif
 
+#if !defined(__EMSCRIPTEN__)
                   lockMutex.Release();
                   lockMutex.Wait();
+#endif
 
-#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
+#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
                   if(xGlobalDisplay)
                      XLockDisplay(xGlobalDisplay);
 #endif
@@ -747,23 +788,27 @@ public:
 
    void Wait(void)
    {
-#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
+#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
       if(xGlobalDisplay)
          XUnlockDisplay(xGlobalDisplay);
 #endif
 
+#if !defined(__EMSCRIPTEN__)
       lockMutex.Release();
 
       waitMutex.Wait();
+#endif
       waiting = true;
       if(interfaceDriver)
          interfaceDriver.Wait();
       waiting = false;
+#if !defined(__EMSCRIPTEN__)
       waitMutex.Release();
 
       lockMutex.Wait();
+#endif
 
-#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
+#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
       if(xGlobalDisplay)
          XLockDisplay(xGlobalDisplay);
 #endif
@@ -814,7 +859,9 @@ public:
       {
          if(fullScreenMode && desktop.display)
          {
+#if !defined(__EMSCRIPTEN__)
             desktop.mutex.Wait();
+#endif
             if(desktop.active)
             {
                desktop.display.Lock(true);
@@ -836,7 +883,9 @@ public:
 
                desktop.display.Unlock();
             }
+#if !defined(__EMSCRIPTEN__)
             desktop.mutex.Release();
+#endif
          }
          else
          {
@@ -844,7 +893,9 @@ public:
 
             for(window = desktop.children.first; window; window = window.next)
             {
+#if !defined(__EMSCRIPTEN__)
                if(window.mutex) window.mutex.Wait();
+#endif
                if(window.visible && window.dirty)
                {
                   // Logf("Updating %s\n", window.name);
@@ -867,7 +918,9 @@ public:
                   usleep(1000000);
                   */
                }
+#if !defined(__EMSCRIPTEN__)
                if(window.mutex) window.mutex.Release();
+#endif
             }
          }
       }
@@ -875,7 +928,9 @@ public:
 
    void WaitEvent(void)
    {
+#if !defined(__EMSCRIPTEN__)
       globalSystem.eventSemaphore.Wait();
+#endif
    }
 
 #if !defined(ECERE_VANILLA) && !defined(ECERE_NONET)
@@ -1090,7 +1145,9 @@ public:
 
    void SignalEvent(void)
    {
+#if !defined(__EMSCRIPTEN__)
       globalSystem.eventSemaphore.Release();
+#endif
    }
 
    // TODO: Might want to make this private with simpler public version?
@@ -1282,6 +1339,7 @@ public:
 
    bool ProcessFileNotifications()
    {
+#if !defined(__EMSCRIPTEN__)
       bool activity = false;
       FileMonitor monitor, next;
       static int reentrant = 0;
@@ -1347,24 +1405,31 @@ public:
       // printf("[%d] Releasing in ProcessFileNotifications fileMonitor Mutex %x...\n", (int)GetCurrentThreadID(), globalSystem.fileMonitorMutex);
       globalSystem.fileMonitorMutex.Release();
       return activity;
+#else
+      return false;
+#endif
    }
 
    void Lock(void)
    {
+#if !defined(__EMSCRIPTEN__)
       lockMutex.Wait();
-#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
+#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
       if(xGlobalDisplay)
          XLockDisplay(xGlobalDisplay);
 #endif
+#endif
    }
 
    void Unlock(void)
    {
-#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
+#if !defined(__EMSCRIPTEN__)
+#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
       if(xGlobalDisplay)
          XUnlockDisplay(xGlobalDisplay);
 #endif
       lockMutex.Release();
+#endif
    }
 
    Cursor GetCursor(SystemCursor cursor)
@@ -1395,7 +1460,9 @@ public:
          return (const char *)(this ? appName : null);
       }
    };
+#if !defined(__EMSCRIPTEN__)
    property Semaphore semaphore { get { return globalSystem.eventSemaphore; } };
+#endif
    property bool alwaysEmptyInput{ set { processAll = value; } get { return processAll; } };
    property bool fullScreen
    {
@@ -1463,3 +1530,12 @@ public:
       set { timerResolution = value; if(interfaceDriver) interfaceDriver.SetTimerResolution(value); }
    };
 };
+
+#ifdef __EMSCRIPTEN__
+private void emscripten_main_loop_callback()
+{
+   guiApp.ProcessInput(false);
+   guiApp.Cycle(false);
+   guiApp.UpdateDisplay();
+}
+#endif
index bcc6bc8..a65d1e8 100644 (file)
@@ -568,6 +568,7 @@ private:
       OldLink slave;
       ResPtr ptr;
 
+#if !defined(__EMSCRIPTEN__)
       if(fileMonitor)
       {
          int i, lockCount = guiApp.lockMutex.lockCount;
@@ -577,6 +578,7 @@ private:
          for(i = 0; i < lockCount; i++)
             guiApp.lockMutex.Wait();
       }
+#endif
 
       if(parent)
       {
@@ -661,7 +663,9 @@ private:
       delete statusBar;
 
       OnDestroyed();
+#if !defined(__EMSCRIPTEN__)
       delete mutex;
+#endif
       delete icon;
 
       if(((subclass(Window))_class).pureVTbl)
@@ -1858,7 +1862,9 @@ private:
                   child.display.width = display.width;
                   child.display.height = display.height;
                   child.display.driverData = display.driverData;
+#if !defined(__EMSCRIPTEN__)
                   child.display.mutex = null;
+#endif
                }
             }
          }
@@ -5968,7 +5974,9 @@ private:
       {
          if(guiApp.fullScreenMode && guiApp.desktop.display)
          {
+#if !defined(__EMSCRIPTEN__)
             guiApp.desktop.mutex.Wait();
+#endif
             guiApp.desktop.display.Lock(true);
 
             Update(extent);
@@ -5992,12 +6000,16 @@ private:
             }
 
             guiApp.desktop.display.Unlock();
+#if !defined(__EMSCRIPTEN__)
             guiApp.desktop.mutex.Release();
+#endif
          }
          else
          {
             Window rootWindow = this.rootWindow;
+#if !defined(__EMSCRIPTEN__)
             rootWindow.mutex.Wait();
+#endif
             display.Lock(true);
 
             Update(extent);
@@ -6005,7 +6017,9 @@ private:
                guiApp.SignalEvent();
             else
             {
+#if !defined(__EMSCRIPTEN__)
                guiApp.waitMutex.Wait();
+#endif
                guiApp.interfaceDriver.Lock(rootWindow);
                if(!rootWindow.style.hidden && rootWindow.dirty)
                {
@@ -6017,10 +6031,14 @@ private:
                   rootWindow.dirty = false;
                }
                guiApp.interfaceDriver.Unlock(rootWindow);
+#if !defined(__EMSCRIPTEN__)
                guiApp.waitMutex.Release();
+#endif
             }
             display.Unlock();
+#if !defined(__EMSCRIPTEN__)
             rootWindow.mutex.Release();
+#endif
          }
       }
    }
@@ -6153,6 +6171,7 @@ private:
 
    void SetupFileMonitor()
    {
+#if !defined(__EMSCRIPTEN__)
       if(!fileMonitor)
       {
          fileMonitor = FileMonitor
@@ -6171,6 +6190,7 @@ private:
          };
          incref fileMonitor;
       }
+#endif
    }
 
 public:
@@ -6221,8 +6241,10 @@ public:
                }
          }
 
+#if !defined(__EMSCRIPTEN__)
          if(parent == guiApp.desktop && !mutex)
             mutex = Mutex {};
+#endif
 
          if(style.isDocument)
          {
@@ -7446,7 +7468,9 @@ public:
       SetupFileMonitor();
       if(fileName)
       {
+#if !defined(__EMSCRIPTEN__)
          fileMonitor.fileName = null;
+#endif
          saving = true;
 
          if(OnSaveFile(fileName))
@@ -7454,7 +7478,9 @@ public:
             //if(OnFileModified != Window::OnFileModified)
             {
                saving = false;
+#if !defined(__EMSCRIPTEN__)
                fileMonitor.fileName = fileName;
+#endif
             }
             return true;
          }
@@ -7489,7 +7515,9 @@ public:
             sprintf(filePath, "Untitled %d", documentID);
             fileDialog.filePath = filePath;
          }
+#if !defined(__EMSCRIPTEN__)
          fileMonitor.fileName = null;
+#endif
 
          fileDialog.type = save;
          fileDialog.text = $"Save As";
@@ -7526,11 +7554,13 @@ public:
                break;
             }
          }
+#if !defined(__EMSCRIPTEN__)
          //if(OnFileModified != Window::OnFileModified && fileName)
          {
             if(fileName)
                fileMonitor.fileName = fileName;
          }
+#endif
          delete fileDialog;
       }
       return (bool)result; // Actually returning result from Yes/NoCancel message box
@@ -9360,8 +9390,10 @@ public:
             UpdateCaption();
 
          // if(style.isDocument)
+#if !defined(__EMSCRIPTEN__)
          if(!saving)
             fileMonitor.fileName = value;
+#endif
       }
       get { return fileName; }
    };
@@ -9669,10 +9701,14 @@ private:
    int numIcons;
    int positionID;
 
+#if !defined(__EMSCRIPTEN__)
    Mutex mutex;
+#endif
    WindowState lastState;
 
+#if !defined(__EMSCRIPTEN__)
    FileMonitor fileMonitor;
+#endif
 
    FontResource setFont, systemFont;
    FontResource usedFont;
diff --git a/ecere/src/gui/drivers/EmscriptenInterface.ec b/ecere/src/gui/drivers/EmscriptenInterface.ec
new file mode 100644 (file)
index 0000000..eb3d17e
--- /dev/null
@@ -0,0 +1,286 @@
+namespace gui::drivers;
+
+#ifdef BUILDING_ECERE_COM
+import "Window"
+import "Interface"
+#else
+#ifdef ECERE_STATIC
+public import static "ecere"
+#else
+public import "ecere"
+#endif
+#endif
+
+#ifdef __EMSCRIPTEN__
+
+#include <stdio.h>
+
+// source file line number printf (sflnprintf)
+#define sflnprintf(format,...) printf("%s:% 5d: " format, __FILE__, __LINE__, ##__VA_ARGS__)
+
+#define property _property
+#define uint _uint
+
+//#include <GLES2/gl2.h>
+#include <GL/glfw.h>
+#include <emscripten/emscripten.h>
+
+#undef property
+#undef uint
+
+
+class EmscriptenInterface : Interface
+{
+   class_property(name) = "Emscripten";
+
+
+   // --- User Interface System ---
+
+   bool ::Initialize()
+   {
+      sflnprintf("class(EmscriptenInterface) ::Initialize [STUB!]\n");
+      return true;
+   }
+
+   void ::Terminate()
+   {
+      sflnprintf("class(EmscriptenInterface) ::Terminate [STUB!]\n");
+   }
+
+   bool ::ProcessInput(bool processAll)
+   {
+      sflnprintf("class(EmscriptenInterface) ::ProcessInput [STUB!]\n");
+      return false;
+   }
+
+   void ::Wait()
+   {
+      sflnprintf("class(EmscriptenInterface) ::Wait [STUB!]\n");
+   }
+
+   void ::Lock(Window window)
+   {
+      sflnprintf("class(EmscriptenInterface) ::Lock [STUB!]\n");
+   }
+
+   void ::Unlock(Window window)
+   {
+      sflnprintf("class(EmscriptenInterface) ::Unlock [STUB!]\n");
+   }
+
+   void ::SetTimerResolution(uint hertz)
+   {
+      sflnprintf("class(EmscriptenInterface) ::SetTimerResolution [STUB!] Implement high resolution timer here\n");
+   }
+
+   const char ** ::GraphicsDrivers(int * numDrivers)
+   {
+      //sflnprintf("class(EmscriptenInterface) ::GraphicsDrivers [STUB!]\n");
+      static const char *graphicsDrivers[] = { "OpenGL" };
+      *numDrivers = sizeof(graphicsDrivers) / sizeof(char *);
+      return (const char **)graphicsDrivers;
+      return null;
+   }
+
+   void ::EnsureFullScreen(bool * fullScreen)
+   {
+      sflnprintf("class(EmscriptenInterface) ::EnsureFullScreen [STUB!]\n");
+      *fullScreen = true;
+   }
+
+   void ::GetCurrentMode(bool * fullScreen, Resolution * resolution, PixelFormat * colorDepth, int * refreshRate)
+   {
+      sflnprintf("class(EmscriptenInterface) ::GetCurrentMode [STUB!]\n");
+   }
+
+   bool ::ScreenMode(bool fullScreen, Resolution resolution, PixelFormat colorDepth, int refreshRate, bool * textMode)
+   {
+      sflnprintf("class(EmscriptenInterface) ::ScreenMode [STUB!]\n");
+      return true;
+   }
+
+
+   // --- Window Creation ---
+
+   void * ::CreateRootWindow(Window window)
+   {
+      sflnprintf("class(EmscriptenInterface) ::CreateRootWindow [STUB!]\n");
+      return null;
+   }
+
+   void ::DestroyRootWindow(Window window)
+   {
+      sflnprintf("class(EmscriptenInterface) ::DestroyRootWindow [STUB!]\n");
+   }
+
+
+   // --- Window manipulation ---
+
+   void ::SetRootWindowCaption(Window window, const char * name)
+   {
+      sflnprintf("class(EmscriptenInterface) ::SetRootWindowCaption [STUB!]\n");
+   }
+
+   void ::PositionRootWindow(Window window, int x, int y, int w, int h, bool move, bool resize)
+   {
+      sflnprintf("class(EmscriptenInterface) ::Stub [STUB!]\n");
+   }
+
+   void ::OffsetWindow(Window window, int * x, int * y)
+   {
+      sflnprintf("class(EmscriptenInterface) ::OffsetWindow [STUB!]\n");
+   }
+
+   void ::UpdateRootWindow(Window window)
+   {
+      sflnprintf("class(EmscriptenInterface) ::UpdateRootWindow [STUB!]\n");
+   }
+
+   void ::SetRootWindowState(Window window, WindowState state, bool visible)
+   {
+      sflnprintf("class(EmscriptenInterface) ::SetRootWindowState [STUB!]\n");
+   }
+
+   void ::ActivateRootWindow(Window window)
+   {
+      sflnprintf("class(EmscriptenInterface) ::ActivateRootWindow [STUB!]\n");
+   }
+
+   void ::OrderRootWindow(Window window, bool topMost)
+   {
+      sflnprintf("class(EmscriptenInterface) ::OrderRootWindow [STUB!]\n");
+   }
+
+   void ::SetRootWindowColor(Window window)
+   {
+      sflnprintf("class(EmscriptenInterface) ::SetRootWindowColor [STUB!]\n");
+   }
+
+   void ::FlashRootWindow(Window window)
+   {
+      sflnprintf("class(EmscriptenInterface) ::FlashRootWindow [STUB!]\n");
+   }
+
+
+   // --- Mouse-based window movement ---
+
+   void ::StartMoving(Window window, int x, int y, bool fromKeyBoard)
+   {
+      sflnprintf("class(EmscriptenInterface) ::StartMoving [STUB!]\n");
+   }
+
+   void ::StopMoving(Window window)
+   {
+      sflnprintf("class(EmscriptenInterface) ::StopMoving [STUB!]\n");
+   }
+
+
+   // --- Mouse manipulation ---
+
+   void ::GetMousePosition(int *x, int *y)
+   {
+      sflnprintf("class(EmscriptenInterface) ::GetMousePosition [STUB!]\n");
+   }
+
+   void ::SetMousePosition(int x, int y)
+   {
+      sflnprintf("class(EmscriptenInterface) ::SetMousePosition [STUB!]\n");
+   }
+
+   void ::SetMouseRange(Window window, Box box)
+   {
+      sflnprintf("class(EmscriptenInterface) ::SetMouseRange [STUB!]\n");
+   }
+
+   void ::SetMouseCapture(Window window)
+   {
+      sflnprintf("class(EmscriptenInterface) ::SetMouseCapture [STUB!]\n");
+   }
+
+
+   // --- Mouse cursor ---
+
+   void ::SetMouseCursor(Window window, SystemCursor cursor)
+   {
+      sflnprintf("class(EmscriptenInterface) ::SetMouseCursor [STUB!]\n");
+   }
+
+
+   // --- Caret manipulation ---
+
+   void ::SetCaret(int caretX, int caretY, int size)
+   {
+      sflnprintf("class(EmscriptenInterface) ::SetCaret [STUB!]\n");
+   }
+
+
+   // --- Clipboard manipulation ---
+
+   void ::ClearClipboard()
+   {
+      sflnprintf("class(EmscriptenInterface) ::ClearClipboard [STUB!]\n");
+   }
+
+   bool ::AllocateClipboard(ClipBoard clipBoard, uint size)
+   {
+      sflnprintf("class(EmscriptenInterface) ::AllocateClipboard [STUB!]\n");
+      return false;
+   }
+
+   bool ::SaveClipboard(ClipBoard clipBoard)
+   {
+      sflnprintf("class(EmscriptenInterface) ::SaveClipboard [STUB!]\n");
+      return false;
+   }
+
+   bool ::LoadClipboard(ClipBoard clipBoard)
+   {
+      sflnprintf("class(EmscriptenInterface) ::LoadClipboard [STUB!]\n");
+      return false;
+   }
+
+   void ::UnloadClipboard(ClipBoard clipBoard)
+   {
+      sflnprintf("class(EmscriptenInterface) ::UnloadClipboard [STUB!]\n");
+   }
+
+
+   // --- State based input ---
+
+   bool ::AcquireInput(Window window, bool state)
+   {
+      sflnprintf("class(EmscriptenInterface) ::AcquireInput [STUB!]\n");
+      return false;
+   }
+
+   bool ::GetMouseState(MouseButtons * buttons, int * x, int * y)
+   {
+      sflnprintf("class(EmscriptenInterface) ::GetMouseState [STUB!]\n");
+      return false;
+   }
+
+   bool ::GetJoystickState(int device, Joystick joystick)
+   {
+      sflnprintf("class(EmscriptenInterface) ::GetJoystickState [STUB!]\n");
+      return false;
+   }
+
+   bool ::GetKeyState(Key key)
+   {
+      sflnprintf("class(EmscriptenInterface) ::GetKeyState [STUB!]\n");
+      return false;
+   }
+
+   bool ::SetIcon(Window window, BitmapResource icon)
+   {
+      sflnprintf("class(EmscriptenInterface) ::SetIcon [STUB!]\n");
+      return false;
+   }
+
+   void ::GetScreenArea(Window window, Box box)
+   {
+      sflnprintf("class(EmscriptenInterface) ::GetScreenArea [STUB!]\n");
+   }
+}
+
+#endif
index 67a2254..a20a7cf 100644 (file)
@@ -2,7 +2,7 @@ namespace gui::drivers;
 
 import "instance"
 
-#if (defined(__unix__) || defined(__APPLE__)) && !defined(__DOS__)
+#if (defined(__unix__) || defined(__APPLE__)) && !defined(__DOS__) && !defined(__EMSCRIPTEN__)
 
 #undef __BLOCKS__
 #define DBLCLICK_DELAY  0.3  // seconds
index aedad06..80d8fae 100644 (file)
@@ -5,7 +5,7 @@ import "instance"
 import "OpenGLDisplayDriver"
 #endif
 
-#if (defined(__unix__) || defined(__APPLE__)) && !defined(ECERE_MINIGLX)
+#if (defined(__unix__) || defined(__APPLE__)) && !defined(ECERE_MINIGLX) && !defined(__EMSCRIPTEN__)
 
 #undef __BLOCKS__
 default:
@@ -50,16 +50,24 @@ typedef int X11Bool;
 
 #include <X11/Xatom.h>
 #include <X11/Xlib.h>
+#if !defined(__EMSCRIPTEN__)
 #include <X11/Xresource.h>
+#endif
 #include <X11/Xutil.h>
 #include <X11/XKBlib.h>
 #include <X11/keysym.h>
 #include <X11/cursorfont.h>
 #include <fcntl.h>
 #if !defined(ECERE_NO3D) && !defined(ECERE_NOGL)
+#if defined(__EMSCRIPTEN__)
+#include <GL/glfw.h>
+#else
 #include <GL/glx.h>
 #endif
+#endif
+#if !defined(__EMSCRIPTEN__)
 #include <X11/extensions/Xrender.h>
+#endif
 #include <X11/extensions/XShm.h>
 
 #undef Bool
index 4c3c395..eab0746 100644 (file)
@@ -198,7 +198,7 @@ public class WindowsSkin_Window : Window
          // PrintLn(_class.name, " is at l = ", rcWindow.left, ", r = ", rcWindow.right);
 #else
          Box widths = { 0 };
-#if !defined(__ANDROID__)
+#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
          XGetBorderWidths(this, widths);
 #endif
          *w += widths.left + widths.right;
@@ -285,7 +285,7 @@ public class WindowsSkin_Window : Window
          *y += client00.y - rcWindow.top;
 #else
          Box widths = { 0 };
-#if !defined(__ANDROID__)
+#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
          XGetBorderWidths(this, widths);
 #endif
          *x += widths.left;
index 455b810..3603854 100644 (file)
@@ -38,6 +38,8 @@ typedef struct in_addr IN_ADDR;
 import "network"
 import "List"
 
+#if !defined(__EMSCRIPTEN__)
+
 // SERVER
 
 static enum DCOMPacketType
@@ -812,3 +814,5 @@ public:
       sendingOut = false;
    }
 }
+
+#endif // !defined(__EMSCRIPTEN__)
index b9366f2..23a6c8c 100644 (file)
@@ -1,8 +1,14 @@
 #if defined(BUILDING_ECERE_COM)
+#if !defined(__EMSCRIPTEN__)
 import "Semaphore"
 #else
 import "ecere"
 #endif
+#else
+import "ecere"
+#endif
+
+#if !defined(__EMSCRIPTEN__)
 
 public class Condition : struct
 {
@@ -56,3 +62,5 @@ public:
       mutex.Wait();
    }
 }
+
+#endif // !defined(__EMSCRIPTEN__)
index f97f45e..d9fd49a 100644 (file)
@@ -1199,7 +1199,7 @@ class EARArchiveDir : ArchiveDir
       return true;
    }
 };
-#endif
+#endif // !defined(ECERE_NOARCHIVE) && !defined(ECERE_VANILLA)
 
 // Directory Description for file listing
 class EARDir : struct
@@ -1690,7 +1690,7 @@ class EARFileSystem : FileSystem
       }
       return result;
    }
-#endif
+#endif // !defined(ECERE_NOARCHIVE) && !defined(ECERE_VANILLA)
    bool ::QuerySize(const char * archive, FileSize * size)
    {
       bool result = false;
index a6dde40..7ea5966 100644 (file)
@@ -2,6 +2,8 @@ namespace sys;
 
 import "System"
 
+#if !defined(__EMSCRIPTEN__)
+
 public class FileChange
 {
 public:
@@ -431,3 +433,5 @@ static class MonitorThread : Thread
       return 0;
    }
 }
+
+#endif // !defined(__EMSCRIPTEN__)
index f44efe9..4fcdb6a 100644 (file)
@@ -146,6 +146,7 @@ private:
    SettingsLocationType readType;
    SettingsLocationType writeType;
 
+#if !defined(__EMSCRIPTEN__)
    FileMonitor settingsMonitor
    {
       this, fileChange = { modified = true };
@@ -156,6 +157,7 @@ private:
          return true;
       }
    };
+#endif
    File f;
    bool locked;
 
@@ -380,7 +382,9 @@ public:
       SettingsLocationType type = readType;
       if(!f)
       {
+#if !defined(__EMSCRIPTEN__)
          settingsMonitor.StopMonitoring();
+#endif
 
          if(settingsFilePath)
             FileOpenTryRead(type);
@@ -475,7 +479,9 @@ public:
       {
          locked = false;
 
+#if !defined(__EMSCRIPTEN__)
          settingsMonitor.StopMonitoring();
+#endif
 
          if(settingsFilePath)
             // Don't auto delete settingsFilePath because only want to try another path if we were using a global path
@@ -544,7 +550,9 @@ public:
    {
       if(f)
       {
+#if !defined(__EMSCRIPTEN__)
          settingsMonitor.StopMonitoring();
+#endif
          f.Unlock(0,0,true);
          locked = false;
          delete f;
@@ -556,8 +564,10 @@ public:
       Close();
       if(settingsFilePath && OnAskReloadSettings != GlobalSettings::OnAskReloadSettings)
       {
+#if !defined(__EMSCRIPTEN__)
          settingsMonitor.fileName = settingsFilePath;
          settingsMonitor.StartMonitoring();
+#endif
       }
    }
 }
index ac048a3..38cb873 100644 (file)
@@ -27,6 +27,8 @@ namespace sys;
 
 import "instance"
 
+#if !defined(__EMSCRIPTEN__)
+
 // Moved this here from Thread.ec to make compiling ecereCOM in Debug easier
 public int64 GetCurrentThreadID()
 {
@@ -179,3 +181,5 @@ public:
 
    property int lockCount { get { return lockCount; } }
 };
+
+#endif // !defined(__EMSCRIPTEN__)
index 44c692c..8f4c98a 100644 (file)
@@ -24,6 +24,8 @@ namespace sys;
 
 import "System"
 
+#if !defined(__EMSCRIPTEN__)
+
 public class Semaphore : struct
 {
 #if defined(__WIN32__)
@@ -159,3 +161,5 @@ public:
       get { return maxCount; }
    };
 };
+
+#endif // !defined(__EMSCRIPTEN__)
index 1f168a0..1b7bcd8 100644 (file)
@@ -64,10 +64,12 @@ private:
 #if !defined(ECERE_BOOTSTRAP)
 import "units"
 import "Time"
+#if !defined(__EMSCRIPTEN__)
 import "Mutex"
 import "Semaphore"
 import "FileMonitor"
 import "Thread"
+#endif
 import "Archive"
 import "EARArchive"
 import "Date"
@@ -488,14 +490,18 @@ private struct System
    ErrorLevel errorLevel;
 
 #ifndef ECERE_BOOTSTRAP
+#if !defined(__EMSCRIPTEN__)
    Semaphore eventSemaphore;
+#endif
 
    //FileSystem fileSystems;
 
    // File Monitor
    OldList fileMonitors;
+#if !defined(__EMSCRIPTEN__)
    Mutex fileMonitorMutex;
    Thread fileMonitorThread;
+#endif
    bool systemTerminate;
 #endif
 };
index 2495455..33802ec 100644 (file)
@@ -25,6 +25,8 @@ import "instance"
 import "Semaphore"
 #endif
 
+#if !defined(__EMSCRIPTEN__)
+
 public enum ThreadPriority
 {
    normal = 0,
@@ -168,3 +170,5 @@ public:
 
    property bool created { get { return started; } };
 }
+
+#endif // !defined(__EMSCRIPTEN__)
index dfb7ae9..004b3b7 100644 (file)
@@ -24,7 +24,7 @@ static Map<const String, Map<const String, const String>> moduleMaps { };
 
 public dllexport void LoadTranslatedStrings(const String moduleName, const char * name)
 {
-#ifndef ECERE_NOFILE
+#if !defined(ECERE_NOFILE) && !defined(__EMSCRIPTEN__)
    File f;
    char fileName[MAX_LOCATION];