root / ofxTouchAPI / src / ofxTouchAPI_IO.h @ 67
View | Annotate | Download (7.2 KB)
| 1 | /***********************************************************************
|
|---|---|
| 2 | |
| 3 | Copyright (c) 2009, 2010 Dimitri Diakopoulos, http://www.dimitridiakopoulos.com/ |
| 4 | |
| 5 | |
| 6 | Portions Copyright (c) 2008, 2009 Memo Aktens, 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 | #include "StateManager.h" |
| 40 | |
| 41 | class ofxTouchAPI_IO : public ofRectangle {
|
| 42 | |
| 43 | public:
|
| 44 | |
| 45 | bool enabled; // set to false to disable all events |
| 46 | bool verbose;
|
| 47 | |
| 48 | ofxTouchAPI_IO(); // constructor
|
| 49 | virtual ~ofxTouchAPI_IO(); // destructor
|
| 50 | |
| 51 | // ================================================================= Event Enable/Disable
|
| 52 | void enableAllEvents(); // enable all event callbacks (default) |
| 53 | void disableAllEvents(); // disable all event callbacks |
| 54 | |
| 55 | void enableAllInput(); // ... |
| 56 | void disableAllInput(); // ... |
| 57 | |
| 58 | void enableMouseEvents(); // call this if object should receive mouse events |
| 59 | void disableMouseEvents(); // call this if object doesn't need to receive mouse events |
| 60 | |
| 61 | void enableKeyEvents(); // call this if object should receive key events |
| 62 | void disableKeyEvents(); // call this if object doesn't need to receive key events |
| 63 | |
| 64 | void enableTouchEvents(); // call this if object should recieve TUIO |
| 65 | void disableTouchEvents(); // call this if object doesn't need to receive TUIO |
| 66 | |
| 67 | void enableAppEvents(); // call this if object should update/draw automatically (default) |
| 68 | void disableAppEvents(); // call this if object doesn't need to update/draw automatically |
| 69 | |
| 70 | // ================================================================= Setters
|
| 71 | void setPos(float _x, float _y); // set position of object |
| 72 | void setSize(float _w, float _h); // set size of object |
| 73 | void setPosAndSize(float _x, float _y, float _w, float _h); // set pos and size in one |
| 74 | |
| 75 | // ================================================================= Getters
|
| 76 | bool isMouseOver(); // returns true if mouse is over object (based on position and size) |
| 77 | bool isMouseDown(); // returns true if mouse button is down and over object (based on position and size) |
| 78 | int getMouseX(); // returns mouse X (in screen coordinates) |
| 79 | int getMouseY(); // returns mouse Y (in screen coordinates) |
| 80 | int getLastMouseButton(); // returns last mouse button to have activity |
| 81 | |
| 82 | int getTouches(); // returns number of touches (doesn't work currently); |
| 83 | bool isTouchActive(int ID); // asks if the current finger ID is touching the object |
| 84 | bool isBeingTouched(); // asks if any touch is currently down -- good for hover over state; |
| 85 | |
| 86 | |
| 87 | // ================================================================= Updater Methods
|
| 88 | virtual void setup() {} // called when app starts |
| 89 | virtual void update() {} // called every frame to update object |
| 90 | virtual void draw() {} // called every frame to draw object |
| 91 | virtual void exit() {} // called when app quits |
| 92 | void killMe(); // if your object is a pointer and you are done with it, explicitly call this |
| 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 | virtual void focusActive() {} // called when all input is disabled but we still want to focus the control |
| 105 | |
| 106 | |
| 107 | // ================================================================= Key States
|
| 108 | virtual void keyPressed(int key) {} |
| 109 | virtual void keyReleased(int key) {} |
| 110 | |
| 111 | // ================================================================= Touch States
|
| 112 | virtual void onTouchDown(float x, float y, int ID) {} // called when a touch down occurs on an object |
| 113 | virtual void onTouchUp(float x, float y, int ID) {} // called when a touch up occurs on an object |
| 114 | virtual void onTouchUpOutside(float x, float y, int ID) {} // called when a touch up occurs after having pressed on an object |
| 115 | virtual void onTouchMove(float x, float y, int ID) {} // called when touch moves inside an object |
| 116 | virtual void onTouchMoveOver(float x, float y, int ID) {} // called when touch moves outside to inside an object |
| 117 | virtual void onTouchMoveOutside(float x, float y, int ID) {} // called when touch moves from inside to outside an object |
| 118 | |
| 119 | // ================================================================= Event Handlers
|
| 120 | void _setup(ofEventArgs &e);
|
| 121 | void _update(ofEventArgs &e);
|
| 122 | void _draw(ofEventArgs &e);
|
| 123 | void _exit(ofEventArgs &e);
|
| 124 | |
| 125 | void _focusActive(ofMouseEventArgs &e);
|
| 126 | |
| 127 | void _mouseMoved(ofMouseEventArgs &e);
|
| 128 | void _mousePressed(ofMouseEventArgs &e);
|
| 129 | void _mouseDragged(ofMouseEventArgs &e);
|
| 130 | void _mouseReleased(ofMouseEventArgs &e);
|
| 131 | |
| 132 | void _keyPressed(ofKeyEventArgs &e);
|
| 133 | void _keyReleased(ofKeyEventArgs &e);
|
| 134 | |
| 135 | void _tuioAdded(ofxTuioCursor &tuioCursor);
|
| 136 | void _tuioRemoved(ofxTuioCursor &tuioCursor);
|
| 137 | void _tuioUpdated(ofxTuioCursor &tuioCursor);
|
| 138 | |
| 139 | protected:
|
| 140 | |
| 141 | int _mouseX, _mouseY, _mouseButton;
|
| 142 | bool _mouseOver;
|
| 143 | bool _mouseDown;
|
| 144 | |
| 145 | std::list<int> touchList;
|
| 146 | |
| 147 | ofRectangle oldRect; |
| 148 | }; |
