]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/WindowBuilder.cxx
NavDisplay: fix update lag when switching range or centre.
[flightgear.git] / src / Main / WindowBuilder.cxx
index aaabbb2dbb58734e82b05e7f8efb6693ad5a7e03..cb19eb77261c8459d0b00e9db02b2775b0c77ac5 100644 (file)
@@ -35,6 +35,8 @@ string makeName(const string& prefix, int num)
 
 ref_ptr<WindowBuilder> WindowBuilder::windowBuilder;
 
+const string WindowBuilder::defaultWindowName("FlightGear");
+
 void WindowBuilder::initWindowBuilder(bool stencil)
 {
     windowBuilder = new WindowBuilder(stencil);
@@ -50,48 +52,58 @@ WindowBuilder::makeDefaultTraits(bool stencil)
 {
     GraphicsContext::WindowingSystemInterface* wsi
         = osg::GraphicsContext::getWindowingSystemInterface();
-    int w = fgGetInt("/sim/startup/xsize");
-    int h = fgGetInt("/sim/startup/ysize");
-    int bpp = fgGetInt("/sim/rendering/bits-per-pixel");
-    bool alpha = fgGetBool("/sim/rendering/clouds3d-enable");
-    bool fullscreen = fgGetBool("/sim/startup/fullscreen");
-
     GraphicsContext::Traits* traits = new osg::GraphicsContext::Traits;
+
     traits->readDISPLAY();
+    if (traits->displayNum < 0)
+        traits->displayNum = 0;
+    if (traits->screenNum < 0)
+        traits->screenNum = 0;
+
+    int bpp = fgGetInt("/sim/rendering/bits-per-pixel");
+    bool alpha = fgGetBool("/sim/rendering/clouds3d-enable");
     int cbits = (bpp <= 16) ?  5 :  8;
     int zbits = (bpp <= 16) ? 16 : 24;
     traits->red = traits->green = traits->blue = cbits;
     traits->depth = zbits;
     if (alpha)
-       traits->alpha = 8;
+        traits->alpha = 8;
+
     if (stencil)
-       traits->stencil = 8;
+        traits->stencil = 8;
+
+    unsigned screenwidth = 0;
+    unsigned screenheight = 0;
+    wsi->getScreenResolution(*traits, screenwidth, screenheight);
+
     traits->doubleBuffer = true;
     traits->mipMapGeneration = true;
     traits->windowName = "FlightGear";
     // XXX should check per window too.
     traits->sampleBuffers = fgGetBool("/sim/rendering/multi-sample-buffers", traits->sampleBuffers);
-    traits->samples = fgGetBool("/sim/rendering/multi-samples", traits->samples);
+    traits->samples = fgGetInt("/sim/rendering/multi-samples", traits->samples);
     traits->vsync = fgGetBool("/sim/rendering/vsync-enable", traits->vsync);
-    if (fullscreen) {
-        unsigned width = 0;
-        unsigned height = 0;
-        wsi->getScreenResolution(*traits, width, height);
-       traits->windowDecoration = false;
-        traits->width = width;
-        traits->height = height;
+    traits->windowDecoration = !fgGetBool("/sim/startup/fullscreen");
+
+    if (!traits->windowDecoration) {
+        // fullscreen
         traits->supportsResize = false;
+        traits->width = screenwidth;
+        traits->height = screenheight;
+        SG_LOG(SG_VIEW,SG_DEBUG,"Using full screen size for window: " << screenwidth << " x " << screenheight);
     } else {
-       traits->windowDecoration = true;
+        // window
+        int w = fgGetInt("/sim/startup/xsize");
+        int h = fgGetInt("/sim/startup/ysize");
+        traits->supportsResize = true;
         traits->width = w;
         traits->height = h;
-#if defined(WIN32) || defined(__APPLE__)
-        // Ugly Hack, why does CW_USEDEFAULT works like phase of the moon?
-        // Mac also needs this to show window frame, menubar and Docks
-        traits->x = 100;
-        traits->y = 100;
-#endif
-        traits->supportsResize = true;
+        if ((w>0)&&(h>0))
+        {
+            traits->x = ((unsigned)w>screenwidth) ? 0 : (screenwidth-w)/3;
+            traits->y = ((unsigned)h>screenheight) ? 0 : (screenheight-h)/3;
+        }
+        SG_LOG(SG_VIEW,SG_DEBUG,"Using initial window size: " << w << " x " << h);
     }
     return traits;
 }
@@ -146,7 +158,7 @@ GraphicsWindow* WindowBuilder::buildWindow(const SGPropertyNode* winNode)
     string windowName;
     if (winNode->hasChild("window-name"))
         windowName = winNode->getStringValue("window-name");
-    else if (winNode->hasChild("name")) 
+    else if (winNode->hasChild("name"))
         windowName = winNode->getStringValue("name");
     GraphicsWindow* result = 0;
     if (!windowName.empty()) {
@@ -159,8 +171,11 @@ GraphicsWindow* WindowBuilder::buildWindow(const SGPropertyNode* winNode)
     int traitsSet = setFromProperty(traits->hostName, winNode, "host-name");
     traitsSet |= setFromProperty(traits->displayNum, winNode, "display");
     traitsSet |= setFromProperty(traits->screenNum, winNode, "screen");
+
     const SGPropertyNode* fullscreenNode = winNode->getNode("fullscreen");
+
     if (fullscreenNode && fullscreenNode->getBoolValue()) {
+        // fullscreen mode
         unsigned width = 0;
         unsigned height = 0;
         wsi->getScreenResolution(*traits, width, height);
@@ -168,9 +183,16 @@ GraphicsWindow* WindowBuilder::buildWindow(const SGPropertyNode* winNode)
         traits->width = width;
         traits->height = height;
         traits->supportsResize = false;
+        traits->x = 0;
+        traits->y = 0;
         traitsSet = 1;
     } else {
         int resizable = 0;
+        if (fullscreenNode && !fullscreenNode->getBoolValue())
+        {
+            traits->windowDecoration = true;
+            resizable = 1;
+        }
         resizable |= setFromProperty(traits->windowDecoration, winNode,
                                      "decoration");
         resizable |= setFromProperty(traits->width, winNode, "width");
@@ -194,7 +216,6 @@ GraphicsWindow* WindowBuilder::buildWindow(const SGPropertyNode* winNode)
     if (traitsSet) {
         GraphicsContext* gc = GraphicsContext::createGraphicsContext(traits);
         if (gc) {
-            gc->realize();
             GraphicsWindow* window = WindowSystemAdapter::getWSA()
                 ->registerWindow(gc, traits->windowName);
             if (drawGUI)
@@ -204,24 +225,29 @@ GraphicsWindow* WindowBuilder::buildWindow(const SGPropertyNode* winNode)
             return 0;
         }
     } else {
+        // XXX What if the window has no traits, but does have a name?
+        // We should create a "default window" registered with that name.
         return getDefaultWindow();
     }
 }
 
 GraphicsWindow* WindowBuilder::getDefaultWindow()
 {
-    if (defaultWindow.valid())
-        return defaultWindow.get();
+    GraphicsWindow* defaultWindow
+        = WindowSystemAdapter::getWSA()->findWindow(defaultWindowName);
+    if (defaultWindow)
+        return defaultWindow;
     GraphicsContext::Traits* traits
         = new GraphicsContext::Traits(*defaultTraits);
     traits->windowName = "FlightGear";
+    
     GraphicsContext* gc = GraphicsContext::createGraphicsContext(traits);
     if (gc) {
-        gc->realize();
         defaultWindow = WindowSystemAdapter::getWSA()
-            ->registerWindow(gc, traits->windowName);
-        return defaultWindow.get();
+            ->registerWindow(gc, defaultWindowName);
+        return defaultWindow;
     } else {
+        SG_LOG(SG_VIEW, SG_ALERT, "getDefaultWindow: failed to create GraphicsContext");
         return 0;
     }
 }