| 1186 | } |
| 1187 | |
| 1188 | void Console::commandTouchSubCommandSwipe(socket_native_type fd, std::string_view args) |
| 1189 | { |
| 1190 | auto argv = Console::Utility::split(args, ' '); |
| 1191 | |
| 1192 | if ((argv.size() == 5) && (Console::Utility::isFloat(argv[1])) && (Console::Utility::isFloat(argv[2])) && |
| 1193 | (Console::Utility::isFloat(argv[3])) && (Console::Utility::isFloat(argv[4]))) |
| 1194 | { |
| 1195 | |
| 1196 | float x1 = (float)utils::atof(argv[1].c_str()); |
| 1197 | float y1 = (float)utils::atof(argv[2].c_str()); |
| 1198 | float x2 = (float)utils::atof(argv[3].c_str()); |
| 1199 | float y2 = (float)utils::atof(argv[4].c_str()); |
| 1200 | |
| 1201 | std::srand((unsigned)time(nullptr)); |
| 1202 | _touchId = rand(); |
| 1203 | |
| 1204 | Scheduler* sched = Director::getInstance()->getScheduler(); |
| 1205 | sched->runOnAxmolThread([x1, y1, this]() { |
| 1206 | float tempx = x1, tempy = y1; |
| 1207 | Director::getInstance()->getRenderView()->handleTouchesBegin(1, &_touchId, &tempx, &tempy); |
| 1208 | }); |
| 1209 | |
| 1210 | float dx = std::abs(x1 - x2); |
| 1211 | float dy = std::abs(y1 - y2); |
| 1212 | float _x_ = x1, _y_ = y1; |
| 1213 | if (dx > dy) |
| 1214 | { |
| 1215 | while (dx > 1) |
| 1216 | { |
| 1217 | |
| 1218 | if (x1 < x2) |
| 1219 | { |
| 1220 | _x_ += 1; |
| 1221 | } |
| 1222 | if (x1 > x2) |
| 1223 | { |
| 1224 | _x_ -= 1; |
| 1225 | } |
| 1226 | if (y1 < y2) |
| 1227 | { |
| 1228 | _y_ += dy / dx; |
| 1229 | } |
| 1230 | if (y1 > y2) |
| 1231 | { |
| 1232 | _y_ -= dy / dx; |
| 1233 | } |
| 1234 | sched->runOnAxmolThread([_x_, _y_, this]() { |
| 1235 | float tempx = _x_, tempy = _y_; |
| 1236 | Director::getInstance()->getRenderView()->handleTouchesMove(1, &_touchId, &tempx, &tempy); |
| 1237 | }); |
| 1238 | dx -= 1; |
| 1239 | } |
| 1240 | } |
| 1241 | else |
| 1242 | { |
| 1243 | while (dy > 1) |
| 1244 | { |
| 1245 | if (x1 < x2) |
nothing calls this directly
no test coverage detected