Real-Time 스타일러스 샘플을 사용하는 Windows Touch Scratchpad(C#)
Windows Touch 스크래치패드 샘플(MTScratchpadRTStylus)은 Windows Touch 메시지를 사용하여 터치 지점의 추적을 창에 그리는 방법을 보여 줍니다. 디지타이저에 먼저 놓인 기본 손가락의 흔적이 검은색으로 그려집니다. 보조 손가락은 빨간색, 녹색, 파란색, 시안, 마젠타 및 노란색의 여섯 가지 다른 색상으로 그려집니다. 다음 스크린샷은 실행 중인 동안 애플리케이션이 어떻게 보일 수 있는지 보여줍니다.
이 샘플에서는 RTS(Real-Time Stylus) 개체가 만들어지고 여러 접점 지원이 사용하도록 설정됩니다. 콘텐츠를 렌더링하기 위해 DynamicRenderer 플러그 인이 RTS에 추가됩니다. 플러그 인 EventHandlerPlugIn은 손가락 수를 추적하고 동적 렌더러가 그리는 색을 변경하기 위해 구현됩니다. RTS 플러그 인 스택의 두 플러그 인을 모두 사용하는 Windows Touch Scratchpad 애플리케이션은 기본 접점이 검은색으로 렌더링되고 나머지 접점은 다양한 색으로 렌더링됩니다.
다음 코드에서는 EventHandlerPlugIn이 연락처 수를 증가 및 감소시키고 동적 렌더러의 색을 설정하는 방법을 보여 줍니다.
public void StylusDown(RealTimeStylus sender, StylusDownData data)
{
// Set new stroke color to the DrawingAttributes of the DynamicRenderer
// If there are no fingers down, this is a primary contact
dynamicRenderer.DrawingAttributes.Color = touchColor.GetColor(cntContacts == 0);
++cntContacts; // Increment finger-down counter
}
public void StylusUp(RealTimeStylus sender, StylusUpData data)
{
--cntContacts; // Decrement finger-down counter
}
다음 코드는 여러 접점 지원을 사용하여 RTS를 만드는 방법을 보여 줍니다.
private void OnLoadHandler(Object sender, EventArgs e)
{
// Create RealTimeStylus object and enable it for multi-touch
realTimeStylus = new RealTimeStylus(this);
realTimeStylus.MultiTouchEnabled = true;
// Create DynamicRenderer and event handler, and add them to the RTS object as synchronous plugins
dynamicRenderer = new DynamicRenderer(this);
eventHandler = new EventHandlerPlugIn(this.CreateGraphics(), dynamicRenderer);
realTimeStylus.SyncPluginCollection.Add(eventHandler);
realTimeStylus.SyncPluginCollection.Add(dynamicRenderer);
// Enable RTS and DynamicRenderer object, and enable auto-redraw of the DynamicRenderer
realTimeStylus.Enabled = true;
dynamicRenderer.Enabled = true;
dynamicRenderer.EnableDataCache = true;
}
DynamicRenderer 개체의 색이 변경되고 스트로크가 그려지면 DynamicRenderer::Refresh를 호출하면 새 스트로크가 표시됩니다. 다음 코드는 OnPaintHandler 메서드에서 이 작업을 수행하는 방법을 보여줍니다.
private void OnPaintHandler(object sender, PaintEventArgs e)
{
// Erase the background
Brush brush = new SolidBrush(SystemColors.Window);
e.Graphics.FillRectangle(brush, ClientRectangle);
// Ask DynamicRenderer to redraw itself
dynamicRenderer.Refresh();
}
관련 항목
멀티 터치 스크래치패드 애플리케이션(RTS/C#), 멀티 터치 스크래치패드 애플리케이션(RTS/C++), Windows Touch 샘플