gamewidget::gamewidget(QWidget *parent) : QDialog(parent) { //background this->setAutoFillBackground(true); this->resize(391,220); this->setWindowTitle("snack"); QPalette palette; palette.setBrush(QPalette::Background,QBrush(QPixmap(":/new/prefix1/img/green.jpg"))); this->setPalette(palette); //button left_button = new QPushButton("Left",this); left_button->setGeometry(QRect(260,70,40,30)); right_button = new QPushButton("Right",this); right_button->setGeometry(QRect(340,70,40,30)); up_button = new QPushButton("Up",this); up_button->setGeometry(QRect(300,40,40,30)); down_button = new QPushButton("Down",this); down_button->setGeometry(QRect(300,70,40,30)); start_button = new QPushButton("Start",this); start_button->setGeometry(270,120,50,30); return_button = new QPushButton("Return",this); return_button->setGeometry(330,120,50,30); //signal and slot connect(left_button,SIGNAL(clicked()),this,SLOT(left_click())); connect(right_button,SIGNAL(clicked()),this,SLOT(right_click())); connect(up_button,SIGNAL(clicked()),this,SLOT(up_click())); connect(down_button,SIGNAL(clicked()),this,SLOT(down_click())); connect(start_button,SIGNAL(clicked()),this,SLOT(start_click())); connect(return_button,SIGNAL(clicked()),this,SLOT(return_click())); //key singnal connect(this,SIGNAL(UpSignal()),this,SLOT(up_click())); connect(this,SIGNAL(DownSignal()),this,SLOT(down_click())); connect(this,SIGNAL(LeftSignal()),left_button,SLOT(click())); connect(this,SIGNAL(RightSignal()),right_button,SLOT(click())); //auto update timer = new QTimer(this); connect(timer,SIGNAL(timeout()),this,SLOT(timeoutslot())); //rand seed QTime t; t= QTime::currentTime(); qsrand(t.msec()+t.second()*1000); //head snake[0][0] = qrand()%ROW; snake[0][1] = qrand()%COL; //data init foodcount = 0; suicide = false; thesame = false; speed = 300; sound_eat = new QSound(":/sounds/eating.wav",this); sound_die = new QSound(":/sounds/gameover.wav",this); foodx = qrand()%ROW; foody = qrand()%COL; while (foodx==snake[0][0]&&foody==snake[0][1]) { foodx = qrand()%ROW; foody = qrand()%COL; } directioin = qrand()%4; }
TaskResult MouseDown(const PosInfo& info) override{ assert(m_textObject != nullptr); if (right_click(info) || outside(m_textObject, info)){ return Commit(info.layerType); } m_newTask.Set(select_text_task(m_textObject, m_newTextObject, info.pos)); return TaskResult::PUSH; }
static void del_client(t_on_screen *screen, t_cli *save_cli, t_cli *list_cli) { if (screen->info_bag->heros != NULL) if (list_cli == screen->info_bag->heros) { screen->info_bag->heros = NULL; right_click(screen); } if (screen->info_bag->heros != NULL) if (list_cli == screen->info_bag->heros) { screen->info_bag->heros = NULL; right_click(screen); } if (save_cli == NULL) screen->world->client = list_cli->next; else save_cli->next = list_cli->next; free(list_cli->team); free(list_cli); }
static gboolean edit_dialog_popup_handler (GtkWidget *w, GdkEventButton *event, dialog_t *d) { if (right_click(event)) { if (d->popup != NULL) { gtk_widget_destroy(d->popup); d->popup = NULL; } d->popup = build_edit_popup(d); if (d->popup != NULL) { gtk_menu_popup(GTK_MENU(d->popup), NULL, NULL, NULL, NULL, event->button, event->time); g_signal_connect(G_OBJECT(d->popup), "destroy", G_CALLBACK(gtk_widget_destroyed), &d->popup); } return TRUE; } return FALSE; }
void mouse_handler_base::mouse_press(const SDL_MouseButtonEvent& event, const bool browse) { if(is_middle_click(event) && !preferences::middle_click_scrolls()) { simple_warp_ = true; } show_menu_ = false; map_location loc = gui().hex_clicked_on(event.x,event.y); mouse_update(browse, loc); #if !SDL_VERSION_ATLEAST(2,0,0) int scrollx = 0; int scrolly = 0; #endif if (is_left_click(event)) { if (event.state == SDL_PRESSED) { cancel_dragging(); init_dragging(dragging_left_); left_click(event.x, event.y, browse); } else if (event.state == SDL_RELEASED) { minimap_scrolling_ = false; clear_dragging(event, browse); left_mouse_up(event.x, event.y, browse); } } else if (is_right_click(event)) { if (event.state == SDL_PRESSED) { cancel_dragging(); init_dragging(dragging_right_); right_click(event.x, event.y, browse); } else if (event.state == SDL_RELEASED) { minimap_scrolling_ = false; clear_dragging(event, browse); right_mouse_up(event.x, event.y, browse); } } else if (is_middle_click(event)) { if (event.state == SDL_PRESSED) { set_scroll_start(event.x, event.y); scroll_started_ = true; map_location loc = gui().minimap_location_on(event.x,event.y); minimap_scrolling_ = false; if(loc.valid()) { simple_warp_ = false; minimap_scrolling_ = true; last_hex_ = loc; gui().scroll_to_tile(loc,display::WARP,false); } else if(simple_warp_) { // middle click not on minimap, check gamemap instead loc = gui().hex_clicked_on(event.x,event.y); if(loc.valid()) { last_hex_ = loc; gui().scroll_to_tile(loc,display::WARP,false); } } } else if (event.state == SDL_RELEASED) { minimap_scrolling_ = false; simple_warp_ = false; scroll_started_ = false; } } #if !SDL_VERSION_ATLEAST(2,0,0) else if (allow_mouse_wheel_scroll(event.x, event.y)) { if (event.button == SDL_BUTTON_WHEELUP) { scrolly = - preferences::scroll_speed(); mouse_wheel_up(event.x, event.y, browse); } else if (event.button == SDL_BUTTON_WHEELDOWN) { scrolly = preferences::scroll_speed(); mouse_wheel_down(event.x, event.y, browse); } else if (event.button == SDL_BUTTON_WHEELLEFT) { scrollx = - preferences::scroll_speed(); mouse_wheel_left(event.x, event.y, browse); } else if (event.button == SDL_BUTTON_WHEELRIGHT) { scrollx = preferences::scroll_speed(); mouse_wheel_right(event.x, event.y, browse); } // Don't scroll map and map zoom slider at same time gui::slider* s = gui().find_slider("map-zoom-slider"); if (s && sdl::point_in_rect(event.x, event.y, s->location())) { scrollx = 0; scrolly = 0; } } if (scrollx != 0 || scrolly != 0) { CKey pressed; // Alt + mousewheel do an 90° rotation on the scroll direction if (pressed[SDLK_LALT] || pressed[SDLK_RALT]) gui().scroll(scrolly,scrollx); else gui().scroll(scrollx,scrolly); } #endif if (!dragging_left_ && !dragging_right_ && dragging_started_) { dragging_started_ = false; cursor::set_dragging(false); } mouse_update(browse, loc); }
void mouse_handler_base::mouse_press(const SDL_MouseButtonEvent& event, const bool browse) { x_ = event.x; y_ = event.y; if(is_middle_click(event) && !preferences::middle_click_scrolls()) { simple_warp_ = true; } show_menu_ = false; mouse_update(browse); int scrollx = 0; int scrolly = 0; if (is_left_click(event)) { if (event.state == SDL_PRESSED) { cancel_dragging(); init_dragging(dragging_left_); left_click(event.x, event.y, browse); } else if (event.state == SDL_RELEASED) { minimap_scrolling_ = false; clear_dragging(event, browse); left_mouse_up(event.x, event.y, browse); } } else if (is_right_click(event)) { if (event.state == SDL_PRESSED) { cancel_dragging(); init_dragging(dragging_right_); right_click(event.x, event.y, browse); } else if (event.state == SDL_RELEASED) { minimap_scrolling_ = false; clear_dragging(event, browse); right_mouse_up(event.x, event.y, browse); } } else if (is_middle_click(event)) { if (event.state == SDL_PRESSED) { map_location loc = gui().minimap_location_on(event.x,event.y); minimap_scrolling_ = false; if(loc.valid()) { simple_warp_ = false; minimap_scrolling_ = true; last_hex_ = loc; gui().scroll_to_tile(loc,display::WARP,false); } else if(simple_warp_) { // middle click not on minimap, check gamemap instead loc = gui().hex_clicked_on(event.x,event.y); if(loc.valid()) { last_hex_ = loc; gui().scroll_to_tile(loc,display::WARP,false); } } } else if (event.state == SDL_RELEASED) { minimap_scrolling_ = false; simple_warp_ = false; } } else if (allow_mouse_wheel_scroll(event.x, event.y)) { if (event.button == SDL_BUTTON_WHEELUP) { scrolly = - preferences::scroll_speed(); } else if (event.button == SDL_BUTTON_WHEELDOWN) { scrolly = preferences::scroll_speed(); } else if (event.button == SDL_BUTTON_WHEELLEFT) { scrollx = - preferences::scroll_speed(); } else if (event.button == SDL_BUTTON_WHEELRIGHT) { scrollx = preferences::scroll_speed(); } } if (scrollx != 0 || scrolly != 0) { CKey pressed; // Alt + mousewheel do an 90° rotation on the scroll direction if (pressed[SDLK_LALT] || pressed[SDLK_RALT]) gui().scroll(scrolly,scrollx); else gui().scroll(scrollx,scrolly); } if (!dragging_left_ && !dragging_right_ && dragging_started_) { dragging_started_ = false; cursor::set_dragging(false); } mouse_update(browse); }
void mouse_handler_base::mouse_press(const SDL_MouseButtonEvent& event, const bool browse) { if(is_middle_click(event) && !preferences::middle_click_scrolls()) { simple_warp_ = true; } show_menu_ = false; map_location loc = gui().hex_clicked_on(event.x,event.y); mouse_update(browse, loc); if (is_left_click(event)) { if (event.state == SDL_PRESSED) { cancel_dragging(); init_dragging(dragging_left_); left_click(event.x, event.y, browse); } else if (event.state == SDL_RELEASED) { minimap_scrolling_ = false; clear_dragging(event, browse); left_mouse_up(event.x, event.y, browse); } } else if (is_right_click(event)) { if (event.state == SDL_PRESSED) { cancel_dragging(); init_dragging(dragging_right_); right_click(event.x, event.y, browse); } else if (event.state == SDL_RELEASED) { minimap_scrolling_ = false; clear_dragging(event, browse); right_mouse_up(event.x, event.y, browse); } } else if (is_middle_click(event)) { if (event.state == SDL_PRESSED) { set_scroll_start(event.x, event.y); scroll_started_ = true; map_location loc = gui().minimap_location_on(event.x,event.y); minimap_scrolling_ = false; if(loc.valid()) { simple_warp_ = false; minimap_scrolling_ = true; last_hex_ = loc; gui().scroll_to_tile(loc,display::WARP,false); } else if(simple_warp_) { // middle click not on minimap, check gamemap instead loc = gui().hex_clicked_on(event.x,event.y); if(loc.valid()) { last_hex_ = loc; gui().scroll_to_tile(loc,display::WARP,false); } } } else if (event.state == SDL_RELEASED) { minimap_scrolling_ = false; simple_warp_ = false; scroll_started_ = false; } } if (!dragging_left_ && !dragging_right_ && dragging_started_) { dragging_started_ = false; cursor::set_dragging(false); } mouse_update(browse, loc); }