Example #1
0
bool Button::gamepadEvent(Gamepad::GamepadEvent evt, Gamepad* gamepad, unsigned int analogIndex)
{
    switch (evt)
    {
    case Gamepad::BUTTON_EVENT:
        if (_state == Control::FOCUS)
        {
            if (gamepad->isButtonDown(Gamepad::BUTTON_A) ||
                gamepad->isButtonDown(Gamepad::BUTTON_X))
            {
                notifyListeners(Control::Listener::PRESS);
                setState(Control::ACTIVE);
                return _consumeInputEvents;
            }
        }
        else if (_state == Control::ACTIVE)
        {
            if (!gamepad->isButtonDown(Gamepad::BUTTON_A) &&
                !gamepad->isButtonDown(Gamepad::BUTTON_X))
            {
                notifyListeners(Control::Listener::RELEASE);
                notifyListeners(Control::Listener::CLICK);
                setState(Control::FOCUS);
                return _consumeInputEvents;
            }
        }
        break;
    default:
        break;
    }

    return false;
}
Example #2
0
void Quadcopter::handleIncomingMessage(
	mavlink_message_t incomingMessage)
{
	receivedMessageMap[incomingMessage.msgid]++;

	switch (incomingMessage.msgid)
	{
		case MAVLINK_MSG_ID_HEARTBEAT:
		{
			flightMode = static_cast<FlightMode>
				(mavlink_msg_heartbeat_get_custom_mode(
					&incomingMessage));
			armed = mavlink_msg_heartbeat_get_base_mode(
				&incomingMessage) & (1 << 7);
			break;
		}
		case MAVLINK_MSG_ID_VFR_HUD:
		{
			altitude = mavlink_msg_vfr_hud_get_alt(&incomingMessage);
			heading = mavlink_msg_vfr_hud_get_heading(&incomingMessage);
			break;
		}
		case MAVLINK_MSG_ID_ATTITUDE:
		{
			roll = mavlink_msg_attitude_get_roll(&incomingMessage);
			pitch = mavlink_msg_attitude_get_pitch(&incomingMessage);
			yaw = mavlink_msg_attitude_get_yaw(&incomingMessage);
			break;
		}
		case MAVLINK_MSG_ID_STATUSTEXT:
		{
			char text[50];
			auto rtn = mavlink_msg_statustext_get_text(
				&incomingMessage, text);
			auto severity = mavlink_msg_statustext_get_severity(
				&incomingMessage);

			text[rtn - 1] = '\0';
			if (statusTextMap.count(text) > 0)
			{
				notifyListeners(statusTextMap.at(text));
			}
			else
			{
				notifyListeners(StatusText::UNKNOWN);
			}
			break;
		}
	}
	notifyListeners(StatusText::NONE);
}
void NetworkCatalogTree::onAuthCheck(const std::string &error) {
	if (!error.empty()) {
		notifyListeners(error);
		return;
	}

	if (!myChildrenItems.empty()) {
		notifyDownloadStopped();
		notifyListeners(std::string()); //TODO maybe not be silent about auth error here
		return;
	}
	new AsyncLoadSubCatalogRunnable(this, false);

}
void MorseEventDelayer::dispatchEvents() {
    std::lock_guard<std::mutex> _(mtx);
    while (!queue.empty() && queue.front().time <= currentTime) {
        notifyListeners(queue.front());
        queue.pop();
    }
}
Example #5
0
void ChannelBase<T>::set(T newValue) {
  if (isDigital) {
    newValue = std::abs(newValue) >= actPoint ? 1.0f : 0.0f;
  } else {
    newValue = std::abs(newValue) >= deadZone ? newValue : 0.0f;

    if (hasBound) {
      newValue = std::abs(newValue) >= bound ? 1.0f : newValue;
    }
    newValue *= sensitivity;
  }

  if (value != newValue or alwaysNotifyListener) {
    value = newValue;

    if (not listeners.empty()) {
      notifyListeners();
    }
  } else {
    return;
  }

  if (autoZero) {
    value = 0.0f;
  }
}
Example #6
0
	SceneNode::~SceneNode()
	{
		LOGD_LOOP("SceneNode destructor [this: 0x%X]", this);

		notifyListeners(k_nodeRemoved);
		removeAllChilds(true);
	}
Example #7
0
bool Button::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
{
    switch (evt)
    {
    case Touch::TOUCH_PRESS:
        if (_contactIndex == INVALID_CONTACT_INDEX)
        {
            if (x > _clipBounds.x && x <= _clipBounds.x + _clipBounds.width &&
                y > _clipBounds.y && y <= _clipBounds.y + _clipBounds.height)
            {
                _contactIndex = (int) contactIndex;
                notifyListeners(Control::Listener::PRESS);
                setState(Control::ACTIVE);
                return _consumeInputEvents;
            }
            else
            {
                setState(Control::NORMAL);
            }
        }
        break;

    case Touch::TOUCH_RELEASE:
        if (_contactIndex == (int) contactIndex)
        {
            _contactIndex = INVALID_CONTACT_INDEX;
            notifyListeners(Control::Listener::RELEASE);
            if (!_parent->isScrolling() &&
                x > _clipBounds.x && x <= _clipBounds.x + _clipBounds.width &&
                y > _clipBounds.y && y <= _clipBounds.y + _clipBounds.height)
            {
                notifyListeners(Control::Listener::CLICK);
                setState(Control::FOCUS);
            }
            else
            {
                setState(Control::NORMAL);
            }
            return _consumeInputEvents;
        }
        break;
    case Touch::TOUCH_MOVE:
        return Control::touchEvent(evt, x, y, contactIndex);
    }

    return false;
}
Example #8
0
void CheckBox::setChecked(bool checked)
{
    if (_checked != checked)
    {
        _checked = checked;
        _dirty = true;
        notifyListeners(Control::Listener::VALUE_CHANGED);
    }
}
Example #9
0
void CheckBox::setChecked(bool checked)
{
    if (_checked != checked)
    {
        _checked = checked;
        setDirty(DIRTY_STATE);
        notifyListeners(Control::Listener::VALUE_CHANGED);
    }
}
Example #10
0
bool Button::keyEvent(Keyboard::KeyEvent evt, int key)
{
    if (evt == Keyboard::KEY_PRESS && key == Keyboard::KEY_RETURN)
    {
        notifyListeners(Control::Listener::PRESS);
        setState(Control::ACTIVE);
        return _consumeInputEvents;
    }
    else if (_state == ACTIVE && evt == Keyboard::KEY_RELEASE && key == Keyboard::KEY_RETURN)
    {
        notifyListeners(Control::Listener::RELEASE);
        notifyListeners(Control::Listener::CLICK);
        setState(Control::FOCUS);
        return _consumeInputEvents;
    }

    return false;
}
Example #11
0
void JingleSessionImpl::handleRequestResponse(RequestRef request) {
	RequestsMap::iterator i = pendingRequests.find(request);
	assert(i != pendingRequests.end());
	if (i->first->getPayloadGeneric()->getAction() == JinglePayload::TransportInfo) {
		notifyListeners(&JingleSessionListener::handleTransportInfoAcknowledged, i->first->getID());
	}
	i->second.disconnect();
	pendingRequests.erase(i);
}
Example #12
0
void MLT3DHub::ProcessMessage(const osc::ReceivedMessage& msg, const IpEndpointName&)
{
	osc::TimeTag frameTime;
	osc::int32 frameID, touchID, deviceID;
	float x, y, z, note;
    
    // todo keep track of alive touches again to fix deadbeats
	// int alive[MLProcInputToSignals::kFrameHeight] = {0};
	
	try
	{
		osc::ReceivedMessageArgumentStream args = msg.ArgumentStream();
		const char * addy = msg.AddressPattern();
        
		//debug() << "t3d: " << addy << "\n";
        
		// frame message.
		// /t3d/frm (int)frameID int)deviceID
		if (strcmp(addy, "/t3d/frm") == 0)
		{
			args >> frameID >> deviceID;
            mT3DWaitTime = 0;
			
			if(!mConnected)
			{
				mConnected = true;
				notifyListeners("connected", 1);
			}
            //debug() << "FRM " << frameID << "\n";
		}
        // match tch[n] message
        else if (strncmp(addy, "/t3d/tch", 8) == 0)
		{
            // get trailing number
			touchID = 1;
            int len = strlen(addy);
            if(len == 9)
            {
                touchID = addy[8] - 48;
            }
            else if(len == 10)
            {
                touchID = 10*(addy[8] - 48) + (addy[9] - 48);
            }
            touchID = clamp(touchID - 1, (osc::int32)0, (osc::int32)16);
            
			// t3d/tch[ID], (float)x, (float)y, (float)z, (float)note
			args >> x >> y >> z >> note;
			
			//debug() << "TCH " << touchID << " " << x << " " << y << " " << z << " " << note << "\n";
            
			mOutputFrame(0, touchID) = x;
			mOutputFrame(1, touchID) = y;
			mOutputFrame(2, touchID) = z;
			mOutputFrame(3, touchID) = note;
		}
Example #13
0
ExposedModel::ExposedModel(boost::shared_ptr<tinia::model::ExposedModel> model,
                           QScriptEngine *engine,
                           QObject *parent)
    : QObject(parent), m_engine(engine), m_model(model)
{
    m_model->addStateListener(this);
    connect(this, SIGNAL(elementModified(QString)), this,
            SLOT(notifyListeners(QString)),
            Qt::QueuedConnection);
}
bool RadioButton::keyEvent(Keyboard::KeyEvent evt, int key)
{
    if (getState() == ACTIVE && evt == Keyboard::KEY_RELEASE && key == Keyboard::KEY_RETURN && !_selected)
    {
        RadioButton::clearSelected(_groupId);
        _selected = true;
        notifyListeners(Control::Listener::VALUE_CHANGED);
    }

    return Button::keyEvent(evt, key);
}
void RadioButton::setSelected(bool selected)
{
    if (selected)
        RadioButton::clearSelected(_groupId);

    if (selected != _selected)
    {
        _selected = selected;
        setDirty(DIRTY_STATE);
        notifyListeners(Control::Listener::VALUE_CHANGED);
    }
}
Example #16
0
SoundplaneModel::~SoundplaneModel()
{
	notifyListeners(0);
		
	// delete driver -- this will cause process thread to terminate.
	//  
	if (mpDriver) 
	{ 
		delete mpDriver; 
		mpDriver = 0; 
	}
}
Example #17
0
bool Parser::parse()
{
  _result = _expr();

  TokenType t = _token();
  if (t != TT_EOF) {
    notifyListeners("Syntax error: unparsed data at end of source");
    _success = false;
  }

  return _success;
}
Example #18
0
bool Cell::replaceGameObject(GameObject & g)
{
	if(!validLayer(g.layer))	// Layer is invalid
		return false;
	
	removeGameObject(g.layer);

	layers[g.layer] = &g;
	g.setCell(this);
	notifyListeners(&g);

	return true;
}
Example #19
0
	void Control::setValue(float value)
	{
		float previousValue = mValue;

		mValue = std::max<float>(0.0,std::min<float>(1.0,value));

		if(mValue != previousValue)
		{
			updateChannels();

			notifyListeners(previousValue);
		}
	}
void NetworkCatalogTree::onChildrenReceived(NetworkItem::List &childrens, const std::string &error) {
	if (!error.empty()) {
		//special case for authenticationFailed after 'cancel' button pressed in AuthDialog?
		//TODO maybe it'll be work wrong at some cases? maybe we should have another error this case?
		if (error != NetworkErrors::errorMessage(NetworkErrors::ERROR_AUTHENTICATION_FAILED)) {
			NetworkErrors::showErrorMessage(error);
		}
		notifyListeners(error);
		return;
	}

	myChildrenItems.insert(myChildrenItems.end(), childrens.begin(), childrens.end());

	if (myChildrenItems.empty()) {
		ZLDialogManager::Instance().informationBox(ZLResourceKey("emptyCatalogBox"));
		notifyListeners(error);
		return;
	}

	bool hasSubcatalogs = false;
	for (NetworkItem::List::iterator it = myChildrenItems.begin(); it != myChildrenItems.end(); ++it) {
		if ((*it)->typeId() == NetworkCatalogItem::TYPE_ID) {
			hasSubcatalogs = true;
			break;
		}
	}

	//TODO rewrite this method
	if (hasSubcatalogs) {
		for (NetworkItem::List::iterator it = childrens.begin(); it != childrens.end(); ++it) {
			NetworkTreeFactory::createNetworkTree(this, *it);
		}
	} else {
		NetworkTreeFactory::fillAuthorTree(this, childrens);
	}
	notifyListeners(error);

	this->updated();
}
Example #21
0
void JingleSessionImpl::handleIncomingAction(JinglePayload::ref action) {
	if (action->getAction() == JinglePayload::SessionTerminate) {
		notifyListeners(&JingleSessionListener::handleSessionTerminateReceived, action->getReason());
		return;
	}
	if (action->getAction() == JinglePayload::SessionInfo) {
		notifyListeners(&JingleSessionListener::handleSessionInfoReceived, action);
		return;
	}

	JingleContentPayload::ref content = action->getPayload<JingleContentPayload>();
	if (!content) {
		SWIFT_LOG(debug) << "no content payload!" << std::endl;
		return;
	}
	JingleContentID contentID(content->getName(), content->getCreator());
	JingleDescription::ref description = content->getDescriptions().empty() ? JingleDescription::ref() : content->getDescriptions()[0];
	JingleTransportPayload::ref transport = content->getTransports().empty() ? JingleTransportPayload::ref() : content->getTransports()[0];
	switch(action->getAction()) {
		case JinglePayload::SessionAccept:
			notifyListeners(&JingleSessionListener::handleSessionAcceptReceived, contentID, description, transport);
			return;
		case JinglePayload::TransportAccept:
			notifyListeners(&JingleSessionListener::handleTransportAcceptReceived, contentID, transport);
			return;
		case JinglePayload::TransportInfo:
			notifyListeners(&JingleSessionListener::handleTransportInfoReceived, contentID, transport);
			return;
		case JinglePayload::TransportReject:
			notifyListeners(&JingleSessionListener::handleTransportRejectReceived, contentID, transport);
			return;
		case JinglePayload::TransportReplace:
			notifyListeners(&JingleSessionListener::handleTransportReplaceReceived, contentID, transport);
			return;
		// following unused Jingle actions
		case JinglePayload::ContentAccept:
		case JinglePayload::ContentAdd:
		case JinglePayload::ContentModify:
		case JinglePayload::ContentReject:
		case JinglePayload::ContentRemove:
		case JinglePayload::DescriptionInfo:
		case JinglePayload::SecurityInfo:

		// handled elsewhere
		case JinglePayload::SessionInitiate:
		case JinglePayload::SessionInfo:
		case JinglePayload::SessionTerminate:

		case JinglePayload::UnknownAction:
			return;
	}
	assert(false);
}
Example #22
0
void repo::core::RepoLogger::log(
        const std::string &msg,
        const RepoSeverity &severity)
{
    std::string filename = getFilename();
    std::string formattedMessage = getHtmlFormattedMessage(msg, severity);

    notifyListeners(formattedMessage);

    std::ofstream file(filename, std::ios::app);
    if (!file.is_open())
    {
        notifyListeners(
                    getHtmlFormattedMessage(
                        "Cannot write to log file: " + getFullFilePath(),
                        RepoSeverity::REPO_CRITICAL));
    }
    else
    {
        file << formattedMessage << std::endl;
        file.close();
    }
}
void 
EventController::startElement(const char* name, const char** atts)
{
	size_t nameLength = strlen(name) + 1;
	wchar_t* wszElementName = (wchar_t*)malloc((strlen(name) + 1)*sizeof(wchar_t));
	size_t convertedChars = 0;
	mbstowcs_s(&convertedChars, wszElementName, nameLength, name, _TRUNCATE);
	wstring elementName = wszElementName;
	free(wszElementName);

	if(pCurrentElement != NULL)
	{
		notifyListeners();
	}

	pCurrentElement = new Element();
	pCurrentElement->name = elementName;
	pCurrentElement->data = NULL;

	if (atts)
	{
		for(int i = 0; atts[i]; i+=2)
		{
			if(atts[i+1] != NULL)
			{
				Attribute att;

				size_t attributeNameLength = strlen(atts[i]) + 1;
				size_t attributeValueLength = strlen(atts[i+1]) + 1;
				wchar_t* wszAttributeName = (wchar_t*)malloc(attributeNameLength*sizeof(wchar_t));
				wchar_t* wszAttributeValue = (wchar_t*)malloc(attributeValueLength*sizeof(wchar_t));
			
				mbstowcs_s(&convertedChars, wszAttributeName, attributeNameLength, atts[i], _TRUNCATE);
				mbstowcs_s(&convertedChars, wszAttributeValue, attributeValueLength, atts[i+1], _TRUNCATE);
				
				att.name = wszAttributeName;
				att.value = wszAttributeValue;

				pCurrentElement->attributes.push_back(att);

				free(wszAttributeName);
				free(wszAttributeValue);

			} else {
				printf("EventController: ERROR - Malformed XML received\n");
			}
		}
	}
}
Example #24
0
bool Slider::mouseEvent(Mouse::MouseEvent evt, int x, int y, int wheelDelta)
{
    switch (evt)
    {
        case Mouse::MOUSE_PRESS_LEFT_BUTTON:
            return touchEvent(Touch::TOUCH_PRESS, x, y, 0);

        case Mouse::MOUSE_MOVE:
            return Control::mouseEvent(evt, x, y, 0);

        case Mouse::MOUSE_RELEASE_LEFT_BUTTON:
            return touchEvent(Touch::TOUCH_RELEASE, x, y, 0);

        case Mouse::MOUSE_WHEEL:
        {
            if ((hasFocus() && _state == HOVER) || _state == ACTIVE)
            {
                float total = _max - _min;
                float oldValue = _value;
                _value += (total * SCROLLWHEEL_FRACTION) * wheelDelta;
            
                if (_value > _max)
                    _value = _max;
                else if (_value < _min)
                    _value = _min;

                if (_step > 0.0f)
                {            
                    int numSteps = round(_value / _step);
                    _value = _step * numSteps;
                }

                if (_value != oldValue)
                {
                    notifyListeners(Control::Listener::VALUE_CHANGED);
                }

                _dirty = true;
                return true;
            }
            break;
        }

        default:
            break;
    }

    return false;
}
Example #25
0
bool Slider::mouseEvent(Mouse::MouseEvent evt, int x, int y, int wheelDelta)
{
    if (!isEnabled())
    {
        return false;
    }

    switch (evt)
    {
        case Mouse::MOUSE_PRESS_LEFT_BUTTON:
            return touchEvent(Touch::TOUCH_PRESS, x, y, 0);

        case Mouse::MOUSE_MOVE:
            return touchEvent(Touch::TOUCH_MOVE, x, y, 0);

        case Mouse::MOUSE_RELEASE_LEFT_BUTTON:
            return touchEvent(Touch::TOUCH_RELEASE, x, y, 0);

        case Mouse::MOUSE_WHEEL:
        {
            if (_state == FOCUS || _state == ACTIVE)
            {
                float total = _max - _min;
                float oldValue = _value;
                _value += (total * SCROLL_FRACTION) * wheelDelta;
            
                if (_value > _max)
                    _value = _max;
                else if (_value < _min)
                    _value = _min;

                if (_value != oldValue)
                {
                    notifyListeners(Listener::VALUE_CHANGED);
                }

                _dirty = true;
                return _consumeInputEvents;
            }
            break;
        }

        default:
            break;
    }

    return false;
}
Example #26
0
	void IClock::updateTime()
	{
		unsigned long newTime = getPhysicalTime();
		_lastRealFrameDuration = newTime - _lastTime;
		_lastFrameDuration =  _lastRealFrameDuration / _factorRalentizar;
		_lastTime = newTime;

		//Para que el tiempo no pueda ser mayor de uno, suele darse cuando ponemos un punto de interrupcion, y da resultados raros, asi lo evitamos
		//Si el tick dura mas de medio segundo, lo fijamos en medio segundo
		assert((_lastFrameDuration = _lastFrameDuration > 500 ? 500 : _lastFrameDuration) || true);
		assert((_lastRealFrameDuration = _lastRealFrameDuration > 500 ? 500 : _lastRealFrameDuration) || true);

		_currentTime += _lastFrameDuration;
		notifyListeners();

	} // updateTime
Example #27
0
	void SceneNode::removeAllChilds(bool deleteChild)
	{
		LOGD_LOOP("SceneNode::removeAllChilds [this: 0x%X, delete: %d]", this, deleteChild);

		for(ChildNodeListIt it = m_childsNodes.begin();
						it != m_childsNodes.end(); ++it)
		{
			notifyListeners(deleteChild ? k_removeChild : k_dettachChild, (*it));

			if(deleteChild)
			{
				delete (*it);
			}
		}
		m_childsNodes.clear();
	}
void RadioButton::controlEvent(Control::Listener::EventType evt)
{
    Button::controlEvent(evt);

    switch (evt)
    {
    case Control::Listener::CLICK:
        if (!_selected)
        {
            RadioButton::clearSelected(_groupId);
            _selected = true;
            notifyListeners(Control::Listener::VALUE_CHANGED);
        }
        break;
    }
}
Example #29
0
	void SceneNode::removeChild(SceneNode* childNode, bool deleteChild)
	{
		LOGD_LOOP("SceneNode::removeChild [this: 0x%X, child = 0x%X, delete: %d]", this, childNode, deleteChild);

		ChildNodeListIt it = std::find(m_childsNodes.begin(),
						m_childsNodes.end(), childNode);

		if(it != m_childsNodes.end())
		{
			notifyListeners(deleteChild ? k_removeChild : k_dettachChild, (*it));

			if(deleteChild)
			{
				delete (*it);
			}
			m_childsNodes.erase(it);
		}
	}
Example #30
0
void Slider::setValue(float value)
{
    value = MATH_CLAMP(value, _min, _max);

    if (value != _value)
    {
        _value = value;
        notifyListeners(Control::Listener::VALUE_CHANGED);
    }

    // Always update value text if it's visible
    if (_valueTextVisible)
    {
        char s[32];
        sprintf(s, "%.*f", _valueTextPrecision, _value);
        _valueText = s;
    }
}