示例#1
0
CAllegroDisplay::CAllegroDisplay(int width,int height,int color_depth,char *error_file)
{
  /*
    Init the error log handler
  */
  error_log = fopen(error_file,"at");
  if (error_file == NULL) 
  {
    error_log = stdout;
    PrintError("Error opening error_log file!!!\n");
  }
  
  /*
    Init allegro graphic library
  */
  allegro_init();
  install_timer();
  install_keyboard();
  install_mouse();
  alfont_init();
  
  show_mouse(NULL);
  /*
    Try to init display resolution
  */
  set_color_depth(color_depth);
  if (set_gfx_mode(GFX_AUTODETECT_FULLSCREEN,width,height,0,0)) fatalError(allegro_error);
  set_display_switch_mode(SWITCH_PAUSE);
  srandom(time(0));
}
示例#2
0
/* _win_reset_switch_mode:
 *  Resets the switch mode to its default state.
 */
void _win_reset_switch_mode(void)
{
   /* The default state must be SWITCH_BACKGROUND so that the
      threads don't get blocked when the focus moves forth and
      back during window creation and destruction.  This seems
      to be particularly relevant to WinXP.  */
   set_display_switch_mode(SWITCH_BACKGROUND);

   _win_app_foreground = TRUE;
}
示例#3
0
/* gfx_gdi_init:
 */
static struct BITMAP *gfx_gdi_init(int w, int h, int v_w, int v_h, int color_depth)
{
   /* virtual screen are not supported */
   if ((v_w!=0 && v_w!=w) || (v_h!=0 && v_h!=h))
      return NULL;
   
   _enter_critical();

   gfx_gdi.w = w;
   gfx_gdi.h = h;

   if (adjust_window(w, h) != 0) {
      _TRACE(PREFIX_E "window size not supported.\n");
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Resolution not supported"));
      goto Error;
   }

   /* the last flag serves as an end of loop delimiter */
   gdi_dirty_lines = _AL_MALLOC_ATOMIC((h+1) * sizeof(char));
   ASSERT(gdi_dirty_lines);
   memset(gdi_dirty_lines, 0, (h+1) * sizeof(char));
   gdi_dirty_lines[h] = 1;

   /* create the screen surface */
   screen_surf = _AL_MALLOC_ATOMIC(w * h * BYTES_PER_PIXEL(color_depth));
   gdi_screen = _make_bitmap(w, h, (unsigned long)screen_surf, &gfx_gdi, color_depth, w * BYTES_PER_PIXEL(color_depth));
   gdi_screen->write_bank = gfx_gdi_write_bank; 
   _screen_vtable.acquire = gfx_gdi_lock;
   _screen_vtable.release = gfx_gdi_unlock;
   _screen_vtable.unwrite_bank = gfx_gdi_unwrite_bank; 

   /* create render timer */
   vsync_event = CreateEvent(NULL, FALSE, FALSE, NULL);
   install_int(render_proc, RENDER_DELAY);

   /* connect to the system driver */
   win_gfx_driver = &win_gfx_driver_gdi;

   /* set the default switching policy */
   set_display_switch_mode(SWITCH_PAUSE);

   /* grab input devices */
   win_grab_input();

   _exit_critical();

   return gdi_screen;

 Error:
   _exit_critical();

   gfx_gdi_exit(NULL);

   return NULL;
}
示例#4
0
/* finalize_fullscreen_init:
 *  Finalizes initialization of the three fullscreen drivers.
 */
static void finalize_fullscreen_init(void)
{
   /* connect to the system driver */
   win_gfx_driver = &win_gfx_fullscreen;

   /* set the default switching policy */
   set_display_switch_mode(SWITCH_AMNESIA);

   /* grab input devices */
   win_grab_input();
}
示例#5
0
int main(int argc, char *argv[])
{	
	//////////////////////////////////////////////////////////////////////////
	allegro_init(); // Initialize Allegro
	install_keyboard();
	set_close_button_callback(quit_function);
	FreeImage_Initialise(TRUE);

	create_cycles_table();

	Configuration cfg;
	cfg.Process(argc, argv);

	if (cfg.continue_processing)
	{
		quiet=true;
		rasta.Resume();
		rasta.cfg.continue_processing=true;
		quiet=false;
	}
	else
		rasta.SetConfig(cfg);

	screen_color_depth = desktop_color_depth();
	get_desktop_resolution(&desktop_width,&desktop_height);
	set_color_depth(screen_color_depth);

	if (!rasta.cfg.preprocess_only)
	{
		if (desktop_width>=320*3)
			set_gfx_mode(GFX_AUTODETECT_WINDOWED, 320*3,480,0,0); 
		else
			set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480,0,0); // Change our graphics mode to 640x480

		set_display_switch_mode(SWITCH_BACKGROUND);
		set_close_button_callback(close_button_procedure);

		set_window_title(rasta.cfg.command_line.c_str());
	}
	else
		quiet=true;

	rasta.LoadAtariPalette();

	rasta.LoadInputBitmap();
	if (rasta.ProcessInit())
	{
		rasta.FindBestSolution();
		rasta.SaveBestSolution();
	}
	return 0; // Exit with no errors
}
示例#6
0
文件: allegro.c 项目: gsrr/Python
static int setgfxmode(int fullscreen)
{
	if (!fullscreen &&
	    set_gfx_mode(GFX_AUTODETECT_WINDOWED, 512, 400, 0, 0) == 0) {
		term_width = 64;
		set_display_switch_mode(SWITCH_BACKGROUND);
		set_display_switch_callback(SWITCH_OUT, lost_focus);
		return 1;
	}
	if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) == 0) {
		term_width = 80;
		set_display_switch_mode(SWITCH_PAUSE);
		return 1;
	}
	if (get_color_depth() != 8) {
		set_color_depth(8);
		return setgfxmode(fullscreen);
	}
	set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
	allegro_message("Unable to set any graphics mode:\n"
			"%s\n", allegro_error);
	return 0;
}
示例#7
0
/* __al_linux_use_console:
 *   Init Linux console if not initialized yet.
 */
int __al_linux_use_console(void)
{
   console_users++;
   if (console_users > 1) return 0;

   if (init_console()) {
      console_users--;
      return 1;
   }

   /* Initialise the console switching system */
   set_display_switch_mode (SWITCH_PAUSE);
   return __al_linux_init_vtswitch();
}
示例#8
0
int main(int argc, char **argv)
{
	bool fullScreen;
	int windowW, windowH;

	srand(time(0));
	allegro_init();

	install_keyboard();
	install_mouse();
	install_timer();
	install_joystick(JOY_TYPE_AUTODETECT);

	set_color_depth(32);

	CheckMIDIs();
	set_config_file("trog.cfg");

	CfgLoad();

	set_gfx_mode(cfgFull ? GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED, std::atoi(cfgW), std::atoi(cfgH), 0, 0);
	install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, 0);

	set_window_title("The Revenge of Gregorius");
	set_display_switch_mode(SWITCH_BACKGROUND);
	set_display_switch_callback(SWITCH_OUT, &SwitchOut);
	
	LoadSoundVolumes("sounds.cfg");
	game.Init();

	bool notQuit = true;
	while(notQuit)
	{
		int ret = MainMenu();
		switch(ret)
		{
			case 0:
				game.zoomMode = cfgZoom;
				game.Start(-1);
				break;
			case 1:
				DoConfiguration();
				break;
			case 2:
				notQuit = false;
				break;
		}
	}
	return 0;
}
示例#9
0
/* gfx_gdi_exit:
 */
static void gfx_gdi_exit(struct BITMAP *bmp)
{
   _enter_critical();

   _enter_gfx_critical();

   if (bmp) {
      save_window_pos();
      clear_bitmap(bmp);
   }

   /* stop timer */
   remove_int(render_proc);
   CloseHandle(vsync_event);

   /* disconnect from the system driver */
   win_gfx_driver = NULL;

   /* destroy dirty lines array */   
   _AL_FREE(gdi_dirty_lines);
   gdi_dirty_lines = NULL;   

   /* destroy screen surface */
   _AL_FREE(screen_surf);
   gdi_screen = NULL;

   /* destroy mouse bitmaps */
   if (wgdi_mouse_sprite) {
      destroy_bitmap(wgdi_mouse_sprite);
      wgdi_mouse_sprite = NULL;

      destroy_bitmap(mouse_frontbuffer);
      mouse_frontbuffer = NULL;

      destroy_bitmap(mouse_backbuffer);
      mouse_backbuffer = NULL;
   }

   _exit_gfx_critical();

   /* before restoring video mode, hide window */
   set_display_switch_mode(SWITCH_PAUSE);
   system_driver->restore_console_state();
   restore_window_style();

   _exit_critical();
}
示例#10
0
int WINAPI WinMain(
    HINSTANCE hInstance,  // handle to current instance
    HINSTANCE hPrevInstance,  // handle to previous instance
    LPSTR lpCmdLine,      // pointer to command line
    int nCmdShow) {

    install_allegro(SYSTEM_AUTODETECT, &errno, atexit);

    install_keyboard();

    set_color_depth(16);
    set_gfx_mode (GFX_DIRECTX_WIN, 640, 480, 0,0);

    set_display_switch_mode(SWITCH_BACKGROUND);

    dxmedia_play_video ("f:\\download\\Seinfeld S05E04 - The Sniffing Accountant.mpg", 1, 1);
    dxmedia_play_video ("f:\\download\\Family Guy S02E16 - There's Something About Paulie.mpg", 2, 1);

    return 0;
}
示例#11
0
文件: allegro.c 项目: gsrr/Python
BITMAP *set_screen(int fullscreen)
{
	const unsigned char
	vgargb[16][3] = {
		  0,  0,  0,	/* 0 black */
		170,  0,  0,	/* 1 red */
		  0,170,  0, 	/* 2 green */
		170, 85,  0, 	/* 3 yellow */
		  0,  0,170,	/* 4 blue */
		170,  0,170,	/* 5 magenta */
		  0,170,170,	/* 6 cyan */
		170,170,170,	/* 7 white */
		 85, 85, 85,
		255, 85, 85,
		 85,255, 85,
		255,255, 85,
		 85, 85,255,
		255, 85,255,
		 85,255,255,
		255,255,255
	};
	const unsigned char *rgb;
	if (!setgfxmode(fullscreen))
		exit(1);
	clear_bitmap(screen);
	if (set_display_switch_callback(SWITCH_IN, got_focus_back) == -1)
		set_display_switch_mode(SWITCH_PAUSE);
	BITMAP *bmp = create_bitmap(8 * term_width, 400);
	clear_bitmap(bmp);
	set_clip_state(bmp, 0);
	set_clip_state(screen, 0);
	int i;
	for (i=0; i<16; i++) {
		rgb = &vgargb[i][0];
		vgacolors[i] = makecol(rgb[0], rgb[1], rgb[2]);
	}
	return bmp;
}
示例#12
0
/* _xdga2_gfxdrv_exit:
 *  Shuts down gfx driver.
 */
static void _xdga2_gfxdrv_exit(BITMAP *bmp)
{
   XLOCK();
   
   if (_xwin.in_dga_mode) {
      _xwin_input_handler = 0;
       
      XDGACloseFramebuffer(_xwin.display, _xwin.screen);
      XDGASetMode(_xwin.display, _xwin.screen, 0);
      _xwin.in_dga_mode = 0;

      if (_dga_cmap) {
         XFreeColormap(_xwin.display, _dga_cmap);
         _dga_cmap = 0;
      }

      XInstallColormap(_xwin.display, _xwin.colormap);

      set_display_switch_mode(SWITCH_BACKGROUND);
   }
   
   XUNLOCK();
}
void inicia_allegro() {
	int profundidade, res;
	allegro_init();
	install_timer();
	install_keyboard();
	clear_keybuf();
	install_mouse();

	set_uformat(U_ASCII); // Habilita acentuação em ALGUMAS FONTES
	/*profundidade = desktop_color_depth();
	if (profundidade == 0) profundidade = 32;
	   set_color_depth(profundidade);*/

	//roda configuracao de um arquivo
	set_config_file("config.txt");

	profundidade = get_config_int("Inicializacao", "colordepth",32);
	int v = GetVersion() & 65535;
    float versao = (v%256) + (v/256)/10.;
    /*if (versao<=5.1) //5.1 = XP, 6.0 = Vista, 6.1 Win7
        profundidade=16;
    else
        profundidade=32;*/

	set_color_depth(profundidade); //padrao é 32 bits, no XP é 16

	volume=get_config_int("Inicializacao", "volume", 128); //usa as config de volume do arquivo
	exibirFPS=get_config_int("Inicializacao", "exibirFps", 0);

	#define GFX_BWINDOWSCREEN_ACCEL AL_ID('B','W','S','A')
	#define GFX_BWINDOWSCREEN        AL_ID('B','W','S',' ')
    AL_VAR(GFX_DRIVER, gfx_beos_bwindowscreen_accel);
    AL_VAR(GFX_DRIVER, gfx_beos_bwindowscreen);

	vSync = get_config_int("Inicializacao", "vsync",0);
	resolucaoX = get_config_int("Inicializacao", "resolucaox",800);
	resolucaoY = get_config_int("Inicializacao", "resolucaoy",600);
    //Fullscreen
    //res = set_gfx_mode(GFX_AUTODETECT_FULLSCREEN & GFX_BWINDOWSCREEN_ACCEL, resolucaoX, resolucaoY, 0, 0);
    //Janela
	res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, resolucaoX, resolucaoY, 0, 0);
	if (res != 0) {
		allegro_message(allegro_error);
		exit(-1);
	}
	if(install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL))
    {
        allegro_message("Sound Error: %s", allegro_error);
    }

	//inicializa o metodo de atualizacao
	initialize_screen_updating(get_config_int("Inicializacao", "updatemethod", UPDATE_TRIPLE_BUFFER));

    set_window_title("Snake Criado por Arthur Assuncao"); //nome da Janela

    set_display_switch_mode(SWITCH_BACKGROUND); //roda o allegro em segundo plano

    //Botao fechar
    LOCK_FUNCTION(BotaoFechar);
    set_close_button_callback(BotaoFechar);

	//Contador de frames
	// Faz o lock das variaveis usadas pela funcao de timer e da propria funcao
    LOCK_VARIABLE(fps);
    LOCK_VARIABLE(contFrames);
    LOCK_FUNCTION(funcFPS);
	//chama a funcao funcFPS
	install_int_ex(funcFPS,BPS_TO_TIMER(MAXFPS)); //Frames por segundo, 60FPS
	//chama a funcao funcTempo
	LOCK_VARIABLE(contTempo);
    LOCK_FUNCTION(funcTempo);
	install_int(funcTempo, 1000); //Timer "ticks" a cada mil milisegundos, ou seja, 1 segundo

	/* adicione outras iniciacoes aqui */
}
示例#14
0
/*
 * call-seq:
 *   set_display_switch_mode(mode) -> int
 *
 * Sets how the program should handle being switched into the background, if the
 * user tabs away from it. Not all of the possible modes will be supported by
 * every graphics driver on every platform. The available modes are:
 * SWITCH_NONE::
 *   Disables switching. This is the default in single-tasking systems like DOS.
 *   It may be supported on other platforms, but you should use it with caution,
 *   because your users won't be impressed if they want to switch away from your
 *   program, but you don't let them!
 * SWITCH_PAUSE::
 *   Pauses the program whenever it is in the background. Execution will be
 *   resumed as soon as the user switches back to it. This is the default in
 *   most fullscreen multitasking environments, for example the Linux console,
 *   but not under Windows.
 * SWITCH_AMNESIA::
 *   Like SWITCH_PAUSE, but this mode doesn't bother to remember the contents of
 *   video memory, so the screen, and any video bitmaps that you have created,
 *   will be erased after the user switches away and then back to your program.
 *   This is not a terribly useful mode to have, but it is the default for the
 *   fullscreen drivers under Windows because DirectDraw is too dumb to
 *   implement anything better.
 * SWITCH_BACKGROUND::
 *   The program will carry on running in the background, with the screen bitmap
 *   temporarily being pointed at a memory buffer for the fullscreen drivers.
 *   You must take special care when using this mode, because bad things will
 *   happen if the screen bitmap gets changed around when your program isn't
 *   expecting it (see below).
 * SWITCH_BACKAMNESIA::
 *   Like SWITCH_BACKGROUND, but this mode doesn't bother to remember the
 *   contents of video memory (see SWITCH_AMNESIA). It is again the only mode
 *   supported by the fullscreen drivers under Windows that lets the program
 *   keep running in the background.
 *
 * Note that you should be very careful when you are using graphics routines in
 * the switching context: you must always call acquire_screen before the start
 * of any drawing code onto the screen and not release it until you are
 * completely finished, because the automatic locking mechanism may not be good
 * enough to work when the program runs in the background or has just been
 * raised in the foreground.
 *
 * Return value: Returns zero on success, invalidating at the same time all
 * callbacks previously registered with set_display_switch_callback. Returns -1
 * if the requested mode is not currently possible. 
 */
VALUE a4r_API_set_display_switch_mode(VALUE self, VALUE mode)
{
  return INT2FIX(set_display_switch_mode(FIX2INT(mode)));
}
示例#15
0
int main(int argc, const char *const *argv) /* I'm const-crazy! */
{
	DUH *duh;          /* Encapsulates the music file. */
	AL_DUH_PLAYER *dp; /* Holds the current playback state. */

	/* Initialise Allegro */
	if (allegro_init())
		return EXIT_FAILURE;

	/* Check that we have one argument (plus the executable name). */
	if (argc != 2)
		usage(argv[0]);

	/* Tell Allegro where to find configuration data. This means you can
	 * put any settings for Allegro in dumb.ini. See Allegro's
	 * documentation for more information.
	 */
	set_config_file("dumb.ini");

	/* Initialise Allegro's keyboard input. */
	if (install_keyboard()) {
		allegro_message("Failed to initialise keyboard driver!\n");
		return EXIT_FAILURE;
	}

	/* This function call is appropriate for a program that will play one
	 * sample or one audio stream at a time. If you have sound effects
	 * too, you may want to increase the parameter. See Allegro's
	 * documentation for details on what the parameter means. Note that
	 * newer versions of Allegro act as if set_volume_per_voice() was
	 * called with parameter 1 initially, while older versions behave as
	 * if -1 was passed, so you should call the function if you want
	 * consistent behaviour.
	 */
	set_volume_per_voice(0);

	/* Initialise Allegro's sound output system. */
	if (install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL)) {
		allegro_message("Failed to initialise sound driver!\n%s\n", allegro_error);
		return EXIT_FAILURE;
	}

	/* dumb_exit() is a function defined by DUMB. This operation arranges
	 * for dumb_exit() to be called last thing before the program exits.
	 * dumb_exit() does a bit of cleaning up for you. atexit() is
	 * declared in stdlib.h.
	 */
	atexit(&dumb_exit);

	/* DUMB defines its own wrappers for file input. There is a struct
	 * called DUMBFILE that holds function pointers for the various file
	 * operations needed by DUMB. You can decide whether to use stdio
	 * FILE objects, Allegro's PACKFILEs or something else entirely. No
	 * wrapper is installed initially, so you must call this or
	 * dumb_register_stdfiles() or set up your own before trying to load
	 * modules by file name. (If you are using another method, such as
	 * loading an Allegro datafile with modules embedded in it, then DUMB
	 * never opens a file by file name so this doesn't apply.)
	 */
	dumb_register_packfiles();

	/* Load the module file into a DUH object. Quick and dirty: try the
	 * loader for each format until one succeeds. Note that 15-sample
	 * mods have no identifying features, so dumb_load_mod() may succeed
	 * on files that aren't mods at all. We therefore try that one last.
	 */
	duh = dumb_load_it(argv[1]);
	if (!duh) {
		duh = dumb_load_xm(argv[1]);
		if (!duh) {
			duh = dumb_load_s3m(argv[1]);
			if (!duh) {
				duh = dumb_load_mod(argv[1]);
				if (!duh) {
					allegro_message("Failed to load %s!\n", argv[1]);
					return EXIT_FAILURE;
				}
			}
		}
	}

	/* Read the quality values from the config file we told Allegro to
	 * use. You may want to hardcode these or provide a more elaborate
	 * interface via which the user can control them.
	 */
	dumb_resampling_quality = get_config_int("sound", "dumb_resampling_quality", 4);
	dumb_it_max_to_mix = get_config_int("sound", "dumb_it_max_to_mix", 128);

	/* If we're not in DOS, show a window and register our close hook
	 * function.
	 */
#	ifndef ALLEGRO_DOS
		{
			const char *fn = get_filename(argv[1]);
			gfx_half_width = strlen(fn);
			if (gfx_half_width < 22) gfx_half_width = 22;
			gfx_half_width = (gfx_half_width + 2) * 4;

			/* set_window_title() is not const-correct (yet). */
			set_window_title((char *)"DUMB Music Player");

			if (set_gfx_mode(GFX_DUMB_MODE, gfx_half_width*2, 80, 0, 0) == 0) {
				acquire_screen();
				textout_centre(screen, font, fn, gfx_half_width, 20, 14);
				textout_centre(screen, font, "Press any key to exit.", gfx_half_width, 52, 11);
				release_screen();
			} else
				gfx_half_width = 0;
		}

		/* Silly check to get around the fact that someone stupidly removed
		 * an old function from Allegro instead of deprecating it. The old
		 * function was put back a version later, but we may as well use the
		 * new one if it's there!
		 */
#		if ALLEGRO_VERSION*10000 + ALLEGRO_SUB_VERSION*100 + ALLEGRO_WIP_VERSION >= 40105
			set_close_button_callback(&closehook);
#		else
			set_window_close_hook(&closehook);
#		endif

#	endif

	/* We want to continue running if the user switches to another
	 * application.
	 */
	set_display_switch_mode(SWITCH_BACKGROUND);

	/* We have the music loaded, but it isn't playing yet. This starts it
	 * playing. We construct a second object, the AL_DUH_PLAYER, to
	 * represent the playing music. This means you can play the music
	 * twice at the same time should you want to!
	 *
	 * Specify the number of channels (2 for stereo), which 'signal' to
	 * play (always 0 for modules), the volume (1.0f for default), the
	 * buffer size (4096 generally works well) and the sampling frequency
	 * (ideally match the final output frequency Allegro is using). An
	 * Allegro audio stream will be started.
	 */
	dp = al_start_duh(duh, 2, 0, 1.0f,
		get_config_int("sound", "buffer_size", 4096),
		get_config_int("sound", "sound_freq", 44100));

	/* Register our callback functions so that they are called when the
	 * music loops or stops. See docs/howto.txt for more information.
	 * There is no threading issue: DUMB will only process playback
	 * in al_poll_duh(), which we call below.
	 */
	{
		DUH_SIGRENDERER *sr = al_duh_get_sigrenderer(dp);
		DUMB_IT_SIGRENDERER *itsr = duh_get_it_sigrenderer(sr);
		dumb_it_set_loop_callback(itsr, &loop_callback, NULL);
		dumb_it_set_xm_speed_zero_callback(itsr, &xm_speed_zero_callback, NULL);
	}

	/* Main loop. */
	for (;;) {
		/* Check for keys in the buffer. If we get one, discard it
		 * and exit the main loop.
		 */
		if (keypressed()) {
			readkey();
			break;
		}

		/* Poll the music. We exit the loop if al_poll_duh() has
		 * returned nonzero (music finished) or the window has been
		 * closed. al_poll_duh() might return nonzero if you have set
		 * up a callback that tells the music to stop.
		 */
		if (al_poll_duh(dp) || closed)
			break;

		/* Give other threads a look-in, or allow the processor to
		 * sleep for a bit. YIELD() is defined further up in this
		 * file.
		 */
		YIELD();
	}

	/* Remove the audio stream and deallocate the memory being used for
	 * the playback state. We set dp to NULL to emphasise that the object
	 * has gone.
	 */
	al_stop_duh(dp);
	dp = NULL;

	/* Free the DUH object containing the actual music data. */
	unload_duh(duh);
	duh = NULL;

	/* All done! */
	return EXIT_SUCCESS;
}
示例#16
0
/***
  Function : install()
  Returns  : TRUE on succes, FALSE on failure
  Purpose  : Will install game variables, sets up the entire game.
***/
bool install()
{
    // Each time we run the game, we clear out the logbook
    FILE *fp;
    fp = fopen("log.txt", "wt");

    if (fp)
    {
        fprintf(fp, "Counter-Strike 2D Logbook\n");
        fprintf(fp, "-------------------------\n\n"); // print head of logbook
        fclose(fp);
    }

    logbook("--------------");
    logbook("Initialization");
    logbook("--------------");

    // init game
    map.init();
    game.init();
    steam.init();

    logbook("Creating entity types.");
    game.install_entities();

    // Logbook notification
    logbook("\n-------");
    logbook("Allegro");
    logbook("-------");


    // ALLEGRO - INIT
    if (allegro_init() != 0)
        return false;

    logbook(allegro_id);
    yield_timeslice();
    logbook("yield_timeslice()");

    int r = install_timer();
    if (r > -1) logbook("install_timer()");
    else
    {
        logbook("FAILED");
        return false;
    }

    alfont_init();
    logbook("alfont_init()");
    install_keyboard();
    logbook("install_keyboard()");
    install_mouse();
    logbook("install_mouse()");

    logbook("setting up timer functions / locking functions & memory");
    /* set up the interrupt routines... */
    LOCK_VARIABLE(RUNNING_TIMER_tenth);
    LOCK_VARIABLE(RUNNING_TIMER_fps);
    LOCK_FUNCTION(timer_tenth);
    LOCK_FUNCTION(fps_proc);

    install_int(timer_tenth, 10);
    install_int(fps_proc, 1000);

    logbook("Timers installed");

    frame_count = fps = 0;


    // set window title
    char title[80];
    sprintf(title, "Counter-Strike 2D");

    // Set window title
    set_window_title(title);
    char window_title[256];
    sprintf(window_title, "Window title set: [%s]", title);
    logbook(window_title);

    set_color_depth(16);      // run in 16 bit mode
    if (game.windowed)
    {
        int r = set_gfx_mode(GFX_AUTODETECT_WINDOWED, game.screen_x, game.screen_y, game.screen_x, game.screen_y);
        if (r > -1)
        {
            // Succes
        }
        else
        {
            // GFX_DIRECTX_ACCEL / GFX_AUTODETECT
            r = set_gfx_mode(GFX_DIRECTX_ACCEL, game.screen_x, game.screen_y, game.screen_x, game.screen_y);
            if (r > -1)
            {
                game.windowed = false;
                logbook("Could not enter windowed-mode; settings.d3 adjusted");
            }
            else
            {
                logbook("ERROR - !");
                return false;
            }
        }
    }
    else
    {
        int r = set_gfx_mode(GFX_AUTODETECT, game.screen_x, game.screen_y, game.screen_x, game.screen_y);

        // succes
        if (r > -1)
        {

        }
        else
        {
            logbook("ERROR - !!");
            return false;
        }

    }


    text_mode(0);

    logbook("Loading font data");
    // loading font

    game_font = alfont_load_font("gfx\\font\\tahoma.ttf");

    if (game_font != NULL)
    {
        alfont_set_font_size(game_font, 20); // set size
    }
    else
        allegro_message("Error loading tahoma.ttf!");

    // CS Font
    cs_font = alfont_load_font("gfx\\font\\cs.ttf");

    if (cs_font != NULL)
    {
        alfont_set_font_size(cs_font, 20); // set size
    }
    else
        allegro_message("Error loading cs.ttf");

    alfont_text_mode(-1);

    if (set_display_switch_mode(SWITCH_BACKGROUND) < 0)
    {
        set_display_switch_mode(SWITCH_PAUSE);
        logbook("Display 'switch and pause' mode set");
    }
    else
        logbook("Display 'switch to background' mode set");

    // sound
    logbook("Initializing sound");
    int s = install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL);

    /***
     Bitmap Creation
     ***/

    bmp_screen = create_bitmap(game.screen_x, game.screen_y);

    if (bmp_screen == NULL)
    {
        logbook("ERROR: Could not create bitmap: bmp_screen");
        return false;
    }
    else
        logbook("Bitmap created: bmp_screen");

    bmp_collide = create_bitmap(game.screen_x, game.screen_y);

    if (bmp_collide == NULL)
    {
        logbook("ERROR: Could not create bitmap: bmp_collide");
        return false;
    }
    else
        logbook("Bitmap created: bmp_collide");

    /*** End of Bitmap Creation ***/

    // load datafiles
    graphics = load_datafile("graphics.dat");
    if (graphics == NULL)
    {
        logbook("ERROR: Could not load datafile: graphics.dat");
        return false;
    }
    else
        logbook("Datafile loaded: graphics.dat");

    // Shadows
    shadows = load_datafile("shadows.dat");
    if (shadows == NULL)
    {
        logbook("ERROR: Could not load datafile: shadows.dat");
        return false;
    }
    else
        logbook("Datafile loaded: shadows.dat");

    // HUD
    hud = load_datafile("hud.dat");
    if (hud == NULL)
    {
        logbook("ERROR: Could not load datafile: hud.dat");
        return false;
    }
    else
        logbook("Datafile loaded: hud.dat");

    //set_color_conversion(COLORCONV_NONE);
    set_color_conversion(COLORCONV_MOST);
    logbook("Color conversion method set");

    // setup mouse speed
    set_mouse_speed(2,2);

    logbook("Mouse speed set");

    logbook("");
    logbook("----");
    logbook("GAME ");
    logbook("----");

    game.LOAD_TexturesFromDataFile("data//de_aztec.dat");
//  DATA_Init();

    // randomize timer
    srand( (unsigned)time( NULL ) );

    //srand(time(NULL));

    // normal sounds are loud, the music is lower (its background music, so it should not be disturbing)
    set_volume(255, 200);

    set_trans_blender(128, 128, 128, 128);

    logbook("");
    logbook("--------------");
    logbook("BATTLE CONTROL");
    logbook("--------------");
    logbook("\n3...2...1... GO!\n");
    return true;
}
示例#17
0
/* _xdga2_gfxdrv_init_drv:
 *  Initializes driver and creates screen bitmap.
 */
static BITMAP *_xdga2_private_gfxdrv_init_drv(GFX_DRIVER *drv, int w, int h, int vw, int vh, int depth, int accel)
{
   int dga_error_base, dga_major_version, dga_minor_version;
   int mode, mask, red_shift = 0, green_shift = 0, blue_shift = 0;
   long input_mask;
   char tmp1[128], tmp2[128];
   BITMAP *bmp;

   /* This is just to test if the system driver has been installed properly */
   if (_xwin.window == None)
      return NULL;

   /* Test that display is local.  */
   if (!_xdga2_private_display_is_local()) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("This driver needs local display"));
      return NULL;
   }

   /* Choose convenient size.  */
   if ((w == 0) && (h == 0)) {
      w = 640;
      h = 480;
   }

   if ((w < 80) || (h < 80) || (w > 4096) || (h > 4096)) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Unsupported screen size"));
      return NULL;
   }

   if (vw < w)
      vw = w;
   if (vh < h)
      vh = h;

   if (1
#ifdef ALLEGRO_COLOR8
       && (depth != 8)
#endif
#ifdef ALLEGRO_COLOR16
       && (depth != 15)
       && (depth != 16)
#endif
#ifdef ALLEGRO_COLOR24
       && (depth != 24)
#endif
#ifdef ALLEGRO_COLOR32
       && (depth != 32)
#endif
       ) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Unsupported color depth"));
      return NULL;
   }

   /* Checks presence of DGA extension */
   if (!XDGAQueryExtension(_xwin.display, &dga_event_base, &dga_error_base) ||
       !XDGAQueryVersion(_xwin.display, &dga_major_version, &dga_minor_version)) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("DGA extension is not supported"));
      return NULL;
   }

   /* Works only with DGA 2.0 or newer */
   if (dga_major_version < 2) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("DGA 2.0 or newer is required"));
      return NULL;
   }

   /* Attempts to access the framebuffer */
   if (!XDGAOpenFramebuffer(_xwin.display, _xwin.screen)) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Can not open framebuffer"));
      return NULL;
   }

   /* Finds suitable video mode number */
   mode = _xdga2_find_mode(w, h, vw, vh, depth);
   if (!mode) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Resolution not supported"));
      return NULL;
   }

   /* Sets DGA video mode */
   dga_device = XDGASetMode(_xwin.display, _xwin.screen, mode);
   if (dga_device == NULL) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Can not switch to DGA mode"));
      return NULL;
   }
   _xwin.in_dga_mode = 2;
   _set_current_refresh_rate(dga_device->mode.verticalRefresh);
   set_display_switch_mode(SWITCH_NONE);

   /* Installs DGA color map */
   if (_dga_cmap) {
      XFreeColormap(_xwin.display, _dga_cmap);
      _dga_cmap = 0;
   }
   if ((dga_device->mode.visualClass == PseudoColor)
       || (dga_device->mode.visualClass == GrayScale)
       || (dga_device->mode.visualClass == DirectColor))
      _dga_cmap = XDGACreateColormap(_xwin.display, _xwin.screen, dga_device, AllocAll);
   else
      _dga_cmap = XDGACreateColormap(_xwin.display, _xwin.screen, dga_device, AllocNone);
   XDGAInstallColormap(_xwin.display, _xwin.screen, _dga_cmap);

   /* Sets up direct color shifts */
   if (depth != 8) {
      for (mask = dga_device->mode.redMask, red_shift = 0; (mask & 1) == 0;
         mask >>= 1, red_shift++);
      for (mask = dga_device->mode.greenMask, green_shift = 0; (mask & 1) == 0;
         mask >>= 1, green_shift++);
      for (mask = dga_device->mode.blueMask, blue_shift = 0; (mask & 1) == 0;
         mask >>= 1, blue_shift++);
   }
   switch (depth) {

      case 15:
         _rgb_r_shift_15 = red_shift;
         _rgb_g_shift_15 = green_shift;
         _rgb_b_shift_15 = blue_shift;
         break;

      case 16:
         _rgb_r_shift_16 = red_shift;
         _rgb_g_shift_16 = green_shift;
         _rgb_b_shift_16 = blue_shift;
         break;

      case 24:
         _rgb_r_shift_24 = red_shift;
         _rgb_g_shift_24 = green_shift;
         _rgb_b_shift_24 = blue_shift;
         break;

      case 32:
         _rgb_r_shift_32 = red_shift;
         _rgb_g_shift_32 = green_shift;
         _rgb_b_shift_32 = blue_shift;
         break;
   }

   /* Enables input */
   XSync(_xwin.display, True);
   input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask
              | ButtonReleaseMask | PointerMotionMask;
   XDGASelectInput(_xwin.display, _xwin.screen, input_mask);
   if (_xwin_keyboard_focused) {
      (*_xwin_keyboard_focused)(FALSE, 0);
      keyboard_got_focus = TRUE;
   }
   _mouse_on = TRUE;

   /* Creates screen bitmap */
   drv->linear = TRUE;
   bmp = _make_bitmap(dga_device->mode.imageWidth, dga_device->mode.imageHeight,
         (uintptr_t)dga_device->data, drv, depth,
         dga_device->mode.bytesPerScanline);
   if (!bmp) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Not enough memory"));
      return NULL;
   }
   drv->w = bmp->cr = w;
   drv->h = bmp->cb = h;
   drv->vid_mem = dga_device->mode.imageWidth * dga_device->mode.imageHeight
                * BYTES_PER_PIXEL(depth);

   if (accel) {
      /* Hardware acceleration has been requested */
      
      /* Updates line switcher to accommodate framebuffer synchronization */
#ifdef ALLEGRO_NO_ASM
      bmp->write_bank = _xdga2_write_line;
      bmp->read_bank = _xdga2_write_line;
#else
      bmp->write_bank = _xdga2_write_line_asm;
      bmp->read_bank = _xdga2_write_line_asm;
#endif

      _screen_vtable.acquire = _xdga2_acquire;

      /* Checks for hardware acceleration support */
      if (dga_device->mode.flags & XDGASolidFillRect) {
         /* XDGAFillRectangle is available */
         _orig_hline = _screen_vtable.hline;
         _orig_vline = _screen_vtable.vline;
         _orig_rectfill = _screen_vtable.rectfill;
         _screen_vtable.hline = _xaccel_hline;
         _screen_vtable.vline = _xaccel_vline;
         _screen_vtable.rectfill = _xaccel_rectfill;
         _screen_vtable.clear_to_color = _xaccel_clear_to_color;
         gfx_capabilities |= (GFX_HW_HLINE | GFX_HW_FILL);
      }
      if (dga_device->mode.flags & XDGABlitRect) {
         /* XDGACopyArea is available */
         _screen_vtable.blit_to_self = _xaccel_blit_to_self;
         _screen_vtable.blit_to_self_forward = _xaccel_blit_to_self;
         _screen_vtable.blit_to_self_backward = _xaccel_blit_to_self;
         gfx_capabilities |= GFX_HW_VRAM_BLIT;
      }
      if (dga_device->mode.flags & XDGABlitTransRect) {
         /* XDGACopyTransparentArea is available */
         _orig_draw_sprite = _screen_vtable.draw_sprite;
         _orig_masked_blit = _screen_vtable.masked_blit;
         _screen_vtable.masked_blit = _xaccel_masked_blit;
         _screen_vtable.draw_sprite = _xaccel_draw_sprite;
         if (_screen_vtable.color_depth == 8)
            _screen_vtable.draw_256_sprite = _xaccel_draw_sprite;
         gfx_capabilities |= GFX_HW_VRAM_BLIT_MASKED;
      }

      RESYNC();
   }

   /* Checks for triple buffering */
   if (dga_device->mode.viewportFlags & XDGAFlipRetrace)
      gfx_capabilities |= GFX_CAN_TRIPLE_BUFFER;

   /* Sets up driver description */
   uszprintf(_xdga2_driver_desc, sizeof(_xdga2_driver_desc),
             uconvert_ascii("X-Windows DGA 2.0 graphics%s", tmp1),
             uconvert_ascii(accel ? (gfx_capabilities ? " (accelerated)" : "") : " (software only)", tmp2));
   drv->desc = _xdga2_driver_desc;

   return bmp;
}
示例#18
0
文件: main.c 项目: hoglet67/b-em
void main_init(int argc, char *argv[])
{
        char t[512], *p;
        int c;
        int tapenext = 0, discnext = 0;

        startblit();

        log_open();
        log_info("main: starting %s", VERSION_STR);

        vid_fskipmax = 1;

        al_init_main(argc, argv);

        append_filename(t, exedir, "roms/tube/ReCo6502ROM_816", 511);
        if (!file_exists(t,FA_ALL,NULL) && selecttube == 4) selecttube = -1;

        curtube = selecttube;
        model_check();

        for (c = 1; c < argc; c++)
        {
//                log_debug("%i : %s",c,argv[c]);
/*                if (!strcasecmp(argv[c],"-1770"))
                {
                        I8271=0;
                        WD1770=1;
                }
                else*/
//#ifndef WIN32
                if (!strcasecmp(argv[c], "--help"))
                {
                        printf("%s command line options :\n\n", VERSION_STR);
                        printf("-mx             - start as model x (see readme.txt for models)\n");
                        printf("-tx             - start with tube x (see readme.txt for tubes)\n");
                        printf("-disc disc.ssd  - load disc.ssd into drives :0/:2\n");
                        printf("-disc1 disc.ssd - load disc.ssd into drives :1/:3\n");
                        printf("-autoboot       - boot disc in drive :0\n");
                        printf("-tape tape.uef  - load tape.uef\n");
                        printf("-fasttape       - set tape speed to fast\n");
                        printf("-s              - scanlines display mode\n");
                        printf("-i              - interlace display mode\n");
                        printf("-debug          - start debugger\n");
                        printf("-allegro        - use Allegro for video rendering\n");
                        exit(-1);
                }
                else
//#endif
                if (!strcasecmp(argv[c], "-tape"))
                {
                        tapenext = 2;
                }
                else if (!strcasecmp(argv[c], "-disc") || !strcasecmp(argv[c], "-disk"))
                {
                        discnext = 1;
                }
                else if (!strcasecmp(argv[c], "-disc1"))
                {
                        discnext = 2;
                }
                else if (argv[c][0] == '-' && (argv[c][1] == 'm' || argv[c][1] == 'M'))
                {
                        sscanf(&argv[c][2], "%i", &curmodel);
                }
                else if (argv[c][0] == '-' && (argv[c][1] == 't' || argv[c][1] == 'T'))
                {
                        sscanf(&argv[c][2], "%i", &curtube);
                }
                else if (!strcasecmp(argv[c], "-fasttape"))
                {
                        fasttape = 1;
                }
                else if (!strcasecmp(argv[c], "-autoboot"))
                {
                        autoboot = 150;
                }
                else if (argv[c][0] == '-' && (argv[c][1] == 'f' || argv[c][1]=='F'))
                {
                        sscanf(&argv[c][2], "%i", &vid_fskipmax);
            if (vid_fskipmax < 1) vid_fskipmax = 1;
            if (vid_fskipmax > 9) vid_fskipmax = 9;
                }
                else if (argv[c][0] == '-' && (argv[c][1] == 's' || argv[c][1] == 'S'))
                {
                        vid_scanlines = 1;
                }
                else if (!strcasecmp(argv[c], "-debug"))
                {
                        debug_core = 1;
                }
                else if (!strcasecmp(argv[c], "-debugtube"))
                {
                        debug_tube = 1;
                }
                else if (argv[c][0] == '-' && (argv[c][1] == 'i' || argv[c][1] == 'I'))
                {
                        vid_interlace = 1;
            vid_linedbl = vid_scanlines = 0;
                }
                else if (tapenext)
                   strcpy(tape_fn, argv[c]);
                else if (discnext)
                {
                        strcpy(discfns[discnext-1], argv[c]);
                        discnext = 0;
                }
                else
                {
                    if ((p = strrchr(argv[c], '.')) && (!strcasecmp(p, ".uef") || !strcasecmp(p, ".csw"))) {
                        strncpy(tape_fn, argv[c], sizeof tape_fn);
                        tapenext = 0;
                    }
                    else {
                        strncpy(discfns[0], argv[c], sizeof discfns[0]);
                        discnext = 0;
                        autoboot = 150;
                    }
                }
                if (tapenext) tapenext--;
        }

        video_init();
        mode7_makechars();

#ifndef WIN32
        install_keyboard();
#endif
        install_timer();

        mem_init();
        ddnoise_init();
        tapenoise_init();

        sound_init();
        al_init();
        sid_init();
        sid_settype(sidmethod, cursid);
        music5000_init();

    adc_init();
#ifdef WIN32
        pal_init();
#endif
        disc_init();
        fdi_init();

        scsi_init();
        ide_init();
        vdfs_init();

        model_init();

        midi_init();
        main_reset();

        install_int_ex(secint, MSEC_TO_TIMER(1000));
        install_int_ex(int50,  MSEC_TO_TIMER(20));

        set_display_switch_mode(SWITCH_BACKGROUND);
#ifdef WIN32
                timeBeginPeriod(1);
#endif
        oldmodel = curmodel;

        if (curtube == 3 || mouse_amx) install_mouse();

        disc_load(0, discfns[0]);
        disc_load(1, discfns[1]);
        tape_load(tape_fn);
        if (defaultwriteprot) writeprot[0] = writeprot[1] = 1;

        endblit();

        debug_start();
}
示例#19
0
/* be_gfx_bwindow_init:
 *  Initializes specified video mode.
 */
extern "C" struct BITMAP *be_gfx_bwindow_init(int w, int h, int v_w, int v_h, int color_depth)
{
   BITMAP *bmp;
   
   if (1
#ifdef ALLEGRO_COLOR8
       && (color_depth != 8)
#endif
#ifdef ALLEGRO_COLOR16
       && (color_depth != 15)
       && (color_depth != 16)
#endif
#ifdef ALLEGRO_COLOR32
       && (color_depth != 32)
#endif
       ) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Unsupported color depth"));
      return NULL;
   }

   if ((!v_w) && (!v_h)) {
      v_w = w;
      v_h = h;
   }

   if ((w != v_w) || (h != v_h)) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Unsupported virtual resolution"));
      return NULL;
   }
   
   set_display_switch_mode(SWITCH_PAUSE);

   _be_allegro_window = new BeAllegroWindow(BRect(0, 0, w-1, h-1), wnd_title,
			      B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
			      B_NOT_RESIZABLE | B_NOT_ZOOMABLE,
			      B_CURRENT_WORKSPACE, v_w, v_h, color_depth);
   _be_window = _be_allegro_window;
   if (!_be_allegro_window->buffer->IsValid() ||
       ((color_depth == 8) && (!_be_allegro_window->aux_buffer->IsValid()))) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Not enough memory"));
      goto cleanup;
   }
   
   _be_mouse_view = new BView(_be_allegro_window->Bounds(),
			     "allegro mouse view", B_FOLLOW_ALL_SIDES, 0);
   _be_allegro_window->Lock();
   _be_allegro_window->AddChild(_be_mouse_view);
   _be_allegro_window->Unlock();

   _be_mouse_window = _be_allegro_window;
   _be_mouse_window_mode = true;

   release_sem(_be_mouse_view_attached);
   
   _be_allegro_window->MoveTo(6, 25);
   _be_allegro_window->Show();

   gfx_beos_bwindow.w       = w;
   gfx_beos_bwindow.h       = h;
   gfx_beos_bwindow.linear  = TRUE;
   gfx_beos_bwindow.vid_mem = _be_allegro_window->buffer->BitsLength();
   
   bmp = _make_bitmap(v_w, v_h, (unsigned long)_be_allegro_window->buffer->Bits(),
              &gfx_beos_bwindow, color_depth,
		      _be_allegro_window->buffer->BytesPerRow());
  
   if (!bmp) {
      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Not enough memory"));
      goto cleanup;
   }
   
#ifdef ALLEGRO_NO_ASM
   bmp->read_bank = (void *)_be_gfx_bwindow_read_write_bank;
   bmp->write_bank = (void *)_be_gfx_bwindow_read_write_bank;
   _screen_vtable.unwrite_bank = (void *)_be_gfx_bwindow_unwrite_bank;
#else
   bmp->read_bank = _be_gfx_bwindow_read_write_bank_asm;
   bmp->write_bank = _be_gfx_bwindow_read_write_bank_asm;
   _screen_vtable.unwrite_bank = _be_gfx_bwindow_unwrite_bank_asm;
#endif
   
   _screen_vtable.acquire = be_gfx_bwindow_acquire;
   _screen_vtable.release = be_gfx_bwindow_release;
   
   _be_gfx_set_truecolor_shifts();

   uszprintf(driver_desc, sizeof(driver_desc), get_config_text("BWindow object, %d bit BBitmap framebuffer"),
             color_depth);
   gfx_beos_bwindow.desc = driver_desc;
   
   snooze(50000);
   _be_gfx_initialized = true;
   
   return bmp;

cleanup:
   be_gfx_bwindow_exit(NULL);
   return NULL;
}
示例#20
0
文件: app.cpp 项目: optigon/aseprite
int App::run()
{
#ifdef ENABLE_UPDATER
  app::CheckUpdateThreadLauncher checkUpdate;
#endif

  // Initialize GUI interface
  if (isGui()) {
    View* view;
    Editor* editor;

    PRINTF("GUI mode\n");

    // Setup the GUI screen
    jmouse_set_cursor(JI_CURSOR_NORMAL);
    gui::Manager::getDefault()->invalidate();

    // Load main window
    top_window = static_cast<Frame*>(load_widget("main_window.xml", "main_window"));

    box_menubar = top_window->findChild("menubar");
    box_editors = top_window->findChild("editor");
    box_colorbar = top_window->findChild("colorbar");
    box_toolbar = top_window->findChild("toolbar");
    box_statusbar = top_window->findChild("statusbar");
    box_tabsbar = top_window->findChild("tabsbar");

    menubar = new MenuBar();
    statusbar = new StatusBar();
    colorbar = new ColorBar(box_colorbar->getAlign());
    toolbar = toolbar_new();
    tabsbar = new Tabs(m_tabsDelegate = new AppTabsDelegate());
    view = new EditorView(EditorView::CurrentEditorMode);
    editor = create_new_editor();

    // configure all widgets to expansives
    menubar->setExpansive(true);
    statusbar->setExpansive(true);
    colorbar->setExpansive(true);
    toolbar->setExpansive(true);
    tabsbar->setExpansive(true);
    view->setExpansive(true);

    /* prepare the first editor */
    view->attachToView(editor);

    /* setup the menus */
    menubar->setMenu(get_root_menu());

    /* start text of status bar */
    app_default_statusbar_message();

    /* add the widgets in the boxes */
    if (box_menubar) box_menubar->addChild(menubar);
    if (box_editors) box_editors->addChild(view);
    if (box_colorbar) box_colorbar->addChild(colorbar);
    if (box_toolbar) box_toolbar->addChild(toolbar);
    if (box_statusbar) box_statusbar->addChild(statusbar);
    if (box_tabsbar) box_tabsbar->addChild(tabsbar);

    /* prepare the window */
    top_window->remap_window();

    // Create the list of tabs
    app_rebuild_documents_tabs();
    app_rebuild_recent_list();

    // Set current editor
    set_current_editor(editor);

    // Open the window
    top_window->open_window();

    // Redraw the whole screen.
    gui::Manager::getDefault()->invalidate();
  }

  /* set background mode for non-GUI modes */
/*   if (!(ase_mode & MODE_GUI)) */
/*     set_display_switch_mode(SWITCH_BACKAMNESIA); */
    set_display_switch_mode(SWITCH_BACKGROUND);

    // procress options
  PRINTF("Processing options...\n");

  ASSERT(m_checkArgs != NULL);
  {
    Console console;
    for (CheckArgs::iterator
           it  = m_checkArgs->begin();
         it != m_checkArgs->end(); ++it) {
      CheckArgs::Option* option = *it;

      switch (option->type()) {

        case CheckArgs::Option::OpenSprite: {
          // Load the sprite
          Document* document = load_document(option->data().c_str());
          if (!document) {
            if (!isGui())
              console.printf("Error loading file \"%s\"\n", option->data().c_str());
          }
          else {
            // Mount and select the sprite
            UIContext* context = UIContext::instance();
            context->addDocument(document);
            context->setActiveDocument(document);

            if (isGui()) {
              // Show it
              set_document_in_more_reliable_editor(context->getFirstDocument());

              // Recent file
              getRecentFiles()->addRecentFile(option->data().c_str());
            }
          }
          break;
        }
      }
    }
    delete m_checkArgs;
    m_checkArgs = NULL;
  }

  // Run the GUI
  if (isGui()) {
    // Support to drop files from Windows explorer
    install_drop_files();

#ifdef ENABLE_UPDATER
    // Launch the thread to check for updates.
    checkUpdate.launch();
#endif

    // Run the GUI main message loop
    gui_run();

    // Uninstall support to drop files
    uninstall_drop_files();

    // Remove the root-menu from the menu-bar (because the rootmenu
    // module should destroy it).
    menubar->setMenu(NULL);

    // Delete all editors first because they used signals from other
    // widgets (e.g. color bar).
    delete box_editors;

    // Destroy mini-editor.
    exit_module_editors();

    // Destroy the top-window
    delete top_window;
    top_window = NULL;
  }

  return 0;
}
示例#21
0
/* _xwin_sysdrv_init:
 *  Top level system driver wakeup call.
 */
static int _xwin_sysdrv_init(void)
{
   char tmp[256];

   _unix_read_os_type();

   /* install emergency-exit signal handlers */
   old_sig_abrt = signal(SIGABRT, _xwin_signal_handler);
   old_sig_fpe  = signal(SIGFPE,  _xwin_signal_handler);
   old_sig_ill  = signal(SIGILL,  _xwin_signal_handler);
   old_sig_segv = signal(SIGSEGV, _xwin_signal_handler);
   old_sig_term = signal(SIGTERM, _xwin_signal_handler);
   old_sig_int  = signal(SIGINT,  _xwin_signal_handler);

#ifdef SIGQUIT
   old_sig_quit = signal(SIGQUIT, _xwin_signal_handler);
#endif

   /* Initialise dynamic driver lists and load modules */
   _unix_driver_lists_init();
   if (_unix_gfx_driver_list)
      _driver_list_append_list(&_unix_gfx_driver_list, _xwin_gfx_driver_list);
   _unix_load_modules(SYSTEM_XWINDOWS);

#ifdef ALLEGRO_HAVE_LIBPTHREAD
   _unix_bg_man = &_bg_man_pthreads;
#else
   _unix_bg_man = &_bg_man_sigalrm;
#endif

   /* Initialise bg_man */
   if (_unix_bg_man->init()) {
      _xwin_sysdrv_exit();
      return -1;
   }

#ifdef ALLEGRO_MULTITHREADED
   if (_unix_bg_man->multi_threaded) {
      _xwin.mutex = _unix_create_mutex();
   }
#endif

   get_executable_name(tmp, sizeof(tmp));
   set_window_title(get_filename(tmp));

   if (get_config_int("system", "XInitThreads", 1))
      XInitThreads();

   /* Open the display, create a window, and background-process
    * events for it all. */
   if (_xwin_open_display(0) || _xwin_create_window()
       || _unix_bg_man->register_func(_xwin_bg_handler))
   {
      _xwin_sysdrv_exit();
      return -1;
   }

   set_display_switch_mode(SWITCH_BACKGROUND);

   return 0;
}
示例#22
0
int main(int argc, char *argv[])
{
   MIDI *the_music;
   int length, pos;
   int beats, beat;
   int x, y, tw, th;
   int background_color;
   int text_color;
   int paused = 0;
   int done = 0;

   if (allegro_init() != 0)
      return 1;

   if (argc != 2) {
      allegro_message("Usage: 'exmidi filename.mid'\n");
      return 1;
   }

   install_keyboard(); 
   install_timer();

   /* install a MIDI sound driver */
   if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) {
      allegro_message("Error initialising sound system\n%s\n", allegro_error);
      return 1;
   }

   /* read in the MIDI file */
   the_music = load_midi(argv[1]);
   if (!the_music) {
      allegro_message("Error reading MIDI file '%s'\n", argv[1]);
      return 1;
   }
   length = get_midi_length(the_music);
   beats = -midi_pos; /* get_midi_length updates midi_pos to the negative
                         number of beats (quarter notes) in the midi. */

   if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) {
      if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
	 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
	 allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
	 return 1;
      }
   }
   
   /* try to continue in the background */
   if (set_display_switch_mode(SWITCH_BACKGROUND))
      set_display_switch_mode(SWITCH_BACKAMNESIA);

   set_palette(desktop_palette);
   background_color = makecol(255, 255, 255);
   text_color = makecol(0, 0, 0);
   clear_to_color(screen, background_color);
   th = text_height(font);
   x = SCREEN_W / 2;

   textprintf_centre_ex(screen, font, x, SCREEN_H / 3, text_color, -1,
			"Driver: %s", midi_driver->name);
   textprintf_centre_ex(screen, font, x, SCREEN_H / 2, text_color, -1,
			"Playing %s", get_filename(argv[1]));

   /* start up the MIDI file */
   play_midi(the_music, TRUE);

   y = 2 * SCREEN_H / 3;
   tw = text_length(font, "0000:00 / 0000:00");
   /* wait for a key press */
   while (!done) {
       /* P key pauses/resumes, any other key exits. */
      while (keypressed()) {
	 int k = readkey() & 255;
	 if (k == 'p') {
	    paused = !paused;
	    if (paused) {
	       midi_pause();
	       textprintf_centre_ex(screen, font, x, y + th * 3,
		  text_color, -1, "P A U S E D");
	    }
	    else {
	       midi_resume();
	       rectfill(screen, x - tw / 2, y + th * 3, x + tw / 2,
		  y + th * 4, background_color);
	    }
	 }
	 else
	    done = 1;
      }
      pos = midi_time;
      beat = midi_pos;
      rectfill(screen, x - tw / 2, y, x + tw / 2, y + th * 2, background_color);
      textprintf_centre_ex(screen, font, x, y, text_color, -1,
	 "%d:%02d / %d:%02d", pos / 60, pos % 60, length / 60, length % 60);
      textprintf_centre_ex(screen, font, x, y + th, text_color, -1,
	 "beat %d / %d", beat, beats);
      /* We have nothing else to do. */
      rest(100);
   }

   /* destroy the MIDI file */
   destroy_midi(the_music);

   return 0;
}