Exemplo n.º 1
0
void PlayerButton::onMouseEvent(MouseEvent &event)
{
    switch (event.getType()) {
        case MouseEvent::Type::DOWN_INSIDE:
            mIsPressed = true;
            mPressPosition = event.getLocalPos();
            mShape->setFillColor(.4f, .4f, .4f);
            break;
            
        case MouseEvent::Type::UP_INSIDE:
            if (mIsPressed) doAction();
            mShape->setFillColor(1, 1, 1);
            mIsPressed = false;
            break;
            
        case MouseEvent::Type::MOVE:
        case MouseEvent::Type::DRAG:
            if (mIsPressed) {
                ci::vec2 dragVec = mPressPosition - event.getLocalPos();
                float dragDist = length(dragVec);
                if (dragDist > 10.f) {
                    mShape->setFillColor(1, 1, 1);
                    mIsPressed = false;
                }
            }
            break;
            
        default:
            break;
    }
}
Exemplo n.º 2
0
 void
 mouse_callback (const MouseEvent& mouse_event,
                 void* /*cookie*/)
 {
     if (mouse_event.getType () == MouseEvent::MouseButtonPress &&
             mouse_event.getButton () == MouseEvent::LeftButton)
     {
         cout << mouse_event.getX () << " , " << mouse_event.getY () << endl;
     }
 }
Exemplo n.º 3
0
	void Panel::passToCtrl(const MouseEvent &e,bool focus) {
		Pos pos = e.getPos();
		for(auto it = _controls.begin(); it != _controls.end(); ++it) {
			shared_ptr<Control> c = *it;
			Pos cpos = c->getPos();
			if(pos.x >= cpos.x && pos.x < (gpos_t)(cpos.x + c->getSize().width) &&
				pos.y >= cpos.y && pos.y < (gpos_t)(cpos.y + c->getSize().height)) {
				MouseEvent ce(e.getType(),e.getXMovement(),e.getYMovement(),e.getWheelMovement(),
					  pos - cpos,e.getButtonMask());
				if(focus)
					_focus = c.get();
				if(e.getType() == MouseEvent::MOUSE_PRESSED)
					c->onMousePressed(ce);
				else
					c->onMouseWheel(ce);
				return;
			}
		}

		// if we're here the user has not clicked on a control, so set the focus to "nothing"
		if(focus)
			_focus = nullptr;
	}