#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
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
\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
\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
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
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
}
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
/*