aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcnlohr <lohr85@gmail.com>2017-03-17 01:13:42 -0400
committercnlohr <lohr85@gmail.com>2017-03-17 01:13:42 -0400
commit195053d034b2bca63db1f72be14bff9b2c7b1916 (patch)
tree19918ac03580f1284e7700672a75015c1751f468
parent2954876a8fb8c21d1947dfa6c77e47008a719b8a (diff)
downloadlibsurvive-195053d034b2bca63db1f72be14bff9b2c7b1916.tar.gz
libsurvive-195053d034b2bca63db1f72be14bff9b2c7b1916.tar.bz2
bump rawdraw to newest version.
-rw-r--r--Makefile8
-rw-r--r--calibrate.c2
-rw-r--r--calibrate_client.c2
-rw-r--r--data_recorder.c2
-rw-r--r--redist/CNFGFunctions.c (renamed from redist/DrawFunctions.c)11
-rw-r--r--redist/CNFGFunctions.h (renamed from redist/DrawFunctions.h)6
-rw-r--r--redist/CNFGNullDriver.c (renamed from redist/RawDrawNull.c)0
-rw-r--r--redist/CNFGRasterizer.h (renamed from redist/RawDrawRasterizer.c)33
-rw-r--r--redist/CNFGWinDriver.c (renamed from redist/WinDriver.c)236
-rw-r--r--redist/CNFGXDriver.c (renamed from redist/XDriver.c)16
-rwxr-xr-xtest.c2
11 files changed, 199 insertions, 119 deletions
diff --git a/Makefile b/Makefile
index 03f37d6..a642877 100644
--- a/Makefile
+++ b/Makefile
@@ -13,14 +13,14 @@ UNAME=$(shell uname)
# Mac OSX
ifeq ($(UNAME), Darwin)
-DRAWFUNCTIONS=redist/DrawFunctions.c redist/RawDrawNull.c
-GRAPHICS_LOFI:=redist/DrawFunctions.o redist/RawDrawNull.o
+DRAWFUNCTIONS=redist/CNFGFunctions.c redist/CNFGNullDriver.c
+GRAPHICS_LOFI:=redist/CNFGFunctions.o redist/CNFGNullDriver.o
# Linux / FreeBSD
else
LDFLAGS:=$(LDFLAGS) -lX11
-DRAWFUNCTIONS=redist/DrawFunctions.c redist/XDriver.c
-GRAPHICS_LOFI:=redist/DrawFunctions.o redist/XDriver.o
+DRAWFUNCTIONS=redist/CNFGFunctions.c redist/CNFGXDriver.c
+GRAPHICS_LOFI:=redist/CNFGFunctions.o redist/CNFGXDriver.o
endif
diff --git a/calibrate.c b/calibrate.c
index 9633a77..3d83baf 100644
--- a/calibrate.c
+++ b/calibrate.c
@@ -7,7 +7,7 @@
#include <string.h>
#include <os_generic.h>
#include "src/survive_cal.h"
-#include <DrawFunctions.h>
+#include <CNFGFunctions.h>
#include "src/survive_config.h"
diff --git a/calibrate_client.c b/calibrate_client.c
index f28520b..5e31cfb 100644
--- a/calibrate_client.c
+++ b/calibrate_client.c
@@ -8,7 +8,7 @@
#include <string.h>
#include <os_generic.h>
#include "src/survive_cal.h"
-#include <DrawFunctions.h>
+#include <CNFGFunctions.h>
#include "src/survive_config.h"
diff --git a/data_recorder.c b/data_recorder.c
index 5504d42..630598a 100644
--- a/data_recorder.c
+++ b/data_recorder.c
@@ -7,7 +7,7 @@
#include <survive.h>
#include <string.h>
#include <os_generic.h>
-#include <DrawFunctions.h>
+#include <CNFGFunctions.h>
struct SurviveContext * ctx;
diff --git a/redist/DrawFunctions.c b/redist/CNFGFunctions.c
index f4f27d2..947456f 100644
--- a/redist/DrawFunctions.c
+++ b/redist/CNFGFunctions.c
@@ -21,14 +21,13 @@ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
-#include "DrawFunctions.h"
+#include "CNFGFunctions.h"
#include <stdio.h>
int CNFGPenX, CNFGPenY;
uint32_t CNFGBGColor;
uint32_t CNFGLastColor;
uint32_t CNFGDialogColor; //background for boxes
-
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,
@@ -68,7 +67,7 @@ const unsigned char FontCharData[1902] = {
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, 0x31, 0xc0, 0x03, 0xa1, 0x00, 0x20, 0x20, 0x24,
+ 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,
@@ -208,11 +207,7 @@ void CNFGDrawText( const char * text, int scale )
int x2 = (int)((((*(lmap+1)) & 0x70)>>4)*scale + iox);
int y2 = (int)(((*(lmap+1)) & 0x0f)*scale + ioy);
lmap++;
- if(x1 == x2 && y1 == y2){
- CNFGTackPixel( x1, y1 );
- } else {
- CNFGTackSegment( x1, y1, x2, y2 );
- }
+ CNFGTackSegment( x1, y1, x2, y2 );
bQuit = *lmap & 0x80;
lmap++;
} while( !bQuit );
diff --git a/redist/DrawFunctions.h b/redist/CNFGFunctions.h
index 542fcf9..9ecb1bd 100644
--- a/redist/DrawFunctions.h
+++ b/redist/CNFGFunctions.h
@@ -34,7 +34,6 @@ void CNFGClearFrame();
void CNFGSwapBuffers();
void CNFGGetDimensions( short * x, short * y );
-void CNFGTearDown();
void CNFGSetup( const char * WindowName, int w, int h );
void CNFGSetupFullscreen( const char * WindowName, int screen_number );
void CNFGHandleInput();
@@ -44,6 +43,11 @@ void CNFGHandleInput();
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.
#ifdef __cplusplus
diff --git a/redist/RawDrawNull.c b/redist/CNFGNullDriver.c
index 34346cc..34346cc 100644
--- a/redist/RawDrawNull.c
+++ b/redist/CNFGNullDriver.c
diff --git a/redist/RawDrawRasterizer.c b/redist/CNFGRasterizer.h
index af40588..1b8e2dd 100644
--- a/redist/RawDrawRasterizer.c
+++ b/redist/CNFGRasterizer.h
@@ -1,6 +1,7 @@
+//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 "DrawFunctions.h"
-#include <stdio.h>
+#include "CNFGFunctions.h"
#include <stdlib.h>
#include <stdint.h>
@@ -8,6 +9,15 @@ 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;
@@ -24,11 +34,6 @@ uint32_t CNFGColor( uint32_t RGB )
return CNFGLastColor;
}
-void CNFGTackPixel( short x, short y )
-{
- buffer[bufferx*y+x] = CNFGLastColor;
-}
-
void CNFGTackSegment( short x1, short y1, short x2, short y2 )
{
short tx, ty;
@@ -53,11 +58,11 @@ void CNFGTackSegment( short x1, short y1, short x2, short y2 )
for( tx = minx; tx <= maxx; tx++ )
{
- thisy += slope;
ty = thisy;
if( tx < 0 || ty < 0 || ty >= buffery ) continue;
if( tx >= bufferx ) break;
buffer[ty * bufferx + tx] = CNFGLastColor;
+ thisy += slope;
}
}
else
@@ -71,15 +76,14 @@ void CNFGTackSegment( short x1, short y1, short x2, short y2 )
for( ty = miny; ty <= maxy; ty++ )
{
- thisx += slope;
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;
@@ -216,7 +220,6 @@ void CNFGClearFrame()
{
bufferx = x;
buffery = y;
- printf( "MALLOCING: %d\n", x * y );
buffer = malloc( x * y * 8 );
}
@@ -229,9 +232,15 @@ void CNFGClearFrame()
}
}
+void CNFGTackPixel( short x, short y )
+{
+ if( x < 0 || y < 0 || x >= bufferx || y >= buffery ) return;
+ buffer[x+bufferx*y] = CNFGLastColor;
+}
+
void CNFGSwapBuffers()
{
- CNFGUpdateScreenWithBitmap( buffer, bufferx, buffery );
+ CNFGUpdateScreenWithBitmap( (long unsigned int*)buffer, bufferx, buffery );
}
diff --git a/redist/WinDriver.c b/redist/CNFGWinDriver.c
index 3613150..a029419 100644
--- a/redist/WinDriver.c
+++ b/redist/CNFGWinDriver.c
@@ -2,80 +2,54 @@
//Portion from: http://en.wikibooks.org/wiki/Windows_Programming/Window_Creation
-#include "DrawFunctions.h"
+#include "CNFGFunctions.h"
#include <windows.h>
#include <stdlib.h>
#include <malloc.h> //for alloca
+static HBITMAP lsBitmap;
static HINSTANCE lhInstance;
static HWND lsHWND;
-static HDC lsHDC;
-static HBITMAP lsBackBitmap;
static HDC lsWindowHDC;
-static HBRUSH lsHBR;
-static HPEN lsHPEN;
-static HBRUSH lsClearBrush;
-static unsigned int lsLastWidth;
-static unsigned int lsLastHeight;
+static HDC lsHDC;
-static void InternalHandleResize()
-{
- DeleteObject( lsBackBitmap );
- lsBackBitmap = CreateCompatibleBitmap( lsHDC, lsLastWidth, lsLastHeight );
- SelectObject( lsHDC, lsBackBitmap );
-}
+#ifdef RASTERIZER
+#include "CNFGRasterizer.h"
-uint32_t CNFGColor( uint32_t RGB )
+void InternalHandleResize()
{
- CNFGLastColor = RGB;
-
- DeleteObject( lsHBR );
- lsHBR = CreateSolidBrush( RGB );
- SelectObject( lsHDC, lsHBR );
+ if( lsBitmap ) DeleteObject( lsBitmap );
- DeleteObject( lsHPEN );
- lsHPEN = CreatePen( PS_SOLID, 0, RGB );
- SelectObject( lsHDC, lsHPEN );
-
- return RGB;
+ 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
-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 )
+void CNFGGetDimensions( short * x, short * y )
{
- 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 );
+ *x = bufferx;
+ *y = buffery;
}
-void CNFGClearFrame()
-{
- RECT r = { 0, 0, lsLastWidth, lsLastHeight };
- DeleteObject( lsClearBrush );
- lsClearBrush = CreateSolidBrush( CNFGBGColor );
- SelectObject( lsHDC, lsClearBrush );
- FillRect( lsHDC, &r, lsClearBrush );
-}
-void CNFGSwapBuffers()
+void CNFGUpdateScreenWithBitmap( unsigned long * data, int w, int h )
{
- int thisw, thish;
RECT r;
- BitBlt( lsWindowHDC, 0, 0, lsLastWidth, lsLastHeight, lsHDC, 0, 0, SRCCOPY );
+
+ int a = SetBitmapBits(lsBitmap,w*h*4,data);
+ a = 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 ) )
{
@@ -85,36 +59,18 @@ void CNFGSwapBuffers()
GetClientRect( lsHWND, &r );
thisw = r.right - r.left;
thish = r.bottom - r.top;
- if( thisw != lsLastWidth || thish != lsLastHeight )
+ if( thisw != bufferx || thish != buffery )
{
- lsLastWidth = thisw;
- lsLastHeight = thish;
+ bufferx = thisw;
+ buffery = thish;
InternalHandleResize();
}
}
-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 CNFGGetDimensions( short * x, short * y )
+void CNFGTearDown()
{
- *x = lsLastWidth;
- *y = lsLastHeight;
+ PostQuitMessage(0);
}
//This was from the article
@@ -123,17 +79,13 @@ LRESULT CALLBACK MyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
switch(msg)
{
case WM_DESTROY:
+ HandleDestroy();
CNFGTearDown();
return 0;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
-void CNFGTearDown()
-{
- PostQuitMessage(0);
-}
-
//This was from the article, too... well, mostly.
void CNFGSetup( const char * name_of_window, int width, int height )
{
@@ -143,8 +95,8 @@ void CNFGSetup( const char * name_of_window, int width, int height )
int w, h, wd, hd;
HINSTANCE hInstance = GetModuleHandle(NULL);
- lsLastWidth = width;
- lsLastHeight = height;
+ bufferx = width;
+ buffery = height;
wnd.style = CS_HREDRAW | CS_VREDRAW; //we will explain this later
wnd.lpfnWndProc = MyWndProc;
@@ -167,8 +119,8 @@ void CNFGSetup( const char * name_of_window, int width, int height )
WS_OVERLAPPEDWINDOW, //basic window style
CW_USEDEFAULT,
CW_USEDEFAULT, //set starting point to default value
- lsLastWidth,
- lsLastHeight, //set all the dimensions to default value
+ bufferx,
+ buffery, //set all the dimensions to default value
NULL, //no parent window
NULL, //no menu
hInstance,
@@ -176,13 +128,14 @@ void CNFGSetup( const char * name_of_window, int width, int height )
lsWindowHDC = GetDC( lsHWND );
+
lsHDC = CreateCompatibleDC( lsWindowHDC );
- lsBackBitmap = CreateCompatibleBitmap( lsWindowHDC, lsLastWidth, lsLastHeight );
- SelectObject( lsHDC, lsBackBitmap );
+ lsBitmap = CreateCompatibleBitmap( lsWindowHDC, bufferx, buffery );
+ SelectObject( lsHDC, lsBitmap );
- lsClearBrush = CreateSolidBrush( CNFGBGColor );
- lsHBR = CreateSolidBrush( 0xFFFFFF );
- lsHPEN = CreatePen( PS_SOLID, 0, 0xFFFFFF );
+ //lsClearBrush = CreateSolidBrush( CNFGBGColor );
+ //lsHBR = CreateSolidBrush( 0xFFFFFF );
+ //lsHPEN = CreatePen( PS_SOLID, 0, 0xFFFFFF );
ShowWindow(lsHWND, 1); //display the window on the screen
@@ -193,7 +146,7 @@ void CNFGSetup( const char * name_of_window, int width, int height )
h = ( window.bottom - window.top);
wd = w - client.right;
hd = h - client.bottom;
- MoveWindow( lsHWND, window.left, window.top, lsLastWidth + wd, lsLastHeight + hd, 1 );
+ MoveWindow( lsHWND, window.left, window.top, bufferx + wd, buffery + hd, 1 );
InternalHandleResize();
}
@@ -220,7 +173,7 @@ void CNFGHandleInput()
case WM_MBUTTONUP: HandleButton( (msg.lParam & 0xFFFF), (msg.lParam>>16) & 0xFFFF, 3, 0 ); break;
case WM_KEYDOWN:
case WM_KEYUP:
- HandleKey( tolower( (int)msg.wParam ), (msg.message==WM_KEYDOWN) );
+ HandleKey( tolower( msg.wParam ), (msg.message==WM_KEYDOWN) );
break;
default:
DispatchMessage(&msg);
@@ -229,3 +182,108 @@ void CNFGHandleInput()
}
}
+
+#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
+
diff --git a/redist/XDriver.c b/redist/CNFGXDriver.c
index 507ca95..8a8904a 100644
--- a/redist/XDriver.c
+++ b/redist/CNFGXDriver.c
@@ -4,7 +4,7 @@
//#define HAS_XINERAMA
-#include "DrawFunctions.h"
+#include "CNFGFunctions.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
@@ -29,8 +29,18 @@ 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 );
+ }
}
static void InternalLinkScreenAndGo( const char * WindowName )
@@ -286,5 +296,9 @@ void CNFGTackPoly( RDPoint * points, int verts )
XFillPolygon(CNFGDisplay, CNFGPixmap, CNFGGC, (XPoint *)points, 3, Convex, CoordModeOrigin );
}
+void CNFGInternalResize( short x, short y ) { }
+
+#else
+#include "CNFGRasterizer.h"
#endif
diff --git a/test.c b/test.c
index a7da490..7679ad4 100755
--- a/test.c
+++ b/test.c
@@ -5,7 +5,7 @@
#include <survive.h>
#include <os_generic.h>
-#include <DrawFunctions.h>
+#include <CNFGFunctions.h>
struct SurviveContext * ctx;