Permalink
Browse files

Cocoa Port: Fix some bugs with HUD font loading and HUD rendering on …

…Retina displays.
  • Loading branch information...
rogerman committed Jan 16, 2017
1 parent 6756f41 commit 25c023267364d10b3b57556caf14f55241272efc
@@ -174,15 +174,15 @@ double ClientDisplayView::GetScaleFactor() const
void ClientDisplayView::SetScaleFactor(const double scaleFactor)
{
const bool willChangeScaleFactor = (this->_scaleFactor != scaleFactor);
this->_scaleFactor = scaleFactor;
const bool willChangeScaleFactor = (this->_scaleFactor != scaleFactor);
if (willChangeScaleFactor)
{
this->_glyphTileSize = (double)HUD_TEXTBOX_BASEGLYPHSIZE * scaleFactor;
this->_glyphSize = (double)this->_glyphTileSize * 0.75;
this->SetHUDFontUsingPath(this->_lastFontFilePath);
this->LoadHUDFont();
}
}
@@ -321,32 +321,41 @@ void ClientDisplayView::SetPixelScaler(const VideoFilterTypeID filterID)
}
// HUD appearance
void ClientDisplayView::SetHUDFontUsingPath(const char *filePath)
const char* ClientDisplayView::GetHUDFontPath() const
{
return this->_lastFontFilePath;
}
void ClientDisplayView::SetHUDFontPath(const char *filePath)
{
if (filePath == NULL)
this->_lastFontFilePath = filePath;
}
void ClientDisplayView::LoadHUDFont()
{
if (this->_lastFontFilePath == NULL)
{
return;
}
FT_Face fontFace;
FT_Error error = FT_Err_Ok;
error = FT_New_Face(this->_ftLibrary, filePath, 0, &fontFace);
error = FT_New_Face(this->_ftLibrary, this->_lastFontFilePath, 0, &fontFace);
if (error == FT_Err_Unknown_File_Format)
{
printf("ClientDisplayView: FreeType failed to load font face because it is in an unknown format from:\n%s\n", filePath);
printf("ClientDisplayView: FreeType failed to load font face because it is in an unknown format from:\n%s\n", this->_lastFontFilePath);
return;
}
else if (error)
{
printf("ClientDisplayView: FreeType failed to load font face with an unknown error from:\n%s\n", filePath);
printf("ClientDisplayView: FreeType failed to load font face with an unknown error from:\n%s\n", this->_lastFontFilePath);
return;
}
this->CopyHUDFont(fontFace, this->_glyphSize, this->_glyphTileSize, this->_glyphInfo);
FT_Done_Face(fontFace);
this->_lastFontFilePath = filePath;
}
void ClientDisplayView::CopyHUDFont(const FT_Face &fontFace, const size_t glyphSize, const size_t glyphTileSize, GlyphInfo *glyphInfo)
@@ -445,6 +454,17 @@ void ClientDisplayView::SetHUDShowRTC(const bool visibleState)
this->_SetHUDShowInfoItem(this->_showRTC, visibleState);
}
// NDS GPU Interface
void ClientDisplayView::FrameProcessGPU()
{
// Do nothing. This is implementation dependent.
}
void ClientDisplayView::FrameProcessHUD()
{
// Do nothing. This is implementation dependent.
}
// Touch screen input handling
void ClientDisplayView::GetNDSPoint(const int inputID, const bool isInitialTouchPress,
const double clientX, const double clientY,
@@ -908,6 +928,8 @@ void ClientDisplay3DView::SetHUDVertices(float viewportWidth, float viewportHeig
textBoxScale = HUD_TEXTBOX_BASE_SCALE * HUD_TEXTBOX_MIN_SCALE;
}
textBoxScale /= this->_scaleFactor;
float boxOffset = 8.0f * HUD_TEXTBOX_BASE_SCALE * this->_hudObjectScale;
if (boxOffset < 1.0f)
{
@@ -182,7 +182,9 @@ class ClientDisplayView
virtual void SetPixelScaler(const VideoFilterTypeID filterID);
// HUD appearance
virtual void SetHUDFontUsingPath(const char *filePath);
const char* GetHUDFontPath() const;
void SetHUDFontPath(const char *filePath);
virtual void LoadHUDFont();
virtual void CopyHUDFont(const FT_Face &fontFace, const size_t glyphSize, const size_t glyphTileSize, GlyphInfo *glyphInfo);
virtual void SetHUDInfo(const NDSFrameInfo &frameInfo);
@@ -207,8 +209,8 @@ class ClientDisplayView
// NDS GPU interface
virtual void FrameLoadGPU(bool isMainSizeNative, bool isTouchSizeNative) = 0;
virtual void FrameProcessGPU() = 0;
virtual void FrameProcessHUD() = 0;
virtual void FrameProcessGPU();
virtual void FrameProcessHUD();
virtual void FrameRender() = 0;
virtual void FrameFinish() = 0;
@@ -261,7 +263,7 @@ class ClientDisplay3DView : public ClientDisplayView
const void *nativeBuffer0,
const void *nativeBuffer1,
const void *customBuffer0, const size_t customWidth0, const size_t customHeight0,
const void *customBuffer1, const size_t customWidth1, const size_t customHeight1) = 0;
const void *customBuffer1, const size_t customWidth1, const size_t customHeight1);
void SetHUDVertices(float viewportWidth, float viewportHeight, float *vtxBufferPtr);
void SetHUDTextureCoordinates(float *texCoordBufferPtr);
@@ -6407,7 +6407,7 @@ void OGLHUDLayer::RenderOGL()
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
// Next, draw each character inside the box.
const GLfloat textBoxScale = (GLfloat)HUD_TEXTBOX_BASE_SCALE * this->_output->GetHUDObjectScale();
const GLfloat textBoxScale = (GLfloat)HUD_TEXTBOX_BASE_SCALE * this->_output->GetHUDObjectScale() / this->_output->GetScaleFactor();
if (textBoxScale >= (2.0/3.0))
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -95,7 +95,7 @@ class OGLVideoOutput;
BOOL _isMinSizeNormal;
NSUInteger _statusBarHeight;
BOOL _isUpdatingDisplayScaleValueOnly;
BOOL _useMavericksFullScreen;
BOOL _canUseMavericksFullScreen;
BOOL _masterStatusBarState;
NSRect _masterWindowFrame;
double _masterWindowScale;
@@ -116,7 +116,7 @@ - (id)initWithWindowNibName:(NSString *)windowNibName emuControlDelegate:(EmuCon
_isMinSizeNormal = YES;
_statusBarHeight = WINDOW_STATUS_BAR_HEIGHT;
_isUpdatingDisplayScaleValueOnly = NO;
_useMavericksFullScreen = IsOSXVersionSupported(10, 9, 0);
_canUseMavericksFullScreen = IsOSXVersionSupported(10, 9, 0);
_masterWindowScale = 1.0;
_masterWindowFrame = NSMakeRect(0.0, 0.0, _localViewProps.clientWidth, _localViewProps.clientHeight + _localViewProps.gapDistance);
_masterStatusBarState = NO;
@@ -538,17 +538,17 @@ - (void) setupUserDefaults
- (BOOL) masterStatusBarState
{
return (![self isFullScreen] || !_useMavericksFullScreen) ? [self isShowingStatusBar] : _masterStatusBarState;
return (![self isFullScreen] || !_canUseMavericksFullScreen) ? [self isShowingStatusBar] : _masterStatusBarState;
}
- (NSRect) masterWindowFrame
{
return (![self isFullScreen] || !_useMavericksFullScreen) ? [masterWindow frame] : _masterWindowFrame;
return (![self isFullScreen] || !_canUseMavericksFullScreen) ? [masterWindow frame] : _masterWindowFrame;
}
- (double) masterWindowScale
{
return (![self isFullScreen] || !_useMavericksFullScreen) ? [self displayScale] : _masterWindowScale;
return (![self isFullScreen] || !_canUseMavericksFullScreen) ? [self displayScale] : _masterWindowScale;
}
- (NSRect) updateViewProperties
@@ -698,7 +698,7 @@ - (void) exitFullScreen
- (void) respondToScreenChange:(NSNotification *)aNotification
{
if (_useMavericksFullScreen)
if (_canUseMavericksFullScreen)
{
return;
}
@@ -839,7 +839,7 @@ - (IBAction) toggleStatusBar:(id)sender
- (IBAction) toggleFullScreenDisplay:(id)sender
{
#if defined(MAC_OS_X_VERSION_10_7) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
if (_useMavericksFullScreen)
if (_canUseMavericksFullScreen)
{
[masterWindow toggleFullScreen:nil];
}
@@ -1286,7 +1286,20 @@ - (void)windowDidLoad
// Set up the video output thread.
CocoaDSDisplayVideo *newDisplayOutput = [[CocoaDSDisplayVideo alloc] init];
[newDisplayOutput setClientDisplayView:[view clientDisplay3DView]];
[newDisplayOutput setScaleFactor:scaleFactor];
ClientDisplayView *cdv = [newDisplayOutput clientDisplayView];
NSString *fontPath = [[NSBundle mainBundle] pathForResource:@"SourceSansPro-Bold" ofType:@"otf"];
cdv->SetHUDFontPath([fontPath cStringUsingEncoding:NSUTF8StringEncoding]);
if (scaleFactor != 1.0f)
{
[newDisplayOutput setScaleFactor:scaleFactor];
}
else
{
cdv->LoadHUDFont();
}
[newDisplayOutput resetVideoBuffers];
[self setCdsVideoOutput:newDisplayOutput];
[view setCdsVideoOutput:newDisplayOutput];
@@ -1645,10 +1658,6 @@ - (id)initWithFrame:(NSRect)frameRect
}
}
ClientDisplay3DView *cdv = [(id<DisplayViewCALayer>)localLayer clientDisplay3DView];
NSString *fontPath = [[NSBundle mainBundle] pathForResource:@"SourceSansPro-Bold" ofType:@"otf"];
cdv->SetHUDFontUsingPath([fontPath cStringUsingEncoding:NSUTF8StringEncoding]);
return self;
}
@@ -60,7 +60,7 @@ class MacOGLDisplayView : public OGLVideoOutput, public DisplayViewCALayerInterf
bool GetRenderToCALayer() const;
void SetRenderToCALayer(const bool renderToLayer);
virtual void SetHUDFontUsingPath(const char *filePath);
virtual void LoadHUDFont();
virtual void SetVideoBuffers(const uint32_t colorFormat,
const void *videoBufferHead,
@@ -197,11 +197,11 @@ - (void)drawInCGLContext:(CGLContextObj)glContext pixelFormat:(CGLPixelFormatObj
this->_willRenderToCALayer = renderToLayer;
}
void MacOGLDisplayView::SetHUDFontUsingPath(const char *filePath)
void MacOGLDisplayView::LoadHUDFont()
{
CGLLockContext(this->_context);
CGLSetCurrentContext(this->_context);
this->OGLVideoOutput::SetHUDFontUsingPath(filePath);
this->OGLVideoOutput::LoadHUDFont();
CGLUnlockContext(this->_context);
}

0 comments on commit 25c0232

Please sign in to comment.