void meh_exec_popup_start_random_executable(App* app, Screen* screen) { g_assert(app != NULL); g_assert(screen != NULL); SimplePopupData* data = meh_simple_popup_get_data(screen); ExecutableListData* exec_list_data = meh_exec_list_get_data(data->src_screen); /* get a random executable */ int platform_id = exec_list_data->platform->id; Executable* executable = meh_db_get_platform_random_executable(app->db, platform_id); if (executable) { Platform* platform = meh_db_get_platform(app->db, platform_id); if (platform) { /* keep some infos */ PlatformListData* platform_list_data = meh_screen_platform_list_get_data(data->src_screen->parent_screen); int cursor_platform = platform_list_data->selected_platform; int cursor_exec = exec_list_data->selected_executable; meh_app_start_executable(app, platform, executable); /* destroy screens view */ meh_screen_destroy(data->src_screen->parent_screen); data->src_screen->parent_screen = NULL; platform_list_data = NULL; meh_screen_destroy(data->src_screen); app->current_screen = NULL; exec_list_data = NULL; /* recreate the executable list view */ data->src_screen = meh_exec_list_new(app, platform->id); exec_list_data = meh_exec_list_get_data(data->src_screen); /* restore the cursor position */ exec_list_data->selected_executable = cursor_exec; meh_exec_list_after_cursor_move(app, data->src_screen, 0); /* recreate the parent screen which is the platform list */ Screen* platform_screen = meh_screen_platform_list_new(app); data->src_screen->parent_screen = platform_screen; /* restore the cursor position */ platform_list_data = meh_screen_platform_list_get_data(platform_screen); platform_list_data->selected_platform = cursor_platform; meh_screen_platform_change_platform(app, platform_screen); meh_model_platform_destroy(platform); } meh_model_executable_destroy(executable); } }
void meh_exec_selection_render(App* app, Screen* screen) { ExecutableListData* data = meh_exec_list_get_data(screen); /* selection */ meh_widget_rect_render(app->window, data->selection_widget); /* render all the executables names. */ for (unsigned int i = 0; i < g_queue_get_length(data->executable_widgets); i++) { meh_widget_text_render(app->window, g_queue_peek_nth(data->executable_widgets, i)); } }
void meh_exec_selection_destroy(Screen* screen) { g_assert(screen != NULL); ExecutableListData* data = meh_exec_list_get_data(screen); /* Selection */ meh_widget_rect_destroy(data->selection_widget); /* Executables */ for (unsigned int i = 0; i < g_queue_get_length(data->executable_widgets); i++) { meh_widget_text_destroy( g_queue_peek_nth( data->executable_widgets, i) ); } g_queue_free(data->executable_widgets); }
void meh_exec_selection_prepare(App* app, Screen* screen) { g_assert(app != NULL); g_assert(screen != NULL); ExecutableListData* data = meh_exec_list_get_data(screen); SDL_Color white = { 255, 255, 255, 255 }; SDL_Color white_transparent = { 255, 255, 255, 50 }; /* Selection */ data->selection_widget = meh_widget_rect_new(0, -100, 415, 28, white_transparent, TRUE); data->selection_widget->y = meh_transition_start(MEH_TRANSITION_CUBIC, -100, 130, 500); meh_screen_add_rect_transitions(screen, data->selection_widget); /* Executables */ for (int i = 0; i < MEH_EXEC_LIST_SIZE; i++) { WidgetText* text = meh_widget_text_new(app->small_font, "", 55, 130+(i*32), 350, 30, white, FALSE); text->uppercase = TRUE; /* executables name in uppercase */ g_queue_push_tail(data->executable_widgets, text); } }
/* * meh_exec_list_refresh_executables_widget re-creates all the texture * in the text widgets for the executables. */ void meh_exec_selection_refresh_executables_widgets(App* app, Screen* screen) { ExecutableListData* data = meh_exec_list_get_data(screen); int page = (data->selected_executable / (MEH_EXEC_LIST_SIZE)); /* for every executable text widget */ for (unsigned int i = 0; i < g_queue_get_length(data->executable_widgets); i++) { WidgetText* text = g_queue_peek_nth(data->executable_widgets, i); text->text = ""; /* look for the executable text if any */ int executable_idx = page*(MEH_EXEC_LIST_SIZE) + i; if (executable_idx <= data->executables_length) { Executable* executable = g_queue_peek_nth(data->executables, executable_idx); if (executable != NULL) { text->text = executable->display_name; } } /* reload the text texture. */ meh_widget_text_reload(app->window, text); } }
static void meh_screen_popup_favorite_toggle(App* app, Screen* screen) { g_assert(app != NULL); g_assert(screen != NULL); PopupData* data = meh_screen_popup_get_data(screen); ExecutableListData* exec_list_data = meh_exec_list_get_data(data->src_screen); /* updates the value of the executable */ gboolean new_value = data->executable->favorite == 1 ? FALSE : TRUE; if (meh_db_set_executable_favorite(app->db, data->executable, new_value)) { data->executable->favorite = new_value; } /* re-position the executable in the executables list if necessary */ if (g_queue_get_length(exec_list_data->executables) > 1) { int prev_selected = exec_list_data->selected_executable; unsigned int i = 0; /* retrieves the one which will move in the list */ Executable* to_move = g_queue_pop_nth(exec_list_data->executables, exec_list_data->selected_executable); /* find the good position for the moved executable */ for (i = 0; i < g_queue_get_length(exec_list_data->executables); i++) { gboolean exit = FALSE; Executable* ex = g_queue_peek_nth(exec_list_data->executables, i); /* if favorite, ensure to stay in the favorite zone */ if (new_value == TRUE) { if (ex->favorite == FALSE) { exit = TRUE; } } gchar* first = g_utf8_strup(ex->display_name, g_utf8_strlen(ex->display_name, -1)); gchar* second = g_utf8_strup(data->executable->display_name, g_utf8_strlen(ex->display_name, -1)); if (g_utf8_collate(first, second) > 0) { if (new_value == TRUE && ex->favorite == TRUE) { exit = TRUE; } else if (new_value == FALSE && ex->favorite == FALSE) { exit = TRUE; } } g_free(first); g_free(second); if (exit) { break; } } GList* after = g_queue_peek_nth_link(exec_list_data->executables, i); /* re-add it to the good position */ g_queue_insert_before(exec_list_data->executables, after, to_move); /* notify the screen of the new selected executable */ exec_list_data->selected_executable = i; /* redraw the executables list texts */ meh_exec_list_refresh_executables_widget(app, data->src_screen); /* move and redraw the selection */ meh_exec_list_after_cursor_move(app, data->src_screen, prev_selected); } /* finally close the popup */ meh_screen_popup_close(screen); }