Exemplo n.º 1
0
// -----------------------------------------------------------------
// Name : onButtonEvent
// -----------------------------------------------------------------
guiObject * guiButton::onButtonEvent(ButtonAction * pEvent)
{
    if ((pEvent->eButton != Button1 && (pEvent->eButton != Button2 || !m_bCatchButton2Events)) || !m_bEnabled || !m_bVisible) {
        return NULL;
    }
    switch (pEvent->eEvent)
    {
    case Event_Down:
    {
        m_bMouseDown = true;
        m_bMouseOver = true;
        m_bClickState = true;
// TODO audio        AudioManager::getInstance()->playSound(SOUND_CLICK);
        if (m_bMultiClicks)
        {
            m_fMultiClicksTimer = MULTICLICKS_TIMER_FIRST;
            memcpy(&m_MultiClicksEvent, pEvent, sizeof(ButtonAction));
            bool bClose = doClick(pEvent);
            return bClose ? NULL : this;
        }
        return this;
    }
    case Event_Up:
    {
        m_bMouseDown = false;
        m_bClickState = false;
        bool bClose = false;
        if (!m_bMultiClicks && m_bMouseOver) {
            bClose = doClick(pEvent);
        }
        return bClose ? NULL : this;
    }
    case Event_Drag:
    {
        m_bClickState = m_bMouseOver = isAt(pEvent->xPos - pEvent->xOffset, pEvent->yPos - pEvent->yOffset);
        return this;
    }
    case Event_DoubleClick:
    {
        if (m_bCatchDoubleClicks)
        {
            bool bClose = false;
            if (m_bMouseOver && m_pOwner != NULL) {
                bClose = !m_pOwner->onButtonEvent(pEvent, this);
            }
            return bClose ? NULL : this;
        }
        break;
    }
    default:
        break;
    }
    return NULL;
}
Exemplo n.º 2
0
DealButton::DealButton(int rowNum, const QString& text, QWidget* parent)
: QPushButton(text, parent)
, m_rowNum(rowNum)
{
  connect(this, SIGNAL(clicked()), this, SLOT(doClick()));
}
Exemplo n.º 3
0
void MenuState::update(double dt){
	entityx::ComponentHandle<Drawable> drawable;
	for(entityx::Entity entity: m_entities.entities_with_components(drawable)){
		(void)entity;
		drawable->m_anim.set_y_index(0);
	}

	int x, y;
	SDL_GetMouseState(&x, &y);
	int w, h;
	SDL_GetWindowSize(m_game->window(), &w, &h);

	float real_div_logic_h = h / (float)HEIGHT;
	float real_div_logic_w = w / (float)WIDTH;
	float aspect = (float)HEIGHT/WIDTH;
	float other_size;

	float rel_w, rel_h;
	if(real_div_logic_h < real_div_logic_w)
	{
	  rel_h = (float)y / h;
	  other_size = h / aspect;
	  rel_w = (float(x)-((float(w)-other_size)/2.0)) / other_size;
	}
	else
	{
	  rel_w = (float)x / w;
	  other_size = aspect * w;
	  rel_h = (float(y)-((float(h)-other_size)/2.0)) / other_size;
	}

  x = rel_w * WIDTH;
  y = rel_h * HEIGHT;

	entityx::Entity ent;
	bool hit_entity = find_target(x, y, ent);
	if(hit_entity) {
		auto d = ent.component<Drawable>();
		d->m_anim.set_y_index(1);
	}

	SDL_Event e;
	while (SDL_PollEvent(&e)) {
		if (e.type == SDL_QUIT) {
			m_game->shutdown();
		}
		else if (e.type == SDL_KEYDOWN) {
			if (e.key.keysym.sym == SDLK_ESCAPE) {
				m_game->shutdown();
			} else if (e.key.keysym.sym == SDLK_F3) {
				m_game->toggle_debug_mode();
			}
		}
		else if (hit_entity && e.type == SDL_MOUSEBUTTONUP){
			if(e.button.button == SDL_BUTTON_LEFT){
				auto c = ent.component<MenuItem>();
				if(c) {
					c->doClick(m_game);
				}
			}
		}
	}

	draw(dt);
}