]> icculus.org git repositories - divverent/nexuiz.git/blob - data/source/base/gfx.qc
give menu source its own directory
[divverent/nexuiz.git] / data / source / base / gfx.qc
1 // NG-Menu
2 // base/gfx.qc
3
4 float _Gfx_FPS;
5 float _Gfx_LastTime;
6 float _Gfx_FrameCount;
7
8 void() _Gfx_UpdateFPS =
9 {
10         local float lDeltaTime;
11
12         _Gfx_FrameCount = _Gfx_FrameCount + 1;
13
14         lDeltaTime = Timer_Time - _Gfx_LastTime;
15         if( GFX_SHOWFPS_DURATION < lDeltaTime ) {
16                 _Gfx_FPS = _Gfx_FrameCount / lDeltaTime;
17                 _Gfx_LastTime = Timer_Time;
18                 _Gfx_FrameCount = 0;
19         }
20 };
21
22 // cvar ngmenu_menu_height
23 void() _Gfx_UpdateRes =
24 {
25         Gfx_Real_Width = cvar( "vid_conwidth" );
26         Gfx_Real_Height = cvar( "vid_conheight" );
27         Gfx_Menu_Width = cvar( CVAR_SCMENU_MENU_WIDTH );
28         Gfx_Menu_Height = cvar( CVAR_SCMENU_MENU_HEIGHT );
29
30         if( Gfx_Menu_Width == 0.0 )
31                 Gfx_Menu_Width = GFX_MENU_DEFAULT_WIDTH;
32         if( Gfx_Menu_Height == 0.0 )
33                 Gfx_Menu_Height = GFX_MENU_DEFAULT_HEIGHT;
34 };
35
36 void() Gfx_Init =
37 {
38         local string lWidth, lHeight;
39
40         lWidth = ftos( GFX_MENU_DEFAULT_WIDTH );
41         lHeight = ftos( GFX_MENU_DEFAULT_HEIGHT );
42
43         registercvar( CVAR_SCMENU_MENU_WIDTH, lWidth, CVAR_SAVE );
44         registercvar( CVAR_SCMENU_MENU_HEIGHT, lHeight, CVAR_SAVE );
45
46         registercvar( CVAR_SCMENU_SHOWFPS, ftos( GFX_SHOWFPS_DEFAULT ), 0 );
47
48         _Gfx_UpdateRes();
49 };
50
51 void() Gfx_Quit =
52 {
53 };
54
55 void() Gfx_Display =
56 {
57         Gfx_ResetClipArea();
58 };
59
60 void() Gfx_Hide =
61 {
62 };
63
64 void() Gfx_Update =
65 {
66         _Gfx_UpdateRes();
67         _Gfx_UpdateFPS();
68 };
69
70 void() Gfx_Draw =
71 {
72         if( cvar( CVAR_SCMENU_SHOWFPS ) ) {
73                 local string lText;
74                 local vector lScale;
75                 local vector lPosition;
76
77                 lText = strcat( "FPS: ", ftos( floor( _Gfx_FPS ) ) );
78                 lScale = '15 15 0';
79
80                 lPosition_x = 0;
81                 lPosition_y = Gfx_Menu_Height - lScale_y - 5;
82                 lPosition_z = 0;
83
84                 Gfx_DrawString( lPosition, lText, lScale, '1.0 1.0 1.0', 1.0, 0 );
85         }
86 };
87
88 bool( string pPic )     Gfx_IsCached =
89 {
90         return iscachedpic( pPic );
91 };
92
93 bool( string pPic )     Gfx_Precache =
94 {
95         if( pPic == "" )
96                 return false;
97
98         if( iscachedpic( pPic ) )
99                 return true;
100         if( precache_pic( pPic ) == pPic )
101                 return true;
102         return false;
103 };
104
105 void( string pPic )     Gfx_Free
106 {
107         // DO NOTHING UNTIL A REF COUNTER IS IMPLEMENTED
108 };
109
110 vector( string pPic )   Gfx_GetImageSize
111 {
112         return drawgetimagesize( pPic );
113 };
114
115 vector( vector pPos )  Gfx_ConToMen =
116 {
117         pPos_x = pPos_x * Gfx_Menu_Width / Gfx_Real_Width;
118         pPos_y = pPos_y * Gfx_Menu_Height / Gfx_Real_Height;
119         pPos_z = 0.0;
120
121         return pPos;
122 };
123
124 vector( vector pPos )  Gfx_MenToCon =
125 {
126         pPos_x = pPos_x * Gfx_Real_Width / Gfx_Menu_Width;
127         pPos_y = pPos_y * Gfx_Real_Height / Gfx_Menu_Height;
128         pPos_z = 0.0;
129
130         return pPos;
131 };
132
133 void() Gfx_ResetClipArea =
134 {
135         drawresetcliparea();
136 };
137
138 vector( vector pPosition ) _Gfx_FitCenter =
139 {
140         return (pPosition + '0.375 0.375 0');
141 };
142
143 float( vector pPosition, float pCharacter, vector pScale, vector pRGB, float pAlpha, float pFlag )
144 Gfx_DrawCharacter =
145 {
146         pPosition = _Gfx_FitCenter( Gfx_MenToCon( pPosition ) );
147         pScale = Gfx_MenToCon( pScale );
148
149         return drawcharacter( pPosition, pCharacter, pScale, pRGB, pAlpha, pFlag );
150 };
151
152 float( vector pPosition, string pText, vector pScale, vector pRGB, float pAlpha, float pFlag )
153 Gfx_DrawString =
154 {
155         pPosition = _Gfx_FitCenter( Gfx_MenToCon( pPosition ) );
156         pScale = Gfx_MenToCon( pScale );
157
158         return drawstring( pPosition, pText, pScale, pRGB, pAlpha, pFlag );
159 };
160
161 float( vector pPosition, string pPicture, vector pSize, vector pRGB, float pAlpha, float pFlag )
162 Gfx_DrawPic =
163 {
164         pPosition = _Gfx_FitCenter( Gfx_MenToCon( pPosition ) );
165         pSize = Gfx_MenToCon( pSize );
166
167         return drawpic( pPosition, pPicture, pSize, pRGB, pAlpha, pFlag );
168 };
169
170 float( vector pPosition, vector pSize, vector pRGB, float pAlpha, float pFlag )
171 Gfx_Fill =
172 {
173         pPosition = _Gfx_FitCenter( Gfx_MenToCon( pPosition ) );
174         pSize = Gfx_MenToCon( pSize );
175
176         return drawfill( pPosition, pSize, pRGB, pAlpha, pFlag );
177 };
178
179 void( float pX, float pY, float pWidth, float pHeight )
180 Gfx_SetClipArea =
181 {
182         local vector lPosition, lSize;
183
184         lPosition_x = pX;
185         lPosition_y = pY;
186
187         lSize_x = pWidth;
188         lSize_y = pHeight;
189
190         lPosition = _Gfx_FitCenter( Gfx_MenToCon( lPosition ) );
191         lSize = Gfx_MenToCon( lSize ) + '1 1 0';
192
193         drawsetcliparea( lPosition_x, lPosition_y, lSize_x, lSize_y );
194 };