root / ofxTouchAPI / src / ofxTouchAPI_IO.h @ 14

View | Annotate | Download (7.1 KB)

1
/***********************************************************************
2
 
3
 Copyright (c) 2009 Dimitri Diakopoulos, http://www.dimitridiakopoulos.com/
4
 === Google Summer of Code 2009 - NUI Group === 
5
6
 Portions Copyright (c) 2008, 2009 Memo Atkens, http://www.memo.tv/
7
 -> Based on ofxMSAInteractiveObject
8
9
        Redistribution and use in source and binary forms, with or without modification, 
10
        are permitted provided that the following conditions are met:
11
12
        1. Redistributions of source code must retain the above copyright notice, 
13
        this list of conditions and the following disclaimer.
14
15
        2. Redistributions in binary form must reproduce the above copyright notice, 
16
        this list of conditions and the following disclaimer in the documentation and/or 
17
        other materials provided with the distribution.
18
19
        3. The name of the author may not be used to endorse or promote products derived 
20
        from this software without specific prior written permission.
21
22
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
23
        ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
24
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
25
        ARE DISCLAIMED. IN NOEVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 
26
        INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
27
        (INCLUDING, BUT NOT LIMITED TO,PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
28
        LOSS OF USE, DATA, ORPROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
29
        AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
31
        OF THE USE OF THIS SOFTWARE,EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
32
33
*************************************************************************/ 
34
35
#pragma once
36
37
#include "ofMain.h"
38
#include "ofxTouchAPI.h"
39
40
class ofxTouchAPI_IO : public ofRectangle {
41
42
public:
43
44
        bool                enabled;                // set to false to disable all events (temporarily) 
45
        bool                verbose;
46
        
47
        ofxTouchAPI_IO();                        // constructor
48
        virtual ~ofxTouchAPI_IO();        // destructor
49
        
50
        // ================================================================= Event Enable/Disable
51
        void enableAllEvents();                                // enable all event callbacks (default) 
52
        void disableAllEvents();                        // disable all event callbacks
53
        
54
        void enableMouseEvents();                        // call this if object should receive mouse events
55
        void disableMouseEvents();                        // call this if object doesn't need to receive mouse events
56
        
57
        void enableKeyEvents();                                // call this if object should receive key events
58
        void disableKeyEvents();                        // call this if object doesn't need to receive key events 
59
60
        void enableTouchEvents();                        // call this if object should recieve TUIO
61
        void disableTouchEvents();                        // call this if object doesn't need to receive TUIO
62
        
63
        void enableAppEvents();                                // call this if object should update/draw automatically        (default)
64
        void disableAppEvents();                        // call this if object doesn't need to update/draw automatically
65
66
67
        // ================================================================= Setters
68
        void setPos(float _x, float _y);                                                                // set position of object
69
        void setSize(float _w, float _h);                                                                // set size of object
70
        void setPosAndSize(float _x, float _y, float _w, float _h);                // set pos and size in one
71
72
73
        // ================================================================= Getters
74
        bool isMouseOver();                                        // returns true if mouse is over object (based on position and size)
75
        bool isMouseDown();                                        // returns true if mouse button is down and over object (based on position and size)
76
        int         getMouseX();                                        // returns mouse X (in screen coordinates)
77
        int  getMouseY();                                        // returns mouse Y (in screen coordinates)
78
        int  getLastMouseButton();                        // returns last mouse button to have activity
79
80
        int getTouches();                                        // returns number of touches (doesn't work currently); 
81
        bool isTouchActive(int ID);                        // asks if the current finger ID is touching the object
82
        bool isBeingTouched();                                // asks if any touch is currently down -- good for hover over state; 
83
84
85
86
        // ================================================================= Updater Methods
87
        virtual void setup()        {}        // called when app starts
88
        virtual void update()        {}        // called every frame to update object
89
    virtual void draw()                {}        // called every frame to draw object
90
        virtual void exit()                {}        // called when app quits
91
        void killMe();                                // if your object is a pointer, and you are done with it, explicitly call this
92
93
94
        // ================================================================= Mouse States
95
        virtual void onRollOver(int x, int y)                                        {}                // called when mouse enters object x, y, width, height
96
        virtual void onRollOut()                                                                {}                // called when mouse leaves object x, y, width, height
97
        virtual void onMouseMove(int x, int y)                                        {}                // called when mouse moves while over object x, y, width, height
98
        virtual void onDragOver(int x, int y, int button)                {}                // called when mouse moves while over object and button is down
99
        virtual void onDragOutside(int x, int y, int button)        {}                // called when mouse moves while outside the object after being clicked on it
100
        virtual void onPress(int x, int y, int button)                        {}                // called when mouse presses while over object
101
        virtual void onRelease(int x, int y, int button)                {}                // called when mouse releases while over object
102
        virtual void onReleaseOutside(int x, int y, int button)        {}                // called when mouse releases outside of object after being pressed on object
103
104
        // ================================================================= Key States
105
        virtual void keyPressed(int key)        {}
106
        virtual void keyReleased(int key)        {}
107
108
109
        // ================================================================= Touch States
110
        virtual void onTouchDown(float x, float y, int ID)                        {}                // called when a touch down occurs on an object
111
        virtual void onTouchUp(float x, float y, int ID)                        {}                // called when a touch up occurs on an object
112
        virtual void onTouchUpOutside(float x, float y, int ID)                {}                // called when a touch up occurs after having pressed on an object
113
        virtual void onTouchMove(float x, float y, int ID)                        {}                // called when touch moves inside an object
114
        virtual void onTouchMoveOver(float x, float y, int ID)                {}                // called when touch moves outside to inside an object
115
        virtual void onTouchMoveOutside(float x, float y, int ID)        {}                // called when touch moves from inside to outside an object
116
117
        // ================================================================= Incoming Events
118
        void _setup(ofEventArgs &e);
119
        void _update(ofEventArgs &e);
120
    void _draw(ofEventArgs &e);
121
        void _exit(ofEventArgs &e);
122
123
        void _mouseMoved(ofMouseEventArgs &e);
124
        void _mousePressed(ofMouseEventArgs &e);        
125
        void _mouseDragged(ofMouseEventArgs &e);        
126
        void _mouseReleased(ofMouseEventArgs &e);
127
128
        void _keyPressed(ofKeyEventArgs &e);
129
        void _keyReleased(ofKeyEventArgs &e);
130
131
        void _tuioAdded(ofxTuioCursor &tuioCursor);    
132
        void _tuioRemoved(ofxTuioCursor &tuioCursor); 
133
        void _tuioUpdated(ofxTuioCursor &tuioCursor); 
134
        
135
protected:
136
137
        int                        _mouseX, _mouseY, _mouseButton;
138
        bool                _mouseOver;
139
        bool                _mouseDown;
140
141
        std::list<int> touchList;
142
143
        ofRectangle        oldRect;
144
};