Пример #1
0
void TrackballCamera::handleEvent(Event *event) {
	if(event->getDispatcher() == trackballShape) {
		InputEvent *inputEvent = (InputEvent*) event;
		switch(event->getEventCode()) {
			case InputEvent::EVENT_MOUSEDOWN:
				if(isNavKeyDown() || inputEvent->mouseButton == CoreInput::MOUSE_BUTTON3) {
					if(coreInput->getKeyState(KEY_LSHIFT) || coreInput->getKeyState(KEY_RSHIFT)) {
						mouseMode = MOUSE_MODE_PANNING;
						trackBallMouseStart = Vector2(
							inputEvent->getMousePosition().x / trackballShape->getWidth(),
							inputEvent->getMousePosition().y / trackballShape->getHeight()
						);
						trackBallMouseEnd = trackBallMouseStart;
					} else if(coreInput->getKeyState(KEY_LCTRL) || coreInput->getKeyState(KEY_RCTRL)) {
						mouseMode = MOUSE_MODE_ZOOMING;
						trackBallMouseStart = Vector2(
							inputEvent->getMousePosition().x / trackballShape->getWidth(),
							inputEvent->getMousePosition().y / trackballShape->getHeight()
						);
						trackBallMouseEnd = trackBallMouseStart;												
					} else {
                        if(!rotationDisabled) {
                            mouseMode = MOUSE_MODE_ORBITING;
							trackBallMouseStart = trackBallMouseEnd = Vector2(
								inputEvent->getMousePosition().x / trackballShape->getWidth(),
								inputEvent->getMousePosition().y / trackballShape->getHeight()
							);
                        }
					}
				}
			break;
			case InputEvent::EVENT_MOUSEUP:
			case InputEvent::EVENT_MOUSEUP_OUTSIDE:
				mouseMode = MOUSE_MODE_IDLE;
			break;
			case InputEvent::EVENT_MOUSEMOVE:
				processMouseMovement(inputEvent->getMousePosition());
			break;
			case InputEvent::EVENT_MOUSEWHEEL_UP:
				cameraDistance *= 0.9;
				updateCamera();
			break;
			case InputEvent::EVENT_MOUSEWHEEL_DOWN:
				cameraDistance *= 1.1;
				updateCamera();
			break;
		}		
		return;
	}
}
Пример #2
0
void UIComboBox::handleEvent(Event *event) {

	if(event->getDispatcher() == dropDownBox) {
		switch(event->getEventCode()) {
			case InputEvent::EVENT_MOUSEMOVE:
			{
				InputEvent *inputEvent = (InputEvent*) event;
				selectedOffset = floor(inputEvent->getMousePosition().y/comboHeight);
				if(selectedOffset < 0)
					selectedOffset = 0;
					
				if(selectedOffset >= 0 && selectedOffset < items.size())
					selectorBox->setPosition(0,selectedOffset*comboHeight);
			}				
			break;
			case InputEvent::EVENT_MOUSEDOWN:
			{
				setSelectedIndex(selectedOffset);
			}
			break;
		}	
	}
	
	if(event->getDispatcher() == dropDownImage || event->getDispatcher() == bgBox) {
		switch(event->getEventCode()) {
			case InputEvent::EVENT_MOUSEDOWN:
				toggleDropDown();
			break;
		}
	}
}
Пример #3
0
void UIMenu::handleEvent(Event *event) {

	if(event->getDispatcher() == CoreServices::getInstance()->getCore()->getInput()) {
	
		InputEvent *inputEvent = (InputEvent*) event;	
		
		if(event->getEventCode() == InputEvent::EVENT_KEYDOWN) {
			if(inputEvent->key == KEY_ESCAPE) {
				dispatchEvent(new UIEvent(), UIEvent::CANCEL_EVENT);							
			}
		}
		if((event->getEventCode() == InputEvent::EVENT_MOUSEDOWN || (event->getEventCode() == InputEvent::EVENT_MOUSEUP && initialMouse != inputEvent->getMousePosition())) && !ignoreMouse) {
			if(selectorBox->visible) {
				dispatchEvent(new UIEvent(), UIEvent::OK_EVENT);
			} else if(!dropDownBox->hitTest(inputEvent->getMousePosition())) {
				dispatchEvent(new UIEvent(), UIEvent::CANCEL_EVENT);
			}
		}
	}
	
	if(event->getDispatcher() == dropDownBox) {
		switch(event->getEventCode()) {
			case InputEvent::EVENT_MOUSEOUT:
			{
				selectorBox->visible = false;			
			}
			break;
			case InputEvent::EVENT_MOUSEMOVE:
			{
				CoreServices::getInstance()->getCore()->setCursor(Core::CURSOR_ARROW);				
				InputEvent *inputEvent = (InputEvent*) event;
				selectedOffset = floor(((inputEvent->getMousePosition().y-selectorPadding)-paddingY)/menuItemHeight);
					
				if(selectedOffset >= 0 && selectedOffset < items.size() && items[selectedOffset]->isSelectable()) {
					selectorBox->visible = true;				
					selectorBox->setPosition(paddingX,paddingY+(selectedOffset*menuItemHeight) - selectorPadding);
				} else {
					selectorBox->visible = false;
				}
			}				
			break;
		}	
	}
}
Пример #4
0
void UIColorPicker::handleEvent(Event *event) {

	if((event->getDispatcher() == rTextInput || event->getDispatcher() == gTextInput || event->getDispatcher() == bTextInput || event->getDispatcher() == aTextInput) && event->getEventType() == "UIEvent") {
		switch(event->getEventCode()) {
			case UIEvent::CHANGE_EVENT:
			{
				if(!suppressTextChangeEvent) {
					rebuildFromTextInputs();
				} else {
					suppressTextChangeEvent = false;
				}
			}
			break;
		}	
	}

	if(event->getDispatcher() == alphaSlider) {
		switch(event->getEventCode()) {
			case UIEvent::CHANGE_EVENT:
			{
				colorAlpha = alphaSlider->getSliderValue();
				updateSelectedColor();
			}
			break;
		}
	}

	if(event->getDispatcher() == hueFrame) {
		switch(event->getEventCode()) {
			case InputEvent::EVENT_MOUSEDOWN:
			{
				InputEvent *inputEvent = (InputEvent*) event;
				hueSelector->setPositionY(inputEvent->getMousePosition().y+hueFrame->getPosition().y);
				hueSelector->startDrag(inputEvent->mousePosition.x-hueSelector->getPosition().x,inputEvent->mousePosition.y-hueSelector->getPosition().y+hueFrame->getPosition().y);
			}
			break;
			case InputEvent::EVENT_MOUSEUP:
			case InputEvent::EVENT_MOUSEUP_OUTSIDE:			
			{
				hueSelector->stopDrag();
				updateColorFromHueSelector();	
			}
			break;	
		}
	}



	if(event->getDispatcher() == mainColorRect) {
		switch(event->getEventCode()) {
			case InputEvent::EVENT_MOUSEDOWN:
			{
				InputEvent *inputEvent = (InputEvent*) event;
				mainSelector->setPosition(inputEvent->getMousePosition().x+mainColorRect->getPosition().x, inputEvent->getMousePosition().y+mainColorRect->getPosition().y);
				mainSelector->startDrag(inputEvent->mousePosition.x-mainSelector->getPosition().x+mainColorRect->getPosition().x,inputEvent->mousePosition.y-mainSelector->getPosition().y+mainColorRect->getPosition().y);
			}
			break;
			case InputEvent::EVENT_MOUSEUP:
			case InputEvent::EVENT_MOUSEUP_OUTSIDE:			
			{
				mainSelector->stopDrag();			
				updateColorFromMainSelector();
			}
			break;	
		}
	}
	
	UIWindow::handleEvent(event);
}
Пример #5
0
void UIColorPicker::handleEvent(Event *event) {

	if((event->getDispatcher() == rTextInput || event->getDispatcher() == gTextInput || event->getDispatcher() == bTextInput || event->getDispatcher() == aTextInput) && event->getEventType() == "UIEvent") {
		switch(event->getEventCode()) {
			case UIEvent::CHANGE_EVENT:
			{
				rebuildFromTextInputs();
			}
			break;
		}	
	}

	if(event->getDispatcher() == alphaSlider) {
		switch(event->getEventCode()) {
			case UIEvent::CHANGE_EVENT:
			{
				colorAlpha = alphaSlider->getSliderValue();
				updateSelectedColor();
			}
			break;
		}
	}

	if(event->getDispatcher() == hueFrame) {
		switch(event->getEventCode()) {
			case InputEvent::EVENT_MOUSEDOWN:
			{
				InputEvent *inputEvent = (InputEvent*) event;
				hueSelector->setPositionY(inputEvent->getMousePosition().y);
				hueSelector->startDrag(inputEvent->mousePosition.x-hueSelector->getPosition().x,inputEvent->mousePosition.y-hueSelector->getPosition().y);		
				Number newHue = 360.0 - (((inputEvent->getMousePosition().y-hueFrame->getPosition().y)/((hueFrame->getPosition().y+hueFrame->getHeight())-hueFrame->getPosition().y)) * 360.0f);
				setHue(newHue);
						
			}
			break;
			case InputEvent::EVENT_MOUSEUP:
			case InputEvent::EVENT_MOUSEUP_OUTSIDE:			
			{
				hueSelector->stopDrag();
			}
			break;	
		}
	}



	if(event->getDispatcher() == mainColorRect) {
		switch(event->getEventCode()) {
			case InputEvent::EVENT_MOUSEDOWN:
			{
				InputEvent *inputEvent = (InputEvent*) event;			
				mainSelector->setPosition(inputEvent->getMousePosition().x, inputEvent->getMousePosition().y);
				
				mainSelector->startDrag(inputEvent->mousePosition.x-mainSelector->getPosition().x,inputEvent->mousePosition.y-mainSelector->getPosition().y);
				
				Number newV = 1.0 - ((inputEvent->getMousePosition().y-mainColorRect->getPosition().y)/((mainColorRect->getPosition().y+mainColorRect->getHeight())-mainColorRect->getPosition().y));

				Number newS = ((inputEvent->getMousePosition().x-mainColorRect->getPosition().x)/((mainColorRect->getPosition().x+mainColorRect->getWidth())-mainColorRect->getPosition().x));
					
				setSaturationAndValue(newS, newV);
			}
			break;
			case InputEvent::EVENT_MOUSEUP:
			case InputEvent::EVENT_MOUSEUP_OUTSIDE:			
			{
				mainSelector->stopDrag();			
			}
			break;	
		}
	}
	
	UIWindow::handleEvent(event);
}
void PolycodeScreenEditor::handleEvent(Event *event) {
	InputEvent *inputEvent = (InputEvent*) event;
	
	if(event->getDispatcher() == entityColorBox  && event->getEventType() == "UIEvent") {
		switch (event->getEventCode()) {
			case UIEvent::CHANGE_EVENT:
				if(selectedEntity) {
					selectedEntity->setColor(entityColorBox->getSelectedColor());
				}
			break;
		}
		return;
	}
	
	if(event->getDispatcher() == baseEntity) {
		switch (event->getEventCode()) {
			case InputEvent::EVENT_MOUSEDOWN:
				selectedEntity = NULL;
				screenTransform->visible = false;
			break;		
			case InputEvent::EVENT_MOUSEUP:
			case InputEvent::EVENT_MOUSEUP_OUTSIDE:			
				isDraggingEntity = false;	
				isScalingEntity = false;	
				if(selectedEntity) 					
					selectedEntity->stopDrag();
			break;
			case InputEvent::EVENT_MOUSEMOVE:
			{
				if(isDraggingEntity) {
					if(selectedEntity) 
						syncTransformToSelected();
				} else if(isScalingEntity) {
/*
					Vector2 scaleVector = Vector2(selectedEntity->getPosition2D().x + baseEntity->getPosition2D().x, selectedEntity->getPosition2D().y + baseEntity->getPosition2D().y) - inputEvent->mousePosition;
					
					scaleVector.x =	scaleVector.x / selectedEntity->getWidth() * 2.0;
					scaleVector.y =	scaleVector.y / selectedEntity->getHeight() * 2.0;					
					selectedEntity->setScale(scaleVector.x, scaleVector.y, 0);
					*/
					syncTransformToSelected();
				}
			}
			break;			
		}
		return;
	}

	for(int i=0; i < baseEntity->getNumChildren(); i++) {
		ScreenEntity* childEntity = (ScreenEntity*) baseEntity->getChildAtIndex(i);
		if(event->getDispatcher() == childEntity) {		
			screenTransform->visible = true;					
			
			selectedEntity = childEntity;
			entityColorBox->setBoxColor(selectedEntity->color);
			syncTransformToSelected();
			
			Number cornerSize = 12;
			if(false) {
				isScalingEntity = true;
			} else {
				selectedEntity->startDrag(inputEvent->getMousePosition().x, inputEvent->getMousePosition().y);
				isDraggingEntity = true;						
			}
			
			
		}
	}
}