Mercurial > mplayer.hg
annotate gui/app.c @ 32921:448517f556a5
Fix memory leak in appClearItem().
Mask wasn't freed.
Additionally: symbolic constants are used for initialization where possible,
the pressed default is btnDisabled now, gfree() is preferred to free() and
setting NULL, and statements are rearranged according to members in structure.
author | ib |
---|---|
date | Thu, 03 Mar 2011 11:43:01 +0000 |
parents | efb929029ec9 |
children | 4546e629ae70 |
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 |
19 #include <stdlib.h> | |
20 #include <string.h> | |
21 | |
22 #include "app.h" | |
32897 | 23 |
32921 | 24 #include "gui/skin/font.h" |
25 #include "interface.h" | |
26 | |
32897 | 27 listItems appMPlayer; |
28 | |
29 static const evName evNames[] = { | |
30 { evNone, "evNone" }, | |
31 { evPlay, "evPlay" }, | |
32 { evStop, "evStop" }, | |
33 { evPause, "evPause" }, | |
34 { evPrev, "evPrev" }, | |
35 { evNext, "evNext" }, | |
36 { evLoad, "evLoad" }, | |
37 { evEqualizer, "evEqualizer" }, | |
38 { evEqualizer, "evEqualeaser" }, // NOTE TO MYSELF: any skin using this? | |
39 { evPlayList, "evPlaylist" }, | |
40 { evExit, "evExit" }, | |
41 { evIconify, "evIconify" }, | |
42 { evIncBalance, "evIncBalance" }, // NOTE TO MYSELF: not all of these events | |
43 { evDecBalance, "evDecBalance" }, // are actually implemented, and update doc | |
44 { evFullScreen, "evFullScreen" }, | |
45 { evFName, "evFName" }, | |
46 { evMovieTime, "evMovieTime" }, | |
47 { evAbout, "evAbout" }, | |
48 { evLoadPlay, "evLoadPlay" }, | |
49 { evPreferences, "evPreferences" }, | |
50 { evSkinBrowser, "evSkinBrowser" }, | |
51 { evBackward10sec, "evBackward10sec" }, | |
52 { evForward10sec, "evForward10sec" }, | |
53 { evBackward1min, "evBackward1min" }, | |
54 { evForward1min, "evForward1min" }, | |
55 { evBackward10min, "evBackward10min" }, | |
56 { evForward10min, "evForward10min" }, | |
57 { evIncVolume, "evIncVolume" }, | |
58 { evDecVolume, "evDecVolume" }, | |
59 { evMute, "evMute" }, | |
60 { evIncAudioBufDelay, "evIncAudioBufDelay" }, | |
61 { evDecAudioBufDelay, "evDecAudioBufDelay" }, | |
62 { evPlaySwitchToPause, "evPlaySwitchToPause" }, | |
63 { evPauseSwitchToPlay, "evPauseSwitchToPlay" }, | |
64 { evNormalSize, "evHalfSize" }, | |
65 { evNormalSize, "evNormalSize" }, | |
66 { evDoubleSize, "evDoubleSize" }, | |
67 { evSetMoviePosition, "evSetMoviePosition" }, | |
68 { evSetVolume, "evSetVolume" }, | |
69 { evSetBalance, "evSetBalance" }, | |
70 { evHelp, "evHelp" }, | |
71 { evLoadSubtitle, "evLoadSubtitle" }, | |
72 { evPlayDVD, "evPlayDVD" }, | |
73 { evPlayVCD, "evPlayVCD" }, | |
74 { evSetURL, "evSetURL" }, | |
75 { evLoadAudioFile, "evLoadAudioFile" }, | |
76 { evDropSubtitle, "evDropSubtitle" }, | |
77 { evSetAspect, "evSetAspect" } | |
78 }; | |
23077 | 79 |
32897 | 80 static const int evBoxs = sizeof(evNames) / sizeof(evName); |
23077 | 81 |
32898 | 82 static void appClearItem(wItem *item) |
23077 | 83 { |
32921 | 84 item->type = itNone; |
32918 | 85 item->x = 0; |
86 item->y = 0; | |
87 item->width = 0; | |
88 item->height = 0; | |
32917
9949f3a123cf
Add new function bpFree() to free txSamples (bitmaps).
ib
parents:
32912
diff
changeset
|
89 bpFree(&item->Bitmap); |
32921 | 90 bpFree(&item->Mask); |
32918 | 91 item->fontid = 0; |
32921 | 92 item->align = fntAlignLeft; |
93 gfree((void **)&item->label); | |
94 item->pwidth = 0; | |
95 item->pheight = 0; | |
96 item->numphases = 0; | |
97 item->value = 0; | |
98 item->message = evNone; | |
99 item->R = 0; | |
100 item->G = 0; | |
101 item->B = 0; | |
102 gfree((void **)&item->text); | |
32897 | 103 item->textwidth = 0; |
104 item->starttime = 0; | |
105 item->last_x = 0; | |
32921 | 106 item->pressed = btnDisabled; |
107 item->tmp = 0; | |
23077 | 108 } |
109 | |
32897 | 110 void appInitStruct(listItems *item) |
23077 | 111 { |
32897 | 112 int i; |
113 | |
32912 | 114 for (i = 0; i < item->NumberOfMainItems; i++) |
115 appClearItem(&item->mainItems[i]); | |
32897 | 116 for (i = 0; i < item->NumberOfBarItems; i++) |
117 appClearItem(&item->barItems[i]); | |
32912 | 118 for (i = 0; i < item->NumberOfMenuItems; i++) |
119 appClearItem(&item->menuItems[i]); | |
32897 | 120 |
32912 | 121 item->NumberOfMainItems = -1; |
122 memset(item->mainItems, 0, 256 * sizeof(wItem)); | |
32897 | 123 |
124 item->NumberOfMenuItems = -1; | |
32912 | 125 memset(item->menuItems, 0, 64 * sizeof(wItem)); |
23077 | 126 |
32897 | 127 item->NumberOfBarItems = -1; |
128 memset(item->barItems, 0, 256 * sizeof(wItem)); | |
129 | |
130 appClearItem(&item->main); | |
131 item->mainDecoration = 0; | |
23077 | 132 |
32897 | 133 appClearItem(&item->sub); |
134 item->sub.width = 0; | |
135 item->sub.height = 0; | |
136 item->sub.x = -1; | |
137 item->sub.y = -1; | |
138 | |
139 appClearItem(&item->menuBase); | |
140 appClearItem(&item->menuSelected); | |
141 | |
142 item->sub.R = item->sub.G = item->sub.B = 0; | |
143 item->bar.R = item->bar.G = item->bar.B = 0; | |
144 item->main.R = item->main.G = item->main.B = 0; | |
145 item->barIsPresent = 0; | |
146 item->menuIsPresent = 0; | |
23077 | 147 } |
148 | |
32897 | 149 int appFindMessage(unsigned char *str) |
23077 | 150 { |
32897 | 151 int i; |
152 | |
153 for (i = 0; i < evBoxs; i++) | |
154 if (!strcmp(evNames[i].name, str)) | |
32911 | 155 return evNames[i].message; |
32897 | 156 |
157 return -1; | |
23077 | 158 } |
159 | |
32897 | 160 void btnModify(int event, float state) |
23077 | 161 { |
32897 | 162 int i; |
163 | |
32912 | 164 for (i = 0; i < appMPlayer.NumberOfMainItems + 1; i++) { |
165 if (appMPlayer.mainItems[i].message == event) { | |
166 switch (appMPlayer.mainItems[i].type) { | |
32897 | 167 case itButton: |
32912 | 168 appMPlayer.mainItems[i].pressed = (int)state; |
169 appMPlayer.mainItems[i].tmp = (int)state; | |
32897 | 170 break; |
23077 | 171 |
32897 | 172 case itPotmeter: |
173 case itVPotmeter: | |
174 case itHPotmeter: | |
175 if (state < 0.0) | |
176 state = 0.0; | |
177 if (state > 100.0) | |
178 state = 100.0; | |
32912 | 179 appMPlayer.mainItems[i].value = state; |
32897 | 180 break; |
181 } | |
182 } | |
183 } | |
184 | |
185 for (i = 0; i < appMPlayer.NumberOfBarItems + 1; i++) { | |
32911 | 186 if (appMPlayer.barItems[i].message == event) { |
32897 | 187 switch (appMPlayer.barItems[i].type) { |
188 case itButton: | |
189 appMPlayer.barItems[i].pressed = (int)state; | |
190 appMPlayer.barItems[i].tmp = (int)state; | |
191 break; | |
192 | |
193 case itPotmeter: | |
194 case itVPotmeter: | |
195 case itHPotmeter: | |
196 if (state < 0.0) | |
197 state = 0.0; | |
198 if (state > 100.0) | |
199 state = 100.0; | |
200 appMPlayer.barItems[i].value = state; | |
201 break; | |
202 } | |
203 } | |
204 } | |
23077 | 205 } |
206 | |
32897 | 207 void btnSet(int event, int set) |
23077 | 208 { |
32897 | 209 int i; |
210 | |
32912 | 211 for (i = 0; i < appMPlayer.NumberOfMainItems + 1; i++) { |
212 if (appMPlayer.mainItems[i].message == event) { | |
213 appMPlayer.mainItems[i].pressed = set; | |
214 appMPlayer.barItems[i].tmp = 0; | |
32897 | 215 } |
216 } | |
217 | |
218 for (i = 0; i < appMPlayer.NumberOfBarItems + 1; i++) { | |
32911 | 219 if (appMPlayer.barItems[i].message == event) { |
32897 | 220 appMPlayer.barItems[i].pressed = set; |
221 appMPlayer.barItems[i].tmp = 0; | |
222 } | |
223 } | |
23077 | 224 } |