annotate gui/mplayer/menu.c @ 31544:bce9cacbdeb7

Use AV_RL32 also in x86, it is well enough optimized nowadays.
author reimar
date Thu, 01 Jul 2010 20:57:40 +0000
parents 016e5fc1dead
children e06fbdd8eb46
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26458
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
1 /*
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
2 * This file is part of MPlayer.
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
3 *
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
5 * it under the terms of the GNU General Public License as published by
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
7 * (at your option) any later version.
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
8 *
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
12 * GNU General Public License for more details.
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
13 *
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
14 * You should have received a copy of the GNU General Public License along
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
17 */
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
18
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
19 #include <stdlib.h>
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
20 #include <stdio.h>
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
21 #include <inttypes.h>
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
22
26382
b2f4abcf20ed Make include paths consistent; do not use ../ in them.
diego
parents: 26365
diff changeset
23 #include "config.h"
b2f4abcf20ed Make include paths consistent; do not use ../ in them.
diego
parents: 26365
diff changeset
24 #include "help_mp.h"
b2f4abcf20ed Make include paths consistent; do not use ../ in them.
diego
parents: 26365
diff changeset
25 #include "mp_msg.h"
26365
10dfbc523184 Add gui/ prefix to some #include paths so that compilation from the
diego
parents: 26203
diff changeset
26 #include "gui/app.h"
23154
e564b9cd7290 Fix several implicit declarations of functions warnings.
diego
parents: 23077
diff changeset
27 #include "gmplayer.h"
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
28
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
29 #include "widgets.h"
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
30
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
31 unsigned char * mplMenuDrawBuffer = NULL;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
32 int mplMenuRender = 1;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
33 int mplMenuItem = -1;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
34 int mplOldMenuItem = -1;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
35 int mplMenuX,mplMenuY;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
36 static int mplMenuIsInitialized = 0;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
37
30535
016e5fc1dead GUI: Mark functions that are not used outside their files as static.
diego
parents: 30531
diff changeset
38 static void mplMenuDraw( void )
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
39 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
40 uint32_t * buf = NULL;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
41 uint32_t * drw = NULL;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
42 int x,y,tmp;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
43
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
44 if ( !appMPlayer.menuIsPresent || !appMPlayer.menuBase.Bitmap.Image ) return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
45 if ( !mplMenuRender && !appMPlayer.menuWindow.Visible ) return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
46
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
47 if ( mplMenuRender || mplMenuItem != mplOldMenuItem )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
48 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
49 memcpy( mplMenuDrawBuffer,appMPlayer.menuBase.Bitmap.Image,appMPlayer.menuBase.Bitmap.ImageSize );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
50 // ---
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
51 if ( mplMenuItem != -1 )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
52 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
53 buf=(uint32_t *)mplMenuDrawBuffer;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
54 drw=(uint32_t *)appMPlayer.menuSelected.Bitmap.Image;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
55 for ( y=appMPlayer.MenuItems[ mplMenuItem ].y; y < appMPlayer.MenuItems[ mplMenuItem ].y + appMPlayer.MenuItems[ mplMenuItem ].height; y++ )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
56 for ( x=appMPlayer.MenuItems[ mplMenuItem ].x; x < appMPlayer.MenuItems[ mplMenuItem ].x + appMPlayer.MenuItems[ mplMenuItem ].width; x++ )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
57 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
58 tmp=drw[ y * appMPlayer.menuSelected.width + x ];
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
59 if ( tmp != 0x00ff00ff ) buf[ y * appMPlayer.menuBase.width + x ]=tmp;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
60 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
61 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
62 mplOldMenuItem=mplMenuItem;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
63 // ---
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
64 wsConvert( &appMPlayer.menuWindow,mplMenuDrawBuffer,appMPlayer.menuBase.Bitmap.ImageSize );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
65 mplMenuRender=0;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
66 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
67 wsPutImage( &appMPlayer.menuWindow );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
68 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
69
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
70 void mplMenuMouseHandle( int X,int Y,int RX,int RY )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
71 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
72 int x,y,i;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
73
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
74 if ( !appMPlayer.menuBase.Bitmap.Image ) return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
75
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
76 mplMenuItem=-1;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
77 x=RX - appMPlayer.menuWindow.X;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
78 y=RY - appMPlayer.menuWindow.Y;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
79 if ( ( x < 0 ) || ( y < 0 ) || ( x > appMPlayer.menuBase.width ) || ( y > appMPlayer.menuBase.height ) )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
80 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
81 wsPostRedisplay( &appMPlayer.menuWindow );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
82 return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
83 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
84
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
85 for( i=0;i<=appMPlayer.NumberOfMenuItems;i++ )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
86 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
87 if ( wgIsRect( x,y,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
88 appMPlayer.MenuItems[i].x,appMPlayer.MenuItems[i].y,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
89 appMPlayer.MenuItems[i].x+appMPlayer.MenuItems[i].width,appMPlayer.MenuItems[i].y+appMPlayer.MenuItems[i].height ) ) { mplMenuItem=i; break; }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
90 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
91 wsPostRedisplay( &appMPlayer.menuWindow );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
92 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
93
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
94 void mplShowMenu( int mx,int my )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
95 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
96 int x,y;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
97
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
98 if ( !appMPlayer.menuIsPresent || !appMPlayer.menuBase.Bitmap.Image ) return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
99
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
100 x=mx;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
101 if ( x + appMPlayer.menuWindow.Width > wsMaxX ) x=wsMaxX - appMPlayer.menuWindow.Width - 1 + wsOrgX;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
102 y=my;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
103 if ( y + appMPlayer.menuWindow.Height > wsMaxY ) y=wsMaxY - appMPlayer.menuWindow.Height - 1 + wsOrgY;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
104
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
105 mplMenuX=x; mplMenuY=y;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
106
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
107 mplMenuItem = 0;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
108
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
109 wsMoveWindow( &appMPlayer.menuWindow,False,x,y );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
110 wsMoveTopWindow( wsDisplay,appMPlayer.menuWindow.WindowID );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
111 wsSetLayer( wsDisplay,appMPlayer.menuWindow.WindowID,1 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
112 mplMenuRender=1;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
113 wsVisibleWindow( &appMPlayer.menuWindow,wsShowWindow );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
114 wsPostRedisplay( &appMPlayer.menuWindow );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
115 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
116
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
117 void mplHideMenu( int mx,int my,int w )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
118 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
119 int x,y,i=mplMenuItem;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
120
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
121 if ( !appMPlayer.menuIsPresent || !appMPlayer.menuBase.Bitmap.Image ) return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
122
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
123 x=mx-mplMenuX;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
124 y=my-mplMenuY;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
125 // x=RX - appMPlayer.menuWindow.X;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
126 // y=RY - appMPlayer.menuWindow.Y;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
127
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
128 wsVisibleWindow( &appMPlayer.menuWindow,wsHideWindow );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
129
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
130 if ( ( x < 0 ) || ( y < 0 ) ) return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
131
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
132 // printf( "---------> %d %d,%d\n",i,x,y );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
133 // printf( "--------> mi: %d,%d %dx%d\n",appMPlayer.MenuItems[i].x,appMPlayer.MenuItems[i].y,appMPlayer.MenuItems[i].width,appMPlayer.MenuItems[i].height );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
134 if ( wgIsRect( x,y,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
135 appMPlayer.MenuItems[i].x,appMPlayer.MenuItems[i].y,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
136 appMPlayer.MenuItems[i].x+appMPlayer.MenuItems[i].width,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
137 appMPlayer.MenuItems[i].y+appMPlayer.MenuItems[i].height ) )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
138 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
139 mplEventHandling( appMPlayer.MenuItems[i].msg,(float)w );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
140 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
141 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
142
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
143 void mplMenuInit( void )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
144 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
145
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
146 if ( mplMenuIsInitialized || !appMPlayer.menuIsPresent || !appMPlayer.menuBase.Bitmap.Image ) return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
147
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
148 appMPlayer.menuBase.x=0;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
149 appMPlayer.menuBase.y=0;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
150
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
151 if ( ( mplMenuDrawBuffer = calloc( 1,appMPlayer.menuBase.Bitmap.ImageSize ) ) == NULL )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
152 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
153 #ifdef DEBUG
30531
704903d34069 Rename gui/mplayer/gtk/menu.[ch] --> gui/mplayer/gtk/gtkmenu.[ch].
diego
parents: 26458
diff changeset
154 mp_msg( MSGT_GPLAYER,MSGL_DBG2,MSGTR_NEMFMR );
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
155 #endif
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
156 gtkMessageBox( GTK_MB_FATAL,MSGTR_NEMFMR );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
157 return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
158 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
159
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
160 wsCreateWindow( &appMPlayer.menuWindow,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
161 appMPlayer.menuBase.x,appMPlayer.menuBase.y,appMPlayer.menuBase.width,appMPlayer.menuBase.height,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
162 wsNoBorder,wsShowMouseCursor|wsHandleMouseButton|wsHandleMouseMove,wsOverredirect|wsHideFrame|wsMaxSize|wsMinSize|wsHideWindow,"MPlayer menu" );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
163
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
164 wsSetShape( &appMPlayer.menuWindow,appMPlayer.menuBase.Mask.Image );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
165
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
166 #ifdef DEBUG
30531
704903d34069 Rename gui/mplayer/gtk/menu.[ch] --> gui/mplayer/gtk/gtkmenu.[ch].
diego
parents: 26458
diff changeset
167 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"menu: 0x%x\n",(int)appMPlayer.menuWindow.WindowID );
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
168 #endif
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
169
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
170 mplMenuIsInitialized=1;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
171 appMPlayer.menuWindow.ReDraw=mplMenuDraw;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
172 // appMPlayer.menuWindow.MouseHandler=mplMenuMouseHandle;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
173 // appMPlayer.menuWindow.KeyHandler=mplMainKeyHandle;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
174 mplMenuRender=1; wsPostRedisplay( &appMPlayer.menuWindow );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
175 }