mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-21 06:29:33 +02:00
* disabled color correction and fiddled some more with the translation
transformation, so getpixel works even better (hopefully 100% now) * fixed usage of lineclipped when using native line drawing functions * window was one pixel less tall than the intended resolution, and clearviewport did not clear the entire offscreen buffer - commented out some debugging code git-svn-id: trunk@8353 -
This commit is contained in:
parent
7e5f13cc45
commit
d9691d5c53
@ -105,7 +105,8 @@ const
|
|||||||
kEventClassFPCGraph = $46504367; // 'FPCg'
|
kEventClassFPCGraph = $46504367; // 'FPCg'
|
||||||
kEventInitGraph = $496E6974; // 'Init'
|
kEventInitGraph = $496E6974; // 'Init'
|
||||||
kEventFlush = $466c7368; // 'Flsh'
|
kEventFlush = $466c7368; // 'Flsh'
|
||||||
kEventCloseGraph = $446f6e65; // 'Done'
|
kEventCloseGraph = $446f6e65; // 'Done'
|
||||||
|
kEventQuit = $51756974; // 'Quit'
|
||||||
|
|
||||||
kEventGraphInited = $49746564 ; // Ited;
|
kEventGraphInited = $49746564 ; // Ited;
|
||||||
kEventGraphClosed = $436c6564 ; // Cled;
|
kEventGraphClosed = $436c6564 ; // Cled;
|
||||||
@ -113,9 +114,10 @@ const
|
|||||||
// initGraphSpec : EventTypeSpec = (eventClass: kEventClassFPCGraph; eventKind: kEventInitGraph);
|
// initGraphSpec : EventTypeSpec = (eventClass: kEventClassFPCGraph; eventKind: kEventInitGraph);
|
||||||
// flushGraphSpec : EventTypeSpec = (eventClass: kEventClassFPCGraph; eventKind: kEventFlush);
|
// flushGraphSpec : EventTypeSpec = (eventClass: kEventClassFPCGraph; eventKind: kEventFlush);
|
||||||
// closeGraphSpec : EventTypeSpec = (eventClass: kEventClassFPCGraph; eventKind: kEventCloseGraph);
|
// closeGraphSpec : EventTypeSpec = (eventClass: kEventClassFPCGraph; eventKind: kEventCloseGraph);
|
||||||
allGraphSpec: array[0..2] of EventTypeSpec = ((eventClass: kEventClassFPCGraph; eventKind: kEventInitGraph),
|
allGraphSpec: array[0..3] of EventTypeSpec = ((eventClass: kEventClassFPCGraph; eventKind: kEventInitGraph),
|
||||||
(eventClass: kEventClassFPCGraph; eventKind: kEventFlush),
|
(eventClass: kEventClassFPCGraph; eventKind: kEventFlush),
|
||||||
(eventClass: kEventClassFPCGraph; eventKind: kEventCloseGraph));
|
(eventClass: kEventClassFPCGraph; eventKind: kEventCloseGraph),
|
||||||
|
(eventClass: kEventClassFPCGraph; eventKind: kEventQuit));
|
||||||
|
|
||||||
GraphInitedSpec: array[0..0] of EventTypeSpec = ((eventClass: kEventClassFPCGraph; eventKind: kEventGraphInited));
|
GraphInitedSpec: array[0..0] of EventTypeSpec = ((eventClass: kEventClassFPCGraph; eventKind: kEventGraphInited));
|
||||||
GraphClosedSpec: array[0..0] of EventTypeSpec = ((eventClass: kEventClassFPCGraph; eventKind: kEventGraphClosed));
|
GraphClosedSpec: array[0..0] of EventTypeSpec = ((eventClass: kEventClassFPCGraph; eventKind: kEventGraphClosed));
|
||||||
@ -255,7 +257,7 @@ begin
|
|||||||
bitmapBytesPerRow := (pixelsWide * 4);// always draw in 24 bit colour (+ 8 bit alpha)
|
bitmapBytesPerRow := (pixelsWide * 4);// always draw in 24 bit colour (+ 8 bit alpha)
|
||||||
bitmapByteCount := (bitmapBytesPerRow * pixelsHigh);
|
bitmapByteCount := (bitmapBytesPerRow * pixelsHigh);
|
||||||
|
|
||||||
colorSpace := CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);// 2
|
colorSpace := CGColorSpaceCreateDeviceRGB;// 2
|
||||||
bitmapData := getmem ( bitmapByteCount );// 3
|
bitmapData := getmem ( bitmapByteCount );// 3
|
||||||
if (bitmapData = nil) then
|
if (bitmapData = nil) then
|
||||||
exit;
|
exit;
|
||||||
@ -275,7 +277,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
CGColorSpaceRelease( colorSpace );
|
CGColorSpaceRelease( colorSpace );
|
||||||
{ disable anti-aliasing }
|
{ disable anti-aliasing }
|
||||||
CGContextTranslateCTM(CreateBitmapContext,0.5,-0.5);
|
CGContextTranslateCTM(CreateBitmapContext,0.5,0.5);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -361,9 +363,9 @@ function MyDrawEventHandler (myHandler: EventHandlerCallRef;
|
|||||||
CGContextDrawImage(myContext,
|
CGContextDrawImage(myContext,
|
||||||
bounds,
|
bounds,
|
||||||
img);
|
img);
|
||||||
CGImageRelease(img);
|
|
||||||
updatepending:=false;
|
updatepending:=false;
|
||||||
LeaveCriticalSection(graphdrawing);
|
LeaveCriticalSection(graphdrawing);
|
||||||
|
CGImageRelease(img);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -426,8 +428,6 @@ begin
|
|||||||
LeaveCriticalSection(graphdrawing);
|
LeaveCriticalSection(graphdrawing);
|
||||||
lastcolor:=color;
|
lastcolor:=color;
|
||||||
end
|
end
|
||||||
// else
|
|
||||||
// writeln('color was already set: ',color);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -536,7 +536,7 @@ begin
|
|||||||
if not ClipCoords(X,Y) then
|
if not ClipCoords(X,Y) then
|
||||||
exit;
|
exit;
|
||||||
p := pbyte(CGBitmapContextGetData(offscreen));
|
p := pbyte(CGBitmapContextGetData(offscreen));
|
||||||
y:=maxy-(y-1);
|
y:=maxy-y;
|
||||||
inc(p,(y*(maxx+1)+x)*4);
|
inc(p,(y*(maxx+1)+x)*4);
|
||||||
red:=p^;
|
red:=p^;
|
||||||
green:=(p+1)^;
|
green:=(p+1)^;
|
||||||
@ -575,7 +575,7 @@ procedure q_clrviewproc;
|
|||||||
begin
|
begin
|
||||||
q_SetColor(CurrentBkColor);
|
q_SetColor(CurrentBkColor);
|
||||||
EnterCriticalSection(graphdrawing);
|
EnterCriticalSection(graphdrawing);
|
||||||
CGContextFillRect(offscreen,CGRectMake(StartXViewPort,StartYViewPort,ViewWidth,ViewHeight));
|
CGContextFillRect(offscreen,CGRectMake(StartXViewPort,StartYViewPort,ViewWidth+1,ViewHeight+1));
|
||||||
UpdateScreen;
|
UpdateScreen;
|
||||||
LeaveCriticalSection(graphdrawing);
|
LeaveCriticalSection(graphdrawing);
|
||||||
{ reset coordinates }
|
{ reset coordinates }
|
||||||
@ -625,7 +625,7 @@ begin
|
|||||||
y1 := y1 + StartYViewPort;
|
y1 := y1 + StartYViewPort;
|
||||||
y2 := y2 + StartYViewPort;
|
y2 := y2 + StartYViewPort;
|
||||||
if ClipPixels then
|
if ClipPixels then
|
||||||
if LineClipped(x1,y2,x2,y2,StartXViewPort,StartYViewPort,
|
if LineClipped(x1,y1,x2,y2,StartXViewPort,StartYViewPort,
|
||||||
StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
|
StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
|
||||||
exit;
|
exit;
|
||||||
if (CurrentWriteMode = NotPut) then
|
if (CurrentWriteMode = NotPut) then
|
||||||
@ -661,7 +661,7 @@ begin
|
|||||||
y1 := y1 + StartYViewPort;
|
y1 := y1 + StartYViewPort;
|
||||||
y2 := y2 + StartYViewPort;
|
y2 := y2 + StartYViewPort;
|
||||||
if ClipPixels then
|
if ClipPixels then
|
||||||
if LineClipped(x1,y2,x2,y2,StartXViewPort,StartYViewPort,
|
if LineClipped(x1,y1,x2,y2,StartXViewPort,StartYViewPort,
|
||||||
StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
|
StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
|
||||||
exit;
|
exit;
|
||||||
if (CurrentWriteMode = NotPut) then
|
if (CurrentWriteMode = NotPut) then
|
||||||
@ -773,13 +773,13 @@ begin
|
|||||||
or kWindowNoUpdatesAttribute;
|
or kWindowNoUpdatesAttribute;
|
||||||
|
|
||||||
SetRect (contentRect, 0, 0,
|
SetRect (contentRect, 0, 0,
|
||||||
MaxX, MaxY);
|
MaxX+1, MaxY+1);
|
||||||
|
|
||||||
CreateNewWindow (kDocumentWindowClass, windowAttrs,// 3
|
CreateNewWindow (kDocumentWindowClass, windowAttrs,// 3
|
||||||
contentRect, myMainWindow);
|
contentRect, myMainWindow);
|
||||||
|
|
||||||
SetRect (contentRect, 0, 50,
|
SetRect (contentRect, 0, 50,
|
||||||
MaxX, 50+MaxY);
|
MaxX+1, 51+MaxY);
|
||||||
|
|
||||||
SetWindowBounds(myMainWindow,kWindowContentRgn,contentrect);
|
SetWindowBounds(myMainWindow,kWindowContentRgn,contentrect);
|
||||||
titleKey := CFSTR('Graph Window'); // 4
|
titleKey := CFSTR('Graph Window'); // 4
|
||||||
@ -792,8 +792,8 @@ begin
|
|||||||
begin
|
begin
|
||||||
top:=0;
|
top:=0;
|
||||||
left:=0;
|
left:=0;
|
||||||
bottom:=MaxY;
|
bottom:=MaxY+1;
|
||||||
right:=MaxX;
|
right:=MaxX+1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
offscreen:=CreateBitmapContext(MaxX+1,MaxY+1);
|
offscreen:=CreateBitmapContext(MaxX+1,MaxY+1);
|
||||||
@ -835,19 +835,19 @@ begin
|
|||||||
|
|
||||||
ShowWindow (myMainWindow);
|
ShowWindow (myMainWindow);
|
||||||
|
|
||||||
|
{
|
||||||
|
write('view is active: ',HIViewIsActive(graphHIView,@b));
|
||||||
|
writeln(', latent: ',b);
|
||||||
|
writeln('compositing enabled: ',HIViewIsCompositingEnabled(graphHIView));
|
||||||
|
writeln('visible before: ',HIViewIsVisible(graphHIView));
|
||||||
|
write('drawing enabled: ',HIViewIsDrawingEnabled(graphHIView));
|
||||||
|
writeln(', latent: ',b);
|
||||||
|
write('view is enabled: ',HIViewIsEnabled(graphHIView,@b));
|
||||||
|
writeln(', latent: ',b);
|
||||||
|
|
||||||
write('view is active: ',HIViewIsActive(graphHIView,@b));
|
err := HIViewGetBounds(graphHIView,hiviewbounds);
|
||||||
writeln(', latent: ',b);
|
writeln('err, ',err,' (',hiviewbounds.origin.x:0:2,',',hiviewbounds.origin.y:0:2,'),(',hiviewbounds.size.width:0:2,',',hiviewbounds.size.height:0:2,')');
|
||||||
writeln('compositing enabled: ',HIViewIsCompositingEnabled(graphHIView));
|
}
|
||||||
writeln('visible before: ',HIViewIsVisible(graphHIView));
|
|
||||||
write('drawing enabled: ',HIViewIsDrawingEnabled(graphHIView));
|
|
||||||
writeln(', latent: ',b);
|
|
||||||
write('view is enabled: ',HIViewIsEnabled(graphHIView,@b));
|
|
||||||
writeln(', latent: ',b);
|
|
||||||
|
|
||||||
err := HIViewGetBounds(graphHIView,hiviewbounds);
|
|
||||||
writeln('err, ',err,' (',hiviewbounds.origin.x:0:2,',',hiviewbounds.origin.y:0:2,'),(',hiviewbounds.size.width:0:2,',',hiviewbounds.size.height:0:2,')');
|
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -1011,26 +1011,32 @@ var
|
|||||||
begin
|
begin
|
||||||
// writeln('in GraphEventHandler, event: ',FourCharArray(GetEventKind(event)));
|
// writeln('in GraphEventHandler, event: ',FourCharArray(GetEventKind(event)));
|
||||||
newEvent := nil;
|
newEvent := nil;
|
||||||
if (GetEventKind(event) = kEventInitGraph) then
|
case GetEventKind(event) of
|
||||||
begin
|
kEventInitGraph:
|
||||||
q_initmodeproc;
|
begin
|
||||||
if (GetEventParameter(event,FOUR_CHAR_CODE('Src '), typeVoidPtr, nil, sizeof(EventQueueRef), nil, @source) <> noErr) then
|
q_initmodeproc;
|
||||||
runerror(218);
|
if (GetEventParameter(event,FOUR_CHAR_CODE('Src '), typeVoidPtr, nil, sizeof(EventQueueRef), nil, @source) <> noErr) then
|
||||||
if (CreateEvent(nil, kEventClassFPCGraph, kEventGraphInited, GetCurrentEventTime(), 0, newEvent) <> noErr) then
|
runerror(218);
|
||||||
runerror(218);
|
if (CreateEvent(nil, kEventClassFPCGraph, kEventGraphInited, GetCurrentEventTime(), 0, newEvent) <> noErr) then
|
||||||
end
|
runerror(218);
|
||||||
else if (GetEventKind(event) = kEventCloseGraph) then
|
end;
|
||||||
begin
|
kEventCloseGraph:
|
||||||
q_donegraph;
|
begin
|
||||||
if (GetEventParameter(event,FOUR_CHAR_CODE('Src '), typeVoidPtr, nil, sizeof(EventQueueRef), nil, @source) <> noErr) then
|
q_donegraph;
|
||||||
runerror(218);
|
if (GetEventParameter(event,FOUR_CHAR_CODE('Src '), typeVoidPtr, nil, sizeof(EventQueueRef), nil, @source) <> noErr) then
|
||||||
if (CreateEvent(nil, kEventClassFPCGraph, kEventGraphClosed, GetCurrentEventTime(), 0, newEvent) <> noErr) then
|
runerror(218);
|
||||||
runerror(218);
|
if (CreateEvent(nil, kEventClassFPCGraph, kEventGraphClosed, GetCurrentEventTime(), 0, newEvent) <> noErr) then
|
||||||
end
|
runerror(218);
|
||||||
else if (GetEventKind(event) = kEventFlush) then
|
end;
|
||||||
begin
|
kEventFlush:
|
||||||
HIViewSetNeedsDisplay(graphHIView, true);
|
begin
|
||||||
end;
|
HIViewSetNeedsDisplay(graphHIView, true);
|
||||||
|
end;
|
||||||
|
kEventQuit:
|
||||||
|
begin
|
||||||
|
QuitApplicationEventLoop;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
if assigned(newEvent) then
|
if assigned(newEvent) then
|
||||||
if PostEventToQueue(source,newEvent,kEventPriorityStandard) <> noErr then
|
if PostEventToQueue(source,newEvent,kEventPriorityStandard) <> noErr then
|
||||||
runerror(218);
|
runerror(218);
|
||||||
@ -1039,41 +1045,57 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
var
|
var
|
||||||
proctorun: TGraphProgram;
|
proctorun: TGraphProgram;
|
||||||
|
|
||||||
|
function wrapper(p: pointer): longint;
|
||||||
|
(*
|
||||||
|
var
|
||||||
|
event : EventRef;
|
||||||
|
*)
|
||||||
|
begin
|
||||||
|
wrapper:=proctorun(nil);
|
||||||
|
halt(wrapper);
|
||||||
|
(*
|
||||||
|
if (CreateEvent(nil, kEventClassFPCGraph, kEventQuit, GetCurrentEventTime(), 0, event) <> noErr) then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
if (PostEventToQueue(MainEventQueue,event,kEventPriorityLow) <> noErr) then
|
||||||
|
begin
|
||||||
|
ReleaseEvent(event);
|
||||||
|
halt(wrapper);
|
||||||
|
end;
|
||||||
|
*)
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure StartGraphProgram(p: TGraphProgram);
|
||||||
|
var
|
||||||
|
taskid: mptaskid;
|
||||||
|
eventRec: eventrecord;
|
||||||
|
begin
|
||||||
|
if InstallEventHandler (GetApplicationEventTarget,
|
||||||
|
NewEventHandlerUPP (@GraphEventHandler),
|
||||||
|
length(allGraphSpec),
|
||||||
|
@allGraphSpec,
|
||||||
|
nil,
|
||||||
|
nil) <> noErr then
|
||||||
|
begin
|
||||||
|
_GraphResult:=grError;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
proctorun:=p;
|
||||||
|
|
||||||
function wrapper(p: pointer): longint;
|
{ main program has to be the first one to access the event queue, see }
|
||||||
begin
|
{ http://lists.apple.com/archives/carbon-dev/2007/Jun/msg00612.html }
|
||||||
halt(proctorun(nil));
|
eventavail(0,eventRec);
|
||||||
end;
|
maineventqueue:=GetMainEventQueue;
|
||||||
|
BeginThread(@wrapper);
|
||||||
|
RunApplicationEventLoop;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure StartGraphProgram(p: TGraphProgram);
|
|
||||||
var
|
|
||||||
taskid: mptaskid;
|
|
||||||
eventRec: eventrecord;
|
|
||||||
begin
|
|
||||||
if InstallEventHandler (GetApplicationEventTarget,
|
|
||||||
NewEventHandlerUPP (@GraphEventHandler),
|
|
||||||
length(allGraphSpec),
|
|
||||||
@allGraphSpec,
|
|
||||||
nil,
|
|
||||||
nil) <> noErr then
|
|
||||||
begin
|
|
||||||
_GraphResult:=grError;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
proctorun:=p;
|
|
||||||
|
|
||||||
{ main program has to be the first one to access the event queue, see }
|
|
||||||
{ http://lists.apple.com/archives/carbon-dev/2007/Jun/msg00612.html }
|
|
||||||
eventavail(0,eventRec);
|
|
||||||
maineventqueue:=GetMainEventQueue;
|
|
||||||
BeginThread(@wrapper);
|
|
||||||
RunApplicationEventLoop;
|
|
||||||
end;
|
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
initcriticalsection(graphdrawing);
|
initcriticalsection(graphdrawing);
|
||||||
InitializeGraph;
|
InitializeGraph;
|
||||||
|
Loading…
Reference in New Issue
Block a user