void View::mouse_down(DispPoint coord) { cout << "mouse down!: " << coord.x <<", "<< coord.y << endl; if (!handle_mouse_down(coord)) { if (parent) parent->mouse_down(coord + pos); // else throw Unhandled_Click(coord); } }
void process_events( void ) { /* Our SDL event placeholder. */ SDL_Event event; /* Grab all the events off the queue. */ while( SDL_PollEvent( &event ) ) { switch( event.type ) { case SDL_KEYDOWN: /* Handle key presses. */ handle_key_down( &event.key.keysym ); break; case SDL_QUIT: /* Handle quit requests */ quit(1); break; case SDL_MOUSEBUTTONDOWN: handle_mouse_down(&event.button); break; } } }
void ui_run() { SDL_Event e; quit = false; while(!quit) { ui_render(true); while(SDL_PollEvent(&e) != 0) { if (midi_command_event != (Uint32) -1 && e.type == midi_command_event) { struct midi_event * me = e.user.data1; switch (me->type) { case MIDI_EVENT_SLIDER: set_slider_to(me->slider.index, me->slider.value, me->snap); break; case MIDI_EVENT_KEY:; SDL_KeyboardEvent fakekeyev; memset(&fakekeyev, 0, sizeof fakekeyev); fakekeyev.type = SDL_KEYDOWN; fakekeyev.state = SDL_PRESSED; fakekeyev.keysym.sym = me->key.keycode[0]; handle_key(&fakekeyev); break; } free(e.user.data1); free(e.user.data2); continue; } switch(e.type) { case SDL_QUIT: quit = true; break; case SDL_KEYDOWN: handle_key(&e.key); break; case SDL_MOUSEMOTION: mx = e.motion.x; my = e.motion.y; handle_mouse_move(); break; case SDL_MOUSEBUTTONDOWN: mx = e.button.x; my = e.button.y; switch(e.button.button) { case SDL_BUTTON_LEFT: handle_mouse_down(); break; } break; case SDL_MOUSEBUTTONUP: mx = e.button.x; my = e.button.y; switch(e.button.button) { case SDL_BUTTON_LEFT: handle_mouse_up(); break; } break; case SDL_TEXTINPUT: handle_text(e.text.text); break; } } for(int i=0; i<N_DECKS; i++) { deck_render(&deck[i]); } crossfader_render(&crossfader, deck[left_deck_selector].tex_output, deck[right_deck_selector].tex_output); ui_render(false); render_readback(&render); SDL_GL_SwapWindow(window); double cur_t = SDL_GetTicks(); double dt = cur_t - l_t; if(dt > 0) time += dt / 1000; l_t = cur_t; } }
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; } }