From: mfranz Date: Sun, 6 Nov 2005 23:53:30 +0000 (+0000) Subject: interpret negative dialog and coordinates as distance from the X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e4929c1dc1c44aca6808e00a9907a2a8ffcf798d;p=flightgear.git interpret negative dialog and coordinates as distance from the right/upper screen edge (analogous to the --geometry spec), assuming that we never want to draw outside the screen area; for this to work we need to write the original x/y coords back to overwrite the absolute, positive values that the layouter stored there --- diff --git a/src/GUI/dialog.cxx b/src/GUI/dialog.cxx index f7a38649d..ca8e19753 100644 --- a/src/GUI/dialog.cxx +++ b/src/GUI/dialog.cxx @@ -432,12 +432,20 @@ FGDialog::display (SGPropertyNode * props) wid.setDefaultFont(fnt, int(fnt->getPointSize())); int pw=0, ph=0; + int px, py, savex, savey; if(!userw || !userh) wid.calcPrefSize(&pw, &ph); pw = props->getIntValue("width", pw); ph = props->getIntValue("height", ph); - int px = props->getIntValue("x", (screenw - pw) / 2); - int py = props->getIntValue("y", (screenh - ph) / 2); + px = savex = props->getIntValue("x", (screenw - pw) / 2); + py = savey = props->getIntValue("y", (screenh - ph) / 2); + + // Negative x/y coordinates are interpreted as distance from the top/right + // corner rather than bottom/left. + if (px < 0) + px = screenw - pw + px; + if (py < 0) + py = screenh - ph + py; // Define "x", "y", "width" and/or "height" in the property tree if they // are not specified in the configuration file. @@ -448,9 +456,17 @@ FGDialog::display (SGPropertyNode * props) _object = makeObject(props, screenw, screenh); // Remove automatically generated properties, so the layout looks - // the same next time around. - if(!userx) props->removeChild("x"); - if(!usery) props->removeChild("y"); + // the same next time around, or restore x and y to preserve negative coords. + if(userx) + props->setIntValue("x", savex); + else + props->removeChild("x"); + + if(usery) + props->setIntValue("y", savey); + else + props->removeChild("y"); + if(!userw) props->removeChild("width"); if(!userh) props->removeChild("height");