Example #1
0
bool WinMetaFileDraw::Create(HDC hdc, int cx, int cy, const char *app, const char *name, const char *file) {
	if(handle) Close();

	String s;
	if(app) s.Cat(app);
	s.Cat('\0');
	if(name) s.Cat(name);
	s.Cat('\0');

	bool del = false;
	if(!hdc) {
		hdc = ::GetWindowDC((HWND) NULL);
		del = true;
	}
	size = Size(iscale(cx, 2540, 600), iscale(cy, 2540, 600));

	Rect r = size;

	HDC mfdc = ::CreateEnhMetaFile(hdc, file, r, name || app ? (const char *)s : NULL);
	if(!mfdc)
		return false;
	Size px(max(1, ::GetDeviceCaps(mfdc, HORZRES)),  max(1, ::GetDeviceCaps(mfdc, VERTRES)));
	Size mm(max(1, ::GetDeviceCaps(mfdc, HORZSIZE)), max(1, ::GetDeviceCaps(mfdc, VERTSIZE)));
	Attach(mfdc);

	Init();

	pixels = false;

	::SetMapMode(handle, MM_ANISOTROPIC);
	::SetWindowOrgEx(handle, 0, 0, 0);
	::SetWindowExtEx(handle, 600, 600, 0);
	::SetViewportOrgEx(handle, 0, 0, 0);
	::SetViewportExtEx(handle, px.cx * 254 / (10 * mm.cx), px.cy * 254 / (10 * mm.cy), 0);
	::SelectClipRgn(mfdc, NULL);
	::IntersectClipRect(mfdc, 0, 0, cx, cy);

	if(del) {
		::ReleaseDC((HWND) NULL, hdc);
		hdc = NULL;
	}

	actual_offset = Point(0, 0);

	printer = false;
	pixels = false;
	actual_offset = Point(0, 0);
	device = -1;
	aborted = false;
	palette = false;
	backdraw = true;

	return true;
}
Example #2
0
void ScrollBar::Position() {
	int slsize = GetRange();
	int mint = max(minthumb, style->thumbmin);
	if(slsize < mint || totalsize <= pagesize)
		pagepos = 0;
	else
	if(thumbpos == slsize - thumbsize)
		pagepos = totalsize - pagesize;
	else
	if(thumbsize == mint)
		pagepos = iscale(thumbpos, (totalsize - pagesize), (slsize - mint));
	else
		pagepos = iscale(thumbpos, totalsize, slsize);
	Action();
	WhenScroll();
}
Example #3
0
int Socket::Data::Read(void *buf, int amount)
{
	int res = recv(socket, (char *)buf, amount, 0);
#if FAKESLOWLINE
	if(res > 0) {
		int end = msecs() + iscale(res, 10000, FAKESLOWLINE) + 10;
		for(int delta; (delta = end - msecs()) > 0; Sleep(delta))
			;
	}
#endif
#ifndef NOFAKEERROR
	if(fake_error && res > 0) {
		if((fake_error -= res) <= 0) {
			fake_error = 0;
			if(sock)
				sock->SetSockError(socket, "recv", 1, "fake error");
			return -1;
		}
		else
			LLOG("Socket::Data::Read: fake error after " << fake_error);
	}
#endif
	if(res == 0)
		is_eof = true;
	else if(res < 0 && Socket::GetErrorCode() != IS_BLOCKED)
		SetSockError("recv");
	return res;
}
Example #4
0
int main(int argc, char *argv[])
{
	if(argc==1) 
    {
        printf("You must enter function\n");
        exit(1);     
    }
    char *fn_name;
    fn_name=argv[1];
    if(strcmp(fn_name,"function1")==0) function1(); //basic pointer aritmetic
    else if(strcmp(fn_name,"iscale")==0) iscale(--argc, ++argv); //generate E.T tables for N-notes to the octave (N<=24) ***NOTICE --argc and ++argv
    else if(strcmp(fn_name,"expdecay")==0) expdecay(--argc, ++argv); //generate exponential attack or decay breakpoint data
    else if(strcmp(fn_name,"sinetext")==0) sinetext(--argc, ++argv); //generate sinusoidal curve for use with GNUplot --> showcases use of enum
    else if(strcmp(fn_name,"byte_order")==0) { if(byte_order()==0) printf("System is big-endian\n"); else printf("System is little-endian\n"); } //tells endian type of system
    else if(strcmp(fn_name,"sf2float")==0) sf2float(--argc, ++argv); //convert soundfile to float format
    else if(strcmp(fn_name,"sig_gen")==0) sig_gen(--argc, ++argv); //generate oscillation signal (sine, triangle, square, sawtooth up, sawtooth down)
	else if(strcmp(fn_name,"osc_gen")==0) osc_gen(--argc, ++argv); //Oscillator Bank (Array of oscillators) for additive sythesis for the natural specturm of sound (classic square, trianlgle, saw_up, saw_down)
	else if(strcmp(fn_name,"summation_function")==0) summation_function(--argc, ++argv); // summation for a^n (CS473 Quiz3)
	else if(strcmp(fn_name,"secant_method")==0) secant_method(--argc, ++argv); // secant method implementation for CS357 Quiz3
	else if(strcmp(fn_name,"oddSumTest")==0) oddSumTest(--argc, ++argv); // oddSum program for Rishi
	else if(strcmp(fn_name,"pointerTest")==0) pointerTest();//pointer test for CS241
	else if(strcmp(fn_name,"aQRec")==0) aQRec(); //tests for audioQueueRecorder
    else
    {
        printf("Function not found\n");
        exit(1);
    }
    
    return 0;
}
Example #5
0
Size GetPixelsPerMeter(const Draw& draw)
{
	if(draw.Dots())
		return Size(DOTS_PER_METER_INT, DOTS_PER_METER_INT);
	else
		return iscale(draw.GetPagePixels(), Size(1000, 1000), max(draw.GetPageMMs(), Size(1, 1)));
}
Example #6
0
void drvIDRAW::show_text(const TextInfo & textinfo)
{
	// Output the text header
	print_header("Text");

	// Output the name of the font to use on screen
	outf << "%I f " << psfont2xlfd(textinfo.currentFontName.value());
	outf << iscale(textinfo.currentFontSize);
	outf << "-*-*-*-*-*-*-*" << endl;

	// Output the name of the font to print
	outf << textinfo.currentFontName.value() << ' ';
	outf << iscale(textinfo.currentFontSize);
	outf << " SetF" << endl;

	// Output the next part of the text setup boilerplate
	outf << "%I t" << endl;
	const float toRadians = 3.14159265359f / 180.0f;
	const float angle = textinfo.currentFontAngle * toRadians;
	const float xoffset = textinfo.currentFontSize * (float) -sin(angle);
	const float yoffset = textinfo.currentFontSize * (float) cos(angle);
	outf << "[ " << cos(angle) << ' ' << sin(angle) << ' ';
	outf << -sin(angle) << ' ' << cos(angle) << ' ';
	outf << (unsigned int) (0.5 + xoffset + textinfo.x / IDRAW_SCALING) << ' ';
	outf << (unsigned int) (0.5 + yoffset + textinfo.y / IDRAW_SCALING);
	outf << " ] concat" << endl;
	outf << "%I" << endl;
	outf << "[" << endl;

	// Output the string, escaping parentheses with backslashes
	outf << '(';
	for (const char *c = textinfo.thetext.value(); *c; c++)
		switch (*c) {
		case '(':
			outf << "\\(";
			break;
		case ')':
			outf << "\\)";
			break;
		default:
			outf << *c;
			break;
		}
	outf << ')' << endl;
	outf << "] Text" << endl;
	outf << "End" << endl << endl;
}
Example #7
0
void ProgressIndicator::Set(int _actual, int _total) {
	actual = _actual;
	total = _total;
	Size sz = GetMsz();
	int p;
	if(total <= 0) {
		int l = max(1, max(sz.cx, sz.cy) & ~7);
		int p = GetTickCount() / 15 % (l + l / 4);
		if(pxp != p) {
			pxp = p;
			Refresh();
		}
		return;
	}
	else {
		int l = max(1, max(sz.cx, sz.cy));
		p = total ? min(iscale(actual, l, total), l) : 0;
	}
	if(p != pxp) {
		pxp = p;
		Refresh();
	}
}
Example #8
0
int GetVertPixelsPerMeter(const Draw& draw)
{
	return draw.Dots() ? DOTS_PER_METER_INT
		: iscale(draw.GetPagePixels().cy, 1000, max(draw.GetPageMMs().cy, 1));
}
Example #9
0
int cScrnRest( int iLeft, int iTop, char *cScrFile,
               int image_ops, int iDelFlag, int iMoveFlag )
{
   struct xScrFileHEADER  xScr;              // Screen file header
   FHANDLE fhandle;                          // Screen file handle
   unsigned char *imgbuf;                    // image buffer
   unsigned int isize;                       // image size variable
   unsigned int iRowCnt;                     // row counter
   int iCnt;                                 // image counter


   if(iMoveFlag != MPIXEL)
     {
       iLeft   = iscale(iLeft  , SCALE_X , SCR_SCALE);
       iTop    = iscale(iTop   , SCALE_Y , SCR_SCALE);
      }


   // Open screen input file
   fhandle = _fsOpen(cScrFile, FO_READ|FO_SHARED);

   if (_fsError())
      return( grSCR_IOERROR );

   // Read Screen File Header
   _fsRead(fhandle,(BYTEP)&xScr, sizeof(xScr));

   // Check Screen file for signature word
   if ( xScr.scrType != SCR_SIGNATURE_WORD)
      {
         _fsClose(fhandle);
         return( grSCR_UNSUPPORTED );
      }

   // Position file pointer to start of screen image
   _fsSeek(fhandle, xScr.lOffBits , FS_SET);

   isize = max( xScr.iSizeImage, xScr.iLastImage);

   // allocate largest memory required to hold the image
   imgbuf = _xalloc(isize);

   if (imgbuf == NULL)
      {
         _fsClose(fhandle);
         return( grSCR_NOMEMORY );
      }


   iRowCnt = iTop;

   for ( iCnt = 1; iCnt <= xScr.iImgCount; iCnt++ )
    {

      if( iCnt == xScr.iImgCount )
          isize = xScr.iLastImage;
      else
          isize = xScr.iSizeImage;

      // Read Image buffer
      _fsRead(fhandle, imgbuf, isize);

      // display the image
      putimage(iLeft, iRowCnt, imgbuf, image_ops);

      iRowCnt += xScr.iRowIncr + 1;

    }

   // clean-up code
   _xfree(imgbuf);
   _fsClose(fhandle);

   // delete screen file
   if (iDelFlag)
      _fsDelete (cScrFile);

   return( grSCR_OKAY );
}
Example #10
0
Size PixelsToDots(const Draw& draw, Size size)
{
	return draw.Dots() ? size
		: iscale(size, Size(DOTS_PER_METER_INT, DOTS_PER_METER_INT), GetPixelsPerMeter(draw));
}
Example #11
0
Size PointsToPixels(const Draw& draw, Size points)
{
	if(draw.Dots())
		return points * 600 / 72;
	return iscale(points, draw.GetPixelsPerInch(), Size(72, 72));
}
Example #12
0
int PointsToPixels(const Draw& draw, int points)
{
	if(draw.Dots())
		return points * 600 / 72;
	return iscale(points, draw.GetPixelsPerInch().cx, 72);
}
Example #13
0
Size PixelsToPoints(const Draw& draw, Size pixels)
{
	if(draw.Dots())
		return pixels * 72 / 600;
	return iscale(pixels, Size(72, 72), draw.GetPixelsPerInch());
}
Example #14
0
int PixelsToPoints(const Draw& draw, int pixels)
{
	if(draw.Dots())
		return pixels * 72 / 600;
	return iscale(pixels, 72, draw.GetPixelsPerInch().cx);
}
Example #15
0
int Draw::GetNativeX(int x) const
{
	Size sz = GetNativeDpi();
	return Dots() && sz.cx != 600 ? iscale(x, sz.cx, 600) : x;
}
///////////////////////////////////////////////////////////////////////////////////////////////
// handles changes in images or ctrl
void PixRasterBaseCtrl::Layout(void)
{
	// this to avoid recursion
	static bool inside = false;
	
	// if no associated PixRaster or no pages to display, hides scrollbar and return
	if(!pixRasterCtrl->GetPixBase() || !pixRasterCtrl->GetPageCount())
	{
		hScrollBar.Hide();
		vScrollBar.Hide();
		return;
	}
	
	// if already doing layout, just return
	if(inside)
		return;
	
	// marks inside layout
	inside = true;
	
	// stores scroll positions, in order to go on right position
	// after zoom operations
	int hScrollPos = hScrollBar.Get();
	int hScrollMax = hScrollBar.GetTotal();
	int vScrollPos = vScrollBar.Get();
	int vScrollMax = vScrollBar.GetTotal();

	// gets the PixRaster object
	PixBase *pixBase = pixRasterCtrl->GetPixBase();

	// calculates max width and height
	// and total Tiff height, for all pages, with no gaps by now
	int rasterWidth = 0;
	int rasterHeight = 0;
	int maxHeight = 0;
	int pageCount = pixBase->GetPageCount();
	for(int i = 0 ; i < pageCount ; i++)
	{
		// sets current page
		pixBase->SeekPage(i);
		
		// gets page size
		Size sz = pixBase->GetSizeEx(i);
		
		// updates width, maximum height and total height
		if(sz.cx > rasterWidth)
			rasterWidth = sz.cx;
		if(sz.cy > maxHeight)
			maxHeight = sz.cy;
		rasterHeight += sz.cy;
	}
	
	// calculates image scale factor
	imageScale = CalcScale(imageScale, rasterWidth, maxHeight);
	
	// stops layouting if imagescale is null
	if(!imageScale)
	{
		inside = false;
		return;
	}

	// now calculate gaps to be exactly 10 pixels in every zoom factor
	int gapSize = ScaleToPage(10);
	
	// adds total gaps sizes to total height
	rasterHeight += (pageCount -1) * gapSize;

	// and finally, sets up scrollbars and shows them
	// and calculate cache sizes
	int scaledRasterHeight = ScaleToView(rasterHeight);
	int cacheHeight;
	vScrollBar.SetPage(GetSize().cy);
	vScrollBar.SetTotal(scaledRasterHeight);
	if(vScrollMax)
		vScrollBar.Set(iscale(vScrollPos, scaledRasterHeight, vScrollMax));
	else
		vScrollBar.Set(0);
	if(GetSize().cy <= scaledRasterHeight)
	{
		if(hasVScrollBar)
			vScrollBar.Show();
		cacheHeight = GetSize().cy;
	}
	else
	{
		vScrollBar.Hide();
		cacheHeight = scaledRasterHeight;
	}
	int scaledRasterWidth = ScaleToView(rasterWidth);
	int cacheWidth;
	hScrollBar.SetPage(GetSize().cx);
	hScrollBar.SetTotal(scaledRasterWidth);
	if(hScrollMax)
		hScrollBar.Set(iscale(hScrollPos, scaledRasterWidth, hScrollMax));
	else
		hScrollBar.Set(0);
	if(GetSize().cx <= scaledRasterWidth)
	{
		if(hasHScrollBar)
			hScrollBar.Show();
		cacheWidth = GetSize().cx;
	}
	else
	{
		hScrollBar.Hide();
		cacheWidth = scaledRasterWidth;
	}
	
	// creates cache image, empty by now
	imageCache.Init(Size(cacheWidth, cacheHeight));
	
	// updates image
	Refresh();
	
	// mark layout terminated
	inside = false;
	
} // END PixRasterBaseCtrl::Layout()
Example #17
0
int Draw::GetNativeY(int y) const
{
	Size sz = GetNativeDpi();
	return Dots() && sz.cx != 600 ? iscale(y, sz.cy, 600) : y;
}
Example #18
0
void drvIDRAW::print_coords()
{
	unsigned int pathelts = numberOfElementsInPath();
	bool closed;				// True if shape is closed
	bool curved;				// True if shape is curved
	const Point *firstpoint;	// First and last points in shape
	const Point *lastpoint;
	unsigned int totalpoints;	// Total number of points in shape
	const Point dummypoint(-123.456f, -789.101112f);	// Used to help eliminate duplicates

	unsigned int i, j;

	// First, try to figure out what type of shape we have
	closed = false;
	curved = false;
	for (i = 0; i < pathelts; i++) {
		if (pathElement(i).getType() == curveto)
			curved = true;
		else if (pathElement(i).getType() == closepath)
			closed = true;
	}
	const Point **pointlist = new const Point *[pathelts * 3];	// List of points
	 	// Allocate a conservative amount
	assert(pointlist != NIL);
	firstpoint = NIL;
	lastpoint = &dummypoint;
	totalpoints = 0;
	for (i = 0; i < pathelts; i++) {
		const basedrawingelement & pelt = pathElement(i);

		if ((pelt.getType() == moveto || pelt.getType() == lineto) &&
			!(pelt.getPoint(0) == *lastpoint))
			lastpoint = pointlist[totalpoints++] = &pelt.getPoint(0);
		else if (pelt.getType() == curveto)
			for (j = 0; j < 3; j++)
				lastpoint = pointlist[totalpoints++] = &pelt.getPoint(j);
	}
	if (totalpoints) {
		firstpoint = pointlist[0];
		if (firstpoint->x_ == lastpoint->x_ && firstpoint->y_ == lastpoint->y_)
			closed = true;

		// Find points on the curve for curved lines
		if (curved) {
			const unsigned int pt_per_cp = 5;	// PostScript points per control point
			const unsigned int min_innerpoints = 2;	// Minimum # of points to add
			unsigned int innerpoints;	// Number of points to add
			unsigned int newtotalpoints = 0;	// Number of points in curve

			// ASSUMPTION: Curve is moveto+curveto+curveto+curveto+...
			// List of points on curve
			const Point **newpointlist = new const Point *[pathelts * 3000 / pt_per_cp];	// Allocate a conservative amount
			assert(newpointlist != NIL);
			for (i = 0; i < totalpoints - 3; i += 3) {
				const float x0 = pointlist[i]->x_;
				const float y0 = pointlist[i]->y_;
				const float x1 = pointlist[i + 1]->x_;
				const float y1 = pointlist[i + 1]->y_;
				const float x2 = pointlist[i + 2]->x_;
				const float y2 = pointlist[i + 2]->y_;
				const float x3 = pointlist[i + 3]->x_;
				const float y3 = pointlist[i + 3]->y_;
				const float cx = (x1 - x0) * 3;
				const float cy = (y1 - y0) * 3;
				const float bx = (x2 - x1) * 3 - cx;
				const float by = (y2 - y1) * 3 - cy;
				const float ax = x3 - x0 - cx - bx;
				const float ay = y3 - y0 - cy - by;
				

				// Longer lines get more control points
				innerpoints =(unsigned int) (
							pythagoras((y1 - y0),(x1 - x0) ) + 
							pythagoras((y2 - y1),(x2 - x1) ) + 
							pythagoras((y3 - y2),(x3 - x2) ) ) / pt_per_cp;
				if (innerpoints < min_innerpoints)
					innerpoints = min_innerpoints;

				// Add points to the list
				ADDPOINT(x0, y0);
				for (j = 1; j <= innerpoints; j++) {
					const float t = (float) j / (float) innerpoints;
					const float newx = (((ax * t) + bx) * t + cx) * t + x0;
					const float newy = (((ay * t) + by) * t + cy) * t + y0;
					ADDPOINT(newx, newy);
				}
				ADDPOINT(x3, y3);
			}

			delete[]pointlist;
			pointlist = newpointlist;
			totalpoints = newtotalpoints;
		}
		// Straight lines, not closed
		if (!closed && !curved) {
			if (totalpoints == 2) {	// Special case for single line
				print_header("Line");
				outf << "%I" << endl;
				outf << iscale(firstpoint->x_) << ' ' << iscale(firstpoint->y_) << ' ';
				outf << iscale(lastpoint->x_) << ' ' << iscale(lastpoint->y_) << ' ';
				outf << "Line" << endl;
				outf << "%I 1" << endl;
				outf << "End" << endl << endl;
			} else {			// Otherwise, output a multiline
				print_header("MLine");	// (Should have a special case for Rect)
				outf << "%I " << totalpoints << endl;
				for (i = 0; i < totalpoints; i++) {
					outf << iscale(pointlist[i]->x_) << ' ';
					outf << iscale(pointlist[i]->y_) << endl;
				}
				outf << totalpoints << " MLine" << endl;
				outf << "%I 1" << endl;
				outf << "End" << endl << endl;
			}
		}
		// Straight lines, closed */
		if (closed && !curved) {
			unsigned int numpoints;

			numpoints = totalpoints == 1 ? 1 : totalpoints - 1;
			print_header("Poly");	// Output a polygon
			outf << "%I " << numpoints << endl;
			for (i = 0; i < numpoints; i++) {
				outf << iscale(pointlist[i]->x_) << ' ';
				outf << iscale(pointlist[i]->y_) << endl;
			}
			outf << numpoints << " Poly" << endl;
			outf << "End" << endl << endl;
		}
		// Curved lines, not closed
		if (!closed && curved) {
			print_header("BSpl");	// Output a B-spline
			outf << "%I " << totalpoints << endl;
			for (i = 0; i < totalpoints; i++) {
				outf << iscale(pointlist[i]->x_) << ' ';
				outf << iscale(pointlist[i]->y_) << endl;
			}
			outf << totalpoints << " BSpl" << endl;
			outf << "%I 1" << endl;
			outf << "End" << endl << endl;
		}
		// Curved lines, closed
		if (closed && curved) {
			unsigned int numpoints;

			numpoints = totalpoints == 1 ? 1 : totalpoints - 1;
			print_header("CBSpl");	// Output a closed B-spline
			outf << "%I " << numpoints << endl;
			for (i = 0; i < numpoints; i++) {
				outf << iscale(pointlist[i]->x_) << ' ';
				outf << iscale(pointlist[i]->y_) << endl;
			}
			outf << numpoints << " CBSpl" << endl;
			outf << "End" << endl << endl;
		}
		if (curved) {
			//
			// in this case we have created the pointlist newly with Points on the heap
			//
			if (pointlist)
				for (unsigned int pindex = 0; pindex < totalpoints; pindex++) {
					//cout << "pindex / totalpoints " << pindex  << " " << totalpoints << " " << pointlist[pindex]->x_ << " " << pointlist[pindex]->y_ << " " << pointlist[pindex]<< endl;
#if defined (_MSC_VER) && (_MSC_VER < 1100)
					// MSVC < 6 needs cast here
					delete (Point *)	(pointlist[pindex]);	
#else
					delete				(pointlist[pindex]);	
#endif
				}

		}
	}
	delete[]pointlist;
}