\r
if (Cmd_Argc() != 2)\r
{\r
- Con_Print("usage: gecko_destroy <name>\ndestroys a browser (full texture path " CLGECKOPREFIX "<name>)\n");\r
+ Con_Print("usage: gecko_destroy <name>\ndestroys a browser\n");\r
return;\r
}\r
\r
\r
if (Cmd_Argc() != 3)\r
{\r
- Con_Print("usage: gecko_navigate <name> <URI>\nnavigates to a certain URI (full texture path " CLGECKOPREFIX "<name>)\n");\r
+ Con_Print("usage: gecko_navigate <name> <URI>\nnavigates to a certain URI\n");\r
return;\r
}\r
\r
CL_Gecko_NavigateToURI( CL_Gecko_FindBrowser( name ), URI );\r
}\r
\r
+static void cl_gecko_injecttext_f( void ) {\r
+ char name[MAX_QPATH];\r
+ const char *text;\r
+ clgecko_t *instance;\r
+ const char *p;\r
+\r
+ if (Cmd_Argc() < 3)\r
+ {\r
+ Con_Print("usage: gecko_injecttext <name> <text>\ninjects a certain text into the browser\n");\r
+ return;\r
+ }\r
+\r
+ // TODO: use snprintf instead\r
+ sprintf(name, CLGECKOPREFIX "%s", Cmd_Argv(1));\r
+ instance = CL_Gecko_FindBrowser( name );\r
+ if( !instance ) {\r
+ Con_Printf( "cl_gecko_injecttext_f: gecko instance '%s' couldn't be found!\n", name );\r
+ return;\r
+ }\r
+\r
+ text = Cmd_Argv( 2 );\r
+\r
+ for( p = text ; *p ; p++ ) {\r
+ unsigned key = *p;\r
+ switch( key ) {\r
+ case ' ':\r
+ key = K_SPACE;\r
+ break;\r
+ case '\\':\r
+ key = *++p;\r
+ switch( key ) {\r
+ case 'n':\r
+ key = K_ENTER;\r
+ break;\r
+ case '\0':\r
+ --p;\r
+ key = '\\';\r
+ break;\r
+ }\r
+ break;\r
+ }\r
+\r
+ CL_Gecko_Event_Key( instance, key, CLG_BET_PRESS );\r
+ }\r
+}\r
+\r
void CL_Gecko_Init( void )\r
{\r
OSGK_EmbeddingOptions *options = osgk_embedding_options_create();\r
osgk_embedding_options_add_search_path( options, "./xulrunner/" );\r
- cl_geckoembedding = osgk_embedding_create_with_options( options, NULL );\r
+ cl_geckoembedding = osgk_embedding_create_with_options( options, NULL );\r
osgk_release( options );\r
\r
if( cl_geckoembedding == NULL ) {\r
\r
Cmd_AddCommand( "gecko_create", cl_gecko_create_f, "Create a gecko browser instance" );\r
Cmd_AddCommand( "gecko_destroy", cl_gecko_destroy_f, "Destroy a gecko browser instance" );\r
- Cmd_AddCommand( "gecko_navigate", cl_gecko_navigate_f, "Navigate a gecko browser to an URI" );\r
+ Cmd_AddCommand( "gecko_navigate", cl_gecko_navigate_f, "Navigate a gecko browser to a URI" );\r
+ Cmd_AddCommand( "gecko_injecttext", cl_gecko_injecttext_f, "Injects text into a browser" );\r
\r
R_RegisterModule( "CL_Gecko", cl_gecko_start, cl_gecko_shutdown, cl_gecko_newmap );\r
}\r
}\r
}\r
\r
-// TODO: write this function\r
-void CL_Gecko_Event_CursorMove( clgecko_t *instance, float x, float y );\r
-qboolean CL_Gecko_Event_Key( clgecko_t *instance, int key, clgecko_buttoneventtype_t eventtype );\r
+void CL_Gecko_Event_CursorMove( clgecko_t *instance, float x, float y ) {\r
+ // TODO: assert x, y \in [0.0, 1.0]\r
+ int mappedx, mappedy;\r
+\r
+ if( !instance || !instance->browser ) {\r
+ return;\r
+ }\r
+\r
+ mappedx = x * DEFAULT_GECKO_WIDTH;\r
+ mappedy = y * DEFAULT_GECKO_HEIGHT;\r
+ osgk_browser_event_mouse_move( instance->browser, mappedx, mappedy );\r
+}\r
+\r
+typedef struct geckokeymapping_s {\r
+ keynum_t keycode;\r
+ unsigned int geckokeycode;\r
+} geckokeymapping_t;\r
+\r
+static geckokeymapping_t geckokeymappingtable[] = {\r
+ { K_BACKSPACE, OSGKKey_Backspace },\r
+ { K_TAB, OSGKKey_Tab },\r
+ { K_ENTER, OSGKKey_Return },\r
+ { K_SHIFT, OSGKKey_Shift },\r
+ { K_CTRL, OSGKKey_Control },\r
+ { K_ALT, OSGKKey_Alt },\r
+ { K_CAPSLOCK, OSGKKey_CapsLock },\r
+ { K_ESCAPE, OSGKKey_Escape },\r
+ { K_SPACE, OSGKKey_Space },\r
+ { K_PGUP, OSGKKey_PageUp },\r
+ { K_PGDN, OSGKKey_PageDown },\r
+ { K_END, OSGKKey_End },\r
+ { K_HOME, OSGKKey_Home },\r
+ { K_LEFTARROW, OSGKKey_Left },\r
+ { K_UPARROW, OSGKKey_Up },\r
+ { K_RIGHTARROW, OSGKKey_Right },\r
+ { K_DOWNARROW, OSGKKey_Down },\r
+ { K_INS, OSGKKey_Insert },\r
+ { K_DEL, OSGKKey_Delete },\r
+ { K_F1, OSGKKey_F1 },\r
+ { K_F2, OSGKKey_F2 },\r
+ { K_F3, OSGKKey_F3 },\r
+ { K_F4, OSGKKey_F4 },\r
+ { K_F5, OSGKKey_F5 },\r
+ { K_F6, OSGKKey_F6 },\r
+ { K_F7, OSGKKey_F7 },\r
+ { K_F8, OSGKKey_F8 },\r
+ { K_F9, OSGKKey_F9 },\r
+ { K_F10, OSGKKey_F10 },\r
+ { K_F11, OSGKKey_F11 },\r
+ { K_F12, OSGKKey_F12 },\r
+ { K_NUMLOCK, OSGKKey_NumLock },\r
+ { K_SCROLLOCK, OSGKKey_ScrollLock }\r
+};\r
+\r
+qboolean CL_Gecko_Event_Key( clgecko_t *instance, int key, clgecko_buttoneventtype_t eventtype ) {\r
+ if( !instance || !instance->browser ) {\r
+ return false;\r
+ }\r
+\r
+ // determine whether its a keyboard event\r
+ if( key < K_OTHERDEVICESBEGIN ) {\r
+\r
+ OSGK_KeyboardEventType mappedtype;\r
+ unsigned int mappedkey = key;\r
+ \r
+\r
+ int i;\r
+ // yes! then convert it if necessary!\r
+ for( i = 0 ; i < sizeof( geckokeymappingtable ) / sizeof( *geckokeymappingtable ) ; i++ ) {\r
+ const geckokeymapping_t * const mapping = &geckokeymappingtable[ i ];\r
+ if( key == mapping->keycode ) {\r
+ mappedkey = mapping->geckokeycode;\r
+ break;\r
+ }\r
+ }\r
+\r
+ // convert the eventtype\r
+ // map the type\r
+ switch( eventtype ) {\r
+ case CLG_BET_DOWN:\r
+ mappedtype = keDown;\r
+ break;\r
+ case CLG_BET_UP:\r
+ mappedtype = keUp;\r
+ break;\r
+ case CLG_BET_DOUBLECLICK:\r
+ // TODO: error message\r
+ break;\r
+ case CLG_BET_PRESS:\r
+ mappedtype = kePress;\r
+ }\r
+\r
+ return osgk_browser_event_key( instance->browser, mappedkey, mappedtype ) != 0;\r
+ } else if( K_MOUSE1 <= key && key <= K_MOUSE3 ) {\r
+ OSGK_MouseButtonEventType mappedtype;\r
+ OSGK_MouseButton mappedbutton;\r
+\r
+ mappedbutton = (OSGK_MouseButton) (mbLeft + (key - K_MOUSE1));\r
+\r
+ switch( eventtype ) {\r
+ case CLG_BET_DOWN:\r
+ mappedtype = meDown;\r
+ break;\r
+ case CLG_BET_UP:\r
+ mappedtype = meUp;\r
+ break;\r
+ case CLG_BET_DOUBLECLICK:\r
+ mappedtype = meDoubleClick;\r
+ break;\r
+ case CLG_BET_PRESS:\r
+ // TODO: error message\r
+ break;\r
+ }\r
+\r
+ return true;\r
+ }\r
+ // TODO: error?\r
+ return false;\r
+}\r
\r
#endif
\ No newline at end of file