]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu-div0test/item/gecko.c
background image support; align "quit" to the bottom of the screen
[divverent/nexuiz.git] / data / qcsrc / menu-div0test / 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, mousePress, float(entity, vector))
10         METHOD( Gecko, mouseDrag, float(entity, vector))
11         METHOD( Gecko, mouseRelease, float(entity, vector))
12         METHOD( Gecko, resizeNotify, void(entity, vector, vector, vector, vector))
13         ATTRIB( Gecko, texturePath, string, string_null )
14         ATTRIB( Gecko, textureExtent, vector, '0 0 0')
15 ENDCLASS(Item)
16 #endif
17
18 #ifdef IMPLEMENTATION
19 // define static members
20 float _gecko_instanceNumber;
21
22 void configureBrowserGecko( entity me, string URI ) {
23         me.focusable = 1;
24
25         //create a new gecko object if needed
26         if( !me.texturePath ) {
27                 me.texturePath = strzone( strcat( "_dynamic/gecko/menu/",  ftos( _gecko_instanceNumber ) ) );
28                 _gecko_instanceNumber+=1;
29                 // TODO: add error checks
30                 gecko_create( me.texturePath );
31         }
32         gecko_navigate( me.texturePath, URI );
33 }
34
35 void drawGecko(entity me)
36 {
37         vector drawSize;
38   
39         if( me.texturePath ) {
40                 /* The gecko browser is actually only drawn to a part of the
41                    texture. Correct scaling so that part fills up the whole
42                    item area. */
43                 drawSize_x = 1.0 / me.textureExtent_x;
44                 drawSize_y = 1.0 / me.textureExtent_y;
45                 draw_Picture( '0 0 0', strcat( "/", me.texturePath ), 
46                         drawSize, '1 1 1', 1.0 );
47         } else {
48                 local vector fontsize;
49                 fontsize_x = fontsize_y = 1.0 / 30.0;
50                 fontsize_z = 0.0;
51                 draw_Text( '0 0 0', "Browser not initialized!", fontsize, '1 1 1', 1.0, 0 );
52         }
53 }
54
55 float keyDownGecko(entity me, float scan, float ascii, float shift)
56 {
57         if( scan == K_ESCAPE ) {
58                 return 0;
59         }
60         return gecko_keyevent( me.texturePath, scan, GECKO_BUTTON_DOWN );
61 }
62
63 float keyUpGecko(entity me, float scan, float ascii, float shift)
64 {
65         return gecko_keyevent( me.texturePath, scan, GECKO_BUTTON_UP );
66 }
67
68 float mouseMoveGecko(entity me, vector pos)
69 {
70         gecko_mousemove( me.texturePath, pos_x, pos_y );
71         return 1;
72 }
73
74 float mousePressGecko(entity me, vector pos)
75 {
76         return gecko_keyevent( me.texturePath, K_MOUSE1, GECKO_BUTTON_DOWN );
77 }
78
79 float mouseDragGecko(entity me, vector pos)
80 {
81         gecko_mousemove( me.texturePath, pos_x, pos_y );
82         return 1;
83 }
84
85 float mouseReleaseGecko(entity me, vector pos)
86 {
87         return gecko_keyevent( me.texturePath, K_MOUSE1, GECKO_BUTTON_UP );
88 }
89
90 void resizeNotifyGecko(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
91 {
92         me.origin = absOrigin;
93         me.size = absSize;
94         gecko_resize( me.texturePath, absSize_x, absSize_y );
95         me.textureExtent = gecko_get_texture_extent( me.texturePath );
96 }
97
98 string toStringGecko(entity me)
99 {
100         return me.texturePath;
101 }
102
103 #endif