First attempt at finding the screen pixel sizes. Can't test Xinerame, MSWindows, or X11 yet.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8204 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
d6bffb20a3
commit
7dc05cb20e
3
FL/Fl.H
3
FL/Fl.H
@ -773,7 +773,8 @@ public:
|
||||
screen_xywh(X, Y, W, H, e_x_root, e_y_root);
|
||||
}
|
||||
static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my);
|
||||
static void screen_xywh(int &X, int &Y, int &W, int &H, int n);
|
||||
static void screen_xywh(int &X, int &Y, int &W, int &H, int n);
|
||||
static void screen_dpi(float &h, float &v, int n=0);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
2
FL/mac.H
2
FL/mac.H
@ -145,7 +145,7 @@ public:
|
||||
void contains_GL_subwindow(void);
|
||||
void set_key_window(void);
|
||||
void set_cursor(Fl_Cursor);
|
||||
static int screen_init(XRectangle screens[]);
|
||||
static int screen_init(XRectangle screens[], float dpi[]);
|
||||
static CGImageRef CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h);
|
||||
static unsigned char *bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel);
|
||||
static Fl_Region intersect_region_and_rect(Fl_Region current, int x,int y,int w, int h);
|
||||
|
||||
@ -2715,7 +2715,7 @@ void Fl_X::set_cursor(Fl_Cursor c)
|
||||
cursor = icrsr;
|
||||
}
|
||||
|
||||
int Fl_X::screen_init(XRectangle screens[])
|
||||
int Fl_X::screen_init(XRectangle screens[], float dpi[])
|
||||
{
|
||||
NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];
|
||||
NSArray *a = [NSScreen screens];
|
||||
@ -2728,6 +2728,7 @@ int Fl_X::screen_init(XRectangle screens[])
|
||||
screens[num_screens].y = int(r.size.height - (r.origin.y + r.size.height));
|
||||
screens[num_screens].width = int(r.size.width);
|
||||
screens[num_screens].height = int(r.size.height);
|
||||
dpi[num_screens] = float([[a objectAtIndex:i] userSpaceScaleFactor])*72.0f;
|
||||
num_screens ++;
|
||||
if (num_screens >= 16) break;
|
||||
}
|
||||
|
||||
@ -56,17 +56,29 @@ typedef BOOL (WINAPI* fl_gmi_func)(HMONITOR, LPMONITORINFO);
|
||||
static fl_gmi_func fl_gmi = NULL; // used to get a proc pointer for GetMonitorInfoA
|
||||
|
||||
static RECT screens[16];
|
||||
static int dpi[16][2] = { { 0.0f, 0.0f } };
|
||||
|
||||
static BOOL CALLBACK screen_cb(HMONITOR mon, HDC, LPRECT r, LPARAM) {
|
||||
if (num_screens >= 16) return TRUE;
|
||||
|
||||
MONITORINFO mi;
|
||||
MONITORINFOEX mi;
|
||||
mi.cbSize = sizeof(mi);
|
||||
|
||||
// GetMonitorInfo(mon, &mi);
|
||||
// (but we use our self-aquired function pointer instead)
|
||||
if (fl_gmi(mon, &mi)) {
|
||||
screens[num_screens] = mi.rcWork;
|
||||
|
||||
// find the pixel size
|
||||
if (mi.cbSize == sizeof(mi)) {
|
||||
HDC screen = CreateDC(mi.szDevice, NULL, NULL, NULL);
|
||||
if (screen) {
|
||||
dpi[num_screens][0] = (float)GetDeviceCaps(screen, LOGPIXELSX);
|
||||
dpi[num_screens][1] = (float)GetDeviceCaps(screen, LOGPIXELSY);
|
||||
}
|
||||
ReleaseDC();
|
||||
}
|
||||
|
||||
num_screens ++;
|
||||
}
|
||||
return TRUE;
|
||||
@ -105,16 +117,18 @@ static void screen_init() {
|
||||
num_screens = 1;
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
XRectangle screens[16];
|
||||
static XRectangle screens[16];
|
||||
static float dpi[16];
|
||||
|
||||
static void screen_init() {
|
||||
num_screens = Fl_X::screen_init(screens);
|
||||
num_screens = Fl_X::screen_init(screens, dpi);
|
||||
}
|
||||
#elif HAVE_XINERAMA
|
||||
# include <X11/extensions/Xinerama.h>
|
||||
|
||||
// Screen data...
|
||||
static XineramaScreenInfo *screens;
|
||||
static float dpi[2];
|
||||
|
||||
static void screen_init() {
|
||||
if (!fl_display) fl_open_display();
|
||||
@ -122,10 +136,22 @@ static void screen_init() {
|
||||
if (XineramaIsActive(fl_display)) {
|
||||
screens = XineramaQueryScreens(fl_display, &num_screens);
|
||||
} else num_screens = 1;
|
||||
|
||||
int mm = DisplayWidthMM(fl_display, fl_screen);
|
||||
dpi[0] = mm ? monitor.w()*25.4f/mm : 0.0f;
|
||||
mm = DisplayHeightMM(fl_display, fl_screen);
|
||||
dpi[1] = mm ? monitor.h()*25.4f/mm : dpi[0];
|
||||
}
|
||||
#else
|
||||
static XRectangle screen;
|
||||
static float dpi[2];
|
||||
static void screen_init() {
|
||||
num_screens = 1;
|
||||
if (!fl_display) fl_open_display();
|
||||
int mm = DisplayWidthMM(fl_display, fl_screen);
|
||||
dpi[0] = mm ? monitor.w()*25.4f/mm : 0.0f;
|
||||
mm = DisplayHeightMM(fl_display, fl_screen);
|
||||
dpi[1] = mm ? monitor.h()*25.4f/mm : dpi[0];
|
||||
}
|
||||
#endif // WIN32
|
||||
|
||||
@ -252,6 +278,41 @@ void Fl::screen_xywh(int &X, int &Y, int &W, int &H, int n) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Gets the screen resolution in dots-per-inch for the given screen.
|
||||
\param[out] h, v horizontal and vertical resolution
|
||||
\param[in] n the screen number (0 to Fl::screen_count() - 1)
|
||||
\see void screen_xywh(int &x, int &y, int &w, int &h, int mx, int my)
|
||||
*/
|
||||
void Fl::screen_dpi(float &h, float &v, int n)
|
||||
{
|
||||
if (!num_screens) screen_init();
|
||||
h = v = 0.0f;
|
||||
|
||||
#ifdef WIN32
|
||||
if (n >= 0 && n < num_screens) {
|
||||
h = float(dpi[n][0]);
|
||||
v = float(dpi[n][1]);
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
if (n >= 0 && n < num_screens) {
|
||||
h = v = dpi[n];
|
||||
}
|
||||
#elif HAVE_XINERAMA
|
||||
if (n >= 0 && n < num_screens) {
|
||||
h = dpi[0];
|
||||
v = dpi[1];
|
||||
}
|
||||
#else
|
||||
if (n >= 0 && n < num_screens) {
|
||||
h = dpi[0];
|
||||
v = dpi[1];
|
||||
}
|
||||
#endif // WIN32
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// End of "$Id$".
|
||||
//
|
||||
|
||||
@ -30,6 +30,9 @@
|
||||
#include <FL/Fl_Box.H>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
float h, v;
|
||||
Fl::screen_dpi(h, v);
|
||||
printf("Screen res is %g x %g ppi\n", h, v);
|
||||
Fl_Window *window = new Fl_Window(340,180);
|
||||
Fl_Box *box = new Fl_Box(20,40,300,100,"Hello, World!");
|
||||
box->box(FL_UP_BOX);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user