void Text_button::update() { if(!visible) { return; } int x,y; if(SDL_GetMouseState(&x, &y) & SDL_BUTTON(SDL_BUTTON_LEFT)&&!is_clicked) { if(x>location.x&&x<location.x+location.w&&y>location.y&&y<location.y+location.h) { is_clicked = true; } } else if(is_clicked) { if(x>location.x&&x<location.x+location.w&&y>location.y&&y<location.y+location.h&&!(SDL_GetMouseState(&x, &y) & SDL_BUTTON(SDL_BUTTON_LEFT))) { if(on_click) on_click(); else printf("Warning : no function specified for a button\n"); is_clicked=false; } else if (!(SDL_GetMouseState(&x, &y) & SDL_BUTTON(SDL_BUTTON_LEFT))) { is_clicked=false; } } }
MyDevButton::MyDevButton ( const QString & text, QWidget * parent, BtCompany *emp ) : QPushButton ( text, parent ) { BL_FUNC_DEBUG m_emp = emp; connect ( this, SIGNAL ( released() ), this, SLOT ( on_click() ) ); }
void Button::on_primary_button_release (int x, int y) { mouse_down = false; if (mouse_over) on_click(); }
/** * Updates the button * * @date 2015-02-27 * * @revisions * * @designer * * @programmer Jonathan Chu * Lewis Scott * Melvin Loho * * @return void */ void Button::update(sf::Time& t) { static bool tog = false; static AppWindow& appWindow = AppWindow::getInstance(); if (enabled) // button enabled { if (getGlobalTransform().transformRect(sprite().getLocalBounds()).contains(appWindow.getMousePositionRelativeToWindowAndView(view))) // mouse inside button { if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) // mouse clicking button { sprite().setTextureRect(clicked); // So that holding the mouse doesn't activate multiple times if (!tog) { on_click(); tog = true; } } else // mouse just hovering sprite().setTextureRect(hover); } else //mouse outside button sprite().setTextureRect(normal); } else // button disabled sprite().setTextureRect(disabled); // Reset the button if the mouse is released if (!sf::Mouse::isButtonPressed(sf::Mouse::Left)) tog = false; }
void FileList::on_primary_button_release (int x, int y) { on_pointer_move(x,y); if (click_item == current_item && current_item != -1) { on_click(directory[static_cast<size_t>(current_item)]); } click_item = -1; }
bool GuiButton::mouseup(int button, int x, int y) { if (button == 0) { mouse_is_down = false; if (mouse_is_in_button) { if (on_click) { on_click(this, on_click_data); } } } return true; }
bool GuiCheckbox::mouseup(int button, int x, int y) { if (button == 0) { mouse_is_down = false; if (mouse_is_in_button) { state = !state; if (on_click) { on_click(this, on_click_data, state); } } } return true; }
void UIWidget::mouse_up_func() { if (disabled) return; // call this function on the children first for (auto &child : ElementID::recast_collection<UIWidget>(get_children())) child->mouse_up_func(); // then continue with the function on self if (mouse_over && mouse_down_on_over) { on_click(); } mouse_down_on_over = false; if (dragging) { dragging = false; on_drop(); } on_mouse_up(); }
void ui_checkbox::touch_up(touch t) { if (in_rect(pos, dim, t.pos)) { checked = !checked; on_click(); } }
void SurfaceButton::on_primary_button_click (int x, int y) { on_click(); }
void on_primary_button_click (int x, int y) { on_click (); }
void GUIFileButton::on_primary_button_press (int x, int y) { //std::cout << "GUIFileButton::on_primary_button_press (int x, int y)" << std::endl; on_click (); }
/** Event handler to fire (higher level, abstracted) Item signals from Gtk events. */ bool Item::on_event(GdkEvent* event) { boost::shared_ptr<Canvas> canvas = _canvas.lock(); if (!canvas || !event) return false; static double x, y; static double drag_start_x, drag_start_y; static bool double_click = false; static bool dragging = false; double click_x, click_y; click_x = event->button.x; click_y = event->button.y; property_parent().get_value()->w2i(click_x, click_y); switch (event->type) { case GDK_2BUTTON_PRESS: if (dragging) { ungrab(event->button.time); dragging = false; } on_double_click(&event->button); double_click = true; break; case GDK_BUTTON_PRESS: if (!canvas->locked() && event->button.button == 1) { x = click_x; y = click_y; // Set these so we can tell on a button release if a drag actually // happened (if not, it's just a click) drag_start_x = x; drag_start_y = y; grab(GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK|GDK_BUTTON_PRESS_MASK, Gdk::Cursor(Gdk::FLEUR), event->button.time); dragging = true; } break; case GDK_MOTION_NOTIFY: if ((dragging && (event->motion.state & GDK_BUTTON1_MASK))) { double new_x = click_x; double new_y = click_y; if (event->motion.is_hint) { int t_x; int t_y; GdkModifierType state; gdk_window_get_pointer(event->motion.window, &t_x, &t_y, &state); new_x = t_x; new_y = t_y; } on_drag(new_x - x, new_y - y); x = new_x; y = new_y; } break; case GDK_BUTTON_RELEASE: if (dragging) { ungrab(event->button.time); dragging = false; if (click_x != drag_start_x || click_y != drag_start_y) { on_drop(); } else if (!double_click) { on_click(&event->button); } } else if (!double_click) { on_click(&event->button); } double_click = false; break; case GDK_ENTER_NOTIFY: canvas->signal_item_entered.emit(this); raise_to_top(); break; case GDK_LEAVE_NOTIFY: canvas->signal_item_left.emit(this); break; default: break; } // Never stop event propagation so derived classes have full access // to GTK events. return false; }
/* ---------------------------------------------------------------------------- * Runs the widget's "click" code, used when the player clicks on the widget, * if possible. */ void menu_widget::click() { if(!enabled) return; on_click(); if(click_handler) click_handler(); }
void SpeakingAgent::mouse_down_func() { if (mouse_over) on_click(); }