<commit_before>/*
 * This software is licensed under the terms of the MIT-License
 * See COPYING for further information. 
 * ---
 * Copyright (C) 2011, <NAME> <<EMAIL>>
 */

#include "menu.h"
#include "global.h"

void add_menu_entry(MenuData *menu, char *name, void (*action)(void *), void *arg) {
	menu->entries = realloc(menu->entries, (++menu->ecount)*sizeof(MenuEntry));
	MenuEntry *e = &(menu->entries[menu->ecount-1]);
	memset(e, 0, sizeof(MenuEntry));
	
	e->name = malloc(strlen(name)+1);
	strcpy(e->name, name);
	e->action = action;
	e->arg = arg;
}

void add_menu_separator(MenuData *menu) {
	menu->entries = realloc(menu->entries, (++menu->ecount)*sizeof(MenuEntry));
	memset(&(menu->entries[menu->ecount-1]), 0, sizeof(MenuEntry));
}

void destroy_menu(MenuData *menu) {
	int i;
	
	if(menu->ondestroy)
		menu->ondestroy(menu);
	
	for(i = 0; i < menu->ecount; i++) {
		MenuEntry *e = &(menu->entries[i]);
		
		free(e->name);
		if(e->freearg)
			e->freearg(e->arg);
	}
	
	free(menu->entries);
}

void create_menu(MenuData *menu) {
	memset(menu, 0, sizeof(MenuData));
	
	menu->fade = 1;
	menu->selected = -1;
}

static void key_action(MenuData *menu, int sym) {
	Uint8 *keys = SDL_GetKeyState(NULL);
	
	int look_i_can_hardcode_annoying_menu_hacks_too = menu->title && !strcmp(menu->title, "Save replay?");
	
	if(sym == tconfig.intval[KEY_DOWN]  || sym == SDLK_DOWN || look_i_can_hardcode_annoying_menu_hacks_too &&
	  (sym == tconfig.intval[KEY_RIGHT] || sym == SDLK_RIGHT)) {
		do {
			if(++menu->cursor >= menu->ecount)
				menu->cursor = 0;
		} while(menu->entries[menu->cursor].action == NULL);
	} else if(sym == tconfig.intval[KEY_UP]   || sym == SDLK_UP || look_i_can_hardcode_annoying_menu_hacks_too &&
			 (sym == tconfig.intval[KEY_LEFT] || sym == SDLK_LEFT)) {
		do {
			if(--menu->cursor < 0)
				menu->cursor = menu->ecount - 1;
		} while(menu->entries[menu->cursor].action == NULL);
	} else if((sym == tconfig.intval[KEY_SHOT] || (sym == SDLK_RETURN && !keys[SDLK_LALT] && !keys[SDLK_LALT])) && menu->entries[menu->cursor].action) {
		menu->quit = 1;
		menu->selected = menu->cursor;
	} else if(sym == SDLK_ESCAPE && (menu->type == MT_Transient || menu->abortable) && menu->abortable >= 0) {
		menu->quit = 1;
		menu->abort = 1;
	}
}

void menu_input(MenuData *menu) {
	SDL_Event event;
	<commit_msg>fixed stupid condition no fullscreen in menu condition<commit_after>/*
 * This software is licensed under the terms of the MIT-License
 * See COPYING for further information. 
 * ---
 * Copyright (C) 2011, <NAME> <<EMAIL>>
 */

#include "menu.h"
#include "global.h"

void add_menu_entry(MenuData *menu, char *name, void (*action)(void *), void *arg) {
	menu->entries = realloc(menu->entries, (++menu->ecount)*sizeof(MenuEntry));
	MenuEntry *e = &(menu->entries[menu->ecount-1]);
	memset(e, 0, sizeof(MenuEntry));
	
	e->name = malloc(strlen(name)+1);
	strcpy(e->name, name);
	e->action = action;
	e->arg = arg;
}

void add_menu_separator(MenuData *menu) {
	menu->entries = realloc(menu->entries, (++menu->ecount)*sizeof(MenuEntry));
	memset(&(menu->entries[menu->ecount-1]), 0, sizeof(MenuEntry));
}

void destroy_menu(MenuData *menu) {
	int i;
	
	if(menu->ondestroy)
		menu->ondestroy(menu);
	
	for(i = 0; i < menu->ecount; i++) {
		MenuEntry *e = &(menu->entries[i]);
		
		free(e->name);
		if(e->freearg)
			e->freearg(e->arg);
	}
	
	free(menu->entries);
}

void create_menu(MenuData *menu) {
	memset(menu, 0, sizeof(MenuData));
	
	menu->fade = 1;
	menu->selected = -1;
}

static void key_action(MenuData *menu, int sym) {
	Uint8 *keys = SDL_GetKeyState(NULL);
	
	int look_i_can_hardcode_annoying_menu_hacks_too = menu->title && !strcmp(menu->title, "Save replay?");
	
	if(sym == tconfig.intval[KEY_DOWN]  || sym == SDLK_DOWN || look_i_can_hardcode_annoying_menu_hacks_too &&
	  (sym == tconfig.intval[KEY_RIGHT] || sym == SDLK_RIGHT)) {
		do {
			if(++menu->cursor >= menu->ecount)
				menu->cursor = 0;
		} while(menu->entries[menu->cursor].action == NULL);
	} else if(sym == tconfig.intval[KEY_UP]   || sym == SDLK_UP || look_i_can_hardcode_annoying_menu_hacks_too &&
			 (sym == tconfig.intval[KEY_LEFT] || sym == SDLK_LEFT)) {
		do {
			if(--menu->cursor < 0)
				menu->cursor = menu->ecount - 1;
		} while(menu->entries[menu->cursor].action == NULL);
	} else if((sym == tconfig.intval[KEY_SHOT] || (sym == SDLK_RETURN && !keys[SDLK_LALT] && !keys[SDLK_RALT])) && menu->entries[menu->cursor].action) {
		menu->quit = 1;
		menu->selected = menu->cursor;
	} else if(sym == SDLK_ESCAPE && (menu->type == MT_Transient || menu->abortable) && menu->abortable >= 0) {
		menu->quit = 1;
		menu->abort = 1;
	}
}

void menu_input(MenuData *menu) {
	SDL_Event event;
	
{'fraction_non_alphanumeric': 0.192102454642476, 'fraction_numerical': 0.00896478121664888, 'mean_word_length': 4.4110854503464205, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 107, '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': '5648021', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1785, 'n_words': 341}