1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
/*
* $Id: mouse.d,v 1.1 2005/09/11 00:47:41 kenta Exp $
*
* Copyright 2005 Kenta Cho. Some rights reserved.
*/
module util.mouse;
private import std.string;
private import SDL;
private import br.screen;
/**
* Mouse input.
*/
public class Mouse {
public:
//float accel = 1;
private:
Screen screen;
MouseState state;
public this() {
state = new MouseState;
}
public void init(Screen screen) {
this.screen = screen;
/*if (screen.windowMode) {
SDL_GetMouseState(&state.x, &state.y);
} else {
state.x = screen.width / 2;
state.y = screen.height / 2;
}*/
}
public void handleEvent(SDL_Event *event) {
}
public MouseState getState() {
int mx, my;
int btn = SDL_GetMouseState(&mx, &my);
state.x = mx;
state.y = my;
/*int mvx, mvy;
int btn = SDL_GetRelativeMouseState(&mvx, &mvy);
state.x = mvx * accel;
state.y = mvy * accel;
if (state.x < 0)
state.x = 0;
else if (state.x >= screen.width)
state.x = screen.width - 1;
if (state.y < 0)
state.y = 0;
else if (state.y >= screen.height)
state.x = screen.height - 1;*/
state.button = 0;
if (btn & SDL_BUTTON(1))
state.button |= MouseState.Button.LEFT;
if (btn & SDL_BUTTON(3))
state.button |= MouseState.Button.RIGHT;
adjustPos(state);
return state;
}
protected void adjustPos(MouseState ms) {}
public MouseState getNullState() {
state.clear();
return state;
}
}
public class MouseState {
public:
static enum Button {
LEFT = 1, RIGHT = 2,
};
float x, y;
int button;
private:
public static MouseState newInstance() {
return new MouseState;
}
public static MouseState newInstance(MouseState s) {
return new MouseState(s);
}
public this() {
}
public this(MouseState s) {
this();
set(s);
}
public void set(MouseState s) {
x = s.x;
y = s.y;
button = s.button;
}
public void clear() {
button = 0;
}
public bool equals(MouseState s) {
if (x == s.x && y == s.y && button == s.button)
return true;
else
return false;
}
}
|