Example #1
0
void SkEvent::SignalQueueTimer(SkMSec delay)
{
    SDL_SetTimer(0, NULL);
    if (delay) {
        SDL_SetTimer(delay, timer_callback);
    }
}
Example #2
0
void archTimerDestroy(void* timer) 
{
    if (timerCb != timer) {
        return;
    }

    SDL_SetTimer(0, NULL);
    timerCb = NULL;
}
Example #3
0
void* archCreateTimer(int period, int (*timerCallback)(void*)) 
{ 
    timerFreq = 1000 / period;
    lastTimeout = archGetSystemUpTime(timerFreq);
    timerCb  = timerCallback;

    SDL_SetTimer(period, timerCalback);

    return timerCallback;
}
static void HandleAlarm(int sig)
{
	Uint32 ms;

	if ( SDL_alarm_callback ) {
		ms = (*SDL_alarm_callback)(SDL_alarm_interval);
		if ( ms != SDL_alarm_interval ) {
			SDL_SetTimer(ms, SDL_alarm_callback);
		}
	}
}
Example #5
0
void SDL_TimerQuit(void)
{
	SDL_SetTimer(0, NULL);
	if ( SDL_timer_threaded < 2 ) {
		SDL_SYS_TimerQuit();
	}
	if ( SDL_timer_threaded ) {
		SDL_DestroyMutex(SDL_timer_mutex);
	}
	SDL_timer_started = 0;
	SDL_timer_threaded = 0;
}
Example #6
0
/**
**	Initialise video sync.
*/
global void InitVideoSync(void)
{
    if( !VideoSyncSpeed ) {
	return;
    }

    if( SDL_SetTimer(
		(100*1000/FRAMES_PER_SECOND)/VideoSyncSpeed,
		VideoSyncHandler) ) {
	fprintf(stderr,"Can't set itimer\n");
    }

    // DebugLevel1("Timer installed\n");
}
Example #7
0
int SDL_TimerInit(void)
{
	int retval;

	SDL_timer_running = 0;
	SDL_SetTimer(0, NULL);
	retval = 0;
	if ( ! SDL_timer_threaded ) {
		retval = SDL_SYS_TimerInit();
	}
	if ( SDL_timer_threaded ) {
		SDL_timer_mutex = SDL_CreateMutex();
	}
	SDL_timer_started = 1;
	return(retval);
}
Example #8
0
int main( int argc, char *argv[] )
{
	SDL_Surface* screen;

	const SDL_version* sdlVersion = SDL_Linked_Version();
	if ( sdlVersion->minor < 2 )
	{
		printf( "SDL version must be at least 1.2.0" );
		exit( 254 );
	}

	/* Initialize the SDL library */
	if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_NOPARACHUTE) < 0 ) {
		printf( "Couldn't initialize SDL: %s\n",SDL_GetError());
		exit(255);
	}

	/* Create a display for the image */
	screen = SDL_SetVideoMode( SCREENX, SCREENY, 0, SDL_SWSURFACE );
	if ( screen == NULL ) {
		exit(3);
	}

	KrEngine* engine = new KrEngine( screen );
	engine->Draw();

	SDL_Event event;
	bool done = false;

	// Start timing!
	SDL_SetTimer( TIMER_INTERVAL, TimerCallback );

	while( !done && SDL_WaitEvent(&event) )
	{
		if ( event.type == SDL_QUIT )
			break;

		switch(event.type)
		{
			case SDL_KEYDOWN:
			{
				done = true;
			}
			break;

			case SDL_TIMER_EVENT:
			{
				engine->Draw();
			}
			break;

			default:
				break;
		}

	}

	delete engine;

	SDL_Quit();	
	return 0;
}
Example #9
0
int main( int argc, char *argv[] )
{
	SDL_Surface* screen;
	int  depth = 0;
	bool speedtest = false;	
	U32  flags = SDL_SWSURFACE;
	int i;
	bool timerOn = true;
	bool useOpenGL = false;
// 	bool saveBMP = false;

	const SDL_version* sdlVersion = SDL_Linked_Version();
	if ( sdlVersion->minor < 2 )
	{
		GLOUTPUT(( "SDL version must be at least 1.2.0" ));
		GLASSERT( 0 );
		exit( 254 );
	}

	/* Initialize the SDL library */
	if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_NOPARACHUTE) < 0 ) {
		GLOUTPUT(( "Couldn't initialize SDL: %s\n",SDL_GetError()));
		exit(255);
	}

	SDL_WM_SetCaption( "Kyra Demo", 0 );

	for ( i=1; i<argc; i++ )
	{
		if ( *argv[i] == '-' && *(argv[i]+1) )
		{
			const char* param = argv[i]+2;
			switch( *(argv[i]+1) )
			{
				case 'd':
				{
					depth = atoi( param );
				}
				break;

				case 's':
				{
					speedtest = true;
				}
				break;

				case 'f':
				{
					flags |= SDL_FULLSCREEN;
				}
				break;

				case '1':
				{
					timerOn = false;
				}
				break;

				case 't':
				{
					singleTest = atoi( param );
				}
				break;

				case 'o':
				{
					useOpenGL = true;
				}
			}
		}
	}

	if ( useOpenGL )
	{
		if ( flags & SDL_FULLSCREEN )
			flags = SDL_OPENGL | SDL_FULLSCREEN;
		else
			flags = SDL_OPENGL;
	}

	/* Create a display for the image. If we are forcing the mode,
	   skip this step and potentially use a shadow surface.
	*/
	if ( depth == 0 )
	{
		depth = SDL_VideoModeOK( SCREENX, SCREENY, 32, flags );
		if ( depth < 16 )
			depth = 16;
	}

	if ( useOpenGL )
	{
		// We want *at least* 5 bits per channel.
		//SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
    	//SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
    	//SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );

		SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, depth );
		SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
	}
	screen = SDL_SetVideoMode( SCREENX, SCREENY, depth, flags );

	if ( screen == NULL ) {
		fprintf( stdout, "Can't open display (%dx%d %dbps %s)\n",
				 SCREENX, SCREENY, depth,
				 useOpenGL ? "OpenGL" : "" );		
		fprintf( stdout, "SDL_Error: %s\n", SDL_GetError() );
		exit(3);
	}

	char buf[512];
 	factory.GetHeader( screen, buf );
	printf( buf );
	GLOUTPUT(( "%s\n", buf ));

	SDL_Event event;

	if ( speedtest )
	{
		memset( &event, 0, sizeof( event ) );
		event.type = SDL_TIMER_EVENT;
		SDL_PeepEvents( &event, 1, SDL_ADDEVENT, 0 );
		GLOUTPUT(( "Speedtest mode!\n" ));
	}
	else if ( timerOn )
	{
		SDL_SetTimer( timerInterval, TimerCallback );
		GLOUTPUT(( "Demo play mode!\n" ));
	}
	U32 start = SDL_GetTicks();

	if ( singleTest < 0 )
		currentGame = factory.CreateGame( 0, screen );
	else
		currentGame = factory.CreateGame( singleTest, screen );		
	timerInterval = currentGame->FrameInterval();

	while( currentGame && SDL_WaitEvent(&event) )
	{
		if ( event.type == SDL_QUIT )
			break;

		// Cull extra timer messages:
		if ( !speedtest && timerOn )
		{
			SDL_Event nextEvent;
			if (    SDL_PeepEvents( &nextEvent, 1, SDL_PEEKEVENT, SDL_ALLEVENTS )
			     && nextEvent.type == SDL_TIMER_EVENT )
			{
				// the event is duplicated
				//GLOUTPUT( "Timer event tossed.\n" );
				continue;
			}
		}

		switch(event.type)
		{
			case SDL_KEYDOWN:
			{
				if ( event.key.keysym.sym == SDLK_F10 )
				{
					// save a bitmap.
					static int count = 0;
					char buf[ 256 ];
					sprintf( buf, "krdemo%d.bmp", count++ );

					if ( !(screen->flags & SDL_OPENGL ) )
						SDL_SaveBMP( screen, buf );
				} 
				else if ( !timerOn && event.key.keysym.sym == SDLK_SPACE )
				{
					// Simulate a timer:
					SDL_Event e;
					memset( &e, 0, sizeof( e ) );
					e.type = SDL_TIMER_EVENT;
					SDL_PeepEvents( &e, 1, SDL_ADDEVENT, 0 );
				}
				else if ( event.key.keysym.sym == SDLK_s )
				{
					timerInterval = 500;
				}
				else if ( event.key.keysym.sym == SDLK_a )
				{
					timerInterval = 10000;
				}
				else
				{
					NextTest( screen );
				}
			}
			break;

			case SDL_KEYUP:
			{
				if (    event.key.keysym.sym == SDLK_s
					 || event.key.keysym.sym == SDLK_a )
				{
					if ( currentGame )
						timerInterval = currentGame->FrameInterval();

					SDL_SetTimer( 0, TimerCallback );
					SDL_SetTimer( timerInterval, TimerCallback );
				}
			}
			break;

			case SDL_VIDEOEXPOSE:
			{
				currentGame->VideoExpose();
//				currentGame->UpperDrawFrame();
			}
			break;

			case SDL_TIMER_EVENT:
			{
				if ( currentGame )
				{
					currentGame->UpperDrawFrame();

// 					if (    speedtest 
// 					     && currentGame->Frame() == currentGame->TestFrames() )
					if ( currentGame->Frame() == currentGame->TestFrames() )
					{
						U32 end = SDL_GetTicks();
						factory.SetTime( end - start );
						NextTest( screen );
						start = SDL_GetTicks();
					}
					if ( speedtest )
					{
						SDL_Event e;
						memset( &e, 0, sizeof( e ) );
						e.type = SDL_TIMER_EVENT;
						SDL_PeepEvents( &e, 1, SDL_ADDEVENT, 0 );
					}
				}
			}
			break;
		}

	}

	if ( speedtest )
	{
		factory.PrintTimes( screen );
	}
	else
	{
		printf( "Tested at %dbbp\n", screen->format->BitsPerPixel );
	}

	if ( speedtest )
	{
		FILE* fp = fopen( "perf.txt", "w" );
		if ( fp )
		{
			fprintf( fp, "Performance: \n" );
			
			grinliz::Performance::Dump( fp, "kyra" );
			fclose( fp );
		}
	}
	SDL_Quit();	
	return 0;
}
Example #10
0
void init_stuff()
{
	int i;
	int seed;

	chdir(DATA_DIR);
	
#ifndef WINDOWS
	setlocale(LC_NUMERIC,"en_US");
#endif
	init_translatables();

	//create_error_mutex();
	init_globals();
	init_crc_tables();
	init_zip_archives();
	cache_system_init(MAX_CACHE_SYSTEM);
	init_texture_cache();

	init_vars();
	
	read_config();

	file_check_datadir();

#ifdef LOAD_XML
	//Well, the current version of the map editor doesn't support having a datadir - will add that later ;-)
	load_translatables();
#endif

#ifdef LINUX
#ifdef GTK2
	init_filters();
#else
	file_selector = create_fileselection();
#endif
#endif	//LINUX

	init_gl();

	window_resize();
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LESS);
//	glDepthFunc(GL_LEQUAL);
    glEnable(GL_TEXTURE_2D);
	glShadeModel(GL_SMOOTH);
	glFrontFace(GL_CCW);
	glCullFace(GL_BACK);
	glEnable(GL_NORMALIZE);
	glClearColor( 0.0, 0.0, 0.0, 0.0 );
	glClearStencil(0);

	seed = time (NULL);
  	srand (seed);

	init_texture_cache();
	init_particles ();
	init_e3d_cache();
	init_2d_obj_cache();

	for(i=0; i<256; i++)
        tile_list[i]=0;

	for (i = 0; i < MAX_LIGHTS; i++)
		lights_list[i] = NULL;

	new_map(256,256);
	load_all_tiles();

	//lights setup
	build_global_light_table();
	build_sun_pos_table();
	reset_material();
	init_lights();
	//disable_local_lights();
	//clear_error_log();

	// Setup the new eye candy system
#ifdef	EYE_CANDY
	ec_init();
#endif	//EYE_CANDY

	init_gl_extensions();

	if(have_multitexture)
#ifdef	NEW_TEXTURES
		ground_detail_text = load_texture_cached("./textures/ground_detail.bmp", tt_mesh);
#else	/* NEW_TEXTURES */
		ground_detail_text = load_texture_cache ("./textures/ground_detail.bmp",255);
#endif	/* NEW_TEXTURES */

	//load the fonts texture
	init_fonts();
#ifdef	NEW_TEXTURES
	icons_text=load_texture_cached("./textures/gamebuttons.bmp", tt_gui);
	buttons_text=load_texture_cached("./textures/buttons.bmp", tt_gui);
#else	/* NEW_TEXTURES */
	icons_text=load_texture_cache("./textures/gamebuttons.bmp",0);
	buttons_text=load_texture_cache("./textures/buttons.bmp",0);
#endif	/* NEW_TEXTURES */
	//get the application home dir

	have_multitexture=0;//debug only

#ifndef LINUX
	GetCurrentDirectory(sizeof(exec_path),exec_path);
#else
	exec_path[0]='.';exec_path[1]='/';exec_path[2]=0;
#endif
	init_browser();

    if(SDL_InitSubSystem(SDL_INIT_TIMER)<0)
    { 
        char str[120];
        snprintf(str, sizeof(str), "Couldn't initialize the timer: %s\n", SDL_GetError());
        log_error(__FILE__, __LINE__, str);
        SDL_Quit();
	    exit(1);
    }

	SDL_SetTimer (1000/(18*4), my_timer);

	SDL_EnableUNICODE(1);

    //we might want to do this later.

	// creating windows
	display_browser();
	toggle_window(browser_win);

	display_o3dow();
	toggle_window(o3dow_win);

	display_replace_window();
	toggle_window(replace_window_win);

	display_edit_window();
	toggle_window(edit_window_win);

	create_particles_window ();
}
Example #11
0
int
main(int argc, char *argv[])
{
    int i, desired;
    SDL_TimerID t1, t2, t3;
    Uint64 start, now;

    if (SDL_Init(SDL_INIT_TIMER) < 0) {
        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
        return (1);
    }

    /* Start the timer */
    desired = 0;
    if (argv[1]) {
        desired = atoi(argv[1]);
    }
    if (desired == 0) {
        desired = DEFAULT_RESOLUTION;
    }
    SDL_SetTimer(desired, ticktock);

    /* Wait 10 seconds */
    printf("Waiting 10 seconds\n");
    SDL_Delay(10 * 1000);

    /* Stop the timer */
    SDL_SetTimer(0, NULL);

    /* Print the results */
    if (ticks) {
        fprintf(stderr,
                "Timer resolution: desired = %d ms, actual = %f ms\n",
                desired, (double) (10 * 1000) / ticks);
    }

    /* Test multiple timers */
    printf("Testing multiple timers...\n");
    t1 = SDL_AddTimer(100, callback, (void *) 1);
    if (!t1)
        fprintf(stderr, "Could not create timer 1: %s\n", SDL_GetError());
    t2 = SDL_AddTimer(50, callback, (void *) 2);
    if (!t2)
        fprintf(stderr, "Could not create timer 2: %s\n", SDL_GetError());
    t3 = SDL_AddTimer(233, callback, (void *) 3);
    if (!t3)
        fprintf(stderr, "Could not create timer 3: %s\n", SDL_GetError());

    /* Wait 10 seconds */
    printf("Waiting 10 seconds\n");
    SDL_Delay(10 * 1000);

    printf("Removing timer 1 and waiting 5 more seconds\n");
    SDL_RemoveTimer(t1);

    SDL_Delay(5 * 1000);

    SDL_RemoveTimer(t2);
    SDL_RemoveTimer(t3);

    start = SDL_GetPerformanceCounter();
    for (i = 0; i < 1000000; ++i) {
        ticktock(0);
    }
    now = SDL_GetPerformanceCounter();
    printf("1 million iterations of ticktock took %f ms\n", (double)((now - start)*1000) / SDL_GetPerformanceFrequency());

    SDL_Quit();
    return (0);
}
Example #12
0
int main(int argc, char *argv[])
{
	int desired;
	SDL_TimerID t1, t2, t3;

	if ( SDL_Init(SDL_INIT_TIMER) < 0 ) {
		fprintf(stderr, "Couldn't load SDL: %s\n", SDL_GetError());
		exit(1);
	}
	atexit(SDL_Quit);

	/* Start the timer */
	desired = 0;
	if ( argv[1] ) {
		desired = atoi(argv[1]);
	}
	if ( desired == 0 ) {
		desired = DEFAULT_RESOLUTION;
	}
	SDL_SetTimer(desired, ticktock);

	/* Wait 10 seconds */
	printf("Waiting 10 seconds\n");
	SDL_Delay(10*1000);

	/* Stop the timer */
	SDL_SetTimer(0, NULL);

	/* Print the results */
	if ( ticks ) {
		fprintf(stderr,
		"Timer resolution: desired = %d ms, actual = %f ms\n",
					desired, (double)(10*1000)/ticks);
	}
	
	/* Test multiple timers */
	printf("Testing multiple timers...\n");
	t1 = SDL_AddTimer(100, callback, (void*)1);
	if(!t1)
	  fprintf(stderr,"Could not create timer 1: %s\n", SDL_GetError());
	t2 = SDL_AddTimer(50, callback, (void*)2);
	if(!t2)
	  fprintf(stderr,"Could not create timer 2: %s\n", SDL_GetError());
	t3 = SDL_AddTimer(233, callback, (void*)3);
	if(!t3)
	  fprintf(stderr,"Could not create timer 3: %s\n", SDL_GetError());
	
	/* Wait 10 seconds */
	printf("Waiting 10 seconds\n");
	SDL_Delay(10*1000);

	printf("Removing timer 1 and waiting 5 more seconds\n");
	SDL_RemoveTimer(t1);

	SDL_Delay(5*1000);

	SDL_RemoveTimer(t2);
	SDL_RemoveTimer(t3);

	return(0);
}
Example #13
0
void initTracker(pp_uint32 bpp, PPDisplayDevice::Orientations orientation, 
				 bool swapRedBlue, bool fullScreen, bool noSplash)
{
	/* Initialize SDL */
	if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0 ) 
	{
		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
		exit(1);
	}
	// atexit(SDL_Quit);	Not really needed, and needs a wrapper for OS/2

#ifdef __GP2X__
	if ( SDL_Init(SDL_INIT_JOYSTICK) < 0 || !SDL_JoystickOpen(0)) 
	{
		fprintf(stderr, "Couldn't initialize SDL Joystick: %s\n",SDL_GetError());
		exit(1);
	}
	mouse.x = 0;
	mouse.y = 0;
	mouse.ticks = 0;
	mouse.button = 0;
#endif

	SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,
	                    SDL_DEFAULT_REPEAT_INTERVAL);
						
	SDL_EnableUNICODE(1);

#if (defined(unix) || defined(__unix__) || defined(_AIX) || defined(__OpenBSD__)) && \
    (!defined(__CYGWIN32__) && !defined(ENABLE_NANOX) && \
     !defined(__QNXNTO__) && !defined(__AROS__))

	// Initialise crash handler
	struct sigaction act;
	struct sigaction oldAct;
	memset(&act, 0, sizeof(act));
	act.sa_handler = crashHandler;
	act.sa_flags = SA_RESETHAND;
	sigaction(SIGTERM | SIGILL | SIGABRT | SIGFPE | SIGSEGV, &act, &oldAct);
	sigaction(SIGILL, &act, &oldAct);
	sigaction(SIGABRT, &act, &oldAct);
	sigaction(SIGFPE, &act, &oldAct);
	sigaction(SIGSEGV, &act, &oldAct);
#endif
	
#if defined(HAVE_X11) && !defined(__QTOPIA__)
	SDL_SysWMinfo info;
	SDL_VERSION(&info.version);
	if ( SDL_GetWMInfo(&info) && info.subsystem == SDL_SYSWM_X11)
		isX11 = true;	// Used in SDL_KeyTranslation.cpp
#endif

	SDL_WM_SetCaption("Loading MilkyTracker...", "MilkyTracker");
	// ------------ initialise tracker ---------------
	myTracker = new Tracker();

	PPSize windowSize = myTracker->getWindowSizeFromDatabase();
 	if (!fullScreen) 
		fullScreen = myTracker->getFullScreenFlagFromDatabase();
	pp_int32 scaleFactor = myTracker->getScreenScaleFactorFromDatabase();

#ifdef __LOWRES__
	windowSize.width = DISPLAYDEVICE_WIDTH;
	windowSize.height = DISPLAYDEVICE_HEIGHT;
#endif

#ifdef __OPENGL__
	myDisplayDevice = new PPDisplayDeviceOGL(screen, windowSize.width, windowSize.height, 1, bpp, fullScreen, orientation, swapRedBlue);
#else
	myDisplayDevice = new PPDisplayDeviceFB(screen, windowSize.width, windowSize.height, scaleFactor, 
											bpp, fullScreen, orientation, swapRedBlue);
#endif 
	
	myDisplayDevice->init();

	myTrackerScreen = new PPScreen(myDisplayDevice, myTracker);
	myTracker->setScreen(myTrackerScreen);

#ifdef __QTOPIA__
	// On Qtopia I have to run a short event loop
	// until drawing/blitting can be performed
	// so the splash screen will be visible
	for (pp_int32 i = 0; i < 500; i++)
	{
		SDL_Event event;
		SDL_PollEvent(&event);
	}
#endif
	
	// Startup procedure
	myTracker->startUp(noSplash);

#ifdef HAVE_LIBASOUND
	InitMidi();
#endif

	// try to create timer
	SDL_SetTimer(20, timerCallback);	

	timerMutex->lock();
	ticking = true;
	timerMutex->unlock();
}
Example #14
0
/**
 * ANSI main entry point
 */
int main(int argc, char* argv[])
{
	unsigned long lvl_id;
	level::size lvl_sz;
	bool lvl_wrap;
	if (parse_cmd_params(argc, argv, lvl_id, lvl_sz, lvl_wrap))
		return 0;	//Help or version was shown

	//Initialization
	if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO) != 0) {
		fprintf(stderr, "Critical error\nSDL_Init failed: %s\n", SDL_GetError());
		return 1;
	}
#ifdef USE_OPENGLES
       	if (EGL_Open()){
		fprintf(stderr, "Critical error\nUnable to open egl\n");
		return 1;
	}
#endif
	//Let's get some video information
	const SDL_VideoInfo* vinfo = SDL_GetVideoInfo();
	if (!vinfo) {
		fprintf(stderr, "Critical error\nUnable to get video information: %s\n", SDL_GetError());
		return 1;
	}

	//Save desktop size
	const int desktop_width = vinfo->current_w;
	const int desktop_height = vinfo->current_h;

	//Calculate minimum window sizes
	const int wnd_min_width =  PW_SCREEN_WIDTH  / 3;
	const int wnd_min_height = PW_SCREEN_HEIGHT / 3;

	//Create window
#if USE_OPENGLES
	if (!SDL_SetVideoMode(800, 480, 0, SDL_FULLSCREEN)) {
		fprintf(stderr, "Critical error\nUnable to set video mode: %s\n", SDL_GetError());
		return 1;
	}
	int prevcursorstate=SDL_ShowCursor(SDL_QUERY);
	SDL_ShowCursor(SDL_DISABLE);
	EGL_Init();
#else
	if (!SDL_SetVideoMode(PW_SCREEN_WIDTH, PW_SCREEN_HEIGHT, 0, SDL_OPENGL | SDL_RESIZABLE)) {
		fprintf(stderr, "Critical error\nUnable to set video mode: %s\n", SDL_GetError());
		return 1;
	}
#endif
	SDL_WM_SetCaption(PACKAGE_NAME, PACKAGE_NAME);
	image wnd_icon;
	if (wnd_icon.load_XPM(pipewalker_xpm, sizeof(pipewalker_xpm) / sizeof(pipewalker_xpm[0])))
		SDL_WM_SetIcon(wnd_icon.get_surface(), NULL);

	game& game_instance = game::instance();
	if (!game_instance.initialize(lvl_id, lvl_sz, lvl_wrap))
		return 1;

	//Timer - about 25 fps
	SDL_SetTimer(40, &timer_callback);

#ifdef WIN32
	SDL_SysWMinfo wmi;
	SDL_VERSION(&wmi.version);
	if (SDL_GetWMInfo(&wmi)) {
		//Set own window procedure
		sdl_wnd_proc = reinterpret_cast<WNDPROC>(SetWindowLongPtr(wmi.window, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(&pw_win32_wnd_proc)));
		//Set normal icon
		static HICON icon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(0));
		if (icon)
			SetClassLongPtr(wmi.window, GCL_HICON, reinterpret_cast<LONG>(icon));
	}
#endif // WIN32

	bool done = false;
	Uint8 last_mouse_state = 0;

	while (!done) {
		SDL_Event event;
		if (SDL_WaitEvent(&event) == 0) {
			fprintf(stderr, "Critical error\nSDL_WaitEvent failed: %s\n", SDL_GetError());
			return 1;
		}
		switch (event.type) {
			case SDL_MOUSEMOTION:
				{
					Sint32 x, y;
					SDL_GetMouseState(&x, &y);
					game_instance.on_mouse_move(x, y);
				}
				break;
			case SDL_MOUSEBUTTONDOWN:
				//We need to save buttons state - in the SDL_MOUSEBUTTONUP event doesn't have this information
				last_mouse_state = SDL_GetMouseState(NULL, NULL);
				break;
			case SDL_MOUSEBUTTONUP:
				if (last_mouse_state) {
					game_instance.on_mouse_click(last_mouse_state);
					last_mouse_state = 0;
				}
				break;
			case SDL_KEYDOWN:
				if (event.key.keysym.sym == SDLK_F4 && (SDL_GetModState() == KMOD_LALT || SDL_GetModState() == KMOD_RALT))
					done = true;	//Alt+F4 pressed
				else
					done = game_instance.on_key_press(event.key.keysym.sym);
				break;
			case SDL_QUIT:
				done = true;
				break;
			case SDL_VIDEOEXPOSE:
				game_instance.draw_scene();
				break;
			case SDL_VIDEORESIZE:
				if (event.resize.w && event.resize.h) {
					int wnd_width = event.resize.w;
					int wnd_height = event.resize.h;

					//Set correct aspect ratio
					if (wnd_width != desktop_width && wnd_height != desktop_height) {
						if (wnd_height != vinfo->current_h)
							wnd_width = static_cast<int>(static_cast<float>(wnd_height) / PW_ASPECT_RATIO);
						else if (wnd_width != vinfo->current_w)
							wnd_height = static_cast<int>(static_cast<float>(wnd_width) * PW_ASPECT_RATIO);
						if (wnd_width < wnd_min_width || wnd_height < wnd_min_height) {
							//Set minimum window size
							wnd_width = wnd_min_width;
							wnd_height = wnd_min_height;
						}
					}

					SDL_SetVideoMode(wnd_width, wnd_height, 0, SDL_OPENGL | SDL_RESIZABLE);
					game_instance.on_window_resize(wnd_width, wnd_height);
					SDL_Event expose_event;
					expose_event.type = SDL_VIDEOEXPOSE;
					SDL_PushEvent(&expose_event);
				}
				break;
		}
	}

	game_instance.finalize();
#if USE_OPENGLES
	EGL_Close();
	SDL_ShowCursor(prevcursorstate);
#endif

	SDL_Quit();
	return 0;
}
Example #15
0
int main(int argc, char *argv[])
#endif
{
	Uint32 videoflags;	
	SDL_Event event;
	char *loadFile = 0;
	
	pp_int32 defaultBPP = -1;
	PPDisplayDevice::Orientations orientation = PPDisplayDevice::ORIENTATION_NORMAL;
	bool swapRedBlue = false, fullScreen = false, noSplash = false;
	bool recVelocity = false;
	
	// Parse command line
	while ( argc > 1 ) 
	{
		--argc;
		if ( strcmp(argv[argc-1], "-bpp") == 0 ) 
		{
			defaultBPP = atoi(argv[argc]);
			--argc;
		}
		else if ( strcmp(argv[argc], "-nosplash") == 0 ) 
		{
			noSplash = true;
		} 
		else if ( strcmp(argv[argc], "-swap") == 0 ) 
		{
			swapRedBlue = true;
		}
		else if ( strcmp(argv[argc], "-fullscreen") == 0)
		{
			fullScreen = true;
		}
		else if ( strcmp(argv[argc-1], "-orientation") == 0 ) 
		{
			if (strcmp(argv[argc], "NORMAL") == 0)
			{
				orientation = PPDisplayDevice::ORIENTATION_NORMAL;
			}
			else if (strcmp(argv[argc], "ROTATE90CCW") == 0)
			{
				orientation = PPDisplayDevice::ORIENTATION_ROTATE90CCW;
			}
			else if (strcmp(argv[argc], "ROTATE90CW") == 0)
			{
				orientation = PPDisplayDevice::ORIENTATION_ROTATE90CW;
			}
			else 
				goto unrecognizedCommandLineSwitch;
			--argc;
		} 
		else if ( strcmp(argv[argc], "-nonstdkb") == 0)
		{
			stdKb = false;
		}
		else if ( strcmp(argv[argc], "-recvelocity") == 0)
		{
			recVelocity = true;
		}
		else 
		{
unrecognizedCommandLineSwitch:
			if (argv[argc][0] == '-') 
			{
				fprintf(stderr, 
						"Usage: %s [-bpp N] [-swap] [-orientation NORMAL|ROTATE90CCW|ROTATE90CW] [-fullscreen] [-nosplash] [-nonstdkb] [-recvelocity]\n", argv[0]);
				exit(1);
			} 
			else 
			{
				loadFile = argv[argc];
			}
		}
	}

	// Workaround for seg-fault in SDL_Init on Eee PC (thanks nostromo)
	// (see http://forum.eeeuser.com/viewtopic.php?pid=136945)
#if HAVE_DECL_SDL_PUTENV
	SDL_putenv("SDL_VIDEO_X11_WMCLASS=Milkytracker");
#endif

	timerMutex = new PPMutex();
	globalMutex = new PPMutex();
	
	// Store current working path (init routine is likely to change it)
	PPPath_POSIX path;	
	PPSystemString oldCwd = path.getCurrent();
	
	globalMutex->lock();
	initTracker(defaultBPP, orientation, swapRedBlue, fullScreen, noSplash);
	globalMutex->unlock();

#ifdef HAVE_LIBASOUND
	if (myMidiReceiver && recVelocity)
	{
		myMidiReceiver->setRecordVelocity(true);
	}
#endif

	if (loadFile) 
	{
		PPSystemString newCwd = path.getCurrent();
		path.change(oldCwd);
		SendFile(loadFile);
		path.change(newCwd);
		pp_uint16 chr[3] = {VK_RETURN, 0, 0};
		PPEvent event(eKeyDown, &chr, sizeof(chr));
		RaiseEventSerialized(&event);
	}
	
	/* Main event loop */
	done = 0;
	while (!done && SDL_WaitEvent(&event)) 
	{
		switch (event.type) 
		{
			case SDL_QUIT:
				exitSDLEventLoop(false);
				break;
			case SDL_MOUSEMOTION:
			{
				// ignore old mouse motion events in the event queue
				SDL_Event new_event;
				
				if (SDL_PeepEvents(&new_event, 1, SDL_GETEVENT, SDL_EVENTMASK(SDL_MOUSEMOTION)) > 0) 
				{
					while (SDL_PeepEvents(&new_event, 1, SDL_GETEVENT, SDL_EVENTMASK(SDL_MOUSEMOTION)) > 0);
					processSDLEvents(new_event);
				} 
				else 
				{
					processSDLEvents(event);
				}
				break;
			}

			case SDL_USEREVENT:
				processSDLUserEvents((const SDL_UserEvent&)event);
				break;

			default:
				processSDLEvents(event);
				break;
		}
	}

#ifdef __GP2X__
	SDL_JoystickClose(0);
#endif

	timerMutex->lock();
	ticking = false;
	timerMutex->unlock();

	SDL_SetTimer(0, NULL);
	
	timerMutex->lock();
	globalMutex->lock();
#ifdef HAVE_LIBASOUND
	delete myMidiReceiver;
#endif
	delete myTracker;
	myTracker = NULL;
	delete myTrackerScreen;
	myTrackerScreen = NULL;
	delete myDisplayDevice;
	globalMutex->unlock();
	timerMutex->unlock();
	SDL_Quit();
	delete globalMutex;
	delete timerMutex;
	
	/* Quoting from README.Qtopia (Application Porting Notes):
	One thing I have noticed is that applications sometimes don't exit
	correctly. Their icon remains in the taskbar and they tend to
	relaunch themselves automatically. I believe this problem doesn't
	occur if you exit your application using the exit() method. However,
	if you end main() with 'return 0;' or so, this seems to happen.
	*/
#ifdef __QTOPIA__
	exit(0);
#else
	return 0;
#endif
}
Example #16
0
void sound_uninit(void)
{
  int c;

  if (!initted) return;
  initted = 0;

  // Apparently a delay is needed to make sure the sound timer thread is
  // not mixing stuff anymore, and we can safely delete related structures
  SDL_Delay(50);

  if (usehardsid || usecatweasel)
  {
    #ifdef __WIN32__
    if (!playerthread)
    {
      SDL_SetTimer(0, NULL);
    }
    else
    {
      runplayerthread = FALSE;
      SDL_WaitThread(playerthread, NULL);
      playerthread = NULL;
    }
    #else
    SDL_SetTimer(0, NULL);
    #endif
  }
  else
  {
      snd_setcustommixer(NULL);
    snd_player = NULL;
  }

  if (writehandle)
  {
    fclose(writehandle);
    writehandle = NULL;
  }
  
  if (buffer)
  {
    free(buffer);
    buffer = NULL;
  }

  if (usehardsid)
  {
    #ifdef __WIN32__
    for (c = 0; c < NUMSIDREGS; c++)
    {
        if (cycleexacthardsid) {
            HardSID_Write(usehardsid-1, SIDWRITEDELAY, c, 0x00);
        }
        else {
            WriteToHardSID(usehardsid-1, c, 0x00);
        }
    }
    MuteHardSID_Line(TRUE);
    #else
    if (hardsidfd >= 0)
    {
      for (c = 0; c < NUMSIDREGS; c++)
      {
        Uint32 dataword = c << 8;
        write(hardsidfd, &dataword, 4);
      }
      close(hardsidfd);
      hardsidfd = -1;
    }
    #endif
  }

  if (usecatweasel)
  {
    #ifdef __WIN32__
    DWORD w;
    unsigned char buf[NUMSIDREGS * 2];
    for (w = 0; w < NUMSIDREGS; w++)
    {
      buf[w*2] = 0x18 - w;
      buf[w*2+1] = 0;
    }
    DeviceIoControl(catweaselhandle, SID_SID_PEEK_POKE, buf, sizeof(buf), 0L, 0UL, &w, 0L);
    CloseHandle(catweaselhandle);
    catweaselhandle = INVALID_HANDLE_VALUE;
    #else
    if (catweaselfd >= 0)
    {
      unsigned char buf[NUMSIDREGS];
      memset(buf, 0, sizeof(buf));
      lseek(catweaselfd, 0, SEEK_SET);
      write(catweaselfd, buf, sizeof(buf));
      close(catweaselfd);
      catweaselfd = -1;
    }
    #endif
  }
}
Example #17
0
int sound_init(unsigned b, unsigned mr, unsigned writer, unsigned hardsid, unsigned m, unsigned ntsc, unsigned multiplier, unsigned catweasel, unsigned interpolate, unsigned customclockrate)
{
  int c;

  #ifdef __WIN32__
  if (!flushmutex)
      flushmutex = SDL_CreateMutex();
  #endif

  sound_uninit();

  if (multiplier)
  {
    if (ntsc)
    {
      framerate = NTSCFRAMERATE * multiplier;
      snd_bpmtempo = 150 * multiplier;
    }
    else
    {
      framerate = PALFRAMERATE * multiplier;
      snd_bpmtempo = 125 * multiplier;
    }
  }
  else
  {
    if (ntsc)
    {
      framerate = NTSCFRAMERATE / 2;
      snd_bpmtempo = 150 / 2;
    }
    else
    {
      framerate = PALFRAMERATE / 2;
      snd_bpmtempo = 125 / 2;
    }
  }

  if (hardsid)
  {
    #ifdef __WIN32__
    InitHardDLL();
    if (dll_initialized)
    {
      usehardsid = hardsid;
      if (cycleexacthardsid) {
        HardSID_Lock(usehardsid-1);
        HardSID_Flush(usehardsid-1);
        HardSID_Write(usehardsid-1, SIDWRITEDELAY, 0, 0x00);
        Sleep(300);
      }
      for (c = 0; c < NUMSIDREGS; c++)
      {
        sidreg[c] = 0;
        if (cycleexacthardsid) {
            HardSID_Write(usehardsid-1, SIDWRITEDELAY, c, 0x00);
        }
        else {
            WriteToHardSID(usehardsid-1, c, 0x00);
        }
      }
      if (cycleexacthardsid) {
        HardSID_SoftFlush(usehardsid-1);
      }
      else {
        MuteHardSID_Line(FALSE);
      }
    }
    else return 0;
    if (!cycleexacthardsid)
    {
      SDL_SetTimer(1000 / framerate, sound_timer);
    }
    else
    {
      runplayerthread = TRUE;
      playerthread = SDL_CreateThread(sound_thread, NULL);
      if (!playerthread) return 0;
    }
    #else
    char filename[80];
    sprintf(filename, "/dev/sid%d", hardsid-1);
    hardsidfd = open(filename, O_WRONLY, S_IREAD|S_IWRITE);
    if (hardsidfd >= 0)
    {
      usehardsid = hardsid;
      for (c = 0; c < NUMSIDREGS; c++)
      {
        Uint32 dataword = c << 8;
        write(hardsidfd, &dataword, 4);
      }
    }
    else return 0;
    SDL_SetTimer(1000 / framerate, sound_timer);
    #endif

    goto SOUNDOK;
  }

  if (catweasel)
  {
    #ifdef __WIN32__
    catweaselhandle = CreateFile("\\\\.\\SID6581_1", GENERIC_READ, FILE_SHARE_WRITE|FILE_SHARE_READ, 0L,
      OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0L);
    if (catweaselhandle == INVALID_HANDLE_VALUE)
      return 0;
    #else
    catweaselfd = open("/dev/sid", O_WRONLY);
    if (catweaselfd < 0)
      catweaselfd = open("/dev/misc/sid", O_WRONLY);
    if (catweaselfd < 0)
      return 0;
    #ifndef __amigaos__
    if (ntsc)
      ioctl(catweaselfd, CWSID_IOCTL_NTSC);
    else
      ioctl(catweaselfd, CWSID_IOCTL_PAL);
    #endif
    #endif

    usecatweasel = 1;
    SDL_SetTimer(1000 / framerate, sound_timer);
    goto SOUNDOK;
  }

  if (!buffer) buffer = malloc(MIXBUFFERSIZE * sizeof(Sint16));
  if (!buffer) return 0;

  if (writer)
    writehandle = fopen("sidaudio.raw", "wb");

  playspeed = mr;
  if (playspeed < MINMIXRATE) playspeed = MINMIXRATE;
  if (playspeed > MAXMIXRATE) playspeed = MAXMIXRATE;
  if (b < MINBUF) b = MINBUF;
  if (b > MAXBUF) b = MAXBUF;

  if (firsttimeinit)
  {
    if (!snd_init(mr, SIXTEENBIT|MONO, b, 1, 0)) return 0;
    firsttimeinit = 0;
  }
  playspeed = snd_mixrate;
  sid_init(playspeed, m, ntsc, interpolate & 1, customclockrate, interpolate >> 1);

  snd_player = &sound_playrout;
  snd_setcustommixer(sound_mixer);

  SOUNDOK:
  initted = 1;
  return 1;
}
Example #18
0
void
SDL_SYS_TimerQuit(void)
{
    SDL_SetTimer(0, NULL);
}
Example #19
0
void init_stuff()
{
	int seed;

	Uint32 (*my_timer_pointer) (unsigned int) = my_timer;

	//TODO: process command line options
	chdir(datadir);

	//Initialize all strings
	init_translatables();

#ifdef WRITE_XML
	load_translatables();//Write to the current working directory - hopefully we'll have write rights here...
#endif

	//read the config file
	read_config();

	//Parse command line options
	read_command_line();

	//OK, we have the video mode settings...
	setup_video_mode(full_screen,video_mode);
	//now you may set the video mode using the %<foo> in-game
	video_mode_set=1;

	//Good, we should be in the right working directory - load all translatables from their files
	load_translatables();

	init_video();
	resize_window();
	init_gl_extensions();
#ifdef CAL3D
	create_cal3d_model();
	init_cal3d_model();
#endif
	seed = time (NULL);
	srand (seed);

	cache_system_init(MAX_CACHE_SYSTEM);
	init_texture_cache();
	init_md2_cache();
	init_e3d_cache();
	init_2d_obj_cache();
	load_ignores();
	load_filters();
	load_e3d_list();
	load_e2d_list();
	load_part_list();
	load_knowledge_list();
	load_cursors();
	build_cursors();
	change_cursor(CURSOR_ARROW);
	build_glow_color_table();


	init_actors_lists();
	memset(tile_list, 0, sizeof(tile_list));
	memset(lights_list, 0, sizeof(lights_list));
	init_particles_list();
	memset(actors_defs, 0, sizeof(actors_defs));
	init_actor_defs();

	load_map_tiles();

	//lights setup
	build_global_light_table();
	build_sun_pos_table();
	reset_material();
	init_lights();
	disable_local_lights();
	init_colors();
	clear_error_log();
	clear_conn_log();
	clear_thunders();
	build_rain_table();
	read_bin_cfg();
	build_levels_table();//for some HUD stuff
	init_scale_array();

	if(!no_sound)init_sound();

	//initialize the fonts
	init_fonts();
	check_gl_errors();

	//load the necesary textures
	//font_text=load_texture_cache("./textures/font.bmp",0);
	icons_text=load_texture_cache("./textures/gamebuttons.bmp",0);
	hud_text=load_texture_cache("./textures/gamebuttons2.bmp",0);
	cons_text=load_texture_cache("./textures/console.bmp",255);
	sky_text_1=load_texture_cache("./textures/sky.bmp",70);
	particle_textures[0]=load_texture_cache("./textures/particle0.bmp",0);
	particle_textures[1]=load_texture_cache("./textures/particle1.bmp",0);
	particle_textures[2]=load_texture_cache("./textures/particle2.bmp",0);
	particle_textures[3]=load_texture_cache("./textures/particle3.bmp",0);
	particle_textures[4]=load_texture_cache("./textures/particle4.bmp",0);
	particle_textures[5]=load_texture_cache("./textures/particle5.bmp",0);
	particle_textures[6]=load_texture_cache("./textures/particle6.bmp",0);
	particle_textures[7]=load_texture_cache("./textures/particle7.bmp",0);

	items_text_1=load_texture_cache("./textures/items1.bmp",0);
	items_text_2=load_texture_cache("./textures/items2.bmp",0);
	items_text_3=load_texture_cache("./textures/items3.bmp",0);
	items_text_4=load_texture_cache("./textures/items4.bmp",0);
	items_text_5=load_texture_cache("./textures/items5.bmp",0);
	items_text_6=load_texture_cache("./textures/items6.bmp",0);
	items_text_7=load_texture_cache("./textures/items7.bmp",0);
	items_text_8=load_texture_cache("./textures/items8.bmp",0);
	items_text_9=load_texture_cache("./textures/items9.bmp",0);

	portraits1_tex=load_texture_cache("./textures/portraits1.bmp",0);
	portraits2_tex=load_texture_cache("./textures/portraits2.bmp",0);
	portraits3_tex=load_texture_cache("./textures/portraits3.bmp",0);
	portraits4_tex=load_texture_cache("./textures/portraits4.bmp",0);
	portraits5_tex=load_texture_cache("./textures/portraits5.bmp",0);
	halo_tex=load_texture_cache("./textures/halo.bmp",0);

	if(have_multitexture)ground_detail_text=load_texture_cache("./textures/ground_detail.bmp",255);
	check_gl_errors();
	create_char_error_str[0]=0;
	init_opening_interface();
	init_hud_interface();

	if(SDLNet_Init()<0)
 		{
			char str[120];
			sprintf(str,"%s: %s\n",failed_sdl_net_init,SDLNet_GetError());
			log_error(str);
			SDLNet_Quit();
			SDL_Quit();
			exit(2);
		}

	if(SDL_InitSubSystem(SDL_INIT_TIMER)<0)
		{
 			char str[120];
			sprintf(str, "%s: %s\n", failed_sdl_timer_init,SDL_GetError());
			log_error(str);
			SDL_Quit();
		 	exit(1);
		}
	SDL_SetTimer (1000/(18*4), my_timer_pointer);

	ReadXML("languages/en/Encyclopedia/index.xml");
	read_key_config();
	load_questlog();
	init_buddy();

	//initiate function pointers
	init_attribf();

	//we might want to do this later.
	connect_to_server();
}
Example #20
0
void start_game() {
	SDL_SetTimer( 1000, PlayerCall );
}
Example #21
0
void ttext_::signal_handler_sdl_key_down(const event::tevent event
        , bool& handled
        , const SDLKey key
        , SDLMod modifier
        , const Uint16 unicode)
{

    DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";

// For copy/paste we use a different key on the MAC. Other ctrl modifiers won't
// be modifed seems not to be required when I read the comment in
// widgets/textbox.cpp:516. Would be nice if somebody on a MAC would test it.
#ifdef __APPLE__
    const unsigned copypaste_modifier = KMOD_LMETA | KMOD_RMETA;
#else
    const unsigned copypaste_modifier = KMOD_CTRL;
#endif

    switch(key) {

    case SDLK_LEFT :
        handle_key_left_arrow(modifier, handled);
        break;

    case SDLK_RIGHT :
        handle_key_right_arrow(modifier, handled);
        break;

    case SDLK_UP :
        handle_key_up_arrow(modifier, handled);
        break;

    case SDLK_DOWN :
        handle_key_down_arrow(modifier, handled);
        break;

    case SDLK_PAGEUP :
        handle_key_page_up(modifier, handled);
        break;

    case SDLK_PAGEDOWN :
        handle_key_page_down(modifier, handled);
        break;

    case SDLK_a :
        if(!(modifier & KMOD_CTRL)) {
            handle_key_default(handled, key, modifier, unicode);
            break;
        }

        // If ctrl-a is used for home drop the control modifier
        modifier = static_cast<SDLMod>(modifier &~ KMOD_CTRL);
    /* FALL DOWN */

    case SDLK_HOME :
        handle_key_home(modifier, handled);
        break;

    case SDLK_e :
        if(!(modifier & KMOD_CTRL)) {
            handle_key_default(handled, key, modifier, unicode);
            break;
        }

        // If ctrl-e is used for end drop the control modifier
        modifier = static_cast<SDLMod>(modifier &~ KMOD_CTRL);
    /* FALL DOWN */

    case SDLK_END :
        handle_key_end(modifier, handled);
        break;

    case SDLK_BACKSPACE :
        handle_key_backspace(modifier, handled);
        break;

    case SDLK_u :
        if(modifier & KMOD_CTRL) {
            handle_key_clear_line(modifier, handled);
        } else {
            handle_key_default(handled, key, modifier, unicode);
        }
        break;

    case SDLK_DELETE :
#if defined(__APPLE__) && TARGET_OS_IPHONE
        handle_key_backspace(modifier, handled);
#else
        handle_key_delete(modifier, handled);
#endif
        break;

#if defined(__APPLE__) && TARGET_OS_IPHONE
    case SDLK_RETURN:
        SDL_SetTimer(0xbbbbbbb0, NULL);
        break;
#endif

    case SDLK_c :
        if(!(modifier & copypaste_modifier)) {
            handle_key_default(handled, key, modifier, unicode);
            break;
        }

        // atm we don't care whether there is something to copy or paste
        // if nothing is there we still don't want to be chained.
        copy_selection(false);
        handled = true;
        break;

    case SDLK_x :
        if(!(modifier & copypaste_modifier)) {
            handle_key_default(handled, key, modifier, unicode);
            break;
        }

        copy_selection(false);
        delete_selection();
        handled = true;
        break;

    case SDLK_v :
        if(!(modifier & copypaste_modifier)) {
            handle_key_default(handled, key, modifier, unicode);
            break;
        }

        paste_selection(false);
        handled = true;
        break;

    default :
        handle_key_default(handled, key, modifier, unicode);

    }

    if (text_changed_callback_) {
        text_changed_callback_(this, this->text());
    }

}