📄 glutwindow.cpp
字号:
window->UnlockGL(); // now, if the window was top-level, delete its BWindow if(!window->parent) { bwindow->Quit(); } else { // else, detach it from the BWindow and delete it window->RemoveSelf(); delete window; bwindow->Unlock(); } // relock GL if the current window is still valid if(gState.currentWindow) gState.currentWindow->LockGL();}/*********************************************************** * FUNCTION: __glutDestroyAllWindows * * DESCRIPTION: destroy all windows when exit() is called * this seems to be necessary to avoid delays * and crashes when using BDirectWindow ***********************************************************/void __glutDestroyAllWindows() { for(int i=0; i<gState.windowListSize; i++) { if (gState.windowList[i]) { glutDestroyWindow(i + 1); } } gState.display->Lock(); gState.display->Quit(); status_t ignored; wait_for_thread(gState.appthread, &ignored);}/*********************************************************** * FUNCTION: glutPostRedisplay (4.5) * * DESCRIPTION: mark window as needing redisplay ***********************************************************/void glutPostRedisplay() { gState.currentWindow->Window()->Lock(); gState.currentWindow->anyevents = true; gState.currentWindow->displayEvent = true; gState.currentWindow->Window()->Unlock(); gBlock.QuickNewEvent();}/*********************************************************** * FUNCTION: glutPostWindowRedisplay * * DESCRIPTION: mark window as needing redisplay ***********************************************************/void glutPostWindowRedisplay(int win) { GlutWindow *gwin = gState.windowList[win - 1]; gwin->Window()->Lock(); gwin->anyevents = true; gwin->displayEvent = true; gwin->Window()->Unlock(); gBlock.QuickNewEvent();}/*********************************************************** * FUNCTION: glutSwapBuffers (4.6) * * DESCRIPTION: swap buffers ***********************************************************/void glutSwapBuffers() { gState.currentWindow->SwapBuffers();}/*********************************************************** * FUNCTION: glutPositionWindow (4.7) * * DESCRIPTION: move window ***********************************************************/void glutPositionWindow(int x, int y) { BDirectWindow *win = dynamic_cast<BDirectWindow*>(gState.currentWindow->Window()); win->Lock(); if (gState.currentWindow->parent) gState.currentWindow->MoveTo(x, y); // move the child view else { if(win->IsFullScreen()) { win->SetFullScreen(false); } win->MoveTo(x, y); // move the window } win->Unlock();}/*********************************************************** * FUNCTION: glutReshapeWindow (4.8) * * DESCRIPTION: reshape window (we'll catch the callback * when the view gets a Draw() message ***********************************************************/void glutReshapeWindow(int width, int height) { BDirectWindow *win = dynamic_cast<BDirectWindow*>(gState.currentWindow->Window()); win->Lock(); if (gState.currentWindow->parent) gState.currentWindow->ResizeTo(width-1, height-1); // resize the child else { if(win->IsFullScreen()) { win->SetFullScreen(false); } win->ResizeTo(width-1, height-1); // resize the parent } win->Unlock();}/*********************************************************** * FUNCTION: glutFullScreen (4.9) * * DESCRIPTION: makes the window full screen ***********************************************************/void glutFullScreen() { BDirectWindow *win = dynamic_cast<BDirectWindow*>(gState.currentWindow->Window()); win->Lock(); win->SetFullScreen(true); win->Unlock();}/*********************************************************** * FUNCTION: glutPopWindow (4.10) * glutPushWindow * * DESCRIPTION: change the stacking order of the current window * NOTE: I can't figure out how to do this for windows, * and there is no concept of "stacking order" for * subwindows, so these are currently no-ops. ***********************************************************/void glutPopWindow() { }void glutPushWindow() { }/*********************************************************** * FUNCTION: glutShowWindow (4.11) * glutHideWindow * glutIconifyWindow * * DESCRIPTION: change display status of current window ***********************************************************/void glutShowWindow() { gState.currentWindow->Window()->Lock(); if (gState.currentWindow->parent) // subwindow gState.currentWindow->Show(); else { if(gState.currentWindow->Window()->IsHidden()) gState.currentWindow->Window()->Show(); // show the actual BWindow gState.currentWindow->Window()->Minimize(false); } gState.currentWindow->Window()->Unlock();}void glutHideWindow() { gState.currentWindow->Window()->Lock(); if (gState.currentWindow->parent) // subwindow gState.currentWindow->Hide(); else gState.currentWindow->Window()->Hide(); // show the actual BWindow gState.currentWindow->Window()->Unlock();}void glutIconifyWindow() { if(gState.currentWindow->parent) __glutFatalError("can't iconify a subwindow"); gState.currentWindow->Window()->Lock(); gState.currentWindow->Window()->Minimize(true); gState.currentWindow->Window()->Unlock();}/*********************************************************** * FUNCTION: glutSetWindowTitle (4.12) * glutSetIconTitle * * DESCRIPTION: set the window title (icon title is same) ***********************************************************/void glutSetWindowTitle(const char *name) { if (gState.currentWindow->parent) __glutFatalError("glutSetWindowTitle: isn't a top-level window"); gState.currentWindow->Window()->Lock(); gState.currentWindow->Window()->SetTitle(name); gState.currentWindow->Window()->Unlock();}void glutSetIconTitle(const char *name) { glutSetWindowTitle(name);}/*********************************************************** * FUNCTION: __glutConvertDisplayMode * * DESCRIPTION: converts the current display mode into a BGLView * display mode, printing warnings as appropriate. * * PARAMETERS: if options is non-NULL, the current display mode is * returned in it. * * RETURNS: 1 if the current display mode is possible, else 0 ***********************************************************/int __glutConvertDisplayMode(unsigned long *options) { if (gState.displayString) { /* __glutDisplayString should be NULL except if glutInitDisplayString has been called to register a different display string. Calling glutInitDisplayString means using a string instead of an integer mask determine the visual to use. This big ugly code is in glutDstr.cpp */ return __glutConvertDisplayModeFromString(options); } if(options) { ulong newoptions = 0; if(gState.displayMode & GLUT_ACCUM) newoptions |= BGL_ACCUM; if(gState.displayMode & GLUT_ALPHA) newoptions |= BGL_ALPHA; if(gState.displayMode & GLUT_DEPTH) newoptions |= BGL_DEPTH; if(gState.displayMode & GLUT_DOUBLE) newoptions |= BGL_DOUBLE; if(gState.displayMode & GLUT_STENCIL) newoptions |= BGL_STENCIL; *options = newoptions; } if(gState.displayMode & GLUT_INDEX) { __glutWarning("BeOS doesn't support indexed color"); return 0; } if(gState.displayMode & GLUT_MULTISAMPLE) { return 1; // try to go without multisampling } if(gState.displayMode & GLUT_STEREO) { __glutWarning("BeOS doesn't support stereo windows"); return 0; } if(gState.displayMode & GLUT_LUMINANCE) { __glutWarning("BeOS doesn't support luminance color model"); return 0; } return 1; // visual supported}/*********************************************************** * CLASS: GlutBWindow * * DESCRIPTION: very thin wrapper around BWindow ***********************************************************/GlutBWindow::GlutBWindow(BRect frame, char *name) : BDirectWindow(frame, name, B_TITLED_WINDOW, 0) { fConnectionDisabled = false; bgl = 0; SetPulseRate(100000); if (!SupportsWindowMode()) { __glutFatalError("video card doesn't support windowed operation"); }}void GlutBWindow::DirectConnected( direct_buffer_info *info ) { bgl->DirectConnected(info); if(bgl && !fConnectionDisabled) { bgl->EnableDirectMode(true); } int newVisState; if((info->buffer_state & B_DIRECT_MODE_MASK) == B_DIRECT_START) { bgl->visible = true; } if(!bgl->visible || info->buffer_state == B_DIRECT_STOP) newVisState = GLUT_HIDDEN; else { if (info->clip_list_count == 0) newVisState = GLUT_FULLY_COVERED; else if (info->clip_list_count == 1) newVisState = GLUT_FULLY_RETAINED; else newVisState = GLUT_PARTIALLY_RETAINED; } if(newVisState != bgl->visState) { bgl->visState = newVisState; bgl->anyevents = bgl->windowStatusEvent = true; gBlock.NewEvent(); }}GlutBWindow::~GlutBWindow() { fConnectionDisabled = true; if(bgl) { bgl->EnableDirectMode(false); } if(!IsHidden()) Hide(); Sync();} bool GlutBWindow::QuitRequested() { gState.quitAll = true; gBlock.NewEvent(); return false; // don't quit now, wait for main thread to do it}void GlutBWindow::Minimize(bool minimize) { bgl->visible = !minimize; BWindow::Minimize(minimize);}void GlutBWindow::Hide() { BWindow::Hide(); bgl->visible = false;}void GlutBWindow::Show() { BWindow::Show(); bgl->visible = true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -