BOOL mouse_click(unsigned short btn, unsigned short count) { if(btn < 1) { fprintf(stderr, "The first mouse button is #1, clicking '0' will not work\n"); return FALSE; } if (!_check_init()) { return FALSE; } BOOL success = TRUE; unsigned short i; for (i = 0; i < count; i++) { success = mouse_down(btn); logit(LOG_LEVEL_VERBOSE, "Mouse button %d down ", btn); if (!success) { mouse_up(btn); //Just in case break; } usleep(MILLI_MULTIPLIER * defaults->mouse_down_delay); success = mouse_up(btn); logit(LOG_LEVEL_VERBOSE, "Mouse button %d up\n", btn); if (i < count - 1) { usleep(MILLI_MULTIPLIER * defaults->mouse_click_delay); } } return (success != 0); }
void button::handle_event(const SDL_Event& event) { if (hidden() || !enabled()) return; STATE start_state = state_; if (!mouse_locked()) { switch(event.type) { case SDL_MOUSEBUTTONDOWN: mouse_down(event.button); break; case SDL_MOUSEBUTTONUP: mouse_up(event.button); break; case SDL_MOUSEMOTION: mouse_motion(event.motion); break; default: return; } } if (start_state != state_) set_dirty(true); }
void TEST_mouse_up() { char *routine = "TEST_mouse_up"; printf(testing, routine); //It is necessary to include both down and up assert(mouse_down(1)); assert(mouse_up(1)); printf(done, routine); }
static void edit_release(void *data, XButtonEvent *event) { EDITINFO *einf = (EDITINFO *) data; if (event->window == einf->drawwin_id) { stop_motion_hints(); mouse_up(event->x -edit_margin(data), event->y); change_check = MP_True; } }
int main() { deltaTime = 0; sfg::SFGUI sfgui; // map sprite sf::Texture map_texture; sf::Sprite map_sprite; map_texture.loadFromFile("resources/map.png"); map_sprite.setTexture(map_texture); // window window.create(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, 32), "Runestone"); view.setSize(sf::Vector2f(WINDOW_WIDTH, WINDOW_HEIGHT)); view.setCenter(sf::Vector2f(0, 0)); window.setView(view); // timer sf::Clock clock; // thor actions thor::Action quit(sf::Event::Closed); thor::Action left(sf::Keyboard::A, thor::Action::Hold); thor::Action right(sf::Keyboard::D, thor::Action::Hold); thor::Action up(sf::Keyboard::W, thor::Action::Hold); thor::Action down(sf::Keyboard::S, thor::Action::Hold); thor::Action mouse_down(sf::Mouse::Left, thor::Action::PressOnce); thor::Action mouse_up(sf::Mouse::Left, thor::Action::ReleaseOnce); // thor action map thor::ActionMap<std::string> action_map; action_map["quit"] = quit; action_map["left"] = left; action_map["right"] = right; action_map["up"] = up; action_map["down"] = down; action_map["mouse_down"] = mouse_down; action_map["mouse_up"] = mouse_up; thor::ActionMap<std::string>::CallbackSystem action_callbacks; action_callbacks.connect("quit", &OnQuit); action_callbacks.connect("left", &OnLeft); action_callbacks.connect("right", &OnRight); action_callbacks.connect("up", &OnUp); action_callbacks.connect("down", &OnDown); action_callbacks.connect("mouse_down", &OnMouseDown); action_callbacks.connect("mouse_up", &OnMouseUp); // thor particles sf::Texture particleTexture; particleTexture.loadFromFile("Media/particle.png"); emitter.setEmissionRate(100.0f); emitter.setParticleLifetime(sf::seconds(1.0f)); particle_system.setTexture(particleTexture); // sfgui auto sfgui_window = sfg::Window::Create(); sfgui_window->SetTitle("Runestones: "); auto rune_one = sfg::Button::Create("Rune One"); rune_one->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnRuneOne)); rune_one->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnButtonClicked)); auto rune_two = sfg::Button::Create("Rune Two"); rune_two->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnRuneTwo)); rune_two->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnButtonClicked)); auto rune_three = sfg::Button::Create("Rune Three"); rune_three->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnRuneThree)); rune_three->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnButtonClicked)); auto rune_four = sfg::Button::Create("Rune Four"); rune_four->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnRuneFour)); rune_four->GetSignal(sfg::Button::OnMouseLeftPress).Connect(std::bind(&OnButtonClicked)); auto hbox = sfg::Box::Create(sfg::Box::Orientation::HORIZONTAL, 4.0f); hbox->Pack(rune_one); hbox->Pack(rune_two); hbox->Pack(rune_three); hbox->Pack(rune_four); sfgui_window->Add(hbox); sfgui_window->SetStyle(!sfg::Window::Style::RESIZE); sfgui_window->SetPosition(sf::Vector2f((WINDOW_WIDTH / 2.0f) - (sfgui_window->GetAllocation().width / 2.0f), WINDOW_HEIGHT - sfgui_window->GetAllocation().height)); // tileset sf::Texture tileTexture; tileTexture.loadFromFile("resources/tiles.png"); rf::TileMap tileMap(4, 8); tileMap.setTexture(tileTexture); int layout[4][8] = { {-1, -1, -1, 1, 1, -1, -1, -1}, {1,1,1,1,1,1,1,1}, {-1,-1,1,1,1,1,-1,-1}, {1,1,1,1,1,1,1,1} }; for (size_t i = 0; i < 4; i++) { for (size_t j = 0; j < 8; j++) { tileMap.setTile(layout[i][j], i, j); } } while (window.isOpen()) { deltaTime = clock.restart().asSeconds(); action_map.clearEvents(); sf::Event event; while (window.pollEvent(event)) { sfgui_window->HandleEvent(event); action_map.pushEvent(event); } particle_system.update(sf::seconds(deltaTime)); sfgui_window->Update(deltaTime); action_map.invokeCallbacks(action_callbacks, &window); window.setView(view); window.clear(sf::Color::Black); window.draw(map_sprite); window.draw(tileMap); window.draw(particle_system); sfgui.Display(window); window.display(); } return 0; }
int run_game_loop(GameState * state) { int done = 0; int i = 0; /* Initialise gui */ init_gui(SCREEN_WIDTH,SCREEN_HEIGHT); /* Load resources */ init_sprite_cache(); render_world_to_sprite(&state->world); update_hud( &state->hud, &state->score, &state->mana, &state->money, &state->world.castle->castle.health, &state->wave.wave_number, &state->play); /* Initialise game loop */ init_game_loop(FPS); while (!done) { /* Get events */ Event ev; wait_for_event(&ev); /* Event handlers */ switch (ev.type) { case EVENT_TIMER: state->redraw = 1; if (!state->game_over) { if (*state->hud.play) { check_spells(state); check_enemy_wave(state); update_movement(state); do_tower_attacks(state); } } break; case EVENT_MOUSE_MOVE: mouse_move(&ev.mouseMoveEvent, state); break; case EVENT_MOUSE_DOWN: mouse_down(&ev.mouseDownEvent, state); break; case EVENT_MOUSE_UP: mouse_up(&ev.mouseUpEvent, state); break; case EVENT_DISPLAY_CLOSE: done = 1; break; } /* Render only on timer event AND if all movement and logic was processed */ if (state->redraw && all_events_processed()) { render_game(state); } } /* Cleanup */ cleanup_game_loop(); cleanup_sprite_cache(); return 0; }