src/test.cpp
changeset 24 c6b5c552980a
parent 23 d4e164906a1b
child 25 233a997193b8
     1.1 --- a/src/test.cpp	Thu May 22 21:32:45 2014 +0200
     1.2 +++ b/src/test.cpp	Thu May 22 22:36:43 2014 +0200
     1.3 @@ -55,7 +55,8 @@
     1.4  MainWindow::MainWindow(FXApp *app)
     1.5  	: FXMainWindow(app, "HIDAPI Test Application", NULL, NULL, DECOR_ALL, 200,100, 600,900),
     1.6      iCurrentFont(NULL),
     1.7 -    iFontImage(NULL)
     1.8 +    iFontImage(NULL),
     1.9 +	iPixelBuffer(NULL)
    1.10  {
    1.11  	iBrightness=iVfd01.MaxBrightness();
    1.12  	devices = NULL;
    1.13 @@ -173,6 +174,9 @@
    1.14      delete iFontImage;
    1.15      iFontImage = NULL;
    1.16  
    1.17 +	delete[] iPixelBuffer;
    1.18 +	iPixelBuffer = NULL;
    1.19 +
    1.20  	if (connected_device)
    1.21  		hid_close(connected_device);
    1.22  	hid_exit();
    1.23 @@ -754,9 +758,13 @@
    1.24          delete iFontImage;
    1.25          iFontImage = NULL;
    1.26          //
    1.27 -        FXString text="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-[]{}();%$£&~#|_";
    1.28 +		delete[] iPixelBuffer;
    1.29 +		iPixelBuffer=NULL;
    1.30 +
    1.31 +        //FXString text="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-[]{}();%$£&~#|_";
    1.32 +		FXString text="0123456789ABCDEF";
    1.33          //Create an image the proper size for our text
    1.34 -        iFontImage = new FXTGAImage(getApp(),NULL,IMAGE_SHMI|IMAGE_SHMP,iCurrentFont->getTextWidth(text),iCurrentFont->getFontHeight());
    1.35 +        iFontImage = new FXTGAImage(getApp(),NULL,IMAGE_KEEP/*IMAGE_SHMI|IMAGE_SHMP*/,iCurrentFont->getTextWidth(text),iCurrentFont->getFontHeight());
    1.36          iFontImage->create();
    1.37          //Perform our drawing
    1.38              {
    1.39 @@ -771,13 +779,39 @@
    1.40              dc.drawText(0,iCurrentFont->getFontAscent(),text);
    1.41              //dc.end();
    1.42              }
    1.43 +
    1.44 +		//Save to file
    1.45          FXFileStream file;
    1.46          file.open("fonttest.tga",FXStreamSave);
    1.47          iFontImage->restore();
    1.48          iFontImage->savePixels(file);
    1.49          file.close();
    1.50  
    1.51 -        //
    1.52 +        //Create display pixel buffer from our image pixels
    1.53 +		int w=iFontImage->getWidth();
    1.54 +		int h=iFontImage->getHeight(); 
    1.55 +		int pixelBufferSize=(w*h)/8;
    1.56 +		iPixelBuffer = new unsigned char[pixelBufferSize];
    1.57 +		memset(iPixelBuffer,0x00,pixelBufferSize);
    1.58 +		for (int i=0;i<w;i++)
    1.59 +			{
    1.60 +			for (int j=0;j<h;j++)
    1.61 +				{
    1.62 +				int byteOffset=(i*h+j)/8;
    1.63 +				int bitOffset=(i*h+j)%8;
    1.64 +				FXColor color=iFontImage->getPixel(i,j);
    1.65 +				if (color!=0xffffffff)
    1.66 +					{
    1.67 +					iPixelBuffer[byteOffset] |= ( 1 << bitOffset );
    1.68 +					}
    1.69 +				}
    1.70 +			}
    1.71 +
    1.72 +		if (iVfd01.IsOpen())
    1.73 +			{
    1.74 +			iVfd01.SetPixelBlock(0,0,h-1,pixelBufferSize,iPixelBuffer);
    1.75 +			iVfd01.SwapBuffers();
    1.76 +			}
    1.77  
    1.78          }
    1.79