Mercurial > mplayer.hg
annotate gui/ui/menu.c @ 35796:497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
These are the counterparts to the Init functions and they free and
release everything associated with the respective window. (Something
that hasn't been done so far.)
author | ib |
---|---|
date | Fri, 25 Jan 2013 23:47:34 +0000 |
parents | e30d541b3ea6 |
children | 2849b02700e5 |
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; | |
35493 | 41 static int menuIsInitialized = False; |
23077 | 42 |
33555 | 43 static void uiMenuDraw( void ) |
23077 | 44 { |
45 uint32_t * buf = NULL; | |
46 uint32_t * drw = NULL; | |
47 int x,y,tmp; | |
48 | |
33555 | 49 if ( !guiApp.menuIsPresent || !guiApp.menu.Bitmap.Image ) return; |
35750 | 50 if ( !uiMenuRender && !guiApp.menuWindow.Visible ) return; |
23077 | 51 |
35750 | 52 if ( uiMenuRender || menuItem != oldMenuItem ) |
23077 | 53 { |
33555 | 54 memcpy( menuDrawBuffer,guiApp.menu.Bitmap.Image,guiApp.menu.Bitmap.ImageSize ); |
34684 | 55 /* --- */ |
33555 | 56 if ( menuItem != -1 ) |
23077 | 57 { |
33555 | 58 buf=(uint32_t *)menuDrawBuffer; |
59 drw=(uint32_t *)guiApp.menuSelected.Bitmap.Image; | |
60 for ( y=guiApp.menuItems[ menuItem ].y; y < guiApp.menuItems[ menuItem ].y + guiApp.menuItems[ menuItem ].height; y++ ) | |
61 for ( x=guiApp.menuItems[ menuItem ].x; x < guiApp.menuItems[ menuItem ].x + guiApp.menuItems[ menuItem ].width; x++ ) | |
23077 | 62 { |
33555 | 63 tmp=drw[ y * guiApp.menuSelected.width + x ]; |
64 if ( !IS_TRANSPARENT ( tmp ) ) buf[ y * guiApp.menu.width + x ]=tmp; | |
23077 | 65 } |
66 } | |
33555 | 67 oldMenuItem=menuItem; |
34684 | 68 /* --- */ |
35744 | 69 wsImageRender( &guiApp.menuWindow,menuDrawBuffer ); |
35750 | 70 uiMenuRender=False; |
23077 | 71 } |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
72 wsImageDraw( &guiApp.menuWindow ); |
23077 | 73 } |
74 | |
35778 | 75 static void uiMenuMouse( int Button,int X,int Y,int RX,int RY ) |
23077 | 76 { |
77 int x,y,i; | |
78 | |
33555 | 79 if ( !guiApp.menu.Bitmap.Image ) return; |
23077 | 80 |
33555 | 81 menuItem=-1; |
35778 | 82 x=X - guiApp.menuWindow.X; |
83 y=Y - guiApp.menuWindow.Y; | |
33555 | 84 if ( ( x < 0 ) || ( y < 0 ) || ( x > guiApp.menu.width ) || ( y > guiApp.menu.height ) ) |
23077 | 85 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
86 wsWindowRedraw( &guiApp.menuWindow ); |
23077 | 87 return; |
88 } | |
89 | |
33555 | 90 for( i=0;i<=guiApp.IndexOfMenuItems;i++ ) |
23077 | 91 { |
35675 | 92 if ( isInside( x,y, |
33555 | 93 guiApp.menuItems[i].x,guiApp.menuItems[i].y, |
94 guiApp.menuItems[i].x+guiApp.menuItems[i].width,guiApp.menuItems[i].y+guiApp.menuItems[i].height ) ) { menuItem=i; break; } | |
23077 | 95 } |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
96 wsWindowRedraw( &guiApp.menuWindow ); |
23077 | 97 } |
98 | |
35767 | 99 void uiMenuInit( void ) |
100 { | |
101 | |
102 if ( menuIsInitialized || !guiApp.menuIsPresent || !guiApp.menu.Bitmap.Image ) return; | |
103 | |
104 guiApp.menu.x=0; | |
105 guiApp.menu.y=0; | |
106 | |
107 if ( ( menuDrawBuffer = calloc( 1,guiApp.menu.Bitmap.ImageSize ) ) == NULL ) | |
108 { | |
109 mp_msg( MSGT_GPLAYER,MSGL_DBG2,MSGTR_NEMFMR ); | |
110 gtkMessageBox( GTK_MB_FATAL,MSGTR_NEMFMR ); | |
111 return; | |
112 } | |
113 | |
114 wsWindowCreate( &guiApp.menuWindow, | |
115 guiApp.menu.x,guiApp.menu.y,guiApp.menu.width,guiApp.menu.height, | |
116 wsOverredirect|wsHideFrame|wsMaxSize|wsMinSize|wsHideWindow,wsShowMouseCursor|wsHandleMouseButton|wsHandleMouseMove,"MPlayer menu" ); | |
117 | |
35782 | 118 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[menu] menuWindow ID: 0x%x\n",(int)guiApp.menuWindow.WindowID ); |
35767 | 119 |
35782 | 120 wsWindowShape( &guiApp.menuWindow,guiApp.menu.Mask.Image ); |
35767 | 121 |
122 menuIsInitialized=True; | |
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); |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35782
diff
changeset
|
133 } |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35782
diff
changeset
|
134 |
35766
16ed8155439b
Rename uiShowMenu() uiMenuShow() and uiHideMenu() uiMenuHide().
ib
parents:
35762
diff
changeset
|
135 void uiMenuShow( int mx,int my ) |
23077 | 136 { |
137 int x,y; | |
138 | |
33555 | 139 if ( !guiApp.menuIsPresent || !guiApp.menu.Bitmap.Image ) return; |
23077 | 140 |
141 x=mx; | |
33555 | 142 if ( x + guiApp.menuWindow.Width > wsMaxX ) x=wsMaxX - guiApp.menuWindow.Width - 1 + wsOrgX; |
23077 | 143 y=my; |
33555 | 144 if ( y + guiApp.menuWindow.Height > wsMaxY ) y=wsMaxY - guiApp.menuWindow.Height - 1 + wsOrgY; |
23077 | 145 |
33555 | 146 menuX=x; menuY=y; |
23077 | 147 |
33555 | 148 menuItem = 0; |
23077 | 149 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
150 wsWindowMove( &guiApp.menuWindow,True,x,y ); |
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
151 wsWindowRaiseTop( wsDisplay,guiApp.menuWindow.WindowID ); |
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
152 wsWindowLayer( wsDisplay,guiApp.menuWindow.WindowID,1 ); |
35750 | 153 uiMenuRender=True; |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
154 wsWindowVisibility( &guiApp.menuWindow,wsShowWindow ); |
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
155 wsWindowRedraw( &guiApp.menuWindow ); |
23077 | 156 } |
157 | |
35766
16ed8155439b
Rename uiShowMenu() uiMenuShow() and uiHideMenu() uiMenuHide().
ib
parents:
35762
diff
changeset
|
158 void uiMenuHide( int mx,int my,int w ) |
23077 | 159 { |
33555 | 160 int x,y,i=menuItem; |
23077 | 161 |
33555 | 162 if ( !guiApp.menuIsPresent || !guiApp.menu.Bitmap.Image ) return; |
23077 | 163 |
33555 | 164 x=mx-menuX; |
165 y=my-menuY; | |
166 // x=RX - guiApp.menuWindow.X; | |
167 // y=RY - guiApp.menuWindow.Y; | |
23077 | 168 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
169 wsWindowVisibility( &guiApp.menuWindow,wsHideWindow ); |
23077 | 170 |
171 if ( ( x < 0 ) || ( y < 0 ) ) return; | |
172 | |
173 // printf( "---------> %d %d,%d\n",i,x,y ); | |
33555 | 174 // printf( "--------> mi: %d,%d %dx%d\n",guiApp.menuItems[i].x,guiApp.menuItems[i].y,guiApp.menuItems[i].width,guiApp.menuItems[i].height ); |
35675 | 175 if ( isInside( x,y, |
33555 | 176 guiApp.menuItems[i].x,guiApp.menuItems[i].y, |
177 guiApp.menuItems[i].x+guiApp.menuItems[i].width, | |
178 guiApp.menuItems[i].y+guiApp.menuItems[i].height ) ) | |
23077 | 179 { |
35773 | 180 uiEvent( guiApp.menuItems[i].message,(float)w ); |
23077 | 181 } |
182 } |