Skip to content

Commit

Permalink
Added displayList for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
gameoverhack committed Nov 24, 2011
1 parent 553f16f commit 8e2ebf0
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 29 deletions.
6 changes: 5 additions & 1 deletion src/ofxDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ class ofxDisplayLinux: public ofxDisplay{
/***WINDOWS***/

#ifdef TARGET_WIN32
//TODO

class ofxDisplayWindows: public ofxDisplay{
public:
DISPLAY_DEVICE* display;
};
#endif

#endif
71 changes: 66 additions & 5 deletions src/ofxDisplayManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ bool ofxDisplayManager::hasSingleton = false;
ofxDisplayManager* ofxDisplayManager::singleton;

ofxDisplayManager::ofxDisplayManager(){

};

ofxDisplayManager::~ofxDisplayManager(){

};

ofxDisplayList ofxDisplayManager::getDisplays()
Expand All @@ -44,7 +44,7 @@ ofxDisplayManager* ofxDisplayManager::get(){
#endif

#ifdef TARGET_WIN32
singleton = new ofxDisplayManager();
singleton = new ofxDisplayManagerWin();
#endif
hasSingleton = true;
}
Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions src/ofxDisplayManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class ofxDisplayManager{
public:
ofxDisplayManager();
~ofxDisplayManager();

static ofxDisplayManager* get();
virtual ofxDisplayList getDisplays();
protected:
private:

static bool hasSingleton;
static ofxDisplayManager* singleton;
};
Expand Down Expand Up @@ -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

Expand Down
38 changes: 19 additions & 19 deletions src/ofxFensterManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -80,7 +80,7 @@ void ofxFensterManager::update()
{
ghostSystem->processEvents(false);
ghostSystem->dispatchEvents();

if (nFrameCount != 0 && bFrameRateSet == true) {
diffMillis = ofGetElapsedTimeMillis() - prevMillis;
if (diffMillis > millisForFrame) {
Expand All @@ -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 ) {
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}

Expand All @@ -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)
Expand All @@ -449,7 +449,7 @@ void ofxFensterManager::setWindowTitle(string title)

void ofxFensterManager::showCursor()
{

}

void ofxFensterManager::toggleFullscreen()
Expand Down

0 comments on commit 8e2ebf0

Please sign in to comment.