Ejemplo n.º 1
0
//-------------------------------------------
void BlockBehaviourAir::update(float dt)
{
    //simply negate sideways movement and allow gravity to do its thing
    auto vel = getVelocity();
    vel.x *= getFriction();
    setVelocity(vel);

    sf::Int32 cat = getParentCategory();
    if (cat & (Category::CarriedOne | Category::CarriedTwo))
    {
        //can't carry blocks which are in the air 
        Event e;
        e.type = Event::Player;
        e.player.action = Event::PlayerEvent::Dropped;
        e.player.playerId = (cat & (Category::CarriedOne)) ? Category::PlayerOne : Category::PlayerTwo;
        e.player.positionX = 0.f;
        e.player.positionY = 0.f;
        raiseEvent(e);
    }

    if (getFootSenseMask() == CollisionWorld::Body::Type::Water) //touches water only
    {
        setBehaviour<BlockBehaviourWater>();

        Event e;
        e.type = Event::Block;
        e.block.action = Event::BlockEvent::HitWater;
        auto pos = getBody()->getCentre();
        e.block.positionX = pos.x;
        e.block.positionY = pos.y;
        raiseEvent(e);
    }
}
Ejemplo n.º 2
0
void CXUIFreeDraw::OnPaint()
{
	PAINTSTRUCT ps;
	HDC hdc = BeginPaint(m_hWnd, &ps);

	RECT rcClient;
	GetClientRect(m_hWnd, &rcClient);

	if(m_bDoubleBuffered)
	{
		RECT rcDraw = {0, 0, 0, 0};
		rcDraw.right	= rcClient.right - rcClient.left;
		rcDraw.bottom	= rcClient.bottom - rcClient.top;
		HDC memDC	= CreateCompatibleDC(hdc);
		HBITMAP bmp = CreateCompatibleBitmap(hdc, rcDraw.right, rcDraw.bottom);
		HBITMAP oldBmp = (HBITMAP) SelectObject(memDC, bmp);
		SendMessage(GetParent(m_hWnd), WM_ERASEBKGND, (WPARAM) memDC, NULL);
		raiseEvent(XUI_EVENT_FREEDRAW, (WPARAM) memDC, (LPARAM) &rcDraw);
		BitBlt(hdc, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, memDC, 0, 0, SRCCOPY);
		SelectObject(memDC, oldBmp);
		DeleteObject(bmp);
		DeleteDC(memDC);
	} else
	{
		raiseEvent(XUI_EVENT_FREEDRAW, (WPARAM) hdc, (LPARAM) &rcClient);
	}

	EndPaint(m_hWnd, &ps);
}
Ejemplo n.º 3
0
void MergeSort(int *array, int start, int end)
{
	if(start == end)
		return;

	int middle = (start + end) / 2,
		helper[end - start + 1],
		i = 0, j = 0,
		place = 0;
	bool event = raiseEvent(EVENT_TYPE_CHECK, 0);
	if(!event)
		return;

	MergeSort(array, start, middle);
	MergeSort(array, middle + 1, end);
	for(i = start, j = middle + 1, place = 0; event && (i <= middle || j <= end);)
	{
		if(j > end || (i <= middle && (event = raiseEvent(EVENT_TYPE_COMPARE, 2, i, j)) && array[i] < array[j]))
			helper[place ++] = array[i ++];

		else if(event && (i > middle || (j <= end && (event = raiseEvent(EVENT_TYPE_COMPARE, 2, i, j)) && array[i] >= array[j])))
			helper[place ++] = array[j ++];
	}

	for(i = start; event && i <= end; ++ i)
		if((event = raiseEvent(EVENT_TYPE_SWAP, 2, i, i)))
		{
			array[i] = helper[i - start];
			event = raiseEvent(EVENT_TYPE_SWAP, 2, i, i);
		}

	return;
}
Ejemplo n.º 4
0
void AIEngine::update()
{
    if (_pause || _finished)
        return;

    sMsgDisp.update();

    if (_self_auto_fight)
        sAutoFightSys.update(true);
    
    if (_enemy_auto_fight)
        sAutoFightSys.update(false);

    if (_frame == TimeLimit)
    {
        auto cv = sCrtMgr.getAllHeros(CreatureManager::S_ALL);
        if (cv->size() != 0)
        {
            AIEvent evt;
            evt.etype = EVT_TIME_OUT;
            evt.raiser = (*cv->begin())->getId();
            raiseEvent(evt);
        }
    }
    else if (_reload && _evt_seq.size())
    {
        auto it = _evt_seq.begin();
        while (true)
        {
            it = std::find_if(it, _evt_seq.end(),
                             [this](AIEvent const &evt) { 
                                 return evt.frame == _frame;
                             }
                             );
            if (it != _evt_seq.end())
            {
                raiseEvent(*it);
                _evt_seq.erase(it++);
            }
            else
            {
                break;
            }
        }
	}

    _frame++;

    FriendCommonCoolDown::reduceCoolDown();
    EnemyCommonCoolDown::reduceCoolDown();
    FriendStartBattleCoolDown::reduceCoolDown();
    EnemyStartBattleCoolDown::reduceCoolDown();
    sCrtMgr.update();
}
Ejemplo n.º 5
0
void DebugSession::_stateChanged(KDevelop::IDebugSession::DebuggerState state)
{
    kDebug() << state;
    if (state == StartingState) {
        run();
    } else if (state == PausedState) {
        raiseEvent(program_state_changed);
    } else if (state == StoppingState) {
        m_connection->sendCommand("stop");
    } else if (state == EndedState) {
        raiseEvent(debugger_exited);
        emit finished();
    }
}
Ejemplo n.º 6
0
void AIEngine::raiseGlobalSpell()
{
    AIEvent evt;
    evt.raiser = _spl_c->getId();
    evt.etype  = EVT_SPELL;
    raiseEvent(evt);
}
Ejemplo n.º 7
0
//=============================================================================
// METHOD    : SPELLcontroller::setStatus
//=============================================================================
void SPELLcontroller::setStatus( const SPELLexecutorStatus& st )
{
	DEBUG("[C] Attempt to set status " + SPELLexecutorUtils::statusToString(st));
    bool newStatus = (st != m_status);

	if (newStatus) notifyBeforeStatusChange(m_status);

    m_status = st;
    // We don't want to notify status redundantly
    if (newStatus || st == STATUS_WAITING || st == STATUS_PROMPT)
    {
        LOG_INFO("Procedure status: " + SPELLexecutorUtils::statusToString(st));
        SPELLstatusInfo info(st);
        info.condition = getCondition();
        info.actionLabel = SPELLexecutor::instance().getUserAction().getLabel();
        info.actionEnabled = SPELLexecutor::instance().getUserAction().isEnabled();

		SPELLexecutor::instance().getCIF().notifyStatus( info );
    }

    if (newStatus) notifyAfterStatusChange(m_status);

    if (newStatus && st == STATUS_ABORTED)
    {
    	std::string event = "Procedure aborted: " + m_procId;
    	raiseEvent( event );
    }
}
Ejemplo n.º 8
0
	bool UiElement::checkMouseClickEvent( const UiInputState& prevState, const UiInputState& currentState )
	{
		if( m_mouseMoveState )
		{
			UiEvent eventData;
			eventData.data.mouseButton.position	= currentState.mousePosition;

			bool result = false;
			for( uint i = 0u; i < MouseButton_Count; ++i )
			{
				eventData.data.mouseButton.button = (MouseButton)i;

				if( !prevState.mouseButtonState.state[ i ] && currentState.mouseButtonState.state[ i ] )
				{
					m_mouseClickState.state[ i ] = true;

					eventData.type = UiEventType_MouseButtonDown;
					raiseEvent( eventData );

					result = true;
				}
				else if( prevState.mouseButtonState.state[ i ] && !currentState.mouseButtonState.state[ i ] )
				{
					if( m_mouseClickState.state[ i ] )
					{
						eventData.type = UiEventType_MouseButtonClick;
						raiseEvent( eventData );
					}
					m_mouseClickState.state[ i ] = false;

					eventData.type = UiEventType_MouseButtonUp;
					raiseEvent( eventData );

					result = true;
				}
			}

			for( UiElement& child : m_children )
			{
				child.checkMouseClickEvent( prevState, currentState );
			}

			return result;
		}

		return false;
	}
Ejemplo n.º 9
0
BOOL CXUIDatePicker::onNotify( int idCtrl, LPNMHDR pnmh )
{
	if(pnmh->code == DTN_DATETIMECHANGE)
	{
		return raiseEvent(XUI_EVENT_CHANGED, NULL, NULL);
	}
	return FALSE;
}
Ejemplo n.º 10
0
void QuickSort(int *array, int start, int end)
{
	if(start >= end)
		return;

	int middle = (start + end) / 2,
		i = start, j = end - 1,
		temp = 0;
	bool event = raiseEvent(EVENT_TYPE_CHECK, 0);
	if(!event)
		return;

	if((event = raiseEvent(EVENT_TYPE_SWAP, 2, middle, end)))
	{
		temp = array[middle];
		array[middle] = array[end];
		array[end] = temp;
		event = raiseEvent(EVENT_TYPE_SWAP, 2, middle, end);
	}

	for(i = start; event && i < j;)
	{
		if((event = raiseEvent(EVENT_TYPE_COMPARE, 2, i, end)) && 
		   array[i] >= array[end] && (event = raiseEvent(EVENT_TYPE_SWAP, 2, i, j)))
		{
			temp = array[i];
			array[i] = array[j];
			array[j] = temp;
			event = raiseEvent(EVENT_TYPE_SWAP, 2, i, j);
			-- j;
		}

		else
			++ i;
	}

	if(array[j] < array[end])
		++ j;

	if((event = raiseEvent(EVENT_TYPE_SWAP, 2, j, end)))
	{
		temp = array[j];
		array[j] = array[end];
		array[end] = temp;
		event = raiseEvent(EVENT_TYPE_SWAP, 2, j, end);
	}

	if(event)
	{
		QuickSort(array, start, j - 1);
		QuickSort(array, j + 1, end);
	}
}
Ejemplo n.º 11
0
void
ZBarFilter::barcodeDetected (guint64 ts, std::string &type, std::string &symbol)
{
  if (lastSymbol != symbol || lastType != type ||
      lastTs == G_GUINT64_CONSTANT (0) || ( (ts - lastTs) >= GST_SECOND) ) {
    lastSymbol = symbol;
    lastType = type;
    lastTs = ts;
    raiseEvent (ts, type, symbol);
  }
}
Ejemplo n.º 12
0
void EditNamePage::onKeyPress(unsigned char key)
{

	uint8_t value;
	switch (key) {
		case VIRTUAL_KEY_ENTER:
			if ( m_user ) {
				String newName = controller.inputAsString();
				newName.toCharArray(m_user->name, newName.length()  +1);
				raiseEvent(ClosePageWithSuccessEvent);
			}
			else {
				raiseEvent(ClosePageEvent);
			}
			break;
		case VIRTUAL_KEY_ESCAPE:
			raiseEvent(ClosePageEvent);
			break;
	}
	
}
Ejemplo n.º 13
0
//-------------------------------------------
void PlayerBehaviourGround::update(float dt)
{
    auto vel = getVelocity();
    if(vel.y > 0.f) vel.y = 0.f;

    vel.x *= getFriction(); //TODO equate dt into this
    setVelocity(vel);

    //raise start / stop events
    if (vel.x != 0 && m_lastVelocity.x == 0)
    {
        Event e;
        e.type = Event::Type::Player;
        e.player.action = Event::PlayerEvent::Moved;
        raiseEvent(e);
    }
    else if (vel.x == 0 && m_lastVelocity.x != 0)
    {
        Event e;
        e.type = Event::Type::Player;
        e.player.action = Event::PlayerEvent::Stopped;
        raiseEvent(e);
    }
    m_lastVelocity = vel;

    if ((getFootSenseMask() & (CollisionWorld::Body::Type::Block | CollisionWorld::Body::Type::Solid)) == 0)
    {
        setBehaviour<PlayerBehaviourAir>();

        //let go of whatever we're holding
        Event e;
        e.type = Event::Player;
        e.player.action = Event::PlayerEvent::Released;
        e.player.playerId = getParentCategory();// (cat & Category::GrabbedOne) ? Category::PlayerOne : Category::PlayerTwo;
        auto pos = getBody()->getCentre();
        e.player.positionX = pos.x;
        e.player.positionY = pos.y;
        raiseEvent(e);
    }
}
Ejemplo n.º 14
0
	void NetLinkManager::run()
	{
		struct nl_handle *handle = nl_handle_alloc();
		nl_connect(handle, NETLINK_ROUTE);

		// init route messages
		nl_socket_add_membership(handle, RTNLGRP_IPV4_IFADDR);

//		IPv6 requires further support in the parsing procedures!
//		nl_socket_add_membership(handle, RTNLGRP_IPV6_IFADDR);
		nl_socket_add_membership(handle, RTNLGRP_LINK);

		// add netlink fd to vsocket
		_sock->add(nl_socket_get_fd(handle));

		try {
			while (_initialized)
			{
				std::list<int> fds;
				_sock->select(fds, NULL);
				int fd = fds.front();

				// create a new event object
				NetLinkManagerEvent lme(fd);

				// ignore if the event is unknown
				if (lme.getType() == LinkManagerEvent::EVENT_UNKOWN) continue;

				// ignore if this is an wireless extension event
				if (lme.isWirelessExtension()) continue;

				// need to refresh the cache
				{
					ibrcommon::MutexLock l(_call_mutex);
					_refresh_cache = true;
				}

				// print out some debugging
				IBRCOMMON_LOGGER_DEBUG(10) << lme.toString() << IBRCOMMON_LOGGER_ENDL;

				// notify all subscribers about this event
				raiseEvent(lme);
			}
		} catch (const vsocket_exception&) {
			// stopped / interrupted
			IBRCOMMON_LOGGER(error) << "NetLink connection stopped" << IBRCOMMON_LOGGER_ENDL;
		}

		nl_close(handle);
		nl_handle_destroy(handle);
	}
Ejemplo n.º 15
0
void BlockBehaviourAir::resolve(const sf::Vector3f& manifold, CollisionWorld::Body* other)
{
    switch (other->getType())
    {
    case CollisionWorld::Body::Type::Block:
        //setParentCategory(Category::Block); //reset any previous owners
    case CollisionWorld::Body::Type::Solid:
        move(sf::Vector2f(manifold.x, manifold.y) * manifold.z);
        setVelocity({getVelocity().x, 0.f});
        setBehaviour<BlockBehaviourGround>();

        Event e;
        e.type = Event::Block;
        e.block.action = Event::BlockEvent::HitGround;
        {
            auto pos = getBody()->getCentre();
            e.block.positionX = pos.x;
            e.block.positionY = pos.y;
        }
        raiseEvent(e);

        e.block.action = Event::BlockEvent::DragEnd;
        raiseEvent(e);

        break;
    case CollisionWorld::Body::FreeForm:
    {
        sf::Vector2f normal(manifold.x, manifold.y);
        move(normal * manifold.z);
        setVelocity(Util::Vector::reflect(getVelocity() * getFriction(), normal));

        if (getFootSenseMask() & CollisionWorld::Body::FreeForm)
            setBehaviour<BlockBehaviourGround>();
    }
    break;
    default: break;
    }
}
Ejemplo n.º 16
0
//-------------------------------------------
PlayerBehaviourWater::PlayerBehaviourWater(CollisionWorld::Body* b)
    : BodyBehaviour(b), m_sinkTime(1.5f), m_currentTime(0.f), m_splashed(false)
{
    if (!deleted())
    {
        Event e;
        e.type = Event::Type::Player;
        e.player.action = Event::PlayerEvent::HitWater;
        auto pos = b->getCentre();
        e.player.positionX = pos.x;
        e.player.positionY = pos.y;
        raiseEvent(e);
    }
}
Ejemplo n.º 17
0
void BlockBehaviourWater::resolve(const sf::Vector3f& manifold, CollisionWorld::Body* other)
{
    switch (other->getType())
    {
    case CollisionWorld::Body::Type::Block:
    case CollisionWorld::Body::Type::Solid:
        move(sf::Vector2f(manifold.x, manifold.y) * manifold.z);
        setVelocity({});
        setBehaviour<BlockBehaviourGround>();
        break;
    case CollisionWorld::Body::Type::Water:
        if(!m_splashed)
        {
            //raise splash event
            Event evt;
            evt.type = Event::Node;
            evt.node.type = Category::Water;
            evt.node.action = Event::NodeEvent::HitWater;
            evt.node.positionX = getBody()->getCentre().x;
            evt.node.positionY = getBody()->getCentre().y + (getBody()->getSize().y / 2.f);
            evt.node.speed = getVelocity().y;
            raiseEvent(evt, other);

            Event e;
            e.type = Event::Block;
            e.block.action = Event::BlockEvent::DragEnd;
            auto pos = getBody()->getCentre();
            e.block.positionX = pos.x;
            e.block.positionY = pos.y;
            raiseEvent(e);

            m_splashed = true;
        }
        break;
    default: break;
    }
}
Ejemplo n.º 18
0
void Director::getKeyState()
{
	getCurrentScene()->clearKeys();
	if (_keyList.size())
	{
		for (vector<int>::iterator it = _keyList.begin(); it != _keyList.end(); it++)
		{
			if (GetAsyncKeyState((*it)) & 0x8000)
			{
				getCurrentScene()->onKeyPressedCallback((*it));
			}

		}
	}
	int LBUTTONState = GetAsyncKeyState(VK_LBUTTON) & 0x8000;
	mouseEvent _event;
	
	if (LBUTTONState)
	{
		if (lastLBUTTONState)
		{
			_event.type = DRAG;
		}
		else
		{
			_event.type = DOWN;
		}
	}
	else
	{
		if (lastLBUTTONState)
		{
			_event.type = UP;
		}
		else
		{
			_event.type = MOVE;
		}
	}
	_event.point = POINT2Point(_mousepos);
	lastLBUTTONState = LBUTTONState;
	EventMsg msg;
	msg._event = _event;
	msg.name = "test";
	raiseEvent(msg);
	raiseMouseEvent(_event);
	
}
Ejemplo n.º 19
0
//------------------------------------------
void PlayerBehaviourAir::update(float dt)
{
    auto vel = getVelocity();
    vel.x *= 0.8f; //this should always be <= ground friction?
    setVelocity(vel);

    if (vel.y > 0 && m_lastVelocity.y < 0)
    {
        //started falling
        Event e;
        e.type = Event::Type::Player;
        e.player.action = Event::PlayerEvent::Action::StartedFalling;
        raiseEvent(e);
    }
    m_lastVelocity = vel;
}
Ejemplo n.º 20
0
void PlayerBehaviourWater::resolve(const sf::Vector3f& manifold, CollisionWorld::Body* other)
{
    if (!m_splashed && other->getType() == CollisionWorld::Body::Type::Water)
    {
        //raise splash event
        Event evt;
        evt.type = Event::Node;
        evt.node.type = Category::Water;
        evt.node.action = Event::NodeEvent::HitWater;
        evt.node.positionX = getBody()->getCentre().x;
        evt.node.positionY = getBody()->getCentre().y + (getBody()->getSize().y / 2.f);
        evt.node.speed = getVelocity().y;
        raiseEvent(evt, other);

        m_splashed = true;
    }
}
Ejemplo n.º 21
0
void BlockBehaviourCarry::resolve(const sf::Vector3f& manifold, CollisionWorld::Body* other)
{
    switch (other->getType())
    {
    case CollisionWorld::Body::Type::Player:
    case CollisionWorld::Body::Type::Npc:

    case CollisionWorld::Body::Type::Block:
    case CollisionWorld::Body::Type::Solid:
        //if block above then drop block by raising player drop event
        if (manifold.y != 0)//(manifold.y * manifold.z) > 0.f)
        {
            Event e;
            e.type = Event::Player;
            e.player.action = Event::PlayerEvent::Dropped;
            e.player.playerId = (getParentCategory() & (Category::CarriedOne)) ? Category::PlayerOne : Category::PlayerTwo;
            e.player.positionX = other->getCentre().x;
            e.player.positionY = other->getCentre().y;
            raiseEvent(e);
            std::cerr << "dropped from carry!" << std::endl;
        }

        //Event e;
        //e.type = Event::Block;
        //e.block.action = Event::BlockEvent::HitGround;
        //{
        //    auto pos = getBody()->getCentre();
        //    e.block.positionX = pos.x;
        //    e.block.positionY = pos.y;
        //}
        //raiseEvent(e);

    //case CollisionWorld::Body::Type::Player:
    //case CollisionWorld::Body::Type::Npc:
        move(sf::Vector2f(manifold.x, manifold.y) * manifold.z);
        setVelocity({0.f, getVelocity().y});

        break;
    default: break;
    }
}
Ejemplo n.º 22
0
	bool UiElement::checkMouseMoveEvent( const UiInputState& state )
	{
		const bool isInElement = m_layoutRectangle.contains( state.mousePosition );
		if( isInElement || m_mouseMoveState )
		{
			UiEvent eventData;
			eventData.data.mouseMove.position	= state.mousePosition;
			eventData.data.mouseMove.buttons	= state.mouseButtonState;

			if( isInElement && m_mouseMoveState )
			{
				eventData.type = UiEventType_MouseOver;
			}
			else if( isInElement && !m_mouseMoveState )
			{
				eventData.type = UiEventType_MouseIn;
				m_mouseMoveState = true;
			}
			else if( !isInElement && m_mouseMoveState )
			{
				eventData.type = UiEventType_MouseOut;
				m_mouseMoveState = false;
				m_mouseClickState = MouseButtonState();
			}

			raiseEvent( eventData );

			for( UiElement& child : m_children )
			{
				child.checkMouseMoveEvent( state );
			}

			return true;
		}

		return false;
	}
Ejemplo n.º 23
0
int pgQueryThread::execute()
{
	rowsInserted = -1L;

	if (!conn->conn)
		return(raiseEvent(0));

	wxCharBuffer queryBuf = query.mb_str(*conn->conv);
	if (!queryBuf && !query.IsEmpty())
	{
		conn->SetLastResultError(NULL, _("The query could not be converted to the required encoding."));
		return(raiseEvent(0));
	}

	if (!PQsendQuery(conn->conn, queryBuf))
	{
		conn->SetLastResultError(NULL);
		conn->IsAlive();
		return(raiseEvent(0));
	}
	int resultsRetrieved = 0;
	PGresult *lastResult = 0;
	while (true)
	{
		if (TestDestroy())
		{
			if (rc != -3)
			{
				if (!PQrequestCancel(conn->conn)) // could not abort; abort failed.
					return(raiseEvent(-1));

				rc = -3;
			}
		}
		if (!PQconsumeInput(conn->conn))
			return(raiseEvent(0));
		if (PQisBusy(conn->conn))
		{
			Yield();
			this->Sleep(10);
			continue;
		}

		// If resultToRetrieve is given, the nth result will be returned,
		// otherwise the last result set will be returned.
		// all others are discarded
		PGresult *res = PQgetResult(conn->conn);

		if (!res)
			break;

		resultsRetrieved++;
		if (resultsRetrieved == resultToRetrieve)
		{
			result = res;
			insertedOid = PQoidValue(res);
			if (insertedOid && insertedOid != (OID) - 1)
				appendMessage(wxString::Format(_("Query inserted one row with OID %d.\n"), insertedOid));
			else
				appendMessage(wxString::Format(wxPLURAL("Query result with %d row will be returned.\n", "Query result with %d rows will be returned.\n",
				                                        PQntuples(result))));
			continue;
		}
		if (lastResult)
		{
			if (PQntuples(lastResult))
				appendMessage(wxString::Format(wxPLURAL("Query result with %d row discarded.\n", "Query result with %d rows discarded.\n",
				                                        PQntuples(lastResult))));
			PQclear(lastResult);
		}
		lastResult = res;
	}

	if (!result)
		result = lastResult;

	conn->SetLastResultError(result);

	appendMessage(wxT("\n"));
	rc = PQresultStatus(result);
	insertedOid = PQoidValue(result);
	if (insertedOid == (OID) - 1)
		insertedOid = 0;

	if (rc == PGRES_TUPLES_OK)
	{
		dataSet = new pgSet(result, conn, *conn->conv, conn->needColQuoting);
		dataSet->MoveFirst();
	}
	else if (rc == PGRES_COMMAND_OK)
	{
		char *s = PQcmdTuples(result);
		if (*s)
			rowsInserted = atol(s);
	}
	else if (rc == PGRES_FATAL_ERROR)
	{
		appendMessage(conn->GetLastError() + wxT("\n"));
	}
	return(raiseEvent(1));
}
Ejemplo n.º 24
0
void TextEdit::eventOccured(Event *e)
{
	UString keyname;

	Control::eventOccured(e);

	if (e->type() == EVENT_FORM_INTERACTION)
	{
		if (e->forms().RaisedBy == shared_from_this())
		{
			if (e->forms().EventFlag == FormEventType::GotFocus ||
			    e->forms().EventFlag == FormEventType::MouseClick ||
			    e->forms().EventFlag == FormEventType::KeyDown)
			{
				editing = true;

				fw().textStartInput();
				// e->Handled = true;
				// FIXME: Should we really fall through here?
			}
		}
		if (editing)
		{
			if (e->forms().RaisedBy == shared_from_this())
			{

				if (e->forms().EventFlag == FormEventType::LostFocus)
				{
					editing = false;
					fw().textStopInput();
					raiseEvent(FormEventType::TextEditFinish);
					// e->Handled = true;
				}
			}
			else if (e->forms().EventFlag == FormEventType::MouseClick)
			{
				// FIXME: Due to event duplication (?), this code won't work. Can only stop editing
				// text by pressing enter.
				// editting = false;
				// fw().textStopInput();
				// raiseEvent(FormEventType::TextEditFinish);
			}
			if (e->forms().EventFlag == FormEventType::KeyDown)
			{
				LogInfo("Key pressed: %d", e->forms().KeyInfo.KeyCode);
				switch (e->forms().KeyInfo.KeyCode)
				{
					case SDLK_BACKSPACE:
						if (SelectionStart > 0)
						{
							text.remove(SelectionStart - 1, 1);
							SelectionStart--;
							raiseEvent(FormEventType::TextChanged);
						}
						e->Handled = true;
						break;
					case SDLK_DELETE:
						if (SelectionStart < text.length())
						{
							text.remove(SelectionStart, 1);
							raiseEvent(FormEventType::TextChanged);
						}
						e->Handled = true;
						break;
					case SDLK_LEFT:
						if (SelectionStart > 0)
						{
							SelectionStart--;
						}
						e->Handled = true;
						break;
					case SDLK_RIGHT:
						if (SelectionStart < text.length())
						{
							SelectionStart++;
						}
						e->Handled = true;
						break;
					case SDLK_HOME:
						SelectionStart = 0;
						e->Handled = true;
						break;
					case SDLK_END:
						SelectionStart = text.length();
						e->Handled = true;
						break;
					case SDLK_RETURN:
						editing = false;
						fw().textStopInput();
						raiseEvent(FormEventType::TextEditFinish);
						break;
					case SDLK_v: // CTRL+V
						if (e->forms().KeyInfo.Modifiers & KMOD_CTRL)
						{
							UString clipboard = fw().textGetClipboard();

							if (text.length() + clipboard.length() >= this->textMaxLength)
							{
								return;
							}
							if (!clipboard.empty())
							{
								text.insert(SelectionStart, clipboard);
								SelectionStart += clipboard.length();
								raiseEvent(FormEventType::TextChanged);
							}
						}
						break;
				}
			}
			else if (e->forms().EventFlag == FormEventType::TextInput)
			{
				if (text.length() >= this->textMaxLength)
				{
					return;
				}

				UString inputCharacter = e->forms().Input.Input;
				if (allowedCharacters.empty() ||
				    allowedCharacters.str().find(inputCharacter.str()) != std::string::npos)
				{
					text.insert(SelectionStart, inputCharacter);
					SelectionStart += inputCharacter.length();
					raiseEvent(FormEventType::TextChanged);
				}
			}
		}
	}
}
Ejemplo n.º 25
0
void TextEdit::setText(const UString &Text)
{
	text = Text;
	SelectionStart = text.length();
	raiseEvent(FormEventType::TextChanged);
}
Ejemplo n.º 26
0
void quicksort(int *array, const unsigned int size)
{
	QuickSort(array, 0, size - 1);
	raiseEvent(EVENT_TYPE_END, 0);
}
Ejemplo n.º 27
0
void LegendManager::procDirectDebugInstruction(StringBuilder *input) {
  char* str = input->position(0);

  uint8_t temp_byte = 0;
  if (*(str) != 0) {
    temp_byte = atoi((char*) str+1);
  }

  StringBuilder parse_mule;

  switch (*(str)) {
    case 'v':
      parse_mule.concat(str);
      local_log.concatf("parse_mule split (%s) into %d positions.\n", str, parse_mule.split(","));
      parse_mule.drop_position(0);
      if (temp_byte < 17) {
        if (parse_mule.count() > 0) {
          int temp_int = parse_mule.position_as_int(0);
          iius[temp_byte].setVerbosity(temp_int);
        }
        local_log.concatf("Verbosity on IIU %d is %d.\n", temp_byte, iius[temp_byte].getVerbosity());
      }
      break;

    case 'i':
      if (1 == temp_byte) {
        local_log.concatf("The IIU preallocated measurements are stored at %p.\n", (uintptr_t) __prealloc);
      }
      else if (2 == temp_byte) {
        if (operating_legend) {
          operating_legend->printDebug(&local_log);
        }
      }
      else {
        int8_t old_verbosity = getVerbosity();
        if (temp_byte && (temp_byte < 7)) setVerbosity(temp_byte);
        printDebug(&local_log);
        if (temp_byte && (temp_byte < 7)) setVerbosity(old_verbosity);
      }
      break;

    case '-':
      if (operating_legend) {
        operating_legend->copy_frame();
        local_log.concat("Frame copied.\n");
        operating_legend->printDataset(&local_log);
      }
      break;
    case '+':
      if (temp_byte < 17) {
        iius[temp_byte].dumpPointers(&local_log);
      }
      break;


    // IMU DEBUG //////////////////////////////////////////////////////////////////
    case 'c':
      if (temp_byte < 17) {
        iius[temp_byte].printDebug(&local_log);
      }
      break;

    // IMU STATE CONTROL //////////////////////////////////////////////////////////
    case 'g':
      if (255 == temp_byte) {
        local_log.concat("Syncing all IIUs...\n");
        for (uint8_t i = 0; i < 17; i++) {
          iius[i].sync();
        }
      }
      else if (temp_byte < 17) {
        iius[temp_byte].sync();
        local_log.concatf("Syncing IIU %d.\n", temp_byte);
      }
      break;

    case 's':
      parse_mule.concat(str);
      parse_mule.split(",");
      parse_mule.drop_position(0);
      if (parse_mule.count() > 0) {
        int temp_int = parse_mule.position_as_int(0);

        if (255 == temp_byte) {
          for (uint8_t i = 0; i < 17; i++) {
            iius[i].setOperatingState(temp_int);
          }
        }
        else if (temp_byte < 17) {
          local_log.concatf("Setting the state of IMU %d to %d\n", temp_byte, temp_int);
          iius[temp_byte].setOperatingState(temp_int);
        }

      }
      break;

    case 'k':
      if ((temp_byte < 6) && (temp_byte >= 0)) {
        ManuvrMsg *event = Kernel::returnEvent(DIGITABULUM_MSG_IMU_INIT);
        event->addArg((uint8_t) temp_byte);  // Set the desired init stage.
        event->priority(0);
        raiseEvent(event);
        local_log.concatf("Broadcasting IMU_INIT for stage %u...\n", temp_byte);
      }
      else {
        local_log.concatf("Illegal INIT stage: %u\n", temp_byte);
      }
      break;

    case 'r':
      if (255 == temp_byte) {
        local_log.concat("Reseting all IIUs...\n");
        for (uint8_t i = 0; i < 17; i++) {
          iius[i].reset();
        }
      }
      else if (temp_byte < 17) {
        local_log.concatf("Resetting IIU %d.\n", temp_byte);
        iius[temp_byte].reset();
      }
      break;


    case 'T':
    case 't':
      if (temp_byte < 17) {
        ManuvrMsg *event = Kernel::returnEvent((*(str) == 'T') ? DIGITABULUM_MSG_IMU_DOUBLE_TAP : DIGITABULUM_MSG_IMU_TAP);
        event->setOriginator((EventReceiver*) this);
        event->addArg((uint8_t) temp_byte);
        Kernel::staticRaiseEvent(event);
        local_log.concatf("Sent %stap event for IMU %d.\n", ((*(str) == 'T') ? "double ":""), temp_byte);
      }
      break;

    case 'q':
      if (temp_byte < 17) {
        ManuvrMsg *event = Kernel::returnEvent(DIGITABULUM_MSG_IMU_QUAT_CRUNCH);
        event->specific_target = (EventReceiver*) this;
        event->addArg((uint8_t) temp_byte);
        Kernel::staticRaiseEvent(event);
        local_log.concatf("Running quat on IIU %d.\n", temp_byte);
      }
      break;



    // IMU DATA ///////////////////////////////////////////////////////////////////
    case 'j':
      switch (*(str+1)) {
        case '0':
          reflection_acc.x = -1;
          reflection_acc.y = 1;
          reflection_acc.z = -1;
          reflection_gyr.set(-1, 1, -1);
          reflection_mag.x = 1;
          reflection_mag.y = 1;
          reflection_mag.z = -1;
          break;
        case 'm':
          if (*(str+2) == 'x')      reflection_mag.x *= -1;
          else if (*(str+2) == 'y') reflection_mag.y *= -1;
          else if (*(str+2) == 'z') reflection_mag.z *= -1;
          break;

        case 'a':
          if (*(str+2) == 'x')      reflection_acc.x *= -1;
          else if (*(str+2) == 'y') reflection_acc.y *= -1;
          else if (*(str+2) == 'z') reflection_acc.z *= -1;
          break;

        case 'g':
          if (*(str+2) == 'x')      reflection_gyr.x *= -1;
          else if (*(str+2) == 'y') reflection_gyr.y *= -1;
          else if (*(str+2) == 'z') reflection_gyr.z *= -1;
          break;
      }
      local_log.concatf("Reflection vectors\n\tMag (%d, %d, %d)\n\tAcc (%d, %d, %d)\n\tGyr (%d, %d, %d)\n", reflection_mag.x, reflection_mag.y, reflection_mag.z, reflection_acc.x, reflection_acc.y, reflection_acc.z, reflection_gyr.x, reflection_gyr.y, reflection_gyr.z);
      break;

    case '[':
    case ']':
      if (255 == temp_byte) {
        local_log.concatf("%sabling spherical abberation correction on all IIUs.\n", ((*(str) == ']') ? "En":"Dis"));
        for (uint8_t i = 0; i < 17; i++) {
          iius[i].correctSphericalAbberation((*(str) == ']'));
        }
      }
      else if (temp_byte < 17) {
        iius[temp_byte].correctSphericalAbberation((*(str) == ']'));
        local_log.concatf("%sabling spherical abberation correction on IIU %d.\n", ((*(str) == ']') ? "En":"Dis"), temp_byte);
      }
      break;

    case 'u':
    case 'U':
      if (255 == temp_byte) {
        local_log.concatf("%sabling (clean-mag-is-zero) on all IIUs.\n", ((*(str) == 'U') ? "En":"Dis"));
        for (uint8_t i = 0; i < 17; i++) {
          iius[i].cleanMagZero((*(str) == 'U'));
        }
      }
      else if (temp_byte < 17) {
        iius[temp_byte].cleanMagZero((*(str) == 'U'));
        local_log.concatf("%sabling (clean-mag-is-zero) on IIU %d.\n", ((*(str) == 'U') ? "En":"Dis"), temp_byte);
      }
      break;

    case 'w':
    case 'W':
      if (255 == temp_byte) {
        local_log.concatf("%sabling mag data scrutiny on all IIUs.\n", ((*(str) == 'Z') ? "En":"Dis"));
        for (uint8_t i = 0; i < 17; i++) {
          iius[i].dropObviousBadMag((*(str) == 'Z'));
        }
      }
      else if (temp_byte < 17) {
        iius[temp_byte].dropObviousBadMag((*(str) == 'Z'));
        local_log.concatf("%sabling mag data scrutiny on IIU %d.\n", ((*(str) == 'Z') ? "En":"Dis"), temp_byte);
      }
      break;

    case 'z':
    case 'Z':
      if (255 == temp_byte) {
        local_log.concatf("%sabling autoscale on all IIUs.\n", ((*(str) == 'Z') ? "En":"Dis"));
        for (uint8_t i = 0; i < 17; i++) {
          iius[i].enableAutoscale((*(str) == 'Z'));
        }
      }
      else if (temp_byte < 17) {
        iius[temp_byte].enableAutoscale((*(str) == 'Z'));
        local_log.concatf("%sabling autoscale on IIU %d.\n", ((*(str) == 'Z') ? "En":"Dis"), temp_byte);
      }
      break;

    case 'n':
    case 'N':
      if (255 == temp_byte) {
        local_log.concatf("%sabling range-binding on all IIUs.\n", ((*(str) == 'N') ? "En":"Dis"));
        for (uint8_t i = 0; i < 17; i++) {
          iius[i].rangeBind((*(str) == 'N'));
        }
      }
      else if (temp_byte < 17) {
        iius[temp_byte].rangeBind((*(str) == 'N'));
        local_log.concatf("%sabling range-binding on IIU %d.\n", ((*(str) == 'N') ? "En":"Dis"), temp_byte);
      }
      break;

    case 'h':
    case 'H':
      if (255 == temp_byte) {
        local_log.concatf("%sabling quats on all IIUs.\n", ((*(str) == 'H') ? "En":"Dis"));
        for (uint8_t i = 0; i < 17; i++) {
          iius[i].processQuats((*(str) == 'H'));
        }
      }
      else if (temp_byte < 17) {
        iius[temp_byte].processQuats((*(str) == 'H'));
        local_log.concatf("%sabling quats on IIU %d.\n", ((*(str) == 'H') ? "En":"Dis"), temp_byte);
      }
      break;

    case 'x':
    case 'X':
      if (255 == temp_byte) {
        local_log.concatf("%sabling gyro error compensation on all IIUs.\n", ((*(str) == 'X') ? "En":"Dis"));
        for (uint8_t i = 0; i < 17; i++) {
          iius[i].nullGyroError((*(str) == 'X'));
        }
      }
      else if (temp_byte < 17) {
        iius[temp_byte].nullGyroError((*(str) == 'X'));
        local_log.concatf("%sabling gyro error compensation on IIU %d.\n", ((*(str) == 'X') ? "En":"Dis"), temp_byte);
      }
      break;

    case 'm':
    case 'M':
      if (255 == temp_byte) {
        local_log.concatf("%sabling gravity nullification on all IIUs.\n", ((*(str) == 'M') ? "En":"Dis"));
        for (uint8_t i = 0; i < 17; i++) {
          iius[i].nullifyGravity((*(str) == 'M'));
        }
      }
      else if (temp_byte < 17) {
        iius[temp_byte].nullifyGravity((*(str) == 'M'));
        local_log.concatf("%sabling gravity nullification on IIU %d.\n", ((*(str) == 'M') ? "En":"Dis"), temp_byte);
      }
      break;

    case 'y':
    case 'Y':
      if (255 == temp_byte) {
        local_log.concatf("%sabling bearing nullification on all IIUs.\n", ((*(str) == 'Y') ? "En":"Dis"));
        for (uint8_t i = 0; i < 17; i++) {
          iius[i].nullifyBearing((*(str) == 'Y'));
        }
      }
      else if (temp_byte < 17) {
        iius[temp_byte].nullifyBearing((*(str) == 'Y'));
        local_log.concatf("%sabling bearing nullification on IIU %d.\n", ((*(str) == 'Y') ? "En":"Dis"), temp_byte);
      }
      break;

    case 'Q':
      local_log.concatf("Madgwick iterations to %d on all IIUs.\n", temp_byte);
      for (uint8_t i = 0; i < 17; i++) {
        iius[i].madgwickIterations(temp_byte);
      }
      break;



    case ',':
      IIU::max_quats_per_event = temp_byte;
      local_log.concatf("IIU class now runs a maximum of %u quats per event.\n", IIU::max_quats_per_event);
      break;

    case 'b':
      for (uint8_t i = 0; i < 17; i++) {
        iius[i].beta = (float)temp_byte * 0.1;
      }
      local_log.concatf("Beta value is now %f.\n", (double) (temp_byte * 0.1f));
      break;

    case 'L':
      for (uint8_t i = 0; i < 17; i++) {
        iius[i].setSampleRateProfile(temp_byte);
      }
      local_log.concatf("Moving to sample rate profile %d.\n", temp_byte);
      break;

    case 'o':
      for (uint8_t i = 0; i < 17; i++) {
        iius[i].setGyroBaseFiler(temp_byte);
      }
      local_log.concatf("Setting GYR base filter to %d.\n", temp_byte);
      break;

    case 'O':
      for (uint8_t i = 0; i < 17; i++) {
        iius[i].setAccelBaseFiler(temp_byte);
      }
      local_log.concatf("Setting ACC base filter to %d.\n", temp_byte);
      break;

    case 'a':
      if (255 == temp_byte) {
        refreshIMU();
      }
      else if (17 > temp_byte) {
        refreshIMU(temp_byte);
      }
      break;

    case 'd':
      switch (temp_byte) {
        case 255:
          event_legend_frame_ready.fireNow();  // Fire a single frame transmission.
          local_log.concat("We are manually firing the IMU frame broadcasts schedule.\n");
          break;
        case 254:
          event_legend_frame_ready.enableSchedule(true);  // Enable the periodic read.
          local_log.concat("Enabled frame broadcasts.\n");
          break;
        #if defined(__MANUVR_DEBUG)
          case 253:
            event_legend_frame_ready.printDebug(&local_log);
            break;
        #endif
        case 252:
          send_map_event();
          local_log.concat("We are manually firing the IMU frame broadcasts schedule.\n");
          break;
        default:
          if (temp_byte) {
            event_legend_frame_ready.alterSchedulePeriod(temp_byte*10);
            local_log.concatf("Set periodic frame broadcast to once every %dms.\n", temp_byte*10);
          }
          else {
            event_legend_frame_ready.enableSchedule(false);  // Disable the periodic read.
            local_log.concat("Disabled frame broadcasts.\n");
          }
          break;
      }
      break;

    case 'f':
      switch (temp_byte) {
        case 255:
          event_iiu_read.fireNow();
          local_log.concat("We are manually firing the IMU read schedule.\n");
          break;
        case 254:
          event_iiu_read.enableSchedule(true);
          local_log.concat("Enabled periodic readback.\n");
          break;
        default:
          if (temp_byte) {
            event_iiu_read.alterSchedulePeriod(temp_byte*10);
            local_log.concatf("Set periodic read schedule to once every %dms.\n", temp_byte*10);
          }
          else {
            event_iiu_read.enableSchedule(false);  // Disable the periodic read.
            local_log.concat("Disabled periodic readback.\n");
          }
          break;
      }
      break;

    case 'p':
      {
        parse_mule.concat(str);
        parse_mule.split(",");
        parse_mule.drop_position(0);
        uint8_t start = (temp_byte < 17) ? temp_byte   : 0;
        uint8_t stop  = (temp_byte < 17) ? temp_byte+1 : 17;
        int temp_int  = (parse_mule.count() > 0) ? parse_mule.position_as_int(0) : 255;
        for (uint8_t i = start; i < stop; i++) {
          if (255 != temp_int) {  // The user wants to make a change..
            iius[i].enableProfiling(temp_int ? true:false);
          }
          local_log.concatf("Profiling IIU %d: %sabled.\n", i, (iius[i].enableProfiling() ? "en":"dis"));
        }
      }
      break;

    case 'e':
      if (temp_byte < 17) {
        iius[temp_byte].dumpPreformedElements(&local_log);
      }
      break;


    default:
      EventReceiver::procDirectDebugInstruction(input);
      break;
  }

  flushLocalLog();
}
Ejemplo n.º 28
0
int8_t LegendManager::notify(ManuvrMsg* active_event) {
  int8_t return_value = 0;
  uint8_t temp_uint_8 = 0;

  /* Some class-specific set of conditionals below this line. */
  switch (active_event->eventCode()) {
    case DIGITABULUM_MSG_IMU_READ:
      iius[last_imu_read].readSensor();
      return_value++;
      break;


    case MANUVR_MSG_SESS_ESTABLISHED:
      event_legend_frame_ready.delaySchedule(1100);     // Enable the periodic frame broadcast.
      {
        ManuvrMsg *event = Kernel::returnEvent(DIGITABULUM_MSG_IMU_INIT);
        event->addArg((uint8_t) 4);  // Set the desired init stage.
        event->priority(0);
        raiseEvent(event);
      }
      event_iiu_read.delaySchedule(1000);  // Enable the periodic read after letting the dust settle.
      return_value++;
      break;

    case MANUVR_MSG_SESS_HANGUP:
      event_legend_frame_ready.enableSchedule(false);
      for (uint8_t i = 0; i < LEGEND_DATASET_IIU_COUNT; i++) {
        ManuvrMsg *event = Kernel::returnEvent(DIGITABULUM_MSG_IMU_INIT);
        event->addArg((uint8_t) 4);  // Set the desired init stage.
        event->priority(0);
        raiseEvent(event);
      }
      event_iiu_read.enableSchedule(false);    // Disable the periodic read.
      return_value++;
      break;

    case DIGITABULUM_MSG_IMU_INIT:
      /* This is a request (probably from elsewhere in this class) to move one-or-more
           IMUs into the given INIT stage. The argument forms are...
           None        A request to move all IMUs into the minimum meaningful INIT stage (INIT-1).
           uint8       A request to move all IMUs into the given INIT stage.
       */
      if (0 == active_event->argCount()) {
        if (last_imu_read > 16) {
          if (getVerbosity() > 1) local_log.concat("MSG_IMU_INIT: last_imu_read > 16.\n");
        }
        else {
          iius[last_imu_read].init();
          return_value++;
        }
      }
      else if (0 == active_event->getArgAs(&temp_uint_8)) {
        // If the arg was present, we interpret this as a specified INIT stage...
        if (temp_uint_8 > 16) {
          if (getVerbosity() > 1) local_log.concat("MSG_IMU_INIT had an IMU idx > 16.\n");
        }
        else {
          iius[last_imu_read].state_pass_through(temp_uint_8);
          return_value++;
        }
      }
      break;

    case DIGITABULUM_MSG_IMU_MAP_STATE:
      //if (0 == active_event->argCount()) {
        // No args means a request. Send it.
      //  send_map_event();
      //  return_value++;
      //}
      break;


    case DIGITABULUM_MSG_CPLD_RESET_COMPLETE:
      if (getVerbosity() > 3) local_log.concatf("Initializing IMUs...\n");
      // Range-bind everything....
      for (uint8_t i = 0; i < 17; i++) iius[i].rangeBind(true);

      // Fire the event to put the IMUs into INIT-1.
      //raiseEvent(Kernel::returnEvent(DIGITABULUM_MSG_IMU_INIT));
      return_value++;
      break;

    case DIGITABULUM_MSG_IMU_TAP:
      if (0 == active_event->argCount()) {
        // Somthing wants the thresholds for all configured taps.
      }
      else {
        // Otherwise, it means we've emitted the event. No need to respond.
      }
      break;

    case DIGITABULUM_MSG_IMU_QUAT_CRUNCH:
      if (0 == active_event->getArgAs(&temp_uint_8)) {
        if (temp_uint_8 > 16) {
          if (getVerbosity() > 1) local_log.concat("QUAT_CRUNCH had an IMU idx > 16.\n");
        }
        else {
          iius[temp_uint_8].MadgwickQuaternionUpdate();
        }
        return_value++;
      }
      else {
        if (getVerbosity() > 2) local_log.concatf("QUAT_CRUNCH handler (IIU %u) got a bad return from an Arg..\n", temp_uint_8);
      }
      break;

    default:
      return_value += EventReceiver::notify(active_event);
      break;
  }

  flushLocalLog();
  return return_value;
}
Ejemplo n.º 29
0
void CLogger::onFlush(CEvent & event)
{
	raiseEvent("onFlush", event);
}
Ejemplo n.º 30
0
void CLogger::onLog(CEvent & event)
{
	raiseEvent("onLog", event);
}