void GameObject::update() { if(Mouse::checkCollision(position,size)) { onMouseOver(); if(_event.type == SDL_MOUSEBUTTONDOWN) { if(_event.button.button == SDL_BUTTON_LEFT) { if(!_onMouseDown) { onMouseClickLeft(); _onMouseDown=true; } } if(_event.button.button == SDL_BUTTON_RIGHT) { onMouseClickRight(); } } else _onMouseDown=false; } else onMouseNotOver(); }
bool AGameController::handleEvent(sf::Event const& event) { switch (event.type) { case sf::Event::MouseMoved: return onMouseOver(event); case sf::Event::MouseButtonPressed: return onMouseClick(event); case sf::Event::MouseButtonReleased: return onMouseClickReleased(event); case sf::Event::KeyPressed: return onKeyPressed(event); case sf::Event::Closed: return onClose(event); case sf::Event::TextEntered: return onText(event); default: break; } return false; }
void InteractiveObject::handleEvent(const Event &event) { if (event.type == MouseEvent::MOUSE_MOVE || event.type == MouseEvent::CLICK || event.type == MouseEvent::MOUSE_DOWN || event.type == MouseEvent::MOUSE_UP) { MouseEvent* st = (MouseEvent*)(&event); bool hit = hitTestPoint(st->getX(), st->getY()); if (event.type == MouseEvent::MOUSE_MOVE) { onMouseMove(event); if (isHovered) { if (!hit) { onMouseOut(event); dispatchEvent(MouseEvent(this, MouseEvent::MOUSE_OUT, st->getX(), st->getY())); isHovered = !isHovered; } } else { if (hit) { onMouseOver(event); dispatchEvent(MouseEvent(this, MouseEvent::MOUSE_OVER, st->getX(), st->getY())); isHovered = !isHovered; } } } else if (hit) { dispatchEvent(MouseEvent(this, event.type, st->getX(), st->getY())); } } }
void ImageKnob::paint(Graphics &g) { if(isMouseOver() && !isMouseButtonDown()) { onMouseOver(); } const int y = (int)(filmstripImageCount * getValue()) * knobWidth; knobArea.setY(y); const Image knobFrame = imageStates->normal.getClippedImage(knobArea); const Image resizedKnobFrame = knobFrame.rescaled(knobWidth, knobWidth, Graphics::highResamplingQuality); g.drawImageAt(resizedKnobFrame, 0, 0); }
DGLPixelRectangleView::DGLPixelRectangleView(QWidget* _parent) : m_GraphicsView(_parent), m_Scene(NULL) { m_Ui = new Ui::DGLPixelRectangleView(); m_Ui->setupUi(this); m_Ui->verticalLayout->insertWidget(0, &m_GraphicsView); m_Ui->widgetColor->setStyleSheet( "QWidget{background-color: palette(background);}"); QPalette pal; pal.setColor(m_Ui->widgetColor->backgroundRole(), QColor(0, 0, 0, 0)); m_Ui->widgetColor->setPalette(pal); m_Ui->widgetColor->setAutoFillBackground(true); // process Mouse events ourselves CONNASSERT(&m_GraphicsView, SIGNAL(onMouseOver(QPoint)), this, SLOT(onMouseOver(QPoint))); CONNASSERT(&m_GraphicsView, SIGNAL(onMouseLeft()), this, SLOT(onMouseLeft())); }
void ContextMenu::processMouseCallback(const MouseEvent &evt, std::deque<std::string> address) { static MenuHolder *holder = MenuHolder::getInstance(); address.push_front(_label); if (_parentMenu == NULL) { if (evt.getState() == MouseEvent::UP) { holder->closeAllMenus(); onMouseClick(evt, address); onMenuAccessed(address); } else if (evt.getState() == MouseEvent::MOTION) { onMouseOver(evt, address); } } else _parentMenu->processMouseCallback(evt, address); }
void SDL_GUI::GUI_Element::Update() { bool inRect = rect.Contains(inputManager->GetMousePosition()); if (!mouseIsOver && inRect) { mouseIsOver = true; if (onMouseOver != NULL) onMouseOver(); } else if (mouseIsOver && !inRect) { mouseIsOver = false; performingClick = false; if (onMouseOut != NULL) onMouseOut(); } if (inRect) { if (inputManager->MouseDown()) { performingClick = true; if (onMouseDown != NULL) onMouseDown(); } else if (inputManager->MouseUp()) { if (onMouseUp != NULL) onMouseUp(); if (performingClick) { performingClick = false; if (onClick != NULL) onClick(); } } } }
void CButton::onEvent(Uint8 eventType) { if(!display) return; int mouse_x = event.button.x; int mouse_y = event.button.y; if(onButton(mouse_x, mouse_y)) { if(eventType == SDL_MOUSEBUTTONDOWN) onMouseDown(); else if(eventType == SDL_MOUSEBUTTONUP) onClick(); else if(eventType == SDL_MOUSEMOTION) onMouseOver(); } else setImageState(getType()); }
void GameObject::update(const sf::Time& frameTime) { for (auto& component : m_components) { component->update(frameTime); } if (g_inputController->isMouseOver(&m_boundingBox, m_isInputInDefaultView)) { onMouseOver(); // if the inputcontroller has locked actions, skip these methods. if (g_inputController->isActionLocked()) return; if (g_inputController->isRightClicked(&m_boundingBox, m_isInputInDefaultView)) { onRightClick(); } else if (g_inputController->isRightJustPressed(&m_boundingBox, m_isInputInDefaultView)) { onRightJustPressed(); } else if (g_inputController->isLeftClicked(&m_boundingBox, m_isInputInDefaultView)) { onLeftClick(); } else if (g_inputController->isLeftJustPressed(&m_boundingBox, m_isInputInDefaultView)) { onLeftJustPressed(); } } }
void DGLPixRectQGraphicsView::mouseMoveEvent(QMouseEvent* _event) { emit onMouseOver(_event->pos()); QGraphicsView::mouseMoveEvent(_event); }
//main void GameEngine::run() { lib.framestart(); if (!gameStart) renderGameMenu(); else { //Move the char left, right, up, and down if (!deadHero && !shop.isShopping()) { onPlayerTurn((lib.keywentdown("left") || lib.keywentdown("a")), Point(-1, 0)); onPlayerTurn((lib.keywentdown("up") || lib.keywentdown("w")), Point(0, -1)); onPlayerTurn((lib.keywentdown("right") || lib.keywentdown("d")), Point(1, 0)); onPlayerTurn((lib.keywentdown("down") || lib.keywentdown("s")), Point(0, 1)); //Enter stairs if (lib.keywentdown("return") || lib.keywentdown("enter")) { if (hero->getLoc() == stairLoc) { currLevel++; generateLevel(); } if (hero->getLoc() == shop.getLoc()) shop.activateShop(); if (hero->getLoc() == bossLoc) enterBossRoom(); if (hero->getLoc() == stairAscend) leaveBossRoom(); } if (tl_buttonwentdown(1)) { Pickup p = registerInventoryClick(); if (p.getLoc() != Point(-1, -1)) { if (p.getPickupDef().getType() == 0) log.registerEvent(("Used a " + p.getPickupDef().getName() + "!").c_str()); else log.registerEvent(("Equipped a " + p.getPickupDef().getName() + "!").c_str()); } if (lib.mouseLoc() >= Point(lib.res().x() / 2 - 3, lib.res().y() - 4) && lib.mouseLoc() <= Point(lib.res().x() / 2 + 3, lib.res().y() - 4)) useSpell(lib.mouseLoc()); } if (tl_buttonwentdown(3)) { Pickup p; if (invLog.overInvOrGear(lib.mouseLoc()) == 0) { p = invLog.dropItem(lib.mouseLoc()); if (p.getLoc() != Point(-1, -1)) log.registerEvent(("Dropped the " + p.getPickupDef().getName() + "!").c_str()); } else if (invLog.overInvOrGear(lib.mouseLoc()) == 1) { OutputDebugString("herpderp"); p = invLog.unequipGear(lib.mouseLoc()); if (p.getLoc() != Point(-1, -1)) log.registerEvent(("Unequipped the " + p.getPickupDef().getName() + "!").c_str()); } } } drawMap(); onMouseOver(); if(deadHero) { if (lib.keywentdown("escape")) gameStart = false; } } }
void Widget::process(const WidgetEvents & events) { // check automatic size. if (isAutoManagingWidth() || isAutoManagingHeight()) { sf::Vector2f autoSize = getAutomaticSize(); setSize(isAutoManagingWidth() ? autoSize.x : getSize().x, isAutoManagingHeight() ? autoSize.y : getSize().y); } // clear click flags for all buttons. myIsClicked = 0; // set mouse-over flag. mouse position is already pre-transformed. bool mouseOver = events.mouseFocus && checkMouseover(events.mousePosition); if (myIsMouseOver != mouseOver) { myIsMouseOver = mouseOver; if (mouseOver) { onMouseOver(); } else { onMouseAway(); } } // analyze container events to find state changes. for (auto it = events.conEvents.mouseEvents.begin(); it != events.conEvents.mouseEvents.end(); ++it) { ContainerEvents::MouseEvent event = *it; MouseBitmask buttonMask = convertMouseButtonBitmask(event.button); sf::Vector2f convPos = events.transform.getInverse().transformPoint(event.position); // check if mouse is over widget (and widget is not obstructed). if (events.mouseFocus && checkMouseover(convPos)) { // handle mouse presses/releases on the widget, check for successful click. if (event.isPress) { // bring widget to front on left mouse click. //if (event.button == sf::Mouse::Left) // sendToFront(); // add mouse button to bitmask. myIsMouseDown |= buttonMask; onMouseDown(convPos, event.button); } else if (myIsMouseDown & buttonMask) { myIsClicked |= buttonMask; onClick(convPos, event.button); } } // handle mouse button release. if (!event.isPress) { // remove mouse button from bitmask. if (myIsMouseDown & buttonMask) { myIsMouseDown &= ~buttonMask; onMouseUp(convPos, event.button); } } } // now process widget events. onProcess(events); }