I don't like that code snip.
jgc_userinput.h
/*============================================================================
| _________ _______ _______ ______ _______ Jegas, LLC |
| /___ ___// _____/ / _____/ / __ / / _____/ JasonPSage@jegas.com |
| / / / /__ / / ___ / /_/ / / /____ |
| / / / ____/ / / / / / __ / /____ / |
|____/ / / /___ / /__/ / / / / / _____/ / |
/_____/ /______/ /______/ /_/ /_/ /______/ |
| Under the Hood |
==============================================================================
Copyright(c)2007 Jegas, LLC
============================================================================*/
#pragma once
#include <DarkGDK.h>
#include "jgc_configuration.h"
#include "jgc_timer.h"
//============================================================================
class JGC_USERINPUT{
//============================================================================
public:
JGC_USERINPUT();
~JGC_USERINPUT();
void Update(int p_Timer);// Pass ZERO to bypass timerbased user input.
bool MouseEnabled;
JGC_TIMER *MouseTimer;
int MouseX;
int MouseY;
int MouseZ;
int MouseXOld;
int MouseYOld;
int MouseZOld;
int MouseMovedX;
int MouseMovedXOld;
int MouseMovedY;
int MouseMovedYOld;
int MouseMovedZ;
int MouseMovedZOld;
int MouseButtons; // Same as GDK dbMouseClick()
bool MouseButton1;
bool MouseButton1Old;
bool MouseButton2;
bool MouseButton2Old;
bool MouseButton3;
bool MouseButton3Old;
bool MouseButton4;
bool MouseButton4Old;
bool pvt_MouseVisible;
// Set to False Every Poll. To Avoid using
// using the same mouse polled data multiple times (think of the GUI)
// This flag can be used to invalidate the mouse input. Set to true
// when you have "Consumed" the values. This flag gets reset to TRUE
// when the Mouse is polled again.
bool MouseConsumed;
bool MouseVisible_Get(void);
void MouseVisible_Set(bool p_TrueOrFalse);
void pvt_ReadMouse(void);
//end of public
};
//============================================================================
jgc_userinput.cpp
/*============================================================================
| _________ _______ _______ ______ _______ Jegas, LLC |
| /___ ___// _____/ / _____/ / __ / / _____/ JasonPSage@jegas.com |
| / / / /__ / / ___ / /_/ / / /____ |
| / / / ____/ / / / / / __ / /____ / |
|____/ / / /___ / /__/ / / / / / _____/ / |
/_____/ /______/ /______/ /_/ /_/ /______/ |
| Under the Hood |
==============================================================================
Copyright(c)2007 Jegas, LLC
============================================================================*/
#include "jgc_userinput.h"
#include "jgc_common.h"
//============================================================================
// begin JFC_USERINPUT
//============================================================================
//----------------------------------------------------------------------------
JGC_USERINPUT::JGC_USERINPUT(){
//----------------------------------------------------------------------------
MouseEnabled=true;
MouseTimer=JGC::TimerArray->AppendItem_Timer();
MouseX=0;
MouseY=0;
MouseZ=0;
MouseXOld=0;
MouseYOld=0;
MouseZOld=0;
MouseMovedX=0;
MouseMovedXOld=0;
MouseMovedY=0;
MouseMovedYOld=0;
MouseMovedZ=0;
MouseMovedZOld=0;
MouseButton1=false;
MouseButton1Old=false;
MouseButton2=false;
MouseButton2Old=false;
MouseButton3=false;
MouseButton3Old=false;
MouseButton4=false;
MouseButton4Old=false;
pvt_MouseVisible=true;
MouseConsumed=false;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
JGC_USERINPUT::~JGC_USERINPUT(){
//----------------------------------------------------------------------------
delete MouseTimer;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Pass ZERO to bypass timerbased user input.
void JGC_USERINPUT::Update(int p_Timer){
//----------------------------------------------------------------------------
if(MouseEnabled){
if((p_Timer==0)||(MouseTimer->DelayPassed(p_Timer))){
this->pvt_ReadMouse();
};
};
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void JGC_USERINPUT::pvt_ReadMouse(void){
//----------------------------------------------------------------------------
MouseConsumed=false;
MouseXOld=MouseX;
MouseYOld=MouseY;
MouseZOld=MouseZ;
MouseX=dbMouseX();
MouseY=dbMouseY();
MouseZ=dbMouseZ();
MouseMovedXOld=MouseMovedX;
MouseMovedX=MouseX-MouseXOld;
MouseMovedYOld=MouseMovedY;
MouseMovedY=MouseY-MouseYOld;
MouseMovedZOld=MouseMovedZ;
MouseMovedZ=MouseZ-MouseZOld;
MouseButtons = dbMouseClick();
MouseButton1Old=MouseButton1;
MouseButton1=((MouseButtons & 1)==1);
MouseButton2Old=MouseButton2;
MouseButton2=((MouseButtons & 2)==2);
MouseButton3Old=MouseButton3;
MouseButton3=((MouseButtons & 4)==4);
MouseButton4Old=MouseButton4;
MouseButton4=((MouseButtons & 8)==8);
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
bool JGC_USERINPUT::MouseVisible_Get(void){
//----------------------------------------------------------------------------
return this->pvt_MouseVisible;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void JGC_USERINPUT::MouseVisible_Set(bool p_TrueOrFalse){
//----------------------------------------------------------------------------
this->pvt_MouseVisible=p_TrueOrFalse;
if(p_TrueOrFalse){
dbShowMouse();
}else{
dbHideMouse();
};
};
//----------------------------------------------------------------------------
//============================================================================
// end JFC_USERINPUT
//============================================================================
You can exclude the timer code and the configuration code. Just note that the mouse update routine I'm using here has the option to check the mouse ONLY if the correct time interval has passed. You don't necessarily need that... but I DO use this to POLL the MOUSE ONCE in my loop lets say, THEN I NEVER ACCESS the mouse again... instead I access these values I "Stored" of the mouse, so I never get messed up resulted for reading mousemove functions twice or something.
Hope this is helpful...
NOTE how I calculated my own MouseMovedX, MouseMovedY, MouseMovedZ. For your ZWheel thing, you could just do:
if(UserInput->MouseMovedZ<0){
// do this
}else{
if(UserInput->MouseMovedZ>0){
// do that
};
};