]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/item/gecko.c
Merge remote branch 'origin/terencehill/newpanelhud' into fruitiex/newpanelhud
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / item / gecko.c
1 // Andreas Kirsch Gecko item (to test it)
2 #ifdef INTERFACE
3 CLASS(Gecko) EXTENDS(Item)
4         METHOD(Gecko, configureBrowser, void( entity, string ) )
5         METHOD(Gecko, draw, void(entity))
6         METHOD(Gecko, keyDown, float(entity, float, float, float))
7         METHOD(Gecko, keyUp, float(entity, float, float, float))
8         METHOD(Gecko, mouseMove, float(entity, vector))
9         METHOD(Gecko, mouseDrag, float(entity, vector))
10         METHOD(Gecko, resizeNotify, void(entity, vector, vector, vector, vector))
11         ATTRIB(Gecko, texturePath, string, string_null )
12         ATTRIB(Gecko, textureExtent, vector, '0 0 0')
13 ENDCLASS(Gecko)
14 #endif
15
16 #ifdef IMPLEMENTATION
17 // define static members
18 float _gecko_instanceNumber;
19
20 void Gecko_configureBrowser( entity me, string URI ) {
21         me.focusable = 1;
22
23         //create a new gecko object if needed
24         if( !me.texturePath ) {
25                 me.texturePath = strzone( strcat( "_dynamic/gecko/menu/",  ftos( _gecko_instanceNumber ) ) );
26                 _gecko_instanceNumber+=1;
27                 // TODO: add error checks
28                 gecko_create( me.texturePath );
29         }
30         gecko_navigate( me.texturePath, URI );
31 }
32
33 void Gecko_draw(entity me)
34 {
35         vector drawSize;
36   
37         if( me.texturePath ) {
38                 /* The gecko browser is actually only drawn to a part of the
39                    texture. Correct scaling so that part fills up the whole
40                    item area. */
41                 drawSize_x = 1.0 / me.textureExtent_x;
42                 drawSize_y = 1.0 / me.textureExtent_y;
43                 draw_Picture( '0 0 0', strcat( "/", me.texturePath ), 
44                         drawSize, '1 1 1', 1.0 );
45         } else {
46                 local vector fontsize;
47                 fontsize_x = fontsize_y = 1.0 / 30.0;
48                 fontsize_z = 0.0;
49                 draw_Text( '0 0 0', "Browser not initialized!", fontsize, '1 1 1', 1.0, 0 );
50         }
51 }
52
53 float Gecko_keyDown(entity me, float scan, float ascii, float shift)
54 {
55         if( scan == K_ESCAPE ) {
56                 return 0;
57         }
58         if (ascii >= 32)
59                 return gecko_keyevent( me.texturePath, ascii, GECKO_BUTTON_DOWN );
60         else
61                 return gecko_keyevent( me.texturePath, scan, GECKO_BUTTON_DOWN );
62 }
63
64 float Gecko_keyUp(entity me, float scan, float ascii, float shift)
65 {
66         if (ascii >= 32)
67                 return gecko_keyevent( me.texturePath, ascii, GECKO_BUTTON_UP );
68         else
69                 return gecko_keyevent( me.texturePath, scan, GECKO_BUTTON_UP );
70 }
71
72 float Gecko_mouseMove(entity me, vector pos)
73 {
74         gecko_mousemove( me.texturePath, pos_x, pos_y );
75         return 1;
76 }
77
78 float Gecko_mouseDrag(entity me, vector pos)
79 {
80         gecko_mousemove( me.texturePath, pos_x, pos_y );
81         return 1;
82 }
83
84 void Gecko_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
85 {
86         SUPER(Gecko).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
87         gecko_resize( me.texturePath, absSize_x, absSize_y );
88         me.textureExtent = gecko_get_texture_extent( me.texturePath );
89 }
90
91 string toStringGecko(entity me)
92 {
93         return me.texturePath;
94 }
95
96 #endif