]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Gecko resizing support
authorres <res@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 12 Dec 2007 00:08:17 +0000 (00:08 +0000)
committerres <res@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 12 Dec 2007 00:08:17 +0000 (00:08 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7786 d7cf8633-e32d-0410-b094-e92efae38249

cl_gecko.c
cl_gecko.h
gl_textures.c
mvm_cmds.c
prvm_cmds.c
prvm_cmds.h
r_textures.h

index 2289021185bc901d06c03c92dc149d607766c9c6..d9950a14b07d5767331ce4a876506822761ccfa8 100644 (file)
@@ -12,6 +12,8 @@
 #include "cl_gecko.h"\r
 #include "timing.h"\r
 \r
+#define DEFAULT_SIZE     512\r
+\r
 static rtexturepool_t *cl_geckotexturepool;\r
 static OSGK_Embedding *cl_geckoembedding;\r
 \r
@@ -20,6 +22,8 @@ struct clgecko_s {
        char name[ MAX_QPATH + 32 ];\r
 \r
        OSGK_Browser *browser;\r
+       int w, h;\r
+       int texW, texH;\r
        \r
        rtexture_t *texture;\r
 };\r
@@ -59,17 +63,18 @@ clgecko_t * CL_Gecko_FindBrowser( const char *name ) {
 \r
 static void cl_gecko_updatecallback( rtexture_t *texture, clgecko_t *instance ) {\r
        const unsigned char *data;\r
-       if( instance->browser && osgk_browser_query_dirty (instance->browser) ) {\r
+       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, DEFAULT_GECKO_WIDTH, DEFAULT_GECKO_HEIGHT );\r
+               R_UpdateTexture( texture, data, 0, 0, instance->w, instance->h);\r
                osgk_browser_unlock_data( instance->browser, data );\r
        }\r
 }\r
 \r
 static void cl_gecko_linktexture( clgecko_t *instance ) {\r
        // TODO: assert that instance->texture == NULL\r
-       instance->texture = R_LoadTexture2D( cl_geckotexturepool, instance->name, DEFAULT_GECKO_WIDTH, DEFAULT_GECKO_HEIGHT, NULL, TEXTYPE_BGRA, TEXF_ALPHA | TEXF_PERSISTENT, NULL );\r
+       instance->texture = R_LoadTexture2D( cl_geckotexturepool, instance->name, \r
+               instance->texW, instance->texH, 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
@@ -101,9 +106,13 @@ 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_GECKO_WIDTH, DEFAULT_GECKO_HEIGHT );\r
+       instance->browser = osgk_browser_create( cl_geckoembedding, DEFAULT_SIZE, DEFAULT_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
        cl_gecko_linktexture( instance );\r
 \r
        return instance;\r
@@ -294,8 +303,8 @@ void CL_Gecko_Event_CursorMove( clgecko_t *instance, float x, float y ) {
                return;\r
        }\r
 \r
-       mappedx = x * DEFAULT_GECKO_WIDTH;\r
-       mappedy = y * DEFAULT_GECKO_HEIGHT;\r
+       mappedx = x * instance->w;\r
+       mappedy = y * instance->h;\r
        osgk_browser_event_mouse_move( instance->browser, mappedx, mappedy );\r
 }\r
 \r
@@ -408,4 +417,42 @@ qboolean CL_Gecko_Event_Key( clgecko_t *instance, int key, clgecko_buttoneventty
        return false;\r
 }\r
 \r
-#endif
\ No newline at end of file
+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 c5bb63d230ec9e3dcf0fd8b084708881aa4900b4..b4efeffafd83a8a5527fa865da80c0069ddd9c59 100644 (file)
@@ -7,9 +7,6 @@
 \r
 #include "cl_dyntexture.h"\r
 \r
-#define DEFAULT_GECKO_WIDTH    512\r
-#define DEFAULT_GECKO_HEIGHT   DEFAULT_GECKO_WIDTH\r
-\r
 #define CLGECKOPREFIX                  CLDYNTEXTUREPREFIX "gecko/"\r
 #define MAX_GECKO_INSTANCES    16\r
 \r
@@ -38,6 +35,8 @@ 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
 #endif\r
 \r
 #endif\r
index ab18e72271794160ee7f984896670c4287334066..f2fac414d9669cfafa26a18034b2bab647f62f74 100644 (file)
@@ -1131,3 +1131,9 @@ void R_UpdateTexture(rtexture_t *rt, const unsigned char *data, int x, int y, in
        R_Upload(glt, data, x, y, 0, width, height, 1);
 }
 
+void R_ClearTexture (rtexture_t *rt)
+{
+       gltexture_t *glt = (gltexture_t *)rt;
+
+       R_Upload( glt, NULL, 0, 0, 0, glt->tilewidth, glt->tileheight, glt->tiledepth );
+}
index c4b194a9bd2744b1cad144677ecba08e1a9c61f7..2947ebfa88b36f137f0f06ee06b3d3a93a58eee5 100644 (file)
@@ -1268,15 +1268,17 @@ VM_gecko_destroy,                                       // #488
 VM_gecko_navigate,                             // #489
 VM_gecko_keyevent,                             // #490
 VM_gecko_movemouse,                            // #491
+VM_gecko_resize,                                                                       // #492
+VM_gecko_get_texture_extent,                                                                   // #493
 #else
 NULL,                                                                  // #487
 NULL,                                                                  // #488
 NULL,                                                                  // #489
 NULL,                                                                  // #490
 NULL,                                                                  // #491
-#endif
 NULL,                                                                  // #492
 NULL,                                                                  // #493
+#endif
 NULL,                                                                  // #494
 NULL,                                                                  // #495
 NULL,                                                                  // #496
index 3a8b38a3b939a6f171ec567560f63ad37e4c9e5f..cc01c830333dc42b68f28f6ad3e24d24f4a009f9 100644 (file)
@@ -3248,6 +3248,63 @@ void VM_gecko_movemouse( void ) {
        }
        CL_Gecko_Event_CursorMove( instance, x, y );
 }
+
+
+/*
+========================
+VM_gecko_resize
+
+void gecko_resize( string name, float w, float h )
+========================
+*/
+void VM_gecko_resize( void ) {
+       const char *name;
+       float w, h;
+       clgecko_t *instance;
+
+       VM_SAFEPARMCOUNT( 3, VM_gecko_movemouse );
+
+       name = PRVM_G_STRING( OFS_PARM0 );
+       VM_CheckEmptyString( name );
+       w = PRVM_G_FLOAT( OFS_PARM1 );
+       h = PRVM_G_FLOAT( OFS_PARM2 );
+       
+       instance = CL_Gecko_FindBrowser( name );
+       if( !instance ) {
+               return;
+       }
+       CL_Gecko_Resize( instance, w, h );
+}
+
+
+/*
+========================
+VM_gecko_get_texture_extent
+
+vector gecko_get_texture_extent( string name )
+========================
+*/
+void VM_gecko_get_texture_extent( void ) {
+       const char *name;
+       clgecko_t *instance;
+
+       VM_SAFEPARMCOUNT( 1, VM_gecko_movemouse );
+
+       name = PRVM_G_STRING( OFS_PARM0 );
+       VM_CheckEmptyString( name );
+       
+       PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
+       instance = CL_Gecko_FindBrowser( name );
+       if( !instance ) {
+               PRVM_G_VECTOR(OFS_RETURN)[0] = 0;
+               PRVM_G_VECTOR(OFS_RETURN)[1] = 0;
+               return;
+       }
+       CL_Gecko_GetTextureExtent( instance, 
+               PRVM_G_VECTOR(OFS_RETURN), PRVM_G_VECTOR(OFS_RETURN)+1 );
+}
+
+
 #endif
 
 /*
index b9d16bdb8ca8ae5dce0f03953ff16a824cdc72a6..73c8c1911fa86647867deda41fba111f5d44c138 100644 (file)
@@ -364,6 +364,8 @@ void VM_gecko_destroy( void );
 void VM_gecko_navigate( void );
 void VM_gecko_keyevent( void );
 void VM_gecko_movemouse( void );
+void VM_gecko_resize( void );
+void VM_gecko_get_texture_extent( void );
 #endif
 
 void VM_drawline (void);
index aac4bdec1d031cfd358e30e5958a1570f9e9c295..f31460acf139365b25de55bde9f03e2eae069a9f 100644 (file)
@@ -110,5 +110,8 @@ void R_Textures_Frame(void);
 void R_MarkDirtyTexture(rtexture_t *rt);
 void R_MakeTextureDynamic(rtexture_t *rt, updatecallback_t updatecallback, void *data);
 
+// Clear the texture's contents
+void R_ClearTexture (rtexture_t *rt);
+
 #endif