Skip to content

Instantly share code, notes, and snippets.

@toolbits
Created April 18, 2017 05:32
Show Gist options
  • Save toolbits/76a94ef0f4c9240d5ba0cec9fa83c99d to your computer and use it in GitHub Desktop.
Save toolbits/76a94ef0f4c9240d5ba0cec9fa83c99d to your computer and use it in GitHub Desktop.
vector<ofRectangle> ofApp::getMonitorInfo(int* count, ofRectangle* whole)
{
GLFWmonitor** monitor;
GLFWvidmode const* mode;
ofRectangle rect;
vector<ofRectangle> temp;
int c;
int x;
int y;
int i;
vector<ofRectangle> result;
monitor = glfwGetMonitors(&c);
if (c > 0) {
rect.set(FLT_MAX, FLT_MAX, FLT_MIN, FLT_MIN);
for (i = 0; i < c; ++i) {
mode = glfwGetVideoMode(monitor[i]);
glfwGetMonitorPos(monitor[i], &x, &y);
if (x < rect.x) {
rect.x = x;
}
if (y < rect.y) {
rect.y = y;
}
if (x + mode->width > rect.width) {
rect.width = x + mode->width;
}
if (y + mode->height > rect.height) {
rect.height = y + mode->height;
}
temp.push_back(ofRectangle(x, y, mode->width, mode->height));
}
rect.width -= rect.x;
rect.height -= rect.y;
for (i = 0; i < temp.size(); ++i) {
temp[i].x -= rect.x;
temp[i].y -= rect.y;
}
rect.x = 0;
rect.y = 0;
if (count != NULL) {
*count = c;
}
if (whole != NULL) {
*whole = rect;
}
while (temp.size() > 0) {
rect.x = FLT_MAX;
c = -1;
for (i = 0; i < temp.size(); ++i) {
if (temp[i].x < rect.x) {
rect.x = temp[i].x;
c = i;
}
}
if (c > -1) {
result.push_back(temp[c]);
temp.erase(temp.begin() + c);
}
}
}
else {
if (count != NULL) {
*count = 0;
}
if (whole != NULL) {
whole->set(0, 0, 0, 0);
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment