fix Xcode project generation via cmake

Move Objective-C++ Mac code for Wx into macsupport.mm with stub methods
in panel.cpp, and stop compiling all C++ as Objective-C++.

cmake -G Xcode # now works fine
This commit is contained in:
Rafael Kitover 2016-11-06 14:09:00 -08:00
parent 24e2b0ba81
commit 981026dc80
5 changed files with 52 additions and 36 deletions

View File

@ -97,9 +97,6 @@ IF(APPLE)
ELSEIF(EXISTS /sw/bin)
SET(CMAKE_PROGRAM_PATH "${CMAKE_PROGRAM_PATH};/sw/bin")
ENDIF()
# and compile as Objective-C++ for ObjectiveC #ifdefs
SET(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> -x objective-c++ <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
ENDIF(APPLE)
# We do not support amd64 asm yet

View File

@ -153,6 +153,10 @@ SET( SRC_WX
xrc/vbam.xpm
)
IF(APPLE)
SET(SRC_WX ${SRC_WX} macsupport.mm)
ENDIF(APPLE)
SET( HDR_WX
wxvbam.h
drawing.h

29
src/wx/macsupport.mm Normal file
View File

@ -0,0 +1,29 @@
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#include "wxvbam.h"
double HiDPIAware::HiDPIScaleFactor()
{
if (hidpi_scale_factor == 0) {
NSWindow* window = [(NSView*)GetWindow()->GetHandle() window];
if ([window respondsToSelector:@selector(backingScaleFactor)]) {
hidpi_scale_factor = [window backingScaleFactor];
}
else {
hidpi_scale_factor = 1.0;
}
}
return hidpi_scale_factor;
}
void HiDPIAware::RequestHighResolutionOpenGLSurface()
{
NSView* view = (NSView*)(GetWindow()->GetHandle());
if ([view respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) {
[view setWantsBestResolutionOpenGLSurface:YES];
}
}

View File

@ -1,10 +1,5 @@
#include <wx/dcbuffer.h>
#ifdef __WXMAC__
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#endif
#include "../../version.h"
#include "../common/ConfigManager.h"
#include "../common/Patch.h"
@ -18,26 +13,6 @@
int emulating;
double HiDPIAware::HiDPIScaleFactor()
{
if (hidpi_scale_factor == 0) {
#ifdef __WXMAC__
NSWindow* window = [(NSView*)GetWindow()->GetHandle() window];
if ([window respondsToSelector:@selector(backingScaleFactor)]) {
hidpi_scale_factor = [window backingScaleFactor];
}
else {
hidpi_scale_factor = 1.0;
}
#else
hidpi_scale_factor = 1.0;
#endif
}
return hidpi_scale_factor;
}
IMPLEMENT_DYNAMIC_CLASS(GameArea, wxPanel)
GameArea::GameArea()
@ -2023,13 +1998,7 @@ GLDrawingPanel::GLDrawingPanel(wxWindow* parent, int _width, int _height)
wxFULL_REPAINT_ON_RESIZE | wxWANTS_CHARS)
, DrawingPanel(_width, _height)
{
#ifdef __WXMAC__
NSView* view = (NSView*)GetHandle();
if ([view respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) {
[view setWantsBestResolutionOpenGLSurface:YES];
}
#endif
RequestHighResolutionOpenGLSurface();
#if wxCHECK_VERSION(2, 9, 0)
ctx = new wxGLContext(this);
SetCurrent(*ctx);
@ -2479,3 +2448,19 @@ void GameArea::HidePointer()
panel->GetWindow()->SetCursor(wxCursor(wxCURSOR_BLANK));
}
}
// stub HiDPI methods, see macsupport.mm for the Mac support
#ifndef __WXMAC__
double HiDPIAware::HiDPIScaleFactor()
{
if (hidpi_scale_factor == 0) {
hidpi_scale_factor = 1.0;
}
return hidpi_scale_factor;
}
void HiDPIAware::RequestHighResolutionOpenGLSurface()
{
}
#endif // HiDPI stubs

View File

@ -345,7 +345,8 @@ private:
// helper class to add HiDPI awareness (mostly for Mac OS X)
class HiDPIAware {
public:
double HiDPIScaleFactor();
virtual double HiDPIScaleFactor();
virtual void RequestHighResolutionOpenGLSurface();
virtual wxWindow* GetWindow() = 0;
private:
double hidpi_scale_factor = 0;