Mercurial > mplayer.hg
annotate gui/app.c @ 34423:536ab2e339b8
Remove pointless menu entry.
There is only a SubMenu, if there are entries,
so we don't need a "none" entry.
author | ib |
---|---|
date | Thu, 05 Jan 2012 13:55:03 +0000 |
parents | 0ba85cad4c7e |
children | 1e84148527ab |
rev | line source |
---|---|
26458 | 1 /* |
2 * This file is part of MPlayer. | |
3 * | |
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. | |
8 * | |
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. | |
13 * | |
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. | |
17 */ | |
23077 | 18 |
34327 | 19 /** |
20 * @file | |
21 * @brief GUI application helpers | |
22 */ | |
23 | |
23077 | 24 #include "app.h" |
32983 | 25 #include "skin/font.h" |
32921 | 26 |
32944 | 27 #include "libavutil/common.h" |
28 | |
33979 | 29 /** |
30 * @brief Initialize item counters. | |
31 */ | |
33555 | 32 guiItems guiApp = { |
33 .IndexOfMainItems = -1, | |
34 .IndexOfPlaybarItems = -1, | |
35 .IndexOfMenuItems = -1 | |
33266 | 36 }; |
32897 | 37 |
33979 | 38 /** |
34327 | 39 * @brief Event messages belonging to event names. |
33979 | 40 */ |
32897 | 41 static const evName evNames[] = { |
42 { evNone, "evNone" }, | |
43 { evPlay, "evPlay" }, | |
44 { evStop, "evStop" }, | |
45 { evPause, "evPause" }, | |
46 { evPrev, "evPrev" }, | |
47 { evNext, "evNext" }, | |
48 { evLoad, "evLoad" }, | |
34317 | 49 { evLoadPlay, "evLoadPlay" }, |
50 { evLoadAudioFile, "evLoadAudioFile" }, | |
51 { evLoadSubtitle, "evLoadSubtitle" }, | |
52 { evDropSubtitle, "evDropSubtitle" }, | |
34321
daebf766dea6
Cosmetic: Synchronize evPlaylist event and message names.
ib
parents:
34319
diff
changeset
|
53 { evPlaylist, "evPlaylist" }, |
34387 | 54 { evPlayCD, "evPlayCD" }, |
34317 | 55 { evPlayVCD, "evPlayVCD" }, |
56 { evPlayDVD, "evPlayDVD" }, | |
34324 | 57 { evLoadURL, "evSetURL" }, // legacy |
58 { evLoadURL, "evLoadURL" }, | |
34317 | 59 { evPlaySwitchToPause, "evPlaySwitchToPause" }, |
60 { evPauseSwitchToPlay, "evPauseSwitchToPlay" }, | |
32897 | 61 { evBackward10sec, "evBackward10sec" }, |
62 { evForward10sec, "evForward10sec" }, | |
63 { evBackward1min, "evBackward1min" }, | |
64 { evForward1min, "evForward1min" }, | |
65 { evBackward10min, "evBackward10min" }, | |
66 { evForward10min, "evForward10min" }, | |
34317 | 67 { evSetMoviePosition, "evSetMoviePosition" }, |
34319 | 68 { evHalfSize, "evHalfSize" }, |
34317 | 69 { evDoubleSize, "evDoubleSize" }, |
70 { evFullScreen, "evFullScreen" }, | |
71 { evNormalSize, "evNormalSize" }, | |
34322 | 72 { evSetAspect, "evSetAspect" }, |
32897 | 73 { evIncVolume, "evIncVolume" }, |
74 { evDecVolume, "evDecVolume" }, | |
34317 | 75 { evSetVolume, "evSetVolume" }, |
32897 | 76 { evMute, "evMute" }, |
34317 | 77 { evSetBalance, "evSetBalance" }, |
78 { evEqualizer, "evEqualizer" }, | |
79 { evAbout, "evAbout" }, | |
80 { evPreferences, "evPreferences" }, | |
81 { evSkinBrowser, "evSkinBrowser" }, | |
82 { evIconify, "evIconify" }, | |
34326 | 83 { evExit, "evExit" } |
32897 | 84 }; |
23077 | 85 |
33979 | 86 /** |
87 * @brief Free all memory allocated to an item and set all its pointers to NULL. | |
88 * | |
89 * @param item item to be freed | |
90 */ | |
32898 | 91 static void appClearItem(wItem *item) |
23077 | 92 { |
32917
9949f3a123cf
Add new function bpFree() to free txSamples (bitmaps).
ib
parents:
32912
diff
changeset
|
93 bpFree(&item->Bitmap); |
32921 | 94 bpFree(&item->Mask); |
32947 | 95 free(item->label); |
96 free(item->text); | |
32946 | 97 memset(item, 0, sizeof(*item)); |
23077 | 98 } |
99 | |
33979 | 100 /** |
101 * @brief Free all memory allocated to all GUI items and reset all item counters. | |
102 */ | |
32932 | 103 void appFreeStruct(void) |
23077 | 104 { |
32897 | 105 int i; |
106 | |
33555 | 107 appClearItem(&guiApp.main); |
108 guiApp.mainDecoration = 0; | |
32929 | 109 |
33555 | 110 appClearItem(&guiApp.sub); |
32929 | 111 |
33555 | 112 appClearItem(&guiApp.playbar); |
113 guiApp.playbarIsPresent = 0; | |
32929 | 114 |
33555 | 115 appClearItem(&guiApp.menu); |
116 appClearItem(&guiApp.menuSelected); | |
117 guiApp.menuIsPresent = 0; | |
32929 | 118 |
33555 | 119 for (i = 0; i <= guiApp.IndexOfMainItems; i++) |
120 appClearItem(&guiApp.mainItems[i]); | |
121 for (i = 0; i <= guiApp.IndexOfPlaybarItems; i++) | |
122 appClearItem(&guiApp.playbarItems[i]); | |
123 for (i = 0; i <= guiApp.IndexOfMenuItems; i++) | |
124 appClearItem(&guiApp.menuItems[i]); | |
32897 | 125 |
33555 | 126 guiApp.IndexOfMainItems = -1; |
127 guiApp.IndexOfPlaybarItems = -1; | |
128 guiApp.IndexOfMenuItems = -1; | |
33266 | 129 |
32933 | 130 fntFreeFont(); |
23077 | 131 } |
132 | |
33979 | 133 /** |
134 * @brief Find the event belonging to an event name. | |
135 * | |
34328 | 136 * @param name event name |
33979 | 137 * |
138 * @return event >= 0 (ok) or -1 (not found) | |
139 */ | |
34328 | 140 int appFindMessage(const char *name) |
23077 | 141 { |
32944 | 142 unsigned int i; |
32897 | 143 |
32944 | 144 for (i = 0; i < FF_ARRAY_ELEMS(evNames); i++) |
34328 | 145 if (!strcmp(evNames[i].name, name)) |
32911 | 146 return evNames[i].message; |
32897 | 147 |
148 return -1; | |
23077 | 149 } |
150 | |
33979 | 151 /** |
34339 | 152 * @brief Find the item belonging to an event. |
153 * | |
154 * @param event event | |
155 * | |
156 * @return pointer to the item (ok) or NULL (not found) | |
157 */ | |
158 wItem *appFindItem(int event) | |
159 { | |
160 wItem *item; | |
161 int i, n; | |
162 | |
163 if (guiApp.subWindow.isFullScreen && guiApp.playbarIsPresent) { | |
164 item = guiApp.playbarItems; | |
165 n = guiApp.IndexOfPlaybarItems; | |
166 } else { | |
167 item = guiApp.mainItems; | |
168 n = guiApp.IndexOfMainItems; | |
169 } | |
170 | |
171 for (i = 0; i <= n; i++) | |
172 if (item[i].message == event) | |
34353 | 173 return &item[i]; |
34339 | 174 |
175 return NULL; | |
176 } | |
177 | |
178 /** | |
33979 | 179 * @brief Modify the state (i.e. set a new value) to the item belonging to an event. |
180 * | |
181 * @param event event | |
182 * @param state new value | |
183 */ | |
32897 | 184 void btnModify(int event, float state) |
23077 | 185 { |
32897 | 186 int i; |
187 | |
33555 | 188 for (i = 0; i <= guiApp.IndexOfMainItems; i++) { |
189 if (guiApp.mainItems[i].message == event) { | |
190 switch (guiApp.mainItems[i].type) { | |
32897 | 191 case itButton: |
33555 | 192 guiApp.mainItems[i].pressed = (int)state; |
32897 | 193 break; |
23077 | 194 |
32897 | 195 case itPotmeter: |
196 case itVPotmeter: | |
197 case itHPotmeter: | |
32960 | 198 if (state < 0.0f) |
199 state = 0.0f; | |
200 if (state > 100.0f) | |
201 state = 100.0f; | |
33555 | 202 guiApp.mainItems[i].value = state; |
32897 | 203 break; |
204 } | |
205 } | |
206 } | |
207 | |
33555 | 208 for (i = 0; i <= guiApp.IndexOfPlaybarItems; i++) { |
209 if (guiApp.playbarItems[i].message == event) { | |
210 switch (guiApp.playbarItems[i].type) { | |
32897 | 211 case itButton: |
33555 | 212 guiApp.playbarItems[i].pressed = (int)state; |
32897 | 213 break; |
214 | |
215 case itPotmeter: | |
216 case itVPotmeter: | |
217 case itHPotmeter: | |
32960 | 218 if (state < 0.0f) |
219 state = 0.0f; | |
220 if (state > 100.0f) | |
221 state = 100.0f; | |
33555 | 222 guiApp.playbarItems[i].value = state; |
32897 | 223 break; |
224 } | |
225 } | |
226 } | |
23077 | 227 } |
228 | |
33979 | 229 /** |
230 * @brief Set the @a pressed state (i.e. a new value) to the item belonging to an event. | |
231 * | |
232 * @param event event | |
233 * @param set new value | |
234 */ | |
32897 | 235 void btnSet(int event, int set) |
23077 | 236 { |
32897 | 237 int i; |
238 | |
33555 | 239 for (i = 0; i <= guiApp.IndexOfMainItems; i++) |
240 if (guiApp.mainItems[i].message == event) | |
241 guiApp.mainItems[i].pressed = set; | |
32897 | 242 |
33555 | 243 for (i = 0; i <= guiApp.IndexOfPlaybarItems; i++) |
244 if (guiApp.playbarItems[i].message == event) | |
245 guiApp.playbarItems[i].pressed = set; | |
23077 | 246 } |