Obj-C Refactor: General Code Style cleanups

As part of a more general Objective-C GHOST refactor and in an effort to
modernize the macOS backend for further works, this commit cleans up the
codestyle of Objective-C files. Based off the Blender C/C++ style guide,
in addition to some Objective-C specific style changes.

Changes:
- `const` correctness, use nullptr, initializer list for simple struct
- Reduced variable scope for simple functions, removed unused variables
- Use braces for conditional statements, no else after return
- Annotate inheritted function of GHOST Cocoa classes with override and
  use `= default` to define trivial constructors
- Use #import instead of #include for Objective-C headers
    This is only for correctness. As the Objective-C #import directive
    is really just an #include with an implicit #pragma once.
- Use proper C-style comments instead of #pragma mark
    #pragma mark is an XCode feature to mark code chapters, to follow
    the Blender codestyle, and make the Objective-C code more editor
    agnostic, these were replaced with multi-line C-style comments.

Ref #126772

Pull Request: https://projects.blender.org/blender/blender/pulls/126770
This commit is contained in:
Jonas Holzman
2024-09-19 11:37:52 +02:00
committed by Sergey Sharybin
parent 11bf2b9a62
commit b427253a4d
13 changed files with 212 additions and 178 deletions
+2 -2
View File
@@ -49,7 +49,7 @@ class GHOST_ContextCGL : public GHOST_Context {
/**
* Destructor.
*/
~GHOST_ContextCGL();
~GHOST_ContextCGL() override;
/**
* Swaps front and back buffers of a window.
@@ -96,7 +96,7 @@ class GHOST_ContextCGL : public GHOST_Context {
* \param intervalOut: Variable to store the swap interval if it can be read.
* \return Whether the swap interval can be read.
*/
GHOST_TSuccess getSwapInterval(int &) override;
GHOST_TSuccess getSwapInterval(int &intervalOut) override;
/**
* Updates the drawing context of this window.
+8 -8
View File
@@ -16,9 +16,9 @@
#include "GHOST_ContextCGL.hh"
#include <Cocoa/Cocoa.h>
#include <Metal/Metal.h>
#include <QuartzCore/QuartzCore.h>
#import <Cocoa/Cocoa.h>
#import <Metal/Metal.h>
#import <QuartzCore/QuartzCore.h>
#include <cassert>
#include <vector>
@@ -332,10 +332,10 @@ void GHOST_ContextCGL::metalInitFramebuffer()
void GHOST_ContextCGL::metalUpdateFramebuffer()
{
@autoreleasepool {
NSRect bounds = [m_metalView bounds];
NSSize backingSize = [m_metalView convertSizeToBacking:bounds.size];
size_t width = (size_t)backingSize.width;
size_t height = (size_t)backingSize.height;
const NSRect bounds = [m_metalView bounds];
const NSSize backingSize = [m_metalView convertSizeToBacking:bounds.size];
const size_t width = size_t(backingSize.width);
const size_t height = size_t(backingSize.height);
if (m_defaultFramebufferMetalTexture[current_swapchain_index].texture &&
m_defaultFramebufferMetalTexture[current_swapchain_index].texture.width == width &&
@@ -385,7 +385,7 @@ void GHOST_ContextCGL::metalUpdateFramebuffer()
}
[cmdBuffer commit];
m_metalLayer.drawableSize = CGSizeMake((CGFloat)width, (CGFloat)height);
m_metalLayer.drawableSize = CGSizeMake(CGFloat(width), CGFloat(height));
}
}
@@ -24,14 +24,14 @@ class GHOST_DisplayManagerCocoa : public GHOST_DisplayManager {
/**
* Constructor.
*/
GHOST_DisplayManagerCocoa();
GHOST_DisplayManagerCocoa() = default;
/**
* Returns the number of display devices on this system.
* \param numDisplays: The number of displays on this system.
* \return Indication of success.
*/
GHOST_TSuccess getNumDisplays(uint8_t &numDisplays) const;
GHOST_TSuccess getNumDisplays(uint8_t &numDisplays) const override;
/**
* Returns the number of display settings for this display device.
@@ -39,7 +39,7 @@ class GHOST_DisplayManagerCocoa : public GHOST_DisplayManager {
* \param numSetting: The number of settings of the display device with this index.
* \return Indication of success.
*/
GHOST_TSuccess getNumDisplaySettings(uint8_t display, int32_t &numSettings) const;
GHOST_TSuccess getNumDisplaySettings(uint8_t display, int32_t &numSettings) const override;
/**
* Returns the current setting for this display device.
@@ -50,7 +50,7 @@ class GHOST_DisplayManagerCocoa : public GHOST_DisplayManager {
*/
GHOST_TSuccess getDisplaySetting(uint8_t display,
int32_t index,
GHOST_DisplaySetting &setting) const;
GHOST_DisplaySetting &setting) const override;
/**
* Returns the current setting for this display device.
@@ -58,7 +58,8 @@ class GHOST_DisplayManagerCocoa : public GHOST_DisplayManager {
* \param setting: The current setting of the display device with this index.
* \return Indication of success.
*/
GHOST_TSuccess getCurrentDisplaySetting(uint8_t display, GHOST_DisplaySetting &setting) const;
GHOST_TSuccess getCurrentDisplaySetting(uint8_t display,
GHOST_DisplaySetting &setting) const override;
/**
* Changes the current setting for this display device.
@@ -66,7 +67,8 @@ class GHOST_DisplayManagerCocoa : public GHOST_DisplayManager {
* \param setting: The current setting of the display device with this index.
* \return Indication of success.
*/
GHOST_TSuccess setCurrentDisplaySetting(uint8_t display, const GHOST_DisplaySetting &setting);
GHOST_TSuccess setCurrentDisplaySetting(uint8_t display,
const GHOST_DisplaySetting &setting) override;
protected:
// Do not cache values as OS X supports screen hot plug
@@ -10,8 +10,6 @@
/* We do not support multiple monitors at the moment. */
GHOST_DisplayManagerCocoa::GHOST_DisplayManagerCocoa(void) {}
GHOST_TSuccess GHOST_DisplayManagerCocoa::getNumDisplays(uint8_t &numDisplays) const
{
@autoreleasepool {
@@ -36,16 +34,19 @@ GHOST_TSuccess GHOST_DisplayManagerCocoa::getDisplaySetting(uint8_t display,
@autoreleasepool {
NSScreen *askedDisplay;
if (display == kMainDisplay) /* Screen #0 may not be the main one. */
if (display == kMainDisplay) {
/* Screen #0 may not be the main one. */
askedDisplay = [NSScreen mainScreen];
else
}
else {
askedDisplay = [[NSScreen screens] objectAtIndex:display];
}
if (askedDisplay == nil) {
return GHOST_kFailure;
}
NSRect frame = askedDisplay.visibleFrame;
const NSRect frame = askedDisplay.visibleFrame;
setting.xPixels = frame.size.width;
setting.yPixels = frame.size.height;
@@ -75,16 +76,19 @@ GHOST_TSuccess GHOST_DisplayManagerCocoa::getCurrentDisplaySetting(
@autoreleasepool {
NSScreen *askedDisplay;
if (display == kMainDisplay) /* Screen #0 may not be the main one. */
if (display == kMainDisplay) {
/* Screen #0 may not be the main one. */
askedDisplay = [NSScreen mainScreen];
else
}
else {
askedDisplay = [[NSScreen screens] objectAtIndex:display];
}
if (askedDisplay == nil) {
return GHOST_kFailure;
}
NSRect frame = askedDisplay.visibleFrame;
const NSRect frame = askedDisplay.visibleFrame;
setting.xPixels = frame.size.width;
setting.yPixels = frame.size.height;
@@ -123,10 +127,10 @@ GHOST_TSuccess GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(
#if 0
CFDictionaryRef displayModeValues = ::CGDisplayBestModeForParametersAndRefreshRate(
m_displayIDs[display],
(size_t)setting.bpp,
(size_t)setting.xPixels,
(size_t)setting.yPixels,
(CGRefreshRate)setting.frequency,
size_t(setting.bpp),
size_t(setting.xPixels),
size_t(setting.yPixels),
CGRefreshRate(setting.frequency),
nullptr);
#endif
@@ -12,7 +12,7 @@
class GHOST_NDOFManagerCocoa : public GHOST_NDOFManager {
public:
GHOST_NDOFManagerCocoa(GHOST_System &);
~GHOST_NDOFManagerCocoa();
~GHOST_NDOFManagerCocoa() override;
bool available();
bool available() override;
};
+34 -30
View File
@@ -32,10 +32,10 @@ class GHOST_SystemCocoa : public GHOST_System {
/**
* Destructor.
*/
~GHOST_SystemCocoa();
~GHOST_SystemCocoa() override;
/***************************************************************************************
* Time(r) functionality
* Time(r) functionality.
***************************************************************************************/
/**
@@ -44,28 +44,28 @@ class GHOST_SystemCocoa : public GHOST_System {
* Based on ANSI clock() routine.
* \return The number of milliseconds.
*/
uint64_t getMilliSeconds() const;
uint64_t getMilliSeconds() const override;
/***************************************************************************************
* Display/window management functionality
* Display/window management functionality.
***************************************************************************************/
/**
* Returns the number of displays on this system.
* \return The number of displays.
*/
uint8_t getNumDisplays() const;
uint8_t getNumDisplays() const override;
/**
* Returns the dimensions of the main display on this system.
* \return The dimension of the main display.
*/
void getMainDisplayDimensions(uint32_t &width, uint32_t &height) const;
void getMainDisplayDimensions(uint32_t &width, uint32_t &height) const override;
/** Returns the combine dimensions of all monitors.
* \return The dimension of the workspace.
*/
void getAllDisplayDimensions(uint32_t &width, uint32_t &height) const;
void getAllDisplayDimensions(uint32_t &width, uint32_t &height) const override;
/**
* Create a new window.
@@ -92,21 +92,21 @@ class GHOST_SystemCocoa : public GHOST_System {
GHOST_GPUSettings gpuSettings,
const bool exclusive = false,
const bool is_dialog = false,
const GHOST_IWindow *parentWindow = nullptr);
const GHOST_IWindow *parentWindow = nullptr) override;
/**
* Create a new off-screen context.
* Never explicitly delete the context, use #disposeContext() instead.
* \return The new context (or 0 if creation failed).
*/
GHOST_IContext *createOffscreenContext(GHOST_GPUSettings gpuSettings);
GHOST_IContext *createOffscreenContext(GHOST_GPUSettings gpuSettings) override;
/**
* Dispose of a context.
* \param context: Pointer to the context to be disposed.
* \return Indication of success.
*/
GHOST_TSuccess disposeContext(GHOST_IContext *context);
GHOST_TSuccess disposeContext(GHOST_IContext *context) override;
/**
* Get the Window under the cursor.
@@ -114,10 +114,10 @@ class GHOST_SystemCocoa : public GHOST_System {
* \param y: The y-coordinate of the cursor.
* \return The window under the cursor or nullptr if none.
*/
GHOST_IWindow *getWindowUnderCursor(int32_t x, int32_t y);
GHOST_IWindow *getWindowUnderCursor(int32_t x, int32_t y) override;
/***************************************************************************************
* Event management functionality
* Event management functionality.
***************************************************************************************/
/**
@@ -125,7 +125,7 @@ class GHOST_SystemCocoa : public GHOST_System {
* \param waitForEvent: Flag to wait for an event (or return immediately).
* \return Indication of the presence of events.
*/
bool processEvents(bool waitForEvent);
bool processEvents(bool waitForEvent) override;
/**
* Handle User request to quit, from Menu bar Quit, and Command+Q
@@ -157,7 +157,7 @@ class GHOST_SystemCocoa : public GHOST_System {
void *data);
/***************************************************************************************
* Cursor management functionality
* Cursor management functionality.
***************************************************************************************/
/**
@@ -166,7 +166,7 @@ class GHOST_SystemCocoa : public GHOST_System {
* \param y: The y-coordinate of the cursor.
* \return Indication of success.
*/
GHOST_TSuccess getCursorPosition(int32_t &x, int32_t &y) const;
GHOST_TSuccess getCursorPosition(int32_t &x, int32_t &y) const override;
/**
* Updates the location of the cursor (location in screen coordinates).
@@ -174,14 +174,14 @@ class GHOST_SystemCocoa : public GHOST_System {
* \param y: The y-coordinate of the cursor.
* \return Indication of success.
*/
GHOST_TSuccess setCursorPosition(int32_t x, int32_t y);
GHOST_TSuccess setCursorPosition(int32_t x, int32_t y) override;
/**
* Get the color of the pixel at the current mouse cursor location
* \param r_color: returned sRGB float colors
* \return Success value (true == successful and supported by platform)
*/
GHOST_TSuccess getPixelAtCursor(float r_color[3]) const;
GHOST_TSuccess getPixelAtCursor(float r_color[3]) const override;
/***************************************************************************************
* Access to mouse button and keyboard states.
@@ -192,30 +192,34 @@ class GHOST_SystemCocoa : public GHOST_System {
* \param keys: The state of all modifier keys (true == pressed).
* \return Indication of success.
*/
GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys &keys) const;
GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys &keys) const override;
/**
* Returns the state of the mouse buttons (outside the message queue).
* \param buttons: The state of the buttons.
* \return Indication of success.
*/
GHOST_TSuccess getButtons(GHOST_Buttons &buttons) const;
GHOST_TSuccess getButtons(GHOST_Buttons &buttons) const override;
GHOST_TCapabilityFlag getCapabilities() const;
GHOST_TCapabilityFlag getCapabilities() const override;
/***************************************************************************************
* Clipboard get / set.
***************************************************************************************/
/**
* Returns Clipboard data
* \param selection: Indicate which buffer to return.
* \return Returns the selected buffer
*/
char *getClipboard(bool selection) const;
char *getClipboard(bool selection) const override;
/**
* Puts buffer to system clipboard
* \param buffer: The buffer to be copied.
* \param selection: Indicates which buffer to copy too, only used on X11.
*/
void putClipboard(const char *buffer, bool selection) const;
void putClipboard(const char *buffer, bool selection) const override;
/**
* Handles a window event. Called by GHOST_WindowCocoa window delegate
@@ -244,7 +248,7 @@ class GHOST_SystemCocoa : public GHOST_System {
/**
* \see GHOST_ISystem
*/
bool setConsoleWindowState(GHOST_TConsoleWindowState /*action*/)
bool setConsoleWindowState(GHOST_TConsoleWindowState /*action*/) override
{
return false;
}
@@ -283,12 +287,12 @@ class GHOST_SystemCocoa : public GHOST_System {
* \param link: An optional hyperlink.
* \param dialog_options: Options how to display the message.
*/
virtual GHOST_TSuccess showMessageBox(const char *title,
const char *message,
const char *help_label,
const char *continue_label,
const char *link,
GHOST_DialogOptions dialog_options) const;
GHOST_TSuccess showMessageBox(const char *title,
const char *message,
const char *help_label,
const char *continue_label,
const char *link,
GHOST_DialogOptions dialog_options) const override;
protected:
/**
@@ -296,7 +300,7 @@ class GHOST_SystemCocoa : public GHOST_System {
* For now, it just registers the window class (WNDCLASS).
* \return A success value.
*/
GHOST_TSuccess init();
GHOST_TSuccess init() override;
/**
* Performs the actual cursor position update (location in screen coordinates).
+55 -40
View File
@@ -48,7 +48,9 @@
#include <mach/mach_time.h>
#pragma mark KeyMap, mouse converters
/* --------------------------------------------------------------------
* Keymaps, mouse converters.
*/
static GHOST_TButton convertButton(int button)
{
@@ -267,17 +269,16 @@ static GHOST_TKey convertKey(int rawCode, unichar recvChar)
if ((recvChar >= 'A') && (recvChar <= 'Z')) {
return (GHOST_TKey)(recvChar - 'A' + GHOST_kKeyA);
}
else if ((recvChar >= 'a') && (recvChar <= 'z')) {
if ((recvChar >= 'a') && (recvChar <= 'z')) {
return (GHOST_TKey)(recvChar - 'a' + GHOST_kKeyA);
}
else {
/* Leopard and Snow Leopard 64bit compatible API. */
CFDataRef uchrHandle; /* The keyboard layout. */
TISInputSourceRef kbdTISHandle;
kbdTISHandle = TISCopyCurrentKeyboardLayoutInputSource();
uchrHandle = (CFDataRef)TISGetInputSourceProperty(kbdTISHandle,
kTISPropertyUnicodeKeyLayoutData);
const TISInputSourceRef kbdTISHandle = TISCopyCurrentKeyboardLayoutInputSource();
/* The keyboard layout. */
const CFDataRef uchrHandle = static_cast<CFDataRef>(
TISGetInputSourceProperty(kbdTISHandle, kTISPropertyUnicodeKeyLayoutData));
CFRelease(kbdTISHandle);
/* Get actual character value of the "remappable" keys in international keyboards,
@@ -334,7 +335,9 @@ static GHOST_TKey convertKey(int rawCode, unichar recvChar)
return GHOST_kKeyUnknown;
}
#pragma mark Utility functions
/* --------------------------------------------------------------------
* Utility functions.
*/
#define FIRSTFILEBUFLG 512
static bool g_hasFirstFile = false;
@@ -349,12 +352,12 @@ extern "C" int GHOST_HACK_getFirstFile(char buf[FIRSTFILEBUFLG])
buf[FIRSTFILEBUFLG - 1] = '\0';
return 1;
}
else {
return 0;
}
return 0;
}
#pragma mark Cocoa objects
/* --------------------------------------------------------------------
* Cocoa objects.
*/
/**
* CocoaAppDelegate
@@ -486,7 +489,7 @@ extern "C" int GHOST_HACK_getFirstFile(char buf[FIRSTFILEBUFLG])
return;
}
NSInteger index = [[NSApp orderedWindows] indexOfObject:closing_window];
const NSInteger index = [[NSApp orderedWindows] indexOfObject:closing_window];
if (index != NSNotFound) {
return;
}
@@ -529,7 +532,9 @@ extern "C" int GHOST_HACK_getFirstFile(char buf[FIRSTFILEBUFLG])
@end
#pragma mark initialization/finalization
/* --------------------------------------------------------------------
* Initialization / Finalization.
*/
GHOST_SystemCocoa::GHOST_SystemCocoa()
{
@@ -673,7 +678,9 @@ GHOST_TSuccess GHOST_SystemCocoa::init()
return success;
}
#pragma mark window management
/* --------------------------------------------------------------------
* Window management.
*/
uint64_t GHOST_SystemCocoa::getMilliSeconds() const
{
@@ -694,10 +701,10 @@ void GHOST_SystemCocoa::getMainDisplayDimensions(uint32_t &width, uint32_t &heig
{
@autoreleasepool {
/* Get visible frame, that is frame excluding dock and top menu bar. */
NSRect frame = [[NSScreen mainScreen] visibleFrame];
const NSRect frame = [[NSScreen mainScreen] visibleFrame];
/* Returns max window contents (excluding title bar...). */
NSRect contentRect = [NSWindow
const NSRect contentRect = [NSWindow
contentRectForFrameRect:frame
styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
NSWindowStyleMaskMiniaturizable)];
@@ -726,10 +733,9 @@ GHOST_IWindow *GHOST_SystemCocoa::createWindow(const char *title,
{
GHOST_IWindow *window = nullptr;
@autoreleasepool {
/* Get the available rect for including window contents. */
NSRect frame = [[NSScreen mainScreen] visibleFrame];
NSRect contentRect = [NSWindow
const NSRect frame = [[NSScreen mainScreen] visibleFrame];
const NSRect contentRect = [NSWindow
contentRectForFrameRect:frame
styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
NSWindowStyleMaskMiniaturizable)];
@@ -826,10 +832,11 @@ GHOST_TSuccess GHOST_SystemCocoa::disposeContext(GHOST_IContext *context)
GHOST_IWindow *GHOST_SystemCocoa::getWindowUnderCursor(int32_t x, int32_t y)
{
NSPoint scr_co = NSMakePoint(x, y);
const NSPoint scr_co = NSMakePoint(x, y);
@autoreleasepool {
int windowNumberAtPoint = [NSWindow windowNumberAtPoint:scr_co belowWindowWithWindowNumber:0];
const int windowNumberAtPoint = [NSWindow windowNumberAtPoint:scr_co
belowWindowWithWindowNumber:0];
NSWindow *nswindow = [NSApp windowWithWindowNumber:windowNumberAtPoint];
if (nswindow == nil) {
@@ -845,11 +852,11 @@ GHOST_IWindow *GHOST_SystemCocoa::getWindowUnderCursor(int32_t x, int32_t y)
*/
GHOST_TSuccess GHOST_SystemCocoa::getCursorPosition(int32_t &x, int32_t &y) const
{
NSPoint mouseLoc = [NSEvent mouseLocation];
const NSPoint mouseLoc = [NSEvent mouseLocation];
/* Returns the mouse location in screen coordinates. */
x = (int32_t)mouseLoc.x;
y = (int32_t)mouseLoc.y;
x = int32_t(mouseLoc.x);
y = int32_t(mouseLoc.y);
return GHOST_kSuccess;
}
@@ -937,7 +944,7 @@ GHOST_TSuccess GHOST_SystemCocoa::getPixelAtCursor(float r_color[3]) const
GHOST_TSuccess GHOST_SystemCocoa::setMouseCursorPosition(int32_t x, int32_t y)
{
float xf = (float)x, yf = (float)y;
float xf = float(x), yf = float(y);
GHOST_WindowCocoa *window = (GHOST_WindowCocoa *)m_windowManager->getActiveWindow();
if (!window) {
return GHOST_kFailure;
@@ -945,7 +952,7 @@ GHOST_TSuccess GHOST_SystemCocoa::setMouseCursorPosition(int32_t x, int32_t y)
@autoreleasepool {
NSScreen *windowScreen = window->getScreen();
NSRect screenRect = windowScreen.frame;
const NSRect screenRect = windowScreen.frame;
/* Set position relative to current screen. */
xf -= screenRect.origin.x;
@@ -982,7 +989,7 @@ GHOST_TSuccess GHOST_SystemCocoa::getModifierKeys(GHOST_ModifierKeys &keys) cons
GHOST_TSuccess GHOST_SystemCocoa::getButtons(GHOST_Buttons &buttons) const
{
UInt32 button_state = GetCurrentEventButtonState();
const UInt32 button_state = GetCurrentEventButtonState();
buttons.clear();
buttons.set(GHOST_kButtonMaskLeft, button_state & (1 << 0));
@@ -1004,7 +1011,9 @@ GHOST_TCapabilityFlag GHOST_SystemCocoa::getCapabilities() const
GHOST_kCapabilityClipboardImages));
}
#pragma mark Event handlers
/* --------------------------------------------------------------------
* Event handlers.
*/
/**
* The event queue polling function
@@ -1305,7 +1314,7 @@ GHOST_TSuccess GHOST_SystemCocoa::handleDraggingEvent(GHOST_TEventType eventType
strArray->strings[i] = temp_buff;
}
eventData = (GHOST_TDragnDropDataPtr)strArray;
eventData = static_cast<GHOST_TDragnDropDataPtr>(strArray);
break;
}
case GHOST_kDragnDropTypeString: {
@@ -1322,14 +1331,14 @@ GHOST_TSuccess GHOST_SystemCocoa::handleDraggingEvent(GHOST_TEventType eventType
temp_buff, [droppedStr cStringUsingEncoding:NSUTF8StringEncoding], pastedTextSize);
temp_buff[pastedTextSize] = '\0';
eventData = (GHOST_TDragnDropDataPtr)temp_buff;
eventData = static_cast<GHOST_TDragnDropDataPtr>(temp_buff);
break;
}
case GHOST_kDragnDropTypeBitmap: {
NSImage *droppedImg = (NSImage *)data;
NSSize imgSize = droppedImg.size;
const ImBuf *ibuf = IMB_allocImBuf(imgSize.width, imgSize.height, 32, IB_rect);
ImBuf *ibuf = IMB_allocImBuf(imgSize.width, imgSize.height, 32, IB_rect);
if (!ibuf) {
[droppedImg release];
return GHOST_kFailure;
@@ -1448,7 +1457,7 @@ GHOST_TSuccess GHOST_SystemCocoa::handleDraggingEvent(GHOST_TEventType eventType
[droppedImg release];
}
eventData = (GHOST_TDragnDropDataPtr)ibuf;
eventData = static_cast<GHOST_TDragnDropDataPtr>(ibuf);
break;
}
@@ -1487,12 +1496,14 @@ void GHOST_SystemCocoa::handleQuitRequest()
bool GHOST_SystemCocoa::handleOpenDocumentRequest(void *filepathStr)
{
NSString *filepath = (NSString *)filepathStr;
/* Check for blender opened windows and make the front-most key.
* In case blender is minimized, opened on another desktop space,
* or in full-screen mode. */
@autoreleasepool {
NSArray *windowsList = [NSApp orderedWindows];
if (windowsList.count) {
if ([windowsList count]) {
[[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];
}
@@ -1510,7 +1521,6 @@ bool GHOST_SystemCocoa::handleOpenDocumentRequest(void *filepathStr)
return NO;
}
NSString *filepath = (NSString *)filepathStr;
const size_t filenameTextSize = [filepath lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
char *temp_buff = (char *)malloc(filenameTextSize + 1);
@@ -1521,8 +1531,10 @@ bool GHOST_SystemCocoa::handleOpenDocumentRequest(void *filepathStr)
memcpy(temp_buff, [filepath cStringUsingEncoding:NSUTF8StringEncoding], filenameTextSize);
temp_buff[filenameTextSize] = '\0';
pushEvent(new GHOST_EventString(
getMilliSeconds(), GHOST_kEventOpenMainFile, window, (GHOST_TEventDataPtr)temp_buff));
pushEvent(new GHOST_EventString(getMilliSeconds(),
GHOST_kEventOpenMainFile,
window,
static_cast<GHOST_TEventDataPtr>(temp_buff)));
}
return YES;
}
@@ -2040,7 +2052,9 @@ GHOST_TSuccess GHOST_SystemCocoa::handleKeyEvent(void *eventPtr)
return GHOST_kSuccess;
}
#pragma mark Clipboard get/set
/* --------------------------------------------------------------------
* Clipboard get/set.
*/
char *GHOST_SystemCocoa::getClipboard(bool /*selection*/) const
{
@@ -2053,6 +2067,7 @@ char *GHOST_SystemCocoa::getClipboard(bool /*selection*/) const
}
const size_t pastedTextSize = [textPasted lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
char *temp_buff = (char *)malloc(pastedTextSize + 1);
if (temp_buff == nullptr) {
@@ -2118,7 +2133,7 @@ GHOST_TSuccess GHOST_SystemCocoa::showMessageBox(const char *title,
[alert addButtonWithTitle:helpString];
}
NSModalResponse response = [alert runModal];
const NSModalResponse response = [alert runModal];
if (response == NSAlertSecondButtonReturn) {
NSString *linkString = [NSString stringWithCString:link];
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:linkString]];
@@ -19,41 +19,41 @@ class GHOST_SystemPathsCocoa : public GHOST_SystemPaths {
/**
* Constructor.
*/
GHOST_SystemPathsCocoa();
GHOST_SystemPathsCocoa() = default;
/**
* Destructor.
*/
~GHOST_SystemPathsCocoa();
~GHOST_SystemPathsCocoa() override = default;
/**
* Determine the base directory in which shared resources are located. It will first try to use
* "unpack and run" path, then look for properly installed path, including versioning.
* \return Unsigned char string pointing to system directory (eg `/usr/share/blender/`).
*/
const char *getSystemDir(int version, const char *versionstr) const;
const char *getSystemDir(int version, const char *versionstr) const override;
/**
* Determine the base directory in which user configuration is stored, including versioning.
* If needed, it will create the base directory.
* \return Unsigned char string pointing to user directory (eg `~/.blender/`).
*/
const char *getUserDir(int version, const char *versionstr) const;
const char *getUserDir(int version, const char *versionstr) const override;
/**
* Determine a special ("well known") and easy to reach user directory.
* \return Unsigned char string pointing to user directory (eg `~/Documents/`).
*/
const char *getUserSpecialDir(GHOST_TUserSpecialDirTypes type) const;
const char *getUserSpecialDir(GHOST_TUserSpecialDirTypes type) const override;
/**
* Determine the directory of the current binary.
* \return Unsigned char string pointing to the binary directory.
*/
const char *getBinaryDir() const;
const char *getBinaryDir() const override;
/**
* Add the file to the operating system most recently used files
*/
void addToSystemRecentFiles(const char *filepath) const;
void addToSystemRecentFiles(const char *filepath) const override;
};
@@ -8,13 +8,9 @@
#include "GHOST_Debug.hh"
#include "GHOST_SystemPathsCocoa.hh"
#pragma mark initialization/finalization
GHOST_SystemPathsCocoa::GHOST_SystemPathsCocoa() {}
GHOST_SystemPathsCocoa::~GHOST_SystemPathsCocoa() {}
#pragma mark Base directories retrieval
/* --------------------------------------------------------------------
* Base directories retrieval.
*/
static const char *GetApplicationSupportDir(const char *versionstr,
const NSSearchPathDomainMask mask,
@@ -38,13 +34,13 @@ static const char *GetApplicationSupportDir(const char *versionstr,
return tempPath;
}
const char *GHOST_SystemPathsCocoa::getSystemDir(int, const char *versionstr) const
const char *GHOST_SystemPathsCocoa::getSystemDir(int /* version */, const char *versionstr) const
{
static char tempPath[512] = "";
return GetApplicationSupportDir(versionstr, NSLocalDomainMask, tempPath, sizeof(tempPath));
}
const char *GHOST_SystemPathsCocoa::getUserDir(int, const char *versionstr) const
const char *GHOST_SystemPathsCocoa::getUserDir(int /* version */, const char *versionstr) const
{
static char tempPath[512] = "";
return GetApplicationSupportDir(versionstr, NSUserDomainMask, tempPath, sizeof(tempPath));
+32 -32
View File
@@ -54,42 +54,42 @@ class GHOST_WindowCocoa : public GHOST_Window {
const bool stereoVisual = false,
bool is_debug = false,
bool dialog = false,
GHOST_WindowCocoa *parentWindow = 0);
GHOST_WindowCocoa *parentWindow = nullptr);
/**
* Destructor.
* Closes the window and disposes resources allocated.
*/
~GHOST_WindowCocoa();
~GHOST_WindowCocoa() override;
/**
* Returns indication as to whether the window is valid.
* \return The validity of the window.
*/
bool getValid() const;
bool getValid() const override;
/**
* Returns the associated NSWindow object
* \return The associated NSWindow object
*/
void *getOSWindow() const;
void *getOSWindow() const override;
/**
* Sets the title displayed in the title bar.
* \param title: The title to display in the title bar.
*/
void setTitle(const char *title);
void setTitle(const char *title) override;
/**
* Returns the title displayed in the title bar.
* \param title: The title displayed in the title bar.
*/
std::string getTitle() const;
std::string getTitle() const override;
/**
* Sets the file name represented by this window.
* \param filepath: The file directory.
*/
GHOST_TSuccess setPath(const char *filepath);
GHOST_TSuccess setPath(const char *filepath) override;
/**
* Returns the window rectangle dimensions.
@@ -97,46 +97,46 @@ class GHOST_WindowCocoa : public GHOST_Window {
* relative to the upper-left corner of the screen.
* \param bounds: The bounding rectangle of the window.
*/
void getWindowBounds(GHOST_Rect &bounds) const;
void getWindowBounds(GHOST_Rect &bounds) const override;
/**
* Returns the client rectangle dimensions.
* The left and top members of the rectangle are always zero.
* \param bounds: The bounding rectangle of the client area of the window.
*/
void getClientBounds(GHOST_Rect &bounds) const;
void getClientBounds(GHOST_Rect &bounds) const override;
/**
* Resizes client rectangle width.
* \param width: The new width of the client area of the window.
*/
GHOST_TSuccess setClientWidth(uint32_t width);
GHOST_TSuccess setClientWidth(uint32_t width) override;
/**
* Resizes client rectangle height.
* \param height: The new height of the client area of the window.
*/
GHOST_TSuccess setClientHeight(uint32_t height);
GHOST_TSuccess setClientHeight(uint32_t height) override;
/**
* Resizes client rectangle.
* \param width: The new width of the client area of the window.
* \param height: The new height of the client area of the window.
*/
GHOST_TSuccess setClientSize(uint32_t width, uint32_t height);
GHOST_TSuccess setClientSize(uint32_t width, uint32_t height) override;
/**
* Returns the state of the window (normal, minimized, maximized).
* \return The state of the window.
*/
GHOST_TWindowState getState() const;
GHOST_TWindowState getState() const override;
/**
* Sets the window "modified" status, indicating unsaved changes
* \param isUnsavedChanges: Unsaved changes or not.
* \return Indication of success.
*/
GHOST_TSuccess setModifiedState(bool isUnsavedChanges);
GHOST_TSuccess setModifiedState(bool isUnsavedChanges) override;
/**
* Converts a point in screen coordinates to client rectangle coordinates
@@ -145,7 +145,7 @@ class GHOST_WindowCocoa : public GHOST_Window {
* \param outX: The x-coordinate in the client rectangle.
* \param outY: The y-coordinate in the client rectangle.
*/
void screenToClient(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const;
void screenToClient(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const override;
/**
* Converts a point in client rectangle coordinates to screen coordinates.
@@ -154,7 +154,7 @@ class GHOST_WindowCocoa : public GHOST_Window {
* \param outX: The x-coordinate on the screen.
* \param outY: The y-coordinate on the screen.
*/
void clientToScreen(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const;
void clientToScreen(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const override;
/**
* Converts a point in client rectangle coordinates to screen coordinates.
@@ -187,19 +187,19 @@ class GHOST_WindowCocoa : public GHOST_Window {
* \param state: The state of the window.
* \return Indication of success.
*/
GHOST_TSuccess setState(GHOST_TWindowState state);
GHOST_TSuccess setState(GHOST_TWindowState state) override;
/**
* Sets the order of the window (bottom, top).
* \param order: The order of the window.
* \return Indication of success.
*/
GHOST_TSuccess setOrder(GHOST_TWindowOrder order);
GHOST_TSuccess setOrder(GHOST_TWindowOrder order) override;
NSCursor *getStandardCursor(GHOST_TStandardCursor cursor) const;
void loadCursor(bool visible, GHOST_TStandardCursor cursor) const;
bool isDialog() const;
bool isDialog() const override;
GHOST_TabletData &GetCocoaTabletData()
{
@@ -210,21 +210,21 @@ class GHOST_WindowCocoa : public GHOST_Window {
* Sets the progress bar value displayed in the window/application icon
* \param progress: The progress percentage (0.0 to 1.0).
*/
GHOST_TSuccess setProgressBar(float progress);
GHOST_TSuccess setProgressBar(float progress) override;
/**
* Hides the progress bar icon
*/
GHOST_TSuccess endProgressBar();
GHOST_TSuccess endProgressBar() override;
void setNativePixelSize();
GHOST_TSuccess beginFullScreen() const
GHOST_TSuccess beginFullScreen() const override
{
return GHOST_kFailure;
}
GHOST_TSuccess endFullScreen() const
GHOST_TSuccess endFullScreen() const override
{
return GHOST_kFailure;
}
@@ -246,8 +246,8 @@ class GHOST_WindowCocoa : public GHOST_Window {
}
#ifdef WITH_INPUT_IME
void beginIME(int32_t x, int32_t y, int32_t w, int32_t h, bool completed);
void endIME();
void beginIME(int32_t x, int32_t y, int32_t w, int32_t h, bool completed) override;
void endIME() override;
#endif /* WITH_INPUT_IME */
protected:
@@ -255,32 +255,32 @@ class GHOST_WindowCocoa : public GHOST_Window {
* \param type: The type of rendering context create.
* \return Indication of success.
*/
GHOST_Context *newDrawingContext(GHOST_TDrawingContextType type);
GHOST_Context *newDrawingContext(GHOST_TDrawingContextType type) override;
/**
* Invalidates the contents of this window.
* \return Indication of success.
*/
GHOST_TSuccess invalidate();
GHOST_TSuccess invalidate() override;
/**
* Sets the cursor visibility on the window using
* native window system calls.
*/
GHOST_TSuccess setWindowCursorVisibility(bool visible);
GHOST_TSuccess setWindowCursorVisibility(bool visible) override;
/**
* Sets the cursor grab on the window using
* native window system calls.
*/
GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode mode);
GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode mode) override;
/**
* Sets the cursor shape on the window using
* native window system calls.
*/
GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape);
GHOST_TSuccess hasCursorShape(GHOST_TStandardCursor shape);
GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape) override;
GHOST_TSuccess hasCursorShape(GHOST_TStandardCursor shape) override;
/**
* Sets the cursor shape on the window using
@@ -292,7 +292,7 @@ class GHOST_WindowCocoa : public GHOST_Window {
int sizey,
int hotX,
int hotY,
bool canInvertColor);
bool canInvertColor) override;
/** The window containing the view */
BlenderWindow *m_window;
+41 -26
View File
@@ -21,13 +21,15 @@
# include "GHOST_ContextVK.hh"
#endif
#include <Cocoa/Cocoa.h>
#include <Metal/Metal.h>
#include <QuartzCore/QuartzCore.h>
#import <Cocoa/Cocoa.h>
#import <Metal/Metal.h>
#import <QuartzCore/QuartzCore.h>
#include <sys/sysctl.h>
#pragma mark Blender window delegate object
/* --------------------------------------------------------------------
* Blender window delegate object.
*/
@interface BlenderWindowDelegate : NSObject <NSWindowDelegate>
@@ -234,7 +236,7 @@
- (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender
{
NSPoint mouseLocation = [sender draggingLocation];
const NSPoint mouseLocation = [sender draggingLocation];
m_systemCocoa->handleDraggingEvent(GHOST_kEventDraggingUpdated,
m_draggedObjectType,
@@ -254,10 +256,10 @@
- (BOOL)prepareForDragOperation:(id<NSDraggingInfo>)sender
{
if (m_windowCocoa->canAcceptDragOperation())
if (m_windowCocoa->canAcceptDragOperation()) {
return YES;
else
return NO;
}
return NO;
}
- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender
@@ -315,7 +317,9 @@
#undef COCOA_VIEW_CLASS
#undef COCOA_VIEW_BASE_CLASS
#pragma mark initialization / finalization
/* --------------------------------------------------------------------
* Initialization / Finalization.
*/
GHOST_WindowCocoa::GHOST_WindowCocoa(GHOST_SystemCocoa *systemCocoa,
const char *title,
@@ -334,7 +338,7 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(GHOST_SystemCocoa *systemCocoa,
m_metalView(nil),
m_metalLayer(nil),
m_systemCocoa(systemCocoa),
m_customCursor(0),
m_customCursor(nullptr),
m_immediateDraw(false),
m_debug_context(is_debug),
m_is_dialog(is_dialog)
@@ -503,6 +507,10 @@ GHOST_WindowCocoa::~GHOST_WindowCocoa()
}
}
/* --------------------------------------------------------------------
* Accessors.
*/
bool GHOST_WindowCocoa::getValid() const
{
NSView *view = (m_openGLView) ? m_openGLView : m_metalView;
@@ -569,7 +577,6 @@ void GHOST_WindowCocoa::getWindowBounds(GHOST_Rect &bounds) const
@autoreleasepool {
const NSRect screenSize = m_window.screen.visibleFrame;
const NSRect rect = m_window.frame;
bounds.m_b = screenSize.size.height - (rect.origin.y - screenSize.origin.y);
@@ -608,7 +615,7 @@ GHOST_TSuccess GHOST_WindowCocoa::setClientWidth(uint32_t width)
GHOST_Rect cBnds;
getClientBounds(cBnds);
if (((uint32_t)cBnds.getWidth()) != width) {
if ((uint32_t(cBnds.getWidth())) != width) {
const NSSize size = {(CGFloat)width, (CGFloat)cBnds.getHeight()};
[m_window setContentSize:size];
}
@@ -624,7 +631,7 @@ GHOST_TSuccess GHOST_WindowCocoa::setClientHeight(uint32_t height)
GHOST_Rect cBnds;
getClientBounds(cBnds);
if (((uint32_t)cBnds.getHeight()) != height) {
if ((uint32_t(cBnds.getHeight())) != height) {
const NSSize size = {(CGFloat)cBnds.getWidth(), (CGFloat)height};
[m_window setContentSize:size];
}
@@ -637,9 +644,9 @@ GHOST_TSuccess GHOST_WindowCocoa::setClientSize(uint32_t width, uint32_t height)
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientSize(): window invalid");
@autoreleasepool {
GHOST_Rect cBnds, wBnds;
GHOST_Rect cBnds;
getClientBounds(cBnds);
if ((((uint32_t)cBnds.getWidth()) != width) || (((uint32_t)cBnds.getHeight()) != height)) {
if (((uint32_t(cBnds.getWidth())) != width) || ((uint32_t(cBnds.getHeight())) != height)) {
const NSSize size = {(CGFloat)width, (CGFloat)height};
[m_window setContentSize:size];
}
@@ -738,7 +745,7 @@ NSScreen *GHOST_WindowCocoa::getScreen()
}
/* called for event, when window leaves monitor to another */
void GHOST_WindowCocoa::setNativePixelSize(void)
void GHOST_WindowCocoa::setNativePixelSize()
{
NSView *view = (m_openGLView) ? m_openGLView : m_metalView;
const NSRect backingBounds = [view convertRectToBacking:[view bounds]];
@@ -746,7 +753,7 @@ void GHOST_WindowCocoa::setNativePixelSize(void)
GHOST_Rect rect;
getClientBounds(rect);
m_nativePixelSize = (float)backingBounds.size.width / (float)rect.getWidth();
m_nativePixelSize = float(backingBounds.size.width) / float(rect.getWidth());
}
/**
@@ -770,7 +777,7 @@ GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state)
break;
case GHOST_kWindowStateFullScreen: {
NSUInteger masks = m_window.styleMask;
const NSUInteger masks = m_window.styleMask;
if (!(masks & NSWindowStyleMaskFullScreen)) {
[m_window toggleFullScreen:nil];
@@ -780,7 +787,7 @@ GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state)
case GHOST_kWindowStateNormal:
default:
@autoreleasepool {
NSUInteger masks = m_window.styleMask;
const NSUInteger masks = m_window.styleMask;
if (masks & NSWindowStyleMaskFullScreen) {
/* Lion style full-screen. */
@@ -831,7 +838,9 @@ GHOST_TSuccess GHOST_WindowCocoa::setOrder(GHOST_TWindowOrder order)
return GHOST_kSuccess;
}
#pragma mark Drawing context
/* --------------------------------------------------------------------
* Drawing context.
*/
GHOST_Context *GHOST_WindowCocoa::newDrawingContext(GHOST_TDrawingContextType type)
{
@@ -865,7 +874,9 @@ GHOST_Context *GHOST_WindowCocoa::newDrawingContext(GHOST_TDrawingContextType ty
}
}
#pragma mark invalidate
/* --------------------------------------------------------------------
* Invalidate.
*/
GHOST_TSuccess GHOST_WindowCocoa::invalidate()
{
@@ -878,7 +889,9 @@ GHOST_TSuccess GHOST_WindowCocoa::invalidate()
return GHOST_kSuccess;
}
#pragma mark Progress bar
/* --------------------------------------------------------------------
* Progress bar.
*/
GHOST_TSuccess GHOST_WindowCocoa::setProgressBar(float progress)
{
@@ -940,14 +953,16 @@ GHOST_TSuccess GHOST_WindowCocoa::endProgressBar()
return GHOST_kSuccess;
}
#pragma mark Cursor handling
/* --------------------------------------------------------------------
* Cursor handling.
*/
static NSCursor *getImageCursor(GHOST_TStandardCursor shape, NSString *name, NSPoint hotspot)
{
static NSCursor *cursors[(int)GHOST_kStandardCursorNumCursors] = {0};
static bool loaded[(int)GHOST_kStandardCursorNumCursors] = {false};
static NSCursor *cursors[GHOST_kStandardCursorNumCursors] = {nullptr};
static bool loaded[GHOST_kStandardCursorNumCursors] = {false};
const int index = (int)shape;
const int index = int(shape);
if (!loaded[index]) {
/* Load image from file in application Resources folder. */
@autoreleasepool {
+1 -1
View File
@@ -12,7 +12,7 @@
#include <cstdlib>
static char *user_locale = NULL;
static char *user_locale = nullptr;
/* Get current locale. */
const char *osx_user_locale()
@@ -212,8 +212,6 @@ bool BLI_change_working_dir(const char *dir)
if ([[NSFileManager defaultManager] changeCurrentDirectoryPath:path] == YES) {
return true;
}
else {
return false;
}
return false;
}
}