Example #1
0
// Create a DC representing the whole screen
wxScreenDC::wxScreenDC()
{
    m_macPort = CreateNewPort() ;
    GrafPtr port ;
    GetPort( &port ) ;
    SetPort( (GrafPtr) m_macPort ) ;
    Point pt = { 0,0 } ;
    LocalToGlobal( &pt ) ;     
    SetPort( port ) ;
    m_macLocalOrigin.x = -pt.h ;
    m_macLocalOrigin.y = -pt.v ;
#if wxMAC_USE_CORE_GRAPHICS
    m_macLocalOriginInPort = m_macLocalOrigin ;
#endif
    BitMap screenBits;
    GetQDGlobalsScreenBits( &screenBits );
    m_minX = screenBits.bounds.left ;

    SInt16 height ;
    GetThemeMenuBarHeight( &height ) ;
    m_minY = screenBits.bounds.top + height ;

    m_maxX = screenBits.bounds.right  ;
    m_maxY = screenBits.bounds.bottom ;

#if wxMAC_USE_CORE_GRAPHICS
    m_graphicContext = new wxMacCGContext( port ) ;    
#else
    MacSetRectRgn( (RgnHandle) m_macBoundaryClipRgn , m_minX , m_minY , m_maxX , m_maxY ) ;
    OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
    CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
#endif
    m_ok = TRUE ;    
}
void GHOST_SystemCarbon::getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const
{
	BitMap screenBits;
	Rect bnds = GetQDGlobalsScreenBits(&screenBits)->bounds;
	width = bnds.right - bnds.left;
	height = bnds.bottom - bnds.top;
}
Example #3
0
void createWindow()
{
	int		width, height;
	int		left, top;
	Rect	rect;
	Rect	tempRect1;
	BitMap	bitMap;
	
	GetPortBounds(gGWorld, &tempRect1);
	
	width = 58 + (tempRect1.right - tempRect1.left) * 2;
	height = 230 + tempRect1.bottom - tempRect1.top;
	
	
	tempRect1 = GetQDGlobalsScreenBits(&bitMap)->bounds;
	
	left = (((tempRect1.right - tempRect1.left) - width) / 2);
	top = (((tempRect1.bottom - tempRect1.top) - height) / 2) + 20;

	SetRect( &rect, left, top, left + width, top + height );
	gWindow = NewCWindow( 0L, &rect, "\pQuickDraw Special Effects", true, noGrowDocProc,
							(WindowPtr)-1L, true, 0 );
							
	SetPortWindowPort( gWindow );
}
Example #4
0
void createWindow()
{
	Rect 	wBounds;
	BitMap	bitMap;
	Rect 	tempRect1;
	int		top, left, width, height;
	
	GetQDGlobalsScreenBits(&bitMap);
	
	width = ((bitMap.bounds.right - bitMap.bounds.left) / 2);
	height = ((bitMap.bounds.bottom - bitMap.bounds.top) / 2);

	left = (((bitMap.bounds.right - bitMap.bounds.left) - width) / 2);
	top = (((bitMap.bounds.bottom - bitMap.bounds.top) - height) / 2);
	
	/* Create a window to display the final offscreen image. */
	
	//SetRect( &wBounds, WLEFT, WTOP, WLEFT + WWIDTH, WTOP + WHEIGHT );
	SetRect( &wBounds, left, top, left + width, top + height );
	
	gWindow = NewCWindow( 0L, &wBounds, "\pSnapshot Test", false, documentProc,
							(WindowPtr)-1L, true, 0L );
							
	//SetRect( &gBounds, 0, 0, gWindow->portRect.right - gWindow->portRect.left,
	//				gWindow->portRect.bottom - gWindow->portRect.top );
	GetPortBounds(GetWindowPort(gWindow), &tempRect1);
	SetRect( &gBounds, 0, 0, tempRect1.right - tempRect1.left, 
	 tempRect1.bottom - tempRect1.top);
							
	//SetPort( gWindow );
	SetPortWindowPort( gWindow );
}
Example #5
0
void doMouseDown(EventRecord *eventStrucPtr)
{
    WindowRef      windowRef;
    WindowPartCode partCode, zoomPart;
    BitMap         screenBits;
    Rect           constraintRect, mainScreenRect;
    Point          standardStateHeightAndWidth;
    long           newSize;

    partCode = FindWindow(eventStrucPtr->where,&windowRef);

    switch(partCode)
    {
    case inMenuBar:
        break;

    case inContent:
        if(windowRef != FrontWindow())
            SelectWindow(windowRef);
        else
            doInContent(eventStrucPtr,windowRef);
        break;

    case inDrag:
        DragWindow(windowRef,eventStrucPtr->where,NULL);
        break;

    case inGoAway:
        break;

    case inGrow:
        constraintRect.top   = 75;
        constraintRect.left = 250;
        constraintRect.bottom = constraintRect.right = 32767;
        newSize = GrowWindow(windowRef,eventStrucPtr->where,&constraintRect);
        if (newSize != 0)
            SizeWindow(windowRef,LoWord(newSize),HiWord(newSize),true);
        window_adjust_scrollbars(windowRef);
        window_invalidate(windowRef);
        break;

    case inZoomIn:
    case inZoomOut:
        mainScreenRect = GetQDGlobalsScreenBits(&screenBits)->bounds;
        standardStateHeightAndWidth.v = mainScreenRect.bottom;
        standardStateHeightAndWidth.h = mainScreenRect.right;

        if(IsWindowInStandardState(windowRef,&standardStateHeightAndWidth,NULL))
            zoomPart = inZoomIn;
        else
            zoomPart = inZoomOut;

        if(TrackBox(windowRef,eventStrucPtr->where,partCode))
        {
            ZoomWindowIdeal(windowRef,zoomPart,&standardStateHeightAndWidth);
            window_adjust_scrollbars(windowRef);
        }
        break;
    }
}
Example #6
0
// Create a DC representing the whole screen
wxScreenDC::wxScreenDC()
{
#if wxMAC_USE_CORE_GRAPHICS
    CGRect cgbounds ;
    cgbounds = CGDisplayBounds(CGMainDisplayID());
    Rect bounds;
    bounds.top = (short)cgbounds.origin.y;
    bounds.left = (short)cgbounds.origin.x;
    bounds.bottom = bounds.top + (short)cgbounds.size.height;
    bounds.right = bounds.left  + (short)cgbounds.size.width;
    WindowAttributes overlayAttributes  = kWindowIgnoreClicksAttribute;
    CreateNewWindow( kOverlayWindowClass, overlayAttributes, &bounds, (WindowRef*) &m_overlayWindow );
    ShowWindow((WindowRef)m_overlayWindow);
    SetGraphicsContext( wxGraphicsContext::CreateFromNativeWindow( m_overlayWindow ) );
    m_width = (wxCoord)cgbounds.size.width;
    m_height = (wxCoord)cgbounds.size.height;
#else
    m_macPort = CreateNewPort() ;
    GrafPtr port ;
    GetPort( &port ) ;
    SetPort( (GrafPtr) m_macPort ) ;
    Point pt = { 0,0 } ;
    LocalToGlobal( &pt ) ;
    SetPort( port ) ;
    m_macLocalOrigin.x = -pt.h ;
    m_macLocalOrigin.y = -pt.v ;

    BitMap screenBits;
    GetQDGlobalsScreenBits( &screenBits );
    m_minX = screenBits.bounds.left ;

    SInt16 height ;
    GetThemeMenuBarHeight( &height ) ;
    m_minY = screenBits.bounds.top + height ;

    m_maxX = screenBits.bounds.right  ;
    m_maxY = screenBits.bounds.bottom ;

    MacSetRectRgn( (RgnHandle) m_macBoundaryClipRgn , m_minX , m_minY , m_maxX , m_maxY ) ;
    OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
    CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
#endif
    m_ok = true ;
}
Example #7
0
static void HandleMouseDown(EventRecord *pevent) {

	WindowPtr	hWnd;
	Rect		rDrag;

	switch(FindWindow(pevent->where, &hWnd)) {
		case inMenuBar:
			if (np2running) {
				soundmng_stop();
				mousemng_disable(MOUSEPROC_MACUI);
				HandleMenuChoice(MenuSelect(pevent->where));
				mousemng_enable(MOUSEPROC_MACUI);
				soundmng_play();
			}
			break;

		case inDrag:
#if TARGET_API_MAC_CARBON
		{
			BitMap	gscreenBits;
			GetQDGlobalsScreenBits(&gscreenBits);
			rDrag = gscreenBits.bounds;
			InsetRect(&rDrag, DRAG_THRESHOLD, DRAG_THRESHOLD);
			DragWindow(hWnd, pevent->where, &rDrag);
		}
#else
			rDrag = qd.screenBits.bounds;
			InsetRect(&rDrag, DRAG_THRESHOLD, DRAG_THRESHOLD);
			DragWindow(hWnd, pevent->where, &rDrag);
#endif
			break;

		case inContent:
			mousemng_buttonevent((pevent->modifiers & (1 << 12))
									?MOUSEMNG_RIGHTDOWN:MOUSEMNG_LEFTDOWN);
			break;

		case inGoAway:
			if (TrackGoAway(hWnd, pevent->where)) { }
			np2running = FALSE;
			break;
	}
}
void createWindow()
{
	Rect		rect;
	BitMap		bitMap;
	Rect		tempRect1;
	int			top, left;
	
	GetQDGlobalsScreenBits(&bitMap);
	tempRect1 = bitMap.bounds;
	
	left = (((tempRect1.right - tempRect1.left) - WWIDTH) / 2);
	top = (((tempRect1.bottom - tempRect1.top) - WHEIGHT) / 2);

	//SetRect( &rect, WLEFT, WTOP, WLEFT + WWIDTH, WTOP + WHEIGHT );
	SetRect( &rect, left, top, left + WWIDTH, top + WHEIGHT );
	gWindow = NewCWindow( 0L, &rect, "\pDirect Pixel Access", true, documentProc,
							(WindowPtr)-1L, true, 0L );						
	//SetPort( gWindow );
	SetPortWindowPort( gWindow );
	
	TextFont( kFontIDGeneva );
	TextSize( 9 );
	TextMode( srcXor );
}
Example #9
0
void createWindow()
{
	Rect rect;
	
	BitMap	bitMap;
	int	top, left;
	
	GetQDGlobalsScreenBits(&bitMap);
	
	top = (((bitMap.bounds.bottom - bitMap.bounds.top) - WHEIGHT) / 2);
	left = (((bitMap.bounds.right - bitMap.bounds.left) - WWIDTH) / 2);
	
	//SetRect( &rect, WLEFT, WTOP, WLEFT + WWIDTH, WTOP + WHEIGHT );
	SetRect( &rect, left, top, left + WWIDTH, top + WHEIGHT );
	
	gWindow = NewCWindow( 0L, &rect, "\pMyDeviceLoop", true, documentProc,
							(WindowPtr)-1L, true, 0L );						
	//SetPort( gWindow );
	SetPortWindowPort( gWindow );
	
	TextFont( kFontIDTimes );
	TextSize( 48 );
	TextMode( srcCopy );
}
Example #10
0
static void mac_event(EventRecord *event) {
    short part;
    WindowPtr window;

    switch (event->what) {
      case mouseDown:
	part = FindWindow(event->where, &window);
	switch (part) {
	  case inMenuBar:
	    mac_adjustmenus();
	    mac_menucommand(MenuSelect(event->where));
	    break;
#if !TARGET_API_MAC_CARBON
	  case inSysWindow:
	    SystemClick(event, window);
	    break;
#endif
	  case inContent:
	    if (window != FrontWindow())
	    	/* XXX: check for movable modal dboxes? */
		SelectWindow(window);
	    else
		mac_contentclick(window, event);
	    break;
	  case inGoAway:
	    if (TrackGoAway(window, event->where))
		mac_closewindow(window);
	    break;
	  case inDrag:
	    /* XXX: moveable modal check? */
#if TARGET_API_MAC_CARBON
	    {
		BitMap screenBits;

		GetQDGlobalsScreenBits(&screenBits);
		DragWindow(window, event->where, &screenBits.bounds);
	    }
#else
	    DragWindow(window, event->where, &qd.screenBits.bounds);
#endif
	    break;
	  case inGrow:
	    mac_growwindow(window, event);
	    break;
	  case inZoomIn:
	  case inZoomOut:
	    if (TrackBox(window, event->where, part))
		mac_zoomwindow(window, part);
	    break;
	}
	break;
      case keyDown:
      case autoKey:
        mac_keypress(event);
        break;
      case activateEvt:
	mac_activatewindow((WindowPtr)event->message, event);
        break;
      case updateEvt:
        mac_updatewindow((WindowPtr)event->message);
        break;
#if !TARGET_API_MAC_CARBON
      case diskEvt:
	if (HiWord(event->message) != noErr) {
	    Point pt;

	    SetPt(&pt, 120, 120);
	    DIBadMount(pt, event->message);
        }
        break;
#endif
      case osEvt:
	switch ((event->message & osEvtMessageMask) >> 24) {
	  case suspendResumeMessage:
	    mac_suspendresume(event);
	    break;
	}
	break;
      case kHighLevelEvent:
	AEProcessAppleEvent(event); /* errors? */
	break;
    }
}
bool GHOST_SystemCarbon::handleMouseDown(EventRef event)
{
	WindowPtr window;
	short part;
	BitMap screenBits;
	bool handled = true;
	GHOST_WindowCarbon *ghostWindow;
	Point mousePos = {0, 0};
	
	::GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &mousePos);
	
	part = ::FindWindow(mousePos, &window);
	ghostWindow = (GHOST_WindowCarbon *) ::GetWRefCon(window);
	
	switch (part) {
		case inMenuBar:
			handleMenuCommand(::MenuSelect(mousePos));
			break;
			
		case inDrag:
			/*
			 * The DragWindow() routine creates a lot of kEventWindowBoundsChanged
			 * events. By setting m_ignoreWindowSizedMessages these are suppressed.
			 * \see GHOST_SystemCarbon::handleWindowEvent(EventRef event)
			 */
			/* even worse: scale window also generates a load of events, and nothing 
			 * is handled (read: client's event proc called) until you release mouse (ton) */
			
			GHOST_ASSERT(validWindow(ghostWindow), "GHOST_SystemCarbon::handleMouseDown: invalid window");
			m_ignoreWindowSizedMessages = true;
			::DragWindow(window, mousePos, &GetQDGlobalsScreenBits(&screenBits)->bounds);
			m_ignoreWindowSizedMessages = false;
			
			pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowMove, ghostWindow) );

			break;
		
		case inContent:
			if (window != ::FrontWindow()) {
				::SelectWindow(window);
				/*
				 * We add a mouse down event on the newly actived window
				 */		
				//GHOST_PRINT("GHOST_SystemCarbon::handleMouseDown(): adding mouse down event, " << ghostWindow << "\n");
				EventMouseButton button;
				::GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(button), NULL, &button);
				pushEvent(new GHOST_EventButton(getMilliSeconds(), GHOST_kEventButtonDown, ghostWindow, convertButton(button)));
			}
			else {
				handled = false;
			}
			break;
			
		case inGoAway:
			GHOST_ASSERT(ghostWindow, "GHOST_SystemCarbon::handleMouseEvent: ghostWindow==0");
			if (::TrackGoAway(window, mousePos))
			{
				// todo: add option-close, because it's in the HIG
				// if (event.modifiers & optionKey) {
				// Close the clean documents, others will be confirmed one by one.
				//}
				// else {
				pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowClose, ghostWindow));
				//}
			}
			break;
			
		case inGrow:
			GHOST_ASSERT(ghostWindow, "GHOST_SystemCarbon::handleMouseEvent: ghostWindow==0");
			::ResizeWindow(window, mousePos, NULL, NULL);
			break;
			
		case inZoomIn:
		case inZoomOut:
			GHOST_ASSERT(ghostWindow, "GHOST_SystemCarbon::handleMouseEvent: ghostWindow==0");
			if (::TrackBox(window, mousePos, part)) {
				int macState;
				
				macState = ghostWindow->getMac_windowState();
				if (macState == 0)
					::ZoomWindow(window, part, true);
				else 
				if (macState == 2) {     // always ok
					::ZoomWindow(window, part, true);
					ghostWindow->setMac_windowState(1);
				}
				else {       // need to force size again
					//	GHOST_TUns32 scr_x,scr_y; /*unused*/
					Rect outAvailableRect;
						
					ghostWindow->setMac_windowState(2);
					::GetAvailableWindowPositioningBounds(GetMainDevice(), &outAvailableRect);
						
					//this->getMainDisplayDimensions(scr_x,scr_y);
					::SizeWindow(window, outAvailableRect.right - outAvailableRect.left, outAvailableRect.bottom - outAvailableRect.top - 1, false);
					::MoveWindow(window, outAvailableRect.left, outAvailableRect.top, true);
				}
				
			}
			break;

		default:
			handled = false;
			break;
	}
	
	return handled;
}
Example #12
0
int main( void )
{
	long	result = 0;
	
	// initialize for carbon & QuickTime
	InitCursor();
	if ( IsQuickTimeInstalled() )
		EnterMovies();
	else
		goto bail;
		
	GetQDGlobalsScreenBits( &screenBits );
	
	Gestalt(gestaltMenuMgrAttr, &result);
	if (result & gestaltMenuMgrAquaLayoutMask) {
		// Mmmmmm...X
		SetMenuBar(GetNewMBar(129));
		if (AEInstallEventHandler( kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(doAEQuit), 0, false))
			goto bail;
	} else {
		SetMenuBar(GetNewMBar(128));
	}
	DrawMenuBar();
	
	while (gDone == false) {
		EventRecord theEvent;
		WindowPtr pWhichWindow;		
		short windowPart;
        Boolean SIOUXHandledEvent = false;
		
		WaitNextEvent(everyEvent, &theEvent, 0, NULL);
		
        #ifndef __MACH__
            SIOUXHandledEvent = SIOUXHandleOneEvent(&theEvent);
        #endif
        
		if ( !SIOUXHandledEvent ) {
		
			switch (theEvent.what) {
				case updateEvt:
					pWhichWindow = (WindowPtr)theEvent.message;
					
					// we don't do anything for this simple sample
					BeginUpdate(pWhichWindow);
					EndUpdate(pWhichWindow);
					break;
				
				case keyDown:
					if (theEvent.modifiers & cmdKey) {
						doMenu(MenuKey(theEvent.message & charCodeMask));
					}
					break;
				
				case mouseDown:
					windowPart = FindWindow(theEvent.where, &pWhichWindow);

					switch (windowPart) {
						case inDrag:
							DragWindow(pWhichWindow, theEvent.where, &screenBits.bounds);
							break;

						case inGoAway:
							if (TrackGoAway(pWhichWindow, theEvent.where))
								DisposeWindow( pWhichWindow );
								//gDone = true;
							break;

						case inContent:
							SelectWindow(pWhichWindow);
							break;

						case inMenuBar:
							doMenu(MenuSelect(theEvent.where));
							break;
					}
					break;
			}
		}
	}
	
bail:

	return 0;	
}
Example #13
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;
}