Daiki Kato / MothionEventConverter
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MotionEvent.cpp Source File

MotionEvent.cpp

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 #include "MotionEvent.h"
00018 
00019 float MotionEvent::getX() {
00020     return (float)_s_touch[0].x;
00021 }
00022 
00023 float MotionEvent::getX(int pointerIndex) {
00024     return (float)_s_touch[pointerIndex].x;
00025 }
00026 
00027 float MotionEvent::getY() {
00028     return (float)_s_touch[0].y;
00029 }
00030 
00031 float MotionEvent::getY(int pointerIndex) {
00032     return (float)_s_touch[pointerIndex].y;
00033 }
00034 
00035 int MotionEvent::getPointerCount() {
00036     return _touch_idx;
00037 }
00038 
00039 int MotionEvent::getPointerId(int pointerIndex) {
00040     return _s_touch[pointerIndex].id;
00041 }
00042 
00043 int MotionEvent::getAction() {
00044     return _action;
00045 }
00046 
00047 int MotionEvent::getActionMasked() {
00048     return getAction() & ACTION_MASK;
00049 }
00050 
00051 long MotionEvent::getDownTime() {
00052     return _down_time;
00053 }
00054 
00055 long MotionEvent::getEventTime() {
00056     return _event_time;
00057 }
00058 
00059 int MotionEvent::findPointerIndex(int pointerId) {
00060     int ret = -1;
00061     for (int i = 0; i < TOUCH_NUM_MAX; i++) {
00062         if (_s_touch[i].id == pointerId) {
00063             ret = i;
00064             break;
00065         }
00066     }
00067     return ret;
00068 }
00069 
00070 void MotionEvent::debug_print() {
00071 #if(1) //for debug
00072     int action = getAction();
00073     int index  = (action & MotionEvent::ACTION_POINTER_INDEX_MASK) >> MotionEvent::ACTION_POINTER_INDEX_SHIFT;
00074     int count  = getPointerCount();
00075 
00076     printf("action=%04x", action);
00077     printf(" index=%d", index);
00078 
00079     switch (getActionMasked()) {
00080         case ACTION_DOWN:          printf(" ACTION_DOWN        ");  break;
00081         case ACTION_UP:            printf(" ACTION_UP          ");  break;
00082         case ACTION_MOVE:          printf(" ACTION_MOVE        ");  break;
00083         case ACTION_CANCEL:        printf(" ACTION_CANCEL      ");  break;
00084         case ACTION_POINTER_DOWN:  printf(" ACTION_POINTER_DOWN");  break;
00085         case ACTION_POINTER_UP:    printf(" ACTION_POINTER_UP  ");  break;
00086     }
00087     printf(" DownTime=%8d, EventTime=%8d", getDownTime(), getEventTime());
00088 
00089     for (int i=0; i<count; i++) {
00090         printf("  id=%d,x=%5.1f,y=%5.1f", getPointerId(i), getX(i), getY(i));
00091     }
00092     printf("\n");
00093 #endif
00094 }
00095 
00096 
00097 // MotionEventCtl
00098 
00099 void MotionEventCtl::clearPointerCount() {
00100     _touch_idx = 0;
00101 }
00102 
00103 void MotionEventCtl::setPosData(int id, uint32_t x, uint32_t y) {
00104     if (_touch_idx < TOUCH_NUM_MAX) {
00105         _s_touch[_touch_idx].id = id;
00106         _s_touch[_touch_idx].x  = x;
00107         _s_touch[_touch_idx].y  = y;
00108         _touch_idx++;
00109     }
00110 }
00111 
00112 void MotionEventCtl::setActionInfo(int action, long time) {
00113     _action = action;
00114     _event_time   = time;
00115     if (action == ACTION_DOWN) {
00116         _down_time = time;
00117     }
00118 }
00119