Condividi tramite


Windows Touch Scratchpad usando l'esempio di stilo di Real-Time (C#)

L'esempio di Windows Touch Scratchpad (MTScratchpadRTStylus) mostra come usare i messaggi Touch di Windows per disegnare tracce dei punti di tocco a una finestra. La traccia del dito primario, quella che è stata messa per prima sul digitalizzatore, viene disegnata in nero. Le dita secondarie vengono disegnate in sei altri colori: rosso, verde, blu, ciano, magenta e giallo. La schermata seguente mostra come l'applicazione potrebbe essere visualizzata durante l'esecuzione.

schermata che mostra l'esempio di touchpad di Windows usando lo stilo in tempo reale in c sharp, con squiggles nero e rosso sullo schermo

Per questo esempio, viene creato l'oggetto stylus (RTS) Real-Time e viene abilitato il supporto per più punti di contatto. Un plug-in DynamicRenderer viene aggiunto a RTS per eseguire il rendering del contenuto. Un plug-in, EventHandlerPlugIn, viene implementato per tenere traccia del numero di dita e per modificare il colore che il renderer dinamico sta disegnando. Con entrambi i plug-in nello stack plug-in RTS, l'applicazione Windows Touch Scratchpad eseguirà il rendering del contatto principale in nero e il resto dei contatti nei vari colori.

Il codice seguente illustra in che modo EventHandlerPlugIn incrementa e decrementa un conteggio del numero di contatti e imposta il colore del renderer dinamico.

        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
        }

Il codice seguente illustra come viene creato rts con più supporto del punto di contatto.

        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;
        }

Dopo che il colore dell'oggetto DynamicRenderer è stato modificato e i tratti sono stati disegnati, una chiamata a DynamicRenderer::Refresh causerà la visualizzazione dei nuovi tratti. Il codice seguente illustra come viene eseguito nel metodo 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();
        }

Applicazione Scratchpad multi-tocco (RTS/C#),Applicazione Scratchpad multi-tocco (RTS/C++) , Esempi di tocco di Windows