本文整理汇总了C++中WindowApplication::OnInitialize方法的典型用法代码示例。如果您正苦于以下问题:C++ WindowApplication::OnInitialize方法的具体用法?C++ WindowApplication::OnInitialize怎么用?C++ WindowApplication::OnInitialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WindowApplication
的用法示例。
在下文中一共展示了WindowApplication::OnInitialize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Main
//.........这里部分代码省略.........
EventTypeSpec eventType;
eventType.eventClass = kEventClassWindow;
eventType.eventKind = kEventWindowClose;
EventHandlerUPP handlerUPP = NewEventHandlerUPP(ProcessWindowClose);
InstallWindowEventHandler(window, handlerUPP, 1, &eventType, 0, 0);
// Install window bounds change handler.
eventType.eventKind = kEventWindowBoundsChanged;
handlerUPP = NewEventHandlerUPP(ProcessWindowBoundsChange);
InstallWindowEventHandler(window, handlerUPP, 1, &eventType, 0, 0);
// Install window zoomed handler.
eventType.eventKind = kEventWindowZoomed;
handlerUPP = NewEventHandlerUPP(ProcessWindowZoomed);
InstallWindowEventHandler(window, handlerUPP, 1, &eventType, 0, 0);
// Install window redraw handler.
eventType.eventKind = kEventWindowDrawContent;
handlerUPP = NewEventHandlerUPP(ProcessWindowRedraw);
InstallWindowEventHandler(window, handlerUPP, 1, &eventType, 0, 0);
// Install key down handler.
EventTypeSpec eventTypes[2];
eventTypes[0].eventClass = kEventClassKeyboard;
eventTypes[0].eventKind = kEventRawKeyDown;
eventTypes[1].eventClass = kEventClassKeyboard;
eventTypes[1].eventKind = kEventRawKeyRepeat;
handlerUPP = NewEventHandlerUPP(ProcessKeyDown);
InstallWindowEventHandler(window, handlerUPP, 2, eventTypes, 0, 0);
// Install key up handler.
eventTypes[0].eventClass = kEventClassKeyboard;
eventTypes[0].eventKind = kEventRawKeyUp;
handlerUPP = NewEventHandlerUPP(ProcessKeyUp);
InstallWindowEventHandler(window, handlerUPP, 1, eventTypes, 0, 0);
// Install key-modifier-changed handler.
eventTypes[0].eventClass = kEventClassKeyboard;
eventTypes[0].eventKind = kEventRawKeyModifiersChanged;
handlerUPP = NewEventHandlerUPP(ProcessKeyModifierChanged);
InstallWindowEventHandler(window, handlerUPP, 1, eventTypes, 0, 0);
// Install mouse down handler.
eventType.eventClass = kEventClassMouse;
eventType.eventKind = kEventMouseDown;
handlerUPP = NewEventHandlerUPP(ProcessMouseDown);
InstallWindowEventHandler(window, handlerUPP, 1, &eventType, 0, 0);
// Install mouse up handler.
eventType.eventKind = kEventMouseUp;
handlerUPP = NewEventHandlerUPP(ProcessMouseUp);
InstallWindowEventHandler(window, handlerUPP, 1, &eventType, 0, 0);
// Install mouse drag handler.
eventType.eventKind = kEventMouseDragged;
handlerUPP = NewEventHandlerUPP(ProcessMouseDragged);
InstallWindowEventHandler(window, handlerUPP, 1, &eventType, 0, 0);
// Install mouse move handler.
eventType.eventKind = kEventMouseMoved;
handlerUPP = NewEventHandlerUPP(ProcessMouseMoved);
InstallWindowEventHandler(window, handlerUPP, 1, &eventType, 0, 0);
// Create timer.
EventLoopTimerRef timer;
InstallEventLoopTimer(GetMainEventLoop(), 0, kEventDurationMillisecond,
NewEventLoopTimerUPP(ProcessTimer), 0, &timer);
if (!theApp->OnInitialize())
{
return -4;
}
// Set auto-repeat key timing.
short keyRepeatThresh = LMGetKeyRepThresh();
short keyThresh = LMGetKeyThresh();
LMSetKeyRepThresh(1);
LMSetKeyThresh(30);
// The default OnPreidle() clears the buffers. Allow the application to
// fill them before the window is shown and before the event loop starts.
theApp->OnPreidle();
// Display the window.
ShowWindow(window);
// Run event loop.
RunApplicationEventLoop();
// Reset auto-repeat key timing to initial value.
LMSetKeyRepThresh(keyRepeatThresh);
LMSetKeyThresh(keyThresh);
theApp->OnTerminate();
delete0(mRenderer);
RemoveEventLoopTimer(timer);
DisposeMenu(menu);
return 0;
}
示例2: Main
//.........这里部分代码省略.........
attributes[pos++] = 1;
attributes[pos++] = WGL_DRAW_TO_WINDOW_ARB;
attributes[pos++] = 1;
attributes[pos++] = WGL_ACCELERATION_ARB;
attributes[pos++] = WGL_FULL_ACCELERATION_ARB;
attributes[pos++] = WGL_PIXEL_TYPE_ARB;
attributes[pos++] = WGL_TYPE_RGBA_ARB;
attributes[pos++] = WGL_RED_BITS_ARB;
attributes[pos++] = 8;
attributes[pos++] = WGL_GREEN_BITS_ARB;
attributes[pos++] = 8;
attributes[pos++] = WGL_BLUE_BITS_ARB;
attributes[pos++] = 8;
attributes[pos++] = WGL_ALPHA_BITS_ARB;
attributes[pos++] = 8;
attributes[pos++] = WGL_DEPTH_BITS_ARB;
attributes[pos++] = 24;
attributes[pos++] = WGL_STENCIL_BITS_ARB;
attributes[pos++] = 8;
attributes[pos++] = WGL_DOUBLE_BUFFER_ARB;
attributes[pos++] = 1;
attributes[pos++] = WGL_SAMPLE_BUFFERS_ARB;
attributes[pos++] = 1;
attributes[pos++] = WGL_SAMPLES_ARB;
attributes[pos++] = numMultisamples;
attributes[pos++] = 0; // list is zero-terminated
unsigned int numFormats = 0;
BOOL successful = wglChoosePixelFormatARB(input.mRendererDC,
attributes, 0, 1, &input.mPixelFormat, &numFormats);
if (successful && numFormats > 0)
{
// The card supports multisampling with the requested number of
// samples. Recreate the window and renderer.
delete0(mRenderer);
gsIgnoreWindowDestroy = true;
DestroyWindow(handle);
handle = CreateWindow(sWindowClass, theApp->GetWindowTitle(),
WS_OVERLAPPEDWINDOW, theApp->GetXPosition(),
theApp->GetYPosition(), rect.right - rect.left + 1,
rect.bottom - rect.top + 1, 0, 0, 0, 0);
theApp->SetWindowID(PtrToInt(handle));
input.mWindowHandle = handle;
mRenderer = new0 Renderer(input, theApp->GetWidth(),
theApp->GetHeight(), mColorFormat, mDepthStencilFormat,
mNumMultisamples);
}
}
#endif
if (theApp->OnInitialize())
{
// The default OnPreidle() clears the buffers. Allow the application
// to fill them before the window is shown and before the event loop
// starts.
theApp->OnPreidle();
// Display the window.
ShowWindow(handle, SW_SHOW);
UpdateWindow(handle);
// Start the message pump.
bool applicationRunning = true;
while (applicationRunning)
{
MSG msg;
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
applicationRunning = false;
continue;
}
HACCEL accel = 0;
if (!TranslateAccelerator(handle, accel, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
{
theApp->OnIdle();
}
}
}
theApp->OnTerminate();
delete0(mRenderer);
#ifdef WM5_USE_DX9
input.mDriver->Release();
#endif
return 0;
}
示例3: Main
//.........这里部分代码省略.........
unsigned int width = (unsigned int)theApp->GetWidth();
unsigned int height = (unsigned int)theApp->GetHeight();
unsigned int borderWidth = 0;
unsigned long valueMask = CWBorderPixel | CWColormap | CWEventMask;
Window window = XCreateWindow(display, rootWindow, xPos, yPos, width,
height, borderWidth, input.mVisual->depth, InputOutput,
input.mVisual->visual, valueMask, &windowAttributes);
XSizeHints hints;
hints.flags = PPosition | PSize;
hints.x = xPos;
hints.y = yPos;
hints.width = width;
hints.height = height;
XSetNormalHints(display, window, &hints);
const char* iconName = theApp->GetWindowTitle();
Pixmap iconPixmap = None;
XSetStandardProperties(display, window, theApp->GetWindowTitle(),
iconName, iconPixmap, arguments, numArguments, &hints);
// Intercept the close-window event when the user selects the
// window close button. The event is a "client message".
Atom wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", False);
XSetWMProtocols(display, window, &wmDelete, 1);
// Finish the construction of the renderer.
GlxRendererData* data = (GlxRendererData*)mRenderer->mData;
if (!data->FinishConstruction(window, mRenderer))
{
return -5;
}
if (theApp->OnInitialize())
{
// The default OnPreidle() clears the buffers. Allow the application
// to fill them before the window is shown and before the event loop
// starts.
theApp->OnPreidle();
// Display the window.
XMapWindow(display, window);
// Start the message pump.
bool applicationRunning = true;
while (applicationRunning)
{
if (!XPending(display))
{
theApp->OnIdle();
continue;
}
XEvent evt;
XNextEvent(display, &evt);
int index;
bool state;
if (evt.type == ButtonPress || evt.type == ButtonRelease)
{
theApp->OnMouseClick(evt.xbutton.button, evt.xbutton.type,
evt.xbutton.x, evt.xbutton.y, evt.xbutton.state);
if (evt.type == ButtonPress)
{
index = GLXAPP_BUTTONDOWN + evt.xbutton.button;
示例4: Main
//----------------------------------------------------------------------------
int WindowApplication::Main (int, char**)
{
WindowApplication* theApp = (WindowApplication*)TheApplication;
theApp->KEY_TERMINATE = WindowApplication::KEY_ESCAPE;
// OpenGL uses a projection matrix for depth in [-1,1].
Camera::SetDefaultDepthType(Camera::PM_DEPTH_MINUS_ONE_TO_ONE);
// Register the termination function so that we can destroy the window
// after GLUT abnormally calls 'exit'.
if (atexit(Terminate) != 0)
{
return -1;
}
// Give GLUT dummy arguments, because we are not allowing control to
// GLUT via command-line parameters.
int numArguments = 1;
char* arguments[1];
arguments[0] = new char[6];
strcpy(arguments[0], "dummy");
glutInit(&numArguments, arguments);
delete[] arguments[0];
// We will always use double buffering, 32-bit RGBA front buffer,
// depth buffer, and stencil buffer.
if (mNumMultisamples == 0)
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
}
else
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL
| GLUT_MULTISAMPLE);
mNumMultisamples = glutGet(GLUT_WINDOW_NUM_SAMPLES);
}
// Allow work to be done before the window is created.
if (!theApp->OnPrecreate())
{
return -2;
}
// Create window and renderer. Multisampling is not supported.
glutInitWindowSize(theApp->GetWidth(), theApp->GetHeight());
RendererInput input;
input.mWindowID = glutCreateWindow(theApp->GetWindowTitle());
input.mDisableVerticalSync = true;
mRenderer = new0 Renderer(input, theApp->GetWidth(), theApp->GetHeight(),
mColorFormat, mDepthStencilFormat, mNumMultisamples);
// Save the handle as an 'int' for portable handle storage.
theApp->SetWindowID(input.mWindowID);
// Set the callbacks for event handling.
glutReshapeFunc(ReshapeCallback);
glutDisplayFunc(DisplayCallback);
glutIdleFunc(IdleCallback);
glutKeyboardFunc(KeyDownCallback);
glutKeyboardUpFunc(KeyUpCallback);
glutSpecialFunc(SpecialKeyDownCallback);
glutSpecialUpFunc(SpecialKeyUpCallback);
glutMouseFunc(MouseClickCallback);
glutMotionFunc(MotionCallback);
glutPassiveMotionFunc(PassiveMotionCallback);
if (theApp->OnInitialize())
{
// The default OnPreidle() clears the buffers. Allow the application
// to fill them before the window is shown and before the event loop
// starts.
theApp->OnPreidle();
glutMainLoop();
}
// Because glutMainLoop never exits, the clean-up is handled via the
// static Terminate in this file (registered with 'atexit').
return 0;
}