/** * @brief Handles the mouse events. * * @param wdw Window recieving the mouse event. * @param event Mouse event to handle. */ static void toolkit_mouseEvent( Window *w, SDL_Event* event ) { Widget *wgt; Uint8 type, button; int x, y, rx, ry; /* Translate mouse coords. */ type = toolkit_inputTranslateCoords( w, event, &x, &y, &rx, &ry, 1 ); /* Check each widget. */ for (wgt=w->widgets; wgt!=NULL; wgt=wgt->next) { /* custom widgets take it from here */ if (wgt->type==WIDGET_CUST) { if (wgt->dat.cst.mouse) wgt->dat.cst.mouse( w->id, event, x-wgt->x, y-wgt->y, wgt->w, wgt->h, wgt->dat.cst.userdata ); } else { /* Handle mouse event. */ if (type == SDL_MOUSEMOTION) button = event->motion.state; else button = event->button.button; toolkit_mouseEventWidget( w, wgt, type, button, x, y, rx, ry ); } } }
/** * @brief Handles mouse events. */ static int tab_mouse( Widget* tab, SDL_Event *event ) { int i, p, change; Window *parent; int x, y, rx, ry; /* Get parent window. */ parent = window_wget( tab->wdw ); if (parent == NULL) return 0; /* Convert to window space. */ toolkit_inputTranslateCoords( parent, event, &x, &y, &rx, &ry ); /* Translate to widget space. */ x += parent->w - tab->x; y += parent->h - tab->y; /* Make sure event is in bottom 20 pixels. */ if ((y>=TAB_HEIGHT) || (y<0)) return 0; /* Handle event. */ p = 20; for (i=0; i<tab->dat.tab.ntabs; i++) { p += 10 + tab->dat.tab.namelen[i]; /* Mark as active. */ if (x < p) { change = -1; if (event->button.button == SDL_BUTTON_WHEELUP) change = (tab->dat.tab.active - 1) % tab->dat.tab.ntabs; else if (event->button.button == SDL_BUTTON_WHEELDOWN) change = (tab->dat.tab.active + 1) % tab->dat.tab.ntabs; else tab->dat.tab.active =i; if ((change != -1) && (change < tab->dat.tab.ntabs)) tab->dat.tab.active = change; /* Create event. */ if (tab->dat.tab.onChange != NULL) tab->dat.tab.onChange( tab->wdw, tab->name, tab->dat.tab.active ); break; } } return 0; }
/** * @brief Handles mouse events. */ static int tab_mouse( Widget* tab, SDL_Event *event ) { int i, p; Window *parent; int x, y, rx, ry; Uint8 type; /* Get parrent window. */ parent = window_wget( tab->wdw ); if (parent == NULL) return 0; /* Convert to window space. */ type = toolkit_inputTranslateCoords( parent, event, &x, &y, &rx, &ry, 0 ); /* Translate to widget space. */ x += parent->w - tab->x; y += parent->h - tab->y; /* Make sure event is in bottom 20 pixels. */ if ((y>=TAB_HEIGHT) || (y<0)) return 0; /* Handle event. */ p = 20; for (i=0; i<tab->dat.tab.ntabs; i++) { p += 10 + tab->dat.tab.namelen[i]; /* Mark as active. */ if (x < p) { tab->dat.tab.active = i; /* Create event. */ if (tab->dat.tab.onChange != NULL) tab->dat.tab.onChange( tab->wdw, tab->name, tab->dat.tab.active ); break; } } return 0; }