<commit_before>/*
 * mehstation - Popup.
 *
 * Copyright © 2015 <NAME>
 */

#include "system/app.h"
#include "system/consts.h"
#include "view/screen.h"
#include "view/widget_rect.h"
#include "view/screen/popup.h"
#include "view/screen/executable_list.h"
#include "view/screen/exec_selection.h"

static void meh_screen_popup_favorite_toggle(App* app, Screen* screen);
static void meh_screen_popup_button_pressed(App* app, Screen* screen, int pressed_button);
static void meh_screen_popup_close(App* app, Screen* 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;
}

/*
 * 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_rect_destroy(data->selection_widget);
	screen->data = NULL;
}

PopupData* meh_screen_popup_get_data(Screen* screen) {
	g_assert(screen != NULL);
	if (screen->data == NULL) {
		return NULL;
	}
	return (PopupData*) screen->data;
}

/*
 * 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);<commit_msg>popup: release the memory of the random_widget.<commit_after>/*
 * mehstation - Popup.
 *
 * Copyright © 2015 <NAME>
 */

#include "system/app.h"
#include "system/consts.h"
#include "view/screen.h"
#include "view/widget_rect.h"
#include "view/screen/popup.h"
#include "view/screen/executable_list.h"
#include "view/screen/exec_selection.h"

static void meh_screen_popup_favorite_toggle(App* app, Screen* screen);
static void meh_screen_popup_button_pressed(App* app, Screen* screen, int pressed_button);
static void meh_screen_popup_close(App* app, Screen* 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;
}

/*
 * 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;
}

PopupData* meh_screen_popup_get_data(Screen* screen) {
	g_assert(screen != NULL);
	if (screen->data == NULL) {
		return NULL;
	}
	return (PopupData*) screen->data;
}

/*
 * 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);
{'fraction_non_alphanumeric': 0.13473651866646183, 'fraction_numerical': 0.027346750652942082, 'mean_word_length': 4.745807590467785, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 90, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '321373', 'n_tokens_mistral': 2669, 'n_tokens_neox': 2400, 'n_words': 486}