Ejemplo n.º 1
0
IntRect PluginCarbonWindow::syncWindowAndGetGeometry()
{
    IntRect widgetGeometry(m_ownerPluginView->frameRect());
    Rect const newWindowBounds = { 0, 0, widgetGeometry.height(), widgetGeometry.width() };
    SetWindowBounds(m_windowRef, kWindowContentRgn, &newWindowBounds);
    return widgetGeometry;
}
            void childBoundsChanged (juce::Component* child)
            {
                setSize (child->getWidth(), child->getHeight());
                child->setTopLeftPosition (0, 0);

#if JUCE_WIN32
                resizeHostWindow (hostWindow, titleW, titleH, this);
                owner->updateSize();
#else
                Rect r;
                GetWindowBounds ((WindowRef) hostWindow, kWindowContentRgn, &r);

                HIRect p;
                zerostruct (p);
                HIViewConvertRect (&p, parentView, 0); // find the X position of our view in case there's space to the left of it

                r.right = r.left + jmax (titleW, ((int) p.origin.x) + getWidth());
                r.bottom = r.top + getHeight() + titleH;

                SetWindowBounds ((WindowRef) hostWindow, kWindowContentRgn, &r);

                owner->updateSize();
                owner->Invalidate();
#endif
            }
Ejemplo n.º 3
0
void ResizeWindow(WindowRef pWindow, int w, int h)
{
  Rect gr;  // Screen.
  GetWindowBounds(pWindow, kWindowContentRgn, &gr);
  gr.right = gr.left + w;
  gr.bottom = gr.top + h;
  SetWindowBounds(pWindow, kWindowContentRgn, &gr);
}
Ejemplo n.º 4
0
void mitk::LevelWindow::SetToImageRange(const mitk::Image *image)
{
    if ( IsFixed() )
        return;

    if ( image == NULL || !image->IsInitialized() ) return;

    ScalarType minValue = image->GetStatistics()->GetScalarValueMin(0);
    ScalarType maxValue = image->GetStatistics()->GetScalarValueMaxNoRecompute(0);
    SetRangeMinMax(minValue, maxValue);
    SetDefaultBoundaries(minValue, maxValue);
    SetWindowBounds(minValue, maxValue);
    SetDefaultLevelWindow((maxValue - minValue) / 2 + minValue, maxValue - minValue);
}
Ejemplo n.º 5
0
void
x_full_screen(int do_full)
{
	
#if 0
	WindowRef new_window;
	short	width, height;
	OSErr	ret;
	
	width = 640;
	height = 480;
	if(do_full && (g_mac_fullscreen_state == 0)) {
		g_main_window_saved = g_main_window;
		
		GetWindowBounds(g_main_window, kWindowContentRgn,
						&g_main_window_saved_rect);
		ret = BeginFullScreen(&g_mac_fullscreen_state, 0,
							  &width, &height, &new_window, 0, 0);
		printf("Ret beginfullscreen: %d\n", (int)ret);
		printf("New width: %d, new height: %d\n", width, height);
		if(ret == noErr) {
			g_main_window = new_window;
		} else {
			g_mac_fullscreen_state = 0;
		}
	} else if(!do_full && (g_mac_fullscreen_state != 0)) {
		ret = EndFullScreen(g_mac_fullscreen_state, 0);
		printf("ret endfullscreen: %d\n", (int)ret);
		g_main_window = g_main_window_saved;
		g_mac_fullscreen_state = 0;
		//InitCursor();
		SetWindowBounds(g_main_window, kWindowContentRgn,
						&g_main_window_saved_rect);
	}
	
	update_main_window_size();
	
	ShowWindow(g_main_window);
	BringToFront(g_main_window);
	update_window();
#endif
}
Ejemplo n.º 6
0
static void icvUpdateWindowSize( const CvWindow* window )
{
    int width = 0, height = 240;
    Rect globalBounds;

    GetWindowBounds(window->window, kWindowContentRgn, &globalBounds);

    int minWidth = 320;

    if( window->image ) {
        width = MAX(MAX(window->image->width, width), minWidth);
        height = window->image->height;
    } else
        width = minWidth;

    height += window->trackbarheight;

    //height +=WIDGETHEIGHT; /* 32 pixels are spearating tracbars from the video display */

    globalBounds.right = globalBounds.left + width;
    globalBounds.bottom = globalBounds.top + height;
    SetWindowBounds(window->window, kWindowContentRgn, &globalBounds);
}
Ejemplo n.º 7
0
void MusicBoxDialog(void)
{
	OSStatus	err;
	IBNibRef	nibRef;

	if (!cartOpen)
		return;

	err = CreateNibReference(kMacS9XCFString, &nibRef);
	if (err == noErr)
	{
		CFURLRef	iconURL;
		FSRef		iconFSRef;
		IconRef		actIcon;
		WindowRef	tWindowRef;

		actIcon = nil;

		if (musicboxmode == kMBXSoundEmulation)
			iconURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("musicbox_ledoff"), CFSTR("icns"), nil);
		else
			iconURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("musicbox_ledon" ), CFSTR("icns"), nil);

		if (iconURL)
		{
			if (CFURLGetFSRef(iconURL, &iconFSRef))
				err = RegisterIconRefFromFSRef('~9X~', 'micn', &iconFSRef, &actIcon);

			CFRelease(iconURL);
		}

		err = CreateWindowFromNib(nibRef, CFSTR("MusicBox"), &tWindowRef);
		if (err == noErr)
		{
			EventHandlerRef		mboxRef, paneRef;
			EventHandlerUPP		mboxUPP, paneUPP;
			EventLoopTimerRef	timeRef;
			EventLoopTimerUPP	timeUPP;
			EventTypeSpec		mboxEvents[] = { { kEventClassCommand, kEventCommandProcess      },
												 { kEventClassCommand, kEventCommandUpdateStatus } },
								paneEvents[] = { { kEventClassControl, kEventControlDraw         } };
			CFStringRef			sref;
			CGDataProviderRef	prov;
			CGImageRef			ipng;
			CFURLRef			iurl;
			HIViewRef			ctl, root, paneView, imageView, contentView;
			HIViewID			cid;
			HIRect				bounds;
			Rect				windowRect, barRect;
			char				drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT];

			mboxPause = false;
			mbxFinished = false;
			showIndicator = false;
			so.stereo_switch = ~0;

			for (int i = 0; i < MAC_MAX_PLAYERS; i++)
				controlPad[i] = 0;

			switch (drawingMethod)
			{
				case kDrawingOpenGL:
					Settings.OpenGLEnable = true;
					break;

				case kDrawingDirect:
				case kDrawingBlitGL:
					Settings.OpenGLEnable = false;
			}

			// 107's enhanced SPC player

			root = HIViewGetRoot(tWindowRef);
			cid.id = 0;

			if (musicboxmode == kMBXSoundEmulation)
			{
				cid.signature = 'HEAD';
				HIViewFindByID(root, cid, &ctl);
				EnableControl(ctl);

				StoredAPU          = new SAPU;
				StoredAPURegisters = new SAPURegisters;
				StoredSoundData    = new SSoundData;
				StoredIAPURAM      = new uint8 [0x10000];

				SPCPlayFreeze();
			}
			else
				MusicBoxForceFreeze();

			cid.signature = 'Kart';
			HIViewFindByID(root, cid, &ctl);
			SetStaticTextTrunc(ctl, truncEnd, false);
			_splitpath(Memory.ROMFilename, drive, dir, fname, ext);
			sref = CFStringCreateWithCString(kCFAllocatorDefault, fname, MAC_PATH_ENCODING);
			if (sref)
			{
				SetStaticTextCFString(ctl, sref, false);
				CFRelease(sref);
			}

			ipng = nil;

			iurl = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("musicbox_indicator"), CFSTR("png"), nil);
			if (iurl)
			{
				prov = CGDataProviderCreateWithURL(iurl);
				if (prov)
				{
					ipng = CGImageCreateWithPNGDataProvider(prov, nil, false, kCGRenderingIntentDefault);
					CGDataProviderRelease(prov);
				}

				CFRelease(iurl);
			}

			imageView = nil;

			if (ipng)
			{
				HIViewFindByID(root, kHIViewWindowContentID, &contentView);

				err = HIImageViewCreate(ipng, &imageView);
				if (err == noErr)
				{
					bounds = CGRectMake(30, 64, CGImageGetWidth(ipng), CGImageGetHeight(ipng));
					HIViewSetFrame(imageView, &bounds);
					HIImageViewSetOpaque(imageView, false);
					HIViewSetVisible(imageView, true);
					HIViewAddSubview(contentView, imageView);
					cid.signature = 'iMaG';
					SetControlID(imageView, &cid);
				}

				CGImageRelease(ipng);
			}

			cid.signature = 'Pane';
			HIViewFindByID(root, cid, &paneView);
			HIViewGetBounds(paneView, &bounds);
			mbxViewWidth  = bounds.size.width;
			mbxViewHeight = bounds.size.height;
			mbxMarginY = (mbxViewHeight - mbxBarHeight) / 2.0;
			mbxMarginX = (mbxViewWidth - ((mbxBarWidth * 8.0 + mbxBarSpace * 7.0) * 2.0 + mbxLRSpace)) / 2.0;

			if (imageView)
			{
				HIViewSetZOrder(imageView, kHIViewZOrderBelow, paneView);
				HIViewAddSubview(imageView, paneView);
			}

			cid.signature = 'Tr_i';
			HIViewFindByID(root, cid, &ctl);
			HIViewGetFrame(ctl, &bounds);
			GetWindowBounds(tWindowRef, kWindowTitleBarRgn, &barRect);
			mbxClosedHeight = (short) (bounds.origin.y + bounds.size.height + 7.0) + (barRect.bottom - barRect.top);

			GetWindowBounds(tWindowRef, kWindowStructureRgn, &windowRect);
			mbxOpenedHeight = windowRect.bottom - windowRect.top;

			windowRect.bottom = windowRect.top + mbxClosedHeight;
			SetWindowBounds(tWindowRef, kWindowStructureRgn, &windowRect);

			paneUPP = NewEventHandlerUPP(IndicatorEventHandler);
			err = InstallControlEventHandler(paneView, paneUPP, GetEventTypeCount(paneEvents), paneEvents, (void *) paneView, &paneRef);

			mboxUPP = NewEventHandlerUPP(MusicBoxEventHandler);
			err = InstallWindowEventHandler(tWindowRef, mboxUPP, GetEventTypeCount(mboxEvents), mboxEvents, (void *) tWindowRef, &mboxRef);

			timeUPP = NewEventLoopTimerUPP(MusicBoxTimerHandler);
			err = InstallEventLoopTimer(GetCurrentEventLoop(), kEventDurationNoWait, kEventDurationSecond * 2.0 / (double) Memory.ROMFramesPerSecond, timeUPP, (void *) paneView, &timeRef);

			MusicBoxInitIndicator();

			stopNow = false;
			MacStartSound();
			pthread_create(&mbxThread, nil, SoundTask, nil);

			MoveWindowPosition(tWindowRef, kWindowMusicBox, true);
			GetWindowBounds(tWindowRef, kWindowStructureRgn, &windowRect);
			if (windowRect.bottom - windowRect.top > mbxClosedHeight)
			{
				showIndicator = true;
				SetControl32BitValue(ctl, 1);	// Tr_i
			}

			ShowWindow(tWindowRef);
			err = RunAppModalLoopForWindow(tWindowRef);
			HideWindow(tWindowRef);

			SaveWindowPosition(tWindowRef, kWindowMusicBox);

			stopNow = true;
			pthread_join(mbxThread, nil);
			MacStopSound();

			err = RemoveEventLoopTimer(timeRef);
			DisposeEventLoopTimerUPP(timeUPP);

			err = RemoveEventHandler(mboxRef);
			DisposeEventHandlerUPP(mboxUPP);

			err = RemoveEventHandler(paneRef);
			DisposeEventHandlerUPP(paneUPP);

			ReleaseWindow(tWindowRef);

			so.stereo_switch = ~0;

			mbxFinished = true;

			if (musicboxmode == kMBXSoundEmulation)
			{
 				SPCPlayDefrost();

				delete    StoredAPU;
				delete    StoredAPURegisters;
				delete    StoredSoundData;
				delete [] StoredIAPURAM;
			}
			else
				MusicBoxForceDefrost();

			Settings.OpenGLEnable = false;
		}

		if (actIcon)
			err = UnregisterIconRef('~9X~', 'micn');

		DisposeNibReference(nibRef);
	}
}
Ejemplo n.º 8
0
/*!
This method initializes a mitk::LevelWindow from an mitk::Image. The algorithm is as follows:

Default to taking the central image slice for quick analysis.

Compute the smallest (minValue), second smallest (min2ndValue), second largest (max2ndValue), and
largest (maxValue) data value by traversing the pixel values only once. In the
same scan it also computes the count of minValue values and maxValue values.
After that a basic histogram with specific information about the
extrems is complete.

If minValue == maxValue, the center slice is uniform and the above scan is repeated for
the complete image, not just one slice

Next, special cases of images with only 1, 2 or 3 distinct data values
have hand assigned level window ranges.

Next the level window is set relative to the inner range IR = lengthOf([min2ndValue, max2ndValue])

For count(minValue) > 20% the smallest values are frequent and should be
distinct from the min2ndValue and larger values (minValue may be std:min, may signify
something special) hence the lower end of the level window is set to min2ndValue - 0.5 * IR
 
For count(minValue) <= 20% the smallest values are not so important and can
blend with the next ones => min(level window) = min2ndValue

And analog for max(level window):
count(max2ndValue) > 20%:  max(level window) = max2ndValue + 0.5 * IR
count(max2ndValue) < 20%:  max(level window) = max2ndValue

In both 20%+ cases the level window bounds are clamped to the [minValue, maxValue] range

In consequence the level window maximizes contrast with minimal amount of
computation and does do useful things if the data contains std::min or
std:max values or has only 1 or 2 or 3 data values.
*/
void mitk::LevelWindow::SetAuto(const mitk::Image* image, bool /*tryPicTags*/, bool guessByCentralSlice)
{
  if ( IsFixed() )
    return;
  
  if ( image == NULL || !image->IsInitialized() ) return;

  const mitk::Image* wholeImage = image;
  ScalarType minValue = 0.0;
  ScalarType maxValue = 0.0;
  ScalarType min2ndValue = 0.0; 
  ScalarType max2ndValue = 0.0;
  mitk::ImageSliceSelector::Pointer sliceSelector = mitk::ImageSliceSelector::New();
  if ( guessByCentralSlice )
  {
    sliceSelector->SetInput(image);
    sliceSelector->SetSliceNr(image->GetDimension(2)/2);
    sliceSelector->SetTimeNr(image->GetDimension(3)/2);
    sliceSelector->SetChannelNr(image->GetDimension(4)/2);
    sliceSelector->Update();
    image = sliceSelector->GetOutput();
    if ( image == NULL || !image->IsInitialized() ) return;

    minValue    = image->GetStatistics()->GetScalarValueMin();
    maxValue    = image->GetStatistics()->GetScalarValueMaxNoRecompute();
    min2ndValue = image->GetStatistics()->GetScalarValue2ndMinNoRecompute();
    max2ndValue = image->GetStatistics()->GetScalarValue2ndMaxNoRecompute();
    if ( minValue == maxValue )
    {
      // guessByCentralSlice seems to have failed, lets look at all data
      image       = wholeImage;
      minValue    = image->GetStatistics()->GetScalarValueMin();
      maxValue    = image->GetStatistics()->GetScalarValueMaxNoRecompute();
      min2ndValue = image->GetStatistics()->GetScalarValue2ndMinNoRecompute();
      max2ndValue = image->GetStatistics()->GetScalarValue2ndMaxNoRecompute();
    }
  }
  else
  {
    const_cast<Image*>(image)->Update();
    minValue    = image->GetStatistics()->GetScalarValueMin(0);
    maxValue    = image->GetStatistics()->GetScalarValueMaxNoRecompute(0);
    min2ndValue = image->GetStatistics()->GetScalarValue2ndMinNoRecompute(0);
    max2ndValue = image->GetStatistics()->GetScalarValue2ndMaxNoRecompute(0);
    for (unsigned int i = 1; i < image->GetDimension(3); ++i)
    {
      ScalarType minValueTemp = image->GetStatistics()->GetScalarValueMin(i);
      if (minValue > minValueTemp)
        minValue    = minValueTemp;
      ScalarType maxValueTemp = image->GetStatistics()->GetScalarValueMaxNoRecompute(i);
      if (maxValue < maxValueTemp)
        maxValue = maxValueTemp;
      ScalarType min2ndValueTemp = image->GetStatistics()->GetScalarValue2ndMinNoRecompute(i);
      if (min2ndValue > min2ndValueTemp)
        min2ndValue = min2ndValueTemp; 
      ScalarType max2ndValueTemp = image->GetStatistics()->GetScalarValue2ndMaxNoRecompute(i);
      if (max2ndValue > max2ndValueTemp)
        max2ndValue = max2ndValueTemp; 
    }
  }

  // Fix for bug# 344 Level Window wird bei Eris Cut bildern nicht richtig gesetzt
  if (   image->GetPixelType().GetPixelTypeId()==itk::ImageIOBase::SCALAR
      && image->GetPixelType().GetTypeId() == typeid(int)
      && image->GetPixelType().GetBpe() >= 8)
  {
    // the windows compiler complains about ambiguos 'pow' call, therefore static casting to (double, int)
    if (minValue == -( pow( (double) 2.0, static_cast<int>(image->GetPixelType().GetBpe()/2) ) ) )
    {
      minValue = min2ndValue;
    }
  }
  // End fix

  //// uniform image
  if ( minValue == maxValue )
  {
    minValue = maxValue-1;
  }
  else
  {
      //Due to bug #8690 level window now is no longer of fixed range by default but the range adapts according to levelwindow interaction
      //This is done because the range should be a little bit larger from the beginning so that the scale doesn't start to resize right from the beginning
      double additionalRange = 0.15*(maxValue-minValue);
      minValue -= additionalRange;
      maxValue += additionalRange;
  }
  SetRangeMinMax(minValue, maxValue);
  SetDefaultBoundaries(minValue, maxValue);
/*
  if ( tryPicTags ) // level and window will be set by informations provided directly by the mitkIpPicDescriptor
  {
    if ( SetAutoByPicTags(const_cast<Image*>(image)->GetPic()) )
    {
      return;
    }
  }
 */
   
  unsigned int numPixelsInDataset = image->GetDimensions()[0];
  for ( unsigned int k=0;  k<image->GetDimension();  ++k ) numPixelsInDataset *= image->GetDimensions()[k];
  unsigned int minCount = image->GetStatistics()->GetCountOfMinValuedVoxelsNoRecompute();
  unsigned int maxCount = image->GetStatistics()->GetCountOfMaxValuedVoxelsNoRecompute();
  float minCountFraction = minCount/float(numPixelsInDataset);
  float maxCountFraction = maxCount/float(numPixelsInDataset);

  //// binary image
  if ( min2ndValue == maxValue )
  {
    // noop; full range is fine
  }

  //// triple value image, put middle value in center of gray level ramp
  else if ( min2ndValue == max2ndValue )
  {
    ScalarType minDelta = std::min(min2ndValue-minValue, maxValue-min2ndValue);
    minValue = min2ndValue - minDelta;
    maxValue = min2ndValue + minDelta;
  }

  // now we can assume more than three distict scalar values
  else
  {
    ScalarType innerRange = max2ndValue - min2ndValue;
    
    if ( minCountFraction > 0.2 )  //// lots of min values -> make different from rest, but not miles away
    {
      ScalarType halfInnerRangeGapMinValue = min2ndValue - innerRange/2.0;
      minValue = std::max(minValue, halfInnerRangeGapMinValue);
    }
    else  //// few min values -> focus on innerRange
    {
      minValue = min2ndValue;
    }

    if ( maxCountFraction > 0.2 )  //// lots of max values -> make different from rest
    {
      ScalarType halfInnerRangeGapMaxValue = max2ndValue + innerRange/2.0;
      maxValue = std::min(maxValue, halfInnerRangeGapMaxValue);
    }
    else  //// few max values -> focus on innerRange
    {
      maxValue = max2ndValue;
    }
  }
  SetWindowBounds(minValue, maxValue);
  SetDefaultLevelWindow((maxValue - minValue) / 2 + minValue, maxValue - minValue);
}
Ejemplo n.º 9
0
void mitk::LevelWindow::SetToMaxWindowSize()
{
  SetWindowBounds( m_RangeMin , m_RangeMax );
}
Ejemplo n.º 10
0
void mitk::LevelWindow::SetLevelWindow(mitk::ScalarType level, mitk::ScalarType window, bool expandRangesIfNecessary)
{
  SetWindowBounds( (level-(window/2.0)), (level+(window/2.0)), expandRangesIfNecessary );
}
Ejemplo n.º 11
0
//-------------------------------------------------------------------------------------------------------
bool checkEffectEditor (AEffect* effect)
{
	if ((effect->flags & effFlagsHasEditor) == 0)
	{
		printf ("This plug does not have an editor!\n");
		return false;
	}

#if _WIN32
	theEffect = effect;

	MyDLGTEMPLATE t;
	t.style = WS_POPUPWINDOW|WS_DLGFRAME|DS_MODALFRAME|DS_CENTER;
	t.cx = 100;
	t.cy = 100;
	DialogBoxIndirectParam (GetModuleHandle (0), &t, 0, (DLGPROC)EditorProc, (LPARAM)effect);

	theEffect = 0;

#elif _LINUX
	Display *dpy;
	Window win;
	XEvent e;
	char effect_name[256]; // arbitrary, vst GetEffectName is max 32 chars
	Atom wmDeleteMessage, prop_atom, val_atom;

	// create the window
	dpy = XOpenDisplay(NULL);
	win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 300, 300, 0, 0, 0);

	// we want an event when the window is being closed
	wmDeleteMessage = XInternAtom(dpy, "WM_DELETE_WINDOW", false);
	XSetWMProtocols(dpy, win, &wmDeleteMessage, 1);

	// Make the window a Dialog, maybe the window manager will place it centered
	prop_atom = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
	val_atom = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
	XChangeProperty(dpy, win, prop_atom, XA_ATOM, 32, PropModeReplace, (unsigned char *)&val_atom, 1);

	// prepare the plugin name in the title bar
	effect->dispatcher(effect, effGetEffectName, 0, 0, effect_name, 0);
	strcat(effect_name, " [minihost]");
	XStoreName(dpy, win, effect_name);

	// Get and prepare editor size
	ERect* eRect = 0;
	printf ("HOST> Get editor rect..\n");
	effect->dispatcher (effect, effEditGetRect, 0, 0, &eRect, 0);
	if (eRect) {
		int width = eRect->right - eRect->left;
		int height = eRect->bottom - eRect->top;
		printf("GetRect -> %d, %d\n", width, height);
		XResizeWindow(dpy, win, width, height);
	}

	// ? Is it correct to effEditGetRect above, before effEditOpen ?
	// Display the window, let the plugin populate it
	printf ("HOST> Open editor...\n");
        XMapWindow(dpy, win);
	XFlush(dpy);
	effect->dispatcher (effect, effEditOpen, 0, (VstIntPtr) dpy, (void*) win, 0);

	// Needs adjusting according to events we want to handle in the loop below
	XSelectInput(dpy, win, SubstructureNotifyMask | ButtonPressMask | ButtonReleaseMask
		     | ButtonMotionMask | ExposureMask | KeyPressMask);

	while (true) {
	   XNextEvent(dpy, &e);
	   // handle events as needed
	   if (e.type == ClientMessage && e.xclient.data.l[0] == wmDeleteMessage) {
	      break;
	   }
	}
	printf ("HOST> Close editor..\n");
	effect->dispatcher (effect, effEditClose, 0, 0, 0, 0);
	XCloseDisplay(dpy);


#elif TARGET_API_MAC_CARBON
	WindowRef window;
	Rect mRect = {0, 0, 300, 300};
	OSStatus err = CreateNewWindow (kDocumentWindowClass, kWindowCloseBoxAttribute | kWindowCompositingAttribute | kWindowAsyncDragAttribute | kWindowStandardHandlerAttribute, &mRect, &window);
	if (err != noErr)
	{
		printf ("HOST> Could not create mac window !\n");
		return false;
	}
	static EventTypeSpec eventTypes[] = {
		{ kEventClassWindow, kEventWindowClose }
	};
	InstallWindowEventHandler (window, windowHandler, GetEventTypeCount (eventTypes), eventTypes, window, NULL);

	printf ("HOST> Open editor...\n");
	effect->dispatcher (effect, effEditOpen, 0, 0, window, 0);
	ERect* eRect = 0;
	printf ("HOST> Get editor rect..\n");
	effect->dispatcher (effect, effEditGetRect, 0, 0, &eRect, 0);
	if (eRect)
	{
		int width = eRect->right - eRect->left;
		int height = eRect->bottom - eRect->top;
		Rect bounds;
		GetWindowBounds (window, kWindowContentRgn, &bounds);
		bounds.right = bounds.left + width;
		bounds.bottom = bounds.top + height;
		SetWindowBounds (window, kWindowContentRgn, &bounds);
	}
	RepositionWindow (window, NULL, kWindowCenterOnMainScreen);
	ShowWindow (window);

	EventLoopTimerRef idleEventLoopTimer;
	InstallEventLoopTimer (GetCurrentEventLoop (), kEventDurationSecond / 25., kEventDurationSecond / 25., idleTimerProc, effect, &idleEventLoopTimer);

	RunAppModalLoopForWindow (window);
	RemoveEventLoopTimer (idleEventLoopTimer);

	printf ("HOST> Close editor..\n");
	effect->dispatcher (effect, effEditClose, 0, 0, 0, 0);
	ReleaseWindow (window);
#endif
	return true;
}
Ejemplo n.º 12
0
static Rboolean	Quartz_Open(NewDevDesc *dd, QuartzDesc *xd, char *dsp,
		    double wid, double hgt, int bg)
{

	OSStatus	err;
	WindowRef 	devWindow =  NULL;
	Rect		devBounds, mainRect;
	Str255		Title;
	char		buffer[250];
	int 		devnum = devNumber((DevDesc *)dd);


    xd->windowWidth = wid*72;
    xd->windowHeight = hgt*72;
    xd->window = NULL;
    xd->context = NULL;
    xd->auxcontext = NULL;
	
	xd->bg = dd->startfill = bg; /* 0xffffffff; transparent */
    dd->startcol = R_RGB(0, 0, 0);
    /* Create a new window with the specified size */

	SetRect(&devBounds, 0, 0,  xd->windowWidth, xd->windowHeight ) ;
	
	err = CreateNewWindow( kDocumentWindowClass, kWindowStandardHandlerAttribute|kWindowVerticalZoomAttribute | kWindowCollapseBoxAttribute|kWindowResizableAttribute | kWindowCloseBoxAttribute ,
		& devBounds, & devWindow);
	SetWindowBounds(devWindow,  kWindowContentRgn, &devBounds); 
	mainRect = (*GetMainDevice()) -> gdRect;
    switch(xd->QuartzPos){
		case kQuartzTopRight: /* Top Right */
			RepositionWindow (devWindow,  NULL, kWindowCascadeOnMainScreen);
			GetWindowBounds(devWindow, kWindowStructureRgn, &devBounds);
			devBounds.left = mainRect.right - devBounds.right + 1;
			devBounds.right = mainRect.right;
			SetWindowBounds(devWindow, kWindowStructureRgn, &devBounds); 
		break;
	
		case kQuartzBottomRight: /* Bottom Right */
			GetWindowBounds(devWindow, kWindowStructureRgn, &devBounds);
			devBounds.left = mainRect.right - devBounds.right + 1;
			devBounds.right = mainRect.right;
			devBounds.top = mainRect.bottom - devBounds.bottom + 1;			
			devBounds.bottom = mainRect.bottom;
			SetWindowBounds(devWindow, kWindowStructureRgn, &devBounds); 
		break;
	
		case kQuartzBottomLeft: /* Bottom Left */
			GetWindowBounds(devWindow, kWindowStructureRgn, &devBounds);
			devBounds.top = mainRect.bottom - devBounds.bottom + 1;			
			devBounds.bottom = mainRect.bottom;
			SetWindowBounds(devWindow, kWindowStructureRgn, &devBounds); 
		break;
	
		case kQuartzCenter: /* Center */
			RepositionWindow (devWindow,  NULL, kWindowCenterOnMainScreen);
		break;
	
		case kQuartzTopLeft: /* TopLeft */
			RepositionWindow (devWindow,  NULL, kWindowCascadeOnMainScreen);
		break;
	
		default:
		break; 
	}

	
	
	sprintf(buffer,"Quartz (%d) - Active",devnum+1);
	CopyCStringToPascal(buffer,Title);
        SetWTitle(devWindow, Title);

	ShowWindow(devWindow);

	err = InstallWindowEventHandler( devWindow, NewEventHandlerUPP(QuartzEventHandler),
                                          GetEventTypeCount(QuartzEvents),
                                          QuartzEvents, (void *)devWindow, NULL);
                                          
    if(err != noErr)
     return(0);

    xd->window = devWindow;
    xd->color = xd->fill = R_TRANWHITE;
    xd->resize = false;
    xd->lineType = 0;
    xd->lineWidth = 1;
    return TRUE;
}