void Application::mouse_event(int key, int event, unsigned char mods) { switch(event) { case EVENT_PRESS: switch(key) { case MOUSE_LEFT: mouse_pressed(LEFT); break; case MOUSE_RIGHT: mouse_pressed(RIGHT); break; case MOUSE_MIDDLE: mouse_pressed(MIDDLE); break; } break; case EVENT_RELEASE: switch(key) { case MOUSE_LEFT: mouse_released(LEFT); break; case MOUSE_RIGHT: mouse_released(RIGHT); break; case MOUSE_MIDDLE: mouse_released(MIDDLE); break; } break; } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); view = new QGraphicsView; scene = new ExQGraphicsScene; inputParams = new InputParamsDialog; exportImageDialog = new ExportImageDialog; progressBar = new ProgressBarWidget; this->zoomFactor=1.2; this->load(); QObject::connect(this->scene,SIGNAL(mouse_pressed()),this,SLOT(moused())); QObject::connect(inputParams,SIGNAL(accepted()),this,SLOT(draw())); QObject::connect(ui->closeBtn,SIGNAL(clicked()),this,SLOT(close())); QObject::connect(ui->closeBtn,SIGNAL(clicked()),this->view,SLOT(close())); QObject::connect(ui->zoomInBtn,SIGNAL(clicked()),this,SLOT(zoomIn())); QObject::connect(ui->zoomOutBtn,SIGNAL(clicked()),this,SLOT(zoomOut())); QObject::connect(ui->exportBtn,SIGNAL(clicked()),this,SLOT(exportCalled())); QObject::connect(exportImageDialog,SIGNAL(accepted()),this,SLOT(exportImage())); QObject::connect(exportImageDialog,SIGNAL(accepted()),this,SLOT(showProgressBar())); QObject::connect(exportImageDialog,SIGNAL(accepted()),this->progressBar,SLOT(start())); }
bool _get_touch(const Vector2* pos, float radius, Vector2* touch) { assert(pos); Touch* touches = touches_get(); if(touches) { uint count = touches_count(); for(uint i = 0; i < count; ++i) { if(vec2_length_sq(vec2_sub(*pos, touches[i].pos)) > radius*radius) continue; if(touch) *touch = touches[i].pos; return true; } } if(mouse_pressed(MBTN_LEFT)) { uint x, y; mouse_pos(&x, &y); Vector2 mpos = {(float)x, (float)y}; if(vec2_length_sq(vec2_sub(*pos, mpos)) <= radius*radius) { if(touch) *touch = mpos; return true; } } return false; }
void mouseevent::mousePressEvent(QMouseEvent *ev) { //if(ev->buttons() == Qt::LeftButton){ mousePressed = true; qDebug() << "PRESSED" << mousePressed; emit mouse_pressed(); }
void CarApp::run_event_loop() { logger->log(DEBUG, "CarApp::run_event_loop", "start"); TouchData *pData; int prev_x, prev_y; touchScreen->start(); while(quit == FALSE) { pData = touchScreen->dequeue(); if (pData == NULL) { usleep(20000); // yield CPU for 20ms continue; } if (pData->state == 1) { if (pData->x < button_width) mouse_pressed(pData->x, pData->y); else currentModule->mouse_pressed(pData->x, pData->y); prev_x = pData->x; prev_y = pData->y; } else { if (prev_x < button_width) mouse_released(prev_x, prev_y); else currentModule->mouse_released(prev_x, prev_y); } free(pData); } logger->log(DEBUG, "CarApp::run_event_loop", "end"); }
int dispatcher::execute( void ) { xcb_flush( _connection ); _exit_code = 0; bool done = false; while ( !done ) { auto event = core::wrap_cptr( xcb_wait_for_event( _connection ) ); if ( !event ) break; switch ( event->response_type & ~0x80 ) { case XCB_EXPOSE: { auto *ev = reinterpret_cast<xcb_expose_event_t*>( event.get() ); if ( ev->count == 0 ) _windows[ev->window]->exposed(); xcb_flush( _connection ); break; } case XCB_CONFIGURE_NOTIFY: { auto *ev = reinterpret_cast<xcb_configure_notify_event_t*>( event.get() ); auto w = _windows[ev->window]; if ( w->check_last_position( ev->x, ev->y ) ) w->moved( ev->x, ev->y ); if ( w->check_last_size( ev->width, ev->height ) ) w->resize_canvas( ev->width, ev->height ); break; } case XCB_DESTROY_NOTIFY: { auto *ev = reinterpret_cast<xcb_destroy_notify_event_t*>( event.get() ); auto w = _windows[ev->window]; w->closed(); break; } case XCB_MAP_NOTIFY: { auto *ev = reinterpret_cast<xcb_map_notify_event_t*>( event.get() ); auto w = _windows[ev->window]; w->shown(); w->restored(); break; } case XCB_UNMAP_NOTIFY: { auto *ev = reinterpret_cast<xcb_unmap_notify_event_t*>( event.get() ); auto w = _windows[ev->window]; w->hidden(); w->minimized(); break; } case XCB_ENTER_NOTIFY: { auto *ev = reinterpret_cast<xcb_enter_notify_event_t*>( event.get() ); auto w = _windows[ev->event]; w->entered(); break; } case XCB_LEAVE_NOTIFY: { auto *ev = reinterpret_cast<xcb_leave_notify_event_t*>( event.get() ); auto w = _windows[ev->event]; w->exited(); break; } case XCB_KEY_PRESS: { auto *ev = reinterpret_cast<xcb_key_press_event_t*>( event.get() ); auto w = _windows[ev->event]; platform::scancode sc = _keyboard->get_scancode( ev->detail ); w->key_pressed( _keyboard, sc ); break; } case XCB_KEY_RELEASE: { auto *ev = reinterpret_cast<xcb_key_press_event_t*>( event.get() ); auto w = _windows[ev->event]; platform::scancode sc = _keyboard->get_scancode( ev->detail ); w->key_released( _keyboard, sc ); break; } case XCB_MAPPING_NOTIFY: { auto *ev = reinterpret_cast<xcb_mapping_notify_event_t*>( event.get() ); if ( ev->request == XCB_MAPPING_MODIFIER || ev->request == XCB_MAPPING_KEYBOARD ) _keyboard->update_mapping(); break; } case XCB_BUTTON_PRESS: { auto *ev = reinterpret_cast<xcb_button_press_event_t*>( event.get() ); auto w = _windows[ev->event]; switch ( ev->detail ) { case 1: case 2: case 3: w->mouse_pressed( _mouse, { double(ev->event_x), double(ev->event_y) }, ev->detail ); break; case 4: // Mouse wheel up case 5: // Mouse wheel down break; } break; } case XCB_BUTTON_RELEASE: { auto *ev = reinterpret_cast<xcb_button_press_event_t*>( event.get() ); auto w = _windows[ev->event]; switch ( ev->detail ) { case 1: case 2: case 3: w->mouse_released( _mouse, { double(ev->event_x), double(ev->event_y) }, ev->detail ); break; case 4: // Mouse wheel up case 5: // Mouse wheel down break; } break; } case XCB_MOTION_NOTIFY: { auto *ev = reinterpret_cast<xcb_motion_notify_event_t*>( event.get() ); auto w = _windows[ev->event]; w->mouse_moved( _mouse, { double(ev->event_x), double(ev->event_y) } ); break; } case XCB_VISIBILITY_NOTIFY: case XCB_REPARENT_NOTIFY: break; case XCB_CLIENT_MESSAGE: { auto *ev = reinterpret_cast<xcb_client_message_event_t*>( event.get() ); if ( ev->data.data32[0] == _atom_delete_window ) { auto w = _windows[ev->window]; w->hide(); _windows.erase( w->id() ); done = _windows.empty(); } break; } default: std::cout << "Unknown event: " << uint32_t( event->response_type & ~0x80 ) << ' ' << uint32_t( event->response_type ) << std::endl; } } return _exit_code; }
void Textbox::update() { cs.update(); screenCS.update(); if (!selecting && screenCS.getIsPressed()) { if (cs.getIsPressed()) { active = true; selecting = true; selection_was_started_from = mouse_position(); selection.first = selection_was_started_from; selection.second = selection_was_started_from; } else { active = false; selecting = false; selection.first = 0; selection.second = 0; } } if (selecting) { selection.first = mouse_position(); selection.second = selection_was_started_from; if (selection.first > selection.second) { swap(selection.first, selection.second); } if (!mouse_pressed()) { selecting = false; show_cursor = true; prev_time = chrono::system_clock::now(); } } if (active) { for (KeyChar& k: keychar) { string insertion = k.update(); if (!insertion.empty()) { text.replace(selection.first, selection.second - selection.first, insertion); show_cursor = true; prev_time = chrono::system_clock::now(); if (selection.first == selection.second) { selection.first = range(selection.second + static_cast<int>(insertion.size()), 0, static_cast<int>(text.size())); selection.second = range(selection.second + static_cast<int>(insertion.size()), 0, static_cast<int>(text.size())); } else { selection.second = ++selection.first; } } } // w 4 poniższych if-ach przydałoby się jeszcze dopisać co kiedy shift/ctrl jest wciśnięty if (kcLeft.update()) { show_cursor = true; prev_time = chrono::system_clock::now(); if (selection.second != selection.first) { selection.second = selection.first; } else { selection.first = range(selection.first-1, 0, static_cast<int>(text.size())); selection.second = range(selection.second-1, 0, static_cast<int>(text.size())); } } if (kcRight.update()) { show_cursor = true; prev_time = chrono::system_clock::now(); if (selection.first != selection.second) { selection.first = selection.second; } else { selection.first = range(selection.first+1, 0, static_cast<int>(text.size())); selection.second = range(selection.second+1, 0, static_cast<int>(text.size())); } } if (kcBackspace.update()) { show_cursor = true; prev_time = chrono::system_clock::now(); if (selection.first != selection.second) { text.erase(selection.first, selection.second - selection.first); selection.second = range(selection.first, 0, static_cast<int>(text.size())); } else if (selection.first != 0) { text.erase(selection.first-1, 1); selection.first = range(selection.first-1, 0, static_cast<int>(text.size())); selection.second = range(selection.second-1, 0, static_cast<int>(text.size())); } } if (kcDelete.update()) { show_cursor = true; prev_time = chrono::system_clock::now(); if (selection.first != selection.second) { text.erase(selection.first, selection.second - selection.first); selection.second = range(selection.first, 0, static_cast<int>(text.size())); } else if (selection.first != text.size()) { text.erase(selection.first, 1); } } if (chrono::system_clock::now() - prev_time >= chrono::milliseconds(400)) { show_cursor = show_cursor ? 0 : 1; prev_time = chrono::system_clock::now(); } } }