[Bf-blender-cvs] [6292cab193a] master: GHOST: add GHOST_HasWindowCursorShape() to test if standard cursor exists

Brecht Van Lommel noreply at git.blender.org
Thu Sep 26 14:33:11 CEST 2019


Commit: 6292cab193a6aa2a80ceba929079b47de7d8f48a
Author: Brecht Van Lommel
Date:   Thu Sep 26 14:31:43 2019 +0200
Branches: master
https://developer.blender.org/rB6292cab193a6aa2a80ceba929079b47de7d8f48a

GHOST: add GHOST_HasWindowCursorShape() to test if standard cursor exists

Ref D5197

===================================================================

M	intern/ghost/GHOST_C-api.h
M	intern/ghost/GHOST_IWindow.h
M	intern/ghost/intern/GHOST_C-api.cpp
M	intern/ghost/intern/GHOST_WindowCocoa.h
M	intern/ghost/intern/GHOST_WindowCocoa.mm
M	intern/ghost/intern/GHOST_WindowSDL.cpp
M	intern/ghost/intern/GHOST_WindowSDL.h
M	intern/ghost/intern/GHOST_WindowWin32.cpp
M	intern/ghost/intern/GHOST_WindowWin32.h
M	intern/ghost/intern/GHOST_WindowX11.cpp
M	intern/ghost/intern/GHOST_WindowX11.h

===================================================================

diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index 9c6a0861280..20bb144a924 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -316,7 +316,8 @@ extern GHOST_TSuccess GHOST_EndProgressBar(GHOST_WindowHandle windowhandle);
 extern GHOST_TStandardCursor GHOST_GetCursorShape(GHOST_WindowHandle windowhandle);
 
 /**
- * Set the shape of the cursor.
+ * Set the shape of the cursor. If the shape is not supported by the platform,
+ * it will use the default cursor instead.
  * \param windowhandle The handle to the window
  * \param cursorshape The new cursor shape type id.
  * \return Indication of success.
@@ -324,6 +325,13 @@ extern GHOST_TStandardCursor GHOST_GetCursorShape(GHOST_WindowHandle windowhandl
 extern GHOST_TSuccess GHOST_SetCursorShape(GHOST_WindowHandle windowhandle,
                                            GHOST_TStandardCursor cursorshape);
 
+/**
+ * Test if the standard cursor shape is supported by current platform.
+ * \return Indication of success.
+ */
+extern GHOST_TSuccess GHOST_HasCursorShape(GHOST_WindowHandle windowhandle,
+                                           GHOST_TStandardCursor cursorshape);
+
 /**
  * Set the shape of the cursor to a custom cursor of specified size.
  * \param windowhandle The handle to the window
diff --git a/intern/ghost/GHOST_IWindow.h b/intern/ghost/GHOST_IWindow.h
index 1a1844bfe41..03a0db9abbe 100644
--- a/intern/ghost/GHOST_IWindow.h
+++ b/intern/ghost/GHOST_IWindow.h
@@ -279,6 +279,12 @@ class GHOST_IWindow {
    */
   virtual GHOST_TSuccess setCursorShape(GHOST_TStandardCursor cursorShape) = 0;
 
+  /**
+   * Test if the standard cursor shape is supported by current platform.
+   * \return Indication of success.
+   */
+  virtual GHOST_TSuccess hasCursorShape(GHOST_TStandardCursor cursorShape) = 0;
+
   /**
    * Set the shape of the cursor to a custom cursor.
    * \param   bitmap  The bitmap data for the cursor.
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index 78f171af7d1..a1a209af77a 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -264,6 +264,14 @@ GHOST_TSuccess GHOST_SetCursorShape(GHOST_WindowHandle windowhandle,
   return window->setCursorShape(cursorshape);
 }
 
+GHOST_TSuccess GHOST_HasCursorShape(GHOST_WindowHandle windowhandle,
+                                    GHOST_TStandardCursor cursorshape)
+{
+  GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
+
+  return window->hasCursorShape(cursorshape);
+}
+
 GHOST_TSuccess GHOST_SetCustomCursorShape(GHOST_WindowHandle windowhandle,
                                           GHOST_TUns8 *bitmap,
                                           GHOST_TUns8 *mask,
diff --git a/intern/ghost/intern/GHOST_WindowCocoa.h b/intern/ghost/intern/GHOST_WindowCocoa.h
index 5e857c05a09..66de8bcf7cc 100644
--- a/intern/ghost/intern/GHOST_WindowCocoa.h
+++ b/intern/ghost/intern/GHOST_WindowCocoa.h
@@ -215,6 +215,7 @@ class GHOST_WindowCocoa : public GHOST_Window {
    */
   GHOST_TSuccess setOrder(GHOST_TWindowOrder order);
 
+  NSCursor *getStandardCursor(GHOST_TStandardCursor cursor) const;
   void loadCursor(bool visible, GHOST_TStandardCursor cursor) const;
 
   const GHOST_TabletData *GetTabletData()
@@ -296,6 +297,7 @@ class GHOST_WindowCocoa : public GHOST_Window {
    * native window system calls.
    */
   GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape);
+  GHOST_TSuccess hasCursorShape(GHOST_TStandardCursor shape);
 
   /**
    * Sets the cursor shape on the window using
diff --git a/intern/ghost/intern/GHOST_WindowCocoa.mm b/intern/ghost/intern/GHOST_WindowCocoa.mm
index 0b8e808b84e..dcf6d5da487 100644
--- a/intern/ghost/intern/GHOST_WindowCocoa.mm
+++ b/intern/ghost/intern/GHOST_WindowCocoa.mm
@@ -925,12 +925,56 @@ GHOST_TSuccess GHOST_WindowCocoa::endProgressBar()
 
 #pragma mark Cursor handling
 
-void GHOST_WindowCocoa::loadCursor(bool visible, GHOST_TStandardCursor cursor) const
+NSCursor *GHOST_WindowCocoa::getStandardCursor(GHOST_TStandardCursor shape) const
 {
-  static bool systemCursorVisible = true;
-
-  NSCursor *tmpCursor = nil;
+  switch (shape) {
+    case GHOST_kStandardCursorCustom:
+      if (m_customCursor) {
+        return m_customCursor;
+      }
+      else {
+        return NULL;
+      }
+    case GHOST_kStandardCursorDestroy:
+      return [NSCursor disappearingItemCursor];
+    case GHOST_kStandardCursorText:
+      return [NSCursor IBeamCursor];
+    case GHOST_kStandardCursorCrosshair:
+      return [NSCursor crosshairCursor];
+    case GHOST_kStandardCursorUpDown:
+      return [NSCursor resizeUpDownCursor];
+    case GHOST_kStandardCursorLeftRight:
+      return [NSCursor resizeLeftRightCursor];
+    case GHOST_kStandardCursorTopSide:
+      return [NSCursor resizeUpCursor];
+    case GHOST_kStandardCursorBottomSide:
+      return [NSCursor resizeDownCursor];
+    case GHOST_kStandardCursorLeftSide:
+      return [NSCursor resizeLeftCursor];
+    case GHOST_kStandardCursorRightSide:
+      return [NSCursor resizeRightCursor];
+    case GHOST_kStandardCursorRightArrow:
+    case GHOST_kStandardCursorInfo:
+    case GHOST_kStandardCursorLeftArrow:
+    case GHOST_kStandardCursorHelp:
+    case GHOST_kStandardCursorCycle:
+    case GHOST_kStandardCursorSpray:
+    case GHOST_kStandardCursorWait:
+    case GHOST_kStandardCursorTopLeftCorner:
+    case GHOST_kStandardCursorTopRightCorner:
+    case GHOST_kStandardCursorBottomRightCorner:
+    case GHOST_kStandardCursorBottomLeftCorner:
+    case GHOST_kStandardCursorCopy:
+    case GHOST_kStandardCursorDefault:
+      return [NSCursor arrowCursor];
+    default:
+      return NULL;
+  }
+}
 
+void GHOST_WindowCocoa::loadCursor(bool visible, GHOST_TStandardCursor shape) const
+{
+  static bool systemCursorVisible = true;
   if (visible != systemCursorVisible) {
     if (visible) {
       [NSCursor unhide];
@@ -942,57 +986,12 @@ void GHOST_WindowCocoa::loadCursor(bool visible, GHOST_TStandardCursor cursor) c
     }
   }
 
-  if (cursor == GHOST_kStandardCursorCustom && m_customCursor) {
-    tmpCursor = m_customCursor;
-  }
-  else {
-    switch (cursor) {
-      case GHOST_kStandardCursorDestroy:
-        tmpCursor = [NSCursor disappearingItemCursor];
-        break;
-      case GHOST_kStandardCursorText:
-        tmpCursor = [NSCursor IBeamCursor];
-        break;
-      case GHOST_kStandardCursorCrosshair:
-        tmpCursor = [NSCursor crosshairCursor];
-        break;
-      case GHOST_kStandardCursorUpDown:
-        tmpCursor = [NSCursor resizeUpDownCursor];
-        break;
-      case GHOST_kStandardCursorLeftRight:
-        tmpCursor = [NSCursor resizeLeftRightCursor];
-        break;
-      case GHOST_kStandardCursorTopSide:
-        tmpCursor = [NSCursor resizeUpCursor];
-        break;
-      case GHOST_kStandardCursorBottomSide:
-        tmpCursor = [NSCursor resizeDownCursor];
-        break;
-      case GHOST_kStandardCursorLeftSide:
-        tmpCursor = [NSCursor resizeLeftCursor];
-        break;
-      case GHOST_kStandardCursorRightSide:
-        tmpCursor = [NSCursor resizeRightCursor];
-        break;
-      case GHOST_kStandardCursorRightArrow:
-      case GHOST_kStandardCursorInfo:
-      case GHOST_kStandardCursorLeftArrow:
-      case GHOST_kStandardCursorHelp:
-      case GHOST_kStandardCursorCycle:
-      case GHOST_kStandardCursorSpray:
-      case GHOST_kStandardCursorWait:
-      case GHOST_kStandardCursorTopLeftCorner:
-      case GHOST_kStandardCursorTopRightCorner:
-      case GHOST_kStandardCursorBottomRightCorner:
-      case GHOST_kStandardCursorBottomLeftCorner:
-      case GHOST_kStandardCursorCopy:
-      case GHOST_kStandardCursorDefault:
-      default:
-        tmpCursor = [NSCursor arrowCursor];
-        break;
-    };
+  NSCursor *cursor = getStandardCursor(shape);
+  if (cursor == NULL) {
+    cursor = getStandardCursor(GHOST_kStandardCursorDefault);
   }
-  [tmpCursor set];
+
+  [cursor set];
 }
 
 GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorVisibility(bool visible)
@@ -1047,11 +1046,6 @@ GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorShape(GHOST_TStandardCursor sha
 {
   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 
-  if (m_customCursor) {
-    [m_customCursor release];
-    m_customCursor = nil;
-  }
-
   if ([m_window isVisible]) {
     loadCursor(getCursorVisibility(), shape);
   }
@@ -1060,6 +1054,14 @@ GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorShape(GHOST_TStandardCursor sha
   return GHOST_kSuccess;
 }
 
+GHOST_TSuccess GHOST_WindowCocoa::hasCursorShape(GHOST_TStandardCursor shape)
+{
+  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+  GHOST_TSuccess success = (getStandardCursor(shape)) ? GHOST_kSuccess : GHOST_kFailure;
+  [pool drain];
+  return success;
+}
+
 /** Reverse the bits in a GHOST_TUns8
 static GHOST_TUns8 uns8ReverseBits(GHOST_TUns8 ch)
 {
diff --git a/intern/ghost/intern/GHOST_WindowSDL.cpp b/intern/ghost/intern/GHOST_WindowSDL.cpp
index cd9863d7e72..38c6f51dea4 100644
--- a/intern/ghost/intern/GHOST_WindowSDL.cpp
+++ b/intern/ghost/intern/GHOST_WindowSDL.cpp
@@ -583,9 +583,9 @@ static SDL_Cursor *sdl_ghost_CreateCursor(
 }
 
 /* TODO, this is currently never freed but it wont leak either. */
-static void sdl_cursor_init(void)
+static void getStandardCursorShape(GHOST_TStandardCursor shape)
 {
-
+  if (sdl_std_cursor_array[0] == NULL) {
 #define DEF_CURSOR(name, ind) \
   { \
     sdl_std_cursor_array[(int)ind] = sdl_ghost_CreateCursor( \
@@ -599,32 +599,34 @@ static void sdl_cursor_init(void)
   } \
   (void)0
 
-  DEF_CURSOR(left_ptr, GHOST_kStandardCursorDefault);
-  DEF_CURSOR(right_ptr, GHOST_kStandardCursorRightArrow);
-  DEF_CURSOR(left_ptr, GHOST_kStandardCursorLeftArrow);
-  DEF_CURSOR(umbrella, GHOST_kStandardCursorInfo);  // TODO, replace this one.
-  DEF_CURSOR(pirate, GHOST_kStandardCursorDestroy);
-  DEF_CURSOR(question_arrow, GHOST_kStandardCursorHelp);
-  DEF_CURSOR(exchange, GHOST_kStandardCursorCycle);
-  DEF_CURSOR(spraycan, GHOST_kStandardCursorSpray);
-  DEF_CURSOR(watch, GHOST_kStandardCursorWait);
-  DEF_CURSOR(xterm, GHOST_kStandardCursorText);
-  DEF_CURSOR(crosshair, GH

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list