mirror of
https://github.com/glest/glest-source.git
synced 2025-08-26 09:24:24 +02:00
Updated camera panning so that holding middle mouse button and moving the mouse changes the camera angle.
This commit is contained in:
@@ -69,6 +69,9 @@ public:
|
||||
int64 getMillis() const;
|
||||
int64 getSeconds() const;
|
||||
|
||||
static int64 getCurTicks();
|
||||
static int64 getCurMillis();
|
||||
|
||||
private:
|
||||
int64 queryCounter(int multiplier) const;
|
||||
};
|
||||
|
@@ -1,4 +1,5 @@
|
||||
// ==============================================================
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
|
||||
@@ -15,24 +16,31 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <SDL.h>
|
||||
#include <cassert>
|
||||
|
||||
#include "types.h"
|
||||
#include "vec.h"
|
||||
|
||||
using std::map;
|
||||
using std::string;
|
||||
using Shared::Graphics::Vec2i;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
class Timer;
|
||||
class PlatformContextGl;
|
||||
|
||||
enum MouseButton{
|
||||
enum MouseButton {
|
||||
mbUnknown,
|
||||
mbLeft,
|
||||
mbRight,
|
||||
mbCenter,
|
||||
mbRight,
|
||||
mbWheelUp,
|
||||
mbWheelDown
|
||||
mbWheelDown,
|
||||
mbButtonX1,
|
||||
mbButtonX2,
|
||||
|
||||
mbCount
|
||||
};
|
||||
|
||||
enum SizeState{
|
||||
@@ -41,6 +49,31 @@ enum SizeState{
|
||||
ssRestored
|
||||
};
|
||||
|
||||
class MouseState {
|
||||
private:
|
||||
bool states[mbCount];
|
||||
|
||||
|
||||
public:
|
||||
MouseState() {
|
||||
clear();
|
||||
}
|
||||
//MouseState(const MouseState &);
|
||||
//MouseState &operator=(const MouseState &);
|
||||
void clear() { memset(this, 0, sizeof(MouseState)); }
|
||||
|
||||
bool get(MouseButton b) const {
|
||||
assert(b > 0 && b < mbCount);
|
||||
return states[b];
|
||||
}
|
||||
|
||||
void set(MouseButton b, bool state) {
|
||||
assert(b > 0 && b < mbCount);
|
||||
states[b] = state;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// keycode constants (unfortunately designed after DirectInput and therefore not
|
||||
// very specific)
|
||||
// They also have to fit into a char. The positive numbers seem to be equal
|
||||
@@ -59,11 +92,13 @@ const char vkDown = -10;
|
||||
const char vkReturn = -11;
|
||||
const char vkBack = -12;
|
||||
|
||||
/*
|
||||
struct MouseState{
|
||||
bool leftMouse;
|
||||
bool rightMouse;
|
||||
bool centerMouse;
|
||||
};
|
||||
*/
|
||||
|
||||
enum WindowStyle{
|
||||
wsFullscreen,
|
||||
@@ -81,6 +116,19 @@ private:
|
||||
int lastMouseX[3];
|
||||
int lastMouseY[3];
|
||||
|
||||
static unsigned int lastMouseEvent; /** for use in mouse hover calculations */
|
||||
static MouseState mouseState;
|
||||
static Vec2i mousePos;
|
||||
|
||||
static void setLastMouseEvent(unsigned int lastMouseEvent) {Window::lastMouseEvent = lastMouseEvent;}
|
||||
static unsigned int getLastMouseEvent() {return Window::lastMouseEvent;}
|
||||
|
||||
static const MouseState &getMouseState() {return Window::mouseState;}
|
||||
static void setMouseState(MouseButton b, bool state) {Window::mouseState.set(b, state);}
|
||||
|
||||
static const Vec2i &getMousePos() {return Window::mousePos;}
|
||||
static void setMousePos(const Vec2i &mousePos) {Window::mousePos = mousePos;}
|
||||
|
||||
protected:
|
||||
int w, h;
|
||||
|
||||
|
@@ -70,6 +70,9 @@ public:
|
||||
int64 getMillis() const;
|
||||
int64 getSeconds() const;
|
||||
|
||||
static int64 getCurTicks();
|
||||
static int64 getCurMillis();
|
||||
|
||||
private:
|
||||
int64 queryCounter(int multiplier) const;
|
||||
};
|
||||
|
@@ -115,6 +115,13 @@ int64 Chrono::queryCounter(int multiplier) const {
|
||||
}
|
||||
}
|
||||
|
||||
int64 Chrono::getCurMillis() {
|
||||
return SDL_GetTicks();
|
||||
}
|
||||
int64 Chrono::getCurTicks() {
|
||||
return SDL_GetTicks();
|
||||
}
|
||||
|
||||
// =====================================
|
||||
// Misc
|
||||
// =====================================
|
||||
|
@@ -32,14 +32,22 @@ namespace Shared{ namespace Platform{
|
||||
|
||||
// Matze: hack for now...
|
||||
static Window* global_window = 0;
|
||||
unsigned int Window::lastMouseEvent = 0; /** for use in mouse hover calculations */
|
||||
Vec2i Window::mousePos;
|
||||
MouseState Window::mouseState;
|
||||
|
||||
|
||||
// ========== PUBLIC ==========
|
||||
|
||||
Window::Window() {
|
||||
Window::Window() {
|
||||
memset(lastMouseDown, 0, sizeof(lastMouseDown));
|
||||
|
||||
assert(global_window == 0);
|
||||
global_window = this;
|
||||
|
||||
lastMouseEvent = 0;
|
||||
mousePos = Vec2i(0);
|
||||
mouseState.clear();
|
||||
}
|
||||
|
||||
Window::~Window() {
|
||||
@@ -53,33 +61,55 @@ bool Window::handleEvent() {
|
||||
try {
|
||||
//printf("START [%d]\n",event.type);
|
||||
|
||||
switch(event.type) {
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
case SDL_MOUSEMOTION:
|
||||
|
||||
printf("In [%s::%s] Line :%d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
setLastMouseEvent(Chrono::getCurMillis());
|
||||
setMousePos(Vec2i(event.button.x, event.button.y));
|
||||
break;
|
||||
}
|
||||
|
||||
switch(event.type) {
|
||||
case SDL_QUIT:
|
||||
printf("In [%s::%s] Line :%d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
return false;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
printf("In [%s::%s] Line :%d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
if(global_window) {
|
||||
global_window->handleMouseDown(event);
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEBUTTONUP: {
|
||||
printf("In [%s::%s] Line :%d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
if(global_window) {
|
||||
MouseButton b = getMouseButton(event.button.button);
|
||||
setMouseState(b, false);
|
||||
|
||||
global_window->eventMouseUp(event.button.x,
|
||||
event.button.y,getMouseButton(event.button.button));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEMOTION: {
|
||||
MouseState ms;
|
||||
ms.leftMouse = (event.motion.state & SDL_BUTTON_LMASK) != 0;
|
||||
ms.rightMouse = (event.motion.state & SDL_BUTTON_RMASK) != 0;
|
||||
ms.centerMouse = (event.motion.state & SDL_BUTTON_MMASK) != 0;
|
||||
printf("In [%s::%s] Line :%d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
//MouseState ms;
|
||||
//ms.leftMouse = (event.motion.state & SDL_BUTTON_LMASK) != 0;
|
||||
//ms.rightMouse = (event.motion.state & SDL_BUTTON_RMASK) != 0;
|
||||
//ms.centerMouse = (event.motion.state & SDL_BUTTON_MMASK) != 0;
|
||||
setMouseState(mbLeft, event.motion.state & SDL_BUTTON_LMASK);
|
||||
setMouseState(mbRight, event.motion.state & SDL_BUTTON_RMASK);
|
||||
setMouseState(mbCenter, event.motion.state & SDL_BUTTON_MMASK);
|
||||
|
||||
if(global_window) {
|
||||
global_window->eventMouseMove(event.motion.x, event.motion.y, &ms);
|
||||
global_window->eventMouseMove(event.motion.x, event.motion.y, &getMouseState()); //&ms);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDL_KEYDOWN:
|
||||
printf("In [%s::%s] Line :%d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
/* handle ALT+Return */
|
||||
if(event.key.keysym.sym == SDLK_RETURN
|
||||
&& (event.key.keysym.mod & (KMOD_LALT | KMOD_RALT))) {
|
||||
@@ -91,6 +121,7 @@ bool Window::handleEvent() {
|
||||
}
|
||||
break;
|
||||
case SDL_KEYUP:
|
||||
printf("In [%s::%s] Line :%d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
if(global_window) {
|
||||
global_window->eventKeyUp(getKey(event.key.keysym));
|
||||
}
|
||||
|
@@ -115,6 +115,15 @@ int64 Chrono::queryCounter(int multiplier) const{
|
||||
return multiplier*(accumCount+endCount-startCount)/freq;
|
||||
}
|
||||
}
|
||||
|
||||
int64 Chrono::getCurMillis() {
|
||||
return getCurTicks() * 1000 / freq;
|
||||
}
|
||||
int64 Chrono::getCurTicks() {
|
||||
int64 now;
|
||||
QueryPerformanceCounter((LARGE_INTEGER*) &now);
|
||||
return now;
|
||||
}
|
||||
|
||||
// =====================================================
|
||||
// class PlatformExceptionHandler
|
||||
|
Reference in New Issue
Block a user