void
GUIApplicationWindow::eventOccured() {
    while (!myEvents.empty()) {
        // get the next event
        GUIEvent* e = static_cast<GUIEvent*>(myEvents.top());
        myEvents.pop();
        // process
        switch (e->getOwnType()) {
            case EVENT_SIMULATION_LOADED:
                handleEvent_SimulationLoaded(e);
                break;
            case EVENT_SIMULATION_STEP:
                if (myRunThread->simulationAvailable()) { // avoid race-condition related crash if reload was pressed
                    handleEvent_SimulationStep(e);
                }
                break;
            case EVENT_MESSAGE_OCCURED:
            case EVENT_WARNING_OCCURED:
            case EVENT_ERROR_OCCURED:
                handleEvent_Message(e);
                break;
            case EVENT_SIMULATION_ENDED:
                handleEvent_SimulationEnded(e);
                break;
            default:
                break;
        }
        delete e;
    }
    myToolBar2->forceRefresh();
    myToolBar3->forceRefresh();
}
Beispiel #2
0
static inline void CallEvent(gpointer data, gpointer user_data)
{
	GUIEvent *event = (GUIEvent *) data;

	if (event->type == GPOINTER_TO_INT(user_data))
		event->func();
}
Beispiel #3
0
int EndGameMenu::Run()
{
	this->mSets[this->mCurrentSet].AddSetToRenderer(this->mGe);
	this->mIsRunning = true;
	bool IsClicked = false;
	bool mousePressed = false;
	GUIEvent *returnEvent = NULL;
	CursorControl cc;
	cc.SetVisibility(true);
	while(this->mGe->GetKeyListener()->IsClicked(1))
	{

	}

	while(this->mIsRunning)
	{
		/*If mouse is clicked*/
		if(IsClicked && !mousePressed)
		{
			mousePressed = true;
		}
		this->mGe->Update();
		IsClicked = this->mGe->GetKeyListener()->IsClicked(1);

		D3DXVECTOR2 mousePos;
		mousePos = this->mGe->GetKeyListener()->GetMousePosition();
		returnEvent = this->mSets[this->mCurrentSet].UpdateAndCheckCollision(mousePos.x, mousePos.y, IsClicked, this->mGe);

		if(returnEvent != NULL)
		{
			if(returnEvent->GetEventMessage() == "ChangeSetEvent")
			{
				ChangeSetEvent* temp = (ChangeSetEvent*)returnEvent;
				int whatSet = temp->GetSet();
				if(whatSet == QUITGAME)
				{
					
					this->mSets[this->mCurrentSet].RemoveSetFromRenderer(this->mGe);
					this->mIsRunning = false;
					return QUITGAME;
				}
				if(whatSet == PLAYAGAIN)
				{
					
					this->mSets[this->mCurrentSet].RemoveSetFromRenderer(this->mGe);
					this->mIsRunning = false;
					return PLAYAGAIN;
				}
			}
		}
		if(!IsClicked && mousePressed)
		{
			mousePressed = false;
		}
		if(!this->mGe->isRunning())
			this->mIsRunning = false;
	}
	cc.SetVisibility(false);
	return true;
}
void E_scene_main_game::actionPerformed(GUIEvent &evt)
{
	
	
	const std::string &callbackString  = evt.getCallbackString();
	GUIRectangle      *sourceRectangle = evt.getEventSource();
	int                widgetType      = sourceRectangle->getWidgetType();

	if(widgetType == WT_BUTTON)
	{
		GUIButton   *button = (GUIButton*)sourceRectangle;
		if(button->isClicked())
		{
			
			if(callbackString == "QuitMainGame")
			{
				scene_to_go=GAME_SCENE_MAIN_MENU;
				init_fade_in();
				fade_in=true;
			}
			
			if (callbackString == "ResetCamera")
			{
				chessboard->resetCameraPos();
			}
			
			if (callbackString == "okButtonPromotion")
			{
				player_do_a_move(piece_for_promotion);
				pGlobalInfos->GUI_displayPromotion(false);
				promotion=false;
			}
		}
	}
	else if (widgetType == WT_RADIO_BUTTON)
	{
		GUIRadioButton *button = (GUIRadioButton*)sourceRectangle;
		
		if(button->isClicked())
		{
			
			if(callbackString == "queen")
				piece_for_promotion='q';
			
			if(callbackString == "rook")
				piece_for_promotion='r';
			
			if(callbackString == "bishop")
				piece_for_promotion='b';
			
			if(callbackString == "knight")
				piece_for_promotion='n';
		}
		
	}
}
void MainMenuScene::actionPerformed(GUIEvent &evt)
{
  const String &callbackString  = evt.getCallbackString();
  GUIRectangle *sourceRectangle = evt.getEventSource();
  int           widgetType      = sourceRectangle->getWidgetType();
  
  if (widgetType == BUTTON)
  {
    GUIButton *button = (GUIButton*) sourceRectangle;
    
    if (button->isClicked())
      sceneController.execute(callbackString);
  }
}
Beispiel #6
0
	// ------------------------------------------------------------------
	void GUIComboBox::onMouseDown(GUIEvent& evt)
	{
		Vec2 mousePos = evt.getMousePos() - mPos;
		mousePos.setX(mousePos.getX() - mSize.getX() + 30);
		mousePos.setY(mousePos.getY() - mSize.getY() / 2);

		mExpandDown = (2 <= mousePos.getX() && mousePos.getX() <= 22 && -3 <= mousePos.getY() && mousePos.getY() <= 6);
	}
Beispiel #7
0
void EventsHandler::actionPerformed(GUIEvent &evt)
{
static int num  = 0;
  const std::string &callbackString  = evt.getCallbackString();
  GUIRectangle      *sourceRectangle = evt.getEventSource(),
                    *parent          = sourceRectangle ? sourceRectangle->getParent() : NULL;
  int                widgetType      = sourceRectangle->getWidgetType();

  if(widgetType == WT_SLIDER )
  {
    GUISlider  *slider = (GUISlider*)sourceRectangle;
    if(callbackString == "s1" || callbackString == "s2")
    {
      sprintf(charBuffer, "%s: %.2f",  (callbackString == "s1") ? "Slider 1" : "Slider 2",  slider->getProgress());
      slider->setLabelString(charBuffer);
    }

    if(callbackString == "red")   red   = slider->getProgress();
    if(callbackString == "blue")  blue  = slider->getProgress();
    if(callbackString == "green") green = slider->getProgress();
  }

  if(widgetType == WT_BUTTON)
  {
    GUIButton   *button = (GUIButton*)sourceRectangle;
    if(callbackString == "exit")
      if(button->isClicked())
        exit(0);
  }

  if(widgetType == WT_COMBO_BOX)
  {
    GUIComboBox  *comboBox = (GUIComboBox*)sourceRectangle;
    if(callbackString == "cb1")
    if(comboBox->getSelectedItem() == std::string("Select this item to exit"))
      exit(0);
  }

  if(widgetType == WT_RADIO_BUTTON)
  {
    GUIRadioButton   *radioButton = (GUIRadioButton*)sourceRectangle;
  }

}
Beispiel #8
0
void GUITabbedPanel::actionPerformed(GUIEvent &evt)
{
  GUIEventListener *eventsListener  = parent->getEventsListener();
  const NSString     &cbs             = evt.getCallbackString();
  GUIRectangle     *sourceRectangle = evt.getEventSource();
  int               widgetType      = sourceRectangle->getWidgetType();

  if((widgetType == BUTTON) && sourceRectangle->isPressed())
  {
    const Widgets &widgets = lowerPanel->getWidgets(),
                  &buttons = upperPanel->getWidgets();
    int   target = atoi(sourceRectangle->getCallbackString()),
          count  = int(widgets.size());
    for(int t = 0; t < count; t++)
    {
      widgets[t]->setVisible(t == target);
      ((GUIAlphaElement*)buttons[t])->setMinAlpha((t == target) ? 1.0f : 0.5f);
    }
  }
}
Beispiel #9
0
	// ------------------------------------------------------------------
	void GUIComboBox::onMouseMove(GUIEvent& evt)
	{
		Vec2 mousePos = evt.getMousePos() - mPos;
		mousePos.setX(mousePos.getX() - mSize.getX() + 30);
		mousePos.setY(mousePos.getY() - mSize.getY() / 2);

		if (2 <= mousePos.getX() && mousePos.getX() <= 22 && -3 <= mousePos.getY() && mousePos.getY() <= 6) {
			mExpandOver = true;
		} else {
			mExpandOver = mExpandDown = false;
		}
		
		mousePos = evt.getMousePos() - mPos;

		if (mExpand && mousePos.getY() >= mSize.getY()) {
			Font* ft = Resources::inst().get<Font> (mFontName);
			float y = evt.getMousePos().getY() - mPos.getY() - mSize.getY();
			mHoverItem = y / (ft->getHeight() + 3);
			mOverItem = 0 <= mHoverItem && mHoverItem < mItems.size();
		} else {
			mOverItem = false;
		}
	}
Beispiel #10
0
	// ------------------------------------------------------------------
	void GUIComboBox::onMouseUp(GUIEvent& evt)
	{
		Vec2 mousePos = evt.getMousePos() - mPos;
		mousePos.setX(mousePos.getX() - mSize.getX() + 30);
		mousePos.setY(mousePos.getY() - mSize.getY() / 2);

		if (2 <= mousePos.getX() && mousePos.getX() <= 22 && -3 <= mousePos.getY() && mousePos.getY() <= 6) {
			mExpandDown = false;
			mExpand = !mExpand;
		}

		if (mOverItem) {
			mSelectedItem = mHoverItem;
		}
	}
Beispiel #11
0
bool InGameMenu::Run()
{
	this->mSets[IGNBACKGROUND].AddSetToRenderer(this->mGe);
	this->mSets[INGAMEMENU].AddSetToRenderer(this->mGe);
	this->mIsRunning = true;
	bool IsClicked = false;
	bool mousePressed = false;
	GUIEvent *returnEvent = NULL;
	this->mGe->GetKeyListener()->KeyUp(VK_ESCAPE);

	CursorControl cc;
	cc.SetVisibility(true);

	while(this->mIsRunning)
	{
		/*If mouse is clicked*/
		if(IsClicked && !mousePressed)
		{
			mousePressed = true;
		}
		this->mGe->Update();
		IsClicked = this->mGe->GetKeyListener()->IsClicked(1);

		D3DXVECTOR2 mousePos;
		mousePos = this->mGe->GetKeyListener()->GetMousePosition();
		returnEvent = this->mSets[this->mCurrentSet].UpdateAndCheckCollision(mousePos.x, mousePos.y, IsClicked, this->mGe);
		if(returnEvent == NULL)
			returnEvent = this->mSets[this->mSubSet].UpdateAndCheckCollision(mousePos.x, mousePos.y, IsClicked, this->mGe);

		if(returnEvent != NULL)
		{
			if(returnEvent->GetEventMessage() == "ChangeSetEvent")
			{
				ChangeSetEvent* temp = (ChangeSetEvent*)returnEvent;
				int whatSet = temp->GetSet();
				if(whatSet == IGNQUIT)
				{
					
					this->mSets[this->mCurrentSet].RemoveSetFromRenderer(this->mGe);
					this->mSets[this->mSubSet].RemoveSetFromRenderer(this->mGe);
					this->mIsRunning = false;
					return false;
				}
				if(whatSet == IGNRESUME)
				{
					
					this->mSets[this->mCurrentSet].RemoveSetFromRenderer(this->mGe);
					this->mSets[this->mSubSet].RemoveSetFromRenderer(this->mGe);
					this->mIsRunning = false;
					return true;
				}
				if(whatSet == IGNOPTIONS)
				{
					this->mSets[this->mCurrentSet].RemoveSetFromRenderer(this->mGe);
					this->mSets[this->mSubSet].RemoveSetFromRenderer(this->mGe);
					this->mCurrentSet = IGNOPTIONS;
					this->mSets[this->mCurrentSet].AddSetToRenderer(this->mGe);
					this->mSets[this->mSubSet].AddSetToRenderer(this->mGe);
				}
				if(whatSet == INGAMEMENU)
				{
					this->mSets[this->mCurrentSet].RemoveSetFromRenderer(this->mGe);
					this->mSets[this->mSubSet].RemoveSetFromRenderer(this->mGe);
					this->mCurrentSet = INGAMEMENU;
					this->mSets[this->mCurrentSet].AddSetToRenderer(this->mGe);
				}
			}
			else if(returnEvent->GetEventMessage() == "ChangeSubSetEvent")
			{
				this->mSets[this->mSubSet].RemoveSetFromRenderer(this->mGe);

				ChangeSubSetEvent* tempReturnEvent = (ChangeSubSetEvent*)returnEvent;
				int tempEventSet = tempReturnEvent->GetSet();

				if(tempEventSet == IGNOPTIONS_SOUND)
				{
					CheckBox* temp = this->mSets[IGNOPTIONS_SOUND].GetCheckBox("Sound");
					temp->SetChecked(GameOptions::isPlaying);
				}
				int set = tempReturnEvent->GetSet();
				this->mSubSet = set;
				this->mSets[this->mSubSet].AddSetToRenderer(this->mGe);
				int menuChangeTime = 50;
				while(menuChangeTime > 0)
					menuChangeTime -= (int)this->mGe->Update();
			}
			else if(returnEvent->GetEventMessage() == "ChangeOptionEvent")
			{
				ChangeOptionEvent* tempReturnEvent = (ChangeOptionEvent*)returnEvent;
				if(tempReturnEvent->GetOption() == "Sound")
				{
					if(tempReturnEvent->GetValue() == "true")
					{
						GameOptions::songPlaying->Unmute();
						GameOptions::isPlaying = true;
					}
					else
					{
						GameOptions::songPlaying->Mute();
						GameOptions::isPlaying = false;
					}
				}
			}
		}
		if(!IsClicked && mousePressed)
		{
			mousePressed = false;
		}
		if(!this->mGe->isRunning())
			this->mIsRunning = false;
	}
	cc.SetVisibility(false);
	return true;
}