commit 5851251703721b5bec5e5c94bfbf93ca1a7ad6d5
parent d6341c59995a840f1e85e0389d966d469de15ef2
Author: cnlohr <lohr85@gmail.com>
Date: Fri, 8 May 2020 22:17:01 -0700
remove rawdraw folder in preperation for module
Diffstat:
10 files changed, 10 insertions(+), 2533 deletions(-)
diff --git a/.gitmodules b/.gitmodules
diff --git a/Makefile b/Makefile
@@ -2,6 +2,8 @@ CFLAGS?=-s -Os -I/opt/X11/include -Wall
LDFLAGS?=-s -L/opt/X11/lib/
CC?=gcc
+all : cnping cnping.exe
+
#CFLAGS:=$(CFLAGS) -DCNFGOGL
#LDFLAGS:=$(LDFLAGS) -lGL
@@ -18,10 +20,10 @@ MINGW32?=i686-w64-mingw32-
# If you don't need admin privileges
ADMINFLAGS:= $(ADMINFLAGS) -DWIN_USE_NO_ADMIN_PING
-cnping-wingdi.exe : cnping.c rawdraw/CNFGFunctions.c rawdraw/CNFGWinDriver.c ping.c httping.c resources.o
+cnping-wingdi.exe : cnping.c ping.c httping.c resources.o
$(MINGW32)gcc -g -fno-ident -mwindows -m32 $(CFLAGS) -o $@ $^ -lgdi32 -lws2_32 -s -D_WIN32_WINNT=0x0600 -DWIN32 -liphlpapi -DMINGW_BUILD $(ADMINFLAGS)
-cnping.exe : cnping.c rawdraw/CNFGFunctions.c rawdraw/CNFGWinDriver.c ping.c httping.c resources.o
+cnping.exe : cnping.c ping.c httping.c resources.o
$(MINGW32)gcc -g -fno-ident -mwindows -m32 -DCNFGOGL $(CFLAGS) -o $@ $^ -lgdi32 -lws2_32 -s -D_WIN32_WINNT=0x0600 -DWIN32 -liphlpapi -lopengl32 -DMINGW_BUILD $(ADMINFLAGS)
resources.o : resources.rc
@@ -31,14 +33,14 @@ resources.o : resources.rc
# Unix
all : cnping searchnet
-cnping : cnping.o rawdraw/CNFGFunctions.o rawdraw/CNFGXDriver.o ping.o httping.o
+cnping : cnping.c ping.c httping.c
$(CC) $(CFLAGS) -o $@ $^ -lX11 -lm -lpthread $(LDFLAGS)
-cnping_ogl : cnping.c rawdraw/CNFGFunctions.c rawdraw/CNFGXDriver.c ping.c httping.c
+cnping_ogl : cnping.c ping.c httping.c
$(CC) $(CFLAGS) -o $@ $^ -DCNFGOGL $(CFLAGS) -s -lX11 -lm -lpthread $(LDFLAGS) -lGL
-cnping_mac : cnping.c rawdraw/CNFGFunctions.c rawdraw/CNFGCocoaCGDriver.m ping.c httping.o
- $(CC) -o cnping $^ -x objective-c -framework Cocoa -framework QuartzCore -lm -lpthread
+cnping_mac : cnping.c ping.c httping.c
+ $(CC) -o cnping $^ -x objective-c -framework Cocoa -framework QuartzCore -lm -lpthread -DOSX
searchnet : ping.o searchnet.o
$(CC) $(CFLAGS) -o $@ $^ -lpthread
diff --git a/cnping.c b/cnping.c
@@ -24,8 +24,9 @@
#include <sys/select.h>
#include <netdb.h>
#endif
-#include "rawdraw/CNFGFunctions.h"
+#define CNFG_IMPLEMENTATION
#include "rawdraw/os_generic.h"
+#include "rawdraw/CNFG.h"
#include "ping.h"
#include "error_handling.h"
#include "httping.h"
diff --git a/rawdraw/CNFGCocoaCGDriver.m b/rawdraw/CNFGCocoaCGDriver.m
@@ -1,361 +0,0 @@
-//Copyright (c) 2017 <>< David Chapman - Under the MIT/x11 or NewBSD License you choose.
-//Copyright (C) 2017 Viknet, MIT/x11 License or NewBSD License you choose.
-
-#import <Cocoa/Cocoa.h>
-#import <Foundation/Foundation.h>
-
-#define RGB2Color(RGB) (RGB&0xFF)/256., ((RGB>>8)&0xFF)/256., ((RGB>>16)&0xFF)/256.
-
-#include "CNFGFunctions.h"
-
-id app_menubar, app_appMenuItem, app_appMenu, app_appName, app_quitMenuItem, app_quitTitle, app_quitMenuItem, app_window;
-NSView *app_imageView;
-CGColorSpaceRef colorSpace;
-CGContextRef bufferContext;
-uint32_t *bufferData;
-
-NSAutoreleasePool *app_pool;
-int app_sw=0, app_sh=0;
-NSRect frameRect;
-int app_mouseX=0, app_mouseY=0;
-BOOL inFullscreen = false;
-
-uint32_t CNFGColor( uint32_t RGB )
-{
- CNFGLastColor = RGB;
- unsigned char red = RGB & 0xFF;
- unsigned char grn = ( RGB >> 8 ) & 0xFF;
- unsigned char blu = ( RGB >> 16 ) & 0xFF;
- CGContextSetRGBStrokeColor(bufferContext, RGB2Color(RGB), 1.0);
- CGContextSetRGBFillColor(bufferContext, RGB2Color(RGB), 1.0);
- return CNFGLastColor;
-}
-
-void CNFGTackPixel( short x, short y )
-{
- y = app_sh - y - 1;
- if( x < 0 || y < 0 || x >= app_sw || y >= app_sh ) return;
- bufferData[x + app_sw * y] = CNFGLastColor;
-}
-
-// void CNFGTackSegment( short x1, short y1, short x2, short y2 )
-// {
-// y1 = app_sh - y1 - 1;
-// y2 = app_sh - y2 - 1;
-// CGContextBeginPath(bufferContext);
-// CGContextMoveToPoint(bufferContext, x1, y1);
-// CGContextAddLineToPoint(bufferContext, x2, y2);
-// CGContextStrokePath(bufferContext);
-// }
-
-void CNFGTackSegment( short x1, short y1, short x2, short y2 )
-{
- short tx, ty;
- float slope, lp;
-
- short dx = x2 - x1;
- short dy = y2 - y1;
-
- if( dx < 0 ) dx = -dx;
- if( dy < 0 ) dy = -dy;
-
- if( dx > dy )
- {
- short minx = (x1 < x2)?x1:x2;
- short maxx = (x1 < x2)?x2:x1;
- short miny = (x1 < x2)?y1:y2;
- short maxy = (x1 < x2)?y2:y1;
- float thisy = miny;
- slope = (float)(maxy-miny) / (float)(maxx-minx);
-
- for( tx = minx; tx <= maxx; tx++ )
- {
- ty = thisy;
- if( tx < 0 || ty < 0 || ty >= app_sh ) continue;
- if( tx >= app_sw ) break;
- bufferData[ty * app_sw + tx] = CNFGLastColor;
- thisy += slope;
- }
- }
- else
- {
- short minx = (y1 < y2)?x1:x2;
- short maxx = (y1 < y2)?x2:x1;
- short miny = (y1 < y2)?y1:y2;
- short maxy = (y1 < y2)?y2:y1;
- float thisx = minx;
- slope = (float)(maxx-minx) / (float)(maxy-miny);
-
- for( ty = miny; ty <= maxy; ty++ )
- {
- tx = thisx;
- if( ty < 0 || tx < 0 || tx >= app_sw ) continue;
- if( ty >= app_sh ) break;
- bufferData[ty * app_sw + tx] = CNFGLastColor;
- thisx += slope;
- }
- }
-}
-
-void CNFGTackRectangle( short x1, short y1, short x2, short y2 )
-{
- CGContextFillRect(bufferContext, CGRectMake (x1, app_sh - y1 - 1, x2, app_sh - y2 - 1 ));
-}
-
-void CNFGTackPoly( RDPoint * points, int verts )
-{
- if (verts==0) return;
- CGContextBeginPath(bufferContext);
- CGContextMoveToPoint(bufferContext, points[0].x, app_sh - points[0].y - 1);
- for (int i=1; i<verts; i++){
- CGContextAddLineToPoint(bufferContext, points[i].x, app_sh - points[i].y - 1);
- }
- CGContextFillPath(bufferContext);
-}
-
-@interface MyView : NSView
-@end
-@implementation MyView
-- (id)initWithFrame:(NSRect)frame {
- self = [super initWithFrame:frame];
- if (self)
- {
- [self setWantsLayer:YES];
- [self setLayerContentsRedrawPolicy: NSViewLayerContentsRedrawOnSetNeedsDisplay];
- // [self setLayerContentsPlacement: NSViewLayerContentsPlacementCenter];
- }
- return self;
-}
-
-- (BOOL) wantsUpdateLayer
-{
- return YES;
-}
-- (void) updateLayer
-{
- CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, bufferData, 4*app_sw*app_sh, NULL);
- CGImageRef frameImage = CGImageCreate(app_sw, app_sh, 8, 32, 4*app_sw, colorSpace, kCGBitmapByteOrderDefault, provider, NULL, false, kCGRenderingIntentDefault);
-
- [app_imageView.layer setContents:(id)frameImage];
-
- CGImageRelease(frameImage);
- CGDataProviderRelease(provider);
-}
-@end
-
-CGContextRef createBitmapContext (int pixelsWide,
- int pixelsHigh)
-{
- int bitmapBytesPerRow = (pixelsWide * 4);
-
- CGContextRef context = CGBitmapContextCreate (NULL,
- pixelsWide,
- pixelsHigh,
- 8,
- bitmapBytesPerRow,
- colorSpace,
- kCGImageAlphaNoneSkipLast);
- bufferData = CGBitmapContextGetData(context);
- CGContextSetInterpolationQuality(context, kCGInterpolationNone);
- // CGContextSetShouldAntialias(context, NO);
- // CGContextSetLineWidth(context, 0.5);
-
- return context;
-}
-
-void initApp(){
- [NSApplication sharedApplication];
- [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
- app_menubar = [[NSMenu new] autorelease];
- app_appMenuItem = [[NSMenuItem new] autorelease];
- [app_menubar addItem:app_appMenuItem];
- [NSApp setMainMenu:app_menubar];
- app_appMenu = [[NSMenu new] autorelease];
- app_appName = [[NSProcessInfo processInfo] processName];
- app_quitTitle = [@"Quit " stringByAppendingString:app_appName];
- app_quitMenuItem = [[[NSMenuItem alloc] initWithTitle:app_quitTitle
- action:@selector(terminate:) keyEquivalent:@"q"] autorelease];
- [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 )
-{
- inFullscreen = YES;
- initApp();
-
- NSDictionary *fullScreenOptions = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithInt:
- (NSApplicationPresentationAutoHideMenuBar | NSApplicationPresentationAutoHideDock) ],
- NSFullScreenModeApplicationPresentationOptions, nil];
- [app_imageView enterFullScreenMode:[[NSScreen screens] objectAtIndex:screen_number] withOptions:fullScreenOptions];
- frameRect = [app_imageView frame];
- CGSize app_imageSize = frameRect.size;
- app_sw = app_imageSize.width; app_sh = app_imageSize.height;
- bufferContext = createBitmapContext (app_sw, app_sh);
- [NSApp finishLaunching];
- [NSApp updateWindows];
- app_pool = [NSAutoreleasePool new];
-}
-
-void CNFGSetup( const char * WindowName, int sw, int sh )
-{
- app_sw=sw; app_sh=sh;
- frameRect = NSMakeRect(0, 0, app_sw, app_sh);
-
- initApp();
-
- 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];
- [app_window setTitle:title];
- [app_window setContentView:app_imageView];
- [app_window cascadeTopLeftFromPoint:NSMakePoint(20,20)];
- [app_window makeKeyAndOrderFront:nil];
- [NSApp activateIgnoringOtherApps:YES];
- bufferContext = createBitmapContext (app_sw, app_sh);
- [NSApp finishLaunching];
- [NSApp updateWindows];
- app_pool = [NSAutoreleasePool new];
-}
-
-#define XK_Left 0xff51 /* Move left, left arrow */
-#define XK_Up 0xff52 /* Move up, up arrow */
-#define XK_Right 0xff53 /* Move right, right arrow */
-#define XK_Down 0xff54 /* Move down, down arrow */
-#define KEY_UNDEFINED 255
-#define KEY_LEFT_MOUSE 0
-
-static int keycode(key)
-{
- if (key < 256) return key;
- switch(key) {
- case 63232: return XK_Up;
- case 63233: return XK_Down;
- case 63234: return XK_Left;
- case 63235: return XK_Right;
- }
- return KEY_UNDEFINED;
-}
-
-void CNFGHandleInput()
-{
- [app_pool release];
- app_pool = [NSAutoreleasePool new];
- // Quit if no open windows left
- if ([[NSApp windows] count] == 0) [NSApp terminate: nil];
-
- //----------------------
- // Peek at the next event
- //----------------------
- NSDate *app_currDate = [NSDate new];
- // If we have events, handle them!
- NSEvent *event;
- for (;(event = [NSApp
- nextEventMatchingMask:NSEventMaskAny
- untilDate:app_currDate
- inMode:NSDefaultRunLoopMode
- dequeue:YES]);)
- {
- NSPoint local_point;
- NSEventType type = [event type];
- switch (type)
- {
- case NSEventTypeKeyDown:
- for (int i=0; i<[event.characters length]; i++) {
- unichar ch = [event.characters characterAtIndex: i];
- HandleKey(keycode(ch), 1);
- }
- break;
-
- case NSEventTypeKeyUp:
- for (int i=0; i<[event.characters length]; i++) {
- unichar ch = [event.characters characterAtIndex: i];
- HandleKey(keycode(ch), 0);
- }
- break;
-
- case NSEventTypeMouseMoved:
- case NSEventTypeLeftMouseDragged:
- case NSEventTypeRightMouseDragged:
- case NSEventTypeOtherMouseDragged:
- if (inFullscreen){
- local_point = [NSEvent mouseLocation];
- } else {
- if ([event window] == nil) break;
- NSPoint event_location = event.locationInWindow;
- local_point = [app_imageView convertPoint:event_location fromView:nil];
- }
- app_mouseX = fmax(fmin(local_point.x, app_sw), 0);
- // Y coordinate must be inversed?
- app_mouseY = fmax(fmin(app_sh - local_point.y, app_sh), 0);
- HandleMotion(app_mouseX, app_mouseY, [NSEvent pressedMouseButtons]);
- break;
-
- case NSEventTypeLeftMouseDown:
- case NSEventTypeRightMouseDown:
- case NSEventTypeOtherMouseDown:
- // Button number start from 1?
- HandleButton(app_mouseX, app_mouseY, event.buttonNumber+1, 1);
- break;
-
- case NSEventTypeLeftMouseUp:
- case NSEventTypeRightMouseUp:
- case NSEventTypeOtherMouseUp:
- HandleButton(app_mouseX, app_mouseY, event.buttonNumber+1, 0);
- break;
-
- default:
- break;
- }
- [NSApp sendEvent:event];
- }
- [app_currDate release];
-}
-
-void CNFGGetDimensions( short * x, short * y )
-{
- frameRect = [[app_window contentView] 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);
- CGContextFillRect(bufferContext, CGRectMake (0, 0, app_sw, app_sh ));
-}
-
-void CNFGSwapBuffers()
-{
- [app_imageView setNeedsDisplay:YES];
-}
-
-void CNFGUpdateScreenWithBitmap( unsigned long * data, int w, int h )
-{
- CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, data, 4*w*h, NULL);
- CGImageRef bitmap = CGImageCreate(w, h, 8, 32, 4*w, colorSpace, kCGBitmapByteOrderDefault, provider, NULL, false, kCGRenderingIntentDefault);
- CGContextDrawImage(bufferContext, frameRect, bitmap);
- CGImageRelease(bitmap);
- CGDataProviderRelease(provider);
-}
diff --git a/rawdraw/CNFGFunctions.c b/rawdraw/CNFGFunctions.c
@@ -1,369 +0,0 @@
-/*
-Copyright (c) 2010, 2011 Charles Lohr
-
-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 X CONSORTIUM 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.
-*/
-
-#include "CNFGFunctions.h"
-#include <stdio.h>
-
-int CNFGPenX, CNFGPenY;
-uint32_t CNFGBGColor;
-uint32_t CNFGLastColor;
-uint32_t CNFGDialogColor; //background for boxes
-
-// The following two arrays are generated by Fonter/fonter.cpp
-const unsigned short FontCharMap[256] = {
- 65535, 0, 10, 20, 32, 44, 56, 68, 70, 65535, 65535, 80, 92, 65535, 104, 114,
- 126, 132, 138, 148, 156, 166, 180, 188, 200, 206, 212, 218, 224, 228, 238, 244,
- 65535, 250, 254, 258, 266, 278, 288, 302, 304, 310, 316, 324, 328, 226, 252, 330,
- 332, 342, 348, 358, 366, 372, 382, 392, 400, 410, 420, 424, 428, 262, 432, 436,
- 446, 460, 470, 486, 496, 508, 516, 522, 536, 542, 548, 556, 568, 572, 580, 586,
- 598, 608, 622, 634, 644, 648, 654, 662, 670, 682, 692, 700, 706, 708, 492, 198,
- 714, 716, 726, 734, 742, 750, 760, 768, 782, 790, 794, 802, 204, 810, 820, 384,
- 828, 836, 844, 850, 860, 864, 872, 880, 890, 894, 902, 908, 916, 920, 928, 934,
- 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535,
- 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535,
- 944, 948, 960, 970, 986, 996, 1000, 1016, 1020, 1026, 1034, 1042, 364, 1046, 1056, 1058,
- 1066, 1072, 1080, 932, 1092, 1100, 68, 1110, 1114, 1116, 1124, 1132, 1142, 1154, 1170, 1180,
- 1192, 1204, 1218, 1234, 1248, 1264, 1276, 1290, 1300, 1310, 1322, 1334, 1342, 1350, 1360, 1370,
- 1384, 1396, 1406, 1416, 1428, 1442, 1454, 1458, 1472, 1480, 1488, 1498, 1508, 1520, 1530, 1544,
- 1556, 1568, 1582, 1598, 1612, 1628, 1642, 1654, 1666, 1678, 1692, 1706, 1710, 1714, 1720, 1726,
- 1738, 1752, 1762, 1772, 1784, 1798, 1810, 1816, 1826, 1836, 1846, 1858, 1870, 1880, 1890, 65535, };
-
-const unsigned char FontCharData[1902] = {
- 0x00, 0x01, 0x20, 0x21, 0x03, 0x23, 0x23, 0x14, 0x14, 0x83, 0x00, 0x01, 0x20, 0x21, 0x04, 0x24,
- 0x24, 0x13, 0x13, 0x84, 0x01, 0x21, 0x21, 0x23, 0x23, 0x14, 0x14, 0x03, 0x03, 0x01, 0x11, 0x92,
- 0x11, 0x22, 0x22, 0x23, 0x23, 0x14, 0x14, 0x03, 0x03, 0x02, 0x02, 0x91, 0x01, 0x21, 0x21, 0x23,
- 0x23, 0x01, 0x03, 0x21, 0x03, 0x01, 0x12, 0x94, 0x03, 0x23, 0x13, 0x14, 0x23, 0x22, 0x22, 0x11,
- 0x11, 0x02, 0x02, 0x83, 0x12, 0x92, 0x12, 0x12, 0x01, 0x21, 0x21, 0x23, 0x23, 0x03, 0x03, 0x81,
- 0x03, 0x21, 0x21, 0x22, 0x21, 0x11, 0x03, 0x14, 0x14, 0x23, 0x23, 0x92, 0x01, 0x10, 0x10, 0x21,
- 0x21, 0x12, 0x12, 0x01, 0x12, 0x14, 0x03, 0xa3, 0x02, 0x03, 0x03, 0x13, 0x02, 0x12, 0x13, 0x10,
- 0x10, 0xa1, 0x01, 0x23, 0x03, 0x21, 0x02, 0x11, 0x11, 0x22, 0x22, 0x13, 0x13, 0x82, 0x00, 0x22,
- 0x22, 0x04, 0x04, 0x80, 0x20, 0x02, 0x02, 0x24, 0x24, 0xa0, 0x01, 0x10, 0x10, 0x21, 0x10, 0x14,
- 0x14, 0x03, 0x14, 0xa3, 0x00, 0x03, 0x04, 0x04, 0x20, 0x23, 0x24, 0xa4, 0x00, 0x20, 0x00, 0x02,
- 0x02, 0x22, 0x10, 0x14, 0x20, 0xa4, 0x01, 0x21, 0x21, 0x23, 0x23, 0x03, 0x03, 0x01, 0x20, 0x10,
- 0x10, 0x14, 0x14, 0x84, 0x03, 0x23, 0x23, 0x24, 0x24, 0x04, 0x04, 0x83, 0x01, 0x10, 0x10, 0x21,
- 0x10, 0x14, 0x14, 0x03, 0x14, 0x23, 0x04, 0xa4, 0x01, 0x10, 0x21, 0x10, 0x10, 0x94, 0x03, 0x14,
- 0x23, 0x14, 0x10, 0x94, 0x02, 0x22, 0x22, 0x11, 0x22, 0x93, 0x02, 0x22, 0x02, 0x11, 0x02, 0x93,
- 0x01, 0x02, 0x02, 0xa2, 0x02, 0x22, 0x22, 0x11, 0x11, 0x02, 0x02, 0x13, 0x13, 0xa2, 0x11, 0x22,
- 0x22, 0x02, 0x02, 0x91, 0x02, 0x13, 0x13, 0x22, 0x22, 0x82, 0x10, 0x13, 0x14, 0x94, 0x10, 0x01,
- 0x20, 0x91, 0x10, 0x14, 0x20, 0x24, 0x01, 0x21, 0x03, 0xa3, 0x21, 0x10, 0x10, 0x01, 0x01, 0x23,
- 0x23, 0x14, 0x14, 0x03, 0x10, 0x94, 0x00, 0x01, 0x23, 0x24, 0x04, 0x03, 0x03, 0x21, 0x21, 0xa0,
- 0x21, 0x10, 0x10, 0x01, 0x01, 0x12, 0x12, 0x03, 0x03, 0x14, 0x14, 0x23, 0x02, 0xa4, 0x10, 0x91,
- 0x10, 0x01, 0x01, 0x03, 0x03, 0x94, 0x10, 0x21, 0x21, 0x23, 0x23, 0x94, 0x01, 0x23, 0x11, 0x13,
- 0x21, 0x03, 0x02, 0xa2, 0x02, 0x22, 0x11, 0x93, 0x04, 0x93, 0x03, 0xa1, 0x00, 0x20, 0x20, 0x24,
- 0x24, 0x04, 0x04, 0x00, 0x12, 0x92, 0x01, 0x10, 0x10, 0x14, 0x04, 0xa4, 0x01, 0x10, 0x10, 0x21,
- 0x21, 0x22, 0x22, 0x04, 0x04, 0xa4, 0x00, 0x20, 0x20, 0x24, 0x24, 0x04, 0x12, 0xa2, 0x00, 0x02,
- 0x02, 0x22, 0x20, 0xa4, 0x20, 0x00, 0x00, 0x02, 0x02, 0x22, 0x22, 0x24, 0x24, 0x84, 0x20, 0x02,
- 0x02, 0x22, 0x22, 0x24, 0x24, 0x04, 0x04, 0x82, 0x00, 0x20, 0x20, 0x21, 0x21, 0x12, 0x12, 0x94,
- 0x00, 0x04, 0x00, 0x20, 0x20, 0x24, 0x04, 0x24, 0x02, 0xa2, 0x00, 0x02, 0x02, 0x22, 0x22, 0x20,
- 0x20, 0x00, 0x22, 0x84, 0x11, 0x11, 0x13, 0x93, 0x11, 0x11, 0x13, 0x84, 0x20, 0x02, 0x02, 0xa4,
- 0x00, 0x22, 0x22, 0x84, 0x01, 0x10, 0x10, 0x21, 0x21, 0x12, 0x12, 0x13, 0x14, 0x94, 0x21, 0x01,
- 0x01, 0x04, 0x04, 0x24, 0x24, 0x22, 0x22, 0x12, 0x12, 0x13, 0x13, 0xa3, 0x04, 0x01, 0x01, 0x10,
- 0x10, 0x21, 0x21, 0x24, 0x02, 0xa2, 0x00, 0x04, 0x04, 0x14, 0x14, 0x23, 0x23, 0x12, 0x12, 0x02,
- 0x12, 0x21, 0x21, 0x10, 0x10, 0x80, 0x23, 0x14, 0x14, 0x03, 0x03, 0x01, 0x01, 0x10, 0x10, 0xa1,
- 0x00, 0x10, 0x10, 0x21, 0x21, 0x23, 0x23, 0x14, 0x14, 0x04, 0x04, 0x80, 0x00, 0x04, 0x04, 0x24,
- 0x00, 0x20, 0x02, 0x92, 0x00, 0x04, 0x00, 0x20, 0x02, 0x92, 0x21, 0x10, 0x10, 0x01, 0x01, 0x03,
- 0x03, 0x14, 0x14, 0x23, 0x23, 0x22, 0x22, 0x92, 0x00, 0x04, 0x20, 0x24, 0x02, 0xa2, 0x00, 0x20,
- 0x10, 0x14, 0x04, 0xa4, 0x00, 0x20, 0x20, 0x23, 0x23, 0x14, 0x14, 0x83, 0x00, 0x04, 0x02, 0x12,
- 0x12, 0x21, 0x21, 0x20, 0x12, 0x23, 0x23, 0xa4, 0x00, 0x04, 0x04, 0xa4, 0x04, 0x00, 0x00, 0x11,
- 0x11, 0x20, 0x20, 0xa4, 0x04, 0x00, 0x00, 0x22, 0x20, 0xa4, 0x01, 0x10, 0x10, 0x21, 0x21, 0x23,
- 0x23, 0x14, 0x14, 0x03, 0x03, 0x81, 0x00, 0x04, 0x00, 0x10, 0x10, 0x21, 0x21, 0x12, 0x12, 0x82,
- 0x01, 0x10, 0x10, 0x21, 0x21, 0x23, 0x23, 0x14, 0x14, 0x03, 0x03, 0x01, 0x04, 0x93, 0x00, 0x04,
- 0x00, 0x10, 0x10, 0x21, 0x21, 0x12, 0x12, 0x02, 0x02, 0xa4, 0x21, 0x10, 0x10, 0x01, 0x01, 0x23,
- 0x23, 0x14, 0x14, 0x83, 0x00, 0x20, 0x10, 0x94, 0x00, 0x04, 0x04, 0x24, 0x24, 0xa0, 0x00, 0x03,
- 0x03, 0x14, 0x14, 0x23, 0x23, 0xa0, 0x00, 0x04, 0x04, 0x24, 0x14, 0x13, 0x24, 0xa0, 0x00, 0x01,
- 0x01, 0x23, 0x23, 0x24, 0x04, 0x03, 0x03, 0x21, 0x21, 0xa0, 0x00, 0x01, 0x01, 0x12, 0x12, 0x14,
- 0x12, 0x21, 0x21, 0xa0, 0x00, 0x20, 0x20, 0x02, 0x02, 0x04, 0x04, 0xa4, 0x10, 0x00, 0x00, 0x04,
- 0x04, 0x94, 0x01, 0xa3, 0x10, 0x20, 0x20, 0x24, 0x24, 0x94, 0x00, 0x91, 0x02, 0x04, 0x04, 0x24,
- 0x24, 0x22, 0x23, 0x12, 0x12, 0x82, 0x00, 0x04, 0x04, 0x24, 0x24, 0x22, 0x22, 0x82, 0x24, 0x04,
- 0x04, 0x03, 0x03, 0x12, 0x12, 0xa2, 0x20, 0x24, 0x24, 0x04, 0x04, 0x02, 0x02, 0xa2, 0x24, 0x04,
- 0x04, 0x02, 0x02, 0x22, 0x22, 0x23, 0x23, 0x93, 0x04, 0x01, 0x02, 0x12, 0x01, 0x10, 0x10, 0xa1,
- 0x23, 0x12, 0x12, 0x03, 0x03, 0x14, 0x14, 0x23, 0x23, 0x24, 0x24, 0x15, 0x15, 0x84, 0x00, 0x04,
- 0x03, 0x12, 0x12, 0x23, 0x23, 0xa4, 0x11, 0x11, 0x12, 0x94, 0x22, 0x22, 0x23, 0x24, 0x24, 0x15,
- 0x15, 0x84, 0x00, 0x04, 0x03, 0x13, 0x13, 0x22, 0x13, 0xa4, 0x02, 0x04, 0x02, 0x13, 0x12, 0x14,
- 0x12, 0x23, 0x23, 0xa4, 0x02, 0x04, 0x03, 0x12, 0x12, 0x23, 0x23, 0xa4, 0x02, 0x05, 0x04, 0x24,
- 0x24, 0x22, 0x22, 0x82, 0x02, 0x04, 0x04, 0x24, 0x25, 0x22, 0x22, 0x82, 0x02, 0x04, 0x03, 0x12,
- 0x12, 0xa2, 0x22, 0x02, 0x02, 0x03, 0x03, 0x23, 0x23, 0x24, 0x24, 0x84, 0x11, 0x14, 0x02, 0xa2,
- 0x02, 0x04, 0x04, 0x14, 0x14, 0x23, 0x24, 0xa2, 0x02, 0x03, 0x03, 0x14, 0x14, 0x23, 0x23, 0xa2,
- 0x02, 0x03, 0x03, 0x14, 0x14, 0x12, 0x13, 0x24, 0x24, 0xa2, 0x02, 0x24, 0x04, 0xa2, 0x02, 0x03,
- 0x03, 0x14, 0x22, 0x23, 0x23, 0x85, 0x02, 0x22, 0x22, 0x04, 0x04, 0xa4, 0x20, 0x10, 0x10, 0x14,
- 0x14, 0x24, 0x12, 0x82, 0x10, 0x11, 0x13, 0x94, 0x00, 0x10, 0x10, 0x14, 0x14, 0x04, 0x12, 0xa2,
- 0x01, 0x10, 0x10, 0x11, 0x11, 0xa0, 0x03, 0x04, 0x04, 0x24, 0x24, 0x23, 0x23, 0x12, 0x12, 0x83,
- 0x10, 0x10, 0x11, 0x94, 0x21, 0x10, 0x10, 0x01, 0x01, 0x02, 0x02, 0x13, 0x13, 0x22, 0x10, 0x93,
- 0x11, 0x00, 0x00, 0x04, 0x04, 0x24, 0x24, 0x23, 0x02, 0x92, 0x01, 0x02, 0x11, 0x21, 0x22, 0x23,
- 0x03, 0x13, 0x02, 0x11, 0x11, 0x22, 0x22, 0x13, 0x13, 0x82, 0x00, 0x11, 0x11, 0x20, 0x11, 0x14,
- 0x02, 0x22, 0x03, 0xa3, 0x10, 0x12, 0x13, 0x95, 0x20, 0x00, 0x00, 0x02, 0x02, 0x11, 0x11, 0x22,
- 0x02, 0x13, 0x13, 0x22, 0x22, 0x24, 0x24, 0x84, 0x00, 0x00, 0x20, 0xa0, 0x20, 0x10, 0x10, 0x11,
- 0x11, 0xa1, 0x10, 0x21, 0x20, 0x21, 0x21, 0x11, 0x11, 0x90, 0x11, 0x02, 0x02, 0x13, 0x21, 0x12,
- 0x12, 0xa3, 0x01, 0x21, 0x21, 0xa2, 0x10, 0x20, 0x20, 0x21, 0x21, 0x11, 0x12, 0x10, 0x11, 0xa2,
- 0x00, 0xa0, 0x01, 0x10, 0x10, 0x21, 0x21, 0x12, 0x12, 0x81, 0x02, 0x22, 0x11, 0x13, 0x03, 0xa3,
- 0x01, 0x10, 0x10, 0x21, 0x21, 0x03, 0x03, 0xa3, 0x01, 0x10, 0x10, 0x21, 0x21, 0x12, 0x12, 0x02,
- 0x12, 0x23, 0x23, 0x83, 0x02, 0x05, 0x04, 0x14, 0x14, 0x23, 0x22, 0xa4, 0x14, 0x10, 0x10, 0x01,
- 0x01, 0x12, 0x10, 0x20, 0x20, 0xa4, 0x14, 0x15, 0x15, 0x85, 0x20, 0xa1, 0x10, 0x20, 0x20, 0x21,
- 0x21, 0x11, 0x11, 0x90, 0x01, 0x12, 0x12, 0x03, 0x11, 0x22, 0x22, 0x93, 0x00, 0x01, 0x02, 0x20,
- 0x12, 0x13, 0x13, 0x23, 0x22, 0xa4, 0x00, 0x01, 0x02, 0x20, 0x12, 0x22, 0x22, 0x13, 0x13, 0x14,
- 0x14, 0xa4, 0x00, 0x10, 0x10, 0x11, 0x11, 0x01, 0x11, 0x02, 0x02, 0x20, 0x12, 0x13, 0x13, 0x23,
- 0x22, 0xa4, 0x10, 0x10, 0x11, 0x12, 0x12, 0x03, 0x03, 0x14, 0x14, 0xa3, 0x04, 0x02, 0x02, 0x11,
- 0x11, 0x22, 0x22, 0x24, 0x03, 0x23, 0x10, 0xa1, 0x04, 0x02, 0x02, 0x11, 0x11, 0x22, 0x22, 0x24,
- 0x03, 0x23, 0x01, 0x90, 0x04, 0x02, 0x02, 0x11, 0x11, 0x22, 0x22, 0x24, 0x03, 0x23, 0x01, 0x10,
- 0x10, 0xa1, 0x04, 0x02, 0x02, 0x11, 0x11, 0x22, 0x22, 0x24, 0x03, 0x23, 0x01, 0x10, 0x10, 0x11,
- 0x11, 0xa0, 0x04, 0x02, 0x02, 0x11, 0x11, 0x22, 0x22, 0x24, 0x03, 0x23, 0x00, 0x00, 0x20, 0xa0,
- 0x04, 0x02, 0x02, 0x11, 0x11, 0x22, 0x22, 0x24, 0x03, 0x23, 0x00, 0x20, 0x20, 0x11, 0x11, 0x80,
- 0x00, 0x04, 0x02, 0x22, 0x00, 0x11, 0x10, 0x14, 0x10, 0x20, 0x14, 0xa4, 0x23, 0x14, 0x14, 0x03,
- 0x03, 0x01, 0x01, 0x10, 0x10, 0x21, 0x14, 0x15, 0x15, 0x85, 0x02, 0x22, 0x02, 0x04, 0x04, 0x24,
- 0x03, 0x13, 0x00, 0x91, 0x02, 0x22, 0x02, 0x04, 0x04, 0x24, 0x03, 0x13, 0x11, 0xa0, 0x02, 0x22,
- 0x02, 0x04, 0x04, 0x24, 0x03, 0x13, 0x01, 0x10, 0x10, 0xa1, 0x02, 0x22, 0x02, 0x04, 0x04, 0x24,
- 0x03, 0x13, 0x00, 0x00, 0x20, 0xa0, 0x02, 0x22, 0x12, 0x14, 0x04, 0x24, 0x00, 0x91, 0x02, 0x22,
- 0x12, 0x14, 0x04, 0x24, 0x11, 0xa0, 0x02, 0x22, 0x12, 0x14, 0x04, 0x24, 0x01, 0x10, 0x10, 0xa1,
- 0x02, 0x22, 0x12, 0x14, 0x04, 0x24, 0x20, 0x20, 0x00, 0x80, 0x00, 0x10, 0x10, 0x21, 0x21, 0x23,
- 0x23, 0x14, 0x14, 0x04, 0x04, 0x00, 0x02, 0x92, 0x04, 0x02, 0x02, 0x24, 0x24, 0x22, 0x01, 0x10,
- 0x10, 0x11, 0x11, 0xa0, 0x02, 0x22, 0x22, 0x24, 0x24, 0x04, 0x04, 0x02, 0x00, 0x91, 0x02, 0x22,
- 0x22, 0x24, 0x24, 0x04, 0x04, 0x02, 0x11, 0xa0, 0x02, 0x22, 0x22, 0x24, 0x24, 0x04, 0x04, 0x02,
- 0x11, 0x20, 0x00, 0x91, 0x02, 0x22, 0x22, 0x24, 0x24, 0x04, 0x04, 0x02, 0x01, 0x10, 0x10, 0x11,
- 0x11, 0xa0, 0x01, 0x21, 0x21, 0x24, 0x24, 0x04, 0x04, 0x01, 0x00, 0x00, 0x20, 0xa0, 0x01, 0x23,
- 0x03, 0xa1, 0x01, 0x10, 0x10, 0x21, 0x21, 0x23, 0x23, 0x14, 0x14, 0x03, 0x03, 0x01, 0x03, 0xa1,
- 0x01, 0x04, 0x04, 0x24, 0x24, 0x21, 0x11, 0xa0, 0x01, 0x04, 0x04, 0x24, 0x24, 0x21, 0x00, 0x91,
- 0x02, 0x04, 0x04, 0x24, 0x24, 0x22, 0x01, 0x10, 0x10, 0xa1, 0x01, 0x04, 0x04, 0x24, 0x24, 0x21,
- 0x00, 0x00, 0x20, 0xa0, 0x01, 0x02, 0x02, 0x13, 0x13, 0x14, 0x13, 0x22, 0x22, 0x21, 0x11, 0xa0,
- 0x00, 0x04, 0x01, 0x11, 0x11, 0x22, 0x22, 0x13, 0x13, 0x83, 0x00, 0x05, 0x00, 0x10, 0x10, 0x21,
- 0x21, 0x12, 0x02, 0x22, 0x22, 0x24, 0x24, 0x84, 0x02, 0x04, 0x04, 0x24, 0x24, 0x22, 0x23, 0x12,
- 0x12, 0x02, 0x00, 0x91, 0x02, 0x04, 0x04, 0x24, 0x24, 0x22, 0x23, 0x12, 0x12, 0x02, 0x11, 0xa0,
- 0x02, 0x04, 0x04, 0x24, 0x24, 0x22, 0x23, 0x12, 0x12, 0x02, 0x01, 0x10, 0x10, 0xa1, 0x02, 0x04,
- 0x04, 0x24, 0x24, 0x22, 0x23, 0x12, 0x12, 0x02, 0x01, 0x10, 0x10, 0x11, 0x11, 0xa0, 0x02, 0x04,
- 0x04, 0x24, 0x24, 0x22, 0x23, 0x12, 0x12, 0x02, 0x01, 0x01, 0x21, 0xa1, 0x02, 0x04, 0x04, 0x24,
- 0x24, 0x22, 0x23, 0x12, 0x12, 0x02, 0x01, 0x10, 0x10, 0x21, 0x21, 0x81, 0x02, 0x13, 0x02, 0x04,
- 0x04, 0x24, 0x12, 0x14, 0x12, 0x22, 0x13, 0x23, 0x22, 0xa3, 0x03, 0x04, 0x04, 0x24, 0x03, 0x12,
- 0x12, 0x22, 0x14, 0x15, 0x15, 0x85, 0x24, 0x04, 0x04, 0x02, 0x02, 0x22, 0x22, 0x23, 0x23, 0x13,
- 0x00, 0x91, 0x24, 0x04, 0x04, 0x02, 0x02, 0x22, 0x22, 0x23, 0x23, 0x13, 0x11, 0xa0, 0x24, 0x04,
- 0x04, 0x02, 0x02, 0x22, 0x22, 0x23, 0x23, 0x13, 0x01, 0x10, 0x10, 0xa1, 0x24, 0x04, 0x04, 0x02,
- 0x02, 0x22, 0x22, 0x23, 0x23, 0x13, 0x01, 0x01, 0x21, 0xa1, 0x12, 0x14, 0x00, 0x91, 0x12, 0x14,
- 0x11, 0xa0, 0x12, 0x14, 0x01, 0x10, 0x10, 0xa1, 0x12, 0x14, 0x01, 0x01, 0x21, 0xa1, 0x00, 0x22,
- 0x11, 0x20, 0x02, 0x22, 0x22, 0x24, 0x24, 0x04, 0x04, 0x82, 0x02, 0x04, 0x03, 0x12, 0x12, 0x23,
- 0x23, 0x24, 0x01, 0x10, 0x10, 0x11, 0x11, 0xa0, 0x02, 0x04, 0x04, 0x24, 0x24, 0x22, 0x22, 0x02,
- 0x00, 0x91, 0x02, 0x04, 0x04, 0x24, 0x24, 0x22, 0x22, 0x02, 0x11, 0xa0, 0x02, 0x04, 0x04, 0x24,
- 0x24, 0x22, 0x22, 0x02, 0x01, 0x10, 0x10, 0xa1, 0x02, 0x04, 0x04, 0x24, 0x24, 0x22, 0x22, 0x02,
- 0x01, 0x10, 0x10, 0x11, 0x11, 0xa0, 0x02, 0x04, 0x04, 0x24, 0x24, 0x22, 0x22, 0x02, 0x01, 0x01,
- 0x21, 0xa1, 0x11, 0x11, 0x02, 0x22, 0x13, 0x93, 0x02, 0x04, 0x04, 0x24, 0x24, 0x22, 0x22, 0x02,
- 0x04, 0xa2, 0x02, 0x04, 0x04, 0x14, 0x14, 0x23, 0x24, 0x22, 0x00, 0x91, 0x02, 0x04, 0x04, 0x14,
- 0x14, 0x23, 0x24, 0x22, 0x11, 0xa0, 0x02, 0x04, 0x04, 0x14, 0x14, 0x23, 0x24, 0x22, 0x01, 0x10,
- 0x10, 0xa1, 0x02, 0x04, 0x04, 0x14, 0x14, 0x23, 0x24, 0x22, 0x01, 0x01, 0x21, 0xa1, 0x02, 0x03,
- 0x03, 0x14, 0x22, 0x23, 0x23, 0x05, 0x11, 0xa0, 0x00, 0x04, 0x02, 0x11, 0x11, 0x22, 0x22, 0x13,
- 0x13, 0x82, 0x02, 0x03, 0x03, 0x14, 0x22, 0x23, 0x23, 0x05, 0x01, 0x01, 0x21, 0xa1, };
-
-
-
-void CNFGDrawText( const char * text, int scale )
-{
- const unsigned char * lmap;
- float iox = (float)CNFGPenX;
- float ioy = (float)CNFGPenY;
-
- int place = 0;
- unsigned short index;
- int bQuit = 0;
- while( text[place] )
- {
- unsigned char c = text[place];
-
- switch( c )
- {
- case 9: // tab
- iox += 12 * scale;
- break;
- case 10: // linefeed
- iox = (float)CNFGPenX;
- ioy += 6 * scale;
- break;
- default:
- index = FontCharMap[c];
- if( index == 65535 )
- {
- iox += 3 * scale;
- break;
- }
-
- lmap = &FontCharData[index];
- do
- {
- int x1 = (int)((((*lmap) & 0x70)>>4)*scale + iox);
- int y1 = (int)(((*lmap) & 0x0f)*scale + ioy);
- int x2 = (int)((((*(lmap+1)) & 0x70)>>4)*scale + iox);
- int y2 = (int)(((*(lmap+1)) & 0x0f)*scale + ioy);
- lmap++;
- CNFGTackSegment( x1, y1, x2, y2 );
- bQuit = *lmap & 0x80;
- lmap++;
- } while( !bQuit );
-
- iox += 3 * scale;
- }
- place++;
- }
-}
-
-
-void CNFGDrawBox( int x1, int y1, int x2, int y2 )
-{
- unsigned lc = CNFGLastColor;
- CNFGColor( CNFGDialogColor );
- CNFGTackRectangle( x1, y1, x2, y2 );
- CNFGColor( lc );
- CNFGTackSegment( x1, y1, x2, y1 );
- CNFGTackSegment( x2, y1, x2, y2 );
- CNFGTackSegment( x2, y2, x1, y2 );
- CNFGTackSegment( x1, y2, x1, y1 );
-}
-
-void CNFGGetTextExtents( const char * text, int * w, int * h, int textsize )
-{
- int charsx = 0;
- int charsy = 1;
- int charsline = 0;
- const char * s;
-
- for( s = text; *s; s++ )
- {
- if( *s == '\n' )
- {
- charsline = 0;
- if( *(s+1) )
- charsy++;
- }
- else
- {
- charsline++;
- if( charsline > charsx )
- charsx = charsline;
- }
- }
-
- *w = charsx * textsize * 3 + textsize;
- *h = charsy * textsize * 6;
-}
-
-void CNFGDrawTextbox( int x, int y, const char * text, int textsize )
-{
- int w;
- int h;
-
- CNFGGetTextExtents( text, &w, &h, textsize );
-
- CNFGDrawBox( x, y, x + w, y + h );
- CNFGPenX = x + textsize;
- CNFGPenY = y + textsize;
- CNFGDrawText( text, textsize );
-}
-
-
-#if defined( CNFGOGL ) && !defined( HAS_XSHAPE )
-
-#ifdef _MSC_VER
-#include <windows.h>
-#pragma comment( lib, "OpenGL32.lib" )
-#endif
-#include <GL/gl.h>
-
-uint32_t CNFGColor( uint32_t RGB )
-{
- unsigned char red = RGB & 0xFF;
- unsigned char grn = ( RGB >> 8 ) & 0xFF;
- unsigned char blu = ( RGB >> 16 ) & 0xFF;
- glColor3ub( red, grn, blu );
- return RGB;
-}
-
-void CNFGClearFrame()
-{
- short w, h;
- unsigned char red = CNFGBGColor & 0xFF;
- unsigned char grn = ( CNFGBGColor >> 8 ) & 0xFF;
- unsigned char blu = ( CNFGBGColor >> 16 ) & 0xFF;
- glClearColor( red/255.0, grn/255.0, blu/255.0, 1.0 );
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- CNFGGetDimensions( &w, &h );
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity();
- glViewport( 0, 0, w, h );
- glOrtho( 0, w, h, 0, 1, -1 );
- glMatrixMode( GL_MODELVIEW );
- glLoadIdentity();
-}
-
-
-void CNFGTackSegment( short x1, short y1, short x2, short y2 )
-{
- if( x1 == x2 && y1 == y2 )
- {
- glBegin( GL_POINTS );
- glVertex2f( x1+.5, y1+.5 );
- glEnd();
- }
- else
- {
- // GL_LINE misses the last pixel if the line is not continued
- // due to the Diamond-exit rule so we use GL_LINE_LOOP which
- // draws the line back and forth catching all the pixels.
- glBegin( GL_LINE_LOOP );
- glVertex2f( x1+.5, y1+.5 );
- glVertex2f( x2+.5, y2+.5 );
- glEnd();
- }
-}
-
-void CNFGTackPixel( short x1, short y1 )
-{
- glBegin( GL_POINTS );
- glVertex2f( x1, y1 );
- glEnd();
-}
-
-void CNFGTackRectangle( short x1, short y1, short x2, short y2 )
-{
- glBegin( GL_QUADS );
- glVertex2f( x1, y1 );
- glVertex2f( x2, y1 );
- glVertex2f( x2, y2 );
- glVertex2f( x1, y2 );
- glEnd();
-}
-
-void CNFGTackPoly( RDPoint * points, int verts )
-{
- int i;
- glBegin( GL_TRIANGLE_FAN );
- glVertex2f( points[0].x, points[0].y );
- for( i = 1; i < verts; i++ )
- {
- glVertex2f( points[i].x, points[i].y );
- }
- glEnd();
-}
-
-void CNFGInternalResize( short x, short y ) { }
-
-
-void CNFGSetLineWidth( short width )
-{
- glLineWidth( width );
-}
-
-#endif
diff --git a/rawdraw/CNFGFunctions.h b/rawdraw/CNFGFunctions.h
@@ -1,74 +0,0 @@
-//Copyright (c) 2011, 2017 <>< Charles Lohr - Under the MIT/x11 or NewBSD License you choose.
-
-#ifndef _DRAWFUCNTIONS_H
-#define _DRAWFUCNTIONS_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdint.h>
-
-typedef struct {
- short x, y;
-} RDPoint;
-
-extern int CNFGPenX, CNFGPenY;
-extern uint32_t CNFGBGColor;
-extern uint32_t CNFGLastColor;
-extern uint32_t CNFGDialogColor; //background for boxes
-
-void CNFGDrawText( const char * text, int scale );
-void CNFGDrawBox( int x1, int y1, int x2, int y2 );
-void CNFGGetTextExtents( const char * text, int * w, int * h, int textsize );
-void CNFGDrawTextbox( int x, int y, const char * text, int textsize ); //ignores pen.
-
-//To be provided by driver.
-uint32_t CNFGColor( uint32_t RGB );
-void CNFGUpdateScreenWithBitmap( unsigned long * data, int w, int h );
-void CNFGTackPixel( short x1, short y1 );
-void CNFGTackSegment( short x1, short y1, short x2, short y2 );
-void CNFGTackRectangle( short x1, short y1, short x2, short y2 );
-void CNFGTackPoly( RDPoint * points, int verts );
-void CNFGClearFrame();
-void CNFGSwapBuffers();
-
-void CNFGGetDimensions( short * x, short * y );
-int CNFGSetup( const char * WindowName, int w, int h ); //return 0 if ok.
-void CNFGSetupFullscreen( const char * WindowName, int screen_number );
-void CNFGHandleInput();
-
-
-//You must provide:
-void HandleKey( int keycode, int bDown );
-void HandleButton( int x, int y, int button, int bDown );
-void HandleMotion( int x, int y, int mask );
-void HandleDestroy();
-
-
-//Internal function for resizing rasterizer for rasterizer-mode.
-void CNFGInternalResize( short x, short y ); //don't call this.
-
-//Not available on all systems. Use The OGL portion with care.
-#ifdef CNFGOGL
-void CNFGSetVSync( int vson );
-void * CNFGGetExtension( const char * extname );
-#endif
-
-//Also not available on all systems. Transparency.
-void CNFGPrepareForTransparency();
-void CNFGDrawToTransparencyMode( int transp );
-void CNFGClearTransparencyLevel();
-
-//Only available on systems that support it.
-void CNFGSetLineWidth( short width );
-void CNFGChangeWindowTitle( const char * windowtitle );
-void CNFGSetWindowIconData( int w, int h, uint32_t * data );
-
-#ifdef __cplusplus
-};
-#endif
-
-
-#endif
-
diff --git a/rawdraw/CNFGRasterizer.h b/rawdraw/CNFGRasterizer.h
@@ -1,247 +0,0 @@
-//Don't call this file yourself. It is intended to be included in any drivers which want to support the rasterizer plugin.
-
-#ifdef RASTERIZER
-#include "CNFGFunctions.h"
-#include <stdlib.h>
-#include <stdint.h>
-
-static uint32_t * buffer = 0;
-static short bufferx;
-static short buffery;
-
-
-void CNFGInternalResize( short x, short y )
-{
- bufferx = x;
- buffery = y;
- if( buffer ) free( buffer );
- buffer = malloc( bufferx * buffery * 4 );
-}
-
-static uint32_t SWAPS( uint32_t r )
-{
- uint32_t ret = (r&0xFF)<<16;
- r>>=8;
- ret |= (r&0xff)<<8;
- r>>=8;
- ret |= r;
- return ret;
-}
-
-uint32_t CNFGColor( uint32_t RGB )
-{
- CNFGLastColor = SWAPS(RGB);
- return CNFGLastColor;
-}
-
-void CNFGTackSegment( short x1, short y1, short x2, short y2 )
-{
- short tx, ty;
- float slope, lp;
-
- short dx = x2 - x1;
- short dy = y2 - y1;
-
- if( !buffer ) return;
-
- if( dx < 0 ) dx = -dx;
- if( dy < 0 ) dy = -dy;
-
- if( dx > dy )
- {
- short minx = (x1 < x2)?x1:x2;
- short maxx = (x1 < x2)?x2:x1;
- short miny = (x1 < x2)?y1:y2;
- short maxy = (x1 < x2)?y2:y1;
- float thisy = miny;
- slope = (float)(maxy-miny) / (float)(maxx-minx);
-
- for( tx = minx; tx <= maxx; tx++ )
- {
- ty = thisy;
- if( tx < 0 || ty < 0 || ty >= buffery ) continue;
- if( tx >= bufferx ) break;
- buffer[ty * bufferx + tx] = CNFGLastColor;
- thisy += slope;
- }
- }
- else
- {
- short minx = (y1 < y2)?x1:x2;
- short maxx = (y1 < y2)?x2:x1;
- short miny = (y1 < y2)?y1:y2;
- short maxy = (y1 < y2)?y2:y1;
- float thisx = minx;
- slope = (float)(maxx-minx) / (float)(maxy-miny);
-
- for( ty = miny; ty <= maxy; ty++ )
- {
- tx = thisx;
- if( ty < 0 || tx < 0 || tx >= bufferx ) continue;
- if( ty >= buffery ) break;
- buffer[ty * bufferx + tx] = CNFGLastColor;
- thisx += slope;
- }
- }
-}
-void CNFGTackRectangle( short x1, short y1, short x2, short y2 )
-{
- short minx = (x1<x2)?x1:x2;
- short miny = (y1<y2)?y1:y2;
- short maxx = (x1>=x2)?x1:x2;
- short maxy = (y1>=y2)?y1:y2;
-
- short x, y;
-
- if( minx < 0 ) minx = 0;
- if( miny < 0 ) miny = 0;
- if( maxx >= bufferx ) maxx = bufferx-1;
- if( maxy >= buffery ) maxy = buffery-1;
-
- for( y = miny; y <= maxy; y++ )
- {
- uint32_t * bufferstart = &buffer[y * bufferx + minx];
- for( x = minx; x <= maxx; x++ )
- {
- (*bufferstart++) = CNFGLastColor;
- }
- }
-}
-
-void CNFGTackPoly( RDPoint * points, int verts )
-{
- short minx = 10000, miny = 10000;
- short maxx =-10000, maxy =-10000;
- short i, x, y;
-
- //Just in case...
- if( verts > 32767 ) return;
-
- for( i = 0; i < verts; i++ )
- {
- RDPoint * p = &points[i];
- if( p->x < minx ) minx = p->x;
- if( p->y < miny ) miny = p->y;
- if( p->x > maxx ) maxx = p->x;
- if( p->y > maxy ) maxy = p->y;
- }
-
- if( miny < 0 ) miny = 0;
- if( maxy >= buffery ) maxy = buffery-1;
-
- for( y = miny; y <= maxy; y++ )
- {
- short startfillx = maxx;
- short endfillx = minx;
-
- //Figure out what line segments intersect this line.
- for( i = 0; i < verts; i++ )
- {
- short pl = i + 1;
- if( pl == verts ) pl = 0;
-
- RDPoint ptop;
- RDPoint pbot;
-
- ptop.x = points[i].x;
- ptop.y = points[i].y;
- pbot.x = points[pl].x;
- pbot.y = points[pl].y;
-//printf( "Poly: %d %d\n", pbot.y, ptop.y );
-
- if( pbot.y < ptop.y )
- {
- RDPoint ptmp;
- ptmp.x = pbot.x;
- ptmp.y = pbot.y;
- pbot.x = ptop.x;
- pbot.y = ptop.y;
- ptop.x = ptmp.x;
- ptop.y = ptmp.y;
- }
-
- //Make sure this line segment is within our range.
-//printf( "PT: %d %d %d\n", y, ptop.y, pbot.y );
- if( ptop.y <= y && pbot.y >= y )
- {
- short diffy = pbot.y - ptop.y;
- uint32_t placey = (uint32_t)(y - ptop.y)<<16; //Scale by 16 so we can do integer math.
- short diffx = pbot.x - ptop.x;
- short isectx;
-
- if( diffy == 0 )
- {
- if( pbot.x < ptop.x )
- {
- if( startfillx > pbot.x ) startfillx = pbot.x;
- if( endfillx < ptop.x ) endfillx = ptop.x;
- }
- else
- {
- if( startfillx > ptop.x ) startfillx = ptop.x;
- if( endfillx < pbot.x ) endfillx = pbot.x;
- }
- }
- else
- {
- //Inner part is scaled by 65536, outer part must be scaled back.
- isectx = (( (placey / diffy) * diffx + 32768 )>>16) + ptop.x;
- if( isectx < startfillx ) startfillx = isectx;
- if( isectx > endfillx ) endfillx = isectx;
- }
-//printf( "R: %d %d %d\n", pbot.x, ptop.x, isectx );
- }
- }
-
-//printf( "%d %d %d\n", y, startfillx, endfillx );
-
- if( endfillx >= bufferx ) endfillx = bufferx - 1;
- if( endfillx >= bufferx ) endfillx = buffery - 1;
- if( startfillx < 0 ) startfillx = 0;
- if( startfillx < 0 ) startfillx = 0;
-
- unsigned int * bufferstart = &buffer[y * bufferx + startfillx];
- for( x = startfillx; x <= endfillx; x++ )
- {
- (*bufferstart++) = CNFGLastColor;
- }
- }
-//exit(1);
-}
-
-
-void CNFGClearFrame()
-{
- int i, m;
- uint32_t col = 0;
- short x, y;
- CNFGGetDimensions( &x, &y );
- if( x != bufferx || y != buffery || !buffer )
- {
- bufferx = x;
- buffery = y;
- buffer = malloc( x * y * 8 );
- }
-
- m = x * y;
- col = CNFGColor( CNFGBGColor );
- for( i = 0; i < m; i++ )
- {
-//printf( "Got: %d %p %d\n", m, buffer, i );
- buffer[i] = col;
- }
-}
-
-void CNFGTackPixel( short x, short y )
-{
- if( x < 0 || y < 0 || x >= bufferx || y >= buffery ) return;
- buffer[x+bufferx*y] = CNFGLastColor;
-}
-
-void CNFGSwapBuffers()
-{
- CNFGUpdateScreenWithBitmap( (long unsigned int*)buffer, bufferx, buffery );
-}
-
-
-#endif
diff --git a/rawdraw/CNFGWinDriver.c b/rawdraw/CNFGWinDriver.c
@@ -1,358 +0,0 @@
-//Copyright (c) 2011-2019 <>< Charles Lohr - Under the MIT/x11 or NewBSD License you choose.
-//Portion from: http://en.wikibooks.org/wiki/Windows_Programming/Window_Creation
-
-
-#include "CNFGFunctions.h"
-#include <windows.h>
-#include <stdlib.h>
-#include <malloc.h> //for alloca
-
-static HBITMAP lsBitmap;
-static HWND lsHWND;
-static HDC lsWindowHDC;
-static HDC lsHDC;
-
-#ifdef RASTERIZER
-#include "CNFGRasterizer.h"
-
-void InternalHandleResize()
-{
- if( lsBitmap ) DeleteObject( lsBitmap );
-
- CNFGInternalResize( bufferx, buffery );
- lsBitmap = CreateBitmap( bufferx, buffery, 1, 32, buffer );
- SelectObject( lsHDC, lsBitmap );
-}
-#else
-static int bufferx, buffery;
-static int bufferx, buffery;
-static void InternalHandleResize();
-#endif
-
-
-#ifdef CNFGOGL
-#include <GL/gl.h>
-static HGLRC hRC=NULL;
-static void InternalHandleResize() { }
-void CNFGSwapBuffers()
-{
- SwapBuffers(lsWindowHDC);
-}
-#endif
-
-void CNFGGetDimensions( short * x, short * y )
-{
- static int lastx, lasty;
- RECT window;
- GetClientRect( lsHWND, &window );
- bufferx = ( window.right - window.left);
- buffery = ( window.bottom - window.top);
- if( bufferx != lastx || buffery != lasty )
- {
- lastx = bufferx;
- lasty = buffery;
- InternalHandleResize();
- }
- *x = bufferx;
- *y = buffery;
-}
-
-
-void CNFGUpdateScreenWithBitmap( unsigned long * data, int w, int h )
-{
- RECT r;
-
- SetBitmapBits(lsBitmap,w*h*4,data);
- BitBlt(lsWindowHDC, 0, 0, w, h, lsHDC, 0, 0, SRCCOPY);
- UpdateWindow( lsHWND );
-
- int thisw, thish;
-
- //Check to see if the window is closed.
- if( !IsWindow( lsHWND ) )
- {
- exit( 0 );
- }
-
- GetClientRect( lsHWND, &r );
- thisw = r.right - r.left;
- thish = r.bottom - r.top;
- if( thisw != bufferx || thish != buffery )
- {
- bufferx = thisw;
- buffery = thish;
- InternalHandleResize();
- }
-}
-
-
-void CNFGTearDown()
-{
- PostQuitMessage(0);
-}
-
-//This was from the article
-LRESULT CALLBACK MyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- switch(msg)
- {
-#ifndef CNFGOGL
- case WM_SYSCOMMAND: //Not sure why, if deactivated, the dc gets unassociated?
- if( wParam == SC_RESTORE || wParam == SC_MAXIMIZE || wParam == SC_SCREENSAVE )
- {
- SelectObject( lsHDC, lsBitmap );
- SelectObject( lsWindowHDC, lsBitmap );
- }
- break;
-#endif
- case WM_DESTROY:
- HandleDestroy();
- CNFGTearDown();
- return 0;
- }
- return DefWindowProc(hwnd, msg, wParam, lParam);
-}
-
-//This was from the article, too... well, mostly.
-int CNFGSetup( const char * name_of_window, int width, int height )
-{
- static LPSTR szClassName = "MyClass";
- RECT client, window;
- WNDCLASS wnd;
- int w, h, wd, hd;
- HINSTANCE hInstance = GetModuleHandle(NULL);
-
- bufferx = width;
- buffery = height;
-
- wnd.style = CS_HREDRAW | CS_VREDRAW; //we will explain this later
- wnd.lpfnWndProc = MyWndProc;
- wnd.cbClsExtra = 0;
- wnd.cbWndExtra = 0;
- wnd.hInstance = hInstance;
- wnd.hIcon = LoadIcon(NULL, IDI_APPLICATION); //default icon
- wnd.hCursor = LoadCursor(NULL, IDC_ARROW); //default arrow mouse cursor
- wnd.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);
- wnd.lpszMenuName = NULL; //no menu
- wnd.lpszClassName = szClassName;
-
- if(!RegisterClass(&wnd)) //register the WNDCLASS
- {
- MessageBox(NULL, "This Program Requires Windows NT", "Error", MB_OK);
- }
-
- lsHWND = CreateWindow(szClassName,
- name_of_window, //name_of_window,
- WS_OVERLAPPEDWINDOW, //basic window style
- CW_USEDEFAULT,
- CW_USEDEFAULT, //set starting point to default value
- bufferx,
- buffery, //set all the dimensions to default value
- NULL, //no parent window
- NULL, //no menu
- hInstance,
- NULL); //no parameters to pass
-
- lsWindowHDC = GetDC( lsHWND );
-
-#ifdef CNFGOGL
- //From NeHe
- static PIXELFORMATDESCRIPTOR pfd =
- {
- sizeof(PIXELFORMATDESCRIPTOR),
- 1,
- PFD_DRAW_TO_WINDOW |
- PFD_SUPPORT_OPENGL |
- PFD_DOUBLEBUFFER,
- PFD_TYPE_RGBA,
- 32,
- 0, 0, 0, 0, 0, 0,
- 0,
- 0,
- 0,
- 0, 0, 0, 0,
- 16,
- 0,
- 0,
- PFD_MAIN_PLANE,
- 0,
- 0, 0, 0
- };
- GLuint PixelFormat = ChoosePixelFormat( lsWindowHDC, &pfd );
- if( !SetPixelFormat( lsWindowHDC, PixelFormat, &pfd ) )
- {
- MessageBox( 0, "Could not create PFD for OpenGL Context\n", 0, 0 );
- exit( -1 );
- }
- if (!(hRC=wglCreateContext(lsWindowHDC))) // Are We Able To Get A Rendering Context?
- {
- MessageBox( 0, "Could not create OpenGL Context\n", 0, 0 );
- exit( -1 );
- }
- if(!wglMakeCurrent(lsWindowHDC,hRC)) // Try To Activate The Rendering Context
- {
- MessageBox( 0, "Could not current OpenGL Context\n", 0, 0 );
- exit( -1 );
- }
-#endif
-
- lsHDC = CreateCompatibleDC( lsWindowHDC );
- lsBitmap = CreateCompatibleBitmap( lsWindowHDC, bufferx, buffery );
- SelectObject( lsHDC, lsBitmap );
-
- //lsClearBrush = CreateSolidBrush( CNFGBGColor );
- //lsHBR = CreateSolidBrush( 0xFFFFFF );
- //lsHPEN = CreatePen( PS_SOLID, 0, 0xFFFFFF );
-
- ShowWindow(lsHWND, 1); //display the window on the screen
-
- //Once set up... we have to change the window's borders so we get the client size right.
- GetClientRect( lsHWND, &client );
- GetWindowRect( lsHWND, &window );
- w = ( window.right - window.left);
- h = ( window.bottom - window.top);
- wd = w - client.right;
- hd = h - client.bottom;
- MoveWindow( lsHWND, window.left, window.top, bufferx + wd, buffery + hd, 1 );
-
- InternalHandleResize();
-
- return 0;
-}
-
-void CNFGHandleInput()
-{
- MSG msg;
- while( PeekMessage( &msg, lsHWND, 0, 0xFFFF, 1 ) )
- {
- TranslateMessage(&msg);
-
- switch( msg.message )
- {
- case WM_MOUSEMOVE:
- HandleMotion( (msg.lParam & 0xFFFF), (msg.lParam>>16) & 0xFFFF, ( (msg.wParam & 0x01)?1:0) | ((msg.wParam & 0x02)?2:0) | ((msg.wParam & 0x10)?4:0) );
- break;
- case WM_LBUTTONDOWN: HandleButton( (msg.lParam & 0xFFFF), (msg.lParam>>16) & 0xFFFF, 1, 1 ); break;
- case WM_RBUTTONDOWN: HandleButton( (msg.lParam & 0xFFFF), (msg.lParam>>16) & 0xFFFF, 2, 1 ); break;
- case WM_MBUTTONDOWN: HandleButton( (msg.lParam & 0xFFFF), (msg.lParam>>16) & 0xFFFF, 3, 1 ); break;
- case WM_LBUTTONUP: HandleButton( (msg.lParam & 0xFFFF), (msg.lParam>>16) & 0xFFFF, 1, 0 ); break;
- case WM_RBUTTONUP: HandleButton( (msg.lParam & 0xFFFF), (msg.lParam>>16) & 0xFFFF, 2, 0 ); break;
- case WM_MBUTTONUP: HandleButton( (msg.lParam & 0xFFFF), (msg.lParam>>16) & 0xFFFF, 3, 0 ); break;
- case WM_KEYDOWN:
- case WM_KEYUP:
- HandleKey( tolower( msg.wParam ), (msg.message==WM_KEYDOWN) );
- break;
- default:
- DispatchMessage(&msg);
- break;
- }
- }
-}
-
-#ifndef CNFGOGL
-
-#ifndef RASTERIZER
-
-static HBITMAP lsBackBitmap;
-static HDC lsWindowHDC;
-static HBRUSH lsHBR;
-static HPEN lsHPEN;
-static HBRUSH lsClearBrush;
-
-static void InternalHandleResize()
-{
- DeleteObject( lsBackBitmap );
- lsBackBitmap = CreateCompatibleBitmap( lsHDC, bufferx, buffery );
- SelectObject( lsHDC, lsBackBitmap );
-}
-
-uint32_t CNFGColor( uint32_t RGB )
-{
- CNFGLastColor = RGB;
-
- DeleteObject( lsHBR );
- lsHBR = CreateSolidBrush( RGB );
- SelectObject( lsHDC, lsHBR );
-
- DeleteObject( lsHPEN );
- lsHPEN = CreatePen( PS_SOLID, 0, RGB );
- SelectObject( lsHDC, lsHPEN );
-
- return RGB;
-}
-
-void CNFGTackSegment( short x1, short y1, short x2, short y2 )
-{
- POINT pt[2] = { {x1, y1}, {x2, y2} };
- Polyline( lsHDC, pt, 2 );
- SetPixel( lsHDC, x1, y1, CNFGLastColor );
- SetPixel( lsHDC, x2, y2, CNFGLastColor );
-}
-
-void CNFGTackRectangle( short x1, short y1, short x2, short y2 )
-{
- RECT r;
- if( x1 < x2 ) { r.left = x1; r.right = x2; }
- else { r.left = x2; r.right = x1; }
- if( y1 < y2 ) { r.top = y1; r.bottom = y2; }
- else { r.top = y2; r.bottom = y1; }
- FillRect( lsHDC, &r, lsHBR );
-}
-
-void CNFGClearFrame()
-{
- RECT r = { 0, 0, bufferx, buffery };
- DeleteObject( lsClearBrush );
- lsClearBrush = CreateSolidBrush( CNFGBGColor );
- SelectObject( lsHDC, lsClearBrush );
- FillRect( lsHDC, &r, lsClearBrush);
-}
-
-void CNFGTackPoly( RDPoint * points, int verts )
-{
- int i;
- POINT * t = (POINT*)alloca( sizeof( POINT ) * verts );
- for( i = 0; i < verts; i++ )
- {
- t[i].x = points[i].x;
- t[i].y = points[i].y;
- }
- Polygon( lsHDC, t, verts );
-}
-
-
-void CNFGTackPixel( short x1, short y1 )
-{
- SetPixel( lsHDC, x1, y1, CNFGLastColor );
-}
-
-void CNFGSwapBuffers()
-{
- int thisw, thish;
-
- RECT r;
- BitBlt( lsWindowHDC, 0, 0, bufferx, buffery, lsHDC, 0, 0, SRCCOPY );
- UpdateWindow( lsHWND );
- //Check to see if the window is closed.
- if( !IsWindow( lsHWND ) )
- {
- exit( 0 );
- }
-
- GetClientRect( lsHWND, &r );
- thisw = r.right - r.left;
- thish = r.bottom - r.top;
-
- if( thisw != bufferx || thish != buffery )
- {
- bufferx = thisw;
- buffery = thish;
- InternalHandleResize();
- }
-}
-
-void CNFGInternalResize( short bufferx, short buffery ) { }
-#endif
-
-#endif
-
diff --git a/rawdraw/CNFGXDriver.c b/rawdraw/CNFGXDriver.c
@@ -1,627 +0,0 @@
-//Copyright (c) 2011, 2017, 2018 <>< Charles Lohr - Under the MIT/x11 or NewBSD License you choose.
-//portions from
-//http://www.xmission.com/~georgeps/documentation/tutorials/Xlib_Beginner.html
-
-//#define HAS_XINERAMA
-//#define HAS_XSHAPE
-//#define FULL_SCREEN_STEAL_FOCUS
-
-#include "CNFGFunctions.h"
-
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/Xos.h>
-#include <X11/Xatom.h>
-#include <X11/keysym.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#ifdef HAS_XINERAMA
- #include <X11/extensions/shape.h>
- #include <X11/extensions/Xinerama.h>
-#endif
-#ifdef HAS_XSHAPE
- #include <X11/extensions/shape.h>
- static XGCValues xsval;
- static Pixmap xspixmap;
- static GC xsgc;
-
- static int taint_shape;
- static int prepare_xshape;
- static int was_transp;
-
-#endif
-
-
-XWindowAttributes CNFGWinAtt;
-XClassHint *CNFGClassHint;
-Display *CNFGDisplay;
-Window CNFGWindow;
-Pixmap CNFGPixmap;
-GC CNFGGC;
-GC CNFGWindowGC;
-Visual * CNFGVisual;
-
-int g_x_global_key_state;
-int g_x_global_shift_key;
-
-void CNFGSetWindowIconData( int w, int h, uint32_t * data )
-{
- static Atom net_wm_icon;
- static Atom cardinal;
-
- if( !net_wm_icon ) net_wm_icon = XInternAtom( CNFGDisplay, "_NET_WM_ICON", False );
- if( !cardinal ) cardinal = XInternAtom( CNFGDisplay, "CARDINAL", False );
-
- unsigned long outdata[w*h];
- int i;
- for( i = 0; i < w*h; i++ )
- {
- outdata[i+2] = data[i];
- }
- outdata[0] = w;
- outdata[1] = h;
- XChangeProperty(CNFGDisplay, CNFGWindow, net_wm_icon, cardinal,
- 32, PropModeReplace, (const unsigned char*)outdata, 2 + w*h);
-}
-
-
-#ifdef HAS_XSHAPE
-void CNFGPrepareForTransparency() { prepare_xshape = 1; }
-void CNFGDrawToTransparencyMode( int transp )
-{
- static Pixmap BackupCNFGPixmap;
- static GC BackupCNFGGC;
- if( was_transp && ! transp )
- {
- CNFGGC = BackupCNFGGC;
- CNFGPixmap = BackupCNFGPixmap;
- }
- if( !was_transp && transp )
- {
- BackupCNFGPixmap = CNFGPixmap;
- BackupCNFGGC = CNFGGC;
- taint_shape = 1;
- CNFGGC = xsgc;
- CNFGPixmap = xspixmap;
- }
- was_transp = transp;
-}
-void CNFGClearTransparencyLevel()
-{
- taint_shape = 1;
- XSetForeground(CNFGDisplay, xsgc, 0);
- XFillRectangle(CNFGDisplay, xspixmap, xsgc, 0, 0, CNFGWinAtt.width, CNFGWinAtt.height);
- XSetForeground(CNFGDisplay, xsgc, 1);
-}
-#endif
-
-
-#ifdef CNFGOGL
-#include <GL/glx.h>
-#include <GL/glxext.h>
-
-GLXContext CNFGCtx;
-void * CNFGGetExtension( const char * extname ) { return glXGetProcAddressARB((const GLubyte *) extname); }
-#endif
-
-int FullScreen = 0;
-
-void CNFGGetDimensions( short * x, short * y )
-{
- static int lastx;
- static int lasty;
-
- *x = CNFGWinAtt.width;
- *y = CNFGWinAtt.height;
-
- if( lastx != *x || lasty != *y )
- {
- lastx = *x;
- lasty = *y;
- CNFGInternalResize( lastx, lasty );
- }
-}
-
-void CNFGChangeWindowTitle( const char * WindowName )
-{
- XSetStandardProperties( CNFGDisplay, CNFGWindow, WindowName, 0, 0, 0, 0, 0 );
-}
-
-
-static void InternalLinkScreenAndGo( const char * WindowName )
-{
- XFlush(CNFGDisplay);
- XGetWindowAttributes( CNFGDisplay, CNFGWindow, &CNFGWinAtt );
-
-/*
- //Not sure of purpose of this. If we find it, let me know, if this code is still commented after 2019-12-31, please remove it.
- XGetClassHint( CNFGDisplay, CNFGWindow, CNFGClassHint );
- if (!CNFGClassHint) {
- CNFGClassHint = XAllocClassHint();
- if (CNFGClassHint) {
- CNFGClassHint->res_name = "rawdraw";
- CNFGClassHint->res_class = "rawdraw";
- XSetClassHint( CNFGDisplay, CNFGWindow, CNFGClassHint );
- } else {
- fprintf( stderr, "Failed to allocate XClassHint!\n" );
- }
- } else {
- fprintf( stderr, "Pre-existing XClassHint\n" );
- }
-*/
- XSelectInput (CNFGDisplay, CNFGWindow, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | ExposureMask | PointerMotionMask );
-
-
- CNFGWindowGC = XCreateGC(CNFGDisplay, CNFGWindow, 0, 0);
-
- CNFGPixmap = XCreatePixmap( CNFGDisplay, CNFGWindow, CNFGWinAtt.width, CNFGWinAtt.height, CNFGWinAtt.depth );
- CNFGGC = XCreateGC(CNFGDisplay, CNFGPixmap, 0, 0);
- XSetLineAttributes(CNFGDisplay, CNFGGC, 1, LineSolid, CapRound, JoinRound);
- CNFGChangeWindowTitle( WindowName );
- XMapWindow(CNFGDisplay, CNFGWindow);
-
-#ifdef HAS_XSHAPE
- if( prepare_xshape )
- {
- xsval.foreground = 1;
- xsval.line_width = 1;
- xsval.line_style = LineSolid;
- xspixmap = XCreatePixmap(CNFGDisplay, CNFGWindow, CNFGWinAtt.width, CNFGWinAtt.height, 1);
- xsgc = XCreateGC(CNFGDisplay, xspixmap, 0, &xsval);
- XSetLineAttributes(CNFGDisplay, xsgc, 1, LineSolid, CapRound, JoinRound);
- }
-#endif
-}
-
-void CNFGSetupFullscreen( const char * WindowName, int screen_no )
-{
-#ifdef HAS_XINERAMA
- XineramaScreenInfo *screeninfo = NULL;
- int screens;
- int event_basep, error_basep, a, b;
- CNFGDisplay = XOpenDisplay(NULL);
- int screen = XDefaultScreen(CNFGDisplay);
- int xpos, ypos;
-
- if (!XShapeQueryExtension(CNFGDisplay, &event_basep, &error_basep)) {
- fprintf( stderr, "X-Server does not support shape extension\n" );
- exit( 1 );
- }
-
- CNFGVisual = DefaultVisual(CNFGDisplay, screen);
- CNFGWinAtt.depth = DefaultDepth(CNFGDisplay, screen);
-
-#ifdef CNFGOGL
- int attribs[] = { GLX_RGBA,
- GLX_DOUBLEBUFFER,
- GLX_RED_SIZE, 1,
- GLX_GREEN_SIZE, 1,
- GLX_BLUE_SIZE, 1,
- GLX_DEPTH_SIZE, 1,
- None };
- XVisualInfo * vis = glXChooseVisual(CNFGDisplay, screen, attribs);
- CNFGVisual = vis->visual;
- CNFGWinAtt.depth = vis->depth;
- CNFGCtx = glXCreateContext( CNFGDisplay, vis, NULL, True );
-#endif
-
- if (XineramaQueryExtension(CNFGDisplay, &a, &b ) &&
- (screeninfo = XineramaQueryScreens(CNFGDisplay, &screens)) &&
- XineramaIsActive(CNFGDisplay) && screen_no >= 0 &&
- screen_no < screens ) {
-
- CNFGWinAtt.width = screeninfo[screen_no].width;
- CNFGWinAtt.height = screeninfo[screen_no].height;
- xpos = screeninfo[screen_no].x_org;
- ypos = screeninfo[screen_no].y_org;
- } else
- {
- CNFGWinAtt.width = XDisplayWidth(CNFGDisplay, screen);
- CNFGWinAtt.height = XDisplayHeight(CNFGDisplay, screen);
- xpos = 0;
- ypos = 0;
- }
- if (screeninfo)
- XFree(screeninfo);
-
-
- XSetWindowAttributes setwinattr;
- setwinattr.override_redirect = 1;
- setwinattr.save_under = 1;
-#ifdef HAS_XSHAPE
-
- if (prepare_xshape && !XShapeQueryExtension(CNFGDisplay, &event_basep, &error_basep))
- {
- fprintf( stderr, "X-Server does not support shape extension" );
- exit( 1 );
- }
-
- setwinattr.event_mask = 0;
-#else
- //This code is probably made irrelevant by the XSetEventMask in InternalLinkScreenAndGo, if this code is not found needed by 2019-12-31, please remove.
- //setwinattr.event_mask = StructureNotifyMask | SubstructureNotifyMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | ButtonPressMask | PointerMotionMask | ButtonMotionMask | EnterWindowMask | LeaveWindowMask |KeyPressMask |KeyReleaseMask | SubstructureNotifyMask | FocusChangeMask;
-#endif
- setwinattr.border_pixel = 0;
- setwinattr.colormap = XCreateColormap( CNFGDisplay, RootWindow(CNFGDisplay, 0), CNFGVisual, AllocNone);
-
- CNFGWindow = XCreateWindow(CNFGDisplay, XRootWindow(CNFGDisplay, screen),
- xpos, ypos, CNFGWinAtt.width, CNFGWinAtt.height,
- 0, CNFGWinAtt.depth, InputOutput, CNFGVisual,
- CWBorderPixel/* | CWEventMask */ | CWOverrideRedirect | CWSaveUnder | CWColormap,
- &setwinattr);
-
- FullScreen = 1;
- InternalLinkScreenAndGo( WindowName );
-
-#ifdef CNFGOGL
- glXMakeCurrent( CNFGDisplay, CNFGWindow, CNFGCtx );
-#endif
-
-#else
- CNFGSetup( WindowName, 640, 480 );
-#endif
-}
-
-
-void CNFGTearDown()
-{
- if ( CNFGClassHint ) XFree( CNFGClassHint );
- if ( CNFGGC ) XFreeGC( CNFGDisplay, CNFGGC );
- if ( CNFGWindowGC ) XFreeGC( CNFGDisplay, CNFGWindowGC );
- if ( CNFGDisplay ) XCloseDisplay( CNFGDisplay );
- CNFGDisplay = NULL;
- CNFGWindowGC = CNFGGC = NULL;
- CNFGClassHint = NULL;
-}
-
-int CNFGSetup( const char * WindowName, int w, int h )
-{
- CNFGDisplay = XOpenDisplay(NULL);
- if ( !CNFGDisplay ) {
- fprintf( stderr, "Could not get an X Display.\n%s",
- "Are you in text mode or using SSH without X11-Forwarding?\n" );
- exit( 1 );
- }
- atexit( CNFGTearDown );
-
- int screen = DefaultScreen(CNFGDisplay);
- int depth = DefaultDepth(CNFGDisplay, screen);
- CNFGVisual = DefaultVisual(CNFGDisplay, screen);
- Window wnd = DefaultRootWindow( CNFGDisplay );
-
-#ifdef CNFGOGL
- int attribs[] = { GLX_RGBA,
- GLX_DOUBLEBUFFER,
- GLX_RED_SIZE, 1,
- GLX_GREEN_SIZE, 1,
- GLX_BLUE_SIZE, 1,
- GLX_DEPTH_SIZE, 1,
- None };
- XVisualInfo * vis = glXChooseVisual(CNFGDisplay, screen, attribs);
- CNFGVisual = vis->visual;
- depth = vis->depth;
- CNFGCtx = glXCreateContext( CNFGDisplay, vis, NULL, True );
-#endif
-
- XSetWindowAttributes attr;
- attr.background_pixel = 0;
- attr.colormap = XCreateColormap( CNFGDisplay, wnd, CNFGVisual, AllocNone);
- CNFGWindow = XCreateWindow(CNFGDisplay, wnd, 1, 1, w, h, 0, depth, InputOutput, CNFGVisual, CWBackPixel | CWColormap, &attr );
-
- InternalLinkScreenAndGo( WindowName );
-
-//Not sure of the purpose of this code - if it's still commented out after 2019-12-31 and no one knows why, please delete it.
-// Atom WM_DELETE_WINDOW = XInternAtom( CNFGDisplay, "WM_DELETE_WINDOW", False );
-// XSetWMProtocols( CNFGDisplay, CNFGWindow, &WM_DELETE_WINDOW, 1 );
-
-#ifdef CNFGOGL
- glXMakeCurrent( CNFGDisplay, CNFGWindow, CNFGCtx );
-#endif
- return 0;
-}
-
-void CNFGHandleInput()
-{
- static int ButtonsDown;
- XEvent report;
-
- int bKeyDirection = 1;
- while( XPending( CNFGDisplay ) )
- {
- XNextEvent( CNFGDisplay, &report );
-
- bKeyDirection = 1;
- switch (report.type)
- {
- case NoExpose:
- break;
- case Expose:
- XGetWindowAttributes( CNFGDisplay, CNFGWindow, &CNFGWinAtt );
- if( CNFGPixmap ) XFreePixmap( CNFGDisplay, CNFGPixmap );
- CNFGPixmap = XCreatePixmap( CNFGDisplay, CNFGWindow, CNFGWinAtt.width, CNFGWinAtt.height, CNFGWinAtt.depth );
- if( CNFGGC ) XFreeGC( CNFGDisplay, CNFGGC );
- CNFGGC = XCreateGC(CNFGDisplay, CNFGPixmap, 0, 0);
- break;
- case KeyRelease:
- bKeyDirection = 0;
- case KeyPress:
- g_x_global_key_state = report.xkey.state;
- g_x_global_shift_key = XLookupKeysym(&report.xkey, 1);
- HandleKey( XLookupKeysym(&report.xkey, 0), bKeyDirection );
- break;
- case ButtonRelease:
- bKeyDirection = 0;
- case ButtonPress:
- HandleButton( report.xbutton.x, report.xbutton.y, report.xbutton.button, bKeyDirection );
- ButtonsDown = (ButtonsDown & (~(1<<report.xbutton.button))) | ( bKeyDirection << report.xbutton.button );
-
- //Intentionall fall through -- we want to send a motion in event of a button as well.
- case MotionNotify:
- HandleMotion( report.xmotion.x, report.xmotion.y, ButtonsDown>>1 );
- break;
- case ClientMessage:
- // Only subscribed to WM_DELETE_WINDOW, so just exit
- exit( 0 );
- break;
- default:
- break;
- //printf( "Event: %d\n", report.type );
- }
- }
-}
-
-
-void CNFGUpdateScreenWithBitmap( unsigned long * data, int w, int h )
-{
- static XImage *xi;
- static int depth;
- static int lw, lh;
-
- if( !xi )
- {
- int screen = DefaultScreen(CNFGDisplay);
- depth = DefaultDepth(CNFGDisplay, screen)/8;
-// xi = XCreateImage(CNFGDisplay, DefaultVisual( CNFGDisplay, DefaultScreen(CNFGDisplay) ), depth*8, ZPixmap, 0, (char*)data, w, h, 32, w*4 );
-// lw = w;
-// lh = h;
- }
-
- if( lw != w || lh != h )
- {
- if( xi ) free( xi );
- xi = XCreateImage(CNFGDisplay, CNFGVisual, depth*8, ZPixmap, 0, (char*)data, w, h, 32, w*4 );
- lw = w;
- lh = h;
- }
-
- XPutImage(CNFGDisplay, CNFGWindow, CNFGWindowGC, xi, 0, 0, 0, 0, w, h );
-}
-
-
-#ifdef CNFGOGL
-
-void CNFGSetVSync( int vson )
-{
- void (*glfn)( int );
- glfn = (void (*)( int ))CNFGGetExtension( "glXSwapIntervalMESA" ); if( glfn ) glfn( vson );
- glfn = (void (*)( int ))CNFGGetExtension( "glXSwapIntervalSGI" ); if( glfn ) glfn( vson );
- glfn = (void (*)( int ))CNFGGetExtension( "glXSwapIntervalEXT" ); if( glfn ) glfn( vson );
-}
-
-void CNFGSwapBuffers()
-{
- glFlush();
- glFinish();
-
-#ifdef HAS_XSHAPE
- if( taint_shape )
- {
- XShapeCombineMask(CNFGDisplay, CNFGWindow, ShapeBounding, 0, 0, xspixmap, ShapeSet);
- taint_shape = 0;
- }
-#endif
- glXSwapBuffers( CNFGDisplay, CNFGWindow );
-
-#ifdef FULL_SCREEN_STEAL_FOCUS
- if( FullScreen )
- XSetInputFocus( CNFGDisplay, CNFGWindow, RevertToParent, CurrentTime );
-#endif
-}
-#endif
-
-#if !defined( CNFGOGL)
-#define AGLF(x) x
-#else
-#define AGLF(x) static BACKEND_##x
-#if defined( RASTERIZER )
-#include "CNFGRasterizer.h"
-#endif
-#endif
-
-uint32_t AGLF(CNFGColor)( uint32_t RGB )
-{
- unsigned char red = RGB & 0xFF;
- unsigned char grn = ( RGB >> 8 ) & 0xFF;
- unsigned char blu = ( RGB >> 16 ) & 0xFF;
- CNFGLastColor = RGB;
- unsigned long color = (red<<16)|(grn<<8)|(blu);
- XSetForeground(CNFGDisplay, CNFGGC, color);
- return color;
-}
-
-void AGLF(CNFGClearFrame)()
-{
- XGetWindowAttributes( CNFGDisplay, CNFGWindow, &CNFGWinAtt );
- XSetForeground(CNFGDisplay, CNFGGC, CNFGColor(CNFGBGColor) );
- XFillRectangle(CNFGDisplay, CNFGPixmap, CNFGGC, 0, 0, CNFGWinAtt.width, CNFGWinAtt.height );
-}
-
-void AGLF(CNFGSwapBuffers)()
-{
-#ifdef HAS_XSHAPE
- if( taint_shape )
- {
- XShapeCombineMask(CNFGDisplay, CNFGWindow, ShapeBounding, 0, 0, xspixmap, ShapeSet);
- taint_shape = 0;
- }
-#endif
- XCopyArea(CNFGDisplay, CNFGPixmap, CNFGWindow, CNFGWindowGC, 0,0,CNFGWinAtt.width,CNFGWinAtt.height,0,0);
- XFlush(CNFGDisplay);
-#ifdef FULL_SCREEN_STEAL_FOCUS
- if( FullScreen )
- XSetInputFocus( CNFGDisplay, CNFGWindow, RevertToParent, CurrentTime );
-#endif
-}
-
-void AGLF(CNFGTackSegment)( short x1, short y1, short x2, short y2 )
-{
- XDrawLine( CNFGDisplay, CNFGPixmap, CNFGGC, x1, y1, x2, y2 );
- XDrawPoint( CNFGDisplay, CNFGPixmap, CNFGGC, x2, y2 );
-}
-
-void AGLF(CNFGTackPixel)( short x1, short y1 )
-{
- XDrawPoint( CNFGDisplay, CNFGPixmap, CNFGGC, x1, y1 );
-}
-
-void AGLF(CNFGTackRectangle)( short x1, short y1, short x2, short y2 )
-{
- XFillRectangle(CNFGDisplay, CNFGPixmap, CNFGGC, x1, y1, x2-x1, y2-y1 );
-}
-
-void AGLF(CNFGTackPoly)( RDPoint * points, int verts )
-{
- XFillPolygon(CNFGDisplay, CNFGPixmap, CNFGGC, (XPoint *)points, 3, Convex, CoordModeOrigin );
-}
-
-void AGLF(CNFGInternalResize)( short x, short y ) { }
-
-void AGLF(CNFGSetLineWidth)( short width )
-{
- XSetLineAttributes(CNFGDisplay, CNFGGC, width, LineSolid, CapRound, JoinRound);
-}
-
-
-
-
-#if defined( CNFGOGL ) && defined( HAS_XSHAPE )
-
-#include <GL/gl.h>
-
-uint32_t CNFGColor( uint32_t RGB )
-{
- if( was_transp )
- {
- return BACKEND_CNFGColor( RGB );
- }
-
- unsigned char red = RGB & 0xFF;
- unsigned char grn = ( RGB >> 8 ) & 0xFF;
- unsigned char blu = ( RGB >> 16 ) & 0xFF;
- glColor3ub( red, grn, blu );
-}
-
-void CNFGClearFrame()
-{
- short w, h;
- unsigned char red = CNFGBGColor & 0xFF;
- unsigned char grn = ( CNFGBGColor >> 8 ) & 0xFF;
- unsigned char blu = ( CNFGBGColor >> 16 ) & 0xFF;
- glClearColor( red/255.0, grn/255.0, blu/255.0, 1.0 );
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- CNFGGetDimensions( &w, &h );
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity();
- glViewport( 0, 0, w, h );
- glOrtho( 0, w, h, 0, 1, -1 );
- glMatrixMode( GL_MODELVIEW );
- glLoadIdentity();
-}
-
-
-void CNFGTackSegment( short x1, short y1, short x2, short y2 )
-{
- if( was_transp )
- {
- BACKEND_CNFGTackSegment( x1,y1,x2,y2 );
- return;
- }
-
- if( x1 == x2 && y1 == y2 )
- {
- glBegin( GL_POINTS );
- glVertex2f( x1+.5, y1+.5 );
- glEnd();
- }
- else
- {
- glBegin( GL_POINTS );
- glVertex2f( x1+.5, y1+.5 );
- glVertex2f( x2+.5, y2+.5 );
- glEnd();
- glBegin( GL_LINES );
- glVertex2f( x1+.5, y1+.5 );
- glVertex2f( x2+.5, y2+.5 );
- glEnd();
- }
-}
-
-void CNFGTackPixel( short x1, short y1 )
-{
- if( was_transp )
- {
- BACKEND_CNFGTackPixel( x1,y1 );
- return;
- }
-
- glBegin( GL_POINTS );
- glVertex2f( x1, y1 );
- glEnd();
-}
-
-void CNFGTackRectangle( short x1, short y1, short x2, short y2 )
-{
- if( was_transp )
- {
- BACKEND_CNFGTackRectangle( x1,y1,x2,y2 );
- return;
- }
-
-
- glBegin( GL_QUADS );
- glVertex2f( x1, y1 );
- glVertex2f( x2, y1 );
- glVertex2f( x2, y2 );
- glVertex2f( x1, y2 );
- glEnd();
-}
-
-void CNFGTackPoly( RDPoint * points, int verts )
-{
- if( was_transp )
- {
- BACKEND_CNFGTackPoly( points,verts );
- return;
- }
-
- int i;
- glBegin( GL_TRIANGLE_FAN );
- glVertex2f( points[0].x, points[0].y );
- for( i = 1; i < verts; i++ )
- {
- glVertex2f( points[i].x, points[i].y );
- }
- glEnd();
-}
-
-void CNFGInternalResize( short x, short y ) { }
-
-
-void CNFGSetLineWidth( short width )
-{
- glLineWidth( width );
-}
-
-#endif
diff --git a/rawdraw/os_generic.h b/rawdraw/os_generic.h
@@ -1,490 +0,0 @@
-#ifndef _OS_GENERIC_H
-#define _OS_GENERIC_H
-/*
- "osgeneric" Generic, platform independent tool for threads and time.
- Geared around Windows and Linux. Designed for operation on MSVC,
- TCC, GCC and clang. Others may work.
-
- It offers the following operations:
-
- Delay functions:
- void OGSleep( int is );
- void OGUSleep( int ius );
-
- Getting current time (may be time from program start, boot, or epoc)
- double OGGetAbsoluteTime();
- double OGGetFileTime( const char * file );
-
- Thread functions
- og_thread_t OGCreateThread( void * (routine)( void * ), void * parameter );
- void * OGJoinThread( og_thread_t ot );
- void OGCancelThread( og_thread_t ot );
-
- Mutex functions, used for protecting data structures.
- (recursive on platforms where available.)
- og_mutex_t OGCreateMutex();
- void OGLockMutex( og_mutex_t om );
- void OGUnlockMutex( og_mutex_t om );
- void OGDeleteMutex( og_mutex_t om );
-
- Always a semaphore (not recursive)
- og_sema_t OGCreateSema(); //Create a semaphore, comes locked initially.
- NOTE: For platform compatibility, max count is 32767
- void OGLockSema( og_sema_t os );
- int OGGetSema( og_sema_t os ); //if <0 there was a failure.
- void OGUnlockSema( og_sema_t os );
- void OGDeleteSema( og_sema_t os );
-
- TLS (Thread-Local Storage)
- og_tls_t OGCreateTLS();
- void OGDeleteTLS( og_tls_t tls );
- void OGSetTLS( og_tls_t tls, void * data );
- void * OGGetTLS( og_tls_t tls );
-
- You can permute the operations of this file by the following means:
- OSG_NO_IMPLEMENTATION
- OSG_PREFIX
- OSG_NOSTATIC
-
- The default behavior is to do static inline.
-
- Copyright (c) 2011-2012,2013,2016,2018,2019 <>< Charles Lohr
-
- This file may be licensed under the MIT/x11 license, NewBSD or CC0 licenses
-
- 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 this file.
-
- 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.
-
- Date Stamp: 2019-09-05 CNL: Allow for noninstantiation and added TLS.
- Date Stamp: 2018-03-25 CNL: Switched to header-only format.
-*/
-
-
-#if defined( OSG_NOSTATIC ) && OSG_STATIC != 0
-#ifndef OSG_PREFIX
-#define OSG_PREFIX
-#endif
-#ifndef OSG_NO_IMPLEMENTATION
-#define OSG_NO_IMPLEMENTATION
-#endif
-#endif
-
-#ifndef OSG_PREFIX
-#define OSG_PREFIX static inline
-#endif
-
-//In case you want to hook the closure of a thread, i.e. if your system has thread-local storage.
-#ifndef OSG_TERM_THREAD_CODE
-#define OSG_TERM_THREAD_CODE
-#endif
-
-typedef void* og_thread_t;
-typedef void* og_mutex_t;
-typedef void* og_sema_t;
-typedef void* og_tls_t;
-
-OSG_PREFIX void OGSleep( int is );
-OSG_PREFIX void OGUSleep( int ius );
-OSG_PREFIX double OGGetAbsoluteTime();
-OSG_PREFIX double OGGetFileTime( const char * file );
-OSG_PREFIX og_thread_t OGCreateThread( void * (routine)( void * ), void * parameter );
-OSG_PREFIX void * OGJoinThread( og_thread_t ot );
-OSG_PREFIX void OGCancelThread( og_thread_t ot );
-OSG_PREFIX og_mutex_t OGCreateMutex();
-OSG_PREFIX void OGLockMutex( og_mutex_t om );
-OSG_PREFIX void OGUnlockMutex( og_mutex_t om );
-OSG_PREFIX void OGDeleteMutex( og_mutex_t om );
-OSG_PREFIX og_sema_t OGCreateSema();
-OSG_PREFIX int OGGetSema( og_sema_t os );
-OSG_PREFIX void OGLockSema( og_sema_t os );
-OSG_PREFIX void OGUnlockSema( og_sema_t os );
-OSG_PREFIX void OGDeleteSema( og_sema_t os );
-OSG_PREFIX og_tls_t OGCreateTLS();
-OSG_PREFIX void OGDeleteTLS( og_tls_t key );
-OSG_PREFIX void * OGGetTLS( og_tls_t key );
-OSG_PREFIX void OGSetTLS( og_tls_t key, void * data );
-
-#ifndef OSG_NO_IMPLEMENTATION
-
-#if defined( WIN32 ) || defined (WINDOWS) || defined( _WIN32)
-#define USE_WINDOWS
-#endif
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#ifdef USE_WINDOWS
-
-#include <windows.h>
-
-OSG_PREFIX void OGSleep( int is )
-{
- Sleep( is*1000 );
-}
-
-OSG_PREFIX void OGUSleep( int ius )
-{
- Sleep( ius/1000 );
-}
-
-OSG_PREFIX double OGGetAbsoluteTime()
-{
- static LARGE_INTEGER lpf;
- LARGE_INTEGER li;
-
- if( !lpf.QuadPart )
- {
- QueryPerformanceFrequency( &lpf );
- }
-
- QueryPerformanceCounter( &li );
- return (double)li.QuadPart / (double)lpf.QuadPart;
-}
-
-
-OSG_PREFIX double OGGetFileTime( const char * file )
-{
- FILETIME ft;
-
- HANDLE h = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
-
- if( h==INVALID_HANDLE_VALUE )
- return -1;
-
- GetFileTime( h, 0, 0, &ft );
-
- CloseHandle( h );
-
- return ft.dwHighDateTime + ft.dwLowDateTime;
-}
-
-
-OSG_PREFIX og_thread_t OGCreateThread( void * (routine)( void * ), void * parameter )
-{
- return (og_thread_t)CreateThread( 0, 0, (LPTHREAD_START_ROUTINE)routine, parameter, 0, 0 );
-}
-
-OSG_PREFIX void * OGJoinThread( og_thread_t ot )
-{
- WaitForSingleObject( ot, INFINITE );
- OSG_TERM_THREAD_CODE
- CloseHandle( ot );
- return 0;
-}
-
-OSG_PREFIX void OGCancelThread( og_thread_t ot )
-{
- OSG_TERM_THREAD_CODE
- TerminateThread( ot, 0);
- CloseHandle( ot );
-}
-
-OSG_PREFIX og_mutex_t OGCreateMutex()
-{
- return CreateMutex( 0, 0, 0 );
-}
-
-OSG_PREFIX void OGLockMutex( og_mutex_t om )
-{
- WaitForSingleObject(om, INFINITE);
-}
-
-OSG_PREFIX void OGUnlockMutex( og_mutex_t om )
-{
- ReleaseMutex(om);
-}
-
-OSG_PREFIX void OGDeleteMutex( og_mutex_t om )
-{
- CloseHandle( om );
-}
-
-
-
-OSG_PREFIX og_sema_t OGCreateSema()
-{
- HANDLE sem = CreateSemaphore( 0, 0, 32767, 0 );
- return (og_sema_t)sem;
-}
-
-OSG_PREFIX int OGGetSema( og_sema_t os )
-{
- typedef LONG NTSTATUS;
- HANDLE sem = (HANDLE)os;
- typedef NTSTATUS (NTAPI *_NtQuerySemaphore)(
- HANDLE SemaphoreHandle,
- DWORD SemaphoreInformationClass, /* Would be SEMAPHORE_INFORMATION_CLASS */
- PVOID SemaphoreInformation, /* but this is to much to dump here */
- ULONG SemaphoreInformationLength,
- PULONG ReturnLength OPTIONAL
- );
-
- typedef struct _SEMAPHORE_BASIC_INFORMATION {
- ULONG CurrentCount;
- ULONG MaximumCount;
- } SEMAPHORE_BASIC_INFORMATION;
-
-
- static _NtQuerySemaphore NtQuerySemaphore;
- SEMAPHORE_BASIC_INFORMATION BasicInfo;
- NTSTATUS Status;
-
- if( !NtQuerySemaphore )
- {
- NtQuerySemaphore = (_NtQuerySemaphore)GetProcAddress (GetModuleHandle ("ntdll.dll"), "NtQuerySemaphore");
- if( !NtQuerySemaphore )
- {
- return -1;
- }
- }
-
-
- Status = NtQuerySemaphore (sem, 0 /*SemaphoreBasicInformation*/,
- &BasicInfo, sizeof (SEMAPHORE_BASIC_INFORMATION), NULL);
-
- if (Status == ERROR_SUCCESS)
- {
- return BasicInfo.CurrentCount;
- }
-
- return -2;
-}
-
-OSG_PREFIX void OGLockSema( og_sema_t os )
-{
- WaitForSingleObject( (HANDLE)os, INFINITE );
-}
-
-OSG_PREFIX void OGUnlockSema( og_sema_t os )
-{
- ReleaseSemaphore( (HANDLE)os, 1, 0 );
-}
-
-OSG_PREFIX void OGDeleteSema( og_sema_t os )
-{
- CloseHandle( os );
-}
-
-OSG_PREFIX og_tls_t OGCreateTLS()
-{
- return (og_tls_t)TlsAlloc();
-}
-
-OSG_PREFIX void OGDeleteTLS( og_tls_t key )
-{
- TlsFree( (DWORD)key );
-}
-
-OSG_PREFIX void * OGGetTLS( og_tls_t key )
-{
- return TlsGetValue( (DWORD)key );
-}
-
-OSG_PREFIX void OGSetTLS( og_tls_t key, void * data )
-{
- TlsSetValue( (DWORD)key, data );
-}
-
-#else
-
-#define _GNU_SOURCE
-
-
-#include <sys/stat.h>
-#include <stdlib.h>
-#include <pthread.h>
-#include <sys/time.h>
-#include <semaphore.h>
-#include <unistd.h>
-
-OSG_PREFIX void OGSleep( int is )
-{
- sleep( is );
-}
-
-OSG_PREFIX void OGUSleep( int ius )
-{
- usleep( ius );
-}
-
-OSG_PREFIX double OGGetAbsoluteTime()
-{
- struct timeval tv;
- gettimeofday( &tv, 0 );
- return ((double)tv.tv_usec)/1000000. + (tv.tv_sec);
-}
-
-OSG_PREFIX double OGGetFileTime( const char * file )
-{
- struct stat buff;
-
- int r = stat( file, &buff );
-
- if( r < 0 )
- {
- return -1;
- }
-
- return buff.st_mtime;
-}
-
-
-
-OSG_PREFIX og_thread_t OGCreateThread( void * (routine)( void * ), void * parameter )
-{
- pthread_t * ret = malloc( sizeof( pthread_t ) );
- int r = pthread_create( ret, 0, routine, parameter );
- if( r )
- {
- free( ret );
- return 0;
- }
- return (og_thread_t)ret;
-}
-
-OSG_PREFIX void * OGJoinThread( og_thread_t ot )
-{
- void * retval;
- if( !ot )
- {
- return 0;
- }
- pthread_join( *(pthread_t*)ot, &retval );
- OSG_TERM_THREAD_CODE
- free( ot );
- return retval;
-}
-
-OSG_PREFIX void OGCancelThread( og_thread_t ot )
-{
- if( !ot )
- {
- return;
- }
- pthread_cancel( *(pthread_t*)ot );
- OSG_TERM_THREAD_CODE
- free( ot );
-}
-
-OSG_PREFIX og_mutex_t OGCreateMutex()
-{
- pthread_mutexattr_t mta;
- og_mutex_t r = malloc( sizeof( pthread_mutex_t ) );
-
- pthread_mutexattr_init(&mta);
- pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE);
-
- pthread_mutex_init( (pthread_mutex_t *)r, &mta );
-
- return r;
-}
-
-OSG_PREFIX void OGLockMutex( og_mutex_t om )
-{
- if( !om )
- {
- return;
- }
- pthread_mutex_lock( (pthread_mutex_t*)om );
-}
-
-OSG_PREFIX void OGUnlockMutex( og_mutex_t om )
-{
- if( !om )
- {
- return;
- }
- pthread_mutex_unlock( (pthread_mutex_t*)om );
-}
-
-OSG_PREFIX void OGDeleteMutex( og_mutex_t om )
-{
- if( !om )
- {
- return;
- }
-
- pthread_mutex_destroy( (pthread_mutex_t*)om );
- free( om );
-}
-
-
-
-
-OSG_PREFIX og_sema_t OGCreateSema()
-{
- sem_t * sem = malloc( sizeof( sem_t ) );
- sem_init( sem, 0, 0 );
- return (og_sema_t)sem;
-}
-
-OSG_PREFIX int OGGetSema( og_sema_t os )
-{
- int valp;
- sem_getvalue( os, &valp );
- return valp;
-}
-
-
-OSG_PREFIX void OGLockSema( og_sema_t os )
-{
- sem_wait( os );
-}
-
-OSG_PREFIX void OGUnlockSema( og_sema_t os )
-{
- sem_post( os );
-}
-
-OSG_PREFIX void OGDeleteSema( og_sema_t os )
-{
- sem_destroy( os );
- free(os);
-}
-
-OSG_PREFIX og_tls_t OGCreateTLS()
-{
- pthread_key_t ret = 0;
- pthread_key_create(&ret, 0);
- return (og_tls_t)(intptr_t)ret;
-}
-
-OSG_PREFIX void OGDeleteTLS( og_tls_t key )
-{
- pthread_key_delete( (pthread_key_t)(intptr_t)key );
-}
-
-OSG_PREFIX void * OGGetTLS( og_tls_t key )
-{
- return pthread_getspecific( (pthread_key_t)(intptr_t)key );
-}
-
-OSG_PREFIX void OGSetTLS( og_tls_t key, void * data )
-{
- pthread_setspecific( (pthread_key_t)(intptr_t)key, data );
-}
-
-#endif
-
-#endif
-
-#endif
-