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