Screen* meh_screen_launch_new(App* app, Screen* src_screen, Platform* platform, Executable* executable, WidgetImage* src_widget) { g_assert(app != NULL); g_assert(src_screen != NULL); g_assert(platform != NULL); g_assert(executable != NULL); Screen* screen = meh_screen_new(app->window); screen->name = g_strdup("Launch screen"); screen->messages_handler = &meh_screen_launch_messages_handler; screen->destroy_data = &meh_screen_launch_destroy_data; /* * custom data */ LaunchData* data = g_new(LaunchData, 1); data->src_screen = src_screen; data->image_widget = NULL; data->executable = executable; data->platform = platform; data->src_widget = src_widget; data->zoom_logo = FALSE; /* fading rect */ SDL_Color black = { 0, 0, 0 ,0 }; data->fade_widget = meh_widget_rect_new(0, 0, MEH_FAKE_WIDTH, MEH_FAKE_HEIGHT, black, TRUE); data->fade_widget->a = meh_transition_start(MEH_TRANSITION_LINEAR, 1, 254, app->settings.fade_duration*4); meh_screen_add_rect_transitions(screen, data->fade_widget); if (app->settings.zoom_logo && src_widget != NULL) { /* cover image */ data->image_widget = meh_widget_image_new( src_widget->texture, src_widget->x.value, src_widget->y.value, src_widget->h.value, src_widget->w.value); /* starts the cover transitions */ data->image_widget->x = meh_transition_start(MEH_TRANSITION_CUBIC, src_widget->x.value, -(MEH_FAKE_WIDTH), app->settings.fade_duration*4); data->image_widget->y = meh_transition_start(MEH_TRANSITION_CUBIC, src_widget->y.value, -(MEH_FAKE_HEIGHT), app->settings.fade_duration*4); data->image_widget->w = meh_transition_start(MEH_TRANSITION_CUBIC, src_widget->w.value, MEH_FAKE_WIDTH*3, app->settings.fade_duration*4); data->image_widget->h = meh_transition_start(MEH_TRANSITION_CUBIC, src_widget->h.value, MEH_FAKE_HEIGHT*3, app->settings.fade_duration*4); meh_screen_add_image_transitions(screen, data->image_widget); data->zoom_logo = TRUE; } screen->data = data; return screen; }
/* * meh_widget_rect_destroy allocates a new widget rect. */ WidgetRect* meh_widget_rect_new(float x, float y, float w, float h, SDL_Color color, gboolean filled) { WidgetRect* r = g_new(WidgetRect, 1); r->x = meh_transition_start(MEH_TRANSITION_NONE, x, x, 0); meh_transition_end(&r->x); r->y = meh_transition_start(MEH_TRANSITION_NONE, y, y, 0); meh_transition_end(&r->y); r->w = meh_transition_start(MEH_TRANSITION_NONE, w, w, 0); meh_transition_end(&r->w); r->h = meh_transition_start(MEH_TRANSITION_NONE, h, h, 0); meh_transition_end(&r->h); r->r = meh_transition_start(MEH_TRANSITION_NONE, color.r, color.r, 0); meh_transition_end(&r->r); r->g = meh_transition_start(MEH_TRANSITION_NONE, color.g, color.g, 0); meh_transition_end(&r->g); r->b = meh_transition_start(MEH_TRANSITION_NONE, color.b, color.b, 0); meh_transition_end(&r->b); r->a = meh_transition_start(MEH_TRANSITION_NONE, color.a, color.a, 0); meh_transition_end(&r->a); r->filled = filled; return r; }
Screen* meh_screen_mapping_new(App* app) { g_assert(app != NULL); Screen* screen = meh_screen_new(app->window); screen->name = g_strdup("Gamepad configuration screen"); screen->messages_handler = &meh_screen_mapping_messages_handler; screen->destroy_data = &meh_screen_mapping_destroy_data; /* * Custom data */ MappingData* data = g_new(MappingData, 1); SDL_Color white = { 255, 255, 255, 255 }; data->title = meh_widget_text_new(app->big_font, "Press a key on the controller to configure", 50, 50, 1230, 50, white, FALSE); data->title->x = meh_transition_start(MEH_TRANSITION_LINEAR, -300, 50, 300); meh_screen_add_text_transitions(screen, data->title); data->device_configuring = NULL; data->action = NULL; data->step = MEH_MAPPING_STEP_IDENTIFY; screen->data = data; return screen; }
/* * * meh_popup_button_pressed moves the currently selected position. */ static void meh_simple_popup_move_selection(App* app, Screen* screen, gboolean down) { g_assert(app); g_assert(screen); SimplePopupData* data = meh_simple_popup_get_data(screen); g_assert(data); int old = data->action; if (down) { data->action += 1; } else { data->action -= 1; } int actions_count = g_queue_get_length(data->actions); if (data->action < 0) { data->action = actions_count-1; } else if (data->action >= actions_count) { data->action = 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); }
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; }
/* * meh_widget_image_destroy allocates a new widget image. */ WidgetImage* meh_widget_image_new(SDL_Texture* texture, float x, float y, float w, float h) { WidgetImage* i = g_new(WidgetImage, 1); i->x = meh_transition_start(MEH_TRANSITION_NONE, x, x, 0); meh_transition_end(&i->x); i->y = meh_transition_start(MEH_TRANSITION_NONE, y, y, 0); meh_transition_end(&i->y); i->w = meh_transition_start(MEH_TRANSITION_NONE, w, w, 0); meh_transition_end(&i->w); i->h = meh_transition_start(MEH_TRANSITION_NONE, h, h, 0); meh_transition_end(&i->h); i->texture = texture; return i; }
/* * * 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); }
/* * meh_main_popup_button_pressed moves the currently selected position. */ static void meh_main_popup_move_selection(App* app, Screen* screen, gboolean down) { g_assert(app); g_assert(screen); MainPopupData* data = meh_main_popup_get_data(screen); g_assert(data); int old = data->action; data->action = down == TRUE ? data->action+1 : data->action-1; if (data->action > 2) { data->action = 0; } else if (data->action == -1) { data->action = 2; } 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); }
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); } }
/* * TODO shadow are not supported since some changes, should be rewrote. */ WidgetText* meh_widget_text_new(const Font* font, const char* text, int x, int y, int w, int h, SDL_Color color, gboolean shadow) { WidgetText* t = g_new(WidgetText, 1); t->font = font; t->text = g_strdup(text); t->x = meh_transition_start(MEH_TRANSITION_NONE, x, x, 0); meh_transition_end(&t->x); t->y = meh_transition_start(MEH_TRANSITION_NONE, y, y, 0); meh_transition_end(&t->y); t->r = meh_transition_start(MEH_TRANSITION_NONE, color.r, color.r, 0); meh_transition_end(&t->r); t->g = meh_transition_start(MEH_TRANSITION_NONE, color.g, color.g, 0); meh_transition_end(&t->g); t->b = meh_transition_start(MEH_TRANSITION_NONE, color.b, color.b, 0); meh_transition_end(&t->b); t->a = meh_transition_start(MEH_TRANSITION_NONE, color.a, color.a, 0); meh_transition_end(&t->a); t->shadow = shadow; t->texture = NULL; t->multi = FALSE; t->start_timestamp = -1; t->restart_timestamp = -1; t->off_x = 0; t->off_y = 0; t->w = w; t->h = h; /* By default, not uppercase */ t->uppercase = FALSE; return t; }
Screen* meh_screen_popup_new(App* app, Screen* src_screen, Executable* executable) { g_assert(app != NULL); g_assert(src_screen != NULL); g_assert(executable != NULL); Screen* screen = meh_screen_new(app->window); screen->name = g_strdup("Popup screen"); screen->messages_handler = &meh_screen_popup_messages_handler; screen->destroy_data = &meh_screen_popup_destroy_data; /* * Custom data */ PopupData* data = g_new(PopupData, 1); data->src_screen = src_screen; data->executable = executable; data->action = 0; data->width = 400; data->height = 200; data->x = MEH_FAKE_WIDTH/2 - data->width/2; data->y = MEH_FAKE_HEIGHT/2 - data->height/2; data->quitting = FALSE; /* Popup background */ SDL_Color white = { 255, 255, 255, 255 }; SDL_Color black = { 0, 0, 0, 240 }; SDL_Color gray = { 15, 15, 15, 120 }; SDL_Color light_gray = { 90, 90, 90, 220 }; SDL_Color very_light_gray = { 40, 40, 40, 220 }; data->background_widget = meh_widget_rect_new(data->x, data->y, data->width, data->height, very_light_gray, TRUE); data->background_widget->y = meh_transition_start(MEH_TRANSITION_LINEAR, -data->height, data->background_widget->y.value, 150); meh_screen_add_rect_transitions(screen, data->background_widget); screen->data = data; black.a = 150; data->hover_widget = meh_widget_rect_new(0, 0, MEH_FAKE_WIDTH, MEH_FAKE_HEIGHT, black, TRUE); /* Title */ data->title_widget = meh_widget_text_new(app->small_bold_font, "OPTIONS", data->x+10, data->y+5, data->width-10, 40, white, TRUE); data->title_bg_widget = meh_widget_rect_new(data->x, data->y, data->width, 45, gray, TRUE); data->selection_widget = meh_widget_rect_new( data->x+5, data->y+54, data->width-10, 30, light_gray, TRUE); /* Add/Remove to favorite */ data->favorite_widget = meh_widget_text_new( app->small_font, executable->favorite == 1 ? "Remove from favorite" : "Add to favorite", data->x+20, data->y+55, data->width-20, 30, white, TRUE); screen->data = data; return screen; }
Screen* meh_screen_popup_new(App* app, Screen* src_screen, Platform* platform, Executable* executable) { g_assert(app != NULL); g_assert(src_screen != NULL); g_assert(executable != NULL); Screen* screen = meh_screen_new(app->window); screen->name = g_strdup("Popup screen"); screen->messages_handler = &meh_screen_popup_messages_handler; screen->destroy_data = &meh_screen_popup_destroy_data; /* * Custom data */ PopupData* data = g_new(PopupData, 1); data->src_screen = src_screen; data->executable = executable; data->platform = platform; data->action = 0; data->width = 400; data->height = 200; data->x = MEH_FAKE_WIDTH/2 - data->width/2; data->y = MEH_FAKE_HEIGHT/2 - data->height/2; /* Popup background */ SDL_Color white = { 255, 255, 255, 255 }; SDL_Color black = { 0, 0, 0, 240 }; SDL_Color light_gray = { 40, 40, 40, 220 }; screen->data = data; black.a = 210; data->hover_widget = meh_widget_rect_new(0, 0, MEH_FAKE_WIDTH, MEH_FAKE_HEIGHT, black, TRUE); /* Title */ data->title_widget = meh_widget_text_new(app->small_bold_font, "OPTIONS", -300, data->y+5, data->width-10, 40, white, TRUE); data->title_widget->x = meh_transition_start(MEH_TRANSITION_CUBIC, -300, 300, 350); meh_screen_add_text_transitions(screen, data->title_widget); data->selection_widget = meh_widget_rect_new( 0, data->y+54, MEH_FAKE_WIDTH, 30, light_gray, TRUE); /* Add/Remove to favorite */ data->favorite_widget = meh_widget_text_new( app->small_font, executable->favorite == 1 ? "Remove from favorite" : "Add to favorite", 400, data->y+55, data->width-20, 30, white, TRUE); /* Run random */ data->random_widget = meh_widget_text_new( app->small_font, "Run random executable of this platform", 400, data->y+87, data->width-20, 30, white, TRUE); screen->data = data; return screen; }
Screen* meh_main_popup_new(App* app, Screen* src_screen) { g_assert(app != NULL); g_assert(src_screen != NULL); Screen* screen = meh_screen_new(app->window); screen->name = g_strdup("Main popup screen"); screen->messages_handler = &meh_main_popup_messages_handler; screen->destroy_data = &meh_main_popup_destroy_data; /* * Custom data */ MainPopupData* data = g_new(MainPopupData, 1); data->src_screen = src_screen; data->action = 0; data->width = 400; data->height = 200; data->x = MEH_FAKE_WIDTH/2 - data->width/2; data->y = MEH_FAKE_HEIGHT/2 - data->height/2; /* Popup background */ SDL_Color white = { 255, 255, 255, 255 }; SDL_Color black = { 0, 0, 0, 240 }; SDL_Color light_gray = { 40, 40, 40, 220 }; screen->data = data; black.a = 210; data->hover_widget = meh_widget_rect_new(0, 0, MEH_FAKE_WIDTH, MEH_FAKE_HEIGHT, black, TRUE); /* Title */ data->title_widget = meh_widget_text_new(app->small_bold_font, "COMMANDS", data->x+10, data->y+5, data->width-10, 40, white, TRUE); data->title_widget->x = meh_transition_start(MEH_TRANSITION_CUBIC, -300, 300, 350); meh_screen_add_text_transitions(screen, data->title_widget); data->selection_widget = meh_widget_rect_new( 0, data->y+54, MEH_FAKE_WIDTH, 30, light_gray, TRUE); data->title_widget->x = meh_transition_start(MEH_TRANSITION_CUBIC, -300, 300, 350); meh_screen_add_text_transitions(screen, data->title_widget); /* Run random executable */ data->random_widget = meh_widget_text_new( app->small_font, "Run random executable", 400, data->y+55, data->width-20, 30, white, TRUE); /* Close mehstation */ data->close_widget = meh_widget_text_new( app->small_font, "Close mehstation", 400, data->y+87, data->width-20, 30, white, TRUE); /* Shutdown */ data->shutdown_widget = meh_widget_text_new( app->small_font, "Shutdown", 400, data->y+119, data->width-20, 30, white, TRUE); screen->data = data; return screen; }
/* * meh_screen_mapping_button_pressed is called when we received a button pressed * message. */ void meh_screen_mapping_button_pressed(App* app, Screen* screen, int pressed_button, int sdl_key, gchar* guid) { MappingData* data = meh_screen_mapping_get_data(screen); g_assert(data != NULL); SDL_Color white = { 255, 255, 255, 255 }; Gamepad* gamepad = meh_input_manager_gamepad_by_guid(app->input_manager, guid); const char* name = "keyboard"; if (gamepad != NULL) { name = gamepad->name; } switch (data->step) { case MEH_MAPPING_STEP_IDENTIFY: meh_widget_text_destroy(data->title); data->title = meh_widget_text_new(app->big_font, "Configuring:", 50, 50, 1230, 50, white, FALSE); data->device_configuring = meh_widget_text_new(app->big_font, name, 300, 50, 1030, 50, white, FALSE); data->action = meh_widget_text_new(app->big_font, "Press the key for up", 200, 150, 1030, 50, white, FALSE); data->action->x = meh_transition_start(MEH_TRANSITION_LINEAR, MEH_FAKE_WIDTH+200, 200, 200); meh_screen_add_text_transitions(screen, data->action); break; case MEH_MAPPING_STEP_UP: meh_widget_text_destroy(data->action); data->action = meh_widget_text_new(app->big_font, "Press the key for down", 200, 150, 1030, 50, white, FALSE); data->action->x = meh_transition_start(MEH_TRANSITION_LINEAR, MEH_FAKE_WIDTH+200, 200, 200); meh_screen_add_text_transitions(screen, data->action); data->up = sdl_key; break; case MEH_MAPPING_STEP_DOWN: meh_widget_text_destroy(data->action); data->action = meh_widget_text_new(app->big_font, "Press the key for left", 200, 150, 1030, 50, white, FALSE); data->action->x = meh_transition_start(MEH_TRANSITION_LINEAR, MEH_FAKE_WIDTH+200, 200, 200); meh_screen_add_text_transitions(screen, data->action); data->down = sdl_key; break; case MEH_MAPPING_STEP_LEFT: meh_widget_text_destroy(data->action); data->action = meh_widget_text_new(app->big_font, "Press the key for right", 200, 150, 1030, 50, white, FALSE); data->action->x = meh_transition_start(MEH_TRANSITION_LINEAR, MEH_FAKE_WIDTH+200, 200, 200); meh_screen_add_text_transitions(screen, data->action); data->left = sdl_key; break; case MEH_MAPPING_STEP_RIGHT: meh_widget_text_destroy(data->action); data->action = meh_widget_text_new(app->big_font, "Press the key for A button", 200, 150, 1030, 50, white, FALSE); data->action->x = meh_transition_start(MEH_TRANSITION_LINEAR, MEH_FAKE_WIDTH+200, 200, 200); meh_screen_add_text_transitions(screen, data->action); data->right = sdl_key; break; case MEH_MAPPING_STEP_A: meh_widget_text_destroy(data->action); data->action = meh_widget_text_new(app->big_font, "Press the key for B button", 200, 150, 1030, 50, white, FALSE); data->action->x = meh_transition_start(MEH_TRANSITION_LINEAR, MEH_FAKE_WIDTH+200, 200, 200); meh_screen_add_text_transitions(screen, data->action); data->a = sdl_key; break; case MEH_MAPPING_STEP_B: meh_widget_text_destroy(data->action); data->action = meh_widget_text_new(app->big_font, "Press the key for L button", 200, 150, 1030, 50, white, FALSE); data->action->x = meh_transition_start(MEH_TRANSITION_LINEAR, MEH_FAKE_WIDTH+200, 200, 200); meh_screen_add_text_transitions(screen, data->action); data->b = sdl_key; break; case MEH_MAPPING_STEP_L: meh_widget_text_destroy(data->action); data->action = meh_widget_text_new(app->big_font, "Press the key for R button", 200, 150, 1030, 50, white, FALSE); data->action->x = meh_transition_start(MEH_TRANSITION_LINEAR, MEH_FAKE_WIDTH+200, 200, 200); meh_screen_add_text_transitions(screen, data->action); data->l = sdl_key; break; case MEH_MAPPING_STEP_R: meh_widget_text_destroy(data->action); data->action = meh_widget_text_new(app->big_font, "Press the key for START button", 200, 150, 1030, 50, white, FALSE); data->action->x = meh_transition_start(MEH_TRANSITION_LINEAR, MEH_FAKE_WIDTH+200, 200, 200); meh_screen_add_text_transitions(screen, data->action); data->r = sdl_key; break; case MEH_MAPPING_STEP_START: meh_widget_text_destroy(data->action); data->action = meh_widget_text_new(app->big_font, "Press the key for SELECT button", 200, 150, 1030, 50, white, FALSE); data->action->x = meh_transition_start(MEH_TRANSITION_LINEAR, MEH_FAKE_WIDTH+200, 200, 200); meh_screen_add_text_transitions(screen, data->action); data->start = sdl_key; break; case MEH_MAPPING_STEP_SELECT: meh_widget_text_destroy(data->action); data->action = meh_widget_text_new(app->big_font, "All done", 200, 150, 1030, 50, white, FALSE); data->action->x = meh_transition_start(MEH_TRANSITION_LINEAR, MEH_FAKE_WIDTH+200, 200, 200); meh_screen_add_text_transitions(screen, data->action); data->select = sdl_key; break; case MEH_MAPPING_STEP_END: meh_screen_mapping_next_screen(app, screen); break; } meh_input_manager_reset_buttons_state(app->input_manager); data->step++; }