cnping

Minimal Graphical Ping Tool
git clone https://git.sinitax.com/cnlohr/cnping
Log | Files | Refs | Submodules | README | LICENSE | sfeed.txt

commit fc4fc15e12112385495add6d82684839bbabe725
parent e4472da33f49360c9c4f2a299bd50809d0a4c6e3
Author: CNLohr <charles@cnlohr.com>
Date:   Wed, 24 May 2017 14:55:57 -0400

Merge pull request #22 from Viknet/dev

OSX: window resize added
Diffstat:
MCNFGCocoaCGDriver.m | 47+++++++++++++++++++++++++++++------------------
1 file changed, 29 insertions(+), 18 deletions(-)

diff --git a/CNFGCocoaCGDriver.m b/CNFGCocoaCGDriver.m @@ -113,12 +113,6 @@ void CNFGTackPoly( RDPoint * points, int verts ) CGContextFillPath(bufferContext); } -void CNFGGetDimensions( short * x, short * y ) -{ - *x = app_sw; - *y = app_sh; -} - @interface MyView : NSView @end @implementation MyView @@ -152,23 +146,16 @@ void CNFGGetDimensions( short * x, short * y ) CGContextRef createBitmapContext (int pixelsWide, int pixelsHigh) { - int bitmapByteCount; - int bitmapBytesPerRow; - - bitmapBytesPerRow = (pixelsWide * 4); - bitmapByteCount = (bitmapBytesPerRow * pixelsHigh); + int bitmapBytesPerRow = (pixelsWide * 4); - colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGBLinear); - bufferData = calloc( bitmapByteCount, sizeof(uint8_t) ); - - CGContextRef context = CGBitmapContextCreate (bufferData, + CGContextRef context = CGBitmapContextCreate (NULL, pixelsWide, pixelsHigh, 8, bitmapBytesPerRow, colorSpace, kCGImageAlphaNoneSkipLast); - + bufferData = CGBitmapContextGetData(context); CGContextSetInterpolationQuality(context, kCGInterpolationNone); // CGContextSetShouldAntialias(context, NO); // CGContextSetLineWidth(context, 0.5); @@ -191,6 +178,7 @@ void initApp(){ [app_appMenu addItem:app_quitMenuItem]; [app_appMenuItem setSubmenu:app_appMenu]; app_imageView = [MyView new]; + colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGBLinear); } void CNFGSetupFullscreen( const char * WindowName, int screen_number ) @@ -219,8 +207,15 @@ void CNFGSetup( const char * WindowName, int sw, int sh ) initApp(); - app_window = [[[NSWindow alloc] initWithContentRect:frameRect - styleMask:NSWindowStyleMaskBorderless | NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable backing:NSBackingStoreBuffered defer:NO] + app_window = [[[NSWindow alloc] + initWithContentRect:frameRect + styleMask: + NSWindowStyleMaskBorderless | + NSWindowStyleMaskResizable | + NSWindowStyleMaskTitled | + NSWindowStyleMaskClosable | + NSWindowStyleMaskMiniaturizable + backing:NSBackingStoreBuffered defer:NO] autorelease]; NSString *title = [[[NSString alloc] initWithCString: WindowName encoding: NSUTF8StringEncoding] autorelease]; @@ -329,6 +324,22 @@ void CNFGHandleInput() [app_currDate release]; } +void CNFGGetDimensions( short * x, short * y ) +{ + frameRect = [app_window frame]; + CGSize app_imageSize = frameRect.size; + if (app_imageSize.width != app_sw || app_imageSize.height != app_sh) + { + app_sw = app_imageSize.width; + app_sh = app_imageSize.height; + if (bufferContext != NULL) + CGContextRelease(bufferContext); + bufferContext = createBitmapContext (app_sw, app_sh); + } + *x = app_sw; + *y = app_sh; +} + void CNFGClearFrame() { CGContextSetRGBFillColor(bufferContext, RGB2Color(CNFGBGColor), 1.0);