Add const where appropriate, also gets rid of a compiler warning.
[mplayer/glamo.git] / gui / app.c
bloba389013c984e0ed912b4ebdead98fd5ed2b28d6b
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <string.h>
23 #include "config.h"
24 #include "mp_msg.h"
25 #include "help_mp.h"
27 #include "app.h"
28 #include "wm/wskeys.h"
29 #include "skin/skin.h"
30 #include "mplayer/gmplayer.h"
31 #include "interface.h"
33 static const evName evNames[] =
35 { evNone, "evNone" },
36 { evPlay, "evPlay" },
37 { evStop, "evStop" },
38 { evPause, "evPause" },
39 { evPrev, "evPrev" },
40 { evNext, "evNext" },
41 { evLoad, "evLoad" },
42 { evEqualizer, "evEqualizer" },
43 { evEqualizer, "evEqualeaser" },
44 { evPlayList, "evPlaylist" },
45 { evExit, "evExit" },
46 { evIconify, "evIconify" },
47 { evIncBalance, "evIncBalance" },
48 { evDecBalance, "evDecBalance" },
49 { evFullScreen, "evFullScreen" },
50 { evFName, "evFName" },
51 { evMovieTime, "evMovieTime" },
52 { evAbout, "evAbout" },
53 { evLoadPlay, "evLoadPlay" },
54 { evPreferences, "evPreferences" },
55 { evSkinBrowser, "evSkinBrowser" },
56 { evBackward10sec, "evBackward10sec" },
57 { evForward10sec, "evForward10sec" },
58 { evBackward1min, "evBackward1min" },
59 { evForward1min, "evForward1min" },
60 { evBackward10min, "evBackward10min" },
61 { evForward10min, "evForward10min" },
62 { evIncVolume, "evIncVolume" },
63 { evDecVolume, "evDecVolume" },
64 { evMute, "evMute" },
65 { evIncAudioBufDelay, "evIncAudioBufDelay" },
66 { evDecAudioBufDelay, "evDecAudioBufDelay" },
67 { evPlaySwitchToPause, "evPlaySwitchToPause" },
68 { evPauseSwitchToPlay, "evPauseSwitchToPlay" },
69 { evNormalSize, "evHalfSize" },
70 { evNormalSize, "evNormalSize" },
71 { evDoubleSize, "evDoubleSize" },
72 { evSetMoviePosition, "evSetMoviePosition" },
73 { evSetVolume, "evSetVolume" },
74 { evSetBalance, "evSetBalance" },
75 { evHelp, "evHelp" },
76 { evLoadSubtitle, "evLoadSubtitle" },
77 { evPlayDVD, "evPlayDVD" },
78 { evPlayVCD, "evPlayVCD" },
79 { evSetURL, "evSetURL" },
80 { evLoadAudioFile, "evLoadAudioFile" },
81 { evDropSubtitle, "evDropSubtitle" },
82 { evSetAspect, "evSetAspect" }
85 static const int evBoxs = sizeof( evNames ) / sizeof( evName );
87 // ---
89 listItems appMPlayer;
91 /* FIXME: Eventually remove the obsolete directory names. */
92 char * skinDirInHome=NULL;
93 char * skinDirInHome_obsolete=NULL;
94 char * skinMPlayerDir=NULL;
95 char * skinMPlayerDir_obsolete=NULL;
96 char * skinName = NULL;
98 void appClearItem( wItem * item )
100 item->type=0;
101 // ---
102 item->x=0; item->y=0; item->width=0; item->height=0;
103 // ---
104 item->px=0; item->py=0; item->psx=0; item->psy=0;
105 // ---
106 item->msg=0; item->msg2=0;
107 item->pressed=btnReleased;
108 item->tmp=0;
109 item->key=0; item->key2=0;
110 item->Bitmap.Width=0; item->Bitmap.Height=0; item->Bitmap.BPP=0; item->Bitmap.ImageSize=0;
111 if ( item->Bitmap.Image ) free( item->Bitmap.Image );
112 item->Bitmap.Image=NULL;
113 // ---
114 item->fontid=0;
115 if ( item->label ) free( item->label ); item->label=NULL;
116 item->event=0;
119 void appCopy( listItems * dest,listItems * source )
121 dest->NumberOfItems=source->NumberOfItems;
122 memcpy( &dest->Items,&source->Items,128 * sizeof( wItem ) );
124 dest->NumberOfMenuItems=source->NumberOfMenuItems;
125 memcpy( &dest->MenuItems,&source->MenuItems,32 * sizeof( wItem ) );
127 memcpy( &dest->main,&source->main,sizeof( wItem ) );
128 memcpy( &dest->sub,&source->sub,sizeof( wItem ) );
129 memcpy( &dest->menuBase,&source->menuBase,sizeof( wItem ) );
130 memcpy( &dest->menuSelected,&source->menuSelected,sizeof( wItem ) );
133 void appInitStruct( listItems * item )
135 int i;
136 for ( i=0;i<item->NumberOfItems;i++ )
137 appClearItem( &item->Items[i] );
138 for ( i=0;i<item->NumberOfMenuItems;i++ )
139 appClearItem( &item->MenuItems[i] );
140 for ( i=0;i<item->NumberOfBarItems;i++ )
141 appClearItem( &item->barItems[i] );
143 item->NumberOfItems=-1;
144 memset( item->Items,0,256 * sizeof( wItem ) );
145 item->NumberOfMenuItems=-1;
146 memset( item->MenuItems,0,64 * sizeof( wItem ) );
147 item->NumberOfBarItems=-1;
148 memset( item->barItems,0,256 * sizeof( wItem ) );
150 appClearItem( &item->main );
151 item->mainDecoration=0;
152 appClearItem( &item->sub );
153 item->sub.width=0; item->sub.height=0;
154 item->sub.x=-1; item->sub.y=-1;
155 appClearItem( &item->menuBase );
156 appClearItem( &item->menuSelected );
157 item->sub.R=item->sub.G=item->sub.B=0;
158 item->bar.R=item->bar.G=item->bar.B=0;
159 item->main.R=item->main.G=item->main.B=0;
160 item->barIsPresent=0;
161 item->menuIsPresent=0;
164 int appFindKey( unsigned char * name )
166 int i;
167 for ( i=0;i<wsKeyNumber;i++ )
168 if ( !strcmp( wsKeyNames[i].name,name ) ) return wsKeyNames[i].code;
169 return -1;
172 int appFindMessage( unsigned char * str )
174 int i;
175 for ( i=0;i<evBoxs;i++ )
176 if ( !strcmp( evNames[i].name,str ) ) return evNames[i].msg;
177 return -1;
180 void btnModify( int event,float state )
182 int j;
183 for ( j=0;j < appMPlayer.NumberOfItems + 1;j++ )
184 if ( appMPlayer.Items[j].msg == event )
186 switch ( appMPlayer.Items[j].type )
188 case itButton:
189 appMPlayer.Items[j].pressed=(int)state;
190 appMPlayer.Items[j].tmp=(int)state;
191 break;
192 case itPotmeter:
193 case itVPotmeter:
194 case itHPotmeter:
195 if ( state < 0.0f ) state=0.0f;
196 if ( state > 100.f ) state=100.0f;
197 appMPlayer.Items[j].value=state;
198 break;
202 for ( j=0;j < appMPlayer.NumberOfBarItems + 1;j++ )
203 if ( appMPlayer.barItems[j].msg == event )
205 switch ( appMPlayer.barItems[j].type )
207 case itButton:
208 appMPlayer.barItems[j].pressed=(int)state;
209 appMPlayer.barItems[j].tmp=(int)state;
210 break;
211 case itPotmeter:
212 case itVPotmeter:
213 case itHPotmeter:
214 if ( state < 0.0f ) state=0.0f;
215 if ( state > 100.f ) state=100.0f;
216 appMPlayer.barItems[j].value=state;
217 break;
222 float btnGetValue( int event )
224 int j;
225 for ( j=0;j<appMPlayer.NumberOfItems + 1;j++ )
226 if ( appMPlayer.Items[j].msg == event ) return appMPlayer.Items[j].value;
227 return 0;
230 void btnSet( int event,int set )
232 int j;
233 for ( j=0;j<appMPlayer.NumberOfItems + 1;j++ )
234 if ( appMPlayer.Items[j].msg == event )
235 { appMPlayer.Items[j].pressed=set; appMPlayer.barItems[j].tmp=0; }
236 for ( j=0;j<appMPlayer.NumberOfBarItems + 1;j++ )
237 if ( appMPlayer.barItems[j].msg == event )
238 { appMPlayer.barItems[j].pressed=set; appMPlayer.barItems[j].tmp=0; }