Esempio n. 1
0
static void getevents()
{
	SDL_Event event;
	static BOOL ctrldown = 0, altdown = 0;
	sopkey_t translated;

	while (SDL_PollEvent(&event)) {
		switch (event.type) {
		case SDL_KEYDOWN:
			if (event.key.keysym.sym == SDLK_LALT)
				altdown = 1;
			else if (event.key.keysym.sym == SDLK_LCTRL || event.key.keysym.sym == SDLK_RCTRL)
				ctrldown = 1;
			else if (ctrldown &&
				 (event.key.keysym.sym == SDLK_c ||
				  event.key.keysym.sym == SDLK_BREAK)) {
				++ctrlbreak;
				if (ctrlbreak >= 3) {
					fprintf(stderr,
						"user aborted with 3 ^C's\n");
					exit(-1);
				}
			} else if (event.key.keysym.sym == SDLK_ESCAPE) {
				input_buffer_push(27);
			} else if (event.key.keysym.sym == SDLK_RETURN) {
				if(altdown) {
					vid_fullscreen = !vid_fullscreen;
					Vid_Reset();
				} else {
					input_buffer_push('\n');
				}
 			} else {
				input_buffer_push(event.key.keysym.unicode & 0x7f);
			}
			translated = translate_key(event.key.keysym.sym);
			if (translated)
				keysdown[translated] |= 3;
			break;
		case SDL_KEYUP:
			if (event.key.keysym.sym == SDLK_LALT)
				altdown = 0;
			else if (event.key.keysym.sym == SDLK_LCTRL || event.key.keysym.sym == SDLK_RCTRL)
				ctrldown = 0;
			else {
				translated = translate_key(event.key.keysym.sym);
				if (translated)
					keysdown[translated] &= ~1;
			}
			break;
		}
	}
}
Esempio n. 2
0
void cb_goto_key_down(Ewl_Widget *w, void *ev, void *data)
{
    Ewl_Widget *curwidget;
    char temp[50];
    Ewl_Event_Key_Down *e;
    e = (Ewl_Event_Key_Down*)ev;
    int k = translate_key(e);
    int page,totalpages;
    switch(k)
    {
    case K_RETURN:
        ewl_widget_hide(menu);
        totalpages=epdf_document_page_count_get(ewl_pdf_pdf_document_get(EWL_PDF(pdfwidget)));
        page=(int)strtol(ewl_text_text_get(EWL_TEXT(goto_entry)),NULL,10);
        sprintf(temp,"menuitem1");
        curwidget=ewl_widget_name_find(temp);
        ewl_menu_collapse(EWL_MENU(curwidget));
        if(page>0&&page<=totalpages)
            ewl_pdf_page_set(EWL_PDF(pdfwidget),page-1);
        break;
    case K_ESCAPE:
        sprintf(temp,"menuitem1");
        curwidget=ewl_widget_name_find(temp);
        ewl_menu_collapse(EWL_MENU(curwidget));
        ewl_widget_focus_send(menu);
        break;

    default:
        return;
    }
    
}
Esempio n. 3
0
/*
 * Translates key and button events.
 */
static int
key_event( struct input_event *levt,
           DFBInputEvent      *devt )
{
     if (levt->code >= BTN_MOUSE && levt->code <= BTN_STYLUS2) {
          devt->type   = levt->value ? DIET_BUTTONPRESS : DIET_BUTTONRELEASE;
          /* don't set DIEF_BUTTONS, it will be set by the input core */
          devt->button = DIBI_FIRST + levt->code - BTN_MOUSE;
     }
     else {
          int key = translate_key( levt->code );

          if (key == DIKI_UNKNOWN)
               return 0;

          devt->type = levt->value ? DIET_KEYPRESS : DIET_KEYRELEASE;

          if (DFB_KEY_TYPE(key) == DIKT_IDENTIFIER) {
               devt->key_id = key;
               devt->flags |= DIEF_KEYID;
          }
          else {
               devt->key_symbol = key;
               devt->flags |= DIEF_KEYSYMBOL;
          }
     }

     return 1;
}
Esempio n. 4
0
int
console_wait_for_key(void)
{
	// wait for a key
	char buffer[3];
	ssize_t bytesRead;
	do {
		bytesRead = sInput.ReadAt(NULL, 0, buffer, 3);
		if (bytesRead < 0)
			return 0;
	} while (bytesRead == 0);

	// translate the ESC sequences for cursor keys
	if (bytesRead == 3 && buffer[0] == 27 && buffer[1] == 91) {
		int key = translate_key(buffer[2]);
		if (key != 0)
			return key;
	}

	// put back unread chars
	if (bytesRead > 1)
		sInput.PutChars(buffer + 1, bytesRead - 1);

	return buffer[0];
}
Esempio n. 5
0
/*
 * Input thread reading from device.
 * Generates events on incoming data.
 */
static void*
osxEventThread( DirectThread *thread, void *driver_data )
{
     OSXInputData *data    = (OSXInputData*) driver_data;
     DFBOSX       *dfb_osx = data->dfb_osx;

     while (!data->stop) {
          DFBInputEvent evt;
          EventRecord   event;

          fusion_skirmish_prevail( &dfb_osx->lock );

          /* Check for events */
          while ( WaitNextEvent( everyEvent, &event, 0, nil) ) {
               fusion_skirmish_dismiss( &dfb_osx->lock );

               switch (event.what) {
                    case keyDown:
                    case keyUp:
                    case autoKey:
                         if (event.what == keyUp)
                              evt.type = DIET_KEYRELEASE;
                         else
                              evt.type = DIET_KEYPRESS;

                         if (translate_key( event.message & (charCodeMask | keyCodeMask), &evt )) {
                              dfb_input_dispatch( data->device, &evt );
                         }

                         break;
                    case mouseDown:
                         evt.type = DIET_BUTTONPRESS;
                         evt.button = DIBI_LEFT;
                         dfb_input_dispatch( data->device, &evt );
                         break;
                    case mouseUp:
                         evt.type = DIET_BUTTONRELEASE;
                         evt.button = DIBI_LEFT;
                         dfb_input_dispatch( data->device, &evt );
                         break;
                    default:
                         printf("%d\n",event.what);
                         break;
               }

               fusion_skirmish_prevail( &dfb_osx->lock );
          }

          fusion_skirmish_dismiss( &dfb_osx->lock );

          usleep(10000);

          direct_thread_testcancel( thread );
     }

     return NULL;
}
Esempio n. 6
0
static void keyboard_cb(unsigned char modifiers, unsigned char key)
{
	char c;

	c = translate_key(modifiers, key);
	if(c != 0x00) {
		rx_buf[rx_produce] = c;
		rx_produce = (rx_produce + 1) & UKB_RINGBUFFER_MASK_RX;
	}
}
Esempio n. 7
0
gboolean tree_chroot(KeyBindingTree *tree, GList *keylist)
{
    guint key, state;
    translate_key(keylist->data, &state, &key);
    while (tree != NULL && !(tree->state == state && tree->key == key))
        tree = tree->next_sibling;
    if (tree != NULL) {
        if (keylist->next == NULL) {
            tree->chroot = TRUE;
            return TRUE;
        } else
            return tree_chroot(tree->first_child, keylist->next);
    }
    return FALSE;
}
Esempio n. 8
0
/*
 * Translates key and button events.
 */
static bool
key_event( const struct input_event *levt,
           DFBInputEvent            *devt )
{
     int code = levt->code;

     /* map touchscreen and smartpad events to button mouse */
     if (code == BTN_TOUCH || code == BTN_TOOL_FINGER)
          code = BTN_MOUSE;

     if ((code >= BTN_MOUSE && code < BTN_JOYSTICK) || code == BTN_TOUCH) {
          /* ignore repeat events for buttons */
          if (levt->value == 2)
               return false;

          devt->type   = levt->value ? DIET_BUTTONPRESS : DIET_BUTTONRELEASE;
          /* don't set DIEF_BUTTONS, it will be set by the input core */
          devt->button = DIBI_FIRST + code - BTN_MOUSE;
     }
     else {
          int key = translate_key( code );

          if (key == DIKI_UNKNOWN)
               return false;

          devt->type = levt->value ? DIET_KEYPRESS : DIET_KEYRELEASE;

          if (DFB_KEY_TYPE(key) == DIKT_IDENTIFIER) {
               devt->key_id = key;
               devt->flags |= DIEF_KEYID;
          }
          else {
               devt->key_symbol = key;
               devt->flags |= DIEF_KEYSYMBOL;
          }

          devt->flags |= DIEF_KEYCODE;
          devt->key_code = code;
     }

     if (levt->value == 2)
          devt->flags |= DIEF_REPEAT;

     return true;
}
Esempio n. 9
0
/**
 * User released key
 */
void Keymap_KeyUp(SDL_Keysym *sdlkey)
{
    Log_Printf(LOG_WARN, "Key released: %s\n", SDL_GetKeyName(sdlkey->sym));
    
    int symkey = sdlkey->sym;
	int modkey = sdlkey->mod;
    if (ShortCut_CheckKeys(modkey, symkey, 0))
		return;
    
    Uint8 keycode = translate_key(symkey);
#if NEW_MOD_HANDLING
    Uint8 modifiers = translate_modifiers(modkey);
#else
    Uint8 modifiers = modifier_keyup(symkey);
#endif
    
    Log_Printf(LOG_WARN, "Keycode: $%02x, Modkeys: $%02x\n", keycode, modifiers);
    
    kms_keyup(modifiers, keycode);
}
Esempio n. 10
0
/**
 * User pressed key down
 */
void Keymap_KeyDown(SDL_Keysym *sdlkey)
{
    Log_Printf(LOG_WARN, "Key pressed: %s\n", SDL_GetKeyName(sdlkey->sym));
    
    int symkey = sdlkey->sym;
	int modkey = sdlkey->mod;
    if (ShortCut_CheckKeys(modkey, symkey, 1)) {// Check if we pressed a shortcut
        ShortCut_ActKey();
        return;
    }
    Uint8 keycode = translate_key(symkey);
#if NEW_MOD_HANDLING
    Uint8 modifiers = translate_modifiers(modkey);
#else
    Uint8 modifiers = modifier_keydown(symkey);
#endif
    
    Log_Printf(LOG_WARN, "Keycode: $%02x, Modifiers: $%02x\n", keycode, modifiers);
    
    kms_keydown(modifiers, keycode);
}
Esempio n. 11
0
void cb_menu_key_down(Ewl_Widget *w, void *ev, void *data)
{
    Ewl_Widget *curwidget;
    char temp[50];
    Ewl_Event_Key_Down *e;
    e = (Ewl_Event_Key_Down*)ev;
    int k = translate_key(e);
    
    switch(k)
    {
    case 1:
        sprintf(temp,"menuitem1");
        curwidget=ewl_widget_name_find(temp);
        ewl_menu_cb_expand(curwidget,NULL,NULL);
        ewl_widget_focus_send(EWL_WIDGET(EWL_MENU(curwidget)->popup));
        int curpage=ewl_pdf_page_get(EWL_PDF(pdfwidget))+1;
        //sprintf(temp,"%d",curpage);
        ewl_text_text_set(EWL_TEXT(goto_entry),"");
        ewl_widget_focus_send(goto_entry);
        break;
    case 2:
        /*ewl_widget_hide(menu);
        opt_dlg_init();    
        ewl_window_transient_for(EWL_WINDOW(opt_dlg_widget_get()),EWL_WINDOW(win));
        ewl_widget_show(opt_dlg_widget_get());
        ewl_widget_focus_send(opt_dlg_widget_get());*/
        ewl_widget_hide(menu);
        OptionsDialog();
        
        break;
    case K_ESCAPE:
        ewl_widget_hide(menu);
        break;
    default:
        return;
    }
    
}
Esempio n. 12
0
//-----------------------------------------------------
void CNativeWrapper::onKeyPress(int keycode, int rawkeycode, int up, int flag, int unicode) {
	if (!m_term)
		return;
	debug_log("onKeyPress start");
	GF_Event evt;
	memset(&evt, 0, sizeof(GF_Event));
	if (up == 0) evt.type = GF_EVENT_KEYUP;
	else evt.type = GF_EVENT_KEYDOWN;

	evt.key.flags = 0;
	evt.key.hw_code = rawkeycode;

	translate_key(keycode, &evt.key);
	//evt.key.key_code = GF_KEY_A;
	int ret = gf_term_user_event(m_term, &evt);

	if (evt.type == GF_EVENT_KEYUP && unicode) {
		memset(&evt, 0, sizeof(GF_Event));
		evt.type = GF_EVENT_TEXTINPUT;
		evt.character.unicode_char = unicode;
		ret = gf_term_user_event(m_term, &evt);
	}
}
Esempio n. 13
0
KeyBindingTree *tree_build(GList *keylist)
{
    GList *it;
    KeyBindingTree *ret = NULL, *p;

    if (g_list_length(keylist) <= 0)
        return NULL; /* nothing in the list.. */

    for (it = g_list_last(keylist); it; it = g_list_previous(it)) {
        GList *kit;

        p = ret;
        ret = g_new0(KeyBindingTree, 1);

        for (kit = it; kit != NULL; kit = g_list_previous(kit))
            ret->keylist = g_list_prepend(ret->keylist,
                                          g_strdup(kit->data)); /* deep copy */
        ret->first_child = p;
        if (p != NULL) p->parent = ret;
        translate_key(it->data, &ret->state, &ret->key);
    }
    return ret;
}
// translates all special tokens in a message, producing the new finalized message to be displayed
void message_translate_tokens(char *buf, char *text)
{
	char temp[40], *toke1, *toke2, *ptr, *orig_buf;
	int r;

	orig_buf = buf;
	*buf = 0;
	toke1 = strchr(text, '$');
	toke2 = strchr(text, '#');
	while (toke1 || toke2) {  // is either token types present?
		if (!toke2 || (toke1 && (toke1 < toke2))) {  // found $ before #
			strncpy(buf, text, toke1 - text + 1);  // copy text up to token
			buf += toke1 - text + 1;
			text = toke1 + 1;  // advance pointers past processed data

			toke2 = strchr(text, '$');
			if (!toke2)  // No second one?
				break;

			strncpy(temp, text, toke2 - text);  // isolate token into seperate buffer
			temp[toke2 - text] = 0;  // null terminate string
			ptr = translate_key(temp);  // try and translate key
			if (ptr) {  // was key translated properly?
				if (!stricmp(ptr, NOX("none")) && (Training_bind_warning != Missiontime)) {
					if ( The_mission.game_type & MISSION_TYPE_TRAINING ) {
						r = popup(PF_TITLE_BIG | PF_TITLE_RED, 2, XSTR( "&Bind Control", 424), XSTR( "&Abort mission", 425),
							XSTR( "Warning\nYou have no control bound to the action \"%s\".  You must do so before you can continue with your training.", 426),
							XSTR(Control_config[Failed_key_index].text, CONTROL_CONFIG_XSTR + Failed_key_index));

						if (r) {  // do they want to abort the mission?
							gameseq_post_event(GS_EVENT_END_GAME);
							return;
						}

						gameseq_post_event(GS_EVENT_CONTROL_CONFIG);  // goto control config screen to bind the control
					}
				}

				buf--;  // erase the $
				strcpy(buf, ptr);  // put translated key in place of token
				buf += strlen(buf);
				text = toke2 + 1;
			}

		} else {
			strncpy(buf, text, toke2 - text + 1);  // copy text up to token
			buf += toke2 - text + 1;
			text = toke2 + 1;  // advance pointers past processed data

			toke1 = strchr(text, '#');
			if (toke1)  // No second one?
				break;

			strncpy(temp, text, toke1 - text);  // isolate token into seperate buffer
			temp[toke1 - text] = 0;  // null terminate string
			ptr = translate_msg_token(temp);  // try and translate key
			if (ptr) {  // was key translated properly?
				buf--;  // erase the #
				strcpy(buf, ptr);  // put translated key in place of token
				buf += strlen(buf);
				text = toke1 + 1;
			}
		}

		toke1 = strchr(text, '$');
		toke2 = strchr(text, '#');
	}

	strcpy(buf, text);
	return;
}
Esempio n. 15
0
int	main(int argc, char *argv[])
{

	tu_memdebug::open();

	{	// for testing memory leaks

		assert(tu_types_validate());

		const char* infile = NULL;

		float	exit_timeout = 0;
		bool	do_render = true;
		bool	do_sound = true;
		bool	do_loop = true;
		bool	sdl_abort = true;
		bool	sdl_cursor = true;
		float	tex_lod_bias;
		bool	force_realtime_framerate = false;

	#ifdef _WIN32

		WSADATA wsaData;

		int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );
		if ( iResult != NO_ERROR )
			printf("Error at WSAStartup()\n");
	#endif


		// -1.0 tends to look good.
		tex_lod_bias = -1.2f;
		tu_string flash_vars;

		int	width = 0;
		int	height = 0;

		gameswf::gc_ptr<gameswf::player> player = new gameswf::player();

		for (int arg = 1; arg < argc; arg++)
		{
			if (argv[arg][0] == '-')
			{
				// Looks like an option.

				if (argv[arg][1] == 'h')
				{
					// Help.
					print_usage();
					exit(1);
				}
				if (argv[arg][1] == 'u')
				{
					arg++;
					if (arg < argc)
					{
						flash_vars = argv[arg];
					}
					else
					{
						fprintf(stderr, "-u arg must be followed string like myvar=x&myvar2=y and so on\n");
						print_usage();
						exit(1);
					}

				}
				else if (argv[arg][1] == 'w')
				{
					arg++;
					if (arg < argc)
					{
						width = atoi(argv[arg]);
						const char* x = strstr(argv[arg], "x");
						if (x)
						{
							height = atoi(x + 1);
						}
					}

					if (width <=0 || height <= 0)
					{
						fprintf(stderr, "-w arg must be followed by the window size\n");
						print_usage();
						exit(1);
					}
				}
				else if (argv[arg][1] == 'c')
				{
					sdl_abort = false;
				}
                else if (argv[arg][1] == 'f')
                {
                    force_realtime_framerate = true;
                }
				else if (argv[arg][1] == 'k')
				{
					sdl_cursor = false;
				}
				else if (argv[arg][1] == 'a')
				{
					// Set antialiasing on or off.
					arg++;
					if (arg < argc)
					{
						s_aa_level = atoi(argv[arg]);
						s_antialiased = s_aa_level > 0 ? true : false;
					}
					else
					{
						fprintf(stderr, "-a arg must be followed by the antialiasing level\n");
						print_usage();
						exit(1);
					}
				}
				else if (argv[arg][1] == 'b')
				{
					// Set default bit depth.
					arg++;
					if (arg < argc)
					{
						s_bit_depth = atoi(argv[arg]);
						if (s_bit_depth != 16 && s_bit_depth != 24 && s_bit_depth != 32)
						{
							fprintf(stderr, "Command-line supplied bit depth %d, but it must be 16, 24 or 32", s_bit_depth);
							print_usage();
							exit(1);
						}
					}
					else
					{
						fprintf(stderr, "-b arg must be followed by 16 or 32 to set bit depth\n");
						print_usage();
						exit(1);
					}
				}
				else if (argv[arg][1] == 'd')
				{
					// Set a delay
					arg++;
					if (arg < argc)
					{
						s_delay = atoi(argv[arg]);
					}
					else
					{
						fprintf(stderr, "-d arg must be followed by number of milli-seconds to del in the main loop\n");
						print_usage();
						exit(1);
					}
				}
				else if (argv[arg][1] == 'p')
				{
					// Enable frame-rate/performance logging.
					s_measure_performance = true;
				}
				else if (argv[arg][1] == '1')
				{
					// Play once; don't loop.
					do_loop = false;
				}
				else if (argv[arg][1] == 'r')
				{
					// Set rendering on/off.
					arg++;
					if (arg < argc)
					{
						const int render_arg = atoi(argv[arg]);
						switch (render_arg) {
						case 0:
							// Disable both
							do_render = false;
							do_sound = false;
							break;
						case 1:
							// Enable both
							do_render = true;
							do_sound = true;
							break;
						case 2:
							// Disable just sound
							do_render = true;
							do_sound = false;
							break;
						default:
							fprintf(stderr, "-r must be followed by 0, 1 or 2 (%d is invalid)\n",
								render_arg);
							print_usage();
							exit(1);
							break;
						}
					} else {
						fprintf(stderr, "-r must be followed by 0 an argument to disable/enable rendering\n");
						print_usage();
						exit(1);
					}
				}
				else if (argv[arg][1] == 't')
				{
					// Set timeout.
					arg++;
					if (arg < argc)
					{
						exit_timeout = (float) atof(argv[arg]);
					}
					else
					{
						fprintf(stderr, "-t must be followed by an exit timeout, in seconds\n");
						print_usage();
						exit(1);
					}
				}
				else if (argv[arg][1] == 'v')
				{
					// Be verbose; i.e. print log messages to stdout.
					if (argv[arg][2] == 'a')
					{
						// Enable spew re: action.
						player->verbose_action(true);
					}
					else if (argv[arg][2] == 'p')
					{
						// Enable parse spew.
						player->verbose_parse(true);
					}
					// ...
				}
				else if (argv[arg][1] == 'm')
				{
					if (argv[arg][2] == 'l') {
						arg++;
						tex_lod_bias = (float) atof(argv[arg]);
						//printf("Texture LOD Bais is no %f\n", tex_lod_bias);
					}
					else
					{
						fprintf(stderr, "unknown variant of -m arg\n");
						print_usage();
						exit(1);
					}
				}
				else if (argv[arg][1] == 'n')
				{
					s_allow_http = true;
				}
				else if (argv[arg][1] == 'i')
				{
					player->set_separate_thread(false);
					player->set_log_bitmap_info(true);
				}
			}
			else
			{
				infile = argv[arg];
			}
		}

		if (infile == NULL)
		{
			printf("no input file\n");
			print_usage();
			exit(1);
		}

		//
		if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
		{
			fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
			exit(1);
		}
		atexit(SDL_Quit);
		
		//Use OpenGL 2.1
		SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 2 );
		SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 );

		// Set the video mode.
//				if (SDL_SetVideoMode(width, height, s_bit_depth, SDL_OPENGL | SDL_RESIZABLE) == 0)
		//if (SDL_SetVideoMode(width, height, s_bit_depth, SDL_OPENGL) == 0)
		window = SDL_CreateWindow("TestSWF",
											  SDL_WINDOWPOS_CENTERED,
								  			  SDL_WINDOWPOS_CENTERED,
											  512,
											  512,
											  SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN);
		if(!window)
		{
			fprintf(stderr, "SDL_CreateWindow() failed. %s", SDL_GetError());
			exit(1);
		}
		gContext = SDL_GL_CreateContext(window);
		if( gContext == NULL )
		{
			fprintf(stderr, "OpenGL context could not be created! SDL Error: %s\n", SDL_GetError() );
			exit(1);
		}
		//Use Vsync
		if( SDL_GL_SetSwapInterval( 1 ) < 0 )
		{
			fprintf(stderr, "Warning: Unable to set VSync! SDL Error: %s\n", SDL_GetError() );
		}

		SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0);
		if(!renderer)
		{
			fprintf(stderr, "SDL_CreateRenderer() failed. %s", SDL_GetError());
			exit(1);
		}

		//SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
		//SDL_RenderClear(renderer);
		//SDL_RenderPresent(renderer);

		//
		player->set_force_realtime_framerate(force_realtime_framerate);

		// use this for multifile games
		// workdir is used when LoadMovie("myfile.swf", _root) is called
		{
			tu_string workdir;
			// Find last slash or backslash.
 			const char* ptr = infile + strlen(infile);
			for (; ptr >= infile && *ptr != '/' && *ptr != '\\'; ptr--) {}
			// Use everything up to last slash as the "workdir".
			int len = ptr - infile + 1;
			if (len > 0)
			{
				tu_string workdir(infile, len);
				player->set_workdir(workdir.c_str());
			}
		}

		gameswf::register_file_opener_callback(file_opener);
		gameswf::register_fscommand_callback(fs_callback);
		if (gameswf::get_verbose_parse())
		{
			gameswf::register_log_callback(log_callback);
		}
		
		gameswf::sound_handler*	sound = NULL;
		gameswf::render_handler*	render = NULL;
		if (do_render)
		{
			if (do_sound)
			{

#ifdef TU_USE_SDL
				sound = gameswf::create_sound_handler_sdl();
#endif

#ifdef TU_USE_OPENAL
				sound = gameswf::create_sound_handler_openal();
#endif

				gameswf::set_sound_handler(sound);
			}

#ifdef TU_USE_SDL
			render = gameswf::create_render_handler_ogl();
			gameswf::set_render_handler(render);
#endif

#ifdef TU_USE_OGLES
			render = gameswf::create_render_handler_ogles();
			gameswf::set_render_handler(render);
#endif

#if TU_CONFIG_LINK_TO_FREETYPE == 1
			gameswf::set_glyph_provider(gameswf::create_glyph_provider_freetype());
#else
			gameswf::set_glyph_provider(gameswf::create_glyph_provider_tu());
#endif
		}

		//
		//	set_proxy("192.168.1.201", 8080);
		//

		// gameswf::set_use_cache_files(true);

		player->set_flash_vars(flash_vars);
		{
			gameswf::gc_ptr<gameswf::root>	m = player->load_file(infile);
			if (m == NULL)
			{
				exit(1);
			}

			if (width == 0 || height == 0)
			{
				width = m->get_movie_width();
				height = m->get_movie_height();
			}
			float scale_x = (float) width / m->get_movie_width();
			float scale_y = (float) height / m->get_movie_height();

			float	movie_fps = m->get_movie_fps();

			if (do_render)
			{
				// Initialize the SDL subsystems we're using. Linux
				// and Darwin use Pthreads for SDL threads, Win32
				// doesn't. Otherwise the SDL event loop just polls.
				//if (sdl_abort)
				//{
				//	//  Other flags are SDL_INIT_JOYSTICK | SDL_INIT_CDROM
				//	//#ifdef _WIN32
				//	//if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO))
				//	//#else
				//	//if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_EVENTTHREAD ))
				//	if (SDL_Init(SDL_INIT_EVERYTHING))
				//		//#endif
				//	{
				//		fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
				//		exit(1);
				//	}
				//}
				//else
				//{
				//	fprintf(stderr, "warning: SDL won't trap core dumps \n");
				//	//#ifdef _WIN32
				//	//if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE  | SDL_INIT_EVENTTHREAD))
				//	//#else
				//	//if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE))
				//		//#endif
				//	if (SDL_Init(SDL_INIT_EVERYTHING))
				//	{
				//		fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
				//		exit(1);
				//	}
				//}

				//atexit(SDL_Quit);

				//SDL_EnableKeyRepeat(250, 33);
				//event.key.repeat
				SDL_ShowCursor(sdl_cursor ? SDL_ENABLE : SDL_DISABLE);

				switch (s_bit_depth)
				{
					case 16:
						// 16-bit color, surface creation is likely to succeed.
						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, 15);
						SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
						SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 5);
						break;

					case 24:
						// 24-bit color
						//	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
						//	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
						//	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
						//	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
						//	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
						SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
						SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);
						break;

					case 32:
						// 32-bit color etc, for getting dest alpha,
						// for MULTIPASS_ANTIALIASING (see gameswf_render_handler_ogl.cpp).
						SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
						SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
						SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
						SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
						SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
						SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
						SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
						break;

					default:
						assert(0);
				}

				// try to enable FSAA
				if (s_aa_level > 1)
				{
					SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
					SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, s_aa_level);
				}

				// Change the LOD BIAS values to tweak blurriness.
				if (tex_lod_bias != 0.0f) {
	#ifdef FIX_I810_LOD_BIAS	
					// If 2D textures weren't previously enabled, enable
					// them now and force the driver to notice the update,
					// then disable them again.
					if (!glIsEnabled(GL_TEXTURE_2D)) {
						// Clearing a mask of zero *should* have no
						// side effects, but coupled with enbling
						// GL_TEXTURE_2D it works around a segmentation
						// fault in the driver for the Intel 810 chip.
						glEnable(GL_TEXTURE_2D);
						glClear(0);
						glDisable(GL_TEXTURE_2D);
					}
	#endif // FIX_I810_LOD_BIAS
					glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, tex_lod_bias);
				}
				
				render->open();
				render->set_antialiased(s_antialiased);

				// Turn on alpha blending.
				glEnable(GL_BLEND);
				glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

				// Turn on line smoothing.  Antialiased lines can be used to
				// smooth the outsides of shapes.
				glEnable(GL_LINE_SMOOTH);
				glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);	// GL_NICEST, GL_FASTEST, GL_DONT_CARE

				glMatrixMode(GL_PROJECTION);
				glOrtho(-OVERSIZE, OVERSIZE, OVERSIZE, -OVERSIZE, -1, 1);
				glMatrixMode(GL_MODELVIEW);
				glLoadIdentity();

				// We don't need lighting effects
				glDisable(GL_LIGHTING);
				// glColorPointer(4, GL_UNSIGNED_BYTE, 0, *);
				// glInterleavedArrays(GL_T2F_N3F_V3F, 0, *)
				glPushAttrib (GL_ALL_ATTRIB_BITS);		
			}

			// Set Title
			//SDL_WM_SetCaption("TestSWF", NULL);

			// Mouse state.
			int	mouse_x = 0;
			int	mouse_y = 0;
			int	mouse_buttons = 0;

			float	speed_scale = 1.0f;
			Uint32	start_ticks = 0;
			if (do_render)
			{
				start_ticks = tu_timer::get_ticks();
			}
			Uint32	last_ticks = start_ticks;
			int	frame_counter = 0;
			int	last_logged_fps = last_ticks;
			int fps = 0;

			//TODO
	//		gameswf::player* p = gameswf::create_player();
	//		p.run();


			for (;;)
			{
				Uint32	ticks;
				if (do_render)
				{
					ticks = tu_timer::get_ticks();
				}
				else
				{
					// Simulate time.
					ticks = last_ticks + (Uint32) (1000.0f / movie_fps);
				}
				int	delta_ticks = ticks - last_ticks;
				float	delta_t = delta_ticks / 1000.f;
				last_ticks = ticks;

				// Check auto timeout counter.
				if (exit_timeout > 0
					&& ticks - start_ticks > (Uint32) (exit_timeout * 1000))
				{
					// Auto exit now.
					break;
				}

				bool ret = true;
				if (do_render)
				{
					SDL_Event	event;
					// Handle input.
					while (ret)
					{
						if (SDL_PollEvent(&event) == 0)
						{
							break;
						}

						//printf("EVENT Type is %d\n", event.type);
						switch (event.type)
						{
							//case SDL_VIDEORESIZE:
							//	TODO
							//					s_scale = (float) event.resize.w / (float) width;
							//					width = event.resize.w;
							//					height = event.resize.h;
							//					if (SDL_SetVideoMode(event.resize.w, event.resize.h, 0, SDL_OPENGL | SDL_RESIZABLE) == 0)
							//					{
							//						fprintf(stderr, "SDL_SetVideoMode() failed.");
							//						exit(1);
							//					}
							//					glOrtho(-OVERSIZE, OVERSIZE, OVERSIZE, -OVERSIZE, -1, 1);
							//break;

						case SDL_USEREVENT:
							//printf("SDL_USER_EVENT at %s, code %d%d\n", __FUNCTION__, __LINE__, event.user.code);
							ret = false;
							break;
						case SDL_KEYDOWN:
							{
								SDL_Keycode	key = event.key.keysym.sym;
								bool	ctrl = (event.key.keysym.mod & KMOD_CTRL) != 0;

								if (key == SDLK_ESCAPE
									|| (ctrl && key == SDLK_q)
									|| (ctrl && key == SDLK_w))
								{
									goto done;
								}
								else if (ctrl && key == SDLK_p)
								{
									// Toggle paused state.
									if (m->get_play_state() == gameswf::character::STOP)
									{
										m->set_play_state(gameswf::character::PLAY);
									}
									else
									{
										m->set_play_state(gameswf::character::STOP);
									}
								}
								else if (ctrl && key == SDLK_i)
								{
									// Init library, for detection of memory leaks (for testing purposes)
	/*
									// Clean up gameswf as much as possible, so valgrind will help find actual leaks.

									gameswf::set_sound_handler(NULL);
									delete sound;

									gameswf::set_render_handler(NULL);
									delete render;

									if (do_render)
									{
										if (do_sound)
										{
											sound = gameswf::create_sound_handler_sdl();
											gameswf::set_sound_handler(sound);
										}
										render = gameswf::create_render_handler_ogl();
										gameswf::set_render_handler(render);
									}
	*/
									// Load the actual movie.
									m = player->load_file(infile);
									if (m == NULL)
									{
										exit(1);
									}
								}
								else if (ctrl && (key == SDLK_LEFTBRACKET || key == SDLK_KP_MINUS))
								{
									m->goto_frame(m->get_current_frame()-1);
								}
								else if (ctrl && (key == SDLK_RIGHTBRACKET || key == SDLK_KP_PLUS))
								{
									m->goto_frame(m->get_current_frame()+1);
								}
								else if (ctrl && key == SDLK_a)
								{
									// Toggle antialiasing.
									s_antialiased = !s_antialiased;
									if (render)
									{
										render->set_antialiased(s_antialiased);
									}
								}
								else if (ctrl && key == SDLK_t)
								{
									// test text replacement / variable setting:
									m->set_variable("test.text", "set_edit_text was here...\nanother line of text for you to see in the text box");
								}
								else if (ctrl && key == SDLK_g)
								{
									// test get_variable.
									message_log("testing get_variable: '");
									message_log(m->get_variable("test.text"));
									message_log("'\n");
								}
								else if (ctrl && key == SDLK_m)
								{
									// Test call_method.
									const char* result = m->call_method(
										"test_call",
										"%d, %f, %s, %ls",
										200,
										1.0f,
										"Test string",
										L"Test long string");

									if (result)
									{
										message_log("call_method: result = ");
										message_log(result);
										message_log("\n");
									}
									else
									{
										message_log("call_method: null result\n");
									}
								}
								else if (ctrl && key == SDLK_b)
								{
									// toggle background color.
									s_background = !s_background;
								}
	//							else if (ctrl && key == SDLK_f)	//xxxxxx
	//							{
	//								extern bool gameswf_debug_show_paths;
	//								gameswf_debug_show_paths = !gameswf_debug_show_paths;
	//							}
								else if (ctrl && key == SDLK_EQUALS)
								{
									float	f = gameswf::get_curve_max_pixel_error();
									f *= 1.1f;
									gameswf::set_curve_max_pixel_error(f);
									printf("curve error tolerance = %f\n", f);
								}
								else if (ctrl && key == SDLK_MINUS)
								{
									float	f = gameswf::get_curve_max_pixel_error();
									f *= 0.9f;
									gameswf::set_curve_max_pixel_error(f);
									printf("curve error tolerance = %f\n", f);
								} else if (ctrl && key == SDLK_F2) {
									// Toggle wireframe.
									static bool wireframe_mode = false;
									wireframe_mode = !wireframe_mode;
									if (wireframe_mode) {
										glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
									} else {
										glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
									}
									// TODO: clean up this interafce and re-enable.
									// 					} else if (ctrl && key == SDLK_d) {
									// 						// Flip a special debug flag.
									// 						gameswf_tesselate_dump_shape = true;
								}

								gameswf::key::code c = translate_key(key);
								if (c != gameswf::key::INVALID)
								{
									player->notify_key_event(c, true);
								}

								break;
							}

						case SDL_KEYUP:
							{
								SDL_Keycode	key = event.key.keysym.sym;

								gameswf::key::code c = translate_key(key);
								if (c != gameswf::key::INVALID)
								{
									player->notify_key_event(c, false);
								}

								break;
							}

						case SDL_MOUSEMOTION:
							mouse_x = (int) (event.motion.x / scale_x);
							mouse_y = (int) (event.motion.y / scale_y);
							break;

						case SDL_MOUSEBUTTONDOWN:
						case SDL_MOUSEBUTTONUP:
							{
								int	mask = 1 << (event.button.button - 1);
								if (event.button.state == SDL_PRESSED)
								{
									mouse_buttons |= mask;
								}
								else
								{
									mouse_buttons &= ~mask;
								}
								break;
							}

						case SDL_QUIT:
							goto done;
							break;

						default:
							break;
						}
					}
				}

				if (do_render)
				{
					glDisable(GL_DEPTH_TEST);	// Disable depth testing.
					glDrawBuffer(GL_BACK);
				}

				renderTest();
				//m = player->get_root();
				//m->set_display_viewport(0, 0, width, height);
				//m->set_background_alpha(s_background ? 1.0f : 0.05f);
				//
				//m->notify_mouse_state(mouse_x, mouse_y, mouse_buttons);
				//
				//Uint32 t_advance = tu_timer::get_ticks();
				//m->advance(delta_t * speed_scale);
				//t_advance = tu_timer::get_ticks() - t_advance;
				//
				//if (do_sound && sound)
				//{
				//	sound->advance(delta_t * speed_scale);
				//}
				//
				Uint32 t_display = tu_timer::get_ticks();
				m->display();
				t_display = tu_timer::get_ticks() - t_display;

				if (do_render)
				{
					Uint32 t_swap = tu_timer::get_ticks();
					//SDL_GL_SwapBuffers();
					SDL_GL_SwapWindow(window);
					t_swap = tu_timer::get_ticks() - t_swap;
					//glPopAttrib ();


					frame_counter++;

					// Log the frame rate every second or so.
					if (last_ticks - last_logged_fps > 1000)
					{
						float	delta = (last_ticks - last_logged_fps) / 1000.f;
						fps = (int) ((float) frame_counter / delta);
						last_logged_fps = last_ticks;
						frame_counter = 0;
					}

					if (s_measure_performance == false)
					{
						// Don't hog the CPU.
						SDL_Delay(s_delay);
					}
					else
					{
						printf("fps = %d\n", fps);
					}

					// for perfomance testing
//					printf("advance time: %d, display time %d, swap buffers time = %d\n",
//						t_advance, t_display, t_swap);

#ifdef HAVE_PERFOMANCE_INFO
					char buffer[8];
					snprintf(buffer, 8, "%03d", t_advance);
					m->set_variable("t_Advance", buffer);
					snprintf(buffer, 8, "%03d", t_display);
					m->set_variable("t_Display", buffer);
					snprintf(buffer, 8, "%03d", t_swap);
					m->set_variable("t_SwapBuffers", buffer);
					snprintf(buffer, 8, "%d", fps);
					m->set_variable("FPS", buffer);
#endif
				}

				// TODO: clean up this interface and re-enable.
				//		gameswf_tesselate_dump_shape = false;  ///xxxxx

				// See if we should exit.
				if (do_loop == false && m->get_current_frame() + 1 == m->get_frame_count())
				{
					// We're reached the end of the movie; exit.
					break;
				}
			}

	done:


			gameswf::set_sound_handler(NULL);
			delete sound;

			gameswf::set_render_handler(NULL);
			delete render;

			SDL_Quit();
		}

	}	// for testing memory leaks

	tu_memdebug::close();
	return 0;
}
Esempio n. 16
0
// ---------------------------------------------------------------------------
void X11WindowImpl::processEvent(XEvent& ev)
{
  char   keybuffer[8];
  KeySym keysym;
  XComposeStatus compose;
  int    count, keycode;
  ::Window root, child;
  int    rootx, rooty, winx, winy;
  unsigned int  mask;
  
  switch(ev.type) {
    case ButtonPress:
      switch(ev.xbutton.button) {
        case 1:
          if (window)
            window->buttonPress( GUI_ButtonLeft, ev.xbutton.x, ev.xbutton.y );
          break;
        case 2:
          if (window)
            window->buttonPress( GUI_ButtonMiddle, ev.xbutton.x, ev.xbutton.y );
          break;
        case 3:
          if (window)
            window->buttonPress( GUI_ButtonRight, ev.xbutton.x, ev.xbutton.y );
          break;
        case 4:
          if (window)
            window->wheelRotate( GUI_WheelForward );
          break;
        case 5:
          if (window)
            window->wheelRotate( GUI_WheelBackward );
          break;
      }
      break;
    case ButtonRelease:
      switch(ev.xbutton.button) {
        case 1:
          if (window)
            window->buttonRelease( GUI_ButtonLeft, ev.xbutton.x, ev.xbutton.y );
          break;
        case 2:
          if (window)
            window->buttonRelease( GUI_ButtonMiddle, ev.xbutton.x, ev.xbutton.y );
          break;
        case 3:
          if (window)
            window->buttonRelease( GUI_ButtonRight, ev.xbutton.x, ev.xbutton.y );
          break;
      }
      break;
    case KeyPress:
      count = XLookupString(&ev.xkey, keybuffer, sizeof(keybuffer), &keysym, &compose);
      keycode = translate_key(keysym);
      if (keycode)
        if (window)
          window->keyPress(keycode);
      break;
    case KeyRelease:
      count = XLookupString(&ev.xkey, keybuffer, sizeof(keybuffer), &keysym, &compose);
      keycode = translate_key(keysym);
      if (keycode)
        if (window)
          window->keyRelease(keycode);
      break;
    case MappingNotify:
      XRefreshKeyboardMapping(&ev.xmapping);
      break;
    case MotionNotify:
      if( XQueryPointer(factory->xdisplay, xwindow, &root, &child, &rootx, &rooty, &winx, &winy, &mask) == True )
        if (window)
          window->mouseMove( winx, winy );
      break;
    case Expose:
      if (ev.xexpose.count == 0) {
        if (window) {
          if (window->skipRedraw) break;
          window->paint();
        }  
        swap();
      }
      break;
    case ConfigureNotify:
      if (window)
        window->resize( ev.xconfigure.width, ev.xconfigure.height );
      break;
    case MapNotify:
      if (window)
        window->show();
      break;
    case UnmapNotify:
      if (window)
        window->hide();
      break;
    case ClientMessage:
      if ( ( (::Atom) ev.xclient.data.l[0] ) == factory->atoms[GUI_X11_ATOM_WM_DELETE])
        if (window)
          window->on_close();
      break;
    case DestroyNotify:
      factory->notifyDelete(xwindow);
      xwindow = 0;
      if (window)
        window->notifyDestroy();
      delete this;
      break;
  }
}
Esempio n. 17
0
static int xlib_handle_event()
{
    XEvent event;
    int num_handled_events = 0;

    while(XCheckMaskEvent(glwt.x11.display, ~0, &event) ||
        XCheckTypedEvent(glwt.x11.display, ClientMessage, &event))
    {
        ++num_handled_events;

        GLWTWindow *win = 0;
        if(XFindContext(
                glwt.x11.display,
                event.xany.window,
                glwt.x11.xcontext,
                (XPointer*)&win) != 0)
            continue;

        switch(event.type)
        {
            case ConfigureNotify:
                if(win->win_callback)
                {
                    GLWTWindowEvent e;
                    e.window = win;
                    e.type = GLWT_WINDOW_RESIZE;
                    e.resize.width = event.xconfigure.width;
                    e.resize.height = event.xconfigure.height;
                    win->win_callback(win, &e, win->userdata);
                }
                break;
            case MapNotify:
            case UnmapNotify:
                if(win->win_callback)
                {
                    GLWTWindowEvent e;
                    e.window = win;
                    e.type = event.type == MapNotify ? GLWT_WINDOW_SHOW : GLWT_WINDOW_HIDE;
                    e.dummy.dummy  = 0;
                    win->win_callback(win, &e, win->userdata);
                }
                break;
            case Expose:
                if(win->win_callback)
                {
                    GLWTWindowEvent e;
                    e.window = win;
                    e.type = GLWT_WINDOW_EXPOSE;
                    e.dummy.dummy = 0;
                    win->win_callback(win, &e, win->userdata);
                }
                break;
            case KeyPress:
            case KeyRelease:
                if(win->win_callback)
                {
                    GLWTWindowEvent e;
                    e.window = win;
                    e.type = event.type == KeyPress ? GLWT_WINDOW_KEY_DOWN : GLWT_WINDOW_KEY_UP;
                    e.key.keysym = translate_key(XkbKeycodeToKeysym(glwt.x11.display, event.xkey.keycode, 0, 0));
                    e.key.scancode = event.xkey.keycode;
                    e.key.mod = mapKeyMod(event.xkey.state);
                    win->win_callback(win, &e, win->userdata);
                }
                break;
            case FocusIn:
            case FocusOut:
                if(win->win_callback)
                {
                    GLWTWindowEvent e;
                    e.window = win;
                    e.type = event.type == FocusIn ? GLWT_WINDOW_FOCUS_IN : GLWT_WINDOW_FOCUS_OUT;
                    e.dummy.dummy = 0;
                    win->win_callback(win, &e, win->userdata);
                }
                break;
            case ButtonPress:
            case ButtonRelease:
                if(win->win_callback)
                {
                    GLWTWindowEvent e;
                    e.window = win;
                    e.type = event.type == ButtonPress ? GLWT_WINDOW_BUTTON_DOWN : GLWT_WINDOW_BUTTON_UP;
                    e.button.x = event.xbutton.x;
                    e.button.y = event.xbutton.y;
                    e.button.button = event.xbutton.button; // todo: make these consistent on different platforms
                    e.button.mod = mapKeyMod(event.xbutton.state);
                    win->win_callback(win, &e, win->userdata);
                }
                break;
            case MotionNotify:
                if(win->win_callback)
                {
                    GLWTWindowEvent e;
                    e.window = win;
                    e.type = GLWT_WINDOW_MOUSE_MOTION;
                    e.motion.x = event.xmotion.x;
                    e.motion.y = event.xmotion.y;
                    e.motion.buttons = mapButtons(event.xmotion.state);
                    win->win_callback(win, &e, win->userdata);
                }
                break;
            case EnterNotify:
            case LeaveNotify:
                if(win->win_callback)
                {
                    GLWTWindowEvent e;
                    e.window = win;
                    e.type = event.type == EnterNotify ? GLWT_WINDOW_MOUSE_ENTER : GLWT_WINDOW_MOUSE_LEAVE;
                    e.dummy.dummy = 0;
                    win->win_callback(win, &e, win->userdata);
                }
                break;
            case ClientMessage:
                if((Atom)event.xclient.data.l[0] == glwt.x11.atoms.WM_DELETE_WINDOW)
                {
                    win->closed = 1;

                    if(win->win_callback)
                    {
                        GLWTWindowEvent e;
                        e.window = win;
                        e.type = GLWT_WINDOW_CLOSE;
                        e.dummy.dummy = 0;
                        win->win_callback(win, &e, win->userdata);
                    }
                } else if((Atom)event.xclient.data.l[0] == glwt.x11.atoms._NET_WM_PING)
                {
                    event.xclient.window = RootWindow(glwt.x11.display, glwt.x11.screen_num);
                    XSendEvent(
                        glwt.x11.display,
                        event.xclient.window,
                        False,
                       SubstructureNotifyMask | SubstructureRedirectMask,
                       &event);
                }
                break;
            default:
                break;
        }
    }

    return num_handled_events;
}
Esempio n. 18
0
void cb_key_down(Ewl_Widget *w, void *ev, void *data)
{
    Ewl_Widget *curwidget;
    Ewl_Event_Key_Down *e;
    e = (Ewl_Event_Key_Down*)ev;
    int k = translate_key(e);
    
    curwidget=ewl_widget_name_find("pdfwidget");
    switch(k)
    {
    case 0:
        ewl_pdf_page_next(EWL_PDF(curwidget));
        resize_and_rescale(curscale);
        fprintf(stderr,"l:%d; r:%d; t:%d; b:%d\n",get_left_margin(),get_right_margin(),get_top_margin(),get_bottom_margin());
        //update_statusbar();
        break;
    case 9:
        ewl_pdf_page_previous(EWL_PDF(curwidget));
        resize_and_rescale(curscale);
        //update_statusbar();
        break;
    case 8:
        curscale+=((double)get_settings()->zoominc)/100.0;
        resize_and_rescale(curscale);
        //update_statusbar();
        break;
    case 7:
        curscale-=((double)get_settings()->zoominc)/100.0;
        resize_and_rescale(curscale);
        //update_statusbar();
        break;
    /*case 6:
        if(ewl_pdf_orientation_get(EWL_PDF(curwidget))==EPDF_PAGE_ORIENTATION_LANDSCAPE)
            ewl_pdf_orientation_set(EWL_PDF(curwidget),EPDF_PAGE_ORIENTATION_PORTRAIT);
        else
            ewl_pdf_orientation_set(EWL_PDF(curwidget),EPDF_PAGE_ORIENTATION_LANDSCAPE);
        resize_and_rescale(curscale);
        //update_statusbar();
        break;*/
    case 1:
        move_hscrollbar(EWL_SCROLLPANE(scrollpane), -get_horizontal_pan_inc());
        break;
    case 2:
        move_hscrollbar(EWL_SCROLLPANE(scrollpane), get_horizontal_pan_inc());
        break;
    case 3:
        move_vscrollbar(EWL_SCROLLPANE(scrollpane), get_vertical_pan_inc());
        break;    
    case 4:
        move_vscrollbar(EWL_SCROLLPANE(scrollpane), -get_vertical_pan_inc());
        break;
    case 5:
        if(fitmode==0)
            fitmode=1;
        else if(fitmode==1)
            fitmode=0;
        calculate_margins();
        resize_and_rescale(curscale);
        break;
    case K_RETURN:
        ewl_widget_show(menu);
        ewl_widget_focus_send(menu);
        break;
    case K_ESCAPE:
        ewl_main_quit();
        break;
    default:
        return;
    }
    
    
    
}
Esempio n. 19
0
LRESULT CALLBACK glwtWin32WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    GLWTWindow *win = (GLWTWindow*)GetWindowLongPtr(hwnd, 0);

    if(win)
    {
        switch(uMsg)
        {
            case WM_PAINT:
                if(win->win_callback)
                {
                    GLWTWindowEvent event;
                    event.window = win;
                    event.type = GLWT_WINDOW_EXPOSE;
                    event.dummy.dummy = 0;
                    win->win_callback(win, &event, win->userdata);
                }

                ValidateRect(hwnd, NULL);
                return 0;

            case WM_KEYUP:
            case WM_KEYDOWN:
            case WM_SYSKEYUP:
            case WM_SYSKEYDOWN:
                if(win->win_callback)
                {
                    GLWTWindowEvent event;
                    event.window = win;
                    event.type = (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN) ? GLWT_WINDOW_KEY_DOWN : GLWT_WINDOW_KEY_UP;
                    event.key.keysym = translate_key(wParam, lParam);
                    event.key.scancode = (lParam >> 16) & 0xff;
                    event.key.mod = GetModifiers();
                    win->win_callback(win, &event, win->userdata);
                }

                if(uMsg == WM_SYSKEYUP || uMsg == WM_SYSKEYDOWN)
                    break;
                return 0;

            case WM_LBUTTONUP:
            case WM_LBUTTONDOWN:
            case WM_MBUTTONUP:
            case WM_MBUTTONDOWN:
            case WM_RBUTTONUP:
            case WM_RBUTTONDOWN:
            case WM_XBUTTONUP:
            case WM_XBUTTONDOWN:
            case WM_MOUSEWHEEL:
            case WM_MOUSEHWHEEL:
                if(win->win_callback)
                {
                    GLWTWindowEvent event;

                    event.window = win;
                    event.type = (
                        uMsg == WM_LBUTTONUP ||
                        uMsg == WM_MBUTTONUP ||
                        uMsg == WM_RBUTTONUP ||
                        uMsg == WM_XBUTTONUP ||
                        uMsg == WM_MOUSEWHEEL ||
                        uMsg == WM_MOUSEHWHEEL
                        ) ? GLWT_WINDOW_BUTTON_DOWN : GLWT_WINDOW_BUTTON_UP;
                    event.button.x = LOWORD(lParam);
                    event.button.y = HIWORD(lParam);
                    event.button.button =
                        (uMsg == WM_LBUTTONUP || uMsg == WM_LBUTTONDOWN) ? 0 :
                        (uMsg == WM_MBUTTONUP || uMsg == WM_MBUTTONDOWN) ? 1 :
                        (uMsg == WM_RBUTTONUP || uMsg == WM_RBUTTONDOWN) ? 2 :
                        (uMsg == WM_XBUTTONUP || uMsg == WM_XBUTTONDOWN) ? (HIWORD(wParam) == XBUTTON1 ? 5 : 6) :
                        (uMsg == WM_MOUSEWHEEL) ? (GET_WHEEL_DELTA_WPARAM(wParam) < 0 ? 3 : 4) :
                        (uMsg == WM_MOUSEHWHEEL) ? (GET_WHEEL_DELTA_WPARAM(wParam) < 0 ? 7 : 8) :
                        0;

                    event.button.mod = GetModifiers();
                    win->win_callback(win, &event, win->userdata);
                }

                return 0;

            case WM_MOUSEMOVE:
                if(win->win_callback)
                {
                    GLWTWindowEvent event;

                    event.window = win;
                    event.type = GLWT_WINDOW_MOUSE_MOTION;
                    event.motion.x = GET_X_LPARAM(lParam);
                    event.motion.y = GET_Y_LPARAM(lParam);
                    event.motion.buttons  =
                        (wParam & MK_LBUTTON  ? (1 << 0) : 0) |
                        (wParam & MK_RBUTTON  ? (1 << 1) : 0) |
                        (wParam & MK_MBUTTON  ? (1 << 2) : 0) |
                        (wParam & MK_XBUTTON1 ? (1 << 5) : 0) |
                        (wParam & MK_XBUTTON2 ? (1 << 6) : 0);
                    win->win_callback(win, &event, win->userdata);
                }

                {
                    TRACKMOUSEEVENT tme;
                    tme.cbSize = sizeof(tme);
                    tme.dwFlags = TME_QUERY;
                    tme.hwndTrack = hwnd;
                    TrackMouseEvent(&tme);

                    if(tme.dwFlags != TME_LEAVE)
                    {
                        tme.cbSize = sizeof(tme);
                        tme.dwFlags = TME_HOVER|TME_LEAVE;
                        tme.hwndTrack = hwnd;
                        tme.dwHoverTime = 1;
                        TrackMouseEvent(&tme);
                    }
                }

                return 0;

            case WM_SETFOCUS:
            case WM_KILLFOCUS:
                if(win->win_callback)
                {
                    GLWTWindowEvent event;
                    event.window = win;
                    event.type = uMsg == WM_SETFOCUS ? GLWT_WINDOW_FOCUS_IN : GLWT_WINDOW_FOCUS_OUT;
                    event.dummy.dummy = 0;
                    win->win_callback(win, &event, win->userdata);
                }

                return 0;

            case WM_MOUSEHOVER:
            case WM_MOUSELEAVE:
                if(win->win_callback)
                {
                    GLWTWindowEvent event;
                    event.window = win;
                    event.type = (uMsg == WM_MOUSEHOVER ? GLWT_WINDOW_MOUSE_ENTER : GLWT_WINDOW_MOUSE_LEAVE);
                    event.dummy.dummy = 0;
                    win->win_callback(win, &event, win->userdata);
                }

                {
                    TRACKMOUSEEVENT tme;
                    tme.cbSize = sizeof(tme);
                    tme.dwFlags = uMsg == WM_MOUSEHOVER ? TME_LEAVE : TME_HOVER;
                    tme.hwndTrack = hwnd;
                    tme.dwHoverTime = 1;
                    TrackMouseEvent(&tme);
                }

                return 0;

            case WM_SHOWWINDOW:
                if(win->win_callback)
                {
                    GLWTWindowEvent event;
                    event.window = win;
                    event.type = (wParam == TRUE ? GLWT_WINDOW_SHOW : GLWT_WINDOW_HIDE);
                    event.dummy.dummy = 0;
                    win->win_callback(win, &event, win->userdata);
                }

                return 0;

            case WM_SIZE:
                if(win->win_callback)
                {
                    GLWTWindowEvent event;
                    event.window = win;
                    event.type = GLWT_WINDOW_RESIZE;
                    event.resize.width = LOWORD(lParam);
                    event.resize.height = HIWORD(lParam);
                    win->win_callback(win, &event, win->userdata);
                }

                return 0;

            case WM_CLOSE:
                win->closed = 1;

                if(win->win_callback)
                {
                    GLWTWindowEvent event;
                    event.window = win;
                    event.type = GLWT_WINDOW_CLOSE;
                    event.dummy.dummy = 0;
                    win->win_callback(win, &event, win->userdata);
                }

                return 0;

            case WM_SYSCHAR:
            case WM_CHAR:
                if(win->win_callback)
                {
                    GLWTWindowEvent event;
                    event.window = win;
                    event.type = GLWT_WINDOW_CHARACTER_INPUT;
                    event.character.unicode = utf16_decode((unsigned int)wParam);

                    win->win_callback(win, &event, win->userdata);
                }

                return 0;

            default:
                break;

        }
    }
Esempio n. 20
0
    LRESULT processMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
      LRESULT returnValue = 0;
      switch(message) {
        case WM_CREATE:
          windowHandle = hwnd;
          initGL();
          initGLBitmapFont(GL_BITMAP_FONT_FIRST_GLYPH, GL_BITMAP_FONT_LAST_GLYPH);
          break;
  
        case WM_SHOWWINDOW:
          if ( ( (BOOL) wParam ) == TRUE ) {
            window->show();
            autoUpdate = true;
          }
          else {
            window->hide();
            autoUpdate = false;
          }
          break;
  
        case WM_PAINT:
  
          window->paint();
          swap();
          ValidateRect(hwnd, NULL);
  /*
          if (autoUpdate)
            SetTimer(hwnd, 1, 100, NULL);
   */
          break;
  
        case WM_TIMER:
  /*
          if (wParam == 1)
            UpdateWindow(hwnd);
            InvalidateRect(hwnd, NULL, false);
  */
          break;
  
        case WM_SIZE:
          window->resize(LOWORD(lParam), HIWORD(lParam));
          break;
  
        case WM_CLOSE:
          window->closeRequest();
          break;
  
  
        case WM_KEYDOWN:
        
          if (int keycode = translate_key(wParam) ) {
            window->keyPress(keycode);
          } else
            return -1;  
        case WM_CHAR:
          window->keyPress( (int) ( (char) wParam ) );
          break;
  
        case WM_LBUTTONDOWN:
          ( (captureView) ? captureView : window ) -> buttonPress(GUI_ButtonLeft, (short) LOWORD(lParam), (short) HIWORD(lParam) );
          break;
  
        case WM_LBUTTONUP:
          ( (captureView) ? captureView : window ) -> buttonRelease(GUI_ButtonLeft, (short) LOWORD(lParam), (short) HIWORD(lParam));
          break;
  
        case WM_RBUTTONDOWN:
          ( (captureView) ? captureView : window ) -> buttonPress(GUI_ButtonRight,(short) LOWORD(lParam), (short) HIWORD(lParam) );
          break;
  
        case WM_RBUTTONUP:
          ( (captureView) ? captureView : window ) -> buttonRelease(GUI_ButtonRight,(short) LOWORD(lParam), (short) HIWORD(lParam) );
          break;
  
        case WM_MBUTTONDOWN:
          ( (captureView) ? captureView : window )
           -> buttonPress(GUI_ButtonMiddle, (short) LOWORD(lParam), (short) HIWORD(lParam) );
          break;
  
        case WM_MBUTTONUP:
          ( (captureView) ? captureView : window ) -> buttonRelease(GUI_ButtonMiddle, (short) LOWORD(lParam), (short) HIWORD(lParam) );
          break;
#if (_WIN32_WINNT >= 0x0400) || (_WIN32_WINDOWS > 0x0400)          
        case WM_MOUSEWHEEL: 
          {
            int dir = ( (short) HIWORD(wParam)  > 0 ) ?  GUI_WheelForward : GUI_WheelBackward;
            ( (captureView) ? captureView : window ) -> wheelRotate(dir);
            break;
          }
#endif
  
        case WM_MOUSEMOVE:
          ( (captureView) ? captureView : window ) -> mouseMove( ( (short) LOWORD(lParam) ), ( (short) HIWORD(lParam) ) );
          break;
        case WM_CAPTURECHANGED:
          if (captureView) {
            captureView->captureLost();
            captureView = NULL;
          }
          break;

        case WM_DESTROY:
          destroyGLFont();
          shutdownGL();
          SetWindowLong(hwnd, GWL_USERDATA, (LONG) NULL );
          if (window)
            window->notifyDestroy();
          delete this;
          break;
        
        default:
          returnValue = DefWindowProc(hwnd,message,wParam,lParam);
      }
      return returnValue;
    }
Esempio n. 21
0
	LRESULT WINAPI wnd_proc(HWND wnd, UINT msg, WPARAM wpar, LPARAM lpar)
	{
		//DBG_ui::Event uiev;

		switch (msg) {
		case WM_CREATE:
			//myapp = reinterpret_cast<base::app*>(
			//	reinterpret_cast<const CREATESTRUCT*>(lParam)->lpCreateParams);
			break;
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		case WM_PAINT:
			ValidateRect(wnd, 0);
			break;
		case WM_MOUSEMOVE:
			if (context.input_handler) {
				context.input_handler->mouse(GET_X_LPARAM(lpar), GET_Y_LPARAM(lpar));
			}
			return 0;
		case WM_KEYDOWN:
			if (wpar == VK_F12 && context._ui_key == false) {
				context._ui_key = true;
			}
			else if (context.input_handler) {
				context.input_handler->key(translate_key(wpar, lpar), 1);
			}
			return 0;
		case WM_KEYUP:

			if (wpar == VK_F12 && context._ui_key == true) {
				context._ui_key = false;
			}
			else if (context.input_handler) {
				context.input_handler->key(translate_key(wpar, lpar), 0);
			}
			return 0;
		case WM_CHAR:
			return 0;
		case WM_LBUTTONDOWN:
			SetCapture(wnd);
			if (context.input_handler) {
				context.input_handler->button(0, 1);
			}
			return 0;
		case WM_LBUTTONUP:
			ReleaseCapture();

			if (context.input_handler) {
				context.input_handler->button(0, 0);
			}
			return 0;
		case WM_RBUTTONDOWN:
			SetCapture(wnd);
			if (context.input_handler) {
				context.input_handler->button(1, 1);
			}
			return 0;
		case WM_RBUTTONUP:
			ReleaseCapture();
			if (context.input_handler) {
				context.input_handler->button(1, 0);
			}
			return 0;
		case WM_MBUTTONDOWN:
			SetCapture(wnd);
			if (context.input_handler) {
				context.input_handler->button(2, 1);
			}
			return 0;
		case WM_MBUTTONUP:
			ReleaseCapture();
			if (context.input_handler) {
				context.input_handler->button(2, 0);
			}
			return 0;
		case WM_ACTIVATEAPP:
			//myapp->activated(wParam == TRUE);
			break;
		}

		return DefWindowProc(wnd, msg, wpar, lpar);
	}
Esempio n. 22
0
/*
 * Input thread reading from device.
 * Generates events on incoming data.
 */
static void*
sdlEventThread( DirectThread *thread, void *driver_data )
{
     SDLInputData *data    = (SDLInputData*) driver_data;
     DFBSDL       *dfb_sdl = data->dfb_sdl;

     while (!data->stop) {
          DFBInputEvent evt;
          SDL_Event     event;

          fusion_skirmish_prevail( &dfb_sdl->lock );

          /* Check for events */
          while ( SDL_PollEvent(&event) ) {
               fusion_skirmish_dismiss( &dfb_sdl->lock );

               switch (event.type) {
                    case SDL_MOUSEMOTION:
                         motion_compress( event.motion.x, event.motion.y );
                         break;

                    case SDL_MOUSEBUTTONUP:
                    case SDL_MOUSEBUTTONDOWN:
                         motion_realize( data );

                         if (event.type == SDL_MOUSEBUTTONDOWN)
                              evt.type = DIET_BUTTONPRESS;
                         else
                              evt.type = DIET_BUTTONRELEASE;

                         evt.flags = DIEF_NONE;

                         switch (event.button.button) {
                              case SDL_BUTTON_LEFT:
                                   evt.button = DIBI_LEFT;
                                   break;
                              case SDL_BUTTON_MIDDLE:
                                   evt.button = DIBI_MIDDLE;
                                   break;
                              case SDL_BUTTON_RIGHT:
                                   evt.button = DIBI_RIGHT;
                                   break;
                              case SDL_BUTTON_WHEELUP:
                              case SDL_BUTTON_WHEELDOWN:
                                   if (event.type != SDL_MOUSEBUTTONDOWN) {
                                        fusion_skirmish_prevail( &dfb_sdl->lock );
                                        continue;
                                   }
                                   evt.type  = DIET_AXISMOTION;
                                   evt.flags = DIEF_AXISREL;
                                   evt.axis  = DIAI_Z;
                                   if (event.button.button == SDL_BUTTON_WHEELUP)
                                        evt.axisrel = -1;
                                   else
                                        evt.axisrel = 1;
                                   break;
                              default:
                                   fusion_skirmish_prevail( &dfb_sdl->lock );
                                   continue;
                         }

                         dfb_input_dispatch( data->device, &evt );
                         break;

                    case SDL_KEYUP:
                    case SDL_KEYDOWN:
                         if (event.type == SDL_KEYDOWN)
                              evt.type = DIET_KEYPRESS;
                         else
                              evt.type = DIET_KEYRELEASE;

                         /* Get a key id first */
                         translate_key( event.key.keysym.sym, &evt );

                         /* If SDL provided a symbol, use it */
                         if (event.key.keysym.unicode) {
                              evt.flags     |= DIEF_KEYSYMBOL;
                              evt.key_symbol = event.key.keysym.unicode;

                              /**
                               * Hack to translate the Control+[letter]
                               * combination to
                               * Modifier: CONTROL, Key Symbol: [letter]
                               * A side effect here is that Control+Backspace
                               * produces Control+h
                               */
                              if (evt.modifiers == DIMM_CONTROL &&
                                  evt.key_symbol >= 1 && evt.key_symbol <= ('z'-'a'+1))
                              {
                                  evt.key_symbol += 'a'-1;
                              }
                         }

                         dfb_input_dispatch( data->device, &evt );
                         break;
                    case SDL_QUIT:
                         evt.type       = DIET_KEYPRESS;
                         evt.flags      = DIEF_KEYSYMBOL;
                         evt.key_symbol = DIKS_ESCAPE;

                         dfb_input_dispatch( data->device, &evt );

                         evt.type       = DIET_KEYRELEASE;
                         evt.flags      = DIEF_KEYSYMBOL;
                         evt.key_symbol = DIKS_ESCAPE;

                         dfb_input_dispatch( data->device, &evt );
                         break;

                    default:
                         break;
               }

               fusion_skirmish_prevail( &dfb_sdl->lock );
          }

          fusion_skirmish_dismiss( &dfb_sdl->lock );

          motion_realize( data );

          usleep(10000);

          direct_thread_testcancel( thread );
     }

     return NULL;
}
Esempio n. 23
0
bool handleSDLEvents()
{
    static SDL_Event event;

    KeyboardInterface::sampleKeyboard();
    while(SDL_PollEvent(&event)) {
        switch (event.type) {
        case SDL_QUIT:
            return true;
            break;
        case SDL_MOUSEBUTTONDOWN:
            MouseInterface::onMouseButtonDown(&event.button);
            break;
        case SDL_MOUSEBUTTONUP:
            MouseInterface::onMouseButtonUp(&event.button);
            break;
        case SDL_MOUSEMOTION:
            MouseInterface::onMouseMoved(&event.motion);
            break;
        case SDL_KEYDOWN: {
//                LOGGER.debug("Pressed key : scancode[%d] unicode[%d]", event.key.keysym.sym, event.key.keysym.unicode);
                KeyboardInterface::keyPressed(translate_key(&event.key.keysym));

                if ( (event.key.keysym.unicode & 0xFF80) == 0 )
                {
                  char c = event.key.keysym.unicode & 0x7F;
                  if ( isprint(c) )
                  {
                      KeyboardInterface::putChar(c);
                  }
                  else
                  {
                      // extended chars, first push a 0
                      KeyboardInterface::putChar(0);
                      KeyboardInterface::putChar(event.key.keysym.sym);
                  }
                }
                else
                {
                    // international character ignored for now
                }

                break;
            }
        case SDL_KEYUP:
//            LOGGER.debug("Released key: scancode[%d] unicode[%d]", event.key.keysym.sym, event.key.keysym.unicode);
            KeyboardInterface::keyReleased(translate_key(&event.key.keysym));
            break;
       
        case SDL_ACTIVEEVENT:
            if ( (event.active.state&SDL_APPACTIVE)
                 && (event.active.gain==1)
                 && GameConfig::video_fullscreen )
                Screen->setPalette(Palette::color);
             break;
        case SDL_VIDEORESIZE:
            GameConfig::video_width = event.resize.w;
            GameConfig::video_height = event.resize.h;
            GameManager::setVideoMode();
            break;
        }
    }

    return false;
}
Esempio n. 24
0
File: madpdf.c Progetto: avm/madpdf
void cb_key_down(Ewl_Widget *w, void *ev, void *data)
{
    Ewl_Widget *curwidget;
    Ewl_Event_Key_Down *e;
    e = (Ewl_Event_Key_Down*)ev;
    int k = translate_key(e);
    
    curwidget=ewl_widget_name_find("pdfwidget");
    switch(k)
    {
    case 0:
        ewl_pdf_page_next(EWL_PDF(curwidget));
        resize_and_rescale(curscale);
        break;
    case 9:
        ewl_pdf_page_previous(EWL_PDF(curwidget));
        resize_and_rescale(curscale);
        break;
    case 8:
        curscale+=((double)get_settings()->zoominc)/100.0;
        resize_and_rescale(curscale);
        break;
    case 7:
        curscale-=((double)get_settings()->zoominc)/100.0;
        resize_and_rescale(curscale);
        break;
    case 6:
        change_orientation(curwidget);
        resize_and_rescale(curscale);
        break;
    case 1:
        move_hscrollbar(EWL_SCROLLPANE(scrollpane), -1);
        break;
    case 2:
        move_hscrollbar(EWL_SCROLLPANE(scrollpane),  1);
        break;
    case 3:
        move_vscrollbar(EWL_SCROLLPANE(scrollpane),  1);
        break;    
    case 4:
        move_vscrollbar(EWL_SCROLLPANE(scrollpane), -1);
        break;
    case 5:
        if(fitmode==0)
            fitmode=1;
        else if(fitmode==1)
            fitmode=0;
        calculate_margins();
        resize_and_rescale(curscale);
        break;
    case K_RETURN:
        ewl_widget_show(menu);
        ewl_widget_focus_send(menu);
        break;
    case K_ESCAPE:
        ewl_main_quit();
        break;
    default:
        return;
    }
    
    
    
}