int list_event(list_t *m,int event,int data) { char *str; int y; mousemove_u mm; if(scrollbar_event(&m->scrollbar,event,data) > 0) return(1); switch(event) { //key pressed // case E_KEYDOWN: // return(1); case E_MOUSEDOWN2: case E_MOUSEDOWN: if(mouseinrange(&m->info,data) == 0) return(0); mm.data = data; y = mm.info.y - 1 - m->info.y; m->selected = y / 6 + m->viewstart; if(m->selected >= m->numitems) m->selected = m->numitems - 1; if(event == E_MOUSEDOWN) { if(m->click) m->click(m->user,m->items[m->selected]); } else { if(m->click2) m->click2(m->user,m->items[m->selected]); } return(1); case E_REFRESH: if(m->refresh(m,1) == 0) { //start refresh, dont continue if error if(m->click) m->click(m->user,0); m->numitems = 0; m->viewstart = 0; m->scrollbar.max = 0; //if we need the .. if(data) strcpy(m->items[m->numitems++],".."); //copy all items to list for(m->selected=-1;(str=m->refresh(m,0)) != 0;) strcpy(m->items[m->numitems++],str); m->scrollbar.max = m->numitems; } if(m->refresh(m,1+2) == 0) { //start refresh, dont continue if error //copy all items to list for(m->selected=-1;(str=m->refresh(m,0+2)) != 0;) sprintf(m->items[m->numitems++],"[%s]",str); m->scrollbar.max = m->numitems; } return(1); } return(0); }
/** @copydoc popup_struct::event_func */ static int popup_event_func(popup_struct *popup, SDL_Event *event) { if (scrollbar_event(&scrollbar, event)) { return 1; } if (book_help_history_enabled && BUTTON_CHECK_TOOLTIP(&popup->button_left.button)) { tooltip_create(event->motion.x, event->motion.y, FONT_ARIAL11, "Go back"); tooltip_enable_delay(300); } /* Mouse event and the mouse is inside the book. */ if (event->type == SDL_MOUSEBUTTONDOWN && event->motion.x >= popup->x && event->motion.x < popup->x + popup->surface->w && event->motion.y >= popup->y && event->motion.y < popup->y + popup->surface->h) { /* Scroll the book. */ if (event->button.button == SDL_BUTTON_WHEELDOWN) { scrollbar_scroll_adjust(&scrollbar, 1); return 1; } else if (event->button.button == SDL_BUTTON_WHEELUP) { scrollbar_scroll_adjust(&scrollbar, -1); return 1; } } else if (event->type == SDL_KEYDOWN) { /* Scrolling. */ if (event->key.keysym.sym == SDLK_DOWN) { scrollbar_scroll_adjust(&scrollbar, 1); return 1; } else if (event->key.keysym.sym == SDLK_UP) { scrollbar_scroll_adjust(&scrollbar, -1); return 1; } else if (event->key.keysym.sym == SDLK_PAGEDOWN) { scrollbar_scroll_adjust(&scrollbar, book_scroll_lines); return 1; } else if (event->key.keysym.sym == SDLK_PAGEUP) { scrollbar_scroll_adjust(&scrollbar, -book_scroll_lines); return 1; } } return -1; }
/** * Handle mouse events for one list. Checking whether the mouse is over * the list should have been done before calling this. * @param list * The list. * @param event * Event. * @return * 1 if the event was handled, 0 otherwise. */ int list_handle_mouse(list_struct *list, SDL_Event *event) { uint32_t row, col, old_highlighted, old_selected; int mx, my; if (!list) { return 0; } if (event->type != SDL_MOUSEBUTTONDOWN && event->type != SDL_MOUSEBUTTONUP && event->type != SDL_MOUSEMOTION) { return 0; } mx = event->motion.x - list->px; my = event->motion.y - list->py; if (list->scrollbar_enabled) { list->scrollbar.px = list->px; list->scrollbar.py = list->py; if (scrollbar_event(&list->scrollbar, event)) { return 1; } } if (!LIST_MOUSE_OVER(list, mx, my)) { return 0; } old_highlighted = list->row_highlighted; old_selected = list->row_selected; /* No row is highlighted now. Will be switched back on as needed * below. */ list->row_highlighted = 0; if (list_mouse_get_pos(list, event->motion.x, event->motion.y, &row, &col)) { if (list->handle_mouse_row_func) { list->handle_mouse_row_func(list, row, event); } /* Mouse click? */ if (event->type == SDL_MOUSEBUTTONDOWN && event->button.button == SDL_BUTTON_LEFT) { /* See if we clicked on this row earlier, and whether this * should be considered a double click. */ if (SDL_GetTicks() - list->click_tick < DOUBLE_CLICK_DELAY) { /* Double click, handle it as if enter was used. */ if (list->handle_enter_func) { list->handle_enter_func(list, event); list->click_tick = 0; } /* Update selected row (in case enter handling * function did not actually jump to another GUI, * thus removing the need for this list). */ list->row_selected = row + 1; } else { /* Normal click. */ /* Update selected row and click ticks for above * double click calculation. */ list->row_selected = row + 1; list->click_tick = SDL_GetTicks(); } } else { /* Not a mouse click, so update highlighted row. */ list->row_highlighted = row + 1; } } /* Handle mouse wheel for scrolling. */ if (event->type == SDL_MOUSEBUTTONDOWN && (event->button.button == SDL_BUTTON_WHEELUP || event->button.button == SDL_BUTTON_WHEELDOWN)) { list_scroll(list, event->button.button == SDL_BUTTON_WHEELUP, 1); return 1; } if (old_highlighted != list->row_highlighted || old_selected != list->row_selected) { return 1; } return 0; }
/** @copydoc widgetdata::event_func */ static int widget_event(widgetdata *widget, SDL_Event *event) { size_t i; if (list_mplayer) { if (list_handle_mouse(list_mplayer, event)) { widget->redraw = 1; return 1; } else if (scrollbar_event(&scrollbar_progress, event)) { widget->redraw = 1; return 1; } } for (i = 0; i < BUTTON_NUM; i++) { if (button_event(&buttons[i], event)) { switch (i) { case BUTTON_PLAY: if (sound_map_background(-1)) { sound_start_bg_music("no_music", 0, 0); sound_map_background(0); shuffle = 0; } else { list_handle_enter(list_mplayer, event); } break; case BUTTON_SHUFFLE: shuffle = !shuffle; if (shuffle) { mplayer_do_shuffle(list_mplayer); sound_map_background(1); } else { sound_start_bg_music("no_music", 0, 0); sound_map_background(0); } break; case BUTTON_BLACKLIST: /* Toggle the blacklist state of the selected row. */ mplayer_blacklist_toggle(list_mplayer); mplayer_blacklist_save(list_mplayer); break; case BUTTON_CLOSE: widget->show = 0; break; case BUTTON_HELP: help_show("music player"); break; } widget->redraw = 1; return 1; } if (buttons[i].redraw) { widget->redraw = 1; } } return 0; }