From 85e3e867b4a66fabb4fbd21292b9beb85e00ebf5 Mon Sep 17 00:00:00 2001 From: cxgeorge <> Date: Wed, 19 Sep 2001 23:29:15 +0000 Subject: [PATCH] add custom cursor support --- panda/src/wdxdisplay/config_wdxdisplay.cxx | 8 +++++- panda/src/wdxdisplay/config_wdxdisplay.h | 1 + panda/src/wdxdisplay/wdxGraphicsWindow.cxx | 23 +++++++++++++++- panda/src/wgldisplay/config_wgldisplay.cxx | 6 ++++- panda/src/wgldisplay/config_wgldisplay.h | 6 ++++- panda/src/wgldisplay/wglGraphicsWindow.cxx | 31 ++++++++++++++++++---- 6 files changed, 66 insertions(+), 9 deletions(-) diff --git a/panda/src/wdxdisplay/config_wdxdisplay.cxx b/panda/src/wdxdisplay/config_wdxdisplay.cxx index 98c0bf76d5..f0694e692d 100644 --- a/panda/src/wdxdisplay/config_wdxdisplay.cxx +++ b/panda/src/wdxdisplay/config_wdxdisplay.cxx @@ -62,8 +62,14 @@ init_libwdxdisplay() { 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() { string iconname = config_wdxdisplay.GetString("win32-window-icon",""); 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); +} diff --git a/panda/src/wdxdisplay/config_wdxdisplay.h b/panda/src/wdxdisplay/config_wdxdisplay.h index 867ab6dd49..d3ef06c93a 100644 --- a/panda/src/wdxdisplay/config_wdxdisplay.h +++ b/panda/src/wdxdisplay/config_wdxdisplay.h @@ -28,6 +28,7 @@ NotifyCategoryDecl(wdxdisplay, EXPCL_PANDADX, EXPTP_PANDADX); extern bool bResponsive_minimized_fullscreen_window; extern bool dx_force_16bpp_zbuffer; extern Filename get_icon_filename(); +extern Filename get_cursor_filename(); extern EXPCL_PANDADX void init_libwdxdisplay(); diff --git a/panda/src/wdxdisplay/wdxGraphicsWindow.cxx b/panda/src/wdxdisplay/wdxGraphicsWindow.cxx index cd1ad9393b..0627eb014c 100644 --- a/panda/src/wdxdisplay/wdxGraphicsWindow.cxx +++ b/panda/src/wdxdisplay/wdxGraphicsWindow.cxx @@ -845,16 +845,37 @@ void wdxGraphicsWindow::config(void) { wc.hInstance = hinstance; 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()) { // Note: LoadImage seems to cause win2k internal heap corruption (outputdbgstr warnings) // 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); + + if(wc.hIcon==NULL) { + wdxdisplay_cat.warning() << "windows icon filename '" << windows_icon_filename << "' not found!!\n"; + } } else { 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.lpszMenuName = NULL; wc.lpszClassName = WDX_WINDOWCLASSNAME; diff --git a/panda/src/wgldisplay/config_wgldisplay.cxx b/panda/src/wgldisplay/config_wgldisplay.cxx index 117d923e70..287ebfd768 100644 --- a/panda/src/wgldisplay/config_wgldisplay.cxx +++ b/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 -Filename get_icon_filename_() { +Filename get_icon_filename_2() { string iconname = config_wgldisplay.GetString("win32-window-icon",""); return ExecutionEnvironment::expand_string(iconname); } +Filename get_cursor_filename_2() { + string cursorname = config_wgldisplay.GetString("win32-cursor",""); + return ExecutionEnvironment::expand_string(cursorname); +} diff --git a/panda/src/wgldisplay/config_wgldisplay.h b/panda/src/wgldisplay/config_wgldisplay.h index 6994fa1dee..c54fee43b1 100644 --- a/panda/src/wgldisplay/config_wgldisplay.h +++ b/panda/src/wgldisplay/config_wgldisplay.h @@ -25,7 +25,11 @@ 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 float gl_fps_meter_update_interval; extern bool gl_sync_video; diff --git a/panda/src/wgldisplay/wglGraphicsWindow.cxx b/panda/src/wgldisplay/wglGraphicsWindow.cxx index a6b36529cd..b994ca1cb8 100644 --- a/panda/src/wgldisplay/wglGraphicsWindow.cxx +++ b/panda/src/wgldisplay/wglGraphicsWindow.cxx @@ -315,18 +315,39 @@ void wglGraphicsWindow::config(void) { wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = (WNDPROC) static_window_proc; 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()) { // Note: LoadImage seems to cause win2k internal heap corruption (outputdbgstr warnings) // 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); + + if(wc.hIcon==NULL) { + wgldisplay_cat.warning() << "windows icon filename '" << windows_icon_filename << "' not found!!\n"; + } } else { 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.lpszMenuName = NULL; wc.lpszClassName = WGL_WINDOWCLASSNAME;