MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / MouseState

Class MouseState

src/main/java/field/graphics/Window.java:1059–1182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1057 this.x = x;
1058 this.y = y;
1059 this.dwheel = dwheel;
1060 this.dwheely = dwheely;
1061 this.dx = dx;
1062 this.dy = dy;
1063 this.time = time;
1064 this.buttonsDown.addAll(buttonsDown);
1065 this.mods = mods;
1066 }
1067
1068 static public Set<Integer> buttonsPressed(MouseState before, MouseState after) {
1069 Set<Integer> b = new LinkedHashSet<Integer>(after.buttonsDown);
1070 b.removeAll(before.buttonsDown);
1071 return b;
1072 }
1073
1074 static public Set<Integer> buttonsReleased(MouseState before, MouseState after) {
1075 Set<Integer> b = new LinkedHashSet<Integer>(before.buttonsDown);
1076 b.removeAll(after.buttonsDown);
1077 return b;
1078 }
1079
1080 public MouseState next(int button, float dwheel, int dx, int dy, double x, double y, boolean bs, long time, int mods) {
1081 Set<Integer> buttonsDown = new LinkedHashSet<Integer>(this.buttonsDown);
1082 if (bs && button != -1) buttonsDown.add(button);
1083 else if (!bs && button != -1) buttonsDown.remove(button);
1084
1085 return new MouseState(buttonsDown, x, y, dwheel, dwheely, dx, dy, time, mods);
1086 }
1087
1088 public MouseState withButton(int button, boolean bs, int mods) {
1089 Set<Integer> buttonsDown = new LinkedHashSet<Integer>(this.buttonsDown);
1090 if (bs && button != -1) buttonsDown.add(button);
1091 else if (!bs && button != -1) buttonsDown.remove(button);
1092 MouseState m = new MouseState(buttonsDown, x, y, dwheel, dwheely, 0, 0, time, mods);
1093 return m;
1094 }
1095
1096 public MouseState withMods(int mods) {
1097 return new MouseState(buttonsDown, x, y, dwheel, dwheely, x - this.x, y - this.y, time, mods);
1098 }
1099
1100 // currently we ignore sy
1101 public MouseState withScroll(double sx, double sy) {
1102 return new MouseState(buttonsDown, x, y, (float) sx, (float) sy, dx, dy, time, mods);
1103 }
1104
1105 public MouseState withPosition(double x, double y) {
1106 return new MouseState(buttonsDown, x, y, dwheel, dwheely, x - this.x, y - this.y, time, mods);
1107 }
1108
1109 @Override
1110 public boolean equals(Object o) {
1111 if (this == o) return true;
1112 if (!(o instanceof MouseState)) return false;
1113
1114 MouseState that = (MouseState) o;
1115
1116 if (dwheel != that.dwheel) return false;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected