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