示例#1
0
int main(int argc, char* argv[]) {
    int err;
    text_t text;

    err = (argc != 2);
    if (err) { 
        printf("ERROR: Wrong number of arguments.\n");
        exit(EXIT_FAILURE); 
    }

    /* STACK TEST */
    err = text_from_file(&text, argv[1]);
    if (err) {
        printf("ERROR: Error reading text file.\n");
        exit(EXIT_FAILURE);
    }

    text_print(&text);
    text_free(&text, false);

    /* HEAP TEST */
    text_t* textp = text_alloc();
    err = text_from_file(textp, argv[1]);
    if (err) {
        printf("ERROR: Error reading text lines.\n");
        exit(EXIT_FAILURE);
    }

    text_print(textp);
    text_free(textp, true);

    return EXIT_SUCCESS;
}
示例#2
0
文件: text.c 项目: Distrotech/texinfo
void
text_append_n (TEXT *t, char *s, size_t len)
{
  text_alloc (t, len + 1);
  memcpy (t->text + t->end, s, len);
  t->end += len;
  t->text[t->end] = '\0';
}
void load_screen_alloc(screen_ptr_t screen_ptr)
{
    /*** debug ***/ fprintf(stdout, "[Trace] load_screen_alloc()\n");
    
    int x_res = runtime.screen_width;
    // int y_res = runtime.screen_height;
    
    // create trace text
    text_ptr_t trace_text_ptr = text_alloc("DejaVuSans", 24, &color_white, "Load", 0, 0, 0);
    trace_text_ptr->x = x_res / 2 - runtime_surface_width(trace_text_ptr->surface_ptr) / 2;
    trace_text_ptr->y = runtime_surface_height(trace_text_ptr->surface_ptr) / 4;

    // create a menu [LOAD_MENU_INDEX]
    menu_ptr_t menu_ptr = menu_text_alloc("load", text_alloc("DejaVuSans", 32, &color_white, "Load", 0, 0, 0), 27, mod_key_none, anchor_center, 0, 0, true);
    screen_add_menu(screen_ptr, menu_ptr);
    
    // create a menu item
    menu_item_ptr_t menu_item_1_ptr = menu_item_text_alloc("cancel", text_alloc("DejaVuSans", 32, &color_white, "Cancel", 0, 0, 0), '1', mod_key_none, load_screen_menu_item_task);
    menu_add_menu_item(menu_ptr, menu_item_1_ptr);
}
示例#4
0
文件: main.c 项目: metredigm/hunter
void init_graphic(void) {
	global* global_handle = global_get_singleton();

	config* config_handle = NULL;
	config_alloc(&config_handle, "config/graphics.cfg");

	int resx = config_get_int_value(config_handle, "resx");
	int resy = config_get_int_value(config_handle, "resy");
	int samples = config_get_int_value(config_handle, "msaa");
	int windowed = config_get_int_value(config_handle, "windowed");
	int vsync = config_get_int_value(config_handle, "vertical_sync");

	config_free(&config_handle);

	window* window_handle = NULL;
	window_alloc(&window_handle, resx, resy, samples, !windowed, vsync, 1);

	window_set_blend_mode(window_handle, WINDOW_BLEND_ALPHA);
	window_set_clear_color(window_handle, 0.0f, 0.0f, 0.0f, 0.0f);

	global_set(global_handle, GLOBAL_WINDOW, window_handle);

	hl_render* hl_render_handle = NULL;
	hl_render_alloc(&hl_render_handle);

	global_set(global_handle, GLOBAL_HL_RENDER, hl_render_handle);

	// effect* effect_motion_blur_handle = NULL;
	// effect_alloc(&effect_motion_blur_handle, effect_motion_blur_init, effect_motion_blur_render, effect_motion_blur_config, effect_motion_blur_free, window_get_width(window_handle), window_get_height(window_handle));
	// hl_render_add_effect(hl_render_handle, effect_motion_blur_handle, WINDOW_BLEND_ALPHA);

	camera* camera_handle = NULL;
	camera_alloc(&camera_handle);

	camera_set_dimension(camera_handle, CAMERA_SIZE * (float) window_get_width(window_handle) / (float) window_get_height(window_handle), CAMERA_SIZE);
	camera_set_position(camera_handle, 0.0f, 0.0f);

	camera_update_matrices(camera_handle);

	global_set(global_handle, GLOBAL_CAMERA, camera_handle);

	shader* shader_texture_handle = NULL;
	shader_alloc(&shader_texture_handle, SHADER_TEXTURE_VS, SHADER_TEXTURE_PS);

	global_set(global_handle, GLOBAL_SHADER_TEXTURE, shader_texture_handle);

	text* text_handle = NULL;
	text_alloc(&text_handle, camera_handle, window_handle);

	global_set(global_handle, GLOBAL_TEXT, text_handle);

	input* input_handle = NULL;
	input_alloc(&input_handle, window_handle);

	global_set(global_handle, GLOBAL_INPUT, input_handle);

	debug_draw* debug_draw_handle = NULL;
	debug_draw_alloc(&debug_draw_handle, hl_render_handle);

	global_set(global_handle, GLOBAL_DEBUG_DRAW, debug_draw_handle);
}
void game_screen_alloc(screen_ptr_t screen_ptr)
{
    /*** debug ***/ fprintf(stdout, "[Trace] game_screen_alloc()\n");
    
    int x_res = runtime.screen_width;
    int y_res = runtime.screen_height;
    
    // create trace text
    text_ptr_t trace_text_ptr = text_alloc("DejaVuSans", 24, &color_white, "Game", 0, 0, 0);
    trace_text_ptr->x = x_res / 2 - runtime_surface_width(trace_text_ptr->surface_ptr) / 2;
    trace_text_ptr->y = runtime_surface_height(trace_text_ptr->surface_ptr) / 4;
    screen_add_text(screen_ptr, trace_text_ptr);
    
    // create a menu [SYSTEM_MENU_INDEX]
    menu_ptr_t menu_ptr = menu_image_alloc("system", image_alloc_file("gear_32.png", NULL), 27, mod_key_none, anchor_bottom_right, 0, 0, false);
    screen_add_menu(screen_ptr, menu_ptr);
    
    // create a menu item
    menu_item_ptr_t menu_item_1_ptr = menu_item_text_alloc("save", text_alloc("DejaVuSans", 32, &color_white, "Save", 0, 0, 0), '1', mod_key_none, game_screen_menu_item_task);
    menu_add_menu_item(menu_ptr, menu_item_1_ptr);

    // create a menu item
    menu_item_ptr_t menu_item_2_ptr = menu_item_text_alloc("load", text_alloc("DejaVuSans", 32, &color_white, "Load", 0, 0, 0), '2', mod_key_none, game_screen_menu_item_task);
    menu_add_menu_item(menu_ptr, menu_item_2_ptr);
    
    // create a menu item
    menu_item_ptr_t menu_item_3_ptr = menu_item_text_alloc("options", text_alloc("DejaVuSans", 32, &color_white, "Options", 0, 0, 0), '3', mod_key_none, game_screen_menu_item_task);
    menu_add_menu_item(menu_ptr, menu_item_3_ptr);

    // create a menu item
    menu_item_ptr_t menu_item_4_ptr = menu_item_text_alloc("title", text_alloc("DejaVuSans", 32, &color_white, "Title", 0, 0, 0), '4', mod_key_none, game_screen_menu_item_task);
    menu_add_menu_item(menu_ptr, menu_item_4_ptr);
    
    // create a menu item
    menu_item_ptr_t menu_item_5_ptr = menu_item_text_alloc("cancel", text_alloc("DejaVuSans", 32, &color_white, "Cancel", 0, 0, 0), '5', mod_key_none, game_screen_menu_item_task);
    menu_add_menu_item(menu_ptr, menu_item_5_ptr);

    // debug
    text_ptr_t area_text_ptr = text_alloc("DejaVuSans", 128, &color_white, " ", 0, 0, 0);                               // AREA_TEXT_INDEX
    screen_add_text(screen_ptr, area_text_ptr);
    text_ptr_t left_area_text_ptr = text_alloc("DejaVuSans", 128, &color_white, " ", 0, 0, 0);     // LEFT_AREA_TEXT_INDEX
    screen_add_text(screen_ptr, left_area_text_ptr);
    text_ptr_t right_area_text_ptr = text_alloc("DejaVuSans", 128, &color_white, " ", 0, 0, 0);   // RIGHT_AREA_TEXT_INDEX
    screen_add_text(screen_ptr, right_area_text_ptr);
    text_ptr_t back_area_text_ptr = text_alloc("DejaVuSans", 128, &color_white, " ", 0, 0, 0);     // BACK_AREA_TEXT_INDEX
    screen_add_text(screen_ptr, back_area_text_ptr);
    
    text_ptr_t squid_text_ptr = text_alloc("DejaVuSans", 48, &color_cyan, "swamp squid", 0, 0, -1);
    squid_text_ptr->x = x_res / 2 - runtime_surface_width(squid_text_ptr->surface_ptr) / 2;
    squid_text_ptr->y = y_res / 3 - runtime_surface_height(squid_text_ptr->surface_ptr) / 2;
    screen_add_text(screen_ptr, squid_text_ptr);    // SQUID_TEXT_INDEX

    text_ptr_t wisp_text_ptr = text_alloc("DejaVuSans", 48, &color_yellow, "will-o-wisp", 0, 0, -1);
    wisp_text_ptr->x = x_res / 5 * 4 - runtime_surface_width(wisp_text_ptr->surface_ptr) / 2;
    wisp_text_ptr->y = y_res / 3 - runtime_surface_height(wisp_text_ptr->surface_ptr) / 2;
    screen_add_text(screen_ptr, wisp_text_ptr);     // WISP_TEXT_INDEX

    text_ptr_t vines_text_ptr = text_alloc("DejaVuSans", 48, &color_green, "poison vines", 0, 0, -1);
    vines_text_ptr->x = x_res / 5 - runtime_surface_width(vines_text_ptr->surface_ptr) / 2;
    vines_text_ptr->y = y_res / 3 - runtime_surface_height(vines_text_ptr->surface_ptr) / 2;
    screen_add_text(screen_ptr, vines_text_ptr);    // VINES_TEXT_INDEX

    text_ptr_t squid_near_text_ptr = text_alloc("DejaVuSans", 48, &color_light_cyan, "splash", 0, 0, -1);
    squid_near_text_ptr->x = x_res / 2 - runtime_surface_width(squid_near_text_ptr->surface_ptr) / 2;
    squid_near_text_ptr->y = y_res / 3 * 2 - runtime_surface_height(squid_near_text_ptr->surface_ptr) / 2;
    screen_add_text(screen_ptr, squid_near_text_ptr);   // SQUID_NEAR_TEXT_INDEX

    text_ptr_t wisp_near_text_ptr = text_alloc("DejaVuSans", 48, &color_light_yellow, "glow", 0, 0, -1);
    wisp_near_text_ptr->x = x_res / 5 * 4 - runtime_surface_width(wisp_near_text_ptr->surface_ptr) / 2;
    wisp_near_text_ptr->y = y_res / 3 * 2- runtime_surface_height(wisp_near_text_ptr->surface_ptr) / 2;
    screen_add_text(screen_ptr, wisp_near_text_ptr);    // WISP_NEAR_TEXT_INDEX

    text_ptr_t vines_near_text_ptr = text_alloc("DejaVuSans", 48, &color_light_green, "mist", 0, 0, -1);
    vines_near_text_ptr->x = x_res / 5 - runtime_surface_width(vines_near_text_ptr->surface_ptr) / 2;
    vines_near_text_ptr->y = y_res / 3 * 2- runtime_surface_height(vines_near_text_ptr->surface_ptr) / 2;
    screen_add_text(screen_ptr, vines_near_text_ptr);   // VINES_NEAR_TEXT_INDEX
}