]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Move the code around a bit in cl_gecko and add the console command gecko_movecursor.
authorblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 14 Dec 2007 01:45:07 +0000 (01:45 +0000)
committerblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 14 Dec 2007 01:45:07 +0000 (01:45 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7798 d7cf8633-e32d-0410-b094-e92efae38249

cl_gecko.c
cl_gecko.h

index f1ec9d89f9692387ad6af500180d51ad08501451..ba45235b55664c1887c7d249df572db0afc8717a 100644 (file)
@@ -12,7 +12,7 @@
 #include "cl_gecko.h"\r
 #include "timing.h"\r
 \r
-#define DEFAULT_SIZE     512\r
+#define DEFAULT_GECKO_SIZE       512\r
 \r
 static rtexturepool_t *cl_geckotexturepool;\r
 static OSGK_Embedding *cl_geckoembedding;\r
@@ -22,8 +22,8 @@ struct clgecko_s {
        char name[ MAX_QPATH + 32 ];\r
 \r
        OSGK_Browser *browser;\r
-       int w, h;\r
-       int texW, texH;\r
+       int width, height;\r
+       int texWidth, texHeight;\r
        \r
        rtexture_t *texture;\r
 };\r
@@ -66,7 +66,7 @@ static void cl_gecko_updatecallback( rtexture_t *texture, clgecko_t *instance )
        if( instance->browser ) {\r
                // TODO: OSGK only supports BGRA right now\r
                TIMING_TIMESTATEMENT(data = osgk_browser_lock_data( instance->browser, NULL ));\r
-               R_UpdateTexture( texture, data, 0, 0, instance->w, instance->h);\r
+               R_UpdateTexture( texture, data, 0, 0, instance->width, instance->height );\r
                osgk_browser_unlock_data( instance->browser, data );\r
        }\r
 }\r
@@ -74,7 +74,7 @@ static void cl_gecko_updatecallback( rtexture_t *texture, clgecko_t *instance )
 static void cl_gecko_linktexture( clgecko_t *instance ) {\r
        // TODO: assert that instance->texture == NULL\r
        instance->texture = R_LoadTexture2D( cl_geckotexturepool, instance->name, \r
-               instance->texW, instance->texH, NULL, TEXTYPE_BGRA, TEXF_ALPHA | TEXF_PERSISTENT, NULL );\r
+               instance->texWidth, instance->texHeight, NULL, TEXTYPE_BGRA, TEXF_ALPHA | TEXF_PERSISTENT, NULL );\r
        R_MakeTextureDynamic( instance->texture, cl_gecko_updatecallback, instance );\r
        CL_LinkDynTexture( instance->name, instance->texture );\r
 }\r
@@ -87,6 +87,46 @@ static void cl_gecko_unlinktexture( clgecko_t *instance ) {
        }\r
 }\r
 \r
+void CL_Gecko_Resize( clgecko_t *instance, int width, int height ) {\r
+       int newWidth, newHeight;\r
+\r
+       // early out if bad parameters are passed (no resize to a texture size bigger than the original texture size)\r
+       if( !instance || !instance->browser) {\r
+               return;\r
+       }\r
+\r
+       newWidth = CeilPowerOf2( width );\r
+       newHeight = CeilPowerOf2( height );\r
+       if ((newWidth != instance->texWidth) || (newHeight != instance->texHeight))\r
+       {\r
+               cl_gecko_unlinktexture( instance );\r
+               instance->texWidth = newWidth;\r
+               instance->texHeight = newHeight;\r
+               cl_gecko_linktexture( instance );\r
+       }\r
+       else\r
+       {\r
+               /* The gecko area will only cover a part of the texture; to avoid\r
+               'old' pixels bleeding in at the border clear the texture. */\r
+               R_ClearTexture( instance->texture );\r
+       }\r
+\r
+       osgk_browser_resize( instance->browser, width, height);\r
+       instance->width = width;\r
+       instance->height = height;\r
+}\r
+\r
+void CL_Gecko_GetTextureExtent( clgecko_t *instance, float* pwidth, float* pheight )\r
+{\r
+       if( !instance || !instance->browser ) {\r
+               return;\r
+       }\r
+\r
+       *pwidth = (float)instance->width / instance->texWidth;\r
+       *pheight = (float)instance->height / instance->texHeight;\r
+}\r
+\r
+\r
 clgecko_t * CL_Gecko_CreateBrowser( const char *name ) {\r
        // TODO: verify that we dont use a name twice\r
        clgecko_t *instance = cl_gecko_findunusedinstance();\r
@@ -106,13 +146,11 @@ clgecko_t * CL_Gecko_CreateBrowser( const char *name ) {
 \r
        instance->active = true;\r
        strlcpy( instance->name, name, sizeof( instance->name ) );\r
-       instance->browser = osgk_browser_create( cl_geckoembedding, DEFAULT_SIZE, DEFAULT_SIZE );\r
+       instance->browser = osgk_browser_create( cl_geckoembedding, DEFAULT_GECKO_SIZE, DEFAULT_GECKO_SIZE );\r
        // TODO: assert != NULL\r
 \r
-       instance->texW = DEFAULT_SIZE;\r
-       instance->texH = DEFAULT_SIZE;\r
-       instance->w = DEFAULT_SIZE;\r
-       instance->h = DEFAULT_SIZE;\r
+       instance->width = instance->texWidth = DEFAULT_GECKO_SIZE;\r
+       instance->height = instance->texHeight = DEFAULT_GECKO_SIZE;\r
        cl_gecko_linktexture( instance );\r
 \r
        return instance;\r
@@ -279,12 +317,31 @@ static void cl_gecko_injecttext_f( void ) {
        }\r
 }\r
 \r
+static void gl_gecko_movecursor_f( void ) {\r
+       char name[MAX_QPATH];\r
+       float x, y;\r
+\r
+       if (Cmd_Argc() != 4)\r
+       {\r
+               Con_Print("usage: gecko_movecursor <name> <x> <y>\nmove the cursor to a certain position\n");\r
+               return;\r
+       }\r
+\r
+       // TODO: use snprintf instead\r
+       sprintf(name, CLGECKOPREFIX "%s", Cmd_Argv(1));\r
+       x = atof( Cmd_Argv( 2 ) );\r
+       y = atof( Cmd_Argv( 3 ) );\r
+\r
+       CL_Gecko_Event_CursorMove( CL_Gecko_FindBrowser( name ), x, y );\r
+}\r
+\r
 void CL_Gecko_Init( void )\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 a URI" );\r
        Cmd_AddCommand( "gecko_injecttext", cl_gecko_injecttext_f, "Injects text into a browser" );\r
+       Cmd_AddCommand( "gecko_movecursor", gl_gecko_movecursor_f, "Move the cursor to a certain position" );\r
 \r
        R_RegisterModule( "CL_Gecko", cl_gecko_start, cl_gecko_shutdown, cl_gecko_newmap );\r
 }\r
@@ -303,8 +360,8 @@ void CL_Gecko_Event_CursorMove( clgecko_t *instance, float x, float y ) {
                return;\r
        }\r
 \r
-       mappedx = x * instance->w;\r
-       mappedy = y * instance->h;\r
+       mappedx = x * instance->width;\r
+       mappedy = y * instance->height;\r
        osgk_browser_event_mouse_move( instance->browser, mappedx, mappedy );\r
 }\r
 \r
@@ -422,42 +479,4 @@ qboolean CL_Gecko_Event_Key( clgecko_t *instance, int key, clgecko_buttoneventty
        return false;\r
 }\r
 \r
-void CL_Gecko_Resize( clgecko_t *instance, int w, int h ) {\r
-       int newW, newH;\r
-\r
-       if( !instance || !instance->browser ) {\r
-               return;\r
-       }\r
-\r
-       newW = 1; while( newW < w ) newW *= 2;\r
-       newH = 1; while( newH < h ) newH *= 2;\r
-       if ((newW != instance->texW) || (newH != instance->texH))\r
-       {\r
-         cl_gecko_unlinktexture( instance );\r
-         instance->texW = newW;\r
-         instance->texH = newH;\r
-         cl_gecko_linktexture( instance );\r
-       }\r
-       else\r
-       {\r
-         /* The gecko area will only cover a part of the texture; to avoid\r
-            'old' pixels bleeding in at the border clear the texture. */\r
-         R_ClearTexture( instance->texture );\r
-       }\r
-\r
-       osgk_browser_resize( instance->browser, w, h);\r
-       instance->w = w;\r
-       instance->h = h;\r
-}\r
-\r
-void CL_Gecko_GetTextureExtent( clgecko_t *instance, float* u, float* v )\r
-{\r
-       if( !instance || !instance->browser ) {\r
-               return;\r
-       }\r
-\r
-       *u = (float)instance->w / instance->texW;\r
-       *v = (float)instance->h / instance->texH;\r
-}\r
-\r
 #endif\r
index b4efeffafd83a8a5527fa865da80c0069ddd9c59..3d6109210325ef73b626064522ed606bae7dabf6 100644 (file)
@@ -35,8 +35,9 @@ void CL_Gecko_Event_CursorMove( clgecko_t *instance, float x, float y );
 // returns whether the key/button event was handled or not\r
 qboolean CL_Gecko_Event_Key( clgecko_t *instance, int key, clgecko_buttoneventtype_t eventtype );\r
 \r
-void CL_Gecko_Resize( clgecko_t *instance, int w, int h );\r
-void CL_Gecko_GetTextureExtent( clgecko_t *instance, float* u, float* v );\r
+void CL_Gecko_Resize( clgecko_t *instance, int width, int height );\r
+// get the ratio between gecko instance's size in the texture and the actual texture size..\r
+void CL_Gecko_GetTextureExtent( clgecko_t *instance, float* pwidth, float* pheight );\r
 #endif\r
 \r
 #endif\r