Mercurial > mplayer.hg
annotate gui/app.c @ 34353:deb52aa6ad88
Return right pointer.
Return pointer to found item, not to the start of the array.
author | ib |
---|---|
date | Mon, 12 Dec 2011 09:20:34 +0000 |
parents | f05c75392897 |
children | 0ba85cad4c7e |
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" }, |
34317 | 54 { evPlayVCD, "evPlayVCD" }, |
55 { evPlayDVD, "evPlayDVD" }, | |
34324 | 56 { evLoadURL, "evSetURL" }, // legacy |
57 { evLoadURL, "evLoadURL" }, | |
34317 | 58 { evPlaySwitchToPause, "evPlaySwitchToPause" }, |
59 { evPauseSwitchToPlay, "evPauseSwitchToPlay" }, | |
32897 | 60 { evBackward10sec, "evBackward10sec" }, |
61 { evForward10sec, "evForward10sec" }, | |
62 { evBackward1min, "evBackward1min" }, | |
63 { evForward1min, "evForward1min" }, | |
64 { evBackward10min, "evBackward10min" }, | |
65 { evForward10min, "evForward10min" }, | |
34317 | 66 { evSetMoviePosition, "evSetMoviePosition" }, |
34319 | 67 { evHalfSize, "evHalfSize" }, |
34317 | 68 { evDoubleSize, "evDoubleSize" }, |
69 { evFullScreen, "evFullScreen" }, | |
70 { evNormalSize, "evNormalSize" }, | |
34322 | 71 { evSetAspect, "evSetAspect" }, |
32897 | 72 { evIncVolume, "evIncVolume" }, |
73 { evDecVolume, "evDecVolume" }, | |
34317 | 74 { evSetVolume, "evSetVolume" }, |
32897 | 75 { evMute, "evMute" }, |
34317 | 76 { evSetBalance, "evSetBalance" }, |
77 { evEqualizer, "evEqualizer" }, | |
78 { evAbout, "evAbout" }, | |
79 { evPreferences, "evPreferences" }, | |
80 { evSkinBrowser, "evSkinBrowser" }, | |
81 { evIconify, "evIconify" }, | |
34326 | 82 { evExit, "evExit" } |
32897 | 83 }; |
23077 | 84 |
33979 | 85 /** |
86 * @brief Free all memory allocated to an item and set all its pointers to NULL. | |
87 * | |
88 * @param item item to be freed | |
89 */ | |
32898 | 90 static void appClearItem(wItem *item) |
23077 | 91 { |
32917
9949f3a123cf
Add new function bpFree() to free txSamples (bitmaps).
ib
parents:
32912
diff
changeset
|
92 bpFree(&item->Bitmap); |
32921 | 93 bpFree(&item->Mask); |
32947 | 94 free(item->label); |
95 free(item->text); | |
32946 | 96 memset(item, 0, sizeof(*item)); |
23077 | 97 } |
98 | |
33979 | 99 /** |
100 * @brief Free all memory allocated to all GUI items and reset all item counters. | |
101 */ | |
32932 | 102 void appFreeStruct(void) |
23077 | 103 { |
32897 | 104 int i; |
105 | |
33555 | 106 appClearItem(&guiApp.main); |
107 guiApp.mainDecoration = 0; | |
32929 | 108 |
33555 | 109 appClearItem(&guiApp.sub); |
32929 | 110 |
33555 | 111 appClearItem(&guiApp.playbar); |
112 guiApp.playbarIsPresent = 0; | |
32929 | 113 |
33555 | 114 appClearItem(&guiApp.menu); |
115 appClearItem(&guiApp.menuSelected); | |
116 guiApp.menuIsPresent = 0; | |
32929 | 117 |
33555 | 118 for (i = 0; i <= guiApp.IndexOfMainItems; i++) |
119 appClearItem(&guiApp.mainItems[i]); | |
120 for (i = 0; i <= guiApp.IndexOfPlaybarItems; i++) | |
121 appClearItem(&guiApp.playbarItems[i]); | |
122 for (i = 0; i <= guiApp.IndexOfMenuItems; i++) | |
123 appClearItem(&guiApp.menuItems[i]); | |
32897 | 124 |
33555 | 125 guiApp.IndexOfMainItems = -1; |
126 guiApp.IndexOfPlaybarItems = -1; | |
127 guiApp.IndexOfMenuItems = -1; | |
33266 | 128 |
32933 | 129 fntFreeFont(); |
23077 | 130 } |
131 | |
33979 | 132 /** |
133 * @brief Find the event belonging to an event name. | |
134 * | |
34328 | 135 * @param name event name |
33979 | 136 * |
137 * @return event >= 0 (ok) or -1 (not found) | |
138 */ | |
34328 | 139 int appFindMessage(const char *name) |
23077 | 140 { |
32944 | 141 unsigned int i; |
32897 | 142 |
32944 | 143 for (i = 0; i < FF_ARRAY_ELEMS(evNames); i++) |
34328 | 144 if (!strcmp(evNames[i].name, name)) |
32911 | 145 return evNames[i].message; |
32897 | 146 |
147 return -1; | |
23077 | 148 } |
149 | |
33979 | 150 /** |
34339 | 151 * @brief Find the item belonging to an event. |
152 * | |
153 * @param event event | |
154 * | |
155 * @return pointer to the item (ok) or NULL (not found) | |
156 */ | |
157 wItem *appFindItem(int event) | |
158 { | |
159 wItem *item; | |
160 int i, n; | |
161 | |
162 if (guiApp.subWindow.isFullScreen && guiApp.playbarIsPresent) { | |
163 item = guiApp.playbarItems; | |
164 n = guiApp.IndexOfPlaybarItems; | |
165 } else { | |
166 item = guiApp.mainItems; | |
167 n = guiApp.IndexOfMainItems; | |
168 } | |
169 | |
170 for (i = 0; i <= n; i++) | |
171 if (item[i].message == event) | |
34353 | 172 return &item[i]; |
34339 | 173 |
174 return NULL; | |
175 } | |
176 | |
177 /** | |
33979 | 178 * @brief Modify the state (i.e. set a new value) to the item belonging to an event. |
179 * | |
180 * @param event event | |
181 * @param state new value | |
182 */ | |
32897 | 183 void btnModify(int event, float state) |
23077 | 184 { |
32897 | 185 int i; |
186 | |
33555 | 187 for (i = 0; i <= guiApp.IndexOfMainItems; i++) { |
188 if (guiApp.mainItems[i].message == event) { | |
189 switch (guiApp.mainItems[i].type) { | |
32897 | 190 case itButton: |
33555 | 191 guiApp.mainItems[i].pressed = (int)state; |
32897 | 192 break; |
23077 | 193 |
32897 | 194 case itPotmeter: |
195 case itVPotmeter: | |
196 case itHPotmeter: | |
32960 | 197 if (state < 0.0f) |
198 state = 0.0f; | |
199 if (state > 100.0f) | |
200 state = 100.0f; | |
33555 | 201 guiApp.mainItems[i].value = state; |
32897 | 202 break; |
203 } | |
204 } | |
205 } | |
206 | |
33555 | 207 for (i = 0; i <= guiApp.IndexOfPlaybarItems; i++) { |
208 if (guiApp.playbarItems[i].message == event) { | |
209 switch (guiApp.playbarItems[i].type) { | |
32897 | 210 case itButton: |
33555 | 211 guiApp.playbarItems[i].pressed = (int)state; |
32897 | 212 break; |
213 | |
214 case itPotmeter: | |
215 case itVPotmeter: | |
216 case itHPotmeter: | |
32960 | 217 if (state < 0.0f) |
218 state = 0.0f; | |
219 if (state > 100.0f) | |
220 state = 100.0f; | |
33555 | 221 guiApp.playbarItems[i].value = state; |
32897 | 222 break; |
223 } | |
224 } | |
225 } | |
23077 | 226 } |
227 | |
33979 | 228 /** |
229 * @brief Set the @a pressed state (i.e. a new value) to the item belonging to an event. | |
230 * | |
231 * @param event event | |
232 * @param set new value | |
233 */ | |
32897 | 234 void btnSet(int event, int set) |
23077 | 235 { |
32897 | 236 int i; |
237 | |
33555 | 238 for (i = 0; i <= guiApp.IndexOfMainItems; i++) |
239 if (guiApp.mainItems[i].message == event) | |
240 guiApp.mainItems[i].pressed = set; | |
32897 | 241 |
33555 | 242 for (i = 0; i <= guiApp.IndexOfPlaybarItems; i++) |
243 if (guiApp.playbarItems[i].message == event) | |
244 guiApp.playbarItems[i].pressed = set; | |
23077 | 245 } |