1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-03 15:51:20 +00:00

Implements -g switch to compile with no graphical dependencies

(Can now generate stand-alone executables <1MB)
-g can be specified within code with:
$CONSOLE:ONLY
Note: Programs using this still need to call _DEST _CONSOLE or output will not be visible

Also added dependency rules to remove unrequired static system libs from being linked:
[X] lws2_32 as DEPENDENCY_SOCKETS
	_OPENHOST
	_OPENCLIENT
[X] -lwinspool as DEPENDENCY_PRINTER
	LPRINT
	_PRINTIMAGE
[X] -lwinmm & mmsystem.h
	Required by:
		FreeGlut (GUI)
		Audio Out
[X] -lksguid (From the DirectX SDK, Required for Audio)
	Required by:
		Audio Out
[X] -ldxguid (From the DirectX SDK, Required for Audio)
	Required by:
		Audio Out
[X] -lole32
	Required by:
		Audio Out (dsound.c)
[X] -lgdi32
	Required by:
		void sub__icon(int32 handle_icon, int32 handle_window_icon, int32 passed){
		int32 func__screenimage(int32 x1,int32 y1,int32 x2,int32 y2,int32 passed)
		Printer
Some code has been moved from inside libqb.cpp into subfolder internal\c\libqb

Added dummy config.h file so libsamplerate could compile in Linux (Need to establish when it was removed)
This commit is contained in:
Galleon 2015-01-06 03:55:55 -08:00
parent 9f71265de7
commit 2af8c7399c
10 changed files with 2826 additions and 3026 deletions

View file

@ -1,3 +1,19 @@
#ifndef DEPENDENCY_NO_SOCKETS
#define DEPENDENCY_SOCKETS
#endif
#ifndef DEPENDENCY_NO_PRINTER
#define DEPENDENCY_PRINTER
#endif
#ifndef DEPENDENCY_NO_ICON
#define DEPENDENCY_ICON
#endif
#ifndef DEPENDENCY_NO_SCREENIMAGE
#define DEPENDENCY_SCREENIMAGE
#endif
#ifndef INC_COMMON_CPP
#define INC_COMMON_CPP
#include "os.h"
@ -19,7 +35,11 @@
#endif
#endif
#ifdef DEPENDENCY_CONSOLE_ONLY
#undef QB64_GLUT
#else
#define QB64_GUI
#endif
#define NO_S_D_L
@ -34,6 +54,7 @@
//core
#ifdef QB64_GUI
#ifdef QB64_GLUT
#ifdef QB64_BACKSLASH_FILESYSTEM
#include "parts\\core\\src.c"
@ -41,10 +62,19 @@
#include "parts/core/src.c"
#endif
#endif
#endif
#ifdef QB64_WINDOWS
#include <winbase.h>
#ifndef QB64_GUI
#undef int64 //definition of int64 from os.h conflicts with a definition within windows.h, temporarily undefine then redefine
#include <windows.h>
#define int64 __int64
#endif
#include <float.h>
#include <winbase.h>
#endif
//common includes
@ -57,15 +87,18 @@
#include <string.h>
#include <errno.h>
//OS/compiler specific includes
#ifdef QB64_WINDOWS
#include <direct.h>
#include <winspool.h>
#ifdef DEPENDENCY_PRINTER
#include <winspool.h>
#endif
#include <csignal>
#include <process.h> //required for multi-threading
//2013 midi
#include <mmsystem.h>
#if defined DEPENDENCY_AUDIO_OUT || defined QB64_GUI
#include <mmsystem.h>
#endif
#else
#include <sys/types.h>
@ -79,7 +112,7 @@
#endif
#endif
#ifdef QB64_GUI
#ifdef QB64_GLUT
#ifndef QB64_ANDROID
#ifdef QB64_BACKSLASH_FILESYSTEM
@ -89,6 +122,7 @@
#endif
#endif
#endif
#endif
using namespace std;

File diff suppressed because it is too large Load diff

2179
internal/c/libqb/gui.cpp Normal file

File diff suppressed because it is too large Load diff

278
internal/c/libqb/gui.h Normal file
View file

@ -0,0 +1,278 @@
#ifndef QB64_GUI //begin stubs
//STUB: simulate generating a hardware surface
int32 new_hardware_img(int32 x, int32 y, uint32 *pixels, int32 flags){
//create hardware img
int32 handle;
hardware_img_struct* hardware_img;
handle=list_add(hardware_img_handles);
hardware_img=(hardware_img_struct*)list_get(hardware_img_handles,handle);
hardware_img->w=x;
hardware_img->h=y;
hardware_img->dest_context_handle=0;
hardware_img->depthbuffer_handle=0;
hardware_img->pending_commands=0;
hardware_img->remove=0;
hardware_img->alpha_disabled=0;
hardware_img->depthbuffer_mode=DEPTHBUFFER_MODE__ON;
hardware_img->valid=1;
hardware_img->source_state.PO2_fix=PO2_FIX__OFF;
hardware_img->source_state.texture_wrap=TEXTURE_WRAP_MODE__UNKNOWN;
hardware_img->source_state.smooth_stretched=SMOOTH_MODE__UNKNOWN;
hardware_img->source_state.smooth_shrunk=SMOOTH_MODE__UNKNOWN;
if (flags&NEW_HARDWARE_IMG__BUFFER_CONTENT){
hardware_img->texture_handle=0;
if (flags&NEW_HARDWARE_IMG__DUPLICATE_PROVIDED_BUFFER){
hardware_img->software_pixel_buffer=NULL;
}else{
free(pixels);//the buffer was meant to be consumed, so we just free it immediately
hardware_img->software_pixel_buffer=NULL;
}
}
return handle;
}
#else //end stubs
int32 force_NPO2_fix=0;//This should only be set to 1 for debugging QB64
uint32 *NPO2_buffer=(uint32*)malloc(4);
int32 NPO2_buffer_size_in_pixels=1;
uint32 *NPO2_texture_generate(int32 *px, int32 *py, uint32 *pixels){
int32 ox=*px;
int32 oy=*py;
int32 nx=1;
int32 ny=1;
//assume not negative & not 0
while ((ox&1)==0){
ox>>=1;
nx<<=1;
}
if (ox!=1){//x is not a power of 2
while (ox!=0){
ox>>=1;
nx<<=1;
}
nx<<1;
}
while ((oy&1)==0){
oy>>=1;
ny<<=1;
}
if (oy!=1){//y is not a power of 2
while (oy!=0){
oy>>=1;
ny<<=1;
}
ny<<1;
}
//reset original values
ox=*px;
oy=*py;
if (nx==ox&&ny==oy){ //no action required
return pixels;
}
int32 size_in_pixels=nx*ny;
if (size_in_pixels>NPO2_buffer_size_in_pixels){
NPO2_buffer=(uint32*)realloc(NPO2_buffer,size_in_pixels*4);
NPO2_buffer_size_in_pixels=size_in_pixels;
}
//copy source NPO2 rectangle into destination PO2 rectangle
if (nx==ox){ //can copy as a single block
memcpy(NPO2_buffer,pixels,ox*oy*4);
}else{
uint32 *dst_pixel_offset=NPO2_buffer;
uint32 *src_pixel_offset=pixels;
while (oy--){
memcpy(dst_pixel_offset,src_pixel_offset,ox*4);
dst_pixel_offset+=nx;
src_pixel_offset+=ox;
}
oy=*py;
}
//tidy edges - extend the right-most column and bottom-most row to avoid pixel/color bleeding
//rhs column
if (ox!=nx){
for (int y=0;y<oy;y++){
NPO2_buffer[ox+nx*y]=NPO2_buffer[ox+nx*y-1];
}
}
//bottom row + 1 pixel for corner
if (oy!=ny){
for (int x=0;x<(ox+1);x++){
NPO2_buffer[nx*oy+x]=NPO2_buffer[nx*oy+x-nx];
}
}
//int maxtexsize;
//glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxtexsize);
//alert(maxtexsize);
//alert(nx);
//alert(ny);
*px=nx;
*py=ny;
return NPO2_buffer;
}
int32 new_texture_handle(){
GLuint texture=0;
glGenTextures(1,&texture);
return (int32)texture;
}
int32 new_hardware_img(int32 x, int32 y, uint32 *pixels, int32 flags){
//note: non power-of-2 dimensioned textures are supported on modern 3D cards and
// even on some older cards, as long as mip-mapping is not being used
// therefore, no attempt is made to convert the non-power-of-2 SCREEN sizes via software
// to avoid the performance hit this would incur
//create hardware img
int32 handle;
hardware_img_struct* hardware_img;
handle=list_add(hardware_img_handles);
hardware_img=(hardware_img_struct*)list_get(hardware_img_handles,handle);
hardware_img->w=x;
hardware_img->h=y;
hardware_img->dest_context_handle=0;
hardware_img->depthbuffer_handle=0;
hardware_img->pending_commands=0;
hardware_img->remove=0;
hardware_img->alpha_disabled=0;
hardware_img->depthbuffer_mode=DEPTHBUFFER_MODE__ON;
hardware_img->valid=1;
hardware_img->source_state.PO2_fix=PO2_FIX__OFF;
hardware_img->source_state.texture_wrap=TEXTURE_WRAP_MODE__UNKNOWN;
hardware_img->source_state.smooth_stretched=SMOOTH_MODE__UNKNOWN;
hardware_img->source_state.smooth_shrunk=SMOOTH_MODE__UNKNOWN;
if (flags&NEW_HARDWARE_IMG__BUFFER_CONTENT){
hardware_img->texture_handle=0;
if (flags&NEW_HARDWARE_IMG__DUPLICATE_PROVIDED_BUFFER){
hardware_img->software_pixel_buffer=(uint32*)malloc(x*y*4);
memcpy(hardware_img->software_pixel_buffer,pixels,x*y*4);
}else{
hardware_img->software_pixel_buffer=pixels;
}
}else{
hardware_img->software_pixel_buffer=NULL;
hardware_img->texture_handle=new_texture_handle();
glBindTexture (GL_TEXTURE_2D, hardware_img->texture_handle);
//non-power of 2 dimensions fallback support
static int glerrorcode;
glerrorcode=glGetError();//clear any previous errors
if (force_NPO2_fix==0) glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixels);
glerrorcode=glGetError();
if (glerrorcode!=0||force_NPO2_fix==1){
int32 nx=x,ny=y;
uint32 *npixels=NPO2_texture_generate(&nx,&ny,pixels);
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, nx, ny, 0, GL_BGRA, GL_UNSIGNED_BYTE,npixels);
hardware_img->source_state.PO2_fix=PO2_FIX__EXPANDED;
hardware_img->PO2_w=nx;
hardware_img->PO2_h=ny;
glerrorcode=glGetError();
if (glerrorcode){
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, x, y, GL_BGRA, GL_UNSIGNED_BYTE, pixels );
glerrorcode=glGetError();
if (glerrorcode){
alert("gluBuild2DMipmaps failed");
alert(glerrorcode);
}
hardware_img->source_state.PO2_fix=PO2_FIX__MIPMAPPED;
hardware_img->PO2_w=x;
hardware_img->PO2_h=y;
}
}
set_render_source(INVALID_HARDWARE_HANDLE);
}
return handle;
}
void hardware_img_buffer_to_texture(int32 handle){
static hardware_img_struct* hardware_img;
hardware_img=(hardware_img_struct*)list_get(hardware_img_handles,handle);
if (hardware_img->texture_handle==0){
hardware_img->texture_handle=new_texture_handle();
glBindTexture (GL_TEXTURE_2D, hardware_img->texture_handle);
//non-power of 2 dimensions fallback support
static int glerrorcode;
glerrorcode=glGetError();//clear any previous errors
if (force_NPO2_fix==0) glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, hardware_img->w, hardware_img->h, 0, GL_BGRA, GL_UNSIGNED_BYTE, hardware_img->software_pixel_buffer);
glerrorcode=glGetError();
if (glerrorcode!=0||force_NPO2_fix==1){
hardware_img->source_state.PO2_fix=PO2_FIX__EXPANDED;
int32 x=hardware_img->w;
int32 y=hardware_img->h;
uint32 *pixels=NPO2_texture_generate(&x,&y,hardware_img->software_pixel_buffer);
hardware_img->PO2_w=x;
hardware_img->PO2_h=y;
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_BGRA, GL_UNSIGNED_BYTE,pixels);
glerrorcode=glGetError();
if (glerrorcode){
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, hardware_img->w, hardware_img->h, GL_BGRA, GL_UNSIGNED_BYTE, hardware_img->software_pixel_buffer);
glerrorcode=glGetError();
if (glerrorcode){
alert("gluBuild2DMipmaps failed");
alert(glerrorcode);
}
hardware_img->source_state.PO2_fix=PO2_FIX__MIPMAPPED;
hardware_img->PO2_w=hardware_img->w;
hardware_img->PO2_h=hardware_img->h;
}
}
free(hardware_img->software_pixel_buffer);
set_render_source(INVALID_HARDWARE_HANDLE);
}
}
void hardware_img_requires_depthbuffer(hardware_img_struct* hardware_img){
if (hardware_img->depthbuffer_handle==0){
//inspiration... http://www.opengl.org/wiki/Framebuffer_Object_Examples#Color_texture.2C_Depth_texture
static GLuint depth_tex;
glGenTextures(1, &depth_tex);
glBindTexture(GL_TEXTURE_2D, depth_tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
//NULL means reserve texture memory, but texels are undefined
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, hardware_img->w, hardware_img->h, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depth_tex, 0/*mipmap level*/);
glClear(GL_DEPTH_BUFFER_BIT);
hardware_img->depthbuffer_handle=depth_tex;
set_render_source(INVALID_HARDWARE_HANDLE);
}
}
#endif

View file

@ -0,0 +1,80 @@
#ifndef DEPENDENCY_PRINTER
//stubs
void sub__printimage(int32 i){
return;
}
#else
void sub__printimage(int32 i){
#ifdef QB64_WINDOWS
static LPSTR szPrinterName=NULL;
DWORD dwNameLen;
HDC dc;
DOCINFO di;
uint32 w,h;
int32 x,y;
int32 i2;
BITMAPFILEHEADER bmfHeader;
BITMAPINFOHEADER bi;
img_struct *s,*s2;
if (i>=0){
validatepage(i); s=&img[page[i]];
}else{
x=-i;
if (x>=nextimg){error(258); return;}
s=&img[x];
if (!s->valid){error(258); return;}
}
if (!szPrinterName) szPrinterName=(LPSTR)malloc(65536);
dwNameLen=65536;
GetDefaultPrinter(szPrinterName,&dwNameLen);
if((dc=CreateDC(TEXT("WINSPOOL"),szPrinterName,NULL,NULL))==NULL) goto failed;
ZeroMemory(&di,sizeof(DOCINFO));
di.cbSize=sizeof(DOCINFO);
di.lpszDocName=TEXT("Document");
if(StartDoc(dc,&di)<=0){DeleteDC(dc); goto failed;}
if(StartPage(dc)<=0){EndDoc(dc); DeleteDC(dc); goto failed;}
w=GetDeviceCaps(dc,HORZRES);
h=GetDeviceCaps(dc,VERTRES);
i2=func__newimage(w,h,32,1);
if (i2==-1){EndDoc(dc); DeleteDC(dc); goto failed;}
s2=&img[-i2];
sub__dontblend(i2,1);
sub__putimage(NULL,NULL,NULL,NULL,i,i2,NULL,NULL,NULL,NULL,8+32);
ZeroMemory(&bi,sizeof(BITMAPINFOHEADER));
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = w;
bi.biHeight = h;
bi.biPlanes = 1;
bi.biBitCount = 32;
bi.biCompression = BI_RGB;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
for (y=0;y<h;y++){
SetDIBitsToDevice(dc,0,y,w,1,0,0,0,1,s2->offset32+(y*w),(BITMAPINFO*)&bi, DIB_RGB_COLORS);
}
sub__freeimage(i2,1);
if(EndPage(dc)<=0){EndDoc(dc); DeleteDC(dc); goto failed;}
if(EndDoc(dc)<=0){DeleteDC(dc); goto failed;}
DeleteDC(dc);
failed:;
#endif
}
#endif

View file

@ -0,0 +1,2 @@
//forward references
void sub__printimage(int32 i);

View file

@ -0,0 +1,7 @@
/* Run configure to generate config.h automatically on any
system supported by GNU autoconf. For all other systems,
use this file as a template to create config.h
*/
#undef HAVE_INTTYPES_H

View file

@ -43,6 +43,7 @@ if (midiCaps.dwSupport & MIDICAPS_VOLUME)
extern void error(int32 error_number);
extern int32 sub_gl_called;
#ifdef QB64_GUI
#ifdef DEPENDENCY_GL
#ifdef QB64_BACKSLASH_FILESYSTEM
@ -68,6 +69,7 @@ extern int32 sub_gl_called;
}
#endif
#endif
/*
#ifdef QB64_BACKSLASH_FILESYSTEM
@ -2152,464 +2154,6 @@ uint8 *redim_preserve_cmem_buffer=(uint8*)malloc(65536);//used for temporary sto
#include "myip.cpp"
void sub_lprint(qbs* str,int32 finish_on_new_line){
#ifdef QB64_WINDOWS
//proposed #1:
//_PRINTIMAGE [i]
//ideas: _ASPECT (maintains aspect ratio)
// (?,?)-(?,?) where ? is a value from 0-1 of the respective paper dimension
//_PRINTIMAGE i, _SQUAREPIXELS mypic,(0,0)-(0.5,0.5)
//_PRINTIMAGE [XXXbut what is dimension?)(0,0)[-(1,1)]],i i, _SQUAREPIXELS mypic,(0,0)-(0.5,0.5)
//_PRINTIMAGE _SQUAREPIXELS i,(0,0)-(0.5,0.5)
//idea: where squarepixels is used the image is printed maintaining aspect ratio within
// target area
/*
CDC memDC;
CClientDC dc(this);
int bmpWidth = 1600;
int bmpHeight = 500;
memDC.CreateCompatibleDC( &dc );
CBitmap bitmap;
HBITMAP hbmp=(HBITMAP)LoadImage(NULL,"d:\\italy\\florence.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
bitmap.Attach(hbmp);
BITMAP bm;
bitmap.GetObject(sizeof(BITMAP),&bm);
CBitmap * pOldBitmap = (CBitmap *) memDC.SelectObject(& bitmap );
if (pOldBitmap == NULL) // if bitmap is very big, better check this !
{
memDC.DeleteDC();
AfxMessageBox("Not enough resource for the bitmap. Either reduce the bitmap dimension or switch to lower screen setting (e.g. 256-color mode), and try again.");
return;
}
dc.BitBlt(0,0, bm.bmWidth , bm.bmHeight,&memDC,0,0,SRCCOPY);
CDC prtDC;
CPrintInfo printInfo;
CSize size;
DOCINFO di;
CString szPortName, szAppName, szPrintError;
szAppName.LoadString(AFX_IDS_APP_TITLE);
szPrintError = "";
CSize paper_size; //printer paper size in mm
int xLogPPI = 0;
int yLogPPI = 0;
if( AfxGetApp()->GetPrinterDeviceDefaults(&printInfo.m_pPD->m_pd) )
{
HDC hDC = printInfo.m_pPD->m_pd.hDC;
if (hDC == NULL)
hDC = printInfo.m_pPD->CreatePrinterDC();
if(hDC !=NULL)
{
prtDC.Attach(hDC);
paper_size.cx = prtDC.GetDeviceCaps(HORZSIZE);
paper_size.cy = prtDC.GetDeviceCaps(VERTSIZE);
xLogPPI = prtDC.GetDeviceCaps(LOGPIXELSX);
yLogPPI = prtDC.GetDeviceCaps(LOGPIXELSY);
}
else
{
AfxMessageBox("Can not find printer. Please check installed/default printers.");
return;
}
}
int scr_xLogPPI = dc.GetDeviceCaps(LOGPIXELSX);
int scr_yLogPPI = dc.GetDeviceCaps(LOGPIXELSY);
int paper_width = (int) ((double) paper_size.cx * (double) xLogPPI / 25.4); //width of a printed page in pixels
int paper_height = (int) ((double) paper_size.cy * (double) yLogPPI / 25.4);
double ratio_x = (double) xLogPPI / (double) scr_xLogPPI;
double ratio_y = (double) yLogPPI / (double) scr_yLogPPI;
CString strPageNumber = "";
int page_info_left = (int) ( (double) paper_width * 0.9 );
int page_info_right = paper_width;
int page_info_top = (int) ( (double) paper_height * 0.99);
int page_info_bottom = paper_height;
CRect page_info_rect = CRect(page_info_left, page_info_top,
page_info_right,page_info_bottom );
int printed_pages = 0;
int total_print_pages = 0;
BOOL bAbort_print = FALSE;
// calculate pages
int total_pages = (bmpWidth * ratio_x + paper_width - 1 ) / paper_width;
//pop up printer dialog
CPrintDialog prtDlg(FALSE, PD_PAGENUMS);
prtDlg.m_pd.nMinPage = 1;
prtDlg.m_pd.nMaxPage = total_pages;
prtDlg.m_pd.nFromPage = 1;
prtDlg.m_pd.nToPage = total_pages;
if(prtDlg.DoModal() == IDOK )
{
memset(&di, 0, sizeof(DOCINFO));
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = szAppName;
szPortName = prtDlg.GetPortName();
di.lpszOutput = szPortName;
prtDC.m_bPrinting = TRUE;
}
else
return; //Cancel button pressed, don't forget this!
if(prtDC.StartDoc(&di) == -1)
{
AfxMessageBox("Printing error occured. Unable to find printer.");
prtDC.Detach();
prtDC.DeleteDC();
return;
}
prtDC.SetMapMode(MM_TEXT);
int i = 0;
for(i = 0; i < total_pages; i++)
{
prtDC.StartPage();
strPageNumber.Format("Page:%d of %d", ++printed_pages, total_print_pages );
if ( i == (total_pages - 1) && total_pages > 1 ) //last page
{
int last_bmpWidth = bmpWidth - paper_width / ratio_x * i;
prtDC.StretchBlt(0, 0, last_bmpWidth * ratio_x, bmpHeight* ratio_y, &memDC,
paper_width * i / ratio_x, 0, last_bmpWidth, bmpHeight, SRCCOPY);
}
else
prtDC.StretchBlt(0, 0, paper_width, bmpHeight* ratio_y, &memDC,
paper_width * i / ratio_x, 0, paper_width / ratio_x , bmpHeight, SRCCOPY);
prtDC.TextOut(page_info_rect.left, page_info_rect.top, strPageNumber );
prtDC.EndPage();
}
memDC.SelectObject(pOldBitmap);
memDC.DeleteDC();
prtDC.EndDoc();
prtDC.Detach();
prtDC.DeleteDC();
*/
//assumes 80x60 characters per page
/*
static HWND hwnd;
hwnd=GetDesktopWindow();
static RECT rect;
GetWindowRect(hwnd,&rect);
static int32 x,y;
x=rect.right-rect.left;
y=rect.bottom-rect.top;
static HDC hdc;
hdc=GetDC(hwnd);
static HDC hdc2;
hdc2=CreateCompatibleDC(hdc);
static HBITMAP bitmap;
bitmap=CreateCompatibleBitmap(hdc,x,y);
SelectObject(hdc2,bitmap);
BitBlt( hdc2,
0,0,
x,y,
hdc,
0,0,
SRCCOPY);
static BITMAPFILEHEADER bmfHeader;
static BITMAPINFOHEADER bi;
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = x;
bi.biHeight = y;
bi.biPlanes = 1;
bi.biBitCount = 32;
bi.biCompression = BI_RGB;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
static int32 i,i2,i3;
i2=func__dest();
i=func__newimage(x,y,32,1);
sub__dest(i);
GetDIBits(hdc2,bitmap,0,y,write_page->offset,(BITMAPINFO*)&bi, DIB_RGB_COLORS);
sub__setalpha(255,NULL,NULL,NULL,0);
i3=func__newimage(x,y,32,1);
sub__dontblend(i,1);
sub__dontblend(i3,1);
sub__putimage(NULL,0,y-1,NULL,x-1,0,i,i3,NULL,NULL,NULL,NULL,NULL,NULL,15);
sub__freeimage(i,1);
sub__blend(i3,1);
sub__dest(i2);
DeleteObject(bitmap);
DeleteDC(hdc2);
ReleaseDC(NULL,hdc);
*/
TCHAR szString[81] = TEXT("01234567890123456789012345678901234567890123456789012345678901234567890123456789");
static LPSTR szPrinterName=NULL;
static DWORD dwNameLen;
static HDC dc;
static DOCINFO di;
static HFONT hFont, hOldFont;
static double logPixelsY;
static TEXTMETRIC tm;
static uint32 w,h;
int32 x;
int32 y;
if (!szPrinterName) szPrinterName=(LPSTR)malloc(65536);
dwNameLen=65536;
GetDefaultPrinter(szPrinterName,&dwNameLen);
if((dc=CreateDC(TEXT("WINSPOOL"),szPrinterName,NULL,NULL))==NULL) goto failed;
ZeroMemory(&di,sizeof(DOCINFO));
di.cbSize=sizeof(DOCINFO);
di.lpszDocName=TEXT("MyPic");
if(StartDoc(dc,&di)<=0){DeleteDC(dc); goto failed;}
if(StartPage(dc)<=0){EndDoc(dc); DeleteDC(dc); goto failed;}
/*
int32 paper_size_cx,paper_size_cy;
int32 xLogPPI,yLogPPI;
paper_size_cx = GetDeviceCaps(dc,HORZSIZE);
paper_size_cy = GetDeviceCaps(dc,VERTSIZE);
xLogPPI = GetDeviceCaps(dc,LOGPIXELSX);
yLogPPI = GetDeviceCaps(dc,LOGPIXELSY);
int32 paper_width,paper_height;
w= paper_width = (int) ((double) paper_size_cx * (double) xLogPPI / 25.4); //width of a printed page in pixels
h= paper_height = (int) ((double) paper_size_cy * (double) yLogPPI / 25.4);
*/
//http://support.microsoft.com/kb/122037
// Init our pt struct in case escape not supported
int32 pt_x,pt_y;
pt_x=0; pt_y=0;
// Locate the upper left corner of the printable area
/*
// Figure out how much you need to offset output to produce the left
// and top margins for the output in the printer. Note the
// use of the "max" macro. It is possible that you are asking for
// margins that are not possible on this printer. For example, the HP
// LaserJet has a 0.25" unprintable area so we cannot get margins of
// 0.1".
int32 xOffset,yOffset;
xOffset = max (0, GetDeviceCaps (hPrnDC, LOGPIXELSX) *
nInchesWeWant - pt_x);
yOffset = max (0, GetDeviceCaps (hPrnDC, LOGPIXELSY) *
nInchesWeWant - pt_y);
// When doing all the output, you can either offset it by the above
// values or call SetViewportOrg() to set the point (0,0) at
// the margin offset you calculated.
SetViewportOrg (hPrnDC, xOffset, yOffset);
all other output here
*/
w=GetDeviceCaps(dc,HORZRES);
h=GetDeviceCaps(dc,VERTRES);
double margin_x,margin_y;
margin_x = GetDeviceCaps(dc, PHYSICALOFFSETX);//margins are in device units
margin_y = GetDeviceCaps(dc, PHYSICALOFFSETY);
double size_x,size_y;
size_x = GetDeviceCaps(dc,PHYSICALWIDTH);//in device units
size_y = GetDeviceCaps(dc,PHYSICALHEIGHT);
//note: the HDC represents an area from (not including) the top/left margin to the last point on the paper page
// so w&h are rescaled based on the ratio between the full size without the margin and full size (all in device units)
w=((double)w)*((size_x-margin_x)/size_x);
h=((double)h)*((size_y-margin_y)/size_y);
w--; h--;//ensure bottom/right pixel is within printable area
int32 i;
i=func__newimage(w,h,32,1);
static BITMAPFILEHEADER bmfHeader;
static BITMAPINFOHEADER bi;
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = w;
bi.biHeight = h;
bi.biPlanes = 1;
bi.biBitCount = 32;
bi.biCompression = BI_RGB;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
//GetDIBits(hdc2,bitmap,0,y,write_page->offset,(BITMAPINFO*)&bi, DIB_RGB_COLORS);
uint32 *d;
d=(uint32*)malloc(w*h*4);
int32 xx;
xx=0;
for (y=0;y<h;y++){
for (x=0;x<w;x++){
//d[x]=0xFFFF0000;//this prints in RED (alpha component appears to be ignored)
d[xx]=0x00FFFFFF;
if (xx<1000000) d[xx]=0x00FF0000+(y&255);
xx++;
//if ((x&3)==3) d[x]=255;
}
}
//SetDIBitsToDevice(dc,0,0,w,h,0,0,0,h,d,(BITMAPINFO*)&bi, DIB_RGB_COLORS);
for (y=0;y<h;y++){
SetDIBitsToDevice(dc,0,y,w,1,0,0,0,1,d+(y*w),(BITMAPINFO*)&bi, DIB_RGB_COLORS);
}
/*
int SetDIBitsToDevice(
HDC hdc, // handle to device context
int XDest, // x-coordinate of upper-left corner of
// dest. rect.
int YDest, // y-coordinate of upper-left corner of
// dest. rect.
DWORD dwWidth, // source rectangle width
DWORD dwHeight, // source rectangle height
int XSrc, // x-coordinate of lower-left corner of
// source rect.
int YSrc, // y-coordinate of lower-left corner of
// source rect.
UINT uStartScan, // first scan line in array
UINT cScanLines, // number of scan lines
CONST VOID *lpvBits, // address of array with DIB bits
CONST BITMAPINFO *lpbmi, // address of structure with bitmap info.
UINT fuColorUse // RGB or palette indexes
);
*/
//#define HORZRES 8 /* Horizontal width in pixels */
//#define VERTRES 10 /* Vertical height in pixels */
/*
exit(h);
for (y=0;y<h;y++){
for (x=0;x<w;x++){
SetPixel(dc, x, y, RGB(255, 255, 255));
}}
*/
for (y=0;y<h;y++){
SetPixel(dc, 0, y, RGB(0, 255, 255));
SetPixel(dc, w-1, y, RGB(255, 0, 255));
}
for (x=0;x<w;x++){
SetPixel(dc, x, 0, RGB(255, 0, 0));
SetPixel(dc, x, h-1, RGB(0, 0, 255));
}
TextOut( dc, 0, 0, szString, lstrlen( szString ) );
//COLORREF
/*
logPixelsY = GetDeviceCaps(hDC, LOGPIXELSY);//Logical pixels/inch in Y
hFont = CreateFont(-((logPixelsY/72.0)*12.0),0,0,0,0,0,0,0,0,0,0,0,FIXED_PITCH,"courier");
hOldFont =(HFONT)SelectObject(hDC,hFont);
GetTextMetrics(hDC, &tm);
*/
//...
/*
TextOut( hDC, 0, 0, szString, lstrlen( szString ) );
TextOut( hDC, 0, tm.tmHeight*1, szString, lstrlen( szString ) );
TextOut( hDC, 0, tm.tmHeight*2, szString, lstrlen( szString ) );
TextOut( hDC, 0, tm.tmHeight*3, szString, lstrlen( szString ) );
TextOut( hDC, 0, tm.tmHeight*9, szString, lstrlen( szString ) );
TextOut( hDC, 0, tm.tmHeight*19, szString, lstrlen( szString ) );
TextOut( hDC, 0, tm.tmHeight*29, szString, lstrlen( szString ) );
TextOut( hDC, 0, tm.tmHeight*39, szString, lstrlen( szString ) );
TextOut( hDC, 0, tm.tmHeight*49, szString, lstrlen( szString ) );
TextOut( hDC, 0, tm.tmHeight*59, szString, lstrlen( szString ) );
TextOut( hDC, 0, tm.tmHeight*63, szString, lstrlen( szString ) );
*/
/*
//...
//SelectObject(hDC, hOldFont); DeleteObject(hFont);
*/
if(EndPage(dc)<=0){EndDoc(dc); DeleteDC(dc); goto failed;}
if(EndDoc(dc)<=0){DeleteDC(dc); goto failed;}
DeleteDC(dc);
failed:;
#endif
}
void division_by_zero_handler(int ignore){
error(11);
}

View file

@ -60,6 +60,11 @@ CONST DEPENDENCY_AUDIO_OUT = 4: DEPENDENCY_LAST = DEPENDENCY_LAST + 1
CONST DEPENDENCY_GL = 5: DEPENDENCY_LAST = DEPENDENCY_LAST + 1
CONST DEPENDENCY_IMAGE_CODEC = 6: DEPENDENCY_LAST = DEPENDENCY_LAST + 1
CONST DEPENDENCY_USER_MODS = 7: DEPENDENCY_LAST = DEPENDENCY_LAST + 1
CONST DEPENDENCY_CONSOLE_ONLY = 8: DEPENDENCY_LAST = DEPENDENCY_LAST + 1 '=2 if via -g switch, =1 if via metacommand $CONSOLE:ONLY
CONST DEPENDENCY_SOCKETS = 9: DEPENDENCY_LAST = DEPENDENCY_LAST + 1
CONST DEPENDENCY_PRINTER = 10: DEPENDENCY_LAST = DEPENDENCY_LAST + 1
CONST DEPENDENCY_ICON = 11: DEPENDENCY_LAST = DEPENDENCY_LAST + 1
CONST DEPENDENCY_SCREENIMAGE = 12: DEPENDENCY_LAST = DEPENDENCY_LAST + 1
DIM SHARED DEPENDENCY(1 TO DEPENDENCY_LAST)
@ -1212,9 +1217,9 @@ file$ = f$
fullrecompile:
FOR i = 1 TO UBOUND(DEPENDENCY): DEPENDENCY(i) = 0: NEXT
BU_DEPENDENCY_CONSOLE_ONLY = DEPENDENCY(DEPENDENCY_CONSOLE_ONLY)
FOR i = 1 TO UBOUND(Dependency): DEPENDENCY(i) = 0: NEXT
DEPENDENCY(DEPENDENCY_CONSOLE_ONLY) = BU_DEPENDENCY_CONSOLE_ONLY AND 2 'Restore -g switch if used
Error_Happened = 0
@ -2689,6 +2694,13 @@ DO
GOTO finishednonexec
END IF
IF a3u$ = "$CONSOLE:ONLY" THEN
layout$ = "$CONSOLE:ONLY"
DEPENDENCY(DEPENDENCY_CONSOLE_ONLY) = DEPENDENCY(DEPENDENCY_CONSOLE_ONLY) OR 1
Console = 1
GOTO finishednonexec
END IF
IF a3u$ = "$SCREENHIDE" THEN
layout$ = "$SCREENHIDE"
ScreenHide = 1
@ -10761,6 +10773,35 @@ IF DEPENDENCY(DEPENDENCY_IMAGE_CODEC) THEN
defines$ = defines$ + defines_header$ + "DEPENDENCY_IMAGE_CODEC"
END IF
IF DEPENDENCY(DEPENDENCY_CONSOLE_ONLY) THEN
defines$ = defines$ + defines_header$ + "DEPENDENCY_CONSOLE_ONLY"
END IF
IF DEPENDENCY(DEPENDENCY_SOCKETS) THEN
defines$ = defines$ + defines_header$ + "DEPENDENCY_SOCKETS"
ELSE
defines$ = defines$ + defines_header$ + "DEPENDENCY_NO_SOCKETS"
END IF
IF DEPENDENCY(DEPENDENCY_PRINTER) THEN
defines$ = defines$ + defines_header$ + "DEPENDENCY_PRINTER"
ELSE
defines$ = defines$ + defines_header$ + "DEPENDENCY_NO_PRINTER"
END IF
IF DEPENDENCY(DEPENDENCY_ICON) THEN
defines$ = defines$ + defines_header$ + "DEPENDENCY_ICON"
ELSE
defines$ = defines$ + defines_header$ + "DEPENDENCY_NO_ICON"
END IF
IF DEPENDENCY(DEPENDENCY_SCREENIMAGE) THEN
defines$ = defines$ + defines_header$ + "DEPENDENCY_SCREENIMAGE"
ELSE
defines$ = defines$ + defines_header$ + "DEPENDENCY_NO_SCREENIMAGE"
END IF
IF DEPENDENCY(DEPENDENCY_LOADFONT) THEN
d$ = "internal\c\parts\video\font\ttf\"
'rebuild?
@ -11066,6 +11107,50 @@ IF os$ = "WIN" THEN
x = INSTR(a$, " -s"): a$ = LEFT$(a$, x - 1) + " -mconsole" + RIGHT$(a$, LEN(a$) - x + 1)
END IF
IF DEPENDENCY(DEPENDENCY_CONSOLE_ONLY) THEN
a$ = StrRemove(a$, "-mwindows")
a$ = StrRemove(a$, "-lopengl32")
a$ = StrRemove(a$, "-lglu32")
a$ = StrRemove(a$, "parts\core\os\win\src.a")
a$ = StrRemove(a$, "-D FREEGLUT_STATIC")
a$ = StrRemove(a$, "-D GLEW_STATIC")
END IF
a$ = StrRemove(a$, "-lws2_32")
IF DEPENDENCY(DEPENDENCY_SOCKETS) THEN
x = INSTR(a$, " -o"): a$ = LEFT$(a$, x - 1) + " -lws2_32" + RIGHT$(a$, LEN(a$) - x + 1)
END IF
a$ = StrRemove(a$, "-lwinspool")
IF DEPENDENCY(DEPENDENCY_PRINTER) THEN
x = INSTR(a$, " -o"): a$ = LEFT$(a$, x - 1) + " -lwinspool" + RIGHT$(a$, LEN(a$) - x + 1)
END IF
a$ = StrRemove(a$, "-lwinmm")
IF DEPENDENCY(DEPENDENCY_AUDIO_OUT) <> 0 OR DEPENDENCY(DEPENDENCY_CONSOLE_ONLY) = 0 THEN
x = INSTR(a$, " -o"): a$ = LEFT$(a$, x - 1) + " -lwinmm" + RIGHT$(a$, LEN(a$) - x + 1)
END IF
a$ = StrRemove(a$, "-lksguid")
IF DEPENDENCY(DEPENDENCY_AUDIO_OUT) THEN
x = INSTR(a$, " -o"): a$ = LEFT$(a$, x - 1) + " -lksguid" + RIGHT$(a$, LEN(a$) - x + 1)
END IF
a$ = StrRemove(a$, "-ldxguid")
IF DEPENDENCY(DEPENDENCY_AUDIO_OUT) THEN
x = INSTR(a$, " -o"): a$ = LEFT$(a$, x - 1) + " -ldxguid" + RIGHT$(a$, LEN(a$) - x + 1)
END IF
a$ = StrRemove(a$, "-lole32")
IF DEPENDENCY(DEPENDENCY_AUDIO_OUT) THEN
x = INSTR(a$, " -o"): a$ = LEFT$(a$, x - 1) + " -lole32" + RIGHT$(a$, LEN(a$) - x + 1)
END IF
a$ = StrRemove(a$, "-lgdi32")
IF DEPENDENCY(DEPENDENCY_ICON) <> 0 OR DEPENDENCY(DEPENDENCY_SCREENIMAGE) <> 0 OR DEPENDENCY(DEPENDENCY_PRINTER) <> 0 THEN
x = INSTR(a$, " -o"): a$ = LEFT$(a$, x - 1) + " -lgdi32" + RIGHT$(a$, LEN(a$) - x + 1)
END IF
IF inline_DATA = 0 THEN
'add data.o?
IF DataOffset THEN
@ -11545,6 +11630,10 @@ tpos = 1
DO
token$ = MID$(cmdline$, tpos, 2) '))
SELECT CASE token$
CASE "-g" 'non-GUI environment ($CONSOLE:ONLY in effect)
DEPENDENCY(DEPENDENCY_CONSOLE_ONLY) = DEPENDENCY(DEPENDENCY_CONSOLE_ONLY) OR 2
NoIDEMode = 1 'Implies -c
Console = 1
CASE "-q" 'Building a Qloud program
Cloud = 1
ConsoleMode = 1 'Implies -x
@ -21072,7 +21161,7 @@ SUB xprint (a$, ca$, n)
u$ = str2$(uniquenumber)
l$ = "PRINT"
IF ASC(a$) = 76 THEN lp = 1: lp$ = "l": l$ = "LPRINT": PRINT #12, "tab_LPRINT=1;" '"L"
IF ASC(a$) = 76 THEN lp = 1: lp$ = "l": l$ = "LPRINT": PRINT #12, "tab_LPRINT=1;": DEPENDENCY(DEPENDENCY_PRINTER) = 1 '"L"
'PRINT USING?
IF n >= 2 THEN
@ -23777,6 +23866,31 @@ Error_Happened = 1
Error_Message = a$
END SUB
FUNCTION StrRemove$ (myString$, whatToRemove$) 'noncase sensitive
a$ = myString$
b$ = LCASE$(whatToRemove$)
i = INSTR(LCASE$(a$), b$)
DO WHILE i
a$ = LEFT$(a$, i - 1) + RIGHT$(a$, LEN(a$) - i - LEN(b$) + 1)
i = INSTR(LCASE$(a$), b$)
LOOP
StrRemove$ = a$
END FUNCTION
FUNCTION StrReplace$ (myString$, find$, replaceWith$) 'noncase sensitive
IF LEN(myString$) = 0 THEN EXIT FUNCTION
a$ = myString$
b$ = LCASE$(find$)
basei = 1
i = INSTR(basei, LCASE$(a$), b$)
DO WHILE i
a$ = LEFT$(a$, i - 1) + replaceWith$ + RIGHT$(a$, LEN(a$) - i - LEN(b$) + 1)
basei = i + LEN(replaceWith$)
i = INSTR(basei, LCASE$(a$), b$)
LOOP
StrReplace$ = a$
END FUNCTION
'$INCLUDE:'subs_functions\extensions\opengl\opengl_methods.bas'

View file

@ -521,7 +521,7 @@ id.NoCloud = 1
regid
clearid
id.n = "_PRINTIMAGE"
id.n = "_PRINTIMAGE": id.Dependency = DEPENDENCY_PRINTER
id.subfunc = 2
id.callname = "sub__printimage"
id.args = 1
@ -552,7 +552,7 @@ id.NoCloud = 1
regid
clearid
id.n = "_SCREENIMAGE"
id.n = "_SCREENIMAGE": id.Dependency = DEPENDENCY_SCREENIMAGE
id.subfunc = 1
id.callname = "func__screenimage"
id.args = 4
@ -649,7 +649,7 @@ id.ret = LONGTYPE - ISPOINTER
regid
clearid
id.n = "_OPENHOST"
id.n = "_OPENHOST": id.Dependency = DEPENDENCY_SOCKETS
id.subfunc = 1
id.callname = "func__openhost"
id.args = 1
@ -686,7 +686,7 @@ id.ret = LONGTYPE - ISPOINTER
regid
clearid
id.n = "_OPENCLIENT"
id.n = "_OPENCLIENT": id.Dependency = DEPENDENCY_SOCKETS
id.subfunc = 1
id.callname = "func__openclient"
id.args = 1
@ -753,7 +753,7 @@ id.arg = MKL$(DOUBLETYPE - ISPOINTER)
regid
clearid
id.n = "_ICON"
id.n = "_ICON": id.Dependency = DEPENDENCY_ICON
id.subfunc = 2
id.callname = "sub__icon"
id.args = 2
@ -2722,7 +2722,7 @@ id.arg = MKL$(STRINGTYPE - ISPOINTER)
regid
clearid
id.n = "LPRINT"
id.n = "LPRINT": id.Dependency = DEPENDENCY_PRINTER
id.subfunc = 2
id.callname = "qbs_lprint" 'not called directly
id.args = 1
@ -2731,7 +2731,7 @@ id.NoCloud = 1
regid
clearid
id.n = "LPOS"
id.n = "LPOS": id.Dependency = DEPENDENCY_PRINTER
id.subfunc = 1
id.callname = "func_lpos"
id.args = 1