Ejemplo n.º 1
0
int gui_init(int argc, char *argv[])
{
	memset(frame_time, 0, sizeof(long)*MAX_FRAMES);
	stash = sth_create(512,512);
	if (!stash)
	{
		printf("Could not create stash.\n");
		return -1;
	}
	font_load(0,"data/gui/SourceCodePro-Regular.ttf");
	font_load(1,"data/gui/SourceCodePro-Bold.ttf");
	font_load(2,"data/gui/SourceSansPro-Regular.ttf");
	font_load(3,"data/gui/SourceSansPro-Bold.ttf");

	widget *w;
	widget *menu = widget_menu_new();
	widget *item = widget_menu_add(menu, "File");
	widget_menu_item_add(item, "Open", spawn_open);
	widget_menu_item_add(item, "Voxel Open", spawn_voxopen);
	widget_menu_separator_add(item);
	widget_menu_item_add(item, "Exit", menu_killme);

	item = widget_menu_add(menu, "Display");
	w = widget_menu_item_add(item, "	 Fullscreen - F11", menu_fullscreen);
	w->draw = widget_menu_bool_draw;
	w->data2 = &fullscreen;
	w = widget_menu_item_add(item, "	 Draw 3D Texture", menu_texdraw);
	w->draw = widget_menu_bool_draw;
	extern int texdraw;
	w->data2 = &texdraw;
	widget_menu_item_add(item, "GPU Information", spawn_gpuinfo);
	widget_menu_separator_add(item);
	widget_menu_item_add(item, "Rebuild Shaders", voxel_rebuildshader);

	item = widget_menu_add(menu, "Input");
	w = widget_menu_item_add(item, "	 Accepting Tablets",
		menu_http_toggle);
	w->draw = widget_menu_bool_draw;
	w->data2 = &http_accepting_new_clients;
	w = widget_menu_item_add(item, "Authorised Devices", spawn_http_auth );
	w = widget_menu_item_add(item, "Pending Authorisation", spawn_http_pend);

	item = widget_menu_add(menu, "Help");
	widget_menu_item_add(item, "Overview \u2560", 0);
	widget_menu_item_add(item, "Wiki \u26a0", 0);
	widget_menu_separator_add(item);
	widget_menu_item_add(item, "Credits \u2623", spawn_credits);
	widget_menu_item_add(item, "License", spawn_license);
	widget_menu_separator_add(item);
	widget_menu_item_add(item, "About", spawn_about);

	widget_add(menu);

	last_time = sys_time();
	return 0;
}
Ejemplo n.º 2
0
int main() {
    // Init components
    components_init();
    
    // Load fonts
    f_small = font_load("font_small");
    f_large = font_load("font_large");
    
    // Load images
    img_blood = bmp_load("images/blood.bmp");
    bmp_image *img_space = bmp_load("images/space.bmp");
    bmp_image *img_ufo1 = bmp_load("images/ufo1.bmp");
    bmp_image *img_ufo2 = bmp_load("images/ufo2.bmp");
    bmp_image *img_ufo3 = bmp_load("images/ufo3.bmp");
    bmp_image *img_ufo4 = bmp_load("images/ufo4.bmp");
    bmp_image *img_ufo5 = bmp_load("images/ufo5.bmp");
    bmp_image *img_rabby = bmp_load("rabbit.bmp");
    bmp_image *img_powerup1 = bmp_load("images/pow1.bmp");
    bmp_image *img_powerup2 = bmp_load("images/pow1.bmp");
    bmp_image *img_powerup3 = bmp_load("images/pow1.bmp");
    bmp_image *img_powerup4 = bmp_load("images/pow1.bmp");
    bmp_image *img_rabby_red = bmp_copy(img_rabby);
    bmp_tint(img_rabby_red, 255, 128, 128);
    bmp_tint(img_powerup3, 0, 250, 29);
    bmp_tint(img_powerup2, 0, 0, 255);
    bmp_tint(img_powerup1, 255, 255, 29);
    
    // Create drawables
    space = drawable_create_bmp(img_space);
    ufo1 = drawable_create_bmp(img_ufo1);
    ufo2 = drawable_create_bmp(img_ufo2);
    ufo3 = drawable_create_bmp(img_ufo3);
    ufo4 = drawable_create_bmp(img_ufo4);
    ufo5 = drawable_create_bmp(img_ufo5);
    rabby = drawable_create_bmp(img_rabby);
    bullet = drawable_create_rect(4, 4, 255, 255, 255);
    rabby_red = drawable_create_bmp(img_rabby_red);
    power_sprite[0] = drawable_create_bmp(img_powerup1);
    power_sprite[1] = drawable_create_bmp(img_powerup2);
    power_sprite[2] = drawable_create_bmp(img_powerup3);
    power_sprite[3] = drawable_create_bmp(img_powerup4);
    
    // Start midi player in another thread
    pthread_t thread_midi;
    int result = pthread_create(&thread_midi, NULL, midi_run, NULL);
    
    // Loop game
    while (1) {
        engine_init();
        init();
        engine_run();
        dispose();
        engine_dispose();
    }
}
Ejemplo n.º 3
0
PDFFont const& FontManagement::font_load(Char const* fspec)
{
    // get a font from typeman by the spec
    ITypeMan& typeman(*m_doc.resource_ctx().type_man());
    IFontEx const& font = typeman.font_load(fspec, m_doc.exec_context());
    return font_load(font);
}
Ejemplo n.º 4
0
void game_init( void )
{
    window = SDL_CreateWindow( game_name, SDL_WINDOWPOS_CENTERED, 
                               SDL_WINDOWPOS_CENTERED, screen_width, 
                               screen_height, SDL_WINDOW_SHOWN );
    if ( window == NULL ) {
        send_error( EXIT_FAILURE );
    }
    render = SDL_CreateRenderer( window, -1, SDL_RENDERER_ACCELERATED | 
                                 SDL_RENDERER_PRESENTVSYNC );
    if ( render == NULL ) {
        send_error( EXIT_FAILURE );
    }
    srand( time( NULL ) );
    font_load( render, &ft, "../../00_other/font.cfg" );
    set_color( ft->font, 0xFFFFFF );
    t_star = IMG_LoadTexture( render, "./images/star.png" );
    t_background = IMG_LoadTexture( render, "./images/background.png" );
    t_player = IMG_LoadTexture( render, "./images/player.png" );
    t_laser_enemy = IMG_LoadTexture( render, "./images/laser_enemy.png" );
    t_laser_player = IMG_LoadTexture( render, "./images/laser_player.png" );
    t_enemy = IMG_LoadTexture( render, "./images/enemy.png" );
    t_medkit = IMG_LoadTexture( render, "./images/medkit.png" );
    t_meteor = IMG_LoadTexture( render, "./images/meteor.png" );
    game_restart();
}
Ejemplo n.º 5
0
struct hud* hud_init() {
	struct hud *hud = malloc(sizeof(*hud));

	hud->my_font = font_load("res/LiberationMono-Regular.ttf");

	return hud;
}
Ejemplo n.º 6
0
static void ft_load_font(char *file)
{
    int current_font_id;
    enum screen_type screen = SCREEN_MAIN;
#if NB_SCREENS > 1
    MENUITEM_STRINGLIST(menu, ID2P(LANG_CUSTOM_FONT), NULL, 
                        ID2P(LANG_MAIN_SCREEN), ID2P(LANG_REMOTE_SCREEN))
    switch (do_menu(&menu, NULL, NULL, false))
    {
        case 0: /* main lcd */
            screen = SCREEN_MAIN;
            set_file(file, (char *)global_settings.font_file, MAX_FILENAME);
            break;
        case 1: /* remote */
            screen = SCREEN_REMOTE;
            set_file(file, (char *)global_settings.remote_font_file, MAX_FILENAME);
            break;
    }
#else
    set_file(file, (char *)global_settings.font_file, MAX_FILENAME);
#endif
    splash(0, ID2P(LANG_WAIT));
    current_font_id = global_status.font_id[screen];
    if (current_font_id >= 0)
        font_unload(current_font_id);
    current_font_id = font_load(file);
    if(screen==SCREEN_MAIN)
        font_set_ui(current_font_id);
    global_status.font_id[screen] = current_font_id;
    viewportmanager_theme_changed(THEME_UI_VIEWPORT);
}    
Ejemplo n.º 7
0
Archivo: event.c Proyecto: odrevet/GE
bool event_exec_text(event *p_event, struct t_game* p_game)
{
  event_text *data = (event_text*)p_event->data;

  bool done=false;
  SDL_Event event;
  SDL_Rect srcrect = {0,0,160,144};                               //the part of the screen to be stretched, must be sup 0 and inf screen surface Height and Width
  SDL_Rect dstrect = set_rect(0,0,SCREEN_HEIGHT,SCREEN_WIDTH);    //equals screen resolution

  message_box* p_message_box = NULL;
  p_message_box = gui_new_message_box(p_message_box, data->text, 0, 144-32, 32, 160, 0, 146, 30);
  p_message_box->p_font = font_load("res/fonts/saxmono.ttf", 10);
  p_message_box->border = 0;
  p_message_box->border_color = 999;
  p_message_box->radius = 0;

  while (!done){
    while (SDL_PollEvent (&event)){
      switch (event.type){
      case SDL_KEYDOWN:
	if(event.key.keysym.sym==SDLK_SPACE){
	  done = true;
	}
	break;
      case SDL_QUIT:
	exit(0);
	break;
      case SDL_JOYBUTTONDOWN:
	switch(event.jbutton.button)
	  {
	  case 0:
	    break;
	  case 1:
	    break;
	  case 2:
	    break;
	  case 3:
	    done = true;
	    break;
	  case 4:
	    break;
	  case 5:
	    break;
	  case 6:
	    break;
	  }
      }
    }

    gui_message_box_draw(p_message_box, get_backbuffer_surface());
    SDL_SoftStretch(backbuffer,&srcrect,SDL_GetVideoSurface(),&dstrect);
    SDL_Flip(SDL_GetVideoSurface());
  }

  gui_message_box_free(p_message_box);

  return true;
}
Ejemplo n.º 8
0
Archivo: fonts.c Proyecto: UraKn0x/gbdk
void main(void)
{
    font_t ibm_font, italic_font, min_font;
    int i;

    /* First, init the font system */
    font_init();

    /* Load all the fonts that we can */
    ibm_font = font_load(font_ibm);  /* 96 tiles */
    italic_font = font_load(font_italic);   /* 93 tiles */
    
    /* Load this one with dk grey background and white foreground */
    color(WHITE, DKGREY, SOLID);
    
    min_font = font_load(font_min);

    /* Turn scrolling off (why not?) */
    mode(get_mode() | M_NO_SCROLL);

    /* Print some text! */
    
    /* IBM font */
    font_set(ibm_font);
    printf("Font demo.\n\n");

    printf("IBM Font #!?123\n");

    /* In italic */
    font_set(italic_font);
    for (i=1; i!=5; i++) {
	printf("In italics, line %u\n", i);
    }

    /* With a minimal, colour changed font */
    font_set(min_font);
    printf("Minimal 36 tile font\n");

    /* Done */
    font_set(ibm_font);
    printf("\nDone!");
}
Ejemplo n.º 9
0
int font_set_load(FONT_SET *font_set, const char *font_filename, const char *text_texture_filename, const char *outline_texture_filename, const char * ft_font_filename, int fonts, ...)
{
    int i;
    va_list va; 

    font_set->font_count = fonts;

    va_start(va, fonts); 
    for (i = 0; i < fonts; i++)
    {
        int size;
        char composed_font_filename[256];
        char composed_text_texture_filename[256];
        char composed_outline_texture_filename[256];
        FONT *font = &font_set->fonts[i];

        size = va_arg(va, int);
        str_format(composed_font_filename, sizeof(composed_font_filename), font_filename, size);
        str_format(composed_text_texture_filename, sizeof(composed_text_texture_filename), text_texture_filename, size);
        str_format(composed_outline_texture_filename, sizeof(composed_outline_texture_filename), outline_texture_filename, size);

        if (font_load(font, composed_font_filename))
        {
            dbg_msg("font/loading", "failed loading font %s.", composed_font_filename);
            va_end(va);
            return -1;
        }

        font->size = size;
        font->text_texture = gfx_load_texture(composed_text_texture_filename, IMG_ALPHA, TEXLOAD_NORESAMPLE);
        font->outline_texture = gfx_load_texture(composed_outline_texture_filename, IMG_ALPHA, TEXLOAD_NORESAMPLE);
    }

    va_end(va);
	
	FreeTypeTextRenderer.Init();
	CFont * ft_font = FreeTypeTextRenderer.LoadFont(ft_font_filename);
	if (!ft_font)
	{
		dbg_msg("font/loading", "failed loading freetype font %s.", ft_font_filename);
		return -1;
	} else {
		FreeTypeTextRenderer.SetDefaultFont(ft_font);
	}
	
	/*font_set->ft_font = ft_font_load(ft_font_filename);
	if (!font_set->ft_font)
	{
		dbg_msg("font/loading", "failed loading freetype font %s.", ft_font_filename);
		return -1;
	}*/
	
    return 0;
}
Ejemplo n.º 10
0
Archivo: menu.c Proyecto: odrevet/GE
message_box* menu_ingame_create(game *p_game){
  char text[16];
  sprintf(text, "HP%.2d Gold %.3d",  p_game->p_unit->HP, p_game->p_unit->gold);
  message_box* p_message_box = NULL;
  p_message_box = gui_new_message_box(p_message_box, text, 0, 144-16, 16, 160, 0, 146, 30);
  p_message_box->p_font = font_load("res/fonts/saxmono.ttf", 12);
  p_message_box->border = 0;
  p_message_box->border_color = 999;
  p_message_box->radius = 0;

  return p_message_box;
}
Ejemplo n.º 11
0
int	trap_LoadFont(lua_State *s)
{
	FONT *font;
	const char *fontname;
	int fontsize;

	trap_args(s, "LoadFont", "si", &fontname, &fontsize);
	if (fontsize == 0) fontsize = c_fontsize->integer;

	font = font_load(fontname, fontsize);
	lua_pushlightuserdata(s, font);
	return 1;
}
Ejemplo n.º 12
0
void dialog_font(HWND hWnd)
{
	TCHAR	szPath[MAX_PATH];

	file_cpyname(szPath, np2cfg.fontfile, NELEMENTS(szPath));
	if ((dlgs_openfile(hWnd, &fpFont, szPath, NELEMENTS(szPath), NULL)) &&
		(font_load(szPath, FALSE)))
	{
		gdcs.textdisp |= GDCSCRN_ALLDRAW2;
		milstr_ncpy(np2cfg.fontfile, szPath, NELEMENTS(np2cfg.fontfile));
		sysmng_update(SYS_UPDATECFG);
	}
}
Ejemplo n.º 13
0
int game_mode(game_t g, const char *title,
			unsigned int x, unsigned int y,
			unsigned int depth, unsigned int fullscreen)
{
	int ret;
	ret = renderer_mode(g->g_render, title, x, y, depth, fullscreen);
	if ( NULL == g->con_font )
		g->con_font = font_load("data/font/acknowtt.png", 12, 16);
	if ( NULL == g->con_back )
		g->con_back = png_get_by_name("data/conback.png");
	con_init_display(g->con_font, g->con_back);
	return ret;
}
Ejemplo n.º 14
0
int mlua_load_font(lua_State* L)
{
	assert(L);

	const char* filename = luaL_checkstring(L, 1);
	lua_Number size = luaL_checknumber(L, 2);
	Font* font = font_load(filename, size, 32, 96);
	if (font) {
		push_font(L, font);
		return 1;
	}
	return luaL_fileresult(L, 0, filename);
}
Ejemplo n.º 15
0
GuiDesc greed_gui_style(bool highres) {
	GuiDesc style;

	gui_tex = tex_load("greed_assets/gui_new.png");
	if(highres) {
		huge_font = font_load_ex("greed_assets/lucida_grande_60px.bft", 0.5f);
		big_font = font_load_ex("greed_assets/lucida_grande_28px.bft", 0.5f);
		small_font = font_load_ex("greed_assets/lucida_grande_20px.bft", 0.5f);
	}	
	else {
		huge_font = font_load("greed_assets/lucida_grande_30px.bft");
		big_font = font_load("greed_assets/lucida_grande_14px.bft");
		small_font = font_load("greed_assets/lucida_grande_10px.bft");
	}	

	style.texture = gui_tex;
	style.font = big_font;

	style.text_color = COLOR_WHITE;

	style.first_layer = 12;
	style.second_layer = 13;
	style.text_layer = 14;

	style.src_button_up = rectf(0.0f, 0.0f, 252.0f, 41.0f);
	style.src_button_down = rectf(0.0f, 42.0f, 252.0f, 42.0f + 41.0f);
	style.src_switch_off_up = rectf(0.0f, 93.0f, 0.0f + 24.0f, 93.0f + 30.0f);
	style.src_switch_off_down = rectf(23.0f, 93.0f, 23.0f + 24.0f, 93.0f + 30.0f);
	style.src_switch_on_up = rectf(48.0f, 93.0f, 48.0f + 24.0f, 93.0f + 30.0f);
	style.src_switch_on_down = rectf(74.0f, 93.0f, 74.0f + 24.0f, 93.0f + 30.0f);
	style.src_slider = rectf(0.0f, 126.0f, 254.0f, 126.0f + 18.0f);
	style.src_slider_knob_up = rectf(1.0f, 149.0f, 1.0f + 18.0f, 149.0f + 18.0f);
	style.src_slider_knob_down = rectf(20.0f, 149.0f, 20.0f + 18.0f, 149.0f + 18.0f);

	return style;
}
Ejemplo n.º 16
0
int fonts_init() {
    font_create(&font_small);
    font_create(&font_large);
    char filename[64];

    // Load small font
    get_filename_by_id(DAT_CHARSMAL, filename);
    if(font_load(&font_small, filename, FONT_SMALL)) {
        PERROR("Unable to load font file '%s'!", filename);
        return 1;
    }
    INFO("Loaded font file '%s'", filename);

    // Load big font
    get_filename_by_id(DAT_GRAPHCHR, filename);
    if(font_load(&font_large, filename, FONT_BIG)) {
        PERROR("Unable to load font file '%s'!", filename);
        return 1;
    }
    INFO("Loaded font file '%s'", filename);

    // All done.
    return 0;
}
Ejemplo n.º 17
0
int dgreed_main(int argc, const char** argv) {
	params_init(argc, argv);
	rand_init(time(NULL));
	layouts_init();
	layouts_set("dvorak");

	bool fullscreen = true;
	if(params_find("-windowed") != ~0)
		fullscreen = false;

	video_init_ex(SCREEN_WIDTH, SCREEN_HEIGHT, 
		SCREEN_WIDTH, SCREEN_HEIGHT, "KeyMingler", fullscreen);
	font = font_load(FONT_FILE);	
	float text_width = font_width(font, LOADING_TEXT);
	float text_height = font_height(font);
	Vector2 pos = vec2((SCREEN_WIDTH - text_width) / 2.0f,
		(SCREEN_HEIGHT - text_height) / 2.0f);
	font_draw(font, LOADING_TEXT, 0, &pos, COLOR_WHITE);	
	video_present();
	system_update();

	game_init();
	sounds_init();
	music = sound_load_stream(MUSIC_FILE);
	sound_play(music);

	while(system_update()) {
		game_update();
		game_render();
		video_present();
		sound_update();

		if(key_up(KEY_QUIT))
			break;
	}
	
	font_free(font);
	sound_free(music);
	sounds_close();
	game_close();
	video_close();
	layouts_close();

	return 0;
}
Ejemplo n.º 18
0
void game_init( void )
{
    window = SDL_CreateWindow( game_name, SDL_WINDOWPOS_CENTERED, 
        SDL_WINDOWPOS_CENTERED, screen_width, screen_height, SDL_WINDOW_SHOWN );
    if ( window == NULL ) {
        send_error( EXIT_FAILURE );
    }
    render = SDL_CreateRenderer( window, -1, SDL_RENDERER_ACCELERATED | 
        SDL_RENDERER_PRESENTVSYNC );
    if ( render == NULL ) {
        send_error( EXIT_FAILURE );
    }
    tiles = IMG_LoadTexture( render, "./images/tiles.png" );
    srand( time( NULL ) );
    font_load( render, &ft, "../../00_other/font.cfg" );
    set_color( ft->font, 0xffffff );
    game_restart();
}
Ejemplo n.º 19
0
int Skin::load(char *name, bool quiet) {
    char d[512];
    setpath(name);
    makepath(d,"colors.conf");
    if (!Colors.load(d)) {
        sprintf(d, "Skin[%s]: Cannot load colors.conf", name); 
        if (!quiet) MessageBox(NULL,d,"Error",MB_ICONERROR | MB_OK);
        return 0;
    }
    SDL_Surface *s;
    pngLoad("toolbar.png");
    bmToolbar = new Bitmap( s , true );
    pngLoad("load.png");
    bmLoad = new Bitmap( s , true );
    pngLoad("save.png");
    bmSave = new Bitmap( s , true );
    pngLoad("buttons.png");
    bmButtons = new Bitmap( s , true );

    pngLoad("about.png");
    bmAbout = new Bitmap( s , true );
    if (640 != CONSOLE_WIDTH && 480 != CONSOLE_HEIGHT) {

        double xscale = (double)CONSOLE_WIDTH / 640;
        double yscale = (double)CONSOLE_HEIGHT / 480;
        Drawable ss( zoomSurface(bmAbout->surface, xscale, yscale ,SMOOTHING_ON) , false );
//        S->copy(&ss,5,row(12));
        SDL_FreeSurface( bmAbout->surface );
        bmAbout->surface = ss.surface;
    }    
    pngLoad("logo.png");
    SDL_FreeSurface(s);
    bmLogo = NULL;

    makepath(d,"font.fnt");
    if (font_load(d)) {
        sprintf(d, "Skin[%s]: Cannot load font.fnt", name); 
        if (!quiet) MessageBox(NULL,d,"Error",MB_ICONERROR | MB_OK);
        return 0;
    }
    
    return 1;
}
Ejemplo n.º 20
0
Archivo: main.c Proyecto: odrevet/GE
int state_paused(SDL_Surface* screen)
{
    TTF_Font *font = font_load("res/asia.ttf", 35);
    image* p_image_pause = image_load("./res/pause_XD.png");
    image_set_transp_color(p_image_pause, 255, 0, 255);
    SDL_Surface* background = SDL_DisplayFormat(screen);

    SDL_Rect bak_pos={0, 0, 0, 0};
    SDL_Rect cur_pos;
    SDL_Rect src_pos={0, 0, 144, 192};
    cur_pos.x = 250;
    cur_pos.y = 0;
    bool done=false;

    while (!done)
    {
        SDL_Event event;
        SDL_JoystickUpdate();
        while(SDL_PollEvent(&event)){
           if(event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_p) || (event.type == SDL_JOYBUTTONDOWN && event.jbutton.button == 5)){
                done = true;
            }
            else if((event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_x) || (event.type == SDL_JOYBUTTONDOWN && event.jbutton.button == 1)){
                src_pos.x = 144;
            }
        }
        if(cur_pos.y < SCREEN_HEIGHT / 2 - 144 / 2){
            cur_pos.y++;
        }
        SDL_BlitSurface(background, NULL, screen, &bak_pos);
        image_draw_part(p_image_pause, screen, cur_pos.x, cur_pos.y, src_pos.x, src_pos.y, src_pos.h, src_pos.w);
        font_printf(font, cur_pos.x + 30, cur_pos.y + 80, 255, 0, 0, screen, "pause");
        SDL_Flip(screen);
    }

    TTF_CloseFont(font);
    image_free(p_image_pause);
    SDL_FreeSurface(background);
    return 0;
}
Ejemplo n.º 21
0
void game_init( void )
{
    window = SDL_CreateWindow( game_name, SDL_WINDOWPOS_CENTERED, 
        SDL_WINDOWPOS_CENTERED, screen_width, screen_height, SDL_WINDOW_SHOWN );
    if ( window == NULL ) {
        send_error( EXIT_FAILURE );
    }
    render = SDL_CreateRenderer( window, -1, SDL_RENDERER_ACCELERATED | 
        SDL_RENDERER_PRESENTVSYNC );
    if ( render == NULL ) {
        send_error( EXIT_FAILURE );
    }
    srand( time( NULL ) );
    unit = IMG_LoadTexture( render, "./images/unit.png" );
    background = IMG_LoadTexture( render, "./images/background.png" );
    t_bullet = IMG_LoadTexture( render, "./images/bullet.png" );
    t_ammo = IMG_LoadTexture( render, "./images/ammo.png" );
    t_blood = IMG_LoadTexture( render, "./images/blood.png" );
    font_load( render, &ft, "../../00_other/font.cfg" );
    set_color( ft->font, 0x0 ); // black color
    game_struct_init();
}
Ejemplo n.º 22
0
void font_init()
{
  __font_max = 10;
  strncpy(__default_font,"fonts/default.ttf",LINELEN);
  slog("font: initializing\n");
  if (TTF_Init() != 0)
  {
    slog("font:unable to setup SDL_TTF");
    return;
  }
  atexit(TTF_Quit);
  atexit(font_close);
  __font_list = (Font *)malloc(sizeof(Font)*__font_max);
  memset(__font_list,0,sizeof(Font)*__font_max);
  __font_initialized = 1;
  __font_size[FontTiny] = font_load(__default_font,10);
  __font_size[FontSmall] = font_load(__default_font,12);
  __font_size[FontMedium] = font_load(__default_font,14);
  __font_size[FontLarge] = font_load(__default_font,18);
  __font_size[FontXLarge] = font_load(__default_font,32);
  __font_size[FontHuge] = font_load(__default_font,52);
  slog("font: initialized\n");
}
Ejemplo n.º 23
0
void
main ()
{
  UBYTE keys;
  UBYTE pos, old_pos = 0;
  UBYTE note, old_note = 0;
  UBYTE relative_octave = 0;
  UBYTE absolute_octave;
  UBYTE waveform = pulse_50;
  UBYTE mode = 0;
  UBYTE root = C;
  SCALE scale[8];

  font_t big_font, small_font;
  font_init ();
  big_font = font_load (font_ibm);
  small_font = font_load (font_spect);
  font_set (big_font);
 
  printf (";; Boueux v%s\n", BOUEUX_VERSION);
 
  INIT_SOUND;
  MASTER_VOLUME = OFF;
  update_waveform (waveform);
  MASTER_VOLUME = HIGH;
  
  build_scale_mode (scale, root, mode);
  
  for (;;)
   {
    keys = joypad ();
    pos = scale_position (keys);
    
    if (pos)
     {
      note = scale[pos - 1] + relative_octave*OCTAVE_LEN;
    
      /* Raise by perfect 4th */
      if (PRESSED (B)) note += 5; /* a perfect fourth = 5 semitones */
      /* Lower by semitone */
      if (PRESSED (A)) note -= 1;
     }
    
    /* Change octave */
    if (PRESSED (START))
     {
      relative_octave = !relative_octave;
      printf ("\n;; rel octave +%d\n", relative_octave);
      WAIT_KEY_UP (START);
     }

    if (PRESSED (SELECT))
     {
       /* Change mode */
       if (PRESSED (RIGHT))
        {
         mode = (mode + 1) % NUM_MODES;
         WAIT_KEY_UP (RIGHT);
         build_scale_mode (scale, root, mode);
        }
       /* Change waveform */
       if (PRESSED (LEFT))
        {
         WAIT_KEY_UP (LEFT);
         waveform = (waveform + 1) % NUM_WAVEFORMS;
         update_waveform (waveform);
       }
       /* Increment root note */
       if (PRESSED (UP))
        {
         WAIT_KEY_UP (UP);
         root = (root + 1) % OCTAVE_LEN;
         build_scale_mode (scale, root, mode);
        }
       /* Decrement root note */
       if (PRESSED (DOWN))
        {
         WAIT_KEY_UP (DOWN);
         if (root == 0)
           root = OCTAVE_LEN - 1;
         else
           root = (root - 1) % OCTAVE_LEN;
         build_scale_mode (scale, root, mode);
        }
        
       continue;
     }

     if ((note != old_note) || (pos != old_pos))
     {
      if (pos) /* Note will be played */
       {
        CH1_VOL = HIGH;
        CH2_VOL = HIGH;
        
        play_note (note, waveform);
        
        font_set (small_font);
        printf (note_names[note % OCTAVE_LEN]);
        
        absolute_octave = note/OCTAVE_LEN + 3;
        printf ("%d", absolute_octave);
        
        printf (" ");
        font_set (big_font);
       }
      else /* Stop note */
       {
        CH1_VOL = OFF;
        CH2_VOL = OFF;
        printf (". ");
       }
     }
    
    if (waveform == wawa) wawa_update();
    
    old_note = note;
    old_pos = pos;
   }
}
Ejemplo n.º 24
0
int main(int argc, char **argv) {
        const char *vc;
        char *vc_keymap = NULL;
        char *vc_keymap_toggle = NULL;
        char *vc_font = NULL;
        char *vc_font_map = NULL;
        char *vc_font_unimap = NULL;
        int fd = -1;
        bool utf8;
        pid_t font_pid = 0, keymap_pid = 0;
        bool font_copy = false;
        int r = EXIT_FAILURE;

        log_set_target(LOG_TARGET_AUTO);
        log_parse_environment();
        log_open();

        umask(0022);

        if (argv[1])
                vc = argv[1];
        else {
                vc = "/dev/tty0";
                font_copy = true;
        }

        fd = open_terminal(vc, O_RDWR|O_CLOEXEC);
        if (fd < 0) {
                log_error("Failed to open %s: %m", vc);
                goto finish;
        }

        if (!is_vconsole(fd)) {
                log_error("Device %s is not a virtual console.", vc);
                goto finish;
        }

        utf8 = is_locale_utf8();

        r = parse_env_file("/etc/vconsole.conf", NEWLINE,
                           "KEYMAP", &vc_keymap,
                           "KEYMAP_TOGGLE", &vc_keymap_toggle,
                           "FONT", &vc_font,
                           "FONT_MAP", &vc_font_map,
                           "FONT_UNIMAP", &vc_font_unimap,
                           NULL);

        if (r < 0 && r != -ENOENT)
                log_warning("Failed to read /etc/vconsole.conf: %s", strerror(-r));

        /* Let the kernel command line override /etc/vconsole.conf */
        if (detect_container(NULL) <= 0) {
                r = parse_env_file("/proc/cmdline", WHITESPACE,
                                   "vconsole.keymap", &vc_keymap,
                                   "vconsole.keymap.toggle", &vc_keymap_toggle,
                                   "vconsole.font", &vc_font,
                                   "vconsole.font.map", &vc_font_map,
                                   "vconsole.font.unimap", &vc_font_unimap,
                                   NULL);

                if (r < 0 && r != -ENOENT)
                        log_warning("Failed to read /proc/cmdline: %s", strerror(-r));
        }

        if (utf8)
                enable_utf8(fd);
        else
                disable_utf8(fd);

        r = EXIT_FAILURE;
        if (keymap_load(vc, vc_keymap, vc_keymap_toggle, utf8, &keymap_pid) >= 0 &&
            font_load(vc, vc_font, vc_font_map, vc_font_unimap, &font_pid) >= 0)
                r = EXIT_SUCCESS;

finish:
        if (keymap_pid > 0)
                wait_for_terminate_and_warn(KBD_LOADKEYS, keymap_pid);

        if (font_pid > 0) {
                wait_for_terminate_and_warn(KBD_SETFONT, font_pid);
                if (font_copy)
                        font_copy_to_all_vcs(fd);
        }

        free(vc_keymap);
        free(vc_font);
        free(vc_font_map);
        free(vc_font_unimap);

        safe_close(fd);

        return r;
}
Ejemplo n.º 25
0
Archivo: main.c Proyecto: odrevet/GE
int state_options(SDL_Surface *screen)
{
    TTF_Font *font_menu = font_load("res/asia.ttf", 50);
    image *bg_image = image_load("res/options.jpg");
    Mix_Chunk *select = sample_load("res/select.wav");

    int i;
	//int initial_unit_nb = g_game.unit_nb;
    int font_quality = SOLID;
    int choice_current=1;
    SDL_Rect cur_pos;
    bool done = false;

    cur_pos.x = 10;
    cur_pos.y = 0;
    char sz_choice[20];

    #ifdef GEKKO
        unsigned int start=0;
        int timerset = false;
    #endif
SDL_EnableKeyRepeat(50, 10);
    while (!done)
    {
        #ifdef GEKKO
       unsigned int start=0;
       if (!timerset) {
            timerset=true;
            start=SDL_GetTicks();
        }

       unsigned int now=SDL_GetTicks();
           if ((now-start)>50) {
                timerset=false;
                SDL_JoystickUpdate();
                int joystate = SDL_JoystickGetHat(g_game.v_unit[0].joystick, 0);
                switch (joystate){
                    case SDL_HAT_DOWN:
                       if (choice_current <= 1){
                        sample_play(select);
                        choice_current++;
                        }
                    break;
                    case SDL_HAT_UP:
                        if (choice_current > 1){
                            sample_play(select);
                            choice_current--;
                        }
                    break;
                    case SDL_HAT_LEFT:
                        if (choice_current == 2)
                        {
                            if (g_game.block_fill >= 0.01)
                                g_game.block_fill -= 0.01;
                        }
                        else if (choice_current == 1)
                        {
                            if (g_game.unit_nb > 2)
                            {
                                g_game.unit_nb -= 1;
                            }
                        }
                    break;
                    case SDL_HAT_RIGHT:
                        if (choice_current == 2)
                        {
                            if (g_game.block_fill < 0.99)
                                g_game.block_fill += 0.01;
                        }
                        else if (choice_current == 1)
                        {
                            if (g_game.unit_nb < UNIT_MAX)
                            {
                                g_game.unit_nb++;
                            }
                        }
                    break;
                    default:
                    break;
                }
           }
        #endif


        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            switch ( event.type )
            {
            case SDL_QUIT:
                exit(EXIT_SUCCESS);
                break;
                case SDL_JOYBUTTONDOWN:
                    if(event.jbutton.button == 6){
                        done = true;
                    }
                break;
            case SDL_KEYDOWN:
                switch ( event.key.keysym.sym )
                {
                case SDLK_DOWN:
                    if (choice_current <= 1){
                        sample_play(select);
                        choice_current++;
                    }
                    break;
                case SDLK_UP:
                    if (choice_current > 1)
                    {
                        sample_play(select);
                        choice_current--;
                    }
                    break;
                case SDLK_LEFT:
                    if (choice_current == 2)
                    {
                        if (g_game.block_fill >= 0.01)
                            g_game.block_fill -= 0.01;
                    }
                    else if (choice_current == 1)
                    {
                        if (g_game.unit_nb > 2)
                        {
                            g_game.unit_nb--;
                        }
                    }
                    break;
                case SDLK_RIGHT:
                    if (choice_current == 2)
                    {
                        if (g_game.block_fill < 0.99)
                            g_game.block_fill += 0.01;
                    }
                    else if (choice_current == 1)
                    {
                        if (g_game.unit_nb < UNIT_MAX)
                        {
                            g_game.unit_nb++;
                        }
                    }
                    break;
                case SDLK_ESCAPE:
                    done = true;
                    break;
                default:
                    break;
                }
                break;
            }

            if(event.type == SDL_JOYBUTTONDOWN && event.jbutton.button == 6)done=true;
        }

        SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 20, 20, 20));
        image_draw(bg_image, screen, 0, 0);


        for (i=1;i<=2;i++)
        {
            if (i == 1)
            {
                sprintf(sz_choice, "%s < %.d >", "Player", g_game.unit_nb);
            }
            else if ( i == 2)
            {

                sprintf(sz_choice, "%s < %.0f%% >", "Block fill", g_game.block_fill * 100);
            }

            if (choice_current == i)
            {
                font_quality = SHADED;
            }
            else font_quality = SOLID;

            cur_pos.y = i*100;
            SDL_Surface *font_surface;
            font_surface = font_create_surface(font_menu, 250, 120, 35, 10, 100, 100, 100, 0, sz_choice, font_quality);
            SDL_BlitSurface(font_surface, NULL, screen, &cur_pos);
            SDL_FreeSurface(font_surface);
        }
        SDL_Flip(screen);
    }
    TTF_CloseFont(font_menu);
    SDL_FreeSurface(bg_image->surface);
    SDL_EnableKeyRepeat(0, 0);
    return OPTION;
}
Ejemplo n.º 26
0
Archivo: main.c Proyecto: odrevet/GE
int state_in_game(SDL_Surface *screen)
{
    SDL_Rect srcrect = {0, 0, 480, 480};                      //the part of the screen to be stretched, must be sup 0 and inf screen surface Height and Width
    SDL_Rect dstrect = set_rect(0, 0, SCREEN_HEIGHT, SCREEN_WIDTH);    //equals screen resolution

    int bomb_nb=0;
    int flame_nb=0;
    bool done = false;
    int i=0;                     //generic accumulator 1
    int j=0;                     //generic accumulator 2
    int k=0;                     //unit accumulator
    int tick_count=0;
    int tick_trigger=0;
    int time_elapsed=0;         //time elapsed in this round (in secondes)
    int last_time=0;
    int current_game_status=-1;

    timer *timer_battle = timer_init();
    timer_start(timer_battle);

    // load sample.wav in to sample
    Mix_Chunk *sample = sample_load("res/boom.wav");
    Mix_Music* music = music_load("res/music.xm");
    music_play(music);

    //initialize map
    map *p_map = malloc(sizeof(map));
    p_map->tile_height = 32;
    p_map->tile_width = 32;
    map_load_level(p_map, "res/level_01.map");
    p_map->p_chipset = image_load("res/classic.png");
    SDL_Surface* surface_menu = IMG_Load("./res/menu.png");
    SDL_SetColorKey(surface_menu, SDL_SRCCOLORKEY, SDL_MapRGB(surface_menu->format, 255, 0, 255));

    for (k=0;k<g_game.unit_nb;k++)
    {
        unit_tile_protect(g_game.v_unit+k, p_map);
    }

    int block_nb = map_block_add(p_map, g_game.block_fill, .5);         ///@todo the disp % is not implemented yet
    int panel_nb = panel_add(g_game.v_panel, p_map, block_nb);

    int random_comment = rand() % 9;
    char sz_comment[32];
    SDL_Rect pos_comment = set_rect(10, 465, 0, 0);
    int comment_time_elapsed;
    timer *timer_comment = timer_init();

    //Menu
    TTF_Font *font_menu = font_load("res/asia.ttf", 20);
    TTF_Font *font_result = font_load("res/asia.ttf", 75);

    SDL_Rect cur_pos;
    cur_pos.x = 42;
    cur_pos.y = 425;

    char sz_time[10];

    while (!done)
    {
        SDL_Event event;
        SDL_JoystickUpdate();
        while(SDL_PollEvent(&event)){
            for (k=0;k<g_game.unit_nb;k++)
            {
                if (!g_game.v_unit[k].is_dead)
                {
                    unit_handle_key(g_game.v_unit+k, &event, k, g_game.v_bomb, p_map, &bomb_nb);
                }
            }
           if(event.type == SDL_QUIT || ((event.type == SDL_KEYDOWN) && (event.key.keysym.sym == SDLK_ESCAPE)) || (event.type == SDL_JOYBUTTONDOWN && event.jbutton.button == 6)){
                    done = true;
                    current_game_status = MAIN_MENU;
            }
            else if((event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN)|| (event.type == SDL_JOYBUTTONDOWN && event.jbutton.button == 5)){
                    Mix_PauseMusic();
                    state_paused(screen);
                    Mix_ResumeMusic();
            }
        }

        for (k=0;k<g_game.unit_nb;k++){
            if(!g_game.v_unit[k].use_keyboard){
                int joystate = SDL_JoystickGetHat(g_game.v_unit[k].joystick, 0);
                switch (joystate){
                    case SDL_HAT_DOWN:
                        unit_set_vel_y(g_game.v_unit+k, g_game.v_unit[k].speed);
                        unit_set_vel_x(g_game.v_unit+k, 0);
                        g_game.v_unit[k].p_sprite->animation_current = DOWN;
                    break;
                    case SDL_HAT_UP:
                        unit_set_vel_y(g_game.v_unit+k, -g_game.v_unit[k].speed);
                        unit_set_vel_x(g_game.v_unit+k, 0);
                        g_game.v_unit[k].p_sprite->animation_current = UP;
                    break;
                    case SDL_HAT_RIGHT:
                        unit_set_vel_x(g_game.v_unit+k, g_game.v_unit[k].speed);
                        unit_set_vel_y(g_game.v_unit+k, 0);
                        g_game.v_unit[k].p_sprite->animation_current = RIGHT;
                    break;
                    case SDL_HAT_LEFT:
                        unit_set_vel_x(g_game.v_unit+k, -g_game.v_unit[k].speed);
                        unit_set_vel_y(g_game.v_unit+k, 0);
                        g_game.v_unit[k].p_sprite->animation_current = LEFT;
                    break;
                    default:
                        if ( g_game.v_unit[k].vel_x != 0 ){
                            unit_set_vel_x(g_game.v_unit+k, 0);
                            g_game.v_unit[k].p_sprite->v_anim[g_game.v_unit[k].p_sprite->animation_current].frame_current = 1;
                        }
                        if ( g_game.v_unit[k].vel_y != 0 ){
                            unit_set_vel_y(g_game.v_unit+k, 0);
                            g_game.v_unit[k].p_sprite->v_anim[g_game.v_unit[k].p_sprite->animation_current].frame_current = 1;
                        }

                    break;
                }
            }
        }

        tick_count = SDL_GetTicks();
        if (tick_count > tick_trigger / 60){
            tick_trigger = tick_count;
            SDL_FillRect(backbuffer, 0, SDL_MapRGB(backbuffer->format, 10, 20, 80));


            //draw the map
            map_draw(p_map, backbuffer);
            for (i=0;i<panel_nb;i++)
            {
                if(p_map->pp_tile[g_game.v_panel[i]->p_sprite->y / TILE_SIZE][g_game.v_panel[i]->p_sprite->x / TILE_SIZE].type != BLOCK)panel_draw(g_game.v_panel[i], backbuffer);
            }


            //check panels
            for (i=0;i<panel_nb;i++)
            {
                // for all units
                for (k=0;k<g_game.unit_nb;k++)
                {
                    //Check for bonus
                    if (g_game.v_panel[i]->p_sprite->y / TILE_SIZE == unit_get_bounding_index_center_y(g_game.v_unit+k)
                            && (g_game.v_panel[i]->p_sprite->x / TILE_SIZE == unit_get_bounding_index_center_x(g_game.v_unit+k)))
                    {
                        panel_apply(g_game.v_panel[i], g_game.v_unit+k);

                        panel_free(g_game.v_panel[i]);
                        panel_nb--;

                        //Left shift the vector
                        for (j=i;j<panel_nb;j++)
                        {
                            g_game.v_panel[j] = g_game.v_panel[j+1];
                        }
                    }
                }
            }

            //Draw and update bombs
            for (i=0;i<bomb_nb;i++)
            {
                bomb_draw(g_game.v_bomb[i], backbuffer);
                anim_sprite_update_frame(g_game.v_bomb[i]->p_sprite);
                bomb_update_timer(g_game.v_bomb[i]);

                if ((g_game.v_bomb[i]->time_left <= 0) || (p_map->pp_tile[g_game.v_bomb[i]->p_sprite->y / TILE_SIZE][g_game.v_bomb[i]->p_sprite->x / TILE_SIZE].type == FLAME))
                {
                    sample_play(sample);
                    bomb_explode(g_game.v_bomb[i], p_map, g_game.v_flame, &flame_nb);
                    bomb_nb--;

                    bomb_free(g_game.v_bomb[i]);

                    //Left shift the vector
                    for (j=i;j<bomb_nb;j++)
                    {
                        g_game.v_bomb[j] = g_game.v_bomb[j+1];
                    }
                }
            }

            //Check flame
            for (i=0;i<p_map->height;i++)
            {
                for (j=0;j<p_map->width[i];j++)
                {
                    // for all units, check if hitten (if unit center is on a tile with a flame flag)
                    for (k=0;k<g_game.unit_nb;k++)
                    {
                        if ((p_map->pp_tile[i][j].type == FLAME) &&
                                ((unit_get_index_x(g_game.v_unit+k) == j) &&
                                (unit_get_index_y(g_game.v_unit+k) == i)) &&
                                g_game.v_unit[k].is_dead == false)
                        {
                            g_game.v_unit[k].is_dead = true;
                            timer_start(timer_comment);

                            switch(random_comment)
                            {
                                case(0):sprintf(sz_comment, "Say goodbye, %s ", g_game.v_unit[k].name);
                                break;
                                case(1):sprintf(sz_comment, "burn %s, burn ! ", g_game.v_unit[k].name);
                                break;
                                case(2):sprintf(sz_comment, "%s vanished !!!!!! ", g_game.v_unit[k].name);
                                break;
                                case(3):sprintf(sz_comment, "unit_free(%s); //^^ ", g_game.v_unit[k].name);
                                break;
                                case(4):sprintf(sz_comment, "%s ? Where are you ? ", g_game.v_unit[k].name);
                                break;
                                case(5):sprintf(sz_comment, "%s was a good guy ", g_game.v_unit[k].name);
                                break;
                                case(6):sprintf(sz_comment, "HE says : \"HELLO, %s\" ", g_game.v_unit[k].name);
                                break;
                                case(7):sprintf(sz_comment, "%s has meet his programmer ", g_game.v_unit[k].name);
                                break;
                                case(8):sprintf(sz_comment, "$ %s>/dev/null ", g_game.v_unit[k].name);
                                break;
                                case(9):sprintf(sz_comment, "%s was not ignifugated ", g_game.v_unit[k].name);
                                break;
                            }
                        }
                    }
                }
            }

            //Draw and update flames
            for (i=0;i<flame_nb;i++)
            {
                flame_draw(g_game.v_flame[i], p_map, backbuffer);
                g_game.v_flame[i]->time_left--;
                if (g_game.v_flame[i]->time_left <= 0)
                {
                    flame_free(g_game.v_flame[i], p_map);
                    flame_nb--;

                    //Left shift the vector
                    for (j=i;j<flame_nb;j++)
                    {
                        g_game.v_flame[j] = g_game.v_flame[j+1];
                    }
                }
            }



            for (k=0;k<g_game.unit_nb;k++)
            {
                if (!g_game.v_unit[k].is_dead)
                {
                    unit_calc_bounding_box(g_game.v_unit+k);
                    unit_update(g_game.v_unit+k, p_map);
                }
            }
            // draw and update units
            unit_draw_from_z_index(g_game.v_unit, g_game.unit_nb, backbuffer);

            //Change every 1 second
            time_elapsed = timer_get_ticks (timer_battle) / 1000;
            if (time_elapsed != last_time){
                last_time = time_elapsed;       //Update current time

        /* Check if any unit won
                    This function is performed every second in order to dont call it to often, and
                    have a little delay if two or more units died almost in the same time (even ms, in the case
                    a unit is at the left of a bomb and an other at the right, the right unit win because the
                    flame is first put to the left...)
                */

                int unit_win;
                unit_win = unit_check_victory(g_game.v_unit, g_game.unit_nb);

                if (unit_win >= 0)
                {
                    //print win, sound, etc
                    g_game.v_unit[unit_win].victory++;
                    time_elapsed = 0;
                    ///@todo set a victories limit (from 1 to 5) and display a special image if win... for the moment, another battle
                    font_printf(font_result, TILE_SIZE * 2, TILE_SIZE * 5, 50, 150, 100, backbuffer, "%s wins", g_game.v_unit[unit_win].name);
                    done = true;
                    current_game_status = IN_GAME;
                    SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect);
                    SDL_Flip(screen);
                    SDL_Delay(2000);
                    break;
                }
                else if (unit_win == -1)
                {
                    font_printf(font_result, (3)*TILE_SIZE, (6)*TILE_SIZE, 50, 150, 100, backbuffer, "DRAW !");
                    done = true;
                    current_game_status = IN_GAME;
                    SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect);
                    SDL_Flip(screen);
                    SDL_Delay(2000);
                }

                if (g_game.time - time_elapsed <= 0)
                {
                    cur_pos.x = 240;
                    cur_pos.y = 140;
                    font_printf(font_result, (3)*TILE_SIZE, (6)*TILE_SIZE, 50, 150, 100, backbuffer, "TIMES UP !");
                    done = true;
                    ///@todo select action in times up (blocks falling, etc) for the moment, just a draw...
                    current_game_status = IN_GAME;
                    SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect);
                    SDL_Flip(screen);
                    SDL_Delay(2000);
                }

            }

            ////////////////////  MENU  ////////////////////
            //TIME
            sprintf(sz_time, "%.3d", g_game.time - time_elapsed);
            SDL_Surface *surface_time = font_create_surface(font_menu, 200, 200, 200, 10, 100, 100, 100, 0, sz_time, SOLID);
            SDL_BlitSurface(surface_time, NULL, backbuffer, &cur_pos);
            SDL_FreeSurface(surface_time);
            SDL_Rect menu_src, menu_dest;
            menu_src.h = 32;
            menu_src.w = 32;
            menu_src.x = 0;
            menu_src.y = 0;

            menu_dest.x = 5;
            menu_dest.y = 420;

            SDL_BlitSurface(surface_menu, &menu_src, backbuffer, &menu_dest);

            //VICTORIES
            for (k=0;k<g_game.unit_nb;k++)
            {
                char sz_victory_nb[20];
                SDL_Rect vic_pos = set_rect(10, 450, 0, 0);
                sprintf(sz_victory_nb, "%s: %d", g_game.v_unit[k].name, g_game.v_unit[k].victory);

                vic_pos.x += k * 100;
                SDL_Surface *surface_victory = font_create_surface(font_menu, 200, 200, 200, 10, 100, 100, 100, 0, sz_victory_nb, SOLID);
                SDL_BlitSurface(surface_victory, NULL, backbuffer, &vic_pos);
                SDL_FreeSurface(surface_victory);
            }

            //Comment
            if(timer_comment->started){
                comment_time_elapsed = timer_get_ticks(timer_comment) / 1000;
                if (comment_time_elapsed < 3)   //Display the comment 3 seconds
                {
                    font_printf(font_menu, pos_comment.x, pos_comment.y, 200, 200, 200, backbuffer, sz_comment);
                }
                else{   //done
                    timer_stop(timer_comment);
                    random_comment = rand() % 9;

                }
            }

            //DEBUG
#ifdef DEBUG
            font_printf(font_menu, 10, 10, 255, 255, 200, backbuffer, "flame nb : %d", flame_nb);
            font_printf(font_menu, 10, 30, 255, 255, 200, backbuffer, "bomb nb : %d", bomb_nb);
            font_printf(font_menu, 10, 50, 255, 255, 200, backbuffer, "unit nb : %d", g_game.unit_nb);
            font_printf(font_menu, 10, 70, 255, 255, 200, backbuffer, "fill nb : %.2f", g_game.block_fill);
            font_printf(font_menu, 10, 90, 255, 255, 200, backbuffer, "Blocks at startup : %d", block_nb);
            font_printf(font_menu, 10, 110, 255, 255, 200, backbuffer, "Time elapsed : %d", timer_get_ticks(timer_battle)/1000);
            font_printf(font_menu, 10, 130, 255, 255, 200, backbuffer, "unit 1 index: %d %d", unit_get_bounding_index_center_x(g_game.v_unit+0), unit_get_bounding_index_center_y(g_game.v_unit+0));


            SDL_Rect rect = unit_get_bounding_box(g_game.v_unit+0);
            SDL_FillRect(backbuffer, &rect, SDL_MapRGB(backbuffer->format, 255, 255, 0));
#endif

            SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect);
            SDL_Flip(screen);
        }//end thick
    }   //end while



    //Free the memory
    for (i=0;i<bomb_nb;i++)
    {
        bomb_free(g_game.v_bomb[i]);
    }
    for (i=0;i<panel_nb;i++)
    {
        panel_free(g_game.v_panel[i]);
    }
    for (i=0;i<flame_nb;i++)
    {
        flame_free(g_game.v_flame[i], p_map);
    }
    map_free(p_map);

    free(timer_battle);
    free(timer_comment);

    Mix_FreeChunk(sample);
    Mix_FreeMusic(music);

    TTF_CloseFont(font_menu);
    font_menu=NULL; // to be safe...

    TTF_CloseFont(font_result);
    font_result=NULL; // to be safe...

    return current_game_status;

}
Ejemplo n.º 27
0
Archivo: main.c Proyecto: odrevet/GE
int state_main_menu(SDL_Surface *screen)
{
    TTF_Font *font_menu = font_load("res/asia.ttf", 50);
    TTF_Font *font_credit = font_load("res/asia.ttf", 20);
    image *bg_image = image_load("res/main.jpg");
    Mix_Chunk *select = sample_load("res/select.wav");

    int i;
    const int item_nb = 2;
    int font_quality = SOLID;
    int choice_current=1;
    SDL_Rect cur_pos;
    bool done = false;
	//bool is_in_game = false;

    cur_pos.x = 10;
    cur_pos.y = 0;
    char sz_choice[20];

    #ifdef GEKKO
    bool timerset = false;
    #endif

    while (!done)
    {
        #ifdef GEKKO
       unsigned int start=0;
       if (!timerset) {
            timerset=true;
            start=SDL_GetTicks();
        }

       unsigned int now=SDL_GetTicks();
       if ((now-start)>50) {
            timerset=false;
            SDL_JoystickUpdate();
            int joystate = SDL_JoystickGetHat(g_game.v_unit[0].joystick, 0);
            switch (joystate){
                case SDL_HAT_DOWN:
                    if (choice_current < item_nb){
                        choice_current++;
                        sample_play(select);
                    }
                break;
                case SDL_HAT_UP:
                    if (choice_current > 1){
                        choice_current--;
                        sample_play(select);
                    }
                break;
            }
       }
       #endif



        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            switch ( event.type )
            {
            case SDL_QUIT:
                done = true;
                break;
            case SDL_KEYUP:
                switch ( event.key.keysym.sym )
                {
                case SDLK_DOWN:
                    if (choice_current < item_nb){
                        choice_current++;
                        sample_play(select);
                    }
                    break;
                case SDLK_UP:
                    if (choice_current > 1){
                        choice_current--;
                        sample_play(select);
                    }
                    break;
                case SDLK_RETURN:
                    while (choice_current == IN_GAME)
                    {
                        unit_default_param(g_game.v_unit, g_game.unit_nb);
                        choice_current = state_in_game(screen);
                        if (choice_current == MAIN_MENU)    //The current state is main menu, select in game as default choice and quit
                        {
                            choice_current = IN_GAME;
                            break;
                        }
                    }
                    if (choice_current == OPTION)state_options(screen);
                    break;

                default:
                    break;
                }
            break;
            case SDL_JOYBUTTONDOWN:
                switch(event.jbutton.button)
                {
                    case 0:
                    break;
                    case 1:
                    break;

                    case 2:
                        while (choice_current == IN_GAME)
                        {
                            unit_default_param(g_game.v_unit, g_game.unit_nb);
                            choice_current = state_in_game(screen);
                            if (choice_current == MAIN_MENU)    //The current state is main menu, select in game as default choice and quit
                            {
                                choice_current = IN_GAME;
                                break;
                            }
                        }
                        if (choice_current == OPTION)state_options(screen);
                    break;

                    case 3:
                    break;

                    case 4:
                    break;

                    case 5:
                    break;

                    case 6:
                        done = true;
                    break;
                }
            break;
            default:
            break;
            }
        }

        SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
        image_draw(bg_image, screen, 0, 0);

        int top_shift = 150;

        for (i=1;i<=2;i++)
        {
            if (i == 1)
            {
                strncpy(sz_choice, "Play", 20);
                sz_choice[19] = '\0';
            }
            else if ( i == 2)
            {
                strncpy(sz_choice, "Options", 20);
                sz_choice[19] = '\0';
            }

            if (choice_current == i)
            {
                font_quality = SHADED;
            }
            else font_quality = SOLID;

            cur_pos.y = top_shift + i*50;
            SDL_Surface *font_surface= font_create_surface(font_menu, 250, 120, 35, 10, 100, 100, 100, 0, sz_choice, font_quality);
            SDL_BlitSurface(font_surface, NULL, screen, &cur_pos);
            SDL_FreeSurface (font_surface);
        }

        cur_pos.y = 450;
        SDL_Surface *font_surface= font_create_surface(font_credit, 250, 120, 35, 10, 100, 100, 100, 0, "2010 - 2015 TheDrev", SOLID);
        SDL_BlitSurface(font_surface, NULL, screen, &cur_pos);
        SDL_FreeSurface (font_surface);

        SDL_Flip(screen);
    }

    //free font
    if(font_menu != NULL)TTF_CloseFont(font_menu);
    if(font_credit != NULL)TTF_CloseFont(font_credit);
    SDL_FreeSurface(bg_image->surface);
    Mix_FreeChunk(select);

    //free ressouces
    element* p_browse = images;
    while (p_browse) {
        ressource *res = p_browse->data;
        free(res->name);
        image_free(res->data);
        p_browse = p_browse->next;
    }

    linked_list_clear(&images);

    return EXIT_SUCCESS;
}
Ejemplo n.º 28
0
void settings_apply(bool read_disk)
{
    
    char buf[64];
#if CONFIG_CODEC == SWCODEC
    int i;
#endif
    sound_settings_apply();

#ifdef HAVE_DISK_STORAGE
    audio_set_buffer_margin(global_settings.buffer_margin);
#endif

#ifdef HAVE_LCD_CONTRAST
    lcd_set_contrast(global_settings.contrast);
#endif
    lcd_scroll_speed(global_settings.scroll_speed);
#ifdef HAVE_REMOTE_LCD
    lcd_remote_set_contrast(global_settings.remote_contrast);
    lcd_remote_set_invert_display(global_settings.remote_invert);

#ifdef HAVE_LCD_FLIP
    lcd_remote_set_flip(global_settings.remote_flip_display);
#endif

    lcd_remote_scroll_speed(global_settings.remote_scroll_speed);
    lcd_remote_scroll_step(global_settings.remote_scroll_step);
    lcd_remote_scroll_delay(global_settings.remote_scroll_delay);
    lcd_remote_bidir_scroll(global_settings.remote_bidir_limit);
#ifdef HAVE_REMOTE_LCD_TICKING
    lcd_remote_emireduce(global_settings.remote_reduce_ticking);
#endif
    remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
#if CONFIG_CHARGING
    remote_backlight_set_timeout_plugged(global_settings.remote_backlight_timeout_plugged);
#endif
#ifdef HAS_REMOTE_BUTTON_HOLD
    remote_backlight_set_on_button_hold(global_settings.remote_backlight_on_button_hold);
#endif
#endif /* HAVE_REMOTE_LCD */
#ifdef HAVE_BACKLIGHT_BRIGHTNESS
    backlight_set_brightness(global_settings.brightness);
#endif
#ifdef HAVE_BACKLIGHT
    backlight_set_timeout(global_settings.backlight_timeout);
#if CONFIG_CHARGING
    backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
#endif
#if    defined(HAVE_BACKLIGHT_FADING_INT_SETTING) \
    || defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
    backlight_set_fade_in(global_settings.backlight_fade_in);
    backlight_set_fade_out(global_settings.backlight_fade_out);
#endif
#endif
#ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
    buttonlight_set_brightness(global_settings.buttonlight_brightness);
#endif
#ifdef HAVE_BUTTON_LIGHT
    buttonlight_set_timeout(global_settings.buttonlight_timeout);
#endif
#ifdef HAVE_DISK_STORAGE
    storage_spindown(global_settings.disk_spindown);
#endif
#if (CONFIG_CODEC == MAS3507D) && !defined(SIMULATOR)
    dac_line_in(global_settings.line_in);
#endif
    set_poweroff_timeout(global_settings.poweroff);

    set_battery_capacity(global_settings.battery_capacity);
#if BATTERY_TYPES_COUNT > 1
    set_battery_type(global_settings.battery_type);
#endif

#ifdef HAVE_LCD_BITMAP
#ifdef HAVE_LCD_INVERT
    lcd_set_invert_display(global_settings.invert);
#endif
#ifdef HAVE_LCD_FLIP
    lcd_set_flip(global_settings.flip_display);
    button_set_flip(global_settings.flip_display);
#endif
    lcd_update(); /* refresh after flipping the screen */
    settings_apply_pm_range();
    peak_meter_init_times(
        global_settings.peak_meter_release, global_settings.peak_meter_hold,
        global_settings.peak_meter_clip_hold);
#endif

#ifdef HAVE_SPEAKER
    audiohw_enable_speaker(global_settings.speaker_enabled);
#endif

    if (read_disk)
    {
#ifdef HAVE_LCD_BITMAP
        /* fonts need to be loaded before the WPS */
        if ( global_settings.font_file[0]) {
            snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt",
                     global_settings.font_file);
            if (font_load(NULL, buf) < 0)
                font_reset(NULL);
        }
        else
            font_reset(NULL);
#ifdef HAVE_REMOTE_LCD        
        if ( global_settings.remote_font_file[0]) {
            snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt",
                     global_settings.remote_font_file);
            if (font_load_remoteui(buf) < 0)
                font_load_remoteui(NULL);
        }
        else
            font_load_remoteui(NULL);
#endif
        if ( global_settings.kbd_file[0]) {
            snprintf(buf, sizeof buf, ROCKBOX_DIR "/%s.kbd",
                     global_settings.kbd_file);
            load_kbd(buf);
        }
        else
            load_kbd(NULL);
#endif

        if ( global_settings.lang_file[0]) {
            snprintf(buf, sizeof buf, LANG_DIR "/%s.lng",
                     global_settings.lang_file);
            lang_core_load(buf);
            talk_init(); /* use voice of same language */
        }

        /* reload wpses */
        settings_apply_skins();

        /* load the icon set */
        icons_init();

#ifdef HAVE_LCD_COLOR
        if (global_settings.colors_file[0])
            read_color_theme_file();
#endif
    }

#ifdef HAVE_LCD_COLOR
    screens[SCREEN_MAIN].set_foreground(global_settings.fg_color);
    screens[SCREEN_MAIN].set_background(global_settings.bg_color);
    screens[SCREEN_MAIN].set_selector_start(global_settings.lss_color);
    screens[SCREEN_MAIN].set_selector_end(global_settings.lse_color);
    screens[SCREEN_MAIN].set_selector_text(global_settings.lst_color);
#endif

#ifdef HAVE_LCD_BITMAP
    lcd_scroll_step(global_settings.scroll_step);
    gui_list_screen_scroll_step(global_settings.screen_scroll_step);
    gui_list_screen_scroll_out_of_view(global_settings.offset_out_of_view);
#else
    lcd_jump_scroll(global_settings.jump_scroll);
    lcd_jump_scroll_delay(global_settings.jump_scroll_delay);
#endif
    lcd_bidir_scroll(global_settings.bidir_limit);
    lcd_scroll_delay(global_settings.scroll_delay);


    set_codepage(global_settings.default_codepage);

#if CONFIG_CODEC == SWCODEC
#ifdef HAVE_CROSSFADE
    audio_set_crossfade(global_settings.crossfade);
#endif
    dsp_set_replaygain();
    dsp_set_crossfeed(global_settings.crossfeed);
    dsp_set_crossfeed_direct_gain(global_settings.crossfeed_direct_gain);
    dsp_set_crossfeed_cross_params(global_settings.crossfeed_cross_gain,
                                   global_settings.crossfeed_hf_attenuation,
                                   global_settings.crossfeed_hf_cutoff);

    /* Configure software equalizer, hardware eq is handled in audio_init() */
    dsp_set_eq(global_settings.eq_enabled);
    dsp_set_eq_precut(global_settings.eq_precut);
    for(i = 0; i < 5; i++) {
        dsp_set_eq_coefs(i);
    }

    dsp_dither_enable(global_settings.dithering_enabled);
    dsp_timestretch_enable(global_settings.timestretch_enabled);
    dsp_set_compressor(global_settings.compressor_threshold,
                       global_settings.compressor_makeup_gain,
                       global_settings.compressor_ratio,
                       global_settings.compressor_knee,
                       global_settings.compressor_release_time);
#endif

#ifdef HAVE_SPDIF_POWER
    spdif_power_enable(global_settings.spdif_enable);
#endif

#ifdef HAVE_BACKLIGHT
    set_backlight_filter_keypress(global_settings.bl_filter_first_keypress);
#ifdef HAVE_REMOTE_LCD
    set_remote_backlight_filter_keypress(global_settings.remote_bl_filter_first_keypress);
#endif
#ifdef HAS_BUTTON_HOLD
    backlight_set_on_button_hold(global_settings.backlight_on_button_hold);
#endif
#ifdef HAVE_LCD_SLEEP_SETTING
    lcd_set_sleep_after_backlight_off(global_settings.lcd_sleep_after_backlight_off);
#endif
#endif /* HAVE_BACKLIGHT */

#ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
    touchpad_set_sensitivity(global_settings.touchpad_sensitivity);
#endif

#ifdef HAVE_USB_CHARGING_ENABLE
    usb_charging_enable(global_settings.usb_charging);
#endif

#ifdef HAVE_TOUCHSCREEN
    touchscreen_set_mode(global_settings.touch_mode);
    memcpy(&calibration_parameters, &global_settings.ts_calibration_data, sizeof(struct touchscreen_parameter));
#endif

    /* This should stay last */
#if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
    enc_global_settings_apply();
#endif
#ifdef HAVE_LCD_BITMAP
    /* already called with THEME_STATUSBAR in settings_apply_skins() */
    viewportmanager_theme_changed(THEME_UI_VIEWPORT|THEME_LANGUAGE);
#endif
}
Ejemplo n.º 29
0
static void *ctor(renderer_t r, void *common)
{
	struct _world *world = NULL;
	vec3_t spawn;

	world = calloc(1, sizeof(*world));
	if ( NULL == world )
		goto out;

	world->render = r;
	renderer_viewangles(r, 45.0, 45.0, 0.0);

	world->map = map_load(r, "data/maps/level1");
	if ( NULL == world->map )
		goto out_free;

	spawn[0] = 0.0;
	spawn[1] = CHOPPER_HEIGHT;
	spawn[2] = 0.0;

	world->apache = chopper_comanche(spawn, 0.785);
	if ( NULL == world->apache )
		goto out_free_map;

	world->light = light_new(r, LIGHT_CAST_SHADOWS);
	if ( NULL == world->light ) {
		goto out_free_chopper;
	}

	world->font = font_load(r, "data/font/carbon.png", 16, 16);
	if ( NULL == world->font )
		goto out_free_light;

	world->lightRate = 1440;
	world->light_ticks = 10;

	world->cvars = cvar_ns_new("world");
	if ( NULL == world->cvars )
		goto out_free_font;
		
	cvar_register_float(world->cvars, "time", CVAR_FLAG_SAVE_ALWAYS, &world->lightAngle);
	cvar_register_float(world->cvars, "lightRate", CVAR_FLAG_SAVE_NOTDEFAULT, &world->lightRate);
	cvar_register_uint(world->cvars, "tpf", CVAR_FLAG_SAVE_NOTDEFAULT, &world->light_ticks);
		
	cvar_ns_load(world->cvars);

	world->fcnt = (world->lightAngle / (M_PI / world->lightRate));
	world->fcnt *= world->light_ticks;
	
	/* success */
	goto out;

out_free_font:
	font_free(world->font);
out_free_light:
	light_free(world->light);
out_free_chopper:
	chopper_free(world->apache);
out_free_map:
	map_free(world->map);
out_free:
	free(world);
	world = NULL;
out:
	return world;
}
Ejemplo n.º 30
0
void font::menu_Font ( void )
{
	int rez  = 0;
	QString  str;
	QString   fileName;

	do
	{
		print();
//  edit_menu::s_menu_font_main->run();
//  rez = edit_menu::s_menu_font_main->get_run_rez();

		switch ( rez )
		{

			case 0: //Open
				fileName = QFileDialog::getOpenFileName ( 0, QString ( "Open File" ), QString ( "/home/namatv/workspace/u2/shp" ), QString ( "Shape files (*.shp)" ) );
//    fileName = QString ( "/home/namatv/workspace/u2/shp/es_unicode.shp" );
				std_out << fileName << endl;

				if ( fileName != 0 )
				{
					set_file_name ( fileName );
				}

				font_load();

				break;

			case 1: //Save
				font_save();
				break;

			case 2: //Save as
				break;

			case 3: //Edit header
				menu_Parametr();
				break;

			case 4: //Edit forms
				menu_Forms();
				break;

			case 5: //Draw vars
				break;

			case 6: //Close
				break;

			case 7: //Exit
				break;


			default :
				break;
		}
	}

	while ( rez >= 0 && rez < 7 );
}