Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PoroCYon
Bonzomatic
Commits
73ceb33c
Commit
73ceb33c
authored
Jul 15, 2017
by
mathieu _alkama_ m
Committed by
Gargaj
Jul 15, 2017
Browse files
MacOS: add a setup dialog to change resolution and mode
parent
b2a7b2ea
Changes
2
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
73ceb33c
...
...
@@ -305,8 +305,8 @@ if (APPLE)
${
CMAKE_SOURCE_DIR
}
/src/platform_common/FFT.cpp
${
CMAKE_SOURCE_DIR
}
/src/platform_x11/MIDI.cpp
${
CMAKE_SOURCE_DIR
}
/src/platform_x11/Misc.cpp
${
CMAKE_SOURCE_DIR
}
/src/platform_x11/SetupDialog.cpp
${
CMAKE_SOURCE_DIR
}
/src/platform_x11/Timer.cpp
${
CMAKE_SOURCE_DIR
}
/src/platform_osx/SetupDialog.cpp
${
CMAKE_SOURCE_DIR
}
/src/platform_osx/Clipboard.cpp
)
source_group
(
"Bonzomatic
\\
Platform"
FILES
${
BZC_PLATFORM_SRCS
}
)
...
...
src/platform_osx/SetupDialog.cpp
0 → 100644
View file @
73ceb33c
#include
<iostream>
#include
"../Renderer.h"
#include
<CoreFoundation/CoreFoundation.h>
#include
<CoreGraphics/CoreGraphics.h>
#include
<set>
struct
Resolution
{
unsigned
int
w
,
h
;
Resolution
(
int
_w
,
int
_h
)
:
w
(
_w
),
h
(
_h
)
{}
};
inline
bool
operator
==
(
const
Resolution
&
l
,
const
Resolution
&
r
)
{
return
(
l
.
w
==
r
.
w
)
&&
(
l
.
h
==
r
.
h
);
}
inline
bool
operator
<
(
const
Resolution
&
l
,
const
Resolution
&
r
)
{
return
(
l
.
w
<
r
.
w
)
?
true
:
((
l
.
w
==
r
.
w
)
?
((
l
.
h
<
r
.
h
)
?
true
:
false
)
:
false
);
}
void
BuildListOfMainDisplayResolutions
(
std
::
set
<
Resolution
>
&
resolutions
)
{
CGDirectDisplayID
monitorID
=
CGMainDisplayID
();
CFArrayRef
modes
=
CGDisplayCopyAllDisplayModes
(
monitorID
,
NULL
);
CFIndex
found
=
CFArrayGetCount
(
modes
);
for
(
CFIndex
i
=
0
;
i
<
found
;
i
++
)
{
CGDisplayModeRef
dm
=
(
CGDisplayModeRef
)
CFArrayGetValueAtIndex
(
modes
,
i
);
resolutions
.
insert
({(
int
)
CGDisplayModeGetWidth
(
dm
),
(
int
)
CGDisplayModeGetHeight
(
dm
)});
}
CFRelease
(
modes
);
}
bool
Renderer
::
OpenSetupDialog
(
RENDERER_SETTINGS
*
settings
)
{
std
::
set
<
Resolution
>
resolutions
;
// Force some default resolutions
resolutions
.
insert
({
1280
,
720
});
resolutions
.
insert
({
1920
,
1080
});
// Also add the resolution found in the settings
resolutions
.
insert
({
settings
->
nWidth
,
settings
->
nHeight
});
BuildListOfMainDisplayResolutions
(
resolutions
);
CFURLRef
urlRef
=
CFBundleCopyResourceURL
(
CFBundleGetMainBundle
(),
CFSTR
(
"icon"
),
CFSTR
(
"icns"
),
NULL
);
// The list of resolutions for the dialog
CFMutableArrayRef
popupVals
=
CFArrayCreateMutable
(
NULL
,
resolutions
.
size
(),
&
kCFTypeArrayCallBacks
);
for
(
const
auto
&
r
:
resolutions
)
{
CFArrayAppendValue
(
popupVals
,
CFStringCreateWithFormat
(
NULL
,
NULL
,
CFSTR
(
"%d x %d"
),
r
.
w
,
r
.
h
));
}
// The fullscreen checkbox for the dialog
CFTypeRef
checkboxKeys
[
1
]
=
{
CFSTR
(
"Fullscreen?"
)
};
CFArrayRef
checkboxVals
=
CFArrayCreate
(
NULL
,
checkboxKeys
,
1
,
&
kCFTypeArrayCallBacks
);
const
void
*
keys
[]
=
{
kCFUserNotificationIconURLKey
,
kCFUserNotificationAlertHeaderKey
,
kCFUserNotificationAlertMessageKey
,
kCFUserNotificationDefaultButtonTitleKey
,
kCFUserNotificationPopUpTitlesKey
,
kCFUserNotificationCheckBoxTitlesKey
};
const
void
*
values
[]
=
{
urlRef
,
CFSTR
(
"Bonzomatic"
),
CFSTR
(
"Choose your resolution, it's a REVOLUTION!
\n\n
Note: The list is polled from your main display, but 1920x1080 and 1280x720 are force inserted and NOT garanteed to work on your device.
\n
We also add whatever was found in the
\"
config.json
\"\n
"
),
CFSTR
(
"Ignition"
),
popupVals
,
checkboxVals
};
CFDictionaryRef
parameters
=
CFDictionaryCreate
(
NULL
,
keys
,
values
,
sizeof
(
keys
)
/
sizeof
(
*
keys
),
&
kCFTypeDictionaryKeyCallBacks
,
&
kCFTypeDictionaryValueCallBacks
);
// Setup defaults according to the settings
CFOptionFlags
settingsFlags
=
0
;
if
(
settings
->
windowMode
==
RENDERER_WINDOWMODE_FULLSCREEN
)
{
settingsFlags
|=
CFUserNotificationCheckBoxChecked
(
0
);
}
int
idx
=
0
;
for
(
const
auto
&
r
:
resolutions
)
{
if
((
settings
->
nWidth
==
r
.
w
)
&&
(
settings
->
nHeight
==
r
.
h
))
{
settingsFlags
|=
CFUserNotificationPopUpSelection
(
idx
);
break
;
}
idx
++
;
}
SInt32
err
=
0
;
CFUserNotificationRef
dialog
=
CFUserNotificationCreate
(
NULL
,
0
,
kCFUserNotificationPlainAlertLevel
|
settingsFlags
,
&
err
,
parameters
);
CFOptionFlags
responseFlags
=
0
;
CFUserNotificationReceiveResponse
(
dialog
,
0
,
&
responseFlags
);
// Collect the user selection and feed the settings
if
(
responseFlags
&
CFUserNotificationCheckBoxChecked
(
0
))
{
settings
->
windowMode
=
RENDERER_WINDOWMODE_FULLSCREEN
;
}
else
{
settings
->
windowMode
=
RENDERER_WINDOWMODE_WINDOWED
;
}
idx
=
responseFlags
>>
24
;
if
((
idx
>=
0
)
&&
(
idx
<
resolutions
.
size
()))
{
const
auto
&
r
=
*
std
::
next
(
resolutions
.
cbegin
(),
idx
);
settings
->
nWidth
=
r
.
w
;
settings
->
nHeight
=
r
.
h
;
}
CFRelease
(
dialog
);
CFRelease
(
parameters
);
CFRelease
(
checkboxVals
);
CFRelease
(
popupVals
);
return
true
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment