bool CMenu::CoreHandleKey(wchar_t key)
{
    if (CBaseScroll::CoreHandleKey(key))
        return true;

    switch (key)
    {
        case KEY_UP:
            Move(-1);
            return true;
        case KEY_DOWN:
            Move(1);
            return true;
        case KEY_LEFT:
            HScroll(-1, true);
            return true;
        case KEY_RIGHT:
            HScroll(1, true);
            return true;
        case KEY_PPAGE:
            Move(-ScrollFieldHeight()+1);
            return true;
        case KEY_NPAGE:
            Move(ScrollFieldHeight()-1);
            return true;
        default:
            if (IsEnter(key))
            {
                PushEvent(EVENT_CALLBACK);
                return true;
            }
            else if (isprint(key)) // Go to item which starts with typed character
            {
                // First try from current position
                TMenuList::iterator cur = m_MenuList.begin() + GetCurrent();
                TMenuList::iterator line = std::lower_bound(cur+1, m_MenuList.end(), key);
                
                if ((line == m_MenuList.end()) || (line->name[0] != key)) // Not found, start from begin
                    line = std::lower_bound(m_MenuList.begin(), cur, key);
                
                if ((line != m_MenuList.end()) && (line->name[0] == key))
                {
                    Move(SafeConvert<int>(std::distance(cur, line)));
                    PushEvent(EVENT_DATACHANGED);
                }
                
                return true;
            }
    }

    return false;
}
END_TEST

START_TEST (test_subscribe_and_push_event)
{
    printf("\n-----test_subscribe_and_push_event start-----\n");
    InitEventProcessor();
    int16_t stakeholderId = RegisterStakeholder("teststakeholder");
    eventSubscription_t subscription;
    subscription.stakeholderId = stakeholderId;
    subscription.eventType = EVENT_HEARTBEAT;
    subscription.callback = test_callback;
    Subscribe(subscription);

    struct timespec tms;
    clock_gettime(CLOCK_REALTIME, &tms);
    event_t* event = (event_t*)malloc(sizeof(event_t));
    event->timeStamp = tms.tv_sec;
    event->prio = 123;
    event->sourceId = stakeholderId;
    event->eventType = EVENT_HEARTBEAT;
    event->payloadSize = 0;
    event->payload = NULL;
    int rsp = PushEvent(event);
    
    int result = WaitForCallback();
    ck_assert_int_eq (result, 0);
    ck_assert_int_eq (rsp, EP_OK); 
    ck_assert_ptr_ne (sentToCallback, (event_t*)0);

    int equality = CompareEvent(event, sentToCallback); 
    ck_assert_int_eq (equality, 0);
    free(event);
    printf("-----test_subscribe_and_push_event done-----\n\n");
}
Exemple #3
0
void RetinueAddWarrior(struct Retinue* _Retinue, const struct Person* _Warrior) {
	if(RetinueIsWarrior(_Retinue, _Warrior) != 0 || _Retinue->Leader->Person == _Warrior)
		return;
	ArrayInsertSort_S(&_Retinue->Warriors, (void*)_Warrior, ObjectCmp);	
	_Retinue->FamilySz += FamilySize(_Warrior->Family);
	PushEvent(EVENT_NEWRECRUIT, _Retinue->Leader, (void*)_Warrior);
}
void CMenu::ClearEntries()
{
    m_MenuList.clear();
    m_iXOffset = m_iYOffset = m_iCursorLine = 0;
    RequestUpdate();
    PushEvent(EVENT_DATACHANGED);
}
bool CInputField::CoreHandleKey(wchar_t key)
{
    if (key == KEY_LEFT)
        Move(-1, true);
    else if (key == KEY_RIGHT)
        Move(1, true);
    else if (key == KEY_HOME)
        Move(0, false);
    else if (key == KEY_END)
        Move(m_Text.length(), false);
    else if (IsEnter(key))
        PushEvent(EVENT_CALLBACK);
    else if (key == KEY_DC)
        Delch(m_StartPos + m_CursorPos);
    else if (IsBackspace(key))
    {
        Delch(m_StartPos + m_CursorPos - 1);
        Move(-1, true);
    }
    else
    {
        if (ValidChar(&key))
            Addch(key);
        else
            return false;
    }
    
    return true;
}
void CMenu::DelEntry(const std::string &id)
{
    TMenuList::iterator line = std::lower_bound(m_MenuList.begin(), m_MenuList.end(), id);
    
    if ((line != m_MenuList.end()) && (line->id == id))
    {
        bool checklongest = (MBWidth(line->name) == m_LongestLine);
        
        if (line == m_MenuList.end()-1)
            Move(-1);
        else
            Move(1);
            
        m_MenuList.erase(line);
        
        if (checklongest)
        {
            m_LongestLine = 0;
            for (TMenuList::iterator it=m_MenuList.begin(); it!=m_MenuList.end(); it++)
                m_LongestLine = std::max(m_LongestLine, MBWidth(it->name));
        }
        
        PushEvent(EVENT_DATACHANGED);
    }
    else
        assert(false);
    
    RequestUpdate();
}
bool CWindowManager::CoreHandleEvent(CWidget *emitter, int event)
{
    if (CGroup::CoreHandleEvent(emitter, event))
        return true;
    
    if (event == EVENT_REQQUEUEDDRAW)
    {
        CWidget *focwidget = GetFocusedWidget();
        if (focwidget)
        {
            if ((focwidget != emitter) && !IsChild(emitter, focwidget))
                focwidget->RequestQueuedDraw();
        }
        
        return true;
    }
    else if (event == EVENT_REQUPDATE)
    {
        if (IsDirectChild(emitter, this))
        {
            m_WidgetQueue.push_back(emitter);
            UpdateLayout();
            PushEvent(EVENT_REQUPDATE);
            return true;
        }
    }
    
    return false;
}
Exemple #8
0
void axToggle::OnMouseLeftDown(const axPoint& pos)
{
    if(_selected && IsFlag(Flags::CANT_UNSELECT_WITH_MOUSE, _flags))
    {
        // Don't do anything.
    }
    else
    {
        // Only switch selection on toggle_on_left_down.
        if (IsFlag(Flags::CLICK_ON_LEFT_DOWN, _flags))
        {
            _selected = !_selected;
        }
        
        if(_selected)
        {
            _currentColor = &_info.selected_clicking;
        }
        else
        {
            _currentColor = &_info.clicking;
        }
        
        GrabMouse();
        
        if (IsFlag(Flags::CLICK_ON_LEFT_DOWN, _flags))
        {
            PushEvent(Events::BUTTON_CLICK, new Msg(this, _selected, _msg));
        }
        Update();
    }
}
Exemple #9
0
struct Plot* CreatePlot(int _Type, void* _Data, struct BigGuy* _Owner, struct BigGuy* _Target) {
	struct Plot* _Plot = (struct Plot*) malloc(sizeof(struct Plot));

	Assert(_Type >=0 && _Type < PLOT_SIZE);
	Assert(_Owner != NULL);
	_Plot->Type = _Type;
	ConstructLinkedList(&_Plot->Side[0]);
	ConstructLinkedList(&_Plot->SideAsk[0]);
	ConstructLinkedList(&_Plot->Side[1]);
	ConstructLinkedList(&_Plot->SideAsk[1]);
	PlotJoin(_Plot, PLOT_ATTACKERS, _Owner);
	PlotJoin(_Plot, PLOT_DEFENDERS, _Target);
	_Plot->SidePower[PLOT_ATTACKERS] = 0;
	_Plot->SidePower[PLOT_DEFENDERS] = 0;
	_Plot->Threat[PLOT_ATTACKERS] = 0;
	_Plot->Threat[PLOT_DEFENDERS] = 0;
	_Plot->WarScore = 0;
	_Plot->MaxScore = PLOT_OVERTHROW_MAXSCORE;
	_Plot->CurrActList = 0;
	_Plot->PlotData = _Data;
	_Plot->HasStarted = false;
	for(int i = 0; i < PLOT_SIDES; ++i) {
		for(int j = 0; j < BGSKILL_SIZE; ++j) {
			_Plot->StatMods[i][j] = 0;
		}
	}
//	CreateObject(&_Plot->Object, OBJECT_PLOT);
	PushEvent(EVENT_NEWPLOT, BigGuyHome(_Owner), _Plot);
	if(_Target != NULL)
		BigGuyPlotTarget(_Target, _Plot);
	RBInsert(&g_GameWorld.PlotList, _Plot);
	PLOT_CURRACTLIST(_Plot) = NULL;
	PLOT_PREVACTLIST(_Plot) = NULL;
	return _Plot;
}
Exemple #10
0
void axScrollBar::OnMouseLeftDragging(const axPoint& position)
{
	axPoint pos = position - GetAbsoluteRect().position;

	if(_sliderHeight < _sliderMaxHeight)
	{
		// m_sliderPosition move with mouse position.
		_sliderPos = pos.y - _yClickDelta;

		// If m_sliderPosition reach bottom, clip m_sliderPosition.
		if(_sliderPos + _sliderHeight > GetRect().size.y - _imgHeight - 1)
		{
			_sliderPos = GetRect().size.y - _imgHeight - 1 - _sliderHeight;
		}

		// Clip top.
		if(_sliderPos < _imgHeight)
        {
            _sliderPos = _imgHeight;
        }
			
		// Slider position ratio.
		_value = (_sliderPos - _imgHeight) / double(_sliderMaxHeight - _sliderHeight - 1);
        _value = axClamp<double>(_value, 0.0, 1.0);

        
        PushEvent(axScrollBarEvents::VALUE_CHANGE,
                  new axScrollBarMsg(this, std::string("")));
        
        _handle->SetScrollDecay(axPoint(0, _value * (_panelSize.y - GetRect().size.y)));

		Update();
	}
}
Exemple #11
0
static int SimulationThread(void *unused)
{
	dAllocateODEDataForThread(dAllocateFlagCollisionData);
	if (SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH))
	{
	 //SDL_perror("SDL_SetThreadPriority");
	}
	while (!Quit)
	{
		if (SDL_LockMutex(Mutex))
		{
		 SDL_perror("SDL_LockMutex");
		 break;
		}
		if (SDL_CondWait(Cond, Mutex))
		{
		 SDL_perror("SDL_CondWait");
		 break;
		}
		PushEvent(UPDATE);
		dSpaceCollide(Space, 0, &Near);
		dWorldStep(World, Step);
		dJointGroupEmpty(Group);
		SDL_UnlockMutex(Mutex);
	}
	dCleanupODEAllDataForThread();
	return 0;
}
bool C4InteractiveThread::ThreadLogDebug(const char *szMessage, ...)
{
	// format message
	va_list lst; va_start(lst, szMessage);
	StdStrBuf Msg = FormatStringV(szMessage, lst);
	// send to main thread
	return PushEvent(Ev_LogDebug, Msg.GrabPointer());
}
END_TEST

START_TEST (test_push_event_preinit)
{
    event_t *event = (event_t *)malloc(sizeof(event_t));
    int rsp = PushEvent(event);
    ck_assert_int_eq(rsp, EP_ENOINIT);
}
	void FD3DGPUProfiler::BeginFrame(FD3D12DynamicRHI* InRHI)
	{
		CurrentEventNode = NULL;
		check(!bTrackingEvents);
		check(!CurrentEventNodeFrame); // this should have already been cleaned up and the end of the previous frame

									   // latch the bools from the game thread into our private copy
		bLatchedGProfilingGPU = GTriggerGPUProfile;
		bLatchedGProfilingGPUHitches = GTriggerGPUHitchProfile;
		if (bLatchedGProfilingGPUHitches)
		{
			bLatchedGProfilingGPU = false; // we do NOT permit an ordinary GPU profile during hitch profiles
		}

		if (bLatchedGProfilingGPU)
		{
			// Issue a bunch of GPU work at the beginning of the frame, to make sure that we are GPU bound
			// We can't isolate idle time from GPU timestamps
			InRHI->IssueLongGPUTask();
		}

		// if we are starting a hitch profile or this frame is a gpu profile, then save off the state of the draw events
		if (bLatchedGProfilingGPU || (!bPreviousLatchedGProfilingGPUHitches && bLatchedGProfilingGPUHitches))
		{
			bOriginalGEmitDrawEvents = GEmitDrawEvents;
		}

		if (bLatchedGProfilingGPU || bLatchedGProfilingGPUHitches)
		{
			if (bLatchedGProfilingGPUHitches && GPUHitchDebounce)
			{
				// if we are doing hitches and we had a recent hitch, wait to recover
				// the reasoning is that collecting the hitch report may itself hitch the GPU
				GPUHitchDebounce--;
			}
			else
			{
				GEmitDrawEvents = true;  // thwart an attempt to turn this off on the game side
				bTrackingEvents = true;
				CurrentEventNodeFrame = new FD3D12EventNodeFrame(GetParentAdapter());
				CurrentEventNodeFrame->StartFrame();
			}
		}
		else if (bPreviousLatchedGProfilingGPUHitches)
		{
			// hitch profiler is turning off, clear history and restore draw events
			GPUHitchEventNodeFrames.Empty();
			GEmitDrawEvents = bOriginalGEmitDrawEvents;
		}
		bPreviousLatchedGProfilingGPUHitches = bLatchedGProfilingGPUHitches;

		FrameTiming.StartTiming();

		if (GEmitDrawEvents)
		{
			PushEvent(TEXT("FRAME"), FColor(0, 255, 0, 255));
		}
	}
END_TEST

START_TEST (test_two_subscribers_and_push_event)
{
    printf("\n-----test_two_subscribers_and_push_event start-----\n");
    sentToCallback = NULL;
    sentToCallback2 = NULL;
    InitEventProcessor();
    int16_t stakeholderId = RegisterStakeholder("teststakeholder");
    eventSubscription_t subscription;
    subscription.stakeholderId = stakeholderId;
    subscription.eventType = EVENT_HEARTBEAT;
    subscription.callback = &test_callback;
    Subscribe(subscription);

    stakeholderId = RegisterStakeholder("teststakeholder2");
    eventSubscription_t subscription2;
    subscription2.stakeholderId = stakeholderId;
    subscription2.callback = &test_callback2;
    subscription2.eventType = EVENT_HEARTBEAT;
    Subscribe(subscription2);

    struct timespec tms;
    clock_gettime(CLOCK_REALTIME, &tms);
    event_t* event = (event_t*)malloc(sizeof(event_t));
    event->timeStamp = tms.tv_sec;
    event->prio = 123;
    event->sourceId = stakeholderId;
    event->eventType = EVENT_HEARTBEAT;
    event->payloadSize = 0;
    event->payload = NULL;

    printf("pushing eventdata ptr=%p, timeStamp=%d, prio=%d, sourceId=%d, eventType=%d, payloadSize=%d, *payload=%p\n", event, event->timeStamp, event->prio, event->sourceId, event->eventType, event->payloadSize, event->payload);

    int rsp = PushEvent(event);
    
    printf("Done with PushEvent, moving on to asserts, waiting for callbacks to be called\n");
    fflush(stdout);

    int waitForCallback = WaitForCallback();
    ck_assert_int_eq (waitForCallback, 0);
    int waitForCallback2 = WaitForCallback2();
    ck_assert_int_eq (waitForCallback2, 0);
    ck_assert_int_eq (rsp, EP_OK); 
    printf("sentToCallback=%p sentToCallback2=%p\n", sentToCallback, sentToCallback2);
    ck_assert_ptr_ne (sentToCallback, (event_t*)0);
    ck_assert_ptr_ne (sentToCallback2, (event_t*)0);
    if ((sentToCallback - sentToCallback2) == 0) ck_abort_msg("Failed! Same event sent to both subscribers");


    int firstEventEqual = CompareEvent(event, sentToCallback); 
    ck_assert_int_eq (firstEventEqual, 0);
    int secondEventEqual = CompareEvent(event, sentToCallback2); 
    ck_assert_int_eq (secondEventEqual, 0);
    printf("-----test_two_subscribers_and_push_event done-----\n\n");
    free(event);
}
END_TEST

START_TEST (test_push_event_nolistener)
{
    InitEventProcessor();
    event_t *event = (event_t *)malloc(sizeof(event_t));
    event->eventType = EVENT_HEARTBEAT;
    int rsp = PushEvent(event);
    ck_assert_int_eq(rsp, EP_ENOLISTENER);
}
Exemple #17
0
void PlotThink(struct Plot* _Plot) {
    int _Diff = 0;
    int _ScoreDefender = 0;
    int _ScoreAttacker = 0;
    struct BigGuy* _Looser = NULL;

    if(DAY(g_GameWorld.Date) != 0)
        return;
    if(PlotTarget(_Plot) != NULL)
        _ScoreDefender = PlotWarScore(_Plot, &_Plot->Side[PLOT_DEFENDERS], &PLOT_CURRACTLIST(_Plot), &_Plot->Threat[PLOT_DEFENDERS]);
    _ScoreAttacker = PlotWarScore(_Plot, &_Plot->Side[PLOT_ATTACKERS], &PLOT_CURRACTLIST(_Plot), &_Plot->Threat[PLOT_ATTACKERS]);
    _Diff = _ScoreAttacker - _ScoreDefender;
    _Plot->WarScore += _Diff;
    if(PlotDefenderWon(_Plot)) {
        _Looser = PlotLeader(_Plot);
        goto warscore_end;
    }
    if(PlotAttackerWon(_Plot) != 0) {
        switch(_Plot->PlotType) {
        case PLOT_OVERTHROW:
            PushEvent(EVENT_NEWLEADER, PlotTarget(_Plot), PlotLeader(_Plot));
            break;
        case PLOT_PASSPOLICY:
            PushEvent(EVENT_NEWPOLICY, PlotLeader(_Plot)->Person->Family->HomeLoc->Government, _Plot->PlotData);
            break;
        case PLOT_CHANGEPOLICY:
            PushEvent(EVENT_CHANGEPOLICY, PlotLeader(_Plot)->Person->Family->HomeLoc->Government, _Plot->PlotData);
            break;
        case PLOT_SLANDER:
            PushEvent(EVENT_SLANDER, NULL, NULL);
            break;
        }
        _Looser = PlotTarget(_Plot);
        goto warscore_end;
    }
    PLOT_SWAPACTLIST(_Plot);
    for(struct PlotAction* _Action = PLOT_CURRACTLIST(_Plot); _Action != NULL; _Action = _Action->Next)
        DestroyPlotAction(_Action);
    PLOT_CURRACTLIST(_Plot) = NULL;
    return;
warscore_end:
    PushEvent(EVENT_ENDPLOT, _Plot, _Looser);
}
bool CGroup::CoreHandleEvent(CWidget *emitter, int event)
{
    if (event == EVENT_REQFOCUS)
    {
        FocusWidget(emitter);
        PushEvent(EVENT_REQFOCUS);
        return true;
    }

    return CWidget::CoreHandleEvent(emitter, event);
}
void CWidget::Enable(bool e)
{
    if (e != m_bEnabled)
    {
        m_bEnabled = e;
        PushEvent(EVENT_REQUPDATE);
        
        if (m_pParent)
            m_pParent->EnableWidget(this, e);
    }
}
void CMenu::Move(int n)
{
    int lines = SafeConvert<int>(m_MenuList.size()), curyoffset = m_iYOffset, curcursor = m_iCursorLine;
    int h = Height()-2;

    if (n < 0)
    {
        int nabs = abs(n);
        if (nabs > m_iCursorLine)
        {
            int rest = (nabs - m_iCursorLine);
            
            if (rest > m_iYOffset)
            {
                m_iYOffset = 0;
                VScroll(0, false);
            }
            else
                m_iYOffset -= rest;
            
            m_iCursorLine = 0;
        }
        else
            m_iCursorLine -= nabs;
    }
    else
    {
        int newpos = m_iCursorLine + n;
        if (((newpos+m_iYOffset) >= lines) || (newpos < m_iCursorLine)) // Don't go past menu size and prevent overflows
            newpos = ((lines-1) - m_iYOffset);
        
        m_iCursorLine = newpos;
    }

    if (m_iCursorLine >= h)
    {
        m_iYOffset += (m_iCursorLine - (h-1));
        
        int max = lines - h;
        if (m_iYOffset > max)
            m_iYOffset = max;
                
        m_iCursorLine = h-1;
    }
    
    if (curyoffset != m_iYOffset)
        VScroll(m_iYOffset, false);
    
    if ((curyoffset != m_iYOffset) || (curcursor != m_iCursorLine))
    {
        RequestQueuedDraw();
        PushEvent(EVENT_DATACHANGED);
    }
}
void CInputField::Delch(TSTLStrSize pos)
{
    if ((m_Text.empty()) || (pos >= SafeConvert<TSTLStrSize>(utf8::distance(m_Text.begin(), m_Text.end()))))
        return;
    
    std::string::iterator start = m_Text.begin(), end;
    utf8::advance(start, pos, m_Text.end());
    utf8::next(end = start, m_Text.end());
    m_Text.erase(start, end);
    RequestQueuedDraw();
    PushEvent(EVENT_DATACHANGED);
}
Exemple #22
0
LRESULT WrapperSystem::WindowHookFuncGetMessage( int nCode, WPARAM wParam, LPARAM lParam ) {

	MSG * cwpData = ( MSG * )lParam;

	if( cwpData->message == WM_INPUT ) {

		byte lpb[ 48 ];
		RAWINPUT * raw;
		DWORD dwRet;
		UINT dwSize = 48;
    
		dwRet = GetRawInputData( ( HRAWINPUT )cwpData->lParam, RID_INPUT, lpb, &dwSize, sizeof( RAWINPUTHEADER ) );

		raw = ( RAWINPUT * )lpb;

		if( raw->header.dwType == RIM_TYPEMOUSE && !raw->data.mouse.usFlags ) {

			DI_HID_MouseEvent mouseEvent = raw->data.mouse;
			lastEventTime = GetTickCount( );
			mouseEvent.SetTime( lastEventTime );
			DI_HID_MouseEvent mouseEventWrap;

			if( mouseEvent.Wrap( mouseEventWrap, type_axis_x ) ) PushEvent( mouseEventWrap );
			if( mouseEvent.Wrap( mouseEventWrap, type_axis_y ) ) PushEvent( mouseEventWrap );
			if( mouseEvent.Wrap( mouseEventWrap, type_axis_z ) ) PushEvent( mouseEventWrap );
			if( mouseEvent.Wrap( mouseEventWrap, type_button_1 ) ) PushEvent( mouseEventWrap );
			if( mouseEvent.Wrap( mouseEventWrap, type_button_2 ) ) PushEvent( mouseEventWrap );
			if( mouseEvent.Wrap( mouseEventWrap, type_button_3 ) ) PushEvent( mouseEventWrap );
			if( mouseEvent.Wrap( mouseEventWrap, type_button_4 ) ) PushEvent( mouseEventWrap );
			if( mouseEvent.Wrap( mouseEventWrap, type_button_5 ) ) PushEvent( mouseEventWrap );
			if( mouseEvent.Wrap( mouseEventWrap, type_button_6 ) ) { PushEvent( mouseEventWrap ); PushEvent( button6ShutdownEvent ); }
			if( mouseEvent.Wrap( mouseEventWrap, type_button_7 ) ) { PushEvent( mouseEventWrap ); PushEvent( button7ShutdownEvent ); }

			return TRUE;
		}
	}

	if( nCode < 0 ) return CallNextHookEx( 0, nCode, wParam, lParam );
	return TRUE;
}
bool CButton::CoreHandleKey(wchar_t key)
{
    if (CBox::CoreHandleKey(key))
        return true;
    
    if (IsEnter(key))
    {
        PushEvent(EVENT_CALLBACK);
        return true;
    }
    
    return false;
}
Exemple #24
0
void axToggle::OnMouseLeftUp(const axPoint& pos)
{
	if (IsGrabbed())
	{
		UnGrabMouse();
		
        // If mouse release if still on the toggle.
		if (IsMouseHoverWindow())
		{
            // Only invert selection on toggle_on_left_up.
            if (!IsFlag(Flags::CLICK_ON_LEFT_DOWN, _flags))
            {
                _selected = !_selected;
            }
            
            if (_selected)
            {
                _currentColor = &_info.selected_hover;
            }
            else
            {
                _currentColor = &_info.hover;
            }
			
			_nCurrentImg = axTOG_HOVER;
            
            // If toggle on left up.
            if (!IsFlag(Flags::CLICK_ON_LEFT_DOWN, _flags))
            {
                PushEvent(Events::BUTTON_CLICK, new Msg(this, _selected, _msg));
            }
		}
		else
		{
			if (_selected)
			{
				_currentColor = &_info.selected;
				_nCurrentImg = axTOG_SELECTED;
			}
			else
			{
				_currentColor = &_info.normal;
				_nCurrentImg = axTOG_NORMAL;
			}
		}

		Update();
	}
}
Exemple #25
0
void FASTRUN Ui::Poll() {

  uint32_t now = ++ticks_;
  uint16_t button_state = 0;

  for (size_t i = 0; i < CONTROL_BUTTON_LAST; ++i) {
    if (buttons_[i].Poll())
      button_state |= control_mask(i);
  }

  for (size_t i = 0; i < CONTROL_BUTTON_LAST; ++i) {
    auto &button = buttons_[i];
    if (button.just_pressed()) {
      button_press_time_[i] = now;
    } else if (button.released()) {
      if (now - button_press_time_[i] < kLongPressTicks)
        PushEvent(UI::EVENT_BUTTON_PRESS, control_mask(i), 0, button_state);
      else
        PushEvent(UI::EVENT_BUTTON_LONG_PRESS, control_mask(i), 0, button_state);
    }
  }

  encoder_right_.Poll();
  encoder_left_.Poll();

  int32_t increment;
  increment = encoder_right_.Read();
  if (increment)
    PushEvent(UI::EVENT_ENCODER, CONTROL_ENCODER_R, increment, button_state);

  increment = encoder_left_.Read();
  if (increment)
    PushEvent(UI::EVENT_ENCODER, CONTROL_ENCODER_L, increment, button_state);

  button_state_ = button_state;
}
Exemple #26
0
void MyButton::OnClickButton(const axButtonMsg& msg)
{
    if(_active)
    {
        _led->SetActive(false);
    }
    else
    {
        _led->SetActive(true);
    }
    
    _active = !_active;
    
    PushEvent(2, new axButtonMsg(msg));
}
bool CBox::CoreHandleEvent(CWidget *emitter, int event)
{
    if (IsChild(emitter, this))
    {
        if (event == EVENT_REQUPDATE)
        {
            UpdateLayout();
            PushEvent(event);
            
            if (!GetParentWidget())
                RequestQueuedDraw();
            
            return true;
        }
    }
    
    return CGroup::CoreHandleEvent(emitter, event);
}
Exemple #28
0
	void AppManager::CloseFullScreenApp(const std::string& app_name)
	{
		std::map<std::string, eos::AppLoader>::iterator it = _appLoaders.find(app_name);
		
		if(it == _appLoaders.end()) {
			return;
		}
		
		ax::Window::Backbone* handle = it->second.GetHandle();
		
		if(handle == nullptr) {
			return;
		}
		
		eos::Frame* frame = static_cast<eos::Frame*>(handle);
		frame->UnSetFullScreen(ax::Rect(100, 100, 500, 500));
		
		PushEvent(UN_FULLSCREEN_FRAME, new eos::Frame::Msg(frame));
	}
Exemple #29
0
void Application::CreateFileList(std::vector<std::string> const & a_items
                               , char const * a_name
                               , int * a_currentItem)
{
  if (a_items.size() == 0)
  {
    ImGui::ListBox(a_name, a_currentItem, nullptr, 0, 5);
    *a_currentItem = -1;
  }
  else
  {
    char * * pItems = new char*[a_items.size()];
    for (int i = 0; i < a_items.size(); ++i)
    {
      pItems[i] = new char[a_items[i].size() + 1]();
      memcpy(pItems[i], a_items[i].data(), a_items[i].size() * sizeof(char));
    }
    if (a_items.size() == 0)
    {
      *a_currentItem = -1;
    }
    ImGui::ListBox(a_name, a_currentItem, (char const **)pItems, (int)a_items.size(), 5);

    if (ImGui::BeginPopupContextItem("item context menu"))
    {
      if (ImGui::Selectable("Delete selected"))
      {
        if (*a_currentItem >= 0)
        {
          Event_DeleteFile e;
          e.SetFileName(m_projectPath + a_items[*a_currentItem]);
          PushEvent(e);
        }
      }
      ImGui::EndPopup();
    }
    for (int i = 0; i < a_items.size(); ++i)
    {
      delete[] pItems[i];
    }
    delete[] pItems;
  }
}
void CMenu::Select(const std::string &id)
{
    if (!GetWin())
    {
        // Can't move cursor before being initialized
        m_QueuedSelection = id;
        return;
    }

    TMenuList::iterator line = std::lower_bound(m_MenuList.begin(), m_MenuList.end(), id);

    if ((line != m_MenuList.end()) && (line->id == id))
    {
        TMenuList::iterator cur = m_MenuList.begin() + GetCurrent();
        Move(SafeConvert<int>(std::distance(cur, line)));
        PushEvent(EVENT_DATACHANGED);
    }
    else
        assert(false);
}