osd_menu.c
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:9k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * parser.c : OSD import module
  3.  *****************************************************************************
  4.  * Copyright (C) 2007-2008 M2X
  5.  * $Id: f5d8704f050253abf496438ab47844fee79f7bc8 $
  6.  *
  7.  * Authors: Jean-Paul Saman
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  22.  *****************************************************************************/
  23. /*****************************************************************************
  24.  * Preamble
  25.  *****************************************************************************/
  26. #ifdef HAVE_CONFIG_H
  27. # include "config.h"
  28. #endif
  29. #include <vlc_common.h>
  30. #include <vlc_image.h>
  31. #include <vlc_osd.h>
  32. #include "osd_menu.h"
  33. #undef OSD_MENU_DEBUG
  34. /*****************************************************************************
  35.  * Local prototypes
  36.  *****************************************************************************/
  37. /*****************************************************************************
  38.  * Create a new Menu structure
  39.  *****************************************************************************/
  40. osd_menu_t *osd_MenuNew( osd_menu_t *p_menu, const char *psz_path,
  41.                          int i_x, int i_y )
  42. {
  43.     if( !p_menu ) return NULL;
  44.     p_menu->p_state = calloc( 1, sizeof( osd_menu_state_t ) );
  45.     if( !p_menu->p_state )
  46.         return NULL;
  47.     p_menu->psz_path = psz_path ? strdup( psz_path ) : NULL;
  48.     p_menu->i_x = i_x;
  49.     p_menu->i_y = i_y;
  50.     p_menu->i_style = OSD_MENU_STYLE_SIMPLE;
  51.     return p_menu;
  52. }
  53. /*****************************************************************************
  54.  * Free the menu
  55.  *****************************************************************************/
  56. void osd_MenuFree( osd_menu_t *p_menu )
  57. {
  58.     msg_Dbg( p_menu, "freeing menu" );
  59.     osd_ButtonFree( p_menu, p_menu->p_button );
  60.     free( p_menu->psz_path );
  61.     free( p_menu->p_state );
  62.     p_menu->p_button = NULL;
  63.     p_menu->p_last_button = NULL;
  64.     p_menu->psz_path = NULL;
  65.     p_menu->p_state = NULL;
  66. }
  67. /*****************************************************************************
  68.  * Create a new button
  69.  *****************************************************************************/
  70. osd_button_t *osd_ButtonNew( const char *psz_action, int i_x, int i_y )
  71. {
  72.     osd_button_t *p_button = NULL;
  73.     p_button = calloc( 1, sizeof(osd_button_t) );
  74.     if( !p_button )
  75.         return NULL;
  76.     p_button->psz_action = strdup(psz_action);
  77.     p_button->psz_action_down = NULL;
  78.     p_button->p_feedback = NULL;
  79.     p_button->i_x = i_x;
  80.     p_button->i_y = i_y;
  81.     return p_button;
  82. }
  83. /*****************************************************************************
  84.  * Free a button
  85.  *****************************************************************************/
  86. void osd_ButtonFree( osd_menu_t *p_menu, osd_button_t *p_button )
  87. {
  88.     osd_button_t *p_current = p_button;
  89.     osd_button_t *p_next = NULL;
  90.     osd_button_t *p_prev = NULL;
  91.     if( !p_current ) return;
  92.     /* First walk to the end. */
  93.     while( p_current->p_next )
  94.     {
  95.         p_next = p_current->p_next;
  96.         p_current = p_next;
  97.     }
  98.     /* Then free end first and walk to the start. */
  99.     while( p_current->p_prev )
  100.     {
  101.         msg_Dbg( p_menu, "+ freeing button %s [%p]",
  102.                  p_current->psz_action, p_current );
  103.         p_prev = p_current->p_prev;
  104.         p_current = p_prev;
  105.         if( p_current->p_next )
  106.         {
  107.             free( p_current->p_next->psz_name );
  108.             free( p_current->p_next->psz_action );
  109.             free( p_current->p_next->psz_action_down );
  110.             if( p_current->p_feedback )
  111.             {
  112.                 free( p_current->p_feedback->p_data_orig );
  113.                 free( p_current->p_feedback );
  114.                 p_current->p_feedback = NULL;
  115.             }
  116.             /* Free all states first */
  117.             if( p_current->p_next->p_states )
  118.                 osd_StatesFree( p_menu, p_current->p_next->p_states );
  119.             free( p_current->p_next );
  120.             p_current->p_next = NULL;
  121.         }
  122.         if( p_current->p_up )
  123.         {
  124.             free( p_current->p_up->psz_name );
  125.             free( p_current->p_up->psz_action );
  126.             free( p_current->p_up->psz_action_down );
  127.             if( p_current->p_feedback )
  128.             {
  129.                 free( p_current->p_feedback->p_data_orig );
  130.                 free( p_current->p_feedback );
  131.             }
  132.             p_current->p_feedback = NULL;
  133.             /* Free all states first */
  134.             if( p_current->p_up->p_states )
  135.                 osd_StatesFree( p_menu, p_current->p_up->p_states );
  136.             free( p_current->p_up );
  137.             p_current->p_up = NULL;
  138.         }
  139.     }
  140.     /* Free the last one. */
  141.     if( p_button )
  142.     {
  143.         msg_Dbg( p_menu, "+ freeing button %s [%p]",
  144.                  p_button->psz_action, p_button );
  145.         free( p_button->psz_name );
  146.         free( p_button->psz_action );
  147.         free( p_button->psz_action_down );
  148.         if( p_current->p_feedback )
  149.         {
  150.             free( p_current->p_feedback->p_data_orig );
  151.             free( p_current->p_feedback );
  152.             p_current->p_feedback = NULL;
  153.         }
  154.         if( p_button->p_states )
  155.             osd_StatesFree( p_menu, p_button->p_states );
  156.         free( p_button );
  157.     }
  158. }
  159. /*****************************************************************************
  160.  * Create a new state image
  161.  *****************************************************************************/
  162. osd_state_t *osd_StateNew( osd_menu_t *p_menu, const char *psz_file,
  163.                            const char *psz_state )
  164. {
  165.     osd_state_t *p_state = NULL;
  166.     video_format_t fmt_in, fmt_out;
  167.     p_state = calloc( 1, sizeof(osd_state_t) );
  168.     if( !p_state )
  169.         return NULL;
  170.     memset( &fmt_in, 0, sizeof(video_format_t) );
  171.     memset( &fmt_out, 0, sizeof(video_format_t) );
  172.     fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
  173.     if( p_menu->p_image )
  174.     {
  175.         p_state->p_pic = image_ReadUrl( p_menu->p_image, psz_file,
  176.                                         &fmt_in, &fmt_out );
  177.         if( p_state->p_pic )
  178.         {
  179.             p_state->i_width  = p_state->p_pic->p[Y_PLANE].i_visible_pitch;
  180.             p_state->i_height = p_state->p_pic->p[Y_PLANE].i_visible_lines;
  181.         }
  182.     }
  183.     if( psz_state )
  184.     {
  185.         p_state->psz_state = strdup( psz_state );
  186.         if( strncmp( ppsz_button_states[0], psz_state,
  187.                      strlen(ppsz_button_states[0]) ) == 0 )
  188.             p_state->i_state = OSD_BUTTON_UNSELECT;
  189.         else if( strncmp( ppsz_button_states[1], psz_state,
  190.                           strlen(ppsz_button_states[1]) ) == 0 )
  191.             p_state->i_state = OSD_BUTTON_SELECT;
  192.         else if( strncmp( ppsz_button_states[2], psz_state,
  193.                           strlen(ppsz_button_states[2]) ) == 0 )
  194.             p_state->i_state = OSD_BUTTON_PRESSED;
  195.     }
  196.     return p_state;
  197. }
  198. /*****************************************************************************
  199.  * Free state images
  200.  *****************************************************************************/
  201. void osd_StatesFree( osd_menu_t *p_menu, osd_state_t *p_states )
  202. {
  203.     osd_state_t *p_state = p_states;
  204.     osd_state_t *p_next = NULL;
  205.     osd_state_t *p_prev = NULL;
  206.     if( !p_state ) return;
  207.     while( p_state->p_next )
  208.     {
  209.         p_next = p_state->p_next;
  210.         p_state = p_next;
  211.     }
  212.     /* Then free end first and walk to the start. */
  213.     while( p_state->p_prev )
  214.     {
  215.         msg_Dbg( p_menu, " |- freeing state %s [%p]",
  216.                  p_state->psz_state, p_state );
  217.         p_prev = p_state->p_prev;
  218.         p_state = p_prev;
  219.         if( p_state->p_next )
  220.         {
  221.             if( p_state->p_next->p_pic )
  222.             {
  223.                 free( p_state->p_next->p_pic->p_data_orig );
  224.                 free( p_state->p_next->p_pic );
  225.             }
  226.             free( p_state->p_next->psz_state );
  227.             free( p_state->p_next );
  228.             p_state->p_next = NULL;
  229.         }
  230.     }
  231.     /* Free the last one. */
  232.     if( p_states )
  233.     {
  234.         msg_Dbg( p_menu, " |- freeing state %s [%p]",
  235.                  p_state->psz_state, p_states );
  236.         if( p_states->p_pic )
  237.         {
  238.             free( p_states->p_pic->p_data_orig );
  239.             free( p_states->p_pic );
  240.         }
  241.         free( p_state->psz_state );
  242.         free( p_states );
  243.     }
  244. }