Esempio n. 1
0
/* void lock (); */
NS_IMETHODIMP OSLock::Lock()
{
    WindowRef maskWindow = NULL;
    Rect winRect;
    winRect.top = 0;
    winRect.left = 0;
    winRect.bottom = GetMBarHeight();
    winRect.right = CGDisplayPixelsWide(CGMainDisplayID());
    CreateNewWindow(kOverlayWindowClass, kWindowOpaqueForEventsAttribute |
                    kWindowDoesNotCycleAttribute,
                    &winRect, &maskWindow);
    if (maskWindow == NULL) {
        printf("maskWindow is NULL\n");
    } else {
        if (ChangeWindowAttributes(maskWindow, kWindowNoAttributes,
                                   kWindowHideOnFullScreenAttribute) != 0) {
            printf("Unable to remove kWindowHideOnFullScreenAttribute!\n");
        }
        ShowWindow(maskWindow);
    }
    
    SetSystemUIMode(kUIModeAllHidden, kUIOptionDisableAppleMenu |
                    kUIOptionDisableProcessSwitch); // | kUIOptionDisableForceQuit);

    //CGCaptureAllDisplays();
    return NS_OK;
}
Esempio n. 2
0
VideoMode VideoModeImpl::getDesktopMode()
{
    CGDirectDisplayID display = CGMainDisplayID();
    return VideoMode(CGDisplayPixelsWide(display), 
                     CGDisplayPixelsHigh(display), 
                     displayBitsPerPixel(display));
}
void praat_reportGraphicalProperties () {
	MelderInfo_open ();
	MelderInfo_writeLine (U"Graphical properties of this edition of Praat on this computer:\n");
	double x, y, width, height;
	Gui_getWindowPositioningBounds (& x, & y, & width, & height);
	MelderInfo_writeLine (U"Window positioning area: x = ", x, U", y = ", y,
		U", width = ", width, U", height = ", height);
	#if defined (macintosh)
		CGDirectDisplayID screen = CGMainDisplayID ();
		CGSize screenSize_mm = CGDisplayScreenSize (screen);
		double diagonal_mm = sqrt (screenSize_mm. width * screenSize_mm. width + screenSize_mm. height * screenSize_mm. height);
		double diagonal_inch = diagonal_mm / 25.4;
		MelderInfo_writeLine (U"\nScreen size: ", screenSize_mm. width, U" x ", screenSize_mm. height,
			U" mm (diagonal ", Melder_fixed (diagonal_mm, 1), U" mm = ", Melder_fixed (diagonal_inch, 1), U" inch)");
		size_t screenWidth_pixels = CGDisplayPixelsWide (screen);
		size_t screenHeight_pixels = CGDisplayPixelsHigh (screen);
		MelderInfo_writeLine (U"Screen \"resolution\": ", screenWidth_pixels, U" x ", screenHeight_pixels, U" pixels");
		double resolution = 25.4 * screenWidth_pixels / screenSize_mm. width;
		MelderInfo_writeLine (U"Screen resolution: ", Melder_fixed (resolution, 1), U" pixels/inch");
	#elif defined (_WIN32)
		/*for (int i = 0; i <= 88; i ++)
			MelderInfo_writeLine (U"System metric ", i, U": ", GetSystemMetrics (i));*/
	#endif
	MelderInfo_close ();
}
Esempio n. 4
0
static int mac_shadow_detect_monitors(macShadowSubsystem* subsystem)
{
	size_t wide, high;
	MONITOR_DEF* monitor;
	CGDirectDisplayID displayId;
	displayId = CGMainDisplayID();
	CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displayId);
	subsystem->pixelWidth = CGDisplayModeGetPixelWidth(mode);
	subsystem->pixelHeight = CGDisplayModeGetPixelHeight(mode);
	wide = CGDisplayPixelsWide(displayId);
	high = CGDisplayPixelsHigh(displayId);
	CGDisplayModeRelease(mode);
	subsystem->retina = ((subsystem->pixelWidth / wide) == 2) ? TRUE : FALSE;

	if (subsystem->retina)
	{
		subsystem->width = wide;
		subsystem->height = high;
	}
	else
	{
		subsystem->width = subsystem->pixelWidth;
		subsystem->height = subsystem->pixelHeight;
	}

	subsystem->numMonitors = 1;
	monitor = &(subsystem->monitors[0]);
	monitor->left = 0;
	monitor->top = 0;
	monitor->right = subsystem->width;
	monitor->bottom = subsystem->height;
	monitor->flags = 1;
	return 1;
}
Esempio n. 5
0
void
listDisplays(void)
{
   CGDisplayErr      dErr;
    CGDisplayCount    displayCount, i;
    CGDirectDisplayID mainDisplay;
    CGDisplayCount    maxDisplays = MAX_DISPLAYS;
    CGDirectDisplayID onlineDisplays[MAX_DISPLAYS];
   
    mainDisplay = CGMainDisplayID();
   
    dErr = CGGetOnlineDisplayList(maxDisplays, onlineDisplays, &displayCount);
    if (dErr != kCGErrorSuccess) {
        fprintf(stderr, "CGGetOnlineDisplayList: error %d.\n", dErr);
        exit(1);
    }
   
    printf("Display ID       Resolution\n");
    for (i = 0; i < displayCount; i++) {
        CGDirectDisplayID dID = onlineDisplays[i];
        printf("%-16p %lux%lu %32s", dID,
               CGDisplayPixelsWide(dID), CGDisplayPixelsHigh(dID),
               (dID == mainDisplay) ? "[main display]\n" : "\n");
    }
   
    exit(0);
}
Esempio n. 6
0
static void setup_screen(void) {
  CGDirectDisplayID targetDisplay = kCGDirectMainDisplay;

  CGDisplayCapture(targetDisplay); /* crucial for being permitted to write on it */
  screen.base = (uint32_t *) CGDisplayBaseAddress(targetDisplay);
  screen.stride = CGDisplayBytesPerRow(targetDisplay) / sizeof(uint32_t);
  screen.width = CGDisplayPixelsWide(targetDisplay);
  screen.height = CGDisplayPixelsHigh(targetDisplay);
}
Esempio n. 7
0
Status GetVideoMode(int* xres, int* yres, int* bpp, int* freq)
{
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
	CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(kCGDirectMainDisplay);
#else
	CFDictionaryRef currentMode = CGDisplayCurrentMode(kCGDirectMainDisplay);
#endif

	if(xres)
		*xres = (int)CGDisplayPixelsWide(kCGDirectMainDisplay);

	if(yres)
		*yres = (int)CGDisplayPixelsHigh(kCGDirectMainDisplay);

	if(bpp)
	{
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
		// CGDisplayBitsPerPixel was deprecated in OS X 10.6
		CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(currentMode);
		if (CFStringCompare(pixelEncoding, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
			*bpp = 32;
		else if (CFStringCompare(pixelEncoding, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
			*bpp = 16;
		else if (CFStringCompare(pixelEncoding, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
			*bpp = 8;
		else	// error
			*bpp = 0;

		// We're responsible for this
		CFRelease(pixelEncoding);
#else
		CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(currentMode, kCGDisplayBitsPerPixel);
		CFNumberGetValue(num, kCFNumberIntType, bpp);
#endif
	}

	if(freq)
	{
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
		*freq = (int)CGDisplayModeGetRefreshRate(currentMode);
#else
		CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(currentMode, kCGDisplayRefreshRate);
		CFNumberGetValue(num, kCFNumberIntType, freq);
#endif
	}

#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
	// We're responsible for this
	CGDisplayModeRelease(currentMode);
#endif

	return INFO::OK;
}
Esempio n. 8
0
// Pixels-pr-mm.
SbVec2f
SoOffscreenCGData::getResolution(void)
{
#ifdef COIN_MACOS_10_3
  CGDirectDisplayID display = CGMainDisplayID();
  CGSize size = CGDisplayScreenSize(display);
  return SbVec2f(CGDisplayPixelsWide(display)/size.width,
                 CGDisplayPixelsHigh(display)/size.height)l
#else
  return SbVec2f(72.0f / 25.4f, 72.0f / 25.4f); // fall back to 72dpi
#endif
}
XInputSimulatorImplMacOs::XInputSimulatorImplMacOs()
{
    //TODO
    //this->initCurrentMousePosition();
    std::cout << "constructor " << std::endl;
    this->currentX = 500;
    this->currentY = 500;

    CGDirectDisplayID displayID = CGMainDisplayID();

    this->displayX = CGDisplayPixelsWide(displayID);
    this->displayY = CGDisplayPixelsHigh(displayID);
}
Esempio n. 10
0
File: gdi.c Progetto: AndreRH/wine
/**********************************************************************
 *              device_init
 *
 * Perform initializations needed upon creation of the first device.
 */
static void device_init(void)
{
    CGDirectDisplayID mainDisplay = CGMainDisplayID();
    CGSize size_mm = CGDisplayScreenSize(mainDisplay);
    CGDisplayModeRef mode = CGDisplayCopyDisplayMode(mainDisplay);

    check_retina_status();

    /* Initialize device caps */
    horz_size = size_mm.width;
    vert_size = size_mm.height;

    bits_per_pixel = 32;
    if (mode)
    {
        CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(mode);

        horz_res = CGDisplayModeGetWidth(mode);
        vert_res = CGDisplayModeGetHeight(mode);

        if (pixelEncoding)
        {
            if (CFEqual(pixelEncoding, CFSTR(IO32BitDirectPixels)))
                bits_per_pixel = 32;
            else if (CFEqual(pixelEncoding, CFSTR(IO16BitDirectPixels)))
                bits_per_pixel = 16;
            else if (CFEqual(pixelEncoding, CFSTR(IO8BitIndexedPixels)))
                bits_per_pixel = 8;
            CFRelease(pixelEncoding);
        }

        CGDisplayModeRelease(mode);
    }
    else
    {
        horz_res = CGDisplayPixelsWide(mainDisplay);
        vert_res = CGDisplayPixelsHigh(mainDisplay);
    }

    if (retina_on)
    {
        horz_res *= 2;
        vert_res *= 2;
    }

    compute_desktop_rect();
    desktop_horz_res = desktop_rect.size.width;
    desktop_vert_res = desktop_rect.size.height;

    device_data_valid = TRUE;
}
Esempio n. 11
0
File: main.c Progetto: Aiur/Airtab
int main (int argc, const char * argv[])
{
    Command cmd;
    char lineBuff[100];
    
    // http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/Quartz_Services_Ref/Reference/reference.html#//apple_ref/doc/uid/TP30001070
    g_screenWidth = CGDisplayPixelsWide(CGDisplayPrimaryDisplay(CGMainDisplayID()));
    g_screenHeight = CGDisplayPixelsHigh(CGDisplayPrimaryDisplay(CGMainDisplayID()));
    
    while (true) {
        readLine(lineBuff, 100);
        parseCommand(&cmd, lineBuff);
        execCommand(&cmd);
    }
    
    return 0;
}
Esempio n. 12
0
void
infoDisplays(void)
{
    CGDisplayErr      dErr;
    CGDisplayCount    displayCount, i;
    CGDirectDisplayID mainDisplay;
    CGDisplayCount    maxDisplays = MAX_DISPLAYS;
    CGDirectDisplayID onlineDisplays[MAX_DISPLAYS];
    
    CGEventRef ourEvent = CGEventCreate(NULL);
    CGPoint ourLoc = CGEventGetLocation(ourEvent);
    
    CFRelease(ourEvent);
    
    mainDisplay = CGMainDisplayID();
   
    dErr = CGGetOnlineDisplayList(maxDisplays, onlineDisplays, &displayCount);
    if (dErr != kCGErrorSuccess) {
        fprintf(stderr, "CGGetOnlineDisplayList: error %d.\n", dErr);
        exit(1);
    }
   
    printf("#  Display_ID  Resolution  ____Display_Bounds____  Rotation\n");
    for (i = 0; i < displayCount; i++) {
        CGDirectDisplayID dID = onlineDisplays[i];
        printf("%-2d %10p  %4lux%-4lu  %5.0f %5.0f %5.0f %5.0f    %3.0f    %s%s%s", 
               CGDisplayUnitNumber (dID), dID,
               CGDisplayPixelsWide(dID), CGDisplayPixelsHigh(dID),
               CGRectGetMinX (CGDisplayBounds (dID)),
               CGRectGetMinY (CGDisplayBounds (dID)),
               CGRectGetMaxX (CGDisplayBounds (dID)),
               CGRectGetMaxY (CGDisplayBounds (dID)),           
               CGDisplayRotation (dID),
               (CGDisplayIsActive (dID)) ? "" : "[inactive]",
               (dID == mainDisplay) ? "[main]" : "",
               (CGDisplayIsBuiltin (dID)) ? "[internal]\n" : "\n");
    }
    
    printf("Mouse Cursor Position:  ( %5.0f , %5.0f )\n",
               (float)ourLoc.x, (float)ourLoc.y);
   
    exit(0);
}
Esempio n. 13
0
//--------------------------------------------------------------
// global initialization called in main.m
void initFramework(
  const char* resourceDir)
{
  chdir(resourceDir);

  mgOSLaunchSendLog();
  
  // initialize random numbers
  time_t seed;
  time(&seed);
  srand(12123123); // srand(seed & 0xFFFF);
  
  mgDebugReset();         // reset trace file

  mgDebug(":Program: %s", mgProgramName != NULL ? mgProgramName : "unknown");
  mgDebug(":Program Version: %s", mgProgramVersion != NULL ? mgProgramVersion : "unknown");
  
  char machineID[256];
  getPlatformUUID(machineID, sizeof(machineID)-1);
  machineID[sizeof(machineID)-1] = '\0';
  mgDebug(":Machine Id: %s", machineID);
    
  struct utsname name;
  if (uname(&name) != -1)
  {
    mgDebug(":OS: %s", name.sysname);
    mgDebug(":Machine 64-bit: %s", strstr(name.machine, "_64") != NULL ? "true" : "false");
  }
  else mgDebug(":OS: OSX");

  const int MAX_DISPLAYS = 20;
  uint32_t displayCount;
  CGGetActiveDisplayList(MAX_DISPLAYS, NULL, &displayCount);
  mgDebug(":Machine Monitor count: %d", displayCount);

  CGDirectDisplayID mainDisplay = CGMainDisplayID();
  mgDebug(":Machine Monitor res: %d by %d", CGDisplayPixelsWide(mainDisplay), CGDisplayPixelsHigh(mainDisplay));

  mgOSInitTimer();       // performance timer
  
  atexit(termFramework);
}
Esempio n. 14
0
int QuartzWindow::screen_width() {
  return CGDisplayPixelsWide(screen(my_window()));
}
Esempio n. 15
0
//--------------------------------------------------------------
// initialize display.  
void mgOSXServices::initDisplay()
{
  // build error string if library is unknown choice
  mgString libraryChoices;

  // for each supported library, try to initialize it
  m_support = NULL;
  BOOL triedLibrary = false;

#ifdef SUPPORT_GL33
  libraryChoices += "\"OpenGL3.3\" ";
  if (m_support == NULL && (m_library.equalsIgnoreCase("OpenGL3.3") || m_library.isEmpty()))
  {
    triedLibrary = true;
    mgOSXGL33Support* gl33 = new mgOSXGL33Support();

    // requested gl33 attributes
    gl33->m_fullscreen = m_fullscreen;
    gl33->m_multiSample = m_multiSample;
    gl33->m_swapImmediate = m_swapImmediate;

    if (gl33->initDisplay())
    {
      m_libraryFound = MG_LIBRARY_OPENGL33;
      m_support = gl33;
    }
    else delete gl33;
  }
#endif

#ifdef SUPPORT_GL21
  libraryChoices += "\"OpenGL2.1\" ";
  if (m_support == NULL && (m_library.equalsIgnoreCase("OpenGL2.1") || m_library.isEmpty()))
  {
    triedLibrary = true;
    mgOSXGL21Support* gl21 = new mgOSXGL21Support();

    // requested gl21 attributes
    gl21->m_fullscreen = m_fullscreen;
    gl21->m_multiSample = m_multiSample;
    gl21->m_swapImmediate = m_swapImmediate;

    if (gl21->initDisplay())
    {
      m_libraryFound = MG_LIBRARY_OPENGL21;
      m_support = gl21;
    }
    else delete gl21;
  }
#endif

  // if display initialization failed, throw exception
  if (m_support == NULL)
  {
    // if no library specified
    if (m_library.isEmpty())
      throw new mgErrorMsg("winNoLibrary", "libraries", "%s", (const char*) libraryChoices);

    // library specified could not be initialized
    if (triedLibrary)
      throw new mgErrorMsg("winBadLibrary", "library", "%s", (const char*) m_library);

    // library specified was not supported
    throw new mgErrorMsg("winWrongLibrary", "library,libraries", "%s,%s", 
      (const char*) m_library, (const char*) libraryChoices);
  }

  // save actual gl33 attributes
  m_depthBits = m_support->m_depthBits;
  m_fullscreen = m_support->m_fullscreen;
  m_multiSample = m_support->m_multiSample;
  m_swapImmediate = m_support->m_swapImmediate;

  m_support->setGraphicsSize(m_windowWidth, m_windowHeight);

  // finish display init from system state
  size_t width = CGDisplayPixelsWide(CGMainDisplayID());
  CGSize size = CGDisplayScreenSize(CGMainDisplayID());
  m_DPI = (int) ((width * 25.4) / size.width);
  mgDebug("screen is %d pixels/%d mm = %d dpi", (int) width, (int) size.width, m_DPI);
  m_DPI = max(m_DPI, 72);  // in case monitor info wrong

  mgDebug("");
  mgDebug("------ display initialized.  Return to app: %s", (const char *) m_windowTitle);
}
Esempio n. 16
0
LLWindowMacOSX::LLWindowMacOSX(LLWindowCallbacks* callbacks,
							   const std::string& title, const std::string& name, S32 x, S32 y, S32 width,
							   S32 height, U32 flags,
							   BOOL fullscreen, BOOL clearBg,
							   BOOL disable_vsync, BOOL use_gl,
							   BOOL ignore_pixel_depth,
							   //U32 fsaa_samples,) // <FS:LO> Legacy cursor setting from main program
							   U32 fsaa_samples,
							   BOOL useLegacyCursors)
	: LLWindow(NULL, fullscreen, flags)
{
	mUseLegacyCursors = useLegacyCursors; // <FS:LO> Legacy cursor setting from main program
	// *HACK: During window construction we get lots of OS events for window
	// reshape, activate, etc. that the viewer isn't ready to handle.
	// Route them to a dummy callback structure until the end of constructor.
	LLWindowCallbacks null_callbacks;
	mCallbacks = &null_callbacks;

	// Voodoo for calling cocoa from carbon (see llwindowmacosx-objc.mm).
	setupCocoa();

	// Initialize the keyboard
	gKeyboard = new LLKeyboardMacOSX();
	gKeyboard->setCallbacks(callbacks);

	// Ignore use_gl for now, only used for drones on PC
	mWindow = NULL;
	mContext = NULL;
	mPixelFormat = NULL;
	mDisplay = CGMainDisplayID();
	mSimulatedRightClick = FALSE;
	mLastModifiers = 0;
	mHandsOffEvents = FALSE;
	mCursorDecoupled = FALSE;
	mCursorLastEventDeltaX = 0;
	mCursorLastEventDeltaY = 0;
	mCursorIgnoreNextDelta = FALSE;
	mNeedsResize = FALSE;
	mOverrideAspectRatio = 0.f;
	mMaximized = FALSE;
	mMinimized = FALSE;
	mLanguageTextInputAllowed = FALSE;
	mPreeditor = NULL;
	mFSAASamples = fsaa_samples;
	mForceRebuild = FALSE;

	// Get the original aspect ratio of the main device.
	mOriginalAspectRatio = (double)CGDisplayPixelsWide(mDisplay) / (double)CGDisplayPixelsHigh(mDisplay);

	// Stash the window title
	mWindowTitle = title;
	//mWindowTitle[0] = title.length();

	mDragOverrideCursor = -1;

	// Set up global event handlers (the fullscreen case needs this)
	//InstallStandardEventHandler(GetApplicationEventTarget());

	// Stash an object pointer for OSMessageBox()
	gWindowImplementation = this;
	// Create the GL context and set it up for windowed or fullscreen, as appropriate.
	if(createContext(x, y, width, height, 32, fullscreen, disable_vsync))
	{
		if(mWindow != NULL)
		{
			makeWindowOrderFront(mWindow);
		}

		if (!gGLManager.initGL())
		{
			setupFailure(
				"Second Life is unable to run because your video card drivers\n"
				"are out of date or unsupported. Please make sure you have\n"
				"the latest video card drivers installed.\n"
				"If you continue to receive this message, contact customer service.",
				"Error",
				OSMB_OK);
			return;
		}

		//start with arrow cursor
		//initCursors();
		initCursors(mUseLegacyCursors); // <FS:LO> Legacy cursor setting from main program
		setCursor( UI_CURSOR_ARROW );
		
		allowLanguageTextInput(NULL, FALSE);
	}

	mCallbacks = callbacks;
	stop_glerror();
	
	
}
Esempio n. 17
0
/**********************************************************************
 *              device_init
 *
 * Perform initializations needed upon creation of the first device.
 */
static void device_init(void)
{
    CGDirectDisplayID mainDisplay = CGMainDisplayID();
    CGSize size_mm = CGDisplayScreenSize(mainDisplay);
    CGDisplayModeRef mode = CGDisplayCopyDisplayMode(mainDisplay);
    CGDirectPaletteRef palette;

    /* Initialize device caps */
    log_pixels_x = log_pixels_y = get_dpi();
    if (!log_pixels_x)
    {
        size_t width = CGDisplayPixelsWide(mainDisplay);
        size_t height = CGDisplayPixelsHigh(mainDisplay);
        log_pixels_x = MulDiv(width, 254, size_mm.width * 10);
        log_pixels_y = MulDiv(height, 254, size_mm.height * 10);
    }

    horz_size = size_mm.width;
    vert_size = size_mm.height;

    bits_per_pixel = 32;
    if (mode)
    {
        CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(mode);

        horz_res = CGDisplayModeGetWidth(mode);
        vert_res = CGDisplayModeGetHeight(mode);

        if (pixelEncoding)
        {
            if (CFEqual(pixelEncoding, CFSTR(IO32BitDirectPixels)))
                bits_per_pixel = 32;
            else if (CFEqual(pixelEncoding, CFSTR(IO16BitDirectPixels)))
                bits_per_pixel = 16;
            else if (CFEqual(pixelEncoding, CFSTR(IO8BitIndexedPixels)))
                bits_per_pixel = 8;
            CFRelease(pixelEncoding);
        }

        CGDisplayModeRelease(mode);
    }
    else
    {
        horz_res = CGDisplayPixelsWide(mainDisplay);
        vert_res = CGDisplayPixelsHigh(mainDisplay);
    }

    macdrv_get_desktop_rect();
    desktop_horz_res = desktop_rect.size.width;
    desktop_vert_res = desktop_rect.size.height;

    palette = CGPaletteCreateWithDisplay(mainDisplay);
    if (palette)
    {
        palette_size = CGPaletteGetNumberOfSamples(palette);
        CGPaletteRelease(palette);
    }
    else
        palette_size = 0;

    device_data_valid = TRUE;
}
Esempio n. 18
0
//========================================================================
int main( ){
    
    ofGLFWWindowSettings mainSettings;
    
    mainSettings.resizable = false;
    mainSettings.setGLVersion(4, 1);
    mainSettings.decorated = false;

    ofGLFWWindowSettings guiSettings;
    
    guiSettings.resizable = true;
    guiSettings.setGLVersion(4, 1);

    // Get screen widths and heights from Quartz Services
    // See https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/Quartz_Services_Ref/index.html
    
    CGDisplayCount displayCount;
    CGDirectDisplayID displays[32];
    
    // Grab the active displays
    CGGetActiveDisplayList(32, displays, &displayCount);
    int numDisplays= displayCount;
    
    // print display info.
    cout<<numDisplays<<" display(s) detected."<<endl;
    
    for (int i = 0; i < displayCount; i++){
        cout << displays[i] << "\t(" << CGDisplayPixelsWide(displays[i]) << "x" << CGDisplayPixelsHigh(displays[i]) << ")"<< endl;
    }
    
    CGRect mainDisplayBounds= CGDisplayBounds ( displays[0] );

    if(numDisplays == 1 ){
        
        float divisions = 4.0;
        // one display: palce gui and mainWindow in a default arrangement
        
        mainSettings.width = round(mainDisplayBounds.size.width * (divisions-1) / divisions);
        mainSettings.height = round((mainSettings.width * (9.0 / 16.0)) / 2.0);
        mainSettings.setPosition(ofVec2f(round(mainDisplayBounds.size.width / divisions) ,mainDisplayBounds.origin.y));
        mainSettings.decorated = true;
        
        guiSettings.width = round(mainDisplayBounds.size.width - 100);
        guiSettings.height = mainDisplayBounds.size.height - 100;
        guiSettings.setPosition(ofVec2f(mainDisplayBounds.origin.x, mainDisplayBounds.origin.y + 80));

        cout << "configured default one display setup" << endl;
        
    } else if (numDisplays > 1){
        
        // two displays: palce resizeable gui on first and fill second with undecorated mainWindow - will also work with dual head configuraions for projectors

        guiSettings.width = mainDisplayBounds.size.width;
        guiSettings.height = mainDisplayBounds.size.height - 100;
        guiSettings.setPosition(ofVec2f(mainDisplayBounds.origin.x, mainDisplayBounds.origin.y));

        CGRect secondDisplayBounds= CGDisplayBounds ( displays[1] );
        
        mainSettings.width = secondDisplayBounds.size.width;
        mainSettings.height = secondDisplayBounds.size.height;
        mainSettings.setPosition(ofVec2f(secondDisplayBounds.origin.x,secondDisplayBounds.origin.y));
        
//        CGError e = CGDisplaySetStereoOperation(displays[1], true, true, kCGConfigureForAppOnly);
        
//        if(e == kCGErrorRangeCheck) cout << "no hardware stereo" << endl;
//        if(e == kCGErrorSuccess) cout << "hardware stereo" << endl;
        
        if (numDisplays > 2 ) {
            
            // three or more displays: palce resizeable gui on first and fill second and third with undecorated mainWindow, if they are same size.
            
            CGRect thirdDisplayBounds= CGDisplayBounds ( displays[2] );
            if(secondDisplayBounds.size.width == thirdDisplayBounds.size.width && secondDisplayBounds.size.height == thirdDisplayBounds.size.height){
               
                mainSettings.width = secondDisplayBounds.size.width * 2;
                mainSettings.setPosition(ofVec2f(1,1));
                cout << "configured default three display setup" << endl;

            }
        } else {
            cout << "configured default two display setup" << endl;
        }
    }
    
    shared_ptr<ofAppBaseWindow> mainWindow = ofCreateWindow(mainSettings);
    guiSettings.shareContextWith = mainWindow;

    shared_ptr<ofAppBaseWindow> guiWindow = ofCreateWindow(guiSettings);

    //guiWindow->setVerticalSync(false);
    
    shared_ptr<ofApp> mainApp(new ofApp);
    
    mainApp->setupGui(guiWindow, mainWindow);
    
    ofAddListener(guiWindow->events().draw,mainApp.get(),&ofApp::drawGui);
    
    // gui events to main app gui listener functions
    
#define guiEventMacro(NAME)  ofAddListener(guiWindow->events() . NAME , mainApp.get(), &ofApp::NAME ## Gui);

    guiEventMacro(keyPressed);
    guiEventMacro(keyReleased);
    guiEventMacro(mouseMoved);
    guiEventMacro(mouseDragged);
    guiEventMacro(mousePressed);
    guiEventMacro(mouseReleased);
    guiEventMacro(mouseEntered);
    guiEventMacro(mouseExited);
    guiEventMacro(windowResized);
    
    ofRunApp(mainWindow, mainApp);

    ofRunMainLoop();

}
int doMain (int argc, char **argv)
{
    int dummy;

    // OSG init

    OSG::osgInit(argc, argv);

    // create the graph

    // beacon for camera and light
    OSG::NodeUnrecPtr b1n = OSG::Node::create();
    OSG::GroupUnrecPtr b1 = OSG::Group::create();
    b1n->setCore( b1 );

    // transformation
    OSG::NodeUnrecPtr t1n = OSG::Node::create();
    OSG::TransformUnrecPtr t1 = OSG::Transform::create();
    t1n->setCore( t1 );
    t1n->addChild( b1n );

    cam_trans = t1;

    // light

    OSG::NodeUnrecPtr dlight = OSG::Node::create();
    OSG::DirectionalLightUnrecPtr dl = OSG::DirectionalLight::create();

    dlight->setCore( dl );

    dl->setAmbient( .3, .3, .3, 1 );
    dl->setDiffuse( 1, 1, 1, 1 );
    dl->setDirection(0,0,1);
    dl->setBeacon( b1n);

    // root
    root = OSG::Node::create();
    OSG::GroupUnrecPtr gr1 = OSG::Group::create();

    root->setCore( gr1 );
    root->addChild( t1n );
    root->addChild( dlight );

    // Load the file

    OSG::NodeUnrecPtr file = NULL;

    if ( argc > 1 )
        file = OSG::SceneFileHandler::the()->read(argv[1]);

    if ( file == NULL )
    {
        std::cerr << "Couldn't load file, ignoring" << std::endl;
        file = OSG::makeTorus( .5, 2, 16, 16 );
    }

    OSG::Thread::getCurrentChangeList()->commitChanges();
    file->updateVolume();

    OSG::Vec3f min,max;
    file->getVolume().getBounds( min, max );

    std::cout << "Volume: from " << min << " to " << max << std::endl;

    dlight->addChild( file );

    std::cerr << "Tree: " << std::endl;
    //root->dump();

    // Camera
    cam = OSG::PerspectiveCamera::create();

    cam->setBeacon( b1n );
    cam->setFov( OSG::osgDegree2Rad( 90 ) );
    cam->setNear( 0.1 );
    cam->setFar( 100000 );

    // Background
    OSG::SolidBackgroundUnrecPtr bkgnd = OSG::SolidBackground::create();

    bkgnd->setColor(OSG::Color3f(0,0,1));

    // Viewport

    vp = OSG::Viewport::create();
    vp->setCamera( cam );
    vp->setBackground( bkgnd );
    vp->setRoot( root );
    vp->setSize( 0,0, 1,1 );

    // Action

    ract = OSG::RenderAction::create();

    // tball

    OSG::Vec3f pos;
    pos.setValues(min[0] + ((max[0] - min[0]) * 0.5), 
                  min[1] + ((max[1] - min[1]) * 0.5), 
                  max[2] + ( max[2] - min[2] ) * 1.5 );
    
    float scale = (max[2] - min[2] + max[1] - min[1] + max[0] - min[0]) / 6;

    OSG::Pnt3f tCenter(min[0] + (max[0] - min[0]) / 2,
                       min[1] + (max[1] - min[1]) / 2,
                       min[2] + (max[2] - min[2]) / 2);
    
    tball.setMode( OSG::Trackball::OSGObject );
    tball.setStartPosition( pos, true );
    tball.setSum( true );
    tball.setTranslationMode( OSG::Trackball::OSGFree );
    tball.setTranslationScale(scale);
    tball.setRotationCenter(tCenter);

    // CoreGL init

    // Install event handler
    EventHandlerUPP eventHandlerUPP = NewEventHandlerUPP(eventHandler);
    EventTypeSpec eventList[] =
    {
        { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent },
        { kEventClassMouse, kEventMouseDown },
        { kEventClassMouse, kEventMouseUp },
        { kEventClassMouse, kEventMouseDragged }
    };
    InstallApplicationEventHandler(eventHandlerUPP, GetEventTypeCount(eventList), eventList, 0, 0);

    CGDisplayCapture(kCGDirectMainDisplay);
    CGLPixelFormatAttribute attribs[] =
    {
        kCGLPFADoubleBuffer,
        kCGLPFAFullScreen,
        kCGLPFADepthSize,
        (CGLPixelFormatAttribute)16,
        kCGLPFADisplayMask,
        (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay),
        (CGLPixelFormatAttribute)0
    };
    CGLPixelFormatObj pixelFormatObj;
    GLint numPixelFormats;
    CGLChoosePixelFormat(attribs, &pixelFormatObj, &numPixelFormats); 

    CGLContextObj contextObj;
    CGLCreateContext(pixelFormatObj, 0, &contextObj);

    CGLDestroyPixelFormat(pixelFormatObj);

    CGLSetCurrentContext(contextObj);
    CGLSetFullScreen(contextObj);

    // Create OpenSG window
    win = OSG::CoreGLWindow::create();
    win->addPort( vp );             
    win->setContext ( contextObj );
    win->init();
    win->resize( CGDisplayPixelsWide(kCGDirectMainDisplay), CGDisplayPixelsHigh(kCGDirectMainDisplay) );

    win->activate();

    // do some OpenGL init. Will move into State Chunks later.

    glEnable( GL_DEPTH_TEST );
    glEnable( GL_LIGHTING );
    glEnable( GL_LIGHT0 );
    redraw();

    // Main loop ( event dispatching )
    RunApplicationEventLoop();

    // Cleanup
    CGLSetCurrentContext(0);
    CGLClearDrawable(contextObj);
    CGLDestroyContext(contextObj);
    CGReleaseAllDisplays();
    DisposeEventHandlerUPP(eventHandlerUPP);

    ract      = NULL;
    win       = NULL;
    root      = NULL;
    file      = NULL;
    vp        = NULL;
    cam_trans = NULL;
    cam       = NULL;

    return 0;
}
Esempio n. 20
0
//--------------------------------------------------------------
void ofApp::setup(){
    
    camWidth = 1024;
    camHeight = 768;
    projWidth = 1024;
    projHeight = 768;
    canvasHeight = ofGetHeight() / 3 - 10;
    canvasWidth = canvasHeight * 4 / 3;
    outputHeight = ofGetHeight() * 2 / 3 - 10;
    outputWidth = outputHeight * 4 / 3;
    guiPos = ofPoint(10,10);
    canvas1Pos = ofPoint(ofGetWidth()/3 + 5, 5);
    canvas2Pos = ofPoint(ofGetWidth()*2/3 + 5, 5);
    outputPos = ofPoint(ofGetWidth()/3 + 5, ofGetHeight()/3+5);
    
    ofSetWindowTitle("FaceMapper - OTU CINEMA SL");
    
    CGDisplayCount displayCount;
    CGDirectDisplayID displays[32];
    
    // grab the active displays
    CGGetActiveDisplayList(32, displays, &displayCount);
    
    cout<<"displayCount "<<displayCount<<endl;
    
	vidGrabber.setVerbose(true);
	vidGrabber.initGrabber(camWidth, camHeight);
	colorImg.allocate(camWidth, camHeight);
	grayImage.allocate(canvasWidth, canvasHeight);
    warpedImg.allocate(canvasWidth, canvasHeight);
    
    if (displayCount == 1) {
        
        whichDisplay = 0;
        mainDisplayWidth = CGDisplayPixelsWide ( displays[whichDisplay] );
        mainDisplayWidth = CGDisplayPixelsHigh ( displays[whichDisplay] );
        
    }
    
    else {
        
        whichDisplay = 1;
        mainDisplayWidth = CGDisplayPixelsWide ( displays[0] );
        mainDisplayHeight = CGDisplayPixelsHigh ( displays[0] );
        secondDisplayWidth = CGDisplayPixelsWide ( displays[whichDisplay] );
        secondDisplayHeight = CGDisplayPixelsHigh ( displays[whichDisplay] );
        
    }
    
    
    // the arguments for the second window are its initial x and y position,
    // and its width and height. the last argument is whether the window
    // should be undecorated, i.e. title bar is visible. setting it to
    // true removes the title bar.
    
    
    if (displayCount == 1) secondWindow.setup("Output", 0, 0, 640, 480, false);
    else secondWindow.setup("Output", mainDisplayWidth, 0, secondDisplayWidth, secondDisplayHeight, true);
    
    
	threshold = 80;
	bLearnBakground = true;
	backgroundSubOn = false;
	
	//detect finger is off by default
	fidfinder.detectFinger		= false;
	//fidfinder.maxFingerSize		= 25;
	//fidfinder.minFingerSize		= 5;
	//fidfinder.fingerSensitivity	= 0.05f; //from 0 to 2.0f
        
    gui.setup("Control Panel"); // most of the time you don't need a name
    gui.add(selection.setup("Image Selection", false));
    gui.add(warping.setup("Warping Mode", false));
    gui.add(threshold.setup("Threshold", 160, 0, 255));
    gui.add(tableWidth.setup("Largo Mesa (cm)", 200, 10, 500));
    gui.add(tableHeight.setup("Ancho Mesa (cm)", 100, 10, 500));
    
    // Definimos los puntos de recorte de ROI (warping inverso de imagen de entrada)
    roiCorners[0] = ofPoint(10,10);
    roiCorners[1] = ofPoint(canvasWidth-10, 10);
    roiCorners[2] = ofPoint(canvasWidth - 10, canvasHeight - 10);
    roiCorners[3] = ofPoint(10,canvasHeight - 10);
    destCorners[0] = ofPoint(0,0);
    destCorners[1] = ofPoint(canvasWidth, 0);
    destCorners[2] = ofPoint(canvasWidth, canvasHeight);
    destCorners[3] = ofPoint(0,canvasHeight);
    
    for (int i = 0; i < 4; i++) {
        
        activeCorners[i] = false;
        
    }
    
    // Inicializamos los canvas
    
    canvas1.allocate(canvasWidth, canvasHeight, GL_RGB);
    canvas2.allocate(canvasWidth, canvasHeight, GL_RGB);
    canvasWarp.allocate(canvasWidth, canvasHeight, GL_RGB);
    output.allocate(outputWidth, outputHeight, GL_RGB);
    warpedOutput.allocate(outputWidth, outputHeight, GL_RGB);
    
    
    pixels.allocate(canvasWidth, canvasHeight, GL_RGB);

    // Inicializamos el quad
    quadRoi.setMode(OF_PRIMITIVE_LINE_LOOP);
    
    for(int i = 0; i < 4; i++) {
        
        quadRoi.addVertex(roiCorners[i]);

    }
    
    // Inicializamos el warper
    
    
    warperGui.setup(outputPos.x, outputPos.y, outputWidth, outputHeight);
    warperGui.activate();
    
    warperOutput.setup(mainDisplayWidth, 0, secondDisplayWidth, secondDisplayHeight);; //initializates ofxGLWarper
    
    // Inicializamos el objeto "Bola"
    //lets setup some stupid particles
    for(int i = 0; i < 10; i++){
        
        cards[i].setup(i);

    }
}
Esempio n. 21
0
DisplayInfo MythDisplay::GetDisplayInfo(int video_rate)
{
    DisplayInfo ret;

#if defined(Q_WS_MAC)
    CGDirectDisplayID disp = GetOSXDisplay(GetWindowID());
    if (!disp)
        return ret;

    CFDictionaryRef ref = CGDisplayCurrentMode(disp);
    float rate = 0.0f;
    if (ref)
        rate = get_float_CF(ref, kCGDisplayRefreshRate);

    if (VALID_RATE(rate))
        ret.rate = 1000000.0f / rate;
    else
        ret.rate = fix_rate(video_rate);

    CGSize size_in_mm = CGDisplayScreenSize(disp);
    ret.size = QSize((uint) size_in_mm.width, (uint) size_in_mm.height);

    uint width  = (uint)CGDisplayPixelsWide(disp);
    uint height = (uint)CGDisplayPixelsHigh(disp);
    ret.res     = QSize(width, height);

#elif defined(Q_WS_WIN)
    HDC hdc = GetDC(GetWindowID());
    int rate = 0;
    if (hdc)
    {
        rate       = GetDeviceCaps(hdc, VREFRESH);
        int width  = GetDeviceCaps(hdc, HORZSIZE);
        int height = GetDeviceCaps(hdc, VERTSIZE);
        ret.size   = QSize((uint)width, (uint)height);
        width      = GetDeviceCaps(hdc, HORZRES);
        height     = GetDeviceCaps(hdc, VERTRES);
        ret.res    = QSize((uint)width, (uint)height);
    }

    if (VALID_RATE(rate))
    {
        // see http://support.microsoft.com/kb/2006076
        switch (rate)
        {
        case 23:
            ret.rate = 41708;
            break; // 23.976Hz
        case 29:
            ret.rate = 33367;
            break; // 29.970Hz
        case 47:
            ret.rate = 20854;
            break; // 47.952Hz
        case 59:
            ret.rate = 16683;
            break; // 59.940Hz
        case 71:
            ret.rate = 13903;
            break; // 71.928Hz
        case 119:
            ret.rate = 8342;
            break; // 119.880Hz
        default:
            ret.rate = 1000000.0f / (float)rate;
        }
    }
    else
        ret.rate = fix_rate(video_rate);

#elif USING_X11
    MythXDisplay *disp = OpenMythXDisplay();
    if (!disp)
        return ret;

    float rate = disp->GetRefreshRate();
    if (VALID_RATE(rate))
        ret.rate = 1000000.0f / rate;
    else
        ret.rate = fix_rate(video_rate);
    ret.res  = disp->GetDisplaySize();
    ret.size = disp->GetDisplayDimensions();
    delete disp;
#endif
    return ret;
}