Ejemplo n.º 1
0
void GetRect(Rect *zoomFrom, Rect *zoomTo)
{
	static short numRects = 0;
	Rect theRect,drawRect;
	Point firstPt,curPt,oldPt;
	RgnHandle rgnHandle = NewRgn();
	GrafPtr	oldPort;
	
	GetPort(&oldPort);
	SetPort(GetWindowPort(gWindow));
	
	PenMode(patXor);
	
	GetMouse(&firstPt);
	oldPt = firstPt;
	SetRect(&theRect,firstPt.h,firstPt.v,firstPt.h,firstPt.v);
	
	while (Button()) {
		GetMouse(&curPt);
		if (!EqualPt(curPt,oldPt)) {
			FixRect(&theRect,&drawRect);
			FrameRect(&drawRect);
			oldPt = curPt;
			theRect.right = curPt.h;
			theRect.bottom = curPt.v;
			FixRect(&theRect,&drawRect);
			FrameRect(&drawRect);
			QDFlushPortBuffer(GetWindowPort(gWindow), GetPortVisibleRegion(GetWindowPort(gWindow), rgnHandle));
		}
	}
		
	FixRect(&theRect,&drawRect);
	if (numRects==0)
		*zoomFrom = drawRect;
	else
		*zoomTo = drawRect;
			
	numRects++;
		
	QDFlushPortBuffer(GetWindowPort(gWindow), GetPortVisibleRegion(GetWindowPort(gWindow), rgnHandle));
	
	if (numRects >= 2) {
		ZoomRect(kZoomLarger, zoomFrom, zoomTo);
		numRects = 0;
	}
	
	PenNormal();
	DisposeRgn(rgnHandle);
	SetPort(oldPort);

}
Ejemplo n.º 2
0
void handleMenuSelection(long result)
{
	int menuID, menuItem;
	RgnHandle rgnHandle = NewRgn();
	
	menuID = HiWord(result);
	menuItem = LoWord(result);
	
	if (menuID == FILE_MENU) {
		if (menuItem == FILE_SAVE)
			saveToPICTFile();
		else if (menuItem == FILE_QUIT)
			gDone = true;
		else if (menuItem == FILE_CLOSE) {
			DisposeWindow(FrontWindow());
			if (FrontWindow() == NULL)
				gDone = true;
		}
		else if (menuItem == FILE_NEW) {
		
		}
		else if (menuItem == FILE_REFRESH) {
			createImage();
			drawImage(FrontWindow());
			QDFlushPortBuffer(GetWindowPort(FrontWindow()), GetPortVisibleRegion(GetWindowPort(FrontWindow()), rgnHandle));
		}
	}
	HiliteMenu(0);
	DisposeRgn(rgnHandle);
}
void doEventLoop()
{
	EventRecord event;
	WindowPtr   window;
	short       clickArea;
	Rect        screenRect;
	RgnHandle	rgnHandle = NewRgn();

	for (;;)
	{
		if (WaitNextEvent( everyEvent, &event, 0, nil ))
		{
			if (event.what == mouseDown)
			{
				clickArea = FindWindow( event.where, &window );
				
				if (clickArea == inDrag)
				{
					//screenRect = (**GetGrayRgn ()).rgnBBox;
					GetRegionBounds(GetGrayRgn(), &screenRect);
					DragWindow( window, event.where, &screenRect );
				}
				else if (clickArea == inContent)
				{
					if (window != FrontWindow())
						SelectWindow( window );
				}
				else if (clickArea == inGoAway)
					if (TrackGoAway( window, event.where ))
						return;
			}
			else if (event.what == updateEvt)
			{
				window = (WindowPtr)event.message;	
				//SetPort( window );
				SetPortWindowPort( window );
				
				BeginUpdate( window );
				drawPixelImageData();
				EndUpdate( window );
				QDFlushPortBuffer(GetWindowPort(window), GetPortVisibleRegion(GetWindowPort(window), rgnHandle));
			}
			else if (event.what == activateEvt) 
			{
				/*if (event.modifiers & activeFlag) {
					window = (WindowPtr)event.message;
					SetPortWindowPort(window);
					drawPixelImageData();
					QDFlushPortBuffer(GetWindowPort(window), GetPortVisibleRegion(GetWindowPort(window), rgnHandle));
				}*/
				/*if (event.modifiers & activeFlag)
					PostEvent(updateEvt, (unsigned long)gWindow);*/
			}
		}
	}
	
	DisposeRgn(rgnHandle);
}
Ejemplo n.º 4
0
void x_push_done()      {

  CGrafPtr window_port;

  SetPortWindowPort(g_main_window);
  window_port = GetWindowPort(g_main_window);

  QDFlushPortBuffer(window_port, 0);

}
Ejemplo n.º 5
0
static
void crosshair(int mousex, int mousey)
{
  PenMode(srcXor);

  MoveTo(mousex, 0); LineTo(mousex, p->height);
  MoveTo(0, mousey); LineTo(p->width, mousey);
  QDFlushPortBuffer(p->port, NULL);

  PenMode(srcCopy);
}
Ejemplo n.º 6
0
void
TkMacOSXFlushWindows ()
{
    WindowRef wRef = GetWindowList();
    
    while (wRef) {
        CGrafPtr portPtr = GetWindowPort(wRef);
        if (QDIsPortBuffered(portPtr)) {
            QDFlushPortBuffer(portPtr, NULL);
        }
        wRef = GetNextWindow(wRef);
    }
}
Ejemplo n.º 7
0
static void statsline (bigstring bs) {
	
	register hdlstatsrecord hs = statsdata;
	
	movepento ((**hs).hstats, (**hs).vstats);
	
	pendrawstring (bs);
	
	(**hs).vstats += (**hs).statslineheight;
	
	//Timothy Paustian 10/5/00
	//We need to flush the result to the stats window everytime to see it
	//If this is not called the window remains blank.
	#if TARGET_API_MAC_CARBON == 1
	QDFlushPortBuffer(GetWindowPort(statswindow), nil);
	#endif
	} /*statsline*/
Ejemplo n.º 8
0
boolean openabout (boolean flzoom, long ctreservebytes) {
#pragma unused(flzoom)

	/*
	2.1b5 dmb: added ctreservebytes parameter. of non-zero, caller wants us to 
	reserve space in the heap below the dialog record (during initialization)
	*/
	
	hdlwindowinfo hinfo;
	
#ifdef MACVERSION
	Ptr ptemp = nil;
	
	if (ctreservebytes > 0)
		ptemp = NewPtr (ctreservebytes); /*force about window to load high*/
#endif

	aboutstart ();
	
	shellpatchnilroutines ();
	
//	aboutwindow = newmodaldialog (128, -1);
	newaboutwindow (true);
	
	if (findaboutwindow (&hinfo))
	{
		shellupdatenow ((**hinfo).macwindow);
		//Code change by Timothy Paustian 10/5/00
		//We need to flush the about window to the screen
		//safe because this routine only gets call during init. 
		#if TARGET_API_MAC_CARBON == 1
		QDFlushPortBuffer(GetWindowPort((**hinfo).macwindow), nil);
		#endif
	}
#ifdef MACVERSION
	if (ptemp != nil)
		DisposePtr (ptemp); /*restore heap space for remaining code segments*/
#endif
	
	aboutopenticks = gettickcount ();
	
	return (true);
	} /*openabout*/
Ejemplo n.º 9
0
static void ROM_WindowUpdate(_THIS, int numrects, SDL_Rect *rects)
{
	GWorldPtr memworld;
	GrafPtr saveport;
	CGrafPtr thePort;
	const BitMap *memBits;
	const BitMap *winBits;
	int i;
	Rect update;
	
	/* Copy from the offscreen GWorld to the window port */
	GetPort(&saveport);
	SetPortWindowPort(SDL_Window);
	thePort = GetWindowPort(SDL_Window);
	memworld = (GWorldPtr)GetWRefCon(SDL_Window);
#if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS
	memBits = GetPortBitMapForCopyBits((CGrafPtr) memworld);
#else
	memBits = &((GrafPtr)memworld)->portBits;
#endif
#if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS
	winBits = GetPortBitMapForCopyBits(thePort);
#else
	winBits = &SDL_Window->portBits;
#endif
	for ( i=0; i<numrects; ++i ) {
		update.left = rects[i].x;
		update.right = rects[i].x+rects[i].w;
		update.top = rects[i].y;
		update.bottom = rects[i].y+rects[i].h;
		CopyBits(memBits, winBits,
			 &update, &update, srcCopy, nil);
	}
#if TARGET_API_MAC_CARBON
	if ( QDIsPortBuffered(thePort) ) {
		QDFlushPortBuffer(thePort, NULL);
	}
#endif
	SetPort(saveport);
}
Ejemplo n.º 10
0
static void langerrorupdate (void) {
	
	langerrorsetrects ();
	
	/*
	eraserect ((**hw).contentrect);
	*/
	#if TARGET_API_MAC_CARBON == 1
		drawthemeborder ((**langerrordata).textrect, (**langerrorwindowinfo).contentrect);
	#endif

	langerrordrawicon (false);
	
	#ifdef gray3Dlook
		pushbackcolor (&whitecolor);

		eraserect ((**langerrordata).textrect);
	#endif
	
//	framerect ((**langerrordata).textrect);
	
	langerrorframetext ();
		
	langerrordrawtext (false);

	//Timothy Paustian 10/5/00
	//For some reason the buffer is not being flushed for this window.
	//This should fix it.
	#if TARGET_API_MAC_CARBON == 1
		QDFlushPortBuffer (GetWindowPort (langerrorwindow), nil);
	#endif

	#ifdef gray3Dlook
		popbackcolor ();
	#endif
	} /*langerrorupdate*/
Ejemplo n.º 11
0
static pascal void MyTimerHandler( EventLoopTimerRef inTimer, void *inUserData )
{
    CGrafPtr            currentPort;
    Rect                currentPortRect;
    RgnHandle           flushRegion;

    SetPortWindowPort( (WindowRef) inUserData );

    //  Call the plug-in function "drawBall" which is defined in the plug-in interface.

    (*gDrawBallInterface)->drawBall( gDrawBallInterface );

    //  We are not drawing in response to an update or draw event, so if the window is buffered
    //  (i.e. on Mac OS X) we need to flush the content to be drawn in the window.

    GetPort( &currentPort );
    if( QDIsPortBuffered( currentPort ) ) {
    	GetPortBounds( currentPort, &currentPortRect );
    	flushRegion = NewRgn();
    	RectRgn( flushRegion, &currentPortRect );
        QDFlushPortBuffer( currentPort, flushRegion );
        DisposeRgn( flushRegion );
    }
}
Ejemplo n.º 12
0
void TabbedWindow::ForceUpdate( void )
{
    CGrafPtr port = GetWindowPort( fWindowRef );
    QDFlushPortBuffer( port, NULL );
}
Ejemplo n.º 13
0
void ZoomRect(Boolean zoomLarger,Rect *smallRect, Rect *bigRect)
{
	double firstStep,stepValue,trailer,zoomRatio;
	short i,step;
	Rect curRect;
	unsigned long ticks;
	Pattern	grayPattern; //used in carbonization
	RgnHandle rgnHandle = NewRgn();
	GrafPtr oldPort;
	Rect	tempRect1;
	
	GetPort(&oldPort);
	SetPort(GetWindowPort(gWindow));
	
	//PenPat(&qd.gray);
	PenPat(GetQDGlobalsGray(&grayPattern));
	PenMode(patXor);
	
	
	firstStep=kZoomRatio;
	for (i=0; i<kNumSteps; i++) {
		firstStep *= kZoomRatio;
	}

	if (!zoomLarger) {
		zoomRatio = 1.0/kZoomRatio;
		firstStep = 1.0-firstStep;
	}
	else
		zoomRatio = kZoomRatio;
		
	trailer = firstStep;
	stepValue = firstStep;
	for (step=0; step<(kNumSteps+kRectsVisible); step++) {
	
		// draw new frame
		
		if (step<kNumSteps) {
			stepValue /= zoomRatio;
			CalcRect(&curRect,smallRect,bigRect,stepValue);
			FrameRect(&curRect);
		}
		
		// erase old frame
		
		if (step>=kRectsVisible) {
			trailer /= zoomRatio;
			CalcRect(&curRect,smallRect,bigRect,trailer);
			FrameRect(&curRect);
		}
		QDFlushPortBuffer(GetWindowPort(gWindow), GetPortVisibleRegion(GetWindowPort(gWindow), rgnHandle));
		Delay(kDelayTicks,&ticks);
		
	}

	PenNormal();
	DisposeRgn(rgnHandle);
	smallRect->top = bigRect->top = -1;
	EraseRect(GetPortBounds(GetWindowPort(gWindow), &tempRect1));
	
	SetPort(oldPort);
}
Ejemplo n.º 14
0
void gks_drv_mac(
  int fctid, int dx, int dy, int dimx, int *ia,
  int lr1, double *r1, int lr2, double *r2, int lc, char *chars,
  void **ptr)
{
  p = (ws_state_list *) *ptr;

  switch (fctid)
    {
/* open workstation */
    case 2:
      gkss = (gks_state_list_t *) *ptr;

      p = (ws_state_list *) calloc(1, sizeof(ws_state_list));

      if (pthread_mutex_init(&p->mutex, NULL))
	{
	  perror("pthread_mutex_init");
	  exit(-1);
	}
      p->run = 0;
      if (pthread_create(&p->thread, NULL, exec, (void *) p))
	{
	  perror("pthread_create");
	  exit(-1);
	}

      while (!p->run)
	usleep(10000);

      p->port = GetWindowPort(p->win);
      SetPort(p->port);

      *ptr = p;
      break;

/* close workstation */
    case 3:
      p->run = 0;
      pthread_join(p->thread, NULL);
      pthread_mutex_destroy(&p->mutex);

      free(p);
      break;

/* activate workstation */
    case 4:
      p->state = GKS_K_WS_ACTIVE;
      break;

/* deactivate workstation */
    case 5:
      p->state = GKS_K_WS_INACTIVE;
      break;

/* clear workstation */
    case 6:
      clear_ws();
      break;

/* update workstation */
    case 8:
      pthread_mutex_lock(&p->mutex);
      QDFlushPortBuffer(p->port, NULL);
      pthread_mutex_unlock(&p->mutex);
      break;

/* polyline */
    case 12:
      if (p->state == GKS_K_WS_ACTIVE)
	{
	  pthread_mutex_lock(&p->mutex);
	  LockPortBits(p->port);
	  polyline(ia[0], r1, r2);
	  UnlockPortBits(p->port);
	  pthread_mutex_unlock(&p->mutex);
	}
      break;

/* polymarker */
    case 13:
      if (p->state == GKS_K_WS_ACTIVE)
	{
	  pthread_mutex_lock(&p->mutex);
	  LockPortBits(p->port);
	  polymarker(ia[0], r1, r2);
	  UnlockPortBits(p->port);
	  pthread_mutex_unlock(&p->mutex);
	}
      break;

/* text */
    case 14:
      if (p->state == GKS_K_WS_ACTIVE)
	{
	  pthread_mutex_lock(&p->mutex);
	  LockPortBits(p->port);
	  text(r1[0], r2[0], strlen(chars), chars);
	  UnlockPortBits(p->port);
	  pthread_mutex_unlock(&p->mutex);
	}
      break;

/* fill area */
    case 15:
      if (p->state == GKS_K_WS_ACTIVE)
	{
	  pthread_mutex_lock(&p->mutex);
	  LockPortBits(p->port);
	  fillarea(ia[0], r1, r2);
	  UnlockPortBits(p->port);
	  pthread_mutex_unlock(&p->mutex);
	}
      break;

/* cell array */
    case 16:
    case DRAW_IMAGE:
      if (p->state == GKS_K_WS_ACTIVE)
	{
	  int true_color = fctid == DRAW_IMAGE;

	  pthread_mutex_lock(&p->mutex);
	  LockPortBits(p->port);
	  cellarray(r1[0], r1[1], r2[0], r2[1], dx, dy, dimx, ia, true_color);
	  UnlockPortBits(p->port);
	  pthread_mutex_unlock(&p->mutex);
	}
      break;

/* set color representation */
    case 48:
      set_color_rep(ia[1], r1[0], r1[1], r1[2]);
      break;

    case 49:
/* set window */
      set_norm_xform(*ia, gkss->window[*ia], gkss->viewport[*ia]);
      break;

    case 50:
/* set viewport */
      set_norm_xform(*ia, gkss->window[*ia], gkss->viewport[*ia]);
      if (*ia == gkss->cntnr)
        set_clip_rect(*ia);
      break;

    case 52:
/* select normalization transformation */
    case 53:
/* set clipping inidicator */
      set_clip_rect(gkss->cntnr);
      break;

/* set workstation window */
    case 54:
      p->window[0] = r1[0];
      p->window[1] = r1[1];
      p->window[2] = r2[0];
      p->window[3] = r2[1];

      set_xform();
      init_norm_xform();
      break;

/* set workstation viewport */
    case 55:
      p->viewport[0] = r1[0];
      p->viewport[1] = r1[1];
      p->viewport[2] = r2[0];
      p->viewport[3] = r2[1];

      if (p->state == GKS_K_WS_ACTIVE)
	{
	  pthread_mutex_lock(&p->mutex);
	  LockPortBits(p->port);
	  resize_window();
	  set_xform();
	  init_norm_xform();
	  UnlockPortBits(p->port);
	  pthread_mutex_unlock(&p->mutex);
	}
      break;

/* request locator */
    case 81:
      if (p->state == GKS_K_WS_ACTIVE)
	{
	  pthread_mutex_lock(&p->mutex);
	  QDFlushPortBuffer(p->port, NULL);
	  get_pointer(r1, r2, &ia[0]);
	  pthread_mutex_unlock(&p->mutex);
	}
      break;

    default:
      ;
    }
}
Ejemplo n.º 15
0
int main()
{
	WindowPtr win;
	
#if !TARGET_API_MAC_CARBON
    InitGraf(&qd.thePort);
    InitFonts();
    InitWindows();
    InitMenus();

	Rect r = qd.screenBits.bounds;
#else
	BitMap bm;
	GetQDGlobalsScreenBits(&bm);
	Rect r = bm.bounds;
#endif    
    SetRect(&r, r.left + 5, r.top + 45, r.right - 5, r.bottom -5);
	win = NewWindow(NULL, &r, "\pRaytracer (C Version)", true, 0, (WindowPtr)-1, false, 0);
    
#if !TARGET_API_MAC_CARBON	
	SetPort(win);
	r = win->portRect;
#else
	SetPortWindowPort(win);
	GetPortBounds(GetWindowPort(win), &r);
#endif
    EraseRect(&r);
	float accum = 0.0f;
	short cx = r.right /2;
	short cy = r.bottom / 2;
	int x,y;

	lenl = 1.0f / sqrtf(lx*lx + ly*ly + lz*lz);
	lxn = lx*lenl, lyn = ly*lenl, lzn = lz*lenl;

	long startTime = TickCount();
	float *accumV = calloc(sizeof(float), r.right);
	for(y = 0; y < r.bottom; y++)
	{
		for(x = 0; x < r.right; x++)
		{
			float pixel;
			
			// cam = (0,0,0)
			// ray = t * (x-r.right/2, - (y-r.bottom/2), -1)
			// plane: y = -2
			
			float dx = x - cx;
			float dy = - (y - cy);
			float dz = -cx;
			float n1 = 1.0f / sqrtf(dx*dx + dy*dy + dz*dz);
			
			pixel = ray(1,0,0,0,n1*dx,n1*dy,n1*dz);
			
#if 0
			accum += pixel;
			if(accum >= 0.5f)
				accum -= 1.0f;
			else
			{
				MoveTo(x,y);
				Line(0,0);
			}
#elif 0
			accum += pixel;
			accum += accumV[x];
			if(accum >= 0.5f)
				accum -= 1.0f;
			else
			{
				MoveTo(x,y);
				Line(0,0);
			}
			accumV[x] = accum = accum / 2;
#elif 0			
			//if(pixel < Random() / 32767.0)
			if(pixel < (float)std::rand() / (32767.0f * 65536.0f))
			{
				MoveTo(x,y);
				Line(0,0);
			}
#else
			float thresh = (float)rand() / (32767.0f * 65536.0f);
			thresh = 0.5f + 0.4f * (thresh - 0.5f);
			accum += pixel;
			accum += accumV[x];
			if(accum >= thresh)
				accum -= 1.0f;
			else
			{
				MoveTo(x,y);
				Line(0,0);
			}
			accumV[x] = accum = accum / 2;			
#endif
		}
		if(Button())
			return 0;
#if TARGET_API_MAC_CARBON
		QDFlushPortBuffer(GetWindowPort(win),NULL);
#endif
	}
	long endTime = TickCount();
	
	char buf[256];
	unsigned char* pstr = (unsigned char*)buf;
	sprintf(buf+1, "pps = %d", (int)( (float)r.right * r.bottom / (endTime - startTime) * 60.0f ));
	buf[0] = strlen(buf+1);
	
	SetRect(&r, 10, 10, 10 + StringWidth(pstr) + 10, 30);
	PaintRect(&r);
	PenMode(patXor);
	FrameRect(&r);
	MoveTo(15,25);
	TextMode(srcBic);
	DrawString(pstr);
#if TARGET_API_MAC_CARBON
	QDFlushPortBuffer(GetWindowPort(win),NULL);
#endif
	
	while(!Button())
		;
	FlushEvents(everyEvent, -1);
	return 0;
}