view gui/ui/menu.c @ 35717:42ca1c165174

configure: Add check for _aligned_malloc(), used in libavutil.
author diego
date Mon, 21 Jan 2013 20:18:16 +0000
parents 75155d8a9c7e
children bfe51acc36fb
line wrap: on
line source

/*
 * This file is part of MPlayer.
 *
 * MPlayer is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * MPlayer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

/* menu window */

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>

#include "help_mp.h"
#include "mp_msg.h"
#include "gui/app/app.h"
#include "gui/app/gui.h"
#include "ui.h"

#include "gui/dialog/dialog.h"

unsigned char * menuDrawBuffer = NULL;
int             menuRender = True;
int             menuItem = -1;
int             oldMenuItem = -1;
int             menuX,menuY;
static int      menuIsInitialized = False;

static void uiMenuDraw( void )
{
 uint32_t * buf = NULL;
 uint32_t * drw = NULL;
 int             x,y,tmp;

 if ( !guiApp.menuIsPresent || !guiApp.menu.Bitmap.Image ) return;
 if ( !menuRender && !guiApp.menuWindow.Visible ) return;

 if ( menuRender || menuItem != oldMenuItem )
  {
   memcpy( menuDrawBuffer,guiApp.menu.Bitmap.Image,guiApp.menu.Bitmap.ImageSize );
/* --- */
   if ( menuItem != -1 )
    {
     buf=(uint32_t *)menuDrawBuffer;
     drw=(uint32_t *)guiApp.menuSelected.Bitmap.Image;
     for ( y=guiApp.menuItems[ menuItem ].y; y < guiApp.menuItems[ menuItem ].y + guiApp.menuItems[ menuItem ].height; y++ )
       for ( x=guiApp.menuItems[ menuItem ].x; x < guiApp.menuItems[ menuItem ].x + guiApp.menuItems[ menuItem ].width; x++ )
         {
          tmp=drw[ y * guiApp.menuSelected.width + x ];
          if ( !IS_TRANSPARENT ( tmp ) ) buf[ y * guiApp.menu.width + x ]=tmp;
         }
    }
   oldMenuItem=menuItem;
/* --- */
   wsImageConvert( &guiApp.menuWindow,menuDrawBuffer );
   menuRender=False;
  }
 wsImageDraw( &guiApp.menuWindow );
}

void uiMenuMouseHandle( int RX,int RY )
{
 int x,y,i;

 if ( !guiApp.menu.Bitmap.Image ) return;

 menuItem=-1;
 x=RX - guiApp.menuWindow.X;
 y=RY - guiApp.menuWindow.Y;
 if ( ( x < 0 ) || ( y < 0  ) || ( x > guiApp.menu.width ) || ( y > guiApp.menu.height ) )
  {
   wsWindowRedraw( &guiApp.menuWindow );
   return;
  }

 for( i=0;i<=guiApp.IndexOfMenuItems;i++ )
  {
   if ( isInside( x,y,
         guiApp.menuItems[i].x,guiApp.menuItems[i].y,
         guiApp.menuItems[i].x+guiApp.menuItems[i].width,guiApp.menuItems[i].y+guiApp.menuItems[i].height ) ) { menuItem=i; break; }
  }
 wsWindowRedraw( &guiApp.menuWindow );
}

void uiShowMenu( int mx,int my )
{
 int x,y;

 if ( !guiApp.menuIsPresent || !guiApp.menu.Bitmap.Image ) return;

 x=mx;
 if ( x + guiApp.menuWindow.Width > wsMaxX ) x=wsMaxX - guiApp.menuWindow.Width - 1 + wsOrgX;
 y=my;
 if ( y + guiApp.menuWindow.Height > wsMaxY ) y=wsMaxY - guiApp.menuWindow.Height - 1 + wsOrgY;

 menuX=x; menuY=y;

 menuItem = 0;

 wsWindowMove( &guiApp.menuWindow,True,x,y );
 wsWindowRaiseTop( wsDisplay,guiApp.menuWindow.WindowID );
 wsWindowLayer( wsDisplay,guiApp.menuWindow.WindowID,1 );
 menuRender=True;
 wsWindowVisibility( &guiApp.menuWindow,wsShowWindow );
 wsWindowRedraw( &guiApp.menuWindow );
}

void uiHideMenu( int mx,int my,int w )
{
 int x,y,i=menuItem;

 if ( !guiApp.menuIsPresent || !guiApp.menu.Bitmap.Image ) return;

 x=mx-menuX;
 y=my-menuY;
// x=RX - guiApp.menuWindow.X;
// y=RY - guiApp.menuWindow.Y;

 wsWindowVisibility( &guiApp.menuWindow,wsHideWindow );

 if ( ( x < 0 ) || ( y < 0 ) ) return;

// printf( "---------> %d %d,%d\n",i,x,y );
// printf( "--------> mi: %d,%d %dx%d\n",guiApp.menuItems[i].x,guiApp.menuItems[i].y,guiApp.menuItems[i].width,guiApp.menuItems[i].height );
 if ( isInside( x,y,
        guiApp.menuItems[i].x,guiApp.menuItems[i].y,
        guiApp.menuItems[i].x+guiApp.menuItems[i].width,
        guiApp.menuItems[i].y+guiApp.menuItems[i].height ) )
   {
    uiEventHandling( guiApp.menuItems[i].message,(float)w );
   }
}

void uiMenuInit( void )
{

 if ( menuIsInitialized || !guiApp.menuIsPresent || !guiApp.menu.Bitmap.Image ) return;

 guiApp.menu.x=0;
 guiApp.menu.y=0;

 if ( ( menuDrawBuffer = calloc( 1,guiApp.menu.Bitmap.ImageSize ) ) == NULL )
  {
    mp_msg( MSGT_GPLAYER,MSGL_DBG2,MSGTR_NEMFMR );
   gtkMessageBox( GTK_MB_FATAL,MSGTR_NEMFMR );
   return;
  }

 wsWindowCreate( &guiApp.menuWindow,
 guiApp.menu.x,guiApp.menu.y,guiApp.menu.width,guiApp.menu.height,
 wsOverredirect|wsHideFrame|wsMaxSize|wsMinSize|wsHideWindow,wsShowMouseCursor|wsHandleMouseButton|wsHandleMouseMove,"MPlayer menu" );

 wsWindowShape( &guiApp.menuWindow,guiApp.menu.Mask.Image );

 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[menu] menuWindow ID: 0x%x\n",(int)guiApp.menuWindow.WindowID );

 menuIsInitialized=True;
 guiApp.menuWindow.ReDraw=uiMenuDraw;
// guiApp.menuWindow.MouseHandler=uiMenuMouseHandle;
// guiApp.menuWindow.KeyHandler=uiMainKeyHandle;
 menuRender=True; wsWindowRedraw( &guiApp.menuWindow );
}