public static List <Necrosofty.Input.TouchData> filter(List <Necrosofty.Input.TouchData> touches) { // if no existing touch, grab the first available if (output_touch_id == -1) { if (touches.Count > 0) { output_touch = touches[0]; output_touch.Status = TouchStatus.Down; output_touch_id = touches[0].ID; } } else // update the existing touch { bool found = false; for (int i = 0; i < touches.Count; ++i) { if (touches[i].ID == output_touch_id) { output_touch = touches[i]; found = true; } } // didn't find it in the list! let's release the current touch if (!found) { output_touch.Status = TouchStatus.Up; } } if (output_touch == null) { return(new List <Necrosofty.Input.TouchData>()); } // if touch released, clear the current touch id if (output_touch.Status == TouchStatus.Up) { output_touch_id = -1; } // build the new touch "list" List <Necrosofty.Input.TouchData> output_touches = new List <Necrosofty.Input.TouchData>(); if (output_touch_id != -1) { output_touches.Add(output_touch); } return(output_touches); }
public static void tick(List <Necrosofty.Input.TouchData> touches_in) { // flag to make sure we update all touches for (int i = 0; i < touches.Count; ++i) { Touch touch = touches[i]; touch.updated = false; touches[i] = touch; } int touch_count = touches_in.Count; // for touches coming in for (int i = 0; i < touch_count; ++i) { Necrosofty.Input.TouchData touch_in = touches_in[i]; bool handled = false; // if a touch with a matching id already exists, update it for (int j = 0; j < touches.Count; ++j) { Touch touch = touches[j]; if (touch_in.ID == touch.id) { handled = true; touch.last_position = touch.position; touch.position = new Vector2(AppMain.vscreen.x - (touch_in.X + 0.5f) * AppMain.vscreen.x, (touch_in.Y + 0.5f) * 544); touch.updated = true; touch.status = Touch.Status.MOVE; } touches[j] = touch; } // if not, add it if (!handled) { Touch new_touch = new Touch(); new_touch.id = touch_in.ID; new_touch.position = new Vector2(AppMain.vscreen.x - (touch_in.X + 0.5f) * AppMain.vscreen.x, (touch_in.Y + 0.5f) * 544); new_touch.last_position = new_touch.position; new_touch.initial_position = new_touch.position; new_touch.really_initial_position = new_touch.position; new_touch.updated = true; new_touch.status = Touch.Status.DOWN; touches.Add(new_touch); } } // find unhandled touches and process them for (int i = 0; i < touches.Count; ++i) { Touch touch = touches[i]; if (touch.updated) { continue; } if (touch.status != Touch.Status.UP) { touch.status = Touch.Status.UP; touches[i] = touch; continue; } touches.RemoveAt(i); i--; } }