//! Check for pending events once bool video::next_frame() { if(!running) return false; //! try acquire mutex if threaded code, returns on failure if(vidtype == 3 || threaded && pthread_mutex_trylock(&g_mutex)) return running; //! Refresh screen picture g_fps++; #ifndef X_NOSHMPIX if(vidtype == 2 && updating) XClearWindow(dpy, win); #endif while( XPending(dpy) ) { XEvent report; XNextEvent(dpy, &report); switch( report.type ) { case ClientMessage: if(report.xclient.format != 32 || report.xclient.data.l[0] != _XA_WM_DELETE_WINDOW) break; case DestroyNotify: running = false; case KeyPress: on_key( XLookupKeysym(&report.xkey, 0) ); break; case ButtonPress: on_mouse( report.xbutton.x, report.xbutton.y, report.xbutton.button ); break; case ButtonRelease: on_mouse( report.xbutton.x, report.xbutton.y, -report.xbutton.button ); break; } } struct timezone tz; struct timeval now_time; gettimeofday(&now_time, &tz); double sec = (now_time.tv_sec+1.0*now_time.tv_usec/1000000.0) - (g_time.tv_sec+1.0*g_time.tv_usec/1000000.0); if(sec > 1) { memcpy(&g_time, &now_time, sizeof(g_time)); if(calc_fps) { double fps = g_fps; g_fps = 0; char buffer[256]; snprintf(buffer, 256, "%s%s: %d fps", title, updating?"":" (no updating)", int(fps/sec)); XStoreName(dpy, win, buffer); } #ifndef X_FULLSYNC XSync(dpy, false); // It is often better then using XSynchronize(dpy, true) #endif//X_FULLSYNC } if(threaded) pthread_mutex_unlock(&g_mutex); return true; }
void SignalHandler (int signal) { int event; switch(signal) { case 10: printf("mouse click \n contenido de la memoria\tx1: %d\tx2: %d\n",variable[4],variable[5]); currentState = 0; break; case 30: printf("mouse release \n contenido de la memoria\tx1: %d\tx2: %d\n",variable[4],variable[5]); currentState = 1; break; } if(lastState == 0 && currentState == 0) event = 0; if(lastState == 1 && currentState == 0) event = 1; if(lastState == 0 && currentState == 1) event = 4; if(!(lastState == 1 && currentState == 1)) { on_mouse(event, variable[6],variable[7], 1, NULL); } lastState = currentState; }
void platform_poll_events() { SDL_Event e; while (SDL_PollEvent(&e)) { switch (e.type) { case SDL_KEYDOWN: case SDL_KEYUP: on_key(e.key); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: on_mouse(e.button); break; case SDL_QUIT: has_closed = true; break; default: break; } } }
virtual BOOL handle_mouse(HELEMENT he, MOUSE_PARAMS ¶ms) { return on_mouse(he, params.target, params.cmd, params.pos, params.button_state, params.alt_state); }