Permalink
Browse files

Merge pull request #33 from gameoverhack/feature-windowsDisplayList

Added displayList for windows
(thx gameoverhack)
  • Loading branch information...
2 parents 25bdfbd + 8e2ebf0 commit d71dc9069f768bfbae9dbdfedd73d5da4040770f @underdoeg underdoeg committed Nov 24, 2011
Showing with 94 additions and 29 deletions.
  1. +5 −1 src/ofxDisplay.h
  2. +66 −5 src/ofxDisplayManager.cpp
  3. +4 −4 src/ofxDisplayManager.h
  4. +19 −19 src/ofxFensterManager.cpp
View
@@ -46,7 +46,11 @@ class ofxDisplayLinux: public ofxDisplay{
/***WINDOWS***/
#ifdef TARGET_WIN32
-//TODO
+
+class ofxDisplayWindows: public ofxDisplay{
+public:
+ DISPLAY_DEVICE* display;
+};
#endif
#endif
View
@@ -16,11 +16,11 @@ bool ofxDisplayManager::hasSingleton = false;
ofxDisplayManager* ofxDisplayManager::singleton;
ofxDisplayManager::ofxDisplayManager(){
-
+
};
ofxDisplayManager::~ofxDisplayManager(){
-
+
};
ofxDisplayList ofxDisplayManager::getDisplays()
@@ -44,7 +44,7 @@ ofxDisplayManager* ofxDisplayManager::get(){
#endif
#ifdef TARGET_WIN32
- singleton = new ofxDisplayManager();
+ singleton = new ofxDisplayManagerWin();
#endif
hasSingleton = true;
}
@@ -87,5 +87,66 @@ ofxDisplayList ofxDisplayManagerLinux::getDisplays()
#ifdef TARGET_WIN32
-//TODO
-#endif
+ofxDisplayList ofxDisplayManagerWin::getDisplays()
+{
+ //see: http://www.news2news.com/vfp/?example=374&ver=vcpp & http://stackoverflow.com/questions/181064/enumdisplaydevices-vs-wmi-win32-desktopmonitor-how-to-detect-active-monitors
+ // thias probably needs some finessing, but it's a start...
+
+ ofxDisplayList displays;
+ int numDisplayDevices = 0;
+
+ DISPLAY_DEVICE dd;
+ dd.cb = sizeof(DISPLAY_DEVICE);
+
+ while (EnumDisplayDevices(0, numDisplayDevices, &dd, 0)){
+ DISPLAY_DEVICE ddMon;
+ ZeroMemory(&ddMon, sizeof(ddMon));
+ ddMon.cb = sizeof(ddMon);
+ int numMonitors = 0;
+
+ while (EnumDisplayDevices(dd.DeviceName, numMonitors, &ddMon, 0)){
+ if (//ddMon.StateFlags & DISPLAY_DEVICE_ACTIVE && // this might be necessary on Win XP but is not for Vista/Win 7
+ !(ddMon.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER)){
+
+ DEVMODE dm;
+ dm.dmSize = sizeof(DEVMODE);
+
+ if (!EnumDisplaySettings(dd.DeviceName, ENUM_CURRENT_SETTINGS, &dm)){
+ ofLog(OF_LOG_VERBOSE, "EnumDisplaySettings failed:%d\n", GetLastError());
+ } else {
+ ofLog(OF_LOG_VERBOSE, "Device name: %s\n", dd.DeviceName);
+ ofLog(OF_LOG_VERBOSE, "Monitor name: %s\n", ddMon.DeviceID);
+ ofLog(OF_LOG_VERBOSE, "Refresh rate, in hertz: %d\n", dm.dmDisplayFrequency);
+ ofLog(OF_LOG_VERBOSE, "Color depth: %d\n", dm.dmBitsPerPel);
+ ofLog(OF_LOG_VERBOSE, "Screen position: %d x %d\n", dm.dmPosition.x, dm.dmPosition.y);
+ ofLog(OF_LOG_VERBOSE, "Screen resolution, in pixels: %d x %d\n", dm.dmPelsWidth, dm.dmPelsHeight);
+
+ ofxDisplayWindows* display = new ofxDisplayWindows();
+ display->display = ⅆ
+ display->width = dm.dmPelsWidth;
+ display->height = dm.dmPelsHeight;
+ display->x = dm.dmPosition.x;
+ display->y = dm.dmPosition.y;
+ display->id = numMonitors;//ofToInt(ddMon.DeviceID); // this is actually a unique ID but using int instead for now
+ displays.push_back(display);
+ }
+ ZeroMemory(&dm, sizeof(dm));
+
+ }
+ numMonitors++;
+
+ ZeroMemory(&ddMon, sizeof(ddMon));
+ ddMon.cb = sizeof(ddMon);
+ }
+
+ ZeroMemory(&dd, sizeof(dd));
+ dd.cb = sizeof(dd);
+ numDisplayDevices++;
+ }
+
+ return displays;
+
+};
+
+
+#endif
View
@@ -19,12 +19,12 @@ class ofxDisplayManager{
public:
ofxDisplayManager();
~ofxDisplayManager();
-
+
static ofxDisplayManager* get();
virtual ofxDisplayList getDisplays();
protected:
private:
-
+
static bool hasSingleton;
static ofxDisplayManager* singleton;
};
@@ -52,10 +52,10 @@ class ofxDisplayManagerMac: public ofxDisplayManager{
/***WINDOWS***/
#ifdef TARGET_WIN32
-//TODO
+#include <windows.h>
class ofxDisplayManagerWin: public ofxDisplayManager{
public:
- //ofxDisplayList getDisplays();
+ ofxDisplayList getDisplays();
};
#endif
View
@@ -36,14 +36,14 @@ exitOnEscape(true),endOnNextUpdate(false),running(false),antialiasing(0),hasActi
fps = 60.0; //give a realistic starting value - win32 issues
frameRate = 500.0;
bFrameRateSet = 0;
-
+
ofAddListener(ofEvents.exit, this, &ofxFensterManager::onClose);
GHOST_ISystem::createSystem();
ghostSystem=GHOST_ISystem::getSystem();
if(!ghostSystem)
ofLog(OF_LOG_ERROR, "COULD NOT CREATE GHOST SYSTEM! \n\nhelp... o_O");
ghostSystem->addEventConsumer(this);
-
+
#ifdef TARGET_LINUX
setActiveDisplay(ofxDisplayManager::get()->getDisplays()[0]);
#endif
@@ -80,7 +80,7 @@ void ofxFensterManager::update()
{
ghostSystem->processEvents(false);
ghostSystem->dispatchEvents();
-
+
if (nFrameCount != 0 && bFrameRateSet == true) {
diffMillis = ofGetElapsedTimeMillis() - prevMillis;
if (diffMillis > millisForFrame) {
@@ -94,10 +94,10 @@ void ofxFensterManager::update()
#endif
}
}
-
-
+
+
prevMillis = ofGetElapsedTimeMillis(); // you have to measure here
-
+
timeNow = ofGetElapsedTimef();
double diff = timeNow-timeThen;
if( diff > 0.00001 ) {
@@ -107,16 +107,16 @@ void ofxFensterManager::update()
}
lastFrameTime = diff;
timeThen = timeNow;
-
+
ofNotifyEvent(ofEvents.update, voidEventArgs);
ofNotifyEvent(ofEvents.draw, voidEventArgs);
-
+
nFrameCount++;
}
void ofxFensterManager::initializeWindow()
{
-
+
}
ofxFenster* ofxFensterManager::createFenster(int t, int l, int w, int h, int screenMode)
@@ -165,12 +165,12 @@ bool ofxFensterManager::processEvent(GHOST_IEvent* event)
{
if(event->getType()==GHOST_kEventUnknown)
return false;
-
+
GHOST_IWindow* window = event->getWindow();
bool handled = true;
-
+
ofxFenster* win=getFensterByHandler(window);
-
+
switch (event->getType())
{
//////////////////// MOUSE
@@ -179,10 +179,10 @@ bool ofxFensterManager::processEvent(GHOST_IEvent* event)
GHOST_TEventCursorData* bd=(GHOST_TEventCursorData*)event->getData();
GHOST_TInt32 x,y;
window->screenToClient(bd->x, bd->y, x, y);
-
+
ofPoint p(x, y);
p.y -= 1;
-
+
if(win->isButtonDown) {
win->mouseDragged(p.x, p.y, win->buttonDown);
} else {
@@ -242,7 +242,7 @@ bool ofxFensterManager::processEvent(GHOST_IEvent* event)
//GHOST_TInt32 x,y;
//window->screenToClient(rect.m_l, rect.m_t, x, y);
win->windowMoved(rect.m_l, rect.m_t);
-
+
break;
}
case GHOST_kEventWindowUpdate:
@@ -414,11 +414,11 @@ void ofxFensterManager::setFrameRate(float targetRate)
bFrameRateSet = false;
return;
}
-
+
bFrameRateSet = true;
float durationOfFrame = 1.0f / (float)targetRate;
millisForFrame = (int)(1000.0f * durationOfFrame);
-
+
frameRate = targetRate;
}
@@ -434,7 +434,7 @@ void ofxFensterManager::setOrientation(ofOrientation orientation)
void ofxFensterManager::setWindowPosition(int x, int y)
{
-
+ activeWindow->setWindowPosition(x, y);
}
void ofxFensterManager::setWindowShape(int w, int h)
@@ -449,7 +449,7 @@ void ofxFensterManager::setWindowTitle(string title)
void ofxFensterManager::showCursor()
{
-
+
}
void ofxFensterManager::toggleFullscreen()

0 comments on commit d71dc90

Please sign in to comment.