--- /dev/null
+namespace gfx::drivers;
+
+#ifdef BUILDING_ECERE_COM
+import "instance"
+import "Display"
+#else
+#ifdef ECERE_STATIC
+public import static "ecere"
+#else
+public import "ecere"
+#endif
+#endif
+
+import "SDLInterface"
+
+#if !defined(NO_SDL_DRIVERS) && !defined(NO_SDL1_DRIVER)
+
+#include <stdio.h>
+
+// source file line number printf (sflnprintf)
+#define sflnprintf(format,...) printf("%s:% 5d: " format, __FILE__, __LINE__, ##__VA_ARGS__)
+
+#define watch _watch
+#include <SDL.h>
+#undef watch
+
+class SDLDisplay : LFBDisplay
+{
+};
+
+class SDLDisplayDriver : DisplayDriver
+{
+ class_property(name) = "SDL1";
+
+
+ // Constructor / Destructor
+
+ bool ::CreateDisplaySystem(DisplaySystem displaySystem)
+ {
+ bool result = false;
+ sflnprintf("class(SDLDisplayDriver) ::CreateDisplaySystem [WIP!]\n");
+ displaySystem.flags.memBackBuffer = true;
+ result = true;
+ return result;
+ }
+
+ void ::DestroyDisplaySystem(DisplaySystem displaySystem)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::DestroyDisplaySystem [STUB!]\n");
+ }
+
+ bool ::CreateDisplay(Display display)
+ {
+ bool result = false;
+ SDLDisplay sdlDisplay = display.driverData = SDLDisplay { };
+ sflnprintf("class(SDLDisplayDriver) ::CreateDisplay [WIP!]\n");
+ if(sdlDisplay)
+ {
+ // To find out the format...
+ DisplaySize(display, 1, 1);
+ result = true;
+ }
+ return result;
+ }
+
+ void ::DestroyDisplay(Display display)
+ {
+ SDLDisplay sdlDisplay = display.driverData;
+ sflnprintf("class(SDLDisplayDriver) ::DestroyDisplay [STUB!]\n");
+
+ if(display)
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).DestroyDisplay(display);
+
+ // TODO: Implementation
+
+ delete sdlDisplay;
+ display.driverData = null;
+ }
+
+
+ // Display Position and Size
+
+ bool ::DisplaySize(Display display, int width, int height)
+ {
+ SDLDisplay sdlDisplay = display.driverData;
+ bool result = false;
+ sflnprintf("class(SDLDisplayDriver) ::DisplaySize [WIP!]\n");
+
+ // TODO: Implementation
+
+ /*
+ bool validFormat = true;
+ switch(backDesc.ddpfPixelFormat.dwRGBBitCount)
+ {
+ case 8: bitmap.pixelFormat = pixelFormat8; break;
+ case 15: bitmap.pixelFormat = pixelFormat555; break;
+ case 16:
+ if(backDesc.ddpfPixelFormat.dwGBitMask == 0x3E0)
+ bitmap.pixelFormat = pixelFormat555;
+ else
+ bitmap.pixelFormat = pixelFormat565;
+ break;
+ case 32:
+ bitmap.pixelFormat = pixelFormat888; break;
+ default:
+ validFormat = false;
+ break;
+ }
+ if(validFormat)
+ {
+ bitmap.picture = (byte *)backDesc.lpSurface;
+ bitmap.stride = backDesc.lPitch;
+ bitmap.stride >>= GetColorDepthShifts(bitmap.pixelFormat);
+ bitmap.size = bitmap.stride * bitmap.height;
+ }
+ */
+ display.displaySystem.pixelFormat = sdlDisplay.bitmap.pixelFormat;
+ result = true;
+
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).DisplaySize(display, width, height);
+
+ display.width = width;
+ display.height = height;
+
+ return result;
+ }
+
+ void ::DisplayPosition(Display display, int x, int y)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).DisplayPosition(display, x, y);
+ }
+
+
+ // Palettes
+
+ void ::SetPalette(Display display, ColorAlpha * palette, bool colorMatch)
+ {
+ SDLDisplay sdlDisplay = display.driverData;
+ sflnprintf("class(SDLDisplayDriver) ::SetPalette [WIP!]\n");
+ if(sdlDisplay.bitmap.pixelFormat == pixelFormat8)
+ {
+ // TODO: Implementation
+ }
+ else
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetPalette(display, palette, colorMatch);
+ }
+
+ void ::RestorePalette(Display display)
+ {
+ //SDLDisplay sdlDisplay = display.driverData;
+ sflnprintf("class(SDLDisplayDriver) ::RestorePalette [STUB!]\n");
+ }
+
+
+ // Display the back buffer content
+
+ void ::StartUpdate(Display display)
+ {
+ //SDLDisplay sdlDisplay = display.driverData;
+ sflnprintf("class(SDLDisplayDriver) ::StartUpdate [STUB!]\n");
+ }
+
+ void ::EndUpdate(Display display)
+ {
+ //SDLDisplay sdlDisplay = display.driverData;
+ sflnprintf("class(SDL2DisplayDriver) ::EndUpdate [STUB!]\n");
+ //--//SDL_RenderPresent();
+ }
+
+ void ::Scroll(Display display, Box scroll, int x, int y, Extent dirty)
+ {
+ }
+
+ void ::Update(Display display, Box updateBox)
+ {
+ //SDLDisplay sdlDisplay = display.driverData;
+ //--//Box * box = updateBox;
+ sflnprintf("class(SDLDisplayDriver) ::Update [STUB!]\n");
+ // SDL_RenderPresent();
+ }
+
+
+ // Allocate/free a bitmap
+
+ bool ::AllocateBitmap(DisplaySystem displaySystem, Bitmap bitmap, int width, int height, int stride, PixelFormat format, bool allocatePalette)
+ {
+ return ((subclass(DisplayDriver))class(LFBDisplayDriver)).AllocateBitmap(displaySystem, bitmap, width, height, stride, format, allocatePalette);
+ }
+
+ void ::FreeBitmap(DisplaySystem displaySystem, Bitmap bitmap)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).FreeBitmap(displaySystem, bitmap);
+ }
+
+
+ // Lock
+
+ bool ::LockSystem(DisplaySystem displaySystem)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::LockSystem [STUB!]\n");
+ return false;
+ }
+
+ void ::UnlockSystem(DisplaySystem displaySystem)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::UnlockSystem [STUB!]\n");
+ }
+
+ bool ::Lock(Display display)
+ {
+ //SDLDisplay sdlDisplay = display.driverData;
+ sflnprintf("class(SDLDisplayDriver) ::Lock [STUB!]\n");
+ return true;
+ }
+
+ void ::Unlock(Display display)
+ {
+ //SDLDisplay sdlDisplay = display.driverData;
+ sflnprintf("class(SDLDisplayDriver) ::Unlock [STUB!]\n");
+ }
+
+
+ // Get/release a surface
+
+ bool ::GetSurface(Display display, Surface surface, int x,int y, Box clip)
+ {
+ //SDLDisplay sdlDisplay = display.driverData;
+ LFBSurface lfbSurface;
+ bool result = false;
+ sflnprintf("class(SDLDisplayDriver) ::GetSurface [WIP!]\n");
+ {
+ if((surface.driverData = lfbSurface = LFBSurface { }))
+ {
+ surface.offset.x = x;
+ surface.offset.y = y;
+ //surface.unclippedBox = surface.box = clip;
+ // TODO: Implementation
+ result = ((subclass(DisplayDriver))class(LFBDisplayDriver)).GetSurface(display, surface, x, y, clip);
+ }
+ }
+ return result;
+ }
+
+ bool ::GetBitmapSurface(DisplaySystem displaySystem, Surface surface, Bitmap bitmap, int x, int y, Box clip)
+ {
+ return ((subclass(DisplayDriver))class(LFBDisplayDriver)).GetBitmapSurface(displaySystem, surface, bitmap, x, y, clip);
+ }
+
+ void ::ReleaseSurface(Display display, Surface surface)
+ {
+ //SDLDisplay sdlDisplay = display.driverData;
+ sflnprintf("class(SDL2DisplayDriver) ::ReleaseSurface [WIP!]\n");
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).ReleaseSurface(display, surface);
+ // TODO: Implementation
+ }
+
+
+ // Clip a surface
+
+ void ::Clip(Display display, Surface surface, Box clip)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).Clip(display, surface, clip);
+ }
+
+
+ // Grab from the screen
+
+ bool ::GrabScreen(Display display, Bitmap bitmap, int x, int y, unsigned int w, unsigned int h)
+ {
+ bool result = false;
+ //SDLDisplay sdlDisplay = display.driverData;
+ sflnprintf("class(SDL2DisplayDriver) ::GrabScreen [WIP!]\n");
+ // TODO: Implementation
+ result = ((subclass(DisplayDriver))class(LFBDisplayDriver)).GrabScreen(display, bitmap, x,y, w,h);
+ return result;
+ }
+
+
+ // Converts a bitmap format
+
+ bool ::ConvertBitmap(DisplaySystem displaySystem, Bitmap src, PixelFormat format, ColorAlpha * palette)
+ {
+ return ((subclass(DisplayDriver))class(LFBDisplayDriver)).ConvertBitmap(displaySystem, src, format, palette);
+ }
+
+
+ // Converts an LFB bitmap into an offscreen bitmap for this device
+
+ bool ::MakeDDBitmap(DisplaySystem displaySystem, Bitmap bitmap, bool mipMaps)
+ {
+ return ((subclass(DisplayDriver))class(LFBDisplayDriver)).MakeDDBitmap(displaySystem, bitmap, mipMaps);
+ }
+
+
+ // Font loading
+
+ Font ::LoadFont(DisplaySystem displaySystem, const char * faceName, float size, FontFlags flags)
+ {
+ Font font = (Font)((subclass(DisplayDriver))class(LFBDisplayDriver)).LoadFont(displaySystem, faceName, size, flags);
+ return font;
+ }
+
+ void ::UnloadFont(DisplaySystem displaySystem, Font font)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).UnloadFont(displaySystem, font);
+ }
+
+
+ // 2D Drawing
+
+ void ::SetForeground(Display display, Surface surface, ColorAlpha color)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetForeground(display, surface, color);
+ }
+
+ void ::SetBackground(Display display, Surface surface, ColorAlpha color)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetBackground(display, surface, color);
+ }
+
+ void ::SetBlitTint(Display display, Surface surface, ColorAlpha tint)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::SetBlitTint [STUB!]\n");
+ }
+
+ void ::LineStipple(Display display, Surface surface, uint stipple)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).LineStipple(display, surface, stipple);
+ }
+
+ ColorAlpha ::GetPixel(Display display, Surface surface, int x, int y)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::GetPixel [STUB!]\n");
+ return 0;
+ }
+
+ void ::PutPixel(Display display, Surface surface, int x, int y)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).PutPixel(display, surface, x,y);
+ }
+
+ void ::DrawLine(Display display, Surface surface, int x1, int y1, int x2, int y2)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).DrawLine(display, surface, x1,y1,x2,y2);
+ }
+
+ void ::Rectangle(Display display, Surface surface, int x1, int y1, int x2, int y2)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).Rectangle(display, surface, x1,y1,x2,y2);
+ }
+
+ void ::Area(Display display, Surface surface,int x1, int y1, int x2, int y2)
+ {
+ /* if(x1>x2) { int tmp = x2; x2 = x1; x1 = tmp; }
+
+ if(x1<surface.box.left) x1=surface.box.left;
+ if(x2>surface.box.right) x2=surface.box.right;
+ if(y1<surface.box.top) y1=surface.box.top;
+ if(y2>surface.box.bottom) y2=surface.box.bottom;
+*/
+ x1 += surface.offset.x;
+ x2 += surface.offset.x;
+ y1 += surface.offset.y;
+ y2 += surface.offset.y;
+
+ {
+ //--//SDL_Rect rect = { (short)x1, (short)y1, (short)(x2-x1+1), (short)(y2-y1+1) };
+ //--//SDL_SetRenderDrawColor(surface.background.color.r, surface.background.color.g, surface.background.color.b, surface.background.a);
+ //--//SDL_RenderFill(&rect);
+ //SDL_FillRect()
+ // ((subclass(DisplayDriver))class(LFBDisplayDriver)).Area(display, surface, x1,y1,x2,y2);
+ }
+ }
+
+ void ::Clear(Display display, Surface surface, ClearType type)
+ {
+ sflnprintf("class(SDL2DisplayDriver) ::Clear [WIP!]\n");
+ //--//SDL_Rect rect = { (short)surface.box.left, (short)surface.box.top, (short)(surface.box.right-surface.box.left+1), (short)(surface.box.bottom-surface.box.top+1) };
+ //--//SDL_SetRenderDrawColor(surface.background.color.r, surface.background.color.g, surface.background.color.b, surface.background.a);
+ //--//SDL_RenderFill(&rect);
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).Clear(display, surface, type);
+ }
+
+ void ::Blit(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).Blit(display, surface, src, dx, dy, sx, sy, w, h);
+ }
+
+ void ::Stretch(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).Stretch(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
+ }
+
+ void ::Filter(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).Filter(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
+ }
+
+ void ::BlitDI(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h)
+ {
+ // Using Blit()
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).Blit(display, surface, src, dx, dy, sx, sy, w, h);
+ }
+
+ void ::StretchDI(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
+ {
+ // Using Stretch()
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).Stretch(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
+ }
+
+ void ::FilterDI(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
+ {
+ // Using Filter()
+ //Filter(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).Filter(display, surface, src, dx, dy, sx, sy, w, h, sw, sh);
+ }
+
+ void ::TextFont(Display display, Surface surface, Font font)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).TextFont(display, surface, font);
+ // why this?
+ SetForeground(display, surface, surface.foreground);
+ }
+
+ void ::TextOpacity(Display display, Surface surface, bool opaque)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).TextOpacity(display, surface, opaque);
+ }
+
+ void ::WriteText(Display display, Surface surface, int x, int y, const char * text, int len)
+ {
+ if(surface.textOpacity)
+ {
+ int w, h;
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).FontExtent(display.displaySystem, surface.font, text, len, &w, &h);
+ Area(display, surface, x, y, x+w-1, y+h-1);
+ }
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).WriteText(display, surface, x,y, text, len);
+ }
+
+ void ::TextExtent(Display display, Surface surface, const char * text, int len, int * width, int * height)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).TextExtent(display, surface, text, len, width, height);
+ }
+
+ void ::FontExtent(DisplaySystem displaySystem, Font font, const char * text, int len, int * width, int * height)
+ {
+ ((subclass(DisplayDriver))class(LFBDisplayDriver)).FontExtent(displaySystem, font, text, len, width, height);
+ }
+
+ void ::DrawingChar(Display display, Surface surface, char character)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::DrawingChar [STUB!]\n");
+ }
+
+ void ::NextPage(Display display)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::NextPage [STUB!]\n");
+ }
+
+ // 3D Graphics
+
+#if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D)
+ void ::SetRenderState(Display display, RenderState state, uint value)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::SetRenderState [STUB!]\n");
+ }
+
+ void ::SetLight(Display display, int id, Light light)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::SetLight [STUB!]\n");
+ }
+
+ void ::SetCamera(Display display, Surface surface, Camera camera)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::SetCamera [STUB!]\n");
+ }
+
+ bool ::AllocateMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags, int nVertices)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::AllocateMesh [STUB!]\n");
+ return false;
+ }
+
+ void ::FreeMesh(DisplaySystem displaySystem, Mesh mesh)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::FreeMesh [STUB!]\n");
+ }
+
+ bool ::LockMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::LockMesh [STUB!]\n");
+ return false;
+ }
+
+ void ::UnlockMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::UnlockMesh [STUB!]\n");
+ }
+
+ void * ::AllocateIndices(DisplaySystem displaySystem, int nIndices, bool indices32bit)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::AllocateIndices [STUB!]\n");
+ return null;
+ }
+
+ void ::FreeIndices(DisplaySystem displaySystem, void * indices)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::FreeIndices [STUB!]\n");
+ }
+
+ uint16 * ::LockIndices(DisplaySystem displaySystem, void * indices)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::LockIndices [STUB!]\n");
+ return null;
+ }
+
+ void ::UnlockIndices(DisplaySystem displaySystem, void * indices, bool indices32bit, int nIndices)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::UnlockIndices [STUB!]\n");
+ }
+
+ void ::SelectMesh(Display display, Mesh mesh)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::SelectMesh [STUB!]\n");
+ }
+
+ void ::ApplyMaterial(Display display, Material material, Mesh mesh)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::ApplyMaterial [STUB!]\n");
+ }
+
+ void ::DrawPrimitives(Display display, PrimitiveSingle * primitive, Mesh mesh)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::DrawPrimitives [STUB!]\n");
+ }
+
+ void ::PushMatrix(Display display)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::PushMatrix [STUB!]\n");
+ }
+
+ void ::PopMatrix(Display display, bool setMatrix)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::PopMatrix [STUB!]\n");
+ }
+
+ void ::SetTransform(Display display, Matrix transMatrix, bool viewSpace, bool useCamera)
+ {
+ sflnprintf("class(SDLDisplayDriver) ::SetTransform [STUB!]\n");
+ }
+#endif
+
+}
+
+#endif // !defined(NO_SDL_DRIVERS) && !defined(NO_SDL1_DRIVER)
--- /dev/null
+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
+
+import "SDLDisplayDriver"
+
+#if !defined(NO_SDL_DRIVERS) && !defined(NO_SDL1_DRIVER)
+
+#include <stdio.h>
+
+// source file line number printf (sflnprintf)
+#define sflnprintf(format,...) printf("%s:% 5d: " format, __FILE__, __LINE__, ##__VA_ARGS__)
+
+#define watch _watch
+#include <SDL.h>
+#undef watch
+
+static bool fullScreenMode;
+
+static define guiApp = (GuiApplication)__thisModule.application;
+
+class SDLInterface : Interface
+{
+ class_property(name) = "SDL1";
+
+ /****************************************************************************
+ /// PRIVATE UTILITY FUNCTIONS /////////////
+ ****************************************************************************/
+ void ::RepositionDesktop(bool updateChildren)
+ {
+ // TODO: Implement this
+ int x = 0, y = 0, w = 0, h = 0;
+ guiApp.SetDesktopPosition(x, y, w, h, updateChildren);
+ }
+
+ bool ::ProcessKeyMessage(Key key, unichar ch)
+ {
+ bool result = true;
+ //Key code = key;
+
+ // TODO: Implement this
+
+ // MouseWheel
+ // result = window.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit, code, 0);
+
+ // KeyUp
+ // result = window.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, code, ch);
+
+ // KeyDown
+ // result = window.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, code, ch);
+
+ // KeyHit
+ // result = window.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit, code,ch);
+ return result;
+ }
+
+
+ // TODO: Implement these
+
+ // Activated (Special code to write to handle modal windows...)
+ // window.ExternalActivate(true, true, window, null);
+
+ // Application Activated
+ // guiApp.SetAppFocus
+
+
+ // Window Redraw
+ // window.UpdateDirty(box);
+
+
+ // Resolution changed
+ // guiApp.desktop.DisplayModeChanged()
+
+ // IME Code
+
+ // Keyboard and Mouse Messages
+
+
+ // Timer 18.2 times per second: Call guiApp.SignalEvent();
+
+ // Mouse Cursors
+
+ /****************************************************************************
+ /// DRIVER IMPLEMENTATION /////////////
+ ****************************************************************************/
+
+
+ // --- User Interface System ---
+
+ bool ::Initialize()
+ {
+ SDL_Init(SDL_INIT_EVENTTHREAD);
+ SDL_VideoInit(null, 0);
+ return true;
+ }
+
+ void ::Terminate()
+ {
+ SDL_Quit();
+ }
+
+ bool ::ProcessInput(bool processAll)
+ {
+ // TODO: Implement this
+ SDL_Event event;
+ while(SDL_PollEvent(&event))
+ {
+ //--//Window window = SDL_GetWindowData(event.window.windowID);
+ switch (event.type)
+ {
+ case SDL_KEYUP:
+ // event.key.keysym.sym
+ // SDLK_ESCAPE:
+ break;
+//--//
+/*
+ case SDL_WINDOWEVENT:
+ {
+ switch(event.window.event)
+ {
+ case SDL_WINDOWEVENT_SHOWN:
+ break;
+ case SDL_WINDOWEVENT_HIDDEN:
+ break;
+ case SDL_WINDOWEVENT_MOVED:
+ {
+ int x,y,w,h;
+ //--//SDL_GetWindowSize((SDL_WindowID)window.systemHandle, &w, &h);
+ //--//SDL_GetWindowPosition((SDL_WindowID)window.systemHandle, &x, &y);
+ window.ExternalPosition(x, y, w, h);
+ break;
+ }
+ case SDL_WINDOWEVENT_RESIZED:
+ {
+ int x,y,w,h;
+ //--//SDL_GetWindowSize((SDL_WindowID)window.systemHandle, &w, &h);
+ //--//SDL_GetWindowPosition((SDL_WindowID)window.systemHandle, &x, &y);
+ window.ExternalPosition(x, y, w, h);
+ break;
+ }
+ case SDL_WINDOWEVENT_MINIMIZED:
+ break;
+ case SDL_WINDOWEVENT_MAXIMIZED:
+ break;
+ case SDL_WINDOWEVENT_RESTORED:
+ break;
+ case SDL_WINDOWEVENT_ENTER:
+ break;
+ case SDL_WINDOWEVENT_LEAVE:
+ break;
+ case SDL_WINDOWEVENT_CLOSE:
+ {
+ window.Destroy(0);
+ break;
+ }
+ case SDL_WINDOWEVENT_EXPOSED:
+ {
+ /-*SDL_Rect rect = { 0,0,800,600};
+ SDL_SetRenderDrawColor(0,120,200,255);
+ SDL_RenderFill(&rect);
+ SDL_RenderPresent(); *-/
+ window.Update(null);
+ break;
+ }
+ }
+ break;
+ }
+*/ //--//
+ }
+ }
+ return false;
+ }
+
+ void ::Wait()
+ {
+ sflnprintf("class(SDLInterface) ::Wait [WIP!]\n");
+ // TODO: Implement this, wait on a message as well as guiApp.semaphore
+ SDL_WaitEvent(null);
+ guiApp.WaitEvent();
+ //SDL_WaitEventTimeout(null, (int)(1000 / 18.2));
+ //SDL_WaitEventTimeout
+ }
+
+ void ::Lock(Window window)
+ {
+ sflnprintf("class(SDLInterface) ::Lock [STUB!]\n");
+ }
+
+ void ::Unlock(Window window)
+ {
+ sflnprintf("class(SDLInterface) ::Unlock [STUB!]\n");
+ }
+
+ void ::SetTimerResolution(uint hertz)
+ {
+ sflnprintf("class(SDLInterface) ::SetTimerResolution [STUB!] Implement high resolution timer here\n");
+ }
+
+ const char ** ::GraphicsDrivers(int * numDrivers)
+ {
+ static const char *graphicsDrivers[] = { "SDL1" };
+ *numDrivers = sizeof(graphicsDrivers) / sizeof(char *);
+ return (const char **)graphicsDrivers;
+ }
+
+ void ::EnsureFullScreen(bool * fullScreen)
+ {
+ sflnprintf("class(SDLInterface) ::EnsureFullScreen [STUB!]\n");
+ }
+
+ void ::GetCurrentMode(bool * fullScreen, Resolution * resolution, PixelFormat * colorDepth, int * refreshRate)
+ {
+ int width = 0, height = 0, bpp = 0, freq = 0;
+ sflnprintf("class(SDLInterface) ::GetCurrentMode [WIP!]\n");
+ *fullScreen = fullScreenMode;
+ if(fullScreenMode)
+ {
+ Resolution c;
+ for(c = 0; c<Resolution::enumSize; c++)
+ if(GetResolutionWidth(c) == width && GetResolutionHeight(c) == height)
+ {
+ *resolution = c;
+ break;
+ }
+ switch(bpp)
+ {
+ case 8: *colorDepth = pixelFormat8; break;
+ case 16: *colorDepth = pixelFormat555; break;
+ default: *colorDepth = pixelFormat888; break;
+ }
+ *refreshRate = freq;
+ }
+ }
+
+ bool ::ScreenMode(bool fullScreen, Resolution resolution, PixelFormat colorDepth, int refreshRate, bool * textMode)
+ {
+ bool result = true;
+ sflnprintf("class(SDLInterface) ::ScreenMode [WIP!]\n");
+
+ fullScreenMode = fullScreen;
+ // TODO: Set resolution
+ return result;
+ }
+
+
+ // --- Window Creation ---
+
+ void * ::CreateRootWindow(Window window)
+ {
+ void * windowHandle = null;//--//SDL_WindowID windowHandle;
+
+ //windowHandle = SDL_CreateWindow(window.text, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_RESIZABLE|SDL_WINDOW_SHOWN); //SDL_WINDOW_FULLSCREEN
+
+ //--//windowHandle = SDL_CreateWindow(window.text, -3000, -3000, 1,1,
+ //--// SDL_WINDOW_BORDERLESS | SDL_WINDOW_SHOWN /*| (((BorderBits)window.borderStyle).sizable ? SDL_WINDOW_RESIZABLE : 0)*/);
+
+ //--//SDL_CreateRenderer(windowHandle, -1, SDL_RENDERER_PRESENTFLIP2|SDL_RENDERER_PRESENTVSYNC|SDL_RENDERER_ACCELERATED);
+ //--//SDL_SelectRenderer(windowHandle);
+ //--//SDL_SetWindowData(windowHandle, window);
+
+ return (void *)windowHandle;
+ }
+
+ void ::DestroyRootWindow(Window window)
+ {
+ sflnprintf("class(SDLInterface) ::DestroyRootWindow [STUB!]\n");
+ //--//SDL_DestroyWindow((SDL_WindowID)window.systemHandle);
+ }
+
+
+ // --- Window manipulation ---
+
+ void ::SetRootWindowCaption(Window window, const char * name)
+ {
+ sflnprintf("class(SDLInterface) ::SetRootWindowCaption [STUB!]\n");
+ }
+
+ void ::PositionRootWindow(Window window, int x, int y, int w, int h, bool move, bool resize)
+ {
+ sflnprintf("class(SDLInterface) ::PositionRootWindow [WIP!]\n");
+ //--//if(move) SDL_SetWindowPosition((SDL_WindowID)window.systemHandle, x, y);
+ //--//if(resize) SDL_SetWindowSize((SDL_WindowID)window.systemHandle, w, h);
+ }
+
+ void ::OffsetWindow(Window window, int * x, int * y)
+ {
+ sflnprintf("class(SDLInterface) ::OffsetWindow [WIP!]\n");
+ }
+
+ void ::UpdateRootWindow(Window window)
+ {
+ sflnprintf("class(SDLInterface) ::UpdateRootWindow [STUB!]\n");
+ }
+
+ void ::SetRootWindowState(Window window, WindowState state, bool visible)
+ {
+ sflnprintf("class(SDLInterface) ::SetRootWindowState [STUB!]\n");
+ if(visible)
+ {
+ //--//SDL_ShowWindow((SDL_WindowID)window.systemHandle);
+ }
+ else
+ {
+ //--//SDL_HideWindow((SDL_WindowID)window.systemHandle);
+ }
+ }
+
+ void ::ActivateRootWindow(Window window)
+ {
+ sflnprintf("class(SDLInterface) ::ActivateRootWindow [STUB!]\n");
+ }
+
+ void ::OrderRootWindow(Window window, bool topMost)
+ {
+ sflnprintf("class(SDLInterface) ::OrderRootWindow [STUB!]\n");
+ }
+
+ void ::SetRootWindowColor(Window window)
+ {
+ sflnprintf("class(SDLInterface) ::SetRootWindowColor [STUB!]\n");
+ }
+
+ void ::FlashRootWindow(Window window)
+ {
+ sflnprintf("class(SDLInterface) ::FlashRootWindow [STUB!]\n");
+ }
+
+
+ // --- Mouse-based window movement ---
+
+ void ::StartMoving(Window window, int x, int y, bool fromKeyBoard)
+ {
+ sflnprintf("class(SDLInterface) ::StartMoving [STUB!]\n");
+ }
+
+ void ::StopMoving(Window window)
+ {
+ sflnprintf("class(SDLInterface) ::StopMoving [STUB!]\n");
+ }
+
+
+ // --- Mouse manipulation ---
+
+ void ::GetMousePosition(int *x, int *y)
+ {
+ sflnprintf("class(SDLInterface) ::GetMousePosition [STUB!]\n");
+ }
+
+ void ::SetMousePosition(int x, int y)
+ {
+ sflnprintf("class(SDLInterface) ::SetMousePosition [STUB!]\n");
+ }
+
+ void ::SetMouseRange(Window window, Box box)
+ {
+ sflnprintf("class(SDLInterface) ::SetMouseRange [STUB!]\n");
+ }
+
+ void ::SetMouseCapture(Window window)
+ {
+ sflnprintf("class(SDLInterface) ::SetMouseCapture [STUB!]\n");
+ }
+
+
+ // --- Mouse cursor ---
+
+ void ::SetMouseCursor(Window window, SystemCursor cursor)
+ {
+ sflnprintf("class(SDLInterface) ::SetMouseCursor [STUB!]\n");
+ // (cursor == (SystemCursor)-1) ? null : systemCursors[cursor]);
+ }
+
+
+ // --- Caret manipulation ---
+
+ void ::SetCaret(int caretX, int caretY, int size)
+ {
+ sflnprintf("class(SDLInterface) ::SetCaret [STUB!]\n");
+ }
+
+
+ // --- Clipboard manipulation ---
+
+ void ::ClearClipboard()
+ {
+ sflnprintf("class(SDLInterface) ::ClearClipboard [STUB!]\n");
+ }
+
+ bool ::AllocateClipboard(ClipBoard clipBoard, uint size)
+ {
+ bool result = false;
+ sflnprintf("class(SDLInterface) ::AllocateClipboard [WIP!]\n");
+ clipBoard.text = new byte[size];
+ result = true;
+ return result;
+ }
+
+ bool ::SaveClipboard(ClipBoard clipBoard)
+ {
+ bool result = false;
+ sflnprintf("class(SDLInterface) ::SaveClipboard [WIP!]\n");
+ if(clipBoard.text)
+ {
+
+ }
+ return result;
+ }
+
+ bool ::LoadClipboard(ClipBoard clipBoard)
+ {
+ bool result = false;
+ sflnprintf("class(SDLInterface) ::LoadClipboard [STUB!]\n");
+ return result;
+ }
+
+ void ::UnloadClipboard(ClipBoard clipBoard)
+ {
+ sflnprintf("class(SDLInterface) ::UnloadClipboard [WIP!]\n");
+ delete clipBoard.text;
+ }
+
+
+ // --- State based input ---
+
+ bool ::AcquireInput(Window window, bool state)
+ {
+ sflnprintf("class(SDLInterface) ::AcquireInput [STUB!]\n");
+ return false;
+ }
+
+ bool ::GetMouseState(MouseButtons * buttons, int * x, int * y)
+ {
+ bool result = false;
+ sflnprintf("class(SDLInterface) ::GetMouseState [STUB!]\n");
+ return result;
+ }
+
+ bool ::GetJoystickState(int device, Joystick joystick)
+ {
+ bool result = false;
+ sflnprintf("class(SDLInterface) ::GetJoystickState [STUB!]\n");
+ return result;
+ }
+
+ bool ::GetKeyState(Key key)
+ {
+ bool keyState = false;
+ sflnprintf("class(SDLInterface) ::GetKeyState [STUB!]\n");
+ return keyState;
+ }
+
+ bool ::SetIcon(Window window, BitmapResource icon)
+ {
+ sflnprintf("class(SDLInterface) ::SetIcon [WIP!]\n");
+ if(icon)
+ {
+ Bitmap bitmap { };
+ if(bitmap.Load(icon.fileName, null, null))
+ {
+ Bitmap and { };
+ //int y, x;
+ PixelFormat format = window.display.pixelFormat;
+ //int bits = 8<<GetColorDepthShifts(format);
+ int bits;
+ bool blend;
+
+ bits = GetDepthBits(format);
+
+ bitmap.Convert(null, pixelFormat888, null);
+ and.Allocate(null, (bitmap.width+7/8), bitmap.height, 0, pixelFormat8, false);
+
+ blend = bits == 32 || bitmap.pixelFormat != pixelFormat888;
+
+ {
+ //byte * picture = and.picture;
+ int c = 0;
+ int b = 0;
+ uint size = bitmap.height * bitmap.width;
+ while(c < size)
+ {
+ int m = 0;
+ byte mask = 0;
+ while(m < 8 && c < size)
+ {
+ mask <<= 1;
+ mask |= blend ? (!((ColorAlpha *)bitmap.picture)[c].a) : (((ColorAlpha *)bitmap.picture)[c].a <= 192);
+ c++;
+ m++;
+ }
+ and.picture[b++] = mask;
+ }
+ c = 0;
+ while(c < size)
+ {
+ ColorAlpha color = ((ColorAlpha *)bitmap.picture)[c];
+ if(blend ? (!color.a) : (color.a <= 192))
+ {
+ color.color = { 0, 0, 0 };
+ ((ColorAlpha *)bitmap.picture)[c] = color;
+ }
+ c++;
+ }
+ }
+ if(bits == 15) { bits = 16; format = pixelFormat565; };
+ bitmap.Convert(null, format, null);
+
+ // icon = CreateIcon(hInstance, bitmap.width, bitmap.height, 1, (byte)bits, and.picture, bitmap.picture);
+ delete and;
+ }
+ delete bitmap;
+ }
+ return true;
+ }
+
+ void ::GetScreenArea(Window window, Box box)
+ {
+ sflnprintf("class(SDLInterface) ::GetScreenArea [STUB!]\n");
+ box = { 0, 0, 1820, 1200 };
+ }
+}
+
+#endif // !defined(NO_SDL_DRIVERS) && !defined(NO_SDL1_DRIVER)