annotate gui/mplayer/menu.c @ 23077:17bf4f4b0715

Gui --> gui
author diego
date Mon, 23 Apr 2007 07:42:42 +0000
parents
children e564b9cd7290
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
1
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
2 #include <stdlib.h>
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
3 #include <stdio.h>
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
4 #include <inttypes.h>
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
5
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
6 #include "app.h"
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
7 #include "../config.h"
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
8 #include "../help_mp.h"
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
9 #include "../mp_msg.h"
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
10
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
11 #include "widgets.h"
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
12
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
13 unsigned char * mplMenuDrawBuffer = NULL;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
14 int mplMenuRender = 1;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
15 int mplMenuItem = -1;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
16 int mplOldMenuItem = -1;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
17 int mplMenuX,mplMenuY;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
18 static int mplMenuIsInitialized = 0;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
19
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
20 void mplHideMenu( int mx,int my,int w );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
21
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
22 void mplMenuDraw( void )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
23 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
24 uint32_t * buf = NULL;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
25 uint32_t * drw = NULL;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
26 int x,y,tmp;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
27
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
28 if ( !appMPlayer.menuIsPresent || !appMPlayer.menuBase.Bitmap.Image ) return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
29 if ( !mplMenuRender && !appMPlayer.menuWindow.Visible ) return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
30
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
31 if ( mplMenuRender || mplMenuItem != mplOldMenuItem )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
32 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
33 memcpy( mplMenuDrawBuffer,appMPlayer.menuBase.Bitmap.Image,appMPlayer.menuBase.Bitmap.ImageSize );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
34 // ---
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
35 if ( mplMenuItem != -1 )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
36 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
37 buf=(uint32_t *)mplMenuDrawBuffer;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
38 drw=(uint32_t *)appMPlayer.menuSelected.Bitmap.Image;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
39 for ( y=appMPlayer.MenuItems[ mplMenuItem ].y; y < appMPlayer.MenuItems[ mplMenuItem ].y + appMPlayer.MenuItems[ mplMenuItem ].height; y++ )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
40 for ( x=appMPlayer.MenuItems[ mplMenuItem ].x; x < appMPlayer.MenuItems[ mplMenuItem ].x + appMPlayer.MenuItems[ mplMenuItem ].width; x++ )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
41 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
42 tmp=drw[ y * appMPlayer.menuSelected.width + x ];
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
43 if ( tmp != 0x00ff00ff ) buf[ y * appMPlayer.menuBase.width + x ]=tmp;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
44 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
45 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
46 mplOldMenuItem=mplMenuItem;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
47 // ---
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
48 wsConvert( &appMPlayer.menuWindow,mplMenuDrawBuffer,appMPlayer.menuBase.Bitmap.ImageSize );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
49 mplMenuRender=0;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
50 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
51 wsPutImage( &appMPlayer.menuWindow );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
52 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
53
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
54 void mplMenuMouseHandle( int X,int Y,int RX,int RY )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
55 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
56 int x,y,i;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
57
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
58 if ( !appMPlayer.menuBase.Bitmap.Image ) return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
59
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
60 mplMenuItem=-1;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
61 x=RX - appMPlayer.menuWindow.X;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
62 y=RY - appMPlayer.menuWindow.Y;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
63 if ( ( x < 0 ) || ( y < 0 ) || ( x > appMPlayer.menuBase.width ) || ( y > appMPlayer.menuBase.height ) )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
64 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
65 wsPostRedisplay( &appMPlayer.menuWindow );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
66 return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
67 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
68
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
69 for( i=0;i<=appMPlayer.NumberOfMenuItems;i++ )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
70 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
71 if ( wgIsRect( x,y,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
72 appMPlayer.MenuItems[i].x,appMPlayer.MenuItems[i].y,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
73 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
74 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
75 wsPostRedisplay( &appMPlayer.menuWindow );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
76 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
77
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
78 void mplShowMenu( int mx,int my )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
79 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
80 int x,y;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
81
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
82 if ( !appMPlayer.menuIsPresent || !appMPlayer.menuBase.Bitmap.Image ) return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
83
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
84 x=mx;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
85 if ( x + appMPlayer.menuWindow.Width > wsMaxX ) x=wsMaxX - appMPlayer.menuWindow.Width - 1 + wsOrgX;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
86 y=my;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
87 if ( y + appMPlayer.menuWindow.Height > wsMaxY ) y=wsMaxY - appMPlayer.menuWindow.Height - 1 + wsOrgY;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
88
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
89 mplMenuX=x; mplMenuY=y;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
90
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
91 mplMenuItem = 0;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
92
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
93 wsMoveWindow( &appMPlayer.menuWindow,False,x,y );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
94 wsMoveTopWindow( wsDisplay,appMPlayer.menuWindow.WindowID );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
95 wsSetLayer( wsDisplay,appMPlayer.menuWindow.WindowID,1 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
96 mplMenuRender=1;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
97 wsVisibleWindow( &appMPlayer.menuWindow,wsShowWindow );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
98 wsPostRedisplay( &appMPlayer.menuWindow );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
99 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
100
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
101 void mplHideMenu( int mx,int my,int w )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
102 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
103 int x,y,i=mplMenuItem;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
104
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
105 if ( !appMPlayer.menuIsPresent || !appMPlayer.menuBase.Bitmap.Image ) return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
106
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
107 x=mx-mplMenuX;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
108 y=my-mplMenuY;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
109 // x=RX - appMPlayer.menuWindow.X;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
110 // y=RY - appMPlayer.menuWindow.Y;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
111
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
112 wsVisibleWindow( &appMPlayer.menuWindow,wsHideWindow );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
113
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
114 if ( ( x < 0 ) || ( y < 0 ) ) return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
115
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
116 // printf( "---------> %d %d,%d\n",i,x,y );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
117 // 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
118 if ( wgIsRect( x,y,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
119 appMPlayer.MenuItems[i].x,appMPlayer.MenuItems[i].y,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
120 appMPlayer.MenuItems[i].x+appMPlayer.MenuItems[i].width,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
121 appMPlayer.MenuItems[i].y+appMPlayer.MenuItems[i].height ) )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
122 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
123 mplEventHandling( appMPlayer.MenuItems[i].msg,(float)w );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
124 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
125 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
126
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
127 void mplMenuInit( void )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
128 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
129
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
130 if ( mplMenuIsInitialized || !appMPlayer.menuIsPresent || !appMPlayer.menuBase.Bitmap.Image ) return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
131
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
132 appMPlayer.menuBase.x=0;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
133 appMPlayer.menuBase.y=0;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
134
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
135 if ( ( mplMenuDrawBuffer = calloc( 1,appMPlayer.menuBase.Bitmap.ImageSize ) ) == NULL )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
136 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
137 #ifdef DEBUG
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
138 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[menu.h] %s",MSGTR_NEMFMR );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
139 #endif
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
140 gtkMessageBox( GTK_MB_FATAL,MSGTR_NEMFMR );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
141 return;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
142 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
143
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
144 wsCreateWindow( &appMPlayer.menuWindow,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
145 appMPlayer.menuBase.x,appMPlayer.menuBase.y,appMPlayer.menuBase.width,appMPlayer.menuBase.height,
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
146 wsNoBorder,wsShowMouseCursor|wsHandleMouseButton|wsHandleMouseMove,wsOverredirect|wsHideFrame|wsMaxSize|wsMinSize|wsHideWindow,"MPlayer menu" );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
147
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
148 wsSetShape( &appMPlayer.menuWindow,appMPlayer.menuBase.Mask.Image );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
149
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
150 #ifdef DEBUG
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
151 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[menu.h] menu: 0x%x\n",(int)appMPlayer.menuWindow.WindowID );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
152 #endif
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
153
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
154 mplMenuIsInitialized=1;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
155 appMPlayer.menuWindow.ReDraw=mplMenuDraw;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
156 // appMPlayer.menuWindow.MouseHandler=mplMenuMouseHandle;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
157 // appMPlayer.menuWindow.KeyHandler=mplMainKeyHandle;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
158 mplMenuRender=1; wsPostRedisplay( &appMPlayer.menuWindow );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
159 }