# Touch Support

Touch events are derived from generic events and are equally easy to implement.  
For an example of use have a look at the **ToggleButtonWidget** and it's base class **CgiEventWidget**.

<div class="contents" id="bkmrk-set-eventmask.-the-e"><div class="textblock">

- Set EventMask. The EventMask determines which event types will be sent. 
    
    ```
            const UInt cTbTouchEventExit = CgiEventWidget::TouchEventExit;
            const UInt cTbTouchEventUp = CgiEventWidget::TouchEventUp;
            const UInt cTbTouchEventDown = CgiEventWidget::TouchEventDown;
    
    
            Base::SetEventMask(cTbTouchEventExit | cTbTouchEventUp | cTbTouchEventDown);
    ```
- Override listener function. 
    
    ```
            protected:
    
                virtual void OnTouchEvent(TouchEvent touchEvent, <a class="code" href="http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_node.html" title="The class Node is an abstract base class for all scene graph nodes. Each Node defines a local coordin...">Candera::Node</a>* node, const CgiApplication::MouseEvent& event);
    
    ```
- Define your actions inside the listener function **OnTouchEvent**. 
    
    ```
            switch(touchEvent) {
                case TouchEventDown:
                    m_focus = true;
                    SetOn(!IsOn());
                    break;
                case TouchEventUp:
                    if (m_focus) {
                        SendUiEvent(TouchEventClick, 0);
                    }
                    break;
                case TouchEventExit:
                    m_focus = false;
                    m_down = !m_down;
                    SwitchTexture();
                    break;
                default:
                    break;
            }
    ```

</div></div>