Пример #1
0
/*
 * meh_screen_popup_button_pressed is called when we received a button pressed
 * message.
 */
void meh_screen_popup_button_pressed(App* app, Screen* screen, int pressed_button) {
	g_assert(app != NULL);
	g_assert(screen != NULL);

	PopupData* data = meh_screen_popup_get_data(screen);

	switch (pressed_button) {
		case MEH_INPUT_BUTTON_DOWN:
			meh_screen_popup_move_selection(app, screen, TRUE);
			break;
		case MEH_INPUT_BUTTON_UP:
			meh_screen_popup_move_selection(app, screen, FALSE);
			break;
		case MEH_INPUT_BUTTON_A:
			switch (data->action) {
				case 0:
					meh_screen_popup_favorite_toggle(app, screen);
					break;
				case 1:
					meh_screen_popup_random_executable(app, screen);
					break;
			}
			break;
		/* quit the popup */
		case MEH_INPUT_BUTTON_START:
		case MEH_INPUT_BUTTON_B:
		case MEH_INPUT_SPECIAL_ESCAPE:
			meh_screen_popup_close(app, screen);
			break;
	}
}
Пример #2
0
void meh_screen_popup_render(struct App* app, Screen* screen) {
    PopupData* data = meh_screen_popup_get_data(screen);
    g_assert(data != NULL);

    /* render the background screen */
    gboolean* flip = g_new(gboolean, 1);
    *flip = FALSE;
    meh_message_send(app, data->src_screen, MEH_MSG_RENDER, flip);


    /* render the popup screen */

    meh_widget_rect_render(app->window, data->hover_widget);
    meh_widget_rect_render(app->window, data->background_widget);

    if (data->background_widget->y.ended) {
        /* title */
        meh_widget_rect_render(app->window, data->title_bg_widget);
        meh_widget_text_render(app->window, data->title_widget);

        meh_widget_rect_render(app->window, data->selection_widget);
        meh_widget_text_render(app->window, data->favorite_widget);
    }

    meh_window_render(app->window);
}
Пример #3
0
static void meh_screen_popup_close(Screen* screen) {
    g_assert(screen != NULL);

    PopupData* data = meh_screen_popup_get_data(screen);
    data->background_widget->y = meh_transition_start(MEH_TRANSITION_LINEAR, data->background_widget->y.value, MEH_FAKE_HEIGHT, 150);
    meh_screen_add_rect_transitions(screen, data->background_widget);
    data->quitting = TRUE;
}
Пример #4
0
/*
 * meh_screen_popup_destroy_data destroys the additional data
 * of the popup screen.
 */
void meh_screen_popup_destroy_data(Screen* screen) {
	PopupData* data = meh_screen_popup_get_data(screen);
	meh_widget_rect_destroy(data->hover_widget);
	meh_widget_text_destroy(data->title_widget);
	meh_widget_text_destroy(data->favorite_widget);
	meh_widget_text_destroy(data->random_widget);
	meh_widget_rect_destroy(data->selection_widget);
	screen->data = NULL;
}
Пример #5
0
static void meh_screen_popup_close(App* app, Screen* screen) {
	g_assert(app != NULL);
	g_assert(screen != NULL);

	PopupData* data = meh_screen_popup_get_data(screen);

	meh_app_set_current_screen(app, data->src_screen, TRUE);
	meh_screen_destroy(screen);
	screen = NULL;
}
Пример #6
0
/*
 * meh_screen_popup_update udpates the content of the popup screen.
 */
int meh_screen_popup_update(struct App* app, Screen* screen) {
	/* Animate the fading rect. */
	meh_screen_update_transitions(screen);

	PopupData* data = meh_screen_popup_get_data(screen);

	/* update the src screen */
	meh_message_send(app, data->src_screen, MEH_MSG_UPDATE, NULL);

	return 0;
}
Пример #7
0
/*
 * meh_screen_popup_random_executable starts a random executable of this platform.
 */
static void meh_screen_popup_random_executable(App* app, Screen* screen) {
	g_assert(app != NULL);

	PopupData* data = meh_screen_popup_get_data(screen);

	int platform_id = data->platform->id;

	Executable* executable = meh_db_get_platform_random_executable(app->db, platform_id);
	if (executable) {
		meh_app_start_executable(app, data->platform, executable);
		meh_model_executable_destroy(executable);
	}
}
Пример #8
0
/*
 *
 * meh_popup_button_pressed moves the currently selected position.
 */
static void meh_screen_popup_move_selection(App* app, Screen* screen, gboolean down) {
	g_assert(app);
	g_assert(screen);

	PopupData* data = meh_screen_popup_get_data(screen);
	g_assert(data);

	int old = data->action;

	data->action = data->action == 0 ? 1 : 0;

	data->selection_widget->y = meh_transition_start(MEH_TRANSITION_LINEAR, (data->y+54) + old*32, (data->y+54) + (data->action*32), 100);
	meh_screen_add_rect_transitions(screen, data->selection_widget);
}
Пример #9
0
/*
 * meh_screen_popup_update udpates the content of the popup screen.
 */
int meh_screen_popup_update(struct App* app, Screen* screen) {
    /* Animate the fading rect. */
    meh_screen_update_transitions(screen);

    PopupData* data = meh_screen_popup_get_data(screen);

    /* update the src screen */
    meh_message_send(app, data->src_screen, MEH_MSG_UPDATE, NULL);

    /* quit the screen at the end of the exit animation. */
    if (data->quitting && data->background_widget->y.ended) {
        meh_app_set_current_screen(app, data->src_screen, TRUE);
        meh_screen_destroy(screen);
    }

    return 0;
}
Пример #10
0
/*
 * meh_screen_popup_button_pressed is called when we received a button pressed
 * message.
 */
void meh_screen_popup_button_pressed(App* app, Screen* screen, int pressed_button) {
    g_assert(app != NULL);
    g_assert(screen != NULL);

    PopupData* data = meh_screen_popup_get_data(screen);

    switch (pressed_button) {
    case MEH_INPUT_BUTTON_A:
        switch (data->action) {
        case 0:
            meh_screen_popup_favorite_toggle(app, screen);
            break;
        }
    /* quit the popup */
    case MEH_INPUT_BUTTON_START:
    case MEH_INPUT_BUTTON_B:
    case MEH_INPUT_SPECIAL_ESCAPE:
        meh_screen_popup_close(screen);
        break;
    }
}
Пример #11
0
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);
}