Mercurial > mplayer.hg
annotate gui/ui/menu.c @ 36291:b2edfe1a11a6
Process events after destroying a window.
This allows other windows to get their expose events.
author | ib |
---|---|
date | Thu, 01 Aug 2013 17:29:47 +0000 |
parents | e160aade4b6d |
children | 7d250553d451 |
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 | |
35803 | 48 if ( !guiApp.menuIsPresent ) 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 | |
36010 | 78 (void) Button; |
79 (void) RX; | |
80 (void) RY; | |
81 | |
33555 | 82 menuItem=-1; |
35778 | 83 x=X - guiApp.menuWindow.X; |
84 y=Y - guiApp.menuWindow.Y; | |
33555 | 85 if ( ( x < 0 ) || ( y < 0 ) || ( x > guiApp.menu.width ) || ( y > guiApp.menu.height ) ) |
23077 | 86 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
87 wsWindowRedraw( &guiApp.menuWindow ); |
23077 | 88 return; |
89 } | |
90 | |
33555 | 91 for( i=0;i<=guiApp.IndexOfMenuItems;i++ ) |
23077 | 92 { |
35675 | 93 if ( isInside( x,y, |
33555 | 94 guiApp.menuItems[i].x,guiApp.menuItems[i].y, |
95 guiApp.menuItems[i].x+guiApp.menuItems[i].width,guiApp.menuItems[i].y+guiApp.menuItems[i].height ) ) { menuItem=i; break; } | |
23077 | 96 } |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
97 wsWindowRedraw( &guiApp.menuWindow ); |
23077 | 98 } |
99 | |
35767 | 100 void uiMenuInit( void ) |
101 { | |
102 | |
35803 | 103 if ( !guiApp.menuIsPresent ) return; |
35767 | 104 |
105 guiApp.menu.x=0; | |
106 guiApp.menu.y=0; | |
107 | |
108 if ( ( menuDrawBuffer = calloc( 1,guiApp.menu.Bitmap.ImageSize ) ) == NULL ) | |
109 { | |
110 mp_msg( MSGT_GPLAYER,MSGL_DBG2,MSGTR_NEMFMR ); | |
36036 | 111 gtkMessageBox( MSGBOX_FATAL,MSGTR_NEMFMR ); |
35767 | 112 return; |
113 } | |
114 | |
115 wsWindowCreate( &guiApp.menuWindow, | |
116 guiApp.menu.x,guiApp.menu.y,guiApp.menu.width,guiApp.menu.height, | |
117 wsOverredirect|wsHideFrame|wsMaxSize|wsMinSize|wsHideWindow,wsShowMouseCursor|wsHandleMouseButton|wsHandleMouseMove,"MPlayer menu" ); | |
118 | |
35782 | 119 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[menu] menuWindow ID: 0x%x\n",(int)guiApp.menuWindow.WindowID ); |
35767 | 120 |
35782 | 121 wsWindowShape( &guiApp.menuWindow,guiApp.menu.Mask.Image ); |
35767 | 122 |
123 guiApp.menuWindow.DrawHandler=uiMenuDraw; | |
35778 | 124 guiApp.menuWindow.MouseHandler=uiMenuMouse; |
35780 | 125 // guiApp.menuWindow.KeyHandler=guiApp.mainWindow.KeyHandler; |
35767 | 126 uiMenuRender=True; wsWindowRedraw( &guiApp.menuWindow ); |
127 } | |
128 | |
35796
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35782
diff
changeset
|
129 void uiMenuDone( void ) |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35782
diff
changeset
|
130 { |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35782
diff
changeset
|
131 nfree(menuDrawBuffer); |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35782
diff
changeset
|
132 wsWindowDestroy(&guiApp.menuWindow); |
36291 | 133 wsEvents(); |
35796
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35782
diff
changeset
|
134 } |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35782
diff
changeset
|
135 |
35766
16ed8155439b
Rename uiShowMenu() uiMenuShow() and uiHideMenu() uiMenuHide().
ib
parents:
35762
diff
changeset
|
136 void uiMenuShow( int mx,int my ) |
23077 | 137 { |
138 int x,y; | |
139 | |
35803 | 140 if ( !guiApp.menuIsPresent ) return; |
23077 | 141 |
142 x=mx; | |
33555 | 143 if ( x + guiApp.menuWindow.Width > wsMaxX ) x=wsMaxX - guiApp.menuWindow.Width - 1 + wsOrgX; |
23077 | 144 y=my; |
33555 | 145 if ( y + guiApp.menuWindow.Height > wsMaxY ) y=wsMaxY - guiApp.menuWindow.Height - 1 + wsOrgY; |
23077 | 146 |
33555 | 147 menuX=x; menuY=y; |
23077 | 148 |
33555 | 149 menuItem = 0; |
23077 | 150 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
151 wsWindowMove( &guiApp.menuWindow,True,x,y ); |
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
152 wsWindowRaiseTop( wsDisplay,guiApp.menuWindow.WindowID ); |
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
153 wsWindowLayer( wsDisplay,guiApp.menuWindow.WindowID,1 ); |
35750 | 154 uiMenuRender=True; |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
155 wsWindowVisibility( &guiApp.menuWindow,wsShowWindow ); |
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
156 wsWindowRedraw( &guiApp.menuWindow ); |
23077 | 157 } |
158 | |
35766
16ed8155439b
Rename uiShowMenu() uiMenuShow() and uiHideMenu() uiMenuHide().
ib
parents:
35762
diff
changeset
|
159 void uiMenuHide( int mx,int my,int w ) |
23077 | 160 { |
33555 | 161 int x,y,i=menuItem; |
23077 | 162 |
35803 | 163 if ( !guiApp.menuIsPresent ) return; |
23077 | 164 |
33555 | 165 x=mx-menuX; |
166 y=my-menuY; | |
167 // x=RX - guiApp.menuWindow.X; | |
168 // y=RY - guiApp.menuWindow.Y; | |
23077 | 169 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
170 wsWindowVisibility( &guiApp.menuWindow,wsHideWindow ); |
23077 | 171 |
172 if ( ( x < 0 ) || ( y < 0 ) ) return; | |
173 | |
174 // printf( "---------> %d %d,%d\n",i,x,y ); | |
33555 | 175 // printf( "--------> mi: %d,%d %dx%d\n",guiApp.menuItems[i].x,guiApp.menuItems[i].y,guiApp.menuItems[i].width,guiApp.menuItems[i].height ); |
35675 | 176 if ( isInside( x,y, |
33555 | 177 guiApp.menuItems[i].x,guiApp.menuItems[i].y, |
178 guiApp.menuItems[i].x+guiApp.menuItems[i].width, | |
179 guiApp.menuItems[i].y+guiApp.menuItems[i].height ) ) | |
23077 | 180 { |
36280 | 181 uiEvent( guiApp.menuItems[i].message,w ); |
23077 | 182 } |
183 } |