Skip to content

Commit

Permalink
bugfix: #16
Browse files Browse the repository at this point in the history
  • Loading branch information
roodkcab committed Dec 30, 2020
1 parent 03ff5d7 commit 795249e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
51 changes: 19 additions & 32 deletions Mac/GraphicsElement/CoreGraphics/GuiGraphicsCoreGraphics.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

#include "../../NativeWindow/OSX/CocoaHelper.h"
#include "../../NativeWindow/OSX/CocoaWindow.h"
#include "../../NativeWindow/OSX/CocoaNativeController.h"
#include "../../NativeWindow/OSX/CocoaBaseView.h"
#include "../../NativeWindow/OSX/ServicesImpl/CocoaCallbackService.h"

#import <Cocoa/Cocoa.h>
#import <GacUI.h>
Expand Down Expand Up @@ -76,39 +76,22 @@ - (void)viewDidChangeBackingProperties
[self resize:self.frame.size];
}

- (CGLayerRef)copyLayer:(CGLayerRef *)layer size:(CGSize)newSize
{
CGSize size = CGLayerGetSize(*layer);
CGContextRef context = CGBitmapContextCreate(0, newSize.width, newSize.height, 8, 0, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast);
CGContextSetShouldAntialias(context, true);
CGContextSetShouldSmoothFonts(context, true);
CGLayerRef copyLayer = CGLayerCreateWithContext(context, newSize, NULL);
CGContextRef copyContext = CGLayerGetContext(copyLayer);
//CGContextDrawLayerInRect(copyContext, CGRectMake(0, 0, newSize.width, newSize.height), *layer);
CGContextDrawLayerInRect(copyContext, CGRectMake(0, 0, size.width, size.height), *layer);
CGContextRelease(context);
CGLayerRelease(*layer);
return copyLayer;
}

- (void)resize:(CGSize)size
{
size.width = MAX([[self window] backingScaleFactor], size.width * [[self window] backingScaleFactor]);
size.height = MAX([[self window] backingScaleFactor], size.height * [[self window] backingScaleFactor]);
if (_context)
CGContextRelease(_context);

if (_drawingLayer)
CGLayerRelease(_drawingLayer);

_context = CGBitmapContextCreate(0, size.width, size.height, 8, 0, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast);
if (_context)
{
_drawingLayer = [self copyLayer:&_drawingLayer size:size];
_drawingLayer = CGLayerCreateWithContext(_context, size, NULL);
assert(_drawingLayer);
}
else
{
_context = CGBitmapContextCreate(0, size.width, size.height, 8, 0, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast);
if (_context)
{
_drawingLayer = CGLayerCreateWithContext(_context, size, NULL);
assert(_drawingLayer);
}
}
}

- (void)drawRect:(NSRect)dirtyRect
Expand Down Expand Up @@ -316,9 +299,17 @@ void SetBindedRenderTarget(INativeWindow* window, ICoreGraphicsRenderTarget* ren

void RebuildLayer(NativeSize size)
{
if(previousSize != size)
if (previousSize != size)
{
[nativeView resize:CGSizeMake(size.x.value, size.y.value)];
previousSize = size;
GetCurrentController()->InputService()->StopTimer();
dynamic_cast<CocoaCallbackService *>(GetCurrentController()->CallbackService())->InvokeGlobalTimer();
previousSize = size;
}
else
{
GetCurrentController()->InputService()->StartTimer();
}
}

void ResizeRenderTarget()
Expand Down Expand Up @@ -355,10 +346,6 @@ void Moved()
}
}

void Paint()
{
}

CoreGraphicsView* GetCoreGraphicsView() const
{
return nativeView;
Expand Down
3 changes: 2 additions & 1 deletion Mac/NativeWindow/OSX/ServicesImpl/CocoaInputService.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ namespace vl {
public:
CocoaInputService(MouseTapFunc mouseTap, TimerFunc timer);
virtual ~CocoaInputService();

void RestartTimer();

// INativeInputService

void StartHookMouse() override;
Expand Down

0 comments on commit 795249e

Please sign in to comment.