Last active
June 5, 2017 00:25
-
-
Save Kaiochao/6b96b7e1f5ea522c85e7f19e287e2edd to your computer and use it in GitHub Desktop.
BYOND Mouse Position Tracking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Requires TileWidth and TileHeight to be defined. | |
e.g. with #define or global constants to match world.icon_size (default 32x32). | |
Clients have a mouse: client.mouse. | |
(mouse.X(), mouse.Y()) is the pixel coordinate of the mouse in the screen. | |
The bottom-left pixel of the screen is (1, 1). | |
"Screen" refers to the space where atoms on the map and HUD are drawn, not the computer screen. | |
(mouse.WorldX(), mouse.WorldY()) is the pixel coordinate of the mouse in the world. | |
The bottom-left pixel of the world is (1, 1). | |
*/ | |
mouse | |
var | |
screen_loc | |
reparse = FALSE | |
x | |
y | |
tmp | |
client/client | |
global | |
obj/mouse_catcher/MouseCatcher = new | |
regex/MouseRegex = regex("(\\d+):(\\d+),(\\d+):(\\d+)") | |
New(client/client) | |
src.client = client | |
client.screen += MouseCatcher | |
proc | |
Reparse() | |
if(MouseRegex.Find(screen_loc)) | |
var list/data = MouseRegex.group | |
x = text2num(data[2]) + (text2num(data[1]) - 1) * TileWidth | |
y = text2num(data[4]) + (text2num(data[3]) - 1) * TileHeight | |
reparse = FALSE | |
#define MOUSE_REPARSE reparse && Reparse() | |
X() | |
MOUSE_REPARSE | |
return x | |
Y() | |
MOUSE_REPARSE | |
return y | |
#undef MOUSE_REPARSE | |
WorldX() | |
return X() + client.bound_x - 1 | |
WorldY() | |
return Y() + client.bound_y - 1 | |
client | |
var | |
tmp | |
mouse/mouse | |
New() | |
. = ..() | |
mouse = new(src) | |
#define MOUSE_UPDATE if(mouse) { mouse.screen_loc = params2list(params)["screen-loc"]; mouse.reparse = TRUE; } | |
MouseEntered(object, location, control, params) | |
..() | |
MOUSE_UPDATE | |
MouseMove(object, location, control, params) | |
..() | |
MOUSE_UPDATE | |
MouseDrag(src_object, over_object, src_location, over_location, src_control, over_control, params) | |
..() | |
MOUSE_UPDATE | |
#undef MOUSE_UPDATE | |
obj/mouse_catcher | |
icon = null | |
screen_loc = "SOUTHWEST to NORTHEAST" | |
mouse_opacity = 2 | |
name = "" | |
plane = -100 | |
layer = BACKGROUND_LAYER |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment