static unsigned _action_cb(u32 button, unsigned flags, void *data) { (void)data; if(! GUI_GetSelected() || lp->selected_for_move < 0 || GUI_IsModal()) return 0; if(CHAN_ButtonIsPressed(button, BUT_EXIT)) { gui->elem[lp->selected_for_move].desc.font_color ^= 0xffff; gui->elem[lp->selected_for_move].desc.fill_color ^= 0xffff; GUI_Redraw((guiObject_t *)&gui->elem[lp->selected_for_move]); set_selected_for_move(-1); return 1; } if(CHAN_ButtonIsPressed(button, BUT_ENTER)) { show_config(); return 1; } if(CHAN_ButtonIsPressed(button, BUT_LEFT)) { xpos_cb(NULL, (flags & BUTTON_LONGPRESS) ? -2 : -1, NULL); return 1; } if(CHAN_ButtonIsPressed(button, BUT_RIGHT)) { xpos_cb(NULL, (flags & BUTTON_LONGPRESS) ? 2 : 1, NULL); return 1; } if(CHAN_ButtonIsPressed(button, BUT_UP)) { ypos_cb(NULL, (flags & BUTTON_LONGPRESS) ? -2 : -1, NULL); return 1; } if(CHAN_ButtonIsPressed(button, BUT_DOWN)) { ypos_cb(NULL, (flags & BUTTON_LONGPRESS) ? 2 : 1, NULL); return 1; } return 0; }
void PAGE_Change(int dir) { if ( modal || GUI_IsModal()) return; if (Model.mixer_mode != 0 || (cur_page >= sizeof(groups) / sizeof(struct page_group) - 1) || groups[cur_page].group & 0x80) { //Don't use left/right on model pages in standard mode return; } u8 nextpage = cur_page; if(dir > 0) { if (groups[nextpage+1].group == groups[cur_page].group) { nextpage++; } else { while(nextpage && groups[nextpage-1].group == groups[cur_page].group) nextpage--; } } else if (dir < 0) { if (nextpage && groups[nextpage-1].group == groups[cur_page].group) { nextpage--; } else { while(groups[nextpage+1].group == groups[cur_page].group) nextpage++; } } if (cur_page == nextpage) return; PAGE_Exit(); PAGE_ChangeByID(groups[nextpage].id); }
void PAGE_SplashEvent() { static unsigned int time=0; #if HAS_EXTENDED_AUDIO static unsigned int time_startup_msg; #endif if(GUI_IsModal()) return; // u8 step = 5; if ( 0 == time ) { time = CLOCK_getms() + Transmitter.splash_delay * 100; #if HAS_EXTENDED_AUDIO time_startup_msg = CLOCK_getms() + 5 * 100; // Dealy 0.5 second to play startup audio #endif } #if HAS_EXTENDED_AUDIO if (time_startup_msg && (CLOCK_getms() > time_startup_msg) ) { AUDIO_SetVolume(); MUSIC_Play(MUSIC_STARTUP); time_startup_msg = 0; } #endif if ( CLOCK_getms() > time ) PAGE_ChangeByID(PAGEID_MAIN,0); /* if ( offset > 0 ) { offset -= step; GUI_ChangeImage(&gui->splash_image,SPLASH_FILE,offset,0); GUI_Redraw(&gui->splash_image); }*/ }
struct guiObject *GUI_GetNextSelectable(struct guiObject *origObj) { struct guiObject *obj = origObj, *foundObj = NULL; if (! objHEAD) return NULL; struct guiObject *modalObj = GUI_IsModal(); if (obj && OBJ_IS_SCROLLABLE(obj)) { //The current selected object is scrollable guiScrollable_t *scroll = GUI_FindScrollableParent(obj); obj = GUI_ScrollableGetNextSelectable(scroll, obj); if (obj) return obj; obj = (guiObject_t *)scroll; } obj = obj ? obj->next : modalObj ? modalObj : objHEAD; while(obj) { if (! OBJ_IS_HIDDEN(obj) && OBJ_IS_SELECTABLE(obj)) { if(obj->Type == Scrollable) { foundObj = GUI_ScrollableGetNextSelectable((guiScrollable_t *)obj, NULL); } else { foundObj = obj; } break; } obj = obj->next; } if (! foundObj && origObj) { return GUI_GetNextSelectable(NULL); } return foundObj; }
void _GUI_RefreshScreen(struct guiObject *headObj) { struct guiObject *modalObj = GUI_IsModal(); struct guiObject *obj; if (FullRedraw) { #ifdef DEBUG_DRAW printf("Full Redraw requested: %d\n", FullRedraw); #endif if (modalObj && modalObj->Type == Dialog && FullRedraw != REDRAW_EVERYTHING) { //Handle Dialog redraw as an incremental FullRedraw = REDRAW_ONLY_DIRTY; } else { GUI_DrawScreen(); return; } } GUI_HideObjects(headObj, modalObj); //Only start drawing from headObj(scrollable) or 1st modal if either is set obj = headObj ? headObj : modalObj ? modalObj : objHEAD; while(obj) { if(! OBJ_IS_HIDDEN(obj)) { if (obj->Type == Scrollable && ((guiScrollable_t *)obj)->head) { //Redraw scrollable contents _GUI_RefreshScreen(((guiScrollable_t *)obj)->head); } else if(OBJ_IS_DIRTY(obj)) { if(OBJ_IS_TRANSPARENT(obj) || OBJ_IS_HIDDEN(obj)) { GUI_DrawBackground(obj->box.x, obj->box.y, obj->box.width, obj->box.height); } GUI_DrawObject(obj); } } obj = obj->next; } }
void PAGE_ChangeByID(enum PageID id, s8 menuPage) { if ( modal || GUI_IsModal()) return; PAGE_SaveCurrentPos(); page_scrollable = NULL; PAGE_Exit(); GUI_SelectionNotify(NULL); cur_page = id; BUTTON_InterruptLongPress(); //Make sure button press is not passed to the new page if (pages[cur_page].init == PAGE_MainInit) quick_page_enabled = 1; else if (pages[cur_page].init == PAGE_MenuInit) quick_page_enabled = 0; PAGE_RemoveAllObjects(); if (HAS_TOUCH) { GUI_ChangeSelectionOnTouch(1); } ActionCB = default_button_action_cb; pages[cur_page].init(menuPage); if (page_scrollable) { guiObject_t *obj = GUI_ShowScrollableRowOffset(page_scrollable, *current_selected); if(! HAS_TOUCH || ! GUI_InTouch()) GUI_SetSelected(obj); } }
void PAGE_SplashEvent() { static unsigned int time=0; if(GUI_IsModal()) return; // u8 step = 5; if ( 0 == time ) time = CLOCK_getms() + Transmitter.splash_delay * 100; if ( CLOCK_getms() > time ) PAGE_ChangeByID(PAGEID_MAIN,0); /* if ( offset > 0 ) { offset -= step; GUI_ChangeImage(&gui->splash_image,SPLASH_FILE,offset,0); GUI_Redraw(&gui->splash_image); }*/ }
struct guiObject *GUI_GetPrevSelectable(struct guiObject *origObj) { struct guiObject *obj, *objLast = NULL; struct guiObject *modalObj; if (origObj && OBJ_IS_SCROLLABLE(origObj)) { //The current selected object is scrollable guiScrollable_t *scroll = GUI_FindScrollableParent(origObj); origObj = GUI_ScrollableGetPrevSelectable(scroll, origObj); if (origObj) return origObj; origObj = (guiObject_t *)scroll; } modalObj = GUI_IsModal(); obj = modalObj ? modalObj : objHEAD; while(obj) { if (obj == origObj) break; if (! OBJ_IS_HIDDEN(obj) && OBJ_IS_SELECTABLE(obj)) { objLast = obj; } obj = obj->next; } if (obj && ! objLast) { obj = obj->next; while(obj) { if (obj == origObj) break; if (! OBJ_IS_HIDDEN(obj) && OBJ_IS_SELECTABLE(obj)) { objLast = obj; } obj = obj->next; } } if (! objLast) objLast = origObj; if (objLast && objLast->Type == Scrollable) return GUI_ScrollableGetPrevSelectable((guiScrollable_t *)objLast, NULL); return objLast; }
unsigned handle_buttons(u32 button, unsigned flags, void *data) { (void)data; //When modal, we capture all button presses int modalActive = GUI_IsModal() ? 1 : 0; if(USE_4BUTTON_MODE) { // IN 4 button mode, up/down can also act as left/right for TextSelect if (objACTIVE) { if (CHAN_ButtonIsPressed(button, BUT_UP)) { button = CHAN_ButtonMask(BUT_LEFT); } else if (CHAN_ButtonIsPressed(button, BUT_DOWN)) { button = CHAN_ButtonMask(BUT_RIGHT); } else if (CHAN_ButtonIsPressed(button, BUT_ENTER)) { if (flags & BUTTON_RELEASE) objACTIVE = NULL; } else if (CHAN_ButtonIsPressed(button, BUT_EXIT)) { if (flags & BUTTON_RELEASE) objACTIVE = NULL; return 1; } } else { if (objSELECTED && CHAN_ButtonIsPressed(button, BUT_ENTER) && objSELECTED->Type == TextSelect) { if (flags & BUTTON_RELEASE) { objACTIVE = objSELECTED; } return 1; } } } //printf("Button: %08x Flags: %08x Active: %08x\n", button, flags, objACTIVE); if (CHAN_ButtonIsPressed(button, BUT_LEFT) || CHAN_ButtonIsPressed(button, BUT_RIGHT) || CHAN_ButtonIsPressed(button, BUT_ENTER)) { // Widgets can only handle Left, Right and Enter if (objSELECTED) return GUI_ObjButton(objSELECTED, button, flags) || modalActive; return modalActive; } if (flags & (BUTTON_LONGPRESS | BUTTON_RELEASE)) { if ((flags & BUTTON_HAD_LONGPRESS) & (flags & BUTTON_RELEASE)) { //ignore long-press release return modalActive; } else if (CHAN_ButtonIsPressed(button, BUT_DOWN) || CHAN_ButtonIsPressed(button, BUT_UP)) { struct guiObject *obj = (CHAN_ButtonIsPressed(button, BUT_DOWN) || ! objSELECTED) ? GUI_GetNextSelectable(objSELECTED) : GUI_GetPrevSelectable(objSELECTED); if (obj && obj != objSELECTED) { GUI_SetSelected(obj); } } else if (! (flags & BUTTON_LONGPRESS) && objSELECTED && CHAN_ButtonIsPressed(button, BUT_EXIT)) { if (objDIALOG) { //Why doesn't the dialog handle its own buttons? DialogClose(objDIALOG, 0); } else { OBJ_SET_DIRTY(objSELECTED, 1); objSELECTED = NULL; if (select_notify) select_notify(objSELECTED); } } } else if (! objSELECTED && CHAN_ButtonIsPressed(button, BUT_EXIT)) { // We need to tell the button handler that we will handle this press // But we ignore an EXIT if there is nothing selected return modalActive; } return 1; }
u8 _GUI_CheckTouch(struct touch *coords, u8 long_press, struct guiObject *headObj) { struct guiObject *modalObj = GUI_IsModal(); struct guiObject *obj = headObj ? headObj : modalObj ? modalObj : objHEAD; while(obj) { if (! OBJ_IS_HIDDEN(obj)) { switch (obj->Type) { case UnknownGUI: case Dialog: case CheckBox: case Dropdown: case BarGraph: case Rect: break; case Button: if (coords_in_box(&obj->box, coords)) { if (objTOUCHED && objTOUCHED != obj) return 0; objTOUCHED = obj; return GUI_TouchButton(obj, long_press); } break; case Image: if (((guiImage_t *)obj)->callback && coords_in_box(&obj->box, coords)) { if (objTOUCHED && objTOUCHED != obj) return 0; objTOUCHED = obj; return GUI_TouchImage(obj, coords, long_press); } break; case Label: if (((guiLabel_t *)obj)->pressCallback && coords_in_box(&obj->box, coords)) { if (objTOUCHED && objTOUCHED != obj) return 0; objTOUCHED = obj; return GUI_TouchLabel(obj, coords, long_press); } break; case TextSelect: if(coords_in_box(&obj->box, coords)) { if (objTOUCHED && objTOUCHED != obj) return 0; objTOUCHED = obj; return GUI_TouchTextSelect(obj, coords, long_press); } break; case XYGraph: if(((guiXYGraph_t *)obj)->touch_cb && coords_in_box(&obj->box, coords)) { if (objTOUCHED && objTOUCHED != obj) return 0; objTOUCHED = obj; return GUI_TouchXYGraph(obj, coords, long_press); } break; case Keyboard: //Note that this only works because the keyboard encompasses the whole screen if (objTOUCHED && objTOUCHED != obj) return 0; objTOUCHED = obj; return GUI_TouchKeyboard(obj, coords, long_press); break; case Scrollbar: if(coords_in_box(&obj->box, coords)) { if (objTOUCHED && objTOUCHED != obj) return 0; objTOUCHED = obj; return GUI_TouchScrollbar(obj, coords, long_press); } break; case Scrollable: if(coords_in_box(&obj->box, coords)) { int ret = _GUI_CheckTouch(coords, long_press, ((guiScrollable_t *)obj)->head); return ret; } } } obj = obj->next; } return 0; }