void Button::setup(const std::string& name, Shape shape) { name_ = name; if(shape == kRectangle) { sf::RectangleShape* bg = new sf::RectangleShape(size_); bg->setOrigin(sf::Vector2f(size_.x/2, size_.y/2)); addDrawer("bg", bg); } else { sf::CircleShape* bg = new sf::CircleShape(size_.x); bg->setOrigin(sf::Vector2f(size_.x, size_.x)); addDrawer("bg", bg); } render<sf::Shape>("bg").setOutlineColor(sf::Color(8, 8, 8)); render<sf::Shape>("bg").setOutlineThickness(1); sf::Text* label = new sf::Text(); label->setFont(getFont()); label->setColor(sf::Color::Black); label->setString(name); label->setCharacterSize(Widget::kFontSize); label->setPosition(sf::Vector2f(-label->getLocalBounds().width/2, -label->getLocalBounds().height*.7)); addDrawer("label", label); onMouseOut(); }
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 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 RectangleButton::Update(){ isPressed = wasPressed = false; if (mouseIn()){ select(); if (mouseX_pre != mouseX && mouseY_pre != mouseY && onMouseIn) onMouseIn(); if (hge->Input_KeyUp(HGEK_LBUTTON)){ if(onMouseClick) onMouseClick(); wasPressed = true; } if (hge->Input_GetKeyState(HGEK_LBUTTON)){ float mod = 0.5; captionDx *= mod; captionDy *= mod; isPressed = true; } }else{ deselect(); if (in(mouseX_pre, mouseY_pre) && onMouseOut) onMouseOut(); } }
void Widget::update(const TCOD_key_t k) { bool curs=TCODMouse::isCursorVisible(); if ( curs ) { if ( mouse.cx >= x && mouse.cx < x+w && mouse.cy >= y && mouse.cy < y+h ) { if ( ! mouseIn ) { mouseIn = true; onMouseIn(); } if ( focus != this ) { focus=this; } } else { if ( mouseIn ) { mouseIn = false; onMouseOut(); } mouseL=false; if ( this == focus ) { focus = NULL; } } } if ( mouseIn || (! curs && this == focus ) ) { if ( mouse.lbutton && ! mouseL ) { mouseL = true; onButtonPress(); } else if (! mouse.lbutton && mouseL ) { onButtonRelease(); keyboardFocus=NULL; if ( mouseL ) onButtonClick(); mouseL=false; } else if ( mouse.lbutton_pressed ) { keyboardFocus=NULL; onButtonClick(); } } }