front_idill/extern/fajran-npTuioClient/src/client.cpp
changeset 21 e4e5f02787a1
child 24 2bdf5d51d434
equal deleted inserted replaced
20:f4303074311f 21:e4e5f02787a1
       
     1 //   
       
     2 // Copyright (C) 2009  Fajran Iman Rusadi
       
     3 //
       
     4 // This program is free software: you can redistribute it and/or modify
       
     5 // it under the terms of the GNU General Public License as published by
       
     6 // the Free Software Foundation, either version 3 of the License, or
       
     7 // (at your option) any later version.
       
     8 //
       
     9 // This program is distributed in the hope that it will be useful,
       
    10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 // GNU General Public License for more details.
       
    13 //
       
    14 // You should have received a copy of the GNU General Public License
       
    15 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
       
    16 //
       
    17 
       
    18 #include "client.h"
       
    19 
       
    20 #include <TuioClient.h>
       
    21 #include <TuioListener.h>
       
    22 #include <TuioObject.h>
       
    23 #include <TuioCursor.h>
       
    24 
       
    25 static inline void call(TuioEvent type, long sid, int fid, float x, float y, float a)
       
    26 {
       
    27 	TuioEventData data;
       
    28 	data.type = type;
       
    29 	data.sid = sid;
       
    30 	data.fid = fid;
       
    31 	data.x = x;
       
    32 	data.y = y;
       
    33 	data.a = a;
       
    34 	tuio_callback(data);
       
    35 }
       
    36 
       
    37 class Listener : public TuioListener
       
    38 {
       
    39 public:
       
    40 	Listener() { };
       
    41 	~Listener() { };
       
    42 
       
    43 	void addTuioObject(TuioObject *object)
       
    44 	{
       
    45 		call(TE_OBJECT_ADD,
       
    46 			object->getSessionID(), object->getFiducialID(),
       
    47 			object->getX(), object->getY(), object->getAngle());
       
    48 	}
       
    49 
       
    50 	void updateTuioObject(TuioObject *object)
       
    51 	{
       
    52 		call(TE_OBJECT_UPDATE,
       
    53 			object->getSessionID(), object->getFiducialID(),
       
    54 			object->getX(), object->getY(), object->getAngle());
       
    55 	}
       
    56 
       
    57 	void removeTuioObject(TuioObject *object)
       
    58 	{
       
    59 		call(TE_OBJECT_REMOVE,
       
    60 			object->getSessionID(), object->getFiducialID(),
       
    61 			object->getX(), object->getY(), object->getAngle());
       
    62 	}
       
    63 	
       
    64 	void addTuioCursor(TuioCursor *cursor)
       
    65 	{
       
    66 		call(TE_CURSOR_ADD,
       
    67 			cursor->getSessionID(), cursor->getFingerID(),
       
    68 			cursor->getX(), cursor->getY(), 0);
       
    69 	}
       
    70 
       
    71 	void updateTuioCursor(TuioCursor *cursor)
       
    72 	{
       
    73 		call(TE_CURSOR_UPDATE,
       
    74 			cursor->getSessionID(), cursor->getFingerID(),
       
    75 			cursor->getX(), cursor->getY(), 0);
       
    76 	}
       
    77 
       
    78 	void removeTuioCursor(TuioCursor *cursor)
       
    79 	{
       
    80 		call(TE_CURSOR_REMOVE,
       
    81 			cursor->getSessionID(), cursor->getFingerID(),
       
    82 			cursor->getX(), cursor->getY(), 0);
       
    83 	}
       
    84 	
       
    85 	void refresh(long timestamp) 
       
    86 	{
       
    87 	}
       
    88 };
       
    89 
       
    90 static TuioClient* client = 0;
       
    91 static Listener* listener = 0;
       
    92 
       
    93 void tuio_start(int port)
       
    94 {
       
    95 	if (!client) {
       
    96 		listener = new Listener();
       
    97 
       
    98 		client = new TuioClient(port);
       
    99 		client->addTuioListener(listener);
       
   100 		client->start();
       
   101 	}
       
   102 }
       
   103 
       
   104 void tuio_stop()
       
   105 {
       
   106 	client->stop();
       
   107 	delete listener;
       
   108 	delete client;
       
   109 
       
   110 	client = 0;
       
   111 	listener = 0;
       
   112 }
       
   113