int WNDMGR_Main() { SDL_Event test_event; int timer; SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_NewTimerCallback callback, void *param); SDL_AddTimer(50,wndmgr_Redraw,NULL); WNDMGR_Running = 1; gEventsAllowed = 1; while(WNDMGR_Running) { while(SDL_PollEvent(&test_event)) { if(gEventsAllowed) CurWindow->EventHandler(test_event); switch(test_event.type) { case SDL_QUIT: WNDMGR_Running=0; printf("exit program\n"); break; default: break; } if(windowswitch) windowswitch=0; else SDL_WidgetEvent(&test_event); } SDL_Delay(25); /* To reduce CPU load */ } return 1; }
/* 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; }