Daiki Kato / MothionEventConverter
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MotionEvent.h Source File

MotionEvent.h

Go to the documentation of this file.
00001 /* mbed Microcontroller Library
00002  * Copyright (C) 2016 Renesas Electronics Corporation. All rights reserved.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 /**************************************************************************//**
00017 * @file          MotionEvent.h
00018 * @brief         MotionEvent API
00019 ******************************************************************************/
00020 
00021 #ifndef MOTION_EVENT_H
00022 #define MOTION_EVENT_H
00023 
00024 #include "mbed.h"
00025 
00026 #define ACTION_DOWN            (0x00000000)
00027 #define ACTION_UP              (0x00000001)
00028 #define ACTION_MOVE            (0x00000002)
00029 #define ACTION_CANCEL          (0x00000003)
00030 #define ACTION_POINTER_DOWN    (0x00000005)
00031 #define ACTION_POINTER_UP      (0x00000006)
00032 
00033 /**
00034  * MotionEvent
00035  */
00036 class MotionEvent {
00037 
00038 public:
00039     /** getX(int) for the first pointer index (may be an arbitrary pointer identifier). 
00040      *
00041      * @return float
00042      */
00043     float getX();
00044 
00045     /** Returns the X coordinate of this event for the given pointer index 
00046      * (use getPointerId(int) to find the pointer identifier for this index).
00047      * Whole numbers are pixels; the value may have a fraction for input devices that are sub-pixel precise.
00048      *
00049      * @param pointerIndex Raw index of pointer to retrieve.
00050      *        Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
00051      * @return float
00052      */
00053     float getX(int pointerIndex);
00054 
00055     /** getY(int) for the first pointer index (may be an arbitrary pointer identifier).
00056      *
00057      * @return float
00058      */
00059     float getY();
00060 
00061     /** Returns the Y coordinate of this event for the given pointer index 
00062      * (use getPointerId(int) to find the pointer identifier for this index).
00063      * Whole numbers are pixels; the value may have a fraction for input devices that are sub-pixel precise.
00064      *
00065      * @param pointerIndex Raw index of pointer to retrieve.
00066      *        Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
00067      * @return float
00068      */
00069     float getY(int pointerIndex);
00070 
00071     /** The number of pointers of data contained in this event. Always >= 1.
00072      *
00073      * @return int
00074      */
00075     int getPointerCount();
00076 
00077     /** Return the pointer identifier associated with a particular pointer data index in this event.
00078      * The identifier tells you the actual pointer number associated with the data, accounting for
00079      * individual pointers going up and down since the start of the current gesture.
00080      *
00081      * @return int
00082      */
00083     int getPointerId(int pointerIndex);
00084 
00085     /** Return the kind of action being performed. Consider using getActionMasked() and getActionIndex()
00086      *  to retrieve the separate masked action and pointer index.
00087      *
00088      * @return The action, such as ACTION_DOWN or the combination of ACTION_POINTER_DOWN with a shifted pointer index.
00089      */
00090     int getAction();
00091 
00092     /** Return the masked action being performed, without pointer index information. Use getActionIndex()
00093      *   to return the index associated with pointer actions.
00094      *
00095      * @return The action, such as ACTION_DOWN or ACTION_POINTER_DOWN.
00096      */
00097     int getActionMasked();
00098 
00099     /** Returns the time (in ms) when the user originally pressed down to start a stream of position events.
00100      *
00101      * @return long
00102      */
00103     long getDownTime();
00104 
00105     /** Retrieve the time this event occurred, in the uptimeMillis() time base.
00106      *
00107      * @return Returns the time this event occurred, in the uptimeMillis() time base.
00108      */
00109     long getEventTime();
00110 
00111     /** Given a pointer identifier, find the index of its data in the event.
00112      *
00113      * @param pointerId The identifier of the pointer to be found.
00114      * @return Returns either the index of the pointer (for use with getX(int) et al.),
00115      *  or -1 if there is no data available for that pointer identifier.
00116      */
00117     int findPointerIndex(int pointerId);
00118 
00119 
00120     /** Bits in the action code that represent a pointer index, used with ACTION_POINTER_DOWN and ACTION_POINTER_UP.
00121      * Shifting down by ACTION_POINTER_INDEX_SHIFT provides the actual pointer index where the data for the pointer
00122      * going up or down can be found; you can get its identifier with getPointerId(int) and the actual data with
00123      * getX(int) etc.
00124      */
00125     static const int ACTION_POINTER_INDEX_MASK  = 0x0000ff00;
00126 
00127     /** Bit shift for the action bits holding the pointer index as defined by ACTION_POINTER_INDEX_MASK.
00128      *
00129      */
00130     static const int ACTION_POINTER_INDEX_SHIFT = 0x00000008;
00131 
00132     /** Bit mask of the parts of the action code that are the action itself.
00133      *
00134      */
00135     static const int ACTION_MASK                = 0x000000ff;
00136 
00137 
00138     /** printf output function for debugging
00139      *
00140      */
00141     void debug_print();
00142 
00143     /** The maximum number of touch
00144      *
00145      */
00146     static const int TOUCH_NUM_MAX  = 2;
00147 
00148 protected:
00149     typedef struct {
00150         uint32_t id;
00151         uint32_t x;
00152         uint32_t y;
00153     } touch_t;
00154 
00155     touch_t _s_touch[TOUCH_NUM_MAX];
00156     int     _action;
00157     long    _event_time;
00158     long    _down_time;
00159     int     _touch_idx;
00160 };
00161 
00162 
00163 /**
00164  * The class to set the price as MotionEvent
00165  */
00166 class MotionEventCtl : public MotionEvent {
00167 
00168 public:
00169     /** Initialize of touch information.
00170      *
00171      */
00172     void clearPointerCount();
00173 
00174     /** Set the coordinate.
00175      *
00176      * @param id PointerId.
00177      * @param x X coordinate.
00178      * @param y Y coordinate.
00179      */
00180     void setPosData(int id, uint32_t x, uint32_t y);
00181 
00182     /** Set the action.
00183      *
00184      * @param action The action, such as ACTION_DOWN or the combination of ACTION_POINTER_DOWN with a shifted pointer index.
00185      * @param time The time this event occurred, in the uptimeMillis() time base.
00186      */
00187     void setActionInfo(int action, long time);
00188 };
00189 
00190 #endif
00191