private Point TabletToScreen(IPenData penData) { // Screen means LCD screen of the tablet. return (Point.Round(new PointF((float)penData.x * _capability.screenWidth / _capability.tabletMaxX, (float)penData.y * _capability.screenHeight / _capability.tabletMaxY))); }
private void OnPenData(IPenData penData) // Process incoming pen data { var pt = TabletToScreen(penData); var btn = 0; // will be +ve if the pen is over a button. { for (var i = 0; i < _buttons.Length; ++i) { if (_buttons[i].Bounds.Contains(pt)) { btn = i + 1; break; } } } var isDown = penData.sw != 0; // This code uses a model of four states the pen can be in: // down or up, and whether this is the first sample of that state. if (isDown) { if (_isDown == 0) { if (btn > 0) { _isDown = btn; } else { _isDown = -1; } } // The pen is down, store it for use later. if (_isDown == -1) { _penData.Add(penData); } } else { if (_isDown != 0) { // transition to up if (btn > 0) { if (btn == _isDown) { _buttons[btn - 1].PerformClick(); } } _isDown = 0; } // Add up data once we have collected some down data. if (_penData.Count != 0) { _penData.Add(penData); } } }