From 15f297eb7ecbf39f83691d809122330dcc46c68f Mon Sep 17 00:00:00 2001 From: Jean-Francois Bilodeau Date: Mon, 13 Feb 2012 16:50:24 +0700 Subject: [PATCH] ecere:gui/gfx:drivers/cocoa: Partial native Cocoa drivers implementation for Mac OS X --- ear/cmd/ear.ec | 2 +- ecere/Makefile | 117 +- ecere/Makefile.vanilla | 88 +- ecere/ecere.epj | 46 + ecere/src/com/String.ec | 1 + ecere/src/com/instance.ec | 2 + ecere/src/gfx/drivers/CocoaOpenGLDisplayDriver.ec | 1790 +++++++++++++++++++++ ecere/src/gfx/drivers/LFBDisplayDriver.ec | 1 + ecere/src/gfx/drivers/NCursesDisplayDriver.ec | 2 + ecere/src/gfx/drivers/OpenGLDisplayDriver.ec | 39 +- ecere/src/gui/GuiApplication.ec | 18 +- ecere/src/gui/Key.ec | 4 +- ecere/src/gui/drivers/NCursesInterface.ec | 1 + ecere/src/gui/drivers/XInterface.ec | 1 + ecere/src/gui/drivers/cocoa/CocoaDispatch.ec | 218 +++ ecere/src/gui/drivers/cocoa/CocoaEcereBridge.h | 85 + ecere/src/gui/drivers/cocoa/CocoaEcereBridge.m | 154 ++ ecere/src/gui/drivers/cocoa/CocoaInterface.ec | 291 ++++ ecere/src/gui/drivers/cocoa/EcereView.h | 33 + ecere/src/gui/drivers/cocoa/EcereView.m | 203 +++ ecere/src/sys/File.c | 1 + ecere/src/sys/File.ec | 1 + ecere/src/sys/System.ec | 1 + ecere/src/sys/Time.ec | 2 + ide/src/project/ProjectNode.ec | 6 +- 25 files changed, 3034 insertions(+), 73 deletions(-) create mode 100644 ecere/src/gfx/drivers/CocoaOpenGLDisplayDriver.ec create mode 100644 ecere/src/gui/drivers/cocoa/CocoaDispatch.ec create mode 100644 ecere/src/gui/drivers/cocoa/CocoaEcereBridge.h create mode 100644 ecere/src/gui/drivers/cocoa/CocoaEcereBridge.m create mode 100644 ecere/src/gui/drivers/cocoa/CocoaInterface.ec create mode 100644 ecere/src/gui/drivers/cocoa/EcereView.h create mode 100644 ecere/src/gui/drivers/cocoa/EcereView.m diff --git a/ear/cmd/ear.ec b/ear/cmd/ear.ec index e4dec9a..e39f85c 100644 --- a/ear/cmd/ear.ec +++ b/ear/cmd/ear.ec @@ -2,7 +2,7 @@ #define __unix__ #endif -#if defined(__unix__) +#if defined(__unix__) || defined(__APPLE__) #define uint _uint #include #undef uint diff --git a/ecere/Makefile b/ecere/Makefile index fb4f4e0..c72173d 100644 --- a/ecere/Makefile +++ b/ecere/Makefile @@ -93,8 +93,9 @@ OBJECTS2 = \ $(OBJ)lfbConvert.o \ $(OBJ)LFBDisplayDriver.o \ $(if $(or $(LINUX),$(OSX)),$(OBJ)NCursesDisplayDriver.o,) \ - $(OBJ)OpenGLDisplayDriver.o \ + $(if $(OSX),,$(OBJ)OpenGLDisplayDriver.o) \ $(if $(WINDOWS),$(OBJ)Win32BitmapPrinterDisplayDriver.o,) \ + $(if $(OSX),$(OBJ)CocoaOpenGLDisplayDriver.o,) \ $(if $(WINDOWS),$(OBJ)Win32ConsoleDisplayDriver.o,) \ $(if $(WINDOWS),$(OBJ)Win32PrinterDisplayDriver.o,) \ $(if $(LINUX),$(OBJ)XDisplayDriver.o,) \ @@ -108,11 +109,11 @@ OBJECTS2 = \ $(OBJ)Surface.o \ $(OBJ)Button.o \ $(OBJ)CalendarControl.o \ - $(OBJ)DataBox.o \ + $(OBJ)DataBox.o +OBJECTS3 = \ $(OBJ)DropBox.o \ $(OBJ)EditBox.o \ - $(OBJ)Label.o -OBJECTS3 = \ + $(OBJ)Label.o \ $(OBJ)ListBox.o \ $(OBJ)Menu.o \ $(OBJ)Picture.o \ @@ -132,6 +133,10 @@ OBJECTS3 = \ $(OBJ)MessageBox.o \ $(OBJ)ReplaceDialog.o \ $(OBJ)WindowList.o \ + $(if $(OSX),$(OBJ)CocoaDispatch.o,) \ + $(if $(OSX),$(OBJ)CocoaEcereBridge.o,) \ + $(if $(OSX),$(OBJ)CocoaInterface.o,) \ + $(if $(OSX),$(OBJ)EcereView.o,) \ $(if $(or $(LINUX),$(OSX)),$(OBJ)NCursesInterface.o,) \ $(if $(WINDOWS),$(OBJ)Win32Interface.o,) \ $(if $(WINDOWS),$(OBJ)Win32ConsoleInterface.o,) \ @@ -147,7 +152,8 @@ OBJECTS3 = \ $(OBJ)Interface.o \ $(OBJ)Key.o \ $(OBJ)Skin.o \ - $(OBJ)Timer.o \ + $(OBJ)Timer.o +OBJECTS4 = \ $(OBJ)typeEdit.o \ $(OBJ)Window.o \ $(OBJ)dcom.o \ @@ -157,8 +163,7 @@ OBJECTS3 = \ $(OBJ)Service.o \ $(OBJ)Socket.o \ $(OBJ)Array.o \ - $(OBJ)AVLTree.o -OBJECTS4 = \ + $(OBJ)AVLTree.o \ $(OBJ)BuiltInContainer.o \ $(OBJ)Container.o \ $(OBJ)CustomAVLTree.o \ @@ -222,8 +227,9 @@ COBJECTS1 = \ $(OBJ)LFBDisplayDriver.c \ $(if $(or $(LINUX),$(OSX)),$(OBJ)NCursesDisplayDriver.c,) COBJECTS2 = \ - $(OBJ)OpenGLDisplayDriver.c \ + $(if $(OSX),,$(OBJ)OpenGLDisplayDriver.c) \ $(if $(WINDOWS),$(OBJ)Win32BitmapPrinterDisplayDriver.c,) \ + $(if $(OSX),$(OBJ)CocoaOpenGLDisplayDriver.c,) \ $(if $(WINDOWS),$(OBJ)Win32ConsoleDisplayDriver.c,) \ $(if $(WINDOWS),$(OBJ)Win32PrinterDisplayDriver.c,) \ $(if $(LINUX),$(OBJ)XDisplayDriver.c,) \ @@ -260,9 +266,11 @@ COBJECTS2 = \ $(OBJ)MessageBox.c \ $(OBJ)ReplaceDialog.c \ $(OBJ)WindowList.c \ - $(if $(or $(LINUX),$(OSX)),$(OBJ)NCursesInterface.c,) \ - $(if $(WINDOWS),$(OBJ)Win32Interface.c,) + $(if $(OSX),$(OBJ)CocoaDispatch.c,) COBJECTS3 = \ + $(if $(OSX),$(OBJ)CocoaInterface.c,) \ + $(if $(or $(LINUX),$(OSX)),$(OBJ)NCursesInterface.c,) \ + $(if $(WINDOWS),$(OBJ)Win32Interface.c,) \ $(if $(WINDOWS),$(OBJ)Win32ConsoleInterface.c,) \ $(if $(or $(LINUX),$(OSX)),$(OBJ)XInterface.c,) \ $(OBJ)TVisionSkin.c \ @@ -300,7 +308,7 @@ COBJECTS3 = \ $(OBJ)String.c \ $(OBJ)OldList.c -SYMBOLS = $(SYMBOLS1) $(SYMBOLS2) $(SYMBOLS3) +SYMBOLS = $(SYMBOLS1) $(SYMBOLS2) $(SYMBOLS3) $(SYMBOLS4) SYMBOLS1 = \ $(OBJ)Archive.sym \ $(OBJ)BufferedFile.sym \ @@ -348,8 +356,9 @@ SYMBOLS1 = \ $(OBJ)LFBDisplayDriver.sym SYMBOLS2 = \ $(if $(or $(LINUX),$(OSX)),$(OBJ)NCursesDisplayDriver.sym,) \ - $(OBJ)OpenGLDisplayDriver.sym \ + $(if $(OSX),,$(OBJ)OpenGLDisplayDriver.sym) \ $(if $(WINDOWS),$(OBJ)Win32BitmapPrinterDisplayDriver.sym,) \ + $(if $(OSX),$(OBJ)CocoaOpenGLDisplayDriver.sym,) \ $(if $(WINDOWS),$(OBJ)Win32ConsoleDisplayDriver.sym,) \ $(if $(WINDOWS),$(OBJ)Win32PrinterDisplayDriver.sym,) \ $(if $(LINUX),$(OBJ)XDisplayDriver.sym,) \ @@ -382,11 +391,13 @@ SYMBOLS2 = \ $(OBJ)ColorPicker.sym \ $(OBJ)FileDialog.sym \ $(OBJ)FindDialog.sym \ - $(OBJ)GoToDialog.sym \ + $(OBJ)GoToDialog.sym +SYMBOLS3 = \ $(OBJ)MessageBox.sym \ $(OBJ)ReplaceDialog.sym \ - $(OBJ)WindowList.sym -SYMBOLS3 = \ + $(OBJ)WindowList.sym \ + $(if $(OSX),$(OBJ)CocoaDispatch.sym,) \ + $(if $(OSX),$(OBJ)CocoaInterface.sym,) \ $(if $(or $(LINUX),$(OSX)),$(OBJ)NCursesInterface.sym,) \ $(if $(WINDOWS),$(OBJ)Win32Interface.sym,) \ $(if $(WINDOWS),$(OBJ)Win32ConsoleInterface.sym,) \ @@ -422,11 +433,12 @@ SYMBOLS3 = \ $(OBJ)BinaryTree.sym \ $(OBJ)BTNode.sym \ $(OBJ)dataTypes.sym \ - $(OBJ)instance.sym \ + $(OBJ)instance.sym +SYMBOLS4 = \ $(OBJ)String.sym \ $(OBJ)OldList.sym -IMPORTS = $(IMPORTS1) $(IMPORTS2) $(IMPORTS3) +IMPORTS = $(IMPORTS1) $(IMPORTS2) $(IMPORTS3) $(IMPORTS4) IMPORTS1 = \ $(OBJ)Archive.imp \ $(OBJ)BufferedFile.imp \ @@ -474,8 +486,9 @@ IMPORTS1 = \ $(OBJ)LFBDisplayDriver.imp IMPORTS2 = \ $(if $(or $(LINUX),$(OSX)),$(OBJ)NCursesDisplayDriver.imp,) \ - $(OBJ)OpenGLDisplayDriver.imp \ + $(if $(OSX),,$(OBJ)OpenGLDisplayDriver.imp) \ $(if $(WINDOWS),$(OBJ)Win32BitmapPrinterDisplayDriver.imp,) \ + $(if $(OSX),$(OBJ)CocoaOpenGLDisplayDriver.imp,) \ $(if $(WINDOWS),$(OBJ)Win32ConsoleDisplayDriver.imp,) \ $(if $(WINDOWS),$(OBJ)Win32PrinterDisplayDriver.imp,) \ $(if $(LINUX),$(OBJ)XDisplayDriver.imp,) \ @@ -508,11 +521,13 @@ IMPORTS2 = \ $(OBJ)ColorPicker.imp \ $(OBJ)FileDialog.imp \ $(OBJ)FindDialog.imp \ - $(OBJ)GoToDialog.imp \ + $(OBJ)GoToDialog.imp +IMPORTS3 = \ $(OBJ)MessageBox.imp \ $(OBJ)ReplaceDialog.imp \ - $(OBJ)WindowList.imp -IMPORTS3 = \ + $(OBJ)WindowList.imp \ + $(if $(OSX),$(OBJ)CocoaDispatch.imp,) \ + $(if $(OSX),$(OBJ)CocoaInterface.imp,) \ $(if $(or $(LINUX),$(OSX)),$(OBJ)NCursesInterface.imp,) \ $(if $(WINDOWS),$(OBJ)Win32Interface.imp,) \ $(if $(WINDOWS),$(OBJ)Win32ConsoleInterface.imp,) \ @@ -548,7 +563,8 @@ IMPORTS3 = \ $(OBJ)BinaryTree.imp \ $(OBJ)BTNode.imp \ $(OBJ)dataTypes.imp \ - $(OBJ)instance.imp \ + $(OBJ)instance.imp +IMPORTS4 = \ $(OBJ)String.imp \ $(OBJ)OldList.imp @@ -622,8 +638,9 @@ SOURCES2 = \ src/gfx/drivers/lfbConvert.ec \ src/gfx/drivers/LFBDisplayDriver.ec \ $(if $(or $(LINUX),$(OSX)),src/gfx/drivers/NCursesDisplayDriver.ec,) \ - src/gfx/drivers/OpenGLDisplayDriver.ec \ + $(if $(OSX),,src/gfx/drivers/OpenGLDisplayDriver.ec) \ $(if $(WINDOWS),src/gfx/drivers/Win32BitmapPrinterDisplayDriver.ec,) \ + $(if $(OSX),src/gfx/drivers/CocoaOpenGLDisplayDriver.ec,) \ $(if $(WINDOWS),src/gfx/drivers/Win32ConsoleDisplayDriver.ec,) \ $(if $(WINDOWS),src/gfx/drivers/Win32PrinterDisplayDriver.ec,) \ $(if $(LINUX),src/gfx/drivers/XDisplayDriver.ec,) \ @@ -639,11 +656,11 @@ SOURCES2 = \ src/gui/controls/CalendarControl.ec \ src/gui/controls/DataBox.ec \ src/gui/controls/DropBox.ec \ - src/gui/controls/EditBox.ec \ + src/gui/controls/EditBox.ec +SOURCES3 = \ src/gui/controls/Label.ec \ src/gui/controls/ListBox.ec \ - src/gui/controls/Menu.ec -SOURCES3 = \ + src/gui/controls/Menu.ec \ src/gui/controls/Picture.ec \ src/gui/controls/ProgressBar.ec \ src/gui/controls/ScrollBar.ec \ @@ -661,6 +678,10 @@ SOURCES3 = \ src/gui/dialogs/MessageBox.ec \ src/gui/dialogs/ReplaceDialog.ec \ src/gui/dialogs/WindowList.ec \ + $(if $(OSX),src/gui/drivers/cocoa/CocoaDispatch.ec,) \ + $(if $(OSX),src/gui/drivers/cocoa/CocoaEcereBridge.m,) \ + $(if $(OSX),src/gui/drivers/cocoa/CocoaInterface.ec,) \ + $(if $(OSX),src/gui/drivers/cocoa/EcereView.m,) \ $(if $(or $(LINUX),$(OSX)),src/gui/drivers/NCursesInterface.ec,) \ $(if $(WINDOWS),src/gui/drivers/Win32Interface.ec,) \ $(if $(WINDOWS),src/gui/drivers/Win32ConsoleInterface.ec,) \ @@ -682,7 +703,8 @@ SOURCES3 = \ src/net/dcom.ec \ src/net/HTTPFile.ec \ src/net/network.ec \ - src/net/NetworkClientFile.ec \ + src/net/NetworkClientFile.ec +SOURCES4 = \ src/net/Service.ec \ src/net/Socket.ec \ src/com/containers/Array.ec \ @@ -691,8 +713,7 @@ SOURCES3 = \ src/com/containers/Container.ec \ src/com/containers/CustomAVLTree.ec \ src/com/containers/LinkList.ec \ - src/com/containers/List.ec -SOURCES4 = \ + src/com/containers/List.ec \ src/com/containers/Map.ec \ src/com/BinaryTree.ec \ src/com/BTNode.ec \ @@ -837,6 +858,10 @@ ifdef LINUX OFLAGS += -Wl,--no-undefined endif +ifdef OSX +OFLAGS += -framework cocoa -framework OpenGL +endif + # PLATFORM-SPECIFIC OPTIONS ifdef WINDOWS @@ -1094,6 +1119,9 @@ $(OBJ)OpenGLDisplayDriver.sym: src/gfx/drivers/OpenGLDisplayDriver.ec $(OBJ)Win32BitmapPrinterDisplayDriver.sym: src/gfx/drivers/Win32BitmapPrinterDisplayDriver.ec $(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) -c src/gfx/drivers/Win32BitmapPrinterDisplayDriver.ec -o $(OBJ)Win32BitmapPrinterDisplayDriver.sym +$(OBJ)CocoaOpenGLDisplayDriver.sym: src/gfx/drivers/CocoaOpenGLDisplayDriver.ec + $(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) -c src/gfx/drivers/CocoaOpenGLDisplayDriver.ec -o $(OBJ)CocoaOpenGLDisplayDriver.sym + $(OBJ)Win32ConsoleDisplayDriver.sym: src/gfx/drivers/Win32ConsoleDisplayDriver.ec $(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) -c src/gfx/drivers/Win32ConsoleDisplayDriver.ec -o $(OBJ)Win32ConsoleDisplayDriver.sym @@ -1202,6 +1230,12 @@ $(OBJ)ReplaceDialog.sym: src/gui/dialogs/ReplaceDialog.ec $(OBJ)WindowList.sym: src/gui/dialogs/WindowList.ec $(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) -c src/gui/dialogs/WindowList.ec -o $(OBJ)WindowList.sym +$(OBJ)CocoaDispatch.sym: src/gui/drivers/cocoa/CocoaDispatch.ec + $(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) -c src/gui/drivers/cocoa/CocoaDispatch.ec -o $(OBJ)CocoaDispatch.sym + +$(OBJ)CocoaInterface.sym: src/gui/drivers/cocoa/CocoaInterface.ec + $(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) -c src/gui/drivers/cocoa/CocoaInterface.ec -o $(OBJ)CocoaInterface.sym + $(OBJ)NCursesInterface.sym: src/gui/drivers/NCursesInterface.ec $(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) -c src/gui/drivers/NCursesInterface.ec -o $(OBJ)NCursesInterface.sym @@ -1459,6 +1493,9 @@ $(OBJ)OpenGLDisplayDriver.c: src/gfx/drivers/OpenGLDisplayDriver.ec $(OBJ)OpenGL $(OBJ)Win32BitmapPrinterDisplayDriver.c: src/gfx/drivers/Win32BitmapPrinterDisplayDriver.ec $(OBJ)Win32BitmapPrinterDisplayDriver.sym | $(SYMBOLS) $(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY) -c src/gfx/drivers/Win32BitmapPrinterDisplayDriver.ec -o $(OBJ)Win32BitmapPrinterDisplayDriver.c -symbols $(OBJ) +$(OBJ)CocoaOpenGLDisplayDriver.c: src/gfx/drivers/CocoaOpenGLDisplayDriver.ec $(OBJ)CocoaOpenGLDisplayDriver.sym | $(SYMBOLS) + $(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY) -c src/gfx/drivers/CocoaOpenGLDisplayDriver.ec -o $(OBJ)CocoaOpenGLDisplayDriver.c -symbols $(OBJ) + $(OBJ)Win32ConsoleDisplayDriver.c: src/gfx/drivers/Win32ConsoleDisplayDriver.ec $(OBJ)Win32ConsoleDisplayDriver.sym | $(SYMBOLS) $(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY) -c src/gfx/drivers/Win32ConsoleDisplayDriver.ec -o $(OBJ)Win32ConsoleDisplayDriver.c -symbols $(OBJ) @@ -1567,6 +1604,12 @@ $(OBJ)ReplaceDialog.c: src/gui/dialogs/ReplaceDialog.ec $(OBJ)ReplaceDialog.sym $(OBJ)WindowList.c: src/gui/dialogs/WindowList.ec $(OBJ)WindowList.sym | $(SYMBOLS) $(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY) -c src/gui/dialogs/WindowList.ec -o $(OBJ)WindowList.c -symbols $(OBJ) +$(OBJ)CocoaDispatch.c: src/gui/drivers/cocoa/CocoaDispatch.ec $(OBJ)CocoaDispatch.sym | $(SYMBOLS) + $(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY) -c src/gui/drivers/cocoa/CocoaDispatch.ec -o $(OBJ)CocoaDispatch.c -symbols $(OBJ) + +$(OBJ)CocoaInterface.c: src/gui/drivers/cocoa/CocoaInterface.ec $(OBJ)CocoaInterface.sym | $(SYMBOLS) + $(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY) -c src/gui/drivers/cocoa/CocoaInterface.ec -o $(OBJ)CocoaInterface.c -symbols $(OBJ) + $(OBJ)NCursesInterface.c: src/gui/drivers/NCursesInterface.ec $(OBJ)NCursesInterface.sym | $(SYMBOLS) $(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY) -c src/gui/drivers/NCursesInterface.ec -o $(OBJ)NCursesInterface.c -symbols $(OBJ) @@ -1890,6 +1933,9 @@ $(OBJ)OpenGLDisplayDriver.o: $(OBJ)OpenGLDisplayDriver.c $(OBJ)Win32BitmapPrinterDisplayDriver.o: $(OBJ)Win32BitmapPrinterDisplayDriver.c $(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)Win32BitmapPrinterDisplayDriver.c -o $(OBJ)Win32BitmapPrinterDisplayDriver.o +$(OBJ)CocoaOpenGLDisplayDriver.o: $(OBJ)CocoaOpenGLDisplayDriver.c + $(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)CocoaOpenGLDisplayDriver.c -o $(OBJ)CocoaOpenGLDisplayDriver.o + $(OBJ)Win32ConsoleDisplayDriver.o: $(OBJ)Win32ConsoleDisplayDriver.c $(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)Win32ConsoleDisplayDriver.c -o $(OBJ)Win32ConsoleDisplayDriver.o @@ -1998,6 +2044,18 @@ $(OBJ)ReplaceDialog.o: $(OBJ)ReplaceDialog.c $(OBJ)WindowList.o: $(OBJ)WindowList.c $(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)WindowList.c -o $(OBJ)WindowList.o +$(OBJ)CocoaDispatch.o: $(OBJ)CocoaDispatch.c + $(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)CocoaDispatch.c -o $(OBJ)CocoaDispatch.o + +$(OBJ)CocoaEcereBridge.o: src/gui/drivers/cocoa/CocoaEcereBridge.m + $(CC) $(CFLAGS) -c src/gui/drivers/cocoa/CocoaEcereBridge.m -o $(OBJ)CocoaEcereBridge.o + +$(OBJ)CocoaInterface.o: $(OBJ)CocoaInterface.c + $(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)CocoaInterface.c -o $(OBJ)CocoaInterface.o + +$(OBJ)EcereView.o: src/gui/drivers/cocoa/EcereView.m + $(CC) $(CFLAGS) -c src/gui/drivers/cocoa/EcereView.m -o $(OBJ)EcereView.o + $(OBJ)NCursesInterface.o: $(OBJ)NCursesInterface.c $(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)NCursesInterface.c -o $(OBJ)NCursesInterface.o @@ -2133,6 +2191,7 @@ clean: objdir $(call rmq,$(IMPORTS1)) $(call rmq,$(IMPORTS2)) $(call rmq,$(IMPORTS3)) + $(call rmq,$(IMPORTS4)) $(call rmq,$(SYMBOLS1)) $(call rmq,$(SYMBOLS2)) $(call rmq,$(SYMBOLS3)) diff --git a/ecere/Makefile.vanilla b/ecere/Makefile.vanilla index 421b6fd..822b922 100644 --- a/ecere/Makefile.vanilla +++ b/ecere/Makefile.vanilla @@ -64,6 +64,7 @@ OBJECTS2 = \ $(OBJ)lfbConvert.o \ $(OBJ)LFBDisplayDriver.o \ $(if $(or $(LINUX),$(OSX)),$(OBJ)NCursesDisplayDriver.o,) \ + $(if $(OSX),$(OBJ)CocoaOpenGLDisplayDriver.o,) \ $(if $(LINUX),$(OBJ)XDisplayDriver.o,) \ $(OBJ)Bitmap.o \ $(OBJ)BitmapResource.o \ @@ -92,11 +93,15 @@ OBJECTS2 = \ $(OBJ)ColorPicker.o \ $(OBJ)FileDialog.o \ $(OBJ)FindDialog.o \ - $(OBJ)GoToDialog.o \ - $(OBJ)MessageBox.o \ - $(OBJ)ReplaceDialog.o + $(OBJ)GoToDialog.o OBJECTS3 = \ + $(OBJ)MessageBox.o \ + $(OBJ)ReplaceDialog.o \ $(OBJ)WindowList.o \ + $(if $(OSX),$(OBJ)CocoaDispatch.o,) \ + $(if $(OSX),$(OBJ)CocoaEcereBridge.o,) \ + $(if $(OSX),$(OBJ)CocoaInterface.o,) \ + $(if $(OSX),$(OBJ)EcereView.o,) \ $(if $(or $(LINUX),$(OSX)),$(OBJ)NCursesInterface.o,) \ $(if $(WINDOWS),$(OBJ)Win32Interface.o,) \ $(if $(or $(LINUX),$(OSX)),$(OBJ)XInterface.o,) \ @@ -157,6 +162,7 @@ COBJECTS1 = \ $(OBJ)lfbConvert.c \ $(OBJ)LFBDisplayDriver.c \ $(if $(or $(LINUX),$(OSX)),$(OBJ)NCursesDisplayDriver.c,) \ + $(if $(OSX),$(OBJ)CocoaOpenGLDisplayDriver.c,) \ $(if $(LINUX),$(OBJ)XDisplayDriver.c,) \ $(OBJ)Bitmap.c \ $(OBJ)BitmapResource.c \ @@ -175,10 +181,10 @@ COBJECTS1 = \ $(OBJ)ListBox.c \ $(OBJ)Menu.c \ $(OBJ)Picture.c \ - $(OBJ)ProgressBar.c \ - $(OBJ)ScrollBar.c \ - $(OBJ)StatusBar.c + $(OBJ)ProgressBar.c COBJECTS2 = \ + $(OBJ)ScrollBar.c \ + $(OBJ)StatusBar.c \ $(OBJ)Stacker.c \ $(OBJ)PathBox.c \ $(OBJ)ToolTip.c \ @@ -190,6 +196,8 @@ COBJECTS2 = \ $(OBJ)MessageBox.c \ $(OBJ)ReplaceDialog.c \ $(OBJ)WindowList.c \ + $(if $(OSX),$(OBJ)CocoaDispatch.c,) \ + $(if $(OSX),$(OBJ)CocoaInterface.c,) \ $(if $(or $(LINUX),$(OSX)),$(OBJ)NCursesInterface.c,) \ $(if $(WINDOWS),$(OBJ)Win32Interface.c,) \ $(if $(or $(LINUX),$(OSX)),$(OBJ)XInterface.c,) \ @@ -220,7 +228,7 @@ COBJECTS2 = \ $(OBJ)String.c \ $(OBJ)OldList.c -SYMBOLS = $(SYMBOLS1) $(SYMBOLS2) +SYMBOLS = $(SYMBOLS1) $(SYMBOLS2) $(SYMBOLS3) SYMBOLS1 = \ $(OBJ)Archive.sym \ $(OBJ)BufferedFile.sym \ @@ -248,6 +256,7 @@ SYMBOLS1 = \ $(OBJ)lfbConvert.sym \ $(OBJ)LFBDisplayDriver.sym \ $(if $(or $(LINUX),$(OSX)),$(OBJ)NCursesDisplayDriver.sym,) \ + $(if $(OSX),$(OBJ)CocoaOpenGLDisplayDriver.sym,) \ $(if $(LINUX),$(OBJ)XDisplayDriver.sym,) \ $(OBJ)Bitmap.sym \ $(OBJ)BitmapResource.sym \ @@ -264,9 +273,9 @@ SYMBOLS1 = \ $(OBJ)EditBox.sym \ $(OBJ)Label.sym \ $(OBJ)ListBox.sym \ - $(OBJ)Menu.sym \ - $(OBJ)Picture.sym + $(OBJ)Menu.sym SYMBOLS2 = \ + $(OBJ)Picture.sym \ $(OBJ)ProgressBar.sym \ $(OBJ)ScrollBar.sym \ $(OBJ)StatusBar.sym \ @@ -281,6 +290,8 @@ SYMBOLS2 = \ $(OBJ)MessageBox.sym \ $(OBJ)ReplaceDialog.sym \ $(OBJ)WindowList.sym \ + $(if $(OSX),$(OBJ)CocoaDispatch.sym,) \ + $(if $(OSX),$(OBJ)CocoaInterface.sym,) \ $(if $(or $(LINUX),$(OSX)),$(OBJ)NCursesInterface.sym,) \ $(if $(WINDOWS),$(OBJ)Win32Interface.sym,) \ $(if $(or $(LINUX),$(OSX)),$(OBJ)XInterface.sym,) \ @@ -305,13 +316,14 @@ SYMBOLS2 = \ $(OBJ)List.sym \ $(OBJ)Map.sym \ $(OBJ)BinaryTree.sym \ - $(OBJ)BTNode.sym \ + $(OBJ)BTNode.sym +SYMBOLS3 = \ $(OBJ)dataTypes.sym \ $(OBJ)instance.sym \ $(OBJ)String.sym \ $(OBJ)OldList.sym -IMPORTS = $(IMPORTS1) $(IMPORTS2) +IMPORTS = $(IMPORTS1) $(IMPORTS2) $(IMPORTS3) IMPORTS1 = \ $(OBJ)Archive.imp \ $(OBJ)BufferedFile.imp \ @@ -339,6 +351,7 @@ IMPORTS1 = \ $(OBJ)lfbConvert.imp \ $(OBJ)LFBDisplayDriver.imp \ $(if $(or $(LINUX),$(OSX)),$(OBJ)NCursesDisplayDriver.imp,) \ + $(if $(OSX),$(OBJ)CocoaOpenGLDisplayDriver.imp,) \ $(if $(LINUX),$(OBJ)XDisplayDriver.imp,) \ $(OBJ)Bitmap.imp \ $(OBJ)BitmapResource.imp \ @@ -355,9 +368,9 @@ IMPORTS1 = \ $(OBJ)EditBox.imp \ $(OBJ)Label.imp \ $(OBJ)ListBox.imp \ - $(OBJ)Menu.imp \ - $(OBJ)Picture.imp + $(OBJ)Menu.imp IMPORTS2 = \ + $(OBJ)Picture.imp \ $(OBJ)ProgressBar.imp \ $(OBJ)ScrollBar.imp \ $(OBJ)StatusBar.imp \ @@ -372,6 +385,8 @@ IMPORTS2 = \ $(OBJ)MessageBox.imp \ $(OBJ)ReplaceDialog.imp \ $(OBJ)WindowList.imp \ + $(if $(OSX),$(OBJ)CocoaDispatch.imp,) \ + $(if $(OSX),$(OBJ)CocoaInterface.imp,) \ $(if $(or $(LINUX),$(OSX)),$(OBJ)NCursesInterface.imp,) \ $(if $(WINDOWS),$(OBJ)Win32Interface.imp,) \ $(if $(or $(LINUX),$(OSX)),$(OBJ)XInterface.imp,) \ @@ -396,7 +411,8 @@ IMPORTS2 = \ $(OBJ)List.imp \ $(OBJ)Map.imp \ $(OBJ)BinaryTree.imp \ - $(OBJ)BTNode.imp \ + $(OBJ)BTNode.imp +IMPORTS3 = \ $(OBJ)dataTypes.imp \ $(OBJ)instance.imp \ $(OBJ)String.imp \ @@ -453,6 +469,7 @@ SOURCES2 = \ src/gfx/drivers/lfbConvert.ec \ src/gfx/drivers/LFBDisplayDriver.ec \ $(if $(or $(LINUX),$(OSX)),src/gfx/drivers/NCursesDisplayDriver.ec,) \ + $(if $(OSX),src/gfx/drivers/CocoaOpenGLDisplayDriver.ec,) \ $(if $(LINUX),src/gfx/drivers/XDisplayDriver.ec,) \ src/gfx/Bitmap.ec \ src/gfx/BitmapResource.ec \ @@ -483,9 +500,13 @@ SOURCES2 = \ src/gui/dialogs/FindDialog.ec \ src/gui/dialogs/GoToDialog.ec \ src/gui/dialogs/MessageBox.ec \ - src/gui/dialogs/ReplaceDialog.ec \ - src/gui/dialogs/WindowList.ec + src/gui/dialogs/ReplaceDialog.ec SOURCES3 = \ + src/gui/dialogs/WindowList.ec \ + $(if $(OSX),src/gui/drivers/cocoa/CocoaDispatch.ec,) \ + $(if $(OSX),src/gui/drivers/cocoa/CocoaEcereBridge.m,) \ + $(if $(OSX),src/gui/drivers/cocoa/CocoaInterface.ec,) \ + $(if $(OSX),src/gui/drivers/cocoa/EcereView.m,) \ $(if $(or $(LINUX),$(OSX)),src/gui/drivers/NCursesInterface.ec,) \ $(if $(WINDOWS),src/gui/drivers/Win32Interface.ec,) \ $(if $(or $(LINUX),$(OSX)),src/gui/drivers/XInterface.ec,) \ @@ -790,6 +811,9 @@ $(OBJ)LFBDisplayDriver.sym: src/gfx/drivers/LFBDisplayDriver.ec $(OBJ)NCursesDisplayDriver.sym: src/gfx/drivers/NCursesDisplayDriver.ec $(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) -c src/gfx/drivers/NCursesDisplayDriver.ec -o $(OBJ)NCursesDisplayDriver.sym +$(OBJ)CocoaOpenGLDisplayDriver.sym: src/gfx/drivers/CocoaOpenGLDisplayDriver.ec + $(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) -c src/gfx/drivers/CocoaOpenGLDisplayDriver.ec -o $(OBJ)CocoaOpenGLDisplayDriver.sym + $(OBJ)XDisplayDriver.sym: src/gfx/drivers/XDisplayDriver.ec $(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) -c src/gfx/drivers/XDisplayDriver.ec -o $(OBJ)XDisplayDriver.sym @@ -886,6 +910,12 @@ $(OBJ)ReplaceDialog.sym: src/gui/dialogs/ReplaceDialog.ec $(OBJ)WindowList.sym: src/gui/dialogs/WindowList.ec $(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) -c src/gui/dialogs/WindowList.ec -o $(OBJ)WindowList.sym +$(OBJ)CocoaDispatch.sym: src/gui/drivers/cocoa/CocoaDispatch.ec + $(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) -c src/gui/drivers/cocoa/CocoaDispatch.ec -o $(OBJ)CocoaDispatch.sym + +$(OBJ)CocoaInterface.sym: src/gui/drivers/cocoa/CocoaInterface.ec + $(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) -c src/gui/drivers/cocoa/CocoaInterface.ec -o $(OBJ)CocoaInterface.sym + $(OBJ)NCursesInterface.sym: src/gui/drivers/NCursesInterface.ec $(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) -c src/gui/drivers/NCursesInterface.ec -o $(OBJ)NCursesInterface.sym @@ -1053,6 +1083,9 @@ $(OBJ)LFBDisplayDriver.c: src/gfx/drivers/LFBDisplayDriver.ec $(OBJ)LFBDisplayDr $(OBJ)NCursesDisplayDriver.c: src/gfx/drivers/NCursesDisplayDriver.ec $(OBJ)NCursesDisplayDriver.sym | $(SYMBOLS) $(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY) -c src/gfx/drivers/NCursesDisplayDriver.ec -o $(OBJ)NCursesDisplayDriver.c -symbols $(OBJ) +$(OBJ)CocoaOpenGLDisplayDriver.c: src/gfx/drivers/CocoaOpenGLDisplayDriver.ec $(OBJ)CocoaOpenGLDisplayDriver.sym | $(SYMBOLS) + $(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY) -c src/gfx/drivers/CocoaOpenGLDisplayDriver.ec -o $(OBJ)CocoaOpenGLDisplayDriver.c -symbols $(OBJ) + $(OBJ)XDisplayDriver.c: src/gfx/drivers/XDisplayDriver.ec $(OBJ)XDisplayDriver.sym | $(SYMBOLS) $(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY) -c src/gfx/drivers/XDisplayDriver.ec -o $(OBJ)XDisplayDriver.c -symbols $(OBJ) @@ -1149,6 +1182,12 @@ $(OBJ)ReplaceDialog.c: src/gui/dialogs/ReplaceDialog.ec $(OBJ)ReplaceDialog.sym $(OBJ)WindowList.c: src/gui/dialogs/WindowList.ec $(OBJ)WindowList.sym | $(SYMBOLS) $(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY) -c src/gui/dialogs/WindowList.ec -o $(OBJ)WindowList.c -symbols $(OBJ) +$(OBJ)CocoaDispatch.c: src/gui/drivers/cocoa/CocoaDispatch.ec $(OBJ)CocoaDispatch.sym | $(SYMBOLS) + $(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY) -c src/gui/drivers/cocoa/CocoaDispatch.ec -o $(OBJ)CocoaDispatch.c -symbols $(OBJ) + +$(OBJ)CocoaInterface.c: src/gui/drivers/cocoa/CocoaInterface.ec $(OBJ)CocoaInterface.sym | $(SYMBOLS) + $(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY) -c src/gui/drivers/cocoa/CocoaInterface.ec -o $(OBJ)CocoaInterface.c -symbols $(OBJ) + $(OBJ)NCursesInterface.c: src/gui/drivers/NCursesInterface.ec $(OBJ)NCursesInterface.sym | $(SYMBOLS) $(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY) -c src/gui/drivers/NCursesInterface.ec -o $(OBJ)NCursesInterface.c -symbols $(OBJ) @@ -1382,6 +1421,9 @@ $(OBJ)LFBDisplayDriver.o: $(OBJ)LFBDisplayDriver.c $(OBJ)NCursesDisplayDriver.o: $(OBJ)NCursesDisplayDriver.c $(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)NCursesDisplayDriver.c -o $(OBJ)NCursesDisplayDriver.o +$(OBJ)CocoaOpenGLDisplayDriver.o: $(OBJ)CocoaOpenGLDisplayDriver.c + $(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)CocoaOpenGLDisplayDriver.c -o $(OBJ)CocoaOpenGLDisplayDriver.o + $(OBJ)XDisplayDriver.o: $(OBJ)XDisplayDriver.c $(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)XDisplayDriver.c -o $(OBJ)XDisplayDriver.o @@ -1478,6 +1520,18 @@ $(OBJ)ReplaceDialog.o: $(OBJ)ReplaceDialog.c $(OBJ)WindowList.o: $(OBJ)WindowList.c $(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)WindowList.c -o $(OBJ)WindowList.o +$(OBJ)CocoaDispatch.o: $(OBJ)CocoaDispatch.c + $(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)CocoaDispatch.c -o $(OBJ)CocoaDispatch.o + +$(OBJ)CocoaEcereBridge.o: src/gui/drivers/cocoa/CocoaEcereBridge.m + $(CC) $(CFLAGS) -c src/gui/drivers/cocoa/CocoaEcereBridge.m -o $(OBJ)CocoaEcereBridge.o + +$(OBJ)CocoaInterface.o: $(OBJ)CocoaInterface.c + $(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)CocoaInterface.c -o $(OBJ)CocoaInterface.o + +$(OBJ)EcereView.o: src/gui/drivers/cocoa/EcereView.m + $(CC) $(CFLAGS) -c src/gui/drivers/cocoa/EcereView.m -o $(OBJ)EcereView.o + $(OBJ)NCursesInterface.o: $(OBJ)NCursesInterface.c $(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)NCursesInterface.c -o $(OBJ)NCursesInterface.o @@ -1580,8 +1634,10 @@ clean: objdir $(call rmq,$(COBJECTS2)) $(call rmq,$(IMPORTS1)) $(call rmq,$(IMPORTS2)) + $(call rmq,$(IMPORTS3)) $(call rmq,$(SYMBOLS1)) $(call rmq,$(SYMBOLS2)) + $(call rmq,$(SYMBOLS3)) realclean: $(call rmrq,$(OBJ)) diff --git a/ecere/ecere.epj b/ecere/ecere.epj index 7b1367d..7f14bcd 100644 --- a/ecere/ecere.epj +++ b/ecere/ecere.epj @@ -985,6 +985,14 @@ "Options" : { "ExcludeFromBuild" : false }, + "Platforms" : [ + { + "Name" : "apple", + "Options" : { + "ExcludeFromBuild" : true + } + } + ], "Configurations" : [ { "Name" : "WSMS", @@ -1070,6 +1078,25 @@ ] }, { + "FileName" : "CocoaOpenGLDisplayDriver.ec", + "Platforms" : [ + { + "Name" : "apple", + "Options" : { + "ExcludeFromBuild" : false + } + } + ], + "Configurations" : [ + { + "Name" : "Vanilla", + "Options" : { + "ExcludeFromBuild" : true + } + } + ] + }, + { "FileName" : "Win32ConsoleDisplayDriver.ec", "Platforms" : [ { @@ -1289,6 +1316,25 @@ "Folder" : "drivers", "Files" : [ { + "Folder" : "cocoa", + "Files" : [ + "CocoaDispatch.ec", + "CocoaEcereBridge.h", + "CocoaEcereBridge.m", + "CocoaInterface.ec", + "EcereView.h", + "EcereView.m" + ], + "Platforms" : [ + { + "Name" : "apple", + "Options" : { + "ExcludeFromBuild" : false + } + } + ] + }, + { "FileName" : "NCursesInterface.ec", "Platforms" : [ { diff --git a/ecere/src/com/String.ec b/ecere/src/com/String.ec index 143118e..df057b4 100644 --- a/ecere/src/com/String.ec +++ b/ecere/src/com/String.ec @@ -4,6 +4,7 @@ namespace sys; default: +#undef __BLOCKS__ #include #if !defined(ECERE_BOOTSTRAP) // quick fix for now #if defined(__WIN32__) diff --git a/ecere/src/com/instance.ec b/ecere/src/com/instance.ec index 5a62679..8669444 100644 --- a/ecere/src/com/instance.ec +++ b/ecere/src/com/instance.ec @@ -12,6 +12,8 @@ import "dataTypes" #endif #endif +#undef __BLOCKS__ + #if !defined(ECERE_BOOTSTRAP) import "Mutex" #endif diff --git a/ecere/src/gfx/drivers/CocoaOpenGLDisplayDriver.ec b/ecere/src/gfx/drivers/CocoaOpenGLDisplayDriver.ec new file mode 100644 index 0000000..8ea05cb --- /dev/null +++ b/ecere/src/gfx/drivers/CocoaOpenGLDisplayDriver.ec @@ -0,0 +1,1790 @@ +#define USEPBUFFER + +namespace gfx::drivers; + +#include + +import "CocoaInterface.h" + +import "Display" +import "Window" + +#define glLoadMatrix glLoadMatrixd +#define glMultMatrix glMultMatrixd +#define glGetMatrix glGetDoublev +#define glTranslate glTranslated +#define glScale glScaled + +#define GL_ARRAY_BUFFER_ARB 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER_ARB 0x8893 +#define GL_STATIC_DRAW_ARB 0x88E4 +#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8 +#define GL_SEPARATE_SPECULAR_COLOR 0x81FA + +#define GL_MULTISAMPLE_ARB 0x809D + +//static int displayWidth, displayHeight; + +#define GL_CLAMP_TO_EDGE 0x812F + +static bool useSingleGLContext = false; + +class DisplayData : struct +{ + ColorAlpha * flippingBuffer; + int flipBufH, flipBufW; + bool depthWrite; + int x, y; + uint stride; + byte * picture; +}; + +class SystemData : struct +{ + bool loadingFont; +}; + +class SurfaceData : struct +{ + Font font; + bool opaqueText; + int xOffset; + bool writingText; + + float foreground[4], background[4], bitmapMult[4]; +}; + +class MeshData : struct +{ + int vertices; + int normals; + int texCoords; + int texCoords2; + int colors; +}; + +class IndexData : struct +{ + uint16 *indices; + int buffer; + int nIndices; +}; + +static int primitiveTypes[RenderPrimitiveType] = +{ + GL_POINTS, GL_LINES, GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS, GL_QUAD_STRIP, GL_LINE_STRIP +}; + +int current; +void *previous; + +void CocoaGlAssert() +{ + GLenum error = glGetError(); + + if(error) { + printf("**** glGetError():%i ****\n", error); + exit(1); + } +} + +class OpenGLDisplayDriver : DisplayDriver +{ + class_property(name) = "CocoaOpenGL"; + + bool LockSystem(DisplaySystem displaySystem) + { + printf("CocoaOpenGLDisplayDriver:LockSystem STUB! %s:%i\n", __FILE__, __LINE__); + return true; + } + + void UnlockSystem(DisplaySystem displaySystem) + { + printf("CocoaOpenGLDisplayDriver:UnlockSystem STUB! %s:%i\n", __FILE__, __LINE__); + } + + bool Lock(Display display) + { + printf("CocoaOpenGLDisplayDriver:Lock %s:%i\n", __FILE__, __LINE__); + return CocoaLock(display.window); + } + + void Unlock(Display display) + { + printf("CocoaOpenGLDisplayDriver:Unlock %s:%i\n", __FILE__, __LINE__); + CocoaUnlock(display.window); + } + + void DestroyDisplay(Display display) + { + printf("CocoaOpenGLDisplayDriver:DestroyDisplay STUB! %s:%i\n", __FILE__, __LINE__); + } + + bool CreateDisplaySystem(DisplaySystem displaySystem) + { + bool result = true; + + SystemData system = SystemData { }; + displaySystem.driverData = system; + + printf("CocoaOpenGLDisplayDriver:CreateDisplaySystem %s:%i\n", __FILE__, __LINE__); + return result; + } + + void DestroyDisplaySystem(DisplaySystem displaySystem) + { + printf("CocoaOpenGLDisplayDriver:DestroyDisplaySystem STUB! %s:%i\n", __FILE__, __LINE__); + } + + bool CreateDisplay(Display display) + { + bool result = true; + + DisplayData displayData = display.driverData; + SystemData systemData = display.displaySystem.driverData; + + displayData = display.driverData = DisplayData { }; + + CocoaOpenGLMakeCurrentContext(display.window); + + CocoaGlAssert(); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + CocoaGlAssert(); + glEnable(GL_BLEND); + CocoaGlAssert(); + + glMatrixMode(GL_MODELVIEW); + CocoaGlAssert(); + glScalef(1.0f, 1.0f, -1.0f); + CocoaGlAssert(); + glMatrixMode(GL_PROJECTION); + CocoaGlAssert(); + glShadeModel(GL_FLAT); + CocoaGlAssert(); + + glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); + CocoaGlAssert(); + glFogi(GL_FOG_MODE, GL_EXP); + CocoaGlAssert(); + glFogf(GL_FOG_DENSITY, 0); + CocoaGlAssert(); + glEnable(GL_NORMALIZE); + CocoaGlAssert(); + glDepthFunc(GL_LESS); + CocoaGlAssert(); + glClearDepth(1.0); + CocoaGlAssert(); + glDisable(GL_MULTISAMPLE_ARB); + CocoaGlAssert(); + + display.ambient = Color { 50,50,50 }; + + printf("CocoaOpenGLDisplayDriver:CreateDisplay %p %s:%i\n", display.window, __FILE__, __LINE__); + return result; + } + + bool DisplaySize(Display display, int width, int height) + { + bool result = true; + + DisplayData displayData = display.driverData; + SystemData systemData = display.displaySystem.driverData; + + printf("CocoaOpenGLDisplayDriver:DisplaySize(%i,%i) %s:%i\n", width, height, __FILE__, __LINE__); + + CocoaOpenGLMakeCurrentContext(display.window); + + glViewport(0,0,width,height); + CocoaGlAssert(); + glLoadIdentity(); + CocoaGlAssert(); + glOrtho(0,width,height,0,0.0,1.0); + CocoaGlAssert(); + display.width = width; + display.height = height; + + if(!displayData.flippingBuffer || displayData.flipBufW < width || displayData.flipBufH < height) + { + displayData.flipBufW = width; + displayData.flipBufH = height; + displayData.flippingBuffer = renew displayData.flippingBuffer ColorAlpha [width * height]; + } + if(displayData.flippingBuffer) + result = true; + + return result; + } + + void DisplayPosition(Display display, int x, int y) + { + DisplayData displayData = display.driverData; + + printf("CocoaOpenGLDisplayDriver:DisplayPosition(%i,%i) %s:%i\n", x, y, __FILE__, __LINE__); + + displayData.x = x; + displayData.y = y; + printf("glGetError():%i\n", glGetError()); + } + + void SetPalette(Display display, ColorAlpha * palette, bool colorMatch) + { + printf("CocoaOpenGLDisplayDriver:SetPalette STUB! %s:%i\n", __FILE__, __LINE__); + } + + void RestorePalette(Display display) + { + printf("CocoaOpenGLDisplayDriver:RestorePalette STUB! %s:%i\n", __FILE__, __LINE__); + } + + void StartUpdate(Display display) + { + printf("CocoaOpenGLDisplayDriver:StartUpdate STUB! %s:%i\n", __FILE__, __LINE__); + } + + void EndUpdate(Display display) + { + printf("CocoaOpenGLDisplayDriver:EndUpdate STUB! %s:%i\n", __FILE__, __LINE__); + } + + void Scroll(Display display, Box scroll, int x, int y, Extent dirty) + { + printf("CocoaOpenGLDisplayDriver:Scroll STUB! %s:%i\n", __FILE__, __LINE__); + } + + void Update(Display display, Box updateBox) + { + //CocoaOpenGLUpdate(display.window); + printf("CocoaOpenGLDisplayDriver:Update %s:%i\n", __FILE__, __LINE__); + } + + void FreeBitmap(DisplaySystem displaySystem, Bitmap bitmap) + { + glDeleteTextures(1, (int *)&bitmap.driverData); + bitmap.driverData = 0; + + bitmap.driver = class(LFBDisplayDriver); + + printf("CocoaOpenGLDisplayDriver:FreeBitmap %s:%i\n", __FILE__, __LINE__); + } + + bool AllocateBitmap(DisplaySystem displaySystem, Bitmap bitmap, int width, int height, int stride, PixelFormat format, bool allocatePalette) + { + bool result = false; + Bitmap mipMap { }; + int glBitmap = -1; + + uint w = pow2i(Min(width, 1024)), h = pow2i(Min(height, 1024)); + + printf("CocoaOpenGLDisplayDriver:AllocateBitmap %s:%i\n", __FILE__, __LINE__); + + CocoaGlAssert(); + glGenTextures(1, &glBitmap); + CocoaGlAssert(); + glBindTexture(GL_TEXTURE_2D, glBitmap); + + CocoaGlAssert(); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + CocoaGlAssert(); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + CocoaGlAssert(); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + CocoaGlAssert(); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + CocoaGlAssert(); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + CocoaGlAssert(); + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + + mipMap.Allocate(null, w, h, w, pixelFormatRGBA, false); + + CocoaGlAssert(); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipMap.picture); + delete mipMap; + + bitmap.driverData = (void *)glBitmap; + bitmap.driver = displaySystem.driver; + bitmap.width = w; + bitmap.height = h; + + result = true; + + return result; + } + + bool MakeDDBitmap(DisplaySystem displaySystem, Bitmap bitmap, bool mipMaps) + { + bool result = false; + SystemData systemData = displaySystem.driverData; + + // Pre process the bitmap... First make it 32 bit + if(bitmap.Convert(null, pixelFormat888, null)) + { + int c, level; + uint w = pow2i(Min(bitmap.width, 1024)), h = pow2i(Min(bitmap.height, 1024)); + int glBitmap = -1; + + // Switch ARGB to RGBA + //if(bitmap.format != pixelFormatRGBA) + { + for(c=0; c 1 || h > 1); level++, w >>= 1, h >>= 1) + { + Bitmap mipMap; + if(bitmap.width != w || bitmap.height != h) + { + mipMap = Bitmap { }; + if(mipMap.Allocate(null, w, h, w, bitmap.pixelFormat, false)) + { + Surface mipSurface = mipMap.GetSurface(0,0,null); + mipSurface.Filter(bitmap, 0,0,0,0, w, h, bitmap.width, bitmap.height); + delete mipSurface; + } + else + { + result = false; + delete mipMap; + } + } + else + mipMap = bitmap; + + if(result) + { + int error; + glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipMap.picture); + CocoaGlAssert(); + if((error = glGetError())) + { + result = false; + } + } + if(mipMap != bitmap) + delete mipMap; + if(!mipMaps) break; + } + + if(!bitmap.keepData) + bitmap.driver.FreeBitmap(bitmap.displaySystem, bitmap); + bitmap.driverData = (void *)glBitmap; + bitmap.driver = displaySystem.driver; + + if(!result) + FreeBitmap(displaySystem, bitmap); + else if(systemData.loadingFont) + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + CocoaGlAssert(); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + CocoaGlAssert(); + systemData.loadingFont = false; + } + } + + printf("CocoaOpenGLDisplayDriver:MakeDDBitmap %i %s:%i\n", result, __FILE__, __LINE__); + return result; + } + + void ReleaseSurface(Display display, Surface surface) + { + printf("CocoaOpenGLDisplayDriver:ReleaseSurface %s:%i\n", __FILE__, __LINE__); + + glDisable(GL_SCISSOR_TEST); + CocoaGlAssert(); + delete surface.driverData; + surface.driverData = null; + } + + bool GetBitmapSurface(DisplaySystem displaySystem, Surface surface, Bitmap bitmap, int x, int y, Box clip) + { + printf("CocoaOpenGLDisplayDriver:GetBitmapSurface STUB! %s:%i\n", __FILE__, __LINE__); + return false; + } + + bool GetSurface(Display display, Surface surface, int x,int y, Box clip) + { + bool result = true; + + SurfaceData surfaceData = SurfaceData { }; + surface.driverData = surfaceData; + + printf("CocoaOpenGLDisplayDriver:GetSurface %p %s:%i\n", surfaceData, __FILE__, __LINE__); + + if(surfaceData) + { + CocoaGlAssert(); + glViewport(0,0,display.width,display.height); + CocoaGlAssert(); + glLoadIdentity(); + CocoaGlAssert(); + printf("display:%i, %i\n", display.width, display.height); + glOrtho(0, display.width, display.height, 0, 0.0f, 1.0f); + CocoaGlAssert(); + + surface.offset.x = x; + surface.offset.y = y; + surface.unclippedBox = surface.box = clip; + surfaceData.bitmapMult[0] = 1; + surfaceData.bitmapMult[1] = 1; + surfaceData.bitmapMult[2] = 1; + surfaceData.bitmapMult[3] = 1; + + glEnable(GL_SCISSOR_TEST); + CocoaGlAssert(); + glScissor( + x+clip.left, + (display.height) -(y+clip.bottom)-1, + clip.right-clip.left+1, + clip.bottom-clip.top+1); + CocoaGlAssert(); + result = true; + } + + return result; + } + + void Clip(Display display, Surface surface, Box clip) + { + Box box; + + printf("CocoaOpenGLDisplayDriver:Clip STUB! %s:%i\n", __FILE__, __LINE__); + + if(clip != null) + { + box = clip; + box.Clip(surface.unclippedBox); + surface.box = box; + } + else + { + box = surface.box = surface.unclippedBox; + } + + box.left += surface.offset.x; + box.top += surface.offset.y; + box.right+= surface.offset.x; + box.bottom += surface.offset.y; + + glScissor( + box.left,display.height - box.bottom - 1, + box.right-box.left+1, box.bottom-box.top+1); + } + + bool GrabScreen(Display display, Bitmap bitmap, int x, int y, unsigned int w, unsigned int h) + { + bool result = false; + printf("CocoaOpenGLDisplayDriver:GrabScreen STUB! %s:%i\n", __FILE__, __LINE__); + return result; + } + + void SetForeground(Display display, Surface surface, ColorAlpha color) + { + SurfaceData surfaceData = surface.driverData; + + printf("CocoaOpenGLDisplayDriver:SetForeground(%i,%i,%i,%i) %s:%i\n", color.color.r, color.color.g, color.color.b, color.a, __FILE__, __LINE__); + + surfaceData.foreground[0] = color.color.r/255.0f; + surfaceData.foreground[1] = color.color.g/255.0f; + surfaceData.foreground[2] = color.color.b/255.0f; + surfaceData.foreground[3] = color.a/255.0f; + } + + void SetBackground(Display display, Surface surface, ColorAlpha color) + { + SurfaceData surfaceData = surface.driverData; + + printf("CocoaOpenGLDisplayDriver:SetBackground(%i,%i,%i,%i) %s:%i\n", color.color.r, color.color.g, color.color.b, color.a, __FILE__, __LINE__); + + surfaceData.background[0] = color.color.r/255.0f; + surfaceData.background[1] = color.color.g/255.0f; + surfaceData.background[2] = color.color.b/255.0f; + surfaceData.background[3] = color.a/255.0f; + } + + void SetBlitTint(Display display, Surface surface, ColorAlpha color) + { + SurfaceData surfaceData = surface.driverData; + + printf("CocoaOpenGLDisplayDriver:SetBlitTint(%i,%i,%i,%i) %s:%i\n", color.color.r, color.color.g, color.color.b, color.a, __FILE__, __LINE__); + + surfaceData.bitmapMult[0] = color.color.r/255.0f; + surfaceData.bitmapMult[1] = color.color.g/255.0f; + surfaceData.bitmapMult[2] = color.color.b/255.0f; + surfaceData.bitmapMult[3] = color.a/255.0f; + } + + + ColorAlpha GetPixel(Display display, Surface surface,int x,int y) + { + printf("CocoaOpenGLDisplayDriver:GetPixel STUB! %s:%i\n", __FILE__, __LINE__); + return 0; + } + + void PutPixel(Display display, Surface surface,int x,int y) + { + printf("CocoaOpenGLDisplayDriver:PutPixel %s:%i\n", __FILE__, __LINE__); + + glBegin(GL_POINTS); + CocoaGlAssert(); + glVertex2f(x+surface.offset.x + 0.5f, y+surface.offset.y + 0.5f); + glEnd(); + CocoaGlAssert(); + } + + void DrawLine(Display display, Surface surface, int x1, int y1, int x2, int y2) + { + SurfaceData surfaceData = surface.driverData; + + printf("CocoaOpenGLDisplayDriver:DrawLine %s:%i\n", __FILE__, __LINE__); + printf("--DrawLine(x1:%i, y1:%i, x2:%i, y2:%i)\n", x1, y1, x2, y2); + + glColor4fv(surfaceData.foreground); + glBegin(GL_LINES); + + glVertex2f(x1+surface.offset.x + 0.5f, y1+surface.offset.y + 0.5f); + glVertex2f(x2+surface.offset.x + 0.5f, y2+surface.offset.y + 0.5f); + + glEnd(); + CocoaGlAssert(); + } + + void Rectangle(Display display, Surface surface,int x1,int y1,int x2,int y2) + { + printf("CocoaOpenGLDisplayDriver:Rectangle %s:%i\n", __FILE__, __LINE__); + printf("--Rectangle(x1:%i, y1:%i, x2:%i, y2:%i)\n", x1, y1, x2, y2); + glBegin(GL_LINE_LOOP); + + glVertex2f(x1+surface.offset.x + 0.5f, y1+surface.offset.y + 0.5f); + glVertex2f(x1+surface.offset.x + 0.5f, y2+surface.offset.y + 0.5f); + glVertex2f(x2+surface.offset.x + 0.5f, y2+surface.offset.y + 0.5f); + glVertex2f(x2+surface.offset.x + 0.5f, y1+surface.offset.y + 0.5f); + + glEnd(); + CocoaGlAssert(); + } + + void Area(Display display, Surface surface,int x1,int y1,int x2,int y2) + { + SurfaceData surfaceData = surface.driverData; + + printf("CocoaOpenGLDisplayDriver:Area %s:%i\n", __FILE__, __LINE__); + + CocoaGlAssert(); + glColor4fv(surfaceData.background); + + glRecti(x1+surface.offset.x, y1+surface.offset.y, + x2+surface.offset.x + 1, y2+surface.offset.y + 1); + CocoaGlAssert(); + } + + void Clear(Display display, Surface surface, ClearType type) + { + DisplayData displayData = display.driverData; + SurfaceData surfaceData = surface.driverData; + + if(type != depthBuffer) + { + glClearColor(surfaceData.background[0], surfaceData.background[1], surfaceData.background[2], surfaceData.background[3]); + CocoaGlAssert(); + } + if(type != colorBuffer && !displayData.depthWrite) + { + glDepthMask((byte)bool::true); + CocoaGlAssert(); + } + glClear(((type != depthBuffer) ? GL_COLOR_BUFFER_BIT : 0) | + ((type != colorBuffer) ? GL_DEPTH_BUFFER_BIT : 0)); + CocoaGlAssert(); + + if(type != colorBuffer && !displayData.depthWrite) + { + glDepthMask((byte)bool::false); + CocoaGlAssert(); + } + if(type != depthBuffer) + { + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + CocoaGlAssert(); + } + if(type != colorBuffer) + { + glDepthMask((byte)bool::true); + CocoaGlAssert(); + } + + glClear(((type != depthBuffer) ? GL_COLOR_BUFFER_BIT : 0) | + ((type != colorBuffer) ? GL_DEPTH_BUFFER_BIT : 0)); + CocoaGlAssert(); + + if(type != colorBuffer) + { + glDepthMask((byte)bool::false); + CocoaGlAssert(); + } + printf("CocoaOpenGLDisplayDriver:Clear %s:%i\n", __FILE__, __LINE__); + } + + bool ConvertBitmap(DisplaySystem displaySystem, Bitmap bitmap, PixelFormat format, ColorAlpha * palette) + { + bool result = false; + + printf("CocoaOpenGLDisplayDriver:ConvertBitmap %s:%i\n", __FILE__, __LINE__); + + return result; + } + + void Blit(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h) + { + printf("CocoaOpenGLDisplayDriver:Blit %s:%i\n", __FILE__, __LINE__); + printf("--BLIT(dx:%i, dy:%i, sx:%i, sy:%i, w:%i, h:%i)\n", dx, dy, sx, sy, w, h); + + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, (uint)bitmap.driverData); + glBegin(GL_QUADS); + + if(h < 0) + { + glTexCoord2f((float)sx/ bitmap.width, (float)(sy-h)/ bitmap.height); + glVertex2i(dx+surface.offset.x, dy+surface.offset.y); + glTexCoord2f((float)(sx+w) / bitmap.width, (float)(sy-h)/ bitmap.height); + glVertex2i(dx+w+surface.offset.x, dy+surface.offset.y); + glTexCoord2f((float)(sx+w)/ bitmap.width, (float)sy/ bitmap.height); + glVertex2i(dx+w+surface.offset.x, dy-h+surface.offset.y); + glTexCoord2f((float)sx / bitmap.width, (float)sy/ bitmap.height); + glVertex2i(dx+surface.offset.x, dy-h+surface.offset.y); + } + else + { + glTexCoord2f((float)sx / bitmap.width, (float)sy/ bitmap.height); + glVertex2f((float)dx+surface.offset.x, (float)dy+surface.offset.y); + glTexCoord2f((float)(sx+w)/ bitmap.width, (float)sy/ bitmap.height); + glVertex2f((float)dx+w+surface.offset.x, (float)dy+surface.offset.y); + glTexCoord2f((float)(sx+w) / bitmap.width, (float)(sy+h)/ bitmap.height); + glVertex2f((float)dx+w+surface.offset.x, (float)dy+h+surface.offset.y); + glTexCoord2f((float)sx/ bitmap.width, (float)(sy+h)/ bitmap.height); + glVertex2f((float)dx+surface.offset.x, (float)dy+h+surface.offset.y); + } + glEnd(); + CocoaGlAssert(); + } + + void Stretch(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh) + { + printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__); + glEnable(GL_TEXTURE_2D); + CocoaGlAssert(); + glBindTexture(GL_TEXTURE_2D, (uint)bitmap.driverData); + CocoaGlAssert(); + + glBegin(GL_QUADS); + CocoaGlAssert(); + + if(h < 0) + { + glTexCoord2f((float)(sx)/ bitmap.width, (float)(sy+sh)/ bitmap.height); + CocoaGlAssert(); + glVertex2i(dx+surface.offset.x, dy+surface.offset.y); + CocoaGlAssert(); + + glTexCoord2f((float)(sx+sw) / bitmap.width, (float)(sy+sh)/ bitmap.height); + CocoaGlAssert(); + glVertex2i(dx+w+surface.offset.x, dy+surface.offset.y); + CocoaGlAssert(); + + glTexCoord2f((float)(sx+sw)/ bitmap.width, (float)(sy)/ bitmap.height); + CocoaGlAssert(); + glVertex2i(dx+w+surface.offset.x, dy-h+surface.offset.y); + CocoaGlAssert(); + + glTexCoord2f((float)(sx) / bitmap.width, (float)(sy)/ bitmap.height); + CocoaGlAssert(); + glVertex2i(dx+surface.offset.x, dy-h+surface.offset.y); + CocoaGlAssert(); + } + else + { + glTexCoord2f((float)(sx) / bitmap.width, (float)(sy)/ bitmap.height); + CocoaGlAssert(); + glVertex2i(dx+surface.offset.x, dy+surface.offset.y); + CocoaGlAssert(); + + glTexCoord2f((float)(sx+sw)/ bitmap.width, (float)(sy)/ bitmap.height); + CocoaGlAssert(); + glVertex2i(dx+w+surface.offset.x, dy+surface.offset.y); + CocoaGlAssert(); + + glTexCoord2f((float)(sx+sw) / bitmap.width, (float)(sy+sh)/ bitmap.height); + CocoaGlAssert(); + glVertex2i(dx+w+surface.offset.x, dy+h+surface.offset.y); + CocoaGlAssert(); + + glTexCoord2f((float)(sx)/ bitmap.width, (float)(sy+sh)/ bitmap.height); + CocoaGlAssert(); + glVertex2i(dx+surface.offset.x, dy+h+surface.offset.y); + CocoaGlAssert(); + } + + glEnd(); + CocoaGlAssert(); + + glDisable(GL_TEXTURE_2D); + CocoaGlAssert(); + } + + void Filter(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh) + { + printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__); + Stretch(display, surface, bitmap, dx, dy, sx, sy, w, h, sw, sh); + } + + void StretchDI(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh) + { + float s2dw,s2dh,d2sw,d2sh; + bool flipX = false, flipY = false; + + printf("CocoaOpenGLDisplayDriver: %s:%i\n", __FILE__, __LINE__); + if(Sgn(w) != Sgn(sw)) + { + w = Abs(w); + sw = Abs(sw); + flipX = true; + } + if(Sgn(h) != Sgn(sh)) + { + h = Abs(h); + sh = Abs(sh); + flipY = true; + } + + s2dw=(float)w / sw; + s2dh=(float)h / sh; + d2sw=(float)sw / w; + d2sh=(float)sh / h; + + //Clip against the edges of the source + if(sx<0) + { + dx+=(int)((0-sx) * s2dw); + w-=(int)((0-sx) * s2dw); + sw-=0-sx; + sx=0; + } + if(sy<0) + { + dy+=(int)((0-sy) * s2dh); + h-=(int)((0-sy) * s2dh); + + sh-=0-sy; + sy=0; + } + if(sx+sw>bitmap.width-1) + { + w-=(int)((sx+sw-(bitmap.width-1)-1)*s2dw); + sw-=sx+sw-(bitmap.width-1)-1; + } + if(sy+sh>(bitmap.height-1)) + { + h-=(int)((sy+sh-(bitmap.height-1)-1)*s2dh); + sh-=sy+sh-(bitmap.height-1)-1; + } + //Clip against the edges of the surfaceination + if(dxsurface.box.right) + { + //if(flip) sx+=(int)((dx+w-surface.box.right-1)*d2sw); + sw-=(int)((dx+w-surface.box.right-1)*d2sw); + w-=dx+w-surface.box.right-1; + } + if(dy+h>surface.box.bottom) + { + sh-=(int)((dy+h-surface.box.bottom-1)*d2sh); + h-=dy+h-surface.box.bottom-1; + } + if((w<=0)||(h<=0)||(sw<=0)||(sh<=0)) return; + + dx += surface.offset.x; + dy += surface.offset.y; + + if(bitmap.pixelFormat == pixelFormat888 && !bitmap.paletteShades) + { + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + CocoaGlAssert(); + glPixelStorei(GL_UNPACK_ROW_LENGTH, bitmap.stride); + CocoaGlAssert(); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, sx); + CocoaGlAssert(); + glPixelStorei(GL_UNPACK_SKIP_ROWS, sy); + CocoaGlAssert(); + glRasterPos2d(dx,dy); + CocoaGlAssert(); + //glPixelZoom(flipX ? -s2dw : s2dw, flipY ? s2dh : -s2dh); + CocoaGlAssert(); + glPixelZoom(s2dw, -s2dh); + CocoaGlAssert(); + glDrawPixels(sw,sh,GL_BGRA_EXT,GL_UNSIGNED_BYTE, bitmap.picture); + CocoaGlAssert(); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + CocoaGlAssert(); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + CocoaGlAssert(); + } + } + + void BlitDI(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h) + { + printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__); + //Clip against the edges of the source + if(sx<0) + { + dx+=-sx; + w-=-sx; + sx=0; + } + if(sy<0) + { + dy+=0-sy; + h-=0-sy; + sy=0; + } + if(sx+w>bitmap.width-1) + w-=sx+w-(bitmap.width-1)-1; + if(sy+h>bitmap.height-1) + h-=sy+h-(bitmap.height-1)-1; + //Clip against the edges of the surfaceination + if(dxsurface.box.right) + { + //if(flip) sx+=dx+w-surface.box.right-1; + w-=dx+w-surface.box.right-1; + } + if(dy+h>surface.box.bottom) + h-=dy+h-surface.box.bottom-1; + if((w<=0)||(h<=0)) + return; + + dx += surface.offset.x; + dy += surface.offset.y; + + if(bitmap.pixelFormat == pixelFormat888 && !bitmap.paletteShades) + { + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + CocoaGlAssert(); + glPixelStorei(GL_UNPACK_ROW_LENGTH, bitmap.stride); + CocoaGlAssert(); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, sx); + CocoaGlAssert(); + glPixelStorei(GL_UNPACK_SKIP_ROWS, sy); + CocoaGlAssert(); + glRasterPos2d(dx,dy); + CocoaGlAssert(); + glPixelZoom(1,-1); + CocoaGlAssert(); + glDrawPixels(w,h,GL_BGRA_EXT,GL_UNSIGNED_BYTE, bitmap.picture); + CocoaGlAssert(); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + CocoaGlAssert(); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + CocoaGlAssert(); + } + } + + void FilterDI(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh) + { + printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__); + StretchDI(display, surface, bitmap, dx, dy, sx, sy, w, h, sw, sh); + } + + void UnloadFont(DisplaySystem displaySystem, Font font) + { + printf("CocoaOpenGLDisplayDriver:UnloadFont %s:%i\n", __FILE__, __LINE__); + LFBDisplayDriver::UnloadFont(displaySystem, font); + } + + Font LoadFont(DisplaySystem displaySystem, char * faceName, float size, FontFlags flags) + { + Font font = LFBDisplayDriver::LoadFont(displaySystem, faceName, size, flags); + + printf("CocoaOpenGLDisplayDriver:LoadFont(%s):%p %s:%i\n", faceName, font, __FILE__, __LINE__); + + return font; + } + + void FontExtent(DisplaySystem displaySystem, Font font, char * text, int len, int * width, int * height) + { + printf("CocoaOpenGLDisplayDriver:FontExtent() %s:%i\n", __FILE__, __LINE__); + LFBDisplayDriver::FontExtent(displaySystem, font, text, len, width, height); + } + + void WriteText(Display display, Surface surface, int x, int y, char * text, int len) + { + SurfaceData surfaceData = surface.driverData; + SystemData systemData = display.displaySystem.driverData; + + printf("CocoaOpenGLDisplayDriver:WriteText %s:%i\n", __FILE__, __LINE__); + + systemData.loadingFont = true; + + if(surface.textOpacity) + { + int w, h; + FontExtent(display.displaySystem, surface.font, text, len, &w, &h); + Area(display, surface,x,y,x+w-1,y+h-1); + } + + surfaceData.writingText = true; + + glEnable(GL_TEXTURE_2D); + CocoaGlAssert(); + glColor4fv(surfaceData.foreground); + CocoaGlAssert(); + + LFBDisplayDriver::WriteText(display, surface, x, y, text, len); + surfaceData.writingText = false; + systemData.loadingFont = false; + + glDisable(GL_TEXTURE_2D); + CocoaGlAssert(); + } + + void TextFont(Display display, Surface surface, Font font) + { + LFBDisplayDriver::TextFont(display, surface, font); + printf("CocoaOpenGLDisplayDriver:TextFont %s:%i\n", __FILE__, __LINE__); + } + + void TextOpacity(Display display, Surface surface, bool opaque) + { + SurfaceData surfaceData = surface.driverData; + surfaceData.opaqueText = opaque; + printf("CocoaOpenGLDisplayDriver:TextOpacity(%i) %s:%i\n", opaque, __FILE__, __LINE__); + } + + void TextExtent(Display display, Surface surface, char * text, int len, int * width, int * height) + { + SurfaceData surfaceData = surface.driverData; + SystemData systemData = display.displaySystem.driverData; + systemData.loadingFont = true; + FontExtent(display.displaySystem, surfaceData.font, text, len, width, height); + systemData.loadingFont = false; + + printf("CocoaOpenGLDisplayDriver:TextExtent STUB! %s:%i\n", __FILE__, __LINE__); + } + + void DrawingChar(Display display, Surface surface, char character) + { + printf("CocoaOpenGLDisplayDriver:DrawingChar STUB! %s:%i\n", __FILE__, __LINE__); + + } + + void LineStipple(Display display, Surface surface, uint32 stipple) + { + printf("CocoaOpenGLDisplayDriver:LineStipple %s:%i\n", __FILE__, __LINE__); + if(stipple) + { + glLineStipple(1, (uint16)stipple); + CocoaGlAssert(); + glEnable(GL_LINE_STIPPLE); + CocoaGlAssert(); + } + else + { + glDisable(GL_LINE_STIPPLE); + CocoaGlAssert(); + } + printf("glGetError():%i\n", glGetError()); + } + + void SetRenderState(Display display, RenderState state, uint value) + { + printf("CocoaOpenGLDisplayDriver:SetRenderState STUB! %s:%i\n", __FILE__, __LINE__); + switch(state) + { + case antiAlias: + if(value) + glEnable(GL_MULTISAMPLE_ARB); + else + glDisable(GL_MULTISAMPLE_ARB); + CocoaGlAssert(); + break; + case fillMode: + glPolygonMode(GL_FRONT_AND_BACK, ((FillModeValue)value == solid) ? GL_FILL : GL_LINE); + CocoaGlAssert(); + break; + case depthTest: + if(value) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST); + CocoaGlAssert(); + break; + case depthWrite: + if(value) glDepthMask((byte)bool::true); else glDepthMask((byte)bool::false); + CocoaGlAssert(); + break; + case fogColor: + { + float color[4] = { ((Color)value).r/255.0f, ((Color)value).g/255.0f, ((Color)value).b/255.0f, 1.0f }; + glFogfv(GL_FOG_COLOR, (float *)&color); + CocoaGlAssert(); + break; + } + case fogDensity: + glFogf(GL_FOG_DENSITY, *(float *)(void *)&value); + CocoaGlAssert(); + break; + case blend: + if(value) glEnable(GL_BLEND); else glDisable(GL_BLEND); + CocoaGlAssert(); + break; + case ambient: + { + float ambient[4] = { ((Color)value).r/255.0f, ((Color)value).g/255.0f, ((Color)value).b/255.0f, 1.0f }; + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient); + CocoaGlAssert(); + break; + } + case alphaWrite: + { + if(value) glColorMask(1,1,1,1); else glColorMask(1,1,1,0); + CocoaGlAssert(); + break; + } + case vSync: + { + break; + } + } + } + + void SetLight(Display display, int id, Light light) + { + printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__); + if(light != null) + { + Object lightObject = light.lightObject; + float position[4] = { 0, 0, 0, 0 }; + float color[4] = { 0, 0, 0, 1 }; + + glEnable(GL_LIGHT0 + id); + CocoaGlAssert(); + + if(!light.multiplier) light.multiplier = 1.0f; + + color[0] = light.diffuse.r * light.multiplier; + color[1] = light.diffuse.g * light.multiplier; + color[2] = light.diffuse.b * light.multiplier; + glLightfv(GL_LIGHT0 + id, GL_DIFFUSE, color); + + color[0] = light.ambient.r * light.multiplier; + color[1] = light.ambient.g * light.multiplier; + color[2] = light.ambient.b * light.multiplier; + glLightfv(GL_LIGHT0 + id, GL_AMBIENT, color); + color[0] = light.specular.r * light.multiplier; + color[1] = light.specular.g * light.multiplier; + color[2] = light.specular.b * light.multiplier; + glLightfv(GL_LIGHT0 + id, GL_SPECULAR,color); + + if(lightObject) + { + Vector3D positionVector; + if(light.flags.spot) + { + if(lightObject.flags.root || !lightObject.parent) + { + positionVector = lightObject.transform.position; + positionVector.Subtract(positionVector, display.display3D.camera.cPosition); + } + else + { + positionVector.MultMatrix(lightObject.transform.position, lightObject.parent.matrix); + if(display.display3D.camera) + positionVector.Subtract(positionVector, display.display3D.camera.cPosition); + } + position[3] = 1; + } + else + { + if(!light.direction.x && !light.direction.y && !light.direction.z) + { + Vector3Df vector { 0,0,-1 }; + Matrix mat; + mat.RotationQuaternion(light.orientation); + positionVector.MultMatrixf(vector, mat); + } + else + { + positionVector = light.direction; + position[3] = 1; + } + } + + position[0] = (float)positionVector.x; + position[1] = (float)positionVector.y; + position[2] = (float)positionVector.z; + + glLightfv(GL_LIGHT0 + id, GL_POSITION, position); + CocoaGlAssert(); + + if(light.flags.attenuation) + { + glLightf(GL_LIGHT0 + id, GL_CONSTANT_ATTENUATION, light.Kc); + CocoaGlAssert(); + glLightf(GL_LIGHT0 + id, GL_LINEAR_ATTENUATION, light.Kl); + CocoaGlAssert(); + glLightf(GL_LIGHT0 + id, GL_QUADRATIC_ATTENUATION, light.Kq); + CocoaGlAssert(); + } + + if(light.flags.spot) + { + float exponent = 0; + #define MAXLIGHT 0.9 + float direction[4] = { (float)light.direction.x, (float)light.direction.y, (float)light.direction.z, 1 }; + // Figure out exponent out of the hot spot + exponent = (float)(log(MAXLIGHT) / log(cos((light.hotSpot / 2)))); + + glLightfv(GL_LIGHT0 + id, GL_SPOT_DIRECTION, direction); + CocoaGlAssert(); + glLightf(GL_LIGHT0 + id, GL_SPOT_CUTOFF, (float)(light.fallOff / 2)); + CocoaGlAssert(); + glLightf(GL_LIGHT0 + id, GL_SPOT_EXPONENT, exponent); + CocoaGlAssert(); + } + } + else + { + Vector3Df vector { 0,0,-1 }; + Vector3Df direction; + Matrix mat; + + mat.RotationQuaternion(light.orientation); + direction.MultMatrix(vector, mat); + + position[0] = direction.x; + position[1] = direction.y; + position[2] = direction.z; + + glLightfv(GL_LIGHT0 + id, GL_POSITION, position); + CocoaGlAssert(); + } + } + else + glDisable(GL_LIGHT0 + id); + CocoaGlAssert(); + } + + void SetCamera(Display display, Surface surface, Camera camera) + { + printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__); + if(camera) + { + int left = surface.box.left + surface.offset.x; + int top = surface.box.top + surface.offset.y; + int right = surface.box.right + surface.offset.x; + int bottom = surface.box.bottom + surface.offset.y; + float origX = surface.offset.x + camera.origin.x; + float origY = surface.offset.y + camera.origin.y; + int x = left; + int y = display.height - bottom - 1; + int w = right - left + 1; + int h = bottom - top + 1; + + // *** ViewPort *** + glViewport(x, y, w, h); + + // *** Projection Matrix *** + if(!display.display3D.camera) + glPushMatrix(); + else + glMatrixMode(GL_PROJECTION); + if(display.display3D.collectingHits) + { + float pickX = display.display3D.pickX + surface.offset.x; + float pickY = display.height - (display.display3D.pickY + surface.offset.y) - 1; + Matrix pickMatrix = + { + { + w / display.display3D.pickWidth, 0, 0, 0, + 0, h / display.display3D.pickHeight, 0, 0, + 0, 0, 1, 0, + (w + 2.0f * (x - pickX)) / display.display3D.pickWidth, + (h + 2.0f * (y - pickY)) / display.display3D.pickHeight, 0, 1 + } + }; + glLoadMatrixd(pickMatrix.array); + } + else + glLoadIdentity(); + glFrustum( + (left - origX) * camera.zMin / camera.focalX, + (right - origX) * camera.zMin / camera.focalX, + (bottom - origY) * camera.zMin / camera.focalY, + (top - origY) * camera.zMin / camera.focalY, + camera.zMin, camera.zMax); + + glDisable(GL_BLEND); + + // *** Z Inverted Identity Matrix *** + glMatrixMode(GL_MODELVIEW); + if(!display.display3D.camera) + glPushMatrix(); + + glLoadIdentity(); + glScalef(1.0f, 1.0f, -1.0f); + + // *** View Matrix *** + glMultMatrixd(camera.viewMatrix.array); + + // *** Lights *** + // ... + + glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHTING); + glShadeModel(GL_SMOOTH); + glDepthMask((byte)bool::true); + + glEnable(GL_MULTISAMPLE_ARB); + } + else if(display.display3D.camera) + { + glViewport(0,0,display.width,display.height); + + glDisable(GL_CULL_FACE); + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + glDisable(GL_FOG); + glDisable(GL_TEXTURE_2D); + glShadeModel(GL_FLAT); + glEnable(GL_BLEND); + glDisable(GL_MULTISAMPLE_ARB); + + // *** Restore 2D MODELVIEW Matrix *** + glPopMatrix(); + + // *** Restore 2D PROJECTION Matrix *** + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + } + + if(glBindBufferARB) + glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + printf("glGetError():%i\n", glGetError()); + } + + void ApplyMaterial(Display display, Material material, Mesh mesh) + { + printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__); + // Basic Properties + if(material.flags.doubleSided) + { + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, !material.flags.singleSideLight); + glDisable(GL_CULL_FACE); + } + else + { + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, bool::false); + glEnable(GL_CULL_FACE); + } + + // Fog + if(material.flags.noFog) + glDisable(GL_FOG); + else + glEnable(GL_FOG); + + // Maps + if(material.baseMap && mesh.texCoords) + { + Bitmap map = material.baseMap; + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, (uint)map.driverData); + + if(material.flags.tile) + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + } + else + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + } + } + else + glDisable(GL_TEXTURE_2D); + + if(mesh.flags.colors) + { + glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); + glEnable(GL_COLOR_MATERIAL); + } + else + { + glDisable(GL_COLOR_MATERIAL); + { + float color[4] = { material.diffuse.r, material.diffuse.g, material.diffuse.b, material.opacity }; + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color); + } + { + float color[4] = { material.ambient.r, material.ambient.g, material.ambient.b, 0 }; + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color); + } + } + { + float color[4] = { material.specular.r, material.specular.g, material.specular.b, 0 }; + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color); + } + { + float color[4] = { material.emissive.r, material.emissive.g, material.emissive.b, 0 }; + glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, color); + } + + glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &material.power); + } + + void FreeMesh(DisplaySystem displaySystem, Mesh mesh) + { + MeshData meshData = mesh.data; + printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__); + if(meshData) + { + if(!mesh.flags.vertices) + { + if(meshData.vertices) + { + glDeleteBuffersARB(1, &meshData.vertices); + meshData.vertices = 0; + } + delete mesh.vertices; + } + if(!mesh.flags.normals) + { + if(meshData.normals) + { + glDeleteBuffersARB(1, &meshData.normals); + meshData.normals = 0; + } + delete mesh.normals; + } + if(!mesh.flags.texCoords1) + { + if(meshData.texCoords) + { + glDeleteBuffersARB(1, &meshData.texCoords); + meshData.texCoords = 0; + } + delete mesh.texCoords; + } + if(!mesh.flags.texCoords2) + { + if(meshData.texCoords2) + { + glDeleteBuffersARB(1, &meshData.texCoords2); + meshData.texCoords2 = 0; + } + } + if(!mesh.flags.colors) + { + if(meshData.colors) + { + glDeleteBuffersARB(1, &meshData.colors); + meshData.colors = 0; + } + } + if(!mesh.flags) + { + delete meshData; + mesh.data = null; + } + } + } + + bool AllocateMesh(DisplaySystem displaySystem, Mesh mesh) + { + bool result = false; + printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__); + + if(!mesh.data) + mesh.data = MeshData { }; + + if(mesh.data) + { + MeshData meshData = mesh.data; + + if(mesh.flags.vertices && !meshData.vertices && !mesh.vertices) + { + mesh.vertices = mesh.flags.doubleVertices ? (Vector3Df *)new Vector3D[mesh.nVertices] : new Vector3Df[mesh.nVertices]; + if(glGenBuffersARB) + glGenBuffersARB(1, &meshData.vertices); + } + if(mesh.flags.normals && !meshData.normals && !mesh.normals) + { + if(glGenBuffersARB) + glGenBuffersARB( 1, &meshData.normals); + mesh.normals = mesh.flags.doubleNormals ? (Vector3Df *)new Vector3D[mesh.nVertices] : new Vector3Df[mesh.nVertices]; + } + if(mesh.flags.texCoords1 && !meshData.texCoords && !mesh.texCoords) + { + if(glGenBuffersARB) + glGenBuffersARB( 1, &meshData.texCoords); + mesh.texCoords = new Pointf[mesh.nVertices]; + } + if(mesh.flags.colors && !meshData.colors && !mesh.colors) + { + if(glGenBuffersARB) + glGenBuffersARB( 1, &meshData.colors); + mesh.colors = new ColorRGBAf[mesh.nVertices]; + } + result = true; + } + return result; + } + + void UnlockMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags) + { + MeshData meshData = mesh.data; + printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__); + + if(!flags) flags = mesh.flags; + + if(glGenBuffersARB) + { + if(!(flags.vertices) || meshData.vertices) + { + glBindBufferARB( GL_ARRAY_BUFFER_ARB, meshData.vertices); + glBufferDataARB( GL_ARRAY_BUFFER_ARB, mesh.nVertices * (mesh.flags.doubleVertices ? sizeof(Vector3D) : sizeof(Vector3Df)), mesh.vertices, GL_STATIC_DRAW_ARB ); + } + + if(!(flags.normals) || meshData.normals) + { + glBindBufferARB( GL_ARRAY_BUFFER_ARB, meshData.normals); + glBufferDataARB( GL_ARRAY_BUFFER_ARB, mesh.nVertices * (mesh.flags.doubleNormals ? sizeof(Vector3D) : sizeof(Vector3Df)), mesh.normals, GL_STATIC_DRAW_ARB ); + } + + if(!(flags.texCoords1) || meshData.texCoords) + { + glBindBufferARB( GL_ARRAY_BUFFER_ARB, meshData.texCoords); + glBufferDataARB( GL_ARRAY_BUFFER_ARB, mesh.nVertices * sizeof(Pointf), mesh.texCoords, GL_STATIC_DRAW_ARB ); + } + + if(!(flags.colors) || meshData.colors) + { + glBindBufferARB( GL_ARRAY_BUFFER_ARB, meshData.colors); + glBufferDataARB( GL_ARRAY_BUFFER_ARB, mesh.nVertices * sizeof(ColorRGBAf), mesh.colors, GL_STATIC_DRAW_ARB ); + } + + glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0); + } + } + + bool LockMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags) + { + bool result = true; + printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__); + return result; + } + + void FreeIndices(DisplaySystem displaySystem, IndexData indexData) + { + printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__); + + if(indexData) + { + if(indexData.buffer) + glDeleteBuffersARB(1, &indexData.buffer); + delete indexData.indices; + delete indexData; + } + } + + void * AllocateIndices(DisplaySystem displaySystem, int nIndices, bool indices32bit) + { + IndexData indexData = IndexData { }; + printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__); + if(indexData) + { + indexData.indices = (void *)(indices32bit ? new uint32[nIndices] : new uint16[nIndices]); + if(glGenBuffersARB) + glGenBuffersARB( 1, &indexData.buffer); + indexData.nIndices = nIndices; + } + return indexData; + } + + void UnlockIndices(DisplaySystem displaySystem, IndexData indexData, bool indices32bit, int nIndices) + { + printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__); + if(glGenBuffersARB) + { + glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, indexData.buffer); + glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, nIndices * (indices32bit ? sizeof(uint32) : sizeof(uint16)), + indexData.indices, GL_STATIC_DRAW_ARB); + glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0); + } + } + + uint16 * LockIndices(DisplaySystem displaySystem, IndexData indexData) + { + printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__); + + return indexData.indices; + } + + void SelectMesh(Display display, Mesh mesh) + { + printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__); + + if(display.display3D.mesh && glUnlockArraysEXT) + glUnlockArraysEXT(); + + if(mesh) + { + DisplayData displayData = display.driverData; + Mesh meshData = mesh.data; + + // *** Vertex Stream *** + glEnableClientState(GL_VERTEX_ARRAY); + if(!display.display3D.collectingHits && meshData) + { + if(glBindBufferARB) + glBindBufferARB(GL_ARRAY_BUFFER_ARB, (long)meshData.vertices); + glVertexPointer(3, mesh.flags.doubleVertices ? GL_DOUBLE : GL_FLOAT, 0, glBindBufferARB ? null : mesh.vertices); + + // *** Normals Stream *** + if(mesh.normals) + { + glEnableClientState(GL_NORMAL_ARRAY); + if(glBindBufferARB) + glBindBufferARB(GL_ARRAY_BUFFER_ARB, (long)meshData.normals); + glNormalPointer(mesh.flags.doubleNormals ? GL_DOUBLE : GL_FLOAT, 0, glBindBufferARB ? null : mesh.normals); + } + else + { + glDisableClientState(GL_NORMAL_ARRAY); + } + + // *** Texture Coordinates Stream *** + if(mesh.texCoords) + { + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + if(glBindBufferARB) + glBindBufferARB( GL_ARRAY_BUFFER_ARB, (long)meshData.texCoords); + glTexCoordPointer(2, GL_FLOAT, 0, glBindBufferARB ? null : mesh.texCoords); + } + else + { + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } + + // *** Color Stream *** + if(mesh.colors) + { + glEnableClientState(GL_COLOR_ARRAY); + if(glBindBufferARB) + glBindBufferARB( GL_ARRAY_BUFFER_ARB, (long)meshData.colors); + glColorPointer(4, GL_FLOAT, 0, glBindBufferARB ? null : mesh.colors); + } + else + { + glDisableClientState(GL_COLOR_ARRAY); + } + } + else + { + if(glBindBufferARB) + glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0); + glVertexPointer(3,mesh.flags.doubleVertices ? GL_DOUBLE : GL_FLOAT,0,mesh.vertices); + if(mesh.normals && !display.display3D.collectingHits) + { + glEnableClientState(GL_NORMAL_ARRAY); + glNormalPointer(mesh.flags.doubleNormals ? GL_DOUBLE : GL_FLOAT, 0, mesh.normals); + } + else + glDisableClientState(GL_NORMAL_ARRAY); + if(mesh.texCoords && !display.display3D.collectingHits) + { + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, 0, mesh.texCoords); + } + else + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + if(mesh.colors && !display.display3D.collectingHits) + { + glEnableClientState(GL_COLOR_ARRAY); + glColorPointer(4, GL_FLOAT, 0, mesh.colors); + } + else + glDisableClientState(GL_COLOR_ARRAY); + } + + if(glLockArraysEXT) glLockArraysEXT(0, mesh.nVertices); + } + else if(glBindBufferARB) + glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + } + + void DrawPrimitives(Display display, PrimitiveSingle * primitive, Mesh mesh) + { + DisplayData displayData = display.driverData; + printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__); + + if(primitive->type.vertexRange) + glDrawArrays(primitiveTypes[primitive->type.primitiveType], primitive->first, primitive->nVertices); + else + { + // *** Hoping the data won't be uploaded at all (Won't really work if another group of the mesh is using the mesh ) *** + // HACK TO SPEED THINGS UP... + if(primitive->nIndices < (mesh.nVertices >> 2) && !primitive->type.indices32bit) + { + int c; + glBegin(primitiveTypes[primitive->type.primitiveType]); + if(primitive->data) + { + IndexData indexData = primitive->data; + MeshFeatures flags = mesh.flags; + for(c = 0; c < primitive->nIndices; c++) + { + short index = ((short *) indexData.indices)[c]; + if(flags.normals) glNormal3fv((float *)&mesh.normals[index]); + if(flags.texCoords1) glTexCoord2fv((float *)&mesh.texCoords[index]); + if(flags.colors) glColor4fv((float *)&mesh.colors[index]); + glVertex3fv((float *)&mesh.vertices[index]); + } + } + glEnd(); + } + else + { + IndexData indexData = primitive->data; + + if(!display.display3D.collectingHits && glBindBufferARB && indexData) + { + glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indexData.buffer); + glDrawElements(primitiveTypes[primitive->type.primitiveType], primitive->nIndices, + primitive->type.indices32bit ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0); + glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); + } + else if(indexData) + glDrawElements(primitiveTypes[primitive->type.primitiveType], primitive->nIndices, + primitive->type.indices32bit ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, indexData.indices); + else + glDrawElements(primitiveTypes[primitive->type.primitiveType], primitive->nIndices, + primitive->type.indices32bit ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, primitive->indices); + } + } + } + + void PushMatrix(Display display) + { + printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__); + glPushMatrix(); + } + + void PopMatrix(Display display, bool setMatrix) + { + printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__); + glPopMatrix(); + } + + void SetTransform(Display display, Matrix transMatrix, bool viewSpace, bool useCamera) + { + Matrix matrix = transMatrix; + Camera camera = useCamera ? display.display3D.camera : null; + + printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__); + if(viewSpace) + { + glLoadIdentity(); + glScalef(1.0f, 1.0f, -1.0f); + } + else if(camera) + { + glTranslated( + matrix.m[3][0] - camera.cPosition.x, + matrix.m[3][1] - camera.cPosition.y, + matrix.m[3][2] - camera.cPosition.z); + } + else + glTranslated( + matrix.m[3][0], + matrix.m[3][1], + matrix.m[3][2]); + + matrix.m[3][0] = 0; + matrix.m[3][1] = 0; + matrix.m[3][2] = 0; + + glMultMatrixd(matrix.array); + } +} + +public void UseSingleGLContext(bool useSingle) +{ + printf("CocoaOpenGLDisplayDriver: STUB! %s:%i\n", __FILE__, __LINE__); + useSingleGLContext = useSingle; +} + diff --git a/ecere/src/gfx/drivers/LFBDisplayDriver.ec b/ecere/src/gfx/drivers/LFBDisplayDriver.ec index 5bb2965..322216e 100644 --- a/ecere/src/gfx/drivers/LFBDisplayDriver.ec +++ b/ecere/src/gfx/drivers/LFBDisplayDriver.ec @@ -4,6 +4,7 @@ namespace gfx::drivers; #define ECERE_NOTRUETYPE #endif +#undef __BLOCKS__ #define uint _uint #if !defined(ECERE_NOTRUETYPE) #include diff --git a/ecere/src/gfx/drivers/NCursesDisplayDriver.ec b/ecere/src/gfx/drivers/NCursesDisplayDriver.ec index cb30cc0..2047275 100644 --- a/ecere/src/gfx/drivers/NCursesDisplayDriver.ec +++ b/ecere/src/gfx/drivers/NCursesDisplayDriver.ec @@ -2,6 +2,8 @@ namespace gfx::drivers; import "instance" +#undef __BLOCKS__ + #if (defined(__unix__) || defined(__APPLE__)) && !defined(__DOS__) #define bool CursesBool diff --git a/ecere/src/gfx/drivers/OpenGLDisplayDriver.ec b/ecere/src/gfx/drivers/OpenGLDisplayDriver.ec index b14a720..8a0f01f 100644 --- a/ecere/src/gfx/drivers/OpenGLDisplayDriver.ec +++ b/ecere/src/gfx/drivers/OpenGLDisplayDriver.ec @@ -3,7 +3,7 @@ namespace gfx::drivers; // OpenGL Extensions -#if defined(__unix__) || defined(__APPLE__) +#if defined(__unix__) #if !defined(__MINGW32__) #define GL_GLEXT_PROTOTYPES @@ -53,6 +53,10 @@ namespace gfx::drivers; #endif +#if defined(__APPLE__) +#include +#endif + #if defined(__WIN32__) || defined(__unix__) || defined(__APPLE__) #if defined(__WIN32__) @@ -66,7 +70,7 @@ namespace gfx::drivers; import "Display" -#if defined(__unix__) || defined(__APPLE__) +#if defined(__unix__) import "XInterface" #endif @@ -441,11 +445,11 @@ class OpenGLDisplayDriver : DisplayDriver if(useSingleGLContext) return true; #if defined(__WIN32__) wglMakeCurrent(oglSystem.hdc, oglSystem.glrc); - #else + #elif defined(__unix__) //if(previous) return true; // printf("Making SYSTEM current\n"); /*#if defined(__APPLE__) - glXMakeCurrent(xGlobalDisplay, displaySystem.window, oglSystem.glContext); + //glXMakeCurrent(xGlobalDisplay, displaySystem.window, oglSystem.glContext); #else*/ glXMakeCurrent(xGlobalDisplay, oglSystem.dummyGLXPixmap /*displaySystem.window /*DefaultRootWindow(xGlobalDisplay)*/, oglSystem.glContext); //#endif @@ -459,7 +463,7 @@ class OpenGLDisplayDriver : DisplayDriver if(useSingleGLContext) return; #if defined(__WIN32__) wglMakeCurrent(null, null); - #else + #elif defined(__unix__) // printf("Making NULL current\n"); glXMakeCurrent(xGlobalDisplay, None, null); // previous = null; @@ -474,7 +478,7 @@ class OpenGLDisplayDriver : DisplayDriver if(useSingleGLContext) return true; #if defined(__WIN32__) wglMakeCurrent(oglDisplay.hdc, oglDisplay.glrc); - #else + #elif defined(__unix__) // if(previous) glXMakeCurrent(xGlobalDisplay, None, null); // printf(" Making DISPLAY current\n"); glXMakeCurrent(xGlobalDisplay, (int)display.window, oglDisplay.glContext); @@ -515,7 +519,7 @@ class OpenGLDisplayDriver : DisplayDriver if(oglDisplay.memDC) DeleteDC(oglDisplay.memDC); if(oglDisplay.memBitmap) DeleteObject(oglDisplay.memBitmap); - #else + #elif defined(__unix__) if(oglDisplay.shapePixmap) XFreePixmap(xGlobalDisplay, oglDisplay.shapePixmap); if(oglDisplay.pixmap) @@ -674,7 +678,7 @@ class OpenGLDisplayDriver : DisplayDriver } } } - #else + #elif defined(__unix__) int attrList[] = { #ifndef ECERE_MINIGLX @@ -697,12 +701,7 @@ class OpenGLDisplayDriver : DisplayDriver if(oglSystem.glContext) { //printf("Got a Context\n"); -/*#if defined(__APPLE__) - glXMakeCurrent(xGlobalDisplay, displaySystem.window, oglSystem.glContext); -#else -*/ glXMakeCurrent(xGlobalDisplay, oglSystem.dummyGLXPixmap /*displaySystem.window /*DefaultRootWindow(xGlobalDisplay)*/, oglSystem.glContext); -//#endif // Setup Extensions @@ -733,7 +732,7 @@ class OpenGLDisplayDriver : DisplayDriver ReleaseDC(oglSystem.hwnd, oglSystem.hdc); DestroyWindow(oglSystem.hwnd); - #else + #elif defined(__unix__) if(oglSystem.visualInfo) { @@ -776,7 +775,7 @@ class OpenGLDisplayDriver : DisplayDriver } else ReleaseDC(display.window, oglDisplay.hdc); - #else + #elif defined(__unix__) XVisualInfo * visualInfo = null; /* int attrib[] = @@ -877,7 +876,7 @@ class OpenGLDisplayDriver : DisplayDriver if(!useSingleGLContext) #if defined(__WIN32__) wglMakeCurrent(null, null); - #else + #elif defined(__unix__) glXMakeCurrent(xGlobalDisplay, None, null); #endif @@ -1049,7 +1048,7 @@ class OpenGLDisplayDriver : DisplayDriver } ReleaseDC(display.window, hdc); } -#else +#elif defined(__unix__) int attrib[] = { GLX_DOUBLEBUFFER, True, @@ -1209,7 +1208,7 @@ class OpenGLDisplayDriver : DisplayDriver CreateDisplay(display); #if defined(__WIN32__) wglMakeCurrent(oglDisplay.hdc, oglDisplay.glrc); -#else +#elif defined(__unix__) glXMakeCurrent(xGlobalDisplay, (int)display.window, oglDisplay.glContext); #endif } @@ -1336,7 +1335,7 @@ class OpenGLDisplayDriver : DisplayDriver */ ReleaseDC(0, hdc); -#else +#elif defined(__unix__) XTransform transform = { { @@ -1363,7 +1362,7 @@ class OpenGLDisplayDriver : DisplayDriver #if defined(__WIN32__) //wglSwapLayerBuffers(oglDisplay.hdc,WGL_SWAP_MAIN_PLANE); SwapBuffers(oglDisplay.hdc); -#else +#elif defined(__unix__) glXSwapBuffers(xGlobalDisplay, (int)display.window); #endif } diff --git a/ecere/src/gui/GuiApplication.ec b/ecere/src/gui/GuiApplication.ec index 3740d63..28dbf41 100644 --- a/ecere/src/gui/GuiApplication.ec +++ b/ecere/src/gui/GuiApplication.ec @@ -67,7 +67,9 @@ typedef struct in_addr IN_ADDR; import "network" #endif -#if defined(__unix__) || defined(__APPLE__) +#if defined(__APPLE__) +import "CocoaInterface" +#elif defined(__unix__) import "XInterface" #endif @@ -564,6 +566,14 @@ public class GuiApplication : Application else defaultDriver = "Win32Console"; } + #elif defined(__APPLE__) + { + if (driver) { + defaultDriver = driver; + } else { + defaultDriver = "CocoaOpenGL"; + } + } #else if(this.isGUIApp && !textMode) { @@ -596,7 +606,11 @@ public class GuiApplication : Application SwitchMode(true, "SVGA", Res640x480, PixelFormat8, 0, null, true); #endif - #if defined(__unix__) || defined(__APPLE__) + #if defined(__APPLE__) + SwitchMode(true, "CocoaOpenGL", 0, 0, 0, null, true); + #endif + + #if defined(__unix__) #if defined(ECERE_MINIGLX) SwitchMode(true, "OpenGL", 0, 0, 0, null, true); #endif diff --git a/ecere/src/gui/Key.ec b/ecere/src/gui/Key.ec index 8ae559b..563140f 100644 --- a/ecere/src/gui/Key.ec +++ b/ecere/src/gui/Key.ec @@ -6,7 +6,7 @@ public class Key { public: KeyCode code:16; - bool shift:1, ctrl:1, alt:1; + bool shift:1, ctrl:1, alt:1, cmd:1; Modifiers modifiers:16:16; property SmartKey { @@ -263,7 +263,7 @@ public class Modifiers return 0; }; - public bool shift:1, ctrl:1, alt:1, left:1, middle:1, right:1, isActivate:1, isSideEffect:1, closingDropDown:1; + public bool shift:1, ctrl:1, alt:1, cmd:1, left:1, middle:1, right:1, isActivate:1, isSideEffect:1, closingDropDown:1; }; public enum PredefinedKey : Key diff --git a/ecere/src/gui/drivers/NCursesInterface.ec b/ecere/src/gui/drivers/NCursesInterface.ec index 4af1697..939d695 100644 --- a/ecere/src/gui/drivers/NCursesInterface.ec +++ b/ecere/src/gui/drivers/NCursesInterface.ec @@ -4,6 +4,7 @@ import "instance" #if (defined(__unix__) || defined(__APPLE__)) && !defined(__DOS__) +#undef __BLOCKS__ #define DBLCLICK_DELAY 0.3 // seconds #define DBLCLICK_DELTA 1 diff --git a/ecere/src/gui/drivers/XInterface.ec b/ecere/src/gui/drivers/XInterface.ec index 62e11a2..27fa67f 100644 --- a/ecere/src/gui/drivers/XInterface.ec +++ b/ecere/src/gui/drivers/XInterface.ec @@ -7,6 +7,7 @@ import "OpenGLDisplayDriver" #if (defined(__unix__) || defined(__APPLE__)) && !defined(ECERE_MINIGLX) +#undef __BLOCKS__ default: #define uint _uint #define property _property diff --git a/ecere/src/gui/drivers/cocoa/CocoaDispatch.ec b/ecere/src/gui/drivers/cocoa/CocoaDispatch.ec new file mode 100644 index 0000000..102894e --- /dev/null +++ b/ecere/src/gui/drivers/cocoa/CocoaDispatch.ec @@ -0,0 +1,218 @@ +namespace gui::drivers; + +// Bridges Objective-C callbacks to eC. +import "Window" + +default: + +void CocoaDispatch_UpdateRootWindow(Window window) +{ + window.Update(null); +} + +void CocoaDispatch_ExternalPosition(Window window, int x, int y, int width, int height) +{ + window.ExternalPosition(x, y, width, height); +} + +bool CocoaDispatch_OnCreate(Window window) +{ + return window.OnCreate(); +} + +void CocoaDispatch_OnDestroy(Window window) +{ + return window.OnDestroy(); +} + +void CocoaDispatch_OnDestroyed(Window window) +{ + return window.OnDestroyed(); +} + +bool CocoaDispatch_OnClose(Window window, bool parentClosing) +{ + return window.OnClose(parentClosing); +} + +bool CocoaDispatch_OnStateChange(Window window, WindowState state, Modifiers mods) +{ + return window.OnStateChange(state, mods); +} + +bool CocoaDispatch_OnPostCreate(Window window) +{ + return window.OnPostCreate(); +} + +bool CocoaDispatch_OnMoving(Window window, int *x, int *y, int w, int h) +{ + return window.OnMoving(x, y, w, h); +} + +bool CocoaDispatch_OnResizing(Window window, int *width, int *height) +{ + return window.OnResizing(width, height); +} + +void CocoaDispatch_OnResize(Window window, int width, int height) +{ + window.OnResize(width, height); +} + +void CocoaDispatch_OnPosition(Window window, int x, int y, int width, int height) +{ + window.OnPosition(x, y, width, height); +} + +bool CocoaDispatch_OnLoadGraphics(Window window) +{ + return window.OnLoadGraphics(); +} + +void CocoaDispatch_OnApplyGraphics(Window window) +{ + window.OnApplyGraphics(); +} + +void CocoaDispatch_OnUnloadGraphics(Window window) +{ + window.OnUnloadGraphics(); +} + +void CocoaDispatch_Update(Window window) +{ + window.Update(null); +} + +bool CocoaDispatch_OnActivate(Window window, bool active, Window previous, bool *goOnWithActivation, bool direct) +{ + return window.OnActivate(active, previous, goOnWithActivation, direct); +} + +void CocoaDispatch_OnActivateClient(Window window, Window client, Window previous) +{ + window.OnActivateClient(client, previous); +} + +bool CocoaDispatch_OnKeyDown(Window window, Key key, unichar ch) +{ + return window.OnKeyDown(key, ch); +} + +bool CocoaDispatch_OnKeyUp(Window window, Key key, unichar ch) +{ + return window.OnKeyUp(key, ch); +} + +bool CocoaDispatch_OnKeyHit(Window window, Key key, unichar ch) +{ + return window.OnKeyHit(key, ch); +} + +bool CocoaDispatch_OnSysKeyDown(Window window, Key key, unichar ch) +{ + return window.OnSysKeyDown(key, ch); +} + +bool CocoaDispatch_OnSysKeyUp(Window window, Key key, unichar ch) +{ + return window.OnSysKeyUp(key, ch); +} + +bool CocoaDispatch_OnSysKeyHit(Window window, Key key, unichar ch) +{ + return window.OnSysKeyHit(key, ch); +} + +bool CocoaDispatch_OnMouseOver(Window window, int x, int y, Modifiers mods) +{ + return window.OnMouseOver(x, y, mods); +} + +bool CocoaDispatch_OnMouseLeave(Window window, Modifiers mods) +{ + return window.OnMouseLeave(mods); +} + +bool CocoaDispatch_OnMouseMove(Window window, int x, int y, Modifiers mods) +{ + return window.OnMouseMove(x, y, mods); +} + +bool CocoaDispatch_OnLeftButtonDown(Window window, int x, int y, Modifiers mods) +{ + return window.OnLeftButtonDown(x, y, mods); +} + +bool CocoaDispatch_OnLeftButtonUp(Window window, int x, int y, Modifiers mods) +{ + return window.OnLeftButtonUp(x, y, mods); +} + +bool CocoaDispatch_OnLeftDoubleClick(Window window, int x, int y, Modifiers mods) +{ + return window.OnLeftDoubleClick(x, y, mods); +} + +bool CocoaDispatch_OnRightButtonDown(Window window, int x, int y, Modifiers mods) +{ + return window.OnRightButtonDown(x, y, mods); +} + +bool CocoaDispatch_OnRightButtonUp(Window window, int x, int y, Modifiers mods) +{ + return window.OnRightButtonUp(x, y, mods); +} + +bool CocoaDispatch_OnRightDoubleClick(Window window, int x, int y, Modifiers mods) +{ + return window.OnRightDoubleClick(x, y, mods); +} + +bool CocoaDispatch_OnMiddleButtonDown(Window window, int x, int y, Modifiers mods) +{ + return window.OnMiddleButtonDown(x, y, mods); +} + +bool CocoaDispatch_OnMiddleButtonUp(Window window, int x, int y, Modifiers mods) +{ + return window.OnMiddleButtonUp(x, y, mods); +} + +bool CocoaDispatch_OnMiddleDoubleClick(Window window, int x, int y, Modifiers mods) +{ + return window.OnMiddleDoubleClick(x, y, mods); +} + +void CocoaDispatch_OnMouseCaptureLost(Window window) +{ + window.OnMouseCaptureLost(); +} + +void CocoaDispatch_OnHScroll(Window window, ScrollBarAction action, int position, Key key) +{ + window.OnHScroll(action, position, key); +} + +void CocoaDispatch_OnVScroll(Window window, ScrollBarAction action, int position, Key key) +{ + window.OnVScroll(action, position, key); +} + +void CocoaDispatch_OnDrawOverChildren(Window window, Surface surface) +{ + window.OnDrawOverChildren(surface); +} + +bool CocoaDispatch_OnFileModified(Window window, FileChange fileChange, char * param) +{ + return window.OnFileModified(fileChange, param); +} + +bool CocoaDispatch_OnSaveFile(Window window, char *fileName) +{ + return window.OnSaveFile(fileName); +} + + diff --git a/ecere/src/gui/drivers/cocoa/CocoaEcereBridge.h b/ecere/src/gui/drivers/cocoa/CocoaEcereBridge.h new file mode 100644 index 0000000..92803c6 --- /dev/null +++ b/ecere/src/gui/drivers/cocoa/CocoaEcereBridge.h @@ -0,0 +1,85 @@ +#if !defined(_COCOAINTERFACE_H) +#define _COCOAINTERFACE_H +// CocoaInterface.ec <--> CocoaInterfaceImpl.m bridge. + +typedef struct CocoaKeyMod +{ + bool shift:1; + bool ctrl:1; + bool alt:1; + bool cmd:1; + bool left:1; + bool middle:1; + bool right:1; + bool isActivate:1; + bool isSideEffect:1; + bool closingDropDown:1; +} CocoaKeyMod; + +typedef void *EcereWindowRef; +typedef void *WindowHandle; + +// CocoaInterface +bool CocoaInitialize(); +void CocoaTerminate(); +bool CocoaProcessInput(bool processAll); +bool CocoaLock(WindowHandle handle); +void CocoaUnlock(WindowHandle handle); +void CocoaGetCurrentMode(bool * fullScreen, int * resolution, int * colorDepth, int * refreshRate); +WindowHandle CocoaCreateRootWindow(EcereWindowRef window); +void CocoaDestroyRootWindow(WindowHandle handle); +void CocoaSetRootWindowCaption(WindowHandle window, char *name); +void CocoaPositionRootWindow(WindowHandle handle, int x, int y, int w, int h, bool move, bool resize); +void CocoaOffsetWindow(WindowHandle window, int *x, int *y); +void CocoaGetMousePosition(int *x, int *y); + +// CocoaOpenGLDisplay +void CocoaOpenGLMakeCurrentContext(WindowHandle handle); +void CocoaOpenGLUpdate(WindowHandle handle); + +// Dispatch +void CocoaDispatch_UpdateRootWindow(EcereWindowRef ref); +void CocoaDispatch_ExternalPosition(EcereWindowRef ref, int x, int y, int width, int height); + +bool CocoaDispatch_OnCreate(EcereWindowRef window); +void CocoaDispatch_OnDestroy(EcereWindowRef window); +void CocoaDispatch_OnDestroyed(EcereWindowRef window); +bool CocoaDispatch_OnClose(EcereWindowRef window, bool parentClosing); +//bool CocoaDispatch_OnStateChange(EcereWindowRef window, WindowState state, Modifiers mods); +bool CocoaDispatch_OnPostCreate(EcereWindowRef window); +bool CocoaDispatch_OnMoving(EcereWindowRef window, int *x, int *y, int w, int h); +bool CocoaDispatch_OnResizing(EcereWindowRef window, int *width, int *height); +void CocoaDispatch_OnResize(EcereWindowRef window, int width, int height); +void CocoaDispatch_OnPosition(EcereWindowRef window, int x, int y, int width, int height); +bool CocoaDispatch_OnLoadGraphics(EcereWindowRef window); +void CocoaDispatch_OnApplyGraphics(EcereWindowRef window); +void CocoaDispatch_OnUnloadGraphics(EcereWindowRef window); +void CocoaDispatch_Update(EcereWindowRef window); +bool CocoaDispatch_OnActivate(EcereWindowRef window, bool active, EcereWindowRef previous, bool *goOnWithActivation, bool direct); +void CocoaDispatch_OnActivateClient(EcereWindowRef window, EcereWindowRef client, EcereWindowRef previous); +//bool CocoaDispatch_OnKeyDown(EcereWindowRef window, Key key, unichar ch); +//bool CocoaDispatch_OnKeyUp(EcereWindowRef window, Key key, unichar ch); +//bool CocoaDispatch_OnKeyHit(EcereWindowRef window, Key key, unichar ch); +//bool CocoaDispatch_OnSysKeyDown(EcereWindowRef window, Key key, unichar ch); +//bool CocoaDispatch_OnSysKeyUp(EcereWindowRef window, Key key, unichar ch); +//bool CocoaDispatch_OnSysKeyHit(EcereWindowRef window, Key key, unichar ch); +//bool CocoaDispatch_OnMouseOver(EcereWindowRef window, int x, int y, Modifiers mods); +//bool CocoaDispatch_OnMouseLeave(EcereWindowRef window, Modifiers mods); +//bool CocoaDispatch_OnMouseMove(EcereWindowRef window, int x, int y, Modifiers mods); +bool CocoaDispatch_OnLeftButtonDown(EcereWindowRef window, int x, int y, CocoaKeyMod mods); +//bool CocoaDispatch_OnLeftButtonUp(EcereWindowRef window, int x, int y, Modifiers mods); +//bool CocoaDispatch_OnLeftDoubleClick(EcereWindowRef window, int x, int y, Modifiers mods); +//bool CocoaDispatch_OnRightButtonDown(EcereWindowRef window, int x, int y, Modifiers mods); +//bool CocoaDispatch_OnRightButtonUp(EcereWindowRef window, int x, int y, Modifiers mods); +//bool CocoaDispatch_OnRightDoubleClick(EcereWindowRef window, int x, int y, Modifiers mods); +//bool CocoaDispatch_OnMiddleButtonDown(EcereWindowRef window, int x, int y, Modifiers mods); +//bool CocoaDispatch_OnMiddleButtonUp(EcereWindowRef window, int x, int y, Modifiers mods); +//bool CocoaDispatch_OnMiddleDoubleClick(EcereWindowRef window, int x, int y, Modifiers mods); +void CocoaDispatch_OnMouseCaptureLost(EcereWindowRef window); +//void CocoaDispatch_OnHScroll(EcereWindowRef window, ScrollBarAction action, int position, Key key); +//void CocoaDispatch_OnVScroll(EcereWindowRef window, ScrollBarAction action, int position, Key key); +//void CocoaDispatch_OnDrawOverChildren(EcereWindowRef window, Surface surface); +//bool CocoaDispatch_OnFileModified(EcereWindowRef window, FileChange fileChange, char * param); +bool CocoaDispatch_OnSaveFile(EcereWindowRef window, char *fileName); + +#endif // !defined(_COCOAINTERFACE_H) diff --git a/ecere/src/gui/drivers/cocoa/CocoaEcereBridge.m b/ecere/src/gui/drivers/cocoa/CocoaEcereBridge.m new file mode 100644 index 0000000..37fcb72 --- /dev/null +++ b/ecere/src/gui/drivers/cocoa/CocoaEcereBridge.m @@ -0,0 +1,154 @@ +#import + +#import "CocoaEcereBridge.h" +#import "EcereView.h" + +bool CocoaInitialize() +{ + [[NSAutoreleasePool alloc] init]; + [NSApplication sharedApplication]; + + [NSOpenGLContext clearCurrentContext]; + + return true; +} + + +void CocoaTerminate() +{ + [NSApp release]; +} + +bool CocoaProcessInput(bool processAll) +{ + NSEvent *event = NULL; + NSDate *date; + unsigned int eventMask; + + eventMask = (NSAnyEventMask); + + do { + event = [ + NSApp nextEventMatchingMask:eventMask + untilDate:nil + inMode:NSDefaultRunLoopMode + dequeue:YES]; + + [NSApp sendEvent:event]; + if ([event type]) + printf("e%i\n", [event type]); + } while (event && processAll); + + return true; +} + +bool CocoaLock(WindowHandle handle) +{ + EcereView *view = (EcereView*)handle; + + [view lockFocus]; + + return true; +} + +void CocoaUnlock(WindowHandle handle) +{ + EcereView *view = (EcereView*)handle; + + [view unlockFocus]; +} + +void CocoaGetCurrentMode(bool * fullScreen, int * resolution, int * colorDepth, int * refreshRate) +{ + *fullScreen = false; + *resolution = -1; + *colorDepth = -1; + *refreshRate = -1; +} + +WindowHandle CocoaCreateRootWindow(EcereWindowRef ecereWindow) +{ + NSWindow *window = [[NSWindow alloc] + initWithContentRect:NSZeroRect + styleMask:( NSResizableWindowMask | NSClosableWindowMask | NSTitledWindowMask) + backing:NSBackingStoreBuffered + defer:NO + screen:nil]; + + EcereView *view = [[EcereView alloc] initWithEcereWindow:ecereWindow]; + [window setContentView:view]; + + if (window) { + [window makeKeyAndOrderFront:window]; + } + + return view; +} + +void CocoaDestroyRootWindow(WindowHandle handle) +{ + EcereView *view = (EcereView*)handle; + + [[view window] release]; + [view release]; +} + +void CocoaSetRootWindowCaption(WindowHandle handle, char *name) +{ + EcereView *view = (EcereView*)handle; + + NSString *title = [NSString stringWithCString:name]; + + [[view window] setTitle:title]; + + [title release]; +} + +void CocoaPositionRootWindow(WindowHandle handle, int x, int y, int w, int h, bool move, bool resize) +{ + EcereView *view = (EcereView*)handle; + + NSRect frame = [[view window] frame]; + + if (move) { + frame.origin.x = x; + frame.origin.y = y; + } + + if (resize) { + frame.size.width = w; + frame.size.height = h; + } + + [[view window] setFrame:frame display:YES]; +} + +void CocoaOffsetWindow(WindowHandle handle, int *x, int *y) +{ +} + +void CocoaGetMousePosition(int *x, int *y) +{ + NSPoint location; + location = [NSEvent mouseLocation]; + + *x = location.x; + *y = location.y; +} + +void CocoaOpenGLMakeCurrentContext(WindowHandle handle) +{ + EcereView *view = (EcereView*)handle; + + [view makeCurrentContext]; +} + +void CocoaOpenGLUpdate(WindowHandle handle) +{ + EcereView *view = (EcereView*)handle; + + [view flushOpenGLBuffer]; +} + + + diff --git a/ecere/src/gui/drivers/cocoa/CocoaInterface.ec b/ecere/src/gui/drivers/cocoa/CocoaInterface.ec new file mode 100644 index 0000000..5c0bc70 --- /dev/null +++ b/ecere/src/gui/drivers/cocoa/CocoaInterface.ec @@ -0,0 +1,291 @@ +namespace gui::drivers; + +import "instance" +import "CocoaOpenGLDisplayDriver" + +default: + +private: + +import "Interface" +#include "CocoaEcereBridge.h" + +class CocoaInterface : Interface +{ + class_property(name) = "Cocoa"; + + // --- User Interface System --- + bool Initialize() + { + bool result; + + printf("Initialize %s:%i\n", __FILE__, __LINE__); + result = CocoaInitialize(); + + return result; + } + + void Terminate() + { + printf("Terminate %s:%i\n", __FILE__, __LINE__); + CocoaTerminate(); + } + + bool ProcessInput(bool processAll) + { + bool result; + + //printf("ProcessInput %s:%i\n", __FILE__, __LINE__); + result = CocoaProcessInput(processAll); + + return result; + } + + void Wait() + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + void Lock(Window window) + { + // TODO: + printf("Lock %s:%i\n", __FILE__, __LINE__); + } + + void Unlock(Window window) + { + // TODO: + printf("Unlock %s:%i\n", __FILE__, __LINE__); + } + + char **GraphicsDrivers(int *numDrivers) + { + static char *graphicsDrivers[] = { "CocoaOpenGL" }; + *numDrivers = sizeof(graphicsDrivers) / sizeof(char *); + + return (char **)graphicsDrivers; + } + + void GetCurrentMode(bool * fullScreen, int * resolution, int * colorDepth, int * refreshRate) + { + printf("GetCurrentMode %s:%i\n", __FILE__, __LINE__); + CocoaGetCurrentMode(fullScreen, resolution, colorDepth, refreshRate); + } + + void EnsureFullScreen(bool *fullScreen) + { + printf("STUB! %s:%i\n", __FILE__, __LINE__); + *fullScreen = false; + } + + bool ScreenMode(bool fullScreen, int resolution, int colorDepth, int refreshRate, bool * textMode) + { + printf("STUB! %s:%i\n", __FILE__, __LINE__); + + *textMode = false; + return true; + } + + // --- Window Creation --- + void * CreateRootWindow(Window window) + { + // TODO: + printf("CreateRootWindow %s:%i\n", __FILE__, __LINE__); + window.windowHandle = CocoaCreateRootWindow(window); + + return window.windowHandle; + } + + void DestroyRootWindow(Window window) + { + printf("DestroyRootWindow %s:%i\n", __FILE__, __LINE__); + CocoaDestroyRootWindow(window.windowHandle); + } + + // -- Window manipulation --- + + void SetRootWindowCaption(Window window, char * name) + { + printf("SetRootWindowCaption %s:%i\n", __FILE__, __LINE__); + CocoaSetRootWindowCaption(window.windowHandle, name); + } + + void PositionRootWindow(Window window, int x, int y, int w, int h, bool move, bool resize) + { + printf("PositionRootWindow %s:%i\n", __FILE__, __LINE__); + CocoaPositionRootWindow(window.windowHandle, x, y, w, h, move, resize); + } + + void OrderRootWindow(Window window, bool topMost) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + void SetRootWindowColor(Window window) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + void OffsetWindow(Window window, int *x, int *y) + { + //printf("OffsetWindow %s:%i\n", __FILE__, __LINE__); + CocoaOffsetWindow(window.windowHandle, x, y); + } + + void UpdateRootWindow(Window window) + { + // TODO: + printf("UpdateRootWindow! %s:%i\n", __FILE__, __LINE__); + CocoaDispatch_UpdateRootWindow(window); + } + + void SetRootWindowState(Window window, WindowState state, bool visible) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + void FlashRootWindow(Window window) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + void ActivateRootWindow(Window window) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + // --- Mouse-based window movement --- + + void StartMoving(Window window, int x, int y, bool fromKeyBoard) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + void StopMoving(Window window) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + // -- Mouse manipulation --- + + void GetMousePosition(int *x, int *y) + { + CocoaGetMousePosition(x, y); + //printf("GetMousePosition(%i,%i) %s:%i\n", *x, *y, __FILE__, __LINE__); + } + + void SetMousePosition(int x, int y) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + void SetMouseRange(Window window, Box box) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + void SetMouseCapture(Window window) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + // -- Mouse cursor --- + + void SetMouseCursor(int cursor) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + // --- Caret --- + + void SetCaret(int x, int y, int size) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + void ClearClipboard() + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + bool AllocateClipboard(ClipBoard clipBoard, uint size) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + bool SaveClipboard(ClipBoard clipBoard) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + bool LoadClipboard(ClipBoard clipBoard) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + void UnloadClipboard(ClipBoard clipBoard) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + // --- State based input --- + + bool AcquireInput(Window window, bool state) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + return false; + } + + bool GetMouseState(MouseButtons * buttons, int * x, int * y) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + bool GetJoystickState(int device, Joystick joystick) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + bool GetKeyState(Key key) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + void SetTimerResolution(uint hertz) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + } + + bool SetIcon(Window window, BitmapResource resource) + { + // TODO: + printf("STUB! %s:%i\n", __FILE__, __LINE__); + + return true; + } +} + + diff --git a/ecere/src/gui/drivers/cocoa/EcereView.h b/ecere/src/gui/drivers/cocoa/EcereView.h new file mode 100644 index 0000000..4362b8d --- /dev/null +++ b/ecere/src/gui/drivers/cocoa/EcereView.h @@ -0,0 +1,33 @@ +#include + +typedef uint32_t CocoaColor; + +@interface EcereView : NSView +{ +@private + // Reference to the Ecere Window class via pointer. Used for callbacks. + EcereWindowRef _ecereWindow; + + // Foreground and background draw color. + CocoaColor _foreground; + CocoaColor _background; + + int lockCount; + + NSOpenGLContext *_context; + NSOpenGLPixelFormat *_pixelformat; +} +- (EcereView*)initWithEcereWindow:(EcereWindowRef)ecereWindow; +- (NSOpenGLContext*)openGLContext; +- (void)lockFOcus; +- (void)makeCurrentContext; +- (void)flushOpenGLBuffer; +- (EcereWindowRef)ecereWindow; +- (void)setEcereWindow:(EcereWindowRef)ecereWindow; +- (CocoaColor)foreground; +- (void)setForeground:(CocoaColor)color; +- (CocoaColor)background; +- (void)setBackground:(CocoaColor)color; +@end + + diff --git a/ecere/src/gui/drivers/cocoa/EcereView.m b/ecere/src/gui/drivers/cocoa/EcereView.m new file mode 100644 index 0000000..6c84dc0 --- /dev/null +++ b/ecere/src/gui/drivers/cocoa/EcereView.m @@ -0,0 +1,203 @@ +#import +#import "CocoaEcereBridge.h" +#import "EcereView.h" + +@implementation EcereView +- (EcereView*)initWithEcereWindow:(EcereWindowRef)ecereWindow; +{ + self = [super initWithFrame:NSZeroRect]; + + lockCount = 0; + + if (self != nil) + { + NSOpenGLPixelFormatAttribute attributes[] = + { + NSOpenGLPFAWindow, + //NSOpenGLPFAAccelerated, + NSOpenGLPFADoubleBuffer, + //NSOpenGLPFAColorSize, 24, + NSOpenGLPFAAlphaSize, 8, + NSOpenGLPFADepthSize, 24, + NSOpenGLPFAMinimumPolicy, + // select a pixelformat which meets or + // exceeds these requirements + 0 + }; + + _pixelformat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes] ; + + if (_pixelformat == nil) + { + NSLog( @"No valid OpenGL pixel format" ); + NSLog( @"matching attributes specified" ); + exit(1); + } + + [self setEcereWindow:ecereWindow]; + + _context = [[NSOpenGLContext alloc] + initWithFormat:_pixelformat shareContext:nil] ; + + if (_context == nil) + { + // Failed initialization + self = nil; + NSLog( @"No valid OpenGL" ) ; + exit(1); + } + else + { + // ensure we are pointing to ourself as the Drawable + [_context setView:self]; + } + } + + if (_context == nil) { + self = nil; + } + + return self; +} + +- (void)Dealloc +{ + [_context release]; +} + +- (NSOpenGLContext*)openGLContext +{ + return _context; +} + +- (void)lockFocus +{ + // ensure we are ready to draw + lockCount++; + + [_context setView:self]; + [super lockFocus]; + + [self makeCurrentContext]; + + printf("- (void)lockFocus(%i)\n", lockCount); +} + +- (void)unlockFocus +{ + lockCount--; + + [self flushOpenGLBuffer]; + + [super unlockFocus]; + + printf("- (void)unlockFocus(%i)\n", lockCount); +} + +- (void)makeCurrentContext +{ + printf("- (void)makeCurrentContext\n"); + + [_context makeCurrentContext]; +} + +- (void)flushOpenGLBuffer +{ + printf("- (void)flushOpenGLBuffer\n"); + + [_context flushBuffer]; +} + +- (BOOL)isOpaque +{ + return YES; +} + +- drawRect:(NSRect)rect +{ + // make us the current OpenGL context + //[_context makeCurrentContext]; + printf("- drawRect:(NSRect)rect\n"); + CocoaDispatch_Update([self ecereWindow]); +} + +- (void)viewDidMoveToWindow +{ + // Register with window for resize and move notification. + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(windowResized:) + name:NSWindowDidResizeNotification + object:[self window]]; + + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(windowMoved:) + name:NSWindowDidMoveNotification + object:[self window]]; +} + +- (void)windowResized:(NSNotification *)notification +{ + [_context update]; + + NSRect rect = [[self window] frame]; + + CocoaDispatch_ExternalPosition([self ecereWindow], rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); + + printf("- (void)windowResized:(NSNotification *)notification\n"); +} + +- (void)windowMoved:(NSNotification *)notification; +{ + [_context update]; + + NSRect rect = [[self window] frame]; + + CocoaDispatch_ExternalPosition([self ecereWindow], rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); + + printf("- (void)windowMoved:(NSNotification *)notification\n"); +} + +- (EcereWindowRef)ecereWindow +{ + return _ecereWindow; +} + +- setEcereWindow:(EcereWindowRef)ecereWindow +{ + _ecereWindow = ecereWindow; +} + +- (void)mouseDown:(NSEvent *)event +{ + NSPoint location = [NSEvent mouseLocation]; + + CocoaKeyMod mod; + + CocoaDispatch_OnLeftButtonDown([self ecereWindow], location.x, location.y, mod); +} + +- (CocoaColor)foreground +{ + return _foreground; +} + +- (void)setForeground:(CocoaColor)color +{ + _foreground = color; +} + +- (CocoaColor)background +{ + return _background; +} + +- (void)setBackground:(CocoaColor)color +{ + _background = color; +} + +@end + + diff --git a/ecere/src/sys/File.c b/ecere/src/sys/File.c index 6128f3a..f7eb7c0 100644 --- a/ecere/src/sys/File.c +++ b/ecere/src/sys/File.c @@ -1,3 +1,4 @@ +#undef __BLOCKS__ #include #include #include diff --git a/ecere/src/sys/File.ec b/ecere/src/sys/File.ec index 1e61740..2a3d193 100644 --- a/ecere/src/sys/File.ec +++ b/ecere/src/sys/File.ec @@ -3,6 +3,7 @@ namespace sys; default: #define uint _uint #define File _File +#undef __BLOCKS__ #include #include #include diff --git a/ecere/src/sys/System.ec b/ecere/src/sys/System.ec index c9d0bf7..5dc5840 100644 --- a/ecere/src/sys/System.ec +++ b/ecere/src/sys/System.ec @@ -24,6 +24,7 @@ default: #endif +#undef __BLOCKS__ #include #include #include diff --git a/ecere/src/sys/Time.ec b/ecere/src/sys/Time.ec index 789bd4a..4167734 100644 --- a/ecere/src/sys/Time.ec +++ b/ecere/src/sys/Time.ec @@ -14,6 +14,8 @@ import "instance" #define uint64 _uint64 #define Alignment _Alignment +#undef __BLOCKS__ + #if defined(__WIN32__) #define WIN32_LEAN_AND_MEAN #include diff --git a/ide/src/project/ProjectNode.ec b/ide/src/project/ProjectNode.ec index ebfadde..0a1a1a2 100644 --- a/ide/src/project/ProjectNode.ec +++ b/ide/src/project/ProjectNode.ec @@ -1759,9 +1759,9 @@ private: /*if(!strcmpi(extension, "c") || !strcmpi(extension, "cpp") || !strcmpi(extension, "ec") || !strcmpi(extension, "cc") || !strcmpi(extension, "cxx"))*/ - if((!strcmpi(extension, "c") || !strcmpi(extension, "cpp") || - !strcmpi(extension, "cc") || !strcmpi(extension, "cxx")) || - !strcmpi(extension, "ec")) + if(!strcmpi(extension, "c") || !strcmpi(extension, "cpp") || + !strcmpi(extension, "cc") || !strcmpi(extension, "cxx") || + !strcmpi(extension, "m") || !strcmpi(extension, "ec")) { DualPipe dep; char command[2048]; -- 1.8.3.1