Ejemplo n.º 1
0
void GBWindow::Update(bool running) {
#if MAC
	GrafPtr savePort;
	GetPort(&savePort);
	SetPort(GetWindowPort(window));
	if ( view->NeedsResize() )
		ResizeSelf();
	if ( view->NeedsRedraw(running) ) {
		BeginUpdate(window);
		EndUpdate(window);
		if ( showGrowBox ) DrawGrowIcon(window);
		view->DoDraw();
	} else {
		BeginUpdate(window);
		if ( showGrowBox ) DrawGrowIcon(window);
		view->DoDraw();
		EndUpdate(window);
	}
	SetPort(savePort);
#elif WINDOWS
	PAINTSTRUCT paint;
	HDC dc = BeginPaint(win, &paint);
	GBGraphics graphics(dc);
	view->SetGraphics(&graphics);
	view->DoDraw();
	EndPaint(win, &paint);
#endif
}
Ejemplo n.º 2
0
Archivo: ugView.c Proyecto: rolk/ug
static void RefreshCommand (void)
{
  int error;
  FILE *stream;

  if (globalState!=OPENED) return;

  /* set volume */
  error = SetVol(NULL,vRefNum);
  if (((int)error)!=0)
  {
    OneButtonBox("Could not set volume","OK");
    return;
  }

  stream = fopen(fileName,"rb");
  if (stream==NULL)
  {
    OneButtonBox("Could not open file","OK");
    return;
  }

  /* draw something */
  RasterizeFile(stream,&myWindow,fx,fy);
  fclose(stream);

  DrawGrowIcon(myWindow.theWindow);
  DrawControls(myWindow.theWindow);

  return;
}
Ejemplo n.º 3
0
Archivo: MacGraph.c Proyecto: rolk/ug
static INT GraphOpen (GRAPH_WINDOW *gw, const char *title, short h, short v, short dh, short dv)
{
  WindowPtr MacWin;
  GrafPtr myPort;
  PaletteHandle myPalette;
  Str255 pstr;

  MacWin = MAC_WIN(gw);

  /* read in resources */
  if (GetNewCWindow(GRAPH_RSRC_ID,(Ptr) MacWin,(WindowPtr) -1)==NULL)
    return (1);

  myPalette = GetNewPalette(PALETTE_RSRC_ID);
  SetPalette(MacWin,myPalette,FALSE);

  /* move and size window */
  myPort = (GrafPtr) MacWin;
  SetPort(myPort);
  MoveWindow(MacWin,h,v,false);
  SizeWindow(MacWin,dh,dv,false);
  CopyCStringToPascal(title,pstr);
  SetWTitle(MacWin,pstr);
  ShowWindow(MacWin);
  SelectWindow(MacWin);
  DrawGrowIcon(MacWin);

  return (0);
}
Ejemplo n.º 4
0
void doUpdateWindow(EventRecord *eventStrucPtr)
{
    IMAGE *img;
    WindowRef    windowRef;
    Rect         srcRect, destRect, fillRect;
    PixMapHandle srcPixmapHdl, destPixmapHdl;
    RGBColor     grayColour = { 0xC000,0xC000,0xC000 };
    SInt32  hScroll, vScroll;

    windowRef = (WindowRef) eventStrucPtr->message;
    img = (IMAGE*)GetWRefCon(windowRef);
    srcPixmapHdl = img->pixmapHdl;
    destPixmapHdl = GetPortPixMap(GetWindowPort(windowRef));
    hScroll = GetControl32BitValue(img->scrollbarHorizRef);
    vScroll = GetControl32BitValue(img->scrollbarVertRef);

    if (srcPixmapHdl)
    {
        PixMap *pixmap = *srcPixmapHdl;
        PixPatHandle hdlPixPat = NewPixPat();
        MakeRGBPat(hdlPixPat, &grayColour);

        GetWindowPortBounds(windowRef,&destRect);
        destRect.right  -= kScrollBarWidth;
        destRect.bottom -= kScrollBarWidth;

        if (destRect.right > pixmap->bounds.right)
        {
            fillRect.top = destRect.top;
            fillRect.bottom = destRect.bottom;
            fillRect.left = pixmap->bounds.right;
            fillRect.right = destRect.right;
            FillCRect(&fillRect, hdlPixPat);
            destRect.right = pixmap->bounds.right;
        }
        if (destRect.bottom > pixmap->bounds.bottom)
        {
            fillRect.top = pixmap->bounds.bottom;
            fillRect.bottom = destRect.bottom;
            fillRect.left = destRect.left;
            fillRect.right = destRect.right;
            FillCRect(&fillRect, hdlPixPat);
            destRect.bottom = pixmap->bounds.bottom;
        }
        DisposePixPat(hdlPixPat);

        srcRect = destRect;
        srcRect.left += hScroll;
        srcRect.right += hScroll;
        srcRect.top += vScroll;
        srcRect.bottom += vScroll;

        CopyBits((BitMap*)*srcPixmapHdl, (BitMap*)*destPixmapHdl,
                 &srcRect, &destRect, srcCopy, NULL);
    }

    DrawGrowIcon(windowRef);
}
Ejemplo n.º 5
0
Archivo: ugView.c Proyecto: rolk/ug
static int CreateApplicationWindow (AWindowRecord *wr, char *fname, short h, short v, short dh, short dv)
{
  Rect r;
  GrafPtr myPort;
  PaletteHandle myPalette;
  char name[80];

  /* init AWindowRecord */
  wr->theWindow = (WindowPtr) wr;

  /* read in resources */
  if (GetNewCWindow(appWinId,(Ptr)wr,(WindowPtr) -1)==NULL)
  {
    return(1);
  }
  myPalette = GetNewPalette(defaultPaletteId);
  SetPalette(wr->theWindow,myPalette,false);

  /* move and size window */
  myPort = (GrafPtr) wr->theWindow;
  SetPort(myPort);
  MoveWindow(wr->theWindow,h,v,false);
  SizeWindow(wr->theWindow,dh+15,dv+15,false);
  strcpy(name,fname);
  SetWTitle(wr->theWindow,c2pstr(name));
  ShowWindow(wr->theWindow);
  SelectWindow(wr->theWindow);
  DrawGrowIcon(wr->theWindow);
  r = myPort->portRect;

  TextFont(kFontIDMonaco);

  /* get the scroll bars */
  wr->vScrollBar = GetNewControl(vScrollBarId,wr->theWindow);
  wr->hScrollBar = GetNewControl(hScrollBarId,wr->theWindow);

  /* set correct size of the scroll bars */
  MoveControl(wr->vScrollBar,r.right-15,-1);
  SizeControl(wr->vScrollBar,16,r.bottom-13);
  SetControlMinimum(wr->vScrollBar,0);
  SetControlMaximum(wr->vScrollBar,0);
  SetControlValue(wr->vScrollBar,0);
  ShowControl(wr->vScrollBar);
  MoveControl(wr->hScrollBar,-1,r.bottom-15);
  SizeControl(wr->hScrollBar,r.right-13,16);
  SetControlMinimum(wr->hScrollBar,0);
  SetControlMaximum(wr->hScrollBar,0);
  SetControlValue(wr->hScrollBar,0);
  ShowControl(wr->hScrollBar);
  DrawControls(wr->theWindow);

  SetRect(&(wr->usableRect),0,0,dh,dv);

  return(0);
}
Ejemplo n.º 6
0
void DrawWindow(WindowRef window)
{
    GrafPtr		curPort;
	
    GetPort(&curPort);
    SetPort(GetWindowPort(window));
    BeginUpdate(window);

    DrawControls(window);
    DrawGrowIcon(window);
    EndUpdate(window);
    SetPort(curPort);
}
Ejemplo n.º 7
0
void DrawWindow(WindowRef window)
{
    Rect		tempRect;
    GrafPtr		curPort;
	
    GetPort(&curPort);
    SetPort(GetWindowPort(window));
    BeginUpdate(window);
    EraseRect(GetWindowPortBounds(window, &tempRect));
    DrawControls(window);
    DrawGrowIcon(window);
    EndUpdate(window);
    SetPort(curPort);
}
Ejemplo n.º 8
0
void doEvents(EventRecord *eventStrucPtr)
{
    WindowRef      windowRef;

    if (eventStrucPtr->what == mouseDown &&
        FindWindow(eventStrucPtr->where,&windowRef) == inMenuBar)
        SelectWindow(SIOUXTextWindow->window);

    SIOUXSettings.standalone = true;
    if (SIOUXHandleOneEvent(eventStrucPtr))
    {
        if (SIOUXQuitting)
            gDone = true;
        SIOUXSettings.standalone = false;
        return;
    }
    SIOUXSettings.standalone = false;

    switch(eventStrucPtr->what)
    {
    case kHighLevelEvent:
        AEProcessAppleEvent(eventStrucPtr);
        break;

    case mouseDown:
        doMouseDown(eventStrucPtr);
        break;

    case keyDown:
    case autoKey:
        break;

    case updateEvt:
        doUpdate(eventStrucPtr);
        break;

    case activateEvt:
        DrawGrowIcon(windowRef);
        break;

    case osEvt:
        doOSEvent(eventStrucPtr);
        break;
    }
}
Ejemplo n.º 9
0
Archivo: MacGraph.c Proyecto: rolk/ug
static INT ActivateMacWin (GRAPH_WINDOW *gw, INT tool)
{
  WindowPtr MacWindow;

  MacWindow = MAC_WIN(gw);

  DrawGrowIcon(MacWindow);
  SetPort(GetWindowPort(MacWindow));

  switch (tool)
  {
  case arrowTool :         SetMyCursor(arrowCurs);         break;
  case crossTool :         SetMyCursor(crossCurs);         break;
  case choiceTool :        SetMyCursor(choiceCurs);        break;
  case circleTool :        SetMyCursor(circleCurs);        break;
  case handTool :          SetMyCursor(handCurs);          break;
  case heartTool :         SetMyCursor(heartCurs);         break;
  case gnoedelTool :       SetMyCursor(gnoedelCurs);       break;
  }

  return (0);
}
Ejemplo n.º 10
0
Archivo: MacGraph.c Proyecto: rolk/ug
INT Mac_UpdateOutput (WINDOWID win, INT tool)
{
  GRAPH_WINDOW *gw;
  WindowPtr theWindow;
  Rect myClipRect,*portRect = nil;

  gw = (GRAPH_WINDOW *) win;
  theWindow = MAC_WIN(gw);

  gw->currTool = tool;

  SetPort(GetWindowPort(theWindow));

  /* identify clipping rect with port */
  GetPortBounds(GetWindowPort(theWindow),portRect);
  ClipRect(portRect);

  BeginUpdate(theWindow);
  /* leave this out: uginterface will manage
     EraseRgn(((GrafPtr)theWindow)->visRgn);*/
  EndUpdate(theWindow);

  /* adjust cursor */
  if (theWindow == FrontWindow())
    ActivateMacWin (gw,tool);

  DrawGrowIcon(theWindow);
  DrawToolBox(gw,tool);

  /* reset clipping rectangle */
  myClipRect.left   = portRect->left;
  myClipRect.right  = portRect->right  - SCROLL_BAR;
  myClipRect.bottom = portRect->bottom - SCROLL_BAR;
  myClipRect.top    = portRect->top;

  ClipRect(&myClipRect);

  return (0);
}
Ejemplo n.º 11
0
static void mac_draweventloggrowicon(Session *s)
{
    Rect clip;
    RgnHandle savergn;

    SetPort((GrafPtr)GetWindowPort(s->eventlog_window));
    /*
     * Stop DrawGrowIcon giving us space for a horizontal scrollbar
     * See Tech Note TB575 for details.
     */
#if TARGET_API_MAC_CARBON
    GetPortBounds(GetWindowPort(s->eventlog_window), &clip);
#else
    clip = s->eventlog_window->portRect;
#endif
    clip.left = clip.right - 15;
    savergn = NewRgn();
    GetClip(savergn);
    ClipRect(&clip);
    DrawGrowIcon(s->eventlog_window);
    SetClip(savergn);
    DisposeRgn(savergn);
}
Ejemplo n.º 12
0
void
TkpDisplayScrollbar(
    ClientData clientData)	/* Information about window. */
{
    register TkScrollbar *scrollPtr = (TkScrollbar *) clientData;
    register MacScrollbar *macScrollPtr = (MacScrollbar *) clientData;
    register Tk_Window tkwin = scrollPtr->tkwin;
    
    MacDrawable *macDraw;
    CGrafPtr saveWorld;
    GDHandle saveDevice;
    GWorldPtr destPort;
    WindowRef windowRef;
    
    if ((scrollPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
	goto done;
    }

    /*
     * Draw the focus or any 3D relief we may have.
     */
    if (scrollPtr->highlightWidth != 0) {
	GC fgGC, bgGC;

	bgGC = Tk_GCForColor(scrollPtr->highlightBgColorPtr,
		Tk_WindowId(tkwin));

	if (scrollPtr->flags & GOT_FOCUS) {
	    fgGC = Tk_GCForColor(scrollPtr->highlightColorPtr,
		    Tk_WindowId(tkwin));
	    TkpDrawHighlightBorder(tkwin, fgGC, bgGC, scrollPtr->highlightWidth,
		Tk_WindowId(tkwin));
	} else {
	    TkpDrawHighlightBorder(tkwin, bgGC, bgGC, scrollPtr->highlightWidth,
		Tk_WindowId(tkwin));
	}
    }
    Tk_Draw3DRectangle(tkwin, Tk_WindowId(tkwin), scrollPtr->bgBorder,
	    scrollPtr->highlightWidth, scrollPtr->highlightWidth,
	    Tk_Width(tkwin) - 2*scrollPtr->highlightWidth,
	    Tk_Height(tkwin) - 2*scrollPtr->highlightWidth,
	    scrollPtr->borderWidth, scrollPtr->relief);

    /*
     * Set up port for drawing Macintosh control.
     */
    macDraw = (MacDrawable *) Tk_WindowId(tkwin);
    destPort = TkMacGetDrawablePort(Tk_WindowId(tkwin));
    GetGWorld(&saveWorld, &saveDevice);
    SetGWorld(destPort, NULL);
    TkMacSetUpClippingRgn(Tk_WindowId(tkwin));

    if (macScrollPtr->sbHandle == NULL) {
        Rect r;
        WindowRef frontNonFloating;
        
        r.left = r.top = 0;
        r.right = r.bottom = 1;
	macScrollPtr->sbHandle = NewControl((WindowRef) destPort, &r, "\p",
		false, (short) 500, 0, 1000,
		scrollBarProc, (SInt32) scrollPtr);

	/*
	 * If we are foremost than make us active.
	 */
	
	if (TkMacHaveAppearance() >= 0x110) {
	    frontNonFloating = FrontNonFloatingWindow();
	} else {
	    frontNonFloating = FrontWindow();
	}
	
	if ((WindowPtr) destPort == FrontWindow() || TkpIsWindowFloating((WindowPtr) destPort)) {
	    macScrollPtr->macFlags |= ACTIVE;
	}
    }

    /*
     * Update the control values before we draw.
     */
    windowRef  = (**macScrollPtr->sbHandle).contrlOwner;    
    UpdateControlValues(macScrollPtr);
    
    if (macScrollPtr->macFlags & ACTIVE) {
	Draw1Control(macScrollPtr->sbHandle);
	if (macScrollPtr->macFlags & DRAW_GROW) {
	    DrawGrowIcon(windowRef);
	}
    } else {
	(**macScrollPtr->sbHandle).contrlHilite = 255;
	Draw1Control(macScrollPtr->sbHandle);
	if (macScrollPtr->macFlags & DRAW_GROW) {
	    DrawGrowIcon(windowRef);
	    Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin), scrollPtr->bgBorder,
		Tk_Width(tkwin) - 13, Tk_Height(tkwin) - 13,
		Tk_Width(tkwin), Tk_Height(tkwin),
		0, TK_RELIEF_FLAT);
	}
    }
    
    SetGWorld(saveWorld, saveDevice);
     
    done:
    scrollPtr->flags &= ~REDRAW_PENDING;
}
Ejemplo n.º 13
0
static void update_DocWin()
{
	SetPortWindowPort(win.ref);
	DrawGrowIcon(win.ref);
	TEUpdate(&win.ref->portRect, gDocTE);
}
Ejemplo n.º 14
0
static void update_ListWin()
{
	SetPortWindowPort(win.ref);
	LUpdate( win.ref->visRgn, gPlaylist);
	DrawGrowIcon(win.ref);
}
void init()
{
	RgnHandle			tempRgn;
	Rect				BaseRect;
	OSErr				err;
	long				QDfeature/*, OSfeature*/;
	GDHandle			SaveGD;
	CGrafPtr			SavePort;

	/*	Initialize Managaer.	*/
	//InitGraf(&qd.thePort);
	//InitWindows();
	//InitDialogs(nil);
	InitCursor();
	FlushEvents(everyEvent, 0);
	
	/*	Set up menus.	*/
	mymenu0 = GetMenu(appleID);
	//AppendResMenu(mymenu0, 'DRVR');
	InsertMenu(mymenu0,0);
	mymenu1 = GetMenu(fileID);
	InsertMenu(mymenu1,0);
	DrawMenuBar();
	DoneFlag = false;
	ThePict = GetPicture(PictID);
	if (ThePict == nil)
		DoneFlag = true;

	/*	Use Gestalt to find is QuickDraw is avaiable.	*/
	/*if ((GetOSTrapAddress(Gestalttest) != GetOSTrapAddress(NoTrap))) {
		err = Gestalt(gestaltQuickdrawVersion, &QDfeature);
		if (err)
			DoneFlag = true;
		err = Gestalt(gestaltSystemVersion, &OSfeature);
		if (err)
			DoneFlag = true;
		if (!DoneFlag && (QDfeature & 0x0f00) != 0x0200 && OSfeature < 0x0605)
			DoneFlag = true;
		}
	else
		DoneFlag = true;*/
	
	err = Gestalt(gestaltQuickdrawVersion, &QDfeature);
	if (err != noErr || QDfeature < gestalt32BitQD)
		DoneFlag = true;

	/*	Set Rects.	*/
	SetRect(&BaseRect, 40, 60, 472, 282);
	SetRect(&WinMinusScroll, BaseRect.left-40, BaseRect.top-60, BaseRect.right-60, 
				BaseRect.bottom - 80);
	SetRect(&InitWindowSize, WinMinusScroll.left, WinMinusScroll.top, 
							WinMinusScroll.right, WinMinusScroll.bottom);
	tempRgn = GetGrayRgn();
	HLock ((Handle) tempRgn);
	//TotalRect = (**tempRgn).rgnBBox;
	GetRegionBounds(tempRgn, &TotalRect);
	/*SetRect(&minRect, 80, 80, (**tempRgn).rgnBBox.right - 40, 
				(**tempRgn).rgnBBox.bottom - 40);*/
	SetRect(&minRect, 80, 80, TotalRect.right - 40, TotalRect.bottom - 40);
	HUnlock ((Handle) tempRgn);

	/*	Open window and set up picture.	*/
	GetGWorld (&SavePort, &SaveGD);
	mycolors = GetCTable (clutID);
	(*mycolors)->ctFlags |= 0x4000;

	myWindow = NewCWindow(nil, &BaseRect, (ConstStr255Param)"", true, zoomDocProc, 
							(WindowPtr) -1, true, 150);
	SetGWorld(GetWindowPort(myWindow), SaveGD);
	DrawGrowIcon (myWindow);

	srcPalette = NewPalette (((**mycolors).ctSize)+1, mycolors,
			pmTolerant + pmExplicit + pmAnimated, 0);
	SetPalette ((WindowPtr) myWindow, srcPalette, true);
	
	GetGWorld (&SavePort, &SaveGD);
	err = NewGWorld (&offscreenGWorld, 8, &InitWindowSize, mycolors, nil, 0);
	if (err)
		Debugger();
	SetGWorld (offscreenGWorld, nil);
	EraseRect (&InitWindowSize);
	DrawPicture (ThePict, &InitWindowSize);
	SetGWorld (SavePort, SaveGD);
}
Ejemplo n.º 16
0
void
TkpDisplayScrollbar(
    ClientData clientData)        /* Information about window. */
{
    TkScrollbar *scrollPtr = (TkScrollbar *) clientData;
    MacScrollbar *macScrollPtr = (MacScrollbar *) clientData;
    Tk_Window tkwin = scrollPtr->tkwin;
    
    MacDrawable *macDraw;
    CGrafPtr saveWorld;
    GDHandle saveDevice;
    GWorldPtr destPort;
    WindowRef windowRef;
    
    if ((scrollPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
        goto done;
    }

    /*
     * Draw the focus or any 3D relief we may have.
     */
    if (scrollPtr->highlightWidth != 0) {
        GC fgGC, bgGC;

        bgGC = Tk_GCForColor(scrollPtr->highlightBgColorPtr,
            Tk_WindowId(tkwin));

        if (scrollPtr->flags & GOT_FOCUS) {
            fgGC = Tk_GCForColor(scrollPtr->highlightColorPtr,
                Tk_WindowId(tkwin));
            TkpDrawHighlightBorder(tkwin, fgGC, bgGC, scrollPtr->highlightWidth,
                Tk_WindowId(tkwin));
        } else {
            TkpDrawHighlightBorder(tkwin, bgGC, bgGC, scrollPtr->highlightWidth,
                Tk_WindowId(tkwin));
        }
    }
    Tk_Draw3DRectangle(tkwin, Tk_WindowId(tkwin), scrollPtr->bgBorder,
        scrollPtr->highlightWidth, scrollPtr->highlightWidth,
        Tk_Width(tkwin) - 2*scrollPtr->highlightWidth,
        Tk_Height(tkwin) - 2*scrollPtr->highlightWidth,
        scrollPtr->borderWidth, scrollPtr->relief);

    /*
     * Set up port for drawing Macintosh control.
     */
    macDraw = (MacDrawable *) Tk_WindowId(tkwin);
    destPort = TkMacOSXGetDrawablePort(Tk_WindowId(tkwin));
    GetGWorld(&saveWorld, &saveDevice);
    SetGWorld(destPort, NULL);
    TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin));

    if (macScrollPtr->sbHandle == NULL) {
        Rect r;
        SInt16 initialValue;
        SInt16 minValue;
        SInt16 maxValue;
        SInt16 procID;
        WindowRef frontNonFloating;
        
        r.left = r.top = 0;
        r.right = r.bottom = 1;

        minValue = MIN_SCROLLBAR_VALUE;
        maxValue = MAX_SCROLLBAR_VALUE;
        initialValue = (minValue + maxValue)/2;
        procID = kControlScrollBarLiveProc;

        windowRef = GetWindowFromPort(destPort);
        CreateScrollBarControl(windowRef, &r, initialValue,
                                minValue, maxValue,
                                maxValue - minValue, true,
                                NULL, &(macScrollPtr->sbHandle));
        SetControlReference(macScrollPtr->sbHandle, (SInt32) scrollPtr);
        
        /*
         * If we are foremost then make us active.
         */
        
        frontNonFloating = FrontNonFloatingWindow();
        
        if ((windowRef == FrontWindow()) || TkpIsWindowFloating(windowRef)) {
            macScrollPtr->macFlags |= ACTIVE;
        }
    }

    /*
     * Adjust the control size based on its width...
     */

    if (macScrollPtr->info.width < 13) {
        SetControlData(macScrollPtr->sbHandle, kControlNoPart, kControlSizeTag,
                sizeof(kControlSizeSmall), (void *) kControlSizeSmall);
    } else {
        SetControlData(macScrollPtr->sbHandle, kControlNoPart, kControlSizeTag,
                sizeof(kControlSizeSmall), (void *) kControlSizeLarge);
    }        
    
    /*
     * Update the control values before we draw.
     */
    windowRef  = GetControlOwner (macScrollPtr->sbHandle);
    UpdateControlValues(macScrollPtr);
    
    if (macScrollPtr->macFlags & ACTIVE) {
        Draw1Control(macScrollPtr->sbHandle);
        if (macScrollPtr->macFlags & DRAW_GROW) {
            DrawGrowIcon(windowRef);
        }
    } else {
        HiliteControl (macScrollPtr->sbHandle, 255 );
        Draw1Control(macScrollPtr->sbHandle);
        if (macScrollPtr->macFlags & DRAW_GROW) {
            DrawGrowIcon(windowRef);
            Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin), scrollPtr->bgBorder,
                Tk_Width(tkwin) - 13, Tk_Height(tkwin) - 13,
                Tk_Width(tkwin), Tk_Height(tkwin),
                0, TK_RELIEF_FLAT);
        }
    }
    
    SetGWorld(saveWorld, saveDevice);
     
    done:
    scrollPtr->flags &= ~REDRAW_PENDING;
}
Ejemplo n.º 17
0
int main(int  argc, char *argv[])
{
	AGLPixelFormat		format;		/* OpenGL pixel format */
	WindowPtr		window;		/* Window */
	int			winattrs;	/* Window attributes */
	Str255			title;		/* Title of window */
	Rect			rect;		/* Rectangle definition */
	EventHandlerUPP		handler;	/* Event handler */
	EventLoopTimerUPP	thandler;	/* Timer handler */
	EventLoopTimerRef	timer;		/* Timer for animating the window */
	ProcessSerialNumber	psn;		/* Process serial number */

	static EventTypeSpec	events[] =	/* Events we are interested in... */
			{
			  { kEventClassMouse, kEventMouseDown },
			  { kEventClassMouse, kEventMouseUp },
			  { kEventClassMouse, kEventMouseMoved },
			  { kEventClassMouse, kEventMouseDragged },
			  { kEventClassWindow, kEventWindowDrawContent },
			  { kEventClassWindow, kEventWindowShown },
			  { kEventClassWindow, kEventWindowHidden },
			  { kEventClassWindow, kEventWindowActivated },
			  { kEventClassWindow, kEventWindowDeactivated },
			  { kEventClassWindow, kEventWindowClose },
			  { kEventClassWindow, kEventWindowBoundsChanged },
			  { kCoreEventClass, kAEOpenApplication }
			};
	
	static GLint 		attributes[] =	/* OpenGL attributes */
			{
			  AGL_RGBA,
			  AGL_GREEN_SIZE, 1,
			  AGL_DOUBLEBUFFER,
			  AGL_DEPTH_SIZE, 16,
			  AGL_NONE
			};

	//Set initial values for window
	const int		        origWinHeight = 628;
	const int		        origWinWidth  = 850;
	const int		        origWinXOffset = 50;
	const int		        origWinYOffset = 50;


	// Create the window...

	aglContext = 0;
	WindowVisible = 0;

	SetRect(&rect, origWinXOffset, origWinYOffset, origWinWidth, origWinHeight);

	winattrs =	kWindowStandardHandlerAttribute | kWindowCloseBoxAttribute |
			kWindowCollapseBoxAttribute | kWindowFullZoomAttribute |
			kWindowResizableAttribute | kWindowLiveResizeAttribute;
	winattrs &= GetAvailableWindowAttributes(kDocumentWindowClass);

	strcpy((char *)(title + 1), "Rigid Body Dynamics");
	title[0] = strlen((char *)(title + 1));

	CreateNewWindow(kDocumentWindowClass, winattrs, &rect, &window);
	SetWTitle(window, title);

	handler = NewEventHandlerUPP(EventHandler);
	InstallWindowEventHandler(window, handler, sizeof(events) / sizeof(events[0]), events, NULL, 0L);
	thandler = NewEventLoopTimerUPP((void (*)(EventLoopTimerRef, void *))IdleFunc);
	InstallEventLoopTimer(GetMainEventLoop(), 0, 0, thandler, 0, &timer);

	GetCurrentProcess(&psn);
	SetFrontProcess(&psn);

	DrawGrowIcon(window);
	ShowWindow(window);

	// Create the OpenGL context and bind it to the window...
	format     = aglChoosePixelFormat(NULL, 0, attributes);
	aglContext = aglCreateContext(format, NULL);
	aglSetCurrentContext(aglContext);
	
	if (aglContext == NULL)
	{
		printf("Unable to create OpenGL context.\n");
		return 1;
	}

	aglDestroyPixelFormat(format);
	aglSetDrawable(aglContext, GetWindowPort(window));

	// Set the initial size of the cube
	altEngine.init((void *)&window, (void *)&aglContext);
	altEngine.resize(origWinWidth - origWinXOffset, origWinHeight - origWinYOffset);


	for (;;)
	{
		if (WindowVisible)
			SetEventLoopTimerNextFireTime(timer, 0.05);
	
		RunApplicationEventLoop();
	
		if (WindowVisible)
		{
			altEngine.step();
			//render frame, must pass a message to event handler
			altEngine.render();
		}
	}
}