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