// handle the user input events (mainly the touch events) inside the ui handler static void ui_handle_mouse_input(int* curPos) { pthread_mutex_lock(&key_queue_mutex); //In this case MENU_SELECT icon has maximum possible height. int menu_max_height = gr_get_height(gMenuIcon[MENU_SELECT]); struct { int x; int y; int xL; int xR; } MENU_ICON[] = { { gr_fb_width() - menu_max_height, 7*gr_fb_height()/8, 3*gr_fb_height()/4, 4*gr_fb_height()/4 }, { gr_fb_width() - menu_max_height, 5*gr_fb_height()/8, 2*gr_fb_height()/4, 3*gr_fb_height()/4 }, { gr_fb_width() - menu_max_height, 3*gr_fb_height()/8, 1*gr_fb_height()/4, 2*gr_fb_height()/4 }, { gr_fb_width() - menu_max_height, 1*gr_fb_height()/8, 0*gr_fb_height()/4, 1*gr_fb_height()/4 }, }; if (show_menu) { if (curPos[0] > 0) { int position = gr_fb_height() - curPos[1]; //ui_print("Pressure:%d\tX:%d\tY:%d\n",mousePos[0],mousePos[1],mousePos[2]); pthread_mutex_lock(&gUpdateMutex); if(position > MENU_ICON[MENU_BACK].xL && position < MENU_ICON[MENU_BACK].xR && selMenuIcon != MENU_BACK) { draw_icon_locked(gMenuIcon[selMenuIcon], MENU_ICON[selMenuIcon].x, MENU_ICON[selMenuIcon].y ); draw_icon_locked(gMenuIcon[MENU_BACK_M], MENU_ICON[MENU_BACK].x, MENU_ICON[MENU_BACK].y ); selMenuIcon = MENU_BACK; gr_flip(); } else if(position > MENU_ICON[MENU_DOWN].xL && position < MENU_ICON[MENU_DOWN].xR && selMenuIcon != MENU_DOWN) { draw_icon_locked(gMenuIcon[selMenuIcon], MENU_ICON[selMenuIcon].x, MENU_ICON[selMenuIcon].y ); draw_icon_locked(gMenuIcon[MENU_DOWN_M], MENU_ICON[MENU_DOWN].x, MENU_ICON[MENU_DOWN].y); selMenuIcon = MENU_DOWN; gr_flip(); } else if(position > MENU_ICON[MENU_UP].xL && position < MENU_ICON[MENU_UP].xR && selMenuIcon != MENU_UP) { draw_icon_locked(gMenuIcon[selMenuIcon], MENU_ICON[selMenuIcon].x, MENU_ICON[selMenuIcon].y ); draw_icon_locked(gMenuIcon[MENU_UP_M], MENU_ICON[MENU_UP].x, MENU_ICON[MENU_UP].y ); selMenuIcon = MENU_UP; gr_flip(); } else if(position > MENU_ICON[MENU_SELECT].xL && position < MENU_ICON[MENU_SELECT].xR && selMenuIcon != MENU_SELECT) { draw_icon_locked(gMenuIcon[selMenuIcon], MENU_ICON[selMenuIcon].x, MENU_ICON[selMenuIcon].y ); draw_icon_locked(gMenuIcon[MENU_SELECT_M], MENU_ICON[MENU_SELECT].x, MENU_ICON[MENU_SELECT].y ); selMenuIcon = MENU_SELECT; gr_flip(); } key_queue_len_back = key_queue_len; pthread_mutex_unlock(&gUpdateMutex); } } pthread_mutex_unlock(&key_queue_mutex); }
// Redraw everything on the screen. Does not flip pages. // Should only be called with gUpdateMutex locked. static void draw_screen_locked(void) { if (!ui_has_initialized) return; //In this case MENU_SELECT icon has maximum possible height. int menu_max_height = gr_get_height(gMenuIcon[MENU_SELECT]); struct { int x; int y; } MENU_ICON[] = { { gr_fb_width() - menu_max_height, 7*gr_fb_height()/8 }, { gr_fb_width() - menu_max_height, 5*gr_fb_height()/8 }, { gr_fb_width() - menu_max_height, 3*gr_fb_height()/8 }, { gr_fb_width() - menu_max_height, 1*gr_fb_height()/8 }, }; draw_background_locked(gCurrentIcon); draw_progress_locked(); if (show_text) { gr_color(0, 0, 0, 160); gr_fill(0, 0, gr_fb_width(), gr_fb_height()); int i = 0; int j = 0; int row = 0; // current row that we are drawing on if (show_menu) { draw_icon_locked(gMenuIcon[MENU_BACK], MENU_ICON[MENU_BACK].x, MENU_ICON[MENU_BACK].y ); draw_icon_locked(gMenuIcon[MENU_DOWN], MENU_ICON[MENU_DOWN].x, MENU_ICON[MENU_DOWN].y); draw_icon_locked(gMenuIcon[MENU_UP], MENU_ICON[MENU_UP].x, MENU_ICON[MENU_UP].y ); draw_icon_locked(gMenuIcon[MENU_SELECT], MENU_ICON[MENU_SELECT].x, MENU_ICON[MENU_SELECT].y ); gr_color(MENU_TEXT_COLOR); gr_fill(0, (menu_top + menu_sel - menu_show_start) * CHAR_HEIGHT, gr_fb_width()-menu_max_height*2, (menu_top + menu_sel - menu_show_start + 1)*CHAR_HEIGHT+1); gr_color(HEADER_TEXT_COLOR); for (i = 0; i < menu_top; ++i) { draw_text_line(i, menu[i]); row++; } if (menu_items - menu_show_start + menu_top >= MAX_ROWS) j = MAX_ROWS - menu_top; else j = menu_items - menu_show_start; gr_color(MENU_TEXT_COLOR); for (i = menu_show_start + menu_top; i < (menu_show_start + menu_top + j); ++i) { if (i == menu_top + menu_sel) { gr_color(255, 255, 255, 255); draw_text_line(i - menu_show_start , menu[i]); gr_color(MENU_TEXT_COLOR); } else { gr_color(MENU_TEXT_COLOR); draw_text_line(i - menu_show_start, menu[i]); } row++; } gr_fill(0, row*CHAR_HEIGHT+CHAR_HEIGHT/2-1, gr_fb_width()-menu_max_height*2, row*CHAR_HEIGHT+CHAR_HEIGHT/2+1); } gr_color(NORMAL_TEXT_COLOR); for (; row < text_rows; ++row) { draw_text_line(row, text[(row+text_top) % text_rows]); } } }
// Redraw everything on the screen. Does not flip pages. // Should only be called with gUpdateMutex locked. void draw_screen_locked(void) { if (!ui_has_initialized) return; #ifdef BUILD_IN_LANDSCAPE //In this case MENU_SELECT icon has maximum possible height. int menu_max_height = gr_get_height(gMenuIcon[MENU_SELECT]); struct { int x; int y; } MENU_ICON[] = { { gr_fb_width() - menu_max_height, 7*gr_fb_height()/8 }, { gr_fb_width() - menu_max_height, 5*gr_fb_height()/8 }, { gr_fb_width() - menu_max_height, 3*gr_fb_height()/8 }, { gr_fb_width() - menu_max_height, 1*gr_fb_height()/8 }, #else //ToDo: Following structure should be global struct { int x; int y; int xL; int xR; } MENU_ICON[] = { { get_menu_icon_info(MENU_BACK,MENU_ICON_X), get_menu_icon_info(MENU_BACK,MENU_ICON_Y), get_menu_icon_info(MENU_BACK,MENU_ICON_XL), get_menu_icon_info(MENU_BACK,MENU_ICON_XR) }, { get_menu_icon_info(MENU_DOWN,MENU_ICON_X), get_menu_icon_info(MENU_DOWN,MENU_ICON_Y), get_menu_icon_info(MENU_DOWN,MENU_ICON_XL), get_menu_icon_info(MENU_DOWN,MENU_ICON_XR) }, { get_menu_icon_info(MENU_UP,MENU_ICON_X), get_menu_icon_info(MENU_UP,MENU_ICON_Y), get_menu_icon_info(MENU_UP,MENU_ICON_XL), get_menu_icon_info(MENU_UP,MENU_ICON_XR) }, { get_menu_icon_info(MENU_SELECT,MENU_ICON_X), get_menu_icon_info(MENU_SELECT,MENU_ICON_Y), get_menu_icon_info(MENU_SELECT,MENU_ICON_XL), get_menu_icon_info(MENU_SELECT,MENU_ICON_XR) }, #endif }; draw_background_locked(gCurrentIcon); draw_progress_locked(); if (show_text) { gr_color(0, 0, 0, 160); gr_fill(0, 0, gr_fb_width(), gr_fb_height()); int total_rows = gr_fb_height() / CHAR_HEIGHT+1; int i = 0; int j = 0; int row = 0; // current row that we are drawing on if (show_menu) { draw_icon_locked(gMenuIcon[MENU_BACK], MENU_ICON[MENU_BACK].x, MENU_ICON[MENU_BACK].y ); draw_icon_locked(gMenuIcon[MENU_DOWN], MENU_ICON[MENU_DOWN].x, MENU_ICON[MENU_DOWN].y); draw_icon_locked(gMenuIcon[MENU_UP], MENU_ICON[MENU_UP].x, MENU_ICON[MENU_UP].y ); draw_icon_locked(gMenuIcon[MENU_SELECT], MENU_ICON[MENU_SELECT].x, MENU_ICON[MENU_SELECT].y ); // Setup our text colors gr_color(UICOLOR0, UICOLOR1, UICOLOR2, 255); gr_color(UICOLOR0, UICOLOR1, UICOLOR2, 255); gr_fill(0, (menu_top + menu_sel - menu_show_start) * CHAR_HEIGHT, #ifdef BUILD_IN_LANDSCAPE gr_fb_width()-menu_max_height*2, (menu_top + menu_sel - menu_show_start + 1)*CHAR_HEIGHT+1); #else gr_fb_width(), (menu_top + menu_sel - menu_show_start + 1)*CHAR_HEIGHT+1); #endif gr_color(HEADER_TEXT_COLOR); for (i = 0; i < menu_top; ++i) { draw_text_line(i, menu[i], LEFT_ALIGN); row++; } if (menu_items - menu_show_start + menu_top >= MAX_ROWS) j = MAX_ROWS - menu_top; else j = menu_items - menu_show_start; gr_color(UICOLOR0, UICOLOR1, UICOLOR2, 255); for (i = menu_show_start + menu_top; i < (menu_show_start + menu_top + j); ++i) { if (i == menu_top + menu_sel) { gr_color(255, 255, 255, 255); draw_text_line(i - menu_show_start , menu[i], LEFT_ALIGN); gr_color(UICOLOR0, UICOLOR1, UICOLOR2, 255); } else { gr_color(UICOLOR0, UICOLOR1, UICOLOR2, 255); draw_text_line(i - menu_show_start, menu[i], LEFT_ALIGN); } row++; if (row >= max_menu_rows) break; } gr_fill(0, row*CHAR_HEIGHT+CHAR_HEIGHT/2-1, #ifdef BUILD_IN_LANDSCAPE gr_fb_width()-menu_max_height*2, row*CHAR_HEIGHT+CHAR_HEIGHT/2+1); #else gr_fb_width(), row*CHAR_HEIGHT+CHAR_HEIGHT/2+1); #endif } gr_color(NORMAL_TEXT_COLOR); for (; row < text_rows; ++row) { draw_text_line(row + 1, text[(row+text_top) % text_rows], LEFT_ALIGN); } } }