fix up mouse stuff

This commit is contained in:
cxgeorge 2002-03-08 03:09:44 +00:00
parent 456a0aca5e
commit 6051745d92
9 changed files with 243 additions and 271 deletions

View File

@ -16,7 +16,7 @@
// need to install these due to external projects that link directly with libpandadx (bartop) // need to install these due to external projects that link directly with libpandadx (bartop)
#define INSTALL_HEADERS \ #define INSTALL_HEADERS \
config_dxgsg.h dxGraphicsStateGuardian.I dxGraphicsStateGuardian.h \ config_dxgsg.h dxGraphicsStateGuardian.I dxGraphicsStateGuardian.h \
dxTextureContext.h dxGeomNodeContext.h dxGeomNodeContext.I dxTextureContext.h dxGeomNodeContext.h dxGeomNodeContext.I dxgsgbase.h
// build dxGraphicsStateGuardian separately since its so big // build dxGraphicsStateGuardian separately since its so big

View File

@ -19,25 +19,13 @@
#ifndef DXGEOMNODECONTEXT_H #ifndef DXGEOMNODECONTEXT_H
#define DXGEOMNODECONTEXT_H #define DXGEOMNODECONTEXT_H
#include <pandabase.h> #include "dxgsgbase.h"
#ifdef WIN32_VC
// Must include windows.h before dx.h on NT
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#endif
#include <geomNodeContext.h> #include <geomNodeContext.h>
#include <geomNode.h> #include <geomNode.h>
#include "pvector.h" #include "pvector.h"
#define D3D_OVERLOADS // get D3DVECTOR '+' operator, etc from d3dtypes.h
#include <d3d.h>
#if DIRECT3D_VERSION != 0x0700
#error DX7 headers not available, you need to install MS Platform SDK!
#endif
typedef struct { typedef struct {
DWORD nVerts; DWORD nVerts;

View File

@ -16,7 +16,9 @@
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
#include <pandabase.h> #include "dxGraphicsStateGuardian.h"
#include "config_dxgsg.h"
#include <directRenderTraverser.h> #include <directRenderTraverser.h>
#include <cullTraverser.h> #include <cullTraverser.h>
#include <displayRegion.h> #include <displayRegion.h>
@ -54,20 +56,13 @@
#include <depthWriteTransition.h> #include <depthWriteTransition.h>
#include <cullFaceTransition.h> #include <cullFaceTransition.h>
#include <stencilTransition.h> #include <stencilTransition.h>
#include <mmsystem.h>
#ifdef DO_PSTATS #ifdef DO_PSTATS
#include <pStatTimer.h> #include <pStatTimer.h>
#include <pStatCollector.h> #include <pStatCollector.h>
#endif #endif
#include "config_dxgsg.h"
#include "dxGraphicsStateGuardian.h"
// disable nameless struct 'warning'
#pragma warning (disable : 4201)
#include <mmsystem.h>
// print out simple drawprim stats every few secs // print out simple drawprim stats every few secs
//#define COUNT_DRAWPRIMS //#define COUNT_DRAWPRIMS

View File

@ -19,9 +19,7 @@
#ifndef DXGRAPHICSSTATEGUARDIAN_H #ifndef DXGRAPHICSSTATEGUARDIAN_H
#define DXGRAPHICSSTATEGUARDIAN_H #define DXGRAPHICSSTATEGUARDIAN_H
//#define GSG_VERBOSE #include "dxgsgbase.h"
#include <pandabase.h>
#include <graphicsStateGuardian.h> #include <graphicsStateGuardian.h>
#include <geomprimitives.h> #include <geomprimitives.h>
#include <texture.h> #include <texture.h>
@ -37,95 +35,13 @@
#include <alphaTransformTransition.h> #include <alphaTransformTransition.h>
#include <pointerToArray.h> #include <pointerToArray.h>
#include <planeNode.h> #include <planeNode.h>
#include "dxGeomNodeContext.h" #include "dxGeomNodeContext.h"
#include "dxTextureContext.h" #include "dxTextureContext.h"
#include <vector> #include <vector>
extern char * ConvD3DErrorToString(const HRESULT &error); // defined in wdxGraphicsPipe.cxx
typedef struct {
LPDIRECT3DDEVICE7 pD3DDevice;
LPDIRECTDRAW7 pDD;
LPDIRECT3D7 pD3D;
LPDIRECTDRAWSURFACE7 pddsPrimary,pddsBack,pddsZBuf;
HWND hWnd;
HMONITOR hMon;
DWORD dwRenderWidth,dwRenderHeight,dwFullScreenBitDepth;
RECT view_rect,clip_rect;
DWORD MaxAvailVidMem;
bool bIsLowVidMemCard;
bool bIsTNLDevice;
bool bIsSWRast;
ushort depth_buffer_bitdepth; //GetSurfaceDesc is not reliable so must store this explicitly
ushort CardIDNum; // its posn in DisplayArray, for dbgprint purposes
DDDEVICEIDENTIFIER2 DXDeviceID;
D3DDEVICEDESC7 D3DDevDesc;
#ifdef USE_TEXFMTVEC
DDPixelFormatVec TexPixFmts;
#endif
} DXScreenData;
// typedef vector<DXScreenData> ScreenDataVector;
class PlaneNode; class PlaneNode;
class Light; class Light;
#ifdef GSG_VERBOSE
ostream &output_gl_enum(ostream &out, GLenum v);
INLINE ostream &operator << (ostream &out, GLenum v) {
return output_gl_enum(out, v);
}
#endif
#ifdef DO_PSTATS
#define DO_PSTATS_STUFF(XX) XX;
#else
#define DO_PSTATS_STUFF(XX)
#endif
#define DX_DECLARE_CLEAN(type, var) \
type var; \
ZeroMemory(&var, sizeof(type)); \
var.dwSize = sizeof(type);
// #define DEBUG_RELEASES
// this is bDoDownToZero argument to RELEASE()
#define RELEASE_DOWN_TO_ZERO true
#ifdef DEBUG_RELEASES
#define RELEASE(OBJECT,MODULE,DBGSTR,bDoDownToZero) \
if(((OBJECT)!=NULL)&&(!IsBadWritePtr((OBJECT),4))) { \
refcnt = (OBJECT)->Release(); \
MODULE##_cat.debug() << DBGSTR << " released, refcnt = " << refcnt << endl; \
if((bDoDownToZero) && (refcnt>0)) { \
MODULE##_cat.warning() << DBGSTR << " released but still has a non-zero refcnt(" << refcnt << "), multi-releasing it down to zero!\n"; \
do { \
refcnt = (OBJECT)->Release(); \
} while(refcnt>0); \
} \
(OBJECT) = NULL; \
} else { \
MODULE##_cat.debug() << DBGSTR << " not released, ptr == NULL" << endl; \
}
#define PRINTREFCNT(OBJECT,STR) { (OBJECT)->AddRef(); dxgsg_cat.debug() << STR << " refcnt = " << (OBJECT)->Release() << endl; }
#else
#define RELEASE(OBJECT,MODULE,DBGSTR,bDoDownToZero) \
if(((OBJECT)!=NULL)&&(!IsBadWritePtr((OBJECT),4))) { \
refcnt=(OBJECT)->Release(); \
if((bDoDownToZero) && (refcnt>0)) { \
MODULE##_cat.warning() << DBGSTR << " released but still has a non-zero refcnt(" << refcnt << "), multi-releasing it down to zero!\n"; \
do { \
refcnt = (OBJECT)->Release(); \
} while(refcnt>0); \
} \
(OBJECT) = NULL; \
}
#define PRINTREFCNT(OBJECT,STR)
#endif
//#if defined(NOTIFY_DEBUG) || defined(DO_PSTATS) //#if defined(NOTIFY_DEBUG) || defined(DO_PSTATS)
#ifdef _DEBUG #ifdef _DEBUG
// This function now serves both to print a debug message to the // This function now serves both to print a debug message to the
@ -507,8 +423,6 @@ private:
static TypeHandle _type_handle; static TypeHandle _type_handle;
}; };
#define ISPOW2(X) (((X) & ((X)-1))==0)
#include "dxGraphicsStateGuardian.I" #include "dxGraphicsStateGuardian.I"
#endif #endif

View File

@ -19,33 +19,11 @@
#ifndef DXTEXTURECONTEXT_H #ifndef DXTEXTURECONTEXT_H
#define DXTEXTURECONTEXT_H #define DXTEXTURECONTEXT_H
#include <pandabase.h> #include "dxgsgbase.h"
#define WIN32_LEAN_AND_MEAN
#ifndef STRICT
// enable strict type checking in windows.h, see msdn
#define STRICT
#endif
#include <windows.h>
#include <ddraw.h>
#define D3D_OVERLOADS // get D3DVECTOR '+' operator, etc from d3dtypes.h
#include <d3d.h>
#undef WIN32_LEAN_AND_MEAN
#include <texture.h> #include <texture.h>
#include <textureContext.h> #include <textureContext.h>
//#define USE_TEXFMTVEC // doesnt work now, crashes in destructor
#ifdef USE_TEXFMTVEC
typedef pvector<DDPIXELFORMAT> DDPixelFormatVec;
#else
#define MAX_DX_TEXPIXFMTS 20 // should be enough for any card
#endif
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Class : DXTextureContext // Class : DXTextureContext
// Description : // Description :

136
panda/src/dxgsg/dxgsgbase.h Normal file
View File

@ -0,0 +1,136 @@
// Filename: dxTextureContext.h
// Created by: drose (07Oct99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#ifndef DXGSGBASE_H
#define DXGSGBASE_H
#include <pandabase.h>
// include win32 defns for everything up to XP, and assume I'm smart enough to
// use GetProcAddress for backward compat on w95/w98 for newer fns
#define _WIN32_WINNT 0x0501
#define WIN32_LEAN_AND_MEAN // get rid of mfc win32 hdr stuff
#ifndef STRICT
// enable strict type checking in windows.h, see msdn
#define STRICT
#endif
#include <windows.h>
#include <ddraw.h>
#define D3D_OVERLOADS // get D3DVECTOR '+' operator, etc from d3dtypes.h
#include <d3d.h>
#undef WIN32_LEAN_AND_MEAN
#if DIRECT3D_VERSION != 0x0700
#error DX7 headers not available, you need to install MS Platform SDK or DirectX 8+ SDK!
#endif
// disable nameless struct 'warning'
#pragma warning (disable : 4201)
//#define USE_TEXFMTVEC
// USE_TEXFMTVEC caused crash on dealloc
#ifdef USE_TEXFMTVEC
typedef pvector<DDPIXELFORMAT> DDPixelFormatVec;
#else
#define MAX_DX_TEXPIXFMTS 20 // should be enough for any card
#endif
#define ISPOW2(X) (((X) & ((X)-1))==0)
#define DX_DECLARE_CLEAN(type, var) \
type var; \
ZeroMemory(&var, sizeof(type)); \
var.dwSize = sizeof(type);
#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
#define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p); (p)=NULL; } }
// this is bDoDownToZero argument to RELEASE()
#define RELEASE_DOWN_TO_ZERO true
#define RELEASE_ONCE false
// #define DEBUG_RELEASES
#ifdef DEBUG_RELEASES
#define RELEASE(OBJECT,MODULE,DBGSTR,bDoDownToZero) \
if(((OBJECT)!=NULL)&&(!IsBadWritePtr((OBJECT),4))) { \
refcnt = (OBJECT)->Release(); \
MODULE##_cat.debug() << DBGSTR << " released, refcnt = " << refcnt << endl; \
if((bDoDownToZero) && (refcnt>0)) { \
MODULE##_cat.warning() << DBGSTR << " released but still has a non-zero refcnt(" << refcnt << "), multi-releasing it down to zero!\n"; \
do { \
refcnt = (OBJECT)->Release(); \
} while(refcnt>0); \
} \
(OBJECT) = NULL; \
} else { \
MODULE##_cat.debug() << DBGSTR << " not released, ptr == NULL" << endl; \
}
#define PRINTREFCNT(OBJECT,STR) { (OBJECT)->AddRef(); dxgsg_cat.debug() << STR << " refcnt = " << (OBJECT)->Release() << endl; }
#else
#define RELEASE(OBJECT,MODULE,DBGSTR,bDoDownToZero) \
if(((OBJECT)!=NULL)&&(!IsBadWritePtr((OBJECT),4))) { \
refcnt=(OBJECT)->Release(); \
if((bDoDownToZero) && (refcnt>0)) { \
MODULE##_cat.warning() << DBGSTR << " released but still has a non-zero refcnt(" << refcnt << "), multi-releasing it down to zero!\n"; \
do { \
refcnt = (OBJECT)->Release(); \
} while(refcnt>0); \
} \
(OBJECT) = NULL; \
}
#define PRINTREFCNT(OBJECT,STR)
#endif
#ifdef DO_PSTATS
#define DO_PSTATS_STUFF(XX) XX;
#else
#define DO_PSTATS_STUFF(XX)
#endif
extern char * ConvD3DErrorToString(const HRESULT &error); // defined in wdxGraphicsPipe.cxx
typedef struct {
LPDIRECT3DDEVICE7 pD3DDevice;
LPDIRECTDRAW7 pDD;
LPDIRECT3D7 pD3D;
LPDIRECTDRAWSURFACE7 pddsPrimary,pddsBack,pddsZBuf;
HWND hWnd;
HMONITOR hMon;
DWORD dwRenderWidth,dwRenderHeight,dwFullScreenBitDepth;
RECT view_rect,clip_rect;
DWORD MaxAvailVidMem;
bool bIsLowVidMemCard;
bool bIsTNLDevice;
bool bIsSWRast;
WORD depth_buffer_bitdepth; //GetSurfaceDesc is not reliable so must store this explicitly
WORD CardIDNum; // its posn in DisplayArray, for dbgprint purposes
DDDEVICEIDENTIFIER2 DXDeviceID;
D3DDEVICEDESC7 D3DDevDesc;
#ifdef USE_TEXFMTVEC
DDPixelFormatVec TexPixFmts;
#endif
} DXScreenData;
#endif

View File

@ -21,24 +21,10 @@
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Includes // Includes
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
#include <pandabase.h>
#include <string> #include <string>
#include <interactiveGraphicsPipe.h>
#include "wdxGraphicsWindow.h" #include "wdxGraphicsWindow.h"
#include <interactiveGraphicsPipe.h>
#ifndef STRICT
#define STRICT
#endif
#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
#undef WINDOWS_LEAN_AND_MEAN
////////////////////////////////////////////////////////////////////
// Defines
////////////////////////////////////////////////////////////////////
extern char * ConvD3DErrorToString(const HRESULT &error);
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Class : wdxGraphicsPipe // Class : wdxGraphicsPipe

View File

@ -26,17 +26,12 @@
#include <keyboardButton.h> #include <keyboardButton.h>
#include <mouseButton.h> #include <mouseButton.h>
#include <throw_event.h> #include <throw_event.h>
#ifdef DO_PSTATS #ifdef DO_PSTATS
#include <pStatTimer.h> #include <pStatTimer.h>
#endif #endif
#define D3D_OVERLOADS
//#define INITGUID dont want this if linking w/dxguid.lib
#include <d3d.h>
#include <map> #include <map>
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -58,8 +53,6 @@ wdxGraphicsWindow* global_wdxwinptr = NULL; // need this for temporary windproc
extern bool dx_full_screen_antialiasing; // defined in dxgsg_config.cxx extern bool dx_full_screen_antialiasing; // defined in dxgsg_config.cxx
#define MOUSE_ENTERED 0
#define MOUSE_EXITED 1
#define PAUSED_TIMER_ID 7 // completely arbitrary choice #define PAUSED_TIMER_ID 7 // completely arbitrary choice
#define DXREADY ((_dxgsg!=NULL)&&(_dxgsg->GetDXReady())) #define DXREADY ((_dxgsg!=NULL)&&(_dxgsg->GetDXReady()))
@ -300,6 +293,23 @@ LONG WINAPI static_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam
} }
} }
// Note: could use _TrackMouseEvent in comctrl32.dll (part of IE 3.0+) which emulates
// TrackMouseEvent on w95, but that requires another 500K of memory to hold that DLL,
// which is lame just to support w95, which probably has other issues anyway
INLINE void wdxGraphicsWindow::
track_mouse_leaving(HWND hwnd) {
if(_pParentWindowGroup->_pfnTrackMouseEvent==NULL)
return;
TRACKMOUSEEVENT tme = {sizeof(TRACKMOUSEEVENT),TME_LEAVE,hwnd,0};
BOOL bSucceeded = _pParentWindowGroup->_pfnTrackMouseEvent(&tme); // tell win32 to post WM_MOUSELEAVE msgs
if((!bSucceeded) && wdxdisplay_cat.is_debug())
wdxdisplay_cat.debug() << "TrackMouseEvent failed!, LastError=" << GetLastError() << endl;
_tracking_mouse_leaving=true;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: window_proc // Function: window_proc
// Access: // Access:
@ -314,7 +324,6 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
case WM_PAINT: { case WM_PAINT: {
PAINTSTRUCT ps; PAINTSTRUCT ps;
BeginPaint(hwnd, &ps); BeginPaint(hwnd, &ps);
if(DXREADY) if(DXREADY)
show_frame(); show_frame();
EndPaint(hwnd, &ps); EndPaint(hwnd, &ps);
@ -332,19 +341,56 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
if(iVal & 0x8000) \ if(iVal & 0x8000) \
iVal -= 0x10000; \ iVal -= 0x10000; \
} }
if(!_tracking_mouse_leaving) {
// need to re-call TrackMouseEvent every time mouse re-enters window
track_mouse_leaving(hwnd);
}
SET_MOUSE_COORD(x,LOWORD(lparam)); SET_MOUSE_COORD(x,LOWORD(lparam));
SET_MOUSE_COORD(y,HIWORD(lparam)); SET_MOUSE_COORD(y,HIWORD(lparam));
if(mouse_motion_enabled() if(wparam & (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON)) {
&& wparam & (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON)) {
handle_mouse_motion(x, y); handle_mouse_motion(x, y);
} else if(mouse_passive_motion_enabled() && }
((wparam & (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON)) == 0)) {
handle_mouse_motion(x, y);
}
return 0; return 0;
// if cursor is invisible, make it visible when moving in the window bars,etc
case WM_NCMOUSEMOVE: {
if(!_props._bCursorIsVisible) {
if(!_cursor_in_windowclientarea) {
ShowCursor(true);
_cursor_in_windowclientarea=true;
}
}
break;
}
case WM_NCMOUSELEAVE: {
if(!_props._bCursorIsVisible) {
ShowCursor(false);
_cursor_in_windowclientarea=false;
}
break;
}
case WM_MOUSELEAVE: {
// wdxdisplay_cat.fatal() << "XXXXX WM_MOUSELEAVE received\n";
_tracking_mouse_leaving=false;
handle_mouse_entry(false,0,0);
break;
}
case WM_CREATE: {
track_mouse_leaving(hwnd);
_cursor_in_windowclientarea=false;
if(!_props._bCursorIsVisible)
ShowCursor(false);
break;
}
case WM_IME_NOTIFY: case WM_IME_NOTIFY:
if (wparam == IMN_SETOPENSTATUS) { if (wparam == IMN_SETOPENSTATUS) {
HIMC hIMC = ImmGetContext(hwnd); HIMC hIMC = ImmGetContext(hwnd);
@ -356,7 +402,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
ImmReleaseContext(hwnd, hIMC); ImmReleaseContext(hwnd, hIMC);
} }
break; break;
case WM_IME_STARTCOMPOSITION: case WM_IME_STARTCOMPOSITION:
// In case we're running fullscreen mode, we have to turn on // In case we're running fullscreen mode, we have to turn on
// explicit DX support for overlay windows now, so we'll be able // explicit DX support for overlay windows now, so we'll be able
@ -560,14 +606,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
_WindowAdjustingType = MovingOrResizing; _WindowAdjustingType = MovingOrResizing;
} }
break; break;
/*
case WM_SETCURSOR: {
if(!_props._bCursorIsVisible)
return true; // avoid defaultwindproc showing the cursor
break;
// return false;
}
*/
case WM_DISPLAYCHANGE: { case WM_DISPLAYCHANGE: {
#ifdef _DEBUG #ifdef _DEBUG
width = LOWORD(lparam); height = HIWORD(lparam); width = LOWORD(lparam); height = HIWORD(lparam);
@ -626,7 +665,6 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
} }
case WM_SETFOCUS: { case WM_SETFOCUS: {
// wdxdisplay_cat.info() << "got WM_SETFOCUS\n";
if(!DXREADY) { if(!DXREADY) {
break; break;
} }
@ -635,9 +673,6 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
GetCursorPos(&point); GetCursorPos(&point);
ScreenToClient(hwnd, &point); ScreenToClient(hwnd, &point);
if(_mouse_entry_enabled)
handle_mouse_entry(MOUSE_ENTERED,point.x,point.y);
// this is a hack to make sure common modifier keys have proper state // this is a hack to make sure common modifier keys have proper state
// since at focus loss, app may never receive key-up event corresponding to // since at focus loss, app may never receive key-up event corresponding to
// a key-down. it would be better to know the exact set of ModifierButtons the // a key-down. it would be better to know the exact set of ModifierButtons the
@ -652,14 +687,10 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
} }
case WM_KILLFOCUS: { case WM_KILLFOCUS: {
// wdxdisplay_cat.info() << "got WM_KILLFOCUS\n";
if(!DXREADY) { if(!DXREADY) {
break; break;
} }
if(_mouse_entry_enabled)
handle_mouse_entry(MOUSE_EXITED,0,0);
int i; int i;
for(i=0;i<NUM_MODIFIER_KEYS;i++) { for(i=0;i<NUM_MODIFIER_KEYS;i++) {
if(GetKeyState(hardcoded_modifier_buttons[i]) < 0) if(GetKeyState(hardcoded_modifier_buttons[i]) < 0)
@ -736,11 +767,6 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
} }
return 0; return 0;
case WM_CREATE: {
if(!_props._bCursorIsVisible)
ShowCursor(false);
break;
}
case WM_ACTIVATEAPP: { case WM_ACTIVATEAPP: {
#ifdef _DEBUG #ifdef _DEBUG
@ -1017,6 +1043,19 @@ void wdxGraphicsWindowGroup::CreateWindows(void) {
static bool wc_registered = false; static bool wc_registered = false;
_hParentWindow = NULL; _hParentWindow = NULL;
// these fns arent defined on win95, so get dynamic ptrs to them to avoid
// ugly DLL loader failures on w95
HINSTANCE hUser32 = (HINSTANCE) LoadLibrary("user32.dll");
assert(hUser32);
_pfnGetMonitorInfo = (PFN_GETMONITORINFO) GetProcAddress(hUser32, "GetMonitorInfoA");
// Note: could use _TrackMouseEvent in comctrl32.dll (part of IE 3.0+) which emulates
// TrackMouseEvent on w95, but that requires another 500K of memory to hold that DLL,
// which is lame just to support w95, which probably has other issues anyway
_pfnTrackMouseEvent = (PFN_TRACKMOUSEEVENT) GetProcAddress(hUser32, "TrackMouseEvent");
FreeLibrary(hUser32);
// Clear before filling in window structure! // Clear before filling in window structure!
ZeroMemory(&wc, sizeof(WNDCLASS)); ZeroMemory(&wc, sizeof(WNDCLASS));
wc.style = CS_HREDRAW | CS_VREDRAW; //CS_OWNDC; wc.style = CS_HREDRAW | CS_VREDRAW; //CS_OWNDC;
@ -1132,22 +1171,15 @@ void wdxGraphicsWindowGroup::CreateWindows(void) {
// rect now contains the coords for the entire window, not the client // rect now contains the coords for the entire window, not the client
if(dx_full_screen) { if(dx_full_screen) {
// get upper-left corner coords using GetMonitorInfo
// GetMonInfo doesnt exist on w95, so dont statically link to it
HINSTANCE hUser32 = (HINSTANCE) LoadLibrary("user32.dll");
assert(hUser32);
typedef BOOL (WINAPI* LPGETMONITORINFO)(HMONITOR, LPMONITORINFO);
LPGETMONITORINFO pfnGetMonitorInfo = (LPGETMONITORINFO) GetProcAddress(hUser32, "GetMonitorInfoA");
// extra windows must be parented to the first so app doesnt minimize when user selects them // extra windows must be parented to the first so app doesnt minimize when user selects them
for(DWORD devnum=0;devnum<_windows.size();devnum++) { for(DWORD devnum=0;devnum<_windows.size();devnum++) {
MONITORINFO minfo; MONITORINFO minfo;
ZeroMemory(&minfo, sizeof(MONITORINFO)); ZeroMemory(&minfo, sizeof(MONITORINFO));
minfo.cbSize = sizeof(MONITORINFO); minfo.cbSize = sizeof(MONITORINFO);
if(pfnGetMonitorInfo) if(_pfnGetMonitorInfo!=NULL)
(*pfnGetMonitorInfo)(_windows[devnum]->_dxgsg->scrn.hMon, &minfo); // get upper-left corner coords using GetMonitorInfo
(*_pfnGetMonitorInfo)(_windows[devnum]->_dxgsg->scrn.hMon, &minfo);
else { else {
minfo.rcMonitor.left = minfo.rcMonitor.top = 0; minfo.rcMonitor.left = minfo.rcMonitor.top = 0;
} }
@ -1172,7 +1204,6 @@ void wdxGraphicsWindowGroup::CreateWindows(void) {
_hParentWindow=hWin; _hParentWindow=hWin;
} }
} }
FreeLibrary(hUser32);
} else { } else {
assert(_windows.size()==1); assert(_windows.size()==1);
@ -1277,18 +1308,6 @@ void wdxGraphicsWindow::config_window(wdxGraphicsWindowGroup *pParentGroup) {
} }
void wdxGraphicsWindow::finish_window_setup(void) { void wdxGraphicsWindow::finish_window_setup(void) {
// init panda input handling
_mouse_input_enabled = false;
_mouse_motion_enabled = false;
_mouse_passive_motion_enabled = false;
_mouse_entry_enabled = false;
// Enable detection of mouse input
enable_mouse_input(true);
enable_mouse_motion(true);
enable_mouse_passive_motion(true);
// enable_mouse_entry(true); re-enable this??
// Now indicate that we have our keyboard/mouse device ready. // Now indicate that we have our keyboard/mouse device ready.
GraphicsWindowInputDevice device = GraphicsWindowInputDevice::pointer_and_keyboard("keyboard/mouse"); GraphicsWindowInputDevice device = GraphicsWindowInputDevice::pointer_and_keyboard("keyboard/mouse");
_input_devices.push_back(device); _input_devices.push_back(device);
@ -2447,8 +2466,6 @@ void wdxGraphicsWindow::show_frame(void) {
_dxgsg->show_frame(); _dxgsg->show_frame();
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: end_frame // Function: end_frame
// Access: // Access:
@ -2484,15 +2501,13 @@ void wdxGraphicsWindow::handle_mouse_motion(int x, int y) {
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// BUGBUG: this needs to be called when mouse enters. right now it's just called when keybd focus changes void wdxGraphicsWindow::handle_mouse_entry(bool bEntering, int x, int y) {
void wdxGraphicsWindow::handle_mouse_entry(int state, int x, int y) { // usually 'motion' event is equivalent to entering, so
// ShowCursor(_props._bCursorIsVisible); // this will never be called w/bEntering true
if(bEntering) {
if(state == MOUSE_EXITED) {
_input_devices[0].set_pointer_out_of_window();
} else {
_input_devices[0].set_pointer_in_window(x, y); _input_devices[0].set_pointer_in_window(x, y);
// SetCursor(hCursor); believe this is not necessary, handled by windows } else {
_input_devices[0].set_pointer_out_of_window();
} }
} }
@ -2614,34 +2629,6 @@ void wdxGraphicsWindow::update(void) {
#endif #endif
} }
////////////////////////////////////////////////////////////////////
// Function: enable_mouse_input
// Access:
// Description:
////////////////////////////////////////////////////////////////////
void wdxGraphicsWindow::enable_mouse_input(bool val) {
_mouse_input_enabled = val;
}
////////////////////////////////////////////////////////////////////
// Function: enable_mouse_motion
// Access:
// Description:
////////////////////////////////////////////////////////////////////
void wdxGraphicsWindow::enable_mouse_motion(bool val) {
_mouse_motion_enabled = val;
}
////////////////////////////////////////////////////////////////////
// Function: enable_mouse_passive_motion
// Access:
// Description:
////////////////////////////////////////////////////////////////////
void wdxGraphicsWindow::enable_mouse_passive_motion(bool val) {
_mouse_passive_motion_enabled = val;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: wdxGraphicsWindow::get_gsg_type // Function: wdxGraphicsWindow::get_gsg_type
// Access: Public, Virtual // Access: Public, Virtual

View File

@ -22,14 +22,6 @@
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Includes // Includes
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
#include <pandabase.h>
#include <graphicsWindow.h>
#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
#undef WINDOWS_LEAN_AND_MEAN
#include <d3d.h>
#include "dxGraphicsStateGuardian.h" #include "dxGraphicsStateGuardian.h"
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -80,14 +72,11 @@ public:
LONG window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); LONG window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
void process_events(void); void process_events(void);
INLINE bool mouse_entry_enabled(void) { return _mouse_entry_enabled; } INLINE void handle_mouse_motion(int x, int y);
INLINE bool mouse_motion_enabled(void) { return _mouse_motion_enabled; } INLINE void handle_mouse_entry(bool bEntering, int x, int y);
INLINE bool mouse_passive_motion_enabled(void) { return _mouse_passive_motion_enabled; } INLINE void handle_keypress(ButtonHandle key, int x, int y );
void handle_window_move( int x, int y ); INLINE void handle_keyrelease(ButtonHandle key);
void handle_mouse_motion( int x, int y ); void handle_window_move(int x, int y);
void handle_mouse_entry( int state, int x, int y);
void handle_keypress( ButtonHandle key, int x, int y );
void handle_keyrelease( ButtonHandle key);
void dx_setup(); void dx_setup();
virtual void begin_frame( void ); virtual void begin_frame( void );
void show_frame(); void show_frame();
@ -105,27 +94,21 @@ protected:
bool search_for_device(int devnum,DXDeviceInfo *pDevinfo); bool search_for_device(int devnum,DXDeviceInfo *pDevinfo);
void setup_colormap(void); void setup_colormap(void);
void enable_mouse_input(bool val);
void enable_mouse_motion(bool val);
void enable_mouse_passive_motion(bool val);
void enable_mouse_entry(bool val);
public: public:
UINT_PTR _PandaPausedTimer; UINT_PTR _PandaPausedTimer;
DXGraphicsStateGuardian *_dxgsg; DXGraphicsStateGuardian *_dxgsg;
void CreateScreenBuffersAndDevice(DXScreenData &Display); void CreateScreenBuffersAndDevice(DXScreenData &Display);
private: private:
INLINE void track_mouse_leaving(HWND hwnd);
wdxGraphicsWindowGroup *_pParentWindowGroup; wdxGraphicsWindowGroup *_pParentWindowGroup;
HDC _hdc; HDC _hdc;
HPALETTE _colormap; HPALETTE _colormap;
typedef enum { NotAdjusting,MovingOrResizing,Resizing } WindowAdjustType; typedef enum { NotAdjusting,MovingOrResizing,Resizing } WindowAdjustType;
WindowAdjustType _WindowAdjustingType; WindowAdjustType _WindowAdjustingType;
bool _bSizeIsMaximized; bool _bSizeIsMaximized;
bool _mouse_input_enabled; bool _cursor_in_windowclientarea;
bool _mouse_motion_enabled; bool _tracking_mouse_leaving;
bool _mouse_passive_motion_enabled;
bool _mouse_entry_enabled;
bool _ime_open; bool _ime_open;
bool _ime_active; bool _ime_active;
bool _ime_composition_w; bool _ime_composition_w;
@ -183,10 +166,15 @@ public:
int _numMonitors; int _numMonitors;
LPDIRECTDRAWCREATEEX _pDDCreateEx; LPDIRECTDRAWCREATEEX _pDDCreateEx;
DXDeviceInfoVec _DeviceInfoVec; DXDeviceInfoVec _DeviceInfoVec;
// win32 fns that dont exist on w95
typedef BOOL (WINAPI* PFN_GETMONITORINFO)(HMONITOR, LPMONITORINFO);
PFN_GETMONITORINFO _pfnGetMonitorInfo;
typedef BOOL (WINAPI* PFN_TRACKMOUSEEVENT)(LPTRACKMOUSEEVENT);
PFN_TRACKMOUSEEVENT _pfnTrackMouseEvent;
}; };
extern void set_global_parameters(void); extern void set_global_parameters(void);
extern void restore_global_parameters(void); extern void restore_global_parameters(void);
#endif #endif