annotate gui/mplayer/menu.c @ 24938:328a5d99203e

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