int moth_gui::read_book(moth_book *book) { SDL_Event event; this->book = book; create_textures(); index.name = "START"; book->build_index(index); while(running) { while(SDL_PollEvent(&event)) { switch( event.type ) { case SDL_KEYDOWN: handle_key_down(&event.key.keysym); break; case SDL_KEYUP: handle_key_up(&event.key.keysym); break; case SDL_MOUSEMOTION: handle_mouse_motion(&event.motion); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: handle_mouse_button(&event.button); break; case SDL_VIDEORESIZE: handle_resize(&event.resize); break; case SDL_QUIT: running = 0; break; } } show_pages(); } return SUCCESS; }
void View::mouse_motion(DispPoint coord, DispPoint rel_motion) { // cout << "mouse motion!: " << rel_motion.x <<", "<< rel_motion.y << endl; if (!handle_mouse_motion(coord, rel_motion)) { if (parent) parent->mouse_motion(coord + pos, rel_motion); // else throw Unhandled_Click(coord); } }
void handle_event(){ SDL_Event event; while(SDL_PollEvent(&event)){ switch(event.type){ case SDL_ACTIVEEVENT: //lost focus if(event.active.gain == 0) Active = true; else Active = true; break; case SDL_VIDEORESIZE: surface = SDL_SetVideoMode(event.resize.w, event.resize.h, SCREEN_BPP, videoFlags); case SDL_KEYDOWN: handle_keypress(&event.key.keysym); break; case SDL_MOUSEMOTION: handle_mouse_motion(event.motion); break; case SDL_MOUSEBUTTONDOWN: handle_mouse_button(event.button); break; case SDL_QUIT: Running = false; break; default: break; } } }
void event_loop( Display* display, Window window ) { while (1) { while (XPending(display) > 0) { XEvent event; XNextEvent( display, &event ); switch (event.type) { case Expose: break; case ConfigureNotify: change_size(event.xconfigure.width, event.xconfigure.height); break; case KeyPress: { int code; code = XLookupKeysym( &event.xkey, 0); if ((code == XK_Escape)||(code == XK_q)) return; if (code == XK_Up) { eLit += lStep; if ( eLit > PI) eLit = PI; } if (code == XK_Down) { eLit -= lStep; if (eLit < 0.f) eLit = 0.f; } if (code == XK_Left) aLit -= lStep; if (code == XK_Right) aLit += lStep; if(code == XK_w) dCam = tStep; if(code == XK_s) dCam = -tStep; if(code == XK_d) lCam = tStep; if(code == XK_a) lCam = -tStep; if(code == XK_g) GLSLshader = !GLSLshader; if (code == XK_f) print_fps = !print_fps; if (code == XK_o) { scalePoly++; glPolygonOffset(scalePoly, biasPoly); } if (code == XK_i) { scalePoly--; glPolygonOffset(scalePoly, biasPoly); } if (code == XK_l) { biasPoly++; glPolygonOffset(scalePoly, biasPoly); } if (code == XK_k) { biasPoly--; glPolygonOffset(scalePoly, biasPoly); } if (code == XK_p) // toggle character 0 running/standing { md2_model[0]->anim_command = ANIMATION_CHANGE; md2_model[1]->anim_command = ANIMATION_CHANGE; if (md2_model[0]->current_animation == ANIMATION_RUN) { md2_model[0]->anim_state = ANIMATION_STANDING_IDLE; md2_model[1]->anim_state = ANIMATION_STANDING_IDLE; } else { md2_model[0]->anim_state = ANIMATION_RUN; md2_model[1]->anim_state = ANIMATION_RUN; } } if (code == XK_0) // increase character 1 animation { md2_model[2]->anim_command = ANIMATION_CHANGE; if ( md2_model[2]->anim_state++ == ANIMATION_CROUCH_DEATH ) md2_model[2]->anim_state = ANIMATION_STANDING_IDLE; } if (code == XK_9) // decrease character 1 animation { md2_model[2]->anim_command = ANIMATION_CHANGE; if ( md2_model[2]->anim_state-- == ANIMATION_STANDING_IDLE ) md2_model[2]->anim_state = ANIMATION_CROUCH_DEATH; } if (code == XK_h) // kill character 1 { md2_model[2]->anim_command = ANIMATION_CHANGE; md2_model[2]->anim_state = ANIMATION_DEATH_SLOW; } if (code == XK_r) { wireframe = !wireframe; if (wireframe) glPolygonMode(GL_FRONT, GL_LINE); else glPolygonMode(GL_FRONT, GL_FILL); } } case ButtonPress: { handle_mouse_button(event.xbutton.button, 0, event.xbutton.x, event.xbutton.y); break; } case ButtonRelease: { handle_mouse_button(event.xbutton.button, 1, event.xbutton.x, event.xbutton.y); break; } case MotionNotify: { if (event.xmotion.state & Button1Mask) { handle_mouse_motion(1, event.xmotion.x, event.xmotion.y); break; } if (event.xmotion.state & Button3Mask) handle_mouse_motion(3, event.xmotion.x, event.xmotion.y); break; } } } render(); glXSwapBuffers( display, window ); switch (signal_pending) { case SIGINT: case SIGHUP: case SIGTERM: return; /* return from event_loop */ default: break; } signal_pending = 0; if( (use_timer) && ( (etime - t2) > max_timer ) ) return; } }
static void process_events(void) { /* Our SDL event placeholder. */ SDL_Event event; /* Only poll + sleep if we are autoscrolling or doing * something else that is interactive */ if (((autoscroll) && autoscroll_var) || key_button_down) { if (!SDL_PollEvent(&event)) { /* If we add a sleep, the scrolling won't be super smooth. * Regardless, I think we need to find something to make sure we * don't eat 100% cpu just checking for events. * * I found that 10ms is not a bad wait. Theoretically we want to * wait 1000ms / fps (usually 60) -> 16ms. * */ usleep(16000); if (autoscroll) { if (key_button_down & LEAST_KEY_DOWN) autoscroll_var += 1; if (key_button_down & LEAST_KEY_UP) autoscroll_var -= 1; scroll -= autoscroll_var; } else { if (key_button_down & LEAST_KEY_DOWN) scroll -= 5; if (key_button_down & LEAST_KEY_UP) scroll += 5; } redraw = 1; } } else { SDL_WaitEvent(&event); } next_event: switch (event.type) { case SDL_KEYDOWN: /* Handle key presses. */ handle_key_down(&event.key.keysym); break; case SDL_KEYUP: handle_key_up(&event.key.keysym); break; case SDL_QUIT: /* Handle quit requests (like Ctrl-c). */ quit_tutorial(0); break; case SDL_VIDEORESIZE: handle_resize(event.resize); break; case SDL_VIDEOEXPOSE: redraw = 1; break; case SDL_MOUSEBUTTONDOWN: handle_mouse_down(&event.button); break; case SDL_MOUSEBUTTONUP: handle_mouse_up(&event.button); break; case SDL_MOUSEMOTION: handle_mouse_motion(&event.motion); break; /* A thread completed its rendering * * The thread structure of the completed job is contained * within the data1 pointer of the event. */ case LEAST_PAGE_COMPLETE: finish_page_render((struct least_thread*)event.user.data1); redraw = 1; break; } /* Clear event, just in case SDL doesn't do this (TODO) */ memset(&event, 0, sizeof(SDL_Event)); /* If there are more events, handle them before drawing. * This is required for scrolling with the mouse - without this, * it is pretty slow and lags. */ if (SDL_PollEvent(&event)) { goto next_event; } }
LRESULT CALLBACK dialog_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; Frame* curr; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox (globals.hinst, (LPCTSTR) IDD_ABOUTBOX, hwnd, (DLGPROC) about_callback); break; case IDM_FILE_OPEN: break; case IDM_EXIT: DestroyWindow (hwnd); break; case IDM_SOURCE_MATROX: ise_grab_set_source (&globals.ig, ISE_IMAGE_SOURCE_MATROX_HIRES_FLUORO); highlight_source_menu (hwnd); break; case IDM_SOURCE_BITFLOW: ise_grab_set_source (&globals.ig, ISE_IMAGE_SOURCE_BITFLOW_LORES_FLUORO); //default is low highlight_source_menu (hwnd); break; case IDM_SOURCE_SYNTHETIC: ise_grab_set_source (&globals.ig, ISE_IMAGE_SOURCE_SIMULATED_HIRES_FLUORO); highlight_source_menu (hwnd); break; case IDM_SOURCE_INTERNAL: ise_grab_set_source (&globals.ig, ISE_IMAGE_SOURCE_INTERNAL_FLUORO); highlight_source_menu (hwnd); break; case IDM_SOURCE_FILE: ise_grab_set_source (&globals.ig, ISE_IMAGE_SOURCE_FILE_HIRES_FLUORO); //default is high; fileload_open (&globals.ig.fileload); highlight_source_menu (hwnd); globals.loadfrom_file = !globals.loadfrom_file; //blt_frame_gl (0, curr, curr->img, ISE_IMAGE_SOURCE_FILE_HIRES_FLUORO); break; case IDM_SOURCE_SETTINGS: DialogBox (globals.hinst, (LPCTSTR) IDD_SOURCE_DIALOG, hwnd, (DLGPROC) source_settings_callback); break; case IDM_OPTIONS_DROP_DARK: handle_ddf (); highlight_dialog_buttons (); break; case IDM_OPTIONS_WRITE_DARK: handle_wdf (); highlight_dialog_buttons (); break; case IDM_OPTIONS_HOLD_BRIGHT: handle_hbf (); highlight_dialog_buttons (); break; case IDC_BUTTON_PAUSE: case IDC_BUTTON_STOP: switch (wmEvent) { case BN_CLICKED: handle_button_stop (); highlight_dialog_buttons (); return 1; default: return DefWindowProc(hwnd, message, wParam, lParam); } case IDC_BUTTON_GRAB: switch (wmEvent) { case BN_CLICKED: handle_button_grab (); highlight_dialog_buttons (); return 1; default: return DefWindowProc(hwnd, message, wParam, lParam); } case IDC_BUTTON_REC: switch (wmEvent) { case BN_CLICKED: handle_button_rec (); highlight_dialog_buttons (); return 1; default: return DefWindowProc(hwnd, message, wParam, lParam); } case IDC_BUTTON_RESET: switch (wmEvent) { case BN_CLICKED: handle_button_reset (); globals.notify[hwnd_to_idx (hwnd)] = 1; highlight_dialog_buttons (); return 1; default: return DefWindowProc(hwnd, message, wParam, lParam); } case IDC_BUTTON_AWL: switch (wmEvent) { case BN_CLICKED: handle_button_awl (); highlight_dialog_buttons (); return 1; default: return DefWindowProc(hwnd, message, wParam, lParam); } case IDC_BUTTON_GATE: switch (wmEvent) { case BN_CLICKED: handle_button_gate (); highlight_dialog_buttons (); return 1; default: return DefWindowProc(hwnd, message, wParam, lParam); } case IDC_BUTTON_TRACK: switch (wmEvent) { case BN_CLICKED: handle_button_track (); highlight_dialog_buttons (); return 1; default: return DefWindowProc(hwnd, message, wParam, lParam); } /* Replay buttons */ case IDC_BUTTON_REWBEG: switch (wmEvent) { case BN_CLICKED: ise_fluoro_rewind_display (); gdi_rewind_frame_slider (hwnd_to_idx (hwnd)); highlight_dialog_buttons (); return 1; default: return DefWindowProc(hwnd, message, wParam, lParam); } case IDC_BUTTON_REPLAY: switch (wmEvent) { case BN_CLICKED: handle_button_replay (); globals.notify[hwnd_to_idx (hwnd)] = 1; highlight_dialog_buttons (); return 1; default: return DefWindowProc(hwnd, message, wParam, lParam); } } break; case WM_LBUTTONUP: { int x = LOWORD(lParam); int y = HIWORD(lParam); int idx = hwnd_to_idx (hwnd); handle_mouse_lbutton_up (idx, x, y); } break; case WM_RBUTTONUP: { int x = LOWORD(lParam); int y = HIWORD(lParam); gl_zoom_at_pos (hwnd_to_idx (hwnd), x, y); globals.notify[hwnd_to_idx (hwnd)] = 1; } break; case WM_MOUSEMOVE: { int x = LOWORD(lParam); int y = HIWORD(lParam); int idx = hwnd_to_idx (hwnd); handle_mouse_motion (idx, x, y); } break; case WM_SIZE: // Resize window if (wParam != SIZE_MINIMIZED) { do_resize (hwnd); resize_gl_window (hwnd_to_idx (hwnd)); } break; case WM_PAINT: { debug_printf ("Got WM_PAINT event\n"); hdc = BeginPaint(hwnd, &ps); globals.notify[hwnd_to_idx (hwnd)] = 1; EndPaint(hwnd, &ps); } break; case WM_HSCROLL: { handle_slider_frame (hwnd); return 1; } case WM_VSCROLL: { HWND sb_hwnd = (HWND) lParam; unsigned short bot, top; bot = (unsigned short) SendDlgItemMessage (hwnd, IDC_SLIDER_BOT, TBM_GETPOS, 0, 0); top = (unsigned short) SendDlgItemMessage (hwnd, IDC_SLIDER_TOP, TBM_GETPOS, 0, 0); if (sb_hwnd == GetDlgItem(hwnd, IDC_SLIDER_BOT)) { if (bot > top) { SendDlgItemMessage (hwnd, IDC_SLIDER_TOP, TBM_SETPOS, TRUE, bot); bot = top; } } if (sb_hwnd == GetDlgItem(hwnd, IDC_SLIDER_TOP)) { if (top < bot) { SendDlgItemMessage (hwnd, IDC_SLIDER_BOT, TBM_SETPOS, TRUE, top); bot = top; } } update_wl_status (hwnd_to_idx(hwnd), bot, top); update_lut (hwnd, (long) bot, (long) top); globals.notify[hwnd_to_idx (hwnd)] = 1; } return 0; case WM_NOTIFY: { NMHDR *pnmh = (LPNMHDR) lParam; if (wParam == IDC_SLIDER_BOT) { return 0; } } return 0; case WM_INITDIALOG: return TRUE; case WM_CLOSE: case WM_DESTROY: PostQuitMessage(0); globals.quit = 1; break; default: return 0; } return 0; }