Remove trailing whitespace from most files
[mplayer/glamo.git] / gui / mplayer / menu.c
blob2c541cc7333bbf5e168733ce2f9f4a77bb9f67b4
1 /*
2 * This file is part of MPlayer.
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.
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.
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.
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <inttypes.h>
23 #include "config.h"
24 #include "help_mp.h"
25 #include "mp_msg.h"
26 #include "gui/app.h"
27 #include "gmplayer.h"
29 #include "widgets.h"
31 unsigned char * mplMenuDrawBuffer = NULL;
32 int mplMenuRender = 1;
33 int mplMenuItem = -1;
34 int mplOldMenuItem = -1;
35 int mplMenuX,mplMenuY;
36 static int mplMenuIsInitialized = 0;
38 void mplMenuDraw( void )
40 uint32_t * buf = NULL;
41 uint32_t * drw = NULL;
42 int x,y,tmp;
44 if ( !appMPlayer.menuIsPresent || !appMPlayer.menuBase.Bitmap.Image ) return;
45 if ( !mplMenuRender && !appMPlayer.menuWindow.Visible ) return;
47 if ( mplMenuRender || mplMenuItem != mplOldMenuItem )
49 memcpy( mplMenuDrawBuffer,appMPlayer.menuBase.Bitmap.Image,appMPlayer.menuBase.Bitmap.ImageSize );
50 // ---
51 if ( mplMenuItem != -1 )
53 buf=(uint32_t *)mplMenuDrawBuffer;
54 drw=(uint32_t *)appMPlayer.menuSelected.Bitmap.Image;
55 for ( y=appMPlayer.MenuItems[ mplMenuItem ].y; y < appMPlayer.MenuItems[ mplMenuItem ].y + appMPlayer.MenuItems[ mplMenuItem ].height; y++ )
56 for ( x=appMPlayer.MenuItems[ mplMenuItem ].x; x < appMPlayer.MenuItems[ mplMenuItem ].x + appMPlayer.MenuItems[ mplMenuItem ].width; x++ )
58 tmp=drw[ y * appMPlayer.menuSelected.width + x ];
59 if ( tmp != 0x00ff00ff ) buf[ y * appMPlayer.menuBase.width + x ]=tmp;
62 mplOldMenuItem=mplMenuItem;
63 // ---
64 wsConvert( &appMPlayer.menuWindow,mplMenuDrawBuffer,appMPlayer.menuBase.Bitmap.ImageSize );
65 mplMenuRender=0;
67 wsPutImage( &appMPlayer.menuWindow );
70 void mplMenuMouseHandle( int X,int Y,int RX,int RY )
72 int x,y,i;
74 if ( !appMPlayer.menuBase.Bitmap.Image ) return;
76 mplMenuItem=-1;
77 x=RX - appMPlayer.menuWindow.X;
78 y=RY - appMPlayer.menuWindow.Y;
79 if ( ( x < 0 ) || ( y < 0 ) || ( x > appMPlayer.menuBase.width ) || ( y > appMPlayer.menuBase.height ) )
81 wsPostRedisplay( &appMPlayer.menuWindow );
82 return;
85 for( i=0;i<=appMPlayer.NumberOfMenuItems;i++ )
87 if ( wgIsRect( x,y,
88 appMPlayer.MenuItems[i].x,appMPlayer.MenuItems[i].y,
89 appMPlayer.MenuItems[i].x+appMPlayer.MenuItems[i].width,appMPlayer.MenuItems[i].y+appMPlayer.MenuItems[i].height ) ) { mplMenuItem=i; break; }
91 wsPostRedisplay( &appMPlayer.menuWindow );
94 void mplShowMenu( int mx,int my )
96 int x,y;
98 if ( !appMPlayer.menuIsPresent || !appMPlayer.menuBase.Bitmap.Image ) return;
100 x=mx;
101 if ( x + appMPlayer.menuWindow.Width > wsMaxX ) x=wsMaxX - appMPlayer.menuWindow.Width - 1 + wsOrgX;
102 y=my;
103 if ( y + appMPlayer.menuWindow.Height > wsMaxY ) y=wsMaxY - appMPlayer.menuWindow.Height - 1 + wsOrgY;
105 mplMenuX=x; mplMenuY=y;
107 mplMenuItem = 0;
109 wsMoveWindow( &appMPlayer.menuWindow,False,x,y );
110 wsMoveTopWindow( wsDisplay,appMPlayer.menuWindow.WindowID );
111 wsSetLayer( wsDisplay,appMPlayer.menuWindow.WindowID,1 );
112 mplMenuRender=1;
113 wsVisibleWindow( &appMPlayer.menuWindow,wsShowWindow );
114 wsPostRedisplay( &appMPlayer.menuWindow );
117 void mplHideMenu( int mx,int my,int w )
119 int x,y,i=mplMenuItem;
121 if ( !appMPlayer.menuIsPresent || !appMPlayer.menuBase.Bitmap.Image ) return;
123 x=mx-mplMenuX;
124 y=my-mplMenuY;
125 // x=RX - appMPlayer.menuWindow.X;
126 // y=RY - appMPlayer.menuWindow.Y;
128 wsVisibleWindow( &appMPlayer.menuWindow,wsHideWindow );
130 if ( ( x < 0 ) || ( y < 0 ) ) return;
132 // printf( "---------> %d %d,%d\n",i,x,y );
133 // printf( "--------> mi: %d,%d %dx%d\n",appMPlayer.MenuItems[i].x,appMPlayer.MenuItems[i].y,appMPlayer.MenuItems[i].width,appMPlayer.MenuItems[i].height );
134 if ( wgIsRect( x,y,
135 appMPlayer.MenuItems[i].x,appMPlayer.MenuItems[i].y,
136 appMPlayer.MenuItems[i].x+appMPlayer.MenuItems[i].width,
137 appMPlayer.MenuItems[i].y+appMPlayer.MenuItems[i].height ) )
139 mplEventHandling( appMPlayer.MenuItems[i].msg,(float)w );
143 void mplMenuInit( void )
146 if ( mplMenuIsInitialized || !appMPlayer.menuIsPresent || !appMPlayer.menuBase.Bitmap.Image ) return;
148 appMPlayer.menuBase.x=0;
149 appMPlayer.menuBase.y=0;
151 if ( ( mplMenuDrawBuffer = calloc( 1,appMPlayer.menuBase.Bitmap.ImageSize ) ) == NULL )
153 #ifdef DEBUG
154 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[menu.h] %s",MSGTR_NEMFMR );
155 #endif
156 gtkMessageBox( GTK_MB_FATAL,MSGTR_NEMFMR );
157 return;
160 wsCreateWindow( &appMPlayer.menuWindow,
161 appMPlayer.menuBase.x,appMPlayer.menuBase.y,appMPlayer.menuBase.width,appMPlayer.menuBase.height,
162 wsNoBorder,wsShowMouseCursor|wsHandleMouseButton|wsHandleMouseMove,wsOverredirect|wsHideFrame|wsMaxSize|wsMinSize|wsHideWindow,"MPlayer menu" );
164 wsSetShape( &appMPlayer.menuWindow,appMPlayer.menuBase.Mask.Image );
166 #ifdef DEBUG
167 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[menu.h] menu: 0x%x\n",(int)appMPlayer.menuWindow.WindowID );
168 #endif
170 mplMenuIsInitialized=1;
171 appMPlayer.menuWindow.ReDraw=mplMenuDraw;
172 // appMPlayer.menuWindow.MouseHandler=mplMenuMouseHandle;
173 // appMPlayer.menuWindow.KeyHandler=mplMainKeyHandle;
174 mplMenuRender=1; wsPostRedisplay( &appMPlayer.menuWindow );