Пример #1
0
MainWindow *mainwindow_new(MultiTestApp *app) {
	GHOST_SystemHandle sys= multitestapp_get_system(app);
	GHOST_WindowHandle win;
	
	win= GHOST_CreateWindow(sys, "MultiTest:Main", 40, 40, 400, 400, 
		GHOST_kWindowStateNormal, GHOST_kDrawingContextTypeOpenGL, 
		FALSE);
	
	if (win) {
		MainWindow *mw= MEM_callocN(sizeof(*mw), "mainwindow_new");
		mw->app= app;
		mw->win= win;
		
		GHOST_SetWindowUserData(mw->win, windowdata_new(mw, mainwindow_handle));
		
		GHOST_InstallTimer(sys, 1000, 10000, mainwindow_timer_proc, mw);
		
		return mw;
	} else {
		return NULL;
	}
}
Пример #2
0
int main(int argc, char **argv)
{
	GHOST_GLSettings glSettings = {0};
	char *title1 = "gears - main window";
	char *title2 = "gears - secondary window";
	GHOST_EventConsumerHandle consumer = GHOST_CreateEventConsumer(processEvent, NULL);

	/* Create the system */
	shSystem = GHOST_CreateSystem();
	GHOST_AddEventConsumer(shSystem, consumer);
	
	if (shSystem)
	{
		/* Create the main window */
		sMainWindow = GHOST_CreateWindow(
		        shSystem, title1,
		        10, 64, 320, 200,
		        GHOST_kWindowStateNormal,
		        GHOST_kDrawingContextTypeOpenGL,
		        glSettings);
		if (!sMainWindow)
		{
			printf("could not create main window\n");
			exit(-1);
		}
		
		/* Create a secondary window */
		sSecondaryWindow = GHOST_CreateWindow(
		        shSystem,
		        title2,
		        340, 64, 320, 200,
		        GHOST_kWindowStateNormal,
		        GHOST_kDrawingContextTypeOpenGL,
		        glSettings);
		if (!sSecondaryWindow)
		{
			printf("could not create secondary window\n");
			exit(-1);
		}
		
		/* Install a timer to have the gears running */
		sGearsTimer = GHOST_InstallTimer(shSystem,
		                                 0,
		                                 10,
		                                 gearsTimerProc,
		                                 sMainWindow);

		/* Enter main loop */
		while (!sExitRequested)
		{
			if (!GHOST_ProcessEvents(shSystem, 0)) 
			{
#ifdef WIN32
				/* If there were no events, be nice to other applications */
				Sleep(10);
#endif
			}
			GHOST_DispatchEvents(shSystem);
		}
	}

	/* Dispose windows */
	if (GHOST_ValidWindow(shSystem, sMainWindow))
	{
		GHOST_DisposeWindow(shSystem, sMainWindow);
	}
	if (GHOST_ValidWindow(shSystem, sSecondaryWindow))
	{
		GHOST_DisposeWindow(shSystem, sSecondaryWindow);
	}

	/* Dispose the system */
	GHOST_DisposeSystem(shSystem);
	
	return 0;
}
Пример #3
0
int processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData)
{
	int handled = 1;
	int cursor;
	int visibility;
	GHOST_TEventKeyData *keyData = NULL;
	GHOST_TEventWheelData *wheelData = NULL;
	GHOST_DisplaySetting setting;
	GHOST_WindowHandle window = GHOST_GetEventWindow(hEvent);
	
	switch (GHOST_GetEventType(hEvent))
	{
#if 0
		case GHOST_kEventUnknown:
			break;
		case GHOST_kEventCursorButton:
			break;
		case GHOST_kEventCursorMove:
			break;
#endif
		case GHOST_kEventWheel:
		{
			wheelData = (GHOST_TEventWheelData *)GHOST_GetEventData(hEvent);
			if (wheelData->z > 0)
			{
				view_rotz += 5.f;
			}
			else {
				view_rotz -= 5.f;
			}
		}
		break;

		case GHOST_kEventKeyUp:
			break;
		
		case GHOST_kEventKeyDown:
		{
			keyData = (GHOST_TEventKeyData *)GHOST_GetEventData(hEvent);
			switch (keyData->key)
			{
				case GHOST_kKeyC:
				{
					cursor = sCursor;
					cursor++;
					if (cursor >= GHOST_kStandardCursorNumCursors)
					{
						cursor = GHOST_kStandardCursorFirstCursor;
					}
					sCursor = (GHOST_TStandardCursor)cursor;
					GHOST_SetCursorShape(window, sCursor);
				}
				break;
				case GHOST_kKeyF:
					if (!GHOST_GetFullScreen(shSystem))
					{
						/* Begin fullscreen mode */
						setting.bpp = 24;
						setting.frequency = 85;
						setting.xPixels = 640;
						setting.yPixels = 480;

						/*
						 * setting.bpp = 16;
						 * setting.frequency = 75;
						 * setting.xPixels = 640;
						 * setting.yPixels = 480;
						 */

						sFullScreenWindow = GHOST_BeginFullScreen(shSystem, &setting,

						                                          FALSE /* stereo flag */);
					}
					else {
						GHOST_EndFullScreen(shSystem);
						sFullScreenWindow = 0;
					}
					break;
				case GHOST_kKeyH:
				{
					visibility = GHOST_GetCursorVisibility(window);
					GHOST_SetCursorVisibility(window, !visibility);
				}
				break;
				case GHOST_kKeyQ:
					if (GHOST_GetFullScreen(shSystem))
					{
						GHOST_EndFullScreen(shSystem);
						sFullScreenWindow = 0;
					}
					sExitRequested = 1;
				case GHOST_kKeyT:
					if (!sTestTimer)
					{
						sTestTimer = GHOST_InstallTimer(shSystem, 0, 1000, testTimerProc, NULL);
					}
					else {
						GHOST_RemoveTimer(shSystem, sTestTimer);
						sTestTimer = 0;
					}
					break;
				case GHOST_kKeyW:
				{
					if (sMainWindow)
					{
						char *title = GHOST_GetTitle(sMainWindow);
						char *ntitle = malloc(strlen(title) + 2);

						sprintf(ntitle, "%s-", title);
						GHOST_SetTitle(sMainWindow, ntitle);
						
						free(ntitle);
						free(title);
					}
				}
				break;
				default:
					break;
			}
		}
		break;
		
		case GHOST_kEventWindowClose:
		{
			GHOST_WindowHandle window2 = GHOST_GetEventWindow(hEvent);
			if (window2 == sMainWindow)
			{
				sExitRequested = 1;
			}
			else {
				if (sGearsTimer)
				{
					GHOST_RemoveTimer(shSystem, sGearsTimer);
					sGearsTimer = 0;
				}
				GHOST_DisposeWindow(shSystem, window2);
			}
		}
		break;
		
		case GHOST_kEventWindowActivate:
			handled = 0;
			break;
		case GHOST_kEventWindowDeactivate:
			handled = 0;
			break;
		case GHOST_kEventWindowUpdate:
		{
			GHOST_WindowHandle window2 = GHOST_GetEventWindow(hEvent);
			if (!GHOST_ValidWindow(shSystem, window2))
				break;
			setViewPortGL(window2);
			drawGL();
			GHOST_SwapWindowBuffers(window2);
		}
		break;
		
		default:
			handled = 0;
			break;
	}
	return handled;
}