Просмотр исходного кода

Fixed double click in input events

Ivan Safrin 12 лет назад
Родитель
Сommit
dc166ec2c5
2 измененных файлов с 9 добавлено и 0 удалено
  1. 1 0
      Core/Contents/Include/PolyEntity.h
  2. 8 0
      Core/Contents/Source/PolyEntity.cpp

+ 1 - 0
Core/Contents/Include/PolyEntity.h

@@ -715,6 +715,7 @@ namespace Polycode {
 			//@}		
 		protected:
 		
+			int lastClickTicks;
 			Number yAdjust;
 			std::vector<String> *tags;
 		

+ 8 - 0
Core/Contents/Source/PolyEntity.cpp

@@ -77,6 +77,7 @@ void Entity::initEntity() {
 	bBox.z = 0.001;
 	mouseOver = false;
 	yAdjust = 1.0;
+	lastClickTicks = 0.0;
 }
 
 Entity *Entity::getEntityById(String id, bool recursive) const {
@@ -923,6 +924,13 @@ MouseEventResult Entity::onMouseDown(const Ray &ray, int mouseButton, int timest
 			InputEvent *inputEvent = new InputEvent(Vector2(localCoordinate.x, localCoordinate.y*yAdjust), timestamp);
 			inputEvent->mouseButton = mouseButton;
 			dispatchEvent(inputEvent, InputEvent::EVENT_MOUSEDOWN);
+			
+			if(timestamp - lastClickTicks < 400) {
+				InputEvent *inputEvent = new InputEvent(Vector2(localCoordinate.x, localCoordinate.y*yAdjust), timestamp);
+				inputEvent->mouseButton = mouseButton;
+				dispatchEvent(inputEvent, InputEvent::EVENT_DOUBLECLICK);
+			}
+			lastClickTicks = timestamp;			
 						
 			if(blockMouseInput) {
 				ret.blocked = true;