Skip to content

Commit b56edbb

Browse files
author
Ryan Fields
committed
Merge branch 'osx-modeswitch'
2 parents 9c70979 + 429bace commit b56edbb

File tree

3 files changed

+28
-66
lines changed

3 files changed

+28
-66
lines changed
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
////////////////////////////////////////////////////////////
2727
// Headers
2828
////////////////////////////////////////////////////////////
29+
#include <SFML/Window/VideoMode.hpp>
2930
#include <SFML/Window/OSX/DisplayImpl.hpp>
3031
#include <SFML/Window/OSX/cg_sf_conversion.hpp>
3132
#include <SFML/System/Err.hpp>
@@ -38,10 +39,8 @@
3839
namespace
3940
{
4041

41-
using namespace sf::priv;
42-
4342
struct find_NativeDisplayMode
44-
: public std::unary_function<DisplayImpl::NativeDisplayMode, bool>
43+
: public std::unary_function<sf::priv::DisplayImpl::NativeDisplayMode, bool>
4544
{
4645
sf::VideoMode mode;
4746

@@ -140,6 +139,21 @@ bool operator () (sf::priv::DisplayImpl::NativeDisplayMode const& value)
140139
}
141140
}
142141

142+
////////////////////////////////////////////////////////////
143+
std::vector<VideoMode> DisplayImpl::getModes() {
144+
std::vector<VideoMode> modes;
145+
std::vector<NativeDisplayMode>::iterator it;
146+
147+
for ( it = m_modes.begin();
148+
it != m_modes.end();
149+
it++)
150+
{
151+
modes.push_back(it->mode);
152+
}
153+
154+
return modes;
155+
}
156+
143157
////////////////////////////////////////////////////////////
144158
bool DisplayImpl::setMode(VideoMode const& mode) {
145159
find_NativeDisplayMode findMode;

src/SFML/Window/OSX/DisplayImpl.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,8 @@
2828
////////////////////////////////////////////////////////////
2929
// Headers
3030
////////////////////////////////////////////////////////////
31-
#include <Foundation/Foundation.h>
32-
#include <Quartz/Quartz.h>
33-
34-
#include <vector>
35-
36-
#include <SFML/Window/VideoModeImpl.hpp>
31+
#include <QuartzCore/QuartzCore.h>
32+
#include <SFML/Window/VideoMode.hpp>
3733

3834
namespace sf
3935
{
@@ -61,6 +57,12 @@ public :
6157
////////////////////////////////////////////////////////////
6258
~DisplayImpl();
6359

60+
////////////////////////////////////////////////////////////
61+
/// \brief Get the modes supported by the display
62+
///
63+
////////////////////////////////////////////////////////////
64+
std::vector<VideoMode> getModes();
65+
6466
////////////////////////////////////////////////////////////
6567
/// \brief Set the video mode for the display
6668
///

src/SFML/Window/OSX/VideoModeImpl.cpp

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
// Headers
2828
////////////////////////////////////////////////////////////
2929
#include <SFML/Window/VideoModeImpl.hpp>
30+
#include <SFML/Window/OSX/DisplayImpl.hpp>
3031
#include <SFML/Window/OSX/cg_sf_conversion.hpp>
3132
#include <SFML/System/Err.hpp>
3233
#include <algorithm>
@@ -43,64 +44,9 @@ namespace priv
4344
////////////////////////////////////////////////////////////
4445
std::vector<VideoMode> VideoModeImpl::getFullscreenModes()
4546
{
46-
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
47+
DisplayImpl display(CGMainDisplayID());
4748

48-
std::vector<VideoMode> modes;
49-
50-
// Retrieve array of dictionaries representing display modes.
51-
CFArrayRef displayModes = CGDisplayAvailableModes(CGMainDisplayID());
52-
53-
if (displayModes == NULL) {
54-
sf::err() << "Couldn't get VideoMode for main display.";
55-
return modes;
56-
}
57-
58-
// Loop on each mode and convert it into a sf::VideoMode object.
59-
CFIndex const modesCount = CFArrayGetCount(displayModes);
60-
for (CFIndex i = 0; i < modesCount; i++) {
61-
CFDictionaryRef dictionary = (CFDictionaryRef)CFArrayGetValueAtIndex(displayModes, i);
62-
63-
VideoMode mode = convertCGModeToSFMode(dictionary);
64-
65-
// If not yet listed we add it to our modes array.
66-
if (std::find(modes.begin(), modes.end(), mode) == modes.end()) {
67-
modes.push_back(mode);
68-
}
69-
}
70-
71-
return modes;
72-
73-
#else // MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
74-
75-
std::vector<VideoMode> modes;
76-
77-
// Retrieve all modes available for main screen only.
78-
CFArrayRef cgmodes = CGDisplayCopyAllDisplayModes(CGMainDisplayID(), NULL);
79-
80-
if (cgmodes == NULL) {
81-
sf::err() << "Couldn't get VideoMode for main display.";
82-
return modes;
83-
}
84-
85-
// Loop on each mode and convert it into a sf::VideoMode object.
86-
CFIndex const modesCount = CFArrayGetCount(cgmodes);
87-
for (CFIndex i = 0; i < modesCount; i++) {
88-
CGDisplayModeRef cgmode = (CGDisplayModeRef)CFArrayGetValueAtIndex(cgmodes, i);
89-
90-
VideoMode mode = convertCGModeToSFMode(cgmode);
91-
92-
// If not yet listed we add it to our modes array.
93-
if (std::find(modes.begin(), modes.end(), mode) == modes.end()) {
94-
modes.push_back(mode);
95-
}
96-
}
97-
98-
// Clean up memory.
99-
CFRelease(cgmodes);
100-
101-
return modes;
102-
103-
#endif
49+
return display.getModes();
10450
}
10551

10652

0 commit comments

Comments
 (0)