diff options
| author | Manolo Gouy <Manolo> | 2011-03-12 21:36:21 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2011-03-12 21:36:21 +0000 |
| commit | 7aa48e19b9971c6ce902002c1421223a84a1a447 (patch) | |
| tree | 67b51ebf94e910eee1f00d07c4afa832bde7056f /src/screen_xywh.cxx | |
| parent | c4099faffeb7bb2b5a1d4d3ace81021224f711c5 (diff) | |
Fix STR #2575: use the screen that intersects most of the window when made fullscreen.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8515 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/screen_xywh.cxx')
| -rw-r--r-- | src/screen_xywh.cxx | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/screen_xywh.cxx b/src/screen_xywh.cxx index 9ed788d0b..3cac43fbb 100644 --- a/src/screen_xywh.cxx +++ b/src/screen_xywh.cxx @@ -284,6 +284,41 @@ void Fl::screen_xywh(int &X, int &Y, int &W, int &H, int n) { H = Fl::h(); } +static inline float fl_intersection(int x1, int y1, int w1, int h1, + int x2, int y2, int w2, int h2) { + if(x1+w1 < x2 || x2+w2 < x1 || y1+h1 < y2 || y2+h2 < y1) + return 0.; + int int_left = x1 > x2 ? x1 : x2; + int int_right = x1+w1 > x2+w2 ? x2+w2 : x1+w1; + int int_top = y1 > y2 ? y1 : y2; + int int_bottom = y1+h1 > y2+h2 ? y2+h2 : y1+h1; + return (float)(int_right - int_left) * (int_bottom - int_top); +} + +/** + Gets the screen bounding rect for the screen + which intersects the most with the rectangle + defined by \p mx, \p my, \p mw, \p mh. + \param[out] X,Y,W,H the corresponding screen bounding box + \param[in] mx, my, mw, mh the rectangle to search for intersection with + \see void screen_xywh(int &X, int &Y, int &W, int &H, int n) + */ +void Fl::screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my, int mw, int mh) { + int best_screen = 0; + float best_intersection = 0.; + for(int i = 0; i < Fl::screen_count(); i++) { + int sx, sy, sw, sh; + Fl::screen_xywh(sx, sy, sw, sh, i); + float sintersection = fl_intersection(mx, my, mw, mh, sx, sy, sw, sh); + if(sintersection > best_intersection) { + best_screen = i; + best_intersection = sintersection; + } + } + screen_xywh(X, Y, W, H, best_screen); +} + + /** Gets the screen resolution in dots-per-inch for the given screen. |
