Mercurial > mplayer.hg
annotate gui/ui/playbar.c @ 37053:84c93a60ead3
Add new item 'rpotmeter'.
This is the missing counterpart to hpotmeter and vpotmeter
allowing rotary control elements in a GUI skin now.
Based on an idea and a realization by Hans-Dieter Kosch,
hdkosch kabelbw de.
Additionally, update (and revise) documentation.
author | ib |
---|---|
date | Sat, 12 Apr 2014 23:29:29 +0000 |
parents | 2ef6693131f7 |
children |
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 |
34699
ed0e00db4306
Cosmetic: Move, change and add some comments on GUI windows.
ib
parents:
34697
diff
changeset
|
19 /* playbar window */ |
ed0e00db4306
Cosmetic: Move, change and add some comments on GUI windows.
ib
parents:
34697
diff
changeset
|
20 |
37053 | 21 #include <math.h> |
23077 | 22 #include <stdlib.h> |
23 #include <stdio.h> | |
24 #include <sys/stat.h> | |
25 #include <unistd.h> | |
23305
22d3d12c6dfb
Include string.h for memcpy, fastmemcpy.h alone is not enough.
reimar
parents:
23077
diff
changeset
|
26 #include <string.h> |
23077 | 27 |
35525 | 28 #include "gui/app/app.h" |
29 #include "gui/app/gui.h" | |
33738 | 30 #include "gui/interface.h" |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
31 #include "gui/skin/font.h" |
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
32 #include "gui/skin/skin.h" |
33739 | 33 #include "gui/util/mem.h" |
37026
b6ff1451035d
Constrain an item's value to be in the range of 0 to 100.
ib
parents:
37023
diff
changeset
|
34 #include "gui/util/misc.h" |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
35 #include "gui/wm/ws.h" |
23077 | 36 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
37 #include "help_mp.h" |
35783 | 38 #include "mp_msg.h" |
33024 | 39 #include "mp_core.h" |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
40 #include "libvo/x11_common.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
41 #include "libvo/fastmemcpy.h" |
23077 | 42 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
43 #include "stream/stream.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
44 #include "mixer.h" |
32467 | 45 #include "sub/sub.h" |
23077 | 46 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
47 #include "libmpdemux/demuxer.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
48 #include "libmpdemux/stheader.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
49 #include "codec-cfg.h" |
23077 | 50 |
35528 | 51 #include "ui.h" |
33556 | 52 #include "actions.h" |
35529 | 53 #include "gui/dialog/dialog.h" |
33556 | 54 #include "render.h" |
23077 | 55 |
28051 | 56 unsigned int GetTimerMS( void ); |
57 unsigned int GetTimer( void ); | |
23077 | 58 |
33555 | 59 unsigned char * playbarDrawBuffer = NULL; |
37023 | 60 int playbarVisible = False; |
61 int playbarLength = 0; | |
62 int uiPlaybarFade = 0; | |
23077 | 63 |
33555 | 64 static void uiPlaybarDraw( void ) |
23077 | 65 { |
66 int x; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
67 |
34697 | 68 if ( !guiApp.videoWindow.isFullScreen ) return; |
33555 | 69 if ( !playbarVisible || !guiApp.playbarIsPresent ) return; |
23077 | 70 |
34697 | 71 // guiApp.playbar.x=( guiApp.videoWindow.Width - guiApp.playbar.width ) / 2; |
33555 | 72 switch( guiApp.playbar.x ) |
23077 | 73 { |
34697 | 74 case -1: x=( guiApp.videoWindow.Width - guiApp.playbar.width ) / 2; break; |
75 case -2: x=( guiApp.videoWindow.Width - guiApp.playbar.width ); break; | |
33555 | 76 default: x=guiApp.playbar.x; |
23077 | 77 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
78 |
33555 | 79 switch ( uiPlaybarFade ) |
23077 | 80 { |
81 case 1: // fade in | |
33555 | 82 playbarLength--; |
34697 | 83 if ( guiApp.videoWindow.Height - guiApp.playbar.height >= playbarLength ) |
37023 | 84 { |
85 playbarLength=guiApp.videoWindow.Height - guiApp.playbar.height; | |
86 uiPlaybarFade=0; | |
87 wsMouseVisibility(&guiApp.videoWindow, wsShowMouseCursor); | |
88 } | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
89 wsWindowMove( &guiApp.playbarWindow,True,x,playbarLength ); |
37023 | 90 break; |
23077 | 91 case 2: // fade out |
37023 | 92 playbarLength+=10; |
93 if ( playbarLength > guiApp.videoWindow.Height ) | |
94 { | |
95 playbarLength=guiApp.videoWindow.Height; | |
96 uiPlaybarFade=0; | |
97 playbarVisible=False; | |
36929 | 98 wsMouseVisibility(&guiApp.videoWindow, wsHideMouseCursor); |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
99 wsWindowVisibility( &guiApp.playbarWindow,wsHideWindow ); |
37023 | 100 return; |
101 } | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
102 wsWindowMove( &guiApp.playbarWindow,True,x,playbarLength ); |
37023 | 103 break; |
23077 | 104 } |
105 | |
34684 | 106 /* render */ |
33555 | 107 if ( guiApp.playbarWindow.State == wsWindowExpose ) |
23077 | 108 { |
33555 | 109 btnModify( evSetMoviePosition,guiInfo.Position ); |
110 btnModify( evSetVolume,guiInfo.Volume ); | |
36930 | 111 btnModify( evSetBalance,guiInfo.Balance ); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
112 |
36929 | 113 wsMouseVisibility(&guiApp.videoWindow, wsShowMouseCursor); |
23077 | 114 |
33555 | 115 fast_memcpy( playbarDrawBuffer,guiApp.playbar.Bitmap.Image,guiApp.playbar.Bitmap.ImageSize ); |
116 RenderAll( &guiApp.playbarWindow,guiApp.playbarItems,guiApp.IndexOfPlaybarItems,playbarDrawBuffer ); | |
35744 | 117 wsImageRender( &guiApp.playbarWindow,playbarDrawBuffer ); |
23077 | 118 } |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
119 wsImageDraw( &guiApp.playbarWindow ); |
23077 | 120 } |
121 | |
35762 | 122 static void uiPlaybarMouse( int Button, int X, int Y, int RX, int RY ) |
23077 | 123 { |
124 static int itemtype = 0; | |
125 int i; | |
35688 | 126 guiItem * item = NULL; |
37053 | 127 static double prev_point; |
128 double point; | |
37023 | 129 float value = 0.0f; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
130 |
23077 | 131 static int SelectedItem = -1; |
37023 | 132 int currentselected = -1; |
37053 | 133 static int endstop; |
23077 | 134 |
33555 | 135 for ( i=0;i <= guiApp.IndexOfPlaybarItems;i++ ) |
136 if ( ( guiApp.playbarItems[i].pressed != btnDisabled )&& | |
35675 | 137 ( isInside( X,Y,guiApp.playbarItems[i].x,guiApp.playbarItems[i].y,guiApp.playbarItems[i].x+guiApp.playbarItems[i].width,guiApp.playbarItems[i].y+guiApp.playbarItems[i].height ) ) ) |
23077 | 138 { currentselected=i; break; } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
139 |
23077 | 140 switch ( Button ) |
141 { | |
142 case wsPMMouseButton: | |
34333 | 143 gtkShow( ivHidePopUpMenu,NULL ); |
35766
16ed8155439b
Rename uiShowMenu() uiMenuShow() and uiHideMenu() uiMenuHide().
ib
parents:
35765
diff
changeset
|
144 uiMenuShow( RX,RY ); |
23077 | 145 break; |
146 case wsRMMouseButton: | |
35766
16ed8155439b
Rename uiShowMenu() uiMenuShow() and uiHideMenu() uiMenuHide().
ib
parents:
35765
diff
changeset
|
147 uiMenuHide( RX,RY,0 ); |
23077 | 148 break; |
149 case wsRRMouseButton: | |
34333 | 150 gtkShow( ivShowPopUpMenu,NULL ); |
37023 | 151 break; |
34684 | 152 /* --- */ |
23077 | 153 case wsPLMouseButton: |
37023 | 154 gtkShow( ivHidePopUpMenu,NULL ); |
23077 | 155 SelectedItem=currentselected; |
156 if ( SelectedItem == -1 ) break; // yeees, i'm move the fucking window | |
33555 | 157 item=&guiApp.playbarItems[SelectedItem]; |
37023 | 158 itemtype=item->type; |
159 item->pressed=btnPressed; | |
23077 | 160 |
37023 | 161 switch( item->type ) |
162 { | |
163 case itButton: | |
164 if ( ( SelectedItem > -1 ) && | |
165 ( ( ( item->message == evPlaySwitchToPause && item->message == evPauseSwitchToPlay ) ) || | |
166 ( ( item->message == evPauseSwitchToPlay && item->message == evPlaySwitchToPause ) ) ) ) | |
167 { item->pressed=btnDisabled; } | |
168 break; | |
37053 | 169 case itRPotmeter: |
170 prev_point=appRadian( item, X - item->x, Y - item->y ) - item->zeropoint; | |
171 if ( prev_point < 0.0 ) prev_point+=2*M_PI; | |
172 if ( prev_point <= item->arclength ) endstop=False; | |
173 else endstop=STOPPED_AT_0 + STOPPED_AT_100; // block movement | |
174 break; | |
37023 | 175 } |
23077 | 176 |
37023 | 177 break; |
23077 | 178 case wsRLMouseButton: |
37052
2ef6693131f7
Cosmetic: Shorten comment (and phrase more precisely).
ib
parents:
37026
diff
changeset
|
179 if ( SelectedItem != -1 ) // NOTE TO MYSELF: only if hasButton |
33107 | 180 { |
33555 | 181 item=&guiApp.playbarItems[SelectedItem]; |
33108 | 182 item->pressed=btnReleased; |
33107 | 183 } |
37023 | 184 if ( currentselected == - 1 || SelectedItem == -1 ) { itemtype=0; break; } |
185 SelectedItem=-1; | |
186 value=0; | |
23077 | 187 |
37023 | 188 switch( itemtype ) |
189 { | |
190 case itHPotmeter: | |
191 value=100.0 * ( X - item->x ) / item->width; | |
192 break; | |
193 case itVPotmeter: | |
194 value=100.0 - 100.0 * ( Y - item->y ) / item->height; | |
195 break; | |
37053 | 196 case itRPotmeter: |
197 if ( endstop ) { itemtype=0; return; } | |
198 point=appRadian( item, X - item->x, Y - item->y ) - item->zeropoint; | |
199 if ( point < 0.0 ) point+=2*M_PI; | |
200 value=100.0 * point / item->arclength; | |
201 break; | |
37023 | 202 } |
203 uiEvent( item->message,value ); | |
23077 | 204 |
37023 | 205 itemtype=0; |
206 break; | |
34684 | 207 /* --- */ |
23077 | 208 case wsP5MouseButton: value=-2.5f; goto rollerhandled; |
209 case wsP4MouseButton: value= 2.5f; | |
210 rollerhandled: | |
35365 | 211 if (currentselected != - 1) |
212 { | |
35366 | 213 item=&guiApp.playbarItems[currentselected]; |
37053 | 214 if ( ( item->type == itHPotmeter )||( item->type == itVPotmeter )||( item->type == itRPotmeter ) ) |
35366 | 215 { |
37026
b6ff1451035d
Constrain an item's value to be in the range of 0 to 100.
ib
parents:
37023
diff
changeset
|
216 item->value=constrain(item->value + value); |
35773 | 217 uiEvent( item->message,item->value ); |
35366 | 218 } |
37023 | 219 } |
220 break; | |
34684 | 221 /* --- */ |
23077 | 222 case wsMoveMouse: |
33555 | 223 item=&guiApp.playbarItems[SelectedItem]; |
37023 | 224 switch ( itemtype ) |
225 { | |
226 case itPRMButton: | |
227 if (guiApp.menuIsPresent) guiApp.menuWindow.MouseHandler( 0,RX,RY,0,0 ); | |
228 break; | |
37053 | 229 case itRPotmeter: |
230 point=appRadian( item, X - item->x, Y - item->y ) - item->zeropoint; | |
231 if ( point < 0.0 ) point+=2*M_PI; | |
232 if ( item->arclength < 2 * M_PI ) | |
233 /* a potmeter with separated 0% and 100% positions */ | |
234 { | |
235 value=item->value; | |
236 if ( point - prev_point > M_PI ) | |
237 /* turned beyond the 0% position */ | |
238 { | |
239 if ( !endstop ) | |
240 { | |
241 endstop=STOPPED_AT_0; | |
242 value=0.0f; | |
243 } | |
244 } | |
245 else if ( prev_point - point > M_PI ) | |
246 /* turned back from beyond the 0% position */ | |
247 { | |
248 if ( endstop == STOPPED_AT_0 ) endstop=False; | |
249 } | |
250 else if ( prev_point <= item->arclength && point > item->arclength ) | |
251 /* turned beyond the 100% position */ | |
252 { | |
253 if ( !endstop ) | |
254 { | |
255 endstop=STOPPED_AT_100; | |
256 value=100.0f; | |
257 } | |
258 } | |
259 else if ( prev_point > item->arclength && point <= item->arclength ) | |
260 /* turned back from beyond the 100% position */ | |
261 { | |
262 if ( endstop == STOPPED_AT_100 ) endstop=False; | |
263 } | |
264 } | |
265 if ( !endstop ) value=100.0 * point / item->arclength; | |
266 prev_point=point; | |
267 goto potihandled; | |
37023 | 268 case itVPotmeter: |
37026
b6ff1451035d
Constrain an item's value to be in the range of 0 to 100.
ib
parents:
37023
diff
changeset
|
269 value=100.0 - 100.0 * ( Y - item->y ) / item->height; |
37023 | 270 goto potihandled; |
271 case itHPotmeter: | |
37026
b6ff1451035d
Constrain an item's value to be in the range of 0 to 100.
ib
parents:
37023
diff
changeset
|
272 value=100.0 * ( X - item->x ) / item->width; |
23077 | 273 potihandled: |
37026
b6ff1451035d
Constrain an item's value to be in the range of 0 to 100.
ib
parents:
37023
diff
changeset
|
274 item->value=constrain(value); |
37023 | 275 uiEvent( item->message,item->value ); |
276 break; | |
277 } | |
23077 | 278 break; |
279 } | |
280 } | |
281 | |
33555 | 282 void uiPlaybarInit( void ) |
23077 | 283 { |
33555 | 284 if ( !guiApp.playbarIsPresent ) return; |
23077 | 285 |
33555 | 286 if ( ( playbarDrawBuffer = malloc( guiApp.playbar.Bitmap.ImageSize ) ) == NULL ) |
23077 | 287 { |
36694 | 288 gmp_msg( MSGT_GPLAYER,MSGL_FATAL,"[playbar] " MSGTR_GUI_MSG_MemoryErrorWindow ); |
33768 | 289 mplayer( MPLAYER_EXIT_GUI, EXIT_ERROR, 0 ); |
23077 | 290 } |
291 | |
34697 | 292 guiApp.playbarWindow.Parent=guiApp.videoWindow.WindowID; |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
293 wsWindowCreate( &guiApp.playbarWindow, |
33555 | 294 guiApp.playbar.x,guiApp.playbar.y,guiApp.playbar.width,guiApp.playbar.height, |
35683
75155d8a9c7e
Remove parameter for border_width from wsWindowCreate().
ib
parents:
35681
diff
changeset
|
295 wsHideFrame|wsHideWindow,wsShowMouseCursor|wsHandleMouseButton|wsHandleMouseMove,"PlayBar" ); |
23077 | 296 |
35783 | 297 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[playbar] playbarWindow ID: 0x%x\n",(int)guiApp.playbarWindow.WindowID ); |
298 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
299 wsWindowShape( &guiApp.playbarWindow,guiApp.playbar.Mask.Image ); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
300 |
35761 | 301 guiApp.playbarWindow.DrawHandler=uiPlaybarDraw; |
35762 | 302 guiApp.playbarWindow.MouseHandler=uiPlaybarMouse; |
35780 | 303 guiApp.playbarWindow.KeyHandler=guiApp.mainWindow.KeyHandler; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
304 |
34697 | 305 playbarLength=guiApp.videoWindow.Height; |
23077 | 306 } |
35765 | 307 |
35796
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35783
diff
changeset
|
308 void uiPlaybarDone( void ) |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35783
diff
changeset
|
309 { |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35783
diff
changeset
|
310 nfree(playbarDrawBuffer); |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35783
diff
changeset
|
311 wsWindowDestroy(&guiApp.playbarWindow); |
36291 | 312 wsEvents(); |
35796
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35783
diff
changeset
|
313 } |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35783
diff
changeset
|
314 |
35765 | 315 void uiPlaybarShow( int y ) |
316 { | |
317 if ( !guiApp.playbarIsPresent || !gtkEnablePlayBar ) return; | |
318 if ( !guiApp.videoWindow.isFullScreen ) return; | |
319 | |
320 if ( y > guiApp.videoWindow.Height - guiApp.playbar.height ) | |
321 { | |
322 if ( !uiPlaybarFade ) wsWindowVisibility( &guiApp.playbarWindow,wsShowWindow ); | |
323 uiPlaybarFade=1; playbarVisible=True; wsWindowRedraw( &guiApp.playbarWindow ); | |
324 } | |
325 else if ( !uiPlaybarFade ) uiPlaybarFade=2; | |
326 } |