lazarus/components/opengl/glcocoanscontext.pas
maxim 21fb0ba3d9 Merged revision(s) 59014-59015 #121f09456b-#121f09456b, 59017 #4590a4f178, 59019-59029 #c002ba7df4-#c002ba7df4, 59033-59036 #7a0195312f-#7a0195312f, 59039 #b3b559273c, 59057-59058 #f000038a2b-#f000038a2b, 59060-59063 #23619be5e4-#23619be5e4, 59065 #4d1d0ac454, 59086-59088 #6da9bb3520-#6da9bb3520, 59102-59107 #55d94ff91b-#55d94ff91b, 59129-59132 #b6534f43ef-#b6534f43ef, 59134-59135 #c086c56cde-#c086c56cde, 59140-59141 #fdfa68c0e2-#fdfa68c0e2, 59163-59164 #61657c490e-#61657c490e, 59178-59179 #aa5acf09a9-#aa5acf09a9, 59183 #ed5c165da1, 59185 #a4503bccc0, 59187-59189 #9c1f561955-#9c1f561955, 59195-59196 #bbd07791c8-#bbd07791c8, 59205-59206 #5bb6685e21-#5bb6685e21, 59231-59238 #9b98baa793-#9b98baa793, 59247 #a9e858cf2a, 59249-59252 #003ad96f6d-#003ad96f6d, 59273 #18dbe2687b, 59329-59331 #a341d94c64-#a341d94c64, 59362-59363 #62db4e537d-#62db4e537d, 59380 #b5d3a2e2ab, 59397 #b135ccf3ac, 59492 #f8e9e6474b, 59620 #ed79e7c140, 59627-59628 #7382f53434-#7382f53434, 59645-59646 #f3a0a55e46-#f3a0a55e46, 59674 #477db40534, 59725-59726 #c7ae0282b6-#c7ae0282b6, 59746-59756 #d0e6eb11b6-#d0e6eb11b6 from trunk:
cocoa: rename frame view to handleview. HandleView would be used as HWND for any composed control
........
cocoa: remove lclIsHandle method completetly. Handle use is defined on WS level and stored with the callback object
........
cocoa: prevent MainMenu from being set on a designed form
........
cocoa: switch paintstruct back from dynamic (originally changed back in 2012) to static. Saving on heap change call
........
cocoa: remove the direct reference between TCocoaWindow and LCLForm
........
cocoa: initial support for enabling/disabling menus on ShowModal
........
cocoa: fix compilation issue made by the prev commit
........
cocoa: restore filtering of ampersands in menu titles
........
cocoa: support of BorderStyle property for the common rectangular controls
........
cocoa: adding support for borderstyle of a customchecklist box
........
cocoa: adding cocoawschecklst.pas to the list of units in lcl.lpk file
........
cocoa: extend support of CGContextRef (for macOS 10.10 and later). Adding init of context for custom drawn dropdownlist
........
cocoa: resolve mem leak in listbox custom draw
........
cocoa: update mainmenu implementaiton. Added support for Hide Others and Show All menu items
........
cocoa: preventing NSTabView to appear in chain of responders. That should prevent key event loss. (a very odd cocoa feature)
........
cocoa: update combobox (NSComboBox) to retain the selection after reopenning the popup window
........
cocoa: added code, but not enforcing it for change in border style of TComboBox
........
cocoa: fix in TListBox.setItemIndex to replace the selection, rather than extend it. #34290
........
cocoa: reduce the amount of focus (responders) related code. Process the focus handling in NSWindow only (rather than each control individually). Update tab switch notification to report tab change prior to focus switch
........
cocoa: replacing default keyDown handling routine, with a cusomized one. The reason: unable to fully predict the event processing within Cocoa, causing some keys to be lost
........
cocoa: removing tabControl workaround
........
cocoa: working around macOS problem with transactions during making a keyWindow
........
cocoa: simplify and more robust mac to LCL virtual key codes conversion
........
cocoa: update keyDown handling for custom controls
........
cocoa: remove debugging output
........
cocoa: reverting an attemtped workaround (r59060) to fix the problem with a modality during windows activate
........
cocoa: fix the compiler warning
........
cocoa: an attempt to resolve the issue during crashes, if a (cocoa) modal window is called during Activation of a window
........
cocoa: support for Services menu
........
cocoa: restore radio-menues functionality. #34310
........
cooca: allow autosized columns to be user sized as well. #34311. Patch by David Jenkins
........
cocoa: proper selection of an image index for a sub-item in listview. #34313. Patch by David Jenkins
........
cocoa: adding the support for TDisplayCode to determine a rectangle in ListView. Based on patch by David Jenkins. #34312
........
cocoa: update attachmenu process, so NSMenu can be added into NSMenuItem as a subitem. #34293
........
cocoa: making sure that window with popup_parent would stay above when attaching to the parent (and remain a keywindow). #34301
........
cocoa: update modality using modalitySessions (to keep event processing in place)
........
cocoa: removed the previously added hack for modal window on activation. Doesn't work on every macOS, as well as causing some issues
........
cocoa: improve tracking of menu changes when modal dialogs are switching. Merged menu routines from coocaojbect.inc into cocoaint.pas
........
cocoa: update menus switch in modal. The proper menu history save for modal windows without a menu
........
cocoa: restoring keyboard processing events for NSWindow. #34301
........
cocoa: adding support for focus rect of TMemo
........
cocoa: minimze table view invalidation on add / delete items. #34319. Patch by David Jenkins
........
cocoa: restore key processing, to let hot keys to triggers... odd
........
cocoa: propagating LM_CONTEXTMENU to parents
........
cocoa: the first oddity of modal sessions. Context Menu would not call an action to indicate the menu item selected #34325
........
cocoa: using a single place to process keyDown event related to LCL callbacks
........
cocoa: update key event handling. Not all characters from macOS are suitable for LCL KeyPress
........
cocoa: adding exception for processing key equivalents and return key, if a first responder is capable of processing the return key. #34354
........
cocoa: additional control over cocoa window levels
........
cocoa: implementing owner drawn for status bar panels. #34338
........
cocoa: removed redundant key emulation events (introduced with #32829). With the latest changes in key handling events those are no longer needed
........
cocoa: updating drawing of ownerdrawn statusbar
........
cocoa: update key processing, adding more exception for non-printable keys
........
cocoa: adding a check for TCocoaTextLayout.Draw procedure. Do nothing if string is empty or invalid. Prevents SynEdit crashes for unicode characters
........
cocoa: fix the conversion between WS to LCL tab index #34361
........
cocoa: update insertion and removal of rows in cocoa table (fix implementation from #34319)
........
cocoa: memory management - removing unneeded autorelease pools. There's one global and one per each event
........
cocoa: memory management - removing unneeded autorelease pools. There's one global and one per each event
........
cocoa: fix for a memory leak in overlay (designer) form
........
cocoa: memory management - removing unneeded autorelease pools. There's one global and one per each event
........
cocoa: fix controls leaking spinedit
........
cocoa: improve mouse handling of spinedit
........
cocoa: dereferncing tracked control earlier
........
cocoa: fix drawing overlays - resing overlay designer view to the form
........
cocoa: fix the combobox itemindex when the new text is not the list
........
cocoa: update deallocation of read-only combobox
........
cocoa: fix compiler warning
........
cocoa: preventing too high values on measuring text with soft-line breaks. #34382
........
cocoa: fix combobox onchange which fixes also lazreport designer on second opening and also fixes issue #33800
........
cocoa: prevent listview premature handle allocation. Fixes the issue of IDE not being able to add list view onto a designer form
........
cocoa: workaround for a problem with 64-bit boolean parameter passing (see fpc issue #34411 for details)
........
cocoa: additional methods for handling fpc issue #34411
........
cocoa: additional methods (nsview, nscontrol, nsbuttons, nstextfield) for handling fpc issue #34411
........
cocoa: using Device colorspace, instead of Calibrated colorspace for GDI objects. #34427
........
cocoa: update the behaviour of GetFocus function to use HandleView stored with callback object. #34450
........
cocoa: preventing spinedit value from being change while destroying the handle. #34468
........
cocoa: patch by David Jenkins - forcefully invalidate the content document for manual scroll. Should help with redrawing customcontrols for 10.14. #34478
........
Printers: Support for Cocoa printing, updated examples.
........
cocoa: restoring the code to identify VK code based on the character (support for Dvorak keyboards). Any national characters would still be determined based on keyCode. Suggested by Zoë Peterson
........
cocoa: Fixes TTabControl, it previously was placing controls inside it with Left=0 as if they had Left=-20, because NSTabView is not meant to receive views inside it like that, we need a different handle for TTabControl and TPageControl
........
cocoa: reporting extended UTF8 character as a question mark for ansi char
........
cocoa: using additional storage for keeping checked state of a checklist items. #34590
........
cocoa: any font can utf8 (unicode)... even if it doesn't. #34594
........
cocoa: fix the issue with using enclosing scrollView for mouse position check. #34516
........
cocoa: updating LCL overrides to recognize different boolean types used in FPC headers. #34609
........
cocoa: update OpenGL component to use LCLObjCBoolean type (rel #34609)
........
cocoa: move NSResponderHotKeys to cocoawindows.pas unit. #34609
........
cocoa: cleanup in calendar (datepicker) component. #34609
........
cocoa: cleanup in calendar (datepicker) component - removing unused units. #34609
........
cocoa: registering cocoadatepicker unit with lcl.lpk
........
cocoa: update type cocoawsmenu type switching from boolean to LCLObjCBoolean. #34609
........
cocoa: update printing component to use LCLObjCBoolean type
........
cocoa: update removal of menuItems. Removing an item from parent menu rather than from parentItem's menu. #34602
........
cocoa: update menus to be able to remove separator items
........
cocoa: menus - fix cocoa app mem leak for allocated TcocoaMenuItems
........
cocoa: additional code to handle unassigning of trayicon menu
........
cocoa: making sure that TEdit and TComboBox (editable) are trully single line
........

git-svn-id: branches/fixes_2_0@59765 -
2018-12-09 22:24:53 +00:00

543 lines
17 KiB
ObjectPascal

{
*****************************************************************************
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
Author: Mattias Gaertner
ToDo:
use custom pixelformat
attributes: doublebufferd, version, ...
It should work with initWithFrame_pixelFormat, but this paints nothing
SwapBuffers - there is no function like aglSwapBuffers in CGL/NS
Mouse:
the TLCLCommonCallback mouse handlers check Owner.isEnabled, which
for a NSView always returns false.
SharedControl
}
unit GLCocoaNSContext;
{$mode objfpc}{$H+}
{$ModeSwitch objectivec1}
interface
uses
Classes, SysUtils, types, CocoaWSCommon, CocoaPrivate, CocoaUtils, LCLType,
Controls, LazLoggerBase, WSLCLClasses, gl, MacOSAll, CocoaAll;
function LBackingScaleFactor(Handle: HWND): single;
procedure LSetWantsBestResolutionOpenGLSurface(const AValue: boolean; Handle: HWND);
procedure LOpenGLViewport(Handle: HWND; Left, Top, Width, Height: integer);
procedure LOpenGLSwapBuffers(Handle: HWND);
function LOpenGLMakeCurrent(Handle: HWND): boolean;
function LOpenGLReleaseContext(Handle: HWND): boolean;
procedure LOpenGLClip(Handle: HWND);
function LOpenGLCreateContext(AWinControl: TWinControl;
{%H-}WSPrivate: TWSPrivateClass; SharedControl: TWinControl;
DoubleBuffered, AMacRetinaMode: boolean;
MajorVersion, MinorVersion: Cardinal;
MultiSampling, AlphaBits, DepthBits, StencilBits, AUXBuffers: Cardinal;
const {%H-}AParams: TCreateParams): HWND;
procedure LOpenGLDestroyContextInfo(AWinControl: TWinControl);
function CreateOpenGLContextAttrList(DoubleBuffered: boolean;
MajorVersion, MinorVersion: Cardinal;
MultiSampling, AlphaBits, DepthBits,
StencilBits, AUXBuffers: cardinal): NSOpenGLPixelFormatAttributePtr;
const
// missing constants in FPC 3.1.1 rev 31197 and below
NSOpenGLPFAOpenGLProfile = 99; //cr: name changed to match https://developer.apple.com/library/mac/documentation//Cocoa/Reference/ApplicationKit/Classes/NSOpenGLPixelFormat_Class/index.html
NSOpenGLProfileLegacy = $1000;
NSOpenGLProfileVersion3_2Core = $3200;
NSOpenGLProfileVersion4_1Core = $4100; //requires OSX SDK 10.10 or later, https://github.com/google/gxui/issues/98
type
NSOpenGLViewFix = objccategory external (NSOpenGLView)
procedure setWantsBestResolutionOpenGLSurface(bool: NSInteger); message 'setWantsBestResolutionOpenGLSurface:';
end;
NSScreenFix = objccategory external (NSScreen)
function backingScaleFactor: CGFloat ; message 'backingScaleFactor';
end;
TDummyNoWarnObjCNotUsed = objc.BOOL;
TDummyNoWarnObjCBaseNotUsed = objcbase.NSInteger;
{ TCocoaOpenGLView }
TCocoaOpenGLView = objcclass(NSOpenGLView)
public
Owner: TWinControl;
//nsGL: NSOpenGLContext;
callback: TLCLCommonCallback;
backingScaleFactor: Single;
function acceptsFirstResponder: LCLObjCBoolean; override;
function becomeFirstResponder: LCLObjCBoolean; override;
function resignFirstResponder: LCLObjCBoolean; override;
procedure drawRect(dirtyRect: NSRect); override;
procedure dealloc; override;
function lclGetCallback: ICommonCallback; override;
procedure lclClearCallback; override;
function lclIsHandle: Boolean; override;
function lclIsEnabled: Boolean; override;
// mouse
procedure mouseDown(event: NSEvent); override;
procedure mouseUp(event: NSEvent); override;
procedure rightMouseDown(event: NSEvent); override;
procedure rightMouseUp(event: NSEvent); override;
procedure otherMouseDown(event: NSEvent); override;
procedure otherMouseUp(event: NSEvent); override;
procedure mouseDragged(event: NSEvent); override;
procedure mouseEntered(event: NSEvent); override;
procedure mouseExited(event: NSEvent); override;
procedure mouseMoved(event: NSEvent); override;
procedure scrollWheel(event: NSEvent); override;
// key
procedure keyDown(event: NSEvent); override;
procedure keyUp(event: NSEvent); override;
procedure flagsChanged(event: NSEvent); override;
// other
procedure resetCursorRects; override;
end;
function GetCGLContextObj(OpenGLControlHandle: HWND): CGLContextObj;
(*function CreateCGLContextAttrList(DoubleBuffered: boolean;
{$IFDEF UsesModernGL}
MajorVersion, MinorVersion: Cardinal;
{$ENDIF}
MultiSampling, AlphaBits, DepthBits,
StencilBits, AUXBuffers: cardinal): PInteger;
function IsCGLPixelFormatAvailable(Attribs: PInteger): boolean;*)
implementation
//value > 1 if screen is scaled, e.g. default for MOST retina displays is 2
function LBackingScaleFactor(Handle: HWND): single;
begin
result := TCocoaOpenGLView(Handle).backingScaleFactor;
end;
procedure LSetWantsBestResolutionOpenGLSurface(const AValue: boolean; Handle: HWND);
var
View: TCocoaOpenGLView;
begin
if Handle=0 then exit;
View:=TCocoaOpenGLView(Handle);
if not View.respondsToSelector(objcselector('setWantsBestResolutionOpenGLSurface:')) then exit;
if AValue then
View.setWantsBestResolutionOpenGLSurface(1)
else
View.setWantsBestResolutionOpenGLSurface(0);
if (AValue) and (NSScreen.mainScreen.respondsToSelector(objcselector('backingScaleFactor'))) then //MacOS >=10.7
View.backingScaleFactor := NSScreen.mainScreen.backingScaleFactor
else
View.backingScaleFactor := 1;
end;
procedure LOpenGLViewport(Handle: HWND; Left, Top, Width, Height: integer);
var
View: NSOpenGLView absolute Handle;
lFinalWidth, lFinalHeight: Integer;
begin
lFinalWidth := Width;
lFinalHeight := Height;
if View <> nil then
begin
lFinalWidth := Round(Width * LBackingScaleFactor(Handle));
lFinalHeight := Round(Height * LBackingScaleFactor(Handle));
end;
glViewport(Left,Top,lFinalWidth,lFinalHeight);
end;
procedure LOpenGLSwapBuffers(Handle: HWND);
//var
// View: TCocoaOpenGLView; //TCocoaOpenGLView
begin
if Handle=0 then exit;
glFlush();
// View:=TCocoaOpenGLView(Handle);
// View.nsGL.flushBuffer;
end;
function LOpenGLMakeCurrent(Handle: HWND): boolean;
var
CGLContext: CGLContextObj;
begin
if Handle=0 then exit(false);
CGLContext:=GetCGLContextObj(Handle);
Result:=CGLSetCurrentContext(CGLContext)=kCGLNoError;
end;
function LOpenGLReleaseContext(Handle: HWND): boolean;
begin
if Handle=0 then exit(false);
Result:=CGLSetCurrentContext(nil)=kCGLNoError;
//Result:=true;
end;
procedure LOpenGLClip(Handle: HWND);
begin
if Handle=0 then exit;
// ToDo
end;
function LOpenGLCreateContext(AWinControl: TWinControl;
WSPrivate: TWSPrivateClass; SharedControl: TWinControl;
DoubleBuffered, AMacRetinaMode: boolean;
MajorVersion, MinorVersion: Cardinal;
MultiSampling, AlphaBits, DepthBits, StencilBits,
AUXBuffers: Cardinal; const AParams: TCreateParams): HWND;
var
View: TCocoaOpenGLView;
Attrs: NSOpenGLPixelFormatAttributePtr;
PixFmt: NSOpenGLPixelFormat;
p: NSView;
ns: NSRect;
aNSOpenGLContext: NSOpenGLContext;
CGLContext: CGLContextObj;
begin
Result:=0;
p := nil;
if (AParams.WndParent <> 0) then
p := CocoaUtils.GetNSObjectView(NSObject(AParams.WndParent));
if Assigned(p) then
LCLToNSRect(types.Bounds(AParams.X, AParams.Y, AParams.Width, AParams.Height),
p.frame.size.height, ns)
else
ns := GetNSRect(AParams.X, AParams.Y, AParams.Width, AParams.Height);
Attrs:=CreateOpenGLContextAttrList(DoubleBuffered,MajorVersion,MinorVersion, MultiSampling,AlphaBits,DepthBits,StencilBits,AUXBuffers);
try
PixFmt:=NSOpenGLPixelFormat(NSOpenGLPixelFormat.alloc).initWithAttributes(Attrs);
aNSOpenGLContext:=NSOpenGLContext(NSOpenGLContext.alloc).initWithFormat_shareContext(PixFmt,nil);
if aNSOpenGLContext = nil then
debugln(['LOpenGLCreateContext Error']);
View := TCocoaOpenGLView(TCocoaOpenGLView.alloc).initWithFrame_pixelFormat(ns,PixFmt);
if not Assigned(View) then Exit;
finally
FreeMem(Attrs);
end;
View.setHidden(AParams.Style and WS_VISIBLE = 0);
if Assigned(p) then
p.addSubview(View);
SetViewDefaults(View);
View.Owner:=AWinControl;
//View.nsGL := aNSOpenGLContext;
View.callback:=TLCLCommonCallback.Create(View, AWinControl);
LSetWantsBestResolutionOpenGLSurface(AMacRetinaMode, HWND(View));
//View.setPixelFormat(PixFmt);
Result:=TLCLIntfHandle(View);
end;
procedure LOpenGLDestroyContextInfo(AWinControl: TWinControl);
begin
// no special needed, simply release handle
if AWinControl=nil then
raise Exception.Create('');
end;
function CreateOpenGLContextAttrList(DoubleBuffered: boolean; MajorVersion,
MinorVersion: Cardinal; MultiSampling, AlphaBits, DepthBits, StencilBits,
AUXBuffers: cardinal): NSOpenGLPixelFormatAttributePtr;
var
p: integer;
procedure AddUInt32(i: NSOpenGLPixelFormatAttribute);
begin
if Result<>nil then
Result[p]:=i;
inc(p);
end;
procedure CreateList;
begin
//see https://developer.apple.com/library/mac/documentation//Cocoa/Reference/ApplicationKit/Classes/NSOpenGLPixelFormat_Class/index.html
//AddUInt32(NSOpenGLPFAAccelerated); // <- comment out: we can run in software if hardware is not available
//AddUInt32(NSOpenGLPFAOpenGLProfile); //Versions beyond 'Legacy' appear to break CULL_FACE and DEPTH_BUFFER, legacy seems to be default, so comment out whole instruction
//if (MajorVersion>=4) and (MinorVersion>=1)
// AddUInt32(NSOpenGLProfileVersion4_1Core);
//else if (MajorVersion>=3) and (MinorVersion>=2) then
// AddUInt32(NSOpenGLProfileVersion3_2Core);
//else
//AddUInt32(NSOpenGLProfileLegacy); // NSOpenGLProfileLegacy is default and sufficient, later versions depend on SDK we are building against
AddUInt32(NSOpenGLPFAOpenGLProfile);
if (MajorVersion>=4) and (MinorVersion>=1) then
AddUInt32(NSOpenGLProfileVersion4_1Core) //OpenGL 4.1, GLSL 4.1
else if (MajorVersion>=3) and (MinorVersion>=2) then
AddUInt32(NSOpenGLProfileVersion3_2Core)
else
AddUInt32(NSOpenGLProfileLegacy); //OpenGL 2.1, GLSL 1.2
AddUInt32(NSOpenGLPFAColorSize); AddUInt32(24);
if DepthBits > 0 then begin
AddUInt32(NSOpenGLPFADepthSize); AddUInt32(32);
end;
if AlphaBits>0 then begin
AddUInt32(NSOpenGLPFAAlphaSize); AddUInt32(AlphaBits);
end;
AddUInt32(NSOpenGLPFAAccelerated);
if MultiSampling > 1 then begin
AddUInt32(NSOpenGLPFAMultisample);
AddUInt32(NSOpenGLPFASampleBuffers); AddUInt32(1);
AddUInt32(NSOpenGLPFASamples); AddUInt32(MultiSampling);
end;
if StencilBits>0 then
begin
AddUInt32(NSOpenGLPFAStencilSize); AddUInt32(StencilBits);
end;
if AUXBuffers>0 then
begin
AddUInt32(NSOpenGLPFAAuxBuffers); AddUInt32(AUXBuffers);
end;
//if DoubleBuffered then //requires fix for nsGL
// AddUInt32(NSOpenGLPFADoubleBuffer); //this doen't work with Lazarus
AddUInt32(NSOpenGLPFAMaximumPolicy); //allows future changes to make attributes more demanding, e.g. add multisampling
AddUInt32(NSOpenGLPFANoRecovery); //see apple web page: "not generally useful" but might help with multisample
AddUInt32(0); // end of list
end;
begin
Result:=nil;
p:=0;
CreateList;
GetMem(Result,SizeOf(NSOpenGLPixelFormatAttribute)*(p+1));
p:=0;
CreateList;
end;
function GetCGLContextObj(OpenGLControlHandle: HWND): CGLContextObj;
var
View: NSOpenGLView;
begin
Result:=nil;
if OpenGLControlHandle=0 then exit;
View:=TCocoaOpenGLView(OpenGLControlHandle);
Result:=CGLContextObj(View.openGLContext.CGLContextObj);
NSScreen.mainScreen.colorSpace;
end;
(*
//these functions are commented out: this was an attempt to use CGL, porting NSOpenGLView instead was more successful
function CreateCGLContextAttrList(DoubleBuffered: boolean; MultiSampling,
AlphaBits, DepthBits, StencilBits, AUXBuffers: cardinal): PInteger;
var
p: integer;
procedure Add(i: integer);
begin
if Result<>nil then
Result[p]:=i;
inc(p);
end;
procedure CreateList;
begin
//Add(kCGLPFAWindow); deprecated since 10.9
Add(kCGLPFAAccelerated);
if DoubleBuffered then
Add(kCGLPFADoubleBuffer);
//if (MajorVersion>=3) and (MinorVersion>=2) then
// Add(kCGLOGLPVersion);
Add(kCGLPFANoRecovery);
Add(kCGLPFAMaximumPolicy);
Add(kCGLPFASingleRenderer);
if AlphaBits>0 then
begin
Add(kCGLPFAAlphaSize); Add(AlphaBits);
end;
if DepthBits>0 then
begin
Add(kCGLPFADepthSize); Add(DepthBits);
end;
if StencilBits>0 then
begin
Add(kCGLPFAStencilSize); Add(StencilBits);
end;
if AUXBuffers>0 then
begin
//Add(kCGLPFAAuxBuffers); Add(AUXBuffers); ToDo
end;
if MultiSampling > 1 then
begin
Add(kCGLPFASampleBuffers); Add(1);
Add(kCGLPFASamples); Add(MultiSampling);
end;
Add(0); // end of list
end;
begin
Result:=nil;
p:=0;
CreateList;
GetMem(Result,SizeOf(integer)*p);
p:=0;
CreateList;
end;
function IsCGLPixelFormatAvailable(Attribs: PInteger): boolean;
var
//display: CGDirectDisplayID;
aPixFormatObj: CGLPixelFormatObj;
aPixObjCountAttrList: GLint;
begin
//display := CGMainDisplayID();
if CGLChoosePixelFormat(Attribs, @aPixFormatObj, @aPixObjCountAttrList)<>kCGLNoError
then
exit(false);
if aPixFormatObj=nil then
exit(false);
Result:=true;
// ToDo: free aPixFormatObj
end; *)
{ TCocoaOpenGLView }
function TCocoaOpenGLView.acceptsFirstResponder: LCLObjCBoolean;
begin
Result := True;
end;
function TCocoaOpenGLView.becomeFirstResponder: LCLObjCBoolean;
begin
Result:=inherited becomeFirstResponder;
callback.BecomeFirstResponder;
end;
function TCocoaOpenGLView.resignFirstResponder: LCLObjCBoolean;
begin
Result:=inherited resignFirstResponder;
callback.ResignFirstResponder;
end;
procedure TCocoaOpenGLView.dealloc;
begin
inherited dealloc;
end;
function TCocoaOpenGLView.lclGetCallback: ICommonCallback;
begin
Result := callback;
end;
procedure TCocoaOpenGLView.lclClearCallback;
begin
callback := nil;
end;
function TCocoaOpenGLView.lclIsHandle: Boolean;
begin
Result:=true;
end;
function TCocoaOpenGLView.lclIsEnabled: Boolean;
begin
Result := Owner.Enabled;
end;
procedure TCocoaOpenGLView.mouseDown(event: NSEvent);
begin
if Assigned(callback)
then callback.MouseUpDownEvent(event)
else inherited mouseDown(event);
end;
procedure TCocoaOpenGLView.mouseUp(event: NSEvent);
begin
if Assigned(callback)
then callback.MouseUpDownEvent(event)
else inherited mouseUp(event);
end;
procedure TCocoaOpenGLView.rightMouseDown(event: NSEvent);
begin
if Assigned(callback)
then callback.MouseUpDownEvent(event)
else inherited rightMouseDown(event);
end;
procedure TCocoaOpenGLView.rightMouseUp(event: NSEvent);
begin
if Assigned(callback)
then callback.MouseUpDownEvent(event)
else inherited rightMouseUp(event);
end;
procedure TCocoaOpenGLView.otherMouseDown(event: NSEvent);
begin
if Assigned(callback)
then callback.MouseUpDownEvent(event)
else inherited otherMouseDown(event);
end;
procedure TCocoaOpenGLView.otherMouseUp(event: NSEvent);
begin
if Assigned(callback)
then callback.MouseUpDownEvent(event)
else inherited otherMouseUp(event);
end;
procedure TCocoaOpenGLView.mouseDragged(event: NSEvent);
begin
if Assigned(callback)
then callback.MouseMove(event)
else inherited mouseDragged(event);
end;
procedure TCocoaOpenGLView.mouseEntered(event: NSEvent);
begin
inherited mouseEntered(event);
end;
procedure TCocoaOpenGLView.mouseExited(event: NSEvent);
begin
inherited mouseExited(event);
end;
procedure TCocoaOpenGLView.mouseMoved(event: NSEvent);
begin
if Assigned(callback)
then callback.MouseMove(event)
else inherited mouseMoved(event);
end;
procedure TCocoaOpenGLView.scrollWheel(event: NSEvent);
begin
if Assigned(callback)
then callback.scrollWheel(event)
else inherited scrollWheel(event);
end;
procedure TCocoaOpenGLView.keyDown(event: NSEvent);
begin
if not Assigned(callback) or not callback.KeyEvent(event) then
inherited keyDown(event);
end;
procedure TCocoaOpenGLView.keyUp(event: NSEvent);
begin
if not Assigned(callback) or not callback.KeyEvent(event) then
inherited keyUp(event);
end;
procedure TCocoaOpenGLView.flagsChanged(event: NSEvent);
begin
if not Assigned(callback) or not callback.KeyEvent(event) then
inherited flagsChanged(event);
end;
procedure TCocoaOpenGLView.resetCursorRects;
begin
if not Assigned(callback) or not callback.resetCursorRects then
inherited resetCursorRects;
end;
procedure TCocoaOpenGLView.drawRect(dirtyRect: NSRect);
begin
inherited drawRect(dirtyRect);
if CheckMainThread and Assigned(callback) then
callback.Draw(NSGraphicsContext.currentContext, bounds, dirtyRect);
end;
end.