00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "LampBasic.h"
00026 #include "Input/Mouse/MouseDevice.h"
00027
00028 namespace Lamp{
00029
00030
00031
00032 MouseDevice::MouseDevice() : InputDevice(false){
00033 zResolution_ = 120;
00034 }
00035
00036
00037 MouseDevice::~MouseDevice(){
00038 }
00039
00040
00041 bool MouseDevice::initialize(DirectInputDevice* inputDevice, HWND windowHandle){
00042 if(!InputDevice::initialize(inputDevice, windowHandle)){ return false; }
00043
00044 if(DirectXFailed(inputDevice->SetDataFormat(&c_dfDIMouse2))){
00045 ErrorOut("MouseDevice::initialize() "
00046 "マウスデバイスのデータフォーマット指定に失敗しました。");
00047 return false;
00048 }
00049
00050 if((getAxisCount() >= 3) && isAttached()){
00051 DIPROPDWORD property;
00052 property.diph.dwSize = sizeof(DIPROPDWORD);
00053 property.diph.dwHeaderSize = sizeof(DIPROPHEADER);
00054 property.diph.dwHow = DIPH_BYOFFSET;
00055 property.diph.dwObj = DIMOFS_Z;
00056 HRESULT result =
00057 inputDevice->GetProperty(DIPROP_GRANULARITY, &property.diph);
00058 if(DirectXFailed(result)){
00059 ErrorOut("MouseDevice::initialize() Z解像度の取得に失敗しました。");
00060 }else{
00061 zResolution_ = property.dwData;
00062 }
00063 }
00064
00065 if(!setCooperativeLevel(isExclusive(), isForeground())){ return false; }
00066 return true;
00067 }
00068
00069
00070 bool MouseDevice::polling(){
00071 InputDevice::polling();
00072
00073 DIMOUSESTATE2 state;
00074 HRESULT result = inputDevice_->GetDeviceState(
00075 sizeof(DIMOUSESTATE2), &state);
00076 if(DirectXSucceeded(result)){
00077 mouseState_.setXAxis(state.lX);
00078 mouseState_.setYAxis(state.lY);
00079 mouseState_.setZAxis(state.lZ);
00080 for(int i = 0; i < maxButtonCount; i++){
00081 mouseState_.setButtonPressed(i,
00082 ((state.rgbButtons[i] & 0x80) != 0));
00083 }
00084 return true;
00085 }else{
00086
00087 mouseState_.clear();
00088
00089 if((result != DIERR_INPUTLOST) && (result != DIERR_NOTACQUIRED)){
00090 ErrorOut("GetDeviceState()に失敗しました。");
00091 }else{
00092
00093 acquire();
00094 }
00095 }
00096 return false;
00097 }
00098
00099 }
00100