Mercurial > mplayer.hg
annotate gui/ui/menu.c @ 35802:2849b02700e5
Remove pointless menuIsInitialized.
The draw handler won't be called prior to the initialization,
because it is set only during initialization.
author | ib |
---|---|
date | Sat, 26 Jan 2013 00:45:58 +0000 |
parents | 497a1c45a597 |
children | 8e5a3da0a858 |
rev | line source |
---|---|
26458 | 1 /* |
2 * This file is part of MPlayer. | |
3 * | |
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. | |
8 * | |
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. | |
13 * | |
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. | |
17 */ | |
23077 | 18 |
34699
ed0e00db4306
Cosmetic: Move, change and add some comments on GUI windows.
ib
parents:
34684
diff
changeset
|
19 /* menu window */ |
ed0e00db4306
Cosmetic: Move, change and add some comments on GUI windows.
ib
parents:
34684
diff
changeset
|
20 |
23077 | 21 #include <stdlib.h> |
22 #include <stdio.h> | |
33123
9566100d88a1
Replace inttypes.h by stdint.h and remove inttypes.h where unneeded.
ib
parents:
33084
diff
changeset
|
23 #include <stdint.h> |
33738 | 24 #include <string.h> |
23077 | 25 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
26 #include "help_mp.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
27 #include "mp_msg.h" |
35525 | 28 #include "gui/app/app.h" |
29 #include "gui/app/gui.h" | |
35772 | 30 #include "actions.h" |
35528 | 31 #include "ui.h" |
35796
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35782
diff
changeset
|
32 #include "gui/util/mem.h" |
23077 | 33 |
35529 | 34 #include "gui/dialog/dialog.h" |
23077 | 35 |
33555 | 36 unsigned char * menuDrawBuffer = NULL; |
35750 | 37 static int uiMenuRender = True; |
33555 | 38 int menuItem = -1; |
39 int oldMenuItem = -1; | |
40 int menuX,menuY; | |
23077 | 41 |
33555 | 42 static void uiMenuDraw( void ) |
23077 | 43 { |
44 uint32_t * buf = NULL; | |
45 uint32_t * drw = NULL; | |
46 int x,y,tmp; | |
47 | |
33555 | 48 if ( !guiApp.menuIsPresent || !guiApp.menu.Bitmap.Image ) return; |
35750 | 49 if ( !uiMenuRender && !guiApp.menuWindow.Visible ) return; |
23077 | 50 |
35750 | 51 if ( uiMenuRender || menuItem != oldMenuItem ) |
23077 | 52 { |
33555 | 53 memcpy( menuDrawBuffer,guiApp.menu.Bitmap.Image,guiApp.menu.Bitmap.ImageSize ); |
34684 | 54 /* --- */ |
33555 | 55 if ( menuItem != -1 ) |
23077 | 56 { |
33555 | 57 buf=(uint32_t *)menuDrawBuffer; |
58 drw=(uint32_t *)guiApp.menuSelected.Bitmap.Image; | |
59 for ( y=guiApp.menuItems[ menuItem ].y; y < guiApp.menuItems[ menuItem ].y + guiApp.menuItems[ menuItem ].height; y++ ) | |
60 for ( x=guiApp.menuItems[ menuItem ].x; x < guiApp.menuItems[ menuItem ].x + guiApp.menuItems[ menuItem ].width; x++ ) | |
23077 | 61 { |
33555 | 62 tmp=drw[ y * guiApp.menuSelected.width + x ]; |
63 if ( !IS_TRANSPARENT ( tmp ) ) buf[ y * guiApp.menu.width + x ]=tmp; | |
23077 | 64 } |
65 } | |
33555 | 66 oldMenuItem=menuItem; |
34684 | 67 /* --- */ |
35744 | 68 wsImageRender( &guiApp.menuWindow,menuDrawBuffer ); |
35750 | 69 uiMenuRender=False; |
23077 | 70 } |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
71 wsImageDraw( &guiApp.menuWindow ); |
23077 | 72 } |
73 | |
35778 | 74 static void uiMenuMouse( int Button,int X,int Y,int RX,int RY ) |
23077 | 75 { |
76 int x,y,i; | |
77 | |
33555 | 78 if ( !guiApp.menu.Bitmap.Image ) return; |
23077 | 79 |
33555 | 80 menuItem=-1; |
35778 | 81 x=X - guiApp.menuWindow.X; |
82 y=Y - guiApp.menuWindow.Y; | |
33555 | 83 if ( ( x < 0 ) || ( y < 0 ) || ( x > guiApp.menu.width ) || ( y > guiApp.menu.height ) ) |
23077 | 84 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
85 wsWindowRedraw( &guiApp.menuWindow ); |
23077 | 86 return; |
87 } | |
88 | |
33555 | 89 for( i=0;i<=guiApp.IndexOfMenuItems;i++ ) |
23077 | 90 { |
35675 | 91 if ( isInside( x,y, |
33555 | 92 guiApp.menuItems[i].x,guiApp.menuItems[i].y, |
93 guiApp.menuItems[i].x+guiApp.menuItems[i].width,guiApp.menuItems[i].y+guiApp.menuItems[i].height ) ) { menuItem=i; break; } | |
23077 | 94 } |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
95 wsWindowRedraw( &guiApp.menuWindow ); |
23077 | 96 } |
97 | |
35767 | 98 void uiMenuInit( void ) |
99 { | |
100 | |
35802 | 101 if ( !guiApp.menuIsPresent || !guiApp.menu.Bitmap.Image ) return; |
35767 | 102 |
103 guiApp.menu.x=0; | |
104 guiApp.menu.y=0; | |
105 | |
106 if ( ( menuDrawBuffer = calloc( 1,guiApp.menu.Bitmap.ImageSize ) ) == NULL ) | |
107 { | |
108 mp_msg( MSGT_GPLAYER,MSGL_DBG2,MSGTR_NEMFMR ); | |
109 gtkMessageBox( GTK_MB_FATAL,MSGTR_NEMFMR ); | |
110 return; | |
111 } | |
112 | |
113 wsWindowCreate( &guiApp.menuWindow, | |
114 guiApp.menu.x,guiApp.menu.y,guiApp.menu.width,guiApp.menu.height, | |
115 wsOverredirect|wsHideFrame|wsMaxSize|wsMinSize|wsHideWindow,wsShowMouseCursor|wsHandleMouseButton|wsHandleMouseMove,"MPlayer menu" ); | |
116 | |
35782 | 117 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[menu] menuWindow ID: 0x%x\n",(int)guiApp.menuWindow.WindowID ); |
35767 | 118 |
35782 | 119 wsWindowShape( &guiApp.menuWindow,guiApp.menu.Mask.Image ); |
35767 | 120 |
121 guiApp.menuWindow.DrawHandler=uiMenuDraw; | |
35778 | 122 guiApp.menuWindow.MouseHandler=uiMenuMouse; |
35780 | 123 // guiApp.menuWindow.KeyHandler=guiApp.mainWindow.KeyHandler; |
35767 | 124 uiMenuRender=True; wsWindowRedraw( &guiApp.menuWindow ); |
125 } | |
126 | |
35796
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35782
diff
changeset
|
127 void uiMenuDone( void ) |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35782
diff
changeset
|
128 { |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35782
diff
changeset
|
129 nfree(menuDrawBuffer); |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35782
diff
changeset
|
130 wsWindowDestroy(&guiApp.menuWindow); |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35782
diff
changeset
|
131 } |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35782
diff
changeset
|
132 |
35766
16ed8155439b
Rename uiShowMenu() uiMenuShow() and uiHideMenu() uiMenuHide().
ib
parents:
35762
diff
changeset
|
133 void uiMenuShow( int mx,int my ) |
23077 | 134 { |
135 int x,y; | |
136 | |
33555 | 137 if ( !guiApp.menuIsPresent || !guiApp.menu.Bitmap.Image ) return; |
23077 | 138 |
139 x=mx; | |
33555 | 140 if ( x + guiApp.menuWindow.Width > wsMaxX ) x=wsMaxX - guiApp.menuWindow.Width - 1 + wsOrgX; |
23077 | 141 y=my; |
33555 | 142 if ( y + guiApp.menuWindow.Height > wsMaxY ) y=wsMaxY - guiApp.menuWindow.Height - 1 + wsOrgY; |
23077 | 143 |
33555 | 144 menuX=x; menuY=y; |
23077 | 145 |
33555 | 146 menuItem = 0; |
23077 | 147 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
148 wsWindowMove( &guiApp.menuWindow,True,x,y ); |
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
149 wsWindowRaiseTop( wsDisplay,guiApp.menuWindow.WindowID ); |
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
150 wsWindowLayer( wsDisplay,guiApp.menuWindow.WindowID,1 ); |
35750 | 151 uiMenuRender=True; |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
152 wsWindowVisibility( &guiApp.menuWindow,wsShowWindow ); |
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
153 wsWindowRedraw( &guiApp.menuWindow ); |
23077 | 154 } |
155 | |
35766
16ed8155439b
Rename uiShowMenu() uiMenuShow() and uiHideMenu() uiMenuHide().
ib
parents:
35762
diff
changeset
|
156 void uiMenuHide( int mx,int my,int w ) |
23077 | 157 { |
33555 | 158 int x,y,i=menuItem; |
23077 | 159 |
33555 | 160 if ( !guiApp.menuIsPresent || !guiApp.menu.Bitmap.Image ) return; |
23077 | 161 |
33555 | 162 x=mx-menuX; |
163 y=my-menuY; | |
164 // x=RX - guiApp.menuWindow.X; | |
165 // y=RY - guiApp.menuWindow.Y; | |
23077 | 166 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
167 wsWindowVisibility( &guiApp.menuWindow,wsHideWindow ); |
23077 | 168 |
169 if ( ( x < 0 ) || ( y < 0 ) ) return; | |
170 | |
171 // printf( "---------> %d %d,%d\n",i,x,y ); | |
33555 | 172 // printf( "--------> mi: %d,%d %dx%d\n",guiApp.menuItems[i].x,guiApp.menuItems[i].y,guiApp.menuItems[i].width,guiApp.menuItems[i].height ); |
35675 | 173 if ( isInside( x,y, |
33555 | 174 guiApp.menuItems[i].x,guiApp.menuItems[i].y, |
175 guiApp.menuItems[i].x+guiApp.menuItems[i].width, | |
176 guiApp.menuItems[i].y+guiApp.menuItems[i].height ) ) | |
23077 | 177 { |
35773 | 178 uiEvent( guiApp.menuItems[i].message,(float)w ); |
23077 | 179 } |
180 } |