Substantial NSOpenGL/CGL/Win32Window changes for alpha blended NSOpenGLView's in alpha blend windows. Includes:

- Removed NSOpenGLDrawable_gdiView, moved private child window to CGLContext
- Added some more CGL calls
- NSWindow/Win32Window frame is now actual frame
- X11 OpenGL and Window frame broken
This commit is contained in:
Christopher Lloyd 2010-04-26 22:56:25 -04:00
parent 508451c124
commit f878c01001
30 changed files with 958 additions and 671 deletions

View File

@ -334,7 +334,6 @@
C88975500EA0BF3100D0A0A2 /* KTFont.h in Headers */ = {isa = PBXBuildFile; fileRef = FE89AF470C33679100CD21FB /* KTFont.h */; settings = {ATTRIBUTES = (Private, ); }; };
C88975510EA0BF3100D0A0A2 /* O2DeviceContext_gdi.h in Headers */ = {isa = PBXBuildFile; fileRef = FE57F8D00C46B68C0078FFC1 /* O2DeviceContext_gdi.h */; settings = {ATTRIBUTES = (Private, ); }; };
C88975520EA0BF3100D0A0A2 /* NSPrintPanel.h in Headers */ = {isa = PBXBuildFile; fileRef = FE57FAB50C47F2010078FFC1 /* NSPrintPanel.h */; settings = {ATTRIBUTES = (Public, ); }; };
C88975530EA0BF3100D0A0A2 /* NSOpenGLDrawable_gdiView.h in Headers */ = {isa = PBXBuildFile; fileRef = FEF2EC330C891E7C001FC5A8 /* NSOpenGLDrawable_gdiView.h */; settings = {ATTRIBUTES = (Private, ); }; };
C88975540EA0BF3100D0A0A2 /* opengl_dll.h in Headers */ = {isa = PBXBuildFile; fileRef = FE1CEA6B0C8F12F800184630 /* opengl_dll.h */; };
C88975550EA0BF3100D0A0A2 /* O2zlib.h in Headers */ = {isa = PBXBuildFile; fileRef = FE8F9F260C9C5D0000270AEE /* O2zlib.h */; settings = {ATTRIBUTES = (Private, ); }; };
C88975560EA0BF3100D0A0A2 /* O2ImageSource_BMP.h in Headers */ = {isa = PBXBuildFile; fileRef = FE572D8B0CA0809500FB3E79 /* O2ImageSource_BMP.h */; };
@ -996,7 +995,6 @@
C8A2E3D10F07EA1F0054397C /* KTFont.h in Headers */ = {isa = PBXBuildFile; fileRef = FE89AF470C33679100CD21FB /* KTFont.h */; settings = {ATTRIBUTES = (Private, ); }; };
C8A2E3D20F07EA1F0054397C /* O2DeviceContext_gdi.h in Headers */ = {isa = PBXBuildFile; fileRef = FE57F8D00C46B68C0078FFC1 /* O2DeviceContext_gdi.h */; settings = {ATTRIBUTES = (Private, ); }; };
C8A2E3D30F07EA1F0054397C /* NSPrintPanel.h in Headers */ = {isa = PBXBuildFile; fileRef = FE57FAB50C47F2010078FFC1 /* NSPrintPanel.h */; settings = {ATTRIBUTES = (Public, ); }; };
C8A2E3D40F07EA1F0054397C /* NSOpenGLDrawable_gdiView.h in Headers */ = {isa = PBXBuildFile; fileRef = FEF2EC330C891E7C001FC5A8 /* NSOpenGLDrawable_gdiView.h */; settings = {ATTRIBUTES = (Private, ); }; };
C8A2E3D50F07EA1F0054397C /* opengl_dll.h in Headers */ = {isa = PBXBuildFile; fileRef = FE1CEA6B0C8F12F800184630 /* opengl_dll.h */; };
C8A2E3D60F07EA1F0054397C /* O2zlib.h in Headers */ = {isa = PBXBuildFile; fileRef = FE8F9F260C9C5D0000270AEE /* O2zlib.h */; settings = {ATTRIBUTES = (Private, ); }; };
C8A2E3D70F07EA1F0054397C /* O2ImageSource_BMP.h in Headers */ = {isa = PBXBuildFile; fileRef = FE572D8B0CA0809500FB3E79 /* O2ImageSource_BMP.h */; };
@ -2470,7 +2468,6 @@
FE5A8A0010C6F50E005E348A /* KTFont.h in Headers */ = {isa = PBXBuildFile; fileRef = FE89AF470C33679100CD21FB /* KTFont.h */; settings = {ATTRIBUTES = (Private, ); }; };
FE5A8A0110C6F50E005E348A /* O2DeviceContext_gdi.h in Headers */ = {isa = PBXBuildFile; fileRef = FE57F8D00C46B68C0078FFC1 /* O2DeviceContext_gdi.h */; settings = {ATTRIBUTES = (Private, ); }; };
FE5A8A0210C6F50E005E348A /* NSPrintPanel.h in Headers */ = {isa = PBXBuildFile; fileRef = FE57FAB50C47F2010078FFC1 /* NSPrintPanel.h */; settings = {ATTRIBUTES = (Public, ); }; };
FE5A8A0310C6F50E005E348A /* NSOpenGLDrawable_gdiView.h in Headers */ = {isa = PBXBuildFile; fileRef = FEF2EC330C891E7C001FC5A8 /* NSOpenGLDrawable_gdiView.h */; settings = {ATTRIBUTES = (Private, ); }; };
FE5A8A0410C6F50E005E348A /* opengl_dll.h in Headers */ = {isa = PBXBuildFile; fileRef = FE1CEA6B0C8F12F800184630 /* opengl_dll.h */; };
FE5A8A0510C6F50E005E348A /* O2zlib.h in Headers */ = {isa = PBXBuildFile; fileRef = FE8F9F260C9C5D0000270AEE /* O2zlib.h */; settings = {ATTRIBUTES = (Private, ); }; };
FE5A8A0610C6F50E005E348A /* O2ImageSource_BMP.h in Headers */ = {isa = PBXBuildFile; fileRef = FE572D8B0CA0809500FB3E79 /* O2ImageSource_BMP.h */; };
@ -3272,7 +3269,6 @@
FEA3149E0FD5667D00F480D4 /* NSTypesetter_concrete.h in Headers */ = {isa = PBXBuildFile; fileRef = FE72484F0C0676AA007CBC51 /* NSTypesetter_concrete.h */; };
FEA314A00FD5667D00F480D4 /* O2DeviceContext_gdi.h in Headers */ = {isa = PBXBuildFile; fileRef = FE57F8D00C46B68C0078FFC1 /* O2DeviceContext_gdi.h */; settings = {ATTRIBUTES = (Private, ); }; };
FEA314A10FD5667D00F480D4 /* NSPrintPanel.h in Headers */ = {isa = PBXBuildFile; fileRef = FE57FAB50C47F2010078FFC1 /* NSPrintPanel.h */; settings = {ATTRIBUTES = (Public, ); }; };
FEA314A20FD5667D00F480D4 /* NSOpenGLDrawable_gdiView.h in Headers */ = {isa = PBXBuildFile; fileRef = FEF2EC330C891E7C001FC5A8 /* NSOpenGLDrawable_gdiView.h */; settings = {ATTRIBUTES = (Private, ); }; };
FEA314A30FD5667D00F480D4 /* opengl_dll.h in Headers */ = {isa = PBXBuildFile; fileRef = FE1CEA6B0C8F12F800184630 /* opengl_dll.h */; };
FEA314A80FD5667D00F480D4 /* O2Context_gdi.h in Headers */ = {isa = PBXBuildFile; fileRef = FEABD6030CB9D0C90035F828 /* O2Context_gdi.h */; settings = {ATTRIBUTES = (Private, ); }; };
FEA314A90FD5667D00F480D4 /* KTFont_gdi.h in Headers */ = {isa = PBXBuildFile; fileRef = FE311FA40CCC430200EBD696 /* KTFont_gdi.h */; };
@ -3626,8 +3622,6 @@
FEF0889F10C5B06400D38A2F /* CGImageDestination.m in Sources */ = {isa = PBXBuildFile; fileRef = FEF0889E10C5B06400D38A2F /* CGImageDestination.m */; };
FEF088A010C5B06400D38A2F /* CGImageDestination.m in Sources */ = {isa = PBXBuildFile; fileRef = FEF0889E10C5B06400D38A2F /* CGImageDestination.m */; };
FEF088A110C5B06400D38A2F /* CGImageDestination.m in Sources */ = {isa = PBXBuildFile; fileRef = FEF0889E10C5B06400D38A2F /* CGImageDestination.m */; };
FEF2EC350C891E7C001FC5A8 /* NSOpenGLDrawable_gdiView.h in Headers */ = {isa = PBXBuildFile; fileRef = FEF2EC330C891E7C001FC5A8 /* NSOpenGLDrawable_gdiView.h */; settings = {ATTRIBUTES = (Private, ); }; };
FEF2EC7B0C8A03CC001FC5A8 /* NSOpenGLDrawable_gdiView.m in Sources */ = {isa = PBXBuildFile; fileRef = FEF2EC790C8A03CC001FC5A8 /* NSOpenGLDrawable_gdiView.m */; };
FEF4684310895C9800B45195 /* CGConversions.h in Headers */ = {isa = PBXBuildFile; fileRef = FEF4684210895C9800B45195 /* CGConversions.h */; };
FEF4684410895C9800B45195 /* CGConversions.h in Headers */ = {isa = PBXBuildFile; fileRef = FEF4684210895C9800B45195 /* CGConversions.h */; };
FEF4684510895C9800B45195 /* CGConversions.h in Headers */ = {isa = PBXBuildFile; fileRef = FEF4684210895C9800B45195 /* CGConversions.h */; };
@ -4716,8 +4710,6 @@
FEED24790EC9E8F200A5B07E /* NSRefreshTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = NSRefreshTemplate.pdf; sourceTree = "<group>"; };
FEEF00580B96441800069FD1 /* CGPDFPage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CGPDFPage.m; sourceTree = "<group>"; };
FEF0889E10C5B06400D38A2F /* CGImageDestination.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CGImageDestination.m; sourceTree = "<group>"; };
FEF2EC330C891E7C001FC5A8 /* NSOpenGLDrawable_gdiView.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NSOpenGLDrawable_gdiView.h; sourceTree = "<group>"; };
FEF2EC790C8A03CC001FC5A8 /* NSOpenGLDrawable_gdiView.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = NSOpenGLDrawable_gdiView.m; sourceTree = "<group>"; };
FEF33BFF0B93543C00DC0B6F /* O2MutablePath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = O2MutablePath.h; sourceTree = "<group>"; };
FEF33C000B93543C00DC0B6F /* O2MutablePath.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = O2MutablePath.m; sourceTree = "<group>"; };
FEF4684210895C9800B45195 /* CGConversions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CGConversions.h; sourceTree = "<group>"; };
@ -5361,8 +5353,6 @@
FE311FA50CCC430200EBD696 /* KTFont_gdi.m */,
FE4434020BB9833B00411464 /* NSGraphicsStyle_uxtheme.h */,
FE4434030BB9833B00411464 /* NSGraphicsStyle_uxtheme.m */,
FEF2EC330C891E7C001FC5A8 /* NSOpenGLDrawable_gdiView.h */,
FEF2EC790C8A03CC001FC5A8 /* NSOpenGLDrawable_gdiView.m */,
6E2B565D0976075400DA0954 /* NSOpenPanel-Win32.h */,
6E2B56300976075400DA0954 /* NSOpenPanel-Win32.m */,
6E2B565B0976075400DA0954 /* NSSavePanel-Win32.h */,
@ -6268,7 +6258,6 @@
C88975500EA0BF3100D0A0A2 /* KTFont.h in Headers */,
C88975510EA0BF3100D0A0A2 /* O2DeviceContext_gdi.h in Headers */,
C88975520EA0BF3100D0A0A2 /* NSPrintPanel.h in Headers */,
C88975530EA0BF3100D0A0A2 /* NSOpenGLDrawable_gdiView.h in Headers */,
C88975540EA0BF3100D0A0A2 /* opengl_dll.h in Headers */,
C88975550EA0BF3100D0A0A2 /* O2zlib.h in Headers */,
C88975560EA0BF3100D0A0A2 /* O2ImageSource_BMP.h in Headers */,
@ -6647,7 +6636,6 @@
C8A2E3D10F07EA1F0054397C /* KTFont.h in Headers */,
C8A2E3D20F07EA1F0054397C /* O2DeviceContext_gdi.h in Headers */,
C8A2E3D30F07EA1F0054397C /* NSPrintPanel.h in Headers */,
C8A2E3D40F07EA1F0054397C /* NSOpenGLDrawable_gdiView.h in Headers */,
C8A2E3D50F07EA1F0054397C /* opengl_dll.h in Headers */,
C8A2E3D60F07EA1F0054397C /* O2zlib.h in Headers */,
C8A2E3D70F07EA1F0054397C /* O2ImageSource_BMP.h in Headers */,
@ -7025,7 +7013,6 @@
FE01A94F0C5D9BCB00AEA51A /* KTFont.h in Headers */,
FE01A9510C5D9BCB00AEA51A /* O2DeviceContext_gdi.h in Headers */,
FE01A9520C5D9BCB00AEA51A /* NSPrintPanel.h in Headers */,
FEF2EC350C891E7C001FC5A8 /* NSOpenGLDrawable_gdiView.h in Headers */,
FE1CEA6F0C8F12F800184630 /* opengl_dll.h in Headers */,
FE8F9F2A0C9C5D0000270AEE /* O2zlib.h in Headers */,
FE572D8F0CA0809500FB3E79 /* O2ImageSource_BMP.h in Headers */,
@ -7396,7 +7383,6 @@
FE5A8A0010C6F50E005E348A /* KTFont.h in Headers */,
FE5A8A0110C6F50E005E348A /* O2DeviceContext_gdi.h in Headers */,
FE5A8A0210C6F50E005E348A /* NSPrintPanel.h in Headers */,
FE5A8A0310C6F50E005E348A /* NSOpenGLDrawable_gdiView.h in Headers */,
FE5A8A0410C6F50E005E348A /* opengl_dll.h in Headers */,
FE5A8A0510C6F50E005E348A /* O2zlib.h in Headers */,
FE5A8A0610C6F50E005E348A /* O2ImageSource_BMP.h in Headers */,
@ -7732,7 +7718,6 @@
FEA3149E0FD5667D00F480D4 /* NSTypesetter_concrete.h in Headers */,
FEA314A00FD5667D00F480D4 /* O2DeviceContext_gdi.h in Headers */,
FEA314A10FD5667D00F480D4 /* NSPrintPanel.h in Headers */,
FEA314A20FD5667D00F480D4 /* NSOpenGLDrawable_gdiView.h in Headers */,
FEA314A30FD5667D00F480D4 /* opengl_dll.h in Headers */,
FEA314A80FD5667D00F480D4 /* O2Context_gdi.h in Headers */,
FEA314A90FD5667D00F480D4 /* KTFont_gdi.h in Headers */,
@ -9374,7 +9359,6 @@
FE01AA900C5D9BCB00AEA51A /* KTFont.m in Sources */,
FE01AA920C5D9BCB00AEA51A /* O2DeviceContext_gdi.m in Sources */,
FE01AA930C5D9BCB00AEA51A /* NSPrintPanel.m in Sources */,
FEF2EC7B0C8A03CC001FC5A8 /* NSOpenGLDrawable_gdiView.m in Sources */,
FE1CEA700C8F12F800184630 /* opengl_dll.m in Sources */,
FE8F9F2B0C9C5D0000270AEE /* O2zlib.m in Sources */,
FE572D900CA0809500FB3E79 /* O2ImageSource_BMP.m in Sources */,
@ -10158,6 +10142,7 @@
buildSettings = {
ARCHS = i386;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = stabs;
DEPLOYMENT_LOCATION = YES;
DSTROOT = /;
EXECUTABLE_SUFFIX = .1.0.dll;
@ -10187,6 +10172,7 @@
);
OTHER_LDFLAGS = (
"-shared",
"-lMsimg32",
"-lole32",
"-lgdi32",
"-luser32",
@ -10462,6 +10448,7 @@
INSTALL_MODE_FLAG = "og-w,a+rX";
INSTALL_PATH = /Developer/Cocotron/1.0/Windows/i386/Frameworks;
OTHER_CFLAGS = (
"-DWINVER=0x500",
"-DQUARTZCORE_INSIDE_BUILD",
"-DAPPKIT_INSIDE_BUILD",
"-DCORETEXT_INSIDE_BUILD",
@ -10472,6 +10459,7 @@
);
OTHER_LDFLAGS = (
"-shared",
"-lMsimg32",
"-lole32",
"-lgdi32",
"-luser32",

View File

@ -446,9 +446,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
-(CGColorSpaceRef)CGColorSpace {
if([_colorSpaceName isEqualToString:NSDeviceRGBColorSpace])
return CGColorSpaceCreateDeviceRGB();
return (CGColorSpaceRef)[(id)CGColorSpaceCreateDeviceRGB() autorelease];
if([_colorSpaceName isEqualToString:NSCalibratedRGBColorSpace])
return CGColorSpaceCreateDeviceRGB();
return (CGColorSpaceRef)[(id)CGColorSpaceCreateDeviceRGB() autorelease];
return NULL;
}

View File

@ -8,7 +8,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#import <Foundation/NSObject.h>
@class NSOpenGLPixelFormat,NSOpenGLPixelBuffer,NSView,NSOpenGLDrawable;
@class NSOpenGLPixelFormat,NSOpenGLPixelBuffer,NSView;
typedef enum {
NSOpenGLCPSwapRectangle =200,
@ -24,7 +24,6 @@ typedef enum {
NSOpenGLPixelFormat *_pixelFormat;
NSView *_view;
void *_glContext;
NSOpenGLDrawable *_drawable;
}
+(NSOpenGLContext *)currentContext;

View File

@ -7,8 +7,10 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <AppKit/NSOpenGLContext.h>
#import <AppKit/NSOpenGLPixelFormat.h>
#import <AppKit/NSOpenGLDrawable.h>
#import <AppKit/NSGraphicsContext.h>
#import <AppKit/NSRaise.h>
#import <AppKit/NSView.h>
#import <AppKit/NSWindow-Private.h>
#import <OpenGL/OpenGL.h>
#import <Foundation/NSThread-Private.h>
@ -40,7 +42,11 @@ static inline void _clearCurrentContext(){
}
-initWithFormat:(NSOpenGLPixelFormat *)pixelFormat shareContext:(NSOpenGLContext *)shareContext {
CGLError error;
_pixelFormat=[pixelFormat retain];
if((error=CGLCreateContext([_pixelFormat CGLPixelFormatObj],[shareContext CGLContextObj],(CGLContextObj *)&_glContext))!=kCGLNoError)
NSLog(@"CGLCreateContext failed with %d in %s %d",error,__FILE__,__LINE__);
return self;
}
@ -50,8 +56,6 @@ static inline void _clearCurrentContext(){
_clearCurrentContext();
[_pixelFormat release];
_view=nil;
[_drawable invalidate];
[_drawable release];
CGLDestroyContext(_glContext);
[super dealloc];
}
@ -75,43 +79,37 @@ static inline void _clearCurrentContext(){
return 0;
}
-(void)_createContextIfNeeded {
if(_drawable==nil){
_drawable=[[NSOpenGLDrawable alloc] initWithPixelFormat:_pixelFormat view:_view];
if((_glContext=[_drawable createGLContext])==NULL){
NSLog(@"unable to create _glContext");
return;
}
}
}
-(void *)CGLContextObj {
[self _createContextIfNeeded];
return _glContext;
}
-(void)getValues:(long *)vals forParameter:(NSOpenGLContextParameter)parameter {
CGLGetParameter([self CGLContextObj],parameter,(GLint *)&vals);
CGLGetParameter(_glContext,parameter,(GLint *)vals);
}
-(void)setValues:(const long *)vals forParameter:(NSOpenGLContextParameter)parameter {
CGLSetParameter([self CGLContextObj],parameter,(const GLint *)vals);
CGLSetParameter(_glContext,parameter,(const GLint *)vals);
}
-(void)setView:(NSView *)view {
_view=view;
[self update];
}
-(void)makeCurrentContext {
[self _createContextIfNeeded];
[_drawable makeCurrentWithGLContext:_glContext];
CGLError error;
if((error=CGLSetCurrentContext(_glContext))!=kCGLNoError)
NSLog(@"CGLSetCurrentContext failed with %d in %s %d",error,__FILE__,__LINE__);
_setCurrentContext(self);
}
-(void)_clearCurrentContext {
if (_drawable!=nil)
[_drawable clearCurrentWithGLContext:_glContext];
CGLError error;
if((error=CGLSetCurrentContext(NULL))!=kCGLNoError)
NSLog(@"CGLSetCurrentContext failed with %d in %s %d",error,__FILE__,__LINE__);
}
-(int)currentVirtualScreen {
@ -143,14 +141,22 @@ static inline void _clearCurrentContext(){
}
-(void)update {
[_drawable updateWithView:_view];
if(_view!=nil){
NSRect rect=[_view convertRect:[_view bounds] toView:nil];
GLint frame[4]={
rect.origin.x,
rect.origin.y,
rect.size.width,
rect.size.height };
GLint number[1]={[[_view window] windowNumber]};
CGLSetParameter(_glContext,kCGLCPSurfaceFrame,frame);
CGLSetParameter(_glContext,kCGLCPWindowNumber,number);
}
}
-(void)clearDrawable {
_view=nil;
[_drawable invalidate];
[_drawable release];
_drawable=nil;
}
-(void)copyAttributesFromContext:(NSOpenGLContext *)context withMask:(unsigned long)mask {
@ -162,8 +168,8 @@ static inline void _clearCurrentContext(){
}
-(void)flushBuffer {
// fix, check if doublebuffered
[_drawable swapBuffers];
CGLFlushDrawable(_glContext);
}
@end

View File

@ -7,32 +7,59 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSObject.h>
#import <OpenGL/OpenGL.h>
typedef enum {
NSOpenGLPFADoubleBuffer=5,
NSOpenGLPFAStereo=6,
NSOpenGLPFAAuxBuffers=7,
NSOpenGLPFAColorSize=8,
NSOpenGLPFAAlphaSize=11,
NSOpenGLPFADepthSize=12,
NSOpenGLPFAStencilSize=13,
NSOpenGLPFAAccumSize=14,
NSOpenGLPFAOffScreen=53,
NSOpenGLPFAFullScreen=54,
NSOpenGLPFARendererID=70,
NSOpenGLPFAAccelerated=73,
NSOpenGLPFAWindow=80,
NSOpenGLPFAScreenMask=84,
} NSOpenGLPixelFormatAttribute;
enum {
NSOpenGLPFAAllRenderers = 1,
NSOpenGLPFADoubleBuffer = 5,
NSOpenGLPFAStereo = 6,
NSOpenGLPFAAuxBuffers = 7,
NSOpenGLPFAColorSize = 8,
NSOpenGLPFAAlphaSize = 11,
NSOpenGLPFADepthSize = 12,
NSOpenGLPFAStencilSize = 13,
NSOpenGLPFAAccumSize = 14,
NSOpenGLPFAMinimumPolicy = 51,
NSOpenGLPFAMaximumPolicy = 52,
NSOpenGLPFAOffScreen = 53,
NSOpenGLPFAFullScreen = 54,
NSOpenGLPFASampleBuffers = 55,
NSOpenGLPFASamples = 56,
NSOpenGLPFAAuxDepthStencil = 57,
NSOpenGLPFAColorFloat = 58,
NSOpenGLPFAMultisample = 59,
NSOpenGLPFASupersample = 60,
NSOpenGLPFASampleAlpha = 61,
NSOpenGLPFARendererID = 70,
NSOpenGLPFASingleRenderer = 71,
NSOpenGLPFANoRecovery = 72,
NSOpenGLPFAAccelerated = 73,
NSOpenGLPFAClosestPolicy = 74,
NSOpenGLPFARobust = 75,
NSOpenGLPFABackingStore = 76,
NSOpenGLPFAMPSafe = 78,
NSOpenGLPFAWindow = 80,
NSOpenGLPFAMultiScreen = 81,
NSOpenGLPFACompliant = 83,
NSOpenGLPFAScreenMask = 84,
NSOpenGLPFAPixelBuffer = 90,
NSOpenGLPFARemotePixelBuffer = 91,
NSOpenGLPFAAllowOfflineRenderers= 96,
NSOpenGLPFAAcceleratedCompute = 97,
NSOpenGLPFAVirtualScreenCount =128,
};
typedef uint32_t NSOpenGLPixelFormatAttribute;
@interface NSOpenGLPixelFormat : NSObject {
NSOpenGLPixelFormatAttribute *_attributes;
void *_cglPixelFormat;
GLint _numberOfVirtualScreens;
}
-initWithAttributes:(NSOpenGLPixelFormatAttribute *)attributes;
-initWithAttributes:(const NSOpenGLPixelFormatAttribute *)attributes;
-(void *)CGLPixelFormatObj;
-(int)numberOfVirtualScreens;
-(GLint)numberOfVirtualScreens;
-(void)getValues:(long *)values forAttribute:(NSOpenGLPixelFormatAttribute)attribute forVirtualScreen:(int)screen;

View File

@ -9,42 +9,17 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#import <AppKit/NSRaise.h>
#import <Foundation/NSCoder.h>
#import <Foundation/NSData.h>
#import <OpenGL/OpenGL.h>
@implementation NSOpenGLPixelFormat
static inline BOOL attributeHasArgument(NSOpenGLPixelFormatAttribute attribute){
switch(attribute){
case NSOpenGLPFAAuxBuffers:
case NSOpenGLPFAColorSize:
case NSOpenGLPFAAlphaSize:
case NSOpenGLPFADepthSize:
case NSOpenGLPFAStencilSize:
case NSOpenGLPFAAccumSize:
case NSOpenGLPFARendererID:
case NSOpenGLPFAScreenMask:
return YES;
default:
return NO;
}
}
-initWithAttributes:(NSOpenGLPixelFormatAttribute *)attributes {
int count;
for(count=0;attributes[count]!=0;count++)
if(attributeHasArgument(attributes[count]))
count++;
_attributes=NSZoneMalloc(NULL,sizeof(NSOpenGLPixelFormatAttribute)*(count+1));
for(count=0;(_attributes[count]=attributes[count])!=0;count++)
;
CGLChoosePixelFormat(attributes,(CGLPixelFormatObj *)&_cglPixelFormat,&_numberOfVirtualScreens);
return self;
}
-(void)dealloc {
NSZoneFree(NULL,_attributes);
CGLReleasePixelFormat(_cglPixelFormat);
[super dealloc];
}
@ -83,34 +58,19 @@ static inline BOOL attributeHasArgument(NSOpenGLPixelFormatAttribute attribute){
}
-(void *)CGLPixelFormatObj {
NSUnimplementedMethod();
return 0;
return _cglPixelFormat;
}
-(int)numberOfVirtualScreens {
NSUnimplementedMethod();
return 0;
-(GLint)numberOfVirtualScreens {
return _numberOfVirtualScreens;
}
-(void)getValues:(long *)values forAttribute:(NSOpenGLPixelFormatAttribute)attribute forVirtualScreen:(int)screen {
int i;
for(i=0;_attributes[i]!=0;i++){
BOOL hasArgument=attributeHasArgument(_attributes[i]);
if(_attributes[i]==attribute){
if(hasArgument)
*values=_attributes[i+1];
else
*values=1;
return;
}
if(hasArgument)
i++;
}
*values=0;
GLint glValue=0;
CGLDescribePixelFormat(_cglPixelFormat,screen,attribute,&glValue);
*values=glValue;
}
@end

View File

@ -99,7 +99,12 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
}
- (BOOL)isOpaque {
return YES;
// Cocoa always return YES, until the compositing is improved for transparent surfaces we need to do this
long value=YES;
[[self openGLContext] getValues:&value forParameter:NSOpenGLCPSurfaceOpacity];
return value;
}
- (void)lockFocus {

View File

@ -1,25 +1,25 @@
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd <cjwl@objc.net>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
// Original - Christopher Lloyd <cjwl@objc.net>
#import <AppKit/NSPanel.h>
#import <AppKit/NSAlertPanel.h>
#import <AppKit/NSApplication.h>
#import <CoreGraphics/CGWindow.h>
@implementation NSPanel
+(NSRect)frameRectForContentRect:(NSRect)contentRect styleMask:(unsigned)styleMask {
// we don't do menu adjustments in this class
return contentRect;
NSRect result=CGOutsetRectForNativeWindowBorder(contentRect,styleMask);
return result;
}
+(NSRect)contentRectForFrameRect:(NSRect)frameRect styleMask:(unsigned)styleMask {
return frameRect;
NSRect result=CGInsetRectForNativeWindowBorder(frameRect,styleMask);
return result;
}
-initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(unsigned)backing defer:(BOOL)defer {

View File

@ -152,7 +152,7 @@ APPKIT_EXPORT NSString * const NSWindowDidEndLiveResizeNotification;
BOOL _canHide;
BOOL _displaysWhenScreenProfileChanges;
BOOL _alphaValue;
CGFloat _alphaValue;
BOOL _hasShadow;
BOOL _showsResizeIndicator;
BOOL _showsToolbarButton;
@ -263,7 +263,7 @@ APPKIT_EXPORT NSString * const NSWindowDidEndLiveResizeNotification;
-(NSString *)miniwindowTitle;
-(NSDockTile *)dockTile;
-(NSColor *)backgroundColor;
-(float)alphaValue;
-(CGFloat)alphaValue;
-(NSWindowDepth)depthLimit;
-(NSSize)resizeIncrements;
-(NSSize)contentResizeIncrements;
@ -302,7 +302,7 @@ APPKIT_EXPORT NSString * const NSWindowDidEndLiveResizeNotification;
-(void)setMiniwindowImage:(NSImage *)image;
-(void)setMiniwindowTitle:(NSString *)title;
-(void)setBackgroundColor:(NSColor *)color;
-(void)setAlphaValue:(float)value;
-(void)setAlphaValue:(CGFloat)value;
-(void)setToolbar:(NSToolbar *)toolbar;
-(void)setDefaultButtonCell:(NSButtonCell *)cell;
-(void)setWindowController:(NSWindowController *)value;

View File

@ -75,15 +75,21 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
}
+(NSRect)frameRectForContentRect:(NSRect)contentRect styleMask:(unsigned)styleMask {
NSRect result=CGOutsetRectForNativeWindowBorder(contentRect,styleMask);
if(styleMask!=0)
contentRect.size.height+=[NSMainMenuView menuHeight];
return contentRect;
result.size.height+=[NSMainMenuView menuHeight];
return result;
}
+(NSRect)contentRectForFrameRect:(NSRect)frameRect styleMask:(unsigned)styleMask {
NSRect result=CGInsetRectForNativeWindowBorder(frameRect,styleMask);
if(styleMask!=0)
frameRect.size.height-=[NSMainMenuView menuHeight];
return frameRect;
result.size.height-=[NSMainMenuView menuHeight];
return result;
}
+(float)minFrameWidthWithTitle:(NSString *)title styleMask:(unsigned)styleMask {
@ -124,11 +130,15 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
}
-initWithContentRect:(NSRect)contentRect styleMask:(unsigned)styleMask backing:(unsigned)backing defer:(BOOL)defer {
NSRect backgroundFrame={{0,0},contentRect.size};
NSRect contentViewFrame={{0,0},contentRect.size};
NSRect backgroundFrame;
NSRect contentViewFrame;
_frame=[isa frameRectForContentRect:contentRect styleMask:styleMask];
backgroundFrame.origin=NSMakePoint(0,0);
backgroundFrame.size=_frame.size;
contentViewFrame=[isa contentRectForFrameRect:backgroundFrame styleMask:styleMask];
_savedFrame = _frame;
_styleMask=styleMask;
@ -142,7 +152,7 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
_menu=nil;
if(![self isKindOfClass:[NSPanel class]] && styleMask!=0){
NSRect frame=NSMakeRect(0,contentRect.size.height,contentRect.size.width,[NSMainMenuView menuHeight]);
NSRect frame=NSMakeRect(contentViewFrame.origin.x,NSMaxY(contentViewFrame),contentViewFrame.size.width,[NSMainMenuView menuHeight]);
_menu=[[NSApp mainMenu] copy];
@ -512,7 +522,7 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
return _backgroundColor;
}
-(float)alphaValue {
-(CGFloat)alphaValue {
return _alphaValue;
}
@ -758,11 +768,11 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
}
-(void)setContentSize:(NSSize)size {
NSRect frame,content=[[self class] contentRectForFrameRect:[self frame] styleMask:_styleMask];
NSRect frame,content=[self contentRectForFrameRect:[self frame]];
content.size=size;
frame=[[self class] frameRectForContentRect:content styleMask:_styleMask];
frame=[self frameRectForContentRect:content];
[self setFrame:frame display:YES];
}
@ -905,12 +915,12 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
color=[color copy];
[_backgroundColor release];
_backgroundColor=color;
[_backgroundView setNeedsDisplay:YES];
}
-(void)setAlphaValue:(float)value {
-(void)setAlphaValue:(CGFloat)value {
_alphaValue=value;
// FIXME:
// NSUnimplementedMethod();
[[self platformWindow] setAlphaValue:value];
}
-(void)_toolbarSizeDidChangeFromOldHeight:(CGFloat)oldHeight {
@ -988,7 +998,7 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
-(void)setHasShadow:(BOOL)value {
_hasShadow=value;
// FIXME: implement
[[self platformWindow] setHasShadow:value];
}
-(void)setIgnoresMouseEvents:(BOOL)value {
@ -1025,6 +1035,7 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
-(void)setOpaque:(BOOL)value {
_isOpaque=value;
[[self platformWindow] setOpaque:_isOpaque];
}
-(void)setParentWindow:(NSWindow *)value {
@ -1190,7 +1201,7 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
}
-(int)windowNumber {
return (int)self;
return [[self platformWindow] windowNumber];
}
-(int)gState {
@ -1321,7 +1332,12 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
}
-(NSRect)contentRectForFrameRect:(NSRect)rect {
return [isa contentRectForFrameRect:rect styleMask:[self styleMask]];
NSRect result=[isa contentRectForFrameRect:rect styleMask:[self styleMask]];
if([_toolbar _view]!=nil && ![[_toolbar _view] isHidden])
result.size.height-=[[_toolbar _view] frame].size.height;
return result;
}
-(NSRect)constrainFrameRect:(NSRect)rect toScreen:(NSScreen *)screen {
@ -1744,7 +1760,7 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
[self update];
_isVisible=YES;
[[self platformWindow] placeAboveWindow:[(NSWindow *)relativeTo platformWindow]];
[[self platformWindow] placeAboveWindow:relativeTo];
/* In some instances when a COMMAND is issued from a menu item to bring a
window front, the window is not displayed right (black, incomplete). This
may be the right place to do this, maybe not, further investigation is
@ -1754,7 +1770,7 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
// this is here since it would seem that doing this any earlier will not work.
if(![self isKindOfClass:[NSPanel class]] && ![self isExcludedFromWindowsMenu]) {
[NSApp changeWindowsItem:self title:_title filename:NO];
[NSApp _windowOrderingChange: NSWindowAbove forWindow: self relativeTo: (NSWindow *)relativeTo];
[NSApp _windowOrderingChange: NSWindowAbove forWindow: self relativeTo: [NSApp windowWithWindowNumber:relativeTo]];
}
break;
@ -1763,7 +1779,7 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
[self update];
_isVisible=YES;
[[self platformWindow] placeBelowWindow:[(NSWindow *)relativeTo platformWindow]];
[[self platformWindow] placeBelowWindow:relativeTo];
/* In some instances when a COMMAND is issued from a menu item to bring a
window front, the window is not displayed right (black, incomplete). This
may be the right place to do this, maybe not, further investigation is
@ -1773,7 +1789,7 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
// this is here since it would seem that doing this any earlier will not work.
if(![self isKindOfClass:[NSPanel class]] && ![self isExcludedFromWindowsMenu]) {
[NSApp changeWindowsItem:self title:_title filename:NO];
[NSApp _windowOrderingChange: NSWindowBelow forWindow: self relativeTo: (NSWindow*)relativeTo];
[NSApp _windowOrderingChange: NSWindowBelow forWindow: self relativeTo: [NSApp windowWithWindowNumber:relativeTo]];
}
break;
@ -2630,7 +2646,7 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
location:mousePoint
modifierFlags:[NSEvent modifierFlags]
timestamp:[NSDate timeIntervalSinceReferenceDate]
windowNumber:(int)self
windowNumber:[self windowNumber]
context:[self graphicsContext]
eventNumber:0 // NSEvent currently ignores this.
trackingNumber:(NSInteger)check
@ -2647,7 +2663,7 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
location:mousePoint
modifierFlags:[NSEvent modifierFlags]
timestamp:[NSDate timeIntervalSinceReferenceDate]
windowNumber:(int)self
windowNumber:[self windowNumber]
context:[self graphicsContext]
eventNumber:0 // NSEvent currently ignores this.
trackingNumber:(NSInteger)check
@ -2664,7 +2680,7 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
location:mousePoint
modifierFlags:[NSEvent modifierFlags]
timestamp:[NSDate timeIntervalSinceReferenceDate]
windowNumber:(int)self
windowNumber:[self windowNumber]
context:[self graphicsContext]
eventNumber:0 // NSEvent currently ignores this.
clickCount:0
@ -2681,7 +2697,7 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
location:mousePoint
modifierFlags:[NSEvent modifierFlags]
timestamp:[NSDate timeIntervalSinceReferenceDate]
windowNumber:(int)self
windowNumber:[self windowNumber]
context:[self graphicsContext]
eventNumber:0 // NSEvent currently ignores this.
trackingNumber:(NSInteger)check

View File

@ -30,9 +30,12 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
}
-(void)drawRect:(NSRect)rect {
NSRect bounds=[self bounds];
float cheatSheet = 0;
NSRect bounds=[self bounds];
float cheatSheet = 0;
[[NSColor redColor] setFill];
NSRectFill([self bounds]);
switch(_borderType){
case NSNoBorder:
break;
@ -55,7 +58,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
bounds.size.height += cheatSheet;
[[[self window] backgroundColor] setFill];
NSRectFill(bounds);
NSRectFill([[[self window] contentView] frame]);
}
-(void)resizeSubviewsWithOldSize:(NSSize)oldSize {
@ -76,13 +79,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
[menuView resizeWithOldSuperviewSize:oldSize];
[toolbarView resizeWithOldSuperviewSize:oldSize];
NSRect contentFrame=[self bounds];
if(toolbarView!=nil)
contentFrame.size.height=[toolbarView frame].origin.y-contentFrame.origin.y;
else if(menuView!=nil)
contentFrame.size.height=[menuView frame].origin.y-contentFrame.origin.y;
NSRect contentFrame=[[self window] contentRectForFrameRect:[self bounds]];
[contentView setFrame:contentFrame];
}

View File

@ -1,15 +1,34 @@
#import <OpenGL/OpenGL.h>
#import <Foundation/NSString.h>
#import <Foundation/NSRaise.h>
#import <stdbool.h>
#import <CoreGraphics/CoreGraphics.h>
#import "Win32Window.h"
#import "O2Context_gdi.h"
#import "O2Surface_DIBSection.h"
#import "O2DeviceContext_gdiDIBSection.h"
#import "opengl_dll.h"
struct _CGLContextObj {
GLuint retainCount;
CRITICAL_SECTION lock; // FIXME: this should be converted to the OS*Lock* functions when they appear
HWND window;
HDC dc;
HGLRC glrc;
HGLRC glContext;
int x,y,w,h;
GLint opacity;
int windowNumber;
O2DeviceContext_gdiDIBSection *dibSection;
void *imagePixelData;
};
struct _CGLPixelFormatObj {
GLuint retainCount;
CGLPixelFormatAttribute *attributes;
};
// FIXME: there should be a lock around initialization of this
static DWORD cglThreadStorageIndex(){
static DWORD tlsIndex=TLS_OUT_OF_INDEXES;
@ -23,6 +42,45 @@ static DWORD cglThreadStorageIndex(){
return tlsIndex;
}
static LRESULT CALLBACK windowProcedure(HWND handle,UINT message,WPARAM wParam,LPARAM lParam){
if(message==WM_PAINT)
return 1;
if(message==WM_MOUSEACTIVATE)
return MA_NOACTIVATE;
if(message==WM_ACTIVATE)
return 1;
return DefWindowProc(handle,message,wParam,lParam);
}
void CGLInitializeIfNeeded(){
static bool registerWindowClass=FALSE;
if(!registerWindowClass){
static WNDCLASSEX windowClass;
windowClass.cbSize=sizeof(WNDCLASSEX);
windowClass.style=CS_HREDRAW|CS_VREDRAW|CS_OWNDC|CS_DBLCLKS;
windowClass.lpfnWndProc=windowProcedure;
windowClass.cbClsExtra=0;
windowClass.cbWndExtra=0;
windowClass.hInstance=NULL;
windowClass.hIcon=NULL;
windowClass.hCursor=LoadCursor(NULL,IDC_ARROW);
windowClass.hbrBackground=NULL;
windowClass.lpszMenuName=NULL;
windowClass.lpszClassName="CGLWindow";
windowClass.hIconSm=NULL;
if(RegisterClassEx(&windowClass)==0)
NSLog(@"RegisterClass failed %s %d",__FILE__,__LINE__);
registerWindowClass=TRUE;
}
}
CGL_EXPORT CGLContextObj CGLGetCurrentContext(void) {
CGLContextObj result=TlsGetValue(cglThreadStorageIndex());
@ -34,30 +92,144 @@ CGL_EXPORT CGLError CGLSetCurrentContext(CGLContextObj context) {
if(context==NULL)
opengl_wglMakeCurrent(NULL,NULL);
else
opengl_wglMakeCurrent(context->dc,context->glrc);
opengl_wglMakeCurrent(context->dc,context->glContext);
return kCGLNoError;
}
CGL_EXPORT CGLError CGLCreateContext(CGLPixelFormatObj pixelFormat,HDC dc,CGLContextObj *resultp) {
CGLContextObj result=NSZoneMalloc(NULL,sizeof(struct _CGLContextObj));
static inline bool attributeHasArgument(CGLPixelFormatAttribute attribute){
switch(attribute){
case kCGLPFAAuxBuffers:
case kCGLPFAColorSize:
case kCGLPFAAlphaSize:
case kCGLPFADepthSize:
case kCGLPFAStencilSize:
case kCGLPFAAccumSize:
case kCGLPFARendererID:
case kCGLPFADisplayMask:
return TRUE;
default:
return FALSE;
}
}
static void pfdFromPixelFormat(PIXELFORMATDESCRIPTOR *pfd,CGLPixelFormatObj pixelFormat){
int i,virtualScreen=0;
memset(pfd,0,sizeof(PIXELFORMATDESCRIPTOR));
pfd->nSize=sizeof(PIXELFORMATDESCRIPTOR);
pfd->nVersion=1;
pfd->dwFlags=PFD_SUPPORT_OPENGL|PFD_DRAW_TO_WINDOW|PFD_GENERIC_ACCELERATED|PFD_DOUBLEBUFFER;
pfd->iLayerType=PFD_MAIN_PLANE;
pfd->iPixelType=PFD_TYPE_RGBA;
for(i=0;pixelFormat->attributes[i]!=0;i++){
CGLPixelFormatAttribute attribute=pixelFormat->attributes[i];
if(attributeHasArgument(pixelFormat->attributes[i]))
i++;
switch(attribute){
case kCGLPFAColorSize:
pfd->cColorBits=pixelFormat->attributes[i];
break;
case kCGLPFAAlphaSize:
pfd->cAlphaBits=pixelFormat->attributes[i];
break;
case kCGLPFAAccumSize:
pfd->cAccumBits=pixelFormat->attributes[i];
break;
case kCGLPFADepthSize:
pfd->cDepthBits=pixelFormat->attributes[i];
break;
case kCGLPFAStencilSize:
pfd->cStencilBits=pixelFormat->attributes[i];
break;
case kCGLPFAAuxBuffers:
pfd->cAuxBuffers=pixelFormat->attributes[i];
break;
}
}
}
CGL_EXPORT CGLError CGLCreateContext(CGLPixelFormatObj pixelFormat,CGLContextObj share,CGLContextObj *resultp) {
CGLContextObj result=NSZoneCalloc(NULL,1,sizeof(struct _CGLContextObj));
PIXELFORMATDESCRIPTOR pfd;
int pfIndex;
CGLInitializeIfNeeded();
result->retainCount=1;
pfdFromPixelFormat(&pfd,pixelFormat);
InitializeCriticalSection(&(result->lock));
result->dc=dc;
result->glrc=opengl_wglCreateContext(dc);
result->window=CreateWindowEx(WS_EX_TOOLWINDOW,"CGLWindow","",WS_POPUP,0,0,1,1,NULL,NULL,GetModuleHandle(NULL),NULL);
SetWindowPos(result->window,HWND_TOP,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
result->dc=GetDC(result->window);
pfIndex=ChoosePixelFormat(result->dc,&pfd);
if(!SetPixelFormat(result->dc,pfIndex,&pfd))
NSLog(@"SetPixelFormat failed");
result->glContext=opengl_wglCreateContext(result->dc);
result->opacity=1;
*resultp=result;
return kCGLNoError;
}
CGL_EXPORT CGLError CGLDestroyContext(CGLContextObj context) {
if(context!=NULL){
CGL_EXPORT CGLContextObj CGLRetainContext(CGLContextObj context) {
if(context==NULL)
return NULL;
context->retainCount++;
return context;
}
CGL_EXPORT void CGLReleaseContext(CGLContextObj context) {
if(context==NULL)
return;
context->retainCount--;
if(context->retainCount==0){
if(CGLGetCurrentContext()==context)
CGLSetCurrentContext(NULL);
ReleaseDC(context->window,context->dc);
DestroyWindow(context->window);
[context->dibSection release];
DeleteCriticalSection(&(context->lock));
opengl_wglDeleteContext(context->glrc);
opengl_wglDeleteContext(context->glContext);
NSZoneFree(NULL,context);
}
}
CGL_EXPORT GLuint CGLGetContextRetainCount(CGLContextObj context) {
if(context==NULL)
return 0;
return context->retainCount;
}
CGL_EXPORT CGLError CGLDestroyContext(CGLContextObj context) {
CGLReleaseContext(context);
return kCGLNoError;
}
@ -72,6 +244,47 @@ CGL_EXPORT CGLError CGLUnlockContext(CGLContextObj context) {
return kCGLNoError;
}
static bool usesChildWindow(CGLContextObj context){
return (context->opacity!=0)?TRUE:FALSE;
}
static void adjustFrameInParent(CGLContextObj context,Win32Window *parentWindow,GLint *x,GLint *y,GLint *w,GLint *h){
if(parentWindow!=nil){
CGFloat top,left,bottom,right;
CGNativeBorderFrameWidthsForStyle([parentWindow styleMask],&top,&left,&bottom,&right);
*y=[parentWindow frame].size.height-(*y+*h);
*y-=top;
*x-=left;
}
}
static void adjustInParentForSurfaceOpacity(CGLContextObj context){
GLint x=context->x;
GLint y=context->y;
GLint w=context->w;
GLint h=context->h;
if(usesChildWindow(context)){
Win32Window *parentWindow=[Win32Window windowWithWindowNumber:context->windowNumber];
HWND parentHandle=[parentWindow windowHandle];
SetProp(context->window,"self",parentWindow);
SetParent(context->window,parentHandle);
ShowWindow(context->window,SW_SHOWNOACTIVATE);
adjustFrameInParent(context,parentWindow,&x,&y,&w,&h);
}
else {
ShowWindow(context->window,SW_HIDE);
SetProp(context->window,"self",NULL);
SetParent(context->window,NULL);
}
MoveWindow(context->window,x,y,w,h,NO);
}
CGL_EXPORT CGLError CGLSetParameter(CGLContextObj context,CGLContextParameter parameter,const GLint *value) {
switch(parameter){
@ -85,18 +298,188 @@ CGL_EXPORT CGLError CGLSetParameter(CGLContextObj context,CGLContextParameter pa
wglSwapIntervalEXT(*value);
break;
case kCGLCPSurfaceFrame:;
context->x=value[0];
context->y=value[1];
context->w=value[2];
context->h=value[3];
if(context->imagePixelData!=NULL){
[context->dibSection release];
context->imagePixelData=NULL;
}
context->dibSection=[[O2DeviceContext_gdiDIBSection alloc] initWithWidth:context->w height:-context->h deviceContext:nil];
context->imagePixelData=[context->dibSection bitmapBytes];
adjustInParentForSurfaceOpacity(context);
break;
case kCGLCPSurfaceOpacity:
context->opacity=*value;
adjustInParentForSurfaceOpacity(context);
break;
case kCGLCPWindowNumber:
context->windowNumber=*value;
adjustInParentForSurfaceOpacity(context);
break;
default:
NSUnimplementedFunction();
break;
}
return kCGLNoError;
}
CGL_EXPORT CGLError CGLGetParameter(CGLContextObj context,CGLContextParameter parameter,GLint *value) {
switch(parameter){
case kCGLCPSurfaceOpacity:
*value=context->opacity;
break;
default:
break;
}
return kCGLNoError;
}
CGL_EXPORT CGLError CGLGetParameter(CGLContextObj context,CGLContextParameter parameter,GLint *value) {
NSUnimplementedFunction();
CGLError CGLFlushDrawable(CGLContextObj context) {
if(usesChildWindow(context))
SwapBuffers(context->dc);
else if(context->windowNumber!=0 && context->imagePixelData!=NULL){
Win32Window *parentWindow=[Win32Window windowWithWindowNumber:context->windowNumber];
HWND parentHandle=[parentWindow windowHandle];
O2Context *o2Context=[parentWindow cgContext];
GLint pixelsWide=context->w;
GLint pixelsHigh=context->h;
int bitsPerPixel=32;
int samplesPerPixel=4;
int bytesPerRow=pixelsWide*4;
GLuint bufferId;
// glFinish(); supposedly this is not needed
opengl_glReadPixels(0,0,pixelsWide,pixelsHigh,GL_BGRA,GL_UNSIGNED_INT_8_8_8_8_REV,context->imagePixelData);
int r,c;
unsigned char *imageRow=context->imagePixelData;
for(r=0;r<pixelsHigh;r++,imageRow+=bytesPerRow){
for(c=0;c<bytesPerRow;c+=4){
unsigned int b=imageRow[c+0];
unsigned int g=imageRow[c+1];
unsigned int r=imageRow[c+2];
unsigned int a=imageRow[c+3];
imageRow[c+2]=alphaMultiply(r,a);
imageRow[c+1]=alphaMultiply(g,a);
imageRow[c+0]=alphaMultiply(b,a);
}
}
O2DeviceContext_gdi *deviceContext=nil;
if([o2Context isKindOfClass:[O2Context_gdi class]])
deviceContext=[(O2Context_gdi *)o2Context deviceContext];
else {
O2Surface *surface=[o2Context surface];
if([surface isKindOfClass:[O2Surface_DIBSection class]])
deviceContext=[(O2Surface_DIBSection *)surface deviceContext];
}
BLENDFUNCTION blend;
blend.BlendOp=AC_SRC_OVER;
blend.BlendFlags=0;
blend.SourceConstantAlpha=255;
blend.AlphaFormat=AC_SRC_ALPHA;
int y=[parentWindow frame].size.height-(context->y+context->h);
AlphaBlend([deviceContext dc],context->x,y,context->w,context->h,[context->dibSection dc],0,0,context->w,context->h,blend);
}
return kCGLNoError;
}
static int attributesCount(const CGLPixelFormatAttribute *attributes){
int result;
for(result=0;attributes[result]!=0;result++)
if(attributeHasArgument(attributes[result]))
result++;
return result;
}
CGLError CGLChoosePixelFormat(const CGLPixelFormatAttribute *attributes,CGLPixelFormatObj *pixelFormatp,GLint *numberOfScreensp) {
CGLPixelFormatObj result=malloc(sizeof(struct _CGLPixelFormatObj));
int i,count=attributesCount(attributes);
result->retainCount=1;
result->attributes=malloc(sizeof(CGLPixelFormatAttribute)*count);
for(i=0;i<count;i++)
result->attributes[i]=attributes[i];
*pixelFormatp=result;
*numberOfScreensp=1;
return kCGLNoError;
}
CGLPixelFormatObj CGLRetainPixelFormat(CGLPixelFormatObj pixelFormat) {
if(pixelFormat==NULL)
return NULL;
pixelFormat->retainCount++;
return pixelFormat;
}
void CGLReleasePixelFormat(CGLPixelFormatObj pixelFormat) {
if(pixelFormat==NULL)
return;
pixelFormat->retainCount--;
if(pixelFormat->retainCount==0){
free(pixelFormat->attributes);
free(pixelFormat);
}
}
CGLError CGLDestroyPixelFormat(CGLPixelFormatObj pixelFormat) {
CGLReleasePixelFormat(pixelFormat);
return kCGLNoError;
}
GLuint CGLGetPixelFormatRetainCount(CGLPixelFormatObj pixelFormat) {
return pixelFormat->retainCount;
}
CGL_EXPORT CGLError CGLDescribePixelFormat(CGLPixelFormatObj pixelFormat,GLint screenNumber,CGLPixelFormatAttribute attribute,GLint *valuesp) {
int i;
for(i=0;pixelFormat->attributes[i]!=0;i++){
bool hasArgument=attributeHasArgument(pixelFormat->attributes[i]);
if(pixelFormat->attributes[i]==attribute){
if(hasArgument)
*valuesp=pixelFormat->attributes[i+1];
else
*valuesp=1;
return kCGLNoError;
}
if(hasArgument)
i++;
}
*valuesp=0;
return kCGLNoError;
}

View File

@ -1,14 +0,0 @@
#import <Foundation/NSObject.h>
#import <AppKit/NSOpenGLDrawable.h>
#import <windows.h>
@class NSView,NSOpenGLPixelFormat;
@interface NSOpenGLDrawable_gdiView : NSOpenGLDrawable {
NSView *_view;
HWND _windowHandle;
HDC _dc;
PAINTSTRUCT ps;
}
@end

View File

@ -1,249 +0,0 @@
#import "NSOpenGLDrawable_gdiView.h"
#import <AppKit/NSOpenGLPixelFormat.h>
#import <AppKit/NSWindow-Private.h>
#import <AppKit/Win32Window.h>
#import <OpenGL/OpenGL.h>
@interface NSOpenGLDrawable(GDI)
@end
@implementation NSOpenGLDrawable(GDI)
+allocWithZone:(NSZone *)zone {
return NSAllocateObject([NSOpenGLDrawable_gdiView class],0,NULL);
}
@end
@implementation NSOpenGLDrawable_gdiView
-(LRESULT)windowProcedure:(UINT)message wParam:(WPARAM)wParam
lParam:(LPARAM)lParam {
switch(message){
case WM_MOUSEACTIVATE: return MA_NOACTIVATE;
case WM_PAINT:{
PAINTSTRUCT paintStruct;
RECT updateRECT;
if(GetUpdateRect(_windowHandle,&updateRECT,NO)){
BeginPaint(_windowHandle,&paintStruct);
[_view display];
EndPaint(_windowHandle,&paintStruct);
}
}
return 0;
default:
break;
}
return DefWindowProc(_windowHandle,message,wParam,lParam);
}
static LRESULT CALLBACK windowProcedure(HWND handle,UINT message,WPARAM wParam,LPARAM lParam){
NSAutoreleasePool *pool=[NSAutoreleasePool new];
NSOpenGLDrawable_gdiView *self=GetProp(handle,"self");
LRESULT result;
if(self==nil)
result=DefWindowProc(handle,message,wParam,lParam);
else
result=[self windowProcedure:message wParam:wParam lParam:lParam];
[pool release];
return result;
}
+(void)initialize {
if(self==[NSOpenGLDrawable_gdiView class]){
static WNDCLASS windowClass;
windowClass.style=CS_HREDRAW|CS_VREDRAW|CS_OWNDC|CS_DBLCLKS;
windowClass.lpfnWndProc=windowProcedure;
windowClass.cbClsExtra=0;
windowClass.cbWndExtra=0;
windowClass.hInstance=NULL;
windowClass.hIcon=NULL;
windowClass.hCursor=LoadCursor(NULL,IDC_ARROW);
windowClass.hbrBackground=NULL;
windowClass.lpszMenuName=NULL;
windowClass.lpszClassName=NULL;
windowClass.lpszClassName="NSWin32OpenGLWindow";
windowClass.hIcon=NULL;
if(RegisterClass(&windowClass)==0)
NSLog(@"RegisterClass failed %s %d",__FILE__,__LINE__);
}
}
static inline long attributeLong(NSOpenGLPixelFormat *pixelFormat,NSOpenGLPixelFormatAttribute attribute,int virtualScreen){
long value=0;
[pixelFormat getValues:&value forAttribute:attribute forVirtualScreen:virtualScreen];
return value;
}
static inline BOOL attributeBool(NSOpenGLPixelFormat *pixelFormat,NSOpenGLPixelFormatAttribute attribute,int virtualScreen){
return attributeLong(pixelFormat,attribute,virtualScreen)?YES:NO;
}
static void pfdFromPixelFormat(PIXELFORMATDESCRIPTOR *pfd,NSOpenGLPixelFormat *pixelFormat){
int virtualScreen=0;
pfd->nSize=sizeof(PIXELFORMATDESCRIPTOR);
pfd->nVersion=1;
pfd->dwFlags=PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER;
if(attributeBool(pixelFormat,NSOpenGLPFADoubleBuffer,virtualScreen))
pfd->dwFlags|=PFD_DOUBLEBUFFER;
if(attributeBool(pixelFormat,NSOpenGLPFAStereo,virtualScreen))
pfd->dwFlags|=PFD_STEREO;
if(attributeBool(pixelFormat,NSOpenGLPFAOffScreen,virtualScreen))
pfd->dwFlags|=PFD_DRAW_TO_BITMAP;
if(attributeBool(pixelFormat,NSOpenGLPFAAccelerated,virtualScreen))
pfd->dwFlags|=PFD_GENERIC_ACCELERATED;
if(attributeBool(pixelFormat,NSOpenGLPFAWindow,virtualScreen))
pfd->dwFlags|=PFD_DRAW_TO_WINDOW;
pfd->iPixelType=PFD_TYPE_RGBA;
pfd->cColorBits=attributeLong(pixelFormat,NSOpenGLPFAColorSize,virtualScreen);
pfd->cRedBits=0;
pfd->cRedShift=0;
pfd->cGreenBits=0;
pfd->cGreenShift=0;
pfd->cBlueBits=0;
pfd->cBlueShift=0;
pfd->cAlphaBits=attributeLong(pixelFormat,NSOpenGLPFAAlphaSize,virtualScreen);
pfd->cAlphaShift=0;
pfd->cAccumBits=attributeLong(pixelFormat,NSOpenGLPFAAccumSize,virtualScreen);
pfd->cAccumRedBits=0;
pfd->cAccumGreenBits=0;
pfd->cAccumBlueBits=0;
pfd->cAccumAlphaBits=0;
pfd->cDepthBits=attributeLong(pixelFormat,NSOpenGLPFADepthSize,virtualScreen);
pfd->cStencilBits=attributeLong(pixelFormat,NSOpenGLPFAStencilSize,virtualScreen);
pfd->cAuxBuffers=attributeLong(pixelFormat,NSOpenGLPFAAuxBuffers,virtualScreen);
pfd->iLayerType=PFD_MAIN_PLANE;
pfd->bReserved=0;
pfd->dwLayerMask=0; // ignored
pfd->dwVisibleMask=0;
pfd->dwDamageMask=0; // ignored
}
-initWithPixelFormat:(NSOpenGLPixelFormat *)pixelFormat view:(NSView *)view {
PIXELFORMATDESCRIPTOR pfd;
int pfIndex;
pfdFromPixelFormat(&pfd,pixelFormat);
_windowHandle=CreateWindowEx(WS_EX_TOOLWINDOW,"NSWin32OpenGLWindow", "", WS_CLIPCHILDREN | WS_CLIPSIBLINGS| WS_POPUP|WS_CHILD,
0, 0, 500, 500,
NULL,NULL, GetModuleHandle (NULL),NULL);
SetProp(_windowHandle,"self",self);
_dc=GetDC(_windowHandle);
pfIndex=ChoosePixelFormat(_dc,&pfd);
if(!SetPixelFormat(_dc,pfIndex,&pfd))
NSLog(@"SetPixelFormat failed");
SetWindowPos(_windowHandle,HWND_TOP,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
_view=view;
[self updateWithView:view];
return self;
}
-(void)dealloc {
SetProp(_windowHandle,"self",nil);
ReleaseDC(_windowHandle,_dc);
DestroyWindow(_windowHandle);
_windowHandle=NULL;
[super dealloc];
}
-(NSWindow *)appkitWindow {
return [_view window];
}
-(void)adjustEventLocation:(NSPoint *)location {
NSWindow *window=[_view window];
Win32Window *parent=(Win32Window *)[window platformWindow];
if(![_view isFlipped])
location->y=([_view frame].size.height-1)-location->y;
RECT myRect,parentRect;
GetWindowRect(_windowHandle,&myRect);
GetWindowRect([parent windowHandle],&parentRect);
location->x+=(myRect.left-parentRect.left);
location->y+=(parentRect.bottom-myRect.bottom);
}
-(HDC)dc {
return _dc;
}
-(CGLContextObj)createGLContext {
CGLContextObj result=NULL;
CGLError error;
CGL_EXPORT CGLError CGLCreateContext(CGLPixelFormatObj pixelFormat,HDC dc,CGLContextObj *resultp);
if((error=CGLCreateContext(NULL,[self dc],&result))!=kCGLNoError)
NSLog(@"CGLCreateContext failed with %d in %s %d",error,__FILE__,__LINE__);
return result;
}
-(void)invalidate {
}
-(void)updateWithView:(NSView *)view {
NSWindow *window=[view window];
Win32Window *parent=(Win32Window *)[window platformWindow];
HWND parentHandle=[parent windowHandle];
RECT clientRECT;
int parentHeight;
if(parentHandle!=NULL)
SetParent(_windowHandle,parentHandle);
NSRect frame=[view frame];
frame=[[view superview] convertRect:frame toView:nil];
GetClientRect(parentHandle,&clientRECT);
parentHeight=clientRECT.bottom-clientRECT.top;
MoveWindow(_windowHandle, frame.origin.x, parentHeight-(frame.origin.y+frame.size.height),frame.size.width, frame.size.height,YES);
}
-(void)makeCurrentWithGLContext:(CGLContextObj)glContext {
CGLError error;
if((error=CGLSetCurrentContext(glContext))!=kCGLNoError)
NSLog(@"CGLSetCurrentContext failed with %d in %s %d",error,__FILE__,__LINE__);
}
-(void)clearCurrentWithGLContext:(CGLContextObj)glContext {
CGLError error;
if((error=CGLSetCurrentContext(NULL))!=kCGLNoError)
NSLog(@"CGLSetCurrentContext failed with %d in %s %d",error,__FILE__,__LINE__);
}
-(void)swapBuffers {
SwapBuffers(_dc);
}
@end

View File

@ -1135,22 +1135,6 @@ static void zeroBytes(void *bytes,int size){
return YES;
}
-(void)drawBackingContext:(O2Context *)other size:(NSSize)size {
O2DeviceContext_gdi *deviceContext=nil;
if([other isKindOfClass:[O2Context_gdi class]])
deviceContext=[(O2Context_gdi *)other deviceContext];
else {
O2Surface *surface=[other surface];
if([surface isKindOfClass:[O2Surface_DIBSection class]])
deviceContext=[(O2Surface_DIBSection *)surface deviceContext];
}
if(deviceContext!=nil)
[self drawDeviceContext:deviceContext inRect:NSMakeRect(0,0,size.width,size.height) ctm:O2AffineTransformIdentity];
}
-(void)flush {
GdiFlush();
}

View File

@ -13,21 +13,23 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
@implementation O2DeviceContext_gdiDIBSection
-initWithWidth:(size_t)width height:(size_t)height deviceContext:(O2DeviceContext_gdi *)compatible bitsPerPixel:(int)bpp {
[self initWithDC:CreateCompatibleDC([compatible dc])];
HDC compatibleDC=(compatible!=nil)?[compatible dc]:GetDC(NULL);
[self initWithDC:CreateCompatibleDC(compatibleDC)];
_compatible=[compatible retain];
struct {
BITMAPV4HEADER bitmapInfo;
RGBQUAD colors[256+3];
} dibInfo;
HBITMAP probe=CreateCompatibleBitmap([compatible dc],1,1);
HBITMAP probe=CreateCompatibleBitmap(compatibleDC,1,1);
memset(&dibInfo,0,sizeof(dibInfo));
dibInfo.bitmapInfo.bV4Size=sizeof(BITMAPV4HEADER);
if(!GetDIBits([compatible dc],probe,0,1,NULL,(BITMAPINFO *)&dibInfo,DIB_RGB_COLORS))
if(!GetDIBits(compatibleDC,probe,0,1,NULL,(BITMAPINFO *)&dibInfo,DIB_RGB_COLORS))
NSLog(@"GetDIBits failed");
if(!GetDIBits([compatible dc],probe,0,1,NULL,(BITMAPINFO *)&dibInfo,DIB_RGB_COLORS))
if(!GetDIBits(compatibleDC,probe,0,1,NULL,(BITMAPINFO *)&dibInfo,DIB_RGB_COLORS))
NSLog(@"GetDIBits failed");
if((_bitsPerPixel=bpp)==0)
@ -43,8 +45,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
dibInfo.bitmapInfo.bV4BitCount=32;
dibInfo.bitmapInfo.bV4V4Compression=BI_RGB;
_bitmap=CreateDIBSection([compatible dc],(BITMAPINFO *)&dibInfo,DIB_RGB_COLORS,&_bits,NULL,0);
_bitmap=CreateDIBSection(compatibleDC,(BITMAPINFO *)&dibInfo,DIB_RGB_COLORS,&_bits,NULL,0);
SelectObject(_dc,_bitmap);
return self;

View File

@ -165,8 +165,8 @@ static BOOL CALLBACK monitorEnumerator(HMONITOR hMonitor,HDC hdcMonitor,LPRECT r
info.cbSize = sizeof(info);
getMonitorInfo(hMonitor,&info);
NSRect frame = NSRectFromRECT( info.rcMonitor );
NSRect visibleFrame = NSRectFromRECT( info.rcWork );
NSRect frame = CGRectFromRECT( info.rcMonitor );
NSRect visibleFrame = CGRectFromRECT( info.rcWork );
CGFloat bottom = GetSystemMetrics( SM_YVIRTUALSCREEN ) + GetSystemMetrics( SM_CYVIRTUALSCREEN );
frame.origin.y = bottom - (frame.origin.y + frame.size.height);
@ -596,7 +596,7 @@ The values should be upgraded to something which is more generic to implement, p
if(isKeypad)
modifierFlags|=NSNumericPadKeyMask;
event=[NSEvent keyEventWithType:type location:location modifierFlags:modifierFlags timestamp:[NSDate timeIntervalSinceReferenceDate] windowNumber:(int)window context:nil characters:characters charactersIgnoringModifiers:charactersIgnoringModifiers isARepeat:isARepeat keyCode:keyCode];
event=[NSEvent keyEventWithType:type location:location modifierFlags:modifierFlags timestamp:[NSDate timeIntervalSinceReferenceDate] windowNumber:[window windowNumber] context:nil characters:characters charactersIgnoringModifiers:charactersIgnoringModifiers isARepeat:isARepeat keyCode:keyCode];
[self postEvent:event atStart:NO];
return YES;
}
@ -696,7 +696,7 @@ The values should be upgraded to something which is more generic to implement, p
if([platformWindow respondsToSelector:@selector(appkitWindow)])
window=[platformWindow performSelector:@selector(appkitWindow)];
if(![window isKindOfClass:[NSWindow class]])
window=nil;
@ -798,6 +798,14 @@ The values should be upgraded to something which is more generic to implement, p
location.x=deviceLocation.x;
location.y=deviceLocation.y;
if(msg.hwnd!=[platformWindow windowHandle]){
RECT rect;
GetClientRect(msg.hwnd,&rect);
location.x+=rect.left;
location.y+=rect.top;
}
[platformWindow adjustEventLocation:&location];
modifierFlags=[self currentModifierFlags];

View File

@ -13,21 +13,23 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#define WINVER 0x501 // XP drop shadow constants
#import <windows.h>
@class NSEvent;
@class O2Context_gdi;
@interface Win32Window : CGWindow {
NSRect _frame;
CGRect _frame;
BOOL _isOpaque;
BOOL _hasShadow;
CGFloat _alphaValue;
HWND _handle;
NSSize _size;
O2Context *_cgContext;
O2Context_gdi *_cgContext;
CGSBackingStoreType _backingType;
CGSBackingStoreType _backingType;
O2Context *_backingContext;
CGLContextObj _cglContext;
NSString *_title;
BOOL _isLayered;
BOOL _isOpenGL;
BOOL _ignoreMinMaxMessage;
BOOL _sentBeginSizing;
BOOL _disableDisplay;
@ -38,7 +40,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
NSMutableDictionary *_deviceDictionary;
}
-initWithFrame:(NSRect)frame styleMask:(unsigned)styleMask isPanel:(BOOL)isPanel backingType:(CGSBackingStoreType)backingType;
-initWithFrame:(CGRect)frame styleMask:(unsigned)styleMask isPanel:(BOOL)isPanel backingType:(CGSBackingStoreType)backingType;
-(void)setDelegate:delegate;
-delegate;
@ -46,13 +48,15 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
-(void)invalidate;
-(HWND)windowHandle;
-(unsigned)styleMask;
-(CGRect)frame;
-(void)setStyleMask:(unsigned)mask;
-(void)setTitle:(NSString *)title;
-(void)setFrame:(NSRect)frame;
-(void)setFrame:(CGRect)frame;
-(void)showWindowForAppActivation:(NSRect)frame;
-(void)hideWindowForAppDeactivation:(NSRect)frame;
-(void)showWindowForAppActivation:(CGRect)frame;
-(void)hideWindowForAppDeactivation:(CGRect)frame;
-(void)hideWindow;
-(void)showWindowWithoutActivation;
@ -77,8 +81,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
@end
static inline NSRect NSRectFromRECT(RECT rect) {
NSRect result;
void CGNativeBorderFrameWidthsForStyle(unsigned styleMask,CGFloat *top,CGFloat *left,CGFloat *bottom,CGFloat *right);
static inline CGRect CGRectFromRECT(RECT rect) {
CGRect result;
result.origin.x=rect.left;
result.origin.y=rect.top;
@ -88,3 +94,14 @@ static inline NSRect NSRectFromRECT(RECT rect) {
return result;
}
static inline RECT RECTFromCGRect(CGRect rect) {
RECT result;
result.top=rect.origin.y;
result.left=rect.origin.x;
result.bottom=result.top+rect.size.height;
result.right=result.left+rect.size.width;
return result;
}

View File

@ -19,21 +19,27 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#import <AppKit/NSApplication.h>
#import <AppKit/NSDrawerWindow.h>
#import <QuartzCore/CABackingRenderer.h>
#import "O2Surface_DIBSection.h"
@implementation Win32Window
-(float)primaryScreenHeight {
return GetSystemMetrics(SM_CYSCREEN);
}
-(NSRect)flipOnWin32Screen:(NSRect)rect {
rect.origin.y=[self primaryScreenHeight]-(rect.origin.y+rect.size.height);
static CGRect convertFrameToWin32ScreenCoordinates(CGRect rect){
rect.origin.y=GetSystemMetrics(SM_CYSCREEN)-(rect.origin.y+rect.size.height);
return rect;
}
static DWORD Win32ExtendedStyleForStyleMask(unsigned styleMask,BOOL isPanel,BOOL isLayered) {
static CGRect convertFrameFromWin32ScreenCoordinates(CGRect rect){
rect.origin.y=GetSystemMetrics(SM_CYSCREEN)-(rect.origin.y+rect.size.height);
return rect;
}
static bool isLayeredWindowStyleMask(unsigned styleMask){
return (styleMask&(NSDocModalWindowMask|NSBorderlessWindowMask))?TRUE:FALSE;
}
static DWORD Win32ExtendedStyleForStyleMask(unsigned styleMask,BOOL isPanel) {
DWORD result=0;
if(styleMask==NSBorderlessWindowMask)
@ -47,14 +53,14 @@ static DWORD Win32ExtendedStyleForStyleMask(unsigned styleMask,BOOL isPanel,BOOL
if(isPanel)
result|=WS_EX_NOACTIVATE;
if(isLayered)
if(isLayeredWindowStyleMask(styleMask))
result|=/*CS_DROPSHADOW|*/WS_EX_LAYERED;
return result/*|0x80000*/ ;
}
static DWORD Win32StyleForStyleMask(unsigned styleMask,BOOL isPanel) {
DWORD result=WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
DWORD result=isLayeredWindowStyleMask(styleMask)?0:WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
if(styleMask==NSBorderlessWindowMask)
result|=WS_POPUP;
@ -89,72 +95,69 @@ static DWORD Win32StyleForStyleMask(unsigned styleMask,BOOL isPanel) {
return result;
}
static const char *Win32ClassNameForStyleMask(unsigned styleMask) {
if(styleMask==NSBorderlessWindowMask)
return "NSWin32PopUpWindow";
else
return "NSWin32StandardWindow";
}
-(RECT)win32FrameRECTFromContentRECT:(RECT)rect {
DWORD style=Win32StyleForStyleMask(_styleMask,_isPanel);
DWORD exStyle=Win32ExtendedStyleForStyleMask(_styleMask,_isPanel,_isLayered);
AdjustWindowRectEx(&rect,style,NO,exStyle);
return rect;
}
-(NSRect)win32FrameForRect:(NSRect)frame {
NSRect moveTo=[self flipOnWin32Screen:frame];
RECT winRect;
winRect.top=moveTo.origin.y;
winRect.left=moveTo.origin.x;
winRect.bottom=moveTo.origin.y+moveTo.size.height;
winRect.right=moveTo.origin.x+moveTo.size.width;
winRect=[self win32FrameRECTFromContentRECT:winRect];
moveTo.origin.y=winRect.top;
moveTo.origin.x=winRect.left;
moveTo.size.width=(winRect.right-winRect.left);
moveTo.size.height=(winRect.bottom-winRect.top);
return moveTo;
}
-(RECT)win32ContentRECTFromFrameRECT:(RECT)rect {
DWORD style=Win32StyleForStyleMask(_styleMask,_isPanel);
DWORD exStyle=Win32ExtendedStyleForStyleMask(_styleMask,_isPanel,_isLayered);
RECT delta;
void CGNativeBorderFrameWidthsForStyle(unsigned styleMask,CGFloat *top,CGFloat *left,CGFloat *bottom,CGFloat *right){
RECT delta;
delta.top=0;
delta.left=0;
delta.bottom=100;
delta.right=100;
AdjustWindowRectEx(&delta,style,NO,exStyle);
AdjustWindowRectEx(&delta,Win32StyleForStyleMask(styleMask,NO),NO,Win32ExtendedStyleForStyleMask(styleMask,NO));
*top=-delta.top;
*left=-delta.left;
*bottom=delta.bottom-100;
*right=delta.right-100;
}
rect.top+=-delta.top;
rect.left+=-delta.left;
rect.bottom-=(delta.bottom-100);
rect.right-=(delta.right-100);
CGRect CGInsetRectForNativeWindowBorder(CGRect frame,unsigned styleMask){
CGFloat top,left,bottom,right;
CGNativeBorderFrameWidthsForStyle(styleMask,&top,&left,&bottom,&right);
frame.origin.x+=left;
frame.origin.y+=bottom;
frame.size.width-=left+right;
frame.size.height-=top+bottom;
return frame;
}
return rect;
CGRect CGOutsetRectForNativeWindowBorder(CGRect frame,unsigned styleMask){
CGFloat top,left,bottom,right;
CGNativeBorderFrameWidthsForStyle(styleMask,&top,&left,&bottom,&right);
frame.origin.x-=left;
frame.origin.y-=bottom;
frame.size.width+=left+right;
frame.size.height+=top+bottom;
return frame;
}
static const char *Win32ClassNameForStyleMask(unsigned styleMask,bool hasShadow) {
if(styleMask==NSBorderlessWindowMask)
return hasShadow?"Win32BorderlessWindowWithShadow":"Win32BorderlessWindow";
else
return "NSWin32StandardWindow";
}
-(void)createWindowHandle {
CGRect win32Frame=convertFrameToWin32ScreenCoordinates(_frame);
DWORD style=Win32StyleForStyleMask(_styleMask,_isPanel);
DWORD extendStyle=Win32ExtendedStyleForStyleMask(_styleMask,_isPanel,_isLayered);
NSRect win32Frame=[self win32FrameForRect:_frame];
const char *className=Win32ClassNameForStyleMask(_styleMask);
DWORD extendStyle=Win32ExtendedStyleForStyleMask(_styleMask,_isPanel);
const char *className=Win32ClassNameForStyleMask(_styleMask,_hasShadow);
_handle=CreateWindowEx(extendStyle,className,"", style,
win32Frame.origin.x, win32Frame.origin.y,
win32Frame.size.width, win32Frame.size.height,
NULL,NULL, GetModuleHandle (NULL),NULL);
if(_title!=nil)
SetWindowTextW(_handle,(const unichar *)[_title cStringUsingEncoding:NSUnicodeStringEncoding]);
SetProp(_handle,"self",self);
}
@ -164,38 +167,17 @@ static const char *Win32ClassNameForStyleMask(unsigned styleMask) {
_handle=NULL;
}
-initWithFrame:(NSRect)frame styleMask:(unsigned)styleMask isPanel:(BOOL)isPanel backingType:(CGSBackingStoreType)backingType {
-initWithFrame:(CGRect)frame styleMask:(unsigned)styleMask isPanel:(BOOL)isPanel backingType:(CGSBackingStoreType)backingType {
_frame=frame;
_isOpaque=YES;
_hasShadow=YES;
_alphaValue=1.0;
_styleMask=styleMask;
_isPanel=isPanel;
_isLayered=(_styleMask&(NSDocModalWindowMask|NSBorderlessWindowMask))?YES:NO;
_isOpenGL=NO;
_frame=frame;
[self createWindowHandle];
if(_isOpenGL){
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd,0,sizeof(pfd));
pfd.nSize=sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion=1;
pfd.dwFlags=PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER|PFD_GENERIC_ACCELERATED|PFD_DRAW_TO_WINDOW;
pfd.iPixelType=PFD_TYPE_RGBA;
pfd.cColorBits=24;
pfd.cAlphaBits=8;
pfd.iLayerType=PFD_MAIN_PLANE;
HDC dc=GetDC(_handle);
int pfIndex=ChoosePixelFormat(dc,&pfd);
if(!SetPixelFormat(dc,pfIndex,&pfd))
NSLog(@"SetPixelFormat failed at %s %d",__FILE__,__LINE__);
ReleaseDC(_handle,dc);
}
_size=frame.size;
_cgContext=nil;
_backingType=backingType;
@ -208,6 +190,7 @@ static const char *Win32ClassNameForStyleMask(unsigned styleMask) {
_ignoreMinMaxMessage=NO;
_sentBeginSizing=NO;
_deviceDictionary=[NSMutableDictionary new];
NSString *check=[[NSUserDefaults standardUserDefaults] stringForKey:@"CGBackingRasterizer"];
if([check isEqual:@"Onyx"] || [check isEqual:@"GDI"])
[_deviceDictionary setObject:check forKey:@"CGContext"];
@ -248,14 +231,14 @@ static const char *Win32ClassNameForStyleMask(unsigned styleMask) {
-(O2Context *)createCGContextIfNeeded {
if(_cgContext==nil)
_cgContext=[O2Context createContextWithSize:_size window:self];
_cgContext=(O2Context_gdi *)[O2Context createContextWithSize:_frame.size window:self];
return _cgContext;
}
-(O2Context *)createBackingCGContextIfNeeded {
if(_backingContext==nil){
_backingContext=[O2Context createBackingContextWithSize:_size context:[self createCGContextIfNeeded] deviceDictionary:_deviceDictionary];
_backingContext=[O2Context createBackingContextWithSize:_frame.size context:[self createCGContextIfNeeded] deviceDictionary:_deviceDictionary];
}
return _backingContext;
@ -274,9 +257,9 @@ static const char *Win32ClassNameForStyleMask(unsigned styleMask) {
}
}
-(void)invalidateContextsWithNewSize:(NSSize)size forceRebuild:(BOOL)forceRebuild {
if(!NSEqualSizes(_size,size) || forceRebuild){
_size=size;
-(void)invalidateContextsWithNewSize:(CGSize)size forceRebuild:(BOOL)forceRebuild {
if(!NSEqualSizes(_frame.size,size) || forceRebuild){
_frame.size=size;
[_cgContext release];
_cgContext=nil;
[_backingContext release];
@ -285,38 +268,64 @@ static const char *Win32ClassNameForStyleMask(unsigned styleMask) {
}
}
-(void)invalidateContextsWithNewSize:(NSSize)size {
-(void)invalidateContextsWithNewSize:(CGSize)size {
[self invalidateContextsWithNewSize:size forceRebuild:NO];
}
-(CGRect)frame {
return _frame;
}
-(unsigned)styleMask {
return _styleMask;
}
-(void)setStyleMask:(unsigned)mask {
_styleMask=mask;
_isLayered=(_styleMask&(NSDocModalWindowMask|NSBorderlessWindowMask))?YES:NO;
[self destroyWindowHandle];
[self createWindowHandle];
}
-(void)setTitle:(NSString *)title {
SetWindowTextW(_handle,(const unichar *)[title cStringUsingEncoding:NSUnicodeStringEncoding]);
title=[title copy];
[_title release];
_title=title;
SetWindowTextW(_handle,(const unichar *)[_title cStringUsingEncoding:NSUnicodeStringEncoding]);
}
-(void)setFrame:(NSRect)frame {
-(void)setFrame:(CGRect)frame {
_frame=frame;
NSRect moveTo=[self win32FrameForRect:_frame];
CGRect moveTo=convertFrameToWin32ScreenCoordinates(_frame);
_ignoreMinMaxMessage=YES;
MoveWindow(_handle, moveTo.origin.x, moveTo.origin.y,
moveTo.size.width, moveTo.size.height,YES);
MoveWindow(_handle, moveTo.origin.x, moveTo.origin.y,moveTo.size.width, moveTo.size.height,YES);
_ignoreMinMaxMessage=NO;
[self invalidateContextsWithNewSize:frame.size];
}
-(void)sheetOrderFrontFromFrame:(NSRect)frame aboveWindow:(CGWindow *)aboveWindow {
NSRect moveTo=[self win32FrameForRect:_frame];
-(void)setOpaque:(BOOL)value {
_isOpaque=value;
[self flushBuffer];
}
-(void)setAlphaValue:(CGFloat)value {
_alphaValue=value;
[self flushBuffer];
}
-(void)setHasShadow:(BOOL)value {
_hasShadow=value;
[self destroyWindowHandle];
[self createWindowHandle];
}
-(void)sheetOrderFrontFromFrame:(CGRect)frame aboveWindow:(CGWindow *)aboveWindow {
CGRect moveTo=convertFrameToWin32ScreenCoordinates(_frame);
POINT origin={moveTo.origin.x,moveTo.origin.y};
SIZE sizeWnd = {_size.width, 1};
SIZE sizeWnd = {_frame.size.width, 1};
POINT ptSrc = {0, 0};
UpdateLayeredWindow(_handle, NULL, &origin, &sizeWnd, [(O2Context_gdi *)_backingContext dc], &ptSrc, 0, NULL, ULW_OPAQUE);
@ -325,45 +334,45 @@ static const char *Win32ClassNameForStyleMask(unsigned styleMask) {
_disableDisplay=NO;
int i;
int interval=(_size.height/400.0)*100;
int chunk=_size.height/(interval/2);
int interval=(_frame.size.height/400.0)*100;
int chunk=_frame.size.height/(interval/2);
if(chunk<1)
chunk=1;
for(i=0;i<_size.height;i+=chunk){
sizeWnd = (SIZE){_size.width, i};
ptSrc = (POINT){0, _size.height-i};
for(i=0;i<_frame.size.height;i+=chunk){
sizeWnd = (SIZE){_frame.size.width, i};
ptSrc = (POINT){0, _frame.size.height-i};
UpdateLayeredWindow(_handle, NULL, &origin, &sizeWnd, [(O2Context_gdi *)_backingContext dc], &ptSrc, 0, NULL, ULW_OPAQUE);
Sleep(1);
}
UpdateLayeredWindow(_handle, NULL, &origin, &sizeWnd, [(O2Context_gdi *)_backingContext dc], &ptSrc, 0, NULL, ULW_OPAQUE);
}
-(void)sheetOrderOutToFrame:(NSRect)frame {
-(void)sheetOrderOutToFrame:(CGRect)frame {
int i;
int interval=(_size.height/400.0)*100;
int chunk=_size.height/(interval/2);
int interval=(_frame.size.height/400.0)*100;
int chunk=_frame.size.height/(interval/2);
if(chunk<1)
chunk=1;
for(i=0;i<_size.height;i+=chunk){
SIZE sizeWnd = {_size.width, _size.height-i};
for(i=0;i<_frame.size.height;i+=chunk){
SIZE sizeWnd = {_frame.size.width, _frame.size.height-i};
POINT ptSrc = {0, i};
UpdateLayeredWindow(_handle, NULL, NULL, &sizeWnd, [(O2Context_gdi *)_backingContext dc], &ptSrc, 0, NULL, ULW_OPAQUE);
Sleep(1);
}
SIZE sizeWnd = {_size.width, 0};
SIZE sizeWnd = {_frame.size.width, 0};
POINT ptSrc = {0, i};
UpdateLayeredWindow(_handle, NULL, NULL, &sizeWnd, [(O2Context_gdi *)_backingContext dc], &ptSrc, 0, NULL, ULW_OPAQUE);
}
-(void)showWindowForAppActivation:(NSRect)frame {
-(void)showWindowForAppActivation:(CGRect)frame {
[self showWindowWithoutActivation];
}
-(void)hideWindowForAppDeactivation:(NSRect)frame {
-(void)hideWindowForAppDeactivation:(CGRect)frame {
[self hideWindow];
}
@ -377,12 +386,10 @@ static const char *Win32ClassNameForStyleMask(unsigned styleMask) {
-(void)bringToTop {
if(_styleMask==NSBorderlessWindowMask){
SetWindowPos(_handle,HWND_TOPMOST,0,0,0,0,
SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
SetWindowPos(_handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
}
else {
SetWindowPos(_handle,HWND_TOP,0,0,0,0,
SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
SetWindowPos(_handle,HWND_TOP,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
}
}
@ -424,11 +431,28 @@ static const char *Win32ClassNameForStyleMask(unsigned styleMask) {
return IsIconic(_handle);
}
#if 0
-(CGLContextObj)createCGLContextObjIfNeeded {
if(_cglContext==NULL){
PIXELFORMATDESCRIPTOR pfd;
CGLError error;
HDC dc=GetDC(_handle);
HDC dc=GetDC(_handle);
memset(&pfd,0,sizeof(pfd));
pfd.nSize=sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion=1;
pfd.dwFlags=PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER|PFD_GENERIC_ACCELERATED|PFD_DRAW_TO_WINDOW;
pfd.iPixelType=PFD_TYPE_RGBA;
pfd.cColorBits=24;
pfd.cAlphaBits=8;
pfd.iLayerType=PFD_MAIN_PLANE;
int pfIndex=ChoosePixelFormat(dc,&pfd);
if(!SetPixelFormat(dc,pfIndex,&pfd))
NSLog(@"SetPixelFormat failed at %s %d",__FILE__,__LINE__);
CGL_EXPORT CGLError CGLCreateContext(CGLPixelFormatObj pixelFormat,HDC dc,CGLContextObj *resultp);
if((error=CGLCreateContext(NULL,dc,&_cglContext))!=kCGLNoError)
@ -464,24 +488,23 @@ static const char *Win32ClassNameForStyleMask(unsigned styleMask) {
return YES;
}
#endif
-(void)flushBuffer {
if(_isOpenGL){
if([self openGLFlushBuffer])
return;
}
if(_isLayered){
BLENDFUNCTION blend = {0,0,0,0};
blend.BlendOp = AC_SRC_OVER;
blend.SourceConstantAlpha = 255;
blend.AlphaFormat = AC_SRC_ALPHA;
-(void)flushBuffer {
if(isLayeredWindowStyleMask(_styleMask)){
BLENDFUNCTION blend;
BYTE constantAlpha=MAX(0,MIN(_alphaValue*255,255));
SIZE sizeWnd = {_size.width, _size.height};
blend.BlendOp=AC_SRC_OVER;
blend.BlendFlags=0;
blend.SourceConstantAlpha=constantAlpha;
blend.AlphaFormat=AC_SRC_ALPHA;
SIZE sizeWnd = {_frame.size.width, _frame.size.height};
POINT ptSrc = {0, 0};
// UpdateLayeredWindow(_handle, NULL, NULL, &sizeWnd, [(O2Context_gdi *)_backingContext dc], &ptSrc, 0, &blend, ULW_ALPHA);
UpdateLayeredWindow(_handle, NULL, NULL, &sizeWnd, [(O2Context_gdi *)_backingContext dc], &ptSrc, 0, &blend, ULW_OPAQUE);
DWORD flags=(_isOpaque && constantAlpha==255)?ULW_OPAQUE:ULW_ALPHA;
UpdateLayeredWindow(_handle, NULL, NULL, &sizeWnd, [(O2Context_gdi *)_backingContext dc], &ptSrc, 0, &blend, flags);
}
else {
switch(_backingType){
@ -491,24 +514,45 @@ static const char *Win32ClassNameForStyleMask(unsigned styleMask) {
break;
case CGSBackingStoreBuffered:
if(_backingContext!=nil)
[_cgContext drawBackingContext:_backingContext size:_size];
break;
if(_backingContext!=nil){
int dstX=0;
int dstY=0;
int width=_frame.size.width;
int height=_frame.size.height;
O2Context *other=_backingContext;
O2DeviceContext_gdi *deviceContext=nil;
if([other isKindOfClass:[O2Context_gdi class]])
deviceContext=[(O2Context_gdi *)other deviceContext];
else {
O2Surface *surface=[other surface];
if([surface isKindOfClass:[O2Surface_DIBSection class]])
deviceContext=[(O2Surface_DIBSection *)surface deviceContext];
}
CGFloat top,left,bottom,right;
CGNativeBorderFrameWidthsForStyle([self styleMask],&top,&left,&bottom,&right);
if(deviceContext!=nil)
BitBlt([_cgContext dc],0,0,width,height,[deviceContext dc],left,top,SRCCOPY);
}
}
}
}
-(NSPoint)convertPOINTLToBase:(POINTL)point {
NSPoint result;
-(CGPoint)convertPOINTLToBase:(POINTL)point {
CGPoint result;
result.x=point.x;
result.y=point.y;
result.y=[self primaryScreenHeight]-result.y;
result.y=GetSystemMetrics(SM_CYSCREEN)-result.y;
return result;
}
-(NSPoint)mouseLocationOutsideOfEventStream {
-(CGPoint)mouseLocationOutsideOfEventStream {
POINT winPoint;
GetCursorPos(&winPoint);
@ -516,8 +560,14 @@ static const char *Win32ClassNameForStyleMask(unsigned styleMask) {
return [self convertPOINTLToBase:winPoint];
}
-(void)adjustEventLocation:(NSPoint *)location {
location->y=(_size.height-1)-location->y;
-(void)adjustEventLocation:(CGPoint *)location {
CGFloat top,left,bottom,right;
CGNativeBorderFrameWidthsForStyle([self styleMask],&top,&left,&bottom,&right);
location->x+=left;
location->y+=top;
location->y=(_frame.size.height-1)-location->y;
}
-(void)sendEvent:(CGEvent *)eventX {
@ -535,36 +585,33 @@ static const char *Win32ClassNameForStyleMask(unsigned styleMask) {
FlashWindow(_handle,TRUE);
}
-(CGRect)queryFrame {
RECT rect;
if(GetWindowRect(_handle,&rect)==0){
NSLog(@"GetWindowRect failed, handle=%p, %s %d",_handle,__FILE__,__LINE__);
return CGRectMake(0,0,0,0);
}
return convertFrameFromWin32ScreenCoordinates(CGRectFromRECT(rect));
}
-(void)_GetWindowRectDidSize:(BOOL)didSize {
RECT windowRect;
RECT clientRect;
NSRect frame;
GetWindowRect(_handle,&windowRect);
windowRect=[self win32ContentRECTFromFrameRECT:windowRect];
GetClientRect(_handle,&clientRect);
windowRect.right=windowRect.left+clientRect.right;
windowRect.bottom=windowRect.top+clientRect.bottom;
frame=[self flipOnWin32Screen:NSRectFromRECT(windowRect)];
CGRect frame=[self queryFrame];
if(frame.size.width>0 && frame.size.height>0)
[_delegate platformWindow:self frameChanged:frame didSize:didSize];
}
-(int)WM_SIZE_wParam:(WPARAM)wParam lParam:(LPARAM)lParam {
NSSize contentSize={LOWORD(lParam),HIWORD(lParam)};
// BOOL equalSizes=NSEqualSizes(_backingSize,contentSize);
CGSize contentSize={LOWORD(lParam),HIWORD(lParam)};
if(contentSize.width>0 && contentSize.height>0){
[self invalidateContextsWithNewSize:contentSize];
[self invalidateContextsWithNewSize:[self queryFrame].size];
[self _GetWindowRectDidSize:YES];
// if(equalSizes)
// return 0;
switch(_backingType){
case CGSBackingStoreRetained:
@ -590,7 +637,7 @@ static const char *Win32ClassNameForStyleMask(unsigned styleMask) {
-(int)WM_PAINT_wParam:(WPARAM)wParam lParam:(LPARAM)lParam {
PAINTSTRUCT paintStruct;
RECT updateRECT;
// NSRect displayRect;
// CGRect displayRect;
if(GetUpdateRect(_handle,&updateRECT,NO)){
// The update rect is usually empty
@ -654,8 +701,8 @@ static const char *Win32ClassNameForStyleMask(unsigned styleMask) {
}
-(int)WM_SIZING_wParam:(WPARAM)wParam lParam:(LPARAM)lParam {
RECT rect=[self win32ContentRECTFromFrameRECT:*(RECT *)lParam];
NSSize size=NSMakeSize(rect.right-rect.left,rect.bottom-rect.top);
RECT rect=*(RECT *)lParam;
CGSize size=NSMakeSize(rect.right-rect.left,rect.bottom-rect.top);
if(!_sentBeginSizing)
[_delegate platformWindowWillBeginSizing:self];
@ -690,7 +737,7 @@ static const char *Win32ClassNameForStyleMask(unsigned styleMask) {
break;
}
*(RECT *)lParam=[self win32FrameRECTFromContentRECT:rect];
*(RECT *)lParam=rect;
return 0;
}
@ -789,7 +836,9 @@ static LRESULT CALLBACK windowProcedure(HWND handle,UINT message,WPARAM wParam,L
}
static void initializeWindowClass(WNDCLASS *class){
class->style=CS_HREDRAW|CS_VREDRAW|CS_OWNDC|CS_DBLCLKS;
/* WS_EX_LAYERED windows can not use CS_OWNDC or CS_CLASSDC */
/* OpenGL windows want CS_OWNDC, so don't use OpenGL on a top level window */
class->style=CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS;
class->lpfnWndProc=windowProcedure;
class->cbClsExtra=0;
class->cbWndExtra=0;
@ -807,30 +856,38 @@ static void initializeWindowClass(WNDCLASS *class){
NSString *path=[[NSBundle mainBundle] pathForResource:name ofType:@"ico"];
HICON icon=(path==nil)?NULL:LoadImage(NULL,[path fileSystemRepresentation],IMAGE_ICON,0,0,LR_DEFAULTCOLOR|LR_LOADFROMFILE);
static WNDCLASS _standardWindowClass,_popupWindowClass,_glWindowClass;
static WNDCLASS _standardWindowClass,_borderlessWindowClass,_borderlessWindowClassWithShadow;
OSVERSIONINFOEX osVersion;
osVersion.dwOSVersionInfoSize=sizeof(osVersion);
GetVersionEx((OSVERSIONINFO *)&osVersion);
if(icon==NULL)
icon=LoadImage(NULL,IDI_APPLICATION,IMAGE_ICON,0,0,LR_DEFAULTCOLOR|LR_SHARED);
initializeWindowClass(&_standardWindowClass);
initializeWindowClass(&_borderlessWindowClass);
initializeWindowClass(&_borderlessWindowClassWithShadow);
_standardWindowClass.lpszClassName="NSWin32StandardWindow";
_standardWindowClass.hIcon=icon;
_borderlessWindowClass.lpszClassName="Win32BorderlessWindow";
_borderlessWindowClassWithShadow.lpszClassName="Win32BorderlessWindowWithShadow";
// XP or higher
if((osVersion.dwMajorVersion==5 && osVersion.dwMinorVersion>=1) || osVersion.dwMajorVersion>5){
_borderlessWindowClassWithShadow.style|=CS_DROPSHADOW;
}
if(RegisterClass(&_standardWindowClass)==0)
NSLog(@"RegisterClass failed");
initializeWindowClass(&_popupWindowClass);
_popupWindowClass.style|=CS_SAVEBITS;
osVersion.dwOSVersionInfoSize=sizeof(osVersion);
GetVersionEx((OSVERSIONINFO *)&osVersion);
// XP or higher
if((osVersion.dwMajorVersion==5 && osVersion.dwMinorVersion>=1) || osVersion.dwMajorVersion>5){
_popupWindowClass.style|=CS_DROPSHADOW;
}
_popupWindowClass.lpszClassName="NSWin32PopUpWindow";
if(RegisterClass(&_popupWindowClass)==0)
if(RegisterClass(&_borderlessWindowClass)==0)
NSLog(@"RegisterClass failed");
if(RegisterClass(&_borderlessWindowClassWithShadow)==0)
NSLog(@"RegisterClass failed");
}
}

View File

@ -8,3 +8,4 @@ HGLRC opengl_wglGetCurrentContext(void);
BOOL opengl_wglMakeCurrent(HDC dc,HGLRC hglrc);
BOOL opengl_wglMakeCurrent(HDC dc,HGLRC hglrc);
PROC opengl_wglGetProcAddress(LPCSTR name);
void opengl_glReadPixels(GLint x,GLint y,GLsizei width,GLsizei height,GLenum format,GLenum type,GLvoid *pixels);

View File

@ -78,4 +78,19 @@ PROC opengl_wglGetProcAddress(LPCSTR name){
return function(name);
}
void opengl_glReadPixels(GLint x,GLint y,GLsizei width,GLsizei height,GLenum format,GLenum type,GLvoid *pixels) {
static typeof(glReadPixels) *function=NULL;
if(function==NULL){
HANDLE library=LoadLibrary("OPENGL32");
function=(typeof(function))GetProcAddress(library,"glReadPixels");
}
if(function==NULL)
return;
return function(x,y,width,height,format,type,pixels);
}

View File

@ -50,7 +50,7 @@ CGL_EXPORT CGLError CGLCreateContext(CGLPixelFormatObj pixelFormat,Display *dpy,
if(vis==NULL)
return kCGLBadDisplay;
CGLContextObj result=NSZoneMalloc(NULL,sizeof(struct _CGLContextObj));
CGLContextObj result=malloc(sizeof(struct _CGLContextObj));
pthread_mutex_init(&(result->lock),NULL);
result->dpy=dpy;
@ -69,7 +69,7 @@ CGL_EXPORT CGLError CGLDestroyContext(CGLContextObj context) {
pthread_mutex_destroy(&(context->lock));
glXDestroyContext(context->dpy, context->glc);
NSZoneFree(NULL,context);
free(context);
}
return kCGLNoError;

View File

@ -13,7 +13,7 @@
#import <AppKit/NSRaise.h>
#import <X11/Xutil.h>
#import <Foundation/NSException.h>
#import <Onyx2D/O2Context.h>
#import "O2Context_cairo.h"
#import <Onyx2D/O2Surface.h>
#import <QuartzCore/CARenderer.h>
@ -236,7 +236,8 @@ CGL_EXPORT CGLError CGLCreateContext(CGLPixelFormatObj pixelFormat,Display *dpy,
_mapped=NO;
}
-(void)placeAboveWindow:(X11Window *)other {
-(void)placeAboveWindow:(int)otherNumber {
X11Window *other=[X11Window windowWithWindowNumber:otherNumber];
[self ensureMapped];
if(!other) {
@ -248,7 +249,8 @@ CGL_EXPORT CGLError CGLCreateContext(CGLPixelFormatObj pixelFormat,Display *dpy,
}
}
-(void)placeBelowWindow:(X11Window *)other {
-(void)placeBelowWindow:(int)otherNumber {
X11Window *other=[X11Window windowWithWindowNumber:otherNumber];
[self ensureMapped];
if(!other) {

View File

@ -28,6 +28,9 @@ typedef enum {
-(void)setStyleMask:(unsigned)mask;
-(void)setTitle:(NSString *)title;
-(void)setFrame:(NSRect)frame;
-(void)setOpaque:(BOOL)value;
-(void)setAlphaValue:(CGFloat)value;
-(void)setHasShadow:(BOOL)value;
-(void)sheetOrderFrontFromFrame:(NSRect)frame aboveWindow:(CGWindow *)aboveWindow;
-(void)sheetOrderOutToFrame:(NSRect)frame;
@ -38,8 +41,12 @@ typedef enum {
-(void)hideWindow;
-(void)showWindowWithoutActivation;
-(void)placeAboveWindow:(CGWindow *)other;
-(void)placeBelowWindow:(CGWindow *)other;
+windowWithWindowNumber:(int)windowNumber;
-(int)windowNumber;
-(void)placeAboveWindow:(int)otherNumber;
-(void)placeBelowWindow:(int)otherNumber;
-(void)makeKey;
-(void)captureEvents;
@ -85,3 +92,7 @@ typedef enum {
-(void)platformWindowDidInvalidateCGContext:(CGWindow *)window;
@end
CGRect CGInsetRectForNativeWindowBorder(CGRect frame,unsigned styleMask);
CGRect CGOutsetRectForNativeWindowBorder(CGRect frame,unsigned styleMask);

View File

@ -42,6 +42,18 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
O2InvalidAbstractInvocation();
}
-(void)setOpaque:(BOOL)value {
O2InvalidAbstractInvocation();
}
-(void)setAlphaValue:(CGFloat)value {
O2InvalidAbstractInvocation();
}
-(void)setHasShadow:(BOOL)value {
O2InvalidAbstractInvocation();
}
-(void)sheetOrderFrontFromFrame:(NSRect)frame aboveWindow:(CGWindow *)aboveWindow {
O2InvalidAbstractInvocation();
}
@ -66,12 +78,20 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
O2InvalidAbstractInvocation();
}
// these suck
+windowWithWindowNumber:(int)windowNumber {
return (id)windowNumber;
}
-(void)placeAboveWindow:(CGWindow *)other {
-(int)windowNumber {
return (int)self;
}
-(void)placeAboveWindow:(int)other {
O2InvalidAbstractInvocation();
}
-(void)placeBelowWindow:(CGWindow *)other {
-(void)placeBelowWindow:(int)other {
O2InvalidAbstractInvocation();
}

View File

@ -16111,6 +16111,7 @@
buildSettings = {
ARCHS = i386;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = stabs;
DEPLOYMENT_LOCATION = YES;
DSTROOT = /;
EXECUTABLE_SUFFIX = .1.0.dll;

View File

@ -155,8 +155,6 @@ O2ColorRef O2ContextFillColor(O2ContextRef self);
// temporary
-(void)drawBackingContext:(O2Context *)other size:(O2Size)size;
-(void)setAntialiasingQuality:(int)value;
-(void)setWordSpacing:(O2Float)spacing;
-(void)setTextLeading:(O2Float)leading;

View File

@ -301,10 +301,6 @@ O2ColorRef O2ContextFillColor(O2ContextRef self) {
// temporary
-(void)drawBackingContext:(O2Context *)other size:(O2Size)size {
O2InvalidAbstractInvocation();
}
-(void)setAntialiasingQuality:(int)value {
[currentState(self) setAntialiasingQuality:value];
}

View File

@ -48,9 +48,55 @@ typedef enum {
kCGLBadConnection=10017,
} CGLError;
enum {
kCGLPFAAllRenderers = 1,
kCGLPFADoubleBuffer = 5,
kCGLPFAStereo = 6,
kCGLPFAAuxBuffers = 7,
kCGLPFAColorSize = 8,
kCGLPFAAlphaSize = 11,
kCGLPFADepthSize = 12,
kCGLPFAStencilSize = 13,
kCGLPFAAccumSize = 14,
kCGLPFAMinimumPolicy = 51,
kCGLPFAMaximumPolicy = 52,
kCGLPFAOffScreen = 53,
kCGLPFAFullScreen = 54,
kCGLPFASampleBuffers = 55,
kCGLPFASamples = 56,
kCGLPFAAuxDepthStencil = 57,
kCGLPFAColorFloat = 58,
kCGLPFAMultisample = 59,
kCGLPFASupersample = 60,
kCGLPFASampleAlpha = 61,
kCGLPFARendererID = 70,
kCGLPFASingleRenderer = 71,
kCGLPFANoRecovery = 72,
kCGLPFAAccelerated = 73,
kCGLPFAClosestPolicy = 74,
kCGLPFARobust = 75,
kCGLPFABackingStore = 76,
kCGLPFAMPSafe = 78,
kCGLPFAWindow = 80,
kCGLPFAMultiScreen = 81,
kCGLPFACompliant = 83,
kCGLPFADisplayMask = 84,
kCGLPFAPBuffer = 90,
kCGLPFARemotePBuffer = 91,
kCGLPFAAllowOfflineRenderers= 96,
kCGLPFAAcceleratedCompute = 97,
kCGLPFAVirtualScreenCount =128,
};
typedef uint32_t CGLPixelFormatAttribute;
typedef enum {
kCGLCPSwapInterval =222,
kCGLCPSurfaceOpacity=236,
// internal, do not use
kCGLCPSurfaceFrame=500,
kCGLCPWindowNumber=501,
} CGLContextParameter;
typedef struct _CGLContextObj *CGLContextObj;

View File

@ -6,8 +6,11 @@
#import <OpenGL/CGLTypes.h>
#import <OpenGL/CGLCurrent.h>
// CGLCreateContext is currently platform specific
// CGL_EXPORT CGLError CGLCreateContext(CGLPixelFormatObj pixelFormat,CGLContextObj other,CGLContextObj *result);
CGL_EXPORT CGLError CGLCreateContext(CGLPixelFormatObj pixelFormat,CGLContextObj share,CGLContextObj *result);
CGL_EXPORT CGLContextObj CGLRetainContext(CGLContextObj context);
CGL_EXPORT void CGLReleaseContext(CGLContextObj context);
CGL_EXPORT GLuint CGLGetContextRetainCount(CGLContextObj context);
CGL_EXPORT CGLError CGLDestroyContext(CGLContextObj context);
@ -16,3 +19,11 @@ CGL_EXPORT CGLError CGLUnlockContext(CGLContextObj context);
CGL_EXPORT CGLError CGLSetParameter(CGLContextObj context,CGLContextParameter parameter,const GLint *value);
CGL_EXPORT CGLError CGLGetParameter(CGLContextObj context,CGLContextParameter parameter,GLint *value);
CGL_EXPORT CGLError CGLFlushDrawable(CGLContextObj context);
CGL_EXPORT CGLError CGLChoosePixelFormat(const CGLPixelFormatAttribute *attributes,CGLPixelFormatObj *pixelFormatp,GLint *numberOfScreensp);
CGL_EXPORT CGLPixelFormatObj CGLRetainPixelFormat(CGLPixelFormatObj pixelFormat);
CGL_EXPORT void CGLReleasePixelFormat(CGLPixelFormatObj pixelFormat);
CGL_EXPORT CGLError CGLDestroyPixelFormat(CGLPixelFormatObj pixelFormat);
CGL_EXPORT GLuint CGLGetPixelFormatRetainCount(CGLPixelFormatObj pixelFormat);
CGL_EXPORT CGLError CGLDescribePixelFormat(CGLPixelFormatObj pixelFormat,GLint screenNumber,CGLPixelFormatAttribute attribute,GLint *valuep);