int SDL_ToggleButtonEventHandler(SDL_Widget *widget,SDL_Event *event) { SDL_ToggleButton *Button=(SDL_ToggleButton*)widget; switch(event->type) { case SDL_MOUSEMOTION: if(SDL_WidgetIsInside(widget,event->motion.x,event->motion.y)) { if(Button->State == SDL_BUTTON_STATE_UP) { Button->State = SDL_BUTTON_STATE_HIGHLIGHTED; SDL_WidgetRedrawEvent(widget); } } else Button->State = SDL_BUTTON_STATE_UP; break; case SDL_MOUSEBUTTONUP: if(SDL_WidgetIsInside(widget,event->motion.x,event->motion.y)) { Button->State = SDL_BUTTON_STATE_HIGHLIGHTED; SDL_WidgetRedrawEvent(widget); } else Button->State = SDL_BUTTON_STATE_UP; break; default: break; } return 0; }
int SDL_ProgressBarEventHandler(SDL_Widget *widget, SDL_Event *event) { SDL_ProgressBar *ProgressBar=(SDL_ProgressBar*)widget; switch(event->type) { case SDL_MOUSEBUTTONDOWN: if(SDL_WidgetIsInside(widget,event->motion.x,event->motion.y)) { if(ProgressBar->Orientation == HORIZONTAL) { ProgressBar->State=PROGRESSBAR_DRAG; ProgressBar->CurrentLine = event->motion.x - widget->Rect.x; ProgressBar_CurrentValue(ProgressBar); SDL_WidgetRedrawEvent(widget); } } break; case SDL_MOUSEMOTION: if(ProgressBar->Orientation == HORIZONTAL) { if(ProgressBar->State==PROGRESSBAR_DRAG) { ProgressBar->CurrentLine = event->motion.x - widget->Rect.x; ProgressBar_CurrentValue(ProgressBar); SDL_WidgetRedrawEvent(widget); } } break; case SDL_MOUSEBUTTONUP: if(ProgressBar->State == PROGRESSBAR_DRAG || SDL_WidgetIsInside(widget,event->motion.x,event->motion.y)) { if(ProgressBar->Orientation == VERTICAL) { ProgressBar->CurrentLine = event->motion.y - widget->Rect.y; ProgressBar_CurrentValue(ProgressBar); SDL_WidgetRedrawEvent(widget); } else if(ProgressBar->Orientation == HORIZONTAL) { ProgressBar->CurrentLine = event->motion.x - widget->Rect.x; ProgressBar_CurrentValue(ProgressBar); SDL_WidgetRedrawEvent(widget); } ProgressBar->State=PROGRESSBAR_NORMAL; SDL_SignalEmit(widget,"clicked"); } break; default: break; } return 0; }
static void SDL_ButtonSignalMouseButtonDown(SDL_Object *object,void *signaldata,void *userdata) { SDL_Button *Button = (SDL_Button*) object; SDL_Event *event = (SDL_Event *) signaldata; SDL_Widget *widget = (SDL_Widget*) object; if(SDL_WidgetIsInside(widget,event->motion.x,event->motion.y) && event->button.button == 1) { Button->State = SDL_BUTTON_STATE_DOWN; SDL_SignalEmit(widget,"clicked",NULL); SDL_WidgetRedrawEvent(widget); } else Button->State = SDL_BUTTON_STATE_UP; }
static void SDL_SignalToggleButtonMouseButtonDown(SDL_Object *object,void *signaldata,void *userdata) { SDL_ToggleButton *Button=(SDL_ToggleButton*)object; SDL_Event *event=(SDL_Event*)signaldata; if(SDL_WidgetIsInside((SDL_Widget*)object,event->motion.x,event->motion.y)) { Button->State = SDL_BUTTON_STATE_DOWN; SDL_SignalObjectEmit(object,"clicked",NULL); SDL_WidgetRedrawEvent((SDL_Widget*)object); } else Button->State = SDL_BUTTON_STATE_UP; userdata=userdata; }
void SDL_WidgetEvent(SDL_Event *event) { T_Widget_EventHandler eh; Stack* current_widget; Stack* focus_widget=NULL; SDL_WidgetLOCK(); switch(event->type) { case SDL_MOUSEBUTTONDOWN: { focus_widget=SDL_StackGetStack(); while(focus_widget) { if(SDL_WidgetIsInside(&focus_widget->dest,event->motion.x,event->motion.y)) { SDL_StackSetFocus(focus_widget); // Bug found when there are overlapping widgets the focus is set to the wrong widget // break; } focus_widget=focus_widget->next; } } break; } current_widget=SDL_StackGetStack(); while(current_widget) { eh=WidgetTable[current_widget->type]->eventhandler; if(eh) { eh(current_widget->data,event); } current_widget=current_widget->next; } SDL_WidgetUNLOCK(); }
static void SDL_ButtonSignalMouseMotion(SDL_Object *object,void *signaldata,void *userdata) { SDL_Button *Button=(SDL_Button*)object; SDL_Event *event = (SDL_Event *)signaldata; SDL_Widget *widget=(SDL_Widget*)object; if(SDL_WidgetIsInside(widget,event->motion.x,event->motion.y)) { if(Button->State == SDL_BUTTON_STATE_UP) { Button->State = SDL_BUTTON_STATE_HIGHLIGHTED; #if 0 if(Button->Style != NULL && Button->Style->Highlighted != NULL) { SDL_WidgetRedrawEvent(widget); } #endif } } }
static void SDL_ButtonSignalMouseButtonUp(SDL_Object *object,void *signaldata,void *userdata) { SDL_Button *Button=(SDL_Button*)object; SDL_Event *event=(SDL_Event *)signaldata; SDL_Widget *widget=(SDL_Widget*)object; if(SDL_WidgetIsInside(widget,event->motion.x,event->motion.y)) { Button->State = SDL_BUTTON_STATE_HIGHLIGHTED; SDL_WidgetRedrawEvent(widget); } else { if(Button->State != SDL_BUTTON_STATE_UP) { Button->State = SDL_BUTTON_STATE_UP; SDL_WidgetRedrawEvent(widget); } } }
/* return 0 if no windows are available */ int SDL_WindowManagerEvent(SDL_Event *event) { SDL_WidgetList* WidgetList; SDL_Widget* focus_widget=NULL; SDL_Window *window; SDL_WindowManagerWindowEvent(event); window = SDL_WindowGetTopVisibleWindow(); if(SDL_WindowAvailable() == 0) return 0; if(window && event->type >= SDL_MOUSEMOTION) { event->motion.xrel = event->motion.x; event->motion.yrel = event->motion.y; event->motion.x -= window->Widget.Rect.x; event->motion.y -= window->Widget.Rect.y; } focus_widget = SDL_WindowGetFocusWidget(); if(event->type == SDL_MOUSEBUTTONDOWN && focus_widget != NULL && SDL_WidgetIsInside(focus_widget,event->motion.x,event->motion.y)) { SDL_WidgetEvent(focus_widget,event); return 1; } if(event->type == SDL_MOUSEBUTTONDOWN) { SDL_WidgetList* focus_widget = SDL_WindowGetWidgetList(); while(focus_widget) { SDL_Widget *w=(SDL_Widget*)focus_widget->Widget; if(SDL_WidgetIsInside(w,event->motion.x,event->motion.y)) { if(focus_widget->Widget->flags & WIDGET_FOCUSABLE) { SDL_WindowSetFocusWidget(focus_widget->Widget); SDL_WidgetRedrawEvent(focus_widget->Widget); } /* Bug found when there are overlapping widgets the focus is set to the wrong widget */ } focus_widget=focus_widget->Next; } } WidgetList = SDL_WindowGetWidgetList(); while(WidgetList) { /* ATTEN: here should be the old value of the WidgetList, if the win->WidgetList value changed in the following * SDL_WidgetEvent() function, then this pointer here could not update immediately. */ SDL_Widget *Widget=(SDL_Widget*)WidgetList->Widget; /* tangg added */ if(Widget && (Widget->flags & WIDGET_VISIBLE)) { SDL_WidgetEvent(Widget,event); } WidgetList=WidgetList->Next; } /* If the widgets don't handle the event pass the event to the event handler of the window */ { SDL_Window *Win; Win=SDL_WindowGetTopVisibleWindow(); if(Win && Win->EventHandler) { Win->EventHandler(*event); } } return 1; }
int SDL_WindowManagerWindowEvent(SDL_Event *event) { SDL_WindowListElem *CurrentWindow = (SDL_WindowListElem*)WindowList.last; SDL_WindowListElem *PreviousWindow = NULL; SDL_WindowListElem *StoredPreviousWindow = NULL; SDL_WindowListElem *StoredWindow = NULL; switch(event->type) { case SDL_KEYDOWN: switch( event->key.keysym.sym ) { case SDLK_TAB: { SDL_Widget *FocusWidget; SDL_WidgetList *WidgetList; SDL_Widget *FirstFocusWidget=NULL; int store=0; WidgetList = SDL_WindowGetWidgetList(); FocusWidget = SDL_WindowGetFocusWidget(); while(WidgetList) { if(FocusWidget == NULL) { if(WidgetList->Widget->flags & WIDGET_FOCUSABLE) { SDL_WindowSetFocusWidget(WidgetList->Widget); break; } } else { if((WidgetList->Widget->flags & WIDGET_FOCUSABLE) && FirstFocusWidget == NULL) FirstFocusWidget=WidgetList->Widget; if(store && (WidgetList->Widget->flags & WIDGET_FOCUSABLE)) { SDL_WindowSetFocusWidget(WidgetList->Widget); break; } if(WidgetList->Widget == FocusWidget) store=1; } WidgetList = WidgetList->Next; } if(WidgetList == NULL) { if(FirstFocusWidget) SDL_WindowSetFocusWidget(FirstFocusWidget); } SDL_WidgetRedrawEvent(FocusWidget); } break; default: break; } break; } if(event->type == SDL_MOUSEBUTTONDOWN && CurrentWindow) { while(CurrentWindow->ll.next) { if(SDL_WidgetIsInside(&CurrentWindow->Window->Widget,event->motion.x,event->motion.y)) { /* Remember the top most visible window which is clicked on */ StoredWindow = CurrentWindow; StoredPreviousWindow = PreviousWindow; } PreviousWindow = CurrentWindow; CurrentWindow = (SDL_WindowListElem*)CurrentWindow->ll.next; } if(StoredWindow) { /* If there is a window click, make sure it becomes the top visible window */ CurrentWindow->ll.next = &StoredWindow->ll; if(StoredPreviousWindow == NULL) WindowList.first = StoredWindow->ll.next; else StoredPreviousWindow->ll.next = StoredWindow->ll.next; StoredWindow->ll.next = NULL; return 1; } } return 0; }
static void SDL_ScrollbarSignalMouseButtonDown(SDL_Object *object,void *signaldata,void *userdata) { SDL_Scrollbar *Scrollbar=(SDL_Scrollbar*)object; SDL_Widget *widget =(SDL_Widget*)object; SDL_Event *Event = (SDL_Event *)signaldata; if(!SDL_WidgetIsInside(widget,Event->motion.x,Event->motion.y)) return; if(Scrollbar->Orientation == VERTICAL) { int ymotion; int height; ymotion = Event->motion.y; height = widget->Rect.h * Scrollbar->NormalStepValue / Scrollbar->MaxValue; /* Height is the button height */ if(height < 6) height = 6; if(Event->button.button == SDL_BUTTON_LEFT) { /* if the button click is below the button */ if(ymotion > (widget->Rect.y + Scrollbar->PixelValue + height)) { SDL_ScrollbarStep(Scrollbar,DOWN,NORMAL_STEP); } /* or on the button */ else if (ymotion > widget->Rect.y + Scrollbar->PixelValue && ymotion < widget->Rect.y + Scrollbar->PixelValue + height) { Scrollbar->offset = ymotion - widget->Rect.y - Scrollbar->PixelValue; Scrollbar->State = SCROLLBAR_DRAG; } else { SDL_ScrollbarStep(Scrollbar,UP,NORMAL_STEP); } } } else { int xmotion; int ymotion; int width; xmotion = Event->motion.x - widget->Rect.x; ymotion = Event->motion.y - widget->Rect.y; width = widget->Rect.w *Scrollbar->NormalStepValue / Scrollbar->MaxValue; /* Height is the button height */ if(width < 6) width = 6; if(Event->button.button == SDL_BUTTON_LEFT) { SDL_Rect dims; SDL_StyleGetSizeInfo(widget,SCROLLBAR_ARROW1,STYLE_STATE_NORMAL,&dims); if(xmotion < dims.w) printf("Clicked inside the arrow1 button\n"); else { xmotion -= dims.w; SDL_StyleGetSizeInfo(widget,SCROLLBAR_ARROW2,STYLE_STATE_NORMAL,&dims); if(xmotion < dims.w) printf("Clicked inside the arrow2 button\n"); else { xmotion -= dims.w; SDL_StyleGetSizeInfo(widget,SCROLLBAR_SCROLLBAR,STYLE_STATE_NORMAL,&dims); if(xmotion < dims.w) printf("Clicked inside the scrollbar button\n"); else { xmotion -= dims.w; SDL_StyleGetSizeInfo(widget,SCROLLBAR_THUMB,STYLE_STATE_NORMAL,&dims); printf("Clicked inside the thumb\n"); } } } #if 0 /* if the button click is right of the thumb */ if(xmotion > (widget->Rect.x + Scrollbar->PixelValue + width)) { SDL_ScrollbarStep(Scrollbar,RIGHT,NORMAL_STEP); } /* or on the thumb */ else if (xmotion > widget->Rect.x + Scrollbar->PixelValue && xmotion < widget->Rect.x + Scrollbar->PixelValue + width) { Scrollbar->offset = xmotion - widget->Rect.x - Scrollbar->PixelValue; Scrollbar->State = SCROLLBAR_DRAG; } else { /* left of the thumb */ SDL_ScrollbarStep(Scrollbar,LEFT,NORMAL_STEP); } #endif } } }