소스 검색

add custom cursor support

cxgeorge 24 년 전
부모
커밋
85e3e867b4

+ 7 - 1
panda/src/wdxdisplay/config_wdxdisplay.cxx

@@ -62,8 +62,14 @@ init_libwdxdisplay() {
                 wdxGraphicsWindow::make_wdxGraphicsWindow);
                 wdxGraphicsWindow::make_wdxGraphicsWindow);
 }
 }
 
 
-// cant use global var cleanly because global var static init executed after init_libwgl(), incorrectly reiniting var
+// cant use global var cleanly because global var static init executed after init_libwdxdisplay(), incorrectly reiniting var
 Filename get_icon_filename() {
 Filename get_icon_filename() {
   string iconname = config_wdxdisplay.GetString("win32-window-icon","");
   string iconname = config_wdxdisplay.GetString("win32-window-icon","");
   return ExecutionEnvironment::expand_string(iconname);
   return ExecutionEnvironment::expand_string(iconname);
 }
 }
+
+// cant use global var cleanly because global var static init executed after init_libwdxdisplay(), incorrectly reiniting var
+Filename get_cursor_filename() {
+  string cursorname = config_wdxdisplay.GetString("win32-cursor","");
+  return ExecutionEnvironment::expand_string(cursorname);
+}

+ 1 - 0
panda/src/wdxdisplay/config_wdxdisplay.h

@@ -28,6 +28,7 @@ NotifyCategoryDecl(wdxdisplay, EXPCL_PANDADX, EXPTP_PANDADX);
 extern bool bResponsive_minimized_fullscreen_window;
 extern bool bResponsive_minimized_fullscreen_window;
 extern bool dx_force_16bpp_zbuffer;
 extern bool dx_force_16bpp_zbuffer;
 extern Filename get_icon_filename();
 extern Filename get_icon_filename();
+extern Filename get_cursor_filename();
 
 
 extern EXPCL_PANDADX void init_libwdxdisplay();
 extern EXPCL_PANDADX void init_libwdxdisplay();
 
 

+ 22 - 1
panda/src/wdxdisplay/wdxGraphicsWindow.cxx

@@ -845,16 +845,37 @@ void wdxGraphicsWindow::config(void) {
     wc.hInstance      = hinstance;
     wc.hInstance      = hinstance;
 
 
     string windows_icon_filename = get_icon_filename().to_os_specific();
     string windows_icon_filename = get_icon_filename().to_os_specific();
+    string windows_cursor_filename = get_cursor_filename().to_os_specific();
 
 
     if(!windows_icon_filename.empty()) {
     if(!windows_icon_filename.empty()) {
         // Note: LoadImage seems to cause win2k internal heap corruption (outputdbgstr warnings)
         // Note: LoadImage seems to cause win2k internal heap corruption (outputdbgstr warnings)
         // if icon is more than 8bpp
         // if icon is more than 8bpp
+
+        // loads a .ico fmt file
         wc.hIcon = (HICON) LoadImage(NULL, windows_icon_filename.c_str(), IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
         wc.hIcon = (HICON) LoadImage(NULL, windows_icon_filename.c_str(), IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
+
+        if(wc.hIcon==NULL) {
+            wdxdisplay_cat.warning() << "windows icon filename '" << windows_icon_filename << "' not found!!\n";
+        }
     } else {
     } else {
         wc.hIcon = NULL; // use default app icon
         wc.hIcon = NULL; // use default app icon
     }
     }
 
 
-    wc.hCursor        = _hMouseCursor = LoadCursor(NULL, IDC_ARROW);
+    if(!windows_cursor_filename.empty()) {
+        // Note: LoadImage seems to cause win2k internal heap corruption (outputdbgstr warnings)
+        // if icon is more than 8bpp
+
+        // loads a .cur fmt file
+        _hMouseCursor = (HCURSOR) LoadImage(NULL, windows_cursor_filename.c_str(), IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
+
+        if(_hMouseCursor==NULL) {
+            wdxdisplay_cat.warning() << "windows cursor filename '" << windows_cursor_filename << "' not found!!\n";
+        }
+    } else {
+        _hMouseCursor = LoadCursor(NULL, IDC_ARROW);
+    }
+
+    wc.hCursor = _hMouseCursor;
     wc.hbrBackground  = (HBRUSH)GetStockObject(BLACK_BRUSH);
     wc.hbrBackground  = (HBRUSH)GetStockObject(BLACK_BRUSH);
     wc.lpszMenuName   = NULL;
     wc.lpszMenuName   = NULL;
     wc.lpszClassName  = WDX_WINDOWCLASSNAME;
     wc.lpszClassName  = WDX_WINDOWCLASSNAME;

+ 5 - 1
panda/src/wgldisplay/config_wgldisplay.cxx

@@ -71,8 +71,12 @@ init_libwgldisplay() {
 }
 }
 
 
 // cant use global var cleanly because global var static init executed after init_libwgl(), incorrectly reiniting var
 // cant use global var cleanly because global var static init executed after init_libwgl(), incorrectly reiniting var
-Filename get_icon_filename_() {
+Filename get_icon_filename_2() {
   string iconname = config_wgldisplay.GetString("win32-window-icon","");
   string iconname = config_wgldisplay.GetString("win32-window-icon","");
   return ExecutionEnvironment::expand_string(iconname);
   return ExecutionEnvironment::expand_string(iconname);
 }
 }
 
 
+Filename get_cursor_filename_2() {
+  string cursorname = config_wgldisplay.GetString("win32-cursor","");
+  return ExecutionEnvironment::expand_string(cursorname);
+}

+ 5 - 1
panda/src/wgldisplay/config_wgldisplay.h

@@ -25,7 +25,11 @@
 
 
 NotifyCategoryDecl(wgldisplay, EXPCL_PANDAGL, EXPTP_PANDAGL);
 NotifyCategoryDecl(wgldisplay, EXPCL_PANDAGL, EXPTP_PANDAGL);
 
 
-extern Filename get_icon_filename_();
+// for some reason there is a conflict with the pandadx versions of get_icon_filename during linking,
+// so appended '_2' to name
+extern Filename get_icon_filename_2();
+extern Filename get_cursor_filename_2();
+
 extern bool gl_show_fps_meter;
 extern bool gl_show_fps_meter;
 extern float gl_fps_meter_update_interval;
 extern float gl_fps_meter_update_interval;
 extern bool gl_sync_video;
 extern bool gl_sync_video;

+ 26 - 5
panda/src/wgldisplay/wglGraphicsWindow.cxx

@@ -315,18 +315,39 @@ void wglGraphicsWindow::config(void) {
     wc.style      = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
     wc.style      = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
     wc.lpfnWndProc = (WNDPROC) static_window_proc;
     wc.lpfnWndProc = (WNDPROC) static_window_proc;
     wc.hInstance   = hinstance;
     wc.hInstance   = hinstance;
-    
-    string windows_icon_filename = get_icon_filename_().to_os_specific();
-    
+
+    string windows_icon_filename = get_icon_filename_2().to_os_specific();
+    string windows_cursor_filename = get_cursor_filename_2().to_os_specific();
+
     if(!windows_icon_filename.empty()) {
     if(!windows_icon_filename.empty()) {
         // Note: LoadImage seems to cause win2k internal heap corruption (outputdbgstr warnings)
         // Note: LoadImage seems to cause win2k internal heap corruption (outputdbgstr warnings)
         // if icon is more than 8bpp
         // if icon is more than 8bpp
+
+        // loads a .ico fmt file
         wc.hIcon = (HICON) LoadImage(NULL, windows_icon_filename.c_str(), IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
         wc.hIcon = (HICON) LoadImage(NULL, windows_icon_filename.c_str(), IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
+
+        if(wc.hIcon==NULL) {
+            wgldisplay_cat.warning() << "windows icon filename '" << windows_icon_filename << "' not found!!\n";
+        }
     } else {
     } else {
         wc.hIcon = NULL; // use default app icon
         wc.hIcon = NULL; // use default app icon
     }
     }
-    
-    wc.hCursor        = _hMouseCursor = LoadCursor(NULL, IDC_ARROW);
+
+    if(!windows_cursor_filename.empty()) {
+        // Note: LoadImage seems to cause win2k internal heap corruption (outputdbgstr warnings)
+        // if icon is more than 8bpp
+
+        // loads a .cur fmt file
+        _hMouseCursor = (HCURSOR) LoadImage(NULL, windows_cursor_filename.c_str(), IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
+
+        if(_hMouseCursor==NULL) {
+            wgldisplay_cat.warning() << "windows cursor filename '" << windows_cursor_filename << "' not found!!\n";
+        }
+    } else {
+        _hMouseCursor = LoadCursor(NULL, IDC_ARROW);
+    }
+
+    wc.hCursor = _hMouseCursor;
     wc.hbrBackground  = (HBRUSH)GetStockObject(BLACK_BRUSH);
     wc.hbrBackground  = (HBRUSH)GetStockObject(BLACK_BRUSH);
     wc.lpszMenuName   = NULL;
     wc.lpszMenuName   = NULL;
     wc.lpszClassName  = WGL_WINDOWCLASSNAME;
     wc.lpszClassName  = WGL_WINDOWCLASSNAME;